cp-12 · ORC JIT — compile and execute in-process
cp-11 produced an optimised llvm::Module. cp-12 hands that module
to LLVM's modern JIT (ORCv2, wrapped behind LLJIT) which
compiles it to native code on the spot, looks up main, and calls it.
Build & run
cmake -S src/cpp -B build
cmake --build build
./build/tests/test_jit # → 17/17 checks passed
echo 'print 2 + 3 * 4;' | ./build/mljit # 14
echo 'print 2 + 3 * 4;' | ./build/mljit --emit-llvm # textual IR instead
./build/mljit -O program.ml # run after O2
Headline test (recursive fib)
fn fib(n){ if (n < 2) { return n; } return fib(n-1) + fib(n-2); }
print fib(20);
JIT-compiled with -O → 6765.
Layout
src/cpp/
├── CMakeLists.txt # links orcjit + executionengine + native + nativecodegen
├── src/jit.hpp / jit.cpp # initNative() + runMain(ctx, module)
├── src/main.cpp # `mljit` CLI
└── tests/test_jit.cpp # 17/17 checks