cp-17 — Capstone: JIT for a Tiny Dynamic Language
A small dynamic language frontend (fn / let / control flow / strings) compiled
with the LLVM C++ API and executed via ORC LLJIT, with a host-side
runtime registered as JIT-resolvable symbols.
This is the JIT counterpart to cp-16 (which AOT-compiled by shelling out to
llc and clang). Here we link LLVM as a library and run code in-process.
Build & test
cd src/cpp
cmake -S . -B build && cmake --build build
./build/tests/test_jit # 7/7 checks passed
./build/mldyn examples/hello.ml # CLI entry point
Pipeline
source.ml ──lex──▶ tokens ──parse──▶ AST ──emit──▶ llvm::Module ──ORC──▶ run main()
└── runtime symbols (host)
Layout
src/cpp/src/{source,diag,lex,parse}.{hpp,cpp}— frontend (cp-15/16 style)src/cpp/src/runtime.{hpp,cpp}— host functions exposed to JIT'd codesrc/cpp/src/ir_emit.{hpp,cpp}—Program→llvm::ModuleviaIRBuildersrc/cpp/src/jit.{hpp,cpp}—LLJITsetup, symbol registration,lookup("main")src/cpp/src/main.cpp—mldyn <file>CLIsrc/cpp/tests/test_jit.cpp— end-to-end pipeline testssteps/01..07.md— narrative walkthrough
Tests (7 checks)
print 42→42\nprint 1 + 2 * 3→7\nprint_str "hello, jit"→hello, jit\nfib(10)→55\nwhileloop printing0\n1\n2\nml_record_int_argruntime callback fires from JIT'd code- Interleaved
print_str+printinteger output