Skip to content

Commit

Permalink
[hxb] carry local params in anons
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Jul 14, 2023
1 parent eb55728 commit 71678b2
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ let print_params source ttp =
Printf.eprintf "Params from %s: \n" source;
List.iter (fun t -> Printf.eprintf " %s\n" t.ttp_name) ttp

let print_lparams source ltp =
Printf.eprintf "Local Params from %s: \n" source;
List.iter (fun c -> Printf.eprintf " %s\n" (s_type_path c.cl_path)) ltp

class ['key,'value] pool = object(self)
val lut = Hashtbl.create 0
val items = DynArray.create ()
Expand Down Expand Up @@ -328,7 +332,7 @@ class ['a] hxb_writer
let pfm = Option.get (anon_id#identify true (TAnon an)) in
let ftp = field_type_parameters#to_list in
let ttp = ttp @ type_type_parameters#to_list in
let i = anons#get_or_add pfm.pfm_path (an,ttp,ftp) in
let i = anons#get_or_add pfm.pfm_path (an,ttp,ftp,local_type_parameters) in
chunk#write_uleb128 i

method write_field_ref (source : field_source) (cf : tclass_field) =
Expand All @@ -350,7 +354,7 @@ class ['a] hxb_writer
(* else Printf.eprintf "Adding anon %s in anon_fields\n" cf.cf_name; *)
(* end; *)

let i = anon_fields#get_or_add cf (cf,ttp,ftp) in
let i = anon_fields#get_or_add cf (cf,ttp,ftp,local_type_parameters) in
chunk#write_uleb128 i

(* Type instances *)
Expand Down Expand Up @@ -1157,9 +1161,9 @@ class ['a] hxb_writer
f r;
f w;

method write_class_field ?(with_pos = false) cf =
method write_class_field ?(with_pos = false) ?(ltp = []) cf =
self#set_field_type_parameters cf.cf_params;
local_type_parameters <- [];
local_type_parameters <- ltp;
let restore = self#start_temporary_chunk in
(* if (snd current_module.m_path) = "Main" then *)
(* Printf.eprintf " (1) Write class field %s\n" cf.cf_name; *)
Expand Down Expand Up @@ -1311,15 +1315,15 @@ class ['a] hxb_writer
self#write_common_module_type (Obj.magic td);
self#write_type_instance td.t_type;

method write_anon (m : module_def) ((an : tanon), (ttp : type_params), (ftp : type_params)) =
method write_anon (m : module_def) ((an : tanon), (ttp : type_params), (ftp : type_params), (ltp : tclass list)) =
type_type_parameters <- new pool;
List.iter (fun ttp -> ignore(type_type_parameters#add ttp.ttp_name ttp)) ttp;
chunk#write_list ttp self#write_type_parameter_forward;
chunk#write_list ttp self#write_type_parameter_data;

let write_fields () =
chunk#write_list (PMap.foldi (fun s f acc -> (s,f) :: acc) an.a_fields []) (fun (_,cf) ->
self#write_class_field ~with_pos:true { cf with cf_params = (cf.cf_params @ ftp) };
self#write_class_field ~with_pos:true ~ltp { cf with cf_params = (cf.cf_params @ ftp) };
)
in

Expand Down Expand Up @@ -1499,19 +1503,19 @@ class ['a] hxb_writer
()
| l ->
self#start_chunk ANFR;
chunk#write_list l (fun (cf,_,_) ->
chunk#write_list l (fun (cf,_,_,_) ->
(* Printf.eprintf "Write anon field %s\n" cf.cf_name; *)
chunk#write_string cf.cf_name;
self#write_pos cf.cf_pos;
self#write_pos cf.cf_name_pos;
);
self#start_chunk ANFD;
chunk#write_list l (fun (cf,ttp,ftp) ->
chunk#write_list l (fun (cf,ttp,ftp,ltp) ->
type_type_parameters <- new pool;
List.iter (fun ttp -> ignore(type_type_parameters#add ttp.ttp_name ttp)) ttp;
chunk#write_list ttp self#write_type_parameter_forward;
chunk#write_list ttp self#write_type_parameter_data;
self#write_class_field { cf with cf_params = (cf.cf_params @ ftp) };
self#write_class_field ~ltp { cf with cf_params = (cf.cf_params @ ftp) };
);
end;

Expand Down

0 comments on commit 71678b2

Please sign in to comment.