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