Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 5 additions & 1 deletion document/core/binary/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ $${grammar: {Btypesec Btype}}
pair: binary format; import
pair: section; import
.. _binary-import:
.. _binary-imports:
.. _binary-importdesc:
.. _binary-importsec:

Expand All @@ -148,7 +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 Bimport}}
$${grammar: {Bimportsec Bimports Bimport}}

.. note::
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.
Comment thread
bvisness marked this conversation as resolved.


.. index:: ! function section, function, type index, function type
Expand Down
7 changes: 6 additions & 1 deletion document/core/text/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ $${grammar: Tstart_}
.. index:: import, name, tag type, global type, memory type, table type, function type
pair: text format; import
.. _text-import:
.. _text-imports:

Imports
~~~~~~~
Expand All @@ -356,7 +357,11 @@ $${grammar: Timport_/plain}
Abbreviations
.............

As an abbreviation, imports may also be specified inline with
Multiple imports with the same ${:nm_1} may be declared together:

$${grammar: Timports_/abbrev}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It seems strange to me that the abbreviation has a different name from the main declaration, but I don't see a way to unify them. For function locals, for example, the declaration is always Tlocal_(I)/whatever : (local*, idctxt), so everything expects local*. But here I can't do that because we need it to be a single import.


Imports may also be specified inline with
:ref:`tag <text-tag>`,
:ref:`global <text-global>`,
:ref:`memory <text-mem>`,
Expand Down
2 changes: 2 additions & 0 deletions document/core/util/macros.def
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@
.. |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}}
.. |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}}
.. |Belemkind| mathdef:: \xref{binary/modules}{binary-elemkind}{\B{elemkind}}
Expand Down Expand Up @@ -1071,6 +1072,7 @@
.. |Tglobal| mathdef:: \xref{text/modules}{text-global}{\T{global}}
.. |Ttag| mathdef:: \xref{text/modules}{text-tag}{\T{tag}}
.. |Timport| mathdef:: \xref{text/modules}{text-import}{\T{import}}
.. |Timports| mathdef:: \xref{text/modules}{text-imports}{\T{imports}}
.. |Texport| mathdef:: \xref{text/modules}{text-export}{\T{export}}
.. |Texternidx| mathdef:: \xref{text/modules}{text-externidx}{\T{externidx}}
.. |Telem| mathdef:: \xref{text/modules}{text-elem}{\T{elem}}
Expand Down
10 changes: 7 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,11 +31,15 @@ grammar Btypesec : type* hint(desc "type section") =

;; Import section

grammar Bimport : import =
| nm_1:Bname nm_2:Bname xt:Bexterntype => IMPORT nm_1 nm_2 xt
grammar Bimport : (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
| 0x01 0xFF nm_1:Bname (nm_2, xt)*:Blist(Bimport) => (IMPORT nm_1 nm_2 xt)*

grammar Bimportsec : import* hint(desc "import section") =
| im*:Bsection_(2, Blist(Bimport)) => im*
| im**:Bsection_(2, Blist(Bimports)) => $concat_(import, im**)


;; Function section
Expand Down
5 changes: 4 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,6 +134,10 @@ 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) =
| "(" "import" nm_1:Tname ("(" "item" nm_2:Tname Texterntype_(I) ")")* ")" ==
("(" "import" nm_1:Tname nm_2:Tname Texterntype_(I) ")")*

grammar Timport_(I)/abbrev-tag : (import, idctxt) = ...
| "(" "tag" Tid? "(" "import" Tname^2 ")" Ttagtype_(I) ")" ==
"(" "import" Tname^2 "(" "tag" Tid? Ttagtype_(I) ")" ")"
Expand All @@ -158,7 +162,6 @@ grammar Timport_(I)/abbrev-func : (import, idctxt) = ...
| "(" "func" Tid? "(" "import" Tname^2 ")" Ttypeuse_(I) ")" ==
"(" "import" Tname^2 "(" "func" Tid? Ttypeuse_(I) ")" ")"


;; Exports

grammar Texport_(I) : (export, idctxt) =
Expand Down
Binary file modified spectec/doc/example/output/NanoWasm.pdf
Binary file not shown.
104 changes: 57 additions & 47 deletions spectec/test-frontend/TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -8708,14 +8708,21 @@ 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 : import
grammar Bimport : (name, externtype)
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
prod{nm_1 : name, nm_2 : name, xt : externtype} {{nm_1:Bname} {nm_2:Bname} {xt:Bexterntype}} => IMPORT_import(nm_1, nm_2, xt)
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)]
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
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*`}

;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
grammar Bimportsec : import*
;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
prod{`im*` : import*} im*{im <- `im*`}:Bsection_(2, syntax import, grammar Blist(syntax import, grammar Bimport)) => im*{im <- `im*`}
prod{`im**` : import**} im*{im <- `im*`}*{`im*` <- `im**`}:Bsection_(2, syntax import*, grammar Blist(syntax import*, grammar Bimports)) => $concat_(syntax import, im*{im <- `im*`}*{`im*` <- `im**`})

;; ../../../../specification/wasm-3.0/5.4-binary.modules.spectec
grammar Bfuncsec : typeidx*
Expand Down Expand Up @@ -10863,6 +10870,9 @@ grammar Tstart_(I : I) : (start, idctxt)
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
prod{x : idx} {{"("} {"start"} {x:Tfuncidx_(I)} {")"}} => (START_start(x), {TYPES [], TAGS [], GLOBALS [], MEMS [], TABLES [], FUNCS [], DATAS [], ELEMS [], LOCALS [], LABELS [], FIELDS [], TYPEDEFS []})

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
grammar Timports_(I : I) : (import*, idctxt)

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
grammar Timport_(I : I) : (import, idctxt)
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
Expand Down Expand Up @@ -10963,153 +10973,153 @@ syntax decl =
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec
rec {

;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:258.1-258.76
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:261.1-261.76
def $typesd(decl*) : type*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:270.1-270.23
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:273.1-273.23
def $typesd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:271.1-271.48
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:274.1-274.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:272.1-272.57
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:275.1-275.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:259.1-259.78
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:262.1-262.78
def $importsd(decl*) : import*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:274.1-274.25
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:277.1-277.25
def $importsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:275.1-275.56
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:278.1-278.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:276.1-276.61
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:279.1-279.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:260.1-260.75
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:263.1-263.75
def $tagsd(decl*) : tag*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:278.1-278.22
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:281.1-281.22
def $tagsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:279.1-279.44
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:282.1-282.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:280.1-280.55
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:283.1-283.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:261.1-261.78
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:264.1-264.78
def $globalsd(decl*) : global*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:282.1-282.25
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:285.1-285.25
def $globalsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:283.1-283.56
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:286.1-286.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:284.1-284.61
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:287.1-287.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:262.1-262.75
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:265.1-265.75
def $memsd(decl*) : mem*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:286.1-286.22
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:289.1-289.22
def $memsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:287.1-287.44
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:290.1-290.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:288.1-288.55
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:291.1-291.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:263.1-263.77
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:266.1-266.77
def $tablesd(decl*) : table*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:290.1-290.24
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:293.1-293.24
def $tablesd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:291.1-291.52
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:294.1-294.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:292.1-292.59
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:295.1-295.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:264.1-264.76
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:267.1-267.76
def $funcsd(decl*) : func*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:294.1-294.23
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:297.1-297.23
def $funcsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:295.1-295.48
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:298.1-298.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:296.1-296.57
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:299.1-299.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:265.1-265.76
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:268.1-268.76
def $datasd(decl*) : data*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:298.1-298.23
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:301.1-301.23
def $datasd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:299.1-299.48
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:302.1-302.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:300.1-300.57
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:303.1-303.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:266.1-266.76
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:269.1-269.76
def $elemsd(decl*) : elem*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:302.1-302.23
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:305.1-305.23
def $elemsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:303.1-303.48
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:306.1-306.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:304.1-304.57
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:307.1-307.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:267.1-267.77
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:270.1-270.77
def $startsd(decl*) : start*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:306.1-306.24
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:309.1-309.24
def $startsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:307.1-307.52
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:310.1-310.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:308.1-308.59
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:311.1-311.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:268.1-268.78
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:271.1-271.78
def $exportsd(decl*) : export*
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:310.1-310.25
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:313.1-313.25
def $exportsd([]) = []
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:311.1-311.56
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:314.1-314.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:312.1-312.61
;; ../../../../specification/wasm-3.0/6.3-text.modules.spectec:315.1-315.61
def $exportsd{decl : decl, `decl'*` : decl*}([decl] ++ decl'*{decl' <- `decl'*`}) = $exportsd(decl'*{decl' <- `decl'*`})
-- otherwise
}
Expand Down
Loading