Skip to content

Commit 4865eab

Browse files
ahuoguoGuannan Weibutterunderflow
authored
resume w/o on (#65)
* Implement testing for .bin.wast files * childish implementation of resume with only the default handler * some tests cases for resume --------- Co-authored-by: Guannan Wei <wei220@purdue.edu> Co-authored-by: butterunderflow <azhong.934@gmail.com>
1 parent 9eaad3d commit 4865eab

20 files changed

+3131
-2728
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(module definition binary
2+
"\00\61\73\6d\01\00\00\00\01\90\80\80\80\00\04\60"
3+
"\01\7f\01\7f\5d\00\60\01\7f\00\60\00\01\7f\02\96"
4+
"\80\80\80\00\01\08\73\70\65\63\74\65\73\74\09\70"
5+
"\72\69\6e\74\5f\69\33\32\00\02\03\83\80\80\80\00"
6+
"\02\00\03\07\88\80\80\80\00\01\04\6d\61\69\6e\00"
7+
"\02\09\85\80\80\80\00\01\03\00\01\01\0a\9d\80\80"
8+
"\80\00\02\87\80\80\80\00\00\20\00\41\01\6a\0b\8b"
9+
"\80\80\80\00\00\41\0a\d2\01\e0\01\e3\01\00\0b"
10+
)
11+
(module instance)
12+
(assert_return (invoke "main") (i32.const 0xb))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
(module
3+
;; Import only required for printing
4+
(import "spectest" "print_i32" (func $print_i32 (param i32)))
5+
6+
(func (param i32) (result i32)
7+
local.get 0
8+
i32.const 1
9+
i32.add
10+
)
11+
12+
(elem declare func 1)
13+
14+
(func (export "main") (result i32)
15+
i32.const 10
16+
ref.func 1
17+
cont.new 1
18+
(resume 1)
19+
)
20+
21+
(type (;0;) (func (param i32) (result i32)))
22+
(type (;1;) (cont 0))
23+
24+
)
25+
26+
(assert_return (invoke "main") (i32.const 11))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(module
2+
3+
;; Import only required for printing
4+
(import "spectest" "print_i32" (func $print_i32 (param i32)))
5+
6+
(func $process (param $x i32)
7+
(call $print_i32 (local.get $x))
8+
)
9+
10+
(func $range (param $from i32) (param $to i32)
11+
(local $i i32)
12+
(local.set $i (local.get $from))
13+
(block $b
14+
(loop $l
15+
(br_if $b (i32.gt_u (local.get $i) (local.get $to)))
16+
(call $process (local.get $i))
17+
(local.set $i (i32.add (local.get $i) (i32.const 1)))
18+
(br $l))))
19+
20+
(type $task (func (param i32)))
21+
(func $run (param $task1 (ref $task)) (param $task2 (ref $task))
22+
(call_ref $task (i32.const 10) (local.get $task1))
23+
(call_ref $task (i32.const 20) (local.get $task2)))
24+
25+
(elem declare func $task1)
26+
(elem declare func $task2)
27+
28+
(func $task1 (param $x i32) (call $range (local.get $x) (i32.const 13)))
29+
(func $task2 (param $x i32) (call $range (local.get $x) (i32.const 23)))
30+
(func $main (export "_start")
31+
(call $run (ref.func $task1) (ref.func $task2)))
32+
(start $main)
33+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(module binary
2+
"\00\61\73\6d\01\00\00\00\01\8e\80\80\80\00\04\60"
3+
"\00\00\5d\00\60\01\7f\00\60\00\01\7f\02\96\80\80"
4+
"\80\00\01\08\73\70\65\63\74\65\73\74\09\70\72\69"
5+
"\6e\74\5f\69\33\32\00\02\03\83\80\80\80\00\02\00"
6+
"\03\07\88\80\80\80\00\01\04\6d\61\69\6e\00\02\09"
7+
"\85\80\80\80\00\01\03\00\01\01\0a\9e\80\80\80\00"
8+
"\02\88\80\80\80\00\00\41\b2\f2\19\10\00\0b\8b\80"
9+
"\80\80\00\00\d2\01\e0\01\e3\01\00\41\2a\0b"
10+
)
11+
;; (module instance)
12+
(assert_return (invoke "main") (i32.const 0x2a))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(module
2+
(type $f1 (func))
3+
(type $c1 (cont $f1))
4+
(import "spectest" "print_i32" (func $print_i32 (param i32)))
5+
(func $empty
6+
i32.const 424242
7+
call $print_i32
8+
)
9+
(elem declare func $empty)
10+
(func (export "main") (result i32)
11+
(resume $c1 (cont.new $c1 (ref.func $empty)))
12+
i32.const 42
13+
)
14+
)
15+
16+
(assert_return (invoke "main") (i32.const 42))

grammar/WatLexer.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ DECLARE: 'declare' ;
271271
MODULE : 'module' ;
272272
BIN : 'binary' ;
273273
QUOTE : 'quote' ;
274+
DEFINITION : 'definition' ;
275+
INSTANCE : 'instance' ;
274276

275277
SCRIPT: 'script' ;
276278
REGISTER: 'register' ;

grammar/WatParser.g4

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ module_
435435
scriptModule
436436
: module_
437437
| LPAR MODULE VAR? (BIN | QUOTE) STRING_* RPAR
438+
| LPAR MODULE DEFINITION VAR? BIN STRING_* RPAR
438439
;
439440

440441
action_
@@ -460,6 +461,11 @@ cmd
460461
| scriptModule
461462
| LPAR REGISTER name VAR? RPAR
462463
| meta
464+
| instance
465+
;
466+
467+
instance
468+
: LPAR MODULE INSTANCE VAR? VAR? RPAR
463469
;
464470

465471
meta

src/main/java/wasm/WatLexer.java

Lines changed: 1288 additions & 1270 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)