author | Claus Gittinger <cg@exept.de> |
Wed, 07 Apr 2010 16:33:49 +0200 | |
changeset 12841 | d804b0f27fe7 |
parent 9244 | 14e608c8c5e5 |
child 12952 | 82385a928dac |
permissions | -rw-r--r-- |
6 | 1 |
" |
2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
12841 | 3 |
All Rights Reserved |
6 | 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 |
||
5454 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
15 |
ArrayedCollection variableSubclass:#WeakArray |
12841 | 16 |
instanceVariableNames:'dependents' |
17 |
classVariableNames:'RegistrationFailedSignal AlreadyInitialized' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Collections-Weak' |
|
6 | 20 |
! |
21 |
||
22 |
!WeakArray class methodsFor:'documentation'! |
|
23 |
||
88 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
12841 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
6 | 38 |
documentation |
39 |
" |
|
88 | 40 |
WeakArrays can be used to trace disposal of objects; in contrast to other |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
41 |
objects, references by WeakArrays will NOT keep an object from being |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
42 |
garbage collected. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
43 |
Instead, whenever an object kept in a WeakArray dies, its entry is zeroed, |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
44 |
and the WeakArray is informed by the storage manager. The WeakArray itself |
2271 | 45 |
then informs possible dependents via the dependency mechanism. |
290 | 46 |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
47 |
WeakArrays are used to track disposal of objects which keep external |
95 | 48 |
world resources. For example, FileStreams must close their underlying |
290 | 49 |
file when disposed (otherwise you could run out of OS filedescriptors). |
95 | 50 |
This can be done by keeping the FileStream objects in a weakArray, and |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
51 |
keep a parallel array of filedescriptors. Whenever a fileStream is |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
52 |
freed, search both arrays for an index where the stream is zero, but the |
95 | 53 |
filedescriptor is non-nil. Then close that file, and nil the filedescriptor |
290 | 54 |
entry. Notice, that there is a class (Registry) which does exactly this in |
55 |
a more programmer friendly way. |
|
95 | 56 |
|
290 | 57 |
Another application is caching of data: keep it in a weakArray, so the |
95 | 58 |
data in that cache will not be unreclaimable due to being cached. |
59 |
(for example, the ResourcePack class uses a WeakArray to cache recently |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
60 |
used resource data for a while). |
88 | 61 |
|
186 | 62 |
The way in which weakArrays get informed by the runtime system is via |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
63 |
an interrupt (DisposeInterrupt) which is first sent to the disposeHandler |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
64 |
(typically ObjectMemory). ObjectMemory then takes the required steps to |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
65 |
notify all weakArrays via the #lostPointer message. |
12841 | 66 |
The reason for not sending messages directly from the VM is to make it |
67 |
possible to run the finalization code at lower priority or from another class. |
|
68 |
Also, as a side effect, it is possible to delay finalization by blocking |
|
2271 | 69 |
interrupts. (thus, the actual sending of the #lostPointer message is under |
70 |
control of Smalltalk code, which is modifyable). |
|
71 |
||
186 | 72 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
73 |
A weakArray notifies its dependents via normal dependency notfications. |
186 | 74 |
|
12841 | 75 |
[hint:] |
76 |
WeakArray handling adds small some overhead to the VM |
|
77 |
(each weakarray is scanned after each GC). |
|
78 |
It is uncertain, if the current mechanism works well |
|
79 |
with (say) ten-thousands of weakArrays. |
|
80 |
We had the system running with >2000 weakArrays, some being quite |
|
81 |
big for a while and had a few percent of added gc time. |
|
82 |
The system as delivered creates between 50 and 100 weakArrays, |
|
83 |
but with many dependents, this number may grow. |
|
84 |
If you need the dependency mechanism on a huge number of objects, |
|
85 |
consider adding a (non-weak) dependents field to your class |
|
86 |
- take the implementation of Model as a guide (or subclass them |
|
87 |
from Model). |
|
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
88 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
89 |
As a possible option, we could perform the weakArray scanning only in |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
90 |
the oldSpace reclamation code - this would remove most of the overhead, |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
91 |
but will lead to much longer delayed finalization .... we will see. |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
92 |
|
290 | 93 |
|
1290 | 94 |
[instance variables:] |
290 | 95 |
|
12841 | 96 |
dependents get informed via #change notifiction |
97 |
that the weakArray has lost pointers. |
|
98 |
Having the dependents here is an optimization. |
|
290 | 99 |
|
1290 | 100 |
[class variables:] |
290 | 101 |
|
12841 | 102 |
RegistrationFailedSignal raised if a weakArray cannot be |
103 |
registered by the VM. This only happens, |
|
104 |
if the VM has to resize its internal tables |
|
105 |
and is running out of malloc-memory. |
|
1263 | 106 |
|
4062 | 107 |
[memory requirements:] |
12841 | 108 |
OBJ-HEADER + (size * ptr-size) + ptr-size |
109 |
+ sizeof(dependents-collection) |
|
4062 | 110 |
|
1290 | 111 |
[author:] |
12841 | 112 |
Claus Gittinger |
1290 | 113 |
|
1263 | 114 |
[See also:] |
12841 | 115 |
Array WeakIdentitySet WeakIdentityDictionary Registry |
116 |
Model |
|
6 | 117 |
" |
118 |
! ! |
|
119 |
||
159 | 120 |
!WeakArray class methodsFor:'initialization'! |
121 |
||
122 |
initialize |
|
123 |
"setup the private signal" |
|
124 |
||
125 |
RegistrationFailedSignal isNil ifTrue:[ |
|
7097
23529d6e866e
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
126 |
RegistrationFailedSignal := Error newSignalMayProceed:true. |
23529d6e866e
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
127 |
RegistrationFailedSignal nameClass:self message:#registrationFailedSignal. |
23529d6e866e
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
128 |
RegistrationFailedSignal notifierString:'weakArray registration failed'. |
159 | 129 |
] |
130 |
! ! |
|
131 |
||
6 | 132 |
!WeakArray class methodsFor:'instance creation'! |
133 |
||
3090 | 134 |
basicNew:size |
95 | 135 |
"return a new weakArray with size slots" |
6 | 136 |
|
2271 | 137 |
"This is a kludge: I would like to set the WEAK-flag in the classes |
216 | 138 |
initialize method, but (currently) the order in which the class-initialize |
290 | 139 |
methods are called is not defined ... |
216 | 140 |
... therefore it could happen, that a WeakArray is used by other |
12841 | 141 |
classes initialize method BEFORE this method is evaluated. |
142 |
To avoid this, the WEAK bit in the class is set here, when the very first |
|
2271 | 143 |
WeakArray is created. |
144 |
[Actually, the cleanest solution was to add another class definition |
|
145 |
keyword (such as #variableWeakSubclass:) which sets the weak flag right |
|
146 |
from the start.]" |
|
95 | 147 |
|
216 | 148 |
AlreadyInitialized isNil ifTrue:[ |
12841 | 149 |
self flags:(Behavior flagWeakPointers). |
150 |
AlreadyInitialized := true |
|
216 | 151 |
]. |
95 | 152 |
|
3090 | 153 |
^ (super basicNew:size) registerAsWeakArray |
2271 | 154 |
|
155 |
"Modified: 25.1.1997 / 13:17:22 / cg" |
|
159 | 156 |
! ! |
157 |
||
2318 | 158 |
!WeakArray class methodsFor:'queries'! |
159 |
||
160 |
isBuiltInClass |
|
161 |
"return true if this class is known by the run-time-system. |
|
162 |
Here, true is returned for myself, false for subclasses." |
|
163 |
||
164 |
^ self == WeakArray |
|
165 |
! ! |
|
166 |
||
159 | 167 |
!WeakArray methodsFor:'GC registration'! |
168 |
||
169 |
registerAsWeakArray |
|
12841 | 170 |
"register the receiver in the VM - |
159 | 171 |
i.e. tell the VM to nil disposed entries in the receiver |
172 |
and notify the disposeInterruptHandler whenever that happened." |
|
173 |
||
174 |
|ok| |
|
2318 | 175 |
|
6 | 176 |
%{ |
177 |
OBJ __addShadowObject(); |
|
178 |
||
159 | 179 |
ok = __addShadowObject(self, 0); |
6 | 180 |
if (ok == false) { |
12841 | 181 |
/* |
182 |
* the behavior of __addShadowObject() in case of overflowing |
|
183 |
* VM-table space can be controlled by the second argument: |
|
184 |
* if its 0, the weakObject is not registered, and false |
|
185 |
* is returned. |
|
186 |
* if its 1, the tables are reallocated, registration proceeds, |
|
187 |
* and true is returned. |
|
188 |
* This allows for the caller to have an influence on the VM's |
|
189 |
* shadow table allocation. |
|
190 |
* |
|
191 |
* If addShadowObject() returned false, too many shadow objects are |
|
192 |
* already there. Then collect garbage to get rid of |
|
193 |
* obsolete ones, and try again. |
|
194 |
* Since a full collect is expensive, we try |
|
195 |
* a scavenge first, doing a full collect only if |
|
196 |
* that does not help. |
|
197 |
* |
|
198 |
* THIS MAY OR MAY NOT BE A GOOD IDEA: although it reduces |
|
199 |
* the number of shadow objects that have to be |
|
200 |
* processed at GC time, it may create a long delay here, |
|
201 |
* at shadow object creation time. |
|
202 |
* Dont know which is better ... |
|
203 |
*/ |
|
204 |
__nonTenuringScavenge(__context); |
|
205 |
ok = __addShadowObject(self, 0); |
|
2271 | 206 |
|
12841 | 207 |
if (ok == false) { |
208 |
/* |
|
209 |
* hard stuff - need full collect |
|
210 |
* if this is the very first GC, assume that we are in |
|
211 |
* the startup phase (where all weak stuff is allocated). |
|
212 |
* Then do no GC. |
|
213 |
* Heuristics showed, that this GC does not find much ... |
|
214 |
*/ |
|
215 |
if ((__garbageCollectCount() != 0) |
|
216 |
|| (__incrementalGCCount() != 0)) { |
|
217 |
__markAndSweepIfUseful(__context); |
|
218 |
ok = __addShadowObject(self, 0); |
|
219 |
} |
|
220 |
if (ok == false) { |
|
221 |
/* |
|
222 |
* mhmh - it seems that there are really many shadow |
|
223 |
* objects around - force creation |
|
224 |
*/ |
|
225 |
ok = __addShadowObject(self, 1); |
|
226 |
if (ok == false) { |
|
227 |
/* |
|
228 |
* no chance - something must be wrong |
|
229 |
* lets fall into the exception and see. |
|
230 |
*/ |
|
231 |
} |
|
232 |
} |
|
233 |
} |
|
6 | 234 |
} |
159 | 235 |
%}. |
236 |
ok ifFalse:[ |
|
12841 | 237 |
" |
238 |
the VM was not able to register the new weakArray |
|
239 |
This can only happen, if the VM has to resize its tables, |
|
240 |
and a malloc request failed. Usually, this smells like big |
|
241 |
trouble being on the way (soon running out of memory in |
|
242 |
other places as well). |
|
243 |
Configure your OS for more swap space. |
|
244 |
" |
|
245 |
^ RegistrationFailedSignal raiseRequestWith:self |
|
159 | 246 |
] |
6 | 247 |
! ! |
248 |
||
603 | 249 |
!WeakArray methodsFor:'accessing'! |
250 |
||
251 |
at:index |
|
252 |
"return the indexed instance variable with index, anInteger. |
|
12841 | 253 |
Reimplemented here for IGC readBarrier. |
2271 | 254 |
(You dont have to understand this.)" |
603 | 255 |
|
256 |
^ self basicAt:index |
|
2271 | 257 |
|
258 |
"Modified: 25.1.1997 / 13:41:25 / cg" |
|
603 | 259 |
! |
6 | 260 |
|
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
261 |
at:index put:someObject |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
262 |
"store someObject in the weakArray at some index." |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
263 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
264 |
^ self basicAt:index put:someObject |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
265 |
! |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
266 |
|
603 | 267 |
basicAt:index |
268 |
"return the indexed instance variable with index, anInteger. |
|
12841 | 269 |
Reimplemented here for IGC readBarrier. |
270 |
(You don't have to understand this.)" |
|
603 | 271 |
|
272 |
%{ /* NOCONTEXT */ |
|
273 |
||
274 |
REGISTER int indx; |
|
275 |
REGISTER unsigned int nIndex; |
|
276 |
OBJ el; |
|
6 | 277 |
|
603 | 278 |
if (__isSmallInteger(index)) { |
12841 | 279 |
indx = __intVal(index) - 1; |
280 |
if (indx >= 0) { |
|
281 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
282 |
indx += __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
283 |
if (indx < nIndex) { |
|
284 |
el = __InstPtr(self)->i_instvars[indx]; |
|
285 |
if (__isNonNilObject(el)) { |
|
286 |
el = __WEAK_READ__(self, el); |
|
287 |
} |
|
288 |
RETURN (el); |
|
289 |
} |
|
290 |
} |
|
603 | 291 |
} |
292 |
%}. |
|
293 |
^ super basicAt:index |
|
2644
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
294 |
! |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
295 |
|
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
296 |
basicAt:index put:someObject |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
297 |
"store someObject in the weakArray at some index." |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
298 |
|
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
299 |
%{ /* NOCONTEXT */ |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
300 |
REGISTER int indx; |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
301 |
REGISTER unsigned int nIndex; |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
302 |
|
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
303 |
if (__isSmallInteger(index)) { |
12841 | 304 |
indx = __intVal(index) - 1; |
305 |
if (indx >= 0) { |
|
306 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
307 |
indx += __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
308 |
if (indx < nIndex) { |
|
309 |
REGISTER OBJ el = someObject; |
|
4310 | 310 |
|
12841 | 311 |
__InstPtr(self)->i_instvars[indx] = el; |
312 |
if (__isNonNilObject(el)) { |
|
313 |
__STORE(self, el); |
|
314 |
__WEAK_WRITE__(self, el); |
|
315 |
} |
|
316 |
RETURN (el); |
|
317 |
} |
|
318 |
} |
|
2644
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
319 |
} |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
320 |
%}. |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
321 |
"/ for the error-message ... |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
322 |
^ super basicAt:index put:someObject |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
323 |
! ! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
324 |
|
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
325 |
!WeakArray methodsFor:'copying'! |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
326 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
327 |
postCopy |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
328 |
"copying alone does not really help - we have to tell |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
329 |
the VM, that there is a new WeakArray around ... |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
330 |
Q: who copies weakArrays ?" |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
331 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
332 |
dependents := nil. |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
333 |
self registerAsWeakArray. |
4730
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
334 |
! |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
335 |
|
8931 | 336 |
postDeepCopy |
337 |
dependents := nil. |
|
338 |
self registerAsWeakArray. |
|
339 |
! |
|
340 |
||
4730
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
341 |
skipInstvarIndexInDeepCopy:index |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
342 |
"a helper for deepCopy; only indices for which this method returns |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
343 |
false are copied in a deep copy." |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
344 |
|
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
345 |
index == 1 ifTrue:[ |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
346 |
^ true "/ skip dependents |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
347 |
]. |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
348 |
^ false |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
349 |
|
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
350 |
! ! |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
351 |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
352 |
!WeakArray methodsFor:'dependents access'! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
353 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
354 |
addDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
355 |
"make the argument, anObject be a dependent of the receiver" |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
356 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
357 |
|wasBlocked| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
358 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
359 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
360 |
[ |
5334 | 361 |
|deps| |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
362 |
|
5334 | 363 |
deps := dependents. |
364 |
"/ |
|
365 |
"/ store the very first dependent directly in |
|
366 |
"/ the dependents instVar |
|
367 |
"/ |
|
368 |
(deps isNil and:[anObject isCollection not]) ifTrue:[ |
|
369 |
dependents := anObject |
|
370 |
] ifFalse:[ |
|
371 |
"/ |
|
372 |
"/ store more dependents in the dependents collection |
|
373 |
"/ |
|
374 |
deps isCollection ifTrue:[ |
|
375 |
deps add:anObject |
|
376 |
] ifFalse:[ |
|
377 |
deps == anObject ifFalse:[ |
|
378 |
deps isNil ifTrue:[ |
|
379 |
dependents := (IdentitySet with:anObject) |
|
380 |
] ifFalse:[ |
|
381 |
dependents := (IdentitySet with:deps with:anObject) |
|
382 |
] |
|
383 |
] |
|
384 |
] |
|
385 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
386 |
] ensure:[ |
5334 | 387 |
wasBlocked ifFalse:[ |
388 |
OperatingSystem unblockInterrupts |
|
389 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
390 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
391 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
392 |
"Modified: 8.1.1997 / 23:40:30 / cg" |
603 | 393 |
! |
394 |
||
12841 | 395 |
dependents |
603 | 396 |
"return the dependents of the receiver" |
397 |
||
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
398 |
dependents isNil ifTrue:[^ #()]. |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
399 |
dependents isCollection ifTrue:[ |
12841 | 400 |
^ dependents |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
401 |
]. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
402 |
^ IdentitySet with:dependents |
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
403 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
404 |
"Modified: / 27.10.1997 / 19:37:16 / cg" |
603 | 405 |
! |
406 |
||
407 |
dependents:aCollection |
|
408 |
"set the dependents of the receiver" |
|
409 |
||
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
410 |
|dep| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
411 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
412 |
aCollection size == 1 ifTrue:[ |
12841 | 413 |
dep := aCollection first. |
414 |
dep isCollection ifFalse:[ |
|
415 |
dependents := aCollection first. |
|
416 |
^ self |
|
417 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
418 |
]. |
603 | 419 |
dependents := aCollection |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
420 |
! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
421 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
422 |
dependentsDo:aBlock |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
423 |
"evaluate aBlock for all of my dependents" |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
424 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
425 |
|deps| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
426 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
427 |
deps := dependents. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
428 |
deps notNil ifTrue:[ |
12841 | 429 |
deps isCollection ifTrue:[ |
430 |
deps do:aBlock |
|
431 |
] ifFalse:[ |
|
432 |
aBlock value:deps |
|
433 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
434 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
435 |
! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
436 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
437 |
removeDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
438 |
"make the argument, anObject be independent of the receiver" |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
439 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
440 |
|wasBlocked| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
441 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
442 |
"/ must do this save from interrupts, since the dependents collection |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
443 |
"/ is possibly accessed from multiple threads. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
444 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
445 |
"/ faster execution. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
446 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
447 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
448 |
[ |
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
449 |
|deps sz dep| |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
450 |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
451 |
deps := dependents. |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
452 |
deps notNil ifTrue:[ |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
453 |
deps isCollection ifTrue:[ |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
454 |
deps remove:anObject ifAbsent:[]. |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
455 |
(sz := deps size) == 0 ifTrue:[ |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
456 |
dependents := nil |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
457 |
] ifFalse:[ |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
458 |
sz == 1 ifTrue:[ |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
459 |
(dep := deps first) isCollection ifFalse:[ |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
460 |
dependents := dep |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
461 |
] |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
462 |
] |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
463 |
] |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
464 |
] ifFalse:[ |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
465 |
deps == anObject ifTrue:[ |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
466 |
dependents := nil |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
467 |
] |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
468 |
] |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
469 |
] |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
470 |
] ensure:[ |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
471 |
wasBlocked ifFalse:[ |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
472 |
OperatingSystem unblockInterrupts |
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
473 |
] |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
474 |
] |
6 | 475 |
! ! |
476 |
||
1825 | 477 |
!WeakArray methodsFor:'enumerating'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
478 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
479 |
do:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
480 |
"evaluate the argument, aBlock for each element in the collection. |
12841 | 481 |
- reimplemented for IGC readBarrier. |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
482 |
You dont have to understand this." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
483 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
484 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
485 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
486 |
unsigned int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
487 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
488 |
|
1136 | 489 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
490 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
491 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
492 |
if (__isBlockLike(aBlock) |
8913 | 493 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) { |
5454 | 494 |
{ |
495 |
/* |
|
496 |
* the most common case: a static compiled block, with home on the stack ... |
|
497 |
*/ |
|
498 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
499 |
|
5454 | 500 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
501 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
2254 | 502 |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
503 |
#ifdef NEW_BLOCK_CALL |
2189 | 504 |
# define BLOCK_ARG aBlock |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
505 |
#else |
2189 | 506 |
# define BLOCK_ARG rHome |
5454 | 507 |
REGISTER OBJ rHome; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
508 |
|
5454 | 509 |
rHome = __BlockInstPtr(aBlock)->b_home; |
12841 | 510 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
511 |
#endif |
5454 | 512 |
{ |
513 |
for (; index < nIndex; index++) { |
|
514 |
OBJ element; |
|
2216 | 515 |
|
5454 | 516 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
517 |
|
5454 | 518 |
element = __InstPtr(self)->i_instvars[index]; |
519 |
if (__isNonNilObject(element)) { |
|
520 |
element = __WEAK_READ__(self, element); |
|
521 |
} |
|
522 |
(*codeVal)(BLOCK_ARG, element); |
|
523 |
} |
|
524 |
RETURN (self); |
|
525 |
} |
|
526 |
} |
|
527 |
} |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
528 |
|
5454 | 529 |
/* |
530 |
* sorry, must check code-pointer in the loop |
|
531 |
* it could be recompiled or flushed |
|
532 |
*/ |
|
2189 | 533 |
# undef BLOCK_ARG |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
534 |
#ifdef NEW_BLOCK_CALL |
2189 | 535 |
# define BLOCK_ARG aBlock |
536 |
# define IBLOCK_ARG nil |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
537 |
#else |
2189 | 538 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
539 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
540 |
#endif |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
541 |
|
5454 | 542 |
for (; index < nIndex; index++) { |
543 |
REGISTER OBJFUNC codeVal; |
|
544 |
OBJ element; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
545 |
|
5454 | 546 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
547 |
|
5454 | 548 |
element = __InstPtr(self)->i_instvars[index]; |
549 |
if (__isNonNilObject(element)) { |
|
550 |
element = __WEAK_READ__(self, element); |
|
551 |
} |
|
552 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
553 |
(*codeVal)(BLOCK_ARG, element); |
|
554 |
} else { |
|
555 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
556 |
/* |
|
557 |
* arg is a compiled block with bytecode - |
|
558 |
* directly call interpreter without going through Block>>value |
|
559 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
560 |
#ifdef PASS_ARG_POINTER |
5454 | 561 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
562 |
#else |
5454 | 563 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
564 |
#endif |
5454 | 565 |
} else { |
566 |
/* |
|
567 |
* arg is something else - call it with #value |
|
568 |
*/ |
|
569 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
570 |
} |
|
571 |
} |
|
12841 | 572 |
} |
5454 | 573 |
RETURN (self); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
574 |
|
2189 | 575 |
# undef BLOCK_ARG |
576 |
# undef IBLOCK_ARG |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
577 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
578 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
579 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
580 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
581 |
* not a block - send it #value: |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
582 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
583 |
for (; index < nIndex; index++) { |
5454 | 584 |
OBJ element; |
2216 | 585 |
|
5454 | 586 |
if (InterruptPending != nil) __interruptL(@line); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
587 |
|
5454 | 588 |
element = __InstPtr(self)->i_instvars[index]; |
589 |
if (__isNonNilObject(element)) { |
|
590 |
element = __WEAK_READ__(self, element); |
|
591 |
} |
|
12841 | 592 |
(*val.ilc_func)(aBlock, |
593 |
@symbol(value:), |
|
594 |
nil, &val, |
|
5454 | 595 |
element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
596 |
} |
5454 | 597 |
RETURN (self); |
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
598 |
%}. |
5454 | 599 |
^ super do:[:each | |
600 |
each ~~ nil ifTrue:[aBlock value:each] |
|
601 |
] |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
602 |
! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
603 |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
604 |
forAllDeadIndicesDo:aBlock |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
605 |
"evaluate the argument, aBlock for all indices where elements have been |
2271 | 606 |
replaced by zero (due to a collected object). |
607 |
Be aware, that while indices are being enumerated, other |
|
608 |
slots may change iff the garbage collector finds new garbage." |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
609 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
610 |
self keysAndValuesDo:[:index :element | |
12841 | 611 |
element == 0 ifTrue:[ |
612 |
aBlock value:index |
|
613 |
] |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
614 |
] |
2271 | 615 |
|
616 |
"Modified: 25.1.1997 / 14:50:59 / cg" |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
617 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
618 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
619 |
forAllDeadIndicesDo:aBlock replacingCorpsesWith:newValue |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
620 |
"evaluate the argument, aBlock for all indices where elements have been |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
621 |
replaced by zero (due to a collected object), and replace the element |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
622 |
with newValue. |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
623 |
In the current implementation, the block sees the newValue (i.e. it is |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
624 |
changed before the block is called); this behavior is not guaranteed |
2271 | 625 |
with future versions. |
626 |
Be aware, that while indices are being enumerated, other |
|
627 |
slots may change iff the garbage collector finds new garbage." |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
628 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
629 |
self keysAndValuesDo:[:index :element | |
12841 | 630 |
element == 0 ifTrue:[ |
631 |
self at:index put:newValue. |
|
632 |
aBlock value:index. |
|
633 |
] |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
634 |
] |
2271 | 635 |
|
636 |
"Modified: 25.1.1997 / 14:51:28 / cg" |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
637 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
638 |
|
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
639 |
nilAllCorpsesAndDo:aBlock |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
640 |
"evaluate the argument, aBlock for all indices where elements have been |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
641 |
cleared (due to a collected object), nil the entry." |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
642 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
643 |
self forAllDeadIndicesDo:aBlock replacingCorpsesWith:nil |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
644 |
! |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
645 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
646 |
nonNilElementsDo:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
647 |
"evaluate the argument, aBlock for each non-nil element" |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
648 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
649 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
650 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
651 |
int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
652 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
653 |
|
1136 | 654 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
655 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
656 |
if (__isBlockLike(aBlock) |
8913 | 657 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) { |
5454 | 658 |
{ |
659 |
/* |
|
660 |
* the most common case: a static compiled block, with home on the stack ... |
|
661 |
*/ |
|
662 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
663 |
|
5454 | 664 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
665 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
2254 | 666 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
667 |
#ifdef NEW_BLOCK_CALL |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
668 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
669 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
670 |
# define BLOCK_ARG rHome |
5454 | 671 |
REGISTER OBJ rHome; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
672 |
|
5454 | 673 |
rHome = __BlockInstPtr(aBlock)->b_home; |
12841 | 674 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
675 |
#endif |
5454 | 676 |
{ |
677 |
for (; index < nIndex; index++) { |
|
678 |
REGISTER OBJ element; |
|
2216 | 679 |
|
5454 | 680 |
element = __InstPtr(self)->i_instvars[index]; |
681 |
if (element) { |
|
682 |
if (InterruptPending != nil) { |
|
683 |
__interruptL(@line); |
|
684 |
element = __InstPtr(self)->i_instvars[index]; |
|
685 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
686 |
|
5454 | 687 |
if (__isNonNilObject(element)) { |
688 |
element = __WEAK_READ__(self, element); |
|
689 |
} |
|
690 |
if (element) { |
|
691 |
(*codeVal)(BLOCK_ARG, element); |
|
692 |
} |
|
693 |
} |
|
694 |
} |
|
695 |
RETURN (self); |
|
696 |
} |
|
697 |
} |
|
698 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
699 |
|
5454 | 700 |
/* |
701 |
* sorry, must check code-pointer in the loop |
|
702 |
* it could be recompiled or flushed |
|
703 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
704 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
705 |
#ifdef NEW_BLOCK_CALL |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
706 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
707 |
# define IBLOCK_ARG nil |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
708 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
709 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
710 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
711 |
#endif |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
712 |
|
5454 | 713 |
for (; index < nIndex; index++) { |
714 |
REGISTER OBJFUNC codeVal; |
|
715 |
OBJ element; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
716 |
|
5454 | 717 |
element = __InstPtr(self)->i_instvars[index]; |
718 |
if (element) { |
|
719 |
if (InterruptPending != nil) { |
|
720 |
__interruptL(@line); |
|
721 |
element = __InstPtr(self)->i_instvars[index]; |
|
722 |
} |
|
723 |
if (__isNonNilObject(element)) { |
|
724 |
element = __WEAK_READ__(self, element); |
|
725 |
} |
|
726 |
if (element) { |
|
727 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
728 |
(*codeVal)(BLOCK_ARG, element); |
|
729 |
} else { |
|
730 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
731 |
/* |
|
732 |
* arg is a compiled block with bytecode - |
|
733 |
* directly call interpreter without going through Block>>value |
|
734 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
735 |
#ifdef PASS_ARG_POINTER |
5454 | 736 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
737 |
#else |
5454 | 738 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
739 |
#endif |
5454 | 740 |
} else { |
741 |
/* |
|
742 |
* arg is something else - call it with #value |
|
743 |
*/ |
|
744 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
745 |
} |
|
746 |
} |
|
747 |
} |
|
12841 | 748 |
} |
5454 | 749 |
} |
750 |
RETURN (self); |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
751 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
752 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
753 |
# undef IBLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
754 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
755 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
756 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
757 |
* not a block - send it #value: |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
758 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
759 |
for (; index < nIndex; index++) { |
5454 | 760 |
REGISTER OBJ element; |
2216 | 761 |
|
5454 | 762 |
element = __InstPtr(self)->i_instvars[index]; |
763 |
if (element) { |
|
764 |
if (InterruptPending != nil) { |
|
765 |
__interruptL(@line); |
|
766 |
element = __InstPtr(self)->i_instvars[index]; |
|
767 |
} |
|
768 |
if (__isNonNilObject(element)) { |
|
769 |
element = __WEAK_READ__(self, element); |
|
770 |
} |
|
771 |
if (element) { |
|
12841 | 772 |
(*val.ilc_func)(aBlock, |
773 |
@symbol(value:), |
|
774 |
nil, &val, |
|
5454 | 775 |
element); |
776 |
} |
|
777 |
} |
|
2189 | 778 |
} |
5454 | 779 |
RETURN (self); |
2189 | 780 |
%}. |
5454 | 781 |
^ super do:[:each | |
782 |
each ~~ nil ifTrue:[aBlock value:each] |
|
783 |
] |
|
2189 | 784 |
! |
785 |
||
786 |
validElementsDo:aBlock |
|
787 |
"evaluate the argument, aBlock for each non-nil/non-zero element" |
|
788 |
||
789 |
%{ |
|
790 |
REGISTER int index; |
|
791 |
int nIndex; |
|
792 |
static struct inlineCache val = _ILC1; |
|
793 |
||
794 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
795 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
796 |
if (__isBlockLike(aBlock) |
|
8913 | 797 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) { |
5454 | 798 |
{ |
799 |
/* |
|
800 |
* the most common case: a static compiled block, with home on the stack ... |
|
801 |
*/ |
|
802 |
REGISTER OBJFUNC codeVal; |
|
2189 | 803 |
|
5454 | 804 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
805 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
2254 | 806 |
|
2189 | 807 |
#ifdef NEW_BLOCK_CALL |
808 |
# define BLOCK_ARG aBlock |
|
809 |
#else |
|
810 |
# define BLOCK_ARG rHome |
|
5454 | 811 |
REGISTER OBJ rHome; |
2189 | 812 |
|
5454 | 813 |
rHome = __BlockInstPtr(aBlock)->b_home; |
12841 | 814 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
2189 | 815 |
#endif |
5454 | 816 |
{ |
817 |
for (; index < nIndex; index++) { |
|
818 |
REGISTER OBJ element; |
|
2216 | 819 |
|
5454 | 820 |
element = __InstPtr(self)->i_instvars[index]; |
8913 | 821 |
if (element && (element != __mkSmallInteger(0))) { |
5454 | 822 |
if (InterruptPending != nil) { |
823 |
__interruptL(@line); |
|
824 |
element = __InstPtr(self)->i_instvars[index]; |
|
825 |
} |
|
2189 | 826 |
|
5454 | 827 |
if (__isNonNilObject(element)) { |
828 |
element = __WEAK_READ__(self, element); |
|
829 |
} |
|
8913 | 830 |
if (element && (element != __mkSmallInteger(0))) { |
5454 | 831 |
(*codeVal)(BLOCK_ARG, element); |
832 |
} |
|
833 |
} |
|
834 |
} |
|
835 |
RETURN (self); |
|
836 |
} |
|
837 |
} |
|
838 |
} |
|
2189 | 839 |
|
5454 | 840 |
/* |
841 |
* sorry, must check code-pointer in the loop |
|
842 |
* it could be recompiled or flushed |
|
843 |
*/ |
|
2189 | 844 |
# undef BLOCK_ARG |
845 |
#ifdef NEW_BLOCK_CALL |
|
846 |
# define BLOCK_ARG aBlock |
|
847 |
# define IBLOCK_ARG nil |
|
848 |
#else |
|
849 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
850 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
851 |
#endif |
|
852 |
||
5454 | 853 |
for (; index < nIndex; index++) { |
854 |
REGISTER OBJFUNC codeVal; |
|
855 |
OBJ element; |
|
2189 | 856 |
|
5454 | 857 |
element = __InstPtr(self)->i_instvars[index]; |
8913 | 858 |
if (element && (element != __mkSmallInteger(0))) { |
5454 | 859 |
if (InterruptPending != nil) { |
860 |
__interruptL(@line); |
|
861 |
element = __InstPtr(self)->i_instvars[index]; |
|
862 |
} |
|
863 |
if (__isNonNilObject(element)) { |
|
864 |
element = __WEAK_READ__(self, element); |
|
865 |
} |
|
8913 | 866 |
if (element && (element != __mkSmallInteger(0))) { |
5454 | 867 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
868 |
(*codeVal)(BLOCK_ARG, element); |
|
869 |
} else { |
|
870 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
871 |
/* |
|
872 |
* arg is a compiled block with bytecode - |
|
873 |
* directly call interpreter without going through Block>>value |
|
874 |
*/ |
|
2189 | 875 |
#ifdef PASS_ARG_POINTER |
5454 | 876 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
2189 | 877 |
#else |
5454 | 878 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, element); |
2189 | 879 |
#endif |
5454 | 880 |
} else { |
881 |
/* |
|
882 |
* arg is something else - call it with #value |
|
883 |
*/ |
|
884 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
885 |
} |
|
886 |
} |
|
887 |
} |
|
12841 | 888 |
} |
5454 | 889 |
} |
890 |
RETURN (self); |
|
2189 | 891 |
|
892 |
# undef BLOCK_ARG |
|
893 |
# undef IBLOCK_ARG |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
894 |
} |
2189 | 895 |
|
896 |
/* |
|
897 |
* not a block - send it #value: |
|
898 |
*/ |
|
899 |
for (; index < nIndex; index++) { |
|
5454 | 900 |
REGISTER OBJ element; |
2216 | 901 |
|
5454 | 902 |
element = __InstPtr(self)->i_instvars[index]; |
8913 | 903 |
if (element && (element != __mkSmallInteger(0))) { |
5454 | 904 |
if (InterruptPending != nil) { |
905 |
__interruptL(@line); |
|
906 |
element = __InstPtr(self)->i_instvars[index]; |
|
907 |
} |
|
908 |
if (__isNonNilObject(element)) { |
|
909 |
element = __WEAK_READ__(self, element); |
|
910 |
} |
|
8913 | 911 |
if (element && (element != __mkSmallInteger(0))) { |
12841 | 912 |
(*val.ilc_func)(aBlock, |
913 |
@symbol(value:), |
|
914 |
nil, &val, |
|
5454 | 915 |
element); |
916 |
} |
|
917 |
} |
|
2189 | 918 |
} |
5454 | 919 |
RETURN (self); |
604 | 920 |
%}. |
5454 | 921 |
^ super do:[:each | |
922 |
(each ~~ nil and:[each ~~ 0]) ifTrue:[aBlock value:each] |
|
923 |
] |
|
924 |
||
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
925 |
! ! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
926 |
|
603 | 927 |
!WeakArray methodsFor:'notification'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
928 |
|
603 | 929 |
lostPointer |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
930 |
"I lost a pointer; tell dependents. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
931 |
This is sent from the finalization code in ObjectMemory." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
932 |
|
603 | 933 |
dependents notNil ifTrue:[ |
12841 | 934 |
self changed:#ElementExpired with:nil. |
603 | 935 |
]. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
936 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
937 |
"Modified: 18.10.1996 / 21:28:10 / cg" |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
938 |
"Modified: 7.1.1997 / 17:22:52 / stefan" |
603 | 939 |
! ! |
6 | 940 |
|
9244 | 941 |
!WeakArray methodsFor:'testing'! |
942 |
||
943 |
isWeakCollection |
|
944 |
"return true, if the receiver has weak references to its elements." |
|
945 |
||
946 |
^ true |
|
947 |
! ! |
|
948 |
||
628 | 949 |
!WeakArray class methodsFor:'documentation'! |
950 |
||
951 |
version |
|
12841 | 952 |
^ '$Header: /cvs/stx/stx/libbasic/WeakArray.st,v 1.64 2010-04-07 14:33:48 cg Exp $' |
628 | 953 |
! ! |
7097
23529d6e866e
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
954 |
|
603 | 955 |
WeakArray initialize! |