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

@@ -1317,7 +1317,7 @@ internal class AssignmentAsmGen(
else else
asmgen.out(" sec | sbc #${right.number.toHex()}") asmgen.out(" sec | sbc #${right.number.toHex()}")
} }
assignRegisterByte(target, CpuRegister.A, dt.isSigned, true) assignRegisterByte(target, CpuRegister.A, dt.isSigned, target.datatype.isWord)
return true return true
} }
else -> { else -> {
@@ -3341,7 +3341,7 @@ $endLabel""")
RegisterOrPair.Y -> { asmgen.out(" tay") } RegisterOrPair.Y -> { asmgen.out(" tay") }
RegisterOrPair.AY -> { RegisterOrPair.AY -> {
require(extendWord) { require(extendWord) {
"no extend" "no extend but byte target is registerpair"
} }
if(signed) if(signed)
asmgen.out(""" asmgen.out("""

View File

@@ -6,6 +6,7 @@ import io.kotest.datatest.withData
import io.kotest.engine.spec.tempdir import io.kotest.engine.spec.tempdir
import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldContain
import prog8.ast.Module import prog8.ast.Module
import prog8.ast.Program import prog8.ast.Program
import prog8.ast.expressions.ArrayIndexedExpression import prog8.ast.expressions.ArrayIndexedExpression
@@ -19,10 +20,7 @@ import prog8.code.target.C128Target
import prog8.code.target.C64Target import prog8.code.target.C64Target
import prog8.code.target.PETTarget import prog8.code.target.PETTarget
import prog8.code.target.VMTarget import prog8.code.target.VMTarget
import prog8tests.helpers.DummyFunctions import prog8tests.helpers.*
import prog8tests.helpers.DummyMemsizer
import prog8tests.helpers.DummyStringEncoder
import prog8tests.helpers.compileText
class TestMemory: FunSpec({ class TestMemory: FunSpec({
@@ -421,4 +419,24 @@ class TestMemory: FunSpec({
target.memorySize(DataType.FLOAT, 10) shouldBe 10*target.FLOAT_MEM_SIZE 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, outputDir: Path,
errors: IErrorReporter? = null, errors: IErrorReporter? = null,
writeAssembly: Boolean = true, writeAssembly: Boolean = true,
varshigh: Int? = null,
slabshigh: Int? = null
) : CompilationResult? { ) : CompilationResult? {
val filepath = fileDir.resolve(fileName) val filepath = fileDir.resolve(fileName)
assumeReadableFile(filepath) assumeReadableFile(filepath)
@@ -33,9 +35,9 @@ internal fun compileFile(
experimentalCodegen = false, experimentalCodegen = false,
dumpVariables = false, dumpVariables = false,
dumpSymbols = false, dumpSymbols = false,
varsHighBank = null, varsHighBank = varshigh,
varsGolden = false, varsGolden = false,
slabsHighBank = null, slabsHighBank = slabshigh,
slabsGolden = false, slabsGolden = false,
platform.name, platform.name,
symbolDefs = emptyMap(), symbolDefs = emptyMap(),
@@ -62,10 +64,12 @@ internal fun compileText(
outputDir: Path, outputDir: Path,
errors: IErrorReporter? = null, errors: IErrorReporter? = null,
writeAssembly: Boolean = true, writeAssembly: Boolean = true,
varshigh: Int? = null,
slabshigh: Int? = null
) : CompilationResult? { ) : CompilationResult? {
val filePath = outputDir.resolve("on_the_fly_test_${sourceText.hashCode().toUInt().toString(16)}.p8") 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 // we don't assumeNotExists(filePath) - should be ok to just overwrite it
filePath.toFile().writeText(sourceText) filePath.toFile().writeText(sourceText)
return compileFile(platform, optimize, filePath.parent, filePath.name, outputDir, return compileFile(platform, optimize, filePath.parent, filePath.name, outputDir,
errors=errors, writeAssembly=writeAssembly) errors=errors, writeAssembly=writeAssembly, varshigh=varshigh, slabshigh=slabshigh)
} }