src/Pure/ML-Systems/mosml.ML
author wenzelm
Mon, 23 Jul 2007 14:06:11 +0200
changeset 23921 947152add153
parent 23836 c6094fe98dfd
child 23965 f93e509659c1
permissions -rw-r--r--
added compatibility file for ML systems without multithreading;
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";
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";
21298
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
    30
load "IO";
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    31
23921
947152add153 added compatibility file for ML systems without multithreading;
wenzelm
parents: 23836
diff changeset
    32
use "ML-Systems/no_multithreading.ML";
947152add153 added compatibility file for ML systems without multithreading;
wenzelm
parents: 23836
diff changeset
    33
947152add153 added compatibility file for ML systems without multithreading;
wenzelm
parents: 23836
diff changeset
    34
16517
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    35
(*low-level pointer equality*)
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    36
local val cast : 'a -> int = Obj.magic
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    37
in fun pointer_eq (x:'a, y:'a) = (cast x = cast y) end;
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
    38
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    39
(*proper implementation available?*)
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    40
structure IntInf =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    41
struct
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    42
  open Int;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    43
end;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    44
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    45
structure Real =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    46
struct
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    47
  open Real;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    48
  val realFloor = real o floor;
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
17491
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    51
structure String =
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    52
struct
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    53
  fun isSuffix s1 s2 =
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    54
    let val n1 = size s1 and n2 = size s2
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    55
    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
    56
  open String;
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    57
end;
2bd5a6e26e1e added String.isSuffix;
wenzelm
parents: 16993
diff changeset
    58
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    59
structure Time =
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    60
struct
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    61
  open Time;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    62
  fun toString t = Time.toString t
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    63
    handle Overflow => Real.toString (Time.toReal t);   (*workaround Y2004 bug*)
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    64
end;
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    65
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    66
structure OS =
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    67
struct
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    68
  open OS
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    69
  structure Process = Process
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    70
  structure FileSys = FileSys
16469
7e27422c603e some minor adaptions to make it work again;
wenzelm
parents: 16266
diff changeset
    71
end;
16993
wenzelm
parents: 16681
diff changeset
    72
22252
ce77e9622002 pervasive exception Option;
wenzelm
parents: 22144
diff changeset
    73
exception Option = Option.Option;
ce77e9622002 pervasive exception Option;
wenzelm
parents: 22144
diff changeset
    74
ce77e9622002 pervasive exception Option;
wenzelm
parents: 22144
diff changeset
    75
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    76
(*limit the printing depth*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    77
fun print_depth n =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    78
 (Meta.printDepth := n div 2;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    79
  Meta.printLength := n);
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
(*interface for toplevel pretty printers, see also Pure/install_pp.ML*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    82
(*the documentation refers to an installPP but I couldn't fine it!*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    83
fun make_pp path pprint = ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    84
fun install_pp _ = ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    85
16681
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    86
(*dummy implementation*)
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    87
fun ml_prompts p1 p2 = ();
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    88
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    89
(*dummy implementation*)
16660
76613dff2c9a added profiler interface (dummy);
wenzelm
parents: 16517
diff changeset
    90
fun profile (n: int) f x = f x;
76613dff2c9a added profiler interface (dummy);
wenzelm
parents: 16517
diff changeset
    91
18384
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
    92
(*dummy implementation*)
16681
d54dfd724b35 dummy exception_trace;
wenzelm
parents: 16660
diff changeset
    93
fun exception_trace f = f ();
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    94
18384
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
    95
(*dummy implementation*)
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
    96
fun print x = x;
fa38cca42913 added dummy 'print' to non-polyml systems
haftmann
parents: 17824
diff changeset
    97
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    98
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
    99
(** Compiler-independent timing functions **)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   100
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   101
load "Timer";
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   102
21298
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   103
fun start_timing () =
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   104
  let val CPUtimer = Timer.startCPUTimer();
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   105
      val time = Timer.checkCPUTimer(CPUtimer)
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   106
  in  (CPUtimer,time)  end;
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   107
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   108
fun end_timing (CPUtimer, {gc,sys,usr}) =
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   109
  let open Time  (*...for Time.toString, Time.+ and Time.- *)
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   110
      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
   111
  in  "User " ^ toString (usr2-usr) ^
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   112
      "  GC " ^ toString (gc2-gc) ^
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   113
      "  All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   114
      " secs"
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   115
      handle Time => ""
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   116
  end;
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   117
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   118
fun check_timer timer =
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   119
  let val {sys, usr, gc} = Timer.checkCPUTimer timer
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   120
  in (sys, usr, gc) end;
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   121
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
(* SML basis library fixes *)
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   124
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   125
structure TextIO =
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   126
struct
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   127
  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
   128
  open TextIO;
23836
c6094fe98dfd adapted TextIO.inputLine;
wenzelm
parents: 23826
diff changeset
   129
  fun inputLine is =
c6094fe98dfd adapted TextIO.inputLine;
wenzelm
parents: 23826
diff changeset
   130
    let val s = TextIO.inputLine is
c6094fe98dfd adapted TextIO.inputLine;
wenzelm
parents: 23826
diff changeset
   131
    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
   132
end;
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21280
diff changeset
   133
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   134
14851
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
   135
(* bounded time execution *)
0fc75361e0c7 TimeLimit structure added (no proper implementation yet)
webertj
parents: 14519
diff changeset
   136
21280
b4aa7daa506b tuned comments;
wenzelm
parents: 18760
diff changeset
   137
(*dummy implementation*)
18760
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18384
diff changeset
   138
fun interrupt_timeout time f x =
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18384
diff changeset
   139
  f x;
16517
4699288139f4 proper implementation of pointer_eq;
wenzelm
parents: 16502
diff changeset
   140
21280
b4aa7daa506b tuned comments;
wenzelm
parents: 18760
diff changeset
   141
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   142
(* ML command execution *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   143
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   144
(*Can one redirect 'use' directly to an instream?*)
22144
c33450acd873 use_text: added name argument;
wenzelm
parents: 21770
diff changeset
   145
fun use_text _ _ _ txt =
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   146
  let
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   147
    val tmp_name = FileSys.tmpName ();
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   148
    val tmp_file = TextIO.openOut tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   149
  in
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   150
    TextIO.output (tmp_file, txt);
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   151
    TextIO.closeOut tmp_file;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   152
    use tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   153
    FileSys.remove tmp_name
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   154
  end;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   155
22252
ce77e9622002 pervasive exception Option;
wenzelm
parents: 22144
diff changeset
   156
fun use_file _ _ name = use name;
21770
ea6f846d8c4b added use_file;
wenzelm
parents: 21298
diff changeset
   157
9254
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
16993
wenzelm
parents: 16681
diff changeset
   160
(** interrupts **)      (*Note: may get into race conditions*)
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   161
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   162
(* FIXME proper implementation available? *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   163
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   164
exception Interrupt;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   165
16993
wenzelm
parents: 16681
diff changeset
   166
fun ignore_interrupt f x = f x;
12988
2112f9e337bb renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12896
diff changeset
   167
fun raise_interrupt f x = f x;
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   168
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
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   171
(** OS related **)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   172
23826
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 22252
diff changeset
   173
(* current directory *)
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 22252
diff changeset
   174
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 22252
diff changeset
   175
val cd = OS.FileSys.chDir;
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 22252
diff changeset
   176
val pwd = OS.FileSys.getDir;
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 22252
diff changeset
   177
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 22252
diff changeset
   178
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   179
(* system command execution *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   180
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   181
(*execute Unix command which doesn't take any input from stdin and
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   182
  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
   183
  but that function doesn't use the PATH*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   184
fun execute command =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   185
  let
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   186
    val tmp_name = FileSys.tmpName ();
16993
wenzelm
parents: 16681
diff changeset
   187
    val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   188
    val result = TextIO.inputAll is;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   189
  in
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   190
    TextIO.closeIn is;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   191
    FileSys.remove tmp_name;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   192
    result
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   193
  end;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   194
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   195
(*plain version; with return code*)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   196
fun system cmd =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   197
  if Process.system cmd = Process.success then 0 else 1;
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   198
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   199
17824
36b2978d339a added string_of_pid;
wenzelm
parents: 17491
diff changeset
   200
val string_of_pid = Int.toString;
36b2978d339a added string_of_pid;
wenzelm
parents: 17491
diff changeset
   201
36b2978d339a added string_of_pid;
wenzelm
parents: 17491
diff changeset
   202
9254
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   203
(* getenv *)
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   204
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   205
fun getenv var =
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   206
  (case Process.getEnv var of
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   207
    NONE => ""
f8a0e8b9bcd8 Compatibility file for Moscow ML 2.00;
wenzelm
parents:
diff changeset
   208
  | SOME txt => txt);