diff --git a/tools/src/wyvern/stdlib/Globals.java b/tools/src/wyvern/stdlib/Globals.java index 54410c5bb..dd79233a2 100644 --- a/tools/src/wyvern/stdlib/Globals.java +++ b/tools/src/wyvern/stdlib/Globals.java @@ -175,6 +175,8 @@ public static ValueType getSystemType() { boolDeclTypes.add(new DefDeclType("&&", Util.booleanType(), Arrays.asList(new FormalArg("other", Util.booleanType())))); boolDeclTypes.add(new DefDeclType("||", Util.booleanType(), Arrays.asList(new FormalArg("other", Util.booleanType())))); boolDeclTypes.add(new DefDeclType("!", Util.booleanType(), Arrays.asList())); + boolDeclTypes.add(new DefDeclType("==", Util.booleanType(), Arrays.asList(new FormalArg("other", Util.booleanType())))); + boolDeclTypes.add(new DefDeclType("!=", Util.booleanType(), Arrays.asList(new FormalArg("other", Util.booleanType())))); // construct a type for the system object // N.B.: Operations here are built-in and performed on an instance of a type. diff --git a/tools/src/wyvern/target/corewyvernIL/expression/BooleanLiteral.java b/tools/src/wyvern/target/corewyvernIL/expression/BooleanLiteral.java index c61587721..29b591558 100644 --- a/tools/src/wyvern/target/corewyvernIL/expression/BooleanLiteral.java +++ b/tools/src/wyvern/target/corewyvernIL/expression/BooleanLiteral.java @@ -16,7 +16,7 @@ import wyvern.tools.errors.FileLocation; public class BooleanLiteral extends Literal implements Invokable { - private boolean value; + private Boolean value; @Override public int hashCode() { @@ -118,7 +118,12 @@ public ValueType typeCheck(TypeContext ctx, EffectAccumulator effectAccumulator) return new BooleanLiteral(this.value || ((BooleanLiteral) args.get(0)).value); case "!": return new BooleanLiteral(!this.value); - default: throw new RuntimeException(); + case "==": + return new BooleanLiteral(this.value.compareTo(((BooleanLiteral) args.get(0)).getValue()) == 0); + case "!=": + return new BooleanLiteral(this.value.compareTo(((BooleanLiteral) args.get(0)).getValue()) != 0); + default: + throw new RuntimeException(); } } diff --git a/tools/src/wyvern/tools/tests/OIRTests.java b/tools/src/wyvern/tools/tests/OIRTests.java index f50102c9b..e25c5c1d6 100644 --- a/tools/src/wyvern/tools/tests/OIRTests.java +++ b/tools/src/wyvern/tools/tests/OIRTests.java @@ -694,7 +694,7 @@ public void testTypecheckingLoop() throws ParseException { + "\"typechecked!\""; testPyFromInput(input, "typechecked!"); } - + @Test public void testComparisonOperator() throws ParseException { String input = @@ -711,8 +711,13 @@ public void testComparisonOperator() throws ParseException { + "stdout.printBoolean(\"a\" > \"b\")\n" + "stdout.printBoolean(\"a\" < \"b\")\n" + "stdout.printBoolean(\"a\" != \"b\")\n" + + "stdout.printBoolean(true == true)\n" + + "stdout.printBoolean(false == true)\n" + + "stdout.printBoolean(false != true)\n" + + "stdout.printBoolean((1 > 2) == (2 > 3))\n" + "stdout.println()\n" + "0"; - testPyFromInput(input, "FalseTrueFalseFalseTrueTrueFalseTrueFalseFalseTrueTrue\n0"); + testPyFromInput(input, "FalseTrueFalseFalseTrueTrueFalseTrueFalseFalseTrueTrueTrueFalseTrueTrue\n0"); } } +