Ant is an experimental incremental evaluator that memoises prefixes of CEK machine executions. Instead of caching whole calls, Ant records reusable fragments of the control–environment–continuation state so later runs can jump over work when the live input shares that prefix.
- CEK machine core. Programs are compiled to a control table; the evaluator runs a CEK machine
(C, E, K)and records step summaries keyed by program counter plus slices of the environment/continuation. - Finger-tree values. Environments and continuations are finger trees annotated with monoid hashes and degree measures. This lets Ant split or compare prefixes without rescanning full structures (see
internal.md). - Dependency-aware skips. Each executed step becomes a pattern–value pair. If the current state matches a recorded source pattern, Ant substitutes the live bindings, composes steps, and fast-forwards instead of re-stepping the VM.
For deeper dives, see internal.md (architecture) and motivation.md (why this approach exists).
- Front-end.
Lexer.mll,Parser.mly, andSyntax.mldefine the surface language;Typing.ResolveGlobalupgrades known names to globals so typing can treat them specially. - Type inference.
Typing.mlimplements a constraint-based Hindley–Milner engine over theType/SynInforepresentations. - Normalisation.
Transform.mlperforms CPS and defunctionalisation;Pat.mllowers pattern matches into decision trees. - Backends.
CompileMemo.mlemits the memoising CEK VM,CompileSeq.mlemits a pure interpreter, andCompilePlain.mlproduces direct OCaml for quick inspection. All three share the IR helpers inCode.ml/Ir.ml;CompileType.mlgenerates OCaml converters for user-defined ADTs. - Runtime core. Finger-tree values live in
Value.ml/Words.ml; memo storage and step composition are implemented inMemo.ml,Dependency.ml,Pattern.ml, andState.ml.
use uv sync to install deps.
make dependency # install toolchain/dev tools and refresh dune.lock
make build # dune build
make run # regenerate generated/*.ml, format, and execute GeneratedMainyou may need git submodule update --init
nightly.py underpins these targets; it will print a harmless warning if the ant opam switch already exists.
lib/– OCaml sources (front-end, backends, memo/runtime infrastructure).generated/– Auto-generated OCaml modules (rebuilt bymake).examples/– Sample.antprograms;examples/Test.antis the default demo.bench/– Benchmarks.docs/– Project documentation (README.md,internal.md,dependency.md,motivation.md,AGENTS.md).
Run dune exec ant -- INPUT OUTPUT [flags] to compile or inspect a program. The output file collects whatever artifacts you request.
-p,--print-ast– pretty-print the resolved surface syntax.--pat,--compile-pat– dump the compiled pattern matrices fromPat.--compile– emit backend output (CompileMemoby default) to the output file.-b,--backend memo|seq|plain– pick the backend for--compile.-t,--typing– print inferred types fromTyping; combine with-Lto show levels.-c,--print-cps– show the CPS-transformed AST.-d,--print-defunc– show the defunctionalised AST.-D,--print-cps-defunc– run CPS then defunctionalise before printing.
All CLI wiring lives in bin/main.ml.
make dependency– create/update the localantopam switch, install the Dune toolchain/dev tools, and refresh the lockdir withdune pkg lock.make build– build through the managed switch (dune build).make run– regenerategenerated/*.ml, format, and executeGeneratedMain.dune runtest– run unit tests intest/test_ant.ml(hash monoid and intmap checks).dune exec bench/<target>.exe– run benchmarks inbench/.
Generated modules under generated/ are overwritten by make run; avoid editing them manually.
Pull requests are welcome. Please run make build before submitting and note any remaining warnings or TODOs in the description.