Skip to content

Commit 28b6ad0

Browse files
authored
basic parsing support for wasmfx (#63)
1 parent d636e17 commit 28b6ad0

File tree

204 files changed

+7037
-2837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+7037
-2837
lines changed

benchmarks/wasm/wasmfx/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Tests for wasmfx
2+
3+
Shorter tests: https://github.com/titzer/wizard-engine/tree/master/test/regress/ext:stack-switching
4+
5+
Wasm reference interpreter tests: https://github.com/WebAssembly/stack-switching/blob/wasmfx/test/core/stack-switching/cont.wast
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(module
2+
(type (;0;) (func (param i32)))
3+
(type (;1;) (func (param i64)))
4+
(type (;2;) (func (param f32)))
5+
(type (;3;) (func (param f64)))
6+
(type (;4;) (cont 0))
7+
(type (;5;) (cont 1))
8+
(type (;6;) (cont 2))
9+
(type (;7;) (cont 3))
10+
(tag (;0;) (type 0) (param i32))
11+
)

benchmarks/wasm/wasmfx/cont1.wat

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
;; Check that continuations can be made from all basic primitives types
2+
(module
3+
(type $func1 (func (param i32)))
4+
(type $func2 (func (param i64)))
5+
(type $func3 (func (param f32)))
6+
(type $func4 (func (param f64)))
7+
(type $cont1 (cont $func1))
8+
(type $cont2 (cont $func2))
9+
(type $cont3 (cont $func3))
10+
(type $cont4 (cont $func4))
11+
(tag $tag1 (param i32))
12+
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(module
2+
(type (;0;) (func))
3+
(type (;1;) (cont 0))
4+
(type (;2;) (func (param i32)))
5+
(type (;3;) (func (result i32 (ref 1))))
6+
(import "spectest" "print_i32" (func (;0;) (type 2)))
7+
(tag (;0;) (type 2) (param i32))
8+
(start 2)
9+
(elem (;0;) declare func 1)
10+
(func (;1;) (type 0)
11+
(local i32)
12+
i32.const 100
13+
local.set 0
14+
loop ;; label = @1
15+
local.get 0
16+
suspend 0
17+
local.get 0
18+
i32.const 1
19+
i32.sub
20+
local.tee 0
21+
br_if 0 (;@1;)
22+
end
23+
)
24+
(func (;2;) (type 0)
25+
(local (ref 1))
26+
ref.func 1
27+
cont.new 1
28+
local.set 0
29+
loop ;; label = @1
30+
block (type 3) (result i32 (ref 1)) ;; label = @2
31+
local.get 0
32+
resume 1 (on 0 0 (;@2;))
33+
return
34+
end
35+
local.set 0
36+
call 0
37+
br 0 (;@1;)
38+
end
39+
)
40+
)

benchmarks/wasm/wasmfx/gen.wat

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
(module $generator
2+
(type $ft (func))
3+
;; Types of continuations used by the generator:
4+
;; No need for param or result types: No data passed back to the
5+
;; generator when resuming it, and $generator function has no return
6+
;; values.
7+
(type $ct (cont $ft))
8+
(func $print (import "spectest" "print_i32") (param i32))
9+
10+
;; Tag used to coordinate between generator and consumer: The i32 param
11+
;; corresponds to the generated values passed; no values passed back from
12+
;; generator to consumer.
13+
(tag $gen (param i32))
14+
15+
;; Simple generator yielding values from 100 down to 1
16+
(func $generator
17+
(local $i i32)
18+
(local.set $i (i32.const 100))
19+
(loop $l
20+
;; Suspend execution, pass current value of $i to consumer
21+
(suspend $gen (local.get $i))
22+
;; Decrement $i and exit loop once $i reaches 0
23+
(local.tee $i (i32.sub (local.get $i) (i32.const 1)))
24+
(br_if $l)
25+
)
26+
)
27+
(elem declare func $generator)
28+
29+
(func $consumer
30+
(local $c (ref $ct))
31+
;; Create continuation executing function $generator.
32+
;; Execution only starts when resumed for the first time.
33+
(local.set $c (cont.new $ct (ref.func $generator)))
34+
35+
(loop $loop
36+
(block $on_gen (result i32 (ref $ct))
37+
;; Resume continuation $c
38+
(resume $ct (on $gen $on_gen) (local.get $c))
39+
;; $generator returned: no more data
40+
(return)
41+
)
42+
;; Generator suspended, stack now contains [i32 (ref $ct)]
43+
;; Save continuation to resume it in the next iteration
44+
(local.set $c)
45+
;; Stack now contains the i32 value produced by $generator
46+
(call $print)
47+
48+
(br $loop)
49+
)
50+
)
51+
(start $consumer)
52+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
- typechecking tests
2+
- cont.new
3+
- resume
4+
- resume_throw
5+
- suspend
6+
- handlers
7+
- cont.bind
8+
- passing parameters of GC types
9+
- order of arguments to resumes
10+
- more chains of resumes
11+
- more matching of tags for a suspend
12+
- suspends
13+
- nested suspends
14+
- throwing + catching on another stack
15+
- repeat all exception handling tests and systematically split the stacks?
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
SOURCE="${BASH_SOURCE[0]}"
4+
while [ -h "$SOURCE" ]; do
5+
HERE="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
6+
SOURCE="$(readlink "$SOURCE")"
7+
[[ $SOURCE != /* ]] && SOURCE="$HERE/$SOURCE"
8+
done
9+
HERE="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
10+
11+
cd $HERE
12+
13+
export WIZENG_LOC=$(cd $HERE/../../../ && pwd)
14+
export SPEC_LOC=${SPEC_LOC:=$(cd $WIZENG_LOC/wasm-spec/repos/stack-switching && pwd)}
15+
16+
if [ ! -d $SPEC_LOC ]; then
17+
echo "WebAssembly specification repo not found: $SPEC_LOC"
18+
exit 1
19+
fi
20+
21+
../build.sh "$@"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(module definition binary
2+
"\00\61\73\6d\01\00\00\00\01\99\80\80\80\00\08\60"
3+
"\00\00\60\01\7f\00\60\00\01\7f\60\01\7f\01\7f\5d"
4+
"\00\5d\01\5d\02\5d\03"
5+
)
6+
(module instance)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(module
2+
(type $f1 (func))
3+
(type $f2 (func (param i32)))
4+
(type $f3 (func (result i32)))
5+
(type $f4 (func (param i32) (result i32)))
6+
(type $c1 (cont $f1))
7+
(type $c2 (cont $f2))
8+
(type $c3 (cont $f3))
9+
(type $c4 (cont $f4))
10+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(module definition binary
2+
"\00\61\73\6d\01\00\00\00\01\9f\80\80\80\00\0a\60"
3+
"\01\7f\00\60\01\7e\00\60\01\7d\00\60\01\7c\00\60"
4+
"\01\7b\00\5d\00\5d\01\5d\02\5d\03\5d\04"
5+
)
6+
(module instance)

0 commit comments

Comments
 (0)