Skip to content

Commit

Permalink
[hxb] cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Jun 29, 2023
1 parent 3a8dbf4 commit f530b4c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 48 deletions.
5 changes: 0 additions & 5 deletions src-json/define.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@
"platforms": ["hl"],
"params": ["version"]
},
{
"name": "HxbOnly",
"define": "hxb.only",
"doc": "Only load types from hxb files (and cache)"
},
{
"name": "HxcppApiLevel",
"define": "hxcpp-api-level",
Expand Down
21 changes: 6 additions & 15 deletions src/compiler/args.ml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ let parse_args com =
("Target",["--run"],[], Arg.Unit (fun() ->
raise (Arg.Bad "--run requires an argument: a Haxe module name")
), "<module> [args...]","interpret a Haxe module with command line arguments");
("Target",["--hxb"],[], Arg.String (fun file ->
actx.hxb_out <- Some file;
),"<file>", "generate haxe binary as target file");
("Compilation",["-p";"--class-path"],["-cp"],Arg.String (fun path ->
com.class_path <- Path.add_trailing_slash path :: com.class_path
),"<path>","add a directory to find source files");
Expand All @@ -132,18 +129,9 @@ let parse_args com =
),"<path>","add a directory to find binary source files");
("Compilation",["-m";"--main"],["-main"],Arg.String (fun cl ->
if com.main_class <> None then raise (Arg.Bad "Multiple --main classes specified");
begin match Path.file_extension cl with
| "hxb" ->
actx.pre_compilation <- (fun () ->
(* TODO: update hxb runner *)
(* HxbRunner.run com cl; *)
actx.did_something <- true
) :: actx.pre_compilation;
| _ ->
let cpath = Path.parse_type_path cl in
com.main_class <- Some cpath;
actx.classes <- cpath :: actx.classes
end
let cpath = Path.parse_type_path cl in
com.main_class <- Some cpath;
actx.classes <- cpath :: actx.classes
),"<class>","select startup class");
("Compilation",["-L";"--library"],["-lib"],Arg.String (fun _ -> ()),"<name[:ver]>","use a haxelib library");
("Compilation",["-D";"--define"],[],Arg.String (fun var ->
Expand Down Expand Up @@ -277,6 +265,9 @@ let parse_args com =
("Services",["--json"],[],Arg.String (fun file ->
actx.json_out <- Some file
),"<file>","generate JSON types description");
("Services",["--hxb"],[], Arg.String (fun dir ->
actx.hxb_out <- Some dir;
),"<directory>", "generate haxe binary representation in target directory");
("Optimization",["--no-output"],[], Arg.Unit (fun() -> actx.no_output <- true),"","compiles but does not generate any file");
("Debug",["--times"],[], Arg.Unit (fun() -> Timer.measure_times := true),"","measure compilation times");
("Optimization",["--no-inline"],[],Arg.Unit (fun () ->
Expand Down
1 change: 0 additions & 1 deletion src/compiler/displayOutput.ml
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ let handle_type_path_exception ctx p c is_import pos =
| None ->
DisplayPath.TypePathHandler.complete_type_path com p
| Some (c,cur_package) ->
Printf.eprintf "=== [Display] create typer context ===\n";
let ctx = Typer.create com in
DisplayPath.TypePathHandler.complete_type_path_inner ctx p c cur_package is_import
end with Common.Abort msg ->
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/tasks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ class server_exploration_task (cs : CompilationCache.t) = object(self)

method private execute =
cs#iter_modules (fun m -> cs#add_task (new module_maintenance_task cs m))
end
end
1 change: 0 additions & 1 deletion src/typing/typeloadFields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,6 @@ let init_class ctx c p context_init herits fields =
if cctx.is_class_debug then print_endline ("Created class context: " ^ dump_class_context cctx);
let fields = patch_class ctx c fields in
let fields = build_fields (ctx,cctx) c fields in
(* Triggers a second loading of many types.. *)
if cctx.is_core_api && ctx.com.display.dms_check_core_api then delay ctx PForce (fun() -> init_core_api ctx c);
if not cctx.is_lib then begin
delay ctx PForce (fun() -> check_overloads ctx c);
Expand Down
39 changes: 15 additions & 24 deletions src/typing/typeloadModule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -791,29 +791,23 @@ let type_module ctx mpath file ?(dont_check_path=false) ?(is_extern=false) tdecl

let type_module_hook = ref (fun _ _ _ -> None)

let indent = ref (-1)

let rec get_reader ctx input mpath p =
let make_module path file =
(* Printf.eprintf " \x1b[35m[typeloadModule]\x1b[0m make module %s\n" (s_type_path path); *)
let m = ModuleLevel.make_module ctx path file p in
m.m_extra.m_processed <- 1;
m
in
let make_module path file =
let m = ModuleLevel.make_module ctx path file p in
m.m_extra.m_processed <- 1;
m
in

let add_module m =
(* Printf.eprintf " \x1b[35m[typeloadModule]\x1b[0m add module %s = %s\n" (s_type_path m.m_path) (s_type_path mpath); *)
ctx.com.module_lut#add m.m_path m in
let add_module m =
ctx.com.module_lut#add m.m_path m
in

let resolve_type pack mname tname =
(* Printf.eprintf " \x1b[35m[typeloadModule]\x1b[0m resolve type %s\n" (s_type_path ((pack @ [mname]),tname)); *)
let m = try ctx.com.module_lut#find (pack,mname) with Not_found -> load_module' ctx ctx.g (pack,mname) p in
let t = List.find (fun t -> snd (t_path t) = tname) m.m_types in
(* Printf.eprintf " \x1b[35m[typeloadModule]\x1b[0m resolved type %s\n" (s_type_path ((pack @ [mname]),tname)); *)
t
in
let resolve_type pack mname tname =
let m = try ctx.com.module_lut#find (pack,mname) with Not_found -> load_module' ctx ctx.g (pack,mname) p in
List.find (fun t -> snd (t_path t) = tname) m.m_types
in

new HxbReader.hxb_reader ctx.com input make_module add_module resolve_type
new HxbReader.hxb_reader ctx.com input make_module add_module resolve_type

and load_hxb_module ctx path p =
let compose_path no_rename =
Expand Down Expand Up @@ -842,18 +836,15 @@ and load_hxb_module ctx path p =
raise e

and load_module' ctx g m p =
(* Printf.eprintf "\x1b[45m[typeloadModule]\x1b[0m Load module %s\n" (s_type_path m); *)
try
(* Check current context *)
let m = ctx.com.module_lut#find m in
(* Printf.eprintf "\x1b[44m-- Retrieved %s from cache\x1b[0m\n" (snd m.m_path); *)
m
ctx.com.module_lut#find m
with Not_found ->
(* Check cache *)
match !type_module_hook ctx m p with
| Some m ->
m
(* Try loading from hxb first *)
(* Try loading from hxb first, then from source *)
| None -> try load_hxb_module ctx m p with Not_found ->
let raise_not_found () = raise_error_msg (Module_not_found m) p in
if ctx.com.module_nonexistent_lut#mem m then raise_not_found();
Expand Down
1 change: 0 additions & 1 deletion src/typing/typeloadParse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ let parse_module' com m p =
file,remap,pack,decls

let parse_module ctx m p =
if Common.defined ctx.com Define.HxbOnly then raise Not_found;
let file,remap,pack,decls = parse_module' ctx.com m p in
if pack <> !remap then begin
let spack m = if m = [] then "`package;`" else "`package " ^ (String.concat "." m) ^ ";`" in
Expand Down

0 comments on commit f530b4c

Please sign in to comment.