mirror of
https://github.com/irmen/prog8.git
synced 2025-01-26 19:30:59 +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,
|
class StStaticVariable(name: String,
|
||||||
val dt: DataType,
|
val dt: DataType,
|
||||||
val initialNumericValue: Double?,
|
val onetimeInitializationNumericValue: Double?, // regular (every-run-time) initialization is done via regular assignments
|
||||||
val initialStringValue: StString?,
|
val onetimeInitializationStringValue: StString?,
|
||||||
val initialArrayValue: StArray?,
|
val onetimeInitializationArrayValue: StArray?,
|
||||||
val length: Int?, // for arrays: the number of elements, for strings: number of characters *including* the terminating 0-byte
|
val length: Int?, // for arrays: the number of elements, for strings: number of characters *including* the terminating 0-byte
|
||||||
val zpwish: ZeropageWish,
|
val zpwish: ZeropageWish,
|
||||||
position: Position) : StNode(name, StNodeType.STATICVAR, position) {
|
position: Position) : StNode(name, StNodeType.STATICVAR, position) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if(length!=null) {
|
if(length!=null) {
|
||||||
require(initialNumericValue == null)
|
require(onetimeInitializationNumericValue == null)
|
||||||
if(initialArrayValue!=null)
|
if(onetimeInitializationArrayValue!=null)
|
||||||
require(length == initialArrayValue.size)
|
require(length == onetimeInitializationArrayValue.size)
|
||||||
}
|
}
|
||||||
if(initialNumericValue!=null)
|
if(onetimeInitializationNumericValue!=null)
|
||||||
require(dt in NumericDatatypes)
|
require(dt in NumericDatatypes)
|
||||||
if(initialArrayValue!=null)
|
if(onetimeInitializationArrayValue!=null)
|
||||||
require(dt in ArrayDatatypes)
|
require(dt in ArrayDatatypes)
|
||||||
if(initialStringValue!=null) {
|
if(onetimeInitializationStringValue!=null) {
|
||||||
require(dt == DataType.STR)
|
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 }
|
val vars = allocator.zeropageVars.filter { it.value.dt==DataType.STR }
|
||||||
for (variable in vars) {
|
for (variable in vars) {
|
||||||
val svar = symboltable.flat.getValue(variable.key) as StStaticVariable
|
val svar = symboltable.flat.getValue(variable.key) as StStaticVariable
|
||||||
if(svar.initialStringValue!=null)
|
if(svar.onetimeInitializationStringValue!=null)
|
||||||
result.add(ZpStringWithInitial(variable.key, variable.value, svar.initialStringValue!!))
|
result.add(ZpStringWithInitial(variable.key, variable.value, svar.onetimeInitializationStringValue!!))
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -461,8 +461,8 @@ internal class ProgramAndVarsGen(
|
|||||||
val vars = allocator.zeropageVars.filter { it.value.dt in ArrayDatatypes }
|
val vars = allocator.zeropageVars.filter { it.value.dt in ArrayDatatypes }
|
||||||
for (variable in vars) {
|
for (variable in vars) {
|
||||||
val svar = symboltable.flat.getValue(variable.key) as StStaticVariable
|
val svar = symboltable.flat.getValue(variable.key) as StStaticVariable
|
||||||
if(svar.initialArrayValue!=null)
|
if(svar.onetimeInitializationArrayValue!=null)
|
||||||
result.add(ZpArrayWithInitial(variable.key, variable.value, svar.initialArrayValue!!))
|
result.add(ZpArrayWithInitial(variable.key, variable.value, svar.onetimeInitializationArrayValue!!))
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -481,7 +481,7 @@ internal class ProgramAndVarsGen(
|
|||||||
asmgen.out("; non-zeropage variables")
|
asmgen.out("; non-zeropage variables")
|
||||||
val (stringvars, othervars) = variables.partition { it.dt==DataType.STR }
|
val (stringvars, othervars) = variables.partition { it.dt==DataType.STR }
|
||||||
stringvars.forEach {
|
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 {
|
othervars.sortedBy { it.type }.forEach {
|
||||||
staticVariable2asm(it)
|
staticVariable2asm(it)
|
||||||
@ -491,11 +491,11 @@ internal class ProgramAndVarsGen(
|
|||||||
private fun staticVariable2asm(variable: StStaticVariable) {
|
private fun staticVariable2asm(variable: StStaticVariable) {
|
||||||
val name = variable.name
|
val name = variable.name
|
||||||
val initialValue: Number =
|
val initialValue: Number =
|
||||||
if(variable.initialNumericValue!=null) {
|
if(variable.onetimeInitializationNumericValue!=null) {
|
||||||
if(variable.dt== DataType.FLOAT)
|
if(variable.dt== DataType.FLOAT)
|
||||||
variable.initialNumericValue!!
|
variable.onetimeInitializationNumericValue!!
|
||||||
else
|
else
|
||||||
variable.initialNumericValue!!.toInt()
|
variable.onetimeInitializationNumericValue!!.toInt()
|
||||||
} else 0
|
} else 0
|
||||||
|
|
||||||
when (variable.dt) {
|
when (variable.dt) {
|
||||||
@ -514,7 +514,7 @@ internal class ProgramAndVarsGen(
|
|||||||
DataType.STR -> {
|
DataType.STR -> {
|
||||||
throw AssemblyError("all string vars should have been interned into prog")
|
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 -> {
|
else -> {
|
||||||
throw AssemblyError("weird dt")
|
throw AssemblyError("weird dt")
|
||||||
}
|
}
|
||||||
|
@ -75,24 +75,24 @@ class AstToXmlConverter(internal val program: PtProgram,
|
|||||||
xml.attr("zpwish", node.zpwish.name)
|
xml.attr("zpwish", node.zpwish.name)
|
||||||
if(node.length!=null)
|
if(node.length!=null)
|
||||||
xml.attr("length", node.length.toString())
|
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()
|
xml.startChildren()
|
||||||
if(node.initialNumericValue!=null) {
|
if(node.onetimeInitializationNumericValue!=null) {
|
||||||
writeNumber(node.dt, node.initialNumericValue!!)
|
writeNumber(node.dt, node.onetimeInitializationNumericValue!!)
|
||||||
}
|
}
|
||||||
if(node.initialStringValue!=null) {
|
if(node.onetimeInitializationStringValue!=null) {
|
||||||
xml.writeTextNode(
|
xml.writeTextNode(
|
||||||
"string",
|
"string",
|
||||||
listOf(Pair("encoding", node.initialStringValue!!.second.name)),
|
listOf(Pair("encoding", node.onetimeInitializationStringValue!!.second.name)),
|
||||||
node.initialStringValue!!.first,
|
node.onetimeInitializationStringValue!!.first,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if(node.initialArrayValue!=null) {
|
if(node.onetimeInitializationArrayValue!=null) {
|
||||||
xml.elt("array")
|
xml.elt("array")
|
||||||
xml.startChildren()
|
xml.startChildren()
|
||||||
val eltDt = ArrayToElementTypes.getValue(node.dt)
|
val eltDt = ArrayToElementTypes.getValue(node.dt)
|
||||||
node.initialArrayValue!!.forEach {
|
node.onetimeInitializationArrayValue!!.forEach {
|
||||||
if(it.number!=null) {
|
if(it.number!=null) {
|
||||||
writeNumber(eltDt, it.number!!)
|
writeNumber(eltDt, it.number!!)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ class VariableAllocator(private val st: SymbolTable, private val program: PtProg
|
|||||||
for (variable in st.allVariables) {
|
for (variable in st.allVariables) {
|
||||||
val memsize =
|
val memsize =
|
||||||
when (variable.dt) {
|
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 NumericDatatypes -> program.memsizer.memorySize(variable.dt)
|
||||||
in ArrayDatatypes -> program.memsizer.memorySize(variable.dt, variable.length!!)
|
in ArrayDatatypes -> program.memsizer.memorySize(variable.dt, variable.length!!)
|
||||||
else -> throw InternalCompilerException("weird dt")
|
else -> throw InternalCompilerException("weird dt")
|
||||||
@ -57,22 +57,22 @@ class VariableAllocator(private val st: SymbolTable, private val program: PtProg
|
|||||||
else -> throw InternalCompilerException("weird dt")
|
else -> throw InternalCompilerException("weird dt")
|
||||||
}
|
}
|
||||||
val value = when(variable.dt) {
|
val value = when(variable.dt) {
|
||||||
DataType.FLOAT -> (variable.initialNumericValue ?: 0.0).toString()
|
DataType.FLOAT -> (variable.onetimeInitializationNumericValue ?: 0.0).toString()
|
||||||
in NumericDatatypes -> (variable.initialNumericValue ?: 0).toHex()
|
in NumericDatatypes -> (variable.onetimeInitializationNumericValue ?: 0).toHex()
|
||||||
DataType.STR -> {
|
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() }
|
encoded.joinToString(",") { it.toInt().toHex() }
|
||||||
}
|
}
|
||||||
DataType.ARRAY_F -> {
|
DataType.ARRAY_F -> {
|
||||||
if(variable.initialArrayValue!=null) {
|
if(variable.onetimeInitializationArrayValue!=null) {
|
||||||
variable.initialArrayValue!!.joinToString(",") { it.number!!.toString() }
|
variable.onetimeInitializationArrayValue!!.joinToString(",") { it.number!!.toString() }
|
||||||
} else {
|
} else {
|
||||||
(1..variable.length!!).joinToString(",") { "0" }
|
(1..variable.length!!).joinToString(",") { "0" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in ArrayDatatypes -> {
|
in ArrayDatatypes -> {
|
||||||
if(variable.initialArrayValue!==null) {
|
if(variable.onetimeInitializationArrayValue!==null) {
|
||||||
variable.initialArrayValue!!.joinToString(",") { it.number!!.toHex() }
|
variable.onetimeInitializationArrayValue!!.joinToString(",") { it.number!!.toHex() }
|
||||||
} else {
|
} else {
|
||||||
(1..variable.length!!).joinToString(",") { "0" }
|
(1..variable.length!!).joinToString(",") { "0" }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user