4424
|
1 |
(* Title: Pure/ML-Systems/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 version 1.0r2 or later.
|
|
7 |
*)
|
|
8 |
|
4430
|
9 |
(** ML system related **)
|
|
10 |
|
|
11 |
(* restore old-style character / string functions *)
|
|
12 |
|
|
13 |
fun ord s = Char.ord (String.sub (s, 0));
|
|
14 |
val chr = str o Char.chr;
|
|
15 |
val explode = (map str) o String.explode;
|
|
16 |
val implode = String.concat;
|
|
17 |
|
4424
|
18 |
|
4430
|
19 |
(* MLWorks parameters *)
|
|
20 |
|
|
21 |
MLWorks.Internal.Runtime.Event.stack_overflow_handler
|
|
22 |
(fn () => MLWorks.Internal.Runtime.Memory.max_stack_blocks :=
|
|
23 |
! MLWorks.Internal.Runtime.Memory.max_stack_blocks + 20);
|
|
24 |
|
|
25 |
|
|
26 |
(* Poly/ML emulation *)
|
|
27 |
|
4424
|
28 |
(*To exit the system with an exit code -- an alternative to ^D *)
|
|
29 |
fun exit 0 = (OS.Process.exit OS.Process.success): unit
|
|
30 |
| exit _ = OS.Process.exit OS.Process.failure;
|
|
31 |
fun quit () = exit 0;
|
|
32 |
|
4430
|
33 |
(*n.a.*)
|
4424
|
34 |
fun print_depth n = ();
|
|
35 |
|
4430
|
36 |
(*interface for toplevel pretty printers, see also Pure/install_pp.ML*)
|
|
37 |
(*n.a.*)
|
4424
|
38 |
fun make_pp path pprint = ();
|
|
39 |
fun install_pp _ = ();
|
|
40 |
|
4977
|
41 |
(*prompts*)
|
|
42 |
(*n.a.??*)
|
|
43 |
fun ml_prompts p1 p2 = ();
|
|
44 |
|
4424
|
45 |
|
|
46 |
(** Compiler-independent timing functions **)
|
|
47 |
|
|
48 |
(*Note start point for timing*)
|
|
49 |
fun startTiming() =
|
|
50 |
let val CPUtimer = Timer.startCPUTimer();
|
|
51 |
val time = Timer.checkCPUTimer(CPUtimer)
|
|
52 |
in (CPUtimer,time) end;
|
|
53 |
|
|
54 |
(*Finish timing and return string*)
|
|
55 |
fun endTiming (CPUtimer, {gc,sys,usr}) =
|
|
56 |
let open Time (*...for Time.toString, Time.+ and Time.- *)
|
|
57 |
val {gc=gc2,sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
|
|
58 |
in "User " ^ toString (usr2-usr) ^
|
|
59 |
" GC " ^ toString (gc2-gc) ^
|
|
60 |
" All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^
|
|
61 |
" secs"
|
|
62 |
handle Time => ""
|
|
63 |
end;
|
|
64 |
|
|
65 |
|
4430
|
66 |
(* ML command execution *)
|
4424
|
67 |
|
|
68 |
(*Can one redirect 'use' directly to an instream?*)
|
5038
|
69 |
fun use_text txt =
|
4430
|
70 |
let
|
|
71 |
val tmp_name = OS.FileSys.tmpName ();
|
|
72 |
val tmp_file = TextIO.openOut tmp_name;
|
5038
|
73 |
in
|
|
74 |
TextIO.output (tmp_file, txt);
|
|
75 |
TextIO.closeOut tmp_file;
|
|
76 |
use tmp_name;
|
|
77 |
OS.FileSys.remove tmp_name
|
4424
|
78 |
end;
|
|
79 |
|
|
80 |
|
4430
|
81 |
|
|
82 |
(** OS related **)
|
4424
|
83 |
|
4430
|
84 |
(* system command execution *)
|
|
85 |
|
|
86 |
(*execute Unix command which doesn't take any input from stdin and
|
|
87 |
sends its output to stdout; could be done more easily by Unix.execute,
|
|
88 |
but that function doesn't use the PATH*)
|
4424
|
89 |
fun execute command =
|
4430
|
90 |
let
|
|
91 |
val tmp_name = OS.FileSys.tmpName ();
|
|
92 |
val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
|
|
93 |
val result = TextIO.inputAll is;
|
|
94 |
in
|
|
95 |
TextIO.closeIn is;
|
|
96 |
OS.FileSys.remove tmp_name;
|
|
97 |
result
|
4424
|
98 |
end;
|
|
99 |
|
|
100 |
|
4430
|
101 |
(* file handling *)
|
|
102 |
|
|
103 |
(*get time of last modification; if file doesn't exist return an empty string*)
|
|
104 |
fun file_info "" = "" (* FIXME !? *)
|
|
105 |
| file_info name = Time.toString (OS.FileSys.modTime name) handle _ => "";
|
|
106 |
|
|
107 |
|
4424
|
108 |
(* getenv *)
|
|
109 |
|
|
110 |
fun getenv var =
|
|
111 |
(case OS.Process.getEnv var of
|
|
112 |
NONE => ""
|
|
113 |
| SOME txt => txt);
|
|
114 |
|
|
115 |
|
4430
|
116 |
(* non-ASCII input (see also Thy/use.ML) *)
|
4424
|
117 |
|
4430
|
118 |
val needs_filtered_use = false;
|