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.
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_______________________________________________________________ *)
23 (* Internal functions *******************************************************)
33 let reserved = ["pi"; "sigma"; "nil"; "delay"; "in"; "with"; "resume"; "context"]
36 if List.mem n reserved then !G.alpha ^ n else n
38 let out_preamble och =
39 let ich = open_in !G.preamble in
40 let rec aux () = KP.fprintf och "%s\n" (input_line ich); aux () in
41 try aux () with End_of_file -> close_in ich
43 let out_top_comment och msg =
44 KP.fprintf och "%% %s\n\n" msg
46 let out_comment och msg =
47 KP.fprintf och "%% %s\n" msg
49 let out_clause och msg =
50 KP.fprintf och "%s\n\n" msg
53 let str = U.string_of_uri u in
56 if c = '.' then () else begin
57 output_char och (if c = '/' then '_' else c);
62 if n <= 0 then succ i else
63 strip (String.index_from str (succ i) '/') (pred n)
69 | true -> KP.fprintf och "%s" (alpha n)
70 | false -> KP.fprintf och "_"
72 let err () = f "" false in
75 let rec out_term st e och = function
77 let sort = if h = 0 then "k+0" else if h = 1 then "k+1" else assert false in
78 KP.fprintf och "(sort %s)" sort
80 let _, _, a, b = B.get e i in
81 KP.fprintf och "%a" out_name a
83 KP.fprintf och "%a" out_uri s
85 KP.fprintf och "(cast %a %a)" (out_term st e) u (out_term st e) t
87 KP.fprintf och "(appx %a %a)" (out_term st e) v (out_term st e) t
88 | B.Bind (a, B.Abst (n, w), t) ->
89 let a = R.alpha B.mem e a in
90 let ee = B.push e B.empty a (B.abst n w) in
91 let l = match N.to_string st n with
94 | _ -> ok := false; "?"
96 KP.fprintf och "(abst %s %a %a\\ %a)"
97 l (out_term st e) w out_name a (out_term st ee) t
98 | B.Bind (a, B.Abbr v, t) ->
99 let a = R.alpha B.mem e a in
100 let ee = B.push e B.empty a (B.abbr v) in
101 KP.fprintf och "(abbr %a %a\\ %a)"
102 (out_term st e) v out_name a (out_term st ee) t
103 | B.Bind (a, B.Void, t) ->
104 let a = R.alpha B.mem e a in
105 let ee = B.push e B.empty a (B.Void) in
106 KP.fprintf och "(void %a\\ %a)"
107 out_name a (out_term st ee) t
109 let output_entity och st (_, na, s, b) =
110 (* if na.E.n_apix <= 4500 then begin *)
111 out_comment och (KP.sprintf "constant %u" na.E.n_apix);
114 KP.fprintf och "(gdef c+%u %a\n %a\\\n" na.E.n_apix (out_term st B.empty) t out_uri s;
117 KP.fprintf och "(gdec c+%u %a\n%a\\\n" na.E.n_apix (out_term st B.empty) u out_uri s;
122 let close_out och () =
124 if !level <= 0 then KP.fprintf och "%s" "\n\n).\n"
125 else begin KP.fprintf och "%s" ")"; decr level; aux () end
127 KP.fprintf och "%s" "gtop";
128 aux (); close_out och
130 (* Interface functions ******************************************************)
133 let dir = KF.concat !G.manager_dir base in
134 let path = KF.concat dir fname in
135 let och = open_out (path ^ ext) in
137 out_top_comment och (KP.sprintf "This file was generated by %s: do not edit" G.version_string);
138 out_clause och "k+succ k+0 k+2.";
139 out_clause och "k+succ k+1 k+3.";
140 out_clause och "grundlagen :- gv+ (";
141 output_entity och, close_out och