WEBASSEMBLY illustrated

exploring some mental models and implementations

Takenobu T.
Rev. 0.01.0

NOTE- Please refer to the official documents in detail.
- This information is based on "WebAssembly Specification
Release 1.0 (Draft, last updated Oct 31, 2018)".
- This information is current as of Nov, 2018.
Still work in progress.

Contents
1. Introduction- Overview
2. WebAssembly abstract machine- Abstract machine- Store- Stack- Computational model- Type- Trap- Thread- External interface

3. WebAssembly module- Module- Binary encoding

4. WebAssembly instructions- Instructions- Simple instructions- Control instructions- Byte order

Appendix A : Semantics
Appendix B : Implementation- Implementations- CLI development utilities- Test suite- Desugar examples
Appendix C : Future

References

1. Introduction

1. Introduction

Overview

WebAssembly is a code format

Sourcecode

C/C++
sourceRustsourceGosourceHaskellsource...

Compiler

Emscripten

RustcompilerGo
compiler

GHC/
Asterius

LLVM,
Binaryen

WebAssemblycode

Runtime(Browser, Stand-alone)...

WebAssembly module(WebAssembly binary)

Web browser

Other environment(Firefox, Chrome, Safari, Edge, ...)

(Node.js, WAVM,...)

WebAssembly is a safe, portable, low-level code format.
References : [1] Ch.1.1, [2], [3], [6]WebAssembly code
Text format
syntactic sugar(module(func (export "add7")(param $x i64)
(result i64)
(i64.add(get_local $x)(i64.const 7))))Binary format
core syntax(module(type(func (param i64) (result i64)))(func (type 0)(param i64) (result i64)
get_local 0
i64.const 7
i64.add)(export "add7" (func 0)))0x0061736d010000 ...

WebAssembly encodes a low-level, assembly-like programming language.
WebAssembly has multiple concrete representations.
(its text format and the binary format.)
References : [1] Ch.2, Ch.5, Ch.6, [7]Abstract machine is defined

Code

SoftwareHardware

WebAssembly code

Abstract machine

WebAssembly abstract machine

Platform,
Environment

Web browser, Other environment

Instruction set
Binary encoding
Validation semantics
Execution semantics(Firefox, Chrome, Safari, Edge, Node.js, WAVM,...)

Physical Processor(x86, ARM, ...)

WebAssembly is a virtual instruction set architecture (virtual ISA).
Execution behavior is defined in terms of an abstract machine.
References : [1] Ch.1.1, [2], [3]Validation
WebAssembly module(WebAssembly binary)

Code

Runtime
DecodeValidation
Execution

Validation checks that a WebAssembly module is well-formed.
Validity is defined by a type system.
The type system of WebAssembly is sound, implying both type safety andmemory safety with respect to the WebAssembly semantics.
References : [1] Ch.1, Ch.3, Ch.7, [2]2. WebAssembly abstract machine2. WebAssembly abstract machine

Abstract machine

WebAssembly abstract machine
WebAssembly abstract machine

Operandstack

Functions

Table

Linearmemory(immutable)(immutable)(mutable)

Globals(mutable)

Control
stack
Call
stack

Stack

Store

WebAssembly abstract machine is based on a stack machine.
The abstract machine includes a store and an implicit stack.
References : [1] Ch.2, Ch.4, [2], [4]2. WebAssembly abstract machineStoreStoreFunctions

Table

Linearmemory(immutable)(immutable)(mutable)

Globals(mutable)Store

The store represents all global state.
The store have been allocated during the life time of the abstract machine.
References : [1] Ch.2, Ch.4, [2], [4]Functions

Functionscall #n...

0
12function #0
function #1
function #2::

Instruction sequence

The function component of a module defines a vector of functions.
Functions are referenced through function indices.

References : [1] Ch.2, Ch.4, [2], [4]TableTable
Functions0
1
2

call_indirect #n::function #0
function #1
function #2:

The table is an array of opaque values of a particular element type.
Currently, the only available element type is an untyped function reference.
This allows emulating function pointers by way of table indices.
Tables are referenced through table indices.
References : [1] Ch.2, Ch.4, [2], [4]Linear memory

Linear memory

8, 16, 32, 64-bit load:
8, 16, 32, 64-bit store

Byte array

8 bit

The linear memory is a contiguous, mutable array of raw bytes.
The linear memory can be addressed at byte level (including unaligned).
The size of the memory is a multiple of the WebAssembly page size.
References : [1] Ch.2, Ch.4, [2], [4]GlobalsGlobals

get_global #n0
12

global variable #0
global variable #1
global variable #2::

set_global #n

The globals component defines a vector of global variables.
The globals are referenced through global indices.
The global variables hold a value and can either be mutable or immutable.
References : [1] Ch.2, Ch.4, [2], [4]2. WebAssembly abstract machine

StackStackOperandstack

ValuesControlstack

LabelsCall
stack

FramesStack

Most instructions interact with the implicit stack.
The stack contains values, labels and frames(activations).
References : [1] Ch.2, Ch.4, [2], [4]Operand stack

Stack

Operand stack

add, sub, ...

push ,pop

value
value
value

Instructions manipulate values on an implicit operand stack.
The layout of the operand stack can be statically determined at any point in the code.

References : [1] Ch.2, Ch.4, [2], [4]Control stack

Stack

Control stackblock, if, loop,
branchpush ,pop

label
label
label

Each structured control instruction introduces an implicit label.
Labels are targets for branch instructions that reference them with label indices.

References : [1] Ch.2, Ch.4, [2], [4]Call stackStackcall, return

set_local, get_local

push ,pop

Call stack

set, getlocal variable #2
local variable #1
local variable #0
return arity
Frame
Frame

Frames hold the values of its local variables (including arguments).
Frames also carry the return arity of the respective function.

References : [1] Ch.2, Ch.4, [2], [4]2. WebAssembly abstract machine

Computational model

Computational model
WebAssembly abstract machine

Functions

Instruction sequence

Table

...

Operand stack

Linear memory

Control stack

Globals

External means

instruction

operation

Call stack (Frame)

Store

References : [1] Ch.2, Ch.4, [2], [4]Computational model
WebAssembly abstract machinecallcall_indirect

Functions

Instruction sequence

Table

code

...
instruction

Operand stack

operation

Linear memory

External means

add, sub, ...

load, store

set, getblock, br, ...

valuesControl stackglobal vars

set, getlabelscall, return

Globals

Call stack (Frame)Storelocal vars

References : [1] Ch.2, Ch.4, [2], [4]2. WebAssembly abstract machineTypeValue types

Integers

32bit

Integers

Floating-point numbers
Floating-point numbers

64bit

32bit
64bit

WebAssembly provides only four basic value types.
32 bit integers also serve as Booleans and as memory addresses.

References : [1] Ch.1, Ch.2, Ch.3, Ch.4 , [2], [4]Instructions have type annotations
arguments

32bit integeri32.add
resultarguments

i64.add
result64bit integer

arguments

f32.add
result32bit floating-point

arguments

f64.add
result64bit floating-point

Some instructions have type annotations.
For example, the instruction i32.add has type [i32 i32] → [i32],
consuming two i32 values and producing one.
References : [1] Ch.2, Ch.3, Ch.4, [2]Functions have type declarations

Call stack (Frame)(func(param $x i64)
(result i64)
(i64.add(get_local $x)(i64.const 7)))

arguments

resultlocal variable

Operand stack

value

Each function takes a sequence of WebAssembly values asparameters and returns a sequence of values as results as definedby its function type.
References : [1] Ch.2, Ch.3, Ch.4, [2]Control blocks have also a type declaration(block (result i64)
(i64.add(get_local $x)(i64.const 7)))

resultOperand stack

value

Every control construct is annotated with a function type.

References : [1] Ch.2, Ch.3, Ch.4, [2]2. WebAssembly abstract machine

Trap

Trap
WebAssembly abstract machine
Code

ReportEnvironment

Abort

Handling

Certain instructions may produce a trap, which immediately aborts execution.
Traps cannot be handled by WebAssembly code,
but are reported to the outside environment, where they typically can be caught.
References : [1] Ch.1, Ch.4 , [2], [4]Trap
WebAssembly abstract machine
undefined element
uninitialized element
Functions

Instruction sequence

Table

...
instruction

operation

unreachable
zero division
invalid conversion

Control stack

Linear memory

External means

Operand stackout of bounds

Globals

Call stack (Frame)

Store

References : [1] Ch.1, Ch.4 , [2], [4]Linear memory

Linear memory

load/store

OK:in bounds

Trap

A trap occurs if an access is not within the bounds of the current memory size.
References : [1] Ch.1, Ch.4 , [2], [4]2. WebAssembly abstract machine

ThreadThreadThreads

Instruction
sequence

Functions

Stack

Table

LinearmemoryGlobalsStore

The current version of WebAssembly is single-threaded,
but configurations with multiple threads may be supported in the future.
References : [1] Ch.4 , [2], [4]2. WebAssembly abstract machine

External interface

Import and export
WebAssembly abstract machine

Functions

ImportExportTable

ImportExportLinear memory
ImportHost environment,
External means,
Other instances, ...

ExportGlobals

ImportExport

Stack

Store

Functions, table, memory and globals may be shared via import/export.
References : [1] Ch.2, Ch.4. [2]. [5]Mutation from external
WebAssembly abstract machine

Functions

Table

MutableLinear memory
MutableGlobals

Stack

Host environment,
External means,
Other instances, ...

MutableStore

Table, memory and globals can be mutated by external mean.
References : [1] Ch.2, Ch.4. [2]Invoke from external
WebAssembly abstract machine

Functions
exported

InvokeTable

Host environment,
External means,
Other instances, ...

Linear memory

Globals

Stack

Store

Any exported function can be invoked externally.
References : [1] Ch.2, Ch.4. [2]Foreign call
WebAssembly abstract machine

Functionscall

imported

Code

Invoke (FFI)
Table

Host environment,
External means,
Other instances, ...

Linear memory

Globals

Stack

Store

Call instructions can invoke an imported function.
References : [1] Ch.2, Ch.4. [2]3. WebAssembly module

3. WebAssembly module

ModuleWebAssembly module

WebAssembly module

code

WebAssembly programs are organized into modules.
Modules are the distributable, loadable, and executable unit of code.
WebAssembly modules are distributed in a binary format.

References : [1] Ch.1, Ch.2, Ch.4, [2], [4], [5]WebAssembly module
WebAssembly module

Types

start

Table

Linear memory

Functions

elem

data

ExportGlobals

ImportA module collects definitions for types, functions, table, memory, and globals.
In addition, it can declare imports and exports and provide initialization logic in
the form of data and element segments or a start function.

References : [1] Ch.1, Ch.2, Ch.4, [2], [4], [5]WebAssembly module and abstract machine
WebAssembly module
Types

Stack

start

Table

Linear memory

Export

limit

limit

(size)(size)

Functions

elem

data

Globals

Functions

Table

LinearmemoryGlobals

ImportStore
WebAssembly abstract machine (module instance)

A module corresponds to the static representation of a program.
A module instance corresponds to a dynamic representation.
References : [1] Ch.1, Ch.2, Ch.4, [2], [4], [5]3. WebAssembly module

Binary encodingBinary encoding of modules
WebAssembly module (WebAssembly binary)
00 61 73 6d 01 00 00 00 01 07 01 60 02 7e 7e 01 7e 03

...

Form
magic
versionimport section

sections

type section
table section
func section:

code section

Binary encoding of modules

The binary encoding of modules is organized into sections.
References : [1] Ch.5, [7], [5]Sections
Binary encoding of modules
magic
versionimport section
type section
table section

Section format

func section

id:

00 00 00 01 07 01 60 02 7e 7e 01 7e 03...

content

sections

code section

size

Each section consists of• a one-byte section id,• the u32 size of the contents, in bytes,• the actual contents, whose structure is depended on the section id.
References : [1] Ch.5, [7], [5]Example of WebAssembly module[text format](module(func (export "foo" (result i32)
i32.const 7))(`wat2wasm –v` command)[binary format]
0000000: 0061 736d
0000004: 0100 0000
; section "Type" (1)0000008: 01
0000009: 05
000000a: 01; type 0000000b: 60
000000c: 00
000000d: 01
000000e: 7f; section "Function" (3)000000f: 03
0000010: 02
0000011: 01
0000012: 00; WASM_BINARY_MAGIC; WASM_BINARY_VERSION; section code
; section size
; num types; func; num params; num results; i32; section code
; section size
; num functions; function 0 signature; index; section "Export" (7)0000013: 07
0000014: 07
0000015: 01
0000016: 03
0000017: 666f 6f000001a: 00
000001b: 00; section "Code" (10)000001c: 0a000001d: 06
000001e: 01; function body 0000001f: 04
0000020: 00
0000021: 410000022: 07
0000023: 0b; section code
; section size
; num exports; string length; foo ; export name; export kind
; export func index; section code
; section size
; num functions; func body size
; local decl count; i32.const; i32 literal; end

References : [1] Ch.5, Ch.6, [7], [5]Integer encoding with LEB1288bit

32bit integer

7bit splitting

8bit

8bit

8bit

00000000000000000000010010100011

0000

Adding variable bit

0000000

0000000

0001001

0100011

7bit

7bit

7bit

7bit

00001001

10100011

8bit

8bit

0x00_00_04_C3

0x09_A3(compressed)

All integers are encoded using the LEB128 variable-length integer encoding.

References : [8], [1] Ch.5, [2]4. WebAssembly instructions

4. WebAssembly instructions

Instructions

Instructions
Simple instructions

Control instructions

Block, Loop, ConditionalStackoperations
push/pop/...

Instructions fall into two main categories.
Simple instructions perform basic operations on data.
Control instructions alter control flow.
References : [1] Ch.1, Ch.2, Ch.3, Ch.4, [2], [4]4. WebAssembly instructions

Simple instructions

Numeric instructions
I64.add, I64.sub, ...

Operand stack
pop operands

operation

value bvalue avalue

Operand stack

I64.add, I64.sub, ...
operation
push result

value cvalue

Numeric instructions pop arguments from the operand stackand push results back to it.
References : [1] Ch.2, Ch.4 , [2], [4]Numeric instructions : const
I64.const n, I32.const n, ...
operation

Operand stack

push value nvalue

Operand stackvalue nvalue

The const instruction pushes the value to the stack.
References : [1] Ch.2, Ch.4 , [2], [4]Parametric instructions : drop
Operand stackdrop

pop operands

value
value
value

Operand stack

value
value

The drop instruction simply throws away a single operand.
References : [1] Ch.2, Ch.4 , [2], [4]Parametric instructions : selectOperand stack

pop operands

selectselectvalue cvalue bvalue avalue

Operand stackvalue b or cvalue

The select instruction selects one of its first two operands based onwhether its third operand is zero or not.
References : [1] Ch.2, Ch.4 , [2], [4]Global variable instructions

Operand stack

value
value
value

Globals

get_global #n0
12

global variable #0
global variable #1
global variable #2::

set_global #n

Global variable instructions get or set the values of variables.
References : [1] Ch.2, Ch.4 , [2], [4]Local variable instructions

Operand stack

value
value
value

Frame

get_local #n0
12

local variable #0
local variable #1
local variable #2::

set_local #ntee_local #n

Local variable instructions get or set the values of variables.
(including function arguments)

References : [1] Ch.2, Ch.4 , [2], [4]Memory instructions : load, store

Operand stack

value
value
value

Linear memory

load

:

store

Memory is accessed with load and store instructions for the different value types.
References : [1] Ch.2, Ch.4 , [2], [4]Memory instructions : memory.grow

Linear memory

Linear memory

memory.grow
Current
size:

Page size; 64KiB

:

Grown

The memory.grow instruction grows memory by a given delta.
The memory.grow instruction operate in units of page size (64KiB).
References : [1] Ch.2, Ch.4 , [2], [4]4. WebAssembly instructions

Control instructions

Control flow is structured

block
:
loop
block
:
end
if

:
else
:
end
end
end

:

Control flow is expressed with well-nested constructs such as blocks, loops,
and conditionals (if-else).
Structured control flow allows simpler and more efficient verification.
References : [1] Ch.2, Ch.4 , [2], [4]Structured control instructions

block constructloop construct

if construct

block

loop

if

else

end

end

end

The block, loop and if instructions are structured control instructions.

References : [1] Ch.2, Ch.4 , [2], [4]Control constructs and branch instruction

block constructloop construct

if construct

block
:
:
br 0
:
:
end

loop
:
:
:
br 0
:
end

if
br 0
:
else
:
:
end

forward jumpbackward jump

forward jump

Branches can only target control constructs.
Intuitively, a branch targeting a block or if behaves like a break statement,
while a branch targeting a loop behaves like a continue statement.
References : [1] Ch.2, Ch.4 , [2], [4]Nested constructs and branch instruction

block

block
block

br 0

br 1

br 2

br 2

end
end
end

Branches have "label" immediates.
It do not reference program positions in the instruction stream
but instead reference outer control constructs by relative nesting depth.
References : [1] Ch.2, Ch.4 , [2], [4]Conditional branch instruction

block
Operand stack
br_if
not-taken (else)taken (then)condition

value
value
value

end

The br_if instruction performs a conditional branch.

References : [1] Ch.2, Ch.4 , [2], [4]Table branch instruction

block
block
block

Operand stack

br_tablebrindexing

br

br

end
end

value
value
value

end

The br_table performs an indirect branch through an operand indexing
into the label vector.
References : [1] Ch.2, Ch.4 , [2], [4]Call instruction

Functionsfunction #0
function #1
function #2

call #n:

The call instruction invokes another function,
consuming the necessary arguments from the stack and returning
the result values of the call.
References : [1] Ch.2, Ch.4 , [2], [4]Indirect call instruction

Operand stackindexing

call_indirect

Table

Functions

element #0
element #1
element #2

function #0
function #1
function #2

:

:

value
value
value

The call_indirect instruction calls a function indirectly throughan operand indexing into a table.

References : [1] Ch.2, Ch.4 , [2], [4]Return instruction

block
block
block

return

end
end
end

The return instruction is an unconditional branch to the outermost block,which implicitly is the body of the current function.
References : [1] Ch.2, Ch.4 , [2], [4]4. WebAssembly instructions

Byte orderEndianLinear memory
01Operand stack
MSB

N+3 N+2 N+1

LSB

i32.loadN

i32.store

:

N
N+1
N+2
N+3

Byte array

:

8 bit

WebAssembly abstract machine is little endian byte order.
When a number is stored into memory, it is converted into a sequence ofbytes in little endian byte order.
References : [1] Ch. 4, [2], [4]Appendix A

Appendix A

Semantics

Validation and execution semantics
The semantics is derived from the following article:"Bringing the Web up to Speed with WebAssembly" [2]Validation semantics: typing rules

Execution semantics: reduction rules

References : [2], [1] Ch.3, Ch.4, Ch.7

Appendix B

Appendix B

Implementations

Implementations

RuntimeSpec

Binaryen

WABT

WAVM

Wasm
Text

Wasm
Text

Wasm
Text

Wasm
Text

(.wat)(.wat)(.wat)(.wat)

wasm

wasm-aswat2wasm

Go compiler

Wasm
BinaryWasm
BinaryWasm
BinaryWasm
BinaryWasm
Binary(.wasm)(.wasm)(.wasm)(.wasm)(.wasm)wasm

wasm-shell

wasm-interp

node.js

web browser

wavm-runGo

FirefoxGosourceReferences : [C1], [C2], [C3], [C4], [C5]

Reference interpreter : spec
https://github.com/WebAssembly/spec[interpreter/exec/eval.ml]
let rec step (c : config) : config =let {frame; code = vs, es; _} = c inlet e = List.hd es in
let vs', es' =match e.it, vs with| Plain e', vs ->(match e', vs with
| Unreachable, vs ->vs, [Trapping "unreachable executed" @@ e.at]| Nop, vs ->vs, []| Block (ts, es'), vs ->vs, [Label (List.length ts, [], ([], List.map plain es')) @@ e.at]| Loop (ts, es'), vs ->vs, [Label (0, [e' @@ e.at], ([], List.map plain es')) @@ e.at]| If (ts, es1, es2), I32 0l :: vs' ->vs', [Plain (Block (ts, es2)) @@ e.at]

References : [C1]

Interpreter : WABT
https://github.com/WebAssembly/wabt[src/interp/interp.cc]
Result Thread::Run(int num_instructions) {Result result = Result::Ok;
const uint8_t* istream = GetIstream();const uint8_t* pc = &istream[pc_];
for (int i = 0; i < num_instructions; ++i) {Opcode opcode = ReadOpcode(&pc);
assert(!opcode.IsInvalid());
switch (opcode) {case Opcode::Select: {uint32_t cond = Pop<uint32_t>();Value false_ = Pop();
Value true_ = Pop();CHECK_TRAP(Push(cond ? true_ : false_));break;}
case Opcode::Br:
GOTO(ReadU32(&pc));
break;
case Opcode::BrIf: {References : [C3]

Stand-alone VM : WAVM
https://github.com/WAVM/WAVM[Lib/LLVMJIT/EmitFunction.cpp]// Decode the WebAssembly opcodes and emit LLVM IR for them.
OperatorDecoderStream decoder(functionDef.code);
UnreachableOpVisitor unreachableOpVisitor(*this);
OperatorPrinter operatorPrinter(irModule, functionDef);
Uptr opIndex = 0;
while(decoder && controlStack.size()){
irBuilder.SetCurrentDebugLocation(
llvm::DILocation::get(llvmContext, (unsigned int)opIndex++,0, diFunction));if(ENABLE_LOGGING){ logOperator(decoder.decodeOpWithoutConsume(operatorPrinter)); }if(controlStack.back().isReachable) { decoder.decodeOp(*this); }else{
decoder.decodeOp(unreachableOpVisitor);}
wavmAssert(irBuilder.GetInsertBlock() == returnBlock);if(EMIT_ENTER_EXIT_HOOKS)

References : [C4]Web browser : Firefox
https://github.com/mozilla/gecko-dev[ js/src/wasm/WasmBaselineCompile.cpp]
switch (op.b0) {case uint16_t(Op::End):if (!emitEnd()) {return false;}
if (iter_.controlStackEmpty()) {if (!deadCode_) {doReturn(funcType().ret(), PopStack(false));}return iter_.readFunctionEnd(iter_.end());}
NEXT();// Control opcodes
case uint16_t(Op::Nop):
CHECK_NEXT(iter_.readNop());
case uint16_t(Op::Drop):
CHECK_NEXT(emitDrop());
case uint16_t(Op::Block):
CHECK_NEXT(emitBlock());
case uint16_t(Op::Loop):
References : [C5]Appendix B

CLI development utilities

Assemble
Assemble Wasm text format (.wat) to Wasm binary format (.wasm) :Binaryen :$ wasm-as sample.wat

WABT :$ wat2wasm sample.wat$ wat2wasm -v sample.wat

Spec :$ wasm –d sample.wat

References : [C1], [C2], [C3]

Disassemble
Disassemble Wasm binary format (.wasm) to Wasm text format (.wat)
Binaryen :$ wasm-dis sample.wasm

WABT :$ wasm2wat sample.wasm$ wasm-objdump -d sample.wasm

Spec :$ wasm –d sample.wasm

References : [C1], [C2], [C3]Desugar
Desugar Wasm text format (.wat) to Wasm text format (.wat)
WABT :$ wat-desugar sample.wat

References : [C3]

Dump information
Dump Wasm binary format (.wasm) information :WABT :$ wasm-objdump -s sample.wasm$ wasm-objdump -x sample.wasm

Spec :$ wasm –s sample.wasm

References : [C1], [C3]Run
Run Wasm binary format (.wasm) and Wasm text format (.wat) :WABT : Run Wasm binary format with trace$ wasm-interp --run-all-exports --trace sample.wasm

WAVM : Run Wasm text format$ wavm-run sample.wat

Spec : Run Wasm binary format$ wasm sample.wasm-e '(invoke “XXX”)'

References : [C1], [C3], [c4]

REPL
REPL (Read-Eval-Print-Loop) :Spec :$ wasm-$ wasm sample.wasm-

References : [C1]Appendix B

Test suiteTest suite and Wasm text format examples
https://github.com/WebAssembly/spec[test/core]
README.md
address.wastalign.wast
binary.wast
block.wast
br.wastbr_if.wast
br_table.wast
break-drop.wast
call.wast
call_indirect.wast
comments.wast
const.wast
conversions.wast
custom.wast
data.wast
elem.wast
endianness.wast
exports.wast
f32.wast
f32_bitwise.wast
f32_cmp.wast
f64.wast
f64_bitwise.wast
f64_cmp.wast

fac.wast
float_exprs.wast
float_literals.wast
float_memory.wast
float_misc.wast
forward.wast
func.wast
func_ptrs.wast
get_local.wast
globals.wast
i32.wast
i64.wast
if.wastimports.wast
inline-module.wast
int_exprs.wast
int_literals.wast
labels.wast
left-to-right.wast
linking.wast
loop.wast
memory.wast
memory_grow.wast
memory_redundancy.wast
memory_trap.wastnames.wast
nop.wast
return.wast
run.py*select.wast
set_local.wast
skip-stack-guard-page.wast
stack.wast
start.wast
store_retval.wast
switch.wast
tee_local.wast
token.wast
traps.wast
type.wast
typecheck.wast
unreachable.wast
unreached-invalid.wast
unwind.wast
utf8-custom-section-id.wast
utf8-import-field.wast
utf8-import-module.wast
utf8-invalid-encoding.wast

Note: `.wast` extension means command-script and Wasm text format.

References : [C1]Appendix B

Desugar examples

Desugar example

Text format

Text format

syntactic sugarcore syntax(func (result i32)
(i32.add(i32.const 1)(i32.const 2)))

(func (result i32)
i32.const 1
i32.const 2
i32.add)References : [7], [1] Ch.6, Ch.2, Ch.4

Desugar example

Text format

Text format

syntactic sugarcore syntax(func (result i32)
(i32.add(i32.const 1)(i32.mul(i32.const 2)(i32.const 3))))(func (result i32)
i32.const 1
i32.const 2
i32.const 3
i32.muli32.add)References : [7], [1] Ch.6, Ch.2, Ch.4

Desugar example

Text format

Text format

syntactic sugarcore syntax(func (result i32)
(block (result i32)
(i32.add(i32.const 1)(i32.const 2))))(func (result i32)
block (result i32)
i32.const 1
i32.const 2
i32.add
end)

References : [7], [1] Ch.6, Ch.2, Ch.4

Desugar example

Text format

Text format

syntactic sugarcore syntax(func(block $label_a(block $label_b
br $label_a)))

(func
block
block
br 1
end
end)

References : [7], [1] Ch.6, Ch.2, Ch.4

Desugar example

Text format

Text format

syntactic sugarcore syntax(func (result i32)
(if (result i32) (get_global 0)(then (i32.const 1))(else (i32.const 2))))(func (result i32)
get_global 0
if (result i32)
i32.const 1
else
i32.const 2
end)

References : [7], [1] Ch.6, Ch.2, Ch.4

Appendix C

FutureFuture directions* zero-cost exception, threads, SIMD
* tail call, stack switching, coroutines* garbage collectors

References : [2], [3], [4]ReferencesReferences[1]

WebAssembly Specification Release 1.0 (Draft, last updated Oct 31, 2018)https://webassembly.github.io/spec/core/[2]

Bringing the Web up to Speed with WebAssembly
https://github.com/WebAssembly/spec/blob/master/papers/pldi2017.pdf[3]

WebAssembly High-Level Goals
https://webassembly.org/docs/high-level-goals/[4]

Design Rationale
https://webassembly.org/docs/rationale/[5]

Modules
https://webassembly.org/docs/modules/[6]

MDN: WebAssembly Concepts
https://developer.mozilla.org/en-US/docs/WebAssembly/Concepts[7]

MDN: Understanding WebAssembly text format
https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format[8]

Wikipedia: LEB128
https://en.wikipedia.org/wiki/LEB128

References[C1]

spec: WebAssembly specification, reference interpreter, and test suite.
https://github.com/WebAssembly/spec[C2]

Binaryen: Compiler infrastructure and toolchain library for WebAssembly, in C++
https://github.com/WebAssembly/binaryen[C3]

WABT: The WebAssembly Binary Toolkit
https://github.com/WebAssembly/wabt[C4]

WAVM: WebAssembly Virtual Machinehttps://github.com/WAVM/WAVM[C5]

mozilla/gecko-dev (Firefox)
https://github.com/mozilla/gecko-dev

Here is the slide: https://github.com/takenobu-hs/WebAssembly-illustrated