src/Pure/MLWorks.ML
author wenzelm
Fri, 07 Mar 1997 11:48:46 +0100
changeset 2754 59bd96046ad6
parent 2723 f09ecc2cd3f1
permissions -rw-r--r--
moved settings comment to build;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2330
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
     1
(*  Title:      Pure/MLWorks.ML
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
     2
    ID:         $Id$
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
     4
    Copyright   1996  University of Cambridge
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
     5
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
     6
Compatibility file for MLWorks (??)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
     7
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
     8
NB: There is still no easy way of building Isabelle under MLWorks.  This file
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
     9
    is just a start towards compatibility.  One problem is the peculiar
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    10
    behaviour of "use" in MLWorks.  Strange errors occur when loading theories,
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    11
    and ROOT.ML files on subdirectories are loaded incorrectly.
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    12
*)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    13
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    14
(*** Poly/ML emulation ***)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    15
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    16
(**
2723
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
    17
Shell.File.loadSource "system.__os";
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
    18
Shell.File.loadSource "basis.__timer";
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
    19
Shell.File.loadSource "system.__time";
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
    20
Shell.File.loadSource "unix.__os_file_sys";
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
    21
Shell.File.loadSource "basis.__list";
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
    22
Shell.File.loadSource "basis.__char";
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
    23
Shell.File.loadSource "basis.__string";
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
    24
Shell.File.loadSource "basis.__text_io";
2330
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    25
**)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    26
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    27
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    28
(*To exit the system with an exit code -- an alternative to ^D *)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    29
fun exit 0 = OS.Process.exit OS.Process.success
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    30
  | exit _ = OS.Process.exit OS.Process.failure;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    31
fun quit () = exit 0;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    32
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    33
(*To limit the printing depth [divided by 2 for comparibility with Poly/ML]*)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    34
fun print_depth n = ();
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    35
2723
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
    36
(*Interface for toplevel pretty printers, see also Pure/install_pp.ML
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
    37
  CURRENTLY UNAVAILABLE*)
2330
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    38
fun make_pp path pprint = ();
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    39
fun install_pp _ = ();
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    40
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    41
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    42
(*** New Jersey ML parameters ***)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    43
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    44
(*** Character/string functions which are compatible with 0.93 and Poly/ML ***)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    45
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    46
fun ord s = Char.ord (String.sub(s,0));
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    47
val chr = str o Char.chr;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    48
val explode = (map str) o String.explode;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    49
val implode = String.concat;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    50
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    51
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    52
(*** Timing functions ***)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    53
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    54
(*A conditional timing function: applies f to () and, if the flag is true,
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    55
  prints its runtime. *)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    56
fun cond_timeit flag f =
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    57
  if flag then
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    58
    let open Time  (*...for Time.toString, Time.+ and Time.- *)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    59
	val CPUtimer = Timer.startCPUTimer();
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    60
        val {gc=gct1,sys=syst1,usr=usrt1} = Timer.checkCPUTimer(CPUtimer);
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    61
        val result = f();
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    62
        val {gc=gct2,sys=syst2,usr=usrt2} = Timer.checkCPUTimer(CPUtimer)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    63
    in  print("User " ^ toString (usrt2-usrt1) ^
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    64
              "  GC " ^ toString (gct2-gct1) ^
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    65
              "  All "^ toString (syst2-syst1 + usrt2-usrt1 + gct2-gct1) ^
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    66
              " secs\n")
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    67
	  handle Time => ();
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    68
        result
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    69
    end
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    70
  else f();
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    71
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    72
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    73
(*** File handling ***)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    74
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    75
(*Get time of last modification; if file doesn't exist return an empty string*)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    76
fun file_info "" = ""
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    77
  | file_info name = Time.toString (OS.FileSys.modTime name) handle _ =>"";
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    78
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    79
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    80
(*** ML command execution ***)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    81
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    82
val tmpName = OS.FileSys.tmpName();
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    83
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    84
(*Can one redirect 'use' directly to an instream?*)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    85
fun use_string slist =
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    86
  let val tmpFile = TextIO.openOut tmpName
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    87
  in app (fn s => TextIO.output (tmpFile, s)) slist;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    88
     TextIO.closeOut tmpFile;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    89
     use tmpName
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    90
  end;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    91
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    92
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    93
(*** System command execution ***)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    94
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    95
(*Execute an Unix command which doesn't take any input from stdin and
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    96
  sends its output to stdout.
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    97
  This could be done more easily by Unix.execute, but that function
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    98
  doesn't use the PATH.*)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
    99
fun execute command =
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
   100
  let val is = (OS.Process.system (command ^ " > " ^ tmpName);
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
   101
                TextIO.openIn tmpName);
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
   102
      val result = TextIO.inputAll is;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
   103
  in TextIO.closeIn is;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
   104
     OS.FileSys.remove tmpName;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
   105
     result
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
   106
  end;
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
   107
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
   108
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
   109
(*Don't know what the boolean is for*)
3eea6b72bb4f MLWorks compatibility: it sort of works
paulson
parents:
diff changeset
   110
fun xML filename = Shell.saveImage (filename, false);
2723
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
   111
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
   112
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
   113
(*Non-printing and 8-bit chars are forbidden in string constants*)
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
   114
val needs_filtered_use = true;
f09ecc2cd3f1 Now declares needs_filtered_use, but still unusable with current MLWorks
paulson
parents: 2330
diff changeset
   115