src/Pure/ML-Systems/polyml_old_compiler5.ML
author wenzelm
Sun Mar 01 23:36:12 2009 +0100 (2009-03-01)
changeset 30190 479806475f3c
parent 29564 f8b933a62151
child 30672 beaadd5af500
permissions -rw-r--r--
use long names for old-style fold combinators;
     1 (*  Title:      Pure/ML-Systems/polyml_old_compiler5.ML
     2 
     3 Runtime compilation -- for old PolyML.compilerEx (version 5.0, 5.1).
     4 *)
     5 
     6 fun use_text (tune: string -> string) _ _ (line, name) (print, err) verbose txt =
     7   let
     8     val in_buffer = ref (explode (tune txt));
     9     val out_buffer = ref ([]: string list);
    10     fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
    11 
    12     val current_line = ref line;
    13     fun get () =
    14       (case ! in_buffer of
    15         [] => ""
    16       | c :: cs => (in_buffer := cs; if c = "\n" then current_line := ! current_line + 1 else (); c));
    17     fun put s = out_buffer := s :: ! out_buffer;
    18 
    19     fun exec () =
    20       (case ! in_buffer of
    21         [] => ()
    22       | _ => (PolyML.compilerEx (get, put, fn () => ! current_line, name) (); exec ()));
    23   in
    24     exec () handle exn => (err (output ()); raise exn);
    25     if verbose then print (output ()) else ()
    26   end;
    27 
    28 fun use_file tune str_of_pos name_space output verbose name =
    29   let
    30     val instream = TextIO.openIn name;
    31     val txt = Exn.release (Exn.capture TextIO.inputAll instream before TextIO.closeIn instream);
    32   in use_text tune str_of_pos name_space (1, name) output verbose txt end;