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:
parent
a69937d8dd
commit
2a21dd8e2e
15
src/main/scala/millfork/env/Environment.scala
vendored
15
src/main/scala/millfork/env/Environment.scala
vendored
@ -787,6 +787,21 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
|
|||||||
}
|
}
|
||||||
}.map(_.quickSimplify)
|
}.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]) = {
|
private def constantOperation(op: MathOperator.Value, params: List[Expression]) = {
|
||||||
params.map(eval).reduceLeft[Option[Constant]] { (oc, om) =>
|
params.map(eval).reduceLeft[Option[Constant]] { (oc, om) =>
|
||||||
for {
|
for {
|
||||||
|
@ -51,6 +51,8 @@ class ConsoleLogger extends Logger {
|
|||||||
|
|
||||||
override def traceEnabled: Boolean = verbosity >= 2
|
override def traceEnabled: Boolean = verbosity >= 2
|
||||||
|
|
||||||
|
override def debugEnabled: Boolean = verbosity >= 1
|
||||||
|
|
||||||
override def trace(msg: String, position: Option[Position] = None): Unit = {
|
override def trace(msg: String, position: Option[Position] = None): Unit = {
|
||||||
if (verbosity < 2) return
|
if (verbosity < 2) return
|
||||||
println("TRACE: " + f(position) + msg)
|
println("TRACE: " + f(position) + msg)
|
||||||
|
@ -17,6 +17,8 @@ class ErrorsOnlyLogger(inner: Logger) extends Logger {
|
|||||||
|
|
||||||
override def traceEnabled: Boolean = false
|
override def traceEnabled: Boolean = false
|
||||||
|
|
||||||
|
override def debugEnabled: Boolean = false
|
||||||
|
|
||||||
override def warn(msg: String, position: Option[Position]): Unit = ()
|
override def warn(msg: String, position: Option[Position]): Unit = ()
|
||||||
|
|
||||||
override def error(msg: String, position: Option[Position]): Unit = inner.error(msg, position)
|
override def error(msg: String, position: Option[Position]): Unit = inner.error(msg, position)
|
||||||
|
@ -18,6 +18,8 @@ trait Logger {
|
|||||||
|
|
||||||
def traceEnabled: Boolean
|
def traceEnabled: Boolean
|
||||||
|
|
||||||
|
def debugEnabled: Boolean
|
||||||
|
|
||||||
def warn(msg: String, position: Option[Position] = None): Unit
|
def warn(msg: String, position: Option[Position] = None): Unit
|
||||||
|
|
||||||
def error(msg: String, position: Option[Position] = None): Unit
|
def error(msg: String, position: Option[Position] = None): Unit
|
||||||
|
@ -18,6 +18,8 @@ class NullLogger extends Logger {
|
|||||||
|
|
||||||
override def traceEnabled: Boolean = false
|
override def traceEnabled: Boolean = false
|
||||||
|
|
||||||
|
override def debugEnabled: Boolean = false
|
||||||
|
|
||||||
override def warn(msg: String, position: Option[Position]): Unit = ()
|
override def warn(msg: String, position: Option[Position]): Unit = ()
|
||||||
|
|
||||||
override def error(msg: String, position: Option[Position]): Unit = ()
|
override def error(msg: String, position: Option[Position]): Unit = ()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user