Simon Krajewski 5 лет назад
Родитель
Сommit
1ed58f4c4e
3 измененных файлов с 12 добавлено и 13 удалено
  1. 1 2
      src/generators/genjvm.ml
  2. 4 0
      src/generators/jvm/jvmCode.ml
  3. 7 11
      src/generators/jvm/jvmMethod.ml

+ 1 - 2
src/generators/genjvm.ml

@@ -2084,8 +2084,7 @@ let generate_dynamic_access gctx (jc : JvmClass.builder) fields is_anon =
 					jm#getfield jc#get_this_path name jsig;
 					jm#expect_reference_type;
 				end;
-				ignore(jm#get_code#get_stack#pop);
-				jm#get_code#get_stack#push object_sig;
+				jm#replace_top object_sig;
 			)
 		) fields in
 		let def = (fun () ->

+ 4 - 0
src/generators/jvm/jvmCode.ml

@@ -88,6 +88,10 @@ class jvm_stack = object(self)
 				raise EmptyStack
 		in
 		loop [] i stack
+
+	method replace jsig =
+		ignore(self#pop);
+		self#push jsig
 end
 
 class builder pool = object(self)

+ 7 - 11
src/generators/jvm/jvmMethod.ml

@@ -347,7 +347,7 @@ class builder jc name jsig = object(self)
 			code#dup;
 			code#aconst_null haxe_empty_constructor_sig;
 			self#invokespecial path "<init>" (method_sig [haxe_empty_constructor_sig] None);
-			if not no_value then self#set_top_initialized (object_path_sig path);
+			if not no_value then self#replace_top (object_path_sig path);
 			if not no_value then code#dup;
 			let jsigs = f () in
 			self#invokevirtual path "new" (method_sig jsigs None);
@@ -355,7 +355,7 @@ class builder jc name jsig = object(self)
 			if not no_value then code#dup;
 			let jsigs = f () in
 			self#invokespecial path "<init>" (method_sig jsigs None);
-			if not no_value then self#set_top_initialized (object_path_sig path)
+			if not no_value then self#replace_top (object_path_sig path)
 
 	(** Loads the default value corresponding to a given signature. **)
 	method load_default_value = function
@@ -490,8 +490,7 @@ class builder jc name jsig = object(self)
 		in
 		let rec unboxed_to_int () = match code#get_stack#top with
 			| TBool | TByte | TShort | TChar | TInt ->
-				ignore(code#get_stack#pop);
-				code#get_stack#push TInt;
+				self#replace_top TInt;
 			| TLong ->
 				code#l2i;
 			| TFloat ->
@@ -611,8 +610,7 @@ class builder jc name jsig = object(self)
 			code#l2i;
 			code#i2c;
 		| TBool,TInt ->
-			ignore(code#get_stack#pop);
-			code#get_stack#push TBool;
+			self#replace_top TBool;
 		| TObject(path1,_),TObject(path2,_) when path1 = path2 ->
 			()
 		| TObject((["java";"lang"],"String"),_),_ when allow_to_string ->
@@ -623,8 +621,7 @@ class builder jc name jsig = object(self)
 				self#expect_reference_type
 			else if path1 = object_path then begin
 				(* We should never need a checkcast to Object, but we should adjust the stack so stack maps are wide enough *)
-				ignore(code#get_stack#pop);
-				code#get_stack#push object_sig
+				self#replace_top object_sig
 			end else
 				code#checkcast path1
 		| TMethod _,TMethod _ ->
@@ -1002,9 +999,8 @@ class builder jc name jsig = object(self)
 		in
 		locals <- loop [] locals
 
-	method set_top_initialized jsig =
-		ignore(code#get_stack#pop);
-		code#get_stack#push jsig
+	method replace_top jsig =
+		code#get_stack#replace jsig
 
 	(** This function has to be called once all arguments are declared. *)
 	method finalize_arguments =