Merge pull request #299 from Octachron/fixes_for_4.09

Fixes for 4.09
This commit is contained in:
Anil Madhavapeddy 2019-09-16 16:20:05 +01:00 committed by GitHub
commit 53eca3491a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 15 deletions

View File

@ -625,13 +625,23 @@ let bind_expressions name phrase =
let execute_phrase = let execute_phrase =
let new_cmis = ref []in let new_cmis = ref []in
let default_load = !Env.Persistent_signature.load in let default_load =
#if OCAML_VERSION >= (4, 09, 0)
!Persistent_env.Persistent_signature.load
#else
!Env.Persistent_signature.load
#endif
in
let load ~unit_name = let load ~unit_name =
let res = default_load ~unit_name in let res = default_load ~unit_name in
(match res with None -> () | Some x -> new_cmis := x.cmi :: !new_cmis); (match res with None -> () | Some x -> new_cmis := x.cmi :: !new_cmis);
res res
in in
#if OCAML_VERSION >= (4, 09, 0)
Persistent_env.Persistent_signature.load := load;
#else
Env.Persistent_signature.load := load; Env.Persistent_signature.load := load;
#endif
let rec collect_printers path signature acc = let rec collect_printers path signature acc =
List.fold_left (fun acc item -> List.fold_left (fun acc item ->
@ -1274,14 +1284,28 @@ let prepare () =
Format.eprintf "Uncaught exception: %s\n" (Printexc.to_string exn); Format.eprintf "Uncaught exception: %s\n" (Printexc.to_string exn);
false false
#if OCAML_VERSION >= (4, 09, 0)
external caml_sys_modify_argv : string array -> unit =
"caml_sys_modify_argv"
let override_argv () =
let len = Array.length Sys.argv - !Arg.current in
let copy = Array.init len (fun i -> Sys.argv.(i+ !Arg.current)) in
caml_sys_modify_argv copy;
Arg.current := 0
#else
let override_argv () =
let len = Array.length Sys.argv - !Arg.current in
Array.blit Sys.argv !Arg.current Sys.argv 0 len;
Obj.truncate (Obj.repr Sys.argv) len;
Arg.current := 0
#endif
let run_script name = let run_script name =
(* To prevent message from camlp4 *) (* To prevent message from camlp4 *)
Sys.interactive := false; Sys.interactive := false;
if not (prepare ()) then exit 2; if not (prepare ()) then exit 2;
let len = Array.length Sys.argv - !Arg.current in override_argv ();
Array.blit Sys.argv !Arg.current Sys.argv 0 len;
Obj.truncate (Obj.repr Sys.argv) len;
Arg.current := 0;
Toploop.initialize_toplevel_env (); Toploop.initialize_toplevel_env ();
Location.input_name := UTop.input_name; Location.input_name := UTop.input_name;
if Toploop.use_silently Format.err_formatter name then if Toploop.use_silently Format.err_formatter name then
@ -1540,11 +1564,7 @@ let interact ?(search_path=[]) ?(build_dir="_build") ~unit ~loc:(fname, lnum, cn
Printf.ksprintf failwith "%s.cmt not found in search path!" unit Printf.ksprintf failwith "%s.cmt not found in search path!" unit
in in
let cmt_infos = Cmt_format.read_cmt cmt_fname in let cmt_infos = Cmt_format.read_cmt cmt_fname in
let module Search = let expr next (e : Typedtree.expression) =
TypedtreeIter.MakeIterator(struct
include TypedtreeIter.DefaultIteratorArgument
let enter_expression (e : Typedtree.expression) =
match e.exp_desc with match e.exp_desc with
| Texp_apply (_, args) -> begin | Texp_apply (_, args) -> begin
try try
@ -1557,14 +1577,28 @@ let interact ?(search_path=[]) ?(build_dir="_build") ~unit ~loc:(fname, lnum, cn
pos.pos_lnum = lnum && pos.pos_lnum = lnum &&
pos.pos_cnum - pos.pos_bol = cnum then pos.pos_cnum - pos.pos_bol = cnum then
raise (Found v.exp_env) raise (Found v.exp_env)
| _ -> () | _ -> next e
with Not_found -> () with Not_found -> next e
end end
| _ -> () | _ -> next e
in
#if OCAML_VERSION >= (4,09,0)
let next iterator e = Tast_iterator.default_iterator.expr iterator e in
let expr iterator = expr (next iterator) in
let iter = { Tast_iterator.default_iterator with expr } in
let search = iter.structure iter in
#else
let module Search =
TypedtreeIter.MakeIterator(struct
include TypedtreeIter.DefaultIteratorArgument
let enter_expression = expr ignore
end) in end) in
let search = Search.iter_structure in
#endif
try try
begin match cmt_infos.cmt_annots with begin match cmt_infos.cmt_annots with
| Implementation st -> Search.iter_structure st | Implementation st -> search st
| _ -> () | _ -> ()
end; end;
failwith "Couldn't find location in cmt file" failwith "Couldn't find location in cmt file"