Skip to content

Commit f57cdb8

Browse files
committed
add exception allocation
1 parent 4799452 commit f57cdb8

File tree

4 files changed

+73
-10
lines changed

4 files changed

+73
-10
lines changed

document/core/appendix/embedding.rst

+38
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,44 @@ Tags
576576
\end{array}
577577
578578
579+
.. _embed-tag-type:
580+
581+
:math:`\F{tag\_type}(\store, \tagaddr) : \tagtype`
582+
........................................................
583+
584+
1. Return :math:`S.\STAGS[a].\TAGITYPE`.
585+
586+
2. Post-condition: the returned :ref:`tag type <syntax-tagtype>` is :ref:`valid <valid-tagtype>`.
587+
588+
.. math::
589+
\begin{array}{lclll}
590+
\F{tag\_type}(S, a) &=& S.\STAGS[a].\TAGITYPE \\
591+
\end{array}
592+
593+
594+
.. index:: exception, exception address, store, exception instance, exception type
595+
.. _embed-exception:
596+
597+
Exceptions
598+
~~~~~~~~~~
599+
600+
.. _embed-exception-alloc:
601+
602+
:math:`\F{exception\_alloc}(\store, \tagaddr, \val) : (\store, \exnaddr)`
603+
............................................................................
604+
605+
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{exception\_alloc}(S, \X{gt}, v) &=& (S', \X{a}) && (\iff \allocglobal(S, \X{gt}, v) = S', \X{a}) \\
614+
\end{array}
615+
616+
579617
.. index:: global, global address, store, global instance, global type, value
580618
.. _embed-global:
581619

document/core/exec/instructions.rst

+7-9
Original file line numberDiff line numberDiff line change
@@ -2719,27 +2719,25 @@ Control Instructions
27192719

27202720
2. Assert: due to :ref:`validation <valid-throw>`, :math:`F.\AMODULE.\MITAGS[x]` exists.
27212721

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]`.
27232723

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.
27252725

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]`.
27272727

27282728
6. Let :math:`[t^n] \toF [{t'}^\ast]` be the :ref:`tag type <syntax-tagtype>` :math:`\X{ti}.\TAGITYPE`.
27292729

27302730
7. Assert: due to :ref:`validation <valid-throw>`, there are at least :math:`n` values on the top of the stack.
27312731

27322732
8. Pop the :math:`n` values :math:`\val^n` from the stack.
27332733

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`.
27352735

2736-
10. Let :math:`\X{ea}` be the length of :math:`S.\SEXNS`.
2736+
10. Let :math:`\X{exn}` be :math:`S.\SEXNS[ea]`
27372737

2738-
11. Append :math:`\X{exn}` to :math:`S.\SEXNS`.
2738+
11. Push the value :math:`\REFEXNADDR~\X{ea}` to the stack.
27392739

2740-
12. Push the value :math:`\REFEXNADDR~\X{ea}` to the stack.
2741-
2742-
13. Execute the instruction |THROWREF|.
2740+
12. Execute the instruction |THROWREF|.
27432741

27442742
.. math::
27452743
~\\[-1ex]

document/core/exec/modules.rst

+27-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ The following auxiliary typing rules specify this typing relation relative to a
190190
Allocation
191191
~~~~~~~~~~
192192

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.
194194

195195

196196
.. 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
338338
\end{array}
339339
340340
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`.
354+
355+
5. Return :math:`a`.
356+
357+
.. math::
358+
\begin{array}{rlll}
359+
\allocexn(S, \tagaddr, \val^ast) &=& S', \exnaddr \\[1ex]
360+
\mbox{where:} \hfill \\
361+
\exnaddr &=& |S.\SEXNS| \\
362+
\exninst &=& \{ \EITAG~\tagaddr, \GIVALUE~\val^\ast \} \\
363+
S' &=& S \compose \{\SEXNS~\exninst\} \\
364+
\end{array}
365+
366+
341367
.. index:: global, global instance, global address, global type, value type, mutability, value
342368
.. _alloc-global:
343369

document/core/util/macros.def

+1
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@
981981
.. |alloctable| mathdef:: \xref{exec/modules}{alloc-table}{\F{alloctable}}
982982
.. |allocmem| mathdef:: \xref{exec/modules}{alloc-mem}{\F{allocmem}}
983983
.. |alloctag| mathdef:: \xref{exec/modules}{alloc-tag}{\F{alloctag}}
984+
.. |allocexn| mathdef:: \xref{exec/modules}{alloc-exception}{\F{allocexn}}
984985
.. |allocglobal| mathdef:: \xref{exec/modules}{alloc-global}{\F{allocglobal}}
985986
.. |allocelem| mathdef:: \xref{exec/modules}{alloc-elem}{\F{allocelem}}
986987
.. |allocdata| mathdef:: \xref{exec/modules}{alloc-data}{\F{allocdata}}

0 commit comments

Comments
 (0)