mirror of
https://github.com/irmen/prog8.git
synced 2025-08-19 10:27:43 +00:00
don't optimize empty where choice away! It would call the else clause incorrectly.
This commit is contained in:
@@ -413,10 +413,17 @@ class IRCodeGen(
|
|||||||
result += translateNode(choice.statements)
|
result += translateNode(choice.statements)
|
||||||
addInstr(result, IRInstruction(Opcode.JUMP, labelSymbol = endLabel), null)
|
addInstr(result, IRInstruction(Opcode.JUMP, labelSymbol = endLabel), null)
|
||||||
} else {
|
} else {
|
||||||
val choiceLabel = createLabelName()
|
if(choice.statements.children.isEmpty()) {
|
||||||
choices.add(choiceLabel to choice)
|
// no statements for this choice value, jump to the end immediately
|
||||||
choice.values.children.map { it as PtNumber }.sortedBy { it.number }.forEach { value ->
|
choice.values.children.map { it as PtNumber }.sortedBy { it.number }.forEach { value ->
|
||||||
addInstr(result, IRInstruction(Opcode.BEQ, valueDt, reg1=valueTr.resultReg, immediate = value.number.toInt(), labelSymbol = choiceLabel), null)
|
addInstr(result, IRInstruction(Opcode.BEQ, valueDt, reg1=valueTr.resultReg, immediate = value.number.toInt(), labelSymbol = endLabel), null)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val choiceLabel = createLabelName()
|
||||||
|
choices.add(choiceLabel to choice)
|
||||||
|
choice.values.children.map { it as PtNumber }.sortedBy { it.number }.forEach { value ->
|
||||||
|
addInstr(result, IRInstruction(Opcode.BEQ, valueDt, reg1=valueTr.resultReg, immediate = value.number.toInt(), labelSymbol = choiceLabel), null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -262,15 +262,5 @@ internal class VariousCleanups(val program: Program, val errors: IErrorReporter,
|
|||||||
}
|
}
|
||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun after(whenStmt: When, parent: Node): Iterable<IAstModification> {
|
|
||||||
val removals = mutableListOf<Int>()
|
|
||||||
whenStmt.choices.withIndex().forEach { (index, choice) ->
|
|
||||||
if(choice.statements.isEmpty())
|
|
||||||
removals.add(index)
|
|
||||||
}
|
|
||||||
removals.reversed().forEach { whenStmt.choices.removeAt(it) }
|
|
||||||
return noModifications
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
|
- compiling Rockrunner with -noopt crashes the program soon after startup
|
||||||
|
|
||||||
- IR: reduce the number of branch instructions such as BEQ, BEQR, etc (gradually), replace with CMP(I) + status branch instruction
|
- IR: reduce the number of branch instructions such as BEQ, BEQR, etc (gradually), replace with CMP(I) + status branch instruction
|
||||||
- IR: reduce amount of CMP/CMPI after instructions that set the status bits correctly (LOADs? INC? etc), but only after setting the status bits is verified!
|
- IR: reduce amount of CMP/CMPI after instructions that set the status bits correctly (LOADs? INC? etc), but only after setting the status bits is verified!
|
||||||
|
|
||||||
|
@@ -1,27 +1,16 @@
|
|||||||
%import gfx2
|
|
||||||
%import textio
|
%import textio
|
||||||
|
%zeropage basicsafe
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
gfx2.screen_mode(6) ; 1 and 5 are lo-res and hi-res monochrome
|
ubyte var = 0
|
||||||
|
|
||||||
uword xx
|
when var {
|
||||||
gfx2.rect(10, 10, 180, 140, 3)
|
1 -> txt.print("one")
|
||||||
gfx2.rect(12, 12, 180, 140, 3)
|
2 -> txt.print("two")
|
||||||
|
0 -> {
|
||||||
cbm.SETTIM(0,0,0)
|
}
|
||||||
|
else -> txt.print("other")
|
||||||
for xx in 5 to 100 {
|
|
||||||
gfx2.text(xx, xx, 1, sc:"hello world! should be pixel-aligned.")
|
|
||||||
gfx2.text(xx, xx, 2, sc:"hello world! should be pixel-aligned.")
|
|
||||||
gfx2.text(xx, xx, 3, sc:"hello world! should be pixel-aligned.")
|
|
||||||
gfx2.text(xx, xx, 0, sc:"hello world! should be pixel-aligned.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx2.screen_mode(0)
|
|
||||||
txt.print_uw(cbm.RDTIM16())
|
|
||||||
txt.print(" jiffies")
|
|
||||||
|
|
||||||
repeat { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user