mirror of
https://github.com/irmen/prog8.git
synced 2024-11-20 03:32:05 +00:00
fixed too eager expression operand type adjustment
This commit is contained in:
parent
588133d418
commit
96ecbc9fe4
@ -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?)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user