From 0b5ddcdc9bcd8d24fa579aba8e851bc786b29245 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 29 Oct 2021 05:00:30 +0200 Subject: [PATCH] split out the code generator into own project submodule --- .idea/modules.xml | 1 + codeGeneration/build.gradle | 73 +++++++++++++++++++ codeGeneration/codeGeneration.iml | 18 +++++ .../prog8/compiler/target/AssemblyError.kt | 3 + .../src/prog8/compiler/target/C64Target.kt | 2 +- .../src/prog8/compiler/target/Cx16Target.kt | 2 +- .../target/c64/C64MachineDefinition.kt | 7 +- .../compiler/target/cbm/AssemblyProgram.kt | 22 ++++++ .../src/prog8/compiler/target/cbm/Petscii.kt | 4 +- .../compiler/target/cpu6502/codegen/AsmGen.kt | 22 +++--- .../target/cpu6502/codegen/AsmOptimizer.kt | 0 .../cpu6502/codegen/BuiltinFunctionsAsmGen.kt | 6 +- .../cpu6502/codegen/ExpressionsAsmGen.kt | 4 +- .../target/cpu6502/codegen/ForLoopsAsmGen.kt | 2 +- .../cpu6502/codegen/FunctionCallAsmGen.kt | 2 +- .../cpu6502/codegen/PostIncrDecrAsmGen.kt | 2 +- .../codegen/assignment/AsmAssignment.kt | 8 +- .../codegen/assignment/AssignmentAsmGen.kt | 14 ++-- .../assignment/AugmentableAssignmentAsmGen.kt | 26 ++++++- .../target/cx16/CX16MachineDefinition.kt | 4 +- codeGeneration/test/TestCodeGeneration.kt | 21 ++++++ .../src/prog8/optimizer/UnusedCodeRemover.kt | 1 + compiler/build.gradle | 1 + compiler/compiler.iml | 1 + compiler/src/prog8/compiler/AssemblyError.kt | 3 - compiler/src/prog8/compiler/Compiler.kt | 19 ----- compiler/src/prog8/compiler/ErrorReporting.kt | 48 ------------ .../compiler/astprocessing/AstChecker.kt | 7 +- .../astprocessing/AstIdentifiersChecker.kt | 2 +- .../astprocessing/StatementReorderer.kt | 2 +- .../compiler/astprocessing/TypecastsAdder.kt | 2 +- .../astprocessing/VerifyFunctionArgTypes.kt | 2 +- compiler/test/AsmgenTests.kt | 12 ++- compiler/test/ModuleImporterTests.kt | 1 + compiler/test/TestCallgraph.kt | 2 +- compiler/test/TestCompilerOnExamples.kt | 4 + .../test/TestCompilerOnImportsAndIncludes.kt | 1 + compiler/test/TestCompilerOnRanges.kt | 1 + compiler/test/TestCompilerOptionLibdirs.kt | 4 + .../TestImportedModulesOrderAndOptions.kt | 4 +- compiler/test/TestMemory.kt | 4 +- compiler/test/ZeropageTests.kt | 1 - compiler/test/helpers/compileXyz.kt | 5 +- compilerAst/test/TestAstToSourceText.kt | 6 +- compilerAst/test/TestProg8Parser.kt | 8 +- compilerAst/test/TestSourceCode.kt | 10 +-- compilerAst/test/TestSubroutines.kt | 2 +- compilerAst/test/ast/ProgramTests.kt | 6 +- compilerAst/test/helpers/DummyFunctions.kt | 2 +- compilerAst/test/helpers/DummyMemsizer.kt | 2 +- compilerAst/test/helpers/mapCombinations.kt | 4 +- compilerAst/test/helpers/paths.kt | 2 +- compilerAst/test/helpers_pathsTests.kt | 4 +- .../compilerinterface}/BuiltinFunctions.kt | 39 +++++----- .../src/prog8/compilerinterface}/CallGraph.kt | 3 +- .../{CompilerException.kt => Exceptions.kt} | 0 .../prog8/compilerinterface/IErrorReporter.kt | 44 +++++++++++ compilerInterfaces/test/TestAstExtensions.kt | 2 +- compilerInterfaces/test/TestZeropage.kt | 2 +- docs/source/todo.rst | 1 - settings.gradle | 1 + 61 files changed, 322 insertions(+), 186 deletions(-) create mode 100644 codeGeneration/build.gradle create mode 100644 codeGeneration/codeGeneration.iml create mode 100644 codeGeneration/src/prog8/compiler/target/AssemblyError.kt rename {compiler => codeGeneration}/src/prog8/compiler/target/C64Target.kt (96%) rename {compiler => codeGeneration}/src/prog8/compiler/target/Cx16Target.kt (96%) rename {compiler => codeGeneration}/src/prog8/compiler/target/c64/C64MachineDefinition.kt (97%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cbm/AssemblyProgram.kt (78%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cbm/Petscii.kt (99%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt (98%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt (100%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt (99%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt (99%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cpu6502/codegen/ForLoopsAsmGen.kt (99%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt (99%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cpu6502/codegen/PostIncrDecrAsmGen.kt (99%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cpu6502/codegen/assignment/AsmAssignment.kt (92%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt (99%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt (98%) rename {compiler => codeGeneration}/src/prog8/compiler/target/cx16/CX16MachineDefinition.kt (97%) create mode 100644 codeGeneration/test/TestCodeGeneration.kt delete mode 100644 compiler/src/prog8/compiler/AssemblyError.kt delete mode 100644 compiler/src/prog8/compiler/ErrorReporting.kt rename {compiler/src/prog8/compiler/functions => compilerInterfaces/src/prog8/compilerinterface}/BuiltinFunctions.kt (96%) rename {codeOptimizers/src/prog8/optimizer => compilerInterfaces/src/prog8/compilerinterface}/CallGraph.kt (99%) rename compilerInterfaces/src/prog8/compilerinterface/{CompilerException.kt => Exceptions.kt} (100%) diff --git a/.idea/modules.xml b/.idea/modules.xml index 0c4720f74..41548303d 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,6 +2,7 @@ + diff --git a/codeGeneration/build.gradle b/codeGeneration/build.gradle new file mode 100644 index 000000000..9598063ac --- /dev/null +++ b/codeGeneration/build.gradle @@ -0,0 +1,73 @@ + +plugins { + id 'java' + id 'application' + id "org.jetbrains.kotlin.jvm" +} + +targetCompatibility = 11 +sourceCompatibility = 11 + +repositories { + mavenLocal() + mavenCentral() + maven { url "https://kotlin.bintray.com/kotlinx" } +} + +dependencies { + implementation project(':compilerInterfaces') + implementation project(':compilerAst') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + // implementation "org.jetbrains.kotlin:kotlin-reflect" + implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12" + + 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 { + kotlinOptions { + jvmTarget = "11" + // verbose = true + // freeCompilerArgs += "-XXLanguage:+NewInference" + } +} + +compileTestKotlin { + kotlinOptions { + jvmTarget = "11" + } +} + +sourceSets { + main { + java { + srcDirs = ["${project.projectDir}/src"] + } + resources { + srcDirs = ["${project.projectDir}/res"] + } + } + test { + java { + srcDirs = ["${project.projectDir}/test"] + } + } +} + + +test { + // Enable JUnit 5 (Gradle 4.6+). + useJUnitPlatform() + + // Always run tests, even when nothing changed. + dependsOn 'cleanTest' + + // Show test results. + testLogging { + events "skipped", "failed" + } +} diff --git a/codeGeneration/codeGeneration.iml b/codeGeneration/codeGeneration.iml new file mode 100644 index 000000000..9a8fa347e --- /dev/null +++ b/codeGeneration/codeGeneration.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/codeGeneration/src/prog8/compiler/target/AssemblyError.kt b/codeGeneration/src/prog8/compiler/target/AssemblyError.kt new file mode 100644 index 000000000..236cfecad --- /dev/null +++ b/codeGeneration/src/prog8/compiler/target/AssemblyError.kt @@ -0,0 +1,3 @@ +package prog8.compiler.target + +class AssemblyError(msg: String) : RuntimeException(msg) diff --git a/compiler/src/prog8/compiler/target/C64Target.kt b/codeGeneration/src/prog8/compiler/target/C64Target.kt similarity index 96% rename from compiler/src/prog8/compiler/target/C64Target.kt rename to codeGeneration/src/prog8/compiler/target/C64Target.kt index 73109ded2..2d34161f0 100644 --- a/compiler/src/prog8/compiler/target/C64Target.kt +++ b/codeGeneration/src/prog8/compiler/target/C64Target.kt @@ -10,7 +10,7 @@ import prog8.compiler.target.cbm.Petscii import prog8.compilerinterface.* -internal object C64Target: ICompilationTarget { +object C64Target: ICompilationTarget { override val name = "c64" override val machine = C64MachineDefinition override fun encodeString(str: String, altEncoding: Boolean): List { diff --git a/compiler/src/prog8/compiler/target/Cx16Target.kt b/codeGeneration/src/prog8/compiler/target/Cx16Target.kt similarity index 96% rename from compiler/src/prog8/compiler/target/Cx16Target.kt rename to codeGeneration/src/prog8/compiler/target/Cx16Target.kt index 63ae67582..ce4aff247 100644 --- a/compiler/src/prog8/compiler/target/Cx16Target.kt +++ b/codeGeneration/src/prog8/compiler/target/Cx16Target.kt @@ -10,7 +10,7 @@ import prog8.compiler.target.cx16.CX16MachineDefinition import prog8.compilerinterface.* -internal object Cx16Target: ICompilationTarget { +object Cx16Target: ICompilationTarget { override val name = "cx16" override val machine = CX16MachineDefinition override fun encodeString(str: String, altEncoding: Boolean): List { diff --git a/compiler/src/prog8/compiler/target/c64/C64MachineDefinition.kt b/codeGeneration/src/prog8/compiler/target/c64/C64MachineDefinition.kt similarity index 97% rename from compiler/src/prog8/compiler/target/c64/C64MachineDefinition.kt rename to codeGeneration/src/prog8/compiler/target/c64/C64MachineDefinition.kt index 8c74f20c5..4b7fbbccf 100644 --- a/compiler/src/prog8/compiler/target/c64/C64MachineDefinition.kt +++ b/codeGeneration/src/prog8/compiler/target/c64/C64MachineDefinition.kt @@ -1,6 +1,5 @@ package prog8.compiler.target.c64 -import prog8.compiler.* import prog8.compiler.target.cbm.viceMonListPostfix import prog8.compilerinterface.* import java.io.IOException @@ -8,7 +7,7 @@ import java.nio.file.Path import kotlin.math.absoluteValue import kotlin.math.pow -internal object C64MachineDefinition: IMachineDefinition { +object C64MachineDefinition: IMachineDefinition { override val cpu = CpuType.CPU6502 @@ -75,7 +74,7 @@ internal object C64MachineDefinition: IMachineDefinition { "sta", "stx", "sty", "tas", "tax", "tay", "tsx", "txa", "txs", "tya", "xaa") - internal class C64Zeropage(options: CompilationOptions) : Zeropage(options) { + class C64Zeropage(options: CompilationOptions) : Zeropage(options) { override val SCRATCH_B1 = 0x02 // temp storage for a single byte override val SCRATCH_REG = 0x03 // temp storage for a register, must be B1+1 @@ -144,7 +143,7 @@ internal object C64MachineDefinition: IMachineDefinition { } } - internal data class Mflpt5(val b0: Short, val b1: Short, val b2: Short, val b3: Short, val b4: Short): + data class Mflpt5(val b0: Short, val b1: Short, val b2: Short, val b3: Short, val b4: Short): IMachineFloat { companion object { diff --git a/compiler/src/prog8/compiler/target/cbm/AssemblyProgram.kt b/codeGeneration/src/prog8/compiler/target/cbm/AssemblyProgram.kt similarity index 78% rename from compiler/src/prog8/compiler/target/cbm/AssemblyProgram.kt rename to codeGeneration/src/prog8/compiler/target/cbm/AssemblyProgram.kt index 5f2ba9ef0..6190d8669 100644 --- a/compiler/src/prog8/compiler/target/cbm/AssemblyProgram.kt +++ b/codeGeneration/src/prog8/compiler/target/cbm/AssemblyProgram.kt @@ -1,10 +1,17 @@ package prog8.compiler.target.cbm +import com.github.michaelbull.result.Ok +import com.github.michaelbull.result.Result +import com.github.michaelbull.result.mapError import prog8.compilerinterface.CompilationOptions import prog8.compilerinterface.IAssemblyProgram import prog8.compilerinterface.OutputType import prog8.compilerinterface.generatedLabelPrefix +import prog8.parser.SourceCode +import java.io.File import java.nio.file.Path +import kotlin.io.path.Path +import kotlin.io.path.isRegularFile internal const val viceMonListPostfix = "vice-mon-list" @@ -76,3 +83,18 @@ class AssemblyProgram( viceMonListFile.toFile().appendText(breakpoints.joinToString("\n") + "\n") } } + + +internal fun loadAsmIncludeFile(filename: String, source: SourceCode): Result { + return if (filename.startsWith(SourceCode.libraryFilePrefix)) { + return com.github.michaelbull.result.runCatching { + SourceCode.Resource("/prog8lib/${filename.substring(SourceCode.libraryFilePrefix.length)}").readText() + }.mapError { NoSuchFileException(File(filename)) } + } else { + val sib = Path(source.origin).resolveSibling(filename) + if (sib.isRegularFile()) + Ok(SourceCode.File(sib).readText()) + else + Ok(SourceCode.File(Path(filename)).readText()) + } +} diff --git a/compiler/src/prog8/compiler/target/cbm/Petscii.kt b/codeGeneration/src/prog8/compiler/target/cbm/Petscii.kt similarity index 99% rename from compiler/src/prog8/compiler/target/cbm/Petscii.kt rename to codeGeneration/src/prog8/compiler/target/cbm/Petscii.kt index a4deaea65..deea604a3 100644 --- a/compiler/src/prog8/compiler/target/cbm/Petscii.kt +++ b/codeGeneration/src/prog8/compiler/target/cbm/Petscii.kt @@ -1098,7 +1098,7 @@ object Petscii { fun decodePetscii(petscii: Iterable, lowercase: Boolean = false): String { return petscii.map { val code = it.toInt() - if(code<0 || code>=decodingPetsciiLowercase.size) + if(code<0 || code>= decodingPetsciiLowercase.size) throw CharConversionException("petscii $code out of range 0..${decodingPetsciiLowercase.size-1}") if(lowercase) decodingPetsciiLowercase[code] else decodingPetsciiUppercase[code] }.joinToString("") @@ -1137,7 +1137,7 @@ object Petscii { fun decodeScreencode(screencode: Iterable, lowercase: Boolean = false): String { return screencode.map { val code = it.toInt() - if(code<0 || code>=decodingScreencodeLowercase.size) + if(code<0 || code>= decodingScreencodeLowercase.size) throw CharConversionException("screencode $code out of range 0..${decodingScreencodeLowercase.size-1}") if (lowercase) decodingScreencodeLowercase[code] else decodingScreencodeUppercase[code] }.joinToString("") diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt similarity index 98% rename from compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt rename to codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt index 33ceb7a2e..86276c6fe 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt @@ -7,14 +7,12 @@ import prog8.ast.base.* import prog8.ast.expressions.* import prog8.ast.statements.* import prog8.compiler.* -import prog8.compiler.functions.BuiltinFunctions -import prog8.compiler.functions.FSignature import prog8.compiler.target.* import prog8.compiler.target.cbm.AssemblyProgram +import prog8.compiler.target.cbm.loadAsmIncludeFile import prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignment import prog8.compiler.target.cpu6502.codegen.assignment.AssignmentAsmGen import prog8.compilerinterface.* -import prog8.optimizer.CallGraph import prog8.parser.SourceCode import java.nio.file.Path import java.time.LocalDate @@ -24,7 +22,7 @@ import kotlin.io.path.Path import kotlin.math.absoluteValue -internal class AsmGen(private val program: Program, +class AsmGen(private val program: Program, val errors: IErrorReporter, val zeropage: Zeropage, val options: CompilationOptions, @@ -275,7 +273,7 @@ internal class AsmGen(private val program: Program, && variable.datatype != DataType.FLOAT && options.zeropage != ZeropageType.DONTUSE) { try { - val errors = ErrorReporter() + val errors = ErrorReporter() // TODO why not just use this.errors? then we can clean up the visibility of ErrorReporter class again too val address = zeropage.allocate(fullName, variable.datatype, null, errors) errors.report() out("${variable.name} = $address\t; auto zp ${variable.datatype}") @@ -500,7 +498,7 @@ internal class AsmGen(private val program: Program, return newName } - internal fun asmSymbolName(identifier: IdentifierReference): String { + fun asmSymbolName(identifier: IdentifierReference): String { if(identifier.nameInSource.size==2 && identifier.nameInSource[0]=="prog8_slabs") return identifier.nameInSource.joinToString(".") @@ -531,7 +529,7 @@ internal class AsmGen(private val program: Program, } } - internal fun asmVariableName(identifier: IdentifierReference) = + fun asmVariableName(identifier: IdentifierReference) = fixNameSymbols(identifier.nameInSource.joinToString(".")) private fun getScopedSymbolNameForTarget(actualName: String, target: Statement): MutableList { @@ -546,16 +544,16 @@ internal class AsmGen(private val program: Program, return scopedName } - internal fun asmSymbolName(regs: RegisterOrPair): String = + fun asmSymbolName(regs: RegisterOrPair): String = if (regs in Cx16VirtualRegisters) "cx16." + regs.toString().lowercase() else throw AssemblyError("no symbol name for register $regs") - internal fun asmSymbolName(name: String) = fixNameSymbols(name) - internal fun asmVariableName(name: String) = fixNameSymbols(name) - internal fun asmSymbolName(name: Iterable) = fixNameSymbols(name.joinToString(".")) - internal fun asmVariableName(name: Iterable) = fixNameSymbols(name.joinToString(".")) + fun asmSymbolName(name: String) = fixNameSymbols(name) + fun asmVariableName(name: String) = fixNameSymbols(name) + fun asmSymbolName(name: Iterable) = fixNameSymbols(name.joinToString(".")) + fun asmVariableName(name: Iterable) = fixNameSymbols(name.joinToString(".")) internal fun loadByteFromPointerIntoA(pointervar: IdentifierReference): String { diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt similarity index 100% rename from compiler/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt rename to codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt similarity index 99% rename from compiler/src/prog8/compiler/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt rename to codeGeneration/src/prog8/compiler/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt index 502d07aae..d7b32414f 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt @@ -10,11 +10,11 @@ import prog8.ast.statements.DirectMemoryWrite import prog8.ast.statements.FunctionCallStatement import prog8.ast.statements.Subroutine import prog8.ast.toHex -import prog8.compiler.AssemblyError import prog8.compilerinterface.CpuType -import prog8.compiler.functions.FSignature +import prog8.compiler.target.AssemblyError import prog8.compiler.target.Cx16Target import prog8.compiler.target.cpu6502.codegen.assignment.* +import prog8.compilerinterface.FSignature import prog8.compilerinterface.subroutineFloatEvalResultVar2 internal class BuiltinFunctionsAsmGen(private val program: Program, private val asmgen: AsmGen, private val assignAsmGen: AssignmentAsmGen) { @@ -1532,7 +1532,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val AsmAssignSource.fromAstSource(value, program, asmgen) } } - val tgt = AsmAssignTarget.fromRegisters(conv.reg, null, program, asmgen) + val tgt = AsmAssignTarget.fromRegisters(conv.reg!!, null, program, asmgen) val assign = AsmAssignment(src, tgt, false, program.memsizer, value.position) asmgen.translateNormalAssignment(assign) } diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt similarity index 99% rename from compiler/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt rename to codeGeneration/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt index 532d7ebb4..f21659338 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt @@ -7,9 +7,9 @@ import prog8.ast.statements.ArrayIndex import prog8.ast.statements.BuiltinFunctionStatementPlaceholder import prog8.ast.statements.Subroutine import prog8.ast.toHex -import prog8.compiler.AssemblyError import prog8.compilerinterface.CpuType -import prog8.compiler.functions.BuiltinFunctions +import prog8.compiler.target.AssemblyError +import prog8.compilerinterface.BuiltinFunctions import prog8.compilerinterface.subroutineFloatEvalResultVar1 import kotlin.math.absoluteValue diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/ForLoopsAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/ForLoopsAsmGen.kt similarity index 99% rename from compiler/src/prog8/compiler/target/cpu6502/codegen/ForLoopsAsmGen.kt rename to codeGeneration/src/prog8/compiler/target/cpu6502/codegen/ForLoopsAsmGen.kt index 4f5acdf66..f4e5586ce 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/ForLoopsAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/ForLoopsAsmGen.kt @@ -8,7 +8,7 @@ import prog8.ast.expressions.IdentifierReference import prog8.ast.expressions.RangeExpr import prog8.ast.statements.ForLoop import prog8.ast.toHex -import prog8.compiler.AssemblyError +import prog8.compiler.target.AssemblyError import prog8.compilerinterface.toConstantIntegerRange import kotlin.math.absoluteValue diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt similarity index 99% rename from compiler/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt rename to codeGeneration/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt index 8157d9598..b6826a8d9 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt @@ -9,7 +9,7 @@ import prog8.ast.statements.InlineAssembly import prog8.ast.statements.RegisterOrStatusflag import prog8.ast.statements.Subroutine import prog8.ast.statements.SubroutineParameter -import prog8.compiler.AssemblyError +import prog8.compiler.target.AssemblyError import prog8.compilerinterface.CpuType import prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignSource import prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignTarget diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/PostIncrDecrAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/PostIncrDecrAsmGen.kt similarity index 99% rename from compiler/src/prog8/compiler/target/cpu6502/codegen/PostIncrDecrAsmGen.kt rename to codeGeneration/src/prog8/compiler/target/cpu6502/codegen/PostIncrDecrAsmGen.kt index e8e9f81e8..e156c5869 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/PostIncrDecrAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/PostIncrDecrAsmGen.kt @@ -6,7 +6,7 @@ import prog8.ast.expressions.IdentifierReference import prog8.ast.expressions.NumericLiteralValue import prog8.ast.statements.PostIncrDecr import prog8.ast.toHex -import prog8.compiler.AssemblyError +import prog8.compiler.target.AssemblyError internal class PostIncrDecrAsmGen(private val program: Program, private val asmgen: AsmGen) { diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/assignment/AsmAssignment.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AsmAssignment.kt similarity index 92% rename from compiler/src/prog8/compiler/target/cpu6502/codegen/assignment/AsmAssignment.kt rename to codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AsmAssignment.kt index d120b750e..cf37b2f1d 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/assignment/AsmAssignment.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AsmAssignment.kt @@ -4,8 +4,8 @@ import prog8.ast.Program import prog8.ast.base.* import prog8.ast.expressions.* import prog8.ast.statements.* -import prog8.compiler.AssemblyError import prog8.compiler.IMemSizer +import prog8.compiler.target.AssemblyError import prog8.compiler.target.cpu6502.codegen.AsmGen @@ -61,9 +61,9 @@ internal class AsmAssignTarget(val kind: TargetStorageKind, throw AssemblyError("unknown dt") val dt = idt.getOr(DataType.UNDEFINED) when { - identifier != null -> AsmAssignTarget(TargetStorageKind.VARIABLE, program, asmgen, dt, assign.definingSubroutine, variableAsmName = asmgen.asmVariableName(identifier!!), origAstTarget = this) - arrayindexed != null -> AsmAssignTarget(TargetStorageKind.ARRAY, program, asmgen, dt, assign.definingSubroutine, array = arrayindexed, origAstTarget = this) - memoryAddress != null -> AsmAssignTarget(TargetStorageKind.MEMORY, program, asmgen, dt, assign.definingSubroutine, memory = memoryAddress, origAstTarget = this) + identifier != null -> AsmAssignTarget(prog8.compiler.target.cpu6502.codegen.assignment.TargetStorageKind.VARIABLE, program, asmgen, dt, assign.definingSubroutine, variableAsmName = asmgen.asmVariableName(identifier!!), origAstTarget = this) + arrayindexed != null -> AsmAssignTarget(prog8.compiler.target.cpu6502.codegen.assignment.TargetStorageKind.ARRAY, program, asmgen, dt, assign.definingSubroutine, array = arrayindexed, origAstTarget = this) + memoryAddress != null -> AsmAssignTarget(prog8.compiler.target.cpu6502.codegen.assignment.TargetStorageKind.MEMORY, program, asmgen, dt, assign.definingSubroutine, memory = memoryAddress, origAstTarget = this) else -> throw AssemblyError("weird target") } } diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt similarity index 99% rename from compiler/src/prog8/compiler/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt rename to codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt index 848917aaf..cf7a04a14 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AssignmentAsmGen.kt @@ -5,12 +5,12 @@ import prog8.ast.base.* import prog8.ast.expressions.* import prog8.ast.statements.* import prog8.ast.toHex -import prog8.compiler.AssemblyError +import prog8.compiler.target.AssemblyError import prog8.compilerinterface.CpuType -import prog8.compiler.functions.BuiltinFunctions -import prog8.compiler.functions.builtinFunctionReturnType import prog8.compiler.target.cpu6502.codegen.AsmGen import prog8.compiler.target.cpu6502.codegen.ExpressionsAsmGen +import prog8.compilerinterface.BuiltinFunctions +import prog8.compilerinterface.builtinFunctionReturnType internal class AssignmentAsmGen(private val program: Program, private val asmgen: AsmGen, @@ -21,7 +21,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen fun translate(assignment: Assignment) { val target = AsmAssignTarget.fromAstAssignment(assignment, program, asmgen) - val source = AsmAssignSource.fromAstSource(assignment.value, program, asmgen).adjustSignedUnsigned(target) + val source = AsmAssignSource.Companion.fromAstSource(assignment.value, program, asmgen).adjustSignedUnsigned(target) val assign = AsmAssignment(source, target, assignment.isAugmentable, program.memsizer, assignment.position) target.origAssign = assign @@ -1363,7 +1363,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen // these will be correctly typecasted from a byte to a word value if(target.register !in Cx16VirtualRegisters && target.register!=RegisterOrPair.AX && target.register!=RegisterOrPair.AY && target.register!=RegisterOrPair.XY) { - if(target.kind==TargetStorageKind.VARIABLE) { + if(target.kind== TargetStorageKind.VARIABLE) { val parts = target.asmVarname.split('.') if (parts.size != 2 || parts[0] != "cx16") require(target.datatype in ByteDatatypes) @@ -2158,14 +2158,14 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen } internal fun assignExpressionToRegister(expr: Expression, register: RegisterOrPair) { - val src = AsmAssignSource.fromAstSource(expr, program, asmgen) + val src = AsmAssignSource.Companion.fromAstSource(expr, program, asmgen) val tgt = AsmAssignTarget.fromRegisters(register, null, program, asmgen) val assign = AsmAssignment(src, tgt, false, program.memsizer, expr.position) translateNormalAssignment(assign) } internal fun assignExpressionToVariable(expr: Expression, asmVarName: String, dt: DataType, scope: Subroutine?) { - val src = AsmAssignSource.fromAstSource(expr, program, asmgen) + val src = AsmAssignSource.Companion.fromAstSource(expr, program, asmgen) val tgt = AsmAssignTarget(TargetStorageKind.VARIABLE, program, asmgen, dt, scope, variableAsmName = asmVarName) val assign = AsmAssignment(src, tgt, false, program.memsizer, expr.position) translateNormalAssignment(assign) diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt similarity index 98% rename from compiler/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt rename to codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt index 4c4ef447e..0231a69d6 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt @@ -5,7 +5,7 @@ import prog8.ast.base.* import prog8.ast.expressions.* import prog8.ast.statements.Subroutine import prog8.ast.toHex -import prog8.compiler.AssemblyError +import prog8.compiler.target.AssemblyError import prog8.compilerinterface.CpuType import prog8.compiler.target.cpu6502.codegen.AsmGen import prog8.compiler.target.cpu6502.codegen.ExpressionsAsmGen @@ -246,19 +246,37 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, indexVar!=null -> { when (target.datatype) { in ByteDatatypes -> { - val tgt = AsmAssignTarget.fromRegisters(RegisterOrPair.A, null, program, asmgen) + val tgt = + prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignTarget.fromRegisters( + RegisterOrPair.A, + null, + program, + asmgen + ) val assign = AsmAssignment(target.origAssign.source, tgt, false, program.memsizer, value.position) assignmentAsmGen.translateNormalAssignment(assign) assignmentAsmGen.assignRegisterByte(target, CpuRegister.A) } in WordDatatypes -> { - val tgt = AsmAssignTarget.fromRegisters(RegisterOrPair.AY, null, program, asmgen) + val tgt = + prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignTarget.fromRegisters( + RegisterOrPair.AY, + null, + program, + asmgen + ) val assign = AsmAssignment(target.origAssign.source, tgt, false, program.memsizer, value.position) assignmentAsmGen.translateNormalAssignment(assign) assignmentAsmGen.assignRegisterpairWord(target, RegisterOrPair.AY) } DataType.FLOAT -> { - val tgt = AsmAssignTarget.fromRegisters(RegisterOrPair.FAC1, null, program, asmgen) + val tgt = + prog8.compiler.target.cpu6502.codegen.assignment.AsmAssignTarget.fromRegisters( + RegisterOrPair.FAC1, + null, + program, + asmgen + ) val assign = AsmAssignment(target.origAssign.source, tgt, false, program.memsizer, value.position) assignmentAsmGen.translateNormalAssignment(assign) assignmentAsmGen.assignFAC1float(target) diff --git a/compiler/src/prog8/compiler/target/cx16/CX16MachineDefinition.kt b/codeGeneration/src/prog8/compiler/target/cx16/CX16MachineDefinition.kt similarity index 97% rename from compiler/src/prog8/compiler/target/cx16/CX16MachineDefinition.kt rename to codeGeneration/src/prog8/compiler/target/cx16/CX16MachineDefinition.kt index 99f89ad9d..4227f0224 100644 --- a/compiler/src/prog8/compiler/target/cx16/CX16MachineDefinition.kt +++ b/codeGeneration/src/prog8/compiler/target/cx16/CX16MachineDefinition.kt @@ -8,7 +8,7 @@ import java.io.IOException import java.nio.file.Path -internal object CX16MachineDefinition: IMachineDefinition { +object CX16MachineDefinition: IMachineDefinition { override val cpu = CpuType.CPU65c02 @@ -88,7 +88,7 @@ internal object CX16MachineDefinition: IMachineDefinition { "rmb", "smb", "stp", "wai") - internal class CX16Zeropage(options: CompilationOptions) : Zeropage(options) { + class CX16Zeropage(options: CompilationOptions) : Zeropage(options) { override val SCRATCH_B1 = 0x7a // temp storage for a single byte override val SCRATCH_REG = 0x7b // temp storage for a register, must be B1+1 diff --git a/codeGeneration/test/TestCodeGeneration.kt b/codeGeneration/test/TestCodeGeneration.kt new file mode 100644 index 000000000..dc068e3ce --- /dev/null +++ b/codeGeneration/test/TestCodeGeneration.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 TestCodeGeneration { + + @Test + @Disabled("for future implementation") + fun dummy() { + fail("dummy") + } + +} diff --git a/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt b/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt index 2845b7bb8..770215803 100644 --- a/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt +++ b/codeOptimizers/src/prog8/optimizer/UnusedCodeRemover.kt @@ -9,6 +9,7 @@ import prog8.ast.expressions.TypecastExpression import prog8.ast.statements.* import prog8.ast.walk.AstWalker import prog8.ast.walk.IAstModification +import prog8.compilerinterface.CallGraph import prog8.compilerinterface.ICompilationTarget import prog8.compilerinterface.IErrorReporter import prog8.compilerinterface.isInRegularRAMof diff --git a/compiler/build.gradle b/compiler/build.gradle index b4651dd9f..b063fde52 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -21,6 +21,7 @@ dependencies { implementation project(':compilerInterfaces') implementation project(':codeOptimizers') implementation project(':compilerAst') + implementation project(':codeGeneration') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" // implementation "org.jetbrains.kotlin:kotlin-reflect" implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.3' diff --git a/compiler/compiler.iml b/compiler/compiler.iml index 289d7a8ea..0a11b9cb7 100644 --- a/compiler/compiler.iml +++ b/compiler/compiler.iml @@ -24,5 +24,6 @@ + \ No newline at end of file diff --git a/compiler/src/prog8/compiler/AssemblyError.kt b/compiler/src/prog8/compiler/AssemblyError.kt deleted file mode 100644 index 123d6c13b..000000000 --- a/compiler/src/prog8/compiler/AssemblyError.kt +++ /dev/null @@ -1,3 +0,0 @@ -package prog8.compiler - -internal class AssemblyError(msg: String) : RuntimeException(msg) diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 7394618ea..9bc5fe28d 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -10,7 +10,6 @@ import prog8.ast.expressions.Expression import prog8.ast.expressions.NumericLiteralValue import prog8.ast.statements.Directive import prog8.compiler.astprocessing.* -import prog8.compiler.functions.* import prog8.compiler.target.C64Target import prog8.compiler.target.Cx16Target import prog8.compiler.target.cpu6502.codegen.AsmGen @@ -18,12 +17,8 @@ import prog8.compilerinterface.* import prog8.optimizer.* import prog8.parser.ParseError import prog8.parser.ParsingFailedError -import prog8.parser.SourceCode -import prog8.parser.SourceCode.Companion.libraryFilePrefix -import java.io.File import java.nio.file.Path import kotlin.io.path.Path -import kotlin.io.path.isRegularFile import kotlin.io.path.nameWithoutExtension import kotlin.system.measureTimeMillis @@ -351,20 +346,6 @@ fun printAst(programAst: Program) { println() } -internal fun loadAsmIncludeFile(filename: String, source: SourceCode): Result { - return if (filename.startsWith(libraryFilePrefix)) { - return runCatching { - SourceCode.Resource("/prog8lib/${filename.substring(libraryFilePrefix.length)}").readText() - }.mapError { NoSuchFileException(File(filename)) } - } else { - val sib = Path(source.origin).resolveSibling(filename) - if (sib.isRegularFile()) - Ok(SourceCode.File(sib).readText()) - else - Ok(SourceCode.File(Path(filename)).readText()) - } -} - internal fun asmGeneratorFor( compTarget: ICompilationTarget, program: Program, diff --git a/compiler/src/prog8/compiler/ErrorReporting.kt b/compiler/src/prog8/compiler/ErrorReporting.kt deleted file mode 100644 index 1e15c2f55..000000000 --- a/compiler/src/prog8/compiler/ErrorReporting.kt +++ /dev/null @@ -1,48 +0,0 @@ -package prog8.compiler - -import prog8.ast.base.Position -import prog8.compilerinterface.IErrorReporter - - -internal class ErrorReporter: IErrorReporter { - private enum class MessageSeverity { - WARNING, - ERROR - } - private class CompilerMessage(val severity: MessageSeverity, val message: String, val position: Position) - - private val messages = mutableListOf() - private val alreadyReportedMessages = mutableSetOf() - - override fun err(msg: String, position: Position) { - messages.add(CompilerMessage(MessageSeverity.ERROR, msg, position)) - } - override fun warn(msg: String, position: Position) { - messages.add(CompilerMessage(MessageSeverity.WARNING, msg, position)) - } - - override fun report() { - var numErrors = 0 - var numWarnings = 0 - messages.forEach { - when(it.severity) { - MessageSeverity.ERROR -> System.err.print("\u001b[91m") // bright red - MessageSeverity.WARNING -> System.err.print("\u001b[93m") // bright yellow - } - val msg = "${it.position.toClickableStr()} ${it.severity} ${it.message}".trim() - if(msg !in alreadyReportedMessages) { - System.err.println(msg) - alreadyReportedMessages.add(msg) - when(it.severity) { - MessageSeverity.WARNING -> numWarnings++ - MessageSeverity.ERROR -> numErrors++ - } - } - System.err.print("\u001b[0m") // reset color - } - messages.clear() - finalizeNumErrors(numErrors, numWarnings) - } - - override fun noErrors() = messages.none { it.severity==MessageSeverity.ERROR } -} diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index dface238f..2ac7c5050 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -8,12 +8,7 @@ import prog8.ast.base.* import prog8.ast.expressions.* import prog8.ast.statements.* import prog8.ast.walk.IAstVisitor -import prog8.compilerinterface.CompilationOptions -import prog8.compilerinterface.ICompilationTarget -import prog8.compilerinterface.IErrorReporter -import prog8.compilerinterface.ZeropageType -import prog8.compiler.functions.BuiltinFunctions -import prog8.compiler.functions.builtinFunctionReturnType +import prog8.compilerinterface.* import java.io.CharConversionException import java.io.File import java.util.* diff --git a/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt index cbabaaa96..9fc2462c7 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt @@ -4,9 +4,9 @@ import prog8.ast.base.Position import prog8.ast.expressions.StringLiteralValue import prog8.ast.statements.* import prog8.ast.walk.IAstVisitor +import prog8.compilerinterface.BuiltinFunctions import prog8.compilerinterface.ICompilationTarget import prog8.compilerinterface.IErrorReporter -import prog8.compiler.functions.BuiltinFunctions internal class AstIdentifiersChecker(private val errors: IErrorReporter, private val compTarget: ICompilationTarget) : IAstVisitor { private var blocks = mutableMapOf() diff --git a/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt b/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt index b4b9892ec..428548799 100644 --- a/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt +++ b/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt @@ -10,8 +10,8 @@ import prog8.ast.expressions.* import prog8.ast.statements.* import prog8.ast.walk.AstWalker import prog8.ast.walk.IAstModification +import prog8.compilerinterface.BuiltinFunctions import prog8.compilerinterface.IErrorReporter -import prog8.compiler.functions.BuiltinFunctions internal class StatementReorderer(val program: Program, val errors: IErrorReporter) : AstWalker() { diff --git a/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt b/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt index 3d0529d3e..210703db0 100644 --- a/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt +++ b/compiler/src/prog8/compiler/astprocessing/TypecastsAdder.kt @@ -8,8 +8,8 @@ import prog8.ast.expressions.* import prog8.ast.statements.* import prog8.ast.walk.AstWalker import prog8.ast.walk.IAstModification +import prog8.compilerinterface.BuiltinFunctions import prog8.compilerinterface.IErrorReporter -import prog8.compiler.functions.BuiltinFunctions class TypecastsAdder(val program: Program, val errors: IErrorReporter) : AstWalker() { diff --git a/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt b/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt index 58bbf09d9..8f342ad82 100644 --- a/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt +++ b/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt @@ -8,8 +8,8 @@ import prog8.ast.expressions.FunctionCall import prog8.ast.expressions.TypecastExpression import prog8.ast.statements.* import prog8.ast.walk.IAstVisitor +import prog8.compilerinterface.BuiltinFunctions import prog8.compilerinterface.CompilerException -import prog8.compiler.functions.BuiltinFunctions class VerifyFunctionArgTypes(val program: Program) : IAstVisitor { diff --git a/compiler/test/AsmgenTests.kt b/compiler/test/AsmgenTests.kt index ffed6a188..7f253bfee 100644 --- a/compiler/test/AsmgenTests.kt +++ b/compiler/test/AsmgenTests.kt @@ -14,19 +14,17 @@ import prog8.ast.expressions.AddressOf import prog8.ast.expressions.IdentifierReference import prog8.ast.expressions.NumericLiteralValue import prog8.ast.statements.* -import prog8.compiler.* import prog8.compiler.target.C64Target import prog8.compiler.target.c64.C64MachineDefinition import prog8.compiler.target.cpu6502.codegen.AsmGen -import prog8.compilerinterface.CompilationOptions -import prog8.compilerinterface.LauncherType -import prog8.compilerinterface.OutputType -import prog8.compilerinterface.ZeropageType +import prog8.compilerinterface.* import prog8.parser.SourceCode -import prog8tests.helpers.DummyFunctions -import prog8tests.helpers.DummyMemsizer +import prog8tests.ast.helpers.DummyFunctions +import prog8tests.ast.helpers.DummyMemsizer import java.nio.file.Path +// TODO move to codegen project, readjust symbol protection levels + @TestInstance(TestInstance.Lifecycle.PER_CLASS) class TestAsmGen6502 { diff --git a/compiler/test/ModuleImporterTests.kt b/compiler/test/ModuleImporterTests.kt index ea3677297..1eeb04d44 100644 --- a/compiler/test/ModuleImporterTests.kt +++ b/compiler/test/ModuleImporterTests.kt @@ -13,6 +13,7 @@ import prog8.compilerinterface.IErrorReporter import prog8.compiler.ModuleImporter import prog8.parser.ParseError import prog8.parser.SourceCode +import prog8tests.ast.helpers.* import prog8tests.helpers.* import kotlin.io.path.* import kotlin.test.assertContains diff --git a/compiler/test/TestCallgraph.kt b/compiler/test/TestCallgraph.kt index 16e9bf6a1..43c79bbd9 100644 --- a/compiler/test/TestCallgraph.kt +++ b/compiler/test/TestCallgraph.kt @@ -5,7 +5,7 @@ import org.junit.jupiter.api.TestInstance import prog8.ast.statements.Block import prog8.ast.statements.Subroutine import prog8.compiler.target.C64Target -import prog8.optimizer.CallGraph +import prog8.compilerinterface.CallGraph import prog8tests.helpers.assertSuccess import prog8tests.helpers.compileText import kotlin.test.assertEquals diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index 6aac841f6..2af63c392 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -8,6 +8,10 @@ import prog8.compilerinterface.ICompilationTarget import prog8.compiler.compileProgram import prog8.compiler.target.C64Target import prog8.compiler.target.Cx16Target +import prog8tests.ast.helpers.assumeDirectory +import prog8tests.ast.helpers.mapCombinations +import prog8tests.ast.helpers.outputDir +import prog8tests.ast.helpers.workingDir import prog8tests.helpers.* import kotlin.io.path.absolute import kotlin.io.path.exists diff --git a/compiler/test/TestCompilerOnImportsAndIncludes.kt b/compiler/test/TestCompilerOnImportsAndIncludes.kt index 2e06da1d0..ffe38a113 100644 --- a/compiler/test/TestCompilerOnImportsAndIncludes.kt +++ b/compiler/test/TestCompilerOnImportsAndIncludes.kt @@ -8,6 +8,7 @@ import prog8.ast.expressions.StringLiteralValue import prog8.ast.statements.FunctionCallStatement import prog8.ast.statements.Label import prog8.compiler.target.Cx16Target +import prog8tests.ast.helpers.* import prog8tests.helpers.* import kotlin.io.path.name import kotlin.test.assertEquals diff --git a/compiler/test/TestCompilerOnRanges.kt b/compiler/test/TestCompilerOnRanges.kt index d648eac61..579004202 100644 --- a/compiler/test/TestCompilerOnRanges.kt +++ b/compiler/test/TestCompilerOnRanges.kt @@ -13,6 +13,7 @@ import prog8.compilerinterface.size import prog8.compiler.target.C64Target import prog8.compiler.target.Cx16Target import prog8.compilerinterface.toConstantIntegerRange +import prog8tests.ast.helpers.mapCombinations import prog8tests.helpers.* import kotlin.test.assertContains import kotlin.test.assertEquals diff --git a/compiler/test/TestCompilerOptionLibdirs.kt b/compiler/test/TestCompilerOptionLibdirs.kt index e81108dbd..92370aa26 100644 --- a/compiler/test/TestCompilerOptionLibdirs.kt +++ b/compiler/test/TestCompilerOptionLibdirs.kt @@ -6,6 +6,10 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import prog8.compiler.compileProgram import prog8.compiler.target.Cx16Target +import prog8tests.ast.helpers.assumeReadableFile +import prog8tests.ast.helpers.fixturesDir +import prog8tests.ast.helpers.outputDir +import prog8tests.ast.helpers.workingDir import prog8tests.helpers.* import java.nio.file.Path import kotlin.io.path.absolute diff --git a/compiler/test/TestImportedModulesOrderAndOptions.kt b/compiler/test/TestImportedModulesOrderAndOptions.kt index ec9aa9e4b..a85eb619c 100644 --- a/compiler/test/TestImportedModulesOrderAndOptions.kt +++ b/compiler/test/TestImportedModulesOrderAndOptions.kt @@ -3,14 +3,14 @@ package prog8tests import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import prog8.ast.internedStringsModuleName -import prog8.compiler.ErrorReporter import prog8.compilerinterface.ZeropageType import prog8.compiler.determineCompilationOptions import prog8.compiler.parseImports import prog8.compiler.target.C64Target +import prog8.compilerinterface.ErrorReporter +import prog8tests.ast.helpers.outputDir import prog8tests.helpers.assertSuccess import prog8tests.helpers.compileText -import prog8tests.helpers.outputDir import kotlin.test.assertEquals import kotlin.test.assertTrue diff --git a/compiler/test/TestMemory.kt b/compiler/test/TestMemory.kt index 49a5c5323..3524a5b95 100644 --- a/compiler/test/TestMemory.kt +++ b/compiler/test/TestMemory.kt @@ -15,8 +15,8 @@ import prog8.ast.statements.* import prog8.compilerinterface.isInRegularRAMof import prog8.compiler.target.C64Target import prog8.parser.SourceCode -import prog8tests.helpers.DummyFunctions -import prog8tests.helpers.DummyMemsizer +import prog8tests.ast.helpers.DummyFunctions +import prog8tests.ast.helpers.DummyMemsizer import kotlin.test.assertFalse import kotlin.test.assertTrue diff --git a/compiler/test/ZeropageTests.kt b/compiler/test/ZeropageTests.kt index 6b341e817..5e9075a9d 100644 --- a/compiler/test/ZeropageTests.kt +++ b/compiler/test/ZeropageTests.kt @@ -3,7 +3,6 @@ package prog8tests import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import prog8.ast.base.DataType -import prog8.compiler.* import prog8.compiler.target.C64Target import prog8.compiler.target.Cx16Target import prog8.compiler.target.c64.C64MachineDefinition.C64Zeropage diff --git a/compiler/test/helpers/compileXyz.kt b/compiler/test/helpers/compileXyz.kt index 699df20f8..33111d94c 100644 --- a/compiler/test/helpers/compileXyz.kt +++ b/compiler/test/helpers/compileXyz.kt @@ -1,8 +1,11 @@ package prog8tests.helpers import prog8.compiler.* +import prog8.compilerinterface.ErrorReporter import prog8.compilerinterface.ICompilationTarget import prog8.compilerinterface.IErrorReporter +import prog8tests.ast.helpers.assumeReadableFile +import prog8tests.ast.helpers.outputDir import java.nio.file.Path import kotlin.io.path.name import kotlin.test.assertFalse @@ -28,7 +31,7 @@ internal fun compileFile( optimize: Boolean, fileDir: Path, fileName: String, - outputDir: Path = prog8tests.helpers.outputDir, + outputDir: Path = prog8tests.ast.helpers.outputDir, errors: IErrorReporter? = null, writeAssembly: Boolean = true ) : CompilationResult { diff --git a/compilerAst/test/TestAstToSourceText.kt b/compilerAst/test/TestAstToSourceText.kt index 7532dd315..20ccc0f40 100644 --- a/compilerAst/test/TestAstToSourceText.kt +++ b/compilerAst/test/TestAstToSourceText.kt @@ -1,4 +1,4 @@ -package prog8tests +package prog8tests.ast import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance @@ -9,8 +9,8 @@ import prog8.ast.internedStringsModuleName import prog8.parser.ParseError import prog8.parser.Prog8Parser.parseModule import prog8.parser.SourceCode -import prog8tests.helpers.DummyFunctions -import prog8tests.helpers.DummyMemsizer +import prog8tests.ast.helpers.DummyFunctions +import prog8tests.ast.helpers.DummyMemsizer import kotlin.test.assertContains diff --git a/compilerAst/test/TestProg8Parser.kt b/compilerAst/test/TestProg8Parser.kt index 5d9f656d7..4c442f263 100644 --- a/compilerAst/test/TestProg8Parser.kt +++ b/compilerAst/test/TestProg8Parser.kt @@ -1,4 +1,4 @@ -package prog8tests +package prog8tests.ast import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test @@ -16,9 +16,9 @@ import prog8.ast.statements.* import prog8.parser.ParseError import prog8.parser.Prog8Parser.parseModule import prog8.parser.SourceCode -import prog8tests.helpers.assumeNotExists -import prog8tests.helpers.assumeReadableFile -import prog8tests.helpers.fixturesDir +import prog8tests.ast.helpers.assumeNotExists +import prog8tests.ast.helpers.assumeReadableFile +import prog8tests.ast.helpers.fixturesDir import kotlin.io.path.Path import kotlin.io.path.isRegularFile import kotlin.io.path.name diff --git a/compilerAst/test/TestSourceCode.kt b/compilerAst/test/TestSourceCode.kt index dec7ecd7b..204e9089a 100644 --- a/compilerAst/test/TestSourceCode.kt +++ b/compilerAst/test/TestSourceCode.kt @@ -1,4 +1,4 @@ -package prog8tests +package prog8tests.ast import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.core.StringStartsWith @@ -6,10 +6,10 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import prog8.parser.SourceCode import prog8.parser.SourceCode.Companion.libraryFilePrefix -import prog8tests.helpers.assumeNotExists -import prog8tests.helpers.assumeReadableFile -import prog8tests.helpers.fixturesDir -import prog8tests.helpers.resourcesDir +import prog8tests.ast.helpers.assumeNotExists +import prog8tests.ast.helpers.assumeReadableFile +import prog8tests.ast.helpers.fixturesDir +import prog8tests.ast.helpers.resourcesDir import kotlin.io.path.Path import kotlin.test.* diff --git a/compilerAst/test/TestSubroutines.kt b/compilerAst/test/TestSubroutines.kt index aee7b2fde..9d53ebdf8 100644 --- a/compilerAst/test/TestSubroutines.kt +++ b/compilerAst/test/TestSubroutines.kt @@ -1,4 +1,4 @@ -package prog8tests +package prog8tests.ast import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance diff --git a/compilerAst/test/ast/ProgramTests.kt b/compilerAst/test/ast/ProgramTests.kt index 9a9e13c3a..6694ab6fa 100644 --- a/compilerAst/test/ast/ProgramTests.kt +++ b/compilerAst/test/ast/ProgramTests.kt @@ -1,4 +1,4 @@ -package prog8tests.ast +package prog8tests.ast.ast import org.hamcrest.MatcherAssert.assertThat @@ -12,8 +12,8 @@ import prog8.ast.Program import prog8.ast.base.Position import prog8.ast.internedStringsModuleName import prog8.parser.SourceCode -import prog8tests.helpers.DummyFunctions -import prog8tests.helpers.DummyMemsizer +import prog8tests.ast.helpers.DummyFunctions +import prog8tests.ast.helpers.DummyMemsizer import kotlin.test.assertContains import kotlin.test.assertFailsWith import kotlin.test.assertSame diff --git a/compilerAst/test/helpers/DummyFunctions.kt b/compilerAst/test/helpers/DummyFunctions.kt index b58c7d0bf..a4396bfbe 100644 --- a/compilerAst/test/helpers/DummyFunctions.kt +++ b/compilerAst/test/helpers/DummyFunctions.kt @@ -1,4 +1,4 @@ -package prog8tests.helpers +package prog8tests.ast.helpers import prog8.ast.IBuiltinFunctions import prog8.ast.base.Position diff --git a/compilerAst/test/helpers/DummyMemsizer.kt b/compilerAst/test/helpers/DummyMemsizer.kt index 929514a5b..4735d948f 100644 --- a/compilerAst/test/helpers/DummyMemsizer.kt +++ b/compilerAst/test/helpers/DummyMemsizer.kt @@ -1,4 +1,4 @@ -package prog8tests.helpers +package prog8tests.ast.helpers import prog8.ast.base.DataType import prog8.compiler.IMemSizer diff --git a/compilerAst/test/helpers/mapCombinations.kt b/compilerAst/test/helpers/mapCombinations.kt index e96734cb1..52c601464 100644 --- a/compilerAst/test/helpers/mapCombinations.kt +++ b/compilerAst/test/helpers/mapCombinations.kt @@ -1,4 +1,4 @@ -package prog8tests.helpers +package prog8tests.ast.helpers fun mapCombinations(dim1: Iterable, dim2: Iterable, combine2: (A, B) -> R) = sequence { @@ -22,4 +22,4 @@ fun mapCombinations(dim1: Iterable, dim2: Iterable, dim3: for (c in dim3) for (d in dim4) yield(combine4(a, b, c, d)) - }.toList() \ No newline at end of file + }.toList() diff --git a/compilerAst/test/helpers/paths.kt b/compilerAst/test/helpers/paths.kt index 515ccde04..10e73f4fe 100644 --- a/compilerAst/test/helpers/paths.kt +++ b/compilerAst/test/helpers/paths.kt @@ -1,4 +1,4 @@ -package prog8tests.helpers +package prog8tests.ast.helpers import java.nio.file.Path import kotlin.io.path.* diff --git a/compilerAst/test/helpers_pathsTests.kt b/compilerAst/test/helpers_pathsTests.kt index efc5ddc5b..2f22767d9 100644 --- a/compilerAst/test/helpers_pathsTests.kt +++ b/compilerAst/test/helpers_pathsTests.kt @@ -1,11 +1,11 @@ -package prog8tests +package prog8tests.ast import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.`is` import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance -import prog8tests.helpers.* +import prog8tests.ast.helpers.* import kotlin.io.path.Path import kotlin.io.path.div import kotlin.test.assertFailsWith diff --git a/compiler/src/prog8/compiler/functions/BuiltinFunctions.kt b/compilerInterfaces/src/prog8/compilerinterface/BuiltinFunctions.kt similarity index 96% rename from compiler/src/prog8/compiler/functions/BuiltinFunctions.kt rename to compilerInterfaces/src/prog8/compilerinterface/BuiltinFunctions.kt index 981eec3d6..0ba58f914 100644 --- a/compiler/src/prog8/compiler/functions/BuiltinFunctions.kt +++ b/compilerInterfaces/src/prog8/compilerinterface/BuiltinFunctions.kt @@ -1,14 +1,12 @@ -package prog8.compiler.functions +package prog8.compilerinterface import prog8.ast.Program import prog8.ast.base.* import prog8.ast.expressions.* import prog8.ast.statements.VarDecl -import prog8.compilerinterface.CompilerException import prog8.compiler.IMemSizer import kotlin.math.* - class FParam(val name: String, val possibleDatatypes: Array) @@ -27,11 +25,11 @@ class CallConvention(val params: List, val returns: ReturnConve } } val returnConv = - when { - returns.reg!=null -> returns.reg.toString() - returns.floatFac1 -> "floatFAC1" - else -> "" - } + when { + returns.reg!=null -> returns.reg.toString() + returns.floatFac1 -> "floatFAC1" + else -> "" + } return "CallConvention[" + paramConvs.joinToString() + " ; returns: $returnConv]" } } @@ -52,7 +50,7 @@ class FSignature(val name: String, else -> { val paramType = actualParamTypes.first() if(pure) - // return type depends on arg type + // return type depends on arg type when(paramType) { DataType.UBYTE, DataType.BYTE -> ReturnConvention(paramType, RegisterOrPair.A, false) DataType.UWORD, DataType.WORD -> ReturnConvention(paramType, RegisterOrPair.AY, false) @@ -87,9 +85,12 @@ class FSignature(val name: String, } } + + + @Suppress("UNUSED_ANONYMOUS_PARAMETER") private val functionSignatures: List = listOf( - // this set of function have no return value and operate in-place: + // this set of function have no return value and operate in-place: FSignature("rol" , false, listOf(FParam("item", arrayOf(DataType.UBYTE, DataType.UWORD))), null), FSignature("ror" , false, listOf(FParam("item", arrayOf(DataType.UBYTE, DataType.UWORD))), null), FSignature("rol2" , false, listOf(FParam("item", arrayOf(DataType.UBYTE, DataType.UWORD))), null), @@ -97,14 +98,14 @@ private val functionSignatures: List = listOf( FSignature("sort" , false, listOf(FParam("array", ArrayDatatypes)), null), FSignature("reverse" , false, listOf(FParam("array", ArrayDatatypes)), null), FSignature("cmp" , false, listOf(FParam("value1", IntegerDatatypes), FParam("value2", NumericDatatypes)), null), - // these few have a return value depending on the argument(s): + // these few have a return value depending on the argument(s): FSignature("max" , true, listOf(FParam("values", ArrayDatatypes)), null) { a, p, prg, ct -> collectionArg(a, p, prg, ::builtinMax) }, // type depends on args FSignature("min" , true, listOf(FParam("values", ArrayDatatypes)), null) { a, p, prg, ct -> collectionArg(a, p, prg, ::builtinMin) }, // type depends on args FSignature("sum" , true, listOf(FParam("values", ArrayDatatypes)), null) { a, p, prg, ct -> collectionArg(a, p, prg, ::builtinSum) }, // type depends on args FSignature("abs" , true, listOf(FParam("value", NumericDatatypes)), null, ::builtinAbs), // type depends on argument FSignature("len" , true, listOf(FParam("values", IterableDatatypes)), null, ::builtinLen), // type is UBYTE or UWORD depending on actual length FSignature("sizeof" , true, listOf(FParam("object", DataType.values())), DataType.UBYTE, ::builtinSizeof), - // normal functions follow: + // normal functions follow: FSignature("sgn" , true, listOf(FParam("value", NumericDatatypes)), DataType.BYTE, ::builtinSgn ), FSignature("sin" , true, listOf(FParam("rads", arrayOf(DataType.FLOAT))), DataType.FLOAT) { a, p, prg, ct -> oneDoubleArg(a, p, prg, Math::sin) }, FSignature("sin8" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), DataType.BYTE, ::builtinSin8 ), @@ -144,7 +145,7 @@ private val functionSignatures: List = listOf( FSignature("callfar" , false, listOf(FParam("bank", arrayOf(DataType.UBYTE)), FParam("address", arrayOf(DataType.UWORD)), FParam("arg", arrayOf(DataType.UWORD))), null), FSignature("callrom" , false, listOf(FParam("bank", arrayOf(DataType.UBYTE)), FParam("address", arrayOf(DataType.UWORD)), FParam("arg", arrayOf(DataType.UWORD))), null), -) + ) val BuiltinFunctions = functionSignatures.associateBy { it.name } @@ -297,7 +298,7 @@ private fun builtinSizeof(args: List, position: Position, program: P val dt = args[0].inferType(program) if(dt.isKnown) { val target = (args[0] as IdentifierReference).targetStatement(program) - ?: throw CannotEvaluateException("sizeof", "no target") + ?: throw CannotEvaluateException("sizeof", "no target") return when { dt.isArray -> { @@ -328,7 +329,7 @@ private fun builtinLen(args: List, position: Position, program: Prog if(args[0] !is IdentifierReference) throw SyntaxError("len argument should be an identifier", position) val target = (args[0] as IdentifierReference).targetVarDecl(program) - ?: throw CannotEvaluateException("len", "no target vardecl") + ?: throw CannotEvaluateException("len", "no target vardecl") return when(target.datatype) { DataType.ARRAY_UB, DataType.ARRAY_B, DataType.ARRAY_UW, DataType.ARRAY_W, DataType.ARRAY_F -> { @@ -440,10 +441,10 @@ private fun builtinSgn(args: List, position: Position, program: Prog private fun numericLiteral(value: Number, position: Position): NumericLiteralValue { val floatNum=value.toDouble() val tweakedValue: Number = - if(floatNum== floor(floatNum) && (floatNum>=-32768 && floatNum<=65535)) - floatNum.toInt() // we have an integer disguised as a float. - else - floatNum + if(floatNum== floor(floatNum) && (floatNum>=-32768 && floatNum<=65535)) + floatNum.toInt() // we have an integer disguised as a float. + else + floatNum return when(tweakedValue) { is Int -> NumericLiteralValue.optimalInteger(value.toInt(), position) diff --git a/codeOptimizers/src/prog8/optimizer/CallGraph.kt b/compilerInterfaces/src/prog8/compilerinterface/CallGraph.kt similarity index 99% rename from codeOptimizers/src/prog8/optimizer/CallGraph.kt rename to compilerInterfaces/src/prog8/compilerinterface/CallGraph.kt index 7786b5ad7..6ff91b39d 100644 --- a/codeOptimizers/src/prog8/optimizer/CallGraph.kt +++ b/compilerInterfaces/src/prog8/compilerinterface/CallGraph.kt @@ -1,4 +1,4 @@ -package prog8.optimizer +package prog8.compilerinterface import prog8.ast.Module import prog8.ast.Node @@ -10,7 +10,6 @@ import prog8.ast.expressions.FunctionCall import prog8.ast.expressions.IdentifierReference import prog8.ast.statements.* import prog8.ast.walk.IAstVisitor -import prog8.compilerinterface.IErrorReporter class CallGraph(private val program: Program) : IAstVisitor { diff --git a/compilerInterfaces/src/prog8/compilerinterface/CompilerException.kt b/compilerInterfaces/src/prog8/compilerinterface/Exceptions.kt similarity index 100% rename from compilerInterfaces/src/prog8/compilerinterface/CompilerException.kt rename to compilerInterfaces/src/prog8/compilerinterface/Exceptions.kt diff --git a/compilerInterfaces/src/prog8/compilerinterface/IErrorReporter.kt b/compilerInterfaces/src/prog8/compilerinterface/IErrorReporter.kt index a4247c1d7..daafb9dbf 100644 --- a/compilerInterfaces/src/prog8/compilerinterface/IErrorReporter.kt +++ b/compilerInterfaces/src/prog8/compilerinterface/IErrorReporter.kt @@ -14,3 +14,47 @@ interface IErrorReporter { throw ParsingFailedError("There are $numErrors errors and $numWarnings warnings.") } } + + +class ErrorReporter: IErrorReporter { + private enum class MessageSeverity { + WARNING, + ERROR + } + private class CompilerMessage(val severity: MessageSeverity, val message: String, val position: Position) + + private val messages = mutableListOf() + private val alreadyReportedMessages = mutableSetOf() + + override fun err(msg: String, position: Position) { + messages.add(CompilerMessage(MessageSeverity.ERROR, msg, position)) + } + override fun warn(msg: String, position: Position) { + messages.add(CompilerMessage(MessageSeverity.WARNING, msg, position)) + } + + override fun report() { + var numErrors = 0 + var numWarnings = 0 + messages.forEach { + when(it.severity) { + MessageSeverity.ERROR -> System.err.print("\u001b[91m") // bright red + MessageSeverity.WARNING -> System.err.print("\u001b[93m") // bright yellow + } + val msg = "${it.position.toClickableStr()} ${it.severity} ${it.message}".trim() + if(msg !in alreadyReportedMessages) { + System.err.println(msg) + alreadyReportedMessages.add(msg) + when(it.severity) { + MessageSeverity.WARNING -> numWarnings++ + MessageSeverity.ERROR -> numErrors++ + } + } + System.err.print("\u001b[0m") // reset color + } + messages.clear() + finalizeNumErrors(numErrors, numWarnings) + } + + override fun noErrors() = messages.none { it.severity==MessageSeverity.ERROR } +} diff --git a/compilerInterfaces/test/TestAstExtensions.kt b/compilerInterfaces/test/TestAstExtensions.kt index 996567e0f..843a36aad 100644 --- a/compilerInterfaces/test/TestAstExtensions.kt +++ b/compilerInterfaces/test/TestAstExtensions.kt @@ -1,4 +1,4 @@ -package prog8tests +package prog8tests.interfaces import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance diff --git a/compilerInterfaces/test/TestZeropage.kt b/compilerInterfaces/test/TestZeropage.kt index f9ad5fcfb..e7a0bd608 100644 --- a/compilerInterfaces/test/TestZeropage.kt +++ b/compilerInterfaces/test/TestZeropage.kt @@ -1,4 +1,4 @@ -package prog8tests +package prog8tests.interfaces import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 801c11849..2f3b6fd9a 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -26,7 +26,6 @@ Future - add a flood fill routine to gfx2? - add a diskio.f_seek() routine for the Cx16 that uses its seek dos api? - make it possible for diskio to read and write from more than one file at the same time (= use multiple io channels)? -- refactor the asmgen into own project submodule - make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as ``v_`` - [problematic due to 64tass:] add a compiler option to not remove unused subroutines. this allows for building library programs. But this won't work with 64tass's .proc ... Perhaps replace all uses of .proc/.pend by .block/.bend will fix that? diff --git a/settings.gradle b/settings.gradle index 17558290d..b22fcc687 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,6 +2,7 @@ include ':parser' include ':compilerInterfaces' include ':compilerAst' include ':codeOptimizers' +include ':codeGeneration' include ':compiler' include ':dbusCompilerService' include ':httpCompilerService'