-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
89 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
(executable | ||
(public_name zaml) | ||
(name main) | ||
(libraries zaml ast parsing typing repl interpreter)) | ||
(libraries zaml ast parsing typing repl interpreter evaluating)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
let f1 = fun x -> fun y -> fun k -> k (k x y) (k y x) | ||
let f2 = fun x -> fun y -> let x = x y in fun x -> y x | ||
let f4 = fun x -> let y = let z = x (fun x -> x) in z in y | ||
let f2 = fun x -> let y = let z = x (fun x -> x) in z in y | ||
|
||
let g1 x y k = k (k x y) (k y x) | ||
|
||
let res_g1 = g1 5 10 (fun a b -> a + b) | ||
|
||
let h1 = fun x y k -> k (k x y) (k y x) | ||
|
||
let res_h1 = h1 5 10 (fun a b -> a + b) | ||
|
||
let f1 = fun x -> fun y -> fun k -> k (k x y) (k y x) | ||
|
||
let res_f1 = f1 5 10 (fun a b -> a + b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(library | ||
(name eval_test) | ||
(libraries parsing evaluating) | ||
(inline_tests) | ||
(preprocess | ||
(pps ppx_expect ppx_inline_test))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
open Evaluating.Env | ||
open Evaluating.Eval | ||
|
||
let start_time = Sys.time () | ||
let run () = () | ||
|
||
let test str ctx = | ||
Parsing.Parse.from_string str | ||
|> Parsing.Parse.parse |> List.hd | ||
|> Evaluating.Eval.value_of ctx | ||
|> fst | ||
|
||
let%test "function" = | ||
let ctx = | ||
Parsing.Parse.from_string "let f1 x y k = k (k x y) (k y x)" | ||
|> Parsing.Parse.parse | ||
|> List.fold_left | ||
(fun acc a -> | ||
let _, newctx = Evaluating.Eval.value_of acc a in | ||
ECtx.merge (fun _ _ x -> x) acc newctx) | ||
ECtx.empty | ||
in | ||
match test "f1 5 10 (fun a b -> a + b)" ctx |> string_of_val with | ||
| "30" -> true | ||
| _ -> false | ||
|
||
let%test "one lambda" = | ||
let ctx = | ||
Parsing.Parse.from_string "let f1 = fun x y k -> k (k x y) (k y x)" | ||
|> Parsing.Parse.parse | ||
|> List.fold_left | ||
(fun acc a -> | ||
let _, newctx = Evaluating.Eval.value_of acc a in | ||
ECtx.merge (fun _ _ x -> x) acc newctx) | ||
ECtx.empty | ||
in | ||
match test "f1 5 10 (fun a b -> a + b)" ctx |> string_of_val with | ||
| "30" -> true | ||
| _ -> false | ||
|
||
let%test "chained lambdas" = | ||
let ctx = | ||
Parsing.Parse.from_string | ||
"let f1 = fun x -> fun y -> fun k -> k (k x y) (k y x)" | ||
|> Parsing.Parse.parse | ||
|> List.fold_left | ||
(fun acc a -> | ||
let _, newctx = Evaluating.Eval.value_of acc a in | ||
ECtx.merge (fun _ _ x -> x) acc newctx) | ||
ECtx.empty | ||
in | ||
match test "f1 5 10 (fun a b -> a + b)" ctx |> string_of_val with | ||
| "30" -> true | ||
| _ -> false | ||
|
||
let () = | ||
"Eval tests completed. Time elapsed: " | ||
^ string_of_float ((Sys.time () -. start_time) *. 1000.) | ||
^ "ms" | ||
|> print_endline |