1
0
mirror of https://github.com/KarolS/millfork.git synced 2025-01-01 06:29:53 +00:00

Various fixes related to the -> operator

This commit is contained in:
Karol Stasiak 2019-06-23 19:44:53 +02:00
parent 088b28989f
commit 63c43c414a
3 changed files with 26 additions and 0 deletions

View File

@ -156,6 +156,9 @@ abstract class AbstractStatementPreprocessor(ctx: CompilationContext, statements
case ExpressionStatement(expr) =>
cv = search(expr, cv)
ExpressionStatement(optimizeExpr(expr, cv)).pos(pos) -> cv
case ReturnStatement(Some(expr)) =>
cv = search(expr, cv)
ReturnStatement(Some(optimizeExpr(expr, cv))).pos(pos) -> cv
case IfStatement(cond, th, el) =>
cv = search(cond, cv)
val c = optimizeExpr(cond, cv)

View File

@ -64,6 +64,7 @@ object UnusedGlobalVariables extends NodeOptimization {
case FunctionCallExpression(name, xs) => name :: getAllReadVariables(xs)
case IndexedExpression(arr, index) => arr :: getAllReadVariables(List(index))
case SeparateBytesExpression(h, l) => getAllReadVariables(List(h, l))
case IndirectFieldExpression(root, firstIndices, fields) => getAllReadVariables(List(root) ++ firstIndices ++ fields.flatMap(_._2))
case _ => Nil
}

View File

@ -209,4 +209,26 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
}
}
test("Pointers and arrays") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80)(
"""
| struct P {
| word i
| byte c
| byte d
| }
|
| array a [sizeof(P)*8]
|
| noinline byte f(byte i) {
| return pointer.P(a.addr + sizeof(P)*i)->c
| }
|
| void main() {
| f(6)
| }
""".stripMargin) { m =>
}
}
}