mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
vm target 'zeropage' more robust
This commit is contained in:
parent
e67464325f
commit
8a4979f44c
@ -44,9 +44,24 @@ class VirtualMachineDefinition: IMachineDefinition {
|
||||
|
||||
override fun isIOAddress(address: UInt): Boolean = false
|
||||
|
||||
override fun initializeMemoryAreas(compilerOptions: CompilationOptions) {}
|
||||
override fun initializeMemoryAreas(compilerOptions: CompilationOptions) {
|
||||
zeropage = VirtualZeropage(compilerOptions)
|
||||
}
|
||||
}
|
||||
|
||||
interface IVirtualMachineRunner {
|
||||
fun runProgram(irSource: String)
|
||||
}
|
||||
|
||||
private class VirtualZeropage(options: CompilationOptions): Zeropage(options) {
|
||||
override val SCRATCH_B1: UInt
|
||||
get() = throw IllegalStateException("virtual shouldn't use this zeropage variable")
|
||||
override val SCRATCH_REG: UInt
|
||||
get() = throw IllegalStateException("virtual shouldn't use this zeropage variable")
|
||||
override val SCRATCH_W1: UInt
|
||||
get() = throw IllegalStateException("virtual shouldn't use this zeropage variable")
|
||||
override val SCRATCH_W2: UInt
|
||||
get() = throw IllegalStateException("virtual shouldn't use this zeropage variable")
|
||||
|
||||
override fun allocateCx16VirtualRegisters() { /* there is no actual zero page in this target to allocate thing in */ }
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ internal fun PtIdentifier.targetStatement(program: PtProgram): PtNode {
|
||||
}
|
||||
|
||||
internal fun PtProgram.lookup(name: String): PtNode {
|
||||
val remainder = name.split('.').toMutableList()
|
||||
val remainder = name.split('.').toMutableList() // TODO optimize split to not use memory allocations
|
||||
|
||||
fun recurse(node: PtNode): PtNode {
|
||||
when(node) {
|
||||
|
@ -55,7 +55,7 @@ internal class AsmAssignTarget(val kind: TargetStorageKind,
|
||||
when {
|
||||
identifier != null -> {
|
||||
val paramName = identifier!!.targetVarDecl(program)?.name
|
||||
val parameter = identifier!!.targetStatement(program)?.definingSub()?.parameters?.singleOrNull { it.name===paramName }
|
||||
val parameter = identifier!!.targetStatement(program).definingSub()?.parameters?.singleOrNull { it.name===paramName }
|
||||
println("assign to ${identifier!!.name} param=$parameter") // TODO WEG
|
||||
if (parameter!=null) {
|
||||
val sub = parameter.definingAsmSub()
|
||||
@ -131,12 +131,12 @@ internal class AsmAssignSource(val kind: SourceStorageKind,
|
||||
return AsmAssignSource(SourceStorageKind.LITERALNUMBER, program, asmgen, cv.type, number = cv)
|
||||
|
||||
return when(value) {
|
||||
is PtNumber -> throw AssemblyError("should have been constant value")
|
||||
// checked above: is PtNumber -> throw AssemblyError("should have been constant value")
|
||||
is PtString -> throw AssemblyError("string literal value should not occur anymore for asm generation")
|
||||
is PtArray -> throw AssemblyError("array literal value should not occur anymore for asm generation")
|
||||
is PtIdentifier -> {
|
||||
val paramName = value.targetVarDecl(program)?.name
|
||||
val parameter = value.targetStatement(program)?.definingSub()?.parameters?.singleOrNull { it.name===paramName }
|
||||
val parameter = value.targetStatement(program).definingSub()?.parameters?.singleOrNull { it.name===paramName }
|
||||
println("assign to ${value.name} param=$parameter") // TODO WEG
|
||||
if(parameter?.definingAsmSub() != null)
|
||||
throw AssemblyError("can't assign from a asmsub register parameter $value ${value.position}")
|
||||
|
@ -10,6 +10,7 @@ import prog8.code.core.ArrayDatatypes
|
||||
import prog8.code.core.CompilationOptions
|
||||
import prog8.code.core.DataType
|
||||
import prog8.code.core.Position
|
||||
import prog8.code.target.VMTarget
|
||||
import java.util.*
|
||||
|
||||
internal class SymbolTableMaker(private val program: Program, private val options: CompilationOptions): IAstVisitor {
|
||||
@ -29,13 +30,15 @@ internal class SymbolTableMaker(private val program: Program, private val option
|
||||
}
|
||||
require(scopestack.isEmpty())
|
||||
|
||||
// add the hardcoded temporary zeropage variables
|
||||
st.add(StMemVar("P8ZP_SCRATCH_B1", DataType.UBYTE, options.compTarget.machine.zeropage.SCRATCH_B1, null, Position.DUMMY))
|
||||
st.add(StMemVar("P8ZP_SCRATCH_REG", DataType.UBYTE, options.compTarget.machine.zeropage.SCRATCH_REG, null, Position.DUMMY))
|
||||
st.add(StMemVar("P8ZP_SCRATCH_W1", DataType.UWORD, options.compTarget.machine.zeropage.SCRATCH_W1, null, Position.DUMMY))
|
||||
st.add(StMemVar("P8ZP_SCRATCH_W2", DataType.UWORD, options.compTarget.machine.zeropage.SCRATCH_W2, null, Position.DUMMY))
|
||||
st.add(StMemVar("P8ESTACK_LO", DataType.UBYTE, options.compTarget.machine.ESTACK_LO, null, Position.DUMMY))
|
||||
st.add(StMemVar("P8ESTACK_HI", DataType.UBYTE, options.compTarget.machine.ESTACK_HI, null, Position.DUMMY))
|
||||
if(options.compTarget.name!=VMTarget.NAME) {
|
||||
// add the hardcoded temporary zeropage variables for targets that use them
|
||||
st.add(StMemVar("P8ZP_SCRATCH_B1", DataType.UBYTE, options.compTarget.machine.zeropage.SCRATCH_B1, null, Position.DUMMY))
|
||||
st.add(StMemVar("P8ZP_SCRATCH_REG", DataType.UBYTE, options.compTarget.machine.zeropage.SCRATCH_REG, null, Position.DUMMY))
|
||||
st.add(StMemVar("P8ZP_SCRATCH_W1", DataType.UWORD, options.compTarget.machine.zeropage.SCRATCH_W1, null, Position.DUMMY))
|
||||
st.add(StMemVar("P8ZP_SCRATCH_W2", DataType.UWORD, options.compTarget.machine.zeropage.SCRATCH_W2, null, Position.DUMMY))
|
||||
st.add(StMemVar("P8ESTACK_LO", DataType.UBYTE, options.compTarget.machine.ESTACK_LO, null, Position.DUMMY))
|
||||
st.add(StMemVar("P8ESTACK_HI", DataType.UBYTE, options.compTarget.machine.ESTACK_HI, null, Position.DUMMY))
|
||||
}
|
||||
|
||||
return st
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user