1 (* Title: Pure/ML-Systems/polyml_common.ML
3 Compatibility file for Poly/ML -- common part for 5.x.
6 exception Interrupt = SML90.Interrupt;
8 use "ML-Systems/exn.ML";
9 use "ML-Systems/multithreading.ML";
10 use "ML-Systems/time_limit.ML";
11 use "ML-Systems/system_shell.ML";
12 use "ML-Systems/ml_pretty.ML";
13 use "ML-Systems/use_context.ML";
16 (** ML system and platform related **)
18 val forget_structure = PolyML.Compiler.forgetStructure;
21 (* Compiler options *)
23 val ml_system_fix_ints = false;
25 PolyML.Compiler.printInAlphabeticalOrder := false;
26 PolyML.Compiler.maxInlineSize := 80;
29 (* old Poly/ML emulation *)
40 (* restore old-style character / string functions *)
44 val explode = SML90.explode;
45 val implode = SML90.implode;
48 (* compiler-independent timing functions *)
52 val timer = Timer.startCPUTimer ();
53 val time = Timer.checkCPUTimer timer;
56 fun end_timing (timer, {sys, usr}) =
58 open Time; (*...for Time.toString, Time.+ and Time.- *)
59 val {sys = sys2, usr = usr2} = Timer.checkCPUTimer timer;
60 val user = usr2 - usr;
61 val all = user + sys2 - sys;
62 val message = "User " ^ toString user ^ " All "^ toString all ^ " secs" handle Time => "";
63 in {message = message, user = user, all = all} end;
65 fun check_timer timer =
67 val {sys, usr} = Timer.checkCPUTimer timer;
68 val gc = Timer.checkGCTime timer; (* FIXME already included in usr? *)
69 in (sys, usr, gc) end;
74 fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2);
82 fun get_print_depth () = ! depth;
83 fun print_depth n = (depth := n; PolyML.print_depth n);
93 val default_handler = Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ());
95 val _ = Signal.signal (sig_int, default_handler);
96 val _ = PolyML.onEntry (fn () => (Signal.signal (sig_int, default_handler); ()));
98 fun change_signal new_handler f x =
100 (*RACE wrt. other signals!*)
101 val old_handler = Signal.signal (sig_int, new_handler);
102 val result = Exn.capture (f old_handler) x;
103 val _ = Signal.signal (sig_int, old_handler);
104 in Exn.release result end;
108 fun interruptible f = change_signal default_handler (fn _ => f);
110 fun uninterruptible f =
111 change_signal Signal.SIG_IGN
112 (fn old_handler => f (fn g => change_signal old_handler (fn _ => g)));
120 (* current directory *)
122 val cd = OS.FileSys.chDir;
123 val pwd = OS.FileSys.getDir;
126 Word.fmt StringCvt.DEC (Word.fromLargeWord (Posix.Process.pidToWord (Posix.ProcEnv.getpid ())));
132 (case OS.Process.getEnv var of
137 (* profile execution *)
139 fun profile 0 f x = f x
142 val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler n;
143 val res = Exn.capture f x;
144 val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler 0;
145 in Exn.release res end;