Commit 5b783c84 authored by Luca Bataillard's avatar Luca Bataillard
Browse files

resolve merge conflict and combine both solutions

parents 82cd4b8c 4cffab31
......@@ -28,43 +28,61 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
transform(fun)(fId => transformArgs(args)(fId, Seq()))
}
tree match {
case S.Lit(v) => ctx(C.AtomL(v))
case S.If(cnd, thn, els) =>
cnd match {
case S.Prim(p: L3TestPrimitive, primArgs) =>
// Context continuation name
val ctxCNme = Symbol.fresh("c")
val ctxCId = C.AtomN(ctxCNme)
// Context continuation arg
val ctxCArg = Symbol.fresh("a")
// Context continuation body
// This is simply what we already had
val ctxCBody = ctx(C.AtomN(ctxCArg))
case S.If(cnd, thn, els) => cnd match {
case S.Prim(p: L3TestPrimitive, primArgs) =>
// Context continuation name
val ctxCNme = Symbol.fresh("c")
val ctxCId = C.AtomN(ctxCNme)
// Context continuation arg
val ctxCArg = Symbol.fresh("a")
// Context continuation body
// This is simply what we already had
val ctxCBody = ctx(C.AtomN(ctxCArg))
// Context continuation
val ctxC = C.Cnt(ctxCNme, Seq(ctxCArg), ctxCBody)
// Context continuation
val ctxC = C.Cnt(ctxCNme, Seq(ctxCArg), ctxCBody)
// 'Then' continuation name and body
val thenCNme = Symbol.fresh("ct")
val thenCBody = transform(thn)(v2 => C.AppC(ctxCNme, Seq(v2)))
// 'Then' continuation name and body
val thenCNme = Symbol.fresh("ct")
val thenCBody = transform(thn)(v2 => C.AppC(ctxCNme, Seq(v2)))
// 'Else' continuation name and body
val elseCNme = Symbol.fresh("ce")
val elseCBody = transform(thn)(v3 => C.AppC(ctxCNme, Seq(v3)))
???
case e1 =>
val pArgs = S.Lit(BooleanLit(false))(cnd.pos)
val newCnd = S.Prim(L3.Eq, Seq(e1, pArgs))(cnd.pos)
val newIf = S.If(newCnd, els, thn)(cnd.pos)
transform(newIf)(ctx)
}
// 'Else' continuation name and body
val elseCNme = Symbol.fresh("ce")
val elseCBody = transform(thn)(v3 => C.AppC(ctxCNme, Seq(v3)))
???
case e1 =>
val pArgs = S.Lit(BooleanLit(false))(cnd.pos)
val newCnd = S.Prim(L3.Eq, Seq(e1, pArgs))(cnd.pos)
val newIf = S.If(newCnd, els, thn)(cnd.pos)
transform(newIf)(ctx)
}
case S.App(fun, args) => transformApp(fun, args)
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 _ => ???
}
}
case _ => ???
}
}
}
......@@ -75,11 +93,13 @@ object CL3ToCPSTranslator extends (S.Tree => C.Tree) {
elseC: C.Name): C.Tree = {
val start: C.Tree = C.If(p, Seq(), thenC, elseC)
primArgs.foldLeft(start){
primArgs.foldLeft(start) {
case (C.If(_, s, _, _), e) =>
transform(e)(v => {
C.If(p, s :+ v, thenC, elseC)
})
case _ => ??? // put some exception here idk
// (this is just to shut the compiler up)
}
}
}
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