| author | wenzelm | 
| Sun, 26 Jul 2009 13:21:12 +0200 | |
| changeset 32201 | 3689b647356d | 
| parent 31433 | 12f5f6af3d2d | 
| child 32776 | 1504f9c2d060 | 
| permissions | -rw-r--r-- | 
| 31312 | 1 | (* Title: Pure/ML-Systems/polyml-experimental.ML | 
| 29714 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 2 | |
| 31433 | 3 | Compatibility wrapper for Poly/ML 5.3. | 
| 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 | |
| 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 6 | open Thread; | 
| 30673 | 7 | |
| 8 | structure ML_Name_Space = | |
| 9 | struct | |
| 10 | open PolyML.NameSpace; | |
| 11 | type T = PolyML.NameSpace.nameSpace; | |
| 12 | val global = PolyML.globalNameSpace; | |
| 13 | end; | |
| 14 | ||
| 31427 
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
 wenzelm parents: 
31318diff
changeset | 15 | fun reraise exn = | 
| 
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
 wenzelm parents: 
31318diff
changeset | 16 | (case PolyML.exceptionLocation exn of | 
| 
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
 wenzelm parents: 
31318diff
changeset | 17 | NONE => raise exn | 
| 
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
 wenzelm parents: 
31318diff
changeset | 18 | | SOME location => PolyML.raiseWithLocation (exn, location)); | 
| 
5a07cc86675d
reraise exceptions to preserve original position (ML system specific);
 wenzelm parents: 
31318diff
changeset | 19 | |
| 29714 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 20 | use "ML-Systems/polyml_common.ML"; | 
| 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 21 | use "ML-Systems/multithreading_polyml.ML"; | 
| 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 22 | |
| 
6cef6700c841
Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
 wenzelm parents: diff
changeset | 23 | val pointer_eq = PolyML.pointerEq; | 
| 
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 | 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 | 26 | |
| 31312 | 27 | use "ML-Systems/compiler_polyml-5.3.ML"; | 
| 30626 | 28 | |
| 29 | ||
| 30 | (* toplevel pretty printing *) | |
| 31 | ||
| 30676 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 32 | val pretty_ml = | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 33 | let | 
| 31318 | 34 | 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 | 35 | let | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 36 | fun property name default = | 
| 31318 | 37 | (case List.find (fn PolyML.ContextProperty (a, _) => name = a | _ => false) context of | 
| 38 | SOME (PolyML.ContextProperty (_, b)) => b | |
| 30676 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 39 | | NONE => default); | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 40 | val bg = property "begin" ""; | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 41 | val en = property "end" ""; | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 42 | val len' = property "length" len; | 
| 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 43 | in ML_Pretty.Block ((bg, en), map (convert len') prts, ind) end | 
| 31318 | 44 | | convert len (PolyML.PrettyString s) = | 
| 30676 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 45 | ML_Pretty.String (s, case Int.fromString len of SOME i => i | NONE => size s) | 
| 31318 | 46 | | convert _ (PolyML.PrettyBreak (wd, _)) = | 
| 30676 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 47 | 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 | 48 | in convert "" end; | 
| 30638 | 49 | |
| 30676 
edca392a2abb
pretty_ml/ml_pretty: proper handling of markup and string length;
 wenzelm parents: 
30673diff
changeset | 50 | fun ml_pretty (ML_Pretty.Block ((bg, en), prts, ind)) = | 
| 30679 | 51 | let val context = | 
| 31318 | 52 |         (if bg = "" then [] else [PolyML.ContextProperty ("begin", bg)]) @
 | 
| 53 |         (if en = "" then [] else [PolyML.ContextProperty ("end", en)])
 | |
| 54 | 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 | 55 | | ml_pretty (ML_Pretty.String (s, len)) = | 
| 31318 | 56 | if len = size s then PolyML.PrettyString s | 
| 57 | else PolyML.PrettyBlock | |
| 58 |         (0, false, [PolyML.ContextProperty ("length", Int.toString len)], [PolyML.PrettyString s])
 | |
| 59 | | ml_pretty (ML_Pretty.Break (false, wd)) = PolyML.PrettyBreak (wd, 0) | |
| 60 | | ml_pretty (ML_Pretty.Break (true, _)) = PolyML.PrettyBreak (99999, 0); | |
| 30626 | 61 | |
| 30673 | 62 | fun toplevel_pp context (_: string list) pp = | 
| 63 | use_text context (1, "pp") false | |
| 31318 | 64 |     ("PolyML.addPrettyPrinter (fn _ => fn _ => ml_pretty o Pretty.to_ML o (" ^ pp ^ "))");
 | 
| 30626 | 65 |