Files
mruby-mruby/mrbgems/mruby-bin-mrbc
Yukihiro "Matz" Matsumoto 0d87198c92 mruby-compiler: preserve line number across multi-file boundary
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>
2026-05-11 10:38:02 +09:00
..

mruby-bin-mrbc

mrbc is the mruby compiler that compiles Ruby source files into bytecode.

Usage

mrbc [switches] programfile...

Options

  • -c - check syntax only
  • -o<outfile> - place the output into <outfile>; required for multi-files
  • -v - print version number, then turn on verbose mode
  • -g - produce debugging information
  • -B<symbol> - binary <symbol> output in C language format
  • -S - dump C struct (requires -B)
  • -s - define <symbol> as static variable
  • --remove-lv - remove local variables
  • --no-ext-ops - prohibit using OP_EXTs
  • --no-optimize - disable peephole optimization
  • --verbose - run at verbose mode
  • --version - print the version
  • --copyright - print the copyright

Examples

# Compile a Ruby script to bytecode
mrbc script.rb
# Creates script.mrb

# Specify output file
mrbc -o output.mrb script.rb

# Compile multiple files into one
mrbc -o combined.mrb file1.rb file2.rb

# Generate C source with symbol name
mrbc -Bscript_bytecode script.rb
# Creates script.c with const uint8_t script_bytecode[]

# Check syntax only
mrbc -c script.rb

# Compile with debug information
mrbc -g script.rb

Output Formats

  • .mrb - RiteBinary format (default), executable by mruby -b
  • .c - C source file (with -B option), for embedding in C programs

License

MIT License - see the mruby LICENSE file.