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

allow cache of macros modules

Nicolas Cannasse 13 жил өмнө
parent
commit
6a66c87df3
3 өөрчлөгдсөн 18 нэмэгдсэн , 8 устгасан
  1. 2 0
      common.ml
  2. 15 8
      main.ml
  3. 1 0
      typer.ml

+ 2 - 0
common.ml

@@ -64,6 +64,7 @@ type context = {
 	mutable filters : (unit -> unit) list;
 	mutable filters : (unit -> unit) list;
 	mutable defines_signature : string option;
 	mutable defines_signature : string option;
 	mutable print : string -> unit;
 	mutable print : string -> unit;
+	mutable get_macros : unit -> context option;
 	(* output *)
 	(* output *)
 	mutable file : string;
 	mutable file : string;
 	mutable flash_version : float;
 	mutable flash_version : float;
@@ -117,6 +118,7 @@ let create v =
 		js_gen = None;
 		js_gen = None;
 		load_extern_type = [];
 		load_extern_type = [];
 		defines_signature = None;
 		defines_signature = None;
+		get_macros = (fun() -> None);
 		warning = (fun _ _ -> assert false);
 		warning = (fun _ _ -> assert false);
 		error = (fun _ _ -> assert false);
 		error = (fun _ _ -> assert false);
 		basic = {
 		basic = {

+ 15 - 8
main.ml

@@ -412,11 +412,12 @@ and wait_loop boot_com host port =
 	Typeload.type_module_hook := (fun (ctx:Typecore.typer) mpath p ->
 	Typeload.type_module_hook := (fun (ctx:Typecore.typer) mpath p ->
 		let com2 = ctx.Typecore.com in
 		let com2 = ctx.Typecore.com in
 		let sign = get_signature com2 in
 		let sign = get_signature com2 in
+		let added = (try Hashtbl.find modules_added sign with Not_found -> let added = Hashtbl.create 0 in Hashtbl.add modules_added sign added; added) in
 		let modules_checked = Hashtbl.create 0 in
 		let modules_checked = Hashtbl.create 0 in
 		let dep = ref None in
 		let dep = ref None in
 		let rec check m =
 		let rec check m =
 			try
 			try
-				Hashtbl.find modules_added m.Type.m_path
+				Hashtbl.find added m.Type.m_path
 			with Not_found -> try
 			with Not_found -> try
 				!(Hashtbl.find modules_checked m.Type.m_path)
 				!(Hashtbl.find modules_checked m.Type.m_path)
 			with Not_found ->
 			with Not_found ->
@@ -429,15 +430,15 @@ and wait_loop boot_com host port =
 				PMap.iter (fun m2 _ -> if not (check m2) then begin dep := Some m2; raise Not_found end) !(m.Type.m_deps);
 				PMap.iter (fun m2 _ -> if not (check m2) then begin dep := Some m2; raise Not_found end) !(m.Type.m_deps);
 				true
 				true
 			with Not_found ->
 			with Not_found ->
-				Hashtbl.add modules_added m.Type.m_path false;
+				Hashtbl.add added m.Type.m_path false;
 				ok := false;
 				ok := false;
 				!ok
 				!ok
 		in
 		in
 		let rec add_modules m =
 		let rec add_modules m =
-			if Hashtbl.mem modules_added m.Type.m_path then
+			if Hashtbl.mem added m.Type.m_path then
 				()
 				()
 			else begin
 			else begin
-				Hashtbl.add modules_added m.Type.m_path true;
+				Hashtbl.add added m.Type.m_path true;
 				if verbose then print_endline ("Reusing  cached module " ^ Ast.s_type_path m.Type.m_path);
 				if verbose then print_endline ("Reusing  cached module " ^ Ast.s_type_path m.Type.m_path);
 				Typeload.add_module ctx m p;
 				Typeload.add_module ctx m p;
 				PMap.iter (fun m2 _ -> add_modules m2) !(m.Type.m_deps);
 				PMap.iter (fun m2 _ -> add_modules m2) !(m.Type.m_deps);
@@ -472,12 +473,18 @@ and wait_loop boot_com host port =
 				ignore(Unix.select [] [] [] 0.1);
 				ignore(Unix.select [] [] [] 0.1);
 				read_loop()
 				read_loop()
 		in
 		in
+		let rec cache_context com =
+			if not com.dead_code_elimination then begin
+				List.iter (cache_module (get_signature com)) com.modules;
+				if verbose then print_endline ("Cached " ^ string_of_int (List.length com.modules) ^ " modules");				
+			end;
+			match com.get_macros() with
+			| None -> ()
+			| Some com -> cache_context com
+		in
 		let flush ctx =
 		let flush ctx =
 			Hashtbl.clear modules_added;
 			Hashtbl.clear modules_added;
-			if not ctx.com.dead_code_elimination then begin
-				List.iter (cache_module (get_signature ctx.com)) ctx.com.modules;
-				if verbose then print_endline ("Cached " ^ string_of_int (List.length ctx.com.modules) ^ " modules");
-			end;
+			cache_context ctx.com;
 			List.iter (fun s -> ssend sin (s ^ "\n"); if verbose then print_endline ("> " ^ s)) (List.rev ctx.messages);
 			List.iter (fun s -> ssend sin (s ^ "\n"); if verbose then print_endline ("> " ^ s)) (List.rev ctx.messages);
 		in
 		in
 		(try
 		(try

+ 1 - 0
typer.ml

@@ -2389,6 +2389,7 @@ let load_macro ctx cpath f p =
 			ctx
 			ctx
 		| None ->
 		| None ->
 			let com2 = Common.clone ctx.com in
 			let com2 = Common.clone ctx.com in
+			ctx.com.get_macros <- (fun() -> Some com2);
 			com2.package_rules <- PMap.empty;
 			com2.package_rules <- PMap.empty;
 			com2.main_class <- None;
 			com2.main_class <- None;
 			com2.display <- false;
 			com2.display <- false;