2
0
Эх сурвалжийг харах

group com.main/main_class

Simon Krajewski 1 жил өмнө
parent
commit
bf329ea9d3

+ 4 - 4
src/compiler/args.ml

@@ -111,9 +111,9 @@ let parse_args com =
 		),"<name[=path]>","generate code for a custom target");
 		),"<name[=path]>","generate code for a custom target");
 		("Target",[],["-x"], Arg.String (fun cl ->
 		("Target",[],["-x"], Arg.String (fun cl ->
 			let cpath = Path.parse_type_path cl in
 			let cpath = Path.parse_type_path cl in
-			(match com.main_class with
+			(match com.main.main_class with
 				| Some c -> if cpath <> c then raise (Arg.Bad "Multiple --main classes specified")
 				| Some c -> if cpath <> c then raise (Arg.Bad "Multiple --main classes specified")
-				| None -> com.main_class <- Some cpath);
+				| None -> com.main.main_class <- Some cpath);
 			actx.classes <- cpath :: actx.classes;
 			actx.classes <- cpath :: actx.classes;
 			Common.define com Define.Interp;
 			Common.define com Define.Interp;
 			set_platform com Eval "";
 			set_platform com Eval "";
@@ -138,9 +138,9 @@ let parse_args com =
 			actx.hxb_libs <- lib :: actx.hxb_libs
 			actx.hxb_libs <- lib :: actx.hxb_libs
 		),"<path>","add a hxb library");
 		),"<path>","add a hxb library");
 		("Compilation",["-m";"--main"],["-main"],Arg.String (fun cl ->
 		("Compilation",["-m";"--main"],["-main"],Arg.String (fun cl ->
-			if com.main_class <> None then raise (Arg.Bad "Multiple --main classes specified");
+			if com.main.main_class <> None then raise (Arg.Bad "Multiple --main classes specified");
 			let cpath = Path.parse_type_path cl in
 			let cpath = Path.parse_type_path cl in
-			com.main_class <- Some cpath;
+			com.main.main_class <- Some cpath;
 			actx.classes <- cpath :: actx.classes
 			actx.classes <- cpath :: actx.classes
 		),"<class>","select startup class");
 		),"<class>","select startup class");
 		("Compilation",["-L";"--library"],["-lib"],Arg.String (fun _ -> ()),"<name[:ver]>","use a haxelib library");
 		("Compilation",["-L";"--library"],["-lib"],Arg.String (fun _ -> ()),"<name[:ver]>","use a haxelib library");

+ 2 - 2
src/compiler/compiler.ml

@@ -336,7 +336,7 @@ let finalize_typing ctx tctx =
 	enter_stage com CFilteringStart;
 	enter_stage com CFilteringStart;
 	ServerMessage.compiler_stage com;
 	ServerMessage.compiler_stage com;
 	let main, types, modules = run_or_diagnose ctx (fun () -> Finalization.generate tctx) in
 	let main, types, modules = run_or_diagnose ctx (fun () -> Finalization.generate tctx) in
-	com.main <- main;
+	com.main.main_expr <- main;
 	com.types <- types;
 	com.types <- types;
 	com.modules <- modules;
 	com.modules <- modules;
 	t()
 	t()
@@ -344,7 +344,7 @@ let finalize_typing ctx tctx =
 let filter ctx tctx before_destruction =
 let filter ctx tctx before_destruction =
 	let t = Timer.timer ["filters"] in
 	let t = Timer.timer ["filters"] in
 	DeprecationCheck.run ctx.com;
 	DeprecationCheck.run ctx.com;
-	run_or_diagnose ctx (fun () -> Filters.run tctx ctx.com.main before_destruction);
+	run_or_diagnose ctx (fun () -> Filters.run tctx ctx.com.main.main_expr before_destruction);
 	t()
 	t()
 
 
 let compile ctx actx callbacks =
 let compile ctx actx callbacks =

+ 2 - 2
src/compiler/displayProcessing.ml

@@ -143,7 +143,7 @@ let process_display_file com actx =
 			DPKNone
 			DPKNone
 		| DFPOnly when (DisplayPosition.display_position#get).pfile = file_input_marker ->
 		| DFPOnly when (DisplayPosition.display_position#get).pfile = file_input_marker ->
 			actx.classes <- [];
 			actx.classes <- [];
-			com.main_class <- None;
+			com.main.main_class <- None;
 			begin match com.file_contents with
 			begin match com.file_contents with
 			| [_, Some input] ->
 			| [_, Some input] ->
 				com.file_contents <- [];
 				com.file_contents <- [];
@@ -154,7 +154,7 @@ let process_display_file com actx =
 		| dfp ->
 		| dfp ->
 			if dfp = DFPOnly then begin
 			if dfp = DFPOnly then begin
 				actx.classes <- [];
 				actx.classes <- [];
-				com.main_class <- None;
+				com.main.main_class <- None;
 			end;
 			end;
 			let real = Path.get_real_path (DisplayPosition.display_position#get).pfile in
 			let real = Path.get_real_path (DisplayPosition.display_position#get).pfile in
 			let path = match get_module_path_from_file_path com real with
 			let path = match get_module_path_from_file_path com real with

+ 16 - 7
src/context/common.ml

@@ -340,6 +340,11 @@ class virtual abstract_hxb_lib = object(self)
 	method virtual get_file_path : string
 	method virtual get_file_path : string
 end
 end
 
 
+type context_main = {
+	mutable main_class : path option;
+	mutable main_expr : texpr option;
+}
+
 type context = {
 type context = {
 	compilation_step : int;
 	compilation_step : int;
 	mutable stage : compiler_stage;
 	mutable stage : compiler_stage;
@@ -359,7 +364,7 @@ type context = {
 	mutable config : platform_config;
 	mutable config : platform_config;
 	empty_class_path : ClassPath.class_path;
 	empty_class_path : ClassPath.class_path;
 	class_paths : ClassPaths.class_paths;
 	class_paths : ClassPaths.class_paths;
-	mutable main_class : path option;
+	main : context_main;
 	mutable package_rules : (string,package_rule) PMap.t;
 	mutable package_rules : (string,package_rule) PMap.t;
 	mutable report_mode : report_mode;
 	mutable report_mode : report_mode;
 	(* communication *)
 	(* communication *)
@@ -400,7 +405,6 @@ type context = {
 	mutable file : string;
 	mutable file : string;
 	mutable features : (string,bool) Hashtbl.t;
 	mutable features : (string,bool) Hashtbl.t;
 	mutable modules : Type.module_def list;
 	mutable modules : Type.module_def list;
-	mutable main : Type.texpr option;
 	mutable types : Type.module_type list;
 	mutable types : Type.module_type list;
 	mutable resources : (string,string) Hashtbl.t;
 	mutable resources : (string,string) Hashtbl.t;
 	(* target-specific *)
 	(* target-specific *)
@@ -819,7 +823,10 @@ let create compilation_step cs version args display_mode =
 		run_command_args = (fun s args -> com.run_command (Printf.sprintf "%s %s" s (String.concat " " args)));
 		run_command_args = (fun s args -> com.run_command (Printf.sprintf "%s %s" s (String.concat " " args)));
 		empty_class_path = new ClassPath.directory_class_path "" User;
 		empty_class_path = new ClassPath.directory_class_path "" User;
 		class_paths = new ClassPaths.class_paths;
 		class_paths = new ClassPaths.class_paths;
-		main_class = None;
+		main = {
+			main_class = None;
+			main_expr = None;
+		};
 		package_rules = PMap.empty;
 		package_rules = PMap.empty;
 		file = "";
 		file = "";
 		types = [];
 		types = [];
@@ -828,7 +835,6 @@ let create compilation_step cs version args display_mode =
 		modules = [];
 		modules = [];
 		module_lut = new module_lut;
 		module_lut = new module_lut;
 		module_nonexistent_lut = new hashtbl_lookup;
 		module_nonexistent_lut = new hashtbl_lookup;
-		main = None;
 		flash_version = 10.;
 		flash_version = 10.;
 		resources = Hashtbl.create 0;
 		resources = Hashtbl.create 0;
 		net_std = [];
 		net_std = [];
@@ -907,7 +913,10 @@ let clone com is_macro_context =
 			tbool = mk_mono();
 			tbool = mk_mono();
 			tstring = mk_mono();
 			tstring = mk_mono();
 		};
 		};
-		main_class = None;
+		main = {
+			main_class = None;
+			main_expr = None;
+		};
 		features = Hashtbl.create 0;
 		features = Hashtbl.create 0;
 		callbacks = new compiler_callbacks;
 		callbacks = new compiler_callbacks;
 		display_information = {
 		display_information = {
@@ -1231,6 +1240,6 @@ let get_entry_point com =
 			| Some c when (PMap.mem "main" c.cl_statics) -> c
 			| Some c when (PMap.mem "main" c.cl_statics) -> c
 			| _ -> Option.get (ExtList.List.find_map (fun t -> match t with TClassDecl c when c.cl_path = path -> Some c | _ -> None) m.m_types)
 			| _ -> Option.get (ExtList.List.find_map (fun t -> match t with TClassDecl c when c.cl_path = path -> Some c | _ -> None) m.m_types)
 		in
 		in
-		let e = Option.get com.main in (* must be present at this point *)
+		let e = Option.get com.main.main_expr in (* must be present at this point *)
 		(snd path, c, e)
 		(snd path, c, e)
-	) com.main_class
+	) com.main.main_class

+ 3 - 3
src/generators/gencpp.ml

@@ -8478,7 +8478,7 @@ let generate_cppia ctx =
       );
       );
    ) common_ctx.types;
    ) common_ctx.types;
 
 
-   (match common_ctx.main with
+   (match common_ctx.main.main_expr with
    | None -> script#writeOpLine IaNoMain;
    | None -> script#writeOpLine IaNoMain;
    | Some e -> script#writeOpLine IaMain;
    | Some e -> script#writeOpLine IaMain;
          script#gen_expression e
          script#gen_expression e
@@ -8590,7 +8590,7 @@ let generate_source ctx =
    List.iter (fun job -> job () ) !jobs;
    List.iter (fun job -> job () ) !jobs;
 
 
 
 
-   (match common_ctx.main with
+   (match common_ctx.main.main_expr with
    | None -> generate_dummy_main common_ctx
    | None -> generate_dummy_main common_ctx
    | Some e ->
    | Some e ->
       let main_field = { (mk_field "__main__" t_dynamic e.epos null_pos) with
       let main_field = { (mk_field "__main__" t_dynamic e.epos null_pos) with
@@ -8653,7 +8653,7 @@ let generate_source ctx =
      end;
      end;
    end;
    end;
 
 
-   let output_name = match  common_ctx.main_class with
+   let output_name = match  common_ctx.main.main_class with
    | Some path -> (snd path)
    | Some path -> (snd path)
    | _ -> "output" in
    | _ -> "output" in
 
 

+ 1 - 1
src/generators/genhl.ml

@@ -4187,7 +4187,7 @@ let generate com =
 
 
 	let ctx = create_context com false dump in
 	let ctx = create_context com false dump in
 	add_types ctx com.types;
 	add_types ctx com.types;
-	let code = build_code ctx com.types com.main in
+	let code = build_code ctx com.types com.main.main_expr in
 	Array.sort (fun (lib1,_,_,_) (lib2,_,_,_) -> lib1 - lib2) code.natives;
 	Array.sort (fun (lib1,_,_,_) (lib2,_,_,_) -> lib1 - lib2) code.natives;
 	if dump then begin
 	if dump then begin
 		(match ctx.dump_out with None -> () | Some ch -> IO.close_out ch);
 		(match ctx.dump_out with None -> () | Some ch -> IO.close_out ch);

+ 1 - 1
src/generators/genjs.ml

@@ -1970,7 +1970,7 @@ let generate com =
 	end;
 	end;
 	List.iter (gen_block_element ~newline_after:true ~keep_blocks:(ctx.es_version >= 6) ctx) (List.rev ctx.inits);
 	List.iter (gen_block_element ~newline_after:true ~keep_blocks:(ctx.es_version >= 6) ctx) (List.rev ctx.inits);
 	List.iter (generate_static ctx) (List.rev ctx.statics);
 	List.iter (generate_static ctx) (List.rev ctx.statics);
-	(match com.main with
+	(match com.main.main_expr with
 	| None -> ()
 	| None -> ()
 	| Some e -> gen_expr ctx e; newline ctx);
 	| Some e -> gen_expr ctx e; newline ctx);
 	if ctx.js_modern then begin
 	if ctx.js_modern then begin

+ 1 - 1
src/generators/genlua.ml

@@ -2200,7 +2200,7 @@ let generate com =
             gen_value ctx { e with eexpr = TFunction fn; etype = TFun ([],com.basic.tvoid) };
             gen_value ctx { e with eexpr = TFunction fn; etype = TFun ([],com.basic.tvoid) };
         println ctx ", _hx_handle_error)";
         println ctx ", _hx_handle_error)";
         println ctx "if not success then _G.error(err) end";
         println ctx "if not success then _G.error(err) end";
-    ) com.main;
+    ) com.main.main_expr;
 
 
     if anyExposed then
     if anyExposed then
         println ctx "return _hx_exports";
         println ctx "return _hx_exports";

+ 1 - 1
src/generators/genneko.ml

@@ -780,7 +780,7 @@ let generate com =
 		{ psource = "<header>"; pline = 1; }
 		{ psource = "<header>"; pline = 1; }
 	) in
 	) in
 	let el = build ctx com.types in
 	let el = build ctx com.types in
-	let emain = (match com.main with None -> [] | Some e -> [gen_expr ctx e]) in
+	let emain = (match com.main.main_expr with None -> [] | Some e -> [gen_expr ctx e]) in
 	let e = (EBlock ((header()) @ libs :: el @ emain), null_pos) in
 	let e = (EBlock ((header()) @ libs :: el @ emain), null_pos) in
 	let source = Common.defined com Define.NekoSource in
 	let source = Common.defined com Define.NekoSource in
 	let use_nekoc = Common.defined com Define.UseNekoc in
 	let use_nekoc = Common.defined com Define.UseNekoc in

+ 1 - 1
src/generators/genphp7.ml

@@ -4038,7 +4038,7 @@ class generator (ctx:php_generator_context) =
 			Returns PHP code for entry point
 			Returns PHP code for entry point
 		*)
 		*)
 		method private get_entry_point : (string * string) option =
 		method private get_entry_point : (string * string) option =
-			match ctx.pgc_common.main with
+			match ctx.pgc_common.main.main_expr with
 				| None -> None
 				| None -> None
 				| Some expr ->
 				| Some expr ->
 					let writer = new code_writer ctx ([], "") "" in
 					let writer = new code_writer ctx ([], "") "" in

+ 1 - 1
src/generators/genpy.ml

@@ -2410,7 +2410,7 @@ module Generator = struct
 		List.iter (fun f -> f()) (List.rev ctx.class_inits)
 		List.iter (fun f -> f()) (List.rev ctx.class_inits)
 
 
 	let gen_main ctx =
 	let gen_main ctx =
-		match ctx.com.main with
+		match ctx.com.main.main_expr with
 			| None ->
 			| None ->
 				()
 				()
 			| Some e ->
 			| Some e ->

+ 2 - 2
src/generators/genswf9.ml

@@ -2007,7 +2007,7 @@ let generate_inits ctx =
 			j()
 			j()
 		| _ -> ()
 		| _ -> ()
 	) ctx.com.types;
 	) ctx.com.types;
-	(match ctx.com.main with
+	(match ctx.com.main.main_expr with
 	| None -> ()
 	| None -> ()
 	| Some e -> gen_expr ctx false e);
 	| Some e -> gen_expr ctx false e);
 	write ctx HRetVoid;
 	write ctx HRetVoid;
@@ -2888,7 +2888,7 @@ let generate com boot_name =
 		try_scope_reg = None;
 		try_scope_reg = None;
 		for_call = false;
 		for_call = false;
 	} in
 	} in
-	let types = if ctx.swc && com.main_class = None then
+	let types = if ctx.swc && com.main.main_class = None then
 		(*
 		(*
 			make sure that both Boot and RealBoot are the first two classes in the SWC
 			make sure that both Boot and RealBoot are the first two classes in the SWC
 			this way initializing RealBoot will also run externs __init__ blocks before
 			this way initializing RealBoot will also run externs __init__ blocks before

+ 1 - 1
src/macro/eval/evalStdLib.ml

@@ -2632,7 +2632,7 @@ module StdSys = struct
 	let programPath = vfun0 (fun () ->
 	let programPath = vfun0 (fun () ->
 		let ctx = get_ctx() in
 		let ctx = get_ctx() in
 		let com = ctx.curapi.get_com() in
 		let com = ctx.curapi.get_com() in
-		match com.main_class with
+		match com.main.main_class with
 		| None -> vnull
 		| None -> vnull
 		| Some p ->
 		| Some p ->
 			match ctx.curapi.get_type (s_type_path p) with
 			match ctx.curapi.get_type (s_type_path p) with

+ 3 - 3
src/macro/macroApi.ml

@@ -2021,7 +2021,7 @@ let macro_api ccom get_api =
 				let api = encode_obj [
 				let api = encode_obj [
 					"outputFile", encode_string com.file;
 					"outputFile", encode_string com.file;
 					"types", encode_array (List.map (fun t -> encode_type (type_of_module_type t)) com.types);
 					"types", encode_array (List.map (fun t -> encode_type (type_of_module_type t)) com.types);
-					"main", (match com.main with None -> vnull | Some e -> encode_texpr e);
+					"main", (match com.main.main_expr with None -> vnull | Some e -> encode_texpr e);
 					"generateValue", vfun1 (fun v ->
 					"generateValue", vfun1 (fun v ->
 						let e = decode_texpr v in
 						let e = decode_texpr v in
 						let str = Genjs.gen_single_expr js_ctx e false in
 						let str = Genjs.gen_single_expr js_ctx e false in
@@ -2253,7 +2253,7 @@ let macro_api ccom get_api =
 				"platform", encode_platform com.platform;
 				"platform", encode_platform com.platform;
 				"platformConfig", encode_platform_config com.config;
 				"platformConfig", encode_platform_config com.config;
 				"stdPath", encode_array (List.map (fun path -> encode_string path#path) com.class_paths#get_std_paths);
 				"stdPath", encode_array (List.map (fun path -> encode_string path#path) com.class_paths#get_std_paths);
-				"mainClass", (match com.main_class with None -> vnull | Some path -> encode_path path);
+				"mainClass", (match com.main.main_class with None -> vnull | Some path -> encode_path path);
 				"packageRules", encode_string_map encode_package_rule com.package_rules;
 				"packageRules", encode_string_map encode_package_rule com.package_rules;
 			]
 			]
 		);
 		);
@@ -2262,7 +2262,7 @@ let macro_api ccom get_api =
 			vnull
 			vnull
 		);
 		);
 		"get_main_expr", vfun0 (fun() ->
 		"get_main_expr", vfun0 (fun() ->
-			match (ccom()).main with None -> vnull | Some e -> encode_texpr e
+			match (ccom()).main.main_expr with None -> vnull | Some e -> encode_texpr e
 		);
 		);
 		"get_module_types", vfun0 (fun() ->
 		"get_module_types", vfun0 (fun() ->
 			encode_array (List.map encode_module_type (ccom()).types)
 			encode_array (List.map encode_module_type (ccom()).types)

+ 1 - 1
src/typing/finalization.ml

@@ -9,7 +9,7 @@ open Typecore
 (* FINALIZATION *)
 (* FINALIZATION *)
 
 
 let get_main ctx types =
 let get_main ctx types =
-	match ctx.com.main_class with
+	match ctx.com.main.main_class with
 	| None -> None
 	| None -> None
 	| Some path ->
 	| Some path ->
 		let p = null_pos in
 		let p = null_pos in

+ 1 - 2
src/typing/macroContext.ml

@@ -702,7 +702,6 @@ let create_macro_context com =
 	let com2 = Common.clone com true in
 	let com2 = Common.clone com true in
 	com.get_macros <- (fun() -> Some com2);
 	com.get_macros <- (fun() -> Some com2);
 	com2.package_rules <- PMap.empty;
 	com2.package_rules <- PMap.empty;
-	com2.main_class <- None;
 	(* Inherit most display settings, but require normal typing. *)
 	(* Inherit most display settings, but require normal typing. *)
 	com2.display <- {com.display with dms_kind = DMNone; dms_full_typing = true; dms_force_macro_typing = true; dms_inline = true; };
 	com2.display <- {com.display with dms_kind = DMNone; dms_full_typing = true; dms_force_macro_typing = true; dms_inline = true; };
 	com2.class_paths#lock_context "macro" false;
 	com2.class_paths#lock_context "macro" false;
@@ -1070,7 +1069,7 @@ let interpret ctx =
 	let mctx = get_macro_context ctx in
 	let mctx = get_macro_context ctx in
 	let mctx = Interp.create ctx.com (make_macro_api ctx mctx null_pos) false in
 	let mctx = Interp.create ctx.com (make_macro_api ctx mctx null_pos) false in
 	Interp.add_types mctx ctx.com.types (fun t -> ());
 	Interp.add_types mctx ctx.com.types (fun t -> ());
-	match ctx.com.main with
+	match ctx.com.main.main_expr with
 		| None -> ()
 		| None -> ()
 		| Some e -> ignore(Interp.eval_expr mctx e)
 		| Some e -> ignore(Interp.eval_expr mctx e)