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