The goal of this project is to prototype extensible languages in OCaml to find a good way to represent extensible ASTs which can form the base of a type safe and convenient macro system.
Step one is to experiment with OCamls variant and GADT types and module system to find the things which do not work well. Step two will be to design a language for extensible ASTs.
The following small languages will be implemented and combined:
Arithmetic expressions with integers
Arithmetic expressions with floats
calc-int + calc-float and conversions
Extending calc-int with conditional evaluation
Extending calc with conditional evaluation, loops, and booleans
Extending a given language with conditional evaluation and loops
A system to combine fragments of languages to form new ones
Define values and use them, for dynamic variables and compiled w/o runtime
Constant folding, transformations
Parsers which can be combined easily
Track source locations and use them for error reporting
Should be able to combine contexts of Eval_compiled and Parser, combine several bottom/up or top/down passes into a single one
There are two different approaches so far:
- Extensible ASTs using extensible tagged unions in source/ast
This works well to make languages which can be extended. But it does not scale well to multiple levels of language layers, compare Algo with the implementation for tagless unions
- Functors and tagless staged interpreters in source/tagless
This works well for multiple layers of languages which can extend each other multiple times. Also reusable language layers are very simple to do.
opam switch create . ocaml-base-compiler.4.10.0 --deps-only
dune build
dune exec calc-demo
dune exec algo-demo
dune exec tagless-demo
- Open any .ml file
- Call ‘(tuareg-opam-update-env)’
- Run above build commands
This will install all dependencies into the Nix store and compile the project
nix-build
Run it by calling ./result/bin/tagless-demo