Compare commits

..

8 commits

Author SHA1 Message Date
2e551ab2c7 Clean unused values from pattern matching 2018-02-16 18:25:09 +01:00
89e4cde17f Properly handle binary operators 2018-02-16 18:20:33 +01:00
20d09abe2a Light CPS: cleaner error when lightening non-value 2018-02-16 18:08:54 +01:00
75522128da Light CPS: implement lambdas 2018-02-16 18:08:54 +01:00
04d1ec3555 Lighter CPS: first tentative version
Try to lighten the CPS transformation, using fewer continuations when
there is no need for one
2018-02-16 18:08:54 +01:00
86b097171e Update tests_shared 2018-02-16 18:05:17 +01:00
251bfd4b7d Fix multi_args.lambda 2018-02-16 18:04:34 +01:00
0939615350 Use shared tests 2018-02-16 17:58:30 +01:00
10 changed files with 23 additions and 12 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "src/tests_shared"]
path = src/tests_shared
url = git@github.com:tobast/mpri18-funcprog-tests.git

View file

@ -35,16 +35,8 @@ let rec has_calls (t: S.term): bool = match t with
(* A lambda itself may contain calls, but this call is not evaluated at
* declaration time *)
| S.App _ -> true
| S.IfZero (cond, tIf, tElse) ->
(* Cannot optimize continuation creation
List.exists has_calls [cond; tIf; tElse]
*)
true
| S.Print value ->
(* Cannot optimize continuation creation
has_calls value
*)
true
| S.IfZero _ -> true (* Cannot optimize that with the current languages *)
| S.Print _ -> true (* Cannot optimize that with the current languages *)
| S.Let (_, value, next) ->
List.exists has_calls [value; next]
@ -61,7 +53,16 @@ let rec cps_term_inner (t: S.term) (cont: T.variable) (nameHint: string option)
: T.term = match t with
| S.Var _ -> cps_value_as_term t cont
| S.Lit _ -> cps_value_as_term t cont
| S.BinOp _ -> cps_value_as_term t cont
| S.BinOp (t1, op, t2) ->
(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 ->
let fName = freshBlockVarHinted nameHint in
light_term fName lambda None @@

1
src/tests/if_fib.exp Symbolic link
View file

@ -0,0 +1 @@
../tests_shared/if_fib.exp

1
src/tests/if_fib.lambda Symbolic link
View file

@ -0,0 +1 @@
../tests_shared/if_fib.lambda

1
src/tests/if_nested.exp Symbolic link
View file

@ -0,0 +1 @@
../tests_shared/if_nested.exp

1
src/tests/if_nested.lambda Symbolic link
View file

@ -0,0 +1 @@
../tests_shared/if_nested.lambda

View file

@ -1,2 +1,2 @@
let sum = fun x -> fun y -> x + y in
print(40 + 2)
print(sum 40 2)

1
src/tests/ren.exp Symbolic link
View file

@ -0,0 +1 @@
../tests_shared/ren.exp

1
src/tests/ren.lambda Symbolic link
View file

@ -0,0 +1 @@
../tests_shared/ren.lambda

1
src/tests_shared Submodule

@ -0,0 +1 @@
Subproject commit ab7549347e5b6b51183c5704048c6768aab23d86