Skip to content

Commit

Permalink
[hxb] restore function tvoid optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Jul 7, 2023
1 parent f1425aa commit 9a5ec8b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
32 changes: 20 additions & 12 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ class hxb_reader
val mutable type_type_parameters = Array.make 0 (mk_type_param "" t_dynamic None)
val mutable field_type_parameters = Array.make 0 (mk_type_param "" t_dynamic None)

val mutable tvoid = None
method get_tvoid =
match tvoid with
| Some tvoid -> tvoid
| None ->
let t = type_of_module_type (resolve_type [] "StdTypes" "Void") in
tvoid <- Some t;
t

(* Primitives *)

method read_u8 =
Expand Down Expand Up @@ -615,18 +624,17 @@ class hxb_reader
let a = self#read_abstract_ref in
let tl = self#read_types in
TAbstract(a,tl)
(* TODO see writer *)
(* | 30 -> TFun([],t_void) *)
(* | 31 -> *)
(* let f () = *)
(* let name = self#read_string in *)
(* (1* Printf.eprintf " Read type instance for %s\n" name; *1) *)
(* let opt = self#read_bool in *)
(* let t = self#read_type_instance in *)
(* (name,opt,t) *)
(* in *)
(* let args = self#read_list f in *)
(* TFun(args,t_void) *)
| 30 -> TFun([],self#get_tvoid)
| 31 ->
let f () =
let name = self#read_string in
(* Printf.eprintf " Read type instance for %s\n" name; *)
let opt = self#read_bool in
let t = self#read_type_instance in
(name,opt,t)
in
let args = self#read_list f in
TFun(args,self#get_tvoid)
| 32 ->
let f () =
let name = self#read_string in
Expand Down
11 changes: 5 additions & 6 deletions src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,11 @@ class ['a] hxb_writer
chunk#write_byte 17;
self#write_abstract_ref a;
self#write_types tl
(* TODO what to do with void special case? *)
(* | TFun([],t) when ExtType.is_void (follow t) -> *)
(* chunk#write_byte 30; *)
(* | TFun(args,t) when ExtType.is_void (follow t) -> *)
(* chunk#write_byte 31; *)
(* chunk#write_list args write_function_arg; *)
| TFun([],t) when ExtType.is_void (follow t) ->
chunk#write_byte 30;
| TFun(args,t) when ExtType.is_void (follow t) ->
chunk#write_byte 31;
chunk#write_list args write_function_arg;
| TFun(args,t) ->
chunk#write_byte 32;
chunk#write_list args write_function_arg;
Expand Down

0 comments on commit 9a5ec8b

Please sign in to comment.