src/Pure/ML-Systems/smlnj.ML
author wenzelm
Mon, 15 Jun 1998 11:06:00 +0200
changeset 5038 301c37df931d
parent 4977 6cec2c0ffdbf
child 5090 75ac9b451ae0
permissions -rw-r--r--
use_text replaces use_strings;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/smlnj.ML
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     3
    Author:     Carsten Clasohm and Markus Wenzel, TU Muenchen
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     4
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     5
Compatibility file for Standard ML of New Jersey versions 109.27 to
4407
7d4e2832b791 tuned comment;
wenzelm
parents: 4403
diff changeset
     6
109.33, and 110 or later.
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     7
*)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     8
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     9
(** ML system related **)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    10
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    11
(* restore old-style character / string functions *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    12
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    13
fun ord s = Char.ord (String.sub (s, 0));
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    14
val chr = str o Char.chr;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    15
val explode = (map str) o String.explode;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    16
val implode = String.concat;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    17
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    18
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    19
(* New Jersey ML parameters *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    20
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    21
val _ =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    22
 (Compiler.Control.Print.printLength := 1000;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    23
  Compiler.Control.Print.printDepth := 350;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    24
  Compiler.Control.Print.stringDepth := 250;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    25
  Compiler.Control.Print.signatures := 2);
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    26
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    27
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    28
(* Poly/ML emulation *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    29
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    30
fun quit () = exit 0;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    31
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    32
(*limit the printing depth -- divided by 2 for comparibility with Poly/ML*)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    33
fun print_depth n =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    34
 (Compiler.Control.Print.printDepth := n div 2;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    35
  Compiler.Control.Print.printLength := n);
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    36
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    37
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    38
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    39
(** Compiler-independent timing functions **)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    40
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    41
(*Note start point for timing*)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    42
fun startTiming() = 
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    43
  let val CPUtimer = Timer.startCPUTimer();
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    44
      val time = Timer.checkCPUTimer(CPUtimer)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    45
  in  (CPUtimer,time)  end;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    46
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    47
(*Finish timing and return string*)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    48
fun endTiming (CPUtimer, {gc,sys,usr}) =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    49
  let open Time  (*...for Time.toString, Time.+ and Time.- *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    50
      val {gc=gc2,sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    51
  in  "User " ^ toString (usr2-usr) ^
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    52
      "  GC " ^ toString (gc2-gc) ^
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    53
      "  All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    54
      " secs"
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    55
      handle Time => ""
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    56
  end;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    57
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    58
4977
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    59
(* prompts *)
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    60
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    61
fun ml_prompts p1 p2 =
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    62
  (Compiler.Control.primaryPrompt := p1; Compiler.Control.secondaryPrompt := p2);
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    63
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    64
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    65
(* toplevel pretty printing (see also Pure/install_pp.ML) *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    66
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    67
fun make_pp path pprint =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    68
  let
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    69
    open Compiler.PrettyPrint;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    70
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    71
    fun pp pps obj =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    72
      pprint obj
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    73
        (add_string pps, begin_block pps INCONSISTENT,
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    74
          fn wd => add_break pps (wd, 0), fn () => add_newline pps,
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    75
          fn () => end_block pps);
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    76
  in
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    77
    (path, pp)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    78
  end;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    79
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    80
fun install_pp (path, pp) = Compiler.PPTable.install_pp path pp;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    81
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    82
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    83
(* ML command execution *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    84
5038
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4977
diff changeset
    85
val use_text = Compiler.Interact.useStream o TextIO.openString;
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    86
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    87
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    88
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    89
(** OS related **)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    90
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    91
(* system command execution *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    92
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    93
(*execute Unix command which doesn't take any input from stdin and
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    94
  sends its output to stdout; could be done more easily by Unix.execute,
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    95
  but that function doesn't use the PATH*)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    96
fun execute command =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    97
  let
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    98
    val tmp_name = OS.FileSys.tmpName ();
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    99
    val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   100
    val result = TextIO.inputAll is;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   101
  in
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   102
    TextIO.closeIn is;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   103
    OS.FileSys.remove tmp_name;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   104
    result
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   105
  end;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   106
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   107
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   108
(* file handling *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   109
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   110
(*get time of last modification; if file doesn't exist return an empty string*)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   111
fun file_info "" = ""		(* FIXME !? *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   112
  | file_info name = Time.toString (OS.FileSys.modTime name) handle _ => "";
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   113
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   114
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   115
(* getenv *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   116
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   117
fun getenv var =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   118
  (case OS.Process.getEnv var of
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   119
    NONE => ""
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   120
  | SOME txt => txt);
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   121
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   122
4428
5c26253b8a2e tuned comment;
wenzelm
parents: 4407
diff changeset
   123
(* non-ASCII input (see also Thy/use.ML) *)
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   124
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   125
val needs_filtered_use = false;