src/Pure/ML-Systems/polyml.ML
author wenzelm
Tue, 25 Mar 2008 12:14:17 +0100
changeset 26390 99d4cbb1f941
parent 26385 ae7564661e76
child 26504 6e87c0a60104
permissions -rw-r--r--
moved multithreaded "profile" to multithreading_polyml.ML;

(*  Title:      Pure/ML-Systems/polyml.ML
    ID:         $Id$

Compatibility wrapper for Poly/ML (after 5.1).
*)

use "ML-Systems/polyml_common.ML";
use "ML-Systems/multithreading_polyml.ML";

val pointer_eq = PolyML.pointerEq;


(* runtime compilation *)

fun use_text (tune: string -> string) (line, name) (print, err) verbose txt =
  let
    val in_buffer = ref (String.explode (tune txt));
    val out_buffer = ref ([]: string list);
    fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));

    val current_line = ref line;
    fun get () =
      (case ! in_buffer of
        [] => NONE
      | c :: cs =>
          (in_buffer := cs; if c = #"\n" then current_line := ! current_line + 1 else (); SOME c));
    fun put s = out_buffer := s :: ! out_buffer;

    val _ =
      (while not (List.null (! in_buffer)) do
        PolyML.compiler
          {getChar = get, putString = put, lineNumber = fn () => ! current_line, fileName = name,
            nameSpace = PolyML.globalNameSpace} ())
      handle exn => (err (output ()); raise exn);
  in
    if verbose then print (output ()) else ()
  end;

fun use_file tune output verbose name =
  let
    val instream = TextIO.openIn name;
    val txt = TextIO.inputAll instream before TextIO.closeIn instream;
  in use_text tune (1, name) output verbose txt end;