From 4b7b1379d95a762ee31968d00478a122f623a170 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 8 Aug 2022 00:09:18 +0200 Subject: [PATCH] also binexpr split on and,or,xor if appropriate --- codeCore/src/prog8/code/core/Operators.kt | 2 +- compiler/test/TestTypecasts.kt | 17 +++++++++-------- examples/test.p8 | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/codeCore/src/prog8/code/core/Operators.kt b/codeCore/src/prog8/code/core/Operators.kt index 6bf34b0bd..0e218aa30 100644 --- a/codeCore/src/prog8/code/core/Operators.kt +++ b/codeCore/src/prog8/code/core/Operators.kt @@ -3,7 +3,7 @@ package prog8.code.core val AssociativeOperators = setOf("+", "*", "&", "|", "^", "==", "!=") val ComparisonOperators = setOf("==", "!=", "<", ">", "<=", ">=") val LogicalOperators = setOf("and", "or", "xor", "not") -val AugmentAssignmentOperators = setOf("+", "-", "/", "*", "&", "|", "^", "<<", ">>", "%") +val AugmentAssignmentOperators = setOf("+", "-", "/", "*", "&", "|", "^", "<<", ">>", "%", "and", "or", "xor") val BitwiseOperators = setOf("&", "|", "^", "~") // val InvalidOperatorsForBoolean = setOf("+", "-", "*", "/", "%", "<<", ">>") + BitwiseOperators diff --git a/compiler/test/TestTypecasts.kt b/compiler/test/TestTypecasts.kt index e72886d29..31eb9df7c 100644 --- a/compiler/test/TestTypecasts.kt +++ b/compiler/test/TestTypecasts.kt @@ -95,22 +95,23 @@ main { ubyte ub3 ub3 = 1 ubyte @shared bvalue - bvalue = (((ub1^ub2)^ub3)^1) + bvalue = ub1 + bvalue ^= ub2 + bvalue ^= ub3 + bvalue ^= 1 bvalue = (((ub1^ub2)^ub3)^(ftrue(99)!=0)) bvalue = ((ub1&ub2)&(ftrue(99)!=0)) return */ - stmts.size shouldBe 11 - val assignValue1 = (stmts[7] as Assignment).value as BinaryExpression - val assignValue2 = (stmts[8] as Assignment).value as BinaryExpression - val assignValue3 = (stmts[9] as Assignment).value as BinaryExpression - assignValue1.operator shouldBe "^" + stmts.size shouldBe 14 + val assignValue1 = (stmts[7] as Assignment).value as IdentifierReference + val assignValue2 = (stmts[11] as Assignment).value as BinaryExpression + val assignValue3 = (stmts[12] as Assignment).value as BinaryExpression + assignValue1.nameInSource shouldBe listOf("ub1") assignValue2.operator shouldBe "^" assignValue3.operator shouldBe "&" - val right1 = assignValue1.right as NumericLiteral val right2 = assignValue2.right as BinaryExpression val right3 = assignValue3.right as BinaryExpression - right1.number shouldBe 1.0 right2.operator shouldBe "!=" right3.operator shouldBe "!=" right2.left shouldBe instanceOf() diff --git a/examples/test.p8 b/examples/test.p8 index 584053fae..0dc7fd7c0 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -3,6 +3,24 @@ main { sub start() { + bool b1 = false + bool b2 = true + bool b3 + + b2 = b2 and b1 + txt.print_ub(b2) + txt.nl() + + ubyte ub1 = 1 + ubyte ub2 = 2 + ubyte ub3 + + ub2 = ub2 + ub1 + txt.print_ub(ub2) + } + + + sub start2() { ubyte[] arr = [1,2,3,4] uword pointer ubyte ix