Skip to content

Commit

Permalink
invert texpr order: kind, type, pos
Browse files Browse the repository at this point in the history
This will allow us to omit some type instances in case they can be inferred from the kind.
  • Loading branch information
Simn committed Jan 18, 2024
1 parent 0477c76 commit ab8f870
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
19 changes: 9 additions & 10 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ type field_reader_context = {
t_pool : Type.t Array.t;
pos : pos ref;
vars : tvar Array.t;
mutable tthis : Type.t;
mutable tthis : Type.t option;
}

let create_field_reader_context p ts vars = {
let create_field_reader_context p ts vars tthis = {
t_pool = ts;
pos = ref p;
vars = vars;
tthis = t_dynamic;
tthis = tthis;
}

type hxb_reader_stats = {
Expand Down Expand Up @@ -932,15 +932,11 @@ class hxb_reader
!(fctx.pos)
in
let rec loop () =
let t = fctx.t_pool.(read_uleb128 ch) in
let p = read_relpos () in
let loop2 () =
match IO.read_byte ch with
(* values 0-19 *)
| 0 -> TConst TNull
| 1 ->
fctx.tthis <- t;
TConst TThis
| 1 -> TConst TThis
| 2 -> TConst TSuper
| 3 -> TConst (TBool false)
| 4 -> TConst (TBool true)
Expand Down Expand Up @@ -1138,7 +1134,7 @@ class hxb_reader
let c = self#read_class_ref in
let tl = self#read_types in
let cf = self#read_field_ref in
let ethis = mk (TConst TThis) fctx.tthis p in
let ethis = mk (TConst TThis) (Option.get fctx.tthis) p in
TField(ethis,FInstance(c,tl,cf))

(* module types 120-139 *)
Expand Down Expand Up @@ -1186,6 +1182,8 @@ class hxb_reader
die (Printf.sprintf " [ERROR] Unhandled texpr %d at:" i) __LOC__
in
let e = loop2 () in
let t = fctx.t_pool.(read_uleb128 ch) in
let p = read_relpos () in
let e = {
eexpr = e;
etype = t;
Expand Down Expand Up @@ -1215,6 +1213,7 @@ class hxb_reader
| i ->
die "" __LOC__
end;
let tthis = self#read_option (fun () -> self#read_type_instance) in
let l = read_uleb128 ch in
let ts = Array.init l (fun _ ->
self#read_type_instance
Expand All @@ -1223,7 +1222,7 @@ class hxb_reader
let vars = Array.init l (fun _ ->
self#read_var
) in
create_field_reader_context self#read_pos ts vars
create_field_reader_context self#read_pos ts vars tthis

method read_field_type_parameters =
let num_params = read_uleb128 ch in
Expand Down
11 changes: 6 additions & 5 deletions src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1291,11 +1291,7 @@ module HxbWriter = struct
write_type_instance writer v.v_type;
in
let rec loop e =

write_texpr_type_instance writer fctx e.etype;
PosWriter.write_pos fctx.pos_writer writer.chunk true 0 e.epos;

match e.eexpr with
begin match e.eexpr with
(* values 0-19 *)
| TConst ct ->
begin match ct with
Expand Down Expand Up @@ -1554,6 +1550,10 @@ module HxbWriter = struct
| TIdent s ->
Chunk.write_u8 writer.chunk 250;
Chunk.write_string writer.chunk s;
end;
write_texpr_type_instance writer fctx e.etype;
PosWriter.write_pos fctx.pos_writer writer.chunk true 0 e.epos;

and loop_el el =
Chunk.write_list writer.chunk el loop
in
Expand Down Expand Up @@ -1666,6 +1666,7 @@ module HxbWriter = struct
let ltp = List.map fst writer.local_type_parameters#to_list in
write_type_parameters writer ltp
end;
Chunk.write_option writer.chunk fctx.texpr_this (fun e -> write_type_instance writer e.etype);
let items,length = StringPool.get_sorted_items fctx.t_pool in
Chunk.write_uleb128 writer.chunk length;
List.iter (fun bytes ->
Expand Down

0 comments on commit ab8f870

Please sign in to comment.