author | wenzelm |
Fri, 07 Mar 1997 11:48:46 +0100 | |
changeset 2754 | 59bd96046ad6 |
parent 2723 | f09ecc2cd3f1 |
permissions | -rw-r--r-- |
2330 | 1 |
(* Title: Pure/MLWorks.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1996 University of Cambridge |
|
5 |
||
6 |
Compatibility file for MLWorks (??) |
|
7 |
||
8 |
NB: There is still no easy way of building Isabelle under MLWorks. This file |
|
9 |
is just a start towards compatibility. One problem is the peculiar |
|
10 |
behaviour of "use" in MLWorks. Strange errors occur when loading theories, |
|
11 |
and ROOT.ML files on subdirectories are loaded incorrectly. |
|
12 |
*) |
|
13 |
||
14 |
(*** Poly/ML emulation ***) |
|
15 |
||
16 |
(** |
|
2723
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
17 |
Shell.File.loadSource "system.__os"; |
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
18 |
Shell.File.loadSource "basis.__timer"; |
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
19 |
Shell.File.loadSource "system.__time"; |
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
20 |
Shell.File.loadSource "unix.__os_file_sys"; |
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
21 |
Shell.File.loadSource "basis.__list"; |
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
22 |
Shell.File.loadSource "basis.__char"; |
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
23 |
Shell.File.loadSource "basis.__string"; |
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
24 |
Shell.File.loadSource "basis.__text_io"; |
2330 | 25 |
**) |
26 |
||
27 |
||
28 |
(*To exit the system with an exit code -- an alternative to ^D *) |
|
29 |
fun exit 0 = OS.Process.exit OS.Process.success |
|
30 |
| exit _ = OS.Process.exit OS.Process.failure; |
|
31 |
fun quit () = exit 0; |
|
32 |
||
33 |
(*To limit the printing depth [divided by 2 for comparibility with Poly/ML]*) |
|
34 |
fun print_depth n = (); |
|
35 |
||
2723
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
36 |
(*Interface for toplevel pretty printers, see also Pure/install_pp.ML |
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
37 |
CURRENTLY UNAVAILABLE*) |
2330 | 38 |
fun make_pp path pprint = (); |
39 |
fun install_pp _ = (); |
|
40 |
||
41 |
||
42 |
(*** New Jersey ML parameters ***) |
|
43 |
||
44 |
(*** Character/string functions which are compatible with 0.93 and Poly/ML ***) |
|
45 |
||
46 |
fun ord s = Char.ord (String.sub(s,0)); |
|
47 |
val chr = str o Char.chr; |
|
48 |
val explode = (map str) o String.explode; |
|
49 |
val implode = String.concat; |
|
50 |
||
51 |
||
52 |
(*** Timing functions ***) |
|
53 |
||
54 |
(*A conditional timing function: applies f to () and, if the flag is true, |
|
55 |
prints its runtime. *) |
|
56 |
fun cond_timeit flag f = |
|
57 |
if flag then |
|
58 |
let open Time (*...for Time.toString, Time.+ and Time.- *) |
|
59 |
val CPUtimer = Timer.startCPUTimer(); |
|
60 |
val {gc=gct1,sys=syst1,usr=usrt1} = Timer.checkCPUTimer(CPUtimer); |
|
61 |
val result = f(); |
|
62 |
val {gc=gct2,sys=syst2,usr=usrt2} = Timer.checkCPUTimer(CPUtimer) |
|
63 |
in print("User " ^ toString (usrt2-usrt1) ^ |
|
64 |
" GC " ^ toString (gct2-gct1) ^ |
|
65 |
" All "^ toString (syst2-syst1 + usrt2-usrt1 + gct2-gct1) ^ |
|
66 |
" secs\n") |
|
67 |
handle Time => (); |
|
68 |
result |
|
69 |
end |
|
70 |
else f(); |
|
71 |
||
72 |
||
73 |
(*** File handling ***) |
|
74 |
||
75 |
(*Get time of last modification; if file doesn't exist return an empty string*) |
|
76 |
fun file_info "" = "" |
|
77 |
| file_info name = Time.toString (OS.FileSys.modTime name) handle _ =>""; |
|
78 |
||
79 |
||
80 |
(*** ML command execution ***) |
|
81 |
||
82 |
val tmpName = OS.FileSys.tmpName(); |
|
83 |
||
84 |
(*Can one redirect 'use' directly to an instream?*) |
|
85 |
fun use_string slist = |
|
86 |
let val tmpFile = TextIO.openOut tmpName |
|
87 |
in app (fn s => TextIO.output (tmpFile, s)) slist; |
|
88 |
TextIO.closeOut tmpFile; |
|
89 |
use tmpName |
|
90 |
end; |
|
91 |
||
92 |
||
93 |
(*** System command execution ***) |
|
94 |
||
95 |
(*Execute an Unix command which doesn't take any input from stdin and |
|
96 |
sends its output to stdout. |
|
97 |
This could be done more easily by Unix.execute, but that function |
|
98 |
doesn't use the PATH.*) |
|
99 |
fun execute command = |
|
100 |
let val is = (OS.Process.system (command ^ " > " ^ tmpName); |
|
101 |
TextIO.openIn tmpName); |
|
102 |
val result = TextIO.inputAll is; |
|
103 |
in TextIO.closeIn is; |
|
104 |
OS.FileSys.remove tmpName; |
|
105 |
result |
|
106 |
end; |
|
107 |
||
108 |
||
109 |
(*Don't know what the boolean is for*) |
|
110 |
fun xML filename = Shell.saveImage (filename, false); |
|
2723
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
111 |
|
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
112 |
|
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
113 |
(*Non-printing and 8-bit chars are forbidden in string constants*) |
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
114 |
val needs_filtered_use = true; |
f09ecc2cd3f1
Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents:
2330
diff
changeset
|
115 |