mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -2744,6 +2744,10 @@ RETRY_TRY_BLOCK:
|
||||
a = 0;
|
||||
goto NORMAL_RETURN;
|
||||
}
|
||||
CASE(OP_RETNIL, Z) {
|
||||
a = 0;
|
||||
goto L_RETURN_NIL;
|
||||
}
|
||||
CASE(OP_RETURN, B) {
|
||||
mrb_int acc;
|
||||
mrb_value v;
|
||||
@@ -2751,6 +2755,10 @@ RETRY_TRY_BLOCK:
|
||||
|
||||
NORMAL_RETURN:
|
||||
v = regs[a];
|
||||
goto L_RETURN;
|
||||
L_RETURN_NIL:
|
||||
v = mrb_nil_value();
|
||||
L_RETURN:
|
||||
mrb_gc_protect(mrb, v);
|
||||
return_ci = ci;
|
||||
CHECKPOINT_RESTORE(RBREAK_TAG_BREAK) {
|
||||
|
||||
Reference in New Issue
Block a user