author | wenzelm |
Thu, 06 Mar 2008 20:44:54 +0100 | |
changeset 26223 | f4a1a96cc07c |
parent 26220 | d34b68c21f9a |
child 26474 | 94735cff132c |
permissions | -rw-r--r-- |
9254 | 1 |
(* Title: Pure/ML-Systems/mosml.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1999 University of Cambridge |
|
5 |
||
17491 | 6 |
Compatibility file for Moscow ML 2.01 |
9254 | 7 |
|
17491 | 8 |
NOTE: saving images does not work; may run it interactively as follows: |
9254 | 9 |
|
23826
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
22252
diff
changeset
|
10 |
$ cd Isabelle/src/Pure |
9254 | 11 |
$ isabelle RAW_ML_SYSTEM |
12 |
> val ml_system = "mosml"; |
|
13 |
> use "ML-Systems/mosml.ML"; |
|
14 |
> use "ROOT.ML"; |
|
16470 | 15 |
> Session.finish (); |
23836 | 16 |
> cd "../FOL"; |
16470 | 17 |
> use "ROOT.ML"; |
24808 | 18 |
> Session.finish (); |
19 |
> cd "../ZF"; |
|
20 |
> use "ROOT.ML"; |
|
9254 | 21 |
*) |
22 |
||
23 |
(** ML system related **) |
|
24 |
||
24597 | 25 |
val ml_system_fix_ints = false; |
26 |
||
16517 | 27 |
load "Obj"; |
9254 | 28 |
load "Bool"; |
29 |
load "Int"; |
|
30 |
load "Real"; |
|
31 |
load "ListPair"; |
|
32 |
load "OS"; |
|
33 |
load "Process"; |
|
34 |
load "FileSys"; |
|
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
35 |
load "IO"; |
9254 | 36 |
|
23965
f93e509659c1
ML-Systems/exn.ML, ML-Systems/multithreading_dummy.ML;
wenzelm
parents:
23921
diff
changeset
|
37 |
use "ML-Systems/exn.ML"; |
25732 | 38 |
use "ML-Systems/universal.ML"; |
24688
a5754ca5c510
replaced interrupt_timeout by TimeLimit.timeLimit (available on SML/NJ and Poly/ML 5.1);
wenzelm
parents:
24597
diff
changeset
|
39 |
use "ML-Systems/multithreading.ML"; |
a5754ca5c510
replaced interrupt_timeout by TimeLimit.timeLimit (available on SML/NJ and Poly/ML 5.1);
wenzelm
parents:
24597
diff
changeset
|
40 |
use "ML-Systems/time_limit.ML"; |
23921
947152add153
added compatibility file for ML systems without multithreading;
wenzelm
parents:
23836
diff
changeset
|
41 |
|
947152add153
added compatibility file for ML systems without multithreading;
wenzelm
parents:
23836
diff
changeset
|
42 |
|
16517 | 43 |
(*low-level pointer equality*) |
44 |
local val cast : 'a -> int = Obj.magic |
|
45 |
in fun pointer_eq (x:'a, y:'a) = (cast x = cast y) end; |
|
46 |
||
16469 | 47 |
(*proper implementation available?*) |
48 |
structure IntInf = |
|
49 |
struct |
|
24808 | 50 |
fun divMod (x, y) = (x div y, x mod y); |
16469 | 51 |
open Int; |
52 |
end; |
|
53 |
||
54 |
structure Real = |
|
55 |
struct |
|
56 |
open Real; |
|
57 |
val realFloor = real o floor; |
|
58 |
end; |
|
59 |
||
17491 | 60 |
structure String = |
61 |
struct |
|
62 |
fun isSuffix s1 s2 = |
|
63 |
let val n1 = size s1 and n2 = size s2 |
|
64 |
in if n1 = n2 then s1 = s2 else n1 <= n2 andalso String.substring (s2, n2 - n1, n1) = s1 end; |
|
65 |
open String; |
|
66 |
end; |
|
67 |
||
16469 | 68 |
structure Time = |
69 |
struct |
|
70 |
open Time; |
|
71 |
fun toString t = Time.toString t |
|
72 |
handle Overflow => Real.toString (Time.toReal t); (*workaround Y2004 bug*) |
|
73 |
end; |
|
74 |
||
9254 | 75 |
structure OS = |
16469 | 76 |
struct |
9254 | 77 |
open OS |
78 |
structure Process = Process |
|
79 |
structure FileSys = FileSys |
|
16469 | 80 |
end; |
16993 | 81 |
|
22252 | 82 |
exception Option = Option.Option; |
83 |
||
84 |
||
9254 | 85 |
(*limit the printing depth*) |
24329 | 86 |
local |
87 |
val depth = ref 10; |
|
88 |
in |
|
89 |
fun get_print_depth () = ! depth; |
|
90 |
fun print_depth n = |
|
91 |
(depth := n; |
|
92 |
Meta.printDepth := n div 2; |
|
93 |
Meta.printLength := n); |
|
94 |
end; |
|
9254 | 95 |
|
24290 | 96 |
(*interface for toplevel pretty printers, see also Pure/pure_setup.ML*) |
9254 | 97 |
(*the documentation refers to an installPP but I couldn't fine it!*) |
98 |
fun make_pp path pprint = (); |
|
99 |
fun install_pp _ = (); |
|
100 |
||
16681 | 101 |
(*dummy implementation*) |
102 |
fun ml_prompts p1 p2 = (); |
|
103 |
||
104 |
(*dummy implementation*) |
|
16660 | 105 |
fun profile (n: int) f x = f x; |
106 |
||
18384 | 107 |
(*dummy implementation*) |
16681 | 108 |
fun exception_trace f = f (); |
9254 | 109 |
|
18384 | 110 |
(*dummy implementation*) |
111 |
fun print x = x; |
|
112 |
||
9254 | 113 |
|
114 |
(** Compiler-independent timing functions **) |
|
115 |
||
116 |
load "Timer"; |
|
117 |
||
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
118 |
fun start_timing () = |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
119 |
let val CPUtimer = Timer.startCPUTimer(); |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
120 |
val time = Timer.checkCPUTimer(CPUtimer) |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
121 |
in (CPUtimer,time) end; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
122 |
|
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
123 |
fun end_timing (CPUtimer, {gc,sys,usr}) = |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
124 |
let open Time (*...for Time.toString, Time.+ and Time.- *) |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
125 |
val {gc=gc2,sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer) |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
126 |
in "User " ^ toString (usr2-usr) ^ |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
127 |
" GC " ^ toString (gc2-gc) ^ |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
128 |
" All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^ |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
129 |
" secs" |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
130 |
handle Time => "" |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
131 |
end; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
132 |
|
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
133 |
fun check_timer timer = |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
134 |
let val {sys, usr, gc} = Timer.checkCPUTimer timer |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
135 |
in (sys, usr, gc) end; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
136 |
|
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
137 |
|
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
138 |
(* SML basis library fixes *) |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
139 |
|
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
140 |
structure TextIO = |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
141 |
struct |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
142 |
fun canInput _ = raise IO.Io {cause = Fail "undefined", function = "canInput", name = ""}; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
143 |
open TextIO; |
23836 | 144 |
fun inputLine is = |
145 |
let val s = TextIO.inputLine is |
|
146 |
in if s = "" then NONE else SOME s end; |
|
21298
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
147 |
end; |
6d2306b2376d
tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents:
21280
diff
changeset
|
148 |
|
9254 | 149 |
|
150 |
(* ML command execution *) |
|
151 |
||
152 |
(*Can one redirect 'use' directly to an instream?*) |
|
24808 | 153 |
fun use_text (tune: string -> string) _ _ _ txt = |
9254 | 154 |
let |
155 |
val tmp_name = FileSys.tmpName (); |
|
156 |
val tmp_file = TextIO.openOut tmp_name; |
|
157 |
in |
|
24808 | 158 |
TextIO.output (tmp_file, tune txt); |
9254 | 159 |
TextIO.closeOut tmp_file; |
160 |
use tmp_name; |
|
161 |
FileSys.remove tmp_name |
|
162 |
end; |
|
163 |
||
24808 | 164 |
fun use_file _ _ _ name = use name; |
21770 | 165 |
|
9254 | 166 |
|
167 |
||
16993 | 168 |
(** interrupts **) (*Note: may get into race conditions*) |
9254 | 169 |
|
170 |
(* FIXME proper implementation available? *) |
|
171 |
||
172 |
exception Interrupt; |
|
173 |
||
26084
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
174 |
fun interruptible f x = f x; |
a7475459c740
replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents:
25732
diff
changeset
|
175 |
fun uninterruptible f x = f (fn (g: 'c -> 'd) => g) x; |
9254 | 176 |
|
177 |
||
178 |
||
179 |
(** OS related **) |
|
180 |
||
26223
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
181 |
(*dummy implementation*) |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
182 |
structure Posix = |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
183 |
struct |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
184 |
structure ProcEnv = |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
185 |
struct |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
186 |
fun getpid () = 0; |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
187 |
end; |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
188 |
end; |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
189 |
|
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
190 |
local |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
191 |
|
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
192 |
fun read_file name = |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
193 |
let val is = TextIO.openIn name |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
194 |
in TextIO.inputAll is before TextIO.closeIn is end; |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
195 |
|
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
196 |
fun write_file name txt = |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
197 |
let val os = TextIO.openOut name |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
198 |
in TextIO.output (os, txt) before TextIO.closeOut os end; |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
199 |
|
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
200 |
in |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
201 |
|
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
202 |
fun system_out script = |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
203 |
let |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
204 |
val script_name = OS.FileSys.tmpName (); |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
205 |
val _ = write_file script_name script; |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
206 |
|
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
207 |
val output_name = OS.FileSys.tmpName (); |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
208 |
|
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
209 |
val status = |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
210 |
OS.Process.system ("perl -w \"$ISABELLE_HOME/lib/scripts/system.pl\" nogroup " ^ |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
211 |
script_name ^ " /dev/null " ^ output_name); |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
212 |
val rc = if status = OS.Process.success then 0 else 1; |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
213 |
|
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
214 |
val output = read_file output_name handle IO.Io _ => ""; |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
215 |
val _ = OS.FileSys.remove script_name handle OS.SysErr _ => (); |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
216 |
val _ = OS.FileSys.remove output_name handle OS.SysErr _ => (); |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
217 |
in (output, rc) end; |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
218 |
|
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
219 |
end; |
f4a1a96cc07c
specific system_out (MosML lacks structure Posix);
wenzelm
parents:
26220
diff
changeset
|
220 |
|
23826
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
22252
diff
changeset
|
221 |
val cd = OS.FileSys.chDir; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
22252
diff
changeset
|
222 |
val pwd = OS.FileSys.getDir; |
463903573934
moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents:
22252
diff
changeset
|
223 |
|
17824 | 224 |
val string_of_pid = Int.toString; |
225 |
||
9254 | 226 |
fun getenv var = |
227 |
(case Process.getEnv var of |
|
228 |
NONE => "" |
|
229 |
| SOME txt => txt); |