Skip to content

Commit 954c5eb

Browse files
authored
Spec new encoding from #3 (#5)
* Spec new encoding from #3 * Fix empty name type error * Fix spectec tests
1 parent d194455 commit 954c5eb

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

document/core/binary/modules.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ It decodes into the list of :ref:`imports <syntax-import>` of a :ref:`module <sy
152152
$${grammar: {Bimportsec Bimports Bimport}}
153153

154154
.. note::
155-
The encoding of :ref:`imports <binary-imports>` beginning with ${:0x01 0xFF} allows multiple imports to be expressed without repeating the module name. ${:0x01 0xFF} decodes as an invalid :ref:`name <binary-name>` for compatibility with older implementations.
155+
The encoding of :ref:`imports <binary-imports>` containing ${:0x7F} allows multiple imports to be encoded without repeating the module name. Because ${:0x7F} is not a valid encoding for an :ref:`external type <binary-externtype>`, the encoding is unambiguous.
156156

157157

158158
.. index:: ! function section, function, type index, function type

specification/wasm-3.0/5.4-binary.modules.spectec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ grammar Bimport : (name, externtype) =
3636

3737
grammar Bimports : import* =
3838
| nm_1:Bname (nm_2, xt):Bimport => IMPORT nm_1 nm_2 xt
39-
| 0x01 0xFF nm_1:Bname (nm_2, xt)*:Blist(Bimport) => (IMPORT nm_1 nm_2 xt)*
39+
| nm_1:Bname nm_e:Bname 0x7F (nm_2, xt)*:Blist(Bimport) => (IMPORT nm_1 nm_2 xt)* -- if nm_e = eps
4040

4141
grammar Bimportsec : import* hint(desc "import section") =
4242
| im**:Bsection_(2, Blist(Bimports)) => $concat_(import, im**)
0 Bytes
Binary file not shown.

spectec/test-frontend/TEST.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8717,7 +8717,8 @@ grammar Bimports : import*
87178717
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
87188718
prod{nm_1 : name, nm_2 : name, xt : externtype} {{nm_1:Bname} {(nm_2, xt):Bimport}} => [IMPORT_import(nm_1, nm_2, xt)]
87198719
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
8720-
prod{nm_1 : name, `nm_2*` : name*, `xt*` : externtype*} {{0x01} {0xFF} {nm_1:Bname} {(nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}:Blist(syntax (name, externtype), grammar Bimport)}} => IMPORT_import(nm_1, nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}
8720+
prod{nm_1 : name, nm_e : name, `nm_2*` : name*, `xt*` : externtype*} {{nm_1:Bname} {nm_e:Bname} {0x7F} {(nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}:Blist(syntax (name, externtype), grammar Bimport)}} => IMPORT_import(nm_1, nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}
8721+
-- if (nm_e = `%`_name([]))
87218722

87228723
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
87238724
grammar Bimportsec : import*

spectec/test-latex/TEST.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12026,7 +12026,7 @@ $$
1202612026
\begin{array}[t]{@{}lrrl@{}l@{}l@{}l@{}}
1202712027
& {\mathtt{import}} & ::= & {\mathit{nm}}_2{:}{\mathtt{name}}~~{\mathit{xt}}{:}{\mathtt{externtype}} & \quad\Rightarrow\quad{} & ({\mathit{nm}}_2, {\mathit{xt}}) \\
1202812028
& {\mathtt{imports}} & ::= & {\mathit{nm}}_1{:}{\mathtt{name}}~~({\mathit{nm}}_2, {\mathit{xt}}){:}{\mathtt{import}} & \quad\Rightarrow\quad{} & \mathsf{import}~{\mathit{nm}}_1~{\mathit{nm}}_2~{\mathit{xt}} \\
12029-
& & | & \mathtt{0x01}~~\mathtt{0xFF}~~{\mathit{nm}}_1{:}{\mathtt{name}}~~{({\mathit{nm}}_2, {\mathit{xt}})^\ast}{:}{\mathtt{list}}({\mathtt{import}}) & \quad\Rightarrow\quad{} & {(\mathsf{import}~{\mathit{nm}}_1~{\mathit{nm}}_2~{\mathit{xt}})^\ast} \\
12029+
& & | & {\mathit{nm}}_1{:}{\mathtt{name}}~~{\mathit{nm}}_e{:}{\mathtt{name}}~~\mathtt{0x7F}~~{({\mathit{nm}}_2, {\mathit{xt}})^\ast}{:}{\mathtt{list}}({\mathtt{import}}) & \quad\Rightarrow\quad{} & {(\mathsf{import}~{\mathit{nm}}_1~{\mathit{nm}}_2~{\mathit{xt}})^\ast} & \quad \mbox{if}~ {\mathit{nm}}_e = \epsilon \\
1203012030
\mbox{(import section)} & {\mathtt{importsec}} & ::= & {{{\mathit{im}}^\ast}^\ast}{:}{{\mathtt{section}}}_{2}({\mathtt{list}}({\mathtt{imports}})) & \quad\Rightarrow\quad{} & {\bigoplus}\, {{{\mathit{im}}^\ast}^\ast} \\
1203112031
\end{array}
1203212032
$$

spectec/test-middlend/TEST.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8707,7 +8707,8 @@ grammar Bimports : import*
87078707
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
87088708
prod{nm_1 : name, nm_2 : name, xt : externtype} {{nm_1:Bname} {(nm_2, xt):Bimport}} => [IMPORT_import(nm_1, nm_2, xt)]
87098709
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
8710-
prod{nm_1 : name, `nm_2*` : name*, `xt*` : externtype*} {{0x01} {0xFF} {nm_1:Bname} {(nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}:Blist(syntax (name, externtype), grammar Bimport)}} => IMPORT_import(nm_1, nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}
8710+
prod{nm_1 : name, nm_e : name, `nm_2*` : name*, `xt*` : externtype*} {{nm_1:Bname} {nm_e:Bname} {0x7F} {(nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}:Blist(syntax (name, externtype), grammar Bimport)}} => IMPORT_import(nm_1, nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}
8711+
-- if (nm_e = `%`_name([]))
87118712

87128713
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
87138714
grammar Bimportsec : import*
@@ -20058,7 +20059,8 @@ grammar Bimports : import*
2005820059
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
2005920060
prod{nm_1 : name, nm_2 : name, xt : externtype} {{nm_1:Bname} {(nm_2, xt):Bimport}} => [IMPORT_import(nm_1, nm_2, xt)]
2006020061
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
20061-
prod{nm_1 : name, `nm_2*` : name*, `xt*` : externtype*} {{0x01} {0xFF} {nm_1:Bname} {(nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}:Blist(syntax (name, externtype), grammar Bimport)}} => IMPORT_import(nm_1, nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}
20062+
prod{nm_1 : name, nm_e : name, `nm_2*` : name*, `xt*` : externtype*} {{nm_1:Bname} {nm_e:Bname} {0x7F} {(nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}:Blist(syntax (name, externtype), grammar Bimport)}} => IMPORT_import(nm_1, nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}
20063+
-- if (nm_e = `%`_name([]))
2006220064

2006320065
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
2006420066
grammar Bimportsec : import*
@@ -31588,7 +31590,8 @@ grammar Bimports : import*
3158831590
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
3158931591
prod{nm_1 : name, nm_2 : name, xt : externtype} {{nm_1:Bname} {(nm_2, xt):Bimport}} => [IMPORT_import(nm_1, nm_2, xt)]
3159031592
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
31591-
prod{nm_1 : name, `nm_2*` : name*, `xt*` : externtype*} {{0x01} {0xFF} {nm_1:Bname} {(nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}:Blist(syntax (name, externtype), grammar Bimport)}} => IMPORT_import(nm_1, nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}
31593+
prod{nm_1 : name, nm_e : name, `nm_2*` : name*, `xt*` : externtype*} {{nm_1:Bname} {nm_e:Bname} {0x7F} {(nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}:Blist(syntax (name, externtype), grammar Bimport)}} => IMPORT_import(nm_1, nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}
31594+
-- if (nm_e = `%`_name([]))
3159231595

3159331596
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
3159431597
grammar Bimportsec : import*

0 commit comments

Comments
 (0)