WebAssembly
Text Format (WAT)
Human-readable WebAssembly.
By EZ4Code Team
wattexts-expression
Code
;; WebAssembly Text Format (WAT)
(module
;; Add two i32 values
(func $add (export "add") (param $a i32) (param $b i32) (result i32)
local.get $a
local.get $b
i32.add)
;; A mutable global counter
(global $counter (mut i32) (i32.const 0))
(func (export "increment") (result i32)
global.get $counter
i32.const 1
i32.add
global.set $counter
global.get $counter))Explanation
WAT is the textual representation of WebAssembly, written as s-expressions that mirror the binary module structure. Each func declares params, results, and a stack-based instruction sequence where local.get pushes a value and i32.add pops two and pushes the sum. Tools like wat2wasm and wabt convert between text and binary.
More WebAssembly Snippets
Module Instantiation
Compile and instantiate a .wasm module.
Linear Memory
Shared, growable byte buffer.
Tables
Function references for indirect calls.
Imports and Exports
Exchange functions, memory, and globals.
JS Interop
Pass strings through shared memory.
Performance
Benchmark and parallelize WASM workloads.