Skip to content

Commit

Permalink
[jvm] clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Aug 10, 2020
1 parent 47b40e0 commit 1ed58f4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/generators/genjvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () ->
Expand Down
4 changes: 4 additions & 0 deletions src/generators/jvm/jvmCode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 7 additions & 11 deletions src/generators/jvm/jvmMethod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,15 @@ 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);
| ConstructInit ->
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
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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 ->
Expand All @@ -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 _ ->
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 1ed58f4

Please sign in to comment.