| 1 |
(module $actor-as-lwt |
| 2 |
(type $func (;0;) (func)) |
| 3 |
(type $cont (;1;) (cont $func)) |
| 4 |
(type $i-func (;2;) (func (param i32))) |
| 5 |
(type $i-cont (;3;) (cont $i-func)) |
| 6 |
(type $ic-func (;4;) (func (param i32 (ref $cont)))) |
| 7 |
(type $ic-cont (;5;) (cont $ic-func)) |
| 8 |
(type (;6;) (func (param (ref $cont)))) |
| 9 |
(type (;7;) (func (param i32) (result i32))) |
| 10 |
(type (;8;) (func (result i32))) |
| 11 |
(type (;9;) (func (param i32 i32))) |
| 12 |
(type (;10;) (func (result (ref null $cont)))) |
| 13 |
(type (;11;) (func (param (ref $cont)) (result i32))) |
| 14 |
(type (;12;) (func (result (ref $cont) (ref $i-cont)))) |
| 15 |
(type (;13;) (func (result i32 i32 (ref $cont)))) |
| 16 |
(import "spectest" "print_i32" (func $log (;0;) (type $i-func))) |
| 17 |
(import "lwt" "yield" (tag $yield (;0;) (type $func))) |
| 18 |
(import "lwt" "fork" (tag $fork (;1;) (type 6) (param (ref $cont)))) |
| 19 |
(import "mailboxes" "init" (func $init (;1;) (type $func))) |
| 20 |
(import "mailboxes" "empty-mb" (func $empty-mb (;2;) (type 7))) |
| 21 |
(import "mailboxes" "new-mb" (func $new-mb (;3;) (type 8))) |
| 22 |
(import "mailboxes" "send-to-mb" (func $send-to-mb (;4;) (type 9))) |
| 23 |
(import "mailboxes" "recv-from-mb" (func $recv-from-mb (;5;) (type 7))) |
| 24 |
(import "queue" "queue-empty" (func $queue-empty (;6;) (type 8))) |
| 25 |
(import "queue" "dequeue" (func $dequeue (;7;) (type 10))) |
| 26 |
(import "queue" "enqueue" (func $enqueue (;8;) (type 6))) |
| 27 |
(import "actor" "self" (tag $self (;2;) (type 8) (result i32))) |
| 28 |
(import "actor" "spawn" (tag $spawn (;3;) (type 11) (param (ref $cont)) (result i32))) |
| 29 |
(import "actor" "send" (tag $send (;4;) (type 9) (param i32 i32))) |
| 30 |
(import "actor" "recv" (tag $recv (;5;) (type 8) (result i32))) |
| 31 |
(export "act" (func $act)) |
| 32 |
(elem (;0;) declare func $actk) |
| 33 |
(func $actk (;9;) (type $ic-func) (param $mine i32) (param $nextk (ref $cont)) |
| 34 |
(local $ik (ref $i-cont)) (local $k (ref $cont)) (local $you (ref $cont)) (local $yours i32) |
| 35 |
loop $l |
| 36 |
block $on_self (result (ref $i-cont)) |
| 37 |
block $on_spawn (type 12) (result (ref $cont) (ref $i-cont)) |
| 38 |
block $on_send (type 13) (result i32 i32 (ref $cont)) |
| 39 |
block $on_recv (result (ref $i-cont)) |
| 40 |
local.get $nextk |
| 41 |
resume $cont (on $self $on_self) (on $spawn $on_spawn) (on $send $on_send) (on $recv $on_recv) |
| 42 |
return |
| 43 |
end |
| 44 |
local.set $ik |
| 45 |
loop $blocked |
| 46 |
local.get $mine |
| 47 |
call $empty-mb |
| 48 |
if ;; label = @6 |
| 49 |
suspend $yield |
| 50 |
br $blocked |
| 51 |
end |
| 52 |
end |
| 53 |
local.get $mine |
| 54 |
call $recv-from-mb |
| 55 |
local.get $ik |
| 56 |
cont.bind $i-cont $cont |
| 57 |
local.set $nextk |
| 58 |
br $l |
| 59 |
end |
| 60 |
local.set $k |
| 61 |
call $send-to-mb |
| 62 |
local.get $k |
| 63 |
local.set $nextk |
| 64 |
br $l |
| 65 |
end |
| 66 |
local.set $ik |
| 67 |
local.set $you |
| 68 |
call $new-mb |
| 69 |
local.set $yours |
| 70 |
local.get $yours |
| 71 |
local.get $you |
| 72 |
ref.func $actk |
| 73 |
cont.new $ic-cont |
| 74 |
cont.bind $ic-cont $cont |
| 75 |
suspend $fork |
| 76 |
local.get $yours |
| 77 |
local.get $ik |
| 78 |
cont.bind $i-cont $cont |
| 79 |
local.set $nextk |
| 80 |
br $l |
| 81 |
end |
| 82 |
local.set $ik |
| 83 |
local.get $mine |
| 84 |
local.get $ik |
| 85 |
cont.bind $i-cont $cont |
| 86 |
local.set $nextk |
| 87 |
br $l |
| 88 |
end |
| 89 |
) |
| 90 |
(func $act (;10;) (type 6) (param $k (ref $cont)) |
| 91 |
call $init |
| 92 |
call $new-mb |
| 93 |
local.get $k |
| 94 |
call $actk |
| 95 |
) |
| 96 |
) |