src/Pure/ML-Systems/mosml.ML
author wenzelm
Thu, 06 Mar 2008 20:44:54 +0100
changeset 26223 f4a1a96cc07c
parent 26220 d34b68c21f9a
child 26474 94735cff132c
permissions -rw-r--r--
specific system_out (MosML lacks structure Posix); dummy implementation of Posix.ProcEnv.getpid;
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
23826
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 22252
diff changeset
    10
$ cd Isabelle/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 ();
23836
c6094fe98dfd adapted TextIO.inputLine;
wenzelm
parents: 23826
diff changeset
    16
> cd "../FOL";
16470
051db5bb21b5 improved comment;
wenzelm
parents: 16469
diff changeset
    17
> use "ROOT.ML";
24808
7c9a970d7ab5 fixed use_text;
wenzelm
parents: 24688
diff changeset
    18
> Session.finish ();
7c9a970d7ab5 fixed use_text;
wenzelm
parents: 24688
diff changeset
    19
> cd "../ZF";
7c9a970d7ab5 fixed use_text;
wenzelm
parents: 24688
diff changeset
    20
> use "ROOT.ML";
9254
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
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    23
(** ML system related **)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    24
24597
cbf2c5cf335e added ml_system_fix_ints;
wenzelm
parents: 24329
diff changeset
    25
val ml_system_fix_ints = false;
cbf2c5cf335e added ml_system_fix_ints;
wenzelm
parents: 24329
diff changeset
    26
16517
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    27
load "Obj";
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    28
load "Bool";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    29
load "Int";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    30
load "Real";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    31
load "ListPair";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    32
load "OS";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    33
load "Process";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    34
load "FileSys";
21298
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
    35
load "IO";
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    36
23965
f93e509659c1 ML-Systems/exn.ML, ML-Systems/multithreading_dummy.ML;
wenzelm
parents: 23921
diff changeset
    37
use "ML-Systems/exn.ML";
25732
308315ee2b6d added ML-Systems/universal.ML;
wenzelm
parents: 24808
diff changeset
    38
use "ML-Systems/universal.ML";
24688
a5754ca5c510 replaced interrupt_timeout by TimeLimit.timeLimit (available on SML/NJ and Poly/ML 5.1);
wenzelm
parents: 24597
diff changeset
    39
use "ML-Systems/multithreading.ML";
a5754ca5c510 replaced interrupt_timeout by TimeLimit.timeLimit (available on SML/NJ and Poly/ML 5.1);
wenzelm
parents: 24597
diff changeset
    40
use "ML-Systems/time_limit.ML";
23921
947152add153 added compatibility file for ML systems without multithreading;
wenzelm
parents: 23836
diff changeset
    41
947152add153 added compatibility file for ML systems without multithreading;
wenzelm
parents: 23836
diff changeset
    42
16517
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    43
(*low-level pointer equality*)
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    44
local val cast : 'a -> int = Obj.magic
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    45
in fun pointer_eq (x:'a, y:'a) = (cast x = cast y) end;
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    46
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    47
(*proper implementation available?*)
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    48
structure IntInf =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    49
struct
24808
7c9a970d7ab5 fixed use_text;
wenzelm
parents: 24688
diff changeset
    50
  fun divMod (x, y) = (x div y, x mod y);
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    51
  open Int;
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
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    54
structure Real =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    55
struct
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    56
  open Real;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    57
  val realFloor = real o floor;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    58
end;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    59
17491
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    60
structure String =
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    61
struct
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    62
  fun isSuffix s1 s2 =
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    63
    let val n1 = size s1 and n2 = size s2
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    64
    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
    65
  open String;
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    66
end;
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    67
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    68
structure Time =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    69
struct
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    70
  open Time;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    71
  fun toString t = Time.toString t
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    72
    handle Overflow => Real.toString (Time.toReal t);   (*workaround Y2004 bug*)
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    73
end;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    74
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    75
structure OS =
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    76
struct
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    77
  open OS
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    78
  structure Process = Process
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    79
  structure FileSys = FileSys
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    80
end;
16993
wenzelm
parents: 16681
diff changeset
    81
22252
ce77e9622002 pervasive exception Option;
wenzelm
parents: 22144
diff changeset
    82
exception Option = Option.Option;
ce77e9622002 pervasive exception Option;
wenzelm
parents: 22144
diff changeset
    83
ce77e9622002 pervasive exception Option;
wenzelm
parents: 22144
diff changeset
    84
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    85
(*limit the printing depth*)
24329
f31594168d27 ML system provides get_print_depth;
wenzelm
parents: 24290
diff changeset
    86
local
f31594168d27 ML system provides get_print_depth;
wenzelm
parents: 24290
diff changeset
    87
  val depth = ref 10;
f31594168d27 ML system provides get_print_depth;
wenzelm
parents: 24290
diff changeset
    88
in
f31594168d27 ML system provides get_print_depth;
wenzelm
parents: 24290
diff changeset
    89
  fun get_print_depth () = ! depth;
f31594168d27 ML system provides get_print_depth;
wenzelm
parents: 24290
diff changeset
    90
  fun print_depth n =
f31594168d27 ML system provides get_print_depth;
wenzelm
parents: 24290
diff changeset
    91
   (depth := n;
f31594168d27 ML system provides get_print_depth;
wenzelm
parents: 24290
diff changeset
    92
    Meta.printDepth := n div 2;
f31594168d27 ML system provides get_print_depth;
wenzelm
parents: 24290
diff changeset
    93
    Meta.printLength := n);
f31594168d27 ML system provides get_print_depth;
wenzelm
parents: 24290
diff changeset
    94
end;
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    95
24290
5607b8b752bb tuned comments;
wenzelm
parents: 23965
diff changeset
    96
(*interface for toplevel pretty printers, see also Pure/pure_setup.ML*)
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    97
(*the documentation refers to an installPP but I couldn't fine it!*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    98
fun make_pp path pprint = ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    99
fun install_pp _ = ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   100
16681
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
   101
(*dummy implementation*)
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
   102
fun ml_prompts p1 p2 = ();
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
   103
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
   104
(*dummy implementation*)
16660
76613dff2c9a added profiler interface (dummy);
wenzelm
parents: 16517
diff changeset
   105
fun profile (n: int) f x = f x;
76613dff2c9a added profiler interface (dummy);
wenzelm
parents: 16517
diff changeset
   106
18384
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
   107
(*dummy implementation*)
16681
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
   108
fun exception_trace f = f ();
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   109
18384
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
   110
(*dummy implementation*)
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
   111
fun print x = x;
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
   112
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
(** Compiler-independent timing functions **)
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
load "Timer";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   117
21298
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   118
fun start_timing () =
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   119
  let val CPUtimer = Timer.startCPUTimer();
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   120
      val time = Timer.checkCPUTimer(CPUtimer)
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   121
  in  (CPUtimer,time)  end;
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   122
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   123
fun end_timing (CPUtimer, {gc,sys,usr}) =
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   124
  let open Time  (*...for Time.toString, Time.+ and Time.- *)
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   125
      val {gc=gc2,sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   126
  in  "User " ^ toString (usr2-usr) ^
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   127
      "  GC " ^ toString (gc2-gc) ^
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   128
      "  All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   129
      " secs"
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   130
      handle Time => ""
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   131
  end;
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   132
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   133
fun check_timer timer =
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   134
  let val {sys, usr, gc} = Timer.checkCPUTimer timer
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   135
  in (sys, usr, gc) end;
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   136
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   137
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   138
(* SML basis library fixes *)
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   139
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   140
structure TextIO =
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   141
struct
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   142
  fun canInput _ = raise IO.Io {cause = Fail "undefined", function = "canInput", name = ""};
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   143
  open TextIO;
23836
c6094fe98dfd adapted TextIO.inputLine;
wenzelm
parents: 23826
diff changeset
   144
  fun inputLine is =
c6094fe98dfd adapted TextIO.inputLine;
wenzelm
parents: 23826
diff changeset
   145
    let val s = TextIO.inputLine is
c6094fe98dfd adapted TextIO.inputLine;
wenzelm
parents: 23826
diff changeset
   146
    in if s = "" then NONE else SOME s end;
21298
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   147
end;
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   148
9254
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
(* ML command execution *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   151
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   152
(*Can one redirect 'use' directly to an instream?*)
24808
7c9a970d7ab5 fixed use_text;
wenzelm
parents: 24688
diff changeset
   153
fun use_text (tune: string -> string) _ _ _ txt =
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   154
  let
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   155
    val tmp_name = FileSys.tmpName ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   156
    val tmp_file = TextIO.openOut tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   157
  in
24808
7c9a970d7ab5 fixed use_text;
wenzelm
parents: 24688
diff changeset
   158
    TextIO.output (tmp_file, tune txt);
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   159
    TextIO.closeOut tmp_file;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   160
    use tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   161
    FileSys.remove tmp_name
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   162
  end;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   163
24808
7c9a970d7ab5 fixed use_text;
wenzelm
parents: 24688
diff changeset
   164
fun use_file _ _ _ name = use name;
21770
ea6f846d8c4b added use_file;
wenzelm
parents: 21298
diff changeset
   165
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   166
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   167
16993
wenzelm
parents: 16681
diff changeset
   168
(** interrupts **)      (*Note: may get into race conditions*)
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   169
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   170
(* FIXME proper implementation available? *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   171
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   172
exception Interrupt;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   173
26084
a7475459c740 replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents: 25732
diff changeset
   174
fun interruptible f x = f x;
a7475459c740 replaced ignore/raise_interrupt by more flexible (un)interruptible combinators;
wenzelm
parents: 25732
diff changeset
   175
fun uninterruptible f x = f (fn (g: 'c -> 'd) => g) x;
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   176
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   177
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   178
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   179
(** OS related **)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   180
26223
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   181
(*dummy implementation*)
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   182
structure Posix =
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   183
struct
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   184
  structure ProcEnv =
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   185
  struct
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   186
    fun getpid () = 0;
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   187
  end;  
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   188
end;
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   189
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   190
local
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   191
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   192
fun read_file name =
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   193
  let val is = TextIO.openIn name
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   194
  in TextIO.inputAll is before TextIO.closeIn is end;
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   195
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   196
fun write_file name txt =
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   197
  let val os = TextIO.openOut name
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   198
  in TextIO.output (os, txt) before TextIO.closeOut os end;
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   199
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   200
in
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   201
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   202
fun system_out script =
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   203
  let
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   204
    val script_name = OS.FileSys.tmpName ();
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   205
    val _ = write_file script_name script;
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   206
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   207
    val output_name = OS.FileSys.tmpName ();
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   208
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   209
    val status =
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   210
      OS.Process.system ("perl -w \"$ISABELLE_HOME/lib/scripts/system.pl\" nogroup " ^
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   211
        script_name ^ " /dev/null " ^ output_name);
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   212
    val rc = if status = OS.Process.success then 0 else 1;
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   213
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   214
    val output = read_file output_name handle IO.Io _ => "";
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   215
    val _ = OS.FileSys.remove script_name handle OS.SysErr _ => ();
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   216
    val _ = OS.FileSys.remove output_name handle OS.SysErr _ => ();
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   217
  in (output, rc) end;
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   218
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   219
end;
f4a1a96cc07c specific system_out (MosML lacks structure Posix);
wenzelm
parents: 26220
diff changeset
   220
23826
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 22252
diff changeset
   221
val cd = OS.FileSys.chDir;
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 22252
diff changeset
   222
val pwd = OS.FileSys.getDir;
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 22252
diff changeset
   223
17824
36b2978d339a added string_of_pid;
wenzelm
parents: 17491
diff changeset
   224
val string_of_pid = Int.toString;
36b2978d339a added string_of_pid;
wenzelm
parents: 17491
diff changeset
   225
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   226
fun getenv var =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   227
  (case Process.getEnv var of
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   228
    NONE => ""
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   229
  | SOME txt => txt);