author | wenzelm |
Sat, 16 Feb 2008 16:44:02 +0100 | |
changeset 26084 | a7475459c740 |
parent 25732 | 308315ee2b6d |
child 26220 | d34b68c21f9a |
permissions | -rw-r--r-- |
4403 | 1 |
(* Title: Pure/ML-Systems/smlnj.ML |
2 |
ID: $Id$ |
|
3 |
||
5708 | 4 |
Compatibility file for Standard ML of New Jersey 110 or later. |
4403 | 5 |
*) |
6 |
||
24599
7b0ecf9a9055
use_text/file: tune text (cf. ML_Parse.fix_ints);
wenzelm
parents:
24329
diff
changeset
|
7 |
use "ML-Systems/proper_int.ML"; |
7b0ecf9a9055
use_text/file: tune text (cf. ML_Parse.fix_ints);
wenzelm
parents:
24329
diff
changeset
|
8 |
use "ML-Systems/overloading_smlnj.ML"; |
23965
f93e509659c1
ML-Systems/exn.ML, ML-Systems/multithreading_dummy.ML;
wenzelm
parents:
23921
diff
changeset
|
9 |
use "ML-Systems/exn.ML"; |
25732 | 10 |
use "ML-Systems/universal.ML"; |
24688
a5754ca5c510
replaced interrupt_timeout by TimeLimit.timeLimit (available on SML/NJ and Poly/ML 5.1);
wenzelm
parents:
24599
diff
changeset
|
11 |
use "ML-Systems/multithreading.ML"; |
23921
947152add153
added compatibility file for ML systems without multithreading;
wenzelm
parents:
23826
diff
changeset
|
12 |
|
16542 | 13 |
|
14 |
(*low-level pointer equality*) |
|
16502 | 15 |
|
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
16 |
CM.autoload "$smlnj/init/init.cmi"; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
17 |
val pointer_eq = InlineT.ptreql; |
16528 | 18 |
|
16502 | 19 |
|
4403 | 20 |
(* restore old-style character / string functions *) |
21 |
||
24145 | 22 |
val ord = mk_int o SML90.ord; |
23 |
val chr = SML90.chr o dest_int; |
|
10725 | 24 |
val explode = SML90.explode; |
25 |
val implode = SML90.implode; |
|
4403 | 26 |
|
27 |
||
28 |
(* New Jersey ML parameters *) |
|
29 |
||
30 |
val _ = |
|
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
31 |
(Control.Print.printLength := 1000; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
32 |
Control.Print.printDepth := 350; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
33 |
Control.Print.stringDepth := 250; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
34 |
Control.Print.signatures := 2; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
35 |
Control.MC.matchRedundantError := false); |
4403 | 36 |
|
37 |
||
38 |
(* Poly/ML emulation *) |
|
39 |
||
24599
7b0ecf9a9055
use_text/file: tune text (cf. ML_Parse.fix_ints);
wenzelm
parents:
24329
diff
changeset
|
40 |
val exit = exit o dest_int; |
4403 | 41 |
fun quit () = exit 0; |
42 |
||
43 |
(*limit the printing depth -- divided by 2 for comparibility with Poly/ML*) |
|
24329 | 44 |
local |
24599
7b0ecf9a9055
use_text/file: tune text (cf. ML_Parse.fix_ints);
wenzelm
parents:
24329
diff
changeset
|
45 |
val depth = ref (10: int); |
24329 | 46 |
in |
47 |
fun get_print_depth () = ! depth; |
|
48 |
fun print_depth n = |
|
49 |
(depth := n; |
|
50 |
Control.Print.printDepth := dest_int n div 2; |
|
51 |
Control.Print.printLength := dest_int n); |
|
52 |
end; |
|
4403 | 53 |
|
5816 | 54 |
(* compiler-independent timing functions *) |
4403 | 55 |
|
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
56 |
fun start_timing () = |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
57 |
let val CPUtimer = Timer.startCPUTimer(); |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
58 |
val time = Timer.checkCPUTimer(CPUtimer) |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
59 |
in (CPUtimer,time) end; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
60 |
|
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
61 |
fun end_timing (CPUtimer, {sys,usr}) = |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
62 |
let open Time (*...for Time.toString, Time.+ and Time.- *) |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
63 |
val {sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer) |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
64 |
in "User " ^ toString (usr2-usr) ^ |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
65 |
" All "^ toString (sys2-sys + usr2-usr) ^ |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
66 |
" secs" |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
67 |
handle Time => "" |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
68 |
end; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
69 |
|
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
70 |
fun check_timer timer = |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
71 |
let |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
72 |
val {sys, usr} = Timer.checkCPUTimer timer; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
73 |
val gc = Timer.checkGCTime timer; (* FIXME already included in usr? *) |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
74 |
in (sys, usr, gc) end; |
4403 | 75 |
|
76 |
||
16660 | 77 |
(*prompts*) |
4977 | 78 |
fun ml_prompts p1 p2 = |
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
79 |
(Control.primaryPrompt := p1; Control.secondaryPrompt := p2); |
4977 | 80 |
|
17511 | 81 |
(*dummy implementation*) |
16681 | 82 |
fun profile (n: int) f x = f x; |
83 |
||
17511 | 84 |
(*dummy implementation*) |
16681 | 85 |
fun exception_trace f = f (); |
4977 | 86 |
|
18384 | 87 |
(*dummy implementation*) |
88 |
fun print x = x; |
|
16681 | 89 |
|
23770 | 90 |
(*dummy implementation*) |
91 |
fun makestring x = "dummy string for SML New Jersey"; |
|
92 |
||
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
93 |
|
24290 | 94 |
(* toplevel pretty printing (see also Pure/pure_setup.ML) *) |
4403 | 95 |
|
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
96 |
fun make_pp path pprint = |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
97 |
let |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
98 |
open PrettyPrint; |
4403 | 99 |
|
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
100 |
fun pp pps obj = |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
101 |
pprint obj |
24145 | 102 |
(string pps, openHOVBox pps o Rel o dest_int, |
103 |
fn wd => break pps {nsp=dest_int wd, offset=0}, fn () => newline pps, |
|
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
104 |
fn () => closeBox pps); |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
105 |
in (path, pp) end; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
106 |
|
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
107 |
fun install_pp (path, pp) = CompilerPPTable.install_pp path pp; |
4403 | 108 |
|
109 |
||
110 |
(* ML command execution *) |
|
111 |
||
24599
7b0ecf9a9055
use_text/file: tune text (cf. ML_Parse.fix_ints);
wenzelm
parents:
24329
diff
changeset
|
112 |
fun use_text (tune: string -> string) name (print, err) verbose txt = |
5090 | 113 |
let |
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
114 |
val ref out_orig = Control.Print.out; |
5090 | 115 |
|
116 |
val out_buffer = ref ([]: string list); |
|
117 |
val out = {say = (fn s => out_buffer := s :: ! out_buffer), flush = (fn () => ())}; |
|
10914 | 118 |
fun output () = |
7890 | 119 |
let val str = implode (rev (! out_buffer)) |
10914 | 120 |
in String.substring (str, 0, Int.max (0, size str - 1)) end; |
5090 | 121 |
in |
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
122 |
Control.Print.out := out; |
24599
7b0ecf9a9055
use_text/file: tune text (cf. ML_Parse.fix_ints);
wenzelm
parents:
24329
diff
changeset
|
123 |
Backend.Interact.useStream (TextIO.openString (tune txt)) handle exn => |
22144 | 124 |
(Control.Print.out := out_orig; |
125 |
err ((if name = "" then "" else "Error in " ^ name ^ "\n") ^ output ()); raise exn); |
|
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
126 |
Control.Print.out := out_orig; |
10914 | 127 |
if verbose then print (output ()) else () |
5090 | 128 |
end; |
4403 | 129 |
|
24599
7b0ecf9a9055
use_text/file: tune text (cf. ML_Parse.fix_ints);
wenzelm
parents:
24329
diff
changeset
|
130 |
fun use_file tune output verbose name = |
7b0ecf9a9055
use_text/file: tune text (cf. ML_Parse.fix_ints);
wenzelm
parents:
24329
diff
changeset
|
131 |
let |
7b0ecf9a9055
use_text/file: tune text (cf. ML_Parse.fix_ints);
wenzelm
parents:
24329
diff
changeset
|
132 |
val instream = TextIO.openIn name; |
7b0ecf9a9055
use_text/file: tune text (cf. ML_Parse.fix_ints);
wenzelm
parents:
24329
diff
changeset
|
133 |
val txt = TextIO.inputAll instream before TextIO.closeIn instream; |
7b0ecf9a9055
use_text/file: tune text (cf. ML_Parse.fix_ints);
wenzelm
parents:
24329
diff
changeset
|
134 |
in use_text tune name output verbose txt end; |
21770 | 135 |
|
136 |
||
4403 | 137 |
|
5816 | 138 |
(** interrupts **) |
139 |
||
12990 | 140 |
exception Interrupt; |
141 |
||
26084
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
142 |
local |
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
143 |
|
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
144 |
fun change_signal new_handler f x = |
5816 | 145 |
let |
26084
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
146 |
val old_handler = Signals.setHandler (Signals.sigINT, new_handler); |
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
147 |
val result = Exn.capture (f old_handler) x; |
12990 | 148 |
val _ = Signals.setHandler (Signals.sigINT, old_handler); |
23965
f93e509659c1
ML-Systems/exn.ML, ML-Systems/multithreading_dummy.ML;
wenzelm
parents:
23921
diff
changeset
|
149 |
in Exn.release result end; |
5816 | 150 |
|
26084
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
151 |
in |
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
152 |
|
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
153 |
fun interruptible (f: 'a -> 'b) x = |
12990 | 154 |
let |
26084
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
155 |
val result = ref (Exn.Exn Interrupt: 'b Exn.result); |
12990 | 156 |
val old_handler = Signals.inqHandler Signals.sigINT; |
5816 | 157 |
in |
12990 | 158 |
SMLofNJ.Cont.callcc (fn cont => |
26084
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
159 |
(Signals.setHandler (Signals.sigINT, Signals.HANDLER (fn _ => cont)); |
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
160 |
result := Exn.capture f x)); |
12990 | 161 |
Signals.setHandler (Signals.sigINT, old_handler); |
26084
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
162 |
Exn.release (! result) |
12990 | 163 |
end; |
5816 | 164 |
|
26084
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
165 |
fun uninterruptible f = |
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
166 |
change_signal Signals.IGNORE |
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
167 |
(fn old_handler => f (fn g => change_signal old_handler (fn _ => g))); |
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
168 |
|
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
169 |
end; |
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
170 |
|
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
171 |
|
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
172 |
(* basis library fixes *) |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
173 |
|
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
174 |
structure TextIO = |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
175 |
struct |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
176 |
open TextIO; |
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22144
diff
changeset
|
177 |
fun inputLine is = TextIO.inputLine is |
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
178 |
handle IO.Io _ => raise Interrupt; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
179 |
end; |
17511 | 180 |
|
18790
418131f631fc
interrupt_timeout now raises Interrupt instead of SML90.Interrupt
webertj
parents:
18760
diff
changeset
|
181 |
|
16542 | 182 |
(** Signal handling: emulation of the Poly/ML Signal structure. Note that types |
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
183 |
Posix.Signal.signal and Signals.signal differ **) |
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
184 |
|
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
185 |
structure IsaSignal = |
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
186 |
struct |
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
187 |
|
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
188 |
datatype sig_handle = SIG_DFL | SIG_IGN | SIG_HANDLE of Signals.signal -> unit; |
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
189 |
|
16542 | 190 |
(*From the SML/NJ documentation: "HANDLER(f) installs a handler for a |
191 |
signal. When signal is delivered to the process, the execution state |
|
192 |
of the current thread will be bundled up as a continuation k, then |
|
193 |
f(signal,n,k) will be called. The number n is the number of times |
|
194 |
signal has been signalled since the last time f was invoked for it."*) |
|
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
195 |
|
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
196 |
fun toAction SIG_DFL = Signals.DEFAULT |
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
197 |
| toAction SIG_IGN = Signals.IGNORE |
16542 | 198 |
| toAction (SIG_HANDLE iu) = |
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
199 |
Signals.HANDLER (fn (signo,_,cont) => (iu signo; cont)); |
16542 | 200 |
|
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
201 |
(*The types are correct, but I'm not sure about the semantics!*) |
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
202 |
fun fromAction Signals.DEFAULT = SIG_DFL |
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
203 |
| fromAction Signals.IGNORE = SIG_IGN |
16542 | 204 |
| fromAction (Signals.HANDLER f) = |
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
205 |
SIG_HANDLE (fn signo => SMLofNJ.Cont.callcc (fn k => (f (signo,0,k); ()))); |
16542 | 206 |
|
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
207 |
(*Poly/ML version has type int * sig_handle -> sig_handle*) |
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
208 |
fun signal (signo, sh) = fromAction (Signals.setHandler (signo, toAction sh)); |
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
209 |
|
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
210 |
val usr1 = UnixSignals.sigUSR1 |
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
211 |
val usr2 = UnixSignals.sigUSR2 |
17763 | 212 |
val alrm = UnixSignals.sigALRM |
213 |
val chld = UnixSignals.sigCHLD |
|
214 |
val cont = UnixSignals.sigCONT |
|
215 |
val int = UnixSignals.sigINT |
|
216 |
val quit = UnixSignals.sigQUIT |
|
217 |
val term = UnixSignals.sigTERM |
|
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
218 |
|
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
14981
diff
changeset
|
219 |
end; |
5816 | 220 |
|
221 |
||
4403 | 222 |
(** OS related **) |
223 |
||
23826
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23770
diff
changeset
|
224 |
(* current directory *) |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23770
diff
changeset
|
225 |
|
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23770
diff
changeset
|
226 |
val cd = OS.FileSys.chDir; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23770
diff
changeset
|
227 |
val pwd = OS.FileSys.getDir; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23770
diff
changeset
|
228 |
|
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23770
diff
changeset
|
229 |
|
4403 | 230 |
(* system command execution *) |
231 |
||
232 |
(*execute Unix command which doesn't take any input from stdin and |
|
233 |
sends its output to stdout; could be done more easily by Unix.execute, |
|
234 |
but that function doesn't use the PATH*) |
|
235 |
fun execute command = |
|
236 |
let |
|
237 |
val tmp_name = OS.FileSys.tmpName (); |
|
238 |
val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name); |
|
239 |
val result = TextIO.inputAll is; |
|
240 |
in |
|
241 |
TextIO.closeIn is; |
|
242 |
OS.FileSys.remove tmp_name; |
|
243 |
result |
|
244 |
end; |
|
245 |
||
7855 | 246 |
(*plain version; with return code*) |
24145 | 247 |
val system = mk_int o OS.Process.system; |
7855 | 248 |
|
4403 | 249 |
|
17824 | 250 |
(*Convert a process ID to a decimal string (chiefly for tracing)*) |
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
18790
diff
changeset
|
251 |
fun string_of_pid pid = |
17824 | 252 |
Word.fmt StringCvt.DEC (Word.fromLargeWord (Posix.Process.pidToWord pid)); |
253 |
||
254 |
||
4403 | 255 |
(* getenv *) |
256 |
||
257 |
fun getenv var = |
|
258 |
(case OS.Process.getEnv var of |
|
259 |
NONE => "" |
|
260 |
| SOME txt => txt); |