diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-07-29 17:38:18 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-07-29 17:38:18 +0900 |
| commit | 517071e3faa4aff498da58b3aa22081229af84e2 (patch) | |
| tree | 62d0b61ee7030f548a6bbbf1e3352fd56cbbedf4 | |
| parent | 5cde5983d98fbfe9d2dcc7a45a0da6fa8011aded (diff) | |
| download | mruby-517071e3faa4aff498da58b3aa22081229af84e2.tar.gz mruby-517071e3faa4aff498da58b3aa22081229af84e2.zip | |
codegen.c: order instructions in natural order for loops.
`while` and `until` generates in `cond` `jmpif` `body` `jmp` order.
It used to be in `jmp` `body` `cond` `jmpif` order.
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index d84a3f42c..51f71ba70 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -1938,14 +1938,13 @@ codegen(codegen_scope *s, node *tree, int val) if (!val) lp->acc = -1; lp->pc0 = new_label(s); - pos = genjmp_0(s, OP_JMP); + codegen(s, tree->car, VAL); + pop(); + pos = genjmp2_0(s, OP_JMPNOT, cursp(), NOVAL); lp->pc1 = new_label(s); codegen(s, tree->cdr, NOVAL); + genjmp(s, OP_JMP, lp->pc0); dispatch(s, pos); - codegen(s, tree->car, VAL); - pop(); - genjmp2(s, OP_JMPIF, cursp(), lp->pc1, NOVAL); - loop_pop(s, val); } break; @@ -1957,14 +1956,13 @@ codegen(codegen_scope *s, node *tree, int val) if (!val) lp->acc = -1; lp->pc0 = new_label(s); - pos = genjmp_0(s, OP_JMP); + codegen(s, tree->car, VAL); + pop(); + pos = genjmp2_0(s, OP_JMPIF, cursp(), NOVAL); lp->pc1 = new_label(s); codegen(s, tree->cdr, NOVAL); + genjmp(s, OP_JMP, lp->pc0); dispatch(s, pos); - codegen(s, tree->car, VAL); - pop(); - genjmp2(s, OP_JMPNOT, cursp(), lp->pc1, NOVAL); - loop_pop(s, val); } break; |
