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
Copy file name to clipboardExpand all lines: document/core/exec/instructions.rst
+29-37Lines changed: 29 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1341,47 +1341,43 @@ Where:
1341
1341
1342
1342
19. Assert: due to :ref:`validation <valid-array.init_data>`, the :ref:`array instance <syntax-arrayinst>` :math:`S.\SARRAYS[a]` exists.
1343
1343
1344
-
20. If :math:`d + n` is larger than or equal to the length of :math:`S.\SARRAYS[a].\AIFIELDS`, then:
1344
+
20. Assert: due to :ref:`validation <valid-array.init_data>`, the :ref:`field type <syntax-fieldtype>` :math:`\X{ft}` has a defined :ref:`bit width <bitwidth-fieldtype>`.
1345
1345
1346
-
a. Trap.
1347
-
1348
-
21. Assert: due to :ref:`validation <valid-array.init_data>`, the :ref:`field type <syntax-fieldtype>` :math:`\X{ft}` has a defined :ref:`bit width <bitwidth-fieldtype>`.
1346
+
21. Let :math:`z` be the :ref:`bit width <bitwidth-fieldtype>` of :ref:`field type <syntax-fieldtype>` :math:`\X{ft}` divided by eight.
1349
1347
1350
-
22. Let :math:`z` be the :ref:`bit width <bitwidth-fieldtype>` of :ref:`field type <syntax-fieldtype>` :math:`\X{ft}` divided by eight.
1351
-
1352
-
23. If the sum of :math:`s` and :math:`n` times :math:`z` is larger than the length of :math:`\datainst.\DIDATA`, then:
1348
+
22. If :math:`d + n` is larger than the length of :math:`S.\SARRAYS[a].\AIFIELDS`, or the sum of :math:`s` and :math:`n` times :math:`z` is larger than the length of :math:`\datainst.\DIDATA`, then:
1353
1349
1354
1350
a. Trap.
1355
1351
1356
-
24. If :math:`n = 0`, then:
1352
+
23. If :math:`n = 0`, then:
1357
1353
1358
1354
a. Return.
1359
1355
1360
-
25. Let :math:`b^\ast` be the :ref:`byte <syntax-byte>` sequence :math:`\datainst.\DIDATA[s \slice z]`.
1356
+
24. Let :math:`b^\ast` be the :ref:`byte <syntax-byte>` sequence :math:`\datainst.\DIDATA[s \slice z]`.
1361
1357
1362
-
26. Let :math:`t` be the :ref:`value type <syntax-valtype>` :math:`\unpacktype(\X{ft})`.
1358
+
25. Let :math:`t` be the :ref:`value type <syntax-valtype>` :math:`\unpacktype(\X{ft})`.
1363
1359
1364
-
27. Assert: due to :ref:`validation <valid-array.init_data>`, :math:`\bytes_{\X{ft}}` is defined.
1360
+
26. Assert: due to :ref:`validation <valid-array.init_data>`, :math:`\bytes_{\X{ft}}` is defined.
1365
1361
1366
-
28. Let :math:`c` be the constant for which :math:`\bytes_{\X{ft}}(c)` is :math:`b^\ast`.
1362
+
27. Let :math:`c` be the constant for which :math:`\bytes_{\X{ft}}(c)` is :math:`b^\ast`.
1367
1363
1368
-
29. Push the value :math:`\REFARRAYADDR~a` to the stack.
1364
+
28. Push the value :math:`\REFARRAYADDR~a` to the stack.
1369
1365
1370
-
30. Push the value :math:`\I32.\CONST~d` to the stack.
1366
+
29. Push the value :math:`\I32.\CONST~d` to the stack.
1371
1367
1372
-
31. Push the value :math:`t.\CONST~c` to the stack.
1368
+
30. Push the value :math:`t.\CONST~c` to the stack.
1373
1369
1374
-
32. Execute the instruction :math:`\ARRAYSET~x`.
1370
+
31. Execute the instruction :math:`\ARRAYSET~x`.
1375
1371
1376
-
33. Push the value :math:`\REFARRAYADDR~a` to the stack.
1372
+
32. Push the value :math:`\REFARRAYADDR~a` to the stack.
1377
1373
1378
-
34. Push the value :math:`\I32.\CONST~(d+1)` to the stack.
1374
+
33. Push the value :math:`\I32.\CONST~(d+1)` to the stack.
1379
1375
1380
-
35. Push the value :math:`\I32.\CONST~(s+z)` to the stack.
1376
+
34. Push the value :math:`\I32.\CONST~(s+z)` to the stack.
1381
1377
1382
-
36. Push the value :math:`\I32.\CONST~(n-1)` to the stack.
1378
+
35. Push the value :math:`\I32.\CONST~(n-1)` to the stack.
1383
1379
1384
-
37. Execute the instruction :math:`\ARRAYINITDATA~x~y`.
1380
+
36. Execute the instruction :math:`\ARRAYINITDATA~x~y`.
1385
1381
1386
1382
.. math::
1387
1383
~\\[-1ex]
@@ -1462,37 +1458,33 @@ Where:
1462
1458
1463
1459
19. Assert: due to :ref:`validation <valid-array.init_elem>`, the :ref:`array instance <syntax-arrayinst>` :math:`S.\SARRAYS[a]` exists.
1464
1460
1465
-
20. If :math:`d + n` is larger than or equal to the length of :math:`S.\SARRAYS[a].\AIFIELDS`, then:
1461
+
20. If :math:`d + n` is larger than the length of :math:`S.\SARRAYS[a].\AIFIELDS`, or :math:`s + n` is larger than the length of :math:`\eleminst.\EIELEM`, then:
1466
1462
1467
1463
a. Trap.
1468
1464
1469
-
21. If :math:`s + n` is larger than or equal to the length of :math:`\eleminst.\EIELEM`, then:
1470
-
1471
-
a. Trap.
1472
-
1473
-
22. If :math:`n = 0`, then:
1465
+
21. If :math:`n = 0`, then:
1474
1466
1475
1467
a. Return.
1476
1468
1477
-
23. Let :math:`\reff'` be the :ref:`reference value <syntax-ref>` :math:`\eleminst.\EIELEM[s]`.
1469
+
22. Let :math:`\reff'` be the :ref:`reference value <syntax-ref>` :math:`\eleminst.\EIELEM[s]`.
1478
1470
1479
-
24. Push the value :math:`\REFARRAYADDR~a` to the stack.
1471
+
23. Push the value :math:`\REFARRAYADDR~a` to the stack.
1480
1472
1481
-
25. Push the value :math:`\I32.\CONST~d` to the stack.
1473
+
24. Push the value :math:`\I32.\CONST~d` to the stack.
1482
1474
1483
-
26. Push the value :math:`\reff'` to the stack.
1475
+
25. Push the value :math:`\reff'` to the stack.
1484
1476
1485
-
27. Execute the instruction :math:`\ARRAYSET~x`.
1477
+
26. Execute the instruction :math:`\ARRAYSET~x`.
1486
1478
1487
-
28. Push the value :math:`\REFARRAYADDR~a` to the stack.
1479
+
27. Push the value :math:`\REFARRAYADDR~a` to the stack.
1488
1480
1489
-
29. Push the value :math:`\I32.\CONST~(d+1)` to the stack.
1481
+
28. Push the value :math:`\I32.\CONST~(d+1)` to the stack.
1490
1482
1491
-
30. Push the value :math:`\I32.\CONST~(s+1)` to the stack.
1483
+
29. Push the value :math:`\I32.\CONST~(s+1)` to the stack.
1492
1484
1493
-
31. Push the value :math:`\I32.\CONST~(n-1)` to the stack.
1485
+
30. Push the value :math:`\I32.\CONST~(n-1)` to the stack.
1494
1486
1495
-
32. Execute the instruction :math:`\ARRAYINITELEM~x~y`.
1487
+
31. Execute the instruction :math:`\ARRAYINITELEM~x~y`.
Copy file name to clipboardExpand all lines: document/core/exec/modules.rst
+12-20Lines changed: 12 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -517,19 +517,17 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
517
517
518
518
.. _exec-initvals:
519
519
520
-
5. Let :math:`\moduleinst_{\F{init}}` be the auxiliary module :ref:`instance<syntax-moduleinst>` :math:`\{\MIGLOBALS~\evglobals(\externval^n), \MIFUNCS~\moduleinst.\MIFUNCS\}` that only consists of the imported globals and the imported and allocated functions from the final module instance :math:`\moduleinst`, defined below.
520
+
6. Let :math:`F` be the auxiliary :ref:`frame<syntax-frame>` :math:`\{\AMODULE~\moduleinst, \ALOCALS~\epsilon \}`, that consists of the final module instance :math:`\moduleinst`, defined below.
521
521
522
-
6. Let :math:`F_{\F{init}}` be the auxiliary :ref:`frame <syntax-frame>` :math:`\{ \AMODULE~\moduleinst_{\F{init}}, \ALOCALS~\epsilon \}`.
523
-
524
-
7. Push the frame :math:`F_{\F{init}}` to the stack.
522
+
7. Push the frame :math:`F` to the stack.
525
523
526
524
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.
527
525
528
526
a. For each :ref:`global <syntax-global>` :math:`\global_i` in :math:`\module.\MGLOBALS`, do:
529
527
530
528
i. Let :math:`\val_{\F{g}i}` be the result of :ref:`evaluating <exec-expr>` the initializer expression :math:`\global_i.\GINIT`.
531
529
532
-
b. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F_{\F{init}}` is now on the top of the stack.
530
+
b. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F` is now on the top of the stack.
533
531
534
532
c. Let :math:`\val_{\F{g}}^\ast` be the concatenation of :math:`\val_{\F{g}i}` in index order.
535
533
@@ -543,7 +541,7 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
543
541
544
542
iii. Let :math:`\reff_{\F{t}i}` be the reference :math:`\val_{\F{t}i}`.
545
543
546
-
b. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F_{\F{init}}` is now on the top of the stack.
544
+
b. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F` is now on the top of the stack.
547
545
548
546
c. Let :math:`\reff_{\F{t}}^\ast` be the concatenation of :math:`\reff_{ti}` in index order.
549
547
@@ -557,15 +555,9 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
557
555
558
556
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`.
559
557
560
-
11. Pop the frame :math:`F_{\F{init}}` from the stack.
561
-
562
-
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.
563
-
564
-
13. Let :math:`F` be the auxiliary :ref:`frame <syntax-frame>` :math:`\{ \AMODULE~\moduleinst, \ALOCALS~\epsilon \}`.
565
-
566
-
14. Push the frame :math:`F` to the stack.
558
+
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_{\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.
567
559
568
-
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:
560
+
12. 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:
569
561
570
562
a. Let :math:`n` be the length of the vector :math:`\elem_i.\EINIT`.
571
563
@@ -579,11 +571,11 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
579
571
580
572
f. :ref:`Execute <exec-elem.drop>` the instruction :math:`\ELEMDROP~i`.
581
573
582
-
16. For each :ref:`element segment <syntax-elem>` :math:`\elem_i` in :math:`\module.\MELEMS` whose :ref:`mode <syntax-elemmode>` is of the form :math:`\EDECLARATIVE`, do:
574
+
13. For each :ref:`element segment <syntax-elem>` :math:`\elem_i` in :math:`\module.\MELEMS` whose :ref:`mode <syntax-elemmode>` is of the form :math:`\EDECLARATIVE`, do:
583
575
584
576
a. :ref:`Execute <exec-elem.drop>` the instruction :math:`\ELEMDROP~i`.
585
577
586
-
17. 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:
578
+
14. 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:
587
579
588
580
a. Assert: :math:`\memidx_i` is :math:`0`.
589
581
@@ -599,15 +591,15 @@ It is up to the :ref:`embedder <embedder>` to define how such conditions are rep
599
591
600
592
g. :ref:`Execute <exec-data.drop>` the instruction :math:`\DATADROP~i`.
601
593
602
-
18. If the :ref:`start function <syntax-start>` :math:`\module.\MSTART` is not empty, then:
594
+
15. If the :ref:`start function <syntax-start>` :math:`\module.\MSTART` is not empty, then:
603
595
604
596
a. Let :math:`\start` be the :ref:`start function <syntax-start>` :math:`\module.\MSTART`.
605
597
606
598
b. :ref:`Execute <exec-call>` the instruction :math:`\CALL~\start.\SFUNC`.
607
599
608
-
19. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F` is now on the top of the stack.
600
+
16. Assert: due to :ref:`validation <valid-module>`, the frame :math:`F` is now on the top of the stack.
609
601
610
-
20. Pop the frame :math:`F` from the stack.
602
+
17. Pop the frame :math:`F` from the stack.
611
603
612
604
613
605
.. math::
@@ -658,7 +650,7 @@ where:
658
650
659
651
Similarly, module :ref:`allocation <alloc-module>` and the :ref:`evaluation <exec-expr>` of :ref:`global <syntax-global>` and :ref:`table <syntax-table>` initializers as well as :ref:`element segments <syntax-elem>` are mutually recursive because the global initialization :ref:`values <syntax-val>` :math:`\val_{\F{g}}^\ast`, :math:`\reff_{\F{t}}`, and element segment contents :math:`(\reff^\ast)^\ast` are passed to the module allocator while depending on the module instance :math:`\moduleinst` and store :math:`S'` returned by allocation.
660
652
Again, this recursion is just a specification device.
661
-
In practice, the initialization values can :ref:`be determined <exec-initvals>` beforehand by staging module allocation further such that first, the module's own :ref:`function instances <syntax-funcinst>` are pre-allocated in the store, then the initializer expressions are evaluated in order, allocating globals on the way, then the rest of the module instance is allocated, and finally the new function instances' :math:`\AMODULE` fields are set to that module instance.
653
+
In practice, the initialization values can :ref:`be determined <exec-initvals>` beforehand by staging module allocation such that first, the module's own :ref:`function instances <syntax-funcinst>` are pre-allocated in the store, then the initializer expressions are evaluated in order, allocating globals on the way, then the rest of the module instance is allocated, and finally the new function instances' :math:`\AMODULE` fields are set to that module instance.
662
654
This is possible because :ref:`validation <valid-module>` ensures that initialization expressions cannot actually call a function, only take their reference.
663
655
664
656
All failure conditions are checked before any observable mutation of the store takes place.
0 commit comments