diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt index af46723e4..6f3f37a95 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt @@ -1088,22 +1088,7 @@ internal class AssignmentAsmGen(private val program: PtProgram, return true } else if (expr.left.type in WordDatatypes && expr.right.type in WordDatatypes) { - if (expr.right is PtNumber || expr.right is PtIdentifier) { - assignLogicalAndOrWithSimpleRightOperandWord(target, expr.left, expr.operator, expr.right) - return true - } - else if (expr.left is PtNumber || expr.left is PtIdentifier) { - assignLogicalAndOrWithSimpleRightOperandWord(target, expr.right, expr.operator, expr.left) - return true - } - asmgen.assignWordOperandsToAYAndVar(expr.left, expr.right, "P8ZP_SCRATCH_W1") - when (expr.operator) { - "and" -> TODO("logical and (with optional shortcircuit) ${expr.position}") - "or" -> TODO("logical or (with optional shortcircuit) ${expr.position}") - else -> throw AssemblyError("invalid logical operator") - } - assignRegisterpairWord(target, RegisterOrPair.AY) - return true + throw AssemblyError("logical and/or/xor on words should be done on typecast to bytes instead") } return false } @@ -1833,26 +1818,6 @@ internal class AssignmentAsmGen(private val program: PtProgram, assignRegisterpairWord(target, RegisterOrPair.AY) } - private fun assignLogicalAndOrWithSimpleRightOperandWord(target: AsmAssignTarget, left: PtExpression, operator: String, right: PtExpression) { - when(right) { - is PtNumber -> { - when (operator) { - "and" -> TODO("logical and (with optional shortcircuit) ${left.position}") - "or" -> TODO("logical or (with optional shortcircuit) ${left.position}") - else -> throw AssemblyError("invalid logical operator") - } - } - is PtIdentifier -> { - when (operator) { - "and" -> TODO("logical and (with optional shortcircuit) ${left.position}") - "or" -> TODO("logical or (with optional shortcircuit) ${left.position}") - else -> throw AssemblyError("invalid logical operator") - } - } - else -> throw AssemblyError("wrong right operand type") - } - } - private fun attemptAssignToByteCompareZero(expr: PtBinaryExpression, assign: AsmAssignment): Boolean { when (expr.operator) { "==" -> { diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt index 27e019e54..5cbc0825b 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt @@ -882,10 +882,9 @@ $shortcutLabel:""") +""") } } - "&" -> asmgen.out(" and $variable") - "|" -> asmgen.out(" ora $variable") - "and", "or" -> throw AssemblyError("logical and/or should have been handled earlier because of shortcircuit handling") - "^" -> asmgen.out(" eor $variable") + "&", "and" -> asmgen.out(" and $variable") + "|", "or" -> asmgen.out(" ora $variable") + "^","xor" -> asmgen.out(" eor $variable") "==" -> { asmgen.out(""" cmp $variable diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 7f01406b0..9c7102ddf 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -6,7 +6,7 @@ TODO - note: shortcircuit only on logical boolean expressions (and,or) not on bitwise (&,|) - vm ircodegen (PARTIALLY DONE!) - in 6502 codegen (see vm's ExpressionGen operatorAnd / operatorOr) - - test on word variables, if the TODO doesn't trigger, just replace it with a specific notification + - remove debug println's ... diff --git a/examples/test.p8 b/examples/test.p8 index c1088b7c6..ba1fe9d1b 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -2,15 +2,6 @@ %zeropage dontuse main { -/* - sub start() { - if bool_true() and bool_false() and bool_true() - txt.print("all true") - else - txt.print("not all true") - } -*/ - ubyte @shared a1 = 10 ubyte @shared a2 = 20 ubyte @shared x1 = 30