Commit 4cffab31 authored by Sapphie's avatar Sapphie
Browse files

Implement translation of primitives

parent e7b87da1
......@@ -43,6 +43,26 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
}
case S.Halt(arg) =>
transform(arg)(a => C.Halt(a))
case S.Prim(p, args) =>
p match {
case _ : L3TestPrimitive =>
val newPrim = S.If( tree,
S.Lit(BooleanLit(true))(tree.pos),
S.Lit(BooleanLit(false))(tree.pos)
)(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 _ => ???
}
}
}
}
......
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