author | wenzelm |
Tue, 18 Mar 2014 13:36:28 +0100 | |
changeset 56203 | 76c72f4d0667 |
parent 48992 | 0518bf89c777 |
child 56275 | 600f432ab556 |
permissions | -rw-r--r-- |
31325 | 1 |
(* Title: Pure/ML/ml_env.ML |
2 |
Author: Makarius |
|
3 |
||
31470 | 4 |
Local environment of ML results. |
31325 | 5 |
*) |
6 |
||
7 |
signature ML_ENV = |
|
8 |
sig |
|
9 |
val inherit: Context.generic -> Context.generic -> Context.generic |
|
10 |
val name_space: ML_Name_Space.T |
|
11 |
val local_context: use_context |
|
36163
823c9400eb62
proper checking of ML functors (in Poly/ML 5.2 or later);
wenzelm
parents:
33519
diff
changeset
|
12 |
val check_functor: string -> unit |
31325 | 13 |
end |
14 |
||
15 |
structure ML_Env: ML_ENV = |
|
16 |
struct |
|
17 |
||
31328 | 18 |
(* context data *) |
19 |
||
33519 | 20 |
structure Env = Generic_Data |
31325 | 21 |
( |
22 |
type T = |
|
56203
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
23 |
bool * (*global bootstrap environment*) |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
24 |
(ML_Name_Space.valueVal Symtab.table * |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
25 |
ML_Name_Space.typeVal Symtab.table * |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
26 |
ML_Name_Space.fixityVal Symtab.table * |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
27 |
ML_Name_Space.structureVal Symtab.table * |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
28 |
ML_Name_Space.signatureVal Symtab.table * |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
29 |
ML_Name_Space.functorVal Symtab.table); |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
30 |
val empty : T = |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
31 |
(true, (Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty)); |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
32 |
fun extend (_, tabs) : T = (false, tabs); |
33519 | 33 |
fun merge |
56203
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
34 |
((_, (val1, type1, fixity1, structure1, signature1, functor1)), |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
35 |
(_, (val2, type2, fixity2, structure2, signature2, functor2))) : T = |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
36 |
(false, |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
37 |
(Symtab.merge (K true) (val1, val2), |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
38 |
Symtab.merge (K true) (type1, type2), |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
39 |
Symtab.merge (K true) (fixity1, fixity2), |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
40 |
Symtab.merge (K true) (structure1, structure2), |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
41 |
Symtab.merge (K true) (signature1, signature2), |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
42 |
Symtab.merge (K true) (functor1, functor2))); |
31325 | 43 |
); |
44 |
||
45 |
val inherit = Env.put o Env.get; |
|
46 |
||
31328 | 47 |
|
48 |
(* results *) |
|
49 |
||
31325 | 50 |
val name_space: ML_Name_Space.T = |
51 |
let |
|
52 |
fun lookup sel1 sel2 name = |
|
53 |
Context.thread_data () |
|
56203
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
54 |
|> (fn NONE => NONE | SOME context => Symtab.lookup (sel1 (#2 (Env.get context))) name) |
31325 | 55 |
|> (fn NONE => sel2 ML_Name_Space.global name | some => some); |
56 |
||
57 |
fun all sel1 sel2 () = |
|
58 |
Context.thread_data () |
|
56203
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
59 |
|> (fn NONE => [] | SOME context => Symtab.dest (sel1 (#2 (Env.get context)))) |
31325 | 60 |
|> append (sel2 ML_Name_Space.global ()) |
61 |
|> sort_distinct (string_ord o pairself #1); |
|
62 |
||
63 |
fun enter ap1 sel2 entry = |
|
64 |
if is_some (Context.thread_data ()) then |
|
56203
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
65 |
Context.>> (Env.map (fn (global, tabs) => |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
66 |
let |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
67 |
val _ = if global then sel2 ML_Name_Space.global entry else (); |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
68 |
val tabs' = ap1 (Symtab.update entry) tabs; |
76c72f4d0667
clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents:
48992
diff
changeset
|
69 |
in (global, tabs') end)) |
31325 | 70 |
else sel2 ML_Name_Space.global entry; |
71 |
in |
|
72 |
{lookupVal = lookup #1 #lookupVal, |
|
73 |
lookupType = lookup #2 #lookupType, |
|
74 |
lookupFix = lookup #3 #lookupFix, |
|
75 |
lookupStruct = lookup #4 #lookupStruct, |
|
76 |
lookupSig = lookup #5 #lookupSig, |
|
77 |
lookupFunct = lookup #6 #lookupFunct, |
|
78 |
enterVal = enter (fn h => fn (a, b, c, d, e, f) => (h a, b, c, d, e, f)) #enterVal, |
|
79 |
enterType = enter (fn h => fn (a, b, c, d, e, f) => (a, h b, c, d, e, f)) #enterType, |
|
80 |
enterFix = enter (fn h => fn (a, b, c, d, e, f) => (a, b, h c, d, e, f)) #enterFix, |
|
81 |
enterStruct = enter (fn h => fn (a, b, c, d, e, f) => (a, b, c, h d, e, f)) #enterStruct, |
|
82 |
enterSig = enter (fn h => fn (a, b, c, d, e, f) => (a, b, c, d, h e, f)) #enterSig, |
|
83 |
enterFunct = enter (fn h => fn (a, b, c, d, e, f) => (a, b, c, d, e, h f)) #enterFunct, |
|
84 |
allVal = all #1 #allVal, |
|
85 |
allType = all #2 #allType, |
|
86 |
allFix = all #3 #allFix, |
|
87 |
allStruct = all #4 #allStruct, |
|
88 |
allSig = all #5 #allSig, |
|
89 |
allFunct = all #6 #allFunct} |
|
90 |
end; |
|
91 |
||
92 |
val local_context: use_context = |
|
93 |
{tune_source = ML_Parse.fix_ints, |
|
94 |
name_space = name_space, |
|
48992 | 95 |
str_of_pos = Position.here oo Position.line_file, |
31325 | 96 |
print = writeln, |
97 |
error = error}; |
|
98 |
||
36163
823c9400eb62
proper checking of ML functors (in Poly/ML 5.2 or later);
wenzelm
parents:
33519
diff
changeset
|
99 |
val is_functor = is_some o #lookupFunct name_space; |
823c9400eb62
proper checking of ML functors (in Poly/ML 5.2 or later);
wenzelm
parents:
33519
diff
changeset
|
100 |
|
823c9400eb62
proper checking of ML functors (in Poly/ML 5.2 or later);
wenzelm
parents:
33519
diff
changeset
|
101 |
fun check_functor name = |
36165 | 102 |
if not (is_functor "Table") (*mask dummy version of name_space*) orelse is_functor name then () |
36163
823c9400eb62
proper checking of ML functors (in Poly/ML 5.2 or later);
wenzelm
parents:
33519
diff
changeset
|
103 |
else error ("Unknown ML functor: " ^ quote name); |
823c9400eb62
proper checking of ML functors (in Poly/ML 5.2 or later);
wenzelm
parents:
33519
diff
changeset
|
104 |
|
31325 | 105 |
end; |
106 |