added memsizer unit tests

This commit is contained in:
Irmen de Jong 2024-09-08 15:24:47 +02:00
parent 124ffac4e4
commit c5b7edad82
4 changed files with 41 additions and 6 deletions

View File

@ -41,6 +41,7 @@ dependencies {
testImplementation project(':codeCore')
testImplementation project(':intermediate')
testImplementation 'io.kotest:kotest-runner-junit5-jvm:5.9.1'
testImplementation 'io.kotest:kotest-framework-datatest:5.9.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

View File

@ -15,7 +15,7 @@
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
<orderEntry type="library" name="io.kotest.assertions.core.jvm" level="project" />
<orderEntry type="library" name="io.kotest.runner.junit5.jvm" level="project" />
<orderEntry type="library" name="antlr.antlr4" level="project" />
<orderEntry type="library" name="io.kotest.framework.datatest" level="project" />
<orderEntry type="module" module-name="codeCore" />
<orderEntry type="module" module-name="compilerAst" />
<orderEntry type="module" module-name="codeOptimizers" />
@ -24,5 +24,6 @@
<orderEntry type="module" module-name="codeGenIntermediate" />
<orderEntry type="module" module-name="virtualmachine" />
<orderEntry type="module" module-name="intermediate" scope="TEST" />
<orderEntry type="library" name="antlr.antlr4" level="project" />
</component>
</module>

View File

@ -1,6 +1,8 @@
package prog8tests
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.datatest.withData
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import prog8.ast.Module
@ -10,11 +12,8 @@ import prog8.ast.expressions.IdentifierReference
import prog8.ast.expressions.NumericLiteral
import prog8.ast.expressions.PrefixExpression
import prog8.ast.statements.*
import prog8.code.core.DataType
import prog8.code.core.Position
import prog8.code.core.SourceCode
import prog8.code.core.ZeropageWish
import prog8.code.target.C64Target
import prog8.code.core.*
import prog8.code.target.*
import prog8tests.helpers.DummyFunctions
import prog8tests.helpers.DummyMemsizer
import prog8tests.helpers.DummyStringEncoder
@ -244,4 +243,34 @@ class TestMemory: FunSpec({
}
""", writeAssembly = true) shouldBe null
}
context("memsizer") {
withData(VMTarget(), AtariTarget(), C64Target(), PETTarget(), AtariTarget(), C128Target()) { target ->
shouldThrow<IllegalArgumentException> {
target.memorySize(DataType.UNDEFINED)
}
shouldThrow<IllegalArgumentException> {
target.memorySize(DataType.LONG)
}
target.memorySize(DataType.BOOL) shouldBe 1
target.memorySize(DataType.BYTE) shouldBe 1
target.memorySize(DataType.WORD) shouldBe 2
target.memorySize(DataType.FLOAT) shouldBe target.machine.FLOAT_MEM_SIZE
target.memorySize(DataType.STR) shouldBe 2
target.memorySize(DataType.ARRAY_UB) shouldBe 2
target.memorySize(DataType.ARRAY_UW) shouldBe 2
target.memorySize(DataType.ARRAY_F) shouldBe 2
shouldThrow<NoSuchElementException> {
target.memorySize(DataType.UBYTE, 10)
}
target.memorySize(DataType.UWORD, 10) shouldBe 10 // uword is pointer to array of bytes
target.memorySize(DataType.ARRAY_B, 10) shouldBe 10
target.memorySize(DataType.ARRAY_UB, 10) shouldBe 10
target.memorySize(DataType.ARRAY_F, 10) shouldBe 10*target.machine.FLOAT_MEM_SIZE
target.memorySize(DataType.ARRAY_UW, 10) shouldBe 20
target.memorySize(DataType.ARRAY_W_SPLIT, 10) shouldBe 20
target.memorySize(DataType.ARRAY_UW_SPLIT, 10) shouldBe 20
}
}
})

View File

@ -1,6 +1,10 @@
TODO
====
convert example tests that loop over arrays, to data driven withData()
move those tests to a new separated module in the project so they're not always ran as part of compiler:test
Improve register load order in subroutine call args assignments:
in certain situations, the "wrong" order of evaluation of function call arguments is done which results
in overwriting registers that already got their value, which requires a lot of stack juggling (especially on plain 6502 cpu!)