浏览代码

added follow-once

Nicolas Cannasse 14 年之前
父节点
当前提交
1b3672b9a0
共有 2 个文件被更改,包括 18 次插入4 次删除
  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
 			| 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
 	**/
-	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);
 	}
 	
 	/**