1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
(module
(memory 1 2)
;; import a "yield" function that receives the current value,
;; then pauses execution until it is resumed later.
(import "env" "yield" (func $yield (param i32)))
(export "memory" (memory 0))
;; simple linear progression in a loop
(func "linear" (result i32)
(local $x i32)
(loop $l
(call $yield (local.get $x))
(local.set $x
(i32.add (local.get $x) (i32.const 10))
)
(br $l)
)
)
;; exponential in a loop
(func "exponential" (result i32)
(local $x i32)
(local.set $x
(i32.const 1)
)
(loop $l
(call $yield (local.get $x))
(local.set $x
(i32.mul (local.get $x) (i32.const 2))
)
(br $l)
)
)
;; just some weird numbers, no loop
(func "weird" (result i32)
(call $yield (i32.const 42))
(call $yield (i32.const 1337))
(call $yield (i32.const 0))
(call $yield (i32.const -1000))
(call $yield (i32.const 42))
(call $yield (i32.const 314159))
(call $yield (i32.const 21828))
(unreachable)
)
)
|