src/Pure/ML-Systems/polyml.ML
author wenzelm
Mon, 24 Mar 2008 23:34:24 +0100
changeset 26385 ae7564661e76
parent 26379 a01a05cdd3b8
child 26390 99d4cbb1f941
permissions -rw-r--r--
ML runtime compilation: pass position, tuned signature;
     1 (*  Title:      Pure/ML-Systems/polyml.ML
     2     ID:         $Id$
     3 
     4 Compatibility wrapper for Poly/ML (after 5.1).
     5 *)
     6 
     7 use "ML-Systems/polyml_common.ML";
     8 use "ML-Systems/multithreading_polyml.ML";
     9 
    10 val pointer_eq = PolyML.pointerEq;
    11 
    12 
    13 (* single-threaded profiling *)
    14 
    15 local val profile_orig = profile in
    16 
    17 fun profile 0 f x = f x
    18   | profile n f x = NAMED_CRITICAL "profile" (fn () => profile_orig n f x);
    19 
    20 end;
    21 
    22 
    23 (* improved versions of use_text/file *)
    24 
    25 fun use_text (tune: string -> string) (line, name) (print, err) verbose txt =
    26   let
    27     val in_buffer = ref (String.explode (tune txt));
    28     val out_buffer = ref ([]: string list);
    29     fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
    30 
    31     val current_line = ref line;
    32     fun get () =
    33       (case ! in_buffer of
    34         [] => NONE
    35       | c :: cs =>
    36           (in_buffer := cs; if c = #"\n" then current_line := ! current_line + 1 else (); SOME c));
    37     fun put s = out_buffer := s :: ! out_buffer;
    38 
    39     val _ =
    40       (while not (List.null (! in_buffer)) do
    41         PolyML.compiler
    42           {getChar = get, putString = put, lineNumber = fn () => ! current_line, fileName = name,
    43             nameSpace = PolyML.globalNameSpace} ())
    44       handle exn => (err (output ()); raise exn);
    45   in
    46     if verbose then print (output ()) else ()
    47   end;
    48 
    49 fun use_file tune output verbose name =
    50   let
    51     val instream = TextIO.openIn name;
    52     val txt = TextIO.inputAll instream before TextIO.closeIn instream;
    53   in use_text tune (1, name) output verbose txt end;
    54