Skip to content

A port of the min-caml compiler targeting WebAssembly.

License

Notifications You must be signed in to change notification settings

zxygentoo/min-caml-wasm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

min-caml-wasm

A port of the min-caml compiler targeting WebAssembly.

Dependencies

  • OCaml compiler (tested on 4.07.0)
  • recent release of Node.js with WebAssembly support (tested on v8.12.0 and v11.6.0)

OCaml dependencies

opam switch 4.07.0
opam install dune
  • dune: for building the compiler.

JavaScript dependencies

npm install wabt
  • wabt: for parsing emitted .wat file to WebAssembly module.

Usage

Build the compiler

make

Compile file

./mincaml tests/print        # Note: filename without ".ml"

The original min-caml compiler requires filename without .ml. I decided not to change it.

Run compiled module

node runtime.js tests/print.wat

Run tests from min-caml project

make test

Clean up

make clean

Changes to min-caml

  • 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 to knormal.ml(i) to pass the result type of IfEq and IfLE.

TODO

  • port min-rt
  • maybe a Virtual.ml after all to make things nicer

About

A port of the min-caml compiler targeting WebAssembly.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • OCaml 96.0%
  • JavaScript 1.8%
  • Makefile 1.6%
  • Standard ML 0.6%