+let rec compiler_loop fname =
+ (* initialization, MOVE OUTSIDE *)
+ let matita_debug = Helm_registry.get_bool "matita.debug" in
+ let bench_mode = Helm_registry.get_bool "matita.bench" in
+ let clean_baseuri = not (Helm_registry.get_bool "matita.preserve") in
+ let include_paths =
+ Helm_registry.get_list Helm_registry.string "matita.includes"
+ in
+ (* sanity checks *)
+ let _,baseuri,fname = Librarian.baseuri_of_script ~include_paths fname in
+ let moo_fname =
+ LibraryMisc.obj_file_of_baseuri ~must_exist:false ~baseuri ~writable:true
+ in
+ let lexicon_fname=
+ LibraryMisc.lexicon_file_of_baseuri ~must_exist:false ~baseuri ~writable:true
+ in
+ if Http_getter_storage.is_read_only baseuri then
+ HLog.error
+ (Printf.sprintf "uri %s belongs to a read-only repository" baseuri);
+ (* cleanup of previously compiled objects *)
+ if (not (Http_getter_storage.is_empty ~local:true baseuri) ||
+ LibraryClean.db_uris_of_baseuri baseuri <> []) && clean_baseuri
+ then begin
+ HLog.message ("baseuri " ^ baseuri ^ " is not empty");
+ HLog.message ("cleaning baseuri " ^ baseuri);
+ LibraryClean.clean_baseuris [baseuri];
+ assert (Http_getter_storage.is_empty ~local:true baseuri);
+ end;
+ (* create dir for XML files *)
+ if not (Helm_registry.get_opt_default Helm_registry.bool "matita.nodisk"
+ ~default:false)
+ then
+ HExtlib.mkdir
+ (Filename.dirname
+ (Http_getter.filename ~local:true ~writable:true (baseuri ^
+ "foo.con")));
+ (* begin of compilation *)
+ let grafite_status = GrafiteSync.init baseuri in
+ let lexicon_status =
+ CicNotation2.load_notation ~include_paths:[]
+ BuildTimeConf.core_notation_script
+ in
+ let big_bang = Unix.gettimeofday () in
+ let time = Unix.time () in
+ HLog.message ("compiling " ^ Filename.basename fname ^ " in " ^ baseuri);
+ let buf = Ulexing.from_utf8_channel (open_in fname) in
+ try
+ let grafite_status, lexicon_status =
+ run_script buf lexicon_status grafite_status
+ (MatitaEngine.eval_from_stream ~first_statement_only:false ~include_paths)
+ in
+ let elapsed = Unix.time () -. time in
+ let proof_status,moo_content_rev,lexicon_content_rev =
+ grafite_status.proof_status, grafite_status.moo_content_rev,
+ lexicon_status.LexiconEngine.lexicon_content_rev
+ in
+ if proof_status <> GrafiteTypes.No_proof then
+ (HLog.error
+ "there are still incomplete proofs at the end of the script";
+ pp_times fname bench_mode false big_bang;
+ clean_exit baseuri false)
+ else
+ (if Helm_registry.get_bool "matita.moo" then begin
+ (* FG: we do not generate .moo when dumping .mma files *)
+ GrafiteMarshal.save_moo moo_fname moo_content_rev;
+ LexiconMarshal.save_lexicon lexicon_fname lexicon_content_rev;
+ end;
+ let tm = Unix.gmtime elapsed in
+ let sec = string_of_int tm.Unix.tm_sec ^ "''" in
+ let min =
+ if tm.Unix.tm_min > 0 then (string_of_int tm.Unix.tm_min^"' ") else ""
+ in
+ let hou =
+ if tm.Unix.tm_hour > 0 then (string_of_int tm.Unix.tm_hour^"h ") else ""
+ in
+ HLog.message
+ (sprintf "execution of %s completed in %s." fname (hou^min^sec));
+ pp_times fname bench_mode true big_bang;
+ true)
+ with
+ | End_of_file -> HLog.error "End_of_file?!"; clean_exit baseuri false