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