1 (* Title: Pure/ML-Systems/mosml.ML
3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory
4 Copyright 1999 University of Cambridge
6 Compatibility file for Moscow ML 2.01
8 NOTE: saving images does not work; may run it interactively as follows:
10 $ cd Isabelle/src/Pure
11 $ isabelle RAW_ML_SYSTEM
12 > val ml_system = "mosml";
13 > use "ML-Systems/mosml.ML";
23 (** ML system related **)
25 val ml_system_fix_ints = false;
27 fun forget_structure _ = ();
39 use "ML-Systems/exn.ML";
40 use "ML-Systems/universal.ML";
41 use "ML-Systems/multithreading.ML";
42 use "ML-Systems/time_limit.ML";
45 (*low-level pointer equality*)
46 local val cast : 'a -> int = Obj.magic
47 in fun pointer_eq (x:'a, y:'a) = (cast x = cast y) end;
49 (*proper implementation available?*)
52 fun divMod (x, y) = (x div y, x mod y);
59 val realFloor = real o floor;
65 let val n1 = size s1 and n2 = size s2
66 in if n1 = n2 then s1 = s2 else n1 <= n2 andalso String.substring (s2, n2 - n1, n1) = s1 end;
73 fun toString t = Time.toString t
74 handle Overflow => Real.toString (Time.toReal t); (*workaround Y2004 bug*)
80 structure Process = Process
81 structure FileSys = FileSys
84 exception Option = Option.Option;
87 (*limit the printing depth*)
91 fun get_print_depth () = ! depth;
94 Meta.printDepth := n div 2;
95 Meta.printLength := n);
98 (*interface for toplevel pretty printers, see also Pure/pure_setup.ML*)
99 (*the documentation refers to an installPP but I couldn't fine it!*)
100 fun make_pp path pprint = ();
101 fun install_pp _ = ();
103 (*dummy implementation*)
104 fun ml_prompts p1 p2 = ();
106 (*dummy implementation*)
107 fun profile (n: int) f x = f x;
109 (*dummy implementation*)
110 fun exception_trace f = f ();
112 (*dummy implementation*)
116 (** Compiler-independent timing functions **)
120 fun start_timing () =
121 let val CPUtimer = Timer.startCPUTimer();
122 val time = Timer.checkCPUTimer(CPUtimer)
123 in (CPUtimer,time) end;
125 fun end_timing (CPUtimer, {gc,sys,usr}) =
126 let open Time (*...for Time.toString, Time.+ and Time.- *)
127 val {gc=gc2,sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
128 in "User " ^ toString (usr2-usr) ^
129 " GC " ^ toString (gc2-gc) ^
130 " All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^
135 fun check_timer timer =
136 let val {sys, usr, gc} = Timer.checkCPUTimer timer
137 in (sys, usr, gc) end;
140 (* SML basis library fixes *)
144 fun canInput _ = raise IO.Io {cause = Fail "undefined", function = "canInput", name = ""};
147 let val s = TextIO.inputLine is
148 in if s = "" then NONE else SOME s end;
152 (* ML command execution *)
154 (*Can one redirect 'use' directly to an instream?*)
155 fun use_text (tune: string -> string) _ _ _ txt =
157 val tmp_name = FileSys.tmpName ();
158 val tmp_file = TextIO.openOut tmp_name;
160 TextIO.output (tmp_file, tune txt);
161 TextIO.closeOut tmp_file;
163 FileSys.remove tmp_name
166 fun use_file _ _ _ name = use name;
170 (** interrupts **) (*Note: may get into race conditions*)
172 (* FIXME proper implementation available? *)
176 fun interruptible f x = f x;
177 fun uninterruptible f x = f (fn (g: 'c -> 'd) => g) x;
183 (*dummy implementation*)
195 let val is = TextIO.openIn name
196 in TextIO.inputAll is before TextIO.closeIn is end;
198 fun write_file name txt =
199 let val os = TextIO.openOut name
200 in TextIO.output (os, txt) before TextIO.closeOut os end;
204 fun system_out script =
206 val script_name = OS.FileSys.tmpName ();
207 val _ = write_file script_name script;
209 val output_name = OS.FileSys.tmpName ();
212 OS.Process.system ("perl -w \"$ISABELLE_HOME/lib/scripts/system.pl\" nogroup " ^
213 script_name ^ " /dev/null " ^ output_name);
214 val rc = if status = OS.Process.success then 0 else 1;
216 val output = read_file output_name handle IO.Io _ => "";
217 val _ = OS.FileSys.remove script_name handle OS.SysErr _ => ();
218 val _ = OS.FileSys.remove output_name handle OS.SysErr _ => ();
223 val cd = OS.FileSys.chDir;
224 val pwd = OS.FileSys.getDir;
226 val string_of_pid = Int.toString;
229 (case Process.getEnv var of