Commit 5e1720d2 authored by Luca Bataillard's avatar Luca Bataillard
Browse files

fix improved CC translation

parent 5b6c4476
......@@ -59,12 +59,12 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
val cntsFVs = cnts.flatMap(c => fv(c.body, fvMap) -- c.args)
fv(body, fvMap) ++ cntsFVs
case H.LetF(funs, body) =>
val (newFvMap, funFVs) = fvFunSeq(funs, fvMap)
(fv(body, newFvMap) ++ funFVs) -- funs.map(_.name)
val funsFVs = funs.flatMap(f => (fv(f.body, fvMap) -- f.args))
(fv(body, fvMap) ++ funsFVs) -- funs.map(_.name)
case H.AppC(cnt, args) =>
fvAtomSeq(args, fvMap)
case H.AppF(fun, retC, args) =>
fun.asName.toSet ++ fvAtomSeq(args, fvMap)
fvAtomSeq(args, fvMap) ++ fvMap.getOrElse(fun.asName.get, Set(fun.asName.get))
case H.If(_, args, _, _) =>
fvAtomSeq(args, fvMap)
case H.Halt(arg) =>
......@@ -73,26 +73,14 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
def fvAtomSeq(as: Seq[H.Atom], fvMap: FVMap): Set[Symbol] =
as.map(_.asName).filter(_.isDefined).toSet
.flatMap((n: Option[Symbol]) => fvMap.getOrElse(n.get, Set()) + n.get)
def fvFunSeq(funs: Seq[H.Fun], fvMap: FVMap): (FVMap, Set[Symbol]) = {
val fNames = funs map (_.name)
val defFvMap = fNames.map((_, Set[Symbol]())).toMap
val funFVs = funs map {f => {
val fNewFvMap = fvMap ++ (defFvMap - f.name)
fv(f.body, fNewFvMap) -- f.args
}}
(fvMap ++ (fNames zip funFVs), funFVs reduce (_ ++ _))
}
.map((n: Option[Symbol]) => n.get)
def iterate(fvMap: FVMap): FVMap =
definedFuns.map {
case H.Fun(fName, _, fArgs, fBody) =>
val newFv = (fv(fBody, fvMap - fName)) -- fArgs
(fName, newFv)
}.toMap
definedFuns.foldLeft (fvMap) { case (acc, H.Fun(fName, _, fArgs, fBody)) =>
val newFv = (fv(fBody, acc)) -- fArgs
val newBinding = (fName, newFv)
acc + newBinding
}
val definedFvMap = definedFuns.map(f => (f.name, Set[Symbol]())).toMap
val initialFvMap: FVMap = definedFvMap ++ prevKnownFuns.map{ case (fName, (_, _, fvs)) => (fName, fvs.toSet)}
......@@ -154,7 +142,7 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
val blockAtom = L.AtomN(fName)
val varInits = initFunHelper(fvs, 1, blockAtom, rest)
val t1 = Symbol.fresh("blockset_unused")
val blockSetArgs = Seq(blockAtom, L.AtomL(0), L.AtomN(worker))
val blockSetArgs = Seq(blockAtom, L.AtomL(0), L.AtomN(wrapper))
L.LetP(t1, CPS.BlockSet, blockSetArgs, varInits)
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment