17735
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Collection subclass:#SystemDictionary
|
|
14 |
instanceVariableNames:'sysId'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'System-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
!SystemDictionary class methodsFor:'documentation'!
|
|
21 |
|
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
25 |
All Rights Reserved
|
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
|
36 |
version
|
|
37 |
^ '$Header: /cvs/stx/stx/libbasic/not_delivered/SysDict.st,v 1.1 1996/09/12 01:05:30 cg Exp $'
|
|
38 |
!
|
|
39 |
|
|
40 |
documentation
|
|
41 |
"
|
|
42 |
SystemDictionaries are nameSpaces, which are also known in the c-world
|
|
43 |
somehow (i.e. names found in SystemDictionaries may also be known as
|
|
44 |
a c-global).
|
|
45 |
|
|
46 |
As you will notice, this is NOT a Dictionary
|
|
47 |
- my implementation of globals is totally different
|
|
48 |
(due to the need to be able to access globals from c-code as well).
|
|
49 |
However, it provides the known enumeration protocol.
|
|
50 |
|
|
51 |
Instance variables:
|
|
52 |
sysId <SmallInteger> the dictionaries id
|
|
53 |
"
|
|
54 |
! !
|
|
55 |
|
|
56 |
!SystemDictionary methodsFor:'accessing'!
|
|
57 |
|
|
58 |
at:aKey
|
|
59 |
"retrieve the value stored under aKey, which must be some kind of symbol.
|
|
60 |
Return nil if not present."
|
|
61 |
|
|
62 |
%{ /* NOCONTEXT */
|
|
63 |
extern OBJ _SYSDICT_GET();
|
|
64 |
|
|
65 |
if (__isSmallInteger(__INST(sysId))) {
|
|
66 |
RETURN ( _SYSDICT_GET(__intVal(__INST(sysId)), aKey) );
|
|
67 |
}
|
|
68 |
%}.
|
|
69 |
"
|
|
70 |
the receiver is not a valid systemDictionary
|
|
71 |
"
|
|
72 |
self pimitiveFailed
|
|
73 |
!
|
|
74 |
|
|
75 |
at:aKey ifAbsent:aBlock
|
|
76 |
"retrieve the value stored under aKey.
|
|
77 |
If there is none stored this key, return the value of
|
|
78 |
the evaluation of aBlock"
|
|
79 |
|
|
80 |
(self includesKey:aKey) ifTrue:[
|
|
81 |
^ self at:aKey
|
|
82 |
].
|
|
83 |
^ aBlock value
|
|
84 |
!
|
|
85 |
|
|
86 |
at:aKey put:aValue
|
|
87 |
"store the argument aValue under aKey, which must be some kind of symbol."
|
|
88 |
|
|
89 |
%{ /* NOCONTEXT */
|
|
90 |
if (__isSmallInteger(__INST(sysId))) {
|
|
91 |
_SYSDICT_SET(__intVal(__INST(sysId)), aKey, aValue, (OBJ *)0);
|
|
92 |
RETURN (aValue);
|
|
93 |
}
|
|
94 |
%}.
|
|
95 |
"
|
|
96 |
the receiver is not a valid systemDictionary
|
|
97 |
"
|
|
98 |
self pimitiveFailed
|
|
99 |
!
|
|
100 |
|
|
101 |
removeKey:aKey
|
|
102 |
"remove the argument from the globals dictionary"
|
|
103 |
|
|
104 |
%{ /* NOCONTEXT */
|
|
105 |
extern OBJ _SYSDICT_REMOVE();
|
|
106 |
|
|
107 |
if (__isSmallInteger(__INST(sysId))) {
|
|
108 |
RETURN ( _SYSDICT_REMOVE(__intVal(__INST(sysId)), aKey) );
|
|
109 |
}
|
|
110 |
%}.
|
|
111 |
"
|
|
112 |
the receiver is not a valid systemDictionary
|
|
113 |
"
|
|
114 |
self pimitiveFailed
|
|
115 |
!
|
|
116 |
|
|
117 |
includesKey:aKey
|
|
118 |
"return true, if the key is known"
|
|
119 |
|
|
120 |
%{ /* NOCONTEXT */
|
|
121 |
extern OBJ _SYSDICT_KEYKNOWN();
|
|
122 |
|
|
123 |
if (__isSmallInteger(__INST(sysId))) {
|
|
124 |
RETURN ( _SYSDICT_KEYKNOWN(__intVal(__INST(sysId)), aKey) );
|
|
125 |
}
|
|
126 |
%}.
|
|
127 |
"
|
|
128 |
the receiver is not a valid systemDictionary
|
|
129 |
"
|
|
130 |
self pimitiveFailed
|
|
131 |
!
|
|
132 |
|
|
133 |
keyAtValue:anObject
|
|
134 |
"return the symbol under which anObject is stored - or nil"
|
|
135 |
|
|
136 |
self allKeysDo:[:aKey |
|
|
137 |
(self at:aKey) == anObject ifTrue:[^ aKey]
|
|
138 |
]
|
|
139 |
|
|
140 |
"Smalltalk keyAtValue:Object"
|
|
141 |
!
|
|
142 |
|
|
143 |
keys
|
|
144 |
"return a collection with all keys in the Smalltalk dictionary"
|
|
145 |
|
|
146 |
|keys|
|
|
147 |
|
|
148 |
keys := IdentitySet new.
|
|
149 |
self allKeysDo:[:k | keys add:k].
|
|
150 |
^ keys
|
|
151 |
! !
|
|
152 |
|
|
153 |
!SystemDictionary class methodsFor:'copying'!
|
|
154 |
|
|
155 |
shallowCopy
|
|
156 |
"redefine copy - there is only one instance of each dictionary"
|
|
157 |
|
|
158 |
^ self
|
|
159 |
!
|
|
160 |
|
|
161 |
simpleDeepCopy
|
|
162 |
"redefine copy - there is only one instance of each dictionary"
|
|
163 |
|
|
164 |
^ self
|
|
165 |
!
|
|
166 |
|
|
167 |
deepCopyUsing:aDictionary
|
|
168 |
"redefine copy - there is only one instance of each dictionary"
|
|
169 |
|
|
170 |
^ self
|
|
171 |
!
|
|
172 |
|
|
173 |
deepCopy
|
|
174 |
"redefine copy - there is only one instance of each dictionary"
|
|
175 |
|
|
176 |
^ self
|
|
177 |
! !
|
|
178 |
|
|
179 |
!SystemDictionary methodsFor:'inspecting'!
|
|
180 |
|
|
181 |
inspect
|
|
182 |
"redefined to launch a DictionaryInspector on the receiver
|
|
183 |
(instead of the default InspectorView)."
|
|
184 |
|
|
185 |
DictionaryInspectorView isNil ifTrue:[
|
|
186 |
super inspect
|
|
187 |
] ifFalse:[
|
|
188 |
DictionaryInspectorView openOn:self
|
|
189 |
]
|
|
190 |
! !
|
|
191 |
|
|
192 |
!SystemDictionary methodsFor:'enumeration'!
|
|
193 |
|
|
194 |
do:aBlock
|
|
195 |
"evaluate the argument, aBlock for all values in the dictionary"
|
|
196 |
%{
|
|
197 |
if (__isSmallInteger(__INST(sysId))) {
|
|
198 |
_SYSDICT_DO(__intVal(__INST(sysId)), &aBlock COMMA_CON);
|
|
199 |
}
|
|
200 |
%}.
|
|
201 |
"
|
|
202 |
the receiver is not a valid systemDictionary
|
|
203 |
"
|
|
204 |
self pimitiveFailed
|
|
205 |
|
|
206 |
"
|
|
207 |
Smalltalk do:[:value | value class name printNL]
|
|
208 |
"
|
|
209 |
!
|
|
210 |
|
|
211 |
allKeysDo:aBlock
|
|
212 |
"evaluate the argument, aBlock for all keys in the dictionary"
|
|
213 |
%{
|
|
214 |
if (__isSmallInteger(__INST(sysId))) {
|
|
215 |
_SYSDICT_KEYSDO(__intVal(__INST(sysId)), &aBlock COMMA_CON);
|
|
216 |
}
|
|
217 |
%}.
|
|
218 |
"
|
|
219 |
the receiver is not a valid systemDictionary
|
|
220 |
"
|
|
221 |
self pimitiveFailed
|
|
222 |
|
|
223 |
"
|
|
224 |
Smalltalk allKeysDo:[:key | key printNL]
|
|
225 |
"
|
|
226 |
!
|
|
227 |
|
|
228 |
associationsDo:aBlock
|
|
229 |
"evaluate the argument, aBlock for all key/value pairs
|
|
230 |
in the dictionary"
|
|
231 |
|
|
232 |
self allKeysDo:[:aKey |
|
|
233 |
aBlock value:(aKey -> (self at:aKey))
|
|
234 |
]
|
|
235 |
|
|
236 |
"
|
|
237 |
Smalltalk associationsDo:[:assoc | assoc printNL]
|
|
238 |
"
|
|
239 |
!
|
|
240 |
|
|
241 |
keysAndValuesDo:aBlock
|
|
242 |
"evaluate the two-arg block, aBlock for all keys and values"
|
|
243 |
|
|
244 |
self allKeysDo:[:aKey |
|
|
245 |
aBlock value:aKey value:(self at:aKey)
|
|
246 |
]
|
|
247 |
! !
|
|
248 |
|
|
249 |
!SystemDictionary methodsFor:'queries'!
|
|
250 |
|
|
251 |
cellAt:aKey
|
|
252 |
"return the address of a global cell
|
|
253 |
- used internally for compiler only"
|
|
254 |
|
|
255 |
%{ /* NOCONTEXT */
|
|
256 |
extern OBJ _SYSDICT_GETCELL();
|
|
257 |
|
|
258 |
if (__isSmallInteger(__INST(sysId))) {
|
|
259 |
RETURN ( _SYSDICT_GETCELL(__intVal(__INST(sysId)), aKey) );
|
|
260 |
}
|
|
261 |
%}.
|
|
262 |
"
|
|
263 |
the receiver is not a valid systemDictionary
|
|
264 |
"
|
|
265 |
self pimitiveFailed
|
|
266 |
!
|
|
267 |
|
|
268 |
references:anObject
|
|
269 |
"return true, if I refer to the argument, anObject
|
|
270 |
must be reimplemented since systemDictionaries are no real collections."
|
|
271 |
|
|
272 |
self do:[:o |
|
|
273 |
(o == anObject) ifTrue:[^ true]
|
|
274 |
].
|
|
275 |
^ false
|
|
276 |
! !
|
|
277 |
|
|
278 |
!SystemDictionary class methodsFor: 'binary storage'!
|
|
279 |
|
|
280 |
addGlobalsTo:globalDictionary manager: manager
|
|
281 |
|pools|
|
|
282 |
|
|
283 |
pools := Set new.
|
|
284 |
self associationsDo:[:assoc |
|
|
285 |
|value|
|
|
286 |
|
|
287 |
value := assoc value.
|
|
288 |
value == self ifFalse:[
|
|
289 |
value isClass ifTrue:[
|
|
290 |
value addGlobalsTo:globalDictionary manager:manager.
|
|
291 |
pools addAll:value sharedPools
|
|
292 |
] ifFalse:[
|
|
293 |
globalDictionary at:assoc put:self
|
|
294 |
].
|
|
295 |
value isNil ifFalse:[
|
|
296 |
globalDictionary at:value put:self
|
|
297 |
]
|
|
298 |
]
|
|
299 |
].
|
|
300 |
|
|
301 |
pools do:[:poolDictionary|
|
|
302 |
poolDictionary addGlobalsTo:globalDictionary manager:manager
|
|
303 |
]
|
|
304 |
!
|
|
305 |
|
|
306 |
storeBinaryDefinitionOf:anObject on:stream manager:manager
|
|
307 |
|string|
|
|
308 |
|
|
309 |
anObject class == Association ifTrue:[
|
|
310 |
string := 'Smalltalk associationAt:', anObject key storeString
|
|
311 |
] ifFalse: [
|
|
312 |
string := 'Smalltalk at:', (self keyAtValue: anObject) storeString
|
|
313 |
].
|
|
314 |
stream nextNumber:2 put:string size.
|
|
315 |
string do:[:char | stream nextPut:char asciiValue]
|
|
316 |
! !
|