diff --git a/Triangle.Compiler/src/main/java/triangle/optimiser/ConstantFolder.java b/Triangle.Compiler/src/main/java/triangle/optimiser/ConstantFolder.java index 98addbe..f911e26 100644 --- a/Triangle.Compiler/src/main/java/triangle/optimiser/ConstantFolder.java +++ b/Triangle.Compiler/src/main/java/triangle/optimiser/ConstantFolder.java @@ -592,23 +592,51 @@ public class ConstantFolder implements ActualParameterVisitor 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) { IntegerLiteral il = new IntegerLiteral(foldedValue.toString(), node1.getPosition()); IntegerExpression ie = new IntegerExpression(il, node1.getPosition()); ie.type = StdEnvironment.integerType; 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; } } diff --git a/booleanfold.tam b/booleanfold.tam index 4b9c40f..b9a835b 100644 Binary files a/booleanfold.tam and b/booleanfold.tam differ diff --git a/booleannotfold.tam b/booleannotfold.tam new file mode 100644 index 0000000..4b9c40f Binary files /dev/null and b/booleannotfold.tam differ diff --git a/build/libs/Triangle-Tools.jar b/build/libs/Triangle-Tools.jar index 12a3ad4..b9f2390 100644 Binary files a/build/libs/Triangle-Tools.jar and b/build/libs/Triangle-Tools.jar differ