Skip to content

Commit 8107e01

Browse files
committed
Merge branch 'funcref'
2 parents 404e79f + 4c02753 commit 8107e01

File tree

21 files changed

+187
-162
lines changed

21 files changed

+187
-162
lines changed

document/core/exec/instructions.rst

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,31 +1836,31 @@ Most other vector instructions are defined in terms of numeric operators that ar
18361836

18371837
1. Assert: due to :ref:`validation <valid-vec-replace_lane>`, :math:`x < \dim(\shape)`.
18381838

1839-
2. Let :math:`t_1` be the type :math:`\unpacked(\shape)`.
1839+
2. Let :math:`t_2` be the type :math:`\unpacked(\shape)`.
18401840

18411841
3. Assert: due to :ref:`validation <valid-vec-replace_lane>`, a value of :ref:`value type <syntax-valtype>` :math:`t_1` is on the top of the stack.
18421842

1843-
4. Pop the value :math:`t_1.\CONST~c_1` from the stack.
1843+
4. Pop the value :math:`t_2.\CONST~c_2` from the stack.
18441844

18451845
5. Assert: due to :ref:`validation <valid-vec-replace_lane>`, a value of :ref:`value type <syntax-valtype>` |V128| is on the top of the stack.
18461846

1847-
6. Pop the value :math:`\V128.\VCONST~c_2` from the stack.
1847+
6. Pop the value :math:`\V128.\VCONST~c_1` from the stack.
18481848

1849-
7. Let :math:`i^\ast` be the result of computing :math:`\lanes_{\shape}(c_2)`.
1849+
7. Let :math:`i^\ast` be the result of computing :math:`\lanes_{\shape}(c_1)`.
18501850

1851-
8. Let :math:`c` be the result of computing :math:`\lanes^{-1}_{\shape}(i^\ast \with [x] = c_1)`.
1851+
8. Let :math:`c` be the result of computing :math:`\lanes^{-1}_{\shape}(i^\ast \with [x] = c_2)`.
18521852

18531853
9. Push :math:`\V128.\VCONST~c` on the stack.
18541854

18551855
.. math::
18561856
\begin{array}{l}
18571857
\begin{array}{lcl@{\qquad}l}
1858-
(t_1\K{.}\CONST~c_1)~(\V128\K{.}\VCONST~c_2)~(\shape\K{.}\REPLACELANE~x) &\stepto& (\V128\K{.}\VCONST~c)
1858+
(\V128\K{.}\VCONST~c_1)~(t_2\K{.}\CONST~c_2)~(\shape\K{.}\REPLACELANE~x) &\stepto& (\V128\K{.}\VCONST~c)
18591859
\end{array}
18601860
\\ \qquad
18611861
\begin{array}[t]{@{}r@{~}l@{}}
1862-
(\iff & i^\ast = \lanes_{\shape}(c_2) \\
1863-
\wedge & c = \lanes^{-1}_{\shape}(i^\ast \with [x] = c_1))
1862+
(\iff & i^\ast = \lanes_{\shape}(c_1) \\
1863+
\wedge & c = \lanes^{-1}_{\shape}(i^\ast \with [x] = c_2))
18641864
\end{array}
18651865
\end{array}
18661866
@@ -1992,9 +1992,9 @@ Most other vector instructions are defined in terms of numeric operators that ar
19921992

19931993
1. Assert: due to :ref:`validation <valid-vtestop>`, a value of :ref:`value type <syntax-valtype>` |V128| is on the top of the stack.
19941994

1995-
2. Pop the value :math:`\V128.\VCONST~c_1` from the stack.
1995+
2. Pop the value :math:`\V128.\VCONST~c` from the stack.
19961996

1997-
3. Let :math:`i_1^\ast` be the result of computing :math:`\lanes_{\shape}(c_1)`.
1997+
3. Let :math:`i_1^\ast` be the result of computing :math:`\lanes_{\shape}(c)`.
19981998

19991999
4. Let :math:`i` be the result of computing :math:`\tobool(\bigwedge(i_1 \neq 0)^\ast)`.
20002000

@@ -2004,7 +2004,7 @@ Most other vector instructions are defined in terms of numeric operators that ar
20042004
.. math::
20052005
\begin{array}{l}
20062006
\begin{array}{lcl@{\qquad}l}
2007-
(\V128\K{.}\VCONST~c_1)~\shape\K{.}\ALLTRUE &\stepto& (\I32\K{.}\CONST~i)
2007+
(\V128\K{.}\VCONST~c)~\shape\K{.}\ALLTRUE &\stepto& (\I32\K{.}\CONST~i)
20082008
\end{array}
20092009
\\ \qquad
20102010
\begin{array}[t]{@{}r@{~}l@{}}
@@ -2021,7 +2021,7 @@ Most other vector instructions are defined in terms of numeric operators that ar
20212021

20222022
1. Assert: due to :ref:`validation <valid-vec-bitmask>`, a value of :ref:`value type <syntax-valtype>` |V128| is on the top of the stack.
20232023

2024-
2. Pop the value :math:`\V128.\VCONST~c_1` from the stack.
2024+
2. Pop the value :math:`\V128.\VCONST~c` from the stack.
20252025

20262026
3. Let :math:`i_1^N` be the result of computing :math:`\lanes_{t\K{x}N}(c)`.
20272027

@@ -2031,14 +2031,14 @@ Most other vector instructions are defined in terms of numeric operators that ar
20312031

20322032
6. Let :math:`j^\ast` be the concatenation of the two sequences :math:`i_2^N` and :math:`0^{32-N}`.
20332033

2034-
7. Let :math:`c` be the result of computing :math:`\ibits_{32}^{-1}(j^\ast)`.
2034+
7. Let :math:`i` be the result of computing :math:`\ibits_{32}^{-1}(j^\ast)`.
20352035

2036-
8. Push the value :math:`\I32.\CONST~c` onto the stack.
2036+
8. Push the value :math:`\I32.\CONST~i` onto the stack.
20372037

20382038
.. math::
20392039
\begin{array}{lcl@{\qquad}l}
2040-
(\V128\K{.}\VCONST~c_1)~t\K{x}N\K{.}\BITMASK &\stepto& (\I32\K{.}\CONST~c)
2041-
& (\iff c = \ibits_{32}^{-1}(\ilts_{|t|}(\lanes_{t\K{x}N}(c), 0^N)))
2040+
(\V128\K{.}\VCONST~c)~t\K{x}N\K{.}\BITMASK &\stepto& (\I32\K{.}\CONST~i)
2041+
& (\iff i = \ibits_{32}^{-1}(\ilts_{|t|}(\lanes_{t\K{x}N}(c), 0^N)))
20422042
\\
20432043
\end{array}
20442044
@@ -2160,8 +2160,8 @@ where:
21602160
\end{array}
21612161
21622162
2163-
:math:`t_2\K{x}N\K{.}\vcvtop\K{\_}t_1\K{x}M\K{\_}\sx\K{\_zero}`
2164-
...............................................................
2163+
:math:`t_2\K{x}N\K{.}\vcvtop\K{\_}t_1\K{x}M\K{\_}\sx^?\K{\_zero}`
2164+
.................................................................
21652165

21662166
1. Assert: due to :ref:`syntax <syntax-instr-vec>`, :math:`N = 2 \cdot M`.
21672167

@@ -2171,7 +2171,7 @@ where:
21712171

21722172
4. Let :math:`i^\ast` be the result of computing :math:`\lanes_{t_1\K{x}M}(c_1)`.
21732173

2174-
5. Let :math:`j^\ast` be the result of computing :math:`\vcvtop^{\sx}_{|t_1|,|t_2|}(i^\ast)`.
2174+
5. Let :math:`j^\ast` be the result of computing :math:`\vcvtop^{\sx^?}_{|t_1|,|t_2|}(i^\ast)`.
21752175

21762176
6. Let :math:`k^\ast` be the concatenation of the two sequences :math:`j^\ast` and :math:`0^M`.
21772177

@@ -2182,11 +2182,11 @@ where:
21822182
.. math::
21832183
\begin{array}{l}
21842184
\begin{array}{lcl@{\qquad}l}
2185-
(\V128\K{.}\VCONST~c_1)~t_2\K{x}N\K{.}\vcvtop\K{\_}t_1\K{x}M\K{\_}\sx\K{\_zero} &\stepto& (\V128\K{.}\VCONST~c) \\
2185+
(\V128\K{.}\VCONST~c_1)~t_2\K{x}N\K{.}\vcvtop\K{\_}t_1\K{x}M\K{\_}\sx^?\K{\_zero} &\stepto& (\V128\K{.}\VCONST~c) \\
21862186
\end{array}
21872187
\\ \qquad
21882188
\begin{array}[t]{@{}r@{~}l@{}}
2189-
(\iff & c = \lanes^{-1}_{t_2\K{x}N}(\vcvtop^{\sx}_{|t_1|,|t_2|}(\lanes_{t_1\K{x}M}(c_1))~0^M))
2189+
(\iff & c = \lanes^{-1}_{t_2\K{x}N}(\vcvtop^{\sx^?}_{|t_1|,|t_2|}(\lanes_{t_1\K{x}M}(c_1))~0^M))
21902190
\end{array}
21912191
\end{array}
21922192
@@ -2265,7 +2265,7 @@ where:
22652265

22662266
10. Let :math:`k_2^\ast` be the result of computing :math:`\extend^{\sx}_{|t_1|,|t_2|}(j_2^\ast)`.
22672267

2268-
11. Let :math:`k^\ast` be the result of computing :math:`\imul_{t_2\K{x}N}(k_1^\ast, k_2^\ast)`.
2268+
11. Let :math:`k^\ast` be the result of computing :math:`\imul_{|t_2|}(k_1^\ast, k_2^\ast)`.
22692269

22702270
12. Let :math:`c` be the result of computing :math:`\lanes^{-1}_{t_2\K{x}N}(k^\ast)`.
22712271

@@ -2279,7 +2279,7 @@ where:
22792279
\begin{array}[t]{@{}r@{~}l@{}}
22802280
(\iff & i^\ast = \lanes_{t_1\K{x}M}(c_1)[\half(0, N) \slice N] \\
22812281
\wedge & j^\ast = \lanes_{t_1\K{x}M}(c_2)[\half(0, N) \slice N] \\
2282-
\wedge & c = \lanes^{-1}_{t_2\K{x}N}(\imul_{t_2\K{x}N}(\extend^{\sx}_{|t_1|,|t_2|}(i^\ast), \extend^{\sx}_{|t_1|,|t_2|}(j^\ast))))
2282+
\wedge & c = \lanes^{-1}_{t_2\K{x}N}(\imul_{|t_2|}(\extend^{\sx}_{|t_1|,|t_2|}(i^\ast), \extend^{\sx}_{|t_1|,|t_2|}(j^\ast))))
22832283
\end{array}
22842284
22852285
where:
@@ -2306,7 +2306,7 @@ where:
23062306

23072307
5. Let :math:`(j_1~j_2)^\ast` be the result of computing :math:`\extend^{\sx}_{|t_1|,|t_2|}(i^\ast)`.
23082308

2309-
6. Let :math:`k^\ast` be the result of computing :math:`\iadd_{N}(j_1, j_2)^\ast`.
2309+
6. Let :math:`k^\ast` be the result of computing :math:`\iadd_{|t_2|}(j_1, j_2)^\ast`.
23102310

23112311
7. Let :math:`c` be the result of computing :math:`\lanes^{-1}_{t_2\K{x}N}(k^\ast)`.
23122312

@@ -2320,7 +2320,7 @@ where:
23202320
\\ \qquad
23212321
\begin{array}[t]{@{}r@{~}l@{}}
23222322
(\iff & (i_1~i_2)^\ast = \extend^{\sx}_{|t_1|,|t_2|}(\lanes_{t_1\K{x}M}(c_1)) \\
2323-
\wedge & j^\ast = \iadd_{N}(i_1, i_2)^\ast \\
2323+
\wedge & j^\ast = \iadd_{|t_2|}(i_1, i_2)^\ast \\
23242324
\wedge & c = \lanes^{-1}_{t_2\K{x}N}(j^\ast))
23252325
\end{array}
23262326
\end{array}

document/core/valid/instructions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,9 +1972,9 @@ Control Instructions
19721972
...........................
19731973

19741974

1975-
* The label :math:`C.\CLABELS[l_N]` must be defined in the context.
1975+
* The :ref:`label <syntax-label>` :math:`C.\CLABELS[l_N]` must be defined in the context.
19761976

1977-
* For all :math:`l_i` in :math:`l^\ast`,
1977+
* For each :ref:`label <syntax-label>` :math:`l_i` in :math:`l^\ast`,
19781978
the label :math:`C.\CLABELS[l_i]` must be defined in the context.
19791979

19801980
* There must be a sequence :math:`t^\ast` of :ref:`value types <syntax-valtype>`, such that:

interpreter/dune

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
; Wasm REPL every time in all the dependencies.
77
; We exclude the 'wast' module as it is only used for the JS build.
88
; 'smallint' is a separate test module.
9-
(modules :standard \ main wasm smallint wast))
9+
(modules :standard \ main wasm smallint wast)
10+
(libraries menhirLib))
1011

1112
(executable
1213
(public_name wasm)
@@ -43,7 +44,7 @@
4344
(chdir
4445
%{workspace_root}
4546
(run %{bin:ocamllex} -ml -q -o %{target} %{deps}))))
46-
(ocamlyacc
47+
(menhir
4748
(modules parser)))
4849

4950
(env

interpreter/dune-project

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
(name wasm)
44

55
(generate_opam_files true)
6+
(using menhir 2.1)
7+
(implicit_transitive_deps false)
68

79
(license Apache-2.0)
8-
9-
(source
10-
(github WebAssembly/spec))
10+
(source (github WebAssembly/spec))
1111

1212
(authors "Andreas Rossberg <[email protected]")
1313
(maintainers "Andreas Rossberg <[email protected]")
@@ -17,4 +17,7 @@
1717
(synopsis "Library to read and write WebAssembly (Wasm) files and manipulate their AST")
1818
(tags (wasm webassembly spec interpreter))
1919
(depends
20-
(ocaml (>= 4.12))))
20+
(ocaml (>= 4.12))
21+
(menhir (>= 20220210))
22+
)
23+
)

interpreter/jslib/wast.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
open Wasm
55
open Js_of_ocaml
66

7-
let _ =
7+
let () =
88
Js.export "WebAssemblyText"
99
(object%js (_self)
1010

1111
method encode (s : Js.js_string Js.t) : (Typed_array.arrayBuffer Js.t) =
12-
let def = Parse.string_to_definition (Js.to_string s) in
12+
let _, def = Parse.Module.parse_string (Js.to_string s) in
1313
let bs =
1414
match def.Source.it with
1515
| Script.Textual m -> Encode.encode m

interpreter/script/js.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ let spectest = {
3333
print_f64: console.log.bind(console),
3434
global_i32: 666,
3535
global_i64: 666n,
36-
global_f32: 666,
37-
global_f64: 666,
36+
global_f32: 666.6,
37+
global_f64: 666.6,
3838
table: new WebAssembly.Table({initial: 10, maximum: 20, element: 'anyfunc'}),
3939
memory: new WebAssembly.Memory({initial: 1, maximum: 2})
4040
};
@@ -530,7 +530,8 @@ let rec of_definition def =
530530
| Textual m -> of_bytes (Encode.encode m)
531531
| Encoded (_, bs) -> of_bytes bs
532532
| Quoted (_, s) ->
533-
try of_definition (Parse.string_to_definition s) with Parse.Syntax _ ->
533+
try of_definition (snd (Parse.Module.parse_string s))
534+
with Parse.Syntax _ ->
534535
of_bytes "<malformed quote>"
535536

536537
let of_wrapper mods x_opt name wrap_action wrap_assertion at =
@@ -601,7 +602,7 @@ let of_command mods cmd =
601602
match def.it with
602603
| Textual m -> m
603604
| Encoded (_, bs) -> Decode.decode "binary" bs
604-
| Quoted (_, s) -> unquote (Parse.string_to_definition s)
605+
| Quoted (_, s) -> unquote (snd (Parse.Module.parse_string s))
605606
in bind mods x_opt (unquote def);
606607
"let " ^ current_var mods ^ " = instance(" ^ of_definition def ^ ");\n" ^
607608
(if x_opt = None then "" else

interpreter/script/run.ml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,20 @@ let input_from get_script run =
118118
| Assert (at, msg) -> error at "assertion failure" msg
119119
| Abort _ -> false
120120

121-
let input_script start name lexbuf run =
122-
input_from (fun _ -> Parse.parse name lexbuf start) run
121+
let input_script name lexbuf run =
122+
input_from (fun () -> Parse.Script.parse name lexbuf) run
123+
124+
let input_script1 name lexbuf run =
125+
input_from (fun () -> Parse.Script1.parse name lexbuf) run
123126

124127
let input_sexpr name lexbuf run =
125-
input_from (fun _ ->
126-
let var_opt, def = Parse.parse name lexbuf Parse.Module in
128+
input_from (fun () ->
129+
let var_opt, def = Parse.Module.parse name lexbuf in
127130
[Module (var_opt, def) @@ no_region]) run
128131

129132
let input_binary name buf run =
130133
let open Source in
131-
input_from (fun _ ->
134+
input_from (fun () ->
132135
[Module (None, Encoded (name, buf) @@ no_region) @@ no_region]) run
133136

134137
let input_sexpr_file input file run =
@@ -162,16 +165,16 @@ let input_file file run =
162165
dispatch_file_ext
163166
input_binary_file
164167
(input_sexpr_file input_sexpr)
165-
(input_sexpr_file (input_script Parse.Script))
166-
(input_sexpr_file (input_script Parse.Script))
168+
(input_sexpr_file input_script)
169+
(input_sexpr_file input_script)
167170
input_js_file
168171
file run
169172

170173
let input_string string run =
171174
trace ("Running (\"" ^ String.escaped string ^ "\")...");
172175
let lexbuf = Lexing.from_string string in
173176
trace "Parsing...";
174-
input_script Parse.Script "string" lexbuf run
177+
input_script "string" lexbuf run
175178

176179

177180
(* Interactive *)
@@ -195,7 +198,7 @@ let lexbuf_stdin buf len =
195198
let input_stdin run =
196199
let lexbuf = Lexing.from_function lexbuf_stdin in
197200
let rec loop () =
198-
let success = input_script Parse.Script1 "stdin" lexbuf run in
201+
let success = input_script1 "stdin" lexbuf run in
199202
if not success then Lexing.flush_input lexbuf;
200203
if Lexing.(lexbuf.lex_curr_pos >= lexbuf.lex_buffer_len - 1) then
201204
continuing := false;
@@ -315,7 +318,7 @@ let rec run_definition def : Ast.module_ =
315318
Decode.decode name bs
316319
| Quoted (_, s) ->
317320
trace "Parsing quote...";
318-
let def' = Parse.string_to_definition s in
321+
let _, def' = Parse.Module.parse_string s in
319322
run_definition def'
320323

321324
let run_action act : Value.t list =

interpreter/script/script.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ and meta' =
6464

6565
and script = command list
6666

67-
exception Syntax of Source.region * string
68-
6967

7068
let () =
7169
let type_of_ref' = !Value.type_of_ref' in

interpreter/text/arrange.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,14 +766,14 @@ let definition mode x_opt def =
766766
match def.it with
767767
| Textual m -> m
768768
| Encoded (_, bs) -> Decode.decode "" bs
769-
| Quoted (_, s) -> unquote (Parse.string_to_definition s)
769+
| Quoted (_, s) -> unquote (snd (Parse.Module.parse_string s))
770770
in module_with_var_opt x_opt (unquote def)
771771
| `Binary ->
772772
let rec unquote def =
773773
match def.it with
774774
| Textual m -> Encode.encode m
775775
| Encoded (_, bs) -> Encode.encode (Decode.decode "" bs)
776-
| Quoted (_, s) -> unquote (Parse.string_to_definition s)
776+
| Quoted (_, s) -> unquote (snd (Parse.Module.parse_string s))
777777
in binary_module_with_var_opt x_opt (unquote def)
778778
| `Original ->
779779
match def.it with

interpreter/text/lexer.mll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let region lexbuf =
1414
let right = convert_pos (Lexing.lexeme_end_p lexbuf) in
1515
{left = left; right = right}
1616

17-
let error lexbuf msg = raise (Script.Syntax (region lexbuf, msg))
17+
let error lexbuf msg = raise (Parse_error.Syntax (region lexbuf, msg))
1818
let error_nest start lexbuf msg =
1919
lexbuf.Lexing.lex_start_p <- start;
2020
error lexbuf msg

0 commit comments

Comments
 (0)