/[svn]/driver/cduce.ml
ViewVC logotype

Contents of /driver/cduce.ml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (hide annotations)
Tue Jul 10 16:59:11 2007 UTC (5 years, 10 months ago) by abate
File size: 2688 byte(s)
[r2002-10-21 09:03:48 by cvscast] Empty log message

Original author: cvscast
Date: 2002-10-21 09:03:48+00:00
1 abate 10 open Location
2 abate 23 exception Usage
3 abate 10
4 abate 18 let () =
5     List.iter
6     (fun (n,t) -> Typer.register_global_types [n, mk noloc (Ast.Internal t)])
7     Builtin.types
8    
9 abate 21
10 abate 25 let (source,input_channel) =
11 abate 23 match Array.length Sys.argv with
12 abate 25 | 1 -> ("",stdin)
13     | 2 -> let s = Sys.argv.(1) in (s, open_in s)
14 abate 23 | _ -> raise Usage
15 abate 21
16 abate 23 let input = Stream.of_channel input_channel
17    
18 abate 10 let ppf = Format.std_formatter
19     let prog () =
20     try Parser.prog input
21     with
22 abate 21 | Stdpp.Exc_located (loc, e) -> raise (Location (loc, e))
23 abate 10
24     let rec print_exn ppf = function
25     | Location ((i,j), exn) ->
26 abate 25 if source = "" then
27     Format.fprintf ppf "Error at chars %i-%i@\n" i j
28     else (
29     let (l1,c1) = Location.get_line_number source i
30     and (l2,c2) = Location.get_line_number source j in
31     if l1 = l2 then
32     Format.fprintf ppf "Error at line %i (chars %i-%i)@\n"
33     l1 c1 c2
34     else
35     Format.fprintf ppf "Error at lines %i (char %i) - %i (char %i)@\n"
36     l1 c1 l2 c2
37     );
38 abate 10 print_exn ppf exn
39 abate 26 | Typer.WrongLabel (t,l) ->
40     Format.fprintf ppf "Wrong record selection: the label %s@\n"
41     (Types.label_name l);
42 abate 27 Format.fprintf ppf "applied to an expression of type %a@\n"
43     Types.Print.print_descr t
44 abate 19 | Typer.ShouldHave (t,msg) ->
45     Format.fprintf ppf "This expression should have type %a@\n%s@\n"
46     Types.Print.print_descr t
47     msg
48 abate 10 | Typer.Constraint (s,t,msg) ->
49 abate 19 Format.fprintf ppf "This expression should have type %a@\n"
50     Types.Print.print_descr t;
51     Format.fprintf ppf "but its infered type is: %a@\n"
52     Types.Print.print_descr s;
53     Format.fprintf ppf "which is not a subtype, as shown by the value %a@\n"
54     Types.Print.print_sample (Types.Sample.get (Types.diff s t));
55     Format.fprintf ppf "%s@\n" msg
56 abate 17 | Typer.NonExhaustive t ->
57     Format.fprintf ppf "This pattern matching is not exhaustive@\n";
58     Format.fprintf ppf "Residual type: %a@\n"
59     Types.Print.print_descr t;
60     Format.fprintf ppf "Sample value: %a@\n"
61     Types.Print.print_sample (Types.Sample.get t)
62 abate 10 | exn ->
63     Format.fprintf ppf "%s@\n" (Printexc.to_string exn)
64    
65     let phrase ph =
66     match ph.descr with
67     | Ast.EvalStatement e ->
68     let (fv,e) = Typer.expr e in
69 abate 19 let t = Typer.type_check Typer.Env.empty e Types.any true in
70 abate 22 Format.fprintf ppf "%a@\n" Types.Print.print_descr t
71 abate 13 | Ast.TypeDecl _ -> ()
72 abate 10 | _ -> assert false
73    
74     let () =
75 abate 13 try
76     let p = prog () in
77     let type_decls =
78     List.fold_left
79     (fun accu ph -> match ph.descr with
80     | Ast.TypeDecl (x,t) -> (x,t) :: accu
81     | _ -> accu
82     ) [] p in
83     Typer.register_global_types type_decls;
84     List.iter phrase p
85 abate 26 with (Failure _) as e -> raise e
86     | exn -> print_exn ppf exn
87 abate 10
88 abate 21
89    
90    
91    

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5