Remove unnecessary `OP_JMPNOT` for `unless` statement.
MODIFY
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
@@ -1578,8 +1578,8 @@ codegen(codegen_scope *s, node *tree, int val)
}
codegen(s, tree->car, VAL);
pop();
+ if (tree->cdr->car) {
pos1 = genjmp2(s, OP_JMPNOT, cursp(), 0, val);
-
codegen(s, tree->cdr->car, val);
if (elsepart) {
if (val) pop();
@@ -1588,8 +1588,7 @@ codegen(codegen_scope *s, node *tree, int val)
codegen(s, elsepart, val);
dispatch(s, pos2);
}
- else {
- if (val) {
+ else if (val) {
pop();
pos2 = genjmp(s, OP_JMP, 0);
dispatch(s, pos1);
@@ -1601,6 +1600,17 @@ codegen(codegen_scope *s, node *tree, int val)
dispatch(s, pos1);
}
}
+ else { /* empty then-part */
+ if (elsepart) {
+ pos1 = genjmp2(s, OP_JMPIF, cursp(), 0, val);
+ codegen(s, elsepart, val);
+ dispatch(s, pos1);
+ }
+ else if (val) {
+ genop_1(s, OP_LOADNIL, cursp());
+ push();
+ }
+ }
}
break;

Remove unnecessary `OP_JMPNOT` for `unless` statement.