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;
wenzelm@26383
     1
(*  Title:      Pure/ML-Systems/polyml_old_compiler5.ML
wenzelm@26383
     2
    ID:         $Id$
wenzelm@26383
     3
wenzelm@26385
     4
Runtime compilation -- for old PolyML.compilerEx (version 5.0, 5.1).
wenzelm@26383
     5
*)
wenzelm@26383
     6
wenzelm@26884
     7
fun use_text (tune: string -> string) _ (line, name) (print, err) verbose txt =
wenzelm@26383
     8
  let
wenzelm@26383
     9
    val in_buffer = ref (explode (tune txt));
wenzelm@26383
    10
    val out_buffer = ref ([]: string list);
wenzelm@26383
    11
    fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
wenzelm@26383
    12
wenzelm@26385
    13
    val current_line = ref line;
wenzelm@26383
    14
    fun get () =
wenzelm@26383
    15
      (case ! in_buffer of
wenzelm@26383
    16
        [] => ""
wenzelm@26385
    17
      | c :: cs => (in_buffer := cs; if c = "\n" then current_line := ! current_line + 1 else (); c));
wenzelm@26383
    18
    fun put s = out_buffer := s :: ! out_buffer;
wenzelm@26383
    19
wenzelm@26383
    20
    fun exec () =
wenzelm@26383
    21
      (case ! in_buffer of
wenzelm@26383
    22
        [] => ()
wenzelm@26385
    23
      | _ => (PolyML.compilerEx (get, put, fn () => ! current_line, name) (); exec ()));
wenzelm@26383
    24
  in
wenzelm@26383
    25
    exec () handle exn => (err (output ()); raise exn);
wenzelm@26383
    26
    if verbose then print (output ()) else ()
wenzelm@26383
    27
  end;
wenzelm@26383
    28
wenzelm@26885
    29
fun use_file tune str_of_pos output verbose name =
wenzelm@26383
    30
  let
wenzelm@26383
    31
    val instream = TextIO.openIn name;
wenzelm@26504
    32
    val txt = Exn.release (Exn.capture TextIO.inputAll instream before TextIO.closeIn instream);
wenzelm@26885
    33
  in use_text tune str_of_pos (1, name) output verbose txt end;
wenzelm@26383
    34