Skip to content

Commit

Permalink
[awkward] deal with new TypeParam
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jul 12, 2023
1 parent 535fea0 commit 453dd44
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 28 deletions.
22 changes: 22 additions & 0 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,28 @@ class hxb_reader
let tl = self#read_types in
let el = self#read_texpr_list in
TNew(c,tl,el)
| 127 ->
(* TODO: this is giga awkward *)
let t = match self#read_uleb128 with
| 5 ->
let i = self#read_uleb128 in
(field_type_parameters.(i)).ttp_type
| 6 ->
let i = self#read_uleb128 in
(type_type_parameters.(i)).ttp_type
| 7 ->
let k = self#read_uleb128 in
(DynArray.get local_type_parameters k).ttp_type
| _ ->
die "" __LOC__
in
let c = match t with
| TInst(c,_) -> c
| _ -> die "" __LOC__
in
let tl = self#read_types in
let el = self#read_texpr_list in
TNew(c,tl,el)

(* unops 140-159 *)
| _ when i >= 140 && i < 160 ->
Expand Down
58 changes: 33 additions & 25 deletions src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,33 @@ class ['a] hxb_writer

(* Type instances *)

method write_type_parameter_ref (c : tclass) =
begin try
let i = field_type_parameters#get (snd c.cl_path) in
chunk#write_byte 5;
chunk#write_uleb128 i
with Not_found -> try
let i = type_type_parameters#get (snd c.cl_path) in
chunk#write_byte 6;
chunk#write_uleb128 i
with Not_found -> try
let rec loop k l = match l with
| [] ->
raise Not_found
| c' :: l ->
if c == c' then begin
chunk#write_byte 7;
chunk#write_uleb128 k;
end else
loop (k + 1) l
in
loop 0 local_type_parameters
with Not_found ->
(* error ("Unbound type parameter " ^ (s_type_path c.cl_path)) *)
Printf.eprintf "%s Unbound type parameter %s\n" todo_error (s_type_path c.cl_path);
chunk#write_byte 40
end

method write_type_instance t =
let write_function_arg (n,o,t) =
chunk#write_string n;
Expand All @@ -323,31 +350,7 @@ class ['a] hxb_writer
self#write_type_instance t
end
| TInst({cl_kind = KTypeParameter _} as c,[]) ->
begin try
let i = field_type_parameters#get (snd c.cl_path) in
chunk#write_byte 5;
chunk#write_uleb128 i
with Not_found -> try
let i = type_type_parameters#get (snd c.cl_path) in
chunk#write_byte 6;
chunk#write_uleb128 i
with Not_found -> try
let rec loop k l = match l with
| [] ->
raise Not_found
| c' :: l ->
if c == c' then begin
chunk#write_byte 7;
chunk#write_uleb128 k;
end else
loop (k + 1) l
in
loop 0 local_type_parameters
with Not_found ->
(* error ("Unbound type parameter " ^ (s_type_path c.cl_path)) *)
Printf.eprintf "%s Unbound type parameter %s\n" todo_error (s_type_path c.cl_path);
chunk#write_byte 40
end
self#write_type_parameter_ref c
| TInst(c,[]) ->
chunk#write_byte 10;
self#write_class_ref c;
Expand Down Expand Up @@ -992,6 +995,11 @@ class ['a] hxb_writer
let infos = t_infos md in
let m = infos.mt_module in
self#write_full_path (fst m.m_path) (snd m.m_path) (snd infos.mt_path);
| TNew(({cl_kind = KTypeParameter _} as c),tl,el) ->
chunk#write_byte 127;
self#write_type_parameter_ref c;
self#write_types tl;
loop_el el;
| TNew(c,tl,el) ->
chunk#write_byte 126;
self#write_class_ref c;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
{"label": "Lua", "args": ["compile-lua.hxml", "-cmd", "lua bin/unit.lua"]},
],
"[haxe]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": true
"editor.formatOnSave": false,
"editor.formatOnPaste": false
},
"editor.codeActionsOnSave": {
"source.sortImports": true
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/src/unit/TestMain.hx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function main() {
new TestSerialize(),
new TestSerializerCrossTarget(),
new TestMeta(),
// new TestType(),
new TestType(),
new TestOrder(),
// new TestGADT(), // hxb: Unbound type parameter EBinop.C
// new TestGeneric(),
Expand Down

0 comments on commit 453dd44

Please sign in to comment.