Skip to content

Commit

Permalink
wasmfx (#76)
Browse files Browse the repository at this point in the history
* implemet multi tag, found bug at suspend16 for forgetting meta-continuation

* forgor one test

* only the control flow structure for failed suspend16 test

* push wast file

* newMk doesn't work also

* push wast file

* revert nested resume

* some refactor; add test spec

* revert accidental change

* use the right remaining stack

* rebase on Dinghong's version

* check point

* refactoring

* minor refactor

* handler

* refactor eval, taking only single inst

* try catch

* rebase Dinghong's tests

* some clean up

* unify value repr for cont

* test case: throw -> resume -> throw -> no resume

* initial impl for wasmfx

* unreachable not trap

* rm redundant case

* fix call ref

* utilize trail

* wrap continuations in trail with tags

* drop tail of trail by tagid

* fix fun-state

* some progress on debugging pipes

* fix pipes

* even more nested resume

* ignore all tags in newTrail when suspend

* handler needs only a stack & remove try-catch stuff

* remove mcont

* trail compostion is different with list concat when haltK is there

* when start evaluation: store initK in brtable and haltK in trail

* comment on initK

---------

Co-authored-by: ahuoguo <[email protected]>
Co-authored-by: Guannan Wei <[email protected]>
Co-authored-by: ahuoguo <[email protected]>
  • Loading branch information
4 people authored Jan 29, 2025
1 parent 5b4f1cf commit 7aebeb5
Show file tree
Hide file tree
Showing 30 changed files with 4,198 additions and 3,228 deletions.
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
116 changes: 116 additions & 0 deletions benchmarks/wasm/wasmfx/fun-pipes-strip.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
(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)
(export "main" (func 7))
(elem (;0;) declare func 4 5)
(func (type 4) (param i32)
)

(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 3
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 1
call 6
)
)
Loading

0 comments on commit 7aebeb5

Please sign in to comment.