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.
MODIFY
doc/opcode.md
doc/opcode.md
@@ -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` |

MODIFY
include/mruby/ops.h
include/mruby/ops.h
@@ -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 */

MODIFY
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
@@ -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;

MODIFY
src/vm.c
src/vm.c
@@ -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;
}

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.