memorymapped vars in ZP are now treated as ZP-variables by prog8 itself too

This commit is contained in:
Irmen de Jong
2025-04-17 22:19:01 +02:00
parent 4e5ee333c8
commit 830da8de0a
3 changed files with 27 additions and 36 deletions
@@ -2,10 +2,7 @@ package prog8.codegen.cpu6502
import com.github.michaelbull.result.fold
import com.github.michaelbull.result.onSuccess
import prog8.code.StNode
import prog8.code.StNodeType
import prog8.code.StStaticVariable
import prog8.code.SymbolTable
import prog8.code.*
import prog8.code.core.*
@@ -23,7 +20,13 @@ internal class VariableAllocator(private val symboltable: SymbolTable,
zeropageVars = zeropage.allocatedVariables
}
internal fun isZpVar(scopedName: String) = scopedName in zeropageVars
internal fun isZpVar(scopedName: String): Boolean {
if(scopedName in zeropageVars)
return true
val v = symboltable.lookup(scopedName)
return if(v is StMemVar) v.address <= 255u else false
}
internal fun getFloatAsmConst(number: Double): String {
val asmName = globalFloatConsts[number]
+13
View File
@@ -5,12 +5,15 @@ import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual
import io.kotest.matchers.shouldBe
import prog8.code.StMemVar
import prog8.code.SymbolTable
import prog8.code.SymbolTableMaker
import prog8.code.ast.*
import prog8.code.core.*
import prog8.code.source.SourceCode
import prog8.code.target.C64Target
import prog8.codegen.cpu6502.AsmGen6502
import prog8.codegen.cpu6502.VariableAllocator
import java.nio.file.Files
import kotlin.io.path.Path
@@ -160,5 +163,15 @@ class TestCodegen: FunSpec({
}
}
}
test("memory mapped zp var is correctly considered to be zp var") {
val program = PtProgram("test", DummyMemsizer, DummyStringEncoder)
val st = SymbolTable(program)
st.add(StMemVar("zpmemvar", DataType.WORD, 0x20u, null, null))
st.add(StMemVar("normalmemvar", DataType.WORD, 0x9000u, null, null))
val allocator = VariableAllocator(st, getTestOptions(), ErrorReporterForTests())
allocator.isZpVar("zpmemvar") shouldBe true
allocator.isZpVar("normalmemvar") shouldBe false
}
})
+6 -31
View File
@@ -1,38 +1,13 @@
%import textio
%zeropage basicsafe
%option no_sysinit, romable
%option no_sysinit
main $9000 {
main {
sub start() {
ubyte[] filled_array = [11,22,33,44]
ubyte[10] empty_array
uword block = memory("block", 100, 0)
sys.memset(block, 100, 0)
str name = "irmen"
ubyte @shared number
txt.print(name)
txt.spc()
number++
txt.print_ub(number)
txt.spc()
number++
txt.print_ub(number)
txt.nl()
txt.print_ub(block[10])
txt.spc()
block[10]++
txt.print_ub(block[10])
txt.nl()
txt.print_ub(filled_array[2])
txt.spc()
;;empty_array[2]=0 ; TODO should not give error!
txt.print_ub(empty_array[2])
txt.spc()
;;empty_array[2]++ ; TODO should not give error!
txt.print_ub(empty_array[2])
txt.nl()
&uword zeropagevar = $20
uword @shared ptr = 999
cx16.r0L = @(zeropagevar)
cx16.r1L = @(ptr)
}
}