Wax: a Rust-like syntax for writing WebAssembly by hand
Wax is a Rust-like syntax for WebAssembly, a compact binary instruction format that browsers and standalone engines run, and it compiles to exactly the same instructions as hand-written code. The author wrote it as another way to write the runtime of wasm_of_ocaml, an OCaml-to-WebAssembly compiler, which is nearly 27,000 lines of WebAssembly written by hand in about fifty WAT[1] files. The toolchain is written in OCaml and converts between Wax, WAT and the binary format in every direction.
In the example, a function that adds two numbers takes seven bytes in binary, and the Wax version compiles to the same seven bytes. Wax writes a reference that cannot be null as &t and one that may be null as &?t. The author calls the reverse direction, decompiling a binary or converting WAT back to Wax, the most interesting engineering, and shows it on caml_string_equal from the wasm_of_ocaml runtime.
The wax command can compile to binary or text, decompile a binary, reformat files in place and type-check a file. Converting between the two text formats keeps comments.
Read the original tarides.comDiscussion
Discussion
Commenters are divided: some find the Rust-like syntax no friendlier than the parenthesised text format and would have preferred an ML-style language, while others ask why to choose it over AssemblyScript or Rust with WASM tooling. The reverse direction, converting WAT back to a high-level language, drew the most practical interest.
Links from the post and discussion
- README of wasm_of_ocaml, linked by a commenter github.com
- AssemblyScript, mentioned as an alternative assemblyscript.org
- Quince, a similar language project by a commenter ar-ms.me
Sources
-
Tarides
Wax: A User-Friendly Syntax for WebAssembly
-
KRGeekNews KO
Wax: WebAssembly를 위한 사용자 친화적 문법



