diff --git a/codeCore/src/prog8/code/ast/AstStatements.kt b/codeCore/src/prog8/code/ast/AstStatements.kt index 083408304..ca6f9a999 100644 --- a/codeCore/src/prog8/code/ast/AstStatements.kt +++ b/codeCore/src/prog8/code/ast/AstStatements.kt @@ -5,6 +5,7 @@ import prog8.code.core.* sealed interface IPtSubroutine { val name: String + val scopedName: String } class PtAsmSub( diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt index e79afa364..5b152ad22 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -374,7 +374,7 @@ class AsmGen6502Internal ( val name = asmSymbolName(identifier.name) // see if we're inside a subroutine, if so, remove the whole prefix and just make the variable name locally scoped (64tass scopes it to the proper .proc block) - val subName = identifier.definingSub()?.scopedName + val subName = identifier.definingISub()?.scopedName return if (subName != null && name.length>subName.length && name.startsWith(subName) && name[subName.length] == '.') name.drop(subName.length + 1) else @@ -385,14 +385,14 @@ class AsmGen6502Internal ( val name = asmVariableName(identifier.name) // see if we're inside a subroutine, if so, remove the whole prefix and just make the variable name locally scoped (64tass scopes it to the proper .proc block) - val subName = identifier.definingSub()?.scopedName + val subName = identifier.definingISub()?.scopedName return if (subName != null && name.length>subName.length && name.startsWith(subName) && name[subName.length] == '.') name.drop(subName.length+1) else name } - fun asmVariableName(st: StNode, scope: PtSub?): String { + fun asmVariableName(st: StNode, scope: IPtSubroutine?): String { val name = asmVariableName(st.scopedName) if(scope==null) return name diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt index f690b595c..88aec8a20 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt @@ -205,7 +205,7 @@ internal class FunctionCallAsmGen(private val program: PtProgram, private val as if(value is PtIdentifier) { val addr = PtAddressOf(Position.DUMMY) addr.add(value) - addr.parent = sub as PtNode + addr.parent = scope as PtNode AsmAssignSource.fromAstSource(addr, program, asmgen).adjustSignedUnsigned(target) } else { AsmAssignSource.fromAstSource(value, program, asmgen).adjustSignedUnsigned(target) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt index 92a8d43e3..bfc1185b3 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AssignmentAsmGen.kt @@ -1879,7 +1879,7 @@ $endLabel""") } val symbol = asmgen.symbolTable.lookup(containment.haystackHeapVar!!.name)!! - val symbolName = asmgen.asmVariableName(symbol, containment.definingSub()) + val symbolName = asmgen.asmVariableName(symbol, containment.definingISub()) val (dt, numElements) = when(symbol) { is StStaticVariable -> symbol.dt to symbol.length!! is StMemVar -> symbol.dt to symbol.length!! diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt index efd6d943d..c6a0cd8b1 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt @@ -225,7 +225,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, SourceStorageKind.LITERALNUMBER -> inplacemodificationSplitWordWithLiteralval(target.asmVarname, target.datatype, index, operator, value.number!!.number.toInt()) else -> { // TODO: more optimized code for VARIABLE, REGISTER, MEMORY, ARRAY, EXPRESSION in the case of split-word arrays - val scope = target.origAstTarget?.definingSub() + val scope = target.origAstTarget?.definingISub() val regTarget = AsmAssignTarget.fromRegisters(RegisterOrPair.R0, false, target.position, scope, asmgen) val assignToReg = AsmAssignment(value, regTarget, program.memsizer, target.position) assignmentAsmGen.translateNormalAssignment(assignToReg, scope) diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt index da122a2d4..748035a56 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt @@ -1691,7 +1691,7 @@ class IRCodeGen( private fun translate(parameters: List) = parameters.map { - val flattenedName = it.definingSub()!!.name + "." + it.name + val flattenedName = it.definingISub()!!.name + "." + it.name if(symbolTable.lookup(flattenedName)==null) TODO("fix missing lookup for: $flattenedName parameter") val orig = symbolTable.lookup(flattenedName) as StStaticVariable diff --git a/compiler/res/prog8lib/cx16/diskio.p8 b/compiler/res/prog8lib/cx16/diskio.p8 index 66bcdceb4..afcb912aa 100644 --- a/compiler/res/prog8lib/cx16/diskio.p8 +++ b/compiler/res/prog8lib/cx16/diskio.p8 @@ -938,7 +938,7 @@ io_error: } sub read4hex() -> uword { - ubyte[5] hex = 0 + str hex = "0000" hex[0] = cbm.CHRIN() hex[1] = cbm.CHRIN() hex[2] = cbm.CHRIN() diff --git a/docs/source/todo.rst b/docs/source/todo.rst index be8a5ce11..ce1024254 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,33 +2,7 @@ TODO ==== callgraph issue? : if a sub contains another sub and it calls that, the outer sub is never removed even if it doesn't get called? - -There's an odd case that keeps unused subroutines marked as used , they don't get removed. Has to do with declaring string var. :: -it's a 64tass issue, caused by prog8 including full prefixed symbol name in the str case, and a local name in the array case.... - - %import conv - %option no_sysinit - - main { - sub start() { - cx16.r0++ - } - } - - stuff { - asmsub shim() { - %asm {{ - jmp p8s_read4hex - }} - } - - sub read4hex() -> uword { - ;ubyte[5] hex = 0 - str hex = "0000" ; TODO causes everything to be included , if declared as a byte array, nothing is included - return conv.hex2uword(hex) - } - } - +(diskio, when read4hex is placed back inside internal_f_tell() ) Improve register load order in subroutine call args assignments: diff --git a/examples/test.p8 b/examples/test.p8 index 41efef18b..29ab761e5 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,16 +1,18 @@ -%import textio -%zeropage basicsafe +%import conv %option no_sysinit main { sub start() { - uword @shared large = (320*240/8/8) - const uword WIDTH=320 - uword x1 = ((WIDTH-256)/2 as uword) + 200 - txt.print_uw(x1) - txt.nl() - x1 = ((WIDTH-256)/2) + 200 - txt.print_uw(x1) + read4hex() } -} + sub read4hex() -> uword { + str hex = "0000" + hex[0] = cbm.CHRIN() + hex[1] = cbm.CHRIN() + hex[2] = cbm.CHRIN() + hex[3] = cbm.CHRIN() + return conv.hex2uword(hex) + } + +}