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/
29 (* mo file name, ma file name *)
30 exception IncludedFileNotCompiled of string * string
33 (Cic.context -> GrafiteTypes.status * (Cic.term,Cic.lazy_term) GrafiteAst.macro)
34 exception NMacro of GrafiteAst.loc * GrafiteAst.nmacro
36 type 'a disambiguator_input = string * int * 'a
39 do_heavy_checks: bool ;
42 let concat_nuris uris nuris =
44 | `New uris, `New nuris -> `New (nuris@uris)
50 'term 'lazy_term 'reduction 'obj 'ident.
53 (GrafiteTypes.status ->
54 (('term,'obj) GrafiteAst.command) disambiguator_input ->
55 GrafiteTypes.status * (Cic.term,Cic.obj) GrafiteAst.command) ->
58 (GrafiteTypes.status ->
59 (('term,'lazy_term) GrafiteAst.macro) disambiguator_input ->
60 Cic.context -> GrafiteTypes.status * (Cic.term,Cic.lazy_term) GrafiteAst.macro) ->
62 ?do_heavy_checks:bool ->
63 GrafiteTypes.status ->
64 (('term, 'lazy_term, 'reduction, 'obj, 'ident) GrafiteAst.statement)
65 disambiguator_input ->
66 GrafiteTypes.status * [`Old of UriManager.uri list | `New of NUri.uri list]
69 type 'a eval_command =
72 (GrafiteTypes.status -> (('term,'obj) GrafiteAst.command) disambiguator_input ->
73 GrafiteTypes.status * (Cic.term,Cic.obj) GrafiteAst.command) ->
74 options -> GrafiteTypes.status ->
75 (('term,'obj) GrafiteAst.command) disambiguator_input ->
76 GrafiteTypes.status * [`Old of UriManager.uri list | `New of NUri.uri list]
79 type 'a eval_comment =
80 {ecm_go: 'term 'lazy_term 'reduction_kind 'obj 'ident.
82 (GrafiteTypes.status -> (('term,'obj) GrafiteAst.command) disambiguator_input ->
83 GrafiteTypes.status * (Cic.term,Cic.obj) GrafiteAst.command) ->
84 options -> GrafiteTypes.status ->
85 (('term,'lazy_term,'reduction_kind,'obj,'ident) GrafiteAst.comment) disambiguator_input ->
86 GrafiteTypes.status * [`Old of UriManager.uri list | `New of NUri.uri list]
89 type 'a eval_executable =
90 {ee_go: 'term 'lazy_term 'reduction 'obj 'ident.
93 (GrafiteTypes.status ->
94 (('term,'obj) GrafiteAst.command) disambiguator_input ->
95 GrafiteTypes.status * (Cic.term,Cic.obj) GrafiteAst.command) ->
98 (GrafiteTypes.status ->
99 (('term,'lazy_term) GrafiteAst.macro) disambiguator_input ->
100 Cic.context -> GrafiteTypes.status * (Cic.term,Cic.lazy_term) GrafiteAst.macro) ->
103 GrafiteTypes.status ->
104 (('term, 'lazy_term, 'reduction, 'obj, 'ident) GrafiteAst.code) disambiguator_input ->
105 GrafiteTypes.status * [`Old of UriManager.uri list | `New of NUri.uri list]
108 type 'a eval_from_moo =
109 { efm_go: GrafiteTypes.status -> string -> GrafiteTypes.status }
111 let coercion_moo_statement_of (uri,arity, saturations,_) =
113 (HExtlib.dummy_floc, CicUtil.term_of_uri uri, false, arity, saturations)
115 let basic_eval_unification_hint (t,n) status =
116 NCicUnifHint.add_user_provided_hint status t n
119 let inject_unification_hint =
120 let basic_eval_unification_hint (t,n)
121 ~refresh_uri_in_universe
124 let t = refresh_uri_in_term t in basic_eval_unification_hint (t,n)
126 NCicLibrary.Serializer.register#run "unification_hints"
127 object(_ : 'a NCicLibrary.register_type)
128 method run = basic_eval_unification_hint
132 let eval_unification_hint status t n =
133 let metasenv,subst,status,t =
134 GrafiteDisambiguate.disambiguate_nterm None status [] [] [] ("",0,t) in
135 assert (metasenv=[]);
136 let t = NCicUntrusted.apply_subst subst [] t in
137 let status = basic_eval_unification_hint (t,n) status in
138 let dump = inject_unification_hint (t,n)::status#dump in
139 let status = status#set_dump dump in
143 let basic_index_obj l status =
144 status#set_auto_cache
147 List.fold_left (fun t k ->
148 NDiscriminationTree.DiscriminationTree.index t k v)
153 let record_index_obj =
155 ~refresh_uri_in_universe
160 (fun ks,v -> List.map refresh_uri_in_term ks, refresh_uri_in_term v)
163 NCicLibrary.Serializer.register#run "index_obj"
164 object(_ : 'a NCicLibrary.register_type)
169 let compute_keys status uri height kind =
170 let mk_item ty spec =
171 let orig_ty = NTacStatus.mk_cic_term [] ty in
172 let status,keys = NnAuto.keys_of_type status orig_ty in
176 snd (NTacStatus.term_of_cic_term status t (NTacStatus.ctx_of t)))
179 keys,NCic.Const(NReference.reference_of_spec uri spec)
183 | NCic.Fixpoint (ind,ifl,_) ->
185 (fun (_,_,rno,ty,_) i ->
186 if ind then mk_item ty (NReference.Fix (i,rno,height))
187 else mk_item ty (NReference.CoFix height)) ifl
188 | NCic.Inductive (b,lno,itl,_) ->
190 (fun (_,_,ty,_) i -> mk_item ty (NReference.Ind (b,i,lno))) itl
192 List.map (fun ((_,_,ty),i,j) -> mk_item ty (NReference.Con (i,j+1,lno)))
193 (List.flatten (HExtlib.list_mapi
194 (fun (_,_,_,cl) i -> HExtlib.list_mapi (fun x j-> x,i,j) cl)
196 | NCic.Constant (_,_,Some _, ty, _) ->
197 [ mk_item ty (NReference.Def height) ]
198 | NCic.Constant (_,_,None, ty, _) ->
199 [ mk_item ty NReference.Decl ]
203 let keys = List.filter
206 | (NCic.Appl (NCic.Meta _::_)) -> false
212 HLog.debug ("Indexing:" ^
213 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t);
214 HLog.debug ("With keys:" ^ String.concat "\n" (List.map (fun t ->
215 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t) keys));
220 HLog.debug ("Not indexing:" ^
221 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t);
227 let index_obj_for_auto status (uri, height, _, _, kind) =
228 (*prerr_endline (string_of_int height);*)
229 let data = compute_keys status uri height kind in
230 let status = basic_index_obj data status in
231 let dump = record_index_obj data :: status#dump in
235 let index_eq uri status =
236 let eq_status = status#eq_cache in
237 let eq_status1 = NCicParamod.index_obj eq_status uri in
238 status#set_eq_cache eq_status1
241 let record_index_eq =
242 let basic_index_eq uri
243 ~refresh_uri_in_universe
245 = index_eq (NCicLibrary.refresh_uri uri)
247 NCicLibrary.Serializer.register#run "index_eq"
248 object(_ : 'a NCicLibrary.register_type)
249 method run = basic_index_eq
253 let index_eq_for_auto status uri =
254 if NnAuto.is_a_fact_obj status uri then
255 let newstatus = index_eq uri status in
256 if newstatus#eq_cache == status#eq_cache then status
258 ((*prerr_endline ("recording " ^ (NUri.string_of_uri uri));*)
259 let dump = record_index_eq uri :: newstatus#dump
260 in newstatus#set_dump dump)
262 ((*prerr_endline "Not a fact";*)
266 let basic_eval_add_constraint (u1,u2) status =
267 NCicLibrary.add_constraint status u1 u2
270 let inject_constraint =
271 let basic_eval_add_constraint (u1,u2)
272 ~refresh_uri_in_universe
275 let u1 = refresh_uri_in_universe u1 in
276 let u2 = refresh_uri_in_universe u2 in
277 basic_eval_add_constraint (u1,u2)
279 NCicLibrary.Serializer.register#run "constraints"
280 object(_:'a NCicLibrary.register_type)
281 method run = basic_eval_add_constraint
285 let eval_add_constraint status u1 u2 =
286 let status = basic_eval_add_constraint (u1,u2) status in
287 let dump = inject_constraint (u1,u2)::status#dump in
288 let status = status#set_dump dump in
292 let eval_ng_punct (_text, _prefix_len, punct) =
294 | GrafiteAst.Dot _ -> NTactics.dot_tac
295 | GrafiteAst.Semicolon _ -> fun x -> x
296 | GrafiteAst.Branch _ -> NTactics.branch_tac ~force:false
297 | GrafiteAst.Shift _ -> NTactics.shift_tac
298 | GrafiteAst.Pos (_,l) -> NTactics.pos_tac l
299 | GrafiteAst.Wildcard _ -> NTactics.wildcard_tac
300 | GrafiteAst.Merge _ -> NTactics.merge_tac
303 let eval_ng_tac tac =
304 let rec aux f (text, prefix_len, tac) =
306 | GrafiteAst.NApply (_loc, t) -> NTactics.apply_tac (text,prefix_len,t)
307 | GrafiteAst.NSmartApply (_loc, t) ->
308 NnAuto.smart_apply_tac (text,prefix_len,t)
309 | GrafiteAst.NAssert (_loc, seqs) ->
312 (function (hyps,concl) ->
315 (id,`Decl t) -> id,`Decl (text,prefix_len,t)
316 |(id,`Def (b,t))->id,`Def((text,prefix_len,b),(text,prefix_len,t))
318 (text,prefix_len,concl))
320 | GrafiteAst.NAuto (_loc, (None,a)) ->
321 NnAuto.auto_tac ~params:(None,a) ?trace_ref:None
322 | GrafiteAst.NAuto (_loc, (Some l,a)) ->
324 ~params:(Some List.map (fun x -> "",0,x) l,a) ?trace_ref:None
325 | GrafiteAst.NBranch _ -> NTactics.branch_tac ~force:false
326 | GrafiteAst.NCases (_loc, what, where) ->
328 ~what:(text,prefix_len,what)
329 ~where:(text,prefix_len,where)
330 | GrafiteAst.NCase1 (_loc,n) -> NTactics.case1_tac n
331 | GrafiteAst.NChange (_loc, pat, ww) ->
333 ~where:(text,prefix_len,pat) ~with_what:(text,prefix_len,ww)
334 | GrafiteAst.NConstructor (_loc,num,args) ->
335 NTactics.constructor_tac
336 ?num ~args:(List.map (fun x -> text,prefix_len,x) args)
337 | GrafiteAst.NCut (_loc, t) -> NTactics.cut_tac (text,prefix_len,t)
338 (*| GrafiteAst.NDiscriminate (_,what) -> NDestructTac.discriminate_tac ~what:(text,prefix_len,what)
339 | GrafiteAst.NSubst (_,what) -> NDestructTac.subst_tac ~what:(text,prefix_len,what)*)
340 | GrafiteAst.NDestruct (_,dom,skip) -> NDestructTac.destruct_tac dom skip
341 | GrafiteAst.NDot _ -> NTactics.dot_tac
342 | GrafiteAst.NElim (_loc, what, where) ->
344 ~what:(text,prefix_len,what)
345 ~where:(text,prefix_len,where)
346 | GrafiteAst.NFocus (_,l) -> NTactics.focus_tac l
347 | GrafiteAst.NGeneralize (_loc, where) ->
348 NTactics.generalize_tac ~where:(text,prefix_len,where)
349 | GrafiteAst.NId _ -> (fun x -> x)
350 | GrafiteAst.NIntro (_loc,n) -> NTactics.intro_tac n
351 | GrafiteAst.NIntros (_loc,ns) -> NTactics.intros_tac ns
352 | GrafiteAst.NInversion (_loc, what, where) ->
353 NTactics.inversion_tac
354 ~what:(text,prefix_len,what)
355 ~where:(text,prefix_len,where)
356 | GrafiteAst.NLApply (_loc, t) -> NTactics.lapply_tac (text,prefix_len,t)
357 | GrafiteAst.NLetIn (_loc,where,what,name) ->
358 NTactics.letin_tac ~where:(text,prefix_len,where)
359 ~what:(text,prefix_len,what) name
360 | GrafiteAst.NMerge _ -> NTactics.merge_tac
361 | GrafiteAst.NPos (_,l) -> NTactics.pos_tac l
362 | GrafiteAst.NPosbyname (_,s) -> NTactics.case_tac s
363 | GrafiteAst.NReduce (_loc, reduction, where) ->
364 NTactics.reduce_tac ~reduction ~where:(text,prefix_len,where)
365 | GrafiteAst.NRewrite (_loc,dir,what,where) ->
366 NTactics.rewrite_tac ~dir ~what:(text,prefix_len,what)
367 ~where:(text,prefix_len,where)
368 | GrafiteAst.NSemicolon _ -> fun x -> x
369 | GrafiteAst.NShift _ -> NTactics.shift_tac
370 | GrafiteAst.NSkip _ -> NTactics.skip_tac
371 | GrafiteAst.NUnfocus _ -> NTactics.unfocus_tac
372 | GrafiteAst.NWildcard _ -> NTactics.wildcard_tac
373 | GrafiteAst.NTry (_,tac) -> NTactics.try_tac
374 (aux f (text, prefix_len, tac))
375 | GrafiteAst.NAssumption _ -> NTactics.assumption_tac
376 | GrafiteAst.NBlock (_,l) ->
377 NTactics.block_tac (List.map (fun x -> aux f (text,prefix_len,x)) l)
378 |GrafiteAst.NRepeat (_,tac) ->
379 NTactics.repeat_tac (f f (text, prefix_len, tac))
381 aux aux tac (* trick for non uniform recursion call *)
384 let subst_metasenv_and_fix_names status =
385 let u,h,metasenv, subst,o = status#obj in
387 NCicUntrusted.map_obj_kind ~skip_body:true
388 (NCicUntrusted.apply_subst subst []) o
390 status#set_obj(u,h,NCicUntrusted.apply_subst_metasenv subst metasenv,subst,o)
394 let rec eval_ncommand opts status (text,prefix_len,cmd) =
396 | GrafiteAst.UnificationHint (loc, t, n) -> eval_unification_hint status t n
397 | GrafiteAst.NCoercion (loc, name, t, ty, source, target) ->
398 NCicCoercDeclaration.eval_ncoercion status name t ty source target
399 | GrafiteAst.NQed loc ->
400 if status#ng_mode <> `ProofMode then
401 raise (GrafiteTypes.Command_error "Not in proof mode")
403 let uri,height,menv,subst,obj_kind = status#obj in
406 (GrafiteTypes.Command_error"You can't Qed an incomplete theorem")
409 NCicUntrusted.map_obj_kind
410 (NCicUntrusted.apply_subst subst []) obj_kind in
411 let height = NCicTypeChecker.height_of_obj_kind uri [] obj_kind in
412 (* fix the height inside the object *)
413 let rec fix () = function
414 | NCic.Const (NReference.Ref (u,spec)) when NUri.eq u uri ->
415 NCic.Const (NReference.reference_of_spec u
417 | NReference.Def _ -> NReference.Def height
418 | NReference.Fix (i,j,_) -> NReference.Fix(i,j,height)
419 | NReference.CoFix _ -> NReference.CoFix height
420 | NReference.Ind _ | NReference.Con _
421 | NReference.Decl as s -> s))
422 | t -> NCicUtils.map (fun _ () -> ()) () fix t
427 NCicUntrusted.map_obj_kind (fix ()) obj_kind
430 let obj = uri,height,[],[],obj_kind in
431 prerr_endline ("pp new obj \n"^NCicPp.ppobj obj);
432 let old_status = status in
433 let status = NCicLibrary.add_obj status obj in
436 NCic.Constant (_,_,_,_,(_,`Example,_))
437 | NCic.Fixpoint (_,_,(_,`Example,_)) -> false
442 let status = index_obj_for_auto status obj in
443 (try index_eq_for_auto status uri
450 with _ -> prerr_endline "got an exception"; status
452 (* prerr_endline (NCicPp.ppobj obj); *)
453 HLog.message ("New object: " ^ NUri.string_of_uri uri);
455 (*prerr_endline (NCicPp.ppobj obj);*)
456 let boxml = NCicElim.mk_elims obj in
457 let boxml = boxml @ NCicElim.mk_projections obj in
460 let timestamp,uris_rev =
462 (fun (status,uris_rev) (uri,_,_,_,_) as obj ->
463 let status = NCicLibrary.add_obj status obj in
465 ) (status,[]) objs in
466 let uris = uri::List.rev uris_rev in
468 let status = status#set_ng_mode `CommandMode in
469 let status = LexiconSync.add_aliases_for_objs status (`New [uri]) in
472 (fun (status,uris) boxml ->
475 eval_ncommand opts status
476 ("",0,GrafiteAst.NObj (HExtlib.dummy_floc,boxml))
478 if nstatus#ng_mode <> `CommandMode then
480 (*HLog.warn "error in generating projection/eliminator";*)
484 nstatus, concat_nuris uris nuris
486 | MultiPassDisambiguator.DisambiguationError _
487 | NCicTypeChecker.TypeCheckerFailure _ ->
488 (*HLog.warn "error in generating projection/eliminator";*)
490 ) (status,`New [] (* uris *)) boxml in
491 let _,_,_,_,nobj = obj in
492 let status = match nobj with
493 NCic.Inductive (is_ind,leftno,[it],_) ->
494 let _,ind_name,ty,cl = it in
496 (fun status outsort ->
497 let status = status#set_ng_mode `ProofMode in
500 NInversion.mk_inverter
501 (ind_name ^ "_inv_" ^
502 (snd (NCicElim.ast_of_sort outsort)))
503 is_ind it leftno outsort status status#baseuri in
504 let _,_,menv,_,_ = invobj in
506 [] -> eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
507 | _ -> status,`New []))
509 with _ -> (*HLog.warn "error in generating inversion principle"; *)
510 let status = status#set_ng_mode `CommandMode in status)
513 List.map (fun s -> NCic.Type s) (NCicEnvironment.get_universes ()))
518 _,_,_,_,NCic.Inductive
519 (true,leftno,[_,_,_,[_,_,_]],(_,`Record fields))
522 (fun (name,is_coercion,arity) ->
523 if is_coercion then Some(name,leftno,arity) else None) fields
527 (fun (status,uris) (name,cpos,arity) ->
529 let metasenv,subst,status,t =
530 GrafiteDisambiguate.disambiguate_nterm None status [] [] []
531 ("",0,NotationPt.Ident (name,None)) in
532 assert (metasenv = [] && subst = []);
534 NCicCoercDeclaration.
535 basic_eval_and_record_ncoercion_from_t_cpos_arity
536 status (name,t,cpos,arity)
538 let uris = concat_nuris nuris uris in
540 with MultiPassDisambiguator.DisambiguationError _->
541 HLog.warn ("error in generating coercion: "^name);
543 (status,uris) coercions
548 NCicLibrary.time_travel old_status;
550 | GrafiteAst.NCopy (log,tgt,src_uri, map) ->
551 if status#ng_mode <> `CommandMode then
552 raise (GrafiteTypes.Command_error "Not in command mode")
554 let tgt_uri_ext, old_ok =
555 match NCicEnvironment.get_checked_obj src_uri with
556 | _,_,[],[], (NCic.Inductive _ as ok) -> ".ind", ok
557 | _,_,[],[], (NCic.Fixpoint _ as ok) -> ".con", ok
558 | _,_,[],[], (NCic.Constant _ as ok) -> ".con", ok
561 let tgt_uri = NUri.uri_of_string (status#baseuri^"/"^tgt^tgt_uri_ext) in
562 let map = (src_uri, tgt_uri) :: map in
564 let rec subst () = function
565 | NCic.Meta _ -> assert false
566 | NCic.Const (NReference.Ref (u,spec)) as t ->
568 (NReference.reference_of_spec (List.assoc u map)spec)
570 | t -> NCicUtils.map (fun _ _ -> ()) () subst t
572 NCicUntrusted.map_obj_kind ~skip_body:false (subst ()) old_ok
574 let ninitial_stack = Continuationals.Stack.of_nmetasenv [] in
575 let status = status#set_obj (tgt_uri,0,[],[],ok) in
576 (*prerr_endline (NCicPp.ppobj (tgt_uri,0,[],[],ok));*)
577 let status = status#set_stack ninitial_stack in
578 let status = subst_metasenv_and_fix_names status in
579 let status = status#set_ng_mode `ProofMode in
580 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
581 | GrafiteAst.NObj (loc,obj) ->
582 if status#ng_mode <> `CommandMode then
583 raise (GrafiteTypes.Command_error "Not in command mode")
586 GrafiteDisambiguate.disambiguate_nobj status
587 ~baseuri:status#baseuri (text,prefix_len,obj) in
588 let uri,height,nmenv,nsubst,nobj = obj in
589 let ninitial_stack = Continuationals.Stack.of_nmetasenv nmenv in
590 let status = status#set_obj obj in
591 let status = status#set_stack ninitial_stack in
592 let status = subst_metasenv_and_fix_names status in
593 let status = status#set_ng_mode `ProofMode in
596 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
597 | _ -> status,`New [])
598 | GrafiteAst.NDiscriminator (_,_) -> assert false (*(loc, indty) ->
599 if status#ng_mode <> `CommandMode then
600 raise (GrafiteTypes.Command_error "Not in command mode")
602 let status = status#set_ng_mode `ProofMode in
603 let metasenv,subst,status,indty =
604 GrafiteDisambiguate.disambiguate_nterm None status [] [] [] (text,prefix_len,indty) in
605 let indtyno, (_,_,tys,_,_) = match indty with
606 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
607 indtyno, NCicEnvironment.get_checked_indtys r
608 | _ -> prerr_endline ("engine: indty expected... (fix this error message)"); assert false in
609 let it = List.nth tys indtyno in
610 let status,obj = NDestructTac.mk_discriminator it status in
611 let _,_,menv,_,_ = obj in
613 [] -> eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
614 | _ -> prerr_endline ("Discriminator: non empty metasenv");
616 | GrafiteAst.NInverter (loc, name, indty, selection, sort) ->
617 if status#ng_mode <> `CommandMode then
618 raise (GrafiteTypes.Command_error "Not in command mode")
620 let metasenv,subst,status,sort = match sort with
621 | None -> [],[],status,NCic.Sort NCic.Prop
622 | Some s -> GrafiteDisambiguate.disambiguate_nterm None status [] [] []
625 assert (metasenv = []);
626 let sort = NCicReduction.whd ~subst [] sort in
627 let sort = match sort with
629 | _ -> raise (Invalid_argument (Printf.sprintf "ninverter: found target %s, which is not a sort"
630 (NCicPp.ppterm ~metasenv ~subst ~context:[] sort)))
632 let status = status#set_ng_mode `ProofMode in
633 let metasenv,subst,status,indty =
634 GrafiteDisambiguate.disambiguate_nterm None status [] [] subst (text,prefix_len,indty) in
635 let indtyno,(_,leftno,tys,_,_) = match indty with
636 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
637 indtyno, NCicEnvironment.get_checked_indtys r
638 | _ -> prerr_endline ("engine: indty =" ^ NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] indty) ; assert false in
639 let it = List.nth tys indtyno in
640 let status,obj = NInversion.mk_inverter name true it leftno ?selection sort
641 status status#baseuri in
642 let _,_,menv,_,_ = obj in
645 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
647 | GrafiteAst.NUnivConstraint (loc,u1,u2) ->
648 eval_add_constraint status [`Type,u1] [`Type,u2]
651 let rec eval_command = {ec_go = fun ~disambiguate_command opts status
652 (text,prefix_len,cmd) ->
653 let status,cmd = disambiguate_command status (text,prefix_len,cmd) in
656 | GrafiteAst.Default (loc, what, uris) as cmd ->
657 LibraryObjects.set_default what uris;
658 GrafiteTypes.add_moo_content [cmd] status,`New []
659 | GrafiteAst.Drop loc -> raise Drop
660 | GrafiteAst.Include (loc, mode, new_or_old, baseuri) ->
661 (* Old Include command is not recursive; new one is *)
663 if new_or_old = `OldAndNew then
664 let moopath_rw, moopath_r =
665 LibraryMisc.obj_file_of_baseuri
666 ~must_exist:false ~baseuri ~writable:true,
667 LibraryMisc.obj_file_of_baseuri
668 ~must_exist:false ~baseuri ~writable:false in
670 if Sys.file_exists moopath_r then moopath_r else
671 if Sys.file_exists moopath_rw then moopath_rw else
672 raise (IncludedFileNotCompiled (moopath_rw,baseuri))
674 eval_from_moo.efm_go status moopath
679 NCicLibrary.Serializer.require ~baseuri:(NUri.uri_of_string baseuri)
682 GrafiteTypes.add_moo_content
683 [GrafiteAst.Include (loc,mode,`New,baseuri)] status
686 | GrafiteAst.Print (_,_) -> status,`New []
687 | GrafiteAst.Set (loc, name, value) -> status, `New []
688 (* GrafiteTypes.set_option status name value,[] *)
689 | GrafiteAst.Obj (loc,obj) -> (* MATITA 1.0 *) assert false
693 } and eval_executable = {ee_go = fun ~disambiguate_command
694 ~disambiguate_macro opts status (text,prefix_len,ex) ->
696 | GrafiteAst.NTactic (_(*loc*), tacl) ->
697 if status#ng_mode <> `ProofMode then
698 raise (GrafiteTypes.Command_error "Not in proof mode")
703 let status = eval_ng_tac (text,prefix_len,tac) status in
704 subst_metasenv_and_fix_names status)
708 | GrafiteAst.Command (_, cmd) ->
709 eval_command.ec_go ~disambiguate_command opts status (text,prefix_len,cmd)
710 | GrafiteAst.NCommand (_, cmd) ->
711 eval_ncommand opts status (text,prefix_len,cmd)
712 | GrafiteAst.Macro (loc, macro) ->
713 raise (Macro (loc,disambiguate_macro status (text,prefix_len,macro)))
714 | GrafiteAst.NMacro (loc, macro) ->
715 raise (NMacro (loc,macro))
717 } and eval_from_moo = {efm_go = fun status fname ->
719 ("",0,GrafiteAst.Executable (HExtlib.dummy_floc,
720 GrafiteAst.Command (HExtlib.dummy_floc,
723 let moo = GrafiteMarshal.load_moo fname in
726 let ast = ast_of_cmd ast in
729 ~disambiguate_command:(fun status (_,_,cmd) -> status,cmd)
730 ~disambiguate_macro:(fun _ _ -> assert false)
733 assert (lemmas=`New []);
736 } and eval_ast = {ea_go = fun ~disambiguate_command
737 ~disambiguate_macro ?(do_heavy_checks=false) status
740 let opts = { do_heavy_checks = do_heavy_checks ; } in
742 | GrafiteAst.Executable (_,ex) ->
743 eval_executable.ee_go ~disambiguate_command
744 ~disambiguate_macro opts status (text,prefix_len,ex)
745 | GrafiteAst.Comment (_,c) ->
746 eval_comment.ecm_go ~disambiguate_command opts status (text,prefix_len,c)
747 } and eval_comment = { ecm_go = fun ~disambiguate_command opts status (text,prefix_len,c) ->
753 let eval_ast = eval_ast.ea_go