src/Pure/ML-Systems/polyml-experimental.ML
author wenzelm
Thu, 04 Jun 2009 17:31:38 +0200
changeset 31427 5a07cc86675d
parent 31318 133d1cfd6ae7
child 31433 12f5f6af3d2d
permissions -rw-r--r--
reraise exceptions to preserve original position (ML system specific);
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
31427
5a07cc86675d reraise exceptions to preserve original position (ML system specific);
wenzelm
parents: 31318
diff changeset
    15
fun reraise exn =
5a07cc86675d reraise exceptions to preserve original position (ML system specific);
wenzelm
parents: 31318
diff changeset
    16
  (case PolyML.exceptionLocation exn of
5a07cc86675d reraise exceptions to preserve original position (ML system specific);
wenzelm
parents: 31318
diff changeset
    17
    NONE => raise exn
5a07cc86675d reraise exceptions to preserve original position (ML system specific);
wenzelm
parents: 31318
diff changeset
    18
  | SOME location => PolyML.raiseWithLocation (exn, location));
5a07cc86675d reraise exceptions to preserve original position (ML system specific);
wenzelm
parents: 31318
diff 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
1c00e4ff3c99 more modular setup of runtime compilation;
wenzelm
parents: 30679
diff changeset
    27
use "ML-Systems/compiler_polyml-5.3.ML";
30626
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    28
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    29
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    30
(* toplevel pretty printing *)
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    31
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    32
val pretty_ml =
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    33
  let
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    34
    fun convert len (PolyML.PrettyBlock (ind, _, context, prts)) =
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    35
          let
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    36
            fun property name default =
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    37
              (case List.find (fn PolyML.ContextProperty (a, _) => name = a | _ => false) context of
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    38
                SOME (PolyML.ContextProperty (_, b)) => b
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    39
              | NONE => default);
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    40
            val bg = property "begin" "";
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    41
            val en = property "end" "";
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    42
            val len' = property "length" len;
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    43
          in ML_Pretty.Block ((bg, en), map (convert len') prts, ind) end
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    44
      | convert len (PolyML.PrettyString s) =
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    45
          ML_Pretty.String (s, case Int.fromString len of SOME i => i | NONE => size s)
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    46
      | convert _ (PolyML.PrettyBreak (wd, _)) =
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff 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: 30673
diff changeset
    48
  in convert "" end;
30638
15cc4ad0e6e9 added pretty_ml;
wenzelm
parents: 30626
diff changeset
    49
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
    50
fun ml_pretty (ML_Pretty.Block ((bg, en), prts, ind)) =
30679
wenzelm
parents: 30676
diff changeset
    51
      let val context =
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    52
        (if bg = "" then [] else [PolyML.ContextProperty ("begin", bg)]) @
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    53
        (if en = "" then [] else [PolyML.ContextProperty ("end", en)])
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    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: 30673
diff changeset
    55
  | ml_pretty (ML_Pretty.String (s, len)) =
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    56
      if len = size s then PolyML.PrettyString s
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    57
      else PolyML.PrettyBlock
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    58
        (0, false, [PolyML.ContextProperty ("length", Int.toString len)], [PolyML.PrettyString s])
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    59
  | ml_pretty (ML_Pretty.Break (false, wd)) = PolyML.PrettyBreak (wd, 0)
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    60
  | ml_pretty (ML_Pretty.Break (true, _)) = PolyML.PrettyBreak (99999, 0);
30626
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    61
30673
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
    62
fun toplevel_pp context (_: string list) pp =
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
    63
  use_text context (1, "pp") false
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
    64
    ("PolyML.addPrettyPrinter (fn _ => fn _ => ml_pretty o Pretty.to_ML o (" ^ pp ^ "))");
30626
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
    65