Wax is a Rust-like syntax and OCaml-written toolchain for creating and inspecting WebAssembly. It grew from the wasm_of_ocaml runtime, whose roughly 27,000 lines of hand-written WebAssembly text use verbose stack-machine notation. Wax expresses the same operations more compactly: local reads become variable references, structured data access becomes field notation, and loops can be written as while statements. Its constructs map directly to WebAssembly instructions and types, including garbage-collected references, structs, arrays, nullability, casts, and signed or unsigned operations. Wax can compile to WebAssembly binaries or text, convert WebAssembly text or binaries back into Wax, format code, and type-check without compiling.
A key feature is its decompiler, which turns existing WebAssembly into readable Wax by recognizing patterns such as loops, placing locals near their first use, and removing redundant type annotations. For the wasm_of_ocaml string-equality function, the result is about 320 lines rather than 480 lines of text, while preserving the program’s operations. Decompiling and recompiling can reproduce the same instruction stream; a faithful mode disables optional simplifications, and fuzzing and WebAssembly test-suite checks verify correctness. Wax also provides source-specific diagnostics, formatting, configurable lints, conditional compilation, source maps, and editor integration, including a VS Code extension and language-server support. Its purpose is to make hand-written WebAssembly easier to write and maintain without changing what runs.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.