mirror of
https://github.com/irmen/prog8.git
synced 2024-11-29 17:50:35 +00:00
b14012c9bc
# Conflicts: # codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt # codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt # codeGenIntermediate/src/prog8/codegen/intermediate/AssignmentGen.kt # codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt # compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt # compiler/test/TestZeropage.kt # compilerAst/src/prog8/ast/statements/AstStatements.kt # virtualmachine/src/prog8/vm/VirtualMachine.kt
64 lines
2.3 KiB
Kotlin
64 lines
2.3 KiB
Kotlin
package prog8tests.compiler
|
|
|
|
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)),
|
|
CompilationOptions.AllZeropageAllowed,
|
|
floats = true,
|
|
noSysInit = false,
|
|
compTarget = VMTarget(),
|
|
loadAddress = 999u,
|
|
memtopAddress = 0xffffu
|
|
)
|
|
|
|
test("empty golden ram allocations") {
|
|
val errors = ErrorReporterForTests()
|
|
val golden = GoldenRam(options, UIntRange.EMPTY)
|
|
val result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
|
|
result.expectError { "should not be able to allocate anything" }
|
|
}
|
|
|
|
test("regular golden ram allocations") {
|
|
val errors = ErrorReporterForTests()
|
|
val golden = GoldenRam(options, 0x400u until 0x800u)
|
|
|
|
var result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
|
|
var alloc = result.getOrThrow()
|
|
alloc.size shouldBe 1
|
|
alloc.address shouldBe 0x400u
|
|
result = golden.allocate("test", DataType.forDt(BaseDataType.STR), 100, null, errors)
|
|
alloc = result.getOrThrow()
|
|
alloc.size shouldBe 100
|
|
alloc.address shouldBe 0x401u
|
|
|
|
repeat(461) {
|
|
result = golden.allocate("test", DataType.forDt(BaseDataType.UWORD), null, null, errors)
|
|
alloc = result.getOrThrow()
|
|
alloc.size shouldBe 2
|
|
}
|
|
|
|
result = golden.allocate("test", DataType.forDt(BaseDataType.UWORD), null, null, errors)
|
|
result.expectError { "just 1 more byte available" }
|
|
result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
|
|
alloc = result.getOrThrow()
|
|
alloc.size shouldBe 1
|
|
alloc.address shouldBe golden.region.last
|
|
result = golden.allocate("test", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
|
|
result.expectError { "nothing more available" }
|
|
|
|
}
|
|
})
|