src/Pure/ML-Systems/mlworks.ML
author wenzelm
Mon, 29 Jun 1998 10:32:06 +0200
changeset 5090 75ac9b451ae0
parent 5038 301c37df931d
child 5660 f2c5354cd32f
permissions -rw-r--r--
use_text: verbose flag;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/mlworks.ML
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
     4
    Copyright   1996  University of Cambridge
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
     5
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
     6
Compatibility file for MLWorks version 1.0r2 or later.
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
     7
*)
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
     8
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
     9
(** ML system related **)
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    10
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    11
(* restore old-style character / string functions *)
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    12
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    13
fun ord s = Char.ord (String.sub (s, 0));
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    14
val chr = str o Char.chr;
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    15
val explode = (map str) o String.explode;
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    16
val implode = String.concat;
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    17
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    18
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    19
(* MLWorks parameters *)
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    20
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    21
MLWorks.Internal.Runtime.Event.stack_overflow_handler
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    22
  (fn () => MLWorks.Internal.Runtime.Memory.max_stack_blocks :=
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    23
    ! MLWorks.Internal.Runtime.Memory.max_stack_blocks + 20);
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    24
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    25
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    26
(* Poly/ML emulation *)
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    27
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    28
(*To exit the system with an exit code -- an alternative to ^D *)
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    29
fun exit 0 = (OS.Process.exit OS.Process.success): unit
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    30
  | exit _ = OS.Process.exit OS.Process.failure;
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    31
fun quit () = exit 0;
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    32
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    33
(*n.a.*)
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    34
fun print_depth n = ();
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    35
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    36
(*interface for toplevel pretty printers, see also Pure/install_pp.ML*)
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    37
(*n.a.*)
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    38
fun make_pp path pprint = ();
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    39
fun install_pp _ = ();
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    40
4977
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4973
diff changeset
    41
(*prompts*)
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4973
diff changeset
    42
(*n.a.??*)
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4973
diff changeset
    43
fun ml_prompts p1 p2 = ();
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4973
diff changeset
    44
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    45
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    46
(** Compiler-independent timing functions **)
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    47
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    48
(*Note start point for timing*)
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    49
fun startTiming() = 
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    50
  let val CPUtimer = Timer.startCPUTimer();
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    51
      val time = Timer.checkCPUTimer(CPUtimer)
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    52
  in  (CPUtimer,time)  end;
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    53
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    54
(*Finish timing and return string*)
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    55
fun endTiming (CPUtimer, {gc,sys,usr}) =
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    56
  let open Time  (*...for Time.toString, Time.+ and Time.- *)
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    57
      val {gc=gc2,sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    58
  in  "User " ^ toString (usr2-usr) ^
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    59
      "  GC " ^ toString (gc2-gc) ^
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    60
      "  All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    61
      " secs"
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    62
      handle Time => ""
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    63
  end;
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    64
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    65
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    66
(* ML command execution *)
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    67
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    68
(*Can one redirect 'use' directly to an instream?*)
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    69
fun use_text _ txt =
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    70
  let
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    71
    val tmp_name = OS.FileSys.tmpName ();
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    72
    val tmp_file = TextIO.openOut tmp_name;
5038
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4977
diff changeset
    73
  in
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4977
diff changeset
    74
    TextIO.output (tmp_file, txt);
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4977
diff changeset
    75
    TextIO.closeOut tmp_file;
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4977
diff changeset
    76
    use tmp_name;
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4977
diff changeset
    77
    OS.FileSys.remove tmp_name
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    78
  end;
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    79
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    80
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    81
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    82
(** OS related **)
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    83
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    84
(* system command execution *)
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    85
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    86
(*execute Unix command which doesn't take any input from stdin and
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    87
  sends its output to stdout; could be done more easily by Unix.execute,
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    88
  but that function doesn't use the PATH*)
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    89
fun execute command =
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    90
  let
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    91
    val tmp_name = OS.FileSys.tmpName ();
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    92
    val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    93
    val result = TextIO.inputAll is;
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    94
  in
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    95
    TextIO.closeIn is;
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    96
    OS.FileSys.remove tmp_name;
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
    97
    result
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    98
  end;
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
    99
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
   100
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
   101
(* file handling *)
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
   102
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
   103
(*get time of last modification; if file doesn't exist return an empty string*)
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
   104
fun file_info "" = ""		(* FIXME !? *)
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
   105
  | file_info name = Time.toString (OS.FileSys.modTime name) handle _ => "";
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
   106
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
   107
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
   108
(* getenv *)
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
   109
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
   110
fun getenv var =
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
   111
  (case OS.Process.getEnv var of
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
   112
    NONE => ""
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
   113
  | SOME txt => txt);
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
   114
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
   115
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
   116
(* non-ASCII input (see also Thy/use.ML) *)
4424
1f15655f7307 Compatibility file for MLWorks version 1.0r2 or later.
wenzelm
parents:
diff changeset
   117
4430
b2c1cf960c53 misc improvements;
wenzelm
parents: 4424
diff changeset
   118
val needs_filtered_use = false;