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\mathdef2569#1{{}}\mathdef2569{type index} & \href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2615#1{{\mathtt{u}#1}}\mathdef2615{\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\mathdef2569#1{{}}\mathdef2569{function index} & \href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2615#1{{\mathtt{u}#1}}\mathdef2615{\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\mathdef2569#1{{}}\mathdef2569{table index} & \href{../text/modules.html#text-tableidx}{\mathtt{tableidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2615#1{{\mathtt{u}#1}}\mathdef2615{\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\mathdef2569#1{{}}\mathdef2569{memory index} & \href{../text/modules.html#text-memidx}{\mathtt{memidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2615#1{{\mathtt{u}#1}}\mathdef2615{\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\mathdef2569#1{{}}\mathdef2569{global index} & \href{../text/modules.html#text-globalidx}{\mathtt{globalidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2615#1{{\mathtt{u}#1}}\mathdef2615{\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\mathdef2569#1{{}}\mathdef2569{local index} & \href{../text/modules.html#text-localidx}{\mathtt{localidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef2615#1{{\mathtt{u}#1}}\mathdef2615{\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\mathdef2569#1{{}}\mathdef2569{label index} & \href{../text/modules.html#text-labelidx}{\mathtt{labelidx}}_I &::=& l{:}\href{../text/values.html#text-int}{\def\mathdef2615#1{{\mathtt{u}#1}}\mathdef2615{\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\mathdef2569#1{{}}\mathdef2569{type definition} & \href{../text/modules.html#text-typedef}{\mathtt{type}} &::=& \def\mathdef2627#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2627{(}~\def\mathdef2628#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2628{type}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{ft}{:}\href{../text/types.html#text-functype}{\mathtt{functype}}~\def\mathdef2629#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2629{)} &\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\mathdef2569#1{{}}\mathdef2569{type use} & \href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}_I &::=& \def\mathdef2630#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2630{(}~\def\mathdef2631#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2631{type}~~x{:}\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}_I~\def\mathdef2632#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2632{)} \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] \to [t_2^\ast] \wedge I' = \{\href{../text/conventions.html#text-context}{\mathsf{locals}}~(\epsilon)^n\}) \\ \end{array} \\[1ex] &&|& \def\mathdef2633#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2633{(}~\def\mathdef2634#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2634{type}~~x{:}\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}_I~\def\mathdef2635#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2635{)} ~~(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] \to [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\mathdef2636#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2636{(}~\def\mathdef2637#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2637{param}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef2638#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2638{)}) &=& \href{../text/values.html#text-id}{\mathtt{id}}^? \\ \end{array}\end{split}\]

Note

Both productions overlap for the case that the function type is \([] \to []\). 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\mathdef2569#1{{}}\mathdef2569{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\mathdef2639#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2639{(}~\def\mathdef2640#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2640{type}~~x~\def\mathdef2641#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2641{)}~~\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] \to [t_2^\ast]\). If no such index exists, then a new type definition of the form

\[\def\mathdef2642#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2642{(}~\def\mathdef2643#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2643{type}~~\def\mathdef2644#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2644{(}~\def\mathdef2645#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2645{func}~~\href{../text/types.html#text-functype}{\mathtt{param}}^\ast~~\href{../text/types.html#text-functype}{\mathtt{result}}~\def\mathdef2646#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2646{)}~\def\mathdef2647#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2647{)}\]

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\mathdef2569#1{{}}\mathdef2569{import} & \href{../text/modules.html#text-import}{\mathtt{import}}_I &::=& \def\mathdef2648#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2648{(}~\def\mathdef2649#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2649{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\mathdef2650#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2650{)} \\ &&& \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\mathdef2569#1{{}}\mathdef2569{import description} & \href{../text/modules.html#text-importdesc}{\mathtt{importdesc}}_I &::=& \def\mathdef2651#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2651{(}~\def\mathdef2652#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2652{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~x,I'{:}\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}_I~\def\mathdef2653#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2653{)} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{func}}~x \\ &&|& \def\mathdef2654#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2654{(}~\def\mathdef2655#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2655{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{tt}{:}\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef2656#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2656{)} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{table}}~\mathit{tt} \\ &&|& \def\mathdef2657#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2657{(}~\def\mathdef2658#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2658{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{mt}{:}\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef2659#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2659{)} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{mem}}~~\mathit{mt} \\ &&|& \def\mathdef2660#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2660{(}~\def\mathdef2661#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2661{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{gt}{:}\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~\def\mathdef2662#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2662{)} &\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\mathdef2569#1{{}}\mathdef2569{function} & \href{../text/modules.html#text-func}{\mathtt{func}}_I &::=& \def\mathdef2663#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2663{(}~\def\mathdef2664#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2664{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\mathdef2665#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2665{)} \\ &&& \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\mathdef2569#1{{}}\mathdef2569{local} & \href{../text/modules.html#text-local}{\mathtt{local}} &::=& \def\mathdef2666#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2666{(}~\def\mathdef2667#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2667{local}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~t{:}\href{../text/types.html#text-valtype}{\mathtt{valtype}}~\def\mathdef2668#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2668{)} \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\mathdef2669#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2669{(}~\def\mathdef2670#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2670{local}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef2671#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2671{)}) &=& \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\mathdef2569#1{{}}\mathdef2569{local} & \def\mathdef2672#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2672{(}~~\def\mathdef2673#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2673{local}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}^\ast~~\def\mathdef2674#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2674{)} &\equiv& (\def\mathdef2675#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2675{(}~~\def\mathdef2676#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2676{local}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}~~\def\mathdef2677#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2677{)})^\ast \\ \end{array}\end{split}\]

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

\[\begin{split}\begin{array}{llclll} \def\mathdef2569#1{{}}\mathdef2569{module field} & \def\mathdef2678#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2678{(}~\def\mathdef2679#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2679{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2680#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2680{(}~\def\mathdef2681#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2681{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef2682#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2682{)}~~\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}~\def\mathdef2683#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2683{)} \quad\equiv \\ & \qquad \def\mathdef2684#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2684{(}~\def\mathdef2685#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2685{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef2686#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2686{(}~\def\mathdef2687#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2687{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}~\def\mathdef2688#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2688{)}~\def\mathdef2689#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2689{)} \\[1ex] & \def\mathdef2690#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2690{(}~\def\mathdef2691#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2691{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2692#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2692{(}~\def\mathdef2693#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2693{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef2694#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2694{)}~~\dots~\def\mathdef2695#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2695{)} \quad\equiv \\ & \qquad \def\mathdef2696#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2696{(}~\def\mathdef2697#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2697{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef2698#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2698{(}~\def\mathdef2699#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2699{func}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef2700#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2700{)}~\def\mathdef2701#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2701{)}~~ \def\mathdef2702#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2702{(}~\def\mathdef2703#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2703{func}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef2704#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2704{)} \\ & \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\mathdef2569#1{{}}\mathdef2569{table} & \href{../text/modules.html#text-table}{\mathtt{table}}_I &::=& \def\mathdef2705#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2705{(}~\def\mathdef2706#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2706{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{tt}{:}\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef2707#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2707{)} &\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\mathdef2569#1{{}}\mathdef2569{module field} & \def\mathdef2708#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2708{(}~\def\mathdef2709#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2709{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-elemtype}{\mathtt{elemtype}}~~\def\mathdef2710#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2710{(}~\def\mathdef2711#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2711{elem}~~x^n{:}\href{../text/conventions.html#text-vec}{\mathtt{vec}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}})~\def\mathdef2712#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2712{)}~~\def\mathdef2713#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2713{)} \quad\equiv \\ & \qquad \def\mathdef2714#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2714{(}~\def\mathdef2715#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2715{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~n~~n~~\href{../text/types.html#text-elemtype}{\mathtt{elemtype}}~\def\mathdef2716#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2716{)}~~ \def\mathdef2717#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2717{(}~\def\mathdef2718#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2718{elem}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\def\mathdef2719#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2719{(}~\def\mathdef2720#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2720{i32.const}~~\def\mathdef2721#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2721{0}~\def\mathdef2722#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2722{)}~~\href{../text/conventions.html#text-vec}{\mathtt{vec}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}})~\def\mathdef2723#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2723{)} \\ & \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\mathdef2569#1{{}}\mathdef2569{module field} & \def\mathdef2724#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2724{(}~\def\mathdef2725#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2725{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2726#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2726{(}~\def\mathdef2727#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2727{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef2728#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2728{)}~~\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef2729#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2729{)} \quad\equiv \\ & \qquad \def\mathdef2730#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2730{(}~\def\mathdef2731#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2731{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef2732#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2732{(}~\def\mathdef2733#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2733{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef2734#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2734{)}~\def\mathdef2735#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2735{)} \\[1ex] & \def\mathdef2736#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2736{(}~\def\mathdef2737#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2737{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2738#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2738{(}~\def\mathdef2739#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2739{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef2740#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2740{)}~~\dots~\def\mathdef2741#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2741{)} \quad\equiv \\ & \qquad \def\mathdef2742#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2742{(}~\def\mathdef2743#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2743{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef2744#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2744{(}~\def\mathdef2745#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2745{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef2746#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2746{)}~\def\mathdef2747#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2747{)}~~ \def\mathdef2748#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2748{(}~\def\mathdef2749#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2749{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef2750#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2750{)} \\ & \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\mathdef2569#1{{}}\mathdef2569{memory} & \href{../text/modules.html#text-mem}{\mathtt{mem}}_I &::=& \def\mathdef2751#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2751{(}~\def\mathdef2752#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2752{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{mt}{:}\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef2753#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2753{)} &\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\mathdef2569#1{{}}\mathdef2569{module field} & \def\mathdef2754#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2754{(}~\def\mathdef2755#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2755{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2756#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2756{(}~\def\mathdef2757#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2757{data}~~b^n{:}\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef2758#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2758{)}~~\def\mathdef2759#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2759{)} \quad\equiv \\ & \qquad \def\mathdef2760#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2760{(}~\def\mathdef2761#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2761{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~m~~m~\def\mathdef2762#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2762{)}~~ \def\mathdef2763#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2763{(}~\def\mathdef2764#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2764{data}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\def\mathdef2765#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2765{(}~\def\mathdef2766#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2766{i32.const}~~\def\mathdef2767#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2767{0}~\def\mathdef2768#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2768{)}~~\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef2769#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2769{)} \\ & \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\mathdef2569#1{{}}\mathdef2569{module field} & \def\mathdef2770#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2770{(}~\def\mathdef2771#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2771{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2772#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2772{(}~\def\mathdef2773#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2773{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef2774#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2774{)}~~\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef2775#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2775{)} \quad\equiv \\ & \qquad \def\mathdef2776#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2776{(}~\def\mathdef2777#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2777{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef2778#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2778{(}~\def\mathdef2779#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2779{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef2780#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2780{)}~\def\mathdef2781#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2781{)} \\[1ex] & \def\mathdef2782#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2782{(}~\def\mathdef2783#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2783{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2784#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2784{(}~\def\mathdef2785#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2785{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef2786#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2786{)}~~\dots~\def\mathdef2787#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2787{)} \quad\equiv \\ & \qquad \def\mathdef2788#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2788{(}~\def\mathdef2789#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2789{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef2790#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2790{(}~\def\mathdef2791#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2791{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef2792#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2792{)}~\def\mathdef2793#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2793{)}~~ \def\mathdef2794#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2794{(}~\def\mathdef2795#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2795{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef2796#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2796{)} \\ & \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\mathdef2569#1{{}}\mathdef2569{global} & \href{../text/modules.html#text-global}{\mathtt{global}}_I &::=& \def\mathdef2797#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2797{(}~\def\mathdef2798#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2798{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\mathdef2799#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2799{)} &\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\mathdef2569#1{{}}\mathdef2569{module field} & \def\mathdef2800#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2800{(}~\def\mathdef2801#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2801{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2802#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2802{(}~\def\mathdef2803#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2803{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef2804#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2804{)}~~\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~\def\mathdef2805#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2805{)} \quad\equiv \\ & \qquad \def\mathdef2806#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2806{(}~\def\mathdef2807#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2807{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef2808#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2808{(}~\def\mathdef2809#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2809{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~\def\mathdef2810#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2810{)}~\def\mathdef2811#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2811{)} \\[1ex] & \def\mathdef2812#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2812{(}~\def\mathdef2813#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2813{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef2814#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2814{(}~\def\mathdef2815#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2815{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef2816#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2816{)}~~\dots~\def\mathdef2817#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2817{)} \quad\equiv \\ & \qquad \def\mathdef2818#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2818{(}~\def\mathdef2819#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2819{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef2820#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2820{(}~\def\mathdef2821#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2821{global}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef2822#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2822{)}~\def\mathdef2823#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2823{)}~~ \def\mathdef2824#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2824{(}~\def\mathdef2825#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2825{global}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef2826#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2826{)} \\ & \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\mathdef2569#1{{}}\mathdef2569{export} & \href{../text/modules.html#text-export}{\mathtt{export}}_I &::=& \def\mathdef2827#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2827{(}~\def\mathdef2828#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2828{export}~~\mathit{nm}{:}\href{../text/values.html#text-name}{\mathtt{name}}~~d{:}\href{../text/modules.html#text-exportdesc}{\mathtt{exportdesc}}_I~\def\mathdef2829#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2829{)} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-export}{\mathsf{name}}~\mathit{nm}, \href{../syntax/modules.html#syntax-export}{\mathsf{desc}}~d \} \\ \def\mathdef2569#1{{}}\mathdef2569{export description} & \href{../text/modules.html#text-exportdesc}{\mathtt{exportdesc}}_I &::=& \def\mathdef2830#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2830{(}~\def\mathdef2831#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2831{func}~~x{:}\href{../binary/modules.html#binary-funcidx}{\mathtt{funcidx}}_I~\def\mathdef2832#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2832{)} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{func}}~x \\ &&|& \def\mathdef2833#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2833{(}~\def\mathdef2834#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2834{table}~~x{:}\href{../binary/modules.html#binary-tableidx}{\mathtt{tableidx}}_I~\def\mathdef2835#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2835{)} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{table}}~x \\ &&|& \def\mathdef2836#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2836{(}~\def\mathdef2837#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2837{memory}~~x{:}\href{../binary/modules.html#binary-memidx}{\mathtt{memidx}}_I~\def\mathdef2838#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2838{)} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{mem}}~x \\ &&|& \def\mathdef2839#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2839{(}~\def\mathdef2840#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2840{global}~~x{:}\href{../binary/modules.html#binary-globalidx}{\mathtt{globalidx}}_I~\def\mathdef2841#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2841{)} &\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\mathdef2569#1{{}}\mathdef2569{start function} & \href{../text/modules.html#text-start}{\mathtt{start}}_I &::=& \def\mathdef2842#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2842{(}~\def\mathdef2843#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2843{start}~~x{:}\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I~\def\mathdef2844#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2844{)} &\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\mathdef2569#1{{}}\mathdef2569{element segment} & \href{../text/modules.html#text-elem}{\mathtt{elem}}_I &::=& \def\mathdef2845#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2845{(}~\def\mathdef2846#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2846{elem}~~(x{:}\href{../text/modules.html#text-tableidx}{\mathtt{tableidx}}_I)^?~~\def\mathdef2847#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2847{(}~\def\mathdef2848#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2848{offset}~~e{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef2849#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2849{)}~~y^\ast{:}\href{../text/conventions.html#text-vec}{\mathtt{vec}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I)~\def\mathdef2850#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2850{)} \\ &&& \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, 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\mathdef2569#1{{}}\mathdef2569{data segment} & \href{../text/modules.html#text-data}{\mathtt{data}}_I &::=& \def\mathdef2851#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2851{(}~\def\mathdef2852#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2852{data}~~(x{:}\href{../text/modules.html#text-memidx}{\mathtt{memidx}}_I)^?~~\def\mathdef2853#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2853{(}~\def\mathdef2854#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2854{offset}~~e{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef2855#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2855{)}~~b^\ast{:}\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef2856#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2856{)} \\ &&& \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\mathdef2569#1{{}}\mathdef2569{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, 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\mathdef2569#1{{}}\mathdef2569{module} & \href{../text/modules.html#text-module}{\mathtt{module}} & \begin{array}[t]{@{}cllll} ::=& \def\mathdef2857#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2857{(}~\def\mathdef2858#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2858{module}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~(m{:}\href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}_I)^\ast~\def\mathdef2859#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2859{)} \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\mathdef2569#1{{}}\mathdef2569{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\mathdef2860#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2860{(}~\def\mathdef2861#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2861{type}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\mathit{ft}{:}\href{../text/types.html#text-functype}{\mathtt{functype}}~\def\mathdef2862#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2862{)}) &=& \{\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\mathdef2863#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2863{(}~\def\mathdef2864#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2864{func}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef2865#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2865{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{funcs}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef2866#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2866{(}~\def\mathdef2867#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2867{table}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef2868#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2868{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{tables}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef2869#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2869{(}~\def\mathdef2870#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2870{memory}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef2871#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2871{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{mems}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef2872#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2872{(}~\def\mathdef2873#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2873{global}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef2874#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2874{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{globals}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef2875#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2875{(}~\def\mathdef2876#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2876{import}~\dots~\def\mathdef2877#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2877{(}~\def\mathdef2878#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2878{func}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef2879#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2879{)}~\def\mathdef2880#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2880{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{funcs}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef2881#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2881{(}~\def\mathdef2882#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2882{import}~\dots~\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}}^?~\dots~\def\mathdef2885#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2885{)}~\def\mathdef2886#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2886{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{tables}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef2887#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2887{(}~\def\mathdef2888#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2888{import}~\dots~\def\mathdef2889#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2889{(}~\def\mathdef2890#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2890{memory}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef2891#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2891{)}~\def\mathdef2892#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2892{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{mems}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef2893#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2893{(}~\def\mathdef2894#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2894{import}~\dots~\def\mathdef2895#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2895{(}~\def\mathdef2896#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2896{global}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef2897#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2897{)}~\def\mathdef2898#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2898{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{globals}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef2899#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2899{(}~\dots~\def\mathdef2900#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2900{)}) &=& \{\} \\ \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\mathdef2569#1{{}}\mathdef2569{module} & \href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}^\ast &\equiv& \def\mathdef2901#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2901{(}~\def\mathdef2902#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2902{module}~~\href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}^\ast~\def\mathdef2903#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2903{)} \end{array}\]