Commit 1c744f7e authored by Sapphie's avatar Sapphie
Browse files

Reorganise functions

parent 940968e7
......@@ -42,6 +42,21 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
}
def transformTestPrim( p: L3TestPrimitive,
primArgs: Seq[S.Tree],
thenC: C.Name,
elseC: C.Name): C.Tree = {
val start: C.Tree = C.If(p, Seq(), thenC, elseC)
primArgs.foldLeft(start) {
case (C.If(_, s, _, _), e) =>
transform(e)(v => {
C.If(p, s :+ v, thenC, elseC)
})
case _ => throw new Exception("unreachable code")
}
}
tree match {
case S.Lit(v) => ctx(C.AtomL(v))
case S.Ident(id) => ctx(C.AtomN(id))
......@@ -74,7 +89,7 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
val elseCBody = transform(thn)(v3 => C.AppC(ctxCNme, Seq(v3)))
val elseC = C.Cnt(elseCNme, Seq(), elseCBody)
val letBody = transformTestPrimitive(p, primArgs, thenCNme, elseCNme)
val letBody = transformTestPrim(p, primArgs, thenCNme, elseCNme)
C.LetC(Seq(ctxC),
C.LetC(Seq(thenC),
......@@ -115,21 +130,4 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
}
def transformTestPrimitive( p: L3TestPrimitive,
primArgs: Seq[S.Tree],
thenC: C.Name,
elseC: C.Name): C.Tree = {
val start: C.Tree = C.If(p, Seq(), thenC, elseC)
primArgs.foldLeft(start) {
case (C.If(_, s, _, _), e) =>
transform(e)(v => {
C.If(p, s :+ v, thenC, elseC)
})
case _ => throw new Exception("unreachable code")
}
}
}
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