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