10 let test_cases = ref []
12 test_cases := (name >:: body)::!test_cases;;
15 OUnit.assert_equal ~printer:Std.dump x y
20 method_name = `QName (`Namespace "","");
31 {empty_method with code=insts}
38 | `StackAdd | `StackDel
39 | `ScopeAdd | `ScopeDel
42 | `Script of s method_ ]
49 class_name = `QName (`Namespace "","Foo");
50 super = `QName (`Namespace "","Object");
51 class_flags= [`Sealed];
52 cinit = insts [`OpOnly1];
53 iinit = insts [`OpOnly2];
55 instance_methods = [insts [`OpOnly3]];
56 static_methods = [insts [`OpOnly4]];
65 Some {(insts [`OpOnly1]) with
66 method_name = `QName (`Namespace "","f")}
91 ([`String "foo"] :> Cpool.entry list)
93 ([`Int 42] :> Cpool.entry list)
111 module C = MethodOut.Make(Inst)
114 C.to_abc [] @@ insts xs
117 C.__to_cpool @@ insts xs
119 let _ = test "Instruction" begin
123 to_abc [`OpOnly1; `OpOnly2] in
124 ok 1 @@ List.length mi;
125 ok 1 @@ List.length mb;
126 ok 0 @@ (List.hd mb).method_sig;
127 ok [101; 102] @@ (List.hd mb).AbcType.code
130 let _ = test "constant" begin
133 to_cpool [`String; `Int; `Meth; `Class] in
135 (ignore $ Cpool.index cpool ) [
142 `QName (`Namespace "","f");
143 `QName (`Namespace "","");
144 `QName (`Namespace "","Foo");
145 `QName (`Namespace "","Object");
149 let _ = test "stack" begin
153 to_abc [`StackAdd; `StackAdd; `StackDel] in
154 ok 1 @@ List.length mi;
155 ok 1 @@ List.length mb;
156 ok 2 @@ (List.hd mb).max_stack;
159 let _ = test "scope" begin
163 to_abc [`ScopeAdd; `ScopeAdd; `ScopeDel] in
164 ok 1 @@ List.length mi;
165 ok 1 @@ List.length mb;
166 ok 2 @@ (List.hd mb).max_scope_depth;
167 ok 0 @@ (List.hd mb).init_scope_depth
170 let _ = test "method" begin
175 ok 2 @@ List.length mi;
176 ok 2 @@ List.length mb;
177 ok 0 @@ (List.nth mb 0).method_sig;
178 ok 1 @@ (List.nth mb 1).method_sig;
179 ok [101] @@ (List.nth mb 0).AbcType.code;
180 ok [0] @@ (List.nth mb 1).AbcType.code;
183 let _ = test "method dup" begin
184 (* same method should NOT be unified for AVM2 restriction *)
188 to_abc [`Meth; `Meth] in
189 ok 3 @@ List.length mi;
190 ok 3 @@ List.length mb
193 let method_trait { trait_name = name; data = data} =
195 | MethodTrait (0,i,[]) ->
197 | MethodTrait _ | SlotTrait _
198 | GetterTrait _ | SetterTrait _
199 | ClassTrait _ | FunctionTrait _
201 failwith "munt not happen"
203 let _ = test "class" begin
205 let {method_info = mi;
213 (List.nth mb i).AbcType.code in
214 ok 1 @@ List.length ci;
215 ok 1 @@ List.length ii;
216 ok 5 @@ List.length mi;
217 ok 5 @@ List.length mb;
218 let assert_cpool expect acutal =
219 ok (Cpool.index cp expect) @@ acutal in
225 ok [101] @@ nth_method c.AbcType.cinit;
226 begin match c.class_traits with
228 let (name,method_i) =
230 ok [104] @@ nth_method method_i;
231 assert_cpool (`QName (`Namespace "","")) @@ name
233 assert_failure "must not happen" end;
235 assert_cpool (`QName (`Namespace "","Foo")) @@ i.instance_name;
236 assert_cpool (`QName (`Namespace "","Object")) @@ i.super_name;
237 ok [Sealed] @@ i.instance_flags;
238 ok [102] @@ (List.nth mb i.AbcType.iinit).AbcType.code;
239 begin match i.instance_traits with
241 let (name,method_i) =
243 ok [103] @@ nth_method method_i;
244 assert_cpool (`QName (`Namespace "","")) @@ name
246 assert_failure "must not happen" end;
251 run_test_tt_main ("compile.ml" >::: !test_cases)