author | wenzelm |
Thu, 04 Feb 1999 18:15:20 +0100 | |
changeset 6227 | 3198f547f8af |
parent 5812 | cbc106ddcc83 |
child 7855 | 092a6435afad |
permissions | -rw-r--r-- |
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 _ = |
5750
7ab9dd4a8ba6
Warns when stack is extended; better decl of print_depth
paulson
parents:
5703
diff
changeset
|
22 |
(MLWorks.Internal.Runtime.Event.stack_overflow_handler |
7ab9dd4a8ba6
Warns when stack is extended; better decl of print_depth
paulson
parents:
5703
diff
changeset
|
23 |
(fn () => |
5703 | 24 |
let val max_stack = MLWorks.Internal.Runtime.Memory.max_stack_blocks |
5750
7ab9dd4a8ba6
Warns when stack is extended; better decl of print_depth
paulson
parents:
5703
diff
changeset
|
25 |
in max_stack := (!max_stack * 3) div 2 + 5; |
7ab9dd4a8ba6
Warns when stack is extended; better decl of print_depth
paulson
parents:
5703
diff
changeset
|
26 |
print ("#### Increasing stack to " ^ Int.toString (64 * !max_stack) ^ |
7ab9dd4a8ba6
Warns when stack is extended; better decl of print_depth
paulson
parents:
5703
diff
changeset
|
27 |
"KB\n") |
7ab9dd4a8ba6
Warns when stack is extended; better decl of print_depth
paulson
parents:
5703
diff
changeset
|
28 |
end); |
5660 | 29 |
MLWorks.Internal.Runtime.Memory.gc_message_level := 10; |
30 |
(*Is this of any use at all?*) |
|
31 |
Shell.Options.set (Shell.Options.ValuePrinter.showExnDetails, true)); |
|
4430 | 32 |
|
33 |
||
34 |
(* Poly/ML emulation *) |
|
35 |
||
4424 | 36 |
(*To exit the system with an exit code -- an alternative to ^D *) |
37 |
fun exit 0 = (OS.Process.exit OS.Process.success): unit |
|
38 |
| exit _ = OS.Process.exit OS.Process.failure; |
|
39 |
fun quit () = exit 0; |
|
40 |
||
5660 | 41 |
(*limit the printing depth*) |
5750
7ab9dd4a8ba6
Warns when stack is extended; better decl of print_depth
paulson
parents:
5703
diff
changeset
|
42 |
fun print_depth n = |
7ab9dd4a8ba6
Warns when stack is extended; better decl of print_depth
paulson
parents:
5703
diff
changeset
|
43 |
let open Shell.Options |
7ab9dd4a8ba6
Warns when stack is extended; better decl of print_depth
paulson
parents:
5703
diff
changeset
|
44 |
in set (ValuePrinter.maximumDepth, n div 2); |
7ab9dd4a8ba6
Warns when stack is extended; better decl of print_depth
paulson
parents:
5703
diff
changeset
|
45 |
set (ValuePrinter.maximumSeqSize, n) |
7ab9dd4a8ba6
Warns when stack is extended; better decl of print_depth
paulson
parents:
5703
diff
changeset
|
46 |
end; |
4424 | 47 |
|
4430 | 48 |
(*interface for toplevel pretty printers, see also Pure/install_pp.ML*) |
49 |
(*n.a.*) |
|
4424 | 50 |
fun make_pp path pprint = (); |
51 |
fun install_pp _ = (); |
|
52 |
||
4977 | 53 |
(*prompts*) |
54 |
(*n.a.??*) |
|
55 |
fun ml_prompts p1 p2 = (); |
|
56 |
||
4424 | 57 |
|
58 |
(** Compiler-independent timing functions **) |
|
59 |
||
60 |
(*Note start point for timing*) |
|
61 |
fun startTiming() = |
|
62 |
let val CPUtimer = Timer.startCPUTimer(); |
|
63 |
val time = Timer.checkCPUTimer(CPUtimer) |
|
64 |
in (CPUtimer,time) end; |
|
65 |
||
66 |
(*Finish timing and return string*) |
|
67 |
fun endTiming (CPUtimer, {gc,sys,usr}) = |
|
68 |
let open Time (*...for Time.toString, Time.+ and Time.- *) |
|
69 |
val {gc=gc2,sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer) |
|
70 |
in "User " ^ toString (usr2-usr) ^ |
|
71 |
" GC " ^ toString (gc2-gc) ^ |
|
72 |
" All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^ |
|
73 |
" secs" |
|
74 |
handle Time => "" |
|
75 |
end; |
|
76 |
||
77 |
||
4430 | 78 |
(* ML command execution *) |
4424 | 79 |
|
80 |
(*Can one redirect 'use' directly to an instream?*) |
|
5090 | 81 |
fun use_text _ txt = |
4430 | 82 |
let |
83 |
val tmp_name = OS.FileSys.tmpName (); |
|
84 |
val tmp_file = TextIO.openOut tmp_name; |
|
5038 | 85 |
in |
86 |
TextIO.output (tmp_file, txt); |
|
87 |
TextIO.closeOut tmp_file; |
|
88 |
use tmp_name; |
|
89 |
OS.FileSys.remove tmp_name |
|
4424 | 90 |
end; |
91 |
||
92 |
||
4430 | 93 |
|
5812 | 94 |
(** interrupts **) (*Note: may get into race conditions*) |
95 |
||
96 |
exception Interrupt; |
|
97 |
||
98 |
MLWorks.Internal.Runtime.Event.interrupt_handler (fn () => raise Interrupt); |
|
99 |
||
100 |
fun mask_interrupt f x = f x; |
|
101 |
fun unmask_interrupt f x = f x; |
|
102 |
fun exhibit_interrupt f x = f x; |
|
103 |
||
104 |
||
105 |
||
4430 | 106 |
(** OS related **) |
4424 | 107 |
|
4430 | 108 |
(* system command execution *) |
109 |
||
110 |
(*execute Unix command which doesn't take any input from stdin and |
|
111 |
sends its output to stdout; could be done more easily by Unix.execute, |
|
112 |
but that function doesn't use the PATH*) |
|
4424 | 113 |
fun execute command = |
4430 | 114 |
let |
115 |
val tmp_name = OS.FileSys.tmpName (); |
|
116 |
val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name); |
|
117 |
val result = TextIO.inputAll is; |
|
118 |
in |
|
119 |
TextIO.closeIn is; |
|
120 |
OS.FileSys.remove tmp_name; |
|
121 |
result |
|
4424 | 122 |
end; |
123 |
||
124 |
||
4430 | 125 |
(* file handling *) |
126 |
||
6227 | 127 |
(*get time of last modification*) |
128 |
fun file_info name = Time.toString (OS.FileSys.modTime name) handle _ => ""; |
|
4430 | 129 |
|
130 |
||
4424 | 131 |
(* getenv *) |
132 |
||
133 |
fun getenv var = |
|
134 |
(case OS.Process.getEnv var of |
|
135 |
NONE => "" |
|
136 |
| SOME txt => txt); |
|
137 |
||
138 |
||
4430 | 139 |
(* non-ASCII input (see also Thy/use.ML) *) |
4424 | 140 |
|
4430 | 141 |
val needs_filtered_use = false; |