(module $queue (type $func (;0;) (func)) (type $cont (;1;) (cont $func)) (type (;2;) (func (param i32))) (type (;3;) (func (result i32))) (type (;4;) (func (result (ref null $cont)))) (type (;5;) (func (param (ref $cont)))) (import "spectest" "print_i32" (func $log (;0;) (type 2))) (table $queue (;0;) 0 (ref null $cont)) (memory (;0;) 1) (tag $too-many-mailboxes (;0;) (type $func)) (global $qdelta (;0;) i32 i32.const 10) (global $qback-k (;1;) (mut i32) i32.const 0) (global $qfront-k (;2;) (mut i32) i32.const 0) (global $qback-mb (;3;) (mut i32) i32.const 0) (global $qfront-mb (;4;) (mut i32) i32.const 0) (export "queue-empty" (func $queue-empty-k)) (export "dequeue-k" (func $dequeue-k)) (export "enqueue-k" (func $enqueue-k)) (export "queue-empty-mb" (func $queue-empty-mb)) (export "dequeue-mb" (func $dequeue-mb)) (export "enqueue-mb" (func $enqueue-mb)) (func $queue-empty-k (;1;) (type 3) (result i32) global.get $qfront-k global.get $qback-k i32.eq ) (func $dequeue-k (;2;) (type 4) (result (ref null $cont)) (local $i i32) call $queue-empty-k if ;; label = @1 ref.null $cont return end global.get $qfront-k local.set $i local.get $i i32.const 1 i32.add global.set $qfront-k local.get $i table.get $queue ) (func $enqueue-k (;3;) (type 5) (param $k (ref $cont)) global.get $qback-k table.size $queue i32.eq if ;; label = @1 global.get $qfront-k global.get $qdelta i32.lt_u if ;; label = @2 ref.null $cont global.get $qdelta table.grow $queue drop else global.get $qback-k global.get $qfront-k i32.sub global.set $qback-k i32.const 0 global.get $qfront-k global.get $qback-k table.copy global.get $qback-k ref.null $cont global.get $qfront-k table.fill $queue i32.const 0 global.set $qfront-k end end global.get $qback-k local.get $k table.set $queue global.get $qback-k i32.const 1 i32.add global.set $qback-k ) (func $queue-empty-mb (;4;) (type 3) (result i32) global.get $qfront-mb global.get $qback-mb i32.eq ) (func $dequeue-mb (;5;) (type 3) (result i32) (local $i i32) (local $mb i32) call $queue-empty-mb if ;; label = @1 i32.const -1 return end global.get $qfront-mb local.set $i local.get $i i32.const 1 i32.add global.set $qfront-mb local.get $i i32.const 4 i32.mul i32.load local.set $mb local.get $mb return ) (func $enqueue-mb (;6;) (type 2) (param $mb i32) global.get $qback-mb i32.const 16383 i32.eq if ;; label = @1 global.get $qfront-mb global.get $qdelta i32.lt_u if ;; label = @2 throw $too-many-mailboxes else global.get $qback-mb global.get $qfront-mb i32.sub global.set $qback-mb i32.const 0 global.get $qfront-mb i32.const 4 i32.mul global.get $qback-mb i32.const 4 i32.mul memory.copy global.get $qback-mb i32.const 4 i32.mul i32.const -1 global.get $qfront-mb i32.const 4 i32.mul memory.fill i32.const 0 global.set $qfront-mb end end global.get $qback-mb i32.const 4 i32.mul local.get $mb i32.store global.get $qback-mb i32.const 1 i32.add global.set $qback-mb ) )