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