author | paulson |
Wed, 20 Mar 1996 18:39:59 +0100 | |
changeset 1591 | 7fa0265dcd13 |
parent 1577 | a84cc626ea69 |
child 2076 | ec8857a115af |
permissions | -rw-r--r-- |
1480 | 1 |
(* Title: Pure/NJ1xx.ML |
2 |
ID: $Id$ |
|
3 |
Author: Carsten Clasohm, TU Muenchen |
|
4 |
Copyright 1996 TU Muenchen |
|
5 |
||
6 |
Compatibility file for Standard ML of New Jersey version 1.xx. |
|
7 |
*) |
|
8 |
||
9 |
(*** Poly/ML emulation ***) |
|
10 |
||
11 |
||
12 |
(*To exit the system with an exit code -- an alternative to ^D *) |
|
13 |
fun exit 0 = OS.Process.exit OS.Process.success |
|
14 |
| exit _ = OS.Process.exit OS.Process.failure; |
|
15 |
fun quit () = exit 0; |
|
16 |
||
17 |
(*To change the current directory*) |
|
18 |
val cd = OS.FileSys.chDir; |
|
19 |
||
20 |
(*To limit the printing depth [divided by 2 for comparibility with Poly/ML]*) |
|
21 |
fun print_depth n = (Compiler.Control.Print.printDepth := n div 2; |
|
22 |
Compiler.Control.Print.printLength := n); |
|
23 |
||
24 |
(*Interface for toplevel pretty printers, see also Pure/install_pp.ML*) |
|
25 |
||
26 |
fun make_pp path pprint = |
|
27 |
let |
|
28 |
open Compiler.PrettyPrint; |
|
29 |
||
30 |
fun pp pps obj = |
|
31 |
pprint obj |
|
32 |
(add_string pps, begin_block pps INCONSISTENT, |
|
33 |
fn wd => add_break pps (wd, 0), fn () => add_newline pps, |
|
34 |
fn () => end_block pps); |
|
35 |
in |
|
36 |
(path, pp) |
|
37 |
end; |
|
38 |
||
39 |
fun install_pp (path, pp) = Compiler.PPTable.install_pp path pp; |
|
40 |
||
41 |
||
42 |
(*** New Jersey ML parameters ***) |
|
43 |
||
44 |
(* Suppresses Garbage Collection messages; doesn't work yet *) |
|
45 |
(*System.Runtime.gc 0;*) |
|
46 |
||
47 |
val _ = (Compiler.Control.Print.printLength := 1000; |
|
48 |
Compiler.Control.Print.printDepth := 350; |
|
49 |
Compiler.Control.Print.stringDepth := 250; |
|
50 |
Compiler.Control.Print.signatures := 2); |
|
51 |
||
52 |
(*** Character/string functions which are compatibel with 0.93 and Poly/ML ***) |
|
53 |
||
54 |
val ord = Char.ord o hd o explode; |
|
55 |
val chr = str o Char.chr; |
|
56 |
val explode = (map str) o String.explode; |
|
57 |
val implode = String.concat; |
|
58 |
||
59 |
||
60 |
(*** Timing functions ***) |
|
61 |
||
1492
4e617b8f97ab
cond_timeit now uses totalCPUTimer instead of starting new ones every
clasohm
parents:
1480
diff
changeset
|
62 |
val CPUtimer = Timer.totalCPUTimer(); |
4e617b8f97ab
cond_timeit now uses totalCPUTimer instead of starting new ones every
clasohm
parents:
1480
diff
changeset
|
63 |
|
1480 | 64 |
(*A conditional timing function: applies f to () and, if the flag is true, |
65 |
prints its runtime. *) |
|
66 |
fun cond_timeit flag f = |
|
67 |
if flag then |
|
1492
4e617b8f97ab
cond_timeit now uses totalCPUTimer instead of starting new ones every
clasohm
parents:
1480
diff
changeset
|
68 |
let open Time; |
1480 | 69 |
open Timer; |
1492
4e617b8f97ab
cond_timeit now uses totalCPUTimer instead of starting new ones every
clasohm
parents:
1480
diff
changeset
|
70 |
val {gc=gct1,sys=syst1,usr=usrt1} = checkCPUTimer(CPUtimer); |
1480 | 71 |
val result = f(); |
1492
4e617b8f97ab
cond_timeit now uses totalCPUTimer instead of starting new ones every
clasohm
parents:
1480
diff
changeset
|
72 |
val {gc=gct2,sys=syst2,usr=usrt2} = checkCPUTimer(CPUtimer) |
4e617b8f97ab
cond_timeit now uses totalCPUTimer instead of starting new ones every
clasohm
parents:
1480
diff
changeset
|
73 |
in print("Non GC " ^ toString (usrt2-usrt1) ^ |
4e617b8f97ab
cond_timeit now uses totalCPUTimer instead of starting new ones every
clasohm
parents:
1480
diff
changeset
|
74 |
" GC " ^ toString (gct2-gct1) ^ |
4e617b8f97ab
cond_timeit now uses totalCPUTimer instead of starting new ones every
clasohm
parents:
1480
diff
changeset
|
75 |
" both+sys "^ toString (syst2-syst1 + usrt2-usrt1 + gct2-gct1) ^ |
4e617b8f97ab
cond_timeit now uses totalCPUTimer instead of starting new ones every
clasohm
parents:
1480
diff
changeset
|
76 |
" secs\n"); |
1480 | 77 |
result |
78 |
end |
|
79 |
else f(); |
|
80 |
||
81 |
||
82 |
(*** File handling ***) |
|
83 |
||
84 |
(*Get time of last modification; if file doesn't exist return an empty string*) |
|
85 |
local |
|
86 |
open Timer; |
|
87 |
open Posix.FileSys; |
|
88 |
in |
|
89 |
fun file_info "" = "" |
|
90 |
| file_info name = Time.toString (ST.mtime (stat name)) handle _ => ""; |
|
91 |
||
92 |
val delete_file = unlink; |
|
93 |
end; |
|
94 |
||
95 |
(*Get pathname of current working directory *) |
|
96 |
fun pwd () = OS.FileSys.getDir (); |
|
97 |
||
98 |
||
99 |
(*** ML command execution ***) |
|
100 |
||
101 |
fun use_string commands = |
|
102 |
Compiler.Interact.use_stream (open_string (implode commands)); |
|
103 |
||
104 |
||
105 |
(*** System command execution ***) |
|
106 |
||
107 |
(*Execute an Unix command which doesn't take any input from stdin and |
|
108 |
sends its output to stdout. |
|
109 |
This could be done more easily by Unix.execute, but that function |
|
110 |
doesn't use the PATH.*) |
|
111 |
fun execute command = |
|
112 |
let val tmp_name = "isa_converted.tmp" |
|
113 |
val is = (OS.Process.system (command ^ " > " ^ tmp_name); |
|
114 |
open_in tmp_name); |
|
115 |
val result = input (is, 999999); |
|
116 |
in close_in is; |
|
117 |
delete_file tmp_name; |
|
118 |
result |
|
119 |
end; |
|
120 |
||
121 |
||
122 |
(*For use in Makefiles -- saves space*) |
|
123 |
fun xML filename banner = |
|
124 |
let val runtime = List.hd (SMLofNJ.getAllArgs()) |
|
125 |
val exec_file = IO.open_out filename |
|
1577 | 126 |
|
1480 | 127 |
val _ = IO.output (exec_file, |
128 |
String.concat |
|
129 |
["#!/bin/sh\n", |
|
1577 | 130 |
runtime, " @SMLdebug=/dev/null @SMLload=", filename, |
131 |
".heap\n"]) |
|
132 |
(*"@SMLdebug=..." sends GC messages to /dev/null*) |
|
133 |
||
1480 | 134 |
val _ = IO.close_out exec_file; |
135 |
val _ = OS.Process.system ("chmod a+x " ^ filename) |
|
136 |
in exportML (filename^".heap"); |
|
137 |
print(banner^"\n") |
|
138 |
end; |