2
0
Эх сурвалжийг харах

plaform configuration (only sys/static right now)
+ added "static" define for static platforms

Nicolas Cannasse 13 жил өмнө
parent
commit
e99f465174
4 өөрчлөгдсөн 73 нэмэгдсэн , 11 устгасан
  1. 69 8
      common.ml
  2. 1 0
      main.ml
  3. 2 2
      optimizer.ml
  4. 1 1
      typer.ml

+ 69 - 8
common.ml

@@ -53,6 +53,13 @@ type stats = {
 	s_macros_called : int ref;
 }
 
+type platform_config = {
+	(** has a static type system, with not-nullable basic types (Int/Float/Bool) *)
+	pf_static : bool;
+	(** has access to the "sys" package *)
+	pf_sys : bool;
+}
+
 type context = {
 	(* config *)
 	version : int;
@@ -63,6 +70,7 @@ type context = {
 	mutable foptimize : bool;
 	mutable dead_code_elimination : bool;
 	mutable platform : platform;
+	mutable config : platform_config;
 	mutable std_path : string list;
 	mutable class_path : string list;
 	mutable main_class : Type.path option;
@@ -105,6 +113,63 @@ let stats =
 		s_macros_called = ref 0;
 	}
 
+let default_config = 
+	{
+		pf_static = true;
+		pf_sys = true;
+	}
+
+let get_config com =
+	let defined f = PMap.mem f com.defines in
+	match com.platform with
+	| Cross ->
+		default_config
+	| Flash8 ->
+		{
+			pf_static = false;
+			pf_sys = false;
+		}
+	| Js ->
+		{
+			pf_static = false;
+			pf_sys = false;
+		}
+	| Neko ->
+		{
+			pf_static = false;
+			pf_sys = true;
+		}
+	| Flash when defined "as3" ->
+		{
+			pf_static = true;
+			pf_sys = false;
+		}
+	| Flash ->
+		{
+			pf_static = true;
+			pf_sys = false;
+		}
+	| Php ->
+		{
+			pf_static = false;
+			pf_sys = true;
+		}
+	| Cpp ->
+		{
+			pf_static = true;
+			pf_sys = true;
+		}
+	| Cs ->
+		{
+			pf_static = true;
+			pf_sys = true;
+		}
+	| Java ->
+		{
+			pf_static = true;
+			pf_sys = true;
+		}
+
 let create v args =
 	let m = Type.mk_mono() in
 	{
@@ -117,6 +182,7 @@ let create v args =
 		features = Hashtbl.create 0;
 		dead_code_elimination = false;
 		platform = Cross;
+		config = default_config;
 		print = print_string;
 		std_path = [];
 		class_path = [];
@@ -222,9 +288,9 @@ let init_platform com pf =
 	let name = platform_name pf in
 	let forbid acc p = if p = name || PMap.mem p acc then acc else PMap.add p Forbidden acc in
 	com.package_rules <- List.fold_left forbid com.package_rules (List.map platform_name platforms);
-	(match pf with
-	| Cpp | Php | Neko | Java | Cs -> define com "sys"
-	| _ -> com.package_rules <- PMap.add "sys" Forbidden com.package_rules);
+	com.config <- get_config com;
+	if com.config.pf_static then define com "static";
+	if com.config.pf_sys then define com "sys" else com.package_rules <- PMap.add "sys" Forbidden com.package_rules;
 	define com name
 
 let add_feature com f =
@@ -256,11 +322,6 @@ let error msg p = raise (Abort (msg,p))
 
 let platform ctx p = ctx.platform = p
 
-let is_static_platform ctx =
-	match ctx.platform with
-	| Cpp | Flash | Cs | Java -> true
-	| _ -> false
-
 let add_filter ctx f =
 	ctx.filters <- f :: ctx.filters
 

+ 1 - 0
main.ml

@@ -996,6 +996,7 @@ try
 	) in
 	(* if we are at the last compilation step, allow all packages accesses - in case of macros or opening another project file *)
 	if com.display && not ctx.has_next then com.package_rules <- PMap.foldi (fun p r acc -> match r with Forbidden -> acc | _ -> PMap.add p r acc) com.package_rules PMap.empty;
+	com.config <- get_config com; (* make sure to adapt all flags changes defined after platform *)
 
 	(* check file extension. In case of wrong commandline, we don't want
 		to accidentaly delete a source file. *)

+ 2 - 2
optimizer.ml

@@ -139,7 +139,7 @@ let rec type_inline ctx cf f ethis params tret p force =
 				if we pass a Null<T> var to an inlined method that needs a T.
 				we need to force a local var to be created on some platforms.
 			*)
-			if is_static_platform ctx.com && not (is_nullable v.v_type) && is_null e.etype then (local v).i_write <- true;
+			if ctx.com.config.pf_static && not (is_nullable v.v_type) && is_null e.etype then (local v).i_write <- true;
 			(match e.eexpr, opt with
 			| TConst TNull , Some c -> mk (TConst c) v.v_type e.epos
 			| _ -> e) :: loop pl al
@@ -576,7 +576,7 @@ let sanitize_expr com e =
 	in
 	match e.eexpr with
 	| TConst TNull ->
-		if is_static_platform com && not (is_nullable e.etype) then
+		if com.config.pf_static && not (is_nullable e.etype) then
 			(match follow e.etype with
 			| TMono _ -> () (* in these cases the null will cast to default value *)
 			| TFun _ -> () (* this is a bit a particular case, maybe flash-specific actually *)

+ 1 - 1
typer.ml

@@ -3056,7 +3056,7 @@ let rec create com =
 						);
 						TLazy r
 				in
-				ctx.t.tnull <- if not (is_static_platform com) then (fun t -> t) else mk_null;
+				ctx.t.tnull <- if not com.config.pf_static then (fun t -> t) else mk_null;
 			| _ -> ());
 	) ctx.g.std.m_types;
 	let m = Typeload.load_module ctx ([],"String") null_pos in