src/Pure/ML-Systems/polyml-5.0.ML
author berghofe
Mon Jan 21 14:18:49 2008 +0100 (2008-01-21)
changeset 25939 ddea202704b4
parent 24605 98689b0e5956
child 26215 94d32a7cd0fb
permissions -rw-r--r--
Removed Logic.auto_rename.
wenzelm@21653
     1
(*  Title:      Pure/ML-Systems/polyml-5.0.ML
wenzelm@21653
     2
    ID:         $Id$
wenzelm@21653
     3
wenzelm@21653
     4
Compatibility wrapper for Poly/ML 5.0.
wenzelm@21653
     5
*)
wenzelm@21653
     6
wenzelm@21653
     7
use "ML-Systems/polyml.ML";
wenzelm@21653
     8
wenzelm@21653
     9
val pointer_eq = PolyML.pointerEq;
wenzelm@21771
    10
wenzelm@21771
    11
wenzelm@21771
    12
(* improved versions of use_text/file *)
wenzelm@21853
    13
wenzelm@24600
    14
fun use_text (tune: string -> string) name (print, err) verbose txt =
wenzelm@21771
    15
  let
wenzelm@24600
    16
    val in_buffer = ref (explode (tune txt));
wenzelm@21771
    17
    val out_buffer = ref ([]: string list);
wenzelm@21771
    18
    fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
wenzelm@21771
    19
wenzelm@21771
    20
    val line_no = ref 1;
wenzelm@21771
    21
    fun line () = ! line_no;
wenzelm@21771
    22
    fun get () =
wenzelm@21771
    23
      (case ! in_buffer of
wenzelm@21771
    24
        [] => ""
wenzelm@21771
    25
      | c :: cs => (in_buffer := cs; if c = "\n" then line_no := ! line_no + 1 else (); c));
wenzelm@21923
    26
    fun put s = out_buffer := s :: ! out_buffer;
wenzelm@21771
    27
wenzelm@21771
    28
    fun exec () =
wenzelm@21771
    29
      (case ! in_buffer of
wenzelm@21771
    30
        [] => ()
wenzelm@21923
    31
      | _ => (PolyML.compilerEx (get, put, line, name) (); exec ()));
wenzelm@21771
    32
  in
wenzelm@21771
    33
    exec () handle exn => (err (output ()); raise exn);
wenzelm@21923
    34
    if verbose then print (output ()) else ()
wenzelm@21771
    35
  end;
wenzelm@21771
    36
wenzelm@24605
    37
fun use_file tune output verbose name =
wenzelm@21771
    38
  let
wenzelm@21771
    39
    val instream = TextIO.openIn name;
wenzelm@21771
    40
    val txt = TextIO.inputAll instream before TextIO.closeIn instream;
wenzelm@24605
    41
  in use_text tune name output verbose txt end;