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 |
|
9 (** ML system related **) |
|
10 |
|
11 (* restore old-style character / string functions *) |
|
12 |
|
13 val ord = SML90.ord; |
|
14 val chr = SML90.chr; |
|
15 val explode = SML90.explode; |
|
16 val implode = SML90.implode; |
|
17 |
|
18 |
|
19 (* MLWorks parameters *) |
|
20 |
|
21 val _ = |
|
22 (MLWorks.Internal.Runtime.Event.stack_overflow_handler |
|
23 (fn () => |
|
24 let val max_stack = MLWorks.Internal.Runtime.Memory.max_stack_blocks |
|
25 in max_stack := (!max_stack * 3) div 2 + 5; |
|
26 print ("#### Increasing stack to " ^ Int.toString (64 * !max_stack) ^ |
|
27 "KB\n") |
|
28 end); |
|
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)); |
|
32 |
|
33 |
|
34 (* Poly/ML emulation *) |
|
35 |
|
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 |
|
41 (*limit the printing depth*) |
|
42 fun print_depth n = |
|
43 let open Shell.Options |
|
44 in set (ValuePrinter.maximumDepth, n div 2); |
|
45 set (ValuePrinter.maximumSeqSize, n) |
|
46 end; |
|
47 |
|
48 (*interface for toplevel pretty printers, see also Pure/install_pp.ML*) |
|
49 (*n.a.*) |
|
50 fun make_pp path pprint = (); |
|
51 fun install_pp _ = (); |
|
52 |
|
53 (*prompts*) |
|
54 (*n.a.??*) |
|
55 fun ml_prompts p1 p2 = (); |
|
56 |
|
57 |
|
58 (** Compiler-independent timing functions **) |
|
59 |
|
60 use "ML-Systems/cpu-timer-gc.ML" |
|
61 |
|
62 (* bounded time execution *) |
|
63 |
|
64 (* FIXME proper implementation available? *) |
|
65 |
|
66 structure TimeLimit : sig |
|
67 exception TimeOut |
|
68 val timeLimit : Time.time -> ('a -> 'b) -> 'a -> 'b |
|
69 end = struct |
|
70 exception TimeOut |
|
71 fun timeLimit t f x = |
|
72 f x; |
|
73 end; |
|
74 |
|
75 (* ML command execution *) |
|
76 |
|
77 (*Can one redirect 'use' directly to an instream?*) |
|
78 fun use_text _ _ txt = |
|
79 let |
|
80 val tmp_name = OS.FileSys.tmpName (); |
|
81 val tmp_file = TextIO.openOut tmp_name; |
|
82 in |
|
83 TextIO.output (tmp_file, txt); |
|
84 TextIO.closeOut tmp_file; |
|
85 use tmp_name; |
|
86 OS.FileSys.remove tmp_name |
|
87 end; |
|
88 |
|
89 |
|
90 |
|
91 (** interrupts **) (*Note: may get into race conditions*) |
|
92 |
|
93 exception Interrupt; |
|
94 |
|
95 MLWorks.Internal.Runtime.Event.interrupt_handler (fn () => raise Interrupt); |
|
96 |
|
97 fun ignore_interrupt f x = f x; |
|
98 fun raise_interrupt f x = f x; |
|
99 |
|
100 |
|
101 |
|
102 (** OS related **) |
|
103 |
|
104 (* system command execution *) |
|
105 |
|
106 (*execute Unix command which doesn't take any input from stdin and |
|
107 sends its output to stdout; could be done more easily by Unix.execute, |
|
108 but that function doesn't use the PATH*) |
|
109 fun execute command = |
|
110 let |
|
111 val tmp_name = OS.FileSys.tmpName (); |
|
112 val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name); |
|
113 val result = TextIO.inputAll is; |
|
114 in |
|
115 TextIO.closeIn is; |
|
116 OS.FileSys.remove tmp_name; |
|
117 result |
|
118 end; |
|
119 |
|
120 (*plain version; with return code*) |
|
121 fun system cmd = |
|
122 if OS.Process.system cmd = OS.Process.success then 0 else 1; |
|
123 |
|
124 |
|
125 (* file handling *) |
|
126 |
|
127 (*get time of last modification*) |
|
128 fun file_info name = Time.toString (OS.FileSys.modTime name) handle _ => ""; |
|
129 |
|
130 |
|
131 (* getenv *) |
|
132 |
|
133 fun getenv var = |
|
134 (case OS.Process.getEnv var of |
|
135 NONE => "" |
|
136 | SOME txt => txt); |
|