Browse Source

handle macro pos reification less awkwardly (#12155)

Simon Krajewski 4 months ago
parent
commit
84ba36809e
3 changed files with 15 additions and 22 deletions
  1. 2 5
      src/macro/eval/evalEmitter.ml
  2. 5 10
      src/macro/eval/evalJit.ml
  3. 8 7
      src/syntax/reification.ml

+ 2 - 5
src/macro/eval/evalEmitter.ml

@@ -127,11 +127,8 @@ let emit_array_declaration execs env =
 
 let emit_type_expr proto env = proto
 
-let emit_mk_pos exec1 exec2 exec3 env =
-	let file = exec1 env in
-	let min = exec2 env in
-	let max = exec3 env in
-	encode_pos { pfile = decode_string file; pmin = decode_int min; pmax = decode_int max }
+let emit_mk_pos p env =
+	encode_pos p
 
 let emit_enum_construction key i execs p env =
 	encode_enum_value key i (Array.map (apply env) execs) p

+ 5 - 10
src/macro/eval/evalJit.ml

@@ -495,16 +495,9 @@ and jit_expr jit return e =
 			| _ -> die "" __LOC__
 			end
 		| _ ->
-			match e1.eexpr,el with
-			| TIdent "$__mk_pos__",[file;min;max] ->
-				let exec1 = jit_expr jit false file in
-				let exec2 = jit_expr jit false min in
-				let exec3 = jit_expr jit false max in
-				emit_mk_pos exec1 exec2 exec3
-			| _ ->
-				let exec = jit_expr jit false e1 in
-				let execs = List.map (jit_expr jit false) el in
-				emit_call exec execs e.epos
+			let exec = jit_expr jit false e1 in
+			let execs = List.map (jit_expr jit false) el in
+			emit_call exec execs e.epos
 		end
 	| TNew({cl_path=[],"Array"},_,_) ->
 		emit_new_array
@@ -634,6 +627,8 @@ and jit_expr jit return e =
 	(* rewrites/skips *)
 	| TParenthesis e1 | TMeta(_,e1) | TCast(e1,None) ->
 		loop e1
+	| TIdent "$__mk_pos__" ->
+		emit_mk_pos e.epos
 	| TIdent s ->
 		Error.raise_typing_error ("Unknown identifier: " ^ s) e.epos
 	in

+ 8 - 7
src/syntax/reification.ml

@@ -231,13 +231,14 @@ let reify in_macro =
 		| Some p ->
 			p
 		| None ->
-		let file = (EConst (String(p.pfile,SDoubleQuotes)),p) in
-		let pmin = (EConst (Int ((string_of_int p.pmin), None)),p) in
-		let pmax = (EConst (Int ((string_of_int p.pmax), None)),p) in
-		if in_macro then
-			(EUntyped (ECall ((EConst (Ident "$__mk_pos__"),p),[file;pmin;pmax]),p),p)
-		else
-			to_obj [("file",file);("min",pmin);("max",pmax)] p
+			if in_macro then
+				(EUntyped (EConst (Ident "$__mk_pos__"),p),p)
+			else begin
+				let file = (EConst (String(p.pfile,SDoubleQuotes)),p) in
+				let pmin = (EConst (Int ((string_of_int p.pmin), None)),p) in
+				let pmax = (EConst (Int ((string_of_int p.pmax), None)),p) in
+				to_obj [("file",file);("min",pmin);("max",pmax)] p
+			end
 	and to_enc_pos p =
 		match !cur_pos with
 		| Some p -> p