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

Aliases should access subfields

This commit is contained in:
Karol Stasiak 2019-03-18 15:14:13 +01:00
parent 3a5cf16bba
commit b8547ed154
2 changed files with 31 additions and 0 deletions

View File

@ -1298,6 +1298,22 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
}
}
private def expandAliases(): Unit = {
val aliasesToAdd = mutable.ListBuffer[Alias]()
things.values.foreach{
case Alias(aliasName, target, deprecated) =>
val prefix = target + "."
things.foreach{
case (thingName, thing) =>
if (thingName.startsWith(prefix)) {
aliasesToAdd += Alias(aliasName + "." + thingName.stripPrefix(prefix), thingName, deprecated)
}
}
case _ => ()
}
aliasesToAdd.foreach(a => things += a.name -> a)
}
def collectDeclarations(program: Program, options: CompilationOptions): Unit = {
val b = get[VariableType]("byte")
val v = get[Type]("void")
@ -1320,6 +1336,7 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
case a: ArrayDeclarationStatement => registerArray(a, options)
case _ =>
}
expandAliases()
if (options.zpRegisterSize > 0 && !things.contains("__reg")) {
addThing(BasicPlainType("__reg$type", options.zpRegisterSize), None)
registerVariable(VariableDeclarationStatement(

View File

@ -173,6 +173,20 @@ class BasicSymonTest extends FunSuite with Matchers {
""".stripMargin){ m => () }
}
test("Deep alias test") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80)(
"""
| word output @$c000
| alias a = output
| void main () {
| a.hi = 2
| a.lo = $55
| }
""".stripMargin){ m =>
m.readWord(0xc000) should equal(0x255)
}
}
test("Preprocessor test") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp)(
"""