author | haftmann |
Mon, 16 Feb 2009 19:11:55 +0100 | |
changeset 29940 | 83b373f61d41 |
parent 29564 | f8b933a62151 |
permissions | -rw-r--r-- |
22563 | 1 |
(* Title: Pure/ML-Systems/alice.ML |
2 |
||
22837 | 3 |
Compatibility file for Alice 1.4. |
23826
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
4 |
|
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
5 |
NOTE: there is no wrapper script; may run it interactively as follows: |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
6 |
|
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
7 |
$ cd Isabelle/src/Pure |
27004 | 8 |
$ env ALICE_JIT_MODE=0 ISABELLE_HOME=$(cd ../..; pwd) alice |
23835 | 9 |
- val ml_system = "alice"; |
24807 | 10 |
- use "ML-Systems/exn.ML"; |
26226 | 11 |
- use "ML-Systems/universal.ML"; |
24807 | 12 |
- use "ML-Systems/multithreading.ML"; |
13 |
- use "ML-Systems/time_limit.ML"; |
|
23826
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
14 |
- use "ML-Systems/alice.ML"; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
15 |
- use "ROOT.ML"; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
16 |
- Session.finish (); |
22563 | 17 |
*) |
18 |
||
24597 | 19 |
val ml_system_fix_ints = false; |
20 |
||
26474 | 21 |
fun forget_structure _ = (); |
22 |
||
22563 | 23 |
fun exit 0 = (OS.Process.exit OS.Process.success): unit |
24 |
| exit _ = OS.Process.exit OS.Process.failure; |
|
25 |
||
26 |
||
27 |
(** ML system related **) |
|
28 |
||
29 |
(*low-level pointer equality*) |
|
30 |
fun pointer_eq (_: 'a, _: 'a) = false; |
|
31 |
||
24809
41a21f59f74d
integer compatibility: added wrapper for structure Time;
wenzelm
parents:
24807
diff
changeset
|
32 |
|
41a21f59f74d
integer compatibility: added wrapper for structure Time;
wenzelm
parents:
24807
diff
changeset
|
33 |
(* integer compatibility -- downgraded IntInf *) |
41a21f59f74d
integer compatibility: added wrapper for structure Time;
wenzelm
parents:
24807
diff
changeset
|
34 |
|
41a21f59f74d
integer compatibility: added wrapper for structure Time;
wenzelm
parents:
24807
diff
changeset
|
35 |
structure Time = |
41a21f59f74d
integer compatibility: added wrapper for structure Time;
wenzelm
parents:
24807
diff
changeset
|
36 |
struct |
41a21f59f74d
integer compatibility: added wrapper for structure Time;
wenzelm
parents:
24807
diff
changeset
|
37 |
open Time; |
41a21f59f74d
integer compatibility: added wrapper for structure Time;
wenzelm
parents:
24807
diff
changeset
|
38 |
val fromMilliseconds = Time.fromMilliseconds o IntInf.fromInt; |
41a21f59f74d
integer compatibility: added wrapper for structure Time;
wenzelm
parents:
24807
diff
changeset
|
39 |
val fromSeconds = Time.fromSeconds o IntInf.fromInt; |
41a21f59f74d
integer compatibility: added wrapper for structure Time;
wenzelm
parents:
24807
diff
changeset
|
40 |
end; |
41a21f59f74d
integer compatibility: added wrapper for structure Time;
wenzelm
parents:
24807
diff
changeset
|
41 |
|
24807 | 42 |
structure IntInf = |
43 |
struct |
|
44 |
fun divMod (x, y) = (x div y, x mod y); |
|
45 |
open Int; |
|
46 |
end; |
|
47 |
||
22563 | 48 |
|
49 |
(* restore old-style character / string functions *) |
|
50 |
||
51 |
exception Ord; |
|
52 |
fun ord "" = raise Ord |
|
53 |
| ord s = Char.ord (String.sub (s, 0)); |
|
54 |
||
22575 | 55 |
val chr = String.str o chr; |
56 |
val explode = map String.str o String.explode; |
|
22563 | 57 |
val implode = String.concat; |
58 |
||
59 |
||
60 |
(* Poly/ML emulation *) |
|
61 |
||
62 |
fun quit () = exit 0; |
|
63 |
||
24329 | 64 |
fun get_print_depth () = ! Print.depth; |
22563 | 65 |
fun print_depth n = Print.depth := n; |
66 |
||
67 |
||
68 |
(* compiler-independent timing functions *) |
|
69 |
||
70 |
structure Timer = |
|
71 |
struct |
|
72 |
open Timer; |
|
73 |
type cpu_timer = unit; |
|
74 |
fun startCPUTimer () = (); |
|
75 |
fun checkCPUTimer () = {sys = Time.zeroTime, usr = Time.zeroTime}; |
|
76 |
fun checkGCTime () = Time.zeroTime; |
|
77 |
end; |
|
78 |
||
79 |
fun start_timing () = |
|
80 |
let val CPUtimer = Timer.startCPUTimer(); |
|
81 |
val time = Timer.checkCPUTimer(CPUtimer) |
|
82 |
in (CPUtimer,time) end; |
|
83 |
||
84 |
fun end_timing (CPUtimer, {sys,usr}) = |
|
85 |
let open Time (*...for Time.toString, Time.+ and Time.- *) |
|
86 |
val {sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer) |
|
87 |
in "User " ^ toString (usr2-usr) ^ |
|
88 |
" All "^ toString (sys2-sys + usr2-usr) ^ |
|
89 |
" secs" |
|
90 |
handle Time => "" |
|
91 |
end; |
|
92 |
||
93 |
fun check_timer timer = |
|
94 |
let |
|
95 |
val {sys, usr} = Timer.checkCPUTimer timer; |
|
96 |
val gc = Timer.checkGCTime timer; (* FIXME already included in usr? *) |
|
97 |
in (sys, usr, gc) end; |
|
98 |
||
99 |
||
100 |
(*prompts*) |
|
101 |
fun ml_prompts p1 p2 = (); |
|
102 |
||
103 |
(*dummy implementation*) |
|
104 |
fun profile (n: int) f x = f x; |
|
105 |
||
106 |
(*dummy implementation*) |
|
107 |
fun exception_trace f = f (); |
|
108 |
||
109 |
(*dummy implementation*) |
|
110 |
fun print x = x; |
|
111 |
||
112 |
||
24290 | 113 |
(* toplevel pretty printing (see also Pure/pure_setup.ML) *) |
22563 | 114 |
|
115 |
fun make_pp path pprint = (path, pprint); |
|
116 |
fun install_pp (path, pp) = (); |
|
117 |
||
118 |
||
119 |
(* ML command execution *) |
|
120 |
||
26884 | 121 |
fun use_text _ _ _ _ _ txt = (Compiler.eval txt; ()); |
122 |
fun use_file _ _ _ _ name = use name; |
|
22563 | 123 |
|
124 |
||
125 |
||
126 |
(** interrupts **) |
|
127 |
||
128 |
exception Interrupt; |
|
129 |
||
26084
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
24809
diff
changeset
|
130 |
fun interruptible f x = f x; |
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
24809
diff
changeset
|
131 |
fun uninterruptible f x = f (fn (g: 'c -> 'd) => g) x; |
22563 | 132 |
|
133 |
||
134 |
(* basis library fixes *) |
|
135 |
||
136 |
structure TextIO = |
|
137 |
struct |
|
138 |
open TextIO; |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22837
diff
changeset
|
139 |
fun inputLine is = TextIO.inputLine is |
22563 | 140 |
handle IO.Io _ => raise Interrupt; |
141 |
end; |
|
142 |
||
143 |
||
144 |
||
145 |
(** OS related **) |
|
146 |
||
27004 | 147 |
structure OS = |
148 |
struct |
|
149 |
open OS; |
|
150 |
structure FileSys = |
|
151 |
struct |
|
152 |
open FileSys; |
|
153 |
fun tmpName () = |
|
154 |
let val name = FileSys.tmpName () in |
|
155 |
if String.isSuffix "\000" name |
|
156 |
then String.substring (name, 0, size name - 1) |
|
157 |
else name |
|
158 |
end; |
|
159 |
end; |
|
160 |
end; |
|
161 |
||
23826
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
162 |
val cd = OS.FileSys.chDir; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
163 |
val pwd = OS.FileSys.getDir; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
164 |
|
26226 | 165 |
local |
166 |
||
167 |
fun read_file name = |
|
168 |
let val is = TextIO.openIn name |
|
26504 | 169 |
in Exn.release (Exn.capture TextIO.inputAll is before TextIO.closeIn is) end; |
26226 | 170 |
|
171 |
fun write_file name txt = |
|
172 |
let val os = TextIO.openOut name |
|
26504 | 173 |
in Exn.release (Exn.capture TextIO.output (os, txt) before TextIO.closeOut os) end; |
26226 | 174 |
|
175 |
in |
|
176 |
||
177 |
fun system_out script = |
|
178 |
let |
|
179 |
val script_name = OS.FileSys.tmpName (); |
|
180 |
val _ = write_file script_name script; |
|
181 |
||
182 |
val output_name = OS.FileSys.tmpName (); |
|
183 |
||
184 |
val status = |
|
185 |
OS.Process.system ("perl -w \"$ISABELLE_HOME/lib/scripts/system.pl\" nogroup " ^ |
|
186 |
script_name ^ " /dev/null " ^ output_name); |
|
187 |
val rc = if OS.Process.isSuccess status then 0 else 1; |
|
188 |
||
189 |
val output = read_file output_name handle IO.Io _ => ""; |
|
190 |
val _ = OS.FileSys.remove script_name handle OS.SysErr _ => (); |
|
191 |
val _ = OS.FileSys.remove output_name handle OS.SysErr _ => (); |
|
192 |
in (output, rc) end; |
|
193 |
||
194 |
end; |
|
22563 | 195 |
|
196 |
structure OS = |
|
197 |
struct |
|
198 |
open OS; |
|
199 |
structure FileSys = |
|
200 |
struct |
|
201 |
fun fileId name = |
|
26226 | 202 |
(case system_out ("perl -e '@_ = stat(q:" ^ name ^ ":); print $_[1]'") of |
203 |
("", _) => raise Fail "OS.FileSys.fileId" (* FIXME IO.Io!? *) |
|
204 |
| (s, _) => (case Int.fromString s of NONE => raise Fail "OS.FileSys.fileId" | SOME i => i)); |
|
22563 | 205 |
val compare = Int.compare; |
27004 | 206 |
fun fullPath name = |
207 |
(case system_out ("FILE='" ^ name ^ |
|
208 |
"' && cd \"$(dirname \"$FILE\")\" && echo -n \"$(pwd -P)/$(basename \"$FILE\")\"") of |
|
209 |
("", _) => raise SysErr ("Bad file", NONE) |
|
210 |
| (s, _) => s); |
|
22563 | 211 |
open FileSys; |
212 |
end; |
|
213 |
end; |
|
214 |
||
28488
18fea7e88ea1
removed obsolete Posix/Signal compatibility wrappers;
wenzelm
parents:
27004
diff
changeset
|
215 |
fun process_id () = raise Fail "process_id undefined"; |
26227 | 216 |
|
22563 | 217 |
fun getenv var = |
218 |
(case OS.Process.getEnv var of |
|
219 |
NONE => "" |
|
220 |
| SOME txt => txt); |