author | Claus Gittinger <cg@exept.de> |
Thu, 25 Apr 1996 13:16:22 +0200 | |
changeset 1285 | 7df250a95d7b |
parent 1266 | cef9b3cd49df |
child 1292 | 89497fff7f87 |
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 |
|
1088 | 14 |
instanceVariableNames:'superclass flags selectorArray methodArray otherSuperclasses |
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
15 |
instSize' |
1088 | 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 |
|
1285 | 66 |
[Instance variables:] |
67 |
||
68 |
superclass <Class> the receivers superclass |
|
69 |
||
70 |
otherSuperclasses <Array of Class> experimental: other superclasses |
|
71 |
a hook for experimental multiple inheritance |
|
72 |
implementations |
|
73 |
||
74 |
selectorArray <Array of Symbol> the selectors for which inst-methods are defined here |
|
75 |
||
76 |
methodArray <Array of Method> the inst-methods corresponding to the selectors |
|
77 |
||
78 |
instSize <SmallInteger> the number of instance variables |
|
79 |
||
80 |
flags <SmallInteger> special flag bits coded in a number |
|
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 |
1285 | 86 |
|
87 |
[see also:] |
|
88 |
Class ClassDescription |
|
89 |
Method |
|
47 | 90 |
" |
356 | 91 |
! |
92 |
||
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 |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
143 |
Examples (only of theoretical interest): |
356 | 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 |
||
1133 | 304 |
RETURN ( __MKSMALLINT(BEHAVIOR_INSTS) ); |
620 | 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 |
||
1133 | 345 |
RETURN ( __MKSMALLINT(BLOCK_INSTS) ); |
620 | 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 |
||
1133 | 357 |
RETURN ( __MKSMALLINT(BCONTEXT_INSTS) ); |
620 | 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 |
||
1133 | 369 |
RETURN ( __MKSMALLINT(BYTEARRAY) ); |
620 | 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 |
||
1133 | 384 |
RETURN ( __MKSMALLINT(CONTEXT_INSTS) ); |
620 | 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 |
||
1133 | 396 |
RETURN ( __MKSMALLINT(DOUBLEARRAY) ); |
620 | 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 |
||
1133 | 411 |
RETURN ( __MKSMALLINT(FLOAT_INSTS) ); |
620 | 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 |
||
1133 | 423 |
RETURN ( __MKSMALLINT(FLOATARRAY) ); |
620 | 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 |
||
1133 | 438 |
RETURN ( __MKSMALLINT(LONGARRAY) ); |
620 | 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 |
||
1133 | 453 |
RETURN ( __MKSMALLINT(METHOD_INSTS) ); |
620 | 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 |
||
1133 | 465 |
RETURN ( __MKSMALLINT(NONOBJECT_INSTS) ); |
620 | 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 |
||
1133 | 485 |
RETURN ( __MKSMALLINT(POINTERARRAY) ); |
620 | 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 |
||
1133 | 500 |
RETURN ( __MKSMALLINT(SYMBOL_INSTS) ); |
620 | 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 |
||
1133 | 512 |
RETURN ( __MKSMALLINT(WKPOINTERARRAY) ); |
620 | 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 |
||
1133 | 524 |
RETURN ( __MKSMALLINT(WORDARRAY) ); |
620 | 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 |
||
1133 | 537 |
RETURN ( __MKSMALLINT(ARRAYMASK) ); |
620 | 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 |
|
1266 | 582 |
"return true if this class is known by the run-time-system. |
583 |
Here, true is returned for myself, false for subclasses." |
|
620 | 584 |
|
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
585 |
^ (self == Behavior class) or:[self == Behavior] |
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
586 |
|
1266 | 587 |
"Modified: 23.4.1996 / 15:55:52 / cg" |
620 | 588 |
! ! |
589 |
||
590 |
!Behavior methodsFor:'accessing'! |
|
591 |
||
592 |
addSelector:newSelector withLazyMethod:newMethod |
|
593 |
"add the method given by 2nd argument under the selector given by |
|
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
594 |
1st argument to the methodDictionary. |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
595 |
Since it does not normally flush any caches, |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
596 |
this is only allowed for lazy methods (which are for a new class)." |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
597 |
|
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
598 |
|oldMethod| |
620 | 599 |
|
600 |
newMethod isLazyMethod ifFalse:[ |
|
601 |
self error:'operation only allowed for lazy methods'. |
|
602 |
^ false |
|
603 |
]. |
|
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
604 |
oldMethod := self compiledMethodAt:newSelector. |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
605 |
"/ |
620 | 606 |
"/ oops: we must flush, if this method already exists ... |
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
607 |
"/ otherwise, the old method would still be executed out of the caches. |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
608 |
"/ |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
609 |
oldMethod notNil ifTrue:[ |
746
31f5d9af5680
dont forget privace & restricted when entering a method
Claus Gittinger <cg@exept.de>
parents:
734
diff
changeset
|
610 |
newMethod privacy:(oldMethod privacy). |
31f5d9af5680
dont forget privace & restricted when entering a method
Claus Gittinger <cg@exept.de>
parents:
734
diff
changeset
|
611 |
newMethod restricted:(oldMethod isRestricted). |
620 | 612 |
ObjectMemory flushCaches |
613 |
]. |
|
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
614 |
|
620 | 615 |
(self primAddSelector:newSelector withMethod:newMethod) ifTrue:[ |
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
616 |
"/ |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
617 |
"/ pass the selector AND the old method as changeArg |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
618 |
"/ - this allows for watchers to find out if its a new method or a method-change |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
619 |
"/ |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
620 |
self changed:#methodDictionary with:(Array with:newSelector with:oldMethod). |
620 | 621 |
^ true |
622 |
]. |
|
623 |
^ false |
|
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
624 |
|
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
625 |
"Modified: 11.12.1995 / 13:57:17 / cg" |
308 | 626 |
! |
627 |
||
620 | 628 |
addSelector:newSelector withMethod:newMethod |
629 |
"add the method given by 2nd argument under the selector given by |
|
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
630 |
1st argument to the methodDictionary. Flushes all caches." |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
631 |
|
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
632 |
|nargs oldMethod| |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
633 |
|
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
634 |
oldMethod := self compiledMethodAt:newSelector. |
620 | 635 |
(self primAddSelector:newSelector withMethod:newMethod) ifFalse:[^ false]. |
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
636 |
|
746
31f5d9af5680
dont forget privace & restricted when entering a method
Claus Gittinger <cg@exept.de>
parents:
734
diff
changeset
|
637 |
oldMethod notNil ifTrue:[ |
31f5d9af5680
dont forget privace & restricted when entering a method
Claus Gittinger <cg@exept.de>
parents:
734
diff
changeset
|
638 |
newMethod privacy:(oldMethod privacy). |
31f5d9af5680
dont forget privace & restricted when entering a method
Claus Gittinger <cg@exept.de>
parents:
734
diff
changeset
|
639 |
newMethod restricted:(oldMethod isRestricted). |
31f5d9af5680
dont forget privace & restricted when entering a method
Claus Gittinger <cg@exept.de>
parents:
734
diff
changeset
|
640 |
]. |
31f5d9af5680
dont forget privace & restricted when entering a method
Claus Gittinger <cg@exept.de>
parents:
734
diff
changeset
|
641 |
|
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
642 |
"/ |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
643 |
"/ pass the selector AND the old method as changeArg |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
644 |
"/ - this allows for watchers to find out if its a new method or a method-change |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
645 |
"/ |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
646 |
self changed:#methodDictionary with:(Array with:newSelector with:oldMethod). |
620 | 647 |
|
648 |
" |
|
649 |
if I have no subclasses, all we have to flush is cached |
|
650 |
data for myself ... (actually, in any case all that needs |
|
651 |
to be flushed is info for myself and all of my subclasses) |
|
652 |
" |
|
653 |
" |
|
654 |
problem: this is slower; since looking for all subclasses is (currently) |
|
655 |
a bit slow :-( |
|
656 |
We need the hasSubclasses-info bit in Behavior; now |
|
657 |
||
658 |
self withAllSubclassesDo:[:aClass | |
|
659 |
ObjectMemory flushInlineCachesFor:aClass withArgs:nargs. |
|
660 |
ObjectMemory flushMethodCacheFor:aClass |
|
661 |
]. |
|
662 |
" |
|
663 |
||
664 |
nargs := newSelector numArgs. |
|
665 |
||
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
666 |
ObjectMemory flushMethodCacheForSelector:newSelector. |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
667 |
"/ ObjectMemory flushMethodCache. |
620 | 668 |
ObjectMemory flushInlineCachesWithArgs:nargs. |
669 |
||
670 |
^ true |
|
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
671 |
|
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
672 |
"Created: 11.12.1995 / 13:59:37 / cg" |
620 | 673 |
! |
674 |
||
675 |
addSuperclass:aClass |
|
676 |
"EXPERIMENTAL MI support: add aClass to the set of classes, from which instances |
|
677 |
inherit protocol." |
|
678 |
||
679 |
"first, check if the class is abstract - |
|
680 |
allows abstract mixins are allowed in the current implementation" |
|
681 |
||
682 |
aClass instSize == 0 ifFalse:[ |
|
683 |
self error:'only abstract mixins allowed'. |
|
684 |
^ self |
|
685 |
]. |
|
686 |
otherSuperclasses isNil ifTrue:[ |
|
687 |
otherSuperclasses := Array with:aClass |
|
688 |
] ifFalse:[ |
|
689 |
otherSuperclasses := otherSuperclasses copyWith:aClass |
|
690 |
]. |
|
308 | 691 |
SubclassInfo := nil. |
620 | 692 |
ObjectMemory flushCaches |
693 |
! |
|
694 |
||
695 |
displayString |
|
696 |
"although behaviors have no name, we return something |
|
697 |
useful here - there are many places (inspectors) where |
|
698 |
a classes name is asked for. |
|
699 |
Implementing this message here allows instances of anonymous classes |
|
700 |
to show a reasonable name." |
|
701 |
||
702 |
^ 'someBehavior' |
|
703 |
! |
|
704 |
||
705 |
flags |
|
706 |
"return the receivers flag bits" |
|
707 |
||
708 |
^ flags |
|
709 |
! |
|
710 |
||
711 |
instSize |
|
712 |
"return the number of instance variables of the receiver. |
|
713 |
This includes all superclass instance variables." |
|
714 |
||
715 |
^ instSize |
|
716 |
! |
|
717 |
||
718 |
methodArray |
|
719 |
"return the receivers method array. |
|
720 |
Notice: this is not compatible with ST-80." |
|
721 |
||
722 |
^ methodArray |
|
723 |
! |
|
724 |
||
725 |
methodDictionary |
|
726 |
"return the receivers method dictionary. |
|
727 |
Since no dictionary is actually present, create one for ST-80 compatibility." |
|
728 |
||
729 |
|dict n "{ Class: SmallInteger }"| |
|
730 |
||
731 |
dict := IdentityDictionary new. |
|
732 |
n := selectorArray size. |
|
733 |
1 to:n do:[:index | |
|
734 |
dict at:(selectorArray at:index) put:(methodArray at:index) |
|
735 |
]. |
|
736 |
^ dict |
|
737 |
! |
|
738 |
||
739 |
removeSelector:aSelector |
|
740 |
"remove the selector, aSelector and its associated method |
|
741 |
from the methodDictionary" |
|
742 |
||
743 |
|index oldSelectorArray oldMethodArray newSelectorArray newMethodArray| |
|
744 |
||
745 |
index := selectorArray identityIndexOf:aSelector startingAt:1. |
|
746 |
(index == 0) ifTrue:[^ false]. |
|
747 |
||
748 |
newSelectorArray := selectorArray copyWithoutIndex:index. |
|
749 |
newMethodArray := methodArray copyWithoutIndex:index. |
|
750 |
oldSelectorArray := selectorArray. |
|
751 |
oldMethodArray := methodArray. |
|
752 |
selectorArray := newSelectorArray. |
|
753 |
methodArray := newMethodArray. |
|
754 |
" |
|
755 |
[ |
|
756 |
|nargs| |
|
757 |
nargs := aSelector numArgs. |
|
758 |
ObjectMemory flushMethodCache. |
|
759 |
ObjectMemory flushInlineCachesWithArgs:nargs. |
|
760 |
] value |
|
761 |
" |
|
762 |
" |
|
763 |
actually, we would do better with less flushing ... |
|
764 |
" |
|
765 |
ObjectMemory flushCaches. |
|
766 |
^ true |
|
767 |
! |
|
768 |
||
769 |
removeSuperclass:aClass |
|
770 |
"EXPERIMENTAL MI support: remove aClass from the set of classes, from which instances |
|
771 |
inherit protocol." |
|
772 |
||
773 |
otherSuperclasses notNil ifTrue:[ |
|
774 |
otherSuperclasses := otherSuperclasses copyWithout:aClass. |
|
775 |
otherSuperclasses isEmpty ifTrue:[ |
|
776 |
otherSuperclasses := nil |
|
777 |
]. |
|
778 |
SubclassInfo := nil. |
|
779 |
ObjectMemory flushCaches |
|
780 |
]. |
|
781 |
! |
|
782 |
||
783 |
selectorArray |
|
784 |
"return the receivers selector array. |
|
785 |
Notice: this is not compatible with ST-80." |
|
786 |
||
787 |
^ selectorArray |
|
788 |
! |
|
789 |
||
790 |
selectors |
|
791 |
"return the receivers selector array as an orderedCollection. |
|
792 |
Notice: this may not be compatible with ST-80. |
|
793 |
(should we return a Set ?)" |
|
794 |
||
795 |
^ selectorArray asOrderedCollection |
|
796 |
! |
|
797 |
||
798 |
selectors:newSelectors methods:newMethods |
|
799 |
"set both selector array and method array of the receiver, |
|
800 |
and flush caches" |
|
801 |
||
802 |
ObjectMemory flushCaches. |
|
803 |
selectorArray := newSelectors. |
|
804 |
methodArray := newMethods |
|
805 |
! |
|
806 |
||
807 |
superclass |
|
808 |
"return the receivers superclass" |
|
809 |
||
810 |
^ superclass |
|
811 |
! |
|
812 |
||
813 |
superclass:aClass |
|
814 |
"set the superclass - this actually creates a new class, |
|
815 |
recompiling all methods for the new one. The receiving class stays |
|
816 |
around anonymous to allow existing instances some life. |
|
817 |
This may change in the future (adjusting existing instances)" |
|
818 |
||
819 |
SubclassInfo := nil. |
|
820 |
||
821 |
"must flush caches since lookup chain changes" |
|
822 |
ObjectMemory flushCaches. |
|
823 |
||
824 |
" |
|
825 |
superclass := aClass |
|
826 |
" |
|
827 |
"for correct recompilation, just create a new class ..." |
|
828 |
||
829 |
aClass subclass:(self name) |
|
830 |
instanceVariableNames:(self instanceVariableString) |
|
831 |
classVariableNames:(self classVariableString) |
|
832 |
poolDictionaries:'' |
|
833 |
category:self category |
|
834 |
! ! |
|
835 |
||
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
836 |
!Behavior methodsFor:'accessing virtual instvars'! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
837 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
838 |
implicit_methodDict |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
839 |
"ST-80 compatibility behavior subclasses. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
840 |
This allows subclasses to assume there is an instance variable |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
841 |
named methodDict (compile them with implicit self-sends)." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
842 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
843 |
^ self methodDictionary |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
844 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
845 |
"Modified: 16.4.1996 / 18:09:44 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
846 |
! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
847 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
848 |
implicit_methodDict:aDictionary |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
849 |
"ST-80 compatibility behavior subclasses. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
850 |
This allows subclasses to assume there is an instance variable |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
851 |
named methodDict (compile them with implicit self-sends)." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
852 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
853 |
^ self error:'not allowed to set the methodDictionary' |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
854 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
855 |
"Modified: 16.4.1996 / 18:09:52 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
856 |
! ! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
857 |
|
620 | 858 |
!Behavior methodsFor:'autoload check'! |
859 |
||
860 |
autoload |
|
861 |
"force autoloading - do nothing here; |
|
862 |
redefined in Autoload; see comment there" |
|
863 |
||
864 |
^ self |
|
865 |
! |
|
866 |
||
867 |
isLoaded |
|
868 |
"return true, if the class has been loaded; |
|
869 |
redefined in Autoload; see comment there" |
|
870 |
||
871 |
^ true |
|
872 |
! ! |
|
873 |
||
874 |
!Behavior methodsFor:'binary storage'! |
|
875 |
||
876 |
binaryDefinitionFrom:stream manager:manager |
|
877 |
"sent during a binary read by the input manager. |
|
878 |
Read the definition on an empty instance (of my class) from stream. |
|
879 |
All pointer instances are left nil, while all bits are read in here. |
|
880 |
return the new object." |
|
881 |
||
882 |
|obj t |
|
883 |
basicSize "{ Class: SmallInteger }" | |
|
884 |
||
885 |
self isPointers ifTrue: [ |
|
886 |
"/ |
|
887 |
"/ inst size not needed - if you uncomment the line below, |
|
888 |
"/ also uncomment the corresponding line in |
|
889 |
"/ Object>>storeBinaryDefinitionOn:manager: |
|
890 |
"/ |
|
891 |
"/ stream next. "skip instSize" |
|
892 |
self isVariable ifTrue: [ |
|
893 |
^ self basicNew:(stream nextNumber:3) |
|
894 |
]. |
|
895 |
^ self basicNew |
|
896 |
]. |
|
308 | 897 |
|
898 |
" |
|
620 | 899 |
an object with bit-valued instance variables. |
900 |
These are read here. |
|
901 |
" |
|
902 |
basicSize := stream nextNumber:4. |
|
903 |
obj := self basicNew:basicSize. |
|
904 |
||
905 |
self isBytes ifTrue: [ |
|
906 |
stream nextBytes:basicSize into:obj |
|
907 |
] ifFalse: [ |
|
908 |
self isWords ifTrue: [ |
|
909 |
1 to:basicSize do:[:i | |
|
910 |
obj basicAt:i put:(stream nextNumber:2) |
|
911 |
] |
|
912 |
] ifFalse:[ |
|
913 |
self isLongs ifTrue: [ |
|
914 |
1 to:basicSize do:[:i | |
|
915 |
obj basicAt:i put:(stream nextNumber:4) |
|
916 |
] |
|
917 |
] ifFalse:[ |
|
918 |
self isFloats ifTrue: [ |
|
919 |
"could do it in one big read on machines which use IEEE floats ..." |
|
920 |
t := Float basicNew. |
|
921 |
1 to:basicSize do:[:i | |
|
922 |
Float readBinaryIEEESingleFrom:stream into:t. |
|
923 |
obj basicAt:i put: t |
|
924 |
] |
|
925 |
] ifFalse:[ |
|
926 |
self isDoubles ifTrue: [ |
|
927 |
"could do it in one big read on machines which use IEEE doubles ..." |
|
928 |
t := Float basicNew. |
|
929 |
1 to:basicSize do:[:i | |
|
930 |
Float readBinaryIEEEDoubleFrom:stream into:t. |
|
931 |
obj basicAt:i put: t |
|
932 |
] |
|
933 |
] |
|
934 |
] |
|
935 |
] |
|
936 |
] |
|
937 |
]. |
|
938 |
^obj |
|
939 |
! |
|
940 |
||
941 |
canCloneFrom:anObject |
|
942 |
"return true, if this class can clone an obsolete object as retrieved |
|
943 |
by a binary load. Subclasses which do not want to have obsolete objects |
|
944 |
be converted, should redefine this method to return false. |
|
945 |
(However, conversion is never done silently in a binary load; you |
|
946 |
have to have a handler for the binaryload errors and for the conversion |
|
947 |
request signal.)" |
|
948 |
||
949 |
^ true |
|
950 |
! |
|
951 |
||
952 |
cloneFrom:aPrototype |
|
953 |
"return an instance of myself with variables initialized from |
|
954 |
a prototype. This is used when instances of obsolete classes are |
|
955 |
binary loaded and a conversion is done on the obsolete object. |
|
956 |
UserClasses may redefine this for better conversions." |
|
957 |
||
958 |
|newInst indexed myInfo otherInfo varIndexAssoc| |
|
959 |
||
960 |
indexed := false. |
|
961 |
aPrototype class isVariable ifTrue:[ |
|
962 |
self isVariable ifTrue:[ |
|
963 |
indexed := true. |
|
964 |
]. |
|
965 |
"otherwise, these are lost ..." |
|
966 |
]. |
|
967 |
indexed ifTrue:[ |
|
968 |
newInst := self basicNew:aPrototype basicSize |
|
969 |
] ifFalse:[ |
|
970 |
newInst := self basicNew |
|
971 |
]. |
|
972 |
||
973 |
myInfo := self instanceVariableOffsets. |
|
974 |
otherInfo := aPrototype class instanceVariableOffsets. |
|
975 |
myInfo keysAndValuesDo:[:name :index | |
|
976 |
varIndexAssoc := otherInfo at:name ifAbsent:[]. |
|
977 |
varIndexAssoc notNil ifTrue:[ |
|
978 |
newInst instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
979 |
] |
|
980 |
]. |
|
981 |
indexed ifTrue:[ |
|
982 |
1 to:aPrototype basicSize do:[:index | |
|
983 |
newInst basicAt:index put:(aPrototype basicAt:index) |
|
984 |
]. |
|
985 |
]. |
|
986 |
^ newInst |
|
987 |
||
988 |
" |
|
989 |
Class withoutUpdatingChangesDo:[ |
|
990 |
Point subclass:#Point3D |
|
991 |
instanceVariableNames:'z' |
|
992 |
classVariableNames:'' |
|
993 |
poolDictionaries:'' |
|
994 |
category:'testing'. |
|
995 |
(Point3D cloneFrom:1@2) inspect. |
|
996 |
] |
|
997 |
" |
|
998 |
||
999 |
" |
|
1000 |
Class withoutUpdatingChangesDo:[ |
|
1001 |
Point variableSubclass:#Point3D |
|
1002 |
instanceVariableNames:'z' |
|
1003 |
classVariableNames:'' |
|
1004 |
poolDictionaries:'' |
|
1005 |
category:'testing'. |
|
1006 |
(Point3D cloneFrom:#(1 2 3)) inspect. |
|
1007 |
] |
|
1008 |
" |
|
1009 |
||
1010 |
" |
|
1011 |
|someObject| |
|
1012 |
||
1013 |
Class withoutUpdatingChangesDo:[ |
|
1014 |
Object subclass:#TestClass1 |
|
1015 |
instanceVariableNames:'foo bar' |
|
1016 |
classVariableNames:'' |
|
1017 |
poolDictionaries:'' |
|
1018 |
category:'testing'. |
|
1019 |
someObject := TestClass1 new. |
|
1020 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
1021 |
Object subclass:#TestClass2 |
|
1022 |
instanceVariableNames:'bar foo' |
|
1023 |
classVariableNames:'' |
|
1024 |
poolDictionaries:'' |
|
1025 |
category:'testing'. |
|
1026 |
(TestClass2 cloneFrom:someObject) inspect. |
|
1027 |
] |
|
1028 |
" |
|
1029 |
! |
|
1030 |
||
1031 |
readBinaryFrom:aStream |
|
1032 |
"read an objects binary representation from the argument, |
|
1033 |
aStream and return it. |
|
1034 |
The read object must be a kind of myself, otherwise an error is raised. |
|
1035 |
To get any object, use 'Object readBinaryFrom:...', |
|
1036 |
To get any number, use 'Number readBinaryFrom:...' and so on. |
|
1037 |
This is the reverse operation to 'storeBinaryOn:'. " |
|
1038 |
||
1039 |
^ self readBinaryFrom:aStream onError:[self error:('expected ' , self name)] |
|
1040 |
||
1041 |
" |
|
1042 |
|s| |
|
1043 |
s := WriteStream on:(ByteArray new). |
|
1044 |
#(1 2 3 4) storeBinaryOn:s. |
|
1045 |
Object readBinaryFrom:(ReadStream on:s contents) |
|
1046 |
" |
|
1047 |
" |
|
1048 |
|s| |
|
1049 |
s := 'testFile' asFilename writeStream binary. |
|
1050 |
#(1 2 3 4) storeBinaryOn:s. |
|
1051 |
'hello world' storeBinaryOn:s. |
|
1052 |
s close. |
|
1053 |
||
1054 |
s := 'testFile' asFilename readStream binary. |
|
1055 |
Transcript showCr:(Object readBinaryFrom:s). |
|
1056 |
Transcript showCr:(Object readBinaryFrom:s). |
|
1057 |
s close. |
|
1058 |
" |
|
1059 |
! |
|
1060 |
||
1061 |
readBinaryFrom:aStream onError:exceptionBlock |
|
1062 |
"read an objects binary representation from the argument, |
|
1063 |
aStream and return it. |
|
1064 |
The read object must be a kind of myself, otherwise the value of |
|
1065 |
the exceptionBlock is returned. |
|
1066 |
To get any object, use 'Object readBinaryFrom:...', |
|
1067 |
To get any number, use 'Number readBinaryFrom:...' and so on. |
|
1068 |
This is the reverse operation to 'storeBinaryOn:'. " |
|
1069 |
||
1070 |
|newObject| |
|
1071 |
||
1072 |
newObject := (BinaryInputManager new:1024) readFrom:aStream. |
|
1073 |
(newObject isKindOf:self) ifFalse:[^ exceptionBlock value]. |
|
1074 |
^ newObject |
|
1075 |
||
1076 |
" |
|
1077 |
|s| |
|
1078 |
s := WriteStream on:(ByteArray new). |
|
1079 |
#(1 2 3 4) storeBinaryOn:s. |
|
1080 |
Object readBinaryFrom:(ReadStream on:s contents) onError:['oops'] |
|
1081 |
" |
|
1082 |
" |
|
1083 |
|s| |
|
1084 |
s := WriteStream on:(ByteArray new). |
|
1085 |
#[1 2 3 4] storeBinaryOn:s. |
|
1086 |
Array readBinaryFrom:(ReadStream on:s contents) onError:['oops'] |
|
1087 |
" |
|
1088 |
! |
|
1089 |
||
1090 |
storeBinaryDefinitionOn: stream manager: manager |
|
1091 |
"binary store of a classes definition. |
|
1092 |
Classes will store the name only and restore by looking for |
|
1259 | 1093 |
that name in the Smalltalk dictionary. |
1094 |
This is an internal interface for binary storage mechanism." |
|
620 | 1095 |
|
1096 |
| myName | |
|
1097 |
||
1098 |
myName := self name. |
|
1099 |
stream nextNumber:4 put:self signature. |
|
1100 |
stream nextNumber:2 put:0. |
|
1101 |
stream nextNumber:2 put:myName size. |
|
1102 |
myName do:[:c| |
|
1259 | 1103 |
stream nextPut:c asciiValue |
620 | 1104 |
] |
1105 |
||
1106 |
" |
|
1107 |
|s| |
|
1108 |
s := WriteStream on:ByteArray new. |
|
1109 |
#(1 2 3 4) storeBinaryOn:s. |
|
1110 |
Object readBinaryFrom:(ReadStream on:s contents) |
|
1111 |
||
1112 |
|s| |
|
1113 |
s := WriteStream on:ByteArray new. |
|
1114 |
Rectangle storeBinaryOn:s. |
|
1115 |
Object readBinaryFrom:(ReadStream on:s contents) |
|
1116 |
" |
|
1259 | 1117 |
|
1118 |
"Modified: 23.4.1996 / 09:29:44 / cg" |
|
620 | 1119 |
! ! |
1120 |
||
1121 |
!Behavior methodsFor:'compiler interface'! |
|
1122 |
||
1123 |
compiler |
|
1124 |
"return the compiler to use for this class. |
|
1125 |
OBSOLETE: This is the old ST/X interface, kept for migration. |
|
1126 |
Dont use it - it will vanish." |
|
1127 |
||
1128 |
^ self compilerClass |
|
1129 |
! |
|
1130 |
||
1131 |
compilerClass |
|
1132 |
"return the compiler to use for this class - |
|
1133 |
this can be redefined in special classes, to get classes with |
|
1134 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1135 |
||
1136 |
^ Compiler |
|
1137 |
! |
|
1138 |
||
1139 |
evaluatorClass |
|
1140 |
"return the compiler to use for expression evaluation for this class - |
|
1141 |
this can be redefined in special classes, to get classes with |
|
1142 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1143 |
||
1144 |
^ Compiler |
|
1145 |
! ! |
|
1146 |
||
1147 |
!Behavior methodsFor:'copying'! |
|
1148 |
||
1149 |
deepCopy |
|
1150 |
"return a deep copy of the receiver |
|
1151 |
- return the receiver here - time will show if this is ok" |
|
1152 |
||
1153 |
^ self |
|
1154 |
! |
|
1155 |
||
1156 |
deepCopyUsing:aDictionary |
|
1157 |
"return a deep copy of the receiver |
|
1158 |
- return the receiver here - time will show if this is ok" |
|
1159 |
||
1160 |
^ self |
|
1161 |
! |
|
1162 |
||
1163 |
simpleDeepCopy |
|
1164 |
"return a deep copy of the receiver |
|
1165 |
- return the receiver here - time will show if this is ok" |
|
1166 |
||
1167 |
^ self |
|
1168 |
! ! |
|
1169 |
||
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1170 |
!Behavior methodsFor:'dummy changes management'! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1171 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1172 |
addChangeRecordForClassRemove:aClassName |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1173 |
"add a change record that some class has been removed. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1174 |
Defined as dummy here, since Behavior does not know about change management. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1175 |
(only Classes do). This allows different Behavior-like objects |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1176 |
(alien classes) to be handled by the browser as well." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1177 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1178 |
"Created: 16.4.1996 / 16:30:09 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1179 |
"Modified: 16.4.1996 / 18:10:35 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1180 |
! ! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1181 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1182 |
!Behavior methodsFor:'dummy fileOut'! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1183 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1184 |
fileOutDefinitionOn:aStream |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1185 |
"dummy fileOut defined here. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1186 |
This allows different Behavior-like objects |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1187 |
(alien classes) to be handled by the browser as well." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1188 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1189 |
^ self |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1190 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1191 |
"Created: 16.4.1996 / 16:28:01 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1192 |
! ! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1193 |
|
620 | 1194 |
!Behavior methodsFor:'enumerating'! |
1195 |
||
1196 |
allDerivedInstancesDo:aBlock |
|
1197 |
"evaluate aBlock for all of my instances and all instances of subclasses. |
|
1198 |
This method is going to be removed for protocol compatibility with |
|
1199 |
other STs; use allSubInstancesDo:" |
|
1200 |
||
1201 |
self obsoleteMethodWarning:'please use #allSubInstancesDo:'. |
|
1202 |
self allSubInstancesDo:aBlock |
|
1203 |
||
1204 |
" |
|
1205 |
StandardSystemView allDerivedInstancesDo:[:v | Transcript showCr:(v name)] |
|
1206 |
" |
|
1207 |
! |
|
1208 |
||
1209 |
allInstancesDo:aBlock |
|
1210 |
"evaluate aBlock for all of my instances" |
|
1211 |
||
1212 |
"/ ObjectMemory allObjectsDo:[:anObject | |
|
1213 |
"/ (anObject class == self) ifTrue:[ |
|
1214 |
"/ aBlock value:anObject |
|
1215 |
"/ ] |
|
1216 |
"/ ] |
|
1217 |
||
1218 |
ObjectMemory allInstancesOf:self do:[:anObject | |
|
1219 |
aBlock value:anObject |
|
1220 |
] |
|
1221 |
||
1222 |
" |
|
1223 |
StandardSystemView allInstancesDo:[:v | Transcript showCr:(v name)] |
|
1224 |
" |
|
1225 |
! |
|
1226 |
||
1227 |
allSubInstancesDo:aBlock |
|
1228 |
"evaluate aBlock for all of my instances and all instances of subclasses" |
|
1229 |
||
1230 |
ObjectMemory allObjectsDo:[:anObject | |
|
1231 |
(anObject isKindOf:self) ifTrue:[ |
|
1232 |
aBlock value:anObject |
|
1233 |
] |
|
1234 |
] |
|
1235 |
||
1236 |
" |
|
1237 |
StandardSystemView allSubInstancesDo:[:v | Transcript showCr:(v name)] |
|
1238 |
" |
|
1239 |
! |
|
1240 |
||
1241 |
allSubclassesDo:aBlock |
|
1242 |
"evaluate aBlock for all of my subclasses. |
|
1243 |
There is no specific order, in which the entries are enumerated. |
|
1244 |
This will only enumerate globally known classes - for anonymous |
|
1245 |
behaviors, you have to walk over all instances of Behavior." |
|
1246 |
||
1247 |
Smalltalk allBehaviorsDo:[:aClass | |
|
1248 |
(aClass isSubclassOf:self) ifTrue:[ |
|
1249 |
aBlock value:aClass |
|
1250 |
] |
|
1251 |
] |
|
1252 |
||
1253 |
" |
|
1254 |
Collection allSubclassesDo:[:c | Transcript showCr:(c name)] |
|
1255 |
" |
|
1256 |
! |
|
1257 |
||
1258 |
allSubclassesInOrderDo:aBlock |
|
1259 |
"evaluate aBlock for all of my subclasses. |
|
1260 |
Higher level subclasses will be enumerated before the deeper ones, |
|
1261 |
so the order in which aBlock gets called is ok to fileOut classes in |
|
1262 |
correct order for later fileIn. |
|
1263 |
This will only enumerate globally known classes - for anonymous |
|
1264 |
behaviors, you have to walk over all instances of Behavior" |
|
1265 |
||
1266 |
self subclassesDo:[:aClass | |
|
1267 |
aBlock value:aClass. |
|
1268 |
aClass allSubclassesInOrderDo:aBlock |
|
1269 |
] |
|
1270 |
||
1271 |
" |
|
1272 |
Collection allSubclassesInOrderDo:[:c | Transcript showCr:(c name)] |
|
1273 |
" |
|
1274 |
! |
|
1275 |
||
1276 |
allSuperclassesDo:aBlock |
|
1277 |
"evaluate aBlock for all of my superclasses" |
|
1278 |
||
1279 |
|theClass| |
|
1280 |
||
1281 |
theClass := superclass. |
|
1282 |
[theClass notNil] whileTrue:[ |
|
1283 |
aBlock value:theClass. |
|
1284 |
theClass := theClass superclass |
|
1285 |
] |
|
1286 |
||
1287 |
" |
|
1288 |
String allSuperclassesDo:[:c | Transcript showCr:(c name)] |
|
1289 |
" |
|
1290 |
! |
|
1291 |
||
1292 |
subclassesDo:aBlock |
|
1293 |
"evaluate the argument, aBlock for all immediate subclasses. |
|
1294 |
This will only enumerate globally known classes - for anonymous |
|
1295 |
behaviors, you have to walk over all instances of Behavior." |
|
1296 |
||
1297 |
|coll| |
|
1298 |
||
1299 |
SubclassInfo isNil ifTrue:[ |
|
1300 |
Behavior subclassInfo |
|
1301 |
]. |
|
1302 |
SubclassInfo notNil ifTrue:[ |
|
1303 |
coll := SubclassInfo at:self ifAbsent:nil. |
|
1304 |
coll notNil ifTrue:[ |
|
1305 |
coll do:aBlock. |
|
1306 |
]. |
|
1307 |
^ self |
|
1308 |
]. |
|
1309 |
||
1310 |
Smalltalk allBehaviorsDo:[:aClass | |
|
1311 |
(aClass superclass == self) ifTrue:[ |
|
1312 |
aBlock value:aClass |
|
1313 |
] |
|
1314 |
] |
|
1315 |
||
1316 |
" |
|
1317 |
Collection subclassesDo:[:c | Transcript showCr:(c name)] |
|
308 | 1318 |
" |
1319 |
! ! |
|
1320 |
||
1 | 1321 |
!Behavior methodsFor:'initialization'! |
1322 |
||
620 | 1323 |
deinitialize |
1324 |
"deinitialize is sent to a class before it is physically unloaded. |
|
1325 |
This is only done with classes which have been loaded in from a binary |
|
1326 |
file. Classes may release any primitive memory or other stuff which is |
|
1327 |
not visible to smalltalk (for example, release internal memory). |
|
1328 |
The default action here is to do nothing." |
|
1329 |
||
1330 |
^ self |
|
1331 |
! |
|
1332 |
||
1 | 1333 |
initialize |
442 | 1334 |
"initialize is sent to a class either during startup, |
1335 |
(for all statically compiled-in classes) or after a class |
|
1336 |
has been loaded into the system (either bytecodes or machinecode). |
|
1337 |
The default action here is to do nothing." |
|
1 | 1338 |
|
1339 |
^ self |
|
1340 |
! |
|
1341 |
||
328 | 1342 |
postAutoload |
442 | 1343 |
"postAutoload is sent to a class after it has been autoloaded. |
1344 |
This gives it a chance to arrange for automatic unloading to be done |
|
1345 |
after a while ... |
|
1346 |
This is NOT sent to statically compiled in or explicitely filedIn |
|
1347 |
classes. |
|
1348 |
The default action here is to do nothing." |
|
328 | 1349 |
|
1350 |
^ self |
|
1351 |
! |
|
1352 |
||
1 | 1353 |
reinitialize |
442 | 1354 |
"reinitialize is sent to a class when an image has been restarted. |
1355 |
I.e. when the system is restarted. |
|
1356 |
This gives classes a chance to flush any device dependent or otherwise |
|
1357 |
obsolete data which may be a leftover from the previous live. |
|
1358 |
The default action here is to do nothing." |
|
1359 |
||
1360 |
^ self |
|
11 | 1361 |
! ! |
1362 |
||
492
fa23b14f444b
renamed instance creation category
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
1363 |
!Behavior methodsFor:'instance creation'! |
1 | 1364 |
|
1365 |
basicNew |
|
54 | 1366 |
"return an instance of myself without indexed variables. |
1 | 1367 |
If the receiver-class has indexed instvars, the new object will have |
91 | 1368 |
a basicSize of zero - |
1369 |
i.e. 'aClass basicNew' is equivalent to 'aClass basicNew:0'. |
|
54 | 1370 |
|
1 | 1371 |
** Do not redefine this method in any class **" |
1372 |
||
1373 |
%{ /* NOCONTEXT */ |
|
81 | 1374 |
REGISTER OBJ newobj; |
1375 |
REGISTER char *nextPtr; |
|
91 | 1376 |
unsigned int instsize; |
1377 |
REGISTER unsigned int nInstVars; |
|
1 | 1378 |
|
54 | 1379 |
/* |
369 | 1380 |
* the following ugly code is nothing more than a __new() followed |
54 | 1381 |
* by a nilling of the new instance. |
91 | 1382 |
* Unrolled for a bit more speed since this is one of the central object |
1383 |
* allocation methods in the system |
|
54 | 1384 |
*/ |
1133 | 1385 |
nInstVars = __intVal(__INST(instSize)); |
92 | 1386 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
54 | 1387 |
|
983 | 1388 |
newobj = (OBJ) __newNextPtr; |
81 | 1389 |
nextPtr = ((char *)newobj) + instsize; |
1390 |
||
1391 |
/* |
|
1392 |
* dont argue about the goto and the arrangement below - it saves |
|
1393 |
* an extra nil-compare and branch in the common case ... |
|
91 | 1394 |
* (i.e. if no GC is needed, we fall through without a branch) |
81 | 1395 |
*/ |
983 | 1396 |
if (nextPtr < __newEndPtr) { |
154 | 1397 |
_objPtr(newobj)->o_size = instsize; |
1398 |
/* o_allFlags(newobj) = 0; */ |
|
983 | 1399 |
/* _objPtr(newobj)->o_space = __newSpace; */ |
1400 |
o_setAllFlags(newobj, __newSpace); |
|
91 | 1401 |
#ifdef ALIGN4 |
983 | 1402 |
__newNextPtr = nextPtr; |
91 | 1403 |
#else |
154 | 1404 |
if (instsize & (ALIGN-1)) { |
983 | 1405 |
__newNextPtr = (char *)newobj + (instsize & ~(ALIGN-1)) + ALIGN; |
154 | 1406 |
} else { |
983 | 1407 |
__newNextPtr = nextPtr; |
154 | 1408 |
} |
91 | 1409 |
#endif |
82 | 1410 |
|
1411 |
ok: |
|
1133 | 1412 |
__InstPtr(newobj)->o_class = self; |
369 | 1413 |
__qSTORE(newobj, self); |
82 | 1414 |
|
154 | 1415 |
if (nInstVars) { |
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1416 |
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4) |
1133 | 1417 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
82 | 1418 |
#else |
154 | 1419 |
REGISTER OBJ *op; |
82 | 1420 |
|
1133 | 1421 |
op = __InstPtr(newobj)->i_instvars; |
82 | 1422 |
|
91 | 1423 |
# if !defined(NEGATIVE_ADDRESSES) |
154 | 1424 |
/* |
1425 |
* knowing that nil is 0 |
|
1426 |
*/ |
|
91 | 1427 |
# if defined(FAST_OBJECT_MEMSET_DOUBLES_UNROLLED) |
154 | 1428 |
if (nInstVars > 8) { |
1429 |
*op++ = nil; /* for alignment */ |
|
1430 |
nInstVars--; |
|
1431 |
while (nInstVars >= 8) { |
|
1432 |
*(double *)op = 0.0; |
|
1433 |
((double *)op)[1] = 0.0; |
|
1434 |
((double *)op)[2] = 0.0; |
|
1435 |
((double *)op)[3] = 0.0; |
|
1436 |
op += 8; |
|
1437 |
nInstVars -= 8; |
|
1438 |
} |
|
1439 |
} |
|
1440 |
while (nInstVars != 0) { |
|
1441 |
*op++ = 0; |
|
1442 |
nInstVars--; |
|
1443 |
} |
|
82 | 1444 |
# else |
91 | 1445 |
# if defined(FAST_OBJECT_MEMSET_LONGLONG_UNROLLED) |
154 | 1446 |
if (nInstVars > 8) { |
1447 |
*op++ = nil; /* for alignment */ |
|
1448 |
nInstVars--; |
|
1449 |
while (nInstVars >= 8) { |
|
1450 |
*(long long *)op = 0; |
|
1451 |
((long long *)op)[1] = 0; |
|
1452 |
((long long *)op)[2] = 0; |
|
1453 |
((long long *)op)[3] = 0; |
|
1454 |
op += 8; |
|
1455 |
nInstVars -= 8; |
|
1456 |
} |
|
1457 |
} |
|
1458 |
while (nInstVars != 0) { |
|
1459 |
*op++ = 0; |
|
1460 |
nInstVars--; |
|
1461 |
} |
|
91 | 1462 |
|
1463 |
# else |
|
1464 |
# if defined(FAST_OBJECT_MEMSET_WORDS_UNROLLED) |
|
154 | 1465 |
while (nInstVars >= 8) { |
1466 |
*op = nil; |
|
1467 |
*(op+1) = nil; |
|
1468 |
*(op+2) = nil; |
|
1469 |
*(op+3) = nil; |
|
1470 |
*(op+4) = nil; |
|
1471 |
*(op+5) = nil; |
|
1472 |
*(op+6) = nil; |
|
1473 |
*(op+7) = nil; |
|
1474 |
op += 8; |
|
1475 |
nInstVars -= 8; |
|
1476 |
} |
|
1477 |
while (nInstVars != 0) { |
|
1478 |
*op++ = nil; |
|
1479 |
nInstVars--; |
|
1480 |
} |
|
91 | 1481 |
# else |
1482 |
# if defined(FAST_MEMSET) |
|
1133 | 1483 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE); |
91 | 1484 |
# else |
154 | 1485 |
do { |
1486 |
*op++ = nil; |
|
1487 |
nInstVars--; |
|
1488 |
} while (nInstVars != 0); |
|
91 | 1489 |
# endif |
82 | 1490 |
# endif |
1491 |
# endif |
|
1492 |
# endif |
|
1493 |
# else /* nil could be ~~ 0 */ |
|
154 | 1494 |
while (nInstVars >= 8) { |
1495 |
*op = nil; |
|
1496 |
*(op+1) = nil; |
|
1497 |
*(op+2) = nil; |
|
1498 |
*(op+3) = nil; |
|
1499 |
*(op+4) = nil; |
|
1500 |
*(op+5) = nil; |
|
1501 |
*(op+6) = nil; |
|
1502 |
*(op+7) = nil; |
|
1503 |
op += 8; |
|
1504 |
nInstVars -= 8; |
|
1505 |
} |
|
1506 |
while (nInstVars != 0) { |
|
1507 |
*op++ = nil; |
|
1508 |
nInstVars--; |
|
1509 |
} |
|
82 | 1510 |
# endif |
1511 |
#endif |
|
154 | 1512 |
} |
1513 |
RETURN ( newobj ); |
|
81 | 1514 |
} |
54 | 1515 |
|
92 | 1516 |
/* |
1517 |
* the slow case - a GC will occur |
|
1518 |
*/ |
|
834 | 1519 |
__PROTECT_CONTEXT__ |
369 | 1520 |
newobj = __new(instsize); |
834 | 1521 |
__UNPROTECT_CONTEXT__ |
82 | 1522 |
if (newobj != nil) goto ok; |
1 | 1523 |
%} |
2 | 1524 |
. |
68 | 1525 |
" |
1526 |
memory allocation failed. |
|
1527 |
When we arrive here, there was no memory, even after |
|
165 | 1528 |
a garbage collect. |
1529 |
This means, that the VM wanted to get some more memory from the |
|
1530 |
Operatingsystem, which was not kind enough to give it. |
|
1531 |
Bad luck - you should increase the swap space on your machine. |
|
68 | 1532 |
" |
127 | 1533 |
^ ObjectMemory allocationFailureSignal raise. |
1 | 1534 |
! |
1535 |
||
1536 |
basicNew:anInteger |
|
1537 |
"return an instance of myself with anInteger indexed variables. |
|
1538 |
If the receiver-class has no indexed instvars, this is only allowed |
|
1539 |
if the argument, anInteger is zero. |
|
1540 |
** Do not redefine this method in any class **" |
|
1541 |
||
1542 |
%{ /* NOCONTEXT */ |
|
1543 |
||
1544 |
OBJ newobj; |
|
154 | 1545 |
unsigned INT instsize, nInstVars; |
1546 |
INT nindexedinstvars; |
|
92 | 1547 |
unsigned INT flags; |
1548 |
#if ! defined(FAST_ARRAY_MEMSET) || defined(NEGATIVE_ADDRESSES) |
|
1 | 1549 |
REGISTER char *cp; |
1550 |
short *sp; |
|
1551 |
long *lp; |
|
1552 |
#endif |
|
1553 |
REGISTER OBJ *op; |
|
1554 |
float *fp; |
|
1555 |
double *dp; |
|
1556 |
||
249 | 1557 |
if (__isSmallInteger(anInteger)) { |
1133 | 1558 |
nindexedinstvars = __intVal(anInteger); |
154 | 1559 |
if (nindexedinstvars >= 0) { |
1133 | 1560 |
nInstVars = __intVal(__INST(instSize)); |
1561 |
flags = __intVal(__INST(flags)) & ARRAYMASK; |
|
154 | 1562 |
switch (flags) { |
1563 |
case BYTEARRAY: |
|
1564 |
instsize = OHDR_SIZE + nindexedinstvars; |
|
1565 |
if (nInstVars == 0) { |
|
835 | 1566 |
if (__CanDoQuickNew(instsize)) { |
154 | 1567 |
/* |
1568 |
* the most common case |
|
1569 |
*/ |
|
835 | 1570 |
__qCheckedNew(newobj, instsize); |
1133 | 1571 |
__InstPtr(newobj)->o_class = self; |
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1572 |
#if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
359 | 1573 |
nInstVars = nindexedinstvars >> 2; |
1574 |
if (nindexedinstvars & 3) nInstVars++; |
|
1133 | 1575 |
memset4(__InstPtr(newobj)->i_instvars, 0, nInstVars); |
357 | 1576 |
#else |
1577 |
# if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
|
1133 | 1578 |
memset(__InstPtr(newobj)->i_instvars, 0, nindexedinstvars); |
357 | 1579 |
# else |
1133 | 1580 |
cp = (char *)__InstPtr(newobj)->i_instvars; |
154 | 1581 |
while (nindexedinstvars >= sizeof(long)) { |
1582 |
*(long *)cp = 0; |
|
1583 |
cp += sizeof(long); |
|
1584 |
nindexedinstvars -= sizeof(long); |
|
1585 |
} |
|
1586 |
while (nindexedinstvars--) |
|
1587 |
*cp++ = '\0'; |
|
357 | 1588 |
# endif |
92 | 1589 |
#endif |
154 | 1590 |
RETURN ( newobj ); |
1591 |
} |
|
1592 |
} else { |
|
1593 |
instsize += __OBJS2BYTES__(nInstVars); |
|
1594 |
} |
|
834 | 1595 |
__PROTECT_CONTEXT__ |
835 | 1596 |
__qNew(newobj, instsize, SENDER); |
834 | 1597 |
__UNPROTECT_CONTEXT__ |
154 | 1598 |
if (newobj == nil) { |
1599 |
break; |
|
1600 |
} |
|
1133 | 1601 |
__InstPtr(newobj)->o_class = self; |
369 | 1602 |
__qSTORE(newobj, self); |
1603 |
||
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1604 |
#if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
357 | 1605 |
nInstVars = (instsize-OHDR_SIZE) >> 2; |
1606 |
if (instsize & 3) nInstVars++; |
|
1133 | 1607 |
memset4(__InstPtr(newobj)->i_instvars, 0, nInstVars); |
357 | 1608 |
#else |
1609 |
# if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
|
154 | 1610 |
/* |
1611 |
* knowing that nil is 0 |
|
1612 |
*/ |
|
1133 | 1613 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE); |
357 | 1614 |
# else |
1133 | 1615 |
op = __InstPtr(newobj)->i_instvars; |
154 | 1616 |
while (nInstVars--) |
1617 |
*op++ = nil; |
|
1618 |
cp = (char *)op; |
|
1619 |
while (nindexedinstvars >= sizeof(long)) { |
|
1620 |
*(long *)cp = 0; |
|
1621 |
cp += sizeof(long); |
|
1622 |
nindexedinstvars -= sizeof(long); |
|
1623 |
} |
|
1624 |
while (nindexedinstvars--) |
|
1625 |
*cp++ = '\0'; |
|
357 | 1626 |
# endif |
1 | 1627 |
#endif |
154 | 1628 |
RETURN ( newobj ); |
1629 |
break; |
|
1 | 1630 |
|
154 | 1631 |
case WORDARRAY: |
1632 |
instsize = OHDR_SIZE + |
|
1633 |
__OBJS2BYTES__(nInstVars) + |
|
1634 |
nindexedinstvars * sizeof(short); |
|
834 | 1635 |
__PROTECT_CONTEXT__ |
835 | 1636 |
__qNew(newobj, instsize, SENDER); |
834 | 1637 |
__UNPROTECT_CONTEXT__ |
154 | 1638 |
if (newobj == nil) { |
1639 |
break; |
|
1640 |
} |
|
1133 | 1641 |
__InstPtr(newobj)->o_class = self; |
369 | 1642 |
__qSTORE(newobj, self); |
1643 |
||
92 | 1644 |
#if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
154 | 1645 |
/* |
1646 |
* knowing that nil is 0 |
|
1647 |
*/ |
|
1133 | 1648 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
1 | 1649 |
#else |
1133 | 1650 |
op = __InstPtr(newobj)->i_instvars; |
154 | 1651 |
while (nInstVars--) |
1652 |
*op++ = nil; |
|
1653 |
sp = (short *)op; |
|
1654 |
while (nindexedinstvars--) |
|
1655 |
*sp++ = 0; |
|
1 | 1656 |
#endif |
154 | 1657 |
RETURN ( newobj ); |
1658 |
break; |
|
1 | 1659 |
|
154 | 1660 |
case LONGARRAY: |
1661 |
instsize = OHDR_SIZE + |
|
1662 |
__OBJS2BYTES__(nInstVars) + |
|
1663 |
nindexedinstvars * sizeof(long); |
|
834 | 1664 |
__PROTECT_CONTEXT__ |
835 | 1665 |
__qAlignedNew(newobj, instsize, SENDER); |
834 | 1666 |
__UNPROTECT_CONTEXT__ |
154 | 1667 |
if (newobj == nil) { |
1668 |
break; |
|
1669 |
} |
|
1133 | 1670 |
__InstPtr(newobj)->o_class = self; |
369 | 1671 |
__qSTORE(newobj, self); |
1672 |
||
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1673 |
#if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
154 | 1674 |
/* |
1675 |
* knowing that nil is 0 |
|
1676 |
*/ |
|
1133 | 1677 |
memset4(__InstPtr(newobj)->i_instvars, 0, nInstVars + nindexedinstvars); |
1 | 1678 |
#else |
92 | 1679 |
# if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
154 | 1680 |
/* |
1681 |
* knowing that nil is 0 |
|
1682 |
*/ |
|
1133 | 1683 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
1 | 1684 |
# else |
1133 | 1685 |
op = __InstPtr(newobj)->i_instvars; |
154 | 1686 |
while (nInstVars--) |
1687 |
*op++ = nil; |
|
1688 |
lp = (long *)op; |
|
1689 |
while (nindexedinstvars--) |
|
1690 |
*lp++ = 0; |
|
1 | 1691 |
# endif |
1692 |
#endif |
|
154 | 1693 |
RETURN ( newobj ); |
1694 |
break; |
|
1 | 1695 |
|
154 | 1696 |
case FLOATARRAY: |
325 | 1697 |
instsize = sizeof(struct __floatArray) + |
154 | 1698 |
__OBJS2BYTES__(nInstVars) + |
1699 |
(nindexedinstvars - 1) * sizeof(float); |
|
54 | 1700 |
|
834 | 1701 |
__PROTECT_CONTEXT__ |
835 | 1702 |
__qNew(newobj, instsize, SENDER); |
834 | 1703 |
__UNPROTECT_CONTEXT__ |
154 | 1704 |
if (newobj == nil) { |
1705 |
break; |
|
1706 |
} |
|
1133 | 1707 |
__InstPtr(newobj)->o_class = self; |
369 | 1708 |
__qSTORE(newobj, self); |
1709 |
||
1133 | 1710 |
op = __InstPtr(newobj)->i_instvars; |
92 | 1711 |
# if defined(mips) /* knowin that float 0.0 is all-zeros */ |
1133 | 1712 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
92 | 1713 |
# else |
154 | 1714 |
while (nInstVars--) |
1715 |
*op++ = nil; |
|
1716 |
fp = (float *)op; |
|
1717 |
while (nindexedinstvars--) |
|
1718 |
*fp++ = 0.0; |
|
92 | 1719 |
# endif |
154 | 1720 |
RETURN ( newobj ); |
1721 |
break; |
|
1 | 1722 |
|
154 | 1723 |
case DOUBLEARRAY: |
325 | 1724 |
instsize = sizeof(struct __doubleArray) + |
154 | 1725 |
__OBJS2BYTES__(nInstVars) + |
1726 |
(nindexedinstvars - 1) * sizeof(double); |
|
54 | 1727 |
|
834 | 1728 |
__PROTECT_CONTEXT__ |
835 | 1729 |
__qAlignedNew(newobj, instsize, SENDER); |
834 | 1730 |
__UNPROTECT_CONTEXT__ |
154 | 1731 |
if (newobj == nil) { |
1732 |
break; |
|
1733 |
} |
|
1133 | 1734 |
__InstPtr(newobj)->o_class = self; |
369 | 1735 |
__qSTORE(newobj, self); |
1736 |
||
1133 | 1737 |
op = __InstPtr(newobj)->i_instvars; |
154 | 1738 |
while (nInstVars--) |
1739 |
*op++ = nil; |
|
54 | 1740 |
#ifdef NEED_DOUBLE_ALIGN |
154 | 1741 |
/* |
1742 |
* care for double alignment |
|
1743 |
*/ |
|
1744 |
if ((INT)op & (ALIGN-1)) { |
|
1745 |
*op++ = nil; |
|
1746 |
} |
|
54 | 1747 |
#endif |
154 | 1748 |
dp = (double *)op; |
1749 |
while (nindexedinstvars--) |
|
1750 |
*dp++ = 0.0; |
|
1751 |
RETURN ( newobj ); |
|
1752 |
break; |
|
1 | 1753 |
|
154 | 1754 |
case WKPOINTERARRAY: |
1755 |
case POINTERARRAY: |
|
1756 |
nInstVars += nindexedinstvars; |
|
1757 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
834 | 1758 |
__PROTECT_CONTEXT__ |
835 | 1759 |
__qAlignedNew(newobj, instsize, SENDER); |
834 | 1760 |
__UNPROTECT_CONTEXT__ |
154 | 1761 |
if (newobj == nil) { |
1762 |
break; |
|
1763 |
} |
|
1133 | 1764 |
__InstPtr(newobj)->o_class = self; |
369 | 1765 |
__qSTORE(newobj, self); |
1766 |
||
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1767 |
#if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
1133 | 1768 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
1 | 1769 |
#else |
82 | 1770 |
# if !defined(NEGATIVE_ADDRESSES) |
154 | 1771 |
/* |
1772 |
* knowing that nil is 0 |
|
1773 |
*/ |
|
360 | 1774 |
#ifdef XXmips |
92 | 1775 |
# undef FAST_ARRAY_MEMSET_DOUBLES_UNROLLED |
1776 |
# undef FAST_ARRAY_MEMSET_LONGLONG_UNROLLED |
|
198 | 1777 |
/* seems to be slightly faster */ |
92 | 1778 |
# define FAST_ARRAY_MEMSET |
1779 |
#endif |
|
1780 |
#ifdef sparc |
|
1781 |
# define FAST_ARRAY_MEMSET_DOUBLES_UNROLLED |
|
1782 |
#endif |
|
1783 |
||
91 | 1784 |
# if defined(FAST_ARRAY_MEMSET_DOUBLES_UNROLLED) |
1133 | 1785 |
op = __InstPtr(newobj)->i_instvars; |
154 | 1786 |
if (nInstVars > 8) { |
1787 |
*op++ = nil; /* for alignment */ |
|
1788 |
nInstVars--; |
|
1789 |
while (nInstVars >= 8) { |
|
1790 |
*(double *)op = 0.0; |
|
1791 |
((double *)op)[1] = 0.0; |
|
1792 |
((double *)op)[2] = 0.0; |
|
1793 |
((double *)op)[3] = 0.0; |
|
1794 |
op += 8; |
|
1795 |
nInstVars -= 8; |
|
1796 |
} |
|
1797 |
} |
|
1798 |
while (nInstVars) { |
|
1799 |
*op++ = 0; |
|
1800 |
nInstVars--; |
|
1801 |
} |
|
82 | 1802 |
# else |
91 | 1803 |
# if defined(FAST_ARRAY_MEMSET_LONGLONG_UNROLLED) |
1133 | 1804 |
op = __InstPtr(newobj)->i_instvars; |
154 | 1805 |
if (nInstVars > 8) { |
1806 |
*op++ = nil; /* for alignment */ |
|
1807 |
nInstVars--; |
|
1808 |
while (nInstVars >= 8) { |
|
1809 |
*(long long *)op = 0; |
|
1810 |
((long long *)op)[1] = 0; |
|
1811 |
((long long *)op)[2] = 0; |
|
1812 |
((long long *)op)[3] = 0; |
|
1813 |
op += 8; |
|
1814 |
nInstVars -= 8; |
|
1815 |
} |
|
1816 |
} |
|
1817 |
while (nInstVars) { |
|
1818 |
*op++ = 0; |
|
1819 |
nInstVars--; |
|
1820 |
} |
|
91 | 1821 |
# else |
1822 |
# if defined(FAST_ARRAY_MEMSET) |
|
1133 | 1823 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
91 | 1824 |
# else |
1133 | 1825 |
op = __InstPtr(newobj)->i_instvars; |
154 | 1826 |
while (nInstVars--) |
1827 |
*op++ = nil; |
|
91 | 1828 |
# endif |
82 | 1829 |
# endif |
1830 |
# endif |
|
1831 |
# else |
|
1133 | 1832 |
op = __InstPtr(newobj)->i_instvars; |
154 | 1833 |
while (nInstVars--) |
1834 |
*op++ = nil; |
|
1 | 1835 |
# endif |
1836 |
#endif |
|
154 | 1837 |
RETURN ( newobj ); |
1838 |
break; |
|
1 | 1839 |
|
154 | 1840 |
default: |
1841 |
/* |
|
1842 |
* new:n for non-variable classes only allowed if |
|
1843 |
* n == 0 |
|
1844 |
*/ |
|
1845 |
if (nindexedinstvars == 0) { |
|
1846 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
834 | 1847 |
__PROTECT_CONTEXT__ |
835 | 1848 |
__qAlignedNew(newobj, instsize, SENDER); |
834 | 1849 |
__UNPROTECT_CONTEXT__ |
154 | 1850 |
if (newobj == nil) { |
1851 |
break; |
|
1852 |
} |
|
1133 | 1853 |
__InstPtr(newobj)->o_class = self; |
369 | 1854 |
__qSTORE(newobj, self); |
1855 |
||
154 | 1856 |
if (nInstVars) { |
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1857 |
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4) |
1133 | 1858 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
1 | 1859 |
#else |
1860 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES) |
|
154 | 1861 |
/* |
1862 |
* knowing that nil is 0 |
|
1863 |
*/ |
|
1133 | 1864 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
1 | 1865 |
# else |
1133 | 1866 |
op = __InstPtr(newobj)->i_instvars; |
154 | 1867 |
do { |
1868 |
*op++ = nil; |
|
1869 |
} while (--nInstVars); |
|
1 | 1870 |
# endif |
1871 |
#endif |
|
154 | 1872 |
} |
1873 |
RETURN ( newobj ); |
|
1874 |
} |
|
1875 |
break; |
|
1876 |
} |
|
1877 |
} |
|
1 | 1878 |
} |
68 | 1879 |
%}. |
1880 |
" |
|
1881 |
arrive here if something went wrong ... |
|
1882 |
figure out what it was |
|
1883 |
" |
|
11 | 1884 |
|
1 | 1885 |
(anInteger isMemberOf:SmallInteger) ifFalse:[ |
154 | 1886 |
" |
1887 |
the argument is either not an integer, |
|
1888 |
or a LargeInteger (which means that its definitely too big) |
|
1889 |
" |
|
1890 |
self error:'argument to new: must be Integer'. |
|
1891 |
^ nil |
|
68 | 1892 |
]. |
1893 |
(anInteger < 0) ifTrue:[ |
|
154 | 1894 |
" |
1895 |
the argument is negative, |
|
1896 |
" |
|
1897 |
self error:'bad (negative) argument to new:'. |
|
1898 |
^ nil |
|
68 | 1899 |
]. |
1900 |
self isVariable ifFalse:[ |
|
154 | 1901 |
" |
1902 |
this class does not have any indexed instance variables |
|
1903 |
" |
|
1904 |
self error:'class has no indexed instvars - cannot create with new:'. |
|
1905 |
^ nil |
|
68 | 1906 |
]. |
1907 |
" |
|
1908 |
memory allocation failed. |
|
1909 |
When we arrive here, there was no memory, even after |
|
165 | 1910 |
a garbage collect. |
1911 |
This means, that the VM wanted to get some more memory from the |
|
1912 |
Operatingsystem, which was not kind enough to give it. |
|
1913 |
Bad luck - you should increase the swap space on your machine. |
|
68 | 1914 |
" |
127 | 1915 |
^ ObjectMemory allocationFailureSignal raise. |
11 | 1916 |
! |
1917 |
||
620 | 1918 |
new |
1919 |
"return an instance of myself without indexed variables" |
|
1920 |
||
1921 |
^ self basicNew |
|
1922 |
! |
|
1923 |
||
1924 |
new:anInteger |
|
1925 |
"return an instance of myself with anInteger indexed variables" |
|
1926 |
||
1927 |
^ self basicNew:anInteger |
|
1928 |
! |
|
1929 |
||
1930 |
niceBasicNew:anInteger |
|
1931 |
"same as basicNew:anInteger, but tries to avoid long pauses |
|
1932 |
due to garbage collection. This method checks to see if |
|
1933 |
allocation is possible without a pause, and does a background |
|
1934 |
incremental garbage collect first if there is not enough memory |
|
1935 |
available at the moment for fast allocation. |
|
1936 |
This is useful in low-priority background processes which like to |
|
1937 |
avoid disturbing any higher priority foreground process while allocating |
|
1938 |
big amounts of memory. Of course, using this method only makes |
|
1939 |
sense for big or huge objects (say > 200k). |
|
1940 |
||
1941 |
EXPERIMENTAL: this is a non-standard interface and should only |
|
1942 |
be used for special applications. There is no guarantee, that this |
|
1943 |
method will be available in future ST/X releases." |
|
1944 |
||
1945 |
|size| |
|
1946 |
||
1947 |
size := self sizeOfInst:anInteger. |
|
1948 |
(ObjectMemory checkForFastNew:size) ifFalse:[ |
|
1949 |
" |
|
1950 |
incrementally collect garbage |
|
1951 |
" |
|
1952 |
ObjectMemory incrementalGC. |
|
1953 |
]. |
|
1954 |
^ self basicNew:anInteger |
|
1955 |
! |
|
1956 |
||
11 | 1957 |
readFrom:aStream |
43 | 1958 |
"read an objects printed representation from the argument, aStream |
1959 |
and return it. |
|
154 | 1960 |
The read object must be a kind of myself if its not, an error is raised. |
11 | 1961 |
This is the reverse operation to 'storeOn:'. |
43 | 1962 |
|
68 | 1963 |
WARNING: storeOn: does not handle circular references and multiple |
198 | 1964 |
references to the same object. |
1965 |
Use #storeBinary:/readBinaryFrom: for this." |
|
11 | 1966 |
|
345 | 1967 |
^ self readFrom:aStream onError:[self error:'expected: ' , self name] |
11 | 1968 |
|
91 | 1969 |
" |
1970 |
|s| |
|
11 | 1971 |
s := WriteStream on:String new. |
1972 |
#(1 2 3 4) storeOn:s. |
|
1973 |
Object readFrom:(ReadStream on:s contents) |
|
1974 |
" |
|
1975 |
! |
|
1976 |
||
198 | 1977 |
readFrom:aStream onError:exceptionBlock |
1978 |
"read an objects printed representation from the argument, aStream |
|
1979 |
and return it (i.e. the stream should contain some representation of |
|
1980 |
the object which was created using #storeOn:). |
|
1981 |
The read object must be a kind of myself if its not, the value of |
|
1982 |
exceptionBlock is returned. |
|
1983 |
To get any object, use 'Object readFrom:...', |
|
1984 |
To get any number, use 'Number readFrom:...' and so on. |
|
1985 |
This is the reverse operation to 'storeOn:'. |
|
1986 |
||
1987 |
WARNING: storeOn: does not handle circular references and multiple |
|
1988 |
references to the same object. |
|
1989 |
Use #storeBinary:/readBinaryFrom: for this." |
|
1990 |
||
1991 |
|newObject| |
|
1992 |
||
340 | 1993 |
ErrorSignal handle:[:ex | |
1994 |
ex return |
|
1995 |
] do:[ |
|
345 | 1996 |
newObject := self evaluatorClass evaluate:aStream. |
340 | 1997 |
]. |
198 | 1998 |
(newObject isKindOf:self) ifFalse:[^ exceptionBlock value]. |
1999 |
^ newObject |
|
2000 |
||
2001 |
" |
|
2002 |
|s| |
|
2003 |
s := WriteStream on:String new. |
|
2004 |
#(1 2 3 4) storeOn:s. |
|
293 | 2005 |
Transcript showCr:( |
2006 |
Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
|
2007 |
) |
|
198 | 2008 |
" |
2009 |
" |
|
2010 |
|s| |
|
2011 |
s := WriteStream on:String new. |
|
2012 |
#[1 2 3 4] storeOn:s. |
|
293 | 2013 |
Transcript showCr:( |
2014 |
Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
|
345 | 2015 |
) |
198 | 2016 |
" |
2017 |
! |
|
2018 |
||
11 | 2019 |
readFromString:aString |
275 | 2020 |
"create an object from its printed representation. |
2021 |
For most classes, the string is expected to be in a format created by |
|
2022 |
storeOn: or storeString; however, some (Time, Date) expect a user |
|
2023 |
readable string here. |
|
2024 |
See comments in Behavior>>readFromString:onError:, |
|
2025 |
Behavior>>readFrom: and Behavior>>readFrom:onError:" |
|
11 | 2026 |
|
345 | 2027 |
^ self readFromString:aString onError:[self error:'expected: ' , self name] |
91 | 2028 |
|
2029 |
" |
|
2030 |
Integer readFromString:'12345678901234567890' |
|
2031 |
Point readFromString:'1@2' |
|
345 | 2032 |
Point readFromString:'1' |
91 | 2033 |
" |
198 | 2034 |
! |
2035 |
||
2036 |
readFromString:aString onError:exceptionBlock |
|
275 | 2037 |
"create an object from its printed representation. |
2038 |
Here, the string is expected to be in a format created by |
|
2039 |
storeOn: or storeString; however, some classes (Time, Date) may redefine |
|
2040 |
it to expect a user readable string here. |
|
198 | 2041 |
See comments in Behavior>>readFrom: and Behavior>>readFrom:onError:" |
2042 |
||
2043 |
^ self readFrom:(ReadStream on:aString) onError:exceptionBlock |
|
2044 |
||
2045 |
" |
|
2046 |
Integer readFromString:'12345678901234567890' |
|
275 | 2047 |
Integer readFromString:'abc' |
2048 |
Integer readFromString:'abc' onError:0 |
|
198 | 2049 |
Point readFromString:'1@2' |
345 | 2050 |
Point readFromString:'0' |
275 | 2051 |
Point readFromString:'0' onError:[0@0] |
198 | 2052 |
" |
620 | 2053 |
! |
2054 |
||
2055 |
uninitializedNew |
|
2056 |
"create an instance of myself with uninitialized contents. |
|
2057 |
For all classes except ByteArray, this is the same as #basicNew." |
|
2058 |
||
2059 |
^ self basicNew |
|
2060 |
! |
|
2061 |
||
2062 |
uninitializedNew:anInteger |
|
2063 |
"create an instance of myself with uninitialized contents. |
|
2064 |
For all classes except ByteArray, this is the same as #basicNew:." |
|
2065 |
||
2066 |
^ self basicNew:anInteger |
|
1 | 2067 |
! ! |
2068 |
||
620 | 2069 |
!Behavior methodsFor:'private accessing'! |
2070 |
||
2071 |
flags:aNumber |
|
2072 |
"set the flags. |
|
2073 |
this method is for special uses only - there will be no recompilation |
|
2074 |
and no change record written here; |
|
2075 |
Do NOT use it." |
|
2076 |
||
2077 |
flags := aNumber |
|
2078 |
! |
|
2079 |
||
2080 |
instSize:aNumber |
|
2081 |
"set the instance size. |
|
2082 |
this method is for special uses only - there will be no recompilation |
|
2083 |
and no change record written here; |
|
2084 |
Do NOT use it." |
|
2085 |
||
2086 |
instSize := aNumber |
|
2087 |
! |
|
2088 |
||
2089 |
primAddSelector:newSelector withMethod:newMethod |
|
2090 |
"add the method given by 2nd argument under the selector given by |
|
2091 |
the 1st argument to the methodDictionary. |
|
2092 |
Does NOT flush any caches, does NOT write a change record. |
|
2093 |
||
2094 |
Do not use this in normal situations, strange behavior will be |
|
2095 |
the consequence. |
|
2096 |
I.e. executing obsolete methods, since the old method will still |
|
2097 |
be executed out of the caches." |
|
2098 |
||
2099 |
|index oldSelectorArray oldMethodArray newSelectorArray newMethodArray| |
|
2100 |
||
2101 |
(newSelector isMemberOf:Symbol) ifFalse:[ |
|
2102 |
self error:'invalid selector'. |
|
2103 |
^ false |
|
2104 |
]. |
|
2105 |
newMethod isNil ifTrue:[ |
|
2106 |
self error:'invalid method'. |
|
2107 |
^ false |
|
2108 |
]. |
|
2109 |
||
2110 |
index := selectorArray identityIndexOf:newSelector startingAt:1. |
|
2111 |
(index == 0) ifTrue:[ |
|
2112 |
" |
|
2113 |
a new selector |
|
2114 |
" |
|
2115 |
newSelectorArray := selectorArray copyWith:newSelector. |
|
2116 |
newMethodArray := methodArray copyWith:newMethod. |
|
2117 |
" |
|
2118 |
keep a reference so they wont go away ... |
|
2119 |
mhmh: this is no longer needed - try without |
|
2120 |
" |
|
2121 |
oldSelectorArray := selectorArray. |
|
2122 |
oldMethodArray := methodArray. |
|
2123 |
selectorArray := newSelectorArray. |
|
2124 |
methodArray := newMethodArray |
|
2125 |
] ifFalse:[ |
|
2126 |
methodArray at:index put:newMethod |
|
2127 |
]. |
|
2128 |
^ true |
|
2129 |
! |
|
2130 |
||
2131 |
setMethodArray:anArray |
|
2132 |
"set the method array of the receiver. |
|
2133 |
this method is for special uses only - there will be no recompilation |
|
2134 |
and no change record written here. |
|
2135 |
NOT for general use." |
|
2136 |
||
2137 |
methodArray := anArray |
|
2138 |
! |
|
2139 |
||
2140 |
setMethodDictionary:aDictionary |
|
2141 |
"set the receivers method dictionary. |
|
2142 |
Since no dictionary is actually used, decompose into selector- and |
|
2143 |
method arrays and set those. For ST-80 compatibility. |
|
2144 |
NOT for general use." |
|
2145 |
||
2146 |
|n newSelectorArray newMethodArray idx| |
|
2147 |
||
2148 |
n := aDictionary size. |
|
2149 |
newSelectorArray := Array basicNew:n. |
|
2150 |
newMethodArray := Array basicNew:n. |
|
2151 |
idx := 1. |
|
2152 |
aDictionary keysAndValuesDo:[:sel :method | |
|
2153 |
newSelectorArray at:idx put:sel. |
|
2154 |
newMethodArray at:idx put:method. |
|
2155 |
idx := idx + 1 |
|
2156 |
]. |
|
2157 |
selectorArray := newSelectorArray. |
|
2158 |
methodArray := newMethodArray |
|
2159 |
! |
|
2160 |
||
2161 |
setOtherSuperclasses:anArrayOfClasses |
|
2162 |
"EXPERIMENTAL: set the other superclasses of the receiver. |
|
2163 |
this method is for special uses only - there will be no recompilation |
|
2164 |
and no change record written here; |
|
2165 |
Do NOT use it." |
|
2166 |
||
2167 |
SubclassInfo := nil. |
|
2168 |
otherSuperclasses := anArrayOfClasses |
|
2169 |
! |
|
2170 |
||
2171 |
setSelectorArray:anArray |
|
2172 |
"set the selector array of the receiver. |
|
2173 |
this method is for special uses only - there will be no recompilation |
|
2174 |
and no change record written here. |
|
2175 |
NOT for general use." |
|
2176 |
||
2177 |
selectorArray := anArray |
|
2178 |
! |
|
2179 |
||
2180 |
setSelectors:sels methods:m |
|
2181 |
"set some inst vars. |
|
2182 |
this method is for special uses only - there will be no recompilation |
|
2183 |
and no change record written here; |
|
2184 |
Do NOT use it." |
|
2185 |
||
2186 |
selectorArray := sels. |
|
2187 |
methodArray := m. |
|
2188 |
! |
|
2189 |
||
2190 |
setSuperclass:aClass |
|
2191 |
"set the superclass of the receiver. |
|
2192 |
this method is for special uses only - there will be no recompilation |
|
2193 |
and no change record written here. Also, if the receiver class has |
|
2194 |
already been in use, future operation of the system is not guaranteed to |
|
2195 |
be correct, since no caches are flushed. |
|
2196 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)" |
|
2197 |
||
2198 |
SubclassInfo := nil. |
|
2199 |
superclass := aClass |
|
2200 |
! |
|
2201 |
||
2202 |
setSuperclass:sup selectors:sels methods:m instSize:i flags:f |
|
2203 |
"set some inst vars. |
|
2204 |
this method is for special uses only - there will be no recompilation |
|
2205 |
and no change record is written here. Also, if the receiver class has |
|
2206 |
already been in use, future operation of the system is not guaranteed to |
|
2207 |
be correct, since no caches are flushed. |
|
2208 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)" |
|
2209 |
||
2210 |
SubclassInfo := nil. |
|
2211 |
superclass := sup. |
|
2212 |
selectorArray := sels. |
|
2213 |
methodArray := m. |
|
2214 |
instSize := i. |
|
2215 |
flags := f |
|
2216 |
! ! |
|
2217 |
||
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2218 |
!Behavior methodsFor:'private helpers'! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2219 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2220 |
addAllClassVarNamesTo:aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2221 |
"helper - add the name-strings of the class variables and of the class-vars |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2222 |
of all superclasses to the argument, aCollection. Return aCollection" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2223 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2224 |
|classvars| |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2225 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2226 |
(superclass notNil) ifTrue:[ |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2227 |
superclass addAllClassVarNamesTo:aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2228 |
]. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2229 |
(classvars := self classVariableString) notNil ifTrue:[ |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2230 |
aCollection addAll:(classvars asCollectionOfWords). |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2231 |
]. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2232 |
^ aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2233 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2234 |
"Created: 16.4.1996 / 18:00:38 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2235 |
! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2236 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2237 |
addAllInstVarNamesTo:aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2238 |
"helper for allInstVarNames - add the name-strings of the instance variables |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2239 |
and of the inst-vars of all superclasses to the argument, aCollection. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2240 |
Return aCollection." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2241 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2242 |
|superInsts instvars| |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2243 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2244 |
(superclass notNil) ifTrue:[ |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2245 |
superclass addAllInstVarNamesTo:aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2246 |
]. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2247 |
(instvars := self instanceVariableString) notNil ifTrue:[ |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2248 |
aCollection addAll:(instvars asCollectionOfWords). |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2249 |
] ifFalse:[ |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2250 |
"/ mhmh - either someone klduged around, or this is |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2251 |
"/ a system running without sourceInfo. Generate |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2252 |
"/ synthetic names. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2253 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2254 |
superclass isNil ifTrue:[ |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2255 |
superInsts := 0 |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2256 |
] ifFalse:[ |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2257 |
superInsts := superclass instSize |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2258 |
]. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2259 |
aCollection addAll:((superInsts+1 to:self instSize) |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2260 |
collect:[:index | '* instVar' , index printString , ' *']) |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2261 |
]. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2262 |
^ aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2263 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2264 |
"Modified: 30.10.1995 / 19:46:21 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2265 |
"Created: 16.4.1996 / 18:03:14 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2266 |
! ! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2267 |
|
620 | 2268 |
!Behavior methodsFor:'queries'! |
2269 |
||
2270 |
allClassVarNames |
|
2271 |
"return a collection of all the class variable name-strings |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2272 |
this includes all superclass-class variables" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2273 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2274 |
^ self addAllClassVarNamesTo:(OrderedCollection new) |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2275 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2276 |
" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2277 |
Float allClassVarNames |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2278 |
" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2279 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2280 |
"Modified: 16.4.1996 / 18:01:00 / cg" |
620 | 2281 |
! |
2282 |
||
2283 |
allDerivedInstances |
|
2284 |
"return a collection of all instances of myself and |
|
2285 |
instances of all subclasses of myself. |
|
2286 |
This method is going to be removed for protocol compatibility with |
|
2287 |
other STs; use allSubInstances" |
|
2288 |
||
2289 |
self obsoleteMethodWarning:'please use #allSubInstances'. |
|
2290 |
^ self allSubInstances |
|
2291 |
! |
|
2292 |
||
2293 |
allInstVarNames |
|
2294 |
"return a collection of all the instance variable name-strings |
|
2295 |
this includes all superclass-instance variables. |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2296 |
Instvars of superclasses come first (i.e. the position matches |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2297 |
the instVarAt:-index)." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2298 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2299 |
^ self addAllInstVarNamesTo:(OrderedCollection new) |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2300 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2301 |
" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2302 |
Dictionary instVarNames |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2303 |
Dictionary allInstVarNames |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2304 |
" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2305 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2306 |
"Modified: 16.4.1996 / 18:03:55 / cg" |
620 | 2307 |
! |
2308 |
||
2309 |
allInstances |
|
2310 |
"return a collection of all my instances" |
|
2311 |
||
2312 |
"Read the documentation on why there seem to be no |
|
2313 |
instances of SmallInteger and UndefinedObject" |
|
2314 |
||
2315 |
|coll| |
|
2316 |
||
2317 |
coll := OrderedCollection new:100. |
|
2318 |
self allInstancesDo:[:anObject | |
|
2319 |
coll add:anObject |
|
2320 |
]. |
|
2321 |
^ coll |
|
2322 |
||
2323 |
" |
|
2324 |
ScrollBar allInstances |
|
2325 |
" |
|
2326 |
! |
|
2327 |
||
2328 |
allSubInstances |
|
2329 |
"return a collection of all instances of myself and |
|
2330 |
instances of all subclasses of myself." |
|
2331 |
||
2332 |
|coll| |
|
2333 |
||
2334 |
coll := OrderedCollection new:100. |
|
2335 |
self allSubInstancesDo:[:anObject | |
|
2336 |
(anObject isKindOf:self) ifTrue:[ |
|
2337 |
coll add:anObject |
|
2338 |
] |
|
2339 |
]. |
|
2340 |
^ coll |
|
2341 |
||
2342 |
" |
|
2343 |
View allSubInstances |
|
2344 |
" |
|
2345 |
! |
|
2346 |
||
2347 |
allSubclasses |
|
2348 |
"return a collection of all subclasses (direct AND indirect) of |
|
2349 |
the receiver. There will be no specific order, in which entries |
|
2350 |
are returned." |
|
2351 |
||
2352 |
|newColl| |
|
2353 |
||
2354 |
newColl := OrderedCollection new. |
|
2355 |
self allSubclassesDo:[:aClass | |
|
2356 |
newColl add:aClass |
|
2357 |
]. |
|
2358 |
^ newColl |
|
2359 |
||
2360 |
" |
|
2361 |
Collection allSubclasses |
|
2362 |
" |
|
2363 |
! |
|
2364 |
||
2365 |
allSubclassesInOrder |
|
2366 |
"return a collection of all subclasses (direct AND indirect) of |
|
2367 |
the receiver. Higher level subclasses will come before lower ones." |
|
2368 |
||
2369 |
|newColl| |
|
2370 |
||
2371 |
newColl := OrderedCollection new. |
|
2372 |
self allSubclassesInOrderDo:[:aClass | |
|
2373 |
newColl add:aClass |
|
2374 |
]. |
|
2375 |
^ newColl |
|
2376 |
||
2377 |
" |
|
2378 |
Collection allSubclassesInOrder |
|
2379 |
" |
|
2380 |
! |
|
2381 |
||
2382 |
allSuperclasses |
|
2383 |
"return a collection of the receivers accumulated superclasses" |
|
2384 |
||
2385 |
|aCollection theSuperClass| |
|
2386 |
||
2387 |
theSuperClass := superclass. |
|
2388 |
theSuperClass notNil ifTrue:[ |
|
2389 |
aCollection := OrderedCollection new. |
|
2390 |
[theSuperClass notNil] whileTrue:[ |
|
2391 |
aCollection add:theSuperClass. |
|
2392 |
theSuperClass := theSuperClass superclass |
|
2393 |
] |
|
2394 |
]. |
|
2395 |
^ aCollection |
|
2396 |
||
2397 |
" |
|
2398 |
String allSuperclasses |
|
2399 |
" |
|
2400 |
! |
|
2401 |
||
2402 |
cachedLookupMethodFor:aSelector |
|
2403 |
"return the method, which would be executed if aSelector was sent to |
|
2404 |
an instance of the receiver. I.e. the selector arrays of the receiver |
|
2405 |
and all of its superclasses are searched for aSelector. |
|
2406 |
Return the method, or nil if instances do not understand aSelector. |
|
2407 |
This interface provides exactly the same information as #lookupMethodFor:, |
|
2408 |
but uses the lookup-cache in the VM for faster search. |
|
2409 |
However, keep in mind, that doing a lookup through the cache also adds new |
|
2410 |
entries and can thus slow down the system by polluting the cache with |
|
2411 |
irrelevant entries. (do NOT loop over all objects calling this method). |
|
2412 |
Does NOT (currently) handle MI" |
|
2413 |
||
2414 |
%{ /* NOCONTEXT */ |
|
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2415 |
RETURN ( __lookup(self, aSelector, SENDER) ); |
620 | 2416 |
%} |
2417 |
||
2418 |
" |
|
2419 |
String cachedLookupMethodFor:#= |
|
2420 |
String cachedLookupMethodFor:#asOrderedCollection |
|
2421 |
" |
|
2422 |
! |
|
2423 |
||
2424 |
canBeSubclassed |
|
2425 |
"return true, if its allowed to create subclasses of the receiver. |
|
2426 |
This method is redefined in SmallInteger and UndefinedObject, since |
|
2427 |
instances are detected by their pointer-fields, i.e. they do not have |
|
2428 |
a class entry (you dont have to understand this :-)" |
|
10 | 2429 |
|
2430 |
^ true |
|
2431 |
! |
|
2432 |
||
620 | 2433 |
canUnderstand:aSelector |
2434 |
"return true, if the receiver or one of its superclasses implements aSelector. |
|
2435 |
(i.e. true if my instances understand aSelector)" |
|
2436 |
||
2437 |
^ (self lookupMethodFor:aSelector) notNil |
|
2438 |
||
2439 |
" |
|
2440 |
True canUnderstand:#ifTrue: |
|
2441 |
True canUnderstand:#== |
|
2442 |
True canUnderstand:#do: |
|
2443 |
" |
|
91 | 2444 |
! |
2445 |
||
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2446 |
category |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2447 |
"return the category of the class. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2448 |
Returning nil here, since Behavior does not define a category |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2449 |
(only ClassDescriptions do)." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2450 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2451 |
^ nil |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2452 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2453 |
" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2454 |
Point category |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2455 |
Behavior new category |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2456 |
" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2457 |
! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2458 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2459 |
classVarNames |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2460 |
"return a collection of the class variable name-strings. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2461 |
Returning empty here, since Behavior does not define any classVariables. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2462 |
(only Classes do). This allows different Behavior-like objects |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2463 |
(alien classes) to be handled by the browser as well." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2464 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2465 |
^ #() |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2466 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2467 |
"Created: 16.4.1996 / 17:57:31 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2468 |
! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2469 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2470 |
classVariableString |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2471 |
"return a string of the class variables names. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2472 |
Returning empty here, since Behavior does not define any classVariables. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2473 |
(only Classes do). This allows different Behavior-like objects |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2474 |
(alien classes) to be handled by the browser as well." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2475 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2476 |
^ '' |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2477 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2478 |
"Created: 16.4.1996 / 16:28:56 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2479 |
! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2480 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2481 |
comment |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2482 |
"return the comment of the class. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2483 |
Returning nil here, since Behavior does not define a category |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2484 |
(only Classes do). This allows different Behavior-like objects |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2485 |
(alien classes) to be handled by the browser as well." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2486 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2487 |
^ nil |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2488 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2489 |
"Modified: 16.4.1996 / 16:25:23 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2490 |
! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2491 |
|
620 | 2492 |
compiledMethodAt:aSelector |
2493 |
"return the method for given selector aSelector or nil. |
|
2494 |
Only methods in the receiver - not in the superclass chain are tested." |
|
2495 |
||
2496 |
|index| |
|
2497 |
||
2498 |
selectorArray isNil ifTrue:[ |
|
1088 | 2499 |
('BEHAVIOR: OOPS - nil selectorArray in ' , self name) errorPrintNL. |
2500 |
^ nil |
|
620 | 2501 |
]. |
2502 |
||
2503 |
index := selectorArray identityIndexOf:aSelector startingAt:1. |
|
2504 |
(index == 0) ifTrue:[^ nil]. |
|
2505 |
^ methodArray at:index |
|
2506 |
||
293 | 2507 |
" |
620 | 2508 |
Object compiledMethodAt:#== |
2509 |
(Object compiledMethodAt:#==) category |
|
293 | 2510 |
" |
1088 | 2511 |
|
2512 |
"Modified: 7.3.1996 / 19:14:23 / cg" |
|
620 | 2513 |
! |
2514 |
||
2515 |
containsMethod:aMethod |
|
2516 |
"Return true, if the argument, aMethod is a method of myself" |
|
2517 |
||
2518 |
methodArray isNil ifTrue:[^ false]. "degenerated class" |
|
2519 |
^ (methodArray identityIndexOf:aMethod startingAt:1) ~~ 0 |
|
2520 |
! |
|
2521 |
||
2522 |
derivedInstanceCount |
|
2523 |
"return the number of instances of myself and of subclasses" |
|
2524 |
||
2525 |
|count| |
|
2526 |
||
2527 |
count := 0. |
|
2528 |
ObjectMemory allObjectsDo:[:anObject | |
|
2529 |
(anObject isKindOf:self) ifTrue:[ |
|
2530 |
count := count + 1 |
|
2531 |
] |
|
2532 |
]. |
|
2533 |
^ count |
|
2534 |
||
293 | 2535 |
" |
620 | 2536 |
View derivedInstanceCount |
2537 |
SequenceableCollection derivedInstanceCount |
|
983 | 2538 |
Object derivedInstanceCount |
2539 |
" |
|
2540 |
! |
|
2541 |
||
2542 |
hasDerivedInstances |
|
2543 |
"return true, if there are any instances of myself or of any subclass" |
|
2544 |
||
2545 |
"Read the documentation on why there seem to be no |
|
2546 |
instances of SmallInteger and UndefinedObject" |
|
2547 |
||
2548 |
ObjectMemory allObjectsDo:[:anObject | |
|
2549 |
(anObject isKindOf:self) ifTrue:[ |
|
2550 |
^ true |
|
2551 |
] |
|
2552 |
]. |
|
2553 |
^ false |
|
2554 |
||
2555 |
" |
|
2556 |
Object hasDerivedInstances - certainly true |
|
2557 |
SharedQueue hasDerivedInstances |
|
293 | 2558 |
" |
620 | 2559 |
! |
2560 |
||
2561 |
hasInstances |
|
2562 |
"return true, if there are any instances of myself" |
|
2563 |
||
2564 |
"Read the documentation on why there seem to be no |
|
2565 |
instances of SmallInteger and UndefinedObject" |
|
2566 |
||
2567 |
"/ ObjectMemory allObjectsDo:[:anObject | |
|
2568 |
"/ (anObject class == self) ifTrue:[ |
|
2569 |
"/ ^ true |
|
2570 |
"/ ] |
|
2571 |
"/ ]. |
|
983 | 2572 |
|
620 | 2573 |
ObjectMemory allInstancesOf:self do:[:anObject | |
983 | 2574 |
^ true |
620 | 2575 |
]. |
2576 |
^ false |
|
2577 |
||
293 | 2578 |
" |
620 | 2579 |
Object hasInstances |
2580 |
SequenceableCollection hasInstances |
|
2581 |
Float hasInstances |
|
2582 |
SmallInteger hasInstances |
|
293 | 2583 |
" |
620 | 2584 |
! |
2585 |
||
2586 |
hasMethods |
|
2587 |
"return true, if there are any (local) methods in this class" |
|
2588 |
||
2589 |
^ (methodArray size ~~ 0) |
|
2590 |
||
293 | 2591 |
" |
620 | 2592 |
True hasMethods |
2593 |
True class hasMethods |
|
2594 |
" |
|
2595 |
! |
|
2596 |
||
2597 |
hasMultipleSuperclasses |
|
2598 |
"Return true, if this class inherits from other classes |
|
2599 |
(beside its primary superclass). |
|
2600 |
This method is a preparation for a future multiple inheritance extension |
|
2601 |
- currently it is not supported by the VM" |
|
2602 |
||
2603 |
^ otherSuperclasses notNil |
|
2604 |
! |
|
2605 |
||
2606 |
implements:aSelector |
|
2607 |
"return true, if the receiver implements aSelector. |
|
2608 |
(i.e. implemented in THIS class - NOT in a superclass). |
|
983 | 2609 |
|
2610 |
Caveat: |
|
2611 |
This simply checks for the selector being present in the classes |
|
2612 |
selector table - therefore, it does not care for ignoredMethods. |
|
2613 |
(but: you should not use this method for protocol-testing, anyway). |
|
2614 |
||
2615 |
Hint: |
|
2616 |
Dont use this method to check if someone responds to a message - |
|
2617 |
use #canUnderstand: on the class or #respondsTo: on the instance |
|
2618 |
to do this." |
|
2619 |
||
2620 |
^ self includesSelector:aSelector |
|
620 | 2621 |
|
2622 |
" |
|
983 | 2623 |
notice: this is class protocol |
2624 |
||
2625 |
True implements:#ifTrue: |
|
2626 |
True implements:#== |
|
2627 |
||
2628 |
notice: this is instance protocol |
|
2629 |
||
2630 |
true respondsTo:#ifTrue: |
|
2631 |
true respondsTo:#== |
|
2632 |
||
2633 |
notice: this is class protocol |
|
2634 |
||
2635 |
True canUnderstand:#ifTrue: |
|
2636 |
True canUnderstand:#== |
|
620 | 2637 |
" |
983 | 2638 |
|
2639 |
"Modified: 10.2.1996 / 13:15:56 / cg" |
|
620 | 2640 |
! |
2641 |
||
2642 |
includesSelector:aSelector |
|
983 | 2643 |
"return true, if the methodArray of THIS class includes |
2644 |
a method for aSelector. |
|
2645 |
(i.e. if aSelector is implemented in THIS class - NOT in a superclass). |
|
2646 |
||
2647 |
Hint: |
|
2648 |
Dont use this method to check if someone responds to a message - |
|
2649 |
use #canUnderstand: on the class or #respondsTo: on the instance |
|
2650 |
to do this." |
|
2651 |
||
2652 |
^ (selectorArray identityIndexOf:aSelector startingAt:1) ~~ 0 |
|
620 | 2653 |
! |
2654 |
||
2655 |
inheritsFrom:aClass |
|
2656 |
"return true, if the receiver inherits methods from aClass" |
|
2657 |
||
2658 |
^ self isSubclassOf:aClass |
|
2659 |
||
2660 |
" |
|
2661 |
True inheritsFrom:Object |
|
2662 |
LinkedList inheritsFrom:Array |
|
356 | 2663 |
" |
357 | 2664 |
! |
2665 |
||
620 | 2666 |
instanceCount |
2667 |
"return the number of instances of myself." |
|
2668 |
||
2669 |
"Read the documentation on why there seem to be no |
|
2670 |
instances of SmallInteger and UndefinedObject" |
|
2671 |
||
2672 |
|count| |
|
2673 |
||
2674 |
count := 0. |
|
2675 |
"/ ObjectMemory allObjectsDo:[:anObject | |
|
2676 |
"/ (anObject class == self) ifTrue:[ |
|
2677 |
"/ count := count + 1 |
|
2678 |
"/ ] |
|
2679 |
"/ ]. |
|
983 | 2680 |
|
620 | 2681 |
ObjectMemory allInstancesOf:self do:[:anObject | |
2682 |
count := count + 1 |
|
2683 |
]. |
|
2684 |
^ count |
|
2685 |
||
2686 |
" |
|
2687 |
View instanceCount |
|
2688 |
Object instanceCount |
|
2689 |
Float instanceCount |
|
2690 |
SequenceableCollection instanceCount |
|
2691 |
SmallInteger instanceCount .... mhmh - hear, hear |
|
2692 |
" |
|
2693 |
! |
|
2694 |
||
2695 |
isBehavior |
|
2696 |
"return true, if the receiver is describing another objects behavior, |
|
2697 |
i.e. is a class. Defined to avoid the need to use isKindOf:" |
|
2698 |
||
2699 |
^ true |
|
2700 |
||
2701 |
" |
|
2702 |
True isBehavior |
|
2703 |
true isBehavior |
|
2704 |
" |
|
2705 |
! |
|
2706 |
||
2707 |
isBits |
|
2708 |
"return true, if instances have indexed byte or short instance variables. |
|
2709 |
Ignore long, float and double arrays, since ST-80 code using isBits are probably |
|
2710 |
not prepared to handle them correctly." |
|
92 | 2711 |
|
2712 |
%{ /* NOCONTEXT */ |
|
620 | 2713 |
|
642
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2714 |
REGISTER int what; |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2715 |
|
1133 | 2716 |
what = (INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK); |
642
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2717 |
RETURN (( (what == __MASKSMALLINT(BYTEARRAY)) |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2718 |
|| (what == __MASKSMALLINT(WORDARRAY))) ? true : false ); |
620 | 2719 |
%} |
2720 |
! |
|
2721 |
||
2722 |
isBytes |
|
2723 |
"return true, if instances have indexed byte instance variables" |
|
2724 |
||
2725 |
"this could also be defined as: |
|
2726 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagBytes |
|
2727 |
" |
|
2728 |
%{ /* NOCONTEXT */ |
|
2729 |
||
1133 | 2730 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(BYTEARRAY)) ? true : false ); |
68 | 2731 |
%} |
620 | 2732 |
! |
2733 |
||
2734 |
isDoubles |
|
2735 |
"return true, if instances have indexed double instance variables" |
|
2736 |
||
2737 |
"this could also be defined as: |
|
2738 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagDoubles |
|
2739 |
" |
|
2740 |
%{ /* NOCONTEXT */ |
|
2741 |
||
1133 | 2742 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(DOUBLEARRAY)) ? true : false ); |
620 | 2743 |
%} |
2744 |
! |
|
2745 |
||
2746 |
isFixed |
|
2747 |
"return true, if instances do not have indexed instance variables" |
|
2748 |
||
2749 |
"this could also be defined as: |
|
2750 |
^ self isVariable not |
|
2751 |
" |
|
2752 |
||
2753 |
%{ /* NOCONTEXT */ |
|
2754 |
||
1133 | 2755 |
RETURN ( ((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) ? false : true ); |
620 | 2756 |
%} |
2757 |
! |
|
2758 |
||
2759 |
isFloats |
|
2760 |
"return true, if instances have indexed float instance variables" |
|
2761 |
||
2762 |
"this could also be defined as: |
|
2763 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagFloats |
|
2764 |
" |
|
2765 |
%{ /* NOCONTEXT */ |
|
2766 |
||
1133 | 2767 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(FLOATARRAY)) ? true : false ); |
620 | 2768 |
%} |
91 | 2769 |
! |
2770 |
||
642
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2771 |
isFloatsOrDoubles |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2772 |
"return true, if instances have indexed float or double instance variables" |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2773 |
|
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2774 |
%{ /* NOCONTEXT */ |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2775 |
|
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2776 |
int what; |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2777 |
|
1133 | 2778 |
what = (INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK); |
642
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2779 |
RETURN (( (what == __MASKSMALLINT(FLOATARRAY)) |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2780 |
|| (what == __MASKSMALLINT(DOUBLEARRAY))) ? true : false ); |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2781 |
%} |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2782 |
" |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2783 |
(Object new) class isFloatsOrDoubles |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2784 |
(Point new) class isFloatsOrDoubles |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2785 |
(Array new) class isFloatsOrDoubles |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2786 |
(ByteArray new) class isFloatsOrDoubles |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2787 |
(FloatArray new) class isFloatsOrDoubles |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2788 |
(DoubleArray new) class isFloatsOrDoubles |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2789 |
" |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2790 |
! |
dbf407bedf64
slighly faster isXXX methods; added isFloatsOrDoubles
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
2791 |
|
620 | 2792 |
isLongs |
2793 |
"return true, if instances have indexed long instance variables" |
|
2794 |
||
2795 |
"this could also be defined as: |
|
2796 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagLongs |
|
2797 |
" |
|
2798 |
%{ /* NOCONTEXT */ |
|
2799 |
||
1133 | 2800 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(LONGARRAY)) ? true : false ); |
620 | 2801 |
%} |
356 | 2802 |
! |
2803 |
||
620 | 2804 |
isPointers |
2805 |
"return true, if instances have pointer instance variables |
|
2806 |
i.e. are either non-indexed or have indexed pointer variables" |
|
2807 |
||
2808 |
"QUESTION: should we ignore WeakPointers ?" |
|
2809 |
||
2810 |
%{ /* NOCONTEXT */ |
|
2811 |
||
2812 |
REGISTER int flags; |
|
2813 |
||
1133 | 2814 |
flags = __intVal(__INST(flags)) & ARRAYMASK; |
620 | 2815 |
switch (flags) { |
2816 |
default: |
|
2817 |
/* normal objects */ |
|
2818 |
RETURN ( true ); |
|
2819 |
||
2820 |
case BYTEARRAY: |
|
2821 |
case WORDARRAY: |
|
2822 |
case LONGARRAY: |
|
2823 |
case FLOATARRAY: |
|
2824 |
case DOUBLEARRAY: |
|
2825 |
RETURN (false ); |
|
2826 |
||
2827 |
case WKPOINTERARRAY: |
|
2828 |
/* what about those ? */ |
|
2829 |
RETURN (true ); |
|
2830 |
} |
|
2831 |
%} |
|
2832 |
! |
|
2833 |
||
2834 |
isSubclassOf:aClass |
|
2835 |
"return true, if I am a subclass of the argument, aClass" |
|
2836 |
||
2837 |
|theClass| |
|
2838 |
||
2839 |
theClass := superclass. |
|
2840 |
[theClass notNil] whileTrue:[ |
|
2841 |
(theClass == aClass) ifTrue:[^ true]. |
|
2842 |
%{ |
|
2843 |
if (__isBehaviorLike(theClass)) { |
|
2844 |
theClass = __ClassInstPtr(theClass)->c_superclass; |
|
2845 |
} else { |
|
2846 |
theClass = nil; |
|
2847 |
} |
|
2848 |
%}. |
|
2849 |
"/ theClass := theClass superclass. |
|
2850 |
]. |
|
2851 |
^ false |
|
356 | 2852 |
|
2853 |
" |
|
620 | 2854 |
String isSubclassOf:Collection |
2855 |
LinkedList isSubclassOf:Array |
|
2856 |
1 isSubclassOf:Number <- will fail since 1 is no class |
|
2857 |
" |
|
2858 |
! |
|
2859 |
||
2860 |
isVariable |
|
2861 |
"return true, if instances have indexed instance variables" |
|
2862 |
||
2863 |
"this could also be defined as: |
|
2864 |
^ (flags bitAnd:(Behavior maskIndexType)) ~~ 0 |
|
2865 |
" |
|
2866 |
||
2867 |
%{ /* NOCONTEXT */ |
|
2868 |
||
1133 | 2869 |
RETURN ( ((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) ? true : false ); |
620 | 2870 |
%} |
2871 |
! |
|
2872 |
||
2873 |
isWords |
|
2874 |
"return true, if instances have indexed short instance variables" |
|
2875 |
||
2876 |
"this could also be defined as: |
|
2877 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagWords |
|
2878 |
" |
|
2879 |
%{ /* NOCONTEXT */ |
|
2880 |
||
1133 | 2881 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(WORDARRAY)) ? true : false ); |
620 | 2882 |
%} |
2883 |
! |
|
2884 |
||
2885 |
lookupMethodFor:aSelector |
|
2886 |
"return the method, which would be executed if aSelector was sent to |
|
2887 |
an instance of the receiver. I.e. the selector arrays of the receiver |
|
2888 |
and all of its superclasses are searched for aSelector. |
|
2889 |
Return the method, or nil if instances do not understand aSelector. |
|
2890 |
EXPERIMENTAL: take care of multiple superclasses." |
|
2891 |
||
2892 |
|m cls| |
|
2893 |
||
2894 |
cls := self. |
|
2895 |
[cls notNil] whileTrue:[ |
|
2896 |
m := cls compiledMethodAt:aSelector. |
|
2897 |
m notNil ifTrue:[^ m]. |
|
2898 |
cls hasMultipleSuperclasses ifTrue:[ |
|
2899 |
cls superclasses do:[:aSuperClass | |
|
2900 |
m := aSuperClass lookupMethodFor:aSelector. |
|
2901 |
m notNil ifTrue:[^ m]. |
|
2902 |
]. |
|
2903 |
^ nil |
|
2904 |
] ifFalse:[ |
|
2905 |
cls := cls superclass |
|
2906 |
] |
|
2907 |
]. |
|
2908 |
^ nil |
|
2909 |
! |
|
2910 |
||
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2911 |
name |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2912 |
"although behaviors have no name, we return something |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2913 |
useful here - there are many places (inspectors) where |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2914 |
a classes name is asked for. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2915 |
Implementing this message here allows anonymous classes |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2916 |
and instances of them to be inspected." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2917 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2918 |
^ 'someBehavior' |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2919 |
! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2920 |
|
620 | 2921 |
selectorAtMethod:aMethod |
2922 |
"Return the selector for given method aMethod." |
|
2923 |
||
2924 |
^ self selectorAtMethod:aMethod ifAbsent:[nil] |
|
2925 |
||
2926 |
" |
|
2927 |
|m| |
|
2928 |
||
2929 |
m := Object compiledMethodAt:#copy. |
|
2930 |
Fraction selectorAtMethod:m. |
|
2931 |
" |
|
2932 |
" |
|
2933 |
|m| |
|
2934 |
||
2935 |
m := Object compiledMethodAt:#copy. |
|
2936 |
Object selectorAtMethod:m. |
|
356 | 2937 |
" |
2938 |
! |
|
2939 |
||
620 | 2940 |
selectorAtMethod:aMethod ifAbsent:failBlock |
2941 |
"return the selector for given method aMethod |
|
2942 |
or the value of failBlock, if not found." |
|
2943 |
||
2944 |
|index| |
|
2945 |
||
2946 |
index := methodArray identityIndexOf:aMethod startingAt:1. |
|
2947 |
(index == 0) ifTrue:[^ failBlock value]. |
|
2948 |
^ selectorArray at:index |
|
216 | 2949 |
|
2950 |
" |
|
620 | 2951 |
|m| |
2952 |
||
2953 |
m := Object compiledMethodAt:#copy. |
|
2954 |
Object selectorAtMethod:m ifAbsent:['oops']. |
|
2955 |
" |
|
216 | 2956 |
" |
620 | 2957 |
|m| |
2958 |
||
2959 |
m := Object compiledMethodAt:#copy. |
|
2960 |
Fraction selectorAtMethod:m ifAbsent:['oops']. |
|
216 | 2961 |
" |
2962 |
! |
|
2963 |
||
620 | 2964 |
selectorIndex:aSelector |
2965 |
"return the index in the arrays for given selector aSelector" |
|
2966 |
||
2967 |
^ selectorArray identityIndexOf:aSelector startingAt:1 |
|
216 | 2968 |
! |
2969 |
||
127 | 2970 |
sizeOfInst:n |
2971 |
"return the number of bytes required for an instance of |
|
2972 |
myself with n indexed instance variables. The argument n |
|
2973 |
should be zero for classes without indexed instance variables. |
|
2974 |
See Behavior>>niceNew: for an application of this." |
|
216 | 2975 |
|
127 | 2976 |
|nInstvars| |
2977 |
||
2978 |
nInstvars := self instSize. |
|
2979 |
%{ |
|
2980 |
int nBytes; |
|
2981 |
||
1133 | 2982 |
nBytes = __intVal(nInstvars) * sizeof(OBJ) + OHDR_SIZE; |
249 | 2983 |
if (__isSmallInteger(n)) { |
154 | 2984 |
int nIndex; |
127 | 2985 |
|
1133 | 2986 |
nIndex = __intVal(n); |
2987 |
switch (__intVal(__INST(flags)) & ARRAYMASK) { |
|
154 | 2988 |
case BYTEARRAY: |
2989 |
nBytes += nIndex; |
|
2990 |
if (nBytes & (ALIGN - 1)) { |
|
2991 |
nBytes = (nBytes & ~(ALIGN - 1)) + ALIGN; |
|
2992 |
} |
|
2993 |
break; |
|
127 | 2994 |
|
154 | 2995 |
case WORDARRAY: |
2996 |
nBytes += nIndex * sizeof(short); |
|
2997 |
if (nBytes & (ALIGN - 1)) { |
|
2998 |
nBytes = (nBytes & ~(ALIGN - 1)) + ALIGN; |
|
2999 |
} |
|
3000 |
break; |
|
127 | 3001 |
|
154 | 3002 |
case LONGARRAY: |
3003 |
nBytes += nIndex * sizeof(long); |
|
3004 |
break; |
|
127 | 3005 |
|
154 | 3006 |
case FLOATARRAY: |
3007 |
nBytes += nIndex * sizeof(float); |
|
3008 |
break; |
|
127 | 3009 |
|
154 | 3010 |
case DOUBLEARRAY: |
3011 |
nBytes += nIndex * sizeof(double); |
|
3012 |
break; |
|
127 | 3013 |
|
154 | 3014 |
default: |
3015 |
nBytes += nIndex * sizeof(OBJ); |
|
3016 |
break; |
|
3017 |
} |
|
127 | 3018 |
} |
1133 | 3019 |
RETURN (__MKSMALLINT(nBytes)); |
127 | 3020 |
%} |
3021 |
! |
|
3022 |
||
620 | 3023 |
sourceCodeAt:aSelector |
3024 |
"return the methods source for given selector aSelector or nil. |
|
3025 |
Only methods in the receiver - not in the superclass chain are tested." |
|
3026 |
||
3027 |
|method| |
|
3028 |
||
3029 |
method := self compiledMethodAt:aSelector. |
|
3030 |
method isNil ifTrue:[^ nil]. |
|
3031 |
^ method source |
|
45 | 3032 |
|
91 | 3033 |
" |
620 | 3034 |
True sourceCodeAt:#ifTrue: |
3035 |
Object sourceCodeAt:#== |
|
3036 |
Behavior sourceCodeAt:#sourceCodeAt: |
|
91 | 3037 |
" |
1 | 3038 |
! |
3039 |
||
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3040 |
sourceCodeManager |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3041 |
"return the sourceCodeManager of the class. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3042 |
Returning nil here, since Behavior does not define any sourceCode management. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3043 |
(only Classes do). This allows different Behavior-like objects |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3044 |
(alien classes) to be handled by the browser as well." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3045 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3046 |
^ nil |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3047 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3048 |
"Created: 16.4.1996 / 16:26:03 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3049 |
! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3050 |
|
1 | 3051 |
subclasses |
3052 |
"return a collection of the direct subclasses of the receiver" |
|
3053 |
||
3054 |
|newColl| |
|
3055 |
||
308 | 3056 |
SubclassInfo notNil ifTrue:[ |
3057 |
newColl := SubclassInfo at:self ifAbsent:nil. |
|
3058 |
newColl notNil ifTrue:[^ newColl asOrderedCollection] |
|
3059 |
]. |
|
3060 |
||
1 | 3061 |
newColl := OrderedCollection new. |
3062 |
self subclassesDo:[:aClass | |
|
154 | 3063 |
newColl add:aClass |
1 | 3064 |
]. |
3065 |
^ newColl |
|
45 | 3066 |
|
91 | 3067 |
" |
3068 |
Collection subclasses |
|
3069 |
" |
|
1 | 3070 |
! |
3071 |
||
620 | 3072 |
superclasses |
3073 |
"return a collection of the receivers immediate superclasses. |
|
3074 |
This method is a preparation for a future multiple inheritance extension |
|
3075 |
- currently it is not supported by the VM" |
|
3076 |
||
3077 |
|a| |
|
3078 |
||
3079 |
a := Array with:superclass. |
|
3080 |
otherSuperclasses notNil ifTrue:[ |
|
3081 |
^ a , otherSuperclasses |
|
1 | 3082 |
]. |
620 | 3083 |
^ a |
154 | 3084 |
|
3085 |
" |
|
620 | 3086 |
String superclasses |
91 | 3087 |
" |
2 | 3088 |
! |
3089 |
||
1191
7d458640ca32
moved & added some query methods (from class) to upper abstract classes
Claus Gittinger <cg@exept.de>
parents:
1179
diff
changeset
|
3090 |
wasAutoloaded |
7d458640ca32
moved & added some query methods (from class) to upper abstract classes
Claus Gittinger <cg@exept.de>
parents:
1179
diff
changeset
|
3091 |
"return true, if this class came into the system via an |
7d458640ca32
moved & added some query methods (from class) to upper abstract classes
Claus Gittinger <cg@exept.de>
parents:
1179
diff
changeset
|
3092 |
autoload; false otherwise. |
7d458640ca32
moved & added some query methods (from class) to upper abstract classes
Claus Gittinger <cg@exept.de>
parents:
1179
diff
changeset
|
3093 |
Returning false here. This allows different Behavior-like objects |
7d458640ca32
moved & added some query methods (from class) to upper abstract classes
Claus Gittinger <cg@exept.de>
parents:
1179
diff
changeset
|
3094 |
(alien classes) to be handled by the browser as well." |
7d458640ca32
moved & added some query methods (from class) to upper abstract classes
Claus Gittinger <cg@exept.de>
parents:
1179
diff
changeset
|
3095 |
|
7d458640ca32
moved & added some query methods (from class) to upper abstract classes
Claus Gittinger <cg@exept.de>
parents:
1179
diff
changeset
|
3096 |
^ false |
7d458640ca32
moved & added some query methods (from class) to upper abstract classes
Claus Gittinger <cg@exept.de>
parents:
1179
diff
changeset
|
3097 |
|
7d458640ca32
moved & added some query methods (from class) to upper abstract classes
Claus Gittinger <cg@exept.de>
parents:
1179
diff
changeset
|
3098 |
"Created: 16.4.1996 / 16:27:16 / cg" |
7d458640ca32
moved & added some query methods (from class) to upper abstract classes
Claus Gittinger <cg@exept.de>
parents:
1179
diff
changeset
|
3099 |
! |
7d458640ca32
moved & added some query methods (from class) to upper abstract classes
Claus Gittinger <cg@exept.de>
parents:
1179
diff
changeset
|
3100 |
|
2 | 3101 |
whichClassImplements:aSelector |
328 | 3102 |
"obsolete interface; |
3103 |
use whichClassIncludesSelector: for ST-80 compatibility." |
|
3104 |
||
3105 |
^ self whichClassIncludesSelector:aSelector |
|
3106 |
! |
|
3107 |
||
3108 |
whichClassIncludesSelector:aSelector |
|
68 | 3109 |
"return the class in the inheritance chain, which implements the method |
3110 |
for aSelector; return nil if none. |
|
3111 |
EXPERIMENTAL: handle multiple superclasses" |
|
3112 |
||
3113 |
|cls| |
|
2 | 3114 |
|
68 | 3115 |
cls := self. |
3116 |
[cls notNil] whileTrue:[ |
|
983 | 3117 |
(cls includesSelector:aSelector) ifTrue:[^ cls]. |
154 | 3118 |
cls hasMultipleSuperclasses ifTrue:[ |
3119 |
cls superclasses do:[:aSuperClass | |
|
3120 |
|implementingClass| |
|
2 | 3121 |
|
328 | 3122 |
implementingClass := aSuperClass whichClassIncludesSelector:aSelector. |
154 | 3123 |
implementingClass notNil ifTrue:[^ implementingClass]. |
3124 |
]. |
|
3125 |
^ nil |
|
3126 |
] ifFalse:[ |
|
3127 |
cls := cls superclass |
|
3128 |
] |
|
2 | 3129 |
]. |
3130 |
^ nil |
|
3131 |
||
91 | 3132 |
" |
328 | 3133 |
String whichClassIncludesSelector:#== |
3134 |
String whichClassIncludesSelector:#collect: |
|
91 | 3135 |
" |
2 | 3136 |
! |
3137 |
||
620 | 3138 |
withAllSubclasses |
3139 |
"return a collection containing the receiver and |
|
3140 |
all subclasses (direct AND indirect) of the receiver" |
|
3141 |
||
3142 |
|newColl| |
|
3143 |
||
3144 |
newColl := OrderedCollection with:self. |
|
3145 |
self allSubclassesDo:[:aClass | |
|
3146 |
newColl add:aClass |
|
3147 |
]. |
|
3148 |
^ newColl |
|
328 | 3149 |
|
3150 |
" |
|
620 | 3151 |
Collection withAllSubclasses |
91 | 3152 |
" |
1 | 3153 |
! |
3154 |
||
620 | 3155 |
withAllSuperclasses |
3156 |
"return a collection containing the receiver and all |
|
3157 |
of the receivers accumulated superclasses" |
|
3158 |
||
3159 |
|aCollection theSuperClass| |
|
3160 |
||
3161 |
aCollection := OrderedCollection with:self. |
|
3162 |
theSuperClass := superclass. |
|
3163 |
[theSuperClass notNil] whileTrue:[ |
|
3164 |
aCollection add:theSuperClass. |
|
3165 |
theSuperClass := theSuperClass superclass |
|
308 | 3166 |
]. |
620 | 3167 |
^ aCollection |
11 | 3168 |
|
91 | 3169 |
" |
620 | 3170 |
String withAllSuperclasses |
308 | 3171 |
" |
2 | 3172 |
! ! |
620 | 3173 |
|
3174 |
!Behavior methodsFor:'snapshots'! |
|
3175 |
||
3176 |
postSnapshot |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3177 |
"sent by ObjectMemory to all classes, after a snapshot has been written. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3178 |
Nothing done here. This can be redefined in classes which like to know |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3179 |
about snapshooting." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3180 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3181 |
"Modified: 16.4.1996 / 18:12:08 / cg" |
620 | 3182 |
! |
3183 |
||
3184 |
preSnapshot |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3185 |
"sent by ObjectMemory to all classes, before a snapshot is written. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3186 |
Nothing done here. This can be redefined in classes which like to know |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3187 |
about snapshooting." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3188 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3189 |
"Modified: 16.4.1996 / 18:12:14 / cg" |
620 | 3190 |
! ! |
3191 |
||
662 | 3192 |
!Behavior class methodsFor:'documentation'! |
3193 |
||
3194 |
version |
|
1285 | 3195 |
^ '$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.72 1996-04-25 11:16:22 cg Exp $' |
662 | 3196 |
! ! |