]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_kernel/nCicEnvironment.ml
added add_obj to store objects in the environment, implementation still
[helm.git] / helm / software / components / ng_kernel / nCicEnvironment.ml
1 let cache = NUri.UriHash.create 313;;
2
3 let get_checked_obj u =
4   try NUri.UriHash.find cache u
5   with Not_found ->
6     let ouri = NUri.ouri_of_nuri u in
7     let o,_ = 
8       CicEnvironment.get_cooked_obj ~trust:false CicUniv.oblivion_ugraph ouri 
9     in
10     (* FIX: add all objects to the environment and give back the last one *)
11     let no = HExtlib.list_last (OCic2NCic.convert_obj ouri o) in
12     NUri.UriHash.add cache u no;
13     no
14 ;;
15
16 let get_obj u =
17   try true, NUri.UriHash.find cache u
18   with Not_found ->
19     (* in th final implementation should get it from disk *)
20     let ouri = NUri.ouri_of_nuri u in
21     let o,_ = 
22       CicEnvironment.get_cooked_obj ~trust:false CicUniv.oblivion_ugraph ouri 
23     in
24     (* here we should freeze it *)
25     false, HExtlib.list_last (OCic2NCic.convert_obj ouri o)
26 ;;
27
28 let add_obj (u,_,_,_,_ as o) =
29   (* we should unfreeze it *)
30   NUri.UriHash.add cache u o
31 ;;
32
33 let get_checked_def = function
34   | NReference.Ref (_, uri, NReference.Def) ->
35       (match get_checked_obj uri with
36       | _,height,_,_, NCic.Constant (rlv,name,Some bo,ty,att) ->
37           rlv,name,bo,ty,att,height
38       | _,_,_,_, NCic.Constant (_,_,None,_,_) ->
39           prerr_endline "get_checked_def on an axiom"; assert false
40       | _ -> prerr_endline "get_checked_def on a non def 2"; assert false)
41   | _ -> prerr_endline "get_checked_def on a non def"; assert false
42 ;;
43
44 let get_checked_indtys = function
45   | NReference.Ref (_, uri, NReference.Ind n) ->
46       (match get_checked_obj uri with
47       | _,_,_,_, NCic.Inductive (inductive,leftno,tys,att) ->
48         inductive,leftno,tys,att,n
49       | _ -> prerr_endline "get_checked_indtys on a non ind 2"; assert false)
50   | _ -> prerr_endline "get_checked_indtys on a non ind"; assert false
51 ;;
52
53 let get_checked_fix_or_cofix b = function
54   | NReference.Ref (_, uri, NReference.Fix (fixno,_)) ->
55       (match get_checked_obj uri with
56       | _,height,_,_, NCic.Fixpoint (is_fix,funcs,att) when is_fix = b ->
57          let rlv, name, _, ty, bo = List.nth funcs fixno in
58          rlv, name, bo, ty, att, height
59       | _ ->prerr_endline "get_checked_(co)fix on a non (co)fix 2";assert false)
60   | _ -> prerr_endline "get_checked_(co)fix on a non (co)fix"; assert false
61 ;;
62 let get_checked_fix r = get_checked_fix_or_cofix true r;;
63 let get_checked_cofix r = get_checked_fix_or_cofix false r;;
64
65 let get_indty_leftno = function 
66   | NReference.Ref (_, uri, NReference.Ind _) 
67   | NReference.Ref (_, uri, NReference.Con _) ->
68       (match get_checked_obj uri with
69       | _,_,_,_, NCic.Inductive (_,left,_,_) -> left
70       | _ ->prerr_endline "get_indty_leftno called on a non ind 2";assert false)
71   | _ -> prerr_endline "get_indty_leftno called on a non indty";assert false