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