src/Pure/ML-Systems/polyml-5.1.ML
author wenzelm
Tue, 24 Jul 2007 19:44:38 +0200
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;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23943
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/polyml-5.0.ML
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
     3
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
     4
Compatibility wrapper for Poly/ML 5.1.
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
     5
*)
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
     6
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
     7
use "ML-Systems/polyml.ML";
23966
25f34ff5eedf moved exception capture/release to structure Exn;
wenzelm
parents: 23947
diff changeset
     8
use "ML-Systems/multithreading_polyml.ML";
23943
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
     9
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    10
val pointer_eq = PolyML.pointerEq;
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    11
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    12
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    13
(* improved versions of use_text/file *)
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    14
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    15
fun use_text name (print, err) verbose txt =
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    16
  let
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    17
    val in_buffer = ref (explode txt);
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    18
    val out_buffer = ref ([]: string list);
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    19
    fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    20
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    21
    val line_no = ref 1;
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    22
    fun line () = ! line_no;
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    23
    fun get () =
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    24
      (case ! in_buffer of
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    25
        [] => ""
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    26
      | c :: cs => (in_buffer := cs; if c = "\n" then line_no := ! line_no + 1 else (); c));
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    27
    fun put s = out_buffer := s :: ! out_buffer;
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    28
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    29
    fun exec () =
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    30
      (case ! in_buffer of
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    31
        [] => ()
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    32
      | _ => (PolyML.compilerEx (get, put, line, name) (); exec ()));
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    33
  in
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    34
    exec () handle exn => (err (output ()); raise exn);
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    35
    if verbose then print (output ()) else ()
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    36
  end;
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    37
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    38
fun use_file output verbose name =
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    39
  let
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    40
    val instream = TextIO.openIn name;
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    41
    val txt = TextIO.inputAll instream before TextIO.closeIn instream;
1b5f77bc146a added compatibility wrapper for polyml-5.1;
wenzelm
parents:
diff changeset
    42
  in use_text name output verbose txt end;