mirror of
https://github.com/irmen/prog8.git
synced 2025-02-22 16:29:05 +00:00
fixed a variable scopedname issue where it took the fully scoped name instead of just the local name
this made 64tass not strip out that code if it was unused
This commit is contained in:
parent
a4f7512d44
commit
c7b1e8d772
@ -5,6 +5,7 @@ import prog8.code.core.*
|
||||
|
||||
sealed interface IPtSubroutine {
|
||||
val name: String
|
||||
val scopedName: String
|
||||
}
|
||||
|
||||
class PtAsmSub(
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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!!
|
||||
|
@ -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)
|
||||
|
@ -1691,7 +1691,7 @@ class IRCodeGen(
|
||||
|
||||
private fun translate(parameters: List<PtSubroutineParameter>) =
|
||||
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
|
||||
|
@ -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()
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user