author | wenzelm |
Sun, 05 Jun 2005 11:31:30 +0200 | |
changeset 16266 | 7a6616be8712 |
parent 14851 | 0fc75361e0c7 |
child 16469 | 7e27422c603e |
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 |
|
14851
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
63 |
(* bounded time execution *) |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
64 |
|
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
65 |
(* FIXME proper implementation available? *) |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
66 |
|
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
67 |
structure TimeLimit : sig |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
68 |
exception TimeOut |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
69 |
val timeLimit : Time.time -> ('a -> 'b) -> 'a -> 'b |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
70 |
end = struct |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
71 |
exception TimeOut |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
72 |
fun timeLimit t f x = |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
73 |
f x; |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
74 |
end; |
9254 | 75 |
|
76 |
(* ML command execution *) |
|
77 |
||
78 |
(*Can one redirect 'use' directly to an instream?*) |
|
79 |
fun use_text _ _ txt = |
|
80 |
let |
|
81 |
val tmp_name = FileSys.tmpName (); |
|
82 |
val tmp_file = TextIO.openOut tmp_name; |
|
83 |
in |
|
84 |
TextIO.output (tmp_file, txt); |
|
85 |
TextIO.closeOut tmp_file; |
|
86 |
use tmp_name; |
|
87 |
FileSys.remove tmp_name |
|
88 |
end; |
|
89 |
||
90 |
||
91 |
||
92 |
(** interrupts **) (*Note: may get into race conditions*) |
|
93 |
||
94 |
(* FIXME proper implementation available? *) |
|
95 |
||
96 |
exception Interrupt; |
|
97 |
||
12988 | 98 |
fun ignore_interrupt f x = f x; |
99 |
fun raise_interrupt f x = f x; |
|
9254 | 100 |
|
101 |
||
102 |
||
103 |
(** OS related **) |
|
104 |
||
105 |
(* system command execution *) |
|
106 |
||
107 |
(*execute Unix command which doesn't take any input from stdin and |
|
108 |
sends its output to stdout; could be done more easily by Unix.execute, |
|
109 |
but that function doesn't use the PATH*) |
|
110 |
fun execute command = |
|
111 |
let |
|
112 |
val tmp_name = FileSys.tmpName (); |
|
113 |
val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn |
|
114 |
tmp_name); |
|
115 |
val result = TextIO.inputAll is; |
|
116 |
in |
|
117 |
TextIO.closeIn is; |
|
118 |
FileSys.remove tmp_name; |
|
119 |
result |
|
120 |
end; |
|
121 |
||
122 |
(*plain version; with return code*) |
|
123 |
fun system cmd = |
|
124 |
if Process.system cmd = Process.success then 0 else 1; |
|
125 |
||
126 |
||
127 |
(* getenv *) |
|
128 |
||
129 |
fun getenv var = |
|
130 |
(case Process.getEnv var of |
|
131 |
NONE => "" |
|
132 |
| SOME txt => txt); |