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.
Copy file name to clipboardExpand all lines: document/core/exec/modules.rst
+41-27Lines changed: 41 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -439,30 +439,28 @@ The allocation function for :ref:`modules <syntax-module>` requires a suitable l
439
439
a list of initialization :ref:`values <syntax-val>` for the module's :ref:`globals <syntax-global>`,
440
440
and list of :ref:`reference <syntax-ref>` vectors for the module's :ref:`element segments <syntax-elem>`.
441
441
442
-
1. Let :math:`\module` be the :ref:`module <syntax-module>` to allocate and :math:`\externval_{\F{im}}^\ast` the vector of :ref:`external values <syntax-externval>` providing the module's imports, :math:`\val^\ast` the initialization :ref:`values <syntax-val>` of the module's :ref:`globals <syntax-global>`, and :math:`(\reff^\ast)^\ast` the :ref:`reference <syntax-ref>` vectors of the module's :ref:`element segments <syntax-elem>`.
442
+
1. Let :math:`\module` be the :ref:`module <syntax-module>` to allocate and :math:`\externval_{\F{im}}^\ast` the vector of :ref:`external values <syntax-externval>` providing the module's imports, :math:`\val_{\F{g}}^\ast` the initialization :ref:`values <syntax-val>` of the module's :ref:`globals <syntax-global>`, :math:`\reff_{\F{t}}^\ast` the initializer :ref:`reference <syntax-ref>` of the module's :ref:`tables <syntax-table>`, and :math:`(\reff_{\F{e}}^\ast)^\ast` the :ref:`reference <syntax-ref>` vectors of the module's :ref:`element segments <syntax-elem>`.
443
443
444
444
2. For each :ref:`function <syntax-func>` :math:`\func_i` in :math:`\module.\MFUNCS`, do:
445
445
446
446
a. Let :math:`\funcaddr_i` be the :ref:`function address <syntax-funcaddr>` resulting from :ref:`allocating <alloc-func>` :math:`\func_i` for the :ref:`\module instance <syntax-moduleinst>` :math:`\moduleinst` defined below.
447
447
448
448
3. For each :ref:`table <syntax-table>` :math:`\table_i` in :math:`\module.\MTABLES`, do:
449
449
450
-
a. Let :math:`\limits_i~t_i` be the :ref:`table type <syntax-tabletype>` :math:`\table_i.\TTYPE`.
451
-
452
-
b. Let :math:`\tableaddr_i` be the :ref:`table address <syntax-tableaddr>` resulting from :ref:`allocating <alloc-table>` :math:`\table_i.\TTYPE`
453
-
with initialization value :math:`\REFNULL~t_i`.
450
+
a. Let :math:`\tableaddr_i` be the :ref:`table address <syntax-tableaddr>` resulting from :ref:`allocating <alloc-table>` :math:`\table_i.\TTYPE`
451
+
with initialization value :math:`\ref_{\F{t}}^\ast[i]`.
454
452
455
453
4. For each :ref:`memory <syntax-mem>` :math:`\mem_i` in :math:`\module.\MMEMS`, do:
456
454
457
455
a. Let :math:`\memaddr_i` be the :ref:`memory address <syntax-memaddr>` resulting from :ref:`allocating <alloc-mem>` :math:`\mem_i.\MTYPE`.
458
456
459
457
5. For each :ref:`global <syntax-global>` :math:`\global_i` in :math:`\module.\MGLOBALS`, do:
460
458
461
-
a. Let :math:`\globaladdr_i` be the :ref:`global address <syntax-globaladdr>` resulting from :ref:`allocating <alloc-global>` :math:`\global_i.\GTYPE` with initializer value :math:`\val^\ast[i]`.
459
+
a. Let :math:`\globaladdr_i` be the :ref:`global address <syntax-globaladdr>` resulting from :ref:`allocating <alloc-global>` :math:`\global_i.\GTYPE` with initializer value :math:`\val_{\F{g}}^\ast[i]`.
462
460
463
461
6. For each :ref:`element segment <syntax-elem>` :math:`\elem_i` in :math:`\module.\MELEMS`, do:
464
462
465
-
a. Let :math:`\elemaddr_i` be the :ref:`element address <syntax-elemaddr>` resulting from :ref:`allocating <alloc-elem>` an :ref:`element instance <syntax-eleminst>` of :ref:`reference type <syntax-reftype>` :math:`\elem_i.\ETYPE` with contents :math:`(\reff^\ast)^\ast[i]`.
463
+
a. Let :math:`\elemaddr_i` be the :ref:`element address <syntax-elemaddr>` resulting from :ref:`allocating <alloc-elem>` an :ref:`element instance <syntax-eleminst>` of :ref:`reference type <syntax-reftype>` :math:`\elem_i.\ETYPE` with contents :math:`(\reff_{\F{e}}^\ast)^\ast[i]`.
466
464
467
465
7. For each :ref:`data segment <syntax-data>` :math:`\data_i` in :math:`\module.\MDATAS`, do:
468
466
@@ -510,7 +508,7 @@ and list of :ref:`reference <syntax-ref>` vectors for the module's :ref:`element
@@ -627,35 +625,49 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
627
625
628
626
7. Push the frame :math:`F_{\F{init}}` to the stack.
629
627
630
-
8. Let :math:`\val^\ast` be the vector of :ref:`global <syntax-global>` initialization :ref:`values <syntax-val>` determined by :math:`\module` and :math:`\externval^n`. These may be calculated as follows.
628
+
8. Let :math:`\val_{\F{g}}^\ast` be the vector of :ref:`global <syntax-global>` initialization :ref:`values <syntax-val>` determined by :math:`\module` and :math:`\externval^n`. These may be calculated as follows.
631
629
632
630
a. For each :ref:`global <syntax-global>` :math:`\global_i` in :math:`\module.\MGLOBALS`, do:
633
631
634
-
i. Let :math:`\val_i` be the result of :ref:`evaluating <exec-expr>` the initializer expression :math:`\global_i.\GINIT`.
632
+
i. Let :math:`\val_{\F{g}i}` be the result of :ref:`evaluating <exec-expr>` the initializer expression :math:`\global_i.\GINIT`.
633
+
634
+
b. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F_{\F{init}}` is now on the top of the stack.
635
+
636
+
c. Let :math:`\val_{\F{g}}^\ast` be the concatenation of :math:`\val_{\F{g}i}` in index order.
637
+
638
+
9. Let :math:`\reff_{\F{t}}^\ast` be the vector of :ref:`table <syntax-table>` initialization :ref:`references <syntax-ref>` determined by :math:`\module` and :math:`\externval^n`. These may be calculated as follows.
639
+
640
+
a. For each :ref:`table <syntax-table>` :math:`\table_i` in :math:`\module.\MTABLES`, do:
641
+
642
+
i. Let :math:`\val_{\F{t}i}` be the result of :ref:`evaluating <exec-expr>` the initializer expression :math:`\table_i.\TINIT`.
643
+
644
+
ii. Assert: due to :ref:`validation <valid-table>`, :math:`\val_{\F{t}i}` is a :ref:`reference <syntax-ref>`.
645
+
646
+
iii. Let :math:`\reff_{\F{t}i}` be the reference :math:`\val_{\F{t}i}`.
635
647
636
648
b. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F_{\F{init}}` is now on the top of the stack.
637
649
638
-
c. Let :math:`\val^\ast` be the concatenation of :math:`\val_i` in index order.
650
+
c. Let :math:`\reff_{\F{t}}^\ast` be the concatenation of :math:`\reff_{ti}` in index order.
639
651
640
-
9. Let :math:`(\reff^\ast)^\ast` be the list of :ref:`reference <syntax-ref>` vectors determined by the :ref:`element segments <syntax-elem>` in :math:`\module`. These may be calculated as follows.
652
+
10. Let :math:`(\reff_{\F{e}}^\ast)^\ast` be the list of :ref:`reference <syntax-ref>` vectors determined by the :ref:`element segments <syntax-elem>` in :math:`\module`. These may be calculated as follows.
641
653
642
654
a. For each :ref:`element segment <syntax-elem>` :math:`\elem_i` in :math:`\module.\MELEMS`, and for each element :ref:`expression <syntax-expr>` :math:`\expr_{ij}` in :math:`\elem_i.\EINIT`, do:
643
655
644
656
i. Let :math:`\reff_{ij}` be the result of :ref:`evaluating <exec-expr>` the initializer expression :math:`\expr_{ij}`.
645
657
646
658
b. Let :math:`\reff^\ast_i` be the concatenation of function elements :math:`\reff_{ij}` in order of index :math:`j`.
647
659
648
-
c. Let :math:`(\reff^\ast)^\ast` be the concatenation of function element vectors :math:`\reff^\ast_i` in order of index :math:`i`.
660
+
c. Let :math:`(\reff_{\F{e}}^\ast)^\ast` be the concatenation of function element vectors :math:`\reff^\ast_i` in order of index :math:`i`.
649
661
650
-
10. Pop the frame :math:`F_{\F{init}}` from the stack.
662
+
11. Pop the frame :math:`F_{\F{init}}` from the stack.
651
663
652
-
11. Let :math:`\moduleinst` be a new module instance :ref:`allocated <alloc-module>` from :math:`\module` in store :math:`S` with imports :math:`\externval^n`, global initializer values :math:`\val^\ast`, and element segment contents :math:`(\reff^\ast)^\ast`, and let :math:`S'` be the extended store produced by module allocation.
664
+
12. Let :math:`\moduleinst` be a new module instance :ref:`allocated <alloc-module>` from :math:`\module` in store :math:`S` with imports :math:`\externval^n`, global initializer values :math:`\val_{\F{g}}^\ast`, table initializer values :math:`\reff_{\F{t}}^\ast`, and element segment contents :math:`(\reff_{\F{e}}^\ast)^\ast`, and let :math:`S'` be the extended store produced by module allocation.
653
665
654
-
12. Let :math:`F` be the auxiliary :ref:`frame <syntax-frame>` :math:`\{ \AMODULE~\moduleinst, \ALOCALS~\epsilon \}`.
666
+
13. Let :math:`F` be the auxiliary :ref:`frame <syntax-frame>` :math:`\{ \AMODULE~\moduleinst, \ALOCALS~\epsilon \}`.
655
667
656
-
13. Push the frame :math:`F` to the stack.
668
+
14. Push the frame :math:`F` to the stack.
657
669
658
-
14. For each :ref:`element segment <syntax-elem>` :math:`\elem_i` in :math:`\module.\MELEMS` whose :ref:`mode <syntax-elemmode>` is of the form :math:`\EACTIVE~\{ \ETABLE~\tableidx_i, \EOFFSET~\X{einstr}^\ast_i~\END \}`, do:
670
+
15. For each :ref:`element segment <syntax-elem>` :math:`\elem_i` in :math:`\module.\MELEMS` whose :ref:`mode <syntax-elemmode>` is of the form :math:`\EACTIVE~\{ \ETABLE~\tableidx_i, \EOFFSET~\X{einstr}^\ast_i~\END \}`, do:
659
671
660
672
a. Let :math:`n` be the length of the vector :math:`\elem_i.\EINIT`.
661
673
@@ -669,7 +681,7 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
669
681
670
682
f. :ref:`Execute <exec-elem.drop>` the instruction :math:`\ELEMDROP~i`.
671
683
672
-
15. For each :ref:`data segment <syntax-data>` :math:`\data_i` in :math:`\module.\MDATAS` whose :ref:`mode <syntax-datamode>` is of the form :math:`\DACTIVE~\{ \DMEM~\memidx_i, \DOFFSET~\X{dinstr}^\ast_i~\END \}`, do:
684
+
16. For each :ref:`data segment <syntax-data>` :math:`\data_i` in :math:`\module.\MDATAS` whose :ref:`mode <syntax-datamode>` is of the form :math:`\DACTIVE~\{ \DMEM~\memidx_i, \DOFFSET~\X{dinstr}^\ast_i~\END \}`, do:
673
685
674
686
a. Assert: :math:`\memidx_i` is :math:`0`.
675
687
@@ -685,15 +697,15 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
685
697
686
698
g. :ref:`Execute <exec-data.drop>` the instruction :math:`\DATADROP~i`.
687
699
688
-
16. If the :ref:`start function <syntax-start>` :math:`\module.\MSTART` is not empty, then:
700
+
17. If the :ref:`start function <syntax-start>` :math:`\module.\MSTART` is not empty, then:
689
701
690
702
a. Let :math:`\start` be the :ref:`start function <syntax-start>` :math:`\module.\MSTART`.
691
703
692
704
b. :ref:`Execute <exec-call>` the instruction :math:`\CALL~\start.\SFUNC`.
693
705
694
-
17. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F` is now on the top of the stack.
706
+
18. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F` is now on the top of the stack.
695
707
696
-
18. Pop the frame :math:`F` from the stack.
708
+
19. Pop the frame :math:`F` from the stack.
697
709
698
710
699
711
.. math::
@@ -714,11 +726,13 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
Copy file name to clipboardExpand all lines: document/core/syntax/modules.rst
+5-4Lines changed: 5 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -172,13 +172,14 @@ The |MTABLES| component of a module defines a vector of *tables* described by th
172
172
.. math::
173
173
\begin{array}{llll}
174
174
\production{table} & \table &::=&
175
-
\{ \TTYPE~\tabletype \} \\
175
+
\{ \TTYPE~\tabletype, \TINIT~\expr \} \\
176
176
\end{array}
177
177
178
-
A table is a vector of opaque values of a particular :ref:`reference type <syntax-reftype>`.
179
-
The |LMIN| size in the :ref:`limits <syntax-limits>` of the table type specifies the initial size of that table, while its |LMAX|, if present, restricts the size to which it can grow later.
178
+
A table is an array of opaque values of a particular :ref:`reference type <syntax-reftype>`.
179
+
Moreover, each table slot is initialized with the |TINIT| value given by a :ref:`constant <valid-constant>` initializer :ref:`expression <syntax-expr>`.
180
+
Tables can further be initialized through :ref:`element segments <syntax-elem>`.
180
181
181
-
Tables can be initialized through:ref:`element segments <syntax-elem>`.
182
+
The |LMIN| size in the:ref:`limits <syntax-limits>` of the table type specifies the initial size of that table, while its |LMAX|, if present, restricts the size to which it can grow later.
182
183
183
184
Tables are referenced through :ref:`table indices <syntax-tableidx>`,
184
185
starting with the smallest index not referencing a table :ref:`import <syntax-import>`.
0 commit comments