src/Pure/ML-Systems/smlnj-1.07.ML
author wenzelm
Tue, 27 May 1997 15:45:07 +0200
changeset 3362 0b268cff9344
parent 2409 f4505fe0bd22
permissions -rw-r--r--
NJ 1.09.2x as factory default!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2409
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/smlnj-1.07.ML
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
     3
    Author:     Carsten Clasohm, TU Muenchen
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
     4
    Copyright   1996  TU Muenchen
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
     5
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
     6
Compatibility file for Standard ML of New Jersey, version 1.07.
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
     7
*)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
     8
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
     9
use "basis.ML";
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    10
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    11
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    12
(*** Poly/ML emulation ***)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    13
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    14
fun quit () = exit 0;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    15
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    16
(*To limit the printing depth [divided by 2 for comparibility with Poly/ML]*)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    17
fun print_depth n = (Compiler.Control.Print.printDepth := n div 2;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    18
                     Compiler.Control.Print.printLength := n);
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    19
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    20
(*Interface for toplevel pretty printers, see also Pure/install_pp.ML*)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    21
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    22
fun make_pp path pprint =
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    23
  let
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    24
    open Compiler.PrettyPrint;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    25
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    26
    fun pp pps obj =
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    27
      pprint obj
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    28
        (add_string pps, begin_block pps INCONSISTENT,
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    29
          fn wd => add_break pps (wd, 0), fn () => add_newline pps,
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    30
          fn () => end_block pps);
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    31
  in
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    32
    (path, pp)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    33
  end;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    34
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    35
fun install_pp (path, pp) = Compiler.PPTable.install_pp path pp;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    36
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    37
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    38
(*** New Jersey ML parameters ***)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    39
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    40
(* Suppresses Garbage Collection messages; doesn't work yet *)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    41
(*System.Runtime.gc 0;*)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    42
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    43
val _ = (Compiler.Control.Print.printLength := 1000;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    44
         Compiler.Control.Print.printDepth := 350;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    45
         Compiler.Control.Print.stringDepth := 250;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    46
         Compiler.Control.Print.signatures := 2);
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    47
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    48
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    49
(*** Character/string functions which are compatible with 0.93 and Poly/ML ***)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    50
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    51
fun ord s = Char.ord (String.sub(s,0));
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    52
val chr = str o Char.chr;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    53
val explode = (map str) o String.explode;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    54
val implode = String.concat;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    55
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    56
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    57
(*** Timing functions ***)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    58
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    59
(*Print microseconds, suppressing trailing zeroes*)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    60
fun umakestring 0 = ""
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    61
  | umakestring n = chr(ord "0" + n div 100000) ^
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    62
                    umakestring(10 * (n mod 100000));
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    63
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    64
(*A conditional timing function: applies f to () and, if the flag is true,
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    65
  prints its runtime. *)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    66
fun cond_timeit flag f =
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    67
  if flag then
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    68
    let fun string_of_time (System.Timer.TIME {sec, usec}) =
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    69
            makestring sec ^ "." ^ (if usec=0 then "0" else umakestring usec)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    70
        open System.Timer;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    71
        val start = start_timer()
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    72
        val result = f();
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    73
        val nongc = check_timer(start)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    74
        and gc = check_timer_gc(start);
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    75
        val both = add_time(nongc, gc)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    76
    in  print("Non GC " ^ string_of_time nongc ^
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    77
               "   GC " ^ string_of_time gc ^
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    78
               "  both "^ string_of_time both ^ " secs\n");
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    79
        result
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    80
    end
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    81
  else f();
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    82
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    83
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    84
(*** File handling ***)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    85
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    86
(*Get time of last modification; if file doesn't exist return an empty string*)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    87
local
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    88
    open System.Timer;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    89
    open System.Unsafe.SysIO;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    90
in
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    91
  fun file_info "" = ""
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    92
    | file_info name = makestring (mtime (PATH name))  handle _ => "";
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    93
end;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    94
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    95
structure OS =
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    96
  struct
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    97
  structure FileSys =
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    98
    struct
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
    99
    val chDir = System.Directory.cd
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   100
    val remove = System.Unsafe.SysIO.unlink       (*Delete a file *)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   101
    val getDir = System.Directory.getWD           (*path of working directory*)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   102
    end
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   103
  end;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   104
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   105
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   106
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   107
(*** ML command execution ***)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   108
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   109
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   110
(*For version 109.21 and later:
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   111
val use_string = Compiler.Interact.useStream o TextIO.openString o implode;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   112
*)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   113
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   114
(*For versions prior to 109.21:*)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   115
fun use_string commands = 
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   116
   Compiler.Interact.use_stream (open_string (implode commands));
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   117
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   118
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   119
(*** System command execution ***)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   120
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   121
(*Execute an Unix command which doesn't take any input from stdin and
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   122
  sends its output to stdout.
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   123
  This could be done more easily by Unix.execute, but that function
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   124
  doesn't use the PATH.*)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   125
fun execute command =
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   126
  let val tmp_name = "isa_converted.tmp"
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   127
      val is = (System.Unix.system (command ^ " > " ^ tmp_name);
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   128
                open_in tmp_name);
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   129
      val result = input (is, 999999);
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   130
  in close_in is;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   131
     OS.FileSys.remove tmp_name;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   132
     result
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   133
  end;
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   134
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   135
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   136
(* symbol input *)
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   137
f4505fe0bd22 Compatibility file for Standard ML of New Jersey, version 1.07.
wenzelm
parents:
diff changeset
   138
val needs_filtered_use = false;