src/Pure/ML-Systems/polyml-5.0.ML
author wenzelm
Mon, 11 Dec 2006 19:05:25 +0100
changeset 21771 148c8aba89dd
parent 21653 219924615db6
child 21853 ae3707892310
permissions -rw-r--r--
added improved versions of use_text/file (still inactive);
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-4.1.4-patch.ML";
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     8
use "ML-Systems/polyml.ML";
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     9
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    10
val pointer_eq = PolyML.pointerEq;
21771
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
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    13
(* improved versions of use_text/file *)
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    14
(*
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    15
local
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    16
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    17
fun use_ml name (print, err) verbose txt =
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    18
  let
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    19
    val in_buffer = ref (explode txt);
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    20
    val out_buffer = ref ([]: string list);
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    21
    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
    22
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    23
    val line_no = ref 1;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    24
    fun line () = ! line_no;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    25
    fun get () =
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    26
      (case ! in_buffer of
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
      | c :: cs => (in_buffer := cs; if c = "\n" then line_no := ! line_no + 1 else (); c));
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    29
    fun put s = out_buffer := s :: ! out_buffer;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    30
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    31
    fun exec () =
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    32
      (case ! in_buffer of
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    33
        [] => ()
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    34
      | _ => (PolyML.compilerEx (get, put, line, name) (); exec ()));
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    35
  in
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    36
    exec () handle exn => (err (output ()); raise exn);
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    37
    if verbose then print (output ()) else ()
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    38
  end;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    39
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    40
in
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    41
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    42
fun use_text output = use_ml "ML text" output;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    43
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    44
fun use_file output verbose name =
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    45
  let
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    46
    val instream = TextIO.openIn name;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    47
    val txt = TextIO.inputAll instream before TextIO.closeIn instream;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    48
  in use_ml name output verbose txt end;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    49
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    50
end;
148c8aba89dd added improved versions of use_text/file (still inactive);
wenzelm
parents: 21653
diff changeset
    51
*)