@@ -22,9 +22,10 @@ type args = {mode: mode}
2222exception LangException of string
2323
2424let _ =
25+ let interactive_mode = ref false in
26+ let eval_filepath = ref None in
2527 let quiet = ref false in
2628 let syntax = ref OCaml in
27− let interactive_mode = ref false in
2829 let print_mode = ref false in
2930 let run_mode = ref false in
3031 let ps1 = Sys.getenv_opt "PRYBAR_PS1" |> function | Some str -> str | None -> "#" in
@@ -36,7 +37,6 @@ let _ =
3637 | "ml" -> syntax := OCaml
3738 | arg -> raise (Arg.Bad ("Unknown syntax: " ^ arg))
3839 in
39− (*let string_of_syntax = function OCaml -> "ml" | Reason -> "re" in*)
4040 let print_mode_arg str =
4141 print_mode := true ;
4242 code := str
@@ -56,7 +56,11 @@ let _ =
5656 "OCaml / Reason repl script for prybar. Options available:"
5757 in
5858 Arg.parse speclist
59− (fun str -> print_endline ("Anonymous arg: " ^ str))
59+ (fun str ->
60+ match (str, !interactive_mode) with
61+ | (path, true) -> eval_filepath := Some(path)
62+ | _ -> print_endline ("Anonymous arg: " ^ str)
63+ )
6064 usage_msg ;
6165 let mode =
6266 match (!print_mode, !run_mode, !interactive_mode) with
@@ -95,6 +99,17 @@ let _ =
9599 len )
96100 else len
97101
102+ (* Minimal version of just running any input file, we stripped a lot of original logic
103+ * because we don't want to do any side effects on the compiler environment *)
104+ let run_script ppf name =
105+ let explicit_name =
106+ (* Prevent use_silently from searching in the path. *)
107+ if name <> "" && Filename.is_implicit name
108+ then Filename.concat Filename.current_dir_name name
109+ else name
110+ in
111+ use_silently ppf explicit_name
112+
98113 let loop ppf =
99114 Clflags.debug := true ;
100115 Location.formatter_for_warnings := ppf ;
@@ -108,6 +123,12 @@ let _ =
108123 Location.input_lexbuf := Some lb ;
109124 Sys.catch_break true ;
110125 (*load_ocamlinit ppf;*)
126+
127+ (* If there's an entry file provided, run it before dropping into interactive mode *)
128+ (match !eval_filepath with
129+ | Some name -> run_script ppf name
130+ | _ -> false) |> ignore ;
131+
111132 while true do
112133 let snap = Btype.snapshot () in
113134 try