author | wenzelm |
Sun, 16 Sep 2007 14:52:32 +0200 | |
changeset 24597 | cbf2c5cf335e |
parent 24329 | f31594168d27 |
child 24688 | a5754ca5c510 |
permissions | -rw-r--r-- |
22563 | 1 |
(* Title: Pure/ML-Systems/alice.ML |
2 |
ID: $Id$ |
|
3 |
||
22837 | 4 |
Compatibility file for Alice 1.4. |
23826
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
5 |
|
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
6 |
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
|
7 |
|
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
8 |
$ cd Isabelle/src/Pure |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
9 |
$ env ALICE_JIT_MODE=0 alice |
23835 | 10 |
- val ml_system = "alice"; |
23826
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
11 |
- use "ML-Systems/alice.ML"; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
12 |
- use "ROOT.ML"; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
13 |
- Session.finish (); |
22563 | 14 |
*) |
15 |
||
24597 | 16 |
val ml_system_fix_ints = false; |
17 |
||
23965
f93e509659c1
ML-Systems/exn.ML, ML-Systems/multithreading_dummy.ML;
wenzelm
parents:
23921
diff
changeset
|
18 |
use "ML-Systems/exn.ML"; |
f93e509659c1
ML-Systems/exn.ML, ML-Systems/multithreading_dummy.ML;
wenzelm
parents:
23921
diff
changeset
|
19 |
use "ML-Systems/multithreading_dummy.ML"; |
23921
947152add153
added compatibility file for ML systems without multithreading;
wenzelm
parents:
23835
diff
changeset
|
20 |
|
947152add153
added compatibility file for ML systems without multithreading;
wenzelm
parents:
23835
diff
changeset
|
21 |
|
22563 | 22 |
fun exit 0 = (OS.Process.exit OS.Process.success): unit |
23 |
| exit _ = OS.Process.exit OS.Process.failure; |
|
24 |
||
25 |
||
26 |
(** ML system related **) |
|
27 |
||
28 |
(*low-level pointer equality*) |
|
29 |
fun pointer_eq (_: 'a, _: 'a) = false; |
|
30 |
||
31 |
||
32 |
(* restore old-style character / string functions *) |
|
33 |
||
34 |
exception Ord; |
|
35 |
fun ord "" = raise Ord |
|
36 |
| ord s = Char.ord (String.sub (s, 0)); |
|
37 |
||
22575 | 38 |
val chr = String.str o chr; |
39 |
val explode = map String.str o String.explode; |
|
22563 | 40 |
val implode = String.concat; |
41 |
||
42 |
||
43 |
(* Poly/ML emulation *) |
|
44 |
||
45 |
fun quit () = exit 0; |
|
46 |
||
24329 | 47 |
fun get_print_depth () = ! Print.depth; |
22563 | 48 |
fun print_depth n = Print.depth := n; |
49 |
||
50 |
||
51 |
(* compiler-independent timing functions *) |
|
52 |
||
53 |
structure Timer = |
|
54 |
struct |
|
55 |
open Timer; |
|
56 |
type cpu_timer = unit; |
|
57 |
fun startCPUTimer () = (); |
|
58 |
fun checkCPUTimer () = {sys = Time.zeroTime, usr = Time.zeroTime}; |
|
59 |
fun checkGCTime () = Time.zeroTime; |
|
60 |
end; |
|
61 |
||
62 |
fun start_timing () = |
|
63 |
let val CPUtimer = Timer.startCPUTimer(); |
|
64 |
val time = Timer.checkCPUTimer(CPUtimer) |
|
65 |
in (CPUtimer,time) end; |
|
66 |
||
67 |
fun end_timing (CPUtimer, {sys,usr}) = |
|
68 |
let open Time (*...for Time.toString, Time.+ and Time.- *) |
|
69 |
val {sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer) |
|
70 |
in "User " ^ toString (usr2-usr) ^ |
|
71 |
" All "^ toString (sys2-sys + usr2-usr) ^ |
|
72 |
" secs" |
|
73 |
handle Time => "" |
|
74 |
end; |
|
75 |
||
76 |
fun check_timer timer = |
|
77 |
let |
|
78 |
val {sys, usr} = Timer.checkCPUTimer timer; |
|
79 |
val gc = Timer.checkGCTime timer; (* FIXME already included in usr? *) |
|
80 |
in (sys, usr, gc) end; |
|
81 |
||
82 |
||
83 |
(*prompts*) |
|
84 |
fun ml_prompts p1 p2 = (); |
|
85 |
||
86 |
(*dummy implementation*) |
|
87 |
fun profile (n: int) f x = f x; |
|
88 |
||
89 |
(*dummy implementation*) |
|
90 |
fun exception_trace f = f (); |
|
91 |
||
92 |
(*dummy implementation*) |
|
93 |
fun print x = x; |
|
94 |
||
95 |
||
24290 | 96 |
(* toplevel pretty printing (see also Pure/pure_setup.ML) *) |
22563 | 97 |
|
98 |
fun make_pp path pprint = (path, pprint); |
|
99 |
fun install_pp (path, pp) = (); |
|
100 |
||
101 |
||
102 |
(* ML command execution *) |
|
103 |
||
104 |
fun use_text name (print, err) verbose txt = (Compiler.eval txt; ()); |
|
105 |
||
106 |
fun use_file _ _ name = use name; |
|
107 |
||
108 |
||
109 |
||
110 |
(** interrupts **) |
|
111 |
||
112 |
exception Interrupt; |
|
113 |
||
114 |
fun ignore_interrupt f x = f x; |
|
115 |
fun raise_interrupt f x = f x; |
|
116 |
||
117 |
||
118 |
(* basis library fixes *) |
|
119 |
||
120 |
structure TextIO = |
|
121 |
struct |
|
122 |
open TextIO; |
|
23139
aa899bce7c3b
TextIO.inputLine: use present SML B library version;
wenzelm
parents:
22837
diff
changeset
|
123 |
fun inputLine is = TextIO.inputLine is |
22563 | 124 |
handle IO.Io _ => raise Interrupt; |
125 |
end; |
|
126 |
||
127 |
||
128 |
(* bounded time execution *) |
|
129 |
||
130 |
(*dummy implementation*) |
|
131 |
fun interrupt_timeout time f x = |
|
132 |
f x; |
|
133 |
||
134 |
||
135 |
||
136 |
(** OS related **) |
|
137 |
||
23826
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
138 |
(* current directory *) |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
139 |
|
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
140 |
val cd = OS.FileSys.chDir; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
141 |
val pwd = OS.FileSys.getDir; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
142 |
|
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
23139
diff
changeset
|
143 |
|
22563 | 144 |
(* system command execution *) |
145 |
||
146 |
(*execute Unix command which doesn't take any input from stdin and |
|
147 |
sends its output to stdout; could be done more easily by Unix.execute, |
|
148 |
but that function doesn't use the PATH*) |
|
149 |
fun execute command = |
|
150 |
let |
|
151 |
val tmp_name = OS.FileSys.tmpName (); |
|
152 |
val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name); |
|
153 |
val result = TextIO.inputAll is; |
|
154 |
in |
|
155 |
TextIO.closeIn is; |
|
156 |
OS.FileSys.remove tmp_name; |
|
157 |
result |
|
158 |
end; |
|
159 |
||
160 |
(*plain version; with return code*) |
|
161 |
val system = OS.Process.system: string -> int; |
|
162 |
||
163 |
structure OS = |
|
164 |
struct |
|
165 |
open OS; |
|
166 |
structure FileSys = |
|
167 |
struct |
|
168 |
fun fileId name = |
|
169 |
(case execute ("perl -e '@_ = stat(q:" ^ name ^ ":); print $_[1]'") of |
|
170 |
"" => raise Fail "OS.FileSys.fileId" (* FIXME IO.Io!? *) |
|
171 |
| s => (case Int.fromString s of NONE => raise Fail "OS.FileSys.fileId" | SOME i => i)); |
|
172 |
val compare = Int.compare; |
|
173 |
open FileSys; |
|
174 |
end; |
|
175 |
end; |
|
176 |
||
177 |
||
178 |
(* getenv *) |
|
179 |
||
180 |
fun getenv var = |
|
181 |
(case OS.Process.getEnv var of |
|
182 |
NONE => "" |
|
183 |
| SOME txt => txt); |