| 1 |
(module $queue |
| 2 |
(type $func (;0;) (func)) |
| 3 |
(type $cont (;1;) (cont $func)) |
| 4 |
(type (;2;) (func (param i32))) |
| 5 |
(type (;3;) (func (result i32))) |
| 6 |
(type (;4;) (func (result (ref null $cont)))) |
| 7 |
(type (;5;) (func (param (ref $cont)))) |
| 8 |
(import "spectest" "print_i32" (func $log (;0;) (type 2))) |
| 9 |
(table $queue (;0;) 0 (ref null $cont)) |
| 10 |
(global $qdelta (;0;) i32 i32.const 10) |
| 11 |
(global $qback (;1;) (mut i32) i32.const 0) |
| 12 |
(global $qfront (;2;) (mut i32) i32.const 0) |
| 13 |
(export "queue-empty" (func $queue-empty)) |
| 14 |
(export "dequeue" (func $dequeue)) |
| 15 |
(export "enqueue" (func $enqueue)) |
| 16 |
(func $queue-empty (;1;) (type 3) (result i32) |
| 17 |
global.get $qfront |
| 18 |
global.get $qback |
| 19 |
i32.eq |
| 20 |
) |
| 21 |
(func $dequeue (;2;) (type 4) (result (ref null $cont)) |
| 22 |
(local $i i32) |
| 23 |
call $queue-empty |
| 24 |
if ;; label = @1 |
| 25 |
ref.null $cont |
| 26 |
return |
| 27 |
end |
| 28 |
global.get $qfront |
| 29 |
local.set $i |
| 30 |
local.get $i |
| 31 |
i32.const 1 |
| 32 |
i32.add |
| 33 |
global.set $qfront |
| 34 |
local.get $i |
| 35 |
table.get $queue |
| 36 |
) |
| 37 |
(func $enqueue (;3;) (type 5) (param $k (ref $cont)) |
| 38 |
global.get $qback |
| 39 |
table.size $queue |
| 40 |
i32.eq |
| 41 |
if ;; label = @1 |
| 42 |
global.get $qfront |
| 43 |
global.get $qdelta |
| 44 |
i32.lt_u |
| 45 |
if ;; label = @2 |
| 46 |
ref.null $cont |
| 47 |
global.get $qdelta |
| 48 |
table.grow $queue |
| 49 |
drop |
| 50 |
else |
| 51 |
global.get $qback |
| 52 |
global.get $qfront |
| 53 |
i32.sub |
| 54 |
global.set $qback |
| 55 |
i32.const 0 |
| 56 |
global.get $qfront |
| 57 |
global.get $qback |
| 58 |
table.copy |
| 59 |
global.get $qback |
| 60 |
ref.null $cont |
| 61 |
global.get $qfront |
| 62 |
table.fill $queue |
| 63 |
i32.const 0 |
| 64 |
global.set $qfront |
| 65 |
end |
| 66 |
end |
| 67 |
global.get $qback |
| 68 |
local.get $k |
| 69 |
table.set $queue |
| 70 |
global.get $qback |
| 71 |
i32.const 1 |
| 72 |
i32.add |
| 73 |
global.set $qback |
| 74 |
) |
| 75 |
) |