src/Pure/ML-Systems/polyml.ML
author wenzelm
Thu, 28 May 1998 17:02:29 +0200
changeset 4984 d17004d4c13b
parent 4977 6cec2c0ffdbf
child 5038 301c37df931d
permissions -rw-r--r--
fixed ml_prompts;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/polyml.ML
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     4
    Copyright   1991  University of Cambridge
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     5
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
     6
Compatibility file for Poly/ML (versions 2.x and 3.x).
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     7
*)
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     8
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     9
open PolyML ExtendedIO;
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    10
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    11
(*needs the Basis Library emulation*)
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    12
use "basis.ML";
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    13
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    14
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    15
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    16
(** ML system related **)
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    17
4326
7211ea5f29e2 New timing functions startTiming and endTiming
paulson
parents: 3631
diff changeset
    18
(** Compiler-independent timing functions **)
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    19
4326
7211ea5f29e2 New timing functions startTiming and endTiming
paulson
parents: 3631
diff changeset
    20
(*Note start point for timing*)
7211ea5f29e2 New timing functions startTiming and endTiming
paulson
parents: 3631
diff changeset
    21
fun startTiming() = System.processtime ();
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    22
4326
7211ea5f29e2 New timing functions startTiming and endTiming
paulson
parents: 3631
diff changeset
    23
(*Finish timing and return string*)
7211ea5f29e2 New timing functions startTiming and endTiming
paulson
parents: 3631
diff changeset
    24
fun endTiming before = 
7211ea5f29e2 New timing functions startTiming and endTiming
paulson
parents: 3631
diff changeset
    25
  "User + GC: " ^ 
7211ea5f29e2 New timing functions startTiming and endTiming
paulson
parents: 3631
diff changeset
    26
  makestring (real (System.processtime () - before) / 10.0) ^ 
7211ea5f29e2 New timing functions startTiming and endTiming
paulson
parents: 3631
diff changeset
    27
  " secs";
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    28
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    29
4977
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    30
(* prompts *)
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    31
4984
d17004d4c13b fixed ml_prompts;
wenzelm
parents: 4977
diff changeset
    32
fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2);
4977
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    33
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    34
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    35
(* toplevel pretty printing (see also Pure/install_pp.ML) *)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    36
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    37
fun make_pp _ pprint (str, blk, brk, en) obj =
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    38
  pprint obj (str, fn ind => blk (ind, false), fn wd => brk (wd, 0),
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    39
    fn () => brk (99999, 0), en);
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    40
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    41
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    42
(* ML command execution -- 'eval' *)
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    43
3631
88a279998f90 renamed use_string to use_strings;
wenzelm
parents: 3588
diff changeset
    44
val use_strings =
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    45
  let
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    46
    fun exec line =
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    47
      let
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    48
        val is_first = ref true;
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    49
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    50
        fun get_line () =
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    51
          if ! is_first then (is_first := false; line)
3631
88a279998f90 renamed use_string to use_strings;
wenzelm
parents: 3588
diff changeset
    52
          else raise Io "use_strings: buffer exhausted";
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    53
      in
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    54
        PolyML.compiler (get_line, print) ()
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    55
      end;
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    56
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    57
    fun execs [] = ()
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    58
      | execs (line :: lines) = (exec line; execs lines);
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    59
  in execs end;
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    60
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    61
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    62
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    63
(** OS related **)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    64
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    65
local
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    66
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    67
fun drop_last [] = []
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    68
  | drop_last [x] = []
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    69
  | drop_last (x :: xs) = x :: drop_last xs;
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    70
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    71
val drop_last_char = implode o drop_last o explode;
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    72
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    73
in
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    74
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    75
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    76
(* system command execution *)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    77
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    78
(*execute Unix command which doesn't take any input from stdin and
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    79
  sends its output to stdout*)
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    80
fun execute command =
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    81
  let
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    82
    val (is, os) =  ExtendedIO.execute command;
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    83
    val result = input (is, 999999);
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    84
  in
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    85
    close_out os;
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    86
    close_in is;
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    87
    result
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    88
  end;
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    89
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    90
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    91
(* file handling *)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    92
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    93
(*get time of last modification; if file doesn't exist return an empty string*)
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    94
fun file_info "" = ""		(* FIXME !? *)
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    95
  | file_info name = Int.toString (System.filedate name) handle _ => "";
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    96
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    97
structure OS =
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    98
struct
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    99
  structure FileSys =
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   100
  struct
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   101
    val chDir = PolyML.cd;
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   102
    fun remove name = (execute ("rm " ^ name); ());
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   103
    fun getDir () = drop_last_char (execute "pwd");
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   104
  end;
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   105
end;
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   106
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   107
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   108
(* getenv *)
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   109
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   110
fun getenv var = drop_last_char
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   111
  (execute ("env | grep '^" ^ var ^ "=' | sed -e 's/" ^ var ^ "=//'"));
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   112
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
   113
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
   114
end;
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
   115
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
   116
4428
5c26253b8a2e tuned comment;
wenzelm
parents: 4326
diff changeset
   117
(* non-ASCII input (see also Thy/use.ML) *)
2408
acddf41dbbf7 added needs_filtered_use;
wenzelm
parents: 2341
diff changeset
   118
acddf41dbbf7 added needs_filtered_use;
wenzelm
parents: 2341
diff changeset
   119
val needs_filtered_use =
acddf41dbbf7 added needs_filtered_use;
wenzelm
parents: 2341
diff changeset
   120
  (case explode ml_system of
acddf41dbbf7 added needs_filtered_use;
wenzelm
parents: 2341
diff changeset
   121
    "p" :: "o" :: "l" :: "y" :: "m" :: "l" :: "-" :: "3" :: _ => true
acddf41dbbf7 added needs_filtered_use;
wenzelm
parents: 2341
diff changeset
   122
  | _ => false);