Layer cake stall: 20 levels tracing the WebAssembly stack: WAT opcodes, linear memory, traps and call_indirect. An interpreter hand-rolled from scratch.
WebAssembly runs its instructions one at a time and keeps its values on a stack, not in registers. i32.const 5 puts the value 5, of type i32 (a 32-bit integer), on top of the stack. In Mbak Yuni's kitchen that stack is the cake on the turntable: each value is a layer, coloured by its type.
i32.add, i32.sub and i32.mul take the two top layers and put one layer with the result. The layer put first is the left operand.
A WebAssembly function takes parameters and may have more locals ((local $i i32), starting at 0). In Mbak Yuni's kitchen both are small bowls beside the table. local.get $x puts a copy of bowl $x as a new layer; local.set $x takes the top layer and pours it into the bowl; local.tee $x pours a copy and leaves the layer.
When an instruction cannot be done, WebAssembly stops right there: that is a trap. No value comes back, and the JavaScript that called it gets a WebAssembly.RuntimeError with the engine's message. In Mbak Yuni's kitchen a trap brings the cake down off the turntable.
An i32 is just 32 bits. i32.lt_s, i32.div_s and i32.rem_s read them as a signed number (two’s complement); i32.lt_u, i32.div_u and i32.rem_u as a number from 0 to 4294967295. The same bits, two meanings.
Blocks in WebAssembly have types. if (result i32) ... else ... end takes one i32 condition, and both branches must put one i32. The condition always comes from the stack.