author | wenzelm |
Fri, 15 Feb 2002 20:43:44 +0100 | |
changeset 12896 | 4518acda6d93 |
parent 12108 | b6f10dcde803 |
child 12988 | 2112f9e337bb |
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 |
||
10730 | 13 |
val ord = SML90.ord; |
14 |
val chr = SML90.chr; |
|
15 |
val explode = SML90.explode; |
|
16 |
val implode = SML90.implode; |
|
4430 | 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?*) |
|
7855 | 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 exhibit_interrupt f x = f x; |
|
102 |
||
103 |
||
104 |
||
4430 | 105 |
(** OS related **) |
4424 | 106 |
|
4430 | 107 |
(* system command execution *) |
108 |
||
109 |
(*execute Unix command which doesn't take any input from stdin and |
|
110 |
sends its output to stdout; could be done more easily by Unix.execute, |
|
111 |
but that function doesn't use the PATH*) |
|
4424 | 112 |
fun execute command = |
4430 | 113 |
let |
114 |
val tmp_name = OS.FileSys.tmpName (); |
|
115 |
val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name); |
|
116 |
val result = TextIO.inputAll is; |
|
117 |
in |
|
118 |
TextIO.closeIn is; |
|
119 |
OS.FileSys.remove tmp_name; |
|
120 |
result |
|
4424 | 121 |
end; |
122 |
||
7855 | 123 |
(*plain version; with return code*) |
124 |
fun system cmd = |
|
125 |
if OS.Process.system cmd = OS.Process.success then 0 else 1; |
|
126 |
||
4424 | 127 |
|
4430 | 128 |
(* file handling *) |
129 |
||
6227 | 130 |
(*get time of last modification*) |
131 |
fun file_info name = Time.toString (OS.FileSys.modTime name) handle _ => ""; |
|
4430 | 132 |
|
133 |
||
4424 | 134 |
(* getenv *) |
135 |
||
136 |
fun getenv var = |
|
137 |
(case OS.Process.getEnv var of |
|
138 |
NONE => "" |
|
139 |
| SOME txt => txt); |