mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
d1aa722a98
The previous optimization for converting JMPNOT+JMP to JMPIF in alternative patterns had two bugs: 1. It triggered incorrectly for nested alternatives like `1 | 2 | 3` (parsed as `((1|2)|3)`), causing memory corruption. 2. The chain end detection was wrong - it checked `prev_offset == 0` but the chain actually ends when `(pos+2) + offset == 0`. Fix by: - Only applying optimization when left pattern is not NODE_PAT_ALT - Correctly detecting chain end by checking if next_addr == 0 - Properly unlinking the last JMPNOT from the fail chain Co-authored-by: Claude <noreply@anthropic.com>
mruby-compiler
This mrbgem provides the mruby compiler, which is responsible for parsing Ruby code and generating mruby bytecode.
Functionality
The mruby-compiler gem includes the following components:
- Parser: Translates Ruby source code into an abstract syntax tree (AST).
- Code Generator: Traverses the AST to produce executable mruby bytecode.
mrbcexecutable: A command-line tool for compiling.rbfiles into.mrbbytecode files.
Usage
The mrbc (mruby-bin-mrbc) executable will generate compiled binary from Ruby
programs via this gem.
Example of using mrbc:
# Compile a Ruby script to bytecode
bin/mrbc my_script.rb
# Run the compiled script
bin/mruby my_script.mrb