codegen.c: add short circuit constant folding for NODE_AND, NODE_OR.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-09-24 11:38:02 +09:00
parent 863671c89f
commit 7c6c4ebb56
+16
View File
@@ -2224,6 +2224,14 @@ codegen(codegen_scope *s, node *tree, int val)
{
uint32_t pos;
if (true_always(tree->car)) {
codegen(s, tree->cdr, val);
goto exit;
}
if (false_always(tree->car)) {
codegen(s, tree->car, val);
goto exit;
}
codegen(s, tree->car, VAL);
pop();
pos = genjmp2_0(s, OP_JMPNOT, cursp(), val);
@@ -2236,6 +2244,14 @@ codegen(codegen_scope *s, node *tree, int val)
{
uint32_t pos;
if (true_always(tree->car)) {
codegen(s, tree->car, val);
goto exit;
}
if (false_always(tree->car)) {
codegen(s, tree->cdr, val);
goto exit;
}
codegen(s, tree->car, VAL);
pop();
pos = genjmp2_0(s, OP_JMPIF, cursp(), val);