Some sample WebAssembly Text programs.
WebAssembly defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating interactions between such programs and their host environment.
The text format (WAT) is, essentially, an assembly language. While most people will not write WAT directly (just as most programmers don't write assembly code directly), familiarity this format is important if you seek a deep understanding of WASM mechanisms and related toolchains.
Unless otherwise stated, each sample consists of a single .wat
file and an
accompanying test.js
file. When the setup is more complicated, the directory's
own README will have additional information.
First, start by compiling the WAT file to WASM with wabt or some other WASM toolchain:
$ wat2wasm somefile.wat
This creates a somefile.wasm
binary, which test.js
expects to find in its
own directory. To load and test the WASM, you'll need a recent
Node.js installed, and run:
$ node test.js
This will typically emit some output; if the loading failed or the loaded WASM
behaves unexpectedly, the test.js
script will report an error.
Useful sources of documentation about WASI host calls:
- Preview 1 ABI
- wasi-libc sources; in particular, the wasi/api.h header