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.00
8 NOTE: saving images does not work (yet!?), 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 fun toString t = Time.toString t
51 handle Overflow => Real.toString (Time.toReal t); (*workaround Y2004 bug*)
57 structure Process = Process
58 structure FileSys = FileSys
61 (*limit the printing depth*)
63 (Meta.printDepth := n div 2;
64 Meta.printLength := n);
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 _ = ();
71 (*profiling -- dummy implementation*)
72 fun profile (n: int) f x = f x;
74 (*prompts -- dummy impelemtation*)
75 fun ml_prompts p1 p2 = ();
78 (** Compiler-independent timing functions **)
82 use "ML-Systems/cpu-timer-gc.ML";
84 (* bounded time execution *)
86 (* FIXME proper implementation available? *)
88 structure TimeLimit : sig
90 val timeLimit : Time.time -> ('a -> 'b) -> 'a -> 'b
98 (* ML command execution *)
100 (*Can one redirect 'use' directly to an instream?*)
101 fun use_text _ _ txt =
103 val tmp_name = FileSys.tmpName ();
104 val tmp_file = TextIO.openOut tmp_name;
106 TextIO.output (tmp_file, txt);
107 TextIO.closeOut tmp_file;
109 FileSys.remove tmp_name
114 (** interrupts **) (*Note: may get into race conditions*)
116 (* FIXME proper implementation available? *)
120 fun ignore_interrupt f x = f x;
121 fun raise_interrupt f x = f x;
127 (* system command execution *)
129 (*execute Unix command which doesn't take any input from stdin and
130 sends its output to stdout; could be done more easily by Unix.execute,
131 but that function doesn't use the PATH*)
132 fun execute command =
134 val tmp_name = FileSys.tmpName ();
135 val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn
137 val result = TextIO.inputAll is;
140 FileSys.remove tmp_name;
144 (*plain version; with return code*)
146 if Process.system cmd = Process.success then 0 else 1;
152 (case Process.getEnv var of