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 **)
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;
35 (*proper implementation available?*)
44 val realFloor = real o floor;
50 let val n1 = size s1 and n2 = size s2
51 in if n1 = n2 then s1 = s2 else n1 <= n2 andalso String.substring (s2, n2 - n1, n1) = s1 end;
58 fun toString t = Time.toString t
59 handle Overflow => Real.toString (Time.toReal t); (*workaround Y2004 bug*)
65 structure Process = Process
66 structure FileSys = FileSys
69 (*limit the printing depth*)
71 (Meta.printDepth := n div 2;
72 Meta.printLength := n);
74 (*interface for toplevel pretty printers, see also Pure/install_pp.ML*)
75 (*the documentation refers to an installPP but I couldn't fine it!*)
76 fun make_pp path pprint = ();
77 fun install_pp _ = ();
79 (*dummy implementation*)
80 fun ml_prompts p1 p2 = ();
82 (*dummy implementation*)
83 fun profile (n: int) f x = f x;
85 (*dummy impelemtation*)
86 fun exception_trace f = f ();
89 (** Compiler-independent timing functions **)
93 use "ML-Systems/cpu-timer-gc.ML";
95 (* bounded time execution *)
97 (* FIXME proper implementation available? *)
99 structure TimeLimit : sig
101 val timeLimit : Time.time -> ('a -> 'b) -> 'a -> 'b
104 fun timeLimit t f x =
109 (* ML command execution *)
111 (*Can one redirect 'use' directly to an instream?*)
112 fun use_text _ _ txt =
114 val tmp_name = FileSys.tmpName ();
115 val tmp_file = TextIO.openOut tmp_name;
117 TextIO.output (tmp_file, txt);
118 TextIO.closeOut tmp_file;
120 FileSys.remove tmp_name
125 (** interrupts **) (*Note: may get into race conditions*)
127 (* FIXME proper implementation available? *)
131 fun ignore_interrupt f x = f x;
132 fun raise_interrupt f x = f x;
138 (* system command execution *)
140 (*execute Unix command which doesn't take any input from stdin and
141 sends its output to stdout; could be done more easily by Unix.execute,
142 but that function doesn't use the PATH*)
143 fun execute command =
145 val tmp_name = FileSys.tmpName ();
146 val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
147 val result = TextIO.inputAll is;
150 FileSys.remove tmp_name;
154 (*plain version; with return code*)
156 if Process.system cmd = Process.success then 0 else 1;
159 val string_of_pid = Int.toString;
165 (case Process.getEnv var of