author | Claus Gittinger <cg@exept.de> |
Sun, 09 Jul 2000 19:47:18 +0200 | |
changeset 5454 | 7c81e5984e44 |
parent 5334 | f8837914d424 |
child 6421 | 58dca33cf0fc |
permissions | -rw-r--r-- |
6 | 1 |
" |
2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
186 | 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 |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
16 |
instanceVariableNames:'dependents' |
1263 | 17 |
classVariableNames:'RegistrationFailedSignal AlreadyInitialized' |
18 |
poolDictionaries:'' |
|
4351 | 19 |
category:'Collections-Weak' |
6 | 20 |
! |
21 |
||
22 |
!WeakArray class methodsFor:'documentation'! |
|
23 |
||
88 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
186 | 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. |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
66 |
The reason for not sending messages directly from the VM is to make it |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
67 |
possible to run the finalization code at lower priority or from another class. |
186 | 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 |
|
2145 | 75 |
[hint:] |
4310 | 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 |
|
4310 | 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 |
|
4310 | 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:] |
4310 | 108 |
OBJ-HEADER + (size * ptr-size) + ptr-size |
109 |
+ sizeof(dependents-collection) |
|
4062 | 110 |
|
1290 | 111 |
[author:] |
4310 | 112 |
Claus Gittinger |
1290 | 113 |
|
1263 | 114 |
[See also:] |
4310 | 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:[ |
|
302 | 126 |
RegistrationFailedSignal := ErrorSignal newSignalMayProceed:true. |
186 | 127 |
RegistrationFailedSignal nameClass:self message:#registrationFailedSignal. |
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 |
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:[ |
4310 | 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 |
|
170 |
"register the receiver in the VM - |
|
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) { |
4310 | 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 |
|
4310 | 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:[ |
|
4310 | 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. |
|
2271 | 253 |
Reimplemented here for IGC readBarrier. |
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. |
|
2271 | 269 |
Reimplemented here for IGC readBarrier. |
270 |
(You dont 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)) { |
4310 | 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]; |
|
4311 | 285 |
if (__isNonNilObject(el)) { |
286 |
el = __WEAK_READ__(self, el); |
|
287 |
} |
|
4310 | 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)) { |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
304 |
indx = __intVal(index) - 1; |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
305 |
if (indx >= 0) { |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
306 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
307 |
indx += __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
308 |
if (indx < nIndex) { |
4310 | 309 |
REGISTER OBJ el = someObject; |
310 |
||
311 |
__InstPtr(self)->i_instvars[indx] = el; |
|
2644
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
312 |
if (__isNonNilObject(el)) { |
4310 | 313 |
__STORE(self, el); |
314 |
__WEAK_WRITE__(self, el); |
|
2644
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
315 |
} |
4310 | 316 |
RETURN (el); |
2644
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
317 |
} |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
318 |
} |
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 |
|
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
336 |
skipInstvarIndexInDeepCopy:index |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
337 |
"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
|
338 |
false are copied in a deep copy." |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
339 |
|
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
340 |
index == 1 ifTrue:[ |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
341 |
^ true "/ skip dependents |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
342 |
]. |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
343 |
^ false |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
344 |
|
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
345 |
! ! |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
346 |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
347 |
!WeakArray methodsFor:'dependents access'! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
348 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
349 |
addDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
350 |
"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
|
351 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
352 |
|wasBlocked| |
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 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
355 |
[ |
5334 | 356 |
|deps| |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
357 |
|
5334 | 358 |
deps := dependents. |
359 |
"/ |
|
360 |
"/ store the very first dependent directly in |
|
361 |
"/ the dependents instVar |
|
362 |
"/ |
|
363 |
(deps isNil and:[anObject isCollection not]) ifTrue:[ |
|
364 |
dependents := anObject |
|
365 |
] ifFalse:[ |
|
366 |
"/ |
|
367 |
"/ store more dependents in the dependents collection |
|
368 |
"/ |
|
369 |
deps isCollection ifTrue:[ |
|
370 |
deps add:anObject |
|
371 |
] ifFalse:[ |
|
372 |
deps == anObject ifFalse:[ |
|
373 |
deps isNil ifTrue:[ |
|
374 |
dependents := (IdentitySet with:anObject) |
|
375 |
] ifFalse:[ |
|
376 |
dependents := (IdentitySet with:deps with:anObject) |
|
377 |
] |
|
378 |
] |
|
379 |
] |
|
380 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
381 |
] valueNowOrOnUnwindDo:[ |
5334 | 382 |
wasBlocked ifFalse:[ |
383 |
OperatingSystem unblockInterrupts |
|
384 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
385 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
386 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
387 |
"Modified: 8.1.1997 / 23:40:30 / cg" |
603 | 388 |
! |
389 |
||
390 |
dependents |
|
391 |
"return the dependents of the receiver" |
|
392 |
||
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
393 |
dependents isNil ifTrue:[^ #()]. |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
394 |
dependents isCollection ifTrue:[ |
4310 | 395 |
^ dependents |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
396 |
]. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
397 |
^ IdentitySet with:dependents |
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
398 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
399 |
"Modified: / 27.10.1997 / 19:37:16 / cg" |
603 | 400 |
! |
401 |
||
402 |
dependents:aCollection |
|
403 |
"set the dependents of the receiver" |
|
404 |
||
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
405 |
|dep| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
406 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
407 |
aCollection size == 1 ifTrue:[ |
4310 | 408 |
dep := aCollection first. |
409 |
dep isCollection ifFalse:[ |
|
410 |
dependents := aCollection first. |
|
411 |
^ self |
|
412 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
413 |
]. |
603 | 414 |
dependents := aCollection |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
415 |
! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
416 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
417 |
dependentsDo:aBlock |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
418 |
"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
|
419 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
420 |
|deps| |
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 |
deps := dependents. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
423 |
deps notNil ifTrue:[ |
4310 | 424 |
deps isCollection ifTrue:[ |
425 |
deps do:aBlock |
|
426 |
] ifFalse:[ |
|
427 |
aBlock value:deps |
|
428 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
429 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
430 |
! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
431 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
432 |
removeDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
433 |
"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
|
434 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
435 |
|wasBlocked| |
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 |
"/ 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
|
438 |
"/ 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
|
439 |
"/ 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
|
440 |
"/ faster execution. |
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 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
443 |
[ |
4310 | 444 |
|deps sz dep| |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
445 |
|
4310 | 446 |
deps := dependents. |
447 |
deps notNil ifTrue:[ |
|
448 |
deps isCollection ifTrue:[ |
|
449 |
deps remove:anObject ifAbsent:[]. |
|
450 |
(sz := deps size) == 0 ifTrue:[ |
|
451 |
dependents := nil |
|
452 |
] ifFalse:[ |
|
453 |
sz == 1 ifTrue:[ |
|
454 |
(dep := deps first) isCollection ifFalse:[ |
|
455 |
dependents := dep |
|
456 |
] |
|
457 |
] |
|
458 |
] |
|
459 |
] ifFalse:[ |
|
460 |
deps == anObject ifTrue:[ |
|
461 |
dependents := nil |
|
462 |
] |
|
463 |
] |
|
464 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
465 |
] valueNowOrOnUnwindDo:[ |
4310 | 466 |
wasBlocked ifFalse:[ |
467 |
OperatingSystem unblockInterrupts |
|
468 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
469 |
] |
6 | 470 |
! ! |
471 |
||
1825 | 472 |
!WeakArray methodsFor:'enumerating'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
473 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
474 |
do:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
475 |
"evaluate the argument, aBlock for each element in the collection. |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
476 |
- reimplemented for IGC readBarrier. |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
477 |
You dont have to understand this." |
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 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
480 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
481 |
unsigned int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
482 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
483 |
|
1136 | 484 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
485 |
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
|
486 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
487 |
if (__isBlockLike(aBlock) |
1136 | 488 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
5454 | 489 |
{ |
490 |
/* |
|
491 |
* the most common case: a static compiled block, with home on the stack ... |
|
492 |
*/ |
|
493 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
494 |
|
5454 | 495 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
496 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
2254 | 497 |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
498 |
#ifdef NEW_BLOCK_CALL |
2189 | 499 |
# 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
|
500 |
#else |
2189 | 501 |
# define BLOCK_ARG rHome |
5454 | 502 |
REGISTER OBJ rHome; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
503 |
|
5454 | 504 |
rHome = __BlockInstPtr(aBlock)->b_home; |
505 |
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
|
506 |
#endif |
5454 | 507 |
{ |
508 |
for (; index < nIndex; index++) { |
|
509 |
OBJ element; |
|
2216 | 510 |
|
5454 | 511 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
512 |
|
5454 | 513 |
element = __InstPtr(self)->i_instvars[index]; |
514 |
if (__isNonNilObject(element)) { |
|
515 |
element = __WEAK_READ__(self, element); |
|
516 |
} |
|
517 |
(*codeVal)(BLOCK_ARG, element); |
|
518 |
} |
|
519 |
RETURN (self); |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
523 |
|
5454 | 524 |
/* |
525 |
* sorry, must check code-pointer in the loop |
|
526 |
* it could be recompiled or flushed |
|
527 |
*/ |
|
2189 | 528 |
# undef BLOCK_ARG |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
529 |
#ifdef NEW_BLOCK_CALL |
2189 | 530 |
# define BLOCK_ARG aBlock |
531 |
# 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
|
532 |
#else |
2189 | 533 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
534 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
535 |
#endif |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
536 |
|
5454 | 537 |
for (; index < nIndex; index++) { |
538 |
REGISTER OBJFUNC codeVal; |
|
539 |
OBJ element; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
540 |
|
5454 | 541 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
542 |
|
5454 | 543 |
element = __InstPtr(self)->i_instvars[index]; |
544 |
if (__isNonNilObject(element)) { |
|
545 |
element = __WEAK_READ__(self, element); |
|
546 |
} |
|
547 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
548 |
(*codeVal)(BLOCK_ARG, element); |
|
549 |
} else { |
|
550 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
551 |
/* |
|
552 |
* arg is a compiled block with bytecode - |
|
553 |
* directly call interpreter without going through Block>>value |
|
554 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
555 |
#ifdef PASS_ARG_POINTER |
5454 | 556 |
__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
|
557 |
#else |
5454 | 558 |
__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
|
559 |
#endif |
5454 | 560 |
} else { |
561 |
/* |
|
562 |
* arg is something else - call it with #value |
|
563 |
*/ |
|
564 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
565 |
} |
|
566 |
} |
|
567 |
} |
|
568 |
RETURN (self); |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
569 |
|
2189 | 570 |
# undef BLOCK_ARG |
571 |
# undef IBLOCK_ARG |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
572 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
573 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
574 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
575 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
576 |
* 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
|
577 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
578 |
for (; index < nIndex; index++) { |
5454 | 579 |
OBJ element; |
2216 | 580 |
|
5454 | 581 |
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
|
582 |
|
5454 | 583 |
element = __InstPtr(self)->i_instvars[index]; |
584 |
if (__isNonNilObject(element)) { |
|
585 |
element = __WEAK_READ__(self, element); |
|
586 |
} |
|
587 |
(*val.ilc_func)(aBlock, |
|
588 |
@symbol(value:), |
|
589 |
nil, &val, |
|
590 |
element); |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
591 |
} |
5454 | 592 |
RETURN (self); |
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
593 |
%}. |
5454 | 594 |
^ super do:[:each | |
595 |
each ~~ nil ifTrue:[aBlock value:each] |
|
596 |
] |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
597 |
! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
598 |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
599 |
forAllDeadIndicesDo:aBlock |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
600 |
"evaluate the argument, aBlock for all indices where elements have been |
2271 | 601 |
replaced by zero (due to a collected object). |
602 |
Be aware, that while indices are being enumerated, other |
|
603 |
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
|
604 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
605 |
self keysAndValuesDo:[:index :element | |
4310 | 606 |
element == 0 ifTrue:[ |
607 |
aBlock value:index |
|
608 |
] |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
609 |
] |
2271 | 610 |
|
611 |
"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
|
612 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
613 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
614 |
forAllDeadIndicesDo:aBlock replacingCorpsesWith:newValue |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
615 |
"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
|
616 |
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
|
617 |
with newValue. |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
618 |
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
|
619 |
changed before the block is called); this behavior is not guaranteed |
2271 | 620 |
with future versions. |
621 |
Be aware, that while indices are being enumerated, other |
|
622 |
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
|
623 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
624 |
self keysAndValuesDo:[:index :element | |
4310 | 625 |
element == 0 ifTrue:[ |
626 |
self at:index put:newValue. |
|
627 |
aBlock value:index. |
|
628 |
] |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
629 |
] |
2271 | 630 |
|
631 |
"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
|
632 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
633 |
|
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
634 |
nilAllCorpsesAndDo:aBlock |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
635 |
"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
|
636 |
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
|
637 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
638 |
self forAllDeadIndicesDo:aBlock replacingCorpsesWith:nil |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
639 |
! |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
640 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
641 |
nonNilElementsDo:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
642 |
"evaluate the argument, aBlock for each non-nil element" |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
643 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
644 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
645 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
646 |
int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
647 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
648 |
|
1136 | 649 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
650 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
651 |
if (__isBlockLike(aBlock) |
1136 | 652 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
5454 | 653 |
{ |
654 |
/* |
|
655 |
* the most common case: a static compiled block, with home on the stack ... |
|
656 |
*/ |
|
657 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
658 |
|
5454 | 659 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
660 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
2254 | 661 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
662 |
#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
|
663 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
664 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
665 |
# define BLOCK_ARG rHome |
5454 | 666 |
REGISTER OBJ rHome; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
667 |
|
5454 | 668 |
rHome = __BlockInstPtr(aBlock)->b_home; |
669 |
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
|
670 |
#endif |
5454 | 671 |
{ |
672 |
for (; index < nIndex; index++) { |
|
673 |
REGISTER OBJ element; |
|
2216 | 674 |
|
5454 | 675 |
element = __InstPtr(self)->i_instvars[index]; |
676 |
if (element) { |
|
677 |
if (InterruptPending != nil) { |
|
678 |
__interruptL(@line); |
|
679 |
element = __InstPtr(self)->i_instvars[index]; |
|
680 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
681 |
|
5454 | 682 |
if (__isNonNilObject(element)) { |
683 |
element = __WEAK_READ__(self, element); |
|
684 |
} |
|
685 |
if (element) { |
|
686 |
(*codeVal)(BLOCK_ARG, element); |
|
687 |
} |
|
688 |
} |
|
689 |
} |
|
690 |
RETURN (self); |
|
691 |
} |
|
692 |
} |
|
693 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
694 |
|
5454 | 695 |
/* |
696 |
* sorry, must check code-pointer in the loop |
|
697 |
* it could be recompiled or flushed |
|
698 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
699 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
700 |
#ifdef NEW_BLOCK_CALL |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
701 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
702 |
# define IBLOCK_ARG nil |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
703 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
704 |
# 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
|
705 |
# 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
|
706 |
#endif |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
707 |
|
5454 | 708 |
for (; index < nIndex; index++) { |
709 |
REGISTER OBJFUNC codeVal; |
|
710 |
OBJ element; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
711 |
|
5454 | 712 |
element = __InstPtr(self)->i_instvars[index]; |
713 |
if (element) { |
|
714 |
if (InterruptPending != nil) { |
|
715 |
__interruptL(@line); |
|
716 |
element = __InstPtr(self)->i_instvars[index]; |
|
717 |
} |
|
718 |
if (__isNonNilObject(element)) { |
|
719 |
element = __WEAK_READ__(self, element); |
|
720 |
} |
|
721 |
if (element) { |
|
722 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
723 |
(*codeVal)(BLOCK_ARG, element); |
|
724 |
} else { |
|
725 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
726 |
/* |
|
727 |
* arg is a compiled block with bytecode - |
|
728 |
* directly call interpreter without going through Block>>value |
|
729 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
730 |
#ifdef PASS_ARG_POINTER |
5454 | 731 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
732 |
#else |
5454 | 733 |
__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
|
734 |
#endif |
5454 | 735 |
} else { |
736 |
/* |
|
737 |
* arg is something else - call it with #value |
|
738 |
*/ |
|
739 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
740 |
} |
|
741 |
} |
|
742 |
} |
|
743 |
} |
|
744 |
} |
|
745 |
RETURN (self); |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
746 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
747 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
748 |
# undef IBLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
749 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
750 |
|
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 |
* 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
|
753 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
754 |
for (; index < nIndex; index++) { |
5454 | 755 |
REGISTER OBJ element; |
2216 | 756 |
|
5454 | 757 |
element = __InstPtr(self)->i_instvars[index]; |
758 |
if (element) { |
|
759 |
if (InterruptPending != nil) { |
|
760 |
__interruptL(@line); |
|
761 |
element = __InstPtr(self)->i_instvars[index]; |
|
762 |
} |
|
763 |
if (__isNonNilObject(element)) { |
|
764 |
element = __WEAK_READ__(self, element); |
|
765 |
} |
|
766 |
if (element) { |
|
767 |
(*val.ilc_func)(aBlock, |
|
768 |
@symbol(value:), |
|
769 |
nil, &val, |
|
770 |
element); |
|
771 |
} |
|
772 |
} |
|
2189 | 773 |
} |
5454 | 774 |
RETURN (self); |
2189 | 775 |
%}. |
5454 | 776 |
^ super do:[:each | |
777 |
each ~~ nil ifTrue:[aBlock value:each] |
|
778 |
] |
|
2189 | 779 |
! |
780 |
||
781 |
validElementsDo:aBlock |
|
782 |
"evaluate the argument, aBlock for each non-nil/non-zero element" |
|
783 |
||
784 |
%{ |
|
785 |
REGISTER int index; |
|
786 |
int nIndex; |
|
787 |
static struct inlineCache val = _ILC1; |
|
788 |
||
789 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
790 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
791 |
if (__isBlockLike(aBlock) |
|
792 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
|
5454 | 793 |
{ |
794 |
/* |
|
795 |
* the most common case: a static compiled block, with home on the stack ... |
|
796 |
*/ |
|
797 |
REGISTER OBJFUNC codeVal; |
|
2189 | 798 |
|
5454 | 799 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
800 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
2254 | 801 |
|
2189 | 802 |
#ifdef NEW_BLOCK_CALL |
803 |
# define BLOCK_ARG aBlock |
|
804 |
#else |
|
805 |
# define BLOCK_ARG rHome |
|
5454 | 806 |
REGISTER OBJ rHome; |
2189 | 807 |
|
5454 | 808 |
rHome = __BlockInstPtr(aBlock)->b_home; |
809 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2189 | 810 |
#endif |
5454 | 811 |
{ |
812 |
for (; index < nIndex; index++) { |
|
813 |
REGISTER OBJ element; |
|
2216 | 814 |
|
5454 | 815 |
element = __InstPtr(self)->i_instvars[index]; |
816 |
if (element && (element != __MKSMALLINT(0))) { |
|
817 |
if (InterruptPending != nil) { |
|
818 |
__interruptL(@line); |
|
819 |
element = __InstPtr(self)->i_instvars[index]; |
|
820 |
} |
|
2189 | 821 |
|
5454 | 822 |
if (__isNonNilObject(element)) { |
823 |
element = __WEAK_READ__(self, element); |
|
824 |
} |
|
825 |
if (element && (element != __MKSMALLINT(0))) { |
|
826 |
(*codeVal)(BLOCK_ARG, element); |
|
827 |
} |
|
828 |
} |
|
829 |
} |
|
830 |
RETURN (self); |
|
831 |
} |
|
832 |
} |
|
833 |
} |
|
2189 | 834 |
|
5454 | 835 |
/* |
836 |
* sorry, must check code-pointer in the loop |
|
837 |
* it could be recompiled or flushed |
|
838 |
*/ |
|
2189 | 839 |
# undef BLOCK_ARG |
840 |
#ifdef NEW_BLOCK_CALL |
|
841 |
# define BLOCK_ARG aBlock |
|
842 |
# define IBLOCK_ARG nil |
|
843 |
#else |
|
844 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
845 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
846 |
#endif |
|
847 |
||
5454 | 848 |
for (; index < nIndex; index++) { |
849 |
REGISTER OBJFUNC codeVal; |
|
850 |
OBJ element; |
|
2189 | 851 |
|
5454 | 852 |
element = __InstPtr(self)->i_instvars[index]; |
853 |
if (element && (element != __MKSMALLINT(0))) { |
|
854 |
if (InterruptPending != nil) { |
|
855 |
__interruptL(@line); |
|
856 |
element = __InstPtr(self)->i_instvars[index]; |
|
857 |
} |
|
858 |
if (__isNonNilObject(element)) { |
|
859 |
element = __WEAK_READ__(self, element); |
|
860 |
} |
|
861 |
if (element && (element != __MKSMALLINT(0))) { |
|
862 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
863 |
(*codeVal)(BLOCK_ARG, element); |
|
864 |
} else { |
|
865 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
866 |
/* |
|
867 |
* arg is a compiled block with bytecode - |
|
868 |
* directly call interpreter without going through Block>>value |
|
869 |
*/ |
|
2189 | 870 |
#ifdef PASS_ARG_POINTER |
5454 | 871 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
2189 | 872 |
#else |
5454 | 873 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, element); |
2189 | 874 |
#endif |
5454 | 875 |
} else { |
876 |
/* |
|
877 |
* arg is something else - call it with #value |
|
878 |
*/ |
|
879 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
880 |
} |
|
881 |
} |
|
882 |
} |
|
883 |
} |
|
884 |
} |
|
885 |
RETURN (self); |
|
2189 | 886 |
|
887 |
# undef BLOCK_ARG |
|
888 |
# undef IBLOCK_ARG |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
889 |
} |
2189 | 890 |
|
891 |
/* |
|
892 |
* not a block - send it #value: |
|
893 |
*/ |
|
894 |
for (; index < nIndex; index++) { |
|
5454 | 895 |
REGISTER OBJ element; |
2216 | 896 |
|
5454 | 897 |
element = __InstPtr(self)->i_instvars[index]; |
898 |
if (element && (element != __MKSMALLINT(0))) { |
|
899 |
if (InterruptPending != nil) { |
|
900 |
__interruptL(@line); |
|
901 |
element = __InstPtr(self)->i_instvars[index]; |
|
902 |
} |
|
903 |
if (__isNonNilObject(element)) { |
|
904 |
element = __WEAK_READ__(self, element); |
|
905 |
} |
|
906 |
if (element && (element != __MKSMALLINT(0))) { |
|
907 |
(*val.ilc_func)(aBlock, |
|
908 |
@symbol(value:), |
|
909 |
nil, &val, |
|
910 |
element); |
|
911 |
} |
|
912 |
} |
|
2189 | 913 |
} |
5454 | 914 |
RETURN (self); |
604 | 915 |
%}. |
5454 | 916 |
^ super do:[:each | |
917 |
(each ~~ nil and:[each ~~ 0]) ifTrue:[aBlock value:each] |
|
918 |
] |
|
919 |
||
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
920 |
! ! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
921 |
|
603 | 922 |
!WeakArray methodsFor:'notification'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
923 |
|
603 | 924 |
lostPointer |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
925 |
"I lost a pointer; tell dependents. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
926 |
This is sent from the finalization code in ObjectMemory." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
927 |
|
603 | 928 |
dependents notNil ifTrue:[ |
2189 | 929 |
self changed:#ElementExpired with:nil. |
603 | 930 |
]. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
931 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
932 |
"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
|
933 |
"Modified: 7.1.1997 / 17:22:52 / stefan" |
603 | 934 |
! ! |
6 | 935 |
|
628 | 936 |
!WeakArray class methodsFor:'documentation'! |
937 |
||
938 |
version |
|
5454 | 939 |
^ '$Header: /cvs/stx/stx/libbasic/WeakArray.st,v 1.58 2000-07-09 17:47:18 cg Exp $' |
628 | 940 |
! ! |
603 | 941 |
WeakArray initialize! |