Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2710/stdlib/nice/lang/inline
Modified Files:
ShortCircuitOp.java
Log Message:
Moved optimizations to nice.lang.inline.ShortCircuitOp so that all code
benefits from them and higher-level code-generation code can be kept simple.
Index: ShortCircuitOp.java
===================================================================
RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/inline/ShortCircuitOp.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ShortCircuitOp.java 21 Mar 2003 23:32:35 -0000 1.3
--- ShortCircuitOp.java 2 Feb 2004 12:00:46 -0000 1.4
***************
*** 50,53 ****
--- 50,69 ----
{
Expression[] args = exp.getArgs();
+
+ // Optimize some trivial cases
+ if (kind == And)
+ {
+ if (args[0] == QuoteExp.trueExp)
+ {
+ args[1].compile(comp, target);
+ return;
+ }
+ if (args[1] == QuoteExp.trueExp)
+ {
+ args[0].compile(comp, target);
+ return;
+ }
+ }
+
CodeAttr code = comp.getCode();
Target stack = new StackTarget(Type.boolean_type);
***************
*** 96,99 ****
--- 112,118 ----
}
+ /**
+ Jump to label if the expression yields true.
+ */
public void compileJump (Compilation comp, Expression[] args, Label to)
{
***************
*** 134,137 ****
--- 153,159 ----
}
+ /**
+ Jump to label if the expression yields false.
+ */
public void compileJumpNot (Compilation comp, Expression[] args, Label to)
{
***************
*** 151,154 ****
--- 173,180 ----
branchOp.compileJump(comp, brArgs, _end);
}
+ else if (kind == And && args[0] == QuoteExp.trueExp)
+ {
+ // Optim: do nothing, this argument cannot make the expression false.
+ }
else
{
***************
*** 164,167 ****
--- 190,197 ----
branchOp2.compileJumpNot(comp, brArgs, to);
}
+ else if (kind == And && args[1] == QuoteExp.trueExp)
+ {
+ // Optim: do nothing, this argument cannot make the expression false.
+ }
else
{
|