|
@@ -2392,6 +2392,7 @@ let make_macro_api ctx p =
|
|
m_deps = PMap.empty;
|
|
m_deps = PMap.empty;
|
|
m_processed = 0;
|
|
m_processed = 0;
|
|
m_kind = MFake;
|
|
m_kind = MFake;
|
|
|
|
+ m_binded_res = PMap.empty;
|
|
};
|
|
};
|
|
} in
|
|
} in
|
|
Hashtbl.add fake_modules file mdep;
|
|
Hashtbl.add fake_modules file mdep;
|
|
@@ -2400,8 +2401,52 @@ let make_macro_api ctx p =
|
|
add_dependency m mdep;
|
|
add_dependency m mdep;
|
|
Hashtbl.replace ctx.g.modules mdep.m_path mdep
|
|
Hashtbl.replace ctx.g.modules mdep.m_path mdep
|
|
);
|
|
);
|
|
|
|
+ Interp.current_module = (fun() ->
|
|
|
|
+ ctx.current
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+let get_macro_context ctx p =
|
|
|
|
+ let api = make_macro_api ctx p in
|
|
|
|
+ match ctx.g.macros with
|
|
|
|
+ | Some (select,ctx) ->
|
|
|
|
+ select();
|
|
|
|
+ api, ctx
|
|
|
|
+ | None ->
|
|
|
|
+ let com2 = Common.clone ctx.com in
|
|
|
|
+ ctx.com.get_macros <- (fun() -> Some com2);
|
|
|
|
+ com2.package_rules <- PMap.empty;
|
|
|
|
+ com2.main_class <- None;
|
|
|
|
+ com2.display <- false;
|
|
|
|
+ com2.dead_code_elimination <- false;
|
|
|
|
+ List.iter (fun p -> com2.defines <- PMap.remove (platform_name p) com2.defines) platforms;
|
|
|
|
+ com2.defines_signature <- None;
|
|
|
|
+ com2.class_path <- List.filter (fun s -> not (ExtString.String.exists s "/_std/")) com2.class_path;
|
|
|
|
+ com2.class_path <- List.map (fun p -> p ^ "neko" ^ "/_std/") com2.std_path @ com2.class_path;
|
|
|
|
+ com2.defines <- PMap.foldi (fun k _ acc ->
|
|
|
|
+ match k with
|
|
|
|
+ | "no_traces" -> acc
|
|
|
|
+ | _ when List.exists (fun (_,d) -> "flash" ^ d = k) Common.flash_versions -> acc
|
|
|
|
+ | _ -> PMap.add k () acc
|
|
|
|
+ ) com2.defines PMap.empty;
|
|
|
|
+ Common.define com2 "macro";
|
|
|
|
+ Common.init_platform com2 Neko;
|
|
|
|
+ let ctx2 = ctx.g.do_create com2 in
|
|
|
|
+ let mctx = Interp.create com2 api in
|
|
|
|
+ let on_error = com2.error in
|
|
|
|
+ com2.error <- (fun e p -> Interp.set_error mctx true; on_error e p);
|
|
|
|
+ let macro = ((fun() -> Interp.select mctx), ctx2) in
|
|
|
|
+ ctx.g.macros <- Some macro;
|
|
|
|
+ ctx2.g.macros <- Some macro;
|
|
|
|
+ (* ctx2.g.core_api <- ctx.g.core_api; // causes some issues because of optional args and Null type in Flash9 *)
|
|
|
|
+ ignore(Typeload.load_module ctx2 (["haxe";"macro"],"Expr") p);
|
|
|
|
+ ignore(Typeload.load_module ctx2 (["haxe";"macro"],"Type") p);
|
|
|
|
+ finalize ctx2;
|
|
|
|
+ let _, types, _ = generate ctx2 in
|
|
|
|
+ Interp.add_types mctx types;
|
|
|
|
+ Interp.init mctx;
|
|
|
|
+ api, ctx2
|
|
|
|
+
|
|
let load_macro ctx cpath f p =
|
|
let load_macro ctx cpath f p =
|
|
(*
|
|
(*
|
|
The time measured here takes into account both macro typing an init, but benchmarks
|
|
The time measured here takes into account both macro typing an init, but benchmarks
|
|
@@ -2409,46 +2454,7 @@ let load_macro ctx cpath f p =
|
|
typing the classes needed for macro execution.
|
|
typing the classes needed for macro execution.
|
|
*)
|
|
*)
|
|
let t = macro_timer ctx "typing (+init)" in
|
|
let t = macro_timer ctx "typing (+init)" in
|
|
- let api = make_macro_api ctx p in
|
|
|
|
- let ctx2 = (match ctx.g.macros with
|
|
|
|
- | Some (select,ctx) ->
|
|
|
|
- select();
|
|
|
|
- ctx
|
|
|
|
- | None ->
|
|
|
|
- let com2 = Common.clone ctx.com in
|
|
|
|
- ctx.com.get_macros <- (fun() -> Some com2);
|
|
|
|
- com2.package_rules <- PMap.empty;
|
|
|
|
- com2.main_class <- None;
|
|
|
|
- com2.display <- false;
|
|
|
|
- com2.dead_code_elimination <- false;
|
|
|
|
- List.iter (fun p -> com2.defines <- PMap.remove (platform_name p) com2.defines) platforms;
|
|
|
|
- com2.defines_signature <- None;
|
|
|
|
- com2.class_path <- List.filter (fun s -> not (ExtString.String.exists s "/_std/")) com2.class_path;
|
|
|
|
- com2.class_path <- List.map (fun p -> p ^ "neko" ^ "/_std/") com2.std_path @ com2.class_path;
|
|
|
|
- com2.defines <- PMap.foldi (fun k _ acc ->
|
|
|
|
- match k with
|
|
|
|
- | "no_traces" -> acc
|
|
|
|
- | _ when List.exists (fun (_,d) -> "flash" ^ d = k) Common.flash_versions -> acc
|
|
|
|
- | _ -> PMap.add k () acc
|
|
|
|
- ) com2.defines PMap.empty;
|
|
|
|
- Common.define com2 "macro";
|
|
|
|
- Common.init_platform com2 Neko;
|
|
|
|
- let ctx2 = ctx.g.do_create com2 in
|
|
|
|
- let mctx = Interp.create com2 api in
|
|
|
|
- let on_error = com2.error in
|
|
|
|
- com2.error <- (fun e p -> Interp.set_error mctx true; on_error e p);
|
|
|
|
- let macro = ((fun() -> Interp.select mctx), ctx2) in
|
|
|
|
- ctx.g.macros <- Some macro;
|
|
|
|
- ctx2.g.macros <- Some macro;
|
|
|
|
- (* ctx2.g.core_api <- ctx.g.core_api; // causes some issues because of optional args and Null type in Flash9 *)
|
|
|
|
- ignore(Typeload.load_module ctx2 (["haxe";"macro"],"Expr") p);
|
|
|
|
- ignore(Typeload.load_module ctx2 (["haxe";"macro"],"Type") p);
|
|
|
|
- finalize ctx2;
|
|
|
|
- let _, types, _ = generate ctx2 in
|
|
|
|
- Interp.add_types mctx types;
|
|
|
|
- Interp.init mctx;
|
|
|
|
- ctx2
|
|
|
|
- ) in
|
|
|
|
|
|
+ let api, ctx2 = get_macro_context ctx p in
|
|
let mctx = Interp.get_ctx() in
|
|
let mctx = Interp.get_ctx() in
|
|
let m = (try Hashtbl.find ctx.g.types_module cpath with Not_found -> cpath) in
|
|
let m = (try Hashtbl.find ctx.g.types_module cpath with Not_found -> cpath) in
|
|
let mloaded = Typeload.load_module ctx2 m p in
|
|
let mloaded = Typeload.load_module ctx2 m p in
|