Commit 0ed97a36 authored by Sapphie's avatar Sapphie
Browse files

Fix Value Primitive translation

parent 8b95d0cd
......@@ -41,6 +41,20 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
C.LetF(cpsFuns, transform(body)(ctx))
}
def transformValPrim(p: L3ValuePrimitive, primArgs: Seq[S.Tree]) = {
val name = Symbol.fresh("p")
val body = ctx(C.AtomN(name))
// Slight misnomer
def transformArgs(args: Seq[S.Tree])(atoms: Seq[C.Atom]): C.Tree = args match {
case Nil =>
// Finished gathering atoms, now we can just place them into the primitive
C.LetP(name, p, atoms, body)
case x :: xs =>
// Transform the current argument and add it to the list
transform(x)(v => transformArgs(xs)(atoms :+ v))
}
transformArgs(primArgs)(Seq())
}
def transformTestPrim( p: L3TestPrimitive,
primArgs: Seq[S.Tree],
......@@ -97,7 +111,6 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
)
)
case e1 =>
val pArgs = S.Lit(BooleanLit(false))(cnd.pos)
val newCnd = S.Prim(L3.Eq, Seq(e1, pArgs))(cnd.pos)
......@@ -114,16 +127,7 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
)(tree.pos)
transform(newPrim)(ctx)
case p : L3ValuePrimitive =>
val name = Symbol.fresh("v")
val body = ctx(C.AtomN(name))
val start: C.Tree = C.LetP(name, p, Seq(), body)
args.foldLeft(start) {
case (C.LetP(_, _, s, _), e) =>
transform(e)(v => {
C.LetP(name, p, s :+ v, body)
})
case _ => throw new Exception("unreachable code")
}
transformValPrim(p, args)
}
case S.Halt(arg) => transform(arg)(a => C.Halt(a))
}
......
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