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

parent 863671c8
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment