5 *) |
5 *) |
6 |
6 |
7 signature ML_COMPILER = |
7 signature ML_COMPILER = |
8 sig |
8 sig |
9 type flags = |
9 type flags = |
10 {SML: bool, exchange: bool, redirect: bool, verbose: bool, |
10 {read: string option, write: string option, redirect: bool, verbose: 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 eval: flags -> Position.T -> ML_Lex.token list -> unit |
15 val eval: flags -> Position.T -> ML_Lex.token list -> unit |
19 struct |
19 struct |
20 |
20 |
21 (* flags *) |
21 (* flags *) |
22 |
22 |
23 type flags = |
23 type flags = |
24 {SML: bool, exchange: bool, redirect: bool, verbose: bool, |
24 {read: string option, write: string option, redirect: bool, verbose: bool, |
25 debug: bool option, writeln: string -> unit, warning: string -> unit}; |
25 debug: bool option, writeln: string -> unit, warning: string -> unit}; |
26 |
26 |
27 fun debug_flags opt_debug : flags = |
27 fun debug_flags opt_debug : flags = |
28 {SML = false, exchange = false, redirect = false, verbose = false, |
28 {read = NONE, write = NONE, redirect = false, verbose = false, |
29 debug = opt_debug, writeln = writeln, warning = warning}; |
29 debug = opt_debug, writeln = writeln, warning = warning}; |
30 |
30 |
31 val flags = debug_flags NONE; |
31 val flags = debug_flags NONE; |
32 |
32 |
33 fun verbose b (flags: flags) = |
33 fun verbose b (flags: flags) = |
34 {SML = #SML flags, exchange = #exchange flags, redirect = #redirect flags, verbose = b, |
34 {read = #read flags, write = #write flags, redirect = #redirect flags, verbose = b, |
35 debug = #debug flags, writeln = #writeln flags, warning = #warning flags}; |
35 debug = #debug flags, writeln = #writeln flags, warning = #warning flags}; |
36 |
36 |
37 |
37 |
38 (* parse trees *) |
38 (* parse trees *) |
39 |
39 |
152 fun eval (flags: flags) pos toks = |
152 fun eval (flags: flags) pos toks = |
153 let |
153 let |
154 val opt_context = Context.get_generic_context (); |
154 val opt_context = Context.get_generic_context (); |
155 |
155 |
156 val env as {debug, name_space, add_breakpoints} = |
156 val env as {debug, name_space, add_breakpoints} = |
157 (case (ML_Recursive.get (), #SML flags orelse #exchange flags) of |
157 (case (ML_Recursive.get (), is_some (#read flags) orelse is_some (#write flags)) of |
158 (SOME env, false) => env |
158 (SOME env, false) => env |
159 | _ => |
159 | _ => |
160 {debug = |
160 {debug = |
161 (case #debug flags of |
161 (case #debug flags of |
162 SOME debug => debug |
162 SOME debug => debug |
163 | NONE => ML_Options.debugger_enabled opt_context), |
163 | NONE => ML_Options.debugger_enabled opt_context), |
164 name_space = ML_Env.make_name_space {SML = #SML flags, exchange = #exchange flags}, |
164 name_space = ML_Env.make_name_space {read = #read flags, write = #write flags}, |
165 add_breakpoints = ML_Env.add_breakpoints}); |
165 add_breakpoints = ML_Env.add_breakpoints}); |
166 |
166 |
167 |
167 |
168 (* input *) |
168 (* input *) |
169 |
169 |
170 val location_props = op ^ (YXML.output_markup (":", #props (Position.dest pos))); |
170 val location_props = op ^ (YXML.output_markup (":", #props (Position.dest pos))); |
171 |
171 |
172 val input_explode = |
172 val input_explode = |
173 if #SML flags then String.explode |
173 if ML_Env.is_standard (ML_Env.default_env (#read flags)) then String.explode |
174 else maps (String.explode o Symbol.esc) o Symbol.explode; |
174 else maps (String.explode o Symbol.esc) o Symbol.explode; |
175 |
175 |
176 fun token_content tok = |
176 fun token_content tok = |
177 if ML_Lex.is_comment tok then NONE |
177 if ML_Lex.is_comment tok then NONE |
178 else SOME (input_explode (ML_Lex.check_content_of tok), tok); |
178 else SOME (input_explode (ML_Lex.check_content_of tok), tok); |