Skip to content

Commit

Permalink
[spec] Runtime format of element and data segments (#91)
Browse files Browse the repository at this point in the history
This is copied and modified from this closed PR:

WebAssembly/bulk-memory-operations#19
  • Loading branch information
binji authored May 31, 2019
1 parent 88cb638 commit a976b82
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 7 deletions.
52 changes: 52 additions & 0 deletions document/core/exec/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,58 @@ New instances of :ref:`functions <syntax-funcinst>`, :ref:`tables <syntax-tablei
\end{array}
.. index:: element, element instance, element address
.. _alloc-elem:

:ref:`Element segments <syntax-eleminst>`
.........................................

1. Let :math:`\funcelem^\ast` be the vector of :ref:`function elements <syntax-funcelem>` to allocate.

2. Let :math:`a` be the first free :ref:`element address <syntax-elemaddr>` in :math:`S`.

3. Let :math:`\eleminst` be the :ref:`element instance <syntax-eleminst>` :math:`\{ \EIINIT~\funcelem^\ast \}`.

4. Append :math:`\eleminst` to the |SELEM| of :math:`S`.

5. Return :math:`a`.

.. math::
\begin{array}{rlll}
\allocelem(S, \funcelem^\ast) &=& S', \elemaddr \\[1ex]
\mbox{where:} \hfill \\
\elemaddr &=& |S.\SELEM| \\
\eleminst &=& \{ \EIINIT~\funcelem^\ast \} \\
S' &=& S \compose \{\SELEM~\eleminst\} \\
\end{array}
.. index:: data, data instance, data address
.. _alloc-data:

:ref:`Data segments <syntax-datainst>`
......................................

1. Let :math:`\bytes` be the vector of :ref:`bytes <syntax-byte>` to allocate.

2. Let :math:`a` be the first free :ref:`data address <syntax-dataaddr>` in :math:`S`.

3. Let :math:`\datainst` be the :ref:`data instance <syntax-datainst>` :math:`\{ \DIINIT~\bytes \}`.

4. Append :math:`\datainst` to the |SDATA| of :math:`S`.

5. Return :math:`a`.

.. math::
\begin{array}{rlll}
\allocdata(S, \bytes) &=& S', \dataaddr \\[1ex]
\mbox{where:} \hfill \\
\dataaddr &=& |S.\SDATA| \\
\datainst &=& \{ \DIINIT~\bytes \} \\
S' &=& S \compose \{\SDATA~\datainst\} \\
\end{array}
.. index:: table, table instance, table address, grow, limits
.. _grow-table:

Expand Down
60 changes: 55 additions & 5 deletions document/core/exec/runtime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Store
~~~~~

The *store* represents all global state that can be manipulated by WebAssembly programs.
It consists of the runtime representation of all *instances* of :ref:`functions <syntax-funcinst>`, :ref:`tables <syntax-tableinst>`, :ref:`memories <syntax-meminst>`, and :ref:`globals <syntax-globalinst>` that have been :ref:`allocated <alloc>` during the life time of the abstract machine. [#gc]_
It consists of the runtime representation of all *instances* of :ref:`functions <syntax-funcinst>`, :ref:`tables <syntax-tableinst>`, :ref:`memories <syntax-meminst>`, and :ref:`globals <syntax-globalinst>`, :ref:`element segments <syntax-eleminst>`, and :ref:`data segments <syntax-datainst>` that have been :ref:`allocated <alloc>` during the life time of the abstract machine. [#gc]_

Syntactically, the store is defined as a :ref:`record <notation-record>` listing the existing instances of each category:

Expand All @@ -71,7 +71,9 @@ Syntactically, the store is defined as a :ref:`record <notation-record>` listing
\SFUNCS & \funcinst^\ast, \\
\STABLES & \tableinst^\ast, \\
\SMEMS & \meminst^\ast, \\
\SGLOBALS & \globalinst^\ast ~\} \\
\SGLOBALS & \globalinst^\ast, \\
\SELEM & (\eleminst^?)^\ast, \\
\SDATA & (\datainst^?)^\ast ~\} \\
\end{array}
\end{array}
Expand All @@ -87,25 +89,31 @@ Convention
* The meta variable :math:`S` ranges over stores where clear from context.


.. index:: ! address, store, function instance, table instance, memory instance, global instance, embedder
.. index:: ! address, store, function instance, table instance, memory instance, global instance, element instance, data instance, embedder
pair: abstract syntax; function address
pair: abstract syntax; table address
pair: abstract syntax; memory address
pair: abstract syntax; global address
pair: abstract syntax; element address
pair: abstract syntax; data address
pair: function; address
pair: table; address
pair: memory; address
pair: global; address
pair: element; address
pair: data; address
.. _syntax-funcaddr:
.. _syntax-tableaddr:
.. _syntax-memaddr:
.. _syntax-globaladdr:
.. _syntax-elemaddr:
.. _syntax-dataaddr:
.. _syntax-addr:

Addresses
~~~~~~~~~

:ref:`Function instances <syntax-funcinst>`, :ref:`table instances <syntax-tableinst>`, :ref:`memory instances <syntax-meminst>`, and :ref:`global instances <syntax-globalinst>` in the :ref:`store <syntax-store>` are referenced with abstract *addresses*.
:ref:`Function instances <syntax-funcinst>`, :ref:`table instances <syntax-tableinst>`, :ref:`memory instances <syntax-meminst>`, and :ref:`global instances <syntax-globalinst>`, :ref:`element instances <syntax-eleminst>`, and :ref:`data instances <syntax-datainst>` in the :ref:`store <syntax-store>` are referenced with abstract *addresses*.
These are simply indices into the respective store component.

.. math::
Expand All @@ -120,6 +128,10 @@ These are simply indices into the respective store component.
\addr \\
\production{(global address)} & \globaladdr &::=&
\addr \\
\production{(element address)} & \elemaddr &::=&
\addr \\
\production{(data address)} & \dataaddr &::=&
\addr \\
\end{array}
An :ref:`embedder <embedder>` may assign identity to :ref:`exported <syntax-export>` store objects corresponding to their addresses,
Expand All @@ -137,7 +149,7 @@ even where this identity is not observable from within WebAssembly code itself
hence logical addresses can be arbitrarily large natural numbers.


.. index:: ! instance, function type, function instance, table instance, memory instance, global instance, export instance, table address, memory address, global address, index, name
.. index:: ! instance, function type, function instance, table instance, memory instance, global instance, element instance, data instance, export instance, table address, memory address, global address, element address, data address, index, name
pair: abstract syntax; module instance
pair: module; instance
.. _syntax-moduleinst:
Expand All @@ -158,6 +170,8 @@ and collects runtime representations of all entities that are imported, defined,
\MITABLES & \tableaddr^\ast, \\
\MIMEMS & \memaddr^\ast, \\
\MIGLOBALS & \globaladdr^\ast, \\
\MIELEMS & (\elemaddr^?)^\ast, \\
\MIDATAS & (\dataaddr^?)^\ast, \\
\MIEXPORTS & \exportinst^\ast ~\} \\
\end{array}
\end{array}
Expand Down Expand Up @@ -275,6 +289,42 @@ It holds an individual :ref:`value <syntax-val>` and a flag indicating whether i
The value of mutable globals can be mutated through :ref:`variable instructions <syntax-instr-variable>` or by external means provided by the :ref:`embedder <embedder>`.


.. index:: ! element instance, element segment, embedder, element expression
pair: abstract syntax; element instance
pair: element; instance
.. _syntax-eleminst:

Element Instances
~~~~~~~~~~~~~~~~~

An *element instance* is the runtime representation of an :ref:`element segment <syntax-elem>`.
Like table instances, an element instance holds a vector of function elements.

.. math::
\begin{array}{llll}
\production{(element instance)} & \eleminst &::=&
\{ \EIINIT~\vec(\funcelem) \} \\
\end{array}
.. index:: ! data instance, data segment, embedder, byte
pair: abstract syntax; data instance
pair: data; instance
.. _syntax-datainst:

Data Instances
~~~~~~~~~~~~~~

An *data instance* is the runtime representation of a :ref:`data segment <syntax-data>`.
It holds a vector of :ref:`bytes <syntax-byte>`.

.. math::
\begin{array}{llll}
\production{(data instance)} & \datainst &::=&
\{ \DIINIT~\vec(\byte) \} \\
\end{array}
.. index:: ! export instance, export, name, external value
pair: abstract syntax; export instance
pair: export; instance
Expand Down
16 changes: 14 additions & 2 deletions document/core/util/macros.def
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@
.. |alloctable| mathdef:: \xref{exec/modules}{alloc-table}{\F{alloctable}}
.. |allocmem| mathdef:: \xref{exec/modules}{alloc-mem}{\F{allocmem}}
.. |allocglobal| mathdef:: \xref{exec/modules}{alloc-global}{\F{allocglobal}}
.. |allocelem| mathdef:: \xref{exec/modules}{alloc-elem}{\F{allocelem}}
.. |allocdata| mathdef:: \xref{exec/modules}{alloc-data}{\F{allocdata}}
.. |allocmodule| mathdef:: \xref{exec/modules}{alloc-module}{\F{allocmodule}}

.. |growtable| mathdef:: \xref{exec/modules}{grow-table}{\F{growtable}}
Expand All @@ -819,7 +821,8 @@
.. |tableaddr| mathdef:: \xref{exec/runtime}{syntax-tableaddr}{\X{tableaddr}}
.. |memaddr| mathdef:: \xref{exec/runtime}{syntax-memaddr}{\X{memaddr}}
.. |globaladdr| mathdef:: \xref{exec/runtime}{syntax-globaladdr}{\X{globaladdr}}

.. |elemaddr| mathdef:: \xref{exec/runtime}{syntax-elemaddr}{\X{elemaddr}}
.. |dataaddr| mathdef:: \xref{exec/runtime}{syntax-dataaddr}{\X{dataaddr}}

.. Instances, terminals

Expand All @@ -837,6 +840,10 @@
.. |GIVALUE| mathdef:: \xref{exec/runtime}{syntax-globalinst}{\K{value}}
.. |GIMUT| mathdef:: \xref{exec/runtime}{syntax-globalinst}{\K{mut}}

.. |EIINIT| mathdef:: \xref{exec/runtime}{syntax-eleminst}{\K{init}}

.. |DIINIT| mathdef:: \xref{exec/runtime}{syntax-datainst}{\K{init}}

.. |EINAME| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\K{name}}
.. |EIVALUE| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\K{value}}

Expand All @@ -850,6 +857,8 @@
.. |MITABLES| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{tableaddrs}}
.. |MIMEMS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{memaddrs}}
.. |MIGLOBALS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{globaladdrs}}
.. |MIELEMS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{elemaddrs}}
.. |MIDATAS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{dataaddrs}}
.. |MIEXPORTS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{exports}}


Expand All @@ -863,6 +872,8 @@
.. |funcelem| mathdef:: \xref{exec/runtime}{syntax-funcelem}{\X{funcelem}}
.. |meminst| mathdef:: \xref{exec/runtime}{syntax-meminst}{\X{meminst}}
.. |globalinst| mathdef:: \xref{exec/runtime}{syntax-globalinst}{\X{globalinst}}
.. |eleminst| mathdef:: \xref{exec/runtime}{syntax-eleminst}{\X{eleminst}}
.. |datainst| mathdef:: \xref{exec/runtime}{syntax-datainst}{\X{datainst}}
.. |exportinst| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\X{exportinst}}

.. |hostfunc| mathdef:: \xref{exec/runtime}{syntax-hostfunc}{\X{hostfunc}}
Expand All @@ -882,7 +893,8 @@
.. |STABLES| mathdef:: \xref{exec/runtime}{syntax-store}{\K{tables}}
.. |SMEMS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{mems}}
.. |SGLOBALS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{globals}}

.. |SELEM| mathdef:: \xref{exec/runtime}{syntax-store}{\K{elem}}
.. |SDATA| mathdef:: \xref{exec/runtime}{syntax-store}{\K{data}}

.. Store, non-terminals

Expand Down

0 comments on commit a976b82

Please sign in to comment.