Skip to content

Commit

Permalink
[typer] rework after init macro
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Oct 3, 2023
1 parent 2022807 commit 87a6c29
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@ let do_type ctx mctx actx display_file_dot_path =
com.stage <- CInitMacrosDone;
ServerMessage.compiler_stage com;
MacroContext.macro_enable_cache := macro_cache_enabled;

let macros = match mctx with None -> None | Some mctx -> mctx.g.macros in
let tctx = Setup.create_typer_context ctx macros actx.native_libs in
let display_file_dot_path = DisplayProcessing.maybe_load_display_file_before_typing tctx display_file_dot_path in
check_defines ctx.com;
CommonCache.lock_signature com "after_init_macros";
Option.may (fun mctx -> MacroContext.finalize_macro_api tctx mctx) mctx;

(try begin
com.callbacks#run com.callbacks#get_after_init_macros;
Expand Down
7 changes: 3 additions & 4 deletions src/macro/macroApi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type compiler_options = {
**)

type 'value compiler_api = {
is_full : bool;
pos : Globals.pos;
get_com : unit -> Common.context;
get_macro_stack : unit -> pos list;
Expand Down Expand Up @@ -1894,10 +1893,10 @@ let macro_api ccom get_api =
encode_array (List.map encode_type ((get_api()).get_module (decode_string s)))
);
"on_after_init_macros", vfun1 (fun f ->
if (get_api()).is_full then begin
(get_api()).after_init_macros (fun tctx ->
let f = prepare_callback f 1 in
(get_api()).after_init_macros (fun tctx -> ignore(f []));
end;
ignore(f [])
);
vnull
);
"on_after_typing", vfun1 (fun f ->
Expand Down
13 changes: 8 additions & 5 deletions src/typing/macroContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ let make_macro_com_api com p =
in
{
MacroApi.pos = p;
MacroApi.is_full = false;
get_com = (fun () -> com);
get_macro_stack = (fun () ->
let envs = Interp.call_stack (Interp.get_eval (Interp.get_ctx ())) in
Expand Down Expand Up @@ -317,7 +316,6 @@ and promote_com_api com_api ctx p =
in
{
com_api with
MacroApi.is_full = true;
MacroApi.get_type = (fun s ->
typing_timer ctx false (fun() ->
let path = parse_path s in
Expand Down Expand Up @@ -705,7 +703,7 @@ let create_macro_interp api mctx =
init();
let init = (fun() -> Interp.select mint) in
mctx.g.macros <- Some (init,mctx);
init
(init, mint)

let create_macro_context com =
let com2 = Common.clone com true in
Expand Down Expand Up @@ -735,7 +733,7 @@ let get_macro_context ctx =
| None ->
let mctx = create_macro_context ctx.com in
let api = make_macro_api mctx null_pos in
let init = create_macro_interp api mctx in
let init,_ = create_macro_interp api mctx in
ctx.g.macros <- Some (init,mctx);
mctx.g.macros <- Some (init,mctx);
mctx
Expand Down Expand Up @@ -1048,14 +1046,19 @@ let call_init_macro com mctx e =
let api = make_macro_com_api com p in
(match !macro_interp_cache with
| None ->
let init = create_macro_interp api mctx in
let init,_ = create_macro_interp api mctx in
init();
| _ -> ());

let mctx, (margs,_,mclass,mfield), call = load_macro mctx com mctx api false path meth p in
ignore(call_macro mctx args margs call p);
mctx

let finalize_macro_api tctx mctx =
let api = make_macro_api tctx null_pos in
let mint = (match !macro_interp_cache with None -> snd (create_macro_interp api mctx) | Some mint -> mint) in
Interp.do_reuse mint api;

module MacroLight = struct
let load_macro_light com mctx api display cpath f p =
let api = {api with MacroApi.pos = p} in
Expand Down

0 comments on commit 87a6c29

Please sign in to comment.