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.
[proposal](https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md) for
8
8
adding exception handling to WebAssembly.
9
9
10
-
The exception handling proposal depends on the [reference-types](https://github.com/WebAssembly/reference-types) proposal
11
-
and on the [multi-value](https://github.com/WebAssembly/multi-value) proposal.
10
+
* See the [proposal overview](proposals/Exceptions.md) for a summary of the proposal.
12
11
13
-
The repository is a clone
14
-
of [WebAssembly/spec](https://github.com/WebAssembly/spec), first rebased on the spec of its dependency [reference-types](https://github.com/WebAssembly/reference-types), and then merged with the other dependency [multi-value](https://github.com/WebAssembly/multi-value).
12
+
The repository is now based on the [reference types proposal](proposals/reference-types/Overview.md) and includes all respective changes.
15
13
16
-
The remainder of the document has contents of the two README files of the dependencies: [reference-types/README.md](https://github.com/WebAssembly/reference-types/blob/master/README.md) and [multi-value/README.md](https://github.com/WebAssembly/multi-value/blob/master/README.md).
This repository is a clone of [github.com/WebAssembly/spec/](https://github.com/WebAssembly/spec/).
23
-
It is meant for discussion, prototype specification and implementation of a proposal to add support for basic reference types to WebAssembly.
24
-
25
-
* See the [overview](https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md) for a summary of the proposal.
26
-
27
-
* See the [modified spec](https://webassembly.github.io/reference-types/) for details.
This repository is a clone of [github.com/WebAssembly/spec/](https://github.com/WebAssembly/spec/).
34
-
It is meant for discussion, prototype specification and implementation of a proposal to add support for returning multiple values to WebAssembly.
35
-
36
-
* See the [overview](https://github.com/WebAssembly/multi-value/blob/master/proposals/multi-value/Overview.md) for a summary of the proposal.
37
-
38
-
* See the [modified spec](https://webassembly.github.io/multi-value/) for details.
39
-
40
-
Original `README` from upstream repository follows...
14
+
Original README from upstream repository follows...
The algorithm uses two separate stacks: the *value stack* and the *control stack*.
42
37
The former tracks the :ref:`types <syntax-valtype>` of operand values on the :ref:`stack <stack>`,
43
38
the latter surrounding :ref:`structured control instructions <syntax-instr-control>` and their associated :ref:`blocks <syntax-instr-control>`.
44
39
45
40
.. code-block:: pseudo
46
41
47
-
type val_stack = stack(val_type)
42
+
type val_stack = stack(val_type | Unknown)
48
43
49
44
type ctrl_stack = stack(ctrl_frame)
50
45
type ctrl_frame = {
51
-
label_types : list(val_type)
46
+
opcode : opcode
47
+
start_types : list(val_type)
52
48
end_types : list(val_type)
53
49
height : nat
54
50
unreachable : bool
55
51
}
56
52
57
-
For each value, the value stack records its :ref:`value type <syntax-valtype>`.
53
+
For each value, the value stack records its :ref:`value type <syntax-valtype>`, or :code:`Unknown` when the type is not known.
58
54
59
-
For each entered block, the control stack records a *control frame* with the type of the associated :ref:`label <syntax-label>` (used to type-check branches), the result type of the block (used to check its result), the height of the operand stack at the start of the block (used to check that operands do not underflow the current block), and a flag recording whether the remainder of the block is unreachable (used to handle :ref:`stack-polymorphic <polymorphism>` typing after branches).
60
55
61
-
.. note::
62
-
In the presentation of this algorithm, multiple values are supported for the :ref:`result types <syntax-resulttype>` classifying blocks and labels.
63
-
With the current version of WebAssembly, the :code:`list` could be simplified to an optional value.
56
+
For each entered block, the control stack records a *control frame* with the originating opcode, the types on the top of the operand stack at the start and end of the block (used to check its result as well as branches), the height of the operand stack at the start of the block (used to check that operands do not underflow the current block), and a flag recording whether the remainder of the block is unreachable (used to handle :ref:`stack-polymorphic <polymorphism>` typing after branches).
64
57
65
58
For the purpose of presenting the algorithm, the operand and control stacks are simply maintained as global variables:
66
59
@@ -73,17 +66,19 @@ However, these variables are not manipulated directly by the main checking funct
73
66
74
67
.. code-block:: pseudo
75
68
76
-
func push_val(type : val_type) =
69
+
func push_val(type : val_type | Unknown) =
77
70
vals.push(type)
78
71
79
-
func pop_val() : val_type =
80
-
if (vals.size() = ctrls[0].height && ctrls[0].unreachable) return Bot
72
+
func pop_val() : val_type | Unknown =
73
+
if (vals.size() = ctrls[0].height && ctrls[0].unreachable) return Unknown
return (if frame.opcode == loop then frame.start_types else frame.end_types)
128
127
129
128
func unreachable() =
130
129
vals.resize(ctrls[0].height)
@@ -137,13 +136,15 @@ Popping a frame first checks that the control stack is not empty.
137
136
It then verifies that the operand stack contains the right types of values expected at the end of the exited block and pops them off the operand stack.
138
137
Afterwards, it checks that the stack has shrunk back to its initial height.
139
138
139
+
The type of the :ref:`label <syntax-label>` associated with a control frame is either that of the stack at the start or the end of the frame, determined by the opcode that it originates from.
140
+
140
141
Finally, the current frame can be marked as unreachable.
141
142
In that case, all existing operand types are purged from the value stack, in order to allow for the :ref:`stack-polymorphism <polymorphism>` logic in :code:`pop_val` to take effect.
142
143
143
144
.. note::
144
145
Even with the unreachable flag set, consecutive operands are still pushed to and popped from the operand stack.
145
146
That is necessary to detect invalid :ref:`examples <polymorphism>` like :math:`(\UNREACHABLE~(\I32.\CONST)~\I64.\ADD)`.
146
-
However, a polymorphic stack cannot underflow, but instead generates :code:`Bot` types as needed.
147
+
However, a polymorphic stack cannot underflow, but instead generates :code:`Unknown` types as needed.
147
148
148
149
149
150
.. index:: opcode
@@ -175,8 +176,8 @@ Other instructions are checked in a similar manner.
0 commit comments