mirror of
https://github.com/KarolS/millfork.git
synced 2025-08-13 06:25:13 +00:00
Fix const functions of the form if c {return x} return y
This commit is contained in:
@@ -80,6 +80,10 @@ Examples:
|
|||||||
|
|
||||||
You can control inlining behavior in several ways:
|
You can control inlining behavior in several ways:
|
||||||
|
|
||||||
|
* functions declared with the `const` keyword called with constant arguments will always be inlined,
|
||||||
|
with the whole invocation being converted into a single constant, regardless of `inline` and `noinline` keywords;
|
||||||
|
calls with non-constant arguments are subject to the regular rules.
|
||||||
|
|
||||||
* functions declared with the `inline` keyword will be inlined if possible
|
* functions declared with the `inline` keyword will be inlined if possible
|
||||||
|
|
||||||
* functions declared with the `noinline` keyword will never be inlined
|
* functions declared with the `noinline` keyword will never be inlined
|
||||||
|
@@ -18,6 +18,10 @@ object ConstPureFunctions {
|
|||||||
private def checkConstPure(env: Environment, s: List[Statement], params: Set[String]): Unit = {
|
private def checkConstPure(env: Environment, s: List[Statement], params: Set[String]): Unit = {
|
||||||
s match {
|
s match {
|
||||||
case List(ReturnStatement(Some(expr))) => checkConstPure(env, expr, params)
|
case List(ReturnStatement(Some(expr))) => checkConstPure(env, expr, params)
|
||||||
|
case IfStatement(c, t, Nil) :: e =>
|
||||||
|
checkConstPure(env, c, params)
|
||||||
|
checkConstPure(env, t, params)
|
||||||
|
checkConstPure(env, e, params)
|
||||||
case List(IfStatement(c, t, e)) =>
|
case List(IfStatement(c, t, e)) =>
|
||||||
checkConstPure(env, c, params)
|
checkConstPure(env, c, params)
|
||||||
checkConstPure(env, t, params)
|
checkConstPure(env, t, params)
|
||||||
@@ -38,10 +42,6 @@ object ConstPureFunctions {
|
|||||||
env.log.error(s"Statement ${bad} not allowed in const-pure functions", bad.position)
|
env.log.error(s"Statement ${bad} not allowed in const-pure functions", bad.position)
|
||||||
}
|
}
|
||||||
checkConstPure(env, xs, params)
|
checkConstPure(env, xs, params)
|
||||||
case IfStatement(c, t, Nil) :: e =>
|
|
||||||
checkConstPure(env, c, params)
|
|
||||||
checkConstPure(env, t, params)
|
|
||||||
checkConstPure(env, e, params)
|
|
||||||
case (bad@ReturnStatement(None)) :: xs =>
|
case (bad@ReturnStatement(None)) :: xs =>
|
||||||
env.log.error("Returning without value not allowed in const-pure functions",
|
env.log.error("Returning without value not allowed in const-pure functions",
|
||||||
bad.position.orElse(xs.headOption.flatMap(_.position)))
|
bad.position.orElse(xs.headOption.flatMap(_.position)))
|
||||||
|
Reference in New Issue
Block a user