WebAssembly has both a binary format and a textual one. The latter, WebAssembly Text (WAT), is a stack-machine assembly language that can apparently be quite readable — at least, once you learn its ergonomic tricks.
The Two Big Ergonomics Wins
WASM is a stack machine. Bytecode is compact, but hand-authoring it means mentally tracking what each stack slot refers to at all times. WAT does not remove the stack, but it ships two features that make manual coding much more tractable.
First, you can declare locals and parameters, and give them names. Second, you get folded instructions: instead of spelling out get_local, i32.const, and i32.sub as separate operations, you can nest them in a single S-expression. A sequence like:
(local.set $writeidx (i32.sub (local.get $writeidx) (i32.const 1)))
...is equivalent to writeidx -= 1 in most mainstream languages.
Folding is recursive, so deeply nested expressions are possible — including ones that touch memory:
(local.set
$next_env_ptr
(i32.load (i32.add (global.get $env_ptrs)
(i32.mul (local.get $i) (i32.const 4)))))
In pseudo-C, that reads as:
next_env_ptr = memory[env_ptrs + i*4];
Named functions with named parameters and declared return values are another ergonomic win. The following declares a function with a single $num parameter and two return values:
(func $itoa (export "itoa") (param $num i32) (result i32 i32) ... )
Calls can also be written in folded form:
(call $itoa (i32.add (local.get $n) (i32.const 1)))
That is itoa(n+1) in higher-level terms.
Finally, WAT is explicitly typed. Values — parameters, globals, locals — carry types that the compiler checks. Type checking extends to stack interactions: the compiler tracks how many stack slots each instruction consumes and produces, so mismatches are caught at compile time rather than at runtime. In practice, code that compiles in WAT is much more often actually correct than code written in other assembly languages.
A Greppable Sample Collection
What WAT is missing is approachable documentation. The official WASM spec is written for formal verification, not human browsing; it is hard to grep and contains few practical examples. So far, the author has collected his WAT snippets into a GitHub repository called wasm-wat-samples.
The repository’s goal is to demonstrate how WAT constructs — including WASI — are used in practice. It is deliberately optimized for greppability, serving as a complementary reference to the spec rather than a replacement. Additional samples via issues and pull requests are welcome.



