Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 3793d48c1696cf3edd211e3fe697f4f3b1983e17 Mon Sep 17 00:00:00 2001
- From: nickgian <nick.giannarakis@gmail.com>
- Date: Sun, 4 Aug 2013 22:26:50 +0300
- Subject: [PATCH] Print directives
- ---
- toplevel/topdirs.ml | 116 ++++++++++++++++++++++++++++++++++++---------------
- toplevel/toploop.ml | 9 +++-
- toplevel/toploop.mli | 6 +++
- 3 files changed, 97 insertions(+), 34 deletions(-)
- diff --git a/toplevel/topdirs.ml b/toplevel/topdirs.ml
- index a679f8c..c33693d 100644
- --- a/toplevel/topdirs.ml
- +++ b/toplevel/topdirs.ml
- @@ -27,7 +27,9 @@ let std_out = std_formatter
- let dir_quit () = exit 0
- -let _ = Hashtbl.add directive_table "quit" (Directive_none dir_quit)
- +let _ = add_directive "quit" (Directive_none dir_quit)
- + "Exit the toplevel."
- +
- (* To add a directory to the load path *)
- @@ -36,7 +38,8 @@ let dir_directory s =
- Config.load_path := d :: !Config.load_path;
- Dll.add_path [d]
- -let _ = Hashtbl.add directive_table "directory" (Directive_string dir_directory)
- +let _ = add_directive "directory" (Directive_string dir_directory)
- + "Add the given directory to search path for source and compiled files."
- (* To remove a directory from the load path *)
- let dir_remove_directory s =
- @@ -44,15 +47,16 @@ let dir_remove_directory s =
- Config.load_path := List.filter (fun d' -> d' <> d) !Config.load_path;
- Dll.remove_path [d]
- -let _ =
- - Hashtbl.add directive_table "remove_directory"
- - (Directive_string dir_remove_directory)
- +let _ = add_directive "remove_directory" (Directive_string dir_remove_directory)
- + "Remove the given directory from the search path."
- (* To change the current directory *)
- let dir_cd s = Sys.chdir s
- -let _ = Hashtbl.add directive_table "cd" (Directive_string dir_cd)
- +let _ = add_directive "cd" (Directive_string dir_cd)
- + "Change the current working directory."
- +
- (* Load in-core a .cmo file *)
- @@ -153,11 +157,15 @@ and really_load_file recursive ppf name filename ic =
- let dir_load ppf name = ignore (load_file false ppf name)
- -let _ = Hashtbl.add directive_table "load" (Directive_string (dir_load std_out))
- +let _ = add_directive "load" (Directive_string (dir_load std_out))
- + "Load in memory a bytecode object, produced by ocamlc."
- let dir_load_rec ppf name = ignore (load_file true ppf name)
- -let _ = Hashtbl.add directive_table "load_rec" (Directive_string (dir_load_rec std_out))
- +let _ = add_directive "load_rec" (Directive_string (dir_load_rec std_out))
- + "Also load modules that the object file depends on."
- +
- +
- let load_file = load_file false
- @@ -166,8 +174,11 @@ let load_file = load_file false
- let dir_use ppf name = ignore(Toploop.use_file ppf name)
- let dir_mod_use ppf name = ignore(Toploop.mod_use_file ppf name)
- -let _ = Hashtbl.add directive_table "use" (Directive_string (dir_use std_out))
- -let _ = Hashtbl.add directive_table "mod_use" (Directive_string (dir_mod_use std_out))
- +let _ = add_directive "use" (Directive_string (dir_use std_out))
- + "Read, compile and execute source phrases from the given file."
- +
- +let _ = add_directive "mod_use" (Directive_string (dir_mod_use std_out))
- + "Usage is identical to #use but #mod_use wraps the contents in a module."
- (* Install, remove a printer *)
- @@ -231,10 +242,15 @@ let dir_remove_printer ppf lid =
- end
- with Exit -> ()
- -let _ = Hashtbl.add directive_table "install_printer"
- - (Directive_ident (dir_install_printer std_out))
- -let _ = Hashtbl.add directive_table "remove_printer"
- - (Directive_ident (dir_remove_printer std_out))
- +
- +let _ = add_directive "install_printer"
- + (Directive_ident (dir_install_printer std_out))
- + "Registers a printer for values of a certain type."
- +
- +let _ = add_directive "remove_printer"
- + (Directive_ident (dir_remove_printer std_out))
- + "Remove the named function from the table of toplevel printers."
- +
- (* The trace *)
- @@ -309,32 +325,66 @@ let parse_warnings ppf iserr s =
- try Warnings.parse_options iserr s
- with Arg.Bad err -> fprintf ppf "%s.@." err
- -let _ =
- - Hashtbl.add directive_table "trace" (Directive_ident (dir_trace std_out));
- - Hashtbl.add directive_table "untrace" (Directive_ident (dir_untrace std_out));
- - Hashtbl.add directive_table
- - "untrace_all" (Directive_none (dir_untrace_all std_out));
- +let _ = add_directive "trace"
- + (Directive_ident (dir_trace std_out))
- + "All calls to the function named \
- + function-name will be traced."
- +
- +let _ = add_directive "untrace"
- + (Directive_ident (dir_untrace std_out))
- + "Stop tracing the given function."
- +
- +let _ = add_directive "untrace_all"
- + (Directive_none (dir_untrace_all std_out))
- + "Stop tracing all functions traced so far."
- +
- (* Control the printing of values *)
- - Hashtbl.add directive_table "print_depth"
- - (Directive_int(fun n -> max_printer_depth := n));
- - Hashtbl.add directive_table "print_length"
- - (Directive_int(fun n -> max_printer_steps := n));
- +let _ = add_directive "print_depth"
- + (Directive_int(fun n -> max_printer_depth := n))
- + "Limit the printing of values to a maximal depth of n."
- +
- +let _ = add_directive "print_length"
- + (Directive_int(fun n -> max_printer_steps := n))
- + "Limit the number of value nodes printed to at most n."
- (* Set various compiler flags *)
- - Hashtbl.add directive_table "labels"
- - (Directive_bool(fun b -> Clflags.classic := not b));
- +let _ = add_directive "labels"
- + (Directive_bool(fun b -> Clflags.classic := not b))
- + "Choose whether to ignore labels in function types."
- +
- +let _ = add_directive "principal"
- + (Directive_bool(fun b -> Clflags.principal := b))
- + "Make sure that all types are derived in a principal way."
- +
- +let _ = add_directive "rectypes"
- + (Directive_none(fun () -> Clflags.recursive_types := true))
- + "Allow arbitrary recursive types during type-checking."
- +
- +let _ = add_directive "warnings"
- + (Directive_string (parse_warnings std_out false))
- + "Enable or disable warnings according to the argument."
- +
- +let _ = add_directive "warn_error"
- + (Directive_string (parse_warnings std_out true))
- + "Treat as errors the warnings enabled by the argument."
- +
- +let pp_directive name descr =
- + Printf.printf "#%-20s\t %-s\n" name descr
- - Hashtbl.add directive_table "principal"
- - (Directive_bool(fun b -> Clflags.principal := b));
- - Hashtbl.add directive_table "rectypes"
- - (Directive_none(fun () -> Clflags.recursive_types := true));
- +let print_directives () =
- + Printf.printf "Available directives: \n";
- + Hashtbl.iter pp_directive directive_descr_table;
- + if ((Hashtbl.length directive_table) != (Hashtbl.length directive_descr_table))
- + then
- + Hashtbl.iter (fun k _ -> if (Hashtbl.mem directive_descr_table k)
- + then ()
- + else pp_directive k "") directive_table
- - Hashtbl.add directive_table "warnings"
- - (Directive_string (parse_warnings std_out false));
- +let _ = add_directive "help"
- + (Directive_none (print_directives))
- + "Prints a list of all available directives"
- - Hashtbl.add directive_table "warn_error"
- - (Directive_string (parse_warnings std_out true))
- diff --git a/toplevel/toploop.ml b/toplevel/toploop.ml
- index 636fe15..3e6244f 100644
- --- a/toplevel/toploop.ml
- +++ b/toplevel/toploop.ml
- @@ -225,7 +225,14 @@ let print_exception_outcome ppf exn =
- (* The table of toplevel directives.
- Filled by functions from module topdirs. *)
- -let directive_table = (Hashtbl.create 13 : (string, directive_fun) Hashtbl.t)
- +let directive_table = (Hashtbl.create 23 : (string, directive_fun) Hashtbl.t)
- +
- +let directive_descr_table =
- + (Hashtbl.create 23 : (string, string) Hashtbl.t)
- +
- +let add_directive name dir_fun descr =
- + Hashtbl.add directive_table name dir_fun;
- + Hashtbl.add directive_descr_table name descr
- (* Execute a toplevel phrase *)
- diff --git a/toplevel/toploop.mli b/toplevel/toploop.mli
- index da607de..bf35963 100644
- --- a/toplevel/toploop.mli
- +++ b/toplevel/toploop.mli
- @@ -42,6 +42,11 @@ type directive_fun =
- val directive_table : (string, directive_fun) Hashtbl.t
- (* Table of known directives, with their execution function *)
- +val directive_descr_table : (string, string) Hashtbl.t
- + (* Table of known directives, with their description *)
- +val add_directive : string -> directive_fun -> string -> unit
- + (* Add a directive to the directive tables.
- + Usage : [add_directive name function descr] *)
- val toplevel_env : Env.t ref
- (* Typing environment for the toplevel *)
- val initialize_toplevel_env : unit -> unit
- @@ -110,3 +115,4 @@ val toplevel_startup_hook : (unit -> unit) ref
- (* Used by Trace module *)
- val may_trace : bool ref
- +
- --
- 1.7.12.4 (Apple Git-37)
Add Comment
Please, Sign In to add comment