This commit is contained in:
Irmen de Jong
2025-08-19 23:09:33 +02:00
parent fc5889ec0b
commit 32e531f951
3 changed files with 31 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ import io.kotest.datatest.withData
import io.kotest.engine.spec.tempdir
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldContain
import prog8.ast.Module
import prog8.ast.Program
import prog8.ast.expressions.ArrayIndexedExpression
@@ -19,10 +20,7 @@ import prog8.code.target.C128Target
import prog8.code.target.C64Target
import prog8.code.target.PETTarget
import prog8.code.target.VMTarget
import prog8tests.helpers.DummyFunctions
import prog8tests.helpers.DummyMemsizer
import prog8tests.helpers.DummyStringEncoder
import prog8tests.helpers.compileText
import prog8tests.helpers.*
class TestMemory: FunSpec({
@@ -421,4 +419,24 @@ class TestMemory: FunSpec({
target.memorySize(DataType.FLOAT, 10) shouldBe 10*target.FLOAT_MEM_SIZE
}
}
test("errors when writing to data in ROM (romable code)") {
val src="""
%option romable
main {
ubyte[] array = [1,2,3,4,5]
str name = "foobar"
sub start() {
array[2] = 99
name[2] = 'x'
}
}"""
val errors=ErrorReporterForTests()
compileText(C64Target(), false, src, outputDir, errors=errors, writeAssembly = false, varshigh=1, slabshigh=1) shouldBe null
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "8:9: cannot assign to an array or string that is located in ROM"
errors.errors[1] shouldContain "9:9: cannot assign to an array or string that is located in ROM"
}
})

View File

@@ -17,6 +17,8 @@ internal fun compileFile(
outputDir: Path,
errors: IErrorReporter? = null,
writeAssembly: Boolean = true,
varshigh: Int? = null,
slabshigh: Int? = null
) : CompilationResult? {
val filepath = fileDir.resolve(fileName)
assumeReadableFile(filepath)
@@ -33,9 +35,9 @@ internal fun compileFile(
experimentalCodegen = false,
dumpVariables = false,
dumpSymbols = false,
varsHighBank = null,
varsHighBank = varshigh,
varsGolden = false,
slabsHighBank = null,
slabsHighBank = slabshigh,
slabsGolden = false,
platform.name,
symbolDefs = emptyMap(),
@@ -62,10 +64,12 @@ internal fun compileText(
outputDir: Path,
errors: IErrorReporter? = null,
writeAssembly: Boolean = true,
varshigh: Int? = null,
slabshigh: Int? = null
) : CompilationResult? {
val filePath = outputDir.resolve("on_the_fly_test_${sourceText.hashCode().toUInt().toString(16)}.p8")
// we don't assumeNotExists(filePath) - should be ok to just overwrite it
filePath.toFile().writeText(sourceText)
return compileFile(platform, optimize, filePath.parent, filePath.name, outputDir,
errors=errors, writeAssembly=writeAssembly)
errors=errors, writeAssembly=writeAssembly, varshigh=varshigh, slabshigh=slabshigh)
}