Currently, this work is experimental. There is some initial documentation evolving together with the implementation of safe bindings but it's highly incomplete.
Andy Wingo gave a "Compiling to WebAssembly" presentation at FOSDEM'21, and published his artifacts.
I implemented the same compiler in Racket using the binaryen bindings (see tests/wingo-raw.rkt
). To run it on the same example Andy presented try:
$ racket test/wingo-raw.rkt test/wingo_fact.scm
"Compiled module:"
(module
(type $i32_=>_i32 (func (param i32) (result i32)))
(export "fac" (func $fac))
(func $fac (param $0 i32) (result i32)
(if (result i32)
(i32.eqz
(local.get $0)
)
(i32.const 1)
(i32.mul
(local.get $0)
(call $fac
(i32.sub
(local.get $0)
(i32.const 1)
)
)
)
)
)
)
"Optimized module:"
(module
(type $i32_=>_i32 (func (param i32) (result i32)))
(export "fac" (func $fac))
(func $fac (; has Stack IR ;) (param $0 i32) (result i32)
(if (result i32)
(local.get $0)
(i32.mul
(call $fac
(i32.sub
(local.get $0)
(i32.const 1)
)
)
(local.get $0)
)
(i32.const 1)
)
)
)