diff --git a/compiler/src/prog8/compiler/Zeropage.kt b/compiler/src/prog8/compiler/Zeropage.kt index 0c4b08a35..3aa5859cf 100644 --- a/compiler/src/prog8/compiler/Zeropage.kt +++ b/compiler/src/prog8/compiler/Zeropage.kt @@ -18,6 +18,9 @@ abstract class Zeropage(protected val options: CompilationOptions) { fun allocate(scopedname: String, datatype: DataType, position: Position?): Int { assert(scopedname.isEmpty() || !allocations.values.any { it.first==scopedname } ) {"isSameAs scopedname can't be allocated twice"} + if(options.zeropage==ZeropageType.DONTUSE) + throw CompilerException("zero page usage has been disabled") + val size = when (datatype) { in ByteDatatypes -> 1 diff --git a/compiler/src/prog8/compiler/target/c64/MachineDefinition.kt b/compiler/src/prog8/compiler/target/c64/MachineDefinition.kt index 7f312cd2c..235c334a2 100644 --- a/compiler/src/prog8/compiler/target/c64/MachineDefinition.kt +++ b/compiler/src/prog8/compiler/target/c64/MachineDefinition.kt @@ -84,7 +84,7 @@ object MachineDefinition { )) } - if(options.zeropage==ZeropageType.BASICSAFE) { + if(options.zeropage!=ZeropageType.DONTUSE) { // add the other free Zp addresses, // these are valid for the C-64 (when no RS232 I/O is performed) but to keep BASIC running fully: free.addAll(listOf(0x04, 0x05, 0x06, 0x0a, 0x0e, diff --git a/compiler/test/RuntimeValueTests.kt b/compiler/test/RuntimeValueTests.kt index ac8c4fbb1..1e8ece187 100644 --- a/compiler/test/RuntimeValueTests.kt +++ b/compiler/test/RuntimeValueTests.kt @@ -116,18 +116,6 @@ class TestRuntimeValue { assertFalse(sameValueAndType(RuntimeValue(DataType.FLOAT, 9.99), RuntimeValue(DataType.FLOAT, 9.0))) } - @Test - fun testRequireHeap() - { - assertFailsWith { RuntimeValue(DataType.STR, num = 999) } - assertFailsWith { RuntimeValue(DataType.STR_S, num = 999) } - assertFailsWith { RuntimeValue(DataType.ARRAY_F, num = 999) } - assertFailsWith { RuntimeValue(DataType.ARRAY_W, num = 999) } - assertFailsWith { RuntimeValue(DataType.ARRAY_UW, num = 999) } - assertFailsWith { RuntimeValue(DataType.ARRAY_B, num = 999) } - assertFailsWith { RuntimeValue(DataType.ARRAY_UB, num = 999) } - } - @Test fun testEqualityHeapTypes() { diff --git a/compiler/test/UnitTests.kt b/compiler/test/UnitTests.kt index 2d84632b7..a11519514 100644 --- a/compiler/test/UnitTests.kt +++ b/compiler/test/UnitTests.kt @@ -145,8 +145,14 @@ class TestZeropage { assertFailsWith { zp.allocate("", DataType.FLOAT, null) } - val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true)) - zp2.allocate("", DataType.FLOAT, null) + val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), true)) + assertFailsWith { + zp.allocate("", DataType.FLOAT, null) + } + val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true)) + assertFailsWith { + zp.allocate("", DataType.FLOAT, null) + } } @Test @@ -170,11 +176,11 @@ class TestZeropage { @Test fun testFreeSpaces() { val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true)) - assertEquals(20, zp1.available()) + assertEquals(16, zp1.available()) val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false)) - assertEquals(95, zp2.available()) + assertEquals(91, zp2.available()) val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false)) - assertEquals(129, zp3.available()) + assertEquals(125, zp3.available()) val zp4 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false)) assertEquals(238, zp4.available()) } @@ -204,11 +210,10 @@ class TestZeropage { @Test fun testBasicsafeAllocation() { val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true)) - assertEquals(20, zp.available()) + assertEquals(16, zp.available()) - zp.allocate("", DataType.FLOAT, null) assertFailsWith { - // in regular zp there aren't 5 sequential bytes free after we take the first sequence + // in regular zp there aren't 5 sequential bytes free zp.allocate("", DataType.FLOAT, null) } @@ -258,16 +263,16 @@ class TestZeropage { @Test fun testEfficientAllocation() { val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true)) - assertEquals(20, zp.available()) - assertEquals(0x04, zp.allocate("", DataType.FLOAT, null)) - assertEquals(0x09, zp.allocate("", DataType.UBYTE, null)) - assertEquals(0x0d, zp.allocate("", DataType.UWORD, null)) + assertEquals(16, zp.available()) + assertEquals(0x04, zp.allocate("", DataType.WORD, null)) + assertEquals(0x06, zp.allocate("", DataType.UBYTE, null)) + assertEquals(0x0a, zp.allocate("", DataType.UBYTE, null)) assertEquals(0x94, zp.allocate("", DataType.UWORD, null)) assertEquals(0xa7, zp.allocate("", DataType.UWORD, null)) assertEquals(0xa9, zp.allocate("", DataType.UWORD, null)) assertEquals(0xb5, zp.allocate("", DataType.UWORD, null)) assertEquals(0xf7, zp.allocate("", DataType.UWORD, null)) - assertEquals(0x0a, zp.allocate("", DataType.UBYTE, null)) + assertEquals(0x0e, zp.allocate("", DataType.UBYTE, null)) assertEquals(0xf9, zp.allocate("", DataType.UBYTE, null)) assertEquals(0, zp.available()) }