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;
wenzelm@26382
     1
(*  Title:      Pure/ML-Systems/polyml_old_compiler4.ML
wenzelm@26382
     2
    ID:         $Id$
wenzelm@26382
     3
wenzelm@26385
     4
Runtime compilation -- for old PolyML.compiler (version 4.x).
wenzelm@26382
     5
*)
wenzelm@26382
     6
wenzelm@26884
     7
fun use_text (tune: string -> string) _ (line: int, name) (print, err) verbose txt =
wenzelm@26382
     8
  let
wenzelm@26382
     9
    val in_buffer = ref (explode (tune txt));
wenzelm@26382
    10
    val out_buffer = ref ([]: string list);
wenzelm@26382
    11
    fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
wenzelm@26382
    12
wenzelm@26382
    13
    fun get () =
wenzelm@26382
    14
      (case ! in_buffer of
wenzelm@26382
    15
        [] => ""
wenzelm@26382
    16
      | c :: cs => (in_buffer := cs; c));
wenzelm@26382
    17
    fun put s = out_buffer := s :: ! out_buffer;
wenzelm@26382
    18
wenzelm@26382
    19
    fun exec () =
wenzelm@26382
    20
      (case ! in_buffer of
wenzelm@26382
    21
        [] => ()
wenzelm@26382
    22
      | _ => (PolyML.compiler (get, put) (); exec ()));
wenzelm@26382
    23
  in
wenzelm@26382
    24
    exec () handle exn =>
wenzelm@26382
    25
      (err ((if name = "" then "" else "Error in " ^ name ^ "\n") ^ output ()); raise exn);
wenzelm@26382
    26
    if verbose then print (output ()) else ()
wenzelm@26382
    27
  end;
wenzelm@26382
    28
wenzelm@26885
    29
fun use_file tune str_of_pos output verbose name =
wenzelm@26382
    30
  let
wenzelm@26382
    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@26382
    34