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 t in basic_eval_unification_hint (t,n) status
51 GrafiteTypes.Serializer.register#run "unification_hints"
52 basic_eval_unification_hint
55 let eval_unification_hint status t n =
56 let metasenv,subst,status,t =
57 GrafiteDisambiguate.disambiguate_nterm status None [] [] [] ("",0,t) in
59 let t = NCicUntrusted.apply_subst subst [] t in
60 let status = basic_eval_unification_hint (t,n) status in
61 NCicLibrary.dump_obj status (inject_unification_hint (t,n))
64 let basic_index_obj l status =
68 List.fold_left (fun t k ->
69 NDiscriminationTree.DiscriminationTree.index t k v)
74 let basic_eval_interpretation ~alias_only (dsc, (symbol, args), cic_appl_pattern) status =
76 if not alias_only then
77 Interpretations.add_interpretation status dsc (symbol, args) cic_appl_pattern
81 let mode = GrafiteAst.WithPreferences (*assert false*) in (* MATITA 1.0 VEDI SOTTO *)
83 [DisambiguateTypes.Symbol (symbol, 0), GrafiteAst.Symbol_alias (symbol,0,dsc)]
85 GrafiteDisambiguate.set_proof_aliases status ~implicit_aliases:false mode diff
88 let inject_interpretation =
89 let basic_eval_interpretation (dsc, (symbol, args), cic_appl_pattern)
90 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
95 NotationPt.NRefPattern (NReference.Ref (uri,spec)) ->
96 NotationPt.NRefPattern
97 (NReference.reference_of_spec (NCicLibrary.refresh_uri uri) spec)
98 | NotationPt.VarPattern _
99 | NotationPt.ImplicitPattern as x -> x
100 | NotationPt.ApplPattern l -> NotationPt.ApplPattern (List.map refresh l)
102 let cic_appl_pattern = refresh cic_appl_pattern in
103 basic_eval_interpretation ~alias_only (dsc, (symbol, args), cic_appl_pattern)
105 GrafiteTypes.Serializer.register#run "interpretation"
106 basic_eval_interpretation
109 let eval_interpretation status data=
110 let status = basic_eval_interpretation ~alias_only:false data status in
111 NCicLibrary.dump_obj status (inject_interpretation data)
114 let basic_eval_alias (mode,diff) status =
115 GrafiteDisambiguate.set_proof_aliases status ~implicit_aliases:false mode diff
119 let basic_eval_alias (mode,diff) ~refresh_uri_in_universe ~refresh_uri_in_term
120 ~refresh_uri_in_reference ~alias_only =
121 basic_eval_alias (mode,diff)
123 GrafiteTypes.Serializer.register#run "alias" basic_eval_alias
126 let eval_alias status data=
127 let status = basic_eval_alias data status in
128 NCicLibrary.dump_obj status (inject_alias data)
131 let basic_eval_input_notation (l1,l2) status =
132 GrafiteParser.extend status l1
134 NotationPt.AttributedTerm
135 (`Loc loc,TermContentPres.instantiate_level2 env l2))
138 let inject_input_notation =
139 let basic_eval_input_notation (l1,l2)
140 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
143 if not alias_only then
145 CicNotationParser.refresh_uri_in_checked_l1_pattern
146 ~refresh_uri_in_term ~refresh_uri_in_reference l1 in
147 let l2 = NotationUtil.refresh_uri_in_term
148 ~refresh_uri_in_term ~refresh_uri_in_reference l2
150 basic_eval_input_notation (l1,l2) status
154 GrafiteTypes.Serializer.register#run "input_notation"
155 basic_eval_input_notation
158 let eval_input_notation status data=
159 let status = basic_eval_input_notation data status in
160 NCicLibrary.dump_obj status (inject_input_notation data)
163 let basic_eval_output_notation (l1,l2) status =
164 TermContentPres.add_pretty_printer status l2 l1
167 let inject_output_notation =
168 let basic_eval_output_notation (l1,l2)
169 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
172 if not alias_only then
174 CicNotationParser.refresh_uri_in_checked_l1_pattern
175 ~refresh_uri_in_term ~refresh_uri_in_reference l1 in
176 let l2 = NotationUtil.refresh_uri_in_term
177 ~refresh_uri_in_term ~refresh_uri_in_reference l2
179 basic_eval_output_notation (l1,l2) status
183 GrafiteTypes.Serializer.register#run "output_notation"
184 basic_eval_output_notation
187 let eval_output_notation status data=
188 let status = basic_eval_output_notation data status in
189 NCicLibrary.dump_obj status (inject_output_notation data)
192 let record_index_obj =
193 let aux l ~refresh_uri_in_universe
194 ~refresh_uri_in_term ~refresh_uri_in_reference ~alias_only status
196 if not alias_only then
199 (fun ks,v -> List.map refresh_uri_in_term ks, refresh_uri_in_term v)
204 GrafiteTypes.Serializer.register#run "index_obj" aux
207 let compute_keys status uri height kind =
208 let mk_item ty spec =
209 let orig_ty = NTacStatus.mk_cic_term [] ty in
210 let status,keys = NnAuto.keys_of_type status orig_ty in
214 snd (NTacStatus.term_of_cic_term status t (NTacStatus.ctx_of t)))
217 keys,NCic.Const(NReference.reference_of_spec uri spec)
221 | NCic.Fixpoint (ind,ifl,_) ->
223 (fun (_,_,rno,ty,_) i ->
224 if ind then mk_item ty (NReference.Fix (i,rno,height))
225 else mk_item ty (NReference.CoFix height)) ifl
226 | NCic.Inductive (b,lno,itl,_) ->
228 (fun (_,_,ty,_) i -> mk_item ty (NReference.Ind (b,i,lno))) itl
230 List.map (fun ((_,_,ty),i,j) -> mk_item ty (NReference.Con (i,j+1,lno)))
231 (List.flatten (HExtlib.list_mapi
232 (fun (_,_,_,cl) i -> HExtlib.list_mapi (fun x j-> x,i,j) cl)
234 | NCic.Constant (_,_,Some _, ty, _) ->
235 [ mk_item ty (NReference.Def height) ]
236 | NCic.Constant (_,_,None, ty, _) ->
237 [ mk_item ty NReference.Decl ]
241 let keys = List.filter
244 | (NCic.Appl (NCic.Meta _::_)) -> false
250 HLog.debug ("Indexing:" ^
251 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t);
252 HLog.debug ("With keys:" ^ String.concat "\n" (List.map (fun t ->
253 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t) keys));
258 HLog.debug ("Not indexing:" ^
259 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t);
265 let index_obj_for_auto status (uri, height, _, _, kind) =
266 (*prerr_endline (string_of_int height);*)
267 let data = compute_keys status uri height kind in
268 let status = basic_index_obj data status in
269 NCicLibrary.dump_obj status (record_index_obj data)
272 let index_eq uri status =
273 let eq_status = status#eq_cache in
274 let eq_status1 = NCicParamod.index_obj eq_status uri in
275 status#set_eq_cache eq_status1
278 let record_index_eq =
279 let basic_index_eq uri
280 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
282 = if not alias_only then index_eq (NCicLibrary.refresh_uri uri) status else
285 GrafiteTypes.Serializer.register#run "index_eq" basic_index_eq
288 let index_eq_for_auto status uri =
289 if NnAuto.is_a_fact_obj status uri then
290 let newstatus = index_eq uri status in
291 if newstatus#eq_cache == status#eq_cache then status
293 ((*prerr_endline ("recording " ^ (NUri.string_of_uri uri));*)
294 NCicLibrary.dump_obj newstatus (record_index_eq uri))
296 ((*prerr_endline "Not a fact";*)
300 let inject_constraint =
301 let basic_eval_add_constraint (u1,u2)
302 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
305 if not alias_only then
306 let u1 = refresh_uri_in_universe u1 in
307 let u2 = refresh_uri_in_universe u2 in
308 (* NCicLibrary.add_constraint adds the constraint to the NCicEnvironment
309 * and also to the storage (for undo/redo). During inclusion of compiled
310 * files the storage must not be touched. *)
311 NCicEnvironment.add_lt_constraint u1 u2;
316 GrafiteTypes.Serializer.register#run "constraints" basic_eval_add_constraint
319 let eval_add_constraint status u1 u2 =
320 let status = NCicLibrary.add_constraint status u1 u2 in
321 NCicLibrary.dump_obj status (inject_constraint (u1,u2))
324 let eval_ng_tac tac =
325 let rec aux f (text, prefix_len, tac) =
327 | GrafiteAst.NApply (_loc, t) -> NTactics.apply_tac (text,prefix_len,t)
328 | GrafiteAst.NSmartApply (_loc, t) ->
329 NnAuto.smart_apply_tac (text,prefix_len,t)
330 | GrafiteAst.NAssert (_loc, seqs) ->
333 (function (hyps,concl) ->
336 (id,`Decl t) -> id,`Decl (text,prefix_len,t)
337 |(id,`Def (b,t))->id,`Def((text,prefix_len,b),(text,prefix_len,t))
339 (text,prefix_len,concl))
341 | GrafiteAst.NAuto (_loc, (None,a)) ->
342 NnAuto.auto_tac ~params:(None,a) ?trace_ref:None
343 | GrafiteAst.NAuto (_loc, (Some l,a)) ->
345 ~params:(Some List.map (fun x -> "",0,x) l,a) ?trace_ref:None
346 | GrafiteAst.NBranch _ -> NTactics.branch_tac ~force:false
347 | GrafiteAst.NCases (_loc, what, where) ->
349 ~what:(text,prefix_len,what)
350 ~where:(text,prefix_len,where)
351 | GrafiteAst.NCase1 (_loc,n) -> NTactics.case1_tac n
352 | GrafiteAst.NChange (_loc, pat, ww) ->
354 ~where:(text,prefix_len,pat) ~with_what:(text,prefix_len,ww)
355 | GrafiteAst.NConstructor (_loc,num,args) ->
356 NTactics.constructor_tac
357 ?num ~args:(List.map (fun x -> text,prefix_len,x) args)
358 | GrafiteAst.NCut (_loc, t) -> NTactics.cut_tac (text,prefix_len,t)
359 (*| GrafiteAst.NDiscriminate (_,what) -> NDestructTac.discriminate_tac ~what:(text,prefix_len,what)
360 | GrafiteAst.NSubst (_,what) -> NDestructTac.subst_tac ~what:(text,prefix_len,what)*)
361 | GrafiteAst.NClear (_loc, l) -> NTactics.clear_tac l
362 | GrafiteAst.NDestruct (_,dom,skip) -> NDestructTac.destruct_tac dom skip
363 | GrafiteAst.NDot _ -> NTactics.dot_tac
364 | GrafiteAst.NElim (_loc, what, where) ->
366 ~what:(text,prefix_len,what)
367 ~where:(text,prefix_len,where)
368 | GrafiteAst.NFocus (_,l) -> NTactics.focus_tac l
369 | GrafiteAst.NGeneralize (_loc, where) ->
370 NTactics.generalize_tac ~where:(text,prefix_len,where)
371 | GrafiteAst.NId _ -> (fun x -> x)
372 | GrafiteAst.NIntro (_loc,n) -> NTactics.intro_tac n
373 | GrafiteAst.NIntros (_loc,ns) -> NTactics.intros_tac ns
374 | GrafiteAst.NInversion (_loc, what, where) ->
375 NTactics.inversion_tac
376 ~what:(text,prefix_len,what)
377 ~where:(text,prefix_len,where)
378 | GrafiteAst.NLApply (_loc, t) -> NTactics.lapply_tac (text,prefix_len,t)
379 | GrafiteAst.NLetIn (_loc,where,what,name) ->
380 NTactics.letin_tac ~where:(text,prefix_len,where)
381 ~what:(text,prefix_len,what) name
382 | GrafiteAst.NMerge _ -> NTactics.merge_tac
383 | GrafiteAst.NPos (_,l) -> NTactics.pos_tac l
384 | GrafiteAst.NPosbyname (_,s) -> NTactics.case_tac s
385 | GrafiteAst.NReduce (_loc, reduction, where) ->
386 NTactics.reduce_tac ~reduction ~where:(text,prefix_len,where)
387 | GrafiteAst.NRewrite (_loc,dir,what,where) ->
388 NTactics.rewrite_tac ~dir ~what:(text,prefix_len,what)
389 ~where:(text,prefix_len,where)
390 | GrafiteAst.NSemicolon _ -> fun x -> x
391 | GrafiteAst.NShift _ -> NTactics.shift_tac
392 | GrafiteAst.NSkip _ -> NTactics.skip_tac
393 | GrafiteAst.NUnfocus _ -> NTactics.unfocus_tac
394 | GrafiteAst.NWildcard _ -> NTactics.wildcard_tac
395 | GrafiteAst.NTry (_,tac) -> NTactics.try_tac
396 (f f (text, prefix_len, tac))
397 | GrafiteAst.NAssumption _ -> NTactics.assumption_tac
398 | GrafiteAst.NBlock (_,l) ->
399 NTactics.block_tac (List.map (fun x -> aux f (text,prefix_len,x)) l)
400 |GrafiteAst.NRepeat (_,tac) ->
401 NTactics.repeat_tac (f f (text, prefix_len, tac))
403 aux aux tac (* trick for non uniform recursion call *)
406 let subst_metasenv_and_fix_names status =
407 let u,h,metasenv, subst,o = status#obj in
409 NCicUntrusted.map_obj_kind ~skip_body:true
410 (NCicUntrusted.apply_subst subst []) o
412 status#set_obj(u,h,NCicUntrusted.apply_subst_metasenv subst metasenv,subst,o)
415 let is_proof_irrelevant context ty =
417 NCicReduction.whd ~subst:[] context
418 (NCicTypeChecker.typeof ~subst:[] ~metasenv:[] context ty)
420 NCic.Sort NCic.Prop -> true
421 | NCic.Sort _ -> false
425 let rec relevance_of ?(context=[]) ty =
426 match NCicReduction.whd ~subst:[] context ty with
428 not (is_proof_irrelevant context s) ::
429 relevance_of ~context:((n,NCic.Decl s)::context) t
433 let compute_relevance uri =
435 NCic.Constant (_,name,bo,ty,attrs) ->
436 let relevance = relevance_of ty in
437 NCic.Constant (relevance,name,bo,ty,attrs)
438 | NCic.Fixpoint (ind,funs,attrs) ->
441 (fun (_,name,recno,ty,bo) ->
442 let relevance = relevance_of ty in
443 relevance,name,recno,ty,bo
446 NCic.Fixpoint (ind,funs,attrs)
447 | NCic.Inductive (ind,leftno,tys,attrs) ->
449 List.rev_map (fun (_,name,arity,_) -> name,NCic.Decl arity) tys in
450 let tysno = List.length tys in
453 (fun (_,name,arity,cons) ->
454 let relevance = relevance_of arity in
459 NCicTypeChecker.debruijn uri tysno ~subst:[] [] ty in
460 let relevance = relevance_of ~context dety in
464 (relevance,name,arity,cons)
467 NCic.Inductive (ind,leftno,tys,attrs)
471 let rec eval_ncommand ~include_paths opts status (text,prefix_len,cmd) =
473 | GrafiteAst.Include (loc, mode, fname) ->
474 let _root, baseuri, fullpath, _rrelpath =
475 Librarian.baseuri_of_script ~include_paths fname in
476 let baseuri = NUri.uri_of_string baseuri in
477 (* MATITA 1.0: keep WithoutPreferences? *)
478 let alias_only = (mode = GrafiteAst.OnlyPreferences) in
479 GrafiteTypes.Serializer.require
480 ~alias_only ~baseuri ~fname:fullpath status
481 | GrafiteAst.UnificationHint (loc, t, n) -> eval_unification_hint status t n
482 | GrafiteAst.NCoercion (loc, name, t, ty, source, target) ->
483 let status, composites =
484 NCicCoercDeclaration.eval_ncoercion status name t ty source target in
485 let mode = GrafiteAst.WithPreferences in (* MATITA 1.0: fixme *)
486 let aliases = GrafiteDisambiguate.aliases_for_objs composites in
487 eval_alias status (mode,aliases)
488 | GrafiteAst.NQed loc ->
489 if status#ng_mode <> `ProofMode then
490 raise (GrafiteTypes.Command_error "Not in proof mode")
492 let uri,height,menv,subst,obj_kind = status#obj in
495 (GrafiteTypes.Command_error"You can't Qed an incomplete theorem")
498 NCicUntrusted.map_obj_kind
499 (NCicUntrusted.apply_subst subst []) obj_kind in
500 let height = NCicTypeChecker.height_of_obj_kind uri [] obj_kind in
501 (* fix the height inside the object *)
502 let rec fix () = function
503 | NCic.Const (NReference.Ref (u,spec)) when NUri.eq u uri ->
504 NCic.Const (NReference.reference_of_spec u
506 | NReference.Def _ -> NReference.Def height
507 | NReference.Fix (i,j,_) -> NReference.Fix(i,j,height)
508 | NReference.CoFix _ -> NReference.CoFix height
509 | NReference.Ind _ | NReference.Con _
510 | NReference.Decl as s -> s))
511 | t -> NCicUtils.map (fun _ () -> ()) () fix t
516 NCicUntrusted.map_obj_kind (fix ()) obj_kind
519 let obj_kind = compute_relevance uri obj_kind in
520 let obj = uri,height,[],[],obj_kind in
521 let old_status = status in
522 let status = NCicLibrary.add_obj status obj in
525 NCic.Constant (_,_,_,_,(_,`Example,_))
526 | NCic.Fixpoint (_,_,(_,`Example,_)) -> false
531 let status = index_obj_for_auto status obj in
532 (try index_eq_for_auto status uri
539 with _ -> prerr_endline "got an exception"; status
541 (* prerr_endline (NCicPp.ppobj obj); *)
542 HLog.message ("New object: " ^ NUri.string_of_uri uri);
544 (*prerr_endline (NCicPp.ppobj obj);*)
545 let boxml = NCicElim.mk_elims obj in
546 let boxml = boxml @ NCicElim.mk_projections obj in
547 let status = status#set_ng_mode `CommandMode in
548 let xxaliases = GrafiteDisambiguate.aliases_for_objs [uri] in
549 let mode = GrafiteAst.WithPreferences in (* MATITA 1.0: fixme *)
550 let status = eval_alias status (mode,xxaliases) in
556 eval_ncommand ~include_paths opts status
557 ("",0,GrafiteAst.NObj (HExtlib.dummy_floc,boxml))
559 if nstatus#ng_mode <> `CommandMode then
561 (*HLog.warn "error in generating projection/eliminator";*)
562 assert(status#ng_mode = `CommandMode);
568 | MultiPassDisambiguator.DisambiguationError _
569 | NCicTypeChecker.TypeCheckerFailure _ ->
570 (*HLog.warn "error in generating projection/eliminator";*)
573 let _,_,_,_,nobj = obj in
574 let status = match nobj with
575 NCic.Inductive (is_ind,leftno,[it],_) ->
576 let _,ind_name,ty,cl = it in
578 (fun status outsort ->
579 let status = status#set_ng_mode `ProofMode in
582 NInversion.mk_inverter
583 (ind_name ^ "_inv_" ^
584 (snd (NCicElim.ast_of_sort outsort)))
585 is_ind it leftno outsort status status#baseuri in
586 let _,_,menv,_,_ = invobj in
588 [] -> eval_ncommand ~include_paths opts status
589 ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
592 with _ -> (*HLog.warn "error in generating inversion principle"; *)
593 let status = status#set_ng_mode `CommandMode in status)
596 List.map (fun s -> NCic.Type s) (NCicEnvironment.get_universes ()))
601 _,_,_,_,NCic.Inductive
602 (true,leftno,[_,_,_,[_,_,_]],(_,`Record fields))
605 (fun (name,is_coercion,arity) ->
606 if is_coercion then Some(name,leftno,arity) else None) fields
610 (fun status (name,cpos,arity) ->
612 let metasenv,subst,status,t =
613 GrafiteDisambiguate.disambiguate_nterm status None [] [] []
614 ("",0,NotationPt.Ident (name,None)) in
615 assert (metasenv = [] && subst = []);
617 NCicCoercDeclaration.
618 basic_eval_and_record_ncoercion_from_t_cpos_arity
619 status (name,t,cpos,arity) in
620 let aliases = GrafiteDisambiguate.aliases_for_objs nuris in
621 eval_alias status (mode,aliases)
622 with MultiPassDisambiguator.DisambiguationError _->
623 HLog.warn ("error in generating coercion: "^name);
630 NCicLibrary.time_travel old_status;
632 | GrafiteAst.NCopy (log,tgt,src_uri, map) ->
633 if status#ng_mode <> `CommandMode then
634 raise (GrafiteTypes.Command_error "Not in command mode")
636 let tgt_uri_ext, old_ok =
637 match NCicEnvironment.get_checked_obj src_uri with
638 | _,_,[],[], (NCic.Inductive _ as ok) -> ".ind", ok
639 | _,_,[],[], (NCic.Fixpoint _ as ok) -> ".con", ok
640 | _,_,[],[], (NCic.Constant _ as ok) -> ".con", ok
643 let tgt_uri = NUri.uri_of_string (status#baseuri^"/"^tgt^tgt_uri_ext) in
644 let map = (src_uri, tgt_uri) :: map in
646 let rec subst () = function
647 | NCic.Meta _ -> assert false
648 | NCic.Const (NReference.Ref (u,spec)) as t ->
650 (NReference.reference_of_spec (List.assoc u map)spec)
652 | t -> NCicUtils.map (fun _ _ -> ()) () subst t
654 NCicUntrusted.map_obj_kind ~skip_body:false (subst ()) old_ok
656 let ninitial_stack = Continuationals.Stack.of_nmetasenv [] in
657 let status = status#set_obj (tgt_uri,0,[],[],ok) in
658 (*prerr_endline (NCicPp.ppobj (tgt_uri,0,[],[],ok));*)
659 let status = status#set_stack ninitial_stack in
660 let status = subst_metasenv_and_fix_names status in
661 let status = status#set_ng_mode `ProofMode in
662 eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
663 | GrafiteAst.NObj (loc,obj) ->
664 if status#ng_mode <> `CommandMode then
665 raise (GrafiteTypes.Command_error "Not in command mode")
668 GrafiteDisambiguate.disambiguate_nobj status
669 ~baseuri:status#baseuri (text,prefix_len,obj) in
670 let uri,height,nmenv,nsubst,nobj = obj in
671 let ninitial_stack = Continuationals.Stack.of_nmetasenv nmenv in
672 let status = status#set_obj obj in
673 let status = status#set_stack ninitial_stack in
674 let status = subst_metasenv_and_fix_names status in
675 let status = status#set_ng_mode `ProofMode in
678 eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
680 | GrafiteAst.NDiscriminator (_,_) -> assert false (*(loc, indty) ->
681 if status#ng_mode <> `CommandMode then
682 raise (GrafiteTypes.Command_error "Not in command mode")
684 let status = status#set_ng_mode `ProofMode in
685 let metasenv,subst,status,indty =
686 GrafiteDisambiguate.disambiguate_nterm None status [] [] [] (text,prefix_len,indty) in
687 let indtyno, (_,_,tys,_,_) = match indty with
688 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
689 indtyno, NCicEnvironment.get_checked_indtys r
690 | _ -> prerr_endline ("engine: indty expected... (fix this error message)"); assert false in
691 let it = List.nth tys indtyno in
692 let status,obj = NDestructTac.mk_discriminator it status in
693 let _,_,menv,_,_ = obj in
695 [] -> eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
696 | _ -> prerr_endline ("Discriminator: non empty metasenv");
698 | GrafiteAst.NInverter (loc, name, indty, selection, sort) ->
699 if status#ng_mode <> `CommandMode then
700 raise (GrafiteTypes.Command_error "Not in command mode")
702 let metasenv,subst,status,sort = match sort with
703 | None -> [],[],status,NCic.Sort NCic.Prop
705 GrafiteDisambiguate.disambiguate_nterm status None [] [] []
708 assert (metasenv = []);
709 let sort = NCicReduction.whd ~subst [] sort in
714 raise (Invalid_argument (Printf.sprintf
715 "ninverter: found target %s, which is not a sort"
716 (NCicPp.ppterm ~metasenv ~subst ~context:[] sort))) in
717 let status = status#set_ng_mode `ProofMode in
718 let metasenv,subst,status,indty =
719 GrafiteDisambiguate.disambiguate_nterm status None [] [] subst
720 (text,prefix_len,indty) in
721 let indtyno,(_,leftno,tys,_,_) =
723 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
724 indtyno, NCicEnvironment.get_checked_indtys r
726 prerr_endline ("engine: indty =" ^ NCicPp.ppterm ~metasenv:[]
727 ~subst:[] ~context:[] indty);
729 let it = List.nth tys indtyno in
731 NInversion.mk_inverter name true it leftno ?selection sort
732 status status#baseuri in
733 let _,_,menv,_,_ = obj in
736 eval_ncommand ~include_paths opts status
737 ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
739 | GrafiteAst.NUnivConstraint (loc,u1,u2) ->
740 eval_add_constraint status [`Type,u1] [`Type,u2]
741 (* ex lexicon commands *)
742 | GrafiteAst.Interpretation (loc, dsc, (symbol, args), cic_appl_pattern) ->
743 let cic_appl_pattern =
744 GrafiteDisambiguate.disambiguate_cic_appl_pattern status args
747 eval_interpretation status (dsc,(symbol, args),cic_appl_pattern)
748 | GrafiteAst.Notation (loc, dir, l1, associativity, precedence, l2) ->
750 CicNotationParser.check_l1_pattern
751 l1 (dir = Some `RightToLeft) precedence associativity
754 if dir <> Some `RightToLeft then eval_input_notation status (l1,l2)
757 if dir <> Some `LeftToRight then eval_output_notation status (l1,l2)
759 | GrafiteAst.Alias (loc, spec) ->
761 (*CSC: Warning: this code should be factorized with the corresponding
762 code in DisambiguatePp *)
764 | GrafiteAst.Ident_alias (id,uri) ->
765 [DisambiguateTypes.Id id,spec]
766 | GrafiteAst.Symbol_alias (symb, instance, desc) ->
767 [DisambiguateTypes.Symbol (symb,instance),spec]
768 | GrafiteAst.Number_alias (instance,desc) ->
769 [DisambiguateTypes.Num instance,spec]
771 let mode = GrafiteAst.WithPreferences in(*assert false in (* VEDI SOPRA *) MATITA 1.0*)
772 eval_alias status (mode,diff)
775 let eval_comment opts status (text,prefix_len,c) = status
777 let rec eval_executable ~include_paths opts status (text,prefix_len,ex) =
779 | GrafiteAst.NTactic (_(*loc*), tacl) ->
780 if status#ng_mode <> `ProofMode then
781 raise (GrafiteTypes.Command_error "Not in proof mode")
786 let status = eval_ng_tac (text,prefix_len,tac) status in
787 subst_metasenv_and_fix_names status)
791 | GrafiteAst.NCommand (_, cmd) ->
792 eval_ncommand ~include_paths opts status (text,prefix_len,cmd)
793 | GrafiteAst.NMacro (loc, macro) ->
794 raise (NMacro (loc,macro))
796 and eval_ast ~include_paths ?(do_heavy_checks=false) status (text,prefix_len,st)
798 let opts = { do_heavy_checks = do_heavy_checks ; } in
800 | GrafiteAst.Executable (_,ex) ->
801 eval_executable ~include_paths opts status (text,prefix_len,ex)
802 | GrafiteAst.Comment (_,c) ->
803 eval_comment opts status (text,prefix_len,c)