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 code
  • src/cpp/src/ir_emit.{hpp,cpp}Programllvm::Module via IRBuilder
  • src/cpp/src/jit.{hpp,cpp}LLJIT setup, symbol registration, lookup("main")
  • src/cpp/src/main.cppmldyn <file> CLI
  • src/cpp/tests/test_jit.cpp — end-to-end pipeline tests
  • steps/01..07.md — narrative walkthrough

Tests (7 checks)

  1. print 4242\n
  2. print 1 + 2 * 37\n
  3. print_str "hello, jit"hello, jit\n
  4. fib(10)55\n
  5. while loop printing 0\n1\n2\n
  6. ml_record_int_arg runtime callback fires from JIT'd code
  7. Interleaved print_str + print integer output