author | wenzelm |
Sun, 08 Jun 2008 14:31:06 +0200 | |
changeset 27094 | 2cf13a72e170 |
parent 26883 | ae6ae88f9240 |
child 28125 | e99427bcf7f3 |
permissions | -rw-r--r-- |
2341 | 1 |
(* Title: Pure/ML-Systems/polyml.ML |
2 |
ID: $Id$ |
|
3 |
||
26379 | 4 |
Compatibility wrapper for Poly/ML (after 5.1). |
2341 | 5 |
*) |
6 |
||
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
26084
diff
changeset
|
7 |
use "ML-Systems/polyml_common.ML"; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
26084
diff
changeset
|
8 |
use "ML-Systems/multithreading_polyml.ML"; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
26084
diff
changeset
|
9 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
26084
diff
changeset
|
10 |
val pointer_eq = PolyML.pointerEq; |
23921
947152add153
added compatibility file for ML systems without multithreading;
wenzelm
parents:
23826
diff
changeset
|
11 |
|
25023 | 12 |
|
26390
99d4cbb1f941
moved multithreaded "profile" to multithreading_polyml.ML;
wenzelm
parents:
26385
diff
changeset
|
13 |
(* runtime compilation *) |
3588 | 14 |
|
26883 | 15 |
local |
16 |
||
17 |
fun drop_newline s = |
|
18 |
if String.isSuffix "\n" s then String.substring (s, 0, size s - 1) |
|
19 |
else s; |
|
20 |
||
21 |
in |
|
22 |
||
23 |
fun use_text (tune: string -> string) str_of_pos (start_line, name) (print, err) verbose txt = |
|
3588 | 24 |
let |
26883 | 25 |
val current_line = ref start_line; |
26379 | 26 |
val in_buffer = ref (String.explode (tune txt)); |
5090 | 27 |
val out_buffer = ref ([]: string list); |
26883 | 28 |
fun output () = drop_newline (implode (rev (! out_buffer))); |
5090 | 29 |
|
5038 | 30 |
fun get () = |
5090 | 31 |
(case ! in_buffer of |
26379 | 32 |
[] => NONE |
26385
ae7564661e76
ML runtime compilation: pass position, tuned signature;
wenzelm
parents:
26379
diff
changeset
|
33 |
| c :: cs => |
ae7564661e76
ML runtime compilation: pass position, tuned signature;
wenzelm
parents:
26379
diff
changeset
|
34 |
(in_buffer := cs; if c = #"\n" then current_line := ! current_line + 1 else (); SOME c)); |
5090 | 35 |
fun put s = out_buffer := s :: ! out_buffer; |
26883 | 36 |
fun message (msg, is_err, line) = |
37 |
(if is_err then "Error: " else "Warning: ") ^ drop_newline msg ^ str_of_pos line name ^ "\n"; |
|
5090 | 38 |
|
26879
4fc89bfc4b0c
adapted PolyML.compiler to latest change of basis/FinalPolyML.sml (2008-04-21);
wenzelm
parents:
26625
diff
changeset
|
39 |
val parameters = |
4fc89bfc4b0c
adapted PolyML.compiler to latest change of basis/FinalPolyML.sml (2008-04-21);
wenzelm
parents:
26625
diff
changeset
|
40 |
[PolyML.Compiler.CPOutStream put, |
4fc89bfc4b0c
adapted PolyML.compiler to latest change of basis/FinalPolyML.sml (2008-04-21);
wenzelm
parents:
26625
diff
changeset
|
41 |
PolyML.Compiler.CPLineNo (fn () => ! current_line), |
26883 | 42 |
PolyML.Compiler.CPErrorMessageProc (put o message)]; |
26379 | 43 |
val _ = |
44 |
(while not (List.null (! in_buffer)) do |
|
26879
4fc89bfc4b0c
adapted PolyML.compiler to latest change of basis/FinalPolyML.sml (2008-04-21);
wenzelm
parents:
26625
diff
changeset
|
45 |
PolyML.compiler (get, parameters) ()) |
26625
e0cc4169626e
use_text: explicitly print exception, which is no longer done by the new PolyML.compiler setup;
wenzelm
parents:
26504
diff
changeset
|
46 |
handle exn => |
e0cc4169626e
use_text: explicitly print exception, which is no longer done by the new PolyML.compiler setup;
wenzelm
parents:
26504
diff
changeset
|
47 |
(put ("Exception- " ^ General.exnMessage exn ^ " raised"); |
e0cc4169626e
use_text: explicitly print exception, which is no longer done by the new PolyML.compiler setup;
wenzelm
parents:
26504
diff
changeset
|
48 |
err (output ()); raise exn); |
26883 | 49 |
in if verbose then print (output ()) else () end; |
3588 | 50 |
|
26883 | 51 |
fun use_file tune str_of_pos output verbose name = |
24598 | 52 |
let |
53 |
val instream = TextIO.openIn name; |
|
26504 | 54 |
val txt = Exn.release (Exn.capture TextIO.inputAll instream before TextIO.closeIn instream); |
26883 | 55 |
in use_text tune str_of_pos (1, name) output verbose txt end; |
26379 | 56 |
|
26883 | 57 |
end; |
58 |