Simon Génier pushed to branch master at Stefan / Typer
Commits: ceed8e81 by Simon Génier at 2021-04-07T16:05:34-04:00 Move code related to command-line argument parsing out of REPL.
- - - - - e229996a by Simon Génier at 2021-04-09T13:41:26-04:00 Merge branch 'extract-args-from-repl'
- - - - -
2 changed files:
- src/REPL.ml - typer.ml
Changes:
===================================== src/REPL.ml ===================================== @@ -53,8 +53,6 @@ open Debruijn module OL = Opslexp module EL = Elexp
-let arg_batch = ref false - let print_input_line i = print_string " In["; ralign_print_int i 2; @@ -178,13 +176,6 @@ let raw_eval source ectx rctx = (* This is for consistency with ieval *) [], ectx', rctx
-let welcome_msg = -" Typer 0.0.0 - Interpreter - (c) 2016 - - %quit (%q) : leave REPL - %help (%h) : print help -" - let help_msg = " %quit (%q) : leave REPL %who (%w) : print runtime environment @@ -273,57 +264,3 @@ let rec repl i clxp rctx = | Log.User_error msg -> (handle_stopped_compilation ("Fatal user error: " ^ msg); repl clxp rctx) - -let arg_files = ref [] - - -(* ./typer [options] files *) -let arg_defs = [ - ("--batch", Arg.Set arg_batch, "Don't run the interactive loop"); - ("--verbosity", - Arg.String Log.set_typer_log_level_str, "Set the logging level"); - ("-v", Arg.Unit Log.increment_log_level, "Increment verbosity"); - ("-Vfull-lctx", - Arg.Set Debruijn.log_full_lctx, - "Print the full lexp context on error."); - (* ("--debug", Arg.Set arg_debug, "Print the Elexp representation") *) - (*"-I", - Arg.String (fun f -> searchpath := f::!searchpath), - "Append a directory to the search path"*) -] - -let parse_args () = - Arg.parse arg_defs (fun s -> arg_files:= s::!arg_files) "" - -let main () = - parse_args (); - - let ectx = Elab.default_ectx in - let rctx = Elab.default_rctx in - - if not !arg_batch then - (print_string (make_title " TYPER REPL "); - print_string welcome_msg; - print_string (make_sep '-'); - flush stdout); - - let (i, ectx, rctx) = ( - try - let res = - readfiles (List.rev !arg_files) (1, ectx, rctx) (not !arg_batch) in - print_and_clear_log (); res - with - | Log.Stop_Compilation msg -> - handle_stopped_compilation msg; exit 1 - | (Log.Internal_error msg) as e -> - handle_stopped_compilation ("Internal error: " ^ msg); - raise e - | Log.User_error msg -> - handle_stopped_compilation ("Fatal user error: " ^ msg); exit 1 - ) in - - flush stdout; - - if not !arg_batch then - (* Initiate REPL. This will allow us to inspect interpreted code *) - repl i ectx rctx
===================================== typer.ml ===================================== @@ -17,4 +17,72 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see http://www.gnu.org/licenses/. *)
-let () = Typerlib.REPL.main () +(** This file is the the entry point to the typer REPL. *) + +open Typerlib + +let welcome_msg = +" Typer 0.0.0 - Interpreter - (c) 2016-2021 + + %quit (%q) : leave REPL + %help (%h) : print help +" + +let arg_batch = ref false + +let arg_files = ref [] +let add_input_file file = + arg_files := file :: !arg_files + +let arg_defs = + [("--batch", Arg.Set arg_batch, "Don't run the interactive loop"); + + ("--verbosity", + Arg.String Log.set_typer_log_level_str, + "Set the logging level"); + + ("-v", Arg.Unit Log.increment_log_level, "Increment verbosity"); + + ("-Vfull-lctx", + Arg.Set Debruijn.log_full_lctx, + "Print the full lexp context on error."); + ] + +let main () = + let usage = Sys.executable_name ^ " [options] <file1> [<file2>] …" in + Arg.parse arg_defs add_input_file usage; + let files = List.rev !arg_files in + let is_interactive = not !arg_batch in + + if is_interactive + then + (print_string (Fmt.make_title " TYPER REPL "); + print_string welcome_msg; + print_string (Fmt.make_sep '-'); + flush stdout); + + let i, ectx, rctx = + try + let ectx = Elab.default_ectx in + let rctx = Elab.default_rctx in + let res = + REPL.readfiles files (1, ectx, rctx) is_interactive + in + REPL.print_and_clear_log (); + res + with + | Log.Stop_Compilation msg + -> REPL.handle_stopped_compilation msg; + exit 1 + | (Log.Internal_error msg) as e + -> REPL.handle_stopped_compilation ("Internal error: " ^ msg); + raise e + | Log.User_error msg + -> REPL.handle_stopped_compilation ("Fatal user error: " ^ msg); + exit 1 + in + + if is_interactive + then REPL.repl i ectx rctx + +let () = main ()
View it on GitLab: https://gitlab.com/monnier/typer/-/compare/6816e0aa66886deafa267f95cc456dfb9...
Afficher les réponses par date