author | wenzelm |
Sun, 19 Jun 2005 00:02:06 +0200 | |
changeset 16469 | 7e27422c603e |
parent 16266 | 7a6616be8712 |
child 16470 | 051db5bb21b5 |
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 |
||
16469 | 10 |
$ cd ~~/src/Pure |
9254 | 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 |
(* Poly/ML emulation *) |
|
20 |
||
21 |
load "Bool"; |
|
22 |
load "Int"; |
|
23 |
load "Real"; |
|
24 |
load "ListPair"; |
|
25 |
load "OS"; |
|
26 |
load "Process"; |
|
27 |
load "FileSys"; |
|
28 |
||
16469 | 29 |
(*proper implementation available?*) |
30 |
structure IntInf = |
|
31 |
struct |
|
32 |
open Int; |
|
33 |
end; |
|
34 |
||
35 |
structure Real = |
|
36 |
struct |
|
37 |
open Real; |
|
38 |
val realFloor = real o floor; |
|
39 |
end; |
|
40 |
||
41 |
structure Time = |
|
42 |
struct |
|
43 |
open Time; |
|
44 |
fun toString t = Time.toString t |
|
45 |
handle Overflow => Real.toString (Time.toReal t); (*workaround Y2004 bug*) |
|
46 |
end; |
|
47 |
||
9254 | 48 |
structure OS = |
16469 | 49 |
struct |
9254 | 50 |
open OS |
51 |
structure Process = Process |
|
52 |
structure FileSys = FileSys |
|
16469 | 53 |
end; |
9254 | 54 |
|
55 |
(*limit the printing depth*) |
|
56 |
fun print_depth n = |
|
57 |
(Meta.printDepth := n div 2; |
|
58 |
Meta.printLength := n); |
|
59 |
||
60 |
(*interface for toplevel pretty printers, see also Pure/install_pp.ML*) |
|
61 |
(*the documentation refers to an installPP but I couldn't fine it!*) |
|
62 |
fun make_pp path pprint = (); |
|
63 |
fun install_pp _ = (); |
|
64 |
||
65 |
(*prompts*) |
|
66 |
(*n.a.??*) |
|
67 |
fun ml_prompts p1 p2 = (); |
|
68 |
||
69 |
||
70 |
(** Compiler-independent timing functions **) |
|
71 |
||
72 |
load "Timer"; |
|
73 |
||
14519
4ca3608fdf4f
Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
12988
diff
changeset
|
74 |
use "ML-Systems/cpu-timer-gc.ML"; |
9254 | 75 |
|
14851
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
76 |
(* bounded time execution *) |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
77 |
|
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
78 |
(* FIXME proper implementation available? *) |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
79 |
|
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
80 |
structure TimeLimit : sig |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
81 |
exception TimeOut |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
82 |
val timeLimit : Time.time -> ('a -> 'b) -> 'a -> 'b |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
83 |
end = struct |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
84 |
exception TimeOut |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
85 |
fun timeLimit t f x = |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
86 |
f x; |
0fc75361e0c7
TimeLimit structure added (no proper implementation yet)
webertj
parents:
14519
diff
changeset
|
87 |
end; |
9254 | 88 |
|
89 |
(* ML command execution *) |
|
90 |
||
91 |
(*Can one redirect 'use' directly to an instream?*) |
|
92 |
fun use_text _ _ txt = |
|
93 |
let |
|
94 |
val tmp_name = FileSys.tmpName (); |
|
95 |
val tmp_file = TextIO.openOut tmp_name; |
|
96 |
in |
|
97 |
TextIO.output (tmp_file, txt); |
|
98 |
TextIO.closeOut tmp_file; |
|
99 |
use tmp_name; |
|
100 |
FileSys.remove tmp_name |
|
101 |
end; |
|
102 |
||
103 |
||
104 |
||
105 |
(** interrupts **) (*Note: may get into race conditions*) |
|
106 |
||
107 |
(* FIXME proper implementation available? *) |
|
108 |
||
109 |
exception Interrupt; |
|
110 |
||
12988 | 111 |
fun ignore_interrupt f x = f x; |
112 |
fun raise_interrupt f x = f x; |
|
9254 | 113 |
|
114 |
||
115 |
||
116 |
(** OS related **) |
|
117 |
||
118 |
(* system command execution *) |
|
119 |
||
120 |
(*execute Unix command which doesn't take any input from stdin and |
|
121 |
sends its output to stdout; could be done more easily by Unix.execute, |
|
122 |
but that function doesn't use the PATH*) |
|
123 |
fun execute command = |
|
124 |
let |
|
125 |
val tmp_name = FileSys.tmpName (); |
|
126 |
val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn |
|
127 |
tmp_name); |
|
128 |
val result = TextIO.inputAll is; |
|
129 |
in |
|
130 |
TextIO.closeIn is; |
|
131 |
FileSys.remove tmp_name; |
|
132 |
result |
|
133 |
end; |
|
134 |
||
135 |
(*plain version; with return code*) |
|
136 |
fun system cmd = |
|
137 |
if Process.system cmd = Process.success then 0 else 1; |
|
138 |
||
139 |
||
140 |
(* getenv *) |
|
141 |
||
142 |
fun getenv var = |
|
143 |
(case Process.getEnv var of |
|
144 |
NONE => "" |
|
145 |
| SOME txt => txt); |