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

Fix badly handled stack overflow

This commit is contained in:
Karol Stasiak 2018-10-12 00:00:41 +02:00
parent df71435c78
commit 30c979cc39
2 changed files with 8 additions and 0 deletions

View File

@ -33,6 +33,7 @@ class ConsoleLogger extends Logger {
}
}
@inline
def f(position: Option[Position]): String = position.fold("")(p => s"(${p.moduleName}:${p.line}:${p.column}) ")
override def info(msg: String, position: Option[Position] = None): Unit = {

View File

@ -79,7 +79,13 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program
}
}
var stackProbeCount = 0
def deepConstResolve(c: Constant): Long = {
def stackProbe(n: Int): Int = {
stackProbeCount += 1
if (n == 0) 0 else stackProbe(n - 1) + 1
}
c match {
case NumericConstant(v, _) => v
case AssertByte(inner) =>
@ -100,6 +106,7 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program
val x5 = env.maybeGet[RelativeVariable](th.name).map(_.address)
val x6 = env.maybeGet[ConstantThing](th.name.stripSuffix(".array") + ".addr").map(_.value)
val x = x1.orElse(x2).orElse(x3).orElse(x4).orElse(x5).orElse(x6)
stackProbe(700)
x match {
case Some(cc) =>
deepConstResolve(cc)