]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/basic_rg/brgType.ml
- performance data added for reference
[helm.git] / helm / software / lambda-delta / basic_rg / brgType.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 module U = NUri
13 module C = Cps
14 module A = Share
15 module L = Log
16 module H = Hierarchy
17 module B = Brg
18 module O = BrgOutput
19 module E = BrgEnvironment
20 module S = BrgSubstitution
21 module R = BrgReduction
22
23 (* Internal functions *******************************************************)
24
25 let level = 4
26
27 let log1 s m t =
28    let s =  s ^ " the term" in
29    L.log O.specs level (R.message1 s m t) 
30
31 let error1 s m t =
32    raise (R.TypeError (R.message1 s m t))
33
34 (* Interface functions ******************************************************)
35
36 let rec b_type_of f ~si g m x =
37    log1 "Now checking" m x;
38    match x with
39    | B.Sort (a, h)           ->
40       let f h = f x (B.Sort (a, h)) in H.apply f g h
41    | B.LRef (_, i)           ->
42       let f _ = function
43          | B.Abst w                  ->
44             S.lift (f x) (succ i) (0) w
45          | B.Abbr (B.Cast (_, w, _)) -> 
46             S.lift (f x) (succ i) (0) w
47          | B.Abbr _                  -> assert false
48          | B.Void                    -> 
49             error1 "reference to excluded variable" m x
50       in
51       R.get f m i
52    | B.GRef (_, uri)         ->
53       let f = function
54          | _, _, B.Abst w                  -> f x w
55          | _, _, B.Abbr (B.Cast (_, w, _)) -> f x w
56          | _, _, B.Abbr _                  -> assert false
57          | _, _, B.Void                    ->
58             error1 "reference to excluded object" m x
59       in
60       E.get_obj f uri   
61    | B.Bind (a, B.Abbr v, t) ->
62       let f xv xt tt =
63          f (A.sh2 v xv t xt x (B.bind_abbr a)) (B.bind_abbr a xv tt)
64       in
65       let f xv m = b_type_of (f xv) ~si g m t in
66       let f xv = R.push (f xv) m a (B.Abbr xv) in
67       let f xv vv = match xv with 
68          | B.Cast _ -> f xv
69          | _        -> f (B.Cast ([], vv, xv))
70       in
71       type_of f ~si g m v
72    | B.Bind (a, B.Abst u, t) ->
73       let f xu xt tt =
74          f (A.sh2 u xu t xt x (B.bind_abst a)) (B.bind_abst a xu tt)
75       in
76       let f xu m = b_type_of (f xu) ~si g m t in
77       let f xu _ = R.push (f xu) m a (B.Abst xu) in
78       type_of f ~si g m u
79    | B.Bind (a, B.Void, t)   ->
80       let f xt tt = 
81          f (A.sh1 t xt x (B.bind a B.Void)) (B.bind a B.Void tt)
82       in
83       let f m = b_type_of f ~si g m t in
84       R.push f m a B.Void   
85    | B.Appl (a, v, t)        ->
86       let f xv vv xt tt = 
87          let f () = f (A.sh2 v xv t xt x (B.appl a)) (B.appl a xv tt) in
88          R.assert_conversion f ~si ~rt:true m tt vv xv
89       in
90       let f xv vv = b_type_of (f xv vv) ~si g m t in
91       type_of f ~si g m v
92    | B.Cast (a, u, t)        ->
93       let f xu xt tt =  
94          let f () = f (A.sh2 u xu t xt x (B.cast a)) xu in
95          R.assert_conversion f ~si m xu tt xt
96       in
97       let f xu _ = b_type_of (f xu) ~si g m t in
98       type_of f ~si g m u
99
100 and type_of f ?(si=false) g m x =
101    let f t u = L.unbox level; f t u in
102    L.box level; b_type_of f ~si g m x