diff --git a/codeCore/src/prog8/code/target/cx16/CX16Zeropage.kt b/codeCore/src/prog8/code/target/cx16/CX16Zeropage.kt
index fdb890ed9..b0aa89983 100644
--- a/codeCore/src/prog8/code/target/cx16/CX16Zeropage.kt
+++ b/codeCore/src/prog8/code/target/cx16/CX16Zeropage.kt
@@ -45,8 +45,9 @@ class CX16Zeropage(options: CompilationOptions) : Zeropage(options) {
removeReservedFromFreePool()
- // note: the 16 virtual registers R0-R15 are not regular allocated variables, they're *memory mapped* elsewhere to fixed addresses.
- // however, to be able for the compiler to "see" them as zero page variables, we have to register them here as well.
+ // Note: the 16 virtual registers R0-R15 are not regular allocated variables, they're *memory mapped* elsewhere to fixed addresses.
+ // However, to be able for the compiler to "see" them as zero page variables, we have to register them here as well.
+ // This is important because the compiler sometimes treats ZP variables more efficiently (for example if it's a pointer)
for(reg in 0..15) {
allocatedVariables[listOf("cx16", "r${reg}")] = ZpAllocation((2+reg*2).toUInt(), DataType.UWORD, 2) // cx16.r0 .. cx16.r15
allocatedVariables[listOf("cx16", "r${reg}s")] = ZpAllocation((2+reg*2).toUInt(), DataType.WORD, 2) // cx16.r0s .. cx16.r15s
diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt
index a89eb31f4..9b887a777 100644
--- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt
+++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt
@@ -70,7 +70,7 @@ internal class ProgramAndVarsGen(
asmgen.out("P8ZP_SCRATCH_REG = ${zp.SCRATCH_REG}")
asmgen.out("P8ZP_SCRATCH_W1 = ${zp.SCRATCH_W1} ; word")
asmgen.out("P8ZP_SCRATCH_W2 = ${zp.SCRATCH_W2} ; word")
- asmgen.out(".weak") // hack to allow user to override the following two with command line redefinition:
+ asmgen.out(".weak") // hack to allow user to override the following two with command line redefinition (however, just use '-esa' command line option instead!)
asmgen.out("P8ESTACK_LO = ${compTarget.machine.ESTACK_LO.toHex()}")
asmgen.out("P8ESTACK_HI = ${compTarget.machine.ESTACK_HI.toHex()}")
asmgen.out(".endweak")
diff --git a/codeGenVirtual/build.gradle b/codeGenVirtual/build.gradle
index 6b3077244..39434270f 100644
--- a/codeGenVirtual/build.gradle
+++ b/codeGenVirtual/build.gradle
@@ -3,6 +3,7 @@ plugins {
id 'java'
id 'application'
id "org.jetbrains.kotlin.jvm"
+ id "io.kotest" version "0.3.9"
}
java {
@@ -31,6 +32,7 @@ dependencies {
// implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.16"
+ testImplementation 'io.kotest:kotest-runner-junit5-jvm:5.3.2'
}
sourceSets {
@@ -42,6 +44,22 @@ sourceSets {
srcDirs = ["${project.projectDir}/res"]
}
}
+ test {
+ java {
+ srcDir "${project.projectDir}/test"
+ }
+ }
}
-// note: there are no unit tests in this module!
+test {
+ // Enable JUnit 5 (Gradle 4.6+).
+ useJUnitPlatform()
+
+ // Always run tests, even when nothing changed.
+ dependsOn 'cleanTest'
+
+ // Show test results.
+ testLogging {
+ events "skipped", "failed"
+ }
+}
\ No newline at end of file
diff --git a/codeGenVirtual/codeGenVirtual.iml b/codeGenVirtual/codeGenVirtual.iml
index baa82a25b..15fd4d946 100644
--- a/codeGenVirtual/codeGenVirtual.iml
+++ b/codeGenVirtual/codeGenVirtual.iml
@@ -4,11 +4,14 @@
+
+
+
diff --git a/codeGenVirtual/test/Dummies.kt b/codeGenVirtual/test/Dummies.kt
new file mode 100644
index 000000000..4b1510e46
--- /dev/null
+++ b/codeGenVirtual/test/Dummies.kt
@@ -0,0 +1,19 @@
+package prog8tests.vm.helpers
+
+import prog8.code.core.*
+
+
+internal object DummyMemsizer : IMemSizer {
+ override fun memorySize(dt: DataType) = 0
+ override fun memorySize(arrayDt: DataType, numElements: Int) = 0
+}
+
+internal object DummyStringEncoder : IStringEncoding {
+ override fun encodeString(str: String, encoding: Encoding): List {
+ return emptyList()
+ }
+
+ override fun decodeString(bytes: List, encoding: Encoding): String {
+ return ""
+ }
+}
diff --git a/compiler/test/vm/TestVmPeepholeOpt.kt b/codeGenVirtual/test/TestVmPeepholeOpt.kt
similarity index 98%
rename from compiler/test/vm/TestVmPeepholeOpt.kt
rename to codeGenVirtual/test/TestVmPeepholeOpt.kt
index 708fb2ba0..f4fc33fb9 100644
--- a/compiler/test/vm/TestVmPeepholeOpt.kt
+++ b/codeGenVirtual/test/TestVmPeepholeOpt.kt
@@ -1,5 +1,6 @@
package prog8tests.vm
+import io.kotest.assertions.fail
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import prog8.code.SymbolTable
@@ -7,8 +8,8 @@ import prog8.code.ast.PtProgram
import prog8.codegen.virtual.*
import prog8.vm.Opcode
import prog8.vm.VmDataType
-import prog8tests.helpers.DummyMemsizer
-import prog8tests.helpers.DummyStringEncoder
+import prog8tests.vm.helpers.DummyMemsizer
+import prog8tests.vm.helpers.DummyStringEncoder
class TestVmPeepholeOpt: FunSpec({
fun makeVmProgram(lines: List): Pair {
diff --git a/compiler/build.gradle b/compiler/build.gradle
index 6099abb38..a5e238277 100644
--- a/compiler/build.gradle
+++ b/compiler/build.gradle
@@ -34,7 +34,6 @@ dependencies {
implementation project(':codeGenCpu6502')
implementation project(':codeGenVirtual')
implementation project(':codeGenExperimental')
- implementation project(':virtualmachine')
implementation 'org.antlr:antlr4-runtime:4.10.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// implementation "org.jetbrains.kotlin:kotlin-reflect"
@@ -69,7 +68,6 @@ sourceSets {
test {
java {
srcDir "${project.projectDir}/test"
- srcDir "${project(':compilerAst').projectDir}/test/helpers"
}
}
}
diff --git a/compiler/compiler.iml b/compiler/compiler.iml
index bcd055869..943a0528b 100644
--- a/compiler/compiler.iml
+++ b/compiler/compiler.iml
@@ -23,6 +23,5 @@
-
\ No newline at end of file
diff --git a/docs/source/todo.rst b/docs/source/todo.rst
index 62e4f313c..f38f56b5d 100644
--- a/docs/source/todo.rst
+++ b/docs/source/todo.rst
@@ -3,11 +3,9 @@ TODO
For next release
^^^^^^^^^^^^^^^^
-- move the vm unit tests to codeGenVirtual module and remove virtualmachine dependency in the compiler module
- add item to XZeropage that enables an option that if zeropage=FULL or KERNALSAFE, moves the cx16 virtual registers to ZP, same location as on x16
- (can be done on C64 only for now) Remove those addresses from the ZP free pool!!!
- needs the dynamic base address for the symbols in syslib.p8
- also needs a trick to allocate them in ZP like Cx16Zeropage already does
+ (can be done on C64 only for now) Remove those addresses from the ZP free pool = allocate them in ZP like Cx16Zeropage does
+ Adapt the code in AstPreprocessor that relocates the registers as well.
...