Change try ... catch
+ br_on_exn
to br_on_catch{,_else}
? #80
Description
Edit: Redid a couple things.
After reading #58 and that eventually getting merged in #71, I feel you could remove try ... catch ... end
altogether and simplify the branching generation a lot by just unifying try ... catch
and br_on_exn
with a generic br_on_catch len ($lbl $id)+
and br_on_catch_else len ($lbl $id)* $default_lbl
that operate more like a br_table
for exceptions. The label of the corresponding block for $default_lbl
must be a (result except_ref)
, but the rest just need to match the corresponding exception. And except_ref
can only be plugged into a rethrow
, manipulated as an opaque parameter, local, or result, or dropped.
The br_on_catch
is sugar for br_on_catch_else
, just with the default branch always rethrowing. (This is very commonly the case, so I felt it was worth including.)
This would make the corresponding grammar look like this:
br_on_catch len (label except_index)+ |
br_on_catch_else len (label except_index)* label |
throw except_index |
rethrow
And of course, this makes the code a lot smaller with no loss in power. (You can always organize your blocks to have shared logic as appropriate - it's roughly the same amount of code, and you'd likely need to do it anyways in the case of C++ exception handling.)