OSDN Git Service

451170fbb1c9580852d37bd968201338bd173ac3
[happyabc/happyabc.git] / test / test_closuretrans.ml
1 open Base
2 open Ast
3 open Util
4 open ClosureTrans
5
6 let ok x y =
7   OUnit.assert_equal
8     ~printer:(fun x-> (Std.dump (List.map Ast.to_string_stmt x) ^ "\n"))
9     x y
10
11 test closure_with_args =
12   ok
13     [Define ("f",Lambda (["x"],(Let (["x",Var "x"],Block [Lambda ([],Block [Var "x"])]))))]
14     (trans @@ compile_string "(define (f x) (lambda () x))")
15
16 test closure_with_class =
17   ok [
18     Class ("Foo",("","Object"),[],
19            ["init",["self"],
20               Let (["self",Var "self"],
21                    Block [Lambda ([],Block [Var "self"])])])] @@
22     trans @@ compile_string "(define-class Foo (Object) ())  (define-method init ((self Foo)) (lambda () self))"
23