+let rec compiler_loop fname big_bang mode buf =
+ let include_paths =
+ Helm_registry.get_list Helm_registry.string "matita.includes" in
+ let clean_baseuri = not (Helm_registry.get_bool "matita.preserve") in
+ let matita_debug = Helm_registry.get_bool "matita.debug" in
+ let bench_mode = Helm_registry.get_bool "matita.bench" in
+ try
+ run_script buf
+ (MatitaEngine.eval_from_stream ~first_statement_only:false ~include_paths
+ ~clean_baseuri)
+ with
+ | End_of_file -> ()
+ | Sys.Break as exn ->
+ if matita_debug then raise exn;
+ HLog.error "user break!";
+ pp_times fname bench_mode false big_bang;
+ if mode = `COMPILER then
+ clean_exit (Some ~-1)
+ else
+ pp_ocaml_mode ()
+ | GrafiteEngine.Drop ->
+ if mode = `COMPILER then
+ begin
+ pp_times fname bench_mode false big_bang;
+ clean_exit (Some 1)
+ end
+ else
+ pp_ocaml_mode ()
+ | GrafiteEngine.Macro (floc, f) ->
+ begin match f (get_macro_context !grafite_status) with
+ | _, GrafiteAst.Inline (_, style, suri, prefix) ->
+ let str =
+ ApplyTransformation.txt_of_inline_macro style suri prefix
+ ~map_unicode_to_tex:(Helm_registry.get_bool
+ "matita.paste_unicode_as_tex") in
+ !out str;
+ compiler_loop fname big_bang mode buf
+ | _ ->
+ let x, y = HExtlib.loc_of_floc floc in
+ HLog.error (sprintf "A macro has been found in a script at %d-%d" x y);
+ if mode = `COMPILER then
+ begin
+ pp_times fname bench_mode false big_bang;
+ clean_exit (Some 1)
+ end
+ else
+ pp_ocaml_mode ()
+ end
+ | HExtlib.Localized (floc,CicNotationParser.Parse_error err) ->
+ let (x, y) = HExtlib.loc_of_floc floc in
+ HLog.error (sprintf "Parse error at %d-%d: %s" x y err);
+ if mode = `COMPILER then
+ begin
+ pp_times fname bench_mode false big_bang;
+ clean_exit (Some 1)
+ end
+ else
+ pp_ocaml_mode ()
+ | exn ->
+ if matita_debug then raise exn;
+ if mode = `COMPILER then
+ begin
+ pp_times fname bench_mode false big_bang;
+ clean_exit (Some 3)
+ end
+ else
+ pp_ocaml_mode ()
+