3 let cap = String.capitalize_ascii
6 if b then "KO" else "OO"
9 let file = name ^ ".mli" in
10 if Sys.file_exists file then ()
12 let och = open_out file in
16 let write_subst st och subst =
18 let lhs = List.map (Printf.sprintf "%S :: ") words in
19 let rhs = List.map (Printf.sprintf "%S :: ") hd in
20 Printf.fprintf och " | %stl -> k T.OK (%souts) tl\n"
21 (String.concat "" lhs) (String.concat "" rhs)
25 | hd :: _ -> List.iter (iter (List.rev hd)) subst
27 let write_component st =
28 let cmod = "recommGc" ^ st.ET.cmod in
29 let och = open_out (cmod ^ ".ml") in
30 Printf.fprintf och "module T = RecommTypes\n";
31 Printf.fprintf och "module R = Recomm%s\n" (cap st.ET.rmod);
32 if st.ET.dmod <> "" then begin
33 Printf.fprintf och "module D = Recomm%s\n" (cap st.ET.dmod)
35 Printf.fprintf och "\n";
36 Printf.fprintf och "let step k st outs ins =\n";
37 if st.ET.para then begin
38 Printf.fprintf och " if st <> T.OO then k st outs ins else\n"
40 Printf.fprintf och " if st = T.KO then k st outs ins else\n"
42 Printf.fprintf och " match ins with\n";
43 List.iter (write_subst st och) st.ET.substs;
44 Printf.fprintf och " | _ -> k T.%s outs ins\n\n" (ko st.ET.optn);
45 Printf.fprintf och "let main =\n";
46 Printf.fprintf och " R.register_%s step\n" st.ET.rfun;
51 let p = float (List.length st.ET.mods) in
53 if p > 0. then truncate (log10 p) else -1
55 let ps = Printf.sprintf "%%0%uu" (succ p) in
56 let fmt = Scanf.format_from_string ps "%u" in
57 let cmod = Filename.concat st.ET.cdir "recommGc" in
58 let och = open_out (cmod ^ ".ml") in
60 Printf.fprintf och "module G%(%u%) = RecommGc%s\n" fmt (succ i) name
62 List.iteri iter st.ET.mods;