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\mathdef2721#1{{}}\mathdef2721{type index} & \href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2766#1{{\mathtt{u}#1}}\mathdef2766{\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\mathdef2721#1{{}}\mathdef2721{function index} & \href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2766#1{{\mathtt{u}#1}}\mathdef2766{\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\mathdef2721#1{{}}\mathdef2721{table index} & \href{../text/modules.html#text-tableidx}{\mathtt{tableidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2766#1{{\mathtt{u}#1}}\mathdef2766{\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\mathdef2721#1{{}}\mathdef2721{memory index} & \href{../text/modules.html#text-memidx}{\mathtt{memidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2766#1{{\mathtt{u}#1}}\mathdef2766{\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\mathdef2721#1{{}}\mathdef2721{global index} & \href{../text/modules.html#text-globalidx}{\mathtt{globalidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2766#1{{\mathtt{u}#1}}\mathdef2766{\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\mathdef2721#1{{}}\mathdef2721{local index} & \href{../text/modules.html#text-localidx}{\mathtt{localidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2766#1{{\mathtt{u}#1}}\mathdef2766{\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\mathdef2721#1{{}}\mathdef2721{label index} & \href{../text/modules.html#text-labelidx}{\mathtt{labelidx}}_I &::=& l{:}\href{../text/values.html#text-int}{\def\mathdef2766#1{{\mathtt{u}#1}}\mathdef2766{\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) \\ \end{array}\end{split}$

Types¶

Type definitions can bind a symbolic type identifier.

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{type definition} & \href{../text/modules.html#text-typedef}{\mathtt{type}} &::=& \def\mathdef2778#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2778{(}~\def\mathdef2779#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2779{type}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{ft}{:}\href{../text/types.html#text-functype}{\mathtt{functype}}~\def\mathdef2780#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2780{)} &\Rightarrow& \mathit{ft} \\ \end{array}\end{split}$

Type Uses¶

A type use is a reference to a type definition. It may optionally be augmented by explicit inlined parameter and result declarations. That allows binding symbolic identifiers to name the local indices of parameters. If inline declarations are given, then their types must match the referenced function type.

$\begin{split}\begin{array}{llcllll} \def\mathdef2721#1{{}}\mathdef2721{type use} & \href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}_I &::=& \def\mathdef2781#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2781{(}~\def\mathdef2782#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2782{type}~~x{:}\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}_I~\def\mathdef2783#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2783{)} \quad\Rightarrow\quad x, I' \\ &&& \qquad (\mathrel{\mbox{if}} \begin{array}[t]{@{}l@{}} I.\href{../text/conventions.html#text-context}{\mathsf{typedefs}}[x] = [t_1^n] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] \wedge I' = \{\href{../text/conventions.html#text-context}{\mathsf{locals}}~(\epsilon)^n\}) \\ \end{array} \\[1ex] &&|& \def\mathdef2784#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2784{(}~\def\mathdef2785#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2785{type}~~x{:}\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}_I~\def\mathdef2786#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2786{)} ~~(t_1{:}\href{../text/types.html#text-functype}{\mathtt{param}})^\ast~~(t_2{:}\href{../text/types.html#text-functype}{\mathtt{result}})^\ast \quad\Rightarrow\quad x, I' \\ &&& \qquad (\mathrel{\mbox{if}} \begin{array}[t]{@{}l@{}} I.\href{../text/conventions.html#text-context}{\mathsf{typedefs}}[x] = [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] \wedge I' = \{\href{../text/conventions.html#text-context}{\mathsf{locals}}~\mathrm{id}(\href{../text/types.html#text-functype}{\mathtt{param}})\}^\ast ~\href{../text/conventions.html#text-context-wf}{\mbox{well-formed}}) \\ \end{array} \\ \end{array}\end{split}$

The synthesized attribute of a $$\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}$$ is a pair consisting of both the used type index and the updated identifier context including possible parameter identifiers. The following auxiliary function extracts optional identifiers from parameters:

$\begin{split}\begin{array}{lcl@{\qquad\qquad}l} \mathrm{id}(\def\mathdef2787#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2787{(}~\def\mathdef2788#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2788{param}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef2789#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2789{)}) &=& \href{../text/values.html#text-id}{\mathtt{id}}^? \\ \end{array}\end{split}$

Note

Both productions overlap for the case that the function type is $$[] \href{../syntax/types.html#syntax-functype}{\rightarrow} []$$. However, in that case, they also produce the same results, so that the choice is immaterial.

The well-formedness condition on $$I'$$ ensures that the parameters do not contain duplicate identifier.

Abbreviations¶

A $$\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}$$ may also be replaced entirely by inline parameter and result declarations. In that case, a type index is automatically inserted:

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{type use} & (t_1{:}\href{../text/types.html#text-functype}{\mathtt{param}})^\ast~~(t_2{:}\href{../text/types.html#text-functype}{\mathtt{result}})^\ast &\equiv& \def\mathdef2790#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2790{(}~\def\mathdef2791#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2791{type}~~x~\def\mathdef2792#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2792{)}~~\href{../text/types.html#text-functype}{\mathtt{param}}^\ast~~\href{../text/types.html#text-functype}{\mathtt{result}}^\ast \\ \end{array}\end{split}$

where $$x$$ is the smallest existing type index whose definition in the current module is the function type $$[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]$$. If no such index exists, then a new type definition of the form

$\def\mathdef2793#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2793{(}~\def\mathdef2794#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2794{type}~~\def\mathdef2795#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2795{(}~\def\mathdef2796#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2796{func}~~\href{../text/types.html#text-functype}{\mathtt{param}}^\ast~~\href{../text/types.html#text-functype}{\mathtt{result}}~\def\mathdef2797#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2797{)}~\def\mathdef2798#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2798{)}$

is inserted at the end of the module.

Abbreviations are expanded in the order they appear, such that previously inserted type definitions are reused by consecutive expansions.

Imports¶

The descriptors in imports can bind a symbolic function, table, memory, or global identifier.

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{import} & \href{../text/modules.html#text-import}{\mathtt{import}}_I &::=& \def\mathdef2799#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2799{(}~\def\mathdef2800#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2800{import}~~\mathit{mod}{:}\href{../text/values.html#text-name}{\mathtt{name}}~~\mathit{nm}{:}\href{../text/values.html#text-name}{\mathtt{name}}~~d{:}\href{../text/modules.html#text-importdesc}{\mathtt{importdesc}}_I~\def\mathdef2801#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2801{)} \\ &&& \qquad \Rightarrow\quad \{ \href{../syntax/modules.html#syntax-import}{\mathsf{module}}~\mathit{mod}, \href{../syntax/modules.html#syntax-import}{\mathsf{name}}~\mathit{nm}, \href{../syntax/modules.html#syntax-import}{\mathsf{desc}}~d \} \\[1ex] \def\mathdef2721#1{{}}\mathdef2721{import description} & \href{../text/modules.html#text-importdesc}{\mathtt{importdesc}}_I &::=& \def\mathdef2802#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2802{(}~\def\mathdef2803#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2803{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~x,I'{:}\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}_I~\def\mathdef2804#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2804{)} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{func}}~x \\ &&|& \def\mathdef2805#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2805{(}~\def\mathdef2806#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2806{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{tt}{:}\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef2807#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2807{)} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{table}}~\mathit{tt} \\ &&|& \def\mathdef2808#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2808{(}~\def\mathdef2809#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2809{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{mt}{:}\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef2810#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2810{)} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{mem}}~~\mathit{mt} \\ &&|& \def\mathdef2811#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2811{(}~\def\mathdef2812#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2812{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{gt}{:}\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~\def\mathdef2813#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2813{)} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{global}}~\mathit{gt} \\ \end{array}\end{split}$

Abbreviations¶

As an abbreviation, imports may also be specified inline with function, table, memory, or global definitions; see the respective sections.

Functions¶

Function definitions can bind a symbolic function identifier, and local identifiers for its parameters and locals.

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{function} & \href{../text/modules.html#text-func}{\mathtt{func}}_I &::=& \def\mathdef2814#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2814{(}~\def\mathdef2815#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2815{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~x,I'{:}\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}_I~~ (t{:}\href{../text/modules.html#text-local}{\mathtt{local}})^\ast~~(\mathit{in}{:}\href{../text/instructions.html#text-instr}{\mathtt{instr}}_{I''})^\ast~\def\mathdef2816#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2816{)} \\ &&& \qquad \Rightarrow\quad \{ \href{../syntax/modules.html#syntax-func}{\mathsf{type}}~x, \href{../syntax/modules.html#syntax-func}{\mathsf{locals}}~t^\ast, \href{../syntax/modules.html#syntax-func}{\mathsf{body}}~\mathit{in}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} \} \\ &&& \qquad\qquad\qquad (\mathrel{\mbox{if}} I'' = 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\mathdef2721#1{{}}\mathdef2721{local} & \href{../text/modules.html#text-local}{\mathtt{local}} &::=& \def\mathdef2817#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2817{(}~\def\mathdef2818#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2818{local}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~t{:}\href{../text/types.html#text-valtype}{\mathtt{valtype}}~\def\mathdef2819#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2819{)} \quad\Rightarrow\quad 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\mathdef2820#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2820{(}~\def\mathdef2821#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2821{local}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef2822#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2822{)}) &=& \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\mathdef2721#1{{}}\mathdef2721{local} & \def\mathdef2823#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2823{(}~~\def\mathdef2824#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2824{local}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}^\ast~~\def\mathdef2825#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2825{)} &\equiv& (\def\mathdef2826#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2826{(}~~\def\mathdef2827#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2827{local}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}~~\def\mathdef2828#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2828{)})^\ast \\ \end{array}\end{split}$

Moreover, functions can be defined as imports or exports inline:

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{module field} & \def\mathdef2829#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2829{(}~\def\mathdef2830#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2830{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2831#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2831{(}~\def\mathdef2832#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2832{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef2833#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2833{)}~~\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}~\def\mathdef2834#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2834{)} \quad\equiv \\ & \qquad \def\mathdef2835#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2835{(}~\def\mathdef2836#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2836{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef2837#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2837{(}~\def\mathdef2838#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2838{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}~\def\mathdef2839#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2839{)}~\def\mathdef2840#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2840{)} \\[1ex] & \def\mathdef2841#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2841{(}~\def\mathdef2842#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2842{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2843#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2843{(}~\def\mathdef2844#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2844{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef2845#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2845{)}~~\dots~\def\mathdef2846#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2846{)} \quad\equiv \\ & \qquad \def\mathdef2847#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2847{(}~\def\mathdef2848#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2848{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef2849#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2849{(}~\def\mathdef2850#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2850{func}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef2851#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2851{)}~\def\mathdef2852#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2852{)}~~ \def\mathdef2853#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2853{(}~\def\mathdef2854#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2854{func}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef2855#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2855{)} \\ & \qquad\qquad (\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \vee \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}) \\ \end{array}\end{split}$

The latter abbreviation can be applied repeatedly, with “$$\dots$$” containing another import or export.

Tables¶

Table definitions can bind a symbolic table identifier.

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{table} & \href{../text/modules.html#text-table}{\mathtt{table}}_I &::=& \def\mathdef2856#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2856{(}~\def\mathdef2857#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2857{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{tt}{:}\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef2858#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2858{)} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-table}{\mathsf{type}}~\mathit{tt} \} \\ \end{array}\end{split}$

Abbreviations¶

An element segment can be given inline with a table definition, in which case the limits of the table type are inferred from the length of the given segment:

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{module field} & \def\mathdef2859#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2859{(}~\def\mathdef2860#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2860{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-elemtype}{\mathtt{elemtype}}~~\def\mathdef2861#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2861{(}~\def\mathdef2862#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2862{elem}~~x^n{:}\href{../text/conventions.html#text-vec}{\mathtt{vec}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}})~\def\mathdef2863#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2863{)}~~\def\mathdef2864#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2864{)} \quad\equiv \\ & \qquad \def\mathdef2865#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2865{(}~\def\mathdef2866#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2866{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~n~~n~~\href{../text/types.html#text-elemtype}{\mathtt{elemtype}}~\def\mathdef2867#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2867{)}~~ \def\mathdef2868#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2868{(}~\def\mathdef2869#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2869{elem}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\def\mathdef2870#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2870{(}~\def\mathdef2871#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2871{i32.const}~~\def\mathdef2872#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2872{0}~\def\mathdef2873#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2873{)}~~\href{../text/conventions.html#text-vec}{\mathtt{vec}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}})~\def\mathdef2874#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2874{)} \\ & \qquad\qquad (\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \vee \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}) \\ \end{array}\end{split}$

Moreover, tables can be defined as imports or exports inline:

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{module field} & \def\mathdef2875#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2875{(}~\def\mathdef2876#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2876{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2877#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2877{(}~\def\mathdef2878#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2878{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef2879#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2879{)}~~\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef2880#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2880{)} \quad\equiv \\ & \qquad \def\mathdef2881#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2881{(}~\def\mathdef2882#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2882{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef2883#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2883{(}~\def\mathdef2884#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2884{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef2885#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2885{)}~\def\mathdef2886#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2886{)} \\[1ex] & \def\mathdef2887#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2887{(}~\def\mathdef2888#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2888{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2889#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2889{(}~\def\mathdef2890#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2890{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef2891#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2891{)}~~\dots~\def\mathdef2892#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2892{)} \quad\equiv \\ & \qquad \def\mathdef2893#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2893{(}~\def\mathdef2894#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2894{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef2895#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2895{(}~\def\mathdef2896#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2896{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef2897#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2897{)}~\def\mathdef2898#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2898{)}~~ \def\mathdef2899#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2899{(}~\def\mathdef2900#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2900{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef2901#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2901{)} \\ & \qquad\qquad (\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \vee \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}) \\ \end{array}\end{split}$

The latter abbreviation can be applied repeatedly, with “$$\dots$$” containing another import or export or an inline elements segment.

Memories¶

Memory definitions can bind a symbolic memory identifier.

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{memory} & \href{../text/modules.html#text-mem}{\mathtt{mem}}_I &::=& \def\mathdef2902#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2902{(}~\def\mathdef2903#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2903{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{mt}{:}\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef2904#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2904{)} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-mem}{\mathsf{type}}~\mathit{mt} \} \\ \end{array}\end{split}$

Abbreviations¶

A data segment can be given inline with a memory definition, in which case 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\mathdef2721#1{{}}\mathdef2721{module field} & \def\mathdef2905#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2905{(}~\def\mathdef2906#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2906{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2907#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2907{(}~\def\mathdef2908#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2908{data}~~b^n{:}\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef2909#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2909{)}~~\def\mathdef2910#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2910{)} \quad\equiv \\ & \qquad \def\mathdef2911#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2911{(}~\def\mathdef2912#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2912{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~m~~m~\def\mathdef2913#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2913{)}~~ \def\mathdef2914#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2914{(}~\def\mathdef2915#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2915{data}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\def\mathdef2916#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2916{(}~\def\mathdef2917#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2917{i32.const}~~\def\mathdef2918#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2918{0}~\def\mathdef2919#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2919{)}~~\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef2920#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2920{)} \\ & \qquad\qquad (\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \vee \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}, m = \mathrm{ceil}(n / 64\mathrm{Ki})) \\ \end{array}\end{split}$

Moreover, memories can be defined as imports or exports inline:

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{module field} & \def\mathdef2921#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2921{(}~\def\mathdef2922#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2922{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2923#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2923{(}~\def\mathdef2924#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2924{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef2925#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2925{)}~~\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef2926#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2926{)} \quad\equiv \\ & \qquad \def\mathdef2927#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2927{(}~\def\mathdef2928#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2928{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef2929#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2929{(}~\def\mathdef2930#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2930{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef2931#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2931{)}~\def\mathdef2932#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2932{)} \\[1ex] & \def\mathdef2933#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2933{(}~\def\mathdef2934#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2934{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2935#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2935{(}~\def\mathdef2936#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2936{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef2937#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2937{)}~~\dots~\def\mathdef2938#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2938{)} \quad\equiv \\ & \qquad \def\mathdef2939#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2939{(}~\def\mathdef2940#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2940{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef2941#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2941{(}~\def\mathdef2942#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2942{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef2943#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2943{)}~\def\mathdef2944#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2944{)}~~ \def\mathdef2945#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2945{(}~\def\mathdef2946#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2946{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef2947#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2947{)} \\ & \qquad\qquad (\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \vee \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}) \\ \end{array}\end{split}$

The latter abbreviation can be applied repeatedly, with “$$\dots$$” containing another import or export or an inline data segment.

Globals¶

Global definitions can bind a symbolic global identifier.

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{global} & \href{../text/modules.html#text-global}{\mathtt{global}}_I &::=& \def\mathdef2948#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2948{(}~\def\mathdef2949#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2949{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{gt}{:}\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~~e{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef2950#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2950{)} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-global}{\mathsf{type}}~\mathit{gt}, \href{../syntax/modules.html#syntax-global}{\mathsf{init}}~e \} \\ \end{array}\end{split}$

Abbreviations¶

Globals can be defined as imports or exports inline:

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{module field} & \def\mathdef2951#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2951{(}~\def\mathdef2952#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2952{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2953#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2953{(}~\def\mathdef2954#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2954{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef2955#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2955{)}~~\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~\def\mathdef2956#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2956{)} \quad\equiv \\ & \qquad \def\mathdef2957#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2957{(}~\def\mathdef2958#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2958{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef2959#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2959{(}~\def\mathdef2960#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2960{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~\def\mathdef2961#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2961{)}~\def\mathdef2962#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2962{)} \\[1ex] & \def\mathdef2963#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2963{(}~\def\mathdef2964#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2964{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2965#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2965{(}~\def\mathdef2966#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2966{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef2967#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2967{)}~~\dots~\def\mathdef2968#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2968{)} \quad\equiv \\ & \qquad \def\mathdef2969#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2969{(}~\def\mathdef2970#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2970{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef2971#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2971{(}~\def\mathdef2972#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2972{global}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef2973#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2973{)}~\def\mathdef2974#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2974{)}~~ \def\mathdef2975#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2975{(}~\def\mathdef2976#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2976{global}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef2977#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2977{)} \\ & \qquad\qquad (\mathrel{\mbox{if}} \href{../text/values.html#text-id}{\mathtt{id}}' = \href{../text/values.html#text-id}{\mathtt{id}}^? \neq \epsilon \vee \href{../text/values.html#text-id}{\mathtt{id}}' ~\href{../text/values.html#text-id-fresh}{\mbox{fresh}}) \\ \end{array}\end{split}$

The latter abbreviation can be applied repeatedly, with “$$\dots$$” containing another import or export.

Exports¶

The syntax for exports mirrors their abstract syntax directly.

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{export} & \href{../text/modules.html#text-export}{\mathtt{export}}_I &::=& \def\mathdef2978#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2978{(}~\def\mathdef2979#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2979{export}~~\mathit{nm}{:}\href{../text/values.html#text-name}{\mathtt{name}}~~d{:}\href{../text/modules.html#text-exportdesc}{\mathtt{exportdesc}}_I~\def\mathdef2980#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2980{)} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-export}{\mathsf{name}}~\mathit{nm}, \href{../syntax/modules.html#syntax-export}{\mathsf{desc}}~d \} \\ \def\mathdef2721#1{{}}\mathdef2721{export description} & \href{../text/modules.html#text-exportdesc}{\mathtt{exportdesc}}_I &::=& \def\mathdef2981#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2981{(}~\def\mathdef2982#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2982{func}~~x{:}\href{../binary/modules.html#binary-funcidx}{\mathtt{funcidx}}_I~\def\mathdef2983#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2983{)} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{func}}~x \\ &&|& \def\mathdef2984#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2984{(}~\def\mathdef2985#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2985{table}~~x{:}\href{../binary/modules.html#binary-tableidx}{\mathtt{tableidx}}_I~\def\mathdef2986#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2986{)} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{table}}~x \\ &&|& \def\mathdef2987#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2987{(}~\def\mathdef2988#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2988{memory}~~x{:}\href{../binary/modules.html#binary-memidx}{\mathtt{memidx}}_I~\def\mathdef2989#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2989{)} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{mem}}~x \\ &&|& \def\mathdef2990#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2990{(}~\def\mathdef2991#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2991{global}~~x{:}\href{../binary/modules.html#binary-globalidx}{\mathtt{globalidx}}_I~\def\mathdef2992#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2992{)} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{global}}~x \\ \end{array}\end{split}$

Abbreviations¶

As an abbreviation, exports may also be specified inline with function, table, memory, or global definitions; see the respective sections.

Start Function¶

A start function is defined in terms of its index.

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{start function} & \href{../text/modules.html#text-start}{\mathtt{start}}_I &::=& \def\mathdef2993#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2993{(}~\def\mathdef2994#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2994{start}~~x{:}\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I~\def\mathdef2995#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2995{)} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-start}{\mathsf{func}}~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.

Element Segments¶

Element segments allow for an optional table index to identify the table to initialize. When omitted, $$\mathtt{0}$$ is assumed.

$\begin{split}\begin{array}{llclll} \def\mathdef2721#1{{}}\mathdef2721{element segment} & \href{../text/modules.html#text-elem}{\mathtt{elem}}_I &::=& \def\mathdef2996#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2996{(}~\def\mathdef2997#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2997{elem}~~(x{:}\href{../text/modules.html#text-tableidx}{\mathtt{tableidx}}_I)^?~~\def\mathdef2998#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2998{(}~\def\mathdef2999#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2999{offset}~~e{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef3000#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3000{)}~~y^\ast{:}\href{../text/conventions.html#text-vec}{\mathtt{vec}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I)~\def\mathdef3001#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3001{)} \\ &&& \qquad \Rightarrow\quad \{ \href{../syntax/modules.html#syntax-elem}{\mathsf{table}}~x', \href{../syntax/modules.html#syntax-elem}{\mathsf{offset}}~e, \href{../syntax/modules.html#syntax-elem}{\mathsf{init}}~y^\ast \} \\ &&& \qquad\qquad\qquad (\mathrel{\mbox{if}} x' = x^? \neq \epsilon \vee x' = 0) \\ \end{array}\end{split}$

Note

In the current version of WebAssembly, the only valid table index is 0 or a symbolic table identifier resolving to the same value.

Abbreviations¶

As an abbreviation, a single instruction may occur in place of the offset:

$\begin{array}{llcll} \def\mathdef2721#1{{}}\mathdef2721{element offset} & \href{../text/instructions.html#text-instr}{\mathtt{instr}} &\equiv& \def\mathdef3002#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3002{(}~\def\mathdef3003#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3003{offset}~~\href{../text/instructions.html#text-instr}{\mathtt{instr}}~\def\mathdef3004#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3004{)} \end{array}$

As another abbreviation, element segments may also be specified inline with table definitions; see the respective section.

Data Segments¶

Data segments allow for an optional memory index to identify the memory to initialize. When omitted, $$\mathtt{0}$$ is assumed. 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\mathdef2721#1{{}}\mathdef2721{data segment} & \href{../text/modules.html#text-data}{\mathtt{data}}_I &::=& \def\mathdef3005#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3005{(}~\def\mathdef3006#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3006{data}~~(x{:}\href{../text/modules.html#text-memidx}{\mathtt{memidx}}_I)^?~~\def\mathdef3007#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3007{(}~\def\mathdef3008#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3008{offset}~~e{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef3009#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3009{)}~~b^\ast{:}\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef3010#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3010{)} \\ &&& \qquad \Rightarrow\quad \{ \href{../syntax/modules.html#syntax-data}{\mathsf{data}}~x', \href{../syntax/modules.html#syntax-data}{\mathsf{offset}}~e, \href{../syntax/modules.html#syntax-data}{\mathsf{init}}~b^\ast \} \\ &&& \qquad\qquad\qquad (\mathrel{\mbox{if}} x' = x^? \neq \epsilon \vee x' = 0) \\[1ex] \def\mathdef2721#1{{}}\mathdef2721{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}{\mathrm{concat}}((b^\ast)^\ast) \\ \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 instruction may occur in place of the offset:

$\begin{array}{llcll} \def\mathdef2721#1{{}}\mathdef2721{data offset} & \href{../text/instructions.html#text-instr}{\mathtt{instr}} &\equiv& \def\mathdef3011#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3011{(}~\def\mathdef3012#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3012{offset}~~\href{../text/instructions.html#text-instr}{\mathtt{instr}}~\def\mathdef3013#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3013{)} \end{array}$

As another abbreviation, data segments may also be specified inline with memory definitions; see the respective section.

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.

Note

Tools may include the module name in the name section of the binary format.

$\begin{split}\begin{array}{lll} \def\mathdef2721#1{{}}\mathdef2721{module} & \href{../text/modules.html#text-module}{\mathtt{module}} & \begin{array}[t]{@{}cllll} ::=& \def\mathdef3014#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3014{(}~\def\mathdef3015#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3015{module}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~(m{:}\href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}_I)^\ast~\def\mathdef3016#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3016{)} \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\mathdef2721#1{{}}\mathdef2721{module field} & \href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}_I & \begin{array}[t]{@{}clll} ::=& \mathit{ty}{:}\href{../text/modules.html#text-typedef}{\mathtt{type}} &\Rightarrow& \{\href{../syntax/modules.html#syntax-module}{\mathsf{types}}~\mathit{ty}\} \\ |& \mathit{im}{:}\href{../text/modules.html#text-import}{\mathtt{import}}_I &\Rightarrow& \{\href{../syntax/modules.html#syntax-module}{\mathsf{imports}}~\mathit{im}\} \\ |& \mathit{fn}{:}\href{../text/modules.html#text-func}{\mathtt{func}}_I &\Rightarrow& \{\href{../syntax/modules.html#syntax-module}{\mathsf{funcs}}~\mathit{fn}\} \\ |& \mathit{ta}{:}\href{../text/modules.html#text-table}{\mathtt{table}}_I &\Rightarrow& \{\href{../syntax/modules.html#syntax-module}{\mathsf{tables}}~\mathit{ta}\} \\ |& \mathit{me}{:}\href{../text/modules.html#text-mem}{\mathtt{mem}}_I &\Rightarrow& \{\href{../syntax/modules.html#syntax-module}{\mathsf{mems}}~\mathit{me}\} \\ |& \mathit{gl}{:}\href{../text/modules.html#text-global}{\mathtt{global}}_I &\Rightarrow& \{\href{../syntax/modules.html#syntax-module}{\mathsf{globals}}~\mathit{gl}\} \\ |& \mathit{ex}{:}\href{../text/modules.html#text-export}{\mathtt{export}}_I &\Rightarrow& \{\href{../syntax/modules.html#syntax-module}{\mathsf{exports}}~\mathit{ex}\} \\ |& \mathit{st}{:}\href{../text/modules.html#text-start}{\mathtt{start}}_I &\Rightarrow& \{\href{../syntax/modules.html#syntax-module}{\mathsf{start}}~\mathit{st}\} \\ |& \mathit{el}{:}\href{../text/modules.html#text-elem}{\mathtt{elem}}_I &\Rightarrow& \{\href{../syntax/modules.html#syntax-module}{\mathsf{elem}}~\mathit{el}\} \\ |& \mathit{da}{:}\href{../text/modules.html#text-data}{\mathtt{data}}_I &\Rightarrow& \{\href{../syntax/modules.html#syntax-module}{\mathsf{data}}~\mathit{da}\} \\ \end{array} \end{array}\end{split}$

The following restrictions are imposed on the composition of modules: $$m_1 \href{../syntax/conventions.html#notation-compose}{\oplus} m_2$$ is defined if and only if

• $$m_1.\href{../syntax/modules.html#syntax-module}{\mathsf{start}} = \epsilon \vee m_2.\href{../syntax/modules.html#syntax-module}{\mathsf{start}} = \epsilon$$
• $$m_1.\href{../syntax/modules.html#syntax-module}{\mathsf{funcs}} = m_1.\href{../syntax/modules.html#syntax-module}{\mathsf{tables}} = m_1.\href{../syntax/modules.html#syntax-module}{\mathsf{mems}} = m_1.\href{../syntax/modules.html#syntax-module}{\mathsf{globals}} = \epsilon \vee m_2.\href{../syntax/modules.html#syntax-module}{\mathsf{imports}} = \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 function, table, memory, or global, 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\mathdef3017#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3017{(}~\def\mathdef3018#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3018{type}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\mathit{ft}{:}\href{../text/types.html#text-functype}{\mathtt{functype}}~\def\mathdef3019#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3019{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{types}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?), \href{../text/conventions.html#text-context}{\mathsf{typedefs}}~\mathit{ft}\} \\ \mathrm{idc}(\def\mathdef3020#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3020{(}~\def\mathdef3021#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3021{func}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3022#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3022{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{funcs}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3023#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3023{(}~\def\mathdef3024#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3024{table}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3025#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3025{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{tables}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3026#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3026{(}~\def\mathdef3027#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3027{memory}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3028#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3028{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{mems}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3029#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3029{(}~\def\mathdef3030#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3030{global}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3031#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3031{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{globals}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3032#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3032{(}~\def\mathdef3033#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3033{import}~\dots~\def\mathdef3034#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3034{(}~\def\mathdef3035#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3035{func}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3036#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3036{)}~\def\mathdef3037#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3037{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{funcs}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3038#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3038{(}~\def\mathdef3039#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3039{import}~\dots~\def\mathdef3040#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3040{(}~\def\mathdef3041#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3041{table}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3042#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3042{)}~\def\mathdef3043#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3043{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{tables}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3044#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3044{(}~\def\mathdef3045#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3045{import}~\dots~\def\mathdef3046#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3046{(}~\def\mathdef3047#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3047{memory}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3048#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3048{)}~\def\mathdef3049#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3049{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{mems}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3050#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3050{(}~\def\mathdef3051#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3051{import}~\dots~\def\mathdef3052#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3052{(}~\def\mathdef3053#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3053{global}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3054#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3054{)}~\def\mathdef3055#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3055{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{globals}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3056#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3056{(}~\dots~\def\mathdef3057#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3057{)}) &=& \{\} \\ \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\mathdef2721#1{{}}\mathdef2721{module} & \href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}^\ast &\equiv& \def\mathdef3058#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3058{(}~\def\mathdef3059#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3059{module}~~\href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}^\ast~\def\mathdef3060#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3060{)} \end{array}$