src/Pure/ML-Systems/polyml_old_compiler5.ML
author wenzelm
Thu Sep 04 16:03:47 2008 +0200 (2008-09-04)
changeset 28124 10a1f1f4c6ae
parent 26885 cfd5eb167706
child 28268 ac8431ecd57e
permissions -rw-r--r--
moved Multithreading.task/schedule to Concurrent/schedule.ML;
     1 (*  Title:      Pure/ML-Systems/polyml_old_compiler5.ML
     2     ID:         $Id$
     3 
     4 Runtime compilation -- for old PolyML.compilerEx (version 5.0, 5.1).
     5 *)
     6 
     7 fun use_text (tune: string -> string) _ (line, name) (print, err) verbose txt =
     8   let
     9     val in_buffer = ref (explode (tune txt));
    10     val out_buffer = ref ([]: string list);
    11     fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
    12 
    13     val current_line = ref line;
    14     fun get () =
    15       (case ! in_buffer of
    16         [] => ""
    17       | c :: cs => (in_buffer := cs; if c = "\n" then current_line := ! current_line + 1 else (); c));
    18     fun put s = out_buffer := s :: ! out_buffer;
    19 
    20     fun exec () =
    21       (case ! in_buffer of
    22         [] => ()
    23       | _ => (PolyML.compilerEx (get, put, fn () => ! current_line, name) (); exec ()));
    24   in
    25     exec () handle exn => (err (output ()); raise exn);
    26     if verbose then print (output ()) else ()
    27   end;
    28 
    29 fun use_file tune str_of_pos output verbose name =
    30   let
    31     val instream = TextIO.openIn name;
    32     val txt = Exn.release (Exn.capture TextIO.inputAll instream before TextIO.closeIn instream);
    33   in use_text tune str_of_pos (1, name) output verbose txt end;
    34