src/Pure/ML-Systems/polyml.ML
author wenzelm
Mon, 17 Aug 2015 23:45:12 +0200
changeset 60962 faa452d8e265
parent 60956 10d463883dc2
child 60964 fdb82e722f8a
permissions -rw-r--r--
basic setup for native Windows (RAW session without image);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33538
edf497b5b5d2 setup for official Poly/ML 5.3.0, which is now the default;
wenzelm
parents: 32778
diff changeset
     1
(*  Title:      Pure/ML-Systems/polyml.ML
47980
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
     2
    Author:     Makarius
29714
6cef6700c841 Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff changeset
     3
50910
54f06ba192ef tuned comments;
wenzelm
parents: 50909
diff changeset
     4
Compatibility wrapper for Poly/ML.
29714
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
60953
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
     7
(* initial ML name space *)
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
     8
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
     9
structure ML_Name_Space =
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    10
struct
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    11
  open PolyML.NameSpace;
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    12
  type T = PolyML.NameSpace.nameSpace;
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    13
  val global = PolyML.globalNameSpace;
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    14
  val initial_val =
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    15
    List.filter (fn (a, _) => a <> "use" andalso a <> "exit" andalso a <> "commit")
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    16
      (#allVal global ());
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    17
  val initial_type = #allType global ();
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    18
  val initial_fixity = #allFix global ();
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    19
  val initial_structure = #allStruct global ();
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    20
  val initial_signature = #allSig global ();
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    21
  val initial_functor = #allFunct global ();
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    22
  val forget_global_structure = PolyML.Compiler.forgetStructure;
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
    23
end;
56275
600f432ab556 added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents: 54723
diff changeset
    24
600f432ab556 added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents: 54723
diff changeset
    25
54717
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    26
(* ML system operations *)
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    27
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    28
use "ML-Systems/ml_system.ML";
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    29
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    30
if ML_System.name = "polyml-5.3.0"
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    31
then use "ML-Systems/share_common_data_polyml-5.3.0.ML"
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    32
else ();
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    33
60962
faa452d8e265 basic setup for native Windows (RAW session without image);
wenzelm
parents: 60956
diff changeset
    34
if ML_System.platform_is_windows then use "ML-Systems/windows_polyml.ML" else ();
faa452d8e265 basic setup for native Windows (RAW session without image);
wenzelm
parents: 60956
diff changeset
    35
54717
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    36
structure ML_System =
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    37
struct
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    38
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    39
open ML_System;
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    40
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    41
fun share_common_data () = PolyML.shareCommonData PolyML.rootFunction;
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    42
val save_state = PolyML.SaveState.saveState;
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    43
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    44
end;
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    45
42c209a6c225 support for polml-5.5.2;
wenzelm
parents: 54342
diff changeset
    46
47980
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    47
(* exceptions *)
30673
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
    48
31427
5a07cc86675d reraise exceptions to preserve original position (ML system specific);
wenzelm
parents: 31318
diff changeset
    49
fun reraise exn =
5a07cc86675d reraise exceptions to preserve original position (ML system specific);
wenzelm
parents: 31318
diff changeset
    50
  (case PolyML.exceptionLocation exn of
5a07cc86675d reraise exceptions to preserve original position (ML system specific);
wenzelm
parents: 31318
diff changeset
    51
    NONE => raise exn
5a07cc86675d reraise exceptions to preserve original position (ML system specific);
wenzelm
parents: 31318
diff changeset
    52
  | SOME location => PolyML.raiseWithLocation (exn, location));
5a07cc86675d reraise exceptions to preserve original position (ML system specific);
wenzelm
parents: 31318
diff changeset
    53
47980
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    54
exception Interrupt = SML90.Interrupt;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    55
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    56
use "General/exn.ML";
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    57
59470
31d810570879 tuned bootstrap;
wenzelm
parents: 59468
diff changeset
    58
fun print_exception_trace (_: exn -> string) (_: string -> unit) = PolyML.exception_trace;
31d810570879 tuned bootstrap;
wenzelm
parents: 59468
diff changeset
    59
31d810570879 tuned bootstrap;
wenzelm
parents: 59468
diff changeset
    60
if ML_System.name = "polyml-5.5.1"
31d810570879 tuned bootstrap;
wenzelm
parents: 59468
diff changeset
    61
  orelse ML_System.name = "polyml-5.5.2"
31d810570879 tuned bootstrap;
wenzelm
parents: 59468
diff changeset
    62
  orelse ML_System.name = "polyml-5.5.3"
31d810570879 tuned bootstrap;
wenzelm
parents: 59468
diff changeset
    63
then use "ML-Systems/exn_trace_polyml-5.5.1.ML"
31d810570879 tuned bootstrap;
wenzelm
parents: 59468
diff changeset
    64
else ();
31d810570879 tuned bootstrap;
wenzelm
parents: 59468
diff changeset
    65
47980
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    66
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    67
(* multithreading *)
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    68
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    69
val seconds = Time.fromReal;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    70
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    71
if List.exists (fn s => s = "SingleAssignment") (PolyML.Compiler.structureNames ())
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    72
then ()
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    73
else use "ML-Systems/single_assignment_polyml.ML";
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    74
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    75
open Thread;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    76
use "ML-Systems/multithreading.ML";
29714
6cef6700c841 Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff changeset
    77
use "ML-Systems/multithreading_polyml.ML";
47980
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    78
59468
fe6651760643 explicit threads_stack_limit (for recent Poly/ML SVN versions), which leads to soft interrupt instead of exhaustion of virtual memory, which is particularly relevant for the bigger address space of x86_64;
wenzelm
parents: 59127
diff changeset
    79
if ML_System.name = "polyml-5.5.3"
60923
020becec359c clarified modules;
wenzelm
parents: 60897
diff changeset
    80
then use "ML-Systems/ml_stack_polyml-5.5.3.ML"
020becec359c clarified modules;
wenzelm
parents: 60897
diff changeset
    81
else use "ML-Systems/ml_stack_dummy.ML";
59468
fe6651760643 explicit threads_stack_limit (for recent Poly/ML SVN versions), which leads to soft interrupt instead of exhaustion of virtual memory, which is particularly relevant for the bigger address space of x86_64;
wenzelm
parents: 59127
diff changeset
    82
39616
8052101883c3 renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents: 38470
diff changeset
    83
use "ML-Systems/unsynchronized.ML";
8052101883c3 renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents: 38470
diff changeset
    84
val _ = PolyML.Compiler.forgetValue "ref";
8052101883c3 renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents: 38470
diff changeset
    85
val _ = PolyML.Compiler.forgetType "ref";
29714
6cef6700c841 Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff changeset
    86
47980
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    87
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    88
(* pervasive environment *)
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    89
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    90
val _ = PolyML.Compiler.forgetValue "isSome";
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    91
val _ = PolyML.Compiler.forgetValue "getOpt";
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    92
val _ = PolyML.Compiler.forgetValue "valOf";
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    93
val _ = PolyML.Compiler.forgetValue "foldl";
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    94
val _ = PolyML.Compiler.forgetValue "foldr";
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    95
val _ = PolyML.Compiler.forgetValue "print";
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    96
val _ = PolyML.Compiler.forgetValue "explode";
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    97
val _ = PolyML.Compiler.forgetValue "concat";
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    98
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
    99
val ord = SML90.ord;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   100
val chr = SML90.chr;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   101
val raw_explode = SML90.explode;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   102
val implode = SML90.implode;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   103
54342
fbcaa9f08879 avoid non-portable int constant -- make SML/NJ happy;
wenzelm
parents: 53709
diff changeset
   104
val io_buffer_size = 4096;
fbcaa9f08879 avoid non-portable int constant -- make SML/NJ happy;
wenzelm
parents: 53709
diff changeset
   105
47980
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   106
fun quit () = exit 0;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   107
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   108
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   109
(* ML runtime system *)
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   110
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   111
val timing = PolyML.timing;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   112
val profiling = PolyML.profiling;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   113
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   114
fun profile 0 f x = f x
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   115
  | profile n f x =
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   116
      let
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   117
        val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler n;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   118
        val res = Exn.capture f x;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   119
        val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler 0;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   120
      in Exn.release res end;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   121
29714
6cef6700c841 Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff changeset
   122
val pointer_eq = PolyML.pointerEq;
6cef6700c841 Compatibility wrapper for experimental versions of Poly/ML after 5.2.1.
wenzelm
parents:
diff changeset
   123
47980
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   124
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   125
(* ML toplevel pretty printing *)
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   126
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   127
use "ML-Systems/ml_pretty.ML";
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   128
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   129
local
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   130
  val depth = Unsynchronized.ref 10;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   131
in
56281
03c3d1a7c3b8 proper configuration option "ML_print_depth";
wenzelm
parents: 56275
diff changeset
   132
  fun get_default_print_depth () = ! depth;
56285
wenzelm
parents: 56283
diff changeset
   133
  fun default_print_depth n = (depth := n; PolyML.print_depth n);
wenzelm
parents: 56283
diff changeset
   134
  val _ = default_print_depth 10;
47980
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   135
end;
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   136
c81801f881b3 simplified Poly/ML setup -- 5.3.0 is now the common base-line;
wenzelm
parents: 44249
diff changeset
   137
val error_depth = PolyML.error_depth;
30626
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
   138
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
   139
val pretty_ml =
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
   140
  let
51638
1275716f395b more defensive representation of forced break within PolyML.PrettyBreak -- avoid accidental blowup if low-level operations are used, notably PolyML.makestring or its variant General.exnMessage;
wenzelm
parents: 50911
diff changeset
   141
    fun convert _ (PolyML.PrettyBreak (wd, _)) = ML_Pretty.Break (false, wd)
54718
8c5221d698cd tuned patterns;
wenzelm
parents: 54717
diff changeset
   142
      | convert _ (PolyML.PrettyBlock (_, _,
51638
1275716f395b more defensive representation of forced break within PolyML.PrettyBreak -- avoid accidental blowup if low-level operations are used, notably PolyML.makestring or its variant General.exnMessage;
wenzelm
parents: 50911
diff changeset
   143
            [PolyML.ContextProperty ("fbrk", _)], [PolyML.PrettyString " "])) =
1275716f395b more defensive representation of forced break within PolyML.PrettyBreak -- avoid accidental blowup if low-level operations are used, notably PolyML.makestring or its variant General.exnMessage;
wenzelm
parents: 50911
diff changeset
   144
          ML_Pretty.Break (true, 1)
1275716f395b more defensive representation of forced break within PolyML.PrettyBreak -- avoid accidental blowup if low-level operations are used, notably PolyML.makestring or its variant General.exnMessage;
wenzelm
parents: 50911
diff changeset
   145
      | 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
   146
          let
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
   147
            fun property name default =
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
   148
              (case List.find (fn PolyML.ContextProperty (a, _) => name = a | _ => false) context of
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
   149
                SOME (PolyML.ContextProperty (_, b)) => b
54718
8c5221d698cd tuned patterns;
wenzelm
parents: 54717
diff changeset
   150
              | _ => default);
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
   151
            val bg = property "begin" "";
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
   152
            val en = property "end" "";
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
   153
            val len' = property "length" len;
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
   154
          in ML_Pretty.Block ((bg, en), map (convert len') prts, ind) end
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
   155
      | convert len (PolyML.PrettyString s) =
30676
edca392a2abb pretty_ml/ml_pretty: proper handling of markup and string length;
wenzelm
parents: 30673
diff changeset
   156
          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
   157
  in convert "" end;
30638
15cc4ad0e6e9 added pretty_ml;
wenzelm
parents: 30626
diff changeset
   158
51638
1275716f395b more defensive representation of forced break within PolyML.PrettyBreak -- avoid accidental blowup if low-level operations are used, notably PolyML.makestring or its variant General.exnMessage;
wenzelm
parents: 50911
diff changeset
   159
fun ml_pretty (ML_Pretty.Break (false, wd)) = PolyML.PrettyBreak (wd, 0)
1275716f395b more defensive representation of forced break within PolyML.PrettyBreak -- avoid accidental blowup if low-level operations are used, notably PolyML.makestring or its variant General.exnMessage;
wenzelm
parents: 50911
diff changeset
   160
  | ml_pretty (ML_Pretty.Break (true, _)) =
1275716f395b more defensive representation of forced break within PolyML.PrettyBreak -- avoid accidental blowup if low-level operations are used, notably PolyML.makestring or its variant General.exnMessage;
wenzelm
parents: 50911
diff changeset
   161
      PolyML.PrettyBlock (0, false, [PolyML.ContextProperty ("fbrk", "")],
1275716f395b more defensive representation of forced break within PolyML.PrettyBreak -- avoid accidental blowup if low-level operations are used, notably PolyML.makestring or its variant General.exnMessage;
wenzelm
parents: 50911
diff changeset
   162
        [PolyML.PrettyString " "])
1275716f395b more defensive representation of forced break within PolyML.PrettyBreak -- avoid accidental blowup if low-level operations are used, notably PolyML.makestring or its variant General.exnMessage;
wenzelm
parents: 50911
diff changeset
   163
  | ml_pretty (ML_Pretty.Block ((bg, en), prts, ind)) =
30679
wenzelm
parents: 30676
diff changeset
   164
      let val context =
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
   165
        (if bg = "" then [] else [PolyML.ContextProperty ("begin", bg)]) @
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
   166
        (if en = "" then [] else [PolyML.ContextProperty ("end", en)])
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
   167
      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
   168
  | ml_pretty (ML_Pretty.String (s, len)) =
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
   169
      if len = size s then PolyML.PrettyString s
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
   170
      else PolyML.PrettyBlock
51638
1275716f395b more defensive representation of forced break within PolyML.PrettyBreak -- avoid accidental blowup if low-level operations are used, notably PolyML.makestring or its variant General.exnMessage;
wenzelm
parents: 50911
diff changeset
   171
        (0, false, [PolyML.ContextProperty ("length", Int.toString len)], [PolyML.PrettyString s]);
30626
248de8dd839e adapted toplevel_pp to ML_Pretty.pretty;
wenzelm
parents: 30619
diff changeset
   172
60897
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   173
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   174
(* ML compiler *)
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   175
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   176
structure ML_Name_Space =
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   177
struct
60953
87f0f707a5f8 clarified initial ML name space (amending 7aad4be8a48e);
wenzelm
parents: 60923
diff changeset
   178
  open ML_Name_Space;
60897
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   179
  val display_val = pretty_ml o PolyML.NameSpace.displayVal;
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   180
end;
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   181
60956
10d463883dc2 explicit debug flag for ML compiler;
wenzelm
parents: 60954
diff changeset
   182
use "ML-Systems/ml_compiler_parameters.ML";
10d463883dc2 explicit debug flag for ML compiler;
wenzelm
parents: 60954
diff changeset
   183
if ML_System.name = "polyml-5.5.3"
10d463883dc2 explicit debug flag for ML compiler;
wenzelm
parents: 60954
diff changeset
   184
then use "ML-Systems/ml_compiler_parameters_polyml-5.5.3.ML" else ();
10d463883dc2 explicit debug flag for ML compiler;
wenzelm
parents: 60954
diff changeset
   185
60897
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   186
use "ML-Systems/use_context.ML";
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   187
use "ML-Systems/ml_positions.ML";
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   188
use "ML-Systems/compiler_polyml.ML";
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   189
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   190
PolyML.Compiler.reportUnreferencedIds := true;
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   191
PolyML.Compiler.printInAlphabeticalOrder := false;
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   192
PolyML.Compiler.maxInlineSize := 80;
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   193
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   194
fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2);
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   195
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   196
use "ML-Systems/ml_parse_tree.ML";
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   197
if ML_System.name = "polyml-5.5.3"
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   198
then use "ML-Systems/ml_parse_tree_polyml-5.5.3.ML" else ();
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   199
30673
60568c168040 more systematic type use_context;
wenzelm
parents: 30638
diff changeset
   200
fun toplevel_pp context (_: string list) pp =
60956
10d463883dc2 explicit debug flag for ML compiler;
wenzelm
parents: 60954
diff changeset
   201
  use_text context {line = 1, file = "pp", verbose = false, debug = false}
31318
133d1cfd6ae7 explicit PolyML qualification;
wenzelm
parents: 31312
diff changeset
   202
    ("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
   203
59127
723b11f8ffbf more careful handling of auxiliary environment structure -- allow nested ML evaluation;
wenzelm
parents: 59055
diff changeset
   204
fun ml_make_string struct_name =
723b11f8ffbf more careful handling of auxiliary environment structure -- allow nested ML evaluation;
wenzelm
parents: 59055
diff changeset
   205
  "(fn x => Pretty.string_of (Pretty.from_ML (pretty_ml (PolyML.prettyRepresentation (x, " ^
723b11f8ffbf more careful handling of auxiliary environment structure -- allow nested ML evaluation;
wenzelm
parents: 59055
diff changeset
   206
    struct_name ^ ".ML_print_depth ())))))";
60897
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   207
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   208
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   209
(* ML debugger *)
7aad4be8a48e print values for stack entry;
wenzelm
parents: 60745
diff changeset
   210
60954
eeee8349e9eb abstract exn_id based on getExnId in polyml/basis/FinalPolyML.sml (NB: the mutable machine word cannot be inspected in ML, e.g. toplevel pp dumps core);
wenzelm
parents: 60953
diff changeset
   211
if ML_System.name = "polyml-5.5.3"
eeee8349e9eb abstract exn_id based on getExnId in polyml/basis/FinalPolyML.sml (NB: the mutable machine word cannot be inspected in ML, e.g. toplevel pp dumps core);
wenzelm
parents: 60953
diff changeset
   212
then use "ML-Systems/ml_debugger_polyml-5.5.3.ML"
eeee8349e9eb abstract exn_id based on getExnId in polyml/basis/FinalPolyML.sml (NB: the mutable machine word cannot be inspected in ML, e.g. toplevel pp dumps core);
wenzelm
parents: 60953
diff changeset
   213
else use "ML-Systems/ml_debugger.ML";