mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
vm: add OP_SEND0 and OP_SSEND0 for zero-argument method calls
These opcodes use BB format instead of BBB, saving 1 byte per call. In the standard library, this saves ~790 bytes (568 SEND0 + 222 SSEND0). Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -336,6 +336,9 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out)
|
||||
fprintf(out, "SSEND\t\tR%d\t:%s\t", a, mrb_sym_dump(mrb, irep->syms[b]));
|
||||
print_args(c, out);
|
||||
break;
|
||||
CASE(OP_SSEND0, BB):
|
||||
fprintf(out, "SSEND0\tR%d\t:%s\n", a, mrb_sym_dump(mrb, irep->syms[b]));
|
||||
break;
|
||||
CASE(OP_SSENDB, BBB):
|
||||
fprintf(out, "SSENDB\tR%d\t:%s\t", a, mrb_sym_dump(mrb, irep->syms[b]));
|
||||
print_args(c, out);
|
||||
@@ -344,6 +347,9 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out)
|
||||
fprintf(out, "SEND\t\tR%d\t:%s\t", a, mrb_sym_dump(mrb, irep->syms[b]));
|
||||
print_args(c, out);
|
||||
break;
|
||||
CASE(OP_SEND0, BB):
|
||||
fprintf(out, "SEND0\t\tR%d\t:%s\n", a, mrb_sym_dump(mrb, irep->syms[b]));
|
||||
break;
|
||||
CASE(OP_SENDB, BBB):
|
||||
fprintf(out, "SENDB\t\tR%d\t:%s\t", a, mrb_sym_dump(mrb, irep->syms[b]));
|
||||
print_args(c, out);
|
||||
|
||||
@@ -2211,6 +2211,12 @@ RETRY_TRY_BLOCK:
|
||||
}
|
||||
goto L_SENDB;
|
||||
|
||||
CASE(OP_SSEND0, BB) {
|
||||
regs[a] = regs[0];
|
||||
c = 0;
|
||||
}
|
||||
goto L_SENDB;
|
||||
|
||||
CASE(OP_SSENDB, BBB) {
|
||||
regs[a] = regs[0];
|
||||
}
|
||||
@@ -2219,6 +2225,11 @@ RETRY_TRY_BLOCK:
|
||||
CASE(OP_SEND, BBB)
|
||||
goto L_SENDB;
|
||||
|
||||
CASE(OP_SEND0, BB) {
|
||||
c = 0;
|
||||
}
|
||||
goto L_SENDB;
|
||||
|
||||
L_SEND_SYM:
|
||||
c = 1;
|
||||
/* push nil after arguments */
|
||||
@@ -2259,7 +2270,7 @@ RETRY_TRY_BLOCK:
|
||||
}
|
||||
|
||||
mrb_assert(bidx < irep->nregs);
|
||||
if (insn == OP_SEND || insn == OP_SSEND) {
|
||||
if (insn == OP_SEND || insn == OP_SEND0 || insn == OP_SSEND || insn == OP_SSEND0) {
|
||||
/* clear block argument */
|
||||
SET_NIL_VALUE(regs[new_bidx]);
|
||||
SET_NIL_VALUE(blk);
|
||||
@@ -2280,7 +2291,7 @@ RETRY_TRY_BLOCK:
|
||||
else {
|
||||
ci->mid = mid;
|
||||
}
|
||||
if (insn == OP_SEND || insn == OP_SENDB) {
|
||||
if (insn == OP_SEND || insn == OP_SEND0 || insn == OP_SENDB) {
|
||||
mrb_bool priv = TRUE;
|
||||
if (m.flags & MRB_METHOD_PRIVATE_FL) {
|
||||
vis_err:;
|
||||
|
||||
Reference in New Issue
Block a user