src/Pure/POLY.ML
author paulson
Thu Jun 05 13:28:32 1997 +0200 (1997-06-05)
changeset 3406 131262e21ada
parent 2724 ddc6cf6b62e9
permissions -rw-r--r--
There was never need for another copy of radixstring...
clasohm@0
     1
(*  Title:      Pure/POLY
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1991  University of Cambridge
clasohm@0
     5
clasohm@0
     6
Compatibility file for Poly/ML (AHL release 1.88)
clasohm@0
     7
*)
clasohm@0
     8
clasohm@0
     9
open PolyML ExtendedIO;
clasohm@0
    10
paulson@2242
    11
use"basis.ML";
paulson@2141
    12
clasohm@0
    13
(*A conditional timing function: applies f to () and, if the flag is true,
clasohm@0
    14
  prints its runtime.*)
clasohm@0
    15
clasohm@0
    16
fun cond_timeit flag f =
clasohm@0
    17
  if flag then
clasohm@0
    18
    let val before = System.processtime()
clasohm@0
    19
        val result = f()
clasohm@0
    20
        val both = real(System.processtime() - before) / 10.0
clasohm@0
    21
    in  output(std_out, "Process time (incl GC): "^
clasohm@0
    22
                         makestring both ^ " secs\n");
clasohm@0
    23
        result
clasohm@0
    24
    end
clasohm@0
    25
  else f();
clasohm@0
    26
clasohm@0
    27
clasohm@0
    28
(*Save function: in Poly/ML, ignores filename and commits to present file*)
clasohm@0
    29
clasohm@0
    30
fun xML filename banner = commit();
clasohm@0
    31
clasohm@0
    32
clasohm@0
    33
(*Interface for toplevel pretty printers, see also Pure/install_pp.ML*)
clasohm@0
    34
clasohm@0
    35
fun make_pp _ pprint (str, blk, brk, en) obj =
wenzelm@19
    36
  pprint obj (str, fn ind => blk (ind, false), fn wd => brk (wd, 0),
wenzelm@19
    37
    fn () => brk (99999, 0), en);
clasohm@0
    38
clasohm@0
    39
lcp@66
    40
(*** File handling ***)
clasohm@0
    41
clasohm@100
    42
local
clasohm@100
    43
clasohm@100
    44
(*These are functions from library.ML *)
clasohm@100
    45
fun take_suffix _ [] = ([], [])
clasohm@100
    46
  | take_suffix pred (x :: xs) =
clasohm@100
    47
      (case take_suffix pred xs of
clasohm@100
    48
         ([], sffx) => if pred x then ([], x :: sffx)
clasohm@100
    49
                                 else ([x], sffx)
clasohm@100
    50
       | (prfx, sffx) => (x :: prfx, sffx));
clasohm@100
    51
clasohm@100
    52
fun apr (f,y) x = f(x,y);
clasohm@100
    53
clasohm@396
    54
fun seq (proc: 'a -> unit) : 'a list -> unit =
clasohm@396
    55
  let fun seqf [] = ()
clasohm@396
    56
        | seqf (x :: xs) = (proc x; seqf xs)
clasohm@396
    57
  in seqf end;
clasohm@396
    58
clasohm@100
    59
in
clasohm@100
    60
clasohm@1480
    61
(*Get time of last modification; if file doesn't exist return an empty string*)
clasohm@0
    62
fun file_info "" = ""
paulson@3406
    63
  | file_info name = makestring (System.filedate name)  handle _ => "";
lcp@66
    64
paulson@2242
    65
paulson@2242
    66
structure OS =
paulson@2242
    67
  struct
paulson@2242
    68
  structure FileSys =
paulson@2242
    69
    struct
paulson@2242
    70
    val chDir = PolyML.cd
paulson@2242
    71
paulson@2242
    72
    fun remove name =    (*Delete a file *)
paulson@2242
    73
      let val (is, os) = ExtendedIO.execute ("rm " ^ name)
paulson@2242
    74
      in close_in is; close_out os end;
paulson@2242
    75
paulson@2242
    76
    (*Get pathname of current working directory *)
paulson@2242
    77
    fun getDir () =
paulson@2242
    78
      let val (is, os) = ExtendedIO.execute ("pwd")
paulson@2242
    79
	  val (path, _) = take_suffix (apr(op=,"\n")) (*remove newline*)
paulson@2242
    80
			   (explode (ExtendedIO.input_line is)) 
paulson@2242
    81
      in close_in is; close_out os; implode path end;
paulson@2242
    82
paulson@2242
    83
    end
clasohm@100
    84
  end;
clasohm@100
    85
clasohm@100
    86
clasohm@378
    87
clasohm@378
    88
(*** ML command execution ***)
clasohm@378
    89
clasohm@396
    90
val use_string =
clasohm@396
    91
  let fun exec command =
clasohm@396
    92
    let val firstLine = ref true;
clasohm@396
    93
clasohm@396
    94
        fun getLine () =
clasohm@396
    95
          if !firstLine
clasohm@396
    96
          then (firstLine := false; command)
clasohm@396
    97
          else raise Io "use_string: buffer exhausted"
clasohm@396
    98
    in PolyML.compiler (getLine, fn s => output (std_out, s)) () end
clasohm@396
    99
  in seq exec end;
clasohm@396
   100
clasohm@396
   101
end;
clasohm@1289
   102
clasohm@1289
   103
clasohm@1289
   104
(*** System command execution ***)
clasohm@1289
   105
clasohm@1289
   106
(*Execute an Unix command which doesn't take any input from stdin and
clasohm@1289
   107
  sends its output to stdout.*)
clasohm@1289
   108
fun execute command =
clasohm@1289
   109
  let val (is, os) =  ExtendedIO.execute command;
clasohm@1289
   110
      val result = input (is, 999999);
clasohm@1289
   111
  in close_out os;
clasohm@1289
   112
     close_in is;
clasohm@1289
   113
     result
clasohm@1289
   114
  end;
wenzelm@2408
   115
wenzelm@2408
   116
paulson@2724
   117
(*Non-printing and 8-bit chars are forbidden in string constants*)
wenzelm@2408
   118
val needs_filtered_use = true;