mirror of
https://github.com/irmen/prog8.git
synced 2025-01-10 20:30:23 +00:00
clearer name
This commit is contained in:
parent
f37a822725
commit
40aa733ea7
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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!!)
|
||||
}
|
||||
|
@ -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" }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user