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:
@@ -74,6 +74,7 @@ OPCODE(KARG, BB) /* R[a] = kdict[Syms[b]]; kdict.delete(Syms[b]) */
|
||||
OPCODE(RETURN, B) /* return R[a] (normal) */
|
||||
OPCODE(RETURN_BLK, B) /* return R[a] (in-block return) */
|
||||
OPCODE(RETSELF, Z) /* return self */
|
||||
OPCODE(RETNIL, Z) /* return nil */
|
||||
OPCODE(BREAK, B) /* break R[a] */
|
||||
OPCODE(BLKPUSH, BS) /* R[a] = block (16=m5:r1:m5:d1:lv4) */
|
||||
OPCODE(ADD, B) /* R[a] = R[a]+R[a+1] */
|
||||
|
||||
Reference in New Issue
Block a user