@@ -23,10 +23,7 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
2323 private var breakpointCounter = 0
2424
2525 init {
26- // Because 64tass understands scoped names via .proc / .block,
27- // we'll strip the block prefix from all scoped names in the program.
28- // Also, convert invalid label names (such as "<anon-1>") to something that's allowed.
29- // Also have to do that for the variablesMarkedForZeropage! TODO is this true?
26+ // Convert invalid label names (such as "<anon-1>") to something that's allowed.
3027 val newblocks = mutableListOf<IntermediateProgram .ProgramBlock >()
3128 for (block in program.blocks) {
3229 val newvars = block.variables.map { symname(it.key, block) to it.value }.toMap().toMutableMap()
@@ -42,13 +39,13 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
4239 callLabel2 = if (it.callLabel2 != null ) symname(it.callLabel2, block) else null )
4340 }
4441 }.toMutableList()
45- val newConstants = block.memoryPointers.map { symname(it.key, block) to it.value }.toMap().toMutableMap()
42+ val newMempointers = block.memoryPointers.map { symname(it.key, block) to it.value }.toMap().toMutableMap()
4643 val newblock = IntermediateProgram .ProgramBlock (
4744 block.name,
4845 block.address,
4946 newinstructions,
5047 newvars,
51- newConstants ,
48+ newMempointers ,
5249 newlabels,
5350 force_output = block.force_output)
5451 newblock.variablesMarkedForZeropage.clear()
@@ -58,10 +55,9 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
5855 program.blocks.clear()
5956 program.blocks.addAll(newblocks)
6057
61- // TODO is this still needed?????
62- // val newAllocatedZp = program.allocatedZeropageVariables.map { symname(it.key, null) to it.value}
63- // program.allocatedZeropageVariables.clear()
64- // program.allocatedZeropageVariables.putAll(newAllocatedZp)
58+ val newAllocatedZp = program.allocatedZeropageVariables.map { symname(it.key, null ) to it.value}
59+ program.allocatedZeropageVariables.clear()
60+ program.allocatedZeropageVariables.putAll(newAllocatedZp)
6561
6662 // make a list of all const floats that are used
6763 for (block in program.blocks) {
@@ -107,11 +103,11 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
107103
108104
109105 // convert a fully scoped name (defined in the given block) to a valid assembly symbol name
110- private fun symname (scoped : String , block : IntermediateProgram .ProgramBlock ): String {
106+ private fun symname (scoped : String , block : IntermediateProgram .ProgramBlock ? ): String {
111107 if (' ' in scoped)
112108 return scoped
113109 val blockLocal: Boolean
114- var name = if (scoped.startsWith(" ${block.name} ." )) {
110+ var name = if (block != null && scoped.startsWith(" ${block.name} ." )) {
115111 blockLocal = true
116112 scoped.substring(block.name.length+ 1 )
117113 }
@@ -221,16 +217,16 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
221217 out (" * = ${block.address?.toHex()} " )
222218 }
223219
224- // deal with zeropage variables TODO does this still work correctly (the symname was changed a little)
220+ // deal with zeropage variables
225221 for (variable in blk.variables) {
226- val sym = symname(blk.name+ " ." + variable.key, blk )
222+ val sym = symname(blk.name+ " ." + variable.key, null )
227223 val zpVar = program.allocatedZeropageVariables[sym]
228224 if (zpVar== null ) {
229225 // This var is not on the ZP yet. Attempt to move it there (if it's not a float, those take up too much space)
230226 if (variable.value.type in zeropage.allowedDatatypes && variable.value.type != DataType .FLOAT ) {
231227 try {
232228 val address = zeropage.allocate(sym, variable.value.type, null )
233- out (" ${variable.key} = $address \t ; zp ${variable.value.type} " )
229+ out (" ${variable.key} = $address \t ; auto zp ${variable.value.type} " )
234230 // make sure we add the var to the set of zpvars for this block
235231 blk.variablesMarkedForZeropage.add(variable.key)
236232 program.allocatedZeropageVariables[sym] = Pair (address, variable.value.type)
0 commit comments