mirror of
https://github.com/irmen/prog8.git
synced 2025-01-10 20:30:23 +00:00
fix that memory("name", ...) also allocates a STR variable for the name
This commit is contained in:
parent
7bc75fd220
commit
74257163b1
@ -341,8 +341,9 @@ class AsmGen(private val program: Program,
|
||||
}
|
||||
}
|
||||
DataType.STR -> {
|
||||
val str = decl.value as StringLiteralValue
|
||||
outputStringvar(decl, compTarget.encodeString(str.value, str.altEncoding).plus(0.toUByte()))
|
||||
throw AssemblyError("all string vars should have been interned")
|
||||
// val str = decl.value as StringLiteralValue
|
||||
// outputStringvar(decl, compTarget.encodeString(str.value, str.altEncoding).plus(0.toUByte()))
|
||||
}
|
||||
DataType.ARRAY_UB -> {
|
||||
val data = makeArrayFillDataUnsigned(decl)
|
||||
@ -435,7 +436,7 @@ class AsmGen(private val program: Program,
|
||||
val vars = statements.filterIsInstance<VarDecl>().filter { it.type==VarDeclType.VAR }
|
||||
|
||||
val encodedstringVars = vars
|
||||
.filter {it.datatype == DataType.STR }
|
||||
.filter { it.datatype == DataType.STR && shouldActuallyOutputStringVar(it) }
|
||||
.map {
|
||||
val str = it.value as StringLiteralValue
|
||||
it to compTarget.encodeString(str.value, str.altEncoding).plus(0.toUByte())
|
||||
@ -456,6 +457,17 @@ class AsmGen(private val program: Program,
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldActuallyOutputStringVar(strvar: VarDecl): Boolean {
|
||||
if(strvar.sharedWithAsm)
|
||||
return true
|
||||
val uses = callGraph.usages(strvar)
|
||||
val onlyInMemoryFuncs = uses.all {
|
||||
val builtinfunc = (it.parent as? IFunctionCall)?.target?.targetStatement(program) as? BuiltinFunctionPlaceholder
|
||||
builtinfunc?.name=="memory"
|
||||
}
|
||||
return !onlyInMemoryFuncs
|
||||
}
|
||||
|
||||
private fun outputStringvar(strdecl: VarDecl, bytes: List<UByte>) {
|
||||
val sv = strdecl.value as StringLiteralValue
|
||||
val altEncoding = if(sv.altEncoding) "@" else ""
|
||||
|
@ -15,13 +15,13 @@ class TestVariables: FunSpec({
|
||||
val text = """
|
||||
main {
|
||||
sub start() {
|
||||
ubyte[] @shared array = [1,2,3,4]
|
||||
str @shared name = "test"
|
||||
ubyte[] @shared arrayvar = [1,2,3,4]
|
||||
str @shared stringvar = "test"
|
||||
ubyte @shared bytevar = 0
|
||||
|
||||
%asm {{
|
||||
lda array
|
||||
lda name
|
||||
lda arrayvar
|
||||
lda stringvar
|
||||
lda bytevar
|
||||
}}
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ class CallGraph(private val program: Program) : IAstVisitor {
|
||||
}
|
||||
|
||||
fun usages(decl: VarDecl): List<IdentifierReference> {
|
||||
if(decl.type!=VarDeclType.VAR || decl.autogeneratedDontRemove || decl.sharedWithAsm)
|
||||
if(decl.type!=VarDeclType.VAR)
|
||||
return emptyList()
|
||||
|
||||
if(decl.definingBlock !in usedBlocks)
|
||||
|
@ -3,7 +3,6 @@ TODO
|
||||
|
||||
For next compiler release (7.6)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
- fix that memory("name", ...) allocates a STR variable with contents "name" in the assembly source
|
||||
- make it possible to inline non-asmsub routines that just contain a single statement (return, functioncall, assignment)
|
||||
...
|
||||
|
||||
|
@ -8,6 +8,10 @@ main {
|
||||
sub start() {
|
||||
txt.print_uwhex(buffer, true)
|
||||
txt.print_uwhex(buffer2, true)
|
||||
txt.print_uwhex("zzzz", true)
|
||||
str xyz = "irmen"
|
||||
xyz="2342344234"
|
||||
txt.print_uwhex(xyz, true)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user