Skip to content

Commit

Permalink
[spec] Update algorithm (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg committed Jan 25, 2024
1 parent 84663dc commit 7a97c6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
34 changes: 19 additions & 15 deletions document/core/appendix/algorithm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Types are representable as an enumeration.

.. code-block:: pseudo
type val_type = I32 | I64 | F32 | F64 | V128 | Funcref | Externref
type val_type = I32 | I64 | F32 | F64 | V128 | Funcref | Exnref | Externref
func is_num(t : val_type | Unknown) : bool =
return t = I32 || t = I64 || t = F32 || t = F64 || t = Unknown
Expand All @@ -34,7 +34,7 @@ Types are representable as an enumeration.
return t = V128 || t = Unknown
func is_ref(t : val_type | Unknown) : bool =
return t = Funcref || t = Externref || t = Unknown
return t = Funcref || t = Exnref || t = Externref || t = Unknown
The algorithm uses two separate stacks: the *value stack* and the *control stack*.
The former tracks the :ref:`types <syntax-valtype>` of operand values on the :ref:`stack <stack>`,
Expand Down Expand Up @@ -212,22 +212,26 @@ Other instructions are checked in a similar manner.
error_if(frame.opcode =/= if)
push_ctrl(else, frame.start_types, frame.end_types)
case (try t1*->t2*)
case (try_table t1*->t2* handler*)
pop_vals([t1*])
push_ctrl(try, [t1*], [t2*])
case (catch x)
let frame = pop_ctrl()
error_if(frame.opcode =/= try || frame.opcode =/= catch)
push_ctrl(catch, tags[x].type.params, frame.end_types)
case (catch_all)
let frame = pop_ctrl()
error_if(frame.opcode =/= try || frame.opcode =/= catch)
push_ctrl(catch_all, [], frame.end_types)
foreach (handler in handler*)
error_if(ctrls.size() < handler.label)
push_ctrl(catch, [], label_types(ctrls[handler.label]))
switch (handler.clause)
case (catch x)
push_vals(tags[x].type.params)
case (catch_ref x)
push_vals(tags[x].type.params)
push_val(Exnref)
case (catch_all)
skip
case (catch_all_ref)
push_val(Exnref)
pop_ctrl()
push_ctrl(try_table, [t1*], [t2*])
case (throw x)
pop.vals(tags[x].type.params)
pop_vals(tags[x].type.params)
unreachable()
case (br n)
Expand Down
6 changes: 2 additions & 4 deletions document/core/syntax/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,9 @@ The |DATADROP| instruction prevents further use of a passive data segment. This
.. _syntax-block:
.. _syntax-loop:
.. _syntax-if:
.. _syntax-try:
.. _syntax-try-catch:
.. _syntax-try-delegate:
.. _syntax-try_table:
.. _syntax-throw:
.. _syntax-rethrow:
.. _syntax-throw_ref:
.. _syntax-br:
.. _syntax-br_if:
.. _syntax-br_table:
Expand Down

0 comments on commit 7a97c6b

Please sign in to comment.