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