diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt index 7cc6ef77a..d23d653c8 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt @@ -1307,9 +1307,6 @@ $repeatLabel lda $counterVar // at this time, nothing has to be done here anymore code-wise } - /** - * TODO: %asminclude and %asmbinary should be done earlier than code gen (-> put content into AST) ... (describe why?) - */ private fun translate(stmt: Directive) { when(stmt.directive) { "%asminclude" -> { diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt index 99103af86..eb4d8a878 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmOptimizer.kt @@ -180,7 +180,7 @@ private fun optimizeSameAssignments(linesByFourteen: List>>): List { // sta X + lda X, sty X + ldy X, stx X + ldx X -> the second instruction can OFTEN be eliminated - // TODO this is not true if X is not a regular RAM memory address (but instead mapped I/O or ROM) + // TODO this is not true if X is not a regular RAM memory address (but instead mapped I/O or ROM) but how does this code know? val mods = mutableListOf() for (pair in linesByFour) { val first = pair[0].value.trimStart() diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt index 7ba03fba8..2066db2d7 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/FunctionCallAsmGen.kt @@ -148,6 +148,7 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg if(arg.isSimple) { // TODO FOR ALL ARG TYPES? // note this stuff below is needed to (eventually) avoid calling asmgen.translateExpression() // TODO but This STILL requires the translateNormalAssignment() to be fixed to avoid stack eval for expressions... + // println("*** ALT PARAM PASSING FOR ASMSUB $stmt $arg") // TODO DEBUG when (val dt = arg.inferType(program).getOr(DataType.UNDEFINED)) { in ByteDatatypes -> { asmgen.assignExpressionToRegister(arg, RegisterOrPair.A) diff --git a/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt b/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt index ee1742e50..00728fe9d 100644 --- a/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt +++ b/codeOptimizers/src/prog8/optimizer/BinExprSplitter.kt @@ -18,7 +18,7 @@ import prog8.compilerinterface.isInRegularRAMof class BinExprSplitter(private val program: Program, private val options: CompilationOptions, private val compTarget: ICompilationTarget) : AstWalker() { // override fun after(decl: VarDecl, parent: Node): Iterable { -// TODO somehow if we do this, the resulting code for some programs (cube3d.p8) gets hundreds of bytes larger...: +// TODO somehow if we do this, the resulting code for some programs (cube3d.p8) gets hundreds of bytes larger...: [ IS THIS STILL TRUE AFTER ALL CHANGES? ] // if(decl.type==VarDeclType.VAR ) { // val binExpr = decl.value as? BinaryExpression // if (binExpr != null && binExpr.operator in augmentAssignmentOperators) { diff --git a/compiler/src/prog8/compiler/ModuleImporter.kt b/compiler/src/prog8/compiler/ModuleImporter.kt index 0015988ec..1dc8526ae 100644 --- a/compiler/src/prog8/compiler/ModuleImporter.kt +++ b/compiler/src/prog8/compiler/ModuleImporter.kt @@ -143,7 +143,6 @@ class ModuleImporter(private val program: Program, } else { val dropCurDir = if(sourcePaths.isNotEmpty() && sourcePaths[0].name == ".") 1 else 0 sourcePaths.drop(dropCurDir) + - // TODO: won't work until Prog8Parser is fixed s.t. it fully initializes the modules it returns. // hm, what won't work?) listOf(Path(importingModule.position.file).parent ?: Path("")) + listOf(Path(".", "prog8lib")) } diff --git a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt index 940c04840..a86edfab1 100644 --- a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt +++ b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt @@ -29,7 +29,7 @@ private fun ParserRuleContext.toPosition() : Position { pathString } // note: beware of TAB characters in the source text, they count as 1 column... - return Position(filename, start.line, start.charPositionInLine, stop.charPositionInLine + stop.text.length) + return Position(filename, start.line, start.charPositionInLine, start.charPositionInLine + start.stopIndex - start.startIndex) } internal fun Prog8ANTLRParser.BlockContext.toAst(isInLibrary: Boolean) : Block { diff --git a/compilerAst/src/prog8/parser/Prog8Parser.kt b/compilerAst/src/prog8/parser/Prog8Parser.kt index b8210f318..b417730d6 100644 --- a/compilerAst/src/prog8/parser/Prog8Parser.kt +++ b/compilerAst/src/prog8/parser/Prog8Parser.kt @@ -100,7 +100,7 @@ object Prog8Parser { val offending = this.offendingToken val line = offending.line val beginCol = offending.charPositionInLine - val endCol = beginCol + offending.stopIndex - offending.startIndex // TODO: point to col *after* token? / why, what's wrong with endCol being inclusive + val endCol = beginCol + offending.stopIndex - offending.startIndex return Position(file, line, beginCol, endCol) } diff --git a/compilerAst/test/TestProg8Parser.kt b/compilerAst/test/TestProg8Parser.kt index 73f87a1d9..48d35c23d 100644 --- a/compilerAst/test/TestProg8Parser.kt +++ b/compilerAst/test/TestProg8Parser.kt @@ -287,24 +287,16 @@ class TestProg8Parser { fun `in ParseError from bad string source code`() { val srcText = "bad * { }\n" - assertFailsWith { parseModule(SourceCode.Text(srcText)) } - try { - parseModule(SourceCode.Text(srcText)) - } catch (e: ParseError) { - assertPosition(e.position, Regex("^$"), 1, 4, 4) - } + val e = assertFailsWith { parseModule(SourceCode.Text(srcText)) } + assertPosition(e.position, Regex("^$"), 1, 4, 4) } @Test fun `in ParseError from bad file source code`() { val path = assumeReadableFile(fixturesDir, "file_with_syntax_error.p8") - assertFailsWith { parseModule(SourceCode.File(path)) } - try { - parseModule(SourceCode.File(path)) - } catch (e: ParseError) { - assertPosition(e.position, SourceCode.relative(path).toString(), 2, 6) // TODO: endCol wrong - } + val e = assertFailsWith { parseModule(SourceCode.File(path)) } + assertPosition(e.position, SourceCode.relative(path).toString(), 2, 6) } @Test @@ -312,16 +304,16 @@ class TestProg8Parser { val srcText = """ main { } - """.trimIndent() + """ val module = parseModule(SourceCode.Text(srcText)) - assertPositionOf(module, Regex("^$"), 1, 0) // TODO: endCol wrong + assertPositionOf(module, Regex("^$"), 1, 0) } @Test fun `of Module parsed from a file`() { val path = assumeReadableFile(fixturesDir, "simple_main.p8") val module = parseModule(SourceCode.File(path)) - assertPositionOf(module, SourceCode.relative(path).toString(), 1, 0) // TODO: endCol wrong + assertPositionOf(module, SourceCode.relative(path).toString(), 1, 0) } @Test @@ -330,27 +322,24 @@ class TestProg8Parser { val module = parseModule(SourceCode.File(path)) val mpf = module.position.file - assertPositionOf(module, SourceCode.relative(path).toString(), 1, 0) // TODO: endCol wrong + assertPositionOf(module, SourceCode.relative(path).toString(), 1, 0) val mainBlock = module.statements.filterIsInstance()[0] - assertPositionOf(mainBlock, mpf, 2, 0) // TODO: endCol wrong! + assertPositionOf(mainBlock, mpf, 2, 0, 3) val startSub = mainBlock.statements.filterIsInstance()[0] - assertPositionOf(startSub, mpf, 3, 4) // TODO: endCol wrong! + assertPositionOf(startSub, mpf, 3, 4, 6) } - /** - * TODO: this test is testing way too much at once - */ @Test fun `of non-root Nodes parsed from a string`() { val srcText = """ - %zeropage basicsafe ; DirectiveArg directly inherits from Node - neither an Expression nor a Statement..? + %zeropage basicsafe main { sub start() { ubyte foo = 42 ubyte bar when (foo) { - 23 -> bar = 'x' ; WhenChoice, also directly inheriting Node + 23 -> bar = 'x' 42 -> bar = 'y' else -> bar = 'z' } @@ -361,22 +350,22 @@ class TestProg8Parser { val mpf = module.position.file val targetDirective = module.statements.filterIsInstance()[0] - assertPositionOf(targetDirective, mpf, 1, 0) // TODO: endCol wrong! + assertPositionOf(targetDirective, mpf, 1, 0, 8) val mainBlock = module.statements.filterIsInstance()[0] - assertPositionOf(mainBlock, mpf, 2, 0) // TODO: endCol wrong! + assertPositionOf(mainBlock, mpf, 2, 0, 3) val startSub = mainBlock.statements.filterIsInstance()[0] - assertPositionOf(startSub, mpf, 3, 4) // TODO: endCol wrong! + assertPositionOf(startSub, mpf, 3, 4, 6) val declFoo = startSub.statements.filterIsInstance()[0] - assertPositionOf(declFoo, mpf, 4, 8) // TODO: endCol wrong! + assertPositionOf(declFoo, mpf, 4, 8, 12) val rhsFoo = declFoo.value!! - assertPositionOf(rhsFoo, mpf, 4, 20) // TODO: endCol wrong! + assertPositionOf(rhsFoo, mpf, 4, 20, 21) val declBar = startSub.statements.filterIsInstance()[1] - assertPositionOf(declBar, mpf, 5, 8) // TODO: endCol wrong! + assertPositionOf(declBar, mpf, 5, 8, 12) val whenStmt = startSub.statements.filterIsInstance()[0] - assertPositionOf(whenStmt, mpf, 6, 8) // TODO: endCol wrong! - assertPositionOf(whenStmt.choices[0], mpf, 7, 12) // TODO: endCol wrong! - assertPositionOf(whenStmt.choices[1], mpf, 8, 12) // TODO: endCol wrong! - assertPositionOf(whenStmt.choices[2], mpf, 9, 12) // TODO: endCol wrong! + assertPositionOf(whenStmt, mpf, 6, 8, 11) + assertPositionOf(whenStmt.choices[0], mpf, 7, 12, 13) + assertPositionOf(whenStmt.choices[1], mpf, 8, 12, 13) + assertPositionOf(whenStmt.choices[2], mpf, 9, 12, 15) } }