src/Pure/ML-Systems/polyml-experimental.ML
author wenzelm
Sun, 31 May 2009 14:51:21 +0200
changeset 31312 1c00e4ff3c99
parent 30679 bcc63fcbc3ce
child 31318 133d1cfd6ae7
permissions -rw-r--r--
more modular setup of runtime compilation;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31312
1c00e4ff3c99 more modular setup of runtime compilation;
wenzelm
parents: 30679
diff changeset
     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
31312
1c00e4ff3c99 more modular setup of runtime compilation;
wenzelm
parents: 30679
diff changeset
     3
Compatibility wrapper for Poly/ML 5.3 (SVN experimental).
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
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
     7
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
     8
structure ML_Name_Space =
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
     9
struct
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
    10
  open PolyML.NameSpace;
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
    11
  type T = PolyML.NameSpace.nameSpace;
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
    12
  val global = PolyML.globalNameSpace;
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
    13
end;
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
    14
29714
6cef6700c841 Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff changeset
    15
use "ML-Systems/polyml_common.ML";
6cef6700c841 Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff changeset
    16
use "ML-Systems/multithreading_polyml.ML";
6cef6700c841 Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff changeset
    17
6cef6700c841 Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff changeset
    18
val pointer_eq = PolyML.pointerEq;
6cef6700c841 Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff changeset
    19
6cef6700c841 Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff changeset
    20
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
    21
31312
1c00e4ff3c99 more modular setup of runtime compilation;
wenzelm
parents: 30679
diff changeset
    22
use "ML-Systems/compiler_polyml-5.3.ML";
30626
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    23
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    24
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    25
(* toplevel pretty printing *)
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    26
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    27
val pretty_ml =
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    28
  let
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    29
    fun convert len (PrettyBlock (ind, _, context, prts)) =
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    30
          let
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    31
            fun property name default =
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    32
              (case List.find (fn ContextProperty (a, _) => name = a | _ => false) context of
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    33
                SOME (ContextProperty (_, b)) => b
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    34
              | NONE => default);
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    35
            val bg = property "begin" "";
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    36
            val en = property "end" "";
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    37
            val len' = property "length" len;
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    38
          in ML_Pretty.Block ((bg, en), map (convert len') prts, ind) end
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    39
      | convert len (PrettyString s) =
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    40
          ML_Pretty.String (s, case Int.fromString len of SOME i => i | NONE => size s)
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    41
      | convert _ (PrettyBreak (wd, _)) =
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    42
          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: 30673
diff changeset
    43
  in convert "" end;
30638
15cc4ad0e6e9 added pretty_ml;
wenzelm
parents: 30626
diff changeset
    44
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    45
fun ml_pretty (ML_Pretty.Block ((bg, en), prts, ind)) =
30679
wenzelm
parents: 30676
diff changeset
    46
      let val context =
wenzelm
parents: 30676
diff changeset
    47
        (if bg = "" then [] else [ContextProperty ("begin", bg)]) @
wenzelm
parents: 30676
diff changeset
    48
        (if en = "" then [] else [ContextProperty ("end", en)])
wenzelm
parents: 30676
diff changeset
    49
      in PrettyBlock (ind, false, context, map ml_pretty prts) end
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    50
  | ml_pretty (ML_Pretty.String (s, len)) =
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    51
      if len = size s then PrettyString s
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    52
      else PrettyBlock (0, false, [ContextProperty ("length", Int.toString len)], [PrettyString s])
30626
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    53
  | ml_pretty (ML_Pretty.Break (false, wd)) = PrettyBreak (wd, 0)
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    54
  | ml_pretty (ML_Pretty.Break (true, _)) = PrettyBreak (99999, 0);
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    55
30673
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
    56
fun toplevel_pp context (_: string list) pp =
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
    57
  use_text context (1, "pp") false
30626
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    58
    ("addPrettyPrinter (fn _ => fn _ => ml_pretty o Pretty.to_ML o (" ^ pp ^ "))");
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    59