]> matita.cs.unibo.it Git - helm.git/blob - helm/software/helena/src/basic_rg/brg.ml
update in helena
[helm.git] / helm / software / helena / src / basic_rg / brg.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.              
9      \ /   This software is distributed as is, NO WARRANTY.              
10       V_______________________________________________________________ *)
11
12 (* kernel version: basic, relative, global *)
13 (* note          : ufficial basic \lambda\delta version 3 *) 
14
15 module N = Layer
16 module E = Entity
17
18 type uri = E.uri
19 type n_attrs = E.node_attrs
20 type a_attrs = E.appl_attrs
21 type b_attrs = E.bind_attrs
22
23 (* x-reduced abstractions are output by RTM only *)
24 type bind = Void                          (*                         *)
25           | Abst of bool * N.layer * term (* x-reduced?, layer, type *)
26           | Abbr of term                  (* body                    *)
27
28 and term = Sort of int                    (* hierarchy index *)
29          | LRef of n_attrs * int          (* attrs, position index *)
30          | GRef of n_attrs * uri          (* attrs, reference *)
31          | Cast of term * term            (* type, term *)
32          | Appl of a_attrs * term * term  (* attrs, argument, function *)
33          | Bind of b_attrs * bind * term  (* attrs, binder, scope *)
34
35 type entity = term E.entity (* attrs, uri, binder *)
36
37 type lenv = Null
38 (* Cons: tail, relative local environment, attrs, binder *) 
39           | Cons of lenv * lenv * n_attrs * b_attrs * bind 
40
41 type manager = (N.status -> entity -> bool) * (unit -> unit)
42
43 (* Currified constructors ***************************************************)
44
45 let abst r n w = Abst (r, n, w)
46
47 let abbr v = Abbr v
48
49 let lref a i = LRef (a, i)
50
51 let gref a u = GRef (a, u)
52
53 let cast u t = Cast (u, t)
54
55 let appl a u t = Appl (a, u, t)
56
57 let bind y b t = Bind (y, b, t)
58
59 let bind_abst r n y u t = Bind (y, Abst (r, n, u), t)
60
61 let bind_abbr y u t = Bind (y, Abbr u, t)
62
63 let bind_void y t = Bind (y, Void, t)
64
65 (* local environment handling functions *************************************)
66
67 let empty = Null
68
69 let push e c a y b = Cons (e, c, a, y, b)
70
71 let rec get e i = match e with
72    | Null                            -> empty, empty, E.empty_node, E.empty_bind, Void
73    | Cons (e, c, a, y, b) when i = 0 -> e, c, a, y, b
74    | Cons (e, _, _, _, _)            -> get e (pred i)
75
76 let rec mem err f e y0 = match e with
77    | Null                 -> err ()
78    | Cons (e, _, _, y, _) ->
79       if y.E.b_name = y0.E.b_name then f () else mem err f e y0
80
81 (* used in BrgOutput.pp_lenv *)
82 let rec fold_right f map e x = match e with   
83    | Null                 -> f x
84    | Cons (e, c, a, y, b) -> fold_right (map f c a y b) map e x
85
86 (* used in BrgCC.output_entity_cc0 *)
87 let rec fold_left map x e = match e with   
88    | Null                 -> x
89    | Cons (e, c, a, y, b) -> fold_left map (map x c a y b) e