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 |
|
4506
|
30 |
|
3594
|
31 |
(* timing *)
|
2413
|
32 |
|
4506
|
33 |
(*Note start point for timing*)
|
|
34 |
fun startTiming() = System.Timer.start_timer();
|
|
35 |
|
|
36 |
(*Finish timing and return string*)
|
3594
|
37 |
local
|
3631
|
38 |
(*print microseconds, suppressing trailing zeroes*)
|
|
39 |
fun umakestring 0 = ""
|
|
40 |
| umakestring n =
|
|
41 |
chr (ord "0" + n div 100000) ^ umakestring (10 * (n mod 100000));
|
4506
|
42 |
|
|
43 |
fun string_of_time (System.Timer.TIME {sec, usec}) =
|
|
44 |
makestring sec ^ "." ^ (if usec=0 then "0" else umakestring usec)
|
|
45 |
|
3594
|
46 |
in
|
4506
|
47 |
|
|
48 |
fun endTiming start =
|
|
49 |
let val nongc = System.Timer.check_timer(start)
|
|
50 |
and gc = System.Timer.check_timer_gc(start);
|
|
51 |
val both = System.Timer.add_time(nongc, gc)
|
|
52 |
in "Non GC " ^ string_of_time nongc ^
|
|
53 |
" GC " ^ string_of_time gc ^
|
|
54 |
" both "^ string_of_time both ^ " secs\n"
|
|
55 |
end
|
3594
|
56 |
end;
|
|
57 |
|
|
58 |
|
4977
|
59 |
(* prompts *)
|
|
60 |
|
|
61 |
fun ml_prompts p1 p2 = ();
|
4506
|
62 |
|
|
63 |
|
3594
|
64 |
(* toplevel pretty printing (see also Pure/install_pp.ML) *)
|
2413
|
65 |
|
|
66 |
fun make_pp path pprint =
|
|
67 |
let
|
|
68 |
open System.PrettyPrint;
|
|
69 |
|
|
70 |
fun pp pps obj =
|
|
71 |
pprint obj
|
|
72 |
(add_string pps, begin_block pps INCONSISTENT,
|
|
73 |
fn wd => add_break pps (wd, 0), fn () => add_newline pps,
|
|
74 |
fn () => end_block pps);
|
|
75 |
in
|
|
76 |
(path, pp)
|
|
77 |
end;
|
|
78 |
|
|
79 |
fun install_pp (path, pp) = System.PrettyPrint.install_pp path pp;
|
|
80 |
|
|
81 |
|
3594
|
82 |
(* ML command execution *)
|
2413
|
83 |
|
5090
|
84 |
fun use_text _ = System.Compile.use_stream o open_string;
|
3594
|
85 |
|
2413
|
86 |
|
|
87 |
|
3594
|
88 |
(** OS related **)
|
2413
|
89 |
|
3594
|
90 |
(* system command execution *)
|
2413
|
91 |
|
3594
|
92 |
(*execute Unix command which doesn't take any input from stdin and
|
|
93 |
sends its output to stdout; could be done more easily by IO.execute,
|
|
94 |
but that function seems to be buggy in SML/NJ 0.93*)
|
|
95 |
fun execute command =
|
|
96 |
let
|
4494
|
97 |
val tmp_name = "/tmp/isabelle-execute";
|
3594
|
98 |
val is = (System.system (command ^ " > " ^ tmp_name); open_in tmp_name);
|
|
99 |
val result = input (is, 999999);
|
|
100 |
in
|
|
101 |
close_in is;
|
|
102 |
System.Unsafe.SysIO.unlink tmp_name;
|
|
103 |
result
|
|
104 |
end;
|
2413
|
105 |
|
|
106 |
|
3594
|
107 |
(* file handling *)
|
2413
|
108 |
|
|
109 |
(*Get time of last modification; if file doesn't exist return an empty string*)
|
|
110 |
local
|
3594
|
111 |
open System.Timer System.Unsafe.SysIO;
|
2413
|
112 |
in
|
|
113 |
fun file_info "" = ""
|
3594
|
114 |
| file_info name = makestring (mtime (PATH name)) handle _ => "";
|
2413
|
115 |
end;
|
|
116 |
|
|
117 |
structure OS =
|
3594
|
118 |
struct
|
2413
|
119 |
structure FileSys =
|
3594
|
120 |
struct
|
|
121 |
val chDir = System.Directory.cd;
|
|
122 |
val remove = System.Unsafe.SysIO.unlink;
|
|
123 |
val getDir = System.Directory.getWD;
|
2413
|
124 |
end;
|
3594
|
125 |
end;
|
2413
|
126 |
|
3594
|
127 |
(*redefine to flush its output immediately -- temporary patch suggested
|
|
128 |
by Kim Dam Petersen*) (* FIXME !? *)
|
|
129 |
val output = fn (s, t) => (output (s, t); flush_out s);
|
2413
|
130 |
|
|
131 |
|
3594
|
132 |
(* getenv *)
|
2413
|
133 |
|
3594
|
134 |
local
|
|
135 |
fun drop_last [] = []
|
|
136 |
| drop_last [x] = []
|
|
137 |
| drop_last (x :: xs) = x :: drop_last xs;
|
2413
|
138 |
|
3594
|
139 |
val drop_last_char = implode o drop_last o explode;
|
|
140 |
in
|
|
141 |
fun getenv var = drop_last_char
|
|
142 |
(execute ("env | grep '^" ^ var ^ "=' | sed -e 's/" ^ var ^ "=//'"));
|
|
143 |
end;
|
2413
|
144 |
|
|
145 |
|
4428
|
146 |
(* non-ASCII input (see also Thy/use.ML) *)
|
2413
|
147 |
|
|
148 |
val needs_filtered_use = false;
|