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 **)
22 (* Poly/ML emulation *)
32 (*proper implementation available?*)
41 val realFloor = real o floor;
47 fun toString t = Time.toString t
48 handle Overflow => Real.toString (Time.toReal t); (*workaround Y2004 bug*)
54 structure Process = Process
55 structure FileSys = FileSys
58 (*limit the printing depth*)
60 (Meta.printDepth := n div 2;
61 Meta.printLength := n);
63 (*interface for toplevel pretty printers, see also Pure/install_pp.ML*)
64 (*the documentation refers to an installPP but I couldn't fine it!*)
65 fun make_pp path pprint = ();
66 fun install_pp _ = ();
70 fun ml_prompts p1 p2 = ();
73 (** Compiler-independent timing functions **)
77 use "ML-Systems/cpu-timer-gc.ML";
79 (* bounded time execution *)
81 (* FIXME proper implementation available? *)
83 structure TimeLimit : sig
85 val timeLimit : Time.time -> ('a -> 'b) -> 'a -> 'b
92 (* ML command execution *)
94 (*Can one redirect 'use' directly to an instream?*)
95 fun use_text _ _ txt =
97 val tmp_name = FileSys.tmpName ();
98 val tmp_file = TextIO.openOut tmp_name;
100 TextIO.output (tmp_file, txt);
101 TextIO.closeOut tmp_file;
103 FileSys.remove tmp_name
108 (** interrupts **) (*Note: may get into race conditions*)
110 (* FIXME proper implementation available? *)
114 fun ignore_interrupt f x = f x;
115 fun raise_interrupt f x = f x;
121 (* system command execution *)
123 (*execute Unix command which doesn't take any input from stdin and
124 sends its output to stdout; could be done more easily by Unix.execute,
125 but that function doesn't use the PATH*)
126 fun execute command =
128 val tmp_name = FileSys.tmpName ();
129 val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn
131 val result = TextIO.inputAll is;
134 FileSys.remove tmp_name;
138 (*plain version; with return code*)
140 if Process.system cmd = Process.success then 0 else 1;
146 (case Process.getEnv var of