mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
0d87198c92
When mrbc compiles multiple input files (e.g. `mrbc -g -o out.mrb a.rb b.rb`), the bison parser's one-token lookahead can buffer the final token of one file before partial_hook switches to the next. By the time bison reduces that token into an AST node, `mrb_parser_set_filename` has already reset `p->lineno` to 0, so init_var_header recorded lineno=0 for the previous file's last statement and codegen propagated the previous instruction's line. Save the lineno into `prev_file_lineno` immediately before the reset so init_var_header can restore the correct value when it detects the lookahead edge case (lineno==0 && filename_index>0). close #1316 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