1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-07-18 02:28:57 +00:00

Fixed object allocation fixes, assembly output improvements

This commit is contained in:
Karol Stasiak 2018-03-09 16:31:49 +01:00
parent 2b182ee2c7
commit a414feedec
3 changed files with 26 additions and 4 deletions

View File

@ -68,6 +68,18 @@ class Environment(val parent: Option[Environment], val prefix: String) {
case _ => Nil
}.toList
def getAllFixedAddressObjects: List[(Int, Int)] = {
things.values.flatMap {
case RelativeArray(_, NumericConstant(addr, _), size) =>
List(addr.toInt -> size)
case RelativeVariable(_, NumericConstant(addr, _), typ, _) =>
List(addr.toInt -> typ.size)
case f: NormalFunction =>
f.environment.getAllFixedAddressObjects
case _ => Nil
}.toList
}
def allocateVariables(nf: Option[NormalFunction], mem: MemoryBank, callGraph: CallGraph, allocator: VariableAllocator, options: CompilationOptions, onEachVariable: (String, Int) => Unit): Unit = {
val b = get[Type]("byte")
val p = get[Type]("pointer")

View File

@ -31,6 +31,7 @@ object ErrorReporting {
flushOutput()
}
@inline
private def flushOutput(): Unit = {
System.out.flush()
System.err.flush()
@ -55,6 +56,7 @@ object ErrorReporting {
hasErrors = true
println("FATAL: " + f(position) + msg)
flushOutput()
System.exit(1)
throw new RuntimeException(msg)
}

View File

@ -89,8 +89,7 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
}
} catch {
case e: StackOverflowError =>
e.printStackTrace()
ErrorReporting.fatal("Stack overflow")
ErrorReporting.fatal("Stack overflow " + c)
}
case HalfWordConstant(cc, true) => deepConstResolve(cc).>>>(8).&(0xff)
case HalfWordConstant(cc, false) => deepConstResolve(cc).&(0xff)
@ -212,13 +211,15 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
assembly.append(name)
for (item <- items) {
writeByte(0, index, item)
assembly.append(" !byte " + item)
bank0.occupied(index) = true
bank0.initialized(index) = true
bank0.writeable(index) = true
bank0.readable(index) = true
index += 1
}
items.grouped(16).foreach {group =>
assembly.append(" !byte " + group.mkString(", "))
}
initializedVariablesSize += items.length
case InitializedArray(name, Some(_), items) => ???
case f: NormalFunction if f.address.isDefined =>
@ -268,9 +269,11 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
assembly.append(name)
for (item <- items) {
writeByte(0, index, item)
assembly.append(" !byte " + item)
index += 1
}
items.grouped(16).foreach {group =>
assembly.append(" !byte " + group.mkString(", "))
}
initializedVariablesSize += items.length
justAfterCode = index
case m@InitializedMemoryVariable(name, None, typ, value) =>
@ -289,6 +292,11 @@ class Assembler(private val program: Program, private val rootEnv: Environment)
justAfterCode = index
case _ =>
}
env.getAllFixedAddressObjects.foreach {
case (addr, size) =>
println(addr)
for(i <- 0 until size) bank0.occupied(addr + i) = true
}
val variableAllocator = platform.variableAllocator
variableAllocator.notifyAboutEndOfCode(justAfterCode)
env.allocateVariables(None, bank0, callGraph, variableAllocator, options, labelMap.put)