author | obua |
Sun, 09 May 2004 23:04:36 +0200 | |
changeset 14722 | 8e739a6eaf11 |
parent 14519 | 4ca3608fdf4f |
child 14851 | 0fc75361e0c7 |
permissions | -rw-r--r-- |
9254 | 1 |
(* Title: Pure/ML-Systems/mosml.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1999 University of Cambridge |
|
5 |
||
6 |
Compatibility file for Moscow ML 2.00 |
|
7 |
||
8 |
NOTE: saving images does not work (yet!?), may run it interactively as follows: |
|
9 |
||
10 |
$ cd .../Pure |
|
11 |
$ isabelle RAW_ML_SYSTEM |
|
12 |
> val ml_system = "mosml"; |
|
13 |
> use "ML-Systems/mosml.ML"; |
|
14 |
> use "ROOT.ML"; |
|
15 |
*) |
|
16 |
||
17 |
(** ML system related **) |
|
18 |
||
19 |
||
20 |
(* Poly/ML emulation *) |
|
21 |
||
22 |
load "Bool"; |
|
23 |
load "Int"; |
|
24 |
load "Real"; |
|
25 |
load "ListPair"; |
|
26 |
||
27 |
load "OS"; |
|
28 |
load "Process"; |
|
29 |
load "FileSys"; |
|
30 |
||
31 |
structure OS = |
|
32 |
struct |
|
33 |
open OS |
|
34 |
structure Process = Process |
|
35 |
structure FileSys = FileSys |
|
36 |
end; |
|
37 |
||
38 |
(*To exit the system with an exit code -- an alternative to ^D *) |
|
39 |
fun exit 0 = Process.exit Process.success |
|
40 |
| exit _ = Process.exit Process.failure; |
|
41 |
||
42 |
(*limit the printing depth*) |
|
43 |
fun print_depth n = |
|
44 |
(Meta.printDepth := n div 2; |
|
45 |
Meta.printLength := n); |
|
46 |
||
47 |
(*interface for toplevel pretty printers, see also Pure/install_pp.ML*) |
|
48 |
(*the documentation refers to an installPP but I couldn't fine it!*) |
|
49 |
fun make_pp path pprint = (); |
|
50 |
fun install_pp _ = (); |
|
51 |
||
52 |
(*prompts*) |
|
53 |
(*n.a.??*) |
|
54 |
fun ml_prompts p1 p2 = (); |
|
55 |
||
56 |
||
57 |
(** Compiler-independent timing functions **) |
|
58 |
||
59 |
load "Timer"; |
|
60 |
||
14519
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12988
diff
changeset
|
61 |
use "ML-Systems/cpu-timer-gc.ML"; |
9254 | 62 |
|
63 |
||
64 |
(* ML command execution *) |
|
65 |
||
66 |
(*Can one redirect 'use' directly to an instream?*) |
|
67 |
fun use_text _ _ txt = |
|
68 |
let |
|
69 |
val tmp_name = FileSys.tmpName (); |
|
70 |
val tmp_file = TextIO.openOut tmp_name; |
|
71 |
in |
|
72 |
TextIO.output (tmp_file, txt); |
|
73 |
TextIO.closeOut tmp_file; |
|
74 |
use tmp_name; |
|
75 |
FileSys.remove tmp_name |
|
76 |
end; |
|
77 |
||
78 |
||
79 |
||
80 |
(** interrupts **) (*Note: may get into race conditions*) |
|
81 |
||
82 |
(* FIXME proper implementation available? *) |
|
83 |
||
84 |
exception Interrupt; |
|
85 |
||
12988 | 86 |
fun ignore_interrupt f x = f x; |
87 |
fun raise_interrupt f x = f x; |
|
9254 | 88 |
|
89 |
||
90 |
||
91 |
(** OS related **) |
|
92 |
||
93 |
(* system command execution *) |
|
94 |
||
95 |
(*execute Unix command which doesn't take any input from stdin and |
|
96 |
sends its output to stdout; could be done more easily by Unix.execute, |
|
97 |
but that function doesn't use the PATH*) |
|
98 |
fun execute command = |
|
99 |
let |
|
100 |
val tmp_name = FileSys.tmpName (); |
|
101 |
val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn |
|
102 |
tmp_name); |
|
103 |
val result = TextIO.inputAll is; |
|
104 |
in |
|
105 |
TextIO.closeIn is; |
|
106 |
FileSys.remove tmp_name; |
|
107 |
result |
|
108 |
end; |
|
109 |
||
110 |
(*plain version; with return code*) |
|
111 |
fun system cmd = |
|
112 |
if Process.system cmd = Process.success then 0 else 1; |
|
113 |
||
114 |
||
115 |
(* file handling *) |
|
116 |
||
117 |
(*get time of last modification*) |
|
118 |
fun file_info name = Time.toString (FileSys.modTime name) handle _ => ""; |
|
119 |
||
120 |
||
121 |
(* getenv *) |
|
122 |
||
123 |
fun getenv var = |
|
124 |
(case Process.getEnv var of |
|
125 |
NONE => "" |
|
126 |
| SOME txt => txt); |