vm.c: OP_DEF to push a symbol to a register.

The code generator no longer need to emit `OP_LOADSYM` after `OP_DEF`.
`doc/opcode.md` is also updated.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-07-03 06:40:05 +09:00
parent a624da6fdb
commit d9a8981c26
4 changed files with 5 additions and 10 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ sign) of operands.
| `OP_CLASS` | `BB` | `R(a) = newclass(R(a),Syms(b),R(a+1))` |
| `OP_MODULE` | `BB` | `R(a) = newmodule(R(a),Syms(b))` |
| `OP_EXEC` | `BB` | `R(a) = blockexec(R(a),SEQ[b])` |
| `OP_DEF` | `BB` | `R(a).newmethod(Syms(b),R(a+1))` |
| `OP_DEF` | `BB` | `R(a).newmethod(Syms(b),R(a+1)); R(a) = Syms(b)` |
| `OP_ALIAS` | `BB` | `alias_method(target_class,Syms(a),Syms(b))` |
| `OP_UNDEF` | `B` | `undef_method(target_class,Syms(a))` |
| `OP_SCLASS` | `B` | `R(a) = R(a).singleton_class` |
+1 -1
View File
@@ -105,7 +105,7 @@ OPCODE(OCLASS, B) /* R(a) = ::Object */
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),SEQ[b]) */
OPCODE(DEF, BB) /* R(a).newmethod(Syms(b),R(a+1)) */
OPCODE(DEF, BB) /* R(a).newmethod(Syms(b),R(a+1)); 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 */
+2 -8
View File
@@ -3049,10 +3049,7 @@ codegen(codegen_scope *s, node *tree, int val)
push(); pop();
pop();
genop_2(s, OP_DEF, cursp(), sym);
if (val) {
genop_2(s, OP_LOADSYM, cursp(), sym);
push();
}
if (val) push();
}
break;
@@ -3069,10 +3066,7 @@ codegen(codegen_scope *s, node *tree, int val)
genop_2(s, OP_METHOD, cursp(), idx);
pop();
genop_2(s, OP_DEF, cursp(), sym);
if (val) {
genop_2(s, OP_LOADSYM, cursp(), sym);
push();
}
if (val) push();
}
break;
+1
View File
@@ -2823,6 +2823,7 @@ RETRY_TRY_BLOCK:
mrb_define_method_raw(mrb, target, mid, m);
mrb_method_added(mrb, target, mid);
mrb_gc_arena_restore(mrb, ai);
regs[a] = mrb_symbol_value(mid);
NEXT;
}