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;
wenzelm@33538
     1
(*  Title:      Pure/ML-Systems/polyml.ML
wenzelm@29714
     2
wenzelm@38470
     3
Compatibility wrapper for Poly/ML 5.3 and 5.4.
wenzelm@29714
     4
*)
wenzelm@29714
     5
wenzelm@29714
     6
open Thread;
wenzelm@30673
     7
wenzelm@30673
     8
structure ML_Name_Space =
wenzelm@30673
     9
struct
wenzelm@30673
    10
  open PolyML.NameSpace;
wenzelm@30673
    11
  type T = PolyML.NameSpace.nameSpace;
wenzelm@30673
    12
  val global = PolyML.globalNameSpace;
wenzelm@30673
    13
end;
wenzelm@30673
    14
wenzelm@31427
    15
fun reraise exn =
wenzelm@31427
    16
  (case PolyML.exceptionLocation exn of
wenzelm@31427
    17
    NONE => raise exn
wenzelm@31427
    18
  | SOME location => PolyML.raiseWithLocation (exn, location));
wenzelm@31427
    19
wenzelm@29714
    20
use "ML-Systems/polyml_common.ML";
wenzelm@29714
    21
use "ML-Systems/multithreading_polyml.ML";
wenzelm@39616
    22
use "ML-Systems/unsynchronized.ML";
wenzelm@39616
    23
wenzelm@39616
    24
val _ = PolyML.Compiler.forgetValue "ref";
wenzelm@39616
    25
val _ = PolyML.Compiler.forgetType "ref";
wenzelm@29714
    26
wenzelm@29714
    27
val pointer_eq = PolyML.pointerEq;
wenzelm@29714
    28
wenzelm@29714
    29
fun share_common_data () = PolyML.shareCommonData PolyML.rootFunction;
wenzelm@29714
    30
wenzelm@31312
    31
use "ML-Systems/compiler_polyml-5.3.ML";
wenzelm@32778
    32
PolyML.Compiler.reportUnreferencedIds := true;
wenzelm@30626
    33
wenzelm@30626
    34
wenzelm@30626
    35
(* toplevel pretty printing *)
wenzelm@30626
    36
wenzelm@30676
    37
val pretty_ml =
wenzelm@30676
    38
  let
wenzelm@31318
    39
    fun convert len (PolyML.PrettyBlock (ind, _, context, prts)) =
wenzelm@30676
    40
          let
wenzelm@30676
    41
            fun property name default =
wenzelm@31318
    42
              (case List.find (fn PolyML.ContextProperty (a, _) => name = a | _ => false) context of
wenzelm@31318
    43
                SOME (PolyML.ContextProperty (_, b)) => b
wenzelm@30676
    44
              | NONE => default);
wenzelm@30676
    45
            val bg = property "begin" "";
wenzelm@30676
    46
            val en = property "end" "";
wenzelm@30676
    47
            val len' = property "length" len;
wenzelm@30676
    48
          in ML_Pretty.Block ((bg, en), map (convert len') prts, ind) end
wenzelm@31318
    49
      | convert len (PolyML.PrettyString s) =
wenzelm@30676
    50
          ML_Pretty.String (s, case Int.fromString len of SOME i => i | NONE => size s)
wenzelm@31318
    51
      | convert _ (PolyML.PrettyBreak (wd, _)) =
wenzelm@30676
    52
          ML_Pretty.Break (if wd < 99999 then (false, wd) else (true, 2));
wenzelm@30676
    53
  in convert "" end;
wenzelm@30638
    54
wenzelm@30676
    55
fun ml_pretty (ML_Pretty.Block ((bg, en), prts, ind)) =
wenzelm@30679
    56
      let val context =
wenzelm@31318
    57
        (if bg = "" then [] else [PolyML.ContextProperty ("begin", bg)]) @
wenzelm@31318
    58
        (if en = "" then [] else [PolyML.ContextProperty ("end", en)])
wenzelm@31318
    59
      in PolyML.PrettyBlock (ind, false, context, map ml_pretty prts) end
wenzelm@30676
    60
  | ml_pretty (ML_Pretty.String (s, len)) =
wenzelm@31318
    61
      if len = size s then PolyML.PrettyString s
wenzelm@31318
    62
      else PolyML.PrettyBlock
wenzelm@31318
    63
        (0, false, [PolyML.ContextProperty ("length", Int.toString len)], [PolyML.PrettyString s])
wenzelm@31318
    64
  | ml_pretty (ML_Pretty.Break (false, wd)) = PolyML.PrettyBreak (wd, 0)
wenzelm@31318
    65
  | ml_pretty (ML_Pretty.Break (true, _)) = PolyML.PrettyBreak (99999, 0);
wenzelm@30626
    66
wenzelm@30673
    67
fun toplevel_pp context (_: string list) pp =
wenzelm@30673
    68
  use_text context (1, "pp") false
wenzelm@31318
    69
    ("PolyML.addPrettyPrinter (fn _ => fn _ => ml_pretty o Pretty.to_ML o (" ^ pp ^ "))");
wenzelm@30626
    70
wenzelm@36162
    71
val ml_make_string =
wenzelm@36162
    72
  "(fn x => Pretty.string_of (Pretty.from_ML (pretty_ml (PolyML.prettyRepresentation (x, get_print_depth ())))))";
wenzelm@36162
    73