12 `QName ((`Namespace (join ns)),x)
14 let ok expect actual =
15 assert_equal (expect@[ `Pop ]) @@
16 generate_program [`Expr actual]
18 let member i ns name =
19 `BindVar (Node.ghost (Member ((Scope i),(ns,name))))
21 let global_member ns name =
22 `BindVar (Node.ghost (Member (Global,(ns,name))))
25 `BindVar (Node.ghost (Slot ((Scope i),j)))
28 `BindVar (Node.ghost (Register i))
31 let l = Label.peek 0 in
32 {Asm.empty_method with
33 method_name = qname [] @@ Label.to_string l;
35 instructions = inst@[`ReturnValue] }
38 ("codegen.ml(expr)" >::: [
42 ok [`PushByte 42] (int 42));
45 ok [`PushInt 200] (int 200);
46 ok [`PushInt 300] (int 300));
49 ok [`PushString "Thanks for All the Fish"] @@
50 string "Thanks for All the Fish");
53 ok [`PushDouble 4.2] @@
63 ok [`NewArray 0] (`Array []);
64 ok [`PushByte 1; `PushByte 2; `NewArray 2] (`Array [int 1; int 2]););
75 `IfNe a; `PushByte 0; `Coerce_a; `Jump b;
76 `Label a; `PushByte 1; `Coerce_a; `Label b] @@
77 if_ (call [var [] "="; int 10; int 20]) (int 0) (int 1));
89 op a; `PushByte 0; `Coerce_a; `Jump b;
90 `Label a; `PushByte 1; `Coerce_a; `Label b] @@
91 if_ (call [var [] sym; int 10; int 20]) (int 0) (int 1))
92 [("=" ,fun x -> `IfNe x);
93 ("<=",fun x -> `IfNle x);
94 (">" ,fun x -> `IfNgt x);
95 (">=",fun x -> `IfNge x); ]);
98 ok [`PushByte 1; `Pop; `PushByte 2] @@
102 ok [`PushUndefined] @@
106 ok [`PushString "x"; `PushByte 1;
107 `PushString "y"; `PushByte 2;
112 let_ ["x",int 1; "y",int 2] @@ block []);
120 `SetProperty (qname [] "x");
124 let_rec ["x",int 42] @@ block []);
128 inner [] [`GetLex (qname [] "z")] in
129 ok [`NewFunction m] @@
130 lambda [] @@ block [var [] "z"]);
134 ok [`GetScopeObject 1;
135 `GetProperty (qname [] "foo")] @@
137 ok [`GetScopeObject 1;
138 `GetProperty (qname [] "bar")] @@
143 `GetProperty (qname [] "foo")] @@
144 global_member [] "foo");
147 ok [`GetScopeObject 0;
160 ok [`FindPropStrict (qname [] "print");
162 `CallPropLex ((qname [] "print"),1)] @@
163 call [var [] "print"; string "Hello"]);
166 ok [`GetScopeObject 1;
168 `CallPropLex ((qname [] "f"),1)] @@
169 call [member 1 [] "f"; int 42]);
174 `CallPropLex ((qname [] "f"),1)] @@
175 call [global_member [] "f"; int 42]);
178 ok [`PushByte 1; `PushByte 2; `Add_i] @@
179 call [var [] "+";int 1;int 2];
180 ok [`PushByte 1; `PushByte 2; `Equals] @@
181 call [var [] "=";int 1;int 2])