Browse Source

[typer] change how we initialize basic types

Simon Krajewski 1 year ago
parent
commit
122ea09563
2 changed files with 29 additions and 12 deletions
  1. 11 7
      src/context/common.ml
  2. 18 5
      src/typing/typerEntry.ml

+ 11 - 7
src/context/common.ml

@@ -781,7 +781,6 @@ let get_config com =
 let memory_marker = [|Unix.time()|]
 let memory_marker = [|Unix.time()|]
 
 
 let create compilation_step cs version args display_mode =
 let create compilation_step cs version args display_mode =
-	let m = Type.mk_mono() in
 	let rec com = {
 	let rec com = {
 		compilation_step = compilation_step;
 		compilation_step = compilation_step;
 		cs = cs;
 		cs = cs;
@@ -848,12 +847,12 @@ let create compilation_step cs version args display_mode =
 		filter_messages = (fun _ -> ());
 		filter_messages = (fun _ -> ());
 		pass_debug_messages = DynArray.create();
 		pass_debug_messages = DynArray.create();
 		basic = {
 		basic = {
-			tvoid = m;
-			tint = m;
-			tfloat = m;
-			tbool = m;
+			tvoid = mk_mono();
+			tint = mk_mono();
+			tfloat = mk_mono();
+			tbool = mk_mono();
+			tstring = mk_mono();
 			tnull = (fun _ -> die "Could use locate abstract Null<T> (was it redefined?)" __LOC__);
 			tnull = (fun _ -> die "Could use locate abstract Null<T> (was it redefined?)" __LOC__);
-			tstring = m;
 			tarray = (fun _ -> die "Could not locate class Array<T> (was it redefined?)" __LOC__);
 			tarray = (fun _ -> die "Could not locate class Array<T> (was it redefined?)" __LOC__);
 		};
 		};
 		file_lookup_cache = new hashtbl_lookup;
 		file_lookup_cache = new hashtbl_lookup;
@@ -889,7 +888,12 @@ let clone com is_macro_context =
 	let t = com.basic in
 	let t = com.basic in
 	{ com with
 	{ com with
 		cache = None;
 		cache = None;
-		basic = { t with tvoid = t.tvoid };
+		basic = { t with
+			tint = mk_mono();
+			tfloat = mk_mono();
+			tbool = mk_mono();
+			tstring = mk_mono();
+		};
 		main_class = None;
 		main_class = None;
 		features = Hashtbl.create 0;
 		features = Hashtbl.create 0;
 		callbacks = new compiler_callbacks;
 		callbacks = new compiler_callbacks;

+ 18 - 5
src/typing/typerEntry.ml

@@ -92,10 +92,20 @@ let create com macros =
 		| TAbstractDecl a ->
 		| TAbstractDecl a ->
 			(match snd a.a_path with
 			(match snd a.a_path with
 			| "Void" -> ctx.t.tvoid <- TAbstract (a,[]);
 			| "Void" -> ctx.t.tvoid <- TAbstract (a,[]);
-			| "Float" -> ctx.t.tfloat <- TAbstract (a,[]);
-			| "Int" -> ctx.t.tint <- TAbstract (a,[])
-			| "Bool" -> ctx.t.tbool <- TAbstract (a,[])
-			| "Dynamic" -> t_dynamic_def := TAbstract(a,extract_param_types a.a_params);
+			| "Float" ->
+				let t = (TAbstract (a,[])) in
+				Type.unify t ctx.t.tfloat;
+				ctx.t.tfloat <- t
+			| "Int" ->
+				let t = (TAbstract (a,[])) in
+				Type.unify t ctx.t.tint;
+				ctx.t.tint <- t
+			| "Bool" ->
+				let t = (TAbstract (a,[])) in
+				Type.unify t ctx.t.tbool;
+				ctx.t.tbool <- t
+			| "Dynamic" ->
+				t_dynamic_def := TAbstract(a,extract_param_types a.a_params);
 			| "Null" ->
 			| "Null" ->
 				let mk_null t =
 				let mk_null t =
 					try
 					try
@@ -117,7 +127,10 @@ let create com macros =
 	) ctx.g.std_types.m_types;
 	) ctx.g.std_types.m_types;
 	let m = TypeloadModule.load_module ctx ([],"String") null_pos in
 	let m = TypeloadModule.load_module ctx ([],"String") null_pos in
 	List.iter (fun mt -> match mt with
 	List.iter (fun mt -> match mt with
-		| TClassDecl c -> ctx.t.tstring <- TInst (c,[])
+		| TClassDecl c ->
+			let t = (TInst (c,[])) in
+			Type.unify t ctx.t.tstring;
+			ctx.t.tstring <- t
 		| _ -> ()
 		| _ -> ()
 	) m.m_types;
 	) m.m_types;
 	let m = TypeloadModule.load_module ctx ([],"Std") null_pos in
 	let m = TypeloadModule.load_module ctx ([],"Std") null_pos in