1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
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
|
|
14 |
instanceVariableNames:'superclass selectors methods
|
|
15 |
instSize flags'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Kernel-Classes'
|
|
19 |
!
|
|
20 |
|
|
21 |
Behavior comment:'
|
|
22 |
|
5
|
23 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
24 |
All Rights Reserved
|
|
25 |
|
47
|
26 |
NOTICE: layout known by compiler and runtime system; be careful when changing
|
|
27 |
|
54
|
28 |
$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.11 1994-02-25 12:54:13 claus Exp $
|
47
|
29 |
written Dec 88 by claus
|
|
30 |
'!
|
|
31 |
|
|
32 |
!Behavior class methodsFor:'documentation'!
|
|
33 |
|
|
34 |
documentation
|
|
35 |
"
|
1
|
36 |
this class provides minimum support for all classes - additional stuff is
|
|
37 |
found in Class; Behaviors stuff has been extracted to make generation of
|
47
|
38 |
compact binaries possible. (these do not need all of the functionality
|
|
39 |
in Class) However, stc cannot yet produce output for Behaviors instead
|
|
40 |
of Classes.
|
|
41 |
|
|
42 |
In contrast to other ST implementations, the Methods have been separated
|
|
43 |
from the selectors - this avoids the need for knowledge about Dictionaries
|
|
44 |
in the runtime library (lookup and search in these is seldom anyway, so
|
|
45 |
the added benefit from using a hashed dictionary is almost void).
|
1
|
46 |
|
|
47 |
Instance variables:
|
|
48 |
|
|
49 |
superclass <Class> the classes superclass
|
|
50 |
selectors <Array> the selectors for which inst-methods are defined here
|
|
51 |
methods <Array> the inst-methods corresponding to the selectors
|
|
52 |
instSize <SmallInteger> the number of instance variables
|
|
53 |
flags <SmallInteger> special flag bits coded in a number
|
|
54 |
|
47
|
55 |
flag bits:
|
|
56 |
|
|
57 |
2r 0000 0000 1111 index type:
|
|
58 |
0 - not indexed
|
|
59 |
1 - byte indexed
|
|
60 |
2 - short indexed
|
|
61 |
3 - long indexed
|
|
62 |
4 - pointer indexed
|
|
63 |
5 - weak pointer indexed
|
|
64 |
6 - float indexed
|
|
65 |
7 - double indexed
|
|
66 |
|
|
67 |
8-15 reserved for future extensions
|
1
|
68 |
|
47
|
69 |
2r 0000 0001 0000 reserved for alien pointers extension
|
|
70 |
2r 0000 0010 0000 class has subclasses - not set/used currently
|
|
71 |
|
|
72 |
2r 0000 0100 0000 instances are blocks (alien ptr in code)
|
|
73 |
2r 0000 1000 0000 instances are methods (alien ptr in code)
|
|
74 |
|
|
75 |
2r 0001 0000 0000 instances are contexts
|
|
76 |
2r 0010 0000 0000 instances are block contexts
|
|
77 |
|
|
78 |
2r 0100 0000 0000 reserved for C++ extension
|
|
79 |
2r 1000 0000 0000 reserved for objectiveC extension
|
|
80 |
|
|
81 |
NOTICE: layout known by compiler and runtime system; be careful when changing
|
|
82 |
"
|
|
83 |
! !
|
1
|
84 |
|
3
|
85 |
!Behavior class methodsFor:'queries'!
|
|
86 |
|
|
87 |
isBuiltInClass
|
|
88 |
"this class is known by the run-time-system"
|
|
89 |
|
|
90 |
^ true
|
|
91 |
! !
|
|
92 |
|
1
|
93 |
!Behavior class methodsFor:'creating new classes'!
|
|
94 |
|
|
95 |
new
|
|
96 |
"creates and return a new class"
|
|
97 |
|
|
98 |
|newClass|
|
|
99 |
|
|
100 |
newClass := self basicNew.
|
|
101 |
newClass setSuperclass:Object
|
|
102 |
selectors:(Array new:0)
|
|
103 |
methods:(Array new:0)
|
|
104 |
instSize:0
|
|
105 |
flags:0.
|
|
106 |
^ newClass
|
|
107 |
! !
|
|
108 |
|
|
109 |
!Behavior methodsFor:'initialization'!
|
|
110 |
|
|
111 |
initialize
|
|
112 |
"to catch initialize for classes which do not"
|
|
113 |
|
|
114 |
^ self
|
|
115 |
!
|
|
116 |
|
|
117 |
reinitialize
|
|
118 |
"to catch reinitialize for classes which do not"
|
|
119 |
|
|
120 |
^ self
|
|
121 |
! !
|
|
122 |
|
11
|
123 |
!Behavior methodsFor:'copying'!
|
|
124 |
|
|
125 |
deepCopy
|
|
126 |
"return a deep copy of the receiver
|
|
127 |
- return the receiver here - time will show if this is ok"
|
|
128 |
|
|
129 |
^ self
|
|
130 |
!
|
|
131 |
|
|
132 |
deepCopyUsing:aDictionary
|
|
133 |
"return a deep copy of the receiver
|
|
134 |
- return the receiver here - time will show if this is ok"
|
|
135 |
|
|
136 |
^ self
|
|
137 |
!
|
|
138 |
|
|
139 |
simpleDeepCopy
|
|
140 |
"return a deep copy of the receiver
|
|
141 |
- return the receiver here - time will show if this is ok"
|
|
142 |
|
|
143 |
^ self
|
|
144 |
! !
|
|
145 |
|
1
|
146 |
!Behavior methodsFor:'creating an instance of myself'!
|
|
147 |
|
|
148 |
uninitializedNew
|
3
|
149 |
"same as new - only redefined in ByteArray"
|
1
|
150 |
|
|
151 |
^ self basicNew
|
|
152 |
!
|
|
153 |
|
|
154 |
uninitializedNew:anInteger
|
3
|
155 |
"same as new:anInteger - only redefined in ByteArray"
|
1
|
156 |
|
|
157 |
^ self basicNew:anInteger
|
|
158 |
!
|
|
159 |
|
|
160 |
new
|
|
161 |
"return an instance of myself without indexed variables"
|
|
162 |
|
|
163 |
^ self basicNew
|
|
164 |
!
|
|
165 |
|
|
166 |
new:anInteger
|
|
167 |
"return an instance of myself with anInteger indexed variables"
|
|
168 |
|
|
169 |
^ self basicNew:anInteger
|
|
170 |
!
|
|
171 |
|
|
172 |
basicNew
|
54
|
173 |
"return an instance of myself without indexed variables.
|
1
|
174 |
If the receiver-class has indexed instvars, the new object will have
|
54
|
175 |
a basicSize of zero - i.e. 'aClass basicNew' is equivalent to 'aClass basicNew:0'.
|
|
176 |
|
1
|
177 |
** Do not redefine this method in any class **"
|
|
178 |
|
|
179 |
%{ /* NOCONTEXT */
|
|
180 |
|
11
|
181 |
OBJ new();
|
1
|
182 |
OBJ newobj;
|
|
183 |
int instsize;
|
|
184 |
REGISTER int nInstVars;
|
|
185 |
|
54
|
186 |
/*
|
|
187 |
* the following ugly code is nothing more than a new() followed
|
|
188 |
* by a nilling of the new instance.
|
|
189 |
* unrolled for a bit more speed since this is one the central object allocation
|
|
190 |
* methods in the system
|
|
191 |
*/
|
1
|
192 |
nInstVars = _intVal(_INST(instSize));
|
|
193 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ);
|
54
|
194 |
|
|
195 |
newobj = newNextPtr;
|
|
196 |
if (allocSpace && (((char *)newobj + instsize) < newEndPtr)) {
|
|
197 |
_objPtr(newobj)->o_size = instsize;
|
|
198 |
o_allFlags(newobj) = 0;
|
|
199 |
_objPtr(newobj)->o_space = allocSpace;
|
|
200 |
if (instsize & (ALIGN-1)) {
|
|
201 |
newNextPtr = (char *)newobj + (instsize & ~(ALIGN-1)) + ALIGN;
|
|
202 |
} else {
|
|
203 |
newNextPtr = (char *)newobj + instsize;
|
|
204 |
}
|
|
205 |
|
|
206 |
/*
|
|
207 |
* save nil-check in this case
|
|
208 |
* stupid: c-compilers should find this out themselfes ...
|
|
209 |
*/
|
25
|
210 |
goto ok;
|
11
|
211 |
} else {
|
|
212 |
PROTECT_CONTEXT
|
|
213 |
newobj = new(instsize, SENDER);
|
|
214 |
UNPROTECT_CONTEXT
|
|
215 |
}
|
25
|
216 |
|
2
|
217 |
if (newobj != nil) {
|
11
|
218 |
ok:
|
2
|
219 |
_InstPtr(newobj)->o_class = self;
|
1
|
220 |
|
2
|
221 |
if (nInstVars) {
|
1
|
222 |
#if defined(memset4)
|
2
|
223 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
|
1
|
224 |
#else
|
|
225 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
2
|
226 |
/*
|
|
227 |
* knowing that nil is 0
|
|
228 |
*/
|
|
229 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
1
|
230 |
# else
|
54
|
231 |
REGISTER OBJ *op;
|
|
232 |
|
2
|
233 |
op = _InstPtr(newobj)->i_instvars;
|
54
|
234 |
# ifdef FAST_MEMSET_WORDS_UNROLLED
|
|
235 |
while (nInstVars > 8) {
|
|
236 |
*op++ = nil;
|
|
237 |
*op++ = nil;
|
|
238 |
*op++ = nil;
|
|
239 |
*op++ = nil;
|
|
240 |
*op++ = nil;
|
|
241 |
*op++ = nil;
|
|
242 |
*op++ = nil;
|
|
243 |
*op++ = nil;
|
|
244 |
nInstVars -= 8;
|
|
245 |
}
|
|
246 |
# endif
|
2
|
247 |
do {
|
|
248 |
*op++ = nil;
|
|
249 |
} while (--nInstVars);
|
1
|
250 |
# endif
|
|
251 |
#endif
|
2
|
252 |
}
|
|
253 |
RETURN ( newobj );
|
1
|
254 |
}
|
|
255 |
%}
|
2
|
256 |
.
|
|
257 |
ObjectMemory allocationFailureSignal raise
|
1
|
258 |
!
|
|
259 |
|
|
260 |
basicNew:anInteger
|
|
261 |
"return an instance of myself with anInteger indexed variables.
|
|
262 |
If the receiver-class has no indexed instvars, this is only allowed
|
|
263 |
if the argument, anInteger is zero.
|
|
264 |
** Do not redefine this method in any class **"
|
|
265 |
|
|
266 |
%{ /* NOCONTEXT */
|
|
267 |
|
|
268 |
OBJ newobj;
|
|
269 |
INT instsize, nInstVars, nindexedinstvars;
|
|
270 |
INT flags;
|
|
271 |
#if ! defined(FAST_MEMSET) || defined(NEGATIVE_ADDRESSES)
|
|
272 |
REGISTER char *cp;
|
|
273 |
short *sp;
|
|
274 |
long *lp;
|
|
275 |
#endif
|
|
276 |
REGISTER OBJ *op;
|
|
277 |
float *fp;
|
|
278 |
double *dp;
|
|
279 |
extern OBJ new();
|
|
280 |
|
|
281 |
if (_isSmallInteger(anInteger)) {
|
|
282 |
nindexedinstvars = _intVal(anInteger);
|
|
283 |
if (nindexedinstvars >= 0) {
|
25
|
284 |
PROTECT_CONTEXT
|
1
|
285 |
nInstVars = _intVal(_INST(instSize));
|
|
286 |
flags = _intVal(_INST(flags)) & ARRAYMASK;
|
|
287 |
switch (flags) {
|
|
288 |
case BYTEARRAY:
|
|
289 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ) + nindexedinstvars * sizeof(char);
|
|
290 |
_qNew(newobj, instsize, SENDER);
|
25
|
291 |
UNPROTECT_CONTEXT
|
3
|
292 |
if (newobj == nil) {
|
|
293 |
break;
|
|
294 |
}
|
1
|
295 |
_InstPtr(newobj)->o_class = self;
|
|
296 |
#if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
|
297 |
/*
|
|
298 |
* knowing that nil is 0
|
|
299 |
*/
|
|
300 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
301 |
#else
|
|
302 |
op = _InstPtr(newobj)->i_instvars;
|
|
303 |
while (nInstVars--)
|
|
304 |
*op++ = nil;
|
|
305 |
cp = (char *)op;
|
|
306 |
while (nindexedinstvars >= sizeof(long)) {
|
|
307 |
*(long *)cp = 0;
|
2
|
308 |
cp += sizeof(long);
|
|
309 |
nindexedinstvars -= sizeof(long);
|
|
310 |
}
|
1
|
311 |
while (nindexedinstvars--)
|
|
312 |
*cp++ = '\0';
|
|
313 |
#endif
|
|
314 |
RETURN ( newobj );
|
|
315 |
break;
|
|
316 |
|
|
317 |
case WORDARRAY:
|
|
318 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ) + nindexedinstvars * sizeof(short);
|
|
319 |
_qNew(newobj, instsize, SENDER);
|
25
|
320 |
UNPROTECT_CONTEXT
|
3
|
321 |
if (newobj == nil) {
|
|
322 |
break;
|
|
323 |
}
|
1
|
324 |
_InstPtr(newobj)->o_class = self;
|
|
325 |
#if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
|
326 |
/*
|
|
327 |
* knowing that nil is 0
|
|
328 |
*/
|
|
329 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
330 |
#else
|
|
331 |
op = _InstPtr(newobj)->i_instvars;
|
|
332 |
while (nInstVars--)
|
|
333 |
*op++ = nil;
|
|
334 |
sp = (short *)op;
|
|
335 |
while (nindexedinstvars--)
|
|
336 |
*sp++ = 0;
|
|
337 |
#endif
|
|
338 |
RETURN ( newobj );
|
|
339 |
break;
|
|
340 |
|
|
341 |
case LONGARRAY:
|
|
342 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ) + nindexedinstvars * sizeof(long);
|
2
|
343 |
_qAlignedNew(newobj, instsize, SENDER);
|
25
|
344 |
UNPROTECT_CONTEXT
|
3
|
345 |
if (newobj == nil) {
|
|
346 |
break;
|
|
347 |
}
|
1
|
348 |
_InstPtr(newobj)->o_class = self;
|
|
349 |
#if defined(memset4) && ! defined(NEGATIVE_ADDRESSES)
|
|
350 |
/*
|
|
351 |
* knowing that nil is 0
|
|
352 |
*/
|
|
353 |
memset4(_InstPtr(newobj)->i_instvars, 0, nInstVars + nindexedinstvars);
|
|
354 |
#else
|
|
355 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
|
356 |
/*
|
|
357 |
* knowing that nil is 0
|
|
358 |
*/
|
|
359 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
360 |
# else
|
|
361 |
op = _InstPtr(newobj)->i_instvars;
|
|
362 |
while (nInstVars--)
|
|
363 |
*op++ = nil;
|
|
364 |
lp = (long *)op;
|
|
365 |
while (nindexedinstvars--)
|
|
366 |
*lp++ = 0;
|
|
367 |
# endif
|
|
368 |
#endif
|
|
369 |
RETURN ( newobj );
|
|
370 |
break;
|
|
371 |
|
|
372 |
case FLOATARRAY:
|
54
|
373 |
instsize = sizeof(struct floatArray) +
|
|
374 |
nInstVars * sizeof(OBJ) +
|
|
375 |
(nindexedinstvars - 1) * sizeof(float);
|
|
376 |
|
1
|
377 |
_qNew(newobj, instsize, SENDER);
|
25
|
378 |
UNPROTECT_CONTEXT
|
3
|
379 |
if (newobj == nil) {
|
|
380 |
break;
|
|
381 |
}
|
1
|
382 |
_InstPtr(newobj)->o_class = self;
|
|
383 |
op = _InstPtr(newobj)->i_instvars;
|
|
384 |
while (nInstVars--)
|
|
385 |
*op++ = nil;
|
|
386 |
fp = (float *)op;
|
|
387 |
while (nindexedinstvars--)
|
|
388 |
*fp++ = 0.0;
|
|
389 |
RETURN ( newobj );
|
|
390 |
break;
|
|
391 |
|
|
392 |
case DOUBLEARRAY:
|
54
|
393 |
instsize = sizeof(struct doubleArray) +
|
|
394 |
nInstVars * sizeof(OBJ) +
|
|
395 |
(nindexedinstvars - 1) * sizeof(double);
|
|
396 |
|
|
397 |
_qAlignedNew(newobj, instsize, SENDER);
|
25
|
398 |
UNPROTECT_CONTEXT
|
3
|
399 |
if (newobj == nil) {
|
|
400 |
break;
|
|
401 |
}
|
1
|
402 |
_InstPtr(newobj)->o_class = self;
|
|
403 |
op = _InstPtr(newobj)->i_instvars;
|
|
404 |
while (nInstVars--)
|
|
405 |
*op++ = nil;
|
54
|
406 |
#ifdef NEED_DOUBLE_ALIGN
|
|
407 |
/*
|
|
408 |
* care for double alignment
|
|
409 |
*/
|
|
410 |
if ((INT)op & (ALIGN-1)) {
|
|
411 |
*op++ = nil;
|
|
412 |
}
|
|
413 |
#endif
|
1
|
414 |
dp = (double *)op;
|
|
415 |
while (nindexedinstvars--)
|
|
416 |
*dp++ = 0.0;
|
|
417 |
RETURN ( newobj );
|
|
418 |
break;
|
|
419 |
|
|
420 |
case WKPOINTERARRAY:
|
|
421 |
case POINTERARRAY:
|
|
422 |
nInstVars += nindexedinstvars;
|
|
423 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ);
|
|
424 |
_qAlignedNew(newobj, instsize, SENDER);
|
25
|
425 |
UNPROTECT_CONTEXT
|
3
|
426 |
if (newobj == nil) {
|
|
427 |
break;
|
|
428 |
}
|
1
|
429 |
_InstPtr(newobj)->o_class = self;
|
|
430 |
#if defined(memset4)
|
|
431 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
|
|
432 |
#else
|
|
433 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
|
434 |
/*
|
|
435 |
* knowing that nil is 0
|
|
436 |
*/
|
|
437 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
438 |
# else
|
|
439 |
op = _InstPtr(newobj)->i_instvars;
|
|
440 |
while (nInstVars--)
|
|
441 |
*op++ = nil;
|
|
442 |
# endif
|
|
443 |
#endif
|
|
444 |
RETURN ( newobj );
|
|
445 |
break;
|
|
446 |
|
|
447 |
default:
|
|
448 |
/*
|
|
449 |
* new:n for non-variable classes only allowed if
|
|
450 |
* n == 0
|
|
451 |
*/
|
|
452 |
if (nindexedinstvars == 0) {
|
|
453 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ);
|
|
454 |
_qAlignedNew(newobj, instsize, SENDER);
|
25
|
455 |
UNPROTECT_CONTEXT
|
3
|
456 |
if (newobj == nil) {
|
|
457 |
break;
|
|
458 |
}
|
1
|
459 |
_InstPtr(newobj)->o_class = self;
|
|
460 |
if (nInstVars) {
|
|
461 |
#if defined(memset4)
|
|
462 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
|
|
463 |
#else
|
|
464 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
|
465 |
/*
|
|
466 |
* knowing that nil is 0
|
|
467 |
*/
|
|
468 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
469 |
# else
|
|
470 |
op = _InstPtr(newobj)->i_instvars;
|
|
471 |
do {
|
|
472 |
*op++ = nil;
|
|
473 |
} while (--nInstVars);
|
|
474 |
# endif
|
|
475 |
#endif
|
|
476 |
}
|
|
477 |
RETURN ( newobj );
|
|
478 |
}
|
|
479 |
break;
|
|
480 |
}
|
|
481 |
}
|
|
482 |
}
|
|
483 |
%}
|
|
484 |
.
|
11
|
485 |
"arrive here if something went wrong ...
|
|
486 |
figure out what"
|
|
487 |
|
1
|
488 |
(anInteger isMemberOf:SmallInteger) ifFalse:[
|
|
489 |
self error:'argument to new: must be Integer'
|
|
490 |
] ifTrue:[
|
11
|
491 |
(anInteger < 0) ifTrue:[
|
|
492 |
self error:'bad (negative) argument to new'
|
|
493 |
] ifFalse:[
|
3
|
494 |
self isVariable ifFalse:[
|
11
|
495 |
self error:'class has no indexed instvars - cannot create with new:'
|
3
|
496 |
] ifTrue:[
|
|
497 |
ObjectMemory allocationFailureSignal raise
|
|
498 |
]
|
1
|
499 |
]
|
|
500 |
]
|
11
|
501 |
!
|
|
502 |
|
|
503 |
readFrom:aStream
|
43
|
504 |
"read an objects printed representation from the argument, aStream
|
|
505 |
and return it.
|
11
|
506 |
The read object must be a kind of myself
|
43
|
507 |
- to get any object, use 'Object readFrom:...',
|
|
508 |
to get any number, use 'Number readFrom:...' and so on.
|
11
|
509 |
This is the reverse operation to 'storeOn:'.
|
43
|
510 |
|
11
|
511 |
Notice, that storeOn: does not handle circular references and
|
|
512 |
multiple references to the same object - use storeBinary: for this."
|
|
513 |
|
|
514 |
|newObject|
|
|
515 |
|
|
516 |
newObject := Compiler evaluate:aStream.
|
|
517 |
(newObject isKindOf:self) ifFalse:[
|
|
518 |
self error:('expected ' , self name)
|
|
519 |
].
|
|
520 |
^ newObject
|
|
521 |
|
|
522 |
"|s|
|
|
523 |
s := WriteStream on:String new.
|
|
524 |
#(1 2 3 4) storeOn:s.
|
|
525 |
Object readFrom:(ReadStream on:s contents)
|
|
526 |
"
|
|
527 |
!
|
|
528 |
|
|
529 |
readFromString:aString
|
|
530 |
"create an object from its printed representation
|
|
531 |
(i.e. stored using storeOn: or storeString)"
|
|
532 |
|
|
533 |
^ self readFrom:(ReadStream on:aString)
|
1
|
534 |
! !
|
|
535 |
|
10
|
536 |
!Behavior methodsFor:'autoload check'!
|
|
537 |
|
|
538 |
isLoaded
|
|
539 |
"return true, if the class has been loaded;
|
|
540 |
redefined in Autoload; see comment there"
|
|
541 |
|
|
542 |
^ true
|
|
543 |
!
|
|
544 |
|
|
545 |
autoload
|
|
546 |
"force autoloading - do nothing here;
|
|
547 |
redefined in Autoload; see comment there"
|
|
548 |
|
|
549 |
^ self
|
|
550 |
! !
|
|
551 |
|
1
|
552 |
!Behavior methodsFor:'accessing'!
|
|
553 |
|
|
554 |
superclass
|
|
555 |
"return the receivers superclass"
|
|
556 |
|
|
557 |
^ superclass
|
|
558 |
!
|
|
559 |
|
|
560 |
selectors
|
|
561 |
"return the receivers selector array"
|
|
562 |
|
|
563 |
^ selectors
|
|
564 |
!
|
|
565 |
|
|
566 |
methods
|
|
567 |
"return the receivers method array"
|
|
568 |
|
|
569 |
^ methods
|
|
570 |
!
|
|
571 |
|
|
572 |
methodDictionary
|
|
573 |
"return the receivers method dictionary - since no dictionary is
|
|
574 |
used (for now) just return the method array"
|
|
575 |
|
|
576 |
^ methods
|
|
577 |
!
|
|
578 |
|
|
579 |
instSize
|
|
580 |
"return the number of instance variables of the receiver"
|
|
581 |
|
|
582 |
^ instSize
|
|
583 |
!
|
|
584 |
|
|
585 |
flags
|
|
586 |
"return the receivers flag bits"
|
|
587 |
|
|
588 |
^ flags
|
|
589 |
!
|
|
590 |
|
|
591 |
isVariable
|
|
592 |
"return true, if instances have indexed instance variables"
|
|
593 |
|
|
594 |
"this used to be defined as:
|
|
595 |
^ (flags bitAnd:16r0F) ~~ 0
|
|
596 |
but then, changes in stc.h would not affect us here. Therefore:"
|
|
597 |
|
|
598 |
%{ /* NOCONTEXT */
|
|
599 |
/* this is defined as a primitive to get defines from stc.h */
|
|
600 |
|
|
601 |
RETURN ( (_intVal(_INST(flags)) & ARRAYMASK) ? true : false );
|
|
602 |
%}
|
|
603 |
!
|
|
604 |
|
|
605 |
isFixed
|
|
606 |
"return true, if instances do not have indexed instance variables"
|
|
607 |
|
|
608 |
%{ /* NOCONTEXT */
|
|
609 |
/* this is defined as a primitive to get defines from stc.h */
|
|
610 |
|
|
611 |
RETURN ( (_intVal(_INST(flags)) & ARRAYMASK) ? false : true );
|
|
612 |
%}
|
|
613 |
!
|
|
614 |
|
|
615 |
isBits
|
|
616 |
"return true, if instances have indexed byte or short instance variables.
|
|
617 |
Ignore long, float and double arrays, since classes using isBits are probably
|
|
618 |
not prepared to handle them correctly."
|
|
619 |
|
|
620 |
%{ /* NOCONTEXT */
|
|
621 |
/* this is defined as a primitive to get defines from stc.h */
|
|
622 |
|
|
623 |
REGISTER int flags;
|
|
624 |
|
|
625 |
RETURN ( (((flags = (_intVal(_INST(flags)) & ARRAYMASK)) == BYTEARRAY)
|
2
|
626 |
|| (flags == WORDARRAY)) ? true : false );
|
1
|
627 |
%}
|
|
628 |
!
|
|
629 |
|
|
630 |
isBytes
|
|
631 |
"return true, if instances have indexed byte instance variables"
|
|
632 |
|
|
633 |
%{ /* NOCONTEXT */
|
|
634 |
/* this is defined as a primitive to get defines from stc.h */
|
|
635 |
|
|
636 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == BYTEARRAY) ? true : false );
|
|
637 |
%}
|
|
638 |
!
|
|
639 |
|
|
640 |
isWords
|
|
641 |
"return true, if instances have indexed short instance variables"
|
|
642 |
|
|
643 |
%{ /* NOCONTEXT */
|
|
644 |
/* this is defined as a primitive to get defines from stc.h */
|
|
645 |
|
|
646 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == WORDARRAY) ? true : false );
|
|
647 |
%}
|
|
648 |
!
|
|
649 |
|
|
650 |
isLongs
|
|
651 |
"return true, if instances have indexed long instance variables"
|
|
652 |
|
|
653 |
%{ /* NOCONTEXT */
|
|
654 |
/* this is defined as a primitive to get defines from stc.h */
|
|
655 |
|
|
656 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == LONGARRAY) ? true : false );
|
|
657 |
%}
|
|
658 |
!
|
|
659 |
|
|
660 |
isFloats
|
|
661 |
"return true, if instances have indexed float instance variables"
|
|
662 |
|
|
663 |
%{ /* NOCONTEXT */
|
|
664 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == FLOATARRAY) ? true : false );
|
|
665 |
%}
|
|
666 |
!
|
|
667 |
|
|
668 |
isDoubles
|
|
669 |
"return true, if instances have indexed double instance variables"
|
|
670 |
|
|
671 |
%{ /* NOCONTEXT */
|
|
672 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == DOUBLEARRAY) ? true : false );
|
|
673 |
%}
|
|
674 |
!
|
|
675 |
|
|
676 |
isPointers
|
2
|
677 |
"return true, if instances have pointer instance variables
|
|
678 |
i.e. are either non-indexed or have indexed pointer variables"
|
1
|
679 |
|
|
680 |
"question: should we ignore WeakPointers ?"
|
|
681 |
%{ /* NOCONTEXT */
|
|
682 |
REGISTER int flags;
|
|
683 |
|
2
|
684 |
flags = _intVal(_INST(flags)) & ARRAYMASK;
|
|
685 |
switch (flags) {
|
|
686 |
default:
|
|
687 |
/* normal objects */
|
|
688 |
RETURN ( true );
|
|
689 |
|
|
690 |
case BYTEARRAY:
|
|
691 |
case WORDARRAY:
|
|
692 |
case LONGARRAY:
|
|
693 |
case FLOATARRAY:
|
|
694 |
case DOUBLEARRAY:
|
|
695 |
RETURN (false );
|
|
696 |
|
|
697 |
case WKPOINTERARRAY:
|
|
698 |
/* what about those ? */
|
|
699 |
RETURN (true );
|
|
700 |
}
|
1
|
701 |
%}
|
2
|
702 |
!
|
|
703 |
|
|
704 |
superclass:aClass
|
|
705 |
"set the superclass - this actually creates a new class,
|
|
706 |
recompiling all methods."
|
|
707 |
|
|
708 |
"must flush caches since lookup chain changes"
|
|
709 |
ObjectMemory flushCaches.
|
10
|
710 |
|
2
|
711 |
"
|
|
712 |
superclass := aClass
|
|
713 |
"
|
|
714 |
"for correct recompilation, just create a new class ..."
|
|
715 |
|
|
716 |
aClass subclass:(self name)
|
|
717 |
instanceVariableNames:(self instanceVariableString)
|
|
718 |
classVariableNames:(self classVariableString)
|
|
719 |
poolDictionaries:''
|
|
720 |
category:self category
|
|
721 |
!
|
|
722 |
|
|
723 |
selectors:selectorArray methods:methodArray
|
|
724 |
"set both selector array and method array of the receiver,
|
|
725 |
and flush caches"
|
|
726 |
|
|
727 |
ObjectMemory flushCaches.
|
|
728 |
selectors := selectorArray.
|
|
729 |
methods := methodArray
|
1
|
730 |
! !
|
|
731 |
|
|
732 |
!Behavior methodsFor:'queries'!
|
|
733 |
|
|
734 |
isBehavior
|
47
|
735 |
"return true, if the receiver is describing another objects behavior,
|
45
|
736 |
i.e. is a class. Defined to avoid the need to use isKindOf:"
|
1
|
737 |
|
|
738 |
^ true
|
45
|
739 |
|
|
740 |
"True isBehavior"
|
|
741 |
"true isBehavior"
|
1
|
742 |
!
|
|
743 |
|
47
|
744 |
canBeSubclassed
|
|
745 |
"return true, if its allowed to create subclasses of the receiver.
|
|
746 |
This method is redefined in SmallInteger and UndefinedObject, since
|
|
747 |
those are detected by their pointer-fields, i.e. they do not have
|
|
748 |
a class entry (you dont have to understand this)"
|
|
749 |
|
|
750 |
^ true
|
|
751 |
!
|
|
752 |
|
1
|
753 |
hasMultipleSuperclasses
|
47
|
754 |
"NO multiple inheritance in this system (yet ?)"
|
1
|
755 |
|
|
756 |
^ false
|
|
757 |
!
|
|
758 |
|
|
759 |
superclasses
|
|
760 |
"return a collection of the receivers immediate superclasses
|
47
|
761 |
- since we have NO multiple inheritance, there is only one."
|
1
|
762 |
|
|
763 |
^ Array with:superclass
|
45
|
764 |
|
|
765 |
"String superclasses"
|
1
|
766 |
!
|
|
767 |
|
|
768 |
allSuperclasses
|
|
769 |
"return a collection of the receivers accumulated superclasses"
|
|
770 |
|
|
771 |
|aCollection theSuperClass|
|
|
772 |
|
|
773 |
theSuperClass := superclass.
|
|
774 |
theSuperClass notNil ifTrue:[
|
|
775 |
aCollection := OrderedCollection new.
|
|
776 |
[theSuperClass notNil] whileTrue:[
|
|
777 |
aCollection add:theSuperClass.
|
|
778 |
theSuperClass := theSuperClass superclass
|
|
779 |
]
|
|
780 |
].
|
|
781 |
^ aCollection
|
45
|
782 |
|
|
783 |
"String allSuperclasses"
|
1
|
784 |
!
|
|
785 |
|
|
786 |
withAllSuperclasses
|
|
787 |
"return a collection containing the receiver and all
|
|
788 |
of the receivers accumulated superclasses"
|
|
789 |
|
|
790 |
|aCollection theSuperClass|
|
|
791 |
|
|
792 |
aCollection := OrderedCollection with:self.
|
|
793 |
theSuperClass := superclass.
|
|
794 |
[theSuperClass notNil] whileTrue:[
|
|
795 |
aCollection add:theSuperClass.
|
|
796 |
theSuperClass := theSuperClass superclass
|
|
797 |
].
|
|
798 |
^ aCollection
|
45
|
799 |
|
|
800 |
"String withAllSuperclasses"
|
1
|
801 |
!
|
|
802 |
|
|
803 |
subclasses
|
|
804 |
"return a collection of the direct subclasses of the receiver"
|
|
805 |
|
|
806 |
|newColl|
|
|
807 |
|
|
808 |
newColl := OrderedCollection new.
|
|
809 |
self subclassesDo:[:aClass |
|
|
810 |
newColl add:aClass
|
|
811 |
].
|
|
812 |
^ newColl
|
45
|
813 |
|
|
814 |
"Collection subclasses"
|
1
|
815 |
!
|
|
816 |
|
|
817 |
allSubclasses
|
|
818 |
"return a collection of all subclasses (direct AND indirect) of
|
45
|
819 |
the receiver. There will be no specific order, in which entries
|
|
820 |
are returned."
|
1
|
821 |
|
|
822 |
|newColl|
|
|
823 |
|
|
824 |
newColl := OrderedCollection new.
|
|
825 |
self allSubclassesDo:[:aClass |
|
|
826 |
newColl add:aClass
|
|
827 |
].
|
|
828 |
^ newColl
|
45
|
829 |
|
|
830 |
"Collection allSubclasses"
|
|
831 |
!
|
|
832 |
|
|
833 |
allSubclassesInOrder
|
|
834 |
"return a collection of all subclasses (direct AND indirect) of
|
|
835 |
the receiver. Higher level subclasses will come before lower ones."
|
|
836 |
|
|
837 |
|newColl|
|
|
838 |
|
|
839 |
newColl := OrderedCollection new.
|
|
840 |
self allSubclassesInOrderDo:[:aClass |
|
|
841 |
newColl add:aClass
|
|
842 |
].
|
|
843 |
^ newColl
|
|
844 |
|
|
845 |
"Collection allSubclassesInOrder"
|
1
|
846 |
!
|
|
847 |
|
|
848 |
withAllSubclasses
|
|
849 |
"return a collection containing the receiver and
|
|
850 |
all subclasses (direct AND indirect) of the receiver"
|
|
851 |
|
|
852 |
|newColl|
|
|
853 |
|
|
854 |
newColl := OrderedCollection with:self.
|
|
855 |
self allSubclassesDo:[:aClass |
|
|
856 |
newColl add:aClass
|
|
857 |
].
|
|
858 |
^ newColl
|
45
|
859 |
|
|
860 |
"Collection withAllSubclasses"
|
1
|
861 |
!
|
|
862 |
|
|
863 |
isSubclassOf:aClass
|
|
864 |
"return true, if I am a subclass of the argument, aClass"
|
|
865 |
|
|
866 |
|theClass|
|
2
|
867 |
|
1
|
868 |
theClass := superclass.
|
|
869 |
[theClass notNil] whileTrue:[
|
|
870 |
(theClass == aClass) ifTrue:[^ true].
|
|
871 |
theClass := theClass superclass
|
|
872 |
].
|
|
873 |
^ false
|
45
|
874 |
|
|
875 |
"String isSubclassOf:Collection"
|
|
876 |
"LinkedList isSubclassOf:Array"
|
47
|
877 |
"1 isSubclassOf:Number" "will fail since 1 is no class"
|
1
|
878 |
!
|
|
879 |
|
|
880 |
allInstances
|
|
881 |
"return a collection of all my instances"
|
|
882 |
|
|
883 |
|coll|
|
|
884 |
|
|
885 |
coll := OrderedCollection new.
|
45
|
886 |
self allInstancesDo:[:anObject |
|
|
887 |
coll add:anObject
|
1
|
888 |
].
|
47
|
889 |
^ coll asArray "mhmh - isnt an orderedCollection ok ?"
|
25
|
890 |
|
|
891 |
"ScrollBar allInstances"
|
|
892 |
!
|
|
893 |
|
|
894 |
allDerivedInstances
|
|
895 |
"return a collection of all instances of myself and
|
|
896 |
instances of all subclasses of myself"
|
|
897 |
|
|
898 |
|coll|
|
|
899 |
|
|
900 |
coll := OrderedCollection new.
|
45
|
901 |
self allDerivedInstancesDo:[:anObject |
|
25
|
902 |
(anObject isKindOf:self) ifTrue:[
|
|
903 |
coll add:anObject
|
|
904 |
]
|
|
905 |
].
|
47
|
906 |
^ coll asArray "mhmh - isnt an orderedCollection ok ?"
|
25
|
907 |
|
|
908 |
"View allDerivedInstances"
|
1
|
909 |
!
|
|
910 |
|
|
911 |
instanceCount
|
|
912 |
"return the number of instances of myself"
|
|
913 |
|
|
914 |
|count|
|
|
915 |
|
|
916 |
count := 0.
|
|
917 |
ObjectMemory allObjectsDo:[:anObject |
|
|
918 |
(anObject class == self) ifTrue:[
|
|
919 |
count := count + 1
|
|
920 |
]
|
|
921 |
].
|
|
922 |
^ count
|
45
|
923 |
|
|
924 |
"View instanceCount"
|
|
925 |
!
|
|
926 |
|
|
927 |
derivedInstanceCount
|
|
928 |
"return the number of instances of myself and of subclasses"
|
|
929 |
|
|
930 |
|count|
|
|
931 |
|
|
932 |
count := 0.
|
|
933 |
ObjectMemory allObjectsDo:[:anObject |
|
|
934 |
(anObject isKindOf:self) ifTrue:[
|
|
935 |
count := count + 1
|
|
936 |
]
|
|
937 |
].
|
|
938 |
^ count
|
|
939 |
|
|
940 |
"View derivedInstanceCount"
|
2
|
941 |
!
|
|
942 |
|
|
943 |
selectorIndex:aSelector
|
|
944 |
"return the index in the arrays for given selector aSelector"
|
|
945 |
|
|
946 |
^ selectors identityIndexOf:aSelector startingAt:1
|
|
947 |
!
|
|
948 |
|
|
949 |
compiledMethodAt:aSelector
|
47
|
950 |
"return the method for given selector aSelector or nil."
|
2
|
951 |
|
|
952 |
|index|
|
|
953 |
|
|
954 |
index := selectors identityIndexOf:aSelector startingAt:1.
|
|
955 |
(index == 0) ifTrue:[^ nil].
|
|
956 |
^ methods at:index
|
45
|
957 |
|
|
958 |
"Object compiledMethodAt:#=="
|
|
959 |
"(Object compiledMethodAt:#==) category"
|
2
|
960 |
!
|
|
961 |
|
|
962 |
sourceCodeAt:aSelector
|
47
|
963 |
"return the methods source for given selector aSelector or nil."
|
2
|
964 |
|
3
|
965 |
|method|
|
2
|
966 |
|
3
|
967 |
method := self compiledMethodAt:aSelector.
|
|
968 |
method isNil ifTrue:[^ nil].
|
|
969 |
^ method source
|
2
|
970 |
|
|
971 |
"True sourceCodeAt:#ifTrue:"
|
45
|
972 |
"Object sourceCodeAt:#=="
|
|
973 |
"Behavior sourceCodeAt:#sourceCodeAt:"
|
2
|
974 |
!
|
|
975 |
|
|
976 |
hasMethods
|
|
977 |
"return true, if there are any (local) methods in this class"
|
|
978 |
|
|
979 |
^ (methods size ~~ 0)
|
10
|
980 |
|
|
981 |
"True hasMethods"
|
|
982 |
"True class hasMethods"
|
2
|
983 |
!
|
|
984 |
|
|
985 |
implements:aSelector
|
10
|
986 |
"return true, if I implement selector.
|
|
987 |
(i.e. implemented in this class - not in a superclass).
|
|
988 |
Dont use this method to check if someone responds to a message -
|
45
|
989 |
use #canUnderstand: on the class or #respondsTo: on the instance
|
10
|
990 |
to do this."
|
2
|
991 |
|
54
|
992 |
^ (selectors identityIndexOf:aSelector startingAt:1) ~~ 0
|
2
|
993 |
|
|
994 |
"True implements:#ifTrue:"
|
|
995 |
"True implements:#=="
|
|
996 |
!
|
|
997 |
|
|
998 |
canUnderstand:aSelector
|
10
|
999 |
"return true, if I or one of my superclasses implements selector.
|
2
|
1000 |
(i.e. my instances understand aSelector)"
|
|
1001 |
|
|
1002 |
|classToLookAt|
|
|
1003 |
|
|
1004 |
classToLookAt := self.
|
|
1005 |
[classToLookAt notNil] whileTrue:[
|
|
1006 |
(classToLookAt implements:aSelector) ifTrue:[^ true].
|
|
1007 |
classToLookAt := classToLookAt superclass
|
|
1008 |
].
|
|
1009 |
^ false
|
10
|
1010 |
|
|
1011 |
"True canUnderstand:#ifTrue:"
|
|
1012 |
"True canUnderstand:#=="
|
|
1013 |
"True canUnderstand:#do:"
|
2
|
1014 |
!
|
|
1015 |
|
|
1016 |
whichClassImplements:aSelector
|
45
|
1017 |
"Return the first class in the inheritance chain
|
|
1018 |
(i.e. the receiver or a superclass),
|
47
|
1019 |
which implements the method for aSelector, if none, return nil."
|
2
|
1020 |
|
|
1021 |
|classToLookAt|
|
|
1022 |
|
|
1023 |
classToLookAt := self.
|
|
1024 |
[classToLookAt notNil] whileTrue:[
|
|
1025 |
(classToLookAt implements:aSelector) ifTrue:[^ classToLookAt].
|
|
1026 |
classToLookAt := classToLookAt superclass
|
|
1027 |
].
|
|
1028 |
^ nil
|
|
1029 |
|
|
1030 |
"True whichClassImplements:#ifTrue:"
|
|
1031 |
"True whichClassImplements:#=="
|
|
1032 |
!
|
|
1033 |
|
|
1034 |
inheritsFrom:aClass
|
|
1035 |
"return true, if I inherit methods from aClass"
|
|
1036 |
|
|
1037 |
^ self isSubclassOf:aClass
|
45
|
1038 |
|
|
1039 |
"True inheritsFrom:Object"
|
|
1040 |
"LinkedList inheritsFrom:Array"
|
2
|
1041 |
!
|
|
1042 |
|
|
1043 |
selectorForMethod:aMethod
|
47
|
1044 |
"Return the selector for given method aMethod."
|
2
|
1045 |
|
|
1046 |
|index|
|
|
1047 |
|
54
|
1048 |
index := methods identityIndexOf:aMethod startingAt:1.
|
2
|
1049 |
(index == 0) ifTrue:[^ nil].
|
|
1050 |
^ selectors at:index
|
|
1051 |
!
|
|
1052 |
|
|
1053 |
containsMethod:aMethod
|
|
1054 |
"Return true, if aMethod is a method of myself"
|
|
1055 |
|
54
|
1056 |
^ (methods identityIndexOf:aMethod startingAt:1) ~~ 0
|
1
|
1057 |
! !
|
|
1058 |
|
|
1059 |
!Behavior methodsFor:'private accessing'!
|
|
1060 |
|
|
1061 |
setSuperclass:sup selectors:sels methods:m instSize:i flags:f
|
45
|
1062 |
"set some inst vars.
|
|
1063 |
this method is for private use only - there will be not recompilation
|
|
1064 |
and no change record written here; DO NOT use it."
|
1
|
1065 |
|
|
1066 |
superclass := sup.
|
|
1067 |
selectors := sels.
|
|
1068 |
methods := m.
|
|
1069 |
instSize := i.
|
|
1070 |
flags := f
|
|
1071 |
!
|
|
1072 |
|
|
1073 |
setSuperclass:aClass
|
45
|
1074 |
"set the superclass of the receiver.
|
|
1075 |
this method is for private use only - there will be not recompilation
|
|
1076 |
and no change record written here; DO NOT use it."
|
1
|
1077 |
|
|
1078 |
superclass := aClass
|
|
1079 |
!
|
|
1080 |
|
|
1081 |
instSize:aNumber
|
45
|
1082 |
"set the instance size.
|
|
1083 |
this method is for private use only - there will be not recompilation
|
|
1084 |
and no change record written here; DO NOT use it."
|
1
|
1085 |
|
|
1086 |
instSize := aNumber
|
|
1087 |
!
|
|
1088 |
|
|
1089 |
flags:aNumber
|
45
|
1090 |
"set the flags.
|
|
1091 |
this method is for private use only - there will be not recompilation
|
|
1092 |
and no change record written here; DO NOT use it."
|
1
|
1093 |
|
|
1094 |
flags := aNumber
|
|
1095 |
!
|
|
1096 |
|
|
1097 |
setSelectors:anArray
|
45
|
1098 |
"set the selector array of the receiver.
|
|
1099 |
this method is for private use only - there will be not recompilation
|
|
1100 |
and no change record written here; DO NOT use it."
|
1
|
1101 |
|
|
1102 |
selectors := anArray
|
|
1103 |
!
|
|
1104 |
|
|
1105 |
setMethodDictionary:anArray
|
45
|
1106 |
"set the method array of the receiver.
|
|
1107 |
this method is for private use only - there will be not recompilation
|
|
1108 |
and no change record written here; DO NOT use it."
|
1
|
1109 |
|
|
1110 |
methods := anArray
|
|
1111 |
! !
|
|
1112 |
|
|
1113 |
!Behavior methodsFor:'enumeration'!
|
|
1114 |
|
|
1115 |
allInstancesDo:aBlock
|
45
|
1116 |
"evaluate aBlock for all of my instances"
|
1
|
1117 |
|
|
1118 |
ObjectMemory allObjectsDo:[:anObject |
|
|
1119 |
(anObject class == self) ifTrue:[
|
|
1120 |
aBlock value:anObject
|
|
1121 |
]
|
|
1122 |
]
|
45
|
1123 |
|
|
1124 |
"StandardSystemView allInstancesDo:[:v | Transcript showCr:(v name)]"
|
|
1125 |
!
|
|
1126 |
|
|
1127 |
allDerivedInstancesDo:aBlock
|
|
1128 |
"evaluate aBlock for all of my instances and all instances of subclasses"
|
|
1129 |
|
|
1130 |
ObjectMemory allObjectsDo:[:anObject |
|
|
1131 |
(anObject isKindOf:self) ifTrue:[
|
|
1132 |
aBlock value:anObject
|
|
1133 |
]
|
|
1134 |
]
|
|
1135 |
|
|
1136 |
"StandardSystemView allDerivedInstancesDo:[:v | Transcript showCr:(v name)]"
|
1
|
1137 |
!
|
|
1138 |
|
|
1139 |
subclassesDo:aBlock
|
|
1140 |
"evaluate the argument, aBlock for all immediate subclasses"
|
|
1141 |
|
2
|
1142 |
Smalltalk allBehaviorsDo:[:aClass |
|
1
|
1143 |
(aClass superclass == self) ifTrue:[
|
|
1144 |
aBlock value:aClass
|
|
1145 |
]
|
|
1146 |
]
|
45
|
1147 |
|
|
1148 |
"Collection subclassesDo:[:c | Transcript showCr:(c name)]"
|
1
|
1149 |
!
|
|
1150 |
|
|
1151 |
allSubclassesDo:aBlock
|
45
|
1152 |
"evaluate aBlock for all of my subclasses.
|
|
1153 |
There is no specific order, in which the entries are enumerated."
|
1
|
1154 |
|
2
|
1155 |
Smalltalk allBehaviorsDo:[:aClass |
|
1
|
1156 |
(aClass isSubclassOf:self) ifTrue:[
|
|
1157 |
aBlock value:aClass
|
|
1158 |
]
|
|
1159 |
]
|
45
|
1160 |
|
|
1161 |
"Collection allSubclassesDo:[:c | Transcript showCr:(c name)]"
|
1
|
1162 |
!
|
|
1163 |
|
|
1164 |
allSubclassesInOrderDo:aBlock
|
45
|
1165 |
"evaluate aBlock for all of my subclasses.
|
|
1166 |
Higher level subclasses will be enumerated before the deeper ones"
|
1
|
1167 |
|
|
1168 |
self subclassesDo:[:aClass |
|
|
1169 |
aBlock value:aClass.
|
|
1170 |
aClass allSubclassesInOrderDo:aBlock
|
|
1171 |
]
|
45
|
1172 |
|
|
1173 |
"Collection allSubclassesInOrderDo:[:c | Transcript showCr:(c name)]"
|
1
|
1174 |
!
|
|
1175 |
|
|
1176 |
allSuperclassesDo:aBlock
|
45
|
1177 |
"evaluate aBlock for all of my superclasses"
|
1
|
1178 |
|
|
1179 |
|theClass|
|
|
1180 |
|
|
1181 |
theClass := superclass.
|
|
1182 |
[theClass notNil] whileTrue:[
|
|
1183 |
aBlock value:theClass.
|
|
1184 |
theClass := theClass superclass
|
|
1185 |
]
|
45
|
1186 |
|
|
1187 |
"String allSuperclassesDo:[:c | Transcript showCr:(c name)]"
|
1
|
1188 |
! !
|
2
|
1189 |
|
|
1190 |
!Behavior methodsFor: 'binary storage'!
|
|
1191 |
|
11
|
1192 |
readBinaryFrom:aStream
|
|
1193 |
"read an objects binary representation from the argument,
|
|
1194 |
aStream and return it.
|
|
1195 |
The read object must be a kind of myself
|
43
|
1196 |
- to get any object, use 'Object readBinaryFrom:...',
|
|
1197 |
to get any number, use 'Number readBinaryFrom:...' and so on.
|
11
|
1198 |
This is the reverse operation to 'storeBinaryOn:'. "
|
|
1199 |
|
|
1200 |
|newObject|
|
|
1201 |
|
|
1202 |
newObject := (BinaryInputManager new:1024) readFrom:aStream.
|
|
1203 |
(newObject isKindOf:self) ifFalse:[
|
|
1204 |
self error:('expected ' , self name)
|
|
1205 |
].
|
|
1206 |
^ newObject
|
|
1207 |
|
|
1208 |
"|s|
|
|
1209 |
s := WriteStream on:ByteArray new.
|
|
1210 |
#(1 2 3 4) storeBinaryOn:s.
|
|
1211 |
Object readBinaryFrom:(ReadStream on:s contents)
|
|
1212 |
"
|
|
1213 |
!
|
|
1214 |
|
43
|
1215 |
storeBinaryDefinitionOn: stream manager: manager
|
|
1216 |
"classes will store the name only and restore by looking for
|
|
1217 |
that name in the Smalltalk dictionary."
|
2
|
1218 |
|
43
|
1219 |
| myName |
|
2
|
1220 |
|
43
|
1221 |
myName := self name.
|
|
1222 |
stream
|
|
1223 |
"nextWordPut: (format bitAnd: 16rFFFF);"
|
|
1224 |
"nextWordPut:" nextNumber:2 put:myName size.
|
|
1225 |
myName do:[:c|
|
|
1226 |
stream nextPut:c asciiValue
|
|
1227 |
]
|
2
|
1228 |
!
|
|
1229 |
|
43
|
1230 |
binaryDefinitionFrom:stream manager:manager
|
|
1231 |
"read the definition on an empty instance (of my class) from stream.
|
|
1232 |
All pointer instances are left nil, while all bits are read in here.
|
|
1233 |
return the new object."
|
2
|
1234 |
|
43
|
1235 |
|obj t
|
|
1236 |
basicSize "{ Class: SmallInteger }" |
|
2
|
1237 |
|
|
1238 |
self isPointers ifTrue: [
|
|
1239 |
stream next. "skip instSize"
|
|
1240 |
self isVariable ifTrue: [
|
43
|
1241 |
^ self basicNew:(stream nextNumber:3)
|
2
|
1242 |
].
|
|
1243 |
^ self basicNew
|
|
1244 |
].
|
|
1245 |
|
43
|
1246 |
basicSize := stream nextNumber:4.
|
|
1247 |
obj := self basicNew:basicSize.
|
|
1248 |
|
2
|
1249 |
self isBytes ifTrue: [
|
45
|
1250 |
stream nextBytes:basicSize into:obj
|
43
|
1251 |
"
|
2
|
1252 |
1 to:basicSize do:[:i |
|
43
|
1253 |
obj basicAt:i put:stream next
|
2
|
1254 |
]
|
43
|
1255 |
"
|
2
|
1256 |
] ifFalse: [
|
|
1257 |
self isWords ifTrue: [
|
|
1258 |
1 to:basicSize do:[:i |
|
43
|
1259 |
obj basicAt:i put: stream nextNumber:2
|
2
|
1260 |
]
|
|
1261 |
] ifFalse:[
|
|
1262 |
self isLongs ifTrue: [
|
|
1263 |
1 to:basicSize do:[:i |
|
43
|
1264 |
obj basicAt:i put: stream nextNumber:4
|
2
|
1265 |
]
|
|
1266 |
] ifFalse:[
|
|
1267 |
self isFloats ifTrue: [
|
47
|
1268 |
"could do it in one big read on machines which use IEEE floats ..."
|
2
|
1269 |
1 to:basicSize do:[:i |
|
|
1270 |
t := Float basicNew.
|
43
|
1271 |
Float readBinaryIEEESingleFrom:stream into:t.
|
|
1272 |
obj basicAt:i put: t
|
2
|
1273 |
]
|
|
1274 |
] ifFalse:[
|
47
|
1275 |
self isDoubles ifTrue: [
|
|
1276 |
"could do it in one big read on machines which use IEEE doubles ..."
|
|
1277 |
1 to:basicSize do:[:i |
|
|
1278 |
t := Float basicNew.
|
|
1279 |
Float readBinaryIEEEDoubleFrom:stream into:t.
|
|
1280 |
obj basicAt:i put: t
|
|
1281 |
]
|
2
|
1282 |
]
|
|
1283 |
]
|
|
1284 |
]
|
|
1285 |
]
|
|
1286 |
].
|
|
1287 |
^obj
|
|
1288 |
! !
|