vm: add OP_TDEF/OP_SDEF for fused method definition

TDEF fuses TCLASS+METHOD+DEF for normal method definitions.
SDEF fuses SCLASS+METHOD+DEF for singleton method definitions.
Saves 4 bytes per method definition (8 bytes -> 4 bytes).
Falls back to unfused instructions if irep index exceeds 255.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-01-20 13:02:06 +09:00
parent 51e8da6614
commit 48a88ed79b
4 changed files with 68 additions and 12 deletions
+2
View File
@@ -113,6 +113,8 @@ OPCODE(CLASS, BB) /* R[a] = newclass(R[a],Syms[b],R[a+1]) */
OPCODE(MODULE, BB) /* R[a] = newmodule(R[a],Syms[b]) */
OPCODE(EXEC, BB) /* R[a] = blockexec(R[a],Irep[b]) */
OPCODE(DEF, BB) /* R[a].newmethod(Syms[b],R[a+1]); R[a] = Syms[b] */
OPCODE(TDEF, BBB) /* target_class.newmethod(Syms[b],Irep[c]); R[a] = Syms[b] */
OPCODE(SDEF, BBB) /* R[a].singleton_class.newmethod(Syms[b],Irep[c]); R[a] = Syms[b] */
OPCODE(ALIAS, BB) /* alias_method(target_class,Syms[a],Syms[b]) */
OPCODE(UNDEF, B) /* undef_method(target_class,Syms[a]) */
OPCODE(SCLASS, B) /* R[a] = R[a].singleton_class */