mirror of
https://github.com/irmen/prog8.git
synced 2024-09-07 19:54:26 +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 leftDt = expr.left.resultingDatatype(namespace, heap)
|
||||||
val rightDt = expr.right.resultingDatatype(namespace, heap)
|
val rightDt = expr.right.resultingDatatype(namespace, heap)
|
||||||
if (leftDt != null && rightDt != null && leftDt != rightDt) {
|
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)) {
|
if (adjustDatatypes(expr, leftVal, leftDt, rightVal, rightDt)) {
|
||||||
optimizationsDone++
|
optimizationsDone++
|
||||||
return expr
|
return expr
|
||||||
@ -347,26 +347,37 @@ class SimplifyExpressions(private val namespace: INameScope, private val heap: H
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(leftConstVal==null && rightConstVal!=null) {
|
if(leftConstVal==null && rightConstVal!=null) {
|
||||||
val (adjusted, newValue) = adjust(rightConstVal, leftDt)
|
if(isBiggerType(leftDt, rightDt)) {
|
||||||
if(adjusted) {
|
val (adjusted, newValue) = adjust(rightConstVal, leftDt)
|
||||||
expr.right = newValue
|
if (adjusted) {
|
||||||
optimizationsDone++
|
expr.right = newValue
|
||||||
return true
|
optimizationsDone++
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
} else if(leftConstVal!=null && rightConstVal==null) {
|
} else if(leftConstVal!=null && rightConstVal==null) {
|
||||||
val (adjusted, newValue) = adjust(leftConstVal, rightDt)
|
if(isBiggerType(rightDt, leftDt)) {
|
||||||
if(adjusted) {
|
val (adjusted, newValue) = adjust(leftConstVal, rightDt)
|
||||||
expr.left = newValue
|
if (adjusted) {
|
||||||
optimizationsDone++
|
expr.left = newValue
|
||||||
return true
|
optimizationsDone++
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
} else {
|
} 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?)
|
private data class ReorderedAssociativeBinaryExpr(val expr: BinaryExpression, val leftVal: LiteralValue?, val rightVal: LiteralValue?)
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
; @todo see problem in looplabelproblem.p8
|
; @todo see problem in looplabelproblem.p8
|
||||||
|
|
||||||
; @todo add docs for '@zp' tag in variable datatype declarations (including forloop loopvars)
|
; @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 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"
|
; uword ypos=4; ypos += 5000 ; @todo fix "cannot assign word to uword"
|
||||||
|
|
||||||
@ -26,16 +26,9 @@
|
|||||||
bb2 = bb*55
|
bb2 = bb*55
|
||||||
ww2 = ww*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"
|
;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+0)*40, 40, 1)
|
||||||
; memset($0400+(ypos+1)*40, 40, 2)
|
; memset($0400+(ypos+1)*40, 40, 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user