1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(* $Id: global.ml 10664 2008-03-14 11:27:37Z soubiran $ *)
19
(* We introduce here the global environment of the system, and we declare it
20
as a synchronized table. *)
22
let global_env = ref empty_environment
24
let safe_env () = !global_env
26
let env () = env_of_safe_env !global_env
28
let env_is_empty () = is_empty !global_env
31
declare_summary "Global environment"
32
{ freeze_function = (fun () -> !global_env);
33
unfreeze_function = (fun fr -> global_env := fr);
34
init_function = (fun () -> global_env := empty_environment);
35
survive_module = true;
36
survive_section = false }
38
(* Then we export the functions of [Typing] on that environment. *)
40
let universes () = universes (env())
41
let named_context () = named_context (env())
42
let named_context_val () = named_context_val (env())
44
let push_named_assum a =
45
let (cst,env) = push_named_assum a !global_env in
48
let push_named_def d =
49
let (cst,env) = push_named_def d !global_env in
53
(*let add_thing add kn thing =
54
let _,dir,l = repr_kn kn in
55
let kn',newenv = add dir l thing !global_env in
59
anomaly "Kernel names do not match."
62
let add_thing add dir id thing =
63
let kn, newenv = add dir (label_of_id id) thing !global_env in
67
let add_constant = add_thing add_constant
68
let add_mind = add_thing add_mind
69
let add_modtype = add_thing (fun _ -> add_modtype) ()
70
let add_module = add_thing (fun _ -> add_module) ()
71
let add_alias = add_thing (fun _ -> add_alias) ()
73
let add_constraints c = global_env := add_constraints c !global_env
75
let set_engagement c = global_env := set_engagement c !global_env
77
let add_include me = global_env := add_include me !global_env
80
let l = label_of_id id in
81
let mp,newenv = start_module l !global_env in
85
let end_module id mtyo =
86
let l = label_of_id id in
87
let mp,newenv = end_module l mtyo !global_env in
92
let add_module_parameter mbid mte =
93
let newenv = add_module_parameter mbid mte !global_env in
97
let start_modtype id =
98
let l = label_of_id id in
99
let mp,newenv = start_modtype l !global_env in
100
global_env := newenv;
104
let l = label_of_id id in
105
let kn,newenv = end_modtype l !global_env in
106
global_env := newenv;
112
let lookup_named id = lookup_named id (env())
113
let lookup_constant kn = lookup_constant kn (env())
114
let lookup_inductive ind = Inductive.lookup_mind_specif (env()) ind
115
let lookup_mind kn = lookup_mind kn (env())
117
let lookup_module mp = lookup_module mp (env())
118
let lookup_modtype kn = lookup_modtype kn (env())
123
let start_library dir =
124
let mp,newenv = start_library dir !global_env in
125
global_env := newenv;
128
let export s = snd (export !global_env s)
130
let import cenv digest =
131
let mp,newenv = import cenv digest !global_env in
132
global_env := newenv;
137
(*s Function to get an environment from the constants part of the global
138
environment and a given context. *)
140
let env_of_context hyps =
141
reset_with_named_context hyps (env())
145
let type_of_reference env = function
146
| VarRef id -> Environ.named_type id env
147
| ConstRef c -> Typeops.type_of_constant env c
149
let specif = Inductive.lookup_mind_specif env ind in
150
Inductive.type_of_inductive env specif
151
| ConstructRef cstr ->
153
Inductive.lookup_mind_specif env (inductive_of_constructor cstr) in
154
Inductive.type_of_constructor cstr specif
156
let type_of_global t = type_of_reference (env ()) t
159
(* spiwack: register/unregister functions for retroknowledge *)
160
let register field value by_clause =
161
let entry = kind_of_term value in
162
let senv = Safe_typing.register !global_env field entry by_clause in