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
Add exceptional return to func_invoke in embedding doc (#268)
Embedding:
* Adds an auxiliary syntactic class to represent exception throwing/propagation
* Allows `func_invoke` to propagate exceptions
* Adds `tag_type` and `exn_alloc` to the embedding interface
core/exec:
* Refactors exception allocation into `alloc-exception` in modules.rst to expose it to the embedder
1. Try :ref:`invoking <exec-invocation>` the function :math:`\funcaddr` in :math:`\store` with :ref:`values <syntax-val>` :math:`\val^\ast` as arguments:
300
311
301
312
a. If it succeeds with :ref:`values <syntax-val>` :math:`{\val'}^\ast` as results, then let :math:`\X{result}` be :math:`{\val'}^\ast`.
302
313
303
-
b. Else it has trapped, hence let :math:`\X{result}` be :math:`\ERROR`.
314
+
b. Else if the outcome is an exception with a thrown :ref:`exception <exec-throw_ref>` :math:`\REFEXNADDR~\exnaddr` as the result, then let :math:`\X{result}` be :math:`\ETHROW~\exnaddr`
315
+
316
+
c. Else it has trapped, hence let :math:`\X{result}` be :math:`\ERROR`.
304
317
305
318
2. Return the new store paired with :math:`\X{result}`.
306
319
307
320
.. math::
308
321
~ \\
309
322
\begin{array}{lclll}
310
323
\F{func\_invoke}(S, a, v^\ast) &=& (S', {v'}^\ast) && (\iff\invoke(S, a, v^\ast) \stepto^\ast S'; F; {v'}^\ast) \\
324
+
\F{func\_invoke}(S, a, v^\ast) &=& (S', \ETHROW~a') && (\iff\invoke(S, a, v^\ast) \stepto^\ast S'; F; \XT[(\REFEXNADDR~a')~\THROWREF] \\
311
325
\F{func\_invoke}(S, a, v^\ast) &=& (S', \ERROR) && (\iff\invoke(S, a, v^\ast) \stepto^\ast S'; F; \TRAP) \\
1. Pre-condition: :math:`\tagaddr` is an allocated :ref:`tag address <syntax-tagaddr>`.
606
+
607
+
2. Let :math:`\exnaddr` be the result of :ref:`allocating an exception <alloc-exception>` in :math:`\store` with :ref:`tag address <syntax-tagaddr>` :math:`\tagaddr` and initialization values :math:`\val^\ast`.
608
+
609
+
3. Return the new store paired with :math:`\exnaddr`.
610
+
611
+
.. math::
612
+
\begin{array}{lclll}
613
+
\F{exn\_alloc}(S, \tagaddr, \val^\ast) &=& (S', a) && (\iff\allocexn(S, \tagaddr, \val^\ast) = S', a) \\
Copy file name to clipboardExpand all lines: document/core/exec/instructions.rst
+7-9
Original file line number
Diff line number
Diff line change
@@ -2719,27 +2719,25 @@ Control Instructions
2719
2719
2720
2720
2. Assert: due to :ref:`validation <valid-throw>`, :math:`F.\AMODULE.\MITAGS[x]` exists.
2721
2721
2722
-
3. Let :math:`a` be the :ref:`tag address <syntax-tagaddr>` :math:`F.\AMODULE.\MITAGS[x]`.
2722
+
3. Let :math:`ta` be the :ref:`tag address <syntax-tagaddr>` :math:`F.\AMODULE.\MITAGS[x]`.
2723
2723
2724
-
4. Assert: due to :ref:`validation <valid-throw>`, :math:`S.\STAGS[a]` exists.
2724
+
4. Assert: due to :ref:`validation <valid-throw>`, :math:`S.\STAGS[ta]` exists.
2725
2725
2726
-
5. Let :math:`\X{ti}` be the :ref:`tag instance <syntax-taginst>` :math:`S.\STAGS[a]`.
2726
+
5. Let :math:`\X{ti}` be the :ref:`tag instance <syntax-taginst>` :math:`S.\STAGS[ta]`.
2727
2727
2728
2728
6. Let :math:`[t^n] \toF [{t'}^\ast]` be the :ref:`tag type <syntax-tagtype>` :math:`\X{ti}.\TAGITYPE`.
2729
2729
2730
2730
7. Assert: due to :ref:`validation <valid-throw>`, there are at least :math:`n` values on the top of the stack.
2731
2731
2732
2732
8. Pop the :math:`n` values :math:`\val^n` from the stack.
2733
2733
2734
-
9. Let :math:`\X{exn}` be the :ref:`exception instance<syntax-exninst>` :math:`\{ \EITAG~a, \EIFIELDS~\val^n \}`.
2734
+
9. Let :math:`\X{ea}` be the :ref:`exception address<syntax-exnaddr>` resulting from :ref:`allocating <alloc-exception>` an exception instance with tag address :math:`ta` and initializer values :math:`\val^n`.
2735
2735
2736
-
10. Let :math:`\X{ea}` be the length of :math:`S.\SEXNS`.
2736
+
10. Let :math:`\X{exn}` be :math:`S.\SEXNS[ea]`
2737
2737
2738
-
11. Append :math:`\X{exn}` to :math:`S.\SEXNS`.
2738
+
11. Push the value :math:`\REFEXNADDR~\X{ea}` to the stack.
2739
2739
2740
-
12. Push the value :math:`\REFEXNADDR~\X{ea}` to the stack.
Copy file name to clipboardExpand all lines: document/core/exec/modules.rst
+27-1
Original file line number
Diff line number
Diff line change
@@ -190,7 +190,7 @@ The following auxiliary typing rules specify this typing relation relative to a
190
190
Allocation
191
191
~~~~~~~~~~
192
192
193
-
New instances of :ref:`functions <syntax-funcinst>`, :ref:`tables <syntax-tableinst>`, :ref:`memories <syntax-meminst>`, :ref:`tags <syntax-taginst>`, and :ref:`globals <syntax-globalinst>` are *allocated* in a :ref:`store <syntax-store>` :math:`S`, as defined by the following auxiliary functions.
193
+
New instances of :ref:`functions <syntax-funcinst>`, :ref:`tables <syntax-tableinst>`, :ref:`memories <syntax-meminst>`, :ref:`tags <syntax-taginst>`, :ref:`exceptions <syntax-exninst>`, and :ref:`globals <syntax-globalinst>` are *allocated* in a :ref:`store <syntax-store>` :math:`S`, as defined by the following auxiliary functions.
194
194
195
195
196
196
.. index:: function, function instance, function address, module instance, function type
@@ -338,6 +338,32 @@ New instances of :ref:`functions <syntax-funcinst>`, :ref:`tables <syntax-tablei
338
338
\end{array}
339
339
340
340
341
+
.. index:: exception, exception instance, exception address, tag address
342
+
.. _alloc-exception:
343
+
344
+
:ref:`Exceptions <syntax-exninst>`
345
+
..................................
346
+
347
+
1. Let :math:`ta` be the :ref:`tag address <syntax-tagaddr>` associated with the exception to allocate and :math:`\EIFIELDS~\val^\ast` be the values to initialize the exception with.
348
+
349
+
2. Let :math:`a` be the first free :ref:`exception address <syntax-exnaddr>` in :math:`S`.
350
+
351
+
3. Let :math:`\exninst` be the :ref:`exception instance <syntax-exninst>` :math:`\{ \EITAG~ta, \EIFIELDS~\val^\ast \}`.
352
+
353
+
4. Append :math:`\exninst` to the |SEXNS| of :math:`S`.
0 commit comments