Browse Source

[jvm] move type_expr to JvmMethod.get_class

Simon Krajewski 5 years ago
parent
commit
17d35f8299
2 changed files with 33 additions and 34 deletions
  1. 2 34
      src/generators/genjvm.ml
  2. 31 0
      src/generators/jvm/jvmMethod.ml

+ 2 - 34
src/generators/genjvm.ml

@@ -1781,38 +1781,6 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 	method new_native_array jsig el =
 		jm#new_native_array jsig (List.map (fun e -> fun () -> self#texpr (rvalue_sig jsig) e) el)
 
-	method basic_type_path name =
-		let offset = pool#add_field (["java";"lang"],name) "TYPE" java_class_sig FKField in
-		code#getstatic offset java_class_sig
-
-	method type_expr = function
-		| TByte -> self#basic_type_path "Byte"
-		| TChar -> self#basic_type_path "Character"
-		| TDouble -> self#basic_type_path "Double"
-		| TFloat -> self#basic_type_path "Float"
-		| TInt -> self#basic_type_path "Integer"
-		| TLong -> self#basic_type_path "Long"
-		| TShort -> self#basic_type_path "Short"
-		| TBool -> self#basic_type_path "Boolean"
-		| TObject(path,_) ->
-			let offset = pool#add_path path in
-			let t = object_path_sig path in
-			code#ldc offset (TObject(java_class_path,[TType(WNone,t)]))
-		| TMethod _ ->
-			assert false
-			(* let offset = pool#add_path method_handle_path in
-			code#ldc offset (TObject(java_class_path,[TType(WNone,method_handle_sig)])) *)
-		| TTypeParameter _ ->
-			let offset = pool#add_path object_path in
-			code#ldc offset (TObject(java_class_path,[TType(WNone,object_sig)]))
-		| TArray _ as t ->
-			(* TODO: this seems hacky *)
-			let offset = pool#add_path ([],generate_signature false t) in
-			code#ldc offset (TObject(java_class_path,[TType(WNone,object_sig)]))
-		| jsig ->
-			print_endline (generate_signature false jsig);
-			assert false
-
 	method texpr ret e =
 		try
 			if not jm#is_terminated then self#texpr' ret e
@@ -1836,8 +1804,8 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 			load()
 		| TTypeExpr mt ->
 			let t = type_of_module_type mt in
-			if ExtType.is_void (follow t) then self#basic_type_path "Void"
-			else self#type_expr (jsignature_of_type gctx t)
+			if ExtType.is_void (follow t) then jm#get_basic_type_class "Void"
+			else jm#get_class (jsignature_of_type gctx t)
 		| TUnop(op,flag,e1) ->
 			begin match op with
 			| Not | Neg | NegBits when not (need_val ret) -> self#texpr ret e1

+ 31 - 0
src/generators/jvm/jvmMethod.ml

@@ -269,6 +269,37 @@ class builder jc name jsig = object(self)
 		let offset = code#get_pool#add_field path name jsigf FKField in
 		code#putstatic offset jsigf
 
+	method get_basic_type_class (name : string) =
+		self#getstatic (["java";"lang"],name) "TYPE" java_class_sig
+
+	method get_class (jsig : jsignature) =
+		match jsig with
+		| TByte -> self#get_basic_type_class "Byte"
+		| TChar -> self#get_basic_type_class "Character"
+		| TDouble -> self#get_basic_type_class "Double"
+		| TFloat -> self#get_basic_type_class "Float"
+		| TInt -> self#get_basic_type_class "Integer"
+		| TLong -> self#get_basic_type_class "Long"
+		| TShort -> self#get_basic_type_class "Short"
+		| TBool -> self#get_basic_type_class "Boolean"
+		| TObject(path,_) ->
+			let offset = code#get_pool#add_path path in
+			let t = object_path_sig path in
+			code#ldc offset (TObject(java_class_path,[TType(WNone,t)]))
+		| TTypeParameter _ ->
+			let offset = code#get_pool#add_path object_path in
+			code#ldc offset (TObject(java_class_path,[TType(WNone,object_sig)]))
+		| TArray _ as t ->
+			(* TODO: this seems hacky *)
+			let offset = code#get_pool#add_path ([],generate_signature false t) in
+			code#ldc offset (TObject(java_class_path,[TType(WNone,object_sig)]))
+		| TMethod _ ->
+			let offset = code#get_pool#add_path haxe_function_path in
+			code#ldc offset (TObject(java_class_path,[TType(WNone,object_sig)]))
+		| jsig ->
+			print_endline (generate_signature false jsig);
+			assert false
+
 	(** Loads `this` **)
 	method load_this =
 		code#aload self#get_this_sig 0