This project is a Prism-based Ruby parser and bytecode compiler for mruby, PicoRuby, and FemtoRuby.
Read this note first:
- If this file is under
mruby/mrbgems/mruby-compiler, you are reading the canonical mruby core mgem. This is where development happens. - If this file is at the top of
picoruby/mruby-compiler2, you are reading the standalone mirror. That repository exists for projects that need to use the compiler independently from mruby and pin it at an arbitrary commit. - Please send patches to
mruby/mruby, not topicoruby/mruby-compiler2. The standalone repository is synchronized from mruby after changes land there.
The compiler must remain usable without fundamentally depending on mruby. mruby uses it as mruby-compiler; PicoRuby and FemtoRuby use the same compiler through the standalone mruby-compiler2 mirror.
Projects that want to pin the compiler independently from mruby can use:
MRuby::Build.new do |conf|
conf.gem github: "picoruby/mruby-compiler2", commit: "..."
endpicoruby/mruby-compiler2 is synchronized from
mruby/mruby/mrbgems/mruby-compiler. It may lag behind mruby until the sync workflow opens and merges a mirror PR.
Prism support in mruby is opt-in:
MRB_COMPILER_PRISM=yes rake testThe top-level mruby Rakefile maps MRB_COMPILER_PRISM=yes to MRUBY_CONFIG=prism only when neither MRUBY_CONFIG nor CONFIG is already set. Explicit config selection continues to win:
MRUBY_CONFIG=ci/gcc-clang rake test
MRUBY_CONFIG=prism rake testThis keeps the normal mruby build and CI path compatible with the existing mruby-compiler gem while Prism support is still being aligned.
The Prism route currently includes:
mruby-compilermruby-bin-mrbcmruby-bin-mrubymruby-bin-mirbmruby-eval
lib/prism is a git submodule pointing at ruby/prism.
The gem bootstrap runs before mrbgem.rake collects Prism C sources with Dir.glob. This matters for fresh checkouts, where the submodule may not yet be initialized and generated Prism files may be absent.
During normal build setup, mrbgem.rake does the following:
-
If
lib/prism/templates/template.rbis missing, run:git submodule update --init lib/prism
-
If generated Prism files such as
src/node.c,src/serialize.c,include/prism/ast.h, orinclude/prism/diagnostic.hare missing, run:ruby templates/template.rb
This bootstrap belongs in the compiler gem because the same source tree is used from mruby, PicoRuby, FemtoRuby, and the standalone mirror.
The compiler is shared by multiple runtimes. Changes made for mruby must preserve these boundaries.
-
Do not introduce a fundamental dependency on mruby.
The compiler should continue to build for both
MRC_TARGET_MRUBYandMRC_TARGET_MRUBYC. mruby-only compatibility code must stay behindMRC_TARGET_MRUBY. -
The compiler library must not define
global_mrb.The executable or embedding runtime owns
global_mrbwhen the mruby allocator path needs it. This avoids duplicate-symbol conflicts in PicoRuby and r2p2. In standalone mruby,mrbc-prism,mruby-prism,mirb-prism, andmrbtestprovide the owner when building the Prism route. -
PICORB_VM_MRUBYandPICORB_VM_MRUBYCmust remain respected.PicoRuby builds the mruby VM path. FemtoRuby builds the mruby/c VM path. The gem configuration must not accidentally select
MRC_TARGET_MRUBYwhile building FemtoRuby. -
Public compiler headers are the API boundary for PicoRuby and FemtoRuby.
Keep the C API usable without depending on mruby internals:
mrc_common.hmrc_ccontext.hmrc_compile.hmrc_dump.h
-
Do not hard-code the PicoRuby submodule path.
PicoRuby intentionally uses top-level gems such as
mrbgems/mruby-compiler-prismor the standalonemruby-compiler2mirror and synchronizes them at chosen times. -
mruby-eval-prismis for the mruby VM path.FemtoRuby uses
picoruby-eval, loaded as a prebuilt gem. On FemtoRuby,evalis available after:require "eval"
MRB_COMPILER_PRISM=yes rake test:build currently passes in the local port. The Prism build links:
mrbc-prismmruby-prismmirb-prismmrbtest
Basic execution works:
build/host/bin/mruby-prism -e 'p 1 + 2'
#=> 3
build/host/bin/mruby-prism -e 'p eval("1 + 2")'
#=> 3Known remaining work:
MRB_COMPILER_PRISM=yes rake test:run:libreachedmrbtestlocally but failed in the socket tests with an AF_UNIX bind error. This should be rechecked in upstream CI before treating it as a Prism compiler issue.MRB_COMPILER_PRISM=yes rake test:run:binstill has Prism-specific bintest failures around diagnostics, verbose dump output, top-level locals, andmirb-prismmulti-line behavior.mruby-bin-strip-prismdoes not exist yet.- Some non-Prism gems and gemboxes still refer directly to
mruby-compiler.
MIT License. See LICENSE.