src/Pure/ML-Systems/polyml_old_compiler5.ML
author wenzelm
Wed, 14 May 2008 11:09:07 +0200
changeset 26885 cfd5eb167706
parent 26884 67c54c53da28
child 28268 ac8431ecd57e
permissions -rw-r--r--
use_file: pass str_of_pos;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26383
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/polyml_old_compiler5.ML
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
     3
26385
ae7564661e76 ML runtime compilation: pass position, tuned signature;
wenzelm
parents: 26383
diff changeset
     4
Runtime compilation -- for old PolyML.compilerEx (version 5.0, 5.1).
26383
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
     5
*)
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
     6
26884
67c54c53da28 use_text/file: ignore str_of_pos argument;
wenzelm
parents: 26504
diff changeset
     7
fun use_text (tune: string -> string) _ (line, name) (print, err) verbose txt =
26383
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
     8
  let
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
     9
    val in_buffer = ref (explode (tune txt));
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    10
    val out_buffer = ref ([]: string list);
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    11
    fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    12
26385
ae7564661e76 ML runtime compilation: pass position, tuned signature;
wenzelm
parents: 26383
diff changeset
    13
    val current_line = ref line;
26383
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    14
    fun get () =
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    15
      (case ! in_buffer of
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    16
        [] => ""
26385
ae7564661e76 ML runtime compilation: pass position, tuned signature;
wenzelm
parents: 26383
diff changeset
    17
      | c :: cs => (in_buffer := cs; if c = "\n" then current_line := ! current_line + 1 else (); c));
26383
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    18
    fun put s = out_buffer := s :: ! out_buffer;
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    19
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    20
    fun exec () =
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    21
      (case ! in_buffer of
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    22
        [] => ()
26385
ae7564661e76 ML runtime compilation: pass position, tuned signature;
wenzelm
parents: 26383
diff changeset
    23
      | _ => (PolyML.compilerEx (get, put, fn () => ! current_line, name) (); exec ()));
26383
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    24
  in
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    25
    exec () handle exn => (err (output ()); raise exn);
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    26
    if verbose then print (output ()) else ()
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    27
  end;
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    28
26885
cfd5eb167706 use_file: pass str_of_pos;
wenzelm
parents: 26884
diff changeset
    29
fun use_file tune str_of_pos output verbose name =
26383
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    30
  let
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    31
    val instream = TextIO.openIn name;
26504
6e87c0a60104 before close: Exn.capture/release;
wenzelm
parents: 26385
diff changeset
    32
    val txt = Exn.release (Exn.capture TextIO.inputAll instream before TextIO.closeIn instream);
26885
cfd5eb167706 use_file: pass str_of_pos;
wenzelm
parents: 26884
diff changeset
    33
  in use_text tune str_of_pos (1, name) output verbose txt end;
26383
08da16c3f124 Runtime compilation -- for old version of PolyML.compilerEx (version 5.0, 5.1).
wenzelm
parents:
diff changeset
    34