author | Stefan Vogel <sv@exept.de> |
Fri, 04 Apr 2014 10:18:36 +0200 | |
changeset 16302 | 6e87ae369992 |
parent 16280 | cd8ddeffcf92 |
child 16734 | 5184124214e2 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
16050 | 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 |
" |
|
5368
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
13 |
|
1 | 14 |
Object subclass:#Behavior |
16268 | 15 |
instanceVariableNames:'superclass flags methodDictionary lookupObject instSize' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Kernel-Classes' |
|
1 | 19 |
! |
20 |
||
1760 | 21 |
!Behavior class methodsFor:'documentation'! |
47 | 22 |
|
14065
6f6d6223c947
changed: #commonSuperclass:
Claus Gittinger <cg@exept.de>
parents:
13862
diff
changeset
|
23 |
VS |
6f6d6223c947
changed: #commonSuperclass:
Claus Gittinger <cg@exept.de>
parents:
13862
diff
changeset
|
24 |
^ '§Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.315 2011/11/29 10:20:21 cg Exp §' |
6f6d6223c947
changed: #commonSuperclass:
Claus Gittinger <cg@exept.de>
parents:
13862
diff
changeset
|
25 |
! |
6f6d6223c947
changed: #commonSuperclass:
Claus Gittinger <cg@exept.de>
parents:
13862
diff
changeset
|
26 |
|
88 | 27 |
copyright |
28 |
" |
|
29 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
16050 | 30 |
All Rights Reserved |
88 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
47 | 41 |
documentation |
42 |
" |
|
68 | 43 |
Every class in the system inherits from Behavior (via Class, ClassDescription); |
44 |
so here is where most of the class messages end up being implemented. |
|
45 |
(to answer a FAQ: 'Point basicNew' will be done here :-) |
|
46 |
||
356 | 47 |
Beginners should keep in mind, that all classes are instances (of subclasses) |
12094 | 48 |
of Behavior, therefore you will find the above mentioned 'basicNew:' method |
49 |
under the 'instance'-methods of Behavior - NOT under the class methods |
|
50 |
('Behavior new' will create and return a new class, while sending 'new' to |
|
154 | 51 |
any instance of Behavior (i.e. any class) will return an instance of that class). |
68 | 52 |
|
2226 | 53 |
|
68 | 54 |
Behavior provides minimum support for all classes - additional stuff is |
77 | 55 |
found in ClassDescription and Class. Behaviors provides all mechanisms needed |
12094 | 56 |
to create instances, and send messages to those. However, Behavior does not provide |
77 | 57 |
all the (symbolic) information needed to compile methods for a class or to get |
58 |
useful information in inspectors. |
|
47 | 59 |
|
2226 | 60 |
for experts: |
61 |
||
62 |
Since instances of Behavior provide all that is needed to interact with the VM's |
|
63 |
message dispatch mechanism, these can be used as 'light weight' classes. |
|
64 |
I.e. it is possible, to generate completely anonymous classes (and instances thereof) |
|
65 |
on the fly - 'Behavior new new' is such a thingy. |
|
66 |
||
12094 | 67 |
The selectors and Methods are organized in a MethodDictionary (which is not a true |
2226 | 68 |
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
|
69 |
This avoids the need for knowledge about Dictionaries in the runtime library (VM) |
12094 | 70 |
(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
|
71 |
hashed dictionary is almost void). |
1 | 72 |
|
1285 | 73 |
[Instance variables:] |
74 |
||
16050 | 75 |
superclass <Class> the receivers superclass |
76 |
||
77 |
methodDictionary <MethodDictionary> inst-selectors and methods |
|
78 |
||
79 |
instSize <SmallInteger> the number of instance variables |
|
80 |
||
81 |
flags <SmallInteger> special flag bits coded in a number |
|
82 |
not for application use |
|
1 | 83 |
|
81 | 84 |
flag bits (see stc.h): |
47 | 85 |
|
68 | 86 |
NOTICE: layout known by compiler and runtime system; be careful when changing |
1285 | 87 |
|
1292 | 88 |
[author:] |
16050 | 89 |
Claus Gittinger |
1292 | 90 |
|
1285 | 91 |
[see also:] |
16050 | 92 |
Class ClassDescription Metaclass |
93 |
Method MethodDictionary |
|
47 | 94 |
" |
356 | 95 |
! |
96 |
||
12094 | 97 |
virtualMachineRelationship |
356 | 98 |
" |
2230
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
99 |
Expert info follows: |
12858
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
100 |
-------------------- |
12094 | 101 |
NOTICE: |
16050 | 102 |
the stuff described below may not be available on other |
103 |
Smalltalk implementations; be aware that these error mechanisms |
|
104 |
are ST/X specials and applications using these (tricks) may |
|
105 |
not be portable to other systems. |
|
12094 | 106 |
|
107 |
WARNING: |
|
16050 | 108 |
do not try the examples below on (some) other smalltalk systems; |
109 |
it has been reported, that some crash badly when doing this .... ;-) |
|
357 | 110 |
|
356 | 111 |
Instances of Behavior and subclasses (i.e. in sloppy words: classes) |
112 |
play a special role w.r.t. the VM. Only objects whose class-slot is marked |
|
113 |
as being behaviorLike (in the flag-instvar) are considered to be classLike |
|
114 |
and a message lookup will be done for it in the well known way. |
|
115 |
Thus, if an object has a class for which its class does NOT have |
|
362 | 116 |
this flag bit set, the VM will trigger an error on a message send. |
356 | 117 |
|
2230
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
118 |
|
356 | 119 |
Why is this so: |
12858
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
120 |
--------------- |
356 | 121 |
the above lets every object play the role of a class, |
122 |
which has been flagged as behaviorLike in its class's flag. |
|
12094 | 123 |
Thus, you can create arbitrary new classLike objects and have the VM |
356 | 124 |
play with them. |
125 |
This may offer the flexibility to create a totally different object scheme |
|
362 | 126 |
on top of ST/X (for example: Self like objects) where any object can play |
12858
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
127 |
a classRole for another object or even for itself. |
356 | 128 |
|
2148 | 129 |
[A concrete application of this is found in the Structure class, |
130 |
which creates objects which are their own class !! |
|
12094 | 131 |
This may look to be of theoretical value at first sight, |
132 |
however, such a construct saves memory, by not requiring an extra |
|
2148 | 133 |
class object per Structure object.] |
134 |
||
135 |
Be aware, that the VM trusts the isBehaviorLike flag - IF it is set for some |
|
136 |
object, the VM EXPECTS the object selector and methodDictionaries to be found |
|
362 | 137 |
at the instance positions as defined here. |
138 |
(i.e. instanceVariables with contents and semantic corresponding to |
|
16050 | 139 |
superclass |
140 |
flags |
|
141 |
methodDictionary |
|
362 | 142 |
must be present and have the same instVar-index as here). |
143 |
||
356 | 144 |
The VM (and the system) may crash badly, if this is not the case. |
362 | 145 |
|
356 | 146 |
Since every class in the system derives from Behavior, the flag setting |
357 | 147 |
(and instance variable layout) is correct for all 'normal' classes. |
148 |
If you experiment by creating new behaviorLike objects, please take |
|
149 |
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
|
150 |
instVars 'superclass' and 'methodDictionary' are required |
357 | 151 |
and have to be at the same instVar index. |
362 | 152 |
(we suggest, you subclass Behavior, to make certain) |
357 | 153 |
|
2230
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
154 |
|
8503 | 155 |
Vice versa, defining 'dumb classes', which have the behaviorLike bit turned |
12858
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
156 |
off may be useful as well; if a message is sent to an instance of such |
2230
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
157 |
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
|
158 |
#doesNotUnderstand: mechanism - however, since the instance is no good |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
and arguments) along with the original receiver. |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
162 |
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
|
163 |
however, you may redefine this in your 'dum class' for recovery. |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
164 |
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
|
165 |
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
|
166 |
interface. |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
167 |
|
12094 | 168 |
All of the above is pure expert stuff |
2230
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
169 |
- 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
|
170 |
ST-programmer, though (and even most of those will never use these features). |
357 | 171 |
|
356 | 172 |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
173 |
Examples (only of theoretical interest): |
12858
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
174 |
---------------------------------------- |
16050 | 175 |
take away the behaviorLike-flag from a class. |
176 |
-> The instances will not understand any messages, since the VM will |
|
177 |
not recognize its class as being a class ... |
|
178 |
||
179 |
|newMeta notRecognizedAsClass someInstance| |
|
180 |
||
181 |
newMeta := Metaclass new. |
|
182 |
newMeta flags:0. |
|
183 |
||
184 |
notRecognizedAsClass := newMeta new. |
|
185 |
||
186 |
someInstance := notRecognizedAsClass new. |
|
187 |
someInstance perform:#isNil |
|
356 | 188 |
|
357 | 189 |
|
190 |
Of course, this is an exception which can be handled ...: |
|
191 |
Example: |
|
192 |
||
16050 | 193 |
|newMeta notRecognizedAsClass someInstance| |
194 |
||
195 |
newMeta := Metaclass new. |
|
196 |
newMeta flags:0. |
|
197 |
||
198 |
notRecognizedAsClass := newMeta new. |
|
199 |
||
200 |
someInstance := notRecognizedAsClass new. |
|
201 |
Object errorSignal handle:[:ex | |
|
202 |
ex return |
|
203 |
] do:[ |
|
204 |
someInstance perform:#isNil |
|
205 |
] |
|
357 | 206 |
|
207 |
||
208 |
likewise, a doesNotUnderstand-notUnderstood can be handled: |
|
209 |
Example: |
|
210 |
||
16050 | 211 |
|newMeta funnyClass someInstance| |
212 |
||
213 |
newMeta := Metaclass new. |
|
214 |
||
215 |
funnyClass := newMeta new. |
|
216 |
funnyClass setSuperclass:nil. |
|
217 |
||
218 |
someInstance := funnyClass new. |
|
219 |
Object errorSignal handle:[:ex | |
|
220 |
ex return |
|
221 |
] do:[ |
|
222 |
someInstance perform:#isNil |
|
223 |
] |
|
357 | 224 |
|
225 |
||
362 | 226 |
more examples, which try to trick the VM ;-): |
16050 | 227 |
badly playing around with a classes internals ... |
228 |
||
229 |
|newClass someInstance| |
|
230 |
||
231 |
newClass := Class new. |
|
232 |
newClass setSuperclass:nil. |
|
233 |
someInstance := newClass new. |
|
234 |
someInstance inspect |
|
235 |
||
236 |
||
237 |
|newClass someInstance| |
|
238 |
||
239 |
newClass := Class new. |
|
240 |
newClass setSuperclass:newClass. |
|
241 |
someInstance := newClass new. |
|
242 |
someInstance inspect |
|
243 |
||
244 |
||
245 |
|newClass someInstance| |
|
246 |
||
247 |
newClass := Class new. |
|
248 |
newClass setSuperclass:1. |
|
249 |
someInstance := newClass new. |
|
250 |
someInstance inspect |
|
12858
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
251 |
|
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
252 |
|
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
253 |
Example: |
16050 | 254 |
creating totally anonymous classes: |
255 |
||
256 |
|newClass someInstance| |
|
257 |
||
258 |
newClass := Class new. |
|
259 |
someInstance := newClass new. |
|
260 |
someInstance inspect |
|
357 | 261 |
|
262 |
||
356 | 263 |
Example: |
16050 | 264 |
creating totally anonymous metaclasses: |
265 |
||
266 |
|newMeta newClass someInstance| |
|
267 |
||
268 |
newMeta := Metaclass new. |
|
269 |
newClass := newMeta new. |
|
270 |
someInstance := newClass new. |
|
271 |
someInstance inspect |
|
12094 | 272 |
|
273 |
||
274 |
PS: if you experiment with new behaviorLike objects, you may want |
|
16050 | 275 |
to turn off the VM's debugPrintouts |
276 |
with: |
|
277 |
'Smalltalk debugPrinting:false' |
|
278 |
and: |
|
279 |
'Smalltalk infoPrinting:false' |
|
12858
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
280 |
|
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
281 |
Meta-Object-Protocol support: |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
282 |
----------------------------- |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
283 |
the above tricks do not affect the inline caches, and are therefore somewhat slow. |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
284 |
Another hook is the lookupObject which, if non-nil, is consulted to do the lookup |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
285 |
instead of the hardwired VM lookup algorithm, and provide a method as return value. |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
286 |
This method (if non-nil) will be put into the inline-and polymorph caches for speedy |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
287 |
call the next time. If non-nil, the lookup object is sent the: |
16050 | 288 |
lookupMethodForSelector:aSelector |
289 |
directedTo:searchClass |
|
290 |
for:aReceiver |
|
291 |
withArguments:argArrayOrNil |
|
292 |
from:sendingContext |
|
12858
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
293 |
message. |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
294 |
'searchClass' is the object class or any of its superclasses (for directed/super sends). |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
295 |
You can return any arbitrary method there - for example to implement multiple inheritance, |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
296 |
selector namespace tricks or multi-dispatch on argument types (double dispatch for a method). |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
297 |
Be aware, that the returned method is cached, and the lookup is not consulted again for the |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
298 |
same receiver/callsite combination. So the returned method should check if it's ok to be called |
695cbd35ce8a
changed: #virtualMachineRelationship
Claus Gittinger <cg@exept.de>
parents:
12855
diff
changeset
|
299 |
again (maybe, a synthetic method is generated and returned). |
356 | 300 |
" |
47 | 301 |
! ! |
1 | 302 |
|
1760 | 303 |
!Behavior class methodsFor:'creating new classes'! |
1 | 304 |
|
305 |
new |
|
356 | 306 |
"creates and return a new behavior (which is like a class, |
307 |
but without the symbolic & name information). |
|
308 |
Not for normal applications. |
|
309 |
Sending the returned behavior the #new message gives you |
|
310 |
an instance if it. |
|
311 |
||
312 |
Notice: the returned class is given a superclass of Object; |
|
313 |
this allows for its new instances to be inspected and the like." |
|
1 | 314 |
|
315 |
|newClass| |
|
316 |
||
317 |
newClass := self basicNew. |
|
12094 | 318 |
newClass |
16050 | 319 |
setSuperclass:Object |
320 |
methodDictionary:(MethodDictionary new) |
|
321 |
instSize:0 |
|
322 |
flags:(self flagBehavior). |
|
1 | 323 |
^ newClass |
356 | 324 |
|
325 |
" |
|
326 |
Behavior new <- a new behavior |
|
327 |
Behavior new new <- an instance of it |
|
328 |
ClassDescription new <- a new classDescription |
|
329 |
ClassDescription new new <- an instance of it |
|
330 |
Class new <- a new class |
|
331 |
Class new new <- an instance of it |
|
332 |
Metaclass new <- a new metaclass |
|
333 |
Metaclass new new <- an instance (i.e. a class) of it |
|
334 |
Metaclass new new new <- an instance of this new class |
|
335 |
" |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
336 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
337 |
"Modified: 7.6.1996 / 15:38:58 / stefan" |
1 | 338 |
! ! |
339 |
||
1760 | 340 |
!Behavior class methodsFor:'flag bit constants'! |
620 | 341 |
|
15948 | 342 |
flagAlien |
343 |
"Return the flag code for Alien objects for Translucent Object implementation" |
|
344 |
||
345 |
%{ /* NOCONTEXT */ |
|
346 |
/* this is defined as a primitive to get defines from stc.h */ |
|
347 |
||
348 |
RETURN ( __mkSmallInteger(ALIENPOINTERS) ); |
|
349 |
%} |
|
350 |
! |
|
351 |
||
620 | 352 |
flagBehavior |
353 |
"return the flag code which marks Behavior-like instances. |
|
7190 | 354 |
Inline C-code and the VM check this single bit in the flag value when |
620 | 355 |
checking for behaviors." |
356 |
||
357 |
%{ /* NOCONTEXT */ |
|
358 |
/* this is defined as a primitive to get defines from stc.h */ |
|
359 |
||
8913 | 360 |
RETURN ( __mkSmallInteger(BEHAVIOR_INSTS) ); |
620 | 361 |
%} |
362 |
||
363 |
"consistency check: |
|
364 |
all class-entries must be behaviors; |
|
365 |
all behaviors must be flagged so (in its class's flags) |
|
366 |
(otherwise, VM will bark) |
|
367 |
all non-behaviors may not be flagged |
|
368 |
||
369 |
|bit| |
|
370 |
bit := Class flagBehavior. |
|
371 |
||
372 |
ObjectMemory allObjectsDo:[:o| |
|
373 |
o isBehavior ifTrue:[ |
|
16050 | 374 |
(o class flags bitTest:bit) ifFalse:[ |
375 |
self halt |
|
376 |
]. |
|
620 | 377 |
] ifFalse:[ |
16050 | 378 |
(o class flags bitTest:bit) ifTrue:[ |
379 |
self halt |
|
380 |
]. |
|
620 | 381 |
]. |
382 |
o class isBehavior ifFalse:[ |
|
16050 | 383 |
self halt |
620 | 384 |
] ifTrue:[ |
16050 | 385 |
(o class class flags bitTest:bit) ifFalse:[ |
386 |
self halt |
|
387 |
] |
|
620 | 388 |
] |
389 |
] |
|
390 |
" |
|
391 |
! |
|
392 |
||
393 |
flagBlock |
|
394 |
"return the flag code which marks Block-like instances. |
|
12094 | 395 |
The VM checks for either this bit or the blockLike bit in the flag |
2236 | 396 |
value when checking for blocks to be evaluated from bytecodes. |
397 |
However, compiled code only checks for the block bit." |
|
620 | 398 |
|
399 |
%{ /* NOCONTEXT */ |
|
400 |
/* this is defined as a primitive to get defines from stc.h */ |
|
401 |
||
8913 | 402 |
RETURN ( __mkSmallInteger(BLOCK_INSTS) ); |
620 | 403 |
%} |
404 |
! |
|
405 |
||
406 |
flagBlockContext |
|
407 |
"return the flag code which marks BlockContext-like instances. |
|
2226 | 408 |
The VM checks this single bit in the flag value when |
620 | 409 |
checking for blockContexts." |
410 |
||
411 |
%{ /* NOCONTEXT */ |
|
412 |
/* this is defined as a primitive to get defines from stc.h */ |
|
413 |
||
8913 | 414 |
RETURN ( __mkSmallInteger(BCONTEXT_INSTS) ); |
620 | 415 |
%} |
416 |
! |
|
417 |
||
2236 | 418 |
flagBlockLike |
419 |
"return the flag code which marks Block-like instances |
|
420 |
with respect to byteCode interpretation. |
|
12094 | 421 |
The VM checks for either this bit or the block bit in the flag |
2236 | 422 |
value when checking for blocks to be evaluated from bytecodes. |
423 |
However, compiled code only checks for the block bit." |
|
424 |
||
425 |
%{ /* NOCONTEXT */ |
|
426 |
/* this is defined as a primitive to get defines from stc.h */ |
|
427 |
||
8913 | 428 |
RETURN ( __mkSmallInteger(BLOCKLIKE_INSTS) ); |
2236 | 429 |
%} |
430 |
! |
|
431 |
||
620 | 432 |
flagBytes |
433 |
"return the flag code for byte-valued indexed instances. |
|
12094 | 434 |
The VM masks the flag value with the indexMask (maskIndexType) |
2226 | 435 |
and compares it to this flag value, when checking for byte valued |
436 |
variable instances." |
|
620 | 437 |
|
438 |
%{ /* NOCONTEXT */ |
|
439 |
/* this is defined as a primitive to get defines from stc.h */ |
|
440 |
||
8913 | 441 |
RETURN ( __mkSmallInteger(BYTEARRAY) ); |
620 | 442 |
%} |
443 |
" |
|
12094 | 444 |
Behavior flagBytes |
620 | 445 |
" |
446 |
! |
|
447 |
||
448 |
flagContext |
|
449 |
"return the flag code which marks Context-like instances. |
|
2226 | 450 |
The VM checks this single bit in the flag value when |
620 | 451 |
checking for contexts." |
452 |
||
453 |
%{ /* NOCONTEXT */ |
|
454 |
/* this is defined as a primitive to get defines from stc.h */ |
|
455 |
||
8913 | 456 |
RETURN ( __mkSmallInteger(CONTEXT_INSTS) ); |
620 | 457 |
%} |
458 |
! |
|
459 |
||
460 |
flagDoubles |
|
461 |
"return the flag code for double-valued indexed instances (i.e. 8-byte reals). |
|
12094 | 462 |
The VM masks the flag value with the indexMask (maskIndexType) |
2226 | 463 |
and compares it to this flag value, when checking for double valued |
464 |
variable instances." |
|
620 | 465 |
|
466 |
%{ /* NOCONTEXT */ |
|
467 |
/* this is defined as a primitive to get defines from stc.h */ |
|
468 |
||
8913 | 469 |
RETURN ( __mkSmallInteger(DOUBLEARRAY) ); |
620 | 470 |
%} |
471 |
" |
|
12094 | 472 |
Behavior flagDoubles |
473 |
||
474 |
(ByteArray flags bitAnd:(Behavior maskIndexType)) == (Behavior flagDoubles) |
|
475 |
(DoubleArray flags bitAnd:(Behavior maskIndexType)) == (Behavior flagDoubles) |
|
476 |
(Object flags bitAnd:(Behavior maskIndexType)) == (Behavior flagDoubles) |
|
620 | 477 |
" |
478 |
! |
|
479 |
||
7190 | 480 |
flagExternalBytes |
481 |
"return the flag code which marks ExternalBytes-like instances. |
|
482 |
Inline C-code and the VM check this single bit in the flag value when |
|
483 |
checking for an externalBytes-like objet." |
|
484 |
||
485 |
%{ /* NOCONTEXT */ |
|
486 |
/* this is defined as a primitive to get defines from stc.h */ |
|
487 |
||
8913 | 488 |
RETURN ( __mkSmallInteger(EXTERNALBYTES_INSTS) ); |
7190 | 489 |
%} |
490 |
! |
|
491 |
||
620 | 492 |
flagFloat |
493 |
"return the flag code which marks Float-like instances. |
|
7190 | 494 |
Inline C-code and the VM check this single bit in the flag value when |
2226 | 495 |
checking for a float." |
620 | 496 |
|
497 |
%{ /* NOCONTEXT */ |
|
498 |
/* this is defined as a primitive to get defines from stc.h */ |
|
499 |
||
8913 | 500 |
RETURN ( __mkSmallInteger(FLOAT_INSTS) ); |
620 | 501 |
%} |
502 |
! |
|
503 |
||
504 |
flagFloats |
|
505 |
"return the flag code for float-valued indexed instances (i.e. 4-byte reals). |
|
12094 | 506 |
The VM masks the flag value with the indexMask (maskIndexType) |
2226 | 507 |
and compares it to this flag value, when checking for double valued |
508 |
variable instances." |
|
620 | 509 |
|
510 |
%{ /* NOCONTEXT */ |
|
511 |
/* this is defined as a primitive to get defines from stc.h */ |
|
512 |
||
8913 | 513 |
RETURN ( __mkSmallInteger(FLOATARRAY) ); |
620 | 514 |
%} |
515 |
" |
|
12094 | 516 |
Behavior flagFloats |
620 | 517 |
" |
518 |
! |
|
519 |
||
1634 | 520 |
flagForSymbolic:aSymbol |
521 |
"return the flag code for indexed instances with aSymbolic type. |
|
12094 | 522 |
The argument may be one of |
16050 | 523 |
#float, #double, |
524 |
#word, #signedWord, |
|
525 |
#long, #signedLong |
|
526 |
#longLong, #signedLongLong, |
|
527 |
#byte |
|
528 |
#weakObjects |
|
6104 | 529 |
For VW compatibility, also accept: |
16050 | 530 |
#objects, #bytes, #weak. |
6104 | 531 |
" |
1634 | 532 |
|
533 |
%{ /* NOCONTEXT */ |
|
534 |
if (aSymbol == @symbol(float)) { |
|
16050 | 535 |
RETURN ( __mkSmallInteger(FLOATARRAY) ); |
1634 | 536 |
} |
537 |
if (aSymbol == @symbol(double)) { |
|
16050 | 538 |
RETURN ( __mkSmallInteger(DOUBLEARRAY) ); |
1634 | 539 |
} |
540 |
if (aSymbol == @symbol(long)) { |
|
16050 | 541 |
RETURN ( __mkSmallInteger(LONGARRAY) ); |
1634 | 542 |
} |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
543 |
if (aSymbol == @symbol(longLong)) { |
16050 | 544 |
RETURN ( __mkSmallInteger(LONGLONGARRAY) ); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
545 |
} |
1634 | 546 |
if (aSymbol == @symbol(word)) { |
16050 | 547 |
RETURN ( __mkSmallInteger(WORDARRAY) ); |
1634 | 548 |
} |
549 |
if (aSymbol == @symbol(signedWord)) { |
|
16050 | 550 |
RETURN ( __mkSmallInteger(SWORDARRAY) ); |
1634 | 551 |
} |
552 |
if (aSymbol == @symbol(signedLong)) { |
|
16050 | 553 |
RETURN ( __mkSmallInteger(SLONGARRAY) ); |
1634 | 554 |
} |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
555 |
if (aSymbol == @symbol(signedLongLong)) { |
16050 | 556 |
RETURN ( __mkSmallInteger(SLONGLONGARRAY) ); |
6104 | 557 |
} |
558 |
if ((aSymbol == @symbol(byte)) || (aSymbol == @symbol(bytes))) { |
|
16050 | 559 |
RETURN ( __mkSmallInteger(BYTEARRAY) ); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
560 |
} |
6104 | 561 |
if (aSymbol == @symbol(objects)) { |
16050 | 562 |
RETURN ( __mkSmallInteger(POINTERARRAY) ); |
6104 | 563 |
} |
10605 | 564 |
if ((aSymbol == @symbol(weakObjects)) || (aSymbol == @symbol(weak))) { |
16050 | 565 |
RETURN ( __mkSmallInteger(WKPOINTERARRAY) ); |
1634 | 566 |
} |
567 |
%}. |
|
2666
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
568 |
^ 0 "/ not indexed |
10605 | 569 |
|
570 |
"Modified: / 07-06-2007 / 11:57:44 / cg" |
|
1634 | 571 |
! |
572 |
||
15948 | 573 |
flagJavaArray |
574 |
"return the flag code which marks Java array-like instances. |
|
575 |
The VM checks this single bit in the flag value when |
|
576 |
checking for a java arrays." |
|
577 |
||
578 |
%{ /* NOCONTEXT */ |
|
579 |
/* this is defined as a primitive to get defines from stc.h */ |
|
580 |
||
581 |
RETURN ( __mkSmallInteger(JARRAY_INSTS) ); |
|
582 |
%} |
|
583 |
! |
|
584 |
||
3141 | 585 |
flagJavaClass |
586 |
"return the flag code which marks JavaClass-like instances. |
|
587 |
The VM checks this single bit in the flag value when |
|
588 |
checking for a javaClass." |
|
589 |
||
590 |
%{ /* NOCONTEXT */ |
|
591 |
/* this is defined as a primitive to get defines from stc.h */ |
|
592 |
||
8913 | 593 |
RETURN ( __mkSmallInteger(JCLASS_INSTS) ); |
3141 | 594 |
%} |
595 |
! |
|
596 |
||
2801 | 597 |
flagJavaMethod |
598 |
"return the flag code which marks JavaMethod-like instances. |
|
7190 | 599 |
Inline C-code and the VM check this single bit in the flag value when |
2801 | 600 |
checking for a method." |
601 |
||
602 |
%{ /* NOCONTEXT */ |
|
603 |
/* this is defined as a primitive to get defines from stc.h */ |
|
604 |
||
8913 | 605 |
RETURN ( __mkSmallInteger(JMETHOD_INSTS) ); |
2801 | 606 |
%} |
607 |
! |
|
608 |
||
4307 | 609 |
flagLongLongs |
610 |
"return the flag code for longlong-valued indexed instances (i.e. 8-byte). |
|
12094 | 611 |
The VM masks the flag value with the indexMask (maskIndexType) |
612 |
and compares it to this flag value, when checking for |
|
4307 | 613 |
unsigned long valued variable instances." |
614 |
||
615 |
%{ /* NOCONTEXT */ |
|
616 |
/* this is defined as a primitive to get defines from stc.h */ |
|
617 |
||
8913 | 618 |
RETURN ( __mkSmallInteger(LONGLONGARRAY) ); |
4307 | 619 |
%} |
620 |
" |
|
12094 | 621 |
Behavior flagLongLongs |
4307 | 622 |
" |
623 |
! |
|
624 |
||
620 | 625 |
flagLongs |
626 |
"return the flag code for long-valued indexed instances (i.e. 4-byte). |
|
12094 | 627 |
The VM masks the flag value with the indexMask (maskIndexType) |
628 |
and compares it to this flag value, when checking for |
|
2226 | 629 |
unsigned long valued variable instances." |
620 | 630 |
|
631 |
%{ /* NOCONTEXT */ |
|
632 |
/* this is defined as a primitive to get defines from stc.h */ |
|
633 |
||
8913 | 634 |
RETURN ( __mkSmallInteger(LONGARRAY) ); |
620 | 635 |
%} |
636 |
" |
|
12094 | 637 |
Behavior flagLongs |
620 | 638 |
" |
639 |
! |
|
640 |
||
5743 | 641 |
flagMetaMethod |
642 |
"return the flag code which marks MetaMethod-like instances. |
|
7190 | 643 |
Inline C-code and the VM check this single bit in the flag value when |
5743 | 644 |
about to evaluate a method." |
645 |
||
646 |
%{ /* NOCONTEXT */ |
|
647 |
/* this is defined as a primitive to get defines from stc.h */ |
|
648 |
||
8913 | 649 |
RETURN ( __mkSmallInteger(METAMETHOD_INSTS) ); |
5743 | 650 |
%} |
651 |
! |
|
652 |
||
620 | 653 |
flagMethod |
654 |
"return the flag code which marks Method-like instances. |
|
7190 | 655 |
Inline C-code and the VM check this single bit in the flag value when |
2226 | 656 |
checking for a method." |
620 | 657 |
|
658 |
%{ /* NOCONTEXT */ |
|
659 |
/* this is defined as a primitive to get defines from stc.h */ |
|
660 |
||
8913 | 661 |
RETURN ( __mkSmallInteger(METHOD_INSTS) ); |
620 | 662 |
%} |
663 |
! |
|
664 |
||
665 |
flagNonObjectInst |
|
666 |
"return the flag code which marks instances which have a |
|
667 |
non-object instance variable (in slot 1). |
|
668 |
(these are ignored by the garbage collector)" |
|
669 |
||
670 |
%{ /* NOCONTEXT */ |
|
671 |
/* this is defined as a primitive to get defines from stc.h */ |
|
672 |
||
8913 | 673 |
RETURN ( __mkSmallInteger(NONOBJECT_INSTS) ); |
620 | 674 |
%} |
675 |
! |
|
676 |
||
677 |
flagNotIndexed |
|
678 |
"return the flag code for non-indexed instances. |
|
679 |
You have to mask the flag value with indexMask when comparing |
|
680 |
it with flagNotIndexed." |
|
681 |
||
682 |
^ 0 |
|
683 |
! |
|
684 |
||
685 |
flagPointers |
|
686 |
"return the flag code for pointer indexed instances (i.e. Array of object). |
|
12094 | 687 |
The VM masks the flag value with the indexMask (maskIndexType) |
688 |
and compares it to this flag value, when checking for |
|
2226 | 689 |
pointer variable instances." |
620 | 690 |
|
691 |
%{ /* NOCONTEXT */ |
|
692 |
/* this is defined as a primitive to get defines from stc.h */ |
|
693 |
||
8913 | 694 |
RETURN ( __mkSmallInteger(POINTERARRAY) ); |
620 | 695 |
%} |
696 |
" |
|
12094 | 697 |
Behavior flagPointers |
620 | 698 |
" |
699 |
! |
|
700 |
||
1383 | 701 |
flagRegular |
702 |
"return the flag code which marks regular instances." |
|
703 |
||
704 |
^ 0 |
|
705 |
||
706 |
"Created: 12.5.1996 / 17:53:36 / cg" |
|
707 |
! |
|
708 |
||
4307 | 709 |
flagSignedLongLongs |
710 |
"return the flag code for signed longlong-valued indexed instances (i.e. 8-byte). |
|
12094 | 711 |
The VM masks the flag value with the indexMask (maskIndexType) |
712 |
and compares it to this flag value, when checking for |
|
4307 | 713 |
signed long valued variable instances." |
714 |
||
715 |
%{ /* NOCONTEXT */ |
|
716 |
/* this is defined as a primitive to get defines from stc.h */ |
|
717 |
||
8913 | 718 |
RETURN ( __mkSmallInteger(SLONGLONGARRAY) ); |
4307 | 719 |
%} |
720 |
" |
|
721 |
Behavior flagSignedLongLongs |
|
722 |
" |
|
723 |
! |
|
724 |
||
1634 | 725 |
flagSignedLongs |
726 |
"return the flag code for signed long-valued indexed instances (i.e. 4-byte). |
|
12094 | 727 |
The VM masks the flag value with the indexMask (maskIndexType) |
728 |
and compares it to this flag value, when checking for |
|
2226 | 729 |
signed long valued variable instances." |
1634 | 730 |
|
731 |
%{ /* NOCONTEXT */ |
|
732 |
/* this is defined as a primitive to get defines from stc.h */ |
|
733 |
||
8913 | 734 |
RETURN ( __mkSmallInteger(SLONGARRAY) ); |
1634 | 735 |
%} |
736 |
" |
|
737 |
Behavior flagSignedLongs |
|
738 |
" |
|
739 |
! |
|
740 |
||
741 |
flagSignedWords |
|
742 |
"return the flag code for signed word-valued indexed instances (i.e. 2-byte). |
|
12094 | 743 |
The VM masks the flag value with the indexMask (maskIndexType) |
744 |
and compares it to this flag value, when checking for |
|
2226 | 745 |
signed word valued variable instances." |
1634 | 746 |
|
747 |
%{ /* NOCONTEXT */ |
|
748 |
/* this is defined as a primitive to get defines from stc.h */ |
|
749 |
||
8913 | 750 |
RETURN ( __mkSmallInteger(SWORDARRAY) ); |
1634 | 751 |
%} |
752 |
" |
|
753 |
Behavior flagSignedWords |
|
754 |
" |
|
755 |
! |
|
756 |
||
620 | 757 |
flagSymbol |
758 |
"return the flag code which marks Symbol-like instances. |
|
7190 | 759 |
Inline C-code and the VM check this single bit in the flag value when |
620 | 760 |
checking for symbols." |
761 |
||
762 |
%{ /* NOCONTEXT */ |
|
763 |
/* this is defined as a primitive to get defines from stc.h */ |
|
764 |
||
8913 | 765 |
RETURN ( __mkSmallInteger(SYMBOL_INSTS) ); |
620 | 766 |
%} |
767 |
! |
|
768 |
||
10605 | 769 |
flagWeak |
770 |
"return the flag code for weak-object-pointer indexed instances. |
|
12094 | 771 |
The VM masks the flag value with the indexMask (maskIndexType) |
772 |
and compares it to this flag value, when checking for |
|
10605 | 773 |
weak pointer variable instances." |
774 |
||
775 |
%{ /* NOCONTEXT */ |
|
776 |
/* this is defined as a primitive to get defines from stc.h */ |
|
777 |
||
778 |
RETURN ( __mkSmallInteger(WKPOINTERARRAY) ); |
|
779 |
%} |
|
780 |
" |
|
12094 | 781 |
Behavior flagWeak |
10605 | 782 |
" |
783 |
||
784 |
"Created: / 07-06-2007 / 11:59:12 / cg" |
|
785 |
! |
|
786 |
||
620 | 787 |
flagWeakPointers |
788 |
"return the flag code for weak pointer indexed instances (i.e. WeakArray). |
|
12094 | 789 |
The VM masks the flag value with the indexMask (maskIndexType) |
2226 | 790 |
and compares it to this flag value, when checking for weak pointers." |
620 | 791 |
|
792 |
%{ /* NOCONTEXT */ |
|
793 |
/* this is defined as a primitive to get defines from stc.h */ |
|
794 |
||
8913 | 795 |
RETURN ( __mkSmallInteger(WKPOINTERARRAY) ); |
620 | 796 |
%} |
797 |
! |
|
798 |
||
799 |
flagWords |
|
800 |
"return the flag code for word-valued indexed instances (i.e. 2-byte). |
|
12094 | 801 |
The VM masks the flag value with the indexMask (maskIndexType) |
802 |
and compares it to this flag value, when checking for |
|
2226 | 803 |
unsigned word valued variable instances." |
620 | 804 |
|
805 |
%{ /* NOCONTEXT */ |
|
806 |
/* this is defined as a primitive to get defines from stc.h */ |
|
807 |
||
8913 | 808 |
RETURN ( __mkSmallInteger(WORDARRAY) ); |
620 | 809 |
%} |
810 |
" |
|
12094 | 811 |
Behavior flagWords |
620 | 812 |
" |
813 |
! |
|
814 |
||
815 |
maskIndexType |
|
816 |
"return a mask to extract all index-type bits" |
|
817 |
||
818 |
%{ /* NOCONTEXT */ |
|
819 |
/* this is defined as a primitive to get defines from stc.h */ |
|
820 |
||
8913 | 821 |
RETURN ( __mkSmallInteger(ARRAYMASK) ); |
620 | 822 |
%} |
823 |
! ! |
|
824 |
||
8962 | 825 |
!Behavior class methodsFor:'helpers'! |
826 |
||
15125 | 827 |
classesSortedByLoadOrder2:aCollectionOfClasses |
828 |
"return a copy of the given collection of classes, which is sorted |
|
829 |
by inheritance and superclass-of-any-private class. |
|
830 |
This is the optimal order for loading, and the required order for compilation. |
|
831 |
||
832 |
This is an alternate algorithm showing cycles" |
|
833 |
||
15230 | 834 |
|orderedTuples| |
835 |
||
836 |
orderedTuples := OrderedCollection new:aCollectionOfClasses size. |
|
15125 | 837 |
aCollectionOfClasses do:[:eachClass| |
16050 | 838 |
|sharedPools| |
839 |
orderedTuples add:(Array with:eachClass with:eachClass superclass). |
|
840 |
sharedPools := eachClass sharedPools. |
|
841 |
sharedPools notEmptyOrNil ifTrue:[ |
|
842 |
orderedTuples add:((OrderedCollection with:eachClass) addAll:sharedPools). |
|
843 |
]. |
|
844 |
eachClass allPrivateClasses do:[:eachPrivateClass| |superClassOwner| |
|
845 |
superClassOwner := eachPrivateClass superclass. |
|
846 |
"take care of classes inheriting from nil or ProtoObject" |
|
847 |
superClassOwner isBehavior ifTrue:[ |
|
848 |
superClassOwner := superClassOwner owningClassOrYourself. |
|
849 |
]. |
|
850 |
orderedTuples add:(Array with:eachPrivateClass with:superClassOwner). |
|
851 |
sharedPools := eachPrivateClass sharedPools. |
|
852 |
sharedPools notEmptyOrNil ifTrue:[ |
|
853 |
orderedTuples add:((OrderedCollection with:eachPrivateClass) addAll:sharedPools). |
|
854 |
]. |
|
855 |
]. |
|
15125 | 856 |
]. |
857 |
||
858 |
"I am only interested in my classes" |
|
859 |
^ orderedTuples topologicalSort intersect:aCollectionOfClasses. |
|
860 |
||
861 |
" |
|
862 |
Class classesSortedByLoadOrder:stx_libbasic compiled_classes_common |
|
863 |
Class classesSortedByLoadOrder2:stx_libbasic compiled_classes_common |
|
864 |
Class classesSortedByLoadOrder:stx_libjava compiled_classes_common |
|
865 |
Class classesSortedByLoadOrder2:stx_libjava compiled_classes_common |
|
866 |
" |
|
867 |
! |
|
868 |
||
9849 | 869 |
classesSortedByLoadOrder:someClasses |
870 |
"return a copy of the given collection of classes, which is sorted |
|
871 |
by inheritance and superclass-of-any-private class. |
|
872 |
This is the optimal order for loading, and the required order for compilation" |
|
873 |
||
874 |
|remaining classesInLoadOrder| |
|
875 |
||
10008
85b80de0562a
fix private class dependency handling in #classesSortedByLoadOrder:
Stefan Vogel <sv@exept.de>
parents:
9849
diff
changeset
|
876 |
"private classes are not loaded directly, so ignore them" |
14990 | 877 |
remaining := someClasses select:[:eachClass| eachClass isPrivate not] as:IdentitySet. |
13419 | 878 |
"JV-2011-05-05: Sort the classes by name to get more stable order. |
13414 | 879 |
This stabilizes order of classes in generated build files and |
880 |
makes text-based diffing/merging easier for both human beings |
|
881 |
and version control systems" |
|
882 |
remaining := remaining asOrderedCollection sort:[:a :b|a name < b name]. |
|
10008
85b80de0562a
fix private class dependency handling in #classesSortedByLoadOrder:
Stefan Vogel <sv@exept.de>
parents:
9849
diff
changeset
|
883 |
classesInLoadOrder := OrderedCollection new:(remaining size). |
85b80de0562a
fix private class dependency handling in #classesSortedByLoadOrder:
Stefan Vogel <sv@exept.de>
parents:
9849
diff
changeset
|
884 |
|
9849 | 885 |
[remaining notEmpty] whileTrue:[ |
16050 | 886 |
|thoseWithOtherSuperclasses thoseWhichCanBeLoadedNow| |
887 |
||
888 |
"find the next class(es) to be loaded. |
|
889 |
Consider first: |
|
890 |
all those, which do not have a superclass in the remaining set. |
|
891 |
and which do not use a shared pool defined in the remaining set" |
|
892 |
||
893 |
thoseWithOtherSuperclasses := |
|
894 |
remaining |
|
895 |
reject:[:eachClass | |
|
896 |
(remaining includes:eachClass superclass) |
|
897 |
or:[eachClass sharedPoolNames contains:[:eachPoolSymbol| |
|
898 |
remaining contains:[:eachRemainingClass| eachPoolSymbol = eachRemainingClass name] |
|
899 |
] |
|
900 |
]. |
|
901 |
]. |
|
902 |
||
903 |
"second: the subset with all those having no private classes, |
|
904 |
or having private classes, whose superclasses are NOT in the remaining set, |
|
905 |
or having private classes which do not use a shared pool in the remaining set" |
|
906 |
||
907 |
thoseWhichCanBeLoadedNow := |
|
908 |
thoseWithOtherSuperclasses |
|
909 |
reject:[:eachClass | |
|
910 |
eachClass allPrivateClasses contains:[:eachPrivateClass| |
|
911 |
|superClassesOwner sharedPools| |
|
912 |
superClassesOwner := eachPrivateClass superclass. |
|
913 |
"take care of classes inheriting from nil or ProtoObject" |
|
914 |
superClassesOwner isBehavior ifTrue:[ |
|
915 |
superClassesOwner := superClassesOwner owningClassOrYourself. |
|
916 |
]. |
|
917 |
sharedPools := eachPrivateClass sharedPools. |
|
918 |
(superClassesOwner ~~ eachClass |
|
919 |
and:[remaining includes:superClassesOwner]) |
|
920 |
or:[remaining includesAny:sharedPools] |
|
921 |
]. |
|
922 |
]. |
|
923 |
||
924 |
thoseWhichCanBeLoadedNow isEmpty ifTrue:[ |
|
925 |
thoseWithOtherSuperclasses isEmpty ifTrue:[ |
|
926 |
"this does not normally happen" |
|
927 |
self error:'superclass order is cyclic'. |
|
928 |
] ifFalse:[ |
|
929 |
"no class found, that may be loaded - maybe there is a cyclic |
|
930 |
dependency involving private classes. |
|
931 |
If you proceed here, private class dependencies are ignored |
|
932 |
for this pass" |
|
933 |
self error:'load order is cyclic (care for private classes)' mayProceed:true. |
|
934 |
thoseWhichCanBeLoadedNow := thoseWithOtherSuperclasses. |
|
935 |
]. |
|
936 |
]. |
|
937 |
remaining removeAllFoundIn:thoseWhichCanBeLoadedNow. |
|
938 |
classesInLoadOrder addAll:(thoseWhichCanBeLoadedNow sort:[:a :b | a name < b name]). |
|
9849 | 939 |
]. |
940 |
^ classesInLoadOrder |
|
941 |
||
942 |
" |
|
12094 | 943 |
Class classesSortedByLoadOrder:(Smalltalk allClassesInPackage:'stx:libbasic') |
944 |
Class classesSortedByLoadOrder:(Smalltalk allClassesInPackage:'stx:libbasic3') |
|
945 |
Class classesSortedByLoadOrder:(Smalltalk allClassesInPackage:'stx:libwidg') |
|
15125 | 946 |
Class classesSortedByLoadOrder:(Smalltalk allClassesInPackage:'stx:libjava') |
9849 | 947 |
" |
948 |
||
949 |
"Created: / 14-09-2006 / 11:21:25 / cg" |
|
13215
14d2bc8d5c5f
changed: #classesSortedByLoadOrder:
Claus Gittinger <cg@exept.de>
parents:
12936
diff
changeset
|
950 |
"Modified: / 18-01-2011 / 17:55:59 / cg" |
13414 | 951 |
"Modified: / 05-05-2011 / 12:43:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9849 | 952 |
! |
953 |
||
8962 | 954 |
commonSuperclassOf:listOfClassesOrClassNames |
11984 | 955 |
"given a list of classes, return the common superclass. |
956 |
A helper for the browser, some dialogs and some refactorings" |
|
957 |
||
8962 | 958 |
|common| |
959 |
||
960 |
listOfClassesOrClassNames do:[:classOrClassName | |
|
16050 | 961 |
|class| |
962 |
||
963 |
class := classOrClassName isBehavior |
|
964 |
ifTrue:[classOrClassName] |
|
965 |
ifFalse:[Smalltalk classNamed:classOrClassName]. |
|
966 |
||
967 |
common isNil ifTrue:[ |
|
968 |
common := class |
|
969 |
] ifFalse:[ |
|
970 |
(class isSubclassOf:common) ifTrue:[ |
|
971 |
"keep common" |
|
972 |
] ifFalse:[ |
|
973 |
(common isSubclassOf:class) ifTrue:[ |
|
974 |
common := class |
|
975 |
] ifFalse:[ |
|
976 |
common := common commonSuperclass:class. |
|
8962 | 977 |
|
978 |
"/ "walk up, checking" |
|
979 |
"/ found := false. |
|
980 |
"/ |
|
981 |
"/ common allSuperclassesDo:[:sup | |
|
982 |
"/ (found not and:[class isSubclassOf:sup]) ifTrue:[ |
|
983 |
"/ common := sup. |
|
984 |
"/ found := true. |
|
985 |
"/ ] |
|
986 |
"/ ]. |
|
987 |
"/ found ifFalse:[ |
|
988 |
"/ class allSuperclassesDo:[:sup | |
|
989 |
"/ (found not and:[common isSubclassOf:sup]) ifTrue:[ |
|
990 |
"/ common := sup. |
|
991 |
"/ found := true. |
|
992 |
"/ ] |
|
993 |
"/ ]. |
|
994 |
"/ ]. |
|
16050 | 995 |
] |
996 |
]. |
|
997 |
]. |
|
998 |
(common isNil or:[common == Object]) ifTrue:[^ common]. |
|
8962 | 999 |
]. |
1000 |
^ common |
|
1001 |
||
11984 | 1002 |
" |
1003 |
Class commonSuperclassOf:#(Array OrderedCollection Set) |
|
1004 |
Class commonSuperclassOf:#(Character Number Point) |
|
1005 |
" |
|
1006 |
||
8962 | 1007 |
"Modified: 17.6.1996 / 17:09:21 / stefan" |
1008 |
"Modified: 5.9.1996 / 19:34:41 / cg" |
|
1009 |
! ! |
|
1010 |
||
4964 | 1011 |
!Behavior class methodsFor:'misc'! |
1012 |
||
1013 |
autoload |
|
1014 |
"for compatibility with autoloaded classes - dummy here" |
|
1015 |
||
1016 |
^ self |
|
1017 |
||
1018 |
! ! |
|
1019 |
||
1760 | 1020 |
!Behavior class methodsFor:'queries'! |
620 | 1021 |
|
4332
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
1022 |
definitionSelectorFirstParts |
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
1023 |
"return a collection of partial class-definition selectors" |
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
1024 |
|
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
1025 |
^ #( #'subclass:' |
16050 | 1026 |
#'variableSubclass:' |
1027 |
#'variableByteSubclass:' |
|
1028 |
#'variableWordSubclass:' |
|
1029 |
#'variableLongSubclass:' |
|
1030 |
#'variableSignedWordSubclass:' |
|
1031 |
#'variableSignedLongSubclass:' |
|
1032 |
#'variableLongLongSubclass:' |
|
1033 |
#'variableSignedLongLongSubclass:' |
|
1034 |
#'variableFloatSubclass:' |
|
1035 |
#'variableDoubleSubclass:' |
|
12094 | 1036 |
) |
4332
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
1037 |
! |
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
1038 |
|
4428 | 1039 |
definitionSelectors |
1040 |
"return a collection class-definition selectors" |
|
1041 |
||
12094 | 1042 |
^ #( |
16050 | 1043 |
#'subclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
1044 |
#'variableSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
|
1045 |
#'variableByteSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
|
1046 |
#'variableWordSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
|
1047 |
#'variableLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
|
1048 |
#'variableSignedWordSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
|
1049 |
#'variableSignedLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
|
1050 |
#'variableLongLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
|
1051 |
#'variableSignedLongLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
|
1052 |
#'variableFloatSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
|
1053 |
#'variableDoubleSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
|
1054 |
||
1055 |
"/ ST/X private subclasses |
|
1056 |
||
1057 |
#'subclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
|
1058 |
#'variableSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
|
1059 |
#'variableByteSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
|
1060 |
#'variableWordSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
|
1061 |
#'variableLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
|
1062 |
#'variableSignedWordSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
|
1063 |
#'variableSignedLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
|
1064 |
#'variableLongLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
|
1065 |
#'variableSignedLongLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
|
1066 |
#'variableFloatSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
|
1067 |
#'variableDoubleSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
|
1068 |
||
1069 |
"/ ST/V subclass messages |
|
1070 |
||
1071 |
#'subclass:instanceVariableNames:classVariableNames:poolDictionaries:' |
|
1072 |
#'variableByteSubclass:classVariableNames:poolDictionaries:' |
|
1073 |
#'variableSubclass:instanceVariableNames:classVariableNames:poolDictionaries:' |
|
1074 |
||
1075 |
"/ Dolphin |
|
1076 |
#'subclass:instanceVariableNames:classVariableNames:poolDictionaries:classInstanceVariableNames:' |
|
12094 | 1077 |
) |
9194 | 1078 |
! |
1079 |
||
1080 |
isBuiltInClass |
|
1081 |
"return true if this class is known by the run-time-system. |
|
1082 |
Here, true is returned for myself, false for subclasses." |
|
1083 |
||
1084 |
^ (self == Behavior class) or:[self == Behavior] |
|
1085 |
||
1086 |
"Modified: 23.4.1996 / 15:55:52 / cg" |
|
14154
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
1087 |
! |
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
1088 |
|
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
1089 |
supportsMethodCategories |
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
1090 |
"return true, if my methods are categorized. |
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
1091 |
This is a hook for the browser to allow alien classes |
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
1092 |
to be handled (actually, this is not yet used)." |
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
1093 |
|
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
1094 |
^ true |
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
1095 |
|
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
1096 |
"Created: / 01-06-2012 / 20:37:46 / cg" |
9194 | 1097 |
! ! |
1098 |
||
16280 | 1099 |
|
7269 | 1100 |
!Behavior methodsFor:'Compatibility-Dolphin'! |
6329 | 1101 |
|
1102 |
allSubinstances |
|
11953 | 1103 |
"Compatibility method - do not use in new code. |
1104 |
Same as allSubInstances; added for Dolphin compatibility" |
|
1105 |
||
6865 | 1106 |
^ self allSubInstances |
1107 |
! |
|
1108 |
||
6889
7efa6d375ef7
+fromBinaryStoreBytes; +fromString.
Claus Gittinger <cg@exept.de>
parents:
6865
diff
changeset
|
1109 |
fromString:aString |
11953 | 1110 |
"reconstruct an instance of myself from the ascii-store string. |
1111 |
These bytes are typically the result from storing into a string/stream. |
|
1112 |
Same as readFrom:, for Dolphin compatibility." |
|
1113 |
||
14972 | 1114 |
|s result| |
1115 |
||
1116 |
s := aString readStream. |
|
1117 |
result := self readFrom:s. |
|
1118 |
"/ should check here for garbage - maybe later |
|
1119 |
"/ s atEnd ifFalse:[^ ConversionError raiseRequestWith:aString errorString:' - garbage at end of ', self name]. |
|
1120 |
^ result |
|
6889
7efa6d375ef7
+fromBinaryStoreBytes; +fromString.
Claus Gittinger <cg@exept.de>
parents:
6865
diff
changeset
|
1121 |
! |
7efa6d375ef7
+fromBinaryStoreBytes; +fromString.
Claus Gittinger <cg@exept.de>
parents:
6865
diff
changeset
|
1122 |
|
6865 | 1123 |
guid:aUUID |
11953 | 1124 |
"Compatibility method - do not use in new code. |
1125 |
An ignored dummy; for Dolphin compatibility." |
|
1126 |
||
1127 |
"/ intentionally left blank - for now |
|
11158 | 1128 |
! |
1129 |
||
1130 |
lookupMethod:selector |
|
11953 | 1131 |
"Compatibility method - do not use in new code. |
1132 |
Return the method for given selector aSelector or nil. |
|
1133 |
Only methods in the receiver - not in the superclass chain are returned. |
|
1134 |
For dolphin compatibility. |
|
1135 |
TODO: fixme if I am wrong, and dolphin does a full lookup here. If that is the case, |
|
1136 |
change to use lookupMethodFor:aSelector below." |
|
1137 |
||
11158 | 1138 |
^ self compiledMethodAt:selector |
6329 | 1139 |
! ! |
1140 |
||
7269 | 1141 |
!Behavior methodsFor:'Compatibility-Squeak'! |
4889 | 1142 |
|
12359 | 1143 |
classComment:comment stamp:commentStamp |
1144 |
self comment:comment |
|
1145 |
! |
|
1146 |
||
13600 | 1147 |
classSide |
1148 |
"alias for theMetaclass - return the metaclass" |
|
1149 |
||
1150 |
^ self theMetaclass |
|
1151 |
||
1152 |
"Created: / 26-08-2009 / 11:44:51 / Jaroslav Havlin <havlij6@fel.cvut.cz>" |
|
1153 |
"Modified: / 12-09-2010 / 16:38:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1154 |
"Modified (comment): / 20-08-2011 / 16:33:47 / cg" |
|
1155 |
! |
|
1156 |
||
9194 | 1157 |
defaultNameStemForInstances |
1158 |
"Answer a basis for names of default instances of the receiver" |
|
1159 |
||
1160 |
^ self name |
|
1161 |
||
1162 |
! |
|
5753
65cce9486ee9
added #lookupSelector: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5743
diff
changeset
|
1163 |
|
65cce9486ee9
added #lookupSelector: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5743
diff
changeset
|
1164 |
lookupSelector:aSelector |
65cce9486ee9
added #lookupSelector: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5743
diff
changeset
|
1165 |
"return the method for a selector - Squeak compatibility" |
65cce9486ee9
added #lookupSelector: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5743
diff
changeset
|
1166 |
|
65cce9486ee9
added #lookupSelector: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5743
diff
changeset
|
1167 |
^ self lookupMethodFor:aSelector |
6147 | 1168 |
! |
1169 |
||
12094 | 1170 |
selectorsWithArgs:numberOfArgs |
6147 | 1171 |
"Return all selectors defined in this class that take this number of arguments." |
1172 |
||
12094 | 1173 |
^ self selectors |
16050 | 1174 |
select:[:sel | sel numArgs == numberOfArgs] |
6147 | 1175 |
|
1176 |
" |
|
12094 | 1177 |
SmallInteger selectorsWithArgs:0 |
1178 |
SmallInteger selectorsWithArgs:2 |
|
6147 | 1179 |
SmallInteger selectorsWithArgs:3 |
12094 | 1180 |
SmallInteger selectorsWithArgs:4 |
6147 | 1181 |
" |
13600 | 1182 |
! |
1183 |
||
1184 |
theNonMetaClass |
|
1185 |
"alias for theNonMetaclass - return the class" |
|
1186 |
||
1187 |
^ self theNonMetaclass |
|
1188 |
||
1189 |
"Created: / 26-08-2009 / 11:39:08 / Jaroslav Havlin <havlij6@fel.cvut.cz>" |
|
1190 |
"Modified (comment): / 20-08-2011 / 16:35:07 / cg" |
|
4889 | 1191 |
! ! |
1192 |
||
7269 | 1193 |
!Behavior methodsFor:'Compatibility-VW'! |
5964 | 1194 |
|
1195 |
>> aSelector |
|
1196 |
"return the method stored under the given selector; nil if there is none" |
|
1197 |
||
1198 |
^ self compiledMethodAt:aSelector |
|
1199 |
||
1200 |
" |
|
1201 |
self compiledMethodAt:#compiledMethodAt: |
|
1202 |
self >> #compiledMethodAt: |
|
1203 |
" |
|
6115 | 1204 |
! |
1205 |
||
1206 |
fixedFieldsMask |
|
1207 |
"Mask on the format word to indicate the number of fixed fields in instances |
|
1208 |
of a behavior. If this is non-zero, the behavior must be pointer-type" |
|
1209 |
||
1210 |
^ 255 |
|
1211 |
||
1212 |
! |
|
1213 |
||
1214 |
format |
|
1215 |
"Answer an Integer that encodes the kinds and numbers of |
|
1216 |
variables of instances of the receiver. |
|
1217 |
||
1218 |
See instSize method for reference to the fixedFieldsMask bit mask of the format. |
|
1219 |
See isVariable method for reference to the indexableMask bit mask of the format. |
|
1220 |
See isBits method for reference to the pointersMask bit mask of the format. |
|
1221 |
All other bits of the format are unused and should be 0." |
|
1222 |
||
1223 |
"/ simulate a VW5i mask |
|
1224 |
||
1225 |
^ (self instSize |
|
1226 |
bitOr:( self isPointers ifTrue:[16384] ifFalse:[0])) |
|
1227 |
bitOr:( self isVariable ifTrue:[ 4096] ifFalse:[0]) |
|
1228 |
||
1229 |
! |
|
1230 |
||
10085 | 1231 |
getMethodDictionary |
1232 |
"ST 80 compatibility: return the receivers method dictionary." |
|
1233 |
||
1234 |
^ self methodDictionary |
|
1235 |
||
1236 |
"Modified: / 6.3.1998 / 15:45:50 / stefan" |
|
1237 |
! |
|
1238 |
||
6115 | 1239 |
instanceBehavior |
12094 | 1240 |
"Answer the instance behavior of the receiver. |
1241 |
This is the receiver for non metaclasses. |
|
6115 | 1242 |
Metaclass overrides this to answer a Metaclass's sole instance. |
1243 |
Same as #theNonMetaclass - for VW compatibility |
|
1244 |
" |
|
1245 |
||
1246 |
^ self theNonMetaclass |
|
1247 |
||
6968 | 1248 |
! |
1249 |
||
1250 |
shortName |
|
1251 |
^ self nameWithoutPrefix |
|
5964 | 1252 |
! ! |
1253 |
||
15230 | 1254 |
|
16280 | 1255 |
|
620 | 1256 |
!Behavior methodsFor:'accessing'! |
1257 |
||
1258 |
addSelector:newSelector withMethod:newMethod |
|
1259 |
"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
|
1260 |
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
|
1261 |
|
15046 | 1262 |
|oldMethod ns nsName selector newLookupObject| |
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
1263 |
|
7800 | 1264 |
(newSelector isMemberOf:Symbol) ifFalse:[ |
16050 | 1265 |
self error:'invalid selector'. |
7800 | 1266 |
]. |
13419 | 1267 |
|
14551 | 1268 |
ns := newMethod nameSpace. |
15046 | 1269 |
(ns notNil and:[(nsName := ns name) ~= self programmingLanguage defaultSelectorNameSpacePrefix]) ifTrue:[ |
16050 | 1270 |
selector := (':' , nsName , '::' , newSelector) asSymbol. |
1271 |
newLookupObject := Smalltalk at: #NamespaceAwareLookup. "/ so it can be nilled to disable that feature |
|
14550 | 1272 |
] ifFalse:[ |
16050 | 1273 |
selector := newSelector |
14550 | 1274 |
]. |
14535 | 1275 |
|
1276 |
"/ Q (cg): isn't that something that the caller should decide? |
|
13414 | 1277 |
oldMethod := self compiledMethodAt:selector. |
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
1278 |
oldMethod notNil ifTrue:[ |
16050 | 1279 |
newMethod restricted:(oldMethod isRestricted). |
1280 |
newMethod setPrivacy:(oldMethod privacy) flushCaches:false. |
|
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
1281 |
]. |
11578 | 1282 |
|
13414 | 1283 |
(self primAddSelector:selector withMethod:newMethod) ifFalse:[^ false]. |
1284 |
||
14550 | 1285 |
newLookupObject notNil ifTrue:[ |
16050 | 1286 |
lookupObject ~= newLookupObject ifTrue:[ |
1287 |
self lookupObject: newLookupObject |
|
1288 |
] |
|
13460 | 1289 |
]. |
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
1290 |
|
620 | 1291 |
" |
1292 |
if I have no subclasses, all we have to flush is cached |
|
1293 |
data for myself ... (actually, in any case all that needs |
|
1294 |
to be flushed is info for myself and all of my subclasses) |
|
1295 |
" |
|
1296 |
" |
|
1297 |
problem: this is slower; since looking for all subclasses is (currently) |
|
16050 | 1298 |
a bit slow :-( |
1299 |
We need the hasSubclasses-info bit in Behavior; now |
|
620 | 1300 |
|
1301 |
self withAllSubclassesDo:[:aClass | |
|
16050 | 1302 |
ObjectMemory flushInlineCachesFor:aClass withArgs:nargs. |
1303 |
ObjectMemory flushMethodCacheFor:aClass |
|
620 | 1304 |
]. |
1305 |
" |
|
1306 |
||
3805
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1307 |
"/ |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1308 |
"/ pass the selector AND the old method as changeArg |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1309 |
"/ - this allows for watchers to find out if its a new method or a method-change |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1310 |
"/ |
13414 | 1311 |
self changed:#methodDictionary with:(Array with:selector with:oldMethod). |
3805
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1312 |
|
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1313 |
"/ |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1314 |
"/ also notify a change of Smalltalk; |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1315 |
"/ this allows a dependent of Smalltalk to watch all class |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1316 |
"/ changes (no need for observing all classes) |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1317 |
"/ - this allows for watchers to find out if its a new method or a method-change |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1318 |
"/ |
13414 | 1319 |
Smalltalk changed:#methodInClass with:(Array with:self with:selector with:oldMethod). |
11574 | 1320 |
^ true. |
3805
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1321 |
|
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
1322 |
"Created: / 11-12-1995 / 13:59:37 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
1323 |
"Modified: / 04-08-2006 / 11:39:28 / cg" |
13414 | 1324 |
"Modified: / 20-07-2010 / 11:29:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
620 | 1325 |
! |
1326 |
||
9445 | 1327 |
basicAddSelector:newSelector withMethod:newMethod |
1328 |
"add the method given by 2nd argument under the selector given by |
|
1329 |
1st argument to the methodDictionary. Flushes all caches." |
|
1330 |
||
1331 |
|nargs | |
|
1332 |
||
1333 |
self primAddSelector:newSelector withMethod:newMethod. |
|
1334 |
||
1335 |
nargs := newSelector numArgs. |
|
1336 |
||
1337 |
ObjectMemory flushMethodCacheForSelector:newSelector. |
|
1338 |
"/ ObjectMemory flushMethodCache. |
|
1339 |
ObjectMemory flushInlineCachesWithArgs:nargs. |
|
1340 |
ObjectMemory flushCachesForSelector:newSelector |
|
1341 |
||
1342 |
"Created: / 15-07-2006 / 16:56:43 / cg" |
|
1343 |
! |
|
1344 |
||
10535 | 1345 |
basicRemoveSelector:aSelector |
12094 | 1346 |
"remove the selector, aSelector and its associated method |
10535 | 1347 |
from the methodDictionary" |
1348 |
||
1349 |
|dict newDict| |
|
1350 |
||
12094 | 1351 |
(Smalltalk |
16050 | 1352 |
changeRequest:#methodInClassRemoved |
1353 |
with:(Array with:self with:aSelector) |
|
13419 | 1354 |
) ifFalse:[ |
16050 | 1355 |
^ false |
11578 | 1356 |
]. |
1357 |
||
10535 | 1358 |
dict := self methodDictionary. |
1359 |
newDict := dict removeKeyAndCompress:aSelector. |
|
12094 | 1360 |
newDict isNil ifTrue:[ |
13414 | 1361 |
^ false. |
10535 | 1362 |
]. |
1363 |
self setMethodDictionary:newDict. |
|
1364 |
||
1365 |
" |
|
1366 |
actually, we would do better with less flushing ... |
|
1367 |
" |
|
1368 |
"/ObjectMemory flushCaches. |
|
1369 |
||
1370 |
"yes, we can:" |
|
1371 |
ObjectMemory flushCachesForSelector:aSelector. |
|
1372 |
^ true |
|
1373 |
||
13414 | 1374 |
"Modified: / 12-06-1996 / 11:54:29 / stefan" |
1375 |
"Modified: / 19-07-2010 / 11:22:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10535 | 1376 |
! |
1377 |
||
14703 | 1378 |
containingNameSpace |
1379 |
"return the namespace which contains me. |
|
1380 |
Defined here as a dummy; actually only real classes should ever be put into a namespace." |
|
1381 |
||
1382 |
^ nil |
|
1383 |
! |
|
1384 |
||
620 | 1385 |
flags |
16016 | 1386 |
"return the receiver's flag bits. |
1387 |
see flagXXX methods on my class side for details" |
|
620 | 1388 |
|
1389 |
^ flags |
|
1390 |
! |
|
1391 |
||
1392 |
instSize |
|
1393 |
"return the number of instance variables of the receiver. |
|
1394 |
This includes all superclass instance variables." |
|
1395 |
||
1396 |
^ instSize |
|
1397 |
! |
|
1398 |
||
12842 | 1399 |
lookupObject |
1400 |
"return the lookupObject (Jan's MetaObjectProtocol support) or nil. |
|
1401 |
If non-nil, no lookup is performed by the VM, instead the lookupObject |
|
1402 |
has to provide a method object for message sends." |
|
1403 |
||
13414 | 1404 |
| behavior lookup | |
13419 | 1405 |
|
1406 |
Lookup isNil ifTrue:[^ nil]. |
|
1407 |
||
13414 | 1408 |
behavior := self. |
13419 | 1409 |
[ behavior notNil ] whileTrue:[ |
16050 | 1410 |
lookup := behavior getLookupObject. |
1411 |
lookup notNil ifTrue: [^ lookup]. |
|
1412 |
behavior := behavior superclass |
|
13419 | 1413 |
]. |
1414 |
||
1415 |
^ Lookup builtin. |
|
13414 | 1416 |
|
1417 |
"Modified: / 26-04-2010 / 21:05:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1418 |
! |
|
1419 |
||
1420 |
lookupObject: anObject |
|
14535 | 1421 |
lookupObject == anObject ifTrue:[^ self ]. |
13414 | 1422 |
anObject isNil ifTrue:[^self setLookupObject: anObject]. |
1423 |
||
15948 | 1424 |
(anObject respondsTo: #lookupMethodForSelector:directedTo:for:withArguments:from:ilc:) |
13419 | 1425 |
ifFalse:[ |
16050 | 1426 |
self error:'Lookup object does not respond to #lookupMethodForSelector:directedTo:for:withArguments:from:ilc' |
13419 | 1427 |
]. |
1428 |
(anObject respondsTo:#superLookupObject:) |
|
1429 |
ifTrue:[ |
|
16050 | 1430 |
anObject superLookupObject: self lookupObject |
13419 | 1431 |
]. |
13414 | 1432 |
self setLookupObject: anObject. |
1433 |
||
1434 |
"Created: / 26-04-2010 / 13:35:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15948 | 1435 |
"Modified: / 26-10-2011 / 13:00:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
12842 | 1436 |
! |
1437 |
||
620 | 1438 |
methodDictionary |
1634 | 1439 |
"return the receivers method dictionary." |
620 | 1440 |
|
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
1441 |
^ methodDictionary |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1442 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1443 |
"Modified: 12.6.1996 / 13:47:08 / stefan" |
1634 | 1444 |
"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
|
1445 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1446 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1447 |
methodDictionary:dict |
12094 | 1448 |
"set the receivers method dictionary and flush inline caches." |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1449 |
|
1814 | 1450 |
dict isNil ifTrue:[ |
16050 | 1451 |
self error:'attempt to set methodDictionary to nil.' mayProceed:true. |
1452 |
^ self |
|
1814 | 1453 |
]. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1454 |
self setMethodDictionary:dict. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1455 |
ObjectMemory flushCaches. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1456 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1457 |
"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
|
1458 |
"Modified: 7.6.1996 / 08:39:51 / stefan" |
620 | 1459 |
! |
1460 |
||
7605
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1461 |
package |
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1462 |
"for protocol compatibility with class" |
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1463 |
|
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1464 |
^ '' |
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1465 |
! |
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1466 |
|
620 | 1467 |
removeSelector:aSelector |
12094 | 1468 |
"remove the selector, aSelector and its associated method |
620 | 1469 |
from the methodDictionary" |
1470 |
||
10535 | 1471 |
^ self basicRemoveSelector:aSelector |
620 | 1472 |
! |
1473 |
||
1474 |
selectors |
|
1475 |
"return the receivers selector array as an orderedCollection. |
|
1476 |
Notice: this may not be compatible with ST-80. |
|
1477 |
(should we return a Set ?)" |
|
1478 |
||
1814 | 1479 |
|md| |
1480 |
||
1967
e8a6fb1e14ce
oops - iNil instead of isNil
Claus Gittinger <cg@exept.de>
parents:
1918
diff
changeset
|
1481 |
(md := self methodDictionary) isNil ifTrue:[ |
16050 | 1482 |
'oops - nil methodDictionary' errorPrintCR. |
1483 |
^ #() |
|
1814 | 1484 |
]. |
1485 |
^ md keys |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1486 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1487 |
"Modified: 7.6.1996 / 15:33:18 / stefan" |
1967
e8a6fb1e14ce
oops - iNil instead of isNil
Claus Gittinger <cg@exept.de>
parents:
1918
diff
changeset
|
1488 |
"Modified: 12.11.1996 / 11:31:51 / cg" |
620 | 1489 |
! |
1490 |
||
1491 |
superclass |
|
1492 |
"return the receivers superclass" |
|
1493 |
||
1494 |
^ superclass |
|
1495 |
! ! |
|
1496 |
||
1497 |
!Behavior methodsFor:'autoload check'! |
|
1498 |
||
1499 |
autoload |
|
12094 | 1500 |
"force autoloading - do nothing here; |
620 | 1501 |
redefined in Autoload; see comment there" |
1502 |
||
1503 |
^ self |
|
1504 |
! |
|
1505 |
||
1506 |
isLoaded |
|
12094 | 1507 |
"return true, if the class has been loaded; |
620 | 1508 |
redefined in Autoload; see comment there" |
1509 |
||
1510 |
^ true |
|
6727 | 1511 |
! |
1512 |
||
1513 |
wasAutoloaded |
|
1514 |
"return true, if this class came into the system via an |
|
1515 |
autoload; false otherwise. |
|
1516 |
Returning false here. This allows different Behavior-like objects |
|
1517 |
(alien classes) to be handled by the browser as well." |
|
1518 |
||
1519 |
^ false |
|
1520 |
||
1521 |
"Created: 16.4.1996 / 16:27:16 / cg" |
|
620 | 1522 |
! ! |
1523 |
||
15230 | 1524 |
|
15769 | 1525 |
!Behavior methodsFor:'cleanup'! |
1526 |
||
1527 |
lowSpaceCleanup |
|
1528 |
"ignored here - redefined in some classes to |
|
1529 |
cleanup in low-memory situations" |
|
1530 |
||
1531 |
^ self |
|
1532 |
! ! |
|
1533 |
||
9639 | 1534 |
!Behavior methodsFor:'compiler interface'! |
1535 |
||
1536 |
browserClass |
|
12094 | 1537 |
"return the browser to use for this class - |
9639 | 1538 |
this can be redefined in special classes, to get different browsers" |
1539 |
||
1540 |
^ self class browserClass. |
|
1541 |
! |
|
1542 |
||
1543 |
compilerClass |
|
12094 | 1544 |
"return the compiler to use for this class - |
9639 | 1545 |
this can be redefined in special classes, to compile classes with |
1546 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1547 |
||
1548 |
^ self class compilerClass. |
|
1549 |
! |
|
1550 |
||
12936 | 1551 |
dllPath |
13419 | 1552 |
"if a class contains ExternalFunctions, |
12936 | 1553 |
return a collection of pathNames where to find the DLLs |
1554 |
containing the external functions. |
|
1555 |
||
1556 |
Do not code absolute path names here - keep them in the system settings. |
|
1557 |
Use this if the DLL location is kept in some registry entry." |
|
1558 |
||
1559 |
^ #() |
|
1560 |
! |
|
1561 |
||
9639 | 1562 |
evaluatorClass |
12094 | 1563 |
"return the compiler to use for expression evaluation for this class - |
9639 | 1564 |
this can be redefined in special classes, to evaluate expressions with |
1565 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1566 |
||
1567 |
^ self class evaluatorClass. |
|
1568 |
! |
|
1569 |
||
1570 |
formatterClass |
|
12094 | 1571 |
"return the parser to use for formatting (prettyPrinting) this class - |
9639 | 1572 |
this can be redefined in special classes, to format classes with |
1573 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1574 |
||
1575 |
^ self class formatterClass. |
|
620 | 1576 |
! |
1577 |
||
11990 | 1578 |
language |
12936 | 1579 |
<resource: #obsolete> |
1580 |
self obsoleteMethodWarning:'use #programmingLanguage or Smalltalk language'. |
|
12148
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1581 |
^ self class programmingLanguage |
11990 | 1582 |
|
1583 |
"Created: / 15-08-2009 / 09:06:46 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
1584 |
! |
|
1585 |
||
9639 | 1586 |
parserClass |
12094 | 1587 |
"return the parser to use for parsing this class - |
9639 | 1588 |
this can be redefined in special classes, to parse classes with |
1589 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1590 |
||
1591 |
^ self class parserClass. |
|
1592 |
! |
|
1593 |
||
12148
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1594 |
programmingLanguage |
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1595 |
|
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1596 |
^self class programmingLanguage |
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1597 |
|
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1598 |
"Created: / 15-08-2009 / 09:06:46 / Jan Vrany <vranyj1@fel.cvut.cz>" |
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1599 |
! |
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1600 |
|
9639 | 1601 |
subclassDefinerClass |
12094 | 1602 |
"Answer an evaluator class appropriate for evaluating definitions of new |
9639 | 1603 |
subclasses of this class." |
1604 |
||
1605 |
^ self class subclassDefinerClass. |
|
1606 |
! |
|
1607 |
||
1608 |
syntaxHighlighterClass |
|
12094 | 1609 |
"return the class to use for syntaxHighlighting (prettyPrinting) this class - |
9639 | 1610 |
this can be redefined in special classes, to highlight classes with |
1611 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1612 |
||
1613 |
^ self class syntaxHighlighterClass. |
|
1614 |
! ! |
|
1615 |
||
1616 |
!Behavior methodsFor:'compiling'! |
|
1617 |
||
15107 | 1618 |
compile:code |
1619 |
"compile code, aString for this class; |
|
1620 |
if successful update the method dictionary. |
|
1621 |
Returns the new method or nil (on failure)." |
|
1622 |
||
1623 |
^ self compilerClass |
|
16050 | 1624 |
compile:code |
1625 |
forClass:self |
|
15107 | 1626 |
|
1627 |
"Modified: 13.12.1995 / 10:56:00 / cg" |
|
1628 |
"Created: 1.4.1997 / 23:43:51 / stefan" |
|
1629 |
! |
|
1630 |
||
15344 | 1631 |
compile:code categorized:methodCategory |
1632 |
"compile code, aString for this class; |
|
1633 |
if successful update the method dictionary. |
|
1634 |
Returns the new method or nil (on failure)." |
|
1635 |
||
1636 |
^ self compilerClass |
|
1637 |
compile:code |
|
1638 |
forClass:self |
|
1639 |
inCategory:methodCategory |
|
1640 |
notifying:nil |
|
1641 |
! |
|
1642 |
||
1643 |
compile:code categorized:methodCategory notifying:requestor |
|
1644 |
"compile code, aString for this class; |
|
1645 |
if successful update the method dictionary. |
|
1646 |
Returns the new method or nil (on failure)." |
|
1647 |
||
1648 |
^ self compilerClass |
|
1649 |
compile:code |
|
1650 |
forClass:self |
|
1651 |
inCategory:methodCategory |
|
1652 |
notifying:requestor |
|
1653 |
! |
|
1654 |
||
9639 | 1655 |
compile:code notifying:requestor |
1656 |
"compile code, aString for this class; on any error, notify |
|
1657 |
requestor, anObject with the error reason. |
|
1658 |
Returns the new method or nil (on failure)." |
|
1659 |
||
1660 |
^ self compilerClass |
|
16050 | 1661 |
compile:code |
1662 |
forClass:self |
|
1663 |
notifying:requestor |
|
9639 | 1664 |
|
1665 |
"Modified: 13.12.1995 / 11:02:40 / cg" |
|
1666 |
"Created: 1.4.1997 / 23:43:43 / stefan" |
|
1667 |
! ! |
|
1668 |
||
1669 |
!Behavior methodsFor:'copying'! |
|
1670 |
||
12094 | 1671 |
canCloneFrom:anObject |
620 | 1672 |
"return true, if this class can clone an obsolete object as retrieved |
1673 |
by a binary load. Subclasses which do not want to have obsolete objects |
|
1674 |
be converted, should redefine this method to return false. |
|
1675 |
(However, conversion is never done silently in a binary load; you |
|
1676 |
have to have a handler for the binaryload errors and for the conversion |
|
1677 |
request signal.)" |
|
1678 |
||
1679 |
^ true |
|
1680 |
! |
|
1681 |
||
1682 |
cloneFrom:aPrototype |
|
1683 |
"return an instance of myself with variables initialized from |
|
1684 |
a prototype. This is used when instances of obsolete classes are |
|
12094 | 1685 |
binary loaded and a conversion is done on the obsolete object. |
620 | 1686 |
UserClasses may redefine this for better conversions." |
1687 |
||
4738 | 1688 |
|newInst indexed| |
620 | 1689 |
|
1690 |
indexed := false. |
|
1691 |
aPrototype class isVariable ifTrue:[ |
|
16050 | 1692 |
self isVariable ifTrue:[ |
1693 |
indexed := true. |
|
1694 |
]. |
|
1695 |
"otherwise, these are lost ..." |
|
620 | 1696 |
]. |
1697 |
indexed ifTrue:[ |
|
16050 | 1698 |
newInst := self basicNew:aPrototype basicSize |
620 | 1699 |
] ifFalse:[ |
16050 | 1700 |
newInst := self basicNew |
620 | 1701 |
]. |
1702 |
||
4692
055edf6e95af
Redefine #cloneFrom: using #cloneInstanceVariablesFrom:.
Stefan Vogel <sv@exept.de>
parents:
4682
diff
changeset
|
1703 |
newInst cloneInstanceVariablesFrom:aPrototype. |
055edf6e95af
Redefine #cloneFrom: using #cloneInstanceVariablesFrom:.
Stefan Vogel <sv@exept.de>
parents:
4682
diff
changeset
|
1704 |
|
620 | 1705 |
^ newInst |
1706 |
||
1707 |
" |
|
1708 |
Class withoutUpdatingChangesDo:[ |
|
16050 | 1709 |
Point subclass:#Point3D |
1710 |
instanceVariableNames:'z' |
|
1711 |
classVariableNames:'' |
|
1712 |
poolDictionaries:'' |
|
1713 |
category:'testing'. |
|
1714 |
(Point3D cloneFrom:1@2) inspect. |
|
620 | 1715 |
] |
1716 |
" |
|
1717 |
||
1718 |
" |
|
1719 |
Class withoutUpdatingChangesDo:[ |
|
16050 | 1720 |
Point variableSubclass:#Point3D |
1721 |
instanceVariableNames:'z' |
|
1722 |
classVariableNames:'' |
|
1723 |
poolDictionaries:'' |
|
1724 |
category:'testing'. |
|
1725 |
(Point3D cloneFrom:#(1 2 3)) inspect. |
|
620 | 1726 |
] |
1727 |
" |
|
1728 |
||
1729 |
" |
|
1730 |
|someObject| |
|
1731 |
||
1732 |
Class withoutUpdatingChangesDo:[ |
|
16050 | 1733 |
Object subclass:#TestClass1 |
1734 |
instanceVariableNames:'foo bar' |
|
1735 |
classVariableNames:'' |
|
1736 |
poolDictionaries:'' |
|
1737 |
category:'testing'. |
|
1738 |
someObject := TestClass1 new. |
|
1739 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
1740 |
Object subclass:#TestClass2 |
|
1741 |
instanceVariableNames:'bar foo' |
|
1742 |
classVariableNames:'' |
|
1743 |
poolDictionaries:'' |
|
1744 |
category:'testing'. |
|
1745 |
(TestClass2 cloneFrom:someObject) inspect. |
|
620 | 1746 |
] |
1747 |
" |
|
1748 |
! |
|
1749 |
||
10949 | 1750 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
620 | 1751 |
"return a deep copy of the receiver |
1752 |
- return the receiver here - time will show if this is ok" |
|
1753 |
||
1754 |
^ self |
|
1755 |
! |
|
1756 |
||
1757 |
simpleDeepCopy |
|
1758 |
"return a deep copy of the receiver |
|
1759 |
- return the receiver here - time will show if this is ok" |
|
1760 |
||
1761 |
^ self |
|
1762 |
! ! |
|
1763 |
||
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1764 |
!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
|
1765 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1766 |
addChangeRecordForClassRemove:aClassName |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1767 |
"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
|
1768 |
Defined as dummy here, since Behavior does not know about change management. |
9194 | 1769 |
(only Classes do). This allows different Behavior-like objects |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1770 |
(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
|
1771 |
|
9194 | 1772 |
"Created: 16.4.1996 / 16:30:09 / cg" |
1773 |
"Modified: 16.4.1996 / 18:10:35 / cg" |
|
1774 |
! ! |
|
1775 |
||
1776 |
!Behavior methodsFor:'dummy fileOut'! |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1777 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1778 |
fileOutDefinitionOn:aStream |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1779 |
"dummy fileOut defined here. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1780 |
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
|
1781 |
(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
|
1782 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1783 |
^ self |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1784 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1785 |
"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
|
1786 |
! ! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1787 |
|
620 | 1788 |
!Behavior methodsFor:'enumerating'! |
1789 |
||
1790 |
allDerivedInstancesDo:aBlock |
|
1791 |
"evaluate aBlock for all of my instances and all instances of subclasses. |
|
1792 |
This method is going to be removed for protocol compatibility with |
|
1793 |
other STs; use allSubInstancesDo:" |
|
1794 |
||
5862 | 1795 |
<resource:#obsolete> |
1796 |
||
9194 | 1797 |
self obsoleteMethodWarning:'use #allSubInstancesDo:'. |
1798 |
self allSubInstancesDo:aBlock |
|
1799 |
||
1800 |
" |
|
1801 |
StandardSystemView allDerivedInstancesDo:[:v | Transcript showCR:(v name)] |
|
1802 |
" |
|
1803 |
||
1804 |
"Modified: 31.7.1997 / 23:05:04 / cg" |
|
1805 |
! |
|
620 | 1806 |
|
1807 |
allInstancesDo:aBlock |
|
1808 |
"evaluate aBlock for all of my instances" |
|
1809 |
||
1810 |
ObjectMemory allInstancesOf:self do:[:anObject | |
|
16050 | 1811 |
aBlock value:anObject |
620 | 1812 |
] |
1813 |
||
1814 |
" |
|
1422 | 1815 |
StandardSystemView allInstancesDo:[:v | Transcript showCR:(v name)] |
620 | 1816 |
" |
1817 |
! |
|
1818 |
||
7809 | 1819 |
allOwningclassesDo:aBlock |
1820 |
"evaluate aBlock for all of my owners (i.e. owner, owner-of-owner etc)." |
|
1821 |
||
1822 |
|owner| |
|
1823 |
||
1824 |
owner := self owningClass. |
|
1825 |
[owner notNil] whileTrue:[ |
|
16050 | 1826 |
aBlock value:owner. |
1827 |
owner := owner owningClass. |
|
9194 | 1828 |
]. |
1829 |
||
1830 |
" |
|
1831 |
Method::MethodWhoInfo allOwningclassesDo:[:c | Transcript showCR:(c name)] |
|
1832 |
" |
|
1833 |
! |
|
7809 | 1834 |
|
5368
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1835 |
allSelectorsAndMethodsDo:aTwoArgBlock |
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1836 |
"evaluate the argument, aBlock for all selectors of mySelf and my metaclass, |
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1837 |
passing the corresponding method as second argument" |
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1838 |
|
8353 | 1839 |
<resource: #obsolete> |
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1840 |
self obsoleteMethodWarning:'use #instAndClassSelectorsAndMethodsDo:'. |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1841 |
|
6022 | 1842 |
self selectorsAndMethodsDo:aTwoArgBlock. |
9194 | 1843 |
self class selectorsAndMethodsDo:aTwoArgBlock. |
1844 |
! |
|
5368
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1845 |
|
620 | 1846 |
allSubInstancesDo:aBlock |
1847 |
"evaluate aBlock for all of my instances and all instances of subclasses" |
|
1848 |
||
1849 |
ObjectMemory allObjectsDo:[:anObject | |
|
16050 | 1850 |
(anObject isKindOf:self) ifTrue:[ |
1851 |
aBlock value:anObject |
|
1852 |
] |
|
620 | 1853 |
] |
1854 |
||
1855 |
" |
|
1422 | 1856 |
StandardSystemView allSubInstancesDo:[:v | Transcript showCR:(v name)] |
620 | 1857 |
" |
1858 |
! |
|
1859 |
||
1860 |
allSubclassesDo:aBlock |
|
1861 |
"evaluate aBlock for all of my subclasses. |
|
1862 |
There is no specific order, in which the entries are enumerated. |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1863 |
Warning: |
16050 | 1864 |
This will only enumerate globally known classes - for anonymous |
1865 |
behaviors, you have to walk over all instances of Behavior." |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1866 |
|
6931 | 1867 |
self allSubclassesInOrderDo:aBlock |
1868 |
||
1869 |
"/ self isMeta ifTrue:[ |
|
1870 |
"/ "/ metaclasses are not found via Smalltalk allClassesDo: |
|
1871 |
"/ "/ here, walk over classes and enumerate corresponding metas. |
|
1872 |
"/ self soleInstance allSubclassesDo:[:aSubClass | |
|
1873 |
"/ aBlock value:(aSubClass class) |
|
1874 |
"/ ]. |
|
1875 |
"/ ] ifFalse:[ |
|
1876 |
"/ Smalltalk allClassesDo:[:aClass | |
|
1877 |
"/ (aClass isSubclassOf:self) ifTrue:[ |
|
1878 |
"/ aBlock value:aClass |
|
1879 |
"/ ] |
|
1880 |
"/ ] |
|
1881 |
"/ ] |
|
620 | 1882 |
|
1883 |
" |
|
1422 | 1884 |
Collection allSubclassesDo:[:c | Transcript showCR:(c name)] |
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1885 |
Collection class allSubclassesDo:[:c | Transcript showCR:(c name)] |
620 | 1886 |
" |
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1887 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1888 |
"Modified: / 25.10.1997 / 21:17:13 / cg" |
9194 | 1889 |
! |
1890 |
||
1891 |
allSubclassesInOrderDo:aBlock |
|
620 | 1892 |
"evaluate aBlock for all of my subclasses. |
15562 | 1893 |
The subclasses are enumerated breath first (i.e. all of a classes superclasses |
1894 |
come before a class, which comes before any of its subclasses). |
|
1895 |
However, within one inheritance level, there is no specific order, |
|
1896 |
in which the entries are enumerated. |
|
6931 | 1897 |
Warning: |
15562 | 1898 |
This will only enumerate globally known classes - for anonymous |
1899 |
behaviors, you have to walk over all instances of Behavior." |
|
6931 | 1900 |
|
1901 |
|meta toDo cls| |
|
1902 |
||
1903 |
meta := self isMeta. |
|
12094 | 1904 |
|
6931 | 1905 |
toDo := OrderedCollection new. |
1906 |
toDo addAll:self theNonMetaclass subclasses. |
|
1907 |
[toDo notEmpty] whileTrue:[ |
|
15562 | 1908 |
cls := toDo removeFirst. |
1909 |
toDo addAll:cls subclasses. |
|
1910 |
meta ifTrue:[ |
|
1911 |
aBlock value:cls class. |
|
1912 |
] ifFalse:[ |
|
1913 |
aBlock value:cls. |
|
1914 |
] |
|
6931 | 1915 |
]. |
1916 |
||
1917 |
"/ self isMeta ifTrue:[ |
|
1918 |
"/ "/ metaclasses are not found via Smalltalk allClassesDo: |
|
1919 |
"/ "/ here, walk over classes and enumerate corresponding metas. |
|
1920 |
"/ self soleInstance allSubclassesDo:[:aSubClass | |
|
1921 |
"/ aBlock value:(aSubClass class) |
|
1922 |
"/ ]. |
|
1923 |
"/ ] ifFalse:[ |
|
1924 |
"/ Smalltalk allClassesDo:[:aClass | |
|
1925 |
"/ (aClass isSubclassOf:self) ifTrue:[ |
|
1926 |
"/ aBlock value:aClass |
|
1927 |
"/ ] |
|
1928 |
"/ ] |
|
1929 |
"/ ] |
|
620 | 1930 |
|
1931 |
" |
|
7435
c5afb1b0fd1b
Prepare for moving of SubclassInfo to subclass instcar in Class
Stefan Vogel <sv@exept.de>
parents:
7358
diff
changeset
|
1932 |
Collection allSubclassesInOrderDo:[:c | Transcript showCR:(c name)] |
c5afb1b0fd1b
Prepare for moving of SubclassInfo to subclass instcar in Class
Stefan Vogel <sv@exept.de>
parents:
7358
diff
changeset
|
1933 |
Collection class allSubclassesInOrderDo:[:c | Transcript showCR:(c name)] |
620 | 1934 |
" |
6931 | 1935 |
|
15562 | 1936 |
"Modified: / 25-10-1997 / 21:17:13 / cg" |
1937 |
"Modified (comment): / 27-07-2013 / 08:13:04 / cg" |
|
9194 | 1938 |
! |
1939 |
||
1940 |
allSuperclassesDo:aBlock |
|
1941 |
"evaluate aBlock for all of my superclasses" |
|
1942 |
||
16050 | 1943 |
|theClass |
1944 |
n "{ Class: SmallInteger }"| |
|
1945 |
||
1946 |
n := 1. |
|
9194 | 1947 |
theClass := self superclass. |
1948 |
[theClass notNil] whileTrue:[ |
|
16050 | 1949 |
aBlock value:theClass. |
1950 |
theClass := theClass superclass. |
|
1951 |
n := n + 1. |
|
1952 |
n > 100000 ifTrue:[ VMInternalError raiseErrorString:'deep inheritance' ]. |
|
9194 | 1953 |
] |
1954 |
||
1955 |
" |
|
1956 |
String allSuperclassesDo:[:c | Transcript showCR:(c name)] |
|
1957 |
" |
|
1958 |
! |
|
620 | 1959 |
|
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1960 |
instAndClassMethodsDo:aOneArgBlock |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1961 |
"evaluate the argument, aBlock for all methods of mySelf and my metaclass |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1962 |
(i.e. for both instance- and class methods)" |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1963 |
|
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
1964 |
self theNonMetaclass methodsDo:aOneArgBlock. |
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
1965 |
self theMetaclass methodsDo:aOneArgBlock. |
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1966 |
! |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1967 |
|
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1968 |
instAndClassSelectorsAndMethodsDo:aTwoArgBlock |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1969 |
"evaluate the argument, aBlock for all selectors of mySelf and my metaclass, |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1970 |
passing the corresponding method as second argument" |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1971 |
|
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1972 |
self selectorsAndMethodsDo:aTwoArgBlock. |
9194 | 1973 |
self class selectorsAndMethodsDo:aTwoArgBlock. |
1974 |
! |
|
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1975 |
|
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1976 |
methodsDo:aOneArgBlock |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1977 |
"evaluate the argument, aBlock for all my methods" |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1978 |
|
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
1979 |
self methodDictionary do:aOneArgBlock |
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1980 |
|
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1981 |
" |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1982 |
UndefinedObject methodsDo:[:m | Transcript showCR:m whoString] |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1983 |
UndefinedObject selectorsDo:[:sym | Transcript showCR:sym] |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1984 |
" |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1985 |
! |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1986 |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1987 |
selectorsAndMethodsDo:aTwoArgBlock |
5368
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1988 |
"evaluate the argument, aBlock for all my selectors, |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
1989 |
passing the corresponding method as second argument" |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
1990 |
|
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
1991 |
self methodDictionary keysAndValuesDo:aTwoArgBlock |
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1992 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1993 |
"Created: / 27.10.1997 / 14:09:27 / cg" |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1994 |
! |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1995 |
|
9194 | 1996 |
selectorsDo:aOneArgBlock |
1997 |
"evaluate the argument, aBlock for all my selectors" |
|
1998 |
||
1999 |
self methodDictionary keysDo:aOneArgBlock |
|
2000 |
! |
|
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
2001 |
|
620 | 2002 |
subclassesDo:aBlock |
2003 |
"evaluate the argument, aBlock for all immediate subclasses. |
|
2004 |
This will only enumerate globally known classes - for anonymous |
|
2005 |
behaviors, you have to walk over all instances of Behavior." |
|
2006 |
||
7435
c5afb1b0fd1b
Prepare for moving of SubclassInfo to subclass instcar in Class
Stefan Vogel <sv@exept.de>
parents:
7358
diff
changeset
|
2007 |
"Do it the hard way. Subclasses redefine this" |
5581 | 2008 |
Smalltalk allClassesDo:[:aClass | |
16050 | 2009 |
(aClass superclass == self) ifTrue:[ |
2010 |
aBlock value:aClass |
|
2011 |
] |
|
9194 | 2012 |
] |
2013 |
! |
|
5638 | 2014 |
|
12094 | 2015 |
whichClassSatisfies: aBlock |
12862
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2016 |
"return the first class along the superclass-chain, which satisfies aBlock. |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2017 |
Return nil, if there is none." |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2018 |
|
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2019 |
|cls| |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2020 |
|
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2021 |
cls := self. |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2022 |
[cls notNil] whileTrue:[ |
16050 | 2023 |
(aBlock value: cls) ifTrue: [^ cls]. |
2024 |
cls := cls superclass. |
|
12862
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2025 |
]. |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2026 |
^ nil |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2027 |
|
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2028 |
" |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2029 |
SimpleView whichClassSatisfies:[:cls | cls instanceVariableNames includes:'gc'] |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
2030 |
" |
6727 | 2031 |
! |
2032 |
||
5638 | 2033 |
withAllSubclassesDo:aBlock |
2034 |
"evaluate aBlock for mySelf and all of my subclasses. |
|
2035 |
There is no specific order, in which the entries are enumerated. |
|
2036 |
Warning: |
|
16050 | 2037 |
This will only enumerate globally known classes - for anonymous |
2038 |
behaviors, you have to walk over all instances of Behavior." |
|
5638 | 2039 |
|
2040 |
aBlock value:self. |
|
2041 |
self allSubclassesDo:aBlock |
|
2042 |
||
2043 |
" |
|
2044 |
Collection withAllSubclassesDo:[:c | Transcript showCR:(c name)] |
|
2045 |
Collection class withAllSubclassesDo:[:c | Transcript showCR:(c name)] |
|
2046 |
" |
|
9194 | 2047 |
! |
2048 |
||
2049 |
withAllSuperclassesDo:aBlock |
|
2050 |
"evaluate aBlock for the class and all of its superclasses" |
|
2051 |
||
2052 |
aBlock value:self. |
|
16050 | 2053 |
self allSuperclassesDo:aBlock |
9194 | 2054 |
|
2055 |
" |
|
12094 | 2056 |
String withAllSuperclassesDo:[:each| Transcript showCR:each] |
9194 | 2057 |
" |
2058 |
! ! |
|
2059 |
||
14469
239e909bf765
added: #abstractClassInstantiationError
Claus Gittinger <cg@exept.de>
parents:
14414
diff
changeset
|
2060 |
!Behavior methodsFor:'error handling'! |
239e909bf765
added: #abstractClassInstantiationError
Claus Gittinger <cg@exept.de>
parents:
14414
diff
changeset
|
2061 |
|
239e909bf765
added: #abstractClassInstantiationError
Claus Gittinger <cg@exept.de>
parents:
14414
diff
changeset
|
2062 |
abstractClassInstantiationError |
239e909bf765
added: #abstractClassInstantiationError
Claus Gittinger <cg@exept.de>
parents:
14414
diff
changeset
|
2063 |
"sent by an abstract classes redefined new method" |
239e909bf765
added: #abstractClassInstantiationError
Claus Gittinger <cg@exept.de>
parents:
14414
diff
changeset
|
2064 |
|
239e909bf765
added: #abstractClassInstantiationError
Claus Gittinger <cg@exept.de>
parents:
14414
diff
changeset
|
2065 |
^ AbstractClassInstantiationError raiseRequest |
239e909bf765
added: #abstractClassInstantiationError
Claus Gittinger <cg@exept.de>
parents:
14414
diff
changeset
|
2066 |
|
239e909bf765
added: #abstractClassInstantiationError
Claus Gittinger <cg@exept.de>
parents:
14414
diff
changeset
|
2067 |
"Created: / 02-11-2012 / 10:07:01 / cg" |
239e909bf765
added: #abstractClassInstantiationError
Claus Gittinger <cg@exept.de>
parents:
14414
diff
changeset
|
2068 |
! ! |
239e909bf765
added: #abstractClassInstantiationError
Claus Gittinger <cg@exept.de>
parents:
14414
diff
changeset
|
2069 |
|
9194 | 2070 |
!Behavior methodsFor:'initialization'! |
1 | 2071 |
|
620 | 2072 |
deinitialize |
2073 |
"deinitialize is sent to a class before it is physically unloaded. |
|
2074 |
This is only done with classes which have been loaded in from a binary |
|
2075 |
file. Classes may release any primitive memory or other stuff which is |
|
2076 |
not visible to smalltalk (for example, release internal memory). |
|
2077 |
The default action here is to do nothing." |
|
2078 |
||
2079 |
^ self |
|
2080 |
! |
|
2081 |
||
1 | 2082 |
initialize |
442 | 2083 |
"initialize is sent to a class either during startup, |
2084 |
(for all statically compiled-in classes) or after a class |
|
2085 |
has been loaded into the system (either bytecodes or machinecode). |
|
2086 |
The default action here is to do nothing." |
|
1 | 2087 |
|
2088 |
^ self |
|
2089 |
! |
|
2090 |
||
3442
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2091 |
initializeWithAllPrivateClasses |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2092 |
"if implemented, send #initialize to myself and any private |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2093 |
class which does so. |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2094 |
This is sent to a class after it |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2095 |
has been loaded into the system. |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2096 |
Statically compiled classes are initialized by the VM" |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2097 |
|
6412
4d6aaac56707
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
6395
diff
changeset
|
2098 |
(self class includesSelector:#initialize) ifTrue:[ |
16050 | 2099 |
self initialize. |
3442
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2100 |
]. |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2101 |
self privateClassesSorted do:[:aPrivateClass | |
16050 | 2102 |
aPrivateClass initializeWithAllPrivateClasses. |
3442
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2103 |
]. |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2104 |
|
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2105 |
"Created: / 13.5.1998 / 23:33:16 / cg" |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
2106 |
"Modified: / 13.5.1998 / 23:34:06 / cg" |
9194 | 2107 |
! |
2108 |
||
2109 |
postAutoload |
|
2110 |
"postAutoload is sent to a class after it has been autoloaded. |
|
2111 |
This gives it a chance to arrange for automatic unloading to be done |
|
2112 |
after a while ... |
|
2113 |
This is NOT sent to statically compiled in or explicitely filedIn |
|
2114 |
classes. |
|
2115 |
The default action here is to do nothing." |
|
2116 |
||
2117 |
^ self |
|
2118 |
! |
|
328 | 2119 |
|
1 | 2120 |
reinitialize |
442 | 2121 |
"reinitialize is sent to a class when an image has been restarted. |
2122 |
I.e. when the system is restarted. |
|
2123 |
This gives classes a chance to flush any device dependent or otherwise |
|
2124 |
obsolete data which may be a leftover from the previous live. |
|
2125 |
The default action here is to do nothing." |
|
2126 |
||
9194 | 2127 |
^ self |
2128 |
! ! |
|
2129 |
||
15230 | 2130 |
|
9194 | 2131 |
!Behavior methodsFor:'instance creation'! |
2132 |
||
2133 |
basicNew |
|
54 | 2134 |
"return an instance of myself without indexed variables. |
1 | 2135 |
If the receiver-class has indexed instvars, the new object will have |
12094 | 2136 |
a basicSize of zero - |
91 | 2137 |
i.e. 'aClass basicNew' is equivalent to 'aClass basicNew:0'. |
54 | 2138 |
|
1 | 2139 |
** Do not redefine this method in any class **" |
2140 |
||
2141 |
%{ /* NOCONTEXT */ |
|
81 | 2142 |
REGISTER OBJ newobj; |
15231 | 2143 |
REGISTER char *nextPtr; |
14688 | 2144 |
unsigned INT instsize; |
2145 |
REGISTER unsigned INT nInstVars; |
|
1 | 2146 |
|
54 | 2147 |
/* |
369 | 2148 |
* the following ugly code is nothing more than a __new() followed |
54 | 2149 |
* by a nilling of the new instance. |
12094 | 2150 |
* Unrolled for a bit more speed since this is one of the central object |
91 | 2151 |
* allocation methods in the system |
54 | 2152 |
*/ |
1133 | 2153 |
nInstVars = __intVal(__INST(instSize)); |
92 | 2154 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
54 | 2155 |
|
983 | 2156 |
newobj = (OBJ) __newNextPtr; |
15231 | 2157 |
nextPtr = ((char *)newobj) + instsize; |
81 | 2158 |
|
2159 |
/* |
|
15230 | 2160 |
* don't argue about the goto and the arrangement below - it saves |
81 | 2161 |
* an extra nil-compare and branch in the common case ... |
91 | 2162 |
* (i.e. if no GC is needed, we fall through without a branch) |
81 | 2163 |
*/ |
15231 | 2164 |
if (nextPtr < (char *)__newEndPtr) { |
16050 | 2165 |
__objPtr(newobj)->o_size = instsize; |
2166 |
/* o_allFlags(newobj) = 0; */ |
|
2167 |
/* __objPtr(newobj)->o_space = __newSpace; */ |
|
2168 |
o_setAllFlags(newobj, __newSpace); |
|
2894 | 2169 |
#ifdef __HAS_ALIGN4__ |
16050 | 2170 |
/* |
2171 |
* if the alignment is 4, we are already sat, |
|
2172 |
* since a non-indexed object always has a word-aligned size. |
|
2173 |
*/ |
|
2174 |
__newNextPtr = nextPtr; |
|
91 | 2175 |
#else |
16050 | 2176 |
if (instsize & (__ALIGN__-1)) { |
2177 |
__newNextPtr = (char *)newobj + (instsize & ~(__ALIGN__-1)) + __ALIGN__; |
|
2178 |
} else { |
|
2179 |
__newNextPtr = nextPtr; |
|
2180 |
} |
|
91 | 2181 |
#endif |
82 | 2182 |
|
2183 |
ok: |
|
16050 | 2184 |
__InstPtr(newobj)->o_class = self; |
2185 |
__qSTORE(newobj, self); |
|
2186 |
||
2187 |
if (nInstVars) { |
|
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2188 |
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4) |
16050 | 2189 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
82 | 2190 |
#else |
16050 | 2191 |
REGISTER OBJ *op = __InstPtr(newobj)->i_instvars; |
2192 |
||
2193 |
/* |
|
2194 |
* knowing that nil is 0 |
|
2195 |
*/ |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2196 |
# if defined(FAST_OBJECT_MEMSET_DOUBLES_UNROLLED) |
16050 | 2197 |
if (nInstVars > 8) { |
2198 |
*op++ = nil; /* for alignment */ |
|
2199 |
nInstVars--; |
|
2200 |
while (nInstVars >= 8) { |
|
2201 |
*(double *)op = 0.0; |
|
2202 |
((double *)op)[1] = 0.0; |
|
2203 |
((double *)op)[2] = 0.0; |
|
2204 |
((double *)op)[3] = 0.0; |
|
2205 |
op += 8; |
|
2206 |
nInstVars -= 8; |
|
2207 |
} |
|
2208 |
} |
|
2209 |
while (nInstVars != 0) { |
|
2210 |
*op++ = 0; |
|
2211 |
nInstVars--; |
|
2212 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2213 |
# else |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2214 |
# if defined(FAST_OBJECT_MEMSET_LONGLONG_UNROLLED) |
16050 | 2215 |
if (nInstVars > 8) { |
2216 |
*op++ = nil; /* for alignment */ |
|
2217 |
nInstVars--; |
|
2218 |
while (nInstVars >= 8) { |
|
2219 |
*(long long *)op = 0; |
|
2220 |
((long long *)op)[1] = 0; |
|
2221 |
((long long *)op)[2] = 0; |
|
2222 |
((long long *)op)[3] = 0; |
|
2223 |
op += 8; |
|
2224 |
nInstVars -= 8; |
|
2225 |
} |
|
2226 |
} |
|
2227 |
while (nInstVars != 0) { |
|
2228 |
*op++ = 0; |
|
2229 |
nInstVars--; |
|
2230 |
} |
|
91 | 2231 |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2232 |
# else |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2233 |
# if defined(FAST_OBJECT_MEMSET_WORDS_UNROLLED) |
16050 | 2234 |
while (nInstVars >= 8) { |
2235 |
*op = nil; |
|
2236 |
*(op+1) = nil; |
|
2237 |
*(op+2) = nil; |
|
2238 |
*(op+3) = nil; |
|
2239 |
*(op+4) = nil; |
|
2240 |
*(op+5) = nil; |
|
2241 |
*(op+6) = nil; |
|
2242 |
*(op+7) = nil; |
|
2243 |
op += 8; |
|
2244 |
nInstVars -= 8; |
|
2245 |
} |
|
2246 |
while (nInstVars != 0) { |
|
2247 |
*op++ = nil; |
|
2248 |
nInstVars--; |
|
2249 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2250 |
# else |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2251 |
# if defined(FAST_MEMSET) |
16050 | 2252 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE); |
91 | 2253 |
# else |
16050 | 2254 |
while (nInstVars >= 8) { |
2255 |
nInstVars -= 8; |
|
2256 |
op[0] = nil; op[1] = nil; |
|
2257 |
op[2] = nil; op[3] = nil; |
|
2258 |
op[4] = nil; op[5] = nil; |
|
2259 |
op[6] = nil; op[7] = nil; |
|
2260 |
op += 8; |
|
2261 |
} |
|
2262 |
while (nInstVars != 0) { |
|
2263 |
*op++ = nil; |
|
2264 |
nInstVars--; |
|
2265 |
} |
|
82 | 2266 |
# endif |
2267 |
# endif |
|
2268 |
# endif |
|
2269 |
# endif |
|
2270 |
#endif |
|
16050 | 2271 |
} |
2272 |
RETURN ( newobj ); |
|
81 | 2273 |
} |
54 | 2274 |
|
92 | 2275 |
/* |
2276 |
* the slow case - a GC will occur |
|
2277 |
*/ |
|
834 | 2278 |
__PROTECT_CONTEXT__ |
14688 | 2279 |
newobj = __STX___new((INT)instsize); |
834 | 2280 |
__UNPROTECT_CONTEXT__ |
82 | 2281 |
if (newobj != nil) goto ok; |
9194 | 2282 |
%} |
2283 |
. |
|
2284 |
" |
|
2285 |
memory allocation failed. |
|
2286 |
When we arrive here, there was no memory, even after |
|
12094 | 2287 |
a garbage collect. |
2288 |
This means, that the VM wanted to get some more memory from the |
|
9194 | 2289 |
Operatingsystem, which was not kind enough to give it. |
2290 |
Bad luck - you should increase the swap space on your machine. |
|
68 | 2291 |
" |
127 | 2292 |
^ ObjectMemory allocationFailureSignal raise. |
1 | 2293 |
! |
2294 |
||
9194 | 2295 |
basicNew:anInteger |
1 | 2296 |
"return an instance of myself with anInteger indexed variables. |
2297 |
If the receiver-class has no indexed instvars, this is only allowed |
|
2298 |
if the argument, anInteger is zero. |
|
2299 |
** Do not redefine this method in any class **" |
|
2300 |
||
2301 |
%{ /* NOCONTEXT */ |
|
2302 |
||
2303 |
OBJ newobj; |
|
14688 | 2304 |
unsigned INT nInstVars; |
2305 |
unsigned INT instsize; |
|
154 | 2306 |
INT nindexedinstvars; |
92 | 2307 |
unsigned INT flags; |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2308 |
#if ! defined(FAST_ARRAY_MEMSET) |
1 | 2309 |
REGISTER char *cp; |
2310 |
short *sp; |
|
2311 |
long *lp; |
|
2312 |
#endif |
|
2313 |
REGISTER OBJ *op; |
|
2314 |
float *fp; |
|
2315 |
double *dp; |
|
2316 |
||
249 | 2317 |
if (__isSmallInteger(anInteger)) { |
16050 | 2318 |
nindexedinstvars = __intVal(anInteger); |
2319 |
if (nindexedinstvars >= 0) { |
|
2320 |
nInstVars = __intVal(__INST(instSize)); |
|
2321 |
flags = __intVal(__INST(flags)) & ARRAYMASK; |
|
2322 |
switch (flags) { |
|
2323 |
case BYTEARRAY: |
|
2324 |
instsize = OHDR_SIZE + nindexedinstvars; |
|
2325 |
if (nInstVars == 0) { |
|
2326 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
2327 |
/* |
|
2328 |
* the most common case |
|
2329 |
*/ |
|
2330 |
__qCheckedNew(newobj, instsize); |
|
2331 |
__InstPtr(newobj)->o_class = self; |
|
2332 |
__qSTORE(newobj, self); |
|
7858
65d77eb25fda
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7809
diff
changeset
|
2333 |
|
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2334 |
#if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
16050 | 2335 |
nInstVars = nindexedinstvars >> 2; |
2336 |
if (nindexedinstvars & 3) nInstVars++; |
|
2337 |
memset4(__InstPtr(newobj)->i_instvars, 0, nInstVars); |
|
357 | 2338 |
#else |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2339 |
# if defined(FAST_ARRAY_MEMSET) |
16050 | 2340 |
memset(__InstPtr(newobj)->i_instvars, 0, nindexedinstvars); |
357 | 2341 |
# else |
16050 | 2342 |
cp = (char *)__InstPtr(newobj)->i_instvars; |
2343 |
while (nindexedinstvars >= sizeof(INT)) { |
|
2344 |
*(INT *)cp = (INT)0; |
|
2345 |
cp += sizeof(INT); |
|
2346 |
nindexedinstvars -= sizeof(INT); |
|
2347 |
} |
|
2348 |
while (nindexedinstvars--) |
|
2349 |
*cp++ = '\0'; |
|
357 | 2350 |
# endif |
92 | 2351 |
#endif |
16050 | 2352 |
RETURN ( newobj ); |
2353 |
} |
|
2354 |
} else { |
|
2355 |
instsize += __OBJS2BYTES__(nInstVars); |
|
2356 |
} |
|
2357 |
__PROTECT_CONTEXT__ |
|
2358 |
__qNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2359 |
__UNPROTECT_CONTEXT__ |
|
2360 |
if (newobj == nil) { |
|
2361 |
break; |
|
2362 |
} |
|
2363 |
__InstPtr(newobj)->o_class = self; |
|
2364 |
__qSTORE(newobj, self); |
|
369 | 2365 |
|
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2366 |
#if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
16050 | 2367 |
nInstVars = (instsize-OHDR_SIZE) >> 2; |
2368 |
if (instsize & 3) nInstVars++; |
|
2369 |
memset4(__InstPtr(newobj)->i_instvars, 0, nInstVars); |
|
357 | 2370 |
#else |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2371 |
# if defined(FAST_ARRAY_MEMSET) |
16050 | 2372 |
/* |
2373 |
* knowing that nil is 0 |
|
2374 |
*/ |
|
2375 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE); |
|
357 | 2376 |
# else |
16050 | 2377 |
op = __InstPtr(newobj)->i_instvars; |
2378 |
while (nInstVars--) |
|
2379 |
*op++ = nil; |
|
2380 |
cp = (char *)op; |
|
2381 |
while (nindexedinstvars >= sizeof(INT)) { |
|
2382 |
*(INT *)cp = 0; |
|
2383 |
cp += sizeof(INT); |
|
2384 |
nindexedinstvars -= sizeof(INT); |
|
2385 |
} |
|
2386 |
while (nindexedinstvars--) |
|
2387 |
*cp++ = '\0'; |
|
357 | 2388 |
# endif |
1 | 2389 |
#endif |
16050 | 2390 |
RETURN ( newobj ); |
2391 |
break; |
|
2392 |
||
2393 |
case WORDARRAY: |
|
2394 |
case SWORDARRAY: |
|
2395 |
instsize = OHDR_SIZE + |
|
2396 |
__OBJS2BYTES__(nInstVars) + |
|
2397 |
nindexedinstvars * 2; |
|
2398 |
__PROTECT_CONTEXT__ |
|
2399 |
__qNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2400 |
__UNPROTECT_CONTEXT__ |
|
2401 |
if (newobj == nil) { |
|
2402 |
break; |
|
2403 |
} |
|
2404 |
__InstPtr(newobj)->o_class = self; |
|
2405 |
__qSTORE(newobj, self); |
|
369 | 2406 |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2407 |
#if defined(FAST_ARRAY_MEMSET) |
16050 | 2408 |
/* |
2409 |
* knowing that nil is 0 |
|
2410 |
*/ |
|
2411 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
1 | 2412 |
#else |
16050 | 2413 |
op = __InstPtr(newobj)->i_instvars; |
2414 |
while (nInstVars--) |
|
2415 |
*op++ = nil; |
|
2416 |
sp = (short *)op; |
|
2417 |
while (nindexedinstvars--) |
|
2418 |
*sp++ = 0; |
|
1 | 2419 |
#endif |
16050 | 2420 |
RETURN ( newobj ); |
2421 |
break; |
|
2422 |
||
2423 |
case LONGARRAY: |
|
2424 |
case SLONGARRAY: |
|
2425 |
instsize = OHDR_SIZE + |
|
2426 |
__OBJS2BYTES__(nInstVars) + |
|
2427 |
nindexedinstvars * 4; |
|
2428 |
__PROTECT_CONTEXT__ |
|
2429 |
__qAlignedNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2430 |
__UNPROTECT_CONTEXT__ |
|
2431 |
if (newobj == nil) { |
|
2432 |
break; |
|
2433 |
} |
|
2434 |
__InstPtr(newobj)->o_class = self; |
|
2435 |
__qSTORE(newobj, self); |
|
369 | 2436 |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2437 |
#if defined(memset4) |
16050 | 2438 |
/* |
2439 |
* knowing that nil is 0 |
|
2440 |
*/ |
|
2441 |
{ |
|
2442 |
int n4 = nInstVars + nindexedinstvars; |
|
2443 |
||
2444 |
memset4(__InstPtr(newobj)->i_instvars, 0, n4); |
|
2445 |
} |
|
1 | 2446 |
#else |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2447 |
# if defined(FAST_ARRAY_MEMSET) |
16050 | 2448 |
/* |
2449 |
* knowing that nil is 0 |
|
2450 |
*/ |
|
2451 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
1 | 2452 |
# else |
16050 | 2453 |
op = __InstPtr(newobj)->i_instvars; |
2454 |
while (nInstVars--) |
|
2455 |
*op++ = nil; |
|
2456 |
lp = (long *)op; |
|
2457 |
while (nindexedinstvars--) |
|
2458 |
*lp++ = 0; |
|
1 | 2459 |
# endif |
2460 |
#endif |
|
16050 | 2461 |
RETURN ( newobj ); |
2462 |
break; |
|
2463 |
||
2464 |
case LONGLONGARRAY: |
|
2465 |
case SLONGLONGARRAY: |
|
2466 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2467 |
|
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2468 |
#ifdef __NEED_LONGLONG_ALIGN |
16050 | 2469 |
instsize = ((instsize-1) + __LONGLONG_ALIGN) & ~(__LONGLONG_ALIGN-1); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2470 |
#endif |
16050 | 2471 |
instsize += nindexedinstvars * 8; |
2472 |
||
2473 |
__PROTECT_CONTEXT__ |
|
2474 |
__qAlignedNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2475 |
__UNPROTECT_CONTEXT__ |
|
2476 |
if (newobj == nil) { |
|
2477 |
break; |
|
2478 |
} |
|
2479 |
__InstPtr(newobj)->o_class = self; |
|
2480 |
__qSTORE(newobj, self); |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2481 |
|
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2482 |
#if defined(memset4) |
16050 | 2483 |
{ |
2484 |
int n4 = (instsize-OHDR_SIZE) / 4; |
|
2485 |
||
2486 |
memset4(__InstPtr(newobj)->i_instvars, 0, n4); |
|
2487 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2488 |
#else |
16050 | 2489 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2490 |
#endif |
16050 | 2491 |
RETURN ( newobj ); |
2492 |
break; |
|
2493 |
||
2494 |
case FLOATARRAY: |
|
2495 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
2496 |
instsize += nindexedinstvars * sizeof(float); |
|
2497 |
||
2498 |
__PROTECT_CONTEXT__ |
|
2499 |
__qNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2500 |
__UNPROTECT_CONTEXT__ |
|
2501 |
if (newobj == nil) { |
|
2502 |
break; |
|
2503 |
} |
|
2504 |
__InstPtr(newobj)->o_class = self; |
|
2505 |
__qSTORE(newobj, self); |
|
2506 |
||
2507 |
op = __InstPtr(newobj)->i_instvars; |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2508 |
#if defined(__FLOAT0_IS_INT0) /* knowin that float 0.0 is all-zeros */ |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2509 |
# if defined(memset4) |
16050 | 2510 |
{ |
2511 |
int n4 = (instsize-OHDR_SIZE) / 4; |
|
2512 |
||
2513 |
memset4(__InstPtr(newobj)->i_instvars, 0, n4); |
|
2514 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2515 |
# else |
16050 | 2516 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2517 |
# endif |
3870
ea7a0f0db4be
use memset to initialize float- and doubleArrays, if float0/double0 is int0
Claus Gittinger <cg@exept.de>
parents:
3805
diff
changeset
|
2518 |
#else |
16050 | 2519 |
while (nInstVars--) |
2520 |
*op++ = nil; |
|
2521 |
fp = (float *)op; |
|
2522 |
while (nindexedinstvars--) |
|
2523 |
*fp++ = 0.0; |
|
3870
ea7a0f0db4be
use memset to initialize float- and doubleArrays, if float0/double0 is int0
Claus Gittinger <cg@exept.de>
parents:
3805
diff
changeset
|
2524 |
#endif |
16050 | 2525 |
RETURN ( newobj ); |
2526 |
break; |
|
2527 |
||
2528 |
case DOUBLEARRAY: |
|
2529 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2530 |
#ifdef __NEED_DOUBLE_ALIGN |
16050 | 2531 |
instsize = ((instsize-1) + __DOUBLE_ALIGN) & ~(__DOUBLE_ALIGN-1); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2532 |
#endif |
16050 | 2533 |
instsize += nindexedinstvars * sizeof(double); |
2534 |
||
2535 |
__PROTECT_CONTEXT__ |
|
2536 |
__qAlignedNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2537 |
__UNPROTECT_CONTEXT__ |
|
2538 |
if (newobj == nil) { |
|
2539 |
break; |
|
2540 |
} |
|
2541 |
__InstPtr(newobj)->o_class = self; |
|
2542 |
__qSTORE(newobj, self); |
|
369 | 2543 |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2544 |
#if defined(__DOUBLE0_IS_INT0) /* knowin that double 0.0 is all-zeros */ |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2545 |
# ifdef memset4 |
16050 | 2546 |
{ |
2547 |
int n4 = (instsize-OHDR_SIZE) / 4; |
|
2548 |
||
2549 |
memset4(__InstPtr(newobj)->i_instvars, 0, n4); |
|
2550 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2551 |
# else |
16050 | 2552 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2553 |
# endif |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2554 |
#else |
16050 | 2555 |
op = __InstPtr(newobj)->i_instvars; |
2556 |
while (nInstVars--) |
|
2557 |
*op++ = nil; |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2558 |
|
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2559 |
# ifdef __NEED_DOUBLE_ALIGN |
16050 | 2560 |
/* |
2561 |
* care for double alignment |
|
2562 |
* add filler. |
|
2563 |
*/ |
|
2564 |
if ((INT)op & (__DOUBLE_ALIGN-1)) { |
|
2565 |
*op++ = nil; |
|
2566 |
} |
|
3870
ea7a0f0db4be
use memset to initialize float- and doubleArrays, if float0/double0 is int0
Claus Gittinger <cg@exept.de>
parents:
3805
diff
changeset
|
2567 |
# endif |
16050 | 2568 |
dp = (double *)op; |
2569 |
while (nindexedinstvars--) |
|
2570 |
*dp++ = 0.0; |
|
3870
ea7a0f0db4be
use memset to initialize float- and doubleArrays, if float0/double0 is int0
Claus Gittinger <cg@exept.de>
parents:
3805
diff
changeset
|
2571 |
#endif |
16050 | 2572 |
RETURN ( newobj ); |
2573 |
break; |
|
2574 |
||
2575 |
case WKPOINTERARRAY: |
|
2576 |
case POINTERARRAY: |
|
2577 |
nInstVars += nindexedinstvars; |
|
2578 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
2579 |
__PROTECT_CONTEXT__ |
|
2580 |
__qAlignedNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2581 |
__UNPROTECT_CONTEXT__ |
|
2582 |
if (newobj == nil) { |
|
2583 |
break; |
|
2584 |
} |
|
2585 |
__InstPtr(newobj)->o_class = self; |
|
2586 |
__qSTORE(newobj, self); |
|
369 | 2587 |
|
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2588 |
#if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
16050 | 2589 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
1 | 2590 |
#else |
16050 | 2591 |
/* |
2592 |
* knowing that nil is 0 |
|
2593 |
*/ |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2594 |
# ifdef sparc |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2595 |
# define FAST_ARRAY_MEMSET_DOUBLES_UNROLLED |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2596 |
# endif |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2597 |
|
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2598 |
# if defined(FAST_ARRAY_MEMSET_DOUBLES_UNROLLED) |
16050 | 2599 |
op = __InstPtr(newobj)->i_instvars; |
2600 |
if (nInstVars > 8) { |
|
2601 |
*op++ = nil; /* for alignment */ |
|
2602 |
nInstVars--; |
|
2603 |
while (nInstVars >= 8) { |
|
2604 |
*(double *)op = 0.0; |
|
2605 |
((double *)op)[1] = 0.0; |
|
2606 |
((double *)op)[2] = 0.0; |
|
2607 |
((double *)op)[3] = 0.0; |
|
2608 |
op += 8; |
|
2609 |
nInstVars -= 8; |
|
2610 |
} |
|
2611 |
} |
|
2612 |
while (nInstVars) { |
|
2613 |
*op++ = 0; |
|
2614 |
nInstVars--; |
|
2615 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2616 |
# else |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2617 |
# if defined(FAST_ARRAY_MEMSET_LONGLONG_UNROLLED) |
16050 | 2618 |
op = __InstPtr(newobj)->i_instvars; |
2619 |
if (nInstVars > 8) { |
|
2620 |
*op++ = nil; /* for alignment */ |
|
2621 |
nInstVars--; |
|
2622 |
while (nInstVars >= 8) { |
|
2623 |
*(long long *)op = 0; |
|
2624 |
((long long *)op)[1] = 0; |
|
2625 |
((long long *)op)[2] = 0; |
|
2626 |
((long long *)op)[3] = 0; |
|
2627 |
op += 8; |
|
2628 |
nInstVars -= 8; |
|
2629 |
} |
|
2630 |
} |
|
2631 |
while (nInstVars) { |
|
2632 |
*op++ = 0; |
|
2633 |
nInstVars--; |
|
2634 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2635 |
# else |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2636 |
# if defined(FAST_ARRAY_MEMSET) |
16050 | 2637 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
91 | 2638 |
# else |
16050 | 2639 |
op = __InstPtr(newobj)->i_instvars; |
2640 |
while (nInstVars >= 8) { |
|
2641 |
nInstVars -= 8; |
|
2642 |
op[0] = nil; op[1] = nil; |
|
2643 |
op[2] = nil; op[3] = nil; |
|
2644 |
op[4] = nil; op[5] = nil; |
|
2645 |
op[6] = nil; op[7] = nil; |
|
2646 |
op += 8; |
|
2647 |
} |
|
2648 |
while (nInstVars--) |
|
2649 |
*op++ = nil; |
|
82 | 2650 |
# endif |
2651 |
# endif |
|
1 | 2652 |
# endif |
2653 |
#endif |
|
16050 | 2654 |
RETURN ( newobj ); |
2655 |
break; |
|
2656 |
||
2657 |
default: |
|
2658 |
/* |
|
2659 |
* new:n for non-variable classes only allowed if |
|
2660 |
* n == 0 |
|
2661 |
*/ |
|
2662 |
if (nindexedinstvars == 0) { |
|
2663 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
2664 |
__PROTECT_CONTEXT__ |
|
2665 |
__qAlignedNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2666 |
__UNPROTECT_CONTEXT__ |
|
2667 |
if (newobj == nil) { |
|
2668 |
break; |
|
2669 |
} |
|
2670 |
__InstPtr(newobj)->o_class = self; |
|
2671 |
__qSTORE(newobj, self); |
|
2672 |
||
2673 |
if (nInstVars) { |
|
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2674 |
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4) |
16050 | 2675 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
1 | 2676 |
#else |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2677 |
# if defined(FAST_MEMSET) |
16050 | 2678 |
/* |
2679 |
* knowing that nil is 0 |
|
2680 |
*/ |
|
2681 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
1 | 2682 |
# else |
16050 | 2683 |
op = __InstPtr(newobj)->i_instvars; |
2684 |
do { |
|
2685 |
*op++ = nil; |
|
2686 |
} while (--nInstVars); |
|
1 | 2687 |
# endif |
2688 |
#endif |
|
16050 | 2689 |
} |
2690 |
RETURN ( newobj ); |
|
2691 |
} |
|
2692 |
break; |
|
2693 |
} |
|
2694 |
} |
|
1 | 2695 |
} |
68 | 2696 |
%}. |
2697 |
" |
|
2698 |
arrive here if something went wrong ... |
|
2699 |
figure out what it was |
|
2700 |
" |
|
11 | 2701 |
|
1 | 2702 |
(anInteger isMemberOf:SmallInteger) ifFalse:[ |
16050 | 2703 |
" |
2704 |
the argument is either not an integer, |
|
2705 |
or a LargeInteger (which means that its definitely too big) |
|
2706 |
" |
|
2707 |
self error:'argument to new: must be Integer' mayProceed:true. |
|
2708 |
^ nil |
|
68 | 2709 |
]. |
2710 |
(anInteger < 0) ifTrue:[ |
|
16050 | 2711 |
" |
2712 |
the argument is negative, |
|
2713 |
" |
|
2714 |
self error:'bad (negative) argument to new:'. |
|
2715 |
^ nil |
|
68 | 2716 |
]. |
2717 |
self isVariable ifFalse:[ |
|
16050 | 2718 |
" |
2719 |
this class does not have any indexed instance variables |
|
2720 |
" |
|
2721 |
self error:'class has no indexed instvars - cannot create with new:'. |
|
2722 |
^ nil |
|
68 | 2723 |
]. |
2724 |
" |
|
2725 |
memory allocation failed. |
|
2726 |
When we arrive here, there was no memory, even after |
|
12094 | 2727 |
a garbage collect. |
2728 |
This means, that the VM wanted to get some more memory from the |
|
165 | 2729 |
Operatingsystem, which was not kind enough to give it. |
2730 |
Bad luck - you should increase the swap space on your machine. |
|
68 | 2731 |
" |
127 | 2732 |
^ ObjectMemory allocationFailureSignal raise. |
9194 | 2733 |
! |
2734 |
||
2735 |
decodeFromLiteralArray:anArray |
|
2736 |
"create & return a new instance from information encoded in anArray." |
|
2737 |
||
2738 |
^ self new fromLiteralArrayEncoding:anArray. |
|
2739 |
||
2740 |
" |
|
2741 |
Rectangle |
|
16050 | 2742 |
decodeFromLiteralArray:#(Rectangle 10 10 100 100) |
9194 | 2743 |
" |
2744 |
||
2745 |
"Modified: / 28.1.1998 / 17:40:30 / cg" |
|
2370
694ebbc71f04
added #decodeFromLiteralArray: - ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2236
diff
changeset
|
2746 |
! |
694ebbc71f04
added #decodeFromLiteralArray: - ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2236
diff
changeset
|
2747 |
|
9194 | 2748 |
new |
2749 |
"return an instance of myself without indexed variables" |
|
2750 |
||
2751 |
^ self basicNew |
|
2752 |
! |
|
2753 |
||
2754 |
new:anInteger |
|
2755 |
"return an instance of myself with anInteger indexed variables" |
|
2756 |
||
2757 |
^ self basicNew:anInteger |
|
2758 |
! |
|
2759 |
||
2760 |
niceBasicNew:anInteger |
|
620 | 2761 |
"same as basicNew:anInteger, but tries to avoid long pauses |
2762 |
due to garbage collection. This method checks to see if |
|
2763 |
allocation is possible without a pause, and does a background |
|
2764 |
incremental garbage collect first if there is not enough memory |
|
12094 | 2765 |
available at the moment for fast allocation. |
2766 |
This is useful in low-priority background processes which like to |
|
620 | 2767 |
avoid disturbing any higher priority foreground process while allocating |
2768 |
big amounts of memory. Of course, using this method only makes |
|
2769 |
sense for big or huge objects (say > 200k). |
|
2770 |
||
12094 | 2771 |
EXPERIMENTAL: this is a non-standard interface and should only |
620 | 2772 |
be used for special applications. There is no guarantee, that this |
2773 |
method will be available in future ST/X releases." |
|
2774 |
||
2775 |
|size| |
|
2776 |
||
2777 |
size := self sizeOfInst:anInteger. |
|
2778 |
(ObjectMemory checkForFastNew:size) ifFalse:[ |
|
16050 | 2779 |
" |
2780 |
incrementally collect garbage |
|
2781 |
" |
|
2782 |
ObjectMemory incrementalGC. |
|
620 | 2783 |
]. |
2784 |
^ self basicNew:anInteger |
|
9194 | 2785 |
! |
2786 |
||
2787 |
readFrom:aStream |
|
12094 | 2788 |
"read an objects printed representation from the argument, aStream |
2789 |
and return it. |
|
154 | 2790 |
The read object must be a kind of myself if its not, an error is raised. |
11 | 2791 |
This is the reverse operation to 'storeOn:'. |
43 | 2792 |
|
12094 | 2793 |
WARNING: storeOn: does not handle circular references and multiple |
16050 | 2794 |
references to the same object. |
2795 |
Use #storeBinary:/readBinaryFrom: for this." |
|
12094 | 2796 |
|
2797 |
^ self |
|
16050 | 2798 |
readFrom:aStream |
2799 |
onError:[ self conversionErrorSignal |
|
2800 |
raiseWith:aStream errorString:'conversion error for: ' , self name ] |
|
11 | 2801 |
|
91 | 2802 |
" |
2803 |
|s| |
|
11 | 2804 |
s := WriteStream on:String new. |
2805 |
#(1 2 3 4) storeOn:s. |
|
12094 | 2806 |
Object readFrom:(ReadStream on:s contents) |
11 | 2807 |
" |
9194 | 2808 |
! |
2809 |
||
2810 |
readFrom:aStream onError:exceptionBlock |
|
15862 | 2811 |
"read an object's printed representation from the argument, aStream |
198 | 2812 |
and return it (i.e. the stream should contain some representation of |
12094 | 2813 |
the object which was created using #storeOn:). |
15862 | 2814 |
The read object must be a kind of myself. |
2815 |
If its not, the value of exceptionBlock is returned. |
|
198 | 2816 |
To get any object, use 'Object readFrom:...', |
2817 |
To get any number, use 'Number readFrom:...' and so on. |
|
2818 |
This is the reverse operation to 'storeOn:'. |
|
2819 |
||
12094 | 2820 |
WARNING: storeOn: does not handle circular references and multiple |
15862 | 2821 |
references to the same object. |
2822 |
Use #storeBinary:/readBinaryFrom: for this." |
|
198 | 2823 |
|
6627
685ab6f994f0
Avoid block creation in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6596
diff
changeset
|
2824 |
^ [ |
15862 | 2825 |
|newObject| |
2826 |
newObject := self evaluatorClass evaluateFrom:aStream ifFail:exceptionBlock. |
|
2827 |
(newObject isKindOf:self) ifTrue:[newObject] ifFalse:[exceptionBlock value]. |
|
6627
685ab6f994f0
Avoid block creation in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6596
diff
changeset
|
2828 |
] on:Error do:exceptionBlock. |
198 | 2829 |
|
2830 |
" |
|
2831 |
|s| |
|
2832 |
s := WriteStream on:String new. |
|
2833 |
#(1 2 3 4) storeOn:s. |
|
1422 | 2834 |
Transcript showCR:( |
15862 | 2835 |
Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
293 | 2836 |
) |
198 | 2837 |
" |
2838 |
" |
|
2839 |
|s| |
|
2840 |
s := WriteStream on:String new. |
|
2841 |
#[1 2 3 4] storeOn:s. |
|
1422 | 2842 |
Transcript showCR:( |
15862 | 2843 |
Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
345 | 2844 |
) |
198 | 2845 |
" |
5842
720736f72cb4
exceptionBlock handling in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5753
diff
changeset
|
2846 |
" |
6627
685ab6f994f0
Avoid block creation in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6596
diff
changeset
|
2847 |
Object readFrom:'illegal' onError:['bla'] |
685ab6f994f0
Avoid block creation in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6596
diff
changeset
|
2848 |
String readFrom:'illegal' onError:'bla' |
5842
720736f72cb4
exceptionBlock handling in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5753
diff
changeset
|
2849 |
" |
9194 | 2850 |
! |
2851 |
||
2852 |
readFromString:aString |
|
275 | 2853 |
"create an object from its printed representation. |
2854 |
For most classes, the string is expected to be in a format created by |
|
2855 |
storeOn: or storeString; however, some (Time, Date) expect a user |
|
2856 |
readable string here. |
|
2857 |
See comments in Behavior>>readFromString:onError:, |
|
2858 |
Behavior>>readFrom: and Behavior>>readFrom:onError:" |
|
11 | 2859 |
|
12094 | 2860 |
^ self |
16050 | 2861 |
readFromString:aString |
2862 |
onError:[ self conversionErrorSignal |
|
2863 |
raiseErrorString:'expected: ' , self name ] |
|
91 | 2864 |
|
2865 |
" |
|
12094 | 2866 |
Integer readFromString:'12345678901234567890' |
2867 |
Point readFromString:'1@2' |
|
2868 |
Point readFromString:'1' |
|
91 | 2869 |
" |
198 | 2870 |
! |
2871 |
||
2872 |
readFromString:aString onError:exceptionBlock |
|
275 | 2873 |
"create an object from its printed representation. |
2874 |
Here, the string is expected to be in a format created by |
|
12094 | 2875 |
storeOn: or storeString; |
9196
a6d45629bb3b
readFromString allows for whiteSpace after reading
Claus Gittinger <cg@exept.de>
parents:
9194
diff
changeset
|
2876 |
However, some classes (Time, Date) may redefine it to expect a user readable string here. |
198 | 2877 |
See comments in Behavior>>readFrom: and Behavior>>readFrom:onError:" |
2878 |
||
8531
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
2879 |
|str val| |
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
2880 |
|
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
2881 |
str := ReadStream on:aString. |
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
2882 |
val := self readFrom:str onError:[^ exceptionBlock value]. |
12094 | 2883 |
str atEnd ifFalse:[ |
16050 | 2884 |
str skipSeparators. |
2885 |
str atEnd ifFalse:[ |
|
2886 |
^ exceptionBlock value |
|
2887 |
] |
|
9196
a6d45629bb3b
readFromString allows for whiteSpace after reading
Claus Gittinger <cg@exept.de>
parents:
9194
diff
changeset
|
2888 |
]. |
8531
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
2889 |
^ val |
198 | 2890 |
|
2891 |
" |
|
12094 | 2892 |
Integer readFromString:'12345678901234567890' |
2893 |
Integer readFromString:'abc' |
|
275 | 2894 |
Integer readFromString:'abc' onError:0 |
12094 | 2895 |
Point readFromString:'1@2' |
2896 |
Point readFromString:'0' |
|
2897 |
Point readFromString:'0' onError:[0@0] |
|
198 | 2898 |
" |
9194 | 2899 |
! |
2900 |
||
2901 |
uninitializedNew |
|
2902 |
"create an instance of myself with uninitialized contents. |
|
2903 |
For all classes except ByteArray, this is the same as #basicNew." |
|
2904 |
||
2905 |
^ self basicNew |
|
2906 |
! |
|
2907 |
||
2908 |
uninitializedNew:anInteger |
|
2909 |
"create an instance of myself with uninitialized contents. |
|
2910 |
For all classes except ByteArray, this is the same as #basicNew:." |
|
2911 |
||
2912 |
^ self basicNew:anInteger |
|
2913 |
! ! |
|
2914 |
||
2915 |
!Behavior methodsFor:'misc'! |
|
3619 | 2916 |
|
4928 | 2917 |
browse |
5727 | 2918 |
"open a browser showing the receiver" |
2919 |
||
12094 | 2920 |
self browserClass openInClass:self |
4928 | 2921 |
|
2922 |
" |
|
5546 | 2923 |
Array browserClass |
4928 | 2924 |
Array browse |
2925 |
" |
|
2926 |
! |
|
2927 |
||
8725 | 2928 |
classOperationsMenu |
13260 | 2929 |
"a chance to return additional menu items for the browser's class-menu" |
8725 | 2930 |
|
2931 |
^ nil |
|
13260 | 2932 |
|
2933 |
"Modified: / 31-01-2011 / 11:05:49 / cg" |
|
8725 | 2934 |
! |
2935 |
||
12869 | 2936 |
flushSubclasses |
2937 |
"I dont keep my subclasses - but if anyone inherits from me, |
|
2938 |
it better knows how to ignore this" |
|
2939 |
! |
|
2940 |
||
10667
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2941 |
iconInBrowserSymbol |
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2942 |
"can be redefined for a private icon in the browser (for me and my subclasses). |
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2943 |
The returned symbol must be a selector of the ToolbarIconLibrary." |
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2944 |
|
14504 | 2945 |
<resource: #programImage> |
2946 |
||
2947 |
self isLoaded ifFalse:[ |
|
16050 | 2948 |
^ #autoloadedClassBrowserIcon |
12094 | 2949 |
]. |
14504 | 2950 |
(self isBrowserStartable) ifTrue:[ |
16050 | 2951 |
self isVisualStartable ifTrue:[ |
2952 |
^ #visualStartableClassBrowserIcon |
|
2953 |
]. |
|
2954 |
^ #startableClassBrowserIcon |
|
12094 | 2955 |
]. |
2956 |
||
14504 | 2957 |
"/ give ruby and other special metaclasses a chance to provide their own icon... |
12094 | 2958 |
^ self class iconInBrowserSymbol |
10667
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2959 |
|
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2960 |
"Created: / 20-07-2007 / 08:52:17 / cg" |
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2961 |
! |
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2962 |
|
3619 | 2963 |
sourceCodeTemplate |
2964 |
^ 'messageSelector and arguments |
|
2965 |
"method comment - purpose of message" |
|
2966 |
||
2967 |
|temporaries| |
|
2968 |
||
2969 |
statements |
|
2970 |
||
2971 |
" |
|
2972 |
example uses |
|
2973 |
" |
|
2974 |
' |
|
2975 |
||
2976 |
"Created: / 19.6.1998 / 02:14:02 / cg" |
|
2977 |
! ! |
|
2978 |
||
9194 | 2979 |
!Behavior methodsFor:'printing & storing'! |
2980 |
||
14288
d30ff513d793
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14259
diff
changeset
|
2981 |
displayOn:aGCOrStream |
d30ff513d793
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14259
diff
changeset
|
2982 |
"return a string to display the receiver - include the |
d30ff513d793
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14259
diff
changeset
|
2983 |
count for your convenience. |
d30ff513d793
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14259
diff
changeset
|
2984 |
|
d30ff513d793
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14259
diff
changeset
|
2985 |
although behaviors have no name, we return something |
10085 | 2986 |
useful here - there are many places (inspectors) where |
2987 |
a classes name is asked for. |
|
2988 |
Implementing this message here allows instances of anonymous classes |
|
2989 |
to show a reasonable name." |
|
2990 |
||
14288
d30ff513d793
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14259
diff
changeset
|
2991 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
d30ff513d793
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14259
diff
changeset
|
2992 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
d30ff513d793
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14259
diff
changeset
|
2993 |
(aGCOrStream isStream) ifFalse:[ |
16050 | 2994 |
^ super displayOn:aGCOrStream |
14288
d30ff513d793
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14259
diff
changeset
|
2995 |
]. |
d30ff513d793
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14259
diff
changeset
|
2996 |
|
d30ff513d793
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14259
diff
changeset
|
2997 |
aGCOrStream nextPutAll:self name |
10085 | 2998 |
! |
2999 |
||
9194 | 3000 |
printOn:aStream |
3001 |
aStream nextPutAll:(self name). |
|
6590 | 3002 |
! ! |
6589 | 3003 |
|
9194 | 3004 |
!Behavior methodsFor:'private-accessing'! |
3005 |
||
3006 |
flags:aNumber |
|
3007 |
"set the flags. |
|
16016 | 3008 |
see flagXXX methods on my class side for details. |
15102 | 3009 |
This method is for special uses only - there will be no recompilation |
12094 | 3010 |
and no change record written here; |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15231
diff
changeset
|
3011 |
Warning: |
16016 | 3012 |
the flags slot specifies the layout and behavior of my instances slots |
3013 |
and affects both the VM's and the class library's behavior. |
|
3014 |
It is required to be consistent and correct. |
|
3015 |
Setting it to a wrong value may severely affect the system's operation, |
|
3016 |
and even crash the system (in the garbage collector). |
|
3017 |
Do NOT use it, unless you really know what you are doing." |
|
9194 | 3018 |
|
3019 |
flags := aNumber |
|
3020 |
! |
|
620 | 3021 |
|
3022 |
instSize:aNumber |
|
3023 |
"set the instance size. |
|
15102 | 3024 |
This method is for special uses only - there will be no recompilation |
12094 | 3025 |
and no change record written here; |
15262
5047292c9107
all stx macros begin with double underline (eg. __qClass instead of _qClass)
Claus Gittinger <cg@exept.de>
parents:
15231
diff
changeset
|
3026 |
Warning: |
16050 | 3027 |
the instSize slot specifies the size of my instances and affects |
3028 |
both the VM's and the class library's behavior. |
|
3029 |
It is required to be consistent and correct. |
|
3030 |
Setting it to a wrong value may severely affect the system's operation, |
|
3031 |
and even crash the system (in the garbage collector). |
|
3032 |
Do NOT use it, unless you really know what you are doing." |
|
620 | 3033 |
|
3034 |
instSize := aNumber |
|
3035 |
! |
|
3036 |
||
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3037 |
primAddSelector:aSelector withMethod:newMethod |
620 | 3038 |
"add the method given by 2nd argument under the selector given by |
12094 | 3039 |
the 1st argument to the methodDictionary. |
620 | 3040 |
Does NOT flush any caches, does NOT write a change record. |
3041 |
||
3042 |
Do not use this in normal situations, strange behavior will be |
|
3043 |
the consequence. |
|
12094 | 3044 |
I.e. executing obsolete methods, since the old method will still |
620 | 3045 |
be executed out of the caches." |
3046 |
||
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3047 |
|dict oldMethod| |
620 | 3048 |
|
3049 |
newMethod isNil ifTrue:[ |
|
16050 | 3050 |
self error:'invalid method'. |
620 | 3051 |
]. |
3052 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
3053 |
dict := self methodDictionary. |
15230 | 3054 |
oldMethod := dict at:aSelector ifAbsent:nil. |
3055 |
||
3056 |
(Smalltalk |
|
16050 | 3057 |
changeRequest:#methodInClass |
3058 |
with:(Array with:self with:aSelector with:oldMethod)) ifFalse:[ |
|
3059 |
^ false |
|
15230 | 3060 |
]. |
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3061 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3062 |
self setMethodDictionary:(dict at:aSelector putOrAppend:newMethod). |
7123
2af84f5b1447
pre-set the methods mclass cache when adding a method
Claus Gittinger <cg@exept.de>
parents:
6968
diff
changeset
|
3063 |
newMethod mclass:self. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
3064 |
|
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3065 |
ObjectMemory flushCachesForSelector:aSelector. |
11578 | 3066 |
^ true |
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3067 |
|
9445 | 3068 |
"Modified: / 07-06-1996 / 14:48:45 / stefan" |
10693
d397d49e1134
changed #primAddSelector:withMethod:
Claus Gittinger <cg@exept.de>
parents:
10669
diff
changeset
|
3069 |
"Modified: / 31-08-2007 / 16:53:20 / cg" |
9194 | 3070 |
! |
3071 |
||
3072 |
setMethodDictionary:dict |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
3073 |
"set the receivers method dictionary. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
3074 |
Convert dict to a MethodDictionary if necessary. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
3075 |
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
|
3076 |
after this call" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
3077 |
|
2228 | 3078 |
"/ since the only thing the VM is prepared to deal with are |
3079 |
"/ proper methodDictionaries (it cannot do another message send, to |
|
3080 |
"/ find any methods ...), we convert it here if required. |
|
3081 |
"/ No other classes instances are allowed. |
|
3082 |
||
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
3083 |
dict class ~~ MethodDictionary ifTrue:[ |
16050 | 3084 |
methodDictionary := MethodDictionary withAll:dict. |
3085 |
methodDictionary isNil ifTrue:[ |
|
3086 |
||
3087 |
"/ refuse to do this |
|
3088 |
"/ (can only happen in case of memory allocation trouble, |
|
3089 |
"/ where the allocation failed and some exception handler returned |
|
3090 |
"/ nil ...) |
|
3091 |
||
3092 |
self error:'cannot set methodDictionary to nil' mayProceed:true. |
|
3093 |
^ self. |
|
3094 |
] |
|
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
3095 |
] ifFalse:[ |
16050 | 3096 |
methodDictionary := dict. |
620 | 3097 |
]. |
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
3098 |
^ self. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
3099 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
3100 |
"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
|
3101 |
"Modified: 12.6.1996 / 13:58:55 / stefan" |
2228 | 3102 |
"Modified: 22.1.1997 / 21:10:48 / cg" |
9194 | 3103 |
! |
3104 |
||
3105 |
setSuperclass:aClass |
|
3106 |
"set the superclass of the receiver. |
|
3107 |
this method is for special uses only - there will be no recompilation |
|
3108 |
and no change record written here. Also, if the receiver class has |
|
3109 |
already been in use, future operation of the system is not guaranteed to |
|
3110 |
be correct, since no caches are flushed. |
|
3111 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)" |
|
3112 |
||
3113 |
superclass := aClass |
|
3114 |
||
3115 |
"Modified: 3.3.1997 / 13:27:00 / cg" |
|
3116 |
! |
|
620 | 3117 |
|
12094 | 3118 |
setSuperclass:aClass instSize:i |
3119 |
"set some inst vars. |
|
5906 | 3120 |
this method is for special uses only - there will be no recompilation |
12094 | 3121 |
and no change record is written here. Also, if the receiver class has |
5906 | 3122 |
already been in use, future operation of the system is not guaranteed to |
3123 |
be correct, since no caches are flushed. |
|
3124 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)" |
|
3125 |
||
3126 |
self setSuperclass:aClass. |
|
3127 |
instSize := i. |
|
3128 |
! |
|
3129 |
||
9194 | 3130 |
setSuperclass:aClass methodDictionary:d instSize:i flags:f |
12094 | 3131 |
"set some inst vars. |
9194 | 3132 |
this method is for special uses only - there will be no recompilation |
12094 | 3133 |
and no change record is written here. Also, if the receiver class has |
9194 | 3134 |
already been in use, future operation of the system is not guaranteed to |
3135 |
be correct, since no caches are flushed. |
|
3136 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)" |
|
3137 |
||
3138 |
self setSuperclass:aClass. |
|
3139 |
self setMethodDictionary:d. |
|
620 | 3140 |
instSize := i. |
3141 |
flags := f |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
3142 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
3143 |
"Created: 7.6.1996 / 08:41:20 / stefan" |
2224 | 3144 |
"Modified: 22.1.1997 / 18:42:12 / cg" |
620 | 3145 |
! ! |
3146 |
||
7260 | 3147 |
!Behavior methodsFor:'private-helpers'! |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3148 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3149 |
addAllClassVarNamesTo:aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3150 |
"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
|
3151 |
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
|
3152 |
|
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
3153 |
|classvars superclass| |
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
3154 |
|
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
3155 |
superclass := self superclass. |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3156 |
(superclass notNil) ifTrue:[ |
16050 | 3157 |
superclass addAllClassVarNamesTo:aCollection |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3158 |
]. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3159 |
(classvars := self classVariableString) notNil ifTrue:[ |
16050 | 3160 |
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
|
3161 |
]. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3162 |
^ aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3163 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3164 |
"Created: 16.4.1996 / 18:00:38 / cg" |
9194 | 3165 |
! |
3166 |
||
3167 |
addAllInstVarNamesTo:aCollection |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3168 |
"helper for allInstVarNames - add the name-strings of the instance variables |
12094 | 3169 |
and of the inst-vars of all superclasses to the argument, aCollection. |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3170 |
Return aCollection." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3171 |
|
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
3172 |
|superclass| |
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
3173 |
|
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
3174 |
superclass := self superclass. |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3175 |
(superclass notNil) ifTrue:[ |
16050 | 3176 |
superclass addAllInstVarNamesTo:aCollection |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3177 |
]. |
5512 | 3178 |
aCollection addAll:self instVarNames. |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3179 |
^ aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3180 |
|
5512 | 3181 |
" |
3182 |
SortedCollection allInstVarNames |
|
3183 |
SortedCollection instVarNames |
|
3184 |
" |
|
4371
dc83645cc903
support to recursively enumerate all private classes
Claus Gittinger <cg@exept.de>
parents:
4366
diff
changeset
|
3185 |
! |
dc83645cc903
support to recursively enumerate all private classes
Claus Gittinger <cg@exept.de>
parents:
4366
diff
changeset
|
3186 |
|
9194 | 3187 |
addAllPrivateClassesTo:aCollection |
3188 |
"add all of my private classes to aCollection" |
|
3189 |
||
3190 |
self privateClassesDo:[:aPrivateClass | |
|
16050 | 3191 |
aCollection add:aPrivateClass. |
3192 |
aPrivateClass addAllPrivateClassesTo:aCollection |
|
9194 | 3193 |
]. |
13414 | 3194 |
! |
3195 |
||
3196 |
getLookupObject |
|
3197 |
"return the lookupObject (Jan's MetaObjectProtocol support) or nil. |
|
3198 |
If non-nil, no lookup is performed by the VM, instead the lookupObject |
|
3199 |
has to provide a method object for message sends." |
|
3200 |
||
13419 | 3201 |
^ lookupObject |
13414 | 3202 |
|
3203 |
"Created: / 26-04-2010 / 13:36:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3204 |
! |
|
3205 |
||
3206 |
setLookupObject:aMethodLookupObject |
|
3207 |
"set the lookupObject (Jan's MetaObjectProtocol support) or nil. |
|
3208 |
If non-nil, no lookup is performed by the VM, instead the lookupObject |
|
3209 |
has to provide a method object for message sends." |
|
3210 |
||
14535 | 3211 |
lookupObject ~~ aMethodLookupObject ifTrue:[ |
16050 | 3212 |
lookupObject := aMethodLookupObject. |
3213 |
ObjectMemory flushCachesFor: self. |
|
3214 |
self allSubclassesDo:[:cls|ObjectMemory flushCachesFor: cls] |
|
14535 | 3215 |
] |
13414 | 3216 |
|
3217 |
"Modified: / 22-07-2010 / 18:10:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
9194 | 3218 |
! ! |
3219 |
||
3220 |
!Behavior methodsFor:'queries'! |
|
620 | 3221 |
|
6727 | 3222 |
category |
12094 | 3223 |
"return the category of the class. |
6727 | 3224 |
Returning nil here, since Behavior does not define a category |
3225 |
(only ClassDescriptions do)." |
|
3226 |
||
3227 |
^ nil |
|
3228 |
||
3229 |
" |
|
12094 | 3230 |
Point category |
3231 |
Behavior new category |
|
6727 | 3232 |
" |
9194 | 3233 |
! |
6727 | 3234 |
|
3235 |
comment |
|
12094 | 3236 |
"return the comment of the class. |
6727 | 3237 |
Returning nil here, since Behavior does not define a category |
3238 |
(only Classes do). This allows different Behavior-like objects |
|
3239 |
(alien classes) to be handled by the browser as well." |
|
3240 |
||
9194 | 3241 |
^ nil |
3242 |
||
3243 |
"Modified: 16.4.1996 / 16:25:23 / cg" |
|
3244 |
! |
|
6727 | 3245 |
|
3246 |
definitionSelector |
|
3247 |
"return the selector with which I was (can be) defined in my superclass" |
|
3248 |
||
3249 |
^ (self firstDefinitionSelectorPart |
|
3250 |
, |
|
3251 |
'instanceVariableNames:classVariableNames:poolDictionaries:category:') asSymbol |
|
3252 |
||
3253 |
" |
|
3254 |
Object definitionSelector |
|
12094 | 3255 |
Array definitionSelector |
3256 |
ByteArray definitionSelector |
|
3257 |
FloatArray definitionSelector |
|
9194 | 3258 |
" |
3259 |
||
3260 |
"Modified: 3.3.1997 / 11:50:37 / cg" |
|
3261 |
! |
|
6727 | 3262 |
|
3263 |
definitionSelectorPrivate |
|
3264 |
"return the selector with which I was (can be) defined in my superclass |
|
3265 |
as a private class" |
|
3266 |
||
3267 |
^ (self firstDefinitionSelectorPart |
|
3268 |
, |
|
3269 |
'instanceVariableNames:classVariableNames:poolDictionaries:privateIn:') asSymbol |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3270 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3271 |
" |
12094 | 3272 |
Array definitionSelector |
3273 |
Array definitionSelectorPrivate |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3274 |
" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
3275 |
|
6727 | 3276 |
"Modified: 23.6.1997 / 10:45:57 / cg" |
620 | 3277 |
! |
3278 |
||
15103 | 3279 |
environment |
3280 |
"return the namespace I am contained in; ST-80 compatible name. |
|
3281 |
Not normally needed here, but added to allow for instances of anonymous behaviours |
|
3282 |
to be inspected or browsed." |
|
3283 |
||
3284 |
^ nil |
|
3285 |
! |
|
3286 |
||
9194 | 3287 |
firstDefinitionSelectorPart |
6727 | 3288 |
"return the first part of the selector with which I was (can be) defined in my superclass" |
3289 |
||
3290 |
self isVariable ifFalse:[ |
|
16050 | 3291 |
^ #'subclass:' |
6727 | 3292 |
]. |
3293 |
self isBytes ifTrue:[ |
|
16050 | 3294 |
^ #'variableByteSubclass:' |
6727 | 3295 |
]. |
3296 |
self isLongs ifTrue:[ |
|
16050 | 3297 |
^ #'variableLongSubclass:' |
6727 | 3298 |
]. |
3299 |
self isFloats ifTrue:[ |
|
16050 | 3300 |
^ #'variableFloatSubclass:' |
6727 | 3301 |
]. |
3302 |
self isDoubles ifTrue:[ |
|
16050 | 3303 |
^ #'variableDoubleSubclass:' |
6727 | 3304 |
]. |
3305 |
self isWords ifTrue:[ |
|
16050 | 3306 |
^ #'variableWordSubclass:' |
6727 | 3307 |
]. |
3308 |
self isSignedWords ifTrue:[ |
|
16050 | 3309 |
^ #'variableSignedWordSubclass:' |
6727 | 3310 |
]. |
3311 |
self isSignedLongs ifTrue:[ |
|
16050 | 3312 |
^ #'variableSignedLongSubclass:' |
6727 | 3313 |
]. |
3314 |
self isSignedLongLongs ifTrue:[ |
|
16050 | 3315 |
^ #'variableSignedLongLongSubclass:' |
6727 | 3316 |
]. |
3317 |
self isLongLongs ifTrue:[ |
|
16050 | 3318 |
^ #'variableLongLongSubclass:' |
6727 | 3319 |
]. |
3320 |
^ #'variableSubclass:' |
|
9194 | 3321 |
! |
3322 |
||
3323 |
fullName |
|
3324 |
"Answer the name of the receiver, fully qualified." |
|
3325 |
||
3326 |
^ self name asString |
|
3327 |
||
3328 |
! |
|
3329 |
||
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3330 |
hasExtensions |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3331 |
^ false |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3332 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3333 |
"Created: / 06-08-2006 / 15:23:32 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3334 |
! |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3335 |
|
14504 | 3336 |
isAbstract |
3337 |
^ false |
|
3338 |
! |
|
3339 |
||
9194 | 3340 |
isBehavior |
9219 | 3341 |
"return true, if the receiver is describing another objects behavior. |
3342 |
Defined to avoid the need to use isKindOf:" |
|
9194 | 3343 |
|
3344 |
^ true |
|
3345 |
||
3346 |
" |
|
12094 | 3347 |
True isBehavior |
9194 | 3348 |
true isBehavior |
3349 |
" |
|
3350 |
! |
|
620 | 3351 |
|
10043
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3352 |
isBrowserStartable |
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3353 |
^ false |
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3354 |
|
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3355 |
"Created: / 06-10-2006 / 11:33:42 / cg" |
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3356 |
! |
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3357 |
|
6727 | 3358 |
isBuiltInClass |
3359 |
"return true if this class is known by the run-time-system. |
|
3360 |
Here, false is returned as default. |
|
3361 |
Notice, this is instance protocol, which means that any class |
|
3362 |
other than those special ones) are non-builtIn by default." |
|
3363 |
||
3364 |
^ false |
|
3365 |
||
3366 |
"Modified: 23.4.1996 / 15:55:52 / cg" |
|
9194 | 3367 |
"Created: 28.10.1996 / 15:10:02 / cg" |
3368 |
! |
|
3369 |
||
15103 | 3370 |
isObsolete |
3371 |
"return true, if the receiver is obsolete |
|
3372 |
(i.e. has been replaced by a different class or was removed, |
|
3373 |
but is still referenced by instanced). |
|
3374 |
Not normally needed here, but added to allow for instances of anonymous behaviours |
|
3375 |
to be inspected or browsed." |
|
3376 |
||
3377 |
^ false |
|
3378 |
! |
|
3379 |
||
9194 | 3380 |
isPrivate |
3381 |
"return true, if the receiver is some private class" |
|
3382 |
||
3383 |
^ self owningClass notNil |
|
3384 |
||
3385 |
"Modified: 12.10.1996 / 20:11:05 / cg" |
|
3386 |
! |
|
6727 | 3387 |
|
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3388 |
isStartableWithMain |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3389 |
^ false |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3390 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3391 |
"Created: / 06-08-2006 / 15:23:50 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3392 |
! |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3393 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3394 |
isStartableWithStart |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3395 |
^ false |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3396 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3397 |
"Created: / 06-08-2006 / 15:23:57 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3398 |
! |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3399 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3400 |
isVisualStartable |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3401 |
^ false |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3402 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3403 |
"Created: / 06-08-2006 / 15:23:38 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3404 |
! |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3405 |
|
6727 | 3406 |
name |
3407 |
"although behaviors have no name, we return something |
|
3408 |
useful here - there are many places (inspectors) where |
|
3409 |
a classes name is asked for. |
|
3410 |
Implementing this message here allows anonymous classes |
|
9194 | 3411 |
and instances of them to be inspected." |
3412 |
||
3413 |
^ #'anonymous Behavior' |
|
3414 |
! |
|
3415 |
||
3416 |
nameInBrowser |
|
3417 |
"return a nameString as shown in browsers" |
|
3418 |
||
3419 |
^ self name ? '?' |
|
3420 |
! |
|
6727 | 3421 |
|
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3422 |
nameWithArticle |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3423 |
"return a string consisting of classname preceeded by an article. |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3424 |
(dont expect me to write national variants for this ... :-) |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3425 |
If you have special preferences, redefine it..." |
12094 | 3426 |
|
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3427 |
|classname| |
12094 | 3428 |
|
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3429 |
classname := self name. |
14259 | 3430 |
classname isEmptyOrNil ifTrue:[ ^ 'an anonymous' ]. |
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3431 |
^ classname article , ' ' , classname |
12094 | 3432 |
|
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3433 |
" |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3434 |
SmallInteger nameWithArticle |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3435 |
" |
9445 | 3436 |
|
14259 | 3437 |
"Modified: / 13-06-2012 / 14:50:03 / cg" |
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3438 |
! |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3439 |
|
6727 | 3440 |
owningClass |
3441 |
"return my owning class - nil if I am a public class" |
|
3442 |
||
3443 |
"/ this information is in the metaclass ... |
|
3444 |
||
3445 |
^ self class owningClass |
|
3446 |
||
3447 |
"Created: 15.10.1996 / 21:19:32 / cg" |
|
3448 |
"Modified: 7.11.1996 / 13:49:28 / cg" |
|
3449 |
! |
|
3450 |
||
6733
4f8a80a22261
added #owningClassOrYourself
Claus Gittinger <cg@exept.de>
parents:
6727
diff
changeset
|
3451 |
owningClassOrYourself |
4f8a80a22261
added #owningClassOrYourself
Claus Gittinger <cg@exept.de>
parents:
6727
diff
changeset
|
3452 |
"return my owning class if I am private, myself otherwise" |
4f8a80a22261
added #owningClassOrYourself
Claus Gittinger <cg@exept.de>
parents:
6727
diff
changeset
|
3453 |
|
9194 | 3454 |
self owningClass notNil ifTrue:[^ self topOwningClass]. |
3455 |
^ self |
|
3456 |
! |
|
6733
4f8a80a22261
added #owningClassOrYourself
Claus Gittinger <cg@exept.de>
parents:
6727
diff
changeset
|
3457 |
|
15103 | 3458 |
privateClassesAt:aClassNameStringOrSymbol |
3459 |
"return a private class if present; nil otherwise. |
|
3460 |
Not normally needed here, but added to allow for instances of anonymous behaviours |
|
3461 |
to be inspected or browsed." |
|
3462 |
||
3463 |
^ nil |
|
3464 |
! |
|
3465 |
||
3466 |
realSharedPoolNames |
|
3467 |
"this returns the namespace aware pool names. |
|
3468 |
Not normally needed here, but added to allow for instances of anonymous behaviours |
|
3469 |
to be inspected or browsed." |
|
3470 |
||
3471 |
^ #() |
|
3472 |
! |
|
3473 |
||
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3474 |
revision |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3475 |
^ nil |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3476 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3477 |
"Created: / 03-08-2006 / 01:53:44 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3478 |
! |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3479 |
|
6727 | 3480 |
sourceCodeAt:aSelector |
3481 |
"return the methods source for given selector aSelector or nil. |
|
3482 |
Only methods in the receiver - not in the superclass chain are tested." |
|
3483 |
||
7676 | 3484 |
^ self sourceCodeAt:aSelector ifAbsent:nil |
6727 | 3485 |
|
3486 |
" |
|
3487 |
True sourceCodeAt:#ifTrue: |
|
3488 |
Object sourceCodeAt:#== |
|
3489 |
Behavior sourceCodeAt:#sourceCodeAt: |
|
2053 | 3490 |
" |
3491 |
! |
|
3492 |
||
7676 | 3493 |
sourceCodeAt:aSelector ifAbsent:exceptionalValue |
3494 |
"return the methods source for given selector aSelector or exceptionalValue. |
|
3495 |
Only methods in the receiver - not in the superclass chain are tested." |
|
3496 |
||
3497 |
|method| |
|
3498 |
||
3499 |
method := self compiledMethodAt:aSelector. |
|
3500 |
method isNil ifTrue:[^ exceptionalValue value]. |
|
9194 | 3501 |
^ method source |
3502 |
! |
|
7676 | 3503 |
|
6727 | 3504 |
sourceCodeManager |
12094 | 3505 |
"return the sourceCodeManager of the class. |
6727 | 3506 |
Returning nil here, since Behavior does not define any sourceCode management. |
3507 |
(only Classes do). This allows different Behavior-like objects |
|
3508 |
(alien classes) to be handled by the browser as well." |
|
3509 |
||
3510 |
^ nil |
|
3511 |
||
3512 |
"Created: 16.4.1996 / 16:26:03 / cg" |
|
9194 | 3513 |
! |
6727 | 3514 |
|
3515 |
supportsMethodCategories |
|
3516 |
"return true, if my methods are categorized. |
|
3517 |
This is a hook for the browser to allow alien classes |
|
14154
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
3518 |
to be handled (actually, this is not yet used)." |
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
3519 |
|
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
3520 |
^ self class supportsMethodCategories |
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
3521 |
|
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
3522 |
"Created: / 30-07-1997 / 14:59:08 / cg" |
2bbca940477e
added: #supportsMethodCategories
Claus Gittinger <cg@exept.de>
parents:
14065
diff
changeset
|
3523 |
"Modified: / 01-06-2012 / 20:38:03 / cg" |
620 | 3524 |
! |
3525 |
||
6727 | 3526 |
theMetaclass |
9696 | 3527 |
"return the metaClass of the class-meta pair. |
3528 |
Here, return my metaclass object, because I am the class. |
|
3529 |
Also implemented in my metaclass, which returns itself." |
|
9194 | 3530 |
|
3531 |
^ self class |
|
3532 |
||
3533 |
"Created: / 30.1.2000 / 23:08:30 / cg" |
|
3534 |
"Modified: / 31.1.2000 / 16:16:52 / cg" |
|
3535 |
! |
|
6727 | 3536 |
|
3537 |
theNonMetaclass |
|
9696 | 3538 |
"return the nonMetaClass of the class-meta pair. |
3539 |
Here, return myself, because I am the nonMetaclass. |
|
3540 |
Also implemented in my metaclass, which also returns me." |
|
6727 | 3541 |
|
3542 |
^ self |
|
3543 |
||
3544 |
"Created: / 30.1.2000 / 23:07:59 / cg" |
|
3545 |
"Modified: / 31.1.2000 / 16:17:46 / cg" |
|
3546 |
! |
|
3547 |
||
15103 | 3548 |
topNameSpace |
3549 |
"return the nameSpace of my topOwningClass (if private) or my own nameSpace. |
|
3550 |
Not normally needed here, but added to allow for instances of anonymous behaviours |
|
3551 |
to be inspected or browsed." |
|
3552 |
||
3553 |
^ nil |
|
3554 |
! |
|
3555 |
||
6727 | 3556 |
topOwningClass |
3557 |
"return my outermost owning class - nil if I am a public class" |
|
3558 |
||
3559 |
"/ this information is in the metaclass ... |
|
3560 |
||
3561 |
^ self class topOwningClass |
|
3562 |
||
3563 |
"Created: 15.10.1996 / 21:19:32 / cg" |
|
3564 |
"Modified: 3.1.1997 / 19:18:49 / cg" |
|
3565 |
! ! |
|
3566 |
||
9194 | 3567 |
!Behavior methodsFor:'queries-inheritance'! |
6727 | 3568 |
|
620 | 3569 |
allSubclasses |
3570 |
"return a collection of all subclasses (direct AND indirect) of |
|
3571 |
the receiver. There will be no specific order, in which entries |
|
10172 | 3572 |
are returned. NameSpaces are excluded from the list." |
620 | 3573 |
|
3574 |
|newColl| |
|
3575 |
||
3576 |
newColl := OrderedCollection new. |
|
3577 |
self allSubclassesDo:[:aClass | |
|
16050 | 3578 |
(aClass isRealNameSpace) ifFalse:[ |
3579 |
newColl add:aClass |
|
3580 |
] |
|
620 | 3581 |
]. |
3582 |
^ newColl |
|
3583 |
||
3584 |
" |
|
3585 |
Collection allSubclasses |
|
3586 |
" |
|
10172 | 3587 |
|
3588 |
"Modified: / 10-11-2006 / 17:22:58 / cg" |
|
620 | 3589 |
! |
3590 |
||
3591 |
allSubclassesInOrder |
|
3592 |
"return a collection of all subclasses (direct AND indirect) of |
|
10172 | 3593 |
the receiver. Higher level subclasses will come before lower ones. |
3594 |
NameSpaces are excluded from the list." |
|
620 | 3595 |
|
3596 |
|newColl| |
|
3597 |
||
3598 |
newColl := OrderedCollection new. |
|
3599 |
self allSubclassesInOrderDo:[:aClass | |
|
16050 | 3600 |
(aClass isRealNameSpace) ifFalse:[ |
3601 |
newColl add:aClass |
|
3602 |
] |
|
620 | 3603 |
]. |
3604 |
^ newColl |
|
3605 |
||
3606 |
" |
|
9194 | 3607 |
Collection allSubclassesInOrder |
3608 |
" |
|
10172 | 3609 |
|
3610 |
"Modified: / 10-11-2006 / 17:23:06 / cg" |
|
9194 | 3611 |
! |
620 | 3612 |
|
3613 |
allSuperclasses |
|
3614 |
"return a collection of the receivers accumulated superclasses" |
|
3615 |
||
3616 |
|aCollection theSuperClass| |
|
3617 |
||
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
3618 |
theSuperClass := self superclass. |
4451 | 3619 |
theSuperClass isNil ifTrue:[ |
16050 | 3620 |
^ #() |
4451 | 3621 |
]. |
3622 |
aCollection := OrderedCollection new. |
|
3623 |
[theSuperClass notNil] whileTrue:[ |
|
16050 | 3624 |
aCollection add:theSuperClass. |
3625 |
theSuperClass := theSuperClass superclass |
|
620 | 3626 |
]. |
3627 |
^ aCollection |
|
3628 |
||
3629 |
" |
|
12094 | 3630 |
String allSuperclasses |
9194 | 3631 |
" |
3632 |
! |
|
620 | 3633 |
|
3634 |
canBeSubclassed |
|
3635 |
"return true, if its allowed to create subclasses of the receiver. |
|
3636 |
This method is redefined in SmallInteger and UndefinedObject, since |
|
3637 |
instances are detected by their pointer-fields, i.e. they do not have |
|
7435
c5afb1b0fd1b
Prepare for moving of SubclassInfo to subclass instcar in Class
Stefan Vogel <sv@exept.de>
parents:
7358
diff
changeset
|
3638 |
a class entry (you don't have to understand this :-)" |
10 | 3639 |
|
3640 |
^ true |
|
3641 |
! |
|
3642 |
||
3641 | 3643 |
commonSuperclass:aClass |
3644 |
"Return the common superclass of the receiver and aClass. |
|
6754
d9c0f178f091
commonSuperClass: care for nil subclass
Claus Gittinger <cg@exept.de>
parents:
6733
diff
changeset
|
3645 |
Assumes that there is a common superclass of any two classes. |
14065
6f6d6223c947
changed: #commonSuperclass:
Claus Gittinger <cg@exept.de>
parents:
13862
diff
changeset
|
3646 |
(might return nil, if either the receiver or the argument inherits from nil)" |
6f6d6223c947
changed: #commonSuperclass:
Claus Gittinger <cg@exept.de>
parents:
13862
diff
changeset
|
3647 |
|
6f6d6223c947
changed: #commonSuperclass:
Claus Gittinger <cg@exept.de>
parents:
13862
diff
changeset
|
3648 |
(aClass == self) ifTrue:[^ self]. |
6f6d6223c947
changed: #commonSuperclass:
Claus Gittinger <cg@exept.de>
parents:
13862
diff
changeset
|
3649 |
(aClass isSubclassOf:self) ifTrue:[^ self]. |
6f6d6223c947
changed: #commonSuperclass:
Claus Gittinger <cg@exept.de>
parents:
13862
diff
changeset
|
3650 |
(self isSubclassOf:aClass) ifTrue:[^ aClass]. |
6754
d9c0f178f091
commonSuperClass: care for nil subclass
Claus Gittinger <cg@exept.de>
parents:
6733
diff
changeset
|
3651 |
superclass isNil ifTrue:[^ nil]. |
d9c0f178f091
commonSuperClass: care for nil subclass
Claus Gittinger <cg@exept.de>
parents:
6733
diff
changeset
|
3652 |
^ superclass commonSuperclass:aClass |
3641 | 3653 |
|
3654 |
" |
|
14688 | 3655 |
Integer commonSuperclass:Fraction |
3656 |
SmallInteger commonSuperclass:Fraction |
|
3657 |
View commonSuperclass:Form |
|
3658 |
View commonSuperclass:Image |
|
3659 |
View commonSuperclass:View |
|
3660 |
Integer commonSuperclass:Autoload |
|
3661 |
Integer commonSuperclass:Object |
|
3641 | 3662 |
" |
3663 |
||
14065
6f6d6223c947
changed: #commonSuperclass:
Claus Gittinger <cg@exept.de>
parents:
13862
diff
changeset
|
3664 |
"Modified (comment): / 17-03-2012 / 19:56:28 / cg" |
9194 | 3665 |
! |
3666 |
||
3667 |
hasMultipleSuperclasses |
|
12094 | 3668 |
"Return true, if this class inherits from other classes |
3669 |
(beside its primary superclass). |
|
3670 |
This method is a preparation for a future multiple inheritance extension |
|
9194 | 3671 |
- currently it is not supported by the VM" |
3672 |
||
3673 |
^ false |
|
3674 |
! |
|
6727 | 3675 |
|
13318 | 3676 |
includesBehavior:aClass |
3677 |
"return true, if the receiver includes the behavior of aClass; |
|
3678 |
i.e. if is either identical to a class or inherits from it." |
|
3679 |
||
3680 |
^ (self == aClass) or:[self isSubclassOf:aClass] |
|
3681 |
||
3682 |
" |
|
3683 |
True includesBehavior:Object |
|
3684 |
True includesBehavior:Boolean |
|
3685 |
True includesBehavior:True |
|
3686 |
True includesBehavior:False |
|
3687 |
" |
|
3688 |
||
3689 |
"Modified: 19.6.1997 / 18:14:35 / cg" |
|
3690 |
! |
|
3691 |
||
6727 | 3692 |
inheritsFrom:aClass |
3693 |
"return true, if the receiver inherits methods from aClass; |
|
3694 |
i.e. if aClass is on the receivers superclass chain." |
|
3695 |
||
3696 |
^ self isSubclassOf:aClass |
|
620 | 3697 |
|
293 | 3698 |
" |
6727 | 3699 |
True inheritsFrom:Object |
3700 |
LinkedList inheritsFrom:Array |
|
293 | 3701 |
" |
1088 | 3702 |
|
9194 | 3703 |
"Modified: 19.6.1997 / 18:13:21 / cg" |
3704 |
! |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
3705 |
|
13318 | 3706 |
isSubclassOf:aClass |
3707 |
"return true, if I am a subclass of the argument, aClass" |
|
3708 |
||
3709 |
%{ /* NOCONTEXT */ |
|
3710 |
OBJ __theClass = __INST(superclass); |
|
16050 | 3711 |
int n = 0; |
13318 | 3712 |
|
3713 |
while (__theClass != nil) { |
|
16050 | 3714 |
if (__theClass == aClass) { |
3715 |
RETURN(true); |
|
3716 |
} |
|
3717 |
if (__isBehaviorLike(__theClass)) { |
|
3718 |
__theClass = __ClassInstPtr(__theClass)->c_superclass; |
|
3719 |
} else { |
|
3720 |
__theClass = nil; |
|
3721 |
} |
|
3722 |
if (++n > 100000) goto vmError; |
|
13318 | 3723 |
} |
3724 |
RETURN (false); |
|
16050 | 3725 |
vmError: ; |
13318 | 3726 |
%}. |
16050 | 3727 |
VMInternalError raiseErrorString:'deep inheritance'. |
13318 | 3728 |
|
3729 |
"/ |theClass| |
|
3730 |
"/ |
|
3731 |
"/ theClass := superclass. |
|
3732 |
"/ [theClass notNil] whileTrue:[ |
|
3733 |
"/ (theClass == aClass) ifTrue:[^ true]. |
|
3734 |
"/%{ |
|
3735 |
"/ if (__isBehaviorLike(theClass)) { |
|
3736 |
"/ theClass = __ClassInstPtr(theClass)->c_superclass; |
|
3737 |
"/ } else { |
|
3738 |
"/ theClass = nil; |
|
3739 |
"/ } |
|
3740 |
"/%}. |
|
3741 |
"/"/ theClass := theClass superclass. |
|
3742 |
"/ ]. |
|
3743 |
"/ ^ false |
|
3744 |
||
3745 |
" |
|
13419 | 3746 |
String isSubclassOf:Collection |
3747 |
LinkedList isSubclassOf:Array |
|
13318 | 3748 |
1 isSubclassOf:Number <- will fail since 1 is no class |
13419 | 3749 |
Number isSubclassOf:1 |
13318 | 3750 |
" |
3751 |
! |
|
3752 |
||
6727 | 3753 |
subclasses |
3754 |
"return a collection of the direct subclasses of the receiver" |
|
3755 |
||
3756 |
|newColl| |
|
3757 |
||
3758 |
newColl := OrderedCollection new. |
|
3759 |
self subclassesDo:[:aClass | |
|
16050 | 3760 |
newColl add:aClass |
6727 | 3761 |
]. |
7435
c5afb1b0fd1b
Prepare for moving of SubclassInfo to subclass instcar in Class
Stefan Vogel <sv@exept.de>
parents:
7358
diff
changeset
|
3762 |
^ newColl. |
6727 | 3763 |
! |
3764 |
||
3765 |
superclasses |
|
9194 | 3766 |
"return a collection of the receivers immediate superclasses. |
12094 | 3767 |
This method is a preparation for a future multiple inheritance extension |
9194 | 3768 |
- currently it is not supported by the VM" |
3769 |
||
3770 |
^ Array with:self superclass. |
|
3771 |
||
3772 |
" |
|
12094 | 3773 |
String superclasses |
9194 | 3774 |
" |
3775 |
! |
|
6727 | 3776 |
|
3777 |
withAllSubclasses |
|
12094 | 3778 |
"return a collection containing the receiver and |
6727 | 3779 |
all subclasses (direct AND indirect) of the receiver" |
3780 |
||
3781 |
|coll| |
|
3782 |
||
14414
5966c2554334
comment/format in: #withAllSuperclasses
Claus Gittinger <cg@exept.de>
parents:
14288
diff
changeset
|
3783 |
coll := OrderedCollection new. |
5966c2554334
comment/format in: #withAllSuperclasses
Claus Gittinger <cg@exept.de>
parents:
14288
diff
changeset
|
3784 |
self withAllSubclassesDo:[:eachClass | coll add:eachClass]. |
6727 | 3785 |
^ coll |
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
3786 |
|
14414
5966c2554334
comment/format in: #withAllSuperclasses
Claus Gittinger <cg@exept.de>
parents:
14288
diff
changeset
|
3787 |
"/ the following original code is slighly less efficient (makes big collections) |
5966c2554334
comment/format in: #withAllSuperclasses
Claus Gittinger <cg@exept.de>
parents:
14288
diff
changeset
|
3788 |
"/ coll := self allSubclasses asOrderedCollection. |
5966c2554334
comment/format in: #withAllSuperclasses
Claus Gittinger <cg@exept.de>
parents:
14288
diff
changeset
|
3789 |
"/ coll addFirst:self. |
5966c2554334
comment/format in: #withAllSuperclasses
Claus Gittinger <cg@exept.de>
parents:
14288
diff
changeset
|
3790 |
"/ ^ coll |
5966c2554334
comment/format in: #withAllSuperclasses
Claus Gittinger <cg@exept.de>
parents:
14288
diff
changeset
|
3791 |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
3792 |
" |
6727 | 3793 |
Collection withAllSubclasses |
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
3794 |
" |
620 | 3795 |
! |
3796 |
||
6727 | 3797 |
withAllSuperclasses |
3798 |
"return a collection containing the receiver and all |
|
3799 |
of the receivers accumulated superclasses" |
|
3800 |
||
14414
5966c2554334
comment/format in: #withAllSuperclasses
Claus Gittinger <cg@exept.de>
parents:
14288
diff
changeset
|
3801 |
|coll| |
5966c2554334
comment/format in: #withAllSuperclasses
Claus Gittinger <cg@exept.de>
parents:
14288
diff
changeset
|
3802 |
|
5966c2554334
comment/format in: #withAllSuperclasses
Claus Gittinger <cg@exept.de>
parents:
14288
diff
changeset
|
3803 |
coll := OrderedCollection new. |
6727 | 3804 |
self withAllSuperclassesDo:[:cls | |
16050 | 3805 |
coll add:cls |
6727 | 3806 |
]. |
14414
5966c2554334
comment/format in: #withAllSuperclasses
Claus Gittinger <cg@exept.de>
parents:
14288
diff
changeset
|
3807 |
^ coll |
9194 | 3808 |
|
3809 |
" |
|
12094 | 3810 |
String withAllSuperclasses |
9194 | 3811 |
" |
3812 |
! ! |
|
3813 |
||
3814 |
!Behavior methodsFor:'queries-instances'! |
|
6727 | 3815 |
|
3816 |
allDerivedInstances |
|
12094 | 3817 |
"return a collection of all instances of myself and |
6727 | 3818 |
instances of all subclasses of myself. |
3819 |
This method is going to be removed for protocol compatibility with |
|
3820 |
other STs; use allSubInstances" |
|
3821 |
||
3822 |
<resource:#obsolete> |
|
3823 |
||
3824 |
self obsoleteMethodWarning:'use #allSubInstances'. |
|
3825 |
^ self allSubInstances |
|
3826 |
||
9194 | 3827 |
"Modified: 31.7.1997 / 23:04:59 / cg" |
3828 |
! |
|
2436 | 3829 |
|
6727 | 3830 |
allInstances |
3831 |
"return a collection of all my instances" |
|
3832 |
||
3833 |
"Read the documentation on why there seem to be no |
|
3834 |
instances of SmallInteger and UndefinedObject" |
|
3835 |
||
3836 |
|coll| |
|
3837 |
||
3838 |
coll := OrderedCollection new:100. |
|
3839 |
self allInstancesDo:[:anObject | |
|
16050 | 3840 |
coll add:anObject |
6727 | 3841 |
]. |
12094 | 3842 |
^ coll |
2713 | 3843 |
|
3844 |
" |
|
6727 | 3845 |
ScrollBar allInstances |
2713 | 3846 |
" |
6727 | 3847 |
! |
3848 |
||
3849 |
allInstancesWeakly:doWeakly |
|
3850 |
"return a collection of all my instances. |
|
3851 |
If weakly is true, a weak collection is returned." |
|
3852 |
||
3853 |
"Read the documentation on why there seem to be no |
|
3854 |
instances of SmallInteger and UndefinedObject" |
|
3855 |
||
3856 |
|coll| |
|
3857 |
||
3858 |
coll := self allInstances. |
|
3859 |
doWeakly ifTrue:[ |
|
16050 | 3860 |
coll := WeakArray withAll:coll |
9194 | 3861 |
]. |
3862 |
^ coll |
|
3863 |
||
3864 |
"Created: / 19.6.1998 / 02:17:20 / cg" |
|
3865 |
! |
|
6727 | 3866 |
|
3867 |
allSubInstances |
|
12094 | 3868 |
"return a collection of all instances of myself and |
6727 | 3869 |
instances of all subclasses of myself." |
3870 |
||
3871 |
|coll| |
|
3872 |
||
3873 |
coll := OrderedCollection new:100. |
|
3874 |
self allSubInstancesDo:[:anObject | |
|
16268 | 3875 |
coll add:anObject |
6727 | 3876 |
]. |
12094 | 3877 |
^ coll |
6727 | 3878 |
|
3879 |
" |
|
3880 |
View allSubInstances |
|
3881 |
" |
|
2713 | 3882 |
! |
3883 |
||
10669 | 3884 |
anyInstance |
3885 |
"return any of my instances; raise an error, if there is none" |
|
3886 |
||
3887 |
"Read the documentation on why there seem to be no |
|
3888 |
instances of SmallInteger and UndefinedObject" |
|
3889 |
||
3890 |
self allInstancesDo:[:anObject | ^ anObject]. |
|
3891 |
self errorNotFound |
|
3892 |
||
3893 |
" |
|
3894 |
ScrollBar anyInstance |
|
3895 |
SmallInteger anyInstance |
|
3896 |
" |
|
3897 |
||
3898 |
"Created: / 24-07-2007 / 06:12:27 / cg" |
|
3899 |
! |
|
3900 |
||
15745 | 3901 |
anySubInstance |
3902 |
"return any of my or derived instances; raise an error, if there is none" |
|
3903 |
||
3904 |
"Read the documentation on why there seem to be no |
|
3905 |
instances of SmallInteger and UndefinedObject" |
|
3906 |
||
3907 |
self allSubInstancesDo:[:anObject | ^ anObject]. |
|
3908 |
self errorNotFound |
|
3909 |
||
3910 |
" |
|
3911 |
View anySubInstance |
|
3912 |
" |
|
3913 |
! |
|
3914 |
||
620 | 3915 |
derivedInstanceCount |
3916 |
"return the number of instances of myself and of subclasses" |
|
3917 |
||
3918 |
|count| |
|
3919 |
||
3920 |
count := 0. |
|
3921 |
ObjectMemory allObjectsDo:[:anObject | |
|
16050 | 3922 |
(anObject isKindOf:self) ifTrue:[ |
3923 |
count := count + 1 |
|
3924 |
] |
|
620 | 3925 |
]. |
3926 |
^ count |
|
3927 |
||
293 | 3928 |
" |
620 | 3929 |
View derivedInstanceCount |
9194 | 3930 |
SequenceableCollection derivedInstanceCount |
3931 |
Object derivedInstanceCount |
|
3932 |
" |
|
3933 |
! |
|
983 | 3934 |
|
3935 |
hasDerivedInstances |
|
3936 |
"return true, if there are any instances of myself or of any subclass" |
|
3937 |
||
3938 |
"Read the documentation on why there seem to be no |
|
3939 |
instances of SmallInteger and UndefinedObject" |
|
3940 |
||
3941 |
ObjectMemory allObjectsDo:[:anObject | |
|
16050 | 3942 |
(anObject isKindOf:self) ifTrue:[ |
3943 |
^ true |
|
3944 |
] |
|
983 | 3945 |
]. |
3946 |
^ false |
|
3947 |
||
3948 |
" |
|
9194 | 3949 |
Object hasDerivedInstances - certainly true |
3950 |
SharedQueue hasDerivedInstances |
|
3951 |
" |
|
3952 |
! |
|
620 | 3953 |
|
2674
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3954 |
hasImmediateInstances |
4657
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
3955 |
"return true if this class has immediate instances |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
3956 |
i.e. if the instances are represented in the pointer itself and |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
3957 |
no real object header/storage is used for the object. |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
3958 |
Redefined in classes which have so (only SmallInteger and UndefinedObject)" |
2674
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3959 |
|
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3960 |
^ false |
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3961 |
|
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3962 |
"Created: 3.6.1997 / 12:01:05 / cg" |
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3963 |
! |
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3964 |
|
620 | 3965 |
hasInstances |
3966 |
"return true, if there are any instances of myself" |
|
3967 |
||
3968 |
"Read the documentation on why there seem to be no |
|
3969 |
instances of SmallInteger and UndefinedObject" |
|
3970 |
||
3971 |
"/ ObjectMemory allObjectsDo:[:anObject | |
|
3972 |
"/ (anObject class == self) ifTrue:[ |
|
3973 |
"/ ^ true |
|
3974 |
"/ ] |
|
3975 |
"/ ]. |
|
983 | 3976 |
|
620 | 3977 |
ObjectMemory allInstancesOf:self do:[:anObject | |
16050 | 3978 |
^ true |
620 | 3979 |
]. |
3980 |
^ false |
|
3981 |
||
293 | 3982 |
" |
620 | 3983 |
Object hasInstances |
3984 |
SequenceableCollection hasInstances |
|
3985 |
Float hasInstances |
|
3986 |
SmallInteger hasInstances |
|
293 | 3987 |
" |
9194 | 3988 |
! |
3989 |
||
3990 |
hasSharedInstances |
|
3991 |
"return true if this class has shared instances, that is, instances |
|
3992 |
with the same value are identical. |
|
3993 |
False is returned here, only redefined in classes which have unified |
|
3994 |
instances (or should be treated so)." |
|
3995 |
||
3996 |
^ false |
|
3997 |
! |
|
3998 |
||
3999 |
instanceCount |
|
6727 | 4000 |
"return the number of instances of myself." |
4001 |
||
4002 |
"Read the documentation on why there seem to be no |
|
4003 |
instances of SmallInteger and UndefinedObject" |
|
4004 |
||
4005 |
|count| |
|
4006 |
||
4007 |
count := 0. |
|
4008 |
"/ ObjectMemory allObjectsDo:[:anObject | |
|
4009 |
"/ (anObject class == self) ifTrue:[ |
|
4010 |
"/ count := count + 1 |
|
4011 |
"/ ] |
|
4012 |
"/ ]. |
|
4013 |
||
4014 |
ObjectMemory allInstancesOf:self do:[:anObject | |
|
16050 | 4015 |
count := count + 1 |
6727 | 4016 |
]. |
4017 |
^ count |
|
4018 |
||
4019 |
" |
|
4020 |
View instanceCount |
|
4021 |
Object instanceCount |
|
4022 |
Float instanceCount |
|
4023 |
SequenceableCollection instanceCount |
|
4024 |
SmallInteger instanceCount .... mhmh - hear, hear |
|
4025 |
" |
|
9194 | 4026 |
! ! |
4027 |
||
4028 |
!Behavior methodsFor:'queries-instlayout'! |
|
6727 | 4029 |
|
4030 |
elementByteSize |
|
9194 | 4031 |
"for bit-like containers, return the number of bytes stored per |
4032 |
element. For pointer indexed classes, 0 is returned" |
|
4033 |
||
4034 |
self isBitsExtended ifTrue:[ |
|
16050 | 4035 |
self isBytes ifTrue:[^ 1]. |
4036 |
self isWords ifTrue:[^ 2]. |
|
4037 |
self isSignedWords ifTrue:[^ 2]. |
|
4038 |
self isLongs ifTrue:[^ 4]. |
|
4039 |
self isSignedLongs ifTrue:[^ 4]. |
|
4040 |
self isLongLongs ifTrue:[^ 8]. |
|
4041 |
self isSignedLongLongs ifTrue:[^ 8]. |
|
9194 | 4042 |
]. |
4043 |
self isFloats ifTrue:[^ 4]. |
|
4044 |
self isDoubles ifTrue:[^ 8]. |
|
4045 |
||
4046 |
^ 0 |
|
4047 |
||
4048 |
! |
|
6727 | 4049 |
|
15948 | 4050 |
isAlienBehavior |
4051 |
"Returns true iff I'm an alien behavior." |
|
4052 |
%{ |
|
4053 |
RETURN( ( (INT)(__INST(flags)) & __MASKSMALLINT(ALIENPOINTERS)) ? true : false ) |
|
4054 |
%}. |
|
4055 |
||
4056 |
! |
|
4057 |
||
6727 | 4058 |
isBits |
4059 |
"return true, if instances have indexed byte or short instance variables. |
|
4060 |
Ignore long, float and double arrays, since ST-80 code using isBits are probably |
|
4061 |
not prepared to handle them correctly." |
|
4062 |
||
4063 |
%{ /* NOCONTEXT */ |
|
4064 |
||
4065 |
REGISTER int what; |
|
4066 |
||
4067 |
what = (INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK); |
|
4068 |
RETURN (( (what == __MASKSMALLINT(BYTEARRAY)) |
|
16050 | 4069 |
|| (what == __MASKSMALLINT(WORDARRAY))) ? true : false ); |
6727 | 4070 |
%}. |
9194 | 4071 |
^ self isBytes or:[self isWords] |
4072 |
! |
|
4073 |
||
4074 |
isBitsExtended |
|
4075 |
"return true, if instances have indexed byte, short, long or longlong instance variables. |
|
4076 |
Ignore float and double arrays. |
|
4077 |
This is really the thing we expect #isBits to return, however, #isBits |
|
4078 |
is defined to only return true for byte- and wordIndexed instances. |
|
4079 |
This avoids confusion of ST80 code, which is not prepared for long or longLong |
|
4080 |
instVars." |
|
4081 |
||
4082 |
%{ /* NOCONTEXT */ |
|
4083 |
||
4084 |
REGISTER int what; |
|
4085 |
||
4086 |
what = (INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK); |
|
6727 | 4087 |
RETURN (( (what == __MASKSMALLINT(BYTEARRAY)) |
16050 | 4088 |
|| (what == __MASKSMALLINT(WORDARRAY)) |
4089 |
|| (what == __MASKSMALLINT(SWORDARRAY)) |
|
4090 |
|| (what == __MASKSMALLINT(LONGARRAY)) |
|
4091 |
|| (what == __MASKSMALLINT(SLONGARRAY)) |
|
4092 |
|| (what == __MASKSMALLINT(LONGLONGARRAY)) |
|
4093 |
|| (what == __MASKSMALLINT(SLONGLONGARRAY))) ? true : false ); |
|
6727 | 4094 |
%} |
4095 |
! |
|
4096 |
||
4097 |
isBytes |
|
4098 |
"return true, if instances have indexed byte instance variables" |
|
4099 |
||
4100 |
"this could also be defined as: |
|
16050 | 4101 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagBytes |
6727 | 4102 |
" |
4103 |
%{ /* NOCONTEXT */ |
|
4104 |
||
12094 | 4105 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(BYTEARRAY)) ? true : false ); |
6727 | 4106 |
%} |
4107 |
! |
|
4108 |
||
4109 |
isDoubles |
|
4110 |
"return true, if instances have indexed double instance variables" |
|
4111 |
||
4112 |
"this could also be defined as: |
|
16050 | 4113 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagDoubles |
6727 | 4114 |
" |
4115 |
%{ /* NOCONTEXT */ |
|
4116 |
||
12094 | 4117 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(DOUBLEARRAY)) ? true : false ); |
9194 | 4118 |
%} |
4119 |
! |
|
6727 | 4120 |
|
4121 |
isFixed |
|
4122 |
"return true, if instances do not have indexed instance variables" |
|
4123 |
||
4124 |
"this could also be defined as: |
|
16050 | 4125 |
^ self isVariable not |
6727 | 4126 |
" |
4127 |
||
4128 |
%{ /* NOCONTEXT */ |
|
4129 |
||
12094 | 4130 |
RETURN ( ((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) ? false : true ); |
6727 | 4131 |
%}. |
4132 |
^ self isVariable not |
|
4133 |
! |
|
4134 |
||
4135 |
isFloats |
|
9194 | 4136 |
"return true, if instances have indexed float instance variables" |
6727 | 4137 |
|
4138 |
"this could also be defined as: |
|
16050 | 4139 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagFloats |
6727 | 4140 |
" |
9194 | 4141 |
%{ /* NOCONTEXT */ |
4142 |
||
12094 | 4143 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(FLOATARRAY)) ? true : false ); |
9194 | 4144 |
%} |
4145 |
! |
|
4146 |
||
4147 |
isFloatsOrDoubles |
|
4148 |
"return true, if instances have indexed float or double instance variables" |
|
4149 |
||
4150 |
%{ /* NOCONTEXT */ |
|
4151 |
||
4152 |
int what; |
|
4153 |
||
4154 |
what = (INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK); |
|
4155 |
RETURN (( (what == __MASKSMALLINT(FLOATARRAY)) |
|
16050 | 4156 |
|| (what == __MASKSMALLINT(DOUBLEARRAY))) ? true : false ); |
9194 | 4157 |
%}. |
4158 |
^ self isFloats or:[self isDoubles] |
|
4159 |
||
4160 |
" |
|
12094 | 4161 |
(Object new) class isFloatsOrDoubles |
4162 |
(Point new) class isFloatsOrDoubles |
|
4163 |
(Array new) class isFloatsOrDoubles |
|
4164 |
(ByteArray new) class isFloatsOrDoubles |
|
4165 |
(FloatArray new) class isFloatsOrDoubles |
|
4166 |
(DoubleArray new) class isFloatsOrDoubles |
|
6727 | 4167 |
" |
4168 |
! |
|
4169 |
||
4170 |
isLongLongs |
|
4171 |
"return true, if instances have indexed long-long instance variables (8 byte uints)" |
|
4172 |
||
4173 |
%{ /* NOCONTEXT */ |
|
4174 |
||
4175 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(LONGLONGARRAY)) ? true : false ); |
|
4176 |
%} |
|
4177 |
! |
|
4178 |
||
4179 |
isLongs |
|
9194 | 4180 |
"return true, if instances have indexed long instance variables (4 byte uints)" |
4181 |
||
4182 |
%{ /* NOCONTEXT */ |
|
4183 |
||
12094 | 4184 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(LONGARRAY)) ? true : false ); |
9194 | 4185 |
%} |
4186 |
! |
|
4187 |
||
4188 |
isPointers |
|
12094 | 4189 |
"return true, if instances have pointer instance variables |
9194 | 4190 |
i.e. are either non-indexed or have indexed pointer variables" |
4191 |
||
4192 |
"QUESTION: should we ignore WeakPointers ?" |
|
6727 | 4193 |
|
4194 |
%{ /* NOCONTEXT */ |
|
4195 |
||
9194 | 4196 |
REGISTER int flags; |
4197 |
||
4198 |
flags = __intVal(__INST(flags)) & ARRAYMASK; |
|
4199 |
switch (flags) { |
|
16050 | 4200 |
default: |
4201 |
/* normal objects */ |
|
4202 |
RETURN ( true ); |
|
4203 |
||
4204 |
case BYTEARRAY: |
|
4205 |
case WORDARRAY: |
|
4206 |
case LONGARRAY: |
|
4207 |
case SWORDARRAY: |
|
4208 |
case SLONGARRAY: |
|
4209 |
case SLONGLONGARRAY: |
|
4210 |
case LONGLONGARRAY: |
|
4211 |
case FLOATARRAY: |
|
4212 |
case DOUBLEARRAY: |
|
4213 |
RETURN (false ); |
|
4214 |
||
4215 |
case WKPOINTERARRAY: |
|
4216 |
/* what about those ? */ |
|
4217 |
RETURN (true ); |
|
6727 | 4218 |
} |
4219 |
%} |
|
4220 |
! |
|
4221 |
||
4222 |
isSignedLongLongs |
|
4223 |
"return true, if instances have indexed signed long-long instance variables (8 byte ints)" |
|
4224 |
||
4225 |
%{ /* NOCONTEXT */ |
|
4226 |
||
4227 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(SLONGLONGARRAY)) ? true : false ); |
|
4228 |
%} |
|
4229 |
! |
|
4230 |
||
4231 |
isSignedLongs |
|
9194 | 4232 |
"return true, if instances have indexed signed long instance variables (4 byte ints)" |
4233 |
||
4234 |
%{ /* NOCONTEXT */ |
|
4235 |
||
4236 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(SLONGARRAY)) ? true : false ); |
|
4237 |
%} |
|
4238 |
! |
|
6727 | 4239 |
|
4240 |
isSignedWords |
|
4241 |
"return true, if instances have indexed signed short instance variables" |
|
4242 |
||
4243 |
%{ /* NOCONTEXT */ |
|
4244 |
||
4245 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(SWORDARRAY)) ? true : false ); |
|
4246 |
%} |
|
4247 |
! |
|
4248 |
||
4249 |
isVariable |
|
4250 |
"return true, if instances have indexed instance variables" |
|
4251 |
||
4252 |
"this could also be defined as: |
|
16050 | 4253 |
^ (flags bitAnd:(Behavior maskIndexType)) ~~ 0 |
9194 | 4254 |
" |
4255 |
||
4256 |
%{ /* NOCONTEXT */ |
|
4257 |
||
12094 | 4258 |
RETURN ( ((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) ? true : false ); |
9194 | 4259 |
%} |
4260 |
! |
|
6727 | 4261 |
|
4262 |
isWeakPointers |
|
4263 |
"return true, if instances have weak pointer instance variables" |
|
4264 |
||
4265 |
%{ /* NOCONTEXT */ |
|
4266 |
||
4267 |
REGISTER int flags; |
|
4268 |
||
4269 |
flags = __intVal(__INST(flags)) & ARRAYMASK; |
|
4270 |
if (flags == WKPOINTERARRAY) { |
|
16050 | 4271 |
RETURN ( true ); |
6727 | 4272 |
} |
4273 |
%}. |
|
4274 |
^ false |
|
4275 |
! |
|
4276 |
||
4277 |
isWords |
|
4278 |
"return true, if instances have indexed short instance variables" |
|
4279 |
||
4280 |
"this could also be defined as: |
|
16050 | 4281 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagWords |
9194 | 4282 |
" |
4283 |
%{ /* NOCONTEXT */ |
|
4284 |
||
12094 | 4285 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(WORDARRAY)) ? true : false ); |
6727 | 4286 |
%} |
9194 | 4287 |
! |
4288 |
||
4289 |
sizeOfInst:n |
|
6727 | 4290 |
"return the number of bytes required for an instance of |
12094 | 4291 |
myself with n indexed instance variables. The argument n |
6727 | 4292 |
should be zero for classes without indexed instance variables. |
4293 |
See Behavior>>niceNew: for an application of this." |
|
4294 |
||
4295 |
|nInstvars| |
|
4296 |
||
4297 |
nInstvars := self instSize. |
|
4298 |
%{ |
|
15986 | 4299 |
INT nBytes = __intVal(nInstvars) * sizeof(OBJ) + OHDR_SIZE; |
6727 | 4300 |
if (__isSmallInteger(n)) { |
15986 | 4301 |
int nIndex; |
4302 |
||
4303 |
nIndex = __intVal(n); |
|
4304 |
switch (__intVal(__INST(flags)) & ARRAYMASK) { |
|
4305 |
case BYTEARRAY: |
|
4306 |
nBytes += nIndex; |
|
4307 |
if (nBytes & (__ALIGN__ - 1)) { |
|
4308 |
nBytes = (nBytes & ~(__ALIGN__ - 1)) + __ALIGN__; |
|
4309 |
} |
|
4310 |
break; |
|
4311 |
||
4312 |
case WORDARRAY: |
|
4313 |
case SWORDARRAY: |
|
4314 |
nBytes += nIndex * 2; |
|
4315 |
if (nBytes & (__ALIGN__ - 1)) { |
|
4316 |
nBytes = (nBytes & ~(__ALIGN__ - 1)) + __ALIGN__; |
|
4317 |
} |
|
4318 |
break; |
|
4319 |
||
4320 |
case LONGARRAY: |
|
4321 |
case SLONGARRAY: |
|
4322 |
nBytes += nIndex * 4; |
|
4323 |
break; |
|
4324 |
||
4325 |
case LONGLONGARRAY: |
|
4326 |
case SLONGLONGARRAY: |
|
4327 |
nBytes += nIndex * 8; |
|
4328 |
#ifdef __NEED_LONGLONG_ALIGN |
|
4329 |
nBytes = (nBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
|
4330 |
#endif |
|
4331 |
break; |
|
4332 |
||
4333 |
case FLOATARRAY: |
|
4334 |
nBytes += nIndex * sizeof(float); |
|
4335 |
break; |
|
4336 |
||
4337 |
case DOUBLEARRAY: |
|
4338 |
nBytes += nIndex * sizeof(double); |
|
4339 |
#ifdef __NEED_DOUBLE_ALIGN |
|
4340 |
nBytes = (nBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
|
4341 |
#endif |
|
4342 |
break; |
|
4343 |
||
4344 |
default: |
|
4345 |
nBytes += nIndex * sizeof(OBJ); |
|
4346 |
break; |
|
4347 |
} |
|
9194 | 4348 |
} |
4349 |
RETURN (__mkSmallInteger(nBytes)); |
|
4350 |
%} |
|
15986 | 4351 |
|
4352 |
" |
|
4353 |
DoubleArray sizeOfInst:8 |
|
4354 |
IntegerArray sizeOfInst:8 |
|
4355 |
" |
|
9194 | 4356 |
! ! |
4357 |
||
4358 |
!Behavior methodsFor:'queries-protocol'! |
|
6727 | 4359 |
|
4360 |
allSelectors |
|
4361 |
"return a collection of all selectors understood by the receiver; |
|
4362 |
this includes my selectors and all superclass selectors |
|
4363 |
(i.e. the receivers full protocol)" |
|
4364 |
||
4365 |
|superclass| |
|
4366 |
||
4367 |
superclass := self superclass. |
|
4368 |
superclass notNil ifTrue:[ |
|
16050 | 4369 |
^ superclass allSelectors addAll:(self selectors); yourself. |
6727 | 4370 |
]. |
15027 | 4371 |
^ self selectors asNewIdentitySet |
6727 | 4372 |
|
4373 |
" |
|
4374 |
Point allSelectors |
|
4375 |
View allSelectors |
|
9194 | 4376 |
Array allSelectors |
4377 |
" |
|
4378 |
! |
|
4379 |
||
4380 |
cachedLookupMethodFor:aSelector |
|
4381 |
"return the method, which would be executed if aSelector was sent to |
|
4382 |
an instance of the receiver. I.e. the selector arrays of the receiver |
|
4383 |
and all of its superclasses are searched for aSelector. |
|
4384 |
Return the method, or nil if instances do not understand aSelector. |
|
4385 |
This interface provides exactly the same information as #lookupMethodFor:, |
|
12094 | 4386 |
but uses the lookup-cache in the VM for faster search. |
9194 | 4387 |
However, keep in mind, that doing a lookup through the cache also adds new |
12094 | 4388 |
entries and can thus slow down the system by polluting the cache with |
6727 | 4389 |
irrelevant entries. (do NOT loop over all objects calling this method). |
4390 |
Does NOT (currently) handle MI" |
|
4391 |
||
4392 |
%{ /* NOCONTEXT */ |
|
4393 |
RETURN ( __lookup(self, aSelector) ); |
|
4394 |
%} |
|
4395 |
||
4396 |
" |
|
4397 |
String cachedLookupMethodFor:#= |
|
4398 |
String cachedLookupMethodFor:#asOrderedCollection |
|
4399 |
" |
|
4400 |
! |
|
4401 |
||
4402 |
canUnderstand:aSelector |
|
9194 | 4403 |
"return true, if the receiver or one of its superclasses implements aSelector. |
15744 | 4404 |
(i.e. true if my instances understand aSelector). |
4405 |
I think this is a bad name, but well, we are compatible." |
|
9194 | 4406 |
|
4407 |
^ (self lookupMethodFor:aSelector) notNil |
|
4408 |
||
4409 |
" |
|
4410 |
True canUnderstand:#ifTrue: |
|
4411 |
True canUnderstand:#== |
|
4412 |
True canUnderstand:#do: |
|
4413 |
" |
|
4414 |
! |
|
6727 | 4415 |
|
4416 |
compiledMethodAt:aSelector |
|
4417 |
"return the method for given selector aSelector or nil. |
|
4418 |
Only methods in the receiver - not in the superclass chain are tested." |
|
4419 |
||
4420 |
^ self compiledMethodAt:aSelector ifAbsent:nil |
|
4421 |
||
4422 |
" |
|
4423 |
Object compiledMethodAt:#== |
|
4424 |
(Object compiledMethodAt:#==) category |
|
4425 |
" |
|
4426 |
||
4427 |
"Modified: / 7.6.1996 / 14:43:32 / stefan" |
|
4428 |
"Modified: / 27.10.1997 / 20:18:55 / cg" |
|
4429 |
! |
|
4430 |
||
4431 |
compiledMethodAt:aSelector ifAbsent:exceptionValue |
|
4432 |
"return the method for given selector aSelector or the value |
|
4433 |
of exceptionValue if not present. |
|
4434 |
Only methods in the receiver - not in the superclass chain are tested." |
|
4435 |
||
4436 |
|dict| |
|
4437 |
||
4438 |
dict := self methodDictionary. |
|
4439 |
dict isNil ifTrue:[ |
|
16050 | 4440 |
('Behavior [warning]: nil methodDictionary in ' , self name printString) errorPrintCR. |
4441 |
^ exceptionValue value |
|
6727 | 4442 |
]. |
4443 |
||
4444 |
^ dict at:aSelector ifAbsent:exceptionValue |
|
4445 |
||
4446 |
" |
|
4447 |
Object compiledMethodAt:#== |
|
4448 |
(Object compiledMethodAt:#==) category |
|
4449 |
" |
|
4450 |
||
4451 |
"Modified: / 7.6.1996 / 14:43:32 / stefan" |
|
4452 |
"Modified: / 10.1.1997 / 17:27:21 / cg" |
|
4453 |
"Created: / 27.10.1997 / 20:18:28 / cg" |
|
9194 | 4454 |
! |
4455 |
||
13414 | 4456 |
compiledMethodNamed: methodName |
4457 |
"Warning: this method is here to support multiple languages. |
|
4458 |
Do not use in code that works just with the smalltalk code. |
|
4459 |
Use compiledMethodAt: selector instead" |
|
4460 |
||
4461 |
"Returns a method with given name. This differs from |
|
4462 |
#compiledMethodAt:, since class may contain more methods |
|
4463 |
with same names and different selectors. |
|
4464 |
||
4465 |
Only methods in the receiver - not in the superclass chain are tested." |
|
4466 |
||
4467 |
^ self compiledMethodNamed:methodName ifAbsent:nil |
|
4468 |
||
4469 |
" |
|
4470 |
Object compiledMethodNamed:#== |
|
4471 |
(Object compiledMethodNamed:#==) category |
|
4472 |
" |
|
4473 |
||
4474 |
"Created: / 24-08-2009 / 10:00:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4475 |
"Modified: / 28-06-2011 / 14:16:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4476 |
! |
|
4477 |
||
4478 |
compiledMethodNamed: name ifAbsent:exceptionValue |
|
4479 |
"Warning: this method is here to support multiple languages. |
|
4480 |
Do not use in code that works just with the smalltalk code. |
|
4481 |
Use compiledMethodAt: selector instead" |
|
4482 |
||
4483 |
"Returns a method with given name of value of exceptionValue |
|
13419 | 4484 |
if not present. This differs from #compiledMethodAt:, since class |
13414 | 4485 |
may contain more methods with same name and different selectors. |
4486 |
||
4487 |
Only methods in the receiver - not in the superclass chain are tested." |
|
4488 |
||
4489 |
|dict mth| |
|
4490 |
||
4491 |
dict := self methodDictionary. |
|
4492 |
dict isNil ifTrue:[ |
|
16050 | 4493 |
('Behavior [warning]: nil methodDictionary in ' , self name printString) errorPrintCR. |
4494 |
^ exceptionValue value |
|
13414 | 4495 |
]. |
13419 | 4496 |
"Quick check: look into method dictionary" |
13414 | 4497 |
mth := dict at: name asSymbol ifAbsent:nil. |
13838
1d91d75691f0
changed: #compiledMethodNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13600
diff
changeset
|
4498 |
mth notNil ifTrue:[^mth]. |
13414 | 4499 |
|
4500 |
"Slow search..." |
|
13838
1d91d75691f0
changed: #compiledMethodNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13600
diff
changeset
|
4501 |
dict do: [:each| |
16050 | 4502 |
(each isSynthetic not and:[each name = name]) |
4503 |
ifTrue:[^each] |
|
13838
1d91d75691f0
changed: #compiledMethodNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13600
diff
changeset
|
4504 |
]. |
13414 | 4505 |
^exceptionValue value |
13419 | 4506 |
|
13414 | 4507 |
|
4508 |
" |
|
4509 |
Object compiledMethodNamed:#== |
|
4510 |
(Object compiledMethodNamed:#==) category |
|
4511 |
" |
|
4512 |
||
4513 |
"Created: / 24-08-2009 / 10:02:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4514 |
"Modified: / 28-06-2011 / 14:16:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
13838
1d91d75691f0
changed: #compiledMethodNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
13600
diff
changeset
|
4515 |
"Modified (format): / 29-11-2011 / 11:20:08 / cg" |
13414 | 4516 |
! |
4517 |
||
9194 | 4518 |
containsMethod:aMethod |
4519 |
"Return true, if the argument, aMethod is a method of myself" |
|
4520 |
||
4521 |
|dict| |
|
4522 |
||
12094 | 4523 |
dict := self methodDictionary. |
9194 | 4524 |
dict isNil ifTrue:[^ false]. "degenerated class" |
4525 |
^ (dict keyAtValue:aMethod ifAbsent:[0]) ~~ 0 |
|
4526 |
||
4527 |
"Modified: 12.6.1996 / 13:33:53 / stefan" |
|
4528 |
! |
|
6727 | 4529 |
|
620 | 4530 |
hasMethods |
4531 |
"return true, if there are any (local) methods in this class" |
|
4532 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4533 |
^ (self methodDictionary size ~~ 0) |
620 | 4534 |
|
293 | 4535 |
" |
620 | 4536 |
True hasMethods |
4537 |
True class hasMethods |
|
4538 |
" |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4539 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4540 |
"Modified: 7.6.1996 / 15:43:09 / stefan" |
620 | 4541 |
! |
4542 |
||
4543 |
implements:aSelector |
|
4544 |
"return true, if the receiver implements aSelector. |
|
4545 |
(i.e. implemented in THIS class - NOT in a superclass). |
|
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4546 |
This is semantically equivalent to includesSelector: (which is ST/80/Squeak compatibility). |
983 | 4547 |
|
4548 |
Caveat: |
|
16050 | 4549 |
This simply checks for the selector being present in the classes |
4550 |
selector table - therefore, it does not care for ignoredMethods. |
|
4551 |
(but: you should not use this method for protocol-testing, anyway). |
|
983 | 4552 |
|
4553 |
Hint: |
|
16050 | 4554 |
Dont use this method to check if someone responds to a message - |
4555 |
use #canUnderstand: on the class or #respondsTo: on the instance |
|
4556 |
to do this." |
|
983 | 4557 |
|
4558 |
^ self includesSelector:aSelector |
|
620 | 4559 |
|
4560 |
" |
|
983 | 4561 |
notice: this is class protocol |
4562 |
||
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4563 |
True includesSelector:#ifTrue: |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4564 |
True includesSelector:#== |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4565 |
|
12094 | 4566 |
True implements:#ifTrue: |
4567 |
True implements:#== |
|
983 | 4568 |
|
4569 |
notice: this is instance protocol |
|
4570 |
||
12094 | 4571 |
true respondsTo:#ifTrue: |
4572 |
true respondsTo:#== |
|
983 | 4573 |
|
4574 |
notice: this is class protocol |
|
4575 |
||
12094 | 4576 |
True canUnderstand:#ifTrue: |
4577 |
True canUnderstand:#== |
|
620 | 4578 |
" |
983 | 4579 |
|
4580 |
"Modified: 10.2.1996 / 13:15:56 / cg" |
|
620 | 4581 |
! |
4582 |
||
9194 | 4583 |
includesSelector:aSelector |
9219 | 4584 |
"return true, if the methodDictionary of THIS class includes a method for aSelector. |
983 | 4585 |
(i.e. if aSelector is implemented in THIS class - NOT in a superclass). |
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4586 |
This is semantically equivalent to implements: (ST/80/Squeak compatibility). |
983 | 4587 |
|
4588 |
Hint: |
|
16050 | 4589 |
Don't use this method to check if someone responds to a message - |
4590 |
use #canUnderstand: on the class or #respondsTo: on the instance |
|
4591 |
to do this. |
|
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4592 |
|
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4593 |
Caveat: |
16050 | 4594 |
This simply checks for the selector being present in the classes |
4595 |
selector table - therefore, it does not care for ignoredMethods. |
|
4596 |
(but: you should not use this method for protocol-testing, anyway)." |
|
4307 | 4597 |
|
10534 | 4598 |
^ self methodDictionary includesIdenticalKey:aSelector |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4599 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4600 |
" |
9219 | 4601 |
Object includesSelector:#== |
4602 |
Object includesSelector:#murks |
|
13372
d2e9922a9791
comment/format in: #includesSelector:
Stefan Vogel <sv@exept.de>
parents:
13318
diff
changeset
|
4603 |
Object includesSelector:nil |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4604 |
" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4605 |
|
3882 | 4606 |
"Modified: / 7.6.1996 / 14:27:24 / stefan" |
4607 |
"Modified: / 16.10.1998 / 13:00:15 / cg" |
|
9194 | 4608 |
! |
4609 |
||
10085 | 4610 |
instAndClassMethods |
4611 |
^ (self theMetaclass methodDictionary values) , (self theNonMetaclass methodDictionary values) |
|
4612 |
||
4613 |
"Created: / 12-10-2006 / 18:36:57 / cg" |
|
4614 |
"Modified: / 12-10-2006 / 20:36:34 / cg" |
|
4615 |
! |
|
4616 |
||
9194 | 4617 |
lookupMethodFor:aSelector |
620 | 4618 |
"return the method, which would be executed if aSelector was sent to |
4619 |
an instance of the receiver. I.e. the selector arrays of the receiver |
|
4620 |
and all of its superclasses are searched for aSelector. |
|
4621 |
Return the method, or nil if instances do not understand aSelector. |
|
4622 |
EXPERIMENTAL: take care of multiple superclasses." |
|
4623 |
||
13419 | 4624 |
|l m cls| |
4625 |
||
4626 |
"JV @ 2010-08-22: Rewritten to respect lookup object." |
|
4627 |
(l := self lookupObject) notNil ifTrue:[ |
|
16050 | 4628 |
^ (l |
4629 |
lookupMethodForSelector:aSelector |
|
4630 |
directedTo:self |
|
4631 |
for: nil "Fake receiver" |
|
4632 |
withArguments: nil "Fake arguments" |
|
4633 |
from: thisContext methodHome sender |
|
4634 |
ilc: nil "fake ilc") |
|
13419 | 4635 |
]. |
620 | 4636 |
|
4637 |
cls := self. |
|
15785 | 4638 |
[ |
16050 | 4639 |
m := cls compiledMethodAt:aSelector. |
4640 |
m notNil ifTrue:[^ m]. |
|
4641 |
cls hasMultipleSuperclasses ifTrue:[ |
|
4642 |
cls superclasses do:[:aSuperClass | |
|
4643 |
m := aSuperClass lookupMethodFor:aSelector. |
|
4644 |
m notNil ifTrue:[^ m]. |
|
4645 |
]. |
|
4646 |
^ nil |
|
4647 |
] ifFalse:[ |
|
4648 |
cls := cls superclass |
|
4649 |
] |
|
15785 | 4650 |
] doWhile:[cls notNil]. |
620 | 4651 |
^ nil |
4652 |
! |
|
4653 |
||
6460 | 4654 |
responseTo:aSelector |
12094 | 4655 |
"return the method (from here or the inheritance chain), |
6460 | 4656 |
which implements aSelector; return nil if none." |
4657 |
||
4658 |
|cls| |
|
4659 |
||
4660 |
cls := self whichClassIncludesSelector:aSelector. |
|
4661 |
cls notNil ifTrue:[ |
|
16050 | 4662 |
^ cls compiledMethodAt:aSelector |
6460 | 4663 |
]. |
4664 |
^ nil |
|
4665 |
||
4666 |
" |
|
12094 | 4667 |
String responseTo:#== |
4668 |
String responseTo:#collect: |
|
4669 |
String responseTo:#, |
|
6460 | 4670 |
" |
4671 |
! |
|
4672 |
||
9194 | 4673 |
selectorAtMethod:aMethod |
4674 |
"Return the selector for given method aMethod." |
|
4675 |
||
4676 |
^ self selectorAtMethod:aMethod ifAbsent:[nil] |
|
4677 |
||
620 | 4678 |
" |
9194 | 4679 |
|m| |
4680 |
||
4681 |
m := Object compiledMethodAt:#copy. |
|
4682 |
Fraction selectorAtMethod:m. |
|
4683 |
" |
|
4684 |
" |
|
4685 |
|m| |
|
4686 |
||
4687 |
m := Object compiledMethodAt:#copy. |
|
4688 |
Object selectorAtMethod:m. |
|
4689 |
" |
|
356 | 4690 |
! |
4691 |
||
9194 | 4692 |
selectorAtMethod:aMethod ifAbsent:failBlock |
620 | 4693 |
"return the selector for given method aMethod |
4694 |
or the value of failBlock, if not found." |
|
4695 |
||
1814 | 4696 |
|md| |
4697 |
||
4698 |
md := self methodDictionary. |
|
4699 |
md isNil ifTrue:[ |
|
16050 | 4700 |
'OOPS - nil methodDictionary' errorPrintCR. |
16280 | 4701 |
^ failBlock value. |
1814 | 4702 |
]. |
4703 |
^ md keyAtValue:aMethod ifAbsent:failBlock. |
|
216 | 4704 |
|
4705 |
" |
|
620 | 4706 |
|m| |
4707 |
||
4708 |
m := Object compiledMethodAt:#copy. |
|
4709 |
Object selectorAtMethod:m ifAbsent:['oops']. |
|
4710 |
" |
|
216 | 4711 |
" |
620 | 4712 |
|m| |
4713 |
||
4714 |
m := Object compiledMethodAt:#copy. |
|
4715 |
Fraction selectorAtMethod:m ifAbsent:['oops']. |
|
216 | 4716 |
" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4717 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4718 |
"Modified: 7.6.1996 / 15:15:45 / stefan" |
216 | 4719 |
! |
4720 |
||
2 | 4721 |
whichClassImplements:aSelector |
328 | 4722 |
"obsolete interface; |
4723 |
use whichClassIncludesSelector: for ST-80 compatibility." |
|
4724 |
||
9363 | 4725 |
<resource:#obsolete> |
4726 |
||
328 | 4727 |
^ self whichClassIncludesSelector:aSelector |
4728 |
! |
|
4729 |
||
4730 |
whichClassIncludesSelector:aSelector |
|
68 | 4731 |
"return the class in the inheritance chain, which implements the method |
4732 |
for aSelector; return nil if none. |
|
4733 |
EXPERIMENTAL: handle multiple superclasses" |
|
4734 |
||
4735 |
|cls| |
|
2 | 4736 |
|
68 | 4737 |
cls := self. |
4738 |
[cls notNil] whileTrue:[ |
|
16050 | 4739 |
(cls includesSelector:aSelector) ifTrue:[^ cls]. |
4740 |
cls hasMultipleSuperclasses ifTrue:[ |
|
4741 |
cls superclasses do:[:aSuperClass | |
|
4742 |
|implementingClass| |
|
4743 |
||
4744 |
implementingClass := aSuperClass whichClassIncludesSelector:aSelector. |
|
4745 |
implementingClass notNil ifTrue:[^ implementingClass]. |
|
4746 |
]. |
|
4747 |
^ nil |
|
4748 |
] ifFalse:[ |
|
4749 |
cls := cls superclass |
|
4750 |
] |
|
2 | 4751 |
]. |
4752 |
^ nil |
|
4753 |
||
91 | 4754 |
" |
328 | 4755 |
String whichClassIncludesSelector:#== |
4756 |
String whichClassIncludesSelector:#collect: |
|
91 | 4757 |
" |
6727 | 4758 |
! ! |
4759 |
||
6931 | 4760 |
!Behavior methodsFor:'queries-variables'! |
6727 | 4761 |
|
4762 |
allClassVarNames |
|
4763 |
"return a collection of all the class variable name-strings |
|
4764 |
this includes all superclass-class variables" |
|
4765 |
||
4766 |
^ self addAllClassVarNamesTo:(OrderedCollection new) |
|
4767 |
||
4768 |
" |
|
4769 |
Float allClassVarNames |
|
4770 |
" |
|
4771 |
||
4772 |
"Modified: 16.4.1996 / 18:01:00 / cg" |
|
4773 |
! |
|
4774 |
||
4775 |
allInstVarNames |
|
4776 |
"return a collection of all the instance variable name-strings |
|
4777 |
this includes all superclass-instance variables. |
|
4778 |
Instvars of superclasses come first (i.e. the position matches |
|
4779 |
the instVarAt:-index)." |
|
4780 |
||
4781 |
self superclass isNil ifTrue:[^ self instVarNames]. |
|
4782 |
^ self addAllInstVarNamesTo:(OrderedCollection new) |
|
4783 |
||
4784 |
" |
|
12094 | 4785 |
Dictionary instVarNames |
4786 |
Dictionary allInstVarNames |
|
6727 | 4787 |
" |
4788 |
||
4789 |
"Modified: 16.4.1996 / 18:03:55 / cg" |
|
4790 |
! |
|
4791 |
||
4792 |
allInstanceVariableNames |
|
4793 |
"alias for allInstVarNames" |
|
4794 |
||
4795 |
^ self allInstVarNames |
|
4796 |
! |
|
4797 |
||
4798 |
classVarNames |
|
4799 |
"return a collection of the class variable name-strings. |
|
4800 |
Returning empty here, since Behavior does not define any classVariables. |
|
4801 |
(only Classes do). This allows different Behavior-like objects |
|
16042 | 4802 |
(alien classes) to be handled by the browser as well. |
4803 |
Traditionally, this was called classVarNames, but newer versions of squeak |
|
4804 |
seem to have changed to use classVariableNames. |
|
4805 |
So you probably should use the alias" |
|
6727 | 4806 |
|
4807 |
^ #() |
|
4808 |
||
4809 |
"Created: 16.4.1996 / 17:57:31 / cg" |
|
4810 |
! |
|
4811 |
||
16042 | 4812 |
classVariableNames |
4813 |
"alias for classVarNames. |
|
4814 |
Traditionally, this was called classVarNames, but newer versions of squeak |
|
4815 |
seem to have changed to use classVariableNames. |
|
4816 |
So you probably should use this alias" |
|
4817 |
||
4818 |
^ self classVarNames |
|
4819 |
||
4820 |
" |
|
4821 |
Infinity classVariableNames |
|
4822 |
" |
|
4823 |
! |
|
4824 |
||
6727 | 4825 |
classVariableString |
4826 |
"return a string of the class variables names. |
|
4827 |
Returning empty here, since Behavior does not define any classVariables. |
|
4828 |
(only Classes do). This allows different Behavior-like objects |
|
4829 |
(alien classes) to be handled by the browser as well." |
|
4830 |
||
4831 |
^ '' |
|
4832 |
||
4833 |
"Created: 16.4.1996 / 16:28:56 / cg" |
|
4834 |
! |
|
4835 |
||
9445 | 4836 |
instVarNameForIndex:index |
4837 |
"Behavior does not provide this info - generate synthetic names." |
|
4838 |
||
4839 |
^ '* instVar' , index printString , ' *' |
|
4840 |
||
4841 |
"Created: / 17-07-2006 / 00:28:24 / cg" |
|
4842 |
! |
|
4843 |
||
6727 | 4844 |
instVarNames |
15667 | 4845 |
"return a collection of the instance variable name-strings. |
16042 | 4846 |
Behavior does not provide this info - generate synthetic names. |
4847 |
Traditionally, this was called instVarNames, but newer versions of squeak |
|
4848 |
seem to have changed to use instanceVariableNames. |
|
4849 |
So you probably should use the alias" |
|
6727 | 4850 |
|
4851 |
|superclass superInsts| |
|
4852 |
||
4853 |
superclass := self superclass. |
|
4854 |
superclass isNil ifTrue:[ |
|
15667 | 4855 |
superInsts := 0 |
6727 | 4856 |
] ifFalse:[ |
15667 | 4857 |
superInsts := superclass instSize |
6727 | 4858 |
]. |
12094 | 4859 |
^ (superInsts+1 to:self instSize) |
15667 | 4860 |
collect:[:index | self instVarNameForIndex:index] |
9445 | 4861 |
|
4862 |
"Modified: / 17-07-2006 / 00:28:40 / cg" |
|
6727 | 4863 |
! |
4864 |
||
4865 |
instanceVariableNames |
|
16042 | 4866 |
"alias for instVarNames. |
4867 |
Traditionally, this was called instVarNames, but newer versions of squeak |
|
4868 |
seem to have changed to use instanceVariableNames. |
|
4869 |
So you probably should use this alias" |
|
6727 | 4870 |
|
4871 |
^ self instVarNames |
|
12794
ccfaa18fac96
comment/format in: #instanceVariableNames
Claus Gittinger <cg@exept.de>
parents:
12359
diff
changeset
|
4872 |
|
ccfaa18fac96
comment/format in: #instanceVariableNames
Claus Gittinger <cg@exept.de>
parents:
12359
diff
changeset
|
4873 |
" |
ccfaa18fac96
comment/format in: #instanceVariableNames
Claus Gittinger <cg@exept.de>
parents:
12359
diff
changeset
|
4874 |
Point instanceVariableNames |
ccfaa18fac96
comment/format in: #instanceVariableNames
Claus Gittinger <cg@exept.de>
parents:
12359
diff
changeset
|
4875 |
" |
6727 | 4876 |
! |
4877 |
||
4878 |
instanceVariableString |
|
4879 |
"return a string with dummy names here - typically, your |
|
8857 | 4880 |
objects are instances of Class, not Behavior, |
4881 |
so this is only invoked for very artificial behaviors." |
|
4882 |
||
4883 |
|superclass s superInsts first n "{Class: SmallInteger }"| |
|
6727 | 4884 |
|
4885 |
superclass := self superclass. |
|
4886 |
s := ''. |
|
4887 |
superclass isNil ifTrue:[ |
|
16050 | 4888 |
superInsts := 0 |
6727 | 4889 |
] ifFalse:[ |
16050 | 4890 |
superInsts := superclass instSize |
6727 | 4891 |
]. |
4892 |
n := self instSize. |
|
8857 | 4893 |
first := true. |
6727 | 4894 |
superInsts+1 to:n do:[:i | |
16050 | 4895 |
first ifFalse:[s := s , ' '] ifTrue:[first := false]. |
4896 |
||
4897 |
s := s , 'instvar' , i printString |
|
6727 | 4898 |
]. |
4899 |
^ s |
|
4900 |
||
4901 |
" |
|
12094 | 4902 |
Behavior new instanceVariableString |
4903 |
(Behavior new instSize:2) instanceVariableString |
|
6727 | 4904 |
" |
4905 |
||
4906 |
"Modified: 7.5.1996 / 12:50:25 / cg" |
|
4907 |
"Modified: 3.6.1996 / 16:03:33 / stefan" |
|
4908 |
! |
|
4909 |
||
12862
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
4910 |
whichClassDefinesClassVar:aStringOrText |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
4911 |
|name| |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
4912 |
|
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
4913 |
name := aStringOrText asString string. |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
4914 |
^ self whichClassSatisfies:[:aClass | aClass classVarNames includes:name] |
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
4915 |
|
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
4916 |
" |
13419 | 4917 |
TextView whichClassDefinesClassVar:'CachedScales' |
4918 |
TextView whichClassDefinesClassVar:'xxx' |
|
12862
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
4919 |
" |
6727 | 4920 |
! |
4921 |
||
12094 | 4922 |
whichClassDefinesInstVar: aString |
12862
aab829fab334
comment/format in: #whichClassDefinesInstVar:
Claus Gittinger <cg@exept.de>
parents:
12858
diff
changeset
|
4923 |
^ self whichClassSatisfies: [:aClass | aClass instVarNames includes: aString] |
6727 | 4924 |
! |
4925 |
||
12094 | 4926 |
whichSelectorsAssign: instVarName |
16050 | 4927 |
"Answer a set of selectors whose methods write the argument, instVarName, |
4928 |
as a named instance variable." |
|
4929 |
||
4930 |
^ self whichSelectorsWrite: instVarName |
|
6727 | 4931 |
! |
4932 |
||
12094 | 4933 |
whichSelectorsRead: instVarName |
16050 | 4934 |
"Answer a set of selectors whose methods read the argument, instVarName, |
4935 |
as a named instance variable." |
|
14239 | 4936 |
|
4937 |
"/ | instVarIndex methodDict| |
|
4938 |
"/ instVarIndex := self allInstVarNames indexOf: instVarName ifAbsent: [^Set new]. |
|
4939 |
"/ methodDict := self methodDictionary. |
|
4940 |
"/ ^methodDict keys select: [:sel | (methodDict at: sel) |
|
4941 |
"/ readsField: instVarIndex] |
|
4942 |
||
16050 | 4943 |
| methodDict | |
4944 |
methodDict := self methodDictionary. |
|
4945 |
^ methodDict keys |
|
4946 |
select: [:sel | (methodDict at: sel) readsInstVar: instVarName] |
|
14239 | 4947 |
|
4948 |
"Modified: / 23-07-2012 / 11:22:04 / cg" |
|
2 | 4949 |
! |
4950 |
||
9194 | 4951 |
whichSelectorsReferTo:someLiteralConstant |
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4952 |
"return a collection of selectors of methods which refer to the argument. |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4953 |
Search the literal arrays of my methods to do this." |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4954 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4955 |
|setOfSelectors| |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4956 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4957 |
setOfSelectors := IdentitySet new. |
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
4958 |
self methodDictionary keysAndValuesDo:[:sel :mthd | |
16050 | 4959 |
(mthd referencesLiteral:someLiteralConstant) ifTrue:[ |
4960 |
setOfSelectors add:sel |
|
4961 |
]. |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4962 |
]. |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4963 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4964 |
^ setOfSelectors |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4965 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4966 |
" |
12094 | 4967 |
String whichSelectorsReferTo:#at: |
4968 |
String whichSelectorsReferTo:CharacterArray |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4969 |
" |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4970 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4971 |
"Modified: / 28.10.1997 / 13:13:18 / cg" |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4972 |
! |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4973 |
|
5297 | 4974 |
whichSelectorsReferToClassVariable:nameOfClassVariable |
4975 |
"return a collection of selectors of methods which refer to the argument. |
|
4976 |
Search the literal arrays of my methods to do this." |
|
4977 |
||
10413 | 4978 |
^ self whichSelectorsReferToGlobal:(self theNonMetaclass globalKeyForClassVar:nameOfClassVariable) |
5297 | 4979 |
|
4980 |
" |
|
4981 |
Object whichSelectorsReferToClassVariable:#Dependencies |
|
4982 |
" |
|
4983 |
||
10185 | 4984 |
"Modified: / 18-11-2006 / 17:14:08 / cg" |
5297 | 4985 |
! |
4986 |
||
4987 |
whichSelectorsReferToGlobal:nameOfGlobal |
|
4988 |
"return a collection of selectors of methods which refer to the argument. |
|
4989 |
Search the literal arrays of my methods to do this." |
|
4990 |
||
4991 |
|internalNameOfVar| |
|
4992 |
||
4993 |
internalNameOfVar := nameOfGlobal asSymbol. |
|
4994 |
^ self whichSelectorsReferTo:internalNameOfVar |
|
4995 |
||
4996 |
" |
|
4997 |
Object whichSelectorsReferToGlobal:#Debugger |
|
4998 |
" |
|
4999 |
||
5000 |
"Modified: / 4.2.2000 / 00:41:10 / cg" |
|
5001 |
! |
|
5002 |
||
12094 | 5003 |
whichSelectorsWrite: instVarName |
16050 | 5004 |
"Answer a set of selectors whose methods write the argument, instVarName, |
5005 |
as a named instance variable." |
|
14239 | 5006 |
|
5007 |
"/ | instVarIndex methodDict | |
|
5008 |
"/ instVarIndex := self allInstVarNames indexOf: instVarName ifAbsent: [^Set new]. |
|
5009 |
"/ methodDict := self methodDictionary. |
|
5010 |
"/ ^methodDict keys select: [:sel | (methodDict at: sel) |
|
5011 |
"/ writesField: instVarIndex] |
|
16050 | 5012 |
| methodDict | |
5013 |
methodDict := self methodDictionary. |
|
5014 |
^ methodDict keys |
|
5015 |
select: [:sel | (methodDict at: sel) writesInstVar: instVarName] |
|
14239 | 5016 |
|
5017 |
"Modified: / 23-07-2012 / 11:21:17 / cg" |
|
2 | 5018 |
! ! |
620 | 5019 |
|
5020 |
!Behavior methodsFor:'snapshots'! |
|
5021 |
||
9194 | 5022 |
postSnapshot |
5023 |
"sent by ObjectMemory to all classes, after a snapshot has been written. |
|
5024 |
Nothing done here. This can be redefined in classes which like to know |
|
5025 |
about snapshooting." |
|
5026 |
||
5027 |
"Modified: 16.4.1996 / 18:12:08 / cg" |
|
5028 |
! |
|
9189
3fbc934d46a9
readFromString: - allow for whitespace following the string
Claus Gittinger <cg@exept.de>
parents:
8962
diff
changeset
|
5029 |
|
3fbc934d46a9
readFromString: - allow for whitespace following the string
Claus Gittinger <cg@exept.de>
parents:
8962
diff
changeset
|
5030 |
preSnapshot |
3fbc934d46a9
readFromString: - allow for whitespace following the string
Claus Gittinger <cg@exept.de>
parents:
8962
diff
changeset
|
5031 |
"sent by ObjectMemory to all classes, before a snapshot is written. |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
5032 |
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
|
5033 |
about snapshooting." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
5034 |
|
9189
3fbc934d46a9
readFromString: - allow for whitespace following the string
Claus Gittinger <cg@exept.de>
parents:
8962
diff
changeset
|
5035 |
"Modified: 16.4.1996 / 18:12:14 / cg" |
620 | 5036 |
! ! |
5037 |
||
4657
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
5038 |
!Behavior methodsFor:'tracing'! |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
5039 |
|
9194 | 5040 |
traceInto:aRequestor level:level from:referrer |
5041 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
5042 |
||
5043 |
^ aRequestor traceBehavior:self level:level from:referrer |
|
5044 |
||
5045 |
||
4657
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
5046 |
! ! |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
5047 |
|
9194 | 5048 |
!Behavior methodsFor:'visiting'! |
5049 |
||
5050 |
acceptVisitor:aVisitor with:aParameter |
|
8398
666ef609ec93
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8353
diff
changeset
|
5051 |
|
666ef609ec93
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8353
diff
changeset
|
5052 |
^ aVisitor visitBehavior:self with:aParameter |
666ef609ec93
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8353
diff
changeset
|
5053 |
! ! |
666ef609ec93
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8353
diff
changeset
|
5054 |
|
1760 | 5055 |
!Behavior class methodsFor:'documentation'! |
662 | 5056 |
|
13839
95b353c4d5f1
changed: #setTraitComposition:
Claus Gittinger <cg@exept.de>
parents:
13838
diff
changeset
|
5057 |
version |
16280 | 5058 |
^ '$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.358 2014-03-25 15:47:43 stefan Exp $' |
13839
95b353c4d5f1
changed: #setTraitComposition:
Claus Gittinger <cg@exept.de>
parents:
13838
diff
changeset
|
5059 |
! |
95b353c4d5f1
changed: #setTraitComposition:
Claus Gittinger <cg@exept.de>
parents:
13838
diff
changeset
|
5060 |
|
12113
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
5061 |
version_CVS |
16280 | 5062 |
^ '$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.358 2014-03-25 15:47:43 stefan Exp $' |
662 | 5063 |
! ! |
14703 | 5064 |