Enhance OP_RESCUE to take B operand fas matching exception; ref #3487

parent 000c68da
...@@ -82,7 +82,8 @@ enum { ...@@ -82,7 +82,8 @@ enum {
OP_JMPIF,/* A sBx if R(A) pc+=sBx */ OP_JMPIF,/* A sBx if R(A) pc+=sBx */
OP_JMPNOT,/* A sBx if !R(A) pc+=sBx */ OP_JMPNOT,/* A sBx if !R(A) pc+=sBx */
OP_ONERR,/* sBx rescue_push(pc+sBx) */ OP_ONERR,/* sBx rescue_push(pc+sBx) */
OP_RESCUE,/* A B R(A) := exc; R(B) := matched (ignore if A/B=0) */ OP_RESCUE,/* A B C if A (if C exc=R(A) else R(A) := exc);
if B R(B) := exc.isa?(R(B)); clear(exc) */
OP_POPERR,/* A A.times{rescue_pop()} */ OP_POPERR,/* A A.times{rescue_pop()} */
OP_RAISE,/* A raise(R(A)) */ OP_RAISE,/* A raise(R(A)) */
OP_EPUSH,/* Bx ensure_push(SEQ[Bx]) */ OP_EPUSH,/* Bx ensure_push(SEQ[Bx]) */
......
...@@ -1294,7 +1294,7 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -1294,7 +1294,7 @@ codegen(codegen_scope *s, node *tree, int val)
node *n2 = tree->car; node *n2 = tree->car;
int exc = cursp(); int exc = cursp();
genop(s, MKOP_AB(OP_RESCUE, exc, 0)); genop(s, MKOP_ABC(OP_RESCUE, exc, 0, 0));
push(); push();
while (n2) { while (n2) {
node *n3 = n2->car; node *n3 = n2->car;
...@@ -1788,7 +1788,11 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -1788,7 +1788,11 @@ codegen(codegen_scope *s, node *tree, int val)
genop(s, MKOP_A(OP_POPERR, 1)); genop(s, MKOP_A(OP_POPERR, 1));
noexc = genop(s, MKOP_Bx(OP_JMP, 0)); noexc = genop(s, MKOP_Bx(OP_JMP, 0));
dispatch(s, onerr); dispatch(s, onerr);
<<<<<<< HEAD
genop(s, MKOP_AB(OP_RESCUE, exc, 0)); genop(s, MKOP_AB(OP_RESCUE, exc, 0));
=======
genop(s, MKOP_ABC(OP_RESCUE, exc, 0, 0));
>>>>>>> 55d89bd... Enhance OP_RESCUE to take B operand fas matching exception; ref #3487
genop(s, MKOP_A(OP_LOADF, exc)); genop(s, MKOP_A(OP_LOADF, exc));
dispatch(s, noexc); dispatch(s, noexc);
loop_pop(s, NOVAL); loop_pop(s, NOVAL);
......
...@@ -408,8 +408,22 @@ codedump(mrb_state *mrb, mrb_irep *irep) ...@@ -408,8 +408,22 @@ codedump(mrb_state *mrb, mrb_irep *irep)
printf("OP_ONERR\t%03d\n", i+GETARG_sBx(c)); printf("OP_ONERR\t%03d\n", i+GETARG_sBx(c));
break; break;
case OP_RESCUE: case OP_RESCUE:
printf("OP_RESCUE\tR%d\t\t", GETARG_A(c)); {
print_lv(mrb, irep, c, RA); int a = GETARG_A(c);
int b = GETARG_B(c);
int cnt = GETARG_C(c);
if (b == 0) {
printf("OP_RESCUE\tR%d\t\t%s", a, cnt ? "cont" : "");
print_lv(mrb, irep, c, RA);
break;
}
else {
printf("OP_RESCUE\tR%d\tR%d\t%s", a, b, cnt ? "cont" : "");
print_lv(mrb, irep, c, RAB);
break;
}
}
break; break;
case OP_RAISE: case OP_RAISE:
printf("OP_RAISE\tR%d\t\t", GETARG_A(c)); printf("OP_RAISE\tR%d\t\t", GETARG_A(c));
......
...@@ -1083,7 +1083,31 @@ RETRY_TRY_BLOCK: ...@@ -1083,7 +1083,31 @@ RETRY_TRY_BLOCK:
CASE(OP_RESCUE) { CASE(OP_RESCUE) {
/* A R(A) := exc; clear(exc) */ /* A R(A) := exc; clear(exc) */
SET_OBJ_VALUE(regs[GETARG_A(i)], mrb->exc); /* B R(B) := matched (bool) */
int b = GETARG_B(i);
mrb_value exc = mrb_obj_value(mrb->exc);
if (b != 0) {
mrb_value e = regs[b];
struct RClass *ec;
switch (mrb_type(e)) {
case MRB_TT_CLASS:
case MRB_TT_MODULE:
break;
default:
mrb_raise(mrb, E_TYPE_ERROR, "class or module required for rescue clause");
break;
}
ec = mrb_class_ptr(e);
if (mrb_obj_is_kind_of(mrb, exc, ec)) {
regs[b] = mrb_true_value();
}
else {
regs[b] = mrb_false_value();
}
}
regs[GETARG_A(i)] = exc;
mrb->exc = 0; mrb->exc = 0;
NEXT; NEXT;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment