| author | krauss | 
| Wed, 05 May 2010 00:59:59 +0200 | |
| changeset 36664 | 6302f9ad7047 | 
| parent 36162 | 0bd034a80a9a | 
| child 38470 | 484e483eb606 | 
| permissions | -rw-r--r-- | 
| 33538 
edf497b5b5d2
setup for official Poly/ML 5.3.0, which is now the default;
 wenzelm parents: 
32778diff
changeset | 1 | (* Title: Pure/ML-Systems/polyml.ML | 
| 29714 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 2 | |
| 33538 
edf497b5b5d2
setup for official Poly/ML 5.3.0, which is now the default;
 wenzelm parents: 
32778diff
changeset | 3 | Compatibility wrapper for Poly/ML 5.3.0. | 
| 29714 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 4 | *) | 
| 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 5 | |
| 32776 
1504f9c2d060
more uniform treatment of structure Unsynchronized in ML bootstrap phase;
 wenzelm parents: 
31433diff
changeset | 6 | use "ML-Systems/unsynchronized.ML"; | 
| 
1504f9c2d060
more uniform treatment of structure Unsynchronized in ML bootstrap phase;
 wenzelm parents: 
31433diff
changeset | 7 | |
| 29714 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 8 | open Thread; | 
| 30673 | 9 | |
| 10 | structure ML_Name_Space = | |
| 11 | struct | |
| 12 | open PolyML.NameSpace; | |
| 13 | type T = PolyML.NameSpace.nameSpace; | |
| 14 | val global = PolyML.globalNameSpace; | |
| 15 | end; | |
| 16 | ||
| 31427 
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
 wenzelm parents: 
31318diff
changeset | 17 | fun reraise exn = | 
| 
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
 wenzelm parents: 
31318diff
changeset | 18 | (case PolyML.exceptionLocation exn of | 
| 
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
 wenzelm parents: 
31318diff
changeset | 19 | NONE => raise exn | 
| 
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
 wenzelm parents: 
31318diff
changeset | 20 | | SOME location => PolyML.raiseWithLocation (exn, location)); | 
| 
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
 wenzelm parents: 
31318diff
changeset | 21 | |
| 29714 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 22 | use "ML-Systems/polyml_common.ML"; | 
| 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 23 | use "ML-Systems/multithreading_polyml.ML"; | 
| 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 24 | |
| 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 25 | val pointer_eq = PolyML.pointerEq; | 
| 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 26 | |
| 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 27 | fun share_common_data () = PolyML.shareCommonData PolyML.rootFunction; | 
| 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 28 | |
| 31312 | 29 | use "ML-Systems/compiler_polyml-5.3.ML"; | 
| 32778 | 30 | PolyML.Compiler.reportUnreferencedIds := true; | 
| 30626 | 31 | |
| 32 | ||
| 33 | (* toplevel pretty printing *) | |
| 34 | ||
| 30676 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 35 | val pretty_ml = | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 36 | let | 
| 31318 | 37 | fun convert len (PolyML.PrettyBlock (ind, _, context, prts)) = | 
| 30676 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 38 | let | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 39 | fun property name default = | 
| 31318 | 40 | (case List.find (fn PolyML.ContextProperty (a, _) => name = a | _ => false) context of | 
| 41 | SOME (PolyML.ContextProperty (_, b)) => b | |
| 30676 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 42 | | NONE => default); | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 43 | val bg = property "begin" ""; | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 44 | val en = property "end" ""; | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 45 | val len' = property "length" len; | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 46 | in ML_Pretty.Block ((bg, en), map (convert len') prts, ind) end | 
| 31318 | 47 | | convert len (PolyML.PrettyString s) = | 
| 30676 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 48 | ML_Pretty.String (s, case Int.fromString len of SOME i => i | NONE => size s) | 
| 31318 | 49 | | convert _ (PolyML.PrettyBreak (wd, _)) = | 
| 30676 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 50 | 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: 
30673diff
changeset | 51 | in convert "" end; | 
| 30638 | 52 | |
| 30676 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 53 | fun ml_pretty (ML_Pretty.Block ((bg, en), prts, ind)) = | 
| 30679 | 54 | let val context = | 
| 31318 | 55 |         (if bg = "" then [] else [PolyML.ContextProperty ("begin", bg)]) @
 | 
| 56 |         (if en = "" then [] else [PolyML.ContextProperty ("end", en)])
 | |
| 57 | 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: 
30673diff
changeset | 58 | | ml_pretty (ML_Pretty.String (s, len)) = | 
| 31318 | 59 | if len = size s then PolyML.PrettyString s | 
| 60 | else PolyML.PrettyBlock | |
| 61 |         (0, false, [PolyML.ContextProperty ("length", Int.toString len)], [PolyML.PrettyString s])
 | |
| 62 | | ml_pretty (ML_Pretty.Break (false, wd)) = PolyML.PrettyBreak (wd, 0) | |
| 63 | | ml_pretty (ML_Pretty.Break (true, _)) = PolyML.PrettyBreak (99999, 0); | |
| 30626 | 64 | |
| 30673 | 65 | fun toplevel_pp context (_: string list) pp = | 
| 66 | use_text context (1, "pp") false | |
| 31318 | 67 |     ("PolyML.addPrettyPrinter (fn _ => fn _ => ml_pretty o Pretty.to_ML o (" ^ pp ^ "))");
 | 
| 30626 | 68 | |
| 36162 
0bd034a80a9a
added ML antiquotation @{make_string}, which produces proper pretty printed version in Poly/ML 5.3.0 or later;
 wenzelm parents: 
33543diff
changeset | 69 | 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: 
33543diff
changeset | 70 | "(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: 
33543diff
changeset | 71 |