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