2024-09-08 14:03:57 +00:00
|
|
|
package prog8tests.compiler
|
2022-12-02 22:58:21 +00:00
|
|
|
|
|
|
|
import com.github.michaelbull.result.expectError
|
|
|
|
import com.github.michaelbull.result.getOrThrow
|
|
|
|
import io.kotest.core.spec.style.FunSpec
|
|
|
|
import io.kotest.matchers.shouldBe
|
|
|
|
import prog8.code.core.*
|
|
|
|
import prog8.code.target.VMTarget
|
|
|
|
import prog8tests.helpers.ErrorReporterForTests
|
|
|
|
|
|
|
|
|
|
|
|
class TestGoldenRam: FunSpec({
|
|
|
|
|
|
|
|
val options = CompilationOptions(
|
|
|
|
OutputType.RAW,
|
|
|
|
CbmPrgLauncherType.NONE,
|
|
|
|
ZeropageType.FULL,
|
|
|
|
listOf((0x00u..0xffu)),
|
2023-11-02 22:45:10 +00:00
|
|
|
CompilationOptions.AllZeropageAllowed,
|
2022-12-02 22:58:21 +00:00
|
|
|
floats = true,
|
|
|
|
noSysInit = false,
|
|
|
|
compTarget = VMTarget(),
|
2024-11-01 23:13:23 +00:00
|
|
|
loadAddress = 999u,
|
|
|
|
memtopAddress = 0xffffu
|
2022-12-02 22:58:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
test("empty golden ram allocations") {
|
|
|
|
val errors = ErrorReporterForTests()
|
|
|
|
val golden = GoldenRam(options, UIntRange.EMPTY)
|
2024-12-05 20:48:51 +00:00
|
|
|
val result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-12-02 22:58:21 +00:00
|
|
|
result.expectError { "should not be able to allocate anything" }
|
|
|
|
}
|
|
|
|
|
|
|
|
test("regular golden ram allocations") {
|
|
|
|
val errors = ErrorReporterForTests()
|
|
|
|
val golden = GoldenRam(options, 0x400u until 0x800u)
|
|
|
|
|
2024-12-05 20:48:51 +00:00
|
|
|
var result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-12-02 22:58:21 +00:00
|
|
|
var alloc = result.getOrThrow()
|
|
|
|
alloc.size shouldBe 1
|
|
|
|
alloc.address shouldBe 0x400u
|
2024-12-05 20:48:51 +00:00
|
|
|
result = golden.allocate("test", DataType.forDt(BaseDataType.STR), 100, null, errors)
|
2022-12-02 22:58:21 +00:00
|
|
|
alloc = result.getOrThrow()
|
|
|
|
alloc.size shouldBe 100
|
|
|
|
alloc.address shouldBe 0x401u
|
|
|
|
|
|
|
|
repeat(461) {
|
2024-12-05 20:48:51 +00:00
|
|
|
result = golden.allocate("test", DataType.forDt(BaseDataType.UWORD), null, null, errors)
|
2022-12-02 22:58:21 +00:00
|
|
|
alloc = result.getOrThrow()
|
|
|
|
alloc.size shouldBe 2
|
|
|
|
}
|
|
|
|
|
2024-12-05 20:48:51 +00:00
|
|
|
result = golden.allocate("test", DataType.forDt(BaseDataType.UWORD), null, null, errors)
|
2022-12-02 22:58:21 +00:00
|
|
|
result.expectError { "just 1 more byte available" }
|
2024-12-05 20:48:51 +00:00
|
|
|
result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-12-02 22:58:21 +00:00
|
|
|
alloc = result.getOrThrow()
|
|
|
|
alloc.size shouldBe 1
|
|
|
|
alloc.address shouldBe golden.region.last
|
2024-12-05 20:48:51 +00:00
|
|
|
result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
|
2022-12-02 22:58:21 +00:00
|
|
|
result.expectError { "nothing more available" }
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|