mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 19:29:50 +00:00
fix wrong values generated from range expression in array vardecl
This commit is contained in:
parent
390043e9e8
commit
a81b82495c
@ -47,7 +47,10 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
|
||||
DataType.ARRAY_UB, DataType.ARRAY_B, DataType.ARRAY_UW, DataType.ARRAY_W -> {
|
||||
val rangeExpr = decl.value as? RangeExpr
|
||||
if(rangeExpr!=null) {
|
||||
// convert the initializer range expression to an actual array
|
||||
// convert the initializer range expression to an actual array (will be put on heap later)
|
||||
val declArraySize = decl.arraysize?.size()
|
||||
if(declArraySize!=null && declArraySize!=rangeExpr.size(heap))
|
||||
errors.add(ExpressionError("range expression size doesn't match declared array size", decl.value?.position!!))
|
||||
val constRange = rangeExpr.toConstantIntegerRange(heap)
|
||||
if(constRange!=null) {
|
||||
val eltType = rangeExpr.resultingDatatype(namespace, heap)!!
|
||||
@ -68,7 +71,7 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
|
||||
if(decl.arraysize==null)
|
||||
return decl
|
||||
val size = decl.arraysize.size()
|
||||
if ((litval==null || !litval.isArray) && size != null) {
|
||||
if ((litval==null || !litval.isArray) && size != null && rangeExpr==null) {
|
||||
// arraysize initializer is empty or a single int, and we know the size; create the arraysize.
|
||||
val fillvalue = if (litval == null) 0 else litval.asIntegerValue ?: 0
|
||||
when(decl.datatype){
|
||||
|
@ -4,15 +4,13 @@
|
||||
|
||||
sub start() {
|
||||
|
||||
ubyte[5] array2 = 20 to 100 ; @todo fix this initializer value
|
||||
word[5] array3 = 3000 to 3100 ; @todo fix this initializer value
|
||||
ubyte[81] array2 = 20 to 100
|
||||
word[] array3 = 3000 to 3100
|
||||
|
||||
c64scr.print_uw(len(array2))
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print_uw(len(array3))
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print_uw(len(array4))
|
||||
c64.CHROUT('\n')
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print_ub(array2[0])
|
||||
c64.CHROUT(',')
|
||||
|
Loading…
x
Reference in New Issue
Block a user