src/Pure/ML-Systems/mosml.ML
author webertj
Mon, 23 Jan 2006 17:29:52 +0100
changeset 18760 97aaecb84afe
parent 18384 fa38cca42913
child 21280 b4aa7daa506b
permissions -rw-r--r--
TimeLimit replaced by interrupt_timeout
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
17491
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
     6
Compatibility file for Moscow ML 2.01
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
     7
17491
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
     8
NOTE: saving images does not work; may run it interactively as follows:
9254
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
17491
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    47
structure String =
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    48
struct
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    49
  fun isSuffix s1 s2 =
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    50
    let val n1 = size s1 and n2 = size s2
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    51
    in if n1 = n2 then s1 = s2 else n1 <= n2 andalso String.substring (s2, n2 - n1, n1) = s1 end;
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    52
  open String;
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    53
end;
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    54
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    55
structure Time =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    56
struct
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    57
  open Time;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    58
  fun toString t = Time.toString t
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    59
    handle Overflow => Real.toString (Time.toReal t);   (*workaround Y2004 bug*)
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    60
end;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    61
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    62
structure OS =
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    63
struct
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    64
  open OS
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    65
  structure Process = Process
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    66
  structure FileSys = FileSys
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    67
end;
16993
wenzelm
parents: 16681
diff changeset
    68
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    69
(*limit the printing depth*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    70
fun print_depth n =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    71
 (Meta.printDepth := n div 2;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    72
  Meta.printLength := n);
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    73
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    74
(*interface for toplevel pretty printers, see also Pure/install_pp.ML*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    75
(*the documentation refers to an installPP but I couldn't fine it!*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    76
fun make_pp path pprint = ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    77
fun install_pp _ = ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    78
16681
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    79
(*dummy implementation*)
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    80
fun ml_prompts p1 p2 = ();
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    81
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    82
(*dummy implementation*)
16660
76613dff2c9a added profiler interface (dummy);
wenzelm
parents: 16517
diff changeset
    83
fun profile (n: int) f x = f x;
76613dff2c9a added profiler interface (dummy);
wenzelm
parents: 16517
diff changeset
    84
18384
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
    85
(*dummy implementation*)
16681
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    86
fun exception_trace f = f ();
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    87
18384
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
    88
(*dummy implementation*)
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
    89
fun print x = x;
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
    90
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
(** Compiler-independent timing functions **)
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
load "Timer";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    95
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12988
diff changeset
    96
use "ML-Systems/cpu-timer-gc.ML";
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    97
14851
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    98
(* bounded time execution *)
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
    99
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
   100
(* FIXME proper implementation available? *)
18760
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18384
diff changeset
   101
fun interrupt_timeout time f x =
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18384
diff changeset
   102
  f x;
16517
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
   103
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   104
(* ML command execution *)
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
(*Can one redirect 'use' directly to an instream?*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   107
fun use_text _ _ txt =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   108
  let
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   109
    val tmp_name = FileSys.tmpName ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   110
    val tmp_file = TextIO.openOut tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   111
  in
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   112
    TextIO.output (tmp_file, txt);
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   113
    TextIO.closeOut tmp_file;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   114
    use tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   115
    FileSys.remove tmp_name
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   116
  end;
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
16993
wenzelm
parents: 16681
diff changeset
   120
(** interrupts **)      (*Note: may get into race conditions*)
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   121
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   122
(* FIXME proper implementation available? *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   123
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   124
exception Interrupt;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   125
16993
wenzelm
parents: 16681
diff changeset
   126
fun ignore_interrupt f x = f x;
12988
2112f9e337bb renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12896
diff changeset
   127
fun raise_interrupt f x = f x;
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   128
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
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   131
(** OS related **)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   132
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   133
(* system command execution *)
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
(*execute Unix command which doesn't take any input from stdin and
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   136
  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
   137
  but that function doesn't use the PATH*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   138
fun execute command =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   139
  let
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   140
    val tmp_name = FileSys.tmpName ();
16993
wenzelm
parents: 16681
diff changeset
   141
    val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   142
    val result = TextIO.inputAll is;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   143
  in
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   144
    TextIO.closeIn is;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   145
    FileSys.remove tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   146
    result
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   147
  end;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   148
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   149
(*plain version; with return code*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   150
fun system cmd =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   151
  if Process.system cmd = Process.success then 0 else 1;
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
17824
36b2978d339a added string_of_pid;
wenzelm
parents: 17491
diff changeset
   154
val string_of_pid = Int.toString;
36b2978d339a added string_of_pid;
wenzelm
parents: 17491
diff changeset
   155
36b2978d339a added string_of_pid;
wenzelm
parents: 17491
diff changeset
   156
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   157
(* getenv *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   158
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   159
fun getenv var =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   160
  (case Process.getEnv var of
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   161
    NONE => ""
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   162
  | SOME txt => txt);