mirror of
https://github.com/irmen/prog8.git
synced 2025-02-04 02:30:19 +00:00
cleanup
This commit is contained in:
parent
c13b7fd883
commit
bd0dee5db5
@ -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
|
||||
|
@ -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.*
|
||||
|
@ -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<String>) = scopedName in zeropage.variables
|
||||
|
||||
private fun numArrayElements(variable: IVariablesAndConsts.StaticVariable) =
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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].
|
||||
|
Loading…
x
Reference in New Issue
Block a user