Parameters and results in WebAssembly
Signatures declare everything; $names alias the argument indices.
(module
;; Parameters and results are declared in the signature; $names are
;; readable aliases for their indices.
(func (export "area") (param $w i32) (param $h i32) (result i32)
(i32.mul (local.get $w) (local.get $h)))
(func (export "perimeter") (param $w i32) (param $h i32) (result i32)
(i32.mul (i32.add (local.get $w) (local.get $h)) (i32.const 2))))
How it works
(param $w i32)declares a typed parameter readable by name.local.getpushes a parameter;i32.mulconsumes two values.- Each export is independent:
areaandperimetershare nothing but style.
Keywords and builtins used here
exportfunci32moduleparamresult
The run, in numbers
- Lines
- 8
- Characters to type
- 357
- Tokens
- 80
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 74 seconds.
Step 2 of 3 in Modules, step 2 of 28 in Language basics.