1 (* Title: Pure/ML-Systems/polyml.ML
4 Compatibility wrapper for Poly/ML (after 5.1).
7 use "ML-Systems/polyml_common.ML";
8 use "ML-Systems/multithreading_polyml.ML";
10 val pointer_eq = PolyML.pointerEq;
13 (* single-threaded profiling *)
15 local val profile_orig = profile in
17 fun profile 0 f x = f x
18 | profile n f x = NAMED_CRITICAL "profile" (fn () => profile_orig n f x);
23 (* improved versions of use_text/file *)
25 fun use_text (tune: string -> string) (line, name) (print, err) verbose txt =
27 val in_buffer = ref (String.explode (tune txt));
28 val out_buffer = ref ([]: string list);
29 fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
31 val current_line = ref line;
36 (in_buffer := cs; if c = #"\n" then current_line := ! current_line + 1 else (); SOME c));
37 fun put s = out_buffer := s :: ! out_buffer;
40 (while not (List.null (! in_buffer)) do
42 {getChar = get, putString = put, lineNumber = fn () => ! current_line, fileName = name,
43 nameSpace = PolyML.globalNameSpace} ())
44 handle exn => (err (output ()); raise exn);
46 if verbose then print (output ()) else ()
49 fun use_file tune output verbose name =
51 val instream = TextIO.openIn name;
52 val txt = TextIO.inputAll instream before TextIO.closeIn instream;
53 in use_text tune (1, name) output verbose txt end;