Browse Source

[java/cs] Unit tests now run correctly with -dce no
- fixed co/contra-variance overrides
- fixed late Codegen.get_underlying_type application
- java Int64-related errors (precision loss)

Caue Waneck 12 years ago
parent
commit
bb7ab46d9d
4 changed files with 60 additions and 26 deletions
  1. 35 19
      gencs.ml
  2. 22 3
      genjava.ml
  3. 2 2
      std/java/_std/haxe/Int64.hx
  4. 1 2
      tests/unit/compile.hxml

+ 35 - 19
gencs.ml

@@ -574,6 +574,7 @@ let configure gen =
       | TAbstract ({ a_path = ["cs"],"Out" },_)
       | TType ({ t_path = [],"Single" },[])
       | TAbstract ({ a_path = [],"Single" },[]) -> Some t
+      | TType ({ t_path = [],"Null" },[_]) -> Some t
       | TAbstract ({ a_impl = Some _ } as a, pl) ->
           Some (gen.gfollow#run_f ( Codegen.Abstract.get_underlying_type a pl) )
       | TAbstract( { a_path = ([], "EnumValue") }, _  )
@@ -1333,7 +1334,7 @@ let configure gen =
         (* <T>(string arg1, object arg2) with T : object *)
         (match cf.cf_expr with
         | Some { eexpr = TFunction tf } ->
-            print w "%s(%s)%s" (params) (String.concat ", " (List.map (fun (var, _) -> sprintf "%s %s" (argt_s (run_follow gen var.v_type)) (change_id var.v_name)) tf.tf_args)) (params_ext)
+            print w "%s(%s)%s" (params) (String.concat ", " (List.map2 (fun (var, _) (_,_,t) -> sprintf "%s %s" (argt_s (run_follow gen t)) (change_id var.v_name)) tf.tf_args args)) (params_ext)
         | _ ->
             print w "%s(%s)%s" (params) (String.concat ", " (List.map (fun (name, _, t) -> sprintf "%s %s" (argt_s (run_follow gen t)) (change_id name)) args)) (params_ext)
         );
@@ -1638,6 +1639,27 @@ let configure gen =
 
   SetHXGen.run_filter gen SetHXGen.default_hxgen_func;
 
+  (* before running the filters, follow all possible types *)
+  (* this is needed so our module transformations don't break some core features *)
+  (* like multitype selection *)
+  let run_follow_gen = run_follow gen in
+  let rec type_map e = Type.map_expr_type (fun e->type_map e) (run_follow_gen)  (fun tvar-> tvar.v_type <- (run_follow_gen tvar.v_type); tvar) e in
+  let super_map (cl,tl) = (cl, List.map run_follow_gen tl) in
+  List.iter (function
+    | TClassDecl cl ->
+        let all_fields = (Option.map_default (fun cf -> [cf]) [] cl.cl_constructor) @ cl.cl_ordered_fields @ cl.cl_ordered_statics in
+        List.iter (fun cf ->
+          cf.cf_type <- run_follow_gen cf.cf_type;
+          cf.cf_expr <- Option.map type_map cf.cf_expr
+        ) all_fields;
+       cl.cl_dynamic <- Option.map run_follow_gen cl.cl_dynamic;
+       cl.cl_array_access <- Option.map run_follow_gen cl.cl_array_access;
+       cl.cl_init <- Option.map type_map cl.cl_init;
+       cl.cl_super <- Option.map super_map cl.cl_super;
+       cl.cl_implements <- List.map super_map cl.cl_implements
+    | _ -> ()
+    ) gen.gcon.types;
+
   let closure_t = ClosuresToClass.DoubleAndDynamicClosureImpl.get_ctx gen 6 in
 
   (*let closure_t = ClosuresToClass.create gen 10 float_cl
@@ -1913,25 +1935,19 @@ let configure gen =
       | TUnop (_, _, e1) -> is_dynamic_expr e1 || is_null_expr e1 (* we will see if the expression is Null<T> also, as the unwrap from Unop will be the same *)
       | _ -> false)
     (fun e1 e2 ->
-      let is_null e = match e.eexpr with | TConst(TNull) | TLocal({ v_name = "__undefined__" }) -> true | _ -> false in
-
-      if is_null e1 || is_null e2 then
-        { e1 with eexpr = TBinop(Ast.OpEq, e1, e2); etype = basic.tbool }
-      else begin
-        let is_basic = is_cs_basic_type (follow e1.etype) || is_cs_basic_type (follow e2.etype) in
-        let is_ref = if is_basic then false else match follow e1.etype, follow e2.etype with
-          | TDynamic _, _
-          | _, TDynamic _
-          | TInst( { cl_path = ([], "String") }, [] ), _
-          | _, TInst( { cl_path = ([], "String") }, [] )
-          | TInst( { cl_kind = KTypeParameter _ }, [] ), _
-          | _, TInst( { cl_kind = KTypeParameter _ }, [] ) -> false
-          | _, _ -> true
-        in
+      let is_basic = is_cs_basic_type (follow e1.etype) || is_cs_basic_type (follow e2.etype) in
+      let is_ref = if is_basic then false else match follow e1.etype, follow e2.etype with
+        | TDynamic _, _
+        | _, TDynamic _
+        | TInst( { cl_path = ([], "String") }, [] ), _
+        | _, TInst( { cl_path = ([], "String") }, [] )
+        | TInst( { cl_kind = KTypeParameter _ }, [] ), _
+        | _, TInst( { cl_kind = KTypeParameter _ }, [] ) -> false
+        | _, _ -> true
+      in
 
-        let static = mk_static_field_access_infer (runtime_cl) (if is_ref then "refEq" else "eq") e1.epos [] in
-        { eexpr = TCall(static, [e1; e2]); etype = gen.gcon.basic.tbool; epos=e1.epos }
-      end
+      let static = mk_static_field_access_infer (runtime_cl) (if is_ref then "refEq" else "eq") e1.epos [] in
+      { eexpr = TCall(static, [e1; e2]); etype = gen.gcon.basic.tbool; epos=e1.epos }
     )
     (fun e e1 e2 ->
       match may_nullable e1.etype, may_nullable e2.etype with

+ 22 - 3
genjava.ml

@@ -893,8 +893,6 @@ let configure gen =
               path_s_import pos (["java";"lang"], "Object"))
         | TDynamic _ ->
             path_s_import pos (["java";"lang"], "Object")
-      | TAbstract(a,pl) when a.a_impl <> None ->
-        t_s pos (Codegen.Abstract.get_underlying_type a pl)
       (* No Lazy type nor Function type made. That's because function types will be at this point be converted into other types *)
       | _ -> if !strict_mode then begin trace ("[ !TypeError " ^ (Type.s_type (Type.print_context()) t) ^ " ]"); assert false end else "[ !TypeError " ^ (Type.s_type (Type.print_context()) t) ^ " ]"
 
@@ -1466,7 +1464,7 @@ let configure gen =
         (* <T>(string arg1, object arg2) with T : object *)
         (match cf.cf_expr with
           | Some { eexpr = TFunction tf } ->
-              print w "(%s)" (String.concat ", " (List.map (fun (var,_) -> sprintf "%s %s" (t_s cf.cf_pos (run_follow gen var.v_type)) (change_id var.v_name)) tf.tf_args))
+              print w "(%s)" (String.concat ", " (List.map2 (fun (var,_) (_,_,t) -> sprintf "%s %s" (t_s cf.cf_pos (run_follow gen t)) (change_id var.v_name)) tf.tf_args args))
           | _ ->
               print w "(%s)" (String.concat ", " (List.map (fun (name, _, t) -> sprintf "%s %s" (t_s cf.cf_pos (run_follow gen t)) (change_id name)) args))
         );
@@ -1696,6 +1694,27 @@ let configure gen =
 
   SetHXGen.run_filter gen SetHXGen.default_hxgen_func;
 
+  (* before running the filters, follow all possible types *)
+  (* this is needed so our module transformations don't break some core features *)
+  (* like multitype selection *)
+  let run_follow_gen = run_follow gen in
+  let rec type_map e = Type.map_expr_type (fun e->type_map e) (run_follow_gen)  (fun tvar-> tvar.v_type <- (run_follow_gen tvar.v_type); tvar) e in
+  let super_map (cl,tl) = (cl, List.map run_follow_gen tl) in
+  List.iter (function
+    | TClassDecl cl ->
+        let all_fields = (Option.map_default (fun cf -> [cf]) [] cl.cl_constructor) @ cl.cl_ordered_fields @ cl.cl_ordered_statics in
+        List.iter (fun cf ->
+          cf.cf_type <- run_follow_gen cf.cf_type;
+          cf.cf_expr <- Option.map type_map cf.cf_expr
+        ) all_fields;
+       cl.cl_dynamic <- Option.map run_follow_gen cl.cl_dynamic;
+       cl.cl_array_access <- Option.map run_follow_gen cl.cl_array_access;
+       cl.cl_init <- Option.map type_map cl.cl_init;
+       cl.cl_super <- Option.map super_map cl.cl_super;
+       cl.cl_implements <- List.map super_map cl.cl_implements
+    | _ -> ()
+    ) gen.gcon.types;
+
   let closure_t = ClosuresToClass.DoubleAndDynamicClosureImpl.get_ctx gen 6 in
 
   (*let closure_t = ClosuresToClass.create gen 10 float_cl

+ 2 - 2
std/java/_std/haxe/Int64.hx

@@ -42,7 +42,7 @@ private typedef NativeInt64 = Int;
 
 	public static inline function getHigh( x : Int64 ) : Int
 	{
-		return cast(x,NativeInt64) >>> 32;
+		return cast(cast(x,NativeInt64) >>> cast(32,NativeInt64), Int);
 	}
 
 	public static inline function ofInt( x : Int ) : Int64 {
@@ -127,7 +127,7 @@ private typedef NativeInt64 = Int;
 
 	public static inline function compare( a : Int64, b : Int64 ) : Int
 	{
-		return cast (a.asNative() - b.asNative());
+		return cast(a.asNative() - b.asNative(), Int);
 	}
 
 	/**

+ 1 - 2
tests/unit/compile.hxml

@@ -21,8 +21,7 @@
 -resource res1.txt
 -resource res2.bin
 --no-opt
-#DCE temporarily disabled so we can fix all DCE-obscured issues
-#-dce full
+-dce full
 --each
 
 #flash8