| author | wenzelm | 
| Wed, 17 Feb 2016 23:29:35 +0100 | |
| changeset 62357 | ab76bd43c14a | 
| parent 60956 | 10d463883dc2 | 
| parent 62355 | 00f7618a9f2b | 
| child 62387 | ad3eb2889f9a | 
| permissions | -rw-r--r-- | 
| 62355 | 1  | 
(* Title: Pure/ML/ml_compiler.ML  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
2  | 
Author: Makarius  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
3  | 
|
| 62355 | 4  | 
Runtime compilation and evaluation.  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
5  | 
*)  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
6  | 
|
| 62354 | 7  | 
signature ML_COMPILER =  | 
8  | 
sig  | 
|
9  | 
type flags =  | 
|
10  | 
    {SML: bool, exchange: bool, redirect: bool, verbose: bool,
 | 
|
11  | 
debug: bool option, writeln: string -> unit, warning: string -> unit}  | 
|
12  | 
val flags: flags  | 
|
13  | 
val verbose: bool -> flags -> flags  | 
|
14  | 
val eval: flags -> Position.T -> ML_Lex.token list -> unit  | 
|
15  | 
end  | 
|
16  | 
||
17  | 
||
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
18  | 
structure ML_Compiler: ML_COMPILER =  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
19  | 
struct  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
20  | 
|
| 62354 | 21  | 
(* flags *)  | 
22  | 
||
23  | 
type flags =  | 
|
24  | 
  {SML: bool, exchange: bool, redirect: bool, verbose: bool,
 | 
|
25  | 
debug: bool option, writeln: string -> unit, warning: string -> unit};  | 
|
26  | 
||
27  | 
val flags: flags =  | 
|
28  | 
  {SML = false, exchange = false, redirect = false, verbose = false,
 | 
|
29  | 
debug = NONE, writeln = writeln, warning = warning};  | 
|
30  | 
||
31  | 
fun verbose b (flags: flags) =  | 
|
32  | 
  {SML = #SML flags, exchange = #exchange flags, redirect = #redirect flags,
 | 
|
33  | 
verbose = b, debug = #debug flags, writeln = #writeln flags, warning = #warning flags};  | 
|
| 56281 | 34  | 
|
35  | 
||
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
36  | 
(* parse trees *)  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
37  | 
|
| 60913 | 38  | 
fun breakpoint_position loc =  | 
39  | 
let val pos = Position.reset_range (Exn_Properties.position_of loc) in  | 
|
40  | 
(case Position.offset_of pos of  | 
|
41  | 
NONE => pos  | 
|
42  | 
| SOME 1 => pos  | 
|
43  | 
| SOME j =>  | 
|
44  | 
Position.properties_of pos  | 
|
45  | 
|> Properties.put (Markup.offsetN, Markup.print_int (j - 1))  | 
|
46  | 
|> Position.of_properties)  | 
|
47  | 
end;  | 
|
48  | 
||
| 
56304
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
49  | 
fun report_parse_tree redirect depth space parse_tree =  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
50  | 
let  | 
| 
56304
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
51  | 
val is_visible =  | 
| 
38720
 
7f8bc335e203
ML_Context.eval: produce antiquotation environment preferably in invisible context, to avoid displaced report messages from ML_Compiler;
 
wenzelm 
parents: 
38228 
diff
changeset
 | 
52  | 
(case Context.thread_data () of  | 
| 
56304
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
53  | 
SOME context => Context_Position.is_visible_generic context  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
54  | 
| NONE => true);  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
55  | 
fun is_reported pos = is_visible andalso Position.is_reported pos;  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
56  | 
|
| 60744 | 57  | 
|
58  | 
(* syntax reports *)  | 
|
59  | 
||
| 
56304
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
60  | 
fun reported_types loc types =  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
61  | 
let val pos = Exn_Properties.position_of loc in  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
62  | 
is_reported pos ?  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
63  | 
let  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
64  | 
val xml =  | 
| 
61715
 
5dc95d957569
speculative support for polyml-5.6, according to git commit 3527f4ba7b8b;
 
wenzelm 
parents: 
60956 
diff
changeset
 | 
65  | 
ML_Name_Space.displayTypeExpression (types, depth, space)  | 
| 
56304
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
66  | 
|> pretty_ml |> Pretty.from_ML |> Pretty.string_of  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
67  | 
|> Output.output |> YXML.parse_body;  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
68  | 
in cons (pos, fn () => Markup.ML_typing, fn () => YXML.string_of_body xml) end  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
69  | 
end;  | 
| 
38720
 
7f8bc335e203
ML_Context.eval: produce antiquotation environment preferably in invisible context, to avoid displaced report messages from ML_Compiler;
 
wenzelm 
parents: 
38228 
diff
changeset
 | 
70  | 
|
| 44737 | 71  | 
fun reported_entity kind loc decl =  | 
| 
58991
 
92b6f4e68c5a
more careful ML source positions, for improved PIDE markup;
 
wenzelm 
parents: 
56618 
diff
changeset
 | 
72  | 
let  | 
| 
 
92b6f4e68c5a
more careful ML source positions, for improved PIDE markup;
 
wenzelm 
parents: 
56618 
diff
changeset
 | 
73  | 
val pos = Exn_Properties.position_of loc;  | 
| 
 
92b6f4e68c5a
more careful ML source positions, for improved PIDE markup;
 
wenzelm 
parents: 
56618 
diff
changeset
 | 
74  | 
val def_pos = Exn_Properties.position_of decl;  | 
| 
 
92b6f4e68c5a
more careful ML source positions, for improved PIDE markup;
 
wenzelm 
parents: 
56618 
diff
changeset
 | 
75  | 
in  | 
| 
 
92b6f4e68c5a
more careful ML source positions, for improved PIDE markup;
 
wenzelm 
parents: 
56618 
diff
changeset
 | 
76  | 
(is_reported pos andalso pos <> def_pos) ?  | 
| 
56304
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
77  | 
let  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
78  | 
fun markup () =  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
79  | 
(Markup.entityN, (Markup.kindN, kind) :: Position.def_properties_of def_pos);  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
80  | 
in cons (pos, markup, fn () => "") end  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
81  | 
end;  | 
| 
41503
 
a7462e442e35
refined report_parse_tree: reverse reports happen to produce proper type information for inlined @{term}, @{typ} etc.;
 
wenzelm 
parents: 
41501 
diff
changeset
 | 
82  | 
|
| 
60731
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
83  | 
fun reported_completions loc names =  | 
| 
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
84  | 
let val pos = Exn_Properties.position_of loc in  | 
| 60732 | 85  | 
if is_reported pos andalso not (null names) then  | 
| 
60731
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
86  | 
let  | 
| 60732 | 87  | 
            val completion = Completion.names pos (map (fn a => (a, ("ML", a))) names);
 | 
| 
60731
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
88  | 
val xml = Completion.encode completion;  | 
| 
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
89  | 
in cons (pos, fn () => Markup.completion, fn () => YXML.string_of_body xml) end  | 
| 
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
90  | 
else I  | 
| 
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
91  | 
end;  | 
| 
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
92  | 
|
| 60744 | 93  | 
fun reported _ (PolyML.PTnextSibling tree) = reported_tree (tree ())  | 
94  | 
| reported _ (PolyML.PTfirstChild tree) = reported_tree (tree ())  | 
|
95  | 
| reported loc (PolyML.PTtype types) = reported_types loc types  | 
|
| 
56304
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
96  | 
| reported loc (PolyML.PTdeclaredAt decl) = reported_entity Markup.ML_defN loc decl  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
97  | 
| reported loc (PolyML.PTopenedAt decl) = reported_entity Markup.ML_openN loc decl  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
98  | 
| reported loc (PolyML.PTstructureAt decl) = reported_entity Markup.ML_structureN loc decl  | 
| 
60731
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
99  | 
| reported loc pt =  | 
| 
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
100  | 
(case ML_Parse_Tree.completions pt of  | 
| 
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
101  | 
SOME names => reported_completions loc names  | 
| 
 
4ac4b314d93c
additional ML parse tree components for Poly/ML 5.5.3, or later;
 
wenzelm 
parents: 
60730 
diff
changeset
 | 
102  | 
| NONE => I)  | 
| 44737 | 103  | 
and reported_tree (loc, props) = fold (reported loc) props;  | 
| 
56304
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
104  | 
|
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
105  | 
val persistent_reports = reported_tree parse_tree [];  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
106  | 
|
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
107  | 
fun output () =  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
108  | 
persistent_reports  | 
| 
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
109  | 
|> map (fn (pos, markup, text) => Position.reported_text pos (markup ()) (text ()))  | 
| 
56333
 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 
wenzelm 
parents: 
56305 
diff
changeset
 | 
110  | 
|> Output.report;  | 
| 60744 | 111  | 
val _ =  | 
112  | 
if not (null persistent_reports) andalso redirect andalso Multithreading.enabled ()  | 
|
113  | 
then  | 
|
114  | 
Execution.print  | 
|
115  | 
          {name = "ML_Compiler.report", pos = Position.thread_data (), pri = Task_Queue.urgent_pri}
 | 
|
116  | 
output  | 
|
117  | 
else output ();  | 
|
118  | 
||
119  | 
||
120  | 
(* breakpoints *)  | 
|
121  | 
||
122  | 
fun breakpoints _ (PolyML.PTnextSibling tree) = breakpoints_tree (tree ())  | 
|
123  | 
| breakpoints _ (PolyML.PTfirstChild tree) = breakpoints_tree (tree ())  | 
|
124  | 
| breakpoints loc pt =  | 
|
125  | 
(case ML_Parse_Tree.breakpoint pt of  | 
|
126  | 
SOME b =>  | 
|
| 60913 | 127  | 
let val pos = breakpoint_position loc in  | 
| 60744 | 128  | 
if is_reported pos then  | 
129  | 
let val id = serial ();  | 
|
| 60746 | 130  | 
in cons ((pos, Markup.ML_breakpoint id), (id, (b, pos))) end  | 
| 60744 | 131  | 
else I  | 
132  | 
end  | 
|
133  | 
| NONE => I)  | 
|
134  | 
and breakpoints_tree (loc, props) = fold (breakpoints loc) props;  | 
|
135  | 
||
136  | 
val all_breakpoints = rev (breakpoints_tree parse_tree []);  | 
|
137  | 
val _ = Position.reports (map #1 all_breakpoints);  | 
|
| 60746 | 138  | 
val _ =  | 
139  | 
if is_some (Context.thread_data ()) then  | 
|
140  | 
Context.>> (fold (ML_Env.add_breakpoint o #2) all_breakpoints)  | 
|
141  | 
else ();  | 
|
142  | 
in () end;  | 
|
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
143  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
144  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
145  | 
(* eval ML source tokens *)  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
146  | 
|
| 
56304
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
147  | 
fun eval (flags: flags) pos toks =  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
148  | 
let  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
149  | 
val _ = Secure.secure_mltext ();  | 
| 60746 | 150  | 
    val space = ML_Env.name_space {SML = #SML flags, exchange = #exchange flags};
 | 
| 
56265
 
785569927666
discontinued Toplevel.debug in favour of system option "exception_trace";
 
wenzelm 
parents: 
55837 
diff
changeset
 | 
151  | 
val opt_context = Context.thread_data ();  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
152  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
153  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
154  | 
(* input *)  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
155  | 
|
| 
50911
 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 
wenzelm 
parents: 
50910 
diff
changeset
 | 
156  | 
    val location_props = op ^ (YXML.output_markup (":", #props (Position.dest pos)));
 | 
| 31437 | 157  | 
|
| 
59110
 
8a78c7cb5b14
some special cases for official SML, to treat Isabelle symbols like raw characters;
 
wenzelm 
parents: 
58991 
diff
changeset
 | 
158  | 
val input_explode =  | 
| 
 
8a78c7cb5b14
some special cases for official SML, to treat Isabelle symbols like raw characters;
 
wenzelm 
parents: 
58991 
diff
changeset
 | 
159  | 
if #SML flags then String.explode  | 
| 
 
8a78c7cb5b14
some special cases for official SML, to treat Isabelle symbols like raw characters;
 
wenzelm 
parents: 
58991 
diff
changeset
 | 
160  | 
else maps (String.explode o Symbol.esc) o Symbol.explode;  | 
| 
 
8a78c7cb5b14
some special cases for official SML, to treat Isabelle symbols like raw characters;
 
wenzelm 
parents: 
58991 
diff
changeset
 | 
161  | 
|
| 
41501
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
162  | 
val input_buffer =  | 
| 
59110
 
8a78c7cb5b14
some special cases for official SML, to treat Isabelle symbols like raw characters;
 
wenzelm 
parents: 
58991 
diff
changeset
 | 
163  | 
Unsynchronized.ref (toks |> map (`(input_explode o ML_Lex.check_content_of)));  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
164  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
165  | 
fun get () =  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
166  | 
(case ! input_buffer of  | 
| 
41501
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
167  | 
(c :: cs, tok) :: rest => (input_buffer := (cs, tok) :: rest; SOME c)  | 
| 
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
168  | 
| ([], _) :: rest => (input_buffer := rest; SOME #" ")  | 
| 
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
169  | 
| [] => NONE);  | 
| 
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
170  | 
|
| 
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
171  | 
fun get_pos () =  | 
| 
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
172  | 
(case ! input_buffer of  | 
| 
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
173  | 
(_ :: _, tok) :: _ => ML_Lex.pos_of tok  | 
| 
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
174  | 
| ([], tok) :: _ => ML_Lex.end_pos_of tok  | 
| 
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
175  | 
| [] => Position.none);  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
176  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
177  | 
|
| 60744 | 178  | 
(* output *)  | 
| 
39228
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
179  | 
|
| 
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
180  | 
val writeln_buffer = Unsynchronized.ref Buffer.empty;  | 
| 
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
181  | 
fun write s = Unsynchronized.change writeln_buffer (Buffer.add s);  | 
| 60858 | 182  | 
fun output_writeln () = #writeln flags (trim_line (Buffer.content (! writeln_buffer)));  | 
| 
39228
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
183  | 
|
| 
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
184  | 
val warnings = Unsynchronized.ref ([]: string list);  | 
| 
39231
 
25c345302a17
avoid mixing of static and runtime errors in compiler output, to accomodate Proof General;
 
wenzelm 
parents: 
39230 
diff
changeset
 | 
185  | 
fun warn msg = Unsynchronized.change warnings (cons msg);  | 
| 60858 | 186  | 
fun output_warnings () = List.app (#warning flags) (rev (! warnings));  | 
| 
39228
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
187  | 
|
| 
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
188  | 
val error_buffer = Unsynchronized.ref Buffer.empty;  | 
| 
39231
 
25c345302a17
avoid mixing of static and runtime errors in compiler output, to accomodate Proof General;
 
wenzelm 
parents: 
39230 
diff
changeset
 | 
189  | 
fun err msg = Unsynchronized.change error_buffer (Buffer.add msg #> Buffer.add "\n");  | 
| 60872 | 190  | 
fun flush_error () = #writeln flags (trim_line (Buffer.content (! error_buffer)));  | 
191  | 
fun raise_error msg = error (trim_line (Buffer.content (Buffer.add msg (! error_buffer))));  | 
|
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
192  | 
|
| 
39228
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
193  | 
    fun message {message = msg, hard, location = loc, context = _} =
 | 
| 
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
194  | 
let  | 
| 
56303
 
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
 
wenzelm 
parents: 
56281 
diff
changeset
 | 
195  | 
val pos = Exn_Properties.position_of loc;  | 
| 
39228
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
196  | 
val txt =  | 
| 
49828
 
5631ee099293
more basic ML compiler messages -- avoid conflict of 638cefe3ee99 and cb7264721c91 concerning Protocol.message_positions;
 
wenzelm 
parents: 
48992 
diff
changeset
 | 
197  | 
(if hard then "ML error" else "ML warning") ^ Position.here pos ^ ":\n" ^  | 
| 
 
5631ee099293
more basic ML compiler messages -- avoid conflict of 638cefe3ee99 and cb7264721c91 concerning Protocol.message_positions;
 
wenzelm 
parents: 
48992 
diff
changeset
 | 
198  | 
Pretty.string_of (Pretty.from_ML (pretty_ml msg));  | 
| 
39231
 
25c345302a17
avoid mixing of static and runtime errors in compiler output, to accomodate Proof General;
 
wenzelm 
parents: 
39230 
diff
changeset
 | 
199  | 
in if hard then err txt else warn txt end;  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
200  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
201  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
202  | 
(* results *)  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
203  | 
|
| 
56303
 
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
 
wenzelm 
parents: 
56281 
diff
changeset
 | 
204  | 
val depth = ML_Options.get_print_depth ();  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
205  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
206  | 
    fun apply_result {fixes, types, signatures, structures, functors, values} =
 | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
207  | 
let  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
208  | 
fun display disp x =  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
209  | 
if depth > 0 then  | 
| 
39228
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
210  | 
(disp x |> pretty_ml |> Pretty.from_ML |> Pretty.string_of |> write; write "\n")  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
211  | 
else ();  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
212  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
213  | 
fun apply_fix (a, b) =  | 
| 
61715
 
5dc95d957569
speculative support for polyml-5.6, according to git commit 3527f4ba7b8b;
 
wenzelm 
parents: 
60956 
diff
changeset
 | 
214  | 
(#enterFix space (a, b); display ML_Name_Space.displayFix (a, b));  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
215  | 
fun apply_type (a, b) =  | 
| 
61715
 
5dc95d957569
speculative support for polyml-5.6, according to git commit 3527f4ba7b8b;
 
wenzelm 
parents: 
60956 
diff
changeset
 | 
216  | 
(#enterType space (a, b); display ML_Name_Space.displayType (b, depth, space));  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
217  | 
fun apply_sig (a, b) =  | 
| 
61715
 
5dc95d957569
speculative support for polyml-5.6, according to git commit 3527f4ba7b8b;
 
wenzelm 
parents: 
60956 
diff
changeset
 | 
218  | 
(#enterSig space (a, b); display ML_Name_Space.displaySig (b, depth, space));  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
219  | 
fun apply_struct (a, b) =  | 
| 
61715
 
5dc95d957569
speculative support for polyml-5.6, according to git commit 3527f4ba7b8b;
 
wenzelm 
parents: 
60956 
diff
changeset
 | 
220  | 
(#enterStruct space (a, b); display ML_Name_Space.displayStruct (b, depth, space));  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
221  | 
fun apply_funct (a, b) =  | 
| 
61715
 
5dc95d957569
speculative support for polyml-5.6, according to git commit 3527f4ba7b8b;
 
wenzelm 
parents: 
60956 
diff
changeset
 | 
222  | 
(#enterFunct space (a, b); display ML_Name_Space.displayFunct (b, depth, space));  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
223  | 
fun apply_val (a, b) =  | 
| 
61715
 
5dc95d957569
speculative support for polyml-5.6, according to git commit 3527f4ba7b8b;
 
wenzelm 
parents: 
60956 
diff
changeset
 | 
224  | 
(#enterVal space (a, b); display ML_Name_Space.displayVal (b, depth, space));  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
225  | 
in  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
226  | 
List.app apply_fix fixes;  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
227  | 
List.app apply_type types;  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
228  | 
List.app apply_sig signatures;  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
229  | 
List.app apply_struct structures;  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
230  | 
List.app apply_funct functors;  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
231  | 
List.app apply_val values  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
232  | 
end;  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
233  | 
|
| 
39231
 
25c345302a17
avoid mixing of static and runtime errors in compiler output, to accomodate Proof General;
 
wenzelm 
parents: 
39230 
diff
changeset
 | 
234  | 
exception STATIC_ERRORS of unit;  | 
| 
39230
 
184507f6e8d0
ML_Compiler.eval: discontinued extra "Static Errors" of raw Poly/ML;
 
wenzelm 
parents: 
39228 
diff
changeset
 | 
235  | 
|
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
236  | 
fun result_fun (phase1, phase2) () =  | 
| 31477 | 237  | 
((case phase1 of  | 
238  | 
NONE => ()  | 
|
| 60746 | 239  | 
| SOME parse_tree => report_parse_tree (#redirect flags) depth space parse_tree);  | 
| 31477 | 240  | 
(case phase2 of  | 
| 
39231
 
25c345302a17
avoid mixing of static and runtime errors in compiler output, to accomodate Proof General;
 
wenzelm 
parents: 
39230 
diff
changeset
 | 
241  | 
NONE => raise STATIC_ERRORS ()  | 
| 31477 | 242  | 
| SOME code =>  | 
| 
33603
 
3713a5208671
generalized Runtime.toplevel_error wrt. output function;
 
wenzelm 
parents: 
33538 
diff
changeset
 | 
243  | 
apply_result  | 
| 
 
3713a5208671
generalized Runtime.toplevel_error wrt. output function;
 
wenzelm 
parents: 
33538 
diff
changeset
 | 
244  | 
((code  | 
| 
56303
 
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
 
wenzelm 
parents: 
56281 
diff
changeset
 | 
245  | 
|> Runtime.debugging opt_context  | 
| 
 
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
 
wenzelm 
parents: 
56281 
diff
changeset
 | 
246  | 
|> Runtime.toplevel_error (err o Runtime.exn_message)) ())));  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
247  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
248  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
249  | 
(* compiler invocation *)  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
250  | 
|
| 60956 | 251  | 
val debug =  | 
252  | 
(case #debug flags of  | 
|
253  | 
SOME debug => debug  | 
|
254  | 
| NONE => ML_Options.debugger_enabled opt_context);  | 
|
255  | 
||
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
256  | 
val parameters =  | 
| 
39228
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
257  | 
[PolyML.Compiler.CPOutStream write,  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
258  | 
PolyML.Compiler.CPNameSpace space,  | 
| 
39228
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
259  | 
PolyML.Compiler.CPErrorMessageProc message,  | 
| 
41501
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
260  | 
PolyML.Compiler.CPLineNo (the_default 0 o Position.line_of o get_pos),  | 
| 
 
b5ad6b0d6d7c
ML compiler: more careful treatment of input tokens -- trailing space ensures proper separation and end position (cf. 82c1e348bc18, 08240feb69c7);
 
wenzelm 
parents: 
41484 
diff
changeset
 | 
261  | 
PolyML.Compiler.CPLineOffset (the_default 0 o Position.offset_of o get_pos),  | 
| 31437 | 262  | 
PolyML.Compiler.CPFileName location_props,  | 
| 
56303
 
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
 
wenzelm 
parents: 
56281 
diff
changeset
 | 
263  | 
PolyML.Compiler.CPPrintDepth ML_Options.get_print_depth,  | 
| 31475 | 264  | 
PolyML.Compiler.CPCompilerResultFun result_fun,  | 
| 60730 | 265  | 
PolyML.Compiler.CPPrintInAlphabeticalOrder false] @  | 
| 60956 | 266  | 
ML_Compiler_Parameters.debug debug;  | 
267  | 
||
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
268  | 
val _ =  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
269  | 
(while not (List.null (! input_buffer)) do  | 
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
270  | 
PolyML.compiler (get, parameters) ())  | 
| 
39232
 
69c6d3e87660
more abstract treatment of interrupts in structure Exn -- hardly ever need to mention Interrupt literally;
 
wenzelm 
parents: 
39231 
diff
changeset
 | 
271  | 
handle exn =>  | 
| 
 
69c6d3e87660
more abstract treatment of interrupts in structure Exn -- hardly ever need to mention Interrupt literally;
 
wenzelm 
parents: 
39231 
diff
changeset
 | 
272  | 
if Exn.is_interrupt exn then reraise exn  | 
| 
 
69c6d3e87660
more abstract treatment of interrupts in structure Exn -- hardly ever need to mention Interrupt literally;
 
wenzelm 
parents: 
39231 
diff
changeset
 | 
273  | 
else  | 
| 
 
69c6d3e87660
more abstract treatment of interrupts in structure Exn -- hardly ever need to mention Interrupt literally;
 
wenzelm 
parents: 
39231 
diff
changeset
 | 
274  | 
let  | 
| 
 
69c6d3e87660
more abstract treatment of interrupts in structure Exn -- hardly ever need to mention Interrupt literally;
 
wenzelm 
parents: 
39231 
diff
changeset
 | 
275  | 
val exn_msg =  | 
| 
 
69c6d3e87660
more abstract treatment of interrupts in structure Exn -- hardly ever need to mention Interrupt literally;
 
wenzelm 
parents: 
39231 
diff
changeset
 | 
276  | 
(case exn of  | 
| 
 
69c6d3e87660
more abstract treatment of interrupts in structure Exn -- hardly ever need to mention Interrupt literally;
 
wenzelm 
parents: 
39231 
diff
changeset
 | 
277  | 
STATIC_ERRORS () => ""  | 
| 
 
69c6d3e87660
more abstract treatment of interrupts in structure Exn -- hardly ever need to mention Interrupt literally;
 
wenzelm 
parents: 
39231 
diff
changeset
 | 
278  | 
| Runtime.TOPLEVEL_ERROR => ""  | 
| 
56303
 
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
 
wenzelm 
parents: 
56281 
diff
changeset
 | 
279  | 
| _ => "Exception- " ^ Pretty.string_of (Exn_Output.pretty exn) ^ " raised");  | 
| 
39232
 
69c6d3e87660
more abstract treatment of interrupts in structure Exn -- hardly ever need to mention Interrupt literally;
 
wenzelm 
parents: 
39231 
diff
changeset
 | 
280  | 
val _ = output_warnings ();  | 
| 
 
69c6d3e87660
more abstract treatment of interrupts in structure Exn -- hardly ever need to mention Interrupt literally;
 
wenzelm 
parents: 
39231 
diff
changeset
 | 
281  | 
val _ = output_writeln ();  | 
| 
 
69c6d3e87660
more abstract treatment of interrupts in structure Exn -- hardly ever need to mention Interrupt literally;
 
wenzelm 
parents: 
39231 
diff
changeset
 | 
282  | 
in raise_error exn_msg end;  | 
| 
39228
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
283  | 
in  | 
| 
56304
 
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
284  | 
if #verbose flags then (output_warnings (); flush_error (); output_writeln ())  | 
| 
39228
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
285  | 
else ()  | 
| 
 
cb7264721c91
ML_Compiler.eval: more careful printing of messages and regular output, trying to accomodate Poly/ML, Proof General, Isabelle/Scala/jEdit at the same time;
 
wenzelm 
parents: 
39227 
diff
changeset
 | 
286  | 
end;  | 
| 
31333
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
287  | 
|
| 
 
fcd010617e6c
added structure ML_Compiler: runtime compilation, with advanced version for Poly/ML 5.3 (formerly ML_Test);
 
wenzelm 
parents:  
diff
changeset
 | 
288  | 
end;  |