- fixed redundancy in moo: aliases, interpretation, and default commands are always present only once in a single moo
- added MatitaTypes.add_moo_content: from now on it must be then only function used to add content to moo objects
*)
open Printf
+
open MatitaTypes
exception Drop;;
let set_goals (status,_) goals = status,goals
let id_tac status =
- apply_tactic (GrafiteAst.IdTac Disambiguate.dummy_floc) status
+ apply_tactic (GrafiteAst.IdTac DisambiguateTypes.dummy_floc) status
let mk_tactic tac = tac
List.fold_left (fun s (uri,o,ugraph) -> MatitaSync.add_obj uri o status)
status new_coercions in
let statement_of name =
- GrafiteAstPp.pp_statement
- (GrafiteAst.Executable (Disambiguate.dummy_floc,
- (GrafiteAst.Command (Disambiguate.dummy_floc,
- (GrafiteAst.Coercion (Disambiguate.dummy_floc,
- (CicNotationPt.Ident (name, None)))))))) ^ "\n"
+ GrafiteAst.Coercion (DisambiguateTypes.dummy_floc,
+ (CicNotationPt.Ident (name, None)))
in
- let moo_content_rev =
- [statement_of (UriManager.name_of_uri coer_uri)] @
+ let moo_content =
+ statement_of (UriManager.name_of_uri coer_uri) ::
(List.map
(fun (uri, _, _) ->
statement_of (UriManager.name_of_uri uri))
- new_coercions) @ status.moo_content_rev
+ new_coercions)
in
- let status = {status with moo_content_rev = moo_content_rev} in
- {status with proof_status = No_proof}
+ let status = add_moo_content moo_content status in
+ { status with proof_status = No_proof }
let generate_elimination_principles uri status =
let elim sort status =
match cmd with
| GrafiteAst.Default (loc, what, uris) as cmd ->
LibraryObjects.set_default what uris;
- {status with moo_content_rev =
- (GrafiteAstPp.pp_command cmd ^ "\n") :: status.moo_content_rev}
+ add_moo_content [cmd] status
| GrafiteAst.Include (loc, path) ->
let absolute_path = make_absolute opts.include_paths path in
let moopath = MatitaMisc.obj_file_of_script absolute_path in
| GrafiteAst.Render _ -> assert false (* ZACK: to be removed *)
| GrafiteAst.Dump _ -> assert false (* ZACK: to be removed *)
| GrafiteAst.Interpretation (_, dsc, (symbol, _), _) as stm ->
- let status' =
- { status with
- moo_content_rev =
- (GrafiteAstPp.pp_command stm ^ "\n") :: status.moo_content_rev }
- in
+ let status' = add_moo_content [stm] status in
let aliases' =
DisambiguateTypes.Environment.cons
(DisambiguateTypes.Symbol (symbol, 0))
status.aliases
in
MatitaSync.set_proof_aliases status' aliases'
- | GrafiteAst.Notation _ as stm ->
- { status with moo_content_rev =
- (GrafiteAstPp.pp_command stm ^ "\n") :: status.moo_content_rev }
+ | GrafiteAst.Notation _ as stm -> add_moo_content [stm] status
| GrafiteAst.Obj (loc,obj) ->
let ext,name =
match obj with
let set_proof_aliases status aliases =
let new_status = { status with aliases = aliases } in
let diff = alias_diff ~from:status new_status in
- let textual_diff =
- if DisambiguateTypes.Environment.is_empty diff then
- ""
- else
- DisambiguatePp.pp_environment diff ^ "\n" in
- let moo_content_rev = textual_diff :: status.moo_content_rev in
- {new_status with moo_content_rev = moo_content_rev}
+ if DisambiguateTypes.Environment.is_empty diff then
+ new_status
+ else
+ add_moo_content (DisambiguatePp.commands_of_environment diff) new_status
(** given a uri and a type list (the contructors types) builds a list of pairs
* (name,uri) that is used to generate authomatic aliases **)
type options = option_value StringMap.t
let no_options = StringMap.empty
+type ast_command = (CicNotationPt.term, GrafiteAst.obj) GrafiteAst.command
+
type status = {
- aliases : DisambiguateTypes.environment;
- moo_content_rev : string list;
- proof_status : proof_status;
- options : options;
- objects : (UriManager.uri * string) list;
+ aliases: DisambiguateTypes.environment;
+ moo_content_rev: ast_command list;
+ proof_status: proof_status;
+ options: options;
+ objects: (UriManager.uri * string) list;
notation_ids: CicNotation.notation_id list;
}
in
{ status with proof_status = proof_status }
+let add_moo_content cmds status =
+ let content = status.moo_content_rev in
+ let content' =
+ List.fold_right
+ (fun cmd acc ->
+(* prerr_endline ("adding to moo command: " ^ GrafiteAstPp.pp_command cmd); *)
+ match cmd with
+ | GrafiteAst.Interpretation _
+ | GrafiteAst.Default _ ->
+ if List.mem cmd content then acc
+ else cmd :: acc
+ | GrafiteAst.Alias _ -> (* move Alias as the last inserted one *)
+ cmd :: (List.filter ((<>) cmd) acc)
+ | _ -> cmd :: acc)
+ cmds content
+ in
+(* prerr_endline ("new moo content: " ^ String.concat " " (List.map
+ GrafiteAstPp.pp_command content')); *)
+ { status with moo_content_rev = content' }
+
let dump_status status =
MatitaLog.message "status.aliases:\n";
MatitaLog.message
type options = option_value StringMap.t
val no_options : 'a StringMap.t
+type ast_command = (CicNotationPt.term, GrafiteAst.obj) GrafiteAst.command
+
type status = {
aliases: DisambiguateTypes.environment; (** disambiguation aliases *)
- moo_content_rev: string list;(*CSC: GrafiteAst.command list would be better *)
+ moo_content_rev: ast_command list;
proof_status: proof_status;
options: options;
objects: (UriManager.uri * string) list; (** in-scope objects, with paths *)
val set_metasenv: Cic.metasenv -> status -> status
+ (** list is not reversed, head command will be the first emitted *)
+val add_moo_content: ast_command list -> status -> status
+
val dump_status : status -> unit
val get_option : status -> StringMap.key -> option_value
val get_string_option : status -> StringMap.key -> string
let os = open_out (MatitaMisc.obj_file_of_script file) in
let output s = output_string os s in
output "(* GENERATED FILE: DO NOT EDIT! *)\n\n";
- List.iter output (List.rev moo);
+ List.iter
+ (fun cmd -> output (GrafiteAstPp.pp_command cmd ^ "\n"))
+ (List.rev moo);
close_out os
let main ~mode =
val main : mode:[ `COMPILER | `TOPLEVEL ] -> unit
(** fname is the .ma *)
-val dump_moo_to_file: string -> string list -> unit
+val dump_moo_to_file:
+ string ->
+ (CicNotationPt.term, GrafiteAst.obj) GrafiteAst.command list ->
+ unit
(** clean_exit n
if n = Some n it performs an exit [n] after a complete clean-up of what was