| author | huffman |
| Mon, 27 Apr 2009 07:26:17 -0700 | |
| changeset 31007 | 7c871a9cf6f4 |
| parent 30672 | beaadd5af500 |
| child 31312 | 1c00e4ff3c99 |
| permissions | -rw-r--r-- |
| 2341 | 1 |
(* Title: Pure/ML-Systems/polyml.ML |
2 |
||
| 28255 | 3 |
Compatibility wrapper for Poly/ML 5.2 or later. |
| 2341 | 4 |
*) |
5 |
||
| 28152 | 6 |
open Thread; |
|
30672
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
7 |
|
|
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
8 |
structure ML_Name_Space = |
|
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
9 |
struct |
|
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
10 |
open PolyML.NameSpace; |
|
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
11 |
type T = PolyML.NameSpace.nameSpace; |
|
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
12 |
val global = PolyML.globalNameSpace; |
|
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
13 |
end; |
|
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
14 |
|
|
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
26084
diff
changeset
|
15 |
use "ML-Systems/polyml_common.ML"; |
|
28676
78688a5fafc2
multithreading support only for polyml-5.2.1 or later;
wenzelm
parents:
28268
diff
changeset
|
16 |
|
|
28796
56cb4130177a
multithreading support for polyml-5.2 actually disabled -- as advertized;
wenzelm
parents:
28676
diff
changeset
|
17 |
if ml_system = "polyml-5.2" |
|
56cb4130177a
multithreading support for polyml-5.2 actually disabled -- as advertized;
wenzelm
parents:
28676
diff
changeset
|
18 |
then use "ML-Systems/thread_dummy.ML" |
|
28676
78688a5fafc2
multithreading support only for polyml-5.2.1 or later;
wenzelm
parents:
28268
diff
changeset
|
19 |
else use "ML-Systems/multithreading_polyml.ML"; |
|
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
26084
diff
changeset
|
20 |
|
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
26084
diff
changeset
|
21 |
val pointer_eq = PolyML.pointerEq; |
|
23921
947152add153
added compatibility file for ML systems without multithreading;
wenzelm
parents:
23826
diff
changeset
|
22 |
|
|
29638
1f8f3d26a2cf
added share_common_data -- reduces heap space, but takes long;
wenzelm
parents:
29564
diff
changeset
|
23 |
fun share_common_data () = PolyML.shareCommonData PolyML.rootFunction; |
|
1f8f3d26a2cf
added share_common_data -- reduces heap space, but takes long;
wenzelm
parents:
29564
diff
changeset
|
24 |
|
| 25023 | 25 |
|
|
26390
99d4cbb1f941
moved multithreaded "profile" to multithreading_polyml.ML;
wenzelm
parents:
26385
diff
changeset
|
26 |
(* runtime compilation *) |
| 3588 | 27 |
|
| 26883 | 28 |
local |
29 |
||
30 |
fun drop_newline s = |
|
31 |
if String.isSuffix "\n" s then String.substring (s, 0, size s - 1) |
|
32 |
else s; |
|
33 |
||
34 |
in |
|
35 |
||
|
30672
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
36 |
fun use_text ({tune_source, name_space, str_of_pos, print, error, ...}: use_context)
|
|
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
37 |
(start_line, name) verbose txt = |
| 3588 | 38 |
let |
| 26883 | 39 |
val current_line = ref start_line; |
|
30672
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
40 |
val in_buffer = ref (String.explode (tune_source txt)); |
| 5090 | 41 |
val out_buffer = ref ([]: string list); |
| 26883 | 42 |
fun output () = drop_newline (implode (rev (! out_buffer))); |
| 5090 | 43 |
|
| 5038 | 44 |
fun get () = |
| 5090 | 45 |
(case ! in_buffer of |
| 26379 | 46 |
[] => NONE |
|
26385
ae7564661e76
ML runtime compilation: pass position, tuned signature;
wenzelm
parents:
26379
diff
changeset
|
47 |
| c :: cs => |
|
ae7564661e76
ML runtime compilation: pass position, tuned signature;
wenzelm
parents:
26379
diff
changeset
|
48 |
(in_buffer := cs; if c = #"\n" then current_line := ! current_line + 1 else (); SOME c)); |
| 5090 | 49 |
fun put s = out_buffer := s :: ! out_buffer; |
| 26883 | 50 |
fun message (msg, is_err, line) = |
51 |
(if is_err then "Error: " else "Warning: ") ^ drop_newline msg ^ str_of_pos line name ^ "\n"; |
|
| 5090 | 52 |
|
|
26879
4fc89bfc4b0c
adapted PolyML.compiler to latest change of basis/FinalPolyML.sml (2008-04-21);
wenzelm
parents:
26625
diff
changeset
|
53 |
val parameters = |
|
4fc89bfc4b0c
adapted PolyML.compiler to latest change of basis/FinalPolyML.sml (2008-04-21);
wenzelm
parents:
26625
diff
changeset
|
54 |
[PolyML.Compiler.CPOutStream put, |
|
4fc89bfc4b0c
adapted PolyML.compiler to latest change of basis/FinalPolyML.sml (2008-04-21);
wenzelm
parents:
26625
diff
changeset
|
55 |
PolyML.Compiler.CPLineNo (fn () => ! current_line), |
|
28268
ac8431ecd57e
use_text/use_file now depend on explicit ML name space;
wenzelm
parents:
28255
diff
changeset
|
56 |
PolyML.Compiler.CPErrorMessageProc (put o message), |
|
ac8431ecd57e
use_text/use_file now depend on explicit ML name space;
wenzelm
parents:
28255
diff
changeset
|
57 |
PolyML.Compiler.CPNameSpace name_space]; |
| 26379 | 58 |
val _ = |
59 |
(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
|
60 |
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
|
61 |
handle exn => |
|
e0cc4169626e
use_text: explicitly print exception, which is no longer done by the new PolyML.compiler setup;
wenzelm
parents:
26504
diff
changeset
|
62 |
(put ("Exception- " ^ General.exnMessage exn ^ " raised");
|
|
30672
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
63 |
error (output ()); raise exn); |
| 26883 | 64 |
in if verbose then print (output ()) else () end; |
| 3588 | 65 |
|
|
30672
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
66 |
fun use_file context verbose name = |
| 24598 | 67 |
let |
68 |
val instream = TextIO.openIn name; |
|
| 26504 | 69 |
val txt = Exn.release (Exn.capture TextIO.inputAll instream before TextIO.closeIn instream); |
|
30672
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30627
diff
changeset
|
70 |
in use_text context (1, name) verbose txt end; |
| 26379 | 71 |
|
| 26883 | 72 |
end; |
|
30627
fb9e73c01603
added polyml_pp.ML: toplevel pretty printing for Poly/ML 4.x and 5.x before 5.3;
wenzelm
parents:
29638
diff
changeset
|
73 |
|
|
fb9e73c01603
added polyml_pp.ML: toplevel pretty printing for Poly/ML 4.x and 5.x before 5.3;
wenzelm
parents:
29638
diff
changeset
|
74 |
use "ML-Systems/polyml_pp.ML"; |
|
fb9e73c01603
added polyml_pp.ML: toplevel pretty printing for Poly/ML 4.x and 5.x before 5.3;
wenzelm
parents:
29638
diff
changeset
|
75 |