5 *) |
5 *) |
6 |
6 |
7 signature ML_COMPILER = |
7 signature ML_COMPILER = |
8 sig |
8 sig |
9 type flags = |
9 type flags = |
10 {environment: string, redirect: bool, verbose: bool, |
10 {environment: string, redirect: bool, verbose: bool, catch_all: bool, |
11 debug: bool option, writeln: string -> unit, warning: string -> unit} |
11 debug: bool option, writeln: string -> unit, warning: string -> unit} |
12 val debug_flags: bool option -> flags |
12 val debug_flags: bool option -> flags |
13 val flags: flags |
13 val flags: flags |
14 val verbose: bool -> flags -> flags |
14 val verbose: bool -> flags -> flags |
|
15 val ML_catch_all: bool Config.T |
15 val eval: flags -> Position.T -> ML_Lex.token list -> unit |
16 val eval: flags -> Position.T -> ML_Lex.token list -> unit |
16 end; |
17 end; |
17 |
18 |
18 structure ML_Compiler: ML_COMPILER = |
19 structure ML_Compiler: ML_COMPILER = |
19 struct |
20 struct |
20 |
21 |
21 (* flags *) |
22 (* flags *) |
22 |
23 |
23 type flags = |
24 type flags = |
24 {environment: string, redirect: bool, verbose: bool, |
25 {environment: string, redirect: bool, verbose: bool, catch_all: bool, |
25 debug: bool option, writeln: string -> unit, warning: string -> unit}; |
26 debug: bool option, writeln: string -> unit, warning: string -> unit}; |
26 |
27 |
27 fun debug_flags opt_debug : flags = |
28 fun debug_flags opt_debug : flags = |
28 {environment = "", redirect = false, verbose = false, |
29 {environment = "", redirect = false, verbose = false, catch_all = false, |
29 debug = opt_debug, writeln = writeln, warning = warning}; |
30 debug = opt_debug, writeln = writeln, warning = warning}; |
30 |
31 |
31 val flags = debug_flags NONE; |
32 val flags = debug_flags NONE; |
32 |
33 |
33 fun verbose b (flags: flags) = |
34 fun verbose b ({environment, redirect, verbose = _, catch_all, debug, writeln, warning}: flags) = |
34 {environment = #environment flags, redirect = #redirect flags, verbose = b, |
35 {environment = environment, redirect = redirect, verbose = b, catch_all = catch_all, |
35 debug = #debug flags, writeln = #writeln flags, warning = #warning flags}; |
36 debug = debug, writeln = writeln, warning = warning}; |
36 |
37 |
37 |
38 |
38 (* parse trees *) |
39 (* parse trees *) |
39 |
40 |
40 fun breakpoint_position loc = |
41 fun breakpoint_position loc = |
145 in map (fn (_, (id, (b, pos))) => (id, (b, Position.dest pos))) all_breakpoints end; |
146 in map (fn (_, (id, (b, pos))) => (id, (b, Position.dest pos))) all_breakpoints end; |
146 |
147 |
147 |
148 |
148 (* eval ML source tokens *) |
149 (* eval ML source tokens *) |
149 |
150 |
|
151 val ML_catch_all = Config.declare_bool ("ML_catch_all", \<^here>) (K false); |
|
152 |
150 fun eval (flags: flags) pos toks = |
153 fun eval (flags: flags) pos toks = |
151 let |
154 let |
152 val opt_context = Context.get_generic_context (); |
155 val opt_context = Context.get_generic_context (); |
153 |
156 |
154 val env as {debug, name_space, add_breakpoints} = |
157 val env as {debug, name_space, add_breakpoints} = |
210 in if is_err then error (trim_line msg) else () end; |
213 in if is_err then error (trim_line msg) else () end; |
211 |
214 |
212 fun message {message = msg, hard, location = loc, context = _} = |
215 fun message {message = msg, hard, location = loc, context = _} = |
213 let |
216 let |
214 val pos = Exn_Properties.position_of_polyml_location loc; |
217 val pos = Exn_Properties.position_of_polyml_location loc; |
215 val txt = |
218 val s = Pretty.string_of (Pretty.from_polyml msg); |
216 (if hard then "ML error" else "ML warning") ^ Position.here pos ^ ":\n" ^ |
219 val catch_all = |
217 Pretty.string_of (Pretty.from_polyml msg); |
220 #catch_all flags orelse |
218 in if hard then err txt else warn txt end; |
221 (case opt_context of |
|
222 NONE => false |
|
223 | SOME context => Config.get_generic context ML_catch_all); |
|
224 val is_err = |
|
225 hard orelse |
|
226 (not catch_all andalso |
|
227 String.isPrefix "Handler catches all exceptions" (XML.content_of (YXML.parse_body s))); |
|
228 val txt = (if is_err then "ML error" else "ML warning") ^ Position.here pos ^ ":\n" ^ s; |
|
229 in if is_err then err txt else warn txt end; |
219 |
230 |
220 |
231 |
221 (* results *) |
232 (* results *) |
222 |
233 |
223 val depth = FixedInt.fromInt (ML_Print_Depth.get_print_depth ()); |
234 val depth = FixedInt.fromInt (ML_Print_Depth.get_print_depth ()); |