diff --git a/codeOptimizers/build.gradle b/codeOptimizers/build.gradle index 08fff1115..0cedf5d3b 100644 --- a/codeOptimizers/build.gradle +++ b/codeOptimizers/build.gradle @@ -20,6 +20,11 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" // implementation "org.jetbrains.kotlin:kotlin-reflect" + testImplementation "org.jetbrains.kotlin:kotlin-test-junit5" + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' + testImplementation 'org.hamcrest:hamcrest:2.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' + } compileKotlin { diff --git a/codeOptimizers/codeOptimizers.iml b/codeOptimizers/codeOptimizers.iml index aadd52214..6778075ca 100644 --- a/codeOptimizers/codeOptimizers.iml +++ b/codeOptimizers/codeOptimizers.iml @@ -4,11 +4,14 @@ + + + - + \ No newline at end of file diff --git a/codeOptimizers/test/TestOptimizers.kt b/codeOptimizers/test/TestOptimizers.kt new file mode 100644 index 000000000..1a097f0ff --- /dev/null +++ b/codeOptimizers/test/TestOptimizers.kt @@ -0,0 +1,21 @@ +package prog8tests + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.fail + + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class TestOptimizers { + + @Test + @Disabled("for future implementation") + fun dummy() { + fail("dummy") + } + +} diff --git a/compilerInterfaces/build.gradle b/compilerInterfaces/build.gradle index 68d9db7bc..0499bfdff 100644 --- a/compilerInterfaces/build.gradle +++ b/compilerInterfaces/build.gradle @@ -19,6 +19,11 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" // implementation "org.jetbrains.kotlin:kotlin-reflect" + testImplementation "org.jetbrains.kotlin:kotlin-test-junit5" + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' + testImplementation 'org.hamcrest:hamcrest:2.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' + } compileKotlin { diff --git a/compilerInterfaces/compilerInterfaces.iml b/compilerInterfaces/compilerInterfaces.iml index f9ace27ff..2c25b13e2 100644 --- a/compilerInterfaces/compilerInterfaces.iml +++ b/compilerInterfaces/compilerInterfaces.iml @@ -4,10 +4,13 @@ + + + \ No newline at end of file diff --git a/compilerInterfaces/src/prog8/compilerinterface/AstExtensions.kt b/compilerInterfaces/src/prog8/compilerinterface/AstExtensions.kt index 999ebd569..61c5c5e1e 100644 --- a/compilerInterfaces/src/prog8/compilerinterface/AstExtensions.kt +++ b/compilerInterfaces/src/prog8/compilerinterface/AstExtensions.kt @@ -74,6 +74,7 @@ fun RangeExpr.toConstantIntegerRange(encoding: IStringEncoding): IntProgression? val fromString = from as? StringLiteralValue val toString = to as? StringLiteralValue if(fromString!=null && toString!=null ) { + // TODO WHAT IS A STRING RANGE?????? // string range -> int range over character values fromVal = encoding.encodeString(fromString.value, fromString.altEncoding)[0].toInt() toVal = encoding.encodeString(toString.value, fromString.altEncoding)[0].toInt() diff --git a/compilerInterfaces/test/TestAstExtensions.kt b/compilerInterfaces/test/TestAstExtensions.kt new file mode 100644 index 000000000..996567e0f --- /dev/null +++ b/compilerInterfaces/test/TestAstExtensions.kt @@ -0,0 +1,36 @@ +package prog8tests + +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import prog8.ast.base.Position +import prog8.ast.expressions.NumericLiteralValue +import prog8.ast.expressions.RangeExpr +import prog8.compilerinterface.* +import kotlin.test.assertEquals + + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class TestAstExtensions { + + @Test + fun testRangeExprNumericSize() { + val expr = RangeExpr( + NumericLiteralValue.optimalInteger(10, Position.DUMMY), + NumericLiteralValue.optimalInteger(20, Position.DUMMY), + NumericLiteralValue.optimalInteger(2, Position.DUMMY), + Position.DUMMY) + val encoding = DummyStringEncoding() + assertEquals(6, expr.size(encoding)) + } + + class DummyStringEncoding : IStringEncoding { + override fun encodeString(str: String, altEncoding: Boolean): List { + TODO("Not yet implemented") + } + + override fun decodeString(bytes: List, altEncoding: Boolean): String { + TODO("Not yet implemented") + } + + } +} diff --git a/compilerInterfaces/test/TestZeropage.kt b/compilerInterfaces/test/TestZeropage.kt new file mode 100644 index 000000000..f9ad5fcfb --- /dev/null +++ b/compilerInterfaces/test/TestZeropage.kt @@ -0,0 +1,71 @@ +package prog8tests + +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import prog8.ast.base.DataType +import prog8.compilerinterface.* +import kotlin.test.assertEquals + + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class TestZeropage { + + @Test + fun testAbstractZeropage() { + val compTarget = DummyCompilationTarget() + val zp = DummyZeropage( + CompilationOptions( + OutputType.RAW, + LauncherType.NONE, + ZeropageType.FULL, + listOf((0x50..0x5f)), + false, + false, + compTarget + ) + ) + assertEquals(256-4-16, zp.free.size) + } + + class DummyCompilationTarget: ICompilationTarget { + override val name: String + get() = TODO("Not yet implemented") + override val machine: IMachineDefinition + get() = TODO("Not yet implemented") + + override fun encodeString(str: String, altEncoding: Boolean): List { + TODO("Not yet implemented") + } + + override fun decodeString(bytes: List, altEncoding: Boolean): String { + TODO("Not yet implemented") + } + + override fun memorySize(dt: DataType): Int { + TODO("Not yet implemented") + } + + } + + class DummyZeropage(options: CompilationOptions) : Zeropage(options) { + override val SCRATCH_B1: Int = 0x10 + override val SCRATCH_REG: Int = 0x11 + override val SCRATCH_W1: Int= 0x12 + override val SCRATCH_W2: Int = 0x13 + + init { + free.addAll(0..255) + + // TODO should be in class: + free.remove(SCRATCH_B1) + free.remove(SCRATCH_REG) + free.remove(SCRATCH_W1) + free.remove(SCRATCH_W2) + + // TODO should be in class: + for (reserved in options.zpReserved) + reserve(reserved) + } + } + +}