src/Pure/ML-Systems/polyml_common.ML
author wenzelm
Thu Oct 01 23:27:05 2009 +0200 (2009-10-01)
changeset 32843 c8f5a7c8353f
parent 32776 1504f9c2d060
child 33004 715566791eb0
permissions -rw-r--r--
moved cache_conv to src/Pure/conv.ML, use Thm.cterm_cache;
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@26215
     8
use "ML-Systems/exn.ML";
wenzelm@26215
     9
use "ML-Systems/multithreading.ML";
wenzelm@26215
    10
use "ML-Systems/time_limit.ML";
wenzelm@31686
    11
use "ML-Systems/timing.ML";
wenzelm@26220
    12
use "ML-Systems/system_shell.ML";
wenzelm@30619
    13
use "ML-Systems/ml_pretty.ML";
wenzelm@30672
    14
use "ML-Systems/use_context.ML";
wenzelm@26215
    15
wenzelm@26215
    16
wenzelm@26215
    17
(** ML system and platform related **)
wenzelm@26215
    18
wenzelm@26474
    19
val forget_structure = PolyML.Compiler.forgetStructure;
wenzelm@26474
    20
wenzelm@31324
    21
val _ = PolyML.Compiler.forgetValue "print";
wenzelm@32741
    22
val _ = PolyML.Compiler.forgetValue "ref";
wenzelm@32741
    23
val _ = PolyML.Compiler.forgetType "ref";
wenzelm@31324
    24
wenzelm@26474
    25
wenzelm@26215
    26
(* Compiler options *)
wenzelm@26215
    27
wenzelm@26215
    28
val ml_system_fix_ints = false;
wenzelm@26215
    29
wenzelm@26215
    30
PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm@26215
    31
PolyML.Compiler.maxInlineSize := 80;
wenzelm@26215
    32
wenzelm@26215
    33
wenzelm@26215
    34
(* old Poly/ML emulation *)
wenzelm@26215
    35
wenzelm@31319
    36
fun quit () = exit 0;
wenzelm@26215
    37
wenzelm@26215
    38
wenzelm@26215
    39
(* restore old-style character / string functions *)
wenzelm@26215
    40
wenzelm@26215
    41
val ord = SML90.ord;
wenzelm@26215
    42
val chr = SML90.chr;
wenzelm@26215
    43
val explode = SML90.explode;
wenzelm@26215
    44
val implode = SML90.implode;
wenzelm@26215
    45
wenzelm@26215
    46
wenzelm@26215
    47
(* prompts *)
wenzelm@26215
    48
wenzelm@26215
    49
fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2);
wenzelm@26215
    50
wenzelm@26215
    51
wenzelm@30625
    52
(* print depth *)
wenzelm@26215
    53
wenzelm@26215
    54
local
wenzelm@32737
    55
  val depth = Unsynchronized.ref 10;
wenzelm@26215
    56
in
wenzelm@26215
    57
  fun get_print_depth () = ! depth;
wenzelm@26215
    58
  fun print_depth n = (depth := n; PolyML.print_depth n);
wenzelm@26215
    59
end;
wenzelm@26215
    60
wenzelm@31319
    61
val error_depth = PolyML.error_depth;
wenzelm@31319
    62
wenzelm@26215
    63
wenzelm@26215
    64
wenzelm@26215
    65
(** interrupts **)
wenzelm@26215
    66
wenzelm@26215
    67
local
wenzelm@26215
    68
wenzelm@26215
    69
val sig_int = 2;
wenzelm@26215
    70
val default_handler = Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ());
wenzelm@26215
    71
wenzelm@26215
    72
val _ = Signal.signal (sig_int, default_handler);
wenzelm@26380
    73
val _ = PolyML.onEntry (fn () => (Signal.signal (sig_int, default_handler); ()));
wenzelm@26215
    74
wenzelm@26215
    75
fun change_signal new_handler f x =
wenzelm@26215
    76
  let
wenzelm@26215
    77
    (*RACE wrt. other signals!*)
wenzelm@26215
    78
    val old_handler = Signal.signal (sig_int, new_handler);
wenzelm@26215
    79
    val result = Exn.capture (f old_handler) x;
wenzelm@26215
    80
    val _ = Signal.signal (sig_int, old_handler);
wenzelm@26215
    81
  in Exn.release result end;
wenzelm@26215
    82
wenzelm@26215
    83
in
wenzelm@26215
    84
wenzelm@26215
    85
fun interruptible f = change_signal default_handler (fn _ => f);
wenzelm@26215
    86
wenzelm@26215
    87
fun uninterruptible f =
wenzelm@26215
    88
  change_signal Signal.SIG_IGN
wenzelm@26215
    89
    (fn old_handler => f (fn g => change_signal old_handler (fn _ => g)));
wenzelm@26215
    90
wenzelm@26215
    91
end;
wenzelm@26215
    92
wenzelm@26215
    93
wenzelm@26215
    94
wenzelm@26215
    95
(** OS related **)
wenzelm@26215
    96
wenzelm@26215
    97
(* current directory *)
wenzelm@26215
    98
wenzelm@26215
    99
val cd = OS.FileSys.chDir;
wenzelm@26215
   100
val pwd = OS.FileSys.getDir;
wenzelm@26215
   101
wenzelm@28488
   102
fun process_id () =
wenzelm@28488
   103
  Word.fmt StringCvt.DEC (Word.fromLargeWord (Posix.Process.pidToWord (Posix.ProcEnv.getpid ())));
wenzelm@26215
   104
wenzelm@26215
   105
wenzelm@26215
   106
(* getenv *)
wenzelm@26215
   107
wenzelm@26215
   108
fun getenv var =
wenzelm@26215
   109
  (case OS.Process.getEnv var of
wenzelm@26215
   110
    NONE => ""
wenzelm@26215
   111
  | SOME txt => txt);
wenzelm@26215
   112
wenzelm@26215
   113
wenzelm@31319
   114
wenzelm@31319
   115
(** Runtime system **)
wenzelm@31319
   116
wenzelm@31319
   117
val exception_trace = PolyML.exception_trace;
wenzelm@31319
   118
val timing = PolyML.timing;
wenzelm@31319
   119
val profiling = PolyML.profiling;
wenzelm@26215
   120
wenzelm@26215
   121
fun profile 0 f x = f x
wenzelm@26215
   122
  | profile n f x =
wenzelm@26215
   123
      let
wenzelm@26215
   124
        val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler n;
wenzelm@26215
   125
        val res = Exn.capture f x;
wenzelm@26215
   126
        val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler 0;
wenzelm@26215
   127
      in Exn.release res end;
wenzelm@26215
   128