Skip to content

Commit 7dfe8eb

Browse files
committed
Update binary and text sections
1 parent 1a3226b commit 7dfe8eb

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

document/core/binary/modules.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ $${grammar: {Btypesec Btype}}
139139
pair: binary format; import
140140
pair: section; import
141141
.. _binary-import:
142+
.. _binary-imports:
142143
.. _binary-importdesc:
143144
.. _binary-importsec:
144145

@@ -148,7 +149,10 @@ Import Section
148149
The *import section* has the id 2.
149150
It decodes into the list of :ref:`imports <syntax-import>` of a :ref:`module <syntax-module>`.
150151

151-
$${grammar: {Bimportsec Bimport}}
152+
$${grammar: {Bimportsec Bimports Bimport}}
153+
154+
.. 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.
152156

153157

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

document/core/util/macros.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@
887887
.. |Bglobal| mathdef:: \xref{binary/modules}{binary-global}{\B{global}}
888888
.. |Btag| mathdef:: \xref{binary/modules}{binary-tag}{\B{tag}}
889889
.. |Bimport| mathdef:: \xref{binary/modules}{binary-import}{\B{import}}
890+
.. |Bimports| mathdef:: \xref{binary/modules}{binary-imports}{\B{imports}}
890891
.. |Bexport| mathdef:: \xref{binary/modules}{binary-export}{\B{export}}
891892
.. |Belem| mathdef:: \xref{binary/modules}{binary-elem}{\B{elem}}
892893
.. |Belemkind| mathdef:: \xref{binary/modules}{binary-elemkind}{\B{elemkind}}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ grammar Btypesec : type* hint(desc "type section") =
3131

3232
;; Import section
3333

34-
grammar Bimport : import =
35-
| nm_1:Bname nm_2:Bname xt:Bexterntype => IMPORT nm_1 nm_2 xt
34+
grammar Bimport : (name, externtype) =
35+
| nm_2:Bname xt:Bexterntype => (nm_2, xt)
36+
37+
grammar Bimports : import* =
38+
| nm_1:Bname (nm_2, xt):Bimport => IMPORT nm_1 nm_2 xt
39+
| 0x01 0xFF nm_1:Bname (nm_2, xt)*:Blist(Bimport) => $concat_(import, IMPORT nm_1 nm_2 xt)
3640

3741
grammar Bimportsec : import* hint(desc "import section") =
38-
| im*:Bsection_(2, Blist(Bimport)) => im*
42+
| im*:Bsection_(2, Blist(Bimports)) => im*
3943

4044

4145
;; Function section

specification/wasm-3.0/6.3-text.modules.spectec

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,33 +130,36 @@ grammar Tstart_(I) : (start, idctxt) =
130130

131131
;; Imports
132132

133-
grammar Timport_(I)/plain : (import, idctxt) =
134-
| "(" "import" nm_1:Tname nm_2:Tname (xt,I'):Texterntype_(I) ")" => (IMPORT nm_1 nm_2 xt, I')
133+
grammar Timport_(I)/plain : (name, externtype, idctxt) =
134+
| "(" "item" nm_2:Tname (xt,I'):Texterntype_(I) ")" => (nm_2, xt, I')
135+
136+
grammar Timports_(I)/plain : (import*, idctxt) =
137+
| "(" "import" nm_1:Tname (nm_2,xt,I')*:Timport_(I)* ")" => ($concat_(import, IMPORT nm_1 nm_2 xt), I')
135138
| ...
136139

137-
grammar Timport_(I)/abbrev-tag : (import, idctxt) = ...
140+
grammar Timports_(I)/abbrev-tag : (import*, idctxt) = ...
138141
| "(" "tag" Tid? "(" "import" Tname^2 ")" Ttagtype_(I) ")" ==
139-
"(" "import" Tname^2 "(" "tag" Tid? Ttagtype_(I) ")" ")"
142+
"(" "import" Tname "(" "item" Tname "(" "tag" Tid? Ttagtype_(I) ")" ")" ")"
140143
| ...
141144

142-
grammar Timport_(I)/abbrev-global : (import, idctxt) = ...
145+
grammar Timports_(I)/abbrev-global : (import*, idctxt) = ...
143146
| "(" "global" Tid? "(" "import" Tname^2 ")" Tglobaltype_(I) ")" ==
144-
"(" "import" Tname^2 "(" "global" Tid? Tglobaltype_(I) ")" ")"
147+
"(" "import" Tname "(" "item" Tname "(" "global" Tid? Tglobaltype_(I) ")" ")" ")"
145148
| ...
146149

147-
grammar Timport_(I)/abbrev-mem : (import, idctxt) = ...
150+
grammar Timports_(I)/abbrev-mem : (import*, idctxt) = ...
148151
| "(" "memory" Tid? "(" "import" Tname^2 ")" Tmemtype_(I) ")" ==
149-
"(" "import" Tname^2 "(" "memory" Tid? Tmemtype_(I) ")" ")"
152+
"(" "import" Tname "(" "item" Tname "(" "memory" Tid? Tmemtype_(I) ")" ")" ")"
150153
| ...
151154

152-
grammar Timport_(I)/abbrev-table : (import, idctxt) = ...
155+
grammar Timports_(I)/abbrev-table : (import*, idctxt) = ...
153156
| "(" "table" Tid? "(" "import" Tname^2 ")" Ttabletype_(I) ")" ==
154-
"(" "import" Tname^2 "(" "table" Tid? Ttabletype_(I) ")" ")"
157+
"(" "import" Tname "(" "item" Tname "(" "table" Tid? Ttabletype_(I) ")" ")" ")"
155158
| ...
156159

157-
grammar Timport_(I)/abbrev-func : (import, idctxt) = ...
160+
grammar Timports_(I)/abbrev-func : (import*, idctxt) = ...
158161
| "(" "func" Tid? "(" "import" Tname^2 ")" Ttypeuse_(I) ")" ==
159-
"(" "import" Tname^2 "(" "func" Tid? Ttypeuse_(I) ")" ")"
162+
"(" "import" Tname "(" "item" Tname "(" "func" Tid? Ttypeuse_(I) ")" ")" ")"
160163

161164

162165
;; Exports
@@ -253,7 +256,7 @@ grammar Telemtable_(I)/abbrev : () hint(show Ttable_(%)) =
253256
;; Modules
254257

255258
syntax decl hint(name "declaration") =
256-
type | import | tag | global | mem | table | func | data | elem | start | export
259+
type | import* | tag | global | mem | table | func | data | elem | start | export
257260

258261
def $typesd(decl*) : type* hint(show $types(%)) hint(macro "typesd")
259262
def $importsd(decl*) : import* hint(show $imports(%)) hint(macro "importsd")
@@ -320,7 +323,7 @@ def $ordered(decl_1* import decl_2*) =
320323

321324

322325
grammar Tdecl_(I) : (decl, idctxt) =
323-
| Ttype_(I) | Timport_(I) | Ttag_(I) | Tglobal_(I) | Tmem_(I) | Ttable_(I)
326+
| Ttype_(I) | Timports_(I) | Ttag_(I) | Tglobal_(I) | Tmem_(I) | Ttable_(I)
324327
| Tfunc_(I) | Tdata_(I) | Telem_(I) | Tstart_(I) | Texport_(I)
325328

326329

0 commit comments

Comments
 (0)