]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/helena/src/basic_rg/brgLP.ml
jet a change in dependences
[helm.git] / helm / software / helena / src / basic_rg / brgLP.ml
index 9b832b20e1b546ed1bc8b682a96dcf36300fb77e..8a8f9d4f296d160550d91cf5e6320f26ce67f003 100644 (file)
@@ -24,18 +24,25 @@ IFDEF MANAGER THEN
 
 (* Internal functions *******************************************************)
 
+let version = KP.sprintf "This file was generated by %s: do not edit" (G.version_string true)
+
 let ok = ref true
 
 let uris = ref []
 
+let chunk = ref 0
+
+let sub_och = ref stdout
+
 let top_age = 7000
 
-let size = 16
+let size = 250
 
 let base = "lp"
 
 let ext_lp = ".elpi"
 let ext_tj = ".mod"
+let ext_tj_sig = ".sig"
 
 let reserved = ["pi"; "sigma"; "nil"; "delay"; "in"; "with"; "resume"; "context"]
 
@@ -169,41 +176,85 @@ let close_out_lp2 och () =
 
 (* teyjus variant 2 *************************************************)
 
+let append_out name = 
+   open_out_gen [Open_append; Open_creat; Open_text] 0o666 name
+
+let sub_close () = if !sub_och <> stdout then close_out !sub_och
+
+let mk_name chunk =
+   let dir = KF.concat !G.manager_dir base in
+   let name = KP.sprintf "grundlagen%02u" chunk in
+   dir, name
+
 let output_entity_tj2 och st (_, na, u, b) =
    if na.E.n_apix <= !G.last then begin
-   out_comment och (KP.sprintf "constant %u" na.E.n_apix); 
+   if pred na.E.n_apix mod size = 0 then begin
+      sub_close ();
+      incr chunk;
+      let dir, name = mk_name !chunk in
+      let soch = open_out (KF.concat dir name ^ ext_tj_sig) in
+      out_preamble soch;
+      out_top_comment soch version;
+      out_clause soch (KP.sprintf "sig %s." name);
+      out_clause soch "accum_sig grundlagen.";
+      out_clause soch (KP.sprintf "type line+%02u t -> int -> t -> o." !chunk);
+      close_out soch;
+      let soch = open_out (KF.concat dir name ^ ext_tj) in
+      out_preamble soch;
+      out_top_comment soch version;
+      out_clause soch (KP.sprintf "module %s." name);
+      sub_och := soch
+   end;
+   out_comment !sub_och (KP.sprintf "constant %u" na.E.n_apix); 
    match b with
       | E.Abbr v ->
-         KP.fprintf och "g+line %a %u\n       %a\n.\n\n"
-            out_uri u (top_age - na.E.n_apix) (out_term st B.empty) v;
+         KP.fprintf !sub_och "line+%02u %a %u\n        %a\n.\n\n"
+            !chunk out_uri u (top_age - na.E.n_apix) (out_term st B.empty) v;
          uris := (true, u) :: !uris; !ok
       | E.Abst w ->
-         KP.fprintf och "g+line %a %u\n       %a\n.\n\n"
-            out_uri u (top_age - na.E.n_apix) (out_term st B.empty) w;
+         KP.fprintf !sub_och "line+%02u %a %u\n        %a\n.\n\n"
+            !chunk out_uri u (top_age - na.E.n_apix) (out_term st B.empty) w;
          uris := (false, u) :: !uris; !ok
       | E.Void   -> C.err ()
    end else !ok
 
 let close_out_tj2 och () =
-   let out_name (b, u) =
+   let out_name och (b, u) =
       let gde = if b then "gdef+2" else "gdec+2" in 
       KP.fprintf och "(%s %a\n" gde out_uri u
    in
    let rec out_pars och p =
       if p > 0 then begin KP.fprintf och "%s" ")"; out_pars och (pred p) end
    in
-   let rec out_list och chunk pars first items uris = match first, items, uris with
+   let rec out_list chunk pars first items uris = match first, items, uris with
       | true, _, _         ->
-         KP.fprintf och "g+list %u\n" chunk;
-         out_list och (succ chunk) pars false items uris
-      | false, _, []       -> KP.fprintf och "gtop%a.\n\n" out_pars pars
+         let dir, name = mk_name chunk in
+         let soch = append_out (KF.concat dir name ^ ext_tj) in
+         out_clause soch (KP.sprintf "g+line R C T :- line+%02u R C T, !." chunk);
+         KP.fprintf soch "g+list %u\n" chunk;
+         sub_och := soch;
+         out_list (succ chunk) pars false items uris
+      | false, _, []       ->
+         KP.fprintf !sub_och "gtop%a.\n\n" out_pars pars;
+         sub_close ()
       | false, 0, _        ->
-         KP.fprintf och "(genv %u)%a.\n\n" chunk out_pars pars;
-         out_list och chunk 0 true size uris
+         KP.fprintf !sub_och "(genv %u)%a.\n\n" chunk out_pars pars;
+         sub_close ();
+         out_list chunk 0 true size uris
       | false, _, hd :: tl ->
-         out_name hd; out_list och chunk (succ pars) false (pred items) tl
+         out_name !sub_och hd; out_list chunk (succ pars) false (pred items) tl
    in
-   out_list och 1 0 true size (List.rev !uris);
+   let rec out_accumulate c =
+      if !chunk < c then KP.fprintf och "\n" else begin
+         let _, name = mk_name c in
+         KP.fprintf och "accumulate %s.\n" name;
+         out_accumulate (succ c)
+      end
+   in
+   sub_close ();
+   out_list 1 0 true size (List.rev !uris);
+   KP.fprintf och "accumulate helena.\n";
+   out_accumulate 1;
    out_clause och "main :- grundlagen.";
    out_clause och "grundlagen :- gv+ (genv 1).";
    close_out och
@@ -265,7 +316,8 @@ let open_out_lp1 fname =
    let path = KF.concat dir fname in
    let och = open_out (path ^ "1" ^ ext_lp) in
    out_preamble och;
-   out_top_comment och (KP.sprintf "This file was generated by %s: do not edit" G.version_string);
+   out_top_comment och version;
+   out_clause och "accumulate helena.";
    out_clause och "main :- grundlagen.";
    out_clause och "grundlagen :- gv+";
    output_entity_lp1 och, close_out_lp1 och
@@ -275,17 +327,17 @@ let open_out_lp2 fname =
    let path = KF.concat dir fname in
    let och = open_out (path ^ "2" ^ ext_lp) in
    out_preamble och;
-   out_top_comment och (KP.sprintf "This file was generated by %s: do not edit" G.version_string);
+   out_top_comment och version;
+   out_clause och "accumulate helena.";
    output_entity_lp2 och, close_out_lp2 och
 
 let open_out_tj2 fname =
-   let dir = KF.concat !G.manager_dir base in 
-   let path = KF.concat dir fname in
-   let och = open_out (path ^ "2" ^ ext_tj) in
+   let dir = KF.concat !G.manager_dir base in
+   let path = KF.concat dir fname ^ "2" in
+   let och = open_out (path ^ ext_tj) in
    out_preamble och;
-   out_top_comment och (KP.sprintf "This file was generated by %s: do not edit" G.version_string);
+   out_top_comment och version;
    out_clause och "module grundlagen.";
-   out_clause och "accumulate helena.";
    output_entity_tj2 och, close_out_tj2 och
 
 let open_out_tj3 fname =
@@ -293,7 +345,7 @@ let open_out_tj3 fname =
    let path = KF.concat dir fname in
    let och = open_out (path ^ "3" ^ ext_tj) in
    out_preamble och;
-   out_top_comment och (KP.sprintf "This file was generated by %s: do not edit" G.version_string);
+   out_top_comment och version;
    out_clause och "module grundlagen.";
    out_clause och "accumulate helena.";
    output_entity_tj3 och, close_out_tj3 och