src/Pure/ML-Systems/polyml_old_compiler4.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_compiler4.ML
     2     ID:         $Id$
     3 
     4 Runtime compilation -- for old PolyML.compiler (version 4.x).
     5 *)
     6 
     7 fun use_text (tune: string -> string) _ (line: int, 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     fun get () =
    14       (case ! in_buffer of
    15         [] => ""
    16       | c :: cs => (in_buffer := cs; c));
    17     fun put s = out_buffer := s :: ! out_buffer;
    18 
    19     fun exec () =
    20       (case ! in_buffer of
    21         [] => ()
    22       | _ => (PolyML.compiler (get, put) (); exec ()));
    23   in
    24     exec () handle exn =>
    25       (err ((if name = "" then "" else "Error in " ^ name ^ "\n") ^ 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