src/Pure/ML-Systems/mosml.ML
author wenzelm
Mon, 29 Aug 2005 16:18:04 +0200
changeset 17184 3d80209e9a53
parent 16993 2ec0b8159e8e
child 17491 2bd5a6e26e1e
permissions -rw-r--r--
use AList operations;
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
16517
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    22
load "Obj";
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    23
load "Bool";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    24
load "Int";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    25
load "Real";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    26
load "ListPair";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    27
load "OS";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    28
load "Process";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    29
load "FileSys";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    30
16517
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    31
(*low-level pointer equality*)
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    32
local val cast : 'a -> int = Obj.magic
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    33
in fun pointer_eq (x:'a, y:'a) = (cast x = cast y) end;
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    34
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    35
(*proper implementation available?*)
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    36
structure IntInf =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    37
struct
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    38
  open Int;
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 Real =
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 Real;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    44
  val realFloor = real o floor;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    45
end;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    46
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    47
structure Time =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    48
struct
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    49
  open Time;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    50
  fun toString t = Time.toString t
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    51
    handle Overflow => Real.toString (Time.toReal t);   (*workaround Y2004 bug*)
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    52
end;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    53
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    54
structure OS =
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    55
struct
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    56
  open OS
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    57
  structure Process = Process
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    58
  structure FileSys = FileSys
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    59
end;
16993
wenzelm
parents: 16681
diff changeset
    60
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    61
(*limit the printing depth*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    62
fun print_depth n =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    63
 (Meta.printDepth := n div 2;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    64
  Meta.printLength := n);
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    65
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    66
(*interface for toplevel pretty printers, see also Pure/install_pp.ML*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    67
(*the documentation refers to an installPP but I couldn't fine it!*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    68
fun make_pp path pprint = ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    69
fun install_pp _ = ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    70
16681
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    71
(*dummy implementation*)
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    72
fun ml_prompts p1 p2 = ();
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    73
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    74
(*dummy implementation*)
16660
76613dff2c9a added profiler interface (dummy);
wenzelm
parents: 16517
diff changeset
    75
fun profile (n: int) f x = f x;
76613dff2c9a added profiler interface (dummy);
wenzelm
parents: 16517
diff changeset
    76
16681
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    77
(*dummy impelemtation*)
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    78
fun exception_trace f = f ();
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    79
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    80
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    81
(** Compiler-independent timing functions **)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    82
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    83
load "Timer";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    84
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12988
diff changeset
    85
use "ML-Systems/cpu-timer-gc.ML";
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    86
14851
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    87
(* bounded time execution *)
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    88
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    89
(* FIXME proper implementation available? *)
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    90
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    91
structure TimeLimit : sig
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    92
   exception TimeOut
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    93
   val timeLimit : Time.time -> ('a -> 'b) -> 'a -> 'b
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    94
end = struct
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    95
   exception TimeOut
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    96
   fun timeLimit t f x =
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    97
      f x;
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    98
end;
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    99
16517
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
   100
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   101
(* ML command execution *)
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
(*Can one redirect 'use' directly to an instream?*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   104
fun use_text _ _ txt =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   105
  let
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   106
    val tmp_name = FileSys.tmpName ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   107
    val tmp_file = TextIO.openOut tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   108
  in
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   109
    TextIO.output (tmp_file, txt);
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   110
    TextIO.closeOut tmp_file;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   111
    use tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   112
    FileSys.remove tmp_name
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   113
  end;
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
16993
wenzelm
parents: 16681
diff changeset
   117
(** interrupts **)      (*Note: may get into race conditions*)
9254
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
(* FIXME proper implementation available? *)
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
exception Interrupt;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   122
16993
wenzelm
parents: 16681
diff changeset
   123
fun ignore_interrupt f x = f x;
12988
2112f9e337bb renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12896
diff changeset
   124
fun raise_interrupt f x = f x;
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   125
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   126
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   127
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   128
(** OS related **)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   129
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   130
(* system command execution *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   131
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   132
(*execute Unix command which doesn't take any input from stdin and
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   133
  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
   134
  but that function doesn't use the PATH*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   135
fun execute command =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   136
  let
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   137
    val tmp_name = FileSys.tmpName ();
16993
wenzelm
parents: 16681
diff changeset
   138
    val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   139
    val result = TextIO.inputAll is;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   140
  in
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   141
    TextIO.closeIn is;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   142
    FileSys.remove tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   143
    result
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   144
  end;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   145
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   146
(*plain version; with return code*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   147
fun system cmd =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   148
  if Process.system cmd = Process.success then 0 else 1;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   149
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   150
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   151
(* getenv *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   152
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   153
fun getenv var =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   154
  (case Process.getEnv var of
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   155
    NONE => ""
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   156
  | SOME txt => txt);