2413
|
1 |
(* Title: Pure/ML-Systems/smlnj-0.93.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Carsten Clasohm, TU Muenchen
|
|
4 |
Copyright 1996 TU Muenchen
|
|
5 |
|
|
6 |
Compatibility file for Standard ML of New Jersey version 0.93.
|
|
7 |
*)
|
|
8 |
|
3594
|
9 |
(*needs the Basis Library emulation*)
|
|
10 |
use "basis.ML";
|
2413
|
11 |
|
|
12 |
|
3594
|
13 |
(** ML system related **)
|
|
14 |
|
|
15 |
(* New Jersey ML parameters *)
|
|
16 |
|
|
17 |
System.Control.Runtime.gcmessages := 0;
|
|
18 |
|
|
19 |
|
|
20 |
(* Poly/ML emulation *)
|
2413
|
21 |
|
|
22 |
fun quit () = exit 0;
|
|
23 |
|
3594
|
24 |
(*limit the printing depth -- divided by 2 for comparibility with Poly/ML*)
|
|
25 |
fun print_depth n =
|
|
26 |
(System.Control.Print.printDepth := n div 2;
|
|
27 |
System.Control.Print.printLength := n);
|
|
28 |
|
|
29 |
|
|
30 |
(* timing *)
|
2413
|
31 |
|
3594
|
32 |
local
|
|
33 |
(*print microseconds, suppressing trailing zeroes*)
|
|
34 |
fun umakestring 0 = ""
|
|
35 |
| umakestring n =
|
|
36 |
chr (ord "0" + n div 100000) ^ umakestring (10 * (n mod 100000));
|
|
37 |
in
|
|
38 |
(*a conditional timing function: applies f to () and, if the flag is true,
|
|
39 |
prints its runtime*)
|
|
40 |
fun cond_timeit flag f =
|
|
41 |
if flag then
|
|
42 |
let fun string_of_time (System.Timer.TIME {sec, usec}) =
|
|
43 |
makestring sec ^ "." ^ (if usec=0 then "0" else umakestring usec)
|
|
44 |
open System.Timer;
|
|
45 |
val start = start_timer()
|
|
46 |
val result = f();
|
|
47 |
val nongc = check_timer(start)
|
|
48 |
and gc = check_timer_gc(start);
|
|
49 |
val both = add_time(nongc, gc)
|
|
50 |
in print("Non GC " ^ string_of_time nongc ^
|
|
51 |
" GC " ^ string_of_time gc ^
|
|
52 |
" both "^ string_of_time both ^ " secs\n");
|
|
53 |
result
|
|
54 |
end
|
|
55 |
else f();
|
|
56 |
end;
|
|
57 |
|
|
58 |
|
|
59 |
(* toplevel pretty printing (see also Pure/install_pp.ML) *)
|
2413
|
60 |
|
|
61 |
fun make_pp path pprint =
|
|
62 |
let
|
|
63 |
open System.PrettyPrint;
|
|
64 |
|
|
65 |
fun pp pps obj =
|
|
66 |
pprint obj
|
|
67 |
(add_string pps, begin_block pps INCONSISTENT,
|
|
68 |
fn wd => add_break pps (wd, 0), fn () => add_newline pps,
|
|
69 |
fn () => end_block pps);
|
|
70 |
in
|
|
71 |
(path, pp)
|
|
72 |
end;
|
|
73 |
|
|
74 |
fun install_pp (path, pp) = System.PrettyPrint.install_pp path pp;
|
|
75 |
|
|
76 |
|
3594
|
77 |
(* ML command execution *)
|
2413
|
78 |
|
3594
|
79 |
fun use_string commands =
|
|
80 |
System.Compile.use_stream (open_string (implode commands));
|
|
81 |
|
2413
|
82 |
|
|
83 |
|
3594
|
84 |
(** OS related **)
|
2413
|
85 |
|
3594
|
86 |
(* system command execution *)
|
2413
|
87 |
|
3594
|
88 |
(*execute Unix command which doesn't take any input from stdin and
|
|
89 |
sends its output to stdout; could be done more easily by IO.execute,
|
|
90 |
but that function seems to be buggy in SML/NJ 0.93*)
|
|
91 |
fun execute command =
|
|
92 |
let
|
|
93 |
val tmp_name = "/tmp/.isabelle-execute"; (*let's hope we win the race!*)
|
|
94 |
val is = (System.system (command ^ " > " ^ tmp_name); open_in tmp_name);
|
|
95 |
val result = input (is, 999999);
|
|
96 |
in
|
|
97 |
close_in is;
|
|
98 |
System.Unsafe.SysIO.unlink tmp_name;
|
|
99 |
result
|
|
100 |
end;
|
2413
|
101 |
|
|
102 |
|
3594
|
103 |
(* file handling *)
|
2413
|
104 |
|
|
105 |
(*Get time of last modification; if file doesn't exist return an empty string*)
|
|
106 |
local
|
3594
|
107 |
open System.Timer System.Unsafe.SysIO;
|
2413
|
108 |
in
|
|
109 |
fun file_info "" = ""
|
3594
|
110 |
| file_info name = makestring (mtime (PATH name)) handle _ => "";
|
2413
|
111 |
end;
|
|
112 |
|
|
113 |
structure OS =
|
3594
|
114 |
struct
|
2413
|
115 |
structure FileSys =
|
3594
|
116 |
struct
|
|
117 |
val chDir = System.Directory.cd;
|
|
118 |
val remove = System.Unsafe.SysIO.unlink;
|
|
119 |
val getDir = System.Directory.getWD;
|
2413
|
120 |
end;
|
3594
|
121 |
end;
|
2413
|
122 |
|
3594
|
123 |
(*redefine to flush its output immediately -- temporary patch suggested
|
|
124 |
by Kim Dam Petersen*) (* FIXME !? *)
|
|
125 |
val output = fn (s, t) => (output (s, t); flush_out s);
|
2413
|
126 |
|
|
127 |
|
3594
|
128 |
(* getenv *)
|
2413
|
129 |
|
3594
|
130 |
local
|
|
131 |
fun drop_last [] = []
|
|
132 |
| drop_last [x] = []
|
|
133 |
| drop_last (x :: xs) = x :: drop_last xs;
|
2413
|
134 |
|
3594
|
135 |
val drop_last_char = implode o drop_last o explode;
|
|
136 |
in
|
|
137 |
fun getenv var = drop_last_char
|
|
138 |
(execute ("env | grep '^" ^ var ^ "=' | sed -e 's/" ^ var ^ "=//'"));
|
|
139 |
end;
|
2413
|
140 |
|
|
141 |
|
3594
|
142 |
(* non-ASCII input (see also Thy/symbol_input.ML) *)
|
2413
|
143 |
|
|
144 |
val needs_filtered_use = false;
|