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