diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 09f09ed37..ecf761c54 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -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) { diff --git a/examples/test.p8 b/examples/test.p8 index fcbe84337..4c41d9dfd 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -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 } }