mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
codegen.c: add short circuit constant folding for NODE_AND, NODE_OR.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user