Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify continuations #75

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
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
38 changes: 38 additions & 0 deletions benchmarks/wasm/trycatch/throw_twice.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;; kept in delimited continuation example
(module
;; output: 1, 2, 6, 2, 3, 4, 4, 5
(type (;0;) (func (param i32)))
(type (;1;) (func))
(import "console" "log" (func (;0;) (type 0)))
(func (;1;) (type 1)
(local i32)
try
i32.const 1
call 0
block
block
i32.const 42
;; [42]
throw
i32.const 6
call 0
i32.const 42
;; [42]
throw
end
end
i32.const 3
call 0
catch
;; [42, resume]
i32.const 2
call 0
drop
resume0
i32.const 4
call 0
end
i32.const 5
call 0
)
(start 1))
38 changes: 38 additions & 0 deletions benchmarks/wasm/trycatch/throw_twice2.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;; pushed to meta continuation example
(module
;; output: 1, 2, 6, 2, 3, 4, 5
(type (;0;) (func (param i32)))
(type (;1;) (func))
(import "console" "log" (func (;0;) (type 0)))
(func (;1;) (type 1)
(local i32)
try
i32.const 1
call 0
block
block
i32.const 42
;; [42]
throw
end
i32.const 6
call 0
i32.const 42
;; [42]
throw
end
i32.const 3
call 0
catch
;; [42, resume]
i32.const 2
call 0
drop
resume0
i32.const 4 ;; |---> adk
call 0 ;; |
end
i32.const 5
call 0
)
(start 1))
36 changes: 36 additions & 0 deletions benchmarks/wasm/trycatch/try_catch_br3.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;; ignored example
(module
;; output: 1, 2, 3, 4, 5
;; 4 is printed, because the delimited continuation is kept when breaking out of the block,
;; it's inside the trail1
(type (;0;) (func (param i32)))
(type (;1;) (func))
(import "console" "log" (func (;0;) (type 0)))
(func (;1;) (type 1)
(local i32)
try
i32.const 1
call 0
block
block
i32.const 42
;; [42]
throw
br 0
end
end
i32.const 3
call 0
catch
;; [42, resume]
i32.const 2
call 0
drop
resume0
i32.const 4
call 0
end
i32.const 5
call 0
)
(start 1))
52 changes: 52 additions & 0 deletions benchmarks/wasm/trycatch/try_catch_br4.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
;; pushed to meta continuation example
(module
(type (;0;) (func (param i32)))
(type (;1;) (func))
(import "console" "log" (func (;0;) (type 0)))
(func (;1;) (type 1)
(local i32 i32)
i32.const 0
local.set 1
try
i32.const 1
call 0
block
block
i32.const 42
;; [42]
throw
end
i32.const 6
call 0
i32.const 42
;; [42]
throw
end
i32.const 3
call 0
catch
;; increment local 1
i32.const 1
local.get 1
i32.add
local.set 1
;; [42, resume]
i32.const 2
call 0
drop
local.get 1
i32.const 1
i32.eq
if (param i32 (; input cont actually ;))
resume0
else
i32.const 7
call 0
end
i32.const 4
call 0
end
i32.const 5
call 0
)
(start 1))
39 changes: 39 additions & 0 deletions benchmarks/wasm/trycatch/try_catch_catch_br.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(module
(type (;0;) (func (param i32)))
(type (;1;) (func))
(import "console" "log" (func (;0;) (type 0)))
(func (;1;) (type 1)
(local i32)
try
i32.const 1
call 0
block
i32.const 42
;; [42]
throw
br 0
i32.const 3
call 0
end
i32.const 6
call 0
catch
;; [42, resume]
drop
local.set 0 ;; abusing the type system
local.get 0 ;;
block (param i32) ;;
i32.const 2
call 0
resume0
br 0
end
i32.const 4
call 0
local.get 0
resume0
end
i32.const 5
call 0
)
(start 1))
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
)
)
4 changes: 2 additions & 2 deletions benchmarks/wasm/wasmfx/diff_resume.wast
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
(local.set $i (i32.const 10))
(block $h
(block $on_yield (result (ref $cont))
(resume $cont
(on $yield $on_yield)
(resume $cont
(on $yield $on_yield)
(local.get $i)
(local.get $k)
)
Expand Down
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
)
)
Loading
Loading