| 1 | (************************************************************************) |
| 2 | (* * The Rocq Prover / The Rocq Development Team *) |
| 3 | (* v * Copyright INRIA, CNRS and contributors *) |
| 4 | (* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 | (* \VV/ **************************************************************) |
| 6 | (* // * This file is distributed under the terms of the *) |
| 7 | (* * GNU Lesser General Public License Version 2.1 *) |
| 8 | (* * (see LICENSE file for the text of the license) *) |
| 9 | (************************************************************************) |
| 10 | |
| 11 | (** {5 Toplevel management} *) |
| 12 | |
| 13 | (** Coq plugins are identified by their OCaml library name (in the |
| 14 | Findlib sense) *) |
| 15 | module PluginSpec : sig |
| 16 | |
| 17 | (** A plugin is identified by its canonical library name, |
| 18 | such as [rocq-runtime.plugins.ltac] *) |
| 19 | type t |
| 20 | |
| 21 | (** [to_package p] returns the findlib name of the package *) |
| 22 | val to_package : t -> string |
| 23 | |
| 24 | val pp : t -> string |
| 25 | end |
| 26 | |
| 27 | type toplevel = |
| 28 | { load_plugin : PluginSpec.t -> unit |
| 29 | (** Load a findlib library, given by public name *) |
| 30 | ; load_module : string -> unit |
| 31 | (** Load a cmxs / cmo module, used by the native compiler to load objects *) |
| 32 | ; add_dir : string -> unit |
| 33 | (** Adds a dir to the module search path *) |
| 34 | ; ml_loop : ?init_file:string -> unit -> unit |
| 35 | (** Run the OCaml toplevel with given addtitional initialisation file *) |
| 36 | } |
| 37 | |
| 38 | (** Sets and initializes a toplevel (if any) *) |
| 39 | val set_top : toplevel -> unit |
| 40 | |
| 41 | (** Low level module loading, for the native compiler and similar users. *) |
| 42 | val load_module : string -> unit |
| 43 | |
| 44 | (** Removes the toplevel (if any) *) |
| 45 | val remove : unit -> unit |
| 46 | |
| 47 | (** Tests if an Ocaml toplevel runs under Coq *) |
| 48 | val is_ocaml_top : unit -> bool |
| 49 | |
| 50 | (** Starts the Ocaml toplevel loop *) |
| 51 | val ocaml_toploop : ?init_file:string -> unit -> unit |
| 52 | |
| 53 | (** {5 ML Dynlink} *) |
| 54 | |
| 55 | (** Adds a dir to the plugin search path, this also extends |
| 56 | OCamlfind's search path *) |
| 57 | val add_ml_dir : string -> unit |
| 58 | |
| 59 | (** Tests if we can load ML files *) |
| 60 | val has_dynlink : bool |
| 61 | |
| 62 | (** {5 Initialization functions} *) |
| 63 | |
| 64 | (** Declare a initialization function. The initialization function is |
| 65 | called in Declare ML Module, including reruns after backtracking |
| 66 | over it (either interactive backtrack, module closing backtrack, |
| 67 | Require of a file with Declare ML Module). |
| 68 | *) |
| 69 | val add_init_function : string -> (unit -> unit) -> unit |
| 70 | |
| 71 | (** Register a callback that will be called when the module is declared with |
| 72 | the Declare ML Module command. This is useful to define Coq objects at that |
| 73 | time only. Several functions can be defined for one module; they will be |
| 74 | called in the order of declaration, and after the ML module has been |
| 75 | properly initialized. |
| 76 | |
| 77 | Unlike the init functions it does not run after closing a module |
| 78 | or Requiring a file which contains the Declare ML Module. |
| 79 | This allows to have effects which depend on the module when |
| 80 | command was run in, eg add a named libobject which will use it for the prefix. |
| 81 | |
| 82 | The callback runs in the synterp phase, use |
| 83 | [declare_cache_obj_full] if you also need to interact with Interp |
| 84 | state. |
| 85 | *) |
| 86 | val declare_cache_obj : (unit -> unit) -> string -> unit |
| 87 | |
| 88 | type cache_obj = CacheObj : { synterp : unit -> 'a; interp : 'a -> unit } -> cache_obj |
| 89 | |
| 90 | val interp_only_obj : (unit -> unit) -> cache_obj |
| 91 | |
| 92 | (** Register a callback with an interp phase. *) |
| 93 | val declare_cache_obj_full : cache_obj -> string -> unit |
| 94 | |
| 95 | (** {5 Declaring modules} *) |
| 96 | |
| 97 | type interp_fun |
| 98 | |
| 99 | val run_interp_fun : interp_fun -> unit |
| 100 | |
| 101 | (** Implementation of the [Declare ML Module] vernacular command. *) |
| 102 | val declare_ml_modules : Vernacexpr.locality_flag -> string list -> interp_fun |
| 103 | |
| 104 | (** {5 Utilities} *) |
| 105 | |
| 106 | val print_ml_modules : unit -> Pp.t |
| 107 | val print_gc : unit -> Pp.t |