typestar

call in WebAssembly

Private helpers by $name; only exports face the host.

(module
  ;; call names another function in the module; only the exported one
  ;; is visible to the host.
  (func $celsius_to_f (param $c i32) (result i32)
    (i32.add
      (i32.div_s (i32.mul (local.get $c) (i32.const 9)) (i32.const 5))
      (i32.const 32)))

  (func (export "spread_f") (param $lo_c i32) (param $hi_c i32)
        (result i32)
    (i32.sub
      (call $celsius_to_f (local.get $hi_c))
      (call $celsius_to_f (local.get $lo_c)))))

How it works

  1. $celsius_to_f has no export — it exists for the module alone.
  2. call $celsius_to_f pushes arguments first, folded style.
  3. spread_f calls it twice and subtracts the results.

Keywords and builtins used here

The run, in numbers

Lines
13
Characters to type
407
Tokens
85
Three-star pace
65 tpm

At the three-star pace of 65 tokens a minute, this run takes about 78 seconds.

Type this snippet

Step 1 of 3 in Calls, step 13 of 28 in Language basics.

← Previous Next →