mirror of
https://github.com/irmen/prog8.git
synced 2024-11-29 17:50:35 +00:00
fix crash when using labels in pointerexpression lab+index
This commit is contained in:
parent
c5bfef4264
commit
f2844bdf1a
@ -551,9 +551,16 @@ internal class AsmGen(private val program: Program,
|
||||
|
||||
internal fun loadByteFromPointerIntoA(pointervar: IdentifierReference): Pair<Boolean, String> {
|
||||
// returns if the pointer is already on the ZP itself or not (in the latter case SCRATCH_W1 is used as intermediary)
|
||||
val target = pointervar.targetStatement(program)
|
||||
when (target) {
|
||||
is Label -> {
|
||||
val sourceName = asmSymbolName(pointervar)
|
||||
out(" lda $sourceName")
|
||||
return Pair(true, sourceName)
|
||||
}
|
||||
is VarDecl -> {
|
||||
val sourceName = asmVariableName(pointervar)
|
||||
val vardecl = pointervar.targetVarDecl(program)!!
|
||||
val scopedName = vardecl.makeScopedName(vardecl.name)
|
||||
val scopedName = target.makeScopedName(target.name)
|
||||
if (isTargetCpu(CpuType.CPU65c02)) {
|
||||
return if (isZpVar(scopedName)) {
|
||||
// pointervar is already in the zero page, no need to copy
|
||||
@ -585,6 +592,9 @@ internal class AsmGen(private val program: Program,
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> throw AssemblyError("invalid pointervar")
|
||||
}
|
||||
}
|
||||
|
||||
private fun fixNameSymbols(name: String) = name.replace("<", "prog8_").replace(">", "") // take care of the autogenerated invalid (anon) label names
|
||||
|
||||
@ -1470,6 +1480,14 @@ $label nop""")
|
||||
val ptrAndIndex = pointerViaIndexRegisterPossible(expr)
|
||||
if(ptrAndIndex!=null) {
|
||||
val pointervar = ptrAndIndex.first as? IdentifierReference
|
||||
val target = pointervar?.targetStatement(program)
|
||||
when(target) {
|
||||
is Label -> {
|
||||
assignExpressionToRegister(ptrAndIndex.second, RegisterOrPair.Y)
|
||||
out(" lda ${asmSymbolName(pointervar)},y")
|
||||
return true
|
||||
}
|
||||
is VarDecl, null -> {
|
||||
if(write) {
|
||||
if(pointervar!=null && isZpVar(pointervar)) {
|
||||
val saveA = evalBytevalueWillClobberA(ptrAndIndex.second)
|
||||
@ -1503,6 +1521,9 @@ $label nop""")
|
||||
}
|
||||
return true
|
||||
}
|
||||
else -> throw AssemblyError("invalid pointervar")
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -785,6 +785,7 @@ data class IdentifierReference(val nameInSource: List<String>, override val posi
|
||||
override fun inferType(program: Program): InferredTypes.InferredType {
|
||||
return when (val targetStmt = targetStatement(program)) {
|
||||
is VarDecl -> InferredTypes.knownFor(targetStmt.datatype)
|
||||
is Label -> InferredTypes.InferredType.known(DataType.UWORD)
|
||||
else -> InferredTypes.InferredType.unknown()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user