Modules
Indices
Indices can be given either in raw numeric form or as symbolic identifiers when bound by a respective construct.
Such identifiers are looked up in the suitable space of the identifier context \(I\).
\[\begin{split}\begin{array}{llcllllllll}
\def\mathdef3544#1{{}}\mathdef3544{type index} & \href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}_I &::=&
x{:}\href{../text/values.html#text-int}{\def\mathdef3574#1{{\mathtt{u}#1}}\mathdef3574{\mathtt{32}}} &\Rightarrow& x \\&&|&
v{:}\href{../text/values.html#text-id}{\mathtt{id}} &\Rightarrow& x & (\mathrel{\mbox{if}} I.\href{../text/conventions.html#text-context}{\mathsf{types}}[x] = v) \\
\def\mathdef3544#1{{}}\mathdef3544{global index} & \href{../text/modules.html#text-globalidx}{\mathtt{globalidx}}_I &::=&
x{:}\href{../text/values.html#text-int}{\def\mathdef3574#1{{\mathtt{u}#1}}\mathdef3574{\mathtt{32}}} &\Rightarrow& x \\&&|&
v{:}\href{../text/values.html#text-id}{\mathtt{id}} &\Rightarrow& x & (\mathrel{\mbox{if}} I.\href{../text/conventions.html#text-context}{\mathsf{globals}}[x] = v) \\
\def\mathdef3544#1{{}}\mathdef3544{tag index} & \href{../text/modules.html#text-tagidx}{\mathtt{tagidx}}_I &::=&
x{:}\href{../text/values.html#text-int}{\def\mathdef3574#1{{\mathtt{u}#1}}\mathdef3574{\mathtt{32}}} &\Rightarrow& x \\&&|&
v{:}\href{../text/values.html#text-id}{\mathtt{id}} &\Rightarrow& x & (\mathrel{\mbox{if}} I.\href{../text/conventions.html#text-context}{\mathsf{tags}}[x] = v) \\
\def\mathdef3544#1{{}}\mathdef3544{memory index} & \href{../text/modules.html#text-memidx}{\mathtt{memidx}}_I &::=&
x{:}\href{../text/values.html#text-int}{\def\mathdef3574#1{{\mathtt{u}#1}}\mathdef3574{\mathtt{32}}} &\Rightarrow& x \\&&|&
v{:}\href{../text/values.html#text-id}{\mathtt{id}} &\Rightarrow& x & (\mathrel{\mbox{if}} I.\href{../text/conventions.html#text-context}{\mathsf{mems}}[x] = v) \\
\def\mathdef3544#1{{}}\mathdef3544{table index} & \href{../text/modules.html#text-tableidx}{\mathtt{tableidx}}_I &::=&
x{:}\href{../text/values.html#text-int}{\def\mathdef3574#1{{\mathtt{u}#1}}\mathdef3574{\mathtt{32}}} &\Rightarrow& x \\&&|&
v{:}\href{../text/values.html#text-id}{\mathtt{id}} &\Rightarrow& x & (\mathrel{\mbox{if}} I.\href{../text/conventions.html#text-context}{\mathsf{tables}}[x] = v) \\
\def\mathdef3544#1{{}}\mathdef3544{function index} & \href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I &::=&
x{:}\href{../text/values.html#text-int}{\def\mathdef3574#1{{\mathtt{u}#1}}\mathdef3574{\mathtt{32}}} &\Rightarrow& x \\&&|&
v{:}\href{../text/values.html#text-id}{\mathtt{id}} &\Rightarrow& x & (\mathrel{\mbox{if}} I.\href{../text/conventions.html#text-context}{\mathsf{funcs}}[x] = v) \\
\def\mathdef3544#1{{}}\mathdef3544{data index} & \href{../text/modules.html#text-dataidx}{\mathtt{dataidx}}_I &::=&
x{:}\href{../text/values.html#text-int}{\def\mathdef3574#1{{\mathtt{u}#1}}\mathdef3574{\mathtt{32}}} &\Rightarrow& x \\&&|&
v{:}\href{../text/values.html#text-id}{\mathtt{id}} &\Rightarrow& x & (\mathrel{\mbox{if}} I.\href{../text/conventions.html#text-context}{\mathsf{datas}}[x] = v) \\
\def\mathdef3544#1{{}}\mathdef3544{element index} & \href{../text/modules.html#text-elemidx}{\mathtt{elemidx}}_I &::=&
x{:}\href{../text/values.html#text-int}{\def\mathdef3574#1{{\mathtt{u}#1}}\mathdef3574{\mathtt{32}}} &\Rightarrow& x \\&&|&
v{:}\href{../text/values.html#text-id}{\mathtt{id}} &\Rightarrow& x & (\mathrel{\mbox{if}} I.\href{../text/conventions.html#text-context}{\mathsf{elems}}[x] = v) \\
\def\mathdef3544#1{{}}\mathdef3544{local index} & \href{../text/modules.html#text-localidx}{\mathtt{localidx}}_I &::=&
x{:}\href{../text/values.html#text-int}{\def\mathdef3574#1{{\mathtt{u}#1}}\mathdef3574{\mathtt{32}}} &\Rightarrow& x \\&&|&
v{:}\href{../text/values.html#text-id}{\mathtt{id}} &\Rightarrow& x & (\mathrel{\mbox{if}} I.\href{../text/conventions.html#text-context}{\mathsf{locals}}[x] = v) \\
\def\mathdef3544#1{{}}\mathdef3544{label index} & \href{../text/modules.html#text-labelidx}{\mathtt{labelidx}}_I &::=&
l{:}\href{../text/values.html#text-int}{\def\mathdef3574#1{{\mathtt{u}#1}}\mathdef3574{\mathtt{32}}} &\Rightarrow& l \\&&|&
v{:}\href{../text/values.html#text-id}{\mathtt{id}} &\Rightarrow& l & (\mathrel{\mbox{if}} I.\href{../text/conventions.html#text-context}{\mathsf{labels}}[l] = v) \\
\def\mathdef3544#1{{}}\mathdef3544{field index} & \href{../text/modules.html#text-fieldidx}{\mathtt{fieldidx}}_{I,x} &::=&
i{:}\href{../text/values.html#text-int}{\def\mathdef3574#1{{\mathtt{u}#1}}\mathdef3574{\mathtt{32}}} &\Rightarrow& i \\&&|&
v{:}\href{../text/values.html#text-id}{\mathtt{id}} &\Rightarrow& i & (\mathrel{\mbox{if}} I.\href{../text/conventions.html#text-context}{\mathsf{fields}}[x][i] = v) \\
\end{array}\end{split}\]
Globals
Global definitions can bind a symbolic global identifier.
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{global} & \href{../text/modules.html#text-global}{\mathtt{global}}_I &::=&
\def\mathdef3618#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3618{(}~\def\mathdef3619#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3619{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{gt}{:}\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}_I~~e{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef3620#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3620{)}
&\Rightarrow& \href{../syntax/modules.html#syntax-global}{\mathsf{global}}~\mathit{gt}~e \\
\end{array}\end{split}\]
Abbreviations
Globals can be defined as imports or exports inline:
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{module field} &
\def\mathdef3621#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3621{(}~\def\mathdef3622#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3622{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3623#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3623{(}~\def\mathdef3624#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3624{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef3625#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3625{)}~~\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~\def\mathdef3626#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3626{)} \quad\equiv \\ & \qquad
\def\mathdef3627#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3627{(}~\def\mathdef3628#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3628{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef3629#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3629{(}~\def\mathdef3630#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3630{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~\def\mathdef3631#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3631{)}~\def\mathdef3632#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3632{)}
\\[1ex] &
\def\mathdef3633#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3633{(}~\def\mathdef3634#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3634{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3635#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3635{(}~\def\mathdef3636#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3636{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef3637#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3637{)}~~\dots~\def\mathdef3638#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3638{)} \quad\equiv \\ & \qquad
\def\mathdef3639#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3639{(}~\def\mathdef3640#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3640{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef3641#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3641{(}~\def\mathdef3642#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3642{global}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef3643#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3643{)}~\def\mathdef3644#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3644{)}~~
\def\mathdef3645#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3645{(}~\def\mathdef3646#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3646{global}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef3647#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3647{)}
\\ & \qquad\qquad
(\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \vee \href{../text/values.html#text-id}{\mathtt{id}}^? = \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}) \\
\end{array}\end{split}\]
Note
The latter abbreviation can be applied repeatedly, if “\(\dots\)” contains additional export clauses.
Consequently, a global declaration can contain any number of exports, possibly followed by an import.
Memories
Memory definitions can bind a symbolic memory identifier.
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{memory} & \href{../text/modules.html#text-mem}{\mathtt{mem}}_I &::=&
\def\mathdef3648#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3648{(}~\def\mathdef3649#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3649{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{mt}{:}\href{../text/types.html#text-memtype}{\mathtt{memtype}}_I~\def\mathdef3650#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3650{)}
&\Rightarrow& \href{../syntax/modules.html#syntax-mem}{\mathsf{memory}}~\mathit{mt} \\
\end{array}\end{split}\]
Abbreviations
A data segment can be given inline with a memory definition, in which case its offset is \(0\) and the limits of the memory type are inferred from the length of the data, rounded up to page size:
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{module field} &
\def\mathdef3651#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3651{(}~\def\mathdef3652#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3652{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^?~~\def\mathdef3653#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3653{(}~\def\mathdef3654#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3654{data}~~b^n{:}\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef3655#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3655{)}~~\def\mathdef3656#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3656{)} \quad\equiv \\ & \qquad
\def\mathdef3657#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3657{(}~\def\mathdef3658#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3658{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^?~~m~~m~\def\mathdef3659#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3659{)} \\ & \qquad
\def\mathdef3660#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3660{(}~\def\mathdef3661#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3661{data}~~\def\mathdef3662#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3662{(}~\def\mathdef3663#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3663{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef3664#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3664{)}~~\def\mathdef3665#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3665{(}~\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}'\def\mathdef3666#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3666{.const}~~\def\mathdef3667#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3667{0}~\def\mathdef3668#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3668{)}~~\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef3669#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3669{)}
\\ & \qquad\qquad
(\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \vee \href{../text/values.html#text-id}{\mathtt{id}}^? = \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}, \\ & \qquad\qquad
\mathrel{\mbox{if}} \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}? \neq \epsilon \wedge \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}' = \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^? \vee \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^? = \epsilon \wedge \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}' = \def\mathdef3670#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3670{i32}, \\ & \qquad\qquad
m = \mathrm{ceil}(n / 64\,\mathrm{Ki})) \\
\end{array}\end{split}\]
Memories can be defined as imports or exports inline:
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{module field} &
\def\mathdef3671#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3671{(}~\def\mathdef3672#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3672{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3673#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3673{(}~\def\mathdef3674#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3674{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef3675#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3675{)}~~\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef3676#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3676{)} \quad\equiv \\ & \qquad
\def\mathdef3677#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3677{(}~\def\mathdef3678#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3678{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef3679#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3679{(}~\def\mathdef3680#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3680{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef3681#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3681{)}~\def\mathdef3682#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3682{)}
\\[1ex] &
\def\mathdef3683#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3683{(}~\def\mathdef3684#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3684{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3685#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3685{(}~\def\mathdef3686#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3686{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef3687#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3687{)}~~\dots~\def\mathdef3688#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3688{)} \quad\equiv \\ & \qquad
\def\mathdef3689#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3689{(}~\def\mathdef3690#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3690{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef3691#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3691{(}~\def\mathdef3692#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3692{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef3693#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3693{)}~\def\mathdef3694#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3694{)}~~
\def\mathdef3695#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3695{(}~\def\mathdef3696#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3696{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef3697#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3697{)}
\\ & \qquad\qquad
(\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \vee \href{../text/values.html#text-id}{\mathtt{id}}^? = \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}) \\
\end{array}\end{split}\]
Note
The latter abbreviation can be applied repeatedly, if “\(\dots\)” contains additional export clauses.
Consequently, a memory declaration can contain any number of exports, possibly followed by an import.
Tables
Table definitions can bind a symbolic table identifier.
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{table} & \href{../text/modules.html#text-table}{\mathtt{table}}_I &::=&
\def\mathdef3698#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3698{(}~\def\mathdef3699#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3699{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{tt}{:}\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}_I~~e{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef3700#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3700{)}
&\Rightarrow& \href{../syntax/modules.html#syntax-table}{\mathsf{table}}~\mathit{tt}~e \\
\end{array}\end{split}\]
Abbreviations
A table’s initialization expression can be omitted, in which case it defaults to \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}null}}\):
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{module field} &
\def\mathdef3701#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3701{(}~\def\mathdef3702#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3702{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef3703#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3703{)}
&\equiv&
\def\mathdef3704#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3704{(}~\def\mathdef3705#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3705{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~~\def\mathdef3706#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3706{(}~\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}null}}~\mathit{ht}~\def\mathdef3707#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3707{)}~\def\mathdef3708#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3708{)}
\\ &&& \qquad\qquad
(\mathrel{\mbox{if}} \href{../text/types.html#text-tabletype}{\mathtt{tabletype}} = \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^?~\href{../text/types.html#text-limits}{\mathtt{limits}}~\def\mathdef3709#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3709{(}~\def\mathdef3710#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3710{ref}~\def\mathdef3711#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3711{null}^?~\mathit{ht}~\def\mathdef3712#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3712{)}) \\
\end{array}\end{split}\]
An element segment can be given inline with a table definition, in which case its offset is \(0\) and the limits of the table type are inferred from the length of the given segment:
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{module field} &
\def\mathdef3713#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3713{(}~\def\mathdef3714#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3714{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^?~~\href{../text/types.html#text-reftype}{\mathtt{reftype}}~~\def\mathdef3715#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3715{(}~\def\mathdef3716#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3716{elem}~~\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}^n{:}\href{../text/conventions.html#text-list}{\mathtt{list}}(\href{../text/modules.html#text-elemexpr}{\mathtt{elemexpr}})~\def\mathdef3717#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3717{)}~\def\mathdef3718#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3718{)} \quad\equiv \\ & \qquad
\def\mathdef3719#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3719{(}~\def\mathdef3720#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3720{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^?~~n~~n~~\href{../text/types.html#text-reftype}{\mathtt{reftype}}~\def\mathdef3721#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3721{)} \\ & \qquad
\def\mathdef3722#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3722{(}~\def\mathdef3723#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3723{elem}~~\def\mathdef3724#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3724{(}~\def\mathdef3725#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3725{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef3726#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3726{)}~~\def\mathdef3727#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3727{(}~\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}'\def\mathdef3728#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3728{.const}~~\def\mathdef3729#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3729{0}~\def\mathdef3730#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3730{)}~~\href{../text/types.html#text-reftype}{\mathtt{reftype}}~~\href{../text/conventions.html#text-list}{\mathtt{list}}(\href{../text/modules.html#text-elemexpr}{\mathtt{elemexpr}})~\def\mathdef3731#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3731{)}
\\ & \qquad\qquad
(\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \vee \href{../text/values.html#text-id}{\mathtt{id}}^? = \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}, \\ & \qquad\qquad
\mathrel{\mbox{if}} \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}? \neq \epsilon \wedge \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}' = \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^? \vee \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^? = \epsilon \wedge \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}' = \def\mathdef3732#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3732{i32}) \\
\end{array}\end{split}\]
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{module field} &
\def\mathdef3733#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3733{(}~\def\mathdef3734#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3734{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^?~~\href{../text/types.html#text-reftype}{\mathtt{reftype}}~~\def\mathdef3735#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3735{(}~\def\mathdef3736#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3736{elem}~~x^n{:}\href{../text/conventions.html#text-list}{\mathtt{list}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}})~\def\mathdef3737#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3737{)}~\def\mathdef3738#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3738{)} \quad\equiv \\ & \qquad
\def\mathdef3739#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3739{(}~\def\mathdef3740#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3740{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^?~~n~~n~~\href{../text/types.html#text-reftype}{\mathtt{reftype}}~\def\mathdef3741#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3741{)} \\ & \qquad
\def\mathdef3742#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3742{(}~\def\mathdef3743#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3743{elem}~~\def\mathdef3744#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3744{(}~\def\mathdef3745#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3745{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef3746#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3746{)}~~\def\mathdef3747#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3747{(}~\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}'\def\mathdef3748#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3748{.const}~~\def\mathdef3749#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3749{0}~\def\mathdef3750#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3750{)}~~\href{../text/types.html#text-reftype}{\mathtt{reftype}}~~\href{../text/conventions.html#text-list}{\mathtt{list}}(\def\mathdef3751#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3751{(}~\def\mathdef3752#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3752{ref.func}~~\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}~\def\mathdef3753#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3753{)})~\def\mathdef3754#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3754{)}
\\ & \qquad\qquad
(\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \vee \href{../text/values.html#text-id}{\mathtt{id}}^? = \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}, \\ & \qquad\qquad
\mathrel{\mbox{if}} \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}? \neq \epsilon \wedge \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}' = \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^? \vee \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}^? = \epsilon \wedge \href{../text/types.html#text-addrtype}{\mathtt{addrtype}}' = \def\mathdef3755#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3755{i32}) \\
\end{array}\end{split}\]
Tables can be defined as imports or exports inline:
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{module field} &
\def\mathdef3756#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3756{(}~\def\mathdef3757#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3757{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3758#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3758{(}~\def\mathdef3759#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3759{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef3760#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3760{)}~~\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef3761#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3761{)} \quad\equiv \\ & \qquad
\def\mathdef3762#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3762{(}~\def\mathdef3763#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3763{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef3764#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3764{(}~\def\mathdef3765#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3765{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef3766#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3766{)}~\def\mathdef3767#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3767{)} \\[1ex] &
\def\mathdef3768#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3768{(}~\def\mathdef3769#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3769{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3770#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3770{(}~\def\mathdef3771#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3771{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef3772#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3772{)}~~\dots~\def\mathdef3773#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3773{)} \quad\equiv \\ & \qquad
\def\mathdef3774#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3774{(}~\def\mathdef3775#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3775{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef3776#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3776{(}~\def\mathdef3777#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3777{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef3778#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3778{)}~\def\mathdef3779#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3779{)}~~
\def\mathdef3780#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3780{(}~\def\mathdef3781#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3781{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef3782#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3782{)}
\\ & \qquad\qquad
(\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \vee \href{../text/values.html#text-id}{\mathtt{id}}^? = \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}) \\
\end{array}\end{split}\]
Note
The latter abbreviation can be applied repeatedly, if “\(\dots\)” contains additional export clauses.
Consequently, a table declaration can contain any number of exports, possibly followed by an import.
Functions
Function definitions can bind a symbolic function identifier, and local identifiers for its parameters and locals.
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{function} & \href{../text/modules.html#text-func}{\mathtt{func}}_I &::=&
\def\mathdef3783#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3783{(}~\def\mathdef3784#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3784{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~x,I'{:}\href{../text/types.html#text-typeuse}{\mathtt{typeuse}}_I~~
(\mathit{loc}{:}\href{../text/modules.html#text-local}{\mathtt{local}}_I)^\ast~~(\mathit{in}{:}\href{../text/instructions.html#text-instr}{\mathtt{instr}}_{I''})^\ast~\def\mathdef3785#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3785{)} \\ &&& \qquad
\Rightarrow\quad \href{../syntax/modules.html#syntax-func}{\mathsf{func}}~x~\mathit{loc}^\ast~\mathit{in}^\ast \\ &&& \qquad\qquad\qquad
(\mathrel{\mbox{if}} I'' = I \href{../syntax/conventions.html#notation-compose}{\oplus} I' \href{../syntax/conventions.html#notation-compose}{\oplus} \{\href{../text/conventions.html#text-context}{\mathsf{locals}}~\mathrm{id}(\href{../text/modules.html#text-local}{\mathtt{local}})^\ast\} ~\href{../text/conventions.html#text-context-wf}{\mbox{well-formed}}) \\[1ex]
\def\mathdef3544#1{{}}\mathdef3544{local} & \href{../text/modules.html#text-local}{\mathtt{local}}_I &::=&
\def\mathdef3786#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3786{(}~\def\mathdef3787#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3787{local}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~t{:}\href{../text/types.html#text-valtype}{\mathtt{valtype}}_I~\def\mathdef3788#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3788{)}
\quad\Rightarrow\quad \href{../syntax/modules.html#syntax-local}{\mathsf{local}}~t \\
\end{array}\end{split}\]
The definition of the local identifier context \(I''\) uses the following auxiliary function to extract optional identifiers from locals:
\[\begin{split}\begin{array}{lcl@{\qquad\qquad}l}
\mathrm{id}(\def\mathdef3789#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3789{(}~\def\mathdef3790#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3790{local}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3791#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3791{)}) &=& \href{../text/values.html#text-id}{\mathtt{id}}^? \\
\end{array}\end{split}\]
Note
The well-formedness condition on \(I''\) ensures that parameters and locals do not contain duplicate identifiers.
Abbreviations
Multiple anonymous locals may be combined into a single declaration:
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{local} &
\def\mathdef3792#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3792{(}~~\def\mathdef3793#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3793{local}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}^\ast~~\def\mathdef3794#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3794{)} &\equiv&
(\def\mathdef3795#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3795{(}~~\def\mathdef3796#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3796{local}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}~~\def\mathdef3797#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3797{)})^\ast \\
\end{array}\end{split}\]
Functions can be defined as imports or exports inline:
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{module field} &
\def\mathdef3798#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3798{(}~\def\mathdef3799#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3799{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3800#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3800{(}~\def\mathdef3801#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3801{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef3802#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3802{)}~~\href{../text/types.html#text-typeuse}{\mathtt{typeuse}}~\def\mathdef3803#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3803{)} \quad\equiv \\ & \qquad
\def\mathdef3804#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3804{(}~\def\mathdef3805#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3805{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef3806#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3806{(}~\def\mathdef3807#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3807{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-typeuse}{\mathtt{typeuse}}~\def\mathdef3808#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3808{)}~\def\mathdef3809#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3809{)} \\[1ex] &
\def\mathdef3810#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3810{(}~\def\mathdef3811#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3811{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3812#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3812{(}~\def\mathdef3813#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3813{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef3814#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3814{)}~~\dots~\def\mathdef3815#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3815{)} \quad\equiv \\ & \qquad
\def\mathdef3816#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3816{(}~\def\mathdef3817#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3817{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef3818#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3818{(}~\def\mathdef3819#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3819{func}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef3820#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3820{)}~\def\mathdef3821#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3821{)}~~
\def\mathdef3822#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3822{(}~\def\mathdef3823#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3823{func}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef3824#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3824{)}
\\ & \qquad\qquad
(\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \vee \href{../text/values.html#text-id}{\mathtt{id}}^? = \epsilon \wedge \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}) \\
\end{array}\end{split}\]
Note
The latter abbreviation can be applied repeatedly, if “\(\dots\)” contains additional export clauses.
Consequently, a function declaration can contain any number of exports, possibly followed by an import.
Data Segments
Data segments allow for an optional memory index to identify the memory to initialize.
The data is written as a string, which may be split up into a possibly empty sequence of individual string literals.
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{data segment} & \href{../text/modules.html#text-data}{\mathtt{data}}_I &::=&
\def\mathdef3825#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3825{(}~\def\mathdef3826#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3826{data}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~b^\ast{:}\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef3827#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3827{)} \\ &&& \qquad
\Rightarrow\quad \href{../syntax/modules.html#syntax-data}{\mathsf{data}}~b^\ast~\href{../syntax/modules.html#syntax-datamode}{\mathsf{passive}} \\ &&|&
\def\mathdef3828#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3828{(}~\def\mathdef3829#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3829{data}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~x{:}\href{../text/modules.html#text-memuse}{\mathtt{memuse}}_I~~\def\mathdef3830#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3830{(}~\def\mathdef3831#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3831{offset}~~e{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef3832#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3832{)}~~b^\ast{:}\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef3833#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3833{)} \\ &&& \qquad
\Rightarrow\quad \href{../syntax/modules.html#syntax-data}{\mathsf{data}}~b^\ast~\href{../syntax/modules.html#syntax-datamode}{\mathsf{active}}~x~e \\
\def\mathdef3544#1{{}}\mathdef3544{data string} & \href{../text/modules.html#text-datastring}{\mathtt{datastring}} &::=&
(b^\ast{:}\href{../text/values.html#text-string}{\mathtt{string}})^\ast \quad\Rightarrow\quad \href{../syntax/conventions.html#notation-concat}{\bigoplus}((b^\ast)^\ast) \\
\def\mathdef3544#1{{}}\mathdef3544{memory use} & \href{../text/modules.html#text-memuse}{\mathtt{memuse}}_I &::=&
\def\mathdef3834#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3834{(}~\def\mathdef3835#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3835{memory}~~x{:}\href{../text/modules.html#text-memidx}{\mathtt{memidx}}_I ~\def\mathdef3836#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3836{)}
\quad\Rightarrow\quad x \\
\end{array}\end{split}\]
Note
In the current version of WebAssembly, the only valid memory index is 0
or a symbolic memory identifier resolving to the same value.
Abbreviations
As an abbreviation, a single folded instruction may occur in place of the offset of an active data segment:
\[\begin{array}{llcll}
\def\mathdef3544#1{{}}\mathdef3544{data offset} &
\def\mathdef3837#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3837{(}~\href{../text/instructions.html#text-foldedinstr}{\mathtt{foldedinstr}}~\def\mathdef3838#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3838{)} &\equiv&
\def\mathdef3839#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3839{(}~\def\mathdef3840#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3840{offset}~~\href{../text/instructions.html#text-instr}{\mathtt{instr}}~\def\mathdef3841#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3841{)}
\end{array}\]
Also, a memory use can be omitted, defaulting to \(\mathtt{0}\).
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{memory use} &
\epsilon &\equiv& \def\mathdef3842#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3842{(}~\def\mathdef3843#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3843{memory}~~\def\mathdef3844#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3844{0}~\def\mathdef3845#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3845{)} \\
\end{array}\end{split}\]
As another abbreviation, data segments may also be specified inline with memory definitions; see the respective section.
Element Segments
Element segments allow for an optional table index to identify the table to initialize.
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{element segment} & \href{../text/modules.html#text-elem}{\mathtt{elem}}_I &::=&
\def\mathdef3846#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3846{(}~\def\mathdef3847#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3847{elem}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~(et, e^\ast){:}\href{../text/modules.html#text-elemlist}{\mathtt{elemlist}}_I~\def\mathdef3848#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3848{)} \\ &&& \qquad
\Rightarrow\quad \href{../syntax/modules.html#syntax-elem}{\mathsf{elem}}~et~e^\ast~\href{../syntax/modules.html#syntax-elemmode}{\mathsf{passive}} \\ &&|&
\def\mathdef3849#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3849{(}~\def\mathdef3850#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3850{elem}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~x{:}\href{../text/modules.html#text-tableuse}{\mathtt{tableuse}}_I~~\def\mathdef3851#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3851{(}~\def\mathdef3852#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3852{offset}~~e'{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef3853#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3853{)}~~(et, e^\ast){:}\href{../text/modules.html#text-elemlist}{\mathtt{elemlist}}_I~\def\mathdef3854#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3854{)} \\ &&& \qquad
\Rightarrow\quad \href{../syntax/modules.html#syntax-elem}{\mathsf{elem}}~et~e^\ast~\href{../syntax/modules.html#syntax-elemmode}{\mathsf{active}}~~x~e' \\ &&&
\def\mathdef3855#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3855{(}~\def\mathdef3856#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3856{elem}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3857#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3857{declare}~~(et, y^\ast){:}\href{../text/modules.html#text-elemlist}{\mathtt{elemlist}}_I~\def\mathdef3858#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3858{)} \\ &&& \qquad
\Rightarrow\quad \href{../syntax/modules.html#syntax-elem}{\mathsf{elem}}~et~e^\ast~\href{../syntax/modules.html#syntax-elemmode}{\mathsf{declare}} \\
\def\mathdef3544#1{{}}\mathdef3544{element list} & \href{../text/modules.html#text-elemlist}{\mathtt{elemlist}}_I &::=&
t{:}\href{../text/types.html#text-reftype}{\mathtt{reftype}}_I~~e^\ast{:}\href{../text/conventions.html#text-list}{\mathtt{list}}(\href{../text/modules.html#text-elemexpr}{\mathtt{elemexpr}}_I) \qquad\Rightarrow\quad ( t, ee^\ast ) \\
\def\mathdef3544#1{{}}\mathdef3544{element expression} & \href{../text/modules.html#text-elemexpr}{\mathtt{elemexpr}}_I &::=&
\def\mathdef3859#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3859{(}~\def\mathdef3860#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3860{item}~~e{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef3861#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3861{)}
\quad\Rightarrow\quad e \\
\def\mathdef3544#1{{}}\mathdef3544{table use} & \href{../text/modules.html#text-tableuse}{\mathtt{tableuse}}_I &::=&
\def\mathdef3862#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3862{(}~\def\mathdef3863#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3863{table}~~x{:}\href{../text/modules.html#text-tableidx}{\mathtt{tableidx}}_I ~\def\mathdef3864#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3864{)}
\quad\Rightarrow\quad x \\
\end{array}\end{split}\]
Abbreviations
As an abbreviation, a single folded instruction may occur in place of the offset of an active element segment or as an element expression:
\[\begin{split}\begin{array}{llcll}
\def\mathdef3544#1{{}}\mathdef3544{element offset} &
\def\mathdef3865#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3865{(}~\href{../text/instructions.html#text-foldedinstr}{\mathtt{foldedinstr}}~\def\mathdef3866#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3866{)} &\equiv&
\def\mathdef3867#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3867{(}~\def\mathdef3868#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3868{offset}~~\href{../text/instructions.html#text-instr}{\mathtt{instr}}~\def\mathdef3869#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3869{)} \\
\def\mathdef3544#1{{}}\mathdef3544{element item} &
\def\mathdef3870#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3870{(}~\href{../text/instructions.html#text-foldedinstr}{\mathtt{foldedinstr}}~\def\mathdef3871#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3871{)} &\equiv&
\def\mathdef3872#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3872{(}~\def\mathdef3873#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3873{item}~~\href{../text/instructions.html#text-instr}{\mathtt{instr}}~\def\mathdef3874#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3874{)} \\
\end{array}\end{split}\]
Also, the element list may be written as just a sequence of function indices:
\[\begin{array}{llcll}
\def\mathdef3544#1{{}}\mathdef3544{element list} &
\def\mathdef3875#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3875{func}~~\href{../text/conventions.html#text-list}{\mathtt{list}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I) &\equiv&
\def\mathdef3876#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3876{(ref}~\def\mathdef3877#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3877{func)}~~\href{../text/conventions.html#text-list}{\mathtt{list}}(\def\mathdef3878#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3878{(}~\def\mathdef3879#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3879{ref.func}~~\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I~\def\mathdef3880#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3880{)})
\end{array}\]
A table use can be omitted, defaulting to \(\mathtt{0}\).
Furthermore, for backwards compatibility with earlier versions of WebAssembly, if the table use is omitted, the \(\def\mathdef3881#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3881{func}\) keyword can be omitted as well.
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{table use} &
\epsilon &\equiv& \def\mathdef3882#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3882{(}~\def\mathdef3883#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3883{table}~~\def\mathdef3884#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3884{0}~\def\mathdef3885#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3885{)} \\
\def\mathdef3544#1{{}}\mathdef3544{element segment} &
\def\mathdef3886#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3886{(}~\def\mathdef3887#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3887{elem}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3888#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3888{(}~\def\mathdef3889#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3889{offset}~~\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef3890#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3890{)}~~\\ &
\qquad \href{../text/conventions.html#text-list}{\mathtt{list}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I)~\def\mathdef3891#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3891{)}
&\equiv&
\def\mathdef3892#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3892{(}~\def\mathdef3893#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3893{elem}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3894#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3894{(}~\def\mathdef3895#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3895{table}~~\def\mathdef3896#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3896{0}~\def\mathdef3897#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3897{)}~~\def\mathdef3898#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3898{(}~\def\mathdef3899#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3899{offset}~~\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef3900#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3900{)}~~\\ &
&&\qquad \def\mathdef3901#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3901{func}~~\href{../text/conventions.html#text-list}{\mathtt{list}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I)~\def\mathdef3902#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3902{)}
\end{array}\end{split}\]
As another abbreviation, element segments may also be specified inline with table definitions; see the respective section.
Start Function
A start function is defined in terms of its index.
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{start function} & \href{../text/modules.html#text-start}{\mathtt{start}}_I &::=&
\def\mathdef3903#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3903{(}~\def\mathdef3904#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3904{start}~~x{:}\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I~\def\mathdef3905#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3905{)}
&\Rightarrow& \href{../syntax/modules.html#syntax-start}{\mathsf{start}}~x \\
\end{array}\end{split}\]
Note
At most one start function may occur in a module,
which is ensured by a suitable side condition on the \(\href{../text/modules.html#text-module}{\mathtt{module}}\) grammar.
Imports
The external type in imports can bind a symbolic tag, global, memory, or function identifier.
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{import} & \href{../text/modules.html#text-import}{\mathtt{import}}_I &::=&
\def\mathdef3906#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3906{(}~\def\mathdef3907#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3907{import}~~\mathit{nm}_1{:}\href{../text/values.html#text-name}{\mathtt{name}}~~\mathit{nm}_2{:}\href{../text/values.html#text-name}{\mathtt{name}}~~\mathit{xx}{:}\href{../text/types.html#text-externtype}{\mathtt{externtype}}_I~\def\mathdef3908#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3908{)} \\ &&& \qquad
\Rightarrow\quad \href{../syntax/modules.html#syntax-import}{\mathsf{import}}~\mathit{nm}_1~\mathit{nm}_2~\mathit{xx} \\[1ex]
\end{array}\end{split}\]
Abbreviations
As an abbreviation, imports may also be specified inline with
tag,
global,
memory,
table, or
function
definitions; see the respective sections.
Exports
The syntax for exports mirrors their abstract syntax directly.
\[\begin{split}\begin{array}{llclll}
\def\mathdef3544#1{{}}\mathdef3544{export} & \href{../text/modules.html#text-export}{\mathtt{export}}_I &::=&
\def\mathdef3909#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3909{(}~\def\mathdef3910#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3910{export}~~\mathit{nm}{:}\href{../text/values.html#text-name}{\mathtt{name}}~~\mathit{xx}{:}\href{../text/modules.html#text-externidx}{\mathtt{externidx}}_I~\def\mathdef3911#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3911{)}
&\Rightarrow& \href{../syntax/modules.html#syntax-export}{\mathsf{export}}~\mathit{nm}~\mathit{xx} \} \\
\def\mathdef3544#1{{}}\mathdef3544{external index} & \href{../text/modules.html#text-externidx}{\mathtt{externidx}}_I &::=&
\def\mathdef3912#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3912{(}~\def\mathdef3913#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3913{tag}~~x{:}\href{../text/modules.html#text-tagidx}{\mathtt{tagidx}}_I~\def\mathdef3914#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3914{)}
&\Rightarrow& \href{../syntax/modules.html#syntax-externidx}{\mathsf{tag}}~x \\ &&|&
\def\mathdef3915#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3915{(}~\def\mathdef3916#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3916{global}~~x{:}\href{../text/modules.html#text-globalidx}{\mathtt{globalidx}}_I~\def\mathdef3917#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3917{)}
&\Rightarrow& \href{../syntax/modules.html#syntax-externidx}{\mathsf{global}}~x \\&&|&
\def\mathdef3918#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3918{(}~\def\mathdef3919#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3919{memory}~~x{:}\href{../text/modules.html#text-memidx}{\mathtt{memidx}}_I~\def\mathdef3920#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3920{)}
&\Rightarrow& \href{../syntax/modules.html#syntax-externidx}{\mathsf{memory}}~x \\ &&|&
\def\mathdef3921#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3921{(}~\def\mathdef3922#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3922{table}~~x{:}\href{../text/modules.html#text-tableidx}{\mathtt{tableidx}}_I~\def\mathdef3923#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3923{)}
&\Rightarrow& \href{../syntax/modules.html#syntax-externidx}{\mathsf{table}}~x \\ &&|&
\def\mathdef3924#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3924{(}~\def\mathdef3925#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3925{func}~~x{:}\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I~\def\mathdef3926#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3926{)}
&\Rightarrow& \href{../syntax/modules.html#syntax-externidx}{\mathsf{func}}~x \\
\end{array}\end{split}\]
Abbreviations
As an abbreviation, exports may also be specified inline with
tag,
global,
memory,
table, or
function
definitions; see the respective sections.
Modules
A module consists of a sequence of fields that can occur in any order.
All definitions and their respective bound identifiers scope over the entire module, including the text preceding them.
A module may optionally bind an identifier that names the module.
The name serves a documentary role only.
\[\begin{split}\begin{array}{lll}
\def\mathdef3544#1{{}}\mathdef3544{module} & \href{../text/modules.html#text-module}{\mathtt{module}} &
\begin{array}[t]{@{}cllll}
::=&
\def\mathdef3927#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3927{(}~\def\mathdef3928#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3928{module}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~(m{:}\href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}_I)^\ast~\def\mathdef3929#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3929{)}
\quad\Rightarrow\quad \href{../syntax/conventions.html#notation-compose}{\bigoplus} m^\ast \\
&\qquad (\mathrel{\mbox{if}} I = \href{../syntax/conventions.html#notation-compose}{\bigoplus} \mathrm{idc}(\href{../text/modules.html#text-modulefield}{\mathtt{modulefield}})^\ast ~\href{../text/conventions.html#text-context-wf}{\mbox{well-formed}}) \\
\end{array} \\[1ex]
\def\mathdef3544#1{{}}\mathdef3544{module field} & \href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}_I &
\begin{array}[t]{@{}clll}
::=&
\mathit{ty}^\ast{:}\href{../text/types.html#text-rectype}{\mathtt{rectype}}_I &\Rightarrow& \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~\mathit{ty}^\ast \\ |&
\mathit{im}{:}\href{../text/modules.html#text-import}{\mathtt{import}}_I &\Rightarrow& \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~\mathit{im} \\ |&
\mathit{tg}{:}\href{../text/modules.html#text-tag}{\mathtt{tag}}_I &\Rightarrow& \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~\mathit{tg} \\ |&
\mathit{gl}{:}\href{../text/modules.html#text-global}{\mathtt{global}}_I &\Rightarrow& \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~\mathit{gl} \\ |&
\mathit{me}{:}\href{../text/modules.html#text-mem}{\mathtt{mem}}_I &\Rightarrow& \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~\mathit{me} \\ |&
\mathit{ta}{:}\href{../text/modules.html#text-table}{\mathtt{table}}_I &\Rightarrow& \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~\mathit{ta} \\ |&
\mathit{fn}{:}\href{../text/modules.html#text-func}{\mathtt{func}}_I &\Rightarrow& \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~\mathit{fn} \\ |&
\mathit{da}{:}\href{../text/modules.html#text-data}{\mathtt{data}}_I &\Rightarrow& \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~\mathit{da} \\ |&
\mathit{el}{:}\href{../text/modules.html#text-elem}{\mathtt{elem}}_I &\Rightarrow& \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~\mathit{el} \\ |&
\mathit{st}{:}\href{../text/modules.html#text-start}{\mathtt{start}}_I &\Rightarrow& \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~\mathit{st} \\ |&
\mathit{ex}{:}\href{../text/modules.html#text-export}{\mathtt{export}}_I &\Rightarrow& \href{../syntax/modules.html#syntax-module}{\mathsf{module}}~\mathit{ex} \\
\end{array}
\end{array}\end{split}\]
where \(\href{../syntax/conventions.html#notation-compose}{\bigoplus} m^\ast\) is the module formed by the repeated concatenation of the indivual field sequences in order.
The following restrictions are imposed on this composition: \(m_1 \href{../syntax/conventions.html#notation-compose}{\oplus} m_2\) is defined if and only if
\(\href{../syntax/modules.html#syntax-start}{\mathit{start}}_1^? = \epsilon \vee \href{../syntax/modules.html#syntax-start}{\mathit{start}}_2^? = \epsilon\)
\(\href{../syntax/modules.html#syntax-tag}{\mathit{tag}}_1^\ast = \href{../syntax/modules.html#syntax-global}{\mathit{global}}_1^\ast = \href{../syntax/modules.html#syntax-mem}{\mathit{mem}}_1^\ast = \href{../syntax/modules.html#syntax-table}{\mathit{table}}_1^\ast = \href{../syntax/modules.html#syntax-func}{\mathit{func}}_1^\ast = \epsilon \vee \href{../syntax/modules.html#syntax-import}{\mathit{import}}_2^\ast = \epsilon\)
Note
The first condition ensures that there is at most one start function.
The second condition enforces that all imports must occur before any regular definition of a
tag,
global,
memory,
table, or
function,
thereby maintaining the ordering of the respective index spaces.
The well-formedness condition on \(I\) in the grammar for \(\href{../text/modules.html#text-module}{\mathtt{module}}\) ensures that no namespace contains duplicate identifiers.
The definition of the initial identifier context \(I\) uses the following auxiliary definition which maps each relevant definition to a singular context with one (possibly empty) identifier:
\[\begin{split}\begin{array}{@{}lcl@{\qquad\qquad}l}
\mathrm{idc}(\def\mathdef3930#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3930{(}~\def\mathdef3931#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3931{rec}~~\href{../text/types.html#text-typedef}{\mathtt{typedef}}^\ast~\def\mathdef3932#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3932{)}) &=&
\href{../syntax/conventions.html#notation-compose}{\bigoplus} \mathrm{idc}(\href{../text/types.html#text-typedef}{\mathtt{typedef}})^\ast \\
\mathrm{idc}(\def\mathdef3933#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3933{(}~\def\mathdef3934#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3934{type}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\href{../text/types.html#text-subtype}{\mathtt{subtype}}~\def\mathdef3935#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3935{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{types}}~(v^?), \href{../text/conventions.html#text-context}{\mathsf{fields}}~\mathrm{idf}(\href{../text/types.html#text-subtype}{\mathtt{subtype}}), \href{../text/conventions.html#text-context}{\mathsf{typedefs}}~\mathit{st}\} \\
\mathrm{idc}(\def\mathdef3936#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3936{(}~\def\mathdef3937#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3937{tag}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3938#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3938{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{tags}}~(v^?)\} \\
\mathrm{idc}(\def\mathdef3939#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3939{(}~\def\mathdef3940#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3940{global}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3941#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3941{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{globals}}~(v^?)\} \\
\mathrm{idc}(\def\mathdef3942#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3942{(}~\def\mathdef3943#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3943{memory}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3944#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3944{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{mems}}~(v^?)\} \\
\mathrm{idc}(\def\mathdef3945#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3945{(}~\def\mathdef3946#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3946{table}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3947#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3947{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{tables}}~(v^?)\} \\
\mathrm{idc}(\def\mathdef3948#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3948{(}~\def\mathdef3949#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3949{func}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3950#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3950{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{funcs}}~(v^?)\} \\
\mathrm{idc}(\def\mathdef3951#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3951{(}~\def\mathdef3952#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3952{data}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3953#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3953{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{datas}}~(v^?)\} \\
\mathrm{idc}(\def\mathdef3954#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3954{(}~\def\mathdef3955#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3955{elem}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3956#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3956{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{elems}}~(v^?)\} \\
\mathrm{idc}(\def\mathdef3957#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3957{(}~\def\mathdef3958#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3958{import}~\dots~\def\mathdef3959#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3959{(}~\def\mathdef3960#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3960{func}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3961#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3961{)}~\def\mathdef3962#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3962{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{funcs}}~(v^?)\} \\
\mathrm{idc}(\def\mathdef3963#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3963{(}~\def\mathdef3964#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3964{import}~\dots~\def\mathdef3965#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3965{(}~\def\mathdef3966#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3966{table}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3967#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3967{)}~\def\mathdef3968#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3968{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{tables}}~(v^?)\} \\
\mathrm{idc}(\def\mathdef3969#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3969{(}~\def\mathdef3970#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3970{import}~\dots~\def\mathdef3971#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3971{(}~\def\mathdef3972#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3972{memory}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3973#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3973{)}~\def\mathdef3974#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3974{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{mems}}~(v^?)\} \\
\mathrm{idc}(\def\mathdef3975#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3975{(}~\def\mathdef3976#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3976{import}~\dots~\def\mathdef3977#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3977{(}~\def\mathdef3978#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3978{global}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3979#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3979{)}~\def\mathdef3980#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3980{)}) &=&
\{\href{../text/conventions.html#text-context}{\mathsf{globals}}~(v^?)\} \\
\mathrm{idc}(\def\mathdef3981#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3981{(}~\dots~\def\mathdef3982#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3982{)}) &=&
\{\}
\\[2ex]
\mathrm{idf}(\def\mathdef3983#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3983{(}~\def\mathdef3984#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3984{sub}~\dots~\href{../text/types.html#text-comptype}{\mathtt{comptype}}~\def\mathdef3985#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3985{)}) &=&
\mathrm{idf}(\href{../text/types.html#text-comptype}{\mathtt{comptype}}) \\
\mathrm{idf}(\def\mathdef3986#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3986{(}~\def\mathdef3987#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3987{struct}~\mathit{Tfield}^\ast~\def\mathdef3988#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3988{)}) &=&
\href{../syntax/conventions.html#notation-compose}{\bigoplus} \mathrm{idf}(\href{../text/types.html#text-comptype}{\mathtt{field}})^\ast \\
\mathrm{idf}(\def\mathdef3989#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3989{(}~\def\mathdef3990#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3990{array}~\dots~\def\mathdef3991#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3991{)}) &=&
\epsilon \\
\mathrm{idf}(\def\mathdef3992#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3992{(}~\def\mathdef3993#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3993{func}~\dots~\def\mathdef3994#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3994{)}) &=&
\epsilon \\
\mathrm{idf}(\def\mathdef3995#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3995{(}~\def\mathdef3996#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3996{field}~v^?{:}\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3997#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3997{)}) &=&
v^? \\
\end{array}\end{split}\]
Abbreviations
In a source file, the toplevel \(\mathtt{(module}~\dots\mathtt{)}\) surrounding the module body may be omitted.
\[\begin{array}{llcll}
\def\mathdef3544#1{{}}\mathdef3544{module} &
\href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}^\ast &\equiv&
\def\mathdef3998#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3998{(}~\def\mathdef3999#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3999{module}~~\href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}^\ast~\def\mathdef4000#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef4000{)}
\end{array}\]