}
type 'a eval_from_moo = { efm_go: GrafiteTypes.status ref -> string -> unit }
+
+let coercion_moo_statement_of uri =
+ GrafiteAst.Coercion
+ (DisambiguateTypes.dummy_floc, CicUtil.term_of_uri uri, false)
let eval_coercion status ~add_composites coercion =
let uri = CicUtil.uri_of_term coercion in
- let status = MatitaSync.add_coercion status ~add_composites uri in
+ let basedir = Helm_registry.get "matita.basedir" in
+ let compounds = LibrarySync.add_coercion ~add_composites ~basedir uri in
+ let moo_content = coercion_moo_statement_of uri in
+ let status = GrafiteTypes.add_moo_content [moo_content] status in
+ let status = MatitaSync.add_coercion status uri compounds in
{status with GrafiteTypes.proof_status = GrafiteTypes.No_proof}
let eval_tactical ~disambiguate_tactic status tac =
let eval_comment status c = status
+(* since the record syntax allows to declare coercions, we have to put this
+ * information inside the moo *)
+let add_coercions_of_record_to_moo obj lemmas status =
+ let attributes = CicUtil.attributes_of_obj obj in
+ let is_record = function `Class (`Record att) -> Some att | _-> None in
+ match HExtlib.list_findopt is_record attributes with
+ | None -> status
+ | Some fields ->
+ let is_a_coercion uri =
+ try
+ let obj,_ =
+ CicEnvironment.get_cooked_obj CicUniv.empty_ugraph uri in
+ let attrs = CicUtil.attributes_of_obj obj in
+ List.mem (`Class `Projection) attrs
+ with Not_found -> assert false
+ in
+ (* looking at the fields we can know the 'wanted' coercions, but not the
+ * actually generated ones. So, only the intersection between the wanted
+ * and the actual should be in the moo as coercion, while everithing in
+ * lemmas should go as aliases *)
+ let wanted_coercions =
+ HExtlib.filter_map
+ (function
+ | (name,true) ->
+ Some
+ (UriManager.uri_of_string
+ (GrafiteTypes.qualify status name ^ ".con"))
+ | _ -> None)
+ fields
+ in
+ prerr_endline "wanted coercions:";
+ List.iter
+ (fun u -> prerr_endline (UriManager.string_of_uri u))
+ wanted_coercions;
+ let coercions, moo_content =
+ List.split
+ (HExtlib.filter_map
+ (fun uri ->
+ let is_a_wanted_coercion =
+ List.exists (UriManager.eq uri) wanted_coercions in
+ if is_a_coercion uri && is_a_wanted_coercion then
+ Some (uri, coercion_moo_statement_of uri)
+ else
+ None)
+ lemmas)
+ in
+ List.iter
+ (fun u -> prerr_endline (UriManager.string_of_uri u))
+ coercions;
+ let status = GrafiteTypes.add_moo_content moo_content status in
+ List.fold_left
+ (fun status uri ->
+ MatitaSync.add_coercion status uri [])
+ status coercions
+
+let add_obj uri obj status =
+ let basedir = Helm_registry.get "matita.basedir" in
+ let lemmas = LibrarySync.add_obj uri obj basedir in
+ let status =
+ {status with GrafiteTypes.objects = uri::status.GrafiteTypes.objects} in
+ let status = MatitaSync.add_obj uri obj lemmas status in
+ status, lemmas
+
let rec eval_command = {ec_go = fun ~baseuri_of_script ~disambiguate_command opts status cmd ->
let status,cmd = disambiguate_command status cmd in
let cmd,notation_ids' = CicNotation.process_notation cmd in
"Proof not completed! metasenv is not empty!");
let name = UriManager.name_of_uri uri in
let obj = Cic.Constant (name,Some bo,ty,[],[]) in
- MatitaSync.add_obj uri obj
+ let status, _lemmas = add_obj uri obj status in
+ (* should we assert lemmas = [] ? *)
{status with GrafiteTypes.proof_status = GrafiteTypes.No_proof}
| GrafiteAst.Coercion (loc, coercion, add_composites) ->
eval_coercion status ~add_composites coercion
raise (GrafiteTypes.Command_error (
"metasenv not empty while giving a definition with body: " ^
CicMetaSubst.ppmetasenv [] metasenv));
- MatitaSync.add_obj uri obj
+ let status, lemmas = add_obj uri obj status in
+ let status = add_coercions_of_record_to_moo obj lemmas status in
{status with GrafiteTypes.proof_status = GrafiteTypes.No_proof}
} and eval_executable = {ee_go = fun ~baseuri_of_script ~disambiguate_tactic ~disambiguate_command opts status ex ->