| 1 |
(module $scheduler |
| 2 |
(type $func (;0;) (func)) |
| 3 |
(type $cont (;1;) (cont $func)) |
| 4 |
(type (;2;) (func (param (ref $cont)))) |
| 5 |
(type (;3;) (func (result i32))) |
| 6 |
(type (;4;) (func (result (ref null $cont)))) |
| 7 |
(type (;5;) (func (param (ref null $cont)))) |
| 8 |
(type (;6;) (func (result (ref $cont) (ref $cont)))) |
| 9 |
(import "lwt" "yield" (tag $yield (;0;) (type $func))) |
| 10 |
(import "lwt" "fork" (tag $fork (;1;) (type 2) (param (ref $cont)))) |
| 11 |
(import "queue" "queue-empty" (func $queue-empty (;0;) (type 3))) |
| 12 |
(import "queue" "dequeue" (func $dequeue (;1;) (type 4))) |
| 13 |
(import "queue" "enqueue" (func $enqueue (;2;) (type 2))) |
| 14 |
(export "sync" (func $sync)) |
| 15 |
(export "kt" (func $kt)) |
| 16 |
(export "tk" (func $tk)) |
| 17 |
(export "ykt" (func $ykt)) |
| 18 |
(export "ytk" (func $ytk)) |
| 19 |
(func $sync (;3;) (type 5) (param $nextk (ref null $cont)) |
| 20 |
local.get $nextk |
| 21 |
ref.is_null |
| 22 |
if ;; label = @1 |
| 23 |
return |
| 24 |
end |
| 25 |
block $on_yield (result (ref $cont)) |
| 26 |
block $on_fork (type 6) (result (ref $cont) (ref $cont)) |
| 27 |
local.get $nextk |
| 28 |
resume $cont (on $yield $on_yield) (on $fork $on_fork) |
| 29 |
call $dequeue |
| 30 |
return_call $sync |
| 31 |
end |
| 32 |
local.set $nextk |
| 33 |
call $enqueue |
| 34 |
local.get $nextk |
| 35 |
return_call $sync |
| 36 |
end |
| 37 |
return_call $sync |
| 38 |
) |
| 39 |
(func $kt (;4;) (type 5) (param $nextk (ref null $cont)) |
| 40 |
local.get $nextk |
| 41 |
ref.is_null |
| 42 |
if ;; label = @1 |
| 43 |
return |
| 44 |
end |
| 45 |
block $on_yield (result (ref $cont)) |
| 46 |
block $on_fork (type 6) (result (ref $cont) (ref $cont)) |
| 47 |
local.get $nextk |
| 48 |
resume $cont (on $yield $on_yield) (on $fork $on_fork) |
| 49 |
call $dequeue |
| 50 |
return_call $tk |
| 51 |
end |
| 52 |
local.set $nextk |
| 53 |
call $enqueue |
| 54 |
local.get $nextk |
| 55 |
return_call $tk |
| 56 |
end |
| 57 |
call $enqueue |
| 58 |
call $dequeue |
| 59 |
return_call $tk |
| 60 |
) |
| 61 |
(func $tk (;5;) (type 5) (param $nextk (ref null $cont)) |
| 62 |
local.get $nextk |
| 63 |
ref.is_null |
| 64 |
if ;; label = @1 |
| 65 |
return |
| 66 |
end |
| 67 |
block $on_yield (result (ref $cont)) |
| 68 |
block $on_fork (type 6) (result (ref $cont) (ref $cont)) |
| 69 |
local.get $nextk |
| 70 |
resume $cont (on $yield $on_yield) (on $fork $on_fork) |
| 71 |
call $dequeue |
| 72 |
return_call $kt |
| 73 |
end |
| 74 |
call $enqueue |
| 75 |
return_call $kt |
| 76 |
end |
| 77 |
call $enqueue |
| 78 |
call $dequeue |
| 79 |
return_call $kt |
| 80 |
) |
| 81 |
(func $ykt (;6;) (type 5) (param $nextk (ref null $cont)) |
| 82 |
local.get $nextk |
| 83 |
ref.is_null |
| 84 |
if ;; label = @1 |
| 85 |
return |
| 86 |
end |
| 87 |
block $on_yield (result (ref $cont)) |
| 88 |
block $on_fork (type 6) (result (ref $cont) (ref $cont)) |
| 89 |
local.get $nextk |
| 90 |
resume $cont (on $yield $on_yield) (on $fork $on_fork) |
| 91 |
call $dequeue |
| 92 |
return_call $ykt |
| 93 |
end |
| 94 |
call $enqueue |
| 95 |
call $enqueue |
| 96 |
call $dequeue |
| 97 |
return_call $ykt |
| 98 |
end |
| 99 |
call $enqueue |
| 100 |
call $dequeue |
| 101 |
return_call $ykt |
| 102 |
) |
| 103 |
(func $ytk (;7;) (type 5) (param $nextk (ref null $cont)) |
| 104 |
(local $k (ref $cont)) |
| 105 |
local.get $nextk |
| 106 |
ref.is_null |
| 107 |
if ;; label = @1 |
| 108 |
return |
| 109 |
end |
| 110 |
block $on_yield (result (ref $cont)) |
| 111 |
block $on_fork (type 6) (result (ref $cont) (ref $cont)) |
| 112 |
local.get $nextk |
| 113 |
resume $cont (on $yield $on_yield) (on $fork $on_fork) |
| 114 |
call $dequeue |
| 115 |
return_call $ytk |
| 116 |
end |
| 117 |
local.set $k |
| 118 |
call $enqueue |
| 119 |
local.get $k |
| 120 |
call $enqueue |
| 121 |
call $dequeue |
| 122 |
return_call $ytk |
| 123 |
end |
| 124 |
call $enqueue |
| 125 |
call $dequeue |
| 126 |
return_call $ytk |
| 127 |
) |
| 128 |
) |