Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference interpreter #84

Merged
merged 187 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
187 commits
Select commit Hold shift + click to select a range
9ef4a9b
Merge pull request #2 from effect-handlers/merge-funcref
dhil Feb 15, 2021
41d0c6e
Minimal exception handling extension
dhil Feb 14, 2021
f81d04a
Update interpreter/syntax/free.ml
dhil Feb 16, 2021
1572421
Update interpreter/text/arrange.ml
dhil Feb 16, 2021
7fe3e89
Update interpreter/text/parser.mly
dhil Feb 16, 2021
f293c24
Update interpreter/exec/eval.ml
dhil Feb 16, 2021
ad622f3
Update interpreter/exec/eval.ml
dhil Feb 16, 2021
449e176
Update interpreter/binary/encode.ml
dhil Feb 16, 2021
8e0a378
Update interpreter/exec/eval.ml
dhil Feb 16, 2021
147024b
Declare DO as a token.
dhil Feb 16, 2021
bd8a611
Add lexical rules for try/catch/do/throw.
dhil Feb 16, 2021
b0fcf75
Add a few test cases.
dhil Feb 16, 2021
62fc2d9
Implement binary encoding and decoding.
dhil Feb 16, 2021
4d2b207
Update interpreter/script/run.ml
dhil Feb 16, 2021
bc83c41
Update interpreter/script/run.ml
dhil Feb 16, 2021
5d4602a
Address @rossberg's comments.
dhil Feb 16, 2021
1b59e24
Adds missing success reduction for `catch`.
dhil Feb 16, 2021
68e69ec
Update interpreter/script/js.ml
dhil Feb 16, 2021
ce612e8
Implement events
rossberg Feb 17, 2021
ac039db
Add cont type and instructions; validation, en/decoding
rossberg Feb 18, 2021
2d7252d
Merge pull request #1 from effect-handlers/tiny-exn
dhil Feb 18, 2021
3eebbfe
Merge pull request #4 from effect-handlers/mini-exn
dhil Feb 18, 2021
c1e7772
Merge branch 'master' of github.com:effect-handlers/wasm-spec into ti…
dhil Feb 18, 2021
a6ab02b
Merge pull request #5 from effect-handlers/cont
dhil Feb 18, 2021
fdb69cc
Merge branch 'mini-exn' of github.com:effect-handlers/wasm-spec into …
dhil Feb 18, 2021
fb297a0
Typos
rossberg Feb 18, 2021
7704c23
Merge branch 'master' into cont
rossberg Feb 18, 2021
c9f369b
First semantics
rossberg Feb 18, 2021
7f092d0
Simplify
rossberg Feb 18, 2021
5e510ee
Text, simple test
rossberg Feb 19, 2021
a44c070
Missing rule
rossberg Feb 19, 2021
e10edf6
Minor grammar tweak
rossberg Feb 19, 2021
e235dac
Test exns
rossberg Feb 19, 2021
1b478ef
Scheduler example
rossberg Feb 19, 2021
8349bee
Generator example; make threads more interesting
rossberg Feb 19, 2021
34ebc19
Avoid code duplication
rossberg Feb 19, 2021
3939828
Eps
rossberg Feb 19, 2021
92fd88f
Renames; fixes; add guard instruction
rossberg Feb 20, 2021
6f1aed8
Actually invoke test
rossberg Feb 20, 2021
c3a3a3d
Unify Guarded admin instr with Handle
rossberg Feb 22, 2021
be2c1c0
Test empty handler
rossberg Feb 22, 2021
dfb8dad
Comment
rossberg Feb 22, 2021
6b0b593
Implement reduction and text format (#6)
rossberg Feb 22, 2021
f775ff5
Implement single-shot semantics
rossberg Feb 22, 2021
707dec0
Implement single-shot semantics (#7)
rossberg Feb 25, 2021
a5cacd2
Merge remote-tracking branch 'funcref/master' into single-shot
rossberg Feb 25, 2021
13aa280
Merge remote-tracking branch 'funcref/master'
rossberg Feb 25, 2021
332f4f1
Merge remote-tracking branch 'origin/master'
rossberg Feb 25, 2021
8109132
Merge remote-tracking branch 'funcref/master'
rossberg Mar 11, 2021
261d1a8
Merge remote-tracking branch 'tailcall/master'
rossberg Mar 11, 2021
ee429ef
Add cont.bind; check handler types
rossberg Apr 8, 2021
03a1e4c
Nit
rossberg Apr 8, 2021
eef1931
Fix
rossberg Apr 8, 2021
650e0f0
Add cont.bind; check handler types (#10)
rossberg Apr 8, 2021
ed01787
Merge remote-tracking branch 'upstream/master'
rossberg Apr 8, 2021
c33e8bd
Merge remote-tracking branch 'funcref/master'
rossberg Apr 8, 2021
f3ce3d2
Merge remote-tracking branch 'tailcall/master'
rossberg Apr 8, 2021
3d81921
fix cont.bind to bind arguments in the correct order (fixes #12)
slindley Apr 11, 2021
611a37e
Fix composiiton order
rossberg Apr 12, 2021
43b741d
Merge branch 'cont.bind'
slindley Apr 12, 2021
60d2c28
Examples (#8)
slindley Apr 12, 2021
ce9860d
Add overview of formal rules (#11)
rossberg Apr 15, 2021
a6c90c8
Added mvar implementation
ani003 Sep 23, 2021
e991efe
Added comments
ani003 Sep 28, 2021
5cb386e
Merge pull request #15 from ani003/mvar
dhil Oct 7, 2021
6b6f0e3
Explainer document (#14)
dhil Dec 14, 2021
6a62ed1
Revert "MVar implementation" (#17)
slindley Feb 3, 2022
069848a
update README
slindley Feb 3, 2022
57c5955
Type-indexed tags. (#18)
dhil Oct 10, 2022
f317d0b
Refactor `cont.wast` to not use `let` & `func.bind` (#24)
dhil Mar 3, 2023
eb9932a
Merge
dhil Mar 10, 2023
f4a1f12
Fix compilation errors after merge.
dhil Mar 13, 2023
9f861ea
Merge pull request #25 from dhil/wasmfx-funcref-merge
dhil Mar 17, 2023
c9e60d8
Update `resume_throw` (#26)
dhil Mar 22, 2023
5331635
Fix all examples apart from delimited control (#27)
matijapretnar Apr 10, 2023
2877ce4
Change opcode for cont (#28)
dhil Apr 10, 2023
7ad4f4b
Add type annotations to continuation instructions (#29)
dhil Apr 10, 2023
d24a9bd
Update examples to conform with the recent changes to the syntax (con…
dhil Apr 11, 2023
b7e4ed5
Add a simple and more involved generator example (#31)
matijapretnar Apr 13, 2023
dd4e5a1
Merge with WebAssembly/spec
dhil Aug 31, 2023
08de56b
Disable JS testsuite
dhil Sep 1, 2023
74a3ed3
Merge pull request #1 from dhil/wasmfx-main-sync
dhil Sep 1, 2023
0cfa5a5
Merge branch 'main' of github.com:WebAssembly/spec into wasmfx
dhil Sep 19, 2023
42228fb
Merge pull request #6 from dhil/wasmfx
dhil Sep 19, 2023
af789d0
Merge with WebAssembly/function-references
dhil Sep 21, 2023
1b8e62a
Merge branch 'main' of github.com:WebAssembly/function-references int…
dhil Sep 21, 2023
fe51e7d
Fix CI interpreter
dhil Sep 21, 2023
7fb5764
Merge pull request #7 from dhil/funcref-merge
dhil Sep 21, 2023
aa62cdd
Merge with WebAssembly/spec
dhil Sep 21, 2023
ab3bf77
Merge pull request #8 from dhil/wasmfx-main
dhil Sep 21, 2023
2250826
Merge with upstream
dhil Oct 2, 2023
4f8d8c7
Merge pull request #9 from dhil/wasmfx-merge
dhil Oct 2, 2023
7188e24
Merge branch 'main' of github.com:WebAssembly/gc into wasmfx-merge
dhil Oct 3, 2023
d7aa1d1
Expand tag types
dhil Oct 5, 2023
5e0e3f8
Fix try-catch assertion error.
dhil Oct 5, 2023
8ce5b1f
Fix remaining bugs after merge with the GC proposal.
dhil Oct 18, 2023
697ac89
Fix nit
dhil Oct 18, 2023
52ec720
Address comments
dhil Oct 18, 2023
47367c9
More tests
dhil Oct 19, 2023
c81ef89
Test for resume_throw too
dhil Oct 19, 2023
4eb38ce
Add NoContHT
dhil Oct 19, 2023
92c223d
Add contref, nullcontref, etc to the wat/wast formats
dhil Oct 20, 2023
9072739
Update opcodes again
dhil Oct 20, 2023
d13dc88
Fix opcode
dhil Oct 20, 2023
a8ffd1f
Merge pull request #10 from dhil/wasmfx-merge
dhil Oct 20, 2023
4a46a40
Merge with WebAssembly/main
dhil Oct 20, 2023
5987142
Merge branch 'main' of github.com:WebAssembly/gc into wasmfx-merge
dhil Oct 20, 2023
aa87fc8
Merge pull request #11 from dhil/wasmfx-merge
dhil Oct 20, 2023
dbc1d73
Merge with upstream
dhil Nov 13, 2023
bb16de3
Merge branch 'main' of github.com:WebAssembly/function-references int…
dhil Nov 13, 2023
c27a005
Merge with GC
dhil Nov 13, 2023
4ce0657
Merge with spec, function-references, and gc
dhil Nov 13, 2023
ab570e6
Merge pull request #12 from dhil/wasmfx-merge
dhil Nov 13, 2023
c17b4a6
Merge with WebAssembly/spec
dhil Nov 15, 2023
72b3d35
Merge branch 'main' of github.com:WebAssembly/gc into wasmfx-merge
dhil Nov 15, 2023
d55bb61
Merge pull request #13 from dhil/wasmfx-merge
dhil Nov 15, 2023
41bf3b9
Update Overview.md (#15)
dhil Dec 6, 2023
2168ade
Merge branch 'main' of github.com:WebAssembly/function-references int…
dhil Dec 6, 2023
50b8d7d
Merge branch 'main' of github.com:WebAssembly/gc into wasmfx-merge
dhil Dec 6, 2023
b77ab8d
Merge with WebAssembly/spec, WebAssembly/function-references, and Web…
dhil Dec 6, 2023
4310c76
Merge pull request #16 from dhil/wasmfx-merge
dhil Dec 6, 2023
a9ec313
Resolve wasmfx/specfx#17 (#18)
dhil Jan 25, 2024
a9e6111
Merge branch 'main' of github.com:WebAssembly/spec into wasmfx-merge
dhil Jan 25, 2024
848ebad
Merge pull request #20 from dhil/wasmfx
dhil Jan 25, 2024
b585eb9
Merge pull request #21 from dhil/wasmfx-merge
dhil Jan 25, 2024
00b7aca
Merge with WebAssembly/function-references
dhil Jan 25, 2024
6c78ed3
Merge pull request #22 from dhil/wasmfx-fr-merge
dhil Jan 25, 2024
3e3abe7
Merge with WebAssembly/gc
dhil Jan 25, 2024
e746b32
Merge pull request #23 from dhil/wasmfx-gc-merge
dhil Jan 25, 2024
c8cbfd2
Merge with WebAssembly/main
dhil Feb 12, 2024
4663060
Merge pull request #24 from dhil/wasmfx-merge
dhil Feb 12, 2024
d534658
Merge with WebAssembly/function-references
dhil Feb 12, 2024
4fb7135
Merge with WebAssembly/gc
dhil Feb 12, 2024
25a78b9
Merge pull request #25 from dhil/wasmfx-merge
dhil Feb 12, 2024
ee9cbe7
Update the instruction set descriptions in the Explainer document (#27)
dhil Feb 13, 2024
2992099
Merge branch 'main' of github.com:WebAssembly/spec into wasmfx-merge
dhil Feb 15, 2024
a33a6a0
Merge branch 'main' of github.com:WebAssembly/gc into wasmfx-merge
dhil Feb 15, 2024
0af205c
Merge pull request #28 from dhil/wasmfx-merge
dhil Feb 15, 2024
10286c8
Merge branch 'wasm-3.0+exn' of github.com:WebAssembly/spec into wasmf…
dhil Apr 12, 2024
e49a5b7
Maybe fix bikeshed error; at least silencing it for now.
dhil Apr 12, 2024
02de8d1
Disable W3C publish workflow
dhil Apr 12, 2024
b0a7c47
Merge pull request #29 from dhil/wasmfx-wasm3.0+exn
dhil Apr 12, 2024
a324dba
Fix control-lwt example (#30)
dhil Apr 12, 2024
902e33d
WasmFX documents&examples
dhil Apr 12, 2024
217ed1b
Merge with wasmfx/specfx
dhil Apr 12, 2024
79af763
Merge with WebAssembly/spec
dhil Apr 12, 2024
1638fad
Merge pull request #31 from dhil/wasmfx-merge
dhil Apr 15, 2024
a1ccfe1
Merge pull request #47 from dhil/wasmfx-ref-interp
slindley Apr 22, 2024
66279a8
Fix soundness bug with cont's runtime type
rossberg Apr 23, 2024
dda380b
Merge with upstream
dhil Apr 29, 2024
0c0fed4
Merge pull request #32 from dhil/wasmfx-merge
dhil Apr 29, 2024
e7f1553
Merge branch 'main' into wasmfx
slindley May 7, 2024
d130657
Merge branch 'main' of github.com:WebAssembly/spec into wasmfx-merge
dhil May 8, 2024
9b85d1e
Merge pull request #33 from dhil/wasmfx-merge
dhil May 8, 2024
e24d2ef
Merge branch 'wasm-3.0' of github.com:WebAssembly/spec into wasmfx-merge
dhil Jun 28, 2024
8d8b835
Merge branch 'main' of github.com:WebAssembly/spec into wasmfx-merge
dhil Jun 28, 2024
6ac6b6b
Merge pull request #34 from dhil/wasmfx-merge
dhil Jun 28, 2024
af0bf05
Merge with upstream
dhil Jul 31, 2024
41f6d1f
Merge pull request #36 from dhil/wasmfx-merge
dhil Jul 31, 2024
ca9d3c8
Merge branch 'main' of github.com:WebAssembly/spec into wasmfx-merge
dhil Jul 31, 2024
fe20aaf
Merge pull request #37 from dhil/wasmfx-merge
dhil Jul 31, 2024
2f6a9e8
Fix continuation subtyping (#38)
dhil Jul 31, 2024
3a32c7f
Resume table syntax (#39)
dhil Jul 31, 2024
221b8f1
Fix `global.set` and `table.set` for continuation references (#41)
dhil Aug 1, 2024
7b5c81f
Merge with upstream
dhil Aug 1, 2024
734608e
Merge pull request #42 from dhil/wasmfx-merge
dhil Aug 1, 2024
d1859f9
Tidy up w3c-publish workflow. (#43)
dhil Aug 1, 2024
5d57824
[spec] resume_throw should accept multiple handlers (#71)
Alan-Liang Aug 2, 2024
51ddedf
[spec] resume_throw should accept multiple handlers (#71) (#44)
dhil Aug 2, 2024
f93a379
Merge branch 'main' of github.com:WebAssembly/spec into wasmfx-merge
dhil Aug 2, 2024
6d01dfc
Merge pull request #45 from dhil/wasmfx-merge
dhil Aug 2, 2024
16c75d6
Sync with wasmfx/specfx
dhil Aug 2, 2024
66aa17a
Merge pull request #72 from WebAssembly/wasmfx-up
dhil Aug 9, 2024
6032a3f
Merge branch 'main' of github.com:WebAssembly/spec into wasmfx-merge
dhil Aug 23, 2024
ca746e0
Merge pull request #46 from dhil/wasmfx-merge
dhil Aug 23, 2024
00c6775
add validation tests
frank-emrich Aug 28, 2024
e36ffc5
Implement the switch instruction
dhil Aug 30, 2024
42aa9bd
Merge pull request #82 from dhil/wasmfx-switch
dhil Aug 30, 2024
8d8942a
Merge branch 'main' of github.com:WebAssembly/stack-switching into wa…
dhil Aug 30, 2024
9976224
[switch] the continuation should be on top of the stack. Add a furthe…
dhil Sep 17, 2024
26717a0
Merge with spec/wasm-3.0
dhil Sep 17, 2024
15060f2
Fix bug in evaluation of `resume_throw`.
dhil Sep 18, 2024
b429ba9
Remove the barrier instruction
dhil Sep 25, 2024
70086b9
[Test] Reorganise the stack switching related tests into the subfolde…
dhil Sep 25, 2024
0959c49
Gracefully exit on unhandled tag (#93)
dhil Sep 27, 2024
1d08f77
Merge branch 'main' of github.com:WebAssembly/stack-switching into wa…
dhil Sep 29, 2024
c768f15
Sync documents
dhil Sep 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-interpreter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
- name: Run tests
# TODO: reactiate node once it supports all of Wasm 3.0
# run: cd interpreter && opam exec make JS=node ci
run: cd interpreter && opam exec make ci
run: cd interpreter && opam exec make test
58 changes: 50 additions & 8 deletions interpreter/binary/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ let heap_type s =
(fun s -> VarHT (var_type s33 s));
(fun s ->
match s7 s with
| -0x0b -> NoContHT
| -0x0c -> NoExnHT
| -0x0d -> NoFuncHT
| -0x0e -> NoExternHT
Expand All @@ -192,13 +193,15 @@ let heap_type s =
| -0x15 -> StructHT
| -0x16 -> ArrayHT
| -0x17 -> ExnHT
| -0x18 -> ContHT
| _ -> error s pos "malformed heap type"
)
] s

let ref_type s =
let pos = pos s in
match s7 s with
| -0x0b -> (Null, NoContHT)
| -0x0c -> (Null, NoExnHT)
| -0x0d -> (Null, NoFuncHT)
| -0x0e -> (Null, NoExternHT)
Expand All @@ -211,6 +214,7 @@ let ref_type s =
| -0x15 -> (Null, StructHT)
| -0x16 -> (Null, ArrayHT)
| -0x17 -> (Null, ExnHT)
| -0x18 -> (Null, ContHT)
| -0x1c -> (NoNull, heap_type s)
| -0x1d -> (Null, heap_type s)
| _ -> error s pos "malformed reference type"
Expand Down Expand Up @@ -253,11 +257,15 @@ let func_type s =
let ts2 = result_type s in
FuncT (ts1, ts2)

let cont_type s =
ContT (heap_type s)

let str_type s =
match s7 s with
| -0x20 -> DefFuncT (func_type s)
| -0x21 -> DefStructT (struct_type s)
| -0x22 -> DefArrayT (array_type s)
| -0x23 -> DefContT (cont_type s) (* TODO(dhil): See comment in encode.ml *)
| _ -> error s (pos s - 1) "malformed definition type"

let sub_type s =
Expand Down Expand Up @@ -293,14 +301,15 @@ let memory_type s =
let lim = limits u32 s in
MemoryT lim

let tag_type s =
zero s;
at var s

let global_type s =
let t = val_type s in
let mut = mutability s in
GlobalT (mut, t)

let tag_type s =
zero s; at var s


(* Instructions *)

Expand Down Expand Up @@ -340,6 +349,16 @@ let locals s =
s pos "too many locals";
List.flatten (List.map (Lib.Fun.uncurry Lib.List32.make) nts)

let on_clause s =
match byte s with
| 0x00 ->
let x = at var s in
let y = at var s in
(x, OnLabel y)
| 0x01 ->
let x = at var s in
(x, OnSwitch)
| _ -> error s (pos s) "ON opcode expected"

let rec instr s =
let pos = pos s in
Expand Down Expand Up @@ -399,7 +418,10 @@ let rec instr s =
| 0x14 -> call_ref (at var s)
| 0x15 -> return_call_ref (at var s)

| 0x16 | 0x17 | 0x18 | 0x19 as b -> illegal s pos b
| (0x16 | 0x17) as b -> illegal s pos b

| 0x18 -> error s pos "misplaced DELEGATE opcode"
| 0x19 -> error s pos "misplaced CATCH_ALL opcode"

| 0x1a -> drop
| 0x1b -> select None
Expand Down Expand Up @@ -607,6 +629,26 @@ let rec instr s =
| 0xd5 -> br_on_null (at var s)
| 0xd6 -> br_on_non_null (at var s)

| 0xe0 -> cont_new (at var s)
| 0xe1 ->
let x = at var s in
let y = at var s in
cont_bind x y
| 0xe2 -> suspend (at var s)
| 0xe3 ->
let x = at var s in
let xls = vec on_clause s in
resume x xls
| 0xe4 ->
let x = at var s in
let tag = at var s in
let xls = vec on_clause s in
resume_throw x tag xls
| 0xe5 ->
let x = at var s in
let y = at var s in
switch x y

| 0xfb as b ->
(match u32 s with
| 0x00l -> struct_new (at var s)
Expand Down Expand Up @@ -971,11 +1013,11 @@ let rec instr s =
and instr_block s = List.rev (instr_block' s [])
and instr_block' s es =
match peek s with
| None | Some (0x05 | 0x0b) -> es
| None | Some (0x05 | 0x07 | 0x0b | 0x19) -> es
| _ ->
let pos = pos s in
let e' = instr s in
instr_block' s ((e' @@ region s pos pos) :: es)
instr_block' s (Source.(e' @@ region s pos pos) :: es)

and catch s =
match byte s with
Expand Down Expand Up @@ -1045,7 +1087,7 @@ let import_desc s =
| 0x01 -> TableImport (table_type s)
| 0x02 -> MemoryImport (memory_type s)
| 0x03 -> GlobalImport (global_type s)
| 0x04 -> TagImport (tag_type s)
| 0x04 -> TagImport (at var s)
| _ -> error s (pos s - 1) "malformed import kind"

let import s =
Expand Down Expand Up @@ -1106,6 +1148,7 @@ let tag_section s =
section Custom.Tag (vec (at tag)) [] s



(* Global section *)

let global s =
Expand Down Expand Up @@ -1336,7 +1379,6 @@ let module_ s =
imports; exports; elems; datas; start },
customs


let decode_custom m bs custom =
let open Source in
let Custom.{name; content; place} = custom.it in
Expand Down
48 changes: 36 additions & 12 deletions interpreter/binary/encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ struct
| NoExnHT -> s7 (-0x0c)
| ExternHT -> s7 (-0x11)
| NoExternHT -> s7 (-0x0e)
| ContHT -> s7 (-0x18)
| NoContHT -> s7 (-0x0b)
| VarHT x -> var_type s33 x
| DefHT _ | BotHT -> assert false

Expand All @@ -150,6 +152,8 @@ struct
| (Null, NoExnHT) -> s7 (-0x0c)
| (Null, ExternHT) -> s7 (-0x11)
| (Null, NoExternHT) -> s7 (-0x0e)
| (Null, ContHT) -> s7 (-0x18)
| (Null, NoContHT) -> s7 (-0x0b)
| (Null, t) -> s7 (-0x1d); heap_type t
| (NoNull, t) -> s7 (-0x1c); heap_type t

Expand Down Expand Up @@ -180,10 +184,17 @@ struct
let func_type = function
| FuncT (ts1, ts2) -> vec val_type ts1; vec val_type ts2

let cont_type = function
| ContT ht -> heap_type ht

let str_type = function
| DefStructT st -> s7 (-0x21); struct_type st
| DefArrayT at -> s7 (-0x22); array_type at
| DefFuncT ft -> s7 (-0x20); func_type ft
| DefContT ct -> s7 (-0x23); cont_type ct
(* TODO(dhil): This might need to change again in the future as a
different proposal might claim this opcode! GC proposal claimed
the previous opcode we were using. *)

let sub_type = function
| SubT (Final, [], st) -> str_type st
Expand All @@ -206,9 +217,7 @@ struct
let global_type = function
| GlobalT (mut, t) -> val_type t; mutability mut

let tag_type x =
u32 0x00l; var x

let tag_type x = u32 0x00l; var x

(* Expressions *)

Expand Down Expand Up @@ -245,6 +254,16 @@ struct
| nlocs -> (1, loc) :: nlocs
in vec local (List.fold_right combine locs [])

let on_clause (x, y) =
match y with
| OnSwitch ->
byte 0x01; var x
| OnLabel y ->
byte 0x00; var x; var y

let resumetable xls =
vec on_clause xls

let rec instr e =
match e.it with
| Unreachable -> op 0x00
Expand Down Expand Up @@ -278,6 +297,13 @@ struct
| ReturnCallRef x -> op 0x15; var x
| ReturnCallIndirect (x, y) -> op 0x13; var y; var x

| ContNew x -> op 0xe0; var x
| ContBind (x, y) -> op 0xe1; var x; var y
| Suspend x -> op 0xe2; var x
| Resume (x, xls) -> op 0xe3; var x; resumetable xls
| ResumeThrow (x, y, xls) -> op 0xe4; var x; var y; resumetable xls
| Switch (x, y) -> op 0xe5; var x; var y

| Throw x -> op 0x08; var x
| ThrowRef -> op 0x0a

Expand Down Expand Up @@ -925,7 +951,7 @@ struct
| TableImport t -> byte 0x01; table_type t
| MemoryImport t -> byte 0x02; memory_type t
| GlobalImport t -> byte 0x03; global_type t
| TagImport t -> byte 0x04; tag_type t
| TagImport t -> byte 0x04; var t

let import im =
let {module_name; item_name; idesc} = im.it in
Expand Down Expand Up @@ -966,14 +992,6 @@ struct
section 5 (vec memory) mems (mems <> [])


(* Tag section *)

let tag (t : tag) = byte 0x00; var t.it.tgtype

let tag_section ts =
section 13 (vec tag) ts (ts <> [])


(* Global section *)

let global g =
Expand All @@ -983,6 +1001,12 @@ struct
let global_section gs =
section 6 (vec global) gs (gs <> [])

(* Tag section *)
let tag tag =
tag_type tag.it.tgtype

let tag_section ts =
section 13 (vec tag) ts (ts <> [])

(* Export section *)

Expand Down
Loading
Loading