mirror of
				https://github.com/irmen/prog8.git
				synced 2025-11-03 19:16:13 +00:00 
			
		
		
		
	test
This commit is contained in:
		@@ -1317,7 +1317,7 @@ internal class AssignmentAsmGen(
 | 
			
		||||
                        else
 | 
			
		||||
                            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
 | 
			
		||||
                }
 | 
			
		||||
                else -> {
 | 
			
		||||
@@ -3341,7 +3341,7 @@ $endLabel""")
 | 
			
		||||
                        RegisterOrPair.Y -> { asmgen.out("  tay") }
 | 
			
		||||
                        RegisterOrPair.AY -> {
 | 
			
		||||
                            require(extendWord) {
 | 
			
		||||
                                "no extend"
 | 
			
		||||
                                "no extend but byte target is registerpair"
 | 
			
		||||
                            }
 | 
			
		||||
                            if(signed)
 | 
			
		||||
                                asmgen.out("""
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user