diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-09-10 15:39:24 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-09-10 15:39:24 +0900 |
| commit | cd0ffd6f1ca413f36b6239de7779ae7778e1a200 (patch) | |
| tree | d58a27df03346bb775b4205a02995b4dc7aa16db /mrbgems/mruby-compiler/core/codegen.c | |
| parent | 69da192eec81edd15f2766e64c08dcc6a19ff0fd (diff) | |
| download | mruby-cd0ffd6f1ca413f36b6239de7779ae7778e1a200.tar.gz mruby-cd0ffd6f1ca413f36b6239de7779ae7778e1a200.zip | |
codegen.c: fixed `gen_setxv` bug with taking assignment value; fix #5550
Diffstat (limited to 'mrbgems/mruby-compiler/core/codegen.c')
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index d40d1b8a2..d47661d65 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -1084,13 +1084,15 @@ new_sym(codegen_scope *s, mrb_sym sym) } static void -gen_setxv(codegen_scope *s, uint8_t op, uint16_t dst, mrb_sym sym) +gen_setxv(codegen_scope *s, uint8_t op, uint16_t dst, mrb_sym sym, int val) { int idx = new_sym(s, sym); - struct mrb_insn_data data = mrb_last_insn(s); - if (!no_peephole(s) && data.insn == OP_MOVE && data.a == dst) { - dst = data.b; - rewind_pc(s); + if (!val) { + struct mrb_insn_data data = mrb_last_insn(s); + if (!no_peephole(s) && data.insn == OP_MOVE && data.a == dst) { + dst = data.b; + rewind_pc(s); + } } genop_2(s, op, dst, idx); } @@ -1639,7 +1641,7 @@ gen_assignment(codegen_scope *s, node *tree, int sp, int val) tree = tree->cdr; switch (type) { case NODE_GVAR: - gen_setxv(s, OP_SETGV, sp, nsym(tree)); + gen_setxv(s, OP_SETGV, sp, nsym(tree), val); break; case NODE_ARG: case NODE_LVAR: @@ -1659,13 +1661,13 @@ gen_assignment(codegen_scope *s, node *tree, int sp, int val) codegen_error(s, "Can't assign to numbered parameter"); break; case NODE_IVAR: - gen_setxv(s, OP_SETIV, sp, nsym(tree)); + gen_setxv(s, OP_SETIV, sp, nsym(tree), val); break; case NODE_CVAR: - gen_setxv(s, OP_SETCV, sp, nsym(tree)); + gen_setxv(s, OP_SETCV, sp, nsym(tree), val); break; case NODE_CONST: - gen_setxv(s, OP_SETCONST, sp, nsym(tree)); + gen_setxv(s, OP_SETCONST, sp, nsym(tree), val); break; case NODE_COLON2: gen_move(s, cursp(), sp, 0); |
