author | Claus Gittinger <cg@exept.de> |
Tue, 14 Nov 1995 20:02:34 +0100 | |
changeset 544 | d78012b20769 |
parent 530 | 07d0bce293c9 |
child 579 | 2d26193415b5 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 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:#Object |
|
14 |
instanceVariableNames:'' |
|
15 |
classVariableNames:'ErrorSignal HaltSignal |
|
159 | 16 |
MessageNotUnderstoodSignal UserInterruptSignal |
17 |
RecursionInterruptSignal ExceptionInterruptSignal |
|
18 |
SubscriptOutOfBoundsSignal NonIntegerIndexSignal |
|
19 |
NotFoundSignal KeyNotFoundSignal ElementOutOfBoundsSignal |
|
20 |
InformationSignal PrimitiveFailureSignal |
|
21 |
DeepCopyErrorSignal |
|
22 |
AbortSignal |
|
356 | 23 |
ErrorRecursion Dependencies |
24 |
InfoPrinting' |
|
1 | 25 |
poolDictionaries:'' |
26 |
category:'Kernel-Objects' |
|
27 |
! |
|
28 |
||
71 | 29 |
!Object class methodsFor:'documentation'! |
30 |
||
88 | 31 |
copyright |
32 |
" |
|
33 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 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 |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
482
diff
changeset
|
46 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.69 1995-11-11 15:25:11 cg Exp $' |
88 | 47 |
! |
48 |
||
71 | 49 |
documentation |
50 |
" |
|
159 | 51 |
Object is the superclass of all other classes. Protocol common to |
52 |
every object is defined here. |
|
71 | 53 |
Also some utility stuff (like notify) and error handling is implemented here. |
54 |
||
55 |
Object has no instance variables (and may not get any added). One reason is, that |
|
159 | 56 |
UndefinedObject and SmallInteger are also inheriting from Object - these two cannot have instance |
143 | 57 |
variables (due to their implementation). The other reason is that the runtime system |
159 | 58 |
(VM) knows about the layout of some built-in classes (think of Class, Method, Block |
59 |
and also Integer or Float). If you where allowed to add instance variables to Object, |
|
60 |
the VM had to be recompiled (and also rewritten in some places). |
|
71 | 61 |
|
62 |
Class variables: |
|
63 |
||
159 | 64 |
ErrorSignal <Signal> Signal raised for error/error: messages |
65 |
also, parent of all other signals. |
|
66 |
||
67 |
HaltSignal <Signal> Signal raised for halt/halt: messages |
|
68 |
||
69 |
MessageNotUnderstoodSignal Signals raised for various error conditions |
|
70 |
UserInterruptSignal |
|
71 |
RecursionInterruptSignal |
|
72 |
ExceptionInterruptSignal |
|
73 |
SubscriptOutOfBoundsSignal |
|
74 |
NonIntegerIndexSignal |
|
75 |
NotFoundSignal |
|
76 |
KeyNotFoundSignal |
|
77 |
ElementOutOfBoundsSignal |
|
78 |
InformationSignal |
|
79 |
DeepCopyErrorSignal |
|
80 |
||
81 |
AbortSignal <Signal> Signal raised by debugger, to abort a computation |
|
82 |
BUT, the debugger will only raise it if it is handled. |
|
83 |
By handling the abortSignal, you can control where the |
|
84 |
debuggers abort-function resumes execution in case of |
|
85 |
an error. |
|
86 |
||
87 |
ErrorRecursion <Boolean> controls behavior when recursive errors occur (i.e. |
|
88 |
an error while handling an error). |
|
89 |
||
90 |
Dependencies <Dictionary> keeps track of object dependencies |
|
71 | 91 |
" |
92 |
! ! |
|
1 | 93 |
|
94 |
!Object class methodsFor:'initialization'! |
|
95 |
||
96 |
initialize |
|
97 |
"called only once - initialize signals" |
|
98 |
||
99 |
ErrorSignal isNil ifTrue:[ |
|
159 | 100 |
ErrorSignal := (Signal new) mayProceed:true. |
101 |
ErrorSignal nameClass:self message:#errorSignal. |
|
102 |
ErrorSignal notifierString:'error encountered'. |
|
103 |
||
104 |
HaltSignal := ErrorSignal newSignalMayProceed:true. |
|
105 |
HaltSignal nameClass:self message:#haltSignal. |
|
106 |
HaltSignal notifierString:'halt encountered'. |
|
107 |
||
108 |
MessageNotUnderstoodSignal := ErrorSignal newSignalMayProceed:true. |
|
109 |
MessageNotUnderstoodSignal nameClass:self message:#messageNotUnderstoodSignal. |
|
110 |
MessageNotUnderstoodSignal notifierString:'message not understood'. |
|
111 |
||
112 |
PrimitiveFailureSignal := ErrorSignal newSignalMayProceed:true. |
|
113 |
PrimitiveFailureSignal nameClass:self message:#primitiveFailureSignal. |
|
114 |
PrimitiveFailureSignal notifierString:'primitive failed'. |
|
115 |
||
362 | 116 |
"/ UserInterruptSignal := ErrorSignal newSignalMayProceed:true. |
117 |
UserInterruptSignal := (Signal new) newSignalMayProceed:true. |
|
159 | 118 |
UserInterruptSignal nameClass:self message:#userInterruptSignal. |
119 |
UserInterruptSignal notifierString:'user Interrupt'. |
|
120 |
||
362 | 121 |
"/ RecursionInterruptSignal := ErrorSignal newSignalMayProceed:false. |
122 |
RecursionInterruptSignal := (Signal new) mayProceed:true. |
|
159 | 123 |
RecursionInterruptSignal nameClass:self message:#recursionInterruptSignal. |
124 |
RecursionInterruptSignal notifierString:'recursion limit reached'. |
|
125 |
||
126 |
ExceptionInterruptSignal := ErrorSignal newSignalMayProceed:true. |
|
127 |
ExceptionInterruptSignal nameClass:self message:#exceptionInterruptSignal. |
|
128 |
ExceptionInterruptSignal notifierString:'exception Interrupt'. |
|
129 |
||
130 |
SubscriptOutOfBoundsSignal := ErrorSignal newSignalMayProceed:false. |
|
131 |
SubscriptOutOfBoundsSignal nameClass:self message:#subscriptOutOfBoundsSignal. |
|
132 |
SubscriptOutOfBoundsSignal notifierString:'subscript out of bounds'. |
|
133 |
||
134 |
ElementOutOfBoundsSignal := ErrorSignal newSignalMayProceed:false. |
|
135 |
ElementOutOfBoundsSignal nameClass:self message:#elementOutOfBoundsSignal. |
|
136 |
ElementOutOfBoundsSignal notifierString:'element not appropriate or out of bounds'. |
|
137 |
||
138 |
NotFoundSignal := ErrorSignal newSignalMayProceed:true. |
|
139 |
NotFoundSignal nameClass:self message:#notFoundSignal. |
|
140 |
NotFoundSignal notifierString:'no such element'. |
|
141 |
||
142 |
KeyNotFoundSignal := ErrorSignal newSignalMayProceed:true. |
|
143 |
KeyNotFoundSignal nameClass:self message:#keyNotFoundSignal. |
|
345 | 144 |
KeyNotFoundSignal notifierString:'no such key:'. |
159 | 145 |
|
146 |
NonIntegerIndexSignal := ErrorSignal newSignalMayProceed:false. |
|
147 |
NonIntegerIndexSignal nameClass:self message:#nonIntegerIndexSignal. |
|
148 |
NonIntegerIndexSignal notifierString:'index must be integer'. |
|
149 |
||
150 |
InformationSignal := ErrorSignal newSignalMayProceed:true. |
|
151 |
InformationSignal nameClass:self message:#informationSignal. |
|
152 |
InformationSignal notifierString:'information'. |
|
153 |
||
154 |
DeepCopyErrorSignal := ErrorSignal newSignalMayProceed:true. |
|
155 |
DeepCopyErrorSignal nameClass:self message:#deepCopyErrorSignal. |
|
156 |
DeepCopyErrorSignal notifierString:'object cannot be deepCopy-ed'. |
|
157 |
||
158 |
" |
|
159 |
AbortSignal is not a child of ErrorSignal - |
|
160 |
this would complicate abort from within a signal handler |
|
161 |
" |
|
162 |
AbortSignal := Signal new mayProceed:true. |
|
163 |
AbortSignal nameClass:self message:#abortSignal. |
|
164 |
AbortSignal notifierString:'unhandled abort signal'. |
|
165 |
||
166 |
Dependencies isNil ifTrue:[ |
|
167 |
Dependencies := WeakIdentityDictionary new. |
|
168 |
] |
|
356 | 169 |
]. |
170 |
InfoPrinting := true |
|
1 | 171 |
|
172 |
"Object initialize" |
|
173 |
! ! |
|
174 |
||
345 | 175 |
!Object class methodsFor:'Signal constants'! |
1 | 176 |
|
177 |
errorSignal |
|
71 | 178 |
"return the signal used for error/error: - handling" |
1 | 179 |
|
180 |
^ ErrorSignal |
|
181 |
! |
|
182 |
||
183 |
haltSignal |
|
71 | 184 |
"return the signal used for halt/halt: - handling" |
1 | 185 |
|
186 |
^ HaltSignal |
|
187 |
! |
|
188 |
||
189 |
messageNotUnderstoodSignal |
|
71 | 190 |
"return the signal used for doesNotUnderstand: - error handling" |
1 | 191 |
|
192 |
^ MessageNotUnderstoodSignal |
|
193 |
! |
|
194 |
||
71 | 195 |
privateMethodSignal |
196 |
"return the signal used for privateMethod - error handling" |
|
197 |
||
198 |
^ MessageNotUnderstoodSignal |
|
199 |
! |
|
200 |
||
201 |
primitiveFailureSignal |
|
202 |
"return the signal used for primitiveFailed - error handling" |
|
203 |
||
204 |
^ PrimitiveFailureSignal |
|
205 |
! |
|
206 |
||
1 | 207 |
userInterruptSignal |
71 | 208 |
"return the signal used for ^C interrupts handling" |
1 | 209 |
|
210 |
^ UserInterruptSignal |
|
211 |
! |
|
212 |
||
213 |
recursionInterruptSignal |
|
71 | 214 |
"return the signal used for recursion overflow error handling" |
1 | 215 |
|
216 |
^ RecursionInterruptSignal |
|
217 |
! |
|
218 |
||
219 |
exceptionInterruptSignal |
|
71 | 220 |
"return the signal used for exception (display errors) error handling" |
1 | 221 |
|
222 |
^ ExceptionInterruptSignal |
|
223 |
! |
|
224 |
||
2 | 225 |
subscriptOutOfBoundsSignal |
226 |
"return the signal used for subscript error reporting. |
|
227 |
(this signal is used for example when an array is accessed with an |
|
228 |
index less than 1 or greater than the array size)" |
|
1 | 229 |
|
2 | 230 |
^ SubscriptOutOfBoundsSignal |
231 |
! |
|
232 |
||
233 |
elementOutOfBoundsSignal |
|
234 |
"return the signal used for element error reporting |
|
235 |
(this signal is used for example when a value not in 0..255 is to |
|
236 |
be put into a bytearray)" |
|
237 |
||
238 |
^ ElementOutOfBoundsSignal |
|
1 | 239 |
! |
240 |
||
241 |
nonIntegerIndexSignal |
|
242 |
"return the signal used for bad subscript error reporting" |
|
243 |
||
244 |
^ NonIntegerIndexSignal |
|
245 |
! |
|
246 |
||
2 | 247 |
notFoundSignal |
345 | 248 |
"return the signal used for no element found error reporting" |
2 | 249 |
|
250 |
^ NotFoundSignal |
|
251 |
! |
|
252 |
||
253 |
keyNotFoundSignal |
|
254 |
"return the signal used for no such key error reporting" |
|
255 |
||
256 |
^ KeyNotFoundSignal |
|
257 |
! |
|
258 |
||
1 | 259 |
informationSignal |
260 |
"return the signal used for informations" |
|
261 |
||
262 |
^ InformationSignal |
|
44 | 263 |
! |
264 |
||
159 | 265 |
deepCopyErrorSignal |
266 |
"return the signal raised when a deepcopy is asked for |
|
267 |
an object which cannot do this (for example, BlockClosures |
|
268 |
or Contexts)." |
|
269 |
||
270 |
^ DeepCopyErrorSignal |
|
271 |
! |
|
272 |
||
44 | 273 |
abortSignal |
71 | 274 |
"return the signal used to abort user actions. This signal is only |
77 | 275 |
raised if cought (by the debugger), and will lead way out of the |
71 | 276 |
currently active doIt/printIt or inspectIt. (also some others use |
277 |
this for a save abort)" |
|
44 | 278 |
|
279 |
^ AbortSignal |
|
1 | 280 |
! ! |
281 |
||
356 | 282 |
!Object class methodsFor:'info messages'! |
283 |
||
284 |
infoPrinting:aBoolean |
|
285 |
"turn on/off printing of information messages. |
|
286 |
If the argument, aBoolean is false, infoPrint will not output |
|
287 |
messages. The default is true." |
|
288 |
||
289 |
InfoPrinting := aBoolean |
|
375 | 290 |
! |
291 |
||
292 |
infoPrinting |
|
293 |
"return the flag which controls information messages." |
|
294 |
||
295 |
^ InfoPrinting |
|
356 | 296 |
! ! |
297 |
||
3 | 298 |
!Object class methodsFor:'queries'! |
299 |
||
300 |
isBuiltInClass |
|
49 | 301 |
"return true, if this class is known by the run-time-system, |
302 |
i.e. you cannot add/remove instance variables without recompiling |
|
303 |
the VM." |
|
3 | 304 |
|
305 |
^ self == Object |
|
306 |
! ! |
|
307 |
||
1 | 308 |
!Object methodsFor:'initialization'! |
309 |
||
310 |
initialize |
|
311 |
"just to ignore initialize to objects which do not need it" |
|
312 |
||
313 |
^ self |
|
421 | 314 |
! ! |
315 |
||
316 |
!Object ignoredMethodsFor:'initialization'! |
|
380 | 317 |
|
318 |
fromLiteralArrayEncoding:aSpecArray |
|
319 |
"read my values from a specArray. The argument is supposed to |
|
320 |
consist of setSelector/value pairs, which are sent to the receiver. |
|
321 |
Some classes (Point, Rectangle) redefine this for a slightly more compact |
|
322 |
literal representation. |
|
323 |
This was added to allow for VW windowSpecs to be parsed in ST/X; |
|
324 |
do not use if for general object printing/restoring." |
|
325 |
||
384 | 326 |
|sz "{Class: SmallInteger }"| |
380 | 327 |
|
328 |
sz := aSpecArray size. |
|
329 |
2 to:sz by:2 do:[:i | |
|
330 |
self perform:(aSpecArray at:i) with:(aSpecArray at:i+1) |
|
331 |
] |
|
332 |
||
333 |
" |
|
334 |
(Association new) fromLiteralArrayEncoding:#(#dummy #key: 1 #value: 'one') |
|
335 |
" |
|
1 | 336 |
! ! |
337 |
||
13 | 338 |
!Object methodsFor:'cleanup'! |
339 |
||
340 |
lowSpaceCleanup |
|
341 |
"ignored here - redefined in some classes to |
|
342 |
cleanup in low-memory situations" |
|
343 |
||
344 |
^ self |
|
1 | 345 |
! ! |
346 |
||
347 |
!Object methodsFor:'system primitives'! |
|
348 |
||
349 |
become:anotherObject |
|
13 | 350 |
"make all references to the receiver become references to anotherObject |
351 |
and vice-versa. This may be an expensive (i.e. slow) operation, |
|
352 |
since in the worst case, the whole memory has to be searched for |
|
71 | 353 |
references to the two objects (although the primitive tries hard to |
354 |
limit the search, for acceptable performance in most cases). |
|
93 | 355 |
In general, using become: should be avoided if possible, since it may |
356 |
produce many strange effects (think of hashing in Sets). |
|
13 | 357 |
This method fails, if the receiver or the argument is a SmallInteger |
358 |
or nil, or is a context of a living method (i.e. one that has not already |
|
359 |
returned). |
|
360 |
(notice that become: is not used heavily by the system |
|
93 | 361 |
- the Collection-classes have been rewritten to not use it.)" |
1 | 362 |
%{ |
77 | 363 |
if (__primBecome(self, anotherObject COMMA_CON)) |
159 | 364 |
RETURN ( self ); |
1 | 365 |
%} |
366 |
. |
|
367 |
self primitiveFailed |
|
368 |
! |
|
369 |
||
10 | 370 |
becomeNil |
371 |
"make all references to the receiver become nil - effectively getting |
|
372 |
rid of the receiver. This can be a very dangerous operation - be warned. |
|
71 | 373 |
The receiver may not be a SmallInteger or a context of a living method." |
10 | 374 |
|
375 |
%{ |
|
77 | 376 |
if (__primBecomeNil(self COMMA_CON )) |
159 | 377 |
RETURN ( nil ); |
10 | 378 |
%} |
379 |
. |
|
380 |
self primitiveFailed |
|
381 |
! |
|
382 |
||
3 | 383 |
changeClassTo:otherClass |
384 |
"changes the class of the receiver to the argument, otherClass. |
|
385 |
This is only allowed (possible), if the receivers class and the argument |
|
386 |
have the same structure (i.e. number of named instance variables and |
|
93 | 387 |
type of indexed instance variables). |
388 |
If the structures do not match, or any of the original class or new class |
|
389 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
3 | 390 |
|
85 | 391 |
|myClass ok| |
392 |
||
393 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
|
3 | 394 |
%{ |
329 | 395 |
if (__isNonNilObject(self) |
396 |
&& __isNonNilObject(otherClass) |
|
85 | 397 |
&& (otherClass != UndefinedObject) |
398 |
&& (otherClass != SmallInteger)) { |
|
159 | 399 |
ok = true; |
85 | 400 |
} else { |
159 | 401 |
ok = false; |
85 | 402 |
} |
403 |
%}. |
|
404 |
ok ifTrue:[ |
|
159 | 405 |
ok := false. |
406 |
myClass := self class. |
|
407 |
myClass flags == otherClass flags ifTrue:[ |
|
408 |
myClass instSize == otherClass instSize ifTrue:[ |
|
409 |
"same instance layout and types: its ok to do it" |
|
410 |
ok := true. |
|
411 |
] ifFalse:[ |
|
412 |
myClass isPointers ifTrue:[ |
|
413 |
myClass isVariable ifTrue:[ |
|
414 |
ok := true |
|
415 |
] |
|
416 |
] |
|
417 |
] |
|
418 |
] ifFalse:[ |
|
419 |
myClass isPointers ifTrue:[ |
|
420 |
"if newClass is a variable class, with instSize <= my instsize, |
|
421 |
we can do it (effectively mapping additional instvars into the |
|
422 |
variable part) - usefulness is questionable, though" |
|
423 |
||
424 |
otherClass isPointers ifTrue:[ |
|
425 |
otherClass isVariable ifTrue:[ |
|
426 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
427 |
ifTrue:[ |
|
428 |
ok := true |
|
429 |
] |
|
430 |
] ifFalse:[ |
|
431 |
otherClass instSize == (myClass instSize + self basicSize) |
|
432 |
ifTrue:[ |
|
433 |
ok := true |
|
434 |
] |
|
435 |
] |
|
436 |
] ifFalse:[ |
|
437 |
"it does not make sense to convert pointers to bytes ..." |
|
438 |
] |
|
439 |
] ifFalse:[ |
|
440 |
"does it make sense, to convert bits ?" |
|
441 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
442 |
] |
|
443 |
] |
|
3 | 444 |
]. |
85 | 445 |
ok ifTrue:[ |
159 | 446 |
"now, change the receivers class ..." |
85 | 447 |
%{ |
329 | 448 |
__qClass(self) = otherClass; |
159 | 449 |
__STORE(self, otherClass); |
450 |
RETURN ( self ); |
|
85 | 451 |
%}. |
452 |
]. |
|
3 | 453 |
self primitiveFailed |
454 |
! |
|
455 |
||
456 |
changeClassToThatOf:anObject |
|
457 |
"changes the class of the receiver to that of the argument, anObject. |
|
458 |
This is only allowed (possible), if the receivers class and the arguments |
|
459 |
class have the same structure (i.e. number of named instance variables and |
|
460 |
type of indexed instance variables). If the structures do not match, or any |
|
71 | 461 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
3 | 462 |
|
463 |
self changeClassTo:(anObject class) |
|
1 | 464 |
! ! |
465 |
||
466 |
!Object methodsFor:'queries'! |
|
467 |
||
468 |
size |
|
469 |
"return the number of the receivers indexed instance variables; |
|
470 |
this method may be redefined in subclasses" |
|
471 |
||
472 |
^ self basicSize |
|
473 |
! |
|
474 |
||
475 |
basicSize |
|
71 | 476 |
"return the number of the receivers indexed instance variables, |
477 |
0 if it has none. |
|
478 |
||
479 |
This method should NOT be redefined in any subclass" |
|
1 | 480 |
|
481 |
%{ /* NOCONTEXT */ |
|
482 |
||
329 | 483 |
REGISTER int nbytes; |
484 |
REGISTER OBJ myClass; |
|
485 |
REGISTER int flags; |
|
1 | 486 |
|
487 |
/* |
|
56 | 488 |
* notice the missing test for self being a nonNilObject - |
1 | 489 |
* this can be done since basicSize is defined both in UndefinedObject |
490 |
* and SmallInteger |
|
491 |
*/ |
|
329 | 492 |
myClass = __qClass(self); |
493 |
nbytes = __qSize(self) |
|
159 | 494 |
- OHDR_SIZE |
495 |
- __OBJS2BYTES__(_intVal(_ClassInstPtr(myClass)->c_ninstvars)); |
|
1 | 496 |
|
329 | 497 |
flags = _intVal(_ClassInstPtr(myClass)->c_flags) & ARRAYMASK; |
498 |
/* |
|
499 |
* replaced switch by open-if; this is slightly faster since |
|
500 |
* it avoids the range check and also checks the most common case first |
|
501 |
*/ |
|
502 |
if ((flags == POINTERARRAY) |
|
503 |
|| (flags == WKPOINTERARRAY)) { |
|
504 |
RETURN ( _MKSMALLINT(__BYTES2OBJS__(nbytes)) ); |
|
505 |
} |
|
506 |
if (flags == BYTEARRAY) { |
|
159 | 507 |
RETURN ( _MKSMALLINT(nbytes / sizeof(char)) ); |
329 | 508 |
} |
509 |
if (flags == FLOATARRAY) { |
|
510 |
RETURN ( _MKSMALLINT(nbytes / sizeof(float)) ); |
|
511 |
} |
|
512 |
if (flags == DOUBLEARRAY) { |
|
56 | 513 |
#ifdef NEED_DOUBLE_ALIGN |
159 | 514 |
/* |
515 |
* care for filler |
|
516 |
*/ |
|
517 |
nbytes -= sizeof(FILLTYPE); |
|
56 | 518 |
#endif |
159 | 519 |
RETURN ( _MKSMALLINT(nbytes / sizeof(double)) ); |
329 | 520 |
} |
521 |
if (flags == LONGARRAY) { |
|
522 |
RETURN ( _MKSMALLINT(nbytes / sizeof(long)) ); |
|
1 | 523 |
} |
329 | 524 |
if (flags == WORDARRAY) { |
525 |
RETURN ( _MKSMALLINT(nbytes / sizeof(short)) ); |
|
526 |
} |
|
527 |
%}. |
|
1 | 528 |
^ 0 |
529 |
! |
|
530 |
||
531 |
isVariable |
|
532 |
"return true if the receiver has indexed instance variables, |
|
71 | 533 |
false otherwise." |
1 | 534 |
|
535 |
^ self class isVariable |
|
536 |
! |
|
537 |
||
538 |
isFixedSize |
|
293 | 539 |
"return true if the receiver cannot grow easily |
540 |
(i.e. a grow may be expensive, since it involves a become:)" |
|
1 | 541 |
|
542 |
^ true |
|
543 |
! |
|
544 |
||
545 |
class |
|
546 |
"return the receivers class" |
|
547 |
||
548 |
%{ /* NOCONTEXT */ |
|
549 |
||
329 | 550 |
RETURN ( __Class(self) ); |
1 | 551 |
%} |
552 |
! |
|
553 |
||
554 |
species |
|
555 |
"return a class which is similar to (or the same as) the receivers class. |
|
556 |
This is used to create an appropriate object when creating derived |
|
71 | 557 |
copies in the collection classes (sometimes redefined)." |
1 | 558 |
|
559 |
^ self class |
|
560 |
! |
|
561 |
||
562 |
yourself |
|
563 |
"return the receiver - used for cascades to return self at the end" |
|
564 |
||
565 |
^ self |
|
566 |
! |
|
567 |
||
568 |
isBehavior |
|
569 |
"return true, if the receiver is some kind of class (i.e. behavior); |
|
259 | 570 |
false is returned here - the method is only redefined in Behavior." |
1 | 571 |
|
572 |
^ false |
|
573 |
! |
|
574 |
||
2 | 575 |
isClass |
71 | 576 |
"return true, if the receiver is some kind of class (real class, |
577 |
not just behavior); |
|
259 | 578 |
false is returned here - the method is only redefined in Class." |
2 | 579 |
|
580 |
^ false |
|
581 |
! |
|
582 |
||
1 | 583 |
isMeta |
584 |
"return true, if the receiver is some kind of metaclass; |
|
259 | 585 |
false is returned here - the method is only redefined in Metaclass." |
1 | 586 |
|
587 |
^ false |
|
588 |
! |
|
589 |
||
590 |
isBlock |
|
71 | 591 |
"return true, if the receiver is some kind of block; |
259 | 592 |
false returned here - the method is only redefined in Block." |
593 |
||
594 |
^ false |
|
595 |
! |
|
596 |
||
597 |
isMethod |
|
598 |
"return true, if the receiver is some kind of method; |
|
599 |
false returned here - the method is only redefined in Method." |
|
1 | 600 |
|
601 |
^ false |
|
602 |
! |
|
603 |
||
604 |
isContext |
|
71 | 605 |
"return true, if the receiver is some kind of context; |
259 | 606 |
false returned here - the method is only redefined in Context." |
607 |
||
608 |
^ false |
|
609 |
! |
|
610 |
||
611 |
isSignal |
|
612 |
"return true, if the receiver is some kind of signal; |
|
613 |
false returned here - the method is only redefined in Signal." |
|
1 | 614 |
|
615 |
^ false |
|
616 |
! |
|
617 |
||
618 |
isStream |
|
619 |
"return true, if the receiver is some kind of stream; |
|
259 | 620 |
false is returned here - the method is only redefined in Stream." |
1 | 621 |
|
622 |
^ false |
|
623 |
! |
|
624 |
||
438 | 625 |
isExternalStream |
626 |
"return true, if the receiver is some kind of externalStream; |
|
627 |
false is returned here - the method is only redefined in ExternalStream." |
|
628 |
||
629 |
^false |
|
630 |
! |
|
631 |
||
71 | 632 |
isFileStream |
633 |
"return true, if the receiver is some kind of fileStream; |
|
259 | 634 |
false is returned here - the method is only redefined in FileStream." |
71 | 635 |
|
636 |
^false |
|
637 |
! |
|
638 |
||
259 | 639 |
isCollection |
640 |
"return true, if the receiver is some kind of collection; |
|
641 |
false is returned here - the method is only redefined in Collection." |
|
642 |
||
643 |
^ false |
|
644 |
! |
|
645 |
||
202 | 646 |
isSequenceable |
71 | 647 |
"return true, if the receiver is some kind of sequenceable collection; |
259 | 648 |
false is returned here - the method is only redefined in SequenceableCollection." |
71 | 649 |
|
650 |
^ false |
|
651 |
! |
|
652 |
||
202 | 653 |
isSequenceableCollection |
654 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
655 |
This method is a historic leftover and will be removed soon ..." |
|
656 |
||
359 | 657 |
self obsoleteMethodWarning:'use #isSequenceable'. |
202 | 658 |
^ false |
659 |
! |
|
660 |
||
71 | 661 |
isColor |
662 |
"return true, if the receiver is some kind of color; |
|
259 | 663 |
false is returned here - the method is only redefined in Color." |
71 | 664 |
|
665 |
^ false |
|
666 |
! |
|
667 |
||
370 | 668 |
isArray |
669 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
670 |
false is returned here - the method is only redefined in Array." |
|
671 |
||
672 |
^ false |
|
673 |
! |
|
674 |
||
56 | 675 |
isString |
676 |
"return true, if the receiver is some kind of string; |
|
259 | 677 |
false is returned here - the method is only redefined in String." |
56 | 678 |
|
679 |
^ false |
|
680 |
! |
|
681 |
||
179 | 682 |
isSymbol |
683 |
"return true, if the receiver is some kind of symbol; |
|
259 | 684 |
false is returned here - the method is only redefined in Symbol." |
179 | 685 |
|
686 |
^ false |
|
687 |
! |
|
688 |
||
71 | 689 |
isCharacter |
690 |
"return true, if the receiver is some kind of character; |
|
259 | 691 |
false is returned here - the method is only redefined in Character." |
71 | 692 |
|
693 |
^ false |
|
2 | 694 |
! |
695 |
||
13 | 696 |
isNumber |
697 |
"return true, if the receiver is some kind of number; |
|
259 | 698 |
false is returned here - the method is only redefined in Number." |
699 |
||
700 |
^ false |
|
701 |
! |
|
702 |
||
703 |
isFraction |
|
704 |
"return true, if the receiver is some kind of fraction; |
|
705 |
false is returned here - the method is only redefined in Fraction." |
|
13 | 706 |
|
707 |
^ false |
|
708 |
! |
|
709 |
||
482 | 710 |
isReal |
711 |
"return true, if the receiver is some kind of real number; |
|
712 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
|
713 |
||
714 |
^ false |
|
715 |
! |
|
716 |
||
1 | 717 |
isInteger |
718 |
"return true, if the receiver is some kind of integer number; |
|
259 | 719 |
false is returned here - the method is only redefined in Integer." |
1 | 720 |
|
721 |
^ false |
|
722 |
! |
|
723 |
||
77 | 724 |
isPoint |
725 |
"return true, if the receiver is some kind of point; |
|
259 | 726 |
false is returned here - the method is only redefined in Point." |
77 | 727 |
|
728 |
^ false |
|
729 |
! |
|
730 |
||
731 |
isRectangle |
|
732 |
"return true, if the receiver is some kind of rectangle; |
|
259 | 733 |
false is returned here - the method is only redefined in Rectangle." |
734 |
||
735 |
^ false |
|
736 |
! |
|
737 |
||
339 | 738 |
isLayout |
739 |
"return true, if the receiver is some kind of layout; |
|
740 |
false is returned here - the method is only redefined in Layout." |
|
741 |
||
742 |
^ false |
|
743 |
! |
|
744 |
||
259 | 745 |
isForm |
746 |
"return true, if the receiver is some kind of form; |
|
747 |
false is returned here - the method is only redefined in Form." |
|
748 |
||
749 |
^ false |
|
750 |
! |
|
751 |
||
752 |
isImage |
|
753 |
"return true, if the receiver is some kind of image; |
|
754 |
false is returned here - the method is only redefined in Image." |
|
755 |
||
756 |
^ false |
|
757 |
! |
|
758 |
||
759 |
isImageOrForm |
|
760 |
"return true, if the receiver is some kind of image or form; |
|
761 |
false is returned here - the method is only redefined in Image and Form." |
|
77 | 762 |
|
763 |
^ false |
|
764 |
! |
|
765 |
||
329 | 766 |
isView |
767 |
"return true, if the receiver is some kind of view; |
|
768 |
false is returned here - the method is only redefined in View." |
|
769 |
||
770 |
^ false |
|
771 |
! |
|
772 |
||
56 | 773 |
isLiteral |
774 |
"return true, if the receiver can be represented as a constant in ST syntax; |
|
775 |
false is returned here - the method is redefined in some classes." |
|
776 |
||
777 |
^ false |
|
778 |
! |
|
779 |
||
1 | 780 |
isMemberOf:aClass |
44 | 781 |
"return true, if the receiver is an instance of aClass, false otherwise. |
259 | 782 |
Advice: |
783 |
use of this to check objects for certain attributes/protocoll should |
|
784 |
be avoided; it limits the reusability of your classes by limiting use |
|
785 |
to instances of a certain class. |
|
786 |
Use check-methods to check an object for a certain attributes/protocol |
|
787 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
788 |
||
789 |
Using #isMemberOf: is considered BAD STYLE." |
|
1 | 790 |
|
791 |
^ (self class) == aClass |
|
792 |
! |
|
793 |
||
794 |
isKindOf:aClass |
|
795 |
"return true, if the receiver is an instance of aClass or one of its |
|
44 | 796 |
subclasses, false otherwise. |
259 | 797 |
Advice: |
798 |
use of this to check objects for certain attributes/protocoll should |
|
799 |
be avoided; it limits the reusability of your classes by limiting use |
|
800 |
to instances of certain classes and fences you into a specific inheritance |
|
801 |
hierarchy. |
|
802 |
Use check-methods to check an object for a certain attributes/protocol |
|
803 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
804 |
||
805 |
Using #isKindOf: is considered BAD STYLE. |
|
806 |
||
807 |
Advice2: |
|
325 | 808 |
Be aware, that using an #isXXX method is usually much faster than |
809 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
810 |
hierarchy, comparing every class on the way. |
|
811 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
812 |
a single function call. |
|
259 | 813 |
" |
1 | 814 |
|
815 |
%{ /* NOCONTEXT */ |
|
816 |
register OBJ thisClass; |
|
817 |
||
329 | 818 |
thisClass = __Class(self); |
1 | 819 |
while (thisClass != nil) { |
159 | 820 |
if (thisClass == aClass) { |
821 |
RETURN ( true ); |
|
822 |
} |
|
823 |
thisClass = _ClassInstPtr(thisClass)->c_superclass; |
|
1 | 824 |
} |
825 |
%} |
|
826 |
. |
|
85 | 827 |
"/ |
828 |
"/ the above code is equivalent to: |
|
829 |
"/ |
|
830 |
"/ thisClass := self class. |
|
831 |
"/ [thisClass notNil] whileTrue:[ |
|
832 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
833 |
"/ thisClass := thisClass superclass |
|
834 |
"/ ] |
|
835 |
"/ |
|
1 | 836 |
^ false |
837 |
! |
|
838 |
||
839 |
respondsTo:aSelector |
|
840 |
"return true, if the receiver implements a method with selector equal |
|
841 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
71 | 842 |
receivers class or one of its superclasses. |
843 |
||
844 |
Notice, that this does not imply, that such a message can be sent without |
|
845 |
an error being raised. For example, an implementation could send |
|
846 |
#shouldNotImplement or #subclassResponsibility." |
|
847 |
||
848 |
" |
|
849 |
should we go via the cache, or search (by class) ? |
|
259 | 850 |
The first is faster, most of the time; while the 2nd fills |
71 | 851 |
the cache with useless data if this is sent in a loop over all objects. |
852 |
For now, use the cache ... |
|
853 |
" |
|
1 | 854 |
%{ /* NOCONTEXT */ |
855 |
||
362 | 856 |
extern OBJ __lookup(); |
857 |
||
858 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
159 | 859 |
RETURN ( false ); |
1 | 860 |
} |
861 |
RETURN ( true ); |
|
862 |
%} |
|
863 |
. |
|
71 | 864 |
" |
1 | 865 |
^ self class canUnderstand:aSelector |
71 | 866 |
" |
867 |
||
868 |
"'aString' respondsTo:#+" |
|
869 |
"'aString' respondsTo:#," |
|
870 |
"'aString' respondsTo:#collect:" |
|
871 |
! |
|
872 |
||
873 |
respondsToArithmetic |
|
874 |
"return true, if the receiver responds to arithmetic messages. |
|
875 |
false is returned here - the method is redefined in ArithmeticValue." |
|
876 |
||
877 |
^ false |
|
202 | 878 |
! ! |
879 |
||
880 |
!Object methodsFor:'special queries'! |
|
1 | 881 |
|
882 |
references:anObject |
|
883 |
"return true, if the receiver refers to the argument, anObject. |
|
884 |
- for debugging only" |
|
885 |
||
886 |
|myClass |
|
887 |
numInst "{ Class: SmallInteger }" | |
|
888 |
||
369 | 889 |
%{ |
890 |
/* |
|
891 |
* a little optimization: use the fact that all old objects |
|
892 |
* refering to a new object are on the remSet; if I am not, |
|
893 |
* a trivial reject is possible, if anObject is a newbee |
|
894 |
*/ |
|
895 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
896 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
897 |
int spc; |
|
898 |
||
899 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
900 |
RETURN (false); |
|
901 |
} |
|
902 |
} |
|
903 |
} |
|
904 |
%}. |
|
905 |
||
1 | 906 |
myClass := self class. |
907 |
||
908 |
"check the class" |
|
909 |
(myClass == anObject) ifTrue:[^ true]. |
|
910 |
||
911 |
"check the instance variables" |
|
912 |
numInst := myClass instSize. |
|
913 |
1 to:numInst do:[:i | |
|
159 | 914 |
((self instVarAt:i) == anObject) ifTrue:[^ true] |
1 | 915 |
]. |
916 |
||
917 |
"check the indexed variables" |
|
918 |
myClass isVariable ifTrue:[ |
|
202 | 919 |
myClass isPointers ifFalse:[ |
369 | 920 |
"/ |
921 |
"/ we could argue about the following unconditional return: |
|
922 |
"/ it says that a non pointer array never has a reference to the |
|
923 |
"/ corresponding object - not mimicing a reference to a copy of the |
|
924 |
"/ integer. However, it avoids useless searches in huge byteArray |
|
925 |
"/ like objects when searching for owners. If in doubt, remove it. |
|
926 |
"/ A consequence of the return below is that #[1 2 3] will say that it |
|
927 |
"/ does not refer to the number 2 (think of keeping a copy instead) |
|
928 |
||
216 | 929 |
^ false. |
369 | 930 |
|
931 |
"/ alternative: |
|
932 |
"/ anObject isNumber ifFalse:[^ false]. |
|
179 | 933 |
]. |
369 | 934 |
|
935 |
"/ |
|
936 |
"/ because arrays are so common, and those have a highly tuned |
|
937 |
"/ idenitytIndex method, use it |
|
938 |
"/ |
|
179 | 939 |
myClass == Array ifTrue:[ |
940 |
^ (self identityIndexOf:anObject) ~~ 0 |
|
941 |
]. |
|
369 | 942 |
|
943 |
"/ |
|
944 |
"/ otherwise, do it the slow way |
|
945 |
"/ |
|
179 | 946 |
numInst := self basicSize. |
159 | 947 |
1 to:numInst do:[:i | |
948 |
((self basicAt:i) == anObject) ifTrue:[^ true] |
|
949 |
] |
|
1 | 950 |
]. |
951 |
^ false |
|
202 | 952 |
|
953 |
" |
|
954 |
|v| |
|
955 |
||
956 |
v := View new initialize. |
|
957 |
v references:Display. |
|
958 |
" |
|
1 | 959 |
! |
960 |
||
179 | 961 |
referencesInstanceOf:aClass |
962 |
"return true, if the receiver refers to an instance of |
|
963 |
the argument, aClass.This method exists |
|
964 |
to support searching for users of a class." |
|
965 |
||
966 |
|myClass |
|
967 |
numInst "{ Class: SmallInteger }" | |
|
968 |
||
969 |
myClass := self class. |
|
970 |
||
971 |
"check the class" |
|
972 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
973 |
||
974 |
"check the instance variables" |
|
975 |
numInst := myClass instSize. |
|
976 |
1 to:numInst do:[:i | |
|
977 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
978 |
]. |
|
979 |
||
980 |
"check the indexed variables" |
|
981 |
myClass isVariable ifTrue:[ |
|
216 | 982 |
myClass isPointers ifFalse:[ |
983 |
"no need to search in non-pointer indexed fields" |
|
984 |
myClass isLongs ifTrue:[ |
|
985 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
986 |
] ifFalse:[ |
|
987 |
myClass isFloats ifTrue:[^ aClass == Float]. |
|
988 |
myClass isDoubles ifTrue:[^ aClass == Float]. |
|
989 |
^ aClass == SmallInteger |
|
990 |
] |
|
991 |
]. |
|
179 | 992 |
numInst := self basicSize. |
993 |
1 to:numInst do:[:i | |
|
994 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
995 |
] |
|
996 |
]. |
|
997 |
^ false |
|
998 |
||
999 |
" |
|
1000 |
(1 @ 3.4) referencesInstanceOf:Float |
|
216 | 1001 |
(1 @ 3.4) referencesInstanceOf:Fraction |
202 | 1002 |
View new initialize referencesInstanceOf:(Display class) |
179 | 1003 |
" |
1004 |
! |
|
1005 |
||
1006 |
referencesDerivedInstanceOf:aClass |
|
1007 |
"return true, if the receiver refers to an instance of |
|
1008 |
the argument, aClass or its subclass. This method exists |
|
1009 |
to support searching for users of a class." |
|
1010 |
||
1011 |
|myClass |
|
1012 |
numInst "{ Class: SmallInteger }" | |
|
1013 |
||
1014 |
myClass := self class. |
|
1015 |
||
1016 |
"check the class" |
|
1017 |
(myClass isKindOf:aClass) ifTrue:[^ true]. |
|
1018 |
||
1019 |
"check the instance variables" |
|
1020 |
numInst := myClass instSize. |
|
1021 |
1 to:numInst do:[:i | |
|
1022 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
1023 |
]. |
|
1024 |
||
1025 |
"check the indexed variables" |
|
1026 |
myClass isVariable ifTrue:[ |
|
216 | 1027 |
myClass isPointers ifFalse:[ |
1028 |
"no need to search in non pointer fields" |
|
1029 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
|
1030 |
]. |
|
179 | 1031 |
numInst := self basicSize. |
1032 |
1 to:numInst do:[:i | |
|
1033 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
1034 |
] |
|
1035 |
]. |
|
1036 |
^ false |
|
1037 |
||
1038 |
" |
|
1039 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
|
1040 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
202 | 1041 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
179 | 1042 |
" |
1043 |
! |
|
1044 |
||
1 | 1045 |
allOwners |
1046 |
"return a collection of all objects referencing the receiver" |
|
1047 |
||
1048 |
^ ObjectMemory whoReferences:self |
|
1049 |
! ! |
|
1050 |
||
1051 |
!Object methodsFor:'misc'! |
|
1052 |
||
1053 |
-> anObject |
|
1054 |
"return an association with the receiver as key and |
|
1055 |
the argument as value" |
|
1056 |
||
1057 |
^ Association key:self value:anObject |
|
1058 |
! ! |
|
1059 |
||
159 | 1060 |
!Object methodsFor:'evaluation'! |
1061 |
||
1062 |
value |
|
1063 |
"this allows every object to be used where blocks are typically used. |
|
1064 |
Time will show, if this is a good idea or leads to sloppy programming |
|
202 | 1065 |
style ... (the idea was borrowed from the Self language). |
159 | 1066 |
WARNING: dont 'optimize' away ifXXX: blocks - the compilers will |
1067 |
only generate inline code for the if, if the argument(s) are blocks. |
|
1068 |
It will work, but run slower instead." |
|
1069 |
||
1070 |
^ self |
|
1071 |
||
1072 |
" |
|
1073 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
|
1074 |
" |
|
202 | 1075 |
|
1076 |
"DO NOT DO THIS (its slower) |
|
1077 |
(1 > 4) ifTrue:'oops' ifFalse:'ok' |
|
1078 |
||
1079 |
USE (the compiler optimizes blocks in if/while): |
|
1080 |
(1 > 4) ifTrue:['oops'] ifFalse:['ok'] |
|
1081 |
" |
|
159 | 1082 |
! ! |
1083 |
||
1 | 1084 |
!Object methodsFor:'copying'! |
1085 |
||
1086 |
copy |
|
159 | 1087 |
"return a copy of the receiver - defaults to shallowcopy here. |
1088 |
Notice, that copy does not copy dependents." |
|
1089 |
||
202 | 1090 |
^ self shallowCopy postCopy |
159 | 1091 |
! |
1092 |
||
1093 |
shallowCopyForFinalization |
|
1094 |
"this is used to aquire a copy to be used for finalization - |
|
1095 |
(the copy will get a dispose-notification; see the documentation in the Registry class) |
|
1096 |
This method can be redefined for more efficient copying - especially for large objects." |
|
1 | 1097 |
|
1098 |
^ self shallowCopy |
|
1099 |
! |
|
1100 |
||
1101 |
shallowCopy |
|
13 | 1102 |
"return a copy of the object with shared subobjects (a shallow copy) |
1103 |
i.e. the copy shares referenced instvars with its original." |
|
1 | 1104 |
|
1105 |
|myClass aCopy |
|
1106 |
sz "{ Class: SmallInteger }" | |
|
1107 |
||
1108 |
myClass := self class. |
|
1109 |
myClass isVariable ifTrue:[ |
|
159 | 1110 |
sz := self basicSize. |
1111 |
aCopy := myClass basicNew:sz. |
|
1112 |
||
1113 |
"copy the indexed variables" |
|
1114 |
1 to:sz do:[:i | |
|
1115 |
aCopy basicAt:i put:(self basicAt:i) |
|
1116 |
] |
|
1 | 1117 |
] ifFalse:[ |
159 | 1118 |
aCopy := myClass basicNew |
1 | 1119 |
]. |
1120 |
||
1121 |
"copy the instance variables" |
|
1122 |
sz := myClass instSize. |
|
1123 |
1 to:sz do:[:i | |
|
159 | 1124 |
aCopy instVarAt:i put:(self instVarAt:i) |
1 | 1125 |
]. |
1126 |
||
1127 |
^ aCopy |
|
1128 |
! |
|
1129 |
||
159 | 1130 |
postCopy |
1131 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
1132 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
1133 |
(see there)" |
|
1134 |
||
1135 |
^ self |
|
1136 |
! |
|
1137 |
||
1138 |
postCopyFrom:original |
|
1139 |
"sent to a freshly deep-copied object to give it a chance to adjust things. |
|
1140 |
(a font could flush its device-handle for example). |
|
1141 |
Notice, that for Sets/Dicts etc. a rehash is not needed, since the deepCopy |
|
1142 |
will have the same hash key as the receiver (as long as ST/X provides the |
|
1143 |
setHash: functionality)." |
|
1144 |
||
1145 |
"for ST-80 compatibility, we try postCopy here ..." |
|
1146 |
^ self postCopy |
|
1147 |
! |
|
1148 |
||
1 | 1149 |
deepCopy |
1150 |
"return a copy of the object with all subobjects also copied. |
|
71 | 1151 |
This method DOES handle cycles/self-refs; however the receivers |
159 | 1152 |
class is not copied (to avoid the 'total' copy). |
202 | 1153 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
1154 |
keeps track of already copied objects. If you are sure, that your |
|
1155 |
copied object does not include dublicates (or you do not care) and |
|
1156 |
no cycles, you can use the old simpleDeepCopy, which avoids this overhead, |
|
1157 |
but may run into trouble. |
|
159 | 1158 |
Notice, that copy does not copy dependents." |
13 | 1159 |
|
1160 |
^ self deepCopyUsing:(IdentityDictionary new) |
|
202 | 1161 |
|
1162 |
"an example which is not handled by the old deepCopy: |
|
1163 |
||
1164 |
|a| |
|
1165 |
a := Array new:3. |
|
1166 |
a at:3 put:a. |
|
1167 |
a deepCopy inspect |
|
1168 |
" |
|
13 | 1169 |
! |
1170 |
||
159 | 1171 |
deepCopyError |
1172 |
"raise a signal, that deepCopy is not allowed for this object" |
|
1173 |
||
1174 |
^ DeepCopyErrorSignal raise |
|
13 | 1175 |
! |
1176 |
||
1177 |
deepCopyUsing:aDictionary |
|
1178 |
"a helper for deepCopy; return a copy of the object with |
|
1179 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
1180 |
use the value found there. The class of the receiver is not copied. |
|
71 | 1181 |
This method DOES handle cycles/self references." |
13 | 1182 |
|
1183 |
|myClass aCopy |
|
1184 |
sz "{ Class: SmallInteger }" |
|
1185 |
iOrig iCopy| |
|
1186 |
||
1187 |
myClass := self class. |
|
1188 |
myClass isVariable ifTrue:[ |
|
159 | 1189 |
sz := self basicSize. |
1190 |
aCopy := myClass basicNew:sz. |
|
13 | 1191 |
] ifFalse:[ |
159 | 1192 |
sz := 0. |
1193 |
aCopy := myClass basicNew |
|
13 | 1194 |
]. |
71 | 1195 |
aCopy setHashFrom:self. |
13 | 1196 |
|
1197 |
aDictionary at:self put:aCopy. |
|
202 | 1198 |
|
1199 |
" |
|
1200 |
copy indexed instvars - if any |
|
1201 |
" |
|
13 | 1202 |
sz ~~ 0 ifTrue:[ |
202 | 1203 |
myClass isBits ifTrue:[ |
159 | 1204 |
"block-copy indexed instvars" |
1205 |
aCopy replaceFrom:1 to:sz with:self startingAt:1 |
|
1206 |
] ifFalse:[ |
|
1207 |
"individual deep copy the indexed variables" |
|
1208 |
1 to:sz do:[:i | |
|
1209 |
iOrig := self basicAt:i. |
|
1210 |
iOrig notNil ifTrue:[ |
|
1211 |
(aDictionary includesKey:iOrig) ifTrue:[ |
|
1212 |
iCopy := aDictionary at:iOrig |
|
1213 |
] ifFalse:[ |
|
1214 |
iCopy := iOrig deepCopyUsing:aDictionary. |
|
1215 |
]. |
|
1216 |
aCopy basicAt:i put:iCopy |
|
1217 |
] |
|
1218 |
] |
|
1219 |
] |
|
13 | 1220 |
]. |
1221 |
||
202 | 1222 |
" |
1223 |
copy the instance variables |
|
1224 |
" |
|
13 | 1225 |
sz := myClass instSize. |
1226 |
sz ~~ 0 ifTrue:[ |
|
159 | 1227 |
1 to:sz do:[:i | |
1228 |
iOrig := self instVarAt:i. |
|
1229 |
iOrig notNil ifTrue:[ |
|
1230 |
(aDictionary includesKey:iOrig) ifTrue:[ |
|
1231 |
iCopy := aDictionary at:iOrig |
|
1232 |
] ifFalse:[ |
|
1233 |
iCopy := iOrig deepCopyUsing:aDictionary. |
|
1234 |
]. |
|
1235 |
aCopy instVarAt:i put:iCopy |
|
1236 |
] |
|
1237 |
]. |
|
13 | 1238 |
]. |
1239 |
||
1240 |
^ aCopy |
|
1241 |
! |
|
1242 |
||
1243 |
simpleDeepCopy |
|
1244 |
"return a copy of the object with all subobjects also copied. |
|
77 | 1245 |
This method does NOT handle cycles - but is included to allow this |
1246 |
slightly faster copy in situations where it is known that |
|
1247 |
no recursive references occur (LargeIntegers for example). |
|
71 | 1248 |
NOTICE: you will run into trouble, when trying this with recursive |
77 | 1249 |
objects (usually recursionInterrupt or memory-alert). |
1250 |
This method corresponds to the 'traditional' deepCopy found in |
|
1251 |
the Blue book." |
|
1 | 1252 |
|
1253 |
|myClass aCopy |
|
1254 |
sz "{ Class: SmallInteger }" | |
|
1255 |
||
1256 |
myClass := self class. |
|
1257 |
myClass isVariable ifTrue:[ |
|
159 | 1258 |
sz := self basicSize. |
1259 |
aCopy := myClass basicNew:sz. |
|
1260 |
||
1261 |
"copy the indexed variables" |
|
1262 |
1 to:sz do:[:i | |
|
1263 |
aCopy basicAt:i put:((self basicAt:i) simpleDeepCopy) |
|
1264 |
] |
|
1 | 1265 |
] ifFalse:[ |
159 | 1266 |
aCopy := myClass basicNew |
1 | 1267 |
]. |
1268 |
||
1269 |
"copy the instance variables" |
|
1270 |
sz := myClass instSize. |
|
1271 |
1 to:sz do:[:i | |
|
159 | 1272 |
aCopy instVarAt:i put:((self instVarAt:i) simpleDeepCopy) |
1 | 1273 |
]. |
1274 |
||
1275 |
^ aCopy |
|
71 | 1276 |
|
1277 |
"a bad example (but ST/X should survive ...)" |
|
1278 |
" |
|
1279 |
|a| |
|
1280 |
a := Array new:3. |
|
1281 |
a at:3 put:a. |
|
1282 |
a simpleDeepCopy |
|
1283 |
" |
|
1284 |
! |
|
1285 |
||
1286 |
setHashFrom:anObject |
|
1287 |
"set my identity-hash key to be the same as anObjects hash key. |
|
1288 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
1289 |
Smalltalks, and may not be available in future ST/X versions. |
|
1290 |
DO NEVER use this for normal application code." |
|
1291 |
||
1292 |
%{ /* NOCONTEXT */ |
|
1293 |
||
1294 |
REGISTER unsigned h; |
|
1295 |
||
329 | 1296 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
375 | 1297 |
h = __GET_HASH(anObject); |
1298 |
__SET_HASH(self, h); |
|
159 | 1299 |
RETURN (self); |
71 | 1300 |
} |
1301 |
%} |
|
1302 |
. |
|
1303 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
1 | 1304 |
! ! |
1305 |
||
1306 |
!Object methodsFor:'comparing'! |
|
1307 |
||
1308 |
== anObject |
|
1309 |
"return true, if the receiver and the arg are the same object" |
|
1310 |
||
1311 |
%{ /* NOCONTEXT */ |
|
1312 |
||
1313 |
RETURN ( (self == anObject) ? true : false ); |
|
1314 |
%} |
|
1315 |
! |
|
1316 |
||
1317 |
~~ anObject |
|
1318 |
"return true, if the receiver and the arg are not the same object" |
|
1319 |
||
1320 |
%{ /* NOCONTEXT */ |
|
1321 |
||
1322 |
RETURN ( (self == anObject) ? false : true ); |
|
1323 |
%} |
|
1324 |
! |
|
1325 |
||
1326 |
= anObject |
|
1327 |
"return true, if the receiver and the arg have the same structure" |
|
1328 |
||
1329 |
^ self == anObject |
|
1330 |
! |
|
1331 |
||
1332 |
~= anObject |
|
1333 |
"return true, if the receiver and the arg do not have the same structure" |
|
1334 |
||
1335 |
^ (self = anObject) not |
|
1336 |
! |
|
1337 |
||
1338 |
isNil |
|
1339 |
"return true, if the receiver is nil" |
|
1340 |
||
1341 |
^ false |
|
1342 |
! |
|
1343 |
||
1344 |
notNil |
|
1345 |
"return true, if the receiver is not nil" |
|
1346 |
||
1347 |
^ true |
|
1348 |
! |
|
1349 |
||
1350 |
hash |
|
1351 |
"return an Integer useful as a hash key for the receiver. |
|
1352 |
This hash should return same values for objects with same |
|
1353 |
contents (i.e. use this to hash on structure)" |
|
1354 |
||
1355 |
^ self identityHash |
|
1356 |
! |
|
1357 |
||
1358 |
identityHash |
|
1359 |
"return an Integer useful as a hash key for the receiver. |
|
1360 |
This hash should return same values for the same object (i.e. use |
|
1361 |
this to hash on identity of objects). |
|
1362 |
||
1363 |
We cannot use the Objects address (as other smalltalks do) since |
|
1364 |
no object-table exists and the hashval must not change when objects |
|
1365 |
are moved by the collector. Therefore we assign each object a unique |
|
1366 |
Id in the object header itself as its hashed upon. |
|
370 | 1367 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
1368 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
2 | 1369 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
1370 |
hashed-upon objects could add an instvar containing the hash value." |
|
1 | 1371 |
|
1372 |
%{ /* NOCONTEXT */ |
|
1373 |
||
216 | 1374 |
REGISTER unsigned hash; |
13 | 1375 |
static unsigned nextHash = 0; |
1 | 1376 |
OBJ cls; |
1377 |
||
329 | 1378 |
if (__isNonNilObject(self)) { |
375 | 1379 |
hash = __GET_HASH(self); |
216 | 1380 |
if (hash == 0) { |
1381 |
hash = nextHash++; |
|
375 | 1382 |
__SET_HASH(self, hash); |
1383 |
hash = __GET_HASH(self); |
|
216 | 1384 |
if (hash == 0) { |
1385 |
hash = nextHash++; |
|
375 | 1386 |
__SET_HASH(self, hash); |
1387 |
hash = __GET_HASH(self); |
|
216 | 1388 |
} |
159 | 1389 |
} |
1 | 1390 |
|
359 | 1391 |
/* |
370 | 1392 |
* now, we got 11 bits for hashing; |
359 | 1393 |
* make it as large as possible; since most hashers use the returned |
1394 |
* key and take it modulu some prime number, this will allow for |
|
1395 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
1396 |
* we could shift it up to the 30 bit limit - not making it negative. |
|
1397 |
*/ |
|
370 | 1398 |
RETURN ( _MKSMALLINT(hash << __HASH_SHIFT__) ); |
1 | 1399 |
} |
202 | 1400 |
%}. |
356 | 1401 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
1 | 1402 |
! ! |
1403 |
||
1404 |
!Object methodsFor:'interrupt handling'! |
|
1405 |
||
2 | 1406 |
internalError:msg |
1407 |
"this is triggered, when system hits some bad error, |
|
1408 |
such as corrupted class, corrupted method/selector array |
|
253 | 1409 |
etc. The argument string gives some more information on what happened. |
1410 |
(for example, if you set an objects class to a smallInteger, nil etc). |
|
159 | 1411 |
Its not guaranteed, that the system is in a working condition once |
1412 |
this error occurred ...." |
|
2 | 1413 |
|
85 | 1414 |
^ self error:msg |
2 | 1415 |
! |
1416 |
||
1 | 1417 |
userInterrupt |
1418 |
"user (^c) interrupt - enter debugger" |
|
1419 |
||
10 | 1420 |
UserInterruptSignal raise |
1 | 1421 |
! |
1422 |
||
1423 |
ioInterrupt |
|
10 | 1424 |
"I/O (SIGIO/SIGPOLL) interrupt and no handler - enter debugger" |
1425 |
||
1426 |
self error:'I/O Interrupt - but no handler' |
|
1 | 1427 |
! |
1428 |
||
2 | 1429 |
childSignalInterrupt |
1430 |
"death of a child process (unix process) - do nothing" |
|
1431 |
||
1432 |
^ self |
|
1433 |
! |
|
1434 |
||
1 | 1435 |
spyInterrupt |
1436 |
"spy interrupt and no handler - enter debugger" |
|
1437 |
||
10 | 1438 |
self error:'spy Interrupt - but no handler' |
1 | 1439 |
! |
1440 |
||
1441 |
timerInterrupt |
|
1442 |
"timer interrupt and no handler - enter debugger" |
|
1443 |
||
10 | 1444 |
self error:'timer Interrupt - but no handler' |
1 | 1445 |
! |
1446 |
||
375 | 1447 |
errorInterrupt:errorID with:aParameter |
1448 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
1449 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
|
1450 |
which can be called from C subsystems to raise an (asynchronous) |
|
1451 |
error exception. |
|
345 | 1452 |
|
1453 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
375 | 1454 |
used from other C subsystems too, to upcast errors. |
1455 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
345 | 1456 |
IDs (currently) used: |
1457 |
#DisplayError ..... x-error interrupt |
|
348 | 1458 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
345 | 1459 |
" |
1460 |
||
1461 |
|handler| |
|
1462 |
||
1463 |
handler := ObjectMemory registeredErrorInterruptHandlers at:errorID ifAbsent:nil. |
|
1464 |
handler notNil ifTrue:[ |
|
375 | 1465 |
"/ |
1466 |
"/ handler found; let it do whatever it wants ... |
|
1467 |
"/ |
|
1468 |
handler errorInterrupt:errorID with:aParameter. |
|
345 | 1469 |
^ self |
1470 |
]. |
|
1471 |
||
375 | 1472 |
"/ |
1473 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
1474 |
"/ |
|
345 | 1475 |
^ ErrorSignal |
1476 |
raiseRequestWith:errorID |
|
1477 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
1 | 1478 |
! |
1479 |
||
1480 |
memoryInterrupt |
|
1481 |
"out-of-memory interrupt and no handler - enter debugger" |
|
1482 |
||
345 | 1483 |
^ self error:'almost out of memory' |
1 | 1484 |
! |
1485 |
||
387 | 1486 |
customInterrupt |
1487 |
"a custom interrupt" |
|
1488 |
||
1489 |
^ self error:'custom interrupt' |
|
1490 |
! |
|
1491 |
||
1 | 1492 |
fpExceptionInterrupt |
1493 |
"a floating point exception occured - this one |
|
113 | 1494 |
has to be handled differently since it comes asynchronous |
213 | 1495 |
on some machines (for example, on machines with a separate FPU |
1496 |
or superscalar architectures. Also, errors from within primitive code |
|
113 | 1497 |
(or library functions such as GL) are sent via the Unix-signal |
1498 |
mechanism this way." |
|
1 | 1499 |
|
113 | 1500 |
^ Float domainErrorSignal raise |
1 | 1501 |
! |
1502 |
||
1503 |
signalInterrupt:signalNumber |
|
443 | 1504 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
1505 |
(SIGPIPE), others (SIGBUS) are rather fatal ... |
|
1506 |
In any case, if a smalltalk-signal has been connected to the OS signal, |
|
1507 |
that one is raised. |
|
1508 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
|
1509 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
1510 |
Currently (temporary kludge), these are passed as global variables." |
|
1511 |
||
1512 |
|box name here sig ignorable titles actions badContext msg pc addr| |
|
71 | 1513 |
|
143 | 1514 |
" |
1515 |
special case - since SIGPIPE has an ST-signal associated |
|
1516 |
" |
|
2 | 1517 |
(signalNumber == 13) ifTrue:[ |
159 | 1518 |
"SIGPIPE - write on a pipe with no one to read" |
1519 |
||
1520 |
^ PipeStream brokenPipeSignal raise. |
|
13 | 1521 |
]. |
71 | 1522 |
|
1523 |
"if there has been an ST-signal installed, use it ..." |
|
1524 |
||
113 | 1525 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
71 | 1526 |
sig notNil ifTrue:[ |
159 | 1527 |
^ sig raise |
71 | 1528 |
]. |
1529 |
||
1530 |
" |
|
1531 |
... otherwise , bring up a box asking for what to do ... |
|
1532 |
" |
|
56 | 1533 |
name := OperatingSystem nameForSignal:signalNumber. |
71 | 1534 |
here := thisContext. |
1535 |
||
1536 |
" |
|
1537 |
the context, in which the signal occurred: |
|
1538 |
" |
|
1539 |
badContext := here sender. |
|
1540 |
||
1541 |
" |
|
202 | 1542 |
ungrab - in case it happened in a box/popupview |
1543 |
otherwise display stays locked |
|
1544 |
" |
|
216 | 1545 |
Display notNil ifTrue:[ |
1546 |
Display ungrabPointer. |
|
1547 |
]. |
|
202 | 1548 |
|
1549 |
" |
|
71 | 1550 |
SIGBUS, SIGSEGV and SIGILL do not make sense to ignore (i.e. continue) |
1551 |
since the system will retry the faulty instruction, which leads to |
|
1552 |
another signal - to avoid frustration, better not offer this option. |
|
1553 |
" |
|
1554 |
ignorable := (signalNumber ~~ OperatingSystem sigBUS) |
|
159 | 1555 |
and:[signalNumber ~~ OperatingSystem sigILL |
1556 |
and:[signalNumber ~~ OperatingSystem sigSEGV]]. |
|
71 | 1557 |
|
110 | 1558 |
ignorable ifFalse:[ |
159 | 1559 |
here isRecursive ifTrue:[ |
1560 |
'fatal: signal ' errorPrint. signalNumber errorPrintNL. |
|
1561 |
MiniDebugger enterWithMessage:'recursive signal'. |
|
1562 |
^ self |
|
1563 |
]. |
|
1564 |
" |
|
1565 |
a hard signal - go into debugger immediately |
|
1566 |
" |
|
443 | 1567 |
msg := 'Signal ', name. |
1568 |
InterruptPcLow notNil ifTrue:[ |
|
1569 |
pc := InterruptPcLow + (InterruptPcHi bitShift:16). |
|
1570 |
pc ~~ 0 ifTrue:[ |
|
1571 |
msg := msg , ' PC=' , (pc printStringRadix:16) |
|
1572 |
]. |
|
1573 |
]. |
|
1574 |
InterruptAddrLow notNil ifTrue:[ |
|
1575 |
addr := InterruptAddrLow + (InterruptAddrHi bitShift:16). |
|
1576 |
addr ~~ 0 ifTrue:[ |
|
1577 |
msg := msg , ' ADDR=' , (addr printStringRadix:16) |
|
1578 |
]. |
|
1579 |
]. |
|
1580 |
Debugger enter:here withMessage:msg. |
|
159 | 1581 |
badContext return. |
1582 |
^ nil. |
|
110 | 1583 |
]. |
1584 |
||
93 | 1585 |
OptionBox isNil ifTrue:[ |
159 | 1586 |
" |
1587 |
a system without GUI ... |
|
1588 |
go into minidebugger (if there is one) |
|
1589 |
" |
|
1590 |
MiniDebugger isNil ifTrue:[ |
|
1591 |
" |
|
1592 |
a system without debugging facilities |
|
1593 |
(i.e. a standalone system) |
|
1594 |
output a message and exit. |
|
1595 |
" |
|
1596 |
('exit due to Signal ' , name) errorPrintNL. |
|
1597 |
Smalltalk exit. |
|
1598 |
]. |
|
1599 |
MiniDebugger enterWithMessage:'Signal cought (' , name, ')'. |
|
1600 |
^ self |
|
93 | 1601 |
]. |
1602 |
||
143 | 1603 |
box := OptionBox |
159 | 1604 |
title:'Signal cought (' , name, ')' |
1605 |
numberOfOptions:(ignorable ifTrue:[5] ifFalse:[4]). |
|
71 | 1606 |
|
1607 |
titles := #('return' 'debug' 'dump' 'exit'). |
|
1608 |
actions := Array |
|
159 | 1609 |
with:[badContext return] |
1610 |
with:[Debugger enter:here withMessage:('Signal ', name). ^nil] |
|
1611 |
with:[Smalltalk fatalAbort] |
|
1612 |
with:[Smalltalk exit]. |
|
71 | 1613 |
|
1614 |
ignorable ifTrue:[ |
|
159 | 1615 |
titles := #('ignore') , titles. |
1616 |
actions := (Array with:[^ nil]) , actions. |
|
1 | 1617 |
]. |
71 | 1618 |
box buttonTitles:titles. |
1619 |
box actions:actions. |
|
1620 |
box showAtPointer |
|
1 | 1621 |
! |
1622 |
||
1623 |
recursionInterrupt |
|
255 | 1624 |
"recursion limit (actually: stack overflow) interrupt. |
71 | 1625 |
This interrupt is triggered, when a process stack grows above |
1626 |
its stackLimit - usually, this leads into the debugger, but |
|
213 | 1627 |
could be cought and the stackLimit increased in the handler. |
1628 |
At the time we arrive here, the system has still some stack |
|
1629 |
as a reserve so we can continue to do some useful work or cleanup or |
|
1630 |
debugging for a while. |
|
1631 |
If the signal is ignored, and the stack continues to grow, there |
|
1632 |
will be a few more chances (and more interrupts) before the VM |
|
1633 |
hard-terminates the process." |
|
1 | 1634 |
|
33 | 1635 |
thisContext isRecursive ifFalse:[ |
159 | 1636 |
^ RecursionInterruptSignal raise |
33 | 1637 |
] |
1 | 1638 |
! |
1639 |
||
1640 |
exceptionInterrupt |
|
1641 |
"exception interrupt - enter debugger" |
|
1642 |
||
1643 |
self error:'exception Interrupt' |
|
1644 |
! ! |
|
1645 |
||
1646 |
!Object methodsFor:'error handling'! |
|
1647 |
||
2 | 1648 |
subscriptBoundsError |
143 | 1649 |
"report error that some index is out of bounds. |
1650 |
(when accessing indexable collections)" |
|
1 | 1651 |
|
255 | 1652 |
^ SubscriptOutOfBoundsSignal raiseIn:thisContext sender |
2 | 1653 |
! |
1654 |
||
159 | 1655 |
subscriptBoundsError:anIndex |
1656 |
"report error that anIndex is out of bounds. |
|
1657 |
(when accessing indexable collections)" |
|
1658 |
||
255 | 1659 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:anIndex in:thisContext sender |
159 | 1660 |
! |
1661 |
||
1 | 1662 |
indexNotInteger |
143 | 1663 |
"report error that index is not an Integer. |
1664 |
(when accessing collections indexed by an integer key)" |
|
1 | 1665 |
|
255 | 1666 |
^ NonIntegerIndexSignal raiseIn:thisContext sender |
2 | 1667 |
! |
1668 |
||
1669 |
errorNotFound |
|
345 | 1670 |
"report error that no element was found in a collection" |
2 | 1671 |
|
255 | 1672 |
^ NotFoundSignal raiseIn:thisContext sender |
2 | 1673 |
! |
1674 |
||
345 | 1675 |
errorKeyNotFound:aKey |
2 | 1676 |
"report error that a key was not found in a collection" |
1677 |
||
345 | 1678 |
^ KeyNotFoundSignal raiseRequestWith:aKey in:thisContext sender |
1 | 1679 |
! |
1680 |
||
10 | 1681 |
elementBoundsError |
143 | 1682 |
"report error that badElement is out of bounds |
1683 |
(i.e. cannot be put into that collection)" |
|
1 | 1684 |
|
255 | 1685 |
^ ElementOutOfBoundsSignal raiseIn:thisContext sender |
10 | 1686 |
! |
1687 |
||
1688 |
elementNotInteger |
|
143 | 1689 |
"report error that object to be stored is not Integer. |
1690 |
(in collections that store integers only)" |
|
10 | 1691 |
|
255 | 1692 |
^ ElementOutOfBoundsSignal raiseIn:thisContext sender |
1 | 1693 |
! |
1694 |
||
1695 |
elementNotCharacter |
|
143 | 1696 |
"report error that object to be stored is no Character. |
1697 |
(usually when storing into Strings)" |
|
1 | 1698 |
|
255 | 1699 |
^ ElementOutOfBoundsSignal raiseIn:thisContext sender |
1 | 1700 |
! |
1701 |
||
1702 |
mustBeRectangle |
|
1703 |
"report an argument-not-rectangle-error" |
|
1704 |
||
1705 |
^ self error:'argument must be a Rectangle' |
|
1706 |
! |
|
1707 |
||
1708 |
mustBeString |
|
1709 |
"report an argument-not-string-error" |
|
1710 |
||
1711 |
^ self error:'argument must be a String' |
|
1712 |
! |
|
1713 |
||
1714 |
notIndexed |
|
1715 |
"report error that receiver has no indexed instance variables" |
|
1716 |
||
1717 |
^ self error:'receiver has no indexed variables' |
|
1718 |
! |
|
1719 |
||
2 | 1720 |
integerCheckError |
1721 |
"generated when a variable declared with an integer type gets a bad |
|
1722 |
value assigned" |
|
1723 |
||
1724 |
^ self error:'bad assign of ' , self printString , |
|
159 | 1725 |
' (' , self class name , ') to integer-typed variable' |
2 | 1726 |
! |
1727 |
||
1 | 1728 |
typeCheckError |
1729 |
"generated when a variable declared with a type hint gets a bad |
|
1730 |
value assigned" |
|
1731 |
||
2 | 1732 |
^ self error:'bad assign of ' , self printString , |
159 | 1733 |
' (' , self class name , ') to typed variable' |
1 | 1734 |
! |
1735 |
||
1736 |
primitiveFailed |
|
1737 |
"report error that primitive code failed" |
|
1738 |
||
255 | 1739 |
^ PrimitiveFailureSignal raiseIn:(thisContext sender) |
71 | 1740 |
! |
1741 |
||
1742 |
implementedBySubclass |
|
1743 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
1744 |
||
1745 |
^ self subclassResponsibility |
|
1746 |
! |
|
1747 |
||
1748 |
invalidMessage |
|
1749 |
"this is sent by ST/V code - its the same as #shouldNotImplement" |
|
1750 |
||
1751 |
^ self shouldNotImplement |
|
1 | 1752 |
! |
1753 |
||
1754 |
subclassResponsibility |
|
1755 |
"report error that this message should have been reimplemented in a |
|
1756 |
subclass" |
|
1757 |
||
1758 |
^ self error:'method must be reimplemented in subclass' |
|
1759 |
! |
|
1760 |
||
1761 |
shouldNotImplement |
|
1762 |
"report error that this message should not be implemented" |
|
1763 |
||
1764 |
^ self error:'method not appropriate for this class' |
|
1765 |
! |
|
1766 |
||
1767 |
halt |
|
1768 |
"enter debugger with halt-message" |
|
1769 |
||
255 | 1770 |
^ HaltSignal raiseIn:thisContext sender. |
27 | 1771 |
! |
1772 |
||
1773 |
halt:aString |
|
1774 |
"enter debugger with halt-message" |
|
1775 |
||
255 | 1776 |
^ HaltSignal raiseRequestWith:#halt: |
1777 |
errorString:aString |
|
1778 |
in:thisContext sender |
|
1 | 1779 |
! |
1780 |
||
71 | 1781 |
error |
1782 |
"report error that an error occured" |
|
1783 |
||
255 | 1784 |
^ ErrorSignal raiseIn:thisContext sender |
71 | 1785 |
! |
1786 |
||
1787 |
error:aString |
|
1788 |
"enter debugger with error-message aString" |
|
1789 |
||
255 | 1790 |
^ ErrorSignal raiseRequestWith:#error: |
1791 |
errorString:aString |
|
1792 |
in:thisContext sender |
|
2 | 1793 |
! |
1794 |
||
71 | 1795 |
doesNotUnderstand:aMessage |
143 | 1796 |
"this message is sent by the runtime system (VM) when |
1797 |
a message is not understood by some object (i.e. there |
|
1798 |
is no method for that selector). The original message has |
|
1799 |
been packed into aMessage (i.e. the receiver, selector and |
|
1800 |
any arguments) and the original receiver is then sent the |
|
1801 |
#doesNotUnderstand: message. |
|
1802 |
Here, we raise another signal which usually enters the debugger. |
|
1803 |
You can of course redefine #doesNotUnderstand: in your classes |
|
1804 |
to implement message delegation." |
|
1805 |
||
359 | 1806 |
|sel errorString cls sender| |
1807 |
||
1808 |
(sel := aMessage selector) isNil ifTrue:[ |
|
159 | 1809 |
"happens when things go mad, or a method has been |
1810 |
called by valueWithReceiver: with a wrong receiver" |
|
1811 |
||
1812 |
sel := '(nil)' |
|
71 | 1813 |
]. |
403 | 1814 |
"/ Smalltalk isInitialized ifFalse:[ |
421 | 1815 |
"/ sel printNL |
403 | 1816 |
"/ ]. |
202 | 1817 |
|
1818 |
"the new errorString gives more information ..." |
|
1819 |
"/ errorString := 'Message not understood: ' , sel. |
|
359 | 1820 |
sender := thisContext sender. |
1821 |
cls := sender searchClass. |
|
324 | 1822 |
cls isNil ifTrue:[ |
1823 |
"it was NOT a super or directed send ..." |
|
1824 |
cls := self class |
|
314 | 1825 |
]. |
324 | 1826 |
errorString := cls name , ' does not understand: ' , sel. |
143 | 1827 |
|
1828 |
" |
|
1829 |
this only happens, when YOU play around with my classvars ... |
|
1830 |
" |
|
85 | 1831 |
MessageNotUnderstoodSignal isNil ifTrue:[ |
159 | 1832 |
^ self enterDebuggerWith:nil |
1833 |
message:'oops - MessageNotUnderstoodSignal is gone'. |
|
85 | 1834 |
]. |
113 | 1835 |
^ MessageNotUnderstoodSignal |
159 | 1836 |
raiseRequestWith:aMessage |
1837 |
errorString:errorString |
|
359 | 1838 |
in:sender |
1 | 1839 |
! |
1840 |
||
255 | 1841 |
appropriateDebugger:aSelector |
159 | 1842 |
"return an appropriate debugger to use. |
1843 |
If there is already a debugger active on the stack, and it is |
|
1844 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
85 | 1845 |
|
1846 |
|context| |
|
1847 |
||
1848 |
context := thisContext. |
|
1849 |
context := context sender. |
|
1850 |
[context notNil] whileTrue:[ |
|
159 | 1851 |
((context receiver class == Debugger) |
255 | 1852 |
and:[context selector == aSelector]) ifTrue:[ |
159 | 1853 |
"we are already in some Debugger" |
1854 |
(Debugger == MiniDebugger) ifTrue:[ |
|
1855 |
"we are already in the MiniDebugger" |
|
1856 |
ErrorRecursion ifFalse:[ |
|
1857 |
Smalltalk fatalAbort:'recursive error ...' |
|
1858 |
] |
|
1859 |
]. |
|
1860 |
MiniDebugger isNil ifTrue:[ |
|
1861 |
Smalltalk fatalAbort:'no debugger' |
|
1862 |
]. |
|
1863 |
||
1864 |
"ok, an error occured while in the graphical debugger; |
|
1865 |
lets try MiniDebugger" |
|
1866 |
^ MiniDebugger |
|
1867 |
]. |
|
1868 |
context := context sender |
|
1 | 1869 |
]. |
159 | 1870 |
"not within Debugger - no problem" |
1 | 1871 |
^ Debugger |
1872 |
! |
|
1873 |
||
143 | 1874 |
enterDebuggerWith:anException message:aString |
255 | 1875 |
"enter the debugger with error-message aString" |
1876 |
||
1877 |
^ self enterDebuggerWith:anException |
|
1878 |
message:aString |
|
1879 |
on:anException suspendedContext |
|
1880 |
! |
|
1881 |
||
1882 |
enterDebuggerWith:anException message:aString on:aContext |
|
1883 |
"enter the debugger with error-message aString. |
|
1884 |
The first visible context shown there is aContext |
|
1885 |
(this allows intermediate helpers to hide themselfes from what is |
|
1886 |
presented to the user)" |
|
13 | 1887 |
|
143 | 1888 |
|debugger| |
1889 |
||
1890 |
" |
|
1891 |
if there is no debugger, exit smalltalk |
|
1892 |
" |
|
13 | 1893 |
Debugger isNil ifTrue:[ |
159 | 1894 |
'error: ' errorPrint. aString errorPrintNL. |
1895 |
Smalltalk fatalAbort:'no Debugger defined' |
|
13 | 1896 |
]. |
143 | 1897 |
" |
1898 |
find an appropriate debugger to use |
|
1899 |
" |
|
255 | 1900 |
debugger := self appropriateDebugger:#'enter:withMessage:'. |
1901 |
^ debugger enter:aContext withMessage:aString. |
|
1 | 1902 |
! ! |
1903 |
||
1904 |
!Object methodsFor:'debugging'! |
|
1905 |
||
342 | 1906 |
obsoleteMethodWarning:message from:aContext |
260 | 1907 |
"in methods which are going to be obsoleted, a self send to |
1908 |
this method is used to tell programmers that a method is |
|
1909 |
used which is going to be removed in later ST/X versions. |
|
1910 |
Find all methods which will be obsolete soon by looking at senders |
|
1911 |
of this." |
|
1912 |
||
1913 |
|m spec w| |
|
1914 |
||
342 | 1915 |
m := aContext method. |
260 | 1916 |
spec := m displayString. |
1917 |
m notNil ifTrue:[ |
|
1918 |
w := m who. |
|
1919 |
w notNil ifTrue:[ |
|
1920 |
spec := (w at:1) name , '>>' , (w at:2) |
|
1921 |
] |
|
1922 |
]. |
|
340 | 1923 |
('WARNING: the ''' , spec , ''' method is obsolete.') errorPrintNL. |
1924 |
(' And may not be present in future ST/X versions.') errorPrintNL. |
|
342 | 1925 |
(' called from ' , aContext sender printString) errorPrintNL. |
340 | 1926 |
message notNil ifTrue:[ |
1927 |
'------> ' errorPrint. message errorPrintNL |
|
1928 |
] |
|
1929 |
! |
|
1930 |
||
342 | 1931 |
obsoleteMethodWarning:message |
1932 |
"in methods which are going to be obsoleted, a self send to |
|
1933 |
this method is used to tell programmers that a method is |
|
1934 |
used which is going to be removed in later ST/X versions. |
|
1935 |
Find all methods which will be obsolete soon by looking at senders |
|
1936 |
of this." |
|
1937 |
||
1938 |
self obsoleteMethodWarning:message from:thisContext sender |
|
1939 |
! |
|
1940 |
||
340 | 1941 |
obsoleteMethodWarning |
1942 |
"in methods which are going to be obsoleted, a self send to |
|
1943 |
this method is used to tell programmers that a method is |
|
1944 |
used which is going to be removed in later ST/X versions. |
|
1945 |
Find all methods which will be obsolete soon by looking at senders |
|
1946 |
of this." |
|
1947 |
||
342 | 1948 |
self obsoleteMethodWarning:nil from:thisContext sender |
260 | 1949 |
! |
1950 |
||
325 | 1951 |
mustBeKindOf:aClass |
1952 |
"for compatibility & debugging support: |
|
1953 |
check if the receiver isKindOf:aClass and raise an error if not. |
|
1954 |
Notice: |
|
1955 |
it is VERY questionable, if it makes sense to add manual |
|
1956 |
type checks to a dynamically typed language like smalltalk. |
|
1957 |
It will, at least, slow down performance, |
|
1958 |
make your code less reusable and clutter your code with stupid sends |
|
1959 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
1960 |
use of isXXX check methods. |
|
1961 |
You see: The author does not like this at all ..." |
|
1962 |
||
1963 |
(self isKindOf:aClass) ifFalse:[ |
|
1964 |
self error:'argument is not of expected type' |
|
1965 |
] |
|
1966 |
! |
|
1967 |
||
397 | 1968 |
errorNotify:aString |
1969 |
"launch a Notifier, showing top stack, telling user something |
|
362 | 1970 |
and give a chance to enter debugger." |
1971 |
||
369 | 1972 |
|info con sender| |
362 | 1973 |
|
1974 |
Dialog isNil ifTrue:[ |
|
1975 |
" |
|
1976 |
on systems without GUI, simply show |
|
1977 |
the message on the Transcript. |
|
1978 |
" |
|
1979 |
Transcript showCr:aString. |
|
1980 |
^ self |
|
1981 |
]. |
|
1982 |
Dialog autoload. "in case its autoloaded" |
|
1983 |
||
369 | 1984 |
con := sender := thisContext sender. |
362 | 1985 |
info := aString , Character cr asString , Character cr asString. |
1986 |
1 to:5 do:[:n | |
|
1987 |
con notNil ifTrue:[ |
|
1988 |
info := info , con printString , Character cr asString. |
|
1989 |
con := con sender |
|
1990 |
] |
|
1991 |
]. |
|
1992 |
||
1993 |
(Dialog choose:info |
|
1994 |
labels:#('proceed' 'debug') |
|
1995 |
values:#(#proceed #debug) |
|
1996 |
default:#debug) == #debug |
|
1997 |
ifTrue:[ |
|
369 | 1998 |
Debugger enter:sender withMessage:aString |
362 | 1999 |
] |
2000 |
||
2001 |
" |
|
397 | 2002 |
nil errorNotify:'hello there' |
2003 |
self errorNotify:'hello there' |
|
2004 |
" |
|
2005 |
! |
|
2006 |
||
2007 |
notify:aString |
|
2008 |
"launch a Notifier, telling user something" |
|
2009 |
||
2010 |
Dialog isNil ifTrue:[ |
|
2011 |
" |
|
2012 |
on systems without GUI, simply show |
|
2013 |
the message on the Transcript. |
|
2014 |
" |
|
2015 |
Transcript showCr:aString. |
|
2016 |
^ self |
|
2017 |
]. |
|
2018 |
Dialog autoload. "in case its autoloaded" |
|
2019 |
Dialog information:aString |
|
2020 |
||
2021 |
" |
|
362 | 2022 |
nil notify:'hello there' |
2023 |
self notify:'hello there' |
|
2024 |
" |
|
2025 |
! |
|
2026 |
||
2027 |
information:aString |
|
2028 |
"launch an InfoBox, telling user something" |
|
1 | 2029 |
|
298 | 2030 |
Dialog isNil ifTrue:[ |
159 | 2031 |
" |
2032 |
on systems without GUI, simply show |
|
2033 |
the message on the Transcript. |
|
2034 |
" |
|
2035 |
Transcript showCr:aString. |
|
2036 |
^ self |
|
1 | 2037 |
]. |
298 | 2038 |
Dialog autoload. "in case its autoloaded" |
2039 |
Dialog information:aString |
|
71 | 2040 |
|
143 | 2041 |
" |
2042 |
nil information:'hello there' |
|
2043 |
self information:'hello there' |
|
2044 |
" |
|
1 | 2045 |
! |
2046 |
||
2047 |
warn:aString |
|
2048 |
"launch a WarningBox, telling user something" |
|
2049 |
||
298 | 2050 |
Dialog isNil ifTrue:[ |
159 | 2051 |
" |
2052 |
on systems without GUI, simply show |
|
2053 |
the message on the Transcript. |
|
2054 |
" |
|
2055 |
Transcript showCr:aString. |
|
2056 |
^ self |
|
1 | 2057 |
]. |
298 | 2058 |
Dialog autoload. "in case its autoloaded" |
2059 |
Dialog warn:aString |
|
71 | 2060 |
|
143 | 2061 |
" |
2062 |
nil warn:'hello there' |
|
2063 |
self warn:'hello there' |
|
2064 |
" |
|
1 | 2065 |
! |
2066 |
||
2067 |
confirm:aString |
|
2068 |
"launch a confirmer, which allows user to enter yes or no. |
|
2069 |
return true for yes, false for no" |
|
2070 |
||
298 | 2071 |
Dialog isNil ifTrue:[ |
159 | 2072 |
" |
2073 |
on systems without GUI, output a message |
|
2074 |
and return true (as if yes was answered) |
|
2075 |
Q: should we ask user by reading Stdin ? |
|
2076 |
" |
|
2077 |
Transcript showCr:aString. |
|
202 | 2078 |
Transcript showCr:'continue, assuming <yes>'. |
159 | 2079 |
^ true |
1 | 2080 |
]. |
298 | 2081 |
Dialog autoload. "in case its autoloaded" |
2082 |
^ Dialog confirm:aString |
|
93 | 2083 |
|
143 | 2084 |
" |
2085 |
nil confirm:'hello' |
|
2086 |
self confirm:'hello' |
|
2087 |
" |
|
1 | 2088 |
! |
2089 |
||
2090 |
basicInspect |
|
2091 |
"launch an inspector on the receiver. |
|
2092 |
this method should NOT be redefined in subclasses." |
|
2093 |
||
2094 |
Inspector isNil ifTrue:[ |
|
159 | 2095 |
" |
2096 |
for systems without GUI |
|
2097 |
" |
|
2098 |
Transcript showCr:'no Inspector' |
|
1 | 2099 |
] ifFalse:[ |
159 | 2100 |
Inspector openOn:self |
1 | 2101 |
] |
2102 |
! |
|
2103 |
||
2104 |
inspect |
|
2105 |
"launch an inspector on the receiver. |
|
282 | 2106 |
this method (or better: inspectorClass) can be redefined in subclasses |
2107 |
to start special inspectors." |
|
2108 |
||
2109 |
|cls| |
|
2110 |
||
2111 |
cls := self inspectorClass. |
|
2112 |
cls isNil ifTrue:[ |
|
2113 |
^ self basicInspect |
|
2114 |
]. |
|
2115 |
cls openOn:self |
|
2116 |
||
2117 |
" |
|
2118 |
Object new inspect |
|
2119 |
(1 @ 2) inspect |
|
2120 |
Smalltalk inspect |
|
2121 |
#(1 2 3) asOrderedCollection inspect |
|
2122 |
(Color red) inspect |
|
2123 |
(Image fromFile:'bitmaps/garfield.gif') inspect |
|
2124 |
" |
|
2125 |
! |
|
2126 |
||
2127 |
inspectorClass |
|
2128 |
"return the class to use for inspect. |
|
2129 |
Can (should) be redefined in classes for which a better inspector is available" |
|
2130 |
||
2131 |
^ Inspector |
|
1 | 2132 |
! ! |
2133 |
||
324 | 2134 |
!Object methodsFor:'converting'! |
2135 |
||
2136 |
asValue |
|
2137 |
"return a valueHolder for for the receiver" |
|
2138 |
||
2139 |
^ ValueHolder with:self |
|
2140 |
! ! |
|
2141 |
||
1 | 2142 |
!Object methodsFor:'accessing'! |
2143 |
||
2144 |
at:index |
|
2145 |
"return the indexed instance variable with index, anInteger; |
|
2146 |
this method can be redefined in subclasses." |
|
2147 |
||
2148 |
^ self basicAt:index |
|
2149 |
! |
|
2150 |
||
2151 |
basicAt:index |
|
2152 |
"return the indexed instance variable with index, anInteger. |
|
2153 |
Trigger an error if the receiver has no indexed instance variables. |
|
2154 |
This method should NOT be redefined in any subclass" |
|
2155 |
||
2156 |
%{ /* NOCONTEXT */ |
|
2157 |
||
329 | 2158 |
REGISTER int nbytes, indx; |
1 | 2159 |
OBJ myClass; |
329 | 2160 |
REGISTER char *pFirst; |
1 | 2161 |
unsigned char *cp; |
2162 |
unsigned short *sp; |
|
2163 |
long *lp; |
|
2164 |
OBJ *op; |
|
329 | 2165 |
/* int nInstBytes, nInstVars, flags; */ |
2166 |
REGISTER int n; |
|
228 | 2167 |
extern OBJ _MKLARGEINT(); |
1 | 2168 |
|
2169 |
||
2170 |
/* |
|
56 | 2171 |
* notice the missing test for self being a nonNilObject - |
1 | 2172 |
* this can be done since basicAt: is defined both in UndefinedObject |
2173 |
* and SmallInteger |
|
2174 |
*/ |
|
253 | 2175 |
if (__isSmallInteger(index)) { |
329 | 2176 |
myClass = __qClass(self); |
159 | 2177 |
indx = _intVal(index) - 1; |
329 | 2178 |
n /* nInstVars */ = _intVal(_ClassInstPtr(myClass)->c_ninstvars); |
2179 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
2180 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
2181 |
pFirst = (char *)(_InstPtr(self)) + n /* nInstBytes */; |
|
2182 |
||
2183 |
/* |
|
2184 |
* replaced switch by open-coded if; this is slightly faster |
|
2185 |
* since it avoids the range check and also handles the most common case first |
|
2186 |
*/ |
|
2187 |
n = _intVal(_ClassInstPtr(myClass)->c_flags) & ARRAYMASK; |
|
2188 |
if ((n == POINTERARRAY) || (n == WKPOINTERARRAY)) { |
|
2189 |
if ((indx >= 0) && (indx < (__BYTES2OBJS__(nbytes)))) { |
|
2190 |
op = (OBJ *)pFirst + indx; |
|
2191 |
RETURN ( *op ); |
|
2192 |
} |
|
2193 |
} else if (n == BYTEARRAY) { |
|
2194 |
if ((indx >= 0) && (indx < (nbytes / sizeof(char)))) { |
|
2195 |
cp = (unsigned char *)pFirst + indx; |
|
2196 |
RETURN ( _MKSMALLINT(*cp & 0xFF) ); |
|
2197 |
} |
|
2198 |
} else if (n == FLOATARRAY) { |
|
2199 |
if ((indx >= 0) && (indx < (nbytes / sizeof(float)))) { |
|
2200 |
float *fp; |
|
2201 |
||
2202 |
fp = (float *)pFirst + indx; |
|
2203 |
RETURN ( _MKFLOAT((double)(*fp)) COMMA_CON ); |
|
2204 |
} |
|
2205 |
} else if (n == DOUBLEARRAY) { |
|
2206 |
if ((indx >= 0) && (indx < (nbytes / sizeof(double)))) { |
|
2207 |
double *dp; |
|
1 | 2208 |
|
56 | 2209 |
#ifdef NEED_DOUBLE_ALIGN |
329 | 2210 |
/* |
2211 |
* care for filler |
|
2212 |
*/ |
|
2213 |
pFirst += sizeof(FILLTYPE); |
|
56 | 2214 |
#endif |
329 | 2215 |
dp = (double *)pFirst + indx; |
2216 |
RETURN ( _MKFLOAT(*dp) COMMA_CON ); |
|
2217 |
} |
|
2218 |
} else if (n == LONGARRAY) { |
|
2219 |
if ((indx >= 0) && (indx < (nbytes / sizeof(long)))) { |
|
2220 |
lp = (long *)pFirst + indx; |
|
2221 |
if ((*lp >= _MIN_INT) && (*lp <= _MAX_INT)) |
|
2222 |
RETURN ( _MKSMALLINT(*lp) ); |
|
2223 |
RETURN ( _MKLARGEINT(*lp) ); |
|
2224 |
} |
|
2225 |
} else if (n == WORDARRAY) { |
|
2226 |
if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) { |
|
2227 |
sp = (unsigned short *)pFirst + indx; |
|
2228 |
RETURN ( _MKSMALLINT(*sp & 0xFFFF) ); |
|
2229 |
} |
|
159 | 2230 |
} |
1 | 2231 |
} |
2232 |
%} |
|
2233 |
. |
|
10 | 2234 |
index isInteger ifFalse:[ |
159 | 2235 |
^ self indexNotInteger |
1 | 2236 |
]. |
159 | 2237 |
^ self subscriptBoundsError:index |
1 | 2238 |
! |
2239 |
||
2240 |
at:index put:anObject |
|
2241 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
2242 |
this method can be redefined in subclasses." |
|
2243 |
||
2244 |
^ self basicAt:index put:anObject |
|
2245 |
! |
|
2246 |
||
2247 |
basicAt:index put:anObject |
|
2248 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
2249 |
Trigger an error if the receiver has no indexed instance variables. |
|
2250 |
This method should NOT be redefined in any subclass" |
|
2251 |
||
2252 |
%{ /* NOCONTEXT */ |
|
2253 |
||
2254 |
register int nbytes, indx; |
|
2255 |
OBJ myClass; |
|
2256 |
register char *pFirst; |
|
2257 |
char *cp; |
|
2258 |
short *sp; |
|
2259 |
long *lp; |
|
2260 |
OBJ *op; |
|
329 | 2261 |
/* int nInstBytes, ninstvars, flags; */ |
2262 |
REGISTER int n; |
|
1 | 2263 |
int val; |
2264 |
||
56 | 2265 |
/* notice the missing test for self being a nonNilObject - |
77 | 2266 |
this can be done since basicAt: is defined both in UndefinedObject |
1 | 2267 |
and SmallInteger */ |
2268 |
||
253 | 2269 |
if (__isSmallInteger(index)) { |
159 | 2270 |
indx = _intVal(index) - 1; |
329 | 2271 |
myClass = __qClass(self); |
2272 |
n /* ninstvars */ = _intVal(_ClassInstPtr(myClass)->c_ninstvars); |
|
2273 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
2274 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
2275 |
pFirst = (char *)(_InstPtr(self)) + n /* nInstBytes */; |
|
2276 |
||
2277 |
n = _intVal(_ClassInstPtr(myClass)->c_flags) & ARRAYMASK; |
|
2278 |
if ((n == POINTERARRAY) || (n == WKPOINTERARRAY)) { |
|
2279 |
if ((indx >= 0) && (indx < (__BYTES2OBJS__(nbytes)))) { |
|
2280 |
op = (OBJ *)pFirst + indx; |
|
2281 |
*op = anObject; |
|
2282 |
__STORE(self, anObject); |
|
2283 |
RETURN ( anObject ); |
|
2284 |
} |
|
2285 |
} else if (n == BYTEARRAY) { |
|
2286 |
if (__isSmallInteger(anObject)) { |
|
2287 |
val = _intVal(anObject); |
|
2288 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
2289 |
if ((indx >= 0) && (indx < (nbytes / sizeof(char)))) { |
|
2290 |
cp = pFirst + indx; |
|
2291 |
*cp = val; |
|
159 | 2292 |
RETURN ( anObject ); |
2293 |
} |
|
2294 |
} |
|
329 | 2295 |
} |
2296 |
} else if (n == FLOATARRAY) { |
|
2297 |
if ((indx >= 0) && (indx < (nbytes / sizeof(float)))) { |
|
2298 |
float *fp; |
|
2299 |
||
2300 |
fp = (float *)pFirst + indx; |
|
2301 |
if (__isFloatLike(anObject)) { |
|
2302 |
*fp = _floatVal(anObject); |
|
2303 |
RETURN ( anObject ); |
|
159 | 2304 |
} |
329 | 2305 |
if (__isSmallInteger(anObject)) { |
2306 |
*fp = (float) _intVal(anObject); |
|
2307 |
RETURN ( anObject ); |
|
2308 |
} |
|
2309 |
} |
|
2310 |
} else if (n == DOUBLEARRAY) { |
|
2311 |
if ((indx >= 0) && (indx < (nbytes / sizeof(double)))) { |
|
2312 |
double *dp; |
|
13 | 2313 |
|
56 | 2314 |
#ifdef NEED_DOUBLE_ALIGN |
329 | 2315 |
/* |
2316 |
* care for filler |
|
2317 |
*/ |
|
2318 |
pFirst += sizeof(FILLTYPE); |
|
56 | 2319 |
#endif |
329 | 2320 |
dp = (double *)pFirst + indx; |
2321 |
if (__isFloatLike(anObject)) { |
|
2322 |
*dp = _floatVal(anObject); |
|
2323 |
RETURN ( anObject ); |
|
2324 |
} |
|
2325 |
if (__isSmallInteger(anObject)) { |
|
2326 |
*dp = (double) _intVal(anObject); |
|
2327 |
RETURN ( anObject ); |
|
2328 |
} |
|
2329 |
} |
|
2330 |
} else if (n == LONGARRAY) { |
|
2331 |
if (__isSmallInteger(anObject)) { |
|
2332 |
if ((indx >= 0) && (indx < (nbytes / sizeof(long)))) { |
|
2333 |
lp = (long *)pFirst + indx; |
|
2334 |
*lp = _intVal(anObject); |
|
2335 |
RETURN ( anObject ); |
|
2336 |
} |
|
2337 |
} |
|
2338 |
/* XXX |
|
2339 |
* XXX must add possibility to put in a large number here |
|
2340 |
* XXX |
|
2341 |
*/ |
|
2342 |
} else if (n == WORDARRAY) { |
|
2343 |
if (__isSmallInteger(anObject)) { |
|
2344 |
val = _intVal(anObject); |
|
2345 |
if ((val >= 0) && (val <= 0xFFFF)) { |
|
2346 |
if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) { |
|
339 | 2347 |
sp = (short *)pFirst + indx; |
2348 |
*sp = val; |
|
2349 |
RETURN ( anObject ); |
|
159 | 2350 |
} |
2351 |
} |
|
329 | 2352 |
} |
159 | 2353 |
} |
1 | 2354 |
} |
2355 |
%} |
|
2356 |
. |
|
10 | 2357 |
index isInteger ifFalse:[ |
159 | 2358 |
" |
2359 |
the index should be an integer number |
|
2360 |
" |
|
2361 |
^ self indexNotInteger |
|
1 | 2362 |
]. |
2363 |
(index between:1 and:self size) ifFalse:[ |
|
159 | 2364 |
" |
2365 |
the index is less than 1 or greater than the size of the |
|
213 | 2366 |
receiver collection |
159 | 2367 |
" |
2368 |
^ self subscriptBoundsError:index |
|
1 | 2369 |
]. |
13 | 2370 |
(self class isFloats) ifTrue:[ |
159 | 2371 |
anObject isNumber ifTrue:[ |
2372 |
^ self basicAt:index put:(anObject asFloat) |
|
2373 |
] |
|
13 | 2374 |
]. |
2375 |
(self class isDoubles) ifTrue:[ |
|
159 | 2376 |
anObject isNumber ifTrue:[ |
2377 |
^ self basicAt:index put:(anObject asFloat) |
|
2378 |
] |
|
13 | 2379 |
]. |
10 | 2380 |
anObject isInteger ifFalse:[ |
159 | 2381 |
" |
213 | 2382 |
the object to put into the receiver collection |
159 | 2383 |
should be an integer number |
2384 |
" |
|
2385 |
^ self elementNotInteger |
|
2 | 2386 |
]. |
159 | 2387 |
" |
213 | 2388 |
the object to put into the receiver collection |
362 | 2389 |
is not an instance of the expected element class, |
2390 |
or the value is not within the elements valid range. |
|
159 | 2391 |
" |
2 | 2392 |
^ self elementBoundsError |
1 | 2393 |
! |
2394 |
||
2395 |
instVarAt:index |
|
2396 |
"return a non-indexed instance variable; |
|
13 | 2397 |
peeking into an object this way is not very object oriented |
2398 |
- use with care (needed for copy, inspector etc.)" |
|
1 | 2399 |
|
2400 |
%{ /* NOCONTEXT */ |
|
2401 |
||
2402 |
OBJ myClass; |
|
2403 |
int idx, ninstvars; |
|
2404 |
||
253 | 2405 |
if (__isSmallInteger(index)) { |
329 | 2406 |
myClass = __Class(self); |
357 | 2407 |
idx = _intVal(index) - 1; |
2408 |
/* |
|
2409 |
* do not allow return of non-object fields. |
|
2410 |
* if subclass did not make privisions for that, |
|
2411 |
* we wont do so here ... |
|
2412 |
*/ |
|
2413 |
if (((INT)(_ClassInstPtr(myClass)->c_flags) & _MASKSMALLINT(NONOBJECT_INSTS))) { |
|
2414 |
if (idx == 0) { |
|
2415 |
RETURN ( nil ) |
|
2416 |
} |
|
2417 |
} |
|
159 | 2418 |
ninstvars = _intVal(_ClassInstPtr(myClass)->c_ninstvars); |
2419 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
2420 |
RETURN ( _InstPtr(self)->i_instvars[idx] ); |
|
2421 |
} |
|
1 | 2422 |
} |
2423 |
%} |
|
2424 |
. |
|
2425 |
index isInteger ifFalse:[ |
|
159 | 2426 |
^ self indexNotInteger |
1 | 2427 |
]. |
159 | 2428 |
^ self subscriptBoundsError:index |
1 | 2429 |
! |
2430 |
||
2431 |
instVarAt:index put:value |
|
2432 |
"change a non-indexed instance variable; |
|
13 | 2433 |
peeking into an object this way is not very object oriented |
2434 |
- use with care (needed for copy, inspector etc.)" |
|
1 | 2435 |
|
2436 |
%{ /* NOCONTEXT */ |
|
2437 |
||
2438 |
OBJ myClass; |
|
2439 |
int idx, ninstvars; |
|
2440 |
||
253 | 2441 |
if (__isSmallInteger(index)) { |
329 | 2442 |
myClass = __Class(self); |
357 | 2443 |
idx = _intVal(index) - 1; |
159 | 2444 |
ninstvars = _intVal(_ClassInstPtr(myClass)->c_ninstvars); |
357 | 2445 |
/* |
2446 |
* do not allow setting of non-object fields. |
|
2447 |
* if subclass did not make privisions for that, |
|
2448 |
* we wont do so here ... |
|
2449 |
*/ |
|
2450 |
if (((INT)(_ClassInstPtr(myClass)->c_flags) & _MASKSMALLINT(NONOBJECT_INSTS))) { |
|
2451 |
if (idx == 0) { |
|
2452 |
RETURN ( nil ) |
|
2453 |
} |
|
2454 |
} |
|
159 | 2455 |
if ((idx >= 0) && (idx < ninstvars)) { |
2456 |
_InstPtr(self)->i_instvars[idx] = value; |
|
2457 |
__STORE(self, value); |
|
2458 |
RETURN ( value ); |
|
2459 |
} |
|
1 | 2460 |
} |
2461 |
%} |
|
2462 |
. |
|
2463 |
index isInteger ifFalse:[ |
|
159 | 2464 |
^ self indexNotInteger |
1 | 2465 |
]. |
159 | 2466 |
^ self subscriptBoundsError:index |
359 | 2467 |
! |
2468 |
||
2469 |
instVarNamed:name |
|
2470 |
"return a non-indexed instance variables value by name; |
|
2471 |
peeking into an object this way is not very object oriented |
|
2472 |
- use with care (provided for inspectors)" |
|
2473 |
||
2474 |
^ self instVarAt:(self class instVarOffsetOf:name) |
|
2475 |
! |
|
2476 |
||
2477 |
instVarNamed:name put:value |
|
2478 |
"set a non-indexed instance variable by name; |
|
2479 |
peeking into an object this way is not very object oriented |
|
2480 |
- use with care (provided for inspectors)" |
|
2481 |
||
2482 |
^ self instVarAt:(self class instVarOffsetOf:name) put:value |
|
1 | 2483 |
! ! |
2484 |
||
2485 |
!Object methodsFor:'dependents access'! |
|
2486 |
||
2487 |
dependents |
|
2488 |
"return a Collection of dependents - nil if there is none. |
|
2489 |
The default implementation here uses a global Dictionary to store |
|
202 | 2490 |
dependents which may be too slow for high frequency change&update. |
2491 |
Therefore, some classes (Model) redefine this for better performance." |
|
1 | 2492 |
|
159 | 2493 |
^ Dependencies at:self ifAbsent:[nil] |
1 | 2494 |
! |
2495 |
||
2496 |
dependents:aCollection |
|
2497 |
"set the collection of dependents. |
|
2498 |
The default implementation here uses a global Dictionary to store |
|
202 | 2499 |
dependents which may be too slow for high frequency change&update. |
2500 |
Therefore, some classes (Model) redefine this for better performance." |
|
1 | 2501 |
|
2502 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
159 | 2503 |
Dependencies removeKey:self ifAbsent:[] |
1 | 2504 |
] ifFalse:[ |
159 | 2505 |
Dependencies at:self put:aCollection |
2506 |
] |
|
2507 |
! |
|
2508 |
||
2509 |
dependentsDo:aBlock |
|
2510 |
"evaluate aBlock for all of my dependents" |
|
2511 |
||
2512 |
|deps| |
|
2513 |
||
2514 |
deps := self dependents. |
|
2515 |
deps notNil ifTrue:[ |
|
2516 |
deps do:aBlock |
|
1 | 2517 |
] |
2518 |
! |
|
2519 |
||
2520 |
addDependent:anObject |
|
2521 |
"make the argument, anObject be a dependent of the receiver" |
|
2522 |
||
2523 |
|deps| |
|
2524 |
||
2525 |
deps := self dependents. |
|
2526 |
deps isNil ifTrue:[ |
|
159 | 2527 |
self dependents:(WeakIdentitySet with:anObject) |
1 | 2528 |
] ifFalse:[ |
159 | 2529 |
deps add:anObject |
1 | 2530 |
] |
2531 |
! |
|
2532 |
||
2533 |
removeDependent:anObject |
|
2534 |
"make the argument, anObject be independent of the receiver" |
|
2535 |
||
2536 |
|deps| |
|
2537 |
||
2538 |
deps := self dependents. |
|
2539 |
deps notNil ifTrue:[ |
|
159 | 2540 |
deps remove:anObject ifAbsent:[]. |
2541 |
deps isEmpty ifTrue:[ |
|
2542 |
self dependents:nil |
|
2543 |
] |
|
1 | 2544 |
] |
2545 |
! |
|
2546 |
||
2547 |
release |
|
2548 |
"remove all dependencies from the receiver" |
|
2549 |
||
2550 |
self dependents:nil |
|
2551 |
! ! |
|
2552 |
||
2553 |
!Object methodsFor:'change and update'! |
|
2554 |
||
159 | 2555 |
changeRequest |
2556 |
"the receiver wants to change - check if all dependents |
|
2557 |
grant the request, and return true if so" |
|
2558 |
||
2559 |
self dependentsDo:[:dependent | |
|
2560 |
dependent updateRequest ifFalse:[^ false]. |
|
2561 |
]. |
|
2562 |
^ true |
|
2563 |
! |
|
2564 |
||
2565 |
changeRequest:aParameter |
|
2566 |
"the receiver wants to change - check if all dependents |
|
2567 |
grant the request, and return true if so" |
|
2568 |
||
2569 |
self dependentsDo:[:dependent | |
|
2570 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
2571 |
]. |
|
2572 |
^ true |
|
2573 |
! |
|
2574 |
||
2575 |
changeRequestFrom:anObject |
|
2576 |
"the receiver wants to change - check if all dependents |
|
202 | 2577 |
except anObject grant the request, and return true if so. |
2578 |
The argument anObject is typically going to be the one who is |
|
2579 |
about to send the change request." |
|
159 | 2580 |
|
2581 |
self dependentsDo:[:dependent | |
|
2582 |
dependent == anObject ifFalse:[ |
|
2583 |
(dependent updateRequest) ifFalse:[^ false]. |
|
2584 |
] |
|
2585 |
]. |
|
2586 |
^ true |
|
2587 |
! |
|
2588 |
||
202 | 2589 |
changeRequest:aParameter from:anObject |
2590 |
"the receiver wants to change - check if all dependents |
|
2591 |
except anObject grant the request, and return true if so. |
|
2592 |
The argument anObject is typically going to be the one who is |
|
2593 |
about to send the change request." |
|
2594 |
||
2595 |
self dependentsDo:[:dependent | |
|
2596 |
dependent == anObject ifFalse:[ |
|
2597 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
2598 |
] |
|
2599 |
]. |
|
2600 |
^ true |
|
2601 |
! |
|
2602 |
||
1 | 2603 |
changed |
2604 |
"notify all dependents that the receiver has changed. |
|
71 | 2605 |
Each dependent gets a '#update:'-message with the original |
2606 |
receiver as argument." |
|
1 | 2607 |
|
159 | 2608 |
self changed:nil |
1 | 2609 |
! |
2610 |
||
2611 |
changed:aParameter |
|
2612 |
"notify all dependents that the receiver has changed somehow. |
|
71 | 2613 |
Each dependent gets a '#update:'-message with aParameter |
2614 |
as argument." |
|
1 | 2615 |
|
159 | 2616 |
self changed:aParameter with:nil |
1 | 2617 |
! |
2618 |
||
71 | 2619 |
changed:aParameter with:anArgument |
1 | 2620 |
"notify all dependents that the receiver has changed somehow. |
159 | 2621 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
71 | 2622 |
and anArgument as arguments." |
1 | 2623 |
|
159 | 2624 |
self dependentsDo:[:dependent | |
2625 |
dependent update:aParameter with:anArgument from:self |
|
1 | 2626 |
] |
2627 |
! |
|
2628 |
||
71 | 2629 |
broadcast:aSelectorSymbol |
2630 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1 | 2631 |
|
159 | 2632 |
self dependentsDo:[:dependent | |
2633 |
dependent perform:aSelectorSymbol |
|
1 | 2634 |
] |
2635 |
! |
|
2636 |
||
71 | 2637 |
broadcast:aSelectorSymbol with:anArgument |
2638 |
"send a message with selector aSelectorSymbol with an additional |
|
2639 |
argument anArgument to all my dependents." |
|
1 | 2640 |
|
159 | 2641 |
self dependentsDo:[:dependent | |
2642 |
dependent perform:aSelectorSymbol with:anArgument |
|
1 | 2643 |
] |
2644 |
! |
|
2645 |
||
2646 |
update:aParameter |
|
71 | 2647 |
"the message is sent to a dependent, when one of the objects |
2648 |
on whom the receiver depends, has changed. The argument aParameter |
|
2649 |
is either the changed object or the argument to the #changed: message. |
|
2650 |
||
2651 |
Default behavior here is to do nothing" |
|
1 | 2652 |
|
2653 |
^ self |
|
2654 |
! |
|
2655 |
||
2656 |
update:aParameter with:anArgument |
|
2657 |
"dependent is notified of some change - |
|
159 | 2658 |
Default is to try update:" |
1 | 2659 |
|
2660 |
^ self update:aParameter |
|
2661 |
! |
|
2662 |
||
2663 |
update:aParameter with:anArgument from:sender |
|
2664 |
"dependent is notified of some change - |
|
159 | 2665 |
Default is to try update:with:" |
1 | 2666 |
|
2667 |
^ self update:aParameter with:anArgument |
|
159 | 2668 |
! |
2669 |
||
2670 |
updateRequest |
|
2671 |
"return true, if an update request is granted. |
|
2672 |
Default here is to grant updates - may be used |
|
2673 |
to lock updates if someone is making other changes |
|
202 | 2674 |
from within an update. Or if someone has locked its |
2675 |
state and does not want others to change things. |
|
2676 |
However, these dependents must all honor the |
|
2677 |
changeRequest - ifTrue - change protocol. I.e. they |
|
2678 |
must first ask all others via changeRequest, and only do the change |
|
2679 |
it returns true. The others must decide in updateRequest and |
|
2680 |
return true if they think a change is ok." |
|
159 | 2681 |
|
2682 |
^ true |
|
2683 |
! |
|
2684 |
||
2685 |
updateRequest:aSymbol |
|
2686 |
"return true, if an update request is granted. |
|
2687 |
Default here a simple updateRequest" |
|
2688 |
||
2689 |
^ self updateRequest |
|
1 | 2690 |
! ! |
2691 |
||
71 | 2692 |
!Object methodsFor:'secure message sending'! |
2693 |
||
2694 |
askFor:aSelector |
|
2695 |
"try to send the receiver the message, aSelector. |
|
2696 |
If it does not understand it, return false. Otherwise |
|
2697 |
the real value returned. |
|
2698 |
Useful to send messages such as: 'isColor' to unknown |
|
2699 |
receivers." |
|
2700 |
||
143 | 2701 |
^ self perform:aSelector ifNotUnderstood:[false] |
2702 |
||
2703 |
" |
|
2704 |
1 askFor:#isColor |
|
2705 |
" |
|
71 | 2706 |
! |
2707 |
||
2708 |
perform:aSelector ifNotUnderstood:exceptionBlock |
|
2709 |
"try to send message aSelector to the receiver. |
|
2710 |
If its understood, return the methods returned value, |
|
2711 |
otherwise return the value of the exceptionBlock" |
|
2712 |
||
2713 |
|val| |
|
2714 |
||
2715 |
MessageNotUnderstoodSignal handle:[:ex | |
|
159 | 2716 |
^ exceptionBlock value |
71 | 2717 |
] do:[ |
159 | 2718 |
val := self perform:aSelector |
71 | 2719 |
]. |
2720 |
^ val |
|
2721 |
||
2722 |
" |
|
325 | 2723 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
71 | 2724 |
" |
2725 |
! |
|
2726 |
||
2727 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
2728 |
"try to send message aSelector to the receiver. |
|
2729 |
If its understood, return the methods returned value, |
|
2730 |
otherwise return the value of the exceptionBlock" |
|
2731 |
||
2732 |
|val| |
|
2733 |
||
2734 |
MessageNotUnderstoodSignal handle:[:ex | |
|
159 | 2735 |
^ exceptionBlock value |
71 | 2736 |
] do:[ |
159 | 2737 |
val := self perform:aSelector with:argument |
71 | 2738 |
]. |
2739 |
^ val |
|
2740 |
||
2741 |
" |
|
2742 |
|unknown| |
|
2743 |
||
2744 |
unknown := 1. |
|
2745 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
2746 |
unknown := 'high there'. |
|
2747 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
2748 |
" |
|
2749 |
! ! |
|
2750 |
||
1 | 2751 |
!Object methodsFor:'message sending'! |
2752 |
||
2753 |
perform:aSelector |
|
2754 |
"send the message aSelector to the receiver" |
|
2755 |
||
2756 |
%{ /* NOCONTEXT */ |
|
2757 |
||
213 | 2758 |
#if !defined(hppa) && !defined(mips) |
159 | 2759 |
#define PRE_2_11 |
179 | 2760 |
#endif |
2761 |
||
93 | 2762 |
#ifdef PRE_2_11 |
1 | 2763 |
static struct inlineCache ilc = _ILC0; |
93 | 2764 |
struct inlineCache lilc = _DUMMYILC0; |
2765 |
#else |
|
2766 |
static struct inlineCache ilc = _DUMMYILC0; |
|
2767 |
struct inlineCache lilc; |
|
2768 |
#endif |
|
1 | 2769 |
static OBJ lastSelector = nil; |
2770 |
||
71 | 2771 |
#if defined(THIS_CONTEXT) |
1 | 2772 |
/* |
93 | 2773 |
* must set lineno in sender by hand here ... (because of NOCONTEXT) |
1 | 2774 |
*/ |
329 | 2775 |
_ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 2776 |
#endif |
2777 |
||
93 | 2778 |
#ifdef PRE_2_11 |
1 | 2779 |
if (aSelector != lastSelector) { |
159 | 2780 |
ilc.ilc_func = _SEND0; |
2781 |
lastSelector = aSelector; |
|
1 | 2782 |
} |
93 | 2783 |
#else |
2784 |
lilc = ilc; |
|
2785 |
#endif |
|
2786 |
||
329 | 2787 |
#if !defined(TRADITIONAL_STACK_FRAME) |
2788 |
lilc.ilc_lineNo = __pilc->ilc_lineNo; |
|
2789 |
#endif |
|
2790 |
||
93 | 2791 |
#if defined(xxTHIS_CONTEXT) |
85 | 2792 |
# ifdef PRE_2_11 |
1 | 2793 |
ilc.ilc_lineNo = __pilc->ilc_lineNo; |
85 | 2794 |
# else |
2795 |
lilc.ilc_lineNo = __pilc->ilc_lineNo; |
|
2796 |
# endif |
|
1 | 2797 |
#endif |
2798 |
||
85 | 2799 |
#ifdef PRE_2_11 |
1 | 2800 |
RETURN ( (*ilc.ilc_func)(self, aSelector, CON_COMMA nil, &ilc) ); |
85 | 2801 |
#else |
2802 |
RETURN ( (*ilc.ilc_func)(self, aSelector, CON_COMMA nil, &lilc) ); |
|
2803 |
#endif |
|
1 | 2804 |
%} |
2805 |
! |
|
2806 |
||
2807 |
perform:aSelector with:anObject |
|
2808 |
"send the one-arg-message aSelector to the receiver" |
|
2809 |
||
2810 |
%{ /* NOCONTEXT */ |
|
2811 |
||
93 | 2812 |
#ifdef PRE_2_11 |
1 | 2813 |
static struct inlineCache ilc = _ILC1; |
93 | 2814 |
struct inlineCache lilc = _DUMMYILC1; |
159 | 2815 |
|
1 | 2816 |
static OBJ lastSelector = nil; |
2817 |
||
159 | 2818 |
# if defined(THIS_CONTEXT) |
1 | 2819 |
/* |
93 | 2820 |
* must set lineno in sender by hand here ... (because of NOCONTEXT) |
1 | 2821 |
*/ |
329 | 2822 |
_ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
159 | 2823 |
# endif |
2824 |
||
1 | 2825 |
if (aSelector != lastSelector) { |
159 | 2826 |
ilc.ilc_func = _SEND1; |
2827 |
lastSelector = aSelector; |
|
1 | 2828 |
} |
2829 |
ilc.ilc_lineNo = __pilc->ilc_lineNo; |
|
2830 |
RETURN ( (*ilc.ilc_func)(self, aSelector, CON_COMMA nil, &ilc, anObject) ); |
|
85 | 2831 |
#else |
159 | 2832 |
static struct inlineCache ilc = _DUMMYILC1; |
2833 |
struct inlineCache lilc; |
|
2834 |
||
2835 |
# if defined(THIS_CONTEXT) |
|
2836 |
/* |
|
2837 |
* must set lineno in sender by hand here ... (because of NOCONTEXT) |
|
2838 |
*/ |
|
329 | 2839 |
_ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
159 | 2840 |
# endif |
2841 |
||
2842 |
lilc = ilc; |
|
2843 |
lilc.ilc_lineNo = __pilc->ilc_lineNo; |
|
85 | 2844 |
RETURN ( (*ilc.ilc_func)(self, aSelector, CON_COMMA nil, &lilc, anObject) ); |
2845 |
#endif |
|
1 | 2846 |
%} |
2847 |
! |
|
2848 |
||
2849 |
perform:aSelector with:firstObject with:secondObject |
|
2850 |
"send the two-arg-message aSelector to the receiver" |
|
2851 |
||
2852 |
%{ /* NOCONTEXT */ |
|
2853 |
||
93 | 2854 |
#ifdef PRE_2_11 |
1 | 2855 |
static struct inlineCache ilc = _ILC2; |
93 | 2856 |
struct inlineCache lilc = _DUMMYILC2; |
2857 |
#else |
|
2858 |
static struct inlineCache ilc = _DUMMYILC2; |
|
2859 |
struct inlineCache lilc; |
|
2860 |
#endif |
|
1 | 2861 |
static OBJ lastSelector = nil; |
2862 |
||
71 | 2863 |
#if defined(THIS_CONTEXT) |
1 | 2864 |
/* |
93 | 2865 |
* must set lineno in sender by hand here ... (because of NOCONTEXT) |
1 | 2866 |
*/ |
329 | 2867 |
_ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 2868 |
#endif |
93 | 2869 |
|
2870 |
#ifdef PRE_2_11 |
|
1 | 2871 |
if (aSelector != lastSelector) { |
159 | 2872 |
ilc.ilc_func = _SEND2; |
2873 |
lastSelector = aSelector; |
|
1 | 2874 |
} |
93 | 2875 |
#else |
2876 |
lilc = ilc; |
|
2877 |
#endif |
|
2878 |
||
329 | 2879 |
#if !defined(TRADITIONAL_STACK_FRAME) |
2880 |
lilc.ilc_lineNo = __pilc->ilc_lineNo; |
|
2881 |
#endif |
|
2882 |
||
93 | 2883 |
#if defined(xxTHIS_CONTEXT) |
85 | 2884 |
# ifdef PRE_2_11 |
1 | 2885 |
ilc.ilc_lineNo = __pilc->ilc_lineNo; |
85 | 2886 |
# else |
2887 |
lilc.ilc_lineNo = __pilc->ilc_lineNo; |
|
2888 |
# endif |
|
1 | 2889 |
#endif |
2890 |
||
85 | 2891 |
# ifdef PRE_2_11 |
2892 |
RETURN ((*ilc.ilc_func)(self, aSelector, CON_COMMA nil, &ilc, firstObject, secondObject)); |
|
2893 |
# else |
|
2894 |
RETURN ((*ilc.ilc_func)(self, aSelector, CON_COMMA nil, &lilc, firstObject, secondObject)); |
|
2895 |
# endif |
|
1 | 2896 |
%} |
2897 |
! |
|
2898 |
||
2899 |
perform:aSelector with:firstObject with:secondObject with:thirdObject |
|
2900 |
"send the three-arg-message aSelector to the receiver" |
|
2901 |
||
2902 |
%{ /* NOCONTEXT */ |
|
2903 |
||
93 | 2904 |
#ifdef PRE_2_11 |
1 | 2905 |
static struct inlineCache ilc = _ILC3; |
93 | 2906 |
struct inlineCache lilc = _DUMMYILC3; |
2907 |
#else |
|
2908 |
static struct inlineCache ilc = _DUMMYILC3; |
|
2909 |
struct inlineCache lilc; |
|
2910 |
#endif |
|
1 | 2911 |
static OBJ lastSelector = nil; |
2912 |
||
71 | 2913 |
#if defined(THIS_CONTEXT) |
1 | 2914 |
/* |
93 | 2915 |
* must set lineno in sender by hand here ... (because of NOCONTEXT) |
1 | 2916 |
*/ |
329 | 2917 |
_ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 2918 |
#endif |
93 | 2919 |
|
2920 |
#ifdef PRE_2_11 |
|
1 | 2921 |
if (aSelector != lastSelector) { |
159 | 2922 |
ilc.ilc_func = _SEND3; |
2923 |
lastSelector = aSelector; |
|
1 | 2924 |
} |
93 | 2925 |
#else |
2926 |
lilc = ilc; |
|
329 | 2927 |
# if !defined(TRADITIONAL_STACK_FRAME) |
2928 |
lilc.ilc_lineNo = __pilc->ilc_lineNo; |
|
2929 |
# endif |
|
1 | 2930 |
#endif |
2931 |
||
93 | 2932 |
#if defined(xxTHIS_CONTEXT) |
2933 |
# ifdef PRE_2_11 |
|
2934 |
ilc.ilc_lineNo = __pilc->ilc_lineNo; |
|
2935 |
# else |
|
2936 |
lilc.ilc_lineNo = __pilc->ilc_lineNo; |
|
2937 |
# endif |
|
2938 |
#endif |
|
2939 |
||
2940 |
# ifdef PRE_2_11 |
|
2941 |
RETURN ((*ilc.ilc_func)(self, aSelector, CON_COMMA nil, &ilc, firstObject, secondObject, thirdObject)); |
|
2942 |
# else |
|
2943 |
RETURN ((*ilc.ilc_func)(self, aSelector, CON_COMMA nil, &lilc, firstObject, secondObject, thirdObject)); |
|
2944 |
# endif |
|
1 | 2945 |
%} |
2946 |
! |
|
2947 |
||
2948 |
perform:aSelector withArguments:argArray |
|
2949 |
"send the message aSelector with all args taken from argArray |
|
44 | 2950 |
to the receiver." |
1 | 2951 |
|
77 | 2952 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
1 | 2953 |
|
2954 |
numberOfArgs := argArray size. |
|
2955 |
%{ |
|
443 | 2956 |
extern OBJ Array, __AT_(); |
1 | 2957 |
REGISTER OBJ *argP; |
2958 |
int nargs, i; |
|
2959 |
static OBJ last0 = nil; static struct inlineCache ilc0 = _ILC0; |
|
2960 |
static OBJ last1 = nil; static struct inlineCache ilc1 = _ILC1; |
|
2961 |
static OBJ last2 = nil; static struct inlineCache ilc2 = _ILC2; |
|
2962 |
static OBJ last3 = nil; static struct inlineCache ilc3 = _ILC3; |
|
2963 |
static OBJ last4 = nil; static struct inlineCache ilc4 = _ILC4; |
|
2964 |
static OBJ last5 = nil; static struct inlineCache ilc5 = _ILC5; |
|
2965 |
static OBJ last6 = nil; static struct inlineCache ilc6 = _ILC6; |
|
2966 |
static OBJ last7 = nil; static struct inlineCache ilc7 = _ILC7; |
|
2967 |
static OBJ last8 = nil; static struct inlineCache ilc8 = _ILC8; |
|
2968 |
static OBJ last9 = nil; static struct inlineCache ilc9 = _ILC9; |
|
2969 |
static OBJ last10 = nil; static struct inlineCache ilc10 = _ILC10; |
|
2970 |
static OBJ last11 = nil; static struct inlineCache ilc11 = _ILC11; |
|
2971 |
static OBJ last12 = nil; static struct inlineCache ilc12 = _ILC12; |
|
71 | 2972 |
static OBJ last13 = nil; static struct inlineCache ilc13 = _ILC13; |
2973 |
static OBJ last14 = nil; static struct inlineCache ilc14 = _ILC14; |
|
2974 |
static OBJ last15 = nil; static struct inlineCache ilc15 = _ILC15; |
|
2975 |
||
93 | 2976 |
#if defined(xxxTHIS_CONTEXT) |
71 | 2977 |
/* |
93 | 2978 |
* must set lineno in sender by hand here ... (because of NOCONTEXT) |
71 | 2979 |
*/ |
329 | 2980 |
_ContextInstPtr(__sender)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
71 | 2981 |
#endif |
1 | 2982 |
|
253 | 2983 |
if (__isSmallInteger(numberOfArgs)) { |
159 | 2984 |
nargs = _intVal(numberOfArgs); |
2985 |
if (nargs == 0) { |
|
2986 |
if (aSelector != last0) { |
|
2987 |
ilc0.ilc_func = _SEND0; |
|
332 | 2988 |
if (ilc0.ilc_poly) { |
339 | 2989 |
__flushPolyCache(ilc0.ilc_poly); |
2990 |
ilc0.ilc_poly = 0; |
|
2991 |
} |
|
159 | 2992 |
last0 = aSelector; |
2993 |
} |
|
93 | 2994 |
#ifdef xxTHIS_CONTEXT |
159 | 2995 |
ilc0.ilc_lineNo = __pilc->ilc_lineNo; |
44 | 2996 |
#endif |
159 | 2997 |
RETURN ((*ilc0.ilc_func)(self, aSelector, CON_COMMA nil, &ilc0)); |
2998 |
} |
|
2999 |
||
3000 |
if (__isArray(argArray)) { |
|
3001 |
argP = _ArrayInstPtr(argArray)->a_element; |
|
3002 |
} else { |
|
3003 |
argP = (OBJ *)(&a1); |
|
3004 |
for (i=1; i <= nargs; i++) { |
|
443 | 3005 |
*argP++ = __AT_(argArray, CON_COMMA _MKSMALLINT(i)); |
159 | 3006 |
} |
3007 |
} |
|
3008 |
switch (nargs) { |
|
3009 |
case 1: |
|
3010 |
if (aSelector != last1) { |
|
3011 |
ilc1.ilc_func = _SEND1; |
|
332 | 3012 |
if (ilc1.ilc_poly) { |
339 | 3013 |
__flushPolyCache(ilc1.ilc_poly); |
3014 |
ilc1.ilc_poly = 0; |
|
3015 |
} |
|
159 | 3016 |
last1 = aSelector; |
3017 |
} |
|
93 | 3018 |
#ifdef xxTHIS_CONTEXT |
159 | 3019 |
ilc1.ilc_lineNo = __pilc->ilc_lineNo; |
44 | 3020 |
#endif |
159 | 3021 |
RETURN ( (*ilc1.ilc_func)(self, aSelector, CON_COMMA nil, &ilc1, argP[0])); |
3022 |
||
3023 |
case 2: |
|
3024 |
if (aSelector != last2) { |
|
3025 |
ilc2.ilc_func = _SEND2; |
|
332 | 3026 |
if (ilc2.ilc_poly) { |
339 | 3027 |
__flushPolyCache(ilc2.ilc_poly); |
3028 |
ilc2.ilc_poly = 0; |
|
3029 |
} |
|
159 | 3030 |
last2 = aSelector; |
3031 |
} |
|
93 | 3032 |
#ifdef xxTHIS_CONTEXT |
159 | 3033 |
ilc2.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3034 |
#endif |
159 | 3035 |
RETURN ( (*ilc2.ilc_func)(self, aSelector, CON_COMMA nil, &ilc2, |
3036 |
argP[0], argP[1])); |
|
3037 |
||
3038 |
case 3: |
|
3039 |
if (aSelector != last3) { |
|
3040 |
ilc3.ilc_func = _SEND3; |
|
332 | 3041 |
if (ilc3.ilc_poly) { |
339 | 3042 |
__flushPolyCache(ilc3.ilc_poly); |
3043 |
ilc3.ilc_poly = 0; |
|
3044 |
} |
|
159 | 3045 |
last3 = aSelector; |
3046 |
} |
|
93 | 3047 |
#ifdef xxTHIS_CONTEXT |
159 | 3048 |
ilc3.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3049 |
#endif |
159 | 3050 |
RETURN ( (*ilc3.ilc_func)(self, aSelector, CON_COMMA nil, &ilc3, |
3051 |
argP[0], argP[1], argP[2])); |
|
3052 |
||
3053 |
case 4: |
|
3054 |
if (aSelector != last4) { |
|
3055 |
ilc4.ilc_func = _SEND4; |
|
332 | 3056 |
if (ilc4.ilc_poly) { |
339 | 3057 |
__flushPolyCache(ilc4.ilc_poly); |
3058 |
ilc4.ilc_poly = 0; |
|
3059 |
} |
|
159 | 3060 |
last4 = aSelector; |
3061 |
} |
|
93 | 3062 |
#ifdef xxTHIS_CONTEXT |
159 | 3063 |
ilc4.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3064 |
#endif |
159 | 3065 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, CON_COMMA nil, &ilc4, |
3066 |
argP[0], argP[1], argP[2], argP[3])); |
|
3067 |
||
3068 |
case 5: |
|
3069 |
if (aSelector != last5) { |
|
3070 |
ilc5.ilc_func = _SEND5; |
|
332 | 3071 |
if (ilc5.ilc_poly) { |
339 | 3072 |
__flushPolyCache(ilc5.ilc_poly); |
3073 |
ilc5.ilc_poly = 0; |
|
3074 |
} |
|
159 | 3075 |
last5 = aSelector; |
3076 |
} |
|
93 | 3077 |
#ifdef xxTHIS_CONTEXT |
159 | 3078 |
ilc5.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3079 |
#endif |
159 | 3080 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, CON_COMMA nil, &ilc5, |
3081 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
3082 |
||
3083 |
case 6: |
|
3084 |
if (aSelector != last6) { |
|
3085 |
ilc6.ilc_func = _SEND6; |
|
332 | 3086 |
if (ilc6.ilc_poly) { |
339 | 3087 |
__flushPolyCache(ilc6.ilc_poly); |
3088 |
ilc6.ilc_poly = 0; |
|
3089 |
} |
|
159 | 3090 |
last6 = aSelector; |
3091 |
} |
|
93 | 3092 |
#ifdef xxTHIS_CONTEXT |
159 | 3093 |
ilc6.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3094 |
#endif |
159 | 3095 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, CON_COMMA nil, &ilc6, |
3096 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3097 |
argP[5])); |
|
3098 |
||
3099 |
case 7: |
|
3100 |
if (aSelector != last7) { |
|
3101 |
ilc7.ilc_func = _SEND7; |
|
332 | 3102 |
if (ilc7.ilc_poly) { |
339 | 3103 |
__flushPolyCache(ilc7.ilc_poly); |
3104 |
ilc7.ilc_poly = 0; |
|
3105 |
} |
|
159 | 3106 |
last7 = aSelector; |
3107 |
} |
|
93 | 3108 |
#ifdef xxTHIS_CONTEXT |
159 | 3109 |
ilc7.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3110 |
#endif |
159 | 3111 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, CON_COMMA nil, &ilc7, |
3112 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3113 |
argP[5], argP[6])); |
|
3114 |
||
3115 |
case 8: |
|
3116 |
if (aSelector != last8) { |
|
3117 |
ilc8.ilc_func = _SEND8; |
|
3118 |
last8 = aSelector; |
|
3119 |
} |
|
93 | 3120 |
#ifdef xxTHIS_CONTEXT |
159 | 3121 |
ilc8.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3122 |
#endif |
159 | 3123 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, CON_COMMA nil, &ilc8, |
3124 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3125 |
argP[5], argP[6], argP[7])); |
|
3126 |
||
3127 |
case 9: |
|
3128 |
if (aSelector != last9) { |
|
3129 |
ilc9.ilc_func = _SEND9; |
|
3130 |
last9 = aSelector; |
|
3131 |
} |
|
93 | 3132 |
#ifdef xxTHIS_CONTEXT |
159 | 3133 |
ilc9.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3134 |
#endif |
159 | 3135 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, CON_COMMA nil, &ilc9, |
3136 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3137 |
argP[5], argP[6], argP[7], argP[8])); |
|
3138 |
||
3139 |
case 10: |
|
3140 |
if (aSelector != last10) { |
|
3141 |
ilc10.ilc_func = _SEND10; |
|
3142 |
last10 = aSelector; |
|
3143 |
} |
|
93 | 3144 |
#ifdef xxTHIS_CONTEXT |
159 | 3145 |
ilc10.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3146 |
#endif |
159 | 3147 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, CON_COMMA nil, &ilc10, |
3148 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3149 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
3150 |
||
3151 |
case 11: |
|
3152 |
if (aSelector != last11) { |
|
3153 |
ilc11.ilc_func = _SEND11; |
|
3154 |
last11 = aSelector; |
|
3155 |
} |
|
93 | 3156 |
#ifdef xxTHIS_CONTEXT |
159 | 3157 |
ilc11.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3158 |
#endif |
159 | 3159 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, CON_COMMA nil, &ilc11, |
3160 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3161 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
3162 |
argP[10])); |
|
3163 |
||
3164 |
case 12: |
|
3165 |
if (aSelector != last12) { |
|
3166 |
ilc12.ilc_func = _SEND12; |
|
3167 |
last12 = aSelector; |
|
3168 |
} |
|
93 | 3169 |
#ifdef xxTHIS_CONTEXT |
159 | 3170 |
ilc12.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3171 |
#endif |
159 | 3172 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, CON_COMMA nil, &ilc12, |
3173 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3174 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
3175 |
argP[10], argP[11])); |
|
3176 |
||
3177 |
case 13: |
|
3178 |
if (aSelector != last13) { |
|
3179 |
ilc13.ilc_func = _SEND13; |
|
3180 |
last13 = aSelector; |
|
3181 |
} |
|
93 | 3182 |
#ifdef xxTHIS_CONTEXT |
159 | 3183 |
ilc13.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3184 |
#endif |
159 | 3185 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, CON_COMMA nil, &ilc13, |
3186 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3187 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
3188 |
argP[10], argP[11], argP[12])); |
|
3189 |
||
3190 |
case 14: |
|
3191 |
if (aSelector != last14) { |
|
3192 |
ilc14.ilc_func = _SEND14; |
|
3193 |
last14 = aSelector; |
|
3194 |
} |
|
93 | 3195 |
#ifdef xxTHIS_CONTEXT |
159 | 3196 |
ilc14.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3197 |
#endif |
159 | 3198 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, CON_COMMA nil, &ilc14, |
3199 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3200 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
3201 |
argP[10], argP[11], argP[12], argP[13])); |
|
3202 |
||
3203 |
case 15: |
|
3204 |
if (aSelector != last15) { |
|
3205 |
ilc15.ilc_func = _SEND15; |
|
3206 |
last15 = aSelector; |
|
3207 |
} |
|
93 | 3208 |
#ifdef xxTHIS_CONTEXT |
159 | 3209 |
ilc15.ilc_lineNo = __pilc->ilc_lineNo; |
77 | 3210 |
#endif |
159 | 3211 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, CON_COMMA nil, &ilc15, |
3212 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3213 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
3214 |
argP[10], argP[11], argP[12], argP[13], |
|
3215 |
argP[14])); |
|
3216 |
} |
|
1 | 3217 |
} |
3218 |
%} |
|
3219 |
. |
|
3220 |
^ self primitiveFailed |
|
44 | 3221 |
! |
3222 |
||
3223 |
perform:aSelector inClass:aClass withArguments:argArray |
|
3224 |
"send the message aSelector with all args taken from argArray |
|
3225 |
to the receiver as a super-send message. |
|
3226 |
This is actually more flexible than the normal super-send, since it allows |
|
3227 |
to execute a method in ANY superclass of the receiver (not just the |
|
3228 |
immediate superclass). |
|
3229 |
Thus, it is (theoretically) possible to do |
|
159 | 3230 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
44 | 3231 |
and evaluate Magnitudes compare method even if there was one in Number. |
93 | 3232 |
This method is used by the interpreter to evaluate super sends |
3233 |
and could be used for very special behavior (language extension ?). |
|
3234 |
||
71 | 3235 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
44 | 3236 |
|
77 | 3237 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
44 | 3238 |
|
93 | 3239 |
" |
3240 |
check, if aClass is really a superclass of the receiver |
|
3241 |
" |
|
44 | 3242 |
(self class isSubclassOf:aClass) ifFalse:[ |
159 | 3243 |
self error:'class argument is not a superclass of the receiver'. |
3244 |
^ nil |
|
44 | 3245 |
]. |
3246 |
numberOfArgs := argArray size. |
|
3247 |
%{ |
|
443 | 3248 |
extern OBJ Array, __AT_(); |
44 | 3249 |
REGISTER OBJ *argP; |
3250 |
int nargs, i; |
|
3251 |
static struct inlineCache ilc0 = _DUMMYILC0; |
|
3252 |
static struct inlineCache ilc1 = _DUMMYILC1; |
|
3253 |
static struct inlineCache ilc2 = _DUMMYILC2; |
|
3254 |
static struct inlineCache ilc3 = _DUMMYILC3; |
|
3255 |
static struct inlineCache ilc4 = _DUMMYILC4; |
|
3256 |
static struct inlineCache ilc5 = _DUMMYILC5; |
|
3257 |
static struct inlineCache ilc6 = _DUMMYILC6; |
|
3258 |
static struct inlineCache ilc7 = _DUMMYILC7; |
|
3259 |
static struct inlineCache ilc8 = _DUMMYILC8; |
|
3260 |
static struct inlineCache ilc9 = _DUMMYILC9; |
|
3261 |
static struct inlineCache ilc10 = _DUMMYILC10; |
|
3262 |
static struct inlineCache ilc11 = _DUMMYILC11; |
|
3263 |
static struct inlineCache ilc12 = _DUMMYILC12; |
|
77 | 3264 |
static struct inlineCache ilc13 = _DUMMYILC13; |
3265 |
static struct inlineCache ilc14 = _DUMMYILC14; |
|
3266 |
static struct inlineCache ilc15 = _DUMMYILC15; |
|
44 | 3267 |
|
253 | 3268 |
if (__isSmallInteger(numberOfArgs)) { |
159 | 3269 |
nargs = _intVal(numberOfArgs); |
3270 |
if (nargs == 0) { |
|
3271 |
RETURN (_SEND0(self, aSelector, CON_COMMA aClass, &ilc0)); |
|
3272 |
} |
|
3273 |
||
3274 |
argP = (OBJ *)(&a1); |
|
329 | 3275 |
if (__Class(argArray) == Array) { |
159 | 3276 |
for (i=0; i < nargs; i++) { |
3277 |
*argP++ = _ArrayInstPtr(argArray)->a_element[i]; |
|
3278 |
} |
|
3279 |
} else { |
|
3280 |
for (i=1; i <= nargs; i++) { |
|
443 | 3281 |
*argP++ = __AT_(argArray, CON_COMMA _MKSMALLINT(i)); |
159 | 3282 |
} |
3283 |
} |
|
3284 |
switch (nargs) { |
|
3285 |
case 1: |
|
3286 |
RETURN ( _SEND1(self, aSelector, CON_COMMA aClass, &ilc1, a1)); |
|
3287 |
||
3288 |
case 2: |
|
3289 |
RETURN ( _SEND2(self, aSelector, CON_COMMA aClass, &ilc2, a1, a2)); |
|
3290 |
||
3291 |
case 3: |
|
3292 |
RETURN ( _SEND3(self, aSelector, CON_COMMA aClass, &ilc3, a1, a2, a3)); |
|
3293 |
||
3294 |
case 4: |
|
3295 |
RETURN ( _SEND4(self, aSelector, CON_COMMA aClass, &ilc4, a1, a2, a3, a4)); |
|
3296 |
||
3297 |
case 5: |
|
3298 |
RETURN ( _SEND5(self, aSelector, CON_COMMA aClass, &ilc5, |
|
3299 |
a1, a2, a3, a4, a5)); |
|
3300 |
||
3301 |
case 6: |
|
3302 |
RETURN ( _SEND6(self, aSelector, CON_COMMA aClass, &ilc6, |
|
3303 |
a1, a2, a3, a4, a5, a6)); |
|
3304 |
||
3305 |
case 7: |
|
3306 |
RETURN ( _SEND7(self, aSelector, CON_COMMA aClass, &ilc7, |
|
3307 |
a1, a2, a3, a4, a5, a6, a7)); |
|
3308 |
||
3309 |
case 8: |
|
3310 |
RETURN ( _SEND8(self, aSelector, CON_COMMA aClass, &ilc8, |
|
3311 |
a1, a2, a3, a4, a5, a6, a7, a8)); |
|
3312 |
||
3313 |
case 9: |
|
3314 |
RETURN ( _SEND9(self, aSelector, CON_COMMA aClass, &ilc9, |
|
3315 |
a1, a2, a3, a4, a5, a6, a7, a8, a9)); |
|
3316 |
||
3317 |
case 10: |
|
3318 |
RETURN ( _SEND10(self, aSelector, CON_COMMA aClass, &ilc10, |
|
3319 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)); |
|
3320 |
||
3321 |
case 11: |
|
3322 |
RETURN ( _SEND11(self, aSelector, CON_COMMA aClass, &ilc11, |
|
3323 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)); |
|
3324 |
||
3325 |
case 12: |
|
3326 |
RETURN ( _SEND12(self, aSelector, CON_COMMA aClass, &ilc12, |
|
3327 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)); |
|
3328 |
||
3329 |
case 13: |
|
3330 |
RETURN ( _SEND13(self, aSelector, CON_COMMA aClass, &ilc13, |
|
3331 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, |
|
3332 |
a13)); |
|
3333 |
||
3334 |
case 14: |
|
3335 |
RETURN ( _SEND14(self, aSelector, CON_COMMA aClass, &ilc14, |
|
3336 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, |
|
3337 |
a13, a14)); |
|
3338 |
||
3339 |
case 15: |
|
3340 |
RETURN ( _SEND15(self, aSelector, CON_COMMA aClass, &ilc15, |
|
3341 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, |
|
3342 |
a13, a14, a15)); |
|
3343 |
} |
|
44 | 3344 |
} |
3345 |
%} |
|
3346 |
. |
|
3347 |
^ self primitiveFailed |
|
1 | 3348 |
! ! |
3349 |
||
2 | 3350 |
!Object methodsFor:'binary storage'! |
3351 |
||
39 | 3352 |
storeBinaryOn:aStream |
2 | 3353 |
"Writes a description of the receiver onto aStream, in a way that allows |
3354 |
the object's structure to be reconstructed from the stream's contents" |
|
3355 |
||
39 | 3356 |
BinaryOutputManager store:self on:aStream |
2 | 3357 |
! |
3358 |
||
3359 |
hasSpecialBinaryRepresentation |
|
39 | 3360 |
"return true, if the receiver has a special binary representation; |
3361 |
default here is false, but can be redefined in class which provide |
|
343 | 3362 |
their own storeBinary/readBinary methods. |
3363 |
||
3364 |
Normal user classes should not use this, it is meant as a hook for |
|
3365 |
special classes such as True, False, UndefinedObject or SmallInteger. |
|
3366 |
||
3367 |
If your instances should be stored in a special way, see |
|
3368 |
#representBinaryOn: and #readBinaryContentsFromdata:manager:." |
|
39 | 3369 |
|
2 | 3370 |
^ false |
3371 |
! |
|
3372 |
||
343 | 3373 |
representBinaryOn:manager |
3374 |
"this method is called by the storage manager to ask objects |
|
3375 |
if they wish to provide their own binary representation. |
|
3376 |
||
3377 |
If they want to do so, they should return an array containing all |
|
3378 |
instance variables (named & indexed pointer) to be stored. |
|
3379 |
If not redefined, this method returns nil which means that all |
|
3380 |
instance variables are to be stored. |
|
3381 |
||
362 | 3382 |
It should be redefined in objects which do not want all instance variables |
343 | 3383 |
to be stored (for example: objects which keep references to a view etc.). |
3384 |
||
3385 |
If this is redefined returning non-nil, the corresponding class needs |
|
3386 |
a redefined instance method named #readBinaryContentsFromData:manager: |
|
3387 |
which has to fill the receivers named (and optionally indexed pointer) |
|
3388 |
instance variables with corresponding values from a data array." |
|
3389 |
||
3390 |
^ nil |
|
3391 |
||
362 | 3392 |
"typical implementation: |
3393 |
(see also comment in #readBinaryContentsFromData:manager:) |
|
3394 |
for an object with foo, bar and baz as instance variables, |
|
3395 |
which does not want to store baz: |
|
3396 |
||
3397 |
representBinaryOn:manager |
|
343 | 3398 |
|data| |
3399 |
||
3400 |
data := Array new:2. |
|
3401 |
data at:1 put:foo. |
|
3402 |
data at:2 put:bar. |
|
362 | 3403 |
^ data |
343 | 3404 |
" |
3405 |
! |
|
3406 |
||
3407 |
readBinaryContentsFromData:instvarArray manager:manager |
|
3408 |
"reconstruct the receivers instance variables by filling instance |
|
3409 |
variables with values from instvarArray. This array contains the instvars |
|
3410 |
as specified in #representBinaryOn: when the object was stored. |
|
3411 |
It is the receivers responsibility to set its instance variables in the |
|
3412 |
same order from that array." |
|
3413 |
||
3414 |
^ self subclassResponsibility |
|
3415 |
||
3416 |
"typical implementation (see also comment in #representBinaryOn:) |
|
3417 |
(for an object with foo, bar and baz as instance variables, |
|
3418 |
which did not store baz and wants baz to be reinitialized to |
|
3419 |
some constant string) |
|
3420 |
||
3421 |
foo := instvarArray at:1. |
|
3422 |
bar := instvarArray at:2. |
|
3423 |
baz := 'aConstant'. |
|
3424 |
" |
|
3425 |
! |
|
3426 |
||
3427 |
storeBinaryContentsFromData:instvarArray on:stream manager:manager |
|
3428 |
"store the instvars (both named & indexed pointer) |
|
3429 |
as returned by #representBinaryOn:." |
|
3430 |
||
3431 |
|size "{ Class: SmallInteger }"| |
|
3432 |
||
3433 |
size := instvarArray size. |
|
3434 |
1 to:size do:[:i | |
|
3435 |
manager putIdOf:(instvarArray at:i) on:stream |
|
3436 |
]. |
|
3437 |
! |
|
3438 |
||
39 | 3439 |
readBinaryContentsFrom:stream manager:manager |
3440 |
"reconstruct the receivers instance variables by reading a binary |
|
343 | 3441 |
binary representation from stream. |
324 | 3442 |
This is a general implementation, walking over instances |
3443 |
and loading each recursively using manager. |
|
343 | 3444 |
Redefined by some classes to read a more compact representations |
3445 |
(see String, SmallInteger etc). |
|
3446 |
||
3447 |
Notice, that the object is already recreated as an empty corps |
|
3448 |
with instance variables all nil and bit-instances (bytes, words etc.) |
|
3449 |
already read and restored. |
|
3450 |
||
3451 |
Also notice: this method is not called for if a private representation |
|
3452 |
has been stored (see representBinaryOn:). |
|
3453 |
In that case, #readBinaryContentsFromData:manager: is called, which |
|
3454 |
has to be reimplemented in the objects class." |
|
3455 |
||
3456 |
|size "{ Class: SmallInteger }" |
|
3457 |
instvarArray| |
|
3458 |
||
3459 |
stream next == 1 ifTrue:[ |
|
3460 |
"/ |
|
3461 |
"/ special representation ... |
|
3462 |
"/ |
|
3463 |
instvarArray := Array new:(size := stream nextNumber:3). |
|
3464 |
1 to:size do:[:i | |
|
3465 |
instvarArray basicAt:i put:(manager nextObject) |
|
3466 |
]. |
|
3467 |
self readBinaryContentsFromData:instvarArray manager:manager. |
|
3468 |
^ self |
|
39 | 3469 |
]. |
343 | 3470 |
|
3471 |
"/ |
|
3472 |
"/ standard representation |
|
3473 |
"/ |
|
39 | 3474 |
size := self basicSize. |
44 | 3475 |
size ~~ 0 ifTrue:[ |
159 | 3476 |
self class isPointers ifTrue:[ |
3477 |
1 to:size do:[:i | |
|
3478 |
self basicAt:i put:(manager nextObject) |
|
3479 |
] |
|
3480 |
] |
|
343 | 3481 |
]. |
3482 |
size := self class instSize. |
|
3483 |
1 to:size do:[:i | |
|
3484 |
self instVarAt:i put:(manager nextObject) |
|
3485 |
]. |
|
2 | 3486 |
! |
3487 |
||
343 | 3488 |
storeBinaryContentsOn:stream manager:manager |
3489 |
"store the receivers instance variables in a binary representation |
|
3490 |
on a stream using manager. |
|
3491 |
This is a general implementation, walking over instances |
|
3492 |
and storing each recursively using manager. |
|
3493 |
||
3494 |
Notice, that the objects definition and bit-instances (bytes, words etc.) |
|
3495 |
are already stored. |
|
3496 |
Here, we only have to deal with indexed-pointer and named instance variables. |
|
3497 |
||
3498 |
Also notice: this method is not called for if a private representation |
|
3499 |
has been stored (see representBinaryOn:). |
|
3500 |
In that case, #storeBinaryContentsFromData:manager: is called." |
|
3501 |
||
3502 |
|size "{ Class: SmallInteger }"| |
|
3503 |
||
3504 |
size := self basicSize. |
|
3505 |
size ~~ 0 ifTrue:[ |
|
3506 |
self class isPointers ifTrue:[ |
|
3507 |
1 to:size do:[:i | |
|
3508 |
manager putIdOf:(self basicAt:i) on:stream |
|
3509 |
]. |
|
3510 |
]. |
|
3511 |
]. |
|
3512 |
size := self class instSize. |
|
3513 |
1 to:size do:[:i | |
|
3514 |
manager putIdOf:(self instVarAt:i) on:stream |
|
3515 |
]. |
|
3516 |
! |
|
3517 |
||
3518 |
storeBinaryDefinitionOn:stream manager:manager |
|
39 | 3519 |
"append a binary representation of the receiver onto stream. |
159 | 3520 |
This method first stores the class, then the body, which is done |
3521 |
in a separate method to allow redefinition of the bodies format. |
|
324 | 3522 |
Can be redefined in subclasses to write more compact representations |
3523 |
(see String, SmallInteger etc)." |
|
159 | 3524 |
|
343 | 3525 |
manager putIdOfClass:(self class) on:stream. |
159 | 3526 |
self storeBinaryDefinitionBodyOn:stream manager:manager |
3527 |
! |
|
3528 |
||
343 | 3529 |
storeBinaryDefinitionBodyOn:stream manager:manager |
159 | 3530 |
"append a binary representation of the receivers body onto stream. |
39 | 3531 |
This is a general implementation walking over instances storing |
3532 |
each recursively as an ID using manager. |
|
159 | 3533 |
Can be redefined in subclasses." |
39 | 3534 |
|
3535 |
|basicSize "{ Class: SmallInteger }" |
|
179 | 3536 |
instSize "{ Class: SmallInteger }" |
446 | 3537 |
myClass specialRep pointers| |
179 | 3538 |
|
3539 |
myClass := self class. |
|
3540 |
instSize := myClass instSize. |
|
343 | 3541 |
|
446 | 3542 |
(pointers := myClass isPointers) ifTrue:[ |
343 | 3543 |
"/ |
3544 |
"/ inst size not needed - if you uncomment the line below, |
|
3545 |
"/ also uncomment the corresponding line in |
|
3546 |
"/ Object>>binaryDefinitionFrom:manager: |
|
3547 |
"/ |
|
3548 |
"/ stream nextPut:instSize. "mhmh this limits us to 255 named instvars" |
|
159 | 3549 |
|
179 | 3550 |
myClass isVariable ifTrue:[ |
159 | 3551 |
stream nextNumber:3 put:(basicSize := self basicSize) |
3552 |
] ifFalse:[ |
|
3553 |
basicSize := 0 |
|
3554 |
]. |
|
39 | 3555 |
] ifFalse: [ |
159 | 3556 |
stream nextNumber:4 put:(basicSize := self basicSize). |
179 | 3557 |
myClass isBytes ifTrue:[ |
159 | 3558 |
1 to:basicSize do:[:i | |
3559 |
stream nextPut:(self basicAt:i) |
|
3560 |
] |
|
3561 |
] ifFalse:[ |
|
179 | 3562 |
myClass isWords ifTrue:[ |
159 | 3563 |
1 to:basicSize do:[:i | |
343 | 3564 |
stream nextNumber:2 put:(self basicAt: i) |
159 | 3565 |
] |
3566 |
] ifFalse:[ |
|
179 | 3567 |
myClass isLongs ifTrue:[ |
159 | 3568 |
1 to:basicSize do:[:i | |
343 | 3569 |
stream nextNumber:4 put:(self basicAt: i) |
159 | 3570 |
] |
3571 |
] ifFalse:[ |
|
179 | 3572 |
myClass isFloats ifTrue:[ |
159 | 3573 |
"could do it in one big write on machines which use IEEE floats ..." |
3574 |
1 to:basicSize do:[:i | |
|
3575 |
Float storeBinaryIEEESingle:(self basicAt:i) on:stream |
|
3576 |
] |
|
3577 |
] ifFalse:[ |
|
179 | 3578 |
myClass isDoubles ifTrue:[ |
159 | 3579 |
"could do it in one big write on machines which use IEEE doubles ..." |
3580 |
1 to:basicSize do:[:i | |
|
3581 |
Float storeBinaryIEEEDouble:(self basicAt:i) on:stream |
|
3582 |
] |
|
3583 |
] ifFalse:[ |
|
343 | 3584 |
"/ should never be reached ... |
159 | 3585 |
1 to:basicSize do:[:i | |
343 | 3586 |
manager putIdOf:(self basicAt:i) on:stream |
159 | 3587 |
] |
3588 |
] |
|
3589 |
] |
|
3590 |
] |
|
3591 |
] |
|
3592 |
]. |
|
343 | 3593 |
]. |
3594 |
||
446 | 3595 |
(pointers or:[instSize ~~ 0]) ifTrue:[ |
3596 |
specialRep := self representBinaryOn:manager. |
|
3597 |
specialRep notNil ifTrue:[ |
|
3598 |
stream nextPut:1. "/ means: private representation follows |
|
3599 |
stream nextNumber:3 put:(specialRep basicSize). |
|
3600 |
self storeBinaryContentsFromData:specialRep on:stream manager:manager |
|
3601 |
] ifFalse:[ |
|
3602 |
stream nextPut:0. "/ means: full representation follows |
|
3603 |
self storeBinaryContentsOn:stream manager:manager |
|
3604 |
] |
|
39 | 3605 |
] |
446 | 3606 |
|
3607 |
"Modified: 25.10.1995 / 14:00:51 / cg" |
|
2 | 3608 |
! |
3609 |
||
159 | 3610 |
storeBinaryOn:stream manager:manager |
39 | 3611 |
"append a binary representation of the receiver onto stream." |
3612 |
||
3613 |
manager putIdOf:self on:stream |
|
2 | 3614 |
! ! |
3615 |
||
1 | 3616 |
!Object methodsFor:'printing & storing'! |
3617 |
||
3618 |
className |
|
3619 |
"return the classname of the receivers class" |
|
3620 |
||
3621 |
^ self class name |
|
56 | 3622 |
|
293 | 3623 |
" |
3624 |
1 className |
|
3625 |
1 class className 'this may change ...' |
|
3626 |
$a className |
|
3627 |
$a class className 'this may change ...' |
|
3628 |
" |
|
1 | 3629 |
! |
3630 |
||
3631 |
classNameWithArticle |
|
71 | 3632 |
"return a string consisting of classname preceeded by an article. |
3633 |
(dont expect me to write national variants for this ... :-) |
|
3634 |
If you have special preferences, redefine it ..." |
|
1 | 3635 |
|
85 | 3636 |
|classname| |
1 | 3637 |
|
293 | 3638 |
classname := self class displayString. |
85 | 3639 |
^ classname article , ' ' , classname |
56 | 3640 |
|
293 | 3641 |
" |
3642 |
1 classNameWithArticle |
|
3643 |
(1->2) classNameWithArticle |
|
3644 |
XWorkstation basicNew classNameWithArticle |
|
3645 |
" |
|
1 | 3646 |
! |
3647 |
||
3648 |
printOn:aStream |
|
71 | 3649 |
"print the receiver on the argument-stream. |
3650 |
The default here is to output the receivers class name. |
|
3651 |
BUT: this method is heavily redefined for objects which |
|
3652 |
can print prettier." |
|
3653 |
||
56 | 3654 |
aStream nextPutAll:self classNameWithArticle |
3655 |
! |
|
3656 |
||
3657 |
||
3658 |
"print the receiver on the standard output stream" |
|
3659 |
||
3660 |
self printOn:Stdout |
|
3661 |
! |
|
3662 |
||
3663 |
printNewline |
|
3664 |
"print the receiver followed by a cr on the standard output stream" |
|
3665 |
||
3666 |
self printOn:Stdout. |
|
3667 |
Stdout cr |
|
1 | 3668 |
! |
3669 |
||
71 | 3670 |
printNL |
3671 |
"print the receiver followed by a cr on the standard output stream |
|
3672 |
- for GNU Smalltalk compatibility" |
|
3673 |
||
3674 |
^ self printNewline |
|
3675 |
! |
|
3676 |
||
356 | 3677 |
infoPrint |
3678 |
"print the receiver on the standard error stream. |
|
3679 |
This is meant for information messages which are not warnings |
|
3680 |
or fatal messages. |
|
3681 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
3682 |
||
3683 |
InfoPrinting ifTrue:[ |
|
3684 |
self printOn:Stderr |
|
3685 |
] |
|
3686 |
! |
|
3687 |
||
3688 |
infoPrintNL |
|
3689 |
"print the receiver followed by a cr on the standard error stream. |
|
3690 |
This is meant for information messages which are not warnings |
|
3691 |
or fatal messages. |
|
3692 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
3693 |
||
3694 |
InfoPrinting ifTrue:[ |
|
3695 |
self errorPrintNewline |
|
3696 |
] |
|
3697 |
! |
|
3698 |
||
71 | 3699 |
errorPrint |
3700 |
"print the receiver on the standard error stream." |
|
3701 |
||
3702 |
self printOn:Stderr |
|
3703 |
! |
|
3704 |
||
3705 |
errorPrintNewline |
|
3706 |
"print the receiver followed by a cr on the standard error stream" |
|
3707 |
||
3708 |
self printOn:Stderr. |
|
3709 |
Stderr cr |
|
3710 |
! |
|
3711 |
||
3712 |
errorPrintNL |
|
3713 |
"print the receiver followed by a cr on the standard error stream" |
|
3714 |
||
3715 |
^ self errorPrintNewline |
|
3716 |
! |
|
3717 |
||
3718 |
printString |
|
3719 |
"return a string for printing the receiver. |
|
3720 |
Since we now use printOn: as the basic print mechanism, |
|
3721 |
we have to create a stream and print into it." |
|
3722 |
||
3723 |
|s| |
|
3724 |
||
3725 |
s := WriteStream on:(String new:30). |
|
3726 |
self printOn:s. |
|
3727 |
^ s contents |
|
3728 |
! |
|
3729 |
||
369 | 3730 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
3731 |
"return a printed representation of the receiver, |
|
3732 |
padded with padCharacter (at the right) up to size. |
|
3733 |
If the resulting printString is too large, |
|
3734 |
return the result from evaluating alternative." |
|
3735 |
||
3736 |
|s| |
|
3737 |
||
3738 |
s := self printString. |
|
3739 |
s size > size ifTrue:[^ alternative value]. |
|
3740 |
^ s paddedTo:size with:padCharacter |
|
3741 |
||
3742 |
" |
|
3743 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
3744 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
3745 |
" |
|
3746 |
! |
|
3747 |
||
2 | 3748 |
printStringPaddedTo:size with:padCharacter |
56 | 3749 |
"return a printed representation of the receiver, |
369 | 3750 |
padded with padCharacter (at the right) up to size. |
3751 |
If the printString is longer than size, |
|
3752 |
it is returned unchanged (i.e. not truncated)" |
|
1 | 3753 |
|
71 | 3754 |
^ (self printString) paddedTo:size with:padCharacter |
2 | 3755 |
|
293 | 3756 |
" |
369 | 3757 |
123 printStringPaddedTo:10 with:$. |
3758 |
123 printStringPaddedTo:10 with:$* |
|
3759 |
123 printStringPaddedTo:3 with:$* |
|
3760 |
1234 printStringPaddedTo:3 with:$* |
|
293 | 3761 |
" |
13 | 3762 |
! |
3763 |
||
3764 |
printStringPaddedTo:size |
|
56 | 3765 |
"return a printed representation of the receiver, |
369 | 3766 |
padded with spaces (at the right) up to size. |
293 | 3767 |
If the printString is longer than size, |
3768 |
it is returned unchanged (i.e. not truncated)" |
|
13 | 3769 |
|
3770 |
^ self printStringPaddedTo:size with:(Character space) |
|
3771 |
||
293 | 3772 |
" |
3773 |
123 printStringPaddedTo:10 |
|
3774 |
1234567890123456 printStringPaddedTo:10 |
|
3775 |
'hello' printStringPaddedTo:10 |
|
3776 |
" |
|
2 | 3777 |
! |
3778 |
||
369 | 3779 |
printStringPaddedTo:size ifLarger:alternative |
3780 |
"return a printed representation of the receiver, |
|
3781 |
padded with spaces (at the right) up to size. |
|
3782 |
If the resulting printString is too large, |
|
3783 |
return the result from evaluating alternative." |
|
3784 |
||
3785 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
3786 |
||
3787 |
" |
|
3788 |
12 printStringPaddedTo:3 ifLarger:['***'] |
|
3789 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
3790 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
3791 |
" |
|
3792 |
! |
|
3793 |
||
2 | 3794 |
printStringZeroPaddedTo:size |
71 | 3795 |
"return a printed representation of the receiver, |
369 | 3796 |
padded with zero (at the right) characters up to size. |
13 | 3797 |
Usually used with float numbers." |
2 | 3798 |
|
3799 |
^ self printStringPaddedTo:size with:$0 |
|
13 | 3800 |
|
293 | 3801 |
" |
3802 |
123.0 printStringZeroPaddedTo:10 |
|
3803 |
" |
|
2 | 3804 |
! |
3805 |
||
369 | 3806 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
3807 |
"return my printString as a right-adjusted string of length size; |
|
3808 |
characters on the left are filled with padCharacter. |
|
3809 |
If the printString is larger than size, |
|
3810 |
return the result from evaluating alternative." |
|
3811 |
||
3812 |
|s| |
|
3813 |
||
3814 |
s := self printString. |
|
3815 |
s size > size ifTrue:[^ alternative value]. |
|
3816 |
^ s leftPaddedTo:size with:padCharacter |
|
3817 |
||
3818 |
" |
|
3819 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
3820 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
3821 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
3822 |
" |
|
3823 |
! |
|
3824 |
||
2 | 3825 |
printStringLeftPaddedTo:size with:padCharacter |
3826 |
"return my printString as a right-adjusted string of length size; |
|
369 | 3827 |
characters on the left are filled with padCharacter. |
3828 |
If the printString is longer than size, |
|
3829 |
it is returned unchanged (i.e. not truncated)" |
|
2 | 3830 |
|
71 | 3831 |
^ (self printString) leftPaddedTo:size with:padCharacter |
13 | 3832 |
|
293 | 3833 |
" |
3834 |
123 printStringLeftPaddedTo:10 with:$. |
|
3835 |
1 printStringLeftPaddedTo:10 with:$. |
|
3836 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
|
3837 |
" |
|
1 | 3838 |
! |
3839 |
||
369 | 3840 |
printStringLeftPaddedTo:size ifLarger:alternative |
3841 |
"return my printString as a right-adjusted string of length size; |
|
3842 |
characters on the left are filled with spaces. |
|
3843 |
If the printString is larger than size, |
|
3844 |
return the result from evaluating alternative." |
|
3845 |
||
3846 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
3847 |
||
3848 |
" |
|
3849 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
3850 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
3851 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
3852 |
" |
|
3853 |
! |
|
3854 |
||
2 | 3855 |
printStringLeftPaddedTo:size |
3856 |
"return my printString as a right-adjusted string of length size; |
|
369 | 3857 |
characters on the left are filled with spaces. |
3858 |
If the printString is longer than size, |
|
3859 |
it is returned unchanged (i.e. not truncated)" |
|
2 | 3860 |
|
3861 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
13 | 3862 |
|
293 | 3863 |
" |
3864 |
10 printStringLeftPaddedTo:10 |
|
3865 |
1 printStringLeftPaddedTo:10 |
|
3866 |
" |
|
2 | 3867 |
! |
3868 |
||
71 | 3869 |
printOn:aStream paddedTo:size with:padCharacter |
3870 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
3871 |
||
3872 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
3873 |
||
293 | 3874 |
" |
3875 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
3876 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
3877 |
" |
|
71 | 3878 |
! |
3879 |
||
3880 |
printOn:aStream zeroPaddedTo:size |
|
3881 |
"print the receiver on aStream, padding with zeros up to size. |
|
3882 |
Usually used with float numbers." |
|
3883 |
||
3884 |
self printOn:aStream paddedTo:size with:$0. |
|
3885 |
||
293 | 3886 |
" |
3887 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
3888 |
" |
|
71 | 3889 |
! |
3890 |
||
3891 |
printOn:aStream paddedTo:size |
|
3892 |
"print the receiver on aStream, padding with spaces up to size." |
|
3893 |
||
3894 |
self printOn:aStream paddedTo:size with:(Character space) |
|
3895 |
||
293 | 3896 |
" |
3897 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
3898 |
" |
|
71 | 3899 |
! |
3900 |
||
2 | 3901 |
printOn:aStream leftPaddedTo:size with:padCharacter |
3902 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
3903 |
padding is done on the left." |
|
3904 |
||
3905 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
56 | 3906 |
|
293 | 3907 |
" |
3908 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
3909 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
3910 |
" |
|
2 | 3911 |
! |
1 | 3912 |
|
2 | 3913 |
printOn:aStream leftPaddedTo:size |
3914 |
"print the receiver on aStream, padding with spaces up to size. |
|
3915 |
padding is done on the left." |
|
3916 |
||
71 | 3917 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
56 | 3918 |
|
293 | 3919 |
" |
3920 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
3921 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
3922 |
" |
|
2 | 3923 |
! |
3924 |
||
3925 |
printStringRightAdjustLen:size |
|
56 | 3926 |
"obsolete - just a name confusion. |
3927 |
This method will go away ..." |
|
2 | 3928 |
|
3929 |
^ self printStringLeftPaddedTo:size |
|
3930 |
! |
|
3931 |
||
3932 |
printRightAdjustLen:size |
|
56 | 3933 |
"obsolete - just a name confusion. |
3934 |
This method will go away ..." |
|
2 | 3935 |
|
3936 |
(self printStringLeftPaddedTo:size) printOn:Stdout |
|
3937 |
! |
|
3938 |
||
1 | 3939 |
displayString |
71 | 3940 |
"return a string used when displaying the receiver in a view; |
56 | 3941 |
for example an Inspector. This is usually the same as printString, |
293 | 3942 |
but sometimes redefined for a better look." |
1 | 3943 |
|
3944 |
^ self printString |
|
293 | 3945 |
|
3946 |
" |
|
3947 |
#(1 2 3) printString |
|
3948 |
#(1 2 3) displayString |
|
3949 |
#(1 2 3) storeString |
|
3950 |
" |
|
1 | 3951 |
! |
3952 |
||
308 | 3953 |
displayOn:aGc x:x y:y |
3954 |
"display the receiver in a graphicsContext - this method allows |
|
3955 |
for any object to be displayed in a ListView - for example." |
|
3956 |
||
3957 |
^ aGc displayString:(self displayString) x:x y:y. |
|
3958 |
! |
|
3959 |
||
460
7e058858cc3b
New Method: displayOn:aGc at:aPoint (ST80-compatibility).
Stefan Vogel <sv@exept.de>
parents:
446
diff
changeset
|
3960 |
displayOn:aGc at:aPoint |
7e058858cc3b
New Method: displayOn:aGc at:aPoint (ST80-compatibility).
Stefan Vogel <sv@exept.de>
parents:
446
diff
changeset
|
3961 |
"ST-80 Compatibility |
7e058858cc3b
New Method: displayOn:aGc at:aPoint (ST80-compatibility).
Stefan Vogel <sv@exept.de>
parents:
446
diff
changeset
|
3962 |
display the receiver in a graphicsContext - this method allows |
7e058858cc3b
New Method: displayOn:aGc at:aPoint (ST80-compatibility).
Stefan Vogel <sv@exept.de>
parents:
446
diff
changeset
|
3963 |
for any object to be displayed in a ListView - for example." |
7e058858cc3b
New Method: displayOn:aGc at:aPoint (ST80-compatibility).
Stefan Vogel <sv@exept.de>
parents:
446
diff
changeset
|
3964 |
|
7e058858cc3b
New Method: displayOn:aGc at:aPoint (ST80-compatibility).
Stefan Vogel <sv@exept.de>
parents:
446
diff
changeset
|
3965 |
^ self displayOn:aGc x:(aPoint x) y:(aPoint y). |
7e058858cc3b
New Method: displayOn:aGc at:aPoint (ST80-compatibility).
Stefan Vogel <sv@exept.de>
parents:
446
diff
changeset
|
3966 |
! |
7e058858cc3b
New Method: displayOn:aGc at:aPoint (ST80-compatibility).
Stefan Vogel <sv@exept.de>
parents:
446
diff
changeset
|
3967 |
|
56 | 3968 |
storeOn:aStream |
3969 |
"store the receiver on aStream; i.e. print an expression which will |
|
293 | 3970 |
reconstruct the receiver. |
3971 |
Notice, that no self referencing or cyclic objects can be represented |
|
3972 |
in this format. |
|
3973 |
Use storeBinaryOn:, which handles these cases correctly." |
|
56 | 3974 |
|
3975 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
1 | 3976 |
|
25 | 3977 |
thisContext isRecursive ifTrue:[ |
159 | 3978 |
Transcript showCr:'Error: storeString of self referencing object.'. |
3979 |
aStream nextPutAll:'#("recursive")'. |
|
3980 |
^ self |
|
25 | 3981 |
]. |
56 | 3982 |
|
1 | 3983 |
myClass := self class. |
56 | 3984 |
aStream nextPut:$(. |
3985 |
aStream nextPutAll:self class name. |
|
3986 |
||
1 | 3987 |
hasSemi := false. |
3988 |
myClass isVariable ifTrue:[ |
|
159 | 3989 |
aStream nextPutAll:' basicNew:'. |
3990 |
self basicSize printOn:aStream |
|
1 | 3991 |
] ifFalse:[ |
159 | 3992 |
aStream nextPutAll:' basicNew' |
1 | 3993 |
]. |
56 | 3994 |
|
1 | 3995 |
sz := myClass instSize. |
3996 |
1 to:sz do:[:i | |
|
159 | 3997 |
aStream nextPutAll:' instVarAt:'. |
3998 |
i printOn:aStream. |
|
3999 |
aStream nextPutAll:' put:'. |
|
4000 |
(self instVarAt:i) storeOn:aStream. |
|
4001 |
aStream nextPut:$;. |
|
4002 |
hasSemi := true |
|
1 | 4003 |
]. |
4004 |
myClass isVariable ifTrue:[ |
|
159 | 4005 |
sz := self basicSize. |
4006 |
1 to:sz do:[:i | |
|
4007 |
aStream nextPutAll:' basicAt:'. |
|
4008 |
i printOn:aStream. |
|
4009 |
aStream nextPutAll:' put:'. |
|
4010 |
(self basicAt:i) storeOn:aStream. |
|
4011 |
aStream nextPut:$;. |
|
4012 |
hasSemi := true |
|
4013 |
] |
|
1 | 4014 |
]. |
4015 |
hasSemi ifTrue:[ |
|
159 | 4016 |
aStream nextPutAll:' yourself' |
1 | 4017 |
]. |
56 | 4018 |
aStream nextPut:$). |
293 | 4019 |
|
4020 |
" |
|
4021 |
|s| |
|
4022 |
||
4023 |
s := WriteStream on:(String new). |
|
4024 |
('hello' -> 'world') storeOn:s. |
|
4025 |
s := ReadStream on:(s contents). |
|
4026 |
(Object readFrom:s) inspect |
|
4027 |
" |
|
4028 |
" |
|
4029 |
|s| |
|
4030 |
||
4031 |
s := 'data' asFilename writeStream. |
|
4032 |
('hello' -> 'world') storeOn:s. |
|
4033 |
s close. |
|
4034 |
||
4035 |
s := 'data' asFilename readStream. |
|
4036 |
(Object readFrom:s) inspect |
|
4037 |
" |
|
4038 |
||
4039 |
"does not work example:" |
|
4040 |
" |
|
4041 |
|s a| |
|
4042 |
||
4043 |
a := Array new:2. |
|
4044 |
a at:1 put:a. |
|
4045 |
||
4046 |
s := 'data' asFilename writeStream. |
|
4047 |
a storeOn:s. |
|
4048 |
s close. |
|
4049 |
||
4050 |
s := 'data' asFilename readStream. |
|
4051 |
(Object readFrom:s) inspect |
|
4052 |
" |
|
1 | 4053 |
! |
4054 |
||
56 | 4055 |
storeString |
293 | 4056 |
"return a string representing an expression to reconstruct the receiver. |
4057 |
Notice, that no self referencing or cyclic objects can be represented |
|
4058 |
in this format. |
|
4059 |
Use storeBinaryOn:, which handles these cases correctly." |
|
56 | 4060 |
|
4061 |
|s| |
|
4062 |
||
4063 |
s := WriteStream on:(String new:50). |
|
4064 |
self storeOn:s. |
|
4065 |
^ s contents |
|
1 | 4066 |
! |
4067 |
||
4068 |
store |
|
71 | 4069 |
"store the receiver on standard output. |
4070 |
this method is useless, but included for compatibility." |
|
1 | 4071 |
|
4072 |
self storeOn:Stdout |
|
4073 |
! |
|
4074 |
||
4075 |
storeNl |
|
71 | 4076 |
"store the receiver on standard output; append a newline. |
4077 |
this method is useless, but included for compatibility." |
|
1 | 4078 |
|
4079 |
self store. |
|
4080 |
Character nl print |
|
4081 |
! ! |