summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-03-11 16:32:29 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-03-12 00:50:38 +0900
commit26169f9e25788caf2781a92087f489e5e5fdc0c9 (patch)
tree08fd028dc6857486eb470a057269d77b5fcd9356 /src
parent000c68da97ec0bfbd93e3969a2eef21081569a72 (diff)
downloadmruby-26169f9e25788caf2781a92087f489e5e5fdc0c9.tar.gz
mruby-26169f9e25788caf2781a92087f489e5e5fdc0c9.zip
Enhance OP_RESCUE to take B operand fas matching exception; ref #3487
Diffstat (limited to 'src')
-rw-r--r--src/codedump.c18
-rw-r--r--src/vm.c26
2 files changed, 41 insertions, 3 deletions
diff --git a/src/codedump.c b/src/codedump.c
index 59ba4fdae..c20afdd00 100644
--- a/src/codedump.c
+++ b/src/codedump.c
@@ -408,8 +408,22 @@ codedump(mrb_state *mrb, mrb_irep *irep)
printf("OP_ONERR\t%03d\n", i+GETARG_sBx(c));
break;
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;
case OP_RAISE:
printf("OP_RAISE\tR%d\t\t", GETARG_A(c));
diff --git a/src/vm.c b/src/vm.c
index b0a8fab40..4a08948aa 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -1083,7 +1083,31 @@ RETRY_TRY_BLOCK:
CASE(OP_RESCUE) {
/* 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;
NEXT;
}