Просмотр исходного кода

fixed F9 Math, Array and Date methods

Nicolas Cannasse 18 лет назад
Родитель
Сommit
1a6cfa5c80
4 измененных файлов с 28 добавлено и 9 удалено
  1. 1 0
      doc/CHANGES.txt
  2. 21 2
      genswf9.ml
  3. 5 6
      type.ml
  4. 1 1
      typer.ml

+ 1 - 0
doc/CHANGES.txt

@@ -11,6 +11,7 @@
 	optional enums arguments on Flash9 are now automatically Null
 	forbid usage of type parameters in static functions
 	fixed Std.int with negative numbers
+	fixed some F9 issues with haXe-specific Array, Date and Math methods
 
 2007-07-25: 1.14
 	fixed no error when invalid "catch" expression

+ 21 - 2
genswf9.ml

@@ -1027,10 +1027,29 @@ and gen_call ctx e el =
 		write ctx (A3FindPropStrict id);
 		List.iter (gen_expr ctx true) el;
 		write ctx (A3CallProperty (id,List.length el));
-	| TField (e,f) , _ ->
-		gen_expr ctx true e;
+	| TField (e1,f) , _ ->
+		gen_expr ctx true e1;
 		List.iter (gen_expr ctx true) el;
 		write ctx (A3CallProperty (ident ctx f,List.length el));
+		let coerce() =
+			match follow e.etype with
+			| TFun (_,r) -> coerce ctx (classify ctx r)
+			| _ -> ()
+		in
+		(match follow e1.etype with
+		| TInst ({ cl_path = [],"Array" },_) -> 
+			(match f with
+			| "copy" | "remove" -> coerce()
+			| _ -> ())
+		| TAnon a when (match !(a.a_status) with Statics { cl_path = ([],"Date") } -> true | _ -> false) ->
+			(match f with
+			| "now" | "fromString" | "fromTime"  -> coerce()
+			| _ -> ())
+		| TAnon a when (match !(a.a_status) with Statics { cl_path = ([],"Math") } -> true | _ -> false) ->
+			(match f with
+			| "isFinite" | "isNaN" -> coerce()
+			| _ -> ())
+		| _ -> ())
 	| TEnumField (e,f) , _ ->
 		let id = type_path ctx ~getclass:true e.e_path in
 		write ctx (A3GetLex id);

+ 5 - 6
type.ml

@@ -27,11 +27,6 @@ type field_access =
 	| MethodAccess of string
 	| F9MethodAccess
 
-type anon_status =
-	| Closed
-	| Opened
-	| Statics
-
 type t =
 	| TMono of t option ref
 	| TEnum of tenum * tparams
@@ -59,6 +54,11 @@ and tfunc = {
 	tf_expr : texpr;
 }
 
+and anon_status =
+	| Closed
+	| Opened
+	| Statics of tclass
+
 and tanon = {
 	mutable a_fields : (string, tclass_field) PMap.t;
 	a_status : anon_status ref;
@@ -172,7 +172,6 @@ let mk e t p = { eexpr = e; etype = t; epos = p }
 
 let not_opened = ref Closed
 let const_status = ref Closed
-let static_status = ref Statics
 let is_closed a = !(a.a_status) <> Opened
 let mk_anon fl = TAnon { a_fields = fl; a_status = not_opened; }
 

+ 1 - 1
typer.ml

@@ -906,7 +906,7 @@ let type_type ctx tpath p =
 			t_path = fst c.cl_path, "#" ^ snd c.cl_path;
 			t_doc = None;
 			t_pos = c.cl_pos;
-			t_type = if pub then mk_anon (PMap.map (fun f -> { f with cf_public = true }) c.cl_statics) else TAnon { a_fields = c.cl_statics; a_status = static_status };
+			t_type = if pub then mk_anon (PMap.map (fun f -> { f with cf_public = true }) c.cl_statics) else TAnon { a_fields = c.cl_statics; a_status = ref (Statics c) };
 			t_private = true;
 			t_static = Some c;
 			t_types = [];