| author | wenzelm |
| Mon, 21 Jun 2004 16:40:44 +0200 | |
| changeset 14988 | 973ced82812d |
| parent 14981 | e73f8140af78 |
| child 15702 | 2677db44c795 |
| permissions | -rw-r--r-- |
| 4403 | 1 |
(* Title: Pure/ML-Systems/smlnj.ML |
2 |
ID: $Id$ |
|
3 |
Author: Carsten Clasohm and Markus Wenzel, TU Muenchen |
|
4 |
||
| 5708 | 5 |
Compatibility file for Standard ML of New Jersey 110 or later. |
| 4403 | 6 |
*) |
7 |
||
|
12874
368966ceafe5
ML-Systems/smlnj-compiler.ML compatibility tweak;
wenzelm
parents:
12581
diff
changeset
|
8 |
(case #version_id (Compiler.version) of |
|
368966ceafe5
ML-Systems/smlnj-compiler.ML compatibility tweak;
wenzelm
parents:
12581
diff
changeset
|
9 |
[110, x] => if x >= 35 then use "ML-Systems/smlnj-compiler.ML" else () |
|
368966ceafe5
ML-Systems/smlnj-compiler.ML compatibility tweak;
wenzelm
parents:
12581
diff
changeset
|
10 |
| _ => ()); |
|
368966ceafe5
ML-Systems/smlnj-compiler.ML compatibility tweak;
wenzelm
parents:
12581
diff
changeset
|
11 |
|
| 4403 | 12 |
(** ML system related **) |
13 |
||
14 |
(* restore old-style character / string functions *) |
|
15 |
||
| 10725 | 16 |
val ord = SML90.ord; |
17 |
val chr = SML90.chr; |
|
18 |
val explode = SML90.explode; |
|
19 |
val implode = SML90.implode; |
|
| 4403 | 20 |
|
21 |
||
22 |
(* New Jersey ML parameters *) |
|
23 |
||
24 |
val _ = |
|
25 |
(Compiler.Control.Print.printLength := 1000; |
|
26 |
Compiler.Control.Print.printDepth := 350; |
|
27 |
Compiler.Control.Print.stringDepth := 250; |
|
| 12581 | 28 |
Compiler.Control.Print.signatures := 2; |
29 |
Compiler.Control.MC.matchRedundantError := false); |
|
| 4403 | 30 |
|
31 |
||
32 |
(* Poly/ML emulation *) |
|
33 |
||
34 |
fun quit () = exit 0; |
|
35 |
||
36 |
(*limit the printing depth -- divided by 2 for comparibility with Poly/ML*) |
|
37 |
fun print_depth n = |
|
38 |
(Compiler.Control.Print.printDepth := n div 2; |
|
39 |
Compiler.Control.Print.printLength := n); |
|
40 |
||
41 |
||
| 5816 | 42 |
(* compiler-independent timing functions *) |
| 4403 | 43 |
|
|
14519
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12990
diff
changeset
|
44 |
(case #version_id (Compiler.version) of |
| 14656 | 45 |
[110, x] => if x >= 44 |
|
14519
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12990
diff
changeset
|
46 |
then use "ML-Systems/cpu-timer-basis.ML" |
|
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12990
diff
changeset
|
47 |
else use "ML-Systems/cpu-timer-gc.ML" |
| 14520 | 48 |
| _ => use "ML-Systems/cpu-timer-gc.ML"); |
| 4403 | 49 |
|
50 |
||
| 4977 | 51 |
(* prompts *) |
52 |
||
53 |
fun ml_prompts p1 p2 = |
|
54 |
(Compiler.Control.primaryPrompt := p1; Compiler.Control.secondaryPrompt := p2); |
|
55 |
||
56 |
||
|
14519
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12990
diff
changeset
|
57 |
(case #version_id (Compiler.version) of |
| 14656 | 58 |
[110, x] => if x >= 44 |
|
14519
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12990
diff
changeset
|
59 |
then use "ML-Systems/smlnj-basis-compat.ML" |
|
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12990
diff
changeset
|
60 |
else () |
|
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12990
diff
changeset
|
61 |
| _ => ()); |
|
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12990
diff
changeset
|
62 |
|
| 4403 | 63 |
(* toplevel pretty printing (see also Pure/install_pp.ML) *) |
64 |
||
|
14519
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12990
diff
changeset
|
65 |
(case #version_id (Compiler.version) of |
| 14656 | 66 |
[110, x] => if x >= 44 |
|
14519
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12990
diff
changeset
|
67 |
then use "ML-Systems/smlnj-pp-new.ML" |
|
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12990
diff
changeset
|
68 |
else use "ML-Systems/smlnj-pp-old.ML" |
| 14520 | 69 |
| _ => use "ML-Systems/smlnj-pp-old.ML"); |
| 4403 | 70 |
|
71 |
fun install_pp (path, pp) = Compiler.PPTable.install_pp path pp; |
|
72 |
||
73 |
||
74 |
(* ML command execution *) |
|
75 |
||
| 10914 | 76 |
fun use_text (print, err) verbose txt = |
| 5090 | 77 |
let |
78 |
val ref out_orig = Compiler.Control.Print.out; |
|
79 |
||
80 |
val out_buffer = ref ([]: string list); |
|
81 |
val out = {say = (fn s => out_buffer := s :: ! out_buffer), flush = (fn () => ())};
|
|
| 10914 | 82 |
fun output () = |
| 7890 | 83 |
let val str = implode (rev (! out_buffer)) |
| 10914 | 84 |
in String.substring (str, 0, Int.max (0, size str - 1)) end; |
| 5090 | 85 |
in |
86 |
Compiler.Control.Print.out := out; |
|
87 |
Compiler.Interact.useStream (TextIO.openString txt) handle exn => |
|
| 10914 | 88 |
(Compiler.Control.Print.out := out_orig; err (output ()); raise exn); |
| 5090 | 89 |
Compiler.Control.Print.out := out_orig; |
| 10914 | 90 |
if verbose then print (output ()) else () |
| 5090 | 91 |
end; |
| 4403 | 92 |
|
93 |
||
94 |
||
| 5816 | 95 |
(** interrupts **) |
96 |
||
| 12990 | 97 |
exception Interrupt; |
98 |
||
| 5816 | 99 |
local |
100 |
||
| 12990 | 101 |
fun capture f x = ((f x): unit; NONE) handle exn => SOME exn; |
| 5816 | 102 |
|
| 12990 | 103 |
fun release NONE = () |
104 |
| release (SOME exn) = raise exn; |
|
| 5816 | 105 |
|
106 |
in |
|
107 |
||
| 12990 | 108 |
fun ignore_interrupt f x = |
| 5816 | 109 |
let |
| 12990 | 110 |
val old_handler = Signals.setHandler (Signals.sigINT, Signals.IGNORE); |
111 |
val result = capture f x; |
|
112 |
val _ = Signals.setHandler (Signals.sigINT, old_handler); |
|
113 |
in release result end; |
|
| 5816 | 114 |
|
| 12990 | 115 |
fun raise_interrupt f x = |
116 |
let |
|
| 5816 | 117 |
val interrupted = ref false; |
| 12990 | 118 |
val result = ref NONE; |
119 |
val old_handler = Signals.inqHandler Signals.sigINT; |
|
| 5816 | 120 |
in |
| 12990 | 121 |
SMLofNJ.Cont.callcc (fn cont => |
122 |
(Signals.setHandler (Signals.sigINT, Signals.HANDLER (fn _ => (interrupted := true; cont))); |
|
123 |
result := capture f x)); |
|
124 |
Signals.setHandler (Signals.sigINT, old_handler); |
|
125 |
if ! interrupted then raise Interrupt else release (! result) |
|
126 |
end; |
|
| 5816 | 127 |
|
128 |
end; |
|
129 |
||
130 |
||
131 |
||
| 4403 | 132 |
(** OS related **) |
133 |
||
134 |
(* system command execution *) |
|
135 |
||
136 |
(*execute Unix command which doesn't take any input from stdin and |
|
137 |
sends its output to stdout; could be done more easily by Unix.execute, |
|
138 |
but that function doesn't use the PATH*) |
|
139 |
fun execute command = |
|
140 |
let |
|
141 |
val tmp_name = OS.FileSys.tmpName (); |
|
142 |
val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name); |
|
143 |
val result = TextIO.inputAll is; |
|
144 |
in |
|
145 |
TextIO.closeIn is; |
|
146 |
OS.FileSys.remove tmp_name; |
|
147 |
result |
|
148 |
end; |
|
149 |
||
| 7855 | 150 |
(*plain version; with return code*) |
| 12990 | 151 |
val system = OS.Process.system: string -> int; |
| 7855 | 152 |
|
| 4403 | 153 |
|
154 |
(* file handling *) |
|
155 |
||
| 6227 | 156 |
(*get time of last modification*) |
157 |
fun file_info name = Time.toString (OS.FileSys.modTime name) handle _ => ""; |
|
| 4403 | 158 |
|
159 |
||
160 |
(* getenv *) |
|
161 |
||
162 |
fun getenv var = |
|
163 |
(case OS.Process.getEnv var of |
|
164 |
NONE => "" |
|
165 |
| SOME txt => txt); |