typestar

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

  1. (param $w i32) declares a typed parameter readable by name.
  2. local.get pushes a parameter; i32.mul consumes two values.
  3. Each export is independent: area and perimeter share nothing but style.

Keywords and builtins used here

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.

Type this snippet

Step 2 of 3 in Modules, step 2 of 28 in Language basics.

← Previous Next →