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