equal
deleted
inserted
replaced
104 val writeln_buffer = Unsynchronized.ref Buffer.empty; |
104 val writeln_buffer = Unsynchronized.ref Buffer.empty; |
105 fun write s = Unsynchronized.change writeln_buffer (Buffer.add s); |
105 fun write s = Unsynchronized.change writeln_buffer (Buffer.add s); |
106 fun output_writeln () = writeln (Buffer.content (! writeln_buffer)); |
106 fun output_writeln () = writeln (Buffer.content (! writeln_buffer)); |
107 |
107 |
108 val warnings = Unsynchronized.ref ([]: string list); |
108 val warnings = Unsynchronized.ref ([]: string list); |
|
109 fun warn msg = Unsynchronized.change warnings (cons msg); |
109 fun output_warnings () = List.app warning (rev (! warnings)); |
110 fun output_warnings () = List.app warning (rev (! warnings)); |
110 |
111 |
111 val error_buffer = Unsynchronized.ref Buffer.empty; |
112 val error_buffer = Unsynchronized.ref Buffer.empty; |
|
113 fun err msg = Unsynchronized.change error_buffer (Buffer.add msg #> Buffer.add "\n"); |
112 fun flush_error () = writeln (Buffer.content (! error_buffer)); |
114 fun flush_error () = writeln (Buffer.content (! error_buffer)); |
113 fun raise_error msg = error (Buffer.content (Buffer.add msg (! error_buffer))); |
115 fun raise_error msg = error (Buffer.content (Buffer.add msg (! error_buffer))); |
114 |
116 |
115 fun message {message = msg, hard, location = loc, context = _} = |
117 fun message {message = msg, hard, location = loc, context = _} = |
116 let |
118 let |
118 val txt = |
120 val txt = |
119 Markup.markup Markup.location |
121 Markup.markup Markup.location |
120 ((if hard then "Error" else "Warning") ^ Position.str_of pos ^ ":\n") ^ |
122 ((if hard then "Error" else "Warning") ^ Position.str_of pos ^ ":\n") ^ |
121 Pretty.string_of (Pretty.from_ML (pretty_ml msg)) ^ |
123 Pretty.string_of (Pretty.from_ML (pretty_ml msg)) ^ |
122 Markup.markup (Position.report_markup pos) ""; |
124 Markup.markup (Position.report_markup pos) ""; |
123 in |
125 in if hard then err txt else warn txt end; |
124 if hard then Unsynchronized.change error_buffer (Buffer.add txt #> Buffer.add "\n") |
|
125 else Unsynchronized.change warnings (cons txt) |
|
126 end; |
|
127 |
126 |
128 |
127 |
129 (* results *) |
128 (* results *) |
130 |
129 |
131 val depth = get_print_depth (); |
130 val depth = get_print_depth (); |
156 List.app apply_struct structures; |
155 List.app apply_struct structures; |
157 List.app apply_funct functors; |
156 List.app apply_funct functors; |
158 List.app apply_val values |
157 List.app apply_val values |
159 end; |
158 end; |
160 |
159 |
161 exception Static_Errors of unit; |
160 exception STATIC_ERRORS of unit; |
162 |
161 |
163 fun result_fun (phase1, phase2) () = |
162 fun result_fun (phase1, phase2) () = |
164 ((case phase1 of |
163 ((case phase1 of |
165 NONE => () |
164 NONE => () |
166 | SOME parse_tree => report_parse_tree depth space parse_tree); |
165 | SOME parse_tree => report_parse_tree depth space parse_tree); |
167 (case phase2 of |
166 (case phase2 of |
168 NONE => raise Static_Errors () |
167 NONE => raise STATIC_ERRORS () |
169 | SOME code => |
168 | SOME code => |
170 apply_result |
169 apply_result |
171 ((code |
170 ((code |
172 |> Runtime.debugging |
171 |> Runtime.debugging |
173 |> Runtime.toplevel_error (Output.error_msg o exn_message)) ()))); |
172 |> Runtime.toplevel_error (err o exn_message)) ()))); |
174 |
173 |
175 |
174 |
176 (* compiler invocation *) |
175 (* compiler invocation *) |
177 |
176 |
178 val parameters = |
177 val parameters = |
185 PolyML.Compiler.CPCompilerResultFun result_fun, |
184 PolyML.Compiler.CPCompilerResultFun result_fun, |
186 PolyML.Compiler.CPPrintInAlphabeticalOrder false]; |
185 PolyML.Compiler.CPPrintInAlphabeticalOrder false]; |
187 val _ = |
186 val _ = |
188 (while not (List.null (! input_buffer)) do |
187 (while not (List.null (! input_buffer)) do |
189 PolyML.compiler (get, parameters) ()) |
188 PolyML.compiler (get, parameters) ()) |
190 handle exn => |
189 handle exn as Exn.Interrupt => reraise exn |
191 (output_warnings (); |
190 | exn => |
192 output_writeln (); |
191 let |
193 (case exn of Static_Errors () => raise_error "" |
192 val exn_msg = |
194 | _ => raise_error ("Exception- " ^ General.exnMessage exn ^ " raised"))); |
193 (case exn of |
|
194 STATIC_ERRORS () => "" |
|
195 | Runtime.TOPLEVEL_ERROR => "" |
|
196 | _ => "Exception- " ^ General.exnMessage exn ^ " raised"); |
|
197 val _ = output_warnings (); |
|
198 val _ = output_writeln (); |
|
199 in raise_error exn_msg end; |
195 in |
200 in |
196 if verbose then (output_warnings (); flush_error (); output_writeln ()) |
201 if verbose then (output_warnings (); flush_error (); output_writeln ()) |
197 else () |
202 else () |
198 end; |
203 end; |
199 |
204 |