author | wenzelm |
Sat, 21 Jul 2012 12:42:28 +0200 | |
changeset 48416 | 5787e1c911d0 |
parent 47980 | c81801f881b3 |
child 50909 | b2fb1ab1475d |
permissions | -rw-r--r-- |
33538
edf497b5b5d2
setup for official Poly/ML 5.3.0, which is now the default;
wenzelm
parents:
32778
diff
changeset
|
1 |
(* Title: Pure/ML-Systems/polyml.ML |
47980
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
2 |
Author: Makarius |
29714
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff
changeset
|
3 |
|
47980
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
4 |
Compatibility wrapper for Poly/ML 5.3.0 or later. |
29714
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff
changeset
|
5 |
*) |
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff
changeset
|
6 |
|
47980
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
7 |
(* exceptions *) |
30673 | 8 |
|
31427
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
wenzelm
parents:
31318
diff
changeset
|
9 |
fun reraise exn = |
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
wenzelm
parents:
31318
diff
changeset
|
10 |
(case PolyML.exceptionLocation exn of |
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
wenzelm
parents:
31318
diff
changeset
|
11 |
NONE => raise exn |
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
wenzelm
parents:
31318
diff
changeset
|
12 |
| SOME location => PolyML.raiseWithLocation (exn, location)); |
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
wenzelm
parents:
31318
diff
changeset
|
13 |
|
44249
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
14 |
fun set_exn_serial i exn = |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
15 |
let |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
16 |
val (file, startLine, endLine) = |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
17 |
(case PolyML.exceptionLocation exn of |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
18 |
NONE => ("", 0, 0) |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
19 |
| SOME {file, startLine, endLine, startPosition, ...} => (file, startLine, endLine)); |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
20 |
val location = |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
21 |
{file = file, startLine = startLine, endLine = endLine, |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
22 |
startPosition = ~ i, endPosition = 0}; |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
23 |
in PolyML.raiseWithLocation (exn, location) handle e => e end; |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
24 |
|
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
25 |
fun get_exn_serial exn = |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
26 |
(case Option.map #startPosition (PolyML.exceptionLocation exn) of |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
27 |
NONE => NONE |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
28 |
| SOME i => if i >= 0 then NONE else SOME (~ i)); |
64620f1d6f87
identify parallel exceptions where they emerge first -- to achieve unique results within evaluation graph;
wenzelm
parents:
43948
diff
changeset
|
29 |
|
47980
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
30 |
exception Interrupt = SML90.Interrupt; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
31 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
32 |
use "General/exn.ML"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
33 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
34 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
35 |
(* multithreading *) |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
36 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
37 |
val seconds = Time.fromReal; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
38 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
39 |
if List.exists (fn s => s = "SingleAssignment") (PolyML.Compiler.structureNames ()) |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
40 |
then () |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
41 |
else use "ML-Systems/single_assignment_polyml.ML"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
42 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
43 |
open Thread; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
44 |
use "ML-Systems/multithreading.ML"; |
29714
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff
changeset
|
45 |
use "ML-Systems/multithreading_polyml.ML"; |
47980
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
46 |
|
39616
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
38470
diff
changeset
|
47 |
use "ML-Systems/unsynchronized.ML"; |
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
38470
diff
changeset
|
48 |
val _ = PolyML.Compiler.forgetValue "ref"; |
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
38470
diff
changeset
|
49 |
val _ = PolyML.Compiler.forgetType "ref"; |
29714
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff
changeset
|
50 |
|
47980
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
51 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
52 |
(* pervasive environment *) |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
53 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
54 |
fun op before (a, _: unit) = a; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
55 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
56 |
val _ = PolyML.Compiler.forgetValue "isSome"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
57 |
val _ = PolyML.Compiler.forgetValue "getOpt"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
58 |
val _ = PolyML.Compiler.forgetValue "valOf"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
59 |
val _ = PolyML.Compiler.forgetValue "foldl"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
60 |
val _ = PolyML.Compiler.forgetValue "foldr"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
61 |
val _ = PolyML.Compiler.forgetValue "print"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
62 |
val _ = PolyML.Compiler.forgetValue "explode"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
63 |
val _ = PolyML.Compiler.forgetValue "concat"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
64 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
65 |
val ord = SML90.ord; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
66 |
val chr = SML90.chr; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
67 |
val raw_explode = SML90.explode; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
68 |
val implode = SML90.implode; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
69 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
70 |
fun quit () = exit 0; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
71 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
72 |
|
48416 | 73 |
(* ML system operations *) |
47980
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
74 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
75 |
use "ML-Systems/ml_system.ML"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
76 |
|
48416 | 77 |
structure ML_System = |
78 |
struct |
|
79 |
||
80 |
open ML_System; |
|
81 |
||
82 |
fun share_common_data () = PolyML.shareCommonData PolyML.rootFunction; |
|
83 |
val save_state = PolyML.SaveState.saveState; |
|
84 |
||
85 |
end; |
|
86 |
||
47980
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
87 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
88 |
(* ML runtime system *) |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
89 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
90 |
val exception_trace = PolyML.exception_trace; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
91 |
val timing = PolyML.timing; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
92 |
val profiling = PolyML.profiling; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
93 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
94 |
fun profile 0 f x = f x |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
95 |
| profile n f x = |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
96 |
let |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
97 |
val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler n; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
98 |
val res = Exn.capture f x; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
99 |
val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler 0; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
100 |
in Exn.release res end; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
101 |
|
29714
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff
changeset
|
102 |
val pointer_eq = PolyML.pointerEq; |
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff
changeset
|
103 |
|
47980
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
104 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
105 |
(* ML compiler *) |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
106 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
107 |
structure ML_Name_Space = |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
108 |
struct |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
109 |
open PolyML.NameSpace; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
110 |
type T = PolyML.NameSpace.nameSpace; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
111 |
val global = PolyML.globalNameSpace; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
112 |
end; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
113 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
114 |
use "ML-Systems/use_context.ML"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
115 |
use "ML-Systems/compiler_polyml.ML"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
116 |
|
32778 | 117 |
PolyML.Compiler.reportUnreferencedIds := true; |
47980
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
118 |
PolyML.Compiler.printInAlphabeticalOrder := false; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
119 |
PolyML.Compiler.maxInlineSize := 80; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
120 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
121 |
fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2); |
30626 | 122 |
|
123 |
||
47980
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
124 |
(* ML toplevel pretty printing *) |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
125 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
126 |
use "ML-Systems/ml_pretty.ML"; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
127 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
128 |
local |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
129 |
val depth = Unsynchronized.ref 10; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
130 |
in |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
131 |
fun get_print_depth () = ! depth; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
132 |
fun print_depth n = (depth := n; PolyML.print_depth n); |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
133 |
end; |
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
134 |
|
c81801f881b3
simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents:
44249
diff
changeset
|
135 |
val error_depth = PolyML.error_depth; |
30626 | 136 |
|
30676
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
137 |
val pretty_ml = |
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
138 |
let |
31318 | 139 |
fun convert len (PolyML.PrettyBlock (ind, _, context, prts)) = |
30676
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
140 |
let |
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
141 |
fun property name default = |
31318 | 142 |
(case List.find (fn PolyML.ContextProperty (a, _) => name = a | _ => false) context of |
143 |
SOME (PolyML.ContextProperty (_, b)) => b |
|
30676
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
144 |
| NONE => default); |
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
145 |
val bg = property "begin" ""; |
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
146 |
val en = property "end" ""; |
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
147 |
val len' = property "length" len; |
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
148 |
in ML_Pretty.Block ((bg, en), map (convert len') prts, ind) end |
31318 | 149 |
| convert len (PolyML.PrettyString s) = |
30676
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
150 |
ML_Pretty.String (s, case Int.fromString len of SOME i => i | NONE => size s) |
31318 | 151 |
| convert _ (PolyML.PrettyBreak (wd, _)) = |
30676
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
152 |
ML_Pretty.Break (if wd < 99999 then (false, wd) else (true, 2)); |
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
153 |
in convert "" end; |
30638 | 154 |
|
30676
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
155 |
fun ml_pretty (ML_Pretty.Block ((bg, en), prts, ind)) = |
30679 | 156 |
let val context = |
31318 | 157 |
(if bg = "" then [] else [PolyML.ContextProperty ("begin", bg)]) @ |
158 |
(if en = "" then [] else [PolyML.ContextProperty ("end", en)]) |
|
159 |
in PolyML.PrettyBlock (ind, false, context, map ml_pretty prts) end |
|
30676
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents:
30673
diff
changeset
|
160 |
| ml_pretty (ML_Pretty.String (s, len)) = |
31318 | 161 |
if len = size s then PolyML.PrettyString s |
162 |
else PolyML.PrettyBlock |
|
163 |
(0, false, [PolyML.ContextProperty ("length", Int.toString len)], [PolyML.PrettyString s]) |
|
164 |
| ml_pretty (ML_Pretty.Break (false, wd)) = PolyML.PrettyBreak (wd, 0) |
|
165 |
| ml_pretty (ML_Pretty.Break (true, _)) = PolyML.PrettyBreak (99999, 0); |
|
30626 | 166 |
|
30673 | 167 |
fun toplevel_pp context (_: string list) pp = |
168 |
use_text context (1, "pp") false |
|
31318 | 169 |
("PolyML.addPrettyPrinter (fn _ => fn _ => ml_pretty o Pretty.to_ML o (" ^ pp ^ "))"); |
30626 | 170 |
|
36162
0bd034a80a9a
added ML antiquotation @{make_string}, which produces proper pretty printed version in Poly/ML 5.3.0 or later;
wenzelm
parents:
33543
diff
changeset
|
171 |
val ml_make_string = |
0bd034a80a9a
added ML antiquotation @{make_string}, which produces proper pretty printed version in Poly/ML 5.3.0 or later;
wenzelm
parents:
33543
diff
changeset
|
172 |
"(fn x => Pretty.string_of (Pretty.from_ML (pretty_ml (PolyML.prettyRepresentation (x, get_print_depth ())))))"; |
0bd034a80a9a
added ML antiquotation @{make_string}, which produces proper pretty printed version in Poly/ML 5.3.0 or later;
wenzelm
parents:
33543
diff
changeset
|
173 |