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 add_coercions_of_lemmas lemmas status =
296 match CoercDb.is_a_coercion (Cic.Const (uri,[])) with
298 | Some (_,tgt,_,sat,_) ->
299 let arity = match tgt with CoercDb.Fun n -> n | _ -> 0 in
300 Some (coercion_moo_statement_of (uri,arity,sat,0)))
303 let status = GrafiteTypes.add_moo_content moo_content status in
304 status#set_coercions (CoercDb.dump ()),
307 let eval_ng_punct (_text, _prefix_len, punct) =
309 | GrafiteAst.Dot _ -> NTactics.dot_tac
310 | GrafiteAst.Semicolon _ -> fun x -> x
311 | GrafiteAst.Branch _ -> NTactics.branch_tac ~force:false
312 | GrafiteAst.Shift _ -> NTactics.shift_tac
313 | GrafiteAst.Pos (_,l) -> NTactics.pos_tac l
314 | GrafiteAst.Wildcard _ -> NTactics.wildcard_tac
315 | GrafiteAst.Merge _ -> NTactics.merge_tac
318 let eval_ng_tac tac =
319 let rec aux f (text, prefix_len, tac) =
321 | GrafiteAst.NApply (_loc, t) -> NTactics.apply_tac (text,prefix_len,t)
322 | GrafiteAst.NSmartApply (_loc, t) ->
323 NnAuto.smart_apply_tac (text,prefix_len,t)
324 | GrafiteAst.NAssert (_loc, seqs) ->
327 (function (hyps,concl) ->
330 (id,`Decl t) -> id,`Decl (text,prefix_len,t)
331 |(id,`Def (b,t))->id,`Def((text,prefix_len,b),(text,prefix_len,t))
333 (text,prefix_len,concl))
335 | GrafiteAst.NAuto (_loc, (None,a)) ->
336 NnAuto.auto_tac ~params:(None,a) ?trace_ref:None
337 | GrafiteAst.NAuto (_loc, (Some l,a)) ->
339 ~params:(Some List.map (fun x -> "",0,x) l,a) ?trace_ref:None
340 | GrafiteAst.NBranch _ -> NTactics.branch_tac ~force:false
341 | GrafiteAst.NCases (_loc, what, where) ->
343 ~what:(text,prefix_len,what)
344 ~where:(text,prefix_len,where)
345 | GrafiteAst.NCase1 (_loc,n) -> NTactics.case1_tac n
346 | GrafiteAst.NChange (_loc, pat, ww) ->
348 ~where:(text,prefix_len,pat) ~with_what:(text,prefix_len,ww)
349 | GrafiteAst.NConstructor (_loc,num,args) ->
350 NTactics.constructor_tac
351 ?num ~args:(List.map (fun x -> text,prefix_len,x) args)
352 | GrafiteAst.NCut (_loc, t) -> NTactics.cut_tac (text,prefix_len,t)
353 (*| GrafiteAst.NDiscriminate (_,what) -> NDestructTac.discriminate_tac ~what:(text,prefix_len,what)
354 | GrafiteAst.NSubst (_,what) -> NDestructTac.subst_tac ~what:(text,prefix_len,what)*)
355 | GrafiteAst.NDestruct (_,dom,skip) -> NDestructTac.destruct_tac dom skip
356 | GrafiteAst.NDot _ -> NTactics.dot_tac
357 | GrafiteAst.NElim (_loc, what, where) ->
359 ~what:(text,prefix_len,what)
360 ~where:(text,prefix_len,where)
361 | GrafiteAst.NFocus (_,l) -> NTactics.focus_tac l
362 | GrafiteAst.NGeneralize (_loc, where) ->
363 NTactics.generalize_tac ~where:(text,prefix_len,where)
364 | GrafiteAst.NId _ -> (fun x -> x)
365 | GrafiteAst.NIntro (_loc,n) -> NTactics.intro_tac n
366 | GrafiteAst.NIntros (_loc,ns) -> NTactics.intros_tac ns
367 | GrafiteAst.NInversion (_loc, what, where) ->
368 NTactics.inversion_tac
369 ~what:(text,prefix_len,what)
370 ~where:(text,prefix_len,where)
371 | GrafiteAst.NLApply (_loc, t) -> NTactics.lapply_tac (text,prefix_len,t)
372 | GrafiteAst.NLetIn (_loc,where,what,name) ->
373 NTactics.letin_tac ~where:(text,prefix_len,where)
374 ~what:(text,prefix_len,what) name
375 | GrafiteAst.NMerge _ -> NTactics.merge_tac
376 | GrafiteAst.NPos (_,l) -> NTactics.pos_tac l
377 | GrafiteAst.NPosbyname (_,s) -> NTactics.case_tac s
378 | GrafiteAst.NReduce (_loc, reduction, where) ->
379 NTactics.reduce_tac ~reduction ~where:(text,prefix_len,where)
380 | GrafiteAst.NRewrite (_loc,dir,what,where) ->
381 NTactics.rewrite_tac ~dir ~what:(text,prefix_len,what)
382 ~where:(text,prefix_len,where)
383 | GrafiteAst.NSemicolon _ -> fun x -> x
384 | GrafiteAst.NShift _ -> NTactics.shift_tac
385 | GrafiteAst.NSkip _ -> NTactics.skip_tac
386 | GrafiteAst.NUnfocus _ -> NTactics.unfocus_tac
387 | GrafiteAst.NWildcard _ -> NTactics.wildcard_tac
388 | GrafiteAst.NTry (_,tac) -> NTactics.try_tac
389 (aux f (text, prefix_len, tac))
390 | GrafiteAst.NAssumption _ -> NTactics.assumption_tac
391 | GrafiteAst.NBlock (_,l) ->
392 NTactics.block_tac (List.map (fun x -> aux f (text,prefix_len,x)) l)
393 |GrafiteAst.NRepeat (_,tac) ->
394 NTactics.repeat_tac (f f (text, prefix_len, tac))
396 aux aux tac (* trick for non uniform recursion call *)
399 let subst_metasenv_and_fix_names status =
400 let u,h,metasenv, subst,o = status#obj in
402 NCicUntrusted.map_obj_kind ~skip_body:true
403 (NCicUntrusted.apply_subst subst []) o
405 status#set_obj(u,h,NCicUntrusted.apply_subst_metasenv subst metasenv,subst,o)
409 let rec eval_ncommand opts status (text,prefix_len,cmd) =
411 | GrafiteAst.UnificationHint (loc, t, n) -> eval_unification_hint status t n
412 | GrafiteAst.NCoercion (loc, name, t, ty, source, target) ->
413 NCicCoercDeclaration.eval_ncoercion status name t ty source target
414 | GrafiteAst.NQed loc ->
415 if status#ng_mode <> `ProofMode then
416 raise (GrafiteTypes.Command_error "Not in proof mode")
418 let uri,height,menv,subst,obj_kind = status#obj in
421 (GrafiteTypes.Command_error"You can't Qed an incomplete theorem")
424 NCicUntrusted.map_obj_kind
425 (NCicUntrusted.apply_subst subst []) obj_kind in
426 let height = NCicTypeChecker.height_of_obj_kind uri [] obj_kind in
427 (* fix the height inside the object *)
428 let rec fix () = function
429 | NCic.Const (NReference.Ref (u,spec)) when NUri.eq u uri ->
430 NCic.Const (NReference.reference_of_spec u
432 | NReference.Def _ -> NReference.Def height
433 | NReference.Fix (i,j,_) -> NReference.Fix(i,j,height)
434 | NReference.CoFix _ -> NReference.CoFix height
435 | NReference.Ind _ | NReference.Con _
436 | NReference.Decl as s -> s))
437 | t -> NCicUtils.map (fun _ () -> ()) () fix t
442 NCicUntrusted.map_obj_kind (fix ()) obj_kind
445 let obj = uri,height,[],[],obj_kind in
446 prerr_endline ("pp new obj \n"^NCicPp.ppobj obj);
447 let old_status = status in
448 let status = NCicLibrary.add_obj status obj in
451 NCic.Constant (_,_,_,_,(_,`Example,_))
452 | NCic.Fixpoint (_,_,(_,`Example,_)) -> false
457 let status = index_obj_for_auto status obj in
458 (try index_eq_for_auto status uri
465 with _ -> prerr_endline "got an exception"; status
467 (* prerr_endline (NCicPp.ppobj obj); *)
468 HLog.message ("New object: " ^ NUri.string_of_uri uri);
470 (*prerr_endline (NCicPp.ppobj obj);*)
471 let boxml = NCicElim.mk_elims obj in
472 let boxml = boxml @ NCicElim.mk_projections obj in
475 let timestamp,uris_rev =
477 (fun (status,uris_rev) (uri,_,_,_,_) as obj ->
478 let status = NCicLibrary.add_obj status obj in
480 ) (status,[]) objs in
481 let uris = uri::List.rev uris_rev in
483 let status = status#set_ng_mode `CommandMode in
484 let status = LexiconSync.add_aliases_for_objs status (`New [uri]) in
487 (fun (status,uris) boxml ->
490 eval_ncommand opts status
491 ("",0,GrafiteAst.NObj (HExtlib.dummy_floc,boxml))
493 if nstatus#ng_mode <> `CommandMode then
495 (*HLog.warn "error in generating projection/eliminator";*)
499 nstatus, concat_nuris uris nuris
501 | MultiPassDisambiguator.DisambiguationError _
502 | NCicTypeChecker.TypeCheckerFailure _ ->
503 (*HLog.warn "error in generating projection/eliminator";*)
505 ) (status,`New [] (* uris *)) boxml in
506 let _,_,_,_,nobj = obj in
507 let status = match nobj with
508 NCic.Inductive (is_ind,leftno,[it],_) ->
509 let _,ind_name,ty,cl = it in
511 (fun status outsort ->
512 let status = status#set_ng_mode `ProofMode in
515 NInversion.mk_inverter
516 (ind_name ^ "_inv_" ^
517 (snd (NCicElim.ast_of_sort outsort)))
518 is_ind it leftno outsort status status#baseuri in
519 let _,_,menv,_,_ = invobj in
521 [] -> eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
522 | _ -> status,`New []))
524 with _ -> (*HLog.warn "error in generating inversion principle"; *)
525 let status = status#set_ng_mode `CommandMode in status)
528 List.map (fun s -> NCic.Type s) (NCicEnvironment.get_universes ()))
533 _,_,_,_,NCic.Inductive
534 (true,leftno,[_,_,_,[_,_,_]],(_,`Record fields))
537 (fun (name,is_coercion,arity) ->
538 if is_coercion then Some(name,leftno,arity) else None) fields
542 (fun (status,uris) (name,cpos,arity) ->
544 let metasenv,subst,status,t =
545 GrafiteDisambiguate.disambiguate_nterm None status [] [] []
546 ("",0,NotationPt.Ident (name,None)) in
547 assert (metasenv = [] && subst = []);
549 NCicCoercDeclaration.
550 basic_eval_and_record_ncoercion_from_t_cpos_arity
551 status (name,t,cpos,arity)
553 let uris = concat_nuris nuris uris in
555 with MultiPassDisambiguator.DisambiguationError _->
556 HLog.warn ("error in generating coercion: "^name);
558 (status,uris) coercions
563 NCicLibrary.time_travel old_status;
565 | GrafiteAst.NCopy (log,tgt,src_uri, map) ->
566 if status#ng_mode <> `CommandMode then
567 raise (GrafiteTypes.Command_error "Not in command mode")
569 let tgt_uri_ext, old_ok =
570 match NCicEnvironment.get_checked_obj src_uri with
571 | _,_,[],[], (NCic.Inductive _ as ok) -> ".ind", ok
572 | _,_,[],[], (NCic.Fixpoint _ as ok) -> ".con", ok
573 | _,_,[],[], (NCic.Constant _ as ok) -> ".con", ok
576 let tgt_uri = NUri.uri_of_string (status#baseuri^"/"^tgt^tgt_uri_ext) in
577 let map = (src_uri, tgt_uri) :: map in
579 let rec subst () = function
580 | NCic.Meta _ -> assert false
581 | NCic.Const (NReference.Ref (u,spec)) as t ->
583 (NReference.reference_of_spec (List.assoc u map)spec)
585 | t -> NCicUtils.map (fun _ _ -> ()) () subst t
587 NCicUntrusted.map_obj_kind ~skip_body:false (subst ()) old_ok
589 let ninitial_stack = Continuationals.Stack.of_nmetasenv [] in
590 let status = status#set_obj (tgt_uri,0,[],[],ok) in
591 (*prerr_endline (NCicPp.ppobj (tgt_uri,0,[],[],ok));*)
592 let status = status#set_stack ninitial_stack in
593 let status = subst_metasenv_and_fix_names status in
594 let status = status#set_ng_mode `ProofMode in
595 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
596 | GrafiteAst.NObj (loc,obj) ->
597 if status#ng_mode <> `CommandMode then
598 raise (GrafiteTypes.Command_error "Not in command mode")
601 GrafiteDisambiguate.disambiguate_nobj status
602 ~baseuri:status#baseuri (text,prefix_len,obj) in
603 let uri,height,nmenv,nsubst,nobj = obj in
604 let ninitial_stack = Continuationals.Stack.of_nmetasenv nmenv in
605 let status = status#set_obj obj in
606 let status = status#set_stack ninitial_stack in
607 let status = subst_metasenv_and_fix_names status in
608 let status = status#set_ng_mode `ProofMode in
611 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
612 | _ -> status,`New [])
613 | GrafiteAst.NDiscriminator (_,_) -> assert false (*(loc, indty) ->
614 if status#ng_mode <> `CommandMode then
615 raise (GrafiteTypes.Command_error "Not in command mode")
617 let status = status#set_ng_mode `ProofMode in
618 let metasenv,subst,status,indty =
619 GrafiteDisambiguate.disambiguate_nterm None status [] [] [] (text,prefix_len,indty) in
620 let indtyno, (_,_,tys,_,_) = match indty with
621 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
622 indtyno, NCicEnvironment.get_checked_indtys r
623 | _ -> prerr_endline ("engine: indty expected... (fix this error message)"); assert false in
624 let it = List.nth tys indtyno in
625 let status,obj = NDestructTac.mk_discriminator it status in
626 let _,_,menv,_,_ = obj in
628 [] -> eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
629 | _ -> prerr_endline ("Discriminator: non empty metasenv");
631 | GrafiteAst.NInverter (loc, name, indty, selection, sort) ->
632 if status#ng_mode <> `CommandMode then
633 raise (GrafiteTypes.Command_error "Not in command mode")
635 let metasenv,subst,status,sort = match sort with
636 | None -> [],[],status,NCic.Sort NCic.Prop
637 | Some s -> GrafiteDisambiguate.disambiguate_nterm None status [] [] []
640 assert (metasenv = []);
641 let sort = NCicReduction.whd ~subst [] sort in
642 let sort = match sort with
644 | _ -> raise (Invalid_argument (Printf.sprintf "ninverter: found target %s, which is not a sort"
645 (NCicPp.ppterm ~metasenv ~subst ~context:[] sort)))
647 let status = status#set_ng_mode `ProofMode in
648 let metasenv,subst,status,indty =
649 GrafiteDisambiguate.disambiguate_nterm None status [] [] subst (text,prefix_len,indty) in
650 let indtyno,(_,leftno,tys,_,_) = match indty with
651 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
652 indtyno, NCicEnvironment.get_checked_indtys r
653 | _ -> prerr_endline ("engine: indty =" ^ NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] indty) ; assert false in
654 let it = List.nth tys indtyno in
655 let status,obj = NInversion.mk_inverter name true it leftno ?selection sort
656 status status#baseuri in
657 let _,_,menv,_,_ = obj in
660 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
662 | GrafiteAst.NUnivConstraint (loc,u1,u2) ->
663 eval_add_constraint status [`Type,u1] [`Type,u2]
666 let rec eval_command = {ec_go = fun ~disambiguate_command opts status
667 (text,prefix_len,cmd) ->
668 let status,cmd = disambiguate_command status (text,prefix_len,cmd) in
671 | GrafiteAst.Default (loc, what, uris) as cmd ->
672 LibraryObjects.set_default what uris;
673 GrafiteTypes.add_moo_content [cmd] status,`New []
674 | GrafiteAst.Drop loc -> raise Drop
675 | GrafiteAst.Include (loc, mode, new_or_old, baseuri) ->
676 (* Old Include command is not recursive; new one is *)
678 if new_or_old = `OldAndNew then
679 let moopath_rw, moopath_r =
680 LibraryMisc.obj_file_of_baseuri
681 ~must_exist:false ~baseuri ~writable:true,
682 LibraryMisc.obj_file_of_baseuri
683 ~must_exist:false ~baseuri ~writable:false in
685 if Sys.file_exists moopath_r then moopath_r else
686 if Sys.file_exists moopath_rw then moopath_rw else
687 raise (IncludedFileNotCompiled (moopath_rw,baseuri))
689 eval_from_moo.efm_go status moopath
694 NCicLibrary.Serializer.require ~baseuri:(NUri.uri_of_string baseuri)
697 GrafiteTypes.add_moo_content
698 [GrafiteAst.Include (loc,mode,`New,baseuri)] status
701 | GrafiteAst.Print (_,_) -> status,`New []
702 | GrafiteAst.Set (loc, name, value) -> status, `New []
703 (* GrafiteTypes.set_option status name value,[] *)
704 | GrafiteAst.Obj (loc,obj) -> (* MATITA 1.0 *) assert false
708 } and eval_executable = {ee_go = fun ~disambiguate_command
709 ~disambiguate_macro opts status (text,prefix_len,ex) ->
711 | GrafiteAst.NTactic (_(*loc*), tacl) ->
712 if status#ng_mode <> `ProofMode then
713 raise (GrafiteTypes.Command_error "Not in proof mode")
718 let status = eval_ng_tac (text,prefix_len,tac) status in
719 subst_metasenv_and_fix_names status)
723 | GrafiteAst.Command (_, cmd) ->
724 eval_command.ec_go ~disambiguate_command opts status (text,prefix_len,cmd)
725 | GrafiteAst.NCommand (_, cmd) ->
726 eval_ncommand opts status (text,prefix_len,cmd)
727 | GrafiteAst.Macro (loc, macro) ->
728 raise (Macro (loc,disambiguate_macro status (text,prefix_len,macro)))
729 | GrafiteAst.NMacro (loc, macro) ->
730 raise (NMacro (loc,macro))
732 } and eval_from_moo = {efm_go = fun status fname ->
734 ("",0,GrafiteAst.Executable (HExtlib.dummy_floc,
735 GrafiteAst.Command (HExtlib.dummy_floc,
738 let moo = GrafiteMarshal.load_moo fname in
741 let ast = ast_of_cmd ast in
744 ~disambiguate_command:(fun status (_,_,cmd) -> status,cmd)
745 ~disambiguate_macro:(fun _ _ -> assert false)
748 assert (lemmas=`New []);
751 } and eval_ast = {ea_go = fun ~disambiguate_command
752 ~disambiguate_macro ?(do_heavy_checks=false) status
755 let opts = { do_heavy_checks = do_heavy_checks ; } in
757 | GrafiteAst.Executable (_,ex) ->
758 eval_executable.ee_go ~disambiguate_command
759 ~disambiguate_macro opts status (text,prefix_len,ex)
760 | GrafiteAst.Comment (_,c) ->
761 eval_comment.ecm_go ~disambiguate_command opts status (text,prefix_len,c)
762 } and eval_comment = { ecm_go = fun ~disambiguate_command opts status (text,prefix_len,c) ->
768 let eval_ast = eval_ast.ea_go