1 (* Copyright (C) 2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 (* mo file name, ma file name *)
29 exception NMacro of GrafiteAst.loc * GrafiteAst.nmacro
31 type 'a disambiguator_input = string * int * 'a
34 do_heavy_checks: bool ;
37 let basic_eval_unification_hint (t,n) status =
38 NCicUnifHint.add_user_provided_hint status t n
41 let inject_unification_hint =
42 let basic_eval_unification_hint (t,n)
43 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
46 if not alias_only then
47 let t = refresh_uri_in_term (status :> NCicEnvironment.status) t in
48 basic_eval_unification_hint (t,n) status
52 GrafiteTypes.Serializer.register#run "unification_hints"
53 basic_eval_unification_hint
56 let eval_unification_hint status t n =
57 let metasenv,subst,status,t =
58 GrafiteDisambiguate.disambiguate_nterm status None [] [] [] ("",0,t) in
60 let t = NCicUntrusted.apply_subst status subst [] t in
61 let status = basic_eval_unification_hint (t,n) status in
62 NCicLibrary.dump_obj status (inject_unification_hint (t,n))
65 let basic_index_obj l status =
69 List.fold_left (fun t k ->
70 NDiscriminationTree.DiscriminationTree.index t k v)
75 let basic_eval_interpretation ~alias_only (dsc, (symbol, args), cic_appl_pattern) status =
77 if not alias_only then
78 Interpretations.add_interpretation status dsc (symbol, args) cic_appl_pattern
83 (* FIXME! the uri should be filled with something meaningful! *)
84 [DisambiguateTypes.Symbol symbol,
85 GrafiteAst.Symbol_alias (symbol,None,dsc)]
87 GrafiteDisambiguate.add_to_disambiguation_univ status diff
90 let inject_interpretation =
91 let basic_eval_interpretation (dsc, (symbol, args), cic_appl_pattern)
92 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
97 NotationPt.NRefPattern (NReference.Ref (uri,spec)) ->
98 NotationPt.NRefPattern
99 (NReference.reference_of_spec (NCicLibrary.refresh_uri uri) spec)
100 | NotationPt.VarPattern _
101 | NotationPt.ImplicitPattern as x -> x
102 | NotationPt.ApplPattern l -> NotationPt.ApplPattern (List.map refresh l)
104 let cic_appl_pattern = refresh cic_appl_pattern in
105 basic_eval_interpretation ~alias_only (dsc, (symbol, args), cic_appl_pattern)
107 GrafiteTypes.Serializer.register#run "interpretation"
108 basic_eval_interpretation
111 let eval_interpretation status data=
112 let status = basic_eval_interpretation ~alias_only:false data status in
113 NCicLibrary.dump_obj status (inject_interpretation data)
116 let basic_eval_alias (mode,diff) status =
117 prerr_endline "basic_eval_alias";
118 GrafiteDisambiguate.add_to_disambiguation_univ status diff
122 let basic_eval_alias (mode,diff) ~refresh_uri_in_universe ~refresh_uri_in_term
123 ~refresh_uri_in_reference ~alias_only =
124 basic_eval_alias (mode,diff)
126 GrafiteTypes.Serializer.register#run "alias" basic_eval_alias
129 let eval_alias status data=
130 let status = basic_eval_alias data status in
131 NCicLibrary.dump_obj status (inject_alias data)
134 let basic_eval_input_notation (l1,l2) status =
135 GrafiteParser.extend status l1
137 let rec get_disamb = function
138 | [] -> Stdpp.dummy_loc,None,None
139 | (_,(NotationEnv.NoType,NotationEnv.DisambiguationValue dv))::_ -> dv
140 | _::tl -> get_disamb tl
142 let l2' = TermContentPres.instantiate_level2 status env (get_disamb env) l2 in
143 prerr_endline ("new l2 ast : " ^ (NotationPp.pp_term status l2'));
144 NotationPt.AttributedTerm (`Loc loc,l2'))
147 let inject_input_notation =
148 let basic_eval_input_notation (l1,l2)
149 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
152 if not alias_only then
154 CicNotationParser.refresh_uri_in_checked_l1_pattern
155 ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCicEnvironment.status))
156 ~refresh_uri_in_reference l1 in
157 let l2 = NotationUtil.refresh_uri_in_term
158 ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCicEnvironment.status))
159 ~refresh_uri_in_reference l2
161 basic_eval_input_notation (l1,l2) status
165 GrafiteTypes.Serializer.register#run "input_notation"
166 basic_eval_input_notation
169 let eval_input_notation status data=
170 let status = basic_eval_input_notation data status in
171 NCicLibrary.dump_obj status (inject_input_notation data)
174 let basic_eval_output_notation (l1,l2) status =
175 TermContentPres.add_pretty_printer status l2 l1
178 let inject_output_notation =
179 let basic_eval_output_notation (l1,l2)
180 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
183 if not alias_only then
185 CicNotationParser.refresh_uri_in_checked_l1_pattern
186 ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCicEnvironment.status))
187 ~refresh_uri_in_reference l1 in
188 let l2 = NotationUtil.refresh_uri_in_term
189 ~refresh_uri_in_term:(refresh_uri_in_term (status:>NCicEnvironment.status))
190 ~refresh_uri_in_reference l2
192 basic_eval_output_notation (l1,l2) status
196 GrafiteTypes.Serializer.register#run "output_notation"
197 basic_eval_output_notation
200 let eval_output_notation status data=
201 let status = basic_eval_output_notation data status in
202 NCicLibrary.dump_obj status (inject_output_notation data)
205 let record_index_obj =
206 let aux l ~refresh_uri_in_universe
207 ~refresh_uri_in_term ~refresh_uri_in_reference ~alias_only status
209 let refresh_uri_in_term = refresh_uri_in_term (status:>NCicEnvironment.status) in
210 if not alias_only then
213 (fun ks,v -> List.map refresh_uri_in_term ks, refresh_uri_in_term v)
218 GrafiteTypes.Serializer.register#run "index_obj" aux
221 let compute_keys status uri height kind =
222 let mk_item ty spec =
223 let orig_ty = NTacStatus.mk_cic_term [] ty in
224 let status,keys = NnAuto.keys_of_type status orig_ty in
228 snd (NTacStatus.term_of_cic_term status t (NTacStatus.ctx_of t)))
231 keys,NCic.Const(NReference.reference_of_spec uri spec)
235 | NCic.Fixpoint (ind,ifl,_) ->
237 (fun (_,_,rno,ty,_) i ->
238 if ind then mk_item ty (NReference.Fix (i,rno,height))
239 else mk_item ty (NReference.CoFix height)) ifl
240 | NCic.Inductive (b,lno,itl,_) ->
242 (fun (_,_,ty,_) i -> mk_item ty (NReference.Ind (b,i,lno))) itl
244 List.map (fun ((_,_,ty),i,j) -> mk_item ty (NReference.Con (i,j+1,lno)))
245 (List.flatten (HExtlib.list_mapi
246 (fun (_,_,_,cl) i -> HExtlib.list_mapi (fun x j-> x,i,j) cl)
248 | NCic.Constant (_,_,Some _, ty, _) ->
249 [ mk_item ty (NReference.Def height) ]
250 | NCic.Constant (_,_,None, ty, _) ->
251 [ mk_item ty NReference.Decl ]
255 let keys = List.filter
258 | (NCic.Appl (NCic.Meta _::_)) -> false
264 HLog.debug ("Indexing:" ^
265 status#ppterm ~metasenv:[] ~subst:[] ~context:[] t);
266 HLog.debug ("With keys:" ^ String.concat "\n" (List.map (fun t ->
267 status#ppterm ~metasenv:[] ~subst:[] ~context:[] t) keys));
272 HLog.debug ("Not indexing:" ^
273 status#ppterm ~metasenv:[] ~subst:[] ~context:[] t);
279 let index_obj_for_auto status (uri, height, _, _, kind) =
280 (*prerr_endline (string_of_int height);*)
281 let data = compute_keys status uri height kind in
282 let status = basic_index_obj data status in
283 NCicLibrary.dump_obj status (record_index_obj data)
286 let index_eq uri status =
287 let eq_status = status#eq_cache in
288 let eq_status = NCicParamod.index_obj status eq_status uri in
289 status#set_eq_cache eq_status
292 let record_index_eq =
293 let basic_index_eq uri
294 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
296 = if not alias_only then index_eq (NCicLibrary.refresh_uri uri) status else
299 GrafiteTypes.Serializer.register#run "index_eq" basic_index_eq
302 let index_eq_for_auto status uri =
303 if NnAuto.is_a_fact_obj status uri then
304 let newstatus = index_eq uri status in
305 if newstatus#eq_cache == status#eq_cache then status
307 ((*prerr_endline ("recording " ^ (NUri.string_of_uri uri));*)
308 NCicLibrary.dump_obj newstatus (record_index_eq uri))
310 ((*prerr_endline "Not a fact";*)
314 let inject_constraint =
315 let basic_eval_add_constraint (u1,u2)
316 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
319 if not alias_only then
320 let u1 = refresh_uri_in_universe u1 in
321 let u2 = refresh_uri_in_universe u2 in
322 (* NCicLibrary.add_constraint adds the constraint to the NCicEnvironment
323 * and also to the storage (for undo/redo). During inclusion of compiled
324 * files the storage must not be touched. *)
325 NCicEnvironment.add_lt_constraint status u1 u2;
330 GrafiteTypes.Serializer.register#run "constraints" basic_eval_add_constraint
333 let eval_add_constraint status u1 u2 =
334 let status = NCicLibrary.add_constraint status u1 u2 in
335 NCicLibrary.dump_obj status (inject_constraint (u1,u2))
338 let eval_ng_tac tac =
339 let rec aux f (text, prefix_len, tac) =
341 | GrafiteAst.NApply (_loc, t) -> NTactics.apply_tac (text,prefix_len,t)
342 | GrafiteAst.NSmartApply (_loc, t) ->
343 NnAuto.smart_apply_tac (text,prefix_len,t)
344 | GrafiteAst.NAssert (_loc, seqs) ->
347 (function (hyps,concl) ->
350 (id,`Decl t) -> id,`Decl (text,prefix_len,t)
351 |(id,`Def (b,t))->id,`Def((text,prefix_len,b),(text,prefix_len,t))
353 (text,prefix_len,concl))
355 | GrafiteAst.NAuto (_loc, (None,a)) ->
356 NnAuto.auto_tac ~params:(None,a) ?trace_ref:None
357 | GrafiteAst.NAuto (_loc, (Some (_,l),a)) ->
359 ~params:(Some List.map (fun x -> "",0,x) l,a) ?trace_ref:None
360 | GrafiteAst.NBranch _ -> NTactics.branch_tac ~force:false
361 | GrafiteAst.NCases (_loc, what, where) ->
363 ~what:(text,prefix_len,what)
364 ~where:(text,prefix_len,where)
365 | GrafiteAst.NCase1 (_loc,n) -> NTactics.case1_tac n
366 | GrafiteAst.NChange (_loc, pat, ww) ->
368 ~where:(text,prefix_len,pat) ~with_what:(text,prefix_len,ww)
369 | GrafiteAst.NConstructor (_loc,num,args) ->
370 NTactics.constructor_tac
371 ?num ~args:(List.map (fun x -> text,prefix_len,x) args)
372 | GrafiteAst.NCut (_loc, t) -> NTactics.cut_tac (text,prefix_len,t)
373 (*| GrafiteAst.NDiscriminate (_,what) -> NDestructTac.discriminate_tac ~what:(text,prefix_len,what)
374 | GrafiteAst.NSubst (_,what) -> NDestructTac.subst_tac ~what:(text,prefix_len,what)*)
375 | GrafiteAst.NClear (_loc, l) -> NTactics.clear_tac l
376 | GrafiteAst.NDestruct (_,dom,skip) -> NDestructTac.destruct_tac dom skip
377 | GrafiteAst.NDot _ -> NTactics.dot_tac
378 | GrafiteAst.NElim (_loc, what, where) ->
380 ~what:(text,prefix_len,what)
381 ~where:(text,prefix_len,where)
382 | GrafiteAst.NFocus (_,l) -> NTactics.focus_tac l
383 | GrafiteAst.NGeneralize (_loc, where) ->
384 NTactics.generalize_tac ~where:(text,prefix_len,where)
385 | GrafiteAst.NId _ -> (fun x -> x)
386 | GrafiteAst.NIntro (_loc,n) -> NTactics.intro_tac n
387 | GrafiteAst.NIntros (_loc,ns) -> NTactics.intros_tac ns
388 | GrafiteAst.NInversion (_loc, what, where) ->
389 NTactics.inversion_tac
390 ~what:(text,prefix_len,what)
391 ~where:(text,prefix_len,where)
392 | GrafiteAst.NLApply (_loc, t) -> NTactics.lapply_tac (text,prefix_len,t)
393 | GrafiteAst.NLetIn (_loc,where,what,name) ->
394 NTactics.letin_tac ~where:(text,prefix_len,where)
395 ~what:(text,prefix_len,what) name
396 | GrafiteAst.NMerge _ -> NTactics.merge_tac
397 | GrafiteAst.NPos (_,l) -> NTactics.pos_tac l
398 | GrafiteAst.NPosbyname (_,s) -> NTactics.case_tac s
399 | GrafiteAst.NReduce (_loc, reduction, where) ->
400 NTactics.reduce_tac ~reduction ~where:(text,prefix_len,where)
401 | GrafiteAst.NRewrite (_loc,dir,what,where) ->
402 NTactics.rewrite_tac ~dir ~what:(text,prefix_len,what)
403 ~where:(text,prefix_len,where)
404 | GrafiteAst.NSemicolon _ -> fun x -> x
405 | GrafiteAst.NShift _ -> NTactics.shift_tac
406 | GrafiteAst.NSkip _ -> NTactics.skip_tac
407 | GrafiteAst.NUnfocus _ -> NTactics.unfocus_tac
408 | GrafiteAst.NWildcard _ -> NTactics.wildcard_tac
409 | GrafiteAst.NTry (_,tac) -> NTactics.try_tac
410 (f f (text, prefix_len, tac))
411 | GrafiteAst.NAssumption _ -> NTactics.assumption_tac
412 | GrafiteAst.NBlock (_,l) ->
413 NTactics.block_tac (List.map (fun x -> aux f (text,prefix_len,x)) l)
414 |GrafiteAst.NRepeat (_,tac) ->
415 NTactics.repeat_tac (f f (text, prefix_len, tac))
417 aux aux tac (* trick for non uniform recursion call *)
420 let subst_metasenv_and_fix_names status =
421 let u,h,metasenv, subst,o = status#obj in
423 NCicUntrusted.map_obj_kind ~skip_body:true
424 (NCicUntrusted.apply_subst status subst []) o
426 status#set_obj(u,h,NCicUntrusted.apply_subst_metasenv status subst metasenv,subst,o)
429 let is_proof_irrelevant status context ty =
431 NCicReduction.whd status ~subst:[] context
432 (NCicTypeChecker.typeof status ~subst:[] ~metasenv:[] context ty)
434 NCic.Sort NCic.Prop -> true
435 | NCic.Sort _ -> false
439 let rec relevance_of status ?(context=[]) ty =
440 match NCicReduction.whd status ~subst:[] context ty with
442 not (is_proof_irrelevant status context s) ::
443 relevance_of status ~context:((n,NCic.Decl s)::context) t
447 let compute_relevance status uri =
449 NCic.Constant (_,name,bo,ty,attrs) ->
450 let relevance = relevance_of status ty in
451 NCic.Constant (relevance,name,bo,ty,attrs)
452 | NCic.Fixpoint (ind,funs,attrs) ->
455 (fun (_,name,recno,ty,bo) ->
456 let relevance = relevance_of status ty in
457 relevance,name,recno,ty,bo
460 NCic.Fixpoint (ind,funs,attrs)
461 | NCic.Inductive (ind,leftno,tys,attrs) ->
463 List.rev_map (fun (_,name,arity,_) -> name,NCic.Decl arity) tys in
464 let tysno = List.length tys in
467 (fun (_,name,arity,cons) ->
468 let relevance = relevance_of status arity in
473 NCicTypeChecker.debruijn status uri tysno ~subst:[] [] ty in
474 let relevance = relevance_of status ~context dety in
478 (relevance,name,arity,cons)
481 NCic.Inductive (ind,leftno,tys,attrs)
485 let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
487 | GrafiteAst.Include (loc, mode, fname) ->
488 let _root, baseuri, fullpath, _rrelpath =
489 Librarian.baseuri_of_script ~include_paths fname in
490 let baseuri = NUri.uri_of_string baseuri in
491 (* MATITA 1.0: keep WithoutPreferences? *)
492 let alias_only = (mode = GrafiteAst.OnlyPreferences) in
493 GrafiteTypes.Serializer.require
494 ~alias_only ~baseuri ~fname:fullpath status
495 | GrafiteAst.UnificationHint (loc, t, n) -> eval_unification_hint status t n
496 | GrafiteAst.NCoercion (loc, name, compose, None) ->
497 let status, t, ty, source, target =
498 let o_t = NotationPt.Ident (name,`Ambiguous) in
499 let metasenv,subst, status,t =
500 GrafiteDisambiguate.disambiguate_nterm
501 status None [] [] [] ("",0,o_t) in
502 assert( metasenv = [] && subst = []);
503 let ty = NCicTypeChecker.typeof status [] [] [] t in
506 | NCic.Appl (NCic.Const _ as r :: l) ->
507 NotationPt.Appl (NotationPt.NCic r ::
508 List.map (fun _ -> NotationPt.Implicit `JustOne)l)
509 | NCic.Const _ as r -> NotationPt.NCic r
510 | _ -> assert false in
511 let rec aux = function
512 | NCic.Prod (_,_, (NCic.Prod _ as rest)) -> aux rest
513 | NCic.Prod (name, src, tgt) -> (name, clean src), clean tgt
514 | _ -> assert false in aux ty in
515 status, o_t, NotationPt.NCic ty, source, target in
516 let status, composites =
517 NCicCoercDeclaration.eval_ncoercion status name compose t ty source
519 let mode = GrafiteAst.WithPreferences in (* MATITA 1.0: fixme *)
520 let aliases = GrafiteDisambiguate.aliases_for_objs status composites in
521 eval_alias status (mode,aliases)
522 | GrafiteAst.NCoercion (loc, name, compose, Some (t, ty, source, target)) ->
523 let status, composites =
524 NCicCoercDeclaration.eval_ncoercion status name compose t ty source
526 let mode = GrafiteAst.WithPreferences in (* MATITA 1.0: fixme *)
527 let aliases = GrafiteDisambiguate.aliases_for_objs status composites in
528 eval_alias status (mode,aliases)
529 | GrafiteAst.NQed (loc,index) ->
530 if status#ng_mode <> `ProofMode then
531 raise (GrafiteTypes.Command_error "Not in proof mode")
533 let uri,height,menv,subst,obj_kind = status#obj in
536 (GrafiteTypes.Command_error"You can't Qed an incomplete theorem")
539 NCicUntrusted.map_obj_kind
540 (NCicUntrusted.apply_subst status subst []) obj_kind in
541 let height = NCicTypeChecker.height_of_obj_kind status uri [] obj_kind in
542 (* fix the height inside the object *)
543 let rec fix () = function
544 | NCic.Const (NReference.Ref (u,spec)) when NUri.eq u uri ->
545 NCic.Const (NReference.reference_of_spec u
547 | NReference.Def _ -> NReference.Def height
548 | NReference.Fix (i,j,_) -> NReference.Fix(i,j,height)
549 | NReference.CoFix i -> NReference.CoFix i
550 | NReference.Ind _ | NReference.Con _
551 | NReference.Decl as s -> s))
552 | t -> NCicUtils.map status (fun _ () -> ()) () fix t
557 NCicUntrusted.map_obj_kind (fix ()) obj_kind
560 let obj_kind = compute_relevance status uri obj_kind in
561 let obj = uri,height,[],[],obj_kind in
562 let old_status = status in
563 let status = NCicLibrary.add_obj status obj in
564 let index_obj = index &&
566 NCic.Constant (_,_,_,_,(_,`Example,_))
567 | NCic.Fixpoint (_,_,(_,`Example,_)) -> false
572 let status = index_obj_for_auto status obj in
573 (try index_eq_for_auto status uri
580 with _ -> prerr_endline "got an exception"; status
582 (* prerr_endline (status#ppobj obj); *)
583 HLog.message ("New object: " ^ NUri.string_of_uri uri);
585 (*prerr_endline (status#ppobj obj);*)
586 let boxml = NCicElim.mk_elims status obj in
587 let boxml = boxml @ NCicElim.mk_projections status obj in
588 let status = status#set_ng_mode `CommandMode in
589 let xxaliases = GrafiteDisambiguate.aliases_for_objs status [uri] in
590 let mode = GrafiteAst.WithPreferences in (* MATITA 1.0: fixme *)
591 let status = eval_alias status (mode,xxaliases) in
597 eval_ncommand ~include_paths opts status
598 ("",0,GrafiteAst.NObj (HExtlib.dummy_floc,boxml,true))
600 if nstatus#ng_mode <> `CommandMode then
602 (*HLog.warn "error in generating projection/eliminator";*)
603 assert(status#ng_mode = `CommandMode);
609 | GrafiteDisambiguate.Error _
610 | NCicTypeChecker.TypeCheckerFailure _ ->
611 (*HLog.warn "error in generating projection/eliminator";*)
614 let _,_,_,_,nobj = obj in
615 let status = match nobj with
616 NCic.Inductive (is_ind,leftno,itl,_) ->
617 List.fold_left (fun status it ->
618 (let _,ind_name,ty,cl = it in
620 (fun status outsort ->
621 let status = status#set_ng_mode `ProofMode in
624 NInversion.mk_inverter
625 (ind_name ^ "_inv_" ^
626 (snd (NCicElim.ast_of_sort outsort)))
627 is_ind it leftno outsort status status#baseuri in
628 let _,_,menv,_,_ = invobj in
630 [] -> eval_ncommand ~include_paths opts status
631 ("",0,GrafiteAst.NQed (Stdpp.dummy_loc,false))
634 with _ -> (*HLog.warn "error in generating inversion principle"; *)
635 let status = status#set_ng_mode `CommandMode in status)
638 List.map (fun s -> NCic.Type s)
639 (NCicEnvironment.get_universes status)))) status itl
644 _,_,_,_,NCic.Inductive
645 (true,leftno,[_,_,_,[_,_,_]],(_,`Record fields))
648 (fun (name,is_coercion,arity) ->
649 if is_coercion then Some(name,leftno,arity) else None) fields
653 (fun status (name,cpos,arity) ->
655 let metasenv,subst,status,t =
656 GrafiteDisambiguate.disambiguate_nterm status None [] [] []
657 ("",0,NotationPt.Ident (name,`Ambiguous)) in
658 assert (metasenv = [] && subst = []);
660 NCicCoercDeclaration.
661 basic_eval_and_record_ncoercion_from_t_cpos_arity
663 status (name,true,t,cpos,arity) in
664 let aliases = GrafiteDisambiguate.aliases_for_objs status nuris in
665 eval_alias status (mode,aliases)
666 with GrafiteDisambiguate.Error _ ->
667 HLog.warn ("error in generating coercion: "^name);
674 NCicLibrary.time_travel old_status;
676 | GrafiteAst.NCopy (log,tgt,src_uri, map) ->
677 if status#ng_mode <> `CommandMode then
678 raise (GrafiteTypes.Command_error "Not in command mode")
680 let tgt_uri_ext, old_ok =
681 match NCicEnvironment.get_checked_obj status src_uri with
682 | _,_,[],[], (NCic.Inductive _ as ok) -> ".ind", ok
683 | _,_,[],[], (NCic.Fixpoint _ as ok) -> ".con", ok
684 | _,_,[],[], (NCic.Constant _ as ok) -> ".con", ok
687 let tgt_uri = NUri.uri_of_string (status#baseuri^"/"^tgt^tgt_uri_ext) in
688 let map = (src_uri, tgt_uri) :: map in
690 let rec subst () = function
691 | NCic.Meta _ -> assert false
692 | NCic.Const (NReference.Ref (u,spec)) as t ->
694 (NReference.reference_of_spec (List.assoc u map)spec)
696 | t -> NCicUtils.map status (fun _ _ -> ()) () subst t
698 NCicUntrusted.map_obj_kind ~skip_body:false (subst ()) old_ok
700 let ninitial_stack = Continuationals.Stack.of_nmetasenv [] in
701 let status = status#set_obj (tgt_uri,0,[],[],ok) in
702 (*prerr_endline (status#ppobj (tgt_uri,0,[],[],ok));*)
703 let status = status#set_stack ninitial_stack in
704 let status = subst_metasenv_and_fix_names status in
705 let status = status#set_ng_mode `ProofMode in
706 eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed (Stdpp.dummy_loc,false))
707 | GrafiteAst.NObj (loc,obj,index) ->
708 if status#ng_mode <> `CommandMode then
709 raise (GrafiteTypes.Command_error "Not in command mode")
712 GrafiteDisambiguate.disambiguate_nobj status
713 ~baseuri:status#baseuri (text,prefix_len,obj) in
714 let uri,height,nmenv,nsubst,nobj = obj in
715 let ninitial_stack = Continuationals.Stack.of_nmetasenv nmenv in
716 let status = status#set_obj obj in
717 let status = status#set_stack ninitial_stack in
718 let status = subst_metasenv_and_fix_names status in
719 let status = status#set_ng_mode `ProofMode in
722 eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed
723 (Stdpp.dummy_loc,index))
725 | GrafiteAst.NDiscriminator (loc, indty) ->
726 if status#ng_mode <> `CommandMode then
727 raise (GrafiteTypes.Command_error "Not in command mode")
729 let status = status#set_ng_mode `ProofMode in
730 let metasenv,subst,status,indty =
731 GrafiteDisambiguate.disambiguate_nterm status None [] [] [] (text,prefix_len,indty) in
732 let indtyno, (_,_,tys,_,_), leftno = match indty with
733 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,leftno))) as r) ->
734 indtyno, NCicEnvironment.get_checked_indtys status r, leftno
735 | _ -> prerr_endline ("engine: indty expected... (fix this error message)"); assert false in
736 let (_,ind_name,_,_ as it) = List.nth tys indtyno in
738 NDestructTac.mk_discriminator ~use_jmeq:true (ind_name ^ "_jmdiscr")
739 it leftno status status#baseuri in
740 let _,_,menv,_,_ = obj in
742 [] -> eval_ncommand ~include_paths opts status
743 ("",0,GrafiteAst.NQed(Stdpp.dummy_loc,false))
744 | _ -> prerr_endline ("Discriminator: non empty metasenv");
746 | GrafiteAst.NInverter (loc, name, indty, selection, sort) ->
747 if status#ng_mode <> `CommandMode then
748 raise (GrafiteTypes.Command_error "Not in command mode")
750 let metasenv,subst,status,sort = match sort with
751 | None -> [],[],status,NCic.Sort NCic.Prop
753 let metasenv,subst,status,sort =
754 GrafiteDisambiguate.disambiguate_nterm status None [] [] []
756 in metasenv,subst,status,sort
758 assert (metasenv = []);
759 let sort = NCicReduction.whd status ~subst [] sort in
764 raise (Invalid_argument (Printf.sprintf
765 "ninverter: found target %s, which is not a sort"
766 (status#ppterm ~metasenv ~subst ~context:[] sort))) in
767 let status = status#set_ng_mode `ProofMode in
768 let metasenv,subst,status,indty =
769 GrafiteDisambiguate.disambiguate_nterm status None [] [] subst
770 (text,prefix_len,indty) in
771 let indtyno,(_,leftno,tys,_,_) =
773 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
774 indtyno, NCicEnvironment.get_checked_indtys status r
776 prerr_endline ("engine: indty =" ^ status#ppterm ~metasenv:[]
777 ~subst:[] ~context:[] indty);
779 let it = List.nth tys indtyno in
781 NInversion.mk_inverter name true it leftno ?selection sort
782 status status#baseuri in
783 let _,_,menv,_,_ = obj in
786 eval_ncommand ~include_paths opts status
787 ("",0,GrafiteAst.NQed(Stdpp.dummy_loc,false))
789 | GrafiteAst.NUnivConstraint (loc,u1,u2) ->
790 eval_add_constraint status [`Type,u1] [`Type,u2]
791 (* ex lexicon commands *)
792 | GrafiteAst.Interpretation (loc, dsc, (symbol, args), cic_appl_pattern) ->
793 let cic_appl_pattern =
794 GrafiteDisambiguate.disambiguate_cic_appl_pattern status args
797 eval_interpretation status (dsc,(symbol, args),cic_appl_pattern)
798 | GrafiteAst.Notation (loc, dir, l1, associativity, precedence, l2) ->
799 prerr_endline ("new notation: " ^ (NotationPp.pp_term status l1));
801 CicNotationParser.check_l1_pattern
802 l1 (dir = Some `RightToLeft) precedence associativity
805 if dir <> Some `RightToLeft then eval_input_notation status (l1,l2)
809 if dir <> Some `LeftToRight then eval_output_notation status (l1,l2)
811 in prerr_endline ("new grammar:\n" ^ (Print_grammar.ebnf_of_term status));
813 | GrafiteAst.Alias (loc, spec) ->
815 (*CSC: Warning: this code should be factorized with the corresponding
816 code in DisambiguatePp *)
818 | GrafiteAst.Ident_alias (id,uri) ->
819 [DisambiguateTypes.Id id,spec]
820 | GrafiteAst.Symbol_alias (symb, uri, desc) ->
821 [DisambiguateTypes.Symbol symb,spec]
822 | GrafiteAst.Number_alias (uri,desc) ->
823 [DisambiguateTypes.Num,spec]
825 let mode = GrafiteAst.WithPreferences in(*assert false in (* VEDI SOPRA *) MATITA 1.0*)
826 eval_alias status (mode,diff)
829 let eval_comment opts status (text,prefix_len,c) = status
831 let rec eval_executable ~include_paths opts status (text,prefix_len,ex) =
833 | GrafiteAst.NTactic (_(*loc*), tacl) ->
834 if status#ng_mode <> `ProofMode then
835 raise (GrafiteTypes.Command_error "Not in proof mode")
840 let status = eval_ng_tac (text,prefix_len,tac) status in
841 prerr_endline "prima di subst_metasenv_and_fix_names";
842 subst_metasenv_and_fix_names status)
846 | GrafiteAst.NCommand (_, cmd) ->
847 eval_ncommand ~include_paths opts status (text,prefix_len,cmd)
848 | GrafiteAst.NMacro (loc, macro) ->
849 raise (NMacro (loc,macro))
851 and eval_ast ~include_paths ?(do_heavy_checks=false) status (text,prefix_len,st)
853 let opts = { do_heavy_checks = do_heavy_checks ; } in
855 | GrafiteAst.Executable (_,ex) ->
856 eval_executable ~include_paths opts status (text,prefix_len,ex)
857 | GrafiteAst.Comment (_,c) ->
858 eval_comment opts status (text,prefix_len,c)