Skip to content

Commit 7aebeb5

Browse files
butterunderflowahuoguoGuannan Wei
authored
wasmfx (#76)
* 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 <ahuoguo@gmail.com> Co-authored-by: Guannan Wei <wei220@purdue.edu> Co-authored-by: ahuoguo <52595524+ahuoguo@users.noreply.github.com>
1 parent 5b4f1cf commit 7aebeb5

30 files changed

+4198
-3228
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
;; kept in delimited continuation example
2+
(module
3+
;; output: 1, 2, 6, 2, 3, 4, 4, 5
4+
(type (;0;) (func (param i32)))
5+
(type (;1;) (func))
6+
(import "console" "log" (func (;0;) (type 0)))
7+
(func (;1;) (type 1)
8+
(local i32)
9+
try
10+
i32.const 1
11+
call 0
12+
block
13+
block
14+
i32.const 42
15+
;; [42]
16+
throw
17+
i32.const 6
18+
call 0
19+
i32.const 42
20+
;; [42]
21+
throw
22+
end
23+
end
24+
i32.const 3
25+
call 0
26+
catch
27+
;; [42, resume]
28+
i32.const 2
29+
call 0
30+
drop
31+
resume0
32+
i32.const 4
33+
call 0
34+
end
35+
i32.const 5
36+
call 0
37+
)
38+
(start 1))
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
;; pushed to meta continuation example
2+
(module
3+
;; output: 1, 2, 6, 2, 3, 4, 5
4+
(type (;0;) (func (param i32)))
5+
(type (;1;) (func))
6+
(import "console" "log" (func (;0;) (type 0)))
7+
(func (;1;) (type 1)
8+
(local i32)
9+
try
10+
i32.const 1
11+
call 0
12+
block
13+
block
14+
i32.const 42
15+
;; [42]
16+
throw
17+
end
18+
i32.const 6
19+
call 0
20+
i32.const 42
21+
;; [42]
22+
throw
23+
end
24+
i32.const 3
25+
call 0
26+
catch
27+
;; [42, resume]
28+
i32.const 2
29+
call 0
30+
drop
31+
resume0
32+
i32.const 4 ;; |---> adk
33+
call 0 ;; |
34+
end
35+
i32.const 5
36+
call 0
37+
)
38+
(start 1))
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
;; ignored example
2+
(module
3+
;; output: 1, 2, 3, 4, 5
4+
;; 4 is printed, because the delimited continuation is kept when breaking out of the block,
5+
;; it's inside the trail1
6+
(type (;0;) (func (param i32)))
7+
(type (;1;) (func))
8+
(import "console" "log" (func (;0;) (type 0)))
9+
(func (;1;) (type 1)
10+
(local i32)
11+
try
12+
i32.const 1
13+
call 0
14+
block
15+
block
16+
i32.const 42
17+
;; [42]
18+
throw
19+
br 0
20+
end
21+
end
22+
i32.const 3
23+
call 0
24+
catch
25+
;; [42, resume]
26+
i32.const 2
27+
call 0
28+
drop
29+
resume0
30+
i32.const 4
31+
call 0
32+
end
33+
i32.const 5
34+
call 0
35+
)
36+
(start 1))
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
;; pushed to meta continuation example
2+
(module
3+
(type (;0;) (func (param i32)))
4+
(type (;1;) (func))
5+
(import "console" "log" (func (;0;) (type 0)))
6+
(func (;1;) (type 1)
7+
(local i32 i32)
8+
i32.const 0
9+
local.set 1
10+
try
11+
i32.const 1
12+
call 0
13+
block
14+
block
15+
i32.const 42
16+
;; [42]
17+
throw
18+
end
19+
i32.const 6
20+
call 0
21+
i32.const 42
22+
;; [42]
23+
throw
24+
end
25+
i32.const 3
26+
call 0
27+
catch
28+
;; increment local 1
29+
i32.const 1
30+
local.get 1
31+
i32.add
32+
local.set 1
33+
;; [42, resume]
34+
i32.const 2
35+
call 0
36+
drop
37+
local.get 1
38+
i32.const 1
39+
i32.eq
40+
if (param i32 (; input cont actually ;))
41+
resume0
42+
else
43+
i32.const 7
44+
call 0
45+
end
46+
i32.const 4
47+
call 0
48+
end
49+
i32.const 5
50+
call 0
51+
)
52+
(start 1))
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(module
2+
(type (;0;) (func (param i32)))
3+
(type (;1;) (func))
4+
(import "console" "log" (func (;0;) (type 0)))
5+
(func (;1;) (type 1)
6+
(local i32)
7+
try
8+
i32.const 1
9+
call 0
10+
block
11+
i32.const 42
12+
;; [42]
13+
throw
14+
br 0
15+
i32.const 3
16+
call 0
17+
end
18+
i32.const 6
19+
call 0
20+
catch
21+
;; [42, resume]
22+
drop
23+
local.set 0 ;; abusing the type system
24+
local.get 0 ;;
25+
block (param i32) ;;
26+
i32.const 2
27+
call 0
28+
resume0
29+
br 0
30+
end
31+
i32.const 4
32+
call 0
33+
local.get 0
34+
resume0
35+
end
36+
i32.const 5
37+
call 0
38+
)
39+
(start 1))
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(module
2+
(type (;0;) (func))
3+
(type (;1;) (cont 0))
4+
(type (;2;) (func (param i32)))
5+
(import "spectest" "print_i32" (func (;0;) (type 2)))
6+
(tag (;0;) (type 0))
7+
(tag (;1;) (type 0))
8+
(export "_start" (func 3))
9+
(start 3)
10+
(elem (;0;) declare func 1 2)
11+
(func (;1;) (type 0)
12+
suspend 0
13+
suspend 1
14+
)
15+
(func (;2;) (type 0)
16+
block ;; label = @1
17+
block (result (ref 1)) ;; label = @2
18+
ref.func 1
19+
cont.new 1
20+
resume 1 (on 0 0 (;@2;))
21+
call 0
22+
br 1 (;@1;)
23+
end
24+
i32.const 0
25+
call 0
26+
resume 1
27+
end
28+
)
29+
(func (;3;) (type 0)
30+
block ;; label = @1
31+
block (result (ref 1)) ;; label = @2
32+
ref.func 2
33+
cont.new 1
34+
resume 1 (on 1 0 (;@2;))
35+
br 1 (;@1;)
36+
end
37+
drop
38+
i32.const 1
39+
call 0
40+
end
41+
)
42+
)

benchmarks/wasm/wasmfx/diff_resume.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
(local.set $i (i32.const 10))
2020
(block $h
2121
(block $on_yield (result (ref $cont))
22-
(resume $cont
23-
(on $yield $on_yield)
22+
(resume $cont
23+
(on $yield $on_yield)
2424
(local.get $i)
2525
(local.get $k)
2626
)
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
(module
2+
(type (;0;) (func (result i32)))
3+
(type (;1;) (func (param i32) (result i32)))
4+
(type (;2;) (cont 0))
5+
(type (;3;) (cont 1))
6+
(type (;4;) (func (param i32)))
7+
(type (;5;) (func (param i32 (ref 2) (ref 3))))
8+
(type (;6;) (func (param (ref 3) (ref 2))))
9+
(type (;7;) (func (result i32 (ref 2))))
10+
(type (;8;) (func (param (ref 2) (ref 3))))
11+
(type (;9;) (func))
12+
;; (import "spectest" "print_i32" (func (;0;) (type 4)))
13+
14+
(tag (;0;) (type 4) (param i32))
15+
(tag (;1;) (type 0) (result i32))
16+
(export "pipe" (func 3))
17+
(export "run" (func 6))
18+
(start 7)
19+
(export "main" (func 7))
20+
(elem (;0;) declare func 4 5)
21+
(func (type 4) (param i32)
22+
)
23+
24+
(func (;1;) (type 5) (param i32 (ref 2) (ref 3))
25+
block (result (ref 3)) ;; label = @1
26+
local.get 0
27+
local.get 2
28+
resume 3 (on 1 0 (;@1;))
29+
return
30+
end
31+
local.set 2
32+
local.get 2
33+
local.get 1
34+
return_call 2
35+
)
36+
(func (;2;) (type 6) (param (ref 3) (ref 2))
37+
(local i32)
38+
block (type 7) (result i32 (ref 2)) ;; label = @1
39+
local.get 1
40+
resume 2 (on 0 0 (;@1;))
41+
return
42+
end
43+
local.set 1
44+
local.set 2
45+
local.get 2
46+
local.get 1
47+
local.get 0
48+
return_call 1
49+
)
50+
(func (;3;) (type 8) (param (ref 2) (ref 3))
51+
i32.const -1
52+
local.get 0
53+
local.get 1
54+
call 1
55+
)
56+
(func (;4;) (type 1) (param i32) (result i32)
57+
loop ;; label = @1
58+
i32.const -1
59+
call 0
60+
local.get 0
61+
call 0
62+
local.get 0
63+
suspend 0
64+
i32.const 44444
65+
call 0
66+
local.get 0
67+
i32.const 1
68+
i32.add
69+
local.set 0
70+
br 0 (;@1;)
71+
end
72+
unreachable
73+
)
74+
(func (;5;) (type 1) (param i32) (result i32)
75+
(local i32 i32)
76+
i32.const 3
77+
local.set 1
78+
i32.const 0
79+
local.set 2
80+
loop ;; label = @1
81+
local.get 2
82+
suspend 1
83+
i32.const 55555
84+
call 0
85+
i32.add
86+
local.set 2
87+
i32.const -2
88+
call 0
89+
local.get 2
90+
call 0
91+
local.get 1
92+
i32.const 1
93+
i32.sub
94+
local.set 1
95+
local.get 1
96+
i32.const 0
97+
i32.ne
98+
br_if 0 (;@1;)
99+
end
100+
local.get 2
101+
return
102+
)
103+
(func (;6;) (type 4) (param i32)
104+
local.get 0
105+
ref.func 4
106+
cont.new 3
107+
cont.bind 3 2
108+
ref.func 5
109+
cont.new 3
110+
call 3
111+
)
112+
(func (;7;) (type 9)
113+
i32.const 1
114+
call 6
115+
)
116+
)

0 commit comments

Comments
 (0)