aboutsummaryrefslogtreecommitdiffhomepage
path: root/library/global.ml
blob: 63efdbe4d9c4d7606511ee5714d00ef69a6708dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

(* $Id$ *)

open Generic
open Term
open Instantiate
open Sign
open Typing
open Summary

(* We introduce here the global environment of the system, and we declare it
   as a synchronized table. *)

let global_env = ref empty_environment

let env () = !global_env

let unsafe_env () = unsafe_env_of_env !global_env

let _ = 
  declare_summary "Global environment"
    { freeze_function = (fun () -> !global_env);
      unfreeze_function = (fun fr -> global_env := fr);
      init_function = (fun () -> global_env := empty_environment) }

(* Then we export the functions of [Typing] on that environment. *)

let universes () = universes !global_env
let context () = context !global_env

let push_var idc = global_env := push_var idc !global_env
let push_rel nac = global_env := push_rel nac !global_env
let add_constant sp ce = global_env := add_constant sp ce !global_env
let add_parameter sp c = global_env := add_parameter sp c !global_env
let add_mind sp mie = global_env := add_mind sp mie !global_env
let add_constraints c = global_env := add_constraints c !global_env

let lookup_var id = lookup_var id !global_env
let lookup_rel n = lookup_rel n !global_env
let lookup_constant sp = lookup_constant sp !global_env
let lookup_mind sp = lookup_mind sp !global_env
let lookup_mind_specif c = lookup_mind_specif c !global_env

let export s = export !global_env s
let import cenv = global_env := import cenv !global_env

(* Re-exported functions of [Inductive], composed with [lookup_mind_specif]. *)

open Inductive

let mind_is_recursive = Util.compose mis_is_recursive lookup_mind_specif 
let mind_nconstr = Util.compose mis_nconstr lookup_mind_specif
let mind_nparams = Util.compose mis_nparams lookup_mind_specif

let mis_arity' mis =
  let idhyps = ids_of_sign mis.mis_mib.mind_hyps 
  and largs = Array.to_list mis.mis_args in 
  { body = instantiate_constr idhyps mis.mis_mip.mind_arity.body largs;
    typ = mis.mis_mip.mind_arity.typ }

let mis_arity mispec =
  let { body = b; typ = t } = mis_arity' mispec in
  DOP2 (Cast, b, DOP0 (Sort t))

let mind_arity = Util.compose mis_arity lookup_mind_specif

let mis_lc mis = 
  instantiate_constr (ids_of_sign mis.mis_mib.mind_hyps)
    mis.mis_mip.mind_lc (Array.to_list mis.mis_args)

let mis_lc_without_abstractions mis = 
  let rec strip_DLAM = function
    | (DLAM (n,c1)) -> strip_DLAM c1 
    | (DLAMV (n,v)) -> v
    | _ -> assert false
  in 
  strip_DLAM (mis_lc mis)

let mind_lc_without_abstractions = 
  Util.compose mis_lc_without_abstractions lookup_mind_specif