From e32732ac1e00e7dd521fa5d76500871a12e6cc7f Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 11 Oct 2023 21:25:44 +0200 Subject: [PATCH] [hxb] restore base hxb --- src/compiler/generate.ml | 36 ++++++------ src/typing/typeloadModule.ml | 107 ++++++++++++++++++----------------- tests/runci/targets/Macro.hx | 5 +- 3 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/compiler/generate.ml b/src/compiler/generate.ml index 312c311a678..d3c3997046f 100644 --- a/src/compiler/generate.ml +++ b/src/compiler/generate.ml @@ -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 @@ -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 diff --git a/src/typing/typeloadModule.ml b/src/typing/typeloadModule.ml index 9be68befba8..36926c050c8 100644 --- a/src/typing/typeloadModule.ml +++ b/src/typing/typeloadModule.ml @@ -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 @@ -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(); diff --git a/tests/runci/targets/Macro.hx b/tests/runci/targets/Macro.hx index 8fcdb46b2e7..869614ba984 100644 --- a/tests/runci/targets/Macro.hx +++ b/tests/runci/targets/Macro.hx @@ -5,9 +5,8 @@ import runci.Config.*; class Macro { static public function run(args:Array) { - // 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));