tweak return's use of intermediate variable

This commit is contained in:
Irmen de Jong 2022-01-24 01:10:04 +01:00
parent adb979df38
commit 586ce1fc80
3 changed files with 18 additions and 19 deletions

View File

@ -459,11 +459,15 @@ class StatementOptimizer(private val program: Program,
return null return null
} }
if(returnStmt.value is BinaryExpression) { // TODO decision when to use intermediary variable to calculate returnvalue seems a bit arbitrary...
val mod = returnViaIntermediaryVar(returnStmt.value!!) val returnvalue = returnStmt.value
if (returnvalue!=null) {
if (returnvalue is BinaryExpression || (returnvalue is TypecastExpression && !returnvalue.expression.isSimple)) {
val mod = returnViaIntermediaryVar(returnvalue)
if(mod!=null) if(mod!=null)
return mod return mod
} }
}
return noModifications return noModifications
} }

View File

@ -3,10 +3,7 @@ TODO
For next release For next release
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
- why does this use stack eval on return: ...
sub sprite_y_for_row(ubyte row) -> word {
return (8-row as byte)
}
Need help with Need help with

View File

@ -4,22 +4,20 @@
main { main {
sub start() { sub start() {
ubyte ccc word ww = calculate(6)
ubyte @shared qq = string.find("irmendejong", ccc)!=0
word ww
ww = calculate(6)
txt.print_w(ww) txt.print_w(ww)
txt.nl() txt.nl()
ww = calculate(8) ubyte bb = calculate2(6)
txt.print_w(ww) txt.print_ub(bb)
txt.nl() txt.nl()
ww = calculate(10)
txt.print_w(ww)
txt.nl()
qq = string.find("irmendejong", ccc)!=0
} }
sub calculate2(ubyte row) -> ubyte {
return 8+row
}
sub calculate(ubyte row) -> word { sub calculate(ubyte row) -> word {
return 8-(row as byte) return 8+row
} }
} }