Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions document/core/appendix/index-instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ Instruction Binary Opcode Type
:math:`\I64.\STORE\K{8}~\memarg` :math:`\hex{3C}` :math:`[\I32~\I64] \to []` :ref:`validation <valid-storen>` :ref:`execution <exec-storen>`
:math:`\I64.\STORE\K{16}~\memarg` :math:`\hex{3D}` :math:`[\I32~\I64] \to []` :ref:`validation <valid-storen>` :ref:`execution <exec-storen>`
:math:`\I64.\STORE\K{32}~\memarg` :math:`\hex{3E}` :math:`[\I32~\I64] \to []` :ref:`validation <valid-storen>` :ref:`execution <exec-storen>`
:math:`\CURRENTMEMORY` :math:`\hex{3F}` :math:`[] \to [\I32]` :ref:`validation <valid-current_memory>` :ref:`execution <exec-current_memory>`
:math:`\GROWMEMORY` :math:`\hex{40}` :math:`[\I32] \to [\I32]` :ref:`validation <valid-grow_memory>` :ref:`execution <exec-grow_memory>`
:math:`\MEMSIZE` :math:`\hex{3F}` :math:`[] \to [\I32]` :ref:`validation <valid-mem.size>` :ref:`execution <exec-mem.size>`
:math:`\MEMGROW` :math:`\hex{40}` :math:`[\I32] \to [\I32]` :ref:`validation <valid-mem.grow>` :ref:`execution <exec-mem.grow>`
:math:`\I32.\CONST~\i32` :math:`\hex{41}` :math:`[] \to [\I32]` :ref:`validation <valid-const>` :ref:`execution <exec-const>`
:math:`\I64.\CONST~\i64` :math:`\hex{42}` :math:`[] \to [\I64]` :ref:`validation <valid-const>` :ref:`execution <exec-const>`
:math:`\F32.\CONST~\f32` :math:`\hex{43}` :math:`[] \to [\F32]` :ref:`validation <valid-const>` :ref:`execution <exec-const>`
Expand Down
10 changes: 5 additions & 5 deletions document/core/binary/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ Each variant of :ref:`memory instruction <syntax-instr-memory>` is encoded with
.. _binary-loadn:
.. _binary-store:
.. _binary-storen:
.. _binary-current_memory:
.. _binary-grow_memory:
.. _binary-mem.size:
.. _binary-mem.grow:

.. math::
\begin{array}{llclll}
Expand Down Expand Up @@ -155,12 +155,12 @@ Each variant of :ref:`memory instruction <syntax-instr-memory>` is encoded with
\hex{3C}~~m{:}\Bmemarg &\Rightarrow& \I64.\STORE\K{8}~m \\ &&|&
\hex{3D}~~m{:}\Bmemarg &\Rightarrow& \I64.\STORE\K{16}~m \\ &&|&
\hex{3E}~~m{:}\Bmemarg &\Rightarrow& \I64.\STORE\K{32}~m \\ &&|&
\hex{3F}~~\hex{00} &\Rightarrow& \CURRENTMEMORY \\ &&|&
\hex{40}~~\hex{00} &\Rightarrow& \GROWMEMORY \\
\hex{3F}~~\hex{00} &\Rightarrow& \MEMSIZE \\ &&|&
\hex{40}~~\hex{00} &\Rightarrow& \MEMGROW \\
\end{array}

.. note::
In future versions of WebAssembly, the additional zero bytes occurring in the encoding of the |CURRENTMEMORY| and |GROWMEMORY| instructions may be used to index additional memories.
In future versions of WebAssembly, the additional zero bytes occurring in the encoding of the |MEMSIZE| and |MEMGROW| instructions may be used to index additional memories.


.. index:: numeric instruction
Expand Down
30 changes: 15 additions & 15 deletions document/core/exec/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -533,18 +533,18 @@ Memory Instructions
\end{array}


.. _exec-current_memory:
.. _exec-mem.size:

:math:`\CURRENTMEMORY`
......................
:math:`\MEMSIZE`
................

1. Let :math:`F` be the :ref:`current <exec-notation-textual>` :ref:`frame <syntax-frame>`.

2. Assert: due to :ref:`validation <valid-current_memory>`, :math:`F.\AMODULE.\MIMEMS[0]` exists.
2. Assert: due to :ref:`validation <valid-mem.size>`, :math:`F.\AMODULE.\MIMEMS[0]` exists.

3. Let :math:`a` be the :ref:`memory address <syntax-memaddr>` :math:`F.\AMODULE.\MIMEMS[0]`.

4. Assert: due to :ref:`validation <valid-current_memory>`, :math:`S.\SMEMS[a]` exists.
4. Assert: due to :ref:`validation <valid-mem.size>`, :math:`S.\SMEMS[a]` exists.

5. Let :math:`\X{mem}` be the :ref:`memory instance <syntax-meminst>` :math:`S.\SMEMS[a]`.

Expand All @@ -555,31 +555,31 @@ Memory Instructions
.. math::
\begin{array}{l}
\begin{array}{lcl@{\qquad}l}
S; F; \CURRENTMEMORY &\stepto& S; F; (\I32.\CONST~\X{sz})
S; F; \MEMSIZE &\stepto& S; F; (\I32.\CONST~\X{sz})
\end{array}
\\ \qquad
(\iff |S.\SMEMS[F.\AMODULE.\MIMEMS[0]].\MIDATA| = \X{sz}\cdot64\,\F{Ki}) \\
\end{array}


.. _exec-grow_memory:
.. _exec-mem.grow:

:math:`\GROWMEMORY`
...................
:math:`\MEMGROW`
................

1. Let :math:`F` be the :ref:`current <exec-notation-textual>` :ref:`frame <syntax-frame>`.

2. Assert: due to :ref:`validation <valid-grow_memory>`, :math:`F.\AMODULE.\MIMEMS[0]` exists.
2. Assert: due to :ref:`validation <valid-mem.grow>`, :math:`F.\AMODULE.\MIMEMS[0]` exists.

3. Let :math:`a` be the :ref:`memory address <syntax-memaddr>` :math:`F.\AMODULE.\MIMEMS[0]`.

4. Assert: due to :ref:`validation <valid-grow_memory>`, :math:`S.\SMEMS[a]` exists.
4. Assert: due to :ref:`validation <valid-mem.grow>`, :math:`S.\SMEMS[a]` exists.

5. Let :math:`\X{mem}` be the :ref:`memory instance <syntax-meminst>` :math:`S.\SMEMS[a]`.

6. Let :math:`\X{sz}` be the length of :math:`S.\SMEMS[a]` divided by the :ref:`page size <page-size>`.

7. Assert: due to :ref:`validation <valid-grow_memory>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.
7. Assert: due to :ref:`validation <valid-mem.grow>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.

8. Pop the value :math:`\I32.\CONST~n` from the stack.

Expand All @@ -595,7 +595,7 @@ Memory Instructions
~\\[-1ex]
\begin{array}{l}
\begin{array}{lcl@{\qquad}l}
S; F; (\I32.\CONST~n)~\GROWMEMORY &\stepto& S'; F; (\I32.\CONST~\X{sz})
S; F; (\I32.\CONST~n)~\MEMGROW &\stepto& S'; F; (\I32.\CONST~\X{sz})
\end{array}
\\ \qquad
\begin{array}[t]{@{}r@{~}l@{}}
Expand All @@ -605,12 +605,12 @@ Memory Instructions
\end{array}
\\[1ex]
\begin{array}{lcl@{\qquad}l}
S; F; (\I32.\CONST~n)~\GROWMEMORY &\stepto& S; F; (\I32.\CONST~{-1})
S; F; (\I32.\CONST~n)~\MEMGROW &\stepto& S; F; (\I32.\CONST~{-1})
\end{array}
\end{array}

.. note::
The |GROWMEMORY| instruction is non-deterministic.
The |MEMGROW| instruction is non-deterministic.
It may either succeed, returning the old memory size :math:`\X{sz}`,
or fail, returning :math:`{-1}`.
Failure *must* occur if the referenced memory instance has a maximum size defined that would be exceeded.
Expand Down
8 changes: 4 additions & 4 deletions document/core/syntax/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ Instructions in this group are concerned with linear :ref:`memory <syntax-mem>`.
\K{i}\X{nn}\K{.}\STORE\K{8}~\memarg ~|~
\K{i}\X{nn}\K{.}\STORE\K{16}~\memarg ~|~
\K{i64.}\STORE\K{32}~\memarg \\&&|&
\CURRENTMEMORY \\&&|&
\GROWMEMORY \\
\MEMSIZE \\&&|&
\MEMGROW \\
\end{array}

Memory is accessed with |LOAD| and |STORE| instructions for the different :ref:`value types <syntax-valtype>`.
Expand All @@ -256,8 +256,8 @@ A :ref:`trap <trap>` results if any of the accessed memory bytes lies outside th
.. note::
Future version of WebAssembly might provide memory instructions with 64 bit address ranges.

The |CURRENTMEMORY| instruction returns the current size of a memory.
The |GROWMEMORY| instruction grows memory by a given delta and returns the previous size, or :math:`-1` if enough memory cannot be allocated.
The |MEMSIZE| instruction returns the current size of a memory.
The |MEMGROW| instruction grows memory by a given delta and returns the previous size, or :math:`-1` if enough memory cannot be allocated.
Both instructions operate in units of :ref:`page size <page-size>`.

.. note::
Expand Down
8 changes: 4 additions & 4 deletions document/core/text/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ Memory Instructions
.. _text-loadn:
.. _text-store:
.. _text-storen:
.. _text-current_memory:
.. _text-grow_memory:
.. _text-mem.size:
.. _text-mem.grow:

The offset and alignment immediates to memory instructions are optional.
The offset defaults to :math:`\T{0}`, the alignment to the storage size of the respective memory access, which is its *natural alignment*.
Expand Down Expand Up @@ -214,8 +214,8 @@ Lexically, an |Toffset| or |Talign| phrase is considered a single :ref:`keyword
\text{i64.store8}~~m{:}\Tmemarg_1 &\Rightarrow& \I64.\STORE\K{8}~m \\ &&|&
\text{i64.store16}~~m{:}\Tmemarg_2 &\Rightarrow& \I64.\STORE\K{16}~m \\ &&|&
\text{i64.store32}~~m{:}\Tmemarg_4 &\Rightarrow& \I64.\STORE\K{32}~m \\ &&|&
\text{current\_memory} &\Rightarrow& \CURRENTMEMORY \\ &&|&
\text{grow\_memory} &\Rightarrow& \GROWMEMORY \\
\text{mem.size} &\Rightarrow& \MEMSIZE \\ &&|&
\text{mem.grow} &\Rightarrow& \MEMGROW \\
\end{array}


Expand Down
28 changes: 14 additions & 14 deletions document/core/text/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ The descriptors in imports can bind a symbolic function, table, memory, or globa
&\Rightarrow& \IDFUNC~x \\ &&|&
\text{(}~\text{table}~~\Tid^?~~\X{tt}{:}\Ttabletype~\text{)}
&\Rightarrow& \IDTABLE~\X{tt} \\ &&|&
\text{(}~\text{memory}~~\Tid^?~~\X{mt}{:}\Tmemtype~\text{)}
\text{(}~\text{mem}~~\Tid^?~~\X{mt}{:}\Tmemtype~\text{)}
&\Rightarrow& \IDMEM~~\X{mt} \\ &&|&
\text{(}~\text{global}~~\Tid^?~~\X{gt}{:}\Tglobaltype~\text{)}
&\Rightarrow& \IDGLOBAL~\X{gt} \\
Expand Down Expand Up @@ -314,7 +314,7 @@ Memory definitions can bind a symbolic :ref:`memory identifier <text-id>`.
.. math::
\begin{array}{llclll}
\production{memory} & \Tmem_I &::=&
\text{(}~\text{memory}~~\Tid^?~~\X{mt}{:}\Tmemtype~\text{)}
\text{(}~\text{mem}~~\Tid^?~~\X{mt}{:}\Tmemtype~\text{)}
&\Rightarrow& \{ \MTYPE~\X{mt} \} \\
\end{array}

Expand All @@ -337,8 +337,8 @@ A :ref:`data segment <text-data>` can be given inline with a memory definition,
.. math::
\begin{array}{llclll}
\production{module field} &
\text{(}~\text{memory}~~\Tid^?~~\text{(}~\text{data}~~b^n{:}\Tdatastring~\text{)}~~\text{)} \quad\equiv \\ & \qquad
\text{(}~\text{memory}~~\Tid'~~m~~m~\text{)}~~
\text{(}~\text{mem}~~\Tid^?~~\text{(}~\text{data}~~b^n{:}\Tdatastring~\text{)}~~\text{)} \quad\equiv \\ & \qquad
\text{(}~\text{mem}~~\Tid'~~m~~m~\text{)}~~
\text{(}~\text{data}~~\Tid'~~\text{(}~\text{i32.const}~~\text{0}~\text{)}~~\Tdatastring~\text{)}
\\ & \qquad\qquad
(\iff \Tid' = \Tid^? \neq \epsilon \vee \Tid' \idfresh, m = \F{ceil}(n / 64\F{Ki})) \\
Expand All @@ -349,12 +349,12 @@ Moreover, memories can be defined as :ref:`imports <text-import>` or :ref:`expor
.. math::
\begin{array}{llclll}
\production{module field} &
\text{(}~\text{memory}~~\Tid^?~~\text{(}~\text{import}~~\Tname_1~~\Tname_2~\text{)}~~\Tmemtype~\text{)} \quad\equiv \\ & \qquad
\text{(}~\text{import}~~\Tname_1~~\Tname_2~~\text{(}~\text{memory}~~\Tid^?~~\Tmemtype~\text{)}~\text{)}
\text{(}~\text{mem}~~\Tid^?~~\text{(}~\text{import}~~\Tname_1~~\Tname_2~\text{)}~~\Tmemtype~\text{)} \quad\equiv \\ & \qquad
\text{(}~\text{import}~~\Tname_1~~\Tname_2~~\text{(}~\text{mem}~~\Tid^?~~\Tmemtype~\text{)}~\text{)}
\\[1ex] &
\text{(}~\text{memory}~~\Tid^?~~\text{(}~\text{export}~~\Tname~\text{)}~~\dots~\text{)} \quad\equiv \\ & \qquad
\text{(}~\text{export}~~\Tname~~\text{(}~\text{memory}~~\Tid'~\text{)}~\text{)}~~
\text{(}~\text{memory}~~\Tid'~~\dots~\text{)}
\text{(}~\text{mem}~~\Tid^?~~\text{(}~\text{export}~~\Tname~\text{)}~~\dots~\text{)} \quad\equiv \\ & \qquad
\text{(}~\text{export}~~\Tname~~\text{(}~\text{mem}~~\Tid'~\text{)}~\text{)}~~
\text{(}~\text{mem}~~\Tid'~~\dots~\text{)}
\\ & \qquad\qquad
(\iff \Tid' = \Tid^? \neq \epsilon \vee \Tid' \idfresh) \\
\end{array}
Expand Down Expand Up @@ -426,7 +426,7 @@ The syntax for exports mirrors their :ref:`abstract syntax <syntax-export>` dire
&\Rightarrow& \EDFUNC~x \\ &&|&
\text{(}~\text{table}~~x{:}\Btableidx_I~\text{)}
&\Rightarrow& \EDTABLE~x \\ &&|&
\text{(}~\text{memory}~~x{:}\Bmemidx_I~\text{)}
\text{(}~\text{mem}~~x{:}\Bmemidx_I~\text{)}
&\Rightarrow& \EDMEM~x \\ &&|&
\text{(}~\text{global}~~x{:}\Bglobalidx_I~\text{)}
&\Rightarrow& \EDGLOBAL~x \\
Expand Down Expand Up @@ -593,15 +593,15 @@ The definition of the initial :ref:`identifier context <text-context>` :math:`I`
\{\IFUNCS~(\Tid^?)\} \\
\F{idc}(\text{(}~\text{table}~\Tid^?~\dots~\text{)}) &=&
\{\ITABLES~(\Tid^?)\} \\
\F{idc}(\text{(}~\text{memory}~\Tid^?~\dots~\text{)}) &=&
\F{idc}(\text{(}~\text{mem}~\Tid^?~\dots~\text{)}) &=&
\{\IMEMS~(\Tid^?)\} \\
\F{idc}(\text{(}~\text{global}~\Tid^?~\dots~\text{)}) &=&
\{\IGLOBALS~(\Tid^?)\} \\
\F{idc}(\text{(}~\text{import}~\dots~\text{(}~\text{func}~\Tid^?~\dots~\text{)}~\text{)}) &=&
\{\IFUNCS~(\Tid^?)\} \\
\F{idc}(\text{(}~\text{import}~\dots~\text{(}~\text{table}~\Tid^?~\dots~\text{)}~\text{)}) &=&
\{\ITABLES~(\Tid^?)\} \\
\F{idc}(\text{(}~\text{import}~\dots~\text{(}~\text{memory}~\Tid^?~\dots~\text{)}~\text{)}) &=&
\F{idc}(\text{(}~\text{import}~\dots~\text{(}~\text{mem}~\Tid^?~\dots~\text{)}~\text{)}) &=&
\{\IMEMS~(\Tid^?)\} \\
\F{idc}(\text{(}~\text{import}~\dots~\text{(}~\text{global}~\Tid^?~\dots~\text{)}~\text{)}) &=&
\{\IGLOBALS~(\Tid^?)\} \\
Expand All @@ -623,11 +623,11 @@ The definition of the initial :ref:`identifier context <text-context>` :math:`I`
\F{id}(\text{(}~\text{type}~\Tid^?~\dots~\text{)}) &=& \Tid^? \\
\F{id}(\text{(}~\text{func}~\Tid^?~\dots~\text{)}) &=& \Tid^? \\
\F{id}(\text{(}~\text{table}~\Tid^?~\dots~\text{)}) &=& \Tid^? \\
\F{id}(\text{(}~\text{memory}~\Tid^?~\dots~\text{)}) &=& \Tid^? \\
\F{id}(\text{(}~\text{mem}~\Tid^?~\dots~\text{)}) &=& \Tid^? \\
\F{id}(\text{(}~\text{global}~\Tid^?~\dots~\text{)}) &=& \Tid^? \\[1ex]
\F{funcids}(\Timport^\ast) &=& [\Tid^? ~|~ \text{(}~\text{func}~\Tid^?~\dots~\text{)} \in \F{desc}(\Timport)^\ast] \\
\F{tableids}(\Timport^\ast) &=& [\Tid^? ~|~ \text{(}~\text{table}~\Tid^?~\dots~\text{)} \in \F{desc}(\Timport)^\ast] \\
\F{memids}(\Timport^\ast) &=& [\Tid^? ~|~ \text{(}~\text{memory}~\Tid^?~\dots~\text{)} \in \F{desc}(\Timport)^\ast] \\
\F{memids}(\Timport^\ast) &=& [\Tid^? ~|~ \text{(}~\text{mem}~\Tid^?~\dots~\text{)} \in \F{desc}(\Timport)^\ast] \\
\F{globalids}(\Timport^\ast) &=& [\Tid^? ~|~ \text{(}~\text{global}~\Tid^?~\dots~\text{)} \in \F{desc}(\Timport)^\ast] \\
\end{array} \\
\F{desc}(\text{(}~\text{import}~\dots~\Timportdesc~\text{)}) \quad=\quad \Timportdesc
Expand Down
4 changes: 2 additions & 2 deletions document/core/util/macros.def
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@

.. |LOAD| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{load}}
.. |STORE| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{store}}
.. |CURRENTMEMORY| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{current\_memory}}
.. |GROWMEMORY| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{grow\_memory}}
.. |MEMSIZE| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{mem.size}}
.. |MEMGROW| mathdef:: \xref{syntax/instructions}{syntax-instr-memory}{\K{mem.grow}}

.. |CONST| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{const}}
.. |EQZ| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{eqz}}
Expand Down
16 changes: 8 additions & 8 deletions document/core/valid/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@ Memory Instructions
}


.. _valid-current_memory:
.. _valid-mem.size:

:math:`\CURRENTMEMORY`
......................
:math:`\MEMSIZE`
................

* The memory :math:`C.\CMEMS[0]` must be defined in the context.

Expand All @@ -402,14 +402,14 @@ Memory Instructions
\frac{
C.\CMEMS[0] = \memtype
}{
C \vdashinstr \CURRENTMEMORY : [] \to [\I32]
C \vdashinstr \MEMSIZE : [] \to [\I32]
}


.. _valid-grow_memory:
.. _valid-mem.grow:

:math:`\GROWMEMORY`
...................
:math:`\MEMGROW`
................

* The memory :math:`C.\CMEMS[0]` must be defined in the context.

Expand All @@ -419,7 +419,7 @@ Memory Instructions
\frac{
C.\CMEMS[0] = \memtype
}{
C \vdashinstr \GROWMEMORY : [\I32] \to [\I32]
C \vdashinstr \MEMGROW : [\I32] \to [\I32]
}


Expand Down
26 changes: 13 additions & 13 deletions interpreter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ block_sig : ( result <type>* )*
func_sig: ( type <var> )? <param>* <result>*
global_sig: <type> | ( mut <type> )
table_sig: <nat> <nat>? <elem_type>
memory_sig: <nat> <nat>?
mem_sig: <nat> <nat>?

expr:
( <op> )
Expand Down Expand Up @@ -226,8 +226,8 @@ op:
set_global <var>
<type>.load((8|16|32)_<sign>)? <offset>? <align>?
<type>.store(8|16|32)? <offset>? <align>?
current_memory
grow_memory
mem.size
mem.grow
<type>.const <value>
<type>.<unop>
<type>.<binop>
Expand All @@ -251,10 +251,10 @@ table: ( table <name>? <table_sig> )
( table <name>? ( export <string> )* <elem_type> ( elem <var>* ) ) ;; = (table <name>? ( export <string> )* <size> <size> <elem_type>) (elem (i32.const 0) <var>*)
elem: ( elem <var>? (offset <instr>* ) <var>* )
( elem <var>? <expr> <var>* ) ;; = (elem <var>? (offset <expr>) <var>*)
memory: ( memory <name>? <memory_sig> )
( memory <name>? ( export <string> ) <...> ) ;; = (export <string> (memory <N>))+ (memory <name>? <...>)
( memory <name>? ( import <string> <string> ) <memory_sig> ) ;; = (import <name>? <string> <string> (memory <memory_sig>))
( memory <name>? ( export <string> )* ( data <string>* ) ;; = (memory <name>? ( export <string> )* <size> <size>) (data (i32.const 0) <string>*)
mem: ( mem <name>? <mem_sig> )
( mem <name>? ( export <string> ) <...> ) ;; = (export <string> (mem <N>))+ (mem <name>? <...>)
( mem <name>? ( import <string> <string> ) <mem_sig> ) ;; = (import <name>? <string> <string> (mem <mem_sig>))
( mem <name>? ( export <string> )* ( data <string>* ) ;; = (mem <name>? ( export <string> )* <size> <size>) (data (i32.const 0) <string>*)
data: ( data <var>? ( offset <instr>* ) <string>* )
( data <var>? <expr> <string>* ) ;; = (data <var>? (offset <expr>) <string>*)

Expand All @@ -266,16 +266,16 @@ import: ( import <string> <string> <imkind> )
imkind: ( func <name>? <func_sig> )
( global <name>? <global_sig> )
( table <name>? <table_sig> )
( memory <name>? <memory_sig> )
( mem <name>? <mem_sig> )
export: ( export <string> <exkind> )
exkind: ( func <var> )
( global <var> )
( table <var> )
( memory <var> )
( mem <var> )

module: ( module <name>? <typedef>* <func>* <import>* <export>* <table>? <memory>? <global>* <elem>* <data>* <start>? )
<typedef>* <func>* <import>* <export>* <table>? <memory>? <global>* <elem>* <data>* <start>? ;; =
( module <typedef>* <func>* <import>* <export>* <table>? <memory>? <global>* <elem>* <data>* <start>? )
module: ( module <name>? <typedef>* <func>* <import>* <export>* <table>? <mem>? <global>* <elem>* <data>* <start>? )
<typedef>* <func>* <import>* <export>* <table>? <mem>? <global>* <elem>* <data>* <start>? ;; =
( module <typedef>* <func>* <import>* <export>* <table>? <mem>? <global>* <elem>* <data>* <start>? )
```

Here, productions marked with respective comments are abbreviation forms for equivalent expansions (see the explanation of the AST below).
Expand All @@ -285,7 +285,7 @@ For raw instructions, the syntax allows omitting the parentheses around the oper
Any form of naming via `<name>` and `<var>` (including expression labels) is merely notational convenience of this text format. The actual AST has no names, and all bindings are referred to via ordered numeric indices; consequently, names are immediately resolved in the parser and replaced by indices. Indices can also be used directly in the text format.

The segment strings in the memory field are used to initialize the consecutive memory at the given offset.
The `<size>` in the expansion of the two short-hand forms for `table` and `memory` is the minimal size that can hold the segment: the number of `<var>`s for tables, and the accumulative length of the strings rounded up to page size for memories.
The `<size>` in the expansion of the two short-hand forms for `table` and `mem` is the minimal size that can hold the segment: the number of `<var>`s for tables, and the accumulative length of the strings rounded up to page size for memories.

In addition to the grammar rules above, the fields of a module may appear in any order, except that all imports must occur before the first proper definition of a function, table, memory, or global.

Expand Down
Loading