Skip to content
Snippets Groups Projects
Commit 212fc8c1 authored by Sapphie's avatar Sapphie
Browse files

Fix Logical Primitive translation

parent 0ed97a36
No related branches found
No related tags found
No related merge requests found
......@@ -56,19 +56,17 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
transformArgs(primArgs)(Seq())
}
// Builds a CPS If out of its arguments
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")
def transformArgs(args: Seq[S.Tree])(atoms: Seq[C.Atom]): C.Tree = args match {
case Nil => C.If(p, atoms, thenC, elseC)
case x::xs =>
transform(x)(v => transformArgs(xs)(atoms :+ v))
}
transformArgs(primArgs)(Seq())
}
tree match {
......@@ -126,8 +124,7 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
S.Lit(BooleanLit(false))(tree.pos)
)(tree.pos)
transform(newPrim)(ctx)
case p : L3ValuePrimitive =>
transformValPrim(p, args)
case p : L3ValuePrimitive => transformValPrim(p, args)
}
case S.Halt(arg) => transform(arg)(a => C.Halt(a))
}
......
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