src/Pure/ML-Systems/polyml.ML
author wenzelm
Mon, 29 Jun 1998 10:32:06 +0200
changeset 5090 75ac9b451ae0
parent 5038 301c37df931d
child 5813 4eea84a9427d
permissions -rw-r--r--
use_text: verbose flag;
     1 (*  Title:      Pure/ML-Systems/polyml.ML
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1991  University of Cambridge
     5 
     6 Compatibility file for Poly/ML (versions 2.x and 3.x).
     7 *)
     8 
     9 open PolyML ExtendedIO;
    10 
    11 (*needs the Basis Library emulation*)
    12 use "basis.ML";
    13 
    14 
    15 
    16 (** ML system related **)
    17 
    18 (** Compiler-independent timing functions **)
    19 
    20 (*Note start point for timing*)
    21 fun startTiming() = System.processtime ();
    22 
    23 (*Finish timing and return string*)
    24 fun endTiming before = 
    25   "User + GC: " ^ 
    26   makestring (real (System.processtime () - before) / 10.0) ^ 
    27   " secs";
    28 
    29 
    30 (* prompts *)
    31 
    32 fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2);
    33 
    34 
    35 (* toplevel pretty printing (see also Pure/install_pp.ML) *)
    36 
    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);
    40 
    41 
    42 (* ML command execution -- 'eval' *)
    43 
    44 fun use_text verbose txt =
    45   let
    46     val in_buffer = ref (explode txt);
    47     val out_buffer = ref ([]: string list);
    48 
    49     fun get () =
    50       (case ! in_buffer of
    51         [] => ""
    52       | c :: cs => (in_buffer := cs; c));
    53     fun put s = out_buffer := s :: ! out_buffer;
    54 
    55     fun exec () =
    56       (case ! in_buffer of
    57         [] => ()
    58       | _ => (PolyML.compiler (get, put) (); exec ()));
    59 
    60     fun show_output () = print (implode (rev (! out_buffer)));
    61   in
    62     exec () handle exn => (show_output (); raise exn);
    63     if verbose then show_output () else ()
    64   end;
    65 
    66 
    67 
    68 (** OS related **)
    69 
    70 local
    71 
    72 fun drop_last [] = []
    73   | drop_last [x] = []
    74   | drop_last (x :: xs) = x :: drop_last xs;
    75 
    76 val drop_last_char = implode o drop_last o explode;
    77 
    78 in
    79 
    80 
    81 (* system command execution *)
    82 
    83 (*execute Unix command which doesn't take any input from stdin and
    84   sends its output to stdout*)
    85 fun execute command =
    86   let
    87     val (is, os) =  ExtendedIO.execute command;
    88     val result = input (is, 999999);
    89   in
    90     close_out os;
    91     close_in is;
    92     result
    93   end;
    94 
    95 
    96 (* file handling *)
    97 
    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 _ => "";
   101 
   102 structure OS =
   103 struct
   104   structure FileSys =
   105   struct
   106     val chDir = PolyML.cd;
   107     fun remove name = (execute ("rm " ^ name); ());
   108     fun getDir () = drop_last_char (execute "pwd");
   109   end;
   110 end;
   111 
   112 
   113 (* getenv *)
   114 
   115 fun getenv var = drop_last_char
   116   (execute ("env | grep '^" ^ var ^ "=' | sed -e 's/" ^ var ^ "=//'"));
   117 
   118 
   119 end;
   120 
   121 
   122 (* non-ASCII input (see also Thy/use.ML) *)
   123 
   124 val needs_filtered_use =
   125   (case explode ml_system of
   126     "p" :: "o" :: "l" :: "y" :: "m" :: "l" :: "-" :: "3" :: _ => true
   127   | _ => false);