Browse Source

added Context.registerModuleReuseCall

Nicolas Cannasse 13 years ago
parent
commit
cb0f7a058a
6 changed files with 25 additions and 4 deletions
  1. 9 2
      interp.ml
  2. 1 0
      main.ml
  3. 7 0
      std/haxe/macro/Context.hx
  4. 1 0
      std/sys/db/SpodMacros.hx
  5. 2 0
      type.ml
  6. 5 2
      typer.ml

+ 9 - 2
interp.ml

@@ -100,7 +100,7 @@ type extern_api = {
 	get_local_type : unit -> t option;
 	get_build_fields : unit -> value;
 	define_type : value -> unit;
-	module_dependency : string -> string -> unit;
+	module_dependency : string -> string -> bool -> unit;
 	current_module : unit -> module_def;
 }
 
@@ -1972,7 +1972,14 @@ let macro_lib =
 		"module_dependency", Fun2 (fun m file ->
 			match m, file with
 			| VString m, VString file ->
-				(get_ctx()).curapi.module_dependency m file;
+				(get_ctx()).curapi.module_dependency m file false;
+				VNull
+			| _ -> error()
+		);
+		"module_reuse_call", Fun2 (fun m mcall ->
+			match m, mcall with
+			| VString m, VString mcall ->
+				(get_ctx()).curapi.module_dependency m mcall true;
 				VNull
 			| _ -> error()
 		);

+ 1 - 0
main.ml

@@ -478,6 +478,7 @@ and wait_loop boot_com host port =
 					Typeload.add_module ctx m p;
 					PMap.iter (Hashtbl.add com2.resources) m.m_extra.m_binded_res;
 					PMap.iter (fun _ m2 -> add_modules m0 m2) m.m_extra.m_deps);
+					List.iter (Typer.call_init_macro ctx) m.m_extra.m_macro_calls
 			end
 		in
 		try

+ 7 - 0
std/haxe/macro/Context.hx

@@ -214,6 +214,13 @@ class Context {
 		load("module_dependency", 2)(untyped modulePath.__s,untyped externFile.__s);
 	}
 
+	/**
+		Add a macro call to perform in case the module is reused by the compilation cache.
+	**/
+	public static function registerModuleReuseCall( modulePath : String, macroCall : String ) {
+		load("module_reuse_call", 2)(untyped modulePath.__s,untyped macroCall.__s);
+	}
+
 	static function load( f, nargs ) : Dynamic {
 		#if macro
 		return neko.Lib.load("macro", f, nargs);

+ 1 - 0
std/sys/db/SpodMacros.hx

@@ -970,6 +970,7 @@ class SpodMacros {
 				default:
 				}
 		});
+		Context.registerModuleReuseCall("sys.db.Manager", "sys.db.SpodMacros.addRtti()");
 		return null;
 	}
 

+ 2 - 0
type.ml

@@ -242,6 +242,7 @@ and module_def_extra = {
 	mutable m_processed : int;
 	mutable m_kind : module_kind;
 	mutable m_binded_res : (string, string) PMap.t;
+	mutable m_macro_calls : string list;
 }
 
 and module_kind =
@@ -312,6 +313,7 @@ let module_extra file sign time kind =
 		m_deps = PMap.empty;
 		m_kind = kind;
 		m_binded_res = PMap.empty;
+		m_macro_calls = [];
 	}
 
 let null_module = {

+ 5 - 2
typer.ml

@@ -2403,9 +2403,12 @@ let make_macro_api ctx p =
 			mdep.m_extra.m_kind <- MFake;
 			add_dependency ctx.current mdep;
 		);
-		Interp.module_dependency = (fun mpath file ->
+		Interp.module_dependency = (fun mpath file ismacro ->
 			let m = typing_timer ctx (fun() -> Typeload.load_module ctx (parse_path mpath) p) in
-			add_dependency m (create_fake_module ctx file);
+			if ismacro then
+				m.m_extra.m_macro_calls <- file :: List.filter ((<>) file) m.m_extra.m_macro_calls
+			else
+				add_dependency m (create_fake_module ctx file);
 		);
 		Interp.current_module = (fun() ->
 			ctx.current