src/Pure/ML-Systems/polyml-5.1.ML
author wenzelm
Mon Jul 23 20:47:55 2007 +0200 (2007-07-23)
changeset 23943 1b5f77bc146a
child 23947 5e396bcf749e
permissions -rw-r--r--
added compatibility wrapper for polyml-5.1;
wenzelm@23943
     1
(*  Title:      Pure/ML-Systems/polyml-5.0.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@23943
     8
wenzelm@23943
     9
val pointer_eq = PolyML.pointerEq;
wenzelm@23943
    10
wenzelm@23943
    11
wenzelm@23943
    12
(* improved versions of use_text/file *)
wenzelm@23943
    13
wenzelm@23943
    14
fun use_text name (print, err) verbose txt =
wenzelm@23943
    15
  let
wenzelm@23943
    16
    val in_buffer = ref (explode txt);
wenzelm@23943
    17
    val out_buffer = ref ([]: string list);
wenzelm@23943
    18
    fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
wenzelm@23943
    19
wenzelm@23943
    20
    val line_no = ref 1;
wenzelm@23943
    21
    fun line () = ! line_no;
wenzelm@23943
    22
    fun get () =
wenzelm@23943
    23
      (case ! in_buffer of
wenzelm@23943
    24
        [] => ""
wenzelm@23943
    25
      | c :: cs => (in_buffer := cs; if c = "\n" then line_no := ! line_no + 1 else (); c));
wenzelm@23943
    26
    fun put s = out_buffer := s :: ! out_buffer;
wenzelm@23943
    27
wenzelm@23943
    28
    fun exec () =
wenzelm@23943
    29
      (case ! in_buffer of
wenzelm@23943
    30
        [] => ()
wenzelm@23943
    31
      | _ => (PolyML.compilerEx (get, put, line, name) (); exec ()));
wenzelm@23943
    32
  in
wenzelm@23943
    33
    exec () handle exn => (err (output ()); raise exn);
wenzelm@23943
    34
    if verbose then print (output ()) else ()
wenzelm@23943
    35
  end;
wenzelm@23943
    36
wenzelm@23943
    37
fun use_file output verbose name =
wenzelm@23943
    38
  let
wenzelm@23943
    39
    val instream = TextIO.openIn name;
wenzelm@23943
    40
    val txt = TextIO.inputAll instream before TextIO.closeIn instream;
wenzelm@23943
    41
  in use_text name output verbose txt end;