clean up unused codegen for logical ops on words, also fix no-shortcircuit exception

This commit is contained in:
Irmen de Jong 2023-12-30 04:01:22 +01:00
parent 1c55a6c6dc
commit 265e7aefbf
4 changed files with 5 additions and 50 deletions

View File

@ -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) {
"==" -> {

View File

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

View File

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

View File

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