mirror of
https://github.com/irmen/prog8.git
synced 2024-08-11 05:29:18 +00:00
clean up unused codegen for logical ops on words, also fix no-shortcircuit exception
This commit is contained in:
parent
1c55a6c6dc
commit
265e7aefbf
@ -1088,22 +1088,7 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
else if (expr.left.type in WordDatatypes && expr.right.type in WordDatatypes) {
|
else if (expr.left.type in WordDatatypes && expr.right.type in WordDatatypes) {
|
||||||
if (expr.right is PtNumber || expr.right is PtIdentifier) {
|
throw AssemblyError("logical and/or/xor on words should be done on typecast to bytes instead")
|
||||||
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
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -1833,26 +1818,6 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
assignRegisterpairWord(target, RegisterOrPair.AY)
|
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 {
|
private fun attemptAssignToByteCompareZero(expr: PtBinaryExpression, assign: AsmAssignment): Boolean {
|
||||||
when (expr.operator) {
|
when (expr.operator) {
|
||||||
"==" -> {
|
"==" -> {
|
||||||
|
@ -882,10 +882,9 @@ $shortcutLabel:""")
|
|||||||
+""")
|
+""")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"&" -> asmgen.out(" and $variable")
|
"&", "and" -> asmgen.out(" and $variable")
|
||||||
"|" -> asmgen.out(" ora $variable")
|
"|", "or" -> asmgen.out(" ora $variable")
|
||||||
"and", "or" -> throw AssemblyError("logical and/or should have been handled earlier because of shortcircuit handling")
|
"^","xor" -> asmgen.out(" eor $variable")
|
||||||
"^" -> asmgen.out(" eor $variable")
|
|
||||||
"==" -> {
|
"==" -> {
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
cmp $variable
|
cmp $variable
|
||||||
|
@ -6,7 +6,7 @@ TODO
|
|||||||
- note: shortcircuit only on logical boolean expressions (and,or) not on bitwise (&,|)
|
- note: shortcircuit only on logical boolean expressions (and,or) not on bitwise (&,|)
|
||||||
- vm ircodegen (PARTIALLY DONE!)
|
- vm ircodegen (PARTIALLY DONE!)
|
||||||
- in 6502 codegen (see vm's ExpressionGen operatorAnd / operatorOr)
|
- 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
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -2,15 +2,6 @@
|
|||||||
%zeropage dontuse
|
%zeropage dontuse
|
||||||
|
|
||||||
main {
|
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 a1 = 10
|
||||||
ubyte @shared a2 = 20
|
ubyte @shared a2 = 20
|
||||||
ubyte @shared x1 = 30
|
ubyte @shared x1 = 30
|
||||||
|
Loading…
Reference in New Issue
Block a user