src/Pure/ML-Systems/polyml.ML
author wenzelm
Sat Nov 27 16:29:53 2010 +0100 (2010-11-27 ago)
changeset 40748 591b6778d076
parent 39616 8052101883c3
child 43948 8f5add916a99
permissions -rw-r--r--
removed bash from ML system bootstrap, and past the Secure ML barrier;
     1 (*  Title:      Pure/ML-Systems/polyml.ML
     2 
     3 Compatibility wrapper for Poly/ML 5.3 and 5.4.
     4 *)
     5 
     6 open Thread;
     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 
    15 fun reraise exn =
    16   (case PolyML.exceptionLocation exn of
    17     NONE => raise exn
    18   | SOME location => PolyML.raiseWithLocation (exn, location));
    19 
    20 use "ML-Systems/polyml_common.ML";
    21 use "ML-Systems/multithreading_polyml.ML";
    22 use "ML-Systems/unsynchronized.ML";
    23 
    24 val _ = PolyML.Compiler.forgetValue "ref";
    25 val _ = PolyML.Compiler.forgetType "ref";
    26 
    27 val pointer_eq = PolyML.pointerEq;
    28 
    29 fun share_common_data () = PolyML.shareCommonData PolyML.rootFunction;
    30 
    31 use "ML-Systems/compiler_polyml-5.3.ML";
    32 PolyML.Compiler.reportUnreferencedIds := true;
    33 
    34 
    35 (* toplevel pretty printing *)
    36 
    37 val pretty_ml =
    38   let
    39     fun convert len (PolyML.PrettyBlock (ind, _, context, prts)) =
    40           let
    41             fun property name default =
    42               (case List.find (fn PolyML.ContextProperty (a, _) => name = a | _ => false) context of
    43                 SOME (PolyML.ContextProperty (_, b)) => b
    44               | NONE => default);
    45             val bg = property "begin" "";
    46             val en = property "end" "";
    47             val len' = property "length" len;
    48           in ML_Pretty.Block ((bg, en), map (convert len') prts, ind) end
    49       | convert len (PolyML.PrettyString s) =
    50           ML_Pretty.String (s, case Int.fromString len of SOME i => i | NONE => size s)
    51       | convert _ (PolyML.PrettyBreak (wd, _)) =
    52           ML_Pretty.Break (if wd < 99999 then (false, wd) else (true, 2));
    53   in convert "" end;
    54 
    55 fun ml_pretty (ML_Pretty.Block ((bg, en), prts, ind)) =
    56       let val context =
    57         (if bg = "" then [] else [PolyML.ContextProperty ("begin", bg)]) @
    58         (if en = "" then [] else [PolyML.ContextProperty ("end", en)])
    59       in PolyML.PrettyBlock (ind, false, context, map ml_pretty prts) end
    60   | ml_pretty (ML_Pretty.String (s, len)) =
    61       if len = size s then PolyML.PrettyString s
    62       else PolyML.PrettyBlock
    63         (0, false, [PolyML.ContextProperty ("length", Int.toString len)], [PolyML.PrettyString s])
    64   | ml_pretty (ML_Pretty.Break (false, wd)) = PolyML.PrettyBreak (wd, 0)
    65   | ml_pretty (ML_Pretty.Break (true, _)) = PolyML.PrettyBreak (99999, 0);
    66 
    67 fun toplevel_pp context (_: string list) pp =
    68   use_text context (1, "pp") false
    69     ("PolyML.addPrettyPrinter (fn _ => fn _ => ml_pretty o Pretty.to_ML o (" ^ pp ^ "))");
    70 
    71 val ml_make_string =
    72   "(fn x => Pretty.string_of (Pretty.from_ML (pretty_ml (PolyML.prettyRepresentation (x, get_print_depth ())))))";
    73