2016-02-18 07:11:59 -08:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. This file is distributed under the terms of *)
|
|
|
|
(* the GNU Lesser General Public License version 2.1, with the *)
|
|
|
|
(* special exception on linking described in the file LICENSE. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
1995-08-09 08:06:35 -07:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
open Format
|
|
|
|
|
2000-05-16 09:19:04 -07:00
|
|
|
(* Accessors for the table of toplevel value bindings. These functions
|
|
|
|
must appear as first and second exported functions in this module.
|
|
|
|
(See module Translmod.) *)
|
|
|
|
val getvalue : string -> Obj.t
|
|
|
|
val setvalue : string -> Obj.t -> unit
|
|
|
|
|
2002-02-07 18:56:04 -08:00
|
|
|
(* Set the load paths, before running anything *)
|
|
|
|
|
|
|
|
val set_paths : unit -> unit
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* The interactive toplevel loop *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
val loop : formatter -> unit
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1997-07-03 07:32:35 -07:00
|
|
|
(* Read and execute a script from the given file *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
val run_script : formatter -> string -> string array -> bool
|
2000-02-06 19:29:29 -08:00
|
|
|
(* true if successful, false if error *)
|
1997-07-03 07:32:35 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Interface with toplevel directives *)
|
|
|
|
|
|
|
|
type directive_fun =
|
2000-03-06 14:12:09 -08:00
|
|
|
| Directive_none of (unit -> unit)
|
|
|
|
| Directive_string of (string -> unit)
|
|
|
|
| Directive_int of (int -> unit)
|
|
|
|
| Directive_ident of (Longident.t -> unit)
|
|
|
|
| Directive_bool of (bool -> unit)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2015-12-25 10:51:20 -08:00
|
|
|
type directive_info = {
|
|
|
|
section: string;
|
|
|
|
doc: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
val add_directive : string -> directive_fun -> directive_info -> unit
|
2015-12-25 09:29:43 -08:00
|
|
|
(* Add toplevel directive and its documentation.
|
|
|
|
|
|
|
|
@since 4.03 *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
val directive_table : (string, directive_fun) Hashtbl.t
|
2015-12-25 09:29:43 -08:00
|
|
|
(* Deprecated: please use [add_directive] instead of inserting
|
|
|
|
in this table directly. *)
|
|
|
|
|
2015-12-25 10:51:20 -08:00
|
|
|
val directive_info_table : (string, directive_info) Hashtbl.t
|
2015-12-25 09:29:43 -08:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
val toplevel_env : Env.t ref
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Typing environment for the toplevel *)
|
2002-07-25 08:45:14 -07:00
|
|
|
val initialize_toplevel_env : unit -> unit
|
|
|
|
(* Initialize the typing environment for the toplevel *)
|
2000-03-06 14:12:09 -08:00
|
|
|
val print_exception_outcome : formatter -> exn -> unit
|
1997-07-03 07:32:35 -07:00
|
|
|
(* Print an exception resulting from the evaluation of user code. *)
|
2000-03-06 14:12:09 -08:00
|
|
|
val execute_phrase : bool -> formatter -> Parsetree.toplevel_phrase -> bool
|
1997-07-03 07:32:35 -07:00
|
|
|
(* Execute the given toplevel phrase. Return [true] if the
|
|
|
|
phrase executed with no errors and [false] otherwise.
|
|
|
|
First bool says whether the values and types of the results
|
|
|
|
should be printed. Uncaught exceptions are always printed. *)
|
2015-09-11 04:58:31 -07:00
|
|
|
val preprocess_phrase :
|
2018-09-18 06:49:18 -07:00
|
|
|
formatter -> Parsetree.toplevel_phrase -> Parsetree.toplevel_phrase
|
2014-10-13 00:17:10 -07:00
|
|
|
(* Preprocess the given toplevel phrase using regular and ppx
|
|
|
|
preprocessors. Return the updated phrase. *)
|
2000-03-06 14:12:09 -08:00
|
|
|
val use_file : formatter -> string -> bool
|
2020-03-16 10:48:41 -07:00
|
|
|
val use_output : formatter -> string -> bool
|
2000-03-06 14:12:09 -08:00
|
|
|
val use_silently : formatter -> string -> bool
|
2012-11-18 08:16:50 -08:00
|
|
|
val mod_use_file : formatter -> string -> bool
|
1997-07-03 07:32:35 -07:00
|
|
|
(* Read and execute commands from a file.
|
|
|
|
[use_file] prints the types and values of the results.
|
2012-11-18 08:16:50 -08:00
|
|
|
[use_silently] does not print them.
|
|
|
|
[mod_use_file] wrap the file contents into a module. *)
|
2018-02-08 09:51:47 -08:00
|
|
|
val eval_module_path: Env.t -> Path.t -> Obj.t
|
|
|
|
val eval_value_path: Env.t -> Path.t -> Obj.t
|
|
|
|
val eval_extension_path: Env.t -> Path.t -> Obj.t
|
|
|
|
val eval_class_path: Env.t -> Path.t -> Obj.t
|
2000-11-07 05:18:20 -08:00
|
|
|
(* Return the toplevel object referred to by the given path *)
|
2015-02-08 06:10:12 -08:00
|
|
|
val record_backtrace : unit -> unit
|
2000-11-07 05:18:20 -08:00
|
|
|
|
|
|
|
(* Printing of values *)
|
|
|
|
|
|
|
|
val print_value: Env.t -> Obj.t -> formatter -> Types.type_expr -> unit
|
|
|
|
val print_untyped_exception: formatter -> Obj.t -> unit
|
|
|
|
|
2014-12-06 09:11:04 -08:00
|
|
|
type ('a, 'b) gen_printer =
|
|
|
|
| Zero of 'b
|
|
|
|
| Succ of ('a -> ('a, 'b) gen_printer)
|
|
|
|
|
2001-07-03 04:04:10 -07:00
|
|
|
val install_printer :
|
|
|
|
Path.t -> Types.type_expr -> (formatter -> Obj.t -> unit) -> unit
|
2014-12-06 09:11:04 -08:00
|
|
|
val install_generic_printer :
|
|
|
|
Path.t -> Path.t ->
|
|
|
|
(int -> (int -> Obj.t -> Outcometree.out_value,
|
|
|
|
Obj.t -> Outcometree.out_value) gen_printer) -> unit
|
|
|
|
val install_generic_printer' :
|
|
|
|
Path.t -> Path.t -> (formatter -> Obj.t -> unit,
|
|
|
|
formatter -> Obj.t -> unit) gen_printer -> unit
|
2000-11-07 05:18:20 -08:00
|
|
|
val remove_printer : Path.t -> unit
|
|
|
|
|
|
|
|
val max_printer_depth: int ref
|
|
|
|
val max_printer_steps: int ref
|
1997-07-03 07:32:35 -07:00
|
|
|
|
2001-08-02 01:51:55 -07:00
|
|
|
(* Hooks for external parsers and printers *)
|
1997-07-03 07:32:35 -07:00
|
|
|
|
1996-05-22 05:43:11 -07:00
|
|
|
val parse_toplevel_phrase : (Lexing.lexbuf -> Parsetree.toplevel_phrase) ref
|
1997-07-03 07:32:35 -07:00
|
|
|
val parse_use_file : (Lexing.lexbuf -> Parsetree.toplevel_phrase list) ref
|
2000-03-06 14:12:09 -08:00
|
|
|
val print_location : formatter -> Location.t -> unit
|
2018-07-27 05:22:22 -07:00
|
|
|
val print_error : formatter -> Location.error -> unit
|
2000-03-06 14:12:09 -08:00
|
|
|
val print_warning : Location.t -> formatter -> Warnings.t -> unit
|
1997-07-03 07:32:35 -07:00
|
|
|
val input_name : string ref
|
2001-02-12 06:32:38 -08:00
|
|
|
|
2002-02-13 03:09:19 -08:00
|
|
|
val print_out_value :
|
|
|
|
(formatter -> Outcometree.out_value -> unit) ref
|
|
|
|
val print_out_type :
|
|
|
|
(formatter -> Outcometree.out_type -> unit) ref
|
|
|
|
val print_out_class_type :
|
|
|
|
(formatter -> Outcometree.out_class_type -> unit) ref
|
|
|
|
val print_out_module_type :
|
|
|
|
(formatter -> Outcometree.out_module_type -> unit) ref
|
2014-05-04 16:08:45 -07:00
|
|
|
val print_out_type_extension :
|
|
|
|
(formatter -> Outcometree.out_type_extension -> unit) ref
|
2002-02-13 03:09:19 -08:00
|
|
|
val print_out_sig_item :
|
|
|
|
(formatter -> Outcometree.out_sig_item -> unit) ref
|
|
|
|
val print_out_signature :
|
|
|
|
(formatter -> Outcometree.out_sig_item list -> unit) ref
|
|
|
|
val print_out_phrase :
|
|
|
|
(formatter -> Outcometree.out_phrase -> unit) ref
|
2001-08-02 01:51:55 -07:00
|
|
|
|
2004-05-15 02:59:37 -07:00
|
|
|
(* Hooks for external line editor *)
|
|
|
|
|
2014-04-29 04:56:17 -07:00
|
|
|
val read_interactive_input : (string -> bytes -> int -> int * bool) ref
|
2004-05-15 02:59:37 -07:00
|
|
|
|
2018-09-18 06:49:18 -07:00
|
|
|
(* Hooks *)
|
2003-06-30 08:31:06 -07:00
|
|
|
|
|
|
|
val toplevel_startup_hook : (unit -> unit) ref
|
|
|
|
|
2018-09-18 06:49:18 -07:00
|
|
|
type event = ..
|
|
|
|
type event +=
|
|
|
|
| Startup
|
|
|
|
| After_setup
|
|
|
|
(* Just after the setup, when the toplevel is ready to evaluate user
|
|
|
|
input. This happens before the toplevel has evaluated any kind of
|
|
|
|
user input, in particular this happens before loading the
|
|
|
|
[.ocamlinit] file. *)
|
|
|
|
|
|
|
|
val add_hook : (event -> unit) -> unit
|
|
|
|
(* Add a function that will be called at key points of the toplevel
|
|
|
|
initialization process. *)
|
|
|
|
|
|
|
|
val run_hooks : event -> unit
|
|
|
|
(* Run all the registered hooks. *)
|
|
|
|
|
2001-02-12 06:32:38 -08:00
|
|
|
(* Used by Trace module *)
|
|
|
|
|
|
|
|
val may_trace : bool ref
|
2016-02-24 09:23:21 -08:00
|
|
|
|
|
|
|
(* Misc *)
|
|
|
|
|
|
|
|
val override_sys_argv : string array -> unit
|
|
|
|
(* [override_sys_argv args] replaces the contents of [Sys.argv] by [args]
|
|
|
|
and reset [Arg.current] to [0].
|
|
|
|
|
|
|
|
This is called by [run_script] so that [Sys.argv] represents
|
|
|
|
"script.ml args..." instead of the full command line:
|
|
|
|
"ocamlrun unix.cma ... script.ml args...". *)
|