author | Stefan Vogel <sv@exept.de> |
Wed, 14 May 2003 14:17:44 +0200 | |
changeset 7285 | 76ff65cdd7e7 |
parent 7266 | f2b64d3b43cf |
child 7303 | 98111fb6a285 |
permissions | -rw-r--r-- |
5755 | 1 |
" |
2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
6654 | 3 |
All Rights Reserved |
5755 | 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 |
"{ Package: 'stx:libbasic' }" |
|
14 |
||
15 |
nil subclass:#Object |
|
6697 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'ErrorSignal HaltSignal MessageNotUnderstoodSignal |
|
18 |
UserInterruptSignal RecursionInterruptSignal |
|
19 |
ExceptionInterruptSignal SubscriptOutOfBoundsSignal |
|
20 |
IndexNotFoundSignal NonIntegerIndexSignal NotFoundSignal |
|
21 |
KeyNotFoundSignal ElementOutOfBoundsSignal UserNotificationSignal |
|
22 |
InformationSignal WarningSignal PrimitiveFailureSignal |
|
23 |
DeepCopyErrorSignal AbortSignal ErrorRecursion Dependencies |
|
24 |
InfoPrinting ActivityNotificationSignal InternalErrorSignal |
|
25 |
NonWeakDependencies SynchronizationSemaphores ObjectAttributes |
|
26 |
OSSignalInterruptSignal FinalizationLobby |
|
27 |
RecursiveStoreStringSignal AbortAllSignal' |
|
28 |
poolDictionaries:'' |
|
29 |
category:'Kernel-Objects' |
|
5755 | 30 |
! |
31 |
||
32 |
!Object class methodsFor:'documentation'! |
|
3023
674376809496
general listView support (#displayOn / widthOn / heightOn)
ca
parents:
3010
diff
changeset
|
33 |
|
5754 | 34 |
copyright |
5755 | 35 |
" |
36 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
6654 | 37 |
All Rights Reserved |
5755 | 38 |
|
39 |
This software is furnished under a license and may be used |
|
40 |
only in accordance with the terms of that license and with the |
|
41 |
inclusion of the above copyright notice. This software may not |
|
42 |
be provided or otherwise made available to, or used by, any |
|
43 |
other person. No title to or ownership of the software is |
|
44 |
hereby transferred. |
|
45 |
" |
|
46 |
! |
|
47 |
||
48 |
dependencies |
|
49 |
" |
|
50 |
ST/X dependencies are slightly modified from ST-80's |
|
51 |
(we think they are better ;-). |
|
52 |
||
53 |
One problem occuring very often in ST-80 is that some object |
|
54 |
cannot be garbage collected because some dependency is present, |
|
55 |
having the object as a dependent of some other object. |
|
56 |
In ST-80, this association remains alive (because a Dictionary |
|
57 |
is used to hold dependents) - even if no other references exist to |
|
58 |
to dependent or the dependee. |
|
59 |
||
60 |
This means, that in ST-80, a #release is mandatory in order to |
|
61 |
prevent memory leaks. |
|
62 |
We think, that this is a bad solution, since after all, exactly that |
|
63 |
kind of work should be performed by a garbage collector - you should not |
|
64 |
need to care about dependencies. |
|
65 |
From a philosophical point of view, why should some object depend on |
|
66 |
something that the programmer considers a dead object ? |
|
67 |
(well - worse than that: it seems that some ST-80 code even depends on |
|
68 |
that behavior) |
|
69 |
||
70 |
In order to limit the trouble, ST-80 reimplemented the way dependents |
|
71 |
are stored in the model class - this one keeps the dependents locally, |
|
72 |
so these dependents go away, once the model is reclaimed. |
|
73 |
That may make things even more confusing: with models, no #release is |
|
74 |
needed, with general objects it is mandatory. |
|
75 |
||
76 |
||
77 |
In ST/X, dependencies are implemented using a WeakDictionary; this means, |
|
78 |
that once the dependee dies, the dependency association is removed automatically, |
|
79 |
and the dependent can be reclaimed by the garbage collector, if no other |
|
80 |
references exist to the dependent. |
|
81 |
In order to (at least) provide a mechanism for the old behavior |
|
82 |
(in case your application heavily depends on the ST-80 mechanism), complementary |
|
83 |
protocol to add nonWeak dependencies is provided |
|
84 |
(see #addNonWeakDependent / #removeNonWeakDependent). |
|
85 |
||
86 |
||
87 |
Caveat: |
|
88 |
since interests are implemented using InterestConverter (which are simply |
|
89 |
forwarding messages), these must use the nonWeak mechanism (as done in ST-80 |
|
90 |
automatically). |
|
91 |
The reason is that there are usually no direct references to the converters, |
|
92 |
and those would be reclaimed if stored in a weakDictionary. |
|
93 |
This means, that those interests MUST be removed with #retractInterest |
|
94 |
(which is bug-compatible to ST-80). |
|
95 |
We rewrite things to provide a more convenient mechanism in the future ... |
|
96 |
||
97 |
||
98 |
I like to hear comments on the above - do you think its better ? |
|
99 |
" |
|
100 |
! |
|
101 |
||
102 |
documentation |
|
103 |
" |
|
104 |
Object is the superclass of most other classes. |
|
105 |
(except for nil-subclasses, which inherit nothing, |
|
106 |
to catch any message into their #doesNotUnderstand: method) |
|
107 |
||
108 |
Protocol which is common to every object is defined here. |
|
109 |
Also some utility stuff (like notify) and error handling is implemented here. |
|
110 |
||
111 |
Object has no instance variables (and may not get any added). One reason is, that |
|
112 |
UndefinedObject and SmallInteger are also inheriting from Object - these two cannot |
|
113 |
have instance variables (due to their implementation). |
|
114 |
The other reason is that the runtime system (VM) knows about the layout of some built-in |
|
115 |
classes (think of Class, Method, Block and also Integer or Float). |
|
116 |
If you were allowed to add instance variables to Object, the VM had to be recompiled |
|
117 |
(and also rewritten in some places). |
|
118 |
||
119 |
[Class variables:] |
|
120 |
||
6654 | 121 |
ErrorSignal <Signal> Signal raised for error/error: messages |
122 |
also, parent of all other signals. |
|
123 |
||
124 |
HaltSignal <Signal> Signal raised for halt/halt: messages |
|
125 |
||
126 |
MessageNotUnderstoodSignal Signals raised for various error conditions |
|
127 |
UserInterruptSignal |
|
128 |
RecursionInterruptSignal |
|
129 |
ExceptionInterruptSignal |
|
130 |
SubscriptOutOfBoundsSignal |
|
131 |
NonIntegerIndexSignal |
|
132 |
NotFoundSignal |
|
133 |
KeyNotFoundSignal |
|
134 |
ElementOutOfBoundsSignal |
|
135 |
InformationSignal |
|
136 |
WarningSignal |
|
137 |
DeepCopyErrorSignal |
|
138 |
InternalErrorSignal |
|
139 |
||
140 |
AbortSignal <Signal> Signal raised by debugger, to abort a computation |
|
141 |
BUT, the debugger will only raise it if it is handled. |
|
142 |
By handling the abortSignal, you can control where the |
|
143 |
debuggers abort-function resumes execution in case of |
|
144 |
an error. |
|
145 |
||
146 |
ErrorRecursion <Boolean> controls behavior when recursive errors occur (i.e. |
|
147 |
an error while handling an error). |
|
148 |
||
149 |
Dependencies <WeakDependencyDictionary> |
|
150 |
keeps track of object dependencies. |
|
151 |
||
152 |
InfoPrinting <Boolean> controls weather informational messages |
|
153 |
are printed. |
|
154 |
||
155 |
ActivityNotificationSignal <QuerySignal> |
|
156 |
raised on #activityNotification: |
|
157 |
||
158 |
NonWeakDependencies <Dictionary> keeps track of object dependencies. |
|
159 |
Dependents stay alive. |
|
160 |
||
161 |
SynchronizationSemaphores <WeakIdentityDictionary> |
|
162 |
Semaphores for per-object-monitor. |
|
5755 | 163 |
|
164 |
||
165 |
[author:] |
|
6654 | 166 |
Claus Gittinger |
5755 | 167 |
|
168 |
" |
|
169 |
! ! |
|
170 |
||
171 |
!Object class methodsFor:'initialization'! |
|
172 |
||
5971 | 173 |
initSignals |
174 |
"called only once - initialize signals" |
|
175 |
||
176 |
ErrorSignal := Error. |
|
177 |
||
178 |
ControlInterrupt notifierString:'control interrupted'. |
|
179 |
||
180 |
"/ HaltSignal := ControlInterrupt newSignalMayProceed:true. |
|
181 |
"/ HaltSignal nameClass:self message:#haltSignal. |
|
182 |
HaltSignal := HaltInterrupt. |
|
183 |
HaltSignal notifierString:'halt encountered'. |
|
184 |
||
5977 | 185 |
"/ MessageNotUnderstoodSignal := ErrorSignal newSignalMayProceed:true. |
186 |
"/ MessageNotUnderstoodSignal nameClass:self message:#messageNotUnderstoodSignal. |
|
187 |
MessageNotUnderstoodSignal := MessageNotUnderstood. |
|
5971 | 188 |
MessageNotUnderstoodSignal notifierString:'message not understood'. |
189 |
||
6000 | 190 |
"/ PrimitiveFailureSignal := ErrorSignal newSignalMayProceed:true. |
191 |
"/ PrimitiveFailureSignal nameClass:self message:#primitiveFailureSignal. |
|
192 |
PrimitiveFailureSignal := PrimitiveFailure. |
|
5971 | 193 |
PrimitiveFailureSignal notifierString:'primitive failed'. |
194 |
||
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
195 |
InternalErrorSignal := ErrorSignal newSignal. |
5971 | 196 |
InternalErrorSignal nameClass:self message:#internalErrorSignal. |
197 |
InternalErrorSignal notifierString:'VM internal error: '. |
|
198 |
||
199 |
"/ UserInterruptSignal := (Signal new) mayProceed:true. |
|
200 |
"/ UserInterruptSignal := ControlInterrupt newSignalMayProceed:true. |
|
201 |
"/ UserInterruptSignal nameClass:self message:#userInterruptSignal. |
|
202 |
UserInterruptSignal := UserInterrupt. |
|
203 |
UserInterruptSignal notifierString:'user Interrupt'. |
|
204 |
||
205 |
"/ RecursionInterruptSignal := ErrorSignal newSignalMayProceed:false. |
|
6146 | 206 |
"/ RecursionInterruptSignal := (Signal new) mayProceed:true. |
207 |
"/ RecursionInterruptSignal nameClass:self message:#recursionInterruptSignal. |
|
208 |
RecursionInterruptSignal := RecursionError. |
|
5971 | 209 |
RecursionInterruptSignal notifierString:'recursion limit reached'. |
210 |
||
211 |
ExceptionInterruptSignal := ErrorSignal newSignalMayProceed:true. |
|
212 |
ExceptionInterruptSignal nameClass:self message:#exceptionInterruptSignal. |
|
213 |
ExceptionInterruptSignal notifierString:'exception Interrupt'. |
|
214 |
||
5977 | 215 |
"/ NotFoundSignal := ErrorSignal newSignalMayProceed:true. |
216 |
"/ NotFoundSignal nameClass:self message:#notFoundSignal. |
|
217 |
NotFoundSignal := NotFoundError. |
|
5971 | 218 |
NotFoundSignal notifierString:'no such element'. |
219 |
||
5977 | 220 |
"/ IndexNotFoundSignal := NotFoundSignal newSignalMayProceed:true. |
221 |
"/ IndexNotFoundSignal nameClass:self message:#indexNotFoundSignal. |
|
222 |
IndexNotFoundSignal := IndexNotFoundError. |
|
5971 | 223 |
IndexNotFoundSignal notifierString:'bad index: '. |
224 |
||
5977 | 225 |
"/ SubscriptOutOfBoundsSignal := IndexNotFoundSignal newSignalMayProceed:true. |
226 |
"/ SubscriptOutOfBoundsSignal nameClass:self message:#subscriptOutOfBoundsSignal. |
|
227 |
SubscriptOutOfBoundsSignal := SubscriptOutOfBoundsError. |
|
5971 | 228 |
SubscriptOutOfBoundsSignal notifierString:'subscript out of bounds: '. |
229 |
||
5977 | 230 |
"/ NonIntegerIndexSignal := IndexNotFoundSignal newSignalMayProceed:true. |
231 |
"/ NonIntegerIndexSignal nameClass:self message:#nonIntegerIndexSignal. |
|
232 |
NonIntegerIndexSignal := NonIntegerIndexError. |
|
233 |
NonIntegerIndexSignal notifierString:'index must be integer'. |
|
234 |
||
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
235 |
KeyNotFoundSignal := NotFoundSignal newSignal. |
5977 | 236 |
KeyNotFoundSignal nameClass:self message:#keyNotFoundSignal. |
237 |
KeyNotFoundSignal notifierString:'no such key: '. |
|
238 |
||
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
239 |
ElementOutOfBoundsSignal := ErrorSignal newSignal. |
5971 | 240 |
ElementOutOfBoundsSignal nameClass:self message:#elementOutOfBoundsSignal. |
241 |
ElementOutOfBoundsSignal notifierString:'element not appropriate or out of bounds'. |
|
242 |
||
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
243 |
UserNotificationSignal := UserNotification. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
244 |
WarningSignal := Warning. |
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
245 |
InformationSignal := UserInformation. |
5971 | 246 |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
247 |
ActivityNotificationSignal := UserNotificationSignal newSignal. |
5971 | 248 |
ActivityNotificationSignal nameClass:self message:#activityNotificationSignal. |
249 |
ActivityNotificationSignal notifierString:'activity'. |
|
250 |
||
251 |
DeepCopyErrorSignal := ErrorSignal newSignalMayProceed:true. |
|
252 |
DeepCopyErrorSignal nameClass:self message:#deepCopyErrorSignal. |
|
253 |
DeepCopyErrorSignal notifierString:'object cannot be deepCopy-ed'. |
|
254 |
||
255 |
" |
|
256 |
AbortSignal is not a child of ErrorSignal - |
|
257 |
this would complicate abort from within a signal handler |
|
258 |
" |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
259 |
|
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
260 |
"/ AbortSignal := Signal genericSignal newSignalMayProceed:true. |
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
261 |
"/ AbortSignal nameClass:self message:#abortSignal. |
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
262 |
AbortSignal := AbortOperationRequest. |
5971 | 263 |
AbortSignal notifierString:'unhandled abort signal'. |
264 |
||
6877
ab4e7d42f9f8
AbortAllOperation - now class based
Claus Gittinger <cg@exept.de>
parents:
6874
diff
changeset
|
265 |
"/ AbortAllSignal := Signal genericSignal newSignalMayProceed:true. |
ab4e7d42f9f8
AbortAllOperation - now class based
Claus Gittinger <cg@exept.de>
parents:
6874
diff
changeset
|
266 |
"/ AbortAllSignal nameClass:self message:#abortAllSignal. |
ab4e7d42f9f8
AbortAllOperation - now class based
Claus Gittinger <cg@exept.de>
parents:
6874
diff
changeset
|
267 |
AbortAllSignal := AbortAllOperationRequest. |
5971 | 268 |
AbortAllSignal notifierString:'unhandled abortAll signal'. |
269 |
||
270 |
" |
|
271 |
OSSignalInterruptSignal is not a child of ErrorSignal - |
|
272 |
it requires explicit catching. |
|
273 |
If unhandled, a debugger is entered. |
|
274 |
" |
|
275 |
OSSignalInterruptSignal := Signal genericSignal newSignalMayProceed:true. |
|
276 |
OSSignalInterruptSignal nameClass:self message:#osSignalInterruptSignal. |
|
277 |
OSSignalInterruptSignal notifierString:'OS signal interrupt'. |
|
278 |
||
279 |
RecursiveStoreStringSignal := QuerySignal new. |
|
280 |
RecursiveStoreStringSignal nameClass:self message:#recursiveStoreStringSignal. |
|
281 |
RecursiveStoreStringSignal notifierString:'attempt to generate storeString of recursive object'. |
|
282 |
||
5980 | 283 |
SubclassResponsibilityError notifierString:'subclass responsibility'. |
284 |
||
285 |
" |
|
286 |
Object initSignals |
|
287 |
" |
|
5971 | 288 |
|
289 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
290 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
291 |
"Modified: / 16.11.2001 / 16:30:08 / cg" |
5971 | 292 |
! |
293 |
||
5755 | 294 |
initialize |
295 |
"called only once - initialize signals" |
|
296 |
||
297 |
ErrorSignal isNil ifTrue:[ |
|
6654 | 298 |
self initSignals |
5971 | 299 |
]. |
300 |
||
301 |
ObjectAttributes isNil ifTrue:[ |
|
6654 | 302 |
ObjectAttributes := WeakIdentityDictionary new. |
5971 | 303 |
]. |
304 |
Dependencies isNil ifTrue:[ |
|
6654 | 305 |
Dependencies := WeakDependencyDictionary new. |
5971 | 306 |
]. |
307 |
NonWeakDependencies isNil ifTrue:[ |
|
6654 | 308 |
NonWeakDependencies := IdentityDictionary new. |
5971 | 309 |
]. |
310 |
SynchronizationSemaphores isNil ifTrue:[ |
|
6654 | 311 |
SynchronizationSemaphores := WeakIdentityDictionary new. |
5971 | 312 |
]. |
5755 | 313 |
FinalizationLobby isNil ifTrue:[ |
6654 | 314 |
FinalizationLobby := Registry new. |
5755 | 315 |
]. |
316 |
||
317 |
"/ initialize InfoPrinting to the VM's infoPrint setting |
|
318 |
"/ (which can be turned off via a command line argument) |
|
319 |
InfoPrinting := ObjectMemory infoPrinting. |
|
320 |
||
321 |
"Object initialize" |
|
322 |
||
323 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
324 |
"Modified: / 3.2.1998 / 18:55:09 / cg" |
|
325 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
326 |
! ! |
|
327 |
||
328 |
!Object class methodsFor:'Compatibility - ST80'! |
|
329 |
||
330 |
rootError |
|
331 |
"return the signal used for error/error: - handling. |
|
332 |
Same as errorSignal for ST80 compatibility." |
|
333 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
334 |
^ Error |
5755 | 335 |
|
336 |
"Created: / 15.1.1998 / 23:47:05 / stefan" |
|
337 |
! ! |
|
338 |
||
339 |
!Object class methodsFor:'Signal constants'! |
|
340 |
||
341 |
abortAllSignal |
|
342 |
"return the signal used to abort user actions (much like AbortSignal). |
|
343 |
This signal is supposed to abort multiple operation actions, and get out of |
|
344 |
the loop (such as when confirming multiple class deletions etc.)" |
|
345 |
||
346 |
^ AbortAllSignal |
|
347 |
! |
|
348 |
||
349 |
abortSignal |
|
350 |
"return the signal used to abort user actions. This signal is only |
|
351 |
raised if caught (by the debugger), and will lead way out of the |
|
352 |
currently active doIt/printIt or inspectIt. (also some others use |
|
353 |
this for a save abort)" |
|
354 |
||
355 |
^ AbortSignal |
|
356 |
! |
|
357 |
||
358 |
activityNotificationSignal |
|
359 |
"return the signal used for activity notifications. |
|
360 |
A handler for this signal gets all #activityNotification: sends" |
|
361 |
||
362 |
^ ActivityNotificationSignal |
|
363 |
! |
|
364 |
||
365 |
deepCopyErrorSignal |
|
366 |
"return the signal raised when a deepcopy is asked for |
|
367 |
an object which cannot do this (for example, BlockClosures |
|
368 |
or Contexts)." |
|
369 |
||
370 |
^ DeepCopyErrorSignal |
|
371 |
! |
|
372 |
||
373 |
elementOutOfBoundsSignal |
|
374 |
"return the signal used for element error reporting |
|
375 |
(this signal is used for example when a value not in 0..255 is to |
|
376 |
be put into a bytearray)" |
|
377 |
||
378 |
^ ElementOutOfBoundsSignal |
|
379 |
! |
|
380 |
||
381 |
errorSignal |
|
382 |
"return the signal used for error/error: - handling" |
|
383 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
384 |
^ Error |
5755 | 385 |
! |
386 |
||
387 |
exceptionInterruptSignal |
|
388 |
"return the signal used for exception (display errors) error handling" |
|
389 |
||
390 |
^ ExceptionInterruptSignal |
|
391 |
! |
|
392 |
||
393 |
haltSignal |
|
394 |
"return the signal used for halt/halt: - handling" |
|
395 |
||
396 |
^ HaltSignal |
|
397 |
! |
|
398 |
||
399 |
indexNotFoundSignal |
|
400 |
"return the signal used for bad index error reporting. |
|
401 |
This is also the parentSignal of the nonIntegerIndex- and |
|
402 |
subscriptOutOfBoundsSignal" |
|
403 |
||
404 |
^ IndexNotFoundSignal |
|
405 |
||
406 |
"Created: / 8.11.1997 / 19:15:48 / cg" |
|
407 |
! |
|
408 |
||
409 |
informationSignal |
|
410 |
"return the signal used for informations. |
|
411 |
A handler for this signal gets all #information: sends" |
|
412 |
||
413 |
^ InformationSignal |
|
414 |
! |
|
415 |
||
416 |
internalErrorSignal |
|
417 |
"return the signal used to report internal (VM-) errors." |
|
418 |
||
419 |
^ InternalErrorSignal |
|
420 |
! |
|
421 |
||
422 |
keyNotFoundSignal |
|
423 |
"return the signal used for no such key error reporting" |
|
424 |
||
425 |
^ KeyNotFoundSignal |
|
426 |
! |
|
427 |
||
428 |
messageNotUnderstoodSignal |
|
429 |
"return the signal used for doesNotUnderstand: - error handling" |
|
430 |
||
431 |
^ MessageNotUnderstoodSignal |
|
432 |
! |
|
433 |
||
434 |
nonIntegerIndexSignal |
|
435 |
"return the signal used for bad subscript error reporting" |
|
436 |
||
437 |
^ NonIntegerIndexSignal |
|
438 |
! |
|
439 |
||
440 |
notFoundSignal |
|
441 |
"return the signal used for no element found error reporting" |
|
442 |
||
443 |
^ NotFoundSignal |
|
444 |
! |
|
445 |
||
446 |
osSignalInterruptSignal |
|
447 |
"return the signal used for OS-signal error reporting; |
|
448 |
This is only raised if handled - otherwise, a debugger is entered." |
|
449 |
||
450 |
^ OSSignalInterruptSignal |
|
451 |
||
452 |
"Modified: / 12.6.1998 / 16:27:26 / cg" |
|
453 |
! |
|
454 |
||
455 |
primitiveFailureSignal |
|
456 |
"return the signal used for primitiveFailed - error handling" |
|
457 |
||
458 |
^ PrimitiveFailureSignal |
|
459 |
! |
|
460 |
||
461 |
privateMethodSignal |
|
462 |
"return the signal used for privateMethod - error handling" |
|
463 |
||
464 |
^ MessageNotUnderstoodSignal |
|
465 |
! |
|
466 |
||
467 |
recursionInterruptSignal |
|
468 |
"return the signal used for recursion overflow error handling" |
|
469 |
||
470 |
^ RecursionInterruptSignal |
|
471 |
! |
|
472 |
||
473 |
recursiveStoreStringSignal |
|
474 |
"return the query signal used to report storeString generation of recursive objects" |
|
475 |
||
476 |
^ RecursiveStoreStringSignal |
|
477 |
||
478 |
" |
|
479 |
Object recursiveStoreStringSignal handle:[:ex | |
|
6654 | 480 |
self halt |
5755 | 481 |
] do:[ |
6654 | 482 |
|a| |
483 |
||
484 |
a := Array new:1. |
|
485 |
a at:1 put:a. |
|
486 |
a storeOn:Transcript |
|
5755 | 487 |
] |
488 |
" |
|
489 |
||
490 |
" |
|
491 |
|a| |
|
492 |
||
493 |
a := Array new:1. |
|
494 |
a at:1 put:a. |
|
495 |
a storeOn:Transcript |
|
496 |
" |
|
497 |
||
498 |
||
499 |
||
500 |
! |
|
501 |
||
5980 | 502 |
subclassResponsibilitySignal |
503 |
"return the signal used for subclassResponsibility error reporting. |
|
6652
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
504 |
(this signal is used to signal incomplete subclasses - i.e. a programmers error)" |
5980 | 505 |
|
506 |
^ SubclassResponsibilityError |
|
507 |
! |
|
508 |
||
5755 | 509 |
subscriptOutOfBoundsSignal |
510 |
"return the signal used for subscript error reporting. |
|
511 |
(this signal is used for example when an array is accessed with an |
|
512 |
index less than 1 or greater than the array size)" |
|
513 |
||
514 |
^ SubscriptOutOfBoundsSignal |
|
515 |
! |
|
516 |
||
517 |
userInterruptSignal |
|
518 |
"return the signal used for ^C interrupts handling" |
|
519 |
||
520 |
^ UserInterruptSignal |
|
521 |
! |
|
522 |
||
523 |
userNotificationSignal |
|
524 |
"the parent signal used with information and warnings. |
|
525 |
Handling this allows handling of both information- and warning notifications." |
|
526 |
||
527 |
^ UserNotificationSignal |
|
528 |
! |
|
529 |
||
530 |
warningSignal |
|
531 |
"return the signal used for warnings. |
|
532 |
A handler for this signal gets all #warn: sends" |
|
533 |
||
534 |
^ WarningSignal |
|
535 |
! ! |
|
536 |
||
537 |
!Object class methodsFor:'info messages'! |
|
538 |
||
539 |
infoPrinting |
|
540 |
"return the flag which controls information messages." |
|
541 |
||
542 |
^ InfoPrinting |
|
543 |
! |
|
544 |
||
545 |
infoPrinting:aBoolean |
|
546 |
"{ Pragma: +optSpace }" |
|
547 |
||
548 |
"turn on/off printing of information messages. |
|
549 |
If the argument, aBoolean is false, infoPrint will not output |
|
550 |
messages. The default is true." |
|
551 |
||
552 |
InfoPrinting := aBoolean |
|
553 |
! ! |
|
554 |
||
555 |
!Object class methodsFor:'queries'! |
|
556 |
||
557 |
isBuiltInClass |
|
558 |
"return true, if this class is known by the run-time-system, |
|
559 |
i.e. you cannot add/remove instance variables without recompiling |
|
560 |
the VM. |
|
561 |
Here, true is returned for myself, false for subclasses." |
|
562 |
||
563 |
^ self == Object |
|
564 |
||
565 |
"Modified: 23.4.1996 / 16:00:07 / cg" |
|
566 |
! ! |
|
567 |
||
7261 | 568 |
!Object methodsFor:'Compatibility-ST80'! |
5755 | 569 |
|
570 |
isMetaclass |
|
571 |
^ self isMeta |
|
6918 | 572 |
! |
573 |
||
574 |
oneWayBecome:anotherObject |
|
575 |
^ self becomeSameAs:anotherObject |
|
576 |
||
577 |
" |
|
578 |
|arr o1 o2| |
|
579 |
||
580 |
arr := Array new:2. |
|
581 |
arr at:1 put:(o1 := Object new). |
|
582 |
arr at:2 put:(o2 := Point new). |
|
583 |
o1 oneWayBecome:o2. |
|
584 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
585 |
" |
|
586 |
" |
|
587 |
|arr o1 o2| |
|
588 |
||
589 |
arr := Array new:2. |
|
590 |
arr at:1 put:(o1 := Object new). |
|
591 |
arr at:2 put:(o2 := Point new). |
|
592 |
o1 becomeSameAs:o2. |
|
593 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
594 |
" |
|
5755 | 595 |
! ! |
596 |
||
7261 | 597 |
!Object methodsFor:'Compatibility-Squeak'! |
5755 | 598 |
|
6549
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
599 |
as:aSimilarClass |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
600 |
"If the receivers class is not aSimilarClass, |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
601 |
create and return an object of class aSimilarClass that has the same contents |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
602 |
as the receiver. |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
603 |
Otherwise, return the receiver." |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
604 |
|
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
605 |
self class == aSimilarClass ifTrue:[^ self]. |
5755 | 606 |
^ aSimilarClass newFrom:self |
607 |
||
608 |
" |
|
609 |
#[1 2 3 4] as:ByteArray |
|
6549
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
610 |
#[1 2 3 4] as:Array |
5755 | 611 |
" |
612 |
! |
|
613 |
||
614 |
asString |
|
615 |
^ self printString |
|
616 |
! |
|
617 |
||
618 |
clone |
|
619 |
^ self shallowCopy |
|
620 |
! |
|
621 |
||
6146 | 622 |
copyTwoLevel |
623 |
"one more level than a shallowCopy" |
|
624 |
||
625 |
^ self copyToLevel:2 |
|
626 |
||
627 |
" |
|
628 |
|original copy elL1 elL2 elL3 copyOfElL1| |
|
629 |
||
630 |
original := Array new:3. |
|
631 |
original at:1 put:1234. |
|
632 |
original at:2 put:'hello'. |
|
633 |
original at:3 put:(elL1 := Array new:3). |
|
634 |
||
635 |
elL1 at:1 put:1234. |
|
636 |
elL1 at:2 put:'hello'. |
|
637 |
elL1 at:3 put:(elL2 := Array new:3). |
|
638 |
||
639 |
elL2 at:1 put:1234. |
|
640 |
elL2 at:2 put:'hello'. |
|
641 |
elL2 at:3 put:(elL3 := Array new:3). |
|
642 |
||
643 |
elL3 at:1 put:1234. |
|
644 |
elL3 at:2 put:'hello'. |
|
645 |
elL3 at:3 put:(Array new:3). |
|
646 |
||
647 |
copy := original copyTwoLevel. |
|
648 |
(original at:2) ~~ (copy at:2) ifFalse:[self halt]. |
|
649 |
(original at:3) ~~ (copy at:3) ifFalse:[self halt]. |
|
650 |
||
651 |
copyOfElL1 := copy at:3. |
|
652 |
(elL1 at:2) == (copyOfElL1 at:2) ifFalse:[self halt]. |
|
653 |
(elL1 at:3) == (copyOfElL1 at:3) ifFalse:[self halt]. |
|
654 |
" |
|
655 |
! |
|
656 |
||
5755 | 657 |
currentHand |
5912 | 658 |
"Return a usable HandMorph -- the one associated with the object's current environment. This method will always return a hand, even if it has to conjure one up as a last resort. If a particular hand is actually handling events at the moment (such as a remote hand or a ghost hand), it will be returned." |
659 |
||
660 |
|w h| |
|
661 |
||
662 |
w := self currentWorld. |
|
663 |
h := w activeHand. |
|
664 |
h isNil ifTrue:[ |
|
6654 | 665 |
h := w hands first |
5912 | 666 |
]. |
667 |
^ h |
|
5755 | 668 |
! |
669 |
||
670 |
currentWorld |
|
7159
7964c345d74c
Object currentWorld - recursion if Utilities is unloaded
Claus Gittinger <cg@exept.de>
parents:
7121
diff
changeset
|
671 |
Utilities autoload. |
7964c345d74c
Object currentWorld - recursion if Utilities is unloaded
Claus Gittinger <cg@exept.de>
parents:
7121
diff
changeset
|
672 |
^ Utilities currentWorld |
5755 | 673 |
! |
674 |
||
675 |
newTileMorphRepresentative |
|
6654 | 676 |
^ TileMorph new setLiteral: self |
5755 | 677 |
! |
678 |
||
679 |
stringForReadout |
|
6654 | 680 |
^ self stringRepresentation |
5755 | 681 |
! |
682 |
||
683 |
stringRepresentation |
|
6654 | 684 |
"Answer a string that represents the receiver. For most objects this is simply its printString, but for strings themselves, it's themselves. 6/12/96 sw" |
685 |
||
686 |
^ self printString |
|
5755 | 687 |
! |
688 |
||
689 |
veryDeepCopy |
|
690 |
||
691 |
^(self deepCopyUsing:(IdentityDictionary new)) postDeepCopyFrom:self |
|
692 |
! ! |
|
693 |
||
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
694 |
|
5755 | 695 |
!Object methodsFor:'accessing'! |
696 |
||
697 |
at:index |
|
698 |
"return the indexed instance variable with index, anInteger; |
|
699 |
this method can be redefined in subclasses." |
|
700 |
||
701 |
^ self basicAt:index |
|
702 |
! |
|
703 |
||
704 |
at:index put:anObject |
|
705 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
706 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
|
707 |
||
708 |
^ self basicAt:index put:anObject |
|
709 |
||
710 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
|
711 |
! |
|
712 |
||
713 |
basicAt:index |
|
714 |
"return the indexed instance variable with index, anInteger. |
|
715 |
Trigger an error if the receiver has no indexed instance variables. |
|
716 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
717 |
||
718 |
%{ /* NOCONTEXT */ |
|
719 |
||
720 |
REGISTER int nbytes, indx; |
|
721 |
OBJ myClass; |
|
722 |
REGISTER char *pFirst; |
|
723 |
#ifdef alpha64 |
|
724 |
# define int32 int |
|
725 |
#else |
|
726 |
# define int32 long |
|
727 |
#endif |
|
728 |
REGISTER int n; |
|
729 |
||
730 |
/* |
|
731 |
* notice the missing test for self being a nonNilObject - |
|
732 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
733 |
* and SmallInteger |
|
734 |
*/ |
|
735 |
if (__isSmallInteger(index)) { |
|
6654 | 736 |
myClass = __qClass(self); |
737 |
indx = __intVal(index) - 1; |
|
738 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
739 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
740 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
741 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
742 |
||
743 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
744 |
case __MASKSMALLINT(POINTERARRAY): |
|
745 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
746 |
/* |
|
747 |
* pointers |
|
748 |
*/ |
|
749 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
750 |
OBJ *op; |
|
751 |
||
752 |
op = (OBJ *)pFirst + indx; |
|
753 |
RETURN ( *op ); |
|
754 |
} |
|
755 |
break; |
|
756 |
||
757 |
case __MASKSMALLINT(BYTEARRAY): |
|
758 |
/* |
|
759 |
* (unsigned) bytes |
|
760 |
*/ |
|
761 |
if ((unsigned)indx < nbytes) { |
|
762 |
unsigned char *cp; |
|
763 |
||
764 |
cp = (unsigned char *)pFirst + indx; |
|
765 |
RETURN ( __MKSMALLINT( (INT)(*cp & 0xFF)) ); |
|
766 |
} |
|
767 |
break; |
|
768 |
||
769 |
case __MASKSMALLINT(FLOATARRAY): |
|
770 |
/* |
|
771 |
* native floats |
|
772 |
*/ |
|
773 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
774 |
float *fp; |
|
775 |
float f; |
|
776 |
OBJ v; |
|
777 |
||
778 |
fp = (float *)pFirst + indx; |
|
779 |
f = *fp; |
|
780 |
if (f == 0.0) { |
|
781 |
v = __float0; |
|
782 |
} else { |
|
783 |
__qMKSFLOAT(v, f); |
|
784 |
} |
|
785 |
RETURN (v); |
|
786 |
} |
|
787 |
break; |
|
788 |
||
789 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
790 |
/* |
|
791 |
* native doubles |
|
792 |
*/ |
|
5755 | 793 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 794 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
795 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
796 |
||
797 |
pFirst += delta; |
|
798 |
nbytes -= delta; |
|
799 |
} |
|
5755 | 800 |
#endif |
6654 | 801 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
802 |
double *dp; |
|
803 |
double d; |
|
804 |
OBJ v; |
|
805 |
||
806 |
dp = (double *)pFirst + indx; |
|
807 |
d = *dp; |
|
808 |
if (d == 0.0) { |
|
809 |
v = __float0; |
|
810 |
} else { |
|
811 |
__qMKFLOAT(v, d); |
|
812 |
} |
|
813 |
RETURN (v); |
|
814 |
} |
|
815 |
break; |
|
816 |
||
817 |
case __MASKSMALLINT(WORDARRAY): |
|
818 |
/* |
|
819 |
* unsigned 16bit ints |
|
820 |
*/ |
|
821 |
/* Notice: the hard coded shifts are by purpose; |
|
822 |
* it makes us independent of the short-size of the machine |
|
823 |
*/ |
|
824 |
if ((unsigned)indx < (nbytes>>1)) { |
|
825 |
unsigned short *sp; |
|
826 |
||
827 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
828 |
RETURN ( __MKSMALLINT( (INT)(*sp & 0xFFFF)) ); |
|
829 |
} |
|
830 |
break; |
|
831 |
||
832 |
case __MASKSMALLINT(SWORDARRAY): |
|
833 |
/* |
|
834 |
* signed 16bit ints |
|
835 |
*/ |
|
836 |
/* Notice: the hard coded shifts are by purpose; |
|
837 |
* it makes us independent of the short-size of the machine |
|
838 |
*/ |
|
839 |
if ((unsigned)indx < (nbytes>>1)) { |
|
840 |
short *ssp; |
|
841 |
||
842 |
ssp = (short *)(pFirst + (indx<<1)); |
|
843 |
RETURN ( __MKSMALLINT( (INT)(*ssp) )); |
|
844 |
} |
|
845 |
break; |
|
846 |
||
847 |
case __MASKSMALLINT(LONGARRAY): |
|
848 |
/* |
|
849 |
* unsigned 32bit ints |
|
850 |
*/ |
|
851 |
/* Notice: the hard coded shifts are by purpose; |
|
852 |
* it makes us independent of the int-size of the machine |
|
853 |
*/ |
|
854 |
if ((unsigned)indx < (nbytes>>2)) { |
|
855 |
unsigned int32 ul; |
|
856 |
unsigned int32 *lp; |
|
857 |
||
858 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
859 |
ul = *lp; |
|
5755 | 860 |
#ifdef alpha64 |
6654 | 861 |
{ |
862 |
unsigned INT ull = (unsigned INT)ul; |
|
863 |
RETURN ( __MKSMALLINT(ull) ); |
|
864 |
} |
|
5755 | 865 |
#else |
6654 | 866 |
if (ul <= _MAX_INT) { |
867 |
RETURN ( __MKSMALLINT(ul) ); |
|
868 |
} |
|
869 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 870 |
#endif |
6654 | 871 |
} |
872 |
break; |
|
873 |
||
874 |
case __MASKSMALLINT(SLONGARRAY): |
|
875 |
/* |
|
876 |
* signed 32bit ints |
|
877 |
*/ |
|
878 |
/* Notice: the hard coded shifts are by purpose; |
|
879 |
* it makes us independent of the int-size of the machine |
|
880 |
*/ |
|
881 |
if ((unsigned)indx < (nbytes>>2)) { |
|
882 |
int32 *slp; |
|
883 |
int32 l; |
|
884 |
||
885 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
886 |
l = *slp; |
|
5755 | 887 |
#ifdef alpha64 |
6654 | 888 |
{ |
889 |
INT ll = (INT)l; |
|
890 |
RETURN ( __MKSMALLINT(ll) ); |
|
891 |
} |
|
5755 | 892 |
#else |
6654 | 893 |
if (__ISVALIDINTEGER(l)) { |
894 |
RETURN ( __MKSMALLINT(l) ); |
|
895 |
} |
|
896 |
RETURN ( __MKLARGEINT(l) ); |
|
5755 | 897 |
#endif |
6654 | 898 |
} |
899 |
break; |
|
900 |
||
901 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
902 |
/* |
|
903 |
* signed 64bit longlongs |
|
904 |
*/ |
|
5755 | 905 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 906 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
907 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
908 |
||
909 |
pFirst += delta; |
|
910 |
nbytes -= delta; |
|
911 |
} |
|
5755 | 912 |
#endif |
6654 | 913 |
/* Notice: the hard coded shifts are by purpose; |
914 |
* it makes us independent of the long/longlong-size of the machine |
|
915 |
*/ |
|
916 |
if ((unsigned)indx < (nbytes>>3)) { |
|
5755 | 917 |
#ifdef alpha64 |
6654 | 918 |
INT *slp, ll; |
919 |
||
920 |
slp = (INT *)(pFirst + (indx<<3)); |
|
921 |
ll = *slp; |
|
922 |
if (__ISVALIDINTEGER(ll)) { |
|
923 |
RETURN ( __MKSMALLINT(ll) ); |
|
924 |
} |
|
925 |
RETURN ( __MKLARGEINT(ll) ); |
|
5755 | 926 |
#else |
6654 | 927 |
__int64__ *llp; |
928 |
extern OBJ __MKINT64(); |
|
929 |
||
930 |
llp = (__int64__ *)(pFirst + (indx<<3)); |
|
931 |
RETURN (__MKINT64(llp)); |
|
5755 | 932 |
#endif |
6654 | 933 |
} |
934 |
break; |
|
935 |
||
936 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
937 |
/* |
|
938 |
* unsigned 64bit longlongs |
|
939 |
*/ |
|
5755 | 940 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 941 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
942 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
943 |
||
944 |
pFirst += delta; |
|
945 |
nbytes -= delta; |
|
946 |
} |
|
5755 | 947 |
#endif |
6654 | 948 |
/* Notice: the hard coded shifts are by purpose; |
949 |
* it makes us independent of the long/longlong-size of the machine |
|
950 |
*/ |
|
951 |
if ((unsigned)indx < (nbytes>>3)) { |
|
5755 | 952 |
#ifdef alpha64 |
6654 | 953 |
unsigned INT *ulp, ul; |
954 |
||
955 |
ulp = (unsigned INT *)(pFirst + (indx<<3)); |
|
956 |
ul = *ulp; |
|
957 |
if (ul <= _MAX_INT) { |
|
958 |
RETURN ( __MKSMALLINT(ul) ); |
|
959 |
} |
|
960 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 961 |
#else |
6654 | 962 |
__uint64__ *llp; |
963 |
extern OBJ __MKUINT64(); |
|
964 |
||
965 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
966 |
RETURN (__MKUINT64(llp)); |
|
5755 | 967 |
#endif |
6654 | 968 |
} |
969 |
break; |
|
970 |
} |
|
5755 | 971 |
} |
972 |
||
973 |
# undef int32 |
|
974 |
||
975 |
%}. |
|
7216 | 976 |
^ self indexNotIntegerOrOutOfBounds:index |
5755 | 977 |
! |
978 |
||
979 |
basicAt:index put:anObject |
|
980 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
981 |
Returns anObject (sigh). |
|
982 |
Trigger an error if the receiver has no indexed instance variables. |
|
983 |
||
984 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
985 |
||
986 |
%{ /* NOCONTEXT */ |
|
987 |
||
988 |
register int nbytes, indx; |
|
989 |
OBJ myClass; |
|
990 |
register char *pFirst; |
|
991 |
#ifdef alpha64 |
|
992 |
# define int32 int |
|
993 |
#else |
|
994 |
# define int32 long |
|
995 |
#endif |
|
996 |
/* int nInstBytes, ninstvars, flags; */ |
|
997 |
REGISTER int n; |
|
998 |
unsigned int u; |
|
999 |
int val; |
|
1000 |
||
1001 |
/* notice the missing test for self being a nonNilObject - |
|
1002 |
this can be done since basicAt: is defined both in UndefinedObject |
|
1003 |
and SmallInteger */ |
|
1004 |
||
1005 |
if (__isSmallInteger(index)) { |
|
6654 | 1006 |
indx = __intVal(index) - 1; |
1007 |
myClass = __qClass(self); |
|
1008 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1009 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
1010 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
1011 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
1012 |
||
1013 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1014 |
case __MASKSMALLINT(POINTERARRAY): |
|
1015 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
1016 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
1017 |
OBJ *op; |
|
1018 |
||
1019 |
op = (OBJ *)pFirst + indx; |
|
1020 |
*op = anObject; |
|
1021 |
__STORE(self, anObject); |
|
1022 |
RETURN ( anObject ); |
|
1023 |
} |
|
1024 |
break; |
|
1025 |
||
1026 |
case __MASKSMALLINT(BYTEARRAY): |
|
1027 |
if (__isSmallInteger(anObject)) { |
|
1028 |
val = __intVal(anObject); |
|
1029 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
1030 |
if ((unsigned)indx < nbytes) { |
|
1031 |
char *cp; |
|
1032 |
||
1033 |
cp = pFirst + indx; |
|
1034 |
*cp = val; |
|
1035 |
RETURN ( anObject ); |
|
1036 |
} |
|
1037 |
} |
|
1038 |
} |
|
1039 |
break; |
|
1040 |
||
1041 |
case __MASKSMALLINT(FLOATARRAY): |
|
1042 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
1043 |
float *fp; |
|
1044 |
||
1045 |
fp = (float *)pFirst + indx; |
|
1046 |
if (anObject != nil) { |
|
1047 |
if (! __isSmallInteger(anObject)) { |
|
1048 |
if (__qIsFloatLike(anObject)) { |
|
1049 |
*fp = (float)(__floatVal(anObject)); |
|
1050 |
RETURN ( anObject ); |
|
1051 |
} |
|
1052 |
if (__qIsShortFloat(anObject)) { |
|
1053 |
*fp = __shortFloatVal(anObject); |
|
1054 |
RETURN ( anObject ); |
|
1055 |
} |
|
1056 |
} else { |
|
1057 |
*fp = (float) __intVal(anObject); |
|
1058 |
RETURN ( anObject ); |
|
1059 |
} |
|
1060 |
} |
|
1061 |
} |
|
1062 |
break; |
|
1063 |
||
1064 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1065 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 1066 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1067 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1068 |
||
1069 |
pFirst += delta; |
|
1070 |
nbytes -= delta; |
|
1071 |
} |
|
5755 | 1072 |
#endif |
6654 | 1073 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
1074 |
double *dp; |
|
1075 |
||
1076 |
dp = (double *)pFirst + indx; |
|
1077 |
if (anObject != nil) { |
|
1078 |
if (! __isSmallInteger(anObject)) { |
|
1079 |
if (__qIsFloatLike(anObject)) { |
|
1080 |
*dp = __floatVal(anObject); |
|
1081 |
RETURN ( anObject ); |
|
1082 |
} |
|
1083 |
if (__qIsShortFloat(anObject)) { |
|
1084 |
*dp = (double)__shortFloatVal(anObject); |
|
1085 |
RETURN ( anObject ); |
|
1086 |
} |
|
1087 |
} else { |
|
1088 |
*dp = (double) __intVal(anObject); |
|
1089 |
RETURN ( anObject ); |
|
1090 |
} |
|
1091 |
} |
|
1092 |
} |
|
1093 |
break; |
|
1094 |
||
1095 |
case __MASKSMALLINT(WORDARRAY): |
|
1096 |
if (__isSmallInteger(anObject)) { |
|
1097 |
val = __intVal(anObject); |
|
1098 |
if ((unsigned)val <= 0xFFFF) { |
|
1099 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1100 |
unsigned short *sp; |
|
1101 |
||
1102 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
1103 |
*sp = val; |
|
1104 |
RETURN ( anObject ); |
|
1105 |
} |
|
1106 |
} |
|
1107 |
} |
|
1108 |
break; |
|
1109 |
||
1110 |
case __MASKSMALLINT(SWORDARRAY): |
|
1111 |
if (__isSmallInteger(anObject)) { |
|
1112 |
val = __intVal(anObject); |
|
1113 |
if ((val >= -32768) && (val < 32768)) { |
|
1114 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1115 |
short *ssp; |
|
1116 |
||
1117 |
ssp = (short *)(pFirst + (indx<<1)); |
|
1118 |
*ssp = val; |
|
1119 |
RETURN ( anObject ); |
|
1120 |
} |
|
1121 |
} |
|
1122 |
} |
|
1123 |
break; |
|
1124 |
||
1125 |
case __MASKSMALLINT(SLONGARRAY): |
|
1126 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1127 |
int32 *slp; |
|
1128 |
||
1129 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
1130 |
if (__isSmallInteger(anObject)) { |
|
1131 |
*slp = __intVal(anObject); |
|
1132 |
RETURN ( anObject ); |
|
1133 |
} |
|
1134 |
n = __signedLongIntVal(anObject); |
|
1135 |
/* |
|
1136 |
* zero means failure for an int larger than 4 bytes |
|
1137 |
* (would be a smallInteger) |
|
1138 |
*/ |
|
1139 |
if (n) { |
|
1140 |
*slp = n; |
|
1141 |
RETURN ( anObject ); |
|
1142 |
} |
|
1143 |
} |
|
1144 |
break; |
|
1145 |
||
1146 |
case __MASKSMALLINT(LONGARRAY): |
|
1147 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1148 |
unsigned int32 *lp; |
|
1149 |
||
1150 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
1151 |
if (anObject == __MKSMALLINT(0)) { |
|
1152 |
*lp = 0; |
|
1153 |
RETURN ( anObject ); |
|
1154 |
} |
|
1155 |
u = __longIntVal(anObject); |
|
1156 |
/* |
|
1157 |
* zero means failure for an int larger than 4 bytes |
|
1158 |
* (would be a smallInteger) |
|
1159 |
*/ |
|
1160 |
if (u) { |
|
1161 |
*lp = u; |
|
1162 |
RETURN ( anObject ); |
|
1163 |
} |
|
1164 |
} |
|
1165 |
break; |
|
1166 |
||
1167 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1168 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1169 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1170 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1171 |
||
1172 |
pFirst += delta; |
|
1173 |
nbytes -= delta; |
|
1174 |
} |
|
5755 | 1175 |
#endif |
6654 | 1176 |
if ((unsigned)indx < (nbytes>>3)) { |
1177 |
__int64__ ll; |
|
1178 |
__int64__ *sllp; |
|
1179 |
||
1180 |
sllp = (__int64__ *)(pFirst + (indx<<3)); |
|
1181 |
||
1182 |
if (anObject == __MKSMALLINT(0)) { |
|
1183 |
ll.lo = ll.hi = 0; |
|
1184 |
*sllp = ll; |
|
1185 |
RETURN ( anObject ); |
|
1186 |
} |
|
1187 |
if (__signedLong64IntVal(anObject, &ll)) { |
|
1188 |
*sllp = ll; |
|
1189 |
RETURN ( anObject ); |
|
1190 |
} |
|
1191 |
} |
|
1192 |
break; |
|
1193 |
||
1194 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
5755 | 1195 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1196 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1197 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1198 |
||
1199 |
pFirst += delta; |
|
1200 |
nbytes -= delta; |
|
1201 |
} |
|
5755 | 1202 |
#endif |
6654 | 1203 |
if ((unsigned)indx < (nbytes>>3)) { |
1204 |
__uint64__ ll; |
|
1205 |
__uint64__ *llp; |
|
1206 |
||
1207 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
1208 |
if (anObject == __MKSMALLINT(0)) { |
|
1209 |
ll.lo = ll.hi = 0; |
|
1210 |
*llp = ll; |
|
1211 |
RETURN ( anObject ); |
|
1212 |
} |
|
1213 |
if (__unsignedLong64IntVal(anObject, &ll)) { |
|
1214 |
*llp = ll; |
|
1215 |
RETURN ( anObject ); |
|
1216 |
} |
|
1217 |
} |
|
1218 |
break; |
|
1219 |
} |
|
5755 | 1220 |
} |
1221 |
||
1222 |
# undef int32 |
|
1223 |
||
1224 |
%}. |
|
1225 |
index isInteger ifFalse:[ |
|
6654 | 1226 |
" |
1227 |
the index should be an integer number |
|
1228 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1229 |
^ self indexNotInteger:index |
5755 | 1230 |
]. |
1231 |
(index between:1 and:self size) ifFalse:[ |
|
6654 | 1232 |
" |
1233 |
the index is less than 1 or greater than the size of the |
|
1234 |
receiver collection |
|
1235 |
" |
|
1236 |
^ self subscriptBoundsError:index |
|
5755 | 1237 |
]. |
1238 |
(self class isFloatsOrDoubles) ifTrue:[ |
|
6654 | 1239 |
anObject isNumber ifTrue:[ |
1240 |
^ self basicAt:index put:(anObject asFloat) |
|
1241 |
] |
|
5755 | 1242 |
]. |
1243 |
anObject isInteger ifFalse:[ |
|
6654 | 1244 |
" |
1245 |
the object to put into the receiver collection |
|
1246 |
should be an integer number |
|
1247 |
" |
|
1248 |
^ self elementNotInteger |
|
5755 | 1249 |
]. |
1250 |
" |
|
1251 |
the object to put into the receiver collection |
|
1252 |
is not an instance of the expected element class, |
|
1253 |
or the value is not within the elements valid range. |
|
1254 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1255 |
^ self elementBoundsError:anObject |
5755 | 1256 |
|
1257 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
|
1258 |
! |
|
1259 |
||
1260 |
byteAt:index |
|
1261 |
"return the byte at index. |
|
1262 |
This is only allowed for non-pointer indexed objects |
|
1263 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1264 |
The receivers indexed instvars are treated as an uninterpreted |
|
1265 |
collection of bytes. |
|
1266 |
Only useful with binary storage." |
|
1267 |
||
1268 |
%{ /* NOCONTEXT */ |
|
1269 |
||
1270 |
REGISTER int indx; |
|
1271 |
int nIndex; |
|
1272 |
REGISTER OBJ slf; |
|
1273 |
REGISTER OBJ cls; |
|
1274 |
||
1275 |
if (__isSmallInteger(index)) { |
|
6654 | 1276 |
slf = self; |
1277 |
if (__isNonNilObject(slf)) { |
|
1278 |
unsigned char *pFirst; |
|
1279 |
int nIndex; |
|
1280 |
||
1281 |
cls = __qClass(slf); |
|
1282 |
||
1283 |
pFirst = __byteArrayVal(slf); |
|
1284 |
pFirst += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1285 |
nIndex = __byteArraySize(slf); |
|
1286 |
indx = __intVal(index) - 1; |
|
1287 |
||
1288 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1289 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1290 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 1291 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1292 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1293 |
||
1294 |
pFirst += delta; |
|
1295 |
nIndex -= delta; |
|
1296 |
} |
|
5755 | 1297 |
#endif |
6654 | 1298 |
/* fall into */ |
1299 |
case __MASKSMALLINT(BYTEARRAY): |
|
1300 |
case __MASKSMALLINT(WORDARRAY): |
|
1301 |
case __MASKSMALLINT(LONGARRAY): |
|
1302 |
case __MASKSMALLINT(SWORDARRAY): |
|
1303 |
case __MASKSMALLINT(SLONGARRAY): |
|
1304 |
case __MASKSMALLINT(FLOATARRAY): |
|
1305 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1306 |
RETURN ( __MKSMALLINT( (INT)(pFirst[indx])) ); |
|
1307 |
} |
|
1308 |
break; |
|
1309 |
||
1310 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1311 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1312 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1313 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1314 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1315 |
||
1316 |
pFirst += delta; |
|
1317 |
nIndex -= delta; |
|
1318 |
} |
|
5755 | 1319 |
#endif |
6654 | 1320 |
if ((unsigned)indx < (unsigned)nIndex) { |
1321 |
RETURN ( __MKSMALLINT( (INT)(pFirst[indx])) ); |
|
1322 |
} |
|
1323 |
break; |
|
1324 |
} |
|
1325 |
} |
|
5755 | 1326 |
} |
1327 |
%}. |
|
1328 |
"/ index not integer or index out of range |
|
1329 |
"/ or non-byte indexable receiver |
|
1330 |
||
1331 |
^ self primitiveFailed |
|
1332 |
||
1333 |
" |
|
1334 |
Point new byteAt:1 |
|
1335 |
(ByteArray with:1 with:2) byteAt:2 |
|
1336 |
(WordArray with:1) byteAt:1 |
|
1337 |
(FloatArray with:1.0) byteAt:2 |
|
1338 |
'hello' byteAt:1 |
|
1339 |
" |
|
1340 |
! |
|
1341 |
||
1342 |
byteAt:index put:byteValue |
|
1343 |
"set the byte at index. |
|
1344 |
This is only allowed for non-pointer indexed objects |
|
1345 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1346 |
The receivers indexed instvars are treated as an uninterpreted |
|
1347 |
collection of bytes. |
|
1348 |
Only useful with binary storage." |
|
1349 |
||
1350 |
%{ /* NOCONTEXT */ |
|
1351 |
||
1352 |
REGISTER int indx; |
|
1353 |
int val, nIndex; |
|
1354 |
REGISTER OBJ slf; |
|
1355 |
REGISTER OBJ cls; |
|
1356 |
||
1357 |
if (__bothSmallInteger(index, byteValue)) { |
|
6654 | 1358 |
val = __intVal(byteValue); |
1359 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
1360 |
slf = self; |
|
1361 |
if (__isNonNilObject(slf)) { |
|
1362 |
cls = __qClass(slf); |
|
1363 |
||
1364 |
indx = __intVal(index) - 1; |
|
1365 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1366 |
case __MASKSMALLINT(BYTEARRAY): |
|
1367 |
case __MASKSMALLINT(WORDARRAY): |
|
1368 |
case __MASKSMALLINT(LONGARRAY): |
|
1369 |
case __MASKSMALLINT(SWORDARRAY): |
|
1370 |
case __MASKSMALLINT(SLONGARRAY): |
|
1371 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1372 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1373 |
case __MASKSMALLINT(FLOATARRAY): |
|
1374 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
1375 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1376 |
nIndex = __byteArraySize(slf); |
|
1377 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1378 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
1379 |
RETURN ( byteValue ); |
|
1380 |
} |
|
1381 |
break; |
|
1382 |
} |
|
1383 |
} |
|
1384 |
} |
|
5755 | 1385 |
} |
1386 |
%}. |
|
1387 |
"/ index not integer or index out of range |
|
1388 |
"/ or non-byte indexable receiver |
|
1389 |
||
1390 |
^ self primitiveFailed |
|
1391 |
||
1392 |
" |
|
1393 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
|
1394 |
'hello' copy byteAt:1 put:105; yourself |
|
1395 |
" |
|
1396 |
! |
|
1397 |
||
1398 |
instVarAt:index |
|
1399 |
"return a non-indexed instance variable; |
|
1400 |
peeking into an object this way is not very object oriented |
|
1401 |
- use with care (needed for copy, inspector etc.)" |
|
1402 |
||
1403 |
%{ /* NOCONTEXT */ |
|
1404 |
||
1405 |
OBJ myClass; |
|
1406 |
int idx, ninstvars; |
|
1407 |
||
1408 |
if (__isSmallInteger(index)) { |
|
6654 | 1409 |
myClass = __Class(self); |
1410 |
idx = __intVal(index) - 1; |
|
1411 |
/* |
|
1412 |
* do not allow returning of non-object fields. |
|
1413 |
* if subclass did not make privisions for that, |
|
1414 |
* we wont do so here ... |
|
1415 |
*/ |
|
1416 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1417 |
if (idx == 0) { |
|
1418 |
RETURN ( nil ) |
|
1419 |
} |
|
1420 |
} |
|
1421 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1422 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1423 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
|
1424 |
} |
|
5755 | 1425 |
} |
7216 | 1426 |
%}. |
1427 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1428 |
! |
1429 |
||
1430 |
instVarAt:index put:value |
|
1431 |
"change a non-indexed instance variable; |
|
1432 |
peeking into an object this way is not very object oriented |
|
1433 |
- use with care (needed for copy, inspector etc.)" |
|
1434 |
||
1435 |
%{ /* NOCONTEXT */ |
|
1436 |
||
1437 |
OBJ myClass; |
|
1438 |
int idx, ninstvars; |
|
1439 |
||
1440 |
if (__isSmallInteger(index)) { |
|
6654 | 1441 |
myClass = __Class(self); |
1442 |
idx = __intVal(index) - 1; |
|
1443 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1444 |
/* |
|
1445 |
* do not allow setting of non-object fields. |
|
1446 |
* if subclass did not make privisions for that, |
|
1447 |
* we wont do so here ... |
|
1448 |
*/ |
|
1449 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1450 |
if (idx == 0) { |
|
1451 |
RETURN ( nil ) |
|
1452 |
} |
|
1453 |
} |
|
1454 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1455 |
__InstPtr(self)->i_instvars[idx] = value; |
|
1456 |
__STORE(self, value); |
|
1457 |
RETURN ( value ); |
|
1458 |
} |
|
5755 | 1459 |
} |
7216 | 1460 |
%}. |
1461 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1462 |
! |
1463 |
||
1464 |
instVarNamed:name |
|
1465 |
"return a non-indexed instance variables value by name; |
|
1466 |
peeking into an object this way is not very object oriented |
|
1467 |
- use with care if at all (provided for inspectors and memory usage monitor). |
|
1468 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1469 |
parsed ad runtime)" |
|
1470 |
||
1471 |
^ self instVarAt:(self class instVarOffsetOf:name) |
|
1472 |
||
1473 |
||
1474 |
" |
|
1475 |
|p| |
|
1476 |
||
1477 |
p := Point x:10 y:20. |
|
1478 |
p instVarNamed:'x' |
|
1479 |
" |
|
1480 |
||
1481 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
|
1482 |
! |
|
1483 |
||
1484 |
instVarNamed:name ifAbsent:exceptionBlock |
|
1485 |
"return a non-indexed instance variables value by name, |
|
1486 |
or the value of exceptionBlock, if there is no such instance variable. |
|
1487 |
peeking into an object this way is not very object oriented |
|
1488 |
- use with care if at all (provided for inspectors and memory usage monitor). |
|
1489 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1490 |
parsed ad runtime)" |
|
1491 |
||
1492 |
|idx| |
|
1493 |
||
1494 |
idx := self class instVarOffsetOf:name. |
|
1495 |
idx isNil ifTrue:[^ exceptionBlock value]. |
|
1496 |
^ self instVarAt:idx |
|
1497 |
||
1498 |
||
1499 |
" |
|
1500 |
|p| |
|
1501 |
||
1502 |
p := Point x:10 y:20. |
|
1503 |
p instVarNamed:'x' |
|
1504 |
" |
|
1505 |
||
1506 |
"Created: 6.7.1996 / 23:02:49 / cg" |
|
1507 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
|
1508 |
! |
|
1509 |
||
1510 |
instVarNamed:name put:value |
|
1511 |
"set a non-indexed instance variable by name; |
|
1512 |
peeking into an object this way is not very object oriented |
|
1513 |
- if at all, use with care (provided for protocol completeness). |
|
1514 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1515 |
parsed ad runtime)" |
|
1516 |
||
1517 |
^ self instVarAt:(self class instVarOffsetOf:name) put:value |
|
1518 |
||
1519 |
" |
|
1520 |
|p| |
|
1521 |
||
1522 |
p := Point x:10 y:20. |
|
1523 |
p instVarNamed:'x' put:30. |
|
1524 |
p |
|
1525 |
" |
|
1526 |
||
1527 |
"Modified: 19.4.1996 / 11:12:49 / cg" |
|
1528 |
! ! |
|
1529 |
||
1530 |
!Object methodsFor:'attributes access'! |
|
1531 |
||
6323 | 1532 |
objectAttributeAt:attributeKey |
5755 | 1533 |
"return the attribute for a given key or nil if not found" |
1534 |
||
1535 |
| attrs | |
|
1536 |
||
1537 |
attrs := self objectAttributes. |
|
1538 |
(attrs notNil and:[attrs size > 0]) ifTrue:[ |
|
6654 | 1539 |
^ attrs at:attributeKey ifAbsent:[] |
5755 | 1540 |
]. |
1541 |
^ nil |
|
1542 |
||
1543 |
"Created: / 22.1.1998 / 21:29:17 / av" |
|
1544 |
"Modified: / 3.2.1998 / 18:55:55 / cg" |
|
1545 |
! |
|
1546 |
||
6323 | 1547 |
objectAttributeAt:attributeKey put:anObject |
5755 | 1548 |
"store the attribute anObject referenced by key into the receiver" |
1549 |
||
1550 |
"/ must do this save from interrupts, since the attributes collection |
|
1551 |
"/ is possibly accessed from multiple threads ... |
|
1552 |
[ |
|
6654 | 1553 |
| attrs | |
1554 |
||
1555 |
attrs := self objectAttributes. |
|
1556 |
(attrs isNil or:[attrs size == 0]) ifTrue:[ |
|
1557 |
attrs := WeakIdentityDictionary new. |
|
1558 |
attrs at:attributeKey put:anObject. |
|
1559 |
self objectAttributes:attrs. |
|
1560 |
] ifFalse:[ |
|
1561 |
attrs at:attributeKey put:anObject. |
|
1562 |
]. |
|
6323 | 1563 |
] valueUninterruptably |
5755 | 1564 |
|
1565 |
"Attaching additional attributes (slots) to an arbitrary object: |
|
1566 |
||
1567 |
|p| |
|
1568 |
||
1569 |
p := Point new. |
|
1570 |
p objectAttributeAt:#color put:#green. |
|
1571 |
||
1572 |
p objectAttributeAt:#color |
|
1573 |
" |
|
1574 |
||
1575 |
"Created: / 22.1.1998 / 21:29:25 / av" |
|
1576 |
"Modified: / 3.2.1998 / 18:57:58 / cg" |
|
1577 |
! |
|
1578 |
||
1579 |
objectAttributes |
|
1580 |
"return a Collection of attributes - nil if there is none. |
|
1581 |
The default implementation here uses a global WeakDictionary to store |
|
1582 |
attributes |
|
1583 |
This may be too slow for high frequency slot access, |
|
1584 |
therefore, some classes may redefine this for better performance. |
|
1585 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
1586 |
||
1587 |
^ ObjectAttributes at:self ifAbsent:[nil] |
|
1588 |
||
1589 |
"Created: / 22.1.1998 / 21:29:30 / av" |
|
1590 |
"Modified: / 18.2.2000 / 11:34:16 / cg" |
|
1591 |
! |
|
1592 |
||
1593 |
objectAttributes:aCollection |
|
1594 |
"set the collection of attributes. |
|
1595 |
The default implementation here uses a global Dictionary to store |
|
1596 |
attributes which may be too slow for high frequency change&update. |
|
1597 |
Therefore, some classes may redefine this for better performance." |
|
1598 |
||
1599 |
"/ must do this save from interrupts, since the attributes collection |
|
1600 |
"/ is possibly accessed from multiple threads. |
|
1601 |
||
1602 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
6654 | 1603 |
"/ the common case - already blocked |
1604 |
||
1605 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
1606 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1607 |
] ifFalse:[ |
|
1608 |
ObjectAttributes at:self put:aCollection |
|
1609 |
]. |
|
1610 |
^ self |
|
5755 | 1611 |
]. |
1612 |
||
1613 |
[ |
|
6654 | 1614 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
1615 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1616 |
] ifFalse:[ |
|
1617 |
ObjectAttributes at:self put:aCollection |
|
1618 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
1619 |
] ensure:[ |
6654 | 1620 |
OperatingSystem unblockInterrupts |
5755 | 1621 |
] |
1622 |
||
1623 |
"Created: / 22.1.1998 / 21:29:35 / av" |
|
1624 |
"Modified: / 3.2.1998 / 18:58:10 / cg" |
|
1625 |
! |
|
1626 |
||
6323 | 1627 |
removeObjectAttribute:attributeKey |
5755 | 1628 |
"make the argument, anObject be no attribute of the receiver" |
1629 |
||
1630 |
"/ must do this save from interrupts, since the attributes collection |
|
1631 |
"/ is possibly accessed from multiple threads. |
|
1632 |
[ |
|
6654 | 1633 |
|attrs n a| |
1634 |
||
1635 |
attrs := self objectAttributes. |
|
1636 |
attrs size == 0 ifTrue:[ |
|
1637 |
self objectAttributes:nil |
|
1638 |
] ifFalse:[ |
|
1639 |
attrs removeKey:attributeKey ifAbsent:nil. |
|
1640 |
attrs size == 0 ifTrue:[ |
|
1641 |
self objectAttributes:nil |
|
1642 |
] |
|
1643 |
] |
|
6323 | 1644 |
] valueUninterruptably |
5755 | 1645 |
|
1646 |
"Created: / 22.1.1998 / 21:29:39 / av" |
|
1647 |
"Modified: / 18.2.2000 / 11:32:19 / cg" |
|
1648 |
! ! |
|
1649 |
||
1650 |
!Object methodsFor:'binary storage'! |
|
1651 |
||
6900 | 1652 |
binaryStoreBytes |
1653 |
^ ByteArray streamContents:[:s | self storeBinaryOn:s]. |
|
1654 |
||
1655 |
" |
|
1656 |
#('hello' 1 1.234) binaryStoreBytes |
|
1657 |
" |
|
1658 |
! |
|
1659 |
||
5755 | 1660 |
hasSpecialBinaryRepresentation |
1661 |
"return true, if the receiver has a special binary representation; |
|
1662 |
default here is false, but can be redefined in class which provide |
|
1663 |
their own storeBinary/readBinary methods. |
|
1664 |
||
1665 |
Normal user classes should not use this, it is meant as a hook for |
|
1666 |
special classes such as True, False, UndefinedObject or SmallInteger. |
|
1667 |
||
1668 |
If your instances should be stored in a special way, see |
|
1669 |
#representBinaryOn: and #readBinaryContentsFromdata:manager:." |
|
1670 |
||
1671 |
^ false |
|
1672 |
! |
|
1673 |
||
1674 |
readBinaryContentsFrom:stream manager:manager |
|
1675 |
"reconstruct the receivers instance variables by reading a binary |
|
1676 |
binary representation from stream. |
|
1677 |
This is a general implementation, walking over instances |
|
1678 |
and loading each recursively using manager. |
|
1679 |
Redefined by some classes to read a more compact representations |
|
1680 |
(see String, SmallInteger etc). |
|
1681 |
||
1682 |
Notice, that the object is already recreated as an empty corps |
|
1683 |
with instance variables all nil and bit-instances (bytes, words etc.) |
|
1684 |
already read and restored. |
|
1685 |
||
1686 |
Also notice: this method is not called for if a private representation |
|
1687 |
has been stored (see representBinaryOn:). |
|
1688 |
In that case, #readBinaryContentsFromData:manager: is called, which |
|
1689 |
has to be reimplemented in the objects class." |
|
1690 |
||
1691 |
|size "{ Class: SmallInteger }" |
|
1692 |
instvarArray| |
|
1693 |
||
1694 |
stream next == 1 ifTrue:[ |
|
6654 | 1695 |
"/ |
1696 |
"/ special representation ... |
|
1697 |
"/ |
|
1698 |
instvarArray := Array new:(size := stream nextNumber:3). |
|
1699 |
1 to:size do:[:i | |
|
1700 |
instvarArray basicAt:i put:(manager nextObject) |
|
1701 |
]. |
|
1702 |
self readBinaryContentsFromData:instvarArray manager:manager. |
|
1703 |
^ self |
|
5755 | 1704 |
]. |
1705 |
||
1706 |
"/ |
|
1707 |
"/ standard representation |
|
1708 |
"/ |
|
1709 |
size := self basicSize. |
|
1710 |
size ~~ 0 ifTrue:[ |
|
6654 | 1711 |
self class isPointers ifTrue:[ |
1712 |
1 to:size do:[:i | |
|
1713 |
self basicAt:i put:(manager nextObject) |
|
1714 |
] |
|
1715 |
] |
|
5755 | 1716 |
]. |
1717 |
size := self class instSize. |
|
1718 |
1 to:size do:[:i | |
|
6654 | 1719 |
self instVarAt:i put:(manager nextObject) |
5755 | 1720 |
]. |
1721 |
! |
|
1722 |
||
1723 |
readBinaryContentsFromData:instvarArray manager:manager |
|
1724 |
"reconstruct the receivers instance variables by filling instance |
|
1725 |
variables with values from instvarArray. This array contains the instvars |
|
1726 |
as specified in #representBinaryOn: when the object was stored. |
|
1727 |
It is the receivers responsibility to set its instance variables in the |
|
1728 |
same order from that array." |
|
1729 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
1730 |
^ self subclassResponsibility:'method must be reimplemented in subclass for binary storage' |
5755 | 1731 |
|
1732 |
"typical implementation (see also comment in #representBinaryOn:) |
|
1733 |
(for an object with foo, bar and baz as instance variables, |
|
1734 |
which did not store baz and wants baz to be reinitialized to |
|
1735 |
some constant string) |
|
1736 |
||
6654 | 1737 |
foo := instvarArray at:1. |
1738 |
bar := instvarArray at:2. |
|
1739 |
baz := 'aConstant'. |
|
5755 | 1740 |
" |
1741 |
! |
|
1742 |
||
1743 |
representBinaryOn:manager |
|
1744 |
"this method is called by the storage manager to ask objects |
|
1745 |
if they wish to provide their own binary representation. |
|
1746 |
||
1747 |
If they want to do so, they should return an array containing all |
|
1748 |
instance variables (named & indexed pointer) to be stored. |
|
1749 |
If not redefined, this method returns nil which means that all |
|
1750 |
instance variables are to be stored. |
|
1751 |
||
1752 |
It should be redefined in objects which do not want all instance variables |
|
1753 |
to be stored (for example: objects which keep references to a view etc.). |
|
1754 |
||
1755 |
If this is redefined returning non-nil, the corresponding class needs |
|
1756 |
a redefined instance method named #readBinaryContentsFromData:manager: |
|
1757 |
which has to fill the receivers named (and optionally indexed pointer) |
|
1758 |
instance variables with corresponding values from a data array." |
|
1759 |
||
1760 |
^ nil |
|
1761 |
||
1762 |
"typical implementation: |
|
1763 |
(see also comment in #readBinaryContentsFromData:manager:) |
|
1764 |
for an object with foo, bar and baz as instance variables, |
|
1765 |
which does not want to store baz: |
|
1766 |
||
1767 |
representBinaryOn:manager |
|
6654 | 1768 |
|data| |
1769 |
||
1770 |
data := Array new:2. |
|
1771 |
data at:1 put:foo. |
|
1772 |
data at:2 put:bar. |
|
1773 |
^ data |
|
5755 | 1774 |
" |
1775 |
! |
|
1776 |
||
1777 |
storeBinaryDefinitionBodyOn:stream manager:manager |
|
1778 |
"append a binary representation of the receivers body onto stream. |
|
1779 |
This is a general implementation walking over instances storing |
|
1780 |
each recursively as an ID using manager. |
|
1781 |
Can be redefined in subclasses." |
|
1782 |
||
1783 |
|basicSize "{ Class: SmallInteger }" |
|
1784 |
instSize "{ Class: SmallInteger }" |
|
1785 |
specialSize "{ Class: SmallInteger }" |
|
1786 |
myClass specialRep pointers| |
|
1787 |
||
1788 |
myClass := self class. |
|
1789 |
instSize := myClass instSize. |
|
1790 |
||
1791 |
(pointers := myClass isPointers) ifTrue:[ |
|
6654 | 1792 |
"/ |
1793 |
"/ inst size not needed - if you uncomment the line below, |
|
1794 |
"/ also uncomment the corresponding line in |
|
1795 |
"/ Object>>binaryDefinitionFrom:manager: |
|
1796 |
"/ |
|
1797 |
"/ stream nextPut:instSize. "mhmh this limits us to 255 named instvars" |
|
1798 |
||
1799 |
myClass isVariable ifTrue:[ |
|
1800 |
stream nextNumber:3 put:(basicSize := self basicSize) |
|
1801 |
] ifFalse:[ |
|
1802 |
basicSize := 0 |
|
1803 |
]. |
|
5755 | 1804 |
] ifFalse: [ |
6654 | 1805 |
stream nextNumber:4 put:(basicSize := self basicSize). |
1806 |
myClass isBytes ifTrue:[ |
|
1807 |
1 to:basicSize do:[:i | |
|
1808 |
stream nextPut:(self basicAt:i) |
|
1809 |
] |
|
1810 |
] ifFalse:[ |
|
1811 |
myClass isWords ifTrue:[ |
|
1812 |
1 to:basicSize do:[:i | |
|
1813 |
stream nextNumber:2 put:(self basicAt: i) |
|
1814 |
] |
|
1815 |
] ifFalse:[ |
|
1816 |
myClass isLongs ifTrue:[ |
|
1817 |
1 to:basicSize do:[:i | |
|
1818 |
stream nextNumber:4 put:(self basicAt: i) |
|
1819 |
] |
|
1820 |
] ifFalse:[ |
|
1821 |
myClass isFloats ifTrue:[ |
|
1822 |
"could do it in one big write on machines which use IEEE floats ..." |
|
1823 |
1 to:basicSize do:[:i | |
|
1824 |
Float storeBinaryIEEESingle:(self basicAt:i) on:stream |
|
1825 |
] |
|
1826 |
] ifFalse:[ |
|
1827 |
myClass isDoubles ifTrue:[ |
|
1828 |
"could do it in one big write on machines which use IEEE doubles ..." |
|
1829 |
1 to:basicSize do:[:i | |
|
1830 |
Float storeBinaryIEEEDouble:(self basicAt:i) on:stream |
|
1831 |
] |
|
1832 |
] ifFalse:[ |
|
1833 |
"/ should never be reached ... |
|
1834 |
1 to:basicSize do:[:i | |
|
1835 |
manager putIdOf:(self basicAt:i) on:stream |
|
1836 |
] |
|
1837 |
] |
|
1838 |
] |
|
1839 |
] |
|
1840 |
] |
|
1841 |
]. |
|
5755 | 1842 |
]. |
1843 |
||
1844 |
(pointers or:[instSize ~~ 0]) ifTrue:[ |
|
6654 | 1845 |
specialRep := self representBinaryOn:manager. |
1846 |
specialRep notNil ifTrue:[ |
|
1847 |
specialSize := specialRep basicSize. |
|
1848 |
stream nextPut:1. "/ means: private representation follows |
|
1849 |
stream nextNumber:3 put:specialSize. |
|
1850 |
||
1851 |
1 to:specialSize do:[:i | |
|
1852 |
manager putIdOf:(specialRep at:i) on:stream |
|
1853 |
]. |
|
1854 |
] ifFalse:[ |
|
1855 |
stream nextPut:0. "/ means: normal representation follows |
|
1856 |
"/ index pointers followed by named instanceVars |
|
1857 |
pointers ifTrue:[ |
|
1858 |
basicSize ~~ 0 ifTrue:[ |
|
1859 |
1 to:basicSize do:[:i | |
|
1860 |
manager putIdOf:(self basicAt:i) on:stream |
|
1861 |
]. |
|
1862 |
]. |
|
1863 |
]. |
|
1864 |
instSize ~~ 0 ifTrue:[ |
|
1865 |
1 to:instSize do:[:i | |
|
1866 |
manager putIdOf:(self instVarAt:i) on:stream |
|
1867 |
] |
|
1868 |
]. |
|
1869 |
] |
|
5755 | 1870 |
] |
1871 |
||
1872 |
"Modified: / 2.11.1997 / 14:43:29 / cg" |
|
1873 |
! |
|
1874 |
||
1875 |
storeBinaryDefinitionOn:stream manager:manager |
|
1876 |
"append a binary representation of the receiver onto stream. |
|
1877 |
This is an internal interface for binary storage mechanism. |
|
1878 |
This method first stores the class, then the body, which is done |
|
1879 |
in a separate method to allow redefinition of the bodies format. |
|
1880 |
Can be redefined in subclasses to write more compact representations |
|
1881 |
(see String, SmallInteger etc)." |
|
1882 |
||
1883 |
manager putIdOfClass:(self class) on:stream. |
|
1884 |
self storeBinaryDefinitionBodyOn:stream manager:manager |
|
1885 |
||
1886 |
"Modified: 23.4.1996 / 09:31:12 / cg" |
|
1887 |
! |
|
1888 |
||
1889 |
storeBinaryOn:aStreamOrFilename |
|
1890 |
"Writes a description of the receiver onto aStreamOrFilename, in a way that allows |
|
1891 |
the object's structure to be reconstructed from the stream's contents" |
|
1892 |
||
1893 |
BinaryOutputManager store:self on:aStreamOrFilename |
|
1894 |
||
1895 |
" |
|
1896 |
|a s1 s2| |
|
1897 |
||
1898 |
s1 := 'hello'. |
|
1899 |
s2 := 'world'. |
|
1900 |
a := Array new:5. |
|
1901 |
a at:1 put:s1. |
|
1902 |
a at:2 put:s2. |
|
1903 |
a at:3 put:s1. |
|
1904 |
a at:4 put:s2. |
|
1905 |
a storeBinaryOn:'test.boss' |
|
1906 |
" |
|
1907 |
||
1908 |
" |
|
1909 |
(BinaryObjectStorage onOld:'test.boss' asFilename readStream) |
|
6654 | 1910 |
next |
1911 |
inspect |
|
5755 | 1912 |
" |
1913 |
||
1914 |
"Modified: / 1.11.1997 / 21:16:24 / cg" |
|
1915 |
! |
|
1916 |
||
1917 |
storeBinaryOn:stream manager:manager |
|
1918 |
"append a binary representation of the receiver onto stream." |
|
1919 |
||
1920 |
manager putIdOf:self on:stream |
|
1921 |
! ! |
|
1922 |
||
1923 |
!Object methodsFor:'change & update'! |
|
1924 |
||
1925 |
broadcast:aSelectorSymbol |
|
1926 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1927 |
||
1928 |
self dependentsDo:[:dependent | |
|
6654 | 1929 |
dependent perform:aSelectorSymbol |
5755 | 1930 |
] |
1931 |
! |
|
1932 |
||
1933 |
broadcast:aSelectorSymbol with:anArgument |
|
1934 |
"send a message with selector aSelectorSymbol with an additional |
|
1935 |
argument anArgument to all my dependents." |
|
1936 |
||
1937 |
self dependentsDo:[:dependent | |
|
6654 | 1938 |
dependent perform:aSelectorSymbol with:anArgument |
5755 | 1939 |
] |
1940 |
! |
|
1941 |
||
1942 |
changeRequest |
|
1943 |
"the receiver wants to change - check if all dependents |
|
1944 |
grant the request, and return true if so" |
|
1945 |
||
1946 |
self dependentsDo:[:dependent | |
|
6654 | 1947 |
dependent updateRequest ifFalse:[^ false]. |
5755 | 1948 |
]. |
1949 |
^ true |
|
1950 |
! |
|
1951 |
||
1952 |
changeRequest:aParameter |
|
1953 |
"the receiver wants to change - check if all dependents |
|
1954 |
grant the request, and return true if so" |
|
1955 |
||
1956 |
self dependentsDo:[:dependent | |
|
6654 | 1957 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
5755 | 1958 |
]. |
1959 |
^ true |
|
1960 |
! |
|
1961 |
||
1962 |
changeRequest:aParameter from:anObject |
|
1963 |
"the receiver wants to change - check if all dependents |
|
1964 |
except anObject grant the request, and return true if so. |
|
1965 |
The argument anObject is typically going to be the one who is |
|
1966 |
about to send the change request." |
|
1967 |
||
1968 |
self dependentsDo:[:dependent | |
|
6654 | 1969 |
dependent == anObject ifFalse:[ |
1970 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
1971 |
] |
|
5755 | 1972 |
]. |
1973 |
^ true |
|
1974 |
! |
|
1975 |
||
1976 |
changeRequestFrom:anObject |
|
1977 |
"the receiver wants to change - check if all dependents |
|
1978 |
except anObject grant the request, and return true if so. |
|
1979 |
The argument anObject is typically going to be the one who is |
|
1980 |
about to send the change request." |
|
1981 |
||
1982 |
self dependentsDo:[:dependent | |
|
6654 | 1983 |
dependent == anObject ifFalse:[ |
1984 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1985 |
] |
|
5755 | 1986 |
]. |
1987 |
^ true |
|
1988 |
! |
|
1989 |
||
1990 |
changed |
|
1991 |
"notify all dependents that the receiver has changed. |
|
1992 |
Each dependent gets a '#update:'-message with the original |
|
1993 |
receiver as argument." |
|
1994 |
||
1995 |
self changed:nil |
|
1996 |
! |
|
1997 |
||
1998 |
changed:aParameter |
|
1999 |
"notify all dependents that the receiver has changed somehow. |
|
2000 |
Each dependent gets a '#update:'-message with aParameter |
|
2001 |
as argument." |
|
2002 |
||
2003 |
self changed:aParameter with:nil |
|
2004 |
! |
|
2005 |
||
2006 |
changed:aParameter with:anArgument |
|
2007 |
"notify all dependents that the receiver has changed somehow. |
|
2008 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
|
2009 |
and anArgument as arguments." |
|
2010 |
||
2011 |
self dependentsDo:[:dependent | |
|
6654 | 2012 |
dependent update:aParameter with:anArgument from:self |
5755 | 2013 |
] |
2014 |
! |
|
2015 |
||
2016 |
update:aParameter |
|
2017 |
"the message is sent to a dependent, when one of the objects |
|
2018 |
on whom the receiver depends, has changed. The argument aParameter |
|
2019 |
is either the changed object or the argument to the #changed: message. |
|
2020 |
||
2021 |
Default behavior here is to do nothing" |
|
2022 |
||
2023 |
^ self |
|
2024 |
! |
|
2025 |
||
2026 |
update:aParameter with:anArgument |
|
2027 |
"dependent is notified of some change - |
|
2028 |
Default is to try update:" |
|
2029 |
||
2030 |
^ self update:aParameter |
|
2031 |
! |
|
2032 |
||
2033 |
update:aParameter with:anArgument from:sender |
|
2034 |
"dependent is notified of some change - |
|
2035 |
Default is to try update:with:" |
|
2036 |
||
2037 |
^ self update:aParameter with:anArgument |
|
2038 |
! |
|
2039 |
||
2040 |
updateRequest |
|
2041 |
"return true, if an update request is granted. |
|
2042 |
Default here is to grant updates - may be used |
|
2043 |
to lock updates if someone is making other changes |
|
2044 |
from within an update. Or if someone has locked its |
|
2045 |
state and does not want others to change things. |
|
2046 |
However, these dependents must all honor the |
|
2047 |
changeRequest - ifTrue - change protocol. I.e. they |
|
2048 |
must first ask all others via changeRequest, and only do the change |
|
2049 |
it returns true. The others must decide in updateRequest and |
|
2050 |
return true if they think a change is ok." |
|
2051 |
||
2052 |
^ true |
|
2053 |
! |
|
2054 |
||
2055 |
updateRequest:aSymbol |
|
2056 |
"return true, if an update request is granted. |
|
2057 |
Default here a simple updateRequest" |
|
2058 |
||
2059 |
^ self updateRequest |
|
7177 | 2060 |
! |
2061 |
||
2062 |
withoutUpdating:someone do:aBlock |
|
2063 |
"evaluate a block but remove someone from my dependents temporarily" |
|
2064 |
||
2065 |
(self dependents includesIdentical:someone) |
|
2066 |
ifFalse:[ |
|
2067 |
^ aBlock value. |
|
2068 |
]. |
|
2069 |
self removeDependent:someone. |
|
2070 |
^ aBlock ensure:[ self addDependent:someone ] |
|
5755 | 2071 |
! ! |
2072 |
||
2073 |
!Object methodsFor:'cleanup'! |
|
2074 |
||
2075 |
lowSpaceCleanup |
|
2076 |
"ignored here - redefined in some classes to |
|
2077 |
cleanup in low-memory situations" |
|
2078 |
||
2079 |
^ self |
|
2080 |
! ! |
|
2081 |
||
2082 |
!Object methodsFor:'comparing'! |
|
2083 |
||
2084 |
= anObject |
|
2085 |
"return true, if the receiver and the arg have the same structure. |
|
2086 |
Notice: |
|
6654 | 2087 |
This method is partially open coded (inlined) by the compiler(s) |
2088 |
identical objects are always considered equal. |
|
2089 |
redefining it may not work as expected." |
|
5755 | 2090 |
|
2091 |
^ self == anObject |
|
2092 |
! |
|
2093 |
||
2094 |
== anObject |
|
2095 |
"return true, if the receiver and the arg are the same object. |
|
2096 |
Never redefine this in any class. |
|
2097 |
Notice: |
|
6654 | 2098 |
This method is open coded (inlined) by the compiler(s) |
2099 |
- redefining it may not work as expected." |
|
5755 | 2100 |
|
2101 |
%{ /* NOCONTEXT */ |
|
2102 |
||
2103 |
RETURN ( (self == anObject) ? true : false ); |
|
2104 |
%} |
|
2105 |
! |
|
2106 |
||
5814 | 2107 |
deepSameContentsAs:anObject |
2108 |
"return true, if the receiver and the arg have the same contents |
|
2109 |
in both the named instance vars and any indexed instVars. |
|
2110 |
This method descends into referenced objects, where #sameContentsAs: does not descend" |
|
2111 |
||
5821 | 2112 |
|myClass val |
5814 | 2113 |
sz "{ Class: SmallInteger }" | |
2114 |
||
2115 |
myClass := self class. |
|
2116 |
myClass isVariable ifTrue:[ |
|
6654 | 2117 |
sz := self basicSize. |
2118 |
||
2119 |
"compare the indexed variables" |
|
2120 |
1 to:sz do:[:i | |
|
2121 |
val := self basicAt:i. |
|
2122 |
val isLiteral ifTrue:[ |
|
2123 |
val = (anObject basicAt:i) ifFalse:[^ false]. |
|
2124 |
] ifFalse:[ |
|
2125 |
(val deepSameContentsAs:(anObject basicAt:i)) ifFalse:[^ false]. |
|
2126 |
] |
|
2127 |
] |
|
5814 | 2128 |
]. |
2129 |
||
2130 |
"compare the instance variables" |
|
2131 |
sz := myClass instSize. |
|
2132 |
1 to:sz do:[:i | |
|
6654 | 2133 |
val := self instVarAt:i. |
2134 |
val isLiteral ifTrue:[ |
|
2135 |
val = (anObject instVarAt:i) ifFalse:[^ false]. |
|
2136 |
] ifFalse:[ |
|
2137 |
(val deepSameContentsAs:(anObject instVarAt:i)) ifFalse:[^ false]. |
|
2138 |
] |
|
5814 | 2139 |
]. |
2140 |
||
2141 |
^ true |
|
2142 |
||
2143 |
" |
|
2144 |
#(1 2 3 4) deepSameContentsAs:#[1 2 3 4] asArray |
|
2145 |
(1@2) deepSameContentsAs:(1->2) |
|
2146 |
" |
|
2147 |
! |
|
2148 |
||
5755 | 2149 |
hash |
2150 |
"return an Integer useful as a hash key for the receiver. |
|
2151 |
This hash should return same values for objects with same |
|
2152 |
contents (i.e. use this to hash on structure)" |
|
2153 |
||
2154 |
^ self identityHash |
|
2155 |
! |
|
2156 |
||
2157 |
identityHash |
|
2158 |
"return an Integer useful as a hash key for the receiver. |
|
2159 |
This hash should return same values for the same object (i.e. use |
|
2160 |
this to hash on identity of objects). |
|
2161 |
||
2162 |
We cannot use the Objects address (as other smalltalks do) since |
|
2163 |
no object-table exists and the hashval must not change when objects |
|
2164 |
are moved by the collector. Therefore we assign each object a unique |
|
2165 |
Id in the object header itself as its hashed upon. |
|
2166 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
2167 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
2168 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
2169 |
hashed-upon objects could add an instvar containing the hash value." |
|
2170 |
||
2171 |
%{ /* NOCONTEXT */ |
|
2172 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2173 |
REGISTER unsigned INT hash; |
5755 | 2174 |
static unsigned nextHash = 0; |
2175 |
||
2176 |
if (__isNonNilObject(self)) { |
|
6654 | 2177 |
hash = __GET_HASH(self); |
2178 |
if (hash == 0) { |
|
2179 |
/* has no hash yet */ |
|
2180 |
||
2181 |
if (++nextHash > __MAX_HASH__) { |
|
2182 |
nextHash = 1; |
|
2183 |
} |
|
2184 |
hash = nextHash; |
|
2185 |
__SET_HASH(self, hash); |
|
2186 |
} |
|
2187 |
||
2188 |
/* |
|
2189 |
* now, we got 11 bits for hashing; |
|
2190 |
* make it as large as possible; since most hashers use the returned |
|
2191 |
* key and take it modulo some prime number, this will allow for |
|
2192 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2193 |
*/ |
|
2194 |
hash = __MAKE_HASH__(hash); |
|
2195 |
RETURN ( __MKSMALLINT(hash) ); |
|
5755 | 2196 |
} |
2197 |
%}. |
|
2198 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
2199 |
! |
|
2200 |
||
2201 |
identityHashForBinaryStore |
|
2202 |
"hash which is usable if the object does not change its class |
|
2203 |
and does not #become something else, while the hash is used. |
|
2204 |
This is only used by the binary storage mechanism, during the |
|
2205 |
object writing phase." |
|
2206 |
||
2207 |
%{ /* NOCONTEXT */ |
|
2208 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2209 |
REGISTER unsigned INT hash, hash1, hash2, sz; |
5755 | 2210 |
OBJ o; |
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2211 |
static unsigned INT nextHash = 0; |
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2212 |
static unsigned INT nextClassHash = 0; |
5755 | 2213 |
|
2214 |
if (__isNonNilObject(self)) { |
|
6654 | 2215 |
/* |
2216 |
* my own identityHash |
|
2217 |
*/ |
|
2218 |
hash1 = __GET_HASH(self); |
|
2219 |
if (hash1 == 0) { |
|
2220 |
/* has no hash yet */ |
|
2221 |
||
2222 |
if (++nextHash > __MAX_HASH__) { |
|
2223 |
nextHash = 1; |
|
2224 |
} |
|
2225 |
hash1 = nextHash; |
|
2226 |
__SET_HASH(self, hash1); |
|
2227 |
} |
|
2228 |
/* |
|
2229 |
* my classes identityHash |
|
2230 |
*/ |
|
2231 |
o = __qClass(self); |
|
2232 |
hash2 = __GET_HASH(o); |
|
2233 |
if (hash2 == 0) { |
|
2234 |
/* has no hash yet */ |
|
2235 |
||
2236 |
if (++nextClassHash > __MAX_HASH__) { |
|
2237 |
nextClassHash = 1; |
|
2238 |
} |
|
2239 |
hash2 = nextClassHash; |
|
2240 |
__SET_HASH(o, hash2); |
|
2241 |
} |
|
2242 |
||
2243 |
/* |
|
2244 |
* some bits of my size |
|
2245 |
*/ |
|
2246 |
sz = __qSize(self); |
|
2247 |
||
2248 |
/* |
|
2249 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
2250 |
* make it as large as possible; since most hashers use the returned |
|
2251 |
* key and take it modulo some prime number, this will allow for |
|
2252 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2253 |
*/ |
|
2254 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
2255 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
2256 |
||
2257 |
while ((hash & 0x20000000) == 0) { |
|
2258 |
hash <<= 1; |
|
2259 |
} |
|
2260 |
||
2261 |
RETURN ( __MKSMALLINT(hash) ); |
|
5755 | 2262 |
} |
2263 |
%}. |
|
2264 |
"never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
|
2265 |
^ self identityHash |
|
2266 |
! |
|
2267 |
||
2268 |
sameContentsAs:anObject |
|
2269 |
"return true, if the receiver and the arg have the same contents |
|
7121 | 2270 |
in both the named instance vars and any indexed instVars. |
2271 |
The code here only checks if values present in the receiver are also |
|
2272 |
present in the arg, not vice versa. |
|
2273 |
I.e. the argument may be bigger and/or have more instance variables." |
|
5755 | 2274 |
|
5821 | 2275 |
|myClass |
5755 | 2276 |
sz "{ Class: SmallInteger }" | |
2277 |
||
2278 |
myClass := self class. |
|
2279 |
myClass isVariable ifTrue:[ |
|
6654 | 2280 |
sz := self basicSize. |
7121 | 2281 |
anObject basicSize >= sz ifFalse:[^ false]. |
6654 | 2282 |
|
2283 |
"compare the indexed variables" |
|
2284 |
1 to:sz do:[:i | |
|
2285 |
(self basicAt:i) == (anObject basicAt:i) ifFalse:[^ false]. |
|
2286 |
] |
|
5755 | 2287 |
]. |
2288 |
||
2289 |
"compare the instance variables" |
|
2290 |
sz := myClass instSize. |
|
7121 | 2291 |
anObject instSize >= sz ifFalse:[^ false]. |
2292 |
||
5755 | 2293 |
1 to:sz do:[:i | |
6654 | 2294 |
(self instVarAt:i) == (anObject instVarAt:i) ifFalse:[^ false]. |
5755 | 2295 |
]. |
2296 |
||
2297 |
^ true |
|
2298 |
||
2299 |
" |
|
5814 | 2300 |
#(1 2 3 4) sameContentsAs:#[1 2 3 4] asArray |
2301 |
(1@2) sameContentsAs:(1->2) |
|
5755 | 2302 |
" |
2303 |
||
2304 |
"Created: / 21.4.1998 / 15:56:40 / cg" |
|
2305 |
"Modified: / 21.4.1998 / 15:58:15 / cg" |
|
2306 |
! |
|
2307 |
||
2308 |
~= anObject |
|
2309 |
"return true, if the receiver and the arg do not have the same structure. |
|
2310 |
Notice: |
|
6654 | 2311 |
This method is partially open coded (inlined) by the compiler(s) |
2312 |
identical objects are never considered unequal. |
|
2313 |
redefining it may not work as expected." |
|
5755 | 2314 |
|
2315 |
^ (self = anObject) not |
|
2316 |
! |
|
2317 |
||
2318 |
~~ anObject |
|
2319 |
"return true, if the receiver and the arg are not the same object. |
|
2320 |
Never redefine this in any class. |
|
2321 |
Notice: |
|
6654 | 2322 |
This method is open coded (inlined) by the compiler(s) |
2323 |
- redefining it may not work as expected." |
|
5755 | 2324 |
|
2325 |
%{ /* NOCONTEXT */ |
|
2326 |
RETURN ( (self == anObject) ? false : true ); |
|
2327 |
%} |
|
2328 |
! ! |
|
2329 |
||
2330 |
!Object methodsFor:'converting'! |
|
2331 |
||
6696
36eaa6c17e2c
use excla for conses (looks better);
Claus Gittinger <cg@exept.de>
parents:
6656
diff
changeset
|
2332 |
!! anObject |
6652
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2333 |
"return a cons with the receiver as car and the argument as cdr" |
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2334 |
|
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2335 |
^ Cons car:self cdr:anObject |
6697 | 2336 |
|
2337 |
" |
|
6698 | 2338 |
(1 !! 2) |
2339 |
(#car !! #cdr) |
|
2340 |
(1 !! (2 !! (3 !! nil))) |
|
2341 |
(1 !! 2) !! (2 !! 3) |
|
6697 | 2342 |
" |
6652
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2343 |
! |
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2344 |
|
5755 | 2345 |
-> anObject |
2346 |
"return an association with the receiver as key and |
|
2347 |
the argument as value" |
|
2348 |
||
2349 |
^ Association key:self value:anObject |
|
2350 |
! |
|
2351 |
||
2352 |
asCollection |
|
2353 |
"return myself as a Collection. |
|
2354 |
Redefined in collection to return themself." |
|
2355 |
||
2356 |
^ Array with:self |
|
2357 |
! |
|
2358 |
||
2359 |
asSequenceableCollection |
|
2360 |
"return myself as a SequenceableCollection. |
|
2361 |
Redefined in SequenceableCollection" |
|
2362 |
||
2363 |
^ Array with:self |
|
2364 |
! |
|
2365 |
||
2366 |
asValue |
|
2367 |
"return a valueHolder for for the receiver" |
|
2368 |
||
2369 |
^ ValueHolder with:self |
|
6146 | 2370 |
! |
2371 |
||
2372 |
collect |
|
2373 |
"return mySelf" |
|
2374 |
||
2375 |
^ self |
|
2376 |
! |
|
2377 |
||
2378 |
deepCollect |
|
2379 |
"return mySelf" |
|
2380 |
||
2381 |
^ self |
|
2382 |
! |
|
2383 |
||
2384 |
deepSelect |
|
2385 |
"return mySelf" |
|
2386 |
||
2387 |
^ self |
|
2388 |
! |
|
2389 |
||
2390 |
select |
|
2391 |
"return mySelf" |
|
2392 |
||
2393 |
^ self |
|
5755 | 2394 |
! ! |
2395 |
||
2396 |
!Object methodsFor:'copying'! |
|
2397 |
||
2398 |
cloneFrom:anObject |
|
2399 |
"Helper for copy: |
|
2400 |
copy all instance variables from anObject into the receiver, |
|
2401 |
which should be of the same class as the argument." |
|
2402 |
||
2403 |
self cloneFrom:anObject performing:#yourself |
|
2404 |
||
2405 |
" |
|
2406 |
|x| |
|
2407 |
||
2408 |
x := Array new:3. |
|
2409 |
x cloneFrom:#(1 2 3). |
|
2410 |
" |
|
2411 |
! |
|
2412 |
||
2413 |
cloneFrom:anObject performing:aSymbol |
|
2414 |
"Helper for copy: |
|
2415 |
for each instance variables from anObject, send it aSymbol |
|
2416 |
and store the result into the receiver, |
|
2417 |
which should be of the same class as the argument." |
|
2418 |
||
2419 |
|myClass sz "{ Class: SmallInteger }" t | |
|
2420 |
||
2421 |
myClass := self class. |
|
2422 |
myClass isVariable ifTrue:[ |
|
6654 | 2423 |
sz := self basicSize. |
2424 |
||
2425 |
"copy the indexed variables" |
|
2426 |
1 to:sz do:[:i | |
|
2427 |
t := anObject basicAt:i. |
|
2428 |
aSymbol ~~ #yourself ifTrue:[ |
|
2429 |
t := t perform:aSymbol. |
|
2430 |
]. |
|
2431 |
self basicAt:i put:t. |
|
2432 |
] |
|
5755 | 2433 |
]. |
2434 |
||
2435 |
"copy the instance variables" |
|
2436 |
sz := myClass instSize. |
|
2437 |
1 to:sz do:[:i | |
|
6654 | 2438 |
t := anObject instVarAt:i. |
2439 |
aSymbol ~~ #yourself ifTrue:[ |
|
2440 |
t := t perform:aSymbol |
|
2441 |
]. |
|
2442 |
self instVarAt:i put:t |
|
5755 | 2443 |
]. |
2444 |
||
2445 |
^ self |
|
2446 |
||
2447 |
! |
|
2448 |
||
2449 |
cloneInstanceVariablesFrom:aPrototype |
|
2450 |
"Shallow copy variables from a prototype into myself. |
|
2451 |
This copies instVars by name - i.e. same-named variables are |
|
2452 |
copied, others are not. |
|
2453 |
The variable slots are copied as available |
|
2454 |
(i.e. the min of both indexed sizes is used)." |
|
2455 |
||
2456 |
|myInfo otherInfo| |
|
2457 |
||
2458 |
myInfo := self class instanceVariableOffsets. |
|
2459 |
otherInfo := aPrototype class instanceVariableOffsets. |
|
2460 |
myInfo keysAndValuesDo:[:name :index | |varIndexAssoc| |
|
6654 | 2461 |
varIndexAssoc := otherInfo at:name ifAbsent:[]. |
2462 |
varIndexAssoc notNil ifTrue:[ |
|
2463 |
self instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
2464 |
] |
|
5755 | 2465 |
]. |
2466 |
self isVariable ifTrue:[ |
|
6654 | 2467 |
1 to:(self basicSize min:aPrototype basicSize) do:[:index | |
2468 |
self basicAt:index put:(aPrototype basicAt:index) |
|
2469 |
]. |
|
5755 | 2470 |
]. |
2471 |
||
2472 |
" |
|
2473 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2474 |
Point subclass:#Point3D |
2475 |
instanceVariableNames:'z' |
|
2476 |
classVariableNames:'' |
|
2477 |
poolDictionaries:'' |
|
2478 |
category:'testing'. |
|
2479 |
(Point3D new cloneInstanceVariablesFrom:1@2) inspect. |
|
5755 | 2480 |
] |
2481 |
" |
|
2482 |
||
2483 |
" |
|
2484 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2485 |
Point variableSubclass:#Point3D |
2486 |
instanceVariableNames:'z' |
|
2487 |
classVariableNames:'' |
|
2488 |
poolDictionaries:'' |
|
2489 |
category:'testing'. |
|
2490 |
((Point3D new:2) cloneInstanceVariablesFrom:#(1 2 3)) inspect. |
|
5755 | 2491 |
] |
2492 |
" |
|
2493 |
||
2494 |
" |
|
2495 |
|someObject| |
|
2496 |
||
2497 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2498 |
Object subclass:#TestClass1 |
2499 |
instanceVariableNames:'foo bar' |
|
2500 |
classVariableNames:'' |
|
2501 |
poolDictionaries:'' |
|
2502 |
category:'testing'. |
|
2503 |
someObject := TestClass1 new. |
|
2504 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
2505 |
Object subclass:#TestClass2 |
|
2506 |
instanceVariableNames:'bar foo' |
|
2507 |
classVariableNames:'' |
|
2508 |
poolDictionaries:'' |
|
2509 |
category:'testing'. |
|
2510 |
(TestClass2 new cloneInstanceVariablesFrom:someObject) inspect. |
|
5755 | 2511 |
] |
2512 |
" |
|
2513 |
||
2514 |
" |
|
2515 |
|top b b1| |
|
2516 |
||
2517 |
top := StandardSystemView new. |
|
2518 |
top extent:100@100. |
|
2519 |
||
2520 |
b := Button in:top. |
|
2521 |
b label:'hello'. |
|
2522 |
||
2523 |
b1 := ArrowButton new cloneInstanceVariablesFrom:b. |
|
2524 |
||
2525 |
top open. |
|
2526 |
b1 inspect |
|
2527 |
" |
|
2528 |
! |
|
2529 |
||
2530 |
copy |
|
2531 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
2532 |
Notice, that copy does not copy dependents." |
|
2533 |
||
2534 |
^ self shallowCopy postCopy |
|
2535 |
! |
|
2536 |
||
6146 | 2537 |
copyToLevel:level |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2538 |
"a controlled deepCopy, where the number of levels can be specified. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2539 |
Notice: |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2540 |
This method DOES NOT handle cycles/self-refs and does NOT preserve object identity; |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2541 |
i.e. identical references in the source are copied multiple into the copy." |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2542 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2543 |
|newObject class index| |
6146 | 2544 |
|
2545 |
level == 1 ifTrue:[^ self shallowCopy]. |
|
2546 |
||
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2547 |
class := self class. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2548 |
newObject := self clone. |
6146 | 2549 |
newObject == self ifTrue: [^ self]. |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2550 |
class isVariable ifTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2551 |
index := self basicSize. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2552 |
[index > 0] whileTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2553 |
newObject basicAt: index put: ((self basicAt: index) copyToLevel:(level-1)). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2554 |
index := index - 1 |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2555 |
] |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2556 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2557 |
index := class instSize. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2558 |
[index > 0] whileTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2559 |
newObject instVarAt: index put: ((self instVarAt: index) copyToLevel:(level-1)). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2560 |
index := index - 1 |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2561 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2562 |
^ newObject |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2563 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2564 |
" |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2565 |
|a b| |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2566 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2567 |
a := #( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2568 |
'1.1' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2569 |
'1.2' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2570 |
'1.3' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2571 |
( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2572 |
'1.41' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2573 |
'1.42' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2574 |
'1.43' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2575 |
( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2576 |
'1.441' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2577 |
'1.442' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2578 |
'1.443' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2579 |
( '1.4441' '1.4442' '1.4443' ) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2580 |
'1.445' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2581 |
) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2582 |
'1.45' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2583 |
) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2584 |
'1.5' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2585 |
). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2586 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2587 |
b := a copyToLevel:1. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2588 |
self assert: ( (a at:1) == (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2589 |
self assert: ( (a at:4) == (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2590 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2591 |
b := a copyToLevel:2. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2592 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2593 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2594 |
self assert: ( ((a at:4) at:1) == ((b at:4) at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2595 |
self assert: ( ((a at:4) at:4) == ((b at:4) at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2596 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2597 |
b := a copyToLevel:3. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2598 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2599 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2600 |
self assert: ( ((a at:4) at:1) ~~ ((b at:4) at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2601 |
self assert: ( ((a at:4) at:4) ~~ ((b at:4) at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2602 |
self assert: ( (((a at:4) at:4) at:1) == (((b at:4) at:4)at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2603 |
self assert: ( (((a at:4) at:4) at:4) == (((b at:4) at:4)at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2604 |
" |
6146 | 2605 |
! |
2606 |
||
5755 | 2607 |
deepCopy |
2608 |
"return a copy of the object with all subobjects also copied. |
|
2609 |
This method DOES handle cycles/self-refs and preserves object identity; |
|
2610 |
however the receivers class is not copied (to avoid the 'total' copy). |
|
2611 |
||
2612 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
2613 |
keeps track of already copied objects. If you are sure, that your |
|
2614 |
copied object does not include duplicates (or you do not care) and |
|
2615 |
no cycles are involved, you can use the old simpleDeepCopy, |
|
2616 |
which avoids this overhead (but may run into trouble). |
|
2617 |
Notice, that deepCopy does not copy dependents." |
|
2618 |
||
2619 |
^ (self deepCopyUsing:(IdentityDictionary new)) postDeepCopyFrom:self |
|
2620 |
||
2621 |
"an example which is not handled by the old deepCopy: |
|
2622 |
||
2623 |
|a| |
|
2624 |
a := Array new:3. |
|
2625 |
a at:3 put:a. |
|
2626 |
a deepCopy inspect |
|
2627 |
" |
|
2628 |
||
2629 |
" |
|
2630 |
|a| |
|
2631 |
a := Color black onDevice:Screen current. |
|
2632 |
a deepCopy inspect |
|
2633 |
" |
|
2634 |
||
2635 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
2636 |
! |
|
2637 |
||
2638 |
deepCopyError |
|
2639 |
"{ Pragma: +optSpace }" |
|
2640 |
||
2641 |
"raise a signal, that deepCopy is not allowed for this object" |
|
2642 |
||
2643 |
^ DeepCopyErrorSignal raise |
|
2644 |
! |
|
2645 |
||
2646 |
deepCopyUsing:aDictionary |
|
2647 |
"a helper for deepCopy; return a copy of the object with |
|
2648 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
2649 |
use the value found there. The class of the receiver is not copied. |
|
2650 |
This method DOES handle cycles/self references." |
|
2651 |
||
2652 |
|myClass aCopy |
|
2653 |
sz "{ Class: SmallInteger }" |
|
2654 |
iOrig iCopy| |
|
2655 |
||
2656 |
myClass := self class. |
|
2657 |
myClass isVariable ifTrue:[ |
|
6654 | 2658 |
sz := self basicSize. |
2659 |
aCopy := myClass basicNew:sz. |
|
5755 | 2660 |
] ifFalse:[ |
6654 | 2661 |
sz := 0. |
2662 |
aCopy := myClass basicNew |
|
5755 | 2663 |
]. |
2664 |
aCopy setHashFrom:self. |
|
2665 |
||
2666 |
aDictionary at:self put:aCopy. |
|
2667 |
||
2668 |
" |
|
2669 |
copy indexed instvars - if any |
|
2670 |
" |
|
2671 |
sz ~~ 0 ifTrue:[ |
|
6654 | 2672 |
myClass isBits ifTrue:[ |
2673 |
"block-copy indexed instvars" |
|
2674 |
aCopy replaceFrom:1 to:sz with:self startingAt:1 |
|
2675 |
] ifFalse:[ |
|
2676 |
"individual deep copy the indexed variables" |
|
2677 |
1 to:sz do:[:i | |
|
2678 |
iOrig := self basicAt:i. |
|
2679 |
iOrig notNil ifTrue:[ |
|
2680 |
(aDictionary includesKey:iOrig) ifTrue:[ |
|
2681 |
iCopy := aDictionary at:iOrig |
|
2682 |
] ifFalse:[ |
|
2683 |
iCopy := (iOrig deepCopyUsing:aDictionary) postDeepCopy |
|
2684 |
]. |
|
2685 |
aCopy basicAt:i put:iCopy |
|
2686 |
] |
|
2687 |
] |
|
2688 |
] |
|
5755 | 2689 |
]. |
2690 |
||
2691 |
" |
|
2692 |
copy the instance variables |
|
2693 |
" |
|
2694 |
sz := myClass instSize. |
|
2695 |
1 to:sz do:[:i | |
|
6654 | 2696 |
(self skipInstvarIndexInDeepCopy:i) ifFalse:[ |
2697 |
iOrig := self instVarAt:i. |
|
2698 |
iOrig notNil ifTrue:[ |
|
2699 |
(aDictionary includesKey:iOrig) ifTrue:[ |
|
2700 |
iCopy := aDictionary at:iOrig |
|
2701 |
] ifFalse:[ |
|
2702 |
iCopy := (iOrig deepCopyUsing:aDictionary) postDeepCopy |
|
2703 |
]. |
|
2704 |
aCopy instVarAt:i put:iCopy |
|
2705 |
] |
|
2706 |
] |
|
5755 | 2707 |
]. |
2708 |
^ aCopy |
|
2709 |
||
2710 |
" |
|
2711 |
|a b c copyOfC| |
|
2712 |
||
2713 |
a := Array with:'hello' with:'world' with:nil. |
|
2714 |
b := 99 @ 999. |
|
2715 |
a at:3 put:b. |
|
2716 |
c := Array with:a with:b with:a. |
|
2717 |
||
2718 |
Transcript showCR: (c at:1) == (c at:3). |
|
2719 |
copyOfC := c deepCopy. |
|
2720 |
Transcript showCR: (copyOfC at:1) == (copyOfC at:3) |
|
2721 |
" |
|
2722 |
! |
|
2723 |
||
2724 |
postCopy |
|
2725 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
2726 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
2727 |
(see there)" |
|
2728 |
||
2729 |
^ self |
|
2730 |
! |
|
2731 |
||
2732 |
postDeepCopy |
|
2733 |
"allows for cleanup after deep copying" |
|
2734 |
||
2735 |
^ self postCopy |
|
2736 |
! |
|
2737 |
||
2738 |
postDeepCopyFrom:aSource |
|
2739 |
"allows for cleanup after deep copying" |
|
2740 |
||
2741 |
^ self postDeepCopy |
|
2742 |
! |
|
2743 |
||
2744 |
setHashFrom:anObject |
|
2745 |
"set my identity-hash key to be the same as anObjects hash key. |
|
2746 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
2747 |
Smalltalks, and may not be available in future ST/X versions. |
|
2748 |
DO NEVER use this for normal application code." |
|
2749 |
||
2750 |
%{ /* NOCONTEXT */ |
|
2751 |
||
2752 |
REGISTER unsigned h; |
|
2753 |
||
2754 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
6654 | 2755 |
h = __GET_HASH(anObject); |
2756 |
__SET_HASH(self, h); |
|
2757 |
RETURN (self); |
|
5755 | 2758 |
} |
2759 |
%}. |
|
2760 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
2761 |
! |
|
2762 |
||
2763 |
shallowCopy |
|
2764 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2765 |
i.e. the copy shares referenced instvars with its original." |
|
2766 |
||
2767 |
%{ /* NOCONTEXT */ |
|
2768 |
int ninsts, spc; |
|
2769 |
int sz; |
|
2770 |
OBJ theCopy; |
|
2771 |
OBJ cls; |
|
2772 |
int flags; |
|
2773 |
||
2774 |
cls = __qClass(self); |
|
2775 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
2776 |
||
2777 |
/* |
|
2778 |
* bail out for special objects .. |
|
2779 |
*/ |
|
2780 |
if (((flags & ~ARRAYMASK) == 0) |
|
2781 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
6654 | 2782 |
sz = __qSize(self); |
2783 |
__PROTECT__(self); |
|
2784 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
2785 |
__UNPROTECT__(self); |
|
2786 |
if (theCopy) { |
|
2787 |
cls = __qClass(self); |
|
2788 |
spc = __qSpace(theCopy); |
|
2789 |
||
2790 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
2791 |
||
2792 |
sz = sz - OHDR_SIZE; |
|
2793 |
if (sz) { |
|
2794 |
char *src, *dst; |
|
2795 |
||
2796 |
src = (char *)(__InstPtr(self)->i_instvars); |
|
2797 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
5755 | 2798 |
#ifdef bcopy4 |
6654 | 2799 |
{ |
2800 |
/* care for odd-number of longs */ |
|
2801 |
int nW = sz >> 2; |
|
2802 |
||
2803 |
if (sz & 3) { |
|
2804 |
nW++; |
|
2805 |
} |
|
2806 |
||
2807 |
bcopy4(src, dst, nW); |
|
2808 |
} |
|
5755 | 2809 |
#else |
6654 | 2810 |
bcopy(src, dst, sz); |
5755 | 2811 |
#endif |
2812 |
||
6654 | 2813 |
flags &= ARRAYMASK; |
2814 |
if (flags == POINTERARRAY) { |
|
2815 |
ninsts = __BYTES2OBJS__(sz); |
|
2816 |
} else { |
|
2817 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
2818 |
} |
|
2819 |
if (ninsts) { |
|
2820 |
do { |
|
2821 |
OBJ el; |
|
2822 |
||
2823 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
2824 |
__STORE_SPC(theCopy, el, spc); |
|
2825 |
} while (--ninsts); |
|
2826 |
} |
|
2827 |
} |
|
2828 |
RETURN (theCopy); |
|
2829 |
} |
|
5755 | 2830 |
} |
2831 |
%}. |
|
2832 |
"/ fallBack for special objects & memoryAllocation failure case |
|
2833 |
||
2834 |
^ self slowShallowCopy |
|
2835 |
! |
|
2836 |
||
2837 |
simpleDeepCopy |
|
2838 |
"return a copy of the object with all subobjects also copied. |
|
2839 |
This method does NOT handle cycles - but is included to allow this |
|
2840 |
slightly faster copy in situations where it is known that |
|
2841 |
no recursive references occur (LargeIntegers for example). |
|
2842 |
NOTICE: you will run into trouble, when trying this with recursive |
|
2843 |
objects (usually recursionInterrupt or memory-alert). |
|
2844 |
This method corresponds to the 'traditional' deepCopy found in |
|
2845 |
the Blue book." |
|
2846 |
||
2847 |
|myClass aCopy| |
|
2848 |
||
2849 |
(myClass := self class) isVariable ifTrue:[ |
|
6654 | 2850 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2851 |
] ifFalse:[ |
6654 | 2852 |
aCopy := myClass basicNew |
5755 | 2853 |
]. |
2854 |
||
2855 |
"copy the instance variables" |
|
2856 |
aCopy cloneFrom:self performing:#simpleDeepCopy. |
|
2857 |
^ aCopy |
|
2858 |
||
2859 |
"a bad example (but ST/X should survive ...)" |
|
2860 |
" |
|
2861 |
|a| |
|
2862 |
a := Array new:3. |
|
2863 |
a at:3 put:a. |
|
2864 |
a simpleDeepCopy |
|
2865 |
" |
|
2866 |
! |
|
2867 |
||
2868 |
skipInstvarIndexInDeepCopy:index |
|
2869 |
"a helper for deepCopy; only indices for which this method returns |
|
2870 |
false are copied in a deep copy. |
|
2871 |
The default is false here - which means that everything is copied. |
|
2872 |
Can be redefined in subclasses for partial copies" |
|
2873 |
||
2874 |
^ false |
|
2875 |
! |
|
2876 |
||
2877 |
slowShallowCopy |
|
2878 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2879 |
i.e. the copy shares referenced instvars with its original. |
|
2880 |
This method is only invoked as a fallback from #shallowCopy." |
|
2881 |
||
2882 |
|myClass aCopy| |
|
2883 |
||
2884 |
(myClass := self class) isVariable ifTrue:[ |
|
6654 | 2885 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2886 |
] ifFalse:[ |
6654 | 2887 |
aCopy := myClass basicNew |
5755 | 2888 |
]. |
2889 |
||
2890 |
"copy the instance variables" |
|
2891 |
aCopy cloneFrom:self performing:#yourself. |
|
2892 |
^ aCopy |
|
2893 |
! ! |
|
2894 |
||
2895 |
!Object methodsFor:'debugging'! |
|
2896 |
||
6961 | 2897 |
assert:aBoolean |
6964 | 2898 |
"fail, if the argument is not true and report an error" |
2899 |
||
6961 | 2900 |
"{ Pragma: +optSpace }" |
2901 |
||
2902 |
self assert:aBoolean message:'Assertion failed' |
|
2903 |
! |
|
2904 |
||
2905 |
assert:aBoolean message:messageIfFailing |
|
6964 | 2906 |
"fail, if the argument is not true and report an error" |
6961 | 2907 |
|
2908 |
"{ Pragma: +optSpace }" |
|
2909 |
||
2910 |
(aBoolean isBoolean) ifFalse:[ |
|
2911 |
self error:'non boolean assertion' |
|
2912 |
]. |
|
2913 |
aBoolean ifFalse:[ |
|
2914 |
self error:messageIfFailing |
|
2915 |
]. |
|
2916 |
! |
|
2917 |
||
5755 | 2918 |
basicInspect |
2919 |
"{ Pragma: +optSpace }" |
|
2920 |
||
2921 |
"launch an inspector on the receiver. |
|
2922 |
this method should NOT be redefined in subclasses." |
|
2923 |
||
2924 |
Inspector isNil ifTrue:[ |
|
6654 | 2925 |
" |
2926 |
for systems without GUI |
|
2927 |
" |
|
6926 | 2928 |
self warn:'No Inspector defined (Inspector is nil).' |
5755 | 2929 |
] ifFalse:[ |
6654 | 2930 |
Inspector openOn:self |
5755 | 2931 |
] |
2932 |
||
2933 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
2934 |
! |
|
2935 |
||
6954 | 2936 |
breakPoint:something |
2937 |
"{ Pragma: +optSpace }" |
|
2938 |
||
2939 |
"Like halt, but disabled by default. |
|
2940 |
Can be easily enabled. |
|
2941 |
Can be filtered on the arguments value (typically: a symbol). |
|
2942 |
Code with breakpoints may be even checked into the source repository" |
|
2943 |
||
2944 |
"Example: nil breakPoint:#stefan" |
|
2945 |
||
2946 |
"/ something = OperatingSystem getLoginName ifTrue:[ |
|
2947 |
"/ ^ HaltSignal raiseRequestWith:something errorString:'Breakpoint encountered: ', something printString |
|
2948 |
"/ ]. |
|
2949 |
||
2950 |
"/ something = 'testThis' ifTrue:[ |
|
2951 |
"/ ^ HaltSignal raiseRequestWith:something errorString:'Breakpoint encountered: ', something printString |
|
2952 |
"/ ]. |
|
2953 |
! |
|
2954 |
||
5995 | 2955 |
browse |
2956 |
"open a browser on the receivers class" |
|
2957 |
||
2958 |
self class theNonMetaclass browse |
|
2959 |
||
2960 |
" |
|
2961 |
10 browse |
|
2962 |
Collection browse |
|
2963 |
Collection class browse |
|
2964 |
" |
|
2965 |
! |
|
2966 |
||
5755 | 2967 |
inspect |
2968 |
"{ Pragma: +optSpace }" |
|
2969 |
||
2970 |
"launch an inspector on the receiver. |
|
2971 |
this method (or better: inspectorClass) can be redefined in subclasses |
|
2972 |
to start special inspectors." |
|
2973 |
||
2974 |
|cls| |
|
2975 |
||
2976 |
cls := self inspectorClass. |
|
2977 |
cls isNil ifTrue:[ |
|
6654 | 2978 |
^ self basicInspect |
5755 | 2979 |
]. |
2980 |
cls openOn:self |
|
2981 |
||
2982 |
" |
|
2983 |
Object new inspect |
|
2984 |
(1 @ 2) inspect |
|
2985 |
Smalltalk inspect |
|
2986 |
#(1 2 3) asOrderedCollection inspect |
|
2987 |
(Color red) inspect |
|
2988 |
(Image fromFile:'bitmaps/garfield.gif') inspect |
|
2989 |
" |
|
2990 |
! |
|
2991 |
||
2992 |
inspectorClass |
|
2993 |
"{ Pragma: +optSpace }" |
|
2994 |
||
2995 |
"return the class to use for inspect. |
|
2996 |
Can (should) be redefined in classes for which a better inspector is available" |
|
2997 |
||
2998 |
^ Inspector |
|
2999 |
! |
|
3000 |
||
3001 |
mustBeBoolean |
|
3002 |
"this message is sent by the VM, if a non-Boolean receiver is encountered |
|
3003 |
in an if* or while* message. |
|
3004 |
Caveat: for now, this is only sent by the interpreter; |
|
3005 |
both the JIT and the stc compiler treat it as undefined." |
|
3006 |
||
3007 |
self error:'Non boolean receiver - proceed for truth' mayProceed:true. |
|
3008 |
^ true |
|
3009 |
! |
|
3010 |
||
3011 |
mustBeKindOf:aClass |
|
3012 |
"for compatibility & debugging support: |
|
3013 |
check if the receiver isKindOf:aClass and raise an error if not. |
|
3014 |
Notice: |
|
6654 | 3015 |
it is VERY questionable, if it makes sense to add manual |
3016 |
type checks to a dynamically typed language like smalltalk. |
|
3017 |
It will, at least, slow down performance, |
|
3018 |
make your code less reusable and clutter your code with stupid sends |
|
3019 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
3020 |
use of isXXX check methods. |
|
5755 | 3021 |
You see: The author does not like this at all ..." |
3022 |
||
3023 |
(self isKindOf:aClass) ifFalse:[ |
|
6654 | 3024 |
self error:'argument is not of expected type' |
5755 | 3025 |
] |
3026 |
! |
|
3027 |
||
6950 | 3028 |
obsoleteFeatureWarning |
3029 |
"{ Pragma: +optSpace }" |
|
3030 |
||
3031 |
"in methods which are going to be changed, a send to |
|
3032 |
this method is used to tell programmers that some feature/semantics is |
|
3033 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3034 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)." |
6950 | 3035 |
|
3036 |
self obsoleteFeatureWarning:nil from:thisContext sender |
|
3037 |
! |
|
3038 |
||
3039 |
obsoleteFeatureWarning:message |
|
3040 |
"{ Pragma: +optSpace }" |
|
3041 |
||
3042 |
"in methods which are going to be changed, a send to |
|
3043 |
this method is used to tell programmers that some feature/semantics is |
|
3044 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3045 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3046 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3047 |
|
3048 |
self obsoleteFeatureWarning:message from:thisContext sender |
|
3049 |
! |
|
3050 |
||
3051 |
obsoleteFeatureWarning:message from:aContext |
|
3052 |
"{ Pragma: +optSpace }" |
|
3053 |
||
3054 |
"in methods which are going to be changed, a send to |
|
3055 |
this method is used to tell programmers that some feature/semantics is |
|
3056 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3057 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3058 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3059 |
|
3060 |
|spec| |
|
3061 |
||
3062 |
spec := aContext methodPrintString. |
|
3063 |
('WARNING: the ''' , spec , ''' semantics will be changed.') infoPrintCR. |
|
3064 |
(' Its behavior may be different in future ST/X versions.') infoPrintCR. |
|
3065 |
(' called from ' , aContext sender printString) infoPrintCR. |
|
7204 | 3066 |
(aContext sender selector startsWith:'perform:') ifTrue:[ |
3067 |
(' called from ' , aContext sender sender printString) infoPrintCR. |
|
3068 |
]. |
|
6950 | 3069 |
message notNil ifTrue:[ |
3070 |
'------> ' infoPrint. message infoPrintCR |
|
3071 |
] |
|
3072 |
||
3073 |
" |
|
3074 |
Object obsoleteFeatureWarning:'foo' from:thisContext sender sender |
|
3075 |
" |
|
3076 |
! |
|
3077 |
||
5755 | 3078 |
obsoleteMethodWarning |
3079 |
"{ Pragma: +optSpace }" |
|
3080 |
||
3081 |
"in methods which are going to be obsoleted, a self send to |
|
3082 |
this method is used to tell programmers that a method is |
|
3083 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3084 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3085 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3086 |
|
3087 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
3088 |
! |
|
3089 |
||
3090 |
obsoleteMethodWarning:message |
|
3091 |
"{ Pragma: +optSpace }" |
|
3092 |
||
3093 |
"in methods which are going to be obsoleted, a self send to |
|
3094 |
this method is used to tell programmers that a method is |
|
3095 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3096 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3097 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3098 |
|
3099 |
self obsoleteMethodWarning:message from:thisContext sender |
|
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3100 |
! |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3101 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3102 |
obsoleteMethodWarning:message from:aContext |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3103 |
"{ Pragma: +optSpace }" |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3104 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3105 |
"in methods which are going to be obsoleted, a self-send to |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3106 |
this method is used to tell programmers that a method is |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3107 |
used which is going to be removed in later ST/X versions. |
6963 | 3108 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3109 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
|
3110 |
This message is intended for application developers, so its printed as info message." |
|
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3111 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3112 |
|spec| |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3113 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3114 |
spec := aContext methodPrintString. |
6405
bbee0a853e2f
#obsoleteMethodWarning now uses infoPrint instead of errorPrint.
Stefan Vogel <sv@exept.de>
parents:
6388
diff
changeset
|
3115 |
('WARNING: the ''' , spec , ''' method is obsolete.') infoPrintCR. |
bbee0a853e2f
#obsoleteMethodWarning now uses infoPrint instead of errorPrint.
Stefan Vogel <sv@exept.de>
parents:
6388
diff
changeset
|
3116 |
(' And may not be present in future ST/X versions.') infoPrintCR. |
bbee0a853e2f
#obsoleteMethodWarning now uses infoPrint instead of errorPrint.
Stefan Vogel <sv@exept.de>
parents:
6388
diff
changeset
|
3117 |
(' called from ' , aContext sender printString) infoPrintCR. |
7204 | 3118 |
(aContext sender selector startsWith:'perform:') ifTrue:[ |
3119 |
(' called from ' , aContext sender sender printString) infoPrintCR. |
|
3120 |
]. |
|
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3121 |
message notNil ifTrue:[ |
6654 | 3122 |
'------> ' infoPrint. message infoPrintCR |
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3123 |
] |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3124 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3125 |
" |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3126 |
Object obsoleteMethodWarning:'foo' from:thisContext sender sender |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3127 |
" |
5755 | 3128 |
! ! |
3129 |
||
3130 |
!Object methodsFor:'dependents access'! |
|
3131 |
||
3132 |
addDependent:anObject |
|
3133 |
"make the argument, anObject be a dependent of the receiver" |
|
3134 |
||
3135 |
|wasBlocked| |
|
3136 |
||
3137 |
"/ must do this save from interrupts, since the dependents collection |
|
3138 |
"/ is possibly accessed from multiple threads. |
|
3139 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3140 |
"/ faster execution. |
|
3141 |
||
3142 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3143 |
[ |
|
6654 | 3144 |
|deps dep| |
3145 |
||
3146 |
deps := self dependents. |
|
3147 |
||
3148 |
"/ to save a fair amount of memory in case of |
|
3149 |
"/ many dependencies, we store a single dependent in |
|
3150 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3151 |
"/ added. |
|
3152 |
||
3153 |
(deps isNil or:[deps size == 0]) ifTrue:[ |
|
3154 |
self dependents:(WeakArray with:anObject) |
|
3155 |
] ifFalse:[ |
|
3156 |
deps class == WeakArray ifTrue:[ |
|
3157 |
dep := deps at:1. |
|
3158 |
dep ~~ anObject ifTrue:[ |
|
3159 |
(dep isNil or:[dep == 0]) ifTrue:[ |
|
3160 |
deps at:1 put:anObject |
|
3161 |
] ifFalse:[ |
|
3162 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
3163 |
] |
|
3164 |
] |
|
3165 |
] ifFalse:[ |
|
3166 |
deps add:anObject |
|
3167 |
] |
|
3168 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3169 |
] ensure:[ |
6654 | 3170 |
wasBlocked ifFalse:[ |
3171 |
OperatingSystem unblockInterrupts |
|
3172 |
] |
|
5755 | 3173 |
] |
3174 |
||
3175 |
"Modified: / 27.10.1997 / 19:35:52 / cg" |
|
3176 |
! |
|
3177 |
||
3178 |
breakDependents |
|
3179 |
"remove all dependencies from the receiver" |
|
3180 |
||
3181 |
self dependents:nil. |
|
3182 |
self nonWeakDependents:nil |
|
3183 |
||
3184 |
"Modified: / 19.4.1996 / 10:55:36 / cg" |
|
3185 |
"Created: / 27.2.1998 / 11:26:11 / stefan" |
|
3186 |
! |
|
3187 |
||
3188 |
dependents |
|
3189 |
"return a Collection of dependents. |
|
3190 |
The default implementation here uses a global WeakDictionary to store |
|
3191 |
dependents |
|
3192 |
This may be too slow for high frequency change&update, |
|
3193 |
therefore, some classes (Model) redefine this for better performance. |
|
3194 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
3195 |
||
3196 |
|deps| |
|
3197 |
||
3198 |
(deps := Dependencies at:self ifAbsent:nil) isNil ifTrue:[ |
|
6654 | 3199 |
^ #(). |
5755 | 3200 |
]. |
3201 |
^ deps |
|
3202 |
||
3203 |
"Modified: / 26.1.1998 / 11:18:15 / cg" |
|
3204 |
! |
|
3205 |
||
3206 |
dependents:aCollection |
|
3207 |
"set the collection of dependents. |
|
3208 |
The default implementation here uses a global Dictionary to store |
|
3209 |
dependents which may be too slow for high frequency change&update. |
|
3210 |
Therefore, some classes (Model) redefine this for better performance." |
|
3211 |
||
3212 |
"/ must do this save from interrupts, since the dependents collection |
|
3213 |
"/ is possibly accessed from multiple threads. |
|
3214 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3215 |
"/ faster execution (and to avoid creation of garbage blocks). |
|
3216 |
||
3217 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
6654 | 3218 |
"/ the common case - already blocked |
3219 |
||
3220 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
3221 |
Dependencies removeKey:self ifAbsent:nil |
|
3222 |
] ifFalse:[ |
|
3223 |
Dependencies at:self put:aCollection |
|
3224 |
]. |
|
3225 |
^ self |
|
5755 | 3226 |
]. |
3227 |
||
3228 |
[ |
|
6654 | 3229 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3230 |
Dependencies removeKey:self ifAbsent:nil |
|
3231 |
] ifFalse:[ |
|
3232 |
Dependencies at:self put:aCollection |
|
3233 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3234 |
] ensure:[ |
6654 | 3235 |
OperatingSystem unblockInterrupts |
5755 | 3236 |
] |
3237 |
||
3238 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
|
3239 |
! |
|
3240 |
||
3241 |
dependentsDo:aBlock |
|
3242 |
"evaluate aBlock for all of my dependents" |
|
3243 |
||
3244 |
|deps nwDeps| |
|
3245 |
||
3246 |
deps := self dependents. |
|
3247 |
deps size ~~ 0 ifTrue:[ |
|
6654 | 3248 |
deps do:[:d | |
3249 |
(d notNil and:[d ~~ 0]) ifTrue:[ |
|
3250 |
aBlock value:d |
|
3251 |
] |
|
3252 |
] |
|
5755 | 3253 |
]. |
3254 |
nwDeps := self nonWeakDependents. |
|
3255 |
(nwDeps ~~ deps and:[nwDeps size ~~ 0]) ifTrue:[ |
|
6654 | 3256 |
nwDeps do:aBlock |
5755 | 3257 |
]. |
3258 |
||
3259 |
"Modified: / 30.1.1998 / 14:03:40 / cg" |
|
3260 |
! |
|
3261 |
||
3262 |
myDependents |
|
3263 |
"same as dependents - ST-80 compatibility" |
|
3264 |
||
3265 |
^ self dependents |
|
3266 |
! |
|
3267 |
||
3268 |
release |
|
3269 |
"remove all references to objects that may refer to self. |
|
3270 |
Subclasses may redefine this method but should do a 'super release'." |
|
3271 |
||
3272 |
self breakDependents |
|
3273 |
||
3274 |
"Modified: / 27.2.1998 / 11:29:35 / stefan" |
|
3275 |
! |
|
3276 |
||
3277 |
removeDependent:anObject |
|
3278 |
"make the argument, anObject be independent of the receiver" |
|
3279 |
||
3280 |
|wasBlocked| |
|
3281 |
||
3282 |
"/ must do this save from interrupts, since the dependents collection |
|
3283 |
"/ is possibly accessed from multiple threads. |
|
3284 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3285 |
"/ faster execution. |
|
3286 |
||
3287 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3288 |
[ |
|
6654 | 3289 |
|deps n d| |
3290 |
||
3291 |
deps := self dependents. |
|
3292 |
deps size ~~ 0 ifTrue:[ |
|
3293 |
||
3294 |
"/ to save a fair amount of memory in case of |
|
3295 |
"/ many dependencies, we store a single dependent in |
|
3296 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3297 |
"/ added. Here we have to do the inverse ... |
|
3298 |
||
3299 |
deps class == WeakArray ifTrue:[ |
|
3300 |
((d := deps at:1) == anObject |
|
3301 |
or:[d isNil |
|
3302 |
or:[d == 0]]) ifTrue:[ |
|
3303 |
self dependents:nil |
|
3304 |
] |
|
3305 |
] ifFalse:[ |
|
3306 |
deps remove:anObject ifAbsent:[]. |
|
3307 |
(n := deps size) == 0 ifTrue:[ |
|
3308 |
self dependents:nil |
|
3309 |
] ifFalse:[ |
|
3310 |
n == 1 ifTrue:[ |
|
3311 |
d := deps firstIfEmpty:nil. |
|
3312 |
d notNil ifTrue:[ |
|
3313 |
deps := WeakArray with:d |
|
3314 |
] ifFalse:[ |
|
3315 |
deps := nil |
|
3316 |
]. |
|
3317 |
self dependents:deps. |
|
3318 |
] |
|
3319 |
] |
|
3320 |
] |
|
3321 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3322 |
] ensure:[ |
6654 | 3323 |
wasBlocked ifFalse:[ |
3324 |
OperatingSystem unblockInterrupts |
|
3325 |
] |
|
5755 | 3326 |
] |
3327 |
||
3328 |
"Modified: / 26.1.1998 / 19:51:50 / cg" |
|
3329 |
! ! |
|
3330 |
||
7266 | 3331 |
!Object methodsFor:'dependents access (non weak)'! |
5755 | 3332 |
|
3333 |
addNonWeakDependent:anObject |
|
3334 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
|
3335 |
Be careful: this nonWeakDependency will prevent the dependent from being |
|
3336 |
garbage collected unless the dependency is removed. |
|
3337 |
This is a private mechanism, for directed dependencies." |
|
3338 |
||
3339 |
|wasBlocked| |
|
3340 |
||
3341 |
"/ must do this save from interrupts, since the dependents collection |
|
3342 |
"/ is possibly accessed from multiple threads. |
|
3343 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3344 |
"/ faster execution. |
|
3345 |
||
3346 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3347 |
[ |
|
6654 | 3348 |
|deps dep| |
3349 |
||
3350 |
deps := self nonWeakDependents. |
|
3351 |
||
3352 |
"/ to save a fair amount of memory in case of |
|
3353 |
"/ many dependencies, we store a single dependent in |
|
3354 |
"/ an Array, and switch to a Set if more dependents are |
|
3355 |
"/ added. |
|
3356 |
||
3357 |
deps size == 0 ifTrue:[ |
|
3358 |
self nonWeakDependents:(Array with:anObject) |
|
3359 |
] ifFalse:[ |
|
3360 |
deps class == Array ifTrue:[ |
|
3361 |
dep := deps at:1. |
|
3362 |
dep ~~ anObject ifTrue:[ |
|
3363 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
3364 |
] |
|
3365 |
] ifFalse:[ |
|
3366 |
deps add:anObject |
|
3367 |
] |
|
3368 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3369 |
] ensure:[ |
6654 | 3370 |
wasBlocked ifFalse:[ |
3371 |
OperatingSystem unblockInterrupts |
|
3372 |
] |
|
5755 | 3373 |
] |
3374 |
||
3375 |
"Created: / 19.4.1996 / 10:54:08 / cg" |
|
3376 |
"Modified: / 30.1.1998 / 14:03:08 / cg" |
|
3377 |
! |
|
3378 |
||
3379 |
nonWeakDependents |
|
3380 |
"return a Collection of nonWeakDependents - empty if there is none. |
|
3381 |
This is a private mechanism for directed dependencies." |
|
3382 |
||
3383 |
NonWeakDependencies isNil ifTrue:[^ #()]. |
|
3384 |
^ NonWeakDependencies at:self ifAbsent:#() |
|
3385 |
||
3386 |
"Created: / 19.4.1996 / 10:55:06 / cg" |
|
3387 |
"Modified: / 30.1.1998 / 14:06:47 / cg" |
|
3388 |
! |
|
3389 |
||
3390 |
nonWeakDependents:aCollection |
|
3391 |
"set the collection of nonWeak dependents. |
|
3392 |
This is a private helper for directed dependencies." |
|
3393 |
||
3394 |
[ |
|
6654 | 3395 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3396 |
NonWeakDependencies removeKey:self ifAbsent:nil |
|
3397 |
] ifFalse:[ |
|
3398 |
NonWeakDependencies at:self put:aCollection |
|
3399 |
] |
|
5755 | 3400 |
] valueUninterruptably |
3401 |
||
3402 |
"Created: 19.4.1996 / 11:07:47 / cg" |
|
3403 |
! |
|
3404 |
||
3405 |
removeNonWeakDependent:anObject |
|
3406 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
|
3407 |
(i.e. make it independent of the receiver)" |
|
3408 |
||
3409 |
|wasBlocked| |
|
3410 |
||
3411 |
"/ must do this save from interrupts, since the dependents collection |
|
3412 |
"/ is possibly accessed from multiple threads. |
|
3413 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3414 |
"/ faster execution. |
|
3415 |
||
3416 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3417 |
[ |
|
6654 | 3418 |
|deps n| |
3419 |
||
3420 |
deps := self nonWeakDependents. |
|
3421 |
deps size ~~ 0 ifTrue:[ |
|
3422 |
deps class == Array ifTrue:[ |
|
3423 |
(deps at:1) == anObject ifTrue:[ |
|
3424 |
self nonWeakDependents:nil |
|
3425 |
] |
|
3426 |
] ifFalse:[ |
|
3427 |
deps remove:anObject ifAbsent:[]. |
|
3428 |
(n := deps size) == 0 ifTrue:[ |
|
3429 |
self nonWeakDependents:nil |
|
3430 |
] ifFalse:[ |
|
3431 |
n == 1 ifTrue:[ |
|
3432 |
self nonWeakDependents:(Array with:(deps first)) |
|
3433 |
] |
|
3434 |
] |
|
3435 |
] |
|
3436 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3437 |
] ensure:[ |
6654 | 3438 |
wasBlocked ifFalse:[ |
3439 |
OperatingSystem unblockInterrupts |
|
3440 |
] |
|
5755 | 3441 |
] |
3442 |
||
3443 |
"Created: / 19.4.1996 / 11:44:44 / cg" |
|
3444 |
"Modified: / 30.1.1998 / 14:04:01 / cg" |
|
3445 |
! ! |
|
3446 |
||
3447 |
!Object methodsFor:'displaying'! |
|
3448 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3449 |
ascentOn:aGC |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3450 |
"when displayed via displayOn:, some objects assume that the given y coordinate |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3451 |
is the baseline (strings, text etc. do), while others assume that the topY |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3452 |
coordinate is given by y. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3453 |
In other words: some draw above the given y coordinate. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3454 |
This method returns the number of pixels by which the receiver will draw above |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3455 |
the given y coordinate." |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3456 |
|
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3457 |
^ (aGC font onDevice:aGC device) ascent |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3458 |
! |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3459 |
|
6900 | 3460 |
displayOn:aGCOrStream |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3461 |
"Compatibility |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3462 |
append a printed desription on some stream (Dolphin, Squeak) |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3463 |
OR: |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3464 |
display the receiver in a graphicsContext at 0@0 (ST80). |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3465 |
This method allows for any object to be displayed in some view |
5755 | 3466 |
(although the fallBack is to display its printString ...)" |
3467 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3468 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3469 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
6900 | 3470 |
(aGCOrStream isStream or:[aGCOrStream == Transcript]) ifTrue:[ |
3471 |
self printOn:aGCOrStream. |
|
3472 |
^ self |
|
3473 |
]. |
|
3474 |
^ self displayOn:aGCOrStream x:0 y:0. |
|
5755 | 3475 |
|
3476 |
"Created: 29.5.1996 / 16:28:58 / cg" |
|
3477 |
! |
|
3478 |
||
3479 |
displayOn:aGC at:aPoint |
|
3480 |
"ST-80 Compatibility |
|
3481 |
display the receiver in a graphicsContext - this method allows |
|
3482 |
for any object to be displayed in a ListView - for example." |
|
3483 |
||
3484 |
^ self displayOn:aGC x:(aPoint x) y:(aPoint y). |
|
3485 |
! |
|
3486 |
||
3487 |
displayOn:aGC x:x y:y |
|
3488 |
"display the receiver in a graphicsContext - this method allows |
|
3489 |
for any object to be displayed in a ListView - for example." |
|
3490 |
||
3491 |
self displayOn:aGC x:x y:y opaque:false |
|
3492 |
||
3493 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3494 |
! |
|
3495 |
||
3496 |
displayOn:aGc x:x y:y opaque:opaque |
|
3497 |
"display the receiver in a graphicsContext - this method allows |
|
3498 |
for any object to be displayed in a ListView - for example. |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3499 |
The fallBack here shows the receivers displayString. |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3500 |
Notice, that the string is displayed on the baseLine; |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3501 |
ask using #ascentOn: if required" |
5755 | 3502 |
|
3503 |
|s yBaseline| |
|
3504 |
||
3505 |
s := self displayString. |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3506 |
yBaseline := y "+ aGc font ascent". |
5755 | 3507 |
opaque ifTrue:[ |
6654 | 3508 |
aGc displayOpaqueString:s x:x y:yBaseline. |
5755 | 3509 |
] ifFalse:[ |
6654 | 3510 |
aGc displayString:s x:x y:yBaseline. |
5755 | 3511 |
]. |
3512 |
||
3513 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3514 |
! |
|
3515 |
||
3516 |
displayOpaqueOn:aGC x:x y:y |
|
3517 |
"display the receiver in a graphicsContext - this method allows |
|
3518 |
for any object to be displayed in a ListView - for example." |
|
3519 |
||
3520 |
self displayOn:aGC x:x y:y opaque:true |
|
3521 |
||
3522 |
"Modified: / 29.5.1996 / 16:29:38 / cg" |
|
3523 |
"Created: / 26.10.1997 / 15:01:36 / cg" |
|
3524 |
! |
|
3525 |
||
3526 |
displayString |
|
3527 |
"return a string used when displaying the receiver in a view; |
|
3528 |
for example an Inspector. This is usually the same as printString, |
|
3529 |
but sometimes redefined for a better look." |
|
3530 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3531 |
|s| |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3532 |
|
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3533 |
s := '' writeStream. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3534 |
self displayOn:s. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3535 |
^ s contents |
5755 | 3536 |
|
3537 |
" |
|
3538 |
#(1 2 3) printString |
|
3539 |
#(1 2 3) displayString |
|
3540 |
#(1 2 3) storeString |
|
3541 |
" |
|
3542 |
! |
|
3543 |
||
3544 |
heightOn:aGC |
|
3545 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
3546 |
||
3547 |
^ (aGC font onDevice:aGC device) heightOf:(self displayString) |
|
3548 |
! |
|
3549 |
||
6654 | 3550 |
widthFrom:startIndex to:endIndex on:aGC |
3551 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3552 |
||
3553 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) from:startIndex to:endIndex |
|
3554 |
! |
|
3555 |
||
5755 | 3556 |
widthOn:aGC |
3557 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3558 |
||
3559 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) |
|
3560 |
! ! |
|
3561 |
||
3562 |
!Object methodsFor:'encoding & decoding'! |
|
3563 |
||
3564 |
decodeAsLiteralArray |
|
3565 |
^ self |
|
3566 |
! |
|
3567 |
||
3568 |
encodeOn:anEncoder with:aParameter |
|
3569 |
"double-dispatch onto an ObjectEncoder. |
|
3570 |
Subclasses redefine this" |
|
3571 |
||
3572 |
anEncoder encodeObject:self with:aParameter |
|
3573 |
||
3574 |
||
3575 |
! |
|
3576 |
||
6718 | 3577 |
encodingVectorFor:aspect |
3578 |
"answer a collection of associations containing the |
|
3579 |
objects state to be encoded for aspect. |
|
3580 |
Association key is the instance variable name or access selector, |
|
3581 |
association value is the contents of the instance variable. |
|
3582 |
||
3583 |
The default is to return the contents of all instance variables" |
|
3584 |
||
3585 |
|ret| |
|
3586 |
||
3587 |
ret := self perform:aspect ifNotUnderstood:[0]. |
|
3588 |
ret == 0 ifTrue:[ |
|
3589 |
^ self encodingVectorForNonNilInstanceVariables |
|
3590 |
]. |
|
3591 |
^ ret. |
|
3592 |
! |
|
3593 |
||
3594 |
encodingVectorForInstanceVariables |
|
3595 |
"return all instance variables for encoding" |
|
3596 |
||
7112 | 3597 |
^ self encodingVectorForInstanceVariablesMatching:[:val | true]. |
3598 |
||
3599 |
" |
|
3600 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
3601 |
Dictionary new encodingVectorForInstanceVariables |
|
3602 |
(5 @ nil) encodingVectorForInstanceVariables |
|
3603 |
" |
|
3604 |
! |
|
3605 |
||
3606 |
encodingVectorForInstanceVariablesMatching:aBlock |
|
3607 |
"return all instance variables for which aBlock returns true, for encoding. |
|
3608 |
Indexed vars are all included." |
|
3609 |
||
6718 | 3610 |
|instVarNames theClass children |
3611 |
instSize "{ Class: SmallInteger }" |
|
3612 |
varSize "{ Class: SmallInteger }"| |
|
3613 |
||
3614 |
theClass := self class. |
|
3615 |
||
3616 |
instSize := theClass instSize. |
|
3617 |
varSize := theClass isVariable ifTrue:[self basicSize] ifFalse:[0]. |
|
3618 |
children := OrderedCollection new:(instSize + varSize). |
|
3619 |
||
3620 |
instVarNames := theClass allInstVarNames. |
|
3621 |
1 to:instSize do:[:i | |var| |
|
3622 |
var := self instVarAt:i. |
|
7112 | 3623 |
(aBlock value:var) ifTrue:[ |
3624 |
children add:((instVarNames at:i) -> var) |
|
3625 |
] |
|
6718 | 3626 |
]. |
3627 |
||
3628 |
varSize ~~ 0 ifTrue:[ |
|
3629 |
1 to:varSize do:[:i | |
|
3630 |
children add:(i -> (self basicAt:i)) |
|
3631 |
] |
|
3632 |
]. |
|
3633 |
||
3634 |
^ children. |
|
3635 |
||
3636 |
" |
|
3637 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
3638 |
Dictionary new encodingVectorForInstanceVariables |
|
3639 |
(5 @ nil) encodingVectorForInstanceVariables |
|
3640 |
" |
|
3641 |
! |
|
3642 |
||
3643 |
encodingVectorForNonNilInstanceVariables |
|
3644 |
"return all instance variables for encoding" |
|
3645 |
||
7112 | 3646 |
^ self encodingVectorForInstanceVariablesMatching:[:varVal | varVal notNil]. |
6718 | 3647 |
|
3648 |
" |
|
3649 |
#(1 2 3 nil true symbol) encodingVectorForNonNilInstanceVariables |
|
3650 |
(5 @ nil) encodingVectorForNonNilInstanceVariables |
|
3651 |
" |
|
3652 |
! |
|
3653 |
||
5755 | 3654 |
fromLiteralArrayEncoding:aSpecArray |
3655 |
"read my attributes from aSpecArray |
|
3656 |
" |
|
3657 |
|sel val |
|
3658 |
stop "{ Class:SmallInteger }" | |
|
3659 |
||
3660 |
stop := aSpecArray size. |
|
3661 |
||
3662 |
2 to:stop by:2 do:[:i| |
|
6654 | 3663 |
sel := aSpecArray at:i. |
3664 |
val := aSpecArray at:i + 1. |
|
3665 |
||
3666 |
(self respondsTo:sel) ifTrue:[ |
|
3667 |
self perform:sel with:(val decodeAsLiteralArray) |
|
3668 |
] ifFalse:[ |
|
3669 |
Transcript show:self class name; show:': unhandled literalArrayEncoding attribute: '. |
|
3670 |
Transcript showCR:sel. |
|
3671 |
] |
|
5755 | 3672 |
] |
3673 |
||
3674 |
||
3675 |
! |
|
3676 |
||
3677 |
literalArrayEncoding |
|
3678 |
"generate a literalArrayEncoding array for myself. |
|
3679 |
This uses #literalArrayEncodingSlotOrder which defines the slots and |
|
3680 |
order and #skippedInLiteralEncoding which defines slots to skip. |
|
3681 |
For most subclasses, there is no need to redefine those." |
|
3682 |
||
3683 |
|names encoding cls skipped| |
|
3684 |
||
3685 |
self isLiteral ifTrue:[ |
|
6654 | 3686 |
^ self |
5755 | 3687 |
]. |
3688 |
||
3689 |
skipped := self skippedInLiteralEncoding. |
|
3690 |
cls := self class. |
|
3691 |
names := cls allInstVarNames. |
|
3692 |
encoding := OrderedCollection with:(cls name). |
|
3693 |
||
3694 |
(self literalArrayEncodingSlotOrder) do:[:instSlot | |
|
6654 | 3695 |
|value nm| |
3696 |
||
3697 |
nm := names at:instSlot. |
|
3698 |
||
3699 |
(skipped includes:nm) ifFalse:[ |
|
3700 |
(value := self instVarAt:instSlot) notNil ifTrue:[ |
|
3701 |
encoding add:(nm , ':') asSymbol. |
|
3702 |
encoding add:value literalArrayEncoding |
|
3703 |
] |
|
3704 |
] |
|
5755 | 3705 |
]. |
3706 |
^ encoding asArray |
|
3707 |
||
3708 |
||
3709 |
! |
|
3710 |
||
3711 |
literalArrayEncodingSlotOrder |
|
3712 |
"define the order in which inst-slots are saved when generating |
|
3713 |
a literalArrayEncoding |
|
3714 |
" |
|
3715 |
^ 1 to:self class instSize |
|
3716 |
||
3717 |
! |
|
3718 |
||
7112 | 3719 |
postDecodeFrom:aDecoder aspect:aspectSymbol |
3720 |
"invoked by xmlDecoder (and others in the future), after an |
|
3721 |
object has been decoded (i.e. its instance variables have been restored)" |
|
3722 |
||
3723 |
"/ intentionally left blank |
|
3724 |
! |
|
3725 |
||
5755 | 3726 |
skippedInLiteralEncoding |
3727 |
"return a Collection with it's elements are slots for skipping |
|
3728 |
" |
|
3729 |
^ #() |
|
3730 |
||
3731 |
! ! |
|
3732 |
||
3733 |
!Object methodsFor:'error handling'! |
|
3734 |
||
3735 |
appropriateDebugger:aSelector |
|
3736 |
"{ Pragma: +optSpace }" |
|
3737 |
||
3738 |
"return an appropriate debugger to use. |
|
3739 |
If there is already a debugger active on the stack, and it is |
|
3740 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
3741 |
||
3742 |
|context| |
|
3743 |
||
3744 |
"DebugView cannot run without system processes" |
|
3745 |
||
3746 |
(Processor isNil |
|
3747 |
or:[Processor activeProcessIsSystemProcess |
|
3748 |
or:[Smalltalk isInitialized not]]) ifTrue:[ |
|
6654 | 3749 |
^ MiniDebugger |
5755 | 3750 |
]. |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
3751 |
(Screen isNil or:[Screen default isNil or:[Screen default isOpen not]]) ifTrue:[ |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
3752 |
Debugger isNil ifTrue:[^ nil]. |
6654 | 3753 |
^ MiniDebugger |
5755 | 3754 |
]. |
3755 |
||
3756 |
context := thisContext. |
|
3757 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
3758 |
[context notNil] whileTrue:[ |
|
6654 | 3759 |
((context receiver class == Debugger) |
3760 |
and:[context selector == aSelector]) ifTrue:[ |
|
3761 |
"we are already in some Debugger" |
|
3762 |
(Debugger == MiniDebugger) ifTrue:[ |
|
3763 |
"we are already in the MiniDebugger" |
|
3764 |
ErrorRecursion ifFalse:[ |
|
3765 |
Smalltalk fatalAbort:'recursive error ...' |
|
3766 |
] |
|
3767 |
]. |
|
3768 |
MiniDebugger isNil ifTrue:[ |
|
3769 |
Smalltalk fatalAbort:'no debugger' |
|
3770 |
]. |
|
3771 |
||
3772 |
"ok, an error occured while in the graphical debugger; |
|
3773 |
lets try MiniDebugger" |
|
3774 |
^ MiniDebugger |
|
3775 |
]. |
|
3776 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
5755 | 3777 |
]. |
3778 |
"not within Debugger - no problem" |
|
3779 |
^ Debugger |
|
3780 |
||
3781 |
"Modified: / 23.9.1996 / 12:14:52 / stefan" |
|
3782 |
"Modified: / 19.5.1999 / 18:05:00 / cg" |
|
3783 |
! |
|
3784 |
||
3785 |
cannotSendMessage:aMessage to:someReceiver |
|
3786 |
"this message is sent by the runtime system (VM), |
|
3787 |
when a message is sent to some object, whose class is not |
|
3788 |
a valid behavior (see documentation in Behavior)." |
|
3789 |
||
3790 |
^ InternalErrorSignal |
|
6654 | 3791 |
raiseWith:someReceiver |
3792 |
errorString:('bad class in send of #' , aMessage selector) |
|
5755 | 3793 |
|
3794 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
3795 |
! |
|
3796 |
||
3797 |
doesNotUnderstand:aMessage |
|
3798 |
"this message is sent by the runtime system (VM) when |
|
3799 |
a message is not understood by some object (i.e. there |
|
3800 |
is no method for that selector). The original message has |
|
3801 |
been packed into aMessage (i.e. the receiver, selector and |
|
3802 |
any arguments) and the original receiver is then sent the |
|
3803 |
#doesNotUnderstand: message. |
|
3804 |
Here, we raise another signal which usually enters the debugger. |
|
3805 |
You can of course redefine #doesNotUnderstand: in your classes |
|
3806 |
to implement message delegation, |
|
3807 |
or handle the MessageNotUnderstoodSignal gracefully." |
|
3808 |
||
3809 |
<context: #return> |
|
3810 |
||
5821 | 3811 |
|sel selStr errorString cls| |
5755 | 3812 |
|
3813 |
sel := aMessage selector. |
|
3814 |
selStr := sel printString. |
|
3815 |
||
3816 |
"/ Although sel should always be a symbol, |
|
3817 |
"/ always use printStrings in the code below. |
|
3818 |
"/ Non-symbol selector may happen when things go mad in a primitive, |
|
3819 |
"/ or a method has been called by valueWithReceiver: with a wrong arg. |
|
3820 |
||
3821 |
"/ handle the case of an error during early startup |
|
3822 |
"/ (output streams not yet initialized) |
|
3823 |
||
3824 |
Stdout isNil ifTrue:[ |
|
6654 | 3825 |
Smalltalk fatalAbort:'error during init: ' , selStr , ' not understood'. |
5755 | 3826 |
]. |
3827 |
||
3828 |
"/ |
|
3829 |
"/ extract the class that should have implemented the message. |
|
3830 |
"/ (in case of a super-send, this is not the receivers class) |
|
3831 |
"/ |
|
3832 |
cls := thisContext sender searchClass. |
|
3833 |
cls isNil ifTrue:[ |
|
6654 | 3834 |
"it was NOT a super or directed send ..." |
3835 |
cls := self class |
|
5755 | 3836 |
]. |
3837 |
||
3838 |
cls notNil ifTrue:[ |
|
6654 | 3839 |
"/ |
3840 |
"/ displayString is better than 'cls name', |
|
3841 |
"/ since it appends (obsolete) for outdated classes. |
|
3842 |
"/ (this happens if you send messages to old instances |
|
3843 |
"/ after changing a classes definition) |
|
3844 |
"/ |
|
3845 |
errorString := cls displayString. |
|
5755 | 3846 |
] ifFalse:[ |
6654 | 3847 |
errorString := '(** nil-class **)' |
5755 | 3848 |
]. |
3849 |
sel class ~~ Symbol ifTrue:[ |
|
6654 | 3850 |
errorString := errorString , ' nonSymbol selector: ' , selStr , ' not understood'. |
5755 | 3851 |
] ifFalse:[ |
6654 | 3852 |
errorString := errorString , ' does not understand: ' , selStr. |
5755 | 3853 |
]. |
3854 |
||
3855 |
"/ |
|
3856 |
"/ this only happens, when YOU play around with my classvars ... |
|
3857 |
"/ (or an error occurs during very early startup, when signals are not yet set) |
|
3858 |
"/ |
|
6146 | 3859 |
MessageNotUnderstood isNil ifTrue:[ |
6654 | 3860 |
^ MiniDebugger |
3861 |
enterWithMessage:'oops - MessageNotUnderstoodSignal is gone (nil)' |
|
3862 |
mayProceed:true. |
|
5755 | 3863 |
]. |
3864 |
||
3865 |
"/ |
|
3866 |
"/ thats where we end up normally - raise a signal which (if unhandled) opens a debugger |
|
3867 |
"/ |
|
6146 | 3868 |
^ MessageNotUnderstood |
6654 | 3869 |
raiseRequestWith:aMessage |
3870 |
errorString:errorString |
|
5755 | 3871 |
|
3872 |
"Modified: / 9.6.1999 / 17:46:17 / cg" |
|
3873 |
! |
|
3874 |
||
3875 |
elementBoundsError |
|
3876 |
"{ Pragma: +optSpace }" |
|
3877 |
||
3878 |
"report an error that badElement is out of bounds |
|
3879 |
(i.e. cannot be put into that collection). |
|
3880 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3881 |
||
3882 |
^ ElementOutOfBoundsSignal raise |
|
3883 |
||
3884 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
3885 |
! |
|
3886 |
||
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3887 |
elementBoundsError:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3888 |
"{ Pragma: +optSpace }" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3889 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3890 |
"report an error that aValue is not valid as element |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3891 |
(i.e. cannot be put into that collection). |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3892 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3893 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3894 |
^ ElementOutOfBoundsSignal raiseWith:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3895 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3896 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3897 |
! |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3898 |
|
5755 | 3899 |
elementNotCharacter |
3900 |
"{ Pragma: +optSpace }" |
|
3901 |
||
3902 |
"report an error that object to be stored is no Character. |
|
3903 |
(usually when storing into Strings). |
|
3904 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3905 |
||
3906 |
^ ElementOutOfBoundsSignal raise |
|
3907 |
||
3908 |
"Modified: 8.5.1996 / 09:12:49 / cg" |
|
3909 |
! |
|
3910 |
||
3911 |
elementNotInteger |
|
3912 |
"{ Pragma: +optSpace }" |
|
3913 |
||
3914 |
"report an error that object to be stored is not Integer. |
|
3915 |
(in collections that store integers only). |
|
3916 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3917 |
||
3918 |
^ ElementOutOfBoundsSignal raise |
|
3919 |
||
3920 |
"Modified: 8.5.1996 / 09:12:51 / cg" |
|
3921 |
! |
|
3922 |
||
3923 |
error |
|
3924 |
"{ Pragma: +optSpace }" |
|
3925 |
||
3926 |
<context: #return> |
|
3927 |
||
3928 |
"report error that an error occured. |
|
3929 |
The error is reported by raising the Error exception, |
|
3930 |
which is non-proceedable. |
|
3931 |
If no handler has been setup, a debugger is entered." |
|
3932 |
||
3933 |
Error raiseWith:#error: |
|
3934 |
||
3935 |
" |
|
3936 |
nil error |
|
3937 |
" |
|
3938 |
||
3939 |
"Modified: / 8.5.1996 / 09:13:01 / cg" |
|
3940 |
"Modified: / 2.8.1999 / 17:00:19 / stefan" |
|
3941 |
! |
|
3942 |
||
3943 |
error:aString |
|
3944 |
"{ Pragma: +optSpace }" |
|
3945 |
||
3946 |
<context: #return> |
|
3947 |
||
3948 |
"Raise an error with error message aString. |
|
3949 |
The error is reported by raising the Error exception, |
|
3950 |
which is non-proceedable. |
|
3951 |
If no handler has been setup, a debugger is entered." |
|
3952 |
||
3953 |
Error raiseWith:#error: errorString:aString |
|
3954 |
||
3955 |
" |
|
3956 |
nil error:' bad bad bad' |
|
3957 |
" |
|
3958 |
||
3959 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
3960 |
! |
|
3961 |
||
3962 |
error:aString mayProceed:mayProceed |
|
3963 |
"{ Pragma: +optSpace }" |
|
3964 |
||
3965 |
"enter debugger with error-message aString. |
|
3966 |
The error is reported by raising either the |
|
3967 |
non-proceedable Error exception, |
|
3968 |
or the ProceedableError exception." |
|
3969 |
||
3970 |
mayProceed ifTrue:[ |
|
6654 | 3971 |
^ ProceedableError raiseRequestWith:#error: errorString:aString |
5755 | 3972 |
]. |
3973 |
||
3974 |
Error raiseWith:#error: errorString:aString |
|
3975 |
||
3976 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
3977 |
! |
|
3978 |
||
6900 | 3979 |
errorInvalidFormat |
3980 |
"{ Pragma: +optSpace }" |
|
3981 |
||
3982 |
<context: #return> |
|
3983 |
||
3984 |
"report an error that some conversion to/from string representation failed |
|
3985 |
typically when converting numbers, date, time etc." |
|
3986 |
||
3987 |
^ ConversionError raiseErrorString:'invalid format' |
|
3988 |
! |
|
3989 |
||
5755 | 3990 |
errorKeyNotFound:aKey |
3991 |
"{ Pragma: +optSpace }" |
|
3992 |
||
3993 |
"report an error that a key was not found in a collection. |
|
3994 |
The error is reported by raising the KeyNotFoundSignal exception." |
|
3995 |
||
3996 |
^ KeyNotFoundSignal raiseRequestWith:aKey |
|
3997 |
||
3998 |
" |
|
3999 |
#(1 2) at:3 |
|
4000 |
" |
|
4001 |
! |
|
4002 |
||
4003 |
errorNotFound |
|
4004 |
"{ Pragma: +optSpace }" |
|
4005 |
||
4006 |
"report an error that no element was found in a collection. |
|
4007 |
The error is reported by raising the NotFoundSignal exception." |
|
4008 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4009 |
^ NotFoundError raiseRequestWith:nil |
5755 | 4010 |
|
4011 |
"Modified: / 8.5.1996 / 09:13:11 / cg" |
|
4012 |
"Modified: / 26.7.1999 / 10:51:50 / stefan" |
|
4013 |
! |
|
4014 |
||
6874 | 4015 |
errorNotFound:errorString |
4016 |
"{ Pragma: +optSpace }" |
|
4017 |
||
4018 |
"report an error that no element was found in a collection. |
|
4019 |
The error is reported by raising the NotFoundSignal exception." |
|
4020 |
||
4021 |
^ NotFoundError raiseErrorString:errorString |
|
4022 |
! |
|
4023 |
||
5755 | 4024 |
errorSignal |
4025 |
^ self class errorSignal |
|
4026 |
||
4027 |
"Created: / 19.6.1998 / 02:32:32 / cg" |
|
4028 |
! |
|
4029 |
||
4030 |
halt |
|
4031 |
"{ Pragma: +optSpace }" |
|
4032 |
||
4033 |
"enter debugger with halt-message. |
|
4034 |
The error is reported by raising the HaltSignal exception." |
|
4035 |
||
6716
7e2bac4221d1
allow for halts to be ignored
Claus Gittinger <cg@exept.de>
parents:
6708
diff
changeset
|
4036 |
(Smalltalk at:#IgnoreHalt ifAbsent:false) == true ifTrue:[^ self]. |
6221 | 4037 |
^ HaltInterrupt raiseRequestWith:#halt |
4038 |
||
5755 | 4039 |
"Modified: / 2.8.1999 / 17:00:29 / stefan" |
6221 | 4040 |
"Modified: / 17.11.2001 / 22:47:44 / cg" |
5755 | 4041 |
! |
4042 |
||
4043 |
halt:aString |
|
4044 |
"{ Pragma: +optSpace }" |
|
4045 |
||
4046 |
"enter debugger with halt-message. |
|
4047 |
The error is reported by raising the HaltSignal exception." |
|
4048 |
||
6716
7e2bac4221d1
allow for halts to be ignored
Claus Gittinger <cg@exept.de>
parents:
6708
diff
changeset
|
4049 |
(Smalltalk at:#IgnoreHalt ifAbsent:false) == true ifTrue:[^ self]. |
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4050 |
^ HaltInterrupt raiseRequestWith:#halt: errorString:aString |
5755 | 4051 |
|
4052 |
"Modified: 8.5.1996 / 09:13:23 / cg" |
|
4053 |
! |
|
4054 |
||
4055 |
implementedBySubclass |
|
4056 |
"{ Pragma: +optSpace }" |
|
4057 |
||
4058 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
4059 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4060 |
^ self subclassResponsibility:'method must be reimplemented in ST/V subclass' |
5755 | 4061 |
! |
4062 |
||
4063 |
indexNotInteger |
|
4064 |
"{ Pragma: +optSpace }" |
|
4065 |
||
4066 |
"report an error that index is not an Integer. |
|
4067 |
(when accessing collections indexed by an integer key). |
|
4068 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4069 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4070 |
^ NonIntegerIndexError raiseRequestWith:nil |
5755 | 4071 |
|
4072 |
"Modified: / 8.5.1996 / 09:13:37 / cg" |
|
4073 |
"Modified: / 26.7.1999 / 10:57:43 / stefan" |
|
4074 |
! |
|
4075 |
||
4076 |
indexNotInteger:anIndex |
|
4077 |
"{ Pragma: +optSpace }" |
|
4078 |
||
4079 |
"report an error that index is not an Integer. |
|
4080 |
(when accessing collections indexed by an integer key). |
|
4081 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4082 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4083 |
^ NonIntegerIndexError raiseRequestWith:anIndex |
5755 | 4084 |
|
4085 |
"Created: / 16.5.1998 / 19:39:41 / cg" |
|
4086 |
! |
|
4087 |
||
7216 | 4088 |
indexNotIntegerOrOutOfBounds:index |
4089 |
"{ Pragma: +optSpace }" |
|
4090 |
||
4091 |
"report an error that index is either non-integral or out of bounds" |
|
4092 |
||
4093 |
index isInteger ifFalse:[ |
|
4094 |
^ self indexNotInteger:index |
|
4095 |
]. |
|
4096 |
^ self subscriptBoundsError:index |
|
4097 |
! |
|
4098 |
||
5755 | 4099 |
integerCheckError |
4100 |
"{ Pragma: +optSpace }" |
|
4101 |
||
4102 |
"generated when a variable declared with an integer type gets a bad |
|
4103 |
value assigned" |
|
4104 |
||
4105 |
^ self error:'bad assign of ' , self printString , |
|
6654 | 4106 |
' (' , self class name , ') to integer-typed variable' |
5755 | 4107 |
! |
4108 |
||
4109 |
invalidCodeObject |
|
4110 |
"{ Pragma: +optSpace }" |
|
4111 |
||
4112 |
self error:'not an executable code object' |
|
4113 |
||
4114 |
"Created: 1.8.1997 / 00:16:44 / cg" |
|
4115 |
! |
|
4116 |
||
4117 |
invalidMessage |
|
4118 |
"{ Pragma: +optSpace }" |
|
4119 |
||
4120 |
"this is sent by ST/V code - its the same as #shouldNotImplement" |
|
4121 |
||
4122 |
^ self shouldNotImplement |
|
4123 |
! |
|
4124 |
||
4125 |
mustBeRectangle |
|
4126 |
"{ Pragma: +optSpace }" |
|
4127 |
||
4128 |
"report an argument-not-rectangle-error" |
|
4129 |
||
4130 |
^ self error:'argument must be a Rectangle' |
|
4131 |
! |
|
4132 |
||
4133 |
mustBeString |
|
4134 |
"{ Pragma: +optSpace }" |
|
4135 |
||
4136 |
"report an argument-not-string-error" |
|
4137 |
||
4138 |
^ self error:'argument must be a String' |
|
4139 |
! |
|
4140 |
||
4141 |
notIndexed |
|
4142 |
"{ Pragma: +optSpace }" |
|
4143 |
||
4144 |
<context: #return> |
|
4145 |
||
4146 |
"report an error that receiver has no indexed instance variables. |
|
4147 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4148 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4149 |
^ SubscriptOutOfBoundsError |
6654 | 4150 |
raiseErrorString:'receiver has no indexed variables' |
5755 | 4151 |
|
4152 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
|
4153 |
! |
|
4154 |
||
4155 |
openDebuggerOnException:ex |
|
4156 |
"{ Pragma: +optSpace }" |
|
4157 |
||
4158 |
"enter the debugger on some unhandled exception" |
|
4159 |
||
6884 | 4160 |
|msgString debugger answer| |
5755 | 4161 |
|
7208 | 4162 |
msgString := ex description. |
5755 | 4163 |
|
4164 |
" |
|
4165 |
if there is no debugger, |
|
4166 |
ask for ignore or exit. Exit will terminate the applciation. |
|
4167 |
ignore will raise an abortSignal. |
|
4168 |
" |
|
4169 |
Debugger isNil ifTrue:[ |
|
6840 | 4170 |
msgString := 'Error: ' , msgString. |
6654 | 4171 |
|
4172 |
Smalltalk isStandAloneApp ifTrue:[ |
|
4173 |
Dialog notNil ifTrue:[ |
|
7208 | 4174 |
AbortSignal isHandled ifTrue:[ |
4175 |
answer := OptionBox |
|
4176 |
request:msgString |
|
4177 |
label:msgString |
|
4178 |
buttonLabels:#('Ignore' 'Abort' 'Exit') |
|
4179 |
values:#(#ignore #abort #exit) |
|
4180 |
default:#exit. |
|
4181 |
] ifFalse:[ |
|
4182 |
answer := OptionBox |
|
4183 |
request:msgString |
|
4184 |
label:msgString |
|
4185 |
buttonLabels:#('Ignore' 'Exit') |
|
4186 |
values:#(#ignore #exit) |
|
4187 |
default:#exit. |
|
4188 |
]. |
|
6884 | 4189 |
answer == #abort ifTrue:[ |
6654 | 4190 |
^ AbortSignal raise |
6884 | 4191 |
]. |
7208 | 4192 |
answer == #ignore ifTrue:[ |
6884 | 4193 |
^ nil |
4194 |
]. |
|
6654 | 4195 |
]. |
6845
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4196 |
"/ dont output the message, if its a CTRL-C (userInterrupt) |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4197 |
ex signal == NoHandlerError ifTrue:[ |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4198 |
ex parameter signal == UserInterrupt ifTrue:[ |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4199 |
OperatingSystem exit:130 |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4200 |
]. |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4201 |
]. |
6654 | 4202 |
msgString errorPrintCR. |
4203 |
OperatingSystem exit:1 |
|
4204 |
]. |
|
4205 |
||
4206 |
msgString errorPrintCR. |
|
4207 |
Smalltalk fatalAbort:'no Debugger defined' |
|
5755 | 4208 |
]. |
4209 |
||
4210 |
" |
|
4211 |
find an appropriate debugger to use |
|
4212 |
" |
|
4213 |
debugger := self appropriateDebugger:(thisContext selector). |
|
4214 |
debugger isNil ifTrue:[ |
|
6654 | 4215 |
^ AbortSignal raise |
5755 | 4216 |
]. |
4217 |
||
4218 |
^ debugger |
|
6654 | 4219 |
enter:ex suspendedContext |
4220 |
withMessage:msgString |
|
4221 |
mayProceed:(ex mayProceed). |
|
5755 | 4222 |
|
4223 |
"Modified: 24.7.1997 / 10:09:20 / cg" |
|
4224 |
! |
|
4225 |
||
4226 |
primitiveFailed |
|
4227 |
"{ Pragma: +optSpace }" |
|
4228 |
||
4229 |
"report an error that some primitive code failed. |
|
4230 |
The error is reported by raising the PrimitiveFailureSignal exception." |
|
4231 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4232 |
^ PrimitiveFailure raiseRequestWith:nil |
5755 | 4233 |
|
6005 | 4234 |
" |
4235 |
1234 primitiveFailed |
|
4236 |
" |
|
4237 |
||
5755 | 4238 |
"Modified: / 8.5.1996 / 09:14:07 / cg" |
4239 |
"Modified: / 26.7.1999 / 10:58:08 / stefan" |
|
4240 |
! |
|
4241 |
||
6005 | 4242 |
primitiveFailed:messageString |
4243 |
"{ Pragma: +optSpace }" |
|
4244 |
||
4245 |
"report an error that some primitive code failed. |
|
4246 |
The error is reported by raising the PrimitiveFailureSignal exception." |
|
4247 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4248 |
^ PrimitiveFailure raiseRequestWith:nil errorString:messageString |
6005 | 4249 |
|
4250 |
" |
|
4251 |
1234 primitiveFailed:'this is a test' |
|
4252 |
" |
|
4253 |
! |
|
4254 |
||
6815 | 4255 |
shouldImplement |
4256 |
"{ Pragma: +optSpace }" |
|
4257 |
||
4258 |
"report an error that this message should be implemented. |
|
4259 |
This is send by automatically generated method bodies" |
|
4260 |
||
4261 |
^ self error:'method not yet implemented by class' |
|
4262 |
! |
|
4263 |
||
5755 | 4264 |
shouldNotImplement |
4265 |
"{ Pragma: +optSpace }" |
|
4266 |
||
4267 |
"report an error that this message should not be implemented" |
|
4268 |
||
4269 |
^ self error:'method not appropriate for this class' |
|
4270 |
||
4271 |
"Modified: 8.5.1996 / 09:09:44 / cg" |
|
4272 |
! |
|
4273 |
||
4274 |
subclassResponsibility |
|
4275 |
"{ Pragma: +optSpace }" |
|
4276 |
||
4277 |
"report an error that this message should have been reimplemented in a |
|
4278 |
subclass" |
|
4279 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4280 |
^ SubclassResponsibilityError |
6708 | 4281 |
raiseRequestErrorString:'method must be reimplemented in subclass' |
5755 | 4282 |
! |
4283 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4284 |
subclassResponsibility:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4285 |
"{ Pragma: +optSpace }" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4286 |
|
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4287 |
"report an error that this message should have been reimplemented in a subclass" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4288 |
|
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4289 |
^ SubclassResponsibilityError |
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4290 |
raiseRequestErrorString:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4291 |
! |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4292 |
|
5755 | 4293 |
subscriptBoundsError |
4294 |
"{ Pragma: +optSpace }" |
|
4295 |
||
4296 |
"report an error that some index is out of bounds. |
|
4297 |
(when accessing indexable collections). |
|
4298 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4299 |
||
4300 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:nil |
|
4301 |
||
4302 |
"Modified: / 26.7.1996 / 16:45:42 / cg" |
|
4303 |
"Modified: / 26.7.1999 / 10:58:27 / stefan" |
|
4304 |
! |
|
4305 |
||
4306 |
subscriptBoundsError:anIndex |
|
4307 |
"{ Pragma: +optSpace }" |
|
4308 |
||
4309 |
"report an error that anIndex is out of bounds. |
|
4310 |
(when accessing indexable collections). |
|
4311 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4312 |
||
6221 | 4313 |
^ SubscriptOutOfBoundsError |
6654 | 4314 |
raiseRequestWith:anIndex |
4315 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
5755 | 4316 |
|
6221 | 4317 |
"Modified: / 17.11.2001 / 22:49:56 / cg" |
5755 | 4318 |
! |
4319 |
||
4320 |
typeCheckError |
|
4321 |
"{ Pragma: +optSpace }" |
|
4322 |
||
4323 |
"generated when a variable declared with a type hint gets a bad |
|
4324 |
value assigned" |
|
4325 |
||
4326 |
^ self error:'bad assign of ' , self printString , |
|
6654 | 4327 |
' (' , self class name , ') to typed variable' |
5755 | 4328 |
! ! |
4329 |
||
4330 |
!Object methodsFor:'evaluation'! |
|
4331 |
||
4332 |
value |
|
4333 |
"return the receiver itself. |
|
4334 |
This allows every object to be used where blocks or valueHolders |
|
4335 |
are typically used, and allows for valueHolders and blocks to be |
|
4336 |
used interchangably in some situations. |
|
4337 |
||
4338 |
Time will show, if this is a good idea or leads to sloppy programming |
|
4339 |
style ... (the idea was borrowed from the Self language). |
|
4340 |
||
4341 |
WARNING: dont 'optimize' away ifXXX: blocks |
|
6654 | 4342 |
(i.e. do NOT replace |
4343 |
foo ifTrue:[var1] ifFalse:[var2] |
|
4344 |
by: |
|
4345 |
foo ifTrue:var1 ifFalse:var2 |
|
4346 |
) |
|
4347 |
- the compilers will only generate inline code for the if, |
|
4348 |
iff the argument(s) are blocks - otherwise, a true send is |
|
4349 |
generated. |
|
4350 |
This 'oprimization' will work semantically correct, |
|
4351 |
but execute SLOWER instead." |
|
5755 | 4352 |
|
4353 |
^ self |
|
4354 |
||
4355 |
" |
|
4356 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
|
4357 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
4358 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
4359 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
4360 |
" |
|
4361 |
||
4362 |
"DO NOT DO THIS (its slower) |
|
4363 |
(1 > 4) ifTrue:'oops' ifFalse:'ok' |
|
4364 |
||
4365 |
USE (the compiler optimizes blocks in if/while): |
|
4366 |
(1 > 4) ifTrue:['oops'] ifFalse:['ok'] |
|
4367 |
" |
|
4368 |
||
4369 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
4370 |
! ! |
|
4371 |
||
4372 |
!Object methodsFor:'finalization'! |
|
4373 |
||
4374 |
disposed |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4375 |
"OBSOLETE INTERFACE: use #finalize |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4376 |
this is invoked for objects which have been registered |
5755 | 4377 |
in a Registry, when the original object dies. |
4378 |
Subclasses may redefine this method" |
|
4379 |
||
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4380 |
<resource: #obsolete> |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4381 |
|
5755 | 4382 |
^ self |
4383 |
! |
|
4384 |
||
4385 |
executor |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4386 |
"Return the object which does the finalization for me. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4387 |
This interface is also VW & Sqeak compatible," |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4388 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4389 |
"for now, send #shallowCopyForFinalization, to be compatible with |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4390 |
classes designed for old ST/X versions" |
5755 | 4391 |
|
4392 |
^ self shallowCopyForFinalization |
|
4393 |
! |
|
4394 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4395 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4396 |
"answer a Registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4397 |
Use a generic Registry for any object. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4398 |
Subclasses using their own Registry should redefine this" |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4399 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4400 |
^ FinalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4401 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4402 |
|
5755 | 4403 |
finalize |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4404 |
"this is invoked for executor objects which have been registered |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4405 |
in a Registry, when the original object dies. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4406 |
Subclasses may redefine this method |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4407 |
This interface is also VW-compatible" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4408 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4409 |
"send #disposed for compatibility with existing classes that still |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4410 |
implement the obsolete #disposed message" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4411 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4412 |
^ self disposed |
5755 | 4413 |
! |
4414 |
||
4415 |
reRegisterForFinalization |
|
4416 |
"re-register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4417 |
This will create a new executor, which will receive a #finalize message when |
5755 | 4418 |
the receiver is garbage collected." |
4419 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4420 |
self finalizationLobby registerChange:self |
5755 | 4421 |
! |
4422 |
||
4423 |
registerForFinalization |
|
4424 |
"register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4425 |
Once registered, the executor of the receiver will receive a #finalize message when |
5755 | 4426 |
the receiver is garbage collected." |
4427 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4428 |
self finalizationLobby register:self |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4429 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4430 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4431 |
shallowCopyForFinalization |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4432 |
"OBSOLETE INTERFACE: use #executor. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4433 |
This is used to aquire a copy to be used for finalization - |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4434 |
(the copy will be sent a #finalize message; see the documentation in the Registry class) |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4435 |
This method can be redefined for more efficient copying - especially for large objects." |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4436 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4437 |
<resource: #obsolete> |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4438 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4439 |
^ self shallowCopy |
5755 | 4440 |
! |
4441 |
||
4442 |
unregisterForFinalization |
|
4443 |
"unregister mySelf from later finalization" |
|
4444 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4445 |
self finalizationLobby unregister:self |
5755 | 4446 |
! ! |
4447 |
||
4448 |
!Object methodsFor:'initialization'! |
|
4449 |
||
4450 |
initialize |
|
4451 |
"just to ignore initialize to objects which do not need it" |
|
4452 |
||
4453 |
^ self |
|
4454 |
! ! |
|
4455 |
||
4456 |
!Object methodsFor:'interest'! |
|
4457 |
||
4458 |
addInterest:anInterest |
|
4459 |
"install an interest forwarder. |
|
4460 |
Here, we use the nonWeakDependencies." |
|
4461 |
||
4462 |
self addNonWeakDependent:anInterest |
|
4463 |
||
4464 |
"Created: 14.10.1996 / 22:27:34 / stefan" |
|
4465 |
! |
|
4466 |
||
4467 |
expressInterestIn:aspect for:anObject sendBack:aSelector |
|
4468 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
4469 |
changes aspect." |
|
4470 |
||
4471 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
4472 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4473 |
||
4474 |
self addInterest:(InterestConverter |
|
6654 | 4475 |
destination:anObject |
4476 |
selector:aSelector |
|
4477 |
aspect:aspect) |
|
5755 | 4478 |
|
4479 |
" |
|
4480 |
|p b| |
|
4481 |
||
4482 |
b := [Transcript showCR:' -> the point changed']. |
|
4483 |
||
4484 |
p := Point new. |
|
4485 |
Transcript showCR:'interest in #foo:'. |
|
4486 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4487 |
p x:1. |
|
4488 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
4489 |
p changed:#bar. |
|
4490 |
Transcript cr. |
|
4491 |
||
4492 |
Delay waitForSeconds:1. |
|
4493 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
4494 |
p changed:#foo. |
|
4495 |
Transcript cr. |
|
4496 |
||
4497 |
Delay waitForSeconds:1. |
|
4498 |
Transcript showCR:'no more interest in #foo:'. |
|
4499 |
p retractInterestIn:#foo for:b. |
|
4500 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4501 |
p changed:#foo. |
|
4502 |
Transcript cr. |
|
4503 |
||
4504 |
Delay waitForSeconds:1. |
|
4505 |
Transcript showCR:'interest in #bar now:'. |
|
4506 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
4507 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4508 |
p changed:#foo. |
|
4509 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
4510 |
p changed:#bar. |
|
4511 |
Transcript cr. |
|
4512 |
||
4513 |
Delay waitForSeconds:1. |
|
4514 |
Transcript showCR:'interest in #foo now:'. |
|
4515 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4516 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
4517 |
p changed:#foo. |
|
4518 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
4519 |
p changed:#bar. |
|
4520 |
Transcript cr. |
|
4521 |
||
4522 |
Delay waitForSeconds:1. |
|
4523 |
Transcript showCR:'no more interests:'. |
|
4524 |
p retractInterestsFor:b. |
|
4525 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4526 |
p changed:#foo. |
|
4527 |
Transcript showCR:'now changing #bar... (expect no notification)'. |
|
4528 |
p changed:#bar. |
|
4529 |
Transcript cr. |
|
4530 |
||
4531 |
p release. |
|
4532 |
" |
|
4533 |
||
4534 |
"Created: 19.4.1996 / 10:26:22 / cg" |
|
4535 |
"Modified: 19.4.1996 / 12:34:08 / cg" |
|
4536 |
"Modified: 14.10.1996 / 22:28:20 / stefan" |
|
4537 |
! |
|
4538 |
||
4539 |
interests |
|
4540 |
"return a Collection of interests - empty if there is none. |
|
4541 |
Here, we use the nonWeakDependents for interests." |
|
4542 |
||
4543 |
^ self nonWeakDependents |
|
4544 |
||
4545 |
"Created: / 14.10.1996 / 22:20:51 / stefan" |
|
4546 |
"Modified: / 30.1.1998 / 14:07:35 / cg" |
|
4547 |
! |
|
4548 |
||
4549 |
interestsFor:someOne |
|
4550 |
"return a collection of interests of someOne - empty if there is none." |
|
4551 |
||
4552 |
|coll deps| |
|
4553 |
||
4554 |
deps := self interests. |
|
4555 |
deps size == 0 ifTrue:[^ #()]. |
|
4556 |
||
4557 |
coll := IdentitySet new. |
|
4558 |
||
4559 |
deps do:[:dep | |
|
6654 | 4560 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
4561 |
dep destination == someOne ifTrue:[ |
|
4562 |
coll add:dep. |
|
4563 |
] |
|
4564 |
] |
|
5755 | 4565 |
]. |
4566 |
^ coll |
|
4567 |
||
4568 |
"Created: / 30.1.1998 / 14:02:26 / cg" |
|
4569 |
"Modified: / 30.1.1998 / 14:08:24 / cg" |
|
4570 |
! |
|
4571 |
||
4572 |
onChangeEvaluate:aBlock |
|
4573 |
"arrange for aBlock to be evaluated whenever the receiver changes." |
|
4574 |
||
4575 |
^ self onChangeSend:#value to:aBlock |
|
4576 |
||
4577 |
"Created: / 29.1.1999 / 16:01:22 / cg" |
|
4578 |
! |
|
4579 |
||
4580 |
onChangeSend:aSelector to:anObject |
|
4581 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
4582 |
changes." |
|
4583 |
||
4584 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
4585 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4586 |
||
4587 |
self addInterest:(InterestConverter |
|
6654 | 4588 |
destination:anObject |
4589 |
selector:aSelector) |
|
5755 | 4590 |
|
4591 |
" |
|
4592 |
|p b| |
|
4593 |
||
4594 |
b := [Transcript showCR:'the point changed']. |
|
4595 |
||
4596 |
p := Point new. |
|
4597 |
p onChangeSend:#value to:b. |
|
4598 |
p x:1. |
|
4599 |
Transcript showCR:'now changing'. |
|
4600 |
p changed. |
|
4601 |
Transcript cr. |
|
4602 |
||
4603 |
Delay waitForSeconds:1. |
|
4604 |
Transcript showCR:'now changing'. |
|
4605 |
p changed. |
|
4606 |
Transcript cr. |
|
4607 |
||
4608 |
Delay waitForSeconds:1. |
|
4609 |
Transcript showCR:'no more interest'. |
|
4610 |
p retractInterestsFor:b. |
|
4611 |
Transcript showCR:'now changing again'. |
|
4612 |
p changed. |
|
4613 |
Transcript cr. |
|
4614 |
||
4615 |
Delay waitForSeconds:1. |
|
4616 |
Transcript showCR:'interest again'. |
|
4617 |
p onChangeSend:#value to:b. |
|
4618 |
Transcript showCR:'now changing again'. |
|
4619 |
p changed. |
|
4620 |
Transcript cr. |
|
4621 |
" |
|
4622 |
||
4623 |
"Created: 19.4.1996 / 10:26:38 / cg" |
|
4624 |
"Modified: 19.4.1996 / 12:34:26 / cg" |
|
4625 |
"Modified: 14.10.1996 / 22:28:27 / stefan" |
|
4626 |
! |
|
4627 |
||
4628 |
removeInterest:anInterest |
|
4629 |
"remove an interest forwarder. |
|
4630 |
Here, we use the nonWeakDependencies." |
|
4631 |
||
4632 |
self removeNonWeakDependent:anInterest |
|
4633 |
||
4634 |
"Created: 14.10.1996 / 22:21:59 / stefan" |
|
4635 |
! |
|
4636 |
||
4637 |
retractInterestIn:aspect for:someOne |
|
4638 |
"remove the interest of someOne in the receiver changing aspect |
|
4639 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
4640 |
||
4641 |
"/ for now, remove the interestConverter. |
|
4642 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4643 |
||
4644 |
"/ cannot removeDependent within the loop - the collection rehashes |
|
4645 |
||
4646 |
|deps coll| |
|
4647 |
||
4648 |
deps := self interests. |
|
4649 |
deps size ~~ 0 ifTrue:[ |
|
6654 | 4650 |
coll := IdentitySet new. |
4651 |
||
4652 |
deps do:[:dep | |
|
4653 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
|
4654 |
dep destination == someOne ifTrue:[ |
|
4655 |
dep aspect == aspect ifTrue:[ |
|
4656 |
self removeInterest:dep. |
|
4657 |
^ self |
|
4658 |
] |
|
4659 |
] |
|
4660 |
] |
|
4661 |
]. |
|
4662 |
coll do:[:dep | |
|
4663 |
self removeInterest:dep. |
|
4664 |
]. |
|
5755 | 4665 |
]. |
4666 |
||
4667 |
||
4668 |
" |
|
4669 |
|p b| |
|
4670 |
||
4671 |
b := [Transcript showCR:'the point changed']. |
|
4672 |
||
4673 |
p := Point new. |
|
4674 |
Transcript showCR:'interest in #foo'. |
|
4675 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4676 |
p x:1. |
|
4677 |
Transcript showCR:'now changing #bar'. |
|
4678 |
p changed:#bar. |
|
4679 |
Transcript cr. |
|
4680 |
||
4681 |
Delay waitForSeconds:1. |
|
4682 |
Transcript showCR:'now changing #foo'. |
|
4683 |
p changed:#foo. |
|
4684 |
Transcript cr. |
|
4685 |
||
4686 |
Delay waitForSeconds:1. |
|
4687 |
Transcript showCR:'no more interest in #foo'. |
|
4688 |
p retractInterestIn:#foo for:b. |
|
4689 |
Transcript showCR:'now changing #foo'. |
|
4690 |
p changed:#foo. |
|
4691 |
Transcript cr. |
|
4692 |
||
4693 |
Delay waitForSeconds:1. |
|
4694 |
Transcript showCR:'interest in #bar now'. |
|
4695 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
4696 |
Transcript showCR:'now changing #foo'. |
|
4697 |
p changed:#foo. |
|
4698 |
Transcript showCR:'now changing #bar'. |
|
4699 |
p changed:#bar. |
|
4700 |
Transcript cr. |
|
4701 |
||
4702 |
Delay waitForSeconds:1. |
|
4703 |
Transcript showCR:'interest in #foo now'. |
|
4704 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4705 |
Transcript showCR:'now changing #foo'. |
|
4706 |
p changed:#foo. |
|
4707 |
Transcript showCR:'now changing #bar'. |
|
4708 |
p changed:#bar. |
|
4709 |
Transcript cr. |
|
4710 |
||
4711 |
Delay waitForSeconds:1. |
|
4712 |
Transcript showCR:'no more interests'. |
|
4713 |
p retractInterestsFor:b. |
|
4714 |
Transcript showCR:'now changing #foo'. |
|
4715 |
p changed:#foo. |
|
4716 |
Transcript showCR:'now changing #bar'. |
|
4717 |
p changed:#bar. |
|
4718 |
Transcript cr. |
|
4719 |
" |
|
4720 |
||
4721 |
"Created: / 19.4.1996 / 10:27:11 / cg" |
|
4722 |
"Modified: / 14.10.1996 / 22:21:19 / stefan" |
|
4723 |
"Modified: / 30.1.1998 / 14:05:34 / cg" |
|
4724 |
! |
|
4725 |
||
4726 |
retractInterestsFor:someOne |
|
4727 |
"remove the interest of someOne in the receiver |
|
4728 |
(as installed with #onChangeSend:to:)." |
|
4729 |
||
4730 |
"/ for now, remove the interestConverter. |
|
4731 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4732 |
||
4733 |
|coll deps| |
|
4734 |
||
4735 |
"/ cannot removeDependent within the loop - the collection rehashes |
|
4736 |
||
4737 |
deps := self interests. |
|
4738 |
deps size ~~ 0 ifTrue:[ |
|
6654 | 4739 |
coll := IdentitySet new. |
4740 |
||
4741 |
deps do:[:dep | |
|
4742 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
|
4743 |
dep destination == someOne ifTrue:[ |
|
4744 |
coll add:dep. |
|
4745 |
] |
|
4746 |
] |
|
4747 |
]. |
|
4748 |
coll do:[:dep | |
|
4749 |
self removeInterest:dep. |
|
4750 |
]. |
|
5755 | 4751 |
]. |
4752 |
||
4753 |
||
4754 |
||
4755 |
" |
|
4756 |
|p b| |
|
4757 |
||
4758 |
b := [Transcript showCR:'the point changed']. |
|
4759 |
||
4760 |
p := Point new. |
|
4761 |
p onChangeSend:#value to:b. |
|
4762 |
p x:1. |
|
4763 |
Transcript showCR:'now changing'. |
|
4764 |
p changed. |
|
4765 |
Transcript cr. |
|
4766 |
||
4767 |
Delay waitForSeconds:1. |
|
4768 |
Transcript showCR:'now changing'. |
|
4769 |
p changed. |
|
4770 |
Transcript cr. |
|
4771 |
||
4772 |
Delay waitForSeconds:1. |
|
4773 |
Transcript showCR:'no more interest'. |
|
4774 |
p retractInterestsFor:b. |
|
4775 |
Transcript showCR:'now changing again'. |
|
4776 |
p changed. |
|
4777 |
Transcript cr. |
|
4778 |
||
4779 |
Delay waitForSeconds:1. |
|
4780 |
Transcript showCR:'interest again'. |
|
4781 |
p onChangeSend:#value to:b. |
|
4782 |
Transcript showCR:'now changing again'. |
|
4783 |
p changed. |
|
4784 |
Transcript cr. |
|
4785 |
" |
|
4786 |
||
4787 |
"Created: / 19.4.1996 / 10:23:46 / cg" |
|
4788 |
"Modified: / 14.10.1996 / 22:21:25 / stefan" |
|
4789 |
"Modified: / 30.1.1998 / 14:04:52 / cg" |
|
4790 |
! ! |
|
4791 |
||
4792 |
!Object methodsFor:'interrupt handling'! |
|
4793 |
||
4794 |
childSignalInterrupt |
|
4795 |
"death of a child process (unix process) - do nothing" |
|
4796 |
||
4797 |
^ self |
|
4798 |
! |
|
4799 |
||
4800 |
customInterrupt |
|
4801 |
"{ Pragma: +optSpace }" |
|
4802 |
||
4803 |
"a custom interrupt - but no handler has defined" |
|
4804 |
||
4805 |
self error:'custom interrupt' mayProceed:true |
|
4806 |
! |
|
4807 |
||
4808 |
errorInterrupt:errorID with:aParameter |
|
4809 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
4810 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
|
4811 |
which can be called from C subsystems to raise an (asynchronous) |
|
4812 |
error exception. |
|
4813 |
||
4814 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
4815 |
used from other C subsystems too, to upcast errors. |
|
4816 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
4817 |
IDs (currently) used: |
|
6654 | 4818 |
#DisplayError ..... x-error interrupt |
4819 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
5755 | 4820 |
" |
4821 |
||
6263
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4822 |
|handlers handler| |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4823 |
|
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4824 |
handlers := ObjectMemory registeredErrorInterruptHandlers. |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4825 |
handlers notNil ifTrue:[ |
6654 | 4826 |
handler := handlers at:errorID ifAbsent:nil. |
4827 |
handler notNil ifTrue:[ |
|
4828 |
"/ |
|
4829 |
"/ handler found; let it do whatever it wants ... |
|
4830 |
"/ |
|
4831 |
handler errorInterrupt:errorID with:aParameter. |
|
4832 |
^ self |
|
4833 |
]. |
|
5755 | 4834 |
]. |
4835 |
||
4836 |
"/ |
|
4837 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
4838 |
"/ |
|
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
4839 |
^ Error |
6654 | 4840 |
raiseRequestWith:errorID |
4841 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
5755 | 4842 |
! |
4843 |
||
4844 |
exceptionInterrupt |
|
4845 |
"{ Pragma: +optSpace }" |
|
4846 |
||
4847 |
"exception interrupt - enter debugger" |
|
4848 |
||
4849 |
self error:'exception Interrupt' mayProceed:true |
|
4850 |
! |
|
4851 |
||
4852 |
fpExceptionInterrupt |
|
4853 |
"{ Pragma: +optSpace }" |
|
4854 |
||
4855 |
"a floating point exception occured - this one |
|
4856 |
has to be handled differently since it comes asynchronous |
|
4857 |
on some machines (for example, on machines with a separate FPU |
|
4858 |
or superscalar architectures. Also, errors from within primitive code |
|
4859 |
(or library functions such as GL) are sent via the Unix-signal |
|
4860 |
mechanism this way." |
|
4861 |
||
4862 |
|where rec| |
|
4863 |
||
4864 |
where := thisContext sender. |
|
4865 |
rec := where receiver. |
|
4866 |
rec isNumber ifTrue:[ |
|
6654 | 4867 |
^ rec class |
4868 |
raise:#domainErrorSignal |
|
4869 |
receiver:rec |
|
4870 |
selector:where selector |
|
4871 |
arguments:(where args asArray) |
|
4872 |
errorString:'floating point exception' |
|
5755 | 4873 |
]. |
4874 |
||
4875 |
"/ could be in some C-library ... |
|
4876 |
^ Float domainErrorSignal raise |
|
4877 |
! |
|
4878 |
||
4879 |
internalError:msg |
|
4880 |
"{ Pragma: +optSpace }" |
|
4881 |
||
4882 |
"this is triggered, when VM hits some bad error, |
|
4883 |
such as corrupted class, corrupted method/selector array |
|
4884 |
etc. The argument string gives some more information on what happened. |
|
4885 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
|
4886 |
Its not guaranteed, that the system is in a working condition once |
|
4887 |
this error occurred ...." |
|
4888 |
||
4889 |
InternalErrorSignal raiseWith:self errorString:msg |
|
4890 |
! |
|
4891 |
||
4892 |
ioInterrupt |
|
4893 |
"{ Pragma: +optSpace }" |
|
4894 |
||
4895 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
|
4896 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
4897 |
or it does not understand the ioInterrupt message. |
|
4898 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
4899 |
||
4900 |
self error:'I/O Interrupt - but no handler' mayProceed:true |
|
4901 |
! |
|
4902 |
||
4903 |
memoryInterrupt |
|
4904 |
"{ Pragma: +optSpace }" |
|
4905 |
||
4906 |
"out-of-memory interrupt and no handler - enter debugger" |
|
4907 |
||
4908 |
self error:'almost out of memory' mayProceed:true |
|
4909 |
! |
|
4910 |
||
4911 |
recursionInterrupt |
|
4912 |
"{ Pragma: +optSpace }" |
|
4913 |
||
4914 |
"recursion limit (actually: stack overflow) interrupt. |
|
4915 |
This interrupt is triggered, when a process stack grows above |
|
4916 |
its stackLimit - usually, this leads into the debugger, but |
|
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4917 |
could be caught. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4918 |
Under Unix, the stackLimit may be increased in the handler, |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4919 |
and the exception can be resumed. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4920 |
Sorry, but under win32, the stack cannot grow, and the exception |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4921 |
is not proceedable. |
5755 | 4922 |
At the time we arrive here, the system has still some stack |
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4923 |
as a reserve so we can continue to do some useful work, or cleanup, |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4924 |
or debug for a while. |
5755 | 4925 |
If the signal is ignored, and the stack continues to grow, there |
4926 |
will be a few more chances (and more interrupts) before the VM |
|
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4927 |
terminates the process." |
5755 | 4928 |
|
4929 |
|con remaining| |
|
4930 |
||
4931 |
(con := thisContext) isRecursive ifFalse:[ |
|
4932 |
"/ Processor activeProcess usedStackSize < Processor activeProcess maximumStackSize ifTrue:[ |
|
4933 |
"/ "/ mhmh - it hit me, but I am not responsible ... |
|
4934 |
"/ 'Stray recursionInterrupt ...' infoPrintCR. |
|
4935 |
"/ ^ self |
|
4936 |
"/ ]. |
|
6654 | 4937 |
ObjectMemory infoPrinting ifTrue:[ |
4938 |
'Object [info]: recursionInterrupt from:' printCR. |
|
4939 |
con := con sender. |
|
4940 |
remaining := 50. |
|
4941 |
[con notNil and:[remaining > 0]] whileTrue:[ |
|
4942 |
'| ' print. con fullPrint. |
|
4943 |
con := con sender. |
|
4944 |
remaining := remaining - 1 |
|
4945 |
]. |
|
4946 |
]. |
|
4947 |
^ RecursionInterruptSignal raiseSignal |
|
5755 | 4948 |
] |
4949 |
||
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4950 |
"Modified: / 10.11.2001 / 15:15:56 / cg" |
5755 | 4951 |
! |
4952 |
||
4953 |
schedulerInterrupt |
|
4954 |
"{ Pragma: +optSpace }" |
|
4955 |
||
4956 |
"scheduler interrupt (supposed to be sent to Processor). |
|
4957 |
If we arrive here, either the Processor does not understand it, |
|
4958 |
or it has been set to nil. In any case, this is a sign of some |
|
4959 |
big trouble. Enter debugger." |
|
4960 |
||
4961 |
self error:'schedulerInterrupt - but no Processor' mayProceed:true |
|
4962 |
! |
|
4963 |
||
4964 |
signalInterrupt:signalNumber |
|
4965 |
"{ Pragma: +optSpace }" |
|
4966 |
||
4967 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
|
4968 |
(SIGPIPE), others (SIGBUS) are rather fatal ... |
|
4969 |
In any case, IF a smalltalk-signal has been connected to the OS signal, |
|
4970 |
that one is raised. |
|
4971 |
Otherwise, a dialog is shown, asking the user on how to handle the |
|
4972 |
signal. |
|
4973 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
|
4974 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
4975 |
Currently (temporary kludge), these are passed as global variables." |
|
4976 |
||
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4977 |
|name here sig fatal titles actions badContext msg pc addr |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4978 |
action title screen| |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4979 |
|
5755 | 4980 |
|
4981 |
"if there has been an ST-signal installed, use it ..." |
|
4982 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
4983 |
sig notNil ifTrue:[ |
|
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4984 |
sig raise. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4985 |
^ self. |
5755 | 4986 |
]. |
4987 |
||
4988 |
"/ if handled, raise OSSignalInterruptSignal |
|
4989 |
OSSignalInterruptSignal isHandled ifTrue:[ |
|
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4990 |
OSSignalInterruptSignal raiseRequestWith:signalNumber. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4991 |
^ self. |
5755 | 4992 |
]. |
4993 |
||
4994 |
" |
|
7031 | 4995 |
special case - SIGPWR: write a crash image and continue |
4996 |
- SIGHUP: write a crash image |
|
4997 |
" |
|
4998 |
signalNumber == 30 "OperatingSystem sigPWR" ifTrue:[ |
|
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4999 |
ObjectMemory snapShotOn:'crash.img'. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5000 |
^ self. |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
5001 |
]. |
7031 | 5002 |
(signalNumber == 1 "OperatingSystem sigHUP") ifTrue:[ |
5003 |
ObjectMemory snapShotOn:'crash.img'. |
|
5004 |
Smalltalk exit. |
|
5005 |
]. |
|
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
5006 |
|
5755 | 5007 |
name := OperatingSystem nameForSignal:signalNumber. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5008 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5009 |
"if there is no screen at all, bring up a mini debugger" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5010 |
(Screen isNil |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5011 |
or:[(screen := Screen current) isNil |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5012 |
or:[(screen := Screen default) isNil |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5013 |
or:[screen isOpen not]]]) ifTrue:[ |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5014 |
^ self startMiniDebuggerOrExit:'Signal (' , name, ')'. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5015 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5016 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5017 |
"ungrab - in case it happened in a box/popupview |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5018 |
otherwise display stays locked" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5019 |
screen ungrabPointer; ungrabKeyboard. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5020 |
|
7031 | 5021 |
here := thisContext. |
5022 |
badContext := here sender. "the context, in which the signal occurred" |
|
5023 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5024 |
"there is a screen. use it to bring up a box asking for what to do ..." |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5025 |
Screen currentScreenQuerySignal answer:screen do:[ |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5026 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5027 |
SIGBUS, SIGSEGV and SIGILL do not make sense to ignore (i.e. continue) |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5028 |
since the system will retry the faulty instruction, which leads to |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5029 |
another signal - to avoid frustration, better not offer this option. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5030 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5031 |
fatal := OperatingSystem isFatalSignal:signalNumber. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5032 |
fatal ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5033 |
(Debugger isNil or:[here isRecursive]) ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5034 |
'Object [hard error]: signal ' errorPrint. signalNumber errorPrintCR. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5035 |
^ self startMiniDebuggerOrExit:'Signal (' , name, ')'. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5036 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5037 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5038 |
a hard signal - go into debugger immediately |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5039 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5040 |
msg := 'OS-signal: ', name. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5041 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5042 |
"/ the IRQ-PC is passed as low-hi, to avoid the need |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5043 |
"/ to allocate a LargeInteger in the VM during signal |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5044 |
"/ time. I know, this is ugly. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5045 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5046 |
InterruptPcLow notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5047 |
pc := InterruptPcLow + (InterruptPcHi bitShift:(SmallInteger maxBits + 1 // 2)). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5048 |
pc ~~ 0 ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5049 |
msg := msg , ' PC=' , (pc printStringRadix:16) |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5050 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5051 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5052 |
InterruptAddrLow notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5053 |
addr := InterruptAddrLow + (InterruptAddrHi bitShift:(SmallInteger maxBits + 1 // 2)). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5054 |
addr ~~ 0 ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5055 |
msg := msg , ' ADDR=' , (addr printStringRadix:16) |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5056 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5057 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5058 |
Debugger enter:here withMessage:msg mayProceed:false. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5059 |
"unreachable" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5060 |
^ nil. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5061 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5062 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5063 |
"if possible, open an option box asking the user what do. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5064 |
Otherwise, start a debugger" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5065 |
Dialog notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5066 |
titles := #('save crash image' 'dump core' 'exit ST/X' 'debug'). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5067 |
actions := #(save core exit debug). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5068 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5069 |
action := nil. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5070 |
title := 'OS Signal caught (' , name, ')'. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5071 |
title := (title , '\[in ST-process: ' , Processor activeProcess nameOrId ,']') withCRs. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5072 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5073 |
"/ if cought while in the scheduler or event dispatcher, |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5074 |
"/ a modal dialog is not possible ... |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5075 |
"/ (therefore, abort & return does not makes sense) |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5076 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5077 |
Processor activeProcess isSystemProcess ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5078 |
titles := #('abort') , titles. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5079 |
actions := #(abort), actions. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5080 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5081 |
badContext canReturn ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5082 |
titles := #('return') , titles. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5083 |
actions := #(return), actions. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5084 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5085 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5086 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5087 |
fatal ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5088 |
titles := titles, #('ignore'). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5089 |
actions := actions , #(ignore). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5090 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5091 |
action := Dialog choose:title |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5092 |
labels:titles |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5093 |
values:actions |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5094 |
default:(fatal ifTrue:[nil] ifFalse:[#ignore]). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5095 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5096 |
"Dialog may fail (if system process), default action is debug" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5097 |
action size == 0 ifTrue:[action := #debug]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5098 |
] ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5099 |
action := #debug. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5100 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5101 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5102 |
action == #save ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5103 |
ObjectMemory snapShotOn:'crash.img' |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5104 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5105 |
action == #core ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5106 |
Smalltalk fatalAbort |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5107 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5108 |
action == #exit ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5109 |
Smalltalk exit |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5110 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5111 |
action == #return ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5112 |
badContext return |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5113 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5114 |
action == #abort ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5115 |
AbortSignal raise. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5116 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5117 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5118 |
action == #debug ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5119 |
Debugger isNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5120 |
^ self startMiniDebuggerOrExit:'Signal (' , name, ')'. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5121 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5122 |
Debugger enter:here withMessage:('Signal ', name) mayProceed:true. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5123 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5124 |
"action == #ignore" |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5125 |
]. |
5755 | 5126 |
! |
5127 |
||
5128 |
spyInterrupt |
|
5129 |
"{ Pragma: +optSpace }" |
|
5130 |
||
5131 |
"spy interrupt and no handler - enter debugger" |
|
5132 |
||
5133 |
self error:'spy Interrupt - but no handler' mayProceed:true |
|
5134 |
! |
|
5135 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5136 |
startMiniDebuggerOrExit:text |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5137 |
"some critical condition happened. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5138 |
Start a mini debugger or exit if none is present" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5139 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5140 |
MiniDebugger isNil ifTrue:[ |
6654 | 5141 |
"a system without debugging facilities (i.e. a standalone system) |
5142 |
output a message and exit." |
|
5143 |
('Object [error]: exit due to ', text, ' - and no debugger.') errorPrintCR. |
|
5144 |
OperatingSystem exit:99. |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5145 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5146 |
MiniDebugger enterWithMessage:text mayProceed:true. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5147 |
! |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5148 |
|
5755 | 5149 |
timerInterrupt |
5150 |
"{ Pragma: +optSpace }" |
|
5151 |
||
5152 |
"timer interrupt and no handler - enter debugger" |
|
5153 |
||
5154 |
self error:'timer Interrupt - but no handler' mayProceed:true |
|
5155 |
! |
|
5156 |
||
5157 |
userInterrupt |
|
5158 |
"{ Pragma: +optSpace }" |
|
5159 |
||
5160 |
"user (^c) interrupt. |
|
5161 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
5162 |
controlling tty (i.e. in the xterm)." |
|
5163 |
||
6466 | 5164 |
UserInterruptSignal raiseRequest |
5755 | 5165 |
! |
5166 |
||
5167 |
userInterruptIn:aContext |
|
5168 |
"{ Pragma: +optSpace }" |
|
5169 |
||
5170 |
"user (^c) interrupt - enter debugger, but show aContext |
|
5171 |
as top-context. |
|
5172 |
This is used to hide any intermediate scheduler contexts, |
|
5173 |
in case of an interrupted process. Typically, this is sent by |
|
5174 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
5175 |
processed." |
|
5176 |
||
5177 |
<context: #return> |
|
5178 |
||
5179 |
UserInterruptSignal raiseRequestWith:nil errorString:nil in:aContext |
|
5180 |
||
5181 |
"Created: / 18.10.1996 / 20:46:04 / cg" |
|
5182 |
"Modified: / 20.10.1996 / 13:06:38 / cg" |
|
5183 |
"Modified: / 26.7.1999 / 10:58:49 / stefan" |
|
5184 |
! ! |
|
5185 |
||
5186 |
!Object methodsFor:'message sending'! |
|
5187 |
||
5188 |
perform:aSelector |
|
5189 |
"send the message aSelector to the receiver" |
|
5190 |
||
5191 |
%{ |
|
5192 |
REGISTER OBJ sel = aSelector; |
|
5193 |
||
5194 |
if (InterruptPending == nil) { |
|
6654 | 5195 |
struct inlineCache *pIlc; |
5196 |
static struct inlineCache ilc_0 = __ILCPERF0(@line); |
|
5197 |
static struct inlineCache ilc_1 = __ILCPERF0(@line); |
|
5198 |
static struct inlineCache ilc_2 = __ILCPERF0(@line); |
|
5199 |
static struct inlineCache ilc_3 = __ILCPERF0(@line); |
|
5200 |
static struct inlineCache ilc_4 = __ILCPERF0(@line); |
|
5201 |
static OBJ last_0 = nil; |
|
5202 |
static OBJ last_1 = nil; |
|
5203 |
static OBJ last_2 = nil; |
|
5204 |
static OBJ last_3 = nil; |
|
5205 |
static OBJ last_4 = nil; |
|
5206 |
static flip = 0; |
|
5207 |
||
5208 |
if (sel == last_0) { |
|
5209 |
pIlc = &ilc_0; |
|
5210 |
} else if (sel == last_1) { |
|
5211 |
pIlc = &ilc_1; |
|
5212 |
} else if (sel == last_2) { |
|
5213 |
pIlc = &ilc_2; |
|
5214 |
} else if (sel == last_3) { |
|
5215 |
pIlc = &ilc_3; |
|
5216 |
} else if (sel == last_4) { |
|
5217 |
pIlc = &ilc_4; |
|
5218 |
} else { |
|
5219 |
if (flip == 0) { |
|
5220 |
pIlc = &ilc_0; |
|
5221 |
flip = 1; |
|
5222 |
last_0 = sel; |
|
5223 |
} else if (flip == 1) { |
|
5224 |
pIlc = &ilc_1; |
|
5225 |
flip = 2; |
|
5226 |
last_1 = sel; |
|
5227 |
} else if (flip == 2) { |
|
5228 |
pIlc = &ilc_2; |
|
5229 |
flip = 3; |
|
5230 |
last_2 = sel; |
|
5231 |
} else if (flip == 3) { |
|
5232 |
pIlc = &ilc_3; |
|
5233 |
flip = 4; |
|
5234 |
last_3 = sel; |
|
5235 |
} else { |
|
5236 |
pIlc = &ilc_4; |
|
5237 |
flip = 0; |
|
5238 |
last_4 = sel; |
|
5239 |
} |
|
5240 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5241 |
if (pIlc->ilc_poly) { |
|
5242 |
__flushPolyCache(pIlc->ilc_poly); |
|
5243 |
pIlc->ilc_poly = 0; |
|
5244 |
} |
|
5245 |
} |
|
5246 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
|
5755 | 5247 |
} else { |
6654 | 5248 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
5249 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5755 | 5250 |
} |
5251 |
%}. |
|
5252 |
^ self perform:aSelector withArguments:#() |
|
5253 |
! |
|
5254 |
||
5255 |
perform:aSelector inClass:aClass withArguments:argArray |
|
5256 |
"send the message aSelector with all args taken from argArray |
|
5257 |
to the receiver as a super-send message. |
|
5258 |
This is actually more flexible than the normal super-send, since it allows |
|
5259 |
to execute a method in ANY superclass of the receiver (not just the |
|
5260 |
immediate superclass). |
|
5261 |
Thus, it is (theoretically) possible to do |
|
6654 | 5262 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
5755 | 5263 |
and evaluate Magnitudes compare method even if there was one in Number. |
5264 |
This method is used by the interpreter to evaluate super sends |
|
5265 |
and could be used for very special behavior (language extension ?). |
|
5266 |
||
5267 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
5268 |
||
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5269 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 myClass| |
5755 | 5270 |
|
5271 |
" |
|
5272 |
check, if aClass is really a superclass of the receiver |
|
5273 |
" |
|
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5274 |
myClass := self class. |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5275 |
(myClass == aClass or:[myClass isSubclassOf:aClass]) ifFalse:[ |
6654 | 5276 |
self error:'lookup-class argument is not a superclass of the receiver'. |
5277 |
^ nil |
|
5755 | 5278 |
]. |
5279 |
%{ |
|
5280 |
REGISTER OBJ *argP; |
|
5281 |
int nargs, i; |
|
5282 |
||
5283 |
if (__isArray(argArray)) { |
|
6654 | 5284 |
nargs = __arraySize(argArray); |
5285 |
argP = __arrayVal(argArray); |
|
5755 | 5286 |
} else { |
6654 | 5287 |
if (__isNonNilObject(argArray)) { |
5288 |
static struct inlineCache ilcSize = __ILC0(@line+1); |
|
5289 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5290 |
if (!__isSmallInteger(numberOfArgs)) |
|
5291 |
goto bad; |
|
5292 |
nargs = __intVal(numberOfArgs); |
|
5293 |
argP = (OBJ *)(&a1); |
|
5294 |
for (i=1; i <= nargs; i++) { |
|
5295 |
*argP++ = __AT_(argArray, __MKSMALLINT((INT)i)); |
|
5296 |
} |
|
5297 |
argP = (OBJ *)(&a1); |
|
5298 |
} else { |
|
5299 |
nargs = 0; |
|
5300 |
} |
|
5755 | 5301 |
} |
5302 |
switch (nargs) { |
|
6654 | 5303 |
case 0: |
5304 |
{ |
|
5305 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5306 |
RETURN ( _SEND0(self, aSelector, aClass, &ilc0)); |
|
5307 |
} |
|
5308 |
||
5309 |
case 1: |
|
5310 |
{ |
|
5311 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5312 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, argP[0])); |
|
5313 |
} |
|
5314 |
||
5315 |
case 2: |
|
5316 |
{ |
|
5317 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5318 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, argP[0], argP[1])); |
|
5319 |
} |
|
5320 |
||
5321 |
case 3: |
|
5322 |
{ |
|
5323 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5324 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, |
|
5325 |
argP[0], argP[1], argP[2])); |
|
5326 |
} |
|
5327 |
||
5328 |
case 4: |
|
5329 |
{ |
|
5330 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
5331 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, |
|
5332 |
argP[0], argP[1], argP[2], argP[3])); |
|
5333 |
} |
|
5334 |
||
5335 |
case 5: |
|
5336 |
{ |
|
5337 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
5338 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
5339 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5340 |
} |
|
5341 |
||
5342 |
case 6: |
|
5343 |
{ |
|
5344 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
5345 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
5346 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5])); |
|
5347 |
} |
|
5348 |
||
5349 |
case 7: |
|
5350 |
{ |
|
5351 |
static struct inlineCache ilc7 = __DUMMYILCSELF7(@line+1); |
|
5352 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
5353 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5354 |
argP[6])); |
|
5355 |
} |
|
5356 |
||
5357 |
case 8: |
|
5358 |
{ |
|
5359 |
static struct inlineCache ilc8 = __DUMMYILCSELF8(@line+1); |
|
5360 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
5361 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5362 |
argP[6], argP[7])); |
|
5363 |
} |
|
5364 |
||
5365 |
case 9: |
|
5366 |
{ |
|
5367 |
static struct inlineCache ilc9 = __DUMMYILCSELF9(@line+1); |
|
5368 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
5369 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5370 |
argP[6], argP[7], argP[8])); |
|
5371 |
} |
|
5372 |
||
5373 |
case 10: |
|
5374 |
{ |
|
5375 |
static struct inlineCache ilc10 = __DUMMYILCSELF10(@line+1); |
|
5376 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
5377 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5378 |
argP[6], argP[7], argP[8], argP[9])); |
|
5379 |
} |
|
5380 |
||
5381 |
case 11: |
|
5382 |
{ |
|
5383 |
static struct inlineCache ilc11 = __DUMMYILCSELF11(@line+1); |
|
5384 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
5385 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5386 |
argP[6], argP[7], argP[8], argP[9], argP[10])); |
|
5387 |
} |
|
5388 |
||
5389 |
case 12: |
|
5390 |
{ |
|
5391 |
static struct inlineCache ilc12 = __DUMMYILCSELF12(@line+1); |
|
5392 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
5393 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5394 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5395 |
argP[11])); |
|
5396 |
} |
|
5397 |
||
5398 |
case 13: |
|
5399 |
{ |
|
5400 |
static struct inlineCache ilc13 = __DUMMYILCSELF13(@line+1); |
|
5401 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
5402 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5403 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5404 |
argP[11], argP[12])); |
|
5405 |
} |
|
5406 |
||
5407 |
case 14: |
|
5408 |
{ |
|
5409 |
static struct inlineCache ilc14 = __DUMMYILCSELF14(@line+1); |
|
5410 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
5411 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5412 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5413 |
argP[11], argP[12], argP[13])); |
|
5414 |
} |
|
5415 |
||
5416 |
case 15: |
|
5417 |
{ |
|
5418 |
static struct inlineCache ilc15 = __DUMMYILCSELF15(@line+1); |
|
5419 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
5420 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5421 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5422 |
argP[11], argP[12], argP[13], argP[14])); |
|
5423 |
} |
|
5755 | 5424 |
|
5425 |
#ifdef _SEND16 |
|
6654 | 5426 |
case 16: |
5427 |
{ |
|
5428 |
static struct inlineCache ilc16 = __DUMMYILCSELF16(@line+1); |
|
5429 |
RETURN ( _SEND16(self, aSelector, aClass, &ilc15, |
|
5430 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5431 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5432 |
argP[11], argP[12], argP[13], argP[14], argP[15])); |
|
5433 |
} |
|
5755 | 5434 |
#endif |
5435 |
#ifdef _SEND17 |
|
6654 | 5436 |
case 17: |
5437 |
{ |
|
5438 |
static struct inlineCache ilc17 = __DUMMYILCSELF17(@line+1); |
|
5439 |
RETURN ( _SEND17(self, aSelector, aClass, &ilc15, |
|
5440 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5441 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5442 |
argP[11], argP[12], argP[13], argP[14], argP[15], argP[16])); |
|
5443 |
} |
|
5755 | 5444 |
#endif |
5445 |
||
5446 |
||
5447 |
} |
|
5448 |
bad:; |
|
5449 |
%}. |
|
5450 |
"/ arrive here, if bad number of arguments (too many) |
|
5451 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5452 |
||
5453 |
^ self primitiveFailed |
|
5454 |
! |
|
5455 |
||
5456 |
perform:aSelector with:arg |
|
5457 |
"send the one-arg-message aSelector to the receiver" |
|
5458 |
||
5459 |
%{ |
|
5460 |
REGISTER OBJ sel = aSelector; |
|
5461 |
||
5462 |
if (InterruptPending == nil) { |
|
6654 | 5463 |
struct inlineCache *pIlc; |
5464 |
static struct inlineCache ilc_0 = __ILCPERF1(@line); |
|
5465 |
static struct inlineCache ilc_1 = __ILCPERF1(@line); |
|
5466 |
static struct inlineCache ilc_2 = __ILCPERF1(@line); |
|
5467 |
static struct inlineCache ilc_3 = __ILCPERF1(@line); |
|
5468 |
static struct inlineCache ilc_4 = __ILCPERF1(@line); |
|
5469 |
static OBJ last_0 = nil; |
|
5470 |
static OBJ last_1 = nil; |
|
5471 |
static OBJ last_2 = nil; |
|
5472 |
static OBJ last_3 = nil; |
|
5473 |
static OBJ last_4 = nil; |
|
5474 |
static flip = 0; |
|
5475 |
||
5476 |
if (sel == last_0) { |
|
5477 |
pIlc = &ilc_0; |
|
5478 |
} else if (sel == last_1) { |
|
5479 |
pIlc = &ilc_1; |
|
5480 |
} else if (sel == last_2) { |
|
5481 |
pIlc = &ilc_2; |
|
5482 |
} else if (sel == last_3) { |
|
5483 |
pIlc = &ilc_3; |
|
5484 |
} else if (sel == last_4) { |
|
5485 |
pIlc = &ilc_4; |
|
5486 |
} else { |
|
5487 |
if (flip == 0) { |
|
5488 |
pIlc = &ilc_0; |
|
5489 |
flip = 1; |
|
5490 |
last_0 = sel; |
|
5491 |
} else if (flip == 1) { |
|
5492 |
pIlc = &ilc_1; |
|
5493 |
flip = 2; |
|
5494 |
last_1 = sel; |
|
5495 |
} else if (flip == 2) { |
|
5496 |
pIlc = &ilc_2; |
|
5497 |
flip = 3; |
|
5498 |
last_2 = sel; |
|
5499 |
} else if (flip == 3) { |
|
5500 |
pIlc = &ilc_3; |
|
5501 |
flip = 4; |
|
5502 |
last_3 = sel; |
|
5503 |
} else { |
|
5504 |
pIlc = &ilc_4; |
|
5505 |
flip = 0; |
|
5506 |
last_4 = sel; |
|
5507 |
} |
|
5508 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5509 |
if (pIlc->ilc_poly) { |
|
5510 |
__flushPolyCache(pIlc->ilc_poly); |
|
5511 |
pIlc->ilc_poly = 0; |
|
5512 |
} |
|
5513 |
} |
|
5514 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
|
5755 | 5515 |
} else { |
6654 | 5516 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
5517 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
5755 | 5518 |
} |
5519 |
%}. |
|
5520 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5521 |
||
5522 |
! |
|
5523 |
||
5524 |
perform:aSelector with:arg1 with:arg2 |
|
5525 |
"send the two-arg-message aSelector to the receiver" |
|
5526 |
||
5527 |
%{ |
|
5528 |
struct inlineCache *pIlc; |
|
5529 |
||
5530 |
if (InterruptPending == nil) { |
|
6654 | 5531 |
static struct inlineCache ilc_0 = __ILCPERF2(@line); |
5532 |
static struct inlineCache ilc_1 = __ILCPERF2(@line); |
|
5533 |
static OBJ last_0 = nil; |
|
5534 |
static OBJ last_1 = nil; |
|
5535 |
static flip = 0; |
|
5536 |
||
5537 |
if (aSelector == last_0) { |
|
5538 |
pIlc = &ilc_0; |
|
5539 |
} else if (aSelector == last_1) { |
|
5540 |
pIlc = &ilc_1; |
|
5541 |
} else { |
|
5542 |
if (flip == 0) { |
|
5543 |
pIlc = &ilc_0; |
|
5544 |
flip = 1; |
|
5545 |
last_0 = aSelector; |
|
5546 |
} else { |
|
5547 |
pIlc = &ilc_1; |
|
5548 |
flip = 0; |
|
5549 |
last_1 = aSelector; |
|
5550 |
} |
|
5551 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5552 |
if (pIlc->ilc_poly) { |
|
5553 |
__flushPolyCache(pIlc->ilc_poly); |
|
5554 |
pIlc->ilc_poly = 0; |
|
5555 |
} |
|
5556 |
} |
|
5557 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
|
5755 | 5558 |
} else { |
6654 | 5559 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
5560 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, arg1, arg2)); |
|
5755 | 5561 |
} |
5562 |
%}. |
|
5563 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2) |
|
5564 |
||
5565 |
! |
|
5566 |
||
5567 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
|
5568 |
"send the three-arg-message aSelector to the receiver" |
|
5569 |
||
5570 |
%{ |
|
5571 |
struct inlineCache *pIlc; |
|
5572 |
static struct inlineCache ilc_0 = __ILCPERF3(@line); |
|
5573 |
static struct inlineCache ilc_1 = __ILCPERF3(@line); |
|
5574 |
static OBJ last_0 = nil; |
|
5575 |
static OBJ last_1 = nil; |
|
5576 |
static flip = 0; |
|
5577 |
||
5578 |
if (InterruptPending == nil) { |
|
6654 | 5579 |
if (aSelector != last_0) { |
5580 |
if (aSelector != last_1) { |
|
5581 |
if (flip) { |
|
5582 |
pIlc = &ilc_0; |
|
5583 |
flip = 0; |
|
5584 |
last_0 = aSelector; |
|
5585 |
} else { |
|
5586 |
pIlc = &ilc_1; |
|
5587 |
flip = 1; |
|
5588 |
last_1 = aSelector; |
|
5589 |
} |
|
5590 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5591 |
if (pIlc->ilc_poly) { |
|
5592 |
__flushPolyCache(pIlc->ilc_poly); |
|
5593 |
pIlc->ilc_poly = 0; |
|
5594 |
} |
|
5595 |
} else { |
|
5596 |
pIlc = &ilc_1; |
|
5597 |
} |
|
5598 |
} else { |
|
5599 |
pIlc = &ilc_0; |
|
5600 |
} |
|
5601 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
|
5755 | 5602 |
} else { |
6654 | 5603 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
5604 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, arg1, arg2, arg3)); |
|
5755 | 5605 |
} |
5606 |
%}. |
|
5607 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3) |
|
5608 |
||
5609 |
! |
|
5610 |
||
5611 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
5612 |
"send the four-arg-message aSelector to the receiver" |
|
5613 |
||
5614 |
%{ |
|
5615 |
struct inlineCache *pIlc; |
|
5616 |
static struct inlineCache ilc_0 = __ILCPERF4(@line); |
|
5617 |
static struct inlineCache ilc_1 = __ILCPERF4(@line); |
|
5618 |
static OBJ last_0 = nil; |
|
5619 |
static OBJ last_1 = nil; |
|
5620 |
static flip = 0; |
|
5621 |
||
5622 |
if (InterruptPending == nil) { |
|
6654 | 5623 |
if (aSelector != last_0) { |
5624 |
if (aSelector != last_1) { |
|
5625 |
if (flip) { |
|
5626 |
pIlc = &ilc_0; |
|
5627 |
flip = 0; |
|
5628 |
last_0 = aSelector; |
|
5629 |
} else { |
|
5630 |
pIlc = &ilc_1; |
|
5631 |
flip = 1; |
|
5632 |
last_1 = aSelector; |
|
5633 |
} |
|
5634 |
pIlc->ilc_func = __SEND4ADDR__; |
|
5635 |
if (pIlc->ilc_poly) { |
|
5636 |
__flushPolyCache(pIlc->ilc_poly); |
|
5637 |
pIlc->ilc_poly = 0; |
|
5638 |
} |
|
5639 |
} else { |
|
5640 |
pIlc = &ilc_1; |
|
5641 |
} |
|
5642 |
} else { |
|
5643 |
pIlc = &ilc_0; |
|
5644 |
} |
|
5645 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5646 |
arg1, arg2, arg3, arg4) ); |
|
5755 | 5647 |
} else { |
6654 | 5648 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
5649 |
RETURN (_SEND4(self, aSelector, nil, &ilc4, |
|
5650 |
arg1, arg2, arg3, arg4)); |
|
5755 | 5651 |
} |
5652 |
%}. |
|
5653 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
5654 |
||
5655 |
! |
|
5656 |
||
5657 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
5658 |
"send the five-arg-message aSelector to the receiver" |
|
5659 |
||
5660 |
%{ |
|
5661 |
struct inlineCache *pIlc; |
|
5662 |
static struct inlineCache ilc_0 = __ILCPERF5(@line); |
|
5663 |
static struct inlineCache ilc_1 = __ILCPERF5(@line); |
|
5664 |
static OBJ last_0 = nil; |
|
5665 |
static OBJ last_1 = nil; |
|
5666 |
static flip = 0; |
|
5667 |
||
5668 |
if (InterruptPending == nil) { |
|
6654 | 5669 |
if (aSelector != last_0) { |
5670 |
if (aSelector != last_1) { |
|
5671 |
if (flip) { |
|
5672 |
pIlc = &ilc_0; |
|
5673 |
flip = 0; |
|
5674 |
last_0 = aSelector; |
|
5675 |
} else { |
|
5676 |
pIlc = &ilc_1; |
|
5677 |
flip = 1; |
|
5678 |
last_1 = aSelector; |
|
5679 |
} |
|
5680 |
pIlc->ilc_func = __SEND5ADDR__; |
|
5681 |
if (pIlc->ilc_poly) { |
|
5682 |
__flushPolyCache(pIlc->ilc_poly); |
|
5683 |
pIlc->ilc_poly = 0; |
|
5684 |
} |
|
5685 |
} else { |
|
5686 |
pIlc = &ilc_1; |
|
5687 |
} |
|
5688 |
} else { |
|
5689 |
pIlc = &ilc_0; |
|
5690 |
} |
|
5691 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5692 |
arg1, arg2, arg3, arg4, arg5) ); |
|
5755 | 5693 |
} else { |
6654 | 5694 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
5695 |
RETURN (_SEND5(self, aSelector, nil, &ilc5, |
|
5696 |
arg1, arg2, arg3, arg4, arg5)); |
|
5755 | 5697 |
} |
5698 |
%}. |
|
5699 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
6654 | 5700 |
with:arg5) |
5755 | 5701 |
|
5702 |
! |
|
5703 |
||
5704 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
|
5705 |
"send the six-arg-message aSelector to the receiver" |
|
5706 |
||
5707 |
%{ |
|
5708 |
struct inlineCache *pIlc; |
|
5709 |
static struct inlineCache ilc_0 = __ILCPERF6(@line); |
|
5710 |
static struct inlineCache ilc_1 = __ILCPERF6(@line); |
|
5711 |
static OBJ last_0 = nil; |
|
5712 |
static OBJ last_1 = nil; |
|
5713 |
static flip = 0; |
|
5714 |
||
5715 |
if (InterruptPending == nil) { |
|
6654 | 5716 |
if (aSelector != last_0) { |
5717 |
if (aSelector != last_1) { |
|
5718 |
if (flip) { |
|
5719 |
pIlc = &ilc_0; |
|
5720 |
flip = 0; |
|
5721 |
last_0 = aSelector; |
|
5722 |
} else { |
|
5723 |
pIlc = &ilc_1; |
|
5724 |
flip = 1; |
|
5725 |
last_1 = aSelector; |
|
5726 |
} |
|
5727 |
pIlc->ilc_func = __SEND6ADDR__; |
|
5728 |
if (pIlc->ilc_poly) { |
|
5729 |
__flushPolyCache(pIlc->ilc_poly); |
|
5730 |
pIlc->ilc_poly = 0; |
|
5731 |
} |
|
5732 |
} else { |
|
5733 |
pIlc = &ilc_1; |
|
5734 |
} |
|
5735 |
} else { |
|
5736 |
pIlc = &ilc_0; |
|
5737 |
} |
|
5738 |
||
5739 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5740 |
arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
5755 | 5741 |
} else { |
6654 | 5742 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
5743 |
RETURN (_SEND6(self, aSelector, nil, &ilc6, |
|
5744 |
arg1, arg2, arg3, arg4, arg5, arg6)); |
|
5755 | 5745 |
} |
5746 |
%}. |
|
5747 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
6654 | 5748 |
with:arg5 with:arg6) |
5755 | 5749 |
|
5750 |
! |
|
5751 |
||
5752 |
perform:aSelector withArguments:argArray |
|
5753 |
"send the message aSelector with all args taken from argArray |
|
5754 |
to the receiver." |
|
5755 |
||
5756 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
5757 |
||
5758 |
%{ |
|
5759 |
REGISTER OBJ *argP; |
|
5760 |
int nargs; |
|
5761 |
OBJ l; |
|
5762 |
||
5763 |
if (__isArray(argArray)) { |
|
6654 | 5764 |
nargs = __arraySize(argArray); |
5765 |
argP = __arrayVal(argArray); |
|
5755 | 5766 |
} else { |
6654 | 5767 |
if (__isNonNilObject(argArray)) { |
5768 |
static struct inlineCache ilcSize = __ILC0(@line); |
|
5769 |
int i; |
|
5770 |
||
5771 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5772 |
if (!__isSmallInteger(numberOfArgs)) |
|
5773 |
goto bad; |
|
5774 |
nargs = __intVal(numberOfArgs); |
|
5775 |
argP = (OBJ *)(&a1); |
|
5776 |
for (i=1; i <= nargs; i++) { |
|
5777 |
*argP++ = __AT_(argArray, __MKSMALLINT((INT)i)); |
|
5778 |
} |
|
5779 |
argP = (OBJ *)(&a1); |
|
5780 |
} else { |
|
5781 |
nargs = 0; |
|
5782 |
} |
|
5755 | 5783 |
} |
5784 |
switch (nargs) { |
|
6654 | 5785 |
case 0: |
5786 |
if (InterruptPending == nil) { |
|
5787 |
static OBJ last0_0 = nil; static struct inlineCache ilc0_0 = __ILCPERF0(@line); |
|
5788 |
static OBJ last0_1 = nil; static struct inlineCache ilc0_1 = __ILCPERF0(@line); |
|
5789 |
static OBJ last0_2 = nil; static struct inlineCache ilc0_2 = __ILCPERF0(@line); |
|
5790 |
static OBJ last0_3 = nil; static struct inlineCache ilc0_3 = __ILCPERF0(@line); |
|
5791 |
static int flip0 = 0; |
|
5792 |
struct inlineCache *pIlc; |
|
5793 |
||
5794 |
if (aSelector == last0_0) { |
|
5795 |
pIlc = &ilc0_0; |
|
5796 |
} else if (aSelector == last0_1) { |
|
5797 |
pIlc = &ilc0_1; |
|
5798 |
} else if (aSelector == last0_2) { |
|
5799 |
pIlc = &ilc0_2; |
|
5800 |
} else if (aSelector == last0_3) { |
|
5801 |
pIlc = &ilc0_3; |
|
5802 |
} else { |
|
5803 |
if (flip0 == 0) { |
|
5804 |
pIlc = &ilc0_0; |
|
5805 |
flip0 = 1; |
|
5806 |
last0_0 = aSelector; |
|
5807 |
} else if (flip0 == 1) { |
|
5808 |
pIlc = &ilc0_1; |
|
5809 |
flip0 = 2; |
|
5810 |
last0_1 = aSelector; |
|
5811 |
} else if (flip0 == 2) { |
|
5812 |
pIlc = &ilc0_2; |
|
5813 |
flip0 = 3; |
|
5814 |
last0_2 = aSelector; |
|
5815 |
} else { |
|
5816 |
pIlc = &ilc0_3; |
|
5817 |
flip0 = 0; |
|
5818 |
last0_3 = aSelector; |
|
5819 |
} |
|
5820 |
||
5821 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5822 |
if (pIlc->ilc_poly) { |
|
5823 |
__flushPolyCache(pIlc->ilc_poly); |
|
5824 |
pIlc->ilc_poly = 0; |
|
5825 |
} |
|
5826 |
} |
|
5827 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc)); |
|
5828 |
} else { |
|
5829 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5830 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5831 |
} |
|
5832 |
||
5833 |
case 1: |
|
5834 |
if (InterruptPending == nil) { |
|
5835 |
static OBJ last1_0 = nil; static struct inlineCache ilc1_0 = __ILCPERF1(@line); |
|
5836 |
static OBJ last1_1 = nil; static struct inlineCache ilc1_1 = __ILCPERF1(@line); |
|
5837 |
static OBJ last1_2 = nil; static struct inlineCache ilc1_2 = __ILCPERF1(@line); |
|
5838 |
static OBJ last1_3 = nil; static struct inlineCache ilc1_3 = __ILCPERF1(@line); |
|
5839 |
static int flip1 = 0; |
|
5840 |
struct inlineCache *pIlc; |
|
5841 |
||
5842 |
if (aSelector == last1_0) { |
|
5843 |
pIlc = &ilc1_0; |
|
5844 |
} else if (aSelector == last1_1) { |
|
5845 |
pIlc = &ilc1_1; |
|
5846 |
} else if (aSelector == last1_2) { |
|
5847 |
pIlc = &ilc1_2; |
|
5848 |
} else if (aSelector == last1_3) { |
|
5849 |
pIlc = &ilc1_3; |
|
5850 |
} else { |
|
5851 |
if (flip1 == 0) { |
|
5852 |
pIlc = &ilc1_0; |
|
5853 |
flip1 = 1; |
|
5854 |
last1_0 = aSelector; |
|
5855 |
} else if (flip1 == 1) { |
|
5856 |
pIlc = &ilc1_1; |
|
5857 |
flip1 = 2; |
|
5858 |
last1_1 = aSelector; |
|
5859 |
} else if (flip1 == 2) { |
|
5860 |
pIlc = &ilc1_2; |
|
5861 |
flip1 = 3; |
|
5862 |
last1_2 = aSelector; |
|
5863 |
} else { |
|
5864 |
pIlc = &ilc1_3; |
|
5865 |
flip1 = 0; |
|
5866 |
last1_3 = aSelector; |
|
5867 |
} |
|
5868 |
||
5869 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5870 |
if (pIlc->ilc_poly) { |
|
5871 |
__flushPolyCache(pIlc->ilc_poly); |
|
5872 |
pIlc->ilc_poly = 0; |
|
5873 |
} |
|
5874 |
} |
|
5875 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0])); |
|
5876 |
} else { |
|
5877 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5878 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, argP[0])); |
|
5879 |
} |
|
5880 |
||
5881 |
case 2: |
|
5882 |
if (InterruptPending == nil) { |
|
5883 |
static OBJ last2_0 = nil; static struct inlineCache ilc2_0 = __ILCPERF2(@line); |
|
5884 |
static OBJ last2_1 = nil; static struct inlineCache ilc2_1 = __ILCPERF2(@line); |
|
5885 |
static int flip2 = 0; |
|
5886 |
struct inlineCache *pIlc; |
|
5887 |
||
5888 |
if (aSelector == last2_0) { |
|
5889 |
pIlc = &ilc2_0; |
|
5890 |
} else if (aSelector == last2_1) { |
|
5891 |
pIlc = &ilc2_1; |
|
5892 |
} else { |
|
5893 |
if (flip2 == 0) { |
|
5894 |
pIlc = &ilc2_0; |
|
5895 |
flip2 = 1; |
|
5896 |
last2_0 = aSelector; |
|
5897 |
} else { |
|
5898 |
pIlc = &ilc2_1; |
|
5899 |
flip2 = 0; |
|
5900 |
last2_1 = aSelector; |
|
5901 |
} |
|
5902 |
||
5903 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5904 |
if (pIlc->ilc_poly) { |
|
5905 |
__flushPolyCache(pIlc->ilc_poly); |
|
5906 |
pIlc->ilc_poly = 0; |
|
5907 |
} |
|
5908 |
} |
|
5909 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1])); |
|
5910 |
} else { |
|
5911 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5912 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, argP[0], argP[1])); |
|
5913 |
} |
|
5914 |
||
5915 |
case 3: |
|
5916 |
if (InterruptPending == nil) { |
|
5917 |
static OBJ last3_0 = nil; static struct inlineCache ilc3_0 = __ILCPERF3(@line); |
|
5918 |
static OBJ last3_1 = nil; static struct inlineCache ilc3_1 = __ILCPERF3(@line); |
|
5919 |
static int flip3 = 0; |
|
5920 |
struct inlineCache *pIlc; |
|
5921 |
||
5922 |
if (aSelector == last3_0) { |
|
5923 |
pIlc = &ilc3_0; |
|
5924 |
} else if (aSelector == last3_1) { |
|
5925 |
pIlc = &ilc3_1; |
|
5926 |
} else { |
|
5927 |
if (flip3 == 0) { |
|
5928 |
pIlc = &ilc3_0; |
|
5929 |
flip3 = 1; |
|
5930 |
last3_0 = aSelector; |
|
5931 |
} else { |
|
5932 |
pIlc = &ilc3_1; |
|
5933 |
flip3 = 0; |
|
5934 |
last3_1 = aSelector; |
|
5935 |
} |
|
5936 |
||
5937 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5938 |
if (pIlc->ilc_poly) { |
|
5939 |
__flushPolyCache(pIlc->ilc_poly); |
|
5940 |
pIlc->ilc_poly = 0; |
|
5941 |
} |
|
5942 |
} |
|
5943 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1], argP[2])); |
|
5944 |
} else { |
|
5945 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5946 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, argP[0], argP[1], argP[2])); |
|
5947 |
} |
|
5948 |
||
5949 |
case 4: |
|
5950 |
{ |
|
5951 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(@line); |
|
5952 |
||
5953 |
if ((InterruptPending != nil) || (aSelector != last4)) { |
|
5954 |
ilc4.ilc_func = __SEND4ADDR__; |
|
5955 |
if (ilc4.ilc_poly) { |
|
5956 |
__flushPolyCache(ilc4.ilc_poly); |
|
5957 |
ilc4.ilc_poly = 0; |
|
5958 |
} |
|
5959 |
last4 = aSelector; |
|
5960 |
} |
|
5961 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
|
5962 |
argP[0], argP[1], argP[2], argP[3])); |
|
5963 |
} |
|
5964 |
||
5965 |
case 5: |
|
5966 |
{ |
|
5967 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(@line); |
|
5968 |
||
5969 |
if ((InterruptPending != nil) || (aSelector != last5)) { |
|
5970 |
ilc5.ilc_func = __SEND5ADDR__; |
|
5971 |
if (ilc5.ilc_poly) { |
|
5972 |
__flushPolyCache(ilc5.ilc_poly); |
|
5973 |
ilc5.ilc_poly = 0; |
|
5974 |
} |
|
5975 |
last5 = aSelector; |
|
5976 |
} |
|
5977 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
|
5978 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5979 |
} |
|
5980 |
||
5981 |
case 6: |
|
5982 |
{ |
|
5983 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(@line); |
|
5984 |
||
5985 |
if ((InterruptPending != nil) || (aSelector != last6)) { |
|
5986 |
ilc6.ilc_func = __SEND6ADDR__; |
|
5987 |
if (ilc6.ilc_poly) { |
|
5988 |
__flushPolyCache(ilc6.ilc_poly); |
|
5989 |
ilc6.ilc_poly = 0; |
|
5990 |
} |
|
5991 |
last6 = aSelector; |
|
5992 |
} |
|
5993 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
|
5994 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5995 |
argP[5])); |
|
5996 |
} |
|
5997 |
||
5998 |
case 7: |
|
5999 |
{ |
|
6000 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(@line); |
|
6001 |
||
6002 |
if ((InterruptPending != nil) || (aSelector != last7)) { |
|
6003 |
ilc7.ilc_func = __SEND7ADDR__; |
|
6004 |
if (ilc7.ilc_poly) { |
|
6005 |
__flushPolyCache(ilc7.ilc_poly); |
|
6006 |
ilc7.ilc_poly = 0; |
|
6007 |
} |
|
6008 |
last7 = aSelector; |
|
6009 |
} |
|
6010 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
|
6011 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6012 |
argP[5], argP[6])); |
|
6013 |
} |
|
6014 |
||
6015 |
case 8: |
|
6016 |
{ |
|
6017 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(@line); |
|
6018 |
||
6019 |
if ((InterruptPending != nil) || (aSelector != last8)) { |
|
6020 |
ilc8.ilc_func = __SEND8ADDR__; |
|
6021 |
if (ilc8.ilc_poly) { |
|
6022 |
__flushPolyCache(ilc8.ilc_poly); |
|
6023 |
ilc8.ilc_poly = 0; |
|
6024 |
} |
|
6025 |
last8 = aSelector; |
|
6026 |
} |
|
6027 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
|
6028 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6029 |
argP[5], argP[6], argP[7])); |
|
6030 |
} |
|
6031 |
||
6032 |
case 9: |
|
6033 |
{ |
|
6034 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(@line); |
|
6035 |
||
6036 |
if ((InterruptPending != nil) || (aSelector != last9)) { |
|
6037 |
ilc9.ilc_func = __SEND9ADDR__; |
|
6038 |
if (ilc9.ilc_poly) { |
|
6039 |
__flushPolyCache(ilc9.ilc_poly); |
|
6040 |
ilc9.ilc_poly = 0; |
|
6041 |
} |
|
6042 |
last9 = aSelector; |
|
6043 |
} |
|
6044 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
|
6045 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6046 |
argP[5], argP[6], argP[7], argP[8])); |
|
6047 |
} |
|
6048 |
||
6049 |
case 10: |
|
6050 |
{ |
|
6051 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(@line); |
|
6052 |
||
6053 |
if ((InterruptPending != nil) || (aSelector != last10)) { |
|
6054 |
ilc10.ilc_func = __SEND10ADDR__; |
|
6055 |
if (ilc10.ilc_poly) { |
|
6056 |
__flushPolyCache(ilc10.ilc_poly); |
|
6057 |
ilc10.ilc_poly = 0; |
|
6058 |
} |
|
6059 |
last10 = aSelector; |
|
6060 |
} |
|
6061 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
|
6062 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6063 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
6064 |
} |
|
6065 |
||
6066 |
case 11: |
|
6067 |
{ |
|
6068 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(@line); |
|
6069 |
||
6070 |
if ((InterruptPending != nil) || (aSelector != last11)) { |
|
6071 |
ilc11.ilc_func = __SEND11ADDR__; |
|
6072 |
if (ilc11.ilc_poly) { |
|
6073 |
__flushPolyCache(ilc11.ilc_poly); |
|
6074 |
ilc11.ilc_poly = 0; |
|
6075 |
} |
|
6076 |
last11 = aSelector; |
|
6077 |
} |
|
6078 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
|
6079 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6080 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6081 |
argP[10])); |
|
6082 |
} |
|
6083 |
||
6084 |
case 12: |
|
6085 |
{ |
|
6086 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(@line); |
|
6087 |
||
6088 |
if ((InterruptPending != nil) || (aSelector != last12)) { |
|
6089 |
ilc12.ilc_func = __SEND12ADDR__; |
|
6090 |
if (ilc12.ilc_poly) { |
|
6091 |
__flushPolyCache(ilc12.ilc_poly); |
|
6092 |
ilc12.ilc_poly = 0; |
|
6093 |
} |
|
6094 |
last12 = aSelector; |
|
6095 |
} |
|
6096 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
|
6097 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6098 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6099 |
argP[10], argP[11])); |
|
6100 |
} |
|
6101 |
||
6102 |
case 13: |
|
6103 |
{ |
|
6104 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(@line); |
|
6105 |
||
6106 |
if ((InterruptPending != nil) || (aSelector != last13)) { |
|
6107 |
ilc13.ilc_func = __SEND13ADDR__; |
|
6108 |
if (ilc13.ilc_poly) { |
|
6109 |
__flushPolyCache(ilc13.ilc_poly); |
|
6110 |
ilc13.ilc_poly = 0; |
|
6111 |
} |
|
6112 |
last13 = aSelector; |
|
6113 |
} |
|
6114 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
|
6115 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6116 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6117 |
argP[10], argP[11], argP[12])); |
|
6118 |
} |
|
6119 |
||
6120 |
case 14: |
|
6121 |
{ |
|
6122 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(@line); |
|
6123 |
||
6124 |
if ((InterruptPending != nil) || (aSelector != last14)) { |
|
6125 |
ilc14.ilc_func = __SEND14ADDR__; |
|
6126 |
if (ilc14.ilc_poly) { |
|
6127 |
__flushPolyCache(ilc14.ilc_poly); |
|
6128 |
ilc14.ilc_poly = 0; |
|
6129 |
} |
|
6130 |
last14 = aSelector; |
|
6131 |
} |
|
6132 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
|
6133 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6134 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6135 |
argP[10], argP[11], argP[12], argP[13])); |
|
6136 |
} |
|
6137 |
||
6138 |
case 15: |
|
6139 |
{ |
|
6140 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(@line); |
|
6141 |
||
6142 |
if ((InterruptPending != nil) || (aSelector != last15)) { |
|
6143 |
ilc15.ilc_func = __SEND15ADDR__; |
|
6144 |
if (ilc15.ilc_poly) { |
|
6145 |
__flushPolyCache(ilc15.ilc_poly); |
|
6146 |
ilc15.ilc_poly = 0; |
|
6147 |
} |
|
6148 |
last15 = aSelector; |
|
6149 |
} |
|
6150 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
|
6151 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6152 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6153 |
argP[10], argP[11], argP[12], argP[13], |
|
6154 |
argP[14])); |
|
6155 |
} |
|
5755 | 6156 |
} |
6157 |
bad:; |
|
6158 |
%}. |
|
6159 |
||
6160 |
"/ arrive here, if bad number of arguments (too many) |
|
6161 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
6162 |
||
6163 |
^ self primitiveFailed |
|
6164 |
! |
|
6165 |
||
6316 | 6166 |
perform:aSelector withOptionalArgument:arg |
6167 |
"send aSelector-message to the receiver. |
|
6318 | 6168 |
If the message expects an argument, pass arg." |
6316 | 6169 |
|
6170 |
aSelector numArgs == 1 ifTrue:[ |
|
6654 | 6171 |
^ self perform:aSelector with:arg |
6316 | 6172 |
]. |
6173 |
^ self perform:aSelector |
|
6319 | 6174 |
|
6175 |
" |
|
6176 |
|rec sel| |
|
6177 |
||
6178 |
rec := -1. |
|
6179 |
sel := #abs. |
|
6180 |
rec perform:sel withOptionalArgument:2. |
|
6181 |
||
6182 |
sel := #max:. |
|
6183 |
rec perform:sel withOptionalArgument:2. |
|
6184 |
" |
|
6316 | 6185 |
! |
6186 |
||
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6187 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6188 |
"send aSelector-message to the receiver. |
6728 | 6189 |
Depending on the number of arguments the message expects, |
6190 |
pass either none, 1, or 2 arguments." |
|
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6191 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6192 |
|numArgs| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6193 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6194 |
numArgs := aSelector numArgs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6195 |
numArgs == 0 ifTrue:[ |
6654 | 6196 |
^ self perform:aSelector |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6197 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6198 |
numArgs == 1 ifTrue:[ |
6654 | 6199 |
^ self perform:aSelector with:optionalArg1 |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6200 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6201 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6202 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6203 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6204 |
|rec sel| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6205 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6206 |
rec := -1. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6207 |
sel := #abs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6208 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6209 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6210 |
sel := #max:. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6211 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6212 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6213 |
! |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6214 |
|
6728 | 6215 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 |
6216 |
"send aSelector-message to the receiver. |
|
6217 |
Depending on the number of arguments the message expects, |
|
6218 |
pass either none, 1, 2 or 3 arguments." |
|
6219 |
||
6220 |
|numArgs| |
|
6221 |
||
6222 |
numArgs := aSelector numArgs. |
|
6223 |
numArgs == 0 ifTrue:[ |
|
6224 |
^ self perform:aSelector |
|
6225 |
]. |
|
6226 |
numArgs == 1 ifTrue:[ |
|
6227 |
^ self perform:aSelector with:optionalArg1 |
|
6228 |
]. |
|
6229 |
numArgs == 2 ifTrue:[ |
|
6230 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
|
6231 |
]. |
|
6232 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3. |
|
6233 |
||
6234 |
" |
|
6235 |
|rec sel| |
|
6236 |
||
6237 |
rec := -1. |
|
6238 |
sel := #abs. |
|
6239 |
rec perform:sel withOptionalArgument:2. |
|
6240 |
||
6241 |
sel := #max:. |
|
6242 |
rec perform:sel withOptionalArgument:2. |
|
6243 |
" |
|
6244 |
! |
|
6245 |
||
6764 | 6246 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 and:optionalArg4 |
6247 |
"send aSelector-message to the receiver. |
|
6248 |
Depending on the number of arguments the message expects, |
|
6249 |
pass either none, 1, 2, 3 or 4 arguments." |
|
6250 |
||
6251 |
|numArgs| |
|
6252 |
||
6253 |
numArgs := aSelector numArgs. |
|
6254 |
numArgs == 0 ifTrue:[ |
|
6255 |
^ self perform:aSelector |
|
6256 |
]. |
|
6257 |
numArgs == 1 ifTrue:[ |
|
6258 |
^ self perform:aSelector with:optionalArg1 |
|
6259 |
]. |
|
6260 |
numArgs == 2 ifTrue:[ |
|
6261 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
|
6262 |
]. |
|
6263 |
numArgs == 3 ifTrue:[ |
|
6264 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 |
|
6265 |
]. |
|
6266 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 with:optionalArg4. |
|
6267 |
||
6268 |
" |
|
6269 |
|rec sel| |
|
6270 |
||
6271 |
rec := -1. |
|
6272 |
sel := #abs. |
|
6273 |
rec perform:sel withOptionalArgument:2. |
|
6274 |
||
6275 |
sel := #max:. |
|
6276 |
rec perform:sel withOptionalArgument:2. |
|
6277 |
" |
|
6278 |
! |
|
6279 |
||
5755 | 6280 |
performMethod:aMethod |
6281 |
"invoke aMethod on the receiver. |
|
6282 |
The method should be a zero-argument method. |
|
6283 |
This is a non-object-oriented entry, applying a method |
|
6284 |
in a functional way on a receiver. |
|
6285 |
Warning: |
|
6654 | 6286 |
Take care for the method to be appropriate for the |
6287 |
receiver - no checking is done by the VM." |
|
5755 | 6288 |
|
6289 |
^ aMethod valueWithReceiver:self arguments:#() |
|
6290 |
||
6291 |
" |
|
6292 |
|mthd| |
|
6293 |
||
6294 |
mthd := SmallInteger compiledMethodAt:#negated. |
|
6295 |
Transcript showCR:(1 performMethod:mthd) |
|
6296 |
" |
|
6297 |
||
6298 |
"BAD USE example: |
|
6299 |
||
6300 |
|mthd| |
|
6301 |
||
6302 |
mthd := Point compiledMethodAt:#x. |
|
6303 |
Transcript showCR:((1->2) performMethod:mthd) |
|
6304 |
" |
|
6305 |
||
6306 |
"Modified: 31.7.1997 / 17:41:50 / cg" |
|
6307 |
! |
|
6308 |
||
6309 |
performMethod:aMethod arguments:argumentArray |
|
6310 |
"invoke aMethod on the receiver, passing an argumentArray. |
|
6311 |
The size of the argumentArray should match the number of args |
|
6312 |
expected by the method. |
|
6313 |
This is a non-object-oriented entry, applying a method |
|
6314 |
in a functional way on a receiver. |
|
6315 |
Warning: |
|
6654 | 6316 |
Take care for the method to be appropriate for the |
6317 |
receiver - no checking is done by the VM." |
|
5755 | 6318 |
|
6319 |
^ aMethod valueWithReceiver:self arguments:argumentArray |
|
6320 |
||
6321 |
" |
|
6322 |
|mthd| |
|
6323 |
||
6324 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6325 |
Transcript showCR:(1 performMethod:mthd arguments:#(2)) |
|
6326 |
" |
|
6327 |
||
6328 |
"Created: 31.7.1997 / 17:46:31 / cg" |
|
6329 |
! |
|
6330 |
||
6331 |
performMethod:aMethod with:arg |
|
6332 |
"invoke aMethod on the receiver, passing an argument. |
|
6333 |
The method should be a one-argument method. |
|
6334 |
This is a non-object-oriented entry, applying a method |
|
6335 |
in a functional way on a receiver. |
|
6336 |
Warning: |
|
6654 | 6337 |
Take care for the method to be appropriate for the |
6338 |
receiver - no checking is done by the VM." |
|
5755 | 6339 |
|
6340 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg) |
|
6341 |
||
6342 |
" |
|
6343 |
|mthd| |
|
6344 |
||
6345 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6346 |
Transcript showCR:(1 performMethod:mthd with:2) |
|
6347 |
" |
|
6348 |
||
6349 |
"Modified: 31.7.1997 / 17:42:32 / cg" |
|
6350 |
! |
|
6351 |
||
6352 |
performMethod:aMethod with:arg1 with:arg2 |
|
6353 |
"invoke aMethod on the receiver, passing two arguments. |
|
6354 |
The method should be a two-argument method. |
|
6355 |
This is a non-object-oriented entry, applying a method |
|
6356 |
in a functional way on a receiver. |
|
6357 |
Warning: |
|
6654 | 6358 |
Take care for the method to be appropriate for the |
6359 |
receiver - no checking is done by the VM." |
|
5755 | 6360 |
|
6361 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) |
|
6362 |
||
6363 |
" |
|
6364 |
|mthd arr| |
|
6365 |
||
6366 |
arr := Array new:1. |
|
6367 |
mthd := Array compiledMethodAt:#basicAt:put:. |
|
6368 |
arr performMethod:mthd with:1 with:'foo'. |
|
6369 |
Transcript showCR:arr |
|
6370 |
" |
|
6371 |
||
6372 |
"Modified: 31.7.1997 / 17:44:54 / cg" |
|
6373 |
! |
|
6374 |
||
6375 |
performMethod:aMethod with:arg1 with:arg2 with:arg3 |
|
6376 |
"invoke aMethod on the receiver, passing three arguments. |
|
6377 |
The method should be a three-argument method. |
|
6378 |
This is a non-object-oriented entry, applying a method |
|
6379 |
in a functional way on a receiver. |
|
6380 |
Warning: |
|
6654 | 6381 |
Take care for the method to be appropriate for the |
6382 |
receiver - no checking is done by the VM." |
|
5755 | 6383 |
|
6384 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3) |
|
6385 |
||
6386 |
"Created: 31.7.1997 / 17:45:20 / cg" |
|
6387 |
! ! |
|
6388 |
||
6389 |
!Object methodsFor:'printing & storing'! |
|
6390 |
||
6235 | 6391 |
basicPrintOn:aStream |
6392 |
"append the receivers className with an articel to the argument, aStream" |
|
6393 |
||
6394 |
aStream nextPutAll:self classNameWithArticle |
|
6395 |
! |
|
6396 |
||
5755 | 6397 |
className |
6398 |
"return the classname of the receivers class" |
|
6399 |
||
6400 |
^ self class name |
|
6401 |
||
6402 |
" |
|
6403 |
1 className |
|
6404 |
1 class className 'this may change ...' |
|
6405 |
$a className |
|
6406 |
$a class className 'this may change ...' |
|
6407 |
" |
|
6408 |
! |
|
6409 |
||
6410 |
classNameWithArticle |
|
6411 |
"return a string consisting of classname preceeded by an article. |
|
6412 |
(dont expect me to write national variants for this ... :-) |
|
6413 |
If you have special preferences, redefine it ..." |
|
6414 |
||
6829 | 6415 |
| cls| |
5755 | 6416 |
|
6417 |
(cls := self class) == self ifTrue:[ |
|
6654 | 6418 |
^ 'a funny object' |
5755 | 6419 |
]. |
6829 | 6420 |
^ cls nameWithArticle |
5755 | 6421 |
|
6422 |
" |
|
6418 | 6423 |
1 classNameWithArticle |
6424 |
(1->2) classNameWithArticle |
|
5755 | 6425 |
XWorkstation basicNew classNameWithArticle |
6418 | 6426 |
XWorkstation classNameWithArticle |
5755 | 6427 |
" |
6428 |
||
6429 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
6430 |
! |
|
6431 |
||
6432 |
errorPrint |
|
6433 |
"print the receiver on the standard error stream." |
|
6434 |
||
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
6435 |
StreamError catch:[ |
6654 | 6436 |
self printOn:Stderr |
5755 | 6437 |
] |
6438 |
||
6439 |
"Modified: 7.3.1996 / 19:11:29 / cg" |
|
6440 |
! |
|
6441 |
||
6442 |
errorPrintCR |
|
6443 |
"{ Pragma: +optSpace }" |
|
6444 |
||
6445 |
"print the receiver followed by a cr on the standard error stream." |
|
6446 |
||
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
6447 |
StreamError catch:[ |
6654 | 6448 |
self printOn:Stderr. |
6449 |
Stderr cr |
|
5755 | 6450 |
] |
6451 |
||
6452 |
"Modified: 7.3.1996 / 19:13:01 / cg" |
|
6453 |
"Created: 20.5.1996 / 10:20:41 / cg" |
|
6454 |
! |
|
6455 |
||
6456 |
errorPrintNL |
|
6457 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6458 |
<resource:#obsolete> |
5755 | 6459 |
|
6460 |
"print the receiver followed by a cr on the standard error stream. |
|
6461 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6462 |
||
6463 |
^ self errorPrintCR |
|
6464 |
||
6465 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
6466 |
! |
|
6467 |
||
6468 |
errorPrintNewline |
|
6469 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6470 |
<resource:#obsolete> |
5755 | 6471 |
|
6472 |
"print the receiver followed by a cr on the standard error stream. |
|
6473 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6474 |
||
6475 |
self errorPrintCR. |
|
6476 |
||
6477 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
6478 |
! |
|
6479 |
||
6480 |
infoPrint |
|
6481 |
"{ Pragma: +optSpace }" |
|
6482 |
||
6483 |
"print the receiver on the standard error stream. |
|
6484 |
This is meant for information messages which are not warnings |
|
6485 |
or fatal messages. |
|
6486 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6487 |
||
6488 |
InfoPrinting == true ifTrue:[ |
|
6654 | 6489 |
self errorPrint |
5755 | 6490 |
] |
6491 |
! |
|
6492 |
||
6493 |
infoPrintCR |
|
6494 |
"{ Pragma: +optSpace }" |
|
6495 |
||
6496 |
"print the receiver followed by a cr on the standard error stream. |
|
6497 |
This is meant for information messages which are not warnings |
|
6498 |
or fatal messages. |
|
6499 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6500 |
||
6501 |
InfoPrinting == true ifTrue:[ |
|
6654 | 6502 |
self errorPrintCR |
5755 | 6503 |
] |
6504 |
||
6505 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
6506 |
! |
|
6507 |
||
6508 |
infoPrintNL |
|
6509 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6510 |
<resource:#obsolete> |
5755 | 6511 |
|
6512 |
"print the receiver followed by a cr on the standard error stream. |
|
6513 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
6514 |
||
6515 |
^ self infoPrintCR |
|
6516 |
! |
|
6517 |
||
6518 |
||
6519 |
"print the receiver on the standard output stream (which is not the Transcript)" |
|
6520 |
||
6521 |
"/ the following allows printCR to be used during |
|
6522 |
"/ the early init-phase, when no Stdout has been set up. |
|
6523 |
"/ (depends on string to respond to #print) |
|
6524 |
||
6525 |
Stdout isNil ifTrue:[ |
|
6654 | 6526 |
self printString print. |
6527 |
^ self |
|
5755 | 6528 |
]. |
6529 |
self printOn:Stdout |
|
6530 |
||
6531 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
6532 |
! |
|
6533 |
||
6534 |
printCR |
|
6535 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
|
6536 |
||
6537 |
"/ the following allows printCR to be used during |
|
6538 |
"/ the early init-phase, when no Stdout has been set up. |
|
6539 |
"/ (depends on string to respond to #printCR) |
|
6540 |
||
6541 |
Stdout isNil ifTrue:[ |
|
6654 | 6542 |
self printString printCR. |
6543 |
^ self |
|
5755 | 6544 |
]. |
6545 |
self printOn:Stdout. |
|
6546 |
Stdout cr |
|
6547 |
||
6548 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
6549 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
|
6550 |
! |
|
6551 |
||
6552 |
printNL |
|
6553 |
"print the receiver followed by a cr on the standard output stream |
|
6554 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
6555 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6556 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6557 |
|
5755 | 6558 |
^ self printCR |
6559 |
||
6560 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
6561 |
! |
|
6562 |
||
6563 |
printNewline |
|
6564 |
"print the receiver followed by a cr on the standard output stream. |
|
6565 |
This exists for backward compatibility - please use #printCR." |
|
6566 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6567 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6568 |
|
5755 | 6569 |
self printCR |
6570 |
||
6571 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
6572 |
! |
|
6573 |
||
6574 |
printOn:aStream |
|
6575 |
"append a user printed representation of the receiver to aStream. |
|
6576 |
The format is suitable for a human - not meant to be read back. |
|
6577 |
||
6578 |
The default here is to output the receivers class name. |
|
6579 |
BUT: this method is heavily redefined for objects which |
|
6580 |
can print prettier." |
|
6581 |
||
6235 | 6582 |
self basicPrintOn:aStream. |
6583 |
||
6584 |
" |
|
6585 |
(1@2) printOn:Transcript |
|
6586 |
(1@2) basicPrintOn:Transcript |
|
6587 |
" |
|
5755 | 6588 |
! |
6589 |
||
6590 |
printOn:aStream leftPaddedTo:size |
|
6591 |
"print the receiver on aStream, padding with spaces up to size. |
|
6592 |
padding is done on the left." |
|
6593 |
||
6594 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
6595 |
||
6596 |
" |
|
6597 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
6598 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
6599 |
" |
|
6600 |
! |
|
6601 |
||
6602 |
printOn:aStream leftPaddedTo:size with:padCharacter |
|
6603 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
6604 |
padding is done on the left." |
|
6605 |
||
6606 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
6607 |
||
6608 |
" |
|
6609 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
6610 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
6611 |
" |
|
6612 |
! |
|
6613 |
||
6614 |
printOn:aStream paddedTo:size |
|
6615 |
"print the receiver on aStream, padding with spaces up to size." |
|
6616 |
||
6617 |
self printOn:aStream paddedTo:size with:(Character space) |
|
6618 |
||
6619 |
" |
|
6620 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
6621 |
" |
|
6622 |
! |
|
6623 |
||
6624 |
printOn:aStream paddedTo:size with:padCharacter |
|
6625 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
6626 |
||
6627 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
6628 |
||
6629 |
" |
|
6630 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
6631 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
6632 |
" |
|
6633 |
! |
|
6634 |
||
6635 |
printOn:aStream zeroPaddedTo:size |
|
6636 |
"print the receiver on aStream, padding with zeros up to size. |
|
6637 |
Usually used with float numbers." |
|
6638 |
||
6639 |
self printOn:aStream paddedTo:size with:$0. |
|
6640 |
||
6641 |
" |
|
6642 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
6643 |
" |
|
6644 |
! |
|
6645 |
||
6646 |
printRightAdjustLen:size |
|
6647 |
"obsolete - just a name confusion. |
|
6648 |
This method will go away ..." |
|
6649 |
||
6650 |
(self printStringLeftPaddedTo:size) printOn:Stdout |
|
6651 |
! |
|
6652 |
||
6653 |
printString |
|
6654 |
"return a string for printing the receiver. |
|
6655 |
Since we now use printOn: as the basic print mechanism, |
|
6656 |
we have to create a stream and print into it." |
|
6657 |
||
6658 |
|s| |
|
6659 |
||
6660 |
s := WriteStream on:(String new:30). |
|
6661 |
self printOn:s. |
|
6662 |
^ s contents |
|
6663 |
! |
|
6664 |
||
6665 |
printStringLeftPaddedTo:size |
|
6666 |
"return my printString as a right-adjusted string of length size; |
|
6667 |
characters on the left are filled with spaces. |
|
6668 |
If the printString is longer than size, |
|
6669 |
it is returned unchanged (i.e. not truncated)" |
|
6670 |
||
6671 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
6672 |
||
6673 |
" |
|
6674 |
10 printStringLeftPaddedTo:10 |
|
6675 |
1 printStringLeftPaddedTo:10 |
|
6676 |
" |
|
6677 |
! |
|
6678 |
||
6679 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
6680 |
"return my printString as a right-adjusted string of length size; |
|
6681 |
characters on the left are filled with spaces. |
|
6682 |
If the printString is larger than size, |
|
6683 |
return the result from evaluating alternative." |
|
6684 |
||
6685 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
6686 |
||
6687 |
" |
|
6688 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6689 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6690 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6691 |
" |
|
6692 |
! |
|
6693 |
||
6694 |
printStringLeftPaddedTo:size with:padCharacter |
|
6695 |
"return my printString as a right-adjusted string of length size; |
|
6696 |
characters on the left are filled with padCharacter. |
|
6697 |
If the printString is longer than size, |
|
6698 |
it is returned unchanged (i.e. not truncated)" |
|
6699 |
||
6700 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
6701 |
||
6702 |
" |
|
6703 |
123 printStringLeftPaddedTo:10 with:$. |
|
6704 |
1 printStringLeftPaddedTo:10 with:$. |
|
6705 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
|
6706 |
" |
|
6707 |
! |
|
6708 |
||
6709 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
6710 |
"return my printString as a right-adjusted string of length size; |
|
6711 |
characters on the left are filled with padCharacter. |
|
6712 |
If the printString is larger than size, |
|
6713 |
return the result from evaluating alternative." |
|
6714 |
||
6715 |
|s| |
|
6716 |
||
6717 |
s := self printString. |
|
6718 |
s size > size ifTrue:[^ alternative value]. |
|
6719 |
^ s leftPaddedTo:size with:padCharacter |
|
6720 |
||
6721 |
" |
|
6722 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6723 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6724 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6725 |
" |
|
6726 |
! |
|
6727 |
||
6728 |
printStringOnError:exceptionBlock |
|
6729 |
"return a string for printing the receiver; if any error occurs, return the result from |
|
6730 |
evaluating exceptionBlock. Useful to print something in an exceptionHandler or other |
|
6731 |
cleanup code." |
|
6732 |
||
6733 |
|rslt| |
|
6734 |
||
6735 |
Error handle:[:ex | |
|
6654 | 6736 |
rslt := exceptionBlock value |
5755 | 6737 |
] do:[ |
6654 | 6738 |
rslt := self printString |
5755 | 6739 |
]. |
6740 |
^ rslt |
|
6741 |
! |
|
6742 |
||
6743 |
printStringPaddedTo:size |
|
6744 |
"return a printed representation of the receiver, |
|
6745 |
padded with spaces (at the right) up to size. |
|
6746 |
If the printString is longer than size, |
|
6747 |
it is returned unchanged (i.e. not truncated)" |
|
6748 |
||
6749 |
^ self printStringPaddedTo:size with:(Character space) |
|
6750 |
||
6751 |
" |
|
6752 |
123 printStringPaddedTo:10 |
|
6753 |
1234567890123456 printStringPaddedTo:10 |
|
6754 |
'hello' printStringPaddedTo:10 |
|
6755 |
" |
|
6756 |
! |
|
6757 |
||
6758 |
printStringPaddedTo:size ifLarger:alternative |
|
6759 |
"return a printed representation of the receiver, |
|
6760 |
padded with spaces (at the right) up to size. |
|
6761 |
If the resulting printString is too large, |
|
6762 |
return the result from evaluating alternative." |
|
6763 |
||
6764 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
6765 |
||
6766 |
" |
|
6767 |
12 printStringPaddedTo:3 ifLarger:['***'] |
|
6768 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
6769 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
6770 |
" |
|
6771 |
! |
|
6772 |
||
6773 |
printStringPaddedTo:size with:padCharacter |
|
6774 |
"return a printed representation of the receiver, |
|
6775 |
padded with padCharacter (at the right) up to size. |
|
6776 |
If the printString is longer than size, |
|
6777 |
it is returned unchanged (i.e. not truncated)" |
|
6778 |
||
6779 |
^ (self printString) paddedTo:size with:padCharacter |
|
6780 |
||
6781 |
" |
|
6782 |
123 printStringPaddedTo:10 with:$. |
|
6783 |
123 printStringPaddedTo:10 with:$* |
|
6784 |
123 printStringPaddedTo:3 with:$* |
|
6785 |
1234 printStringPaddedTo:3 with:$* |
|
6786 |
" |
|
6787 |
! |
|
6788 |
||
6789 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
6790 |
"return a printed representation of the receiver, |
|
6791 |
padded with padCharacter (at the right) up to size. |
|
6792 |
If the resulting printString is too large, |
|
6793 |
return the result from evaluating alternative." |
|
6794 |
||
6795 |
|s| |
|
6796 |
||
6797 |
s := self printString. |
|
6798 |
s size > size ifTrue:[^ alternative value]. |
|
6799 |
^ s paddedTo:size with:padCharacter |
|
6800 |
||
6801 |
" |
|
6802 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6803 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6804 |
" |
|
6805 |
! |
|
6806 |
||
6807 |
printStringRightAdjustLen:size |
|
6808 |
"obsolete - just a name confusion. |
|
6809 |
This method will go away ..." |
|
6810 |
||
6811 |
^ self printStringLeftPaddedTo:size |
|
6812 |
! |
|
6813 |
||
6814 |
printStringZeroPaddedTo:size |
|
6815 |
"return a printed representation of the receiver, |
|
6816 |
padded with zero (at the right) characters up to size. |
|
6817 |
Usually used with float numbers." |
|
6818 |
||
6819 |
^ self printStringPaddedTo:size with:$0 |
|
6820 |
||
6821 |
" |
|
6822 |
123.0 printStringZeroPaddedTo:10 |
|
6823 |
" |
|
6824 |
! |
|
6825 |
||
6826 |
store |
|
6827 |
"store the receiver on standard output. |
|
6828 |
this method is useless, but included for compatibility." |
|
6829 |
||
6830 |
self storeOn:Stdout |
|
6831 |
! |
|
6832 |
||
6833 |
storeCR |
|
6834 |
"store the receiver on standard output; append a carriage return." |
|
6835 |
||
6836 |
self store. |
|
6837 |
Character cr print |
|
6838 |
||
6839 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
6840 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
6841 |
! |
|
6842 |
||
6843 |
storeNl |
|
6844 |
"store the receiver on standard output; append a newline. |
|
6845 |
This method is included for backward compatibility- use #storeCR." |
|
6846 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6847 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6848 |
|
5755 | 6849 |
self storeCR. |
6850 |
||
6851 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
6852 |
! |
|
6853 |
||
6854 |
storeOn:aStream |
|
6855 |
"store the receiver on aStream; i.e. print an expression which will |
|
6856 |
reconstruct the receiver. |
|
6857 |
Notice, that no self referencing or cyclic objects can be represented |
|
6858 |
in this format. |
|
6859 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6860 |
||
6861 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
6862 |
||
6863 |
thisContext isRecursive ifTrue:[ |
|
6654 | 6864 |
Object recursiveStoreStringSignal raiseRequestWith:self. |
6865 |
('Object [error]: storeString of self referencing object.') errorPrintCR. |
|
6866 |
aStream nextPutAll:'#("recursive")'. |
|
6867 |
^ self |
|
5755 | 6868 |
]. |
6869 |
||
6870 |
myClass := self class. |
|
6871 |
aStream nextPut:$(. |
|
6872 |
aStream nextPutAll:self class name. |
|
6873 |
||
6874 |
hasSemi := false. |
|
6875 |
myClass isVariable ifTrue:[ |
|
6654 | 6876 |
aStream nextPutAll:' basicNew:'. |
6877 |
self basicSize printOn:aStream |
|
5755 | 6878 |
] ifFalse:[ |
6654 | 6879 |
aStream nextPutAll:' basicNew' |
5755 | 6880 |
]. |
6881 |
||
6882 |
sz := myClass instSize. |
|
6883 |
1 to:sz do:[:i | |
|
6654 | 6884 |
aStream nextPutAll:' instVarAt:'. |
6885 |
i printOn:aStream. |
|
6886 |
aStream nextPutAll:' put:'. |
|
6887 |
(self instVarAt:i) storeOn:aStream. |
|
6888 |
aStream nextPut:$;. |
|
6889 |
hasSemi := true |
|
5755 | 6890 |
]. |
6891 |
myClass isVariable ifTrue:[ |
|
6654 | 6892 |
sz := self basicSize. |
6893 |
1 to:sz do:[:i | |
|
6894 |
aStream nextPutAll:' basicAt:'. |
|
6895 |
i printOn:aStream. |
|
6896 |
aStream nextPutAll:' put:'. |
|
6897 |
(self basicAt:i) storeOn:aStream. |
|
6898 |
aStream nextPut:$;. |
|
6899 |
hasSemi := true |
|
6900 |
] |
|
5755 | 6901 |
]. |
6902 |
hasSemi ifTrue:[ |
|
6654 | 6903 |
aStream nextPutAll:' yourself' |
5755 | 6904 |
]. |
6905 |
aStream nextPut:$). |
|
6906 |
||
6907 |
" |
|
6908 |
|s| |
|
6909 |
||
6910 |
s := WriteStream on:(String new). |
|
6911 |
('hello' -> 'world') storeOn:s. |
|
6912 |
s := ReadStream on:(s contents). |
|
6913 |
(Object readFrom:s) inspect |
|
6914 |
" |
|
6915 |
" |
|
6916 |
|s| |
|
6917 |
||
6918 |
s := 'data' asFilename writeStream. |
|
6919 |
('hello' -> 'world') storeOn:s. |
|
6920 |
s close. |
|
6921 |
||
6922 |
s := 'data' asFilename readStream. |
|
6923 |
(Object readFrom:s) inspect |
|
6924 |
" |
|
6925 |
||
6926 |
"does not work example:" |
|
6927 |
" |
|
6928 |
|s a| |
|
6929 |
||
6930 |
a := Array new:2. |
|
6931 |
a at:1 put:a. |
|
6932 |
||
6933 |
s := 'data' asFilename writeStream. |
|
6934 |
a storeOn:s. |
|
6935 |
s close. |
|
6936 |
||
6937 |
s := 'data' asFilename readStream. |
|
6938 |
(Object readFrom:s) inspect |
|
6939 |
" |
|
6940 |
||
6941 |
"Modified: 28.1.1997 / 00:36:12 / cg" |
|
6942 |
! |
|
6943 |
||
6944 |
storeString |
|
6945 |
"return a string representing an expression to reconstruct the receiver. |
|
6946 |
Notice, that no self referencing or cyclic objects can be represented |
|
6947 |
in this format. |
|
6948 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6949 |
||
6950 |
|s| |
|
6951 |
||
6952 |
s := WriteStream on:(String new:50). |
|
6953 |
self storeOn:s. |
|
6954 |
^ s contents |
|
6955 |
! ! |
|
6956 |
||
6957 |
!Object methodsFor:'private'! |
|
6958 |
||
6959 |
isHierarchicalItem |
|
6960 |
"used to decide if the parent is a hierarchical item |
|
6961 |
or the model |
|
6962 |
" |
|
6963 |
^ false |
|
6964 |
! ! |
|
6965 |
||
6966 |
!Object methodsFor:'queries'! |
|
6967 |
||
6968 |
basicSize |
|
6969 |
"return the number of the receivers indexed instance variables, |
|
6970 |
0 if it has none. |
|
6971 |
||
6972 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
6973 |
||
6974 |
%{ /* NOCONTEXT */ |
|
6975 |
||
6976 |
REGISTER int nbytes; |
|
6977 |
REGISTER OBJ myClass; |
|
6978 |
int nInstBytes; |
|
6979 |
||
6980 |
/* |
|
6981 |
* notice the missing test for self being a nonNilObject - |
|
6982 |
* this can be done since basicSize is defined both in UndefinedObject |
|
6983 |
* and SmallInteger |
|
6984 |
*/ |
|
6985 |
myClass = __qClass(self); |
|
6986 |
nbytes = __qSize(self); |
|
6987 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) ); |
|
6988 |
||
6989 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
6654 | 6990 |
case __MASKSMALLINT(POINTERARRAY): |
6991 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
6992 |
nbytes -= nInstBytes; |
|
6993 |
RETURN ( __MKSMALLINT(__BYTES2OBJS__(nbytes)) ); |
|
6994 |
||
6995 |
case __MASKSMALLINT(BYTEARRAY): |
|
6996 |
nbytes -= nInstBytes; |
|
6997 |
RETURN ( __MKSMALLINT(nbytes / sizeof(char)) ); |
|
6998 |
||
6999 |
case __MASKSMALLINT(FLOATARRAY): |
|
7000 |
nbytes -= nInstBytes; |
|
7001 |
RETURN ( __MKSMALLINT(nbytes / sizeof(float)) ); |
|
7002 |
||
7003 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 7004 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 7005 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
5755 | 7006 |
#endif |
6654 | 7007 |
nbytes -= nInstBytes; |
7008 |
RETURN ( __MKSMALLINT(nbytes / sizeof(double)) ); |
|
7009 |
||
7010 |
case __MASKSMALLINT(WORDARRAY): |
|
7011 |
case __MASKSMALLINT(SWORDARRAY): |
|
7012 |
nbytes -= nInstBytes; |
|
7013 |
RETURN ( __MKSMALLINT(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */ |
|
7014 |
||
7015 |
case __MASKSMALLINT(LONGARRAY): |
|
7016 |
case __MASKSMALLINT(SLONGARRAY): |
|
7017 |
nbytes -= nInstBytes; |
|
7018 |
RETURN ( __MKSMALLINT(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */ |
|
7019 |
||
7020 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
7021 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 7022 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 7023 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
5755 | 7024 |
#endif |
6654 | 7025 |
nbytes -= nInstBytes; |
7026 |
RETURN ( __MKSMALLINT(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */ |
|
5755 | 7027 |
} |
7028 |
%}. |
|
7029 |
^ 0 |
|
7030 |
! |
|
7031 |
||
7032 |
byteSize |
|
7033 |
"return the number of bytes in the receivers indexed instance variables, |
|
7034 |
0 if it has none. This only returns non-zero for non-pointer indexed |
|
7035 |
instvars i.e. byteArrays, wordArrays etc. |
|
7036 |
Notice: for Strings the returned size may look strange. |
|
7037 |
Only useful with binary storage." |
|
7038 |
||
7039 |
|myClass| |
|
7040 |
||
7041 |
myClass := self class. |
|
7042 |
myClass isVariable ifTrue:[ |
|
6654 | 7043 |
myClass isPointers ifFalse:[ |
7044 |
myClass isBytes ifTrue:[ |
|
7045 |
^ self basicSize. |
|
7046 |
]. |
|
7047 |
myClass isWords ifTrue:[ |
|
7048 |
^ self basicSize * 2. |
|
7049 |
]. |
|
7050 |
myClass isSignedWords ifTrue:[ |
|
7051 |
^ self basicSize * 2. |
|
7052 |
]. |
|
7053 |
myClass isLongs ifTrue:[ |
|
7054 |
^ self basicSize * 4. |
|
7055 |
]. |
|
7056 |
myClass isSignedLongs ifTrue:[ |
|
7057 |
^ self basicSize * 4. |
|
7058 |
]. |
|
7059 |
myClass isLongLongs ifTrue:[ |
|
7060 |
^ self basicSize * 8. |
|
7061 |
]. |
|
7062 |
myClass isSignedLongLongs ifTrue:[ |
|
7063 |
^ self basicSize * 8. |
|
7064 |
]. |
|
7065 |
myClass isFloats ifTrue:[ |
|
7066 |
^ self basicSize * (ExternalBytes sizeofFloat) |
|
7067 |
]. |
|
7068 |
myClass isDoubles ifTrue:[ |
|
7069 |
^ self basicSize * (ExternalBytes sizeofDouble) |
|
7070 |
]. |
|
7071 |
self halt:'oops'. |
|
7072 |
] |
|
5755 | 7073 |
]. |
7074 |
^ 0 |
|
7075 |
||
7076 |
" |
|
7077 |
Point new byteSize |
|
7078 |
'hello' byteSize |
|
7079 |
(ByteArray with:1 with:2) byteSize |
|
7080 |
(FloatArray with:1.5) byteSize |
|
7081 |
(DoubleArray with:1.5) byteSize |
|
7082 |
(WordArray with:1 with:2) byteSize |
|
7083 |
" |
|
7084 |
! |
|
7085 |
||
7086 |
class |
|
7087 |
"return the receivers class" |
|
7088 |
||
7089 |
%{ /* NOCONTEXT */ |
|
7090 |
||
7091 |
RETURN ( __Class(self) ); |
|
7092 |
%} |
|
7093 |
! |
|
7094 |
||
7095 |
respondsTo:aSelector |
|
7096 |
"return true, if the receiver implements a method with selector equal |
|
7097 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
7098 |
receivers class or one of its superclasses. |
|
7099 |
||
7100 |
Notice, that this does not imply, that such a message can be sent without |
|
7101 |
an error being raised. For example, an implementation could send |
|
7102 |
#shouldNotImplement or #subclassResponsibility." |
|
7103 |
||
7104 |
" |
|
7105 |
should we go via the cache, or search (by class) ? |
|
7106 |
The first is faster, most of the time; while the 2nd fills |
|
7107 |
the cache with useless data if this is sent in a loop over all objects. |
|
7108 |
For now, use the cache ... |
|
7109 |
" |
|
7110 |
%{ /* NOCONTEXT */ |
|
7111 |
||
7112 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
6654 | 7113 |
RETURN ( false ); |
5755 | 7114 |
} |
7115 |
RETURN ( true ); |
|
7116 |
%} |
|
7117 |
. |
|
7118 |
^ self class canUnderstand:aSelector |
|
7119 |
||
7120 |
||
7121 |
"'aString' respondsTo:#+" |
|
7122 |
"'aString' respondsTo:#," |
|
7123 |
"'aString' respondsTo:#collect:" |
|
7124 |
! |
|
7125 |
||
7126 |
respondsToArithmetic |
|
7127 |
"return true, if the receiver responds to arithmetic messages. |
|
7128 |
false is returned here - the method is redefined in ArithmeticValue." |
|
7129 |
||
7130 |
^ false |
|
7131 |
! |
|
7132 |
||
7133 |
size |
|
7134 |
"return the number of the receivers indexed instance variables; |
|
7135 |
this method may be redefined in subclasses" |
|
7136 |
||
7137 |
^ self basicSize |
|
7138 |
! |
|
7139 |
||
7140 |
species |
|
7141 |
"return a class which is similar to (or the same as) the receivers class. |
|
7142 |
This is used to create an appropriate object when creating derived |
|
7143 |
copies in the collection classes (sometimes redefined)." |
|
7144 |
||
7145 |
^ self class |
|
7146 |
! |
|
7147 |
||
7148 |
yourself |
|
7149 |
"return the receiver - used for cascades to return self at the end" |
|
7150 |
||
7151 |
^ self |
|
7152 |
! ! |
|
7153 |
||
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
7154 |
|
5755 | 7155 |
!Object methodsFor:'secure message sending'! |
7156 |
||
7157 |
askFor:aSelector |
|
7158 |
"try to send the receiver the message, aSelector. |
|
7159 |
If it does not understand it, return false. |
|
7160 |
Otherwise the real value returned. |
|
7161 |
Useful to send messages such as: #isColor to unknown |
|
7162 |
receivers." |
|
7163 |
||
7164 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
7165 |
||
7166 |
" |
|
7167 |
1 askFor:#isColor |
|
7168 |
Color red askFor:#isColor |
|
7169 |
||
7170 |
1 askFor:#isFoo |
|
7171 |
Color red askFor:#isFoo |
|
7172 |
" |
|
7173 |
! |
|
7174 |
||
7175 |
perform:aSelector ifNotUnderstood:exceptionBlock |
|
7176 |
"try to send message aSelector to the receiver. |
|
7177 |
If its understood, return the methods returned value, |
|
7178 |
otherwise return the value of the exceptionBlock" |
|
7179 |
||
7180 |
|val ok| |
|
7181 |
||
6146 | 7182 |
MessageNotUnderstood handle:[:ex | |
6654 | 7183 |
"/ reject, if the bad message is not the one |
7184 |
"/ we have sent originally |
|
7185 |
ex parameter selector == aSelector ifFalse:[ |
|
7186 |
ex reject |
|
6741
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7187 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7188 |
ex receiver == self ifFalse:[ |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7189 |
ex reject |
6654 | 7190 |
] |
5755 | 7191 |
] do:[ |
6654 | 7192 |
val := self perform:aSelector. |
7193 |
ok := true. |
|
5755 | 7194 |
]. |
7195 |
ok isNil ifTrue:[ |
|
6654 | 7196 |
^ exceptionBlock value |
5755 | 7197 |
]. |
7198 |
^ val |
|
7199 |
||
7200 |
" |
|
7201 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
|
7202 |
1.2345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7203 |
12345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7204 |
" |
|
7205 |
! |
|
7206 |
||
7207 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
7208 |
"try to send message aSelector to the receiver. |
|
7209 |
If its understood, return the methods returned value, |
|
7210 |
otherwise return the value of the exceptionBlock" |
|
7211 |
||
7212 |
|val ok| |
|
7213 |
||
7214 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6654 | 7215 |
"/ reject, if the bad message is not the one |
7216 |
"/ we have sent originally |
|
7217 |
ex parameter selector == aSelector ifFalse:[ |
|
7218 |
ex reject |
|
6741
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7219 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7220 |
ex receiver == self ifFalse:[ |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7221 |
ex reject |
6654 | 7222 |
] |
5755 | 7223 |
] do:[ |
6654 | 7224 |
val := self perform:aSelector with:argument. |
7225 |
ok := true. |
|
5755 | 7226 |
]. |
7227 |
ok isNil ifTrue:[ |
|
6654 | 7228 |
^ exceptionBlock value |
5755 | 7229 |
]. |
7230 |
^ val |
|
7231 |
||
7232 |
" |
|
7233 |
|unknown| |
|
7234 |
||
7235 |
unknown := 1. |
|
7236 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7237 |
unknown := 'high there'. |
|
7238 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7239 |
" |
|
7240 |
! |
|
7241 |
||
5926 | 7242 |
perform:aSelector with:arg1 with:arg2 ifNotUnderstood:exceptionBlock |
7243 |
"try to send message aSelector to the receiver. |
|
7244 |
If its understood, return the methods returned value, |
|
7245 |
otherwise return the value of the exceptionBlock" |
|
7246 |
||
7247 |
|val ok| |
|
7248 |
||
7249 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6654 | 7250 |
"/ reject, if the bad message is not the one |
7251 |
"/ we have sent originally |
|
7252 |
ex parameter selector == aSelector ifFalse:[ |
|
7253 |
ex reject |
|
6741
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7254 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7255 |
ex receiver == self ifFalse:[ |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7256 |
ex reject |
6654 | 7257 |
] |
5926 | 7258 |
] do:[ |
6654 | 7259 |
val := self perform:aSelector with:arg1 with:arg2. |
7260 |
ok := true. |
|
5926 | 7261 |
]. |
7262 |
ok isNil ifTrue:[ |
|
6654 | 7263 |
^ exceptionBlock value |
5926 | 7264 |
]. |
7265 |
^ val |
|
7266 |
||
7267 |
" |
|
7268 |
|unknown| |
|
7269 |
||
7270 |
unknown := 1. |
|
7271 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7272 |
unknown := 'high there'. |
|
7273 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7274 |
" |
|
7275 |
! |
|
7276 |
||
5755 | 7277 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
7278 |
"try to send message aSelector to the receiver. |
|
7279 |
If its understood, return the methods returned value, |
|
7280 |
otherwise return the value of the exceptionBlock" |
|
7281 |
||
7282 |
|val ok| |
|
7283 |
||
7284 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6654 | 7285 |
"/ reject, if the bad message is not the one |
7286 |
"/ we have sent originally |
|
7287 |
ex parameter selector == aSelector ifFalse:[ |
|
7288 |
ex reject |
|
6741
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7289 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7290 |
ex receiver == self ifFalse:[ |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7291 |
ex reject |
6654 | 7292 |
] |
5755 | 7293 |
] do:[ |
6654 | 7294 |
val := self perform:aSelector withArguments:argumentArray. |
7295 |
ok := true. |
|
5755 | 7296 |
]. |
7297 |
ok isNil ifTrue:[ |
|
6654 | 7298 |
^ exceptionBlock value |
5755 | 7299 |
]. |
7300 |
^ val |
|
7301 |
||
7302 |
" |
|
7303 |
|unknown| |
|
7304 |
||
7305 |
unknown := 1. |
|
7306 |
(unknown perform:#+ withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
|
7307 |
unknown := 'high there'. |
|
7308 |
(unknown perform:#+ withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
|
7309 |
" |
|
7310 |
||
7311 |
"Modified: 27.3.1997 / 14:13:16 / cg" |
|
7312 |
! ! |
|
7313 |
||
7314 |
!Object methodsFor:'signal constants'! |
|
7315 |
||
7316 |
messageNotUnderstoodSignal |
|
6146 | 7317 |
^ MessageNotUnderstood |
5755 | 7318 |
|
7319 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
7320 |
! ! |
|
7321 |
||
7322 |
!Object methodsFor:'special queries'! |
|
7323 |
||
7324 |
allOwners |
|
7325 |
"return a collection of all objects referencing the receiver" |
|
7326 |
||
7327 |
^ ObjectMemory whoReferences:self |
|
7328 |
! |
|
7329 |
||
7330 |
references:anObject |
|
7331 |
"return true, if the receiver refers to the argument, anObject. |
|
7332 |
- for debugging only" |
|
7333 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7334 |
^ self referencesObject:anObject |
5755 | 7335 |
|
7336 |
" |
|
7337 |
|v| |
|
7338 |
||
7339 |
v := View new initialize. |
|
7340 |
v references:Display. |
|
7341 |
" |
|
7342 |
! |
|
7343 |
||
7344 |
referencesAny:aCollection |
|
7345 |
"return true, if the receiver refers to any object from |
|
7346 |
the argument, aCollection. |
|
7347 |
- for debugging only" |
|
7348 |
||
7349 |
%{ |
|
7350 |
OBJ cls, flags; |
|
7351 |
int nInsts, inst; |
|
7352 |
||
7353 |
if (! __isNonNilObject(self)) { |
|
6654 | 7354 |
RETURN (false); |
5755 | 7355 |
} |
7356 |
||
7357 |
if (__isArray(aCollection)) { |
|
6654 | 7358 |
int nObjs = __arraySize(aCollection); |
7359 |
char *minAddr = 0, *maxAddr = 0; |
|
7360 |
||
7361 |
if (nObjs == 0) { |
|
7362 |
RETURN (false); |
|
7363 |
} |
|
7364 |
||
7365 |
/* |
|
7366 |
* a little optimization: use the fact that all old objects |
|
7367 |
* refering to a new object are on the remSet; if I am not, |
|
7368 |
* a trivial reject is possible, if all objects are newbees. |
|
7369 |
* as a side effect, gather min/max addresses |
|
7370 |
*/ |
|
7371 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
7372 |
int allNewBees = 1; |
|
7373 |
int i; |
|
7374 |
||
7375 |
minAddr = (char *)(__ArrayInstPtr(aCollection)->a_element[0]); |
|
7376 |
maxAddr = minAddr; |
|
7377 |
||
7378 |
for (i=0; i<nObjs; i++) { |
|
7379 |
OBJ anObject; |
|
7380 |
||
7381 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7382 |
||
7383 |
if (__isNonNilObject(anObject)) { |
|
7384 |
int spc; |
|
7385 |
||
7386 |
if (((spc = __qSpace(anObject)) != NEWSPACE) && (spc != SURVSPACE)) { |
|
7387 |
allNewBees = 0; |
|
7388 |
} |
|
7389 |
} |
|
7390 |
||
7391 |
if ((char *)anObject < minAddr) { |
|
7392 |
minAddr = (char *)anObject; |
|
7393 |
} else if ((char *)anObject > maxAddr) { |
|
7394 |
maxAddr = (char *)anObject; |
|
7395 |
} |
|
7396 |
} |
|
7397 |
if (allNewBees) { |
|
7398 |
RETURN (false); |
|
7399 |
} |
|
7400 |
} |
|
7401 |
||
7402 |
/* |
|
7403 |
* fetch min/max in searchList (if not already done) |
|
7404 |
*/ |
|
7405 |
if (minAddr == 0) { |
|
7406 |
int i; |
|
7407 |
||
7408 |
for (i=0; i<nObjs; i++) { |
|
7409 |
OBJ anObject; |
|
7410 |
||
7411 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7412 |
if ((char *)anObject < minAddr) { |
|
7413 |
minAddr = (char *)anObject; |
|
7414 |
} else if ((char *)anObject > maxAddr) { |
|
7415 |
maxAddr = (char *)anObject; |
|
7416 |
} |
|
7417 |
} |
|
7418 |
} |
|
7419 |
||
7420 |
cls = __qClass(self); |
|
7421 |
if (((char *)cls >= minAddr) && ((char *)cls <= maxAddr)) { |
|
5755 | 7422 |
#if defined(memsrch4) |
6654 | 7423 |
if (memsrch4(__arrayVal(aCollection), (INT)cls, nObjs)) { |
7424 |
RETURN (true); |
|
7425 |
} |
|
5755 | 7426 |
#else |
6654 | 7427 |
int i; |
7428 |
||
7429 |
for (i=0; i<nObjs; i++) { |
|
7430 |
OBJ anObject; |
|
7431 |
||
7432 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7433 |
if (cls == anObject) { |
|
7434 |
RETURN (true); |
|
7435 |
} |
|
7436 |
} |
|
5755 | 7437 |
#endif /* memsrch4 */ |
6654 | 7438 |
} |
7439 |
||
7440 |
flags = __ClassInstPtr(cls)->c_flags; |
|
7441 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
7442 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
7443 |
} else { |
|
7444 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
7445 |
} |
|
7446 |
if (! nInsts) { |
|
7447 |
RETURN (false); |
|
7448 |
} |
|
7449 |
||
7450 |
if (nObjs == 1) { |
|
7451 |
/* better reverse the loop */ |
|
7452 |
OBJ anObject; |
|
7453 |
||
7454 |
anObject = __ArrayInstPtr(aCollection)->a_element[0]; |
|
5755 | 7455 |
#if defined(memsrch4) |
6654 | 7456 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
7457 |
RETURN (true); |
|
7458 |
} |
|
5755 | 7459 |
#else |
6654 | 7460 |
for (inst=0; inst<nInsts; inst++) { |
7461 |
if ((__InstPtr(self)->i_instvars[inst]) == anObject) { |
|
7462 |
RETURN (true); |
|
7463 |
} |
|
7464 |
} |
|
5755 | 7465 |
#endif |
6654 | 7466 |
RETURN (false); |
7467 |
} |
|
7468 |
||
7469 |
for (inst=0; inst<nInsts; inst++) { |
|
7470 |
OBJ instVar = __InstPtr(self)->i_instvars[inst]; |
|
7471 |
int i; |
|
7472 |
||
7473 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
5755 | 7474 |
#if defined(memsrch4) |
6654 | 7475 |
if (memsrch4(__arrayVal(aCollection), (INT)instVar, nObjs)) { |
7476 |
RETURN (true); |
|
7477 |
} |
|
5755 | 7478 |
#else |
6654 | 7479 |
for (i=0; i<nObjs; i++) { |
7480 |
OBJ anObject; |
|
7481 |
||
7482 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7483 |
if (instVar == anObject) { |
|
7484 |
RETURN (true); |
|
7485 |
} |
|
7486 |
} |
|
5755 | 7487 |
#endif /* memsrch4 */ |
6654 | 7488 |
} |
7489 |
} |
|
7490 |
RETURN (false); |
|
5755 | 7491 |
} |
7492 |
%}. |
|
7493 |
||
7494 |
aCollection do:[:el | |
|
6654 | 7495 |
(self references:el) ifTrue:[^ true]. |
5755 | 7496 |
]. |
7497 |
^ false |
|
7498 |
! |
|
7499 |
||
7500 |
referencesDerivedInstanceOf:aClass |
|
7501 |
"return true, if the receiver refers to an instance of |
|
7502 |
the argument, aClass or its subclass. This method exists |
|
7503 |
to support searching for users of a class." |
|
7504 |
||
7505 |
|myClass |
|
7506 |
numInst "{ Class: SmallInteger }" | |
|
7507 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7508 |
"check the class" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7509 |
(self isKindOf:aClass) ifTrue:[^ true]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7510 |
|
5755 | 7511 |
myClass := self class. |
7512 |
"check the instance variables" |
|
7513 |
numInst := myClass instSize. |
|
7514 |
1 to:numInst do:[:i | |
|
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7515 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
5755 | 7516 |
]. |
7517 |
||
7518 |
"check the indexed variables" |
|
7519 |
myClass isVariable ifTrue:[ |
|
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7520 |
myClass isPointers ifFalse:[ |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7521 |
"no need to search in non pointer fields" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7522 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7523 |
]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7524 |
numInst := self basicSize. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7525 |
1 to:numInst do:[:i | |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7526 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7527 |
] |
5755 | 7528 |
]. |
7529 |
^ false |
|
7530 |
||
7531 |
" |
|
7532 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
|
7533 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
7534 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
7535 |
" |
|
7536 |
! |
|
7537 |
||
7538 |
referencesInstanceOf:aClass |
|
7539 |
"return true, if the receiver refers to an instance of |
|
7540 |
the argument, aClass.This method exists |
|
7541 |
to support searching for users of a class." |
|
7542 |
||
7543 |
|myClass |
|
7544 |
numInst "{ Class: SmallInteger }" | |
|
7545 |
||
7546 |
myClass := self class. |
|
7547 |
||
7548 |
"check the class" |
|
7549 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
7550 |
||
7551 |
"check the instance variables" |
|
7552 |
numInst := myClass instSize. |
|
7553 |
1 to:numInst do:[:i | |
|
6654 | 7554 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
5755 | 7555 |
]. |
7556 |
||
7557 |
"check the indexed variables" |
|
7558 |
myClass isVariable ifTrue:[ |
|
6654 | 7559 |
myClass isPointers ifFalse:[ |
7560 |
"no need to search in non-pointer indexed fields" |
|
7561 |
myClass isLongs ifTrue:[ |
|
7562 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
7563 |
] ifFalse:[ |
|
7564 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
7565 |
^ aClass == SmallInteger |
|
7566 |
] |
|
7567 |
]. |
|
7568 |
numInst := self basicSize. |
|
7569 |
1 to:numInst do:[:i | |
|
7570 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
7571 |
] |
|
5755 | 7572 |
]. |
7573 |
^ false |
|
7574 |
||
7575 |
" |
|
7576 |
(1 @ 3.4) referencesInstanceOf:Float |
|
7577 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
7578 |
View new initialize referencesInstanceOf:(Display class) |
|
7579 |
" |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7580 |
! |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7581 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7582 |
referencesObject:anObject |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7583 |
"return true, if the receiver refers to the argument, anObject. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7584 |
- for debugging only" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7585 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7586 |
%{ /* NOCONTEXT */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7587 |
OBJ cls, flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7588 |
int nInsts, i; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7589 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7590 |
if (! __isNonNilObject(self)) { |
6654 | 7591 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7592 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7593 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7594 |
/* |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7595 |
* a little optimization: use the fact that all old objects |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7596 |
* refering to a new object are on the remSet; if I am not, |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7597 |
* a trivial reject is possible, if anObject is a newbee |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7598 |
*/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7599 |
if (__isNonNilObject(anObject)) { |
6654 | 7600 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7601 |
int spc; |
|
7602 |
||
7603 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7604 |
RETURN (false); |
|
7605 |
} |
|
7606 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7607 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7608 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7609 |
cls = __qClass(self); |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7610 |
if (cls == anObject) { |
6654 | 7611 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7612 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7613 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7614 |
flags = __ClassInstPtr(cls)->c_flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7615 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
6654 | 7616 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7617 |
} else { |
6654 | 7618 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7619 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7620 |
if (! nInsts) { |
6654 | 7621 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7622 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7623 |
#if defined(memsrch4) |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7624 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
6654 | 7625 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7626 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7627 |
#else |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7628 |
for (i=0; i<nInsts; i++) { |
6654 | 7629 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7630 |
RETURN (true); |
|
7631 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7632 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7633 |
#endif /* memsrch4 */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7634 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7635 |
%}. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7636 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7637 |
"/ |myClass |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7638 |
"/ numInst "{ Class: SmallInteger }" | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7639 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7640 |
"/ myClass := self class. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7641 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7642 |
"/ "check the class" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7643 |
"/ (myClass == anObject) ifTrue:[^ true]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7644 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7645 |
"/ "check the instance variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7646 |
"/ numInst := myClass instSize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7647 |
"/ 1 to:numInst do:[:i | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7648 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7649 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7650 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7651 |
"/ "check the indexed variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7652 |
"/ myClass isVariable ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7653 |
"/ myClass isPointers ifFalse:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7654 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7655 |
"/ "/ we could argue about the following unconditional return: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7656 |
"/ "/ it says that a non pointer array never has a reference to the |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7657 |
"/ "/ corresponding object - not mimicing a reference to a copy of the |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7658 |
"/ "/ integer. However, it avoids useless searches in huge byteArray |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7659 |
"/ "/ like objects when searching for owners. If in doubt, remove it. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7660 |
"/ "/ A consequence of the return below is that #[1 2 3] will say that it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7661 |
"/ "/ does not refer to the number 2 (think of keeping a copy instead) |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7662 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7663 |
"/ ^ false. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7664 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7665 |
"/ "/ alternative: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7666 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7667 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7668 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7669 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7670 |
"/ "/ because arrays are so common, and those have a highly tuned |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7671 |
"/ "/ idenitytIndex method, use it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7672 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7673 |
"/ myClass == Array ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7674 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7675 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7676 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7677 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7678 |
"/ "/ otherwise, do it the slow way |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7679 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7680 |
"/ numInst := self basicSize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7681 |
"/ 1 to:numInst do:[:i | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7682 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7683 |
"/ ] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7684 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7685 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7686 |
^ false |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7687 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7688 |
" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7689 |
|v| |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7690 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7691 |
v := View new initialize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7692 |
v references:Display. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7693 |
" |
5755 | 7694 |
! ! |
7695 |
||
7696 |
!Object methodsFor:'synchronized evaluation'! |
|
7697 |
||
7698 |
freeSynchronizationSemaphore |
|
7699 |
"free synchronizationSemaphore. May be used, to save memory when |
|
7700 |
an object is no longer used synchronized." |
|
7701 |
||
7702 |
|sema| |
|
7703 |
||
7704 |
sema := self synchronizationSemaphore. |
|
7705 |
sema notNil ifTrue:[ |
|
6654 | 7706 |
sema wait. "/ get lock |
7707 |
self synchronizationSemaphore:nil. |
|
5755 | 7708 |
]. |
7709 |
||
7710 |
" |
|
7711 |
self synchronized:[]. |
|
7712 |
self synchronizationSemaphore. |
|
7713 |
self freeSynchronizationSemaphore. |
|
7714 |
" |
|
7715 |
||
7716 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
7717 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
7718 |
! |
|
7719 |
||
7720 |
synchronizationSemaphore |
|
7721 |
"return the synchronization semaphore for myself. |
|
7722 |
subclasses may redefine" |
|
7723 |
||
7724 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
7725 |
||
7726 |
" |
|
7727 |
self synchronizationSemaphore |
|
7728 |
" |
|
7729 |
||
7730 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
7731 |
! |
|
7732 |
||
7733 |
synchronizationSemaphore:aSemaphore |
|
7734 |
"set the synchronisationSemaphore for myself. |
|
7735 |
subclasses may redefine this method" |
|
7736 |
||
7737 |
aSemaphore isNil ifTrue:[ |
|
6654 | 7738 |
"/ remove Semaphore |
7739 |
SynchronizationSemaphores removeKey:self ifAbsent:nil. |
|
5755 | 7740 |
] ifFalse:[ |
6654 | 7741 |
SynchronizationSemaphores at:self put:aSemaphore. |
5755 | 7742 |
]. |
7743 |
||
7744 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
7745 |
! |
|
7746 |
||
7747 |
synchronized:aBlock |
|
7748 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
7749 |
||
6600 | 7750 |
|sema wasBlocked| |
7751 |
||
7752 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5755 | 7753 |
|
7754 |
sema := self synchronizationSemaphore. |
|
7755 |
sema isNil ifTrue:[ |
|
7211
87f5d25b5c3d
Make synchronizationSemaphore a recursionLock
Stefan Vogel <sv@exept.de>
parents:
7208
diff
changeset
|
7756 |
sema := RecursionLock new name:'SynchronizationSemaphore'. |
6600 | 7757 |
self synchronizationSemaphore:sema. |
5755 | 7758 |
]. |
7759 |
||
6600 | 7760 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
7211
87f5d25b5c3d
Make synchronizationSemaphore a recursionLock
Stefan Vogel <sv@exept.de>
parents:
7208
diff
changeset
|
7761 |
sema critical:aBlock. |
5755 | 7762 |
|
7763 |
" |
|
7764 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
7765 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
7766 |
" |
|
7767 |
||
7768 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
7769 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
|
7770 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
|
7771 |
! ! |
|
7772 |
||
7773 |
!Object methodsFor:'system primitives'! |
|
7774 |
||
7775 |
asOop |
|
7776 |
"ST-80 compatibility: |
|
7777 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
7778 |
or index); since ST/X has no such thing, and the objects address cannot |
|
7779 |
be used (since its changing over time), we return the objects identityHash |
|
7780 |
key, which provides (at least) some identity indication. |
|
7781 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
7782 |
key of two non-identical objects may be the same. |
|
7783 |
You'd better not use it - especially do not misuse it." |
|
7784 |
||
7785 |
^ self identityHash |
|
7786 |
||
7787 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
7788 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
7789 |
! |
|
7790 |
||
7791 |
become:anotherObject |
|
7792 |
"make all references to the receiver become references to anotherObject |
|
7793 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
|
7794 |
This can be a very dangerous operation - be warned. |
|
7795 |
In general, using #become: should be avoided if possible, since it may |
|
7796 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
7797 |
||
7798 |
This may also be an expensive (i.e. slow) operation, |
|
7799 |
since in the worst case, the whole memory has to be searched for |
|
7800 |
references to the two objects (although the primitive tries hard to |
|
7801 |
limit the search, for acceptable performance in most cases). |
|
7802 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7803 |
or nil, or is a context of a living method (i.e. one that has not already |
|
7804 |
returned). |
|
7805 |
(notice that #become: is not used heavily by the system |
|
7806 |
- the Collection-classes have been rewritten to not use it.)" |
|
7807 |
%{ |
|
7808 |
if (__primBecome(self, anotherObject)) { |
|
6654 | 7809 |
RETURN ( self ); |
5755 | 7810 |
} |
7811 |
%}. |
|
7812 |
self primitiveFailed |
|
7813 |
! |
|
7814 |
||
7815 |
becomeNil |
|
7816 |
"make all references to the receiver become nil - effectively getting |
|
7817 |
rid of the receiver. |
|
7818 |
This can be a very dangerous operation - be warned. |
|
7819 |
||
7820 |
This may be an expensive (i.e. slow) operation. |
|
7821 |
The receiver may not be a SmallInteger or a context of a living method." |
|
7822 |
||
7823 |
%{ |
|
7824 |
if (__primBecomeNil(self)) { |
|
6654 | 7825 |
RETURN ( nil ); |
5755 | 7826 |
} |
7827 |
%}. |
|
7828 |
self primitiveFailed |
|
7829 |
! |
|
7830 |
||
7831 |
becomeSameAs:anotherObject |
|
7832 |
"make all references to the receiver become references to anotherObject |
|
7833 |
but NOT vice versa (as done in #become:). |
|
7834 |
This can be a very dangerous operation - be warned. |
|
7835 |
In general, using #become: should be avoided if possible, since it may |
|
7836 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
7837 |
||
7838 |
This may also be an expensive (i.e. slow) operation, |
|
7839 |
since in the worst case, the whole memory has to be searched for |
|
7840 |
references to the two objects (although the primitive tries hard to |
|
7841 |
limit the search, for acceptable performance in most cases). |
|
7842 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7843 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
7844 |
%{ |
|
7845 |
if (__primBecomeSameAs(self, anotherObject)) { |
|
6654 | 7846 |
RETURN ( self ); |
5755 | 7847 |
} |
7848 |
%}. |
|
7849 |
self primitiveFailed |
|
7850 |
! |
|
7851 |
||
7852 |
changeClassTo:otherClass |
|
7853 |
"changes the class of the receiver to the argument, otherClass. |
|
7854 |
This is only allowed (possible), if the receivers class and the argument |
|
7855 |
have the same structure (i.e. number of named instance variables and |
|
7856 |
type of indexed instance variables). |
|
7857 |
If the structures do not match, or any of the original class or new class |
|
7858 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
7859 |
||
7860 |
|myClass ok| |
|
7861 |
||
7862 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
|
7202
85178c4cefe0
ensure that other class is autoloaded in changeClassTo:
penk
parents:
7177
diff
changeset
|
7863 |
otherClass autoload. |
5755 | 7864 |
%{ |
7865 |
{ |
|
6533 | 7866 |
OBJ other = otherClass; |
7867 |
||
7868 |
if (__isNonNilObject(self) |
|
7869 |
&& __isNonNilObject(other) |
|
7870 |
&& (other != UndefinedObject) |
|
7871 |
&& (other != SmallInteger)) { |
|
7872 |
ok = true; |
|
7873 |
} else { |
|
7874 |
ok = false; |
|
7875 |
} |
|
5755 | 7876 |
} |
7877 |
%}. |
|
7878 |
ok ifTrue:[ |
|
6533 | 7879 |
ok := false. |
7880 |
myClass := self class. |
|
7881 |
myClass flags == otherClass flags ifTrue:[ |
|
7882 |
myClass instSize == otherClass instSize ifTrue:[ |
|
7883 |
"same instance layout and types: its ok to do it" |
|
7884 |
ok := true. |
|
7885 |
] ifFalse:[ |
|
7886 |
myClass isPointers ifTrue:[ |
|
7887 |
myClass isVariable ifTrue:[ |
|
7888 |
ok := true |
|
7889 |
] |
|
7890 |
] |
|
7891 |
] |
|
7892 |
] ifFalse:[ |
|
7893 |
myClass isPointers ifTrue:[ |
|
7894 |
"if newClass is a variable class, with instSize <= my instsize, |
|
7895 |
we can do it (effectively mapping additional instvars into the |
|
7896 |
variable part) - usefulness is questionable, though" |
|
7897 |
||
7898 |
otherClass isPointers ifTrue:[ |
|
7899 |
otherClass isVariable ifTrue:[ |
|
7900 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
7901 |
ifTrue:[ |
|
7902 |
ok := true |
|
7903 |
] |
|
7904 |
] ifFalse:[ |
|
7905 |
otherClass instSize == (myClass instSize + self basicSize) |
|
7906 |
ifTrue:[ |
|
7907 |
ok := true |
|
7908 |
] |
|
7909 |
] |
|
7910 |
] ifFalse:[ |
|
7911 |
"it does not make sense to convert pointers to bytes ..." |
|
7912 |
] |
|
7913 |
] ifFalse:[ |
|
7914 |
"does it make sense, to convert bits ?" |
|
7915 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
7916 |
(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[ |
|
7917 |
ok := true |
|
7918 |
] |
|
7919 |
] |
|
7920 |
] |
|
5755 | 7921 |
]. |
7922 |
ok ifTrue:[ |
|
6533 | 7923 |
"now, change the receivers class ..." |
5755 | 7924 |
%{ |
6533 | 7925 |
{ |
7926 |
OBJ me = self; |
|
7927 |
||
7928 |
__qClass(me) = otherClass; |
|
7929 |
__STORE(me, otherClass); |
|
7930 |
RETURN (me); |
|
7931 |
} |
|
5755 | 7932 |
%}. |
7933 |
]. |
|
6533 | 7934 |
otherClass isLoaded ifFalse:[ |
7935 |
^ self changeClassTo:(otherClass autoload). |
|
7936 |
]. |
|
5755 | 7937 |
" |
7938 |
the receiver cannot be represented as a instance of |
|
7939 |
the desired class. |
|
7940 |
For example, you cannot change a bitInstance (byteArray etc.) |
|
7941 |
into a pointer object and vice versa. |
|
7942 |
" |
|
7943 |
self primitiveFailed |
|
7944 |
! |
|
7945 |
||
7946 |
changeClassToThatOf:anObject |
|
7947 |
"changes the class of the receiver to that of the argument, anObject. |
|
7948 |
This is only allowed (possible), if the receivers class and the arguments |
|
7949 |
class have the same structure (i.e. number of named instance variables and |
|
7950 |
type of indexed instance variables). If the structures do not match, or any |
|
7951 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
7952 |
||
7953 |
self changeClassTo:(anObject class) |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7954 |
! |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7955 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7956 |
replaceReferencesTo:anObject with:newRef |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7957 |
"if the receiver refers to the argument, anObject, replace this reference with newRef. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7958 |
Return true, if any reference was changed. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7959 |
Notice: this does not change the class-reference." |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7960 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7961 |
%{ /* NOCONTEXT */ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7962 |
OBJ cls, flags, anyChange; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7963 |
int nInsts, i; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7964 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7965 |
if (! __isNonNilObject(self)) { |
6654 | 7966 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7967 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7968 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7969 |
/* |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7970 |
* a little optimization: use the fact that all old objects |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7971 |
* refering to a new object are on the remSet; if I am not, |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7972 |
* a trivial reject is possible, if anObject is a newbee |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7973 |
*/ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7974 |
if (__isNonNilObject(anObject)) { |
6654 | 7975 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7976 |
int spc; |
|
7977 |
||
7978 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7979 |
RETURN (false); |
|
7980 |
} |
|
7981 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7982 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7983 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7984 |
cls = __qClass(self); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7985 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7986 |
flags = __ClassInstPtr(cls)->c_flags; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7987 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
6654 | 7988 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7989 |
} else { |
6654 | 7990 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7991 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7992 |
if (! nInsts) { |
6654 | 7993 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7994 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7995 |
anyChange = false; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7996 |
for (i=0; i<nInsts; i++) { |
6654 | 7997 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7998 |
__InstPtr(self)->i_instvars[i] = newRef; |
|
7999 |
__STORE(self, newRef); |
|
8000 |
anyChange = true; |
|
8001 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8002 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8003 |
RETURN (anyChange); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8004 |
%}. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8005 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8006 |
" |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8007 |
|v| |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8008 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8009 |
v := Array with:1234 with:'hello' with:Array. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8010 |
v replaceReferencesTo:Array with:ByteArray. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8011 |
v inspect |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8012 |
" |
5755 | 8013 |
! ! |
8014 |
||
8015 |
!Object methodsFor:'testing'! |
|
8016 |
||
8017 |
? defaultValue |
|
8018 |
"a syntactic shugar-piece: |
|
8019 |
if the receiver is nil, return the defaultValue; |
|
8020 |
otherwise, return the receiver. |
|
8021 |
This method is only redefined in UndefinedObject - therefore, |
|
8022 |
the recevier is retuned here. |
|
8023 |
||
8024 |
Thus, if foo and bar are simple variables or constants, |
|
6654 | 8025 |
foo ? bar |
5755 | 8026 |
is the same as: |
6654 | 8027 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
5755 | 8028 |
|
8029 |
if they are message sends, the equivalent code is: |
|
6654 | 8030 |
[ |
8031 |
|t1 t2| |
|
8032 |
||
8033 |
t1 := foo. |
|
8034 |
t2 := bar. |
|
8035 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
8036 |
] value |
|
5755 | 8037 |
|
8038 |
Can be used to provide defaultValues to variables, |
|
8039 |
as in: |
|
6654 | 8040 |
foo := arg ? #defaultValue |
5755 | 8041 |
|
8042 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8043 |
Notice: |
|
6654 | 8044 |
This method is open coded (inlined) by the compiler(s) |
8045 |
- redefining it may not work as expected." |
|
5755 | 8046 |
|
8047 |
^ self |
|
8048 |
||
8049 |
" |
|
8050 |
1 ? #default |
|
8051 |
nil ? #default |
|
8052 |
" |
|
8053 |
||
8054 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8055 |
"Modified: / 19.5.1998 / 17:39:56 / cg" |
|
8056 |
! |
|
8057 |
||
8058 |
?? defaultValue |
|
8059 |
"a syntactic shugar-piece: |
|
8060 |
much like ?, but sends #value to the argument if required. |
|
8061 |
(i.e. its the same as #ifNil:) |
|
8062 |
If the receiver is nil, return the defaultValues value; |
|
8063 |
otherwise, return the receiver. |
|
8064 |
This method is only redefined in UndefinedObject - therefore, |
|
8065 |
the recevier is retuned here. |
|
8066 |
||
8067 |
Thus, if foo and bar are simple variables or constants, |
|
6654 | 8068 |
foo ?? bar |
5755 | 8069 |
is the same as: |
6654 | 8070 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
5755 | 8071 |
|
8072 |
if they are message sends, the equivalent code is: |
|
6654 | 8073 |
[ |
8074 |
|t t2| |
|
8075 |
||
8076 |
t := foo. |
|
8077 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
8078 |
] value |
|
5755 | 8079 |
|
8080 |
Can be used to provide defaultValues to variables, |
|
8081 |
as in: |
|
6654 | 8082 |
foo := arg ?? [ self computeDefault ] |
5755 | 8083 |
|
8084 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8085 |
" |
|
8086 |
||
8087 |
^ self |
|
8088 |
||
8089 |
" |
|
8090 |
1 ?? #default |
|
8091 |
nil ?? #default |
|
8092 |
1 ?? [ self halt. 1 + 2 ] |
|
8093 |
nil ?? [ self halt. 1 + 2 ] |
|
6069 | 8094 |
1 ?? [Date today] |
8095 |
nil ?? [Date today] |
|
5755 | 8096 |
" |
8097 |
||
8098 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8099 |
"Modified: / 19.5.1998 / 17:42:56 / cg" |
|
8100 |
! |
|
8101 |
||
8102 |
ifNil:aBlockOrValue |
|
8103 |
"return myself, or the result from evaluating the argument, if I am nil. |
|
8104 |
This is much like #?, but sends #value to the argument in case of a nil |
|
8105 |
receiver. |
|
8106 |
Notice: |
|
6654 | 8107 |
This method is open coded (inlined) by the compiler(s) |
8108 |
- redefining it may not work as expected." |
|
5755 | 8109 |
|
8110 |
^ self |
|
8111 |
! |
|
8112 |
||
8113 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
|
8114 |
"return the value of the first arg, if I am nil, |
|
8115 |
the result from evaluating the 2nd argument, if I am not nil. |
|
8116 |
Notice: |
|
6654 | 8117 |
This method is open coded (inlined) by the compiler(s) |
8118 |
- redefining it may not work as expected." |
|
5755 | 8119 |
|
8120 |
^ notNilBlockOrValue value |
|
8121 |
||
8122 |
! |
|
8123 |
||
8124 |
ifNotNil:aBlockOrValue |
|
8125 |
"return myself if nil, or the result from evaluating the argument, |
|
8126 |
if I am not nil. |
|
8127 |
Notice: |
|
6654 | 8128 |
This method is open coded (inlined) by the compiler(s) |
8129 |
- redefining it may not work as expected." |
|
5755 | 8130 |
|
8131 |
^ aBlockOrValue value |
|
8132 |
||
8133 |
! |
|
8134 |
||
8135 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
|
8136 |
"return the value of the 2nd arg, if I am nil, |
|
8137 |
the result from evaluating the 1st argument, if I am not nil. |
|
8138 |
Notice: |
|
6654 | 8139 |
This method is open coded (inlined) by the compiler(s) |
8140 |
- redefining it may not work as expected." |
|
5755 | 8141 |
|
8142 |
^ notNilBlockOrValue value |
|
8143 |
||
8144 |
||
8145 |
! |
|
8146 |
||
8147 |
isArray |
|
8148 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
8149 |
false is returned here - the method is only redefined in Array." |
|
8150 |
||
8151 |
^ false |
|
8152 |
! |
|
8153 |
||
8154 |
isAssociation |
|
8155 |
"return true, if the receiver is some kind of association; |
|
8156 |
false is returned here - the method is only redefined in Association." |
|
8157 |
||
8158 |
^ false |
|
8159 |
||
8160 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
8161 |
! |
|
8162 |
||
8163 |
isBehavior |
|
8164 |
"return true, if the receiver is some kind of class (i.e. behavior); |
|
8165 |
false is returned here - the method is only redefined in Behavior." |
|
8166 |
||
8167 |
^ false |
|
8168 |
! |
|
8169 |
||
8170 |
isBlock |
|
8171 |
"return true, if the receiver is some kind of block; |
|
8172 |
false returned here - the method is only redefined in Block." |
|
8173 |
||
8174 |
^ false |
|
8175 |
! |
|
8176 |
||
5824 | 8177 |
isBoolean |
8178 |
"return true, if the receiver is a boolean; |
|
8179 |
false is returned here - the method is only redefined in Boolean." |
|
8180 |
||
8181 |
^ false |
|
8182 |
! |
|
8183 |
||
5755 | 8184 |
isByteArray |
8185 |
"return true, if the receiver is some kind of bytearray; |
|
8186 |
false is returned here - the method is only redefined in ByteArray." |
|
8187 |
||
8188 |
^ false |
|
8189 |
! |
|
8190 |
||
8191 |
isCharacter |
|
8192 |
"return true, if the receiver is some kind of character; |
|
8193 |
false is returned here - the method is only redefined in Character." |
|
8194 |
||
8195 |
^ false |
|
8196 |
! |
|
8197 |
||
8198 |
isClass |
|
8199 |
"return true, if the receiver is some kind of class (real class, |
|
8200 |
not just behavior); |
|
8201 |
false is returned here - the method is only redefined in Class." |
|
8202 |
||
8203 |
^ false |
|
8204 |
! |
|
8205 |
||
8206 |
isCollection |
|
8207 |
"return true, if the receiver is some kind of collection; |
|
8208 |
false is returned here - the method is only redefined in Collection." |
|
8209 |
||
8210 |
^ false |
|
8211 |
! |
|
8212 |
||
8213 |
isColor |
|
8214 |
"return true, if the receiver is some kind of color; |
|
8215 |
false is returned here - the method is only redefined in Color." |
|
8216 |
||
8217 |
^ false |
|
8218 |
! |
|
8219 |
||
6567 | 8220 |
isCons |
8221 |
"return true, if the receiver is a cons (pair); |
|
8222 |
false is returned here - the method is only redefined in Cons." |
|
8223 |
||
8224 |
^ false |
|
8225 |
! |
|
8226 |
||
5755 | 8227 |
isContext |
8228 |
"return true, if the receiver is some kind of context; |
|
8229 |
false returned here - the method is only redefined in Context." |
|
8230 |
||
8231 |
^ false |
|
8232 |
! |
|
8233 |
||
6181 | 8234 |
isEmptyOrNil |
8235 |
"Squeak compatibility: |
|
6182 | 8236 |
return true if I am nil or an empty collection - return false here. |
8237 |
Sigh: the same as ST/X isNilOrEmptyCollection - which one should be kept in the long run ?" |
|
6181 | 8238 |
|
8239 |
^ false |
|
8240 |
||
8241 |
"Created: / 13.11.2001 / 13:17:04 / cg" |
|
6182 | 8242 |
"Modified: / 13.11.2001 / 13:28:40 / cg" |
6181 | 8243 |
! |
8244 |
||
6221 | 8245 |
isException |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8246 |
"answer true, if this ia an Exception, that may be queried about its type" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8247 |
|
6221 | 8248 |
^ false |
8249 |
||
8250 |
"Created: / 17.11.2001 / 18:37:44 / cg" |
|
8251 |
! |
|
8252 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8253 |
isExceptionCreator |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8254 |
"return true, if the receiver can create exceptions, |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8255 |
this includes #raise, #raiseRequest as well as the behavior of |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8256 |
an exception handler, such as the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8257 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8258 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8259 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8260 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8261 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8262 |
"return true, if the receiver responds to the exception handler protocol, |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8263 |
especially to the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8264 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8265 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8266 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8267 |
|
5755 | 8268 |
isExternalStream |
8269 |
"return true, if the receiver is some kind of externalStream; |
|
8270 |
false is returned here - the method is only redefined in ExternalStream." |
|
8271 |
||
8272 |
^false |
|
8273 |
! |
|
8274 |
||
8275 |
isFileStream |
|
8276 |
"return true, if the receiver is some kind of fileStream; |
|
8277 |
false is returned here - the method is only redefined in FileStream." |
|
8278 |
||
8279 |
^false |
|
8280 |
! |
|
8281 |
||
8282 |
isFilename |
|
8283 |
"return true, if the receiver is some kind of filename; |
|
8284 |
false is returned here - the method is only redefined in Filename." |
|
8285 |
||
8286 |
^false |
|
8287 |
! |
|
8288 |
||
8289 |
isFixedPoint |
|
8290 |
"return true, if the receiver is some kind of fixedPoint number; |
|
8291 |
false is returned here - the method is only redefined in FixedPoint." |
|
8292 |
||
8293 |
^ false |
|
8294 |
||
8295 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
8296 |
! |
|
8297 |
||
8298 |
isFixedSize |
|
8299 |
"return true if the receiver cannot grow easily |
|
8300 |
(i.e. a grow may be expensive, since it involves a become:)" |
|
8301 |
||
8302 |
^ true |
|
8303 |
! |
|
8304 |
||
6185 | 8305 |
isFloat |
8306 |
"return true, if the receiver is some kind of floating point number; |
|
8307 |
false is returned here. |
|
8308 |
Same as #isLimitedPrecisionReal, but a better name ;-)" |
|
8309 |
||
8310 |
^ false |
|
8311 |
||
8312 |
"Modified: / 14.11.2001 / 14:57:46 / cg" |
|
8313 |
! |
|
8314 |
||
5755 | 8315 |
isForm |
8316 |
"return true, if the receiver is some kind of form; |
|
8317 |
false is returned here - the method is only redefined in Form." |
|
8318 |
||
8319 |
^ false |
|
8320 |
! |
|
8321 |
||
8322 |
isFraction |
|
8323 |
"return true, if the receiver is some kind of fraction; |
|
8324 |
false is returned here - the method is only redefined in Fraction." |
|
8325 |
||
8326 |
^ false |
|
8327 |
! |
|
8328 |
||
8329 |
isImage |
|
8330 |
"return true, if the receiver is some kind of image; |
|
8331 |
false is returned here - the method is only redefined in Image." |
|
8332 |
||
8333 |
^ false |
|
8334 |
! |
|
8335 |
||
8336 |
isImageOrForm |
|
8337 |
"return true, if the receiver is some kind of image or form; |
|
8338 |
false is returned here - the method is only redefined in Image and Form." |
|
8339 |
||
8340 |
^ false |
|
8341 |
! |
|
8342 |
||
8343 |
isImmediate |
|
8344 |
"return true if I am an immediate object |
|
8345 |
i.e. I am represented in the pointer itself and |
|
8346 |
no real object header/storage is used me. |
|
8347 |
(currently, only SmallIntegers, some characters and nil return true)" |
|
8348 |
||
8349 |
^ self class hasImmediateInstances |
|
8350 |
||
8351 |
"Created: 3.6.1997 / 12:00:18 / cg" |
|
8352 |
! |
|
8353 |
||
8354 |
isInteger |
|
8355 |
"return true, if the receiver is some kind of integer number; |
|
8356 |
false is returned here - the method is only redefined in Integer." |
|
8357 |
||
8358 |
^ false |
|
8359 |
! |
|
8360 |
||
8361 |
isJavaClass |
|
8362 |
"return true, if this is a javaClass. |
|
8363 |
false is returned here - the method is only redefined in JavaClass." |
|
8364 |
||
8365 |
^ false |
|
8366 |
||
8367 |
"Created: / 26.3.1997 / 13:34:54 / cg" |
|
8368 |
"Modified: / 8.5.1998 / 21:25:21 / cg" |
|
8369 |
! |
|
8370 |
||
8371 |
isJavaClassRef |
|
8372 |
"return true, if this is a JavaClassRef. |
|
8373 |
false is returned here - the method is only redefined in JavaClassRef." |
|
8374 |
||
8375 |
^ false |
|
8376 |
||
8377 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8378 |
"Created: / 24.12.1999 / 01:46:28 / cg" |
|
8379 |
! |
|
8380 |
||
8381 |
isJavaContext |
|
8382 |
"return true, if this is a javaContext. |
|
8383 |
false is returned here - the method is only redefined in JavaContext." |
|
8384 |
||
8385 |
^ false |
|
8386 |
||
8387 |
"Created: / 8.5.1998 / 21:24:27 / cg" |
|
8388 |
"Modified: / 8.5.1998 / 21:25:35 / cg" |
|
8389 |
! |
|
8390 |
||
8391 |
isJavaMethod |
|
8392 |
"return true, if this is a JavaMethod. |
|
8393 |
false is returned here - the method is only redefined in JavaMethod." |
|
8394 |
||
8395 |
^ false |
|
8396 |
||
8397 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8398 |
"Created: / 25.9.1999 / 23:26:12 / cg" |
|
8399 |
! |
|
8400 |
||
8401 |
isJavaMethodRef |
|
8402 |
"return true, if this is a JavaMethodRef. |
|
8403 |
false is returned here - the method is only redefined in JavaMethodRef." |
|
8404 |
||
8405 |
^ false |
|
8406 |
||
8407 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8408 |
"Created: / 23.12.1999 / 19:44:51 / cg" |
|
8409 |
! |
|
8410 |
||
8411 |
isJavaObject |
|
8412 |
"return true, if this is a javaObject. |
|
8413 |
false is returned here - the method is only redefined in JavaObject." |
|
8414 |
||
8415 |
^ false |
|
8416 |
||
8417 |
"Created: / 26.3.1997 / 13:34:48 / cg" |
|
8418 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8419 |
! |
|
8420 |
||
8421 |
isJavaScriptClass |
|
8422 |
"return true, if this is a javaScriptClass. |
|
8423 |
false is returned here - the method is only redefined in JavaScriptClass." |
|
8424 |
||
8425 |
^ false |
|
8426 |
! |
|
8427 |
||
8428 |
isKindOf:aClass |
|
8429 |
"return true, if the receiver is an instance of aClass or one of its |
|
8430 |
subclasses, false otherwise. |
|
8431 |
Advice: |
|
6654 | 8432 |
use of this to check objects for certain attributes/protocoll should |
8433 |
be avoided; it limits the reusability of your classes by limiting use |
|
8434 |
to instances of certain classes and fences you into a specific inheritance |
|
8435 |
hierarchy. |
|
8436 |
Use check-methods to check an object for a certain attributes/protocol |
|
8437 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
8438 |
||
8439 |
Using #isKindOf: is considered BAD STYLE. |
|
5755 | 8440 |
|
8441 |
Advice2: |
|
6654 | 8442 |
Be aware, that using an #isXXX method is usually much faster than |
8443 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
8444 |
hierarchy, comparing every class on the way. |
|
8445 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
8446 |
a single function call. |
|
5755 | 8447 |
" |
8448 |
||
8449 |
%{ /* NOCONTEXT */ |
|
8450 |
register OBJ thisClass; |
|
8451 |
||
8452 |
thisClass = __Class(self); |
|
8453 |
while (thisClass != nil) { |
|
6654 | 8454 |
if (thisClass == aClass) { |
8455 |
RETURN ( true ); |
|
8456 |
} |
|
8457 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
5755 | 8458 |
} |
8459 |
RETURN ( false ); |
|
8460 |
%} |
|
8461 |
||
8462 |
"/ |
|
8463 |
"/ the above code is equivalent to: |
|
8464 |
"/ |
|
8465 |
"/ thisClass := self class. |
|
8466 |
"/ [thisClass notNil] whileTrue:[ |
|
8467 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
8468 |
"/ thisClass := thisClass superclass |
|
8469 |
"/ ]. |
|
8470 |
"/ ^ false |
|
8471 |
"/ |
|
8472 |
||
8473 |
! |
|
8474 |
||
8475 |
isLayout |
|
8476 |
"return true, if the receiver is some kind of layout; |
|
8477 |
false is returned here - the method is only redefined in Layout." |
|
8478 |
||
8479 |
^ false |
|
8480 |
! |
|
8481 |
||
6567 | 8482 |
isLazyValue |
8483 |
^ false |
|
8484 |
! |
|
8485 |
||
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8486 |
isLimitedPrecisionReal |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8487 |
"return true, if the receiver is some kind of floating point number; |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8488 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8489 |
|
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8490 |
^ false |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8491 |
! |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8492 |
|
5755 | 8493 |
isList |
8494 |
"return true, if the receiver is some kind of list collection; |
|
8495 |
false is returned here - the method is only redefined in List." |
|
8496 |
||
8497 |
^ false |
|
8498 |
||
8499 |
"Created: / 11.2.2000 / 01:37:05 / cg" |
|
8500 |
! |
|
8501 |
||
8502 |
isLiteral |
|
8503 |
"return true, if the receiver can be represented as a literal constant in ST syntax; |
|
8504 |
false is returned here - the method is redefined in some classes." |
|
8505 |
||
8506 |
^ false |
|
8507 |
! |
|
8508 |
||
8509 |
isMemberOf:aClass |
|
8510 |
"return true, if the receiver is an instance of aClass, false otherwise. |
|
8511 |
Advice: |
|
6654 | 8512 |
use of this to check objects for certain attributes/protocoll should |
8513 |
be avoided; it limits the reusability of your classes by limiting use |
|
8514 |
to instances of a certain class. |
|
8515 |
Use check-methods to check an object for a certain attributes/protocol |
|
8516 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
8517 |
||
8518 |
Using #isMemberOf: is considered BAD STYLE. |
|
5755 | 8519 |
Notice: |
6654 | 8520 |
This method is open coded (inlined) by the compiler(s) |
8521 |
- redefining it may not work as expected." |
|
5755 | 8522 |
|
8523 |
^ (self class) == aClass |
|
8524 |
! |
|
8525 |
||
8526 |
isMeta |
|
8527 |
"return true, if the receiver is some kind of metaclass; |
|
8528 |
false is returned here - the method is only redefined in Metaclass." |
|
8529 |
||
8530 |
^ false |
|
8531 |
! |
|
8532 |
||
8533 |
isMethod |
|
8534 |
"return true, if the receiver is some kind of method; |
|
8535 |
false returned here - the method is only redefined in Method." |
|
8536 |
||
8537 |
^ false |
|
8538 |
! |
|
8539 |
||
8540 |
isMorph |
|
8541 |
"return true, if the receiver is some kind of morph; |
|
8542 |
false is returned here - the method is only redefined in Morph." |
|
8543 |
||
8544 |
^ false |
|
8545 |
! |
|
8546 |
||
8547 |
isNameSpace |
|
8548 |
"return true, if this is a nameSpace. |
|
8549 |
false is returned here - the method is only redefined in Namespace." |
|
8550 |
||
8551 |
^ false |
|
8552 |
||
8553 |
"Created: / 11.10.1996 / 18:08:56 / cg" |
|
8554 |
"Modified: / 8.5.1998 / 21:26:05 / cg" |
|
8555 |
! |
|
8556 |
||
8557 |
isNamespace |
|
8558 |
"return true, if this is a nameSpace. |
|
8559 |
false is returned here - the method is only redefined in Namespace." |
|
8560 |
||
5869 | 8561 |
<resource:#obsolete> |
8562 |
||
5755 | 8563 |
self obsoleteMethodWarning:'use #isNameSpace'. |
6805 | 8564 |
^ self isNameSpace |
5755 | 8565 |
! |
8566 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8567 |
isNil |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8568 |
"return true, if the receiver is nil. |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8569 |
Notice: |
6654 | 8570 |
This method is open coded (inlined) by the compiler(s) |
8571 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8572 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8573 |
^ false |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8574 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8575 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8576 |
isNilOrEmptyCollection |
6182 | 8577 |
"return true if I am nil or an empty collection - false here. |
8578 |
Sigh: the same as Squeaks isEmptyOrNil - which one should be kept in the long run ?" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8579 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8580 |
^ false |
6182 | 8581 |
|
8582 |
"Modified: / 13.11.2001 / 13:28:06 / cg" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8583 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8584 |
|
5755 | 8585 |
isNumber |
8586 |
"return true, if the receiver is some kind of number; |
|
8587 |
false is returned here - the method is only redefined in Number." |
|
8588 |
||
8589 |
^ false |
|
8590 |
! |
|
8591 |
||
8592 |
isOrderedCollection |
|
8593 |
"return true, if the receiver is some kind of ordered collection (or list etc); |
|
8594 |
false is returned here - the method is only redefined in OrderedCollection." |
|
8595 |
||
8596 |
^ false |
|
8597 |
! |
|
8598 |
||
8599 |
isPoint |
|
8600 |
"return true, if the receiver is some kind of point; |
|
8601 |
false is returned here - the method is only redefined in Point." |
|
8602 |
||
8603 |
^ false |
|
8604 |
! |
|
8605 |
||
8606 |
isRectangle |
|
8607 |
"return true, if the receiver is some kind of rectangle; |
|
8608 |
false is returned here - the method is only redefined in Rectangle." |
|
8609 |
||
8610 |
^ false |
|
8611 |
! |
|
8612 |
||
8613 |
isRemoteObject |
|
8614 |
"return true, if the receiver is some kind of remoteObject, |
|
8615 |
false if its local - the method is only redefined in RemoteObject." |
|
8616 |
||
8617 |
^ false |
|
8618 |
||
8619 |
"Created: 28.10.1996 / 15:18:45 / cg" |
|
8620 |
"Modified: 28.10.1996 / 15:20:57 / cg" |
|
8621 |
! |
|
8622 |
||
8623 |
isSequenceable |
|
8624 |
"return true, if the receiver is some kind of sequenceable collection; |
|
8625 |
false is returned here - the method is only redefined in SequenceableCollection." |
|
8626 |
||
8627 |
^ false |
|
8628 |
! |
|
8629 |
||
8630 |
isSequenceableCollection |
|
8631 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
8632 |
This method is a historic leftover and will be removed soon ... |
|
8633 |
(although its name is much better than #isSequenceable - sigh)" |
|
8634 |
||
5869 | 8635 |
<resource:#obsolete> |
8636 |
||
5755 | 8637 |
self obsoleteMethodWarning:'use #isSequenceable'. |
8638 |
^ false |
|
8639 |
! |
|
8640 |
||
8641 |
isStream |
|
8642 |
"return true, if the receiver is some kind of stream; |
|
8643 |
false is returned here - the method is only redefined in Stream." |
|
8644 |
||
8645 |
^ false |
|
8646 |
! |
|
8647 |
||
8648 |
isString |
|
8649 |
"return true, if the receiver is some kind of string; |
|
8650 |
false is returned here - the method is only redefined in CharacterArray." |
|
8651 |
||
8652 |
^ false |
|
8653 |
! |
|
8654 |
||
8655 |
isStringCollection |
|
8656 |
"return true, if the receiver is some kind of stringCollection; |
|
8657 |
false is returned here - the method is only redefined in StringCollection." |
|
8658 |
||
8659 |
^ false |
|
8660 |
! |
|
8661 |
||
8662 |
isSymbol |
|
8663 |
"return true, if the receiver is some kind of symbol; |
|
8664 |
false is returned here - the method is only redefined in Symbol." |
|
8665 |
||
8666 |
^ false |
|
8667 |
! |
|
8668 |
||
8669 |
isText |
|
8670 |
"return true, if the receiver is some kind of text object; |
|
8671 |
false is returned here - the method is only redefined in Text." |
|
8672 |
||
8673 |
^ false |
|
8674 |
||
8675 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
8676 |
! |
|
8677 |
||
8678 |
isValueModel |
|
8679 |
"return true, if the receiver is some kind of valueModel; |
|
8680 |
false is returned here - the method is only redefined in ValueModel." |
|
8681 |
||
8682 |
^ false |
|
8683 |
||
8684 |
! |
|
8685 |
||
8686 |
isVariable |
|
8687 |
"return true if the receiver has indexed instance variables, |
|
8688 |
false otherwise." |
|
8689 |
||
8690 |
^ self class isVariable |
|
8691 |
! |
|
8692 |
||
8693 |
isVariableBinding |
|
8694 |
"return true, if this is a binding for a variable. |
|
8695 |
false is returned here - the method is only redefined in Binding." |
|
8696 |
||
8697 |
^ false |
|
8698 |
||
8699 |
"Created: / 19.6.1997 / 17:38:44 / cg" |
|
8700 |
"Modified: / 8.5.1998 / 21:26:55 / cg" |
|
8701 |
! |
|
8702 |
||
8703 |
isView |
|
8704 |
"return true, if the receiver is some kind of view; |
|
8705 |
false is returned here - the method is only redefined in View." |
|
8706 |
||
8707 |
^ false |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8708 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8709 |
|
6932 | 8710 |
notEmptyOrNil |
8711 |
"Squeak compatibility: |
|
8712 |
return true if I am neither nil nor an empty collection. |
|
8713 |
Return true here." |
|
8714 |
||
8715 |
^ true |
|
8716 |
! |
|
8717 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8718 |
notNil |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8719 |
"return true, if the receiver is not nil. |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8720 |
Notice: |
6654 | 8721 |
This method is open coded (inlined) by the compiler(s) |
8722 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8723 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8724 |
^ true |
5755 | 8725 |
! ! |
8726 |
||
8727 |
!Object methodsFor:'tracing'! |
|
8728 |
||
8729 |
traceInto:aRequestor level:level from:referrer |
|
8730 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
8731 |
||
8732 |
^ aRequestor traceObject:self level:level from:referrer |
|
8733 |
||
8734 |
"Created: / 2.9.1999 / 09:05:17 / stefan" |
|
8735 |
! ! |
|
8736 |
||
8737 |
!Object methodsFor:'user interaction & notifications'! |
|
8738 |
||
8739 |
activityNotification:aString |
|
8740 |
"this can be sent from deeply nested methods, which are going to perform |
|
8741 |
some long-time activity. |
|
8742 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
8743 |
passing the argument. The handler should show this message whereever it likes, |
|
8744 |
and proceed. If there is no handler, this is simply ignored. |
|
8745 |
||
8746 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
8747 |
which likes to display that message in its label or a busy-box. |
|
8748 |
It could also be put into some logfile or printed on the standard output/error." |
|
8749 |
||
8750 |
ActivityNotificationSignal isHandled ifTrue:[ |
|
6654 | 8751 |
^ ActivityNotificationSignal raiseRequestWith:self errorString:aString |
5755 | 8752 |
]. |
8753 |
||
8754 |
" |
|
8755 |
nil activityNotification:'hello there' |
|
8756 |
self activityNotification:'hello there' |
|
8757 |
" |
|
8758 |
||
8759 |
" |
|
8760 |
ActivityNotificationSignal handle:[:ex | |
|
6654 | 8761 |
ex errorString printNL. |
8762 |
ex proceed. |
|
5755 | 8763 |
] do:[ |
6654 | 8764 |
'hello' printNL. |
8765 |
self activityNotification:'doing some long time computation'. |
|
8766 |
'world' printNL. |
|
5755 | 8767 |
] |
8768 |
" |
|
8769 |
||
8770 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
8771 |
! |
|
8772 |
||
8773 |
confirm:aString |
|
8774 |
"launch a confirmer, which allows user to enter yes or no. |
|
8775 |
return true for yes, false for no. |
|
8776 |
If no GUI is present (headless applications), true is returned." |
|
8777 |
||
8778 |
" |
|
8779 |
on systems without GUI, or during startup, output a message |
|
8780 |
and return true (as if yes was answered) |
|
8781 |
Q: should we ask user by reading Stdin ? |
|
8782 |
" |
|
8783 |
Smalltalk isInitialized ifFalse:[ |
|
6654 | 8784 |
'*** confirmation requested during initialization:' errorPrintCR. |
8785 |
aString errorPrintCR. |
|
8786 |
'*** I''ll continue, assuming <yes> ...' errorPrintCR. |
|
8787 |
^ true |
|
5755 | 8788 |
]. |
8789 |
||
8790 |
(Dialog isNil |
|
8791 |
or:[Screen isNil |
|
8792 |
or:[Screen current isNil |
|
8793 |
or:[Screen current isOpen not]]]) ifTrue:[ |
|
6654 | 8794 |
'confirm: ' infoPrint. |
8795 |
aString infoPrintCR. |
|
8796 |
'continue, assuming <yes>' infoPrintCR. |
|
8797 |
^ true |
|
5755 | 8798 |
]. |
8799 |
||
8800 |
Dialog autoload. "in case its autoloaded" |
|
8801 |
^ Dialog confirm:aString |
|
8802 |
||
8803 |
" |
|
8804 |
nil confirm:'hello' |
|
8805 |
self confirm:'hello' |
|
8806 |
" |
|
8807 |
||
8808 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8809 |
! |
|
8810 |
||
8811 |
confirm:aString orCancel:cancelBlock |
|
8812 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8813 |
return true for yes, false for no, or the value from cancelBlock for cancel. |
|
8814 |
If no GUI is present (headless applications), cancelBlock is returned." |
|
8815 |
||
8816 |
|answer| |
|
8817 |
||
8818 |
answer := self confirmWithCancel:aString. |
|
8819 |
answer isNil ifTrue:[ |
|
6654 | 8820 |
^ cancelBlock value |
5755 | 8821 |
]. |
8822 |
^ answer |
|
8823 |
||
8824 |
" |
|
8825 |
self confirm:'hello' orCancel:[self halt] |
|
8826 |
" |
|
8827 |
||
8828 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8829 |
! |
|
8830 |
||
8831 |
confirmWithCancel:aString |
|
8832 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8833 |
return true for yes, false for no, nil for cancel. |
|
8834 |
If no GUI is present (headless applications), nil is returned." |
|
8835 |
||
8836 |
" |
|
8837 |
on systems without GUI, or during startup, output a message |
|
8838 |
and return true (as if yes was answered) |
|
8839 |
Q: should we ask user by reading Stdin ? |
|
8840 |
" |
|
8841 |
Smalltalk isInitialized ifFalse:[ |
|
6654 | 8842 |
'*** confirmation requested during initialization:' errorPrintCR. |
8843 |
aString errorPrintCR. |
|
8844 |
'*** I''ll continue, assuming <cancel> ...' errorPrintCR. |
|
8845 |
^ nil |
|
5755 | 8846 |
]. |
8847 |
||
8848 |
(Dialog isNil |
|
8849 |
or:[Screen isNil |
|
8850 |
or:[Screen current isNil |
|
8851 |
or:[Screen current isOpen not]]]) ifTrue:[ |
|
6654 | 8852 |
'confirm: ' infoPrint. |
8853 |
aString infoPrintCR. |
|
8854 |
'continue, assuming <cancel>' infoPrintCR. |
|
8855 |
^ nil |
|
5755 | 8856 |
]. |
8857 |
||
8858 |
Dialog autoload. "in case its autoloaded" |
|
8859 |
^ Dialog confirmWithCancel:aString |
|
8860 |
||
8861 |
" |
|
8862 |
nil confirmWithCancel:'hello' |
|
8863 |
self confirmWithCancel:'hello' |
|
8864 |
" |
|
8865 |
||
8866 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8867 |
! |
|
8868 |
||
8869 |
errorNotify:aString |
|
8870 |
"launch a Notifier, showing top stack, telling user something |
|
8871 |
and give user a chance to enter debugger." |
|
8872 |
||
8873 |
^ self |
|
6654 | 8874 |
errorNotify:aString |
8875 |
from:thisContext sender |
|
8876 |
allowDebug:true |
|
5755 | 8877 |
|
8878 |
" |
|
8879 |
nil errorNotify:'hello there' |
|
8880 |
self errorNotify:'hello there' |
|
8881 |
" |
|
8882 |
||
6199 | 8883 |
"Modified: / 16.11.2001 / 15:36:49 / cg" |
5755 | 8884 |
! |
8885 |
||
8886 |
errorNotify:aString from:aContext |
|
8887 |
"launch a Notifier, showing top stack (above aContext), |
|
8888 |
telling user something and give user a chance to enter debugger." |
|
8889 |
||
8890 |
^ self errorNotify:aString from:aContext allowDebug:true |
|
8891 |
||
8892 |
"Modified: / 17.8.1998 / 10:09:27 / cg" |
|
8893 |
! |
|
8894 |
||
8895 |
errorNotify:aString from:aContext allowDebug:allowDebug |
|
8896 |
"launch a Notifier, showing top stack (above aContext), |
|
8897 |
telling user something and optionally give the user a chance to enter debugger." |
|
8898 |
||
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8899 |
|currentScreen con sender action boxLabels boxValues default| |
5755 | 8900 |
|
8901 |
Smalltalk isInitialized ifFalse:[ |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8902 |
'errorNotification: ' print. aString printCR. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8903 |
^ self |
5755 | 8904 |
]. |
8905 |
(Dialog isNil |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8906 |
or:[Screen isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8907 |
or:[(currentScreen := Screen current) isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8908 |
or:[currentScreen isOpen not]]]) ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8909 |
" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8910 |
on systems without GUI, simply show |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8911 |
the message on the Transcript and abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8912 |
" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8913 |
Transcript showCR:aString. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8914 |
AbortSignal raise. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8915 |
^ self |
5755 | 8916 |
]. |
8917 |
||
8918 |
Processor activeProcessIsSystemProcess ifTrue:[ |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8919 |
action := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8920 |
sender := aContext. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8921 |
Debugger isNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8922 |
'****************** Cought Error while in SystemProcess ****************' errorPrintCR. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8923 |
thisContext fullPrintAll. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8924 |
action := #abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8925 |
]. |
5755 | 8926 |
] ifFalse:[ |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8927 |
Dialog autoload. "in case it's autoloaded" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8928 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8929 |
Error handle:[:ex | |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8930 |
"/ a recursive error - quickly enter debugger |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8931 |
"/ this happened, when I corrupted the Dialog class ... |
7208 | 8932 |
('Object [error]: ' , ex description , ' caught in errorNotification') errorPrintCR. |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8933 |
action := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8934 |
ex return. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8935 |
] do:[ |s| |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8936 |
sender := aContext. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8937 |
sender isNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8938 |
sender := thisContext sender. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8939 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8940 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8941 |
"/ skip intermediate (signal & exception) contexts |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8942 |
DebugView notNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8943 |
sender := DebugView interestingContextFrom:sender |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8944 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8945 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8946 |
"/ show the first few contexts |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8947 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8948 |
s := WriteStream with:aString. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8949 |
s cr; cr. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8950 |
con := sender. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8951 |
1 to:15 do:[:n | |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8952 |
con notNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8953 |
con printOn:s. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8954 |
s cr. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8955 |
con := con sender |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8956 |
] |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8957 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8958 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8959 |
(allowDebug and:[Debugger notNil]) ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8960 |
boxLabels := #('Proceed' 'Abort' 'Copy Trace and Abort' 'Debug'). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8961 |
boxValues := #(#proceed #abort #copy #debug). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8962 |
default := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8963 |
] ifFalse:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8964 |
boxLabels := #('Proceed' 'Abort' 'Copy Trace and Abort'). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8965 |
boxValues := #(#proceed #abort #copy). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8966 |
default := #abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8967 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8968 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8969 |
action := Dialog |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8970 |
choose:s contents |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8971 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8972 |
image:WarningBox errorIconBitmap |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8973 |
labels:boxLabels |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8974 |
values:boxValues |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8975 |
default:default |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8976 |
onCancel:nil. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8977 |
]. |
5755 | 8978 |
]. |
8979 |
||
8980 |
action == #debug ifTrue:[ |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8981 |
Debugger enter:sender withMessage:aString mayProceed:true |
5755 | 8982 |
] ifFalse:[ |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8983 |
action == #proceed ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8984 |
^ self. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8985 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8986 |
action == #copy ifTrue:[ |s| |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8987 |
s := '' writeStream. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8988 |
sender fullPrintAllOn:s. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8989 |
currentScreen rootView setTextSelection:s contents. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8990 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8991 |
AbortSignal raise |
5755 | 8992 |
] |
8993 |
||
8994 |
" |
|
8995 |
nil errorNotify:'hello there' |
|
8996 |
self errorNotify:'hello there' |
|
8997 |
" |
|
8998 |
||
8999 |
"Created: / 17.8.1998 / 10:09:26 / cg" |
|
6199 | 9000 |
"Modified: / 16.11.2001 / 15:40:12 / cg" |
5755 | 9001 |
! |
9002 |
||
9003 |
information:aString |
|
9004 |
"launch an InfoBox, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9005 |
These info-boxes can be suppressed by handling |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9006 |
UserNotification or InformationSignal and proceeding in the handler. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9007 |
Use #notify: for more important messages. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9008 |
If nobody handles the exception, the dafault action of UserNotification |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9009 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9010 |
|
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
9011 |
UserInformation raiseRequestWith:self errorString:aString |
5755 | 9012 |
|
9013 |
" |
|
9014 |
nil information:'hello there' |
|
9015 |
self information:'hello there' |
|
9016 |
" |
|
9017 |
||
9018 |
" |
|
9019 |
InformationSignal handle:[:ex | |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9020 |
'no box popped' printCR. |
6654 | 9021 |
ex proceed. |
5755 | 9022 |
] do:[ |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9023 |
'hello' printCR. |
6654 | 9024 |
self information:'some info'. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9025 |
'world' printCR. |
5755 | 9026 |
] |
9027 |
" |
|
9028 |
||
9029 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
9030 |
! |
|
9031 |
||
9032 |
notify:aString |
|
9033 |
"launch a Notifier, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9034 |
Use #information: for ignorable messages. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9035 |
If nobody handles the exception, the dafault action of UserNotification |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9036 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9037 |
|
5755 | 9038 |
|
9039 |
Smalltalk isInitialized ifFalse:[ |
|
6656 | 9040 |
"/ thisContext fullPrintAll. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9041 |
'information: ' print. aString printCR. |
6654 | 9042 |
^ self |
5755 | 9043 |
]. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9044 |
UserNotification raiseRequestWith:self errorString:aString. |
5755 | 9045 |
|
9046 |
" |
|
9047 |
nil notify:'hello there' |
|
9048 |
self notify:'hello there' |
|
9049 |
" |
|
9050 |
||
9051 |
"Modified: 20.5.1996 / 10:28:48 / cg" |
|
9052 |
! |
|
9053 |
||
9054 |
warn:aString |
|
9055 |
"launch a WarningBox, telling user something. |
|
9056 |
These warn-boxes can be suppressed by handling the |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9057 |
UserNotification- or WarningSignal and proceeding in the handler. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9058 |
If nobody handles the exception, the dafault action of Warning |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9059 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9060 |
|
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9061 |
Warning raiseRequestWith:self errorString:aString |
5755 | 9062 |
|
9063 |
" |
|
9064 |
nil warn:'hello there' |
|
9065 |
self warn:'hello there' |
|
9066 |
" |
|
9067 |
||
9068 |
" |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9069 |
Warning handle:[:ex | |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9070 |
Transcript showCR:ex description. |
6654 | 9071 |
ex proceed. |
5755 | 9072 |
] do:[ |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9073 |
'hello' printCR. |
6654 | 9074 |
self warn:'some info'. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9075 |
'world' printCR. |
5755 | 9076 |
] |
9077 |
" |
|
9078 |
||
9079 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
|
9080 |
! ! |
|
9081 |
||
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
9082 |
|
5755 | 9083 |
!Object class methodsFor:'documentation'! |
1 | 9084 |
|
5754 | 9085 |
version |
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
9086 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.466 2003-05-14 12:17:44 stefan Exp $' |
1 | 9087 |
! ! |
6764 | 9088 |
|
5755 | 9089 |
Object initialize! |