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