Commit e6899d1b authored by Sapphie's avatar Sapphie
Browse files

Try to fix improvedCC

parent 5b6c4476
...@@ -62,6 +62,11 @@ sealed abstract class CPSInterpreter[M <: CPSTreeModule]( ...@@ -62,6 +62,11 @@ sealed abstract class CPSInterpreter[M <: CPSTreeModule](
case AppF(fun, retC, args) => case AppF(fun, retC, args) =>
val FunV(fRetC, fArgs, fBody, fEnv) = unwrapFunV(resolve(fun)) val FunV(fRetC, fArgs, fBody, fEnv) = unwrapFunV(resolve(fun))
if (fArgs.length != args.length) {
println(fun)
println(fArgs.length)
println(args.length)
}
assume(fArgs.length == args.length) assume(fArgs.length == args.length)
val rArgs = args map resolve val rArgs = args map resolve
val env1 = ((fRetC +: fArgs) zip (env(retC) +: rArgs)).toMap orElse fEnv val env1 = ((fRetC +: fArgs) zip (env(retC) +: rArgs)).toMap orElse fEnv
......
...@@ -42,7 +42,11 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) { ...@@ -42,7 +42,11 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
val f = Symbol.fresh("f") val f = Symbol.fresh("f")
val newBody = L.AppF(L.AtomN(f), retC, rewrite(fun) +: args.map(rewrite)) val newBody = L.AppF(L.AtomN(f), retC, rewrite(fun) +: args.map(rewrite))
val newArgs = Seq(rewrite(fun), L.AtomL(0)) val newArgs = Seq(rewrite(fun), L.AtomL(0))
L.LetP(f, CPS.BlockGet, newArgs, newBody) val res = L.LetP(f, CPS.BlockGet, newArgs, newBody)
println("satoeuhsoethu")
println(fName)
println(res)
res
} }
} }
...@@ -118,6 +122,10 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) { ...@@ -118,6 +122,10 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
val fv = fvs(fName) val fv = fvs(fName)
(fName -> (wName, sName, fv)) (fName -> (wName, sName, fv))
} }
println("eeeee")
println(initialFuns.map(_.name))
println(definedFuns)
println()
val knownFuns = oldKnownFuns ++ definedFuns val knownFuns = oldKnownFuns ++ definedFuns
val workers = initialFuns map { case H.Fun(fName, fRetC, fArgs, fBody) => val workers = initialFuns map { case H.Fun(fName, fRetC, fArgs, fBody) =>
......
...@@ -17,6 +17,7 @@ object Main { ...@@ -17,6 +17,7 @@ object Main {
andThen CPSValueRepresenter andThen CPSValueRepresenter
andThen treePrinter("---------- After value representation") andThen treePrinter("---------- After value representation")
andThen treeChecker andThen treeChecker
andThen treePrinter("---------- After hoisting")
andThen CPSHoister andThen CPSHoister
andThen CPSInterpreterLow andThen CPSInterpreterLow
) )
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
;; Test the "fun" expression ;; Test the "fun" expression
(@byte-write 73) ;;(@byte-write 73)
((fun (b) (@byte-write b)) 65) ;;((fun (b) (@byte-write b)) 65)
((fun (b) ;;((fun (b)
(@byte-write b) ;; (@byte-write b)
(@byte-write (@+ b 1))) ;; (@byte-write (@+ b 1)))
66) ;; 66)
(@byte-write ((fun (x) x) 68)) ;;(@byte-write ((fun (x) x) 68))
(let ((compose (fun (f g) (let ((compose (fun (f g)
(fun (x) (f (g x))))) (fun (x) (f (g x)))))
...@@ -17,16 +17,16 @@ ...@@ -17,16 +17,16 @@
(twice (fun (x) (@+ x x)))) (twice (fun (x) (@+ x x))))
(@byte-write ((compose succ twice) 34))) (@byte-write ((compose succ twice) 34)))
((fun (x y z) #u) ;;((fun (x y z) #u)
(@byte-write 70) ;; (@byte-write 70)
(@byte-write 71) ;; (@byte-write 71)
(@byte-write 72)) ;; (@byte-write 72))
(let* ((fact (fun (self x) ;;(let* ((fact (fun (self x)
(if (@= 0 x) ;; (if (@= 0 x)
1 ;; 1
(@* x (self self (@- x 1)))))) ;; (@* x (self self (@- x 1))))))
(fix (fun (f x) ;; (fix (fun (f x)
(f f x)))) ;; (f f x))))
(if (@= (fix fact 5) 120) ;; (if (@= (fix fact 5) 120)
(@byte-write 73))) ;; (@byte-write 73)))
Markdown is supported
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