From 41bf338d7e638ebb5d97e525055bff05b1f0f045 Mon Sep 17 00:00:00 2001 From: Ferruccio Guidi Date: Fri, 12 Dec 2008 12:45:42 +0000 Subject: [PATCH] - basic_rg: architectural bug fix - toplevel: more help on command line options --- helm/software/lambda-delta/.depend.opt | 41 ++-- helm/software/lambda-delta/basic_rg/Make | 2 +- helm/software/lambda-delta/basic_rg/brg.ml | 27 ++ .../lambda-delta/basic_rg/brgEnvironment.ml | 8 +- .../lambda-delta/basic_rg/brgEnvironment.mli | 2 +- .../lambda-delta/basic_rg/brgOutput.ml | 36 ++- .../lambda-delta/basic_rg/brgOutput.mli | 2 +- .../lambda-delta/basic_rg/brgReduction.ml | 230 +++++++++--------- .../lambda-delta/basic_rg/brgReduction.mli | 17 +- .../software/lambda-delta/basic_rg/brgType.ml | 37 +-- .../lambda-delta/basic_rg/brgType.mli | 6 +- .../lambda-delta/basic_rg/brgUntrusted.ml | 3 +- .../lambda-delta/basic_rg/brgUntrusted.mli | 4 +- helm/software/lambda-delta/toplevel/top.ml | 7 +- 14 files changed, 233 insertions(+), 189 deletions(-) diff --git a/helm/software/lambda-delta/.depend.opt b/helm/software/lambda-delta/.depend.opt index 7e884babc..65ad62e6a 100644 --- a/helm/software/lambda-delta/.depend.opt +++ b/helm/software/lambda-delta/.depend.opt @@ -14,25 +14,26 @@ automath/autParser.cmo: automath/aut.cmx automath/autParser.cmi automath/autParser.cmx: automath/aut.cmx automath/autParser.cmi automath/autLexer.cmo: lib/log.cmi automath/autParser.cmi automath/autLexer.cmx: lib/log.cmx automath/autParser.cmx -basic_rg/brg.cmo: lib/nUri.cmi automath/aut.cmx -basic_rg/brg.cmx: lib/nUri.cmx automath/aut.cmx +basic_rg/brg.cmo: lib/nUri.cmi lib/log.cmi lib/cps.cmx automath/aut.cmx +basic_rg/brg.cmx: lib/nUri.cmx lib/log.cmx lib/cps.cmx automath/aut.cmx +basic_rg/brgOutput.cmi: lib/log.cmi basic_rg/brg.cmx +basic_rg/brgOutput.cmo: lib/nUri.cmi lib/log.cmi lib/cps.cmx basic_rg/brg.cmx \ + basic_rg/brgOutput.cmi +basic_rg/brgOutput.cmx: lib/nUri.cmx lib/log.cmx lib/cps.cmx basic_rg/brg.cmx \ + basic_rg/brgOutput.cmi basic_rg/brgEnvironment.cmi: lib/nUri.cmi basic_rg/brg.cmx -basic_rg/brgEnvironment.cmo: lib/nUri.cmi basic_rg/brg.cmx \ +basic_rg/brgEnvironment.cmo: lib/nUri.cmi lib/log.cmi basic_rg/brg.cmx \ basic_rg/brgEnvironment.cmi -basic_rg/brgEnvironment.cmx: lib/nUri.cmx basic_rg/brg.cmx \ +basic_rg/brgEnvironment.cmx: lib/nUri.cmx lib/log.cmx basic_rg/brg.cmx \ basic_rg/brgEnvironment.cmi -basic_rg/brgReduction.cmi: lib/log.cmi basic_rg/brg.cmx -basic_rg/brgReduction.cmo: lib/share.cmx lib/nUri.cmi lib/log.cmi lib/cps.cmx \ - basic_rg/brgEnvironment.cmi basic_rg/brg.cmx basic_rg/brgReduction.cmi -basic_rg/brgReduction.cmx: lib/share.cmx lib/nUri.cmx lib/log.cmx lib/cps.cmx \ - basic_rg/brgEnvironment.cmx basic_rg/brg.cmx basic_rg/brgReduction.cmi -basic_rg/brgOutput.cmi: lib/log.cmi basic_rg/brgReduction.cmi \ - basic_rg/brg.cmx -basic_rg/brgOutput.cmo: lib/nUri.cmi lib/log.cmi lib/cps.cmx \ - basic_rg/brgReduction.cmi basic_rg/brg.cmx basic_rg/brgOutput.cmi -basic_rg/brgOutput.cmx: lib/nUri.cmx lib/log.cmx lib/cps.cmx \ - basic_rg/brgReduction.cmx basic_rg/brg.cmx basic_rg/brgOutput.cmi -basic_rg/brgType.cmi: lib/log.cmi basic_rg/brgReduction.cmi basic_rg/brg.cmx +basic_rg/brgReduction.cmi: basic_rg/brg.cmx +basic_rg/brgReduction.cmo: lib/share.cmx lib/log.cmi lib/cps.cmx \ + basic_rg/brgOutput.cmi basic_rg/brgEnvironment.cmi basic_rg/brg.cmx \ + basic_rg/brgReduction.cmi +basic_rg/brgReduction.cmx: lib/share.cmx lib/log.cmx lib/cps.cmx \ + basic_rg/brgOutput.cmx basic_rg/brgEnvironment.cmx basic_rg/brg.cmx \ + basic_rg/brgReduction.cmi +basic_rg/brgType.cmi: basic_rg/brg.cmx basic_rg/brgType.cmo: lib/log.cmi basic_rg/brgReduction.cmi \ basic_rg/brgOutput.cmi basic_rg/brgEnvironment.cmi basic_rg/brg.cmx \ basic_rg/brgType.cmi @@ -40,10 +41,10 @@ basic_rg/brgType.cmx: lib/log.cmx basic_rg/brgReduction.cmx \ basic_rg/brgOutput.cmx basic_rg/brgEnvironment.cmx basic_rg/brg.cmx \ basic_rg/brgType.cmi basic_rg/brgUntrusted.cmi: basic_rg/brg.cmx -basic_rg/brgUntrusted.cmo: basic_rg/brgType.cmi basic_rg/brgReduction.cmi \ - basic_rg/brgEnvironment.cmi basic_rg/brg.cmx basic_rg/brgUntrusted.cmi -basic_rg/brgUntrusted.cmx: basic_rg/brgType.cmx basic_rg/brgReduction.cmx \ - basic_rg/brgEnvironment.cmx basic_rg/brg.cmx basic_rg/brgUntrusted.cmi +basic_rg/brgUntrusted.cmo: basic_rg/brgType.cmi basic_rg/brgEnvironment.cmi \ + basic_rg/brg.cmx basic_rg/brgUntrusted.cmi +basic_rg/brgUntrusted.cmx: basic_rg/brgType.cmx basic_rg/brgEnvironment.cmx \ + basic_rg/brg.cmx basic_rg/brgUntrusted.cmi toplevel/meta.cmo: lib/nUri.cmi automath/aut.cmx toplevel/meta.cmx: lib/nUri.cmx automath/aut.cmx toplevel/metaOutput.cmi: toplevel/meta.cmx diff --git a/helm/software/lambda-delta/basic_rg/Make b/helm/software/lambda-delta/basic_rg/Make index 7085d3b57..eb1c64a66 100644 --- a/helm/software/lambda-delta/basic_rg/Make +++ b/helm/software/lambda-delta/basic_rg/Make @@ -1 +1 @@ -brg brgEnvironment brgReduction brgOutput brgType brgUntrusted +brg brgOutput brgEnvironment brgReduction brgType brgUntrusted diff --git a/helm/software/lambda-delta/basic_rg/brg.ml b/helm/software/lambda-delta/basic_rg/brg.ml index e9897c08a..17532c970 100644 --- a/helm/software/lambda-delta/basic_rg/brg.ml +++ b/helm/software/lambda-delta/basic_rg/brg.ml @@ -27,6 +27,10 @@ type obj = int * uri * bind (* age, uri, binder, contents *) type item = obj option +type context = int * (id * bind) list + +type message = (context, term) Log.item list + type hierarchy = int -> int (* Currified constructors ***************************************************) @@ -40,3 +44,26 @@ let cast u t = Cast (u, t) let appl u t = Appl (u, t) let bind id b t = Bind (id, b, t) + +(* context handling functions ***********************************************) + +let empty_context = 0, [] + +let push f (l, es) id b = + let c = succ l, (id, b) :: es in + f c + +let append f (l1, es1) (l2, es2) = + f (l2 + l1, List.append es2 es1) + +let map f map (l, es) = + let f es = f (l, es) in + Cps.list_map f map es + +let contents f (l, es) = f l es + +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) + diff --git a/helm/software/lambda-delta/basic_rg/brgEnvironment.ml b/helm/software/lambda-delta/basic_rg/brgEnvironment.ml index e640c865b..fb4243c74 100644 --- a/helm/software/lambda-delta/basic_rg/brgEnvironment.ml +++ b/helm/software/lambda-delta/basic_rg/brgEnvironment.ml @@ -10,10 +10,11 @@ V_______________________________________________________________ *) module U = NUri +module L = Log module H = U.UriHash module B = Brg -exception ObjectNotFound of string Lazy.t +exception ObjectNotFound of B.message let hsize = 7000 let env = H.create hsize @@ -21,6 +22,8 @@ let entry = ref 0 (* Internal functions *******************************************************) +let error uri = raise (ObjectNotFound (L.items1 (U.string_of_uri uri))) + (* Interface functions ******************************************************) let set_obj f obj = @@ -29,5 +32,4 @@ let set_obj f obj = incr entry; H.add env uri obj; f obj let get_obj f uri = - try f (H.find env uri) - with Not_found -> raise (ObjectNotFound (lazy (U.string_of_uri uri))) + try f (H.find env uri) with Not_found -> error uri diff --git a/helm/software/lambda-delta/basic_rg/brgEnvironment.mli b/helm/software/lambda-delta/basic_rg/brgEnvironment.mli index ddf55d7a4..8f9f8b1b0 100644 --- a/helm/software/lambda-delta/basic_rg/brgEnvironment.mli +++ b/helm/software/lambda-delta/basic_rg/brgEnvironment.mli @@ -9,7 +9,7 @@ \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) -exception ObjectNotFound of string Lazy.t +exception ObjectNotFound of Brg.message val set_obj: (Brg.obj -> 'a) -> Brg.obj -> 'a diff --git a/helm/software/lambda-delta/basic_rg/brgOutput.ml b/helm/software/lambda-delta/basic_rg/brgOutput.ml index 4c100375d..4d3eb0ff7 100644 --- a/helm/software/lambda-delta/basic_rg/brgOutput.ml +++ b/helm/software/lambda-delta/basic_rg/brgOutput.ml @@ -15,7 +15,6 @@ module U = NUri module C = Cps module L = Log module B = Brg -module R = BrgReduction type counters = { eabsts: int; @@ -100,29 +99,42 @@ let print_counters f c = let rec pp_term c frm = function | B.Sort h -> F.fprintf frm "@[*%u@]" h - | B.LRef i -> F.fprintf frm "@[#%u@]" i + | B.LRef i -> + let f = function + | Some (id, _) -> F.fprintf frm "@[%s@]" id + | None -> F.fprintf frm "@[#%u@]" i + in + B.get f c i | B.GRef s -> F.fprintf frm "@[$%s@]" (U.string_of_uri s) | B.Cast (u, t) -> F.fprintf frm "@[{%a}.%a@]" (pp_term c) u (pp_term c) t | B.Appl (v, t) -> F.fprintf frm "@[(%a).%a@]" (pp_term c) v (pp_term c) t | B.Bind (id, B.Abst w, t) -> - F.fprintf frm "@[[%s:%a].%a@]" id (pp_term c) w (pp_term c) t + let f cc = + F.fprintf frm "@[[%s:%a].%a@]" id (pp_term c) w (pp_term cc) t + in + B.push f c id (B.Abst w) | B.Bind (id, B.Abbr v, t) -> - F.fprintf frm "@[[%s=%a].%a@]" id (pp_term c) v (pp_term c) t + let f cc = + F.fprintf frm "@[[%s=%a].%a@]" id (pp_term c) v (pp_term cc) t + in + B.push f c id (B.Abbr v) | B.Bind (id, B.Void, t) -> - F.fprintf frm "@[[%s].%a@]" id (pp_term c) t + let f cc = F.fprintf frm "@[[%s].%a@]" id (pp_term cc) t in + B.push f c id B.Void let pp_context frm c = let pp_entry f = function - | B.Abst w -> - F.fprintf frm "%s %a\n%!" "\\decl" (pp_term c) w; f () - | B.Abbr v -> - F.fprintf frm "%s %a\n%!" "\\def " (pp_term c) v; f () - | B.Void -> - F.fprintf frm "%s\n%!" "\\void"; f () + | id, B.Abst w -> + F.fprintf frm "%s : %a\n%!" id (pp_term c) w; f () + | id, B.Abbr v -> + F.fprintf frm "%s = %a\n%!" id (pp_term c) v; f () + | id, B.Void -> + F.fprintf frm "%s\n%!" id; f () in - R.iter C.start pp_entry c + let f _ es = C.list_iter C.start pp_entry (List.rev es) in + B.contents f c let pp_term frm c t = F.fprintf frm "%a\n%!" (pp_term c) t diff --git a/helm/software/lambda-delta/basic_rg/brgOutput.mli b/helm/software/lambda-delta/basic_rg/brgOutput.mli index cd7e49dc5..9fa180abd 100644 --- a/helm/software/lambda-delta/basic_rg/brgOutput.mli +++ b/helm/software/lambda-delta/basic_rg/brgOutput.mli @@ -17,4 +17,4 @@ val count_item: (counters -> 'a) -> counters -> Brg.item -> 'a val print_counters: (unit -> 'a) -> counters -> 'a -val specs: (BrgReduction.context, Brg.term) Log.specs +val specs: (Brg.context, Brg.term) Log.specs diff --git a/helm/software/lambda-delta/basic_rg/brgReduction.ml b/helm/software/lambda-delta/basic_rg/brgReduction.ml index 74f6a5048..4cfd5260d 100644 --- a/helm/software/lambda-delta/basic_rg/brgReduction.ml +++ b/helm/software/lambda-delta/basic_rg/brgReduction.ml @@ -9,30 +9,25 @@ \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) -module U = NUri module C = Cps module S = Share module L = Log module B = Brg +module O = BrgOutput module E = BrgEnvironment -type environment = int * B.bind list +exception LRefNotFound of B.message -type stack = B.term list - -type context = { - g: environment; - l: environment; - s: stack +type machine = { + c: B.context; + s: B.term list } -exception LRefNotFound of (context, B.term) L.item list - type whd_result = | Sort_ of int | LRef_ of int * B.term option | GRef_ of int * B.bind - | Bind_ of B.term * B.term + | Bind_ of B.id * B.term * B.term type ho_whd_result = | Sort of int @@ -40,21 +35,30 @@ type ho_whd_result = (* Internal functions *******************************************************) -let error i = raise (LRefNotFound (L.items1 (string_of_int i))) +let level = 5 -let empty_e = 0, [] +let error i = raise (LRefNotFound (L.items1 (string_of_int i))) -let push_e f b (l, e) = - f (succ l, b :: e) +let empty_machine = {c = B.empty_context; s = []} -let get_e f c i = - let (gl, ge), (ll, le) = c.g, c.l in - if i >= gl + ll then error i; - let b = - if i < gl then List.nth ge (gl - (succ i)) - else List.nth le (gl + ll - (succ i)) +let get f c m i = + let f = function + | Some (_, b) -> f b + | None -> error i in - f b + let f gl _ = if i < gl then B.get f c i else B.get f m.c (i - gl) in + B.contents f c + +let contents f c m = + let f gl ges = B.contents (f gl ges) m.c in + B.contents f c + +let unwind_to_context f c m = B.append f c m.c + +let unwind_to_term f m t = + let map f t (id, b) = f (B.Bind (id, b, t)) in + let f _ mc = C.list_fold_left f map t mc in + B.contents f m.c let rec lref_map_bind f map b = match b with | B.Abbr v -> @@ -83,119 +87,117 @@ and lref_map f map t = match t with lref_map_bind f map b (* to share *) -let lift f c = - let (gl, _), (ll, le) = c.g, c.l in - let map i = if i >= gl then succ i else i in - let map f = function - | B.Abbr t -> let f t' = f (B.Abbr t') in lref_map f map t - | _ -> assert false +let lift f c m = + let f gl _ = + let map i = if i >= gl then succ i else i in + let map f = function + | id, B.Abbr t -> let f t = f (id, B.Abbr t) in lref_map f map t + | _ -> assert false + in + let f mc = f {m with c = mc} in + B.map f map m.c in - let f le' = f {c with l = (ll, le')} in - C.list_map f map le - -let xchg f c t = - let (gl, _), (ll, _) = c.g, c.l in - let map i = - if i < gl || i > gl + ll then i else - if i >= gl && i < gl + ll then succ i else gl + B.contents f c + +(* to share *) +let xchg f c m t = + let f gl _ ll _ = + let map i = + if i < gl || i > gl + ll then i else + if i >= gl && i < gl + ll then succ i else gl + in + lref_map f map t in - lref_map (f c) map t + contents f c m + +let push f c m id w t = + assert (m.s = []); + let f c m = xchg (f c m) c m t in + let f c = lift (f c) c m in + let f w = B.push f c id (B.Abst w) in + unwind_to_term f m w (* to share *) -let rec whd f c t = match t with - | B.Sort h -> f c (Sort_ h) +let rec whd f c m x = match x with + | B.Sort h -> f m (Sort_ h) | B.GRef uri -> - let f (i, _, b) = f c (GRef_ (i, b)) in + let f (i, _, b) = f m (GRef_ (i, b)) in E.get_obj f uri - | B.LRef i -> + | B.LRef i -> let f = function - | B.Void -> f c (LRef_ (i, None)) - | B.Abst t -> f c (LRef_ (i, Some t)) - | B.Abbr t -> whd f c t + | B.Void -> f m (LRef_ (i, None)) + | B.Abst t -> f m (LRef_ (i, Some t)) + | B.Abbr t -> whd f c m t in - get_e f c i - | B.Cast (_, t) -> whd f c t - | B.Appl (v, t) -> whd f {c with s = v :: c.s} t - | B.Bind (_, B.Abst w, t) -> - begin match c.s with - | [] -> f c (Bind_ (w, t)) + get f c m i + | B.Cast (_, t) -> whd f c m t + | B.Appl (v, t) -> whd f c {m with s = v :: m.s} t + | B.Bind (id, B.Abst w, t) -> + begin match m.s with + | [] -> f m (Bind_ (id, w, t)) | v :: tl -> - let f tl l = whd f {c with l = l; s = tl} t in - push_e (f tl) (B.Abbr v) c.l + let f mc = whd f c {c = mc; s = tl} t in + B.push f m.c id (B.Abbr (B.Cast (w, v))) end - | B.Bind (_, b, t) -> - let f l = whd f {c with l = l} t in - push_e f b c.l - -let push f c t = - assert (c.s = []); - let f c g = xchg f {c with g = g} t in - let f c = push_e (f c) B.Void c.g in - lift f c + | B.Bind (id, b, t) -> + let f mc = whd f c {m with c = mc} t in + B.push f m.c id b (* Interface functions ******************************************************) -let rec are_convertible f c1 t1 c2 t2 = - let rec aux c1' r1 c2' r2 = match r1, r2 with +let rec ho_whd f c m x = + let aux m = function + | Sort_ h -> f c (Sort h) + | Bind_ (_, w, _) -> + let f c = f c (Abst w) in unwind_to_context f c m + | LRef_ (_, Some w) -> ho_whd f c m w + | GRef_ (_, B.Abst u) -> ho_whd f c m u + | GRef_ (_, B.Abbr t) -> ho_whd f c m t + | LRef_ (_, None) -> assert false + | GRef_ (_, B.Void) -> assert false + in + whd aux c m x + +let ho_whd f c t = + L.log O.specs level (L.ct_items1 "Now scanning" c t); + ho_whd f c empty_machine t + +let rec are_convertible f c1 m1 t1 c2 m2 t2 = + let rec aux m1 r1 m2 r2 = match r1, r2 with | Sort_ h1, Sort_ h2 -> f (h1 = h2) | LRef_ (i1, _), LRef_ (i2, _) -> - if i1 = i2 then are_convertible_stacks f c1' c2' else f false + if i1 = i2 then are_convertible_stacks f c1 m1 c2 m2 else f false | GRef_ (a1, B.Abst _), GRef_ (a2, B.Abst _) -> - if a1 = a2 then are_convertible_stacks f c1' c2' else f false + if a1 = a2 then are_convertible_stacks f c1 m1 c2 m2 else f false | GRef_ (a1, B.Abbr v1), GRef_ (a2, B.Abbr v2) -> - if a1 = a2 then are_convertible_stacks f c1' c2' else - if a1 < a2 then whd (aux c1' r1) c2' v2 else - whd (aux_rev c2' r2) c1' v1 + if a1 = a2 then are_convertible_stacks f c1 m1 c2 m2 else + if a1 < a2 then whd (aux m1 r1) c2 m2 v2 else + whd (aux_rev m2 r2) c1 m1 v1 | _, GRef_ (_, B.Abbr v2) -> - whd (aux c1' r1) c2' v2 + whd (aux m1 r1) c2 m2 v2 | GRef_ (_, B.Abbr v1), _ -> - whd (aux_rev c2' r2) c1' v1 - | Bind_ (w1, t1), Bind_ (w2, t2) -> + whd (aux_rev m2 r2) c1 m1 v1 + | Bind_ (id1, w1, t1), Bind_ (id2, w2, t2) -> let f b = if b then - let f c1'' t1' = push (are_convertible f c1'' t1') c2' t2 in - push f c1' t1 + let f c1 m1 t1 = + push (are_convertible f c1 m1 t1) c2 m2 id2 w2 t2 + in + push f c1 m1 id1 w1 t1 else f false in - are_convertible f c1' w1 c2' w2 + are_convertible f c1 m1 w1 c2 m2 w2 | _ -> f false - and aux_rev c2 r2 c1 r1 = aux c1 r1 c2 r2 in - let f c1' r1 = whd (aux c1' r1) c2 t2 in - whd f c1 t1 - -and are_convertible_stacks f c1 c2 = - let map f v1 v2 = are_convertible f c1 v1 c2 v2 in - if List.length c1.s <> List.length c2.s then f false else - C.forall2 f map c1.s c2.s - -let are_convertible f c t1 t2 = are_convertible f c t1 c t2 - -let rec ho_whd f c t = - let aux c' = function - | Sort_ h -> f c' (Sort h) - | Bind_ (w, t) -> f c' (Abst w) - | LRef_ (_, Some w) -> ho_whd f c w - | GRef_ (_, B.Abst u) -> ho_whd f c u - | GRef_ (_, B.Abbr u) -> ho_whd f c u - | LRef_ (_, None) -> assert false - | GRef_ (_, B.Void) -> assert false - in - whd aux c t - -let push f c b = - assert (c.l = empty_e && c.s = []); - let f g = f {c with g = g} in - push_e f b c.g - -let get f c i = - let gl, ge = c.g in - if i >= gl then error i; - f (List.nth ge (gl - (succ i))) - -let empty_context = { - g = empty_e; l = empty_e; s = [] -} - -let iter f map c = - let _, ge = c.g in - C.list_iter f map ge + and aux_rev m2 r2 m1 r1 = aux m1 r1 m2 r2 in + let f m1 r1 = whd (aux m1 r1) c2 m2 t2 in + whd f c1 m1 t1 + +and are_convertible_stacks f c1 m1 c2 m2 = + let mm1, mm2 = {m1 with s = []}, {m2 with s = []} in + let map f v1 v2 = are_convertible f c1 mm1 v1 c2 mm2 v2 in + if List.length m1.s <> List.length m2.s then f false else + C.forall2 f map m1.s m2.s + +let are_convertible f c t1 t2 = + L.log O.specs level (L.ct_items2 "Now converting" c t1 "and" c t2); + are_convertible f c empty_machine t1 c empty_machine t2 diff --git a/helm/software/lambda-delta/basic_rg/brgReduction.mli b/helm/software/lambda-delta/basic_rg/brgReduction.mli index b3a79ecae..91a0289bb 100644 --- a/helm/software/lambda-delta/basic_rg/brgReduction.mli +++ b/helm/software/lambda-delta/basic_rg/brgReduction.mli @@ -9,22 +9,15 @@ \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) -type context -exception LRefNotFound of (context, Brg.term) Log.item list +exception LRefNotFound of Brg.message type ho_whd_result = | Sort of int | Abst of Brg.term -val empty_context: context +val ho_whd: + (Brg.context -> ho_whd_result -> 'a) -> Brg.context -> Brg.term -> 'a -val push: (context -> 'a) -> context -> Brg.bind -> 'a - -val get: (Brg.bind -> 'a) -> context -> int -> 'a - -val iter: (unit -> 'a) -> ((unit -> 'a) -> Brg.bind -> 'a) -> context -> 'a - -val are_convertible: (bool -> 'a) -> context -> Brg.term -> Brg.term -> 'a - -val ho_whd: (context -> ho_whd_result -> 'a) -> context -> Brg.term -> 'a +val are_convertible: + (bool -> 'a) -> Brg.context -> Brg.term -> Brg.term -> 'a diff --git a/helm/software/lambda-delta/basic_rg/brgType.ml b/helm/software/lambda-delta/basic_rg/brgType.ml index 60b5b75bc..fd2409945 100644 --- a/helm/software/lambda-delta/basic_rg/brgType.ml +++ b/helm/software/lambda-delta/basic_rg/brgType.ml @@ -15,46 +15,48 @@ module O = BrgOutput module E = BrgEnvironment module R = BrgReduction -exception TypeError of (R.context, B.term) Log.item list +exception TypeError of B.message (* Internal functions *******************************************************) +let level = 4 + let error1 s c t = raise (TypeError (L.ct_items1 s c t)) let error2 s1 c1 t1 s2 c2 t2 = raise (TypeError (L.ct_items2 s1 c1 t1 s2 c2 t2)) -let are_convertible f c t1 t2 = - L.log O.specs 4 (L.ct_items2 "Now converting" c t1 "and" c t2); - R.are_convertible f c t1 t2 - (* Interface functions ******************************************************) let rec type_of f g c x = - L.log O.specs 5 (L.ct_items1 "now checking" c x); + L.log O.specs level (L.ct_items1 "now checking" c x); match x with | B.Sort h -> f (B.Sort (g h)) | B.LRef i -> let f = function - | B.Abst w -> f w - | B.Abbr (B.Cast (w, v)) -> f w - | B.Abbr _ -> assert false - | B.Void -> assert false + | Some (_, B.Abst w) -> f w + | Some (_, B.Abbr (B.Cast (w, v))) -> f w + | Some (_, B.Abbr _) -> assert false + | Some (_, B.Void) -> + error1 "reference to excluded variable" c x + | None -> + error1 "variable not found" c x in - R.get f c i + B.get f c i | B.GRef uri -> let f = function | _, _, B.Abst w -> f w | _, _, B.Abbr (B.Cast (w, v)) -> f w | _, _, B.Abbr _ -> assert false - | _, _, B.Void -> assert false + | _, _, B.Void -> + error1 "reference to excluded object" c x in E.get_obj f uri | B.Bind (id, B.Abbr u, t) -> let f tt = f (B.Bind (id, B.Abbr u, tt)) in let f cc = type_of f g cc t in - let f u = R.push f c (B.Abbr u) in + let f u = B.push f c id (B.Abbr u) in let f uu = match u with | B.Cast _ -> f u | _ -> f (B.Cast (uu, u)) @@ -63,21 +65,22 @@ let rec type_of f g c x = | B.Bind (id, B.Abst u, t) -> let f tt = f (B.Bind (id, B.Abst u, tt)) in let f cc = type_of f g cc t in - let f _ = R.push f c (B.Abst u) in + let f _ = B.push f c id (B.Abst u) in type_of f g c u | B.Bind (id, B.Void, t) -> let f tt = f (B.Bind (id, B.Void, tt)) in let f cc = type_of f g cc t in - R.push f c B.Void + B.push f c id B.Void | B.Appl (v, t) -> let f tt cc = function | R.Sort _ -> error1 "not a function" c t | R.Abst w -> + L.log O.specs (succ level) (L.ct_items1 "Just scanned" cc w); let f b = if b then f (B.Appl (v, tt)) else error2 "the term" c v "must be of type" cc w in - type_of (are_convertible f cc w) g c v + type_of (R.are_convertible f cc w) g c v in let f tt = R.ho_whd (f tt) c t in type_of f g c t @@ -86,5 +89,5 @@ let rec type_of f g c x = if b then f u else error2 "the term" c t "must be of type" c u in - let f _ = type_of (are_convertible f c u) g c t in + let f _ = type_of (R.are_convertible f c u) g c t in type_of f g c u diff --git a/helm/software/lambda-delta/basic_rg/brgType.mli b/helm/software/lambda-delta/basic_rg/brgType.mli index dc6fc998d..05845ce61 100644 --- a/helm/software/lambda-delta/basic_rg/brgType.mli +++ b/helm/software/lambda-delta/basic_rg/brgType.mli @@ -9,7 +9,7 @@ \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) -exception TypeError of (BrgReduction.context, Brg.term) Log.item list +exception TypeError of Brg.message -val type_of: (Brg.term -> 'a) -> - Brg.hierarchy -> BrgReduction.context -> Brg.term -> 'a +val type_of: + (Brg.term -> 'a) -> Brg.hierarchy -> Brg.context -> Brg.term -> 'a diff --git a/helm/software/lambda-delta/basic_rg/brgUntrusted.ml b/helm/software/lambda-delta/basic_rg/brgUntrusted.ml index d08209f12..80a9d4fe7 100644 --- a/helm/software/lambda-delta/basic_rg/brgUntrusted.ml +++ b/helm/software/lambda-delta/basic_rg/brgUntrusted.ml @@ -11,7 +11,6 @@ module B = Brg module E = BrgEnvironment -module R = BrgReduction module T = BrgType (* Interface functions ******************************************************) @@ -22,5 +21,5 @@ let type_check f g = function | Some ((_, _, B.Abbr t) as obj) -> let f tt obj = f (Some (tt, obj)) in let f tt = E.set_obj (f tt) obj in - T.type_of f g R.empty_context t + T.type_of f g B.empty_context t | Some (_, _, B.Void) -> assert false diff --git a/helm/software/lambda-delta/basic_rg/brgUntrusted.mli b/helm/software/lambda-delta/basic_rg/brgUntrusted.mli index 7bf3c8793..1c79b77e3 100644 --- a/helm/software/lambda-delta/basic_rg/brgUntrusted.mli +++ b/helm/software/lambda-delta/basic_rg/brgUntrusted.mli @@ -9,5 +9,5 @@ \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) -val type_check: ((Brg.term * Brg.obj) option -> 'a) -> - Brg.hierarchy -> Brg.item -> 'a +val type_check: + ((Brg.term * Brg.obj) option -> 'a) -> Brg.hierarchy -> Brg.item -> 'a diff --git a/helm/software/lambda-delta/toplevel/top.ml b/helm/software/lambda-delta/toplevel/top.ml index 7504e2c0b..b3f65bb84 100644 --- a/helm/software/lambda-delta/toplevel/top.ml +++ b/helm/software/lambda-delta/toplevel/top.ml @@ -107,7 +107,12 @@ try if !L.level > 2 && !stage > 0 then MO.print_counters Cps.start st.mc; if !L.level > 2 && !stage > 1 then BrgO.print_counters Cps.start st.brgc; in - let help = "Usage: helena [ -V | -Ss | -m ] ..." in + let help = + "Usage: helena [ -V | -Ss | -m ] ...\n\n" ^ + "Summary levels: 0 just errors, 1 time stamps, 2 processed file names, \ + 3 data information, 4 typing information, 5 reduction information\n\n" ^ + "Stages: 0 parsing, 1 to intermediate, 2 to untrusted, 3 to trusted\n" + in let help_S = " Set summary level" in let help_V = " Show version information" in let help_m = " output intermediate representation" in -- 2.39.2