errormessage for assignment to str/arrays in ROM

This commit is contained in:
Irmen de Jong
2025-03-31 23:57:04 +02:00
parent 1075ee8fc3
commit 61079c1eb7
2 changed files with 48 additions and 6 deletions

View File

@@ -686,6 +686,25 @@ internal class AstChecker(private val program: Program,
}
}
}
fun checkRomTarget(target: AssignTarget) {
val idx=target.arrayindexed
if(idx!=null) {
val decl = idx.arrayvar.targetVarDecl(program)!!
if(decl.type!=VarDeclType.MEMORY && decl.zeropage!=ZeropageWish.REQUIRE_ZEROPAGE) {
// memory mapped arrays are assumed to be in RAM. If they're not.... well, POOF
errors.err("cannot assign to an array or string that is located in ROM", assignTarget.position)
}
}
}
if(compilerOptions.romable) {
if (assignTarget.multi != null)
assignTarget.multi?.forEach { checkRomTarget(it) }
else
checkRomTarget(assignTarget)
}
}
override fun visit(addressOf: AddressOf) {

View File

@@ -1,19 +1,42 @@
%import test_stack
%import textio
%zeropage dontuse
%zeropage basicsafe
%option no_sysinit, romable
main {
sub start() {
str name = "irmen" ; there a re no memory-mepped strings.
ubyte[] array = [11,22,33,44]
&ubyte[20] marray = $2000
uword @shared pointer = $4000
ubyte @shared bankno = 10
sys.memset($2000, 20, 55)
extsub @bank bankno $a000 = routine1()
extsub @bank 11 $a000 = routine2()
txt.print(name)
txt.spc()
txt.print_ub(array[1])
txt.spc()
txt.print_ub(marray[1])
txt.nl()
routine1()
routine2()
name[2] = '!'
marray[1] = '!' ; TODO should be allowed because memory mapped to non-rom area
array[1], marray[1] = multi()
cx16.r0L=1
pointer[cx16.r0L] = 99
txt.print(name)
txt.spc()
txt.print_ub(array[1])
txt.spc()
txt.print_ub(marray[1])
txt.nl()
}
sub multi() -> ubyte, ubyte {
cx16.r0++
return 65,66
}
}