src/Pure/ML-Systems/poplogml.ML
author wenzelm
Tue, 24 Jul 2007 19:44:33 +0200
changeset 23962 e0358fac0541
parent 22144 c33450acd873
child 24329 f31594168d27
permissions -rw-r--r--
Runtime exceptions as values (from library.ML);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/poplogml.ML
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
     4
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
     5
Compatibility file for Poplog/PML (version 15.6/2.1).
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
     6
*)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
     7
17798
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
     8
(* Compiler and runtime options *)
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
     9
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    10
val _ = Compile.filetype := ".ML";
17808
81c113e4d6fc tuned Memory.hilim;
wenzelm
parents: 17798
diff changeset
    11
val _ = Memory.hilim := let fun MB n = n div 4 * 1024 * 1024 in MB 120 end;
17798
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    12
val _ = Memory.stacklim := 10 * ! Memory.stacklim;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    13
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    14
fun pointer_eq (_: 'a, _: 'a) = false;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    15
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    16
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    17
(* ML toplevel *)
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    18
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    19
fun ml_prompts p1 p2 = ();
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    20
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    21
fun make_pp path pprint = ();
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    22
fun install_pp _ = ();
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    23
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    24
fun print_depth _ = ();
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    25
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    26
fun exception_trace f = f ();
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    27
fun profile (n: int) f x = f x;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    28
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    29
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    30
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    31
(** Basis structures **)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    32
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    33
structure General =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    34
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    35
  exception Subscript = Array.Subscript;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    36
  exception Size;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    37
  exception Fail of string;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    38
  fun exnMessage (exn: exn) = "exception " ^ makestring exn ^ " raised";
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    39
  datatype order = LESS | EQUAL | GREATER;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    40
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    41
open General;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    42
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    43
structure Bool =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    44
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    45
  val toString: bool -> string = makestring;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    46
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    47
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    48
structure Option =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    49
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    50
  open Option;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    51
  exception Option;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    52
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    53
  fun valOf (SOME x) = x
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    54
    | valOf NONE = raise Option;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    55
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    56
  fun getOpt (SOME x, _) = x
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    57
    | getOpt (NONE, x) = x;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    58
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    59
  fun isSome (SOME _) = true
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    60
    | isSome NONE = false;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    61
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    62
open Option;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    63
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    64
structure Option =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    65
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    66
  open Option;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    67
  fun map f (SOME x) = SOME (f x)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    68
    | map _ NONE = NONE;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    69
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    70
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    71
structure Int =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    72
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    73
  open Int;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    74
  type int = int;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    75
  val toString: int -> string = makestring;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    76
  fun fromInt (i: int) = i;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    77
  val fromString = String.stringint;
17798
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    78
  val op + = op + : int * int -> int;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    79
  val op - = op - : int * int -> int;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    80
  val op * = op * : int * int -> int;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    81
  val op div = op div : int * int -> int;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    82
  val op mod = op mod : int * int -> int;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    83
  fun pow (x, y) = power x y : int;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    84
  val op < = op < : int * int -> bool;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    85
  val op > = op > : int * int -> bool;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    86
  val op <= = op <= : int * int -> bool;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    87
  val op >= = op >= : int * int -> bool;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    88
  val abs = abs: int -> int;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
    89
  val sign = sign: int -> int;
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    90
  fun max (x, y) : int = if x < y then y else x;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    91
  fun min (x, y) : int = if x < y then x else y;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    92
  fun compare (x: int, y) = if x = y then EQUAL else if x < y then LESS else GREATER;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    93
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    94
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    95
structure IntInf = Int;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    96
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    97
structure Real =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    98
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
    99
  open Real;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   100
  val toString: real -> string = makestring;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   101
  fun max (x, y) : real = if x < y then y else x;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   102
  fun min (x, y) : real = if x < y then x else y;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   103
  val real = real;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   104
  val floor = floor;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   105
  val realFloor = real o floor;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   106
  fun ceil x = ~1 - floor (~ (x + 1.0));
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   107
  fun round x = floor (x + 0.5);  (*does not do round-to-nearest*)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   108
  fun trunc x = if x < 0.0 then ceil x else floor x;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   109
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   110
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   111
structure String =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   112
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   113
  open String;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   114
  type char = string
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   115
  fun str (c: char) = c: string;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   116
  val translate = mapstring;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   117
  val isPrefix = isprefix;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   118
  val isSuffix = issuffix;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   119
  val size = size;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   120
  fun compare (x: string, y) = if x = y then EQUAL else if x < y then LESS else GREATER;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   121
  fun substring (s, i, n) = String.substring i (i + n) s
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   122
    handle String.Substring => raise Subscript;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   123
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   124
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   125
structure List =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   126
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   127
  open List;
17798
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   128
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   129
  exception Empty;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   130
  fun null [] = true | null _ = false;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   131
  fun hd (x :: _) = x | hd _ = raise Empty;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   132
  fun tl (_ :: xs) = xs | tl _ = raise Empty;
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   133
  val map = map;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   134
17798
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   135
  fun foldl f b [] = b
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   136
    | foldl f b (x :: xs) = foldl f (f (x, b)) xs;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   137
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   138
  fun foldr f b [] = b
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   139
    | foldr f b (x :: xs) = f (x, foldr f b xs);
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   140
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   141
  fun last []      = raise Empty
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   142
    | last [x]     = x
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   143
    | last (x::xs) = last xs;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   144
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   145
  fun nth (xs, n) =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   146
      let fun h []      _ = raise Subscript
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   147
            | h (x::xs) n = if n=0 then x else h xs (n-1)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   148
      in if n<0 then raise Subscript else h xs n end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   149
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   150
  fun drop (xs, n) =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   151
      let fun h xs      0 = xs
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   152
            | h []      n = raise Subscript
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   153
            | h (x::xs) n = h xs (n-1)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   154
      in if n<0 then raise Subscript else h xs n end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   155
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   156
  fun take (xs, n) =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   157
      let fun h xs      0 = []
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   158
            | h []      n = raise Subscript
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   159
            | h (x::xs) n = x :: h xs (n-1)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   160
      in if n<0 then raise Subscript else h xs n end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   161
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   162
  fun concat []      = []
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   163
    | concat (l::ls) = l @ concat ls;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   164
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   165
  fun mapPartial f []      = []
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   166
    | mapPartial f (x::xs) =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   167
         (case f x of NONE   => mapPartial f xs
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   168
                    | SOME y => y :: mapPartial f xs);
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   169
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   170
  fun find _ []        = NONE
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   171
    | find p (x :: xs) = if p x then SOME x else find p xs;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   172
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   173
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   174
  (*copy the list preserving elements that satisfy the predicate*)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   175
  fun filter p [] = []
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   176
    | filter p (x :: xs) = if p x then x :: filter p xs else filter p xs;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   177
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   178
  (*Partition list into elements that satisfy predicate and those that don't.
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   179
    Preserves order of elements in both lists.*)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   180
  fun partition (p: 'a->bool) (ys: 'a list) : ('a list * 'a list) =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   181
      let fun part ([], answer) = answer
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   182
            | part (x::xs, (ys, ns)) = if p(x)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   183
              then  part (xs, (x::ys, ns))
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   184
              else  part (xs, (ys, x::ns))
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   185
      in  part (rev ys, ([], []))  end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   186
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   187
end;
17798
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   188
exception Empty = List.Empty;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   189
val null = List.null;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   190
val hd = List.hd;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   191
val tl = List.tl;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   192
val map = List.map;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   193
val foldl = List.foldl;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   194
val foldr = List.foldr;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   195
val app = List.app;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   196
val length = List.length;
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   197
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   198
structure ListPair =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   199
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   200
  fun zip ([], [])      = []
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   201
    | zip (x::xs,y::ys) = (x,y) :: zip(xs,ys);
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   202
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   203
  fun unzip [] = ([],[])
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   204
    | unzip((x,y)::pairs) =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   205
          let val (xs,ys) = unzip pairs
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   206
          in  (x::xs, y::ys)  end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   207
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   208
  fun app f (x::xs, y::ys) = (f (x, y); app f (xs, ys))
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   209
    | app f _ = ();
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   210
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   211
  fun map f ([], [])      = []
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   212
    | map f (x::xs,y::ys) = f(x,y) :: map f (xs,ys);
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   213
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   214
  fun exists p =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   215
    let fun boolf ([], [])      = false
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   216
          | boolf (x::xs,y::ys) = p(x,y) orelse boolf (xs,ys)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   217
    in boolf end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   218
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   219
  fun all p =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   220
    let fun boolf ([], [])      = true
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   221
          | boolf (x::xs,y::ys) = p(x,y) andalso boolf (xs,ys)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   222
    in boolf end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   223
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   224
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   225
structure TextIO =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   226
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   227
  type instream = instream;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   228
  type outstream = outstream;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   229
  exception Io = Io;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   230
  val stdIn = std_in;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   231
  val stdOut = std_out;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   232
  val stdErr = std_err;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   233
  val openIn = open_in;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   234
  val openAppend = open_append;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   235
  val openOut = open_out;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   236
  val closeIn = close_in;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   237
  val closeOut = close_out;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   238
  val inputN = input;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   239
  val inputAll = fn is => inputN (is, 1000000000);
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   240
  val inputLine = input_line;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   241
  val endOfStream = end_of_stream;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   242
  val output = output;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   243
  val flushOut = flush_out;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   244
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   245
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   246
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   247
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   248
(** Compiler-independent timing functions **)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   249
21295
63552bc99cfb tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 18760
diff changeset
   250
fun start_timing() = "FIXME";
63552bc99cfb tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 18760
diff changeset
   251
fun end_timing (s: string) = s;
63552bc99cfb tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 18760
diff changeset
   252
fun check_timer _ = (0, 0, 0);
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   253
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   254
structure Timer =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   255
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   256
  type cpu_timer = int;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   257
  fun startCPUTimer () = 0;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   258
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   259
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   260
structure Time =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   261
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   262
  exception Time;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   263
  type time = int;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   264
  val toString: time -> string = makestring;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   265
  val zeroTime = 0;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   266
  fun now () = 0;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   267
  fun (x: int) + y = x + y;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   268
  fun (x: int) - y = x - y;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   269
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   270
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   271
18760
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18392
diff changeset
   272
(* bounded time execution *)
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18392
diff changeset
   273
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18392
diff changeset
   274
(* FIXME proper implementation available? *)
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18392
diff changeset
   275
fun interrupt_timeout time f x =
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18392
diff changeset
   276
  f x;
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18392
diff changeset
   277
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   278
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   279
(** interrupts **)      (*Note: may get into race conditions*)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   280
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   281
fun ignore_interrupt f x = f x;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   282
fun raise_interrupt f x = f x;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   283
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   284
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   285
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   286
(** OS related **)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   287
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   288
val tmp_name =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   289
  let val count = ref 0 in
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   290
    fn () => (count := ! count + 1;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   291
      "/tmp/pml" ^ Int.toString (OS.pid ()) ^ "." ^ Int.toString (! count))
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   292
  end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   293
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   294
local
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   295
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   296
fun shell cmdline = OS.execve "/bin/sh" ["sh", "-c", cmdline] (OS.envlist());
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   297
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   298
fun execute_rc cmdline =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   299
  let
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   300
    fun wait pid =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   301
      (case OS.wait () of
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   302
        NONE => wait pid
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   303
      | SOME (pid', rc) =>
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   304
          if pid = pid' then rc div 256 else raise OS.Error ("wait", "wrong pid", ""));
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   305
  in
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   306
    (case OS.fork () of
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   307
      NONE => shell cmdline
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   308
    | SOME pid => wait pid)
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   309
  end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   310
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   311
fun squote s = "'" ^ s ^ "'";
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   312
fun remove name = (execute_rc ("/bin/rm -- " ^ squote name); ());
17862
ecd890746fcf use perl for test/stat;
wenzelm
parents: 17824
diff changeset
   313
fun is_dir name = execute_rc ("perl -e \"exit (-d " ^ squote name ^ " ? 0 : 1)\"") = 0;
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   314
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   315
fun execute_result cmdline =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   316
  let
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   317
    val tmp = tmp_name ();
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   318
    val rc = execute_rc (cmdline  ^ " > " ^ tmp);
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   319
    val instream = TextIO.openIn tmp;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   320
    val result = TextIO.inputAll instream;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   321
    val _ = TextIO.closeIn instream;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   322
    val _ = remove tmp;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   323
  in (rc, result) end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   324
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   325
in
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   326
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   327
fun exit rc = shell ("exit " ^ Int.toString rc);
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   328
fun quit () = exit 0;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   329
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   330
fun execute cmdline = #2 (execute_result cmdline);
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   331
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   332
fun system cmdline =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   333
  let val (rc, result) = execute_result cmdline
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   334
  in TextIO.output (TextIO.stdOut, result); TextIO.flushOut TextIO.stdOut; rc end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   335
17824
36b2978d339a added string_of_pid;
wenzelm
parents: 17808
diff changeset
   336
val string_of_pid: int -> string = makestring;
36b2978d339a added string_of_pid;
wenzelm
parents: 17808
diff changeset
   337
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   338
fun getenv var = (case OS.translate var of NONE => "" | SOME s => s);
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   339
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   340
structure OS =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   341
struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   342
  structure FileSys =
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   343
  struct
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   344
    val tmpName = tmp_name;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   345
    val chDir = OS.cd;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   346
    val getDir = OS.pwd;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   347
    val remove = remove;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   348
    val isDir = is_dir;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   349
    val compare = Int.compare;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   350
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   351
    fun modTime name =
17862
ecd890746fcf use perl for test/stat;
wenzelm
parents: 17824
diff changeset
   352
      (case execute ("perl -e '@_ = stat(q:" ^ name ^ ":); print $_[9]'") of
ecd890746fcf use perl for test/stat;
wenzelm
parents: 17824
diff changeset
   353
        "" => raise TextIO.Io "OS.FileSys.modTime"
ecd890746fcf use perl for test/stat;
wenzelm
parents: 17824
diff changeset
   354
      | s => Int.fromString s);
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   355
    fun fileId name =
17862
ecd890746fcf use perl for test/stat;
wenzelm
parents: 17824
diff changeset
   356
      (case execute ("perl -e '@_ = stat(q:" ^ name ^ ":); print $_[1]'") of
ecd890746fcf use perl for test/stat;
wenzelm
parents: 17824
diff changeset
   357
        "" => raise TextIO.Io "OS.FileSys.fileId"
ecd890746fcf use perl for test/stat;
wenzelm
parents: 17824
diff changeset
   358
      | s => Int.fromString s);
17758
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   359
  end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   360
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   361
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   362
end;
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   363
8f443890fab9 Compatibility file for Poplog/PML (version 15.6/2.1).
wenzelm
parents:
diff changeset
   364
17798
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   365
(* use *)
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   366
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   367
local val pml_use = use in
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   368
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   369
fun use name =
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   370
  if name = "ROOT.ML" then   (*workaround error about looping compilations*)
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   371
    let
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   372
      val instream = TextIO.openIn name;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   373
      val txt = TextIO.inputAll instream;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   374
      val _ = TextIO.closeIn;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   375
    in use_string txt end
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   376
  else pml_use name;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   377
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   378
end;
7daef8964aeb tuned memory limits;
wenzelm
parents: 17760
diff changeset
   379
22144
c33450acd873 use_text: added name argument;
wenzelm
parents: 21770
diff changeset
   380
fun use_text _ _ _ txt = use_string txt;
21770
ea6f846d8c4b added use_file;
wenzelm
parents: 21295
diff changeset
   381
fun use_file _ _ name = use name;