Skip to content
Snippets Groups Projects
Commit 3c096064 authored by Sapphie's avatar Sapphie
Browse files

Implement LetF shrinking and start AppF shrinking

parent f868bab7
No related merge requests found
......@@ -55,7 +55,32 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
private def shrink(tree: Tree): Tree =
shrink(tree, State(census(tree)))
private def shrink(tree: Tree, s: State): Tree = ???
private def shrink(tree: Tree, s: State): Tree = tree match {
case LetF(funs, body) =>
val undeadFuns = funs.filter(fun => !s.dead(fun.name))
val undeadShrunkFuns = undeadFuns.map { fun =>
Fun(fun.name, fun.retC, fun.args, shrink(fun.body, s))}
val (funsAppliedOnce, restFuns) = undeadShrunkFuns
.partition(fun => s.appliedOnce(fun.name))
val newState = s.withFuns(undeadShrunkFuns)
val newBody = shrink(body, newState)
if (restFuns.isEmpty) {
newBody
} else {
LetF(restFuns, newBody)
}
case AppF(fun, retC, args) =>
fun match {
case AtomN(n) if s.fEnv.contains(n) && s.appliedOnce(n) =>
// Inline
val fun = s.fEnv.get(n)
???
case _ => tree
}
}
// (Non-shrinking) inlining
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment