Skip to content

Commit ee27d82

Browse files
committed
[stack-switching] Compression test files
1 parent bcd89b2 commit ee27d82

18 files changed

Lines changed: 571 additions & 0 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(module definition binary
2+
"\00\61\73\6d\01\00\00\00\01\94\80\80\80\00\05\60"
3+
"\00\01\7f\5d\00\60\01\7f\01\7f\5d\02\60\00\02\7f"
4+
"\63\03\03\84\80\80\80\00\03\02\00\00\0d\83\80\80"
5+
"\80\00\01\00\02\07\88\80\80\80\00\01\04\6d\61\69"
6+
"\6e\00\02\09\85\80\80\80\00\01\03\00\01\01\0a\cb"
7+
"\80\80\80\00\03\97\80\80\80\00\00\20\00\45\04\7f"
8+
"\41\00\e2\00\05\20\00\41\01\6b\10\00\41\01\6a\0b"
9+
"\0b\87\80\80\80\00\00\41\c8\01\10\00\0b\9d\80\80"
10+
"\80\00\01\01\63\03\02\04\d2\01\e0\01\e3\01\01\00"
11+
"\00\00\0f\0b\21\00\1a\41\00\20\00\e3\03\00\0b"
12+
)
13+
(module instance)
14+
(assert_return (invoke "main") (i32.const 0xc8))
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
;; Deep recursion (200-deep), suspend at base, resume.
2+
;; Tests 201 identical frames compressed/decompressed.
3+
(module
4+
(type $f_start (func (result i32)))
5+
(type $c_start (cont $f_start))
6+
(type $f_resume (func (param i32) (result i32)))
7+
(type $c_resume (cont $f_resume))
8+
(tag $ts (param i32) (result i32))
9+
10+
(func $foo (param i32) (result i32)
11+
(if (result i32) (i32.eqz (local.get 0))
12+
(then
13+
(suspend $ts (i32.const 0))
14+
)
15+
(else
16+
(i32.add
17+
(call $foo (i32.sub (local.get 0) (i32.const 1)))
18+
(i32.const 1))
19+
)
20+
)
21+
)
22+
23+
(func $start (result i32)
24+
(call $foo (i32.const 200))
25+
)
26+
(elem declare func $start)
27+
28+
;; main: catches suspension (payload=0), resumes with 0
29+
;; Each recursive frame adds 1 on return: result = 200
30+
(func (export "main") (result i32)
31+
(local $k (ref null $c_resume))
32+
(block (result i32 (ref null $c_resume))
33+
(resume $c_start (on $ts 0) (cont.new $c_start (ref.func $start)))
34+
(return)
35+
)
36+
(local.set $k)
37+
(drop) ;; drop tag payload (0)
38+
(i32.const 0)
39+
(local.get $k)
40+
(resume $c_resume)
41+
)
42+
)
43+
44+
(assert_return (invoke "main") (i32.const 200))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(module definition binary
2+
"\00\61\73\6d\01\00\00\00\01\99\80\80\80\00\06\60"
3+
"\00\01\7f\5d\00\60\01\7f\01\7f\5d\02\60\01\7c\01"
4+
"\7f\60\02\7e\7d\01\7f\03\86\80\80\80\00\05\04\05"
5+
"\02\00\00\0d\83\80\80\80\00\01\00\00\07\88\80\80"
6+
"\80\00\01\04\6d\61\69\6e\00\04\09\85\80\80\80\00"
7+
"\01\03\00\01\03\0a\d9\80\80\80\00\05\88\80\80\80"
8+
"\00\00\20\00\aa\e2\00\6a\0b\8b\80\80\80\00\00\20"
9+
"\00\b9\10\00\20\01\a8\6a\0b\90\80\80\80\00\00\20"
10+
"\00\ac\43\00\00\00\40\10\01\41\e4\00\6a\0b\86\80"
11+
"\80\80\00\00\41\05\10\02\0b\96\80\80\80\00\00\41"
12+
"\0a\02\63\03\d2\03\e0\01\e3\01\01\00\00\00\0f\0b"
13+
"\e3\03\00\0b"
14+
)
15+
(module instance)
16+
(assert_return (invoke "main") (i32.const 0x75))
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
;; 3-function chain with mixed types.
2+
;; Tests 3 heterogeneous frames with i32/i64/f32/f64.
3+
(module
4+
(type $f (func (result i32)))
5+
(type $c (cont $f))
6+
(type $fb (func (param i32) (result i32)))
7+
(type $cb (cont $fb))
8+
(tag $fetch (result i32))
9+
10+
;; func_c: suspends, gets fetched value, adds to trunc(param)
11+
(func $func_c (param f64) (result i32)
12+
(i32.add
13+
(i32.trunc_f64_s (local.get 0))
14+
(suspend $fetch))
15+
)
16+
17+
;; func_b: calls func_c with converted params, adds trunc(f32 param)
18+
(func $func_b (param i64 f32) (result i32)
19+
(i32.add
20+
(call $func_c (f64.convert_i64_s (local.get 0)))
21+
(i32.trunc_f32_s (local.get 1)))
22+
)
23+
24+
;; func_a: calls func_b, adds 100
25+
(func $func_a (param i32) (result i32)
26+
(i32.add
27+
(call $func_b (i64.extend_i32_s (local.get 0)) (f32.const 2.0))
28+
(i32.const 100))
29+
)
30+
31+
(func $start (result i32)
32+
(call $func_a (i32.const 5))
33+
)
34+
(elem declare func $start)
35+
36+
;; main: catches suspension, resumes with 10
37+
;; Result: trunc(5.0)+10=15, +trunc(2.0)=17, +100=117
38+
(func (export "main") (result i32)
39+
(i32.const 10)
40+
(block (result (ref null $cb))
41+
(resume $c (on $fetch 0) (cont.new $c (ref.func $start)))
42+
(return)
43+
)
44+
(resume $cb)
45+
)
46+
)
47+
48+
(assert_return (invoke "main") (i32.const 117))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(module definition binary
2+
"\00\61\73\6d\01\00\00\00\01\9a\80\80\80\00\05\60"
3+
"\00\01\7e\5d\00\60\01\7e\01\7e\5d\02\60\08\7f\7e"
4+
"\7d\7c\7f\7e\7d\7c\01\7e\03\84\80\80\80\00\03\04"
5+
"\00\00\0d\83\80\80\80\00\01\00\00\07\88\80\80\80"
6+
"\00\01\04\6d\61\69\6e\00\02\09\85\80\80\80\00\01"
7+
"\03\00\01\01\0a\f0\80\80\80\00\03\9f\80\80\80\00"
8+
"\00\20\00\ac\20\01\7c\20\02\ae\20\03\b0\7c\7c\20"
9+
"\04\ac\20\05\7c\20\06\ae\20\07\b0\7c\7c\7c\0b\ab"
10+
"\80\80\80\00\00\e2\00\1a\41\01\42\02\43\00\00\40"
11+
"\40\44\00\00\00\00\00\00\10\40\41\05\42\06\43\00"
12+
"\00\e0\40\44\00\00\00\00\00\00\20\40\10\00\0b\96"
13+
"\80\80\80\00\00\42\00\02\63\03\d2\01\e0\01\e3\01"
14+
"\01\00\00\00\0f\0b\e3\03\00\0b"
15+
)
16+
(module instance)
17+
(assert_return (invoke "main") (i64.const 0x24))
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;; 8 parameters of mixed types.
2+
;; Tests frame with 8 mixed-type values packed in compression.
3+
(module
4+
(type $f (func (result i64)))
5+
(type $c (cont $f))
6+
(type $fb (func (param i64) (result i64)))
7+
(type $cb (cont $fb))
8+
(tag $ts (result i64))
9+
10+
(func $top (param i32 i64 f32 f64 i32 i64 f32 f64) (result i64)
11+
(i64.add
12+
(i64.add
13+
(i64.add (i64.extend_i32_s (local.get 0)) (local.get 1))
14+
(i64.add (i64.trunc_f32_s (local.get 2)) (i64.trunc_f64_s (local.get 3))))
15+
(i64.add
16+
(i64.add (i64.extend_i32_s (local.get 4)) (local.get 5))
17+
(i64.add (i64.trunc_f32_s (local.get 6)) (i64.trunc_f64_s (local.get 7)))))
18+
)
19+
20+
(func $bot (result i64)
21+
(suspend $ts)
22+
(drop)
23+
(call $top
24+
(i32.const 1) (i64.const 2) (f32.const 3.0) (f64.const 4.0)
25+
(i32.const 5) (i64.const 6) (f32.const 7.0) (f64.const 8.0))
26+
)
27+
(elem declare func $bot)
28+
29+
;; main: catches suspension, resumes; result = 1+2+3+4+5+6+7+8 = 36
30+
(func (export "main") (result i64)
31+
(i64.const 0)
32+
(block (result (ref null $cb))
33+
(resume $c (on $ts 0) (cont.new $c (ref.func $bot)))
34+
(return)
35+
)
36+
(resume $cb)
37+
)
38+
)
39+
40+
(assert_return (invoke "main") (i64.const 36))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(module definition binary
2+
"\00\61\73\6d\01\00\00\00\01\94\80\80\80\00\05\60"
3+
"\00\01\7f\5d\00\60\01\7f\01\7f\5d\02\60\00\02\7f"
4+
"\63\03\03\83\80\80\80\00\02\00\00\0d\83\80\80\80"
5+
"\00\01\00\02\07\88\80\80\80\00\01\04\6d\61\69\6e"
6+
"\00\01\09\85\80\80\80\00\01\03\00\01\00\0a\f1\80"
7+
"\80\80\00\02\a7\80\80\80\00\01\01\7f\41\01\41\01"
8+
"\e2\00\6a\21\00\20\00\20\00\41\01\6a\e2\00\6a\21"
9+
"\00\20\00\20\00\41\01\6a\e2\00\6a\21\00\20\00\0b"
10+
"\bf\80\80\80\00\01\01\63\03\02\04\d2\00\e0\01\e3"
11+
"\01\01\00\00\00\0f\0b\21\00\1a\02\04\41\0a\20\00"
12+
"\e3\03\01\00\00\00\0f\0b\21\00\1a\02\04\41\14\20"
13+
"\00\e3\03\01\00\00\00\0f\0b\21\00\1a\41\03\20\00"
14+
"\e3\03\00\0b"
15+
)
16+
(module instance)
17+
(assert_return (invoke "main") (i32.const 0x22))
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
;; Triple suspend/resume on same continuation.
2+
;; Tests repeated compress/decompress cycles, varying PC each time.
3+
;; Flow: yield(1)->10, yield(12)->20, yield(32)->3, return 34
4+
(module
5+
(type $f (func (result i32)))
6+
(type $c (cont $f))
7+
(type $fb (func (param i32) (result i32)))
8+
(type $cb (cont $fb))
9+
(tag $yield (param i32) (result i32))
10+
11+
(func $worker (result i32)
12+
(local $acc i32)
13+
;; yield 1, receive 10: acc = 1 + 10 = 11
14+
(local.set $acc (i32.add (i32.const 1) (suspend $yield (i32.const 1))))
15+
;; yield 12, receive 20: acc = 11 + 20 = 31
16+
(local.set $acc (i32.add (local.get $acc)
17+
(suspend $yield (i32.add (local.get $acc) (i32.const 1)))))
18+
;; yield 32, receive 3: acc = 31 + 3 = 34
19+
(local.set $acc (i32.add (local.get $acc)
20+
(suspend $yield (i32.add (local.get $acc) (i32.const 1)))))
21+
(local.get $acc)
22+
)
23+
(elem declare func $worker)
24+
25+
(func (export "main") (result i32)
26+
(local $k (ref null $cb))
27+
;; Start worker, catch first yield (value 1)
28+
(block (result i32 (ref null $cb))
29+
(resume $c (on $yield 0) (cont.new $c (ref.func $worker)))
30+
(return)
31+
)
32+
(local.set $k)
33+
(drop)
34+
;; Resume with 10, catch second yield (value 12)
35+
(block (result i32 (ref null $cb))
36+
(resume $cb (on $yield 0) (i32.const 10) (local.get $k))
37+
(return)
38+
)
39+
(local.set $k)
40+
(drop)
41+
;; Resume with 20, catch third yield (value 32)
42+
(block (result i32 (ref null $cb))
43+
(resume $cb (on $yield 0) (i32.const 20) (local.get $k))
44+
(return)
45+
)
46+
(local.set $k)
47+
(drop)
48+
;; Final resume with 3, worker returns 34
49+
(i32.const 3)
50+
(local.get $k)
51+
(resume $cb)
52+
)
53+
)
54+
55+
(assert_return (invoke "main") (i32.const 34))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(module definition binary
2+
"\00\61\73\6d\01\00\00\00\01\96\80\80\80\00\05\60"
3+
"\00\03\7f\7e\7d\5d\00\60\01\7f\03\7f\7e\7d\5d\02"
4+
"\60\00\01\7f\03\84\80\80\80\00\03\02\00\00\0d\83"
5+
"\80\80\80\00\01\00\04\07\88\80\80\80\00\01\04\6d"
6+
"\61\69\6e\00\02\09\85\80\80\80\00\01\03\00\01\01"
7+
"\0a\c6\80\80\80\00\03\99\80\80\80\00\01\01\7f\e2"
8+
"\00\21\01\20\00\20\01\6a\20\00\41\02\6c\ac\20\00"
9+
"\41\01\6a\b2\0b\86\80\80\80\00\00\41\05\10\00\0b"
10+
"\97\80\80\80\00\00\41\e4\00\02\63\03\d2\01\e0\01"
11+
"\e3\01\01\00\00\00\0f\0b\e3\03\00\0b"
12+
)
13+
(module instance)
14+
(assert_return
15+
(invoke "main")
16+
(i32.const 0x69)
17+
(i64.const 0xa)
18+
(f32.const 0x1.8p+2)
19+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
;; Multi-value return (i32, i64, f32) through suspended stack.
2+
(module
3+
(type $f (func (result i32 i64 f32)))
4+
(type $c (cont $f))
5+
(type $fb (func (param i32) (result i32 i64 f32)))
6+
(type $cb (cont $fb))
7+
(tag $ts (result i32))
8+
9+
(func $compute (param i32) (result i32 i64 f32)
10+
(local $received i32)
11+
(local.set $received (suspend $ts))
12+
;; return (param + received, i64(param * 2), f32(param + 1))
13+
(i32.add (local.get 0) (local.get $received))
14+
(i64.extend_i32_s (i32.mul (local.get 0) (i32.const 2)))
15+
(f32.convert_i32_s (i32.add (local.get 0) (i32.const 1)))
16+
)
17+
18+
(func $start (result i32 i64 f32)
19+
(call $compute (i32.const 5))
20+
)
21+
(elem declare func $start)
22+
23+
;; main: catches suspension, resumes with 100
24+
;; With input 5: returns (5+100=105, i64(5*2)=10, f32(5+1)=6.0)
25+
(func (export "main") (result i32 i64 f32)
26+
(i32.const 100)
27+
(block (result (ref null $cb))
28+
(resume $c (on $ts 0) (cont.new $c (ref.func $start)))
29+
(return)
30+
)
31+
(resume $cb)
32+
)
33+
)
34+
35+
(assert_return (invoke "main") (i32.const 105) (i64.const 10) (f32.const 6.0))

0 commit comments

Comments
 (0)