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

Diff of /driver/cduce.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 431 by abate, Tue Jul 10 17:34:25 2007 UTC revision 433 by abate, Tue Jul 10 17:34:42 2007 UTC
# Line 31  Line 31 
31  let dump_env ppf =  let dump_env ppf =
32    Format.fprintf ppf "Global types:";    Format.fprintf ppf "Global types:";
33    Typer.dump_global_types ppf;    Typer.dump_global_types ppf;
34    Format.fprintf ppf ".@\n";    Format.fprintf ppf ".@.";
35    Env.iter    Env.iter
36      (fun x v ->      (fun x v ->
37         let t = Env.find x !typing_env in         let t = Env.find x !typing_env in
38         Format.fprintf ppf "@[|- %a : %a@ => %a@]@\n"         Format.fprintf ppf "@[val %a : @[%a = %a@]@]@."
39           U.print (Id.value x)           U.print (Id.value x) print_norm t print_value v
          print_norm t  
          print_value v  
40      )      )
41      !eval_env      !eval_env
42    
43    
44  let rec print_exn ppf = function  let rec print_exn ppf = function
45    | Location (loc, exn) ->    | Location (loc, exn) ->
46        Format.fprintf ppf "Error %a:@\n" Location.print_loc loc;        Format.fprintf ppf "Error %a:@." Location.print_loc loc;
47        Format.fprintf ppf "%a" Location.html_hilight loc;        Format.fprintf ppf "%a" Location.html_hilight loc;
48        print_exn ppf exn        print_exn ppf exn
49    | Value.CDuceExn v ->    | Value.CDuceExn v ->
50        Format.fprintf ppf "Uncaught CDuce exception: @[%a@]@\n"        Format.fprintf ppf "Uncaught CDuce exception: @[%a@]@."
51          print_value v          print_value v
52    | Eval.MultipleDeclaration v ->    | Eval.MultipleDeclaration v ->
53        Format.fprintf ppf "Multiple declaration for global value %a@\n"        Format.fprintf ppf "Multiple declaration for global value %a@."
54          U.print (Id.value v)          U.print (Id.value v)
55    | Typer.WrongLabel (t,l) ->    | Typer.WrongLabel (t,l) ->
56        Format.fprintf ppf "Wrong record selection: the label %a@\n"        Format.fprintf ppf "Wrong record selection: the label %a@."
57          U.print (LabelPool.value l);          U.print (LabelPool.value l);
58        Format.fprintf ppf "applied to an expression of type:@\n%a@\n"        Format.fprintf ppf "applied to an expression of type:@.%a@."
59          print_norm t          print_norm t
60    | Typer.ShouldHave (t,msg) ->    | Typer.ShouldHave (t,msg) ->
61        Format.fprintf ppf "This expression should have type:@\n%a@\n%s@\n"        Format.fprintf ppf "This expression should have type:@.%a@.%s@."
62          print_norm t          print_norm t
63          msg          msg
64    | Typer.ShouldHave2 (t1,msg,t2) ->    | Typer.ShouldHave2 (t1,msg,t2) ->
65        Format.fprintf ppf "This expression should have type:@\n%a@\n%s %a@\n"        Format.fprintf ppf "This expression should have type:@.%a@.%s %a@."
66          print_norm t1          print_norm t1
67          msg          msg
68          print_norm t2          print_norm t2
69    | Typer.Error s ->    | Typer.Error s ->
70        Format.fprintf ppf "%s@\n" s        Format.fprintf ppf "%s@." s
71    | Typer.Constraint (s,t) ->    | Typer.Constraint (s,t) ->
72        Format.fprintf ppf "This expression should have type:@\n%a@\n"        Format.fprintf ppf "This expression should have type:@.%a@."
73          print_norm t;          print_norm t;
74        Format.fprintf ppf "but its inferred type is:@\n%a@\n"        Format.fprintf ppf "but its inferred type is:@.%a@."
75          print_norm s;          print_norm s;
76        Format.fprintf ppf "which is not a subtype, as shown by the sample:@\n%a@\n"        Format.fprintf ppf "which is not a subtype, as shown by the sample:@.%a@."
77          print_sample (Sample.get (Types.diff s t))          print_sample (Sample.get (Types.diff s t))
78    | Typer.NonExhaustive t ->    | Typer.NonExhaustive t ->
79        Format.fprintf ppf "This pattern matching is not exhaustive@\n";        Format.fprintf ppf "This pattern matching is not exhaustive@.";
80        Format.fprintf ppf "Residual type:@\n%a@\n"        Format.fprintf ppf "Residual type:@.%a@."
81          print_norm t;          print_norm t;
82        Format.fprintf ppf "Sample:@\n%a@\n" print_sample (Sample.get t)        Format.fprintf ppf "Sample:@.%a@." print_sample (Sample.get t)
83    | Typer.UnboundId x ->    | Typer.UnboundId x ->
84        Format.fprintf ppf "Unbound identifier %a@\n" U.print (Id.value x)        Format.fprintf ppf "Unbound identifier %a@." U.print (Id.value x)
85    | Wlexer.Illegal_character c ->    | Wlexer.Illegal_character c ->
86        Format.fprintf ppf "Illegal character (%s)@\n" (Char.escaped c)        Format.fprintf ppf "Illegal character (%s)@." (Char.escaped c)
87    | Wlexer.Unterminated_comment ->    | Wlexer.Unterminated_comment ->
88        Format.fprintf ppf "Comment not terminated@\n"        Format.fprintf ppf "Comment not terminated@."
89    | Wlexer.Unterminated_string ->    | Wlexer.Unterminated_string ->
90        Format.fprintf ppf "String literal not terminated@\n"        Format.fprintf ppf "String literal not terminated@."
91    | Wlexer.Unterminated_string_in_comment ->    | Wlexer.Unterminated_string_in_comment ->
92        Format.fprintf ppf "This comment contains an unterminated string literal@\n"        Format.fprintf ppf "This comment contains an unterminated string literal@."
93    | Parser.Error s | Stream.Error s ->    | Parser.Error s | Stream.Error s ->
94        Format.fprintf ppf "Parsing error: %s@\n" s        Format.fprintf ppf "Parsing error: %s@." s
95    | Location.Generic s ->    | Location.Generic s ->
96        Format.fprintf ppf "%s@\n" s        Format.fprintf ppf "%s@." s
97    | exn ->    | exn ->
98  (*      raise exn *)  (*      raise exn *)
99        Format.fprintf ppf "%s@\n" (Printexc.to_string exn)        Format.fprintf ppf "%s@." (Printexc.to_string exn)
100    
101  let debug ppf = function  let debug ppf = function
102    | `Subtype (t1,t2) ->    | `Subtype (t1,t2) ->
103        Format.fprintf ppf "[DEBUG:subtype]@\n";        Format.fprintf ppf "[DEBUG:subtype]@.";
104        let t1 = Types.descr (Typer.typ t1)        let t1 = Types.descr (Typer.typ t1)
105        and t2 = Types.descr (Typer.typ t2) in        and t2 = Types.descr (Typer.typ t2) in
106        Format.fprintf ppf "%a <= %a : %b@\n" print_norm t1 print_norm t2        Format.fprintf ppf "%a <= %a : %b@." print_norm t1 print_norm t2
107          (Types.subtype t1 t2)          (Types.subtype t1 t2)
108    | `Sample t ->    | `Sample t ->
109        Format.fprintf ppf "[DEBUG:sample]@\n";        Format.fprintf ppf "[DEBUG:sample]@.";
110          (try
111        let t = Types.descr (Typer.typ t) in        let t = Types.descr (Typer.typ t) in
112        Format.fprintf ppf "%a@\n" print_sample (Sample.get t)           Format.fprintf ppf "%a@." print_sample (Sample.get t)
113           with Not_found ->
114             Format.fprintf ppf "Empty type : no sample !@.")
115    | `Filter (t,p) ->    | `Filter (t,p) ->
116        Format.fprintf ppf "[DEBUG:filter]@\n";        Format.fprintf ppf "[DEBUG:filter]@.";
117        let t = Typer.typ t        let t = Typer.typ t
118        and p = Typer.pat p in        and p = Typer.pat p in
119        let f = Patterns.filter (Types.descr t) p in        let f = Patterns.filter (Types.descr t) p in
120        List.iter (fun (x,t) ->        List.iter (fun (x,t) ->
121                     Format.fprintf ppf " %a:%a@\n" U.print (Id.value x)                     Format.fprintf ppf " %a:%a@." U.print (Id.value x)
122                       print_norm (Types.descr t)) f                       print_norm (Types.descr t)) f
123    | `Accept p ->    | `Accept p ->
124        Format.fprintf ppf "[DEBUG:accept]@\n";        Format.fprintf ppf "[DEBUG:accept]@.";
125        let p = Typer.pat p in        let p = Typer.pat p in
126        let t = Patterns.accept p in        let t = Patterns.accept p in
127        Format.fprintf ppf " %a@\n" Types.Print.print (Types.descr t)        Format.fprintf ppf " %a@." Types.Print.print (Types.descr t)
128    | `Compile (t,pl) ->    | `Compile (t,pl) ->
129        Format.fprintf ppf "[DEBUG:compile]@\n";        Format.fprintf ppf "[DEBUG:compile]@.";
130        let t = Typer.typ t        let t = Typer.typ t
131        and pl = List.map Typer.pat pl in        and pl = List.map Typer.pat pl in
132        Patterns.Compile.debug_compile ppf t pl        Patterns.Compile.debug_compile ppf t pl
133    
134    let insert_bindings ppf =
135      List.iter2
136  let insert_type_bindings ppf =      (fun (x,t) (y,v) ->
137    List.iter         assert (x = y);
     (fun (x,t) ->  
138         typing_env := Env.add x t !typing_env;         typing_env := Env.add x t !typing_env;
        if not !quiet then  
          Format.fprintf ppf "|- %a : %a@."  
            U.print (Id.value x) print_norm t)  
   
 let insert_eval_bindings ppf =  
   List.iter  
     (fun (x,v) ->  
139         eval_env := Env.add x v !eval_env;         eval_env := Env.add x v !eval_env;
140         if not !quiet then         if not !quiet then
141           Format.fprintf ppf "=> %a : @[%a@]@."           Format.fprintf ppf "val %a : @[%a@] = @[%a@]@."
142             U.print (Id.value x) print_value v             U.print (Id.value x) print_norm t print_value v)
     )  
143    
144  let rec collect_funs ppf accu = function  let rec collect_funs ppf accu = function
145    | { descr = Ast.FunDecl e } :: rest ->    | { descr = Ast.FunDecl e } :: rest ->
146        let (_,e) = Typer.expr e in        let (_,e) = Typer.expr e in
147        collect_funs ppf (e::accu) rest        collect_funs ppf (e::accu) rest
148    | rest ->    | rest ->
149        insert_type_bindings ppf (Typer.type_rec_funs !typing_env accu);        let typs = Typer.type_rec_funs !typing_env accu in
150        Typer.report_unused_branches ();        Typer.report_unused_branches ();
151        insert_eval_bindings ppf (Eval.eval_rec_funs !eval_env accu);        let vals = Eval.eval_rec_funs !eval_env accu in
152          insert_bindings ppf typs vals;
153        rest        rest
154    
155  let rec collect_types ppf accu = function  let rec collect_types ppf accu = function
# Line 177  Line 170 
170        Typer.report_unused_branches ();        Typer.report_unused_branches ();
171        if not !quiet then        if not !quiet then
172          Location.dump_loc ppf e.Typed.exp_loc;          Location.dump_loc ppf e.Typed.exp_loc;
       if not !quiet then  
         Format.fprintf ppf "|- %a@." print_norm t;  
173        let v = Eval.eval !eval_env e in        let v = Eval.eval !eval_env e in
174        if not !quiet then        if not !quiet then
175          Format.fprintf ppf "=> @[%a@]@." print_value v;          Format.fprintf ppf "- : @[%a@] = @[%a@]@." print_norm t print_value v;
176        phrases ppf rest        phrases ppf rest
177    | { descr = Ast.LetDecl (p,e) } :: rest ->    | { descr = Ast.LetDecl (p,e) } :: rest ->
178        let decl = Typer.let_decl p e in        let decl = Typer.let_decl p e in
179        insert_type_bindings ppf (Typer.type_let_decl !typing_env decl);        let typs = Typer.type_let_decl !typing_env decl in
180        Typer.report_unused_branches ();        Typer.report_unused_branches ();
181        insert_eval_bindings ppf (Eval.eval_let_decl !eval_env decl);        let vals = Eval.eval_let_decl !eval_env decl in
182          insert_bindings ppf typs vals;
183        phrases ppf rest        phrases ppf rest
184    | { descr = Ast.Debug l } :: rest ->    | { descr = Ast.Debug l } :: rest ->
185        debug ppf l;        debug ppf l;
186        phrases ppf rest        phrases ppf rest
187    | [] -> ()    | [] -> ()
   | _ -> assert false  
188    
189  let run rule ppf ppf_err input =  let run rule ppf ppf_err input =
190    try    try

Legend:
Removed from v.431  
changed lines
  Added in v.433

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