src/Pure/ML-Systems/polyml_common.ML
author wenzelm
Sat Nov 27 16:29:53 2010 +0100 (2010-11-27 ago)
changeset 40748 591b6778d076
parent 40627 becf5d5187cc
child 41352 87adb55fb0fb
permissions -rw-r--r--
removed bash from ML system bootstrap, and past the Secure ML barrier;
wenzelm@26215
     1
(*  Title:      Pure/ML-Systems/polyml_common.ML
wenzelm@26215
     2
wenzelm@31308
     3
Compatibility file for Poly/ML -- common part for 5.x.
wenzelm@26215
     4
*)
wenzelm@26215
     5
wenzelm@28443
     6
exception Interrupt = SML90.Interrupt;
wenzelm@28443
     7
wenzelm@34136
     8
use "General/exn.ML";
wenzelm@36876
     9
wenzelm@36876
    10
if List.exists (fn s => s = "SingleAssignment") (PolyML.Compiler.structureNames ())
wenzelm@36876
    11
then ()
wenzelm@36876
    12
else use "ML-Systems/single_assignment_polyml.ML";
wenzelm@36876
    13
wenzelm@26215
    14
use "ML-Systems/multithreading.ML";
wenzelm@26215
    15
use "ML-Systems/time_limit.ML";
wenzelm@40393
    16
use "General/timing.ML";
wenzelm@30619
    17
use "ML-Systems/ml_pretty.ML";
wenzelm@30672
    18
use "ML-Systems/use_context.ML";
wenzelm@26215
    19
wenzelm@26215
    20
wenzelm@26215
    21
(** ML system and platform related **)
wenzelm@26215
    22
wenzelm@26474
    23
val forget_structure = PolyML.Compiler.forgetStructure;
wenzelm@26474
    24
wenzelm@33213
    25
val _ = PolyML.Compiler.forgetValue "isSome";
wenzelm@33213
    26
val _ = PolyML.Compiler.forgetValue "getOpt";
wenzelm@33213
    27
val _ = PolyML.Compiler.forgetValue "valOf";
wenzelm@33004
    28
val _ = PolyML.Compiler.forgetValue "foldl";
wenzelm@33004
    29
val _ = PolyML.Compiler.forgetValue "foldr";
wenzelm@31324
    30
val _ = PolyML.Compiler.forgetValue "print";
wenzelm@40627
    31
val _ = PolyML.Compiler.forgetValue "explode";
wenzelm@31324
    32
wenzelm@26474
    33
wenzelm@26215
    34
(* Compiler options *)
wenzelm@26215
    35
wenzelm@26215
    36
val ml_system_fix_ints = false;
wenzelm@26215
    37
wenzelm@26215
    38
PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm@26215
    39
PolyML.Compiler.maxInlineSize := 80;
wenzelm@26215
    40
wenzelm@26215
    41
wenzelm@26215
    42
(* old Poly/ML emulation *)
wenzelm@26215
    43
wenzelm@31319
    44
fun quit () = exit 0;
wenzelm@26215
    45
wenzelm@26215
    46
wenzelm@26215
    47
(* restore old-style character / string functions *)
wenzelm@26215
    48
wenzelm@26215
    49
val ord = SML90.ord;
wenzelm@26215
    50
val chr = SML90.chr;
wenzelm@40627
    51
val raw_explode = SML90.explode;
wenzelm@26215
    52
val implode = SML90.implode;
wenzelm@26215
    53
wenzelm@26215
    54
wenzelm@26215
    55
(* prompts *)
wenzelm@26215
    56
wenzelm@26215
    57
fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2);
wenzelm@26215
    58
wenzelm@26215
    59
wenzelm@36162
    60
(* toplevel printing *)
wenzelm@26215
    61
wenzelm@26215
    62
local
wenzelm@39616
    63
  val depth = ref 10;
wenzelm@26215
    64
in
wenzelm@26215
    65
  fun get_print_depth () = ! depth;
wenzelm@26215
    66
  fun print_depth n = (depth := n; PolyML.print_depth n);
wenzelm@26215
    67
end;
wenzelm@26215
    68
wenzelm@31319
    69
val error_depth = PolyML.error_depth;
wenzelm@31319
    70
wenzelm@36162
    71
val ml_make_string = "PolyML.makestring";
wenzelm@36162
    72
wenzelm@26215
    73
wenzelm@26215
    74
wenzelm@26215
    75
(** interrupts **)
wenzelm@26215
    76
wenzelm@26215
    77
local
wenzelm@26215
    78
wenzelm@26215
    79
val sig_int = 2;
wenzelm@26215
    80
val default_handler = Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ());
wenzelm@26215
    81
wenzelm@26215
    82
val _ = Signal.signal (sig_int, default_handler);
wenzelm@26380
    83
val _ = PolyML.onEntry (fn () => (Signal.signal (sig_int, default_handler); ()));
wenzelm@26215
    84
wenzelm@26215
    85
fun change_signal new_handler f x =
wenzelm@26215
    86
  let
wenzelm@26215
    87
    (*RACE wrt. other signals!*)
wenzelm@26215
    88
    val old_handler = Signal.signal (sig_int, new_handler);
wenzelm@26215
    89
    val result = Exn.capture (f old_handler) x;
wenzelm@26215
    90
    val _ = Signal.signal (sig_int, old_handler);
wenzelm@26215
    91
  in Exn.release result end;
wenzelm@26215
    92
wenzelm@26215
    93
in
wenzelm@26215
    94
wenzelm@26215
    95
fun interruptible f = change_signal default_handler (fn _ => f);
wenzelm@26215
    96
wenzelm@26215
    97
fun uninterruptible f =
wenzelm@26215
    98
  change_signal Signal.SIG_IGN
wenzelm@26215
    99
    (fn old_handler => f (fn g => change_signal old_handler (fn _ => g)));
wenzelm@26215
   100
wenzelm@26215
   101
end;
wenzelm@26215
   102
wenzelm@26215
   103
wenzelm@26215
   104
wenzelm@26215
   105
(** OS related **)
wenzelm@26215
   106
wenzelm@26215
   107
(* current directory *)
wenzelm@26215
   108
wenzelm@26215
   109
val cd = OS.FileSys.chDir;
wenzelm@26215
   110
val pwd = OS.FileSys.getDir;
wenzelm@26215
   111
wenzelm@26215
   112
wenzelm@26215
   113
(* getenv *)
wenzelm@26215
   114
wenzelm@26215
   115
fun getenv var =
wenzelm@26215
   116
  (case OS.Process.getEnv var of
wenzelm@26215
   117
    NONE => ""
wenzelm@26215
   118
  | SOME txt => txt);
wenzelm@26215
   119
wenzelm@26215
   120
wenzelm@31319
   121
wenzelm@31319
   122
(** Runtime system **)
wenzelm@31319
   123
wenzelm@31319
   124
val exception_trace = PolyML.exception_trace;
wenzelm@31319
   125
val timing = PolyML.timing;
wenzelm@31319
   126
val profiling = PolyML.profiling;
wenzelm@26215
   127
wenzelm@26215
   128
fun profile 0 f x = f x
wenzelm@26215
   129
  | profile n f x =
wenzelm@26215
   130
      let
wenzelm@26215
   131
        val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler n;
wenzelm@26215
   132
        val res = Exn.capture f x;
wenzelm@26215
   133
        val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler 0;
wenzelm@26215
   134
      in Exn.release res end;
wenzelm@26215
   135