author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 1995 15:23:19 +0100 | |
changeset 624 | f09ad5cf21d4 |
parent 620 | c7353f86a302 |
child 642 | dbf407bedf64 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
154 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
Object subclass:#Behavior |
|
620 | 14 |
instanceVariableNames:'superclass flags selectorArray methodArray otherSuperclasses |
15 |
instSize' |
|
16 |
classVariableNames:'SubclassInfo' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Kernel-Classes' |
|
1 | 19 |
! |
20 |
||
47 | 21 |
!Behavior class methodsFor:'documentation'! |
22 |
||
88 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
154 | 26 |
All Rights Reserved |
88 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
47 | 37 |
documentation |
38 |
" |
|
68 | 39 |
Every class in the system inherits from Behavior (via Class, ClassDescription); |
40 |
so here is where most of the class messages end up being implemented. |
|
41 |
(to answer a FAQ: 'Point basicNew' will be done here :-) |
|
42 |
||
356 | 43 |
Beginners should keep in mind, that all classes are instances (of subclasses) |
91 | 44 |
of Behavior, therefore you will find the above mentioned 'basicNew:' method |
45 |
under the 'instance'-methods of Behavior - NOT under the class methods |
|
154 | 46 |
('Behavior new' will create and return a new class, while sending 'new' to |
47 |
any instance of Behavior (i.e. any class) will return an instance of that class). |
|
68 | 48 |
|
49 |
Behavior provides minimum support for all classes - additional stuff is |
|
77 | 50 |
found in ClassDescription and Class. Behaviors provides all mechanisms needed |
51 |
to create instances, and send messages to those. However, Behavior does not provide |
|
52 |
all the (symbolic) information needed to compile methods for a class or to get |
|
53 |
useful information in inspectors. |
|
47 | 54 |
|
68 | 55 |
In contrast to other ST implementations, the methods have been separated |
56 |
from the selectors (there is no Dictionary, but two separate Arrays) |
|
57 |
- this avoids the need for knowledge about Dictionaries in the runtime library (VM) |
|
58 |
(lookup and search in these is seldom anyway, so the added benefit from using a |
|
356 | 59 |
hashed dictionary is almost void). |
60 |
For ST-80 compatibility, this will be replaced by a single instance of |
|
362 | 61 |
MethodDictionary (which will NOT be a true dictionary, but an Array with |
356 | 62 |
alternating selector/method entries). |
63 |
To be prepared for this change, please do NOT directly use the methodArray |
|
64 |
and selectorArray instVars. |
|
1 | 65 |
|
68 | 66 |
Instance variables: |
1 | 67 |
|
154 | 68 |
superclass <Class> the receivers superclass |
356 | 69 |
|
154 | 70 |
otherSuperclasses <Array of Class> experimental: other superclasses |
356 | 71 |
a hook for experimental multiple inheritance |
72 |
implementations |
|
73 |
||
154 | 74 |
selectorArray <Array of Symbol> the selectors for which inst-methods are defined here |
356 | 75 |
|
154 | 76 |
methodArray <Array of Method> the inst-methods corresponding to the selectors |
356 | 77 |
|
154 | 78 |
instSize <SmallInteger> the number of instance variables |
356 | 79 |
|
154 | 80 |
flags <SmallInteger> special flag bits coded in a number |
356 | 81 |
not for application use |
1 | 82 |
|
81 | 83 |
flag bits (see stc.h): |
47 | 84 |
|
68 | 85 |
NOTICE: layout known by compiler and runtime system; be careful when changing |
47 | 86 |
" |
356 | 87 |
! |
88 |
||
620 | 89 |
version |
90 |
^ '$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.53 1995-11-23 10:45:04 cg Exp $' |
|
91 |
! |
|
92 |
||
356 | 93 |
virtualMachineRelationship |
94 |
" |
|
357 | 95 |
NOTICE: |
96 |
the stuff described below may not be available on other |
|
97 |
Smalltalk implementations; be aware that these error mechanisms |
|
98 |
are ST/X specials and applications using these (tricks) may |
|
99 |
not be portable to other systems. |
|
100 |
||
101 |
WARNING: |
|
102 |
do not try the examples below on (some) other smalltalk systems; |
|
103 |
it has been reported, that some crash badly when doing this .... ;-) |
|
104 |
||
356 | 105 |
Instances of Behavior and subclasses (i.e. in sloppy words: classes) |
106 |
play a special role w.r.t. the VM. Only objects whose class-slot is marked |
|
107 |
as being behaviorLike (in the flag-instvar) are considered to be classLike |
|
108 |
and a message lookup will be done for it in the well known way. |
|
109 |
Thus, if an object has a class for which its class does NOT have |
|
362 | 110 |
this flag bit set, the VM will trigger an error on a message send. |
356 | 111 |
|
112 |
Why is this so: |
|
113 |
||
114 |
the above lets every object play the role of a class, |
|
115 |
which has been flagged as behaviorLike in its class's flag. |
|
116 |
Thus, you can create arbitrary new classLike objects and have the VM |
|
117 |
play with them. |
|
118 |
This may offer the flexibility to create a totally different object scheme |
|
362 | 119 |
on top of ST/X (for example: Self like objects) where any object can play |
120 |
a classRole for another object. |
|
356 | 121 |
|
357 | 122 |
However, the VM trusts the isBehaviorLike flag - if it is set for some |
362 | 123 |
object, it expects the object selector and methodDictionaries to be found |
124 |
at the instance positions as defined here. |
|
125 |
(i.e. instanceVariables with contents and semantic corresponding to |
|
126 |
superclass flags selectorArray methodArray |
|
127 |
must be present and have the same instVar-index as here). |
|
128 |
||
356 | 129 |
The VM (and the system) may crash badly, if this is not the case. |
362 | 130 |
|
356 | 131 |
Since every class in the system derives from Behavior, the flag setting |
357 | 132 |
(and instance variable layout) is correct for all 'normal' classes. |
133 |
If you experiment by creating new behaviorLike objects, please take |
|
134 |
care of this flag. If you want to use the VM's lookup function, the |
|
135 |
instVars 'superclass', 'selectorArray' and 'methodArray' are required |
|
136 |
and have to be at the same instVar index. |
|
362 | 137 |
(we suggest, you subclass Behavior, to make certain) |
357 | 138 |
|
139 |
You do not have to care about the above details if you are a 'normal' |
|
140 |
ST-programmer, though. |
|
141 |
||
356 | 142 |
|
143 |
Examples (only of theoretical interrest): |
|
144 |
take away the behaviorLike-flag from a class. |
|
145 |
-> The instances will not understand any messages, since the VM will |
|
146 |
not recognize its class as being a class ... |
|
147 |
||
148 |
|newMeta notRecognizedAsClass someInstance| |
|
149 |
||
150 |
newMeta := Metaclass new. |
|
151 |
newMeta flags:0. |
|
152 |
||
153 |
notRecognizedAsClass := newMeta new. |
|
154 |
||
155 |
someInstance := notRecognizedAsClass new. |
|
156 |
someInstance perform:#isNil |
|
157 |
||
357 | 158 |
|
159 |
Of course, this is an exception which can be handled ...: |
|
160 |
Example: |
|
161 |
||
162 |
|newMeta notRecognizedAsClass someInstance| |
|
163 |
||
164 |
newMeta := Metaclass new. |
|
165 |
newMeta flags:0. |
|
166 |
||
167 |
notRecognizedAsClass := newMeta new. |
|
168 |
||
169 |
someInstance := notRecognizedAsClass new. |
|
170 |
Object errorSignal handle:[:ex | |
|
171 |
ex return |
|
172 |
] do:[ |
|
173 |
someInstance perform:#isNil |
|
174 |
] |
|
175 |
||
176 |
||
177 |
likewise, a doesNotUnderstand-notUnderstood can be handled: |
|
178 |
Example: |
|
179 |
||
180 |
|newMeta funnyClass someInstance| |
|
181 |
||
182 |
newMeta := Metaclass new. |
|
183 |
||
184 |
funnyClass := newMeta new. |
|
185 |
funnyClass setSuperclass:nil. |
|
186 |
||
187 |
someInstance := funnyClass new. |
|
188 |
Object errorSignal handle:[:ex | |
|
189 |
ex return |
|
190 |
] do:[ |
|
191 |
someInstance perform:#isNil |
|
192 |
] |
|
193 |
||
194 |
||
362 | 195 |
more examples, which try to trick the VM ;-): |
357 | 196 |
badly playing around with a classes internals ... |
197 |
||
198 |
|newClass someInstance| |
|
199 |
||
200 |
newClass := Class new. |
|
201 |
newClass setSelectorArray:nil. |
|
202 |
someInstance := newClass new. |
|
203 |
someInstance inspect |
|
204 |
||
205 |
||
206 |
|newClass someInstance| |
|
207 |
||
208 |
newClass := Class new. |
|
209 |
newClass setSuperclass:nil. |
|
210 |
someInstance := newClass new. |
|
211 |
someInstance inspect |
|
212 |
||
213 |
||
214 |
|newClass someInstance| |
|
215 |
||
216 |
newClass := Class new. |
|
217 |
newClass setSuperclass:newClass. |
|
218 |
someInstance := newClass new. |
|
219 |
someInstance inspect |
|
220 |
||
221 |
||
222 |
|newClass someInstance| |
|
223 |
||
224 |
newClass := Class new. |
|
225 |
newClass setSuperclass:1. |
|
226 |
someInstance := newClass new. |
|
227 |
someInstance inspect |
|
228 |
||
229 |
||
356 | 230 |
Example: |
231 |
creating totally anonymous classes: |
|
232 |
||
233 |
|newClass someInstance| |
|
234 |
||
235 |
newClass := Class new. |
|
236 |
someInstance := newClass new. |
|
237 |
someInstance inspect |
|
238 |
||
357 | 239 |
|
356 | 240 |
Example: |
357 | 241 |
creating totally anonymous metaclasses: |
356 | 242 |
|
243 |
|newMeta newClass someInstance| |
|
244 |
||
245 |
newMeta := Metaclass new. |
|
246 |
newClass := newMeta new. |
|
247 |
someInstance := newClass new. |
|
248 |
someInstance inspect |
|
357 | 249 |
|
250 |
PS: if you experiment with new behaviorLike objects, you may want |
|
251 |
to turn off the VM's debugPrintouts |
|
252 |
with: |
|
253 |
'Smalltalk debugPrinting:false' |
|
254 |
and: |
|
255 |
'Smalltalk infoPrinting:false' |
|
356 | 256 |
" |
47 | 257 |
! ! |
1 | 258 |
|
259 |
!Behavior class methodsFor:'creating new classes'! |
|
260 |
||
261 |
new |
|
356 | 262 |
"creates and return a new behavior (which is like a class, |
263 |
but without the symbolic & name information). |
|
264 |
Not for normal applications. |
|
265 |
Sending the returned behavior the #new message gives you |
|
266 |
an instance if it. |
|
267 |
||
268 |
Notice: the returned class is given a superclass of Object; |
|
269 |
this allows for its new instances to be inspected and the like." |
|
1 | 270 |
|
271 |
|newClass| |
|
272 |
||
273 |
newClass := self basicNew. |
|
274 |
newClass setSuperclass:Object |
|
345 | 275 |
selectors:#() "/ (Array new:0) |
276 |
methods:#() "/ (Array new:0) |
|
154 | 277 |
instSize:0 |
345 | 278 |
flags:(self flagBehavior). |
1 | 279 |
^ newClass |
356 | 280 |
|
281 |
" |
|
282 |
Behavior new <- a new behavior |
|
283 |
Behavior new new <- an instance of it |
|
284 |
ClassDescription new <- a new classDescription |
|
285 |
ClassDescription new new <- an instance of it |
|
286 |
Class new <- a new class |
|
287 |
Class new new <- an instance of it |
|
288 |
Metaclass new <- a new metaclass |
|
289 |
Metaclass new new <- an instance (i.e. a class) of it |
|
290 |
Metaclass new new new <- an instance of this new class |
|
291 |
" |
|
1 | 292 |
! ! |
293 |
||
620 | 294 |
!Behavior class methodsFor:'flag bit constants'! |
295 |
||
296 |
flagBehavior |
|
297 |
"return the flag code which marks Behavior-like instances. |
|
298 |
You have to check this single bit in the flag value when |
|
299 |
checking for behaviors." |
|
300 |
||
301 |
%{ /* NOCONTEXT */ |
|
302 |
/* this is defined as a primitive to get defines from stc.h */ |
|
303 |
||
304 |
RETURN ( _MKSMALLINT(BEHAVIOR_INSTS) ); |
|
305 |
%} |
|
306 |
||
307 |
"consistency check: |
|
308 |
all class-entries must be behaviors; |
|
309 |
all behaviors must be flagged so (in its class's flags) |
|
310 |
(otherwise, VM will bark) |
|
311 |
all non-behaviors may not be flagged |
|
312 |
||
313 |
|bit| |
|
314 |
bit := Class flagBehavior. |
|
315 |
||
316 |
ObjectMemory allObjectsDo:[:o| |
|
317 |
o isBehavior ifTrue:[ |
|
318 |
(o class flags bitTest:bit) ifFalse:[ |
|
319 |
self halt |
|
320 |
]. |
|
321 |
] ifFalse:[ |
|
322 |
(o class flags bitTest:bit) ifTrue:[ |
|
323 |
self halt |
|
324 |
]. |
|
325 |
]. |
|
326 |
o class isBehavior ifFalse:[ |
|
327 |
self halt |
|
328 |
] ifTrue:[ |
|
329 |
(o class class flags bitTest:bit) ifFalse:[ |
|
330 |
self halt |
|
331 |
] |
|
332 |
] |
|
333 |
] |
|
334 |
" |
|
335 |
! |
|
336 |
||
337 |
flagBlock |
|
338 |
"return the flag code which marks Block-like instances. |
|
339 |
You have to check this single bit in the flag value when |
|
340 |
checking for blocks." |
|
341 |
||
342 |
%{ /* NOCONTEXT */ |
|
343 |
/* this is defined as a primitive to get defines from stc.h */ |
|
344 |
||
345 |
RETURN ( _MKSMALLINT(BLOCK_INSTS) ); |
|
346 |
%} |
|
347 |
! |
|
348 |
||
349 |
flagBlockContext |
|
350 |
"return the flag code which marks BlockContext-like instances. |
|
351 |
You have to check this single bit in the flag value when |
|
352 |
checking for blockContexts." |
|
353 |
||
354 |
%{ /* NOCONTEXT */ |
|
355 |
/* this is defined as a primitive to get defines from stc.h */ |
|
356 |
||
357 |
RETURN ( _MKSMALLINT(BCONTEXT_INSTS) ); |
|
358 |
%} |
|
359 |
! |
|
360 |
||
361 |
flagBytes |
|
362 |
"return the flag code for byte-valued indexed instances. |
|
363 |
You have to mask the flag value with indexMask when comparing |
|
364 |
it with flagBytes." |
|
365 |
||
366 |
%{ /* NOCONTEXT */ |
|
367 |
/* this is defined as a primitive to get defines from stc.h */ |
|
368 |
||
369 |
RETURN ( _MKSMALLINT(BYTEARRAY) ); |
|
370 |
%} |
|
371 |
" |
|
372 |
Behavior flagBytes |
|
373 |
" |
|
374 |
! |
|
375 |
||
376 |
flagContext |
|
377 |
"return the flag code which marks Context-like instances. |
|
378 |
You have to check this single bit in the flag value when |
|
379 |
checking for contexts." |
|
380 |
||
381 |
%{ /* NOCONTEXT */ |
|
382 |
/* this is defined as a primitive to get defines from stc.h */ |
|
383 |
||
384 |
RETURN ( _MKSMALLINT(CONTEXT_INSTS) ); |
|
385 |
%} |
|
386 |
! |
|
387 |
||
388 |
flagDoubles |
|
389 |
"return the flag code for double-valued indexed instances (i.e. 8-byte reals). |
|
390 |
You have to mask the flag value with indexMask when comparing |
|
391 |
it with flagDoubles." |
|
392 |
||
393 |
%{ /* NOCONTEXT */ |
|
394 |
/* this is defined as a primitive to get defines from stc.h */ |
|
395 |
||
396 |
RETURN ( _MKSMALLINT(DOUBLEARRAY) ); |
|
397 |
%} |
|
398 |
" |
|
399 |
Behavior flagDoubles |
|
400 |
" |
|
401 |
! |
|
402 |
||
403 |
flagFloat |
|
404 |
"return the flag code which marks Float-like instances. |
|
405 |
You have to check this single bit in the flag value when |
|
406 |
checking for floats." |
|
407 |
||
408 |
%{ /* NOCONTEXT */ |
|
409 |
/* this is defined as a primitive to get defines from stc.h */ |
|
410 |
||
411 |
RETURN ( _MKSMALLINT(FLOAT_INSTS) ); |
|
412 |
%} |
|
413 |
! |
|
414 |
||
415 |
flagFloats |
|
416 |
"return the flag code for float-valued indexed instances (i.e. 4-byte reals). |
|
417 |
You have to mask the flag value with indexMask when comparing |
|
418 |
it with flagFloats." |
|
419 |
||
420 |
%{ /* NOCONTEXT */ |
|
421 |
/* this is defined as a primitive to get defines from stc.h */ |
|
422 |
||
423 |
RETURN ( _MKSMALLINT(FLOATARRAY) ); |
|
424 |
%} |
|
425 |
" |
|
426 |
Behavior flagFloats |
|
427 |
" |
|
428 |
! |
|
429 |
||
430 |
flagLongs |
|
431 |
"return the flag code for long-valued indexed instances (i.e. 4-byte). |
|
432 |
You have to mask the flag value with indexMask when comparing |
|
433 |
it with flagLongs." |
|
434 |
||
435 |
%{ /* NOCONTEXT */ |
|
436 |
/* this is defined as a primitive to get defines from stc.h */ |
|
437 |
||
438 |
RETURN ( _MKSMALLINT(LONGARRAY) ); |
|
439 |
%} |
|
440 |
" |
|
441 |
Behavior flagLongs |
|
442 |
" |
|
443 |
! |
|
444 |
||
445 |
flagMethod |
|
446 |
"return the flag code which marks Method-like instances. |
|
447 |
You have to check this single bit in the flag value when |
|
448 |
checking for methods." |
|
449 |
||
450 |
%{ /* NOCONTEXT */ |
|
451 |
/* this is defined as a primitive to get defines from stc.h */ |
|
452 |
||
453 |
RETURN ( _MKSMALLINT(METHOD_INSTS) ); |
|
454 |
%} |
|
455 |
! |
|
456 |
||
457 |
flagNonObjectInst |
|
458 |
"return the flag code which marks instances which have a |
|
459 |
non-object instance variable (in slot 1). |
|
460 |
(these are ignored by the garbage collector)" |
|
461 |
||
462 |
%{ /* NOCONTEXT */ |
|
463 |
/* this is defined as a primitive to get defines from stc.h */ |
|
464 |
||
465 |
RETURN ( _MKSMALLINT(NONOBJECT_INSTS) ); |
|
466 |
%} |
|
467 |
! |
|
468 |
||
469 |
flagNotIndexed |
|
470 |
"return the flag code for non-indexed instances. |
|
471 |
You have to mask the flag value with indexMask when comparing |
|
472 |
it with flagNotIndexed." |
|
473 |
||
474 |
^ 0 |
|
475 |
! |
|
476 |
||
477 |
flagPointers |
|
478 |
"return the flag code for pointer indexed instances (i.e. Array of object). |
|
479 |
You have to mask the flag value with indexMask when comparing |
|
480 |
it with flagPointers." |
|
481 |
||
482 |
%{ /* NOCONTEXT */ |
|
483 |
/* this is defined as a primitive to get defines from stc.h */ |
|
484 |
||
485 |
RETURN ( _MKSMALLINT(POINTERARRAY) ); |
|
486 |
%} |
|
487 |
" |
|
488 |
Behavior flagPointers |
|
489 |
" |
|
490 |
! |
|
491 |
||
492 |
flagSymbol |
|
493 |
"return the flag code which marks Symbol-like instances. |
|
494 |
You have to check this single bit in the flag value when |
|
495 |
checking for symbols." |
|
496 |
||
497 |
%{ /* NOCONTEXT */ |
|
498 |
/* this is defined as a primitive to get defines from stc.h */ |
|
499 |
||
500 |
RETURN ( _MKSMALLINT(SYMBOL_INSTS) ); |
|
501 |
%} |
|
502 |
! |
|
503 |
||
504 |
flagWeakPointers |
|
505 |
"return the flag code for weak pointer indexed instances (i.e. WeakArray). |
|
506 |
You have to mask the flag value with indexMask when comparing |
|
507 |
it with flagWeakPointers." |
|
508 |
||
509 |
%{ /* NOCONTEXT */ |
|
510 |
/* this is defined as a primitive to get defines from stc.h */ |
|
511 |
||
512 |
RETURN ( _MKSMALLINT(WKPOINTERARRAY) ); |
|
513 |
%} |
|
514 |
! |
|
515 |
||
516 |
flagWords |
|
517 |
"return the flag code for word-valued indexed instances (i.e. 2-byte). |
|
518 |
You have to mask the flag value with indexMask when comparing |
|
519 |
it with flagWords." |
|
520 |
||
521 |
%{ /* NOCONTEXT */ |
|
522 |
/* this is defined as a primitive to get defines from stc.h */ |
|
523 |
||
524 |
RETURN ( _MKSMALLINT(WORDARRAY) ); |
|
525 |
%} |
|
526 |
" |
|
527 |
Behavior flagWords |
|
528 |
" |
|
529 |
! |
|
530 |
||
531 |
maskIndexType |
|
532 |
"return a mask to extract all index-type bits" |
|
533 |
||
534 |
%{ /* NOCONTEXT */ |
|
535 |
/* this is defined as a primitive to get defines from stc.h */ |
|
536 |
||
537 |
RETURN ( _MKSMALLINT(ARRAYMASK) ); |
|
538 |
%} |
|
539 |
! ! |
|
540 |
||
308 | 541 |
!Behavior class methodsFor:'private '! |
542 |
||
620 | 543 |
flushSubclassInfo |
544 |
SubclassInfo := nil. |
|
545 |
||
546 |
" |
|
547 |
Class flushSubclassInfo |
|
548 |
" |
|
549 |
! |
|
550 |
||
308 | 551 |
subclassInfo |
357 | 552 |
|d| |
308 | 553 |
|
554 |
SubclassInfo notNil ifTrue:[^ SubclassInfo]. |
|
555 |
||
556 |
d := IdentityDictionary new. |
|
557 |
Smalltalk allClassesDo:[:aClass | |
|
558 |
|superCls| |
|
559 |
||
560 |
aClass isMeta not ifTrue:[ |
|
561 |
superCls := aClass superclass. |
|
562 |
superCls notNil ifTrue:[ |
|
563 |
(d includesKey: superCls) ifFalse:[ |
|
564 |
d at:superCls put:(Set with:aClass). |
|
565 |
] ifTrue:[ |
|
566 |
(d at:superCls ) add:aClass |
|
567 |
] |
|
568 |
] |
|
569 |
]. |
|
570 |
]. |
|
571 |
SubclassInfo := d. |
|
572 |
^ d |
|
573 |
||
574 |
" |
|
575 |
Class subclassInfo |
|
576 |
" |
|
620 | 577 |
! ! |
578 |
||
579 |
!Behavior class methodsFor:'queries'! |
|
580 |
||
581 |
isBuiltInClass |
|
582 |
"this class is known by the run-time-system" |
|
583 |
||
584 |
^ true |
|
585 |
! ! |
|
586 |
||
587 |
!Behavior methodsFor:'accessing'! |
|
588 |
||
589 |
addSelector:newSelector withLazyMethod:newMethod |
|
590 |
"add the method given by 2nd argument under the selector given by |
|
591 |
1st argument to the methodDictionary. Since it does not flush |
|
592 |
any caches, this is only allowed for lazy methods." |
|
593 |
||
594 |
newMethod isLazyMethod ifFalse:[ |
|
595 |
self error:'operation only allowed for lazy methods'. |
|
596 |
^ false |
|
597 |
]. |
|
598 |
"/ oops: we must flush, if this method already exists ... |
|
599 |
(selectorArray includes:newSelector) ifTrue:[ |
|
600 |
ObjectMemory flushCaches |
|
601 |
]. |
|
602 |
(self primAddSelector:newSelector withMethod:newMethod) ifTrue:[ |
|
603 |
self changed:#methodDictionary with:newSelector. |
|
604 |
^ true |
|
605 |
]. |
|
606 |
^ false |
|
308 | 607 |
! |
608 |
||
620 | 609 |
addSelector:newSelector withMethod:newMethod |
610 |
"add the method given by 2nd argument under the selector given by |
|
611 |
1st argument to the methodDictionary. Flush all caches." |
|
612 |
||
613 |
|nargs| |
|
614 |
||
615 |
(self primAddSelector:newSelector withMethod:newMethod) ifFalse:[^ false]. |
|
616 |
self changed:#methodDictionary with:newSelector. |
|
617 |
||
618 |
" |
|
619 |
if I have no subclasses, all we have to flush is cached |
|
620 |
data for myself ... (actually, in any case all that needs |
|
621 |
to be flushed is info for myself and all of my subclasses) |
|
622 |
" |
|
623 |
" |
|
624 |
problem: this is slower; since looking for all subclasses is (currently) |
|
625 |
a bit slow :-( |
|
626 |
We need the hasSubclasses-info bit in Behavior; now |
|
627 |
||
628 |
self withAllSubclassesDo:[:aClass | |
|
629 |
ObjectMemory flushInlineCachesFor:aClass withArgs:nargs. |
|
630 |
ObjectMemory flushMethodCacheFor:aClass |
|
631 |
]. |
|
632 |
" |
|
633 |
||
634 |
" |
|
635 |
actually, we would do better with less flushing ... |
|
636 |
" |
|
637 |
nargs := newSelector numArgs. |
|
638 |
||
639 |
ObjectMemory flushMethodCache. |
|
640 |
ObjectMemory flushInlineCachesWithArgs:nargs. |
|
641 |
||
642 |
^ true |
|
643 |
! |
|
644 |
||
645 |
addSuperclass:aClass |
|
646 |
"EXPERIMENTAL MI support: add aClass to the set of classes, from which instances |
|
647 |
inherit protocol." |
|
648 |
||
649 |
"first, check if the class is abstract - |
|
650 |
allows abstract mixins are allowed in the current implementation" |
|
651 |
||
652 |
aClass instSize == 0 ifFalse:[ |
|
653 |
self error:'only abstract mixins allowed'. |
|
654 |
^ self |
|
655 |
]. |
|
656 |
otherSuperclasses isNil ifTrue:[ |
|
657 |
otherSuperclasses := Array with:aClass |
|
658 |
] ifFalse:[ |
|
659 |
otherSuperclasses := otherSuperclasses copyWith:aClass |
|
660 |
]. |
|
308 | 661 |
SubclassInfo := nil. |
620 | 662 |
ObjectMemory flushCaches |
663 |
! |
|
664 |
||
665 |
category |
|
666 |
"return the category of the class. |
|
667 |
Returning nil here, since Behavior does not define a category |
|
668 |
(only ClassDescriptions do)." |
|
669 |
||
670 |
^ nil |
|
671 |
||
672 |
" |
|
673 |
Point category |
|
674 |
Behavior new category |
|
675 |
" |
|
676 |
! |
|
677 |
||
678 |
displayString |
|
679 |
"although behaviors have no name, we return something |
|
680 |
useful here - there are many places (inspectors) where |
|
681 |
a classes name is asked for. |
|
682 |
Implementing this message here allows instances of anonymous classes |
|
683 |
to show a reasonable name." |
|
684 |
||
685 |
^ 'someBehavior' |
|
686 |
! |
|
687 |
||
688 |
flags |
|
689 |
"return the receivers flag bits" |
|
690 |
||
691 |
^ flags |
|
692 |
! |
|
693 |
||
694 |
implicit_methodDict |
|
695 |
"ST-80 compatibility. |
|
696 |
This allows subclasses to assume there is an instance variable |
|
697 |
named methodDict." |
|
698 |
||
699 |
^ self methodDictionary |
|
700 |
! |
|
701 |
||
702 |
implicit_methodDict:aDictionary |
|
703 |
"ST-80 compatibility. |
|
704 |
This allows subclasses to assume there is an instance variable |
|
705 |
named methodDict." |
|
706 |
||
707 |
^ self error:'not allowed to set the methodDictionary' |
|
708 |
! |
|
709 |
||
710 |
instSize |
|
711 |
"return the number of instance variables of the receiver. |
|
712 |
This includes all superclass instance variables." |
|
713 |
||
714 |
^ instSize |
|
715 |
! |
|
716 |
||
717 |
methodArray |
|
718 |
"return the receivers method array. |
|
719 |
Notice: this is not compatible with ST-80." |
|
720 |
||
721 |
^ methodArray |
|
722 |
! |
|
723 |
||
724 |
methodDictionary |
|
725 |
"return the receivers method dictionary. |
|
726 |
Since no dictionary is actually present, create one for ST-80 compatibility." |
|
727 |
||
728 |
|dict n "{ Class: SmallInteger }"| |
|
729 |
||
730 |
dict := IdentityDictionary new. |
|
731 |
n := selectorArray size. |
|
732 |
1 to:n do:[:index | |
|
733 |
dict at:(selectorArray at:index) put:(methodArray at:index) |
|
734 |
]. |
|
735 |
^ dict |
|
736 |
! |
|
737 |
||
738 |
name |
|
739 |
"although behaviors have no name, we return something |
|
740 |
useful here - there are many places (inspectors) where |
|
741 |
a classes name is asked for. |
|
742 |
Implementing this message here allows anonymous classes |
|
743 |
and instances of them to be inspected." |
|
744 |
||
745 |
^ 'someBehavior' |
|
746 |
! |
|
747 |
||
748 |
removeSelector:aSelector |
|
749 |
"remove the selector, aSelector and its associated method |
|
750 |
from the methodDictionary" |
|
751 |
||
752 |
|index oldSelectorArray oldMethodArray newSelectorArray newMethodArray| |
|
753 |
||
754 |
index := selectorArray identityIndexOf:aSelector startingAt:1. |
|
755 |
(index == 0) ifTrue:[^ false]. |
|
756 |
||
757 |
newSelectorArray := selectorArray copyWithoutIndex:index. |
|
758 |
newMethodArray := methodArray copyWithoutIndex:index. |
|
759 |
oldSelectorArray := selectorArray. |
|
760 |
oldMethodArray := methodArray. |
|
761 |
selectorArray := newSelectorArray. |
|
762 |
methodArray := newMethodArray. |
|
763 |
" |
|
764 |
[ |
|
765 |
|nargs| |
|
766 |
nargs := aSelector numArgs. |
|
767 |
ObjectMemory flushMethodCache. |
|
768 |
ObjectMemory flushInlineCachesWithArgs:nargs. |
|
769 |
] value |
|
770 |
" |
|
771 |
" |
|
772 |
actually, we would do better with less flushing ... |
|
773 |
" |
|
774 |
ObjectMemory flushCaches. |
|
775 |
^ true |
|
776 |
! |
|
777 |
||
778 |
removeSuperclass:aClass |
|
779 |
"EXPERIMENTAL MI support: remove aClass from the set of classes, from which instances |
|
780 |
inherit protocol." |
|
781 |
||
782 |
otherSuperclasses notNil ifTrue:[ |
|
783 |
otherSuperclasses := otherSuperclasses copyWithout:aClass. |
|
784 |
otherSuperclasses isEmpty ifTrue:[ |
|
785 |
otherSuperclasses := nil |
|
786 |
]. |
|
787 |
SubclassInfo := nil. |
|
788 |
ObjectMemory flushCaches |
|
789 |
]. |
|
790 |
! |
|
791 |
||
792 |
selectorArray |
|
793 |
"return the receivers selector array. |
|
794 |
Notice: this is not compatible with ST-80." |
|
795 |
||
796 |
^ selectorArray |
|
797 |
! |
|
798 |
||
799 |
selectors |
|
800 |
"return the receivers selector array as an orderedCollection. |
|
801 |
Notice: this may not be compatible with ST-80. |
|
802 |
(should we return a Set ?)" |
|
803 |
||
804 |
^ selectorArray asOrderedCollection |
|
805 |
! |
|
806 |
||
807 |
selectors:newSelectors methods:newMethods |
|
808 |
"set both selector array and method array of the receiver, |
|
809 |
and flush caches" |
|
810 |
||
811 |
ObjectMemory flushCaches. |
|
812 |
selectorArray := newSelectors. |
|
813 |
methodArray := newMethods |
|
814 |
! |
|
815 |
||
816 |
superclass |
|
817 |
"return the receivers superclass" |
|
818 |
||
819 |
^ superclass |
|
820 |
! |
|
821 |
||
822 |
superclass:aClass |
|
823 |
"set the superclass - this actually creates a new class, |
|
824 |
recompiling all methods for the new one. The receiving class stays |
|
825 |
around anonymous to allow existing instances some life. |
|
826 |
This may change in the future (adjusting existing instances)" |
|
827 |
||
828 |
SubclassInfo := nil. |
|
829 |
||
830 |
"must flush caches since lookup chain changes" |
|
831 |
ObjectMemory flushCaches. |
|
832 |
||
833 |
" |
|
834 |
superclass := aClass |
|
835 |
" |
|
836 |
"for correct recompilation, just create a new class ..." |
|
837 |
||
838 |
aClass subclass:(self name) |
|
839 |
instanceVariableNames:(self instanceVariableString) |
|
840 |
classVariableNames:(self classVariableString) |
|
841 |
poolDictionaries:'' |
|
842 |
category:self category |
|
843 |
! ! |
|
844 |
||
845 |
!Behavior methodsFor:'autoload check'! |
|
846 |
||
847 |
autoload |
|
848 |
"force autoloading - do nothing here; |
|
849 |
redefined in Autoload; see comment there" |
|
850 |
||
851 |
^ self |
|
852 |
! |
|
853 |
||
854 |
isLoaded |
|
855 |
"return true, if the class has been loaded; |
|
856 |
redefined in Autoload; see comment there" |
|
857 |
||
858 |
^ true |
|
859 |
! ! |
|
860 |
||
861 |
!Behavior methodsFor:'binary storage'! |
|
862 |
||
863 |
binaryDefinitionFrom:stream manager:manager |
|
864 |
"sent during a binary read by the input manager. |
|
865 |
Read the definition on an empty instance (of my class) from stream. |
|
866 |
All pointer instances are left nil, while all bits are read in here. |
|
867 |
return the new object." |
|
868 |
||
869 |
|obj t |
|
870 |
basicSize "{ Class: SmallInteger }" | |
|
871 |
||
872 |
self isPointers ifTrue: [ |
|
873 |
"/ |
|
874 |
"/ inst size not needed - if you uncomment the line below, |
|
875 |
"/ also uncomment the corresponding line in |
|
876 |
"/ Object>>storeBinaryDefinitionOn:manager: |
|
877 |
"/ |
|
878 |
"/ stream next. "skip instSize" |
|
879 |
self isVariable ifTrue: [ |
|
880 |
^ self basicNew:(stream nextNumber:3) |
|
881 |
]. |
|
882 |
^ self basicNew |
|
883 |
]. |
|
308 | 884 |
|
885 |
" |
|
620 | 886 |
an object with bit-valued instance variables. |
887 |
These are read here. |
|
888 |
" |
|
889 |
basicSize := stream nextNumber:4. |
|
890 |
obj := self basicNew:basicSize. |
|
891 |
||
892 |
self isBytes ifTrue: [ |
|
893 |
stream nextBytes:basicSize into:obj |
|
894 |
] ifFalse: [ |
|
895 |
self isWords ifTrue: [ |
|
896 |
1 to:basicSize do:[:i | |
|
897 |
obj basicAt:i put:(stream nextNumber:2) |
|
898 |
] |
|
899 |
] ifFalse:[ |
|
900 |
self isLongs ifTrue: [ |
|
901 |
1 to:basicSize do:[:i | |
|
902 |
obj basicAt:i put:(stream nextNumber:4) |
|
903 |
] |
|
904 |
] ifFalse:[ |
|
905 |
self isFloats ifTrue: [ |
|
906 |
"could do it in one big read on machines which use IEEE floats ..." |
|
907 |
t := Float basicNew. |
|
908 |
1 to:basicSize do:[:i | |
|
909 |
Float readBinaryIEEESingleFrom:stream into:t. |
|
910 |
obj basicAt:i put: t |
|
911 |
] |
|
912 |
] ifFalse:[ |
|
913 |
self isDoubles ifTrue: [ |
|
914 |
"could do it in one big read on machines which use IEEE doubles ..." |
|
915 |
t := Float basicNew. |
|
916 |
1 to:basicSize do:[:i | |
|
917 |
Float readBinaryIEEEDoubleFrom:stream into:t. |
|
918 |
obj basicAt:i put: t |
|
919 |
] |
|
920 |
] |
|
921 |
] |
|
922 |
] |
|
923 |
] |
|
924 |
]. |
|
925 |
^obj |
|
926 |
! |
|
927 |
||
928 |
canCloneFrom:anObject |
|
929 |
"return true, if this class can clone an obsolete object as retrieved |
|
930 |
by a binary load. Subclasses which do not want to have obsolete objects |
|
931 |
be converted, should redefine this method to return false. |
|
932 |
(However, conversion is never done silently in a binary load; you |
|
933 |
have to have a handler for the binaryload errors and for the conversion |
|
934 |
request signal.)" |
|
935 |
||
936 |
^ true |
|
937 |
! |
|
938 |
||
939 |
cloneFrom:aPrototype |
|
940 |
"return an instance of myself with variables initialized from |
|
941 |
a prototype. This is used when instances of obsolete classes are |
|
942 |
binary loaded and a conversion is done on the obsolete object. |
|
943 |
UserClasses may redefine this for better conversions." |
|
944 |
||
945 |
|newInst indexed myInfo otherInfo varIndexAssoc| |
|
946 |
||
947 |
indexed := false. |
|
948 |
aPrototype class isVariable ifTrue:[ |
|
949 |
self isVariable ifTrue:[ |
|
950 |
indexed := true. |
|
951 |
]. |
|
952 |
"otherwise, these are lost ..." |
|
953 |
]. |
|
954 |
indexed ifTrue:[ |
|
955 |
newInst := self basicNew:aPrototype basicSize |
|
956 |
] ifFalse:[ |
|
957 |
newInst := self basicNew |
|
958 |
]. |
|
959 |
||
960 |
myInfo := self instanceVariableOffsets. |
|
961 |
otherInfo := aPrototype class instanceVariableOffsets. |
|
962 |
myInfo keysAndValuesDo:[:name :index | |
|
963 |
varIndexAssoc := otherInfo at:name ifAbsent:[]. |
|
964 |
varIndexAssoc notNil ifTrue:[ |
|
965 |
newInst instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
966 |
] |
|
967 |
]. |
|
968 |
indexed ifTrue:[ |
|
969 |
1 to:aPrototype basicSize do:[:index | |
|
970 |
newInst basicAt:index put:(aPrototype basicAt:index) |
|
971 |
]. |
|
972 |
]. |
|
973 |
^ newInst |
|
974 |
||
975 |
" |
|
976 |
Class withoutUpdatingChangesDo:[ |
|
977 |
Point subclass:#Point3D |
|
978 |
instanceVariableNames:'z' |
|
979 |
classVariableNames:'' |
|
980 |
poolDictionaries:'' |
|
981 |
category:'testing'. |
|
982 |
(Point3D cloneFrom:1@2) inspect. |
|
983 |
] |
|
984 |
" |
|
985 |
||
986 |
" |
|
987 |
Class withoutUpdatingChangesDo:[ |
|
988 |
Point variableSubclass:#Point3D |
|
989 |
instanceVariableNames:'z' |
|
990 |
classVariableNames:'' |
|
991 |
poolDictionaries:'' |
|
992 |
category:'testing'. |
|
993 |
(Point3D cloneFrom:#(1 2 3)) inspect. |
|
994 |
] |
|
995 |
" |
|
996 |
||
997 |
" |
|
998 |
|someObject| |
|
999 |
||
1000 |
Class withoutUpdatingChangesDo:[ |
|
1001 |
Object subclass:#TestClass1 |
|
1002 |
instanceVariableNames:'foo bar' |
|
1003 |
classVariableNames:'' |
|
1004 |
poolDictionaries:'' |
|
1005 |
category:'testing'. |
|
1006 |
someObject := TestClass1 new. |
|
1007 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
1008 |
Object subclass:#TestClass2 |
|
1009 |
instanceVariableNames:'bar foo' |
|
1010 |
classVariableNames:'' |
|
1011 |
poolDictionaries:'' |
|
1012 |
category:'testing'. |
|
1013 |
(TestClass2 cloneFrom:someObject) inspect. |
|
1014 |
] |
|
1015 |
" |
|
1016 |
! |
|
1017 |
||
1018 |
readBinaryFrom:aStream |
|
1019 |
"read an objects binary representation from the argument, |
|
1020 |
aStream and return it. |
|
1021 |
The read object must be a kind of myself, otherwise an error is raised. |
|
1022 |
To get any object, use 'Object readBinaryFrom:...', |
|
1023 |
To get any number, use 'Number readBinaryFrom:...' and so on. |
|
1024 |
This is the reverse operation to 'storeBinaryOn:'. " |
|
1025 |
||
1026 |
^ self readBinaryFrom:aStream onError:[self error:('expected ' , self name)] |
|
1027 |
||
1028 |
" |
|
1029 |
|s| |
|
1030 |
s := WriteStream on:(ByteArray new). |
|
1031 |
#(1 2 3 4) storeBinaryOn:s. |
|
1032 |
Object readBinaryFrom:(ReadStream on:s contents) |
|
1033 |
" |
|
1034 |
" |
|
1035 |
|s| |
|
1036 |
s := 'testFile' asFilename writeStream binary. |
|
1037 |
#(1 2 3 4) storeBinaryOn:s. |
|
1038 |
'hello world' storeBinaryOn:s. |
|
1039 |
s close. |
|
1040 |
||
1041 |
s := 'testFile' asFilename readStream binary. |
|
1042 |
Transcript showCr:(Object readBinaryFrom:s). |
|
1043 |
Transcript showCr:(Object readBinaryFrom:s). |
|
1044 |
s close. |
|
1045 |
" |
|
1046 |
! |
|
1047 |
||
1048 |
readBinaryFrom:aStream onError:exceptionBlock |
|
1049 |
"read an objects binary representation from the argument, |
|
1050 |
aStream and return it. |
|
1051 |
The read object must be a kind of myself, otherwise the value of |
|
1052 |
the exceptionBlock is returned. |
|
1053 |
To get any object, use 'Object readBinaryFrom:...', |
|
1054 |
To get any number, use 'Number readBinaryFrom:...' and so on. |
|
1055 |
This is the reverse operation to 'storeBinaryOn:'. " |
|
1056 |
||
1057 |
|newObject| |
|
1058 |
||
1059 |
newObject := (BinaryInputManager new:1024) readFrom:aStream. |
|
1060 |
(newObject isKindOf:self) ifFalse:[^ exceptionBlock value]. |
|
1061 |
^ newObject |
|
1062 |
||
1063 |
" |
|
1064 |
|s| |
|
1065 |
s := WriteStream on:(ByteArray new). |
|
1066 |
#(1 2 3 4) storeBinaryOn:s. |
|
1067 |
Object readBinaryFrom:(ReadStream on:s contents) onError:['oops'] |
|
1068 |
" |
|
1069 |
" |
|
1070 |
|s| |
|
1071 |
s := WriteStream on:(ByteArray new). |
|
1072 |
#[1 2 3 4] storeBinaryOn:s. |
|
1073 |
Array readBinaryFrom:(ReadStream on:s contents) onError:['oops'] |
|
1074 |
" |
|
1075 |
! |
|
1076 |
||
1077 |
storeBinaryDefinitionOn: stream manager: manager |
|
1078 |
"binary store of a classes definition. |
|
1079 |
Classes will store the name only and restore by looking for |
|
1080 |
that name in the Smalltalk dictionary." |
|
1081 |
||
1082 |
| myName | |
|
1083 |
||
1084 |
myName := self name. |
|
1085 |
stream nextNumber:4 put:self signature. |
|
1086 |
stream nextNumber:2 put:0. |
|
1087 |
stream nextNumber:2 put:myName size. |
|
1088 |
myName do:[:c| |
|
1089 |
stream nextPut:c asciiValue |
|
1090 |
] |
|
1091 |
||
1092 |
" |
|
1093 |
|s| |
|
1094 |
s := WriteStream on:ByteArray new. |
|
1095 |
#(1 2 3 4) storeBinaryOn:s. |
|
1096 |
Object readBinaryFrom:(ReadStream on:s contents) |
|
1097 |
||
1098 |
|s| |
|
1099 |
s := WriteStream on:ByteArray new. |
|
1100 |
Rectangle storeBinaryOn:s. |
|
1101 |
Object readBinaryFrom:(ReadStream on:s contents) |
|
1102 |
" |
|
1103 |
! ! |
|
1104 |
||
1105 |
!Behavior methodsFor:'compiler interface'! |
|
1106 |
||
1107 |
compiler |
|
1108 |
"return the compiler to use for this class. |
|
1109 |
OBSOLETE: This is the old ST/X interface, kept for migration. |
|
1110 |
Dont use it - it will vanish." |
|
1111 |
||
1112 |
^ self compilerClass |
|
1113 |
! |
|
1114 |
||
1115 |
compilerClass |
|
1116 |
"return the compiler to use for this class - |
|
1117 |
this can be redefined in special classes, to get classes with |
|
1118 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1119 |
||
1120 |
^ Compiler |
|
1121 |
! |
|
1122 |
||
1123 |
evaluatorClass |
|
1124 |
"return the compiler to use for expression evaluation for this class - |
|
1125 |
this can be redefined in special classes, to get classes with |
|
1126 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1127 |
||
1128 |
^ Compiler |
|
1129 |
! ! |
|
1130 |
||
1131 |
!Behavior methodsFor:'copying'! |
|
1132 |
||
1133 |
deepCopy |
|
1134 |
"return a deep copy of the receiver |
|
1135 |
- return the receiver here - time will show if this is ok" |
|
1136 |
||
1137 |
^ self |
|
1138 |
! |
|
1139 |
||
1140 |
deepCopyUsing:aDictionary |
|
1141 |
"return a deep copy of the receiver |
|
1142 |
- return the receiver here - time will show if this is ok" |
|
1143 |
||
1144 |
^ self |
|
1145 |
! |
|
1146 |
||
1147 |
simpleDeepCopy |
|
1148 |
"return a deep copy of the receiver |
|
1149 |
- return the receiver here - time will show if this is ok" |
|
1150 |
||
1151 |
^ self |
|
1152 |
! ! |
|
1153 |
||
1154 |
!Behavior methodsFor:'enumerating'! |
|
1155 |
||
1156 |
allDerivedInstancesDo:aBlock |
|
1157 |
"evaluate aBlock for all of my instances and all instances of subclasses. |
|
1158 |
This method is going to be removed for protocol compatibility with |
|
1159 |
other STs; use allSubInstancesDo:" |
|
1160 |
||
1161 |
self obsoleteMethodWarning:'please use #allSubInstancesDo:'. |
|
1162 |
self allSubInstancesDo:aBlock |
|
1163 |
||
1164 |
" |
|
1165 |
StandardSystemView allDerivedInstancesDo:[:v | Transcript showCr:(v name)] |
|
1166 |
" |
|
1167 |
! |
|
1168 |
||
1169 |
allInstancesDo:aBlock |
|
1170 |
"evaluate aBlock for all of my instances" |
|
1171 |
||
1172 |
"/ ObjectMemory allObjectsDo:[:anObject | |
|
1173 |
"/ (anObject class == self) ifTrue:[ |
|
1174 |
"/ aBlock value:anObject |
|
1175 |
"/ ] |
|
1176 |
"/ ] |
|
1177 |
||
1178 |
ObjectMemory allInstancesOf:self do:[:anObject | |
|
1179 |
aBlock value:anObject |
|
1180 |
] |
|
1181 |
||
1182 |
" |
|
1183 |
StandardSystemView allInstancesDo:[:v | Transcript showCr:(v name)] |
|
1184 |
" |
|
1185 |
! |
|
1186 |
||
1187 |
allSubInstancesDo:aBlock |
|
1188 |
"evaluate aBlock for all of my instances and all instances of subclasses" |
|
1189 |
||
1190 |
ObjectMemory allObjectsDo:[:anObject | |
|
1191 |
(anObject isKindOf:self) ifTrue:[ |
|
1192 |
aBlock value:anObject |
|
1193 |
] |
|
1194 |
] |
|
1195 |
||
1196 |
" |
|
1197 |
StandardSystemView allSubInstancesDo:[:v | Transcript showCr:(v name)] |
|
1198 |
" |
|
1199 |
! |
|
1200 |
||
1201 |
allSubclassesDo:aBlock |
|
1202 |
"evaluate aBlock for all of my subclasses. |
|
1203 |
There is no specific order, in which the entries are enumerated. |
|
1204 |
This will only enumerate globally known classes - for anonymous |
|
1205 |
behaviors, you have to walk over all instances of Behavior." |
|
1206 |
||
1207 |
Smalltalk allBehaviorsDo:[:aClass | |
|
1208 |
(aClass isSubclassOf:self) ifTrue:[ |
|
1209 |
aBlock value:aClass |
|
1210 |
] |
|
1211 |
] |
|
1212 |
||
1213 |
" |
|
1214 |
Collection allSubclassesDo:[:c | Transcript showCr:(c name)] |
|
1215 |
" |
|
1216 |
! |
|
1217 |
||
1218 |
allSubclassesInOrderDo:aBlock |
|
1219 |
"evaluate aBlock for all of my subclasses. |
|
1220 |
Higher level subclasses will be enumerated before the deeper ones, |
|
1221 |
so the order in which aBlock gets called is ok to fileOut classes in |
|
1222 |
correct order for later fileIn. |
|
1223 |
This will only enumerate globally known classes - for anonymous |
|
1224 |
behaviors, you have to walk over all instances of Behavior" |
|
1225 |
||
1226 |
self subclassesDo:[:aClass | |
|
1227 |
aBlock value:aClass. |
|
1228 |
aClass allSubclassesInOrderDo:aBlock |
|
1229 |
] |
|
1230 |
||
1231 |
" |
|
1232 |
Collection allSubclassesInOrderDo:[:c | Transcript showCr:(c name)] |
|
1233 |
" |
|
1234 |
! |
|
1235 |
||
1236 |
allSuperclassesDo:aBlock |
|
1237 |
"evaluate aBlock for all of my superclasses" |
|
1238 |
||
1239 |
|theClass| |
|
1240 |
||
1241 |
theClass := superclass. |
|
1242 |
[theClass notNil] whileTrue:[ |
|
1243 |
aBlock value:theClass. |
|
1244 |
theClass := theClass superclass |
|
1245 |
] |
|
1246 |
||
1247 |
" |
|
1248 |
String allSuperclassesDo:[:c | Transcript showCr:(c name)] |
|
1249 |
" |
|
1250 |
! |
|
1251 |
||
1252 |
subclassesDo:aBlock |
|
1253 |
"evaluate the argument, aBlock for all immediate subclasses. |
|
1254 |
This will only enumerate globally known classes - for anonymous |
|
1255 |
behaviors, you have to walk over all instances of Behavior." |
|
1256 |
||
1257 |
|coll| |
|
1258 |
||
1259 |
SubclassInfo isNil ifTrue:[ |
|
1260 |
Behavior subclassInfo |
|
1261 |
]. |
|
1262 |
SubclassInfo notNil ifTrue:[ |
|
1263 |
coll := SubclassInfo at:self ifAbsent:nil. |
|
1264 |
coll notNil ifTrue:[ |
|
1265 |
coll do:aBlock. |
|
1266 |
]. |
|
1267 |
^ self |
|
1268 |
]. |
|
1269 |
||
1270 |
Smalltalk allBehaviorsDo:[:aClass | |
|
1271 |
(aClass superclass == self) ifTrue:[ |
|
1272 |
aBlock value:aClass |
|
1273 |
] |
|
1274 |
] |
|
1275 |
||
1276 |
" |
|
1277 |
Collection subclassesDo:[:c | Transcript showCr:(c name)] |
|
308 | 1278 |
" |
1279 |
! ! |
|
1280 |
||
1 | 1281 |
!Behavior methodsFor:'initialization'! |
1282 |
||
620 | 1283 |
deinitialize |
1284 |
"deinitialize is sent to a class before it is physically unloaded. |
|
1285 |
This is only done with classes which have been loaded in from a binary |
|
1286 |
file. Classes may release any primitive memory or other stuff which is |
|
1287 |
not visible to smalltalk (for example, release internal memory). |
|
1288 |
The default action here is to do nothing." |
|
1289 |
||
1290 |
^ self |
|
1291 |
! |
|
1292 |
||
1 | 1293 |
initialize |
442 | 1294 |
"initialize is sent to a class either during startup, |
1295 |
(for all statically compiled-in classes) or after a class |
|
1296 |
has been loaded into the system (either bytecodes or machinecode). |
|
1297 |
The default action here is to do nothing." |
|
1 | 1298 |
|
1299 |
^ self |
|
1300 |
! |
|
1301 |
||
328 | 1302 |
postAutoload |
442 | 1303 |
"postAutoload is sent to a class after it has been autoloaded. |
1304 |
This gives it a chance to arrange for automatic unloading to be done |
|
1305 |
after a while ... |
|
1306 |
This is NOT sent to statically compiled in or explicitely filedIn |
|
1307 |
classes. |
|
1308 |
The default action here is to do nothing." |
|
328 | 1309 |
|
1310 |
^ self |
|
1311 |
! |
|
1312 |
||
1 | 1313 |
reinitialize |
442 | 1314 |
"reinitialize is sent to a class when an image has been restarted. |
1315 |
I.e. when the system is restarted. |
|
1316 |
This gives classes a chance to flush any device dependent or otherwise |
|
1317 |
obsolete data which may be a leftover from the previous live. |
|
1318 |
The default action here is to do nothing." |
|
1319 |
||
1320 |
^ self |
|
11 | 1321 |
! ! |
1322 |
||
492
fa23b14f444b
renamed instance creation category
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
1323 |
!Behavior methodsFor:'instance creation'! |
1 | 1324 |
|
1325 |
basicNew |
|
54 | 1326 |
"return an instance of myself without indexed variables. |
1 | 1327 |
If the receiver-class has indexed instvars, the new object will have |
91 | 1328 |
a basicSize of zero - |
1329 |
i.e. 'aClass basicNew' is equivalent to 'aClass basicNew:0'. |
|
54 | 1330 |
|
1 | 1331 |
** Do not redefine this method in any class **" |
1332 |
||
1333 |
%{ /* NOCONTEXT */ |
|
81 | 1334 |
REGISTER OBJ newobj; |
1335 |
REGISTER char *nextPtr; |
|
91 | 1336 |
unsigned int instsize; |
1337 |
REGISTER unsigned int nInstVars; |
|
369 | 1338 |
extern OBJ __new(); |
1 | 1339 |
|
54 | 1340 |
/* |
369 | 1341 |
* the following ugly code is nothing more than a __new() followed |
54 | 1342 |
* by a nilling of the new instance. |
91 | 1343 |
* Unrolled for a bit more speed since this is one of the central object |
1344 |
* allocation methods in the system |
|
54 | 1345 |
*/ |
1 | 1346 |
nInstVars = _intVal(_INST(instSize)); |
92 | 1347 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
54 | 1348 |
|
77 | 1349 |
newobj = (OBJ) newNextPtr; |
81 | 1350 |
nextPtr = ((char *)newobj) + instsize; |
1351 |
||
1352 |
/* |
|
1353 |
* dont argue about the goto and the arrangement below - it saves |
|
1354 |
* an extra nil-compare and branch in the common case ... |
|
91 | 1355 |
* (i.e. if no GC is needed, we fall through without a branch) |
81 | 1356 |
*/ |
82 | 1357 |
if (nextPtr < newEndPtr) { |
154 | 1358 |
_objPtr(newobj)->o_size = instsize; |
1359 |
/* o_allFlags(newobj) = 0; */ |
|
1360 |
/* _objPtr(newobj)->o_space = newSpace; */ |
|
1361 |
o_setAllFlags(newobj, newSpace); |
|
91 | 1362 |
#ifdef ALIGN4 |
154 | 1363 |
newNextPtr = nextPtr; |
91 | 1364 |
#else |
154 | 1365 |
if (instsize & (ALIGN-1)) { |
1366 |
newNextPtr = (char *)newobj + (instsize & ~(ALIGN-1)) + ALIGN; |
|
1367 |
} else { |
|
1368 |
newNextPtr = nextPtr; |
|
1369 |
} |
|
91 | 1370 |
#endif |
82 | 1371 |
|
1372 |
ok: |
|
154 | 1373 |
_InstPtr(newobj)->o_class = self; |
369 | 1374 |
__qSTORE(newobj, self); |
82 | 1375 |
|
154 | 1376 |
if (nInstVars) { |
357 | 1377 |
#if defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4) |
154 | 1378 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars); |
82 | 1379 |
#else |
154 | 1380 |
REGISTER OBJ *op; |
82 | 1381 |
|
154 | 1382 |
op = _InstPtr(newobj)->i_instvars; |
82 | 1383 |
|
91 | 1384 |
# if !defined(NEGATIVE_ADDRESSES) |
154 | 1385 |
/* |
1386 |
* knowing that nil is 0 |
|
1387 |
*/ |
|
91 | 1388 |
# if defined(FAST_OBJECT_MEMSET_DOUBLES_UNROLLED) |
154 | 1389 |
if (nInstVars > 8) { |
1390 |
*op++ = nil; /* for alignment */ |
|
1391 |
nInstVars--; |
|
1392 |
while (nInstVars >= 8) { |
|
1393 |
*(double *)op = 0.0; |
|
1394 |
((double *)op)[1] = 0.0; |
|
1395 |
((double *)op)[2] = 0.0; |
|
1396 |
((double *)op)[3] = 0.0; |
|
1397 |
op += 8; |
|
1398 |
nInstVars -= 8; |
|
1399 |
} |
|
1400 |
} |
|
1401 |
while (nInstVars != 0) { |
|
1402 |
*op++ = 0; |
|
1403 |
nInstVars--; |
|
1404 |
} |
|
82 | 1405 |
# else |
91 | 1406 |
# if defined(FAST_OBJECT_MEMSET_LONGLONG_UNROLLED) |
154 | 1407 |
if (nInstVars > 8) { |
1408 |
*op++ = nil; /* for alignment */ |
|
1409 |
nInstVars--; |
|
1410 |
while (nInstVars >= 8) { |
|
1411 |
*(long long *)op = 0; |
|
1412 |
((long long *)op)[1] = 0; |
|
1413 |
((long long *)op)[2] = 0; |
|
1414 |
((long long *)op)[3] = 0; |
|
1415 |
op += 8; |
|
1416 |
nInstVars -= 8; |
|
1417 |
} |
|
1418 |
} |
|
1419 |
while (nInstVars != 0) { |
|
1420 |
*op++ = 0; |
|
1421 |
nInstVars--; |
|
1422 |
} |
|
91 | 1423 |
|
1424 |
# else |
|
1425 |
# if defined(FAST_OBJECT_MEMSET_WORDS_UNROLLED) |
|
154 | 1426 |
while (nInstVars >= 8) { |
1427 |
*op = nil; |
|
1428 |
*(op+1) = nil; |
|
1429 |
*(op+2) = nil; |
|
1430 |
*(op+3) = nil; |
|
1431 |
*(op+4) = nil; |
|
1432 |
*(op+5) = nil; |
|
1433 |
*(op+6) = nil; |
|
1434 |
*(op+7) = nil; |
|
1435 |
op += 8; |
|
1436 |
nInstVars -= 8; |
|
1437 |
} |
|
1438 |
while (nInstVars != 0) { |
|
1439 |
*op++ = nil; |
|
1440 |
nInstVars--; |
|
1441 |
} |
|
91 | 1442 |
# else |
1443 |
# if defined(FAST_MEMSET) |
|
154 | 1444 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE); |
91 | 1445 |
# else |
154 | 1446 |
do { |
1447 |
*op++ = nil; |
|
1448 |
nInstVars--; |
|
1449 |
} while (nInstVars != 0); |
|
91 | 1450 |
# endif |
82 | 1451 |
# endif |
1452 |
# endif |
|
1453 |
# endif |
|
1454 |
# else /* nil could be ~~ 0 */ |
|
154 | 1455 |
while (nInstVars >= 8) { |
1456 |
*op = nil; |
|
1457 |
*(op+1) = nil; |
|
1458 |
*(op+2) = nil; |
|
1459 |
*(op+3) = nil; |
|
1460 |
*(op+4) = nil; |
|
1461 |
*(op+5) = nil; |
|
1462 |
*(op+6) = nil; |
|
1463 |
*(op+7) = nil; |
|
1464 |
op += 8; |
|
1465 |
nInstVars -= 8; |
|
1466 |
} |
|
1467 |
while (nInstVars != 0) { |
|
1468 |
*op++ = nil; |
|
1469 |
nInstVars--; |
|
1470 |
} |
|
82 | 1471 |
# endif |
1472 |
#endif |
|
154 | 1473 |
} |
1474 |
RETURN ( newobj ); |
|
81 | 1475 |
} |
54 | 1476 |
|
92 | 1477 |
/* |
1478 |
* the slow case - a GC will occur |
|
1479 |
*/ |
|
82 | 1480 |
PROTECT_CONTEXT |
369 | 1481 |
newobj = __new(instsize); |
82 | 1482 |
UNPROTECT_CONTEXT |
1483 |
if (newobj != nil) goto ok; |
|
1 | 1484 |
%} |
2 | 1485 |
. |
68 | 1486 |
" |
1487 |
memory allocation failed. |
|
1488 |
When we arrive here, there was no memory, even after |
|
165 | 1489 |
a garbage collect. |
1490 |
This means, that the VM wanted to get some more memory from the |
|
1491 |
Operatingsystem, which was not kind enough to give it. |
|
1492 |
Bad luck - you should increase the swap space on your machine. |
|
68 | 1493 |
" |
127 | 1494 |
^ ObjectMemory allocationFailureSignal raise. |
1 | 1495 |
! |
1496 |
||
1497 |
basicNew:anInteger |
|
1498 |
"return an instance of myself with anInteger indexed variables. |
|
1499 |
If the receiver-class has no indexed instvars, this is only allowed |
|
1500 |
if the argument, anInteger is zero. |
|
1501 |
** Do not redefine this method in any class **" |
|
1502 |
||
1503 |
%{ /* NOCONTEXT */ |
|
1504 |
||
1505 |
OBJ newobj; |
|
154 | 1506 |
unsigned INT instsize, nInstVars; |
1507 |
INT nindexedinstvars; |
|
92 | 1508 |
unsigned INT flags; |
1509 |
#if ! defined(FAST_ARRAY_MEMSET) || defined(NEGATIVE_ADDRESSES) |
|
1 | 1510 |
REGISTER char *cp; |
1511 |
short *sp; |
|
1512 |
long *lp; |
|
1513 |
#endif |
|
1514 |
REGISTER OBJ *op; |
|
1515 |
float *fp; |
|
1516 |
double *dp; |
|
1517 |
||
249 | 1518 |
if (__isSmallInteger(anInteger)) { |
154 | 1519 |
nindexedinstvars = _intVal(anInteger); |
1520 |
if (nindexedinstvars >= 0) { |
|
1521 |
nInstVars = _intVal(_INST(instSize)); |
|
1522 |
flags = _intVal(_INST(flags)) & ARRAYMASK; |
|
1523 |
switch (flags) { |
|
1524 |
case BYTEARRAY: |
|
1525 |
instsize = OHDR_SIZE + nindexedinstvars; |
|
1526 |
if (nInstVars == 0) { |
|
1527 |
if (_CanDoQuickNew(instsize)) { |
|
1528 |
/* |
|
1529 |
* the most common case |
|
1530 |
*/ |
|
1531 |
_qCheckedNew(newobj, instsize); |
|
1532 |
_InstPtr(newobj)->o_class = self; |
|
357 | 1533 |
#if defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
359 | 1534 |
nInstVars = nindexedinstvars >> 2; |
1535 |
if (nindexedinstvars & 3) nInstVars++; |
|
1536 |
memset4(_InstPtr(newobj)->i_instvars, 0, nInstVars); |
|
357 | 1537 |
#else |
1538 |
# if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
|
154 | 1539 |
memset(_InstPtr(newobj)->i_instvars, 0, nindexedinstvars); |
357 | 1540 |
# else |
154 | 1541 |
cp = (char *)_InstPtr(newobj)->i_instvars; |
1542 |
while (nindexedinstvars >= sizeof(long)) { |
|
1543 |
*(long *)cp = 0; |
|
1544 |
cp += sizeof(long); |
|
1545 |
nindexedinstvars -= sizeof(long); |
|
1546 |
} |
|
1547 |
while (nindexedinstvars--) |
|
1548 |
*cp++ = '\0'; |
|
357 | 1549 |
# endif |
92 | 1550 |
#endif |
154 | 1551 |
RETURN ( newobj ); |
1552 |
} |
|
1553 |
} else { |
|
1554 |
instsize += __OBJS2BYTES__(nInstVars); |
|
1555 |
} |
|
1556 |
PROTECT_CONTEXT |
|
1557 |
_qNew(newobj, instsize, SENDER); |
|
1558 |
UNPROTECT_CONTEXT |
|
1559 |
if (newobj == nil) { |
|
1560 |
break; |
|
1561 |
} |
|
1562 |
_InstPtr(newobj)->o_class = self; |
|
369 | 1563 |
__qSTORE(newobj, self); |
1564 |
||
357 | 1565 |
#if defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
1566 |
nInstVars = (instsize-OHDR_SIZE) >> 2; |
|
1567 |
if (instsize & 3) nInstVars++; |
|
1568 |
memset4(_InstPtr(newobj)->i_instvars, 0, nInstVars); |
|
1569 |
#else |
|
1570 |
# if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
|
154 | 1571 |
/* |
1572 |
* knowing that nil is 0 |
|
1573 |
*/ |
|
1574 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE); |
|
357 | 1575 |
# else |
154 | 1576 |
op = _InstPtr(newobj)->i_instvars; |
1577 |
while (nInstVars--) |
|
1578 |
*op++ = nil; |
|
1579 |
cp = (char *)op; |
|
1580 |
while (nindexedinstvars >= sizeof(long)) { |
|
1581 |
*(long *)cp = 0; |
|
1582 |
cp += sizeof(long); |
|
1583 |
nindexedinstvars -= sizeof(long); |
|
1584 |
} |
|
1585 |
while (nindexedinstvars--) |
|
1586 |
*cp++ = '\0'; |
|
357 | 1587 |
# endif |
1 | 1588 |
#endif |
154 | 1589 |
RETURN ( newobj ); |
1590 |
break; |
|
1 | 1591 |
|
154 | 1592 |
case WORDARRAY: |
1593 |
instsize = OHDR_SIZE + |
|
1594 |
__OBJS2BYTES__(nInstVars) + |
|
1595 |
nindexedinstvars * sizeof(short); |
|
1596 |
PROTECT_CONTEXT |
|
1597 |
_qNew(newobj, instsize, SENDER); |
|
1598 |
UNPROTECT_CONTEXT |
|
1599 |
if (newobj == nil) { |
|
1600 |
break; |
|
1601 |
} |
|
1602 |
_InstPtr(newobj)->o_class = self; |
|
369 | 1603 |
__qSTORE(newobj, self); |
1604 |
||
92 | 1605 |
#if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
154 | 1606 |
/* |
1607 |
* knowing that nil is 0 |
|
1608 |
*/ |
|
1609 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
1 | 1610 |
#else |
154 | 1611 |
op = _InstPtr(newobj)->i_instvars; |
1612 |
while (nInstVars--) |
|
1613 |
*op++ = nil; |
|
1614 |
sp = (short *)op; |
|
1615 |
while (nindexedinstvars--) |
|
1616 |
*sp++ = 0; |
|
1 | 1617 |
#endif |
154 | 1618 |
RETURN ( newobj ); |
1619 |
break; |
|
1 | 1620 |
|
154 | 1621 |
case LONGARRAY: |
1622 |
instsize = OHDR_SIZE + |
|
1623 |
__OBJS2BYTES__(nInstVars) + |
|
1624 |
nindexedinstvars * sizeof(long); |
|
1625 |
PROTECT_CONTEXT |
|
1626 |
_qAlignedNew(newobj, instsize, SENDER); |
|
1627 |
UNPROTECT_CONTEXT |
|
1628 |
if (newobj == nil) { |
|
1629 |
break; |
|
1630 |
} |
|
1631 |
_InstPtr(newobj)->o_class = self; |
|
369 | 1632 |
__qSTORE(newobj, self); |
1633 |
||
357 | 1634 |
#if defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
154 | 1635 |
/* |
1636 |
* knowing that nil is 0 |
|
1637 |
*/ |
|
1638 |
memset4(_InstPtr(newobj)->i_instvars, 0, nInstVars + nindexedinstvars); |
|
1 | 1639 |
#else |
92 | 1640 |
# if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
154 | 1641 |
/* |
1642 |
* knowing that nil is 0 |
|
1643 |
*/ |
|
1644 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
1 | 1645 |
# else |
154 | 1646 |
op = _InstPtr(newobj)->i_instvars; |
1647 |
while (nInstVars--) |
|
1648 |
*op++ = nil; |
|
1649 |
lp = (long *)op; |
|
1650 |
while (nindexedinstvars--) |
|
1651 |
*lp++ = 0; |
|
1 | 1652 |
# endif |
1653 |
#endif |
|
154 | 1654 |
RETURN ( newobj ); |
1655 |
break; |
|
1 | 1656 |
|
154 | 1657 |
case FLOATARRAY: |
325 | 1658 |
instsize = sizeof(struct __floatArray) + |
154 | 1659 |
__OBJS2BYTES__(nInstVars) + |
1660 |
(nindexedinstvars - 1) * sizeof(float); |
|
54 | 1661 |
|
154 | 1662 |
PROTECT_CONTEXT |
1663 |
_qNew(newobj, instsize, SENDER); |
|
1664 |
UNPROTECT_CONTEXT |
|
1665 |
if (newobj == nil) { |
|
1666 |
break; |
|
1667 |
} |
|
1668 |
_InstPtr(newobj)->o_class = self; |
|
369 | 1669 |
__qSTORE(newobj, self); |
1670 |
||
154 | 1671 |
op = _InstPtr(newobj)->i_instvars; |
92 | 1672 |
# if defined(mips) /* knowin that float 0.0 is all-zeros */ |
154 | 1673 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
92 | 1674 |
# else |
154 | 1675 |
while (nInstVars--) |
1676 |
*op++ = nil; |
|
1677 |
fp = (float *)op; |
|
1678 |
while (nindexedinstvars--) |
|
1679 |
*fp++ = 0.0; |
|
92 | 1680 |
# endif |
154 | 1681 |
RETURN ( newobj ); |
1682 |
break; |
|
1 | 1683 |
|
154 | 1684 |
case DOUBLEARRAY: |
325 | 1685 |
instsize = sizeof(struct __doubleArray) + |
154 | 1686 |
__OBJS2BYTES__(nInstVars) + |
1687 |
(nindexedinstvars - 1) * sizeof(double); |
|
54 | 1688 |
|
154 | 1689 |
PROTECT_CONTEXT |
1690 |
_qAlignedNew(newobj, instsize, SENDER); |
|
1691 |
UNPROTECT_CONTEXT |
|
1692 |
if (newobj == nil) { |
|
1693 |
break; |
|
1694 |
} |
|
1695 |
_InstPtr(newobj)->o_class = self; |
|
369 | 1696 |
__qSTORE(newobj, self); |
1697 |
||
154 | 1698 |
op = _InstPtr(newobj)->i_instvars; |
1699 |
while (nInstVars--) |
|
1700 |
*op++ = nil; |
|
54 | 1701 |
#ifdef NEED_DOUBLE_ALIGN |
154 | 1702 |
/* |
1703 |
* care for double alignment |
|
1704 |
*/ |
|
1705 |
if ((INT)op & (ALIGN-1)) { |
|
1706 |
*op++ = nil; |
|
1707 |
} |
|
54 | 1708 |
#endif |
154 | 1709 |
dp = (double *)op; |
1710 |
while (nindexedinstvars--) |
|
1711 |
*dp++ = 0.0; |
|
1712 |
RETURN ( newobj ); |
|
1713 |
break; |
|
1 | 1714 |
|
154 | 1715 |
case WKPOINTERARRAY: |
1716 |
case POINTERARRAY: |
|
1717 |
nInstVars += nindexedinstvars; |
|
1718 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
1719 |
PROTECT_CONTEXT |
|
1720 |
_qAlignedNew(newobj, instsize, SENDER); |
|
1721 |
UNPROTECT_CONTEXT |
|
1722 |
if (newobj == nil) { |
|
1723 |
break; |
|
1724 |
} |
|
1725 |
_InstPtr(newobj)->o_class = self; |
|
369 | 1726 |
__qSTORE(newobj, self); |
1727 |
||
357 | 1728 |
#if defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
154 | 1729 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars); |
1 | 1730 |
#else |
82 | 1731 |
# if !defined(NEGATIVE_ADDRESSES) |
154 | 1732 |
/* |
1733 |
* knowing that nil is 0 |
|
1734 |
*/ |
|
360 | 1735 |
#ifdef XXmips |
92 | 1736 |
# undef FAST_ARRAY_MEMSET_DOUBLES_UNROLLED |
1737 |
# undef FAST_ARRAY_MEMSET_LONGLONG_UNROLLED |
|
198 | 1738 |
/* seems to be slightly faster */ |
92 | 1739 |
# define FAST_ARRAY_MEMSET |
1740 |
#endif |
|
1741 |
#ifdef sparc |
|
1742 |
# define FAST_ARRAY_MEMSET_DOUBLES_UNROLLED |
|
1743 |
#endif |
|
1744 |
||
91 | 1745 |
# if defined(FAST_ARRAY_MEMSET_DOUBLES_UNROLLED) |
154 | 1746 |
op = _InstPtr(newobj)->i_instvars; |
1747 |
if (nInstVars > 8) { |
|
1748 |
*op++ = nil; /* for alignment */ |
|
1749 |
nInstVars--; |
|
1750 |
while (nInstVars >= 8) { |
|
1751 |
*(double *)op = 0.0; |
|
1752 |
((double *)op)[1] = 0.0; |
|
1753 |
((double *)op)[2] = 0.0; |
|
1754 |
((double *)op)[3] = 0.0; |
|
1755 |
op += 8; |
|
1756 |
nInstVars -= 8; |
|
1757 |
} |
|
1758 |
} |
|
1759 |
while (nInstVars) { |
|
1760 |
*op++ = 0; |
|
1761 |
nInstVars--; |
|
1762 |
} |
|
82 | 1763 |
# else |
91 | 1764 |
# if defined(FAST_ARRAY_MEMSET_LONGLONG_UNROLLED) |
154 | 1765 |
op = _InstPtr(newobj)->i_instvars; |
1766 |
if (nInstVars > 8) { |
|
1767 |
*op++ = nil; /* for alignment */ |
|
1768 |
nInstVars--; |
|
1769 |
while (nInstVars >= 8) { |
|
1770 |
*(long long *)op = 0; |
|
1771 |
((long long *)op)[1] = 0; |
|
1772 |
((long long *)op)[2] = 0; |
|
1773 |
((long long *)op)[3] = 0; |
|
1774 |
op += 8; |
|
1775 |
nInstVars -= 8; |
|
1776 |
} |
|
1777 |
} |
|
1778 |
while (nInstVars) { |
|
1779 |
*op++ = 0; |
|
1780 |
nInstVars--; |
|
1781 |
} |
|
91 | 1782 |
# else |
1783 |
# if defined(FAST_ARRAY_MEMSET) |
|
154 | 1784 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
91 | 1785 |
# else |
154 | 1786 |
op = _InstPtr(newobj)->i_instvars; |
1787 |
while (nInstVars--) |
|
1788 |
*op++ = nil; |
|
91 | 1789 |
# endif |
82 | 1790 |
# endif |
1791 |
# endif |
|
1792 |
# else |
|
154 | 1793 |
op = _InstPtr(newobj)->i_instvars; |
1794 |
while (nInstVars--) |
|
1795 |
*op++ = nil; |
|
1 | 1796 |
# endif |
1797 |
#endif |
|
154 | 1798 |
RETURN ( newobj ); |
1799 |
break; |
|
1 | 1800 |
|
154 | 1801 |
default: |
1802 |
/* |
|
1803 |
* new:n for non-variable classes only allowed if |
|
1804 |
* n == 0 |
|
1805 |
*/ |
|
1806 |
if (nindexedinstvars == 0) { |
|
1807 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
1808 |
PROTECT_CONTEXT |
|
1809 |
_qAlignedNew(newobj, instsize, SENDER); |
|
1810 |
UNPROTECT_CONTEXT |
|
1811 |
if (newobj == nil) { |
|
1812 |
break; |
|
1813 |
} |
|
1814 |
_InstPtr(newobj)->o_class = self; |
|
369 | 1815 |
__qSTORE(newobj, self); |
1816 |
||
154 | 1817 |
if (nInstVars) { |
357 | 1818 |
#if defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4) |
154 | 1819 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars); |
1 | 1820 |
#else |
1821 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
|
154 | 1822 |
/* |
1823 |
* knowing that nil is 0 |
|
1824 |
*/ |
|
1825 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
1 | 1826 |
# else |
154 | 1827 |
op = _InstPtr(newobj)->i_instvars; |
1828 |
do { |
|
1829 |
*op++ = nil; |
|
1830 |
} while (--nInstVars); |
|
1 | 1831 |
# endif |
1832 |
#endif |
|
154 | 1833 |
} |
1834 |
RETURN ( newobj ); |
|
1835 |
} |
|
1836 |
break; |
|
1837 |
} |
|
1838 |
} |
|
1 | 1839 |
} |
68 | 1840 |
%}. |
1841 |
" |
|
1842 |
arrive here if something went wrong ... |
|
1843 |
figure out what it was |
|
1844 |
" |
|
11 | 1845 |
|
1 | 1846 |
(anInteger isMemberOf:SmallInteger) ifFalse:[ |
154 | 1847 |
" |
1848 |
the argument is either not an integer, |
|
1849 |
or a LargeInteger (which means that its definitely too big) |
|
1850 |
" |
|
1851 |
self error:'argument to new: must be Integer'. |
|
1852 |
^ nil |
|
68 | 1853 |
]. |
1854 |
(anInteger < 0) ifTrue:[ |
|
154 | 1855 |
" |
1856 |
the argument is negative, |
|
1857 |
" |
|
1858 |
self error:'bad (negative) argument to new:'. |
|
1859 |
^ nil |
|
68 | 1860 |
]. |
1861 |
self isVariable ifFalse:[ |
|
154 | 1862 |
" |
1863 |
this class does not have any indexed instance variables |
|
1864 |
" |
|
1865 |
self error:'class has no indexed instvars - cannot create with new:'. |
|
1866 |
^ nil |
|
68 | 1867 |
]. |
1868 |
" |
|
1869 |
memory allocation failed. |
|
1870 |
When we arrive here, there was no memory, even after |
|
165 | 1871 |
a garbage collect. |
1872 |
This means, that the VM wanted to get some more memory from the |
|
1873 |
Operatingsystem, which was not kind enough to give it. |
|
1874 |
Bad luck - you should increase the swap space on your machine. |
|
68 | 1875 |
" |
127 | 1876 |
^ ObjectMemory allocationFailureSignal raise. |
11 | 1877 |
! |
1878 |
||
620 | 1879 |
new |
1880 |
"return an instance of myself without indexed variables" |
|
1881 |
||
1882 |
^ self basicNew |
|
1883 |
! |
|
1884 |
||
1885 |
new:anInteger |
|
1886 |
"return an instance of myself with anInteger indexed variables" |
|
1887 |
||
1888 |
^ self basicNew:anInteger |
|
1889 |
! |
|
1890 |
||
1891 |
niceBasicNew:anInteger |
|
1892 |
"same as basicNew:anInteger, but tries to avoid long pauses |
|
1893 |
due to garbage collection. This method checks to see if |
|
1894 |
allocation is possible without a pause, and does a background |
|
1895 |
incremental garbage collect first if there is not enough memory |
|
1896 |
available at the moment for fast allocation. |
|
1897 |
This is useful in low-priority background processes which like to |
|
1898 |
avoid disturbing any higher priority foreground process while allocating |
|
1899 |
big amounts of memory. Of course, using this method only makes |
|
1900 |
sense for big or huge objects (say > 200k). |
|
1901 |
||
1902 |
EXPERIMENTAL: this is a non-standard interface and should only |
|
1903 |
be used for special applications. There is no guarantee, that this |
|
1904 |
method will be available in future ST/X releases." |
|
1905 |
||
1906 |
|size| |
|
1907 |
||
1908 |
size := self sizeOfInst:anInteger. |
|
1909 |
(ObjectMemory checkForFastNew:size) ifFalse:[ |
|
1910 |
" |
|
1911 |
incrementally collect garbage |
|
1912 |
" |
|
1913 |
ObjectMemory incrementalGC. |
|
1914 |
]. |
|
1915 |
^ self basicNew:anInteger |
|
1916 |
! |
|
1917 |
||
11 | 1918 |
readFrom:aStream |
43 | 1919 |
"read an objects printed representation from the argument, aStream |
1920 |
and return it. |
|
154 | 1921 |
The read object must be a kind of myself if its not, an error is raised. |
11 | 1922 |
This is the reverse operation to 'storeOn:'. |
43 | 1923 |
|
68 | 1924 |
WARNING: storeOn: does not handle circular references and multiple |
198 | 1925 |
references to the same object. |
1926 |
Use #storeBinary:/readBinaryFrom: for this." |
|
11 | 1927 |
|
345 | 1928 |
^ self readFrom:aStream onError:[self error:'expected: ' , self name] |
11 | 1929 |
|
91 | 1930 |
" |
1931 |
|s| |
|
11 | 1932 |
s := WriteStream on:String new. |
1933 |
#(1 2 3 4) storeOn:s. |
|
1934 |
Object readFrom:(ReadStream on:s contents) |
|
1935 |
" |
|
1936 |
! |
|
1937 |
||
198 | 1938 |
readFrom:aStream onError:exceptionBlock |
1939 |
"read an objects printed representation from the argument, aStream |
|
1940 |
and return it (i.e. the stream should contain some representation of |
|
1941 |
the object which was created using #storeOn:). |
|
1942 |
The read object must be a kind of myself if its not, the value of |
|
1943 |
exceptionBlock is returned. |
|
1944 |
To get any object, use 'Object readFrom:...', |
|
1945 |
To get any number, use 'Number readFrom:...' and so on. |
|
1946 |
This is the reverse operation to 'storeOn:'. |
|
1947 |
||
1948 |
WARNING: storeOn: does not handle circular references and multiple |
|
1949 |
references to the same object. |
|
1950 |
Use #storeBinary:/readBinaryFrom: for this." |
|
1951 |
||
1952 |
|newObject| |
|
1953 |
||
340 | 1954 |
ErrorSignal handle:[:ex | |
1955 |
ex return |
|
1956 |
] do:[ |
|
345 | 1957 |
newObject := self evaluatorClass evaluate:aStream. |
340 | 1958 |
]. |
198 | 1959 |
(newObject isKindOf:self) ifFalse:[^ exceptionBlock value]. |
1960 |
^ newObject |
|
1961 |
||
1962 |
" |
|
1963 |
|s| |
|
1964 |
s := WriteStream on:String new. |
|
1965 |
#(1 2 3 4) storeOn:s. |
|
293 | 1966 |
Transcript showCr:( |
1967 |
Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
|
1968 |
) |
|
198 | 1969 |
" |
1970 |
" |
|
1971 |
|s| |
|
1972 |
s := WriteStream on:String new. |
|
1973 |
#[1 2 3 4] storeOn:s. |
|
293 | 1974 |
Transcript showCr:( |
1975 |
Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
|
345 | 1976 |
) |
198 | 1977 |
" |
1978 |
! |
|
1979 |
||
11 | 1980 |
readFromString:aString |
275 | 1981 |
"create an object from its printed representation. |
1982 |
For most classes, the string is expected to be in a format created by |
|
1983 |
storeOn: or storeString; however, some (Time, Date) expect a user |
|
1984 |
readable string here. |
|
1985 |
See comments in Behavior>>readFromString:onError:, |
|
1986 |
Behavior>>readFrom: and Behavior>>readFrom:onError:" |
|
11 | 1987 |
|
345 | 1988 |
^ self readFromString:aString onError:[self error:'expected: ' , self name] |
91 | 1989 |
|
1990 |
" |
|
1991 |
Integer readFromString:'12345678901234567890' |
|
1992 |
Point readFromString:'1@2' |
|
345 | 1993 |
Point readFromString:'1' |
91 | 1994 |
" |
198 | 1995 |
! |
1996 |
||
1997 |
readFromString:aString onError:exceptionBlock |
|
275 | 1998 |
"create an object from its printed representation. |
1999 |
Here, the string is expected to be in a format created by |
|
2000 |
storeOn: or storeString; however, some classes (Time, Date) may redefine |
|
2001 |
it to expect a user readable string here. |
|
198 | 2002 |
See comments in Behavior>>readFrom: and Behavior>>readFrom:onError:" |
2003 |
||
2004 |
^ self readFrom:(ReadStream on:aString) onError:exceptionBlock |
|
2005 |
||
2006 |
" |
|
2007 |
Integer readFromString:'12345678901234567890' |
|
275 | 2008 |
Integer readFromString:'abc' |
2009 |
Integer readFromString:'abc' onError:0 |
|
198 | 2010 |
Point readFromString:'1@2' |
345 | 2011 |
Point readFromString:'0' |
275 | 2012 |
Point readFromString:'0' onError:[0@0] |
198 | 2013 |
" |
620 | 2014 |
! |
2015 |
||
2016 |
uninitializedNew |
|
2017 |
"create an instance of myself with uninitialized contents. |
|
2018 |
For all classes except ByteArray, this is the same as #basicNew." |
|
2019 |
||
2020 |
^ self basicNew |
|
2021 |
! |
|
2022 |
||
2023 |
uninitializedNew:anInteger |
|
2024 |
"create an instance of myself with uninitialized contents. |
|
2025 |
For all classes except ByteArray, this is the same as #basicNew:." |
|
2026 |
||
2027 |
^ self basicNew:anInteger |
|
1 | 2028 |
! ! |
2029 |
||
620 | 2030 |
!Behavior methodsFor:'private accessing'! |
2031 |
||
2032 |
flags:aNumber |
|
2033 |
"set the flags. |
|
2034 |
this method is for special uses only - there will be no recompilation |
|
2035 |
and no change record written here; |
|
2036 |
Do NOT use it." |
|
2037 |
||
2038 |
flags := aNumber |
|
2039 |
! |
|
2040 |
||
2041 |
instSize:aNumber |
|
2042 |
"set the instance size. |
|
2043 |
this method is for special uses only - there will be no recompilation |
|
2044 |
and no change record written here; |
|
2045 |
Do NOT use it." |
|
2046 |
||
2047 |
instSize := aNumber |
|
2048 |
! |
|
2049 |
||
2050 |
primAddSelector:newSelector withMethod:newMethod |
|
2051 |
"add the method given by 2nd argument under the selector given by |
|
2052 |
the 1st argument to the methodDictionary. |
|
2053 |
Does NOT flush any caches, does NOT write a change record. |
|
2054 |
||
2055 |
Do not use this in normal situations, strange behavior will be |
|
2056 |
the consequence. |
|
2057 |
I.e. executing obsolete methods, since the old method will still |
|
2058 |
be executed out of the caches." |
|
2059 |
||
2060 |
|index oldSelectorArray oldMethodArray newSelectorArray newMethodArray| |
|
2061 |
||
2062 |
(newSelector isMemberOf:Symbol) ifFalse:[ |
|
2063 |
self error:'invalid selector'. |
|
2064 |
^ false |
|
2065 |
]. |
|
2066 |
newMethod isNil ifTrue:[ |
|
2067 |
self error:'invalid method'. |
|
2068 |
^ false |
|
2069 |
]. |
|
2070 |
||
2071 |
index := selectorArray identityIndexOf:newSelector startingAt:1. |
|
2072 |
(index == 0) ifTrue:[ |
|
2073 |
" |
|
2074 |
a new selector |
|
2075 |
" |
|
2076 |
newSelectorArray := selectorArray copyWith:newSelector. |
|
2077 |
newMethodArray := methodArray copyWith:newMethod. |
|
2078 |
" |
|
2079 |
keep a reference so they wont go away ... |
|
2080 |
mhmh: this is no longer needed - try without |
|
2081 |
" |
|
2082 |
oldSelectorArray := selectorArray. |
|
2083 |
oldMethodArray := methodArray. |
|
2084 |
selectorArray := newSelectorArray. |
|
2085 |
methodArray := newMethodArray |
|
2086 |
] ifFalse:[ |
|
2087 |
methodArray at:index put:newMethod |
|
2088 |
]. |
|
2089 |
^ true |
|
2090 |
! |
|
2091 |
||
2092 |
setMethodArray:anArray |
|
2093 |
"set the method array of the receiver. |
|
2094 |
this method is for special uses only - there will be no recompilation |
|
2095 |
and no change record written here. |
|
2096 |
NOT for general use." |
|
2097 |
||
2098 |
methodArray := anArray |
|
2099 |
! |
|
2100 |
||
2101 |
setMethodDictionary:aDictionary |
|
2102 |
"set the receivers method dictionary. |
|
2103 |
Since no dictionary is actually used, decompose into selector- and |
|
2104 |
method arrays and set those. For ST-80 compatibility. |
|
2105 |
NOT for general use." |
|
2106 |
||
2107 |
|n newSelectorArray newMethodArray idx| |
|
2108 |
||
2109 |
n := aDictionary size. |
|
2110 |
newSelectorArray := Array basicNew:n. |
|
2111 |
newMethodArray := Array basicNew:n. |
|
2112 |
idx := 1. |
|
2113 |
aDictionary keysAndValuesDo:[:sel :method | |
|
2114 |
newSelectorArray at:idx put:sel. |
|
2115 |
newMethodArray at:idx put:method. |
|
2116 |
idx := idx + 1 |
|
2117 |
]. |
|
2118 |
selectorArray := newSelectorArray. |
|
2119 |
methodArray := newMethodArray |
|
2120 |
! |
|
2121 |
||
2122 |
setOtherSuperclasses:anArrayOfClasses |
|
2123 |
"EXPERIMENTAL: set the other superclasses of the receiver. |
|
2124 |
this method is for special uses only - there will be no recompilation |
|
2125 |
and no change record written here; |
|
2126 |
Do NOT use it." |
|
2127 |
||
2128 |
SubclassInfo := nil. |
|
2129 |
otherSuperclasses := anArrayOfClasses |
|
2130 |
! |
|
2131 |
||
2132 |
setSelectorArray:anArray |
|
2133 |
"set the selector array of the receiver. |
|
2134 |
this method is for special uses only - there will be no recompilation |
|
2135 |
and no change record written here. |
|
2136 |
NOT for general use." |
|
2137 |
||
2138 |
selectorArray := anArray |
|
2139 |
! |
|
2140 |
||
2141 |
setSelectors:sels methods:m |
|
2142 |
"set some inst vars. |
|
2143 |
this method is for special uses only - there will be no recompilation |
|
2144 |
and no change record written here; |
|
2145 |
Do NOT use it." |
|
2146 |
||
2147 |
selectorArray := sels. |
|
2148 |
methodArray := m. |
|
2149 |
! |
|
2150 |
||
2151 |
setSuperclass:aClass |
|
2152 |
"set the superclass of the receiver. |
|
2153 |
this method is for special uses only - there will be no recompilation |
|
2154 |
and no change record written here. Also, if the receiver class has |
|
2155 |
already been in use, future operation of the system is not guaranteed to |
|
2156 |
be correct, since no caches are flushed. |
|
2157 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)" |
|
2158 |
||
2159 |
SubclassInfo := nil. |
|
2160 |
superclass := aClass |
|
2161 |
! |
|
2162 |
||
2163 |
setSuperclass:sup selectors:sels methods:m instSize:i flags:f |
|
2164 |
"set some inst vars. |
|
2165 |
this method is for special uses only - there will be no recompilation |
|
2166 |
and no change record is written here. Also, if the receiver class has |
|
2167 |
already been in use, future operation of the system is not guaranteed to |
|
2168 |
be correct, since no caches are flushed. |
|
2169 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)" |
|
2170 |
||
2171 |
SubclassInfo := nil. |
|
2172 |
superclass := sup. |
|
2173 |
selectorArray := sels. |
|
2174 |
methodArray := m. |
|
2175 |
instSize := i. |
|
2176 |
flags := f |
|
2177 |
! ! |
|
2178 |
||
2179 |
!Behavior methodsFor:'queries'! |
|
2180 |
||
2181 |
allClassVarNames |
|
2182 |
"return a collection of all the class variable name-strings |
|
2183 |
this includes all superclass-class variables. |
|
2184 |
Since Behavior has no idea of classvar-names, return an empty collection |
|
2185 |
here. Redefined in ClassDescription." |
|
2186 |
||
2187 |
^ #() |
|
2188 |
! |
|
2189 |
||
2190 |
allDerivedInstances |
|
2191 |
"return a collection of all instances of myself and |
|
2192 |
instances of all subclasses of myself. |
|
2193 |
This method is going to be removed for protocol compatibility with |
|
2194 |
other STs; use allSubInstances" |
|
2195 |
||
2196 |
self obsoleteMethodWarning:'please use #allSubInstances'. |
|
2197 |
^ self allSubInstances |
|
2198 |
! |
|
2199 |
||
2200 |
allInstVarNames |
|
2201 |
"return a collection of all the instance variable name-strings |
|
2202 |
this includes all superclass-instance variables. |
|
2203 |
Since Behavior has no idea of instvar-names, return an empty collection |
|
2204 |
here. Redefined in ClassDescription." |
|
2205 |
||
2206 |
^ #() |
|
2207 |
! |
|
2208 |
||
2209 |
allInstances |
|
2210 |
"return a collection of all my instances" |
|
2211 |
||
2212 |
"Read the documentation on why there seem to be no |
|
2213 |
instances of SmallInteger and UndefinedObject" |
|
2214 |
||
2215 |
|coll| |
|
2216 |
||
2217 |
coll := OrderedCollection new:100. |
|
2218 |
self allInstancesDo:[:anObject | |
|
2219 |
coll add:anObject |
|
2220 |
]. |
|
2221 |
^ coll |
|
2222 |
||
2223 |
" |
|
2224 |
ScrollBar allInstances |
|
2225 |
" |
|
2226 |
! |
|
2227 |
||
2228 |
allSubInstances |
|
2229 |
"return a collection of all instances of myself and |
|
2230 |
instances of all subclasses of myself." |
|
2231 |
||
2232 |
|coll| |
|
2233 |
||
2234 |
coll := OrderedCollection new:100. |
|
2235 |
self allSubInstancesDo:[:anObject | |
|
2236 |
(anObject isKindOf:self) ifTrue:[ |
|
2237 |
coll add:anObject |
|
2238 |
] |
|
2239 |
]. |
|
2240 |
^ coll |
|
2241 |
||
2242 |
" |
|
2243 |
View allSubInstances |
|
2244 |
" |
|
2245 |
! |
|
2246 |
||
2247 |
allSubclasses |
|
2248 |
"return a collection of all subclasses (direct AND indirect) of |
|
2249 |
the receiver. There will be no specific order, in which entries |
|
2250 |
are returned." |
|
2251 |
||
2252 |
|newColl| |
|
2253 |
||
2254 |
newColl := OrderedCollection new. |
|
2255 |
self allSubclassesDo:[:aClass | |
|
2256 |
newColl add:aClass |
|
2257 |
]. |
|
2258 |
^ newColl |
|
2259 |
||
2260 |
" |
|
2261 |
Collection allSubclasses |
|
2262 |
" |
|
2263 |
! |
|
2264 |
||
2265 |
allSubclassesInOrder |
|
2266 |
"return a collection of all subclasses (direct AND indirect) of |
|
2267 |
the receiver. Higher level subclasses will come before lower ones." |
|
2268 |
||
2269 |
|newColl| |
|
2270 |
||
2271 |
newColl := OrderedCollection new. |
|
2272 |
self allSubclassesInOrderDo:[:aClass | |
|
2273 |
newColl add:aClass |
|
2274 |
]. |
|
2275 |
^ newColl |
|
2276 |
||
2277 |
" |
|
2278 |
Collection allSubclassesInOrder |
|
2279 |
" |
|
2280 |
! |
|
2281 |
||
2282 |
allSuperclasses |
|
2283 |
"return a collection of the receivers accumulated superclasses" |
|
2284 |
||
2285 |
|aCollection theSuperClass| |
|
2286 |
||
2287 |
theSuperClass := superclass. |
|
2288 |
theSuperClass notNil ifTrue:[ |
|
2289 |
aCollection := OrderedCollection new. |
|
2290 |
[theSuperClass notNil] whileTrue:[ |
|
2291 |
aCollection add:theSuperClass. |
|
2292 |
theSuperClass := theSuperClass superclass |
|
2293 |
] |
|
2294 |
]. |
|
2295 |
^ aCollection |
|
2296 |
||
2297 |
" |
|
2298 |
String allSuperclasses |
|
2299 |
" |
|
2300 |
! |
|
2301 |
||
2302 |
cachedLookupMethodFor:aSelector |
|
2303 |
"return the method, which would be executed if aSelector was sent to |
|
2304 |
an instance of the receiver. I.e. the selector arrays of the receiver |
|
2305 |
and all of its superclasses are searched for aSelector. |
|
2306 |
Return the method, or nil if instances do not understand aSelector. |
|
2307 |
This interface provides exactly the same information as #lookupMethodFor:, |
|
2308 |
but uses the lookup-cache in the VM for faster search. |
|
2309 |
However, keep in mind, that doing a lookup through the cache also adds new |
|
2310 |
entries and can thus slow down the system by polluting the cache with |
|
2311 |
irrelevant entries. (do NOT loop over all objects calling this method). |
|
2312 |
Does NOT (currently) handle MI" |
|
2313 |
||
2314 |
%{ /* NOCONTEXT */ |
|
2315 |
extern OBJ __lookup(); |
|
2316 |
||
2317 |
RETURN ( __lookup(self, aSelector, SENDER) ); |
|
2318 |
%} |
|
2319 |
||
2320 |
" |
|
2321 |
String cachedLookupMethodFor:#= |
|
2322 |
String cachedLookupMethodFor:#asOrderedCollection |
|
2323 |
" |
|
2324 |
! |
|
2325 |
||
2326 |
canBeSubclassed |
|
2327 |
"return true, if its allowed to create subclasses of the receiver. |
|
2328 |
This method is redefined in SmallInteger and UndefinedObject, since |
|
2329 |
instances are detected by their pointer-fields, i.e. they do not have |
|
2330 |
a class entry (you dont have to understand this :-)" |
|
10 | 2331 |
|
2332 |
^ true |
|
2333 |
! |
|
2334 |
||
620 | 2335 |
canUnderstand:aSelector |
2336 |
"return true, if the receiver or one of its superclasses implements aSelector. |
|
2337 |
(i.e. true if my instances understand aSelector)" |
|
2338 |
||
2339 |
^ (self lookupMethodFor:aSelector) notNil |
|
2340 |
||
2341 |
" |
|
2342 |
True canUnderstand:#ifTrue: |
|
2343 |
True canUnderstand:#== |
|
2344 |
True canUnderstand:#do: |
|
2345 |
" |
|
91 | 2346 |
! |
2347 |
||
620 | 2348 |
compiledMethodAt:aSelector |
2349 |
"return the method for given selector aSelector or nil. |
|
2350 |
Only methods in the receiver - not in the superclass chain are tested." |
|
2351 |
||
2352 |
|index| |
|
2353 |
||
2354 |
selectorArray isNil ifTrue:[ |
|
2355 |
('oops: nil selectorArray in ' , self name) errorPrintNL. |
|
2356 |
^ nil |
|
2357 |
]. |
|
2358 |
||
2359 |
index := selectorArray identityIndexOf:aSelector startingAt:1. |
|
2360 |
(index == 0) ifTrue:[^ nil]. |
|
2361 |
^ methodArray at:index |
|
2362 |
||
293 | 2363 |
" |
620 | 2364 |
Object compiledMethodAt:#== |
2365 |
(Object compiledMethodAt:#==) category |
|
293 | 2366 |
" |
620 | 2367 |
! |
2368 |
||
2369 |
containsMethod:aMethod |
|
2370 |
"Return true, if the argument, aMethod is a method of myself" |
|
2371 |
||
2372 |
methodArray isNil ifTrue:[^ false]. "degenerated class" |
|
2373 |
^ (methodArray identityIndexOf:aMethod startingAt:1) ~~ 0 |
|
2374 |
! |
|
2375 |
||
2376 |
derivedInstanceCount |
|
2377 |
"return the number of instances of myself and of subclasses" |
|
2378 |
||
2379 |
|count| |
|
2380 |
||
2381 |
count := 0. |
|
2382 |
ObjectMemory allObjectsDo:[:anObject | |
|
2383 |
(anObject isKindOf:self) ifTrue:[ |
|
2384 |
count := count + 1 |
|
2385 |
] |
|
2386 |
]. |
|
2387 |
^ count |
|
2388 |
||
293 | 2389 |
" |
620 | 2390 |
View derivedInstanceCount |
2391 |
SequenceableCollection derivedInstanceCount |
|
293 | 2392 |
" |
620 | 2393 |
! |
2394 |
||
2395 |
hasInstances |
|
2396 |
"return true, if there are any instances of myself" |
|
2397 |
||
2398 |
"Read the documentation on why there seem to be no |
|
2399 |
instances of SmallInteger and UndefinedObject" |
|
2400 |
||
2401 |
"/ ObjectMemory allObjectsDo:[:anObject | |
|
2402 |
"/ (anObject class == self) ifTrue:[ |
|
2403 |
"/ ^ true |
|
2404 |
"/ ] |
|
2405 |
"/ ]. |
|
2406 |
ObjectMemory allInstancesOf:self do:[:anObject | |
|
2407 |
^ true |
|
2408 |
]. |
|
2409 |
^ false |
|
2410 |
||
293 | 2411 |
" |
620 | 2412 |
Object hasInstances |
2413 |
SequenceableCollection hasInstances |
|
2414 |
Float hasInstances |
|
2415 |
SmallInteger hasInstances |
|
293 | 2416 |
" |
620 | 2417 |
! |
2418 |
||
2419 |
hasMethods |
|
2420 |
"return true, if there are any (local) methods in this class" |
|
2421 |
||
2422 |
^ (methodArray size ~~ 0) |
|
2423 |
||
293 | 2424 |
" |
620 | 2425 |
True hasMethods |
2426 |
True class hasMethods |
|
2427 |
" |
|
2428 |
! |
|
2429 |
||
2430 |
hasMultipleSuperclasses |
|
2431 |
"Return true, if this class inherits from other classes |
|
2432 |
(beside its primary superclass). |
|
2433 |
This method is a preparation for a future multiple inheritance extension |
|
2434 |
- currently it is not supported by the VM" |
|
2435 |
||
2436 |
^ otherSuperclasses notNil |
|
2437 |
! |
|
2438 |
||
2439 |
implements:aSelector |
|
2440 |
"return true, if the receiver implements aSelector. |
|
2441 |
(i.e. implemented in THIS class - NOT in a superclass). |
|
2442 |
Dont use this method to check if someone responds to a message - |
|
2443 |
use #canUnderstand: on the class or #respondsTo: on the instance |
|
2444 |
to do this." |
|
2445 |
||
2446 |
^ (selectorArray identityIndexOf:aSelector startingAt:1) ~~ 0 |
|
2447 |
||
2448 |
" |
|
2449 |
True implements:#ifTrue: |
|
2450 |
True implements:#== |
|
2451 |
" |
|
2452 |
! |
|
2453 |
||
2454 |
includesSelector:aSelector |
|
2455 |
"for ST-80 compatibility" |
|
2456 |
||
2457 |
^ self implements:aSelector |
|
2458 |
! |
|
2459 |
||
2460 |
inheritsFrom:aClass |
|
2461 |
"return true, if the receiver inherits methods from aClass" |
|
2462 |
||
2463 |
^ self isSubclassOf:aClass |
|
2464 |
||
2465 |
" |
|
2466 |
True inheritsFrom:Object |
|
2467 |
LinkedList inheritsFrom:Array |
|
356 | 2468 |
" |
357 | 2469 |
! |
2470 |
||
620 | 2471 |
instanceCount |
2472 |
"return the number of instances of myself." |
|
2473 |
||
2474 |
"Read the documentation on why there seem to be no |
|
2475 |
instances of SmallInteger and UndefinedObject" |
|
2476 |
||
2477 |
|count| |
|
2478 |
||
2479 |
count := 0. |
|
2480 |
"/ ObjectMemory allObjectsDo:[:anObject | |
|
2481 |
"/ (anObject class == self) ifTrue:[ |
|
2482 |
"/ count := count + 1 |
|
2483 |
"/ ] |
|
2484 |
"/ ]. |
|
2485 |
ObjectMemory allInstancesOf:self do:[:anObject | |
|
2486 |
count := count + 1 |
|
2487 |
]. |
|
2488 |
^ count |
|
2489 |
||
2490 |
" |
|
2491 |
View instanceCount |
|
2492 |
Object instanceCount |
|
2493 |
Float instanceCount |
|
2494 |
SequenceableCollection instanceCount |
|
2495 |
SmallInteger instanceCount .... mhmh - hear, hear |
|
2496 |
" |
|
2497 |
! |
|
2498 |
||
2499 |
isBehavior |
|
2500 |
"return true, if the receiver is describing another objects behavior, |
|
2501 |
i.e. is a class. Defined to avoid the need to use isKindOf:" |
|
2502 |
||
2503 |
^ true |
|
2504 |
||
2505 |
" |
|
2506 |
True isBehavior |
|
2507 |
true isBehavior |
|
2508 |
" |
|
2509 |
! |
|
2510 |
||
2511 |
isBits |
|
2512 |
"return true, if instances have indexed byte or short instance variables. |
|
2513 |
Ignore long, float and double arrays, since ST-80 code using isBits are probably |
|
2514 |
not prepared to handle them correctly." |
|
92 | 2515 |
|
2516 |
%{ /* NOCONTEXT */ |
|
620 | 2517 |
|
2518 |
REGISTER int flags; |
|
2519 |
||
2520 |
RETURN ( (((flags = (_intVal(_INST(flags)) & ARRAYMASK)) == BYTEARRAY) |
|
2521 |
|| (flags == WORDARRAY)) ? true : false ); |
|
2522 |
%} |
|
2523 |
! |
|
2524 |
||
2525 |
isBytes |
|
2526 |
"return true, if instances have indexed byte instance variables" |
|
2527 |
||
2528 |
"this could also be defined as: |
|
2529 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagBytes |
|
2530 |
" |
|
2531 |
%{ /* NOCONTEXT */ |
|
2532 |
||
2533 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == BYTEARRAY) ? true : false ); |
|
68 | 2534 |
%} |
620 | 2535 |
! |
2536 |
||
2537 |
isDoubles |
|
2538 |
"return true, if instances have indexed double instance variables" |
|
2539 |
||
2540 |
"this could also be defined as: |
|
2541 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagDoubles |
|
2542 |
" |
|
2543 |
%{ /* NOCONTEXT */ |
|
2544 |
||
2545 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == DOUBLEARRAY) ? true : false ); |
|
2546 |
%} |
|
2547 |
! |
|
2548 |
||
2549 |
isFixed |
|
2550 |
"return true, if instances do not have indexed instance variables" |
|
2551 |
||
2552 |
"this could also be defined as: |
|
2553 |
^ self isVariable not |
|
2554 |
" |
|
2555 |
||
2556 |
%{ /* NOCONTEXT */ |
|
2557 |
||
2558 |
RETURN ( (_intVal(_INST(flags)) & ARRAYMASK) ? false : true ); |
|
2559 |
%} |
|
2560 |
! |
|
2561 |
||
2562 |
isFloats |
|
2563 |
"return true, if instances have indexed float instance variables" |
|
2564 |
||
2565 |
"this could also be defined as: |
|
2566 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagFloats |
|
2567 |
" |
|
2568 |
%{ /* NOCONTEXT */ |
|
2569 |
||
2570 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == FLOATARRAY) ? true : false ); |
|
2571 |
%} |
|
91 | 2572 |
! |
2573 |
||
620 | 2574 |
isLongs |
2575 |
"return true, if instances have indexed long instance variables" |
|
2576 |
||
2577 |
"this could also be defined as: |
|
2578 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagLongs |
|
2579 |
" |
|
2580 |
%{ /* NOCONTEXT */ |
|
2581 |
||
2582 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == LONGARRAY) ? true : false ); |
|
2583 |
%} |
|
356 | 2584 |
! |
2585 |
||
620 | 2586 |
isPointers |
2587 |
"return true, if instances have pointer instance variables |
|
2588 |
i.e. are either non-indexed or have indexed pointer variables" |
|
2589 |
||
2590 |
"QUESTION: should we ignore WeakPointers ?" |
|
2591 |
||
2592 |
%{ /* NOCONTEXT */ |
|
2593 |
||
2594 |
REGISTER int flags; |
|
2595 |
||
2596 |
flags = _intVal(_INST(flags)) & ARRAYMASK; |
|
2597 |
switch (flags) { |
|
2598 |
default: |
|
2599 |
/* normal objects */ |
|
2600 |
RETURN ( true ); |
|
2601 |
||
2602 |
case BYTEARRAY: |
|
2603 |
case WORDARRAY: |
|
2604 |
case LONGARRAY: |
|
2605 |
case FLOATARRAY: |
|
2606 |
case DOUBLEARRAY: |
|
2607 |
RETURN (false ); |
|
2608 |
||
2609 |
case WKPOINTERARRAY: |
|
2610 |
/* what about those ? */ |
|
2611 |
RETURN (true ); |
|
2612 |
} |
|
2613 |
%} |
|
2614 |
! |
|
2615 |
||
2616 |
isSubclassOf:aClass |
|
2617 |
"return true, if I am a subclass of the argument, aClass" |
|
2618 |
||
2619 |
|theClass| |
|
2620 |
||
2621 |
theClass := superclass. |
|
2622 |
[theClass notNil] whileTrue:[ |
|
2623 |
(theClass == aClass) ifTrue:[^ true]. |
|
2624 |
%{ |
|
2625 |
if (__isBehaviorLike(theClass)) { |
|
2626 |
theClass = __ClassInstPtr(theClass)->c_superclass; |
|
2627 |
} else { |
|
2628 |
theClass = nil; |
|
2629 |
} |
|
2630 |
%}. |
|
2631 |
"/ theClass := theClass superclass. |
|
2632 |
]. |
|
2633 |
^ false |
|
356 | 2634 |
|
2635 |
" |
|
620 | 2636 |
String isSubclassOf:Collection |
2637 |
LinkedList isSubclassOf:Array |
|
2638 |
1 isSubclassOf:Number <- will fail since 1 is no class |
|
2639 |
" |
|
2640 |
! |
|
2641 |
||
2642 |
isVariable |
|
2643 |
"return true, if instances have indexed instance variables" |
|
2644 |
||
2645 |
"this could also be defined as: |
|
2646 |
^ (flags bitAnd:(Behavior maskIndexType)) ~~ 0 |
|
2647 |
" |
|
2648 |
||
2649 |
%{ /* NOCONTEXT */ |
|
2650 |
||
2651 |
RETURN ( (_intVal(_INST(flags)) & ARRAYMASK) ? true : false ); |
|
2652 |
%} |
|
2653 |
! |
|
2654 |
||
2655 |
isWords |
|
2656 |
"return true, if instances have indexed short instance variables" |
|
2657 |
||
2658 |
"this could also be defined as: |
|
2659 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagWords |
|
2660 |
" |
|
2661 |
%{ /* NOCONTEXT */ |
|
2662 |
||
2663 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == WORDARRAY) ? true : false ); |
|
2664 |
%} |
|
2665 |
! |
|
2666 |
||
2667 |
lookupMethodFor:aSelector |
|
2668 |
"return the method, which would be executed if aSelector was sent to |
|
2669 |
an instance of the receiver. I.e. the selector arrays of the receiver |
|
2670 |
and all of its superclasses are searched for aSelector. |
|
2671 |
Return the method, or nil if instances do not understand aSelector. |
|
2672 |
EXPERIMENTAL: take care of multiple superclasses." |
|
2673 |
||
2674 |
|m cls| |
|
2675 |
||
2676 |
cls := self. |
|
2677 |
[cls notNil] whileTrue:[ |
|
2678 |
m := cls compiledMethodAt:aSelector. |
|
2679 |
m notNil ifTrue:[^ m]. |
|
2680 |
cls hasMultipleSuperclasses ifTrue:[ |
|
2681 |
cls superclasses do:[:aSuperClass | |
|
2682 |
m := aSuperClass lookupMethodFor:aSelector. |
|
2683 |
m notNil ifTrue:[^ m]. |
|
2684 |
]. |
|
2685 |
^ nil |
|
2686 |
] ifFalse:[ |
|
2687 |
cls := cls superclass |
|
2688 |
] |
|
2689 |
]. |
|
2690 |
^ nil |
|
2691 |
! |
|
2692 |
||
2693 |
selectorAtMethod:aMethod |
|
2694 |
"Return the selector for given method aMethod." |
|
2695 |
||
2696 |
^ self selectorAtMethod:aMethod ifAbsent:[nil] |
|
2697 |
||
2698 |
" |
|
2699 |
|m| |
|
2700 |
||
2701 |
m := Object compiledMethodAt:#copy. |
|
2702 |
Fraction selectorAtMethod:m. |
|
2703 |
" |
|
2704 |
" |
|
2705 |
|m| |
|
2706 |
||
2707 |
m := Object compiledMethodAt:#copy. |
|
2708 |
Object selectorAtMethod:m. |
|
356 | 2709 |
" |
2710 |
! |
|
2711 |
||
620 | 2712 |
selectorAtMethod:aMethod ifAbsent:failBlock |
2713 |
"return the selector for given method aMethod |
|
2714 |
or the value of failBlock, if not found." |
|
2715 |
||
2716 |
|index| |
|
2717 |
||
2718 |
index := methodArray identityIndexOf:aMethod startingAt:1. |
|
2719 |
(index == 0) ifTrue:[^ failBlock value]. |
|
2720 |
^ selectorArray at:index |
|
216 | 2721 |
|
2722 |
" |
|
620 | 2723 |
|m| |
2724 |
||
2725 |
m := Object compiledMethodAt:#copy. |
|
2726 |
Object selectorAtMethod:m ifAbsent:['oops']. |
|
2727 |
" |
|
216 | 2728 |
" |
620 | 2729 |
|m| |
2730 |
||
2731 |
m := Object compiledMethodAt:#copy. |
|
2732 |
Fraction selectorAtMethod:m ifAbsent:['oops']. |
|
216 | 2733 |
" |
2734 |
! |
|
2735 |
||
620 | 2736 |
selectorIndex:aSelector |
2737 |
"return the index in the arrays for given selector aSelector" |
|
2738 |
||
2739 |
^ selectorArray identityIndexOf:aSelector startingAt:1 |
|
216 | 2740 |
! |
2741 |
||
127 | 2742 |
sizeOfInst:n |
2743 |
"return the number of bytes required for an instance of |
|
2744 |
myself with n indexed instance variables. The argument n |
|
2745 |
should be zero for classes without indexed instance variables. |
|
2746 |
See Behavior>>niceNew: for an application of this." |
|
216 | 2747 |
|
127 | 2748 |
|nInstvars| |
2749 |
||
2750 |
nInstvars := self instSize. |
|
2751 |
%{ |
|
2752 |
int nBytes; |
|
2753 |
||
2754 |
nBytes = _intVal(nInstvars) * sizeof(OBJ) + OHDR_SIZE; |
|
249 | 2755 |
if (__isSmallInteger(n)) { |
154 | 2756 |
int nIndex; |
127 | 2757 |
|
154 | 2758 |
nIndex = _intVal(n); |
2759 |
switch (_intVal(_INST(flags)) & ARRAYMASK) { |
|
2760 |
case BYTEARRAY: |
|
2761 |
nBytes += nIndex; |
|
2762 |
if (nBytes & (ALIGN - 1)) { |
|
2763 |
nBytes = (nBytes & ~(ALIGN - 1)) + ALIGN; |
|
2764 |
} |
|
2765 |
break; |
|
127 | 2766 |
|
154 | 2767 |
case WORDARRAY: |
2768 |
nBytes += nIndex * sizeof(short); |
|
2769 |
if (nBytes & (ALIGN - 1)) { |
|
2770 |
nBytes = (nBytes & ~(ALIGN - 1)) + ALIGN; |
|
2771 |
} |
|
2772 |
break; |
|
127 | 2773 |
|
154 | 2774 |
case LONGARRAY: |
2775 |
nBytes += nIndex * sizeof(long); |
|
2776 |
break; |
|
127 | 2777 |
|
154 | 2778 |
case FLOATARRAY: |
2779 |
nBytes += nIndex * sizeof(float); |
|
2780 |
break; |
|
127 | 2781 |
|
154 | 2782 |
case DOUBLEARRAY: |
2783 |
nBytes += nIndex * sizeof(double); |
|
2784 |
break; |
|
127 | 2785 |
|
154 | 2786 |
default: |
2787 |
nBytes += nIndex * sizeof(OBJ); |
|
2788 |
break; |
|
2789 |
} |
|
127 | 2790 |
} |
2791 |
RETURN (_MKSMALLINT(nBytes)); |
|
2792 |
%} |
|
2793 |
! |
|
2794 |
||
620 | 2795 |
sourceCodeAt:aSelector |
2796 |
"return the methods source for given selector aSelector or nil. |
|
2797 |
Only methods in the receiver - not in the superclass chain are tested." |
|
2798 |
||
2799 |
|method| |
|
2800 |
||
2801 |
method := self compiledMethodAt:aSelector. |
|
2802 |
method isNil ifTrue:[^ nil]. |
|
2803 |
^ method source |
|
45 | 2804 |
|
91 | 2805 |
" |
620 | 2806 |
True sourceCodeAt:#ifTrue: |
2807 |
Object sourceCodeAt:#== |
|
2808 |
Behavior sourceCodeAt:#sourceCodeAt: |
|
91 | 2809 |
" |
1 | 2810 |
! |
2811 |
||
2812 |
subclasses |
|
2813 |
"return a collection of the direct subclasses of the receiver" |
|
2814 |
||
2815 |
|newColl| |
|
2816 |
||
308 | 2817 |
SubclassInfo notNil ifTrue:[ |
2818 |
newColl := SubclassInfo at:self ifAbsent:nil. |
|
2819 |
newColl notNil ifTrue:[^ newColl asOrderedCollection] |
|
2820 |
]. |
|
2821 |
||
1 | 2822 |
newColl := OrderedCollection new. |
2823 |
self subclassesDo:[:aClass | |
|
154 | 2824 |
newColl add:aClass |
1 | 2825 |
]. |
2826 |
^ newColl |
|
45 | 2827 |
|
91 | 2828 |
" |
2829 |
Collection subclasses |
|
2830 |
" |
|
1 | 2831 |
! |
2832 |
||
620 | 2833 |
superclasses |
2834 |
"return a collection of the receivers immediate superclasses. |
|
2835 |
This method is a preparation for a future multiple inheritance extension |
|
2836 |
- currently it is not supported by the VM" |
|
2837 |
||
2838 |
|a| |
|
2839 |
||
2840 |
a := Array with:superclass. |
|
2841 |
otherSuperclasses notNil ifTrue:[ |
|
2842 |
^ a , otherSuperclasses |
|
1 | 2843 |
]. |
620 | 2844 |
^ a |
154 | 2845 |
|
2846 |
" |
|
620 | 2847 |
String superclasses |
91 | 2848 |
" |
2 | 2849 |
! |
2850 |
||
2851 |
whichClassImplements:aSelector |
|
328 | 2852 |
"obsolete interface; |
2853 |
use whichClassIncludesSelector: for ST-80 compatibility." |
|
2854 |
||
2855 |
^ self whichClassIncludesSelector:aSelector |
|
2856 |
! |
|
2857 |
||
2858 |
whichClassIncludesSelector:aSelector |
|
68 | 2859 |
"return the class in the inheritance chain, which implements the method |
2860 |
for aSelector; return nil if none. |
|
2861 |
EXPERIMENTAL: handle multiple superclasses" |
|
2862 |
||
2863 |
|cls| |
|
2 | 2864 |
|
68 | 2865 |
cls := self. |
2866 |
[cls notNil] whileTrue:[ |
|
154 | 2867 |
(cls implements:aSelector) ifTrue:[^ cls]. |
2868 |
cls hasMultipleSuperclasses ifTrue:[ |
|
2869 |
cls superclasses do:[:aSuperClass | |
|
2870 |
|implementingClass| |
|
2 | 2871 |
|
328 | 2872 |
implementingClass := aSuperClass whichClassIncludesSelector:aSelector. |
154 | 2873 |
implementingClass notNil ifTrue:[^ implementingClass]. |
2874 |
]. |
|
2875 |
^ nil |
|
2876 |
] ifFalse:[ |
|
2877 |
cls := cls superclass |
|
2878 |
] |
|
2 | 2879 |
]. |
2880 |
^ nil |
|
2881 |
||
91 | 2882 |
" |
328 | 2883 |
String whichClassIncludesSelector:#== |
2884 |
String whichClassIncludesSelector:#collect: |
|
91 | 2885 |
" |
2 | 2886 |
! |
2887 |
||
620 | 2888 |
withAllSubclasses |
2889 |
"return a collection containing the receiver and |
|
2890 |
all subclasses (direct AND indirect) of the receiver" |
|
2891 |
||
2892 |
|newColl| |
|
2893 |
||
2894 |
newColl := OrderedCollection with:self. |
|
2895 |
self allSubclassesDo:[:aClass | |
|
2896 |
newColl add:aClass |
|
2897 |
]. |
|
2898 |
^ newColl |
|
328 | 2899 |
|
2900 |
" |
|
620 | 2901 |
Collection withAllSubclasses |
91 | 2902 |
" |
1 | 2903 |
! |
2904 |
||
620 | 2905 |
withAllSuperclasses |
2906 |
"return a collection containing the receiver and all |
|
2907 |
of the receivers accumulated superclasses" |
|
2908 |
||
2909 |
|aCollection theSuperClass| |
|
2910 |
||
2911 |
aCollection := OrderedCollection with:self. |
|
2912 |
theSuperClass := superclass. |
|
2913 |
[theSuperClass notNil] whileTrue:[ |
|
2914 |
aCollection add:theSuperClass. |
|
2915 |
theSuperClass := theSuperClass superclass |
|
308 | 2916 |
]. |
620 | 2917 |
^ aCollection |
11 | 2918 |
|
91 | 2919 |
" |
620 | 2920 |
String withAllSuperclasses |
308 | 2921 |
" |
2 | 2922 |
! ! |
620 | 2923 |
|
2924 |
!Behavior methodsFor:'snapshots'! |
|
2925 |
||
2926 |
postSnapshot |
|
2927 |
"sent by ObjectMemory, after a snapshot has been written. |
|
2928 |
Nothing done here." |
|
2929 |
! |
|
2930 |
||
2931 |
preSnapshot |
|
2932 |
"sent by ObjectMemory, before a snapshot is written. |
|
2933 |
Nothing done here." |
|
2934 |
! ! |
|
2935 |