Commit afed2235 authored by Luca Bataillard's avatar Luca Bataillard
Browse files

alloc before init for all in LetF, all tests pass

parent 0ddd02df
......@@ -59,11 +59,11 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
(newFun, fv, f.name) +: transformFunAbs(fs)
}
def allocInitFun(funsAndVars: Seq[(L.Fun, Seq[Symbol], Symbol)], lastBody: L.Tree): L.Tree = {
def initFun(remVars: Seq[Symbol], counter: Int, blockAtom: L.Atom, rest: Seq[(L.Fun, Seq[Symbol], Symbol)]): L.Tree = remVars match {
case Nil => allocInitFun(rest, lastBody)
def initFuns(funsAndVars: Seq[(L.Fun, Seq[Symbol], Symbol)], lastBody: L.Tree): L.Tree = {
def initFunHelper(remVars: Seq[Symbol], counter: Int, blockAtom: L.Atom, rest: Seq[(L.Fun, Seq[Symbol], Symbol)]): L.Tree = remVars match {
case Nil => initFuns(rest, lastBody)
case v :: vs =>
val nextBody = initFun(vs, counter + 1, blockAtom, rest)
val nextBody = initFunHelper(vs, counter + 1, blockAtom, rest)
val args: Seq[L.Atom] = Seq(blockAtom, L.AtomL(counter), L.AtomN(v))
L.LetP(Symbol.fresh("blockset_unused"), CPS.BlockSet, args, nextBody)
}
......@@ -72,20 +72,26 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
case Nil => lastBody
case (workerFun, vars, originalFunName) :: rest =>
val blockAtom = L.AtomN(originalFunName)
val varInits = initFun(vars, 1, blockAtom, rest)
val varInits = initFunHelper(vars, 1, blockAtom, rest)
val t1 = Symbol.fresh("blockset_unused")
val blockSetArgs = Seq(blockAtom, L.AtomL(0), L.AtomN(workerFun.name))
val nextBody = L.LetP(t1, CPS.BlockSet, blockSetArgs, varInits)
L.LetP(originalFunName, CPS.BlockAlloc(202), Seq(L.AtomL(vars.length + 1)), nextBody)
/*val nextBody = */L.LetP(t1, CPS.BlockSet, blockSetArgs, varInits)
//L.LetP(originalFunName, CPS.BlockAlloc(202), Seq(L.AtomL(vars.length + 1)), nextBody)
}
}
def allocFuns(funsAndVars: Seq[(L.Fun, Seq[Symbol], Symbol)], closureInits: L.Tree): L.Tree =
funsAndVars.foldRight(closureInits) { case ((worker, vars, fName), prevBody) =>
L.LetP(fName, CPS.BlockAlloc(202), Seq(L.AtomL(vars.length + 1)), prevBody)
}
val funsAndVars = transformFunAbs(initialFuns)
val lastBody = apply(body)
val closureAllocInit = allocInitFun(funsAndVars, lastBody)
val closureInits = initFuns(funsAndVars, lastBody)
val closureAllocsInits = allocFuns(funsAndVars, closureInits)
val res = L.LetF(funsAndVars.unzip3._1, closureAllocInit)
val res = L.LetF(funsAndVars.unzip3._1, closureAllocsInits)
res
}
......
Supports Markdown
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