mirror of
https://github.com/irmen/prog8.git
synced 2025-02-27 18:29:00 +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> {
|
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)
|
// 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 sourceName = asmVariableName(pointervar)
|
||||||
val vardecl = pointervar.targetVarDecl(program)!!
|
val scopedName = target.makeScopedName(target.name)
|
||||||
val scopedName = vardecl.makeScopedName(vardecl.name)
|
|
||||||
if (isTargetCpu(CpuType.CPU65c02)) {
|
if (isTargetCpu(CpuType.CPU65c02)) {
|
||||||
return if (isZpVar(scopedName)) {
|
return if (isZpVar(scopedName)) {
|
||||||
// pointervar is already in the zero page, no need to copy
|
// 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
|
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)
|
val ptrAndIndex = pointerViaIndexRegisterPossible(expr)
|
||||||
if(ptrAndIndex!=null) {
|
if(ptrAndIndex!=null) {
|
||||||
val pointervar = ptrAndIndex.first as? IdentifierReference
|
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(write) {
|
||||||
if(pointervar!=null && isZpVar(pointervar)) {
|
if(pointervar!=null && isZpVar(pointervar)) {
|
||||||
val saveA = evalBytevalueWillClobberA(ptrAndIndex.second)
|
val saveA = evalBytevalueWillClobberA(ptrAndIndex.second)
|
||||||
@ -1503,6 +1521,9 @@ $label nop""")
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
else -> throw AssemblyError("invalid pointervar")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -785,6 +785,7 @@ data class IdentifierReference(val nameInSource: List<String>, override val posi
|
|||||||
override fun inferType(program: Program): InferredTypes.InferredType {
|
override fun inferType(program: Program): InferredTypes.InferredType {
|
||||||
return when (val targetStmt = targetStatement(program)) {
|
return when (val targetStmt = targetStatement(program)) {
|
||||||
is VarDecl -> InferredTypes.knownFor(targetStmt.datatype)
|
is VarDecl -> InferredTypes.knownFor(targetStmt.datatype)
|
||||||
|
is Label -> InferredTypes.InferredType.known(DataType.UWORD)
|
||||||
else -> InferredTypes.InferredType.unknown()
|
else -> InferredTypes.InferredType.unknown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user