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,unit) 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,unit) 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,unit) 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 basic_eval_unification_hint (t,n) status =
112 NCicUnifHint.add_user_provided_hint status t n
115 let inject_unification_hint =
116 let basic_eval_unification_hint (t,n)
117 ~refresh_uri_in_universe
120 let t = refresh_uri_in_term t in basic_eval_unification_hint (t,n)
122 NCicLibrary.Serializer.register#run "unification_hints"
123 object(_ : 'a NCicLibrary.register_type)
124 method run = basic_eval_unification_hint
128 let eval_unification_hint status t n =
129 let metasenv,subst,status,t =
130 GrafiteDisambiguate.disambiguate_nterm None status [] [] [] ("",0,t) in
131 assert (metasenv=[]);
132 let t = NCicUntrusted.apply_subst subst [] t in
133 let status = basic_eval_unification_hint (t,n) status in
134 let dump = inject_unification_hint (t,n)::status#dump in
135 let status = status#set_dump dump in
139 let basic_index_obj l status =
140 status#set_auto_cache
143 List.fold_left (fun t k ->
144 NDiscriminationTree.DiscriminationTree.index t k v)
149 let record_index_obj =
151 ~refresh_uri_in_universe
156 (fun ks,v -> List.map refresh_uri_in_term ks, refresh_uri_in_term v)
159 NCicLibrary.Serializer.register#run "index_obj"
160 object(_ : 'a NCicLibrary.register_type)
165 let compute_keys status uri height kind =
166 let mk_item ty spec =
167 let orig_ty = NTacStatus.mk_cic_term [] ty in
168 let status,keys = NnAuto.keys_of_type status orig_ty in
172 snd (NTacStatus.term_of_cic_term status t (NTacStatus.ctx_of t)))
175 keys,NCic.Const(NReference.reference_of_spec uri spec)
179 | NCic.Fixpoint (ind,ifl,_) ->
181 (fun (_,_,rno,ty,_) i ->
182 if ind then mk_item ty (NReference.Fix (i,rno,height))
183 else mk_item ty (NReference.CoFix height)) ifl
184 | NCic.Inductive (b,lno,itl,_) ->
186 (fun (_,_,ty,_) i -> mk_item ty (NReference.Ind (b,i,lno))) itl
188 List.map (fun ((_,_,ty),i,j) -> mk_item ty (NReference.Con (i,j+1,lno)))
189 (List.flatten (HExtlib.list_mapi
190 (fun (_,_,_,cl) i -> HExtlib.list_mapi (fun x j-> x,i,j) cl)
192 | NCic.Constant (_,_,Some _, ty, _) ->
193 [ mk_item ty (NReference.Def height) ]
194 | NCic.Constant (_,_,None, ty, _) ->
195 [ mk_item ty NReference.Decl ]
199 let keys = List.filter
202 | (NCic.Appl (NCic.Meta _::_)) -> false
208 HLog.debug ("Indexing:" ^
209 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t);
210 HLog.debug ("With keys:" ^ String.concat "\n" (List.map (fun t ->
211 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t) keys));
216 HLog.debug ("Not indexing:" ^
217 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t);
223 let index_obj_for_auto status (uri, height, _, _, kind) =
224 (*prerr_endline (string_of_int height);*)
225 let data = compute_keys status uri height kind in
226 let status = basic_index_obj data status in
227 let dump = record_index_obj data :: status#dump in
231 let index_eq uri status =
232 let eq_status = status#eq_cache in
233 let eq_status1 = NCicParamod.index_obj eq_status uri in
234 status#set_eq_cache eq_status1
237 let record_index_eq =
238 let basic_index_eq uri
239 ~refresh_uri_in_universe
241 = index_eq (NCicLibrary.refresh_uri uri)
243 NCicLibrary.Serializer.register#run "index_eq"
244 object(_ : 'a NCicLibrary.register_type)
245 method run = basic_index_eq
249 let index_eq_for_auto status uri =
250 if NnAuto.is_a_fact_obj status uri then
251 let newstatus = index_eq uri status in
252 if newstatus#eq_cache == status#eq_cache then status
254 ((*prerr_endline ("recording " ^ (NUri.string_of_uri uri));*)
255 let dump = record_index_eq uri :: newstatus#dump
256 in newstatus#set_dump dump)
258 ((*prerr_endline "Not a fact";*)
262 let basic_eval_add_constraint (u1,u2) status =
263 NCicLibrary.add_constraint status u1 u2
266 let inject_constraint =
267 let basic_eval_add_constraint (u1,u2)
268 ~refresh_uri_in_universe
271 let u1 = refresh_uri_in_universe u1 in
272 let u2 = refresh_uri_in_universe u2 in
273 basic_eval_add_constraint (u1,u2)
275 NCicLibrary.Serializer.register#run "constraints"
276 object(_:'a NCicLibrary.register_type)
277 method run = basic_eval_add_constraint
281 let eval_add_constraint status u1 u2 =
282 let status = basic_eval_add_constraint (u1,u2) status in
283 let dump = inject_constraint (u1,u2)::status#dump in
284 let status = status#set_dump dump in
288 let eval_ng_punct (_text, _prefix_len, punct) =
290 | GrafiteAst.Dot _ -> NTactics.dot_tac
291 | GrafiteAst.Semicolon _ -> fun x -> x
292 | GrafiteAst.Branch _ -> NTactics.branch_tac ~force:false
293 | GrafiteAst.Shift _ -> NTactics.shift_tac
294 | GrafiteAst.Pos (_,l) -> NTactics.pos_tac l
295 | GrafiteAst.Wildcard _ -> NTactics.wildcard_tac
296 | GrafiteAst.Merge _ -> NTactics.merge_tac
299 let eval_ng_tac tac =
300 let rec aux f (text, prefix_len, tac) =
302 | GrafiteAst.NApply (_loc, t) -> NTactics.apply_tac (text,prefix_len,t)
303 | GrafiteAst.NSmartApply (_loc, t) ->
304 NnAuto.smart_apply_tac (text,prefix_len,t)
305 | GrafiteAst.NAssert (_loc, seqs) ->
308 (function (hyps,concl) ->
311 (id,`Decl t) -> id,`Decl (text,prefix_len,t)
312 |(id,`Def (b,t))->id,`Def((text,prefix_len,b),(text,prefix_len,t))
314 (text,prefix_len,concl))
316 | GrafiteAst.NAuto (_loc, (None,a)) ->
317 NnAuto.auto_tac ~params:(None,a) ?trace_ref:None
318 | GrafiteAst.NAuto (_loc, (Some l,a)) ->
320 ~params:(Some List.map (fun x -> "",0,x) l,a) ?trace_ref:None
321 | GrafiteAst.NBranch _ -> NTactics.branch_tac ~force:false
322 | GrafiteAst.NCases (_loc, what, where) ->
324 ~what:(text,prefix_len,what)
325 ~where:(text,prefix_len,where)
326 | GrafiteAst.NCase1 (_loc,n) -> NTactics.case1_tac n
327 | GrafiteAst.NChange (_loc, pat, ww) ->
329 ~where:(text,prefix_len,pat) ~with_what:(text,prefix_len,ww)
330 | GrafiteAst.NConstructor (_loc,num,args) ->
331 NTactics.constructor_tac
332 ?num ~args:(List.map (fun x -> text,prefix_len,x) args)
333 | GrafiteAst.NCut (_loc, t) -> NTactics.cut_tac (text,prefix_len,t)
334 (*| GrafiteAst.NDiscriminate (_,what) -> NDestructTac.discriminate_tac ~what:(text,prefix_len,what)
335 | GrafiteAst.NSubst (_,what) -> NDestructTac.subst_tac ~what:(text,prefix_len,what)*)
336 | GrafiteAst.NDestruct (_,dom,skip) -> NDestructTac.destruct_tac dom skip
337 | GrafiteAst.NDot _ -> NTactics.dot_tac
338 | GrafiteAst.NElim (_loc, what, where) ->
340 ~what:(text,prefix_len,what)
341 ~where:(text,prefix_len,where)
342 | GrafiteAst.NFocus (_,l) -> NTactics.focus_tac l
343 | GrafiteAst.NGeneralize (_loc, where) ->
344 NTactics.generalize_tac ~where:(text,prefix_len,where)
345 | GrafiteAst.NId _ -> (fun x -> x)
346 | GrafiteAst.NIntro (_loc,n) -> NTactics.intro_tac n
347 | GrafiteAst.NIntros (_loc,ns) -> NTactics.intros_tac ns
348 | GrafiteAst.NInversion (_loc, what, where) ->
349 NTactics.inversion_tac
350 ~what:(text,prefix_len,what)
351 ~where:(text,prefix_len,where)
352 | GrafiteAst.NLApply (_loc, t) -> NTactics.lapply_tac (text,prefix_len,t)
353 | GrafiteAst.NLetIn (_loc,where,what,name) ->
354 NTactics.letin_tac ~where:(text,prefix_len,where)
355 ~what:(text,prefix_len,what) name
356 | GrafiteAst.NMerge _ -> NTactics.merge_tac
357 | GrafiteAst.NPos (_,l) -> NTactics.pos_tac l
358 | GrafiteAst.NPosbyname (_,s) -> NTactics.case_tac s
359 | GrafiteAst.NReduce (_loc, reduction, where) ->
360 NTactics.reduce_tac ~reduction ~where:(text,prefix_len,where)
361 | GrafiteAst.NRewrite (_loc,dir,what,where) ->
362 NTactics.rewrite_tac ~dir ~what:(text,prefix_len,what)
363 ~where:(text,prefix_len,where)
364 | GrafiteAst.NSemicolon _ -> fun x -> x
365 | GrafiteAst.NShift _ -> NTactics.shift_tac
366 | GrafiteAst.NSkip _ -> NTactics.skip_tac
367 | GrafiteAst.NUnfocus _ -> NTactics.unfocus_tac
368 | GrafiteAst.NWildcard _ -> NTactics.wildcard_tac
369 | GrafiteAst.NTry (_,tac) -> NTactics.try_tac
370 (aux f (text, prefix_len, tac))
371 | GrafiteAst.NAssumption _ -> NTactics.assumption_tac
372 | GrafiteAst.NBlock (_,l) ->
373 NTactics.block_tac (List.map (fun x -> aux f (text,prefix_len,x)) l)
374 |GrafiteAst.NRepeat (_,tac) ->
375 NTactics.repeat_tac (f f (text, prefix_len, tac))
377 aux aux tac (* trick for non uniform recursion call *)
380 let subst_metasenv_and_fix_names status =
381 let u,h,metasenv, subst,o = status#obj in
383 NCicUntrusted.map_obj_kind ~skip_body:true
384 (NCicUntrusted.apply_subst subst []) o
386 status#set_obj(u,h,NCicUntrusted.apply_subst_metasenv subst metasenv,subst,o)
390 let rec eval_ncommand opts status (text,prefix_len,cmd) =
392 | GrafiteAst.UnificationHint (loc, t, n) -> eval_unification_hint status t n
393 | GrafiteAst.NCoercion (loc, name, t, ty, source, target) ->
394 NCicCoercDeclaration.eval_ncoercion status name t ty source target
395 | GrafiteAst.NQed loc ->
396 if status#ng_mode <> `ProofMode then
397 raise (GrafiteTypes.Command_error "Not in proof mode")
399 let uri,height,menv,subst,obj_kind = status#obj in
402 (GrafiteTypes.Command_error"You can't Qed an incomplete theorem")
405 NCicUntrusted.map_obj_kind
406 (NCicUntrusted.apply_subst subst []) obj_kind in
407 let height = NCicTypeChecker.height_of_obj_kind uri [] obj_kind in
408 (* fix the height inside the object *)
409 let rec fix () = function
410 | NCic.Const (NReference.Ref (u,spec)) when NUri.eq u uri ->
411 NCic.Const (NReference.reference_of_spec u
413 | NReference.Def _ -> NReference.Def height
414 | NReference.Fix (i,j,_) -> NReference.Fix(i,j,height)
415 | NReference.CoFix _ -> NReference.CoFix height
416 | NReference.Ind _ | NReference.Con _
417 | NReference.Decl as s -> s))
418 | t -> NCicUtils.map (fun _ () -> ()) () fix t
423 NCicUntrusted.map_obj_kind (fix ()) obj_kind
426 let obj = uri,height,[],[],obj_kind in
427 prerr_endline ("pp new obj \n"^NCicPp.ppobj obj);
428 let old_status = status in
429 let status = NCicLibrary.add_obj status obj in
432 NCic.Constant (_,_,_,_,(_,`Example,_))
433 | NCic.Fixpoint (_,_,(_,`Example,_)) -> false
438 let status = index_obj_for_auto status obj in
439 (try index_eq_for_auto status uri
446 with _ -> prerr_endline "got an exception"; status
448 (* prerr_endline (NCicPp.ppobj obj); *)
449 HLog.message ("New object: " ^ NUri.string_of_uri uri);
451 (*prerr_endline (NCicPp.ppobj obj);*)
452 let boxml = NCicElim.mk_elims obj in
453 let boxml = boxml @ NCicElim.mk_projections obj in
456 let timestamp,uris_rev =
458 (fun (status,uris_rev) (uri,_,_,_,_) as obj ->
459 let status = NCicLibrary.add_obj status obj in
461 ) (status,[]) objs in
462 let uris = uri::List.rev uris_rev in
464 let status = status#set_ng_mode `CommandMode in
465 let status = LexiconSync.add_aliases_for_objs status (`New [uri]) in
468 (fun (status,uris) boxml ->
471 eval_ncommand opts status
472 ("",0,GrafiteAst.NObj (HExtlib.dummy_floc,boxml))
474 if nstatus#ng_mode <> `CommandMode then
476 (*HLog.warn "error in generating projection/eliminator";*)
480 nstatus, concat_nuris uris nuris
482 | MultiPassDisambiguator.DisambiguationError _
483 | NCicTypeChecker.TypeCheckerFailure _ ->
484 (*HLog.warn "error in generating projection/eliminator";*)
486 ) (status,`New [] (* uris *)) boxml in
487 let _,_,_,_,nobj = obj in
488 let status = match nobj with
489 NCic.Inductive (is_ind,leftno,[it],_) ->
490 let _,ind_name,ty,cl = it in
492 (fun status outsort ->
493 let status = status#set_ng_mode `ProofMode in
496 NInversion.mk_inverter
497 (ind_name ^ "_inv_" ^
498 (snd (NCicElim.ast_of_sort outsort)))
499 is_ind it leftno outsort status status#baseuri in
500 let _,_,menv,_,_ = invobj in
502 [] -> eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
503 | _ -> status,`New []))
505 with _ -> (*HLog.warn "error in generating inversion principle"; *)
506 let status = status#set_ng_mode `CommandMode in status)
509 List.map (fun s -> NCic.Type s) (NCicEnvironment.get_universes ()))
514 _,_,_,_,NCic.Inductive
515 (true,leftno,[_,_,_,[_,_,_]],(_,`Record fields))
518 (fun (name,is_coercion,arity) ->
519 if is_coercion then Some(name,leftno,arity) else None) fields
523 (fun (status,uris) (name,cpos,arity) ->
525 let metasenv,subst,status,t =
526 GrafiteDisambiguate.disambiguate_nterm None status [] [] []
527 ("",0,NotationPt.Ident (name,None)) in
528 assert (metasenv = [] && subst = []);
530 NCicCoercDeclaration.
531 basic_eval_and_record_ncoercion_from_t_cpos_arity
532 status (name,t,cpos,arity)
534 let uris = concat_nuris nuris uris in
536 with MultiPassDisambiguator.DisambiguationError _->
537 HLog.warn ("error in generating coercion: "^name);
539 (status,uris) coercions
544 NCicLibrary.time_travel old_status;
546 | GrafiteAst.NCopy (log,tgt,src_uri, map) ->
547 if status#ng_mode <> `CommandMode then
548 raise (GrafiteTypes.Command_error "Not in command mode")
550 let tgt_uri_ext, old_ok =
551 match NCicEnvironment.get_checked_obj src_uri with
552 | _,_,[],[], (NCic.Inductive _ as ok) -> ".ind", ok
553 | _,_,[],[], (NCic.Fixpoint _ as ok) -> ".con", ok
554 | _,_,[],[], (NCic.Constant _ as ok) -> ".con", ok
557 let tgt_uri = NUri.uri_of_string (status#baseuri^"/"^tgt^tgt_uri_ext) in
558 let map = (src_uri, tgt_uri) :: map in
560 let rec subst () = function
561 | NCic.Meta _ -> assert false
562 | NCic.Const (NReference.Ref (u,spec)) as t ->
564 (NReference.reference_of_spec (List.assoc u map)spec)
566 | t -> NCicUtils.map (fun _ _ -> ()) () subst t
568 NCicUntrusted.map_obj_kind ~skip_body:false (subst ()) old_ok
570 let ninitial_stack = Continuationals.Stack.of_nmetasenv [] in
571 let status = status#set_obj (tgt_uri,0,[],[],ok) in
572 (*prerr_endline (NCicPp.ppobj (tgt_uri,0,[],[],ok));*)
573 let status = status#set_stack ninitial_stack in
574 let status = subst_metasenv_and_fix_names status in
575 let status = status#set_ng_mode `ProofMode in
576 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
577 | GrafiteAst.NObj (loc,obj) ->
578 if status#ng_mode <> `CommandMode then
579 raise (GrafiteTypes.Command_error "Not in command mode")
582 GrafiteDisambiguate.disambiguate_nobj status
583 ~baseuri:status#baseuri (text,prefix_len,obj) in
584 let uri,height,nmenv,nsubst,nobj = obj in
585 let ninitial_stack = Continuationals.Stack.of_nmetasenv nmenv in
586 let status = status#set_obj obj in
587 let status = status#set_stack ninitial_stack in
588 let status = subst_metasenv_and_fix_names status in
589 let status = status#set_ng_mode `ProofMode in
592 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
593 | _ -> status,`New [])
594 | GrafiteAst.NDiscriminator (_,_) -> assert false (*(loc, indty) ->
595 if status#ng_mode <> `CommandMode then
596 raise (GrafiteTypes.Command_error "Not in command mode")
598 let status = status#set_ng_mode `ProofMode in
599 let metasenv,subst,status,indty =
600 GrafiteDisambiguate.disambiguate_nterm None status [] [] [] (text,prefix_len,indty) in
601 let indtyno, (_,_,tys,_,_) = match indty with
602 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
603 indtyno, NCicEnvironment.get_checked_indtys r
604 | _ -> prerr_endline ("engine: indty expected... (fix this error message)"); assert false in
605 let it = List.nth tys indtyno in
606 let status,obj = NDestructTac.mk_discriminator it status in
607 let _,_,menv,_,_ = obj in
609 [] -> eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
610 | _ -> prerr_endline ("Discriminator: non empty metasenv");
612 | GrafiteAst.NInverter (loc, name, indty, selection, sort) ->
613 if status#ng_mode <> `CommandMode then
614 raise (GrafiteTypes.Command_error "Not in command mode")
616 let metasenv,subst,status,sort = match sort with
617 | None -> [],[],status,NCic.Sort NCic.Prop
618 | Some s -> GrafiteDisambiguate.disambiguate_nterm None status [] [] []
621 assert (metasenv = []);
622 let sort = NCicReduction.whd ~subst [] sort in
623 let sort = match sort with
625 | _ -> raise (Invalid_argument (Printf.sprintf "ninverter: found target %s, which is not a sort"
626 (NCicPp.ppterm ~metasenv ~subst ~context:[] sort)))
628 let status = status#set_ng_mode `ProofMode in
629 let metasenv,subst,status,indty =
630 GrafiteDisambiguate.disambiguate_nterm None status [] [] subst (text,prefix_len,indty) in
631 let indtyno,(_,leftno,tys,_,_) = match indty with
632 NCic.Const ((NReference.Ref (_,NReference.Ind (_,indtyno,_))) as r) ->
633 indtyno, NCicEnvironment.get_checked_indtys r
634 | _ -> prerr_endline ("engine: indty =" ^ NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] indty) ; assert false in
635 let it = List.nth tys indtyno in
636 let status,obj = NInversion.mk_inverter name true it leftno ?selection sort
637 status status#baseuri in
638 let _,_,menv,_,_ = obj in
641 eval_ncommand opts status ("",0,GrafiteAst.NQed Stdpp.dummy_loc)
643 | GrafiteAst.NUnivConstraint (loc,u1,u2) ->
644 eval_add_constraint status [`Type,u1] [`Type,u2]
647 let rec eval_command = {ec_go = fun ~disambiguate_command opts status
648 (text,prefix_len,cmd) ->
649 let status,cmd = disambiguate_command status (text,prefix_len,cmd) in
652 | GrafiteAst.Drop loc -> raise Drop
653 | GrafiteAst.Include (loc, mode, new_or_old, baseuri) ->
654 (* Old Include command is not recursive; new one is *)
656 if new_or_old = `OldAndNew then
657 let moopath_rw, moopath_r =
658 LibraryMisc.obj_file_of_baseuri
659 ~must_exist:false ~baseuri ~writable:true,
660 LibraryMisc.obj_file_of_baseuri
661 ~must_exist:false ~baseuri ~writable:false in
663 if Sys.file_exists moopath_r then moopath_r else
664 if Sys.file_exists moopath_rw then moopath_rw else
665 raise (IncludedFileNotCompiled (moopath_rw,baseuri))
667 eval_from_moo.efm_go status moopath
672 NCicLibrary.Serializer.require ~baseuri:(NUri.uri_of_string baseuri)
675 GrafiteTypes.add_moo_content
676 [GrafiteAst.Include (loc,mode,`New,baseuri)] status
679 | GrafiteAst.Print (_,_) -> status,`New []
680 | GrafiteAst.Set (loc, name, value) -> status, `New []
681 (* GrafiteTypes.set_option status name value,[] *)
682 | GrafiteAst.Obj (loc,obj) -> (* MATITA 1.0 *) assert false
686 } and eval_executable = {ee_go = fun ~disambiguate_command
687 ~disambiguate_macro opts status (text,prefix_len,ex) ->
689 | GrafiteAst.NTactic (_(*loc*), tacl) ->
690 if status#ng_mode <> `ProofMode then
691 raise (GrafiteTypes.Command_error "Not in proof mode")
696 let status = eval_ng_tac (text,prefix_len,tac) status in
697 subst_metasenv_and_fix_names status)
701 | GrafiteAst.Command (_, cmd) ->
702 eval_command.ec_go ~disambiguate_command opts status (text,prefix_len,cmd)
703 | GrafiteAst.NCommand (_, cmd) ->
704 eval_ncommand opts status (text,prefix_len,cmd)
705 | GrafiteAst.Macro (loc, macro) ->
706 raise (Macro (loc,disambiguate_macro status (text,prefix_len,macro)))
707 | GrafiteAst.NMacro (loc, macro) ->
708 raise (NMacro (loc,macro))
710 } and eval_from_moo = {efm_go = fun status fname ->
712 ("",0,GrafiteAst.Executable (HExtlib.dummy_floc,
713 GrafiteAst.Command (HExtlib.dummy_floc,
716 let moo = GrafiteMarshal.load_moo fname in
719 let ast = ast_of_cmd ast in
722 ~disambiguate_command:(fun status (_,_,cmd) -> status,cmd)
723 ~disambiguate_macro:(fun _ _ -> assert false)
726 assert (lemmas=`New []);
729 } and eval_ast = {ea_go = fun ~disambiguate_command
730 ~disambiguate_macro ?(do_heavy_checks=false) status
733 let opts = { do_heavy_checks = do_heavy_checks ; } in
735 | GrafiteAst.Executable (_,ex) ->
736 eval_executable.ee_go ~disambiguate_command
737 ~disambiguate_macro opts status (text,prefix_len,ex)
738 | GrafiteAst.Comment (_,c) ->
739 eval_comment.ecm_go ~disambiguate_command opts status (text,prefix_len,c)
740 } and eval_comment = { ecm_go = fun ~disambiguate_command opts status (text,prefix_len,c) ->
746 let eval_ast = eval_ast.ea_go