فهرست منبع

removed EMacro, moved reification to parser

Nicolas Cannasse 13 سال پیش
والد
کامیت
8ad09dad41
5فایلهای تغییر یافته به همراه9 افزوده شده و 15 حذف شده
  1. 0 4
      ast.ml
  2. 1 5
      interp.ml
  3. 8 2
      parser.ml
  4. 0 1
      std/haxe/macro/Expr.hx
  5. 0 3
      typer.ml

+ 0 - 4
ast.ml

@@ -193,7 +193,6 @@ and expr_def =
 	| EDisplayNew of type_path
 	| ETernary of expr * expr * expr
 	| ECheckType of expr * complex_type
-	| EMacro of expr
 
 and expr = expr_def * pos
 
@@ -517,7 +516,6 @@ let map_expr loop (e,p) =
 	| EDisplayNew t -> EDisplayNew (tpath t)
 	| ETernary (e1,e2,e3) -> ETernary (loop e1,loop e2,loop e3)
 	| ECheckType (e,t) -> ECheckType (loop e, ctype t)
-	| EMacro e -> EMacro (loop e)
 	) in
 	(e,p)
 
@@ -768,7 +766,5 @@ let expr_to_value in_macro e =
 			expr "ETernary" [loop e1;loop e2;loop e3]
 		| ECheckType (e1,ct) ->
 			expr "ECheckType" [loop e1; to_ctype ct p]
-		| EMacro e ->
-			expr "EMacro" [loop e]
 	in
 	to_expr e (snd e)

+ 1 - 5
interp.ml

@@ -3511,8 +3511,6 @@ and encode_expr e =
 				27, [loop econd;loop e1;loop e2]
 			| ECheckType (e,t) ->
 				28, [loop e; encode_type t]
-			| EMacro e ->
-				29, [loop e]
 		in
 		enc_obj [
 			"pos", encode_pos p;
@@ -3761,9 +3759,7 @@ let decode_expr v =
 			ETernary (loop e1,loop e2,loop e3)
 		| 28, [e;t] ->
 			ECheckType (loop e, decode_ctype t)
-		| 29, [e] ->
-			EMacro (loop e)
-		| 30, [e;f] ->
+		| 29, [e;f] ->
 			EField (loop e, dec_string f) (*** deprecated EType, keep until haxe 3 **)
 		| _ ->
 			raise Invalid_expr

+ 8 - 2
parser.ml

@@ -62,6 +62,7 @@ let cache = ref (DynArray.create())
 let doc = ref None
 let use_doc = ref false
 let resume_display = ref null_pos
+let in_macro = ref false
 
 let last_token s =
 	let n = Stream.count s in
@@ -619,9 +620,13 @@ and expr = parser
 	| [< '(Const (Ident "macro"),p); s >] ->
 		(match Stream.npeek 1 s with
 		| [(_,p2)] when p2.pmin > p.pmax ->
+			let reify e =
+				let e = expr_to_value !in_macro e in
+				(ECheckType (e,(CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = None; tparams = [] })),pos e)
+			in
 			(match s with parser
-			| [< '(Kwd Var,p1); vl = psep Comma parse_var_decl >] -> (EMacro (EVars vl,p1),punion p p1)
-			| [< e = expr >] -> (EMacro e,punion p (pos e))
+			| [< '(Kwd Var,p1); vl = psep Comma parse_var_decl >] -> reify (EVars vl,p1)
+			| [< e = expr >] -> reify e
 			| [< >] -> expr_next (EConst (Ident "macro"),p) s)
 		| _ ->
 			expr_next (EConst (Ident "macro"),p) s)
@@ -849,6 +854,7 @@ let parse ctx code =
 	let mstack = ref [] in
 	cache := DynArray.create();
 	doc := None;
+	in_macro := Common.defined ctx "macro";
 	Lexer.skip_header code;
 	let sraw = Stream.from (fun _ -> Some (Lexer.token code)) in
 	let rec next_token() = process_token (Lexer.token code)

+ 0 - 1
std/haxe/macro/Expr.hx

@@ -121,7 +121,6 @@ enum ExprDef {
 	EDisplayNew( t : TypePath );
 	ETernary( econd : Expr, eif : Expr, eelse : Expr );
 	ECheckType( e : Expr, t : ComplexType );
-	EMacro( e : Expr );
 	#if !haxe3
 	EType( e : Expr, field : String );
 	#end

+ 0 - 3
typer.ml

@@ -2153,9 +2153,6 @@ and type_expr ctx ?(need_val=true) (e,p) =
 		let e = type_expr_with_type ctx e (Some t) in
 		unify ctx e.etype t e.epos;
 		if e.etype == t then e else mk (TCast (e,None)) t p
-	| EMacro esub ->
-		let e = Ast.expr_to_value ctx.in_macro esub in
-		type_expr_with_type ctx e (Some (Typeload.load_complex_type ctx p (CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = None; tparams = [] })))
 
 and type_call ctx e el twith p =
 	match e, el with