X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Flambda-delta%2Fbasic_rg%2Fbrg.ml;h=efc5d7556914bc6b8976b0ade53be6a751c042ee;hb=85521efd364ec494e4cc024bbf87182a312e1b7b;hp=17532c970f32f234a4f5d5654e852a36834b63a4;hpb=41bf338d7e638ebb5d97e525055bff05b1f0f045;p=helm.git diff --git a/helm/software/lambda-delta/basic_rg/brg.ml b/helm/software/lambda-delta/basic_rg/brg.ml index 17532c970..efc5d7556 100644 --- a/helm/software/lambda-delta/basic_rg/brg.ml +++ b/helm/software/lambda-delta/basic_rg/brg.ml @@ -9,29 +9,35 @@ \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) -type uri = NUri.uri -type id = Aut.id +(* kernel version: basic, relative, global *) +(* note : ufficial basic lambda-delta *) -type bind = Void (* exclusion *) - | Abst of term (* abstraction *) - | Abbr of term (* abbreviation *) +type uri = Entity.uri +type id = Entity.id +type attrs = Entity.attrs -and term = Sort of int (* hierarchy index *) - | LRef of int (* reverse de Bruijn index *) - | GRef of uri (* reference *) - | Cast of term * term (* type, term *) - | Appl of term * term (* argument, function *) - | Bind of id * bind * term (* name, binder, scope *) +type bind = Void (* *) + | Abst of term (* type *) + | Abbr of term (* body *) -type obj = int * uri * bind (* age, uri, binder, contents *) +and term = Sort of attrs * int (* attrs, hierarchy index *) + | LRef of attrs * int (* attrs, position index *) + | GRef of attrs * uri (* attrs, reference *) + | Cast of attrs * term * term (* attrs, type, term *) + | Appl of attrs * term * term (* attrs, argument, function *) + | Bind of attrs * bind * term (* attrs, binder, scope *) -type item = obj option +type entity = term Entity.entity (* attrs, uri, binder *) -type context = int * (id * bind) list +type lenv = Null +(* Cons: tail, relative local environment, attrs, binder *) + | Cons of lenv * lenv * attrs * bind -type message = (context, term) Log.item list +(* helpers ******************************************************************) -type hierarchy = int -> int +let mk_uri si root s = + let kernel = if si then "brg-si" else "brg" in + String.concat "/" ["ld:"; kernel; root; s ^ ".ld"] (* Currified constructors ***************************************************) @@ -39,31 +45,39 @@ let abst w = Abst w let abbr v = Abbr v -let cast u t = Cast (u, t) +let lref a i = LRef (a, i) -let appl u t = Appl (u, t) +let cast a u t = Cast (a, u, t) -let bind id b t = Bind (id, b, t) +let appl a u t = Appl (a, u, t) -(* context handling functions ***********************************************) +let bind a b t = Bind (a, b, t) -let empty_context = 0, [] +let bind_abst a u t = Bind (a, Abst u, t) -let push f (l, es) id b = - let c = succ l, (id, b) :: es in - f c +let bind_abbr a v t = Bind (a, Abbr v, t) -let append f (l1, es1) (l2, es2) = - f (l2 + l1, List.append es2 es1) +let bind_void a t = Bind (a, Void, t) -let map f map (l, es) = - let f es = f (l, es) in - Cps.list_map f map es +(* local environment handling functions *************************************) -let contents f (l, es) = f l es +let empty = Null -let get f (l, es) i = - if i < 0 || i >= l then f None else - let result = List.nth es (l - succ i) in - f (Some result) +let push e c a b = Cons (e, c, a, b) +let rec get i = function + | Null -> Null, Null, [], Void + | Cons (e, c, a, b) when i = 0 -> e, c, a, b + | Cons (e, _, _, _) -> get (pred i) e + +let get e i = get i e + +(* used in BrgOutput.pp_lenv *) +let rec fold_right f map e x = match e with + | Null -> f x + | Cons (e, c, a, b) -> fold_right (map f e c a b) map e x + +(* used in MetaBrg.unwind_to_xlate_term *) +let rec fold_left map x = function + | Null -> x + | Cons (e, _, a, b) -> fold_left map (map x a b) e