src/Pure/ML-Systems/polyml-5.1.ML
author wenzelm
Sun Sep 16 14:55:48 2007 +0200 (2007-09-16)
changeset 24600 5877b88f262c
parent 24584 01e83ffa6c54
child 24852 30da58e0a483
permissions -rw-r--r--
use_text/file: tune text (cf. ML_Parse.fix_ints);
haftmann@24584
     1
(*  Title:      Pure/ML-Systems/polyml-5.1.ML
wenzelm@23943
     2
    ID:         $Id$
wenzelm@23943
     3
wenzelm@23943
     4
Compatibility wrapper for Poly/ML 5.1.
wenzelm@23943
     5
*)
wenzelm@23943
     6
wenzelm@23943
     7
use "ML-Systems/polyml.ML";
wenzelm@23966
     8
use "ML-Systems/multithreading_polyml.ML";
wenzelm@23943
     9
wenzelm@23943
    10
val pointer_eq = PolyML.pointerEq;
wenzelm@23943
    11
wenzelm@23943
    12
wenzelm@23943
    13
(* improved versions of use_text/file *)
wenzelm@23943
    14
wenzelm@24600
    15
fun use_text (tune: string -> string) name (print, err) verbose txt =
wenzelm@23943
    16
  let
wenzelm@24600
    17
    val in_buffer = ref (explode (tune txt));
wenzelm@23943
    18
    val out_buffer = ref ([]: string list);
wenzelm@23943
    19
    fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
wenzelm@23943
    20
wenzelm@23943
    21
    val line_no = ref 1;
wenzelm@23943
    22
    fun line () = ! line_no;
wenzelm@23943
    23
    fun get () =
wenzelm@23943
    24
      (case ! in_buffer of
wenzelm@23943
    25
        [] => ""
wenzelm@23943
    26
      | c :: cs => (in_buffer := cs; if c = "\n" then line_no := ! line_no + 1 else (); c));
wenzelm@23943
    27
    fun put s = out_buffer := s :: ! out_buffer;
wenzelm@23943
    28
wenzelm@23943
    29
    fun exec () =
wenzelm@23943
    30
      (case ! in_buffer of
wenzelm@23943
    31
        [] => ()
wenzelm@23943
    32
      | _ => (PolyML.compilerEx (get, put, line, name) (); exec ()));
wenzelm@23943
    33
  in
wenzelm@23943
    34
    exec () handle exn => (err (output ()); raise exn);
wenzelm@23943
    35
    if verbose then print (output ()) else ()
wenzelm@23943
    36
  end;
wenzelm@23943
    37
wenzelm@24600
    38
fun use_file tune output verbose name =
wenzelm@23943
    39
  let
wenzelm@23943
    40
    val instream = TextIO.openIn name;
wenzelm@23943
    41
    val txt = TextIO.inputAll instream before TextIO.closeIn instream;
wenzelm@24600
    42
  in use_text tune name output verbose txt end;