Compare commits
3 commits
2e551ab2c7
...
93e20cf208
Author | SHA1 | Date | |
---|---|---|---|
93e20cf208 | |||
f5783f2b2b | |||
613adf0621 |
10 changed files with 12 additions and 23 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
||||||
[submodule "src/tests_shared"]
|
|
||||||
path = src/tests_shared
|
|
||||||
url = git@github.com:tobast/mpri18-funcprog-tests.git
|
|
23
src/CPS.ml
23
src/CPS.ml
|
@ -35,8 +35,16 @@ let rec has_calls (t: S.term): bool = match t with
|
||||||
(* A lambda itself may contain calls, but this call is not evaluated at
|
(* A lambda itself may contain calls, but this call is not evaluated at
|
||||||
* declaration time *)
|
* declaration time *)
|
||||||
| S.App _ -> true
|
| S.App _ -> true
|
||||||
| S.IfZero _ -> true (* Cannot optimize that with the current languages *)
|
| S.IfZero (cond, tIf, tElse) ->
|
||||||
| S.Print _ -> true (* Cannot optimize that with the current languages *)
|
(* Cannot optimize continuation creation
|
||||||
|
List.exists has_calls [cond; tIf; tElse]
|
||||||
|
*)
|
||||||
|
true
|
||||||
|
| S.Print value ->
|
||||||
|
(* Cannot optimize continuation creation
|
||||||
|
has_calls value
|
||||||
|
*)
|
||||||
|
true
|
||||||
| S.Let (_, value, next) ->
|
| S.Let (_, value, next) ->
|
||||||
List.exists has_calls [value; next]
|
List.exists has_calls [value; next]
|
||||||
|
|
||||||
|
@ -53,16 +61,7 @@ let rec cps_term_inner (t: S.term) (cont: T.variable) (nameHint: string option)
|
||||||
: T.term = match t with
|
: T.term = match t with
|
||||||
| S.Var _ -> cps_value_as_term t cont
|
| S.Var _ -> cps_value_as_term t cont
|
||||||
| S.Lit _ -> cps_value_as_term t cont
|
| S.Lit _ -> cps_value_as_term t cont
|
||||||
| S.BinOp (t1, op, t2) ->
|
| S.BinOp _ -> cps_value_as_term t cont
|
||||||
(try cps_value_as_term t cont
|
|
||||||
with NotValue _ -> (
|
|
||||||
let t1Var = freshVar ()
|
|
||||||
and t2Var = freshVar () in
|
|
||||||
light_term t1Var t1 None @@
|
|
||||||
light_term t2Var t2 None @@
|
|
||||||
T.TailCall(T.vvar cont,
|
|
||||||
[T.VBinOp(T.vvar t1Var, op, T.vvar t2Var)])
|
|
||||||
))
|
|
||||||
| S.Lam _ as lambda ->
|
| S.Lam _ as lambda ->
|
||||||
let fName = freshBlockVarHinted nameHint in
|
let fName = freshBlockVarHinted nameHint in
|
||||||
light_term fName lambda None @@
|
light_term fName lambda None @@
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
../tests_shared/if_fib.exp
|
|
|
@ -1 +0,0 @@
|
||||||
../tests_shared/if_fib.lambda
|
|
|
@ -1 +0,0 @@
|
||||||
../tests_shared/if_nested.exp
|
|
|
@ -1 +0,0 @@
|
||||||
../tests_shared/if_nested.lambda
|
|
|
@ -1,2 +1,2 @@
|
||||||
let sum = fun x -> fun y -> x + y in
|
let sum = fun x -> fun y -> x + y in
|
||||||
print(sum 40 2)
|
print(40 + 2)
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
../tests_shared/ren.exp
|
|
|
@ -1 +0,0 @@
|
||||||
../tests_shared/ren.lambda
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit ab7549347e5b6b51183c5704048c6768aab23d86
|
|
Loading…
Reference in a new issue