fix various IR file and symboltable issues

This commit is contained in:
Irmen de Jong
2023-03-06 21:42:08 +01:00
parent 8acd94fc89
commit fd07ae5225
15 changed files with 595 additions and 160 deletions
+7 -2
View File
@@ -133,7 +133,7 @@ open class StNode(val name: String,
}
private val scopedNameList: List<String> by lazy {
if(type== StNodeType.GLOBAL)
if(type==StNodeType.GLOBAL)
emptyList()
else
parent.scopedNameList + name
@@ -142,7 +142,7 @@ open class StNode(val name: String,
private fun lookup(scopedName: List<String>): StNode? {
// a scoped name refers to a name in another namespace, and always stars from the root.
var node = this
while(node.type!= StNodeType.GLOBAL)
while(node.type!=StNodeType.GLOBAL)
node = node.parent
for(name in scopedName) {
@@ -201,6 +201,11 @@ class StMemVar(name: String,
val length: Int?, // for arrays: the number of elements, for strings: number of characters *including* the terminating 0-byte
astNode: PtNode) :
StNode(name, StNodeType.MEMVAR, astNode) {
init{
if(dt in ArrayDatatypes || dt == DataType.STR)
require(length!=null) { "memory mapped array or string must have known length" }
}
}
class StMemorySlab(
+3 -3
View File
@@ -26,11 +26,11 @@ class SymbolTableMaker(private val program: PtProgram, private val options: Comp
PtMemMapped("P8ZP_SCRATCH_REG", DataType.UBYTE, options.compTarget.machine.zeropage.SCRATCH_REG, null, Position.DUMMY),
PtMemMapped("P8ZP_SCRATCH_W1", DataType.UWORD, options.compTarget.machine.zeropage.SCRATCH_W1, null, Position.DUMMY),
PtMemMapped("P8ZP_SCRATCH_W2", DataType.UWORD, options.compTarget.machine.zeropage.SCRATCH_W2, null, Position.DUMMY),
PtMemMapped("P8ESTACK_LO", DataType.ARRAY_UB, options.compTarget.machine.ESTACK_LO, 256u, Position.DUMMY),
PtMemMapped("P8ESTACK_HI", DataType.ARRAY_UB, options.compTarget.machine.ESTACK_HI, 256u, Position.DUMMY)
PtMemMapped("P8ESTACK_LO", DataType.ARRAY_UB, options.compTarget.machine.ESTACK_LO, 128u, Position.DUMMY),
PtMemMapped("P8ESTACK_HI", DataType.ARRAY_UB, options.compTarget.machine.ESTACK_HI, 128u, Position.DUMMY)
).forEach {
it.parent = program
st.add(StMemVar(it.name, it.type, it.address, null, it))
st.add(StMemVar(it.name, it.type, it.address, it.arraySize?.toInt(), it))
}
}