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 basic_eval_add_constraint (u1,u2) status =
301 NCicLibrary.add_constraint status u1 u2
304 let inject_constraint =
305 let basic_eval_add_constraint (u1,u2)
306 ~refresh_uri_in_universe ~refresh_uri_in_term ~refresh_uri_in_reference
309 if not alias_only then
310 let u1 = refresh_uri_in_universe u1 in
311 let u2 = refresh_uri_in_universe u2 in
312 basic_eval_add_constraint (u1,u2) status
316 GrafiteTypes.Serializer.register#run "constraints" basic_eval_add_constraint
319 let eval_add_constraint status u1 u2 =
320 let status = basic_eval_add_constraint (u1,u2) status 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 ~alias_only ~baseuri ~fname status
480 | GrafiteAst.UnificationHint (loc, t, n) -> eval_unification_hint status t n
481 | GrafiteAst.NCoercion (loc, name, t, ty, source, target) ->
482 let status, composites =
483 NCicCoercDeclaration.eval_ncoercion status name t ty source target in
484 let mode = GrafiteAst.WithPreferences in (* MATITA 1.0: fixme *)
485 let aliases = GrafiteDisambiguate.aliases_for_objs composites in
486 eval_alias status (mode,aliases)
487 | GrafiteAst.NQed loc ->
488 if status#ng_mode <> `ProofMode then
489 raise (GrafiteTypes.Command_error "Not in proof mode")
491 let uri,height,menv,subst,obj_kind = status#obj in
494 (GrafiteTypes.Command_error"You can't Qed an incomplete theorem")
497 NCicUntrusted.map_obj_kind
498 (NCicUntrusted.apply_subst subst []) obj_kind in
499 let height = NCicTypeChecker.height_of_obj_kind uri [] obj_kind in
500 (* fix the height inside the object *)
501 let rec fix () = function
502 | NCic.Const (NReference.Ref (u,spec)) when NUri.eq u uri ->
503 NCic.Const (NReference.reference_of_spec u
505 | NReference.Def _ -> NReference.Def height
506 | NReference.Fix (i,j,_) -> NReference.Fix(i,j,height)
507 | NReference.CoFix _ -> NReference.CoFix height
508 | NReference.Ind _ | NReference.Con _
509 | NReference.Decl as s -> s))
510 | t -> NCicUtils.map (fun _ () -> ()) () fix t
515 NCicUntrusted.map_obj_kind (fix ()) obj_kind
518 let obj_kind = compute_relevance uri obj_kind in
519 let obj = uri,height,[],[],obj_kind in
520 let old_status = status in
521 let status = NCicLibrary.add_obj status obj in
524 NCic.Constant (_,_,_,_,(_,`Example,_))
525 | NCic.Fixpoint (_,_,(_,`Example,_)) -> false
530 let status = index_obj_for_auto status obj in
531 (try index_eq_for_auto status uri
538 with _ -> prerr_endline "got an exception"; status
540 (* prerr_endline (NCicPp.ppobj obj); *)
541 HLog.message ("New object: " ^ NUri.string_of_uri uri);
543 (*prerr_endline (NCicPp.ppobj obj);*)
544 let boxml = NCicElim.mk_elims obj in
545 let boxml = boxml @ NCicElim.mk_projections obj in
548 let timestamp,uris_rev =
550 (fun (status,uris_rev) (uri,_,_,_,_) as obj ->
551 let status = NCicLibrary.add_obj status obj in
553 ) (status,[]) objs in
554 let uris = uri::List.rev uris_rev in
556 let status = status#set_ng_mode `CommandMode in
557 let xxaliases = GrafiteDisambiguate.aliases_for_objs [uri] in
558 let mode = GrafiteAst.WithPreferences in (* MATITA 1.0: fixme *)
559 let status = eval_alias status (mode,xxaliases) in
565 eval_ncommand ~include_paths opts status
566 ("",0,GrafiteAst.NObj (HExtlib.dummy_floc,boxml))
568 if nstatus#ng_mode <> `CommandMode then
570 (*HLog.warn "error in generating projection/eliminator";*)
571 assert(status#ng_mode = `CommandMode);
577 | MultiPassDisambiguator.DisambiguationError _
578 | NCicTypeChecker.TypeCheckerFailure _ ->
579 (*HLog.warn "error in generating projection/eliminator";*)
582 let _,_,_,_,nobj = obj in
583 let status = match nobj with
584 NCic.Inductive (is_ind,leftno,[it],_) ->
585 let _,ind_name,ty,cl = it in
587 (fun status outsort ->
588 let status = status#set_ng_mode `ProofMode in
591 NInversion.mk_inverter
592 (ind_name ^ "_inv_" ^
593 (snd (NCicElim.ast_of_sort outsort)))
594 is_ind it leftno outsort status status#baseuri in
595 let _,_,menv,_,_ = invobj in
597 [] -> eval_ncommand ~include_paths opts status
598 ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
601 with _ -> (*HLog.warn "error in generating inversion principle"; *)
602 let status = status#set_ng_mode `CommandMode in status)
605 List.map (fun s -> NCic.Type s) (NCicEnvironment.get_universes ()))
610 _,_,_,_,NCic.Inductive
611 (true,leftno,[_,_,_,[_,_,_]],(_,`Record fields))
614 (fun (name,is_coercion,arity) ->
615 if is_coercion then Some(name,leftno,arity) else None) fields
619 (fun status (name,cpos,arity) ->
621 let metasenv,subst,status,t =
622 GrafiteDisambiguate.disambiguate_nterm status None [] [] []
623 ("",0,NotationPt.Ident (name,None)) in
624 assert (metasenv = [] && subst = []);
626 NCicCoercDeclaration.
627 basic_eval_and_record_ncoercion_from_t_cpos_arity
628 status (name,t,cpos,arity) in
629 let aliases = GrafiteDisambiguate.aliases_for_objs nuris in
630 eval_alias status (mode,aliases)
631 with MultiPassDisambiguator.DisambiguationError _->
632 HLog.warn ("error in generating coercion: "^name);
639 NCicLibrary.time_travel old_status;
641 | GrafiteAst.NCopy (log,tgt,src_uri, map) ->
642 if status#ng_mode <> `CommandMode then
643 raise (GrafiteTypes.Command_error "Not in command mode")
645 let tgt_uri_ext, old_ok =
646 match NCicEnvironment.get_checked_obj src_uri with
647 | _,_,[],[], (NCic.Inductive _ as ok) -> ".ind", ok
648 | _,_,[],[], (NCic.Fixpoint _ as ok) -> ".con", ok
649 | _,_,[],[], (NCic.Constant _ as ok) -> ".con", ok
652 let tgt_uri = NUri.uri_of_string (status#baseuri^"/"^tgt^tgt_uri_ext) in
653 let map = (src_uri, tgt_uri) :: map in
655 let rec subst () = function
656 | NCic.Meta _ -> assert false
657 | NCic.Const (NReference.Ref (u,spec)) as t ->
659 (NReference.reference_of_spec (List.assoc u map)spec)
661 | t -> NCicUtils.map (fun _ _ -> ()) () subst t
663 NCicUntrusted.map_obj_kind ~skip_body:false (subst ()) old_ok
665 let ninitial_stack = Continuationals.Stack.of_nmetasenv [] in
666 let status = status#set_obj (tgt_uri,0,[],[],ok) in
667 (*prerr_endline (NCicPp.ppobj (tgt_uri,0,[],[],ok));*)
668 let status = status#set_stack ninitial_stack in
669 let status = subst_metasenv_and_fix_names status in
670 let status = status#set_ng_mode `ProofMode in
671 eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
672 | GrafiteAst.NObj (loc,obj) ->
673 if status#ng_mode <> `CommandMode then
674 raise (GrafiteTypes.Command_error "Not in command mode")
677 GrafiteDisambiguate.disambiguate_nobj status
678 ~baseuri:status#baseuri (text,prefix_len,obj) in
679 let uri,height,nmenv,nsubst,nobj = obj in
680 let ninitial_stack = Continuationals.Stack.of_nmetasenv nmenv in
681 let status = status#set_obj obj in
682 let status = status#set_stack ninitial_stack in
683 let status = subst_metasenv_and_fix_names status in
684 let status = status#set_ng_mode `ProofMode in
687 eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
689 | GrafiteAst.NDiscriminator (_,_) -> assert false (*(loc, indty) ->
690 if status#ng_mode <> `CommandMode then
691 raise (GrafiteTypes.Command_error "Not in command mode")
693 let status = status#set_ng_mode `ProofMode in
694 let metasenv,subst,status,indty =
695 GrafiteDisambiguate.disambiguate_nterm None status [] [] [] (text,prefix_len,indty) in
696 let indtyno, (_,_,tys,_,_) = match indty with
697 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
698 indtyno, NCicEnvironment.get_checked_indtys r
699 | _ -> prerr_endline ("engine: indty expected... (fix this error message)"); assert false in
700 let it = List.nth tys indtyno in
701 let status,obj = NDestructTac.mk_discriminator it status in
702 let _,_,menv,_,_ = obj in
704 [] -> eval_ncommand ~include_paths opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
705 | _ -> prerr_endline ("Discriminator: non empty metasenv");
707 | GrafiteAst.NInverter (loc, name, indty, selection, sort) ->
708 if status#ng_mode <> `CommandMode then
709 raise (GrafiteTypes.Command_error "Not in command mode")
711 let metasenv,subst,status,sort = match sort with
712 | None -> [],[],status,NCic.Sort NCic.Prop
714 GrafiteDisambiguate.disambiguate_nterm status None [] [] []
717 assert (metasenv = []);
718 let sort = NCicReduction.whd ~subst [] sort in
723 raise (Invalid_argument (Printf.sprintf
724 "ninverter: found target %s, which is not a sort"
725 (NCicPp.ppterm ~metasenv ~subst ~context:[] sort))) in
726 let status = status#set_ng_mode `ProofMode in
727 let metasenv,subst,status,indty =
728 GrafiteDisambiguate.disambiguate_nterm status None [] [] subst
729 (text,prefix_len,indty) in
730 let indtyno,(_,leftno,tys,_,_) =
732 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
733 indtyno, NCicEnvironment.get_checked_indtys r
735 prerr_endline ("engine: indty =" ^ NCicPp.ppterm ~metasenv:[]
736 ~subst:[] ~context:[] indty);
738 let it = List.nth tys indtyno in
740 NInversion.mk_inverter name true it leftno ?selection sort
741 status status#baseuri in
742 let _,_,menv,_,_ = obj in
745 eval_ncommand ~include_paths opts status
746 ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
748 | GrafiteAst.NUnivConstraint (loc,u1,u2) ->
749 eval_add_constraint status [`Type,u1] [`Type,u2]
750 (* ex lexicon commands *)
751 | GrafiteAst.Interpretation (loc, dsc, (symbol, args), cic_appl_pattern) ->
752 let cic_appl_pattern =
753 GrafiteDisambiguate.disambiguate_cic_appl_pattern status args
756 eval_interpretation status (dsc,(symbol, args),cic_appl_pattern)
757 | GrafiteAst.Notation (loc, dir, l1, associativity, precedence, l2) ->
759 CicNotationParser.check_l1_pattern
760 l1 (dir = Some `RightToLeft) precedence associativity
763 if dir <> Some `RightToLeft then eval_input_notation status (l1,l2)
766 if dir <> Some `LeftToRight then eval_output_notation status (l1,l2)
768 | GrafiteAst.Alias (loc, spec) ->
770 (*CSC: Warning: this code should be factorized with the corresponding
771 code in DisambiguatePp *)
773 | GrafiteAst.Ident_alias (id,uri) ->
774 [DisambiguateTypes.Id id,spec]
775 | GrafiteAst.Symbol_alias (symb, instance, desc) ->
776 [DisambiguateTypes.Symbol (symb,instance),spec]
777 | GrafiteAst.Number_alias (instance,desc) ->
778 [DisambiguateTypes.Num instance,spec]
780 let mode = GrafiteAst.WithPreferences in(*assert false in (* VEDI SOPRA *) MATITA 1.0*)
781 eval_alias status (mode,diff)
784 let eval_comment opts status (text,prefix_len,c) = status
786 let rec eval_executable ~include_paths opts status (text,prefix_len,ex) =
788 | GrafiteAst.NTactic (_(*loc*), tacl) ->
789 if status#ng_mode <> `ProofMode then
790 raise (GrafiteTypes.Command_error "Not in proof mode")
795 let status = eval_ng_tac (text,prefix_len,tac) status in
796 subst_metasenv_and_fix_names status)
800 | GrafiteAst.NCommand (_, cmd) ->
801 eval_ncommand ~include_paths opts status (text,prefix_len,cmd)
802 | GrafiteAst.NMacro (loc, macro) ->
803 raise (NMacro (loc,macro))
805 and eval_ast ~include_paths ?(do_heavy_checks=false) status (text,prefix_len,st)
807 let opts = { do_heavy_checks = do_heavy_checks ; } in
809 | GrafiteAst.Executable (_,ex) ->
810 eval_executable ~include_paths opts status (text,prefix_len,ex)
811 | GrafiteAst.Comment (_,c) ->
812 eval_comment opts status (text,prefix_len,c)