|
@@ -19,7 +19,7 @@
|
|
|
|
|
|
open Globals
|
|
|
open Ast
|
|
|
-open Common
|
|
|
+open Gctx
|
|
|
open Type
|
|
|
open Path
|
|
|
open JvmGlobals
|
|
@@ -53,7 +53,7 @@ let get_construction_mode c cf =
|
|
|
(* Haxe *)
|
|
|
|
|
|
type generation_context = {
|
|
|
- com : Common.context;
|
|
|
+ gctx : Gctx.t;
|
|
|
out : Zip_output.any_output;
|
|
|
t_runtime_exception : Type.t;
|
|
|
entry_point : (tclass * texpr) option;
|
|
@@ -515,7 +515,6 @@ class texpr_to_jvm
|
|
|
(jm : JvmMethod.builder)
|
|
|
(return_type : jsignature option)
|
|
|
= object(self)
|
|
|
- val com = gctx.com
|
|
|
val code = jm#get_code
|
|
|
val pool : JvmConstantPool.constant_pool = jc#get_pool
|
|
|
|
|
@@ -531,7 +530,7 @@ class texpr_to_jvm
|
|
|
method vtype t =
|
|
|
jsignature_of_type gctx t
|
|
|
|
|
|
- method mknull t = com.basic.tnull (follow t)
|
|
|
+ method mknull t = gctx.gctx.basic.tnull (follow t)
|
|
|
|
|
|
(* locals *)
|
|
|
|
|
@@ -1000,13 +999,13 @@ class texpr_to_jvm
|
|
|
store();
|
|
|
let ev = mk (TLocal v) v.v_type null_pos in
|
|
|
let el = List.rev_map (fun case ->
|
|
|
- let f e' = mk (TBinop(OpEq,ev,e')) com.basic.tbool e'.epos in
|
|
|
+ let f e' = mk (TBinop(OpEq,ev,e')) gctx.gctx.basic.tbool e'.epos in
|
|
|
let e_cond = match case.case_patterns with
|
|
|
| [] -> die "" __LOC__
|
|
|
| [e] -> f e
|
|
|
| e :: el ->
|
|
|
List.fold_left (fun eacc e ->
|
|
|
- mk (TBinop(OpBoolOr,eacc,f e)) com.basic.tbool e.epos
|
|
|
+ mk (TBinop(OpBoolOr,eacc,f e)) gctx.gctx.basic.tbool e.epos
|
|
|
) (f e) el
|
|
|
in
|
|
|
(e_cond,case.case_expr)
|
|
@@ -2143,7 +2142,7 @@ class texpr_to_jvm
|
|
|
| TParenthesis e1 | TMeta(_,e1) ->
|
|
|
self#texpr ret e1
|
|
|
| TFor(v,e1,e2) ->
|
|
|
- self#texpr ret (Texpr.for_remap com.basic v e1 e2 e.epos)
|
|
|
+ self#texpr ret (Texpr.for_remap gctx.gctx.basic v e1 e2 e.epos)
|
|
|
| TEnumIndex e1 ->
|
|
|
self#texpr rvalue_any e1;
|
|
|
jm#invokevirtual java_enum_path "ordinal" (method_sig [] (Some TInt))
|
|
@@ -2593,9 +2592,9 @@ class tclass_to_jvm gctx c = object(self)
|
|
|
| None ->
|
|
|
if c.cl_path = (["haxe"],"Resource") && cf.cf_name = "content" then begin
|
|
|
let el = Hashtbl.fold (fun name _ acc ->
|
|
|
- Texpr.Builder.make_string gctx.com.basic name null_pos :: acc
|
|
|
- ) gctx.com.resources [] in
|
|
|
- let e = mk (TArrayDecl el) (gctx.com.basic.tarray gctx.com.basic.tstring) null_pos in
|
|
|
+ Texpr.Builder.make_string gctx.gctx.basic name null_pos :: acc
|
|
|
+ ) gctx.gctx.resources [] in
|
|
|
+ let e = mk (TArrayDecl el) (gctx.gctx.basic.tarray gctx.gctx.basic.tstring) null_pos in
|
|
|
default e;
|
|
|
end;
|
|
|
| Some e when mtype <> MStatic ->
|
|
@@ -2606,8 +2605,8 @@ class tclass_to_jvm gctx c = object(self)
|
|
|
begin match cf.cf_kind with
|
|
|
| Method MethDynamic ->
|
|
|
let enull = Texpr.Builder.make_null efield.etype null_pos in
|
|
|
- let echeck = Texpr.Builder.binop OpEq efield enull gctx.com.basic.tbool null_pos in
|
|
|
- let eif = mk (TIf(echeck,eop,None)) gctx.com.basic.tvoid null_pos in
|
|
|
+ let echeck = Texpr.Builder.binop OpEq efield enull gctx.gctx.basic.tbool null_pos in
|
|
|
+ let eif = mk (TIf(echeck,eop,None)) gctx.gctx.basic.tvoid null_pos in
|
|
|
DynArray.add delayed_field_inits eif
|
|
|
| _ ->
|
|
|
DynArray.add field_inits eop
|
|
@@ -2644,7 +2643,7 @@ class tclass_to_jvm gctx c = object(self)
|
|
|
let jsig = method_sig [array_sig string_sig] None in
|
|
|
let jm = jc#spawn_method "main" jsig [MPublic;MStatic] in
|
|
|
let _,load,_ = jm#add_local "args" (TArray(string_sig,None)) VarArgument in
|
|
|
- if has_feature gctx.com "haxe.root.Sys.args" then begin
|
|
|
+ if has_feature gctx.gctx "haxe.root.Sys.args" then begin
|
|
|
load();
|
|
|
jm#putstatic (["haxe";"root"],"Sys") "_args" (TArray(string_sig,None))
|
|
|
end;
|
|
@@ -2874,7 +2873,7 @@ let generate_enum gctx en =
|
|
|
jm_values#new_native_array (object_path_sig jc_enum#get_this_path) fl;
|
|
|
jm_values#return;
|
|
|
(* Add __meta__ TODO: do this via annotations instead? *)
|
|
|
- begin match Texpr.build_metadata gctx.com.basic (TEnumDecl en) with
|
|
|
+ begin match Texpr.build_metadata gctx.gctx.basic (TEnumDecl en) with
|
|
|
| None ->
|
|
|
()
|
|
|
| Some e ->
|
|
@@ -3037,7 +3036,7 @@ module Preprocessor = struct
|
|
|
| _ ->
|
|
|
()
|
|
|
) m.m_types
|
|
|
- ) gctx.com.modules;
|
|
|
+ ) gctx.gctx.modules;
|
|
|
(* preprocess classes *)
|
|
|
List.iter (fun mt ->
|
|
|
match mt with
|
|
@@ -3047,24 +3046,24 @@ module Preprocessor = struct
|
|
|
else if has_class_flag c CFunctionalInterface then
|
|
|
check_functional_interface gctx c
|
|
|
| _ -> ()
|
|
|
- ) gctx.com.types;
|
|
|
+ ) gctx.gctx.types;
|
|
|
(* find typedef-interface implementations *)
|
|
|
List.iter (fun mt -> match mt with
|
|
|
| TClassDecl c when not (has_class_flag c CInterface) && not (has_class_flag c CExtern) ->
|
|
|
gctx.typedef_interfaces#process_class c;
|
|
|
| _ ->
|
|
|
()
|
|
|
- ) gctx.com.types
|
|
|
+ ) gctx.gctx.types
|
|
|
end
|
|
|
|
|
|
-let generate jvm_flag com =
|
|
|
- let path = FilePath.parse com.file in
|
|
|
- let jar_name,entry_point = match get_entry_point com with
|
|
|
+let generate jvm_flag gctx =
|
|
|
+ let path = FilePath.parse gctx.file in
|
|
|
+ let jar_name,entry_point = match get_entry_point gctx with
|
|
|
| Some (jarname,cl,expr) -> jarname, Some (cl,expr)
|
|
|
| None -> "jar",None
|
|
|
in
|
|
|
let compression_level = try
|
|
|
- int_of_string (Define.defined_value com.defines Define.JvmCompressionLevel)
|
|
|
+ int_of_string (Define.defined_value gctx.defines Define.JvmCompressionLevel)
|
|
|
with _ ->
|
|
|
6
|
|
|
in
|
|
@@ -3077,10 +3076,10 @@ let generate jvm_flag com =
|
|
|
| Some _ ->
|
|
|
begin match path.directory with
|
|
|
| None ->
|
|
|
- "./",create_jar ("./" ^ com.file)
|
|
|
+ "./",create_jar ("./" ^ gctx.file)
|
|
|
| Some dir ->
|
|
|
mkdir_from_path dir;
|
|
|
- add_trailing_slash dir,create_jar com.file
|
|
|
+ add_trailing_slash dir,create_jar gctx.file
|
|
|
end
|
|
|
| None -> match path.directory with
|
|
|
| Some dir ->
|
|
@@ -3089,25 +3088,25 @@ let generate jvm_flag com =
|
|
|
| None ->
|
|
|
failwith "Please specify an output file name"
|
|
|
end else begin
|
|
|
- let jar_name = if com.debug then jar_name ^ "-Debug" else jar_name in
|
|
|
- let jar_dir = add_trailing_slash com.file in
|
|
|
+ let jar_name = if gctx.debug then jar_name ^ "-Debug" else jar_name in
|
|
|
+ let jar_dir = add_trailing_slash gctx.file in
|
|
|
let jar_path = Printf.sprintf "%s%s.jar" jar_dir jar_name in
|
|
|
jar_dir,create_jar jar_path
|
|
|
end in
|
|
|
let anon_identification = new tanon_identification in
|
|
|
let dynamic_level = try
|
|
|
- int_of_string (Define.defined_value com.defines Define.JvmDynamicLevel)
|
|
|
+ int_of_string (Define.defined_value gctx.defines Define.JvmDynamicLevel)
|
|
|
with _ ->
|
|
|
1
|
|
|
in
|
|
|
if dynamic_level < 0 || dynamic_level > 2 then failwith "Invalid value for -D jvm.dynamic-level: Must be >=0 and <= 2";
|
|
|
let gctx = {
|
|
|
- com = com;
|
|
|
+ gctx = gctx;
|
|
|
out = out;
|
|
|
- t_runtime_exception = TInst(resolve_class com (["java";"lang"],"RuntimeException"),[]);
|
|
|
+ t_runtime_exception = TInst(resolve_class gctx (["java";"lang"],"RuntimeException"),[]);
|
|
|
entry_point = entry_point;
|
|
|
- t_exception = TInst(resolve_class com (["java";"lang"],"Exception"),[]);
|
|
|
- t_throwable = TInst(resolve_class com (["java";"lang"],"Throwable"),[]);
|
|
|
+ t_exception = TInst(resolve_class gctx (["java";"lang"],"Exception"),[]);
|
|
|
+ t_throwable = TInst(resolve_class gctx (["java";"lang"],"Throwable"),[]);
|
|
|
anon_identification = anon_identification;
|
|
|
preprocessor = Obj.magic ();
|
|
|
typedef_interfaces = Obj.magic ();
|
|
@@ -3118,14 +3117,14 @@ let generate jvm_flag com =
|
|
|
default_export_config = {
|
|
|
export_debug = true;
|
|
|
};
|
|
|
- detail_times = Common.raw_defined com "jvm_times";
|
|
|
+ detail_times = Gctx.raw_defined gctx "jvm_times";
|
|
|
timer = new Timer.timer ["generate";"java"];
|
|
|
jar_compression_level = compression_level;
|
|
|
dynamic_level = dynamic_level;
|
|
|
functional_interfaces = [];
|
|
|
} in
|
|
|
Hashtbl.add gctx.known_typed_functions haxe_function_path ();
|
|
|
- gctx.preprocessor <- new preprocessor com.basic (jsignature_of_type gctx);
|
|
|
+ gctx.preprocessor <- new preprocessor gctx.gctx.basic (jsignature_of_type gctx);
|
|
|
gctx.typedef_interfaces <- new typedef_interfaces gctx.preprocessor#get_infos anon_identification;
|
|
|
gctx.typedef_interfaces#add_interface_rewrite (["haxe";"root"],"Iterator") (["java";"util"],"Iterator") true;
|
|
|
let class_paths = ExtList.List.filter_map (fun java_lib ->
|
|
@@ -3142,13 +3141,13 @@ let generate jvm_flag com =
|
|
|
close_out ch_out;
|
|
|
Some (Printf.sprintf "lib/%s \n" name)
|
|
|
end
|
|
|
- ) com.native_libs.java_libs in
|
|
|
+ ) gctx.gctx.native_libs in
|
|
|
Hashtbl.iter (fun name v ->
|
|
|
let filename = StringHelper.escape_res_name name ['/';'-'] in
|
|
|
gctx.out#add_entry v filename;
|
|
|
- ) com.resources;
|
|
|
+ ) gctx.gctx.resources;
|
|
|
let generate_real_types () =
|
|
|
- List.iter (generate_module_type gctx) com.types;
|
|
|
+ List.iter (generate_module_type gctx) gctx.gctx.types;
|
|
|
in
|
|
|
let generate_typed_interfaces () =
|
|
|
Hashtbl.iter (fun _ c -> generate_module_type gctx (TClassDecl c)) gctx.typedef_interfaces#get_interfaces;
|