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