1
0
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:
Karol Stasiak 2020-03-25 23:51:04 +01:00
parent 475496c137
commit e3d5ce4e81
2 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -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)))