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
Types¶
Type definitions can bind a symbolic type identifier.
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.
The synthesized attribute of a
Note
Both productions overlap for the case that the function type is
The well-formedness condition on
Abbreviations¶
A
where
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.
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.
The definition of the local identifier context
Note
The well-formedness condition on
Abbreviations¶
Multiple anonymous locals may be combined into a single declaration:
Functions can be defined as imports or exports inline:
Note
The latter abbreviation can be applied repeatedly, if “
Tables¶
Table definitions can bind a symbolic table identifier.
Abbreviations¶
An element segment can be given inline with a table definition, in which case its offset is
Tables can be defined as imports or exports inline:
Note
The latter abbreviation can be applied repeatedly, if “
Memories¶
Memory definitions can bind a symbolic memory identifier.
Abbreviations¶
A data segment can be given inline with a memory definition, in which case its offset is
Memories can be defined as imports or exports inline:
Note
The latter abbreviation can be applied repeatedly, if “
Globals¶
Global definitions can bind a symbolic global identifier.
Abbreviations¶
Globals can be defined as imports or exports inline:
Note
The latter abbreviation can be applied repeatedly, if “
Exports¶
The syntax for exports mirrors their abstract syntax directly.
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.
Note
At most one start function may occur in a module,
which is ensured by a suitable side condition on the
Element Segments¶
Element segments allow for an optional table index to identify the table to initialize.
Abbreviations¶
As an abbreviation, a single instruction may occur in place of the offset of an active element segment or as an element expression:
Also, the element list may be written as just a sequence of function indices:
A table use can be omitted, defaulting to
As another abbreviation, element segments may also be specified inline with table definitions; see the respective section.
Data Segments¶
Data segments allow for an optional memory index to identify the memory to initialize. The data is written as a string, which may be split up into a possibly empty sequence of individual string literals.
Note
In the current version of WebAssembly, the only valid memory index is 0 or a symbolic memory identifier resolving to the same value.
Abbreviations¶
As an abbreviation, a single instruction may occur in place of the offset of an active data segment:
Also, a memory use can be omitted, defaulting to
As another abbreviation, data segments may also be specified inline with memory definitions; see the respective section.
Modules¶
A module consists of a sequence of fields that can occur in any order. All definitions and their respective bound identifiers scope over the entire module, including the text preceding them.
A module may optionally bind an identifier that names the module. The name serves a documentary role only.
Note
Tools may include the module name in the name section of the binary format.
The following restrictions are imposed on the composition of modules:
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
The definition of the initial identifier context
Abbreviations¶
In a source file, the toplevel