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:
11 $ isabelle RAW_ML_SYSTEM
12 > val ml_system = "mosml";
13 > use "ML-Systems/mosml.ML";
20 (** ML system related **)
32 (*low-level pointer equality*)
33 local val cast : 'a -> int = Obj.magic
34 in fun pointer_eq (x:'a, y:'a) = (cast x = cast y) end;
36 (*proper implementation available?*)
45 val realFloor = real o floor;
51 let val n1 = size s1 and n2 = size s2
52 in if n1 = n2 then s1 = s2 else n1 <= n2 andalso String.substring (s2, n2 - n1, n1) = s1 end;
59 fun toString t = Time.toString t
60 handle Overflow => Real.toString (Time.toReal t); (*workaround Y2004 bug*)
66 structure Process = Process
67 structure FileSys = FileSys
70 (*limit the printing depth*)
72 (Meta.printDepth := n div 2;
73 Meta.printLength := n);
75 (*interface for toplevel pretty printers, see also Pure/install_pp.ML*)
76 (*the documentation refers to an installPP but I couldn't fine it!*)
77 fun make_pp path pprint = ();
78 fun install_pp _ = ();
80 (*dummy implementation*)
81 fun ml_prompts p1 p2 = ();
83 (*dummy implementation*)
84 fun profile (n: int) f x = f x;
86 (*dummy implementation*)
87 fun exception_trace f = f ();
89 (*dummy implementation*)
93 (** Compiler-independent timing functions **)
98 let val CPUtimer = Timer.startCPUTimer();
99 val time = Timer.checkCPUTimer(CPUtimer)
100 in (CPUtimer,time) end;
102 fun end_timing (CPUtimer, {gc,sys,usr}) =
103 let open Time (*...for Time.toString, Time.+ and Time.- *)
104 val {gc=gc2,sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
105 in "User " ^ toString (usr2-usr) ^
106 " GC " ^ toString (gc2-gc) ^
107 " All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^
112 fun check_timer timer =
113 let val {sys, usr, gc} = Timer.checkCPUTimer timer
114 in (sys, usr, gc) end;
117 (* SML basis library fixes *)
121 fun canInput _ = raise IO.Io {cause = Fail "undefined", function = "canInput", name = ""};
126 (* bounded time execution *)
128 (*dummy implementation*)
129 fun interrupt_timeout time f x =
133 (* ML command execution *)
135 (*Can one redirect 'use' directly to an instream?*)
136 fun use_text _ _ txt =
138 val tmp_name = FileSys.tmpName ();
139 val tmp_file = TextIO.openOut tmp_name;
141 TextIO.output (tmp_file, txt);
142 TextIO.closeOut tmp_file;
144 FileSys.remove tmp_name
147 fun use_file _ _ name = PolyML.use name;
151 (** interrupts **) (*Note: may get into race conditions*)
153 (* FIXME proper implementation available? *)
157 fun ignore_interrupt f x = f x;
158 fun raise_interrupt f x = f x;
164 (* system command execution *)
166 (*execute Unix command which doesn't take any input from stdin and
167 sends its output to stdout; could be done more easily by Unix.execute,
168 but that function doesn't use the PATH*)
169 fun execute command =
171 val tmp_name = FileSys.tmpName ();
172 val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
173 val result = TextIO.inputAll is;
176 FileSys.remove tmp_name;
180 (*plain version; with return code*)
182 if Process.system cmd = Process.success then 0 else 1;
185 val string_of_pid = Int.toString;
191 (case Process.getEnv var of