Browse Source

allow storing type parameters in get_build_infos

Simon Krajewski 11 years ago
parent
commit
7797e9fda9
3 changed files with 9 additions and 9 deletions
  1. 1 1
      typecore.ml
  2. 1 1
      typeload.ml
  3. 7 7
      typer.ml

+ 1 - 1
typecore.ml

@@ -67,7 +67,7 @@ type typer_globals = {
 	mutable std : module_def;
 	mutable std : module_def;
 	mutable hook_generate : (unit -> unit) list;
 	mutable hook_generate : (unit -> unit) list;
 	type_patches : (path, (string * bool, type_patch) Hashtbl.t * type_patch) Hashtbl.t;
 	type_patches : (path, (string * bool, type_patch) Hashtbl.t * type_patch) Hashtbl.t;
-	mutable get_build_infos : unit -> (module_type * Ast.class_field list) option;
+	mutable get_build_infos : unit -> (module_type * t list * Ast.class_field list) option;
 	delayed_macros : (unit -> unit) DynArray.t;
 	delayed_macros : (unit -> unit) DynArray.t;
 	mutable global_using : tclass list;
 	mutable global_using : tclass list;
 	(* api *)
 	(* api *)

+ 1 - 1
typeload.ml

@@ -1420,7 +1420,7 @@ let build_module_def ctx mt meta fvars context_init fbuild =
 			let s = try String.concat "." (List.rev (string_list_of_expr_path epath)) with Error (_,p) -> error "Build call parameter must be a class path" p in
 			let s = try String.concat "." (List.rev (string_list_of_expr_path epath)) with Error (_,p) -> error "Build call parameter must be a class path" p in
 			if ctx.in_macro then error "You cannot use @:build inside a macro : make sure that your enum is not used in macro" p;
 			if ctx.in_macro then error "You cannot use @:build inside a macro : make sure that your enum is not used in macro" p;
 			let old = ctx.g.get_build_infos in
 			let old = ctx.g.get_build_infos in
-			ctx.g.get_build_infos <- (fun() -> Some (mt, fvars()));
+			ctx.g.get_build_infos <- (fun() -> Some (mt, List.map snd (t_infos mt).mt_types, fvars()));
 			context_init();
 			context_init();
 			let r = try apply_macro ctx MBuild s el p with e -> ctx.g.get_build_infos <- old; raise e in
 			let r = try apply_macro ctx MBuild s el p with e -> ctx.g.get_build_infos <- old; raise e in
 			ctx.g.get_build_infos <- old;
 			ctx.g.get_build_infos <- old;

+ 7 - 7
typer.ml

@@ -3801,12 +3801,12 @@ let make_macro_api ctx p =
 		);
 		);
 		Interp.get_local_type = (fun() ->
 		Interp.get_local_type = (fun() ->
 			match ctx.g.get_build_infos() with
 			match ctx.g.get_build_infos() with
-			| Some (mt,_) ->
+			| Some (mt,tl,_) ->
 				Some (match mt with
 				Some (match mt with
-					| TClassDecl c -> TInst (c,List.map snd c.cl_types)
-					| TEnumDecl e -> TEnum (e,List.map snd e.e_types)
-					| TTypeDecl t -> TType (t,List.map snd t.t_types)
-					| TAbstractDecl a -> TAbstract(a,List.map snd a.a_types))
+					| TClassDecl c -> TInst (c,tl)
+					| TEnumDecl e -> TEnum (e,tl)
+					| TTypeDecl t -> TType (t,tl)
+					| TAbstractDecl a -> TAbstract(a,tl))
 			| None ->
 			| None ->
 				if ctx.curclass == null_class then
 				if ctx.curclass == null_class then
 					None
 					None
@@ -3830,7 +3830,7 @@ let make_macro_api ctx p =
 		Interp.get_build_fields = (fun() ->
 		Interp.get_build_fields = (fun() ->
 			match ctx.g.get_build_infos() with
 			match ctx.g.get_build_infos() with
 			| None -> Interp.VNull
 			| None -> Interp.VNull
-			| Some (_,fields) -> Interp.enc_array (List.map Interp.encode_field fields)
+			| Some (_,_,fields) -> Interp.enc_array (List.map Interp.encode_field fields)
 		);
 		);
 		Interp.get_pattern_locals = (fun e t ->
 		Interp.get_pattern_locals = (fun e t ->
 			!get_pattern_locals_ref ctx e t
 			!get_pattern_locals_ref ctx e t
@@ -4120,7 +4120,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 						| Interp.VNull ->
 						| Interp.VNull ->
 							(match ctx.g.get_build_infos() with
 							(match ctx.g.get_build_infos() with
 							| None -> assert false
 							| None -> assert false
-							| Some (_,fields) -> fields)
+							| Some (_,_,fields) -> fields)
 						| _ ->
 						| _ ->
 							List.map Interp.decode_field (Interp.dec_array v)
 							List.map Interp.decode_field (Interp.dec_array v)
 					) in
 					) in