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