You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
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.
Copy file name to clipboardExpand all lines: document/core/exec/modules.rst
+22-24Lines changed: 22 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -614,6 +614,8 @@ Moreover, if the dots :math:`\dots` are a sequence :math:`A^n` (as for globals),
614
614
Instantiation
615
615
~~~~~~~~~~~~~
616
616
617
+
.. todo:: Adjust for passive segments.
618
+
617
619
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.
618
620
619
621
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
665
667
666
668
8. Push the frame :math:`F` to the stack.
667
669
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:
671
671
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.
673
673
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]`.
675
675
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.
677
677
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]`.
679
679
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`.
681
681
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`.
683
683
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`.
685
685
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:
687
687
688
688
i. Fail.
689
689
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:
693
691
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.
695
693
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]`.
697
695
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.
699
697
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]`.
701
699
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`.
703
701
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`.
705
703
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`.
707
705
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:
709
707
710
708
i. Fail.
711
709
712
710
11. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F` is now on the top of the stack.
713
711
714
712
12. Pop the frame from the stack.
715
713
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:
717
715
718
716
a. For each :ref:`function index <syntax-funcidx>` :math:`\funcidx_{ij}` in :math:`\elem_i.\EINIT` (starting with :math:`j = 0`), do:
719
717
@@ -723,7 +721,7 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
723
721
724
722
iii. Replace :math:`\tableinst_i.\TIELEM[\X{eo}_i + j]` with :math:`\funcaddr_{ij}`.
725
723
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:
727
725
728
726
a. For each :ref:`byte <syntax-byte>` :math:`b_{ij}` in :math:`\data_i.\DINIT` (starting with :math:`j = 0`), do:
0 commit comments