fixed the concurrent modification issue on zeropage when running unit tests in parallel, by not having machine targets be static objects

This commit is contained in:
Irmen de Jong 2022-02-06 21:29:06 +01:00
parent d2309b8114
commit 10de7dc1f9
26 changed files with 202 additions and 183 deletions

View File

@ -12,10 +12,14 @@ import prog8.compilerinterface.IMemSizer
import prog8.compilerinterface.IStringEncoding
object C128Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
override val name = "c128"
class C128Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
override val name = NAME
override val machine = C128MachineDefinition()
companion object {
const val NAME = "c128"
}
override fun asmsubArgsEvalOrder(sub: Subroutine): List<Int> =
asmsub6502ArgsEvalOrder(sub)
override fun asmsubArgsHaveRegisterClobberRisk(args: List<Expression>, paramRegisters: List<RegisterOrStatusflag>) =

View File

@ -12,10 +12,14 @@ import prog8.compilerinterface.IMemSizer
import prog8.compilerinterface.IStringEncoding
object C64Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
override val name = "c64"
class C64Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
override val name = NAME
override val machine = C64MachineDefinition()
companion object {
const val NAME = "c64"
}
override fun asmsubArgsEvalOrder(sub: Subroutine): List<Int> =
asmsub6502ArgsEvalOrder(sub)
override fun asmsubArgsHaveRegisterClobberRisk(args: List<Expression>, paramRegisters: List<RegisterOrStatusflag>) =

View File

@ -12,10 +12,14 @@ import prog8.compilerinterface.IMemSizer
import prog8.compilerinterface.IStringEncoding
object Cx16Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
override val name = "cx16"
class Cx16Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by CbmMemorySizer {
override val name = NAME
override val machine = CX16MachineDefinition()
companion object {
const val NAME = "cx16"
}
override fun asmsubArgsEvalOrder(sub: Subroutine): List<Int> =
asmsub6502ArgsEvalOrder(sub)
override fun asmsubArgsHaveRegisterClobberRisk(args: List<Expression>, paramRegisters: List<RegisterOrStatusflag>) =

View File

@ -44,7 +44,7 @@ private fun compileMain(args: Array<String>): Boolean {
val quietAssembler by cli.option(ArgType.Boolean, fullName = "quietasm", description = "don't print assembler output results")
val asmListfile by cli.option(ArgType.Boolean, fullName = "asmlist", description = "make the assembler produce a listing file as well")
val experimentalCodegen by cli.option(ArgType.Boolean, fullName = "expericodegen", description = "use experimental codegen")
val compilationTarget by cli.option(ArgType.String, fullName = "target", description = "target output of the compiler (one of '${C64Target.name}', '${C128Target.name}', '${Cx16Target.name}')").default(C64Target.name)
val compilationTarget by cli.option(ArgType.String, fullName = "target", description = "target output of the compiler (one of '${C64Target.NAME}', '${C128Target.NAME}', '${Cx16Target.NAME}')").default(C64Target.NAME)
val sourceDirs by cli.option(ArgType.String, fullName="srcdirs", description = "list of extra paths, separated with ${File.pathSeparator}, to search in for imported modules").multiple().delimiter(File.pathSeparator)
val moduleFiles by cli.argument(ArgType.String, fullName = "modules", description = "main module file(s) to compile").multiple(999)
@ -71,7 +71,7 @@ private fun compileMain(args: Array<String>): Boolean {
if(srcdirs.firstOrNull()!=".")
srcdirs.add(0, ".")
if (compilationTarget !in setOf(C64Target.name, C128Target.name, Cx16Target.name)) {
if (compilationTarget !in setOf(C64Target.NAME, C128Target.NAME, Cx16Target.NAME)) {
System.err.println("Invalid compilation target: $compilationTarget")
return false
}

View File

@ -54,9 +54,9 @@ fun compileProgram(args: CompilerArguments): CompilationResult {
val compTarget =
when(args.compilationTarget) {
C64Target.name -> C64Target
C128Target.name -> C128Target
Cx16Target.name -> Cx16Target
C64Target.NAME -> C64Target()
C128Target.NAME -> C128Target()
Cx16Target.NAME -> Cx16Target()
else -> throw IllegalArgumentException("invalid compilation target")
}
@ -233,7 +233,7 @@ fun determineCompilationOptions(program: Program, compTarget: ICompilationTarget
// error will be printed by the astchecker
}
if (zpType == ZeropageType.FLOATSAFE && compTarget.name == Cx16Target.name) {
if (zpType == ZeropageType.FLOATSAFE && compTarget.name == Cx16Target.NAME) {
System.err.println("Warning: zp option floatsafe changed to basicsafe for cx16 target")
zpType = ZeropageType.BASICSAFE
}

View File

@ -25,7 +25,7 @@ class TestAstChecks: FunSpec({
}
"""
val errors = ErrorReporterForTests(keepMessagesAfterReporting = true)
compileText(C64Target, true, text, writeAssembly = true, errors=errors).assertSuccess()
compileText(C64Target(), true, text, writeAssembly = true, errors=errors).assertSuccess()
errors.errors.size shouldBe 0
errors.warnings.size shouldBe 2
errors.warnings[0] shouldContain "converted to float"
@ -50,7 +50,7 @@ class TestAstChecks: FunSpec({
}
"""
val errors = ErrorReporterForTests()
compileText(C64Target, true, text, writeAssembly = true, errors=errors).assertFailure()
compileText(C64Target(), true, text, writeAssembly = true, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.warnings.size shouldBe 0
errors.errors[0] shouldContain ":7:28) assignment value is invalid"
@ -73,7 +73,7 @@ class TestAstChecks: FunSpec({
}
"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = false, errors=errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
errors.errors.filter { it.contains("missing &") }.size shouldBe 4
}
@ -95,6 +95,6 @@ class TestAstChecks: FunSpec({
}
}
"""
compileText(C64Target, false, text, writeAssembly = false).assertSuccess()
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
}
})

View File

@ -26,7 +26,7 @@ class TestCallgraph: FunSpec({
}
}
"""
val result = compileText(C64Target, false, sourcecode).assertSuccess()
val result = compileText(C64Target(), false, sourcecode).assertSuccess()
val graph = CallGraph(result.program)
graph.imports.size shouldBe 1
@ -67,7 +67,7 @@ class TestCallgraph: FunSpec({
}
}
"""
val result = compileText(C64Target, false, sourcecode).assertSuccess()
val result = compileText(C64Target(), false, sourcecode).assertSuccess()
val graph = CallGraph(result.program)
graph.imports.size shouldBe 1
@ -110,7 +110,7 @@ class TestCallgraph: FunSpec({
}
}
"""
val result = compileText(C64Target, false, sourcecode).assertSuccess()
val result = compileText(C64Target(), false, sourcecode).assertSuccess()
val graph = CallGraph(result.program)
graph.allIdentifiers.size shouldBeGreaterThanOrEqual 9
val empties = graph.allIdentifiers.keys.filter { it.nameInSource==listOf("empty") }

View File

@ -24,7 +24,7 @@ import prog8tests.helpers.compileText
class TestCompilerOnCharLit: FunSpec({
test("testCharLitAsRomsubArg") {
val platform = Cx16Target
val platform = Cx16Target()
val result = compileText(platform, false, """
main {
romsub ${"$"}FFD2 = chrout(ubyte ch @ A)
@ -47,7 +47,7 @@ class TestCompilerOnCharLit: FunSpec({
}
test("testCharVarAsRomsubArg") {
val platform = Cx16Target
val platform = Cx16Target()
val result = compileText(platform, false, """
main {
romsub ${"$"}FFD2 = chrout(ubyte ch @ A)
@ -87,7 +87,7 @@ class TestCompilerOnCharLit: FunSpec({
}
test("testCharConstAsRomsubArg") {
val platform = Cx16Target
val platform = Cx16Target()
val result = compileText(platform, false, """
main {
romsub ${"$"}FFD2 = chrout(ubyte ch @ A)

View File

@ -40,7 +40,7 @@ private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilat
private fun prepareTestFiles(source: String, optimize: Boolean, target: ICompilationTarget): Pair<String, Path> {
val searchIn = mutableListOf(examplesDir)
if (target == Cx16Target) {
if (target is Cx16Target) {
searchIn.add(0, assumeDirectory(examplesDir, "cx16"))
}
val filepath = searchIn.asSequence()
@ -72,9 +72,10 @@ class TestCompilerOnExamplesC64: FunSpec({
onlyC64.forEach {
val (source, optimize) = it
val (displayName, filepath) = prepareTestFiles(source, optimize, C64Target)
val target = C64Target()
val (displayName, filepath) = prepareTestFiles(source, optimize, target)
test(displayName) {
compileTheThing(filepath, optimize, C64Target).assertSuccess()
compileTheThing(filepath, optimize, target).assertSuccess()
}
}
})
@ -103,9 +104,10 @@ class TestCompilerOnExamplesCx16: FunSpec({
onlyCx16.forEach {
val (source, optimize) = it
val (displayName, filepath) = prepareTestFiles(source, optimize, Cx16Target)
val target = Cx16Target()
val (displayName, filepath) = prepareTestFiles(source, optimize, target)
test(displayName) {
compileTheThing(filepath, optimize, Cx16Target).assertSuccess()
compileTheThing(filepath, optimize, target).assertSuccess()
}
}
})
@ -141,13 +143,15 @@ class TestCompilerOnExamplesBothC64andCx16: FunSpec({
bothCx16AndC64.forEach {
val (source, optimize) = it
val (displayNameC64, filepathC64) = prepareTestFiles(source, optimize, C64Target)
val (displayNameCx16, filepathCx16) = prepareTestFiles(source, optimize, Cx16Target)
val c64target = C64Target()
val cx16target = Cx16Target()
val (displayNameC64, filepathC64) = prepareTestFiles(source, optimize, c64target)
val (displayNameCx16, filepathCx16) = prepareTestFiles(source, optimize, cx16target)
test(displayNameC64) {
compileTheThing(filepathC64, optimize, C64Target).assertSuccess()
compileTheThing(filepathC64, optimize, c64target).assertSuccess()
}
test(displayNameCx16) {
compileTheThing(filepathCx16, optimize, Cx16Target).assertSuccess()
compileTheThing(filepathCx16, optimize, cx16target).assertSuccess()
}
}
})

View File

@ -27,7 +27,7 @@ class TestCompilerOnImportsAndIncludes: FunSpec({
val filepath = assumeReadableFile(fixturesDir, "importFromSameFolder.p8")
assumeReadableFile(fixturesDir, "foo_bar.p8")
val platform = Cx16Target
val platform = Cx16Target()
val result = compileFile(platform, optimize = false, fixturesDir, filepath.name)
.assertSuccess()
@ -50,7 +50,7 @@ class TestCompilerOnImportsAndIncludes: FunSpec({
val filepath = assumeReadableFile(fixturesDir, "asmIncludeFromSameFolder.p8")
assumeReadableFile(fixturesDir, "foo_bar.asm")
val platform = Cx16Target
val platform = Cx16Target()
val result = compileFile(platform, optimize = false, fixturesDir, filepath.name)
.assertSuccess()
@ -76,7 +76,7 @@ class TestCompilerOnImportsAndIncludes: FunSpec({
val p8Path = assumeReadableFile(fixturesDir, "asmBinaryNonExisting.p8")
assumeNotExists(fixturesDir, "i_do_not_exist.bin")
compileFile(Cx16Target, false, p8Path.parent, p8Path.name, outputDir)
compileFile(Cx16Target(), false, p8Path.parent, p8Path.name, outputDir)
.assertFailure()
}
@ -84,7 +84,7 @@ class TestCompilerOnImportsAndIncludes: FunSpec({
val p8Path = assumeReadableFile(fixturesDir, "asmBinaryNonReadable.p8")
assumeDirectory(fixturesDir, "subFolder")
compileFile(Cx16Target, false, p8Path.parent, p8Path.name, outputDir)
compileFile(Cx16Target(), false, p8Path.parent, p8Path.name, outputDir)
.assertFailure()
}
@ -104,7 +104,7 @@ class TestCompilerOnImportsAndIncludes: FunSpec({
outputDir.normalize().toAbsolutePath() shouldNotBe workingDir.normalize().toAbsolutePath()
}
compileFile(Cx16Target, false, p8Path.parent, p8Path.name, outputDir)
compileFile(Cx16Target(), false, p8Path.parent, p8Path.name, outputDir)
.assertSuccess(
"argument to assembler directive .binary " +
"should be relative to the generated .asm file (in output dir), " +

View File

@ -27,7 +27,7 @@ import prog8tests.helpers.*
class TestCompilerOnRanges: FunSpec({
test("testUByteArrayInitializerWithRange_char_to_char") {
val platform = Cx16Target
val platform = Cx16Target()
val result = compileText(platform, false, """
main {
sub start() {
@ -58,7 +58,7 @@ class TestCompilerOnRanges: FunSpec({
}
test("testFloatArrayInitializerWithRange_char_to_char") {
val platform = C64Target
val platform = C64Target()
val result = compileText(platform, optimize = false, """
%import floats
main {
@ -93,7 +93,7 @@ class TestCompilerOnRanges: FunSpec({
val combos = cartesianProduct(
listOf("", "42", "41"), // sizeInDecl
listOf("%import floats", ""), // optEnableFloats
listOf(Cx16Target, C64Target), // platform
listOf(Cx16Target(), C64Target()), // platform
listOf(false, true) // optimize
)
@ -128,7 +128,7 @@ class TestCompilerOnRanges: FunSpec({
}
test("testForLoopWithRange_char_to_char") {
val platform = Cx16Target
val platform = Cx16Target()
val result = compileText(platform, optimize = true, """
main {
sub start() {
@ -162,7 +162,7 @@ class TestCompilerOnRanges: FunSpec({
}
test("testForLoopWithRange_bool_to_bool") {
val platform = Cx16Target
val platform = Cx16Target()
val result = compileText(platform, optimize = true, """
main {
sub start() {
@ -188,7 +188,7 @@ class TestCompilerOnRanges: FunSpec({
}
test("testForLoopWithRange_ubyte_to_ubyte") {
val platform = Cx16Target
val platform = Cx16Target()
val result = compileText(platform, optimize = true, """
main {
sub start() {
@ -215,7 +215,7 @@ class TestCompilerOnRanges: FunSpec({
test("testForLoopWithRange_str_downto_str") {
val errors = ErrorReporterForTests()
compileText(Cx16Target, true, """
compileText(Cx16Target(), true, """
main {
sub start() {
ubyte i
@ -231,7 +231,7 @@ class TestCompilerOnRanges: FunSpec({
}
test("testForLoopWithIterable_str") {
val result = compileText(Cx16Target, false, """
val result = compileText(Cx16Target(), false, """
main {
sub start() {
ubyte i
@ -263,7 +263,7 @@ class TestCompilerOnRanges: FunSpec({
}
test("range with negative step should be constvalue") {
val result = compileText(C64Target, false, """
val result = compileText(C64Target(), false, """
main {
sub start() {
ubyte[] array = 100 to 50 step -2
@ -283,7 +283,7 @@ class TestCompilerOnRanges: FunSpec({
}
test("range with start/end variables should be ok") {
val result = compileText(C64Target, false, """
val result = compileText(C64Target(), false, """
main {
sub start() {
byte from = 100
@ -302,7 +302,7 @@ class TestCompilerOnRanges: FunSpec({
test("for statement on all possible iterable expressions") {
compileText(C64Target, false, """
compileText(C64Target(), false, """
main {
sub start() {
ubyte xx
@ -343,7 +343,7 @@ class TestCompilerOnRanges: FunSpec({
}
test("if containment check on all possible iterable expressions") {
compileText(C64Target, false, """
compileText(C64Target(), false, """
main {
sub start() {
ubyte xx
@ -404,7 +404,7 @@ class TestCompilerOnRanges: FunSpec({
}
test("containment check in expressions") {
compileText(C64Target, false, """
compileText(C64Target(), false, """
main {
sub start() {
ubyte xx

View File

@ -46,7 +46,7 @@ class TestCompilerOptionSourcedirs: FunSpec({
quietAssembler = true,
asmListfile = false,
experimentalCodegen = false,
compilationTarget = Cx16Target.name,
compilationTarget = Cx16Target.NAME,
sourceDirs,
outputDir
)

View File

@ -18,7 +18,7 @@ import prog8tests.helpers.outputDir
class TestImportedModulesOrderAndOptions: FunSpec({
test("testImportedModuleOrderAndMainModuleCorrect") {
val result = compileText(C64Target, false, """
val result = compileText(C64Target(), false, """
%import textio
%import floats
@ -49,7 +49,7 @@ main {
}
test("testCompilationOptionsCorrectFromMain") {
val result = compileText(C64Target, false, """
val result = compileText(C64Target(), false, """
%import textio
%import floats
%zeropage dontuse
@ -62,7 +62,7 @@ main {
}
""").assertSuccess()
result.program.toplevelModule.name shouldStartWith "on_the_fly_test"
val options = determineCompilationOptions(result.program, C64Target)
val options = determineCompilationOptions(result.program, C64Target())
options.floats shouldBe true
options.zeropage shouldBe ZeropageType.DONTUSE
options.noSysInit shouldBe true
@ -85,7 +85,7 @@ main {
val filenameBase = "on_the_fly_test_" + sourceText.hashCode().toUInt().toString(16)
val filepath = outputDir.resolve("$filenameBase.p8")
filepath.toFile().writeText(sourceText)
val (program, options, importedfiles) = parseImports(filepath, errors, C64Target, emptyList())
val (program, options, importedfiles) = parseImports(filepath, errors, C64Target(), emptyList())
program.toplevelModule.name shouldBe filenameBase
withClue("all imports other than the test source must have been internal resources library files") {

View File

@ -21,6 +21,8 @@ import prog8tests.helpers.*
class TestMemory: FunSpec({
val c64target = C64Target()
fun wrapWithProgram(statements: List<Statement>): Program {
val program = Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
val subroutine = Subroutine("test", mutableListOf(), emptyList(), statements.toMutableList(), false, Position.DUMMY)
@ -35,49 +37,49 @@ class TestMemory: FunSpec({
var target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
var assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
memexpr = NumericLiteralValue.optimalInteger(0x1000, Position.DUMMY)
target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
memexpr = NumericLiteralValue.optimalInteger(0x9fff, Position.DUMMY)
target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
memexpr = NumericLiteralValue.optimalInteger(0xa000, Position.DUMMY)
target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
memexpr = NumericLiteralValue.optimalInteger(0xc000, Position.DUMMY)
target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
memexpr = NumericLiteralValue.optimalInteger(0xcfff, Position.DUMMY)
target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
memexpr = NumericLiteralValue.optimalInteger(0xeeee, Position.DUMMY)
target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
memexpr = NumericLiteralValue.optimalInteger(0xffff, Position.DUMMY)
target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
}
test("assign target in mapped IO space C64") {
@ -86,25 +88,25 @@ class TestMemory: FunSpec({
var target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
var assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe true
target.isIOAddress(c64target.machine) shouldBe true
memexpr = NumericLiteralValue.optimalInteger(0x0001, Position.DUMMY)
target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe true
target.isIOAddress(c64target.machine) shouldBe true
memexpr = NumericLiteralValue.optimalInteger(0xd000, Position.DUMMY)
target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe true
target.isIOAddress(c64target.machine) shouldBe true
memexpr = NumericLiteralValue.optimalInteger(0xdfff, Position.DUMMY)
target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe true
target.isIOAddress(c64target.machine) shouldBe true
}
fun createTestProgramForMemoryRefViaVar(address: UInt, vartype: VarDeclType): AssignTarget {
@ -118,17 +120,17 @@ class TestMemory: FunSpec({
test("identifier mapped to IO memory on C64") {
var target = createTestProgramForMemoryRefViaVar(0x1000u, VarDeclType.VAR)
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
target = createTestProgramForMemoryRefViaVar(0xd020u, VarDeclType.VAR)
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
target = createTestProgramForMemoryRefViaVar(0x1000u, VarDeclType.CONST)
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
target = createTestProgramForMemoryRefViaVar(0xd020u, VarDeclType.CONST)
target.isIOAddress(C64Target.machine) shouldBe true
target.isIOAddress(c64target.machine) shouldBe true
target = createTestProgramForMemoryRefViaVar(0x1000u, VarDeclType.MEMORY)
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
target = createTestProgramForMemoryRefViaVar(0xd020u, VarDeclType.MEMORY)
target.isIOAddress(C64Target.machine) shouldBe true
target.isIOAddress(c64target.machine) shouldBe true
}
test("memory expression mapped to IO memory on C64") {
@ -136,14 +138,14 @@ class TestMemory: FunSpec({
var target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
var assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
memexpr = PrefixExpression("+", NumericLiteralValue.optimalInteger(0xd020, Position.DUMMY), Position.DUMMY)
target = AssignTarget(null, null, DirectMemoryWrite(memexpr, Position.DUMMY), Position.DUMMY)
assign = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), AssignmentOrigin.USERCODE, Position.DUMMY)
wrapWithProgram(listOf(assign))
printProgram(target.definingModule.program)
target.isIOAddress(C64Target.machine) shouldBe true
target.isIOAddress(c64target.machine) shouldBe true
}
test("regular variable not in mapped IO ram on C64") {
@ -154,7 +156,7 @@ class TestMemory: FunSpec({
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
}
test("memory mapped variable not in mapped IO ram on C64") {
@ -166,7 +168,7 @@ class TestMemory: FunSpec({
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
}
test("memory mapped variable in mapped IO ram on C64") {
@ -178,7 +180,7 @@ class TestMemory: FunSpec({
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe true
target.isIOAddress(c64target.machine) shouldBe true
}
test("array not in mapped IO ram") {
@ -190,7 +192,7 @@ class TestMemory: FunSpec({
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
}
test("memory mapped array not in mapped IO ram") {
@ -203,7 +205,7 @@ class TestMemory: FunSpec({
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe false
target.isIOAddress(c64target.machine) shouldBe false
}
test("memory mapped array in mapped IO ram") {
@ -216,12 +218,12 @@ class TestMemory: FunSpec({
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe true
target.isIOAddress(c64target.machine) shouldBe true
}
test("memory() with spaces in name works") {
compileText(C64Target, false, """
compileText(C64Target(), false, """
main {
sub start() {
uword @shared mem = memory("a b c", 100, $100)
@ -231,7 +233,7 @@ class TestMemory: FunSpec({
}
test("memory() with invalid argument") {
compileText(C64Target, false, """
compileText(C64Target(), false, """
main {
sub start() {
uword @shared mem1 = memory("abc", 100, -2)

View File

@ -126,7 +126,7 @@ class TestNumbers: FunSpec({
}
"""
val errors = ErrorReporterForTests(keepMessagesAfterReporting = true)
compileText(C64Target, true, src, writeAssembly = false, errors=errors).assertSuccess()
compileText(C64Target(), true, src, writeAssembly = false, errors=errors).assertSuccess()
errors.errors.size shouldBe 0
errors.warnings.size shouldBe 2
errors.warnings[0] shouldContain "converted to float"
@ -146,7 +146,7 @@ class TestNumbers: FunSpec({
}
"""
val errors = ErrorReporterForTests()
compileText(C64Target, true, src, writeAssembly = false, errors=errors).assertFailure()
compileText(C64Target(), true, src, writeAssembly = false, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.warnings.size shouldBe 0
errors.errors[0] shouldContain "converted to float"
@ -163,7 +163,7 @@ class TestNumbers: FunSpec({
}
"""
val errors = ErrorReporterForTests()
compileText(C64Target, true, src, writeAssembly = false, errors=errors).assertFailure()
compileText(C64Target(), true, src, writeAssembly = false, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.warnings.size shouldBe 0
errors.errors[0] shouldContain "out of range"
@ -179,6 +179,6 @@ class TestNumbers: FunSpec({
}
}
"""
compileText(C64Target, true, src, writeAssembly = false).assertSuccess()
compileText(C64Target(), true, src, writeAssembly = false).assertSuccess()
}
})

View File

@ -35,7 +35,7 @@ class TestOptimization: FunSpec({
}
}
"""
val result = compileText(C64Target, true, sourcecode).assertSuccess()
val result = compileText(C64Target(), true, sourcecode).assertSuccess()
val toplevelModule = result.program.toplevelModule
val mainBlock = toplevelModule.statements.single() as Block
val startSub = mainBlock.statements.single() as Subroutine
@ -60,7 +60,7 @@ class TestOptimization: FunSpec({
}
}
"""
val result = compileText(C64Target, true, sourcecode).assertSuccess()
val result = compileText(C64Target(), true, sourcecode).assertSuccess()
val toplevelModule = result.program.toplevelModule
val mainBlock = toplevelModule.statements.single() as Block
val startSub = mainBlock.statements[0] as Subroutine
@ -119,7 +119,7 @@ class TestOptimization: FunSpec({
cx16.r7s = llw - 900 + 999
}
}"""
val result = compileText(C64Target, true, source, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), true, source, writeAssembly = false).assertSuccess()
// expected:
// uword load_location
// load_location = 12345
@ -172,7 +172,7 @@ class TestOptimization: FunSpec({
cx16.r4s = llw * 90 / 5 ; not optimized because of loss of integer division precision
}
}"""
val result = compileText(C64Target, true, source, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), true, source, writeAssembly = false).assertSuccess()
printProgram(result.program)
// expected:
// word llw
@ -229,7 +229,7 @@ class TestOptimization: FunSpec({
}
}
"""
val result = compileText(C64Target, false, sourcecode).assertSuccess()
val result = compileText(C64Target(), false, sourcecode).assertSuccess()
val mainsub = result.program.entrypoint
mainsub.statements.size shouldBe 10
val declTest = mainsub.statements[0] as VarDecl
@ -267,7 +267,7 @@ class TestOptimization: FunSpec({
}
}
"""
val result = compileText(C64Target, false, src, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), false, src, writeAssembly = false).assertSuccess()
// ww = ((( not bb as uword) or not ww) as uword)
val wwAssign = result.program.entrypoint.statements.last() as Assignment
@ -288,7 +288,7 @@ class TestOptimization: FunSpec({
}
}
"""
val result = compileText(C64Target, false, src, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), false, src, writeAssembly = false).assertSuccess()
// bb = (( not bb as uword) or not ww)
val bbAssign = result.program.entrypoint.statements.last() as Assignment
@ -300,7 +300,7 @@ class TestOptimization: FunSpec({
expr.right.inferType(result.program).getOrElse { fail("dt") } shouldBe DataType.UWORD
expr.inferType(result.program).getOrElse { fail("dt") } shouldBe DataType.UBYTE
val options = CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), false, true, C64Target, outputDir= outputDir)
val options = CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), false, true, C64Target(), outputDir= outputDir)
result.program.processAstBeforeAsmGeneration(options, ErrorReporterForTests())
// assignment is now split into:
@ -340,7 +340,7 @@ class TestOptimization: FunSpec({
}
}
"""
val result = compileText(C64Target, true, src, writeAssembly = true).assertSuccess()
val result = compileText(C64Target(), true, src, writeAssembly = true).assertSuccess()
/* turned into:
ubyte r
r = 0
@ -376,7 +376,7 @@ class TestOptimization: FunSpec({
}
}
"""
val result = compileText(C64Target, optimize=false, src, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), optimize=false, src, writeAssembly = false).assertSuccess()
val assignFF = result.program.entrypoint.statements.last() as Assignment
assignFF.isAugmentable shouldBe true
assignFF.target.identifier!!.nameInSource shouldBe listOf("ff")
@ -404,7 +404,7 @@ class TestOptimization: FunSpec({
}
}
"""
val result = compileText(C64Target, optimize=true, src, writeAssembly=false).assertSuccess()
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
result.program.entrypoint.statements.size shouldBe 7
val alldecls = result.program.entrypoint.allDefinedSymbols.toList()
alldecls.map { it.first } shouldBe listOf("unused_but_shared", "usedvar_only_written", "usedvar")
@ -427,7 +427,7 @@ class TestOptimization: FunSpec({
}
}
}"""
val result = compileText(C64Target, optimize=true, src, writeAssembly=false).assertSuccess()
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
printProgram(result.program)
result.program.entrypoint.statements.size shouldBe 3
val ifstmt = result.program.entrypoint.statements[0] as IfElse
@ -456,7 +456,7 @@ class TestOptimization: FunSpec({
z6 = z1+z6-5
}
}"""
val result = compileText(C64Target, optimize=true, src, writeAssembly=false).assertSuccess()
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
/* expected:
ubyte z1
z1 = 10
@ -523,7 +523,7 @@ class TestOptimization: FunSpec({
}
"""
val result = compileText(C64Target, optimize=true, src, writeAssembly=false).assertSuccess()
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
val stmts = result.program.entrypoint.statements
stmts.size shouldBe 6
val assign=stmts.last() as Assignment
@ -540,7 +540,7 @@ class TestOptimization: FunSpec({
}
}
"""
val result = compileText(C64Target, optimize=true, src, writeAssembly=false).assertSuccess()
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
val stmts = result.program.entrypoint.statements
stmts.size shouldBe 6
val assign=stmts.last() as Assignment
@ -559,7 +559,7 @@ class TestOptimization: FunSpec({
}
}
"""
val result = compileText(C64Target, optimize=true, src, writeAssembly=false).assertSuccess()
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
val stmts = result.program.entrypoint.statements
stmts.size shouldBe 10
stmts.filterIsInstance<VarDecl>().size shouldBe 5
@ -575,7 +575,7 @@ class TestOptimization: FunSpec({
}
"""
val errors = ErrorReporterForTests()
compileText(C64Target, optimize=true, src, writeAssembly=false, errors = errors).assertFailure()
compileText(C64Target(), optimize=true, src, writeAssembly=false, errors = errors).assertFailure()
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "type of value BYTE doesn't match target UBYTE"
errors.errors[1] shouldContain "out of range"
@ -594,7 +594,7 @@ class TestOptimization: FunSpec({
q=r
}
}"""
val result = compileText(C64Target, optimize=false, src, writeAssembly=true).assertSuccess()
val result = compileText(C64Target(), optimize=false, src, writeAssembly=true).assertSuccess()
result.program.entrypoint.statements.size shouldBe 11
result.program.entrypoint.statements.last() shouldBe instanceOf<Return>()
}
@ -612,7 +612,7 @@ class TestOptimization: FunSpec({
}
}
"""
val result = compileText(C64Target, optimize=true, src, writeAssembly=false).assertSuccess()
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
printProgram(result.program)
/* expected result:
uword yy
@ -642,7 +642,7 @@ class TestOptimization: FunSpec({
xx = xx+10 ; so this should not be changed into xx=10
}
}"""
val result = compileText(C64Target, optimize=true, src, writeAssembly=false).assertSuccess()
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
/*
expected result:
uword xx

View File

@ -42,7 +42,7 @@ class TestPipes: FunSpec({
}
}
"""
val result = compileText(C64Target, true, text, writeAssembly = true).assertSuccess()
val result = compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
val stmts = result.program.entrypoint.statements
stmts.size shouldBe 3
val pipef = stmts[0] as Pipe
@ -76,7 +76,7 @@ class TestPipes: FunSpec({
}
"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, errors=errors).assertFailure()
compileText(C64Target(), false, text, errors=errors).assertFailure()
errors.errors.size shouldBe 1
errors.errors[0] shouldContain "incompatible"
}
@ -104,7 +104,7 @@ class TestPipes: FunSpec({
}
}
"""
val result = compileText(C64Target, true, text, writeAssembly = true).assertSuccess()
val result = compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
val stmts = result.program.entrypoint.statements
stmts.size shouldBe 5
val assignf = stmts[1] as Assignment
@ -139,7 +139,7 @@ class TestPipes: FunSpec({
}
"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, errors=errors).assertFailure()
compileText(C64Target(), false, text, errors=errors).assertFailure()
errors.errors.size shouldBe 1
errors.errors[0] shouldContain "incompatible"
}

View File

@ -27,7 +27,7 @@ class TestScoping: FunSpec({
}
"""
val result = compileText(C64Target, false, src, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), false, src, writeAssembly = false).assertSuccess()
val module = result.program.toplevelModule
module.parent shouldBe instanceOf<GlobalNamespace>()
module.program shouldBeSameInstanceAs result.program
@ -46,7 +46,7 @@ class TestScoping: FunSpec({
}
"""
val result = compileText(C64Target, false, src, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), false, src, writeAssembly = false).assertSuccess()
val module = result.program.toplevelModule
val mainBlock = module.statements.single() as Block
val start = mainBlock.statements.single() as Subroutine
@ -120,7 +120,7 @@ class TestScoping: FunSpec({
}
"""
val result = compileText(C64Target, false, src, writeAssembly = true).assertSuccess()
val result = compileText(C64Target(), false, src, writeAssembly = true).assertSuccess()
val module = result.program.toplevelModule
val mainBlock = module.statements.single() as Block
val start = mainBlock.statements.single() as Subroutine
@ -145,7 +145,7 @@ class TestScoping: FunSpec({
}
}
"""
compileText(C64Target, false, text, writeAssembly = false).assertSuccess()
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
}
test("wrong subroutine call without qualified names") {
@ -161,7 +161,7 @@ class TestScoping: FunSpec({
}
"""
val errors= ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = false, errors = errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = false, errors = errors).assertFailure()
errors.errors.size shouldBe 1
errors.errors[0] shouldContain "undefined symbol: routine2"
}
@ -181,7 +181,7 @@ class TestScoping: FunSpec({
}
}
"""
compileText(C64Target, false, text, writeAssembly = false).assertSuccess()
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
}
test("wrong subroutine calls with qualified names (not from root)") {
@ -200,7 +200,7 @@ class TestScoping: FunSpec({
}
"""
val errors= ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = false, errors=errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
errors.errors.size shouldBe 4
errors.errors[0] shouldContain "undefined symbol: start.routine2"
errors.errors[1] shouldContain "undefined symbol: wrong.start.routine2"
@ -232,7 +232,7 @@ class TestScoping: FunSpec({
}
}
"""
compileText(C64Target, false, text, writeAssembly = false).assertSuccess()
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
}
test("wrong variables without qualified names") {
@ -264,7 +264,7 @@ class TestScoping: FunSpec({
}
"""
val errors= ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = false, errors=errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
errors.errors.size shouldBe 5
errors.errors[0] shouldContain "undefined symbol: v3"
errors.errors[1] shouldContain "undefined symbol: v4"
@ -297,7 +297,7 @@ class TestScoping: FunSpec({
}
}
"""
compileText(C64Target, false, text, writeAssembly = false).assertSuccess()
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
}
test("wrong variable refs with qualified names 1 (not from root)") {
@ -324,7 +324,7 @@ class TestScoping: FunSpec({
}
"""
val errors= ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = false, errors=errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
errors.errors.size shouldBe 5
errors.errors[0] shouldContain "undefined symbol: routine.value"
errors.errors[1] shouldContain "undefined symbol: routine.arg"
@ -362,7 +362,7 @@ class TestScoping: FunSpec({
}
}
"""
compileText(C64Target, false, text, writeAssembly = false).assertSuccess()
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
}
test("various wrong goto targets") {
@ -380,7 +380,7 @@ class TestScoping: FunSpec({
}
"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = false, errors = errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = false, errors = errors).assertFailure()
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "wrong address"
errors.errors[1] shouldContain "takes parameters"

View File

@ -44,7 +44,7 @@ class TestSubroutines: FunSpec({
}
}
"""
val result = compileText(C64Target, false, text, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
val module = result.program.toplevelModule
val mainBlock = module.statements.single() as Block
val asmfunc = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="asmfunc"}
@ -100,7 +100,7 @@ class TestSubroutines: FunSpec({
}
}
"""
val result = compileText(C64Target, false, text, writeAssembly = true).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
val module = result.program.toplevelModule
val mainBlock = module.statements.single() as Block
val asmfunc = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="asmfunc"}
@ -162,7 +162,7 @@ class TestSubroutines: FunSpec({
}
"""
val result = compileText(C64Target, false, text, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
val module = result.program.toplevelModule
val mainBlock = module.statements.single() as Block
val asmfunc = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="asmfunc"}
@ -188,7 +188,7 @@ class TestSubroutines: FunSpec({
"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = false, errors=errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "pass-by-reference type can't be used"
errors.errors[1] shouldContain "pass-by-reference type can't be used"
@ -212,7 +212,7 @@ class TestSubroutines: FunSpec({
}
"""
val result = compileText(C64Target, false, text, writeAssembly = true).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
val module = result.program.toplevelModule
val block = module.statements.single() as Block
val thing = block.statements.filterIsInstance<Subroutine>().single {it.name=="thing"}
@ -253,7 +253,7 @@ class TestSubroutines: FunSpec({
}
"""
val result = compileText(C64Target, false, text, writeAssembly = true).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
val module = result.program.toplevelModule
val block = module.statements.single() as Block
val thing = block.statements.filterIsInstance<Subroutine>().single {it.name=="thing"}
@ -284,7 +284,7 @@ class TestSubroutines: FunSpec({
"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = false, errors=errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "7:25) invalid number of arguments"
errors.errors[1] shouldContain "9:25) invalid number of arguments"
@ -305,7 +305,7 @@ class TestSubroutines: FunSpec({
"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = false, errors=errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "7:25) invalid number of arguments"
errors.errors[1] shouldContain "9:25) invalid number of arguments"
@ -325,7 +325,7 @@ class TestSubroutines: FunSpec({
"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = false, errors=errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "cannot use arguments"
errors.errors[1] shouldContain "invalid number of arguments"
@ -343,7 +343,7 @@ class TestSubroutines: FunSpec({
}
}
"""
val result = compileText(C64Target, false, text, writeAssembly = true).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
val stmts = result.program.entrypoint.statements
stmts.last() shouldBe instanceOf<Subroutine>()

View File

@ -32,7 +32,7 @@ class TestTypecasts: FunSpec({
}
}
"""
val result = compileText(C64Target, false, text, writeAssembly = true).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
result.program.entrypoint.statements.size shouldBe 13
}
@ -54,7 +54,7 @@ class TestTypecasts: FunSpec({
}
"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = true, errors=errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = true, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "can't cast"
errors.errors[1] shouldContain "can't cast"
@ -70,7 +70,7 @@ class TestTypecasts: FunSpec({
}
}"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, errors=errors).assertFailure()
compileText(C64Target(), false, text, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "can't cast"
errors.errors[1] shouldContain "can't cast"
@ -87,7 +87,7 @@ class TestTypecasts: FunSpec({
}
}"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, errors=errors).assertFailure()
compileText(C64Target(), false, text, errors=errors).assertFailure()
errors.errors.size shouldBe 1
errors.errors[0] shouldContain "in-place makes no sense"
}
@ -103,7 +103,7 @@ class TestTypecasts: FunSpec({
}
}"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, errors=errors).assertFailure()
compileText(C64Target(), false, text, errors=errors).assertFailure()
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "can't cast"
errors.errors[1] shouldContain "can't cast"
@ -152,7 +152,7 @@ class TestTypecasts: FunSpec({
}
}
"""
val result = compileText(C64Target, false, text, writeAssembly = true).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
printProgram(result.program)
val statements = result.program.entrypoint.statements
statements.size shouldBe 27
@ -180,7 +180,7 @@ class TestTypecasts: FunSpec({
}
}
}"""
val result = compileText(C64Target, false, text, writeAssembly = true).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
val statements = result.program.entrypoint.statements
statements.size shouldBe 14
}
@ -197,7 +197,7 @@ class TestTypecasts: FunSpec({
}
}
"""
compileText(C64Target, false, text, writeAssembly = true).assertSuccess()
compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
}
test("(u)byte extend to word parameters") {
@ -226,7 +226,7 @@ class TestTypecasts: FunSpec({
}}
}
}"""
compileText(C64Target, true, text, writeAssembly = true).assertSuccess()
compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
}
test("lsb msb used as args with word types") {
@ -245,6 +245,6 @@ class TestTypecasts: FunSpec({
}}
}
}"""
compileText(C64Target, true, text, writeAssembly = true).assertSuccess()
compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
}
})

View File

@ -59,9 +59,10 @@ class TestAbstractZeropage: FunSpec({
class TestC64Zeropage: FunSpec({
val errors = ErrorReporterForTests()
val c64target = C64Target()
test("testNames") {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, false, C64Target))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, false, c64target))
var result = zp.allocate(emptyList(), DataType.UBYTE, null, null, errors)
result.onFailure { fail(it.toString()) }
@ -75,33 +76,33 @@ class TestC64Zeropage: FunSpec({
}
test("testZpFloatEnable") {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, C64Target))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, c64target))
var result = zp.allocate(emptyList(), DataType.FLOAT, null, null, errors)
result.expectError { "should be allocation error due to disabled floats" }
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), true, false, C64Target))
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), true, false, c64target))
result = zp2.allocate(emptyList(), DataType.FLOAT, null, null, errors)
result.expectError { "should be allocation error due to disabled ZP use" }
val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true, false, C64Target))
val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true, false, c64target))
zp3.allocate(emptyList(), DataType.FLOAT, null, null, errors)
}
test("testZpModesWithFloats") {
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, C64Target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, false, C64Target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, false, C64Target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false, false, C64Target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, C64Target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true, false, C64Target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, c64target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, false, c64target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, false, c64target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false, false, c64target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, c64target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true, false, c64target))
shouldThrow<InternalCompilerException> {
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), true, false, C64Target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), true, false, c64target))
}
shouldThrow<InternalCompilerException> {
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), true, false, C64Target))
C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), true, false, c64target))
}
}
test("testZpDontuse") {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), false, false, C64Target))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), false, false, c64target))
println(zp.free)
zp.availableBytes() shouldBe 0
val result = zp.allocate(emptyList(), DataType.BYTE, null, null, errors)
@ -109,13 +110,13 @@ class TestC64Zeropage: FunSpec({
}
test("testFreeSpacesBytes") {
val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, C64Target))
val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, c64target))
zp1.availableBytes() shouldBe 18
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false, false, C64Target))
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false, false, c64target))
zp2.availableBytes() shouldBe 85
val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, false, C64Target))
val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, false, c64target))
zp3.availableBytes() shouldBe 125
val zp4 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, C64Target))
val zp4 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, c64target))
zp4.availableBytes() shouldBe 239
zp4.allocate(listOf("test"), DataType.UBYTE, null, null, errors)
zp4.availableBytes() shouldBe 238
@ -124,7 +125,7 @@ class TestC64Zeropage: FunSpec({
}
test("testReservedSpace") {
val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, C64Target))
val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, c64target))
zp1.availableBytes() shouldBe 239
50u shouldBeIn zp1.free
100u shouldBeIn zp1.free
@ -133,7 +134,7 @@ class TestC64Zeropage: FunSpec({
200u shouldBeIn zp1.free
255u shouldBeIn zp1.free
199u shouldBeIn zp1.free
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, listOf(50u .. 100u, 200u..255u), false, false, C64Target))
val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, listOf(50u .. 100u, 200u..255u), false, false, c64target))
zp2.availableBytes() shouldBe 139
50u shouldNotBeIn zp2.free
100u shouldNotBeIn zp2.free
@ -145,7 +146,7 @@ class TestC64Zeropage: FunSpec({
}
test("testBasicsafeAllocation") {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, C64Target))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, c64target))
zp.availableBytes() shouldBe 18
zp.hasByteAvailable() shouldBe true
zp.hasWordAvailable() shouldBe true
@ -167,7 +168,7 @@ class TestC64Zeropage: FunSpec({
}
test("testFullAllocation") {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, C64Target))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, c64target))
zp.availableBytes() shouldBe 239
zp.hasByteAvailable() shouldBe true
zp.hasWordAvailable() shouldBe true
@ -198,7 +199,7 @@ class TestC64Zeropage: FunSpec({
}
test("testEfficientAllocation") {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, C64Target))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, c64target))
zp.availableBytes() shouldBe 18
zp.allocate(emptyList(), DataType.WORD, null, null, errors ).getOrElse{throw it}.first shouldBe 0x04u
zp.allocate(emptyList(), DataType.UBYTE, null, null, errors).getOrElse{throw it}.first shouldBe 0x06u
@ -216,7 +217,7 @@ class TestC64Zeropage: FunSpec({
}
test("testReservedLocations") {
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, false, C64Target))
val zp = C64Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, false, c64target))
withClue("zp _B1 and _REG must be next to each other to create a word") {
zp.SCRATCH_B1 + 1u shouldBe zp.SCRATCH_REG
}
@ -226,20 +227,21 @@ class TestC64Zeropage: FunSpec({
class TestCx16Zeropage: FunSpec({
val errors = ErrorReporterForTests()
val cx16target = Cx16Target()
test("testReservedLocations") {
val zp = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, false, Cx16Target))
val zp = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, false, cx16target))
withClue("zp _B1 and _REG must be next to each other to create a word") {
zp.SCRATCH_B1 + 1u shouldBe zp.SCRATCH_REG
}
}
test("testFreeSpacesBytes") {
val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, Cx16Target))
val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, cx16target))
zp1.availableBytes() shouldBe 88
val zp2 = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, false, Cx16Target))
val zp2 = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, false, cx16target))
zp2.availableBytes() shouldBe 175
val zp3 = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, Cx16Target))
val zp3 = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, cx16target))
zp3.availableBytes() shouldBe 216
zp3.allocate(listOf("test"), DataType.UBYTE, null, null, errors)
zp3.availableBytes() shouldBe 215
@ -248,7 +250,7 @@ class TestCx16Zeropage: FunSpec({
}
test("testReservedSpace") {
val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, Cx16Target))
val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, cx16target))
zp1.availableBytes() shouldBe 216
0x22u shouldBeIn zp1.free
0x80u shouldBeIn zp1.free
@ -258,7 +260,7 @@ class TestCx16Zeropage: FunSpec({
}
test("preallocated zp vars") {
val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, Cx16Target))
val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, cx16target))
zp1.variables[listOf("test")] shouldBe null
zp1.variables[listOf("cx16", "r0")] shouldNotBe null
zp1.variables[listOf("cx16", "r15")] shouldNotBe null

View File

@ -908,7 +908,7 @@ class TestProg8Parser: FunSpec( {
}
}
"""
val result = compileText(C64Target, false, text, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
val start = result.program.entrypoint
val string = (start.statements[0] as VarDecl).value as StringLiteralValue
withClue("x-escapes are hacked to range 0x8000-0x80ff") {
@ -945,7 +945,7 @@ class TestProg8Parser: FunSpec( {
}
}
"""
val result = compileText(C64Target, false, text, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
val start = result.program.entrypoint
val containmentChecks = start.statements.takeLast(4)
(containmentChecks[0] as IfElse).condition shouldBe instanceOf<ContainmentCheck>()
@ -966,7 +966,7 @@ class TestProg8Parser: FunSpec( {
}
"""
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, writeAssembly = false, errors = errors).assertFailure()
compileText(C64Target(), false, text, writeAssembly = false, errors = errors).assertFailure()
errors.errors.size shouldBe 2
errors.errors[0] shouldContain "must be an iterable type"
errors.errors[1] shouldContain "datatype doesn't match"
@ -986,7 +986,7 @@ class TestProg8Parser: FunSpec( {
}
}
"""
val result = compileText(C64Target, false, text, writeAssembly = false).assertSuccess()
val result = compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
val stmt = result.program.entrypoint.statements
stmt.size shouldBe 12
val var1 = stmt[0] as VarDecl

View File

@ -77,7 +77,7 @@ class TestAsmGenSymbols: StringSpec({
fun createTestAsmGen(program: Program): AsmGen6502 {
val errors = ErrorReporterForTests()
val options = CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, true, C64Target)
val options = CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.FULL, emptyList(), false, true, C64Target())
options.compTarget.machine.zeropage = C64Zeropage(options)
val asmgen = AsmGen6502(program, errors, options)
return asmgen

View File

@ -24,7 +24,7 @@ class TestVariables: FunSpec({
}
}
"""
compileText(C64Target, true, text, writeAssembly = true).assertSuccess()
compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
}
test("array initialization with array literal") {
@ -35,7 +35,7 @@ class TestVariables: FunSpec({
}
}
"""
compileText(C64Target, true, text, writeAssembly = true).assertSuccess()
compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
}
test("array initialization with array var assignment") {
@ -48,6 +48,6 @@ class TestVariables: FunSpec({
ubyte[] values = [1,2,3]
}
"""
compileText(C64Target, false, text, writeAssembly = true).assertSuccess()
compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
}
})

View File

@ -85,7 +85,7 @@ internal fun generateAssembly(
program: Program,
options: CompilationOptions? = null
): IAssemblyProgram? {
val coptions = options ?: CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), true, true, C64Target, outputDir = outputDir)
val coptions = options ?: CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), true, true, C64Target(), outputDir = outputDir)
coptions.compTarget.machine.zeropage = C64Zeropage(coptions)
val asmgen = AsmGen6502(program, ErrorReporterForTests(), coptions)
return asmgen.compileToAssembly()

View File

@ -3,8 +3,7 @@ TODO
For next release
^^^^^^^^^^^^^^^^
fix the concurrent modification issue on zeropage when running unit tests in parallel -> don't use static objects anymore
...
Need help with
^^^^^^^^^^^^^^