author | blanchet |
Wed, 15 Dec 2010 18:10:32 +0100 | |
changeset 41171 | 043f8dc3b51f |
parent 40748 | 591b6778d076 |
child 41352 | 87adb55fb0fb |
permissions | -rw-r--r-- |
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/ML-Systems/polyml_common.ML |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
2 |
|
31308 | 3 |
Compatibility file for Poly/ML -- common part for 5.x. |
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
4 |
*) |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
5 |
|
28443 | 6 |
exception Interrupt = SML90.Interrupt; |
7 |
||
34136 | 8 |
use "General/exn.ML"; |
36876 | 9 |
|
10 |
if List.exists (fn s => s = "SingleAssignment") (PolyML.Compiler.structureNames ()) |
|
11 |
then () |
|
12 |
else use "ML-Systems/single_assignment_polyml.ML"; |
|
13 |
||
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
14 |
use "ML-Systems/multithreading.ML"; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
15 |
use "ML-Systems/time_limit.ML"; |
40393 | 16 |
use "General/timing.ML"; |
30619 | 17 |
use "ML-Systems/ml_pretty.ML"; |
30672
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents:
30625
diff
changeset
|
18 |
use "ML-Systems/use_context.ML"; |
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
19 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
20 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
21 |
(** ML system and platform related **) |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
22 |
|
26474 | 23 |
val forget_structure = PolyML.Compiler.forgetStructure; |
24 |
||
33213
1b550123f133
forget old some old option stuff from NJ -- superceded by material in Pure/General/basics.ML;
wenzelm
parents:
33060
diff
changeset
|
25 |
val _ = PolyML.Compiler.forgetValue "isSome"; |
1b550123f133
forget old some old option stuff from NJ -- superceded by material in Pure/General/basics.ML;
wenzelm
parents:
33060
diff
changeset
|
26 |
val _ = PolyML.Compiler.forgetValue "getOpt"; |
1b550123f133
forget old some old option stuff from NJ -- superceded by material in Pure/General/basics.ML;
wenzelm
parents:
33060
diff
changeset
|
27 |
val _ = PolyML.Compiler.forgetValue "valOf"; |
33004
715566791eb0
always qualify NJ's old List.foldl/foldr in Isabelle/ML;
wenzelm
parents:
32776
diff
changeset
|
28 |
val _ = PolyML.Compiler.forgetValue "foldl"; |
715566791eb0
always qualify NJ's old List.foldl/foldr in Isabelle/ML;
wenzelm
parents:
32776
diff
changeset
|
29 |
val _ = PolyML.Compiler.forgetValue "foldr"; |
31324
3ffa005c7701
removed print function from global ML name space, to reduce risk of surprises;
wenzelm
parents:
31319
diff
changeset
|
30 |
val _ = PolyML.Compiler.forgetValue "print"; |
40627
becf5d5187cc
renamed raw "explode" function to "raw_explode" to emphasize its meaning;
wenzelm
parents:
40393
diff
changeset
|
31 |
val _ = PolyML.Compiler.forgetValue "explode"; |
31324
3ffa005c7701
removed print function from global ML name space, to reduce risk of surprises;
wenzelm
parents:
31319
diff
changeset
|
32 |
|
26474 | 33 |
|
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
34 |
(* Compiler options *) |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
35 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
36 |
val ml_system_fix_ints = false; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
37 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
38 |
PolyML.Compiler.printInAlphabeticalOrder := false; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
39 |
PolyML.Compiler.maxInlineSize := 80; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
40 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
41 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
42 |
(* old Poly/ML emulation *) |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
43 |
|
31319
6974449ddea9
no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents:
31308
diff
changeset
|
44 |
fun quit () = exit 0; |
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
45 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
46 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
47 |
(* restore old-style character / string functions *) |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
48 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
49 |
val ord = SML90.ord; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
50 |
val chr = SML90.chr; |
40627
becf5d5187cc
renamed raw "explode" function to "raw_explode" to emphasize its meaning;
wenzelm
parents:
40393
diff
changeset
|
51 |
val raw_explode = SML90.explode; |
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
52 |
val implode = SML90.implode; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
53 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
54 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
55 |
(* prompts *) |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
56 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
57 |
fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2); |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
58 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
59 |
|
36162
0bd034a80a9a
added ML antiquotation @{make_string}, which produces proper pretty printed version in Poly/ML 5.3.0 or later;
wenzelm
parents:
35014
diff
changeset
|
60 |
(* toplevel printing *) |
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
61 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
62 |
local |
39616
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
39585
diff
changeset
|
63 |
val depth = ref 10; |
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
64 |
in |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
65 |
fun get_print_depth () = ! depth; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
66 |
fun print_depth n = (depth := n; PolyML.print_depth n); |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
67 |
end; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
68 |
|
31319
6974449ddea9
no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents:
31308
diff
changeset
|
69 |
val error_depth = PolyML.error_depth; |
6974449ddea9
no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents:
31308
diff
changeset
|
70 |
|
36162
0bd034a80a9a
added ML antiquotation @{make_string}, which produces proper pretty printed version in Poly/ML 5.3.0 or later;
wenzelm
parents:
35014
diff
changeset
|
71 |
val ml_make_string = "PolyML.makestring"; |
0bd034a80a9a
added ML antiquotation @{make_string}, which produces proper pretty printed version in Poly/ML 5.3.0 or later;
wenzelm
parents:
35014
diff
changeset
|
72 |
|
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
73 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
74 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
75 |
(** interrupts **) |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
76 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
77 |
local |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
78 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
79 |
val sig_int = 2; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
80 |
val default_handler = Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ()); |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
81 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
82 |
val _ = Signal.signal (sig_int, default_handler); |
26380
5d368eb42c11
removed pointer_eq from polyml_common.ML (structure Address no longer available after 5.1);
wenzelm
parents:
26220
diff
changeset
|
83 |
val _ = PolyML.onEntry (fn () => (Signal.signal (sig_int, default_handler); ())); |
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
84 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
85 |
fun change_signal new_handler f x = |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
86 |
let |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
87 |
(*RACE wrt. other signals!*) |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
88 |
val old_handler = Signal.signal (sig_int, new_handler); |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
89 |
val result = Exn.capture (f old_handler) x; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
90 |
val _ = Signal.signal (sig_int, old_handler); |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
91 |
in Exn.release result end; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
92 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
93 |
in |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
94 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
95 |
fun interruptible f = change_signal default_handler (fn _ => f); |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
96 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
97 |
fun uninterruptible f = |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
98 |
change_signal Signal.SIG_IGN |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
99 |
(fn old_handler => f (fn g => change_signal old_handler (fn _ => g))); |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
100 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
101 |
end; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
102 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
103 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
104 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
105 |
(** OS related **) |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
106 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
107 |
(* current directory *) |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
108 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
109 |
val cd = OS.FileSys.chDir; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
110 |
val pwd = OS.FileSys.getDir; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
111 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
112 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
113 |
(* getenv *) |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
114 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
115 |
fun getenv var = |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
116 |
(case OS.Process.getEnv var of |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
117 |
NONE => "" |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
118 |
| SOME txt => txt); |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
119 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
120 |
|
31319
6974449ddea9
no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents:
31308
diff
changeset
|
121 |
|
6974449ddea9
no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents:
31308
diff
changeset
|
122 |
(** Runtime system **) |
6974449ddea9
no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents:
31308
diff
changeset
|
123 |
|
6974449ddea9
no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents:
31308
diff
changeset
|
124 |
val exception_trace = PolyML.exception_trace; |
6974449ddea9
no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents:
31308
diff
changeset
|
125 |
val timing = PolyML.timing; |
6974449ddea9
no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents:
31308
diff
changeset
|
126 |
val profiling = PolyML.profiling; |
26215
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
127 |
|
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
128 |
fun profile 0 f x = f x |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
129 |
| profile n f x = |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
130 |
let |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
131 |
val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler n; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
132 |
val res = Exn.capture f x; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
133 |
val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler 0; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
134 |
in Exn.release res end; |
94d32a7cd0fb
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff
changeset
|
135 |