author | clasohm |
Thu, 22 Jun 1995 12:58:39 +0200 | |
changeset 1154 | bc295e3dc078 |
parent 907 | 61fcac0e50fc |
child 1289 | 2edd7a39d92a |
permissions | -rw-r--r-- |
0 | 1 |
(* Title: Pure/NJ |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1993 University of Cambridge |
|
5 |
||
6 |
Compatibility file for Standard ML of New Jersey. |
|
7 |
*) |
|
8 |
||
9 |
(*** Poly/ML emulation ***) |
|
10 |
||
907 | 11 |
(*To exit the system with an exit code -- an alternative to ^D *) |
12 |
val exit = System.Unsafe.CInterface.exit; |
|
13 |
fun quit () = exit 0; |
|
0 | 14 |
|
15 |
(*To change the current directory*) |
|
16 |
val cd = System.Directory.cd; |
|
17 |
||
18 |
(*To limit the printing depth [divided by 2 for comparibility with Poly/ML]*) |
|
19 |
fun print_depth n = (System.Control.Print.printDepth := n div 2; |
|
20 |
System.Control.Print.printLength := n); |
|
21 |
||
22 |
||
23 |
(*Interface for toplevel pretty printers, see also Pure/install_pp.ML*) |
|
24 |
||
25 |
fun make_pp path pprint = |
|
26 |
let |
|
27 |
open System.PrettyPrint; |
|
28 |
||
29 |
fun pp pps obj = |
|
30 |
pprint obj |
|
31 |
(add_string pps, begin_block pps INCONSISTENT, |
|
19 | 32 |
fn wd => add_break pps (wd, 0), fn () => add_newline pps, |
33 |
fn () => end_block pps); |
|
0 | 34 |
in |
35 |
(path, pp) |
|
36 |
end; |
|
37 |
||
38 |
fun install_pp (path, pp) = System.PrettyPrint.install_pp path pp; |
|
39 |
||
40 |
||
41 |
(*** New Jersey ML parameters ***) |
|
42 |
||
43 |
(* Suppresses Garbage Collection messages; default was 2 *) |
|
44 |
System.Control.Runtime.gcmessages := 0; |
|
45 |
||
46 |
(*redefine to flush its output immediately -- temporary patch suggested |
|
47 |
by Kim Dam Petersen*) |
|
48 |
val output = fn(s, t) => (output(s, t); flush_out s); |
|
49 |
||
50 |
(*Dummy version of the Poly/ML function*) |
|
51 |
fun commit() = (); |
|
52 |
||
53 |
(*For use in Makefiles -- saves space*) |
|
54 |
fun xML filename banner = (exportML filename; print(banner^"\n")); |
|
55 |
||
56 |
(*** Timing functions ***) |
|
57 |
||
58 |
(*Print microseconds, suppressing trailing zeroes*) |
|
59 |
fun umakestring 0 = "" |
|
60 |
| umakestring n = chr(ord"0" + n div 100000) ^ |
|
61 |
umakestring(10 * (n mod 100000)); |
|
62 |
||
63 |
(*A conditional timing function: applies f to () and, if the flag is true, |
|
64 |
prints its runtime. *) |
|
65 |
fun cond_timeit flag f = |
|
66 |
if flag then |
|
67 |
let fun string_of_time (System.Timer.TIME {sec, usec}) = |
|
68 |
makestring sec ^ "." ^ (if usec=0 then "0" else umakestring usec) |
|
69 |
open System.Timer; |
|
70 |
val start = start_timer() |
|
71 |
val result = f(); |
|
72 |
val nongc = check_timer(start) |
|
73 |
and gc = check_timer_gc(start); |
|
74 |
val both = add_time(nongc, gc) |
|
75 |
in print("Non GC " ^ string_of_time nongc ^ |
|
76 |
" GC " ^ string_of_time gc ^ |
|
77 |
" both "^ string_of_time both ^ " secs\n"); |
|
78 |
result |
|
79 |
end |
|
80 |
else f(); |
|
81 |
||
82 |
||
66 | 83 |
(*** File handling ***) |
0 | 84 |
|
85 |
(*Get time of last modification.*) |
|
86 |
local |
|
87 |
open System.Timer; |
|
88 |
open System.Unsafe.SysIO; |
|
89 |
in |
|
90 |
fun file_info "" = "" |
|
91 |
| file_info name = makestring (mtime (PATH name)); |
|
220 | 92 |
|
93 |
val delete_file = unlink; |
|
0 | 94 |
end; |
95 |
||
100
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
96 |
(*Get pathname of current working directory *) |
e95b98536b3d
fixed a bug in POLY.ML: delete_file didn't close streams;
clasohm
parents:
73
diff
changeset
|
97 |
fun pwd () = System.Directory.getWD (); |
378
85ff48546a05
added use_string: string -> unit to execute ML commands passed in a string
clasohm
parents:
220
diff
changeset
|
98 |
|
85ff48546a05
added use_string: string -> unit to execute ML commands passed in a string
clasohm
parents:
220
diff
changeset
|
99 |
|
85ff48546a05
added use_string: string -> unit to execute ML commands passed in a string
clasohm
parents:
220
diff
changeset
|
100 |
(*** ML command execution ***) |
85ff48546a05
added use_string: string -> unit to execute ML commands passed in a string
clasohm
parents:
220
diff
changeset
|
101 |
|
396
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
102 |
fun use_string commands = |
18c9c28d0f7e
changed use_string's type to string list -> unit because POLY can only
clasohm
parents:
378
diff
changeset
|
103 |
System.Compile.use_stream (open_string (implode commands)); |
378
85ff48546a05
added use_string: string -> unit to execute ML commands passed in a string
clasohm
parents:
220
diff
changeset
|
104 |