1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
154
|
3 |
All Rights Reserved
|
1
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Object subclass:#Behavior
|
68
|
14 |
instanceVariableNames:'superclass otherSuperclasses
|
154
|
15 |
selectorArray methodArray
|
|
16 |
instSize flags'
|
308
|
17 |
classVariableNames:'SubclassInfo'
|
1
|
18 |
poolDictionaries:''
|
|
19 |
category:'Kernel-Classes'
|
|
20 |
!
|
|
21 |
|
|
22 |
Behavior comment:'
|
5
|
23 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
154
|
24 |
All Rights Reserved
|
92
|
25 |
|
343
|
26 |
$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.37 1995-05-10 02:17:35 claus Exp $
|
47
|
27 |
'!
|
|
28 |
|
|
29 |
!Behavior class methodsFor:'documentation'!
|
|
30 |
|
88
|
31 |
copyright
|
|
32 |
"
|
|
33 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
154
|
34 |
All Rights Reserved
|
88
|
35 |
|
|
36 |
This software is furnished under a license and may be used
|
|
37 |
only in accordance with the terms of that license and with the
|
|
38 |
inclusion of the above copyright notice. This software may not
|
|
39 |
be provided or otherwise made available to, or used by, any
|
|
40 |
other person. No title to or ownership of the software is
|
|
41 |
hereby transferred.
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
version
|
|
46 |
"
|
343
|
47 |
$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.37 1995-05-10 02:17:35 claus Exp $
|
88
|
48 |
"
|
|
49 |
!
|
|
50 |
|
47
|
51 |
documentation
|
|
52 |
"
|
68
|
53 |
Every class in the system inherits from Behavior (via Class, ClassDescription);
|
|
54 |
so here is where most of the class messages end up being implemented.
|
|
55 |
(to answer a FAQ: 'Point basicNew' will be done here :-)
|
|
56 |
|
91
|
57 |
Beginners should keep in mind, that all classes are instances of subclasses
|
|
58 |
of Behavior, therefore you will find the above mentioned 'basicNew:' method
|
|
59 |
under the 'instance'-methods of Behavior - NOT under the class methods
|
154
|
60 |
('Behavior new' will create and return a new class, while sending 'new' to
|
|
61 |
any instance of Behavior (i.e. any class) will return an instance of that class).
|
68
|
62 |
|
|
63 |
Behavior provides minimum support for all classes - additional stuff is
|
77
|
64 |
found in ClassDescription and Class. Behaviors provides all mechanisms needed
|
|
65 |
to create instances, and send messages to those. However, Behavior does not provide
|
|
66 |
all the (symbolic) information needed to compile methods for a class or to get
|
|
67 |
useful information in inspectors.
|
47
|
68 |
|
68
|
69 |
In contrast to other ST implementations, the methods have been separated
|
|
70 |
from the selectors (there is no Dictionary, but two separate Arrays)
|
|
71 |
- this avoids the need for knowledge about Dictionaries in the runtime library (VM)
|
|
72 |
(lookup and search in these is seldom anyway, so the added benefit from using a
|
|
73 |
hashed dictionary is almost void).
|
1
|
74 |
|
68
|
75 |
Instance variables:
|
1
|
76 |
|
154
|
77 |
superclass <Class> the receivers superclass
|
|
78 |
otherSuperclasses <Array of Class> experimental: other superclasses
|
|
79 |
selectorArray <Array of Symbol> the selectors for which inst-methods are defined here
|
|
80 |
methodArray <Array of Method> the inst-methods corresponding to the selectors
|
|
81 |
instSize <SmallInteger> the number of instance variables
|
|
82 |
flags <SmallInteger> special flag bits coded in a number
|
1
|
83 |
|
81
|
84 |
flag bits (see stc.h):
|
47
|
85 |
|
68
|
86 |
NOTICE: layout known by compiler and runtime system; be careful when changing
|
47
|
87 |
"
|
|
88 |
! !
|
1
|
89 |
|
3
|
90 |
!Behavior class methodsFor:'queries'!
|
|
91 |
|
|
92 |
isBuiltInClass
|
|
93 |
"this class is known by the run-time-system"
|
|
94 |
|
|
95 |
^ true
|
|
96 |
! !
|
|
97 |
|
1
|
98 |
!Behavior class methodsFor:'creating new classes'!
|
|
99 |
|
|
100 |
new
|
|
101 |
"creates and return a new class"
|
|
102 |
|
|
103 |
|newClass|
|
|
104 |
|
|
105 |
newClass := self basicNew.
|
|
106 |
newClass setSuperclass:Object
|
154
|
107 |
selectors:(Array new:0)
|
|
108 |
methods:(Array new:0)
|
|
109 |
instSize:0
|
|
110 |
flags:0.
|
1
|
111 |
^ newClass
|
|
112 |
! !
|
|
113 |
|
308
|
114 |
!Behavior class methodsFor:'private '!
|
|
115 |
|
|
116 |
subclassInfo
|
|
117 |
|d b|
|
|
118 |
|
|
119 |
SubclassInfo notNil ifTrue:[^ SubclassInfo].
|
|
120 |
|
|
121 |
d := IdentityDictionary new.
|
|
122 |
Smalltalk allClassesDo:[:aClass |
|
|
123 |
|superCls|
|
|
124 |
|
|
125 |
aClass isMeta not ifTrue:[
|
|
126 |
superCls := aClass superclass.
|
|
127 |
superCls notNil ifTrue:[
|
|
128 |
(d includesKey: superCls) ifFalse:[
|
|
129 |
d at:superCls put:(Set with:aClass).
|
|
130 |
] ifTrue:[
|
|
131 |
(d at:superCls ) add:aClass
|
|
132 |
]
|
|
133 |
]
|
|
134 |
].
|
|
135 |
].
|
|
136 |
SubclassInfo := d.
|
|
137 |
^ d
|
|
138 |
|
|
139 |
"
|
|
140 |
Class subclassInfo
|
|
141 |
"
|
|
142 |
!
|
|
143 |
|
|
144 |
flushSubclassInfo
|
|
145 |
SubclassInfo := nil.
|
|
146 |
|
|
147 |
"
|
|
148 |
Class flushSubclassInfo
|
|
149 |
"
|
|
150 |
! !
|
|
151 |
|
1
|
152 |
!Behavior methodsFor:'initialization'!
|
|
153 |
|
|
154 |
initialize
|
|
155 |
"to catch initialize for classes which do not"
|
|
156 |
|
|
157 |
^ self
|
|
158 |
!
|
|
159 |
|
328
|
160 |
postAutoload
|
|
161 |
"for autoloaded classes, gives them a second chance"
|
|
162 |
|
|
163 |
^ self
|
|
164 |
!
|
|
165 |
|
1
|
166 |
reinitialize
|
|
167 |
"to catch reinitialize for classes which do not"
|
|
168 |
|
|
169 |
^ self
|
|
170 |
! !
|
|
171 |
|
11
|
172 |
!Behavior methodsFor:'copying'!
|
|
173 |
|
|
174 |
deepCopy
|
|
175 |
"return a deep copy of the receiver
|
|
176 |
- return the receiver here - time will show if this is ok"
|
|
177 |
|
|
178 |
^ self
|
|
179 |
!
|
|
180 |
|
|
181 |
deepCopyUsing:aDictionary
|
|
182 |
"return a deep copy of the receiver
|
|
183 |
- return the receiver here - time will show if this is ok"
|
|
184 |
|
|
185 |
^ self
|
|
186 |
!
|
|
187 |
|
|
188 |
simpleDeepCopy
|
|
189 |
"return a deep copy of the receiver
|
|
190 |
- return the receiver here - time will show if this is ok"
|
|
191 |
|
|
192 |
^ self
|
|
193 |
! !
|
|
194 |
|
1
|
195 |
!Behavior methodsFor:'creating an instance of myself'!
|
|
196 |
|
|
197 |
uninitializedNew
|
308
|
198 |
"create an instance of myself with uninitialized contents.
|
|
199 |
For all classes except ByteArray, this is the same as new."
|
1
|
200 |
|
|
201 |
^ self basicNew
|
|
202 |
!
|
|
203 |
|
|
204 |
uninitializedNew:anInteger
|
308
|
205 |
"create an instance of myself with uninitialized contents.
|
|
206 |
For all classes except ByteArray, this is the same as new."
|
1
|
207 |
|
|
208 |
^ self basicNew:anInteger
|
|
209 |
!
|
|
210 |
|
127
|
211 |
niceBasicNew:anInteger
|
|
212 |
"same as basicNew:anInteger, but tries to avoid long pauses
|
|
213 |
due to garbage collection. This method checks to see if
|
|
214 |
allocation is possible without a pause, and does a background
|
|
215 |
incremental garbage collect first if there is not enough memory
|
|
216 |
available at the moment for fast allocation.
|
|
217 |
This is useful in low-priority background processes which like to
|
|
218 |
avoid disturbing any higher priority foreground process while allocating
|
|
219 |
big amounts of memory. Of course, using this method only makes
|
|
220 |
sense for big or huge objects (say > 200k).
|
|
221 |
|
|
222 |
EXPERIMENTAL: this is a non-standard interface and should only
|
|
223 |
be used for special applications. There is no guarantee, that this
|
|
224 |
method will be available in future ST/X releases."
|
|
225 |
|
|
226 |
|size|
|
|
227 |
|
|
228 |
size := self sizeOfInst:anInteger.
|
|
229 |
(ObjectMemory checkForFastNew:size) ifFalse:[
|
154
|
230 |
"
|
|
231 |
incrementally collect garbage
|
|
232 |
"
|
|
233 |
ObjectMemory incrementalGC.
|
127
|
234 |
].
|
|
235 |
^ self basicNew:anInteger
|
|
236 |
!
|
|
237 |
|
1
|
238 |
new
|
|
239 |
"return an instance of myself without indexed variables"
|
|
240 |
|
|
241 |
^ self basicNew
|
|
242 |
!
|
|
243 |
|
|
244 |
new:anInteger
|
|
245 |
"return an instance of myself with anInteger indexed variables"
|
|
246 |
|
|
247 |
^ self basicNew:anInteger
|
|
248 |
!
|
|
249 |
|
|
250 |
basicNew
|
54
|
251 |
"return an instance of myself without indexed variables.
|
1
|
252 |
If the receiver-class has indexed instvars, the new object will have
|
91
|
253 |
a basicSize of zero -
|
|
254 |
i.e. 'aClass basicNew' is equivalent to 'aClass basicNew:0'.
|
54
|
255 |
|
1
|
256 |
** Do not redefine this method in any class **"
|
|
257 |
|
|
258 |
%{ /* NOCONTEXT */
|
11
|
259 |
OBJ new();
|
81
|
260 |
REGISTER OBJ newobj;
|
|
261 |
REGISTER char *nextPtr;
|
91
|
262 |
unsigned int instsize;
|
|
263 |
REGISTER unsigned int nInstVars;
|
1
|
264 |
|
54
|
265 |
/*
|
|
266 |
* the following ugly code is nothing more than a new() followed
|
|
267 |
* by a nilling of the new instance.
|
91
|
268 |
* Unrolled for a bit more speed since this is one of the central object
|
|
269 |
* allocation methods in the system
|
54
|
270 |
*/
|
1
|
271 |
nInstVars = _intVal(_INST(instSize));
|
92
|
272 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
|
54
|
273 |
|
77
|
274 |
newobj = (OBJ) newNextPtr;
|
81
|
275 |
nextPtr = ((char *)newobj) + instsize;
|
|
276 |
|
|
277 |
/*
|
|
278 |
* dont argue about the goto and the arrangement below - it saves
|
|
279 |
* an extra nil-compare and branch in the common case ...
|
91
|
280 |
* (i.e. if no GC is needed, we fall through without a branch)
|
81
|
281 |
*/
|
82
|
282 |
if (nextPtr < newEndPtr) {
|
154
|
283 |
_objPtr(newobj)->o_size = instsize;
|
|
284 |
/* o_allFlags(newobj) = 0; */
|
|
285 |
/* _objPtr(newobj)->o_space = newSpace; */
|
|
286 |
o_setAllFlags(newobj, newSpace);
|
91
|
287 |
#ifdef ALIGN4
|
154
|
288 |
newNextPtr = nextPtr;
|
91
|
289 |
#else
|
154
|
290 |
if (instsize & (ALIGN-1)) {
|
|
291 |
newNextPtr = (char *)newobj + (instsize & ~(ALIGN-1)) + ALIGN;
|
|
292 |
} else {
|
|
293 |
newNextPtr = nextPtr;
|
|
294 |
}
|
91
|
295 |
#endif
|
82
|
296 |
|
|
297 |
ok:
|
154
|
298 |
_InstPtr(newobj)->o_class = self;
|
308
|
299 |
#ifndef PRE_16_03_95
|
323
|
300 |
__STORE(newobj, self);
|
308
|
301 |
#endif
|
82
|
302 |
|
154
|
303 |
if (nInstVars) {
|
92
|
304 |
#if defined(FAST_OBJECT_MEMSET4)
|
154
|
305 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
|
82
|
306 |
#else
|
154
|
307 |
REGISTER OBJ *op;
|
82
|
308 |
|
154
|
309 |
op = _InstPtr(newobj)->i_instvars;
|
82
|
310 |
|
91
|
311 |
# if !defined(NEGATIVE_ADDRESSES)
|
154
|
312 |
/*
|
|
313 |
* knowing that nil is 0
|
|
314 |
*/
|
91
|
315 |
# if defined(FAST_OBJECT_MEMSET_DOUBLES_UNROLLED)
|
154
|
316 |
if (nInstVars > 8) {
|
|
317 |
*op++ = nil; /* for alignment */
|
|
318 |
nInstVars--;
|
|
319 |
while (nInstVars >= 8) {
|
|
320 |
*(double *)op = 0.0;
|
|
321 |
((double *)op)[1] = 0.0;
|
|
322 |
((double *)op)[2] = 0.0;
|
|
323 |
((double *)op)[3] = 0.0;
|
|
324 |
op += 8;
|
|
325 |
nInstVars -= 8;
|
|
326 |
}
|
|
327 |
}
|
|
328 |
while (nInstVars != 0) {
|
|
329 |
*op++ = 0;
|
|
330 |
nInstVars--;
|
|
331 |
}
|
82
|
332 |
# else
|
91
|
333 |
# if defined(FAST_OBJECT_MEMSET_LONGLONG_UNROLLED)
|
154
|
334 |
if (nInstVars > 8) {
|
|
335 |
*op++ = nil; /* for alignment */
|
|
336 |
nInstVars--;
|
|
337 |
while (nInstVars >= 8) {
|
|
338 |
*(long long *)op = 0;
|
|
339 |
((long long *)op)[1] = 0;
|
|
340 |
((long long *)op)[2] = 0;
|
|
341 |
((long long *)op)[3] = 0;
|
|
342 |
op += 8;
|
|
343 |
nInstVars -= 8;
|
|
344 |
}
|
|
345 |
}
|
|
346 |
while (nInstVars != 0) {
|
|
347 |
*op++ = 0;
|
|
348 |
nInstVars--;
|
|
349 |
}
|
91
|
350 |
|
|
351 |
# else
|
|
352 |
# if defined(FAST_OBJECT_MEMSET_WORDS_UNROLLED)
|
154
|
353 |
while (nInstVars >= 8) {
|
|
354 |
*op = nil;
|
|
355 |
*(op+1) = nil;
|
|
356 |
*(op+2) = nil;
|
|
357 |
*(op+3) = nil;
|
|
358 |
*(op+4) = nil;
|
|
359 |
*(op+5) = nil;
|
|
360 |
*(op+6) = nil;
|
|
361 |
*(op+7) = nil;
|
|
362 |
op += 8;
|
|
363 |
nInstVars -= 8;
|
|
364 |
}
|
|
365 |
while (nInstVars != 0) {
|
|
366 |
*op++ = nil;
|
|
367 |
nInstVars--;
|
|
368 |
}
|
91
|
369 |
# else
|
|
370 |
# if defined(FAST_MEMSET)
|
154
|
371 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE);
|
91
|
372 |
# else
|
154
|
373 |
do {
|
|
374 |
*op++ = nil;
|
|
375 |
nInstVars--;
|
|
376 |
} while (nInstVars != 0);
|
91
|
377 |
# endif
|
82
|
378 |
# endif
|
|
379 |
# endif
|
|
380 |
# endif
|
|
381 |
# else /* nil could be ~~ 0 */
|
154
|
382 |
while (nInstVars >= 8) {
|
|
383 |
*op = nil;
|
|
384 |
*(op+1) = nil;
|
|
385 |
*(op+2) = nil;
|
|
386 |
*(op+3) = nil;
|
|
387 |
*(op+4) = nil;
|
|
388 |
*(op+5) = nil;
|
|
389 |
*(op+6) = nil;
|
|
390 |
*(op+7) = nil;
|
|
391 |
op += 8;
|
|
392 |
nInstVars -= 8;
|
|
393 |
}
|
|
394 |
while (nInstVars != 0) {
|
|
395 |
*op++ = nil;
|
|
396 |
nInstVars--;
|
|
397 |
}
|
82
|
398 |
# endif
|
|
399 |
#endif
|
154
|
400 |
}
|
|
401 |
RETURN ( newobj );
|
81
|
402 |
}
|
54
|
403 |
|
92
|
404 |
/*
|
|
405 |
* the slow case - a GC will occur
|
|
406 |
*/
|
82
|
407 |
PROTECT_CONTEXT
|
|
408 |
newobj = new(instsize, SENDER);
|
|
409 |
UNPROTECT_CONTEXT
|
|
410 |
if (newobj != nil) goto ok;
|
1
|
411 |
%}
|
2
|
412 |
.
|
68
|
413 |
"
|
|
414 |
memory allocation failed.
|
|
415 |
When we arrive here, there was no memory, even after
|
165
|
416 |
a garbage collect.
|
|
417 |
This means, that the VM wanted to get some more memory from the
|
|
418 |
Operatingsystem, which was not kind enough to give it.
|
|
419 |
Bad luck - you should increase the swap space on your machine.
|
68
|
420 |
"
|
127
|
421 |
^ ObjectMemory allocationFailureSignal raise.
|
1
|
422 |
!
|
|
423 |
|
|
424 |
basicNew:anInteger
|
|
425 |
"return an instance of myself with anInteger indexed variables.
|
|
426 |
If the receiver-class has no indexed instvars, this is only allowed
|
|
427 |
if the argument, anInteger is zero.
|
|
428 |
** Do not redefine this method in any class **"
|
|
429 |
|
|
430 |
%{ /* NOCONTEXT */
|
|
431 |
|
|
432 |
OBJ newobj;
|
154
|
433 |
unsigned INT instsize, nInstVars;
|
|
434 |
INT nindexedinstvars;
|
92
|
435 |
unsigned INT flags;
|
|
436 |
#if ! defined(FAST_ARRAY_MEMSET) || defined(NEGATIVE_ADDRESSES)
|
1
|
437 |
REGISTER char *cp;
|
|
438 |
short *sp;
|
|
439 |
long *lp;
|
|
440 |
#endif
|
|
441 |
REGISTER OBJ *op;
|
|
442 |
float *fp;
|
|
443 |
double *dp;
|
|
444 |
extern OBJ new();
|
|
445 |
|
249
|
446 |
if (__isSmallInteger(anInteger)) {
|
154
|
447 |
nindexedinstvars = _intVal(anInteger);
|
|
448 |
if (nindexedinstvars >= 0) {
|
|
449 |
nInstVars = _intVal(_INST(instSize));
|
|
450 |
flags = _intVal(_INST(flags)) & ARRAYMASK;
|
|
451 |
switch (flags) {
|
|
452 |
case BYTEARRAY:
|
|
453 |
instsize = OHDR_SIZE + nindexedinstvars;
|
|
454 |
if (nInstVars == 0) {
|
|
455 |
if (_CanDoQuickNew(instsize)) {
|
|
456 |
/*
|
|
457 |
* the most common case
|
|
458 |
*/
|
|
459 |
_qCheckedNew(newobj, instsize);
|
|
460 |
_InstPtr(newobj)->o_class = self;
|
92
|
461 |
#if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
154
|
462 |
memset(_InstPtr(newobj)->i_instvars, 0, nindexedinstvars);
|
92
|
463 |
#else
|
154
|
464 |
cp = (char *)_InstPtr(newobj)->i_instvars;
|
|
465 |
while (nindexedinstvars >= sizeof(long)) {
|
|
466 |
*(long *)cp = 0;
|
|
467 |
cp += sizeof(long);
|
|
468 |
nindexedinstvars -= sizeof(long);
|
|
469 |
}
|
|
470 |
while (nindexedinstvars--)
|
|
471 |
*cp++ = '\0';
|
92
|
472 |
#endif
|
154
|
473 |
RETURN ( newobj );
|
|
474 |
}
|
|
475 |
} else {
|
|
476 |
instsize += __OBJS2BYTES__(nInstVars);
|
|
477 |
}
|
|
478 |
PROTECT_CONTEXT
|
|
479 |
_qNew(newobj, instsize, SENDER);
|
|
480 |
UNPROTECT_CONTEXT
|
|
481 |
if (newobj == nil) {
|
|
482 |
break;
|
|
483 |
}
|
|
484 |
_InstPtr(newobj)->o_class = self;
|
308
|
485 |
#ifndef PRE_16_03_95
|
323
|
486 |
__STORE(newobj, self);
|
308
|
487 |
#endif
|
92
|
488 |
#if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
154
|
489 |
/*
|
|
490 |
* knowing that nil is 0
|
|
491 |
*/
|
|
492 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE);
|
1
|
493 |
#else
|
154
|
494 |
op = _InstPtr(newobj)->i_instvars;
|
|
495 |
while (nInstVars--)
|
|
496 |
*op++ = nil;
|
|
497 |
cp = (char *)op;
|
|
498 |
while (nindexedinstvars >= sizeof(long)) {
|
|
499 |
*(long *)cp = 0;
|
|
500 |
cp += sizeof(long);
|
|
501 |
nindexedinstvars -= sizeof(long);
|
|
502 |
}
|
|
503 |
while (nindexedinstvars--)
|
|
504 |
*cp++ = '\0';
|
1
|
505 |
#endif
|
154
|
506 |
RETURN ( newobj );
|
|
507 |
break;
|
1
|
508 |
|
154
|
509 |
case WORDARRAY:
|
|
510 |
instsize = OHDR_SIZE +
|
|
511 |
__OBJS2BYTES__(nInstVars) +
|
|
512 |
nindexedinstvars * sizeof(short);
|
|
513 |
PROTECT_CONTEXT
|
|
514 |
_qNew(newobj, instsize, SENDER);
|
|
515 |
UNPROTECT_CONTEXT
|
|
516 |
if (newobj == nil) {
|
|
517 |
break;
|
|
518 |
}
|
|
519 |
_InstPtr(newobj)->o_class = self;
|
308
|
520 |
#ifndef PRE_16_03_95
|
323
|
521 |
__STORE(newobj, self);
|
308
|
522 |
#endif
|
92
|
523 |
#if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
154
|
524 |
/*
|
|
525 |
* knowing that nil is 0
|
|
526 |
*/
|
|
527 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
1
|
528 |
#else
|
154
|
529 |
op = _InstPtr(newobj)->i_instvars;
|
|
530 |
while (nInstVars--)
|
|
531 |
*op++ = nil;
|
|
532 |
sp = (short *)op;
|
|
533 |
while (nindexedinstvars--)
|
|
534 |
*sp++ = 0;
|
1
|
535 |
#endif
|
154
|
536 |
RETURN ( newobj );
|
|
537 |
break;
|
1
|
538 |
|
154
|
539 |
case LONGARRAY:
|
|
540 |
instsize = OHDR_SIZE +
|
|
541 |
__OBJS2BYTES__(nInstVars) +
|
|
542 |
nindexedinstvars * sizeof(long);
|
|
543 |
PROTECT_CONTEXT
|
|
544 |
_qAlignedNew(newobj, instsize, SENDER);
|
|
545 |
UNPROTECT_CONTEXT
|
|
546 |
if (newobj == nil) {
|
|
547 |
break;
|
|
548 |
}
|
|
549 |
_InstPtr(newobj)->o_class = self;
|
308
|
550 |
#ifndef PRE_16_03_95
|
323
|
551 |
__STORE(newobj, self);
|
308
|
552 |
#endif
|
92
|
553 |
#if defined(FAST_ARRAY_MEMSET4) && ! defined(NEGATIVE_ADDRESSES)
|
154
|
554 |
/*
|
|
555 |
* knowing that nil is 0
|
|
556 |
*/
|
|
557 |
memset4(_InstPtr(newobj)->i_instvars, 0, nInstVars + nindexedinstvars);
|
1
|
558 |
#else
|
92
|
559 |
# if defined(FAST_ARRAY_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
154
|
560 |
/*
|
|
561 |
* knowing that nil is 0
|
|
562 |
*/
|
|
563 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
1
|
564 |
# else
|
154
|
565 |
op = _InstPtr(newobj)->i_instvars;
|
|
566 |
while (nInstVars--)
|
|
567 |
*op++ = nil;
|
|
568 |
lp = (long *)op;
|
|
569 |
while (nindexedinstvars--)
|
|
570 |
*lp++ = 0;
|
1
|
571 |
# endif
|
|
572 |
#endif
|
154
|
573 |
RETURN ( newobj );
|
|
574 |
break;
|
1
|
575 |
|
154
|
576 |
case FLOATARRAY:
|
325
|
577 |
instsize = sizeof(struct __floatArray) +
|
154
|
578 |
__OBJS2BYTES__(nInstVars) +
|
|
579 |
(nindexedinstvars - 1) * sizeof(float);
|
54
|
580 |
|
154
|
581 |
PROTECT_CONTEXT
|
|
582 |
_qNew(newobj, instsize, SENDER);
|
|
583 |
UNPROTECT_CONTEXT
|
|
584 |
if (newobj == nil) {
|
|
585 |
break;
|
|
586 |
}
|
|
587 |
_InstPtr(newobj)->o_class = self;
|
308
|
588 |
#ifndef PRE_16_03_95
|
323
|
589 |
__STORE(newobj, self);
|
308
|
590 |
#endif
|
154
|
591 |
op = _InstPtr(newobj)->i_instvars;
|
92
|
592 |
# if defined(mips) /* knowin that float 0.0 is all-zeros */
|
154
|
593 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
92
|
594 |
# else
|
154
|
595 |
while (nInstVars--)
|
|
596 |
*op++ = nil;
|
|
597 |
fp = (float *)op;
|
|
598 |
while (nindexedinstvars--)
|
|
599 |
*fp++ = 0.0;
|
92
|
600 |
# endif
|
154
|
601 |
RETURN ( newobj );
|
|
602 |
break;
|
1
|
603 |
|
154
|
604 |
case DOUBLEARRAY:
|
325
|
605 |
instsize = sizeof(struct __doubleArray) +
|
154
|
606 |
__OBJS2BYTES__(nInstVars) +
|
|
607 |
(nindexedinstvars - 1) * sizeof(double);
|
54
|
608 |
|
154
|
609 |
PROTECT_CONTEXT
|
|
610 |
_qAlignedNew(newobj, instsize, SENDER);
|
|
611 |
UNPROTECT_CONTEXT
|
|
612 |
if (newobj == nil) {
|
|
613 |
break;
|
|
614 |
}
|
|
615 |
_InstPtr(newobj)->o_class = self;
|
308
|
616 |
#ifndef PRE_16_03_95
|
323
|
617 |
__STORE(newobj, self);
|
308
|
618 |
#endif
|
154
|
619 |
op = _InstPtr(newobj)->i_instvars;
|
|
620 |
while (nInstVars--)
|
|
621 |
*op++ = nil;
|
54
|
622 |
#ifdef NEED_DOUBLE_ALIGN
|
154
|
623 |
/*
|
|
624 |
* care for double alignment
|
|
625 |
*/
|
|
626 |
if ((INT)op & (ALIGN-1)) {
|
|
627 |
*op++ = nil;
|
|
628 |
}
|
54
|
629 |
#endif
|
154
|
630 |
dp = (double *)op;
|
|
631 |
while (nindexedinstvars--)
|
|
632 |
*dp++ = 0.0;
|
|
633 |
RETURN ( newobj );
|
|
634 |
break;
|
1
|
635 |
|
154
|
636 |
case WKPOINTERARRAY:
|
|
637 |
case POINTERARRAY:
|
|
638 |
nInstVars += nindexedinstvars;
|
|
639 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
|
|
640 |
PROTECT_CONTEXT
|
|
641 |
_qAlignedNew(newobj, instsize, SENDER);
|
|
642 |
UNPROTECT_CONTEXT
|
|
643 |
if (newobj == nil) {
|
|
644 |
break;
|
|
645 |
}
|
|
646 |
_InstPtr(newobj)->o_class = self;
|
308
|
647 |
#ifndef PRE_16_03_95
|
323
|
648 |
__STORE(newobj, self);
|
308
|
649 |
#endif
|
92
|
650 |
#if defined(FAST_ARRAY_MEMSET4)
|
154
|
651 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
|
1
|
652 |
#else
|
82
|
653 |
# if !defined(NEGATIVE_ADDRESSES)
|
154
|
654 |
/*
|
|
655 |
* knowing that nil is 0
|
|
656 |
*/
|
92
|
657 |
#ifdef mips
|
|
658 |
# undef FAST_ARRAY_MEMSET_DOUBLES_UNROLLED
|
|
659 |
# undef FAST_ARRAY_MEMSET_LONGLONG_UNROLLED
|
198
|
660 |
/* seems to be slightly faster */
|
92
|
661 |
# define FAST_ARRAY_MEMSET
|
|
662 |
#endif
|
|
663 |
#ifdef sparc
|
|
664 |
# define FAST_ARRAY_MEMSET_DOUBLES_UNROLLED
|
|
665 |
#endif
|
|
666 |
|
91
|
667 |
# if defined(FAST_ARRAY_MEMSET_DOUBLES_UNROLLED)
|
154
|
668 |
op = _InstPtr(newobj)->i_instvars;
|
|
669 |
if (nInstVars > 8) {
|
|
670 |
*op++ = nil; /* for alignment */
|
|
671 |
nInstVars--;
|
|
672 |
while (nInstVars >= 8) {
|
|
673 |
*(double *)op = 0.0;
|
|
674 |
((double *)op)[1] = 0.0;
|
|
675 |
((double *)op)[2] = 0.0;
|
|
676 |
((double *)op)[3] = 0.0;
|
|
677 |
op += 8;
|
|
678 |
nInstVars -= 8;
|
|
679 |
}
|
|
680 |
}
|
|
681 |
while (nInstVars) {
|
|
682 |
*op++ = 0;
|
|
683 |
nInstVars--;
|
|
684 |
}
|
82
|
685 |
# else
|
91
|
686 |
# if defined(FAST_ARRAY_MEMSET_LONGLONG_UNROLLED)
|
154
|
687 |
op = _InstPtr(newobj)->i_instvars;
|
|
688 |
if (nInstVars > 8) {
|
|
689 |
*op++ = nil; /* for alignment */
|
|
690 |
nInstVars--;
|
|
691 |
while (nInstVars >= 8) {
|
|
692 |
*(long long *)op = 0;
|
|
693 |
((long long *)op)[1] = 0;
|
|
694 |
((long long *)op)[2] = 0;
|
|
695 |
((long long *)op)[3] = 0;
|
|
696 |
op += 8;
|
|
697 |
nInstVars -= 8;
|
|
698 |
}
|
|
699 |
}
|
|
700 |
while (nInstVars) {
|
|
701 |
*op++ = 0;
|
|
702 |
nInstVars--;
|
|
703 |
}
|
91
|
704 |
# else
|
|
705 |
# if defined(FAST_ARRAY_MEMSET)
|
154
|
706 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
91
|
707 |
# else
|
154
|
708 |
op = _InstPtr(newobj)->i_instvars;
|
|
709 |
while (nInstVars--)
|
|
710 |
*op++ = nil;
|
91
|
711 |
# endif
|
82
|
712 |
# endif
|
|
713 |
# endif
|
|
714 |
# else
|
154
|
715 |
op = _InstPtr(newobj)->i_instvars;
|
|
716 |
while (nInstVars--)
|
|
717 |
*op++ = nil;
|
1
|
718 |
# endif
|
|
719 |
#endif
|
154
|
720 |
RETURN ( newobj );
|
|
721 |
break;
|
1
|
722 |
|
154
|
723 |
default:
|
|
724 |
/*
|
|
725 |
* new:n for non-variable classes only allowed if
|
|
726 |
* n == 0
|
|
727 |
*/
|
|
728 |
if (nindexedinstvars == 0) {
|
|
729 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
|
|
730 |
PROTECT_CONTEXT
|
|
731 |
_qAlignedNew(newobj, instsize, SENDER);
|
|
732 |
UNPROTECT_CONTEXT
|
|
733 |
if (newobj == nil) {
|
|
734 |
break;
|
|
735 |
}
|
|
736 |
_InstPtr(newobj)->o_class = self;
|
308
|
737 |
#ifndef PRE_16_03_95
|
323
|
738 |
__STORE(newobj, self);
|
308
|
739 |
#endif
|
154
|
740 |
if (nInstVars) {
|
92
|
741 |
#if defined(FAST_OBJECT_MEMSET4)
|
154
|
742 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
|
1
|
743 |
#else
|
|
744 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
154
|
745 |
/*
|
|
746 |
* knowing that nil is 0
|
|
747 |
*/
|
|
748 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
1
|
749 |
# else
|
154
|
750 |
op = _InstPtr(newobj)->i_instvars;
|
|
751 |
do {
|
|
752 |
*op++ = nil;
|
|
753 |
} while (--nInstVars);
|
1
|
754 |
# endif
|
|
755 |
#endif
|
154
|
756 |
}
|
|
757 |
RETURN ( newobj );
|
|
758 |
}
|
|
759 |
break;
|
|
760 |
}
|
|
761 |
}
|
1
|
762 |
}
|
68
|
763 |
%}.
|
|
764 |
"
|
|
765 |
arrive here if something went wrong ...
|
|
766 |
figure out what it was
|
|
767 |
"
|
11
|
768 |
|
1
|
769 |
(anInteger isMemberOf:SmallInteger) ifFalse:[
|
154
|
770 |
"
|
|
771 |
the argument is either not an integer,
|
|
772 |
or a LargeInteger (which means that its definitely too big)
|
|
773 |
"
|
|
774 |
self error:'argument to new: must be Integer'.
|
|
775 |
^ nil
|
68
|
776 |
].
|
|
777 |
(anInteger < 0) ifTrue:[
|
154
|
778 |
"
|
|
779 |
the argument is negative,
|
|
780 |
"
|
|
781 |
self error:'bad (negative) argument to new:'.
|
|
782 |
^ nil
|
68
|
783 |
].
|
|
784 |
self isVariable ifFalse:[
|
154
|
785 |
"
|
|
786 |
this class does not have any indexed instance variables
|
|
787 |
"
|
|
788 |
self error:'class has no indexed instvars - cannot create with new:'.
|
|
789 |
^ nil
|
68
|
790 |
].
|
|
791 |
"
|
|
792 |
memory allocation failed.
|
|
793 |
When we arrive here, there was no memory, even after
|
165
|
794 |
a garbage collect.
|
|
795 |
This means, that the VM wanted to get some more memory from the
|
|
796 |
Operatingsystem, which was not kind enough to give it.
|
|
797 |
Bad luck - you should increase the swap space on your machine.
|
68
|
798 |
"
|
127
|
799 |
^ ObjectMemory allocationFailureSignal raise.
|
11
|
800 |
!
|
|
801 |
|
|
802 |
readFrom:aStream
|
43
|
803 |
"read an objects printed representation from the argument, aStream
|
|
804 |
and return it.
|
154
|
805 |
The read object must be a kind of myself if its not, an error is raised.
|
11
|
806 |
This is the reverse operation to 'storeOn:'.
|
43
|
807 |
|
68
|
808 |
WARNING: storeOn: does not handle circular references and multiple
|
198
|
809 |
references to the same object.
|
|
810 |
Use #storeBinary:/readBinaryFrom: for this."
|
11
|
811 |
|
198
|
812 |
^ self readFrom:aStream onError:[self error:'expected ' , self name]
|
11
|
813 |
|
91
|
814 |
"
|
|
815 |
|s|
|
11
|
816 |
s := WriteStream on:String new.
|
|
817 |
#(1 2 3 4) storeOn:s.
|
|
818 |
Object readFrom:(ReadStream on:s contents)
|
|
819 |
"
|
|
820 |
!
|
|
821 |
|
198
|
822 |
readFrom:aStream onError:exceptionBlock
|
|
823 |
"read an objects printed representation from the argument, aStream
|
|
824 |
and return it (i.e. the stream should contain some representation of
|
|
825 |
the object which was created using #storeOn:).
|
|
826 |
The read object must be a kind of myself if its not, the value of
|
|
827 |
exceptionBlock is returned.
|
|
828 |
To get any object, use 'Object readFrom:...',
|
|
829 |
To get any number, use 'Number readFrom:...' and so on.
|
|
830 |
This is the reverse operation to 'storeOn:'.
|
|
831 |
|
|
832 |
WARNING: storeOn: does not handle circular references and multiple
|
|
833 |
references to the same object.
|
|
834 |
Use #storeBinary:/readBinaryFrom: for this."
|
|
835 |
|
|
836 |
|newObject|
|
|
837 |
|
340
|
838 |
ErrorSignal handle:[:ex |
|
|
839 |
ex return
|
|
840 |
] do:[
|
|
841 |
newObject := self compilerClass evaluate:aStream.
|
|
842 |
].
|
198
|
843 |
(newObject isKindOf:self) ifFalse:[^ exceptionBlock value].
|
|
844 |
^ newObject
|
|
845 |
|
|
846 |
"
|
|
847 |
|s|
|
|
848 |
s := WriteStream on:String new.
|
|
849 |
#(1 2 3 4) storeOn:s.
|
293
|
850 |
Transcript showCr:(
|
|
851 |
Array readFrom:(ReadStream on:s contents) onError:'not an Array'
|
|
852 |
)
|
198
|
853 |
"
|
|
854 |
"
|
|
855 |
|s|
|
|
856 |
s := WriteStream on:String new.
|
|
857 |
#[1 2 3 4] storeOn:s.
|
293
|
858 |
Transcript showCr:(
|
|
859 |
Array readFrom:(ReadStream on:s contents) onError:'not an Array'
|
|
860 |
]
|
198
|
861 |
"
|
|
862 |
!
|
|
863 |
|
11
|
864 |
readFromString:aString
|
275
|
865 |
"create an object from its printed representation.
|
|
866 |
For most classes, the string is expected to be in a format created by
|
|
867 |
storeOn: or storeString; however, some (Time, Date) expect a user
|
|
868 |
readable string here.
|
|
869 |
See comments in Behavior>>readFromString:onError:,
|
|
870 |
Behavior>>readFrom: and Behavior>>readFrom:onError:"
|
11
|
871 |
|
275
|
872 |
^ self readFromString:aString onError:[self error:'expected ' , self name]
|
91
|
873 |
|
|
874 |
"
|
|
875 |
Integer readFromString:'12345678901234567890'
|
|
876 |
Point readFromString:'1@2'
|
|
877 |
"
|
198
|
878 |
!
|
|
879 |
|
|
880 |
readFromString:aString onError:exceptionBlock
|
275
|
881 |
"create an object from its printed representation.
|
|
882 |
Here, the string is expected to be in a format created by
|
|
883 |
storeOn: or storeString; however, some classes (Time, Date) may redefine
|
|
884 |
it to expect a user readable string here.
|
198
|
885 |
See comments in Behavior>>readFrom: and Behavior>>readFrom:onError:"
|
|
886 |
|
|
887 |
^ self readFrom:(ReadStream on:aString) onError:exceptionBlock
|
|
888 |
|
|
889 |
"
|
|
890 |
Integer readFromString:'12345678901234567890'
|
275
|
891 |
Integer readFromString:'abc'
|
|
892 |
Integer readFromString:'abc' onError:0
|
198
|
893 |
Point readFromString:'1@2'
|
275
|
894 |
Point readFromString:'0'
|
|
895 |
Point readFromString:'0' onError:[0@0]
|
198
|
896 |
"
|
1
|
897 |
! !
|
|
898 |
|
10
|
899 |
!Behavior methodsFor:'autoload check'!
|
|
900 |
|
|
901 |
isLoaded
|
|
902 |
"return true, if the class has been loaded;
|
|
903 |
redefined in Autoload; see comment there"
|
|
904 |
|
|
905 |
^ true
|
|
906 |
!
|
|
907 |
|
|
908 |
autoload
|
|
909 |
"force autoloading - do nothing here;
|
|
910 |
redefined in Autoload; see comment there"
|
|
911 |
|
|
912 |
^ self
|
|
913 |
! !
|
|
914 |
|
91
|
915 |
!Behavior methodsFor:'snapshots'!
|
|
916 |
|
|
917 |
preSnapshot
|
|
918 |
"sent by ObjectMemory, before a snapshot is written.
|
|
919 |
Nothing done here."
|
|
920 |
!
|
|
921 |
|
|
922 |
postSnapshot
|
|
923 |
"sent by ObjectMemory, after a snapshot has been written.
|
|
924 |
Nothing done here."
|
|
925 |
! !
|
|
926 |
|
68
|
927 |
!Behavior class methodsFor:'flag bit constants'!
|
|
928 |
|
|
929 |
flagNotIndexed
|
|
930 |
"return the flag code for non-indexed instances"
|
|
931 |
|
|
932 |
^ 0
|
|
933 |
!
|
|
934 |
|
|
935 |
flagBytes
|
|
936 |
"return the flag code for byte-valued indexed instances"
|
|
937 |
|
|
938 |
%{ /* NOCONTEXT */
|
|
939 |
/* this is defined as a primitive to get defines from stc.h */
|
|
940 |
|
92
|
941 |
RETURN ( _MKSMALLINT(BYTEARRAY) );
|
68
|
942 |
%}
|
293
|
943 |
"
|
|
944 |
Behavior flagBytes
|
|
945 |
"
|
68
|
946 |
!
|
|
947 |
|
|
948 |
flagWords
|
|
949 |
"return the flag code for word-valued indexed instances (i.e. 2-byte)"
|
|
950 |
|
|
951 |
%{ /* NOCONTEXT */
|
|
952 |
/* this is defined as a primitive to get defines from stc.h */
|
|
953 |
|
92
|
954 |
RETURN ( _MKSMALLINT(WORDARRAY) );
|
68
|
955 |
%}
|
293
|
956 |
"
|
|
957 |
Behavior flagWords
|
|
958 |
"
|
68
|
959 |
!
|
|
960 |
|
|
961 |
flagLongs
|
|
962 |
"return the flag code for long-valued indexed instances (i.e. 4-byte)"
|
|
963 |
|
|
964 |
%{ /* NOCONTEXT */
|
|
965 |
/* this is defined as a primitive to get defines from stc.h */
|
|
966 |
|
92
|
967 |
RETURN ( _MKSMALLINT(LONGARRAY) );
|
68
|
968 |
%}
|
293
|
969 |
"
|
|
970 |
Behavior flagLongs
|
|
971 |
"
|
68
|
972 |
!
|
|
973 |
|
|
974 |
flagFloats
|
|
975 |
"return the flag code for float-valued indexed instances (i.e. 4-byte reals)"
|
|
976 |
|
|
977 |
%{ /* NOCONTEXT */
|
|
978 |
/* this is defined as a primitive to get defines from stc.h */
|
|
979 |
|
92
|
980 |
RETURN ( _MKSMALLINT(FLOATARRAY) );
|
68
|
981 |
%}
|
293
|
982 |
"
|
|
983 |
Behavior flagFloats
|
|
984 |
"
|
68
|
985 |
!
|
|
986 |
|
|
987 |
flagDoubles
|
|
988 |
"return the flag code for double-valued indexed instances (i.e. 8-byte reals)"
|
|
989 |
|
|
990 |
%{ /* NOCONTEXT */
|
|
991 |
/* this is defined as a primitive to get defines from stc.h */
|
|
992 |
|
92
|
993 |
RETURN ( _MKSMALLINT(DOUBLEARRAY) );
|
68
|
994 |
%}
|
293
|
995 |
"
|
|
996 |
Behavior flagDoubles
|
|
997 |
"
|
68
|
998 |
!
|
|
999 |
|
|
1000 |
flagPointers
|
|
1001 |
"return the flag code for pointer indexed instances (i.e. Array of object)"
|
|
1002 |
|
|
1003 |
%{ /* NOCONTEXT */
|
|
1004 |
/* this is defined as a primitive to get defines from stc.h */
|
|
1005 |
|
92
|
1006 |
RETURN ( _MKSMALLINT(POINTERARRAY) );
|
|
1007 |
%}
|
293
|
1008 |
"
|
|
1009 |
Behavior flagPointers
|
|
1010 |
"
|
92
|
1011 |
!
|
|
1012 |
|
|
1013 |
flagWeakPointers
|
|
1014 |
"return the flag code for weak pointer indexed instances (i.e. WeakArray)"
|
|
1015 |
|
|
1016 |
%{ /* NOCONTEXT */
|
|
1017 |
/* this is defined as a primitive to get defines from stc.h */
|
|
1018 |
|
|
1019 |
RETURN ( _MKSMALLINT(WKPOINTERARRAY) );
|
68
|
1020 |
%}
|
|
1021 |
!
|
|
1022 |
|
|
1023 |
maskIndexType
|
|
1024 |
"return a mask to extract all index-type bits"
|
|
1025 |
|
|
1026 |
%{ /* NOCONTEXT */
|
|
1027 |
/* this is defined as a primitive to get defines from stc.h */
|
|
1028 |
|
92
|
1029 |
RETURN ( _MKSMALLINT(ARRAYMASK) );
|
68
|
1030 |
%}
|
|
1031 |
!
|
|
1032 |
|
|
1033 |
flagBlock
|
|
1034 |
"return the flag code which marks Block-type instances"
|
|
1035 |
|
|
1036 |
%{ /* NOCONTEXT */
|
|
1037 |
/* this is defined as a primitive to get defines from stc.h */
|
|
1038 |
|
92
|
1039 |
RETURN ( _MKSMALLINT(BLOCK_INSTS) );
|
68
|
1040 |
%}
|
|
1041 |
!
|
|
1042 |
|
|
1043 |
flagMethod
|
|
1044 |
"return the flag code which marks Method-type instances"
|
|
1045 |
|
|
1046 |
%{ /* NOCONTEXT */
|
|
1047 |
/* this is defined as a primitive to get defines from stc.h */
|
|
1048 |
|
92
|
1049 |
RETURN ( _MKSMALLINT(METHOD_INSTS) );
|
68
|
1050 |
%}
|
|
1051 |
!
|
|
1052 |
|
|
1053 |
flagContext
|
|
1054 |
"return the flag code which marks Context-type instances"
|
|
1055 |
|
|
1056 |
%{ /* NOCONTEXT */
|
|
1057 |
/* this is defined as a primitive to get defines from stc.h */
|
|
1058 |
|
92
|
1059 |
RETURN ( _MKSMALLINT(CONTEXT_INSTS) );
|
68
|
1060 |
%}
|
|
1061 |
!
|
|
1062 |
|
|
1063 |
flagBlockContext
|
|
1064 |
"return the flag code which marks BlockContext-type instances"
|
|
1065 |
|
|
1066 |
%{ /* NOCONTEXT */
|
|
1067 |
/* this is defined as a primitive to get defines from stc.h */
|
|
1068 |
|
92
|
1069 |
RETURN ( _MKSMALLINT(BCONTEXT_INSTS) );
|
|
1070 |
%}
|
|
1071 |
!
|
|
1072 |
|
|
1073 |
flagFloat
|
|
1074 |
"return the flag code which marks Float-type instances"
|
|
1075 |
|
|
1076 |
%{ /* NOCONTEXT */
|
|
1077 |
/* this is defined as a primitive to get defines from stc.h */
|
|
1078 |
|
|
1079 |
RETURN ( _MKSMALLINT(FLOAT_INSTS) );
|
|
1080 |
%}
|
|
1081 |
!
|
|
1082 |
|
|
1083 |
flagSymbol
|
|
1084 |
"return the flag code which marks Symbol-type instances"
|
|
1085 |
|
|
1086 |
%{ /* NOCONTEXT */
|
|
1087 |
/* this is defined as a primitive to get defines from stc.h */
|
|
1088 |
|
|
1089 |
RETURN ( _MKSMALLINT(SYMBOL_INSTS) );
|
68
|
1090 |
%}
|
|
1091 |
! !
|
|
1092 |
|
1
|
1093 |
!Behavior methodsFor:'accessing'!
|
|
1094 |
|
91
|
1095 |
name
|
|
1096 |
"although behaviors have no name, we return something
|
|
1097 |
useful here - there are many places (inspectors) where
|
|
1098 |
a classes name is asked for.
|
|
1099 |
Implementing this message here allows anonymous classes
|
151
|
1100 |
and instances of them to be inspected."
|
91
|
1101 |
|
|
1102 |
^ 'someBehavior'
|
|
1103 |
!
|
|
1104 |
|
1
|
1105 |
superclass
|
|
1106 |
"return the receivers superclass"
|
|
1107 |
|
|
1108 |
^ superclass
|
|
1109 |
!
|
|
1110 |
|
68
|
1111 |
selectorArray
|
|
1112 |
"return the receivers selector array.
|
|
1113 |
Notice: this is not compatible with ST-80."
|
1
|
1114 |
|
91
|
1115 |
^ selectorArray
|
1
|
1116 |
!
|
|
1117 |
|
68
|
1118 |
methodArray
|
|
1119 |
"return the receivers method array.
|
|
1120 |
Notice: this is not compatible with ST-80."
|
1
|
1121 |
|
91
|
1122 |
^ methodArray
|
1
|
1123 |
!
|
|
1124 |
|
|
1125 |
methodDictionary
|
77
|
1126 |
"return the receivers method dictionary.
|
|
1127 |
Since no dictionary is actually present, create one for ST-80 compatibility."
|
68
|
1128 |
|
|
1129 |
|dict|
|
1
|
1130 |
|
68
|
1131 |
dict := IdentityDictionary new.
|
91
|
1132 |
1 to:selectorArray size do:[:index |
|
154
|
1133 |
dict at:(selectorArray at:index) put:(methodArray at:index)
|
68
|
1134 |
].
|
|
1135 |
^ dict
|
1
|
1136 |
!
|
|
1137 |
|
|
1138 |
instSize
|
68
|
1139 |
"return the number of instance variables of the receiver.
|
|
1140 |
This includes all superclass instance variables."
|
1
|
1141 |
|
|
1142 |
^ instSize
|
|
1143 |
!
|
|
1144 |
|
|
1145 |
flags
|
|
1146 |
"return the receivers flag bits"
|
|
1147 |
|
|
1148 |
^ flags
|
|
1149 |
!
|
|
1150 |
|
216
|
1151 |
superclass:aClass
|
|
1152 |
"set the superclass - this actually creates a new class,
|
|
1153 |
recompiling all methods for the new one. The receiving class stays
|
|
1154 |
around anonymous to allow existing instances some life.
|
|
1155 |
This may change in the future (adjusting existing instances)"
|
|
1156 |
|
308
|
1157 |
SubclassInfo := nil.
|
|
1158 |
|
216
|
1159 |
"must flush caches since lookup chain changes"
|
|
1160 |
ObjectMemory flushCaches.
|
|
1161 |
|
|
1162 |
"
|
|
1163 |
superclass := aClass
|
|
1164 |
"
|
|
1165 |
"for correct recompilation, just create a new class ..."
|
|
1166 |
|
|
1167 |
aClass subclass:(self name)
|
|
1168 |
instanceVariableNames:(self instanceVariableString)
|
|
1169 |
classVariableNames:(self classVariableString)
|
|
1170 |
poolDictionaries:''
|
|
1171 |
category:self category
|
|
1172 |
!
|
|
1173 |
|
|
1174 |
addSuperclass:aClass
|
|
1175 |
"EXPERIMENTAL MI support: add aClass to the set of classes, from which instances
|
|
1176 |
inherit protocol."
|
|
1177 |
|
|
1178 |
"first, check if the class is abstract -
|
|
1179 |
allows abstract mixins are allowed in the current implementation"
|
|
1180 |
|
|
1181 |
aClass instSize == 0 ifFalse:[
|
|
1182 |
self error:'only abstract mixins allowed'.
|
|
1183 |
^ self
|
|
1184 |
].
|
|
1185 |
otherSuperclasses isNil ifTrue:[
|
|
1186 |
otherSuperclasses := Array with:aClass
|
|
1187 |
] ifFalse:[
|
|
1188 |
otherSuperclasses := otherSuperclasses copyWith:aClass
|
|
1189 |
].
|
308
|
1190 |
SubclassInfo := nil.
|
216
|
1191 |
ObjectMemory flushCaches
|
|
1192 |
!
|
|
1193 |
|
|
1194 |
removeSuperclass:aClass
|
|
1195 |
"EXPERIMENTAL MI support: remove aClass from the set of classes, from which instances
|
|
1196 |
inherit protocol."
|
|
1197 |
|
|
1198 |
otherSuperclasses notNil ifTrue:[
|
|
1199 |
otherSuperclasses := otherSuperclasses copyWithout:aClass.
|
|
1200 |
otherSuperclasses isEmpty ifTrue:[
|
|
1201 |
otherSuperclasses := nil
|
|
1202 |
].
|
308
|
1203 |
SubclassInfo := nil.
|
216
|
1204 |
ObjectMemory flushCaches
|
|
1205 |
].
|
|
1206 |
!
|
|
1207 |
|
|
1208 |
selectors:newSelectors methods:newMethods
|
|
1209 |
"set both selector array and method array of the receiver,
|
|
1210 |
and flush caches"
|
|
1211 |
|
|
1212 |
ObjectMemory flushCaches.
|
|
1213 |
selectorArray := newSelectors.
|
|
1214 |
methodArray := newMethods
|
|
1215 |
!
|
|
1216 |
|
|
1217 |
addSelector:newSelector withMethod:newMethod
|
|
1218 |
"add the method given by 2nd argument under the selector given by
|
|
1219 |
1st argument to the methodDictionary. Flush all caches."
|
|
1220 |
|
|
1221 |
|nargs|
|
|
1222 |
|
249
|
1223 |
(self primAddSelector:newSelector withMethod:newMethod) ifFalse:[^ false].
|
216
|
1224 |
self changed:#methodDictionary with:newSelector.
|
|
1225 |
|
|
1226 |
"
|
|
1227 |
if I have no subclasses, all we have to flush is cached
|
|
1228 |
data for myself ... (actually, in any case all that needs
|
|
1229 |
to be flushed is info for myself and all of my subclasses)
|
|
1230 |
"
|
|
1231 |
"
|
|
1232 |
problem: this is slower; since looking for all subclasses is (currently)
|
|
1233 |
a bit slow :-(
|
|
1234 |
We need the hasSubclasses-info bit in Behavior; now
|
|
1235 |
|
|
1236 |
self withAllSubclassesDo:[:aClass |
|
|
1237 |
ObjectMemory flushInlineCachesFor:aClass withArgs:nargs.
|
|
1238 |
ObjectMemory flushMethodCacheFor:aClass
|
|
1239 |
].
|
|
1240 |
"
|
|
1241 |
|
|
1242 |
"
|
|
1243 |
actually, we would do better with less flushing ...
|
|
1244 |
"
|
|
1245 |
nargs := newSelector numArgs.
|
|
1246 |
|
|
1247 |
ObjectMemory flushMethodCache.
|
|
1248 |
ObjectMemory flushInlineCachesWithArgs:nargs.
|
|
1249 |
|
|
1250 |
^ true
|
|
1251 |
!
|
|
1252 |
|
|
1253 |
addSelector:newSelector withLazyMethod:newMethod
|
|
1254 |
"add the method given by 2nd argument under the selector given by
|
|
1255 |
1st argument to the methodDictionary. Since it does not flush
|
|
1256 |
any caches, this is only allowed for lazy methods."
|
|
1257 |
|
|
1258 |
newMethod isLazyMethod ifFalse:[
|
|
1259 |
self error:'operation only allowed for lazy methods'.
|
|
1260 |
^ false
|
|
1261 |
].
|
249
|
1262 |
(self primAddSelector:newSelector withMethod:newMethod) ifTrue:[
|
216
|
1263 |
self changed:#methodDictionary with:newSelector.
|
|
1264 |
^ true
|
|
1265 |
].
|
|
1266 |
^ false
|
|
1267 |
!
|
|
1268 |
|
|
1269 |
removeSelector:aSelector
|
|
1270 |
"remove the selector, aSelector and its associated method
|
|
1271 |
from the methodDictionary"
|
|
1272 |
|
|
1273 |
|index oldSelectorArray oldMethodArray newSelectorArray newMethodArray|
|
|
1274 |
|
|
1275 |
index := selectorArray identityIndexOf:aSelector startingAt:1.
|
|
1276 |
(index == 0) ifTrue:[^ false].
|
|
1277 |
|
|
1278 |
newSelectorArray := selectorArray copyWithoutIndex:index.
|
|
1279 |
newMethodArray := methodArray copyWithoutIndex:index.
|
|
1280 |
oldSelectorArray := selectorArray.
|
|
1281 |
oldMethodArray := methodArray.
|
|
1282 |
selectorArray := newSelectorArray.
|
|
1283 |
methodArray := newMethodArray.
|
|
1284 |
"
|
|
1285 |
[
|
|
1286 |
|nargs|
|
|
1287 |
nargs := aSelector numArgs.
|
|
1288 |
ObjectMemory flushMethodCache.
|
|
1289 |
ObjectMemory flushInlineCachesWithArgs:nargs.
|
|
1290 |
] value
|
|
1291 |
"
|
|
1292 |
"
|
|
1293 |
actually, we would do better with less flushing ...
|
|
1294 |
"
|
|
1295 |
ObjectMemory flushCaches.
|
|
1296 |
^ true
|
|
1297 |
! !
|
|
1298 |
|
|
1299 |
!Behavior methodsFor:'queries'!
|
|
1300 |
|
127
|
1301 |
sizeOfInst:n
|
|
1302 |
"return the number of bytes required for an instance of
|
|
1303 |
myself with n indexed instance variables. The argument n
|
|
1304 |
should be zero for classes without indexed instance variables.
|
|
1305 |
See Behavior>>niceNew: for an application of this."
|
216
|
1306 |
|
127
|
1307 |
|nInstvars|
|
|
1308 |
|
|
1309 |
nInstvars := self instSize.
|
|
1310 |
%{
|
|
1311 |
int nBytes;
|
|
1312 |
|
|
1313 |
nBytes = _intVal(nInstvars) * sizeof(OBJ) + OHDR_SIZE;
|
249
|
1314 |
if (__isSmallInteger(n)) {
|
154
|
1315 |
int nIndex;
|
127
|
1316 |
|
154
|
1317 |
nIndex = _intVal(n);
|
|
1318 |
switch (_intVal(_INST(flags)) & ARRAYMASK) {
|
|
1319 |
case BYTEARRAY:
|
|
1320 |
nBytes += nIndex;
|
|
1321 |
if (nBytes & (ALIGN - 1)) {
|
|
1322 |
nBytes = (nBytes & ~(ALIGN - 1)) + ALIGN;
|
|
1323 |
}
|
|
1324 |
break;
|
127
|
1325 |
|
154
|
1326 |
case WORDARRAY:
|
|
1327 |
nBytes += nIndex * sizeof(short);
|
|
1328 |
if (nBytes & (ALIGN - 1)) {
|
|
1329 |
nBytes = (nBytes & ~(ALIGN - 1)) + ALIGN;
|
|
1330 |
}
|
|
1331 |
break;
|
127
|
1332 |
|
154
|
1333 |
case LONGARRAY:
|
|
1334 |
nBytes += nIndex * sizeof(long);
|
|
1335 |
break;
|
127
|
1336 |
|
154
|
1337 |
case FLOATARRAY:
|
|
1338 |
nBytes += nIndex * sizeof(float);
|
|
1339 |
break;
|
127
|
1340 |
|
154
|
1341 |
case DOUBLEARRAY:
|
|
1342 |
nBytes += nIndex * sizeof(double);
|
|
1343 |
break;
|
127
|
1344 |
|
154
|
1345 |
default:
|
|
1346 |
nBytes += nIndex * sizeof(OBJ);
|
|
1347 |
break;
|
|
1348 |
}
|
127
|
1349 |
}
|
|
1350 |
RETURN (_MKSMALLINT(nBytes));
|
|
1351 |
%}
|
|
1352 |
!
|
|
1353 |
|
1
|
1354 |
isVariable
|
|
1355 |
"return true, if instances have indexed instance variables"
|
|
1356 |
|
68
|
1357 |
"this could be defined as:
|
154
|
1358 |
^ (flags bitAnd:(Behavior maskIndexType)) ~~ 0
|
68
|
1359 |
"
|
1
|
1360 |
|
|
1361 |
%{ /* NOCONTEXT */
|
|
1362 |
|
|
1363 |
RETURN ( (_intVal(_INST(flags)) & ARRAYMASK) ? true : false );
|
|
1364 |
%}
|
|
1365 |
!
|
|
1366 |
|
|
1367 |
isFixed
|
|
1368 |
"return true, if instances do not have indexed instance variables"
|
|
1369 |
|
68
|
1370 |
"this could be defined as:
|
154
|
1371 |
^ self isVariable not
|
68
|
1372 |
"
|
|
1373 |
|
1
|
1374 |
%{ /* NOCONTEXT */
|
|
1375 |
|
|
1376 |
RETURN ( (_intVal(_INST(flags)) & ARRAYMASK) ? false : true );
|
|
1377 |
%}
|
|
1378 |
!
|
|
1379 |
|
|
1380 |
isBits
|
|
1381 |
"return true, if instances have indexed byte or short instance variables.
|
68
|
1382 |
Ignore long, float and double arrays, since ST-80 code using isBits are probably
|
1
|
1383 |
not prepared to handle them correctly."
|
|
1384 |
|
|
1385 |
%{ /* NOCONTEXT */
|
|
1386 |
|
|
1387 |
REGISTER int flags;
|
|
1388 |
|
|
1389 |
RETURN ( (((flags = (_intVal(_INST(flags)) & ARRAYMASK)) == BYTEARRAY)
|
154
|
1390 |
|| (flags == WORDARRAY)) ? true : false );
|
1
|
1391 |
%}
|
|
1392 |
!
|
|
1393 |
|
|
1394 |
isBytes
|
|
1395 |
"return true, if instances have indexed byte instance variables"
|
|
1396 |
|
68
|
1397 |
"this could be defined as:
|
154
|
1398 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagBytes
|
68
|
1399 |
"
|
1
|
1400 |
%{ /* NOCONTEXT */
|
|
1401 |
|
|
1402 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == BYTEARRAY) ? true : false );
|
|
1403 |
%}
|
|
1404 |
!
|
|
1405 |
|
|
1406 |
isWords
|
|
1407 |
"return true, if instances have indexed short instance variables"
|
|
1408 |
|
68
|
1409 |
"this could be defined as:
|
154
|
1410 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagWords
|
68
|
1411 |
"
|
1
|
1412 |
%{ /* NOCONTEXT */
|
|
1413 |
|
|
1414 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == WORDARRAY) ? true : false );
|
|
1415 |
%}
|
|
1416 |
!
|
|
1417 |
|
|
1418 |
isLongs
|
|
1419 |
"return true, if instances have indexed long instance variables"
|
|
1420 |
|
68
|
1421 |
"this could be defined as:
|
154
|
1422 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagLongs
|
68
|
1423 |
"
|
1
|
1424 |
%{ /* NOCONTEXT */
|
|
1425 |
|
|
1426 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == LONGARRAY) ? true : false );
|
|
1427 |
%}
|
|
1428 |
!
|
|
1429 |
|
|
1430 |
isFloats
|
|
1431 |
"return true, if instances have indexed float instance variables"
|
|
1432 |
|
68
|
1433 |
"this could be defined as:
|
154
|
1434 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagFloats
|
68
|
1435 |
"
|
1
|
1436 |
%{ /* NOCONTEXT */
|
68
|
1437 |
|
1
|
1438 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == FLOATARRAY) ? true : false );
|
|
1439 |
%}
|
|
1440 |
!
|
|
1441 |
|
|
1442 |
isDoubles
|
|
1443 |
"return true, if instances have indexed double instance variables"
|
|
1444 |
|
68
|
1445 |
"this could be defined as:
|
154
|
1446 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagDoubles
|
68
|
1447 |
"
|
1
|
1448 |
%{ /* NOCONTEXT */
|
68
|
1449 |
|
1
|
1450 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == DOUBLEARRAY) ? true : false );
|
|
1451 |
%}
|
|
1452 |
!
|
|
1453 |
|
|
1454 |
isPointers
|
2
|
1455 |
"return true, if instances have pointer instance variables
|
|
1456 |
i.e. are either non-indexed or have indexed pointer variables"
|
1
|
1457 |
|
68
|
1458 |
"QUESTION: should we ignore WeakPointers ?"
|
|
1459 |
|
1
|
1460 |
%{ /* NOCONTEXT */
|
68
|
1461 |
|
1
|
1462 |
REGISTER int flags;
|
|
1463 |
|
2
|
1464 |
flags = _intVal(_INST(flags)) & ARRAYMASK;
|
|
1465 |
switch (flags) {
|
154
|
1466 |
default:
|
|
1467 |
/* normal objects */
|
|
1468 |
RETURN ( true );
|
2
|
1469 |
|
154
|
1470 |
case BYTEARRAY:
|
|
1471 |
case WORDARRAY:
|
|
1472 |
case LONGARRAY:
|
|
1473 |
case FLOATARRAY:
|
|
1474 |
case DOUBLEARRAY:
|
|
1475 |
RETURN (false );
|
2
|
1476 |
|
154
|
1477 |
case WKPOINTERARRAY:
|
|
1478 |
/* what about those ? */
|
|
1479 |
RETURN (true );
|
2
|
1480 |
}
|
1
|
1481 |
%}
|
2
|
1482 |
!
|
|
1483 |
|
1
|
1484 |
isBehavior
|
47
|
1485 |
"return true, if the receiver is describing another objects behavior,
|
45
|
1486 |
i.e. is a class. Defined to avoid the need to use isKindOf:"
|
1
|
1487 |
|
|
1488 |
^ true
|
45
|
1489 |
|
91
|
1490 |
"
|
|
1491 |
True isBehavior
|
|
1492 |
true isBehavior
|
|
1493 |
"
|
1
|
1494 |
!
|
|
1495 |
|
47
|
1496 |
canBeSubclassed
|
|
1497 |
"return true, if its allowed to create subclasses of the receiver.
|
|
1498 |
This method is redefined in SmallInteger and UndefinedObject, since
|
68
|
1499 |
instances are detected by their pointer-fields, i.e. they do not have
|
|
1500 |
a class entry (you dont have to understand this :-)"
|
47
|
1501 |
|
|
1502 |
^ true
|
|
1503 |
!
|
|
1504 |
|
1
|
1505 |
hasMultipleSuperclasses
|
68
|
1506 |
"Return true, if this class inherits from other classes
|
|
1507 |
(beside its primary superclass).
|
|
1508 |
This method is a preparation for a future multiple inheritance extension
|
|
1509 |
- currently it is not supported by the VM"
|
1
|
1510 |
|
68
|
1511 |
^ otherSuperclasses notNil
|
1
|
1512 |
!
|
|
1513 |
|
|
1514 |
superclasses
|
68
|
1515 |
"return a collection of the receivers immediate superclasses.
|
|
1516 |
This method is a preparation for a future multiple inheritance extension
|
|
1517 |
- currently it is not supported by the VM"
|
1
|
1518 |
|
68
|
1519 |
otherSuperclasses notNil ifTrue:[
|
154
|
1520 |
^ (Array with:superclass) , otherSuperclasses
|
68
|
1521 |
].
|
1
|
1522 |
^ Array with:superclass
|
45
|
1523 |
|
91
|
1524 |
"
|
|
1525 |
String superclasses
|
|
1526 |
"
|
1
|
1527 |
!
|
|
1528 |
|
|
1529 |
allSuperclasses
|
|
1530 |
"return a collection of the receivers accumulated superclasses"
|
|
1531 |
|
|
1532 |
|aCollection theSuperClass|
|
|
1533 |
|
|
1534 |
theSuperClass := superclass.
|
|
1535 |
theSuperClass notNil ifTrue:[
|
154
|
1536 |
aCollection := OrderedCollection new.
|
|
1537 |
[theSuperClass notNil] whileTrue:[
|
|
1538 |
aCollection add:theSuperClass.
|
|
1539 |
theSuperClass := theSuperClass superclass
|
|
1540 |
]
|
1
|
1541 |
].
|
|
1542 |
^ aCollection
|
45
|
1543 |
|
91
|
1544 |
"
|
|
1545 |
String allSuperclasses
|
|
1546 |
"
|
1
|
1547 |
!
|
|
1548 |
|
|
1549 |
withAllSuperclasses
|
|
1550 |
"return a collection containing the receiver and all
|
|
1551 |
of the receivers accumulated superclasses"
|
|
1552 |
|
|
1553 |
|aCollection theSuperClass|
|
|
1554 |
|
|
1555 |
aCollection := OrderedCollection with:self.
|
|
1556 |
theSuperClass := superclass.
|
|
1557 |
[theSuperClass notNil] whileTrue:[
|
154
|
1558 |
aCollection add:theSuperClass.
|
|
1559 |
theSuperClass := theSuperClass superclass
|
1
|
1560 |
].
|
|
1561 |
^ aCollection
|
45
|
1562 |
|
91
|
1563 |
"
|
|
1564 |
String withAllSuperclasses
|
|
1565 |
"
|
1
|
1566 |
!
|
|
1567 |
|
|
1568 |
subclasses
|
|
1569 |
"return a collection of the direct subclasses of the receiver"
|
|
1570 |
|
|
1571 |
|newColl|
|
|
1572 |
|
308
|
1573 |
SubclassInfo notNil ifTrue:[
|
|
1574 |
newColl := SubclassInfo at:self ifAbsent:nil.
|
|
1575 |
newColl notNil ifTrue:[^ newColl asOrderedCollection]
|
|
1576 |
].
|
|
1577 |
|
1
|
1578 |
newColl := OrderedCollection new.
|
|
1579 |
self subclassesDo:[:aClass |
|
154
|
1580 |
newColl add:aClass
|
1
|
1581 |
].
|
|
1582 |
^ newColl
|
45
|
1583 |
|
91
|
1584 |
"
|
|
1585 |
Collection subclasses
|
|
1586 |
"
|
1
|
1587 |
!
|
|
1588 |
|
|
1589 |
allSubclasses
|
|
1590 |
"return a collection of all subclasses (direct AND indirect) of
|
45
|
1591 |
the receiver. There will be no specific order, in which entries
|
|
1592 |
are returned."
|
1
|
1593 |
|
|
1594 |
|newColl|
|
|
1595 |
|
|
1596 |
newColl := OrderedCollection new.
|
|
1597 |
self allSubclassesDo:[:aClass |
|
154
|
1598 |
newColl add:aClass
|
1
|
1599 |
].
|
|
1600 |
^ newColl
|
45
|
1601 |
|
91
|
1602 |
"
|
|
1603 |
Collection allSubclasses
|
|
1604 |
"
|
45
|
1605 |
!
|
|
1606 |
|
|
1607 |
allSubclassesInOrder
|
|
1608 |
"return a collection of all subclasses (direct AND indirect) of
|
|
1609 |
the receiver. Higher level subclasses will come before lower ones."
|
|
1610 |
|
|
1611 |
|newColl|
|
|
1612 |
|
|
1613 |
newColl := OrderedCollection new.
|
|
1614 |
self allSubclassesInOrderDo:[:aClass |
|
154
|
1615 |
newColl add:aClass
|
45
|
1616 |
].
|
|
1617 |
^ newColl
|
|
1618 |
|
91
|
1619 |
"
|
|
1620 |
Collection allSubclassesInOrder
|
|
1621 |
"
|
1
|
1622 |
!
|
|
1623 |
|
|
1624 |
withAllSubclasses
|
|
1625 |
"return a collection containing the receiver and
|
|
1626 |
all subclasses (direct AND indirect) of the receiver"
|
|
1627 |
|
|
1628 |
|newColl|
|
|
1629 |
|
|
1630 |
newColl := OrderedCollection with:self.
|
|
1631 |
self allSubclassesDo:[:aClass |
|
154
|
1632 |
newColl add:aClass
|
1
|
1633 |
].
|
|
1634 |
^ newColl
|
45
|
1635 |
|
91
|
1636 |
"
|
|
1637 |
Collection withAllSubclasses
|
|
1638 |
"
|
1
|
1639 |
!
|
|
1640 |
|
|
1641 |
isSubclassOf:aClass
|
|
1642 |
"return true, if I am a subclass of the argument, aClass"
|
|
1643 |
|
|
1644 |
|theClass|
|
2
|
1645 |
|
1
|
1646 |
theClass := superclass.
|
|
1647 |
[theClass notNil] whileTrue:[
|
154
|
1648 |
(theClass == aClass) ifTrue:[^ true].
|
|
1649 |
theClass := theClass superclass
|
1
|
1650 |
].
|
|
1651 |
^ false
|
45
|
1652 |
|
91
|
1653 |
"
|
|
1654 |
String isSubclassOf:Collection
|
|
1655 |
LinkedList isSubclassOf:Array
|
|
1656 |
1 isSubclassOf:Number <- will fail since 1 is no class
|
|
1657 |
"
|
1
|
1658 |
!
|
|
1659 |
|
151
|
1660 |
allInstVarNames
|
|
1661 |
"return a collection of all the instance variable name-strings
|
|
1662 |
this includes all superclass-instance variables.
|
|
1663 |
Since Behavior has no idea of instvar-names, return an empty collection
|
|
1664 |
here. Redefined in ClassDescription."
|
|
1665 |
|
|
1666 |
^ #()
|
|
1667 |
!
|
|
1668 |
|
|
1669 |
allClassVarNames
|
|
1670 |
"return a collection of all the class variable name-strings
|
|
1671 |
this includes all superclass-class variables.
|
|
1672 |
Since Behavior has no idea of classvar-names, return an empty collection
|
|
1673 |
here. Redefined in ClassDescription."
|
|
1674 |
|
|
1675 |
^ #()
|
|
1676 |
!
|
|
1677 |
|
1
|
1678 |
allInstances
|
|
1679 |
"return a collection of all my instances"
|
|
1680 |
|
|
1681 |
|coll|
|
|
1682 |
|
165
|
1683 |
coll := OrderedCollection new:100.
|
45
|
1684 |
self allInstancesDo:[:anObject |
|
154
|
1685 |
coll add:anObject
|
1
|
1686 |
].
|
68
|
1687 |
^ coll
|
25
|
1688 |
|
91
|
1689 |
"
|
|
1690 |
ScrollBar allInstances
|
|
1691 |
"
|
25
|
1692 |
!
|
|
1693 |
|
328
|
1694 |
allSubInstances
|
25
|
1695 |
"return a collection of all instances of myself and
|
328
|
1696 |
instances of all subclasses of myself."
|
25
|
1697 |
|
|
1698 |
|coll|
|
|
1699 |
|
165
|
1700 |
coll := OrderedCollection new:100.
|
331
|
1701 |
self allSubInstancesDo:[:anObject |
|
154
|
1702 |
(anObject isKindOf:self) ifTrue:[
|
|
1703 |
coll add:anObject
|
|
1704 |
]
|
25
|
1705 |
].
|
68
|
1706 |
^ coll
|
25
|
1707 |
|
91
|
1708 |
"
|
328
|
1709 |
View allSubInstances
|
91
|
1710 |
"
|
1
|
1711 |
!
|
|
1712 |
|
328
|
1713 |
allDerivedInstances
|
|
1714 |
"return a collection of all instances of myself and
|
|
1715 |
instances of all subclasses of myself.
|
|
1716 |
This method is going to be removed for protocol compatibility with
|
|
1717 |
other STs; use allSubInstances"
|
|
1718 |
|
|
1719 |
self obsoleteMethodWarning.
|
|
1720 |
^ self allSubInstances
|
|
1721 |
!
|
|
1722 |
|
154
|
1723 |
hasInstances
|
|
1724 |
"return true, if there are any instances of myself"
|
|
1725 |
|
|
1726 |
ObjectMemory allObjectsDo:[:anObject |
|
|
1727 |
(anObject class == self) ifTrue:[
|
|
1728 |
^ true
|
|
1729 |
]
|
|
1730 |
].
|
|
1731 |
^ false
|
|
1732 |
|
|
1733 |
"
|
|
1734 |
Object hasInstances
|
|
1735 |
SequenceableCollection hasInstances
|
|
1736 |
Float hasInstances
|
|
1737 |
"
|
|
1738 |
!
|
|
1739 |
|
1
|
1740 |
instanceCount
|
|
1741 |
"return the number of instances of myself"
|
|
1742 |
|
|
1743 |
|count|
|
|
1744 |
|
|
1745 |
count := 0.
|
|
1746 |
ObjectMemory allObjectsDo:[:anObject |
|
154
|
1747 |
(anObject class == self) ifTrue:[
|
|
1748 |
count := count + 1
|
|
1749 |
]
|
1
|
1750 |
].
|
|
1751 |
^ count
|
45
|
1752 |
|
91
|
1753 |
"
|
|
1754 |
View instanceCount
|
154
|
1755 |
Object instanceCount
|
|
1756 |
Float instanceCount
|
|
1757 |
SequenceableCollection instanceCount
|
91
|
1758 |
"
|
45
|
1759 |
!
|
|
1760 |
|
|
1761 |
derivedInstanceCount
|
|
1762 |
"return the number of instances of myself and of subclasses"
|
|
1763 |
|
|
1764 |
|count|
|
|
1765 |
|
|
1766 |
count := 0.
|
|
1767 |
ObjectMemory allObjectsDo:[:anObject |
|
154
|
1768 |
(anObject isKindOf:self) ifTrue:[
|
|
1769 |
count := count + 1
|
|
1770 |
]
|
45
|
1771 |
].
|
|
1772 |
^ count
|
|
1773 |
|
91
|
1774 |
"
|
|
1775 |
View derivedInstanceCount
|
154
|
1776 |
SequenceableCollection derivedInstanceCount
|
91
|
1777 |
"
|
2
|
1778 |
!
|
|
1779 |
|
|
1780 |
selectorIndex:aSelector
|
|
1781 |
"return the index in the arrays for given selector aSelector"
|
|
1782 |
|
91
|
1783 |
^ selectorArray identityIndexOf:aSelector startingAt:1
|
2
|
1784 |
!
|
|
1785 |
|
295
|
1786 |
includesSelector:aSelector
|
|
1787 |
"for ST-80 compatibility"
|
|
1788 |
|
|
1789 |
^ self implements:aSelector
|
|
1790 |
!
|
|
1791 |
|
2
|
1792 |
compiledMethodAt:aSelector
|
68
|
1793 |
"return the method for given selector aSelector or nil.
|
|
1794 |
Only methods in the receiver - not in the superclass chain are tested."
|
2
|
1795 |
|
|
1796 |
|index|
|
|
1797 |
|
328
|
1798 |
selectorArray isNil ifTrue:[
|
|
1799 |
('oops: nil selectorArray in ' , self name) errorPrintNL.
|
|
1800 |
^ nil
|
|
1801 |
].
|
|
1802 |
|
91
|
1803 |
index := selectorArray identityIndexOf:aSelector startingAt:1.
|
2
|
1804 |
(index == 0) ifTrue:[^ nil].
|
91
|
1805 |
^ methodArray at:index
|
45
|
1806 |
|
91
|
1807 |
"
|
|
1808 |
Object compiledMethodAt:#==
|
|
1809 |
(Object compiledMethodAt:#==) category
|
|
1810 |
"
|
2
|
1811 |
!
|
|
1812 |
|
|
1813 |
sourceCodeAt:aSelector
|
68
|
1814 |
"return the methods source for given selector aSelector or nil.
|
|
1815 |
Only methods in the receiver - not in the superclass chain are tested."
|
2
|
1816 |
|
3
|
1817 |
|method|
|
2
|
1818 |
|
3
|
1819 |
method := self compiledMethodAt:aSelector.
|
|
1820 |
method isNil ifTrue:[^ nil].
|
|
1821 |
^ method source
|
2
|
1822 |
|
91
|
1823 |
"
|
|
1824 |
True sourceCodeAt:#ifTrue:
|
|
1825 |
Object sourceCodeAt:#==
|
|
1826 |
Behavior sourceCodeAt:#sourceCodeAt:
|
|
1827 |
"
|
2
|
1828 |
!
|
|
1829 |
|
68
|
1830 |
lookupMethodFor:aSelector
|
|
1831 |
"return the method, which would be executed if aSelector was sent to
|
|
1832 |
an instance of the receiver. I.e. the selector arrays of the receiver
|
|
1833 |
and all of its superclasses are searched for aSelector.
|
|
1834 |
Return the method, or nil if instances do not understand aSelector.
|
|
1835 |
EXPERIMENTAL: take care of multiple superclasses."
|
|
1836 |
|
|
1837 |
|m cls|
|
|
1838 |
|
|
1839 |
cls := self.
|
|
1840 |
[cls notNil] whileTrue:[
|
154
|
1841 |
m := cls compiledMethodAt:aSelector.
|
|
1842 |
m notNil ifTrue:[^ m].
|
|
1843 |
cls hasMultipleSuperclasses ifTrue:[
|
|
1844 |
cls superclasses do:[:aSuperClass |
|
|
1845 |
m := aSuperClass lookupMethodFor:aSelector.
|
|
1846 |
m notNil ifTrue:[^ m].
|
|
1847 |
].
|
|
1848 |
^ nil
|
|
1849 |
] ifFalse:[
|
|
1850 |
cls := cls superclass
|
|
1851 |
]
|
68
|
1852 |
].
|
|
1853 |
^ nil
|
|
1854 |
!
|
|
1855 |
|
|
1856 |
cachedLookupMethodFor:aSelector
|
|
1857 |
"return the method, which would be executed if aSelector was sent to
|
|
1858 |
an instance of the receiver. I.e. the selector arrays of the receiver
|
|
1859 |
and all of its superclasses are searched for aSelector.
|
|
1860 |
Return the method, or nil if instances do not understand aSelector.
|
|
1861 |
This interface provides exactly the same information as #lookupMethodFor:,
|
|
1862 |
but uses the lookup-cache in the VM for faster search.
|
|
1863 |
However, keep in mind, that doing a lookup through the cache also adds new
|
|
1864 |
entries and can thus slow down the system by polluting the cache with
|
|
1865 |
irrelevant entries. (do NOT loop over all objects calling this method).
|
|
1866 |
Does NOT (currently) handle MI"
|
|
1867 |
|
|
1868 |
%{ /* NOCONTEXT */
|
|
1869 |
extern OBJ lookup();
|
|
1870 |
|
|
1871 |
RETURN ( lookup(self, aSelector, SENDER) );
|
|
1872 |
%}
|
|
1873 |
|
91
|
1874 |
"
|
|
1875 |
String cachedLookupMethodFor:#=
|
|
1876 |
String cachedLookupMethodFor:#asOrderedCollection
|
|
1877 |
"
|
68
|
1878 |
!
|
|
1879 |
|
2
|
1880 |
hasMethods
|
|
1881 |
"return true, if there are any (local) methods in this class"
|
|
1882 |
|
91
|
1883 |
^ (methodArray size ~~ 0)
|
10
|
1884 |
|
91
|
1885 |
"
|
|
1886 |
True hasMethods
|
|
1887 |
True class hasMethods
|
|
1888 |
"
|
2
|
1889 |
!
|
|
1890 |
|
|
1891 |
implements:aSelector
|
68
|
1892 |
"return true, if the receiver implements aSelector.
|
|
1893 |
(i.e. implemented in THIS class - NOT in a superclass).
|
10
|
1894 |
Dont use this method to check if someone responds to a message -
|
45
|
1895 |
use #canUnderstand: on the class or #respondsTo: on the instance
|
10
|
1896 |
to do this."
|
2
|
1897 |
|
91
|
1898 |
^ (selectorArray identityIndexOf:aSelector startingAt:1) ~~ 0
|
2
|
1899 |
|
91
|
1900 |
"
|
|
1901 |
True implements:#ifTrue:
|
|
1902 |
True implements:#==
|
|
1903 |
"
|
2
|
1904 |
!
|
|
1905 |
|
|
1906 |
canUnderstand:aSelector
|
68
|
1907 |
"return true, if the receiver or one of its superclasses implements aSelector.
|
|
1908 |
(i.e. true if my instances understand aSelector)"
|
2
|
1909 |
|
68
|
1910 |
^ (self lookupMethodFor:aSelector) notNil
|
10
|
1911 |
|
91
|
1912 |
"
|
|
1913 |
True canUnderstand:#ifTrue:
|
|
1914 |
True canUnderstand:#==
|
|
1915 |
True canUnderstand:#do:
|
|
1916 |
"
|
2
|
1917 |
!
|
|
1918 |
|
|
1919 |
whichClassImplements:aSelector
|
328
|
1920 |
"obsolete interface;
|
|
1921 |
use whichClassIncludesSelector: for ST-80 compatibility."
|
|
1922 |
|
|
1923 |
^ self whichClassIncludesSelector:aSelector
|
|
1924 |
!
|
|
1925 |
|
|
1926 |
whichClassIncludesSelector:aSelector
|
68
|
1927 |
"return the class in the inheritance chain, which implements the method
|
|
1928 |
for aSelector; return nil if none.
|
|
1929 |
EXPERIMENTAL: handle multiple superclasses"
|
|
1930 |
|
|
1931 |
|cls|
|
2
|
1932 |
|
68
|
1933 |
cls := self.
|
|
1934 |
[cls notNil] whileTrue:[
|
154
|
1935 |
(cls implements:aSelector) ifTrue:[^ cls].
|
|
1936 |
cls hasMultipleSuperclasses ifTrue:[
|
|
1937 |
cls superclasses do:[:aSuperClass |
|
|
1938 |
|implementingClass|
|
2
|
1939 |
|
328
|
1940 |
implementingClass := aSuperClass whichClassIncludesSelector:aSelector.
|
154
|
1941 |
implementingClass notNil ifTrue:[^ implementingClass].
|
|
1942 |
].
|
|
1943 |
^ nil
|
|
1944 |
] ifFalse:[
|
|
1945 |
cls := cls superclass
|
|
1946 |
]
|
2
|
1947 |
].
|
|
1948 |
^ nil
|
|
1949 |
|
91
|
1950 |
"
|
328
|
1951 |
String whichClassIncludesSelector:#==
|
|
1952 |
String whichClassIncludesSelector:#collect:
|
91
|
1953 |
"
|
2
|
1954 |
!
|
|
1955 |
|
|
1956 |
inheritsFrom:aClass
|
68
|
1957 |
"return true, if the receiver inherits methods from aClass"
|
2
|
1958 |
|
|
1959 |
^ self isSubclassOf:aClass
|
45
|
1960 |
|
91
|
1961 |
"
|
|
1962 |
True inheritsFrom:Object
|
|
1963 |
LinkedList inheritsFrom:Array
|
|
1964 |
"
|
2
|
1965 |
!
|
|
1966 |
|
154
|
1967 |
selectorAtMethod:aMethod ifAbsent:failBlock
|
|
1968 |
"return the selector for given method aMethod
|
|
1969 |
or the value of failBlock, if not found."
|
2
|
1970 |
|
|
1971 |
|index|
|
|
1972 |
|
91
|
1973 |
index := methodArray identityIndexOf:aMethod startingAt:1.
|
154
|
1974 |
(index == 0) ifTrue:[^ failBlock value].
|
91
|
1975 |
^ selectorArray at:index
|
154
|
1976 |
|
|
1977 |
"
|
|
1978 |
|m|
|
|
1979 |
|
|
1980 |
m := Object compiledMethodAt:#copy.
|
328
|
1981 |
Object selectorAtMethod:m ifAbsent:['oops'].
|
154
|
1982 |
"
|
|
1983 |
"
|
|
1984 |
|m|
|
|
1985 |
|
|
1986 |
m := Object compiledMethodAt:#copy.
|
328
|
1987 |
Fraction selectorAtMethod:m ifAbsent:['oops'].
|
154
|
1988 |
"
|
|
1989 |
!
|
|
1990 |
|
328
|
1991 |
selectorAtMethod:aMethod
|
154
|
1992 |
"Return the selector for given method aMethod."
|
|
1993 |
|
|
1994 |
^ self selectorAtMethod:aMethod ifAbsent:[nil]
|
328
|
1995 |
|
|
1996 |
"
|
|
1997 |
|m|
|
|
1998 |
|
|
1999 |
m := Object compiledMethodAt:#copy.
|
|
2000 |
Fraction selectorAtMethod:m.
|
|
2001 |
"
|
|
2002 |
"
|
|
2003 |
|m|
|
|
2004 |
|
|
2005 |
m := Object compiledMethodAt:#copy.
|
|
2006 |
Object selectorAtMethod:m.
|
|
2007 |
"
|
2
|
2008 |
!
|
|
2009 |
|
|
2010 |
containsMethod:aMethod
|
77
|
2011 |
"Return true, if the argument, aMethod is a method of myself"
|
2
|
2012 |
|
91
|
2013 |
methodArray isNil ifTrue:[^ false]. "degenerated class"
|
|
2014 |
^ (methodArray identityIndexOf:aMethod startingAt:1) ~~ 0
|
1
|
2015 |
! !
|
|
2016 |
|
|
2017 |
!Behavior methodsFor:'private accessing'!
|
|
2018 |
|
|
2019 |
setSuperclass:sup selectors:sels methods:m instSize:i flags:f
|
45
|
2020 |
"set some inst vars.
|
77
|
2021 |
this method is for special uses only - there will be no recompilation
|
198
|
2022 |
and no change record is written here. Also, if the receiver class has
|
|
2023 |
already been in use, future operation of the system is not guaranteed to
|
|
2024 |
be correct, since no caches are flushed.
|
|
2025 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)"
|
1
|
2026 |
|
308
|
2027 |
SubclassInfo := nil.
|
1
|
2028 |
superclass := sup.
|
91
|
2029 |
selectorArray := sels.
|
|
2030 |
methodArray := m.
|
1
|
2031 |
instSize := i.
|
|
2032 |
flags := f
|
|
2033 |
!
|
|
2034 |
|
|
2035 |
setSuperclass:aClass
|
45
|
2036 |
"set the superclass of the receiver.
|
77
|
2037 |
this method is for special uses only - there will be no recompilation
|
198
|
2038 |
and no change record written here. Also, if the receiver class has
|
|
2039 |
already been in use, future operation of the system is not guaranteed to
|
|
2040 |
be correct, since no caches are flushed.
|
|
2041 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)"
|
1
|
2042 |
|
308
|
2043 |
SubclassInfo := nil.
|
1
|
2044 |
superclass := aClass
|
|
2045 |
!
|
|
2046 |
|
68
|
2047 |
setOtherSuperclasses:anArrayOfClasses
|
|
2048 |
"EXPERIMENTAL: set the other superclasses of the receiver.
|
77
|
2049 |
this method is for special uses only - there will be no recompilation
|
68
|
2050 |
and no change record written here;
|
|
2051 |
Do NOT use it."
|
|
2052 |
|
308
|
2053 |
SubclassInfo := nil.
|
68
|
2054 |
otherSuperclasses := anArrayOfClasses
|
|
2055 |
!
|
|
2056 |
|
1
|
2057 |
instSize:aNumber
|
45
|
2058 |
"set the instance size.
|
77
|
2059 |
this method is for special uses only - there will be no recompilation
|
68
|
2060 |
and no change record written here;
|
|
2061 |
Do NOT use it."
|
1
|
2062 |
|
|
2063 |
instSize := aNumber
|
|
2064 |
!
|
|
2065 |
|
|
2066 |
flags:aNumber
|
45
|
2067 |
"set the flags.
|
77
|
2068 |
this method is for special uses only - there will be no recompilation
|
68
|
2069 |
and no change record written here;
|
|
2070 |
Do NOT use it."
|
1
|
2071 |
|
|
2072 |
flags := aNumber
|
|
2073 |
!
|
|
2074 |
|
154
|
2075 |
setSelectors:sels methods:m
|
|
2076 |
"set some inst vars.
|
|
2077 |
this method is for special uses only - there will be no recompilation
|
|
2078 |
and no change record written here;
|
|
2079 |
Do NOT use it."
|
|
2080 |
|
|
2081 |
selectorArray := sels.
|
|
2082 |
methodArray := m.
|
|
2083 |
!
|
|
2084 |
|
77
|
2085 |
setSelectorArray:anArray
|
45
|
2086 |
"set the selector array of the receiver.
|
77
|
2087 |
this method is for special uses only - there will be no recompilation
|
|
2088 |
and no change record written here.
|
|
2089 |
NOT for general use."
|
1
|
2090 |
|
91
|
2091 |
selectorArray := anArray
|
1
|
2092 |
!
|
|
2093 |
|
77
|
2094 |
setMethodArray:anArray
|
45
|
2095 |
"set the method array of the receiver.
|
77
|
2096 |
this method is for special uses only - there will be no recompilation
|
|
2097 |
and no change record written here.
|
|
2098 |
NOT for general use."
|
1
|
2099 |
|
91
|
2100 |
methodArray := anArray
|
77
|
2101 |
!
|
|
2102 |
|
|
2103 |
setMethodDictionary:aDictionary
|
|
2104 |
"set the receivers method dictionary.
|
|
2105 |
Since no dictionary is actually used, decompose into selector- and
|
|
2106 |
method arrays and set those. For ST-80 compatibility.
|
|
2107 |
NOT for general use."
|
|
2108 |
|
91
|
2109 |
|n newSelectorArray newMethodArray idx|
|
77
|
2110 |
|
|
2111 |
n := aDictionary size.
|
91
|
2112 |
newSelectorArray := Array new:n.
|
|
2113 |
newMethodArray := Array new:n.
|
77
|
2114 |
idx := 1.
|
|
2115 |
aDictionary keysAndValuesDo:[:sel :method |
|
154
|
2116 |
newSelectorArray at:idx put:sel.
|
|
2117 |
newMethodArray at:idx put:method.
|
|
2118 |
idx := idx + 1
|
77
|
2119 |
].
|
91
|
2120 |
selectorArray := newSelectorArray.
|
|
2121 |
methodArray := newMethodArray
|
|
2122 |
!
|
|
2123 |
|
249
|
2124 |
primAddSelector:newSelector withMethod:newMethod
|
91
|
2125 |
"add the method given by 2nd argument under the selector given by
|
|
2126 |
the 1st argument to the methodDictionary.
|
249
|
2127 |
Does NOT flush any caches, does NOT write a change record.
|
91
|
2128 |
|
|
2129 |
Do not use this in normal situations, strange behavior will be
|
|
2130 |
the consequence.
|
|
2131 |
I.e. executing obsolete methods, since the old method will still
|
|
2132 |
be executed out of the caches."
|
|
2133 |
|
|
2134 |
|index oldSelectorArray oldMethodArray newSelectorArray newMethodArray|
|
|
2135 |
|
|
2136 |
(newSelector isMemberOf:Symbol) ifFalse:[
|
154
|
2137 |
self error:'invalid selector'.
|
|
2138 |
^ false
|
91
|
2139 |
].
|
|
2140 |
newMethod isNil ifTrue:[
|
154
|
2141 |
self error:'invalid method'.
|
|
2142 |
^ false
|
91
|
2143 |
].
|
|
2144 |
|
|
2145 |
index := selectorArray identityIndexOf:newSelector startingAt:1.
|
|
2146 |
(index == 0) ifTrue:[
|
154
|
2147 |
"
|
|
2148 |
a new selector
|
|
2149 |
"
|
|
2150 |
newSelectorArray := selectorArray copyWith:newSelector.
|
|
2151 |
newMethodArray := methodArray copyWith:newMethod.
|
|
2152 |
"
|
|
2153 |
keep a reference so they wont go away ...
|
|
2154 |
mhmh: this is no longer needed - try without
|
|
2155 |
"
|
|
2156 |
oldSelectorArray := selectorArray.
|
|
2157 |
oldMethodArray := methodArray.
|
|
2158 |
selectorArray := newSelectorArray.
|
|
2159 |
methodArray := newMethodArray
|
91
|
2160 |
] ifFalse:[
|
154
|
2161 |
methodArray at:index put:newMethod
|
91
|
2162 |
].
|
|
2163 |
^ true
|
1
|
2164 |
! !
|
|
2165 |
|
68
|
2166 |
!Behavior methodsFor:'compiler interface'!
|
|
2167 |
|
|
2168 |
compiler
|
249
|
2169 |
"return the compiler to use for this class.
|
|
2170 |
This is the old interface, kept for migration. Dont use it."
|
|
2171 |
|
308
|
2172 |
^ self compilerClass
|
249
|
2173 |
!
|
|
2174 |
|
|
2175 |
compilerClass
|
68
|
2176 |
"return the compiler to use for this class -
|
|
2177 |
this can be redefined in special classes, to get classes with
|
|
2178 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax."
|
|
2179 |
|
|
2180 |
^ Compiler
|
|
2181 |
! !
|
|
2182 |
|
216
|
2183 |
!Behavior methodsFor:'enumerating'!
|
1
|
2184 |
|
|
2185 |
allInstancesDo:aBlock
|
45
|
2186 |
"evaluate aBlock for all of my instances"
|
1
|
2187 |
|
|
2188 |
ObjectMemory allObjectsDo:[:anObject |
|
154
|
2189 |
(anObject class == self) ifTrue:[
|
|
2190 |
aBlock value:anObject
|
|
2191 |
]
|
1
|
2192 |
]
|
45
|
2193 |
|
91
|
2194 |
"
|
|
2195 |
StandardSystemView allInstancesDo:[:v | Transcript showCr:(v name)]
|
|
2196 |
"
|
45
|
2197 |
!
|
|
2198 |
|
|
2199 |
allDerivedInstancesDo:aBlock
|
328
|
2200 |
"evaluate aBlock for all of my instances and all instances of subclasses.
|
|
2201 |
This method is going to be removed for protocol compatibility with
|
|
2202 |
other STs; use allSubInstancesDo:"
|
|
2203 |
|
|
2204 |
self obsoleteMethodWarning.
|
|
2205 |
self allSubInstancesDo:aBlock
|
|
2206 |
|
|
2207 |
"
|
|
2208 |
StandardSystemView allDerivedInstancesDo:[:v | Transcript showCr:(v name)]
|
|
2209 |
"
|
|
2210 |
!
|
|
2211 |
|
|
2212 |
allSubInstancesDo:aBlock
|
45
|
2213 |
"evaluate aBlock for all of my instances and all instances of subclasses"
|
|
2214 |
|
|
2215 |
ObjectMemory allObjectsDo:[:anObject |
|
154
|
2216 |
(anObject isKindOf:self) ifTrue:[
|
|
2217 |
aBlock value:anObject
|
|
2218 |
]
|
45
|
2219 |
]
|
|
2220 |
|
91
|
2221 |
"
|
328
|
2222 |
StandardSystemView allSubInstancesDo:[:v | Transcript showCr:(v name)]
|
91
|
2223 |
"
|
1
|
2224 |
!
|
|
2225 |
|
|
2226 |
subclassesDo:aBlock
|
198
|
2227 |
"evaluate the argument, aBlock for all immediate subclasses.
|
|
2228 |
This will only enumerate globally known classes - for anonymous
|
|
2229 |
behaviors, you have to walk over all instances of Behavior."
|
1
|
2230 |
|
308
|
2231 |
|coll|
|
|
2232 |
|
|
2233 |
SubclassInfo isNil ifTrue:[
|
|
2234 |
Behavior subclassInfo
|
|
2235 |
].
|
|
2236 |
SubclassInfo notNil ifTrue:[
|
|
2237 |
coll := SubclassInfo at:self ifAbsent:nil.
|
|
2238 |
coll notNil ifTrue:[
|
|
2239 |
coll do:aBlock.
|
|
2240 |
].
|
|
2241 |
^ self
|
|
2242 |
].
|
|
2243 |
|
2
|
2244 |
Smalltalk allBehaviorsDo:[:aClass |
|
154
|
2245 |
(aClass superclass == self) ifTrue:[
|
|
2246 |
aBlock value:aClass
|
|
2247 |
]
|
1
|
2248 |
]
|
45
|
2249 |
|
154
|
2250 |
"
|
|
2251 |
Collection subclassesDo:[:c | Transcript showCr:(c name)]
|
|
2252 |
"
|
1
|
2253 |
!
|
|
2254 |
|
|
2255 |
allSubclassesDo:aBlock
|
45
|
2256 |
"evaluate aBlock for all of my subclasses.
|
198
|
2257 |
There is no specific order, in which the entries are enumerated.
|
|
2258 |
This will only enumerate globally known classes - for anonymous
|
|
2259 |
behaviors, you have to walk over all instances of Behavior."
|
1
|
2260 |
|
2
|
2261 |
Smalltalk allBehaviorsDo:[:aClass |
|
154
|
2262 |
(aClass isSubclassOf:self) ifTrue:[
|
|
2263 |
aBlock value:aClass
|
|
2264 |
]
|
1
|
2265 |
]
|
45
|
2266 |
|
198
|
2267 |
"
|
|
2268 |
Collection allSubclassesDo:[:c | Transcript showCr:(c name)]
|
|
2269 |
"
|
1
|
2270 |
!
|
|
2271 |
|
|
2272 |
allSubclassesInOrderDo:aBlock
|
45
|
2273 |
"evaluate aBlock for all of my subclasses.
|
198
|
2274 |
Higher level subclasses will be enumerated before the deeper ones,
|
|
2275 |
so the order in which aBlock gets called is ok to fileOut classes in
|
|
2276 |
correct order for later fileIn.
|
|
2277 |
This will only enumerate globally known classes - for anonymous
|
|
2278 |
behaviors, you have to walk over all instances of Behavior"
|
1
|
2279 |
|
|
2280 |
self subclassesDo:[:aClass |
|
154
|
2281 |
aBlock value:aClass.
|
|
2282 |
aClass allSubclassesInOrderDo:aBlock
|
1
|
2283 |
]
|
45
|
2284 |
|
198
|
2285 |
"
|
|
2286 |
Collection allSubclassesInOrderDo:[:c | Transcript showCr:(c name)]
|
|
2287 |
"
|
1
|
2288 |
!
|
|
2289 |
|
|
2290 |
allSuperclassesDo:aBlock
|
45
|
2291 |
"evaluate aBlock for all of my superclasses"
|
1
|
2292 |
|
|
2293 |
|theClass|
|
|
2294 |
|
|
2295 |
theClass := superclass.
|
|
2296 |
[theClass notNil] whileTrue:[
|
154
|
2297 |
aBlock value:theClass.
|
|
2298 |
theClass := theClass superclass
|
1
|
2299 |
]
|
45
|
2300 |
|
198
|
2301 |
"
|
|
2302 |
String allSuperclassesDo:[:c | Transcript showCr:(c name)]
|
|
2303 |
"
|
1
|
2304 |
! !
|
2
|
2305 |
|
68
|
2306 |
!Behavior methodsFor:'binary storage'!
|
2
|
2307 |
|
343
|
2308 |
storeBinaryDefinitionOn: stream manager: manager
|
|
2309 |
"binary store of a classes definition.
|
|
2310 |
Classes will store the name only and restore by looking for
|
|
2311 |
that name in the Smalltalk dictionary."
|
|
2312 |
|
|
2313 |
| myName |
|
|
2314 |
|
|
2315 |
myName := self name.
|
|
2316 |
stream nextNumber:4 put:self signature.
|
|
2317 |
stream nextNumber:2 put:0.
|
|
2318 |
stream nextNumber:2 put:myName size.
|
|
2319 |
myName do:[:c|
|
|
2320 |
stream nextPut:c asciiValue
|
|
2321 |
]
|
|
2322 |
|
|
2323 |
"
|
|
2324 |
|s|
|
|
2325 |
s := WriteStream on:ByteArray new.
|
|
2326 |
#(1 2 3 4) storeBinaryOn:s.
|
|
2327 |
Object readBinaryFrom:(ReadStream on:s contents)
|
|
2328 |
|
|
2329 |
|s|
|
|
2330 |
s := WriteStream on:ByteArray new.
|
|
2331 |
Rectangle storeBinaryOn:s.
|
|
2332 |
Object readBinaryFrom:(ReadStream on:s contents)
|
|
2333 |
"
|
|
2334 |
!
|
|
2335 |
|
11
|
2336 |
readBinaryFrom:aStream
|
|
2337 |
"read an objects binary representation from the argument,
|
|
2338 |
aStream and return it.
|
198
|
2339 |
The read object must be a kind of myself, otherwise an error is raised.
|
|
2340 |
To get any object, use 'Object readBinaryFrom:...',
|
|
2341 |
To get any number, use 'Number readBinaryFrom:...' and so on.
|
|
2342 |
This is the reverse operation to 'storeBinaryOn:'. "
|
|
2343 |
|
|
2344 |
^ self readBinaryFrom:aStream onError:[self error:('expected ' , self name)]
|
|
2345 |
|
|
2346 |
"
|
|
2347 |
|s|
|
|
2348 |
s := WriteStream on:(ByteArray new).
|
|
2349 |
#(1 2 3 4) storeBinaryOn:s.
|
|
2350 |
Object readBinaryFrom:(ReadStream on:s contents)
|
|
2351 |
"
|
|
2352 |
"
|
|
2353 |
|s|
|
|
2354 |
s := 'testFile' asFilename writeStream binary.
|
|
2355 |
#(1 2 3 4) storeBinaryOn:s.
|
|
2356 |
'hello world' storeBinaryOn:s.
|
|
2357 |
s close.
|
|
2358 |
|
|
2359 |
s := 'testFile' asFilename readStream binary.
|
|
2360 |
Transcript showCr:(Object readBinaryFrom:s).
|
|
2361 |
Transcript showCr:(Object readBinaryFrom:s).
|
|
2362 |
s close.
|
|
2363 |
"
|
|
2364 |
!
|
|
2365 |
|
|
2366 |
readBinaryFrom:aStream onError:exceptionBlock
|
|
2367 |
"read an objects binary representation from the argument,
|
|
2368 |
aStream and return it.
|
|
2369 |
The read object must be a kind of myself, otherwise the value of
|
|
2370 |
the exceptionBlock is returned.
|
|
2371 |
To get any object, use 'Object readBinaryFrom:...',
|
|
2372 |
To get any number, use 'Number readBinaryFrom:...' and so on.
|
11
|
2373 |
This is the reverse operation to 'storeBinaryOn:'. "
|
|
2374 |
|
|
2375 |
|newObject|
|
|
2376 |
|
|
2377 |
newObject := (BinaryInputManager new:1024) readFrom:aStream.
|
198
|
2378 |
(newObject isKindOf:self) ifFalse:[^ exceptionBlock value].
|
11
|
2379 |
^ newObject
|
|
2380 |
|
91
|
2381 |
"
|
|
2382 |
|s|
|
198
|
2383 |
s := WriteStream on:(ByteArray new).
|
11
|
2384 |
#(1 2 3 4) storeBinaryOn:s.
|
198
|
2385 |
Object readBinaryFrom:(ReadStream on:s contents) onError:['oops']
|
|
2386 |
"
|
|
2387 |
"
|
|
2388 |
|s|
|
|
2389 |
s := WriteStream on:(ByteArray new).
|
|
2390 |
#[1 2 3 4] storeBinaryOn:s.
|
|
2391 |
Array readBinaryFrom:(ReadStream on:s contents) onError:['oops']
|
11
|
2392 |
"
|
|
2393 |
!
|
|
2394 |
|
43
|
2395 |
binaryDefinitionFrom:stream manager:manager
|
343
|
2396 |
"sent during a binary read by the input manager.
|
|
2397 |
Read the definition on an empty instance (of my class) from stream.
|
43
|
2398 |
All pointer instances are left nil, while all bits are read in here.
|
|
2399 |
return the new object."
|
2
|
2400 |
|
43
|
2401 |
|obj t
|
|
2402 |
basicSize "{ Class: SmallInteger }" |
|
2
|
2403 |
|
|
2404 |
self isPointers ifTrue: [
|
343
|
2405 |
"/
|
|
2406 |
"/ inst size not needed - if you uncomment the line below,
|
|
2407 |
"/ also uncomment the corresponding line in
|
|
2408 |
"/ Object>>storeBinaryDefinitionOn:manager:
|
|
2409 |
"/
|
|
2410 |
"/ stream next. "skip instSize"
|
154
|
2411 |
self isVariable ifTrue: [
|
|
2412 |
^ self basicNew:(stream nextNumber:3)
|
|
2413 |
].
|
|
2414 |
^ self basicNew
|
2
|
2415 |
].
|
|
2416 |
|
343
|
2417 |
"
|
|
2418 |
an object with bit-valued instance variables.
|
|
2419 |
These are read here.
|
|
2420 |
"
|
43
|
2421 |
basicSize := stream nextNumber:4.
|
|
2422 |
obj := self basicNew:basicSize.
|
|
2423 |
|
2
|
2424 |
self isBytes ifTrue: [
|
154
|
2425 |
stream nextBytes:basicSize into:obj
|
2
|
2426 |
] ifFalse: [
|
154
|
2427 |
self isWords ifTrue: [
|
|
2428 |
1 to:basicSize do:[:i |
|
213
|
2429 |
obj basicAt:i put:(stream nextNumber:2)
|
154
|
2430 |
]
|
|
2431 |
] ifFalse:[
|
|
2432 |
self isLongs ifTrue: [
|
|
2433 |
1 to:basicSize do:[:i |
|
213
|
2434 |
obj basicAt:i put:(stream nextNumber:4)
|
154
|
2435 |
]
|
|
2436 |
] ifFalse:[
|
|
2437 |
self isFloats ifTrue: [
|
|
2438 |
"could do it in one big read on machines which use IEEE floats ..."
|
343
|
2439 |
t := Float basicNew.
|
154
|
2440 |
1 to:basicSize do:[:i |
|
|
2441 |
Float readBinaryIEEESingleFrom:stream into:t.
|
|
2442 |
obj basicAt:i put: t
|
|
2443 |
]
|
|
2444 |
] ifFalse:[
|
|
2445 |
self isDoubles ifTrue: [
|
|
2446 |
"could do it in one big read on machines which use IEEE doubles ..."
|
343
|
2447 |
t := Float basicNew.
|
154
|
2448 |
1 to:basicSize do:[:i |
|
|
2449 |
Float readBinaryIEEEDoubleFrom:stream into:t.
|
|
2450 |
obj basicAt:i put: t
|
|
2451 |
]
|
|
2452 |
]
|
|
2453 |
]
|
|
2454 |
]
|
|
2455 |
]
|
2
|
2456 |
].
|
|
2457 |
^obj
|
308
|
2458 |
!
|
|
2459 |
|
|
2460 |
canCloneFrom:anObject
|
|
2461 |
"return true, if this class can clone an obsolete object as retrieved
|
|
2462 |
by a binary load. Subclasses which do not want to have obsolete objects
|
343
|
2463 |
be converted, should redefine this method to return false.
|
|
2464 |
(However, conversion is never done silently in a binary load; you
|
|
2465 |
have to have a handler for the binaryload errors and for the conversion
|
|
2466 |
request signal.)"
|
308
|
2467 |
|
|
2468 |
^ true
|
|
2469 |
!
|
|
2470 |
|
|
2471 |
cloneFrom:aPrototype
|
|
2472 |
"return an instance of myself with variables initialized from
|
343
|
2473 |
a prototype. This is used when instances of obsolete classes are
|
|
2474 |
binary loaded and a conversion is done on the obsolete object.
|
|
2475 |
UserClasses may redefine this for better conversions."
|
308
|
2476 |
|
|
2477 |
|newInst indexed myInfo otherInfo varIndexAssoc|
|
|
2478 |
|
|
2479 |
indexed := false.
|
|
2480 |
aPrototype class isVariable ifTrue:[
|
|
2481 |
self isVariable ifTrue:[
|
|
2482 |
indexed := true.
|
|
2483 |
].
|
|
2484 |
"otherwise, these are lost ..."
|
|
2485 |
].
|
|
2486 |
indexed ifTrue:[
|
|
2487 |
newInst := self basicNew:aPrototype basicSize
|
|
2488 |
] ifFalse:[
|
|
2489 |
newInst := self basicNew
|
|
2490 |
].
|
|
2491 |
|
|
2492 |
myInfo := self instanceVariableOffsets.
|
|
2493 |
otherInfo := aPrototype class instanceVariableOffsets.
|
|
2494 |
myInfo keysAndValuesDo:[:name :index |
|
|
2495 |
varIndexAssoc := otherInfo at:name ifAbsent:[].
|
|
2496 |
varIndexAssoc notNil ifTrue:[
|
|
2497 |
newInst instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value))
|
|
2498 |
]
|
|
2499 |
].
|
|
2500 |
indexed ifTrue:[
|
|
2501 |
1 to:aPrototype basicSize do:[:index |
|
|
2502 |
newInst basicAt:index put:(aPrototype basicAt:index)
|
|
2503 |
].
|
|
2504 |
].
|
|
2505 |
^ newInst
|
|
2506 |
|
|
2507 |
"
|
|
2508 |
Class updateChanges:false.
|
|
2509 |
Point subclass:#Point3D
|
|
2510 |
instanceVariableNames:'z'
|
|
2511 |
classVariableNames:''
|
|
2512 |
poolDictionaries:''
|
|
2513 |
category:'testing'.
|
|
2514 |
(Point3D cloneFrom:1@2) inspect.
|
|
2515 |
Class updateChanges:true.
|
|
2516 |
"
|
|
2517 |
|
|
2518 |
"
|
|
2519 |
Class updateChanges:false.
|
|
2520 |
Point variableSubclass:#Point3D
|
|
2521 |
instanceVariableNames:'z'
|
|
2522 |
classVariableNames:''
|
|
2523 |
poolDictionaries:''
|
|
2524 |
category:'testing'.
|
|
2525 |
(Point3D cloneFrom:#(1 2 3)) inspect.
|
|
2526 |
Class updateChanges:true.
|
|
2527 |
"
|
|
2528 |
|
|
2529 |
"
|
|
2530 |
|someObject|
|
|
2531 |
|
|
2532 |
Class updateChanges:false.
|
|
2533 |
Object subclass:#TestClass1
|
|
2534 |
instanceVariableNames:'foo bar'
|
|
2535 |
classVariableNames:''
|
|
2536 |
poolDictionaries:''
|
|
2537 |
category:'testing'.
|
|
2538 |
someObject := TestClass1 new.
|
|
2539 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'.
|
|
2540 |
Object subclass:#TestClass2
|
|
2541 |
instanceVariableNames:'bar foo'
|
|
2542 |
classVariableNames:''
|
|
2543 |
poolDictionaries:''
|
|
2544 |
category:'testing'.
|
|
2545 |
(TestClass2 cloneFrom:someObject) inspect.
|
|
2546 |
Class updateChanges:true.
|
|
2547 |
"
|
2
|
2548 |
! !
|