diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt index ac5a5b3df..64b1f3a8e 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -1,10 +1,13 @@ package prog8.codegen.cpu6502 import com.github.michaelbull.result.fold -import prog8.ast.* +import prog8.ast.IFunctionCall +import prog8.ast.Node +import prog8.ast.Program import prog8.ast.base.* import prog8.ast.expressions.* import prog8.ast.statements.* +import prog8.ast.toHex import prog8.codegen.cpu6502.assignment.* import prog8.compilerinterface.* import prog8.parser.SourceCode diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt index 59e526ba9..943b1e236 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt @@ -1,10 +1,12 @@ package prog8.codegen.cpu6502 -import prog8.ast.* +import prog8.ast.INameScope +import prog8.ast.Program import prog8.ast.antlr.escape import prog8.ast.base.* import prog8.ast.expressions.* import prog8.ast.statements.* +import prog8.ast.toHex import prog8.codegen.cpu6502.assignment.AsmAssignTarget import prog8.codegen.cpu6502.assignment.TargetStorageKind import prog8.compilerinterface.* diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/VariableAllocator.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/VariableAllocator.kt index 901db9d83..b5479e18a 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/VariableAllocator.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/VariableAllocator.kt @@ -2,7 +2,9 @@ package prog8.codegen.cpu6502 import com.github.michaelbull.result.fold import com.github.michaelbull.result.onSuccess -import prog8.ast.base.* +import prog8.ast.base.ArrayDatatypes +import prog8.ast.base.DataType +import prog8.ast.base.IntegerDatatypes import prog8.ast.expressions.StringLiteralValue import prog8.ast.statements.Subroutine import prog8.ast.statements.ZeropageWish @@ -41,8 +43,6 @@ internal class VariableAllocator(private val vars: IVariablesAndConsts, ).toList() val numberOfAllocatableVariables = allVariables.size - val totalAllocatedMemorySize = allVariables.sumOf { memsize(it) } - val varsRequiringZp = allVariables.filter { it.zp == ZeropageWish.REQUIRE_ZEROPAGE } val varsPreferringZp = allVariables.filter { it.zp == ZeropageWish.PREFER_ZEROPAGE } val varsDontCare = allVariables.filter { it.zp == ZeropageWish.DONTCARE } @@ -115,21 +115,11 @@ internal class VariableAllocator(private val vars: IVariablesAndConsts, } } - println(" number of allocated vars: $numberOfAllocatableVariables total size: $totalAllocatedMemorySize") + println(" number of allocated vars: $numberOfAllocatableVariables") println(" put into zeropage: $numVariablesAllocatedInZP, non-zp allocatable: ${numberOfNonIntegerVariables+numberOfExplicitNonZpVariables}") println(" zeropage free space: ${zeropage.free.size} bytes") } - private fun memsize(variable: IVariablesAndConsts.StaticVariable): Int { - return when(variable.type) { - in NumericDatatypes -> - options.compTarget.memorySize(variable.type) - in ArrayDatatypes -> variable.arraysize!! * options.compTarget.memorySize(ArrayToElementTypes.getValue(variable.type)) - DataType.STR -> (variable.initialValue as StringLiteralValue).value.length + 1 - else -> 0 - } - } - internal fun isZpVar(scopedName: List) = scopedName in zeropage.variables private fun numArrayElements(variable: IVariablesAndConsts.StaticVariable) = diff --git a/codeOptimizers/src/prog8/optimizer/Extensions.kt b/codeOptimizers/src/prog8/optimizer/Extensions.kt index 92453d4a2..9d5cc4aba 100644 --- a/codeOptimizers/src/prog8/optimizer/Extensions.kt +++ b/codeOptimizers/src/prog8/optimizer/Extensions.kt @@ -4,12 +4,7 @@ import prog8.ast.IBuiltinFunctions import prog8.ast.Program import prog8.ast.base.DataType import prog8.ast.base.FatalAstException -import prog8.ast.base.Position -import prog8.ast.base.VarDeclType import prog8.ast.expressions.InferredTypes -import prog8.ast.statements.VarDecl -import prog8.ast.statements.VarDeclOrigin -import prog8.ast.statements.ZeropageWish import prog8.compilerinterface.CompilationOptions import prog8.compilerinterface.ICompilationTarget import prog8.compilerinterface.IErrorReporter diff --git a/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt b/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt index 43e4f0959..bee701cda 100644 --- a/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt +++ b/compiler/src/prog8/compiler/astprocessing/BeforeAsmAstChanger.kt @@ -56,6 +56,7 @@ internal class BeforeAsmAstChanger(val program: Program, } // TODO get rid of the vardecl inside the ast - codegen should depend on the IVariableAllocation object + // but if we do this now, all variable name lookups break because these are still done on the Ast directly rather than on a separate symbol table // return listOf(IAstModification.Remove(decl, parent as IStatementContainer)) return noModifications } diff --git a/compilerAst/src/prog8/parser/SourceCode.kt b/compilerAst/src/prog8/parser/SourceCode.kt index 1d30b8fd2..735090060 100644 --- a/compilerAst/src/prog8/parser/SourceCode.kt +++ b/compilerAst/src/prog8/parser/SourceCode.kt @@ -4,9 +4,7 @@ import java.io.File import java.io.IOException import java.nio.file.Path import kotlin.io.path.Path -import kotlin.io.path.name import kotlin.io.path.readText -import kotlin.io.path.toPath /** * Encapsulates - and ties together - actual source code (=text) and its [origin].