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