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