]> matita.cs.unibo.it Git - helm.git/blob - helm/interface/reduction.ml
Initial revision
[helm.git] / helm / interface / reduction.ml
1 let read_from_stdin = ref false;;
2 let uris_in_input = ref false;;
3 let reduction_only = ref false;;
4
5 let parse uri =
6  print_endline ("^^^" ^ uri ^ "^^^") ;
7  print_string (CicPp.ppobj (CicCache.get_obj (UriManager.uri_of_string uri))) ;
8  print_endline ("\n$$$" ^ uri ^ "$$$\n")
9 ;;
10
11 let uri_of_filename fn =
12  if !uris_in_input then fn
13  else
14   let uri =
15    Str.replace_first (Str.regexp (Str.quote Configuration.helm_dir)) "cic:" fn
16   in
17    let uri' = Str.replace_first (Str.regexp "\.xml$") "" uri in
18     uri'
19 ;;
20
21 (* filenames are read from command line and converted to uris via *)
22 (* uri_of_filenames; then the cic terms are load in cache via     *)
23 (* CicCache.get_obj and then pretty printed via CicPp.ppobj       *)
24
25 exception NotADefinition;;
26
27 let main () =
28  let files = ref [] in
29  Arg.parse
30   ["-stdin", Arg.Set read_from_stdin, "Read from stdin" ;
31    "-uris", Arg.Set uris_in_input, "Read uris, not filenames" ;
32    "-update", Arg.Unit Getter.update, "Update the getter view of the world" ;
33    "-reduction", Arg.Set reduction_only, "Do reduction instead of tyepchecking"]
34   (fun x -> files := (uri_of_filename x) :: !files)
35   "
36 usage: experiment file ...
37
38 List of options:";
39  if !read_from_stdin then
40   begin
41    try
42     while true do
43      let l = Str.split (Str.regexp " ") (read_line ()) in
44       List.iter (fun x -> files := (uri_of_filename x) :: !files) l
45     done
46    with
47     End_of_file -> ()
48   end ;
49  files := List.rev !files;
50   List.iter
51    (function x ->
52      print_string x ;
53      flush stdout ;
54      (try
55        if !reduction_only then
56         match CicCache.get_obj (UriManager.uri_of_string x) with
57            Cic.Definition (_,bo,_,_) ->
58             CicTypeChecker.typecheck (UriManager.uri_of_string x) ;
59             ignore (CicReduction.whd bo)
60          | _ -> raise NotADefinition
61        else
62         CicTypeChecker.typecheck (UriManager.uri_of_string x)
63      with
64        e -> print_newline () ; flush stdout ; raise e ) ;
65      print_endline " OK!" ;
66      flush stdout
67    ) !files
68 ;;
69
70 main ();;