folding for booleans now works

main
Simon Kellet 1 year ago
parent 69a24132d3
commit b6f5eaa3c8
  1. 44
      Triangle.Compiler/src/main/java/triangle/optimiser/ConstantFolder.java
  2. BIN
      booleanfold.tam
  3. BIN
      booleannotfold.tam
  4. BIN
      build/libs/Triangle-Tools.jar

@ -592,6 +592,41 @@ public class ConstantFolder implements ActualParameterVisitor<Void, AbstractSynt
if (o.decl == StdEnvironment.addDecl) { if (o.decl == StdEnvironment.addDecl) {
foldedValue = int1 + int2; foldedValue = int1 + int2;
} else if (o.decl == StdEnvironment.greaterDecl) {
foldedValue = int1 > int2;
} else if (o.decl == StdEnvironment.equalDecl) {
foldedValue = int1 == int2;
} else if (o.decl == StdEnvironment.lessDecl) {
foldedValue = int1 < int2;
} else if (o.decl == StdEnvironment.notgreaterDecl) {
foldedValue = int1 <= int2;
} else if (o.decl == StdEnvironment.notlessDecl) {
foldedValue = int1 >= int2;
} else if (o.decl == StdEnvironment.unequalDecl) {
foldedValue = int1 /= int2;
} else {
}
if (foldedValue.toString() == "true" || foldedValue.toString() == "false") {
Identifier ti = new Identifier(foldedValue.toString(), node1.getPosition());
if (ti.spelling == "true") {
System.out.println("True Decl thingy");
ti.decl = StdEnvironment.trueDecl;
SimpleVname sti = new SimpleVname(ti, node1.getPosition());
VnameExpression esti = new VnameExpression(sti, node1.getPosition());
esti.type = StdEnvironment.booleanType;
return esti;
} else if (ti.spelling == "false") {
System.out.println("False Decl thingy");
ti.decl = StdEnvironment.falseDecl;
SimpleVname sti = new SimpleVname(ti, node1.getPosition());
VnameExpression esti = new VnameExpression(sti, node1.getPosition());
esti.type = StdEnvironment.booleanType;
return esti;
}
} }
if (foldedValue instanceof Integer) { if (foldedValue instanceof Integer) {
@ -599,16 +634,9 @@ public class ConstantFolder implements ActualParameterVisitor<Void, AbstractSynt
IntegerExpression ie = new IntegerExpression(il, node1.getPosition()); IntegerExpression ie = new IntegerExpression(il, node1.getPosition());
ie.type = StdEnvironment.integerType; ie.type = StdEnvironment.integerType;
return ie; return ie;
} else if (foldedValue instanceof Boolean) {
//Task 7?
System.out.println("Boolean Expr. ");
/* currently not handled! */
} }
} else {
//?
}
// any unhandled situation (i.e., not foldable) is ignored }
return null; return null;
} }
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save