src/Pure/ML-Systems/polyml-experimental.ML
author haftmann
Tue Oct 20 16:13:01 2009 +0200 (2009-10-20)
changeset 33037 b22e44496dc2
parent 32778 a92a18253f1e
permissions -rw-r--r--
replaced old_style infixes eq_set, subset, union, inter and variants by generic versions
     1 (*  Title:      Pure/ML-Systems/polyml-experimental.ML
     2 
     3 Compatibility wrapper for Poly/ML 5.3.
     4 *)
     5 
     6 use "ML-Systems/unsynchronized.ML";
     7 
     8 open Thread;
     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 
    17 fun reraise exn =
    18   (case PolyML.exceptionLocation exn of
    19     NONE => raise exn
    20   | SOME location => PolyML.raiseWithLocation (exn, location));
    21 
    22 use "ML-Systems/polyml_common.ML";
    23 use "ML-Systems/multithreading_polyml.ML";
    24 
    25 val pointer_eq = PolyML.pointerEq;
    26 
    27 fun share_common_data () = PolyML.shareCommonData PolyML.rootFunction;
    28 
    29 use "ML-Systems/compiler_polyml-5.3.ML";
    30 PolyML.Compiler.reportUnreferencedIds := true;
    31 
    32 
    33 (* toplevel pretty printing *)
    34 
    35 val pretty_ml =
    36   let
    37     fun convert len (PolyML.PrettyBlock (ind, _, context, prts)) =
    38           let
    39             fun property name default =
    40               (case List.find (fn PolyML.ContextProperty (a, _) => name = a | _ => false) context of
    41                 SOME (PolyML.ContextProperty (_, b)) => b
    42               | NONE => default);
    43             val bg = property "begin" "";
    44             val en = property "end" "";
    45             val len' = property "length" len;
    46           in ML_Pretty.Block ((bg, en), map (convert len') prts, ind) end
    47       | convert len (PolyML.PrettyString s) =
    48           ML_Pretty.String (s, case Int.fromString len of SOME i => i | NONE => size s)
    49       | convert _ (PolyML.PrettyBreak (wd, _)) =
    50           ML_Pretty.Break (if wd < 99999 then (false, wd) else (true, 2));
    51   in convert "" end;
    52 
    53 fun ml_pretty (ML_Pretty.Block ((bg, en), prts, ind)) =
    54       let val context =
    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
    58   | ml_pretty (ML_Pretty.String (s, len)) =
    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);
    64 
    65 fun toplevel_pp context (_: string list) pp =
    66   use_text context (1, "pp") false
    67     ("PolyML.addPrettyPrinter (fn _ => fn _ => ml_pretty o Pretty.to_ML o (" ^ pp ^ "))");
    68