# 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\mathdef3068#1{{}}\mathdef3068{type index} & \href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef3113#1{{\mathtt{u}#1}}\mathdef3113{\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\mathdef3068#1{{}}\mathdef3068{function index} & \href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef3113#1{{\mathtt{u}#1}}\mathdef3113{\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\mathdef3068#1{{}}\mathdef3068{table index} & \href{../text/modules.html#text-tableidx}{\mathtt{tableidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef3113#1{{\mathtt{u}#1}}\mathdef3113{\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\mathdef3068#1{{}}\mathdef3068{memory index} & \href{../text/modules.html#text-memidx}{\mathtt{memidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef3113#1{{\mathtt{u}#1}}\mathdef3113{\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\mathdef3068#1{{}}\mathdef3068{global index} & \href{../text/modules.html#text-globalidx}{\mathtt{globalidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef3113#1{{\mathtt{u}#1}}\mathdef3113{\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\mathdef3068#1{{}}\mathdef3068{local index} & \href{../text/modules.html#text-localidx}{\mathtt{localidx}}_I &::=& x{:}\href{../text/values.html#text-int}{\def\mathdef3113#1{{\mathtt{u}#1}}\mathdef3113{\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\mathdef3068#1{{}}\mathdef3068{label index} & \href{../text/modules.html#text-labelidx}{\mathtt{labelidx}}_I &::=& l{:}\href{../text/values.html#text-int}{\def\mathdef3113#1{{\mathtt{u}#1}}\mathdef3113{\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\mathdef3068#1{{}}\mathdef3068{type definition} & \href{../text/modules.html#text-typedef}{\mathtt{type}} &::=& \def\mathdef3125#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3125{(}~\def\mathdef3126#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3126{type}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{ft}{:}\href{../text/types.html#text-functype}{\mathtt{functype}}~\def\mathdef3127#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3127{)} &\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\mathdef3068#1{{}}\mathdef3068{type use} & \href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}_I &::=& \def\mathdef3128#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3128{(}~\def\mathdef3129#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3129{type}~~x{:}\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}_I~\def\mathdef3130#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3130{)} \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\mathdef3131#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3131{(}~\def\mathdef3132#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3132{type}~~x{:}\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}_I~\def\mathdef3133#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3133{)} ~~(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\mathdef3134#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3134{(}~\def\mathdef3135#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3135{param}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3136#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3136{)}) &=& \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\mathdef3068#1{{}}\mathdef3068{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\mathdef3137#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3137{(}~\def\mathdef3138#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3138{type}~~x~\def\mathdef3139#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3139{)}~~\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\mathdef3140#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3140{(}~\def\mathdef3141#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3141{type}~~\def\mathdef3142#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3142{(}~\def\mathdef3143#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3143{func}~~\href{../text/types.html#text-functype}{\mathtt{param}}^\ast~~\href{../text/types.html#text-functype}{\mathtt{result}}~\def\mathdef3144#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3144{)}~\def\mathdef3145#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3145{)}$

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\mathdef3068#1{{}}\mathdef3068{import} & \href{../text/modules.html#text-import}{\mathtt{import}}_I &::=& \def\mathdef3146#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3146{(}~\def\mathdef3147#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3147{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\mathdef3148#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3148{)} \\ &&& \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\mathdef3068#1{{}}\mathdef3068{import description} & \href{../text/modules.html#text-importdesc}{\mathtt{importdesc}}_I &::=& \def\mathdef3149#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3149{(}~\def\mathdef3150#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3150{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~x,I'{:}\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}_I~\def\mathdef3151#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3151{)} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{func}}~x \\ &&|& \def\mathdef3152#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3152{(}~\def\mathdef3153#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3153{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{tt}{:}\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef3154#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3154{)} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{table}}~\mathit{tt} \\ &&|& \def\mathdef3155#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3155{(}~\def\mathdef3156#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3156{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{mt}{:}\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef3157#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3157{)} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{mem}}~~\mathit{mt} \\ &&|& \def\mathdef3158#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3158{(}~\def\mathdef3159#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3159{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{gt}{:}\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~\def\mathdef3160#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3160{)} &\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\mathdef3068#1{{}}\mathdef3068{function} & \href{../text/modules.html#text-func}{\mathtt{func}}_I &::=& \def\mathdef3161#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3161{(}~\def\mathdef3162#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3162{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\mathdef3163#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3163{)} \\ &&& \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\mathdef3068#1{{}}\mathdef3068{local} & \href{../text/modules.html#text-local}{\mathtt{local}} &::=& \def\mathdef3164#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3164{(}~\def\mathdef3165#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3165{local}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~t{:}\href{../text/types.html#text-valtype}{\mathtt{valtype}}~\def\mathdef3166#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3166{)} \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\mathdef3167#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3167{(}~\def\mathdef3168#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3168{local}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3169#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3169{)}) &=& \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\mathdef3068#1{{}}\mathdef3068{local} & \def\mathdef3170#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3170{(}~~\def\mathdef3171#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3171{local}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}^\ast~~\def\mathdef3172#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3172{)} &\equiv& (\def\mathdef3173#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3173{(}~~\def\mathdef3174#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3174{local}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}~~\def\mathdef3175#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3175{)})^\ast \\ \end{array}\end{split}$

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

$\begin{split}\begin{array}{llclll} \def\mathdef3068#1{{}}\mathdef3068{module field} & \def\mathdef3176#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3176{(}~\def\mathdef3177#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3177{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3178#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3178{(}~\def\mathdef3179#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3179{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef3180#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3180{)}~~\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}~\def\mathdef3181#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3181{)} \quad\equiv \\ & \qquad \def\mathdef3182#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3182{(}~\def\mathdef3183#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3183{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef3184#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3184{(}~\def\mathdef3185#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3185{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/modules.html#text-typeuse}{\mathtt{typeuse}}~\def\mathdef3186#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3186{)}~\def\mathdef3187#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3187{)} \\[1ex] & \def\mathdef3188#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3188{(}~\def\mathdef3189#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3189{func}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3190#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3190{(}~\def\mathdef3191#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3191{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef3192#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3192{)}~~\dots~\def\mathdef3193#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3193{)} \quad\equiv \\ & \qquad \def\mathdef3194#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3194{(}~\def\mathdef3195#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3195{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef3196#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3196{(}~\def\mathdef3197#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3197{func}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef3198#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3198{)}~\def\mathdef3199#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3199{)}~~ \def\mathdef3200#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3200{(}~\def\mathdef3201#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3201{func}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef3202#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3202{)} \\ & \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\mathdef3068#1{{}}\mathdef3068{table} & \href{../text/modules.html#text-table}{\mathtt{table}}_I &::=& \def\mathdef3203#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3203{(}~\def\mathdef3204#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3204{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{tt}{:}\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef3205#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3205{)} &\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\mathdef3068#1{{}}\mathdef3068{module field} & \def\mathdef3206#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3206{(}~\def\mathdef3207#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3207{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-elemtype}{\mathtt{elemtype}}~~\def\mathdef3208#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3208{(}~\def\mathdef3209#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3209{elem}~~x^n{:}\href{../text/conventions.html#text-vec}{\mathtt{vec}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}})~\def\mathdef3210#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3210{)}~~\def\mathdef3211#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3211{)} \quad\equiv \\ & \qquad \def\mathdef3212#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3212{(}~\def\mathdef3213#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3213{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~n~~n~~\href{../text/types.html#text-elemtype}{\mathtt{elemtype}}~\def\mathdef3214#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3214{)}~~ \def\mathdef3215#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3215{(}~\def\mathdef3216#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3216{elem}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\def\mathdef3217#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3217{(}~\def\mathdef3218#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3218{i32.const}~~\def\mathdef3219#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3219{0}~\def\mathdef3220#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3220{)}~~\href{../text/conventions.html#text-vec}{\mathtt{vec}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}})~\def\mathdef3221#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3221{)} \\ & \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\mathdef3068#1{{}}\mathdef3068{module field} & \def\mathdef3222#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3222{(}~\def\mathdef3223#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3223{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3224#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3224{(}~\def\mathdef3225#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3225{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef3226#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3226{)}~~\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef3227#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3227{)} \quad\equiv \\ & \qquad \def\mathdef3228#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3228{(}~\def\mathdef3229#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3229{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef3230#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3230{(}~\def\mathdef3231#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3231{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}~\def\mathdef3232#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3232{)}~\def\mathdef3233#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3233{)} \\[1ex] & \def\mathdef3234#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3234{(}~\def\mathdef3235#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3235{table}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3236#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3236{(}~\def\mathdef3237#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3237{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef3238#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3238{)}~~\dots~\def\mathdef3239#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3239{)} \quad\equiv \\ & \qquad \def\mathdef3240#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3240{(}~\def\mathdef3241#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3241{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef3242#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3242{(}~\def\mathdef3243#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3243{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef3244#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3244{)}~\def\mathdef3245#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3245{)}~~ \def\mathdef3246#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3246{(}~\def\mathdef3247#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3247{table}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef3248#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3248{)} \\ & \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\mathdef3068#1{{}}\mathdef3068{memory} & \href{../text/modules.html#text-mem}{\mathtt{mem}}_I &::=& \def\mathdef3249#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3249{(}~\def\mathdef3250#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3250{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\mathit{mt}{:}\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef3251#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3251{)} &\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\mathdef3068#1{{}}\mathdef3068{module field} & \def\mathdef3252#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3252{(}~\def\mathdef3253#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3253{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3254#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3254{(}~\def\mathdef3255#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3255{data}~~b^n{:}\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef3256#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3256{)}~~\def\mathdef3257#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3257{)} \quad\equiv \\ & \qquad \def\mathdef3258#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3258{(}~\def\mathdef3259#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3259{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~m~~m~\def\mathdef3260#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3260{)}~~ \def\mathdef3261#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3261{(}~\def\mathdef3262#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3262{data}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\def\mathdef3263#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3263{(}~\def\mathdef3264#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3264{i32.const}~~\def\mathdef3265#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3265{0}~\def\mathdef3266#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3266{)}~~\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef3267#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3267{)} \\ & \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\mathdef3068#1{{}}\mathdef3068{module field} & \def\mathdef3268#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3268{(}~\def\mathdef3269#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3269{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3270#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3270{(}~\def\mathdef3271#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3271{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef3272#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3272{)}~~\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef3273#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3273{)} \quad\equiv \\ & \qquad \def\mathdef3274#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3274{(}~\def\mathdef3275#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3275{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef3276#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3276{(}~\def\mathdef3277#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3277{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-memtype}{\mathtt{memtype}}~\def\mathdef3278#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3278{)}~\def\mathdef3279#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3279{)} \\[1ex] & \def\mathdef3280#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3280{(}~\def\mathdef3281#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3281{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3282#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3282{(}~\def\mathdef3283#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3283{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef3284#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3284{)}~~\dots~\def\mathdef3285#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3285{)} \quad\equiv \\ & \qquad \def\mathdef3286#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3286{(}~\def\mathdef3287#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3287{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef3288#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3288{(}~\def\mathdef3289#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3289{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef3290#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3290{)}~\def\mathdef3291#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3291{)}~~ \def\mathdef3292#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3292{(}~\def\mathdef3293#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3293{memory}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef3294#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3294{)} \\ & \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\mathdef3068#1{{}}\mathdef3068{global} & \href{../text/modules.html#text-global}{\mathtt{global}}_I &::=& \def\mathdef3295#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3295{(}~\def\mathdef3296#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3296{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\mathdef3297#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3297{)} &\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\mathdef3068#1{{}}\mathdef3068{module field} & \def\mathdef3298#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3298{(}~\def\mathdef3299#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3299{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3300#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3300{(}~\def\mathdef3301#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3301{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~\def\mathdef3302#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3302{)}~~\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~\def\mathdef3303#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3303{)} \quad\equiv \\ & \qquad \def\mathdef3304#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3304{(}~\def\mathdef3305#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3305{import}~~\href{../text/values.html#text-name}{\mathtt{name}}_1~~\href{../text/values.html#text-name}{\mathtt{name}}_2~~\def\mathdef3306#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3306{(}~\def\mathdef3307#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3307{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}~\def\mathdef3308#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3308{)}~\def\mathdef3309#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3309{)} \\[1ex] & \def\mathdef3310#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3310{(}~\def\mathdef3311#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3311{global}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~\def\mathdef3312#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3312{(}~\def\mathdef3313#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3313{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~\def\mathdef3314#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3314{)}~~\dots~\def\mathdef3315#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3315{)} \quad\equiv \\ & \qquad \def\mathdef3316#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3316{(}~\def\mathdef3317#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3317{export}~~\href{../text/values.html#text-name}{\mathtt{name}}~~\def\mathdef3318#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3318{(}~\def\mathdef3319#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3319{global}~~\href{../text/values.html#text-id}{\mathtt{id}}'~\def\mathdef3320#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3320{)}~\def\mathdef3321#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3321{)}~~ \def\mathdef3322#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3322{(}~\def\mathdef3323#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3323{global}~~\href{../text/values.html#text-id}{\mathtt{id}}'~~\dots~\def\mathdef3324#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3324{)} \\ & \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\mathdef3068#1{{}}\mathdef3068{export} & \href{../text/modules.html#text-export}{\mathtt{export}}_I &::=& \def\mathdef3325#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3325{(}~\def\mathdef3326#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3326{export}~~\mathit{nm}{:}\href{../text/values.html#text-name}{\mathtt{name}}~~d{:}\href{../text/modules.html#text-exportdesc}{\mathtt{exportdesc}}_I~\def\mathdef3327#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3327{)} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-export}{\mathsf{name}}~\mathit{nm}, \href{../syntax/modules.html#syntax-export}{\mathsf{desc}}~d \} \\ \def\mathdef3068#1{{}}\mathdef3068{export description} & \href{../text/modules.html#text-exportdesc}{\mathtt{exportdesc}}_I &::=& \def\mathdef3328#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3328{(}~\def\mathdef3329#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3329{func}~~x{:}\href{../binary/modules.html#binary-funcidx}{\mathtt{funcidx}}_I~\def\mathdef3330#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3330{)} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{func}}~x \\ &&|& \def\mathdef3331#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3331{(}~\def\mathdef3332#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3332{table}~~x{:}\href{../binary/modules.html#binary-tableidx}{\mathtt{tableidx}}_I~\def\mathdef3333#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3333{)} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{table}}~x \\ &&|& \def\mathdef3334#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3334{(}~\def\mathdef3335#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3335{memory}~~x{:}\href{../binary/modules.html#binary-memidx}{\mathtt{memidx}}_I~\def\mathdef3336#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3336{)} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{mem}}~x \\ &&|& \def\mathdef3337#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3337{(}~\def\mathdef3338#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3338{global}~~x{:}\href{../binary/modules.html#binary-globalidx}{\mathtt{globalidx}}_I~\def\mathdef3339#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3339{)} &\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\mathdef3068#1{{}}\mathdef3068{start function} & \href{../text/modules.html#text-start}{\mathtt{start}}_I &::=& \def\mathdef3340#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3340{(}~\def\mathdef3341#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3341{start}~~x{:}\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I~\def\mathdef3342#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3342{)} &\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\mathdef3068#1{{}}\mathdef3068{element segment} & \href{../text/modules.html#text-elem}{\mathtt{elem}}_I &::=& \def\mathdef3343#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3343{(}~\def\mathdef3344#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3344{elem}~~(x{:}\href{../text/modules.html#text-tableidx}{\mathtt{tableidx}}_I)^?~~\def\mathdef3345#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3345{(}~\def\mathdef3346#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3346{offset}~~e{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef3347#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3347{)}~~y^\ast{:}\href{../text/conventions.html#text-vec}{\mathtt{vec}}(\href{../text/modules.html#text-funcidx}{\mathtt{funcidx}}_I)~\def\mathdef3348#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3348{)} \\ &&& \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\mathdef3068#1{{}}\mathdef3068{data segment} & \href{../text/modules.html#text-data}{\mathtt{data}}_I &::=& \def\mathdef3349#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3349{(}~\def\mathdef3350#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3350{data}~~(x{:}\href{../text/modules.html#text-memidx}{\mathtt{memidx}}_I)^?~~\def\mathdef3351#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3351{(}~\def\mathdef3352#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3352{offset}~~e{:}\href{../text/instructions.html#text-expr}{\mathtt{expr}}_I~\def\mathdef3353#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3353{)}~~b^\ast{:}\href{../text/modules.html#text-datastring}{\mathtt{datastring}}~\def\mathdef3354#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3354{)} \\ &&& \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\mathdef3068#1{{}}\mathdef3068{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\mathdef3068#1{{}}\mathdef3068{module} & \href{../text/modules.html#text-module}{\mathtt{module}} & \begin{array}[t]{@{}cllll} ::=& \def\mathdef3355#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3355{(}~\def\mathdef3356#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3356{module}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~(m{:}\href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}_I)^\ast~\def\mathdef3357#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3357{)} \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\mathdef3068#1{{}}\mathdef3068{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\mathdef3358#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3358{(}~\def\mathdef3359#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3359{type}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\mathit{ft}{:}\href{../text/types.html#text-functype}{\mathtt{functype}}~\def\mathdef3360#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3360{)}) &=& \{\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\mathdef3361#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3361{(}~\def\mathdef3362#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3362{func}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3363#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3363{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{funcs}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3364#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3364{(}~\def\mathdef3365#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3365{table}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3366#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3366{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{tables}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3367#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3367{(}~\def\mathdef3368#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3368{memory}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3369#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3369{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{mems}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3370#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3370{(}~\def\mathdef3371#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3371{global}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3372#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3372{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{globals}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3373#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3373{(}~\def\mathdef3374#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3374{import}~\dots~\def\mathdef3375#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3375{(}~\def\mathdef3376#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3376{func}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3377#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3377{)}~\def\mathdef3378#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3378{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{funcs}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3379#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3379{(}~\def\mathdef3380#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3380{import}~\dots~\def\mathdef3381#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3381{(}~\def\mathdef3382#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3382{table}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3383#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3383{)}~\def\mathdef3384#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3384{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{tables}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3385#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3385{(}~\def\mathdef3386#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3386{import}~\dots~\def\mathdef3387#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3387{(}~\def\mathdef3388#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3388{memory}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3389#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3389{)}~\def\mathdef3390#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3390{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{mems}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3391#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3391{(}~\def\mathdef3392#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3392{import}~\dots~\def\mathdef3393#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3393{(}~\def\mathdef3394#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3394{global}~\href{../text/values.html#text-id}{\mathtt{id}}^?~\dots~\def\mathdef3395#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3395{)}~\def\mathdef3396#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3396{)}) &=& \{\href{../text/conventions.html#text-context}{\mathsf{globals}}~(\href{../text/values.html#text-id}{\mathtt{id}}^?)\} \\ \mathrm{idc}(\def\mathdef3397#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3397{(}~\dots~\def\mathdef3398#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3398{)}) &=& \{\} \\ \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\mathdef3068#1{{}}\mathdef3068{module} & \href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}^\ast &\equiv& \def\mathdef3399#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3399{(}~\def\mathdef3400#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3400{module}~~\href{../text/modules.html#text-modulefield}{\mathtt{modulefield}}^\ast~\def\mathdef3401#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3401{)} \end{array}$