1 (* Title: Pure/ML-Systems/polyml.ML
3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory
4 Copyright 1991 University of Cambridge
6 Compatibility file for Poly/ML (versions 2.x and 3.x).
9 open PolyML ExtendedIO;
11 (*needs the Basis Library emulation*)
16 (** ML system related **)
18 (** Compiler-independent timing functions **)
20 (*Note start point for timing*)
21 fun startTiming() = System.processtime ();
23 (*Finish timing and return string*)
24 fun endTiming before =
26 makestring (real (System.processtime () - before) / 10.0) ^
32 fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2);
35 (* toplevel pretty printing (see also Pure/install_pp.ML) *)
37 fun make_pp _ pprint (str, blk, brk, en) obj =
38 pprint obj (str, fn ind => blk (ind, false), fn wd => brk (wd, 0),
39 fn () => brk (99999, 0), en);
42 (* ML command execution -- 'eval' *)
44 fun use_text verbose txt =
46 val in_buffer = ref (explode txt);
47 val out_buffer = ref ([]: string list);
52 | c :: cs => (in_buffer := cs; c));
53 fun put s = out_buffer := s :: ! out_buffer;
58 | _ => (PolyML.compiler (get, put) (); exec ()));
60 fun show_output () = print (implode (rev (! out_buffer)));
62 exec () handle exn => (show_output (); raise exn);
63 if verbose then show_output () else ()
74 | drop_last (x :: xs) = x :: drop_last xs;
76 val drop_last_char = implode o drop_last o explode;
81 (* system command execution *)
83 (*execute Unix command which doesn't take any input from stdin and
84 sends its output to stdout*)
87 val (is, os) = ExtendedIO.execute command;
88 val result = input (is, 999999);
98 (*get time of last modification; if file doesn't exist return an empty string*)
99 fun file_info "" = "" (* FIXME !? *)
100 | file_info name = Int.toString (System.filedate name) handle _ => "";
106 val chDir = PolyML.cd;
107 fun remove name = (execute ("rm " ^ name); ());
108 fun getDir () = drop_last_char (execute "pwd");
115 fun getenv var = drop_last_char
116 (execute ("env | grep '^" ^ var ^ "=' | sed -e 's/" ^ var ^ "=//'"));
122 (* non-ASCII input (see also Thy/use.ML) *)
124 val needs_filtered_use =
125 (case explode ml_system of
126 "p" :: "o" :: "l" :: "y" :: "m" :: "l" :: "-" :: "3" :: _ => true