Next: Resolver, Previous: Data types, Up: Toolchain reference [Contents][Index]
The (wasm wat)
module provides a parser for a variant of
WebAssembly Text (WAT) format. Since the WAT uses an s-expression
syntax that resembles but is distinct from Scheme syntax, Hoot opts to
represent WAT code as Scheme expressions. This allows for embedding
WAT directly into Scheme code and programmatically generating WAT code
via quasiquote templating or other means. We call this variant GWAT
where the “G” stands for “Guile”, of course.
The GWAT form has some additional expressive power such as allowing string constants, bytevectors for data segments, and i32/i64 constants in either the signed or unsigned range.
WAT has two variants: unfolded and folded. In the unfolded form, instruction sequences are linear, as they would be in the resulting binary:
'(module (func (export "add") (param $a i32) (param $b i32) (result i32) (local.get $a) (local.get $b) (i32.add)))
The folded form allows instructions to be nested within each other:
'(module (func (export "add") (param $a i32) (param $b i32) (result i32) (i32.add (local.get $a) (local.get $b))))
This form looks more like Scheme procedure calls and is generally easier to write and reason about.
Parse expr, a Wasm module expressed as WAT code, and return a Wasm module.
(parse-wat '(module (func (export "add") (param $a i32) (param $b i32) (result i32) (i32.add (local.get $a) (local.get $b)))))
The returned Wasm module preserves named references, among other
things, and is thus unsuitable as input to the assembler or
interpreter. To lower the module into a usable form, see
resolve-wasm
in Resolver.
Disassemble wasm and return its symbolic WAT form.
Next: Resolver, Previous: Data types, Up: Toolchain reference [Contents][Index]