src/Pure/ML-Systems/polyml-5.0.ML
author wenzelm
Tue, 24 Jul 2007 19:44:33 +0200
changeset 23962 e0358fac0541
parent 23139 aa899bce7c3b
child 24600 5877b88f262c
permissions -rw-r--r--
Runtime exceptions as values (from library.ML);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/polyml-5.0.ML
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     3
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     4
Compatibility wrapper for Poly/ML 5.0.
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     5
*)
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     6
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     7
use "ML-Systems/polyml.ML";
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     8
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     9
val pointer_eq = PolyML.pointerEq;
21771
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    10
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    11
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    12
(* improved versions of use_text/file *)
21853
ae3707892310 activated improved use_ml, which captures output and reports source positions;
wenzelm
parents: 21771
diff changeset
    13
22144
c33450acd873 use_text: added name argument;
wenzelm
parents: 21923
diff changeset
    14
fun use_text name (print, err) verbose txt =
21771
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    15
  let
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    16
    val in_buffer = ref (explode txt);
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    17
    val out_buffer = ref ([]: string list);
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    18
    fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    19
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    20
    val line_no = ref 1;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    21
    fun line () = ! line_no;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    22
    fun get () =
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    23
      (case ! in_buffer of
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    24
        [] => ""
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    25
      | c :: cs => (in_buffer := cs; if c = "\n" then line_no := ! line_no + 1 else (); c));
21923
663108ee4eef use_ml: reverted to simple output (Poly/ML changed);
wenzelm
parents: 21853
diff changeset
    26
    fun put s = out_buffer := s :: ! out_buffer;
21771
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    27
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    28
    fun exec () =
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    29
      (case ! in_buffer of
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    30
        [] => ()
21923
663108ee4eef use_ml: reverted to simple output (Poly/ML changed);
wenzelm
parents: 21853
diff changeset
    31
      | _ => (PolyML.compilerEx (get, put, line, name) (); exec ()));
21771
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    32
  in
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    33
    exec () handle exn => (err (output ()); raise exn);
21923
663108ee4eef use_ml: reverted to simple output (Poly/ML changed);
wenzelm
parents: 21853
diff changeset
    34
    if verbose then print (output ()) else ()
21771
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    35
  end;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    36
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    37
fun use_file output verbose name =
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    38
  let
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    39
    val instream = TextIO.openIn name;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    40
    val txt = TextIO.inputAll instream before TextIO.closeIn instream;
22144
c33450acd873 use_text: added name argument;
wenzelm
parents: 21923
diff changeset
    41
  in use_text name output verbose txt end;