src/Pure/ML-Systems/polyml.ML
author wenzelm
Tue, 16 Aug 2005 13:42:48 +0200
changeset 17077 f5af929f0fb4
parent 16659 1cf39eba29fe
child 17824 36b2978d339a
permissions -rw-r--r--
added String.isSuffix;
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
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     4
    Copyright   1991  University of Cambridge
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     5
14870
c5cf7c001313 tuned comments;
wenzelm
parents: 14850
diff changeset
     6
Compatibility file for Poly/ML (version 4.0, 4.1, 4.1.x).
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     7
*)
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
     8
16374
f4b7cf8975af some cygwin support;
wenzelm
parents: 16266
diff changeset
     9
(** ML system and platform related **)
f4b7cf8975af some cygwin support;
wenzelm
parents: 16266
diff changeset
    10
17077
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    11
(* String compatibility *)
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    12
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    13
structure String =
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    14
struct
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    15
  fun isSuffix s1 s2 =
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    16
    let val n1 = size s1 and n2 = size s2
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    17
    in if n1 = n2 then s1 = s2 else n1 <= n2 andalso String.substring (s2, n2 - n1, n1) = s1 end;
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    18
  open String;
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    19
end;
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    20
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    21
16374
f4b7cf8975af some cygwin support;
wenzelm
parents: 16266
diff changeset
    22
(* cygwin *)
f4b7cf8975af some cygwin support;
wenzelm
parents: 16266
diff changeset
    23
17077
f5af929f0fb4 added String.isSuffix;
wenzelm
parents: 16659
diff changeset
    24
val cygwin_platform = String.isSuffix "cygwin" ml_platform;
16374
f4b7cf8975af some cygwin support;
wenzelm
parents: 16266
diff changeset
    25
fun if_cygwin f x = if cygwin_platform then f x else ();
f4b7cf8975af some cygwin support;
wenzelm
parents: 16266
diff changeset
    26
fun unless_cygwin f x = if not cygwin_platform then f x else ();
f4b7cf8975af some cygwin support;
wenzelm
parents: 16266
diff changeset
    27
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    28
16516
0842635545c3 tuned pointer_eq;
wenzelm
parents: 16502
diff changeset
    29
(*low-level pointer equality*)
0842635545c3 tuned pointer_eq;
wenzelm
parents: 16502
diff changeset
    30
val pointer_eq = Address.wordEq;
16502
5a56e59526a5 added pointer_eq;
wenzelm
parents: 16453
diff changeset
    31
5a56e59526a5 added pointer_eq;
wenzelm
parents: 16453
diff changeset
    32
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    33
(* old Poly/ML emulation *)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    34
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    35
local
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    36
  val orig_exit = exit;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    37
in
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    38
  open PolyML;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    39
  val exit = orig_exit;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    40
  fun quit () = exit 0;
7148
e9c253036b45 removed obsolete concat;
wenzelm
parents: 7147
diff changeset
    41
end;
6042
0ccde2f25dd6 Basis Library compatible substring oeration
paulson
parents: 5813
diff changeset
    42
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    43
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    44
(* restore old-style character / string functions *)
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    45
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    46
val ord = SML90.ord;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    47
val chr = SML90.chr;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    48
val explode = SML90.explode;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    49
val implode = SML90.implode;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    50
14870
c5cf7c001313 tuned comments;
wenzelm
parents: 14850
diff changeset
    51
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12989
diff changeset
    52
(* compiler-independent timing functions *)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    53
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12989
diff changeset
    54
use "ML-Systems/cpu-timer-basis.ML";
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    55
14870
c5cf7c001313 tuned comments;
wenzelm
parents: 14850
diff changeset
    56
14850
393a7be73160 including polyml-time-limit.ML
webertj
parents: 14519
diff changeset
    57
(* bounded time execution *)
393a7be73160 including polyml-time-limit.ML
webertj
parents: 14519
diff changeset
    58
16374
f4b7cf8975af some cygwin support;
wenzelm
parents: 16266
diff changeset
    59
unless_cygwin
f4b7cf8975af some cygwin support;
wenzelm
parents: 16266
diff changeset
    60
  use "ML-Systems/polyml-time-limit.ML";
14850
393a7be73160 including polyml-time-limit.ML
webertj
parents: 14519
diff changeset
    61
14870
c5cf7c001313 tuned comments;
wenzelm
parents: 14850
diff changeset
    62
4977
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    63
(* prompts *)
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    64
4984
d17004d4c13b fixed ml_prompts;
wenzelm
parents: 4977
diff changeset
    65
fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2);
4977
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    66
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    67
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    68
(* 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
    69
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
    70
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
    71
  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
    72
    fn () => brk (99999, 0), en);
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    73
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
    74
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    75
(* ML command execution -- 'eval' *)
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    76
7890
0aa16bc2abdb use_text: remove last char from output;
wenzelm
parents: 7855
diff changeset
    77
local
0aa16bc2abdb use_text: remove last char from output;
wenzelm
parents: 7855
diff changeset
    78
0aa16bc2abdb use_text: remove last char from output;
wenzelm
parents: 7855
diff changeset
    79
fun drop_last [] = []
0aa16bc2abdb use_text: remove last char from output;
wenzelm
parents: 7855
diff changeset
    80
  | drop_last [x] = []
0aa16bc2abdb use_text: remove last char from output;
wenzelm
parents: 7855
diff changeset
    81
  | drop_last (x :: xs) = x :: drop_last xs;
0aa16bc2abdb use_text: remove last char from output;
wenzelm
parents: 7855
diff changeset
    82
0aa16bc2abdb use_text: remove last char from output;
wenzelm
parents: 7855
diff changeset
    83
in
0aa16bc2abdb use_text: remove last char from output;
wenzelm
parents: 7855
diff changeset
    84
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 8830
diff changeset
    85
fun use_text (print, err) verbose txt =
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
    86
  let
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    87
    val in_buffer = ref (explode txt);
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    88
    val out_buffer = ref ([]: string list);
15832
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
    89
    fun output () = implode (drop_last (rev (! out_buffer)));
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    90
5038
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4984
diff changeset
    91
    fun get () =
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    92
      (case ! in_buffer of
5038
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4984
diff changeset
    93
        [] => ""
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    94
      | c :: cs => (in_buffer := cs; c));
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    95
    fun put s = out_buffer := s :: ! out_buffer;
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    96
5038
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4984
diff changeset
    97
    fun exec () =
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    98
      (case ! in_buffer of
5038
301c37df931d use_text replaces use_strings;
wenzelm
parents: 4984
diff changeset
    99
        [] => ()
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
   100
      | _ => (PolyML.compiler (get, put) (); exec ()));
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
   101
  in
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 8830
diff changeset
   102
    exec () handle exn => (err (output ()); raise exn);
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 8830
diff changeset
   103
    if verbose then print (output ()) else ()
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
   104
  end;
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   105
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   106
end;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   107
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   108
15832
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   109
(*eval command line arguments*)
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   110
local
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   111
  fun println s =
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   112
    (TextIO.output (TextIO.stdOut, s ^ "\n"); TextIO.flushOut TextIO.stdOut);
15851
6b445e021bc8 eval command line: show results;
wenzelm
parents: 15832
diff changeset
   113
  val eval = use_text (println, println) true;
15832
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   114
in
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   115
  val _ = PolyML.onEntry (fn () => app eval (CommandLine.arguments ()));
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   116
end;
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   117
df958c7afe50 eval command line arguments;
wenzelm
parents: 15702
diff changeset
   118
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   119
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   120
(** interrupts **)
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   121
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   122
exception Interrupt = SML90.Interrupt;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   123
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   124
local
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 capture f x = ((f x): unit; NONE) handle exn => SOME exn;
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   127
12989
42ac77552dbf renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12108
diff changeset
   128
fun release NONE = ()
42ac77552dbf renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12108
diff changeset
   129
  | release (SOME exn) = raise exn;
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   130
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   131
val sig_int = 2;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   132
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   133
fun change_signal new_handler f x =
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   134
  let
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   135
    (*RACE wrt. other signals*)
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   136
    val old_handler = Signal.signal (sig_int, new_handler);
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   137
    val result = capture f x;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   138
    val _ = Signal.signal (sig_int, old_handler);
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   139
  in release result end;
5813
4eea84a9427d fake interrupt handler;
wenzelm
parents: 5090
diff changeset
   140
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   141
val default_handler = Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ());
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   142
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   143
in
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   144
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   145
val _ = Signal.signal (sig_int, default_handler);
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   146
12989
42ac77552dbf renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12108
diff changeset
   147
fun ignore_interrupt f = change_signal Signal.SIG_IGN f;
42ac77552dbf renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12108
diff changeset
   148
fun raise_interrupt f = change_signal default_handler f;
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   149
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   150
end;
5813
4eea84a9427d fake interrupt handler;
wenzelm
parents: 5090
diff changeset
   151
4eea84a9427d fake interrupt handler;
wenzelm
parents: 5090
diff changeset
   152
4eea84a9427d fake interrupt handler;
wenzelm
parents: 5090
diff changeset
   153
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   154
(** OS related **)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
   155
16659
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   156
unless_cygwin
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   157
  use "ML-Systems/polyml-posix.ML";
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   158
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   159
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   160
(* system command execution *)
2341
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
   161
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   162
(*execute Unix command which doesn't take any input from stdin and
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   163
  sends its output to stdout; could be done more easily by Unix.execute,
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   164
  but that function doesn't use the PATH*)
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   165
fun execute command =
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   166
  let
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   167
    val tmp_name = OS.FileSys.tmpName ();
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   168
    val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   169
    val result = TextIO.inputAll is;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   170
  in
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   171
    TextIO.closeIn is;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   172
    OS.FileSys.remove tmp_name;
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   173
    result
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   174
  end;
7855
092a6435afad system;
wenzelm
parents: 7148
diff changeset
   175
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   176
(*plain version; with return code*)
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   177
fun system cmd =
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   178
  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
   179
e154da40ef00 Compatibility file for Poly/ML (versions 2.x, 3.x).
wenzelm
parents:
diff changeset
   180
3588
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   181
(* getenv *)
e487bf0ed6c4 cleaned up;
wenzelm
parents: 2408
diff changeset
   182
11078
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   183
fun getenv var =
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   184
  (case OS.Process.getEnv var of
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   185
    NONE => ""
c1b32e7124b4 4.0 version;
wenzelm
parents: 10914
diff changeset
   186
  | SOME txt => txt);
15028
f6a22afe0134 new profiling function
paulson
parents: 14870
diff changeset
   187
f6a22afe0134 new profiling function
paulson
parents: 14870
diff changeset
   188
16659
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   189
(* profile execution *)
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   190
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   191
local
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   192
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   193
fun no_profile () =
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   194
  RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler 0;
15028
f6a22afe0134 new profiling function
paulson
parents: 14870
diff changeset
   195
16659
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   196
in
15699
7d91dd712ff8 fixing an incompatibility with Posix.IO.mkTextReader
paulson
parents: 15028
diff changeset
   197
16659
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   198
fun profile 0 f x = f x
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   199
  | profile n f x =
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   200
     (RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler n;
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   201
      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
   202
      in no_profile (); y end);
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   203
1cf39eba29fe added profiler interface, keep 'profiling' of PolyML structure;
wenzelm
parents: 16516
diff changeset
   204
end;