]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/helena/src/basic_rg/brgELPI.ml
new options activated
[helm.git] / helm / software / helena / src / basic_rg / brgELPI.ml
index 0ead752807986204f85ca6db85fddd71a87fb6da..969cb8ae99f8c7e298abe89699a3ee021bd0d34e 100644 (file)
@@ -24,7 +24,7 @@ module B  = Brg
 
 let ok = ref true
 
-let level = ref 0
+let uris = ref []
 
 let base = "elpi"
 
@@ -74,7 +74,7 @@ let out_name och a =
 
 let rec out_term st e och = function
    | B.Sort (_, h)                   ->
-      let sort = if h = 0 then "k+0" else if h = 1 then "k+1" else assert false in
+      let sort = if h = 0 then "k+set" else if h = 1 then "k+prop" else assert false in
       KP.fprintf och "(sort %s)" sort
    | B.LRef (_, i)                   ->
       let _, _, a, b = B.get e i in
@@ -83,12 +83,13 @@ let rec out_term st e och = function
       KP.fprintf och "%a" out_uri s
    | B.Cast (_, u, t)                ->
       KP.fprintf och "(cast %a %a)" (out_term st e) u (out_term st e) t 
-   | B.Appl (_, v, t)                ->
-      KP.fprintf och "(appr %a %a)" (out_term st e) v (out_term st e) t
-   | B.Bind (a, B.Abst (x, n, w), t) ->
+   | B.Appl (_, x, v, t)             ->
+      let c = if x then "appx" else "appr" in
+      KP.fprintf och "(%s %a %a)" c (out_term st e) v (out_term st e) t
+   | B.Bind (a, B.Abst (r, n, w), t) ->
       let a = R.alpha B.mem e a in
-      let ee = B.push e B.empty a (B.abst x n w) in
-      let c = if x then "prod" else "abst" in
+      let ee = B.push e B.empty a (B.abst r n w) in
+      let c = if r then "prod" else "abst" in
       let l = match N.to_string st n with
          | "1" -> "l+1"
          | "2" -> "l+2"
@@ -107,35 +108,75 @@ let rec out_term st e och = function
       KP.fprintf och "(void %a\\ %a)"
           out_name a (out_term st ee) t
 
-let output_entity och st (_, na, s, b) =
+(* variant 1 *************************************************)
+
+let output_entity_1 och st (_, na, s, b) =
 (*   if na.E.n_apix <= 4500 then begin *)
-   out_comment och (KP.sprintf "constant %u" na.E.n_apix);
+(*   out_comment och (KP.sprintf "constant %u" na.E.n_apix); *)
    match b with
       | E.Abbr t ->
-         KP.fprintf och "(gdef c+%u %a\n %a\\\n" na.E.n_apix (out_term st B.empty) t out_uri s;
-         incr level; !ok
+         KP.fprintf och "(gdef+1 c+%u %a\n %a\\\n" na.E.n_apix (out_term st B.empty) t out_uri s;
+         uris := (true, s) :: !uris; !ok
       | E.Abst u ->
-         KP.fprintf och "(gdec c+%u %a\n%a\\\n" na.E.n_apix (out_term st B.empty) u out_uri s;
-         incr level; !ok
+         KP.fprintf och "(gdec+1 c+%u %a\n%a\\\n" na.E.n_apix (out_term st B.empty) u out_uri s;
+         uris := (false, s) :: !uris; !ok
       | E.Void   -> C.err ()
 (*   end else !ok *)
 
-let close_out och () =
-   let rec aux () =
-      if !level <= 0 then KP.fprintf och "%s" "\n\n).\n" 
-      else begin KP.fprintf och "%s" ")"; decr level; aux () end
+let close_out_1 och () =
+   let aux_sep _ = KP.fprintf och "%s" ")" in
+   KP.fprintf och "%s" "gtop";   
+   List.iter aux_sep !uris;
+   out_clause och "\n\n).";
+   close_out och
+
+(* Variant 2 *************************************************)
+
+let output_entity_2 och st (_, na, s, b) =
+(*   out_comment och (KP.sprintf "constant %u" na.E.n_apix); *)
+(*   if na.E.n_apix <= 9 then begin *)
+   match b with
+      | E.Abbr t ->
+         KP.fprintf och "g+line %a c+%u\n       %a\n.\n\n"
+            out_uri s na.E.n_apix (out_term st B.empty) t;
+         uris := (true, s) :: !uris; !ok
+      | E.Abst u ->
+         KP.fprintf och "g+line %a c+%u\n       %a\n.\n\n"
+            out_uri s na.E.n_apix (out_term st B.empty) u;
+         uris := (false, s) :: !uris; !ok
+      | E.Void   -> C.err ()
+(*   end else !ok *)
+
+let close_out_2 och () =
+   let aux_name (b, s) =
+      let gde = if b then "gdef+2" else "gdec+2" in 
+      KP.fprintf och "(%s %a\n" gde out_uri s
    in
+   let aux_sep _ = KP.fprintf och "%s" ")" in
+   out_clause och "main :- grundlagen.";
+   out_clause och "grundlagen :- (gv+ ";
+   List.iter aux_name (List.rev !uris);
    KP.fprintf och "%s" "gtop";
-   aux (); close_out och
+   List.iter aux_sep !uris;
+   out_clause och "\n\n).";
+   close_out och
 
 (* Interface functions ******************************************************)
 
-let open_out fname =
+let open_out_1 fname =
    let dir = KF.concat !G.manager_dir base in 
    let path = KF.concat dir fname in
-   let och = open_out (path ^ ext) in
+   let och = open_out (path ^ "1" ^ ext) in
    out_preamble och;
    out_top_comment och (KP.sprintf "This file was generated by %s: do not edit" G.version_string);
    out_clause och "main :- grundlagen.";
    out_clause och "grundlagen :- gv+ (";
-   output_entity och, close_out och
+   output_entity_1 och, close_out_1 och
+
+let open_out_2 fname =
+   let dir = KF.concat !G.manager_dir base in 
+   let path = KF.concat dir fname in
+   let och = open_out (path ^ "2" ^ ext) in
+   out_preamble och;
+   out_top_comment och (KP.sprintf "This file was generated by %s: do not edit" G.version_string);
+   output_entity_2 och, close_out_2 och