From d9a8981c26829aae0908244c3728f17e06a88ee2 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 3 Jul 2021 06:40:05 +0900 Subject: 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. --- doc/opcode.md | 2 +- include/mruby/ops.h | 2 +- mrbgems/mruby-compiler/core/codegen.c | 10 ++-------- src/vm.c | 1 + 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/doc/opcode.md b/doc/opcode.md index 21dc2ef9d..3cc95af92 100644 --- a/doc/opcode.md +++ b/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` | diff --git a/include/mruby/ops.h b/include/mruby/ops.h index 8d62f007f..3388d171e 100644 --- a/include/mruby/ops.h +++ b/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 */ diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 62ed4e77d..5ab2f6180 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/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; diff --git a/src/vm.c b/src/vm.c index 3a7d2ac8f..cd70faf11 100644 --- a/src/vm.c +++ b/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; } -- cgit v1.2.3