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