diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-09-24 11:39:00 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-09-24 11:39:00 +0900 |
| commit | ab54ca272a65a5612508c9f49555e591c0ab0278 (patch) | |
| tree | 8e57817e1b04551063ee2301769b2eb6b9a5cebd | |
| parent | 7c6c4ebb56a17c291806c7961f6ca2abc7da4546 (diff) | |
| download | mruby-ab54ca272a65a5612508c9f49555e591c0ab0278.tar.gz mruby-ab54ca272a65a5612508c9f49555e591c0ab0278.zip | |
codegen.c: refactor `NODE_WHILE` and `NODE_UNTIL`.
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 24d23c1be..c04c408ed 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -2268,10 +2268,7 @@ codegen(codegen_scope *s, node *tree, int val) if (!val) lp->reg = -1; lp->pc0 = new_label(s); - switch (nint(tree->car->car)) { - case NODE_TRUE: - case NODE_INT: - case NODE_STR: + if (true_always(tree->car)) { if (nt == NODE_UNTIL) { if (val) { genop_1(s, OP_LOADNIL, cursp()); @@ -2279,9 +2276,8 @@ codegen(codegen_scope *s, node *tree, int val) } goto exit; } - break; - case NODE_FALSE: - case NODE_NIL: + } + else if (false_always(tree->car)) { if (nt == NODE_WHILE) { if (val) { genop_1(s, OP_LOADNIL, cursp()); @@ -2289,17 +2285,14 @@ codegen(codegen_scope *s, node *tree, int val) } goto exit; } - break; - default: - codegen(s, tree->car, VAL); - pop(); - if (nt == NODE_WHILE) { - pos = genjmp2_0(s, OP_JMPNOT, cursp(), NOVAL); - } - else { - pos = genjmp2_0(s, OP_JMPIF, cursp(), NOVAL); - } - break; + } + codegen(s, tree->car, VAL); + pop(); + if (nt == NODE_WHILE) { + pos = genjmp2_0(s, OP_JMPNOT, cursp(), NOVAL); + } + else { + pos = genjmp2_0(s, OP_JMPIF, cursp(), NOVAL); } lp->pc1 = new_label(s); codegen(s, tree->cdr, NOVAL); |
