The module shape in WebAssembly
The smallest WebAssembly text: one module, one exported function.
;; Everything lives in one s-expression: a module of declarations.
(module
;; Export a function under the name the host will call.
(func (export "answer") (result i32)
i32.const 42))
How it works
- Everything is an s-expression;
(module ...)wraps the whole program. (func (export "answer") ...)names the function for the host.(result i32)types the return;i32.const 42pushes it.
Keywords and builtins used here
exportfunci32moduleresult
The run, in numbers
- Lines
- 5
- Characters to type
- 182
- Tokens
- 20
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 17 seconds.
Step 1 of 3 in Modules, step 1 of 28 in Language basics.