From 40aa733ea74942a701605109e36ec7bd2808f4d3 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 15 Aug 2022 20:55:35 +0200 Subject: [PATCH] clearer name --- codeAst/src/prog8/code/SymbolTable.kt | 20 +++++++++---------- .../codegen/cpu6502/ProgramAndVarsGen.kt | 18 ++++++++--------- .../codegen/experimental/AstToXmlConverter.kt | 16 +++++++-------- .../codegen/virtual/VariableAllocator.kt | 16 +++++++-------- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/codeAst/src/prog8/code/SymbolTable.kt b/codeAst/src/prog8/code/SymbolTable.kt index a166c0b1c..ce161717b 100644 --- a/codeAst/src/prog8/code/SymbolTable.kt +++ b/codeAst/src/prog8/code/SymbolTable.kt @@ -163,26 +163,26 @@ open class StNode(val name: String, class StStaticVariable(name: String, val dt: DataType, - val initialNumericValue: Double?, - val initialStringValue: StString?, - val initialArrayValue: StArray?, + val onetimeInitializationNumericValue: Double?, // regular (every-run-time) initialization is done via regular assignments + val onetimeInitializationStringValue: StString?, + val onetimeInitializationArrayValue: StArray?, val length: Int?, // for arrays: the number of elements, for strings: number of characters *including* the terminating 0-byte val zpwish: ZeropageWish, position: Position) : StNode(name, StNodeType.STATICVAR, position) { init { if(length!=null) { - require(initialNumericValue == null) - if(initialArrayValue!=null) - require(length == initialArrayValue.size) + require(onetimeInitializationNumericValue == null) + if(onetimeInitializationArrayValue!=null) + require(length == onetimeInitializationArrayValue.size) } - if(initialNumericValue!=null) + if(onetimeInitializationNumericValue!=null) require(dt in NumericDatatypes) - if(initialArrayValue!=null) + if(onetimeInitializationArrayValue!=null) require(dt in ArrayDatatypes) - if(initialStringValue!=null) { + if(onetimeInitializationStringValue!=null) { require(dt == DataType.STR) - require(length == initialStringValue.first.length+1) + require(length == onetimeInitializationStringValue.first.length+1) } } diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt index cdf244327..5c98ce8b4 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt @@ -450,8 +450,8 @@ internal class ProgramAndVarsGen( val vars = allocator.zeropageVars.filter { it.value.dt==DataType.STR } for (variable in vars) { val svar = symboltable.flat.getValue(variable.key) as StStaticVariable - if(svar.initialStringValue!=null) - result.add(ZpStringWithInitial(variable.key, variable.value, svar.initialStringValue!!)) + if(svar.onetimeInitializationStringValue!=null) + result.add(ZpStringWithInitial(variable.key, variable.value, svar.onetimeInitializationStringValue!!)) } return result } @@ -461,8 +461,8 @@ internal class ProgramAndVarsGen( val vars = allocator.zeropageVars.filter { it.value.dt in ArrayDatatypes } for (variable in vars) { val svar = symboltable.flat.getValue(variable.key) as StStaticVariable - if(svar.initialArrayValue!=null) - result.add(ZpArrayWithInitial(variable.key, variable.value, svar.initialArrayValue!!)) + if(svar.onetimeInitializationArrayValue!=null) + result.add(ZpArrayWithInitial(variable.key, variable.value, svar.onetimeInitializationArrayValue!!)) } return result } @@ -481,7 +481,7 @@ internal class ProgramAndVarsGen( asmgen.out("; non-zeropage variables") val (stringvars, othervars) = variables.partition { it.dt==DataType.STR } stringvars.forEach { - outputStringvar(it.name, it.initialStringValue!!.second, it.initialStringValue!!.first) + outputStringvar(it.name, it.onetimeInitializationStringValue!!.second, it.onetimeInitializationStringValue!!.first) } othervars.sortedBy { it.type }.forEach { staticVariable2asm(it) @@ -491,11 +491,11 @@ internal class ProgramAndVarsGen( private fun staticVariable2asm(variable: StStaticVariable) { val name = variable.name val initialValue: Number = - if(variable.initialNumericValue!=null) { + if(variable.onetimeInitializationNumericValue!=null) { if(variable.dt== DataType.FLOAT) - variable.initialNumericValue!! + variable.onetimeInitializationNumericValue!! else - variable.initialNumericValue!!.toInt() + variable.onetimeInitializationNumericValue!!.toInt() } else 0 when (variable.dt) { @@ -514,7 +514,7 @@ internal class ProgramAndVarsGen( DataType.STR -> { throw AssemblyError("all string vars should have been interned into prog") } - in ArrayDatatypes -> arrayVariable2asm(name, variable.dt, variable.initialArrayValue, variable.length) + in ArrayDatatypes -> arrayVariable2asm(name, variable.dt, variable.onetimeInitializationArrayValue, variable.length) else -> { throw AssemblyError("weird dt") } diff --git a/codeGenExperimental/src/prog8/codegen/experimental/AstToXmlConverter.kt b/codeGenExperimental/src/prog8/codegen/experimental/AstToXmlConverter.kt index 5c6cc5cf5..3c3ce62ae 100644 --- a/codeGenExperimental/src/prog8/codegen/experimental/AstToXmlConverter.kt +++ b/codeGenExperimental/src/prog8/codegen/experimental/AstToXmlConverter.kt @@ -75,24 +75,24 @@ class AstToXmlConverter(internal val program: PtProgram, xml.attr("zpwish", node.zpwish.name) if(node.length!=null) xml.attr("length", node.length.toString()) - if(node.initialNumericValue!=null || node.initialArrayValue!=null || node.initialStringValue!=null) { + if(node.onetimeInitializationNumericValue!=null || node.onetimeInitializationArrayValue!=null || node.onetimeInitializationStringValue!=null) { xml.startChildren() - if(node.initialNumericValue!=null) { - writeNumber(node.dt, node.initialNumericValue!!) + if(node.onetimeInitializationNumericValue!=null) { + writeNumber(node.dt, node.onetimeInitializationNumericValue!!) } - if(node.initialStringValue!=null) { + if(node.onetimeInitializationStringValue!=null) { xml.writeTextNode( "string", - listOf(Pair("encoding", node.initialStringValue!!.second.name)), - node.initialStringValue!!.first, + listOf(Pair("encoding", node.onetimeInitializationStringValue!!.second.name)), + node.onetimeInitializationStringValue!!.first, false ) } - if(node.initialArrayValue!=null) { + if(node.onetimeInitializationArrayValue!=null) { xml.elt("array") xml.startChildren() val eltDt = ArrayToElementTypes.getValue(node.dt) - node.initialArrayValue!!.forEach { + node.onetimeInitializationArrayValue!!.forEach { if(it.number!=null) { writeNumber(eltDt, it.number!!) } diff --git a/codeGenVirtual/src/prog8/codegen/virtual/VariableAllocator.kt b/codeGenVirtual/src/prog8/codegen/virtual/VariableAllocator.kt index 0cd76ec9d..01a01b6d6 100644 --- a/codeGenVirtual/src/prog8/codegen/virtual/VariableAllocator.kt +++ b/codeGenVirtual/src/prog8/codegen/virtual/VariableAllocator.kt @@ -17,7 +17,7 @@ class VariableAllocator(private val st: SymbolTable, private val program: PtProg for (variable in st.allVariables) { val memsize = when (variable.dt) { - DataType.STR -> variable.initialStringValue!!.first.length + 1 // include the zero byte + DataType.STR -> variable.onetimeInitializationStringValue!!.first.length + 1 // include the zero byte in NumericDatatypes -> program.memsizer.memorySize(variable.dt) in ArrayDatatypes -> program.memsizer.memorySize(variable.dt, variable.length!!) else -> throw InternalCompilerException("weird dt") @@ -57,22 +57,22 @@ class VariableAllocator(private val st: SymbolTable, private val program: PtProg else -> throw InternalCompilerException("weird dt") } val value = when(variable.dt) { - DataType.FLOAT -> (variable.initialNumericValue ?: 0.0).toString() - in NumericDatatypes -> (variable.initialNumericValue ?: 0).toHex() + DataType.FLOAT -> (variable.onetimeInitializationNumericValue ?: 0.0).toString() + in NumericDatatypes -> (variable.onetimeInitializationNumericValue ?: 0).toHex() DataType.STR -> { - val encoded = program.encoding.encodeString(variable.initialStringValue!!.first, variable.initialStringValue!!.second) + listOf(0u) + val encoded = program.encoding.encodeString(variable.onetimeInitializationStringValue!!.first, variable.onetimeInitializationStringValue!!.second) + listOf(0u) encoded.joinToString(",") { it.toInt().toHex() } } DataType.ARRAY_F -> { - if(variable.initialArrayValue!=null) { - variable.initialArrayValue!!.joinToString(",") { it.number!!.toString() } + if(variable.onetimeInitializationArrayValue!=null) { + variable.onetimeInitializationArrayValue!!.joinToString(",") { it.number!!.toString() } } else { (1..variable.length!!).joinToString(",") { "0" } } } in ArrayDatatypes -> { - if(variable.initialArrayValue!==null) { - variable.initialArrayValue!!.joinToString(",") { it.number!!.toHex() } + if(variable.onetimeInitializationArrayValue!==null) { + variable.onetimeInitializationArrayValue!!.joinToString(",") { it.number!!.toHex() } } else { (1..variable.length!!).joinToString(",") { "0" } }