Skip to content

Commit

Permalink
[hxb] restore base hxb
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Oct 11, 2023
1 parent e902980 commit e32732a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 74 deletions.
36 changes: 17 additions & 19 deletions src/compiler/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,22 @@ let check_auxiliary_output com actx =
Genjson.generate com.types file
end

let export_hxb com root m =
(* TODO update hxb export *)
()
(* match m.m_extra.m_kind with *)
(* | MCode | MMacro | MFake -> begin *)
(* (1* Printf.eprintf "Export module %s\n" (s_type_path m.m_path); *1) *)
(* let anon_identification = new Tanon_identification.tanon_identification ([],"") in *)
(* let writer = new HxbWriter.hxb_writer com anon_identification in *)
(* writer#write_module m; *)
(* let ch = IO.output_bytes() in *)
(* writer#export ch; *)
(* let bytes_cp = IO.close_out ch in *)
(* let l = (root :: fst m.m_path @ [snd m.m_path]) in *)
(* let ch_file = Path.create_file true ".hxb" [] l in *)
(* output_bytes ch_file bytes_cp; *)
(* close_out ch_file *)
(* end *)
(* | _ -> () *)
let export_hxb root (m:TType.module_def) =
match m.m_extra.m_kind with
| MCode | MMacro | MFake -> begin
(* Printf.eprintf "Export module %s\n" (s_type_path m.m_path); *)
let anon_identification = new Tanon_identification.tanon_identification ([],"") in
let writer = new HxbWriter.hxb_writer anon_identification in
writer#write_module m;
let ch = IO.output_bytes() in
writer#export ch;
let bytes_cp = IO.close_out ch in
let l = (root :: fst m.m_path @ [snd m.m_path]) in
let ch_file = Path.create_file true ".hxb" [] l in
output_bytes ch_file bytes_cp;
close_out ch_file
end
| _ -> ()

let check_hxb_output com actx =
begin match actx.hxb_out with
Expand Down Expand Up @@ -73,7 +71,7 @@ let check_hxb_output com actx =
clean_files path;
let t = Timer.timer ["generate";"hxb"] in
Printf.eprintf "%d modules, %d types\n" (List.length com.modules) (List.length com.types);
List.iter (export_hxb com path) com.modules;
List.iter (export_hxb path) com.modules;
t();
in

Expand Down
107 changes: 55 additions & 52 deletions src/typing/typeloadModule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -797,56 +797,60 @@ let type_module ctx mpath file ?(dont_check_path=false) ?(is_extern=false) tdecl

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

(* let rec get_reader ctx input mpath p = *)
(* 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 = *)
(* ctx.com.module_lut#add m.m_path m *)
(* 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 *)

(* and load_hxb_module ctx path p = *)
(* let compose_path no_rename = *)
(* (match path with *)
(* | [] , name -> name *)
(* | x :: l , name -> *)
(* String.concat "/" (x :: l) ^ "/" ^ name *)
(* ) ^ ".hxb" *)
(* in *)

(* let target = Common.platform_name_macro ctx.com in *)
(* let bcp = List.map (fun p -> p ^ target ^ Path.path_sep) ctx.com.binary_class_path in *)
(* let find_file = Common.find_file ctx.com ~class_path:bcp in *)
(* let file = try find_file (compose_path false) with Not_found -> find_file (compose_path true) in *)
(* let ch = try open_in_bin file with Sys_error _ -> raise Not_found in *)
(* let input = IO.input_channel ch in *)

(* (1* TODO use finally instead *1) *)
(* try *)
(* (1* Printf.eprintf "[%s] Read module %s\n" target (s_type_path path); *1) *)
(* let m = (get_reader ctx input path p)#read true p in *)
(* (1* Printf.eprintf "[%s] Done reading module %s\n" target (s_type_path path); *1) *)
(* close_in ch; *)
(* m *)
(* with e -> *)
(* Printf.eprintf "\x1b[30;41mError loading %s from %s\x1b[0m\n" (snd path) file; *)
(* let msg = Printexc.to_string e and stack = Printexc.get_backtrace () in *)
(* Printf.eprintf " => %s\n%s\n" msg stack; *)
(* close_in ch; *)
(* raise e *)

(* and load_module' ctx g m p = *)
let load_module' ctx g m p =
let rec get_reader ctx mpath p =
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 =
ctx.com.module_lut#add m.m_path m
in

let resolve_type sign 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

let flush_fields () =
flush_pass ctx PConnectField "hxb"
in

let reader = new HxbReader.hxb_reader make_module add_module resolve_type flush_fields in
reader

and load_hxb_module ctx path p =
let compose_path no_rename =
(match path with
| [] , name -> name
| x :: l , name ->
String.concat "/" (x :: l) ^ "/" ^ name
) ^ ".hxb"
in

let target = Common.platform_name_macro ctx.com in
let bcp = List.map (fun p -> p ^ target ^ Path.path_sep) ctx.com.binary_class_path in
let find_file = Common.find_file ctx.com ~class_path:bcp in
let file = try find_file (compose_path false) with Not_found -> find_file (compose_path true) in
let ch = try open_in_bin file with Sys_error _ -> raise Not_found in
let input = IO.input_channel ch in

(* TODO use finally instead *)
try
(* Printf.eprintf "[%s] Read module %s\n" target (s_type_path path); *)
let m = (get_reader ctx path p)#read input true p in
(* Printf.eprintf "[%s] Done reading module %s\n" target (s_type_path path); *)
close_in ch;
m
with e ->
Printf.eprintf "\x1b[30;41mError loading %s from %s\x1b[0m\n" (snd path) file;
let msg = Printexc.to_string e and stack = Printexc.get_backtrace () in
Printf.eprintf " => %s\n%s\n" msg stack;
close_in ch;
raise e

and load_module' ctx g m p =
try
(* Check current context *)
ctx.com.module_lut#find m
Expand All @@ -856,8 +860,7 @@ let load_module' ctx g m p =
| Some m ->
m
(* Try loading from hxb first, then from source *)
(* | None -> try load_hxb_module ctx m p with Not_found -> *)
| None ->
| 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();
if ctx.g.load_only_cached_modules then raise_not_found();
Expand Down
5 changes: 2 additions & 3 deletions tests/runci/targets/Macro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import runci.Config.*;

class Macro {
static public function run(args:Array<String>) {
// runCommand("haxe", ["compile-hxb-interp.hxml"].concat(args));
// runCommand("haxe", ["compile-read-hxb-interp.hxml"].concat(args));
// return; // don't overlook this
runCommand("haxe", ["compile-hxb-interp.hxml"].concat(args));
runCommand("haxe", ["compile-read-hxb-interp.hxml"].concat(args));

runCommand("haxe", ["compile-macro.hxml"].concat(args));

Expand Down

0 comments on commit e32732a

Please sign in to comment.