Skip to content

Commit

Permalink
Update VM to support new OP_RESCUE behavior; ref #3487
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Mar 11, 2017
1 parent 26169f9 commit 92f5bec
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,15 +1082,22 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
}

CASE(OP_RESCUE) {
/* A R(A) := exc; clear(exc) */
/* B R(B) := matched (bool) */
/* A B R(A) := exc; clear(exc); R(B) := matched (bool) */
int a = GETARG_A(i);
int b = GETARG_B(i);
mrb_value exc = mrb_obj_value(mrb->exc);
int c = GETARG_C(i);
mrb_value exc;

if (b != 0) {
mrb_value e = regs[b];
struct RClass *ec;

if (c == 0) {
exc = mrb_obj_value(mrb->exc);
}
else { /* continued; exc taken from R(A) */
exc = regs[a];
}
switch (mrb_type(e)) {
case MRB_TT_CLASS:
case MRB_TT_MODULE:
Expand All @@ -1107,7 +1114,12 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
regs[b] = mrb_false_value();
}
}
regs[GETARG_A(i)] = exc;
else if (c == 0) {
exc = mrb_obj_value(mrb->exc);
}
if (a != 0 && c == 0) {
regs[GETARG_A(i)] = exc;
}
mrb->exc = 0;
NEXT;
}
Expand Down

0 comments on commit 92f5bec

Please sign in to comment.