From f7e74b30884bebc8325f2ccdc9cb1fe5e334a0d1 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 10 Feb 2022 03:18:56 +0100 Subject: [PATCH] naming --- .../src/prog8/codegen/cpu6502/AsmGen.kt | 2 +- .../{ProgramGen.kt => ProgramAndVarsGen.kt} | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) rename codeGenCpu6502/src/prog8/codegen/cpu6502/{ProgramGen.kt => ProgramAndVarsGen.kt} (97%) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt index 5c23723d2..ac5a5b3df 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -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) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt similarity index 97% rename from codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramGen.kt rename to codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt index e1424a7b5..b3bc40ca2 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt @@ -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)