Skip to content

Commit

Permalink
resume w/o on (#65)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: butterunderflow <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 9eaad3d commit 4865eab
Show file tree
Hide file tree
Showing 20 changed files with 3,131 additions and 2,728 deletions.
12 changes: 12 additions & 0 deletions benchmarks/wasm/wasmfx/callcont.bin.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(module definition binary
"\00\61\73\6d\01\00\00\00\01\90\80\80\80\00\04\60"
"\01\7f\01\7f\5d\00\60\01\7f\00\60\00\01\7f\02\96"
"\80\80\80\00\01\08\73\70\65\63\74\65\73\74\09\70"
"\72\69\6e\74\5f\69\33\32\00\02\03\83\80\80\80\00"
"\02\00\03\07\88\80\80\80\00\01\04\6d\61\69\6e\00"
"\02\09\85\80\80\80\00\01\03\00\01\01\0a\9d\80\80"
"\80\00\02\87\80\80\80\00\00\20\00\41\01\6a\0b\8b"
"\80\80\80\00\00\41\0a\d2\01\e0\01\e3\01\00\0b"
)
(module instance)
(assert_return (invoke "main") (i32.const 0xb))
26 changes: 26 additions & 0 deletions benchmarks/wasm/wasmfx/callcont.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

(module
;; Import only required for printing
(import "spectest" "print_i32" (func $print_i32 (param i32)))

(func (param i32) (result i32)
local.get 0
i32.const 1
i32.add
)

(elem declare func 1)

(func (export "main") (result i32)
i32.const 10
ref.func 1
cont.new 1
(resume 1)
)

(type (;0;) (func (param i32) (result i32)))
(type (;1;) (cont 0))

)

(assert_return (invoke "main") (i32.const 11))
33 changes: 33 additions & 0 deletions benchmarks/wasm/wasmfx/callref.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(module

;; Import only required for printing
(import "spectest" "print_i32" (func $print_i32 (param i32)))

(func $process (param $x i32)
(call $print_i32 (local.get $x))
)

(func $range (param $from i32) (param $to i32)
(local $i i32)
(local.set $i (local.get $from))
(block $b
(loop $l
(br_if $b (i32.gt_u (local.get $i) (local.get $to)))
(call $process (local.get $i))
(local.set $i (i32.add (local.get $i) (i32.const 1)))
(br $l))))

(type $task (func (param i32)))
(func $run (param $task1 (ref $task)) (param $task2 (ref $task))
(call_ref $task (i32.const 10) (local.get $task1))
(call_ref $task (i32.const 20) (local.get $task2)))

(elem declare func $task1)
(elem declare func $task2)

(func $task1 (param $x i32) (call $range (local.get $x) (i32.const 13)))
(func $task2 (param $x i32) (call $range (local.get $x) (i32.const 23)))
(func $main (export "_start")
(call $run (ref.func $task1) (ref.func $task2)))
(start $main)
)
12 changes: 12 additions & 0 deletions benchmarks/wasm/wasmfx/resume1.bin.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(module binary
"\00\61\73\6d\01\00\00\00\01\8e\80\80\80\00\04\60"
"\00\00\5d\00\60\01\7f\00\60\00\01\7f\02\96\80\80"
"\80\00\01\08\73\70\65\63\74\65\73\74\09\70\72\69"
"\6e\74\5f\69\33\32\00\02\03\83\80\80\80\00\02\00"
"\03\07\88\80\80\80\00\01\04\6d\61\69\6e\00\02\09"
"\85\80\80\80\00\01\03\00\01\01\0a\9e\80\80\80\00"
"\02\88\80\80\80\00\00\41\b2\f2\19\10\00\0b\8b\80"
"\80\80\00\00\d2\01\e0\01\e3\01\00\41\2a\0b"
)
;; (module instance)
(assert_return (invoke "main") (i32.const 0x2a))
16 changes: 16 additions & 0 deletions benchmarks/wasm/wasmfx/resume1.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(module
(type $f1 (func))
(type $c1 (cont $f1))
(import "spectest" "print_i32" (func $print_i32 (param i32)))
(func $empty
i32.const 424242
call $print_i32
)
(elem declare func $empty)
(func (export "main") (result i32)
(resume $c1 (cont.new $c1 (ref.func $empty)))
i32.const 42
)
)

(assert_return (invoke "main") (i32.const 42))
2 changes: 2 additions & 0 deletions grammar/WatLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ DECLARE: 'declare' ;
MODULE : 'module' ;
BIN : 'binary' ;
QUOTE : 'quote' ;
DEFINITION : 'definition' ;
INSTANCE : 'instance' ;

SCRIPT: 'script' ;
REGISTER: 'register' ;
Expand Down
6 changes: 6 additions & 0 deletions grammar/WatParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ module_
scriptModule
: module_
| LPAR MODULE VAR? (BIN | QUOTE) STRING_* RPAR
| LPAR MODULE DEFINITION VAR? BIN STRING_* RPAR
;

action_
Expand All @@ -460,6 +461,11 @@ cmd
| scriptModule
| LPAR REGISTER name VAR? RPAR
| meta
| instance
;

instance
: LPAR MODULE INSTANCE VAR? VAR? RPAR
;

meta
Expand Down
2,558 changes: 1,288 additions & 1,270 deletions src/main/java/wasm/WatLexer.java

Large diffs are not rendered by default.

Loading

0 comments on commit 4865eab

Please sign in to comment.