Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spec] Update algorithm #290

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 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
rossberg marked this conversation as resolved.
Show resolved Hide resolved

func is_num(t : val_type | Unknown) : bool =
return t = I32 || t = I64 || t = F32 || t = F64 || t = Unknown
Expand Down Expand Up @@ -212,22 +212,28 @@ 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*])
let rest = pop_vals()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If pop_vals is called without a types parameter, does this mean it pops everything in there? (Is it documented somewhere?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, that was missing. I managed to change the algorithm to not require this function and be simpler at the same time.

foreach (handler in handler*)
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)
error_if(ctrls.size() < handler.label)
pop_vals(label_types(ctrls[handler.label]))
error_if(not vals.is_empty())
push_vals(rest)
push_ctrl(try, [t1*], [t2*])
rossberg marked this conversation as resolved.
Show resolved Hide resolved

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)

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
Loading