vm: add OP_MATCHERR instruction for pattern matching errors

Replace 4-instruction sequence (GETCONST + STRING + SEND + RAISEIF)
with single OP_MATCHERR instruction that raises NoMatchingPatternError
with "pattern not matched" message.

Bump RITE binary format version from 0300 to 0400 due to opcode
number shift.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-01-19 12:52:06 +09:00
parent 8c99e3dd29
commit 2fa99a73c2
5 changed files with 11 additions and 16 deletions
+3
View File
@@ -572,6 +572,9 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out)
fprintf(out, "RAISEIF\tR%d\t", a);
print_lv_a(mrb, irep, a, out);
break;
CASE(OP_MATCHERR, Z):
fprintf(out, "MATCHERR\n");
break;
CASE(OP_DEBUG, BBB):
fprintf(out, "DEBUG\t\t%d\t%d\t%d\n", a, b, c);
+4
View File
@@ -2167,6 +2167,10 @@ RETRY_TRY_BLOCK:
NEXT;
}
CASE(OP_MATCHERR, Z) {
RAISE_LIT(mrb, mrb_exc_get_id(mrb, MRB_ERROR_SYM(NoMatchingPatternError)), "pattern not matched");
}
CASE(OP_SSEND, BBB) {
regs[a] = regs[0];
}