Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions benchmarks/wasm/wasmfx/diff_handler.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(module
(type (;0;) (func))
(type (;1;) (cont 0))
(type (;2;) (func (param i32)))
(import "spectest" "print_i32" (func (;0;) (type 2)))
(tag (;0;) (type 0))
(tag (;1;) (type 0))
(export "_start" (func 3))
(start 3)
(elem (;0;) declare func 1 2)
(func (;1;) (type 0)
suspend 0
suspend 1
)
(func (;2;) (type 0)
block ;; label = @1
block (result (ref 1)) ;; label = @2
ref.func 1
cont.new 1
resume 1 (on 0 0 (;@2;))
call 0
br 1 (;@1;)
end
i32.const 0
call 0
resume 1
end
)
(func (;3;) (type 0)
block ;; label = @1
block (result (ref 1)) ;; label = @2
ref.func 2
cont.new 1
resume 1 (on 1 0 (;@2;))
br 1 (;@1;)
end
drop
i32.const 1
call 0
end
)
)
111 changes: 111 additions & 0 deletions benchmarks/wasm/wasmfx/fun-pipes-strip.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
(module
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32) (result i32)))
(type (;2;) (cont 0))
(type (;3;) (cont 1))
(type (;4;) (func (param i32)))
(type (;5;) (func (param i32 (ref 2) (ref 3))))
(type (;6;) (func (param (ref 3) (ref 2))))
(type (;7;) (func (result i32 (ref 2))))
(type (;8;) (func (param (ref 2) (ref 3))))
(type (;9;) (func))
(import "spectest" "print_i32" (func (;0;) (type 4)))
(tag (;0;) (type 4) (param i32))
(tag (;1;) (type 0) (result i32))
(export "pipe" (func 3))
(export "run" (func 6))
(start 7)
(elem (;0;) declare func 4 5)
(func (;1;) (type 5) (param i32 (ref 2) (ref 3))
block (result (ref 3)) ;; label = @1
local.get 0
local.get 2
resume 3 (on 1 0 (;@1;))
return
end
local.set 2
local.get 2
local.get 1
return_call 2
)
(func (;2;) (type 6) (param (ref 3) (ref 2))
(local i32)
block (type 7) (result i32 (ref 2)) ;; label = @1
local.get 1
resume 2 (on 0 0 (;@1;))
return
end
local.set 1
local.set 2
local.get 2
local.get 1
local.get 0
return_call 1
)
(func (;3;) (type 8) (param (ref 2) (ref 3))
i32.const -1
local.get 0
local.get 1
call 1
)
(func (;4;) (type 1) (param i32) (result i32)
loop ;; label = @1
i32.const -1
call 0
local.get 0
call 0
local.get 0
suspend 0
i32.const 44444
call 0
local.get 0
i32.const 1
i32.add
local.set 0
br 0 (;@1;)
end
unreachable
)
(func (;5;) (type 1) (param i32) (result i32)
(local i32 i32)
i32.const 10
local.set 1
i32.const 0
local.set 2
loop ;; label = @1
local.get 2
suspend 1
i32.const 55555
call 0
i32.add
local.set 2
i32.const -2
call 0
local.get 2
call 0
local.get 1
i32.const 1
i32.sub
local.set 1
local.get 1
i32.const 0
i32.ne
br_if 0 (;@1;)
end
local.get 2
return
)
(func (;6;) (type 4) (param i32)
local.get 0
ref.func 4
cont.new 3
cont.bind 3 2
ref.func 5
cont.new 3
call 3
)
(func (;7;) (type 9)
i32.const 0
call 6
)
)
82 changes: 82 additions & 0 deletions benchmarks/wasm/wasmfx/fun-pipes.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

;; Simple pipes example (functional version)
;; modified for just a single module
(module $pipes
(type $pfun (func (result i32)))
(type $cfun (func (param i32) (result i32)))
(type $producer (cont $pfun))
(type $consumer (cont $cfun))

(start $main)

(func $log (import "spectest" "print_i32") (param i32))
(tag $send (param i32))
(tag $receive (result i32))


(func $piper (param $n i32) (param $p (ref $producer)) (param $c (ref $consumer))
(block $on-receive (result (ref $consumer))
(resume $consumer (on $receive $on-receive) (local.get $n) (local.get $c))
(return)
) ;; receive
(local.set $c)
(return_call $copiper (local.get $c) (local.get $p))
)

(func $copiper (param $c (ref $consumer)) (param $p (ref $producer))
(local $n i32)
(block $on-send (result i32 (ref $producer))
(resume $producer (on $send $on-send) (local.get $p))
(return)
) ;; send
(local.set $p)
(local.set $n)
(return_call $piper (local.get $n) (local.get $p) (local.get $c))
)

(func $pipe (export "pipe") (param $p (ref $producer)) (param $c (ref $consumer))
(call $piper (i32.const -1) (local.get $p) (local.get $c))
)

(elem declare func $nats $sum)

;; send n, n+1, ...
(func $nats (param $n i32) (result i32)
(loop $l
(call $log (i32.const -1))
(call $log (local.get $n))
(suspend $send (local.get $n))
(local.set $n (i32.add (local.get $n) (i32.const 1)))
(br $l)
)
(unreachable)
)

;; receive 10 nats and return their sum
(func $sum (param $dummy i32) (result i32)
(local $i i32)
(local $a i32)
(local.set $i (i32.const 10))
(local.set $a (i32.const 0))
(loop $l
(local.set $a (i32.add (local.get $a) (suspend $receive)))
(call $log (i32.const -2))
(call $log (local.get $a))
(local.set $i (i32.sub (local.get $i) (i32.const 1)))
(br_if $l (i32.ne (local.get $i) (i32.const 0)))
)
(return (local.get $a))
)

(func $run (export "run") (param $n i32)
(call $pipe (cont.bind $consumer $producer (local.get $n) (cont.new $consumer (ref.func $nats)))
(cont.new $consumer (ref.func $sum))
)
)
(func $main
(call $run (i32.const 0))
)

)

;; (invoke "run" (i32.const 0))
59 changes: 59 additions & 0 deletions benchmarks/wasm/wasmfx/fun-state.strip.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(module $state
(type $gf (;0;) (func (param i32) (result i32)))
(type $sf (;1;) (func (result i32)))
(type $gk (;2;) (cont $gf))
(type $sk (;3;) (cont $sf))
(type (;4;) (func (param i32)))
(type (;5;) (func (param (ref $gk) i32) (result i32)))
(type (;6;) (func (result i32 (ref $sk))))
(type (;7;) (func (param i32 (ref $sk)) (result i32)))
(tag $get (;0;) (type $sf) (result i32))
(tag $set (;1;) (type 4) (param i32))
;; (export "run" (func $run))
(export "main" (func $run))
(elem (;0;) declare func $f)
(func $getting (;0;) (type 5) (param $k (ref $gk)) (param $s i32) (result i32)
block $on_get (result (ref $gk))
block $on_set (type 6) (result i32 (ref $sk))
local.get $s
local.get $k
resume $gk (on $get $on_get) (on $set $on_set)
return
end
return_call $setting
end
local.get $s
return_call $getting
)
(func $setting (;1;) (type 7) (param $s i32) (param $k (ref $sk)) (result i32)
block $on_get (result (ref $gk))
block $on_set (type 6) (result i32 (ref $sk))
local.get $k
resume $sk (on $get $on_get) (on $set $on_set)
return
end
return_call $setting
end
local.get $s
return_call $getting
)
(func $f (;2;) (type $sf) (result i32)
i32.const 7
suspend $set
suspend $get
i32.const 2
i32.const 3
suspend $set
i32.const 3
suspend $get
i32.add
i32.mul
i32.add
)
(func $run (;3;) (type $sf) (result i32)
i32.const 0
ref.func $f
cont.new $sk
call $setting
)
)
61 changes: 61 additions & 0 deletions benchmarks/wasm/wasmfx/fun-state.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
;; Simple state example - functional with heterogeneous continuations
(module $state
(tag $get (result i32))
(tag $set (param i32))

(type $gf (func (param i32) (result i32)))
(type $sf (func (result i32)))

(type $gk (cont $gf))
(type $sk (cont $sf))

(func $getting (param $k (ref $gk)) (param $s i32) (result i32)
(block $on_get (result (ref $gk))
(block $on_set (result i32 (ref $sk))
(resume $gk (on $get $on_get) (on $set $on_set)
(local.get $s) (local.get $k)
)
(return)
) ;; $on_set (result i32 (ref $sk))
(return_call $setting)
) ;; $on_get (result (ref $gk))
(local.get $s)
(return_call $getting)
)

(func $setting (param $s i32) (param $k (ref $sk)) (result i32)
(block $on_get (result (ref $gk))
(block $on_set (result i32 (ref $sk))
(resume $sk (on $get $on_get) (on $set $on_set)
(local.get $k)
)
(return)
) ;; $on_set (result i32 (ref $sk))
(return_call $setting)
) ;; $on_get (result (ref $gk))
(local.get $s)
(return_call $getting)
)

(func $f (result i32)
(suspend $set (i32.const 7))
(i32.add
(suspend $get)
(i32.mul
(i32.const 2)
(suspend $set (i32.const 3))
(i32.add
(i32.const 3)
(suspend $get)
)
)
)
)

(elem declare func $f)
(func $run (export "run") (result i32)
(call $setting (i32.const 0) (cont.new $sk (ref.func $f)))
)
)

;; (assert_return (invoke "run") (i32.const 19))
Loading
Loading