]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/src/toplevel/metaBag.ml
97148c73719be205eb3a1c18088bcde13a09b675
[helm.git] / helm / software / lambda-delta / src / toplevel / metaBag.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 C = Cps
13 module Z = Bag
14 module M = Meta
15
16 (* Internal functions *******************************************************)
17
18 let rec xlate_term c f = function
19    | M.Sort s            -> 
20       let f h = f (Z.Sort h) in
21       if s then f 0 else f 1
22    | M.LRef (_, i)       ->
23       let l, _, _ = List.nth c i in
24       f (Z.LRef l)
25    | M.GRef (_, uri, vs) ->
26       let map f t v = f (Z.appl v t) in
27       let f vs = C.list_fold_left f map (Z.GRef uri) vs in
28       C.list_map f (xlate_term c) vs
29    | M.Appl (v, t)       ->
30       let f v t = f (Z.Appl (v, t)) in
31       let f v = xlate_term c (f v) t in
32       xlate_term c f v
33    | M.Abst (id, w, t)   ->
34       let f w = 
35          let l = Z.new_location () in
36          let f t = f (Z.Bind (l, id, Z.Abst w, t)) in
37          let f c = xlate_term c f t in
38          Z.push "meta" f c l id (Z.Abst w)
39       in
40       xlate_term c f w
41
42 let xlate_pars f pars =
43    let map f (id, w) c =
44       let l = Z.new_location () in
45       let f w = Z.push "meta" f c l id (Z.Abst w) in
46       xlate_term c f w
47    in
48    C.list_fold_right f map pars Z.empty_lenv
49
50 let unwind_to_xlate_term f c t =
51    let map f t (l, id, b) = f (Z.bind l id b t) in
52    let f t = C.list_fold_left f map t c in
53    xlate_term c f t
54
55 let xlate_entry f = function 
56    | pars, u, None   ->
57       let f c = unwind_to_xlate_term f c u in      
58       xlate_pars f pars   
59    | pars, u, Some t ->
60       let f u t = f (Z.Cast (u, t)) in
61       let f c u = unwind_to_xlate_term (f u) c t in
62       let f c = unwind_to_xlate_term (f c) c u in
63       xlate_pars f pars
64    
65 (* Interface functions ******************************************************)
66
67 let bag_of_meta = xlate_entry