author | Claus Gittinger <cg@exept.de> |
Wed, 07 May 2003 17:16:08 +0200 | |
changeset 7266 | f2b64d3b43cf |
parent 7261 | f35fc9cee675 |
child 7285 | 76ff65cdd7e7 |
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 |
||
694 |
!Object methodsFor:'accessing'! |
|
695 |
||
696 |
at:index |
|
697 |
"return the indexed instance variable with index, anInteger; |
|
698 |
this method can be redefined in subclasses." |
|
699 |
||
700 |
^ self basicAt:index |
|
701 |
! |
|
702 |
||
703 |
at:index put:anObject |
|
704 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
705 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
|
706 |
||
707 |
^ self basicAt:index put:anObject |
|
708 |
||
709 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
|
710 |
! |
|
711 |
||
712 |
basicAt:index |
|
713 |
"return the indexed instance variable with index, anInteger. |
|
714 |
Trigger an error if the receiver has no indexed instance variables. |
|
715 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
716 |
||
717 |
%{ /* NOCONTEXT */ |
|
718 |
||
719 |
REGISTER int nbytes, indx; |
|
720 |
OBJ myClass; |
|
721 |
REGISTER char *pFirst; |
|
722 |
#ifdef alpha64 |
|
723 |
# define int32 int |
|
724 |
#else |
|
725 |
# define int32 long |
|
726 |
#endif |
|
727 |
REGISTER int n; |
|
728 |
||
729 |
/* |
|
730 |
* notice the missing test for self being a nonNilObject - |
|
731 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
732 |
* and SmallInteger |
|
733 |
*/ |
|
734 |
if (__isSmallInteger(index)) { |
|
6654 | 735 |
myClass = __qClass(self); |
736 |
indx = __intVal(index) - 1; |
|
737 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
738 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
739 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
740 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
741 |
||
742 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
743 |
case __MASKSMALLINT(POINTERARRAY): |
|
744 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
745 |
/* |
|
746 |
* pointers |
|
747 |
*/ |
|
748 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
749 |
OBJ *op; |
|
750 |
||
751 |
op = (OBJ *)pFirst + indx; |
|
752 |
RETURN ( *op ); |
|
753 |
} |
|
754 |
break; |
|
755 |
||
756 |
case __MASKSMALLINT(BYTEARRAY): |
|
757 |
/* |
|
758 |
* (unsigned) bytes |
|
759 |
*/ |
|
760 |
if ((unsigned)indx < nbytes) { |
|
761 |
unsigned char *cp; |
|
762 |
||
763 |
cp = (unsigned char *)pFirst + indx; |
|
764 |
RETURN ( __MKSMALLINT( (INT)(*cp & 0xFF)) ); |
|
765 |
} |
|
766 |
break; |
|
767 |
||
768 |
case __MASKSMALLINT(FLOATARRAY): |
|
769 |
/* |
|
770 |
* native floats |
|
771 |
*/ |
|
772 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
773 |
float *fp; |
|
774 |
float f; |
|
775 |
OBJ v; |
|
776 |
||
777 |
fp = (float *)pFirst + indx; |
|
778 |
f = *fp; |
|
779 |
if (f == 0.0) { |
|
780 |
v = __float0; |
|
781 |
} else { |
|
782 |
__qMKSFLOAT(v, f); |
|
783 |
} |
|
784 |
RETURN (v); |
|
785 |
} |
|
786 |
break; |
|
787 |
||
788 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
789 |
/* |
|
790 |
* native doubles |
|
791 |
*/ |
|
5755 | 792 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 793 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
794 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
795 |
||
796 |
pFirst += delta; |
|
797 |
nbytes -= delta; |
|
798 |
} |
|
5755 | 799 |
#endif |
6654 | 800 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
801 |
double *dp; |
|
802 |
double d; |
|
803 |
OBJ v; |
|
804 |
||
805 |
dp = (double *)pFirst + indx; |
|
806 |
d = *dp; |
|
807 |
if (d == 0.0) { |
|
808 |
v = __float0; |
|
809 |
} else { |
|
810 |
__qMKFLOAT(v, d); |
|
811 |
} |
|
812 |
RETURN (v); |
|
813 |
} |
|
814 |
break; |
|
815 |
||
816 |
case __MASKSMALLINT(WORDARRAY): |
|
817 |
/* |
|
818 |
* unsigned 16bit ints |
|
819 |
*/ |
|
820 |
/* Notice: the hard coded shifts are by purpose; |
|
821 |
* it makes us independent of the short-size of the machine |
|
822 |
*/ |
|
823 |
if ((unsigned)indx < (nbytes>>1)) { |
|
824 |
unsigned short *sp; |
|
825 |
||
826 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
827 |
RETURN ( __MKSMALLINT( (INT)(*sp & 0xFFFF)) ); |
|
828 |
} |
|
829 |
break; |
|
830 |
||
831 |
case __MASKSMALLINT(SWORDARRAY): |
|
832 |
/* |
|
833 |
* signed 16bit ints |
|
834 |
*/ |
|
835 |
/* Notice: the hard coded shifts are by purpose; |
|
836 |
* it makes us independent of the short-size of the machine |
|
837 |
*/ |
|
838 |
if ((unsigned)indx < (nbytes>>1)) { |
|
839 |
short *ssp; |
|
840 |
||
841 |
ssp = (short *)(pFirst + (indx<<1)); |
|
842 |
RETURN ( __MKSMALLINT( (INT)(*ssp) )); |
|
843 |
} |
|
844 |
break; |
|
845 |
||
846 |
case __MASKSMALLINT(LONGARRAY): |
|
847 |
/* |
|
848 |
* unsigned 32bit ints |
|
849 |
*/ |
|
850 |
/* Notice: the hard coded shifts are by purpose; |
|
851 |
* it makes us independent of the int-size of the machine |
|
852 |
*/ |
|
853 |
if ((unsigned)indx < (nbytes>>2)) { |
|
854 |
unsigned int32 ul; |
|
855 |
unsigned int32 *lp; |
|
856 |
||
857 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
858 |
ul = *lp; |
|
5755 | 859 |
#ifdef alpha64 |
6654 | 860 |
{ |
861 |
unsigned INT ull = (unsigned INT)ul; |
|
862 |
RETURN ( __MKSMALLINT(ull) ); |
|
863 |
} |
|
5755 | 864 |
#else |
6654 | 865 |
if (ul <= _MAX_INT) { |
866 |
RETURN ( __MKSMALLINT(ul) ); |
|
867 |
} |
|
868 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 869 |
#endif |
6654 | 870 |
} |
871 |
break; |
|
872 |
||
873 |
case __MASKSMALLINT(SLONGARRAY): |
|
874 |
/* |
|
875 |
* signed 32bit ints |
|
876 |
*/ |
|
877 |
/* Notice: the hard coded shifts are by purpose; |
|
878 |
* it makes us independent of the int-size of the machine |
|
879 |
*/ |
|
880 |
if ((unsigned)indx < (nbytes>>2)) { |
|
881 |
int32 *slp; |
|
882 |
int32 l; |
|
883 |
||
884 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
885 |
l = *slp; |
|
5755 | 886 |
#ifdef alpha64 |
6654 | 887 |
{ |
888 |
INT ll = (INT)l; |
|
889 |
RETURN ( __MKSMALLINT(ll) ); |
|
890 |
} |
|
5755 | 891 |
#else |
6654 | 892 |
if (__ISVALIDINTEGER(l)) { |
893 |
RETURN ( __MKSMALLINT(l) ); |
|
894 |
} |
|
895 |
RETURN ( __MKLARGEINT(l) ); |
|
5755 | 896 |
#endif |
6654 | 897 |
} |
898 |
break; |
|
899 |
||
900 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
901 |
/* |
|
902 |
* signed 64bit longlongs |
|
903 |
*/ |
|
5755 | 904 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 905 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
906 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
907 |
||
908 |
pFirst += delta; |
|
909 |
nbytes -= delta; |
|
910 |
} |
|
5755 | 911 |
#endif |
6654 | 912 |
/* Notice: the hard coded shifts are by purpose; |
913 |
* it makes us independent of the long/longlong-size of the machine |
|
914 |
*/ |
|
915 |
if ((unsigned)indx < (nbytes>>3)) { |
|
5755 | 916 |
#ifdef alpha64 |
6654 | 917 |
INT *slp, ll; |
918 |
||
919 |
slp = (INT *)(pFirst + (indx<<3)); |
|
920 |
ll = *slp; |
|
921 |
if (__ISVALIDINTEGER(ll)) { |
|
922 |
RETURN ( __MKSMALLINT(ll) ); |
|
923 |
} |
|
924 |
RETURN ( __MKLARGEINT(ll) ); |
|
5755 | 925 |
#else |
6654 | 926 |
__int64__ *llp; |
927 |
extern OBJ __MKINT64(); |
|
928 |
||
929 |
llp = (__int64__ *)(pFirst + (indx<<3)); |
|
930 |
RETURN (__MKINT64(llp)); |
|
5755 | 931 |
#endif |
6654 | 932 |
} |
933 |
break; |
|
934 |
||
935 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
936 |
/* |
|
937 |
* unsigned 64bit longlongs |
|
938 |
*/ |
|
5755 | 939 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 940 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
941 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
942 |
||
943 |
pFirst += delta; |
|
944 |
nbytes -= delta; |
|
945 |
} |
|
5755 | 946 |
#endif |
6654 | 947 |
/* Notice: the hard coded shifts are by purpose; |
948 |
* it makes us independent of the long/longlong-size of the machine |
|
949 |
*/ |
|
950 |
if ((unsigned)indx < (nbytes>>3)) { |
|
5755 | 951 |
#ifdef alpha64 |
6654 | 952 |
unsigned INT *ulp, ul; |
953 |
||
954 |
ulp = (unsigned INT *)(pFirst + (indx<<3)); |
|
955 |
ul = *ulp; |
|
956 |
if (ul <= _MAX_INT) { |
|
957 |
RETURN ( __MKSMALLINT(ul) ); |
|
958 |
} |
|
959 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 960 |
#else |
6654 | 961 |
__uint64__ *llp; |
962 |
extern OBJ __MKUINT64(); |
|
963 |
||
964 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
965 |
RETURN (__MKUINT64(llp)); |
|
5755 | 966 |
#endif |
6654 | 967 |
} |
968 |
break; |
|
969 |
} |
|
5755 | 970 |
} |
971 |
||
972 |
# undef int32 |
|
973 |
||
974 |
%}. |
|
7216 | 975 |
^ self indexNotIntegerOrOutOfBounds:index |
5755 | 976 |
! |
977 |
||
978 |
basicAt:index put:anObject |
|
979 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
980 |
Returns anObject (sigh). |
|
981 |
Trigger an error if the receiver has no indexed instance variables. |
|
982 |
||
983 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
984 |
||
985 |
%{ /* NOCONTEXT */ |
|
986 |
||
987 |
register int nbytes, indx; |
|
988 |
OBJ myClass; |
|
989 |
register char *pFirst; |
|
990 |
#ifdef alpha64 |
|
991 |
# define int32 int |
|
992 |
#else |
|
993 |
# define int32 long |
|
994 |
#endif |
|
995 |
/* int nInstBytes, ninstvars, flags; */ |
|
996 |
REGISTER int n; |
|
997 |
unsigned int u; |
|
998 |
int val; |
|
999 |
||
1000 |
/* notice the missing test for self being a nonNilObject - |
|
1001 |
this can be done since basicAt: is defined both in UndefinedObject |
|
1002 |
and SmallInteger */ |
|
1003 |
||
1004 |
if (__isSmallInteger(index)) { |
|
6654 | 1005 |
indx = __intVal(index) - 1; |
1006 |
myClass = __qClass(self); |
|
1007 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1008 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
1009 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
1010 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
1011 |
||
1012 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1013 |
case __MASKSMALLINT(POINTERARRAY): |
|
1014 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
1015 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
1016 |
OBJ *op; |
|
1017 |
||
1018 |
op = (OBJ *)pFirst + indx; |
|
1019 |
*op = anObject; |
|
1020 |
__STORE(self, anObject); |
|
1021 |
RETURN ( anObject ); |
|
1022 |
} |
|
1023 |
break; |
|
1024 |
||
1025 |
case __MASKSMALLINT(BYTEARRAY): |
|
1026 |
if (__isSmallInteger(anObject)) { |
|
1027 |
val = __intVal(anObject); |
|
1028 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
1029 |
if ((unsigned)indx < nbytes) { |
|
1030 |
char *cp; |
|
1031 |
||
1032 |
cp = pFirst + indx; |
|
1033 |
*cp = val; |
|
1034 |
RETURN ( anObject ); |
|
1035 |
} |
|
1036 |
} |
|
1037 |
} |
|
1038 |
break; |
|
1039 |
||
1040 |
case __MASKSMALLINT(FLOATARRAY): |
|
1041 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
1042 |
float *fp; |
|
1043 |
||
1044 |
fp = (float *)pFirst + indx; |
|
1045 |
if (anObject != nil) { |
|
1046 |
if (! __isSmallInteger(anObject)) { |
|
1047 |
if (__qIsFloatLike(anObject)) { |
|
1048 |
*fp = (float)(__floatVal(anObject)); |
|
1049 |
RETURN ( anObject ); |
|
1050 |
} |
|
1051 |
if (__qIsShortFloat(anObject)) { |
|
1052 |
*fp = __shortFloatVal(anObject); |
|
1053 |
RETURN ( anObject ); |
|
1054 |
} |
|
1055 |
} else { |
|
1056 |
*fp = (float) __intVal(anObject); |
|
1057 |
RETURN ( anObject ); |
|
1058 |
} |
|
1059 |
} |
|
1060 |
} |
|
1061 |
break; |
|
1062 |
||
1063 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1064 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 1065 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1066 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1067 |
||
1068 |
pFirst += delta; |
|
1069 |
nbytes -= delta; |
|
1070 |
} |
|
5755 | 1071 |
#endif |
6654 | 1072 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
1073 |
double *dp; |
|
1074 |
||
1075 |
dp = (double *)pFirst + indx; |
|
1076 |
if (anObject != nil) { |
|
1077 |
if (! __isSmallInteger(anObject)) { |
|
1078 |
if (__qIsFloatLike(anObject)) { |
|
1079 |
*dp = __floatVal(anObject); |
|
1080 |
RETURN ( anObject ); |
|
1081 |
} |
|
1082 |
if (__qIsShortFloat(anObject)) { |
|
1083 |
*dp = (double)__shortFloatVal(anObject); |
|
1084 |
RETURN ( anObject ); |
|
1085 |
} |
|
1086 |
} else { |
|
1087 |
*dp = (double) __intVal(anObject); |
|
1088 |
RETURN ( anObject ); |
|
1089 |
} |
|
1090 |
} |
|
1091 |
} |
|
1092 |
break; |
|
1093 |
||
1094 |
case __MASKSMALLINT(WORDARRAY): |
|
1095 |
if (__isSmallInteger(anObject)) { |
|
1096 |
val = __intVal(anObject); |
|
1097 |
if ((unsigned)val <= 0xFFFF) { |
|
1098 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1099 |
unsigned short *sp; |
|
1100 |
||
1101 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
1102 |
*sp = val; |
|
1103 |
RETURN ( anObject ); |
|
1104 |
} |
|
1105 |
} |
|
1106 |
} |
|
1107 |
break; |
|
1108 |
||
1109 |
case __MASKSMALLINT(SWORDARRAY): |
|
1110 |
if (__isSmallInteger(anObject)) { |
|
1111 |
val = __intVal(anObject); |
|
1112 |
if ((val >= -32768) && (val < 32768)) { |
|
1113 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1114 |
short *ssp; |
|
1115 |
||
1116 |
ssp = (short *)(pFirst + (indx<<1)); |
|
1117 |
*ssp = val; |
|
1118 |
RETURN ( anObject ); |
|
1119 |
} |
|
1120 |
} |
|
1121 |
} |
|
1122 |
break; |
|
1123 |
||
1124 |
case __MASKSMALLINT(SLONGARRAY): |
|
1125 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1126 |
int32 *slp; |
|
1127 |
||
1128 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
1129 |
if (__isSmallInteger(anObject)) { |
|
1130 |
*slp = __intVal(anObject); |
|
1131 |
RETURN ( anObject ); |
|
1132 |
} |
|
1133 |
n = __signedLongIntVal(anObject); |
|
1134 |
/* |
|
1135 |
* zero means failure for an int larger than 4 bytes |
|
1136 |
* (would be a smallInteger) |
|
1137 |
*/ |
|
1138 |
if (n) { |
|
1139 |
*slp = n; |
|
1140 |
RETURN ( anObject ); |
|
1141 |
} |
|
1142 |
} |
|
1143 |
break; |
|
1144 |
||
1145 |
case __MASKSMALLINT(LONGARRAY): |
|
1146 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1147 |
unsigned int32 *lp; |
|
1148 |
||
1149 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
1150 |
if (anObject == __MKSMALLINT(0)) { |
|
1151 |
*lp = 0; |
|
1152 |
RETURN ( anObject ); |
|
1153 |
} |
|
1154 |
u = __longIntVal(anObject); |
|
1155 |
/* |
|
1156 |
* zero means failure for an int larger than 4 bytes |
|
1157 |
* (would be a smallInteger) |
|
1158 |
*/ |
|
1159 |
if (u) { |
|
1160 |
*lp = u; |
|
1161 |
RETURN ( anObject ); |
|
1162 |
} |
|
1163 |
} |
|
1164 |
break; |
|
1165 |
||
1166 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1167 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1168 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1169 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1170 |
||
1171 |
pFirst += delta; |
|
1172 |
nbytes -= delta; |
|
1173 |
} |
|
5755 | 1174 |
#endif |
6654 | 1175 |
if ((unsigned)indx < (nbytes>>3)) { |
1176 |
__int64__ ll; |
|
1177 |
__int64__ *sllp; |
|
1178 |
||
1179 |
sllp = (__int64__ *)(pFirst + (indx<<3)); |
|
1180 |
||
1181 |
if (anObject == __MKSMALLINT(0)) { |
|
1182 |
ll.lo = ll.hi = 0; |
|
1183 |
*sllp = ll; |
|
1184 |
RETURN ( anObject ); |
|
1185 |
} |
|
1186 |
if (__signedLong64IntVal(anObject, &ll)) { |
|
1187 |
*sllp = ll; |
|
1188 |
RETURN ( anObject ); |
|
1189 |
} |
|
1190 |
} |
|
1191 |
break; |
|
1192 |
||
1193 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
5755 | 1194 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1195 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1196 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1197 |
||
1198 |
pFirst += delta; |
|
1199 |
nbytes -= delta; |
|
1200 |
} |
|
5755 | 1201 |
#endif |
6654 | 1202 |
if ((unsigned)indx < (nbytes>>3)) { |
1203 |
__uint64__ ll; |
|
1204 |
__uint64__ *llp; |
|
1205 |
||
1206 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
1207 |
if (anObject == __MKSMALLINT(0)) { |
|
1208 |
ll.lo = ll.hi = 0; |
|
1209 |
*llp = ll; |
|
1210 |
RETURN ( anObject ); |
|
1211 |
} |
|
1212 |
if (__unsignedLong64IntVal(anObject, &ll)) { |
|
1213 |
*llp = ll; |
|
1214 |
RETURN ( anObject ); |
|
1215 |
} |
|
1216 |
} |
|
1217 |
break; |
|
1218 |
} |
|
5755 | 1219 |
} |
1220 |
||
1221 |
# undef int32 |
|
1222 |
||
1223 |
%}. |
|
1224 |
index isInteger ifFalse:[ |
|
6654 | 1225 |
" |
1226 |
the index should be an integer number |
|
1227 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1228 |
^ self indexNotInteger:index |
5755 | 1229 |
]. |
1230 |
(index between:1 and:self size) ifFalse:[ |
|
6654 | 1231 |
" |
1232 |
the index is less than 1 or greater than the size of the |
|
1233 |
receiver collection |
|
1234 |
" |
|
1235 |
^ self subscriptBoundsError:index |
|
5755 | 1236 |
]. |
1237 |
(self class isFloatsOrDoubles) ifTrue:[ |
|
6654 | 1238 |
anObject isNumber ifTrue:[ |
1239 |
^ self basicAt:index put:(anObject asFloat) |
|
1240 |
] |
|
5755 | 1241 |
]. |
1242 |
anObject isInteger ifFalse:[ |
|
6654 | 1243 |
" |
1244 |
the object to put into the receiver collection |
|
1245 |
should be an integer number |
|
1246 |
" |
|
1247 |
^ self elementNotInteger |
|
5755 | 1248 |
]. |
1249 |
" |
|
1250 |
the object to put into the receiver collection |
|
1251 |
is not an instance of the expected element class, |
|
1252 |
or the value is not within the elements valid range. |
|
1253 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1254 |
^ self elementBoundsError:anObject |
5755 | 1255 |
|
1256 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
|
1257 |
! |
|
1258 |
||
1259 |
byteAt:index |
|
1260 |
"return the byte at index. |
|
1261 |
This is only allowed for non-pointer indexed objects |
|
1262 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1263 |
The receivers indexed instvars are treated as an uninterpreted |
|
1264 |
collection of bytes. |
|
1265 |
Only useful with binary storage." |
|
1266 |
||
1267 |
%{ /* NOCONTEXT */ |
|
1268 |
||
1269 |
REGISTER int indx; |
|
1270 |
int nIndex; |
|
1271 |
REGISTER OBJ slf; |
|
1272 |
REGISTER OBJ cls; |
|
1273 |
||
1274 |
if (__isSmallInteger(index)) { |
|
6654 | 1275 |
slf = self; |
1276 |
if (__isNonNilObject(slf)) { |
|
1277 |
unsigned char *pFirst; |
|
1278 |
int nIndex; |
|
1279 |
||
1280 |
cls = __qClass(slf); |
|
1281 |
||
1282 |
pFirst = __byteArrayVal(slf); |
|
1283 |
pFirst += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1284 |
nIndex = __byteArraySize(slf); |
|
1285 |
indx = __intVal(index) - 1; |
|
1286 |
||
1287 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1288 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1289 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 1290 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1291 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1292 |
||
1293 |
pFirst += delta; |
|
1294 |
nIndex -= delta; |
|
1295 |
} |
|
5755 | 1296 |
#endif |
6654 | 1297 |
/* fall into */ |
1298 |
case __MASKSMALLINT(BYTEARRAY): |
|
1299 |
case __MASKSMALLINT(WORDARRAY): |
|
1300 |
case __MASKSMALLINT(LONGARRAY): |
|
1301 |
case __MASKSMALLINT(SWORDARRAY): |
|
1302 |
case __MASKSMALLINT(SLONGARRAY): |
|
1303 |
case __MASKSMALLINT(FLOATARRAY): |
|
1304 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1305 |
RETURN ( __MKSMALLINT( (INT)(pFirst[indx])) ); |
|
1306 |
} |
|
1307 |
break; |
|
1308 |
||
1309 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1310 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1311 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1312 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1313 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1314 |
||
1315 |
pFirst += delta; |
|
1316 |
nIndex -= delta; |
|
1317 |
} |
|
5755 | 1318 |
#endif |
6654 | 1319 |
if ((unsigned)indx < (unsigned)nIndex) { |
1320 |
RETURN ( __MKSMALLINT( (INT)(pFirst[indx])) ); |
|
1321 |
} |
|
1322 |
break; |
|
1323 |
} |
|
1324 |
} |
|
5755 | 1325 |
} |
1326 |
%}. |
|
1327 |
"/ index not integer or index out of range |
|
1328 |
"/ or non-byte indexable receiver |
|
1329 |
||
1330 |
^ self primitiveFailed |
|
1331 |
||
1332 |
" |
|
1333 |
Point new byteAt:1 |
|
1334 |
(ByteArray with:1 with:2) byteAt:2 |
|
1335 |
(WordArray with:1) byteAt:1 |
|
1336 |
(FloatArray with:1.0) byteAt:2 |
|
1337 |
'hello' byteAt:1 |
|
1338 |
" |
|
1339 |
! |
|
1340 |
||
1341 |
byteAt:index put:byteValue |
|
1342 |
"set the byte at index. |
|
1343 |
This is only allowed for non-pointer indexed objects |
|
1344 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1345 |
The receivers indexed instvars are treated as an uninterpreted |
|
1346 |
collection of bytes. |
|
1347 |
Only useful with binary storage." |
|
1348 |
||
1349 |
%{ /* NOCONTEXT */ |
|
1350 |
||
1351 |
REGISTER int indx; |
|
1352 |
int val, nIndex; |
|
1353 |
REGISTER OBJ slf; |
|
1354 |
REGISTER OBJ cls; |
|
1355 |
||
1356 |
if (__bothSmallInteger(index, byteValue)) { |
|
6654 | 1357 |
val = __intVal(byteValue); |
1358 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
1359 |
slf = self; |
|
1360 |
if (__isNonNilObject(slf)) { |
|
1361 |
cls = __qClass(slf); |
|
1362 |
||
1363 |
indx = __intVal(index) - 1; |
|
1364 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1365 |
case __MASKSMALLINT(BYTEARRAY): |
|
1366 |
case __MASKSMALLINT(WORDARRAY): |
|
1367 |
case __MASKSMALLINT(LONGARRAY): |
|
1368 |
case __MASKSMALLINT(SWORDARRAY): |
|
1369 |
case __MASKSMALLINT(SLONGARRAY): |
|
1370 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1371 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1372 |
case __MASKSMALLINT(FLOATARRAY): |
|
1373 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
1374 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1375 |
nIndex = __byteArraySize(slf); |
|
1376 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1377 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
1378 |
RETURN ( byteValue ); |
|
1379 |
} |
|
1380 |
break; |
|
1381 |
} |
|
1382 |
} |
|
1383 |
} |
|
5755 | 1384 |
} |
1385 |
%}. |
|
1386 |
"/ index not integer or index out of range |
|
1387 |
"/ or non-byte indexable receiver |
|
1388 |
||
1389 |
^ self primitiveFailed |
|
1390 |
||
1391 |
" |
|
1392 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
|
1393 |
'hello' copy byteAt:1 put:105; yourself |
|
1394 |
" |
|
1395 |
! |
|
1396 |
||
1397 |
instVarAt:index |
|
1398 |
"return a non-indexed instance variable; |
|
1399 |
peeking into an object this way is not very object oriented |
|
1400 |
- use with care (needed for copy, inspector etc.)" |
|
1401 |
||
1402 |
%{ /* NOCONTEXT */ |
|
1403 |
||
1404 |
OBJ myClass; |
|
1405 |
int idx, ninstvars; |
|
1406 |
||
1407 |
if (__isSmallInteger(index)) { |
|
6654 | 1408 |
myClass = __Class(self); |
1409 |
idx = __intVal(index) - 1; |
|
1410 |
/* |
|
1411 |
* do not allow returning of non-object fields. |
|
1412 |
* if subclass did not make privisions for that, |
|
1413 |
* we wont do so here ... |
|
1414 |
*/ |
|
1415 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1416 |
if (idx == 0) { |
|
1417 |
RETURN ( nil ) |
|
1418 |
} |
|
1419 |
} |
|
1420 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1421 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1422 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
|
1423 |
} |
|
5755 | 1424 |
} |
7216 | 1425 |
%}. |
1426 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1427 |
! |
1428 |
||
1429 |
instVarAt:index put:value |
|
1430 |
"change a non-indexed instance variable; |
|
1431 |
peeking into an object this way is not very object oriented |
|
1432 |
- use with care (needed for copy, inspector etc.)" |
|
1433 |
||
1434 |
%{ /* NOCONTEXT */ |
|
1435 |
||
1436 |
OBJ myClass; |
|
1437 |
int idx, ninstvars; |
|
1438 |
||
1439 |
if (__isSmallInteger(index)) { |
|
6654 | 1440 |
myClass = __Class(self); |
1441 |
idx = __intVal(index) - 1; |
|
1442 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1443 |
/* |
|
1444 |
* do not allow setting of non-object fields. |
|
1445 |
* if subclass did not make privisions for that, |
|
1446 |
* we wont do so here ... |
|
1447 |
*/ |
|
1448 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1449 |
if (idx == 0) { |
|
1450 |
RETURN ( nil ) |
|
1451 |
} |
|
1452 |
} |
|
1453 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1454 |
__InstPtr(self)->i_instvars[idx] = value; |
|
1455 |
__STORE(self, value); |
|
1456 |
RETURN ( value ); |
|
1457 |
} |
|
5755 | 1458 |
} |
7216 | 1459 |
%}. |
1460 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1461 |
! |
1462 |
||
1463 |
instVarNamed:name |
|
1464 |
"return a non-indexed instance variables value by name; |
|
1465 |
peeking into an object this way is not very object oriented |
|
1466 |
- use with care if at all (provided for inspectors and memory usage monitor). |
|
1467 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1468 |
parsed ad runtime)" |
|
1469 |
||
1470 |
^ self instVarAt:(self class instVarOffsetOf:name) |
|
1471 |
||
1472 |
||
1473 |
" |
|
1474 |
|p| |
|
1475 |
||
1476 |
p := Point x:10 y:20. |
|
1477 |
p instVarNamed:'x' |
|
1478 |
" |
|
1479 |
||
1480 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
|
1481 |
! |
|
1482 |
||
1483 |
instVarNamed:name ifAbsent:exceptionBlock |
|
1484 |
"return a non-indexed instance variables value by name, |
|
1485 |
or the value of exceptionBlock, if there is no such instance variable. |
|
1486 |
peeking into an object this way is not very object oriented |
|
1487 |
- use with care if at all (provided for inspectors and memory usage monitor). |
|
1488 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1489 |
parsed ad runtime)" |
|
1490 |
||
1491 |
|idx| |
|
1492 |
||
1493 |
idx := self class instVarOffsetOf:name. |
|
1494 |
idx isNil ifTrue:[^ exceptionBlock value]. |
|
1495 |
^ self instVarAt:idx |
|
1496 |
||
1497 |
||
1498 |
" |
|
1499 |
|p| |
|
1500 |
||
1501 |
p := Point x:10 y:20. |
|
1502 |
p instVarNamed:'x' |
|
1503 |
" |
|
1504 |
||
1505 |
"Created: 6.7.1996 / 23:02:49 / cg" |
|
1506 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
|
1507 |
! |
|
1508 |
||
1509 |
instVarNamed:name put:value |
|
1510 |
"set a non-indexed instance variable by name; |
|
1511 |
peeking into an object this way is not very object oriented |
|
1512 |
- if at all, use with care (provided for protocol completeness). |
|
1513 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1514 |
parsed ad runtime)" |
|
1515 |
||
1516 |
^ self instVarAt:(self class instVarOffsetOf:name) put:value |
|
1517 |
||
1518 |
" |
|
1519 |
|p| |
|
1520 |
||
1521 |
p := Point x:10 y:20. |
|
1522 |
p instVarNamed:'x' put:30. |
|
1523 |
p |
|
1524 |
" |
|
1525 |
||
1526 |
"Modified: 19.4.1996 / 11:12:49 / cg" |
|
1527 |
! ! |
|
1528 |
||
1529 |
!Object methodsFor:'attributes access'! |
|
1530 |
||
6323 | 1531 |
objectAttributeAt:attributeKey |
5755 | 1532 |
"return the attribute for a given key or nil if not found" |
1533 |
||
1534 |
| attrs | |
|
1535 |
||
1536 |
attrs := self objectAttributes. |
|
1537 |
(attrs notNil and:[attrs size > 0]) ifTrue:[ |
|
6654 | 1538 |
^ attrs at:attributeKey ifAbsent:[] |
5755 | 1539 |
]. |
1540 |
^ nil |
|
1541 |
||
1542 |
"Created: / 22.1.1998 / 21:29:17 / av" |
|
1543 |
"Modified: / 3.2.1998 / 18:55:55 / cg" |
|
1544 |
! |
|
1545 |
||
6323 | 1546 |
objectAttributeAt:attributeKey put:anObject |
5755 | 1547 |
"store the attribute anObject referenced by key into the receiver" |
1548 |
||
1549 |
"/ must do this save from interrupts, since the attributes collection |
|
1550 |
"/ is possibly accessed from multiple threads ... |
|
1551 |
[ |
|
6654 | 1552 |
| attrs | |
1553 |
||
1554 |
attrs := self objectAttributes. |
|
1555 |
(attrs isNil or:[attrs size == 0]) ifTrue:[ |
|
1556 |
attrs := WeakIdentityDictionary new. |
|
1557 |
attrs at:attributeKey put:anObject. |
|
1558 |
self objectAttributes:attrs. |
|
1559 |
] ifFalse:[ |
|
1560 |
attrs at:attributeKey put:anObject. |
|
1561 |
]. |
|
6323 | 1562 |
] valueUninterruptably |
5755 | 1563 |
|
1564 |
"Attaching additional attributes (slots) to an arbitrary object: |
|
1565 |
||
1566 |
|p| |
|
1567 |
||
1568 |
p := Point new. |
|
1569 |
p objectAttributeAt:#color put:#green. |
|
1570 |
||
1571 |
p objectAttributeAt:#color |
|
1572 |
" |
|
1573 |
||
1574 |
"Created: / 22.1.1998 / 21:29:25 / av" |
|
1575 |
"Modified: / 3.2.1998 / 18:57:58 / cg" |
|
1576 |
! |
|
1577 |
||
1578 |
objectAttributes |
|
1579 |
"return a Collection of attributes - nil if there is none. |
|
1580 |
The default implementation here uses a global WeakDictionary to store |
|
1581 |
attributes |
|
1582 |
This may be too slow for high frequency slot access, |
|
1583 |
therefore, some classes may redefine this for better performance. |
|
1584 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
1585 |
||
1586 |
^ ObjectAttributes at:self ifAbsent:[nil] |
|
1587 |
||
1588 |
"Created: / 22.1.1998 / 21:29:30 / av" |
|
1589 |
"Modified: / 18.2.2000 / 11:34:16 / cg" |
|
1590 |
! |
|
1591 |
||
1592 |
objectAttributes:aCollection |
|
1593 |
"set the collection of attributes. |
|
1594 |
The default implementation here uses a global Dictionary to store |
|
1595 |
attributes which may be too slow for high frequency change&update. |
|
1596 |
Therefore, some classes may redefine this for better performance." |
|
1597 |
||
1598 |
"/ must do this save from interrupts, since the attributes collection |
|
1599 |
"/ is possibly accessed from multiple threads. |
|
1600 |
||
1601 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
6654 | 1602 |
"/ the common case - already blocked |
1603 |
||
1604 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
1605 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1606 |
] ifFalse:[ |
|
1607 |
ObjectAttributes at:self put:aCollection |
|
1608 |
]. |
|
1609 |
^ self |
|
5755 | 1610 |
]. |
1611 |
||
1612 |
[ |
|
6654 | 1613 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
1614 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1615 |
] ifFalse:[ |
|
1616 |
ObjectAttributes at:self put:aCollection |
|
1617 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
1618 |
] ensure:[ |
6654 | 1619 |
OperatingSystem unblockInterrupts |
5755 | 1620 |
] |
1621 |
||
1622 |
"Created: / 22.1.1998 / 21:29:35 / av" |
|
1623 |
"Modified: / 3.2.1998 / 18:58:10 / cg" |
|
1624 |
! |
|
1625 |
||
6323 | 1626 |
removeObjectAttribute:attributeKey |
5755 | 1627 |
"make the argument, anObject be no attribute of the receiver" |
1628 |
||
1629 |
"/ must do this save from interrupts, since the attributes collection |
|
1630 |
"/ is possibly accessed from multiple threads. |
|
1631 |
[ |
|
6654 | 1632 |
|attrs n a| |
1633 |
||
1634 |
attrs := self objectAttributes. |
|
1635 |
attrs size == 0 ifTrue:[ |
|
1636 |
self objectAttributes:nil |
|
1637 |
] ifFalse:[ |
|
1638 |
attrs removeKey:attributeKey ifAbsent:nil. |
|
1639 |
attrs size == 0 ifTrue:[ |
|
1640 |
self objectAttributes:nil |
|
1641 |
] |
|
1642 |
] |
|
6323 | 1643 |
] valueUninterruptably |
5755 | 1644 |
|
1645 |
"Created: / 22.1.1998 / 21:29:39 / av" |
|
1646 |
"Modified: / 18.2.2000 / 11:32:19 / cg" |
|
1647 |
! ! |
|
1648 |
||
1649 |
!Object methodsFor:'binary storage'! |
|
1650 |
||
6900 | 1651 |
binaryStoreBytes |
1652 |
^ ByteArray streamContents:[:s | self storeBinaryOn:s]. |
|
1653 |
||
1654 |
" |
|
1655 |
#('hello' 1 1.234) binaryStoreBytes |
|
1656 |
" |
|
1657 |
! |
|
1658 |
||
5755 | 1659 |
hasSpecialBinaryRepresentation |
1660 |
"return true, if the receiver has a special binary representation; |
|
1661 |
default here is false, but can be redefined in class which provide |
|
1662 |
their own storeBinary/readBinary methods. |
|
1663 |
||
1664 |
Normal user classes should not use this, it is meant as a hook for |
|
1665 |
special classes such as True, False, UndefinedObject or SmallInteger. |
|
1666 |
||
1667 |
If your instances should be stored in a special way, see |
|
1668 |
#representBinaryOn: and #readBinaryContentsFromdata:manager:." |
|
1669 |
||
1670 |
^ false |
|
1671 |
! |
|
1672 |
||
1673 |
readBinaryContentsFrom:stream manager:manager |
|
1674 |
"reconstruct the receivers instance variables by reading a binary |
|
1675 |
binary representation from stream. |
|
1676 |
This is a general implementation, walking over instances |
|
1677 |
and loading each recursively using manager. |
|
1678 |
Redefined by some classes to read a more compact representations |
|
1679 |
(see String, SmallInteger etc). |
|
1680 |
||
1681 |
Notice, that the object is already recreated as an empty corps |
|
1682 |
with instance variables all nil and bit-instances (bytes, words etc.) |
|
1683 |
already read and restored. |
|
1684 |
||
1685 |
Also notice: this method is not called for if a private representation |
|
1686 |
has been stored (see representBinaryOn:). |
|
1687 |
In that case, #readBinaryContentsFromData:manager: is called, which |
|
1688 |
has to be reimplemented in the objects class." |
|
1689 |
||
1690 |
|size "{ Class: SmallInteger }" |
|
1691 |
instvarArray| |
|
1692 |
||
1693 |
stream next == 1 ifTrue:[ |
|
6654 | 1694 |
"/ |
1695 |
"/ special representation ... |
|
1696 |
"/ |
|
1697 |
instvarArray := Array new:(size := stream nextNumber:3). |
|
1698 |
1 to:size do:[:i | |
|
1699 |
instvarArray basicAt:i put:(manager nextObject) |
|
1700 |
]. |
|
1701 |
self readBinaryContentsFromData:instvarArray manager:manager. |
|
1702 |
^ self |
|
5755 | 1703 |
]. |
1704 |
||
1705 |
"/ |
|
1706 |
"/ standard representation |
|
1707 |
"/ |
|
1708 |
size := self basicSize. |
|
1709 |
size ~~ 0 ifTrue:[ |
|
6654 | 1710 |
self class isPointers ifTrue:[ |
1711 |
1 to:size do:[:i | |
|
1712 |
self basicAt:i put:(manager nextObject) |
|
1713 |
] |
|
1714 |
] |
|
5755 | 1715 |
]. |
1716 |
size := self class instSize. |
|
1717 |
1 to:size do:[:i | |
|
6654 | 1718 |
self instVarAt:i put:(manager nextObject) |
5755 | 1719 |
]. |
1720 |
! |
|
1721 |
||
1722 |
readBinaryContentsFromData:instvarArray manager:manager |
|
1723 |
"reconstruct the receivers instance variables by filling instance |
|
1724 |
variables with values from instvarArray. This array contains the instvars |
|
1725 |
as specified in #representBinaryOn: when the object was stored. |
|
1726 |
It is the receivers responsibility to set its instance variables in the |
|
1727 |
same order from that array." |
|
1728 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
1729 |
^ self subclassResponsibility:'method must be reimplemented in subclass for binary storage' |
5755 | 1730 |
|
1731 |
"typical implementation (see also comment in #representBinaryOn:) |
|
1732 |
(for an object with foo, bar and baz as instance variables, |
|
1733 |
which did not store baz and wants baz to be reinitialized to |
|
1734 |
some constant string) |
|
1735 |
||
6654 | 1736 |
foo := instvarArray at:1. |
1737 |
bar := instvarArray at:2. |
|
1738 |
baz := 'aConstant'. |
|
5755 | 1739 |
" |
1740 |
! |
|
1741 |
||
1742 |
representBinaryOn:manager |
|
1743 |
"this method is called by the storage manager to ask objects |
|
1744 |
if they wish to provide their own binary representation. |
|
1745 |
||
1746 |
If they want to do so, they should return an array containing all |
|
1747 |
instance variables (named & indexed pointer) to be stored. |
|
1748 |
If not redefined, this method returns nil which means that all |
|
1749 |
instance variables are to be stored. |
|
1750 |
||
1751 |
It should be redefined in objects which do not want all instance variables |
|
1752 |
to be stored (for example: objects which keep references to a view etc.). |
|
1753 |
||
1754 |
If this is redefined returning non-nil, the corresponding class needs |
|
1755 |
a redefined instance method named #readBinaryContentsFromData:manager: |
|
1756 |
which has to fill the receivers named (and optionally indexed pointer) |
|
1757 |
instance variables with corresponding values from a data array." |
|
1758 |
||
1759 |
^ nil |
|
1760 |
||
1761 |
"typical implementation: |
|
1762 |
(see also comment in #readBinaryContentsFromData:manager:) |
|
1763 |
for an object with foo, bar and baz as instance variables, |
|
1764 |
which does not want to store baz: |
|
1765 |
||
1766 |
representBinaryOn:manager |
|
6654 | 1767 |
|data| |
1768 |
||
1769 |
data := Array new:2. |
|
1770 |
data at:1 put:foo. |
|
1771 |
data at:2 put:bar. |
|
1772 |
^ data |
|
5755 | 1773 |
" |
1774 |
! |
|
1775 |
||
1776 |
storeBinaryDefinitionBodyOn:stream manager:manager |
|
1777 |
"append a binary representation of the receivers body onto stream. |
|
1778 |
This is a general implementation walking over instances storing |
|
1779 |
each recursively as an ID using manager. |
|
1780 |
Can be redefined in subclasses." |
|
1781 |
||
1782 |
|basicSize "{ Class: SmallInteger }" |
|
1783 |
instSize "{ Class: SmallInteger }" |
|
1784 |
specialSize "{ Class: SmallInteger }" |
|
1785 |
myClass specialRep pointers| |
|
1786 |
||
1787 |
myClass := self class. |
|
1788 |
instSize := myClass instSize. |
|
1789 |
||
1790 |
(pointers := myClass isPointers) ifTrue:[ |
|
6654 | 1791 |
"/ |
1792 |
"/ inst size not needed - if you uncomment the line below, |
|
1793 |
"/ also uncomment the corresponding line in |
|
1794 |
"/ Object>>binaryDefinitionFrom:manager: |
|
1795 |
"/ |
|
1796 |
"/ stream nextPut:instSize. "mhmh this limits us to 255 named instvars" |
|
1797 |
||
1798 |
myClass isVariable ifTrue:[ |
|
1799 |
stream nextNumber:3 put:(basicSize := self basicSize) |
|
1800 |
] ifFalse:[ |
|
1801 |
basicSize := 0 |
|
1802 |
]. |
|
5755 | 1803 |
] ifFalse: [ |
6654 | 1804 |
stream nextNumber:4 put:(basicSize := self basicSize). |
1805 |
myClass isBytes ifTrue:[ |
|
1806 |
1 to:basicSize do:[:i | |
|
1807 |
stream nextPut:(self basicAt:i) |
|
1808 |
] |
|
1809 |
] ifFalse:[ |
|
1810 |
myClass isWords ifTrue:[ |
|
1811 |
1 to:basicSize do:[:i | |
|
1812 |
stream nextNumber:2 put:(self basicAt: i) |
|
1813 |
] |
|
1814 |
] ifFalse:[ |
|
1815 |
myClass isLongs ifTrue:[ |
|
1816 |
1 to:basicSize do:[:i | |
|
1817 |
stream nextNumber:4 put:(self basicAt: i) |
|
1818 |
] |
|
1819 |
] ifFalse:[ |
|
1820 |
myClass isFloats ifTrue:[ |
|
1821 |
"could do it in one big write on machines which use IEEE floats ..." |
|
1822 |
1 to:basicSize do:[:i | |
|
1823 |
Float storeBinaryIEEESingle:(self basicAt:i) on:stream |
|
1824 |
] |
|
1825 |
] ifFalse:[ |
|
1826 |
myClass isDoubles ifTrue:[ |
|
1827 |
"could do it in one big write on machines which use IEEE doubles ..." |
|
1828 |
1 to:basicSize do:[:i | |
|
1829 |
Float storeBinaryIEEEDouble:(self basicAt:i) on:stream |
|
1830 |
] |
|
1831 |
] ifFalse:[ |
|
1832 |
"/ should never be reached ... |
|
1833 |
1 to:basicSize do:[:i | |
|
1834 |
manager putIdOf:(self basicAt:i) on:stream |
|
1835 |
] |
|
1836 |
] |
|
1837 |
] |
|
1838 |
] |
|
1839 |
] |
|
1840 |
]. |
|
5755 | 1841 |
]. |
1842 |
||
1843 |
(pointers or:[instSize ~~ 0]) ifTrue:[ |
|
6654 | 1844 |
specialRep := self representBinaryOn:manager. |
1845 |
specialRep notNil ifTrue:[ |
|
1846 |
specialSize := specialRep basicSize. |
|
1847 |
stream nextPut:1. "/ means: private representation follows |
|
1848 |
stream nextNumber:3 put:specialSize. |
|
1849 |
||
1850 |
1 to:specialSize do:[:i | |
|
1851 |
manager putIdOf:(specialRep at:i) on:stream |
|
1852 |
]. |
|
1853 |
] ifFalse:[ |
|
1854 |
stream nextPut:0. "/ means: normal representation follows |
|
1855 |
"/ index pointers followed by named instanceVars |
|
1856 |
pointers ifTrue:[ |
|
1857 |
basicSize ~~ 0 ifTrue:[ |
|
1858 |
1 to:basicSize do:[:i | |
|
1859 |
manager putIdOf:(self basicAt:i) on:stream |
|
1860 |
]. |
|
1861 |
]. |
|
1862 |
]. |
|
1863 |
instSize ~~ 0 ifTrue:[ |
|
1864 |
1 to:instSize do:[:i | |
|
1865 |
manager putIdOf:(self instVarAt:i) on:stream |
|
1866 |
] |
|
1867 |
]. |
|
1868 |
] |
|
5755 | 1869 |
] |
1870 |
||
1871 |
"Modified: / 2.11.1997 / 14:43:29 / cg" |
|
1872 |
! |
|
1873 |
||
1874 |
storeBinaryDefinitionOn:stream manager:manager |
|
1875 |
"append a binary representation of the receiver onto stream. |
|
1876 |
This is an internal interface for binary storage mechanism. |
|
1877 |
This method first stores the class, then the body, which is done |
|
1878 |
in a separate method to allow redefinition of the bodies format. |
|
1879 |
Can be redefined in subclasses to write more compact representations |
|
1880 |
(see String, SmallInteger etc)." |
|
1881 |
||
1882 |
manager putIdOfClass:(self class) on:stream. |
|
1883 |
self storeBinaryDefinitionBodyOn:stream manager:manager |
|
1884 |
||
1885 |
"Modified: 23.4.1996 / 09:31:12 / cg" |
|
1886 |
! |
|
1887 |
||
1888 |
storeBinaryOn:aStreamOrFilename |
|
1889 |
"Writes a description of the receiver onto aStreamOrFilename, in a way that allows |
|
1890 |
the object's structure to be reconstructed from the stream's contents" |
|
1891 |
||
1892 |
BinaryOutputManager store:self on:aStreamOrFilename |
|
1893 |
||
1894 |
" |
|
1895 |
|a s1 s2| |
|
1896 |
||
1897 |
s1 := 'hello'. |
|
1898 |
s2 := 'world'. |
|
1899 |
a := Array new:5. |
|
1900 |
a at:1 put:s1. |
|
1901 |
a at:2 put:s2. |
|
1902 |
a at:3 put:s1. |
|
1903 |
a at:4 put:s2. |
|
1904 |
a storeBinaryOn:'test.boss' |
|
1905 |
" |
|
1906 |
||
1907 |
" |
|
1908 |
(BinaryObjectStorage onOld:'test.boss' asFilename readStream) |
|
6654 | 1909 |
next |
1910 |
inspect |
|
5755 | 1911 |
" |
1912 |
||
1913 |
"Modified: / 1.11.1997 / 21:16:24 / cg" |
|
1914 |
! |
|
1915 |
||
1916 |
storeBinaryOn:stream manager:manager |
|
1917 |
"append a binary representation of the receiver onto stream." |
|
1918 |
||
1919 |
manager putIdOf:self on:stream |
|
1920 |
! ! |
|
1921 |
||
1922 |
!Object methodsFor:'change & update'! |
|
1923 |
||
1924 |
broadcast:aSelectorSymbol |
|
1925 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1926 |
||
1927 |
self dependentsDo:[:dependent | |
|
6654 | 1928 |
dependent perform:aSelectorSymbol |
5755 | 1929 |
] |
1930 |
! |
|
1931 |
||
1932 |
broadcast:aSelectorSymbol with:anArgument |
|
1933 |
"send a message with selector aSelectorSymbol with an additional |
|
1934 |
argument anArgument to all my dependents." |
|
1935 |
||
1936 |
self dependentsDo:[:dependent | |
|
6654 | 1937 |
dependent perform:aSelectorSymbol with:anArgument |
5755 | 1938 |
] |
1939 |
! |
|
1940 |
||
1941 |
changeRequest |
|
1942 |
"the receiver wants to change - check if all dependents |
|
1943 |
grant the request, and return true if so" |
|
1944 |
||
1945 |
self dependentsDo:[:dependent | |
|
6654 | 1946 |
dependent updateRequest ifFalse:[^ false]. |
5755 | 1947 |
]. |
1948 |
^ true |
|
1949 |
! |
|
1950 |
||
1951 |
changeRequest:aParameter |
|
1952 |
"the receiver wants to change - check if all dependents |
|
1953 |
grant the request, and return true if so" |
|
1954 |
||
1955 |
self dependentsDo:[:dependent | |
|
6654 | 1956 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
5755 | 1957 |
]. |
1958 |
^ true |
|
1959 |
! |
|
1960 |
||
1961 |
changeRequest:aParameter from:anObject |
|
1962 |
"the receiver wants to change - check if all dependents |
|
1963 |
except anObject grant the request, and return true if so. |
|
1964 |
The argument anObject is typically going to be the one who is |
|
1965 |
about to send the change request." |
|
1966 |
||
1967 |
self dependentsDo:[:dependent | |
|
6654 | 1968 |
dependent == anObject ifFalse:[ |
1969 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
1970 |
] |
|
5755 | 1971 |
]. |
1972 |
^ true |
|
1973 |
! |
|
1974 |
||
1975 |
changeRequestFrom:anObject |
|
1976 |
"the receiver wants to change - check if all dependents |
|
1977 |
except anObject grant the request, and return true if so. |
|
1978 |
The argument anObject is typically going to be the one who is |
|
1979 |
about to send the change request." |
|
1980 |
||
1981 |
self dependentsDo:[:dependent | |
|
6654 | 1982 |
dependent == anObject ifFalse:[ |
1983 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1984 |
] |
|
5755 | 1985 |
]. |
1986 |
^ true |
|
1987 |
! |
|
1988 |
||
1989 |
changed |
|
1990 |
"notify all dependents that the receiver has changed. |
|
1991 |
Each dependent gets a '#update:'-message with the original |
|
1992 |
receiver as argument." |
|
1993 |
||
1994 |
self changed:nil |
|
1995 |
! |
|
1996 |
||
1997 |
changed:aParameter |
|
1998 |
"notify all dependents that the receiver has changed somehow. |
|
1999 |
Each dependent gets a '#update:'-message with aParameter |
|
2000 |
as argument." |
|
2001 |
||
2002 |
self changed:aParameter with:nil |
|
2003 |
! |
|
2004 |
||
2005 |
changed:aParameter with:anArgument |
|
2006 |
"notify all dependents that the receiver has changed somehow. |
|
2007 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
|
2008 |
and anArgument as arguments." |
|
2009 |
||
2010 |
self dependentsDo:[:dependent | |
|
6654 | 2011 |
dependent update:aParameter with:anArgument from:self |
5755 | 2012 |
] |
2013 |
! |
|
2014 |
||
2015 |
update:aParameter |
|
2016 |
"the message is sent to a dependent, when one of the objects |
|
2017 |
on whom the receiver depends, has changed. The argument aParameter |
|
2018 |
is either the changed object or the argument to the #changed: message. |
|
2019 |
||
2020 |
Default behavior here is to do nothing" |
|
2021 |
||
2022 |
^ self |
|
2023 |
! |
|
2024 |
||
2025 |
update:aParameter with:anArgument |
|
2026 |
"dependent is notified of some change - |
|
2027 |
Default is to try update:" |
|
2028 |
||
2029 |
^ self update:aParameter |
|
2030 |
! |
|
2031 |
||
2032 |
update:aParameter with:anArgument from:sender |
|
2033 |
"dependent is notified of some change - |
|
2034 |
Default is to try update:with:" |
|
2035 |
||
2036 |
^ self update:aParameter with:anArgument |
|
2037 |
! |
|
2038 |
||
2039 |
updateRequest |
|
2040 |
"return true, if an update request is granted. |
|
2041 |
Default here is to grant updates - may be used |
|
2042 |
to lock updates if someone is making other changes |
|
2043 |
from within an update. Or if someone has locked its |
|
2044 |
state and does not want others to change things. |
|
2045 |
However, these dependents must all honor the |
|
2046 |
changeRequest - ifTrue - change protocol. I.e. they |
|
2047 |
must first ask all others via changeRequest, and only do the change |
|
2048 |
it returns true. The others must decide in updateRequest and |
|
2049 |
return true if they think a change is ok." |
|
2050 |
||
2051 |
^ true |
|
2052 |
! |
|
2053 |
||
2054 |
updateRequest:aSymbol |
|
2055 |
"return true, if an update request is granted. |
|
2056 |
Default here a simple updateRequest" |
|
2057 |
||
2058 |
^ self updateRequest |
|
7177 | 2059 |
! |
2060 |
||
2061 |
withoutUpdating:someone do:aBlock |
|
2062 |
"evaluate a block but remove someone from my dependents temporarily" |
|
2063 |
||
2064 |
(self dependents includesIdentical:someone) |
|
2065 |
ifFalse:[ |
|
2066 |
^ aBlock value. |
|
2067 |
]. |
|
2068 |
self removeDependent:someone. |
|
2069 |
^ aBlock ensure:[ self addDependent:someone ] |
|
5755 | 2070 |
! ! |
2071 |
||
2072 |
!Object methodsFor:'cleanup'! |
|
2073 |
||
2074 |
lowSpaceCleanup |
|
2075 |
"ignored here - redefined in some classes to |
|
2076 |
cleanup in low-memory situations" |
|
2077 |
||
2078 |
^ self |
|
2079 |
! ! |
|
2080 |
||
2081 |
!Object methodsFor:'comparing'! |
|
2082 |
||
2083 |
= anObject |
|
2084 |
"return true, if the receiver and the arg have the same structure. |
|
2085 |
Notice: |
|
6654 | 2086 |
This method is partially open coded (inlined) by the compiler(s) |
2087 |
identical objects are always considered equal. |
|
2088 |
redefining it may not work as expected." |
|
5755 | 2089 |
|
2090 |
^ self == anObject |
|
2091 |
! |
|
2092 |
||
2093 |
== anObject |
|
2094 |
"return true, if the receiver and the arg are the same object. |
|
2095 |
Never redefine this in any class. |
|
2096 |
Notice: |
|
6654 | 2097 |
This method is open coded (inlined) by the compiler(s) |
2098 |
- redefining it may not work as expected." |
|
5755 | 2099 |
|
2100 |
%{ /* NOCONTEXT */ |
|
2101 |
||
2102 |
RETURN ( (self == anObject) ? true : false ); |
|
2103 |
%} |
|
2104 |
! |
|
2105 |
||
5814 | 2106 |
deepSameContentsAs:anObject |
2107 |
"return true, if the receiver and the arg have the same contents |
|
2108 |
in both the named instance vars and any indexed instVars. |
|
2109 |
This method descends into referenced objects, where #sameContentsAs: does not descend" |
|
2110 |
||
5821 | 2111 |
|myClass val |
5814 | 2112 |
sz "{ Class: SmallInteger }" | |
2113 |
||
2114 |
myClass := self class. |
|
2115 |
myClass isVariable ifTrue:[ |
|
6654 | 2116 |
sz := self basicSize. |
2117 |
||
2118 |
"compare the indexed variables" |
|
2119 |
1 to:sz do:[:i | |
|
2120 |
val := self basicAt:i. |
|
2121 |
val isLiteral ifTrue:[ |
|
2122 |
val = (anObject basicAt:i) ifFalse:[^ false]. |
|
2123 |
] ifFalse:[ |
|
2124 |
(val deepSameContentsAs:(anObject basicAt:i)) ifFalse:[^ false]. |
|
2125 |
] |
|
2126 |
] |
|
5814 | 2127 |
]. |
2128 |
||
2129 |
"compare the instance variables" |
|
2130 |
sz := myClass instSize. |
|
2131 |
1 to:sz do:[:i | |
|
6654 | 2132 |
val := self instVarAt:i. |
2133 |
val isLiteral ifTrue:[ |
|
2134 |
val = (anObject instVarAt:i) ifFalse:[^ false]. |
|
2135 |
] ifFalse:[ |
|
2136 |
(val deepSameContentsAs:(anObject instVarAt:i)) ifFalse:[^ false]. |
|
2137 |
] |
|
5814 | 2138 |
]. |
2139 |
||
2140 |
^ true |
|
2141 |
||
2142 |
" |
|
2143 |
#(1 2 3 4) deepSameContentsAs:#[1 2 3 4] asArray |
|
2144 |
(1@2) deepSameContentsAs:(1->2) |
|
2145 |
" |
|
2146 |
! |
|
2147 |
||
5755 | 2148 |
hash |
2149 |
"return an Integer useful as a hash key for the receiver. |
|
2150 |
This hash should return same values for objects with same |
|
2151 |
contents (i.e. use this to hash on structure)" |
|
2152 |
||
2153 |
^ self identityHash |
|
2154 |
! |
|
2155 |
||
2156 |
identityHash |
|
2157 |
"return an Integer useful as a hash key for the receiver. |
|
2158 |
This hash should return same values for the same object (i.e. use |
|
2159 |
this to hash on identity of objects). |
|
2160 |
||
2161 |
We cannot use the Objects address (as other smalltalks do) since |
|
2162 |
no object-table exists and the hashval must not change when objects |
|
2163 |
are moved by the collector. Therefore we assign each object a unique |
|
2164 |
Id in the object header itself as its hashed upon. |
|
2165 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
2166 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
2167 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
2168 |
hashed-upon objects could add an instvar containing the hash value." |
|
2169 |
||
2170 |
%{ /* NOCONTEXT */ |
|
2171 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2172 |
REGISTER unsigned INT hash; |
5755 | 2173 |
static unsigned nextHash = 0; |
2174 |
||
2175 |
if (__isNonNilObject(self)) { |
|
6654 | 2176 |
hash = __GET_HASH(self); |
2177 |
if (hash == 0) { |
|
2178 |
/* has no hash yet */ |
|
2179 |
||
2180 |
if (++nextHash > __MAX_HASH__) { |
|
2181 |
nextHash = 1; |
|
2182 |
} |
|
2183 |
hash = nextHash; |
|
2184 |
__SET_HASH(self, hash); |
|
2185 |
} |
|
2186 |
||
2187 |
/* |
|
2188 |
* now, we got 11 bits for hashing; |
|
2189 |
* make it as large as possible; since most hashers use the returned |
|
2190 |
* key and take it modulo some prime number, this will allow for |
|
2191 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2192 |
*/ |
|
2193 |
hash = __MAKE_HASH__(hash); |
|
2194 |
RETURN ( __MKSMALLINT(hash) ); |
|
5755 | 2195 |
} |
2196 |
%}. |
|
2197 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
2198 |
! |
|
2199 |
||
2200 |
identityHashForBinaryStore |
|
2201 |
"hash which is usable if the object does not change its class |
|
2202 |
and does not #become something else, while the hash is used. |
|
2203 |
This is only used by the binary storage mechanism, during the |
|
2204 |
object writing phase." |
|
2205 |
||
2206 |
%{ /* NOCONTEXT */ |
|
2207 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2208 |
REGISTER unsigned INT hash, hash1, hash2, sz; |
5755 | 2209 |
OBJ o; |
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2210 |
static unsigned INT nextHash = 0; |
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2211 |
static unsigned INT nextClassHash = 0; |
5755 | 2212 |
|
2213 |
if (__isNonNilObject(self)) { |
|
6654 | 2214 |
/* |
2215 |
* my own identityHash |
|
2216 |
*/ |
|
2217 |
hash1 = __GET_HASH(self); |
|
2218 |
if (hash1 == 0) { |
|
2219 |
/* has no hash yet */ |
|
2220 |
||
2221 |
if (++nextHash > __MAX_HASH__) { |
|
2222 |
nextHash = 1; |
|
2223 |
} |
|
2224 |
hash1 = nextHash; |
|
2225 |
__SET_HASH(self, hash1); |
|
2226 |
} |
|
2227 |
/* |
|
2228 |
* my classes identityHash |
|
2229 |
*/ |
|
2230 |
o = __qClass(self); |
|
2231 |
hash2 = __GET_HASH(o); |
|
2232 |
if (hash2 == 0) { |
|
2233 |
/* has no hash yet */ |
|
2234 |
||
2235 |
if (++nextClassHash > __MAX_HASH__) { |
|
2236 |
nextClassHash = 1; |
|
2237 |
} |
|
2238 |
hash2 = nextClassHash; |
|
2239 |
__SET_HASH(o, hash2); |
|
2240 |
} |
|
2241 |
||
2242 |
/* |
|
2243 |
* some bits of my size |
|
2244 |
*/ |
|
2245 |
sz = __qSize(self); |
|
2246 |
||
2247 |
/* |
|
2248 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
2249 |
* make it as large as possible; since most hashers use the returned |
|
2250 |
* key and take it modulo some prime number, this will allow for |
|
2251 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2252 |
*/ |
|
2253 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
2254 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
2255 |
||
2256 |
while ((hash & 0x20000000) == 0) { |
|
2257 |
hash <<= 1; |
|
2258 |
} |
|
2259 |
||
2260 |
RETURN ( __MKSMALLINT(hash) ); |
|
5755 | 2261 |
} |
2262 |
%}. |
|
2263 |
"never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
|
2264 |
^ self identityHash |
|
2265 |
! |
|
2266 |
||
2267 |
sameContentsAs:anObject |
|
2268 |
"return true, if the receiver and the arg have the same contents |
|
7121 | 2269 |
in both the named instance vars and any indexed instVars. |
2270 |
The code here only checks if values present in the receiver are also |
|
2271 |
present in the arg, not vice versa. |
|
2272 |
I.e. the argument may be bigger and/or have more instance variables." |
|
5755 | 2273 |
|
5821 | 2274 |
|myClass |
5755 | 2275 |
sz "{ Class: SmallInteger }" | |
2276 |
||
2277 |
myClass := self class. |
|
2278 |
myClass isVariable ifTrue:[ |
|
6654 | 2279 |
sz := self basicSize. |
7121 | 2280 |
anObject basicSize >= sz ifFalse:[^ false]. |
6654 | 2281 |
|
2282 |
"compare the indexed variables" |
|
2283 |
1 to:sz do:[:i | |
|
2284 |
(self basicAt:i) == (anObject basicAt:i) ifFalse:[^ false]. |
|
2285 |
] |
|
5755 | 2286 |
]. |
2287 |
||
2288 |
"compare the instance variables" |
|
2289 |
sz := myClass instSize. |
|
7121 | 2290 |
anObject instSize >= sz ifFalse:[^ false]. |
2291 |
||
5755 | 2292 |
1 to:sz do:[:i | |
6654 | 2293 |
(self instVarAt:i) == (anObject instVarAt:i) ifFalse:[^ false]. |
5755 | 2294 |
]. |
2295 |
||
2296 |
^ true |
|
2297 |
||
2298 |
" |
|
5814 | 2299 |
#(1 2 3 4) sameContentsAs:#[1 2 3 4] asArray |
2300 |
(1@2) sameContentsAs:(1->2) |
|
5755 | 2301 |
" |
2302 |
||
2303 |
"Created: / 21.4.1998 / 15:56:40 / cg" |
|
2304 |
"Modified: / 21.4.1998 / 15:58:15 / cg" |
|
2305 |
! |
|
2306 |
||
2307 |
~= anObject |
|
2308 |
"return true, if the receiver and the arg do not have the same structure. |
|
2309 |
Notice: |
|
6654 | 2310 |
This method is partially open coded (inlined) by the compiler(s) |
2311 |
identical objects are never considered unequal. |
|
2312 |
redefining it may not work as expected." |
|
5755 | 2313 |
|
2314 |
^ (self = anObject) not |
|
2315 |
! |
|
2316 |
||
2317 |
~~ anObject |
|
2318 |
"return true, if the receiver and the arg are not the same object. |
|
2319 |
Never redefine this in any class. |
|
2320 |
Notice: |
|
6654 | 2321 |
This method is open coded (inlined) by the compiler(s) |
2322 |
- redefining it may not work as expected." |
|
5755 | 2323 |
|
2324 |
%{ /* NOCONTEXT */ |
|
2325 |
RETURN ( (self == anObject) ? false : true ); |
|
2326 |
%} |
|
2327 |
! ! |
|
2328 |
||
2329 |
!Object methodsFor:'converting'! |
|
2330 |
||
6696
36eaa6c17e2c
use excla for conses (looks better);
Claus Gittinger <cg@exept.de>
parents:
6656
diff
changeset
|
2331 |
!! anObject |
6652
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2332 |
"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
|
2333 |
|
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2334 |
^ Cons car:self cdr:anObject |
6697 | 2335 |
|
2336 |
" |
|
6698 | 2337 |
(1 !! 2) |
2338 |
(#car !! #cdr) |
|
2339 |
(1 !! (2 !! (3 !! nil))) |
|
2340 |
(1 !! 2) !! (2 !! 3) |
|
6697 | 2341 |
" |
6652
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2342 |
! |
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2343 |
|
5755 | 2344 |
-> anObject |
2345 |
"return an association with the receiver as key and |
|
2346 |
the argument as value" |
|
2347 |
||
2348 |
^ Association key:self value:anObject |
|
2349 |
! |
|
2350 |
||
2351 |
asCollection |
|
2352 |
"return myself as a Collection. |
|
2353 |
Redefined in collection to return themself." |
|
2354 |
||
2355 |
^ Array with:self |
|
2356 |
! |
|
2357 |
||
2358 |
asSequenceableCollection |
|
2359 |
"return myself as a SequenceableCollection. |
|
2360 |
Redefined in SequenceableCollection" |
|
2361 |
||
2362 |
^ Array with:self |
|
2363 |
! |
|
2364 |
||
2365 |
asValue |
|
2366 |
"return a valueHolder for for the receiver" |
|
2367 |
||
2368 |
^ ValueHolder with:self |
|
6146 | 2369 |
! |
2370 |
||
2371 |
collect |
|
2372 |
"return mySelf" |
|
2373 |
||
2374 |
^ self |
|
2375 |
! |
|
2376 |
||
2377 |
deepCollect |
|
2378 |
"return mySelf" |
|
2379 |
||
2380 |
^ self |
|
2381 |
! |
|
2382 |
||
2383 |
deepSelect |
|
2384 |
"return mySelf" |
|
2385 |
||
2386 |
^ self |
|
2387 |
! |
|
2388 |
||
2389 |
select |
|
2390 |
"return mySelf" |
|
2391 |
||
2392 |
^ self |
|
5755 | 2393 |
! ! |
2394 |
||
2395 |
!Object methodsFor:'copying'! |
|
2396 |
||
2397 |
cloneFrom:anObject |
|
2398 |
"Helper for copy: |
|
2399 |
copy all instance variables from anObject into the receiver, |
|
2400 |
which should be of the same class as the argument." |
|
2401 |
||
2402 |
self cloneFrom:anObject performing:#yourself |
|
2403 |
||
2404 |
" |
|
2405 |
|x| |
|
2406 |
||
2407 |
x := Array new:3. |
|
2408 |
x cloneFrom:#(1 2 3). |
|
2409 |
" |
|
2410 |
! |
|
2411 |
||
2412 |
cloneFrom:anObject performing:aSymbol |
|
2413 |
"Helper for copy: |
|
2414 |
for each instance variables from anObject, send it aSymbol |
|
2415 |
and store the result into the receiver, |
|
2416 |
which should be of the same class as the argument." |
|
2417 |
||
2418 |
|myClass sz "{ Class: SmallInteger }" t | |
|
2419 |
||
2420 |
myClass := self class. |
|
2421 |
myClass isVariable ifTrue:[ |
|
6654 | 2422 |
sz := self basicSize. |
2423 |
||
2424 |
"copy the indexed variables" |
|
2425 |
1 to:sz do:[:i | |
|
2426 |
t := anObject basicAt:i. |
|
2427 |
aSymbol ~~ #yourself ifTrue:[ |
|
2428 |
t := t perform:aSymbol. |
|
2429 |
]. |
|
2430 |
self basicAt:i put:t. |
|
2431 |
] |
|
5755 | 2432 |
]. |
2433 |
||
2434 |
"copy the instance variables" |
|
2435 |
sz := myClass instSize. |
|
2436 |
1 to:sz do:[:i | |
|
6654 | 2437 |
t := anObject instVarAt:i. |
2438 |
aSymbol ~~ #yourself ifTrue:[ |
|
2439 |
t := t perform:aSymbol |
|
2440 |
]. |
|
2441 |
self instVarAt:i put:t |
|
5755 | 2442 |
]. |
2443 |
||
2444 |
^ self |
|
2445 |
||
2446 |
! |
|
2447 |
||
2448 |
cloneInstanceVariablesFrom:aPrototype |
|
2449 |
"Shallow copy variables from a prototype into myself. |
|
2450 |
This copies instVars by name - i.e. same-named variables are |
|
2451 |
copied, others are not. |
|
2452 |
The variable slots are copied as available |
|
2453 |
(i.e. the min of both indexed sizes is used)." |
|
2454 |
||
2455 |
|myInfo otherInfo| |
|
2456 |
||
2457 |
myInfo := self class instanceVariableOffsets. |
|
2458 |
otherInfo := aPrototype class instanceVariableOffsets. |
|
2459 |
myInfo keysAndValuesDo:[:name :index | |varIndexAssoc| |
|
6654 | 2460 |
varIndexAssoc := otherInfo at:name ifAbsent:[]. |
2461 |
varIndexAssoc notNil ifTrue:[ |
|
2462 |
self instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
2463 |
] |
|
5755 | 2464 |
]. |
2465 |
self isVariable ifTrue:[ |
|
6654 | 2466 |
1 to:(self basicSize min:aPrototype basicSize) do:[:index | |
2467 |
self basicAt:index put:(aPrototype basicAt:index) |
|
2468 |
]. |
|
5755 | 2469 |
]. |
2470 |
||
2471 |
" |
|
2472 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2473 |
Point subclass:#Point3D |
2474 |
instanceVariableNames:'z' |
|
2475 |
classVariableNames:'' |
|
2476 |
poolDictionaries:'' |
|
2477 |
category:'testing'. |
|
2478 |
(Point3D new cloneInstanceVariablesFrom:1@2) inspect. |
|
5755 | 2479 |
] |
2480 |
" |
|
2481 |
||
2482 |
" |
|
2483 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2484 |
Point variableSubclass:#Point3D |
2485 |
instanceVariableNames:'z' |
|
2486 |
classVariableNames:'' |
|
2487 |
poolDictionaries:'' |
|
2488 |
category:'testing'. |
|
2489 |
((Point3D new:2) cloneInstanceVariablesFrom:#(1 2 3)) inspect. |
|
5755 | 2490 |
] |
2491 |
" |
|
2492 |
||
2493 |
" |
|
2494 |
|someObject| |
|
2495 |
||
2496 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2497 |
Object subclass:#TestClass1 |
2498 |
instanceVariableNames:'foo bar' |
|
2499 |
classVariableNames:'' |
|
2500 |
poolDictionaries:'' |
|
2501 |
category:'testing'. |
|
2502 |
someObject := TestClass1 new. |
|
2503 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
2504 |
Object subclass:#TestClass2 |
|
2505 |
instanceVariableNames:'bar foo' |
|
2506 |
classVariableNames:'' |
|
2507 |
poolDictionaries:'' |
|
2508 |
category:'testing'. |
|
2509 |
(TestClass2 new cloneInstanceVariablesFrom:someObject) inspect. |
|
5755 | 2510 |
] |
2511 |
" |
|
2512 |
||
2513 |
" |
|
2514 |
|top b b1| |
|
2515 |
||
2516 |
top := StandardSystemView new. |
|
2517 |
top extent:100@100. |
|
2518 |
||
2519 |
b := Button in:top. |
|
2520 |
b label:'hello'. |
|
2521 |
||
2522 |
b1 := ArrowButton new cloneInstanceVariablesFrom:b. |
|
2523 |
||
2524 |
top open. |
|
2525 |
b1 inspect |
|
2526 |
" |
|
2527 |
! |
|
2528 |
||
2529 |
copy |
|
2530 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
2531 |
Notice, that copy does not copy dependents." |
|
2532 |
||
2533 |
^ self shallowCopy postCopy |
|
2534 |
! |
|
2535 |
||
6146 | 2536 |
copyToLevel:level |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2537 |
"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
|
2538 |
Notice: |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2539 |
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
|
2540 |
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
|
2541 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2542 |
|newObject class index| |
6146 | 2543 |
|
2544 |
level == 1 ifTrue:[^ self shallowCopy]. |
|
2545 |
||
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2546 |
class := self class. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2547 |
newObject := self clone. |
6146 | 2548 |
newObject == self ifTrue: [^ self]. |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2549 |
class isVariable ifTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2550 |
index := self basicSize. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2551 |
[index > 0] whileTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2552 |
newObject basicAt: index put: ((self basicAt: index) copyToLevel:(level-1)). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2553 |
index := index - 1 |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2554 |
] |
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 |
index := class instSize. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2557 |
[index > 0] whileTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2558 |
newObject instVarAt: index put: ((self instVarAt: index) copyToLevel:(level-1)). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2559 |
index := index - 1 |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2560 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2561 |
^ newObject |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2562 |
|
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 |
|a b| |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2565 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2566 |
a := #( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2567 |
'1.1' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2568 |
'1.2' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2569 |
'1.3' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2570 |
( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2571 |
'1.41' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2572 |
'1.42' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2573 |
'1.43' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2574 |
( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2575 |
'1.441' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2576 |
'1.442' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2577 |
'1.443' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2578 |
( '1.4441' '1.4442' '1.4443' ) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2579 |
'1.445' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2580 |
) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2581 |
'1.45' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2582 |
) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2583 |
'1.5' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2584 |
). |
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 |
b := a copyToLevel:1. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2587 |
self assert: ( (a at:1) == (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2588 |
self assert: ( (a at:4) == (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2589 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2590 |
b := a copyToLevel:2. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2591 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2592 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2593 |
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
|
2594 |
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
|
2595 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2596 |
b := a copyToLevel:3. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2597 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2598 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2599 |
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
|
2600 |
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
|
2601 |
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
|
2602 |
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
|
2603 |
" |
6146 | 2604 |
! |
2605 |
||
5755 | 2606 |
deepCopy |
2607 |
"return a copy of the object with all subobjects also copied. |
|
2608 |
This method DOES handle cycles/self-refs and preserves object identity; |
|
2609 |
however the receivers class is not copied (to avoid the 'total' copy). |
|
2610 |
||
2611 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
2612 |
keeps track of already copied objects. If you are sure, that your |
|
2613 |
copied object does not include duplicates (or you do not care) and |
|
2614 |
no cycles are involved, you can use the old simpleDeepCopy, |
|
2615 |
which avoids this overhead (but may run into trouble). |
|
2616 |
Notice, that deepCopy does not copy dependents." |
|
2617 |
||
2618 |
^ (self deepCopyUsing:(IdentityDictionary new)) postDeepCopyFrom:self |
|
2619 |
||
2620 |
"an example which is not handled by the old deepCopy: |
|
2621 |
||
2622 |
|a| |
|
2623 |
a := Array new:3. |
|
2624 |
a at:3 put:a. |
|
2625 |
a deepCopy inspect |
|
2626 |
" |
|
2627 |
||
2628 |
" |
|
2629 |
|a| |
|
2630 |
a := Color black onDevice:Screen current. |
|
2631 |
a deepCopy inspect |
|
2632 |
" |
|
2633 |
||
2634 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
2635 |
! |
|
2636 |
||
2637 |
deepCopyError |
|
2638 |
"{ Pragma: +optSpace }" |
|
2639 |
||
2640 |
"raise a signal, that deepCopy is not allowed for this object" |
|
2641 |
||
2642 |
^ DeepCopyErrorSignal raise |
|
2643 |
! |
|
2644 |
||
2645 |
deepCopyUsing:aDictionary |
|
2646 |
"a helper for deepCopy; return a copy of the object with |
|
2647 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
2648 |
use the value found there. The class of the receiver is not copied. |
|
2649 |
This method DOES handle cycles/self references." |
|
2650 |
||
2651 |
|myClass aCopy |
|
2652 |
sz "{ Class: SmallInteger }" |
|
2653 |
iOrig iCopy| |
|
2654 |
||
2655 |
myClass := self class. |
|
2656 |
myClass isVariable ifTrue:[ |
|
6654 | 2657 |
sz := self basicSize. |
2658 |
aCopy := myClass basicNew:sz. |
|
5755 | 2659 |
] ifFalse:[ |
6654 | 2660 |
sz := 0. |
2661 |
aCopy := myClass basicNew |
|
5755 | 2662 |
]. |
2663 |
aCopy setHashFrom:self. |
|
2664 |
||
2665 |
aDictionary at:self put:aCopy. |
|
2666 |
||
2667 |
" |
|
2668 |
copy indexed instvars - if any |
|
2669 |
" |
|
2670 |
sz ~~ 0 ifTrue:[ |
|
6654 | 2671 |
myClass isBits ifTrue:[ |
2672 |
"block-copy indexed instvars" |
|
2673 |
aCopy replaceFrom:1 to:sz with:self startingAt:1 |
|
2674 |
] ifFalse:[ |
|
2675 |
"individual deep copy the indexed variables" |
|
2676 |
1 to:sz do:[:i | |
|
2677 |
iOrig := self basicAt:i. |
|
2678 |
iOrig notNil ifTrue:[ |
|
2679 |
(aDictionary includesKey:iOrig) ifTrue:[ |
|
2680 |
iCopy := aDictionary at:iOrig |
|
2681 |
] ifFalse:[ |
|
2682 |
iCopy := (iOrig deepCopyUsing:aDictionary) postDeepCopy |
|
2683 |
]. |
|
2684 |
aCopy basicAt:i put:iCopy |
|
2685 |
] |
|
2686 |
] |
|
2687 |
] |
|
5755 | 2688 |
]. |
2689 |
||
2690 |
" |
|
2691 |
copy the instance variables |
|
2692 |
" |
|
2693 |
sz := myClass instSize. |
|
2694 |
1 to:sz do:[:i | |
|
6654 | 2695 |
(self skipInstvarIndexInDeepCopy:i) ifFalse:[ |
2696 |
iOrig := self instVarAt:i. |
|
2697 |
iOrig notNil ifTrue:[ |
|
2698 |
(aDictionary includesKey:iOrig) ifTrue:[ |
|
2699 |
iCopy := aDictionary at:iOrig |
|
2700 |
] ifFalse:[ |
|
2701 |
iCopy := (iOrig deepCopyUsing:aDictionary) postDeepCopy |
|
2702 |
]. |
|
2703 |
aCopy instVarAt:i put:iCopy |
|
2704 |
] |
|
2705 |
] |
|
5755 | 2706 |
]. |
2707 |
^ aCopy |
|
2708 |
||
2709 |
" |
|
2710 |
|a b c copyOfC| |
|
2711 |
||
2712 |
a := Array with:'hello' with:'world' with:nil. |
|
2713 |
b := 99 @ 999. |
|
2714 |
a at:3 put:b. |
|
2715 |
c := Array with:a with:b with:a. |
|
2716 |
||
2717 |
Transcript showCR: (c at:1) == (c at:3). |
|
2718 |
copyOfC := c deepCopy. |
|
2719 |
Transcript showCR: (copyOfC at:1) == (copyOfC at:3) |
|
2720 |
" |
|
2721 |
! |
|
2722 |
||
2723 |
postCopy |
|
2724 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
2725 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
2726 |
(see there)" |
|
2727 |
||
2728 |
^ self |
|
2729 |
! |
|
2730 |
||
2731 |
postDeepCopy |
|
2732 |
"allows for cleanup after deep copying" |
|
2733 |
||
2734 |
^ self postCopy |
|
2735 |
! |
|
2736 |
||
2737 |
postDeepCopyFrom:aSource |
|
2738 |
"allows for cleanup after deep copying" |
|
2739 |
||
2740 |
^ self postDeepCopy |
|
2741 |
! |
|
2742 |
||
2743 |
setHashFrom:anObject |
|
2744 |
"set my identity-hash key to be the same as anObjects hash key. |
|
2745 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
2746 |
Smalltalks, and may not be available in future ST/X versions. |
|
2747 |
DO NEVER use this for normal application code." |
|
2748 |
||
2749 |
%{ /* NOCONTEXT */ |
|
2750 |
||
2751 |
REGISTER unsigned h; |
|
2752 |
||
2753 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
6654 | 2754 |
h = __GET_HASH(anObject); |
2755 |
__SET_HASH(self, h); |
|
2756 |
RETURN (self); |
|
5755 | 2757 |
} |
2758 |
%}. |
|
2759 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
2760 |
! |
|
2761 |
||
2762 |
shallowCopy |
|
2763 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2764 |
i.e. the copy shares referenced instvars with its original." |
|
2765 |
||
2766 |
%{ /* NOCONTEXT */ |
|
2767 |
int ninsts, spc; |
|
2768 |
int sz; |
|
2769 |
OBJ theCopy; |
|
2770 |
OBJ cls; |
|
2771 |
int flags; |
|
2772 |
||
2773 |
cls = __qClass(self); |
|
2774 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
2775 |
||
2776 |
/* |
|
2777 |
* bail out for special objects .. |
|
2778 |
*/ |
|
2779 |
if (((flags & ~ARRAYMASK) == 0) |
|
2780 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
6654 | 2781 |
sz = __qSize(self); |
2782 |
__PROTECT__(self); |
|
2783 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
2784 |
__UNPROTECT__(self); |
|
2785 |
if (theCopy) { |
|
2786 |
cls = __qClass(self); |
|
2787 |
spc = __qSpace(theCopy); |
|
2788 |
||
2789 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
2790 |
||
2791 |
sz = sz - OHDR_SIZE; |
|
2792 |
if (sz) { |
|
2793 |
char *src, *dst; |
|
2794 |
||
2795 |
src = (char *)(__InstPtr(self)->i_instvars); |
|
2796 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
5755 | 2797 |
#ifdef bcopy4 |
6654 | 2798 |
{ |
2799 |
/* care for odd-number of longs */ |
|
2800 |
int nW = sz >> 2; |
|
2801 |
||
2802 |
if (sz & 3) { |
|
2803 |
nW++; |
|
2804 |
} |
|
2805 |
||
2806 |
bcopy4(src, dst, nW); |
|
2807 |
} |
|
5755 | 2808 |
#else |
6654 | 2809 |
bcopy(src, dst, sz); |
5755 | 2810 |
#endif |
2811 |
||
6654 | 2812 |
flags &= ARRAYMASK; |
2813 |
if (flags == POINTERARRAY) { |
|
2814 |
ninsts = __BYTES2OBJS__(sz); |
|
2815 |
} else { |
|
2816 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
2817 |
} |
|
2818 |
if (ninsts) { |
|
2819 |
do { |
|
2820 |
OBJ el; |
|
2821 |
||
2822 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
2823 |
__STORE_SPC(theCopy, el, spc); |
|
2824 |
} while (--ninsts); |
|
2825 |
} |
|
2826 |
} |
|
2827 |
RETURN (theCopy); |
|
2828 |
} |
|
5755 | 2829 |
} |
2830 |
%}. |
|
2831 |
"/ fallBack for special objects & memoryAllocation failure case |
|
2832 |
||
2833 |
^ self slowShallowCopy |
|
2834 |
! |
|
2835 |
||
2836 |
simpleDeepCopy |
|
2837 |
"return a copy of the object with all subobjects also copied. |
|
2838 |
This method does NOT handle cycles - but is included to allow this |
|
2839 |
slightly faster copy in situations where it is known that |
|
2840 |
no recursive references occur (LargeIntegers for example). |
|
2841 |
NOTICE: you will run into trouble, when trying this with recursive |
|
2842 |
objects (usually recursionInterrupt or memory-alert). |
|
2843 |
This method corresponds to the 'traditional' deepCopy found in |
|
2844 |
the Blue book." |
|
2845 |
||
2846 |
|myClass aCopy| |
|
2847 |
||
2848 |
(myClass := self class) isVariable ifTrue:[ |
|
6654 | 2849 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2850 |
] ifFalse:[ |
6654 | 2851 |
aCopy := myClass basicNew |
5755 | 2852 |
]. |
2853 |
||
2854 |
"copy the instance variables" |
|
2855 |
aCopy cloneFrom:self performing:#simpleDeepCopy. |
|
2856 |
^ aCopy |
|
2857 |
||
2858 |
"a bad example (but ST/X should survive ...)" |
|
2859 |
" |
|
2860 |
|a| |
|
2861 |
a := Array new:3. |
|
2862 |
a at:3 put:a. |
|
2863 |
a simpleDeepCopy |
|
2864 |
" |
|
2865 |
! |
|
2866 |
||
2867 |
skipInstvarIndexInDeepCopy:index |
|
2868 |
"a helper for deepCopy; only indices for which this method returns |
|
2869 |
false are copied in a deep copy. |
|
2870 |
The default is false here - which means that everything is copied. |
|
2871 |
Can be redefined in subclasses for partial copies" |
|
2872 |
||
2873 |
^ false |
|
2874 |
! |
|
2875 |
||
2876 |
slowShallowCopy |
|
2877 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2878 |
i.e. the copy shares referenced instvars with its original. |
|
2879 |
This method is only invoked as a fallback from #shallowCopy." |
|
2880 |
||
2881 |
|myClass aCopy| |
|
2882 |
||
2883 |
(myClass := self class) isVariable ifTrue:[ |
|
6654 | 2884 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2885 |
] ifFalse:[ |
6654 | 2886 |
aCopy := myClass basicNew |
5755 | 2887 |
]. |
2888 |
||
2889 |
"copy the instance variables" |
|
2890 |
aCopy cloneFrom:self performing:#yourself. |
|
2891 |
^ aCopy |
|
2892 |
! ! |
|
2893 |
||
2894 |
!Object methodsFor:'debugging'! |
|
2895 |
||
6961 | 2896 |
assert:aBoolean |
6964 | 2897 |
"fail, if the argument is not true and report an error" |
2898 |
||
6961 | 2899 |
"{ Pragma: +optSpace }" |
2900 |
||
2901 |
self assert:aBoolean message:'Assertion failed' |
|
2902 |
! |
|
2903 |
||
2904 |
assert:aBoolean message:messageIfFailing |
|
6964 | 2905 |
"fail, if the argument is not true and report an error" |
6961 | 2906 |
|
2907 |
"{ Pragma: +optSpace }" |
|
2908 |
||
2909 |
(aBoolean isBoolean) ifFalse:[ |
|
2910 |
self error:'non boolean assertion' |
|
2911 |
]. |
|
2912 |
aBoolean ifFalse:[ |
|
2913 |
self error:messageIfFailing |
|
2914 |
]. |
|
2915 |
! |
|
2916 |
||
5755 | 2917 |
basicInspect |
2918 |
"{ Pragma: +optSpace }" |
|
2919 |
||
2920 |
"launch an inspector on the receiver. |
|
2921 |
this method should NOT be redefined in subclasses." |
|
2922 |
||
2923 |
Inspector isNil ifTrue:[ |
|
6654 | 2924 |
" |
2925 |
for systems without GUI |
|
2926 |
" |
|
6926 | 2927 |
self warn:'No Inspector defined (Inspector is nil).' |
5755 | 2928 |
] ifFalse:[ |
6654 | 2929 |
Inspector openOn:self |
5755 | 2930 |
] |
2931 |
||
2932 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
2933 |
! |
|
2934 |
||
6954 | 2935 |
breakPoint:something |
2936 |
"{ Pragma: +optSpace }" |
|
2937 |
||
2938 |
"Like halt, but disabled by default. |
|
2939 |
Can be easily enabled. |
|
2940 |
Can be filtered on the arguments value (typically: a symbol). |
|
2941 |
Code with breakpoints may be even checked into the source repository" |
|
2942 |
||
2943 |
"Example: nil breakPoint:#stefan" |
|
2944 |
||
2945 |
"/ something = OperatingSystem getLoginName ifTrue:[ |
|
2946 |
"/ ^ HaltSignal raiseRequestWith:something errorString:'Breakpoint encountered: ', something printString |
|
2947 |
"/ ]. |
|
2948 |
||
2949 |
"/ something = 'testThis' ifTrue:[ |
|
2950 |
"/ ^ HaltSignal raiseRequestWith:something errorString:'Breakpoint encountered: ', something printString |
|
2951 |
"/ ]. |
|
2952 |
! |
|
2953 |
||
5995 | 2954 |
browse |
2955 |
"open a browser on the receivers class" |
|
2956 |
||
2957 |
self class theNonMetaclass browse |
|
2958 |
||
2959 |
" |
|
2960 |
10 browse |
|
2961 |
Collection browse |
|
2962 |
Collection class browse |
|
2963 |
" |
|
2964 |
! |
|
2965 |
||
5755 | 2966 |
inspect |
2967 |
"{ Pragma: +optSpace }" |
|
2968 |
||
2969 |
"launch an inspector on the receiver. |
|
2970 |
this method (or better: inspectorClass) can be redefined in subclasses |
|
2971 |
to start special inspectors." |
|
2972 |
||
2973 |
|cls| |
|
2974 |
||
2975 |
cls := self inspectorClass. |
|
2976 |
cls isNil ifTrue:[ |
|
6654 | 2977 |
^ self basicInspect |
5755 | 2978 |
]. |
2979 |
cls openOn:self |
|
2980 |
||
2981 |
" |
|
2982 |
Object new inspect |
|
2983 |
(1 @ 2) inspect |
|
2984 |
Smalltalk inspect |
|
2985 |
#(1 2 3) asOrderedCollection inspect |
|
2986 |
(Color red) inspect |
|
2987 |
(Image fromFile:'bitmaps/garfield.gif') inspect |
|
2988 |
" |
|
2989 |
! |
|
2990 |
||
2991 |
inspectorClass |
|
2992 |
"{ Pragma: +optSpace }" |
|
2993 |
||
2994 |
"return the class to use for inspect. |
|
2995 |
Can (should) be redefined in classes for which a better inspector is available" |
|
2996 |
||
2997 |
^ Inspector |
|
2998 |
! |
|
2999 |
||
3000 |
mustBeBoolean |
|
3001 |
"this message is sent by the VM, if a non-Boolean receiver is encountered |
|
3002 |
in an if* or while* message. |
|
3003 |
Caveat: for now, this is only sent by the interpreter; |
|
3004 |
both the JIT and the stc compiler treat it as undefined." |
|
3005 |
||
3006 |
self error:'Non boolean receiver - proceed for truth' mayProceed:true. |
|
3007 |
^ true |
|
3008 |
! |
|
3009 |
||
3010 |
mustBeKindOf:aClass |
|
3011 |
"for compatibility & debugging support: |
|
3012 |
check if the receiver isKindOf:aClass and raise an error if not. |
|
3013 |
Notice: |
|
6654 | 3014 |
it is VERY questionable, if it makes sense to add manual |
3015 |
type checks to a dynamically typed language like smalltalk. |
|
3016 |
It will, at least, slow down performance, |
|
3017 |
make your code less reusable and clutter your code with stupid sends |
|
3018 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
3019 |
use of isXXX check methods. |
|
5755 | 3020 |
You see: The author does not like this at all ..." |
3021 |
||
3022 |
(self isKindOf:aClass) ifFalse:[ |
|
6654 | 3023 |
self error:'argument is not of expected type' |
5755 | 3024 |
] |
3025 |
! |
|
3026 |
||
6950 | 3027 |
obsoleteFeatureWarning |
3028 |
"{ Pragma: +optSpace }" |
|
3029 |
||
3030 |
"in methods which are going to be changed, a send to |
|
3031 |
this method is used to tell programmers that some feature/semantics is |
|
3032 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3033 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)." |
6950 | 3034 |
|
3035 |
self obsoleteFeatureWarning:nil from:thisContext sender |
|
3036 |
! |
|
3037 |
||
3038 |
obsoleteFeatureWarning:message |
|
3039 |
"{ Pragma: +optSpace }" |
|
3040 |
||
3041 |
"in methods which are going to be changed, a send to |
|
3042 |
this method is used to tell programmers that some feature/semantics is |
|
3043 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3044 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3045 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3046 |
|
3047 |
self obsoleteFeatureWarning:message from:thisContext sender |
|
3048 |
! |
|
3049 |
||
3050 |
obsoleteFeatureWarning:message from:aContext |
|
3051 |
"{ Pragma: +optSpace }" |
|
3052 |
||
3053 |
"in methods which are going to be changed, a send to |
|
3054 |
this method is used to tell programmers that some feature/semantics is |
|
3055 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3056 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3057 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3058 |
|
3059 |
|spec| |
|
3060 |
||
3061 |
spec := aContext methodPrintString. |
|
3062 |
('WARNING: the ''' , spec , ''' semantics will be changed.') infoPrintCR. |
|
3063 |
(' Its behavior may be different in future ST/X versions.') infoPrintCR. |
|
3064 |
(' called from ' , aContext sender printString) infoPrintCR. |
|
7204 | 3065 |
(aContext sender selector startsWith:'perform:') ifTrue:[ |
3066 |
(' called from ' , aContext sender sender printString) infoPrintCR. |
|
3067 |
]. |
|
6950 | 3068 |
message notNil ifTrue:[ |
3069 |
'------> ' infoPrint. message infoPrintCR |
|
3070 |
] |
|
3071 |
||
3072 |
" |
|
3073 |
Object obsoleteFeatureWarning:'foo' from:thisContext sender sender |
|
3074 |
" |
|
3075 |
! |
|
3076 |
||
5755 | 3077 |
obsoleteMethodWarning |
3078 |
"{ Pragma: +optSpace }" |
|
3079 |
||
3080 |
"in methods which are going to be obsoleted, a self send to |
|
3081 |
this method is used to tell programmers that a method is |
|
3082 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3083 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3084 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3085 |
|
3086 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
3087 |
! |
|
3088 |
||
3089 |
obsoleteMethodWarning:message |
|
3090 |
"{ Pragma: +optSpace }" |
|
3091 |
||
3092 |
"in methods which are going to be obsoleted, a self send to |
|
3093 |
this method is used to tell programmers that a method is |
|
3094 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3095 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3096 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3097 |
|
3098 |
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
|
3099 |
! |
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 |
obsoleteMethodWarning:message from:aContext |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3102 |
"{ Pragma: +optSpace }" |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3103 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3104 |
"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
|
3105 |
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
|
3106 |
used which is going to be removed in later ST/X versions. |
6963 | 3107 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3108 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
|
3109 |
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
|
3110 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3111 |
|spec| |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3112 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3113 |
spec := aContext methodPrintString. |
6405
bbee0a853e2f
#obsoleteMethodWarning now uses infoPrint instead of errorPrint.
Stefan Vogel <sv@exept.de>
parents:
6388
diff
changeset
|
3114 |
('WARNING: the ''' , spec , ''' method is obsolete.') infoPrintCR. |
bbee0a853e2f
#obsoleteMethodWarning now uses infoPrint instead of errorPrint.
Stefan Vogel <sv@exept.de>
parents:
6388
diff
changeset
|
3115 |
(' 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
|
3116 |
(' called from ' , aContext sender printString) infoPrintCR. |
7204 | 3117 |
(aContext sender selector startsWith:'perform:') ifTrue:[ |
3118 |
(' called from ' , aContext sender sender printString) infoPrintCR. |
|
3119 |
]. |
|
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3120 |
message notNil ifTrue:[ |
6654 | 3121 |
'------> ' infoPrint. message infoPrintCR |
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3122 |
] |
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 |
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
|
3126 |
" |
5755 | 3127 |
! ! |
3128 |
||
3129 |
!Object methodsFor:'dependents access'! |
|
3130 |
||
3131 |
addDependent:anObject |
|
3132 |
"make the argument, anObject be a dependent of the receiver" |
|
3133 |
||
3134 |
|wasBlocked| |
|
3135 |
||
3136 |
"/ must do this save from interrupts, since the dependents collection |
|
3137 |
"/ is possibly accessed from multiple threads. |
|
3138 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3139 |
"/ faster execution. |
|
3140 |
||
3141 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3142 |
[ |
|
6654 | 3143 |
|deps dep| |
3144 |
||
3145 |
deps := self dependents. |
|
3146 |
||
3147 |
"/ to save a fair amount of memory in case of |
|
3148 |
"/ many dependencies, we store a single dependent in |
|
3149 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3150 |
"/ added. |
|
3151 |
||
3152 |
(deps isNil or:[deps size == 0]) ifTrue:[ |
|
3153 |
self dependents:(WeakArray with:anObject) |
|
3154 |
] ifFalse:[ |
|
3155 |
deps class == WeakArray ifTrue:[ |
|
3156 |
dep := deps at:1. |
|
3157 |
dep ~~ anObject ifTrue:[ |
|
3158 |
(dep isNil or:[dep == 0]) ifTrue:[ |
|
3159 |
deps at:1 put:anObject |
|
3160 |
] ifFalse:[ |
|
3161 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
3162 |
] |
|
3163 |
] |
|
3164 |
] ifFalse:[ |
|
3165 |
deps add:anObject |
|
3166 |
] |
|
3167 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3168 |
] ensure:[ |
6654 | 3169 |
wasBlocked ifFalse:[ |
3170 |
OperatingSystem unblockInterrupts |
|
3171 |
] |
|
5755 | 3172 |
] |
3173 |
||
3174 |
"Modified: / 27.10.1997 / 19:35:52 / cg" |
|
3175 |
! |
|
3176 |
||
3177 |
breakDependents |
|
3178 |
"remove all dependencies from the receiver" |
|
3179 |
||
3180 |
self dependents:nil. |
|
3181 |
self nonWeakDependents:nil |
|
3182 |
||
3183 |
"Modified: / 19.4.1996 / 10:55:36 / cg" |
|
3184 |
"Created: / 27.2.1998 / 11:26:11 / stefan" |
|
3185 |
! |
|
3186 |
||
3187 |
dependents |
|
3188 |
"return a Collection of dependents. |
|
3189 |
The default implementation here uses a global WeakDictionary to store |
|
3190 |
dependents |
|
3191 |
This may be too slow for high frequency change&update, |
|
3192 |
therefore, some classes (Model) redefine this for better performance. |
|
3193 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
3194 |
||
3195 |
|deps| |
|
3196 |
||
3197 |
(deps := Dependencies at:self ifAbsent:nil) isNil ifTrue:[ |
|
6654 | 3198 |
^ #(). |
5755 | 3199 |
]. |
3200 |
^ deps |
|
3201 |
||
3202 |
"Modified: / 26.1.1998 / 11:18:15 / cg" |
|
3203 |
! |
|
3204 |
||
3205 |
dependents:aCollection |
|
3206 |
"set the collection of dependents. |
|
3207 |
The default implementation here uses a global Dictionary to store |
|
3208 |
dependents which may be too slow for high frequency change&update. |
|
3209 |
Therefore, some classes (Model) redefine this for better performance." |
|
3210 |
||
3211 |
"/ must do this save from interrupts, since the dependents collection |
|
3212 |
"/ is possibly accessed from multiple threads. |
|
3213 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3214 |
"/ faster execution (and to avoid creation of garbage blocks). |
|
3215 |
||
3216 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
6654 | 3217 |
"/ the common case - already blocked |
3218 |
||
3219 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
3220 |
Dependencies removeKey:self ifAbsent:nil |
|
3221 |
] ifFalse:[ |
|
3222 |
Dependencies at:self put:aCollection |
|
3223 |
]. |
|
3224 |
^ self |
|
5755 | 3225 |
]. |
3226 |
||
3227 |
[ |
|
6654 | 3228 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3229 |
Dependencies removeKey:self ifAbsent:nil |
|
3230 |
] ifFalse:[ |
|
3231 |
Dependencies at:self put:aCollection |
|
3232 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3233 |
] ensure:[ |
6654 | 3234 |
OperatingSystem unblockInterrupts |
5755 | 3235 |
] |
3236 |
||
3237 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
|
3238 |
! |
|
3239 |
||
3240 |
dependentsDo:aBlock |
|
3241 |
"evaluate aBlock for all of my dependents" |
|
3242 |
||
3243 |
|deps nwDeps| |
|
3244 |
||
3245 |
deps := self dependents. |
|
3246 |
deps size ~~ 0 ifTrue:[ |
|
6654 | 3247 |
deps do:[:d | |
3248 |
(d notNil and:[d ~~ 0]) ifTrue:[ |
|
3249 |
aBlock value:d |
|
3250 |
] |
|
3251 |
] |
|
5755 | 3252 |
]. |
3253 |
nwDeps := self nonWeakDependents. |
|
3254 |
(nwDeps ~~ deps and:[nwDeps size ~~ 0]) ifTrue:[ |
|
6654 | 3255 |
nwDeps do:aBlock |
5755 | 3256 |
]. |
3257 |
||
3258 |
"Modified: / 30.1.1998 / 14:03:40 / cg" |
|
3259 |
! |
|
3260 |
||
3261 |
myDependents |
|
3262 |
"same as dependents - ST-80 compatibility" |
|
3263 |
||
3264 |
^ self dependents |
|
3265 |
! |
|
3266 |
||
3267 |
release |
|
3268 |
"remove all references to objects that may refer to self. |
|
3269 |
Subclasses may redefine this method but should do a 'super release'." |
|
3270 |
||
3271 |
self breakDependents |
|
3272 |
||
3273 |
"Modified: / 27.2.1998 / 11:29:35 / stefan" |
|
3274 |
! |
|
3275 |
||
3276 |
removeDependent:anObject |
|
3277 |
"make the argument, anObject be independent of the receiver" |
|
3278 |
||
3279 |
|wasBlocked| |
|
3280 |
||
3281 |
"/ must do this save from interrupts, since the dependents collection |
|
3282 |
"/ is possibly accessed from multiple threads. |
|
3283 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3284 |
"/ faster execution. |
|
3285 |
||
3286 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3287 |
[ |
|
6654 | 3288 |
|deps n d| |
3289 |
||
3290 |
deps := self dependents. |
|
3291 |
deps size ~~ 0 ifTrue:[ |
|
3292 |
||
3293 |
"/ to save a fair amount of memory in case of |
|
3294 |
"/ many dependencies, we store a single dependent in |
|
3295 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3296 |
"/ added. Here we have to do the inverse ... |
|
3297 |
||
3298 |
deps class == WeakArray ifTrue:[ |
|
3299 |
((d := deps at:1) == anObject |
|
3300 |
or:[d isNil |
|
3301 |
or:[d == 0]]) ifTrue:[ |
|
3302 |
self dependents:nil |
|
3303 |
] |
|
3304 |
] ifFalse:[ |
|
3305 |
deps remove:anObject ifAbsent:[]. |
|
3306 |
(n := deps size) == 0 ifTrue:[ |
|
3307 |
self dependents:nil |
|
3308 |
] ifFalse:[ |
|
3309 |
n == 1 ifTrue:[ |
|
3310 |
d := deps firstIfEmpty:nil. |
|
3311 |
d notNil ifTrue:[ |
|
3312 |
deps := WeakArray with:d |
|
3313 |
] ifFalse:[ |
|
3314 |
deps := nil |
|
3315 |
]. |
|
3316 |
self dependents:deps. |
|
3317 |
] |
|
3318 |
] |
|
3319 |
] |
|
3320 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3321 |
] ensure:[ |
6654 | 3322 |
wasBlocked ifFalse:[ |
3323 |
OperatingSystem unblockInterrupts |
|
3324 |
] |
|
5755 | 3325 |
] |
3326 |
||
3327 |
"Modified: / 26.1.1998 / 19:51:50 / cg" |
|
3328 |
! ! |
|
3329 |
||
7266 | 3330 |
!Object methodsFor:'dependents access (non weak)'! |
5755 | 3331 |
|
3332 |
addNonWeakDependent:anObject |
|
3333 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
|
3334 |
Be careful: this nonWeakDependency will prevent the dependent from being |
|
3335 |
garbage collected unless the dependency is removed. |
|
3336 |
This is a private mechanism, for directed dependencies." |
|
3337 |
||
3338 |
|wasBlocked| |
|
3339 |
||
3340 |
"/ must do this save from interrupts, since the dependents collection |
|
3341 |
"/ is possibly accessed from multiple threads. |
|
3342 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3343 |
"/ faster execution. |
|
3344 |
||
3345 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3346 |
[ |
|
6654 | 3347 |
|deps dep| |
3348 |
||
3349 |
deps := self nonWeakDependents. |
|
3350 |
||
3351 |
"/ to save a fair amount of memory in case of |
|
3352 |
"/ many dependencies, we store a single dependent in |
|
3353 |
"/ an Array, and switch to a Set if more dependents are |
|
3354 |
"/ added. |
|
3355 |
||
3356 |
deps size == 0 ifTrue:[ |
|
3357 |
self nonWeakDependents:(Array with:anObject) |
|
3358 |
] ifFalse:[ |
|
3359 |
deps class == Array ifTrue:[ |
|
3360 |
dep := deps at:1. |
|
3361 |
dep ~~ anObject ifTrue:[ |
|
3362 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
3363 |
] |
|
3364 |
] ifFalse:[ |
|
3365 |
deps add:anObject |
|
3366 |
] |
|
3367 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3368 |
] ensure:[ |
6654 | 3369 |
wasBlocked ifFalse:[ |
3370 |
OperatingSystem unblockInterrupts |
|
3371 |
] |
|
5755 | 3372 |
] |
3373 |
||
3374 |
"Created: / 19.4.1996 / 10:54:08 / cg" |
|
3375 |
"Modified: / 30.1.1998 / 14:03:08 / cg" |
|
3376 |
! |
|
3377 |
||
3378 |
nonWeakDependents |
|
3379 |
"return a Collection of nonWeakDependents - empty if there is none. |
|
3380 |
This is a private mechanism for directed dependencies." |
|
3381 |
||
3382 |
NonWeakDependencies isNil ifTrue:[^ #()]. |
|
3383 |
^ NonWeakDependencies at:self ifAbsent:#() |
|
3384 |
||
3385 |
"Created: / 19.4.1996 / 10:55:06 / cg" |
|
3386 |
"Modified: / 30.1.1998 / 14:06:47 / cg" |
|
3387 |
! |
|
3388 |
||
3389 |
nonWeakDependents:aCollection |
|
3390 |
"set the collection of nonWeak dependents. |
|
3391 |
This is a private helper for directed dependencies." |
|
3392 |
||
3393 |
[ |
|
6654 | 3394 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3395 |
NonWeakDependencies removeKey:self ifAbsent:nil |
|
3396 |
] ifFalse:[ |
|
3397 |
NonWeakDependencies at:self put:aCollection |
|
3398 |
] |
|
5755 | 3399 |
] valueUninterruptably |
3400 |
||
3401 |
"Created: 19.4.1996 / 11:07:47 / cg" |
|
3402 |
! |
|
3403 |
||
3404 |
removeNonWeakDependent:anObject |
|
3405 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
|
3406 |
(i.e. make it independent of the receiver)" |
|
3407 |
||
3408 |
|wasBlocked| |
|
3409 |
||
3410 |
"/ must do this save from interrupts, since the dependents collection |
|
3411 |
"/ is possibly accessed from multiple threads. |
|
3412 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3413 |
"/ faster execution. |
|
3414 |
||
3415 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3416 |
[ |
|
6654 | 3417 |
|deps n| |
3418 |
||
3419 |
deps := self nonWeakDependents. |
|
3420 |
deps size ~~ 0 ifTrue:[ |
|
3421 |
deps class == Array ifTrue:[ |
|
3422 |
(deps at:1) == anObject ifTrue:[ |
|
3423 |
self nonWeakDependents:nil |
|
3424 |
] |
|
3425 |
] ifFalse:[ |
|
3426 |
deps remove:anObject ifAbsent:[]. |
|
3427 |
(n := deps size) == 0 ifTrue:[ |
|
3428 |
self nonWeakDependents:nil |
|
3429 |
] ifFalse:[ |
|
3430 |
n == 1 ifTrue:[ |
|
3431 |
self nonWeakDependents:(Array with:(deps first)) |
|
3432 |
] |
|
3433 |
] |
|
3434 |
] |
|
3435 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3436 |
] ensure:[ |
6654 | 3437 |
wasBlocked ifFalse:[ |
3438 |
OperatingSystem unblockInterrupts |
|
3439 |
] |
|
5755 | 3440 |
] |
3441 |
||
3442 |
"Created: / 19.4.1996 / 11:44:44 / cg" |
|
3443 |
"Modified: / 30.1.1998 / 14:04:01 / cg" |
|
3444 |
! ! |
|
3445 |
||
3446 |
!Object methodsFor:'displaying'! |
|
3447 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3448 |
ascentOn:aGC |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3449 |
"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
|
3450 |
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
|
3451 |
coordinate is given by y. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3452 |
In other words: some draw above the given y coordinate. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3453 |
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
|
3454 |
the given y coordinate." |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3455 |
|
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3456 |
^ (aGC font onDevice:aGC device) ascent |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3457 |
! |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3458 |
|
6900 | 3459 |
displayOn:aGCOrStream |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3460 |
"Compatibility |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3461 |
append a printed desription on some stream (Dolphin, Squeak) |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3462 |
OR: |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3463 |
display the receiver in a graphicsContext at 0@0 (ST80). |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3464 |
This method allows for any object to be displayed in some view |
5755 | 3465 |
(although the fallBack is to display its printString ...)" |
3466 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3467 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3468 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
6900 | 3469 |
(aGCOrStream isStream or:[aGCOrStream == Transcript]) ifTrue:[ |
3470 |
self printOn:aGCOrStream. |
|
3471 |
^ self |
|
3472 |
]. |
|
3473 |
^ self displayOn:aGCOrStream x:0 y:0. |
|
5755 | 3474 |
|
3475 |
"Created: 29.5.1996 / 16:28:58 / cg" |
|
3476 |
! |
|
3477 |
||
3478 |
displayOn:aGC at:aPoint |
|
3479 |
"ST-80 Compatibility |
|
3480 |
display the receiver in a graphicsContext - this method allows |
|
3481 |
for any object to be displayed in a ListView - for example." |
|
3482 |
||
3483 |
^ self displayOn:aGC x:(aPoint x) y:(aPoint y). |
|
3484 |
! |
|
3485 |
||
3486 |
displayOn:aGC x:x y:y |
|
3487 |
"display the receiver in a graphicsContext - this method allows |
|
3488 |
for any object to be displayed in a ListView - for example." |
|
3489 |
||
3490 |
self displayOn:aGC x:x y:y opaque:false |
|
3491 |
||
3492 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3493 |
! |
|
3494 |
||
3495 |
displayOn:aGc x:x y:y opaque:opaque |
|
3496 |
"display the receiver in a graphicsContext - this method allows |
|
3497 |
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
|
3498 |
The fallBack here shows the receivers displayString. |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3499 |
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
|
3500 |
ask using #ascentOn: if required" |
5755 | 3501 |
|
3502 |
|s yBaseline| |
|
3503 |
||
3504 |
s := self displayString. |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3505 |
yBaseline := y "+ aGc font ascent". |
5755 | 3506 |
opaque ifTrue:[ |
6654 | 3507 |
aGc displayOpaqueString:s x:x y:yBaseline. |
5755 | 3508 |
] ifFalse:[ |
6654 | 3509 |
aGc displayString:s x:x y:yBaseline. |
5755 | 3510 |
]. |
3511 |
||
3512 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3513 |
! |
|
3514 |
||
3515 |
displayOpaqueOn:aGC x:x y:y |
|
3516 |
"display the receiver in a graphicsContext - this method allows |
|
3517 |
for any object to be displayed in a ListView - for example." |
|
3518 |
||
3519 |
self displayOn:aGC x:x y:y opaque:true |
|
3520 |
||
3521 |
"Modified: / 29.5.1996 / 16:29:38 / cg" |
|
3522 |
"Created: / 26.10.1997 / 15:01:36 / cg" |
|
3523 |
! |
|
3524 |
||
3525 |
displayString |
|
3526 |
"return a string used when displaying the receiver in a view; |
|
3527 |
for example an Inspector. This is usually the same as printString, |
|
3528 |
but sometimes redefined for a better look." |
|
3529 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3530 |
|s| |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3531 |
|
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3532 |
s := '' writeStream. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3533 |
self displayOn:s. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3534 |
^ s contents |
5755 | 3535 |
|
3536 |
" |
|
3537 |
#(1 2 3) printString |
|
3538 |
#(1 2 3) displayString |
|
3539 |
#(1 2 3) storeString |
|
3540 |
" |
|
3541 |
! |
|
3542 |
||
3543 |
heightOn:aGC |
|
3544 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
3545 |
||
3546 |
^ (aGC font onDevice:aGC device) heightOf:(self displayString) |
|
3547 |
! |
|
3548 |
||
6654 | 3549 |
widthFrom:startIndex to:endIndex on:aGC |
3550 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3551 |
||
3552 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) from:startIndex to:endIndex |
|
3553 |
! |
|
3554 |
||
5755 | 3555 |
widthOn:aGC |
3556 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3557 |
||
3558 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) |
|
3559 |
! ! |
|
3560 |
||
3561 |
!Object methodsFor:'encoding & decoding'! |
|
3562 |
||
3563 |
decodeAsLiteralArray |
|
3564 |
^ self |
|
3565 |
! |
|
3566 |
||
3567 |
encodeOn:anEncoder with:aParameter |
|
3568 |
"double-dispatch onto an ObjectEncoder. |
|
3569 |
Subclasses redefine this" |
|
3570 |
||
3571 |
anEncoder encodeObject:self with:aParameter |
|
3572 |
||
3573 |
||
3574 |
! |
|
3575 |
||
6718 | 3576 |
encodingVectorFor:aspect |
3577 |
"answer a collection of associations containing the |
|
3578 |
objects state to be encoded for aspect. |
|
3579 |
Association key is the instance variable name or access selector, |
|
3580 |
association value is the contents of the instance variable. |
|
3581 |
||
3582 |
The default is to return the contents of all instance variables" |
|
3583 |
||
3584 |
|ret| |
|
3585 |
||
3586 |
ret := self perform:aspect ifNotUnderstood:[0]. |
|
3587 |
ret == 0 ifTrue:[ |
|
3588 |
^ self encodingVectorForNonNilInstanceVariables |
|
3589 |
]. |
|
3590 |
^ ret. |
|
3591 |
! |
|
3592 |
||
3593 |
encodingVectorForInstanceVariables |
|
3594 |
"return all instance variables for encoding" |
|
3595 |
||
7112 | 3596 |
^ self encodingVectorForInstanceVariablesMatching:[:val | true]. |
3597 |
||
3598 |
" |
|
3599 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
3600 |
Dictionary new encodingVectorForInstanceVariables |
|
3601 |
(5 @ nil) encodingVectorForInstanceVariables |
|
3602 |
" |
|
3603 |
! |
|
3604 |
||
3605 |
encodingVectorForInstanceVariablesMatching:aBlock |
|
3606 |
"return all instance variables for which aBlock returns true, for encoding. |
|
3607 |
Indexed vars are all included." |
|
3608 |
||
6718 | 3609 |
|instVarNames theClass children |
3610 |
instSize "{ Class: SmallInteger }" |
|
3611 |
varSize "{ Class: SmallInteger }"| |
|
3612 |
||
3613 |
theClass := self class. |
|
3614 |
||
3615 |
instSize := theClass instSize. |
|
3616 |
varSize := theClass isVariable ifTrue:[self basicSize] ifFalse:[0]. |
|
3617 |
children := OrderedCollection new:(instSize + varSize). |
|
3618 |
||
3619 |
instVarNames := theClass allInstVarNames. |
|
3620 |
1 to:instSize do:[:i | |var| |
|
3621 |
var := self instVarAt:i. |
|
7112 | 3622 |
(aBlock value:var) ifTrue:[ |
3623 |
children add:((instVarNames at:i) -> var) |
|
3624 |
] |
|
6718 | 3625 |
]. |
3626 |
||
3627 |
varSize ~~ 0 ifTrue:[ |
|
3628 |
1 to:varSize do:[:i | |
|
3629 |
children add:(i -> (self basicAt:i)) |
|
3630 |
] |
|
3631 |
]. |
|
3632 |
||
3633 |
^ children. |
|
3634 |
||
3635 |
" |
|
3636 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
3637 |
Dictionary new encodingVectorForInstanceVariables |
|
3638 |
(5 @ nil) encodingVectorForInstanceVariables |
|
3639 |
" |
|
3640 |
! |
|
3641 |
||
3642 |
encodingVectorForNonNilInstanceVariables |
|
3643 |
"return all instance variables for encoding" |
|
3644 |
||
7112 | 3645 |
^ self encodingVectorForInstanceVariablesMatching:[:varVal | varVal notNil]. |
6718 | 3646 |
|
3647 |
" |
|
3648 |
#(1 2 3 nil true symbol) encodingVectorForNonNilInstanceVariables |
|
3649 |
(5 @ nil) encodingVectorForNonNilInstanceVariables |
|
3650 |
" |
|
3651 |
! |
|
3652 |
||
5755 | 3653 |
fromLiteralArrayEncoding:aSpecArray |
3654 |
"read my attributes from aSpecArray |
|
3655 |
" |
|
3656 |
|sel val |
|
3657 |
stop "{ Class:SmallInteger }" | |
|
3658 |
||
3659 |
stop := aSpecArray size. |
|
3660 |
||
3661 |
2 to:stop by:2 do:[:i| |
|
6654 | 3662 |
sel := aSpecArray at:i. |
3663 |
val := aSpecArray at:i + 1. |
|
3664 |
||
3665 |
(self respondsTo:sel) ifTrue:[ |
|
3666 |
self perform:sel with:(val decodeAsLiteralArray) |
|
3667 |
] ifFalse:[ |
|
3668 |
Transcript show:self class name; show:': unhandled literalArrayEncoding attribute: '. |
|
3669 |
Transcript showCR:sel. |
|
3670 |
] |
|
5755 | 3671 |
] |
3672 |
||
3673 |
||
3674 |
! |
|
3675 |
||
3676 |
literalArrayEncoding |
|
3677 |
"generate a literalArrayEncoding array for myself. |
|
3678 |
This uses #literalArrayEncodingSlotOrder which defines the slots and |
|
3679 |
order and #skippedInLiteralEncoding which defines slots to skip. |
|
3680 |
For most subclasses, there is no need to redefine those." |
|
3681 |
||
3682 |
|names encoding cls skipped| |
|
3683 |
||
3684 |
self isLiteral ifTrue:[ |
|
6654 | 3685 |
^ self |
5755 | 3686 |
]. |
3687 |
||
3688 |
skipped := self skippedInLiteralEncoding. |
|
3689 |
cls := self class. |
|
3690 |
names := cls allInstVarNames. |
|
3691 |
encoding := OrderedCollection with:(cls name). |
|
3692 |
||
3693 |
(self literalArrayEncodingSlotOrder) do:[:instSlot | |
|
6654 | 3694 |
|value nm| |
3695 |
||
3696 |
nm := names at:instSlot. |
|
3697 |
||
3698 |
(skipped includes:nm) ifFalse:[ |
|
3699 |
(value := self instVarAt:instSlot) notNil ifTrue:[ |
|
3700 |
encoding add:(nm , ':') asSymbol. |
|
3701 |
encoding add:value literalArrayEncoding |
|
3702 |
] |
|
3703 |
] |
|
5755 | 3704 |
]. |
3705 |
^ encoding asArray |
|
3706 |
||
3707 |
||
3708 |
! |
|
3709 |
||
3710 |
literalArrayEncodingSlotOrder |
|
3711 |
"define the order in which inst-slots are saved when generating |
|
3712 |
a literalArrayEncoding |
|
3713 |
" |
|
3714 |
^ 1 to:self class instSize |
|
3715 |
||
3716 |
! |
|
3717 |
||
7112 | 3718 |
postDecodeFrom:aDecoder aspect:aspectSymbol |
3719 |
"invoked by xmlDecoder (and others in the future), after an |
|
3720 |
object has been decoded (i.e. its instance variables have been restored)" |
|
3721 |
||
3722 |
"/ intentionally left blank |
|
3723 |
! |
|
3724 |
||
5755 | 3725 |
skippedInLiteralEncoding |
3726 |
"return a Collection with it's elements are slots for skipping |
|
3727 |
" |
|
3728 |
^ #() |
|
3729 |
||
3730 |
! ! |
|
3731 |
||
3732 |
!Object methodsFor:'error handling'! |
|
3733 |
||
3734 |
appropriateDebugger:aSelector |
|
3735 |
"{ Pragma: +optSpace }" |
|
3736 |
||
3737 |
"return an appropriate debugger to use. |
|
3738 |
If there is already a debugger active on the stack, and it is |
|
3739 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
3740 |
||
3741 |
|context| |
|
3742 |
||
3743 |
"DebugView cannot run without system processes" |
|
3744 |
||
3745 |
(Processor isNil |
|
3746 |
or:[Processor activeProcessIsSystemProcess |
|
3747 |
or:[Smalltalk isInitialized not]]) ifTrue:[ |
|
6654 | 3748 |
^ MiniDebugger |
5755 | 3749 |
]. |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
3750 |
(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
|
3751 |
Debugger isNil ifTrue:[^ nil]. |
6654 | 3752 |
^ MiniDebugger |
5755 | 3753 |
]. |
3754 |
||
3755 |
context := thisContext. |
|
3756 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
3757 |
[context notNil] whileTrue:[ |
|
6654 | 3758 |
((context receiver class == Debugger) |
3759 |
and:[context selector == aSelector]) ifTrue:[ |
|
3760 |
"we are already in some Debugger" |
|
3761 |
(Debugger == MiniDebugger) ifTrue:[ |
|
3762 |
"we are already in the MiniDebugger" |
|
3763 |
ErrorRecursion ifFalse:[ |
|
3764 |
Smalltalk fatalAbort:'recursive error ...' |
|
3765 |
] |
|
3766 |
]. |
|
3767 |
MiniDebugger isNil ifTrue:[ |
|
3768 |
Smalltalk fatalAbort:'no debugger' |
|
3769 |
]. |
|
3770 |
||
3771 |
"ok, an error occured while in the graphical debugger; |
|
3772 |
lets try MiniDebugger" |
|
3773 |
^ MiniDebugger |
|
3774 |
]. |
|
3775 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
5755 | 3776 |
]. |
3777 |
"not within Debugger - no problem" |
|
3778 |
^ Debugger |
|
3779 |
||
3780 |
"Modified: / 23.9.1996 / 12:14:52 / stefan" |
|
3781 |
"Modified: / 19.5.1999 / 18:05:00 / cg" |
|
3782 |
! |
|
3783 |
||
3784 |
cannotSendMessage:aMessage to:someReceiver |
|
3785 |
"this message is sent by the runtime system (VM), |
|
3786 |
when a message is sent to some object, whose class is not |
|
3787 |
a valid behavior (see documentation in Behavior)." |
|
3788 |
||
3789 |
^ InternalErrorSignal |
|
6654 | 3790 |
raiseWith:someReceiver |
3791 |
errorString:('bad class in send of #' , aMessage selector) |
|
5755 | 3792 |
|
3793 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
3794 |
! |
|
3795 |
||
3796 |
doesNotUnderstand:aMessage |
|
3797 |
"this message is sent by the runtime system (VM) when |
|
3798 |
a message is not understood by some object (i.e. there |
|
3799 |
is no method for that selector). The original message has |
|
3800 |
been packed into aMessage (i.e. the receiver, selector and |
|
3801 |
any arguments) and the original receiver is then sent the |
|
3802 |
#doesNotUnderstand: message. |
|
3803 |
Here, we raise another signal which usually enters the debugger. |
|
3804 |
You can of course redefine #doesNotUnderstand: in your classes |
|
3805 |
to implement message delegation, |
|
3806 |
or handle the MessageNotUnderstoodSignal gracefully." |
|
3807 |
||
3808 |
<context: #return> |
|
3809 |
||
5821 | 3810 |
|sel selStr errorString cls| |
5755 | 3811 |
|
3812 |
sel := aMessage selector. |
|
3813 |
selStr := sel printString. |
|
3814 |
||
3815 |
"/ Although sel should always be a symbol, |
|
3816 |
"/ always use printStrings in the code below. |
|
3817 |
"/ Non-symbol selector may happen when things go mad in a primitive, |
|
3818 |
"/ or a method has been called by valueWithReceiver: with a wrong arg. |
|
3819 |
||
3820 |
"/ handle the case of an error during early startup |
|
3821 |
"/ (output streams not yet initialized) |
|
3822 |
||
3823 |
Stdout isNil ifTrue:[ |
|
6654 | 3824 |
Smalltalk fatalAbort:'error during init: ' , selStr , ' not understood'. |
5755 | 3825 |
]. |
3826 |
||
3827 |
"/ |
|
3828 |
"/ extract the class that should have implemented the message. |
|
3829 |
"/ (in case of a super-send, this is not the receivers class) |
|
3830 |
"/ |
|
3831 |
cls := thisContext sender searchClass. |
|
3832 |
cls isNil ifTrue:[ |
|
6654 | 3833 |
"it was NOT a super or directed send ..." |
3834 |
cls := self class |
|
5755 | 3835 |
]. |
3836 |
||
3837 |
cls notNil ifTrue:[ |
|
6654 | 3838 |
"/ |
3839 |
"/ displayString is better than 'cls name', |
|
3840 |
"/ since it appends (obsolete) for outdated classes. |
|
3841 |
"/ (this happens if you send messages to old instances |
|
3842 |
"/ after changing a classes definition) |
|
3843 |
"/ |
|
3844 |
errorString := cls displayString. |
|
5755 | 3845 |
] ifFalse:[ |
6654 | 3846 |
errorString := '(** nil-class **)' |
5755 | 3847 |
]. |
3848 |
sel class ~~ Symbol ifTrue:[ |
|
6654 | 3849 |
errorString := errorString , ' nonSymbol selector: ' , selStr , ' not understood'. |
5755 | 3850 |
] ifFalse:[ |
6654 | 3851 |
errorString := errorString , ' does not understand: ' , selStr. |
5755 | 3852 |
]. |
3853 |
||
3854 |
"/ |
|
3855 |
"/ this only happens, when YOU play around with my classvars ... |
|
3856 |
"/ (or an error occurs during very early startup, when signals are not yet set) |
|
3857 |
"/ |
|
6146 | 3858 |
MessageNotUnderstood isNil ifTrue:[ |
6654 | 3859 |
^ MiniDebugger |
3860 |
enterWithMessage:'oops - MessageNotUnderstoodSignal is gone (nil)' |
|
3861 |
mayProceed:true. |
|
5755 | 3862 |
]. |
3863 |
||
3864 |
"/ |
|
3865 |
"/ thats where we end up normally - raise a signal which (if unhandled) opens a debugger |
|
3866 |
"/ |
|
6146 | 3867 |
^ MessageNotUnderstood |
6654 | 3868 |
raiseRequestWith:aMessage |
3869 |
errorString:errorString |
|
5755 | 3870 |
|
3871 |
"Modified: / 9.6.1999 / 17:46:17 / cg" |
|
3872 |
! |
|
3873 |
||
3874 |
elementBoundsError |
|
3875 |
"{ Pragma: +optSpace }" |
|
3876 |
||
3877 |
"report an error that badElement is out of bounds |
|
3878 |
(i.e. cannot be put into that collection). |
|
3879 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3880 |
||
3881 |
^ ElementOutOfBoundsSignal raise |
|
3882 |
||
3883 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
3884 |
! |
|
3885 |
||
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3886 |
elementBoundsError:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3887 |
"{ Pragma: +optSpace }" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3888 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3889 |
"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
|
3890 |
(i.e. cannot be put into that collection). |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3891 |
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
|
3892 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3893 |
^ ElementOutOfBoundsSignal raiseWith:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3894 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3895 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3896 |
! |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3897 |
|
5755 | 3898 |
elementNotCharacter |
3899 |
"{ Pragma: +optSpace }" |
|
3900 |
||
3901 |
"report an error that object to be stored is no Character. |
|
3902 |
(usually when storing into Strings). |
|
3903 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3904 |
||
3905 |
^ ElementOutOfBoundsSignal raise |
|
3906 |
||
3907 |
"Modified: 8.5.1996 / 09:12:49 / cg" |
|
3908 |
! |
|
3909 |
||
3910 |
elementNotInteger |
|
3911 |
"{ Pragma: +optSpace }" |
|
3912 |
||
3913 |
"report an error that object to be stored is not Integer. |
|
3914 |
(in collections that store integers only). |
|
3915 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3916 |
||
3917 |
^ ElementOutOfBoundsSignal raise |
|
3918 |
||
3919 |
"Modified: 8.5.1996 / 09:12:51 / cg" |
|
3920 |
! |
|
3921 |
||
3922 |
error |
|
3923 |
"{ Pragma: +optSpace }" |
|
3924 |
||
3925 |
<context: #return> |
|
3926 |
||
3927 |
"report error that an error occured. |
|
3928 |
The error is reported by raising the Error exception, |
|
3929 |
which is non-proceedable. |
|
3930 |
If no handler has been setup, a debugger is entered." |
|
3931 |
||
3932 |
Error raiseWith:#error: |
|
3933 |
||
3934 |
" |
|
3935 |
nil error |
|
3936 |
" |
|
3937 |
||
3938 |
"Modified: / 8.5.1996 / 09:13:01 / cg" |
|
3939 |
"Modified: / 2.8.1999 / 17:00:19 / stefan" |
|
3940 |
! |
|
3941 |
||
3942 |
error:aString |
|
3943 |
"{ Pragma: +optSpace }" |
|
3944 |
||
3945 |
<context: #return> |
|
3946 |
||
3947 |
"Raise an error with error message aString. |
|
3948 |
The error is reported by raising the Error exception, |
|
3949 |
which is non-proceedable. |
|
3950 |
If no handler has been setup, a debugger is entered." |
|
3951 |
||
3952 |
Error raiseWith:#error: errorString:aString |
|
3953 |
||
3954 |
" |
|
3955 |
nil error:' bad bad bad' |
|
3956 |
" |
|
3957 |
||
3958 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
3959 |
! |
|
3960 |
||
3961 |
error:aString mayProceed:mayProceed |
|
3962 |
"{ Pragma: +optSpace }" |
|
3963 |
||
3964 |
"enter debugger with error-message aString. |
|
3965 |
The error is reported by raising either the |
|
3966 |
non-proceedable Error exception, |
|
3967 |
or the ProceedableError exception." |
|
3968 |
||
3969 |
mayProceed ifTrue:[ |
|
6654 | 3970 |
^ ProceedableError raiseRequestWith:#error: errorString:aString |
5755 | 3971 |
]. |
3972 |
||
3973 |
Error raiseWith:#error: errorString:aString |
|
3974 |
||
3975 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
3976 |
! |
|
3977 |
||
6900 | 3978 |
errorInvalidFormat |
3979 |
"{ Pragma: +optSpace }" |
|
3980 |
||
3981 |
<context: #return> |
|
3982 |
||
3983 |
"report an error that some conversion to/from string representation failed |
|
3984 |
typically when converting numbers, date, time etc." |
|
3985 |
||
3986 |
^ ConversionError raiseErrorString:'invalid format' |
|
3987 |
! |
|
3988 |
||
5755 | 3989 |
errorKeyNotFound:aKey |
3990 |
"{ Pragma: +optSpace }" |
|
3991 |
||
3992 |
"report an error that a key was not found in a collection. |
|
3993 |
The error is reported by raising the KeyNotFoundSignal exception." |
|
3994 |
||
3995 |
^ KeyNotFoundSignal raiseRequestWith:aKey |
|
3996 |
||
3997 |
" |
|
3998 |
#(1 2) at:3 |
|
3999 |
" |
|
4000 |
! |
|
4001 |
||
4002 |
errorNotFound |
|
4003 |
"{ Pragma: +optSpace }" |
|
4004 |
||
4005 |
"report an error that no element was found in a collection. |
|
4006 |
The error is reported by raising the NotFoundSignal exception." |
|
4007 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4008 |
^ NotFoundError raiseRequestWith:nil |
5755 | 4009 |
|
4010 |
"Modified: / 8.5.1996 / 09:13:11 / cg" |
|
4011 |
"Modified: / 26.7.1999 / 10:51:50 / stefan" |
|
4012 |
! |
|
4013 |
||
6874 | 4014 |
errorNotFound:errorString |
4015 |
"{ Pragma: +optSpace }" |
|
4016 |
||
4017 |
"report an error that no element was found in a collection. |
|
4018 |
The error is reported by raising the NotFoundSignal exception." |
|
4019 |
||
4020 |
^ NotFoundError raiseErrorString:errorString |
|
4021 |
! |
|
4022 |
||
5755 | 4023 |
errorSignal |
4024 |
^ self class errorSignal |
|
4025 |
||
4026 |
"Created: / 19.6.1998 / 02:32:32 / cg" |
|
4027 |
! |
|
4028 |
||
4029 |
halt |
|
4030 |
"{ Pragma: +optSpace }" |
|
4031 |
||
4032 |
"enter debugger with halt-message. |
|
4033 |
The error is reported by raising the HaltSignal exception." |
|
4034 |
||
6716
7e2bac4221d1
allow for halts to be ignored
Claus Gittinger <cg@exept.de>
parents:
6708
diff
changeset
|
4035 |
(Smalltalk at:#IgnoreHalt ifAbsent:false) == true ifTrue:[^ self]. |
6221 | 4036 |
^ HaltInterrupt raiseRequestWith:#halt |
4037 |
||
5755 | 4038 |
"Modified: / 2.8.1999 / 17:00:29 / stefan" |
6221 | 4039 |
"Modified: / 17.11.2001 / 22:47:44 / cg" |
5755 | 4040 |
! |
4041 |
||
4042 |
halt:aString |
|
4043 |
"{ Pragma: +optSpace }" |
|
4044 |
||
4045 |
"enter debugger with halt-message. |
|
4046 |
The error is reported by raising the HaltSignal exception." |
|
4047 |
||
6716
7e2bac4221d1
allow for halts to be ignored
Claus Gittinger <cg@exept.de>
parents:
6708
diff
changeset
|
4048 |
(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
|
4049 |
^ HaltInterrupt raiseRequestWith:#halt: errorString:aString |
5755 | 4050 |
|
4051 |
"Modified: 8.5.1996 / 09:13:23 / cg" |
|
4052 |
! |
|
4053 |
||
4054 |
implementedBySubclass |
|
4055 |
"{ Pragma: +optSpace }" |
|
4056 |
||
4057 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
4058 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4059 |
^ self subclassResponsibility:'method must be reimplemented in ST/V subclass' |
5755 | 4060 |
! |
4061 |
||
4062 |
indexNotInteger |
|
4063 |
"{ Pragma: +optSpace }" |
|
4064 |
||
4065 |
"report an error that index is not an Integer. |
|
4066 |
(when accessing collections indexed by an integer key). |
|
4067 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4068 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4069 |
^ NonIntegerIndexError raiseRequestWith:nil |
5755 | 4070 |
|
4071 |
"Modified: / 8.5.1996 / 09:13:37 / cg" |
|
4072 |
"Modified: / 26.7.1999 / 10:57:43 / stefan" |
|
4073 |
! |
|
4074 |
||
4075 |
indexNotInteger:anIndex |
|
4076 |
"{ Pragma: +optSpace }" |
|
4077 |
||
4078 |
"report an error that index is not an Integer. |
|
4079 |
(when accessing collections indexed by an integer key). |
|
4080 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4081 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4082 |
^ NonIntegerIndexError raiseRequestWith:anIndex |
5755 | 4083 |
|
4084 |
"Created: / 16.5.1998 / 19:39:41 / cg" |
|
4085 |
! |
|
4086 |
||
7216 | 4087 |
indexNotIntegerOrOutOfBounds:index |
4088 |
"{ Pragma: +optSpace }" |
|
4089 |
||
4090 |
"report an error that index is either non-integral or out of bounds" |
|
4091 |
||
4092 |
index isInteger ifFalse:[ |
|
4093 |
^ self indexNotInteger:index |
|
4094 |
]. |
|
4095 |
^ self subscriptBoundsError:index |
|
4096 |
! |
|
4097 |
||
5755 | 4098 |
integerCheckError |
4099 |
"{ Pragma: +optSpace }" |
|
4100 |
||
4101 |
"generated when a variable declared with an integer type gets a bad |
|
4102 |
value assigned" |
|
4103 |
||
4104 |
^ self error:'bad assign of ' , self printString , |
|
6654 | 4105 |
' (' , self class name , ') to integer-typed variable' |
5755 | 4106 |
! |
4107 |
||
4108 |
invalidCodeObject |
|
4109 |
"{ Pragma: +optSpace }" |
|
4110 |
||
4111 |
self error:'not an executable code object' |
|
4112 |
||
4113 |
"Created: 1.8.1997 / 00:16:44 / cg" |
|
4114 |
! |
|
4115 |
||
4116 |
invalidMessage |
|
4117 |
"{ Pragma: +optSpace }" |
|
4118 |
||
4119 |
"this is sent by ST/V code - its the same as #shouldNotImplement" |
|
4120 |
||
4121 |
^ self shouldNotImplement |
|
4122 |
! |
|
4123 |
||
4124 |
mustBeRectangle |
|
4125 |
"{ Pragma: +optSpace }" |
|
4126 |
||
4127 |
"report an argument-not-rectangle-error" |
|
4128 |
||
4129 |
^ self error:'argument must be a Rectangle' |
|
4130 |
! |
|
4131 |
||
4132 |
mustBeString |
|
4133 |
"{ Pragma: +optSpace }" |
|
4134 |
||
4135 |
"report an argument-not-string-error" |
|
4136 |
||
4137 |
^ self error:'argument must be a String' |
|
4138 |
! |
|
4139 |
||
4140 |
notIndexed |
|
4141 |
"{ Pragma: +optSpace }" |
|
4142 |
||
4143 |
<context: #return> |
|
4144 |
||
4145 |
"report an error that receiver has no indexed instance variables. |
|
4146 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4147 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4148 |
^ SubscriptOutOfBoundsError |
6654 | 4149 |
raiseErrorString:'receiver has no indexed variables' |
5755 | 4150 |
|
4151 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
|
4152 |
! |
|
4153 |
||
4154 |
openDebuggerOnException:ex |
|
4155 |
"{ Pragma: +optSpace }" |
|
4156 |
||
4157 |
"enter the debugger on some unhandled exception" |
|
4158 |
||
6884 | 4159 |
|msgString debugger answer| |
5755 | 4160 |
|
7208 | 4161 |
msgString := ex description. |
5755 | 4162 |
|
4163 |
" |
|
4164 |
if there is no debugger, |
|
4165 |
ask for ignore or exit. Exit will terminate the applciation. |
|
4166 |
ignore will raise an abortSignal. |
|
4167 |
" |
|
4168 |
Debugger isNil ifTrue:[ |
|
6840 | 4169 |
msgString := 'Error: ' , msgString. |
6654 | 4170 |
|
4171 |
Smalltalk isStandAloneApp ifTrue:[ |
|
4172 |
Dialog notNil ifTrue:[ |
|
7208 | 4173 |
AbortSignal isHandled ifTrue:[ |
4174 |
answer := OptionBox |
|
4175 |
request:msgString |
|
4176 |
label:msgString |
|
4177 |
buttonLabels:#('Ignore' 'Abort' 'Exit') |
|
4178 |
values:#(#ignore #abort #exit) |
|
4179 |
default:#exit. |
|
4180 |
] ifFalse:[ |
|
4181 |
answer := OptionBox |
|
4182 |
request:msgString |
|
4183 |
label:msgString |
|
4184 |
buttonLabels:#('Ignore' 'Exit') |
|
4185 |
values:#(#ignore #exit) |
|
4186 |
default:#exit. |
|
4187 |
]. |
|
6884 | 4188 |
answer == #abort ifTrue:[ |
6654 | 4189 |
^ AbortSignal raise |
6884 | 4190 |
]. |
7208 | 4191 |
answer == #ignore ifTrue:[ |
6884 | 4192 |
^ nil |
4193 |
]. |
|
6654 | 4194 |
]. |
6845
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4195 |
"/ 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
|
4196 |
ex signal == NoHandlerError ifTrue:[ |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4197 |
ex parameter signal == UserInterrupt ifTrue:[ |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4198 |
OperatingSystem exit:130 |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4199 |
]. |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4200 |
]. |
6654 | 4201 |
msgString errorPrintCR. |
4202 |
OperatingSystem exit:1 |
|
4203 |
]. |
|
4204 |
||
4205 |
msgString errorPrintCR. |
|
4206 |
Smalltalk fatalAbort:'no Debugger defined' |
|
5755 | 4207 |
]. |
4208 |
||
4209 |
" |
|
4210 |
find an appropriate debugger to use |
|
4211 |
" |
|
4212 |
debugger := self appropriateDebugger:(thisContext selector). |
|
4213 |
debugger isNil ifTrue:[ |
|
6654 | 4214 |
^ AbortSignal raise |
5755 | 4215 |
]. |
4216 |
||
4217 |
^ debugger |
|
6654 | 4218 |
enter:ex suspendedContext |
4219 |
withMessage:msgString |
|
4220 |
mayProceed:(ex mayProceed). |
|
5755 | 4221 |
|
4222 |
"Modified: 24.7.1997 / 10:09:20 / cg" |
|
4223 |
! |
|
4224 |
||
4225 |
primitiveFailed |
|
4226 |
"{ Pragma: +optSpace }" |
|
4227 |
||
4228 |
"report an error that some primitive code failed. |
|
4229 |
The error is reported by raising the PrimitiveFailureSignal exception." |
|
4230 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4231 |
^ PrimitiveFailure raiseRequestWith:nil |
5755 | 4232 |
|
6005 | 4233 |
" |
4234 |
1234 primitiveFailed |
|
4235 |
" |
|
4236 |
||
5755 | 4237 |
"Modified: / 8.5.1996 / 09:14:07 / cg" |
4238 |
"Modified: / 26.7.1999 / 10:58:08 / stefan" |
|
4239 |
! |
|
4240 |
||
6005 | 4241 |
primitiveFailed:messageString |
4242 |
"{ Pragma: +optSpace }" |
|
4243 |
||
4244 |
"report an error that some primitive code failed. |
|
4245 |
The error is reported by raising the PrimitiveFailureSignal exception." |
|
4246 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4247 |
^ PrimitiveFailure raiseRequestWith:nil errorString:messageString |
6005 | 4248 |
|
4249 |
" |
|
4250 |
1234 primitiveFailed:'this is a test' |
|
4251 |
" |
|
4252 |
! |
|
4253 |
||
6815 | 4254 |
shouldImplement |
4255 |
"{ Pragma: +optSpace }" |
|
4256 |
||
4257 |
"report an error that this message should be implemented. |
|
4258 |
This is send by automatically generated method bodies" |
|
4259 |
||
4260 |
^ self error:'method not yet implemented by class' |
|
4261 |
! |
|
4262 |
||
5755 | 4263 |
shouldNotImplement |
4264 |
"{ Pragma: +optSpace }" |
|
4265 |
||
4266 |
"report an error that this message should not be implemented" |
|
4267 |
||
4268 |
^ self error:'method not appropriate for this class' |
|
4269 |
||
4270 |
"Modified: 8.5.1996 / 09:09:44 / cg" |
|
4271 |
! |
|
4272 |
||
4273 |
subclassResponsibility |
|
4274 |
"{ Pragma: +optSpace }" |
|
4275 |
||
4276 |
"report an error that this message should have been reimplemented in a |
|
4277 |
subclass" |
|
4278 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4279 |
^ SubclassResponsibilityError |
6708 | 4280 |
raiseRequestErrorString:'method must be reimplemented in subclass' |
5755 | 4281 |
! |
4282 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4283 |
subclassResponsibility:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4284 |
"{ Pragma: +optSpace }" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4285 |
|
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4286 |
"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
|
4287 |
|
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4288 |
^ SubclassResponsibilityError |
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4289 |
raiseRequestErrorString:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4290 |
! |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4291 |
|
5755 | 4292 |
subscriptBoundsError |
4293 |
"{ Pragma: +optSpace }" |
|
4294 |
||
4295 |
"report an error that some index is out of bounds. |
|
4296 |
(when accessing indexable collections). |
|
4297 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4298 |
||
4299 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:nil |
|
4300 |
||
4301 |
"Modified: / 26.7.1996 / 16:45:42 / cg" |
|
4302 |
"Modified: / 26.7.1999 / 10:58:27 / stefan" |
|
4303 |
! |
|
4304 |
||
4305 |
subscriptBoundsError:anIndex |
|
4306 |
"{ Pragma: +optSpace }" |
|
4307 |
||
4308 |
"report an error that anIndex is out of bounds. |
|
4309 |
(when accessing indexable collections). |
|
4310 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4311 |
||
6221 | 4312 |
^ SubscriptOutOfBoundsError |
6654 | 4313 |
raiseRequestWith:anIndex |
4314 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
5755 | 4315 |
|
6221 | 4316 |
"Modified: / 17.11.2001 / 22:49:56 / cg" |
5755 | 4317 |
! |
4318 |
||
4319 |
typeCheckError |
|
4320 |
"{ Pragma: +optSpace }" |
|
4321 |
||
4322 |
"generated when a variable declared with a type hint gets a bad |
|
4323 |
value assigned" |
|
4324 |
||
4325 |
^ self error:'bad assign of ' , self printString , |
|
6654 | 4326 |
' (' , self class name , ') to typed variable' |
5755 | 4327 |
! ! |
4328 |
||
4329 |
!Object methodsFor:'evaluation'! |
|
4330 |
||
4331 |
value |
|
4332 |
"return the receiver itself. |
|
4333 |
This allows every object to be used where blocks or valueHolders |
|
4334 |
are typically used, and allows for valueHolders and blocks to be |
|
4335 |
used interchangably in some situations. |
|
4336 |
||
4337 |
Time will show, if this is a good idea or leads to sloppy programming |
|
4338 |
style ... (the idea was borrowed from the Self language). |
|
4339 |
||
4340 |
WARNING: dont 'optimize' away ifXXX: blocks |
|
6654 | 4341 |
(i.e. do NOT replace |
4342 |
foo ifTrue:[var1] ifFalse:[var2] |
|
4343 |
by: |
|
4344 |
foo ifTrue:var1 ifFalse:var2 |
|
4345 |
) |
|
4346 |
- the compilers will only generate inline code for the if, |
|
4347 |
iff the argument(s) are blocks - otherwise, a true send is |
|
4348 |
generated. |
|
4349 |
This 'oprimization' will work semantically correct, |
|
4350 |
but execute SLOWER instead." |
|
5755 | 4351 |
|
4352 |
^ self |
|
4353 |
||
4354 |
" |
|
4355 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
|
4356 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
4357 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
4358 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
4359 |
" |
|
4360 |
||
4361 |
"DO NOT DO THIS (its slower) |
|
4362 |
(1 > 4) ifTrue:'oops' ifFalse:'ok' |
|
4363 |
||
4364 |
USE (the compiler optimizes blocks in if/while): |
|
4365 |
(1 > 4) ifTrue:['oops'] ifFalse:['ok'] |
|
4366 |
" |
|
4367 |
||
4368 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
4369 |
! ! |
|
4370 |
||
4371 |
!Object methodsFor:'finalization'! |
|
4372 |
||
4373 |
disposed |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4374 |
"OBSOLETE INTERFACE: use #finalize |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4375 |
this is invoked for objects which have been registered |
5755 | 4376 |
in a Registry, when the original object dies. |
4377 |
Subclasses may redefine this method" |
|
4378 |
||
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4379 |
<resource: #obsolete> |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4380 |
|
5755 | 4381 |
^ self |
4382 |
! |
|
4383 |
||
4384 |
executor |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4385 |
"Return the object which does the finalization for me. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4386 |
This interface is also VW & Sqeak compatible," |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4387 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4388 |
"for now, send #shallowCopyForFinalization, to be compatible with |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4389 |
classes designed for old ST/X versions" |
5755 | 4390 |
|
4391 |
^ self shallowCopyForFinalization |
|
4392 |
! |
|
4393 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4394 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4395 |
"answer a Registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4396 |
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
|
4397 |
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
|
4398 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4399 |
^ FinalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4400 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4401 |
|
5755 | 4402 |
finalize |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4403 |
"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
|
4404 |
in a Registry, when the original object dies. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4405 |
Subclasses may redefine this method |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4406 |
This interface is also VW-compatible" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4407 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4408 |
"send #disposed for compatibility with existing classes that still |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4409 |
implement the obsolete #disposed message" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4410 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4411 |
^ self disposed |
5755 | 4412 |
! |
4413 |
||
4414 |
reRegisterForFinalization |
|
4415 |
"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
|
4416 |
This will create a new executor, which will receive a #finalize message when |
5755 | 4417 |
the receiver is garbage collected." |
4418 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4419 |
self finalizationLobby registerChange:self |
5755 | 4420 |
! |
4421 |
||
4422 |
registerForFinalization |
|
4423 |
"register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4424 |
Once registered, the executor of the receiver will receive a #finalize message when |
5755 | 4425 |
the receiver is garbage collected." |
4426 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4427 |
self finalizationLobby register:self |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4428 |
! |
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 |
shallowCopyForFinalization |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4431 |
"OBSOLETE INTERFACE: use #executor. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4432 |
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
|
4433 |
(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
|
4434 |
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
|
4435 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4436 |
<resource: #obsolete> |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4437 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4438 |
^ self shallowCopy |
5755 | 4439 |
! |
4440 |
||
4441 |
unregisterForFinalization |
|
4442 |
"unregister mySelf from later finalization" |
|
4443 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4444 |
self finalizationLobby unregister:self |
5755 | 4445 |
! ! |
4446 |
||
4447 |
!Object methodsFor:'initialization'! |
|
4448 |
||
4449 |
initialize |
|
4450 |
"just to ignore initialize to objects which do not need it" |
|
4451 |
||
4452 |
^ self |
|
4453 |
! ! |
|
4454 |
||
4455 |
!Object methodsFor:'interest'! |
|
4456 |
||
4457 |
addInterest:anInterest |
|
4458 |
"install an interest forwarder. |
|
4459 |
Here, we use the nonWeakDependencies." |
|
4460 |
||
4461 |
self addNonWeakDependent:anInterest |
|
4462 |
||
4463 |
"Created: 14.10.1996 / 22:27:34 / stefan" |
|
4464 |
! |
|
4465 |
||
4466 |
expressInterestIn:aspect for:anObject sendBack:aSelector |
|
4467 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
4468 |
changes aspect." |
|
4469 |
||
4470 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
4471 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4472 |
||
4473 |
self addInterest:(InterestConverter |
|
6654 | 4474 |
destination:anObject |
4475 |
selector:aSelector |
|
4476 |
aspect:aspect) |
|
5755 | 4477 |
|
4478 |
" |
|
4479 |
|p b| |
|
4480 |
||
4481 |
b := [Transcript showCR:' -> the point changed']. |
|
4482 |
||
4483 |
p := Point new. |
|
4484 |
Transcript showCR:'interest in #foo:'. |
|
4485 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4486 |
p x:1. |
|
4487 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
4488 |
p changed:#bar. |
|
4489 |
Transcript cr. |
|
4490 |
||
4491 |
Delay waitForSeconds:1. |
|
4492 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
4493 |
p changed:#foo. |
|
4494 |
Transcript cr. |
|
4495 |
||
4496 |
Delay waitForSeconds:1. |
|
4497 |
Transcript showCR:'no more interest in #foo:'. |
|
4498 |
p retractInterestIn:#foo for:b. |
|
4499 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4500 |
p changed:#foo. |
|
4501 |
Transcript cr. |
|
4502 |
||
4503 |
Delay waitForSeconds:1. |
|
4504 |
Transcript showCR:'interest in #bar now:'. |
|
4505 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
4506 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4507 |
p changed:#foo. |
|
4508 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
4509 |
p changed:#bar. |
|
4510 |
Transcript cr. |
|
4511 |
||
4512 |
Delay waitForSeconds:1. |
|
4513 |
Transcript showCR:'interest in #foo now:'. |
|
4514 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4515 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
4516 |
p changed:#foo. |
|
4517 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
4518 |
p changed:#bar. |
|
4519 |
Transcript cr. |
|
4520 |
||
4521 |
Delay waitForSeconds:1. |
|
4522 |
Transcript showCR:'no more interests:'. |
|
4523 |
p retractInterestsFor:b. |
|
4524 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4525 |
p changed:#foo. |
|
4526 |
Transcript showCR:'now changing #bar... (expect no notification)'. |
|
4527 |
p changed:#bar. |
|
4528 |
Transcript cr. |
|
4529 |
||
4530 |
p release. |
|
4531 |
" |
|
4532 |
||
4533 |
"Created: 19.4.1996 / 10:26:22 / cg" |
|
4534 |
"Modified: 19.4.1996 / 12:34:08 / cg" |
|
4535 |
"Modified: 14.10.1996 / 22:28:20 / stefan" |
|
4536 |
! |
|
4537 |
||
4538 |
interests |
|
4539 |
"return a Collection of interests - empty if there is none. |
|
4540 |
Here, we use the nonWeakDependents for interests." |
|
4541 |
||
4542 |
^ self nonWeakDependents |
|
4543 |
||
4544 |
"Created: / 14.10.1996 / 22:20:51 / stefan" |
|
4545 |
"Modified: / 30.1.1998 / 14:07:35 / cg" |
|
4546 |
! |
|
4547 |
||
4548 |
interestsFor:someOne |
|
4549 |
"return a collection of interests of someOne - empty if there is none." |
|
4550 |
||
4551 |
|coll deps| |
|
4552 |
||
4553 |
deps := self interests. |
|
4554 |
deps size == 0 ifTrue:[^ #()]. |
|
4555 |
||
4556 |
coll := IdentitySet new. |
|
4557 |
||
4558 |
deps do:[:dep | |
|
6654 | 4559 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
4560 |
dep destination == someOne ifTrue:[ |
|
4561 |
coll add:dep. |
|
4562 |
] |
|
4563 |
] |
|
5755 | 4564 |
]. |
4565 |
^ coll |
|
4566 |
||
4567 |
"Created: / 30.1.1998 / 14:02:26 / cg" |
|
4568 |
"Modified: / 30.1.1998 / 14:08:24 / cg" |
|
4569 |
! |
|
4570 |
||
4571 |
onChangeEvaluate:aBlock |
|
4572 |
"arrange for aBlock to be evaluated whenever the receiver changes." |
|
4573 |
||
4574 |
^ self onChangeSend:#value to:aBlock |
|
4575 |
||
4576 |
"Created: / 29.1.1999 / 16:01:22 / cg" |
|
4577 |
! |
|
4578 |
||
4579 |
onChangeSend:aSelector to:anObject |
|
4580 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
4581 |
changes." |
|
4582 |
||
4583 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
4584 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4585 |
||
4586 |
self addInterest:(InterestConverter |
|
6654 | 4587 |
destination:anObject |
4588 |
selector:aSelector) |
|
5755 | 4589 |
|
4590 |
" |
|
4591 |
|p b| |
|
4592 |
||
4593 |
b := [Transcript showCR:'the point changed']. |
|
4594 |
||
4595 |
p := Point new. |
|
4596 |
p onChangeSend:#value to:b. |
|
4597 |
p x:1. |
|
4598 |
Transcript showCR:'now changing'. |
|
4599 |
p changed. |
|
4600 |
Transcript cr. |
|
4601 |
||
4602 |
Delay waitForSeconds:1. |
|
4603 |
Transcript showCR:'now changing'. |
|
4604 |
p changed. |
|
4605 |
Transcript cr. |
|
4606 |
||
4607 |
Delay waitForSeconds:1. |
|
4608 |
Transcript showCR:'no more interest'. |
|
4609 |
p retractInterestsFor:b. |
|
4610 |
Transcript showCR:'now changing again'. |
|
4611 |
p changed. |
|
4612 |
Transcript cr. |
|
4613 |
||
4614 |
Delay waitForSeconds:1. |
|
4615 |
Transcript showCR:'interest again'. |
|
4616 |
p onChangeSend:#value to:b. |
|
4617 |
Transcript showCR:'now changing again'. |
|
4618 |
p changed. |
|
4619 |
Transcript cr. |
|
4620 |
" |
|
4621 |
||
4622 |
"Created: 19.4.1996 / 10:26:38 / cg" |
|
4623 |
"Modified: 19.4.1996 / 12:34:26 / cg" |
|
4624 |
"Modified: 14.10.1996 / 22:28:27 / stefan" |
|
4625 |
! |
|
4626 |
||
4627 |
removeInterest:anInterest |
|
4628 |
"remove an interest forwarder. |
|
4629 |
Here, we use the nonWeakDependencies." |
|
4630 |
||
4631 |
self removeNonWeakDependent:anInterest |
|
4632 |
||
4633 |
"Created: 14.10.1996 / 22:21:59 / stefan" |
|
4634 |
! |
|
4635 |
||
4636 |
retractInterestIn:aspect for:someOne |
|
4637 |
"remove the interest of someOne in the receiver changing aspect |
|
4638 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
4639 |
||
4640 |
"/ for now, remove the interestConverter. |
|
4641 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4642 |
||
4643 |
"/ cannot removeDependent within the loop - the collection rehashes |
|
4644 |
||
4645 |
|deps coll| |
|
4646 |
||
4647 |
deps := self interests. |
|
4648 |
deps size ~~ 0 ifTrue:[ |
|
6654 | 4649 |
coll := IdentitySet new. |
4650 |
||
4651 |
deps do:[:dep | |
|
4652 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
|
4653 |
dep destination == someOne ifTrue:[ |
|
4654 |
dep aspect == aspect ifTrue:[ |
|
4655 |
self removeInterest:dep. |
|
4656 |
^ self |
|
4657 |
] |
|
4658 |
] |
|
4659 |
] |
|
4660 |
]. |
|
4661 |
coll do:[:dep | |
|
4662 |
self removeInterest:dep. |
|
4663 |
]. |
|
5755 | 4664 |
]. |
4665 |
||
4666 |
||
4667 |
" |
|
4668 |
|p b| |
|
4669 |
||
4670 |
b := [Transcript showCR:'the point changed']. |
|
4671 |
||
4672 |
p := Point new. |
|
4673 |
Transcript showCR:'interest in #foo'. |
|
4674 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4675 |
p x:1. |
|
4676 |
Transcript showCR:'now changing #bar'. |
|
4677 |
p changed:#bar. |
|
4678 |
Transcript cr. |
|
4679 |
||
4680 |
Delay waitForSeconds:1. |
|
4681 |
Transcript showCR:'now changing #foo'. |
|
4682 |
p changed:#foo. |
|
4683 |
Transcript cr. |
|
4684 |
||
4685 |
Delay waitForSeconds:1. |
|
4686 |
Transcript showCR:'no more interest in #foo'. |
|
4687 |
p retractInterestIn:#foo for:b. |
|
4688 |
Transcript showCR:'now changing #foo'. |
|
4689 |
p changed:#foo. |
|
4690 |
Transcript cr. |
|
4691 |
||
4692 |
Delay waitForSeconds:1. |
|
4693 |
Transcript showCR:'interest in #bar now'. |
|
4694 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
4695 |
Transcript showCR:'now changing #foo'. |
|
4696 |
p changed:#foo. |
|
4697 |
Transcript showCR:'now changing #bar'. |
|
4698 |
p changed:#bar. |
|
4699 |
Transcript cr. |
|
4700 |
||
4701 |
Delay waitForSeconds:1. |
|
4702 |
Transcript showCR:'interest in #foo now'. |
|
4703 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4704 |
Transcript showCR:'now changing #foo'. |
|
4705 |
p changed:#foo. |
|
4706 |
Transcript showCR:'now changing #bar'. |
|
4707 |
p changed:#bar. |
|
4708 |
Transcript cr. |
|
4709 |
||
4710 |
Delay waitForSeconds:1. |
|
4711 |
Transcript showCR:'no more interests'. |
|
4712 |
p retractInterestsFor:b. |
|
4713 |
Transcript showCR:'now changing #foo'. |
|
4714 |
p changed:#foo. |
|
4715 |
Transcript showCR:'now changing #bar'. |
|
4716 |
p changed:#bar. |
|
4717 |
Transcript cr. |
|
4718 |
" |
|
4719 |
||
4720 |
"Created: / 19.4.1996 / 10:27:11 / cg" |
|
4721 |
"Modified: / 14.10.1996 / 22:21:19 / stefan" |
|
4722 |
"Modified: / 30.1.1998 / 14:05:34 / cg" |
|
4723 |
! |
|
4724 |
||
4725 |
retractInterestsFor:someOne |
|
4726 |
"remove the interest of someOne in the receiver |
|
4727 |
(as installed with #onChangeSend:to:)." |
|
4728 |
||
4729 |
"/ for now, remove the interestConverter. |
|
4730 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4731 |
||
4732 |
|coll deps| |
|
4733 |
||
4734 |
"/ cannot removeDependent within the loop - the collection rehashes |
|
4735 |
||
4736 |
deps := self interests. |
|
4737 |
deps size ~~ 0 ifTrue:[ |
|
6654 | 4738 |
coll := IdentitySet new. |
4739 |
||
4740 |
deps do:[:dep | |
|
4741 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
|
4742 |
dep destination == someOne ifTrue:[ |
|
4743 |
coll add:dep. |
|
4744 |
] |
|
4745 |
] |
|
4746 |
]. |
|
4747 |
coll do:[:dep | |
|
4748 |
self removeInterest:dep. |
|
4749 |
]. |
|
5755 | 4750 |
]. |
4751 |
||
4752 |
||
4753 |
||
4754 |
" |
|
4755 |
|p b| |
|
4756 |
||
4757 |
b := [Transcript showCR:'the point changed']. |
|
4758 |
||
4759 |
p := Point new. |
|
4760 |
p onChangeSend:#value to:b. |
|
4761 |
p x:1. |
|
4762 |
Transcript showCR:'now changing'. |
|
4763 |
p changed. |
|
4764 |
Transcript cr. |
|
4765 |
||
4766 |
Delay waitForSeconds:1. |
|
4767 |
Transcript showCR:'now changing'. |
|
4768 |
p changed. |
|
4769 |
Transcript cr. |
|
4770 |
||
4771 |
Delay waitForSeconds:1. |
|
4772 |
Transcript showCR:'no more interest'. |
|
4773 |
p retractInterestsFor:b. |
|
4774 |
Transcript showCR:'now changing again'. |
|
4775 |
p changed. |
|
4776 |
Transcript cr. |
|
4777 |
||
4778 |
Delay waitForSeconds:1. |
|
4779 |
Transcript showCR:'interest again'. |
|
4780 |
p onChangeSend:#value to:b. |
|
4781 |
Transcript showCR:'now changing again'. |
|
4782 |
p changed. |
|
4783 |
Transcript cr. |
|
4784 |
" |
|
4785 |
||
4786 |
"Created: / 19.4.1996 / 10:23:46 / cg" |
|
4787 |
"Modified: / 14.10.1996 / 22:21:25 / stefan" |
|
4788 |
"Modified: / 30.1.1998 / 14:04:52 / cg" |
|
4789 |
! ! |
|
4790 |
||
4791 |
!Object methodsFor:'interrupt handling'! |
|
4792 |
||
4793 |
childSignalInterrupt |
|
4794 |
"death of a child process (unix process) - do nothing" |
|
4795 |
||
4796 |
^ self |
|
4797 |
! |
|
4798 |
||
4799 |
customInterrupt |
|
4800 |
"{ Pragma: +optSpace }" |
|
4801 |
||
4802 |
"a custom interrupt - but no handler has defined" |
|
4803 |
||
4804 |
self error:'custom interrupt' mayProceed:true |
|
4805 |
! |
|
4806 |
||
4807 |
errorInterrupt:errorID with:aParameter |
|
4808 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
4809 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
|
4810 |
which can be called from C subsystems to raise an (asynchronous) |
|
4811 |
error exception. |
|
4812 |
||
4813 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
4814 |
used from other C subsystems too, to upcast errors. |
|
4815 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
4816 |
IDs (currently) used: |
|
6654 | 4817 |
#DisplayError ..... x-error interrupt |
4818 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
5755 | 4819 |
" |
4820 |
||
6263
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4821 |
|handlers handler| |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4822 |
|
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4823 |
handlers := ObjectMemory registeredErrorInterruptHandlers. |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4824 |
handlers notNil ifTrue:[ |
6654 | 4825 |
handler := handlers at:errorID ifAbsent:nil. |
4826 |
handler notNil ifTrue:[ |
|
4827 |
"/ |
|
4828 |
"/ handler found; let it do whatever it wants ... |
|
4829 |
"/ |
|
4830 |
handler errorInterrupt:errorID with:aParameter. |
|
4831 |
^ self |
|
4832 |
]. |
|
5755 | 4833 |
]. |
4834 |
||
4835 |
"/ |
|
4836 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
4837 |
"/ |
|
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
4838 |
^ Error |
6654 | 4839 |
raiseRequestWith:errorID |
4840 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
5755 | 4841 |
! |
4842 |
||
4843 |
exceptionInterrupt |
|
4844 |
"{ Pragma: +optSpace }" |
|
4845 |
||
4846 |
"exception interrupt - enter debugger" |
|
4847 |
||
4848 |
self error:'exception Interrupt' mayProceed:true |
|
4849 |
! |
|
4850 |
||
4851 |
fpExceptionInterrupt |
|
4852 |
"{ Pragma: +optSpace }" |
|
4853 |
||
4854 |
"a floating point exception occured - this one |
|
4855 |
has to be handled differently since it comes asynchronous |
|
4856 |
on some machines (for example, on machines with a separate FPU |
|
4857 |
or superscalar architectures. Also, errors from within primitive code |
|
4858 |
(or library functions such as GL) are sent via the Unix-signal |
|
4859 |
mechanism this way." |
|
4860 |
||
4861 |
|where rec| |
|
4862 |
||
4863 |
where := thisContext sender. |
|
4864 |
rec := where receiver. |
|
4865 |
rec isNumber ifTrue:[ |
|
6654 | 4866 |
^ rec class |
4867 |
raise:#domainErrorSignal |
|
4868 |
receiver:rec |
|
4869 |
selector:where selector |
|
4870 |
arguments:(where args asArray) |
|
4871 |
errorString:'floating point exception' |
|
5755 | 4872 |
]. |
4873 |
||
4874 |
"/ could be in some C-library ... |
|
4875 |
^ Float domainErrorSignal raise |
|
4876 |
! |
|
4877 |
||
4878 |
internalError:msg |
|
4879 |
"{ Pragma: +optSpace }" |
|
4880 |
||
4881 |
"this is triggered, when VM hits some bad error, |
|
4882 |
such as corrupted class, corrupted method/selector array |
|
4883 |
etc. The argument string gives some more information on what happened. |
|
4884 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
|
4885 |
Its not guaranteed, that the system is in a working condition once |
|
4886 |
this error occurred ...." |
|
4887 |
||
4888 |
InternalErrorSignal raiseWith:self errorString:msg |
|
4889 |
! |
|
4890 |
||
4891 |
ioInterrupt |
|
4892 |
"{ Pragma: +optSpace }" |
|
4893 |
||
4894 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
|
4895 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
4896 |
or it does not understand the ioInterrupt message. |
|
4897 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
4898 |
||
4899 |
self error:'I/O Interrupt - but no handler' mayProceed:true |
|
4900 |
! |
|
4901 |
||
4902 |
memoryInterrupt |
|
4903 |
"{ Pragma: +optSpace }" |
|
4904 |
||
4905 |
"out-of-memory interrupt and no handler - enter debugger" |
|
4906 |
||
4907 |
self error:'almost out of memory' mayProceed:true |
|
4908 |
! |
|
4909 |
||
4910 |
recursionInterrupt |
|
4911 |
"{ Pragma: +optSpace }" |
|
4912 |
||
4913 |
"recursion limit (actually: stack overflow) interrupt. |
|
4914 |
This interrupt is triggered, when a process stack grows above |
|
4915 |
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
|
4916 |
could be caught. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4917 |
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
|
4918 |
and the exception can be resumed. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4919 |
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
|
4920 |
is not proceedable. |
5755 | 4921 |
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
|
4922 |
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
|
4923 |
or debug for a while. |
5755 | 4924 |
If the signal is ignored, and the stack continues to grow, there |
4925 |
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
|
4926 |
terminates the process." |
5755 | 4927 |
|
4928 |
|con remaining| |
|
4929 |
||
4930 |
(con := thisContext) isRecursive ifFalse:[ |
|
4931 |
"/ Processor activeProcess usedStackSize < Processor activeProcess maximumStackSize ifTrue:[ |
|
4932 |
"/ "/ mhmh - it hit me, but I am not responsible ... |
|
4933 |
"/ 'Stray recursionInterrupt ...' infoPrintCR. |
|
4934 |
"/ ^ self |
|
4935 |
"/ ]. |
|
6654 | 4936 |
ObjectMemory infoPrinting ifTrue:[ |
4937 |
'Object [info]: recursionInterrupt from:' printCR. |
|
4938 |
con := con sender. |
|
4939 |
remaining := 50. |
|
4940 |
[con notNil and:[remaining > 0]] whileTrue:[ |
|
4941 |
'| ' print. con fullPrint. |
|
4942 |
con := con sender. |
|
4943 |
remaining := remaining - 1 |
|
4944 |
]. |
|
4945 |
]. |
|
4946 |
^ RecursionInterruptSignal raiseSignal |
|
5755 | 4947 |
] |
4948 |
||
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4949 |
"Modified: / 10.11.2001 / 15:15:56 / cg" |
5755 | 4950 |
! |
4951 |
||
4952 |
schedulerInterrupt |
|
4953 |
"{ Pragma: +optSpace }" |
|
4954 |
||
4955 |
"scheduler interrupt (supposed to be sent to Processor). |
|
4956 |
If we arrive here, either the Processor does not understand it, |
|
4957 |
or it has been set to nil. In any case, this is a sign of some |
|
4958 |
big trouble. Enter debugger." |
|
4959 |
||
4960 |
self error:'schedulerInterrupt - but no Processor' mayProceed:true |
|
4961 |
! |
|
4962 |
||
4963 |
signalInterrupt:signalNumber |
|
4964 |
"{ Pragma: +optSpace }" |
|
4965 |
||
4966 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
|
4967 |
(SIGPIPE), others (SIGBUS) are rather fatal ... |
|
4968 |
In any case, IF a smalltalk-signal has been connected to the OS signal, |
|
4969 |
that one is raised. |
|
4970 |
Otherwise, a dialog is shown, asking the user on how to handle the |
|
4971 |
signal. |
|
4972 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
|
4973 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
4974 |
Currently (temporary kludge), these are passed as global variables." |
|
4975 |
||
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4976 |
|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
|
4977 |
action title screen| |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4978 |
|
5755 | 4979 |
|
4980 |
"if there has been an ST-signal installed, use it ..." |
|
4981 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
4982 |
sig notNil ifTrue:[ |
|
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4983 |
sig raise. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4984 |
^ self. |
5755 | 4985 |
]. |
4986 |
||
4987 |
"/ if handled, raise OSSignalInterruptSignal |
|
4988 |
OSSignalInterruptSignal isHandled ifTrue:[ |
|
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4989 |
OSSignalInterruptSignal raiseRequestWith:signalNumber. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4990 |
^ self. |
5755 | 4991 |
]. |
4992 |
||
4993 |
" |
|
7031 | 4994 |
special case - SIGPWR: write a crash image and continue |
4995 |
- SIGHUP: write a crash image |
|
4996 |
" |
|
4997 |
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
|
4998 |
ObjectMemory snapShotOn:'crash.img'. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4999 |
^ self. |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
5000 |
]. |
7031 | 5001 |
(signalNumber == 1 "OperatingSystem sigHUP") ifTrue:[ |
5002 |
ObjectMemory snapShotOn:'crash.img'. |
|
5003 |
Smalltalk exit. |
|
5004 |
]. |
|
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
5005 |
|
5755 | 5006 |
name := OperatingSystem nameForSignal:signalNumber. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5007 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5008 |
"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
|
5009 |
(Screen isNil |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5010 |
or:[(screen := Screen current) isNil |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5011 |
or:[(screen := Screen default) isNil |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5012 |
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
|
5013 |
^ self startMiniDebuggerOrExit:'Signal (' , name, ')'. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5014 |
]. |
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 |
"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
|
5017 |
otherwise display stays locked" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5018 |
screen ungrabPointer; ungrabKeyboard. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5019 |
|
7031 | 5020 |
here := thisContext. |
5021 |
badContext := here sender. "the context, in which the signal occurred" |
|
5022 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5023 |
"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
|
5024 |
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
|
5025 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5026 |
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
|
5027 |
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
|
5028 |
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
|
5029 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5030 |
fatal := OperatingSystem isFatalSignal:signalNumber. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5031 |
fatal ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5032 |
(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
|
5033 |
'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
|
5034 |
^ self startMiniDebuggerOrExit:'Signal (' , name, ')'. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5035 |
]. |
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 |
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
|
5038 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5039 |
msg := 'OS-signal: ', name. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5040 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5041 |
"/ 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
|
5042 |
"/ 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
|
5043 |
"/ 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
|
5044 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5045 |
InterruptPcLow notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5046 |
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
|
5047 |
pc ~~ 0 ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5048 |
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
|
5049 |
]. |
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 |
InterruptAddrLow notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5052 |
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
|
5053 |
addr ~~ 0 ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5054 |
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
|
5055 |
]. |
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 |
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
|
5058 |
"unreachable" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5059 |
^ nil. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5060 |
]. |
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 |
"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
|
5063 |
Otherwise, start a debugger" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5064 |
Dialog notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5065 |
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
|
5066 |
actions := #(save core exit debug). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5067 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5068 |
action := nil. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5069 |
title := 'OS Signal caught (' , name, ')'. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5070 |
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
|
5071 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5072 |
"/ 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
|
5073 |
"/ 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
|
5074 |
"/ (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
|
5075 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5076 |
Processor activeProcess isSystemProcess ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5077 |
titles := #('abort') , titles. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5078 |
actions := #(abort), actions. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5079 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5080 |
badContext canReturn ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5081 |
titles := #('return') , titles. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5082 |
actions := #(return), actions. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5083 |
]. |
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 |
fatal ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5087 |
titles := titles, #('ignore'). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5088 |
actions := actions , #(ignore). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5089 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5090 |
action := Dialog choose:title |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5091 |
labels:titles |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5092 |
values:actions |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5093 |
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
|
5094 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5095 |
"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
|
5096 |
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
|
5097 |
] ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5098 |
action := #debug. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5099 |
]. |
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 |
action == #save ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5102 |
ObjectMemory snapShotOn:'crash.img' |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5103 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5104 |
action == #core ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5105 |
Smalltalk fatalAbort |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5106 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5107 |
action == #exit ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5108 |
Smalltalk exit |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5109 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5110 |
action == #return ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5111 |
badContext return |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5112 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5113 |
action == #abort ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5114 |
AbortSignal raise. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5115 |
]. |
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 |
action == #debug ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5118 |
Debugger isNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5119 |
^ self startMiniDebuggerOrExit:'Signal (' , name, ')'. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5120 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5121 |
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
|
5122 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5123 |
"action == #ignore" |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5124 |
]. |
5755 | 5125 |
! |
5126 |
||
5127 |
spyInterrupt |
|
5128 |
"{ Pragma: +optSpace }" |
|
5129 |
||
5130 |
"spy interrupt and no handler - enter debugger" |
|
5131 |
||
5132 |
self error:'spy Interrupt - but no handler' mayProceed:true |
|
5133 |
! |
|
5134 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5135 |
startMiniDebuggerOrExit:text |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5136 |
"some critical condition happened. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5137 |
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
|
5138 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5139 |
MiniDebugger isNil ifTrue:[ |
6654 | 5140 |
"a system without debugging facilities (i.e. a standalone system) |
5141 |
output a message and exit." |
|
5142 |
('Object [error]: exit due to ', text, ' - and no debugger.') errorPrintCR. |
|
5143 |
OperatingSystem exit:99. |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5144 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5145 |
MiniDebugger enterWithMessage:text mayProceed:true. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5146 |
! |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5147 |
|
5755 | 5148 |
timerInterrupt |
5149 |
"{ Pragma: +optSpace }" |
|
5150 |
||
5151 |
"timer interrupt and no handler - enter debugger" |
|
5152 |
||
5153 |
self error:'timer Interrupt - but no handler' mayProceed:true |
|
5154 |
! |
|
5155 |
||
5156 |
userInterrupt |
|
5157 |
"{ Pragma: +optSpace }" |
|
5158 |
||
5159 |
"user (^c) interrupt. |
|
5160 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
5161 |
controlling tty (i.e. in the xterm)." |
|
5162 |
||
6466 | 5163 |
UserInterruptSignal raiseRequest |
5755 | 5164 |
! |
5165 |
||
5166 |
userInterruptIn:aContext |
|
5167 |
"{ Pragma: +optSpace }" |
|
5168 |
||
5169 |
"user (^c) interrupt - enter debugger, but show aContext |
|
5170 |
as top-context. |
|
5171 |
This is used to hide any intermediate scheduler contexts, |
|
5172 |
in case of an interrupted process. Typically, this is sent by |
|
5173 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
5174 |
processed." |
|
5175 |
||
5176 |
<context: #return> |
|
5177 |
||
5178 |
UserInterruptSignal raiseRequestWith:nil errorString:nil in:aContext |
|
5179 |
||
5180 |
"Created: / 18.10.1996 / 20:46:04 / cg" |
|
5181 |
"Modified: / 20.10.1996 / 13:06:38 / cg" |
|
5182 |
"Modified: / 26.7.1999 / 10:58:49 / stefan" |
|
5183 |
! ! |
|
5184 |
||
5185 |
!Object methodsFor:'message sending'! |
|
5186 |
||
5187 |
perform:aSelector |
|
5188 |
"send the message aSelector to the receiver" |
|
5189 |
||
5190 |
%{ |
|
5191 |
REGISTER OBJ sel = aSelector; |
|
5192 |
||
5193 |
if (InterruptPending == nil) { |
|
6654 | 5194 |
struct inlineCache *pIlc; |
5195 |
static struct inlineCache ilc_0 = __ILCPERF0(@line); |
|
5196 |
static struct inlineCache ilc_1 = __ILCPERF0(@line); |
|
5197 |
static struct inlineCache ilc_2 = __ILCPERF0(@line); |
|
5198 |
static struct inlineCache ilc_3 = __ILCPERF0(@line); |
|
5199 |
static struct inlineCache ilc_4 = __ILCPERF0(@line); |
|
5200 |
static OBJ last_0 = nil; |
|
5201 |
static OBJ last_1 = nil; |
|
5202 |
static OBJ last_2 = nil; |
|
5203 |
static OBJ last_3 = nil; |
|
5204 |
static OBJ last_4 = nil; |
|
5205 |
static flip = 0; |
|
5206 |
||
5207 |
if (sel == last_0) { |
|
5208 |
pIlc = &ilc_0; |
|
5209 |
} else if (sel == last_1) { |
|
5210 |
pIlc = &ilc_1; |
|
5211 |
} else if (sel == last_2) { |
|
5212 |
pIlc = &ilc_2; |
|
5213 |
} else if (sel == last_3) { |
|
5214 |
pIlc = &ilc_3; |
|
5215 |
} else if (sel == last_4) { |
|
5216 |
pIlc = &ilc_4; |
|
5217 |
} else { |
|
5218 |
if (flip == 0) { |
|
5219 |
pIlc = &ilc_0; |
|
5220 |
flip = 1; |
|
5221 |
last_0 = sel; |
|
5222 |
} else if (flip == 1) { |
|
5223 |
pIlc = &ilc_1; |
|
5224 |
flip = 2; |
|
5225 |
last_1 = sel; |
|
5226 |
} else if (flip == 2) { |
|
5227 |
pIlc = &ilc_2; |
|
5228 |
flip = 3; |
|
5229 |
last_2 = sel; |
|
5230 |
} else if (flip == 3) { |
|
5231 |
pIlc = &ilc_3; |
|
5232 |
flip = 4; |
|
5233 |
last_3 = sel; |
|
5234 |
} else { |
|
5235 |
pIlc = &ilc_4; |
|
5236 |
flip = 0; |
|
5237 |
last_4 = sel; |
|
5238 |
} |
|
5239 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5240 |
if (pIlc->ilc_poly) { |
|
5241 |
__flushPolyCache(pIlc->ilc_poly); |
|
5242 |
pIlc->ilc_poly = 0; |
|
5243 |
} |
|
5244 |
} |
|
5245 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
|
5755 | 5246 |
} else { |
6654 | 5247 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
5248 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5755 | 5249 |
} |
5250 |
%}. |
|
5251 |
^ self perform:aSelector withArguments:#() |
|
5252 |
! |
|
5253 |
||
5254 |
perform:aSelector inClass:aClass withArguments:argArray |
|
5255 |
"send the message aSelector with all args taken from argArray |
|
5256 |
to the receiver as a super-send message. |
|
5257 |
This is actually more flexible than the normal super-send, since it allows |
|
5258 |
to execute a method in ANY superclass of the receiver (not just the |
|
5259 |
immediate superclass). |
|
5260 |
Thus, it is (theoretically) possible to do |
|
6654 | 5261 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
5755 | 5262 |
and evaluate Magnitudes compare method even if there was one in Number. |
5263 |
This method is used by the interpreter to evaluate super sends |
|
5264 |
and could be used for very special behavior (language extension ?). |
|
5265 |
||
5266 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
5267 |
||
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5268 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 myClass| |
5755 | 5269 |
|
5270 |
" |
|
5271 |
check, if aClass is really a superclass of the receiver |
|
5272 |
" |
|
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5273 |
myClass := self class. |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5274 |
(myClass == aClass or:[myClass isSubclassOf:aClass]) ifFalse:[ |
6654 | 5275 |
self error:'lookup-class argument is not a superclass of the receiver'. |
5276 |
^ nil |
|
5755 | 5277 |
]. |
5278 |
%{ |
|
5279 |
REGISTER OBJ *argP; |
|
5280 |
int nargs, i; |
|
5281 |
||
5282 |
if (__isArray(argArray)) { |
|
6654 | 5283 |
nargs = __arraySize(argArray); |
5284 |
argP = __arrayVal(argArray); |
|
5755 | 5285 |
} else { |
6654 | 5286 |
if (__isNonNilObject(argArray)) { |
5287 |
static struct inlineCache ilcSize = __ILC0(@line+1); |
|
5288 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5289 |
if (!__isSmallInteger(numberOfArgs)) |
|
5290 |
goto bad; |
|
5291 |
nargs = __intVal(numberOfArgs); |
|
5292 |
argP = (OBJ *)(&a1); |
|
5293 |
for (i=1; i <= nargs; i++) { |
|
5294 |
*argP++ = __AT_(argArray, __MKSMALLINT((INT)i)); |
|
5295 |
} |
|
5296 |
argP = (OBJ *)(&a1); |
|
5297 |
} else { |
|
5298 |
nargs = 0; |
|
5299 |
} |
|
5755 | 5300 |
} |
5301 |
switch (nargs) { |
|
6654 | 5302 |
case 0: |
5303 |
{ |
|
5304 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5305 |
RETURN ( _SEND0(self, aSelector, aClass, &ilc0)); |
|
5306 |
} |
|
5307 |
||
5308 |
case 1: |
|
5309 |
{ |
|
5310 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5311 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, argP[0])); |
|
5312 |
} |
|
5313 |
||
5314 |
case 2: |
|
5315 |
{ |
|
5316 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5317 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, argP[0], argP[1])); |
|
5318 |
} |
|
5319 |
||
5320 |
case 3: |
|
5321 |
{ |
|
5322 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5323 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, |
|
5324 |
argP[0], argP[1], argP[2])); |
|
5325 |
} |
|
5326 |
||
5327 |
case 4: |
|
5328 |
{ |
|
5329 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
5330 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, |
|
5331 |
argP[0], argP[1], argP[2], argP[3])); |
|
5332 |
} |
|
5333 |
||
5334 |
case 5: |
|
5335 |
{ |
|
5336 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
5337 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
5338 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5339 |
} |
|
5340 |
||
5341 |
case 6: |
|
5342 |
{ |
|
5343 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
5344 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
5345 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5])); |
|
5346 |
} |
|
5347 |
||
5348 |
case 7: |
|
5349 |
{ |
|
5350 |
static struct inlineCache ilc7 = __DUMMYILCSELF7(@line+1); |
|
5351 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
5352 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5353 |
argP[6])); |
|
5354 |
} |
|
5355 |
||
5356 |
case 8: |
|
5357 |
{ |
|
5358 |
static struct inlineCache ilc8 = __DUMMYILCSELF8(@line+1); |
|
5359 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
5360 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5361 |
argP[6], argP[7])); |
|
5362 |
} |
|
5363 |
||
5364 |
case 9: |
|
5365 |
{ |
|
5366 |
static struct inlineCache ilc9 = __DUMMYILCSELF9(@line+1); |
|
5367 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
5368 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5369 |
argP[6], argP[7], argP[8])); |
|
5370 |
} |
|
5371 |
||
5372 |
case 10: |
|
5373 |
{ |
|
5374 |
static struct inlineCache ilc10 = __DUMMYILCSELF10(@line+1); |
|
5375 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
5376 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5377 |
argP[6], argP[7], argP[8], argP[9])); |
|
5378 |
} |
|
5379 |
||
5380 |
case 11: |
|
5381 |
{ |
|
5382 |
static struct inlineCache ilc11 = __DUMMYILCSELF11(@line+1); |
|
5383 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
5384 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5385 |
argP[6], argP[7], argP[8], argP[9], argP[10])); |
|
5386 |
} |
|
5387 |
||
5388 |
case 12: |
|
5389 |
{ |
|
5390 |
static struct inlineCache ilc12 = __DUMMYILCSELF12(@line+1); |
|
5391 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
5392 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5393 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5394 |
argP[11])); |
|
5395 |
} |
|
5396 |
||
5397 |
case 13: |
|
5398 |
{ |
|
5399 |
static struct inlineCache ilc13 = __DUMMYILCSELF13(@line+1); |
|
5400 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
5401 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5402 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5403 |
argP[11], argP[12])); |
|
5404 |
} |
|
5405 |
||
5406 |
case 14: |
|
5407 |
{ |
|
5408 |
static struct inlineCache ilc14 = __DUMMYILCSELF14(@line+1); |
|
5409 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
5410 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5411 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5412 |
argP[11], argP[12], argP[13])); |
|
5413 |
} |
|
5414 |
||
5415 |
case 15: |
|
5416 |
{ |
|
5417 |
static struct inlineCache ilc15 = __DUMMYILCSELF15(@line+1); |
|
5418 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
5419 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5420 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5421 |
argP[11], argP[12], argP[13], argP[14])); |
|
5422 |
} |
|
5755 | 5423 |
|
5424 |
#ifdef _SEND16 |
|
6654 | 5425 |
case 16: |
5426 |
{ |
|
5427 |
static struct inlineCache ilc16 = __DUMMYILCSELF16(@line+1); |
|
5428 |
RETURN ( _SEND16(self, aSelector, aClass, &ilc15, |
|
5429 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5430 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5431 |
argP[11], argP[12], argP[13], argP[14], argP[15])); |
|
5432 |
} |
|
5755 | 5433 |
#endif |
5434 |
#ifdef _SEND17 |
|
6654 | 5435 |
case 17: |
5436 |
{ |
|
5437 |
static struct inlineCache ilc17 = __DUMMYILCSELF17(@line+1); |
|
5438 |
RETURN ( _SEND17(self, aSelector, aClass, &ilc15, |
|
5439 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5440 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5441 |
argP[11], argP[12], argP[13], argP[14], argP[15], argP[16])); |
|
5442 |
} |
|
5755 | 5443 |
#endif |
5444 |
||
5445 |
||
5446 |
} |
|
5447 |
bad:; |
|
5448 |
%}. |
|
5449 |
"/ arrive here, if bad number of arguments (too many) |
|
5450 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5451 |
||
5452 |
^ self primitiveFailed |
|
5453 |
! |
|
5454 |
||
5455 |
perform:aSelector with:arg |
|
5456 |
"send the one-arg-message aSelector to the receiver" |
|
5457 |
||
5458 |
%{ |
|
5459 |
REGISTER OBJ sel = aSelector; |
|
5460 |
||
5461 |
if (InterruptPending == nil) { |
|
6654 | 5462 |
struct inlineCache *pIlc; |
5463 |
static struct inlineCache ilc_0 = __ILCPERF1(@line); |
|
5464 |
static struct inlineCache ilc_1 = __ILCPERF1(@line); |
|
5465 |
static struct inlineCache ilc_2 = __ILCPERF1(@line); |
|
5466 |
static struct inlineCache ilc_3 = __ILCPERF1(@line); |
|
5467 |
static struct inlineCache ilc_4 = __ILCPERF1(@line); |
|
5468 |
static OBJ last_0 = nil; |
|
5469 |
static OBJ last_1 = nil; |
|
5470 |
static OBJ last_2 = nil; |
|
5471 |
static OBJ last_3 = nil; |
|
5472 |
static OBJ last_4 = nil; |
|
5473 |
static flip = 0; |
|
5474 |
||
5475 |
if (sel == last_0) { |
|
5476 |
pIlc = &ilc_0; |
|
5477 |
} else if (sel == last_1) { |
|
5478 |
pIlc = &ilc_1; |
|
5479 |
} else if (sel == last_2) { |
|
5480 |
pIlc = &ilc_2; |
|
5481 |
} else if (sel == last_3) { |
|
5482 |
pIlc = &ilc_3; |
|
5483 |
} else if (sel == last_4) { |
|
5484 |
pIlc = &ilc_4; |
|
5485 |
} else { |
|
5486 |
if (flip == 0) { |
|
5487 |
pIlc = &ilc_0; |
|
5488 |
flip = 1; |
|
5489 |
last_0 = sel; |
|
5490 |
} else if (flip == 1) { |
|
5491 |
pIlc = &ilc_1; |
|
5492 |
flip = 2; |
|
5493 |
last_1 = sel; |
|
5494 |
} else if (flip == 2) { |
|
5495 |
pIlc = &ilc_2; |
|
5496 |
flip = 3; |
|
5497 |
last_2 = sel; |
|
5498 |
} else if (flip == 3) { |
|
5499 |
pIlc = &ilc_3; |
|
5500 |
flip = 4; |
|
5501 |
last_3 = sel; |
|
5502 |
} else { |
|
5503 |
pIlc = &ilc_4; |
|
5504 |
flip = 0; |
|
5505 |
last_4 = sel; |
|
5506 |
} |
|
5507 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5508 |
if (pIlc->ilc_poly) { |
|
5509 |
__flushPolyCache(pIlc->ilc_poly); |
|
5510 |
pIlc->ilc_poly = 0; |
|
5511 |
} |
|
5512 |
} |
|
5513 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
|
5755 | 5514 |
} else { |
6654 | 5515 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
5516 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
5755 | 5517 |
} |
5518 |
%}. |
|
5519 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5520 |
||
5521 |
! |
|
5522 |
||
5523 |
perform:aSelector with:arg1 with:arg2 |
|
5524 |
"send the two-arg-message aSelector to the receiver" |
|
5525 |
||
5526 |
%{ |
|
5527 |
struct inlineCache *pIlc; |
|
5528 |
||
5529 |
if (InterruptPending == nil) { |
|
6654 | 5530 |
static struct inlineCache ilc_0 = __ILCPERF2(@line); |
5531 |
static struct inlineCache ilc_1 = __ILCPERF2(@line); |
|
5532 |
static OBJ last_0 = nil; |
|
5533 |
static OBJ last_1 = nil; |
|
5534 |
static flip = 0; |
|
5535 |
||
5536 |
if (aSelector == last_0) { |
|
5537 |
pIlc = &ilc_0; |
|
5538 |
} else if (aSelector == last_1) { |
|
5539 |
pIlc = &ilc_1; |
|
5540 |
} else { |
|
5541 |
if (flip == 0) { |
|
5542 |
pIlc = &ilc_0; |
|
5543 |
flip = 1; |
|
5544 |
last_0 = aSelector; |
|
5545 |
} else { |
|
5546 |
pIlc = &ilc_1; |
|
5547 |
flip = 0; |
|
5548 |
last_1 = aSelector; |
|
5549 |
} |
|
5550 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5551 |
if (pIlc->ilc_poly) { |
|
5552 |
__flushPolyCache(pIlc->ilc_poly); |
|
5553 |
pIlc->ilc_poly = 0; |
|
5554 |
} |
|
5555 |
} |
|
5556 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
|
5755 | 5557 |
} else { |
6654 | 5558 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
5559 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, arg1, arg2)); |
|
5755 | 5560 |
} |
5561 |
%}. |
|
5562 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2) |
|
5563 |
||
5564 |
! |
|
5565 |
||
5566 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
|
5567 |
"send the three-arg-message aSelector to the receiver" |
|
5568 |
||
5569 |
%{ |
|
5570 |
struct inlineCache *pIlc; |
|
5571 |
static struct inlineCache ilc_0 = __ILCPERF3(@line); |
|
5572 |
static struct inlineCache ilc_1 = __ILCPERF3(@line); |
|
5573 |
static OBJ last_0 = nil; |
|
5574 |
static OBJ last_1 = nil; |
|
5575 |
static flip = 0; |
|
5576 |
||
5577 |
if (InterruptPending == nil) { |
|
6654 | 5578 |
if (aSelector != last_0) { |
5579 |
if (aSelector != last_1) { |
|
5580 |
if (flip) { |
|
5581 |
pIlc = &ilc_0; |
|
5582 |
flip = 0; |
|
5583 |
last_0 = aSelector; |
|
5584 |
} else { |
|
5585 |
pIlc = &ilc_1; |
|
5586 |
flip = 1; |
|
5587 |
last_1 = aSelector; |
|
5588 |
} |
|
5589 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5590 |
if (pIlc->ilc_poly) { |
|
5591 |
__flushPolyCache(pIlc->ilc_poly); |
|
5592 |
pIlc->ilc_poly = 0; |
|
5593 |
} |
|
5594 |
} else { |
|
5595 |
pIlc = &ilc_1; |
|
5596 |
} |
|
5597 |
} else { |
|
5598 |
pIlc = &ilc_0; |
|
5599 |
} |
|
5600 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
|
5755 | 5601 |
} else { |
6654 | 5602 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
5603 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, arg1, arg2, arg3)); |
|
5755 | 5604 |
} |
5605 |
%}. |
|
5606 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3) |
|
5607 |
||
5608 |
! |
|
5609 |
||
5610 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
5611 |
"send the four-arg-message aSelector to the receiver" |
|
5612 |
||
5613 |
%{ |
|
5614 |
struct inlineCache *pIlc; |
|
5615 |
static struct inlineCache ilc_0 = __ILCPERF4(@line); |
|
5616 |
static struct inlineCache ilc_1 = __ILCPERF4(@line); |
|
5617 |
static OBJ last_0 = nil; |
|
5618 |
static OBJ last_1 = nil; |
|
5619 |
static flip = 0; |
|
5620 |
||
5621 |
if (InterruptPending == nil) { |
|
6654 | 5622 |
if (aSelector != last_0) { |
5623 |
if (aSelector != last_1) { |
|
5624 |
if (flip) { |
|
5625 |
pIlc = &ilc_0; |
|
5626 |
flip = 0; |
|
5627 |
last_0 = aSelector; |
|
5628 |
} else { |
|
5629 |
pIlc = &ilc_1; |
|
5630 |
flip = 1; |
|
5631 |
last_1 = aSelector; |
|
5632 |
} |
|
5633 |
pIlc->ilc_func = __SEND4ADDR__; |
|
5634 |
if (pIlc->ilc_poly) { |
|
5635 |
__flushPolyCache(pIlc->ilc_poly); |
|
5636 |
pIlc->ilc_poly = 0; |
|
5637 |
} |
|
5638 |
} else { |
|
5639 |
pIlc = &ilc_1; |
|
5640 |
} |
|
5641 |
} else { |
|
5642 |
pIlc = &ilc_0; |
|
5643 |
} |
|
5644 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5645 |
arg1, arg2, arg3, arg4) ); |
|
5755 | 5646 |
} else { |
6654 | 5647 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
5648 |
RETURN (_SEND4(self, aSelector, nil, &ilc4, |
|
5649 |
arg1, arg2, arg3, arg4)); |
|
5755 | 5650 |
} |
5651 |
%}. |
|
5652 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
5653 |
||
5654 |
! |
|
5655 |
||
5656 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
5657 |
"send the five-arg-message aSelector to the receiver" |
|
5658 |
||
5659 |
%{ |
|
5660 |
struct inlineCache *pIlc; |
|
5661 |
static struct inlineCache ilc_0 = __ILCPERF5(@line); |
|
5662 |
static struct inlineCache ilc_1 = __ILCPERF5(@line); |
|
5663 |
static OBJ last_0 = nil; |
|
5664 |
static OBJ last_1 = nil; |
|
5665 |
static flip = 0; |
|
5666 |
||
5667 |
if (InterruptPending == nil) { |
|
6654 | 5668 |
if (aSelector != last_0) { |
5669 |
if (aSelector != last_1) { |
|
5670 |
if (flip) { |
|
5671 |
pIlc = &ilc_0; |
|
5672 |
flip = 0; |
|
5673 |
last_0 = aSelector; |
|
5674 |
} else { |
|
5675 |
pIlc = &ilc_1; |
|
5676 |
flip = 1; |
|
5677 |
last_1 = aSelector; |
|
5678 |
} |
|
5679 |
pIlc->ilc_func = __SEND5ADDR__; |
|
5680 |
if (pIlc->ilc_poly) { |
|
5681 |
__flushPolyCache(pIlc->ilc_poly); |
|
5682 |
pIlc->ilc_poly = 0; |
|
5683 |
} |
|
5684 |
} else { |
|
5685 |
pIlc = &ilc_1; |
|
5686 |
} |
|
5687 |
} else { |
|
5688 |
pIlc = &ilc_0; |
|
5689 |
} |
|
5690 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5691 |
arg1, arg2, arg3, arg4, arg5) ); |
|
5755 | 5692 |
} else { |
6654 | 5693 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
5694 |
RETURN (_SEND5(self, aSelector, nil, &ilc5, |
|
5695 |
arg1, arg2, arg3, arg4, arg5)); |
|
5755 | 5696 |
} |
5697 |
%}. |
|
5698 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
6654 | 5699 |
with:arg5) |
5755 | 5700 |
|
5701 |
! |
|
5702 |
||
5703 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
|
5704 |
"send the six-arg-message aSelector to the receiver" |
|
5705 |
||
5706 |
%{ |
|
5707 |
struct inlineCache *pIlc; |
|
5708 |
static struct inlineCache ilc_0 = __ILCPERF6(@line); |
|
5709 |
static struct inlineCache ilc_1 = __ILCPERF6(@line); |
|
5710 |
static OBJ last_0 = nil; |
|
5711 |
static OBJ last_1 = nil; |
|
5712 |
static flip = 0; |
|
5713 |
||
5714 |
if (InterruptPending == nil) { |
|
6654 | 5715 |
if (aSelector != last_0) { |
5716 |
if (aSelector != last_1) { |
|
5717 |
if (flip) { |
|
5718 |
pIlc = &ilc_0; |
|
5719 |
flip = 0; |
|
5720 |
last_0 = aSelector; |
|
5721 |
} else { |
|
5722 |
pIlc = &ilc_1; |
|
5723 |
flip = 1; |
|
5724 |
last_1 = aSelector; |
|
5725 |
} |
|
5726 |
pIlc->ilc_func = __SEND6ADDR__; |
|
5727 |
if (pIlc->ilc_poly) { |
|
5728 |
__flushPolyCache(pIlc->ilc_poly); |
|
5729 |
pIlc->ilc_poly = 0; |
|
5730 |
} |
|
5731 |
} else { |
|
5732 |
pIlc = &ilc_1; |
|
5733 |
} |
|
5734 |
} else { |
|
5735 |
pIlc = &ilc_0; |
|
5736 |
} |
|
5737 |
||
5738 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5739 |
arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
5755 | 5740 |
} else { |
6654 | 5741 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
5742 |
RETURN (_SEND6(self, aSelector, nil, &ilc6, |
|
5743 |
arg1, arg2, arg3, arg4, arg5, arg6)); |
|
5755 | 5744 |
} |
5745 |
%}. |
|
5746 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
6654 | 5747 |
with:arg5 with:arg6) |
5755 | 5748 |
|
5749 |
! |
|
5750 |
||
5751 |
perform:aSelector withArguments:argArray |
|
5752 |
"send the message aSelector with all args taken from argArray |
|
5753 |
to the receiver." |
|
5754 |
||
5755 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
5756 |
||
5757 |
%{ |
|
5758 |
REGISTER OBJ *argP; |
|
5759 |
int nargs; |
|
5760 |
OBJ l; |
|
5761 |
||
5762 |
if (__isArray(argArray)) { |
|
6654 | 5763 |
nargs = __arraySize(argArray); |
5764 |
argP = __arrayVal(argArray); |
|
5755 | 5765 |
} else { |
6654 | 5766 |
if (__isNonNilObject(argArray)) { |
5767 |
static struct inlineCache ilcSize = __ILC0(@line); |
|
5768 |
int i; |
|
5769 |
||
5770 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5771 |
if (!__isSmallInteger(numberOfArgs)) |
|
5772 |
goto bad; |
|
5773 |
nargs = __intVal(numberOfArgs); |
|
5774 |
argP = (OBJ *)(&a1); |
|
5775 |
for (i=1; i <= nargs; i++) { |
|
5776 |
*argP++ = __AT_(argArray, __MKSMALLINT((INT)i)); |
|
5777 |
} |
|
5778 |
argP = (OBJ *)(&a1); |
|
5779 |
} else { |
|
5780 |
nargs = 0; |
|
5781 |
} |
|
5755 | 5782 |
} |
5783 |
switch (nargs) { |
|
6654 | 5784 |
case 0: |
5785 |
if (InterruptPending == nil) { |
|
5786 |
static OBJ last0_0 = nil; static struct inlineCache ilc0_0 = __ILCPERF0(@line); |
|
5787 |
static OBJ last0_1 = nil; static struct inlineCache ilc0_1 = __ILCPERF0(@line); |
|
5788 |
static OBJ last0_2 = nil; static struct inlineCache ilc0_2 = __ILCPERF0(@line); |
|
5789 |
static OBJ last0_3 = nil; static struct inlineCache ilc0_3 = __ILCPERF0(@line); |
|
5790 |
static int flip0 = 0; |
|
5791 |
struct inlineCache *pIlc; |
|
5792 |
||
5793 |
if (aSelector == last0_0) { |
|
5794 |
pIlc = &ilc0_0; |
|
5795 |
} else if (aSelector == last0_1) { |
|
5796 |
pIlc = &ilc0_1; |
|
5797 |
} else if (aSelector == last0_2) { |
|
5798 |
pIlc = &ilc0_2; |
|
5799 |
} else if (aSelector == last0_3) { |
|
5800 |
pIlc = &ilc0_3; |
|
5801 |
} else { |
|
5802 |
if (flip0 == 0) { |
|
5803 |
pIlc = &ilc0_0; |
|
5804 |
flip0 = 1; |
|
5805 |
last0_0 = aSelector; |
|
5806 |
} else if (flip0 == 1) { |
|
5807 |
pIlc = &ilc0_1; |
|
5808 |
flip0 = 2; |
|
5809 |
last0_1 = aSelector; |
|
5810 |
} else if (flip0 == 2) { |
|
5811 |
pIlc = &ilc0_2; |
|
5812 |
flip0 = 3; |
|
5813 |
last0_2 = aSelector; |
|
5814 |
} else { |
|
5815 |
pIlc = &ilc0_3; |
|
5816 |
flip0 = 0; |
|
5817 |
last0_3 = aSelector; |
|
5818 |
} |
|
5819 |
||
5820 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5821 |
if (pIlc->ilc_poly) { |
|
5822 |
__flushPolyCache(pIlc->ilc_poly); |
|
5823 |
pIlc->ilc_poly = 0; |
|
5824 |
} |
|
5825 |
} |
|
5826 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc)); |
|
5827 |
} else { |
|
5828 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5829 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5830 |
} |
|
5831 |
||
5832 |
case 1: |
|
5833 |
if (InterruptPending == nil) { |
|
5834 |
static OBJ last1_0 = nil; static struct inlineCache ilc1_0 = __ILCPERF1(@line); |
|
5835 |
static OBJ last1_1 = nil; static struct inlineCache ilc1_1 = __ILCPERF1(@line); |
|
5836 |
static OBJ last1_2 = nil; static struct inlineCache ilc1_2 = __ILCPERF1(@line); |
|
5837 |
static OBJ last1_3 = nil; static struct inlineCache ilc1_3 = __ILCPERF1(@line); |
|
5838 |
static int flip1 = 0; |
|
5839 |
struct inlineCache *pIlc; |
|
5840 |
||
5841 |
if (aSelector == last1_0) { |
|
5842 |
pIlc = &ilc1_0; |
|
5843 |
} else if (aSelector == last1_1) { |
|
5844 |
pIlc = &ilc1_1; |
|
5845 |
} else if (aSelector == last1_2) { |
|
5846 |
pIlc = &ilc1_2; |
|
5847 |
} else if (aSelector == last1_3) { |
|
5848 |
pIlc = &ilc1_3; |
|
5849 |
} else { |
|
5850 |
if (flip1 == 0) { |
|
5851 |
pIlc = &ilc1_0; |
|
5852 |
flip1 = 1; |
|
5853 |
last1_0 = aSelector; |
|
5854 |
} else if (flip1 == 1) { |
|
5855 |
pIlc = &ilc1_1; |
|
5856 |
flip1 = 2; |
|
5857 |
last1_1 = aSelector; |
|
5858 |
} else if (flip1 == 2) { |
|
5859 |
pIlc = &ilc1_2; |
|
5860 |
flip1 = 3; |
|
5861 |
last1_2 = aSelector; |
|
5862 |
} else { |
|
5863 |
pIlc = &ilc1_3; |
|
5864 |
flip1 = 0; |
|
5865 |
last1_3 = aSelector; |
|
5866 |
} |
|
5867 |
||
5868 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5869 |
if (pIlc->ilc_poly) { |
|
5870 |
__flushPolyCache(pIlc->ilc_poly); |
|
5871 |
pIlc->ilc_poly = 0; |
|
5872 |
} |
|
5873 |
} |
|
5874 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0])); |
|
5875 |
} else { |
|
5876 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5877 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, argP[0])); |
|
5878 |
} |
|
5879 |
||
5880 |
case 2: |
|
5881 |
if (InterruptPending == nil) { |
|
5882 |
static OBJ last2_0 = nil; static struct inlineCache ilc2_0 = __ILCPERF2(@line); |
|
5883 |
static OBJ last2_1 = nil; static struct inlineCache ilc2_1 = __ILCPERF2(@line); |
|
5884 |
static int flip2 = 0; |
|
5885 |
struct inlineCache *pIlc; |
|
5886 |
||
5887 |
if (aSelector == last2_0) { |
|
5888 |
pIlc = &ilc2_0; |
|
5889 |
} else if (aSelector == last2_1) { |
|
5890 |
pIlc = &ilc2_1; |
|
5891 |
} else { |
|
5892 |
if (flip2 == 0) { |
|
5893 |
pIlc = &ilc2_0; |
|
5894 |
flip2 = 1; |
|
5895 |
last2_0 = aSelector; |
|
5896 |
} else { |
|
5897 |
pIlc = &ilc2_1; |
|
5898 |
flip2 = 0; |
|
5899 |
last2_1 = aSelector; |
|
5900 |
} |
|
5901 |
||
5902 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5903 |
if (pIlc->ilc_poly) { |
|
5904 |
__flushPolyCache(pIlc->ilc_poly); |
|
5905 |
pIlc->ilc_poly = 0; |
|
5906 |
} |
|
5907 |
} |
|
5908 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1])); |
|
5909 |
} else { |
|
5910 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5911 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, argP[0], argP[1])); |
|
5912 |
} |
|
5913 |
||
5914 |
case 3: |
|
5915 |
if (InterruptPending == nil) { |
|
5916 |
static OBJ last3_0 = nil; static struct inlineCache ilc3_0 = __ILCPERF3(@line); |
|
5917 |
static OBJ last3_1 = nil; static struct inlineCache ilc3_1 = __ILCPERF3(@line); |
|
5918 |
static int flip3 = 0; |
|
5919 |
struct inlineCache *pIlc; |
|
5920 |
||
5921 |
if (aSelector == last3_0) { |
|
5922 |
pIlc = &ilc3_0; |
|
5923 |
} else if (aSelector == last3_1) { |
|
5924 |
pIlc = &ilc3_1; |
|
5925 |
} else { |
|
5926 |
if (flip3 == 0) { |
|
5927 |
pIlc = &ilc3_0; |
|
5928 |
flip3 = 1; |
|
5929 |
last3_0 = aSelector; |
|
5930 |
} else { |
|
5931 |
pIlc = &ilc3_1; |
|
5932 |
flip3 = 0; |
|
5933 |
last3_1 = aSelector; |
|
5934 |
} |
|
5935 |
||
5936 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5937 |
if (pIlc->ilc_poly) { |
|
5938 |
__flushPolyCache(pIlc->ilc_poly); |
|
5939 |
pIlc->ilc_poly = 0; |
|
5940 |
} |
|
5941 |
} |
|
5942 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1], argP[2])); |
|
5943 |
} else { |
|
5944 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5945 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, argP[0], argP[1], argP[2])); |
|
5946 |
} |
|
5947 |
||
5948 |
case 4: |
|
5949 |
{ |
|
5950 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(@line); |
|
5951 |
||
5952 |
if ((InterruptPending != nil) || (aSelector != last4)) { |
|
5953 |
ilc4.ilc_func = __SEND4ADDR__; |
|
5954 |
if (ilc4.ilc_poly) { |
|
5955 |
__flushPolyCache(ilc4.ilc_poly); |
|
5956 |
ilc4.ilc_poly = 0; |
|
5957 |
} |
|
5958 |
last4 = aSelector; |
|
5959 |
} |
|
5960 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
|
5961 |
argP[0], argP[1], argP[2], argP[3])); |
|
5962 |
} |
|
5963 |
||
5964 |
case 5: |
|
5965 |
{ |
|
5966 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(@line); |
|
5967 |
||
5968 |
if ((InterruptPending != nil) || (aSelector != last5)) { |
|
5969 |
ilc5.ilc_func = __SEND5ADDR__; |
|
5970 |
if (ilc5.ilc_poly) { |
|
5971 |
__flushPolyCache(ilc5.ilc_poly); |
|
5972 |
ilc5.ilc_poly = 0; |
|
5973 |
} |
|
5974 |
last5 = aSelector; |
|
5975 |
} |
|
5976 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
|
5977 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5978 |
} |
|
5979 |
||
5980 |
case 6: |
|
5981 |
{ |
|
5982 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(@line); |
|
5983 |
||
5984 |
if ((InterruptPending != nil) || (aSelector != last6)) { |
|
5985 |
ilc6.ilc_func = __SEND6ADDR__; |
|
5986 |
if (ilc6.ilc_poly) { |
|
5987 |
__flushPolyCache(ilc6.ilc_poly); |
|
5988 |
ilc6.ilc_poly = 0; |
|
5989 |
} |
|
5990 |
last6 = aSelector; |
|
5991 |
} |
|
5992 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
|
5993 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5994 |
argP[5])); |
|
5995 |
} |
|
5996 |
||
5997 |
case 7: |
|
5998 |
{ |
|
5999 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(@line); |
|
6000 |
||
6001 |
if ((InterruptPending != nil) || (aSelector != last7)) { |
|
6002 |
ilc7.ilc_func = __SEND7ADDR__; |
|
6003 |
if (ilc7.ilc_poly) { |
|
6004 |
__flushPolyCache(ilc7.ilc_poly); |
|
6005 |
ilc7.ilc_poly = 0; |
|
6006 |
} |
|
6007 |
last7 = aSelector; |
|
6008 |
} |
|
6009 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
|
6010 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6011 |
argP[5], argP[6])); |
|
6012 |
} |
|
6013 |
||
6014 |
case 8: |
|
6015 |
{ |
|
6016 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(@line); |
|
6017 |
||
6018 |
if ((InterruptPending != nil) || (aSelector != last8)) { |
|
6019 |
ilc8.ilc_func = __SEND8ADDR__; |
|
6020 |
if (ilc8.ilc_poly) { |
|
6021 |
__flushPolyCache(ilc8.ilc_poly); |
|
6022 |
ilc8.ilc_poly = 0; |
|
6023 |
} |
|
6024 |
last8 = aSelector; |
|
6025 |
} |
|
6026 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
|
6027 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6028 |
argP[5], argP[6], argP[7])); |
|
6029 |
} |
|
6030 |
||
6031 |
case 9: |
|
6032 |
{ |
|
6033 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(@line); |
|
6034 |
||
6035 |
if ((InterruptPending != nil) || (aSelector != last9)) { |
|
6036 |
ilc9.ilc_func = __SEND9ADDR__; |
|
6037 |
if (ilc9.ilc_poly) { |
|
6038 |
__flushPolyCache(ilc9.ilc_poly); |
|
6039 |
ilc9.ilc_poly = 0; |
|
6040 |
} |
|
6041 |
last9 = aSelector; |
|
6042 |
} |
|
6043 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
|
6044 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6045 |
argP[5], argP[6], argP[7], argP[8])); |
|
6046 |
} |
|
6047 |
||
6048 |
case 10: |
|
6049 |
{ |
|
6050 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(@line); |
|
6051 |
||
6052 |
if ((InterruptPending != nil) || (aSelector != last10)) { |
|
6053 |
ilc10.ilc_func = __SEND10ADDR__; |
|
6054 |
if (ilc10.ilc_poly) { |
|
6055 |
__flushPolyCache(ilc10.ilc_poly); |
|
6056 |
ilc10.ilc_poly = 0; |
|
6057 |
} |
|
6058 |
last10 = aSelector; |
|
6059 |
} |
|
6060 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
|
6061 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6062 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
6063 |
} |
|
6064 |
||
6065 |
case 11: |
|
6066 |
{ |
|
6067 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(@line); |
|
6068 |
||
6069 |
if ((InterruptPending != nil) || (aSelector != last11)) { |
|
6070 |
ilc11.ilc_func = __SEND11ADDR__; |
|
6071 |
if (ilc11.ilc_poly) { |
|
6072 |
__flushPolyCache(ilc11.ilc_poly); |
|
6073 |
ilc11.ilc_poly = 0; |
|
6074 |
} |
|
6075 |
last11 = aSelector; |
|
6076 |
} |
|
6077 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
|
6078 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6079 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6080 |
argP[10])); |
|
6081 |
} |
|
6082 |
||
6083 |
case 12: |
|
6084 |
{ |
|
6085 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(@line); |
|
6086 |
||
6087 |
if ((InterruptPending != nil) || (aSelector != last12)) { |
|
6088 |
ilc12.ilc_func = __SEND12ADDR__; |
|
6089 |
if (ilc12.ilc_poly) { |
|
6090 |
__flushPolyCache(ilc12.ilc_poly); |
|
6091 |
ilc12.ilc_poly = 0; |
|
6092 |
} |
|
6093 |
last12 = aSelector; |
|
6094 |
} |
|
6095 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
|
6096 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6097 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6098 |
argP[10], argP[11])); |
|
6099 |
} |
|
6100 |
||
6101 |
case 13: |
|
6102 |
{ |
|
6103 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(@line); |
|
6104 |
||
6105 |
if ((InterruptPending != nil) || (aSelector != last13)) { |
|
6106 |
ilc13.ilc_func = __SEND13ADDR__; |
|
6107 |
if (ilc13.ilc_poly) { |
|
6108 |
__flushPolyCache(ilc13.ilc_poly); |
|
6109 |
ilc13.ilc_poly = 0; |
|
6110 |
} |
|
6111 |
last13 = aSelector; |
|
6112 |
} |
|
6113 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
|
6114 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6115 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6116 |
argP[10], argP[11], argP[12])); |
|
6117 |
} |
|
6118 |
||
6119 |
case 14: |
|
6120 |
{ |
|
6121 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(@line); |
|
6122 |
||
6123 |
if ((InterruptPending != nil) || (aSelector != last14)) { |
|
6124 |
ilc14.ilc_func = __SEND14ADDR__; |
|
6125 |
if (ilc14.ilc_poly) { |
|
6126 |
__flushPolyCache(ilc14.ilc_poly); |
|
6127 |
ilc14.ilc_poly = 0; |
|
6128 |
} |
|
6129 |
last14 = aSelector; |
|
6130 |
} |
|
6131 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
|
6132 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6133 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6134 |
argP[10], argP[11], argP[12], argP[13])); |
|
6135 |
} |
|
6136 |
||
6137 |
case 15: |
|
6138 |
{ |
|
6139 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(@line); |
|
6140 |
||
6141 |
if ((InterruptPending != nil) || (aSelector != last15)) { |
|
6142 |
ilc15.ilc_func = __SEND15ADDR__; |
|
6143 |
if (ilc15.ilc_poly) { |
|
6144 |
__flushPolyCache(ilc15.ilc_poly); |
|
6145 |
ilc15.ilc_poly = 0; |
|
6146 |
} |
|
6147 |
last15 = aSelector; |
|
6148 |
} |
|
6149 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
|
6150 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6151 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6152 |
argP[10], argP[11], argP[12], argP[13], |
|
6153 |
argP[14])); |
|
6154 |
} |
|
5755 | 6155 |
} |
6156 |
bad:; |
|
6157 |
%}. |
|
6158 |
||
6159 |
"/ arrive here, if bad number of arguments (too many) |
|
6160 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
6161 |
||
6162 |
^ self primitiveFailed |
|
6163 |
! |
|
6164 |
||
6316 | 6165 |
perform:aSelector withOptionalArgument:arg |
6166 |
"send aSelector-message to the receiver. |
|
6318 | 6167 |
If the message expects an argument, pass arg." |
6316 | 6168 |
|
6169 |
aSelector numArgs == 1 ifTrue:[ |
|
6654 | 6170 |
^ self perform:aSelector with:arg |
6316 | 6171 |
]. |
6172 |
^ self perform:aSelector |
|
6319 | 6173 |
|
6174 |
" |
|
6175 |
|rec sel| |
|
6176 |
||
6177 |
rec := -1. |
|
6178 |
sel := #abs. |
|
6179 |
rec perform:sel withOptionalArgument:2. |
|
6180 |
||
6181 |
sel := #max:. |
|
6182 |
rec perform:sel withOptionalArgument:2. |
|
6183 |
" |
|
6316 | 6184 |
! |
6185 |
||
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6186 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6187 |
"send aSelector-message to the receiver. |
6728 | 6188 |
Depending on the number of arguments the message expects, |
6189 |
pass either none, 1, or 2 arguments." |
|
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6190 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6191 |
|numArgs| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6192 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6193 |
numArgs := aSelector numArgs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6194 |
numArgs == 0 ifTrue:[ |
6654 | 6195 |
^ self perform:aSelector |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6196 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6197 |
numArgs == 1 ifTrue:[ |
6654 | 6198 |
^ self perform:aSelector with:optionalArg1 |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6199 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6200 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6201 |
|
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 |
|rec sel| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6204 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6205 |
rec := -1. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6206 |
sel := #abs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6207 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6208 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6209 |
sel := #max:. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6210 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6211 |
" |
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 |
|
6728 | 6214 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 |
6215 |
"send aSelector-message to the receiver. |
|
6216 |
Depending on the number of arguments the message expects, |
|
6217 |
pass either none, 1, 2 or 3 arguments." |
|
6218 |
||
6219 |
|numArgs| |
|
6220 |
||
6221 |
numArgs := aSelector numArgs. |
|
6222 |
numArgs == 0 ifTrue:[ |
|
6223 |
^ self perform:aSelector |
|
6224 |
]. |
|
6225 |
numArgs == 1 ifTrue:[ |
|
6226 |
^ self perform:aSelector with:optionalArg1 |
|
6227 |
]. |
|
6228 |
numArgs == 2 ifTrue:[ |
|
6229 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
|
6230 |
]. |
|
6231 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3. |
|
6232 |
||
6233 |
" |
|
6234 |
|rec sel| |
|
6235 |
||
6236 |
rec := -1. |
|
6237 |
sel := #abs. |
|
6238 |
rec perform:sel withOptionalArgument:2. |
|
6239 |
||
6240 |
sel := #max:. |
|
6241 |
rec perform:sel withOptionalArgument:2. |
|
6242 |
" |
|
6243 |
! |
|
6244 |
||
6764 | 6245 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 and:optionalArg4 |
6246 |
"send aSelector-message to the receiver. |
|
6247 |
Depending on the number of arguments the message expects, |
|
6248 |
pass either none, 1, 2, 3 or 4 arguments." |
|
6249 |
||
6250 |
|numArgs| |
|
6251 |
||
6252 |
numArgs := aSelector numArgs. |
|
6253 |
numArgs == 0 ifTrue:[ |
|
6254 |
^ self perform:aSelector |
|
6255 |
]. |
|
6256 |
numArgs == 1 ifTrue:[ |
|
6257 |
^ self perform:aSelector with:optionalArg1 |
|
6258 |
]. |
|
6259 |
numArgs == 2 ifTrue:[ |
|
6260 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
|
6261 |
]. |
|
6262 |
numArgs == 3 ifTrue:[ |
|
6263 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 |
|
6264 |
]. |
|
6265 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 with:optionalArg4. |
|
6266 |
||
6267 |
" |
|
6268 |
|rec sel| |
|
6269 |
||
6270 |
rec := -1. |
|
6271 |
sel := #abs. |
|
6272 |
rec perform:sel withOptionalArgument:2. |
|
6273 |
||
6274 |
sel := #max:. |
|
6275 |
rec perform:sel withOptionalArgument:2. |
|
6276 |
" |
|
6277 |
! |
|
6278 |
||
5755 | 6279 |
performMethod:aMethod |
6280 |
"invoke aMethod on the receiver. |
|
6281 |
The method should be a zero-argument method. |
|
6282 |
This is a non-object-oriented entry, applying a method |
|
6283 |
in a functional way on a receiver. |
|
6284 |
Warning: |
|
6654 | 6285 |
Take care for the method to be appropriate for the |
6286 |
receiver - no checking is done by the VM." |
|
5755 | 6287 |
|
6288 |
^ aMethod valueWithReceiver:self arguments:#() |
|
6289 |
||
6290 |
" |
|
6291 |
|mthd| |
|
6292 |
||
6293 |
mthd := SmallInteger compiledMethodAt:#negated. |
|
6294 |
Transcript showCR:(1 performMethod:mthd) |
|
6295 |
" |
|
6296 |
||
6297 |
"BAD USE example: |
|
6298 |
||
6299 |
|mthd| |
|
6300 |
||
6301 |
mthd := Point compiledMethodAt:#x. |
|
6302 |
Transcript showCR:((1->2) performMethod:mthd) |
|
6303 |
" |
|
6304 |
||
6305 |
"Modified: 31.7.1997 / 17:41:50 / cg" |
|
6306 |
! |
|
6307 |
||
6308 |
performMethod:aMethod arguments:argumentArray |
|
6309 |
"invoke aMethod on the receiver, passing an argumentArray. |
|
6310 |
The size of the argumentArray should match the number of args |
|
6311 |
expected by the method. |
|
6312 |
This is a non-object-oriented entry, applying a method |
|
6313 |
in a functional way on a receiver. |
|
6314 |
Warning: |
|
6654 | 6315 |
Take care for the method to be appropriate for the |
6316 |
receiver - no checking is done by the VM." |
|
5755 | 6317 |
|
6318 |
^ aMethod valueWithReceiver:self arguments:argumentArray |
|
6319 |
||
6320 |
" |
|
6321 |
|mthd| |
|
6322 |
||
6323 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6324 |
Transcript showCR:(1 performMethod:mthd arguments:#(2)) |
|
6325 |
" |
|
6326 |
||
6327 |
"Created: 31.7.1997 / 17:46:31 / cg" |
|
6328 |
! |
|
6329 |
||
6330 |
performMethod:aMethod with:arg |
|
6331 |
"invoke aMethod on the receiver, passing an argument. |
|
6332 |
The method should be a one-argument method. |
|
6333 |
This is a non-object-oriented entry, applying a method |
|
6334 |
in a functional way on a receiver. |
|
6335 |
Warning: |
|
6654 | 6336 |
Take care for the method to be appropriate for the |
6337 |
receiver - no checking is done by the VM." |
|
5755 | 6338 |
|
6339 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg) |
|
6340 |
||
6341 |
" |
|
6342 |
|mthd| |
|
6343 |
||
6344 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6345 |
Transcript showCR:(1 performMethod:mthd with:2) |
|
6346 |
" |
|
6347 |
||
6348 |
"Modified: 31.7.1997 / 17:42:32 / cg" |
|
6349 |
! |
|
6350 |
||
6351 |
performMethod:aMethod with:arg1 with:arg2 |
|
6352 |
"invoke aMethod on the receiver, passing two arguments. |
|
6353 |
The method should be a two-argument method. |
|
6354 |
This is a non-object-oriented entry, applying a method |
|
6355 |
in a functional way on a receiver. |
|
6356 |
Warning: |
|
6654 | 6357 |
Take care for the method to be appropriate for the |
6358 |
receiver - no checking is done by the VM." |
|
5755 | 6359 |
|
6360 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) |
|
6361 |
||
6362 |
" |
|
6363 |
|mthd arr| |
|
6364 |
||
6365 |
arr := Array new:1. |
|
6366 |
mthd := Array compiledMethodAt:#basicAt:put:. |
|
6367 |
arr performMethod:mthd with:1 with:'foo'. |
|
6368 |
Transcript showCR:arr |
|
6369 |
" |
|
6370 |
||
6371 |
"Modified: 31.7.1997 / 17:44:54 / cg" |
|
6372 |
! |
|
6373 |
||
6374 |
performMethod:aMethod with:arg1 with:arg2 with:arg3 |
|
6375 |
"invoke aMethod on the receiver, passing three arguments. |
|
6376 |
The method should be a three-argument method. |
|
6377 |
This is a non-object-oriented entry, applying a method |
|
6378 |
in a functional way on a receiver. |
|
6379 |
Warning: |
|
6654 | 6380 |
Take care for the method to be appropriate for the |
6381 |
receiver - no checking is done by the VM." |
|
5755 | 6382 |
|
6383 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3) |
|
6384 |
||
6385 |
"Created: 31.7.1997 / 17:45:20 / cg" |
|
6386 |
! ! |
|
6387 |
||
6388 |
!Object methodsFor:'printing & storing'! |
|
6389 |
||
6235 | 6390 |
basicPrintOn:aStream |
6391 |
"append the receivers className with an articel to the argument, aStream" |
|
6392 |
||
6393 |
aStream nextPutAll:self classNameWithArticle |
|
6394 |
! |
|
6395 |
||
5755 | 6396 |
className |
6397 |
"return the classname of the receivers class" |
|
6398 |
||
6399 |
^ self class name |
|
6400 |
||
6401 |
" |
|
6402 |
1 className |
|
6403 |
1 class className 'this may change ...' |
|
6404 |
$a className |
|
6405 |
$a class className 'this may change ...' |
|
6406 |
" |
|
6407 |
! |
|
6408 |
||
6409 |
classNameWithArticle |
|
6410 |
"return a string consisting of classname preceeded by an article. |
|
6411 |
(dont expect me to write national variants for this ... :-) |
|
6412 |
If you have special preferences, redefine it ..." |
|
6413 |
||
6829 | 6414 |
| cls| |
5755 | 6415 |
|
6416 |
(cls := self class) == self ifTrue:[ |
|
6654 | 6417 |
^ 'a funny object' |
5755 | 6418 |
]. |
6829 | 6419 |
^ cls nameWithArticle |
5755 | 6420 |
|
6421 |
" |
|
6418 | 6422 |
1 classNameWithArticle |
6423 |
(1->2) classNameWithArticle |
|
5755 | 6424 |
XWorkstation basicNew classNameWithArticle |
6418 | 6425 |
XWorkstation classNameWithArticle |
5755 | 6426 |
" |
6427 |
||
6428 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
6429 |
! |
|
6430 |
||
6431 |
errorPrint |
|
6432 |
"print the receiver on the standard error stream." |
|
6433 |
||
6434 |
Stream streamErrorSignal catch:[ |
|
6654 | 6435 |
self printOn:Stderr |
5755 | 6436 |
] |
6437 |
||
6438 |
"Modified: 7.3.1996 / 19:11:29 / cg" |
|
6439 |
! |
|
6440 |
||
6441 |
errorPrintCR |
|
6442 |
"{ Pragma: +optSpace }" |
|
6443 |
||
6444 |
"print the receiver followed by a cr on the standard error stream." |
|
6445 |
||
6446 |
Stream streamErrorSignal catch:[ |
|
6654 | 6447 |
self printOn:Stderr. |
6448 |
Stderr cr |
|
5755 | 6449 |
] |
6450 |
||
6451 |
"Modified: 7.3.1996 / 19:13:01 / cg" |
|
6452 |
"Created: 20.5.1996 / 10:20:41 / cg" |
|
6453 |
! |
|
6454 |
||
6455 |
errorPrintNL |
|
6456 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6457 |
<resource:#obsolete> |
5755 | 6458 |
|
6459 |
"print the receiver followed by a cr on the standard error stream. |
|
6460 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6461 |
||
6462 |
^ self errorPrintCR |
|
6463 |
||
6464 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
6465 |
! |
|
6466 |
||
6467 |
errorPrintNewline |
|
6468 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6469 |
<resource:#obsolete> |
5755 | 6470 |
|
6471 |
"print the receiver followed by a cr on the standard error stream. |
|
6472 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6473 |
||
6474 |
self errorPrintCR. |
|
6475 |
||
6476 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
6477 |
! |
|
6478 |
||
6479 |
infoPrint |
|
6480 |
"{ Pragma: +optSpace }" |
|
6481 |
||
6482 |
"print the receiver on the standard error stream. |
|
6483 |
This is meant for information messages which are not warnings |
|
6484 |
or fatal messages. |
|
6485 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6486 |
||
6487 |
InfoPrinting == true ifTrue:[ |
|
6654 | 6488 |
self errorPrint |
5755 | 6489 |
] |
6490 |
! |
|
6491 |
||
6492 |
infoPrintCR |
|
6493 |
"{ Pragma: +optSpace }" |
|
6494 |
||
6495 |
"print the receiver followed by a cr on the standard error stream. |
|
6496 |
This is meant for information messages which are not warnings |
|
6497 |
or fatal messages. |
|
6498 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6499 |
||
6500 |
InfoPrinting == true ifTrue:[ |
|
6654 | 6501 |
self errorPrintCR |
5755 | 6502 |
] |
6503 |
||
6504 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
6505 |
! |
|
6506 |
||
6507 |
infoPrintNL |
|
6508 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6509 |
<resource:#obsolete> |
5755 | 6510 |
|
6511 |
"print the receiver followed by a cr on the standard error stream. |
|
6512 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
6513 |
||
6514 |
^ self infoPrintCR |
|
6515 |
! |
|
6516 |
||
6517 |
||
6518 |
"print the receiver on the standard output stream (which is not the Transcript)" |
|
6519 |
||
6520 |
"/ the following allows printCR to be used during |
|
6521 |
"/ the early init-phase, when no Stdout has been set up. |
|
6522 |
"/ (depends on string to respond to #print) |
|
6523 |
||
6524 |
Stdout isNil ifTrue:[ |
|
6654 | 6525 |
self printString print. |
6526 |
^ self |
|
5755 | 6527 |
]. |
6528 |
self printOn:Stdout |
|
6529 |
||
6530 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
6531 |
! |
|
6532 |
||
6533 |
printCR |
|
6534 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
|
6535 |
||
6536 |
"/ the following allows printCR to be used during |
|
6537 |
"/ the early init-phase, when no Stdout has been set up. |
|
6538 |
"/ (depends on string to respond to #printCR) |
|
6539 |
||
6540 |
Stdout isNil ifTrue:[ |
|
6654 | 6541 |
self printString printCR. |
6542 |
^ self |
|
5755 | 6543 |
]. |
6544 |
self printOn:Stdout. |
|
6545 |
Stdout cr |
|
6546 |
||
6547 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
6548 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
|
6549 |
! |
|
6550 |
||
6551 |
printNL |
|
6552 |
"print the receiver followed by a cr on the standard output stream |
|
6553 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
6554 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6555 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6556 |
|
5755 | 6557 |
^ self printCR |
6558 |
||
6559 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
6560 |
! |
|
6561 |
||
6562 |
printNewline |
|
6563 |
"print the receiver followed by a cr on the standard output stream. |
|
6564 |
This exists for backward compatibility - please use #printCR." |
|
6565 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6566 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6567 |
|
5755 | 6568 |
self printCR |
6569 |
||
6570 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
6571 |
! |
|
6572 |
||
6573 |
printOn:aStream |
|
6574 |
"append a user printed representation of the receiver to aStream. |
|
6575 |
The format is suitable for a human - not meant to be read back. |
|
6576 |
||
6577 |
The default here is to output the receivers class name. |
|
6578 |
BUT: this method is heavily redefined for objects which |
|
6579 |
can print prettier." |
|
6580 |
||
6235 | 6581 |
self basicPrintOn:aStream. |
6582 |
||
6583 |
" |
|
6584 |
(1@2) printOn:Transcript |
|
6585 |
(1@2) basicPrintOn:Transcript |
|
6586 |
" |
|
5755 | 6587 |
! |
6588 |
||
6589 |
printOn:aStream leftPaddedTo:size |
|
6590 |
"print the receiver on aStream, padding with spaces up to size. |
|
6591 |
padding is done on the left." |
|
6592 |
||
6593 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
6594 |
||
6595 |
" |
|
6596 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
6597 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
6598 |
" |
|
6599 |
! |
|
6600 |
||
6601 |
printOn:aStream leftPaddedTo:size with:padCharacter |
|
6602 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
6603 |
padding is done on the left." |
|
6604 |
||
6605 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
6606 |
||
6607 |
" |
|
6608 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
6609 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
6610 |
" |
|
6611 |
! |
|
6612 |
||
6613 |
printOn:aStream paddedTo:size |
|
6614 |
"print the receiver on aStream, padding with spaces up to size." |
|
6615 |
||
6616 |
self printOn:aStream paddedTo:size with:(Character space) |
|
6617 |
||
6618 |
" |
|
6619 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
6620 |
" |
|
6621 |
! |
|
6622 |
||
6623 |
printOn:aStream paddedTo:size with:padCharacter |
|
6624 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
6625 |
||
6626 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
6627 |
||
6628 |
" |
|
6629 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
6630 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
6631 |
" |
|
6632 |
! |
|
6633 |
||
6634 |
printOn:aStream zeroPaddedTo:size |
|
6635 |
"print the receiver on aStream, padding with zeros up to size. |
|
6636 |
Usually used with float numbers." |
|
6637 |
||
6638 |
self printOn:aStream paddedTo:size with:$0. |
|
6639 |
||
6640 |
" |
|
6641 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
6642 |
" |
|
6643 |
! |
|
6644 |
||
6645 |
printRightAdjustLen:size |
|
6646 |
"obsolete - just a name confusion. |
|
6647 |
This method will go away ..." |
|
6648 |
||
6649 |
(self printStringLeftPaddedTo:size) printOn:Stdout |
|
6650 |
! |
|
6651 |
||
6652 |
printString |
|
6653 |
"return a string for printing the receiver. |
|
6654 |
Since we now use printOn: as the basic print mechanism, |
|
6655 |
we have to create a stream and print into it." |
|
6656 |
||
6657 |
|s| |
|
6658 |
||
6659 |
s := WriteStream on:(String new:30). |
|
6660 |
self printOn:s. |
|
6661 |
^ s contents |
|
6662 |
! |
|
6663 |
||
6664 |
printStringLeftPaddedTo:size |
|
6665 |
"return my printString as a right-adjusted string of length size; |
|
6666 |
characters on the left are filled with spaces. |
|
6667 |
If the printString is longer than size, |
|
6668 |
it is returned unchanged (i.e. not truncated)" |
|
6669 |
||
6670 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
6671 |
||
6672 |
" |
|
6673 |
10 printStringLeftPaddedTo:10 |
|
6674 |
1 printStringLeftPaddedTo:10 |
|
6675 |
" |
|
6676 |
! |
|
6677 |
||
6678 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
6679 |
"return my printString as a right-adjusted string of length size; |
|
6680 |
characters on the left are filled with spaces. |
|
6681 |
If the printString is larger than size, |
|
6682 |
return the result from evaluating alternative." |
|
6683 |
||
6684 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
6685 |
||
6686 |
" |
|
6687 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6688 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6689 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6690 |
" |
|
6691 |
! |
|
6692 |
||
6693 |
printStringLeftPaddedTo:size with:padCharacter |
|
6694 |
"return my printString as a right-adjusted string of length size; |
|
6695 |
characters on the left are filled with padCharacter. |
|
6696 |
If the printString is longer than size, |
|
6697 |
it is returned unchanged (i.e. not truncated)" |
|
6698 |
||
6699 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
6700 |
||
6701 |
" |
|
6702 |
123 printStringLeftPaddedTo:10 with:$. |
|
6703 |
1 printStringLeftPaddedTo:10 with:$. |
|
6704 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
|
6705 |
" |
|
6706 |
! |
|
6707 |
||
6708 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
6709 |
"return my printString as a right-adjusted string of length size; |
|
6710 |
characters on the left are filled with padCharacter. |
|
6711 |
If the printString is larger than size, |
|
6712 |
return the result from evaluating alternative." |
|
6713 |
||
6714 |
|s| |
|
6715 |
||
6716 |
s := self printString. |
|
6717 |
s size > size ifTrue:[^ alternative value]. |
|
6718 |
^ s leftPaddedTo:size with:padCharacter |
|
6719 |
||
6720 |
" |
|
6721 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6722 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6723 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6724 |
" |
|
6725 |
! |
|
6726 |
||
6727 |
printStringOnError:exceptionBlock |
|
6728 |
"return a string for printing the receiver; if any error occurs, return the result from |
|
6729 |
evaluating exceptionBlock. Useful to print something in an exceptionHandler or other |
|
6730 |
cleanup code." |
|
6731 |
||
6732 |
|rslt| |
|
6733 |
||
6734 |
Error handle:[:ex | |
|
6654 | 6735 |
rslt := exceptionBlock value |
5755 | 6736 |
] do:[ |
6654 | 6737 |
rslt := self printString |
5755 | 6738 |
]. |
6739 |
^ rslt |
|
6740 |
! |
|
6741 |
||
6742 |
printStringPaddedTo:size |
|
6743 |
"return a printed representation of the receiver, |
|
6744 |
padded with spaces (at the right) up to size. |
|
6745 |
If the printString is longer than size, |
|
6746 |
it is returned unchanged (i.e. not truncated)" |
|
6747 |
||
6748 |
^ self printStringPaddedTo:size with:(Character space) |
|
6749 |
||
6750 |
" |
|
6751 |
123 printStringPaddedTo:10 |
|
6752 |
1234567890123456 printStringPaddedTo:10 |
|
6753 |
'hello' printStringPaddedTo:10 |
|
6754 |
" |
|
6755 |
! |
|
6756 |
||
6757 |
printStringPaddedTo:size ifLarger:alternative |
|
6758 |
"return a printed representation of the receiver, |
|
6759 |
padded with spaces (at the right) up to size. |
|
6760 |
If the resulting printString is too large, |
|
6761 |
return the result from evaluating alternative." |
|
6762 |
||
6763 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
6764 |
||
6765 |
" |
|
6766 |
12 printStringPaddedTo:3 ifLarger:['***'] |
|
6767 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
6768 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
6769 |
" |
|
6770 |
! |
|
6771 |
||
6772 |
printStringPaddedTo:size with:padCharacter |
|
6773 |
"return a printed representation of the receiver, |
|
6774 |
padded with padCharacter (at the right) up to size. |
|
6775 |
If the printString is longer than size, |
|
6776 |
it is returned unchanged (i.e. not truncated)" |
|
6777 |
||
6778 |
^ (self printString) paddedTo:size with:padCharacter |
|
6779 |
||
6780 |
" |
|
6781 |
123 printStringPaddedTo:10 with:$. |
|
6782 |
123 printStringPaddedTo:10 with:$* |
|
6783 |
123 printStringPaddedTo:3 with:$* |
|
6784 |
1234 printStringPaddedTo:3 with:$* |
|
6785 |
" |
|
6786 |
! |
|
6787 |
||
6788 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
6789 |
"return a printed representation of the receiver, |
|
6790 |
padded with padCharacter (at the right) up to size. |
|
6791 |
If the resulting printString is too large, |
|
6792 |
return the result from evaluating alternative." |
|
6793 |
||
6794 |
|s| |
|
6795 |
||
6796 |
s := self printString. |
|
6797 |
s size > size ifTrue:[^ alternative value]. |
|
6798 |
^ s paddedTo:size with:padCharacter |
|
6799 |
||
6800 |
" |
|
6801 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6802 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6803 |
" |
|
6804 |
! |
|
6805 |
||
6806 |
printStringRightAdjustLen:size |
|
6807 |
"obsolete - just a name confusion. |
|
6808 |
This method will go away ..." |
|
6809 |
||
6810 |
^ self printStringLeftPaddedTo:size |
|
6811 |
! |
|
6812 |
||
6813 |
printStringZeroPaddedTo:size |
|
6814 |
"return a printed representation of the receiver, |
|
6815 |
padded with zero (at the right) characters up to size. |
|
6816 |
Usually used with float numbers." |
|
6817 |
||
6818 |
^ self printStringPaddedTo:size with:$0 |
|
6819 |
||
6820 |
" |
|
6821 |
123.0 printStringZeroPaddedTo:10 |
|
6822 |
" |
|
6823 |
! |
|
6824 |
||
6825 |
store |
|
6826 |
"store the receiver on standard output. |
|
6827 |
this method is useless, but included for compatibility." |
|
6828 |
||
6829 |
self storeOn:Stdout |
|
6830 |
! |
|
6831 |
||
6832 |
storeCR |
|
6833 |
"store the receiver on standard output; append a carriage return." |
|
6834 |
||
6835 |
self store. |
|
6836 |
Character cr print |
|
6837 |
||
6838 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
6839 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
6840 |
! |
|
6841 |
||
6842 |
storeNl |
|
6843 |
"store the receiver on standard output; append a newline. |
|
6844 |
This method is included for backward compatibility- use #storeCR." |
|
6845 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6846 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6847 |
|
5755 | 6848 |
self storeCR. |
6849 |
||
6850 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
6851 |
! |
|
6852 |
||
6853 |
storeOn:aStream |
|
6854 |
"store the receiver on aStream; i.e. print an expression which will |
|
6855 |
reconstruct the receiver. |
|
6856 |
Notice, that no self referencing or cyclic objects can be represented |
|
6857 |
in this format. |
|
6858 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6859 |
||
6860 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
6861 |
||
6862 |
thisContext isRecursive ifTrue:[ |
|
6654 | 6863 |
Object recursiveStoreStringSignal raiseRequestWith:self. |
6864 |
('Object [error]: storeString of self referencing object.') errorPrintCR. |
|
6865 |
aStream nextPutAll:'#("recursive")'. |
|
6866 |
^ self |
|
5755 | 6867 |
]. |
6868 |
||
6869 |
myClass := self class. |
|
6870 |
aStream nextPut:$(. |
|
6871 |
aStream nextPutAll:self class name. |
|
6872 |
||
6873 |
hasSemi := false. |
|
6874 |
myClass isVariable ifTrue:[ |
|
6654 | 6875 |
aStream nextPutAll:' basicNew:'. |
6876 |
self basicSize printOn:aStream |
|
5755 | 6877 |
] ifFalse:[ |
6654 | 6878 |
aStream nextPutAll:' basicNew' |
5755 | 6879 |
]. |
6880 |
||
6881 |
sz := myClass instSize. |
|
6882 |
1 to:sz do:[:i | |
|
6654 | 6883 |
aStream nextPutAll:' instVarAt:'. |
6884 |
i printOn:aStream. |
|
6885 |
aStream nextPutAll:' put:'. |
|
6886 |
(self instVarAt:i) storeOn:aStream. |
|
6887 |
aStream nextPut:$;. |
|
6888 |
hasSemi := true |
|
5755 | 6889 |
]. |
6890 |
myClass isVariable ifTrue:[ |
|
6654 | 6891 |
sz := self basicSize. |
6892 |
1 to:sz do:[:i | |
|
6893 |
aStream nextPutAll:' basicAt:'. |
|
6894 |
i printOn:aStream. |
|
6895 |
aStream nextPutAll:' put:'. |
|
6896 |
(self basicAt:i) storeOn:aStream. |
|
6897 |
aStream nextPut:$;. |
|
6898 |
hasSemi := true |
|
6899 |
] |
|
5755 | 6900 |
]. |
6901 |
hasSemi ifTrue:[ |
|
6654 | 6902 |
aStream nextPutAll:' yourself' |
5755 | 6903 |
]. |
6904 |
aStream nextPut:$). |
|
6905 |
||
6906 |
" |
|
6907 |
|s| |
|
6908 |
||
6909 |
s := WriteStream on:(String new). |
|
6910 |
('hello' -> 'world') storeOn:s. |
|
6911 |
s := ReadStream on:(s contents). |
|
6912 |
(Object readFrom:s) inspect |
|
6913 |
" |
|
6914 |
" |
|
6915 |
|s| |
|
6916 |
||
6917 |
s := 'data' asFilename writeStream. |
|
6918 |
('hello' -> 'world') storeOn:s. |
|
6919 |
s close. |
|
6920 |
||
6921 |
s := 'data' asFilename readStream. |
|
6922 |
(Object readFrom:s) inspect |
|
6923 |
" |
|
6924 |
||
6925 |
"does not work example:" |
|
6926 |
" |
|
6927 |
|s a| |
|
6928 |
||
6929 |
a := Array new:2. |
|
6930 |
a at:1 put:a. |
|
6931 |
||
6932 |
s := 'data' asFilename writeStream. |
|
6933 |
a storeOn:s. |
|
6934 |
s close. |
|
6935 |
||
6936 |
s := 'data' asFilename readStream. |
|
6937 |
(Object readFrom:s) inspect |
|
6938 |
" |
|
6939 |
||
6940 |
"Modified: 28.1.1997 / 00:36:12 / cg" |
|
6941 |
! |
|
6942 |
||
6943 |
storeString |
|
6944 |
"return a string representing an expression to reconstruct the receiver. |
|
6945 |
Notice, that no self referencing or cyclic objects can be represented |
|
6946 |
in this format. |
|
6947 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6948 |
||
6949 |
|s| |
|
6950 |
||
6951 |
s := WriteStream on:(String new:50). |
|
6952 |
self storeOn:s. |
|
6953 |
^ s contents |
|
6954 |
! ! |
|
6955 |
||
6956 |
!Object methodsFor:'private'! |
|
6957 |
||
6958 |
isHierarchicalItem |
|
6959 |
"used to decide if the parent is a hierarchical item |
|
6960 |
or the model |
|
6961 |
" |
|
6962 |
^ false |
|
6963 |
! ! |
|
6964 |
||
6965 |
!Object methodsFor:'queries'! |
|
6966 |
||
6967 |
basicSize |
|
6968 |
"return the number of the receivers indexed instance variables, |
|
6969 |
0 if it has none. |
|
6970 |
||
6971 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
6972 |
||
6973 |
%{ /* NOCONTEXT */ |
|
6974 |
||
6975 |
REGISTER int nbytes; |
|
6976 |
REGISTER OBJ myClass; |
|
6977 |
int nInstBytes; |
|
6978 |
||
6979 |
/* |
|
6980 |
* notice the missing test for self being a nonNilObject - |
|
6981 |
* this can be done since basicSize is defined both in UndefinedObject |
|
6982 |
* and SmallInteger |
|
6983 |
*/ |
|
6984 |
myClass = __qClass(self); |
|
6985 |
nbytes = __qSize(self); |
|
6986 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) ); |
|
6987 |
||
6988 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
6654 | 6989 |
case __MASKSMALLINT(POINTERARRAY): |
6990 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
6991 |
nbytes -= nInstBytes; |
|
6992 |
RETURN ( __MKSMALLINT(__BYTES2OBJS__(nbytes)) ); |
|
6993 |
||
6994 |
case __MASKSMALLINT(BYTEARRAY): |
|
6995 |
nbytes -= nInstBytes; |
|
6996 |
RETURN ( __MKSMALLINT(nbytes / sizeof(char)) ); |
|
6997 |
||
6998 |
case __MASKSMALLINT(FLOATARRAY): |
|
6999 |
nbytes -= nInstBytes; |
|
7000 |
RETURN ( __MKSMALLINT(nbytes / sizeof(float)) ); |
|
7001 |
||
7002 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 7003 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 7004 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
5755 | 7005 |
#endif |
6654 | 7006 |
nbytes -= nInstBytes; |
7007 |
RETURN ( __MKSMALLINT(nbytes / sizeof(double)) ); |
|
7008 |
||
7009 |
case __MASKSMALLINT(WORDARRAY): |
|
7010 |
case __MASKSMALLINT(SWORDARRAY): |
|
7011 |
nbytes -= nInstBytes; |
|
7012 |
RETURN ( __MKSMALLINT(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */ |
|
7013 |
||
7014 |
case __MASKSMALLINT(LONGARRAY): |
|
7015 |
case __MASKSMALLINT(SLONGARRAY): |
|
7016 |
nbytes -= nInstBytes; |
|
7017 |
RETURN ( __MKSMALLINT(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */ |
|
7018 |
||
7019 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
7020 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 7021 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 7022 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
5755 | 7023 |
#endif |
6654 | 7024 |
nbytes -= nInstBytes; |
7025 |
RETURN ( __MKSMALLINT(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */ |
|
5755 | 7026 |
} |
7027 |
%}. |
|
7028 |
^ 0 |
|
7029 |
! |
|
7030 |
||
7031 |
byteSize |
|
7032 |
"return the number of bytes in the receivers indexed instance variables, |
|
7033 |
0 if it has none. This only returns non-zero for non-pointer indexed |
|
7034 |
instvars i.e. byteArrays, wordArrays etc. |
|
7035 |
Notice: for Strings the returned size may look strange. |
|
7036 |
Only useful with binary storage." |
|
7037 |
||
7038 |
|myClass| |
|
7039 |
||
7040 |
myClass := self class. |
|
7041 |
myClass isVariable ifTrue:[ |
|
6654 | 7042 |
myClass isPointers ifFalse:[ |
7043 |
myClass isBytes ifTrue:[ |
|
7044 |
^ self basicSize. |
|
7045 |
]. |
|
7046 |
myClass isWords ifTrue:[ |
|
7047 |
^ self basicSize * 2. |
|
7048 |
]. |
|
7049 |
myClass isSignedWords ifTrue:[ |
|
7050 |
^ self basicSize * 2. |
|
7051 |
]. |
|
7052 |
myClass isLongs ifTrue:[ |
|
7053 |
^ self basicSize * 4. |
|
7054 |
]. |
|
7055 |
myClass isSignedLongs ifTrue:[ |
|
7056 |
^ self basicSize * 4. |
|
7057 |
]. |
|
7058 |
myClass isLongLongs ifTrue:[ |
|
7059 |
^ self basicSize * 8. |
|
7060 |
]. |
|
7061 |
myClass isSignedLongLongs ifTrue:[ |
|
7062 |
^ self basicSize * 8. |
|
7063 |
]. |
|
7064 |
myClass isFloats ifTrue:[ |
|
7065 |
^ self basicSize * (ExternalBytes sizeofFloat) |
|
7066 |
]. |
|
7067 |
myClass isDoubles ifTrue:[ |
|
7068 |
^ self basicSize * (ExternalBytes sizeofDouble) |
|
7069 |
]. |
|
7070 |
self halt:'oops'. |
|
7071 |
] |
|
5755 | 7072 |
]. |
7073 |
^ 0 |
|
7074 |
||
7075 |
" |
|
7076 |
Point new byteSize |
|
7077 |
'hello' byteSize |
|
7078 |
(ByteArray with:1 with:2) byteSize |
|
7079 |
(FloatArray with:1.5) byteSize |
|
7080 |
(DoubleArray with:1.5) byteSize |
|
7081 |
(WordArray with:1 with:2) byteSize |
|
7082 |
" |
|
7083 |
! |
|
7084 |
||
7085 |
class |
|
7086 |
"return the receivers class" |
|
7087 |
||
7088 |
%{ /* NOCONTEXT */ |
|
7089 |
||
7090 |
RETURN ( __Class(self) ); |
|
7091 |
%} |
|
7092 |
! |
|
7093 |
||
7094 |
respondsTo:aSelector |
|
7095 |
"return true, if the receiver implements a method with selector equal |
|
7096 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
7097 |
receivers class or one of its superclasses. |
|
7098 |
||
7099 |
Notice, that this does not imply, that such a message can be sent without |
|
7100 |
an error being raised. For example, an implementation could send |
|
7101 |
#shouldNotImplement or #subclassResponsibility." |
|
7102 |
||
7103 |
" |
|
7104 |
should we go via the cache, or search (by class) ? |
|
7105 |
The first is faster, most of the time; while the 2nd fills |
|
7106 |
the cache with useless data if this is sent in a loop over all objects. |
|
7107 |
For now, use the cache ... |
|
7108 |
" |
|
7109 |
%{ /* NOCONTEXT */ |
|
7110 |
||
7111 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
6654 | 7112 |
RETURN ( false ); |
5755 | 7113 |
} |
7114 |
RETURN ( true ); |
|
7115 |
%} |
|
7116 |
. |
|
7117 |
^ self class canUnderstand:aSelector |
|
7118 |
||
7119 |
||
7120 |
"'aString' respondsTo:#+" |
|
7121 |
"'aString' respondsTo:#," |
|
7122 |
"'aString' respondsTo:#collect:" |
|
7123 |
! |
|
7124 |
||
7125 |
respondsToArithmetic |
|
7126 |
"return true, if the receiver responds to arithmetic messages. |
|
7127 |
false is returned here - the method is redefined in ArithmeticValue." |
|
7128 |
||
7129 |
^ false |
|
7130 |
! |
|
7131 |
||
7132 |
size |
|
7133 |
"return the number of the receivers indexed instance variables; |
|
7134 |
this method may be redefined in subclasses" |
|
7135 |
||
7136 |
^ self basicSize |
|
7137 |
! |
|
7138 |
||
7139 |
species |
|
7140 |
"return a class which is similar to (or the same as) the receivers class. |
|
7141 |
This is used to create an appropriate object when creating derived |
|
7142 |
copies in the collection classes (sometimes redefined)." |
|
7143 |
||
7144 |
^ self class |
|
7145 |
! |
|
7146 |
||
7147 |
yourself |
|
7148 |
"return the receiver - used for cascades to return self at the end" |
|
7149 |
||
7150 |
^ self |
|
7151 |
! ! |
|
7152 |
||
7153 |
!Object methodsFor:'secure message sending'! |
|
7154 |
||
7155 |
askFor:aSelector |
|
7156 |
"try to send the receiver the message, aSelector. |
|
7157 |
If it does not understand it, return false. |
|
7158 |
Otherwise the real value returned. |
|
7159 |
Useful to send messages such as: #isColor to unknown |
|
7160 |
receivers." |
|
7161 |
||
7162 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
7163 |
||
7164 |
" |
|
7165 |
1 askFor:#isColor |
|
7166 |
Color red askFor:#isColor |
|
7167 |
||
7168 |
1 askFor:#isFoo |
|
7169 |
Color red askFor:#isFoo |
|
7170 |
" |
|
7171 |
! |
|
7172 |
||
7173 |
perform:aSelector ifNotUnderstood:exceptionBlock |
|
7174 |
"try to send message aSelector to the receiver. |
|
7175 |
If its understood, return the methods returned value, |
|
7176 |
otherwise return the value of the exceptionBlock" |
|
7177 |
||
7178 |
|val ok| |
|
7179 |
||
6146 | 7180 |
MessageNotUnderstood handle:[:ex | |
6654 | 7181 |
"/ reject, if the bad message is not the one |
7182 |
"/ we have sent originally |
|
7183 |
ex parameter selector == aSelector ifFalse:[ |
|
7184 |
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
|
7185 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7186 |
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
|
7187 |
ex reject |
6654 | 7188 |
] |
5755 | 7189 |
] do:[ |
6654 | 7190 |
val := self perform:aSelector. |
7191 |
ok := true. |
|
5755 | 7192 |
]. |
7193 |
ok isNil ifTrue:[ |
|
6654 | 7194 |
^ exceptionBlock value |
5755 | 7195 |
]. |
7196 |
^ val |
|
7197 |
||
7198 |
" |
|
7199 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
|
7200 |
1.2345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7201 |
12345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7202 |
" |
|
7203 |
! |
|
7204 |
||
7205 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
7206 |
"try to send message aSelector to the receiver. |
|
7207 |
If its understood, return the methods returned value, |
|
7208 |
otherwise return the value of the exceptionBlock" |
|
7209 |
||
7210 |
|val ok| |
|
7211 |
||
7212 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6654 | 7213 |
"/ reject, if the bad message is not the one |
7214 |
"/ we have sent originally |
|
7215 |
ex parameter selector == aSelector ifFalse:[ |
|
7216 |
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
|
7217 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7218 |
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
|
7219 |
ex reject |
6654 | 7220 |
] |
5755 | 7221 |
] do:[ |
6654 | 7222 |
val := self perform:aSelector with:argument. |
7223 |
ok := true. |
|
5755 | 7224 |
]. |
7225 |
ok isNil ifTrue:[ |
|
6654 | 7226 |
^ exceptionBlock value |
5755 | 7227 |
]. |
7228 |
^ val |
|
7229 |
||
7230 |
" |
|
7231 |
|unknown| |
|
7232 |
||
7233 |
unknown := 1. |
|
7234 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7235 |
unknown := 'high there'. |
|
7236 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7237 |
" |
|
7238 |
! |
|
7239 |
||
5926 | 7240 |
perform:aSelector with:arg1 with:arg2 ifNotUnderstood:exceptionBlock |
7241 |
"try to send message aSelector to the receiver. |
|
7242 |
If its understood, return the methods returned value, |
|
7243 |
otherwise return the value of the exceptionBlock" |
|
7244 |
||
7245 |
|val ok| |
|
7246 |
||
7247 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6654 | 7248 |
"/ reject, if the bad message is not the one |
7249 |
"/ we have sent originally |
|
7250 |
ex parameter selector == aSelector ifFalse:[ |
|
7251 |
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
|
7252 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7253 |
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
|
7254 |
ex reject |
6654 | 7255 |
] |
5926 | 7256 |
] do:[ |
6654 | 7257 |
val := self perform:aSelector with:arg1 with:arg2. |
7258 |
ok := true. |
|
5926 | 7259 |
]. |
7260 |
ok isNil ifTrue:[ |
|
6654 | 7261 |
^ exceptionBlock value |
5926 | 7262 |
]. |
7263 |
^ val |
|
7264 |
||
7265 |
" |
|
7266 |
|unknown| |
|
7267 |
||
7268 |
unknown := 1. |
|
7269 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7270 |
unknown := 'high there'. |
|
7271 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7272 |
" |
|
7273 |
! |
|
7274 |
||
5755 | 7275 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
7276 |
"try to send message aSelector to the receiver. |
|
7277 |
If its understood, return the methods returned value, |
|
7278 |
otherwise return the value of the exceptionBlock" |
|
7279 |
||
7280 |
|val ok| |
|
7281 |
||
7282 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6654 | 7283 |
"/ reject, if the bad message is not the one |
7284 |
"/ we have sent originally |
|
7285 |
ex parameter selector == aSelector ifFalse:[ |
|
7286 |
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
|
7287 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7288 |
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
|
7289 |
ex reject |
6654 | 7290 |
] |
5755 | 7291 |
] do:[ |
6654 | 7292 |
val := self perform:aSelector withArguments:argumentArray. |
7293 |
ok := true. |
|
5755 | 7294 |
]. |
7295 |
ok isNil ifTrue:[ |
|
6654 | 7296 |
^ exceptionBlock value |
5755 | 7297 |
]. |
7298 |
^ val |
|
7299 |
||
7300 |
" |
|
7301 |
|unknown| |
|
7302 |
||
7303 |
unknown := 1. |
|
7304 |
(unknown perform:#+ withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
|
7305 |
unknown := 'high there'. |
|
7306 |
(unknown perform:#+ withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
|
7307 |
" |
|
7308 |
||
7309 |
"Modified: 27.3.1997 / 14:13:16 / cg" |
|
7310 |
! ! |
|
7311 |
||
7312 |
!Object methodsFor:'signal constants'! |
|
7313 |
||
7314 |
messageNotUnderstoodSignal |
|
6146 | 7315 |
^ MessageNotUnderstood |
5755 | 7316 |
|
7317 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
7318 |
! ! |
|
7319 |
||
7320 |
!Object methodsFor:'special queries'! |
|
7321 |
||
7322 |
allOwners |
|
7323 |
"return a collection of all objects referencing the receiver" |
|
7324 |
||
7325 |
^ ObjectMemory whoReferences:self |
|
7326 |
! |
|
7327 |
||
7328 |
references:anObject |
|
7329 |
"return true, if the receiver refers to the argument, anObject. |
|
7330 |
- for debugging only" |
|
7331 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7332 |
^ self referencesObject:anObject |
5755 | 7333 |
|
7334 |
" |
|
7335 |
|v| |
|
7336 |
||
7337 |
v := View new initialize. |
|
7338 |
v references:Display. |
|
7339 |
" |
|
7340 |
! |
|
7341 |
||
7342 |
referencesAny:aCollection |
|
7343 |
"return true, if the receiver refers to any object from |
|
7344 |
the argument, aCollection. |
|
7345 |
- for debugging only" |
|
7346 |
||
7347 |
%{ |
|
7348 |
OBJ cls, flags; |
|
7349 |
int nInsts, inst; |
|
7350 |
||
7351 |
if (! __isNonNilObject(self)) { |
|
6654 | 7352 |
RETURN (false); |
5755 | 7353 |
} |
7354 |
||
7355 |
if (__isArray(aCollection)) { |
|
6654 | 7356 |
int nObjs = __arraySize(aCollection); |
7357 |
char *minAddr = 0, *maxAddr = 0; |
|
7358 |
||
7359 |
if (nObjs == 0) { |
|
7360 |
RETURN (false); |
|
7361 |
} |
|
7362 |
||
7363 |
/* |
|
7364 |
* a little optimization: use the fact that all old objects |
|
7365 |
* refering to a new object are on the remSet; if I am not, |
|
7366 |
* a trivial reject is possible, if all objects are newbees. |
|
7367 |
* as a side effect, gather min/max addresses |
|
7368 |
*/ |
|
7369 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
7370 |
int allNewBees = 1; |
|
7371 |
int i; |
|
7372 |
||
7373 |
minAddr = (char *)(__ArrayInstPtr(aCollection)->a_element[0]); |
|
7374 |
maxAddr = minAddr; |
|
7375 |
||
7376 |
for (i=0; i<nObjs; i++) { |
|
7377 |
OBJ anObject; |
|
7378 |
||
7379 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7380 |
||
7381 |
if (__isNonNilObject(anObject)) { |
|
7382 |
int spc; |
|
7383 |
||
7384 |
if (((spc = __qSpace(anObject)) != NEWSPACE) && (spc != SURVSPACE)) { |
|
7385 |
allNewBees = 0; |
|
7386 |
} |
|
7387 |
} |
|
7388 |
||
7389 |
if ((char *)anObject < minAddr) { |
|
7390 |
minAddr = (char *)anObject; |
|
7391 |
} else if ((char *)anObject > maxAddr) { |
|
7392 |
maxAddr = (char *)anObject; |
|
7393 |
} |
|
7394 |
} |
|
7395 |
if (allNewBees) { |
|
7396 |
RETURN (false); |
|
7397 |
} |
|
7398 |
} |
|
7399 |
||
7400 |
/* |
|
7401 |
* fetch min/max in searchList (if not already done) |
|
7402 |
*/ |
|
7403 |
if (minAddr == 0) { |
|
7404 |
int i; |
|
7405 |
||
7406 |
for (i=0; i<nObjs; i++) { |
|
7407 |
OBJ anObject; |
|
7408 |
||
7409 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7410 |
if ((char *)anObject < minAddr) { |
|
7411 |
minAddr = (char *)anObject; |
|
7412 |
} else if ((char *)anObject > maxAddr) { |
|
7413 |
maxAddr = (char *)anObject; |
|
7414 |
} |
|
7415 |
} |
|
7416 |
} |
|
7417 |
||
7418 |
cls = __qClass(self); |
|
7419 |
if (((char *)cls >= minAddr) && ((char *)cls <= maxAddr)) { |
|
5755 | 7420 |
#if defined(memsrch4) |
6654 | 7421 |
if (memsrch4(__arrayVal(aCollection), (INT)cls, nObjs)) { |
7422 |
RETURN (true); |
|
7423 |
} |
|
5755 | 7424 |
#else |
6654 | 7425 |
int i; |
7426 |
||
7427 |
for (i=0; i<nObjs; i++) { |
|
7428 |
OBJ anObject; |
|
7429 |
||
7430 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7431 |
if (cls == anObject) { |
|
7432 |
RETURN (true); |
|
7433 |
} |
|
7434 |
} |
|
5755 | 7435 |
#endif /* memsrch4 */ |
6654 | 7436 |
} |
7437 |
||
7438 |
flags = __ClassInstPtr(cls)->c_flags; |
|
7439 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
7440 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
7441 |
} else { |
|
7442 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
7443 |
} |
|
7444 |
if (! nInsts) { |
|
7445 |
RETURN (false); |
|
7446 |
} |
|
7447 |
||
7448 |
if (nObjs == 1) { |
|
7449 |
/* better reverse the loop */ |
|
7450 |
OBJ anObject; |
|
7451 |
||
7452 |
anObject = __ArrayInstPtr(aCollection)->a_element[0]; |
|
5755 | 7453 |
#if defined(memsrch4) |
6654 | 7454 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
7455 |
RETURN (true); |
|
7456 |
} |
|
5755 | 7457 |
#else |
6654 | 7458 |
for (inst=0; inst<nInsts; inst++) { |
7459 |
if ((__InstPtr(self)->i_instvars[inst]) == anObject) { |
|
7460 |
RETURN (true); |
|
7461 |
} |
|
7462 |
} |
|
5755 | 7463 |
#endif |
6654 | 7464 |
RETURN (false); |
7465 |
} |
|
7466 |
||
7467 |
for (inst=0; inst<nInsts; inst++) { |
|
7468 |
OBJ instVar = __InstPtr(self)->i_instvars[inst]; |
|
7469 |
int i; |
|
7470 |
||
7471 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
5755 | 7472 |
#if defined(memsrch4) |
6654 | 7473 |
if (memsrch4(__arrayVal(aCollection), (INT)instVar, nObjs)) { |
7474 |
RETURN (true); |
|
7475 |
} |
|
5755 | 7476 |
#else |
6654 | 7477 |
for (i=0; i<nObjs; i++) { |
7478 |
OBJ anObject; |
|
7479 |
||
7480 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7481 |
if (instVar == anObject) { |
|
7482 |
RETURN (true); |
|
7483 |
} |
|
7484 |
} |
|
5755 | 7485 |
#endif /* memsrch4 */ |
6654 | 7486 |
} |
7487 |
} |
|
7488 |
RETURN (false); |
|
5755 | 7489 |
} |
7490 |
%}. |
|
7491 |
||
7492 |
aCollection do:[:el | |
|
6654 | 7493 |
(self references:el) ifTrue:[^ true]. |
5755 | 7494 |
]. |
7495 |
^ false |
|
7496 |
! |
|
7497 |
||
7498 |
referencesDerivedInstanceOf:aClass |
|
7499 |
"return true, if the receiver refers to an instance of |
|
7500 |
the argument, aClass or its subclass. This method exists |
|
7501 |
to support searching for users of a class." |
|
7502 |
||
7503 |
|myClass |
|
7504 |
numInst "{ Class: SmallInteger }" | |
|
7505 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7506 |
"check the class" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7507 |
(self isKindOf:aClass) ifTrue:[^ true]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7508 |
|
5755 | 7509 |
myClass := self class. |
7510 |
"check the instance variables" |
|
7511 |
numInst := myClass instSize. |
|
7512 |
1 to:numInst do:[:i | |
|
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7513 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
5755 | 7514 |
]. |
7515 |
||
7516 |
"check the indexed variables" |
|
7517 |
myClass isVariable ifTrue:[ |
|
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7518 |
myClass isPointers ifFalse:[ |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7519 |
"no need to search in non pointer fields" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7520 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7521 |
]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7522 |
numInst := self basicSize. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7523 |
1 to:numInst do:[:i | |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7524 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7525 |
] |
5755 | 7526 |
]. |
7527 |
^ false |
|
7528 |
||
7529 |
" |
|
7530 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
|
7531 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
7532 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
7533 |
" |
|
7534 |
! |
|
7535 |
||
7536 |
referencesInstanceOf:aClass |
|
7537 |
"return true, if the receiver refers to an instance of |
|
7538 |
the argument, aClass.This method exists |
|
7539 |
to support searching for users of a class." |
|
7540 |
||
7541 |
|myClass |
|
7542 |
numInst "{ Class: SmallInteger }" | |
|
7543 |
||
7544 |
myClass := self class. |
|
7545 |
||
7546 |
"check the class" |
|
7547 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
7548 |
||
7549 |
"check the instance variables" |
|
7550 |
numInst := myClass instSize. |
|
7551 |
1 to:numInst do:[:i | |
|
6654 | 7552 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
5755 | 7553 |
]. |
7554 |
||
7555 |
"check the indexed variables" |
|
7556 |
myClass isVariable ifTrue:[ |
|
6654 | 7557 |
myClass isPointers ifFalse:[ |
7558 |
"no need to search in non-pointer indexed fields" |
|
7559 |
myClass isLongs ifTrue:[ |
|
7560 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
7561 |
] ifFalse:[ |
|
7562 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
7563 |
^ aClass == SmallInteger |
|
7564 |
] |
|
7565 |
]. |
|
7566 |
numInst := self basicSize. |
|
7567 |
1 to:numInst do:[:i | |
|
7568 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
7569 |
] |
|
5755 | 7570 |
]. |
7571 |
^ false |
|
7572 |
||
7573 |
" |
|
7574 |
(1 @ 3.4) referencesInstanceOf:Float |
|
7575 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
7576 |
View new initialize referencesInstanceOf:(Display class) |
|
7577 |
" |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7578 |
! |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7579 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7580 |
referencesObject:anObject |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7581 |
"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
|
7582 |
- for debugging only" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7583 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7584 |
%{ /* NOCONTEXT */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7585 |
OBJ cls, flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7586 |
int nInsts, i; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7587 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7588 |
if (! __isNonNilObject(self)) { |
6654 | 7589 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7590 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7591 |
|
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 |
* 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
|
7594 |
* 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
|
7595 |
* 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
|
7596 |
*/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7597 |
if (__isNonNilObject(anObject)) { |
6654 | 7598 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7599 |
int spc; |
|
7600 |
||
7601 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7602 |
RETURN (false); |
|
7603 |
} |
|
7604 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7605 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7606 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7607 |
cls = __qClass(self); |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7608 |
if (cls == anObject) { |
6654 | 7609 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7610 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7611 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7612 |
flags = __ClassInstPtr(cls)->c_flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7613 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
6654 | 7614 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7615 |
} else { |
6654 | 7616 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7617 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7618 |
if (! nInsts) { |
6654 | 7619 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7620 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7621 |
#if defined(memsrch4) |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7622 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
6654 | 7623 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7624 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7625 |
#else |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7626 |
for (i=0; i<nInsts; i++) { |
6654 | 7627 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7628 |
RETURN (true); |
|
7629 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7630 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7631 |
#endif /* memsrch4 */ |
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 |
%}. |
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 |
"/ |myClass |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7636 |
"/ numInst "{ Class: SmallInteger }" | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7637 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7638 |
"/ myClass := self class. |
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 |
"/ "check the class" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7641 |
"/ (myClass == anObject) ifTrue:[^ true]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7642 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7643 |
"/ "check the instance variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7644 |
"/ numInst := myClass instSize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7645 |
"/ 1 to:numInst do:[:i | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7646 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7647 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7648 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7649 |
"/ "check the indexed variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7650 |
"/ myClass isVariable ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7651 |
"/ myClass isPointers ifFalse:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7652 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7653 |
"/ "/ 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
|
7654 |
"/ "/ 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
|
7655 |
"/ "/ 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
|
7656 |
"/ "/ 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
|
7657 |
"/ "/ 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
|
7658 |
"/ "/ 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
|
7659 |
"/ "/ 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
|
7660 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7661 |
"/ ^ false. |
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 |
"/ "/ alternative: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7664 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7665 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7666 |
"/ |
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 |
"/ "/ 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
|
7669 |
"/ "/ idenitytIndex method, use it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7670 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7671 |
"/ myClass == Array ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7672 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7673 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7674 |
"/ |
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 |
"/ "/ otherwise, do it the slow way |
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 |
"/ numInst := self basicSize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7679 |
"/ 1 to:numInst do:[:i | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7680 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7681 |
"/ ] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7682 |
"/ ]. |
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 |
^ false |
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 |
" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7687 |
|v| |
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 := View new initialize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7690 |
v references:Display. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7691 |
" |
5755 | 7692 |
! ! |
7693 |
||
7694 |
!Object methodsFor:'synchronized evaluation'! |
|
7695 |
||
7696 |
freeSynchronizationSemaphore |
|
7697 |
"free synchronizationSemaphore. May be used, to save memory when |
|
7698 |
an object is no longer used synchronized." |
|
7699 |
||
7700 |
|sema| |
|
7701 |
||
7702 |
sema := self synchronizationSemaphore. |
|
7703 |
sema notNil ifTrue:[ |
|
6654 | 7704 |
sema wait. "/ get lock |
7705 |
self synchronizationSemaphore:nil. |
|
5755 | 7706 |
]. |
7707 |
||
7708 |
" |
|
7709 |
self synchronized:[]. |
|
7710 |
self synchronizationSemaphore. |
|
7711 |
self freeSynchronizationSemaphore. |
|
7712 |
" |
|
7713 |
||
7714 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
7715 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
7716 |
! |
|
7717 |
||
7718 |
synchronizationSemaphore |
|
7719 |
"return the synchronization semaphore for myself. |
|
7720 |
subclasses may redefine" |
|
7721 |
||
7722 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
7723 |
||
7724 |
" |
|
7725 |
self synchronizationSemaphore |
|
7726 |
" |
|
7727 |
||
7728 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
7729 |
! |
|
7730 |
||
7731 |
synchronizationSemaphore:aSemaphore |
|
7732 |
"set the synchronisationSemaphore for myself. |
|
7733 |
subclasses may redefine this method" |
|
7734 |
||
7735 |
aSemaphore isNil ifTrue:[ |
|
6654 | 7736 |
"/ remove Semaphore |
7737 |
SynchronizationSemaphores removeKey:self ifAbsent:nil. |
|
5755 | 7738 |
] ifFalse:[ |
6654 | 7739 |
SynchronizationSemaphores at:self put:aSemaphore. |
5755 | 7740 |
]. |
7741 |
||
7742 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
7743 |
! |
|
7744 |
||
7745 |
synchronized:aBlock |
|
7746 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
7747 |
||
6600 | 7748 |
|sema wasBlocked| |
7749 |
||
7750 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5755 | 7751 |
|
7752 |
sema := self synchronizationSemaphore. |
|
7753 |
sema isNil ifTrue:[ |
|
7211
87f5d25b5c3d
Make synchronizationSemaphore a recursionLock
Stefan Vogel <sv@exept.de>
parents:
7208
diff
changeset
|
7754 |
sema := RecursionLock new name:'SynchronizationSemaphore'. |
6600 | 7755 |
self synchronizationSemaphore:sema. |
5755 | 7756 |
]. |
7757 |
||
6600 | 7758 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
7211
87f5d25b5c3d
Make synchronizationSemaphore a recursionLock
Stefan Vogel <sv@exept.de>
parents:
7208
diff
changeset
|
7759 |
sema critical:aBlock. |
5755 | 7760 |
|
7761 |
" |
|
7762 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
7763 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
7764 |
" |
|
7765 |
||
7766 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
7767 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
|
7768 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
|
7769 |
! ! |
|
7770 |
||
7771 |
!Object methodsFor:'system primitives'! |
|
7772 |
||
7773 |
asOop |
|
7774 |
"ST-80 compatibility: |
|
7775 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
7776 |
or index); since ST/X has no such thing, and the objects address cannot |
|
7777 |
be used (since its changing over time), we return the objects identityHash |
|
7778 |
key, which provides (at least) some identity indication. |
|
7779 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
7780 |
key of two non-identical objects may be the same. |
|
7781 |
You'd better not use it - especially do not misuse it." |
|
7782 |
||
7783 |
^ self identityHash |
|
7784 |
||
7785 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
7786 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
7787 |
! |
|
7788 |
||
7789 |
become:anotherObject |
|
7790 |
"make all references to the receiver become references to anotherObject |
|
7791 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
|
7792 |
This can be a very dangerous operation - be warned. |
|
7793 |
In general, using #become: should be avoided if possible, since it may |
|
7794 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
7795 |
||
7796 |
This may also be an expensive (i.e. slow) operation, |
|
7797 |
since in the worst case, the whole memory has to be searched for |
|
7798 |
references to the two objects (although the primitive tries hard to |
|
7799 |
limit the search, for acceptable performance in most cases). |
|
7800 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7801 |
or nil, or is a context of a living method (i.e. one that has not already |
|
7802 |
returned). |
|
7803 |
(notice that #become: is not used heavily by the system |
|
7804 |
- the Collection-classes have been rewritten to not use it.)" |
|
7805 |
%{ |
|
7806 |
if (__primBecome(self, anotherObject)) { |
|
6654 | 7807 |
RETURN ( self ); |
5755 | 7808 |
} |
7809 |
%}. |
|
7810 |
self primitiveFailed |
|
7811 |
! |
|
7812 |
||
7813 |
becomeNil |
|
7814 |
"make all references to the receiver become nil - effectively getting |
|
7815 |
rid of the receiver. |
|
7816 |
This can be a very dangerous operation - be warned. |
|
7817 |
||
7818 |
This may be an expensive (i.e. slow) operation. |
|
7819 |
The receiver may not be a SmallInteger or a context of a living method." |
|
7820 |
||
7821 |
%{ |
|
7822 |
if (__primBecomeNil(self)) { |
|
6654 | 7823 |
RETURN ( nil ); |
5755 | 7824 |
} |
7825 |
%}. |
|
7826 |
self primitiveFailed |
|
7827 |
! |
|
7828 |
||
7829 |
becomeSameAs:anotherObject |
|
7830 |
"make all references to the receiver become references to anotherObject |
|
7831 |
but NOT vice versa (as done in #become:). |
|
7832 |
This can be a very dangerous operation - be warned. |
|
7833 |
In general, using #become: should be avoided if possible, since it may |
|
7834 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
7835 |
||
7836 |
This may also be an expensive (i.e. slow) operation, |
|
7837 |
since in the worst case, the whole memory has to be searched for |
|
7838 |
references to the two objects (although the primitive tries hard to |
|
7839 |
limit the search, for acceptable performance in most cases). |
|
7840 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7841 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
7842 |
%{ |
|
7843 |
if (__primBecomeSameAs(self, anotherObject)) { |
|
6654 | 7844 |
RETURN ( self ); |
5755 | 7845 |
} |
7846 |
%}. |
|
7847 |
self primitiveFailed |
|
7848 |
! |
|
7849 |
||
7850 |
changeClassTo:otherClass |
|
7851 |
"changes the class of the receiver to the argument, otherClass. |
|
7852 |
This is only allowed (possible), if the receivers class and the argument |
|
7853 |
have the same structure (i.e. number of named instance variables and |
|
7854 |
type of indexed instance variables). |
|
7855 |
If the structures do not match, or any of the original class or new class |
|
7856 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
7857 |
||
7858 |
|myClass ok| |
|
7859 |
||
7860 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
|
7202
85178c4cefe0
ensure that other class is autoloaded in changeClassTo:
penk
parents:
7177
diff
changeset
|
7861 |
otherClass autoload. |
5755 | 7862 |
%{ |
7863 |
{ |
|
6533 | 7864 |
OBJ other = otherClass; |
7865 |
||
7866 |
if (__isNonNilObject(self) |
|
7867 |
&& __isNonNilObject(other) |
|
7868 |
&& (other != UndefinedObject) |
|
7869 |
&& (other != SmallInteger)) { |
|
7870 |
ok = true; |
|
7871 |
} else { |
|
7872 |
ok = false; |
|
7873 |
} |
|
5755 | 7874 |
} |
7875 |
%}. |
|
7876 |
ok ifTrue:[ |
|
6533 | 7877 |
ok := false. |
7878 |
myClass := self class. |
|
7879 |
myClass flags == otherClass flags ifTrue:[ |
|
7880 |
myClass instSize == otherClass instSize ifTrue:[ |
|
7881 |
"same instance layout and types: its ok to do it" |
|
7882 |
ok := true. |
|
7883 |
] ifFalse:[ |
|
7884 |
myClass isPointers ifTrue:[ |
|
7885 |
myClass isVariable ifTrue:[ |
|
7886 |
ok := true |
|
7887 |
] |
|
7888 |
] |
|
7889 |
] |
|
7890 |
] ifFalse:[ |
|
7891 |
myClass isPointers ifTrue:[ |
|
7892 |
"if newClass is a variable class, with instSize <= my instsize, |
|
7893 |
we can do it (effectively mapping additional instvars into the |
|
7894 |
variable part) - usefulness is questionable, though" |
|
7895 |
||
7896 |
otherClass isPointers ifTrue:[ |
|
7897 |
otherClass isVariable ifTrue:[ |
|
7898 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
7899 |
ifTrue:[ |
|
7900 |
ok := true |
|
7901 |
] |
|
7902 |
] ifFalse:[ |
|
7903 |
otherClass instSize == (myClass instSize + self basicSize) |
|
7904 |
ifTrue:[ |
|
7905 |
ok := true |
|
7906 |
] |
|
7907 |
] |
|
7908 |
] ifFalse:[ |
|
7909 |
"it does not make sense to convert pointers to bytes ..." |
|
7910 |
] |
|
7911 |
] ifFalse:[ |
|
7912 |
"does it make sense, to convert bits ?" |
|
7913 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
7914 |
(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[ |
|
7915 |
ok := true |
|
7916 |
] |
|
7917 |
] |
|
7918 |
] |
|
5755 | 7919 |
]. |
7920 |
ok ifTrue:[ |
|
6533 | 7921 |
"now, change the receivers class ..." |
5755 | 7922 |
%{ |
6533 | 7923 |
{ |
7924 |
OBJ me = self; |
|
7925 |
||
7926 |
__qClass(me) = otherClass; |
|
7927 |
__STORE(me, otherClass); |
|
7928 |
RETURN (me); |
|
7929 |
} |
|
5755 | 7930 |
%}. |
7931 |
]. |
|
6533 | 7932 |
otherClass isLoaded ifFalse:[ |
7933 |
^ self changeClassTo:(otherClass autoload). |
|
7934 |
]. |
|
5755 | 7935 |
" |
7936 |
the receiver cannot be represented as a instance of |
|
7937 |
the desired class. |
|
7938 |
For example, you cannot change a bitInstance (byteArray etc.) |
|
7939 |
into a pointer object and vice versa. |
|
7940 |
" |
|
7941 |
self primitiveFailed |
|
7942 |
! |
|
7943 |
||
7944 |
changeClassToThatOf:anObject |
|
7945 |
"changes the class of the receiver to that of the argument, anObject. |
|
7946 |
This is only allowed (possible), if the receivers class and the arguments |
|
7947 |
class have the same structure (i.e. number of named instance variables and |
|
7948 |
type of indexed instance variables). If the structures do not match, or any |
|
7949 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
7950 |
||
7951 |
self changeClassTo:(anObject class) |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7952 |
! |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7953 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7954 |
replaceReferencesTo:anObject with:newRef |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7955 |
"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
|
7956 |
Return true, if any reference was changed. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7957 |
Notice: this does not change the class-reference." |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7958 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7959 |
%{ /* NOCONTEXT */ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7960 |
OBJ cls, flags, anyChange; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7961 |
int nInsts, i; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7962 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7963 |
if (! __isNonNilObject(self)) { |
6654 | 7964 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7965 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7966 |
|
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 |
* a little optimization: use the fact that all old objects |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7969 |
* 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
|
7970 |
* a trivial reject is possible, if anObject is a newbee |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7971 |
*/ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7972 |
if (__isNonNilObject(anObject)) { |
6654 | 7973 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7974 |
int spc; |
|
7975 |
||
7976 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7977 |
RETURN (false); |
|
7978 |
} |
|
7979 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7980 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7981 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7982 |
cls = __qClass(self); |
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 |
flags = __ClassInstPtr(cls)->c_flags; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7985 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
6654 | 7986 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7987 |
} else { |
6654 | 7988 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7989 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7990 |
if (! nInsts) { |
6654 | 7991 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7992 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7993 |
anyChange = false; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7994 |
for (i=0; i<nInsts; i++) { |
6654 | 7995 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7996 |
__InstPtr(self)->i_instvars[i] = newRef; |
|
7997 |
__STORE(self, newRef); |
|
7998 |
anyChange = true; |
|
7999 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8000 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8001 |
RETURN (anyChange); |
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 |
|
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 |
|v| |
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 := Array with:1234 with:'hello' with:Array. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8008 |
v replaceReferencesTo:Array with:ByteArray. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8009 |
v inspect |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8010 |
" |
5755 | 8011 |
! ! |
8012 |
||
8013 |
!Object methodsFor:'testing'! |
|
8014 |
||
8015 |
? defaultValue |
|
8016 |
"a syntactic shugar-piece: |
|
8017 |
if the receiver is nil, return the defaultValue; |
|
8018 |
otherwise, return the receiver. |
|
8019 |
This method is only redefined in UndefinedObject - therefore, |
|
8020 |
the recevier is retuned here. |
|
8021 |
||
8022 |
Thus, if foo and bar are simple variables or constants, |
|
6654 | 8023 |
foo ? bar |
5755 | 8024 |
is the same as: |
6654 | 8025 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
5755 | 8026 |
|
8027 |
if they are message sends, the equivalent code is: |
|
6654 | 8028 |
[ |
8029 |
|t1 t2| |
|
8030 |
||
8031 |
t1 := foo. |
|
8032 |
t2 := bar. |
|
8033 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
8034 |
] value |
|
5755 | 8035 |
|
8036 |
Can be used to provide defaultValues to variables, |
|
8037 |
as in: |
|
6654 | 8038 |
foo := arg ? #defaultValue |
5755 | 8039 |
|
8040 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8041 |
Notice: |
|
6654 | 8042 |
This method is open coded (inlined) by the compiler(s) |
8043 |
- redefining it may not work as expected." |
|
5755 | 8044 |
|
8045 |
^ self |
|
8046 |
||
8047 |
" |
|
8048 |
1 ? #default |
|
8049 |
nil ? #default |
|
8050 |
" |
|
8051 |
||
8052 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8053 |
"Modified: / 19.5.1998 / 17:39:56 / cg" |
|
8054 |
! |
|
8055 |
||
8056 |
?? defaultValue |
|
8057 |
"a syntactic shugar-piece: |
|
8058 |
much like ?, but sends #value to the argument if required. |
|
8059 |
(i.e. its the same as #ifNil:) |
|
8060 |
If the receiver is nil, return the defaultValues value; |
|
8061 |
otherwise, return the receiver. |
|
8062 |
This method is only redefined in UndefinedObject - therefore, |
|
8063 |
the recevier is retuned here. |
|
8064 |
||
8065 |
Thus, if foo and bar are simple variables or constants, |
|
6654 | 8066 |
foo ?? bar |
5755 | 8067 |
is the same as: |
6654 | 8068 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
5755 | 8069 |
|
8070 |
if they are message sends, the equivalent code is: |
|
6654 | 8071 |
[ |
8072 |
|t t2| |
|
8073 |
||
8074 |
t := foo. |
|
8075 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
8076 |
] value |
|
5755 | 8077 |
|
8078 |
Can be used to provide defaultValues to variables, |
|
8079 |
as in: |
|
6654 | 8080 |
foo := arg ?? [ self computeDefault ] |
5755 | 8081 |
|
8082 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8083 |
" |
|
8084 |
||
8085 |
^ self |
|
8086 |
||
8087 |
" |
|
8088 |
1 ?? #default |
|
8089 |
nil ?? #default |
|
8090 |
1 ?? [ self halt. 1 + 2 ] |
|
8091 |
nil ?? [ self halt. 1 + 2 ] |
|
6069 | 8092 |
1 ?? [Date today] |
8093 |
nil ?? [Date today] |
|
5755 | 8094 |
" |
8095 |
||
8096 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8097 |
"Modified: / 19.5.1998 / 17:42:56 / cg" |
|
8098 |
! |
|
8099 |
||
8100 |
ifNil:aBlockOrValue |
|
8101 |
"return myself, or the result from evaluating the argument, if I am nil. |
|
8102 |
This is much like #?, but sends #value to the argument in case of a nil |
|
8103 |
receiver. |
|
8104 |
Notice: |
|
6654 | 8105 |
This method is open coded (inlined) by the compiler(s) |
8106 |
- redefining it may not work as expected." |
|
5755 | 8107 |
|
8108 |
^ self |
|
8109 |
! |
|
8110 |
||
8111 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
|
8112 |
"return the value of the first arg, if I am nil, |
|
8113 |
the result from evaluating the 2nd argument, if I am not nil. |
|
8114 |
Notice: |
|
6654 | 8115 |
This method is open coded (inlined) by the compiler(s) |
8116 |
- redefining it may not work as expected." |
|
5755 | 8117 |
|
8118 |
^ notNilBlockOrValue value |
|
8119 |
||
8120 |
! |
|
8121 |
||
8122 |
ifNotNil:aBlockOrValue |
|
8123 |
"return myself if nil, or the result from evaluating the argument, |
|
8124 |
if I am not nil. |
|
8125 |
Notice: |
|
6654 | 8126 |
This method is open coded (inlined) by the compiler(s) |
8127 |
- redefining it may not work as expected." |
|
5755 | 8128 |
|
8129 |
^ aBlockOrValue value |
|
8130 |
||
8131 |
! |
|
8132 |
||
8133 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
|
8134 |
"return the value of the 2nd arg, if I am nil, |
|
8135 |
the result from evaluating the 1st argument, if I am not nil. |
|
8136 |
Notice: |
|
6654 | 8137 |
This method is open coded (inlined) by the compiler(s) |
8138 |
- redefining it may not work as expected." |
|
5755 | 8139 |
|
8140 |
^ notNilBlockOrValue value |
|
8141 |
||
8142 |
||
8143 |
! |
|
8144 |
||
8145 |
isArray |
|
8146 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
8147 |
false is returned here - the method is only redefined in Array." |
|
8148 |
||
8149 |
^ false |
|
8150 |
! |
|
8151 |
||
8152 |
isAssociation |
|
8153 |
"return true, if the receiver is some kind of association; |
|
8154 |
false is returned here - the method is only redefined in Association." |
|
8155 |
||
8156 |
^ false |
|
8157 |
||
8158 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
8159 |
! |
|
8160 |
||
8161 |
isBehavior |
|
8162 |
"return true, if the receiver is some kind of class (i.e. behavior); |
|
8163 |
false is returned here - the method is only redefined in Behavior." |
|
8164 |
||
8165 |
^ false |
|
8166 |
! |
|
8167 |
||
8168 |
isBlock |
|
8169 |
"return true, if the receiver is some kind of block; |
|
8170 |
false returned here - the method is only redefined in Block." |
|
8171 |
||
8172 |
^ false |
|
8173 |
! |
|
8174 |
||
5824 | 8175 |
isBoolean |
8176 |
"return true, if the receiver is a boolean; |
|
8177 |
false is returned here - the method is only redefined in Boolean." |
|
8178 |
||
8179 |
^ false |
|
8180 |
! |
|
8181 |
||
5755 | 8182 |
isByteArray |
8183 |
"return true, if the receiver is some kind of bytearray; |
|
8184 |
false is returned here - the method is only redefined in ByteArray." |
|
8185 |
||
8186 |
^ false |
|
8187 |
! |
|
8188 |
||
8189 |
isCharacter |
|
8190 |
"return true, if the receiver is some kind of character; |
|
8191 |
false is returned here - the method is only redefined in Character." |
|
8192 |
||
8193 |
^ false |
|
8194 |
! |
|
8195 |
||
8196 |
isClass |
|
8197 |
"return true, if the receiver is some kind of class (real class, |
|
8198 |
not just behavior); |
|
8199 |
false is returned here - the method is only redefined in Class." |
|
8200 |
||
8201 |
^ false |
|
8202 |
! |
|
8203 |
||
8204 |
isCollection |
|
8205 |
"return true, if the receiver is some kind of collection; |
|
8206 |
false is returned here - the method is only redefined in Collection." |
|
8207 |
||
8208 |
^ false |
|
8209 |
! |
|
8210 |
||
8211 |
isColor |
|
8212 |
"return true, if the receiver is some kind of color; |
|
8213 |
false is returned here - the method is only redefined in Color." |
|
8214 |
||
8215 |
^ false |
|
8216 |
! |
|
8217 |
||
6567 | 8218 |
isCons |
8219 |
"return true, if the receiver is a cons (pair); |
|
8220 |
false is returned here - the method is only redefined in Cons." |
|
8221 |
||
8222 |
^ false |
|
8223 |
! |
|
8224 |
||
5755 | 8225 |
isContext |
8226 |
"return true, if the receiver is some kind of context; |
|
8227 |
false returned here - the method is only redefined in Context." |
|
8228 |
||
8229 |
^ false |
|
8230 |
! |
|
8231 |
||
6181 | 8232 |
isEmptyOrNil |
8233 |
"Squeak compatibility: |
|
6182 | 8234 |
return true if I am nil or an empty collection - return false here. |
8235 |
Sigh: the same as ST/X isNilOrEmptyCollection - which one should be kept in the long run ?" |
|
6181 | 8236 |
|
8237 |
^ false |
|
8238 |
||
8239 |
"Created: / 13.11.2001 / 13:17:04 / cg" |
|
6182 | 8240 |
"Modified: / 13.11.2001 / 13:28:40 / cg" |
6181 | 8241 |
! |
8242 |
||
6221 | 8243 |
isException |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8244 |
"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
|
8245 |
|
6221 | 8246 |
^ false |
8247 |
||
8248 |
"Created: / 17.11.2001 / 18:37:44 / cg" |
|
8249 |
! |
|
8250 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8251 |
isExceptionCreator |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8252 |
"return true, if the receiver can create exceptions, |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8253 |
this includes #raise, #raiseRequest as well as the behavior of |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8254 |
an exception handler, such as the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8255 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8256 |
^ false |
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 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8259 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8260 |
"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
|
8261 |
especially to the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8262 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8263 |
^ false |
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 |
|
5755 | 8266 |
isExternalStream |
8267 |
"return true, if the receiver is some kind of externalStream; |
|
8268 |
false is returned here - the method is only redefined in ExternalStream." |
|
8269 |
||
8270 |
^false |
|
8271 |
! |
|
8272 |
||
8273 |
isFileStream |
|
8274 |
"return true, if the receiver is some kind of fileStream; |
|
8275 |
false is returned here - the method is only redefined in FileStream." |
|
8276 |
||
8277 |
^false |
|
8278 |
! |
|
8279 |
||
8280 |
isFilename |
|
8281 |
"return true, if the receiver is some kind of filename; |
|
8282 |
false is returned here - the method is only redefined in Filename." |
|
8283 |
||
8284 |
^false |
|
8285 |
! |
|
8286 |
||
8287 |
isFixedPoint |
|
8288 |
"return true, if the receiver is some kind of fixedPoint number; |
|
8289 |
false is returned here - the method is only redefined in FixedPoint." |
|
8290 |
||
8291 |
^ false |
|
8292 |
||
8293 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
8294 |
! |
|
8295 |
||
8296 |
isFixedSize |
|
8297 |
"return true if the receiver cannot grow easily |
|
8298 |
(i.e. a grow may be expensive, since it involves a become:)" |
|
8299 |
||
8300 |
^ true |
|
8301 |
! |
|
8302 |
||
6185 | 8303 |
isFloat |
8304 |
"return true, if the receiver is some kind of floating point number; |
|
8305 |
false is returned here. |
|
8306 |
Same as #isLimitedPrecisionReal, but a better name ;-)" |
|
8307 |
||
8308 |
^ false |
|
8309 |
||
8310 |
"Modified: / 14.11.2001 / 14:57:46 / cg" |
|
8311 |
! |
|
8312 |
||
5755 | 8313 |
isForm |
8314 |
"return true, if the receiver is some kind of form; |
|
8315 |
false is returned here - the method is only redefined in Form." |
|
8316 |
||
8317 |
^ false |
|
8318 |
! |
|
8319 |
||
8320 |
isFraction |
|
8321 |
"return true, if the receiver is some kind of fraction; |
|
8322 |
false is returned here - the method is only redefined in Fraction." |
|
8323 |
||
8324 |
^ false |
|
8325 |
! |
|
8326 |
||
8327 |
isImage |
|
8328 |
"return true, if the receiver is some kind of image; |
|
8329 |
false is returned here - the method is only redefined in Image." |
|
8330 |
||
8331 |
^ false |
|
8332 |
! |
|
8333 |
||
8334 |
isImageOrForm |
|
8335 |
"return true, if the receiver is some kind of image or form; |
|
8336 |
false is returned here - the method is only redefined in Image and Form." |
|
8337 |
||
8338 |
^ false |
|
8339 |
! |
|
8340 |
||
8341 |
isImmediate |
|
8342 |
"return true if I am an immediate object |
|
8343 |
i.e. I am represented in the pointer itself and |
|
8344 |
no real object header/storage is used me. |
|
8345 |
(currently, only SmallIntegers, some characters and nil return true)" |
|
8346 |
||
8347 |
^ self class hasImmediateInstances |
|
8348 |
||
8349 |
"Created: 3.6.1997 / 12:00:18 / cg" |
|
8350 |
! |
|
8351 |
||
8352 |
isInteger |
|
8353 |
"return true, if the receiver is some kind of integer number; |
|
8354 |
false is returned here - the method is only redefined in Integer." |
|
8355 |
||
8356 |
^ false |
|
8357 |
! |
|
8358 |
||
8359 |
isJavaClass |
|
8360 |
"return true, if this is a javaClass. |
|
8361 |
false is returned here - the method is only redefined in JavaClass." |
|
8362 |
||
8363 |
^ false |
|
8364 |
||
8365 |
"Created: / 26.3.1997 / 13:34:54 / cg" |
|
8366 |
"Modified: / 8.5.1998 / 21:25:21 / cg" |
|
8367 |
! |
|
8368 |
||
8369 |
isJavaClassRef |
|
8370 |
"return true, if this is a JavaClassRef. |
|
8371 |
false is returned here - the method is only redefined in JavaClassRef." |
|
8372 |
||
8373 |
^ false |
|
8374 |
||
8375 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8376 |
"Created: / 24.12.1999 / 01:46:28 / cg" |
|
8377 |
! |
|
8378 |
||
8379 |
isJavaContext |
|
8380 |
"return true, if this is a javaContext. |
|
8381 |
false is returned here - the method is only redefined in JavaContext." |
|
8382 |
||
8383 |
^ false |
|
8384 |
||
8385 |
"Created: / 8.5.1998 / 21:24:27 / cg" |
|
8386 |
"Modified: / 8.5.1998 / 21:25:35 / cg" |
|
8387 |
! |
|
8388 |
||
8389 |
isJavaMethod |
|
8390 |
"return true, if this is a JavaMethod. |
|
8391 |
false is returned here - the method is only redefined in JavaMethod." |
|
8392 |
||
8393 |
^ false |
|
8394 |
||
8395 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8396 |
"Created: / 25.9.1999 / 23:26:12 / cg" |
|
8397 |
! |
|
8398 |
||
8399 |
isJavaMethodRef |
|
8400 |
"return true, if this is a JavaMethodRef. |
|
8401 |
false is returned here - the method is only redefined in JavaMethodRef." |
|
8402 |
||
8403 |
^ false |
|
8404 |
||
8405 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8406 |
"Created: / 23.12.1999 / 19:44:51 / cg" |
|
8407 |
! |
|
8408 |
||
8409 |
isJavaObject |
|
8410 |
"return true, if this is a javaObject. |
|
8411 |
false is returned here - the method is only redefined in JavaObject." |
|
8412 |
||
8413 |
^ false |
|
8414 |
||
8415 |
"Created: / 26.3.1997 / 13:34:48 / cg" |
|
8416 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8417 |
! |
|
8418 |
||
8419 |
isJavaScriptClass |
|
8420 |
"return true, if this is a javaScriptClass. |
|
8421 |
false is returned here - the method is only redefined in JavaScriptClass." |
|
8422 |
||
8423 |
^ false |
|
8424 |
! |
|
8425 |
||
8426 |
isKindOf:aClass |
|
8427 |
"return true, if the receiver is an instance of aClass or one of its |
|
8428 |
subclasses, false otherwise. |
|
8429 |
Advice: |
|
6654 | 8430 |
use of this to check objects for certain attributes/protocoll should |
8431 |
be avoided; it limits the reusability of your classes by limiting use |
|
8432 |
to instances of certain classes and fences you into a specific inheritance |
|
8433 |
hierarchy. |
|
8434 |
Use check-methods to check an object for a certain attributes/protocol |
|
8435 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
8436 |
||
8437 |
Using #isKindOf: is considered BAD STYLE. |
|
5755 | 8438 |
|
8439 |
Advice2: |
|
6654 | 8440 |
Be aware, that using an #isXXX method is usually much faster than |
8441 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
8442 |
hierarchy, comparing every class on the way. |
|
8443 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
8444 |
a single function call. |
|
5755 | 8445 |
" |
8446 |
||
8447 |
%{ /* NOCONTEXT */ |
|
8448 |
register OBJ thisClass; |
|
8449 |
||
8450 |
thisClass = __Class(self); |
|
8451 |
while (thisClass != nil) { |
|
6654 | 8452 |
if (thisClass == aClass) { |
8453 |
RETURN ( true ); |
|
8454 |
} |
|
8455 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
5755 | 8456 |
} |
8457 |
RETURN ( false ); |
|
8458 |
%} |
|
8459 |
||
8460 |
"/ |
|
8461 |
"/ the above code is equivalent to: |
|
8462 |
"/ |
|
8463 |
"/ thisClass := self class. |
|
8464 |
"/ [thisClass notNil] whileTrue:[ |
|
8465 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
8466 |
"/ thisClass := thisClass superclass |
|
8467 |
"/ ]. |
|
8468 |
"/ ^ false |
|
8469 |
"/ |
|
8470 |
||
8471 |
! |
|
8472 |
||
8473 |
isLayout |
|
8474 |
"return true, if the receiver is some kind of layout; |
|
8475 |
false is returned here - the method is only redefined in Layout." |
|
8476 |
||
8477 |
^ false |
|
8478 |
! |
|
8479 |
||
6567 | 8480 |
isLazyValue |
8481 |
^ false |
|
8482 |
! |
|
8483 |
||
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8484 |
isLimitedPrecisionReal |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8485 |
"return true, if the receiver is some kind of floating point number; |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8486 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8487 |
|
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8488 |
^ false |
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 |
|
5755 | 8491 |
isList |
8492 |
"return true, if the receiver is some kind of list collection; |
|
8493 |
false is returned here - the method is only redefined in List." |
|
8494 |
||
8495 |
^ false |
|
8496 |
||
8497 |
"Created: / 11.2.2000 / 01:37:05 / cg" |
|
8498 |
! |
|
8499 |
||
8500 |
isLiteral |
|
8501 |
"return true, if the receiver can be represented as a literal constant in ST syntax; |
|
8502 |
false is returned here - the method is redefined in some classes." |
|
8503 |
||
8504 |
^ false |
|
8505 |
! |
|
8506 |
||
8507 |
isMemberOf:aClass |
|
8508 |
"return true, if the receiver is an instance of aClass, false otherwise. |
|
8509 |
Advice: |
|
6654 | 8510 |
use of this to check objects for certain attributes/protocoll should |
8511 |
be avoided; it limits the reusability of your classes by limiting use |
|
8512 |
to instances of a certain class. |
|
8513 |
Use check-methods to check an object for a certain attributes/protocol |
|
8514 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
8515 |
||
8516 |
Using #isMemberOf: is considered BAD STYLE. |
|
5755 | 8517 |
Notice: |
6654 | 8518 |
This method is open coded (inlined) by the compiler(s) |
8519 |
- redefining it may not work as expected." |
|
5755 | 8520 |
|
8521 |
^ (self class) == aClass |
|
8522 |
! |
|
8523 |
||
8524 |
isMeta |
|
8525 |
"return true, if the receiver is some kind of metaclass; |
|
8526 |
false is returned here - the method is only redefined in Metaclass." |
|
8527 |
||
8528 |
^ false |
|
8529 |
! |
|
8530 |
||
8531 |
isMethod |
|
8532 |
"return true, if the receiver is some kind of method; |
|
8533 |
false returned here - the method is only redefined in Method." |
|
8534 |
||
8535 |
^ false |
|
8536 |
! |
|
8537 |
||
8538 |
isMorph |
|
8539 |
"return true, if the receiver is some kind of morph; |
|
8540 |
false is returned here - the method is only redefined in Morph." |
|
8541 |
||
8542 |
^ false |
|
8543 |
! |
|
8544 |
||
8545 |
isNameSpace |
|
8546 |
"return true, if this is a nameSpace. |
|
8547 |
false is returned here - the method is only redefined in Namespace." |
|
8548 |
||
8549 |
^ false |
|
8550 |
||
8551 |
"Created: / 11.10.1996 / 18:08:56 / cg" |
|
8552 |
"Modified: / 8.5.1998 / 21:26:05 / cg" |
|
8553 |
! |
|
8554 |
||
8555 |
isNamespace |
|
8556 |
"return true, if this is a nameSpace. |
|
8557 |
false is returned here - the method is only redefined in Namespace." |
|
8558 |
||
5869 | 8559 |
<resource:#obsolete> |
8560 |
||
5755 | 8561 |
self obsoleteMethodWarning:'use #isNameSpace'. |
6805 | 8562 |
^ self isNameSpace |
5755 | 8563 |
! |
8564 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8565 |
isNil |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8566 |
"return true, if the receiver is nil. |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8567 |
Notice: |
6654 | 8568 |
This method is open coded (inlined) by the compiler(s) |
8569 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8570 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8571 |
^ false |
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 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8574 |
isNilOrEmptyCollection |
6182 | 8575 |
"return true if I am nil or an empty collection - false here. |
8576 |
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
|
8577 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8578 |
^ false |
6182 | 8579 |
|
8580 |
"Modified: / 13.11.2001 / 13:28:06 / cg" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8581 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8582 |
|
5755 | 8583 |
isNumber |
8584 |
"return true, if the receiver is some kind of number; |
|
8585 |
false is returned here - the method is only redefined in Number." |
|
8586 |
||
8587 |
^ false |
|
8588 |
! |
|
8589 |
||
8590 |
isOrderedCollection |
|
8591 |
"return true, if the receiver is some kind of ordered collection (or list etc); |
|
8592 |
false is returned here - the method is only redefined in OrderedCollection." |
|
8593 |
||
8594 |
^ false |
|
8595 |
! |
|
8596 |
||
8597 |
isPoint |
|
8598 |
"return true, if the receiver is some kind of point; |
|
8599 |
false is returned here - the method is only redefined in Point." |
|
8600 |
||
8601 |
^ false |
|
8602 |
! |
|
8603 |
||
8604 |
isRectangle |
|
8605 |
"return true, if the receiver is some kind of rectangle; |
|
8606 |
false is returned here - the method is only redefined in Rectangle." |
|
8607 |
||
8608 |
^ false |
|
8609 |
! |
|
8610 |
||
8611 |
isRemoteObject |
|
8612 |
"return true, if the receiver is some kind of remoteObject, |
|
8613 |
false if its local - the method is only redefined in RemoteObject." |
|
8614 |
||
8615 |
^ false |
|
8616 |
||
8617 |
"Created: 28.10.1996 / 15:18:45 / cg" |
|
8618 |
"Modified: 28.10.1996 / 15:20:57 / cg" |
|
8619 |
! |
|
8620 |
||
8621 |
isSequenceable |
|
8622 |
"return true, if the receiver is some kind of sequenceable collection; |
|
8623 |
false is returned here - the method is only redefined in SequenceableCollection." |
|
8624 |
||
8625 |
^ false |
|
8626 |
! |
|
8627 |
||
8628 |
isSequenceableCollection |
|
8629 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
8630 |
This method is a historic leftover and will be removed soon ... |
|
8631 |
(although its name is much better than #isSequenceable - sigh)" |
|
8632 |
||
5869 | 8633 |
<resource:#obsolete> |
8634 |
||
5755 | 8635 |
self obsoleteMethodWarning:'use #isSequenceable'. |
8636 |
^ false |
|
8637 |
! |
|
8638 |
||
8639 |
isStream |
|
8640 |
"return true, if the receiver is some kind of stream; |
|
8641 |
false is returned here - the method is only redefined in Stream." |
|
8642 |
||
8643 |
^ false |
|
8644 |
! |
|
8645 |
||
8646 |
isString |
|
8647 |
"return true, if the receiver is some kind of string; |
|
8648 |
false is returned here - the method is only redefined in CharacterArray." |
|
8649 |
||
8650 |
^ false |
|
8651 |
! |
|
8652 |
||
8653 |
isStringCollection |
|
8654 |
"return true, if the receiver is some kind of stringCollection; |
|
8655 |
false is returned here - the method is only redefined in StringCollection." |
|
8656 |
||
8657 |
^ false |
|
8658 |
! |
|
8659 |
||
8660 |
isSymbol |
|
8661 |
"return true, if the receiver is some kind of symbol; |
|
8662 |
false is returned here - the method is only redefined in Symbol." |
|
8663 |
||
8664 |
^ false |
|
8665 |
! |
|
8666 |
||
8667 |
isText |
|
8668 |
"return true, if the receiver is some kind of text object; |
|
8669 |
false is returned here - the method is only redefined in Text." |
|
8670 |
||
8671 |
^ false |
|
8672 |
||
8673 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
8674 |
! |
|
8675 |
||
8676 |
isValueModel |
|
8677 |
"return true, if the receiver is some kind of valueModel; |
|
8678 |
false is returned here - the method is only redefined in ValueModel." |
|
8679 |
||
8680 |
^ false |
|
8681 |
||
8682 |
! |
|
8683 |
||
8684 |
isVariable |
|
8685 |
"return true if the receiver has indexed instance variables, |
|
8686 |
false otherwise." |
|
8687 |
||
8688 |
^ self class isVariable |
|
8689 |
! |
|
8690 |
||
8691 |
isVariableBinding |
|
8692 |
"return true, if this is a binding for a variable. |
|
8693 |
false is returned here - the method is only redefined in Binding." |
|
8694 |
||
8695 |
^ false |
|
8696 |
||
8697 |
"Created: / 19.6.1997 / 17:38:44 / cg" |
|
8698 |
"Modified: / 8.5.1998 / 21:26:55 / cg" |
|
8699 |
! |
|
8700 |
||
8701 |
isView |
|
8702 |
"return true, if the receiver is some kind of view; |
|
8703 |
false is returned here - the method is only redefined in View." |
|
8704 |
||
8705 |
^ false |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8706 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8707 |
|
6932 | 8708 |
notEmptyOrNil |
8709 |
"Squeak compatibility: |
|
8710 |
return true if I am neither nil nor an empty collection. |
|
8711 |
Return true here." |
|
8712 |
||
8713 |
^ true |
|
8714 |
! |
|
8715 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8716 |
notNil |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8717 |
"return true, if the receiver is not nil. |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8718 |
Notice: |
6654 | 8719 |
This method is open coded (inlined) by the compiler(s) |
8720 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8721 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8722 |
^ true |
5755 | 8723 |
! ! |
8724 |
||
8725 |
!Object methodsFor:'tracing'! |
|
8726 |
||
8727 |
traceInto:aRequestor level:level from:referrer |
|
8728 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
8729 |
||
8730 |
^ aRequestor traceObject:self level:level from:referrer |
|
8731 |
||
8732 |
"Created: / 2.9.1999 / 09:05:17 / stefan" |
|
8733 |
! ! |
|
8734 |
||
8735 |
!Object methodsFor:'user interaction & notifications'! |
|
8736 |
||
8737 |
activityNotification:aString |
|
8738 |
"this can be sent from deeply nested methods, which are going to perform |
|
8739 |
some long-time activity. |
|
8740 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
8741 |
passing the argument. The handler should show this message whereever it likes, |
|
8742 |
and proceed. If there is no handler, this is simply ignored. |
|
8743 |
||
8744 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
8745 |
which likes to display that message in its label or a busy-box. |
|
8746 |
It could also be put into some logfile or printed on the standard output/error." |
|
8747 |
||
8748 |
ActivityNotificationSignal isHandled ifTrue:[ |
|
6654 | 8749 |
^ ActivityNotificationSignal raiseRequestWith:self errorString:aString |
5755 | 8750 |
]. |
8751 |
||
8752 |
" |
|
8753 |
nil activityNotification:'hello there' |
|
8754 |
self activityNotification:'hello there' |
|
8755 |
" |
|
8756 |
||
8757 |
" |
|
8758 |
ActivityNotificationSignal handle:[:ex | |
|
6654 | 8759 |
ex errorString printNL. |
8760 |
ex proceed. |
|
5755 | 8761 |
] do:[ |
6654 | 8762 |
'hello' printNL. |
8763 |
self activityNotification:'doing some long time computation'. |
|
8764 |
'world' printNL. |
|
5755 | 8765 |
] |
8766 |
" |
|
8767 |
||
8768 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
8769 |
! |
|
8770 |
||
8771 |
confirm:aString |
|
8772 |
"launch a confirmer, which allows user to enter yes or no. |
|
8773 |
return true for yes, false for no. |
|
8774 |
If no GUI is present (headless applications), true is returned." |
|
8775 |
||
8776 |
" |
|
8777 |
on systems without GUI, or during startup, output a message |
|
8778 |
and return true (as if yes was answered) |
|
8779 |
Q: should we ask user by reading Stdin ? |
|
8780 |
" |
|
8781 |
Smalltalk isInitialized ifFalse:[ |
|
6654 | 8782 |
'*** confirmation requested during initialization:' errorPrintCR. |
8783 |
aString errorPrintCR. |
|
8784 |
'*** I''ll continue, assuming <yes> ...' errorPrintCR. |
|
8785 |
^ true |
|
5755 | 8786 |
]. |
8787 |
||
8788 |
(Dialog isNil |
|
8789 |
or:[Screen isNil |
|
8790 |
or:[Screen current isNil |
|
8791 |
or:[Screen current isOpen not]]]) ifTrue:[ |
|
6654 | 8792 |
'confirm: ' infoPrint. |
8793 |
aString infoPrintCR. |
|
8794 |
'continue, assuming <yes>' infoPrintCR. |
|
8795 |
^ true |
|
5755 | 8796 |
]. |
8797 |
||
8798 |
Dialog autoload. "in case its autoloaded" |
|
8799 |
^ Dialog confirm:aString |
|
8800 |
||
8801 |
" |
|
8802 |
nil confirm:'hello' |
|
8803 |
self confirm:'hello' |
|
8804 |
" |
|
8805 |
||
8806 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8807 |
! |
|
8808 |
||
8809 |
confirm:aString orCancel:cancelBlock |
|
8810 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8811 |
return true for yes, false for no, or the value from cancelBlock for cancel. |
|
8812 |
If no GUI is present (headless applications), cancelBlock is returned." |
|
8813 |
||
8814 |
|answer| |
|
8815 |
||
8816 |
answer := self confirmWithCancel:aString. |
|
8817 |
answer isNil ifTrue:[ |
|
6654 | 8818 |
^ cancelBlock value |
5755 | 8819 |
]. |
8820 |
^ answer |
|
8821 |
||
8822 |
" |
|
8823 |
self confirm:'hello' orCancel:[self halt] |
|
8824 |
" |
|
8825 |
||
8826 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8827 |
! |
|
8828 |
||
8829 |
confirmWithCancel:aString |
|
8830 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8831 |
return true for yes, false for no, nil for cancel. |
|
8832 |
If no GUI is present (headless applications), nil is returned." |
|
8833 |
||
8834 |
" |
|
8835 |
on systems without GUI, or during startup, output a message |
|
8836 |
and return true (as if yes was answered) |
|
8837 |
Q: should we ask user by reading Stdin ? |
|
8838 |
" |
|
8839 |
Smalltalk isInitialized ifFalse:[ |
|
6654 | 8840 |
'*** confirmation requested during initialization:' errorPrintCR. |
8841 |
aString errorPrintCR. |
|
8842 |
'*** I''ll continue, assuming <cancel> ...' errorPrintCR. |
|
8843 |
^ nil |
|
5755 | 8844 |
]. |
8845 |
||
8846 |
(Dialog isNil |
|
8847 |
or:[Screen isNil |
|
8848 |
or:[Screen current isNil |
|
8849 |
or:[Screen current isOpen not]]]) ifTrue:[ |
|
6654 | 8850 |
'confirm: ' infoPrint. |
8851 |
aString infoPrintCR. |
|
8852 |
'continue, assuming <cancel>' infoPrintCR. |
|
8853 |
^ nil |
|
5755 | 8854 |
]. |
8855 |
||
8856 |
Dialog autoload. "in case its autoloaded" |
|
8857 |
^ Dialog confirmWithCancel:aString |
|
8858 |
||
8859 |
" |
|
8860 |
nil confirmWithCancel:'hello' |
|
8861 |
self confirmWithCancel:'hello' |
|
8862 |
" |
|
8863 |
||
8864 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8865 |
! |
|
8866 |
||
8867 |
errorNotify:aString |
|
8868 |
"launch a Notifier, showing top stack, telling user something |
|
8869 |
and give user a chance to enter debugger." |
|
8870 |
||
8871 |
^ self |
|
6654 | 8872 |
errorNotify:aString |
8873 |
from:thisContext sender |
|
8874 |
allowDebug:true |
|
5755 | 8875 |
|
8876 |
" |
|
8877 |
nil errorNotify:'hello there' |
|
8878 |
self errorNotify:'hello there' |
|
8879 |
" |
|
8880 |
||
6199 | 8881 |
"Modified: / 16.11.2001 / 15:36:49 / cg" |
5755 | 8882 |
! |
8883 |
||
8884 |
errorNotify:aString from:aContext |
|
8885 |
"launch a Notifier, showing top stack (above aContext), |
|
8886 |
telling user something and give user a chance to enter debugger." |
|
8887 |
||
8888 |
^ self errorNotify:aString from:aContext allowDebug:true |
|
8889 |
||
8890 |
"Modified: / 17.8.1998 / 10:09:27 / cg" |
|
8891 |
! |
|
8892 |
||
8893 |
errorNotify:aString from:aContext allowDebug:allowDebug |
|
8894 |
"launch a Notifier, showing top stack (above aContext), |
|
8895 |
telling user something and optionally give the user a chance to enter debugger." |
|
8896 |
||
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8897 |
|currentScreen con sender action boxLabels boxValues default| |
5755 | 8898 |
|
8899 |
Smalltalk isInitialized ifFalse:[ |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8900 |
'errorNotification: ' print. aString printCR. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8901 |
^ self |
5755 | 8902 |
]. |
8903 |
(Dialog isNil |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8904 |
or:[Screen isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8905 |
or:[(currentScreen := Screen current) isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8906 |
or:[currentScreen isOpen not]]]) ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8907 |
" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8908 |
on systems without GUI, simply show |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8909 |
the message on the Transcript and abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8910 |
" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8911 |
Transcript showCR:aString. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8912 |
AbortSignal raise. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8913 |
^ self |
5755 | 8914 |
]. |
8915 |
||
8916 |
Processor activeProcessIsSystemProcess ifTrue:[ |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8917 |
action := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8918 |
sender := aContext. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8919 |
Debugger isNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8920 |
'****************** Cought Error while in SystemProcess ****************' errorPrintCR. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8921 |
thisContext fullPrintAll. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8922 |
action := #abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8923 |
]. |
5755 | 8924 |
] ifFalse:[ |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8925 |
Dialog autoload. "in case it's autoloaded" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8926 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8927 |
Error handle:[:ex | |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8928 |
"/ a recursive error - quickly enter debugger |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8929 |
"/ this happened, when I corrupted the Dialog class ... |
7208 | 8930 |
('Object [error]: ' , ex description , ' caught in errorNotification') errorPrintCR. |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8931 |
action := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8932 |
ex return. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8933 |
] do:[ |s| |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8934 |
sender := aContext. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8935 |
sender isNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8936 |
sender := thisContext sender. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8937 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8938 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8939 |
"/ skip intermediate (signal & exception) contexts |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8940 |
DebugView notNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8941 |
sender := DebugView interestingContextFrom:sender |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8942 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8943 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8944 |
"/ show the first few contexts |
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 |
s := WriteStream with:aString. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8947 |
s cr; cr. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8948 |
con := sender. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8949 |
1 to:15 do:[:n | |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8950 |
con notNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8951 |
con printOn:s. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8952 |
s cr. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8953 |
con := con sender |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8954 |
] |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8955 |
]. |
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 |
(allowDebug and:[Debugger notNil]) ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8958 |
boxLabels := #('Proceed' 'Abort' 'Copy Trace and Abort' 'Debug'). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8959 |
boxValues := #(#proceed #abort #copy #debug). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8960 |
default := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8961 |
] ifFalse:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8962 |
boxLabels := #('Proceed' 'Abort' 'Copy Trace and Abort'). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8963 |
boxValues := #(#proceed #abort #copy). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8964 |
default := #abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8965 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8966 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8967 |
action := Dialog |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8968 |
choose:s contents |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8969 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8970 |
image:WarningBox errorIconBitmap |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8971 |
labels:boxLabels |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8972 |
values:boxValues |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8973 |
default:default |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8974 |
onCancel:nil. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8975 |
]. |
5755 | 8976 |
]. |
8977 |
||
8978 |
action == #debug ifTrue:[ |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8979 |
Debugger enter:sender withMessage:aString mayProceed:true |
5755 | 8980 |
] ifFalse:[ |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8981 |
action == #proceed ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8982 |
^ self. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8983 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8984 |
action == #copy ifTrue:[ |s| |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8985 |
s := '' writeStream. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8986 |
sender fullPrintAllOn:s. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8987 |
currentScreen rootView setTextSelection:s contents. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8988 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8989 |
AbortSignal raise |
5755 | 8990 |
] |
8991 |
||
8992 |
" |
|
8993 |
nil errorNotify:'hello there' |
|
8994 |
self errorNotify:'hello there' |
|
8995 |
" |
|
8996 |
||
8997 |
"Created: / 17.8.1998 / 10:09:26 / cg" |
|
6199 | 8998 |
"Modified: / 16.11.2001 / 15:40:12 / cg" |
5755 | 8999 |
! |
9000 |
||
9001 |
information:aString |
|
9002 |
"launch an InfoBox, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9003 |
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
|
9004 |
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
|
9005 |
Use #notify: for more important messages. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9006 |
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
|
9007 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9008 |
|
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
9009 |
UserInformation raiseRequestWith:self errorString:aString |
5755 | 9010 |
|
9011 |
" |
|
9012 |
nil information:'hello there' |
|
9013 |
self information:'hello there' |
|
9014 |
" |
|
9015 |
||
9016 |
" |
|
9017 |
InformationSignal handle:[:ex | |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9018 |
'no box popped' printCR. |
6654 | 9019 |
ex proceed. |
5755 | 9020 |
] do:[ |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9021 |
'hello' printCR. |
6654 | 9022 |
self information:'some info'. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9023 |
'world' printCR. |
5755 | 9024 |
] |
9025 |
" |
|
9026 |
||
9027 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
9028 |
! |
|
9029 |
||
9030 |
notify:aString |
|
9031 |
"launch a Notifier, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9032 |
Use #information: for ignorable messages. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9033 |
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
|
9034 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9035 |
|
5755 | 9036 |
|
9037 |
Smalltalk isInitialized ifFalse:[ |
|
6656 | 9038 |
"/ thisContext fullPrintAll. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9039 |
'information: ' print. aString printCR. |
6654 | 9040 |
^ self |
5755 | 9041 |
]. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9042 |
UserNotification raiseRequestWith:self errorString:aString. |
5755 | 9043 |
|
9044 |
" |
|
9045 |
nil notify:'hello there' |
|
9046 |
self notify:'hello there' |
|
9047 |
" |
|
9048 |
||
9049 |
"Modified: 20.5.1996 / 10:28:48 / cg" |
|
9050 |
! |
|
9051 |
||
9052 |
warn:aString |
|
9053 |
"launch a WarningBox, telling user something. |
|
9054 |
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
|
9055 |
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
|
9056 |
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
|
9057 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9058 |
|
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9059 |
Warning raiseRequestWith:self errorString:aString |
5755 | 9060 |
|
9061 |
" |
|
9062 |
nil warn:'hello there' |
|
9063 |
self warn:'hello there' |
|
9064 |
" |
|
9065 |
||
9066 |
" |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9067 |
Warning handle:[:ex | |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9068 |
Transcript showCR:ex description. |
6654 | 9069 |
ex proceed. |
5755 | 9070 |
] do:[ |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9071 |
'hello' printCR. |
6654 | 9072 |
self warn:'some info'. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9073 |
'world' printCR. |
5755 | 9074 |
] |
9075 |
" |
|
9076 |
||
9077 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
|
9078 |
! ! |
|
9079 |
||
9080 |
!Object class methodsFor:'documentation'! |
|
1 | 9081 |
|
5754 | 9082 |
version |
7266 | 9083 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.465 2003-05-07 15:15:42 cg Exp $' |
1 | 9084 |
! ! |
6764 | 9085 |
|
5755 | 9086 |
Object initialize! |