mirror of
https://github.com/irmen/prog8.git
synced 2024-07-13 12:29:05 +00:00
reintroduce expressions for array indexing
This commit is contained in:
parent
8f2e166a22
commit
8aeb8a9bb7
@ -1053,9 +1053,8 @@ internal class AstChecker(private val program: Program,
|
|||||||
if(dtxVar!=null && dtxVar != DataType.UBYTE && dtxVar != DataType.BYTE)
|
if(dtxVar!=null && dtxVar != DataType.UBYTE && dtxVar != DataType.BYTE)
|
||||||
errors.err("array indexing is limited to byte size 0..255", arrayIndexedExpression.position)
|
errors.err("array indexing is limited to byte size 0..255", arrayIndexedExpression.position)
|
||||||
|
|
||||||
// check type of array indexer
|
if(arrayIndexedExpression.indexer.origExpression!=null)
|
||||||
if(arrayIndexedExpression.indexer.indexVar==null && arrayIndexedExpression.indexer.indexNum==null)
|
throw FatalAstException("array indexer should have been replaced with a temp var @ ${arrayIndexedExpression.indexer.position}")
|
||||||
errors.err("array indexing can only be done with a number or a variable, or a simple binary expression, but not an arbitrary expression. Use a temp var?", arrayIndexedExpression.indexer.position)
|
|
||||||
|
|
||||||
super.visit(arrayIndexedExpression)
|
super.visit(arrayIndexedExpression)
|
||||||
}
|
}
|
||||||
|
@ -72,18 +72,19 @@ internal class StatementReorderer(val program: Program, val errors: ErrorReporte
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun after(arrayIndexedExpression: ArrayIndexedExpression, parent: Node): Iterable<IAstModification> {
|
override fun after(arrayIndexedExpression: ArrayIndexedExpression, parent: Node): Iterable<IAstModification> {
|
||||||
val expr = arrayIndexedExpression.indexer.origExpression
|
when (val expr = arrayIndexedExpression.indexer.origExpression) {
|
||||||
if (expr is NumericLiteralValue) {
|
is NumericLiteralValue -> {
|
||||||
arrayIndexedExpression.indexer.indexNum = expr
|
arrayIndexedExpression.indexer.indexNum = expr
|
||||||
arrayIndexedExpression.indexer.origExpression = null
|
arrayIndexedExpression.indexer.origExpression = null
|
||||||
}
|
return noModifications
|
||||||
else if (expr is IdentifierReference) {
|
}
|
||||||
arrayIndexedExpression.indexer.indexVar = expr
|
is IdentifierReference -> {
|
||||||
arrayIndexedExpression.indexer.origExpression = null
|
arrayIndexedExpression.indexer.indexVar = expr
|
||||||
}
|
arrayIndexedExpression.indexer.origExpression = null
|
||||||
else if(expr is BinaryExpression) {
|
return noModifications
|
||||||
if((expr.left is NumericLiteralValue || expr.left is IdentifierReference) &&
|
}
|
||||||
(expr.right is NumericLiteralValue || expr.right is IdentifierReference)) {
|
is Expression -> {
|
||||||
|
// replace complex indexing with a temp variable
|
||||||
val modifications = mutableListOf<IAstModification>()
|
val modifications = mutableListOf<IAstModification>()
|
||||||
val indexerVarName = "prog8_autovar_index"
|
val indexerVarName = "prog8_autovar_index"
|
||||||
val block = expr.definingBlock()
|
val block = expr.definingBlock()
|
||||||
@ -107,9 +108,8 @@ internal class StatementReorderer(val program: Program, val errors: ErrorReporte
|
|||||||
|
|
||||||
return modifications
|
return modifications
|
||||||
}
|
}
|
||||||
|
else -> return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
return noModifications
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun after(whenStatement: WhenStatement, parent: Node): Iterable<IAstModification> {
|
override fun after(whenStatement: WhenStatement, parent: Node): Iterable<IAstModification> {
|
||||||
|
@ -41,10 +41,8 @@ main {
|
|||||||
ubyte @zp i
|
ubyte @zp i
|
||||||
for i in 0 to 7 {
|
for i in 0 to 7 {
|
||||||
c64.SPRPTR[i] = $0a00 / 64
|
c64.SPRPTR[i] = $0a00 / 64
|
||||||
ubyte twoi = i*2
|
c64.SPXY[i*2] = 50+25*i
|
||||||
c64.SPXY[twoi] = 50+25*i
|
c64.SPXY[i*2+1] = rnd()
|
||||||
twoi++
|
|
||||||
c64.SPXY[twoi] = rnd()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c64.SPENA = 255 ; enable all sprites
|
c64.SPENA = 255 ; enable all sprites
|
||||||
|
Loading…
Reference in New Issue
Block a user