Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit f47a675

Browse files
authored
Segment refactoring (#113)
Refactor segment representation in AST (in both spec and interpreter) by separating out a `segment_mode`. Other changes in Spec: - Various fixes to text format grammar of segments. - Factor out elemkind in binary format. - Add note about possible future extension of element kinds. - Add note about interpretation of segment kinds as bitfields. - Fix some cross references. Other changes in Interpreter: - Rename {table,memory}_segment to {elem,data}_segment. - Some rename elem to elem_expr and global.value to global.ginit for consistency with spec. - Decode the elem segment kind as vu32 to maintain backwards compat. - Some code simplifications / beautifications.
1 parent b1830ae commit f47a675

File tree

20 files changed

+505
-396
lines changed

20 files changed

+505
-396
lines changed

document/core/appendix/index-rules.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ Construct Judgement
2525
:ref:`Table <valid-table>` :math:`C \vdashtable \table : \tabletype`
2626
:ref:`Memory <valid-mem>` :math:`C \vdashmem \mem : \memtype`
2727
:ref:`Global <valid-global>` :math:`C \vdashglobal \global : \globaltype`
28-
:ref:`Element segment <valid-elem>` :math:`C \vdashelem \elem \ok`
29-
:ref:`Data segment <valid-data>` :math:`C \vdashdata \data \ok`
28+
:ref:`Element segment <valid-elem>` :math:`C \vdashelem \elem : \segtype`
29+
:ref:`Element mode <valid-elemmode>` :math:`C \vdashelemmode \elemmode : \segtype`
30+
:ref:`Data segment <valid-data>` :math:`C \vdashdata \data : \segtype`
31+
:ref:`Data mode <valid-datamode>` :math:`C \vdashdatamode \datamode : \segtype`
3032
:ref:`Start function <valid-start>` :math:`C \vdashstart \start \ok`
3133
:ref:`Export <valid-export>` :math:`C \vdashexport \export : \externtype`
3234
:ref:`Export description <valid-exportdesc>` :math:`C \vdashexportdesc \exportdesc : \externtype`

document/core/binary/modules.rst

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ It decodes into an optional :ref:`start function <syntax-start>` that represents
314314
single: element; segment
315315
.. _binary-elem:
316316
.. _binary-elemsec:
317+
.. _binary-elemkind:
317318
.. _binary-elemexpr:
318319

319320
Element Section
@@ -327,28 +328,37 @@ It decodes into a vector of :ref:`element segments <syntax-elem>` that represent
327328
\production{element section} & \Belemsec &::=&
328329
\X{seg}^\ast{:}\Bsection_9(\Bvec(\Belem)) &\Rightarrow& \X{seg} \\
329330
\production{element segment} & \Belem &::=&
330-
\hex{00}~~o{:}\Bexpr~~y^\ast{:}\Bvec(\Bfuncidx)
331-
&\Rightarrow& \{ \ETABLE~0, \EOFFSET~o, \ETYPE~\FUNCREF, \EINIT~((\REFFUNC~y)~\END)^\ast \} \\ &&|&
332-
\hex{01}~~\hex{00}~~y^\ast{:}\Bvec(\Bfuncidx)
333-
&\Rightarrow& \{ \ETYPE~\FUNCREF, \EINIT~((\REFFUNC~y)~\END)^\ast \} \\ &&|&
334-
\hex{02}~~x{:}\Btableidx~~o{:}\Bexpr~~\hex{00}~~y^\ast{:}\Bvec(\Bfuncidx)
335-
&\Rightarrow& \{ \ETABLE~x, \EOFFSET~o, \ETYPE~\FUNCREF, \EINIT~((\REFFUNC~y)~\END)^\ast \} \\ &&|&
336-
\hex{04}~~o{:}\Bexpr~e^\ast{:}\Bvec(\Belemexpr)
337-
&\Rightarrow& \{ \ETABLE~0, \EOFFSET~o, \ETYPE~\FUNCREF, \EINIT~e^\ast \} \\ &&|&
338-
\hex{05}~~\X{et}:\Belemtype~~e^\ast{:}\Bvec(\Belemexpr)
339-
&\Rightarrow& \{ \ETYPE~et, \EINIT~e^\ast \} \\ &&|&
340-
\hex{06}~~x{:}\Btableidx~~o{:}\Bexpr~~\X{et}:\Belemtype~~e^\ast{:}\Bvec(\Belemexpr)
341-
&\Rightarrow& \{ \ETABLE~x, \EOFFSET~o, \ETYPE~et, \EINIT~e^\ast \} \\
342-
\production{elemexpr} & \Belemexpr &::=&
331+
\hex{00}~~e{:}\Bexpr~~y^\ast{:}\Bvec(\Bfuncidx)
332+
&\Rightarrow& \{ \ETYPE~\FUNCREF, \EINIT~((\REFFUNC~y)~\END)^\ast, \EMODE~\EACTIVE~\{ \ETABLE~0, \EOFFSET~e \} \} \\ &&|&
333+
\hex{01}~~\X{et}:\Belemkind~~y^\ast{:}\Bvec(\Bfuncidx)
334+
&\Rightarrow& \{ \ETYPE~\X{et}, \EINIT~((\REFFUNC~y)~\END)^\ast, \EMODE~\EPASSIVE \} \\ &&|&
335+
\hex{02}~~x{:}\Btableidx~~e{:}\Bexpr~~\X{et}:\Belemkind~~y^\ast{:}\Bvec(\Bfuncidx)
336+
&\Rightarrow& \{ \ETYPE~\X{et}, \EINIT~((\REFFUNC~y)~\END)^\ast, \EMODE~\EACTIVE~\{ \ETABLE~x, \EOFFSET~e \} \} \\ &&|&
337+
\hex{04}~~e{:}\Bexpr~~\X{el}^\ast{:}\Bvec(\Belemexpr)
338+
&\Rightarrow& \{ \ETYPE~\FUNCREF, \EINIT~\X{el}^\ast, \EMODE~\EACTIVE~\{ \ETABLE~0, \EOFFSET~e \} \} \\ &&|&
339+
\hex{05}~~\X{et}:\Belemtype~~\X{el}^\ast{:}\Bvec(\Belemexpr)
340+
&\Rightarrow& \{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EPASSIVE \} \\ &&|&
341+
\hex{06}~~x{:}\Btableidx~~e{:}\Bexpr~~\X{et}:\Belemtype~~\X{el}^\ast{:}\Bvec(\Belemexpr)
342+
&\Rightarrow& \{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EACTIVE~\{ \ETABLE~x, \EOFFSET~e \} \} \\
343+
\production{element kind} & \Belemkind &::=&
344+
\hex{00} &\Rightarrow& \FUNCREF \\
345+
\production{element expression} & \Belemexpr &::=&
343346
\hex{D0}~\hex{0B} &\Rightarrow& \REFNULL~\END \\ &&|&
344347
\hex{D2}~x{:}\Bfuncidx~\hex{0B} &\Rightarrow& (\REFFUNC~x)~\END \\
345348
\end{array}
346349
347350
.. note::
351+
The initial byte can be interpreted as a bitfield.
352+
Bit 0 indicates a passive segment,
353+
bit 1 indicates the presence of an explicit table index for an active segment,
354+
bit 2 indicates the use of element type and element expressions instead of element kind and element indices.
355+
348356
In the current version of WebAssembly, at most one table may be defined or
349357
imported in a single module, so all valid :ref:`active <syntax-active>`
350358
element segments have a |ETABLE| value of :math:`0`.
351359

360+
Additional element kinds may be added in future versions of WebAssembly.
361+
352362

353363
.. index:: ! code section, function, local, type index, function type
354364
pair: binary format; function
@@ -427,14 +437,18 @@ It decodes into a vector of :ref:`data segments <syntax-data>` that represent th
427437
\X{seg}^\ast{:}\Bsection_{11}(\Bvec(\Bdata)) &\Rightarrow& \X{seg} \\
428438
\production{data segment} & \Bdata &::=&
429439
\hex{00}~~e{:}\Bexpr~~b^\ast{:}\Bvec(\Bbyte)
430-
&\Rightarrow& \{ \DMEM~0, \DOFFSET~e, \DINIT~b^\ast \} \\ &&|&
440+
&\Rightarrow& \{ \DINIT~b^\ast, \DMODE~\DACTIVE~\{ \DMEM~0, \DOFFSET~e \} \} \\ &&|&
431441
\hex{01}~~b^\ast{:}\Bvec(\Bbyte)
432-
&\Rightarrow& \{ \DINIT~b^\ast \} \\ &&|&
442+
&\Rightarrow& \{ \DINIT~b^\ast, \DMODE~\DPASSIVE \} \\ &&|&
433443
\hex{02}~~x{:}\Bmemidx~~e{:}\Bexpr~~b^\ast{:}\Bvec(\Bbyte)
434-
&\Rightarrow& \{ \DMEM~x, \DOFFSET~e, \DINIT~b^\ast \} \\
444+
&\Rightarrow& \{ \DINIT~b^\ast, \DMODE~\DACTIVE~\{ \DMEM~x, \DOFFSET~e \} \} \\
435445
\end{array}
436446
437447
.. note::
448+
The initial byte can be interpreted as a bitfield.
449+
Bit 0 indicates a passive segment,
450+
bit 1 indicates the presence of an explicit memory index for an active segment.
451+
438452
In the current version of WebAssembly, at most one memory may be defined or
439453
imported in a single module, so all valid :ref:`active <syntax-active>` data
440454
segments have a |DMEM| value of :math:`0`.

document/core/exec/instructions.rst

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ Memory Instructions
667667

668668
17. Execute the instruction :math:`\MEMORYFILL`.
669669

670-
18. Push the value :math:`\vconst_\I32(i+1)` to the stack.
670+
18. Push the value :math:`\vconst_{\I32}(i+1)` to the stack.
671671

672672
19. Push the value :math:`\val` to the stack.
673673

@@ -688,7 +688,7 @@ Memory Instructions
688688
S; F; (\I32.\CONST~i)~\val~(\I32.\CONST~n)~(\MEMORYFILL) &\stepto& S; F;
689689
\begin{array}[t]{@{}l@{}}
690690
(\I32.\CONST~i)~\val~(\I32.\CONST~1)~(\MEMORYFILL) \\
691-
(\vconst_\I32(i+1))~\val~(\I32.\CONST~(n-1))~(\MEMORYFILL) \\
691+
(\vconst_{\I32}(i+1))~\val~(\I32.\CONST~(n-1))~(\MEMORYFILL) \\
692692
\end{array} \\
693693
\end{array}
694694
\\ \qquad
@@ -711,11 +711,11 @@ Memory Instructions
711711

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

714-
6. Assert: due to :ref:`validation <valid-data.init>`, :math:`F.\AMODULE.\MIDATAS[x]` exists.
714+
6. Assert: due to :ref:`validation <valid-memory.init>`, :math:`F.\AMODULE.\MIDATAS[x]` exists.
715715

716716
7. Let :math:`\X{da}` be the :ref:`data address <syntax-dataaddr>` :math:`F.\AMODULE.\MIDATAS[x]`.
717717

718-
8. Assert: due to :ref:`validation <valid-data.init>`, :math:`S.\SDATA[\X{da}]` exists.
718+
8. Assert: due to :ref:`validation <valid-memory.init>`, :math:`S.\SDATA[\X{da}]` exists.
719719

720720
9. Let :math:`\X{data}^?` be the optional :ref:`data instance <syntax-datainst>` :math:`S.\SDATA[\X{da}]`.
721721

@@ -763,9 +763,9 @@ Memory Instructions
763763

764764
22. Execute the instruction :math:`\MEMORYINIT~x`.
765765

766-
23. Push the value :math:`\vconst_\I32(dst+1)` to the stack.
766+
23. Push the value :math:`\vconst_{\I32}(dst+1)` to the stack.
767767

768-
24. Push the value :math:`\vconst_\I32(src+1)` to the stack.
768+
24. Push the value :math:`\vconst_{\I32}(src+1)` to the stack.
769769

770770
25. Push the value :math:`\I32.\CONST~(cnt-1)` to the stack.
771771

@@ -792,7 +792,7 @@ Memory Instructions
792792
S; F; (\I32.\CONST~dst)~(\I32.\CONST~src)~(\I32.\CONST~cnt))~(\MEMORYINIT~x) &\stepto& S; F;
793793
\begin{array}[t]{@{}l@{}}
794794
(\I32.\CONST~dst)~(\I32.\CONST~src)~(\I32.\CONST~1)~(\MEMORYINIT~x) \\
795-
(\vconst_\I32(dst+1))~(\vconst_\I32(src+1))~(\I32.\CONST~(cnt-1))~(\MEMORYINIT~x) \\
795+
(\vconst_{\I32}(dst+1))~(\vconst_{\I32}(src+1))~(\I32.\CONST~(cnt-1))~(\MEMORYINIT~x) \\
796796
\end{array} \\
797797
\end{array}
798798
\\ \qquad
@@ -813,11 +813,11 @@ Memory Instructions
813813

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

816-
2. Assert: due to :ref:`validation <valid-data.init>`, :math:`F.\AMODULE.\MIDATAS[x]` exists.
816+
2. Assert: due to :ref:`validation <valid-data.drop>`, :math:`F.\AMODULE.\MIDATAS[x]` exists.
817817

818818
3. Let :math:`a` be the :ref:`data address <syntax-dataaddr>` :math:`F.\AMODULE.\MIDATAS[x]`.
819819

820-
4. Assert: due to :ref:`validation <valid-data.init>`, :math:`S.\SDATA[a]` exists.
820+
4. Assert: due to :ref:`validation <valid-data.drop>`, :math:`S.\SDATA[a]` exists.
821821

822822
5. Let :math:`\X{data}^?` be the optional :ref:`data instance <syntax-datainst>` :math:`S.\SDATA[a]`.
823823

@@ -890,15 +890,15 @@ Memory Instructions
890890

891891
d. Execute the instruction :math:`\MEMORYCOPY`.
892892

893-
e. Push the value :math:`\vconst_\I32(dst+1)` to the stack.
893+
e. Push the value :math:`\vconst_{\I32}(dst+1)` to the stack.
894894

895-
f. Push the value :math:`\vconst_\I32(src+1)` to the stack.
895+
f. Push the value :math:`\vconst_{\I32}(src+1)` to the stack.
896896

897897
10. Else:
898898

899-
a. Push the value :math:`\vconst_\I32(dst+cnt-1)` to the stack.
899+
a. Push the value :math:`\vconst_{\I32}(dst+cnt-1)` to the stack.
900900

901-
b. Push the value :math:`\vconst_\I32(src+cnt-1)` to the stack.
901+
b. Push the value :math:`\vconst_{\I32}(src+cnt-1)` to the stack.
902902

903903
c. Push the value :math:`\I32.\CONST~1` to the stack.
904904

@@ -932,7 +932,7 @@ Memory Instructions
932932
S; F; (\I32.\CONST~dst)~(\I32.\CONST~src)~(\I32.\CONST~cnt)~\MEMORYCOPY &\stepto& S; F;
933933
\begin{array}[t]{@{}l@{}}
934934
(\I32.\CONST~dst)~(\I32.\CONST~src)~(\I32.\CONST~1)~\MEMORYCOPY \\
935-
(\vconst_\I32(dst+1))~(\vconst_\I32(src+1))~(\I32.\CONST~(cnt-1))~\MEMORYCOPY \\
935+
(\vconst_{\I32}(dst+1))~(\vconst_{\I32}(src+1))~(\I32.\CONST~(cnt-1))~\MEMORYCOPY \\
936936
\end{array} \\
937937
\end{array}
938938
\\ \qquad
@@ -1001,15 +1001,15 @@ Table Instructions
10011001

10021002
d. Execute the instruction :math:`\TABLECOPY`.
10031003

1004-
e. Push the value :math:`\vconst_\I32(dst+1)` to the stack.
1004+
e. Push the value :math:`\vconst_{\I32}(dst+1)` to the stack.
10051005

1006-
f. Push the value :math:`\vconst_\I32(src+1)` to the stack.
1006+
f. Push the value :math:`\vconst_{\I32}(src+1)` to the stack.
10071007

10081008
10. Else:
10091009

1010-
a. Push the value :math:`\vconst_\I32(dst+cnt-1)` to the stack.
1010+
a. Push the value :math:`\vconst_{\I32}(dst+cnt-1)` to the stack.
10111011

1012-
b. Push the value :math:`\vconst_\I32(src+cnt-1)` to the stack.
1012+
b. Push the value :math:`\vconst_{\I32}(src+cnt-1)` to the stack.
10131013

10141014
c. Push the value :math:`\I32.\CONST~1` to the stack.
10151015

@@ -1039,7 +1039,7 @@ Table Instructions
10391039
S; F; (\I32.\CONST~dst)~(\I32.\CONST~src)~(\I32.\CONST~cnt)~\TABLECOPY &\stepto& S; F;
10401040
\begin{array}[t]{@{}l@{}}
10411041
(\I32.\CONST~dst)~(\I32.\CONST~src)~(\I32.\CONST~1)~\TABLECOPY \\
1042-
(\vconst_\I32(dst+1))~(\vconst_\I32(src+1))~(\I32.\CONST~(cnt-1))~\TABLECOPY \\
1042+
(\vconst_{\I32}(dst+1))~(\vconst_{\I32}(src+1))~(\I32.\CONST~(cnt-1))~\TABLECOPY \\
10431043
\end{array} \\
10441044
\end{array}
10451045
\\ \qquad
@@ -1072,11 +1072,11 @@ Table Instructions
10721072

10731073
5. Let :math:`\X{tab}` be the :ref:`table instance <syntax-tableinst>` :math:`S.\STABLES[\X{ta}]`.
10741074

1075-
6. Assert: due to :ref:`validation <valid-elem.init>`, :math:`F.\AMODULE.\MIELEMS[x]` exists.
1075+
6. Assert: due to :ref:`validation <valid-table.init>`, :math:`F.\AMODULE.\MIELEMS[x]` exists.
10761076

10771077
7. Let :math:`\X{ea}` be the :ref:`element address <syntax-elemaddr>` :math:`F.\AMODULE.\MIELEMS[x]`.
10781078

1079-
8. Assert: due to :ref:`validation <valid-elem.init>`, :math:`S.\SELEM[\X{ea}]` exists.
1079+
8. Assert: due to :ref:`validation <valid-table.init>`, :math:`S.\SELEM[\X{ea}]` exists.
10801080

10811081
9. Let :math:`\X{elem}^?` be the optional :ref:`element instance <syntax-eleminst>` :math:`S.\SELEM[\X{ea}]`.
10821082

@@ -1124,9 +1124,9 @@ Table Instructions
11241124

11251125
22. Execute the instruction :math:`\TABLEINIT~x`.
11261126

1127-
23. Push the value :math:`\vconst_\I32(dst+1)` to the stack.
1127+
23. Push the value :math:`\vconst_{\I32}(dst+1)` to the stack.
11281128

1129-
24. Push the value :math:`\vconst_\I32(src+1)` to the stack.
1129+
24. Push the value :math:`\vconst_{\I32}(src+1)` to the stack.
11301130

11311131
25. Push the value :math:`\I32.\CONST~(cnt-1)` to the stack.
11321132

@@ -1153,7 +1153,7 @@ Table Instructions
11531153
S; F; (\I32.\CONST~dst)~(\I32.\CONST~src)~(\I32.\CONST~cnt)~(\TABLEINIT~x) &\stepto& S; F;
11541154
\begin{array}[t]{@{}l@{}}
11551155
(\I32.\CONST~dst)~(\I32.\CONST~src)~(\I32.\CONST~1)~(\TABLEINIT~x) \\
1156-
(\vconst_\I32(dst+1))~(\vconst_\I32(src+1))~(\I32.\CONST~(cnt-1))~(\TABLEINIT~x) \\
1156+
(\vconst_{\I32}(dst+1))~(\vconst_{\I32}(src+1))~(\I32.\CONST~(cnt-1))~(\TABLEINIT~x) \\
11571157
\end{array} \\
11581158
\end{array}
11591159
\\ \qquad
@@ -1174,11 +1174,11 @@ Table Instructions
11741174

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

1177-
2. Assert: due to :ref:`validation <valid-elem.init>`, :math:`F.\AMODULE.\MIELEMS[x]` exists.
1177+
2. Assert: due to :ref:`validation <valid-elem.drop>`, :math:`F.\AMODULE.\MIELEMS[x]` exists.
11781178

11791179
3. Let :math:`a` be the :ref:`element address <syntax-elemaddr>` :math:`F.\AMODULE.\MIELEMS[x]`.
11801180

1181-
4. Assert: due to :ref:`validation <valid-elem.init>`, :math:`S.\SELEM[a]` exists.
1181+
4. Assert: due to :ref:`validation <valid-elem.drop>`, :math:`S.\SELEM[a]` exists.
11821182

11831183
5. Let :math:`\X{elem}^?` be the optional :ref:`elem instance <syntax-eleminst>` :math:`S.\SELEM[a]`.
11841184

document/core/exec/modules.rst

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ Moreover, if the dots :math:`\dots` are a sequence :math:`A^n` (as for globals),
614614
Instantiation
615615
~~~~~~~~~~~~~
616616

617+
.. todo:: Adjust for passive segments.
618+
617619
Given a :ref:`store <syntax-store>` :math:`S`, a :ref:`module <syntax-module>` :math:`\module` is instantiated with a list of :ref:`external values <syntax-externval>` :math:`\externval^n` supplying the required imports as follows.
618620

619621
Instantiation checks that the module is :ref:`valid <valid>` and the provided imports :ref:`match <match-externtype>` the declared types,
@@ -665,55 +667,51 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
665667

666668
8. Push the frame :math:`F` to the stack.
667669

668-
9. For each :ref:`element segment <syntax-elem>` :math:`\elem_i` in :math:`\module.\MELEM`, do:
669-
670-
a. Let :math:`\X{eoval}_i` be the result of :ref:`evaluating <exec-expr>` the expression :math:`\elem_i.\EOFFSET`.
670+
9. For each :ref:`element segment <syntax-elem>` :math:`\elem_i` in :math:`\module.\MELEM` whose :ref:`mode <syntax-elemmode>` :math:`\elem_i.\EMODE` is of the form :math:`\EACTIVE~\{ \ETABLE~\tableidx_i, \EOFFSET~\X{eoexpr}_i \}`, do:
671671

672-
b. Assert: due to :ref:`validation <valid-elem>`, :math:`\X{eoval}_i` is of the form :math:`\I32.\CONST~\X{eo}_i`.
672+
a. Assert: due to :ref:`validation <valid-elem>`, :math:`\moduleinst.\MITABLES[\tableidx_i]` exists.
673673

674-
c. Let :math:`\tableidx_i` be the :ref:`table index <syntax-tableidx>` :math:`\elem_i.\ETABLE`.
674+
b. Let :math:`\tableaddr_i` be the :ref:`table address <syntax-tableaddr>` :math:`\moduleinst.\MITABLES[\tableidx_i]`.
675675

676-
d. Assert: due to :ref:`validation <valid-elem>`, :math:`\moduleinst.\MITABLES[\tableidx_i]` exists.
676+
c. Assert: due to :ref:`validation <valid-elem>`, :math:`S'.\STABLES[\tableaddr_i]` exists.
677677

678-
e. Let :math:`\tableaddr_i` be the :ref:`table address <syntax-tableaddr>` :math:`\moduleinst.\MITABLES[\tableidx_i]`.
678+
d. Let :math:`\tableinst_i` be the :ref:`table instance <syntax-tableinst>` :math:`S'.\STABLES[\tableaddr_i]`.
679679

680-
f. Assert: due to :ref:`validation <valid-elem>`, :math:`S'.\STABLES[\tableaddr_i]` exists.
680+
e. Let :math:`\X{eoval}_i` be the result of :ref:`evaluating <exec-expr>` the expression :math:`\X{eoexpr}_i`.
681681

682-
g. Let :math:`\tableinst_i` be the :ref:`table instance <syntax-tableinst>` :math:`S'.\STABLES[\tableaddr_i]`.
682+
f. Assert: due to :ref:`validation <valid-elem>`, :math:`\X{eoval}_i` is of the form :math:`\I32.\CONST~\X{eo}_i`.
683683

684-
h. Let :math:`\X{eend}_i` be :math:`\X{eo}_i` plus the length of :math:`\elem_i.\EINIT`.
684+
g. Let :math:`\X{eend}_i` be :math:`\X{eo}_i` plus the length of :math:`\elem_i.\EINIT`.
685685

686-
i. If :math:`\X{eend}_i` is larger than the length of :math:`\tableinst_i.\TIELEM`, then:
686+
h. If :math:`\X{eend}_i` is larger than the length of :math:`\tableinst_i.\TIELEM`, then:
687687

688688
i. Fail.
689689

690-
10. For each :ref:`data segment <syntax-data>` :math:`\data_i` in :math:`\module.\MDATA`, do:
691-
692-
a. Let :math:`\X{doval}_i` be the result of :ref:`evaluating <exec-expr>` the expression :math:`\data_i.\DOFFSET`.
690+
10. For each :ref:`data segment <syntax-data>` :math:`\data_i` in :math:`\module.\MDATA` whose :ref:`mode <syntax-datamode>` :math:`\data_i.\DMODE` is of the form :math:`\DACTIVE~\{ \DMEM~\memidx_i, \DOFFSET~\X{doexpr}_i \}`, do:
693691

694-
b. Assert: due to :ref:`validation <valid-data>`, :math:`\X{doval}_i` is of the form :math:`\I32.\CONST~\X{do}_i`.
692+
a. Assert: due to :ref:`validation <valid-data>`, :math:`\moduleinst.\MIMEMS[\memidx_i]` exists.
695693

696-
c. Let :math:`\memidx_i` be the :ref:`memory index <syntax-memidx>` :math:`\data_i.\DMEM`.
694+
b. Let :math:`\memaddr_i` be the :ref:`memory address <syntax-memaddr>` :math:`\moduleinst.\MIMEMS[\memidx_i]`.
697695

698-
d. Assert: due to :ref:`validation <valid-data>`, :math:`\moduleinst.\MIMEMS[\memidx_i]` exists.
696+
c. Assert: due to :ref:`validation <valid-data>`, :math:`S'.\SMEMS[\memaddr_i]` exists.
699697

700-
e. Let :math:`\memaddr_i` be the :ref:`memory address <syntax-memaddr>` :math:`\moduleinst.\MIMEMS[\memidx_i]`.
698+
d. Let :math:`\meminst_i` be the :ref:`memory instance <syntax-meminst>` :math:`S'.\SMEMS[\memaddr_i]`.
701699

702-
f. Assert: due to :ref:`validation <valid-data>`, :math:`S'.\SMEMS[\memaddr_i]` exists.
700+
e. Let :math:`\X{doval}_i` be the result of :ref:`evaluating <exec-expr>` the expression :math:`\data_i.\DOFFSET`.
703701

704-
g. Let :math:`\meminst_i` be the :ref:`memory instance <syntax-meminst>` :math:`S'.\SMEMS[\memaddr_i]`.
702+
f. Assert: due to :ref:`validation <valid-data>`, :math:`\X{doval}_i` is of the form :math:`\I32.\CONST~\X{do}_i`.
705703

706-
h. Let :math:`\X{dend}_i` be :math:`\X{do}_i` plus the length of :math:`\data_i.\DINIT`.
704+
g. Let :math:`\X{dend}_i` be :math:`\X{do}_i` plus the length of :math:`\data_i.\DINIT`.
707705

708-
i. If :math:`\X{dend}_i` is larger than the length of :math:`\meminst_i.\MIDATA`, then:
706+
h. If :math:`\X{dend}_i` is larger than the length of :math:`\meminst_i.\MIDATA`, then:
709707

710708
i. Fail.
711709

712710
11. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F` is now on the top of the stack.
713711

714712
12. Pop the frame from the stack.
715713

716-
13. For each :ref:`element segment <syntax-elem>` :math:`\elem_i` in :math:`\module.\MELEM`, do:
714+
13. For each :ref:`element segment <syntax-elem>` :math:`\elem_i` in :math:`\module.\MELEM` whose :ref:`mode <syntax-elemmode>` :math:`\elem_i.\EMODE` is of the form :math:`\EACTIVE~\{ \ETABLE~\tableidx_i, \EOFFSET~\X{eoexpr}_i \}`, do:
717715

718716
a. For each :ref:`function index <syntax-funcidx>` :math:`\funcidx_{ij}` in :math:`\elem_i.\EINIT` (starting with :math:`j = 0`), do:
719717

@@ -723,7 +721,7 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
723721

724722
iii. Replace :math:`\tableinst_i.\TIELEM[\X{eo}_i + j]` with :math:`\funcaddr_{ij}`.
725723

726-
14. For each :ref:`data segment <syntax-data>` :math:`\data_i` in :math:`\module.\MDATA`, do:
724+
14. For each :ref:`data segment <syntax-data>` :math:`\data_i` in :math:`\module.\MDATA` whose :ref:`mode <syntax-datamode>` :math:`\data_i.\DMODE` is of the form :math:`\DACTIVE~\{ \DMEM~\memidx_i, \DOFFSET~\X{doexpr}_i \}`, do:
727725

728726
a. For each :ref:`byte <syntax-byte>` :math:`b_{ij}` in :math:`\data_i.\DINIT` (starting with :math:`j = 0`), do:
729727

document/core/exec/runtime.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ Element Instances
314314
~~~~~~~~~~~~~~~~~
315315

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

319319
.. math::
320320
\begin{array}{llll}

0 commit comments

Comments
 (0)