mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
conditional expressions are optimized more intelligently (simple ones are not split off in separate assignments)
This commit is contained in:
parent
5190594c8a
commit
ab2d1122a9
@ -240,10 +240,7 @@ internal class BeforeAsmGenerationAstChanger(val program: Program, private val o
|
||||
var rightAssignment: Assignment? = null
|
||||
var rightOperandReplacement: Expression? = null
|
||||
|
||||
|
||||
// TODO don't optimize simple conditionals that are just a function call
|
||||
|
||||
if(!expr.left.isSimple) {
|
||||
if(!expr.left.isSimple && expr.left !is IFunctionCall) {
|
||||
val dt = expr.left.inferType(program)
|
||||
val name = when {
|
||||
dt.istype(DataType.UBYTE) -> listOf("cx16","r9L") // assume (hope) cx16.r9 isn't used for anything else...
|
||||
@ -259,7 +256,7 @@ internal class BeforeAsmGenerationAstChanger(val program: Program, private val o
|
||||
expr.position
|
||||
)
|
||||
}
|
||||
if(!expr.right.isSimple) {
|
||||
if(!expr.right.isSimple && expr.right !is IFunctionCall) {
|
||||
val dt = expr.right.inferType(program)
|
||||
val name = when {
|
||||
dt.istype(DataType.UBYTE) -> listOf("prog8_lib","retval_interm_ub")
|
||||
|
@ -118,7 +118,7 @@ class PrefixExpression(val operator: String, var expression: Expression, overrid
|
||||
}
|
||||
}
|
||||
|
||||
override val isSimple = false
|
||||
override val isSimple = true
|
||||
|
||||
override fun toString(): String {
|
||||
return "Prefix($operator $expression)"
|
||||
|
@ -3,7 +3,6 @@ TODO
|
||||
|
||||
For next compiler release (7.3)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
- simplifyConditionalExpression: don't change conditinal expressions that are just a single function call
|
||||
- add expression simplification to while and until loops as well.
|
||||
|
||||
|
||||
|
@ -5,15 +5,16 @@
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
float[] farr = [1.111,2.222,3.333,4.444,5.555,6.666]
|
||||
float f2 = 9.999
|
||||
ubyte xx=1
|
||||
ubyte yy=2
|
||||
byte xx=1
|
||||
|
||||
floats.print_f(farr[3])
|
||||
txt.nl()
|
||||
floats.print_f(farr[xx+yy])
|
||||
txt.nl()
|
||||
if -xx {
|
||||
xx++
|
||||
}
|
||||
|
||||
sub test() -> ubyte {
|
||||
xx++
|
||||
return xx
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user