src/Pure/ML-Systems/polyml-5.1.ML
author wenzelm
Tue Jul 24 19:44:38 2007 +0200 (2007-07-24)
changeset 23966 25f34ff5eedf
parent 23947 5e396bcf749e
child 24584 01e83ffa6c54
permissions -rw-r--r--
moved exception capture/release to structure Exn;
moved multithreading to multithreading_polyml.ML;
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@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@23943
    15
fun use_text name (print, err) verbose txt =
wenzelm@23943
    16
  let
wenzelm@23943
    17
    val in_buffer = ref (explode 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@23943
    38
fun use_file 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@23943
    42
  in use_text name output verbose txt end;