Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
6 changes: 3 additions & 3 deletions document/core/binary/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ $${grammar: {Btypesec Btype}}
.. index:: ! import section, import, name, function type, table type, memory type, global type, tag type
pair: binary format; import
pair: section; import
.. _binary-import:
.. _binary-importitem:
.. _binary-imports:
.. _binary-importdesc:
.. _binary-importsec:
Expand All @@ -149,10 +149,10 @@ Import Section
The *import section* has the id 2.
It decodes into the list of :ref:`imports <syntax-import>` of a :ref:`module <syntax-module>`.

$${grammar: {Bimportsec Bimports Bimport}}
$${grammar: {Bimportsec Bimports Bimportitem}}

.. note::
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.
The encodings of :ref:`imports <binary-imports>` containing ${:0x7F} and ${:0x7E} allow multiple imports to be encoded without repeating the module name, and potentially also without repeating the externtype. Because ${:0x7F} and ${:0x7E} are not valid encodings for an :ref:`external type <binary-externtype>`, the encoding is unambiguous.


.. index:: ! function section, function, type index, function type
Expand Down
6 changes: 5 additions & 1 deletion document/core/text/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ Abbreviations

Multiple imports with the same ${:nm_1} may be declared together:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Multiple imports with the same ${:nm_1} may be declared together:
Multiple imports with the same :ref:`name <syntax-name>` ${:nm_1} may be declared together:


$${grammar: Timports_/abbrev}
$${grammar: Timports_/abbrev-compact1}

Multiple imports with the same ${:nm_1} and ${:xt} may also be declared together, in which case identifiers may be placed on individual items instead of the ${:externtype}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Multiple imports with the same ${:nm_1} and ${:xt} may also be declared together, in which case identifiers may be placed on individual items instead of the ${:externtype}:
Multiple imports with the same name ${:nm_1} and :ref:`external type <syntax-externtype>` ${:xt} may also be declared together, in which case identifiers may be placed on individual items instead of the external type:


$${grammar: Timports_/abbrev-compact2}

Imports may also be specified inline with
:ref:`tag <text-tag>`,
Expand Down
2 changes: 1 addition & 1 deletion document/core/util/macros.def
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@
.. |Bmem| mathdef:: \xref{binary/modules}{binary-mem}{\B{mem}}
.. |Bglobal| mathdef:: \xref{binary/modules}{binary-global}{\B{global}}
.. |Btag| mathdef:: \xref{binary/modules}{binary-tag}{\B{tag}}
.. |Bimport| mathdef:: \xref{binary/modules}{binary-import}{\B{import}}
.. |Bimportitem| mathdef:: \xref{binary/modules}{binary-importitem}{\B{importitem}}
.. |Bimports| mathdef:: \xref{binary/modules}{binary-imports}{\B{imports}}
.. |Bexport| mathdef:: \xref{binary/modules}{binary-export}{\B{export}}
.. |Belem| mathdef:: \xref{binary/modules}{binary-elem}{\B{elem}}
Expand Down
7 changes: 4 additions & 3 deletions specification/wasm-3.0/5.4-binary.modules.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ grammar Btypesec : type* hint(desc "type section") =

;; Import section

grammar Bimport : (name, externtype) =
grammar Bimportitem : (name, externtype) =
| nm_2:Bname xt:Bexterntype => (nm_2, xt)

grammar Bimports : import* =
| nm_1:Bname (nm_2, xt):Bimport => IMPORT nm_1 nm_2 xt
| nm_1:Bname nm_e:Bname 0x7F (nm_2, xt)*:Blist(Bimport) => (IMPORT nm_1 nm_2 xt)* -- if nm_e = eps
| nm_1:Bname nm_2:Bname xt:Bexterntype => IMPORT nm_1 nm_2 xt
| nm_1:Bname nm_e:Bname 0x7F (nm_2, xt)*:Blist(Bimportitem) => (IMPORT nm_1 nm_2 xt)* -- if nm_e = eps
| nm_1:Bname nm_e:Bname 0x7E xt:Bexterntype nm_2*:Blist(Bname) => (IMPORT nm_1 nm_2 xt)* -- if nm_e = eps

grammar Bimportsec : import* hint(desc "import section") =
| im**:Bsection_(2, Blist(Bimports)) => $concat_(import, im**)
Expand Down
7 changes: 6 additions & 1 deletion specification/wasm-3.0/6.3-text.modules.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ grammar Timport_(I)/plain : (import, idctxt) =
| "(" "import" nm_1:Tname nm_2:Tname (xt,I'):Texterntype_(I) ")" => (IMPORT nm_1 nm_2 xt, I')
| ...

grammar Timports_(I)/abbrev : (import*, idctxt) =
grammar Timports_(I)/abbrev-compact1 : (import*, idctxt) =
| "(" "import" nm_1:Tname ("(" "item" nm_2:Tname Texterntype_(I) ")")* ")" ==
("(" "import" nm_1:Tname nm_2:Tname Texterntype_(I) ")")*
| ...

grammar Timports_(I)/abbrev-compact2 : (import*, idctxt) = ...
| "(" "import" nm_1:Tname "(" "type" Texterntype_(I) ("(" "item" id?:Tid? nm_2:Tname ")")* ")" ")" ==
("(" "import" nm_1:Tname nm_2:Tname Texterntype_(I) ")")*

grammar Timport_(I)/abbrev-tag : (import, idctxt) = ...
| "(" "tag" Tid? "(" "import" Tname^2 ")" Ttagtype_(I) ")" ==
Expand Down
Binary file modified spectec/doc/example/output/NanoWasm.pdf
Binary file not shown.
97 changes: 50 additions & 47 deletions spectec/test-frontend/TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -8708,16 +8708,19 @@ grammar Btypesec : type*
prod{`ty*` : type*} ty*{ty <- `ty*`}:Bsection_(1, syntax type, grammar Blist(syntax type, grammar Btype)) => ty*{ty <- `ty*`}

;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
grammar Bimport : (name, externtype)
grammar Bimportitem : (name, externtype)
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
prod{nm_2 : name, xt : externtype} {{nm_2:Bname} {xt:Bexterntype}} => (nm_2, xt)

;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
grammar Bimports : import*
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
prod{nm_1 : name, nm_2 : name, xt : externtype} {{nm_1:Bname} {(nm_2, xt):Bimport}} => [IMPORT_import(nm_1, nm_2, xt)]
prod{nm_1 : name, nm_2 : name, xt : externtype} {{nm_1:Bname} {nm_2:Bname} {xt:Bexterntype}} => [IMPORT_import(nm_1, nm_2, xt)]
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
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*`}
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 Bimportitem)}} => IMPORT_import(nm_1, nm_2, xt)*{nm_2 <- `nm_2*`, xt <- `xt*`}
-- if (nm_e = `%`_name([]))
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
prod{nm_1 : name, nm_e : name, xt : externtype, `nm_2*` : name*} {{nm_1:Bname} {nm_e:Bname} {0x7E} {xt:Bexterntype} {nm_2*{nm_2 <- `nm_2*`}:Blist(syntax name, grammar Bname)}} => IMPORT_import(nm_1, nm_2, xt)*{nm_2 <- `nm_2*`}
-- if (nm_e = `%`_name([]))

;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
Expand Down Expand Up @@ -10974,153 +10977,153 @@ syntax decl =
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:261.1-261.76
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:266.1-266.76
def $typesd(decl*) : type*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:273.1-273.23
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:278.1-278.23
def $typesd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:274.1-274.48
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:279.1-279.48
def $typesd{type : type, `decl'*` : decl*}([(type : type <: decl)] ++ decl'*{decl' <- `decl'*`}) = [type] ++ $typesd(decl'*{decl' <- `decl'*`})
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:275.1-275.57
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:280.1-280.57
def $typesd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $typesd(decl'*{decl' <- `decl'*`})
-- otherwise
}

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:262.1-262.78
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:267.1-267.78
def $importsd(decl*) : import*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:277.1-277.25
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:282.1-282.25
def $importsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:278.1-278.56
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:283.1-283.56
def $importsd{import : import, `decl'*` : decl*}([(import : import <: decl)] ++ decl'*{decl' <- `decl'*`}) = [import] ++ $importsd(decl'*{decl' <- `decl'*`})
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:279.1-279.61
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:284.1-284.61
def $importsd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $importsd(decl'*{decl' <- `decl'*`})
-- otherwise
}

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:263.1-263.75
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:268.1-268.75
def $tagsd(decl*) : tag*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:281.1-281.22
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:286.1-286.22
def $tagsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:282.1-282.44
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:287.1-287.44
def $tagsd{tag : tag, `decl'*` : decl*}([(tag : tag <: decl)] ++ decl'*{decl' <- `decl'*`}) = [tag] ++ $tagsd(decl'*{decl' <- `decl'*`})
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:283.1-283.55
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:288.1-288.55
def $tagsd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $tagsd(decl'*{decl' <- `decl'*`})
-- otherwise
}

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:264.1-264.78
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:269.1-269.78
def $globalsd(decl*) : global*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:285.1-285.25
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:290.1-290.25
def $globalsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:286.1-286.56
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:291.1-291.56
def $globalsd{global : global, `decl'*` : decl*}([(global : global <: decl)] ++ decl'*{decl' <- `decl'*`}) = [global] ++ $globalsd(decl'*{decl' <- `decl'*`})
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:287.1-287.61
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:292.1-292.61
def $globalsd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $globalsd(decl'*{decl' <- `decl'*`})
-- otherwise
}

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:265.1-265.75
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:270.1-270.75
def $memsd(decl*) : mem*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:289.1-289.22
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:294.1-294.22
def $memsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:290.1-290.44
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:295.1-295.44
def $memsd{mem : mem, `decl'*` : decl*}([(mem : mem <: decl)] ++ decl'*{decl' <- `decl'*`}) = [mem] ++ $memsd(decl'*{decl' <- `decl'*`})
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:291.1-291.55
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:296.1-296.55
def $memsd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $memsd(decl'*{decl' <- `decl'*`})
-- otherwise
}

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:266.1-266.77
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:271.1-271.77
def $tablesd(decl*) : table*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:293.1-293.24
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:298.1-298.24
def $tablesd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:294.1-294.52
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:299.1-299.52
def $tablesd{table : table, `decl'*` : decl*}([(table : table <: decl)] ++ decl'*{decl' <- `decl'*`}) = [table] ++ $tablesd(decl'*{decl' <- `decl'*`})
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:295.1-295.59
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:300.1-300.59
def $tablesd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $tablesd(decl'*{decl' <- `decl'*`})
-- otherwise
}

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:267.1-267.76
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:272.1-272.76
def $funcsd(decl*) : func*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:297.1-297.23
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:302.1-302.23
def $funcsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:298.1-298.48
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:303.1-303.48
def $funcsd{func : func, `decl'*` : decl*}([(func : func <: decl)] ++ decl'*{decl' <- `decl'*`}) = [func] ++ $funcsd(decl'*{decl' <- `decl'*`})
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:299.1-299.57
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:304.1-304.57
def $funcsd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $funcsd(decl'*{decl' <- `decl'*`})
-- otherwise
}

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:268.1-268.76
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:273.1-273.76
def $datasd(decl*) : data*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:301.1-301.23
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:306.1-306.23
def $datasd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:302.1-302.48
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:307.1-307.48
def $datasd{data : data, `decl'*` : decl*}([(data : data <: decl)] ++ decl'*{decl' <- `decl'*`}) = [data] ++ $datasd(decl'*{decl' <- `decl'*`})
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:303.1-303.57
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:308.1-308.57
def $datasd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $datasd(decl'*{decl' <- `decl'*`})
-- otherwise
}

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:269.1-269.76
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:274.1-274.76
def $elemsd(decl*) : elem*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:305.1-305.23
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:310.1-310.23
def $elemsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:306.1-306.48
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:311.1-311.48
def $elemsd{elem : elem, `decl'*` : decl*}([(elem : elem <: decl)] ++ decl'*{decl' <- `decl'*`}) = [elem] ++ $elemsd(decl'*{decl' <- `decl'*`})
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:307.1-307.57
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:312.1-312.57
def $elemsd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $elemsd(decl'*{decl' <- `decl'*`})
-- otherwise
}

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:270.1-270.77
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:275.1-275.77
def $startsd(decl*) : start*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:309.1-309.24
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:314.1-314.24
def $startsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:310.1-310.52
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:315.1-315.52
def $startsd{start : start, `decl'*` : decl*}([(start : start <: decl)] ++ decl'*{decl' <- `decl'*`}) = [start] ++ $startsd(decl'*{decl' <- `decl'*`})
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:311.1-311.59
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:316.1-316.59
def $startsd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $startsd(decl'*{decl' <- `decl'*`})
-- otherwise
}

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:271.1-271.78
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:276.1-276.78
def $exportsd(decl*) : export*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:313.1-313.25
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:318.1-318.25
def $exportsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:314.1-314.56
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:319.1-319.56
def $exportsd{export : export, `decl'*` : decl*}([(export : export <: decl)] ++ decl'*{decl' <- `decl'*`}) = [export] ++ $exportsd(decl'*{decl' <- `decl'*`})
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:315.1-315.61
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:320.1-320.61
def $exportsd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $exportsd(decl'*{decl' <- `decl'*`})
-- otherwise
}
Expand Down
Loading