Home

Awesome

wam: WebAssembly Macro language and processor

wam syntax

Wam syntax is a near superset of wat syntax that is more convenient for human developers to write directly.

The one place where wam is not a strict superset of wat is that it does not supports numeric indexes for globals, functions, and local references. But this is okay because index based references are much less useful to humans than they are to computers.

The following extensions to the wat syntax are supported:

wamp: wam processor

Current functionality:

Future functionality:

Example

In the examples/ directory is a fizzbuzz example that makes use of wam syntax. Use wamp to convert the example to wat source.

./wamp examples/fizzbuzz.wam examples/print.wam > fizzbuzz.wat

Examine the wam files and the resulting wat to see what processing and macro expansion was performanced by wamp. The wat source can be compiled to a wasm module using the wasm-as assembler from binaryen.

wasm-as fizzbuzz.wat -o fizzbuzz.wasm

The wasm module can be executed using the wac/wace WebAssembly interpreter:

wace ./fizzbuzz.wasm

Examples of wam and equivalent wat:

wamwat
<pre>($myfun)</pre><pre>(call $myfun)</pre>
<pre>7</pre><pre>(i32.const 7)</pre>
<pre>$myvar</pre><pre>(local.get $myvar)</pre>
<pre>(CHR "A")</pre><pre>(i32.const 0x40)</pre>
<pre>"my string"</pre><pre>(global $S_STRING_7 i32 (i32.const 73))<br>(data ... "my string\00" ...)<br>...<br>(i32.add (global.get $memoryBase)<br> (global.get $S_STRING_7))</pre>
<pre>(STATIC_ARRAY 6)</pre><pre>(global $S_STATIC_ARRAY_8 i32 (i32.const 80))<br>(data ... "\00\00\00\00\00\00" ...)<br>...<br>(i32.add (global.get $memoryBase)<br> (global.get $S_STATIC_ARRAY_8))</pre>
<pre>(AND 7 8)</pre><pre>(if i32 (i32.const 7)<br> (if i32 (i32.const 8) (i32.const 1) (i32.const 0))<br> (i32.const 0))</pre>
<pre>(OR 7 8)</pre><pre>(if i32 (i32.const 7)<br> (i32.const 1)<br> (if i32 (i32.const 8) (i32.const 1) (i32.const 0)))</pre>
<pre>(LET $i 7<br> $j (i32.add $i 1))</pre><pre>(local $i i32 $j i32)<br>(local.set $i (i32.const 7)<br>(local.set $j (i32.add (local.get $i) (i32.const 1)))</pre>

License

MPL-2.0 (see ./LICENSE)