1
0
mirror of https://github.com/KarolS/millfork.git synced 2025-02-08 00:30:38 +00:00

Fix variable coercing

This commit is contained in:
Karol Stasiak 2019-07-09 22:39:20 +02:00
parent 62f79388bd
commit 7766ba932b

View File

@ -235,26 +235,8 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
def coerceLocalVariableIntoGlobalVariable(localVarToRelativize: String, concreteGlobalTarget: String): Unit = { def coerceLocalVariableIntoGlobalVariable(localVarToRelativize: String, concreteGlobalTarget: String): Unit = {
log.trace(s"Coercing $localVarToRelativize to $concreteGlobalTarget") log.trace(s"Coercing $localVarToRelativize to $concreteGlobalTarget")
def removeVariableImpl2(e: Environment, str: String): Unit = { def removeVariableImpl2(e: Environment, str: String): Unit = {
e.things -= str e.removeVariable(str)
e.things -= str + ".addr" e.removeVariable(str.stripPrefix(prefix))
e.things -= str + ".addr.lo"
e.things -= str + ".addr.hi"
e.things -= str + ".pointer"
e.things -= str + ".pointer.lo"
e.things -= str + ".pointer.hi"
e.things -= str + ".rawaddr"
e.things -= str + ".rawaddr.lo"
e.things -= str + ".rawaddr.hi"
e.things -= str.stripPrefix(prefix)
e.things -= str.stripPrefix(prefix) + ".addr"
e.things -= str.stripPrefix(prefix) + ".addr.lo"
e.things -= str.stripPrefix(prefix) + ".addr.hi"
e.things -= str.stripPrefix(prefix) + ".pointer"
e.things -= str.stripPrefix(prefix) + ".pointer.lo"
e.things -= str.stripPrefix(prefix) + ".pointer.hi"
e.things -= str.stripPrefix(prefix) + ".rawaddr"
e.things -= str.stripPrefix(prefix) + ".rawaddr.lo"
e.things -= str.stripPrefix(prefix) + ".rawaddr.hi"
e.parent.foreach(x => removeVariableImpl2(x,str)) e.parent.foreach(x => removeVariableImpl2(x,str))
} }
removeVariableImpl2(this, prefix + localVarToRelativize) removeVariableImpl2(this, prefix + localVarToRelativize)
@ -280,36 +262,22 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
} }
private def removeVariableImpl(str: String): Unit = { private def removeVariableImpl(str: String): Unit = {
removedThings += str def extractThingName(fullName: String): String = {
removedThings += str + ".addr" var result = fullName.takeWhile(_ != '.')
removedThings += str + ".addr.lo" if (result.length == fullName.length) return result
removedThings += str + ".addr.hi" val suffix = fullName.drop(result.length)
removedThings += str + ".pointer" if (suffix == ".return" || suffix.startsWith(".return.")) {
removedThings += str + ".pointer.lo" result += ".return"
removedThings += str + ".pointer.hi" }
removedThings += str + ".rawaddr" result
removedThings += str + ".rawaddr.lo" }
removedThings += str + ".rawaddr.hi"
things -= str val toRemove = things.keys.filter { n =>
things -= str + ".addr" val baseName = extractThingName(n)
things -= str + ".addr.lo" baseName == str || baseName == str.stripPrefix(prefix)
things -= str + ".addr.hi" }.toSet
things -= str + ".pointer" removedThings ++= toRemove.map(_.stripPrefix(prefix))
things -= str + ".pointer.lo" things --= toRemove
things -= str + ".pointer.hi"
things -= str + ".rawaddr"
things -= str + ".rawaddr.lo"
things -= str + ".rawaddr.hi"
things -= str.stripPrefix(prefix)
things -= str.stripPrefix(prefix) + ".addr"
things -= str.stripPrefix(prefix) + ".addr.lo"
things -= str.stripPrefix(prefix) + ".addr.hi"
things -= str.stripPrefix(prefix) + ".pointer"
things -= str.stripPrefix(prefix) + ".pointer.lo"
things -= str.stripPrefix(prefix) + ".pointer.hi"
things -= str.stripPrefix(prefix) + ".rawaddr"
things -= str.stripPrefix(prefix) + ".rawaddr.lo"
things -= str.stripPrefix(prefix) + ".rawaddr.hi"
parent.foreach(_ removeVariableImpl str) parent.foreach(_ removeVariableImpl str)
} }