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 |
|
|
11 |
(*To exit the system -- an alternative to ^D *)
|
|
12 |
fun quit () = System.Unsafe.CInterface.exit 0;
|
|
13 |
|
|
14 |
(*To change the current directory*)
|
|
15 |
val cd = System.Directory.cd;
|
|
16 |
|
|
17 |
(*To limit the printing depth [divided by 2 for comparibility with Poly/ML]*)
|
|
18 |
fun print_depth n = (System.Control.Print.printDepth := n div 2;
|
|
19 |
System.Control.Print.printLength := n);
|
|
20 |
|
|
21 |
|
|
22 |
(*Interface for toplevel pretty printers, see also Pure/install_pp.ML*)
|
|
23 |
|
|
24 |
fun make_pp path pprint =
|
|
25 |
let
|
|
26 |
open System.PrettyPrint;
|
|
27 |
|
|
28 |
fun pp pps obj =
|
|
29 |
pprint obj
|
|
30 |
(add_string pps, begin_block pps INCONSISTENT,
|
|
31 |
fn wd => add_break pps (wd, 0), fn () => end_block pps);
|
|
32 |
in
|
|
33 |
(path, pp)
|
|
34 |
end;
|
|
35 |
|
|
36 |
fun install_pp (path, pp) = System.PrettyPrint.install_pp path pp;
|
|
37 |
|
|
38 |
|
|
39 |
(*** New Jersey ML parameters ***)
|
|
40 |
|
|
41 |
(* Suppresses Garbage Collection messages; default was 2 *)
|
|
42 |
System.Control.Runtime.gcmessages := 0;
|
|
43 |
|
|
44 |
(*redefine to flush its output immediately -- temporary patch suggested
|
|
45 |
by Kim Dam Petersen*)
|
|
46 |
val output = fn(s, t) => (output(s, t); flush_out s);
|
|
47 |
|
|
48 |
(*Dummy version of the Poly/ML function*)
|
|
49 |
fun commit() = ();
|
|
50 |
|
|
51 |
(*For use in Makefiles -- saves space*)
|
|
52 |
fun xML filename banner = (exportML filename; print(banner^"\n"));
|
|
53 |
|
|
54 |
(*** Timing functions ***)
|
|
55 |
|
|
56 |
(*Print microseconds, suppressing trailing zeroes*)
|
|
57 |
fun umakestring 0 = ""
|
|
58 |
| umakestring n = chr(ord"0" + n div 100000) ^
|
|
59 |
umakestring(10 * (n mod 100000));
|
|
60 |
|
|
61 |
(*A conditional timing function: applies f to () and, if the flag is true,
|
|
62 |
prints its runtime. *)
|
|
63 |
fun cond_timeit flag f =
|
|
64 |
if flag then
|
|
65 |
let fun string_of_time (System.Timer.TIME {sec, usec}) =
|
|
66 |
makestring sec ^ "." ^ (if usec=0 then "0" else umakestring usec)
|
|
67 |
open System.Timer;
|
|
68 |
val start = start_timer()
|
|
69 |
val result = f();
|
|
70 |
val nongc = check_timer(start)
|
|
71 |
and gc = check_timer_gc(start);
|
|
72 |
val both = add_time(nongc, gc)
|
|
73 |
in print("Non GC " ^ string_of_time nongc ^
|
|
74 |
" GC " ^ string_of_time gc ^
|
|
75 |
" both "^ string_of_time both ^ " secs\n");
|
|
76 |
result
|
|
77 |
end
|
|
78 |
else f();
|
|
79 |
|
|
80 |
|
|
81 |
(*** File information ***)
|
|
82 |
|
|
83 |
(*Get time of last modification.*)
|
|
84 |
local
|
|
85 |
open System.Timer;
|
|
86 |
open System.Unsafe.SysIO;
|
|
87 |
in
|
|
88 |
fun file_info "" = ""
|
|
89 |
| file_info name = makestring (mtime (PATH name));
|
|
90 |
end;
|
|
91 |
|