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

Add debugging of constness

This commit is contained in:
Karol Stasiak 2019-09-25 01:17:23 +02:00
parent a69937d8dd
commit 2a21dd8e2e
5 changed files with 23 additions and 0 deletions

View File

@ -787,6 +787,21 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
}
}.map(_.quickSimplify)
def debugConstness(item: Expression): Unit = {
if (!log.debugEnabled) return
if (eval(item).isEmpty) {
log.debug(s"$item is not const!")
item match {
case FunctionCallExpression(_, expressions) => expressions.foreach(debugConstness)
case SumExpression(expressions, _) => expressions.map(_._2).foreach(debugConstness)
case SeparateBytesExpression(b1, b2) =>
debugConstness(b1)
debugConstness(b2)
case _ =>
}
}
}
private def constantOperation(op: MathOperator.Value, params: List[Expression]) = {
params.map(eval).reduceLeft[Option[Constant]] { (oc, om) =>
for {

View File

@ -51,6 +51,8 @@ class ConsoleLogger extends Logger {
override def traceEnabled: Boolean = verbosity >= 2
override def debugEnabled: Boolean = verbosity >= 1
override def trace(msg: String, position: Option[Position] = None): Unit = {
if (verbosity < 2) return
println("TRACE: " + f(position) + msg)

View File

@ -17,6 +17,8 @@ class ErrorsOnlyLogger(inner: Logger) extends Logger {
override def traceEnabled: Boolean = false
override def debugEnabled: Boolean = false
override def warn(msg: String, position: Option[Position]): Unit = ()
override def error(msg: String, position: Option[Position]): Unit = inner.error(msg, position)

View File

@ -18,6 +18,8 @@ trait Logger {
def traceEnabled: Boolean
def debugEnabled: Boolean
def warn(msg: String, position: Option[Position] = None): Unit
def error(msg: String, position: Option[Position] = None): Unit

View File

@ -18,6 +18,8 @@ class NullLogger extends Logger {
override def traceEnabled: Boolean = false
override def debugEnabled: Boolean = false
override def warn(msg: String, position: Option[Position]): Unit = ()
override def error(msg: String, position: Option[Position]): Unit = ()