author | wenzelm |
Fri, 16 Apr 2010 11:39:08 +0200 | |
changeset 36163 | 823c9400eb62 |
parent 33519 | e31a85f92ce9 |
child 36165 | 310a3f2f0e7e |
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 = |
|
31430 | 23 |
ML_Name_Space.valueVal Symtab.table * |
24 |
ML_Name_Space.typeVal Symtab.table * |
|
25 |
ML_Name_Space.fixityVal Symtab.table * |
|
26 |
ML_Name_Space.structureVal Symtab.table * |
|
27 |
ML_Name_Space.signatureVal Symtab.table * |
|
28 |
ML_Name_Space.functorVal Symtab.table; |
|
29 |
val empty = (Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty); |
|
31325 | 30 |
val extend = I; |
33519 | 31 |
fun merge |
31430 | 32 |
((val1, type1, fixity1, structure1, signature1, functor1), |
33 |
(val2, type2, fixity2, structure2, signature2, functor2)) : T = |
|
31328 | 34 |
(Symtab.merge (K true) (val1, val2), |
35 |
Symtab.merge (K true) (type1, type2), |
|
36 |
Symtab.merge (K true) (fixity1, fixity2), |
|
37 |
Symtab.merge (K true) (structure1, structure2), |
|
38 |
Symtab.merge (K true) (signature1, signature2), |
|
31430 | 39 |
Symtab.merge (K true) (functor1, functor2)); |
31325 | 40 |
); |
41 |
||
42 |
val inherit = Env.put o Env.get; |
|
43 |
||
31328 | 44 |
|
45 |
(* results *) |
|
46 |
||
31325 | 47 |
val name_space: ML_Name_Space.T = |
48 |
let |
|
49 |
fun lookup sel1 sel2 name = |
|
50 |
Context.thread_data () |
|
31430 | 51 |
|> (fn NONE => NONE | SOME context => Symtab.lookup (sel1 (Env.get context)) name) |
31325 | 52 |
|> (fn NONE => sel2 ML_Name_Space.global name | some => some); |
53 |
||
54 |
fun all sel1 sel2 () = |
|
55 |
Context.thread_data () |
|
31430 | 56 |
|> (fn NONE => [] | SOME context => Symtab.dest (sel1 (Env.get context))) |
31325 | 57 |
|> append (sel2 ML_Name_Space.global ()) |
58 |
|> sort_distinct (string_ord o pairself #1); |
|
59 |
||
60 |
fun enter ap1 sel2 entry = |
|
61 |
if is_some (Context.thread_data ()) then |
|
31430 | 62 |
Context.>> (Env.map (ap1 (Symtab.update entry))) |
31325 | 63 |
else sel2 ML_Name_Space.global entry; |
64 |
in |
|
65 |
{lookupVal = lookup #1 #lookupVal, |
|
66 |
lookupType = lookup #2 #lookupType, |
|
67 |
lookupFix = lookup #3 #lookupFix, |
|
68 |
lookupStruct = lookup #4 #lookupStruct, |
|
69 |
lookupSig = lookup #5 #lookupSig, |
|
70 |
lookupFunct = lookup #6 #lookupFunct, |
|
71 |
enterVal = enter (fn h => fn (a, b, c, d, e, f) => (h a, b, c, d, e, f)) #enterVal, |
|
72 |
enterType = enter (fn h => fn (a, b, c, d, e, f) => (a, h b, c, d, e, f)) #enterType, |
|
73 |
enterFix = enter (fn h => fn (a, b, c, d, e, f) => (a, b, h c, d, e, f)) #enterFix, |
|
74 |
enterStruct = enter (fn h => fn (a, b, c, d, e, f) => (a, b, c, h d, e, f)) #enterStruct, |
|
75 |
enterSig = enter (fn h => fn (a, b, c, d, e, f) => (a, b, c, d, h e, f)) #enterSig, |
|
76 |
enterFunct = enter (fn h => fn (a, b, c, d, e, f) => (a, b, c, d, e, h f)) #enterFunct, |
|
77 |
allVal = all #1 #allVal, |
|
78 |
allType = all #2 #allType, |
|
79 |
allFix = all #3 #allFix, |
|
80 |
allStruct = all #4 #allStruct, |
|
81 |
allSig = all #5 #allSig, |
|
82 |
allFunct = all #6 #allFunct} |
|
83 |
end; |
|
84 |
||
85 |
val local_context: use_context = |
|
86 |
{tune_source = ML_Parse.fix_ints, |
|
87 |
name_space = name_space, |
|
88 |
str_of_pos = Position.str_of oo Position.line_file, |
|
89 |
print = writeln, |
|
90 |
error = error}; |
|
91 |
||
36163
823c9400eb62
proper checking of ML functors (in Poly/ML 5.2 or later);
wenzelm
parents:
33519
diff
changeset
|
92 |
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
|
93 |
|
823c9400eb62
proper checking of ML functors (in Poly/ML 5.2 or later);
wenzelm
parents:
33519
diff
changeset
|
94 |
fun check_functor name = |
823c9400eb62
proper checking of ML functors (in Poly/ML 5.2 or later);
wenzelm
parents:
33519
diff
changeset
|
95 |
if is_functor "Table" (*lookup actually works*) andalso is_functor name then () |
823c9400eb62
proper checking of ML functors (in Poly/ML 5.2 or later);
wenzelm
parents:
33519
diff
changeset
|
96 |
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
|
97 |
|
31325 | 98 |
end; |
99 |