This commit is contained in:
Irmen de Jong 2022-02-10 03:18:56 +01:00
parent 343f01d5e1
commit f7e74b3088
2 changed files with 15 additions and 8 deletions

View File

@ -34,7 +34,7 @@ class AsmGen(internal val program: Program,
private val postincrdecrAsmGen = PostIncrDecrAsmGen(program, this)
private val functioncallAsmGen = FunctionCallAsmGen(program, this)
private val expressionsAsmGen = ExpressionsAsmGen(program, this, allocator)
private val programGen = ProgramGen(program, variables, options, errors, functioncallAsmGen, this, allocator, zeropage)
private val programGen = ProgramAndVarsGen(program, variables, options, errors, functioncallAsmGen, this, allocator, zeropage)
private val assignmentAsmGen = AssignmentAsmGen(program, this, allocator)
private val builtinFunctionsAsmGen = BuiltinFunctionsAsmGen(program, this, assignmentAsmGen, allocator)

View File

@ -12,8 +12,15 @@ import java.time.LocalDate
import java.time.LocalDateTime
import kotlin.math.absoluteValue
internal class ProgramGen(
/**
* Generates the main parts of the program:
* - entry/exit code
* - initialization routines
* - blocks
* - subroutines
* - all variables (note: VarDecl ast nodes are *NOT* used anymore for this! now uses IVariablesAndConsts data tables!)
*/
internal class ProgramAndVarsGen(
val program: Program,
val variables: IVariablesAndConsts,
val options: CompilationOptions,
@ -328,7 +335,7 @@ internal class ProgramGen(
arrayVarsWithInitInZp.forEach {
val varname = asmgen.asmVariableName(it.key)+"_init_value"
arrayVardecl2asm(varname, it.value.dt, it.value.initialArrayValue!!, null)
arrayVariable2asm(varname, it.value.dt, it.value.initialArrayValue!!, null)
}
asmgen.out("""+ tsx
@ -365,11 +372,11 @@ internal class ProgramGen(
outputStringvar(it.scopedname.last(), it.type, stringvalue.encoding, stringvalue.value)
}
othervars.sortedBy { it.type }.forEach {
vardecl2asm(it)
staticVariable2asm(it)
}
}
private fun vardecl2asm(variable: IVariablesAndConsts.StaticVariable) {
private fun staticVariable2asm(variable: IVariablesAndConsts.StaticVariable) {
val name = variable.scopedname.last()
val value = variable.initialValue
val staticValue: Number =
@ -402,14 +409,14 @@ internal class ProgramGen(
DataType.STR -> {
throw AssemblyError("all string vars should have been interned into prog")
}
in ArrayDatatypes -> arrayVardecl2asm(name, variable.type, value as? ArrayLiteralValue, variable.arraysize)
in ArrayDatatypes -> arrayVariable2asm(name, variable.type, value as? ArrayLiteralValue, variable.arraysize)
else -> {
throw AssemblyError("weird dt")
}
}
}
private fun arrayVardecl2asm(varname: String, dt: DataType, value: ArrayLiteralValue?, orNumberOfZeros: Int?) {
private fun arrayVariable2asm(varname: String, dt: DataType, value: ArrayLiteralValue?, orNumberOfZeros: Int?) {
when(dt) {
DataType.ARRAY_UB -> {
val data = makeArrayFillDataUnsigned(dt, value, orNumberOfZeros)