mirror of
https://github.com/irmen/prog8.git
synced 2025-11-03 04:17:16 +00:00
errormessage for assignment to str/arrays in ROM
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user