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

Contents of /driver/cduce.ml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations)
Tue Jul 10 16:59:02 2007 UTC (5 years, 11 months ago) by abate
File size: 2452 byte(s)
[r2002-10-20 21:38:35 by cvscast] Empty log message

Original author: cvscast
Date: 2002-10-20 21:38:36+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 19 | Typer.ShouldHave (t,msg) ->
40     Format.fprintf ppf "This expression should have type %a@\n%s@\n"
41     Types.Print.print_descr t
42     msg
43 abate 10 | Typer.Constraint (s,t,msg) ->
44 abate 19 Format.fprintf ppf "This expression should have type %a@\n"
45     Types.Print.print_descr t;
46     Format.fprintf ppf "but its infered type is: %a@\n"
47     Types.Print.print_descr s;
48     Format.fprintf ppf "which is not a subtype, as shown by the value %a@\n"
49     Types.Print.print_sample (Types.Sample.get (Types.diff s t));
50     Format.fprintf ppf "%s@\n" msg
51 abate 17 | Typer.NonExhaustive t ->
52     Format.fprintf ppf "This pattern matching is not exhaustive@\n";
53     Format.fprintf ppf "Residual type: %a@\n"
54     Types.Print.print_descr t;
55     Format.fprintf ppf "Sample value: %a@\n"
56     Types.Print.print_sample (Types.Sample.get t)
57 abate 10 | exn ->
58     Format.fprintf ppf "%s@\n" (Printexc.to_string exn)
59    
60     let phrase ph =
61     match ph.descr with
62     | Ast.EvalStatement e ->
63     let (fv,e) = Typer.expr e in
64 abate 19 let t = Typer.type_check Typer.Env.empty e Types.any true in
65 abate 22 Format.fprintf ppf "%a@\n" Types.Print.print_descr t
66 abate 13 | Ast.TypeDecl _ -> ()
67 abate 10 | _ -> assert false
68    
69     let () =
70 abate 13 try
71     let p = prog () in
72     let type_decls =
73     List.fold_left
74     (fun accu ph -> match ph.descr with
75     | Ast.TypeDecl (x,t) -> (x,t) :: accu
76     | _ -> accu
77     ) [] p in
78     Typer.register_global_types type_decls;
79     List.iter phrase p
80 abate 17 with (Failure _) as e -> raise e | exn -> print_exn ppf exn
81 abate 10
82 abate 21
83    
84    
85    

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