src/Pure/ML-Systems/mosml.ML
author wenzelm
Sun, 19 Jun 2005 00:07:41 +0200
changeset 16470 051db5bb21b5
parent 16469 7e27422c603e
child 16502 5a56e59526a5
permissions -rw-r--r--
improved comment;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/mosml.ML
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
     4
    Copyright   1999  University of Cambridge
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
     5
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
     6
Compatibility file for Moscow ML 2.00
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
     7
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
     8
NOTE: saving images does not work (yet!?), may run it interactively as follows:
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
     9
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    10
$ cd ~~/src/Pure
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    11
$ isabelle RAW_ML_SYSTEM
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    12
> val ml_system = "mosml";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    13
> use "ML-Systems/mosml.ML";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    14
> use "ROOT.ML";
16470
051db5bb21b5 improved comment;
wenzelm
parents: 16469
diff changeset
    15
> Session.finish ();
051db5bb21b5 improved comment;
wenzelm
parents: 16469
diff changeset
    16
> cd "../HOL";
051db5bb21b5 improved comment;
wenzelm
parents: 16469
diff changeset
    17
> use "ROOT.ML";
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    18
*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    19
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    20
(** ML system related **)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    21
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    22
(* Poly/ML emulation *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    23
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    24
load "Bool";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    25
load "Int";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    26
load "Real";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    27
load "ListPair";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    28
load "OS";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    29
load "Process";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    30
load "FileSys";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    31
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    32
(*proper implementation available?*)
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    33
structure IntInf =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    34
struct
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    35
  open Int;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    36
end;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    37
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    38
structure Real =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    39
struct
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    40
  open Real;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    41
  val realFloor = real o floor;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    42
end;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    43
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    44
structure Time =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    45
struct
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    46
  open Time;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    47
  fun toString t = Time.toString t
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    48
    handle Overflow => Real.toString (Time.toReal t);   (*workaround Y2004 bug*)
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    49
end;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    50
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    51
structure OS =
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    52
struct
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    53
  open OS
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    54
  structure Process = Process
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    55
  structure FileSys = FileSys
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    56
end;
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    57
 
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    58
(*limit the printing depth*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    59
fun print_depth n =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    60
 (Meta.printDepth := n div 2;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    61
  Meta.printLength := n);
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    62
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    63
(*interface for toplevel pretty printers, see also Pure/install_pp.ML*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    64
(*the documentation refers to an installPP but I couldn't fine it!*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    65
fun make_pp path pprint = ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    66
fun install_pp _ = ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    67
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    68
(*prompts*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    69
(*n.a.??*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    70
fun ml_prompts p1 p2 = ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    71
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    72
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    73
(** Compiler-independent timing functions **)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    74
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    75
load "Timer";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    76
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12988
diff changeset
    77
use "ML-Systems/cpu-timer-gc.ML";
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    78
14851
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    79
(* bounded time execution *)
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    80
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    81
(* FIXME proper implementation available? *)
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    82
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    83
structure TimeLimit : sig
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    84
   exception TimeOut
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    85
   val timeLimit : Time.time -> ('a -> 'b) -> 'a -> 'b
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    86
end = struct
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    87
   exception TimeOut
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    88
   fun timeLimit t f x =
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    89
      f x;
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    90
end;
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    91
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    92
(* ML command execution *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    93
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    94
(*Can one redirect 'use' directly to an instream?*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    95
fun use_text _ _ txt =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    96
  let
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    97
    val tmp_name = FileSys.tmpName ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    98
    val tmp_file = TextIO.openOut tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    99
  in
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   100
    TextIO.output (tmp_file, txt);
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   101
    TextIO.closeOut tmp_file;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   102
    use tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   103
    FileSys.remove tmp_name
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   104
  end;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   105
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   106
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   107
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   108
(** interrupts **)	(*Note: may get into race conditions*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   109
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   110
(* FIXME proper implementation available? *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   111
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   112
exception Interrupt;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   113
12988
2112f9e337bb renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12896
diff changeset
   114
fun ignore_interrupt f x = f x;           
2112f9e337bb renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12896
diff changeset
   115
fun raise_interrupt f x = f x;
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   116
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   117
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   118
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   119
(** OS related **)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   120
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   121
(* system command execution *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   122
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   123
(*execute Unix command which doesn't take any input from stdin and
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   124
  sends its output to stdout; could be done more easily by Unix.execute,
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   125
  but that function doesn't use the PATH*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   126
fun execute command =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   127
  let
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   128
    val tmp_name = FileSys.tmpName ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   129
    val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn 
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   130
tmp_name);
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   131
    val result = TextIO.inputAll is;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   132
  in
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   133
    TextIO.closeIn is;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   134
    FileSys.remove tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   135
    result
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   136
  end;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   137
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   138
(*plain version; with return code*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   139
fun system cmd =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   140
  if Process.system cmd = Process.success then 0 else 1;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   141
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   142
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   143
(* getenv *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   144
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   145
fun getenv var =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   146
  (case Process.getEnv var of
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   147
    NONE => ""
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   148
  | SOME txt => txt);