-
Notifications
You must be signed in to change notification settings - Fork 0
/
closure_test.ml
37 lines (33 loc) · 1.26 KB
/
closure_test.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
let f_s s =
Lex.f "test.ml" s
|> Parser.f
|> Ast.f
|> Alpha.f Alpha.pervasive_env
|> Typing.f Typing.pervasive_env |> snd
|> Flatlet.f
|> Closure.f Closure.pervasives
module C = Closure
let assert_eq a b =
if a = b
then ()
else
failwith @@ "closure unittest failed "
let add = C.Var (fst (Tbl.lookup ["+"] Alpha.pervasive_var_env |> Tbl.expect ""), Types.Fun (Types.Int, Types.Fun (Types.Int, Types.Int)))
let neg = C.Var (fst (Tbl.lookup ["<neg>"] Alpha.pervasive_var_env |> Tbl.expect ""), Types.Fun (Types.Int, Types.Int))
let eq = C.Var (fst (Tbl.lookup ["="] Alpha.pervasive_var_env |> Tbl.expect ""), Types.Fun (Types.Int, Types.Fun (Types.Int, Types.Bool)))
let i_i_i = Types.Fun (Types.Int, (Types.Fun (Types.Int, Types.Int)))
let i_i_b = Types.Fun (Types.Int, (Types.Fun (Types.Int, Types.Bool)))
let i_i = Types.Fun (Types.Int, Types.Int)
let x_id = ([], "x", 0)
let y_id = ([], "y", 1)
let x = C.Var (x_id, Types.Int)
let y = C.Var (y_id, Types.Int)
let cap4_id = ([], "<cap>", 4)
let cap5_id = ([], "<cap>", 5)
let cap6_id = ([], "<cap>", 6)
let cap4 = C.Var (cap4_id, i_i_b)
let cap5 = C.Var (cap5_id, i_i_i)
let cap6 = C.Var (cap6_id, i_i)
let () = ()
(*assert_eq (f_s "let x = fun x -> fun y -> (- x + y) = 0")
[]*)