mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-11 12:29:46 +00:00
Fix const functions of the form if c {return x} return y
This commit is contained in:
parent
475496c137
commit
e3d5ce4e81
@ -80,6 +80,10 @@ Examples:
|
||||
|
||||
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 `noinline` keyword will never be inlined
|
||||
|
@ -18,6 +18,10 @@ object ConstPureFunctions {
|
||||
private def checkConstPure(env: Environment, s: List[Statement], params: Set[String]): Unit = {
|
||||
s match {
|
||||
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)) =>
|
||||
checkConstPure(env, c, 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)
|
||||
}
|
||||
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 =>
|
||||
env.log.error("Returning without value not allowed in const-pure functions",
|
||||
bad.position.orElse(xs.headOption.flatMap(_.position)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user