diff --git a/document/core/exec/modules.rst b/document/core/exec/modules.rst index 4d6e7b04c..ce6eda189 100644 --- a/document/core/exec/modules.rst +++ b/document/core/exec/modules.rst @@ -371,6 +371,58 @@ New instances of :ref:`functions `, :ref:`tables ` +......................................... + +1. Let :math:`\funcelem^\ast` be the vector of :ref:`function elements ` to allocate. + +2. Let :math:`a` be the first free :ref:`element address ` in :math:`S`. + +3. Let :math:`\eleminst` be the :ref:`element instance ` :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 ` +...................................... + +1. Let :math:`\bytes` be the vector of :ref:`bytes ` to allocate. + +2. Let :math:`a` be the first free :ref:`data address ` in :math:`S`. + +3. Let :math:`\datainst` be the :ref:`data instance ` :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: diff --git a/document/core/exec/runtime.rst b/document/core/exec/runtime.rst index c1375fe1e..204b5fc58 100644 --- a/document/core/exec/runtime.rst +++ b/document/core/exec/runtime.rst @@ -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 `, :ref:`tables `, :ref:`memories `, and :ref:`globals ` that have been :ref:`allocated ` during the life time of the abstract machine. [#gc]_ +It consists of the runtime representation of all *instances* of :ref:`functions `, :ref:`tables `, :ref:`memories `, and :ref:`globals `, :ref:`element segments `, and :ref:`data segments ` that have been :ref:`allocated ` during the life time of the abstract machine. [#gc]_ Syntactically, the store is defined as a :ref:`record ` listing the existing instances of each category: @@ -71,7 +71,9 @@ Syntactically, the store is defined as a :ref:`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} @@ -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 `, :ref:`table instances `, :ref:`memory instances `, and :ref:`global instances ` in the :ref:`store ` are referenced with abstract *addresses*. +:ref:`Function instances `, :ref:`table instances `, :ref:`memory instances `, and :ref:`global instances `, :ref:`element instances `, and :ref:`data instances ` in the :ref:`store ` are referenced with abstract *addresses*. These are simply indices into the respective store component. .. math:: @@ -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 ` may assign identity to :ref:`exported ` store objects corresponding to their addresses, @@ -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: @@ -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} @@ -275,6 +289,42 @@ It holds an individual :ref:`value ` and a flag indicating whether i The value of mutable globals can be mutated through :ref:`variable instructions ` or by external means provided by the :ref:`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 `. +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 `. +It holds a vector of :ref:`bytes `. + +.. 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 diff --git a/document/core/util/macros.def b/document/core/util/macros.def index a2db91bd9..d53e27159 100644 --- a/document/core/util/macros.def +++ b/document/core/util/macros.def @@ -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}} @@ -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 @@ -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}} @@ -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}} @@ -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}} @@ -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