vm: add OP_RETNIL for returning nil directly

Add a new opcode that returns nil without requiring LOADNIL + RETURN.
This avoids loading nil into a register by setting the return value (v)
directly. The implementation uses a separate label (L_RETURN_NIL) to
bypass v = regs[a], preserving self in regs[0] for ensure blocks.

Codegen applies peephole optimization to fuse LOADNIL + RETURN -> RETNIL.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-01-23 00:33:25 +09:00
parent a6bf08847a
commit 0b1af858e2
5 changed files with 19 additions and 1 deletions
+3
View File
@@ -399,6 +399,9 @@ codedump(mrb_state *mrb, const mrb_irep *irep, FILE *out)
CASE(OP_RETSELF, Z):
fprintf(out, "RETSELF\n");
break;
CASE(OP_RETNIL, Z):
fprintf(out, "RETNIL\n");
break;
CASE(OP_BREAK, B):
fprintf(out, "BREAK\t\tR%d\t", a);
print_lv_a(mrb, irep, a, out);