tweak ifelse > and <= order

This commit is contained in:
Irmen de Jong 2024-03-02 17:01:31 +01:00
parent a282b17286
commit c48012c385
2 changed files with 29 additions and 4 deletions

View File

@ -446,8 +446,19 @@ internal class AssignmentAsmGen(private val program: PtProgram,
ifPart.add(assignTrue)
elsePart.add(assignFalse)
val ifelse = PtIfElse(assign.position)
val exprClone = PtBinaryExpression(expr.operator, expr.type, expr.position)
expr.children.forEach { exprClone.children.add(it) } // doesn't seem to need a deep clone
val exprClone: PtBinaryExpression
if(!asmgen.isTargetCpu(CpuType.VIRTUAL)
&& (expr.operator==">" || expr.operator=="<=")
&& expr.right.type in WordDatatypes) {
// word X>Y -> X<Y, X<=Y -> Y>=X , easier to do in 6502 (codegen also expects these to no longe exist!)
exprClone = PtBinaryExpression(if(expr.operator==">") "<" else ">=", expr.type, expr.position)
exprClone.children.add(expr.children[1]) // doesn't seem to need a deep clone
exprClone.children.add(expr.children[0]) // doesn't seem to need a deep clone
} else {
exprClone = PtBinaryExpression(expr.operator, expr.type, expr.position)
exprClone.children.add(expr.children[0]) // doesn't seem to need a deep clone
exprClone.children.add(expr.children[1]) // doesn't seem to need a deep clone
}
ifelse.add(exprClone)
ifelse.add(ifPart)
ifelse.add(elsePart)
@ -511,8 +522,19 @@ internal class AssignmentAsmGen(private val program: PtProgram,
}
ifPart.add(assignTrue)
val ifelse = PtIfElse(assign.position)
val exprClone = PtBinaryExpression(expr.operator, expr.type, expr.position)
expr.children.forEach { exprClone.children.add(it) } // doesn't seem to need a deep clone
val exprClone: PtBinaryExpression
if(!asmgen.isTargetCpu(CpuType.VIRTUAL)
&& (expr.operator==">" || expr.operator=="<=")
&& expr.right.type in WordDatatypes) {
// word X>Y -> X<Y, X<=Y -> Y>=X , easier to do in 6502 (codegen also expects these to no longe exist!)
exprClone = PtBinaryExpression(if(expr.operator==">") "<" else ">=", expr.type, expr.position)
exprClone.children.add(expr.children[1]) // doesn't seem to need a deep clone
exprClone.children.add(expr.children[0]) // doesn't seem to need a deep clone
} else {
exprClone = PtBinaryExpression(expr.operator, expr.type, expr.position)
exprClone.children.add(expr.children[0]) // doesn't seem to need a deep clone
exprClone.children.add(expr.children[1]) // doesn't seem to need a deep clone
}
ifelse.add(exprClone)
ifelse.add(ifPart)
ifelse.add(PtNodeGroup())

View File

@ -2,6 +2,9 @@ TODO
====
larger programs:
dirlist
bobs
cobramk3-gfx
automatons
mandelbrot (quite a bit larger)
mandelbrot-gfx