@@ -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
@@ -45,6 +45,9 @@ let _ =
4545 run_mode := true ;
4646 code := str
4747 in
48+ let interactive_mode_arg str =
49+ interactive_mode := true ;
50+ in
4851 let speclist =
4952 [ ("-q", Arg.Set quiet, "Don't print OCaml version on startup")
5053 ; ( "-e" , Arg.String print_mode_arg , "Eval and output results of interpreted code" )
@@ -56,7 +59,11 @@ let _ =
5659 "OCaml / Reason repl script for prybar. Options available:"
5760 in
5861 Arg.parse speclist
59− (fun str -> print_endline ("Anonymous arg: " ^ str))
62+ (fun str ->
63+ match (str, !interactive_mode) with
64+ | (path, true) -> eval_filepath := Some(path)
65+ | _ -> print_endline ("Anonymous arg: " ^ str)
66+ )
6067 usage_msg ;
6168 let mode =
6269 match (!print_mode, !run_mode, !interactive_mode) with
@@ -95,7 +102,22 @@ let _ =
95102 len )
96103 else len
97104
105+ (* Minimal version of just running any input file, we stripped a lot of original logic
106+ * because we don't want to do any side effects on the compiler environment *)
107+ let run_script ppf name =
108+ let explicit_name =
109+ (* Prevent use_silently from searching in the path. *)
110+ if name <> "" && Filename.is_implicit name
111+ then Filename.concat Filename.current_dir_name name
112+ else name
113+ in
114+ use_silently ppf explicit_name
115+
98116 let loop ppf =
117+ (* If there's an entry file provided, run it before dropping into interactive mode *)
118+ (match !eval_filepath with
119+ | Some name -> run_script ppf name
120+ | _ -> false) |> ignore ;
99121 Clflags.debug := true ;
100122 Location.formatter_for_warnings := ppf ;
101123 ( try initialize_toplevel_env () with