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

View File

@ -3,10 +3,7 @@ TODO
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

View File

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