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, housed in their own directory. When the setup is more
complicated, the directory's wwn README will have additional information.
To run a single sample, cd into its directory, and start by compiling the
WAT file to WASM with watgo,
wasm-tools or some other WASM
toolchain. Let's use the stack example for demonstration:
$ cd stack
$ watgo parse stack.wat -o stack.wasm
This creates a stack.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 and finish successfully if all went well;
if the loading failed or the loaded WASM behaves unexpectedly, the test.js
script will report an error.
An alternative way to run a single sample is using the run-tests.js runner,
mentioned in the next section. From the root directory of the project, run:
$ node run-tests.js stack
And it will automatically do the steps described above.
The run-tests.js script is a test runner for the entire project:
$ node run-tests.js
It should be run from the root directory of the project. This command
will build all .wat files in all directories and run the corresponding
test.js files, summarizing the results.
Useful sources of documentation about WASI host calls:
117 commits
WebAssembly
59.7%
JavaScript
35.6%
Python
2.5%
HTML
1.2%
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, housed in their own directory. When the setup is more
complicated, the directory's wwn README will have additional information.
To run a single sample, cd into its directory, and start by compiling the
WAT file to WASM with watgo,
wasm-tools or some other WASM
toolchain. Let's use the stack example for demonstration:
$ cd stack
$ watgo parse stack.wat -o stack.wasm
This creates a stack.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 and finish successfully if all went well;
if the loading failed or the loaded WASM behaves unexpectedly, the test.js
script will report an error.
An alternative way to run a single sample is using the run-tests.js runner,
mentioned in the next section. From the root directory of the project, run:
$ node run-tests.js stack
And it will automatically do the steps described above.
The run-tests.js script is a test runner for the entire project:
$ node run-tests.js
It should be run from the root directory of the project. This command
will build all .wat files in all directories and run the corresponding
test.js files, summarizing the results.
Useful sources of documentation about WASI host calls:
117 commits
WebAssembly
59.7%
JavaScript
35.6%
Python
2.5%
HTML
1.2%