Jelajahi Sumber

Merge branch 'development' of github.com:HaxeFoundation/haxe into strict-name-encoding

杨博 11 tahun lalu
induk
melakukan
36efa8c1eb
4 mengubah file dengan 250 tambahan dan 17 penghapusan
  1. 32 14
      gencpp.ml
  2. 1 1
      std/cpp/_std/haxe/ds/ObjectMap.hx
  3. 1 1
      std/cpp/_std/sys/FileSystem.hx
  4. 216 1
      tests/unit/unitstd/Math.unit.hx

+ 32 - 14
gencpp.ml

@@ -4326,9 +4326,17 @@ let rec script_type_string haxe_type =
       | TInst ({ cl_path = [],"Float" },_)
       | TEnum ({ e_path = [],"Bool" },_) -> "Dynamic"
       | _ -> script_type_string t)
+   | TInst ({cl_path=[],"Null"},[t]) ->
+      (match follow t with
+      | TAbstract ({ a_path = [],"Int" },_)
+      | TAbstract ({ a_path = [],"Float" },_)
+      | TAbstract ({ a_path = [],"Bool" },_)
+      | TInst ({ cl_path = [],"Int" },_)
+      | TInst ({ cl_path = [],"Float" },_)
+      | TEnum ({ e_path = [],"Bool" },_) -> "Dynamic"
+      | _ -> script_type_string t )
    | _ ->
       match follow haxe_type with
-
       | TType ({t_path = [],"Array"},params) -> "Array"
       | TInst ({cl_path=[],"Array"},params) ->
          (match params with
@@ -4339,13 +4347,14 @@ let rec script_type_string haxe_type =
             | "bool" -> "Array.bool"
             | "::String" -> "Array.String"
             | "unsigned char" -> "Array.unsigned char"
-            | _ -> "Array.Dynamic"
+            | "Dynamic" -> "Array.Any"
+            | _ -> "Array.Object"
             )
-         | _ -> "Array.Dynamic"
+         | _ -> "Array.Object"
          )
-      | TAbstract (abs,pl) when abs.a_impl <> None ->
+     | TAbstract (abs,pl) when abs.a_impl <> None ->
          script_type_string  (Codegen.Abstract.get_underlying_type abs pl);
-      | _ ->
+     | _ ->
          type_string_suff "" haxe_type
 ;;
 
@@ -4353,7 +4362,7 @@ type array_of =
    | ArrayInterface of int
    | ArrayData of string
    | ArrayObject
-   | ArrayDynamic
+   | ArrayAny
    | ArrayNone
 ;;
 
@@ -4470,6 +4479,7 @@ class script_writer common_ctx ctx filename =
       match varExpr with
       | Some expression -> this#gen_expression expression
       | _ -> ()
+   method implDynamic = this#write "IMPLDYNAMIC\n";
    method writeVar v =
       this#ident v.v_name;
       this#wint v.v_id;
@@ -4497,7 +4507,7 @@ class script_writer common_ctx ctx filename =
                   | "::String"  -> ArrayData "String"
                   | "int" | "Float" | "bool" | "String" | "unsigned char" ->
                      ArrayData typeName
-                  | "Dynamic" -> ArrayDynamic
+                  | "Dynamic" -> ArrayAny
                   | _ when is_interface_type param -> ArrayInterface (this#typeId (script_type_string param))
                   | _ -> ArrayObject
                   )
@@ -4512,17 +4522,18 @@ class script_writer common_ctx ctx filename =
                get_array_type expr.etype
             in
          match (get_array_type toType), (get_array_expr_type expr) with
-         | ArrayDynamic, ArrayNone
-         | ArrayDynamic, ArrayData _ -> write_cast ("TODYNARRAY")
+         | ArrayAny, _ -> false
+         | ArrayObject, ArrayData _ -> write_cast ("TODYNARRAY")
          | ArrayData t, ArrayNone
-         | ArrayData t, ArrayDynamic -> write_cast ("TODATAARRAY " ^ (this#typeTextString ("Array." ^ t)))
+         | ArrayData t, ArrayObject
+         | ArrayData t, ArrayAny -> write_cast ("TODATAARRAY " ^ (this#typeTextString ("Array." ^ t)))
          | ArrayInterface t, ArrayNone
-         | ArrayInterface t, ArrayDynamic -> write_cast ("TOINTERFACEARRAY " ^ (string_of_int t))
+         | ArrayInterface t, ArrayAny -> write_cast ("TOINTERFACEARRAY " ^ (string_of_int t))
          | _,_ -> (* a0,a1 ->
                let arrayString a =
                   match a with
                   | ArrayNone -> "ArrayNone"
-                  | ArrayDynamic -> "ArrayDynamic"
+                  | ArrayAny -> "ArrayAny"
                   | ArrayObject -> "ArrayObject"
                   | ArrayData _ -> "ArrayData"
                   | ArrayInterface _ -> "ArrayInterface"
@@ -4609,6 +4620,10 @@ class script_writer common_ctx ctx filename =
                this#write ("CALLMEMBER " ^ (this#typeText obj.etype) ^ " " ^ (this#stringText field.cf_name) ^
                   argN ^ "\n");
                this#gen_expression obj;
+      | TField (obj,FDynamic (name) )  when (is_internal_member name || (type_string obj.etype = "::String" && name="cca") ) ->
+               this#write ("CALLMEMBER " ^ (this#typeText obj.etype) ^ " " ^ (this#stringText name) ^
+                  argN ^ "\n");
+               this#gen_expression obj;
       | TConst TSuper -> this#write ("CALLSUPERNEW " ^ (this#typeText func.etype) ^ " " ^ argN ^ "\n");
       | TField (_,FEnum (enum,field)) -> this#write ("CREATEENUM " ^ (this#enumText enum) ^ " " ^ (this#stringText field.ef_name) ^ argN ^ "\n");
       | _ -> this#write ("CALL " ^ argN ^ "\n");
@@ -4762,6 +4777,7 @@ let generate_script_class common_ctx script class_def =
    script#write ((string_of_int ( (List.length ordered_fields) +
                                  (List.length ordered_statics) +
                                  (match class_def.cl_constructor with Some _ -> 1 | _ -> 0 ) +
+                                 (if (implement_dynamic_here class_def) then 1 else 0) +
                                  (match class_def.cl_init with Some _ -> 1 | _ -> 0 ) ) )
                                  ^ "\n");
 
@@ -4769,7 +4785,7 @@ let generate_script_class common_ctx script class_def =
       match field.cf_kind, follow field.cf_type with
       | Var { v_read = AccInline; v_write = AccNever },_ ->
          script#write "INLINE\n";
-      | Var v,t ->
+      | Var v,_ ->
          let mode_code mode = match mode with
          | AccNormal -> "N"
          | AccNo -> "!"
@@ -4780,7 +4796,7 @@ let generate_script_class common_ctx script class_def =
          | AccRequire (_,_) -> "?"
          in
          let isExtern = is_extern_field field in
-         script#var (mode_code v.v_read) (mode_code v.v_write) isExtern isStatic field.cf_name t field.cf_expr
+         script#var (mode_code v.v_read) (mode_code v.v_write) isExtern isStatic field.cf_name field.cf_type field.cf_expr
       | Method MethDynamic, TFun(args,ret) ->
          script#func isStatic true field.cf_name ret args class_def.cl_interface field.cf_expr
       | Method _, TFun(args,ret) when field.cf_name="new" ->
@@ -4799,6 +4815,8 @@ let generate_script_class common_ctx script class_def =
 
    List.iter (generate_field false) ordered_fields;
    List.iter (generate_field true) ordered_statics;
+   if (implement_dynamic_here class_def) then
+      script#implDynamic;
    script#write "\n";
 ;;
 

+ 1 - 1
std/cpp/_std/haxe/ds/ObjectMap.hx

@@ -41,7 +41,7 @@ class ObjectMap<K:{},V> implements Map.IMap<K,V> {
 		return __Internal.get( untyped __global__.__hxcpp_obj_id(key) );
 	}
 
-	public inline function exists( key : K ) : Bool {
+	public function exists( key : K ) : Bool {
 		return __Internal.exists( untyped __global__.__hxcpp_obj_id(key) );
 	}
 

+ 1 - 1
std/cpp/_std/sys/FileSystem.hx

@@ -30,7 +30,7 @@ private enum FileKind {
 @:coreApi
 class FileSystem {
 
-	public static inline function exists( path : String ) : Bool {
+	public static function exists( path : String ) : Bool {
 		return sys_exists(haxe.io.Path.removeTrailingSlashes(path));
 	}
 

+ 216 - 1
tests/unit/unitstd/Math.unit.hx

@@ -206,4 +206,219 @@ Math.isFinite(0.0) == true;
 Math.isNaN(Math.POSITIVE_INFINITY) == false;
 Math.isNaN(Math.NEGATIVE_INFINITY) == false;
 Math.isNaN(Math.NaN) == true;
-Math.isNaN(0.0) == false;
+Math.isNaN(0.0) == false;
+
+
+// Dynamic version
+var math = Math;
+
+
+//1.0 / zero == math.POSITIVE_INFINITY;
+//-1.0 / zero == math.NEGATIVE_INFINITY;
+(math.NaN == math.NaN) == false;
+math.isNaN(math.NaN) == true;
+math.isNaN(math.sqrt( -1)) == true;
+math.NEGATIVE_INFINITY == math.NEGATIVE_INFINITY;
+math.POSITIVE_INFINITY == math.POSITIVE_INFINITY;
+// +
+math.POSITIVE_INFINITY + math.POSITIVE_INFINITY == math.POSITIVE_INFINITY;
+math.NEGATIVE_INFINITY + math.NEGATIVE_INFINITY == math.NEGATIVE_INFINITY;
+math.POSITIVE_INFINITY + one == math.POSITIVE_INFINITY;
+math.NEGATIVE_INFINITY + one == math.NEGATIVE_INFINITY;
+math.isNaN(math.POSITIVE_INFINITY + math.NEGATIVE_INFINITY) == true;
+math.isNaN(math.POSITIVE_INFINITY + math.NaN) == true;
+math.isNaN(math.NEGATIVE_INFINITY + math.NaN) == true;
+// -
+one - math.POSITIVE_INFINITY == math.NEGATIVE_INFINITY;
+one - math.NEGATIVE_INFINITY == math.POSITIVE_INFINITY;
+-math.POSITIVE_INFINITY == math.NEGATIVE_INFINITY;
+-math.NEGATIVE_INFINITY == math.POSITIVE_INFINITY;
+math.POSITIVE_INFINITY - one == math.POSITIVE_INFINITY;
+math.NEGATIVE_INFINITY - one == math.NEGATIVE_INFINITY;
+math.isNaN(math.POSITIVE_INFINITY - math.POSITIVE_INFINITY ) == true;
+math.isNaN(math.NEGATIVE_INFINITY - math.NEGATIVE_INFINITY) == true;
+math.POSITIVE_INFINITY - math.NEGATIVE_INFINITY == math.POSITIVE_INFINITY;
+math.NEGATIVE_INFINITY - math.POSITIVE_INFINITY == math.NEGATIVE_INFINITY;
+math.isNaN(math.POSITIVE_INFINITY - math.NaN) == true;
+math.isNaN(math.NEGATIVE_INFINITY - math.NaN) == true;
+math.isNaN(math.NaN - math.POSITIVE_INFINITY) == true;
+math.isNaN(math.NaN - math.NEGATIVE_INFINITY) == true;
+// *
+math.POSITIVE_INFINITY * one == math.POSITIVE_INFINITY;
+math.NEGATIVE_INFINITY * one == math.NEGATIVE_INFINITY;
+math.isNaN(math.POSITIVE_INFINITY * zero) == true;
+math.isNaN(math.NEGATIVE_INFINITY * zero) == true;
+math.POSITIVE_INFINITY * math.POSITIVE_INFINITY == math.POSITIVE_INFINITY;
+math.NEGATIVE_INFINITY * math.NEGATIVE_INFINITY  == math.POSITIVE_INFINITY;
+math.POSITIVE_INFINITY * math.NEGATIVE_INFINITY == math.NEGATIVE_INFINITY;
+math.isNaN(math.POSITIVE_INFINITY * math.NaN) == true;
+math.isNaN(math.NEGATIVE_INFINITY * math.NaN) == true;
+// /
+math.POSITIVE_INFINITY / one == math.POSITIVE_INFINITY;
+math.NEGATIVE_INFINITY / one == math.NEGATIVE_INFINITY;
+//math.POSITIVE_INFINITY / zero == math.POSITIVE_INFINITY;
+//math.NEGATIVE_INFINITY / zero == math.NEGATIVE_INFINITY;
+math.isNaN(math.POSITIVE_INFINITY / math.POSITIVE_INFINITY);
+math.isNaN(math.POSITIVE_INFINITY / math.NEGATIVE_INFINITY);
+math.isNaN(math.NEGATIVE_INFINITY / math.POSITIVE_INFINITY);
+math.isNaN(math.NEGATIVE_INFINITY / math.NEGATIVE_INFINITY);
+math.isNaN(math.NaN / math.POSITIVE_INFINITY);
+math.isNaN(math.POSITIVE_INFINITY / math.NaN);
+math.isNaN(math.NaN / math.POSITIVE_INFINITY);
+math.isNaN(math.NEGATIVE_INFINITY / math.NaN);
+
+// abs
+math.abs(-1.223) == 1.223;
+math.abs(1.223) == 1.223;
+math.abs(0) == 0;
+math.isNaN(math.abs(math.NaN)) == true;
+math.abs(math.NEGATIVE_INFINITY) == math.POSITIVE_INFINITY;
+math.abs(math.POSITIVE_INFINITY) == math.POSITIVE_INFINITY;
+
+// min
+math.min(0.0, 1.0) == 0.0;
+math.min(0.0, -1.0) == -1.0;
+math.min(0.0, 0.0) == 0.0;
+math.min(1.0, 1.0) == 1.0;
+math.min(math.NEGATIVE_INFINITY, math.NEGATIVE_INFINITY) == math.NEGATIVE_INFINITY;
+math.min(math.NEGATIVE_INFINITY, math.POSITIVE_INFINITY) == math.NEGATIVE_INFINITY;
+math.min(math.POSITIVE_INFINITY, math.POSITIVE_INFINITY) == math.POSITIVE_INFINITY;
+math.min(math.POSITIVE_INFINITY, zero) == zero;
+math.min(math.NEGATIVE_INFINITY, zero) == math.NEGATIVE_INFINITY;
+math.isNaN(math.min(math.NEGATIVE_INFINITY, math.NaN)) == true;
+math.isNaN(math.min(math.POSITIVE_INFINITY, math.NaN)) == true;
+math.isNaN(math.min(math.NaN, math.NaN)) == true;
+math.isNaN(math.min(one, math.NaN)) == true;
+math.isNaN(math.min(zero, math.NaN)) == true;
+math.isNaN(math.min(math.NaN, math.NEGATIVE_INFINITY)) == true;
+math.isNaN(math.min(math.NaN,math.POSITIVE_INFINITY)) == true;
+math.isNaN(math.min(math.NaN, one)) == true;
+math.isNaN(math.min(math.NaN, zero)) == true;
+
+// max
+math.max(0.0, 1.0) == 1.0;
+math.max(0.0, -1.0) == 0.0;
+math.max(0.0, 0.0) == 0.0;
+math.max(1.0, 1.0) == 1.0;
+math.max(math.NEGATIVE_INFINITY, math.NEGATIVE_INFINITY) == math.NEGATIVE_INFINITY;
+math.max(math.NEGATIVE_INFINITY, math.POSITIVE_INFINITY) == math.POSITIVE_INFINITY;
+math.max(math.POSITIVE_INFINITY, math.POSITIVE_INFINITY) == math.POSITIVE_INFINITY;
+math.max(math.POSITIVE_INFINITY, zero) == math.POSITIVE_INFINITY;
+math.max(math.NEGATIVE_INFINITY, zero) == 0;
+math.isNaN(math.max(math.NEGATIVE_INFINITY, math.NaN)) == true;
+math.isNaN(math.max(math.POSITIVE_INFINITY, math.NaN)) == true;
+math.isNaN(math.max(math.NaN, math.NaN)) == true;
+math.isNaN(math.max(one, math.NaN)) == true;
+math.isNaN(math.max(zero, math.NaN)) == true;
+math.isNaN(math.max(math.NaN, math.NEGATIVE_INFINITY)) == true;
+math.isNaN(math.max(math.NaN,math.POSITIVE_INFINITY)) == true;
+math.isNaN(math.max(math.NaN, one)) == true;
+math.isNaN(math.max(math.NaN, zero)) == true;
+
+// sin
+math.sin(0.0) == 0.0;
+math.sin(math.PI / 2) == 1.0;
+math.sin(math.PI) == 0.0;
+math.sin(math.PI * 3 / 2) == -1.0;
+math.isNaN(math.sin(math.POSITIVE_INFINITY)) == true;
+math.isNaN(math.sin(math.NEGATIVE_INFINITY)) == true;
+math.isNaN(math.sin(math.NaN)) == true;
+
+// cos
+math.cos(0.0) == 1.0;
+math.cos(math.PI / 2) == 0.0;
+math.cos(math.PI) == -1.0;
+math.cos(math.PI * 3 / 2) == 0.0;
+math.isNaN(math.cos(math.POSITIVE_INFINITY)) == true;
+math.isNaN(math.cos(math.NEGATIVE_INFINITY)) == true;
+math.isNaN(math.cos(math.NaN)) == true;
+
+// exp
+math.exp(0.0) == 1.0;
+math.exp(1.0) == 2.7182818284590452353602874713527;
+math.exp(math.POSITIVE_INFINITY) == math.POSITIVE_INFINITY;
+math.exp(math.NEGATIVE_INFINITY) == 0.0;
+math.isNaN(math.exp(math.NaN)) == true;
+
+// log
+math.log(0.0) == math.NEGATIVE_INFINITY;
+math.log(2.7182818284590452353602874713527) == 1.0;
+math.isNaN(math.log( -1.0)) == true;
+math.isNaN(math.log(math.NaN)) == true;
+math.isNaN(math.log(math.NEGATIVE_INFINITY)) == true;
+math.log(math.POSITIVE_INFINITY) == math.POSITIVE_INFINITY;
+
+// exp + log
+var floats = [1.33, 12.0, -112.999992, 0.0, math.NEGATIVE_INFINITY, math.POSITIVE_INFINITY];
+for (f in floats) {
+	#if !php
+	feq(math.log(math.exp(f)), f);
+	#end
+}
+
+// sqrt
+math.sqrt(4.0) == 2;
+math.sqrt(0.0) == 0.0;
+math.sqrt(math.POSITIVE_INFINITY) == math.POSITIVE_INFINITY;
+math.isNaN(math.sqrt(math.NEGATIVE_INFINITY)) == true;
+math.isNaN(math.sqrt(math.NaN)) == true;
+math.isNaN(math.sqrt( -1.0)) == true;
+
+// round
+math.round(0.0) == 0;
+math.round(0.1) == 0;
+math.round(0.4999) == 0;
+math.round(0.5) == 1;
+math.round(1.0) == 1;
+math.round(1.499) == 1;
+math.round(-0.1) == 0;
+math.round(-0.4999) == 0;
+math.round(-0.5) == 0;
+math.round(-0.50001) == -1;
+math.round(-1.0) == -1;
+math.round(-1.499) == -1;
+math.round(-1.5) == -1;
+math.round( -1.50001) == -2;
+math.fround(math.POSITIVE_INFINITY) == math.POSITIVE_INFINITY;
+math.fround(math.NEGATIVE_INFINITY) == math.NEGATIVE_INFINITY;
+math.isNaN(math.fround(math.NaN)) == true;
+
+// floor
+math.floor(0.0) == 0;
+math.floor(0.9999) == 0;
+math.floor(1.0) == 1;
+math.floor( -0.0001) == -1;
+math.floor( -1.0) == -1;
+math.floor( -1.0001) == -2;
+math.ffloor(math.POSITIVE_INFINITY) == math.POSITIVE_INFINITY;
+math.ffloor(math.NEGATIVE_INFINITY) == math.NEGATIVE_INFINITY;
+math.isNaN(math.ffloor(math.NaN)) == true;
+
+// ceil
+math.ceil(0.0) == 0;
+math.ceil(-0.9999) == 0;
+math.ceil(-1.0) == -1;
+math.ceil( 0.0001) == 1;
+math.ceil( 1.0) == 1;
+math.ceil( 1.0001) == 2;
+math.fceil(math.POSITIVE_INFINITY) == math.POSITIVE_INFINITY;
+math.fceil(math.NEGATIVE_INFINITY) == math.NEGATIVE_INFINITY;
+math.isNaN(math.fceil(math.NaN)) == true;
+
+// random
+// not much to test here...
+
+// isFinite
+math.isFinite(math.POSITIVE_INFINITY) == false;
+math.isFinite(math.NEGATIVE_INFINITY) == false;
+math.isFinite(math.NaN) == false;
+math.isFinite(0.0) == true;
+
+// isNaN
+math.isNaN(math.POSITIVE_INFINITY) == false;
+math.isNaN(math.NEGATIVE_INFINITY) == false;
+math.isNaN(math.NaN) == true;
+math.isNaN(0.0) == false;
+
+
+