Skip to content

Commit

Permalink
handle macro pos reification less awkwardly
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Dec 18, 2024
1 parent 5829dda commit 5e279ad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
7 changes: 2 additions & 5 deletions src/macro/eval/evalEmitter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions src/macro/eval/evalJit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -636,6 +629,8 @@ and jit_expr jit return e =
loop (Texpr.for_remap (ctx.curapi.MacroApi.get_com()).Common.basic v e1 e2 e.epos)
| 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
Expand Down
15 changes: 8 additions & 7 deletions src/syntax/reification.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e279ad

Please sign in to comment.