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