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