fixed too eager expression operand type adjustment

This commit is contained in:
Irmen de Jong 2019-02-27 23:07:12 +01:00
parent 588133d418
commit 96ecbc9fe4
2 changed files with 25 additions and 21 deletions

View File

@ -75,7 +75,7 @@ class SimplifyExpressions(private val namespace: INameScope, private val heap: H
val leftDt = expr.left.resultingDatatype(namespace, heap)
val rightDt = expr.right.resultingDatatype(namespace, heap)
if (leftDt != null && rightDt != null && leftDt != rightDt) {
// try to convert a datatype into the other
// try to convert a datatype into the other (where ddd
if (adjustDatatypes(expr, leftVal, leftDt, rightVal, rightDt)) {
optimizationsDone++
return expr
@ -347,26 +347,37 @@ class SimplifyExpressions(private val namespace: INameScope, private val heap: H
}
if(leftConstVal==null && rightConstVal!=null) {
val (adjusted, newValue) = adjust(rightConstVal, leftDt)
if(adjusted) {
expr.right = newValue
optimizationsDone++
return true
if(isBiggerType(leftDt, rightDt)) {
val (adjusted, newValue) = adjust(rightConstVal, leftDt)
if (adjusted) {
expr.right = newValue
optimizationsDone++
return true
}
}
return false
} else if(leftConstVal!=null && rightConstVal==null) {
val (adjusted, newValue) = adjust(leftConstVal, rightDt)
if(adjusted) {
expr.left = newValue
optimizationsDone++
return true
if(isBiggerType(rightDt, leftDt)) {
val (adjusted, newValue) = adjust(leftConstVal, rightDt)
if (adjusted) {
expr.left = newValue
optimizationsDone++
return true
}
}
return false
} else {
return false
return false // two const values, don't adjust (should have been const-folded away)
}
}
private fun isBiggerType(type: DataType, other: DataType) =
when(type) {
in ByteDatatypes -> false
in WordDatatypes -> other in ByteDatatypes
else -> true
}
private data class ReorderedAssociativeBinaryExpr(val expr: BinaryExpression, val leftVal: LiteralValue?, val rightVal: LiteralValue?)

View File

@ -8,8 +8,8 @@
; @todo see problem in looplabelproblem.p8
; @todo add docs for '@zp' tag in variable datatype declarations (including forloop loopvars)
; @todo gradle fatJar should include the antlr runtime jar
; word ww2; byte bb; ww2 = bb * 55.w ; @todo why is this compiling, but resulting in a byte?
; uword x = sin8u(bb) as uword + 50 ; @todo fix "cannot assign word to uword"
; uword ypos=4; ypos += 5000 ; @todo fix "cannot assign word to uword"
@ -26,16 +26,9 @@
bb2 = bb*55
ww2 = ww*55
;uword x = sin8u(bb) as uword + 50 ; @todo fix "cannot assign word to uword"
uword x = sin8u(bb) as uword + 50 ; @todo fix "cannot assign word to uword"
;ypos += 5000 ; @todo fix "cannot assign word to uword"
ww2 = bb * 55.w ; @todo why is this compiling, but resulting in a byte?
c64scr.print_w(ww2)
c64.CHROUT('\n')
ww2 = (bb as word)*55
c64scr.print_w(ww2)
c64.CHROUT('\n')
;
; memset($0400+(ypos+0)*40, 40, 1)
; memset($0400+(ypos+1)*40, 40, 2)