From c223702ea0eabfeabb91a2983feaa6996fd33d67 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 30 Jul 2023 18:42:45 +0200 Subject: [PATCH] code cleanups --- codeCore/src/prog8/code/SymbolTable.kt | 10 +++---- codeCore/src/prog8/code/core/Position.kt | 4 +-- codeCore/src/prog8/code/core/SourceCode.kt | 10 +++---- .../src/prog8/codegen/cpu6502/AsmGen.kt | 4 +-- .../prog8/codegen/cpu6502/AssemblyProgram.kt | 21 --------------- .../src/prog8/codegen/cpu6502/Extensions.kt | 11 -------- .../prog8/codegen/cpu6502/ForLoopsAsmGen.kt | 9 ++++--- .../cpu6502/assignment/AssignmentAsmGen.kt | 8 +++--- .../codegen/experimental/ExperiCodeGen.kt | 2 +- .../prog8/codegen/intermediate/IRCodeGen.kt | 18 ------------- .../intermediate/IRUnusedCodeRemover.kt | 6 ++--- .../src/prog8/codegen/vm/VmCodeGen.kt | 2 +- .../src/prog8/buildversion/BuildVersion.kt | 14 +++++----- compiler/src/prog8/compiler/Compiler.kt | 4 +-- compiler/src/prog8/compiler/ModuleImporter.kt | 4 +-- .../compiler/astprocessing/AstChecker.kt | 2 +- .../compiler/astprocessing/AstExtensions.kt | 4 +-- .../astprocessing/IntermediateAstMaker.kt | 6 ++--- .../astprocessing/StatementReorderer.kt | 8 +++--- compiler/test/ast/TestIntermediateAst.kt | 2 +- compiler/test/ast/TestProg8Parser.kt | 4 +-- compiler/test/ast/TestSourceCode.kt | 12 ++++----- .../test/codegeneration/TestAsmGenSymbols.kt | 2 +- compilerAst/src/prog8/ast/Program.kt | 2 +- .../prog8/ast/expressions/AstExpressions.kt | 2 -- .../src/prog8/ast/statements/AstStatements.kt | 27 ------------------- gradle.properties | 2 +- virtualmachine/src/prog8/vm/GraphicsWindow.kt | 2 +- .../src/prog8/vm/VmVariableAllocator.kt | 2 +- 29 files changed, 62 insertions(+), 142 deletions(-) diff --git a/codeCore/src/prog8/code/SymbolTable.kt b/codeCore/src/prog8/code/SymbolTable.kt index 32dd8a6e5..781c21260 100644 --- a/codeCore/src/prog8/code/SymbolTable.kt +++ b/codeCore/src/prog8/code/SymbolTable.kt @@ -213,8 +213,7 @@ class StStaticVariable(name: String, class StConstant(name: String, val dt: DataType, val value: Double, astNode: PtNode) : - StNode(name, StNodeType.CONSTANT, astNode) { -} + StNode(name, StNodeType.CONSTANT, astNode) class StMemVar(name: String, @@ -236,12 +235,11 @@ class StMemorySlab( val align: UInt, astNode: PtNode ): - StNode(name, StNodeType.MEMORYSLAB, astNode) { -} + StNode(name, StNodeType.MEMORYSLAB, astNode) + class StSub(name: String, val parameters: List, val returnType: DataType?, astNode: PtNode) : - StNode(name, StNodeType.SUBROUTINE, astNode) { -} + StNode(name, StNodeType.SUBROUTINE, astNode) class StRomSub(name: String, diff --git a/codeCore/src/prog8/code/core/Position.kt b/codeCore/src/prog8/code/core/Position.kt index b0c70a40b..b87874319 100644 --- a/codeCore/src/prog8/code/core/Position.kt +++ b/codeCore/src/prog8/code/core/Position.kt @@ -1,6 +1,6 @@ package prog8.code.core -import prog8.code.core.SourceCode.Companion.libraryFilePrefix +import prog8.code.core.SourceCode.Companion.LIBRARYFILEPREFIX import java.nio.file.InvalidPathException import kotlin.io.path.Path import kotlin.io.path.absolute @@ -10,7 +10,7 @@ data class Position(val file: String, val line: Int, val startCol: Int, val endC fun toClickableStr(): String { if(this===DUMMY) return "" - if(file.startsWith(libraryFilePrefix)) + if(file.startsWith(LIBRARYFILEPREFIX)) return "$file:$line:$startCol:" return try { val path = Path(file).absolute().normalize().toString() diff --git a/codeCore/src/prog8/code/core/SourceCode.kt b/codeCore/src/prog8/code/core/SourceCode.kt index 2b7811088..da9d21306 100644 --- a/codeCore/src/prog8/code/core/SourceCode.kt +++ b/codeCore/src/prog8/code/core/SourceCode.kt @@ -54,12 +54,12 @@ sealed class SourceCode { /** * filename prefix to designate library files that will be retreived from internal resources rather than disk */ - const val libraryFilePrefix = "library:" - const val stringSourcePrefix = "string:" + const val LIBRARYFILEPREFIX = "library:" + const val STRINGSOURCEPREFIX = "string:" val curdir: Path = Path(".").toAbsolutePath() fun relative(path: Path): Path = curdir.relativize(path.toAbsolutePath()) fun isRegularFilesystemPath(pathString: String) = - !(pathString.startsWith(libraryFilePrefix) || pathString.startsWith(stringSourcePrefix)) + !(pathString.startsWith(LIBRARYFILEPREFIX) || pathString.startsWith(STRINGSOURCEPREFIX)) } /** @@ -69,7 +69,7 @@ sealed class SourceCode { class Text(override val text: String): SourceCode() { override val isFromResources = false override val isFromFilesystem = false - override val origin = "$stringSourcePrefix${System.identityHashCode(text).toString(16)}" + override val origin = "$STRINGSOURCEPREFIX${System.identityHashCode(text).toString(16)}" override val name = "" } @@ -110,7 +110,7 @@ sealed class SourceCode { override val isFromResources = true override val isFromFilesystem = false - override val origin = "$libraryFilePrefix$normalized" + override val origin = "$LIBRARYFILEPREFIX$normalized" override val text: String override val name: String diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt index dd1188d33..2c6062482 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -203,7 +203,7 @@ class AsmGen6502Internal ( private val allocator = VariableAllocator(symbolTable, options, errors) private val assemblyLines = mutableListOf() private val breakpointLabels = mutableListOf() - private val forloopsAsmGen = ForLoopsAsmGen(program, this, zeropage) + private val forloopsAsmGen = ForLoopsAsmGen(this, zeropage) private val postincrdecrAsmGen = PostIncrDecrAsmGen(program, this) private val functioncallAsmGen = FunctionCallAsmGen(program, this) private val programGen = ProgramAndVarsGen(program, options, errors, symbolTable, functioncallAsmGen, this, allocator, zeropage) @@ -852,7 +852,7 @@ $repeatLabel""") DataType.UBYTE, DataType.UWORD -> { val result = zeropage.allocate(counterVar, dt, null, stmt.position, errors) result.fold( - success = { (address, _) -> asmInfo.extraVars.add(Triple(dt, counterVar, address)) }, + success = { (address, _, _) -> asmInfo.extraVars.add(Triple(dt, counterVar, address)) }, failure = { asmInfo.extraVars.add(Triple(dt, counterVar, null)) } // allocate normally ) return counterVar diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AssemblyProgram.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AssemblyProgram.kt index d6fbf0e05..d10c55104 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AssemblyProgram.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AssemblyProgram.kt @@ -1,14 +1,8 @@ package prog8.codegen.cpu6502 -import com.github.michaelbull.result.Ok -import com.github.michaelbull.result.Result -import com.github.michaelbull.result.mapError import prog8.code.core.* import prog8.code.target.C64Target -import java.io.File import java.nio.file.Path -import kotlin.io.path.Path -import kotlin.io.path.isRegularFile internal class AssemblyProgram( @@ -130,18 +124,3 @@ internal 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)}").text - }.mapError { NoSuchFileException(File(filename)) } - } else { - val sib = Path(source.origin).resolveSibling(filename) - if (sib.isRegularFile()) - Ok(SourceCode.File(sib).text) - else - Ok(SourceCode.File(Path(filename)).text) - } -} diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/Extensions.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/Extensions.kt index 7f56fcbed..3c2d5ed68 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/Extensions.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/Extensions.kt @@ -6,17 +6,6 @@ import prog8.code.ast.PtSub import prog8.code.core.* -internal class KeepAresult(val saveOnEntry: Boolean, val saveOnReturn: Boolean) - -internal fun PtAsmSub.shouldKeepA(): KeepAresult { - // determine if A's value should be kept when preparing for calling the subroutine, and when returning from it - - // it seems that we never have to save A when calling? will be loaded correctly after setup. - // but on return it depends on wether the routine returns something in A. - val saveAonReturn = returns.any { it.first.registerOrPair==RegisterOrPair.A || it.first.registerOrPair==RegisterOrPair.AY || it.first.registerOrPair==RegisterOrPair.AX } - return KeepAresult(false, saveAonReturn) -} - internal fun IPtSubroutine.returnsWhatWhere(): List> { when(this) { is PtAsmSub -> { diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ForLoopsAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ForLoopsAsmGen.kt index 5906c3ae3..4477a9509 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ForLoopsAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ForLoopsAsmGen.kt @@ -5,9 +5,10 @@ import prog8.code.ast.* import prog8.code.core.* import kotlin.math.absoluteValue -internal class ForLoopsAsmGen(private val program: PtProgram, - private val asmgen: AsmGen6502Internal, - private val zeropage: Zeropage) { +internal class ForLoopsAsmGen( + private val asmgen: AsmGen6502Internal, + private val zeropage: Zeropage +) { internal fun translate(stmt: PtForLoop) { val iterableDt = stmt.iterable.type @@ -382,7 +383,7 @@ $loopLabel sty $indexVar // allocate index var on ZP if possible val result = zeropage.allocate(indexVar, DataType.UBYTE, null, stmt.position, asmgen.errors) result.fold( - success = { (address,_)-> asmgen.out("""$indexVar = $address ; auto zp UBYTE""") }, + success = { (address, _, _)-> asmgen.out("""$indexVar = $address ; auto zp UBYTE""") }, failure = { asmgen.out("$indexVar .byte 0") } ) } else { diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt index 175037976..71ae824d4 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt @@ -2497,7 +2497,7 @@ internal class AssignmentAsmGen(private val program: PtProgram, CpuRegister.X -> asmgen.out(" txa") CpuRegister.Y -> asmgen.out(" tya") } - if(asmgen.isZpVar(target.origAstTarget!!.array!!.variable)) { + if(asmgen.isZpVar(target.origAstTarget.array!!.variable)) { asmgen.out(" ldy #${target.constArrayIndexValue} | sta (${target.asmVarname}),y") } else { asmgen.out(""" @@ -2515,8 +2515,8 @@ internal class AssignmentAsmGen(private val program: PtProgram, CpuRegister.X -> asmgen.out(" txa") CpuRegister.Y -> asmgen.out(" tya") } - val indexVar = target.array!!.index as PtIdentifier - if(asmgen.isZpVar(target.origAstTarget!!.array!!.variable)) { + val indexVar = target.array.index as PtIdentifier + if(asmgen.isZpVar(target.origAstTarget.array!!.variable)) { asmgen.out(" ldy ${asmgen.asmVariableName(indexVar)} | sta (${target.asmVarname}),y") } else { asmgen.out(""" @@ -2545,7 +2545,7 @@ internal class AssignmentAsmGen(private val program: PtProgram, CpuRegister.X -> asmgen.out(" txa") CpuRegister.Y -> asmgen.out(" tya") } - val indexVar = target.array!!.index as PtIdentifier + val indexVar = target.array.index as PtIdentifier asmgen.out(" ldy ${asmgen.asmVariableName(indexVar)} | sta ${target.asmVarname},y") } } diff --git a/codeGenExperimental/src/prog8/codegen/experimental/ExperiCodeGen.kt b/codeGenExperimental/src/prog8/codegen/experimental/ExperiCodeGen.kt index 8b6f4c79a..a88c4a3c2 100644 --- a/codeGenExperimental/src/prog8/codegen/experimental/ExperiCodeGen.kt +++ b/codeGenExperimental/src/prog8/codegen/experimental/ExperiCodeGen.kt @@ -15,7 +15,7 @@ class ExperiCodeGen: ICodeGeneratorBackend { symbolTable: SymbolTable, options: CompilationOptions, errors: IErrorReporter - ): IAssemblyProgram? { + ): IAssemblyProgram { // you could write a code generator directly on the PtProgram AST, // but you can also use the Intermediate Representation to build a codegen on: diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt index 11c620ff7..f58c7a00b 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt @@ -1652,24 +1652,6 @@ class IRCodeGen( internal fun isOne(expression: PtExpression): Boolean = expression is PtNumber && expression.number==1.0 - fun getReusableTempvar(scope: PtNamedNode, type: DataType): PtIdentifier { - val uniqueId = Pair(scope, type).hashCode().toUInt() - val tempvarname = "${scope.scopedName}.tempvar_${uniqueId}" - val tempvar = PtIdentifier(tempvarname, type, Position.DUMMY) - val staticVar = StStaticVariable( - tempvarname, - type, - null, - null, - null, - null, - ZeropageWish.DONTCARE, - tempvar - ) - irSymbolTable.add(staticVar) - return tempvar - } - fun makeSyscall(syscall: IMSyscall, params: List>, returns: Pair?, label: String?=null): IRCodeChunk { return IRCodeChunk(label, null).also { val args = params.map { (dt, reg)-> diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/IRUnusedCodeRemover.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/IRUnusedCodeRemover.kt index e11b70bdf..c2163bef1 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/IRUnusedCodeRemover.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/IRUnusedCodeRemover.kt @@ -1,7 +1,7 @@ package prog8.codegen.intermediate import prog8.code.core.IErrorReporter -import prog8.code.core.SourceCode.Companion.libraryFilePrefix +import prog8.code.core.SourceCode.Companion.LIBRARYFILEPREFIX import prog8.intermediate.* @@ -50,7 +50,7 @@ class IRUnusedCodeRemover( irprog.blocks.forEach { block -> block.children.filterIsInstance().reversed().forEach { sub -> if(sub.isEmpty()) { - if(!sub.position.file.startsWith(libraryFilePrefix)) { + if(!sub.position.file.startsWith(LIBRARYFILEPREFIX)) { errors.warn("unused subroutine ${sub.label}", sub.position) } block.children.remove(sub) @@ -71,7 +71,7 @@ class IRUnusedCodeRemover( irprog.blocks.forEach { block -> block.children.filterIsInstance().reversed().forEach { sub -> if(sub.isEmpty()) { - if(!sub.position.file.startsWith(libraryFilePrefix)) { + if(!sub.position.file.startsWith(LIBRARYFILEPREFIX)) { errors.warn("unused asmsubroutine ${sub.label}", sub.position) } block.children.remove(sub) diff --git a/codeGenIntermediate/src/prog8/codegen/vm/VmCodeGen.kt b/codeGenIntermediate/src/prog8/codegen/vm/VmCodeGen.kt index 7bc6195ce..8eb528dbc 100644 --- a/codeGenIntermediate/src/prog8/codegen/vm/VmCodeGen.kt +++ b/codeGenIntermediate/src/prog8/codegen/vm/VmCodeGen.kt @@ -16,7 +16,7 @@ class VmCodeGen: ICodeGeneratorBackend { symbolTable: SymbolTable, options: CompilationOptions, errors: IErrorReporter - ): IAssemblyProgram? { + ): IAssemblyProgram { val irCodeGen = IRCodeGen(program, symbolTable, options, errors) val irProgram = irCodeGen.generate() return VmAssemblyProgram(irProgram.name, irProgram) diff --git a/compiler/src/prog8/buildversion/BuildVersion.kt b/compiler/src/prog8/buildversion/BuildVersion.kt index e5e79b7d7..80b24a229 100644 --- a/compiler/src/prog8/buildversion/BuildVersion.kt +++ b/compiler/src/prog8/buildversion/BuildVersion.kt @@ -5,11 +5,11 @@ package prog8.buildversion */ const val MAVEN_GROUP = "prog8" const val MAVEN_NAME = "compiler" -const val VERSION = "9.2-SNAPSHOT" -const val GIT_REVISION = 3980 -const val GIT_SHA = "9f247901d484ca36d047cdcf77f5b905ba772f82" -const val GIT_DATE = "2023-07-16T21:45:04Z" -const val GIT_BRANCH = "remove_evalstack" -const val BUILD_DATE = "2023-07-17T23:11:43Z" -const val BUILD_UNIX_TIME = 1689635503506L +const val VERSION = "9.3-SNAPSHOT" +const val GIT_REVISION = 4012 +const val GIT_SHA = "9167ba499de99696aa7c6887d4867eae70eb5caf" +const val GIT_DATE = "2023-07-30T15:49:35Z" +const val GIT_BRANCH = "master" +const val BUILD_DATE = "2023-07-30T16:41:27Z" +const val BUILD_UNIX_TIME = 1690735287514L const val DIRTY = 1 diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 9848db539..5373802dd 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -104,7 +104,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? { program.processAstBeforeAsmGeneration(compilationOptions, args.errors) args.errors.report() - val intermediateAst = IntermediateAstMaker(program, compilationOptions).transform() + val intermediateAst = IntermediateAstMaker(program).transform() // println("*********** COMPILER AST RIGHT BEFORE ASM GENERATION *************") // printProgram(program) // println("*********** AST RIGHT BEFORE ASM GENERATION *************") @@ -334,7 +334,7 @@ private fun processAst(program: Program, errors: IErrorReporter, compilerOptions errors.report() program.desugaring(errors) errors.report() - program.reorderStatements(errors, compilerOptions) + program.reorderStatements(errors) errors.report() program.changeNotExpressionAndIfComparisonExpr(errors, compilerOptions.compTarget) errors.report() diff --git a/compiler/src/prog8/compiler/ModuleImporter.kt b/compiler/src/prog8/compiler/ModuleImporter.kt index 00a6ed3fe..6bc623602 100644 --- a/compiler/src/prog8/compiler/ModuleImporter.kt +++ b/compiler/src/prog8/compiler/ModuleImporter.kt @@ -117,7 +117,7 @@ class ModuleImporter(private val program: Program, importedModule.statements.remove(block) } else { val merges = block.statements.filter { it is Directive && it.directive=="%option" && it.args.any { a->a.name=="merge" } } - block.statements.removeAll(merges) + block.statements.removeAll(merges.toSet()) } } } @@ -129,7 +129,7 @@ class ModuleImporter(private val program: Program, // Most global directives don't apply for imported modules, so remove them val moduleLevelDirectives = listOf("%output", "%launcher", "%zeropage", "%zpreserved", "%address") var directives = importedModule.statements.filterIsInstance() - importedModule.statements.removeAll(directives) + importedModule.statements.removeAll(directives.toSet()) directives = directives.filter{ it.directive !in moduleLevelDirectives } importedModule.statements.addAll(0, directives) } diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index b86815d5a..eeaf79184 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -116,7 +116,7 @@ internal class AstChecker(private val program: Program, errors.err("type $valueDt of return value doesn't match subroutine's return type ${expectedReturnValues[0]}",returnStmt.value!!.position) } } else if(valueDt.isIterable && expectedReturnValues[0]==DataType.UWORD) { - // you can return a string or array when a uword (pointer) is returned + // you can return a string or array when an uword (pointer) is returned } else { errors.err("type $valueDt of return value doesn't match subroutine's return type ${expectedReturnValues[0]}",returnStmt.value!!.position) diff --git a/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt b/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt index e33b39b5b..b8cc09ec3 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstExtensions.kt @@ -39,8 +39,8 @@ internal fun Program.processAstBeforeAsmGeneration(compilerOptions: CompilationO } } -internal fun Program.reorderStatements(errors: IErrorReporter, options: CompilationOptions) { - val reorder = StatementReorderer(this, errors, options) +internal fun Program.reorderStatements(errors: IErrorReporter) { + val reorder = StatementReorderer(this, errors) reorder.visit(this) if(errors.noErrors()) { reorder.applyModifications() diff --git a/compiler/src/prog8/compiler/astprocessing/IntermediateAstMaker.kt b/compiler/src/prog8/compiler/astprocessing/IntermediateAstMaker.kt index d05e9cd1b..8f178f948 100644 --- a/compiler/src/prog8/compiler/astprocessing/IntermediateAstMaker.kt +++ b/compiler/src/prog8/compiler/astprocessing/IntermediateAstMaker.kt @@ -19,7 +19,7 @@ import kotlin.io.path.isRegularFile /** * Convert 'old' compiler-AST into the 'new' simplified AST with baked types. */ -class IntermediateAstMaker(private val program: Program, private val options: CompilationOptions) { +class IntermediateAstMaker(private val program: Program) { fun transform(): PtProgram { val ptProgram = PtProgram( program.name, @@ -529,9 +529,9 @@ class IntermediateAstMaker(private val program: Program, private val options: Co private fun loadAsmIncludeFile(filename: String, source: SourceCode): Result { - return if (filename.startsWith(SourceCode.libraryFilePrefix)) { + return if (filename.startsWith(SourceCode.LIBRARYFILEPREFIX)) { return com.github.michaelbull.result.runCatching { - SourceCode.Resource("/prog8lib/${filename.substring(SourceCode.libraryFilePrefix.length)}").text + SourceCode.Resource("/prog8lib/${filename.substring(SourceCode.LIBRARYFILEPREFIX.length)}").text }.mapError { NoSuchFileException(File(filename)) } } else { val sib = Path(source.origin).resolveSibling(filename) diff --git a/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt b/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt index 7cd4e7c1c..0338a926d 100644 --- a/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt +++ b/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt @@ -7,9 +7,9 @@ import prog8.ast.walk.AstWalker import prog8.ast.walk.IAstModification import prog8.code.core.* -internal class StatementReorderer(val program: Program, - val errors: IErrorReporter, - private val options: CompilationOptions +internal class StatementReorderer( + val program: Program, + val errors: IErrorReporter ) : AstWalker() { // Reorders the statements in a way the compiler needs. // - 'main' block must be the very first statement UNLESS it has an address set. @@ -109,7 +109,7 @@ internal class StatementReorderer(val program: Program, private fun directivesToTheTop(statements: MutableList) { val directives = statements.filterIsInstance().filter {it.directive in directivesToMove} - statements.removeAll(directives) + statements.removeAll(directives.toSet()) statements.addAll(0, directives) } diff --git a/compiler/test/ast/TestIntermediateAst.kt b/compiler/test/ast/TestIntermediateAst.kt index 168061267..d259fa763 100644 --- a/compiler/test/ast/TestIntermediateAst.kt +++ b/compiler/test/ast/TestIntermediateAst.kt @@ -37,7 +37,7 @@ class TestIntermediateAst: FunSpec({ loadAddress = target.machine.PROGRAM_LOAD_ADDRESS ) val result = compileText(target, false, text, writeAssembly = false)!! - val ast = IntermediateAstMaker(result.compilerAst, options).transform() + val ast = IntermediateAstMaker(result.compilerAst).transform() ast.name shouldBe result.compilerAst.name ast.allBlocks().any() shouldBe true val entry = ast.entrypoint() ?: fail("no main.start() found") diff --git a/compiler/test/ast/TestProg8Parser.kt b/compiler/test/ast/TestProg8Parser.kt index b6e448777..d70a49d55 100644 --- a/compiler/test/ast/TestProg8Parser.kt +++ b/compiler/test/ast/TestProg8Parser.kt @@ -378,7 +378,7 @@ class TestProg8Parser: FunSpec( { """.trimIndent() val module = parseModule(SourceCode.Text(srcText)) assertSomethingForAllNodes(module) { - it.position.file shouldStartWith SourceCode.stringSourcePrefix + it.position.file shouldStartWith SourceCode.STRINGSOURCEPREFIX } } @@ -387,7 +387,7 @@ class TestProg8Parser: FunSpec( { val resource = SourceCode.Resource("prog8lib/math.p8") val module = parseModule(resource) assertSomethingForAllNodes(module) { - it.position.file shouldStartWith SourceCode.libraryFilePrefix + it.position.file shouldStartWith SourceCode.LIBRARYFILEPREFIX } } } diff --git a/compiler/test/ast/TestSourceCode.kt b/compiler/test/ast/TestSourceCode.kt index ee9d04cfc..5bdfe0f5c 100644 --- a/compiler/test/ast/TestSourceCode.kt +++ b/compiler/test/ast/TestSourceCode.kt @@ -5,7 +5,7 @@ import io.kotest.core.spec.style.AnnotationSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import prog8.code.core.SourceCode -import prog8.code.core.SourceCode.Companion.libraryFilePrefix +import prog8.code.core.SourceCode.Companion.LIBRARYFILEPREFIX import prog8tests.helpers.assumeNotExists import prog8tests.helpers.assumeReadableFile import prog8tests.helpers.fixturesDir @@ -77,7 +77,7 @@ class TestSourceCode: AnnotationSpec() { val srcFile = assumeReadableFile(resourcesDir, pathString).toFile() val src = SourceCode.Resource(pathString) - src.origin shouldBe "$libraryFilePrefix/$pathString" + src.origin shouldBe "$LIBRARYFILEPREFIX/$pathString" src.text shouldBe srcFile.readText() src.isFromResources shouldBe true src.isFromFilesystem shouldBe false @@ -89,7 +89,7 @@ class TestSourceCode: AnnotationSpec() { val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile() val src = SourceCode.Resource(pathString) - src.origin shouldBe "$libraryFilePrefix$pathString" + src.origin shouldBe "$LIBRARYFILEPREFIX$pathString" src.text shouldBe srcFile.readText() } @@ -99,7 +99,7 @@ class TestSourceCode: AnnotationSpec() { val srcFile = assumeReadableFile(resourcesDir, pathString).toFile() val src = SourceCode.Resource(pathString) - src.origin shouldBe "$libraryFilePrefix/$pathString" + src.origin shouldBe "$LIBRARYFILEPREFIX/$pathString" src.text shouldBe srcFile.readText() src.isFromResources shouldBe true } @@ -110,7 +110,7 @@ class TestSourceCode: AnnotationSpec() { val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile() val src = SourceCode.Resource(pathString) - src.origin shouldBe "$libraryFilePrefix$pathString" + src.origin shouldBe "$LIBRARYFILEPREFIX$pathString" src.text shouldBe srcFile.readText() } @@ -120,7 +120,7 @@ class TestSourceCode: AnnotationSpec() { val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile() val src = SourceCode.Resource(pathString) - src.origin shouldBe "$libraryFilePrefix/prog8lib/math.p8" + src.origin shouldBe "$LIBRARYFILEPREFIX/prog8lib/math.p8" src.text shouldBe srcFile.readText() src.isFromResources shouldBe true } diff --git a/compiler/test/codegeneration/TestAsmGenSymbols.kt b/compiler/test/codegeneration/TestAsmGenSymbols.kt index f79f1bd70..ff7ecd2ba 100644 --- a/compiler/test/codegeneration/TestAsmGenSymbols.kt +++ b/compiler/test/codegeneration/TestAsmGenSymbols.kt @@ -75,7 +75,7 @@ class TestAsmGenSymbols: StringSpec({ fun createTestAsmGen6502(program: Program): AsmGen6502Internal { val errors = ErrorReporterForTests() val options = CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), false, true, C64Target(), 999u) - val ptProgram = IntermediateAstMaker(program, options).transform() + val ptProgram = IntermediateAstMaker(program).transform() val st = SymbolTableMaker(ptProgram, options).make() return AsmGen6502Internal(ptProgram, st, options, errors) } diff --git a/compilerAst/src/prog8/ast/Program.kt b/compilerAst/src/prog8/ast/Program.kt index aceb30bd9..95f29cd45 100644 --- a/compilerAst/src/prog8/ast/Program.kt +++ b/compilerAst/src/prog8/ast/Program.kt @@ -75,7 +75,7 @@ class Program(val name: String, // replace it with a variable declaration that points to the entry in the pool. if(string.parent is VarDecl) { - // deduplication can only be performed safely for known-const strings (=string literals OUTSIDE OF A VARDECL)! + // deduplication can only be performed safely for known-const strings (=string literals OUTSIDE A VARDECL)! throw FatalAstException("cannot intern a string literal that's part of a vardecl") } diff --git a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt index f6191910a..1eeb9eb20 100644 --- a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt +++ b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt @@ -985,8 +985,6 @@ data class IdentifierReference(val nameInSource: List, override val posi val scope=decl.definingModule return scope.name==internedStringsModuleName } - - fun renamed(newName: List): IdentifierReference = IdentifierReference(newName, position) } class FunctionCallExpression(override var target: IdentifierReference, diff --git a/compilerAst/src/prog8/ast/statements/AstStatements.kt b/compilerAst/src/prog8/ast/statements/AstStatements.kt index e05a622d0..898d5d164 100644 --- a/compilerAst/src/prog8/ast/statements/AstStatements.kt +++ b/compilerAst/src/prog8/ast/statements/AstStatements.kt @@ -136,7 +136,6 @@ data class Label(override val name: String, override val position: Position) : S override fun accept(visitor: IAstVisitor) = visitor.visit(this) override fun accept(visitor: AstWalker, parent: Node) = visitor.visit(this, parent) override fun toString()= "Label(name=$name, pos=$position)" - fun renamed(newName: String): Label = Label(newName, position) } class Return(var value: Expression?, override val position: Position) : Statement() { @@ -291,13 +290,6 @@ class VarDecl(val type: VarDeclType, return copy } - fun renamed(newName: String): VarDecl { - val copy = VarDecl(type, origin, declaredDatatype, zeropage, arraysize, newName, value, - isArray, sharedWithAsm, splitArray, position) - copy.allowInitializeWithZero = this.allowInitializeWithZero - return copy - } - fun findInitializer(program: Program): Assignment? = (parent as IStatementContainer).statements .asSequence() @@ -883,25 +875,6 @@ class ForLoop(var loopVar: IdentifierReference, fun loopVarDt(program: Program) = loopVar.inferType(program) - fun constIterationCount(program: Program): Int? { - return when (val iter = iterable) { - is IdentifierReference -> { - val target = iter.targetVarDecl(program)!! - if (target.isArray) - target.arraysize!!.constIndex() - else if (target.value is StringLiteral) - (target.value as StringLiteral).value.length - else if (target.value is ArrayLiteral) - (target.value as ArrayLiteral).value.size - else null - } - is ArrayLiteral -> iter.value.size - is RangeExpression -> iter.size() - is StringLiteral -> iter.value.length - else -> null - } - } - } class WhileLoop(var condition: Expression, diff --git a/gradle.properties b/gradle.properties index dc2acdb6c..f3d7cf433 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,4 +5,4 @@ org.gradle.daemon=true kotlin.code.style=official javaVersion=11 kotlinVersion=1.9.0 -version=9.2.1 +version=9.3-SNAPSHOT diff --git a/virtualmachine/src/prog8/vm/GraphicsWindow.kt b/virtualmachine/src/prog8/vm/GraphicsWindow.kt index ddf4461ff..d6c50f437 100644 --- a/virtualmachine/src/prog8/vm/GraphicsWindow.kt +++ b/virtualmachine/src/prog8/vm/GraphicsWindow.kt @@ -76,7 +76,7 @@ class GraphicsWindow(val pixelWidth: Int, val pixelHeight: Int, val pixelScaling } -internal class BitmapScreenPanel(private val drawImage: BufferedImage, val pixelScaling: Int) : JPanel() { +internal class BitmapScreenPanel(private val drawImage: BufferedImage, pixelScaling: Int) : JPanel() { init { val size = Dimension(drawImage.width * pixelScaling, drawImage.height * pixelScaling) minimumSize = size diff --git a/virtualmachine/src/prog8/vm/VmVariableAllocator.kt b/virtualmachine/src/prog8/vm/VmVariableAllocator.kt index 789cc3fce..369606877 100644 --- a/virtualmachine/src/prog8/vm/VmVariableAllocator.kt +++ b/virtualmachine/src/prog8/vm/VmVariableAllocator.kt @@ -3,7 +3,7 @@ package prog8.vm import prog8.code.core.* import prog8.intermediate.IRSymbolTable -internal class VmVariableAllocator(val st: IRSymbolTable, val encoding: IStringEncoding, memsizer: IMemSizer) { +internal class VmVariableAllocator(st: IRSymbolTable, val encoding: IStringEncoding, memsizer: IMemSizer) { internal val allocations = mutableMapOf() private var freeMemoryStart: Int