also binexpr split on and,or,xor if appropriate

This commit is contained in:
Irmen de Jong 2022-08-08 00:09:18 +02:00
parent e560e2ab3f
commit 4b7b1379d9
3 changed files with 28 additions and 9 deletions

View File

@ -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

View File

@ -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<IFunctionCall>()

View File

@ -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