Pārlūkot izejas kodu

[awkward] deal with new TypeParam

Simon Krajewski 2 gadi atpakaļ
vecāks
revīzija
2511ca2ce3

+ 22 - 0
src/compiler/hxb/hxbReader.ml

@@ -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 ->

+ 33 - 25
src/compiler/hxb/hxbWriter.ml

@@ -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;
@@ -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;
@@ -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;

+ 2 - 2
tests/unit/.vscode/settings.json

@@ -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

+ 1 - 1
tests/unit/src/unit/TestMain.hx

@@ -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(),