labels are now prefixed with underscore in assembly to fix undefined symbol errors from the assembler

This commit is contained in:
Irmen de Jong 2020-03-15 00:23:54 +01:00
parent a995867deb
commit 68ce4a1bf0
3 changed files with 20 additions and 5 deletions

View File

@ -750,7 +750,7 @@ internal class AsmGen(private val program: Program,
}
private fun translate(stmt: Label) {
out(stmt.name)
out("_${stmt.name}") // underscore prefix to make sure it's a local label
}
private fun translate(scope: AnonymousScope) {
@ -819,7 +819,14 @@ internal class AsmGen(private val program: Program,
private fun getJumpTarget(jmp: Jump): String {
return when {
jmp.identifier!=null -> asmIdentifierName(jmp.identifier)
jmp.identifier!=null -> {
val target = jmp.identifier.targetStatement(program.namespace)
val asmName = asmIdentifierName(jmp.identifier)
if(target is Label)
"_$asmName" // prefix with underscore to jump to local label
else
asmName
}
jmp.generatedLabel!=null -> jmp.generatedLabel
jmp.address!=null -> jmp.address.toHex()
else -> "????"

View File

@ -38,7 +38,6 @@ main {
ubyte y = y1
if dx >= dy {
; TODO fix assembler problem when defining label here
forever {
c64scr.setcc(x, y, 42, 5)
if x==x2
@ -51,7 +50,6 @@ main {
}
}
} else {
; TODO fix assembler problem when defining label here
forever {
c64scr.setcc(x, y, 42, 5)
if y == y2

View File

@ -1,8 +1,18 @@
%zeropage basicsafe
main 23232323 {
main {
sub start() {
if A>Y {
label1:
Y=0
goto label1
} else {
label2:
Y=1
goto label2
}
c64scr.print("spstart:")
print_stackpointer()
sub1()