]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaEngine.ml
New argument for LApply: the ident for the generated hypothesis.
[helm.git] / helm / matita / matitaEngine.ml
1
2 open Printf
3 open MatitaTypes
4
5 let debug = false ;;
6 let debug_print = if debug then prerr_endline else ignore ;;
7
8 (** create a ProofEngineTypes.mk_fresh_name_type function which uses given
9   * names as long as they are available, then it fallbacks to name generation
10   * using FreshNamesGenerator module *)
11 let namer_of names =
12   let len = List.length names in
13   let count = ref 0 in
14   fun metasenv context name ~typ ->
15     if !count < len then begin
16       let name = Cic.Name (List.nth names !count) in
17       incr count;
18       name
19     end else
20       FreshNamesGenerator.mk_fresh_name ~subst:[] metasenv context name ~typ
21
22 let tactic_of_ast = function
23   | TacticAst.Absurd (_, term) -> Tactics.absurd term
24   | TacticAst.Apply (_, term) -> Tactics.apply term
25   | TacticAst.Assumption _ -> Tactics.assumption
26   | TacticAst.Auto (_,depth,width) -> 
27       AutoTactic.auto_tac ?depth ?width ~dbd:(MatitaDb.instance ()) ()
28   | TacticAst.Change (_, what, with_what, pattern) ->
29      Tactics.change ~what ~with_what ~pattern
30   | TacticAst.Clear (_,id) -> Tactics.clear id
31   | TacticAst.ClearBody (_,id) -> Tactics.clearbody id
32   | TacticAst.Contradiction _ -> Tactics.contradiction
33   | TacticAst.Compare (_, term) -> Tactics.compare term
34   | TacticAst.Constructor (_, n) -> Tactics.constructor n
35   | TacticAst.Cut (_, ident, term) ->
36      let names = match ident with None -> [] | Some id -> [id] in
37      Tactics.cut ~mk_fresh_name_callback:(namer_of names) term
38   | TacticAst.DecideEquality _ -> Tactics.decide_equality
39   | TacticAst.Decompose (_,term) -> Tactics.decompose term
40   | TacticAst.Discriminate (_,term) -> Tactics.discriminate term
41   | TacticAst.Elim (_, term, _) ->
42       Tactics.elim_intros term
43   | TacticAst.ElimType (_, term) -> Tactics.elim_type term
44   | TacticAst.Exact (_, term) -> Tactics.exact term
45   | TacticAst.Exists _ -> Tactics.exists
46   | TacticAst.Fail _ -> Tactics.fail
47   | TacticAst.Fold (_, reduction_kind ,term, pattern) ->
48      let reduction =
49       match reduction_kind with
50        | `Normalize -> CicReduction.normalize ~delta:false ~subst:[]
51        | `Reduce -> ProofEngineReduction.reduce
52        | `Simpl -> ProofEngineReduction.simpl
53        | `Whd -> CicReduction.whd ~delta:false ~subst:[]
54      in
55       Tactics.fold ~reduction ~pattern ~term
56   | TacticAst.Fourier _ -> Tactics.fourier
57   | TacticAst.FwdSimpl (_, term) -> 
58      Tactics.fwd_simpl ~what:term ~dbd:(MatitaDb.instance ())
59   | TacticAst.Generalize (_,term,ident,pat) ->
60      let names = match ident with None -> [] | Some id -> [id] in
61      Tactics.generalize ~term ~mk_fresh_name_callback:(namer_of names) pat
62   | TacticAst.Goal (_, n) -> Tactics.set_goal n
63   | TacticAst.IdTac _ -> Tactics.id
64   | TacticAst.Injection (_,term) -> Tactics.injection term
65   | TacticAst.Intros (_, None, names) ->
66       PrimitiveTactics.intros_tac ~mk_fresh_name_callback:(namer_of names) ()
67   | TacticAst.Intros (_, Some num, names) ->
68       PrimitiveTactics.intros_tac ~howmany:num
69         ~mk_fresh_name_callback:(namer_of names) ()
70   | TacticAst.LApply (_, to_what, what, ident) ->
71      let names = match ident with None -> [] | Some id -> [id] in
72      Tactics.lapply ~mk_fresh_name_callback:(namer_of names) ?to_what what
73   | TacticAst.Left _ -> Tactics.left
74   | TacticAst.LetIn (loc,term,name) ->
75       Tactics.letin term ~mk_fresh_name_callback:(namer_of [name])
76   | TacticAst.Reduce (_, reduction_kind, pattern) ->
77       (match reduction_kind with
78       | `Normalize -> Tactics.normalize ~pattern
79       | `Reduce -> Tactics.reduce ~pattern  
80       | `Simpl -> Tactics.simpl ~pattern 
81       | `Whd -> Tactics.whd ~pattern)
82   | TacticAst.Reflexivity _ -> Tactics.reflexivity
83   | TacticAst.Replace (_, pattern, with_what) ->
84      Tactics.replace ~pattern ~with_what
85   | TacticAst.Rewrite (_, dir, t, pattern) ->
86       if dir = `Left then
87         EqualityTactics.rewrite_tac ~where:pattern ~term:t ()
88       else
89         EqualityTactics.rewrite_back_tac ~where:pattern ~term:t ()
90   | TacticAst.Right _ -> Tactics.right
91   | TacticAst.Ring _ -> Tactics.ring
92   | TacticAst.Split _ -> Tactics.split
93   | TacticAst.Symmetry _ -> Tactics.symmetry
94   | TacticAst.Transitivity (_, term) -> Tactics.transitivity term
95
96 let eval_tactical status tac =
97   let apply_tactic tactic =
98     let (proof, goals) =
99       ProofEngineTypes.apply_tactic tactic (MatitaMisc.get_proof_status status)
100     in
101     let new_status =
102       match goals with
103       | [] -> 
104           let (_,metasenv,_,_) = proof in
105           (match metasenv with
106           | [] -> Proof proof
107           | (ng,_,_)::_ -> Incomplete_proof (proof,ng))
108       | ng::_ -> Incomplete_proof (proof, ng)
109     in
110     { status with proof_status = new_status }
111   in
112   let rec tactical_of_ast = function
113     | TacticAst.Tactic (loc, tactic) -> tactic_of_ast tactic
114     | TacticAst.Do (loc, num, tactical) ->
115         Tacticals.do_tactic num (tactical_of_ast tactical)
116     | TacticAst.Repeat (loc, tactical) ->
117         Tacticals.repeat_tactic (tactical_of_ast tactical)
118     | TacticAst.Seq (loc, tacticals) ->  (* tac1; tac2; ... *)
119         Tacticals.seq (List.map tactical_of_ast tacticals)
120     | TacticAst.Then (loc, tactical, tacticals) ->  (* tac; [ tac1 | ... ] *)
121         Tacticals.thens (tactical_of_ast tactical)
122           (List.map tactical_of_ast tacticals)
123     | TacticAst.Tries (loc, tacticals) ->
124         Tacticals.try_tactics
125           (List.map (fun t -> "", tactical_of_ast t) tacticals)
126     | TacticAst.Try (loc, tactical) ->
127         Tacticals.try_tactic (tactical_of_ast tactical)
128   in
129   apply_tactic (tactical_of_ast tac)
130
131 let eval_coercion status coercion = 
132   let coer_uri,coer_ty =
133     match coercion with 
134     | Cic.Const (uri,_)
135     | Cic.Var (uri,_) ->
136         let o,_ = 
137           CicEnvironment.get_obj CicUniv.empty_ugraph uri 
138         in
139         (match o with
140         | Cic.Constant (_,_,ty,_,_)
141         | Cic.Variable (_,_,ty,_,_) ->
142             uri,ty
143         | _ -> assert false)
144     | Cic.MutConstruct (uri,t,c,_) ->
145         let o,_ = 
146           CicEnvironment.get_obj CicUniv.empty_ugraph uri 
147         in
148         (match o with
149         | Cic.InductiveDefinition (l,_,_,_) ->
150             let (_,_,_,cl) = List.nth l t in
151             let (_,cty) = List.nth cl c in
152               uri,cty
153         | _ -> assert false)
154     | _ -> assert false 
155   in
156   (* we have to get the source and the tgt type uri 
157    * in Coq syntax we have already their names, but 
158    * since we don't support Funclass and similar I think
159    * all the coercion should be of the form
160    * (A:?)(B:?)T1->T2
161    * So we should be able to extract them from the coercion type
162    *)
163   let extract_last_two_p ty =
164     let rec aux = function
165       | Cic.Prod( _, src, Cic.Prod (n,t1,t2)) -> aux (Cic.Prod(n,t1,t2))   
166       | Cic.Prod( _, src, tgt) -> src, tgt
167       | _ -> assert false
168     in  
169     aux ty
170   in
171   let ty_src,ty_tgt = extract_last_two_p coer_ty in
172   let context = [] in 
173   let src_uri = 
174     let ty_src = CicReduction.whd context ty_src in
175      CicUtil.uri_of_term ty_src
176   in
177   let tgt_uri = 
178     let ty_tgt = CicReduction.whd context ty_tgt in
179      CicUtil.uri_of_term ty_tgt
180   in
181   let new_coercions =
182     (* also adds them to the Db *)
183     CoercGraph.close_coercion_graph src_uri tgt_uri coer_uri in
184   let status =
185    List.fold_left (fun s (uri,o,ugraph) -> MatitaSync.add_obj uri o status)
186     status new_coercions in
187   {status with proof_status = No_proof}
188
189 let generate_elimination_principles uri status =
190  let elim sort status =
191    try
192     let uri,obj = CicElim.elim_of ~sort uri 0 in
193      MatitaSync.add_obj uri obj status
194    with CicElim.Can_t_eliminate -> status
195  in
196  List.fold_left (fun status sort -> elim sort status) status
197   [ Cic.Prop; Cic.Set; (Cic.Type (CicUniv.fresh ())) ]
198
199 let generate_projections uri fields status =
200  let projections = CicRecord.projections_of uri fields in
201   List.fold_left
202    (fun status (uri, name, bo) -> 
203      try 
204       let ty, ugraph = 
205         CicTypeChecker.type_of_aux' [] [] bo CicUniv.empty_ugraph in
206       let bo = Unshare.unshare bo in
207       let ty = Unshare.unshare ty in
208       let attrs = [`Class `Projection; `Generated] in
209       let obj = Cic.Constant (name,Some bo,ty,[],attrs) in
210        MatitaSync.add_obj uri obj status
211      with
212         CicTypeChecker.TypeCheckerFailure s ->
213          MatitaLog.message 
214           ("Unable to create projection " ^ name ^ " cause: " ^ s);
215          status
216       | CicEnvironment.Object_not_found uri ->
217          let depend = UriManager.name_of_uri uri in
218           MatitaLog.message 
219            ("Unable to create projection " ^ name ^ " because it requires " ^ depend);
220          status
221   ) status projections
222  
223 let eval_command status cmd =
224   match cmd with
225   | TacticAst.Set (loc, name, value) -> set_option status name value
226   | TacticAst.Qed loc ->
227       let uri, metasenv, bo, ty = 
228         match status.proof_status with
229         | Proof (Some uri, metasenv, body, ty) ->
230             uri, metasenv, body, ty
231         | Proof (None, metasenv, body, ty) -> 
232             command_error 
233               ("Someone allows to start a thm without giving the "^
234                "name/uri. This should be fixed!")
235         | _-> command_error "You can't qed an uncomplete theorem"
236       in
237       let suri = UriManager.string_of_uri uri in
238       if metasenv <> [] then 
239         command_error "Proof not completed! metasenv is not empty!";
240       let name = UriManager.name_of_uri uri in
241       let obj = Cic.Constant (name,Some bo,ty,[],[]) in
242       MatitaSync.add_obj uri obj status
243   | TacticAst.Coercion (loc, coercion) -> 
244       eval_coercion status coercion
245   | TacticAst.Alias (loc, spec) -> 
246      (match spec with
247       | TacticAst.Ident_alias (id,uri) -> 
248           {status with aliases = 
249             DisambiguateTypes.Environment.add 
250               (DisambiguateTypes.Id id) 
251               ("boh?",(fun _ _ _ -> CicUtil.term_of_uri (UriManager.uri_of_string uri)))
252               status.aliases }
253       | TacticAst.Symbol_alias (symb, instance, desc) ->
254           {status with aliases = 
255             DisambiguateTypes.Environment.add 
256               (DisambiguateTypes.Symbol (symb,instance))
257               (DisambiguateChoices.lookup_symbol_by_dsc symb desc) 
258               status.aliases }
259       | TacticAst.Number_alias (instance,desc) ->
260           {status with aliases = 
261             DisambiguateTypes.Environment.add 
262               (DisambiguateTypes.Num instance) 
263               (DisambiguateChoices.lookup_num_by_dsc desc) status.aliases })
264   | TacticAst.Obj (loc,obj) ->
265      let ext,name =
266       match obj with
267          Cic.Constant (name,_,_,_,_)
268        | Cic.CurrentProof (name,_,_,_,_,_) -> ".con",name
269        | Cic.InductiveDefinition (types,_,_,_) ->
270           ".ind",
271           (match types with (name,_,_,_)::_ -> name | _ -> assert false)
272        | _ -> assert false in
273      let uri = 
274        UriManager.uri_of_string (MatitaMisc.qualify status name ^ ext) 
275      in
276      let metasenv = MatitaMisc.get_proof_metasenv status in
277      match obj with
278         Cic.CurrentProof (_,metasenv',bo,ty,_,_) ->
279          assert (metasenv = metasenv');
280          let goalno =
281           match metasenv' with (goalno,_,_)::_ -> goalno | _ -> assert false in
282          let initial_proof = (Some uri, metasenv, bo, ty) in
283           { status with proof_status = Incomplete_proof (initial_proof,goalno)}
284       | _ ->
285         if metasenv <> [] then
286          command_error (
287            "metasenv not empty while giving a definition with body: " ^
288            CicMetaSubst.ppmetasenv metasenv []);
289         let status = MatitaSync.add_obj uri obj status in
290          match obj with
291             Cic.Constant _ -> status
292           | Cic.InductiveDefinition (_,_,_,attrs) ->
293              let status = generate_elimination_principles uri status in
294              let rec get_record_attrs =
295               function
296                  [] -> None
297                | (`Class (`Record fields))::_ -> Some fields
298                | _::tl -> get_record_attrs tl
299              in
300               (match get_record_attrs attrs with
301                   None -> status (* not a record *)
302                 | Some fields -> generate_projections uri fields status)
303           | Cic.CurrentProof _
304           | Cic.Variable _ -> assert false
305
306 let eval_executable status ex =
307   match ex with
308   | TacticAst.Tactical (_, tac) -> eval_tactical status tac
309   | TacticAst.Command (_, cmd) -> eval_command status cmd
310   | TacticAst.Macro (_, mac) -> 
311       command_error (sprintf "The macro %s can't be in a script" 
312         (TacticAstPp.pp_macro_cic mac))
313
314 let eval_comment status c = status
315             
316 let eval status st =
317   match st with
318   | TacticAst.Executable (_,ex) -> eval_executable status ex
319   | TacticAst.Comment (_,c) -> eval_comment status c
320
321 let disambiguate_term status term =
322   let (aliases, metasenv, cic, _) =
323     match
324       MatitaDisambiguator.disambiguate_term ~dbd:(MatitaDb.instance ())
325         ~aliases:(status.aliases) ~context:(MatitaMisc.get_proof_context status)
326         ~metasenv:(MatitaMisc.get_proof_metasenv status) term
327     with
328     | [x] -> x
329     | _ -> assert false
330   in
331   let proof_status =
332     match status.proof_status with
333     | No_proof -> Intermediate metasenv
334     | Incomplete_proof ((uri, _, proof, ty), goal) ->
335         Incomplete_proof ((uri, metasenv, proof, ty), goal)
336     | Intermediate _ -> Intermediate metasenv 
337     | Proof _ -> assert false
338   in
339   let status =
340     { status with
341         aliases = aliases;
342         proof_status = proof_status }
343   in
344   status, cic
345   
346 let disambiguate_obj status obj =
347   let uri =
348    match obj with
349       TacticAst.Inductive (_,(name,_,_,_)::_)
350     | TacticAst.Record (_,name,_,_) ->
351        Some (UriManager.uri_of_string (MatitaMisc.qualify status name ^ ".ind"))
352     | TacticAst.Inductive _ -> assert false
353     | _ -> None in
354   let (aliases, metasenv, cic, _) =
355     match
356       MatitaDisambiguator.disambiguate_obj ~dbd:(MatitaDb.instance ())
357         ~aliases:(status.aliases) ~uri obj
358     with
359     | [x] -> x
360     | _ -> assert false
361   in
362   let proof_status =
363     match status.proof_status with
364     | No_proof -> Intermediate metasenv
365     | Incomplete_proof _
366     | Intermediate _
367     | Proof _ -> assert false
368   in
369   let status =
370     { status with
371         aliases = aliases;
372         proof_status = proof_status }
373   in
374   status, cic
375   
376 let disambiguate_pattern aliases (hyp_paths ,goal_path) =
377   let interp path = Disambiguate.interpretate_path [] aliases path in
378   let goal_path = 
379     match goal_path with 
380     | None -> None
381     | Some path -> Some (interp path) in
382   let hyp_paths = List.map (fun (name, path) -> name, interp path) hyp_paths in
383   (hyp_paths ,goal_path)
384   
385 let disambiguate_tactic status = function
386   | TacticAst.Apply (loc, term) ->
387       let status, cic = disambiguate_term status term in
388       status, TacticAst.Apply (loc, cic)
389   | TacticAst.Absurd (loc, term) -> 
390       let status, cic = disambiguate_term status term in
391       status, TacticAst.Absurd (loc, cic)
392   | TacticAst.Assumption loc -> status, TacticAst.Assumption loc
393   | TacticAst.Auto (loc,depth,width) -> status, TacticAst.Auto (loc,depth,width)
394   | TacticAst.Change (loc, what, with_what, pattern) -> 
395       let status, cic1 = disambiguate_term status what in
396       let status, cic2 = disambiguate_term status with_what in
397       let pattern = disambiguate_pattern status.aliases pattern in
398       status, TacticAst.Change (loc, cic1, cic2, pattern)
399   | TacticAst.Clear (loc,id) -> status,TacticAst.Clear (loc,id)
400   | TacticAst.ClearBody (loc,id) -> status,TacticAst.ClearBody (loc,id)
401   | TacticAst.Compare (loc,term) ->
402       let status, term = disambiguate_term status term in
403       status, TacticAst.Compare (loc,term)
404   | TacticAst.Constructor (loc,n) ->
405       status, TacticAst.Constructor (loc,n)
406   | TacticAst.Contradiction loc ->
407       status, TacticAst.Contradiction loc
408   | TacticAst.Cut (loc, ident, term) -> 
409       let status, cic = disambiguate_term status term in
410       status, TacticAst.Cut (loc, ident, cic)
411   | TacticAst.DecideEquality loc ->
412       status, TacticAst.DecideEquality loc
413   | TacticAst.Decompose (loc,term) ->
414       let status,term = disambiguate_term status term in
415       status, TacticAst.Decompose(loc,term)
416   | TacticAst.Discriminate (loc,term) ->
417       let status,term = disambiguate_term status term in
418       status, TacticAst.Discriminate(loc,term)
419   | TacticAst.Exact (loc, term) -> 
420       let status, cic = disambiguate_term status term in
421       status, TacticAst.Exact (loc, cic)
422   | TacticAst.Elim (loc, term, Some term') ->
423       let status, cic1 = disambiguate_term status term in
424       let status, cic2 = disambiguate_term status term' in
425       status, TacticAst.Elim (loc, cic1, Some cic2)
426   | TacticAst.Elim (loc, term, None) ->
427       let status, cic = disambiguate_term status term in
428       status, TacticAst.Elim (loc, cic, None)
429   | TacticAst.ElimType (loc, term) -> 
430       let status, cic = disambiguate_term status term in
431       status, TacticAst.ElimType (loc, cic)
432   | TacticAst.Exists loc -> status, TacticAst.Exists loc 
433   | TacticAst.Fail loc -> status,TacticAst.Fail loc
434   | TacticAst.Fold (loc,reduction_kind, term, pattern) ->
435      let status, term = disambiguate_term status term in
436      let pattern = disambiguate_pattern status.aliases pattern in
437      status, TacticAst.Fold (loc,reduction_kind, term, pattern)
438   | TacticAst.FwdSimpl (loc, term) ->
439      let status, term = disambiguate_term status term in
440      status, TacticAst.FwdSimpl (loc, term)  
441   | TacticAst.Fourier loc -> status, TacticAst.Fourier loc
442   | TacticAst.Generalize (loc,term,ident,pattern) ->
443       let status,term = disambiguate_term status term in
444       let pattern = disambiguate_pattern status.aliases pattern in
445       status, TacticAst.Generalize(loc,term,ident,pattern)
446   | TacticAst.Goal (loc, g) -> status, TacticAst.Goal (loc, g)
447   | TacticAst.IdTac loc -> status,TacticAst.IdTac loc
448   | TacticAst.Injection (loc,term) ->
449       let status, term = disambiguate_term status term in
450       status, TacticAst.Injection (loc,term)
451   | TacticAst.Intros (loc, num, names) ->
452       status, TacticAst.Intros (loc, num, names)
453   | TacticAst.LApply (loc, to_what, what, ident) ->
454      let status, to_what =
455       match to_what with
456          None -> status,None
457        | Some to_what -> 
458            let status, to_what = disambiguate_term status to_what in
459            status, Some to_what
460      in
461      let status, what = disambiguate_term status what in
462      status, TacticAst.LApply (loc, to_what, what, ident)
463   | TacticAst.Left loc -> status, TacticAst.Left loc
464   | TacticAst.LetIn (loc, term, name) ->
465       let status, term = disambiguate_term status term in
466       status, TacticAst.LetIn (loc,term,name)
467   | TacticAst.Reduce (loc, reduction_kind, pattern) ->
468       let pattern = disambiguate_pattern status.aliases pattern in
469       status, TacticAst.Reduce(loc, reduction_kind, pattern)
470   | TacticAst.Reflexivity loc -> status, TacticAst.Reflexivity loc
471   | TacticAst.Replace (loc, pattern, with_what) -> 
472       let pattern = disambiguate_pattern status.aliases pattern in
473       let status, with_what = disambiguate_term status with_what in
474       status, TacticAst.Replace (loc, pattern, with_what)
475   | TacticAst.Rewrite (loc, dir, t, pattern) ->
476       let status, term = disambiguate_term status t in
477       let pattern = disambiguate_pattern status.aliases pattern in
478       status, TacticAst.Rewrite (loc, dir, term, pattern)
479   | TacticAst.Right loc -> status, TacticAst.Right loc
480   | TacticAst.Ring loc -> status, TacticAst.Ring loc
481   | TacticAst.Split loc -> status, TacticAst.Split loc
482   | TacticAst.Symmetry loc -> status, TacticAst.Symmetry loc
483   | TacticAst.Transitivity (loc, term) -> 
484       let status, cic = disambiguate_term status term in
485       status, TacticAst.Transitivity (loc, cic)
486
487 let rec disambiguate_tactical status = function 
488   | TacticAst.Tactic (loc, tactic) -> 
489       let status, tac = disambiguate_tactic status tactic in
490       status, TacticAst.Tactic (loc, tac)
491   | TacticAst.Do (loc, num, tactical) ->
492       let status, tac = disambiguate_tactical status tactical in
493       status, TacticAst.Do (loc, num, tac)
494   | TacticAst.Repeat (loc, tactical) -> 
495       let status, tac = disambiguate_tactical status tactical in
496       status, TacticAst.Repeat (loc, tac)
497   | TacticAst.Seq (loc, tacticals) ->  (* tac1; tac2; ... *)
498       let status, tacticals = disambiguate_tacticals status tacticals in
499       let tacticals = List.rev tacticals in
500       status, TacticAst.Seq (loc, tacticals)
501   | TacticAst.Then (loc, tactical, tacticals) ->  (* tac; [ tac1 | ... ] *)
502       let status, tactical = disambiguate_tactical status tactical in
503       let status, tacticals = disambiguate_tacticals status tacticals in
504       status, TacticAst.Then (loc, tactical, tacticals)
505   | TacticAst.Tries (loc, tacticals) ->
506       let status, tacticals = disambiguate_tacticals status tacticals in
507       status, TacticAst.Tries (loc, tacticals)
508   | TacticAst.Try (loc, tactical) ->
509       let status, tactical = disambiguate_tactical status tactical in
510       status, TacticAst.Try (loc, tactical)
511
512 and disambiguate_tacticals status tacticals =
513   let status, tacticals =
514     List.fold_left
515       (fun (status, tacticals) tactical ->
516         let status, tac = disambiguate_tactical status tactical in
517         status, tac :: tacticals)
518       (status, [])
519       tacticals
520   in
521   let tacticals = List.rev tacticals in
522   status, tacticals
523   
524 let disambiguate_command status = function
525   | TacticAst.Coercion (loc, term) ->
526       let status, term = disambiguate_term status term in
527       status, TacticAst.Coercion (loc,term)
528   | (TacticAst.Set _ | TacticAst.Qed _) as cmd ->
529       status, cmd
530   | TacticAst.Alias _ as x -> status, x
531   | TacticAst.Obj (loc,obj) ->
532       let status,obj = disambiguate_obj status obj in
533        status, TacticAst.Obj (loc,obj)
534
535 let disambiguate_executable status ex =
536   match ex with
537   | TacticAst.Tactical (loc, tac) ->
538       let status, tac = disambiguate_tactical status tac in
539       status, (TacticAst.Tactical (loc, tac))
540   | TacticAst.Command (loc, cmd) ->
541       let status, cmd = disambiguate_command status cmd in
542       status, (TacticAst.Command (loc, cmd))
543   | TacticAst.Macro (_, mac) -> 
544       command_error (sprintf "The macro %s can't be in a script" 
545         (TacticAstPp.pp_macro_ast mac))
546
547 let disambiguate_comment status c = 
548   match c with
549   | TacticAst.Note (loc,n) -> status, TacticAst.Note (loc,n)
550   | TacticAst.Code (loc,ex) -> 
551         let status, ex = disambiguate_executable status ex in
552         status, TacticAst.Code (loc,ex)
553         
554 let disambiguate_statement status statement =
555   match statement with
556   | TacticAst.Comment (loc,c) -> 
557         let status, c = disambiguate_comment status c in
558         status, TacticAst.Comment (loc,c)
559   | TacticAst.Executable (loc,ex) -> 
560         let status, ex = disambiguate_executable status ex in
561         status, TacticAst.Executable (loc,ex)
562   
563 let eval_ast status ast =
564   let status,st = disambiguate_statement status ast in
565   (* this disambiguation step should be deferred to support tacticals *)
566   eval status st
567
568 let eval_from_stream status str cb =
569   let stl = CicTextualParser2.parse_statements str in
570   List.fold_left 
571     (fun status ast -> cb status ast;eval_ast status ast) status 
572   stl
573   
574 let eval_string status str =
575   eval_from_stream status (Stream.of_string str) (fun _ _ -> ())
576
577 let default_options () =
578   let options =
579     StringMap.add "baseuri"
580       (String
581         (Helm_registry.get "matita.baseuri" ^ Helm_registry.get "matita.owner"))
582       no_options
583   in
584   let options =
585     StringMap.add "basedir"
586       (String (Helm_registry.get "matita.basedir" ))
587       options
588   in
589   options
590
591 let initial_status =
592   lazy {
593     aliases = DisambiguateTypes.empty_environment;
594     proof_status = No_proof;
595     options = default_options ();
596     objects = [];
597   }
598
599