| 1 |
(module $generator |
| 2 |
(type $gen (;0;) (func (param i64))) |
| 3 |
(type $geny (;1;) (func (param i32))) |
| 4 |
(type $cont0 (;2;) (cont $gen)) |
| 5 |
(type $cont (;3;) (cont $geny)) |
| 6 |
(type (;4;) (func (param i64) (result i32))) |
| 7 |
(type (;5;) (func (param i64 i64) (result i64))) |
| 8 |
(type (;6;) (func (param i64 (ref $cont0)) (result i64 (ref $cont)))) |
| 9 |
(type (;7;) (func (param i64 (ref $cont)))) |
| 10 |
(tag $yield (;0;) (type 4) (param i64) (result i32)) |
| 11 |
(global $hook (;0;) (mut (ref $gen)) ref.func $dummy) |
| 12 |
(export "hook" (global $hook)) |
| 13 |
(export "start" (func $gen)) |
| 14 |
(export "sum" (func 2)) |
| 15 |
(elem (;0;) declare func $gen) |
| 16 |
(func $dummy (;0;) (type $gen) (param i64)) |
| 17 |
(func $gen (;1;) (type $gen) (param $i i64) |
| 18 |
loop $l |
| 19 |
local.get $i |
| 20 |
suspend $yield |
| 21 |
br_if 1 |
| 22 |
local.get $i |
| 23 |
global.get $hook |
| 24 |
call_ref $gen |
| 25 |
local.get $i |
| 26 |
i64.const 1 |
| 27 |
i64.add |
| 28 |
local.set $i |
| 29 |
br $l |
| 30 |
end |
| 31 |
) |
| 32 |
(func (;2;) (type 5) (param $i i64) (param $j i64) (result i64) |
| 33 |
(local $sum i64) (local $n i64) (local $k (ref null $cont)) |
| 34 |
local.get $i |
| 35 |
ref.func $gen |
| 36 |
cont.new $cont0 |
| 37 |
block $on_first_yield (type 6) (param i64 (ref $cont0)) (result i64 (ref $cont)) |
| 38 |
resume $cont0 (on $yield $on_first_yield) |
| 39 |
unreachable |
| 40 |
end |
| 41 |
loop $on_yield (type 7) (param i64 (ref $cont)) |
| 42 |
local.set $k |
| 43 |
local.set $n |
| 44 |
local.get $sum |
| 45 |
local.get $n |
| 46 |
i64.add |
| 47 |
local.set $sum |
| 48 |
local.get $n |
| 49 |
local.get $j |
| 50 |
i64.eq |
| 51 |
local.get $k |
| 52 |
resume $cont (on $yield $on_yield) |
| 53 |
end |
| 54 |
local.get $sum |
| 55 |
return |
| 56 |
) |
| 57 |
) |