Commit cab13317 authored by Luca Bataillard's avatar Luca Bataillard
Browse files

revert expr-fun and remove extra printlns

parent c15ee6be
...@@ -62,11 +62,6 @@ sealed abstract class CPSInterpreter[M <: CPSTreeModule]( ...@@ -62,11 +62,6 @@ 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
......
...@@ -37,17 +37,12 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) { ...@@ -37,17 +37,12 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) {
if (knownFuns.contains(fName)) { if (knownFuns.contains(fName)) {
val (wName, sName, fvs) = knownFuns(fName) val (wName, sName, fvs) = knownFuns(fName)
val newArgs = (args map rewrite) ++ (fvs map L.AtomN) val newArgs = (args map rewrite) ++ (fvs map L.AtomN)
val res = L.AppF(L.AtomN(wName), retC, newArgs) L.AppF(L.AtomN(wName), retC, newArgs)
res
} else { } else {
val f = Symbol.fresh("closure") val f = Symbol.fresh("closure")
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))
val res = L.LetP(f, CPS.BlockGet, newArgs, newBody) L.LetP(f, CPS.BlockGet, newArgs, newBody)
println("aaaaaaaaaaaa")
println(fName)
println(res)
res
} }
} }
...@@ -111,10 +106,6 @@ object CPSValueRepresenter extends (H.Tree => L.Tree) { ...@@ -111,10 +106,6 @@ 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) =>
......
...@@ -2,39 +2,31 @@ ...@@ -2,39 +2,31 @@
;; 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)))))
;; (succ (fun (x) (@+ x 1))) (succ (fun (x) (@+ x 1)))
;; (twice (fun (x) (@+ x x)))) (twice (fun (x) (@+ x x))))
;; (@byte-write ((compose succ twice) 34))) (@byte-write ((compose succ twice) 34)))
(let ((fun (x y z) #u)
( (@byte-write 70)
(compose (fun (f) (@byte-write 71)
(fun (x) (f x))) (@byte-write 72))
)
)
((compose 1)))
;;((fun (x y z) #u) (let* ((fact (fun (self x)
;; (@byte-write 70) (if (@= 0 x)
;; (@byte-write 71) 1
;; (@byte-write 72)) (@* x (self self (@- x 1))))))
(fix (fun (f x)
;;(let* ((fact (fun (self x) (f f x))))
;; (if (@= 0 x) (if (@= (fix fact 5) 120)
;; 1 (@byte-write 73)))
;; (@* x (self self (@- x 1))))))
;; (fix (fun (f x)
;; (f f x))))
;; (if (@= (fix fact 5) 120)
;; (@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