浏览代码

[typer] (re)move some fields

Simon Krajewski 3 年之前
父节点
当前提交
9822022fc1
共有 6 个文件被更改,包括 22 次插入26 次删除
  1. 16 12
      src/context/common.ml
  2. 0 4
      src/context/typecore.ml
  3. 1 1
      src/typing/calls.ml
  4. 1 1
      src/typing/functionArguments.ml
  5. 4 4
      src/typing/macroContext.ml
  6. 0 4
      src/typing/typer.ml

+ 16 - 12
src/context/common.ml

@@ -294,12 +294,13 @@ type report_mode =
 type context = {
 	compilation_step : int;
 	mutable stage : compiler_stage;
+	cs : CompilationCache.t;
 	mutable cache : CompilationCache.context_cache option;
+	is_macro_context : bool;
+	mutable json_out : json_api option;
 	(* config *)
 	version : int;
 	args : string list;
-	shared : shared_context;
-	display_information : display_information;
 	mutable sys_args : string list;
 	mutable display : DisplayTypes.DisplayMode.settings;
 	mutable debug : bool;
@@ -311,18 +312,24 @@ type context = {
 	mutable class_path : string list;
 	mutable main_class : path option;
 	mutable package_rules : (string,package_rule) PMap.t;
+	mutable report_mode : report_mode;
+	(* communication *)
+	mutable print : string -> unit;
 	mutable error : string -> pos -> unit;
 	mutable info : string -> pos -> unit;
 	mutable warning : warning -> Warning.warning_option list list -> string -> pos -> unit;
 	mutable warning_options : Warning.warning_option list list;
 	mutable get_messages : unit -> compiler_message list;
 	mutable filter_messages : (compiler_message -> bool) -> unit;
+	mutable run_command : string -> int;
+	(* typing setup *)
 	mutable load_extern_type : (string * (path -> pos -> Ast.package option)) list; (* allow finding types which are not in sources *)
 	callbacks : compiler_callbacks;
 	defines : Define.define;
-	mutable print : string -> unit;
 	mutable get_macros : unit -> context option;
-	mutable run_command : string -> int;
+	(* typing state *)
+	shared : shared_context;
+	display_information : display_information;
 	file_lookup_cache : (string,string option) Hashtbl.t;
 	file_keys : file_keys;
 	readdir_cache : (string * string,(string array) option) Hashtbl.t;
@@ -333,17 +340,17 @@ type context = {
 	pass_debug_messages : string DynArray.t;
 	overload_cache : ((path * string),(Type.t * tclass_field) list) Hashtbl.t;
 	mutable has_error : bool;
-	mutable report_mode : report_mode;
+	module_lut : (path , module_def) Hashtbl.t;
+	type_to_module : (path, path) Hashtbl.t;
 	(* output *)
 	mutable file : string;
-	mutable flash_version : float;
 	mutable features : (string,bool) Hashtbl.t;
 	mutable modules : Type.module_def list;
-	module_lut : (path , module_def) Hashtbl.t;
-	type_to_module : (path, path) Hashtbl.t;
 	mutable main : Type.texpr option;
 	mutable types : Type.module_type list;
 	mutable resources : (string,string) Hashtbl.t;
+	(* target-specific *)
+	mutable flash_version : float;
 	mutable neko_libs : string list;
 	mutable include_files : (string * string) list;
 	mutable native_libs : native_libraries;
@@ -351,12 +358,9 @@ type context = {
 	net_path_map : (path,string list * string list * string) Hashtbl.t;
 	mutable c_args : string list;
 	mutable js_gen : (unit -> unit) option;
-	mutable json_out : json_api option;
-	is_macro_context : bool;
-	(* typing *)
+	(* misc *)
 	mutable basic : basic_types;
 	memory_marker : float array;
-	cs : CompilationCache.t;
 }
 
 exception Abort of string * pos

+ 0 - 4
src/context/typecore.ml

@@ -74,7 +74,6 @@ type typer_globals = {
 	mutable core_api : typer option;
 	mutable macros : ((unit -> unit) * typer) option;
 	mutable std : module_def;
-	mutable hook_generate : (unit -> unit) list;
 	type_patches : (path, (string * bool, type_patch) Hashtbl.t * type_patch) Hashtbl.t;
 	mutable global_metadata : (string list * metadata_entry * (bool * bool * bool)) list;
 	mutable module_check_policies : (string list * module_check_policy list * bool) list;
@@ -89,11 +88,8 @@ type typer_globals = {
 	do_load_macro : typer -> bool -> path -> string -> pos -> ((string * bool * t) list * t * tclass * Type.tclass_field);
 	do_load_module : typer -> path -> pos -> module_def;
 	do_load_type_def : typer -> pos -> type_path -> module_type;
-	do_optimize : typer -> texpr -> texpr;
 	do_build_instance : typer -> module_type -> pos -> (typed_type_param list * path * (t list -> t));
 	do_format_string : typer -> string -> pos -> Ast.expr;
-	do_finalize : typer -> unit;
-	do_generate : typer -> (texpr option * module_type list * module_def list);
 	do_load_core_class : typer -> tclass -> tclass;
 }
 

+ 1 - 1
src/typing/calls.ml

@@ -66,7 +66,7 @@ let make_call ctx e params t ?(force_inline=false) p =
 						typing_error ("Abstract 'this' value can only be modified inside an inline function. '" ^ f.cf_name ^ "' modifies 'this'") p;
 			| _ -> ()
 		);
-		let params = List.map (ctx.g.do_optimize ctx) params in
+		let params = List.map (Optimizer.reduce_expression ctx) params in
 		let force_inline = is_forced_inline cl f in
 		(match f.cf_expr_unoptimized,f.cf_expr with
 		| Some {eexpr = TFunction fd},_

+ 1 - 1
src/typing/functionArguments.ml

@@ -23,7 +23,7 @@ let type_function_arg_value ctx t c do_display =
 		| Some e ->
 			let p = pos e in
 			let e = if do_display then Display.ExprPreprocessing.process_expr ctx.com e else e in
-			let e = ctx.g.do_optimize ctx (type_expr ctx e (WithType.with_type t)) in
+			let e = Optimizer.reduce_expression ctx (type_expr ctx e (WithType.with_type t)) in
 			unify ctx e.etype t p;
 			let rec loop e = match e.eexpr with
 				| TConst _ -> Some e

+ 4 - 4
src/typing/macroContext.ml

@@ -421,8 +421,8 @@ let rec init_macro_interp ctx mctx mint =
 and flush_macro_context mint ctx =
 	let t = macro_timer ctx ["flush"] in
 	let mctx = (match ctx.g.macros with None -> die "" __LOC__ | Some (_,mctx) -> mctx) in
-	ctx.g.do_finalize mctx;
-	let _, types, modules = ctx.g.do_generate mctx in
+	Finalization.finalize mctx;
+	let _, types, modules = Finalization.generate mctx in
 	mctx.com.types <- types;
 	mctx.com.Common.modules <- modules;
 	(* we should maybe ensure that all filters in Main are applied. Not urgent atm *)
@@ -558,7 +558,7 @@ let load_macro' ctx display cpath f p =
 				match mloaded.m_statics with
 				| None -> raise Not_found
 				| Some c ->
-					mctx.g.do_finalize mctx;
+					Finalization.finalize mctx;
 					c, PMap.find f c.cl_statics
 			with Not_found ->
 				let name = Option.default (snd mpath) sub in
@@ -566,7 +566,7 @@ let load_macro' ctx display cpath f p =
 				let mt = try List.find (fun t2 -> (t_infos t2).mt_path = path) mloaded.m_types with Not_found -> raise_typing_error (Type_not_found (mloaded.m_path,name,Not_defined)) p in
 				match mt with
 				| TClassDecl c ->
-					mctx.g.do_finalize mctx;
+					Finalization.finalize mctx;
 					c, (try PMap.find f c.cl_statics with Not_found -> typing_error ("Method " ^ f ^ " not found on class " ^ s_type_path cpath) p)
 				| _ -> typing_error "Macro should be called on a class" p
 		in

+ 0 - 4
src/typing/typer.ml

@@ -1955,7 +1955,6 @@ let rec create com =
 			delayed = [];
 			debug_delayed = [];
 			doinline = com.display.dms_inline && not (Common.defined com Define.NoInline);
-			hook_generate = [];
 			std = null_module;
 			global_using = [];
 			complete = false;
@@ -1966,11 +1965,8 @@ let rec create com =
 			do_load_macro = MacroContext.load_macro';
 			do_load_module = TypeloadModule.load_module;
 			do_load_type_def = Typeload.load_type_def;
-			do_optimize = Optimizer.reduce_expression;
 			do_build_instance = InstanceBuilder.build_instance;
 			do_format_string = format_string;
-			do_finalize = Finalization.finalize;
-			do_generate = Finalization.generate;
 			do_load_core_class = Typeload.load_core_class;
 		};
 		m = {