fix variable zpwish

This commit is contained in:
Irmen de Jong 2023-02-11 15:14:37 +01:00
parent 8f904f75bb
commit 75bd66326a
6 changed files with 15 additions and 15 deletions

View File

@ -102,8 +102,7 @@ class SymbolTableMaker(private val program: PtProgram, private val options: Comp
initialString = null initialString = null
numElements = node.arraySize?.toInt() numElements = node.arraySize?.toInt()
} }
val zeropage = ZeropageWish.DONTCARE // TODO how, can this be removed from the ST perhaps? Or is it required in the variable allocator later StStaticVariable(node.name, node.type, bss, initialNumeric, initialString, initialArray, numElements, node.zeropage, node)
StStaticVariable(node.name, node.type, bss, initialNumeric, initialString, initialArray, numElements, zeropage, node)
} }
is PtBuiltinFunctionCall -> { is PtBuiltinFunctionCall -> {
if(node.name=="memory") { if(node.name=="memory") {

View File

@ -198,7 +198,7 @@ sealed interface IPtVariable {
} }
class PtVariable(name: String, override val type: DataType, var value: PtExpression?, var arraySize: UInt?, position: Position) : PtNamedNode(name, position), IPtVariable { class PtVariable(name: String, override val type: DataType, val zeropage: ZeropageWish, var value: PtExpression?, var arraySize: UInt?, position: Position) : PtNamedNode(name, position), IPtVariable {
override fun printProperties() { override fun printProperties() {
print("$type $name") print("$type $name")
} }

View File

@ -344,7 +344,7 @@ class IntermediateAstMaker(private val program: Program, private val options: Co
return when(srcVar.type) { return when(srcVar.type) {
VarDeclType.VAR -> { VarDeclType.VAR -> {
val value = if(srcVar.value!=null) transformExpression(srcVar.value!!) else null val value = if(srcVar.value!=null) transformExpression(srcVar.value!!) else null
PtVariable(srcVar.name, srcVar.datatype, value, srcVar.arraysize?.constIndex()?.toUInt(), srcVar.position) PtVariable(srcVar.name, srcVar.datatype, srcVar.zeropage, value, srcVar.arraysize?.constIndex()?.toUInt(), srcVar.position)
} }
VarDeclType.CONST -> PtConstant(srcVar.name, srcVar.datatype, (srcVar.value as NumericLiteral).number, srcVar.position) VarDeclType.CONST -> PtConstant(srcVar.name, srcVar.datatype, (srcVar.value as NumericLiteral).number, srcVar.position)
VarDeclType.MEMORY -> PtMemMapped(srcVar.name, srcVar.datatype, (srcVar.value as NumericLiteral).number.toUInt(), srcVar.arraysize?.constIndex()?.toUInt(), srcVar.position) VarDeclType.MEMORY -> PtMemMapped(srcVar.name, srcVar.datatype, (srcVar.value as NumericLiteral).number.toUInt(), srcVar.arraysize?.constIndex()?.toUInt(), srcVar.position)

View File

@ -91,10 +91,10 @@ private fun makeSt(): SymbolTable {
astBlock1.add(astConstant2) astBlock1.add(astConstant2)
val astSub1 = PtSub("sub1", emptyList(), null, Position.DUMMY) val astSub1 = PtSub("sub1", emptyList(), null, Position.DUMMY)
val astSub2 = PtSub("sub2", emptyList(), null, Position.DUMMY) val astSub2 = PtSub("sub2", emptyList(), null, Position.DUMMY)
val astSub1v1 = PtVariable("v1", DataType.BYTE, null, null, Position.DUMMY) val astSub1v1 = PtVariable("v1", DataType.BYTE, ZeropageWish.DONTCARE, null, null, Position.DUMMY)
val astSub1v2 = PtVariable("v2", DataType.BYTE, null, null, Position.DUMMY) val astSub1v2 = PtVariable("v2", DataType.BYTE, ZeropageWish.DONTCARE,null, null, Position.DUMMY)
val astSub2v1 = PtVariable("v1", DataType.BYTE, null, null, Position.DUMMY) val astSub2v1 = PtVariable("v1", DataType.BYTE, ZeropageWish.DONTCARE,null, null, Position.DUMMY)
val astSub2v2 = PtVariable("v2", DataType.BYTE, null, null, Position.DUMMY) val astSub2v2 = PtVariable("v2", DataType.BYTE, ZeropageWish.DONTCARE,null, null, Position.DUMMY)
astSub1.add(astSub1v1) astSub1.add(astSub1v1)
astSub1.add(astSub1v2) astSub1.add(astSub1v2)
astSub2.add(astSub2v2) astSub2.add(astSub2v2)

View File

@ -171,7 +171,7 @@ class IRFileReader {
val arraysize = if(arrayspec.isNotBlank()) arrayspec.substring(1, arrayspec.length-1).toInt() else null val arraysize = if(arrayspec.isNotBlank()) arrayspec.substring(1, arrayspec.length-1).toInt() else null
val dt: DataType = parseDatatype(type, arraysize!=null) val dt: DataType = parseDatatype(type, arraysize!=null)
val zp = if(zpwish.isBlank()) ZeropageWish.DONTCARE else ZeropageWish.valueOf(zpwish) val zp = if(zpwish.isBlank()) ZeropageWish.DONTCARE else ZeropageWish.valueOf(zpwish)
val dummyNode = PtVariable(name, dt, null, null, Position.DUMMY) val dummyNode = PtVariable(name, dt, zp, null, null, Position.DUMMY)
val newVar = StStaticVariable(name, dt, true, null, null, null, arraysize, zp, dummyNode) val newVar = StStaticVariable(name, dt, true, null, null, null, arraysize, zp, dummyNode)
bssVariables.add(newVar) bssVariables.add(newVar)
} }
@ -234,7 +234,7 @@ class IRFileReader {
else -> throw IRParseException("weird dt") else -> throw IRParseException("weird dt")
} }
require(!bss) { "bss var should be in BSS section" } require(!bss) { "bss var should be in BSS section" }
val dummyNode = PtVariable(name, dt, null, null, Position.DUMMY) val dummyNode = PtVariable(name, dt, zp, null, null, Position.DUMMY)
variables.add(StStaticVariable(name, dt, bss, initNumeric, null, initArray, arraysize, zp, dummyNode)) variables.add(StStaticVariable(name, dt, bss, initNumeric, null, initArray, arraysize, zp, dummyNode))
} }
return variables return variables
@ -261,7 +261,7 @@ class IRFileReader {
val (type, arrayspec, name, address) = match.destructured val (type, arrayspec, name, address) = match.destructured
val arraysize = if(arrayspec.isNotBlank()) arrayspec.substring(1, arrayspec.length-1).toInt() else null val arraysize = if(arrayspec.isNotBlank()) arrayspec.substring(1, arrayspec.length-1).toInt() else null
val dt: DataType = parseDatatype(type, arraysize!=null) val dt: DataType = parseDatatype(type, arraysize!=null)
val dummyNode = PtVariable(name, dt, null, null, Position.DUMMY) val dummyNode = PtVariable(name, dt, ZeropageWish.NOT_IN_ZEROPAGE, null, null, Position.DUMMY)
memvars.add(StMemVar(name, dt, parseIRValue(address).toUInt(), arraysize, dummyNode)) memvars.add(StMemVar(name, dt, parseIRValue(address).toUInt(), arraysize, dummyNode))
} }
memvars memvars
@ -284,7 +284,7 @@ class IRFileReader {
// example: "SLAB slabname 4096 0" // example: "SLAB slabname 4096 0"
val match = slabPattern.matchEntire(line) ?: throw IRParseException("invalid SLAB $line") val match = slabPattern.matchEntire(line) ?: throw IRParseException("invalid SLAB $line")
val (name, size, align) = match.destructured val (name, size, align) = match.destructured
val dummyNode = PtVariable(name, DataType.ARRAY_UB, null, null, Position.DUMMY) val dummyNode = PtVariable(name, DataType.ARRAY_UB, ZeropageWish.NOT_IN_ZEROPAGE, null, null, Position.DUMMY)
slabs.add(StMemorySlab(name, size.toUInt(), align.toUInt(), dummyNode)) slabs.add(StMemorySlab(name, size.toUInt(), align.toUInt(), dummyNode))
} }
slabs slabs

View File

@ -3,6 +3,7 @@ package prog8.intermediate
import prog8.code.* import prog8.code.*
import prog8.code.ast.PtVariable import prog8.code.ast.PtVariable
import prog8.code.core.DataType import prog8.code.core.DataType
import prog8.code.core.ZeropageWish
// In the Intermediate Representation, all nesting has been removed. // In the Intermediate Representation, all nesting has been removed.
@ -73,7 +74,7 @@ class IRSymbolTable(sourceSt: SymbolTable?) {
return newArray return newArray
} }
scopedName = variable.scopedName scopedName = variable.scopedName
val dummyNode = PtVariable(scopedName, variable.dt, null, null, variable.astNode.position) val dummyNode = PtVariable(scopedName, variable.dt, variable.zpwish, null, null, variable.astNode.position)
varToadd = StStaticVariable(scopedName, variable.dt, variable.bss, varToadd = StStaticVariable(scopedName, variable.dt, variable.bss,
variable.onetimeInitializationNumericValue, variable.onetimeInitializationNumericValue,
variable.onetimeInitializationStringValue, variable.onetimeInitializationStringValue,
@ -95,7 +96,7 @@ class IRSymbolTable(sourceSt: SymbolTable?) {
varToadd = variable varToadd = variable
} else { } else {
scopedName = variable.scopedName scopedName = variable.scopedName
val dummyNode = PtVariable(scopedName, variable.dt, null, null, variable.astNode.position) val dummyNode = PtVariable(scopedName, variable.dt, ZeropageWish.NOT_IN_ZEROPAGE, null, null, variable.astNode.position)
varToadd = StMemVar(scopedName, variable.dt, variable.address, variable.length, dummyNode) varToadd = StMemVar(scopedName, variable.dt, variable.address, variable.length, dummyNode)
} }
table[scopedName] = varToadd table[scopedName] = varToadd
@ -105,7 +106,7 @@ class IRSymbolTable(sourceSt: SymbolTable?) {
val varToadd = if('.' in variable.name) val varToadd = if('.' in variable.name)
variable variable
else { else {
val dummyNode = PtVariable(variable.name, DataType.ARRAY_UB, null, null, variable.astNode.position) val dummyNode = PtVariable(variable.name, DataType.ARRAY_UB, ZeropageWish.NOT_IN_ZEROPAGE, null, null, variable.astNode.position)
StMemorySlab("prog8_slabs.${variable.name}", variable.size, variable.align, dummyNode) StMemorySlab("prog8_slabs.${variable.name}", variable.size, variable.align, dummyNode)
} }
table[varToadd.name] = varToadd table[varToadd.name] = varToadd