A port of the min-caml compiler targeting WebAssembly.
- OCaml compiler (tested on 4.07.0)
- recent release of Node.js with WebAssembly support (tested on v8.12.0 and v11.6.0)
- using opam:
opam switch 4.07.0
opam install dune
- dune: for building the compiler.
npm install wabt
- wabt: for parsing emitted
.wat
file to WebAssembly module.
make
./mincaml tests/print # Note: filename without ".ml"
The original min-caml compiler requires filename without .ml
. I decided not to change it.
node runtime.js tests/print.wat
make test
make clean
- Compilation pipeline: WebAssembly is rather a "high-level" (compare to assembly) compilation target. There isn't much to do for virtual code preparation and register allocation, so after closure conversion (
closure.ml(i)
) we go direct to code emission (emit.ml(i)
). - K-Normalization: WebAssembly
if...then...else
operation is typed, so changes had to be made toknormal.ml(i)
to pass the result type ofIfEq
andIfLE
.
- port min-rt
- maybe a Virtual.ml after all to make things nicer