src/Pure/ML-Systems/polyml.ML
author wenzelm
Tue, 24 Jul 2007 19:44:33 +0200
changeset 23962 e0358fac0541
parent 23921 947152add153
child 23965 f93e509659c1
permissions -rw-r--r--
Runtime exceptions as values (from library.ML);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/polyml.ML
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     3
23139
aa899bce7c3b TextIO.inputLine: use present SML B library version;
wenzelm
parents: 22144
diff changeset
     4
Compatibility file for Poly/ML (version 4.1.x and 4.2.0).
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     5
*)
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     6
23921
947152add153 added compatibility file for ML systems without multithreading;
wenzelm
parents: 23826
diff changeset
     7
use "ML-Systems/no_multithreading.ML";
947152add153 added compatibility file for ML systems without multithreading;
wenzelm
parents: 23826
diff changeset
     8
947152add153 added compatibility file for ML systems without multithreading;
wenzelm
parents: 23826
diff changeset
     9
16374
f4b7cf8975af some cygwin support;
wenzelm
parents: 16266
diff changeset
    10
(** ML system and platform related **)
f4b7cf8975af some cygwin support;
wenzelm
parents: 16266
diff changeset
    11
17077
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    12
(* String compatibility *)
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    13
16516
0842635545c3 tuned pointer_eq;
wenzelm
parents: 16502
diff changeset
    14
(*low-level pointer equality*)
0842635545c3 tuned pointer_eq;
wenzelm
parents: 16502
diff changeset
    15
val pointer_eq = Address.wordEq;
16502
5a56e59526a5 added pointer_eq;
wenzelm
parents: 16453
diff changeset
    16
5a56e59526a5 added pointer_eq;
wenzelm
parents: 16453
diff changeset
    17
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    18
(* old Poly/ML emulation *)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    19
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    20
local
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    21
  val orig_exit = exit;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    22
in
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    23
  open PolyML;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    24
  val exit = orig_exit;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    25
  fun quit () = exit 0;
7148
e9c253036b45 removed obsolete concat;
wenzelm
parents: 7147
diff changeset
    26
end;
6042
0ccde2f25dd6 Basis Library compatible substring oeration
paulson
parents: 5813
diff changeset
    27
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    28
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    29
(* restore old-style character / string functions *)
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    30
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    31
val ord = SML90.ord;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    32
val chr = SML90.chr;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    33
val explode = SML90.explode;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    34
val implode = SML90.implode;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    35
14870
c5cf7c001313 tuned comments;
wenzelm
parents: 14850
diff changeset
    36
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12989
diff changeset
    37
(* compiler-independent timing functions *)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    38
21298
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    39
fun start_timing () =
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    40
  let val CPUtimer = Timer.startCPUTimer();
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    41
      val time = Timer.checkCPUTimer(CPUtimer)
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    42
  in  (CPUtimer,time)  end;
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    43
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    44
fun end_timing (CPUtimer, {sys,usr}) =
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    45
  let open Time  (*...for Time.toString, Time.+ and Time.- *)
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    46
      val {sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    47
  in  "User " ^ toString (usr2-usr) ^
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    48
      "  All "^ toString (sys2-sys + usr2-usr) ^
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    49
      " secs"
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    50
      handle Time => ""
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    51
  end;
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    52
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    53
fun check_timer timer =
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    54
  let
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    55
    val {sys, usr} = Timer.checkCPUTimer timer;
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    56
    val gc = Timer.checkGCTime timer;    (* FIXME already included in usr? *)
6d2306b2376d tuned names of start_timing,/end_timing/check_timer;
wenzelm
parents: 21281
diff changeset
    57
  in (sys, usr, gc) end;
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    58
14870
c5cf7c001313 tuned comments;
wenzelm
parents: 14850
diff changeset
    59
14850
393a7be73160 including polyml-time-limit.ML
webertj
parents: 14519
diff changeset
    60
(* bounded time execution *)
393a7be73160 including polyml-time-limit.ML
webertj
parents: 14519
diff changeset
    61
21281
0767e7dad549 no special treatment for cygwin (this is supposed to be actual cygwin, not win32 polyml within cygwin);
wenzelm
parents: 18814
diff changeset
    62
(*dummy implementation*)
18760
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18504
diff changeset
    63
fun interrupt_timeout time f x =
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18504
diff changeset
    64
  f x;
97aaecb84afe TimeLimit replaced by interrupt_timeout
webertj
parents: 18504
diff changeset
    65
14870
c5cf7c001313 tuned comments;
wenzelm
parents: 14850
diff changeset
    66
4977
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    67
(* prompts *)
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    68
4984
d17004d4c13b fixed ml_prompts;
wenzelm
parents: 4977
diff changeset
    69
fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2);
4977
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    70
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    71
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    72
(* toplevel pretty printing (see also Pure/install_pp.ML) *)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    73
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    74
fun make_pp _ pprint (str, blk, brk, en) _ _ obj =
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    75
  pprint obj (str, fn ind => blk (ind, false), fn wd => brk (wd, 0),
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    76
    fn () => brk (99999, 0), en);
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    77
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    78
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    79
(* ML command execution -- 'eval' *)
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    80
22144
c33450acd873 use_text: added name argument;
wenzelm
parents: 21770
diff changeset
    81
fun use_text name (print, err) verbose txt =
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    82
  let
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    83
    val in_buffer = ref (explode txt);
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    84
    val out_buffer = ref ([]: string list);
21715
9c19f90272e8 tuned use_text;
wenzelm
parents: 21298
diff changeset
    85
    fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    86
5038
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4984
diff changeset
    87
    fun get () =
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    88
      (case ! in_buffer of
5038
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4984
diff changeset
    89
        [] => ""
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    90
      | c :: cs => (in_buffer := cs; c));
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    91
    fun put s = out_buffer := s :: ! out_buffer;
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    92
5038
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4984
diff changeset
    93
    fun exec () =
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    94
      (case ! in_buffer of
5038
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4984
diff changeset
    95
        [] => ()
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    96
      | _ => (PolyML.compiler (get, put) (); exec ()));
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    97
  in
22144
c33450acd873 use_text: added name argument;
wenzelm
parents: 21770
diff changeset
    98
    exec () handle exn =>
c33450acd873 use_text: added name argument;
wenzelm
parents: 21770
diff changeset
    99
      (err ((if name = "" then "" else "Error in " ^ name ^ "\n") ^ output ()); raise exn);
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 8830
diff changeset
   100
    if verbose then print (output ()) else ()
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
   101
  end;
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   102
21770
ea6f846d8c4b added use_file;
wenzelm
parents: 21715
diff changeset
   103
fun use_file _ _ name = use name;
ea6f846d8c4b added use_file;
wenzelm
parents: 21715
diff changeset
   104
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   105
15832
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   106
(*eval command line arguments*)
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   107
local
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   108
  fun println s =
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   109
    (TextIO.output (TextIO.stdOut, s ^ "\n"); TextIO.flushOut TextIO.stdOut);
21715
9c19f90272e8 tuned use_text;
wenzelm
parents: 21298
diff changeset
   110
  fun eval "-q" = ()
22144
c33450acd873 use_text: added name argument;
wenzelm
parents: 21770
diff changeset
   111
    | eval txt = use_text "" (println, println) false txt;
15832
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   112
in
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   113
  val _ = PolyML.onEntry (fn () => app eval (CommandLine.arguments ()));
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   114
end;
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   115
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   116
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   117
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   118
(** interrupts **)
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   119
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   120
exception Interrupt = SML90.Interrupt;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   121
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   122
local
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   123
12989
42ac77552dbf renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12108
diff changeset
   124
fun capture f x = ((f x): unit; NONE) handle exn => SOME exn;
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   125
12989
42ac77552dbf renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12108
diff changeset
   126
fun release NONE = ()
42ac77552dbf renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12108
diff changeset
   127
  | release (SOME exn) = raise exn;
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   128
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   129
val sig_int = 2;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   130
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   131
fun change_signal new_handler f x =
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   132
  let
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   133
    (*RACE wrt. other signals*)
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   134
    val old_handler = Signal.signal (sig_int, new_handler);
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   135
    val result = capture f x;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   136
    val _ = Signal.signal (sig_int, old_handler);
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   137
  in release result end;
5813
4eea84a9427d fake interrupt handler;
wenzelm
parents: 5090
diff changeset
   138
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   139
val default_handler = Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ());
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   140
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   141
in
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   142
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   143
val _ = Signal.signal (sig_int, default_handler);
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   144
12989
42ac77552dbf renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12108
diff changeset
   145
fun ignore_interrupt f = change_signal Signal.SIG_IGN f;
42ac77552dbf renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12108
diff changeset
   146
fun raise_interrupt f = change_signal default_handler f;
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   147
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   148
end;
5813
4eea84a9427d fake interrupt handler;
wenzelm
parents: 5090
diff changeset
   149
4eea84a9427d fake interrupt handler;
wenzelm
parents: 5090
diff changeset
   150
4eea84a9427d fake interrupt handler;
wenzelm
parents: 5090
diff changeset
   151
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   152
(** OS related **)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
   153
21281
0767e7dad549 no special treatment for cygwin (this is supposed to be actual cygwin, not win32 polyml within cygwin);
wenzelm
parents: 18814
diff changeset
   154
use "ML-Systems/polyml-posix.ML";
16659
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   155
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   156
23826
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 23139
diff changeset
   157
(* current directory *)
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 23139
diff changeset
   158
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 23139
diff changeset
   159
val cd = OS.FileSys.chDir;
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 23139
diff changeset
   160
val pwd = OS.FileSys.getDir;
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 23139
diff changeset
   161
463903573934 moved cd/pwd to ML compatibility layer (simplifies bootstrapping with Alice);
wenzelm
parents: 23139
diff changeset
   162
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   163
(* system command execution *)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
   164
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   165
(*execute Unix command which doesn't take any input from stdin and
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   166
  sends its output to stdout; could be done more easily by Unix.execute,
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   167
  but that function doesn't use the PATH*)
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   168
fun execute command =
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   169
  let
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   170
    val tmp_name = OS.FileSys.tmpName ();
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   171
    val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   172
    val result = TextIO.inputAll is;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   173
  in
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   174
    TextIO.closeIn is;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   175
    OS.FileSys.remove tmp_name;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   176
    result
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   177
  end;
7855
092a6435afad system;
wenzelm
parents: 7148
diff changeset
   178
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   179
(*plain version; with return code*)
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   180
fun system cmd =
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   181
  if OS.Process.isSuccess (OS.Process.system cmd) then 0 else 1;
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
   182
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
   183
17824
36b2978d339a added string_of_pid;
wenzelm
parents: 17077
diff changeset
   184
(*Convert a process ID to a decimal string (chiefly for tracing)*)
36b2978d339a added string_of_pid;
wenzelm
parents: 17077
diff changeset
   185
fun string_of_pid pid = 
23139
aa899bce7c3b TextIO.inputLine: use present SML B library version;
wenzelm
parents: 22144
diff changeset
   186
  Word.fmt StringCvt.DEC (Word.fromLargeWord (Posix.Process.pidToWord pid));
17824
36b2978d339a added string_of_pid;
wenzelm
parents: 17077
diff changeset
   187
36b2978d339a added string_of_pid;
wenzelm
parents: 17077
diff changeset
   188
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   189
(* getenv *)
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   190
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   191
fun getenv var =
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   192
  (case OS.Process.getEnv var of
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   193
    NONE => ""
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   194
  | SOME txt => txt);
15028
f6a22afe0134 new profiling function
paulson
parents: 14870
diff changeset
   195
f6a22afe0134 new profiling function
paulson
parents: 14870
diff changeset
   196
16659
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   197
(* profile execution *)
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   198
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   199
local
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   200
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   201
fun no_profile () =
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   202
  RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler 0;
15028
f6a22afe0134 new profiling function
paulson
parents: 14870
diff changeset
   203
16659
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   204
in
15699
7d91dd712ff8 fixing an incompatibility with Posix.IO.mkTextReader
paulson
parents: 15028
diff changeset
   205
16659
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   206
fun profile 0 f x = f x
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   207
  | profile n f x =
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   208
     (RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler n;
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   209
      let val y = f x handle exn => (no_profile (); raise exn)
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   210
      in no_profile (); y end);
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   211
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   212
end;