Przeglądaj źródła

added follow-once

Nicolas Cannasse 14 lat temu
rodzic
commit
1b3672b9a0
2 zmienionych plików z 18 dodań i 4 usunięć
  1. 16 2
      interp.ml
  2. 2 2
      std/haxe/macro/Context.hx

+ 16 - 2
interp.ml

@@ -1713,8 +1713,22 @@ let macro_lib =
 			| None -> VNull
 			| None -> VNull
 			| Some c -> encode_type (TInst (c,[]))
 			| Some c -> encode_type (TInst (c,[]))
 		);
 		);
-		"follow", Fun1 (fun v ->
-			encode_type (follow (decode_type v))
+		"follow", Fun2 (fun v once ->
+			let t = decode_type v in
+			let follow_once t =
+				match t with
+				| TMono r ->
+					(match !r with
+					| None -> t
+					| Some t -> t)
+				| TEnum _ | TInst _ | TFun _ | TAnon _ | TDynamic _ ->
+					t
+				| TType (t,tl) ->
+					apply_params t.t_types tl t.t_type
+				| TLazy f ->
+					(!f)()
+			in
+			encode_type (match once with VNull | VBool false -> follow t | VBool true -> follow_once t | _ -> error())
 		);
 		);
 	]
 	]
 
 

+ 2 - 2
std/haxe/macro/Context.hx

@@ -134,8 +134,8 @@ class Context {
 	/**
 	/**
 		Follow all typedefs to reach the actual real type
 		Follow all typedefs to reach the actual real type
 	**/
 	**/
-	public static function follow( t : Type ) : Type {
-		return load("follow", 1)(t);
+	public static function follow( t : Type, ?once : Bool ) : Type {
+		return load("follow", 2)(t,once);
 	}
 	}
 	
 	
 	/**
 	/**