Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit 2d16b84

Browse files
committed
[spec] Runtime format of element and data segments
This is copied and modified from this closed PR: #19
1 parent 88cb638 commit 2d16b84

File tree

3 files changed

+127
-7
lines changed

3 files changed

+127
-7
lines changed

document/core/exec/modules.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,64 @@ New instances of :ref:`functions <syntax-funcinst>`, :ref:`tables <syntax-tablei
371371
\end{array}
372372
373373
374+
.. index:: element, element instance, element address
375+
.. _alloc-elem:
376+
377+
:ref:`Element segments <syntax-eleminst>`
378+
.........................................
379+
380+
1. Let :math:`\elem` be the :ref:`element segment <syntax-elem>` to allocate.
381+
382+
2. Let :math:`\{ \EINIT~\elemexpr^\ast, \dots \}` be the structure of :ref:`element segment <syntax-elem>` :math:`\elem`.
383+
384+
3. Let :math:`a` be the first free :ref:`element address <syntax-elemaddr>` in :math:`S`.
385+
386+
5. Let :math:`\eleminst` be the :ref:`element instance <syntax-eleminst>` :math:`\{ \EIINIT~\elemexpr^\ast \}`.
387+
388+
6. Append :math:`\eleminst` to the |SELEM| of :math:`S`.
389+
390+
7. Return :math:`a`.
391+
392+
.. math::
393+
\begin{array}{rlll}
394+
\allocelem(S, \elem) &=& S', \elemaddr \\[1ex]
395+
\mbox{where:} \hfill \\
396+
\elem &=& \{ \EINIT~\elemexpr^\ast, \dots \} \\
397+
\elemaddr &=& |S.\SELEM| \\
398+
\eleminst &=& \{ \EIINIT~\elemexpr^\ast \} \\
399+
S' &=& S \compose \{\SELEM~\eleminst\} \\
400+
\end{array}
401+
402+
403+
.. index:: data, data instance, data address
404+
.. _alloc-data:
405+
406+
:ref:`Data segments <syntax-datainst>`
407+
......................................
408+
409+
1. Let :math:`\data` be the :ref:`data segment <syntax-data>` to allocate.
410+
411+
2. Let :math:`\{ \DINIT~\bytes, \dots \}` be the structure of :ref:`data segment <syntax-data>` :math:`\data`.
412+
413+
2. Let :math:`a` be the first free :ref:`data address <syntax-dataaddr>` in :math:`S`.
414+
415+
3. Let :math:`\datainst` be the :ref:`data instance <syntax-datainst>` :math:`\{ \DIINIT~\bytes \}`.
416+
417+
4. Append :math:`\datainst` to the |SDATA| of :math:`S`.
418+
419+
5. Return :math:`a`.
420+
421+
.. math::
422+
\begin{array}{rlll}
423+
\allocdata(S, \data) &=& S', \dataaddr \\[1ex]
424+
\mbox{where:} \hfill \\
425+
\data &=& \{ \DINIT~\bytes, \dots \} \\
426+
\dataaddr &=& |S.\SDATA| \\
427+
\datainst &=& \{ \DIINIT~d.\DINIT \} \\
428+
S' &=& S \compose \{\SDATA~\datainst\} \\
429+
\end{array}
430+
431+
374432
.. index:: table, table instance, table address, grow, limits
375433
.. _grow-table:
376434

document/core/exec/runtime.rst

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Store
6060
~~~~~
6161

6262
The *store* represents all global state that can be manipulated by WebAssembly programs.
63-
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]_
63+
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]_
6464

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

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

8991

90-
.. index:: ! address, store, function instance, table instance, memory instance, global instance, embedder
92+
.. index:: ! address, store, function instance, table instance, memory instance, global instance, element instance, data instance, embedder
9193
pair: abstract syntax; function address
9294
pair: abstract syntax; table address
9395
pair: abstract syntax; memory address
9496
pair: abstract syntax; global address
97+
pair: abstract syntax; element address
98+
pair: abstract syntax; data address
9599
pair: function; address
96100
pair: table; address
97101
pair: memory; address
98102
pair: global; address
103+
pair: element; address
104+
pair: data; address
99105
.. _syntax-funcaddr:
100106
.. _syntax-tableaddr:
101107
.. _syntax-memaddr:
102108
.. _syntax-globaladdr:
109+
.. _syntax-elemaddr:
110+
.. _syntax-dataaddr:
103111
.. _syntax-addr:
104112

105113
Addresses
106114
~~~~~~~~~
107115

108-
: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*.
116+
: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*.
109117
These are simply indices into the respective store component.
110118

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

139151

140-
.. index:: ! instance, function type, function instance, table instance, memory instance, global instance, export instance, table address, memory address, global address, index, name
152+
.. 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
141153
pair: abstract syntax; module instance
142154
pair: module; instance
143155
.. _syntax-moduleinst:
@@ -158,6 +170,8 @@ and collects runtime representations of all entities that are imported, defined,
158170
\MITABLES & \tableaddr^\ast, \\
159171
\MIMEMS & \memaddr^\ast, \\
160172
\MIGLOBALS & \globaladdr^\ast, \\
173+
\MIELEMS & (\elemaddr^?)^\ast, \\
174+
\MIDATAS & (\dataaddr^?)^\ast, \\
161175
\MIEXPORTS & \exportinst^\ast ~\} \\
162176
\end{array}
163177
\end{array}
@@ -275,6 +289,42 @@ It holds an individual :ref:`value <syntax-val>` and a flag indicating whether i
275289
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>`.
276290

277291

292+
.. index:: ! element instance, element segment, embedder, element expression
293+
pair: abstract syntax; element instance
294+
pair: element; instance
295+
.. _syntax-eleminst:
296+
297+
Element Instances
298+
~~~~~~~~~~~~~~~~~
299+
300+
An *element instance* is the runtime representation of an :ref:`element segment <syntax-elem>`.
301+
It holds a vector of :ref:`element expressions <syntax-elemexpr>`.
302+
303+
.. math::
304+
\begin{array}{llll}
305+
\production{(element instance)} & \eleminst &::=&
306+
\{ \EIINIT~\vec(\elemexpr) \} \\
307+
\end{array}
308+
309+
310+
.. index:: ! data instance, data segment, embedder, byte
311+
pair: abstract syntax; data instance
312+
pair: data; instance
313+
.. _syntax-datainst:
314+
315+
Data Instances
316+
~~~~~~~~~~~~~~
317+
318+
An *data instance* is the runtime representation of a :ref:`data segment <syntax-data>`.
319+
It holds a vector of :ref:`bytes <syntax-byte>`.
320+
321+
.. math::
322+
\begin{array}{llll}
323+
\production{(data instance)} & \datainst &::=&
324+
\{ \DIINIT~\vec(\byte) \} \\
325+
\end{array}
326+
327+
278328
.. index:: ! export instance, export, name, external value
279329
pair: abstract syntax; export instance
280330
pair: export; instance

document/core/util/macros.def

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,8 @@
806806
.. |alloctable| mathdef:: \xref{exec/modules}{alloc-table}{\F{alloctable}}
807807
.. |allocmem| mathdef:: \xref{exec/modules}{alloc-mem}{\F{allocmem}}
808808
.. |allocglobal| mathdef:: \xref{exec/modules}{alloc-global}{\F{allocglobal}}
809+
.. |allocelem| mathdef:: \xref{exec/modules}{alloc-elem}{\F{allocelem}}
810+
.. |allocdata| mathdef:: \xref{exec/modules}{alloc-data}{\F{allocdata}}
809811
.. |allocmodule| mathdef:: \xref{exec/modules}{alloc-module}{\F{allocmodule}}
810812

811813
.. |growtable| mathdef:: \xref{exec/modules}{grow-table}{\F{growtable}}
@@ -819,7 +821,8 @@
819821
.. |tableaddr| mathdef:: \xref{exec/runtime}{syntax-tableaddr}{\X{tableaddr}}
820822
.. |memaddr| mathdef:: \xref{exec/runtime}{syntax-memaddr}{\X{memaddr}}
821823
.. |globaladdr| mathdef:: \xref{exec/runtime}{syntax-globaladdr}{\X{globaladdr}}
822-
824+
.. |elemaddr| mathdef:: \xref{exec/runtime}{syntax-elemaddr}{\X{elemaddr}}
825+
.. |dataaddr| mathdef:: \xref{exec/runtime}{syntax-dataaddr}{\X{dataaddr}}
823826

824827
.. Instances, terminals
825828

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

843+
.. |EIINIT| mathdef:: \xref{exec/runtime}{syntax-eleminst}{\K{init}}
844+
845+
.. |DIINIT| mathdef:: \xref{exec/runtime}{syntax-datainst}{\K{init}}
846+
840847
.. |EINAME| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\K{name}}
841848
.. |EIVALUE| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\K{value}}
842849

@@ -850,6 +857,8 @@
850857
.. |MITABLES| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{tableaddrs}}
851858
.. |MIMEMS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{memaddrs}}
852859
.. |MIGLOBALS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{globaladdrs}}
860+
.. |MIELEMS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{elemaddrs}}
861+
.. |MIDATAS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{dataaddrs}}
853862
.. |MIEXPORTS| mathdef:: \xref{exec/runtime}{syntax-moduleinst}{\K{exports}}
854863

855864

@@ -863,6 +872,8 @@
863872
.. |funcelem| mathdef:: \xref{exec/runtime}{syntax-funcelem}{\X{funcelem}}
864873
.. |meminst| mathdef:: \xref{exec/runtime}{syntax-meminst}{\X{meminst}}
865874
.. |globalinst| mathdef:: \xref{exec/runtime}{syntax-globalinst}{\X{globalinst}}
875+
.. |eleminst| mathdef:: \xref{exec/runtime}{syntax-eleminst}{\X{eleminst}}
876+
.. |datainst| mathdef:: \xref{exec/runtime}{syntax-datainst}{\X{datainst}}
866877
.. |exportinst| mathdef:: \xref{exec/runtime}{syntax-exportinst}{\X{exportinst}}
867878

868879
.. |hostfunc| mathdef:: \xref{exec/runtime}{syntax-hostfunc}{\X{hostfunc}}
@@ -882,7 +893,8 @@
882893
.. |STABLES| mathdef:: \xref{exec/runtime}{syntax-store}{\K{tables}}
883894
.. |SMEMS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{mems}}
884895
.. |SGLOBALS| mathdef:: \xref{exec/runtime}{syntax-store}{\K{globals}}
885-
896+
.. |SELEM| mathdef:: \xref{exec/runtime}{syntax-store}{\K{elem}}
897+
.. |SDATA| mathdef:: \xref{exec/runtime}{syntax-store}{\K{data}}
886898

887899
.. Store, non-terminals
888900

0 commit comments

Comments
 (0)