author | Claus Gittinger <cg@exept.de> |
Wed, 04 Jun 2008 17:19:28 +0200 | |
changeset 11044 | fa13d9423e71 |
parent 11025 | f99538ebf2a3 |
child 11045 | 85315d8893e4 |
permissions | -rw-r--r-- |
5755 | 1 |
" |
2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
10460 | 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 |
"{ Package: 'stx:libbasic' }" |
|
13 |
||
14 |
nil subclass:#Object |
|
6697 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'ErrorSignal HaltSignal MessageNotUnderstoodSignal |
|
17 |
UserInterruptSignal RecursionInterruptSignal |
|
18 |
ExceptionInterruptSignal SubscriptOutOfBoundsSignal |
|
19 |
IndexNotFoundSignal NonIntegerIndexSignal NotFoundSignal |
|
20 |
KeyNotFoundSignal ElementOutOfBoundsSignal UserNotificationSignal |
|
21 |
InformationSignal WarningSignal PrimitiveFailureSignal |
|
22 |
DeepCopyErrorSignal AbortSignal ErrorRecursion Dependencies |
|
23 |
InfoPrinting ActivityNotificationSignal InternalErrorSignal |
|
24 |
NonWeakDependencies SynchronizationSemaphores ObjectAttributes |
|
25 |
OSSignalInterruptSignal FinalizationLobby |
|
11025 | 26 |
RecursiveStoreStringSignal AbortAllSignal EnabledBreakPoints' |
6697 | 27 |
poolDictionaries:'' |
28 |
category:'Kernel-Objects' |
|
5755 | 29 |
! |
30 |
||
31 |
!Object class methodsFor:'documentation'! |
|
3023
674376809496
general listView support (#displayOn / widthOn / heightOn)
ca
parents:
3010
diff
changeset
|
32 |
|
5754 | 33 |
copyright |
5755 | 34 |
" |
35 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
10460 | 36 |
All Rights Reserved |
5755 | 37 |
|
38 |
This software is furnished under a license and may be used |
|
39 |
only in accordance with the terms of that license and with the |
|
40 |
inclusion of the above copyright notice. This software may not |
|
41 |
be provided or otherwise made available to, or used by, any |
|
42 |
other person. No title to or ownership of the software is |
|
43 |
hereby transferred. |
|
44 |
" |
|
45 |
! |
|
46 |
||
47 |
dependencies |
|
48 |
" |
|
10460 | 49 |
ST/X dependencies are slightly modified from ST-80's |
5755 | 50 |
(we think they are better ;-). |
51 |
||
52 |
One problem occuring very often in ST-80 is that some object |
|
53 |
cannot be garbage collected because some dependency is present, |
|
54 |
having the object as a dependent of some other object. |
|
55 |
In ST-80, this association remains alive (because a Dictionary |
|
56 |
is used to hold dependents) - even if no other references exist to |
|
57 |
to dependent or the dependee. |
|
58 |
||
59 |
This means, that in ST-80, a #release is mandatory in order to |
|
60 |
prevent memory leaks. |
|
61 |
We think, that this is a bad solution, since after all, exactly that |
|
62 |
kind of work should be performed by a garbage collector - you should not |
|
63 |
need to care about dependencies. |
|
10460 | 64 |
From a philosophical point of view, why should some object depend on |
5755 | 65 |
something that the programmer considers a dead object ? |
66 |
(well - worse than that: it seems that some ST-80 code even depends on |
|
67 |
that behavior) |
|
68 |
||
69 |
In order to limit the trouble, ST-80 reimplemented the way dependents |
|
70 |
are stored in the model class - this one keeps the dependents locally, |
|
71 |
so these dependents go away, once the model is reclaimed. |
|
72 |
That may make things even more confusing: with models, no #release is |
|
73 |
needed, with general objects it is mandatory. |
|
74 |
||
75 |
||
76 |
In ST/X, dependencies are implemented using a WeakDictionary; this means, |
|
77 |
that once the dependee dies, the dependency association is removed automatically, |
|
78 |
and the dependent can be reclaimed by the garbage collector, if no other |
|
79 |
references exist to the dependent. |
|
80 |
In order to (at least) provide a mechanism for the old behavior |
|
81 |
(in case your application heavily depends on the ST-80 mechanism), complementary |
|
10460 | 82 |
protocol to add nonWeak dependencies is provided |
5755 | 83 |
(see #addNonWeakDependent / #removeNonWeakDependent). |
84 |
||
85 |
||
86 |
Caveat: |
|
87 |
since interests are implemented using InterestConverter (which are simply |
|
88 |
forwarding messages), these must use the nonWeak mechanism (as done in ST-80 |
|
89 |
automatically). |
|
90 |
The reason is that there are usually no direct references to the converters, |
|
91 |
and those would be reclaimed if stored in a weakDictionary. |
|
92 |
This means, that those interests MUST be removed with #retractInterest |
|
10460 | 93 |
(which is bug-compatible to ST-80). |
5755 | 94 |
We rewrite things to provide a more convenient mechanism in the future ... |
95 |
||
96 |
||
97 |
I like to hear comments on the above - do you think its better ? |
|
98 |
" |
|
99 |
! |
|
100 |
||
101 |
documentation |
|
102 |
" |
|
10460 | 103 |
Object is the superclass of most other classes. |
5755 | 104 |
(except for nil-subclasses, which inherit nothing, |
105 |
to catch any message into their #doesNotUnderstand: method) |
|
106 |
||
107 |
Protocol which is common to every object is defined here. |
|
108 |
Also some utility stuff (like notify) and error handling is implemented here. |
|
109 |
||
110 |
Object has no instance variables (and may not get any added). One reason is, that |
|
10460 | 111 |
UndefinedObject and SmallInteger are also inheriting from Object - these two cannot |
112 |
have instance variables (due to their implementation). |
|
113 |
The other reason is that the runtime system (VM) knows about the layout of some built-in |
|
114 |
classes (think of Class, Method, Block and also Integer or Float). |
|
115 |
If you were allowed to add instance variables to Object, the VM had to be recompiled |
|
5755 | 116 |
(and also rewritten in some places). |
117 |
||
118 |
[Class variables:] |
|
119 |
||
10460 | 120 |
ErrorSignal <Signal> Signal raised for error/error: messages |
121 |
also, parent of all other signals. |
|
122 |
||
123 |
HaltSignal <Signal> Signal raised for halt/halt: messages |
|
124 |
||
125 |
MessageNotUnderstoodSignal Signals raised for various error conditions |
|
126 |
UserInterruptSignal |
|
127 |
RecursionInterruptSignal |
|
128 |
ExceptionInterruptSignal |
|
129 |
SubscriptOutOfBoundsSignal |
|
130 |
NonIntegerIndexSignal |
|
131 |
NotFoundSignal |
|
132 |
KeyNotFoundSignal |
|
133 |
ElementOutOfBoundsSignal |
|
134 |
InformationSignal |
|
135 |
WarningSignal |
|
136 |
DeepCopyErrorSignal |
|
137 |
InternalErrorSignal |
|
138 |
||
139 |
AbortSignal <Signal> Signal raised by debugger, to abort a computation |
|
140 |
BUT, the debugger will only raise it if it is handled. |
|
141 |
By handling the abortSignal, you can control where the |
|
142 |
debuggers abort-function resumes execution in case of |
|
143 |
an error. |
|
144 |
||
145 |
ErrorRecursion <Boolean> controls behavior when recursive errors occur (i.e. |
|
146 |
an error while handling an error). |
|
147 |
||
148 |
Dependencies <WeakDependencyDictionary> |
|
149 |
keeps track of object dependencies. |
|
150 |
||
151 |
InfoPrinting <Boolean> controls weather informational messages |
|
152 |
are printed. |
|
153 |
||
154 |
ActivityNotificationSignal <QuerySignal> |
|
155 |
raised on #activityNotification: |
|
156 |
||
157 |
NonWeakDependencies <Dictionary> keeps track of object dependencies. |
|
158 |
Dependents stay alive. |
|
159 |
||
160 |
SynchronizationSemaphores <WeakIdentityDictionary> |
|
161 |
Semaphores for per-object-monitor. |
|
162 |
||
5755 | 163 |
|
164 |
[author:] |
|
10460 | 165 |
Claus Gittinger |
5755 | 166 |
|
167 |
" |
|
168 |
! ! |
|
169 |
||
170 |
!Object class methodsFor:'initialization'! |
|
171 |
||
5971 | 172 |
initSignals |
173 |
"called only once - initialize signals" |
|
174 |
||
175 |
ErrorSignal := Error. |
|
176 |
||
177 |
ControlInterrupt notifierString:'control interrupted'. |
|
178 |
||
179 |
HaltSignal := HaltInterrupt. |
|
180 |
HaltSignal notifierString:'halt encountered'. |
|
181 |
||
5977 | 182 |
MessageNotUnderstoodSignal := MessageNotUnderstood. |
5971 | 183 |
MessageNotUnderstoodSignal notifierString:'message not understood'. |
184 |
||
6000 | 185 |
PrimitiveFailureSignal := PrimitiveFailure. |
5971 | 186 |
PrimitiveFailureSignal notifierString:'primitive failed'. |
187 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
188 |
InternalErrorSignal := VMInternalError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
189 |
|
5971 | 190 |
UserInterruptSignal := UserInterrupt. |
191 |
UserInterruptSignal notifierString:'user Interrupt'. |
|
192 |
||
6146 | 193 |
RecursionInterruptSignal := RecursionError. |
5971 | 194 |
RecursionInterruptSignal notifierString:'recursion limit reached'. |
195 |
||
5977 | 196 |
NotFoundSignal := NotFoundError. |
5971 | 197 |
NotFoundSignal notifierString:'no such element'. |
198 |
||
5977 | 199 |
IndexNotFoundSignal := IndexNotFoundError. |
5971 | 200 |
IndexNotFoundSignal notifierString:'bad index: '. |
201 |
||
5977 | 202 |
SubscriptOutOfBoundsSignal := SubscriptOutOfBoundsError. |
5971 | 203 |
SubscriptOutOfBoundsSignal notifierString:'subscript out of bounds: '. |
204 |
||
5977 | 205 |
NonIntegerIndexSignal := NonIntegerIndexError. |
206 |
NonIntegerIndexSignal notifierString:'index must be integer'. |
|
207 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
208 |
KeyNotFoundSignal := KeyNotFoundError. |
5977 | 209 |
KeyNotFoundSignal notifierString:'no such key: '. |
210 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
211 |
ElementOutOfBoundsSignal := ElementBoundsError. |
5971 | 212 |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
213 |
UserNotificationSignal := UserNotification. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
214 |
WarningSignal := Warning. |
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
215 |
InformationSignal := UserInformation. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
216 |
ActivityNotificationSignal := ActivityNotification. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
217 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
218 |
DeepCopyErrorSignal := DeepCopyError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
219 |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
220 |
AbortSignal := AbortOperationRequest. |
6877
ab4e7d42f9f8
AbortAllOperation - now class based
Claus Gittinger <cg@exept.de>
parents:
6874
diff
changeset
|
221 |
AbortAllSignal := AbortAllOperationRequest. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
222 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
223 |
OSSignalInterruptSignal := OSSignalInterrupt. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
224 |
RecursiveStoreStringSignal := RecursiveStoreError. |
5971 | 225 |
|
5980 | 226 |
" |
227 |
Object initSignals |
|
228 |
" |
|
5971 | 229 |
|
230 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
231 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
232 |
"Modified: / 16.11.2001 / 16:30:08 / cg" |
5971 | 233 |
! |
234 |
||
5755 | 235 |
initialize |
236 |
"called only once - initialize signals" |
|
237 |
||
238 |
ErrorSignal isNil ifTrue:[ |
|
10460 | 239 |
self initSignals |
5971 | 240 |
]. |
241 |
||
242 |
ObjectAttributes isNil ifTrue:[ |
|
10460 | 243 |
ObjectAttributes := WeakIdentityDictionary new. |
5971 | 244 |
]. |
245 |
Dependencies isNil ifTrue:[ |
|
10460 | 246 |
Dependencies := WeakDependencyDictionary new. |
5971 | 247 |
]. |
248 |
NonWeakDependencies isNil ifTrue:[ |
|
10460 | 249 |
NonWeakDependencies := IdentityDictionary new. |
5971 | 250 |
]. |
251 |
SynchronizationSemaphores isNil ifTrue:[ |
|
10460 | 252 |
SynchronizationSemaphores := WeakIdentityDictionary new. |
5971 | 253 |
]. |
5755 | 254 |
FinalizationLobby isNil ifTrue:[ |
10460 | 255 |
FinalizationLobby := Registry new. |
5755 | 256 |
]. |
257 |
||
258 |
"/ initialize InfoPrinting to the VM's infoPrint setting |
|
259 |
"/ (which can be turned off via a command line argument) |
|
260 |
InfoPrinting := ObjectMemory infoPrinting. |
|
261 |
||
262 |
"Object initialize" |
|
263 |
||
264 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
265 |
"Modified: / 3.2.1998 / 18:55:09 / cg" |
|
266 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
267 |
! ! |
|
268 |
||
7303 | 269 |
!Object class methodsFor:'Compatibility-ST80'! |
5755 | 270 |
|
271 |
rootError |
|
272 |
"return the signal used for error/error: - handling. |
|
273 |
Same as errorSignal for ST80 compatibility." |
|
274 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
275 |
^ Error |
5755 | 276 |
|
277 |
"Created: / 15.1.1998 / 23:47:05 / stefan" |
|
278 |
! ! |
|
279 |
||
280 |
!Object class methodsFor:'Signal constants'! |
|
281 |
||
10460 | 282 |
abortAllSignal |
5755 | 283 |
"return the signal used to abort user actions (much like AbortSignal). |
284 |
This signal is supposed to abort multiple operation actions, and get out of |
|
285 |
the loop (such as when confirming multiple class deletions etc.)" |
|
286 |
||
287 |
^ AbortAllSignal |
|
288 |
! |
|
289 |
||
10460 | 290 |
abortSignal |
5755 | 291 |
"return the signal used to abort user actions. This signal is only |
292 |
raised if caught (by the debugger), and will lead way out of the |
|
293 |
currently active doIt/printIt or inspectIt. (also some others use |
|
294 |
this for a save abort)" |
|
295 |
||
8521 | 296 |
^ AbortOperationRequest |
5755 | 297 |
! |
298 |
||
299 |
activityNotificationSignal |
|
300 |
"return the signal used for activity notifications. |
|
301 |
A handler for this signal gets all #activityNotification: sends" |
|
302 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
303 |
^ ActivityNotification |
5755 | 304 |
! |
305 |
||
10460 | 306 |
deepCopyErrorSignal |
5755 | 307 |
"return the signal raised when a deepcopy is asked for |
308 |
an object which cannot do this (for example, BlockClosures |
|
309 |
or Contexts)." |
|
310 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
311 |
^ DeepCopyError |
5755 | 312 |
! |
313 |
||
314 |
elementOutOfBoundsSignal |
|
315 |
"return the signal used for element error reporting |
|
316 |
(this signal is used for example when a value not in 0..255 is to |
|
317 |
be put into a bytearray)" |
|
318 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
319 |
^ ElementBoundsError |
5755 | 320 |
! |
321 |
||
322 |
errorSignal |
|
323 |
"return the signal used for error/error: - handling" |
|
324 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
325 |
^ Error |
5755 | 326 |
! |
327 |
||
328 |
haltSignal |
|
329 |
"return the signal used for halt/halt: - handling" |
|
330 |
||
331 |
^ HaltSignal |
|
332 |
! |
|
333 |
||
334 |
indexNotFoundSignal |
|
335 |
"return the signal used for bad index error reporting. |
|
336 |
This is also the parentSignal of the nonIntegerIndex- and |
|
337 |
subscriptOutOfBoundsSignal" |
|
338 |
||
339 |
^ IndexNotFoundSignal |
|
340 |
||
341 |
"Created: / 8.11.1997 / 19:15:48 / cg" |
|
342 |
! |
|
343 |
||
10460 | 344 |
informationSignal |
345 |
"return the signal used for informations. |
|
5755 | 346 |
A handler for this signal gets all #information: sends" |
347 |
||
348 |
^ InformationSignal |
|
349 |
! |
|
350 |
||
351 |
internalErrorSignal |
|
352 |
"return the signal used to report internal (VM-) errors." |
|
353 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
354 |
^ VMInternalError |
5755 | 355 |
! |
356 |
||
10460 | 357 |
keyNotFoundSignal |
5755 | 358 |
"return the signal used for no such key error reporting" |
359 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
360 |
^ KeyNotFoundError |
5755 | 361 |
! |
362 |
||
363 |
messageNotUnderstoodSignal |
|
364 |
"return the signal used for doesNotUnderstand: - error handling" |
|
365 |
||
366 |
^ MessageNotUnderstoodSignal |
|
367 |
! |
|
368 |
||
10460 | 369 |
nonIntegerIndexSignal |
5755 | 370 |
"return the signal used for bad subscript error reporting" |
371 |
||
372 |
^ NonIntegerIndexSignal |
|
373 |
! |
|
374 |
||
10460 | 375 |
notFoundSignal |
5755 | 376 |
"return the signal used for no element found error reporting" |
377 |
||
378 |
^ NotFoundSignal |
|
379 |
! |
|
380 |
||
7644
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
381 |
notifySignal |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
382 |
"return the parent of all notification signals." |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
383 |
|
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
384 |
^ Notification |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
385 |
! |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
386 |
|
10460 | 387 |
osSignalInterruptSignal |
5755 | 388 |
"return the signal used for OS-signal error reporting; |
389 |
This is only raised if handled - otherwise, a debugger is entered." |
|
390 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
391 |
^ OSSignalInterrupt |
5755 | 392 |
|
393 |
"Modified: / 12.6.1998 / 16:27:26 / cg" |
|
394 |
! |
|
395 |
||
396 |
primitiveFailureSignal |
|
397 |
"return the signal used for primitiveFailed - error handling" |
|
398 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
399 |
^ PrimitiveFailure |
5755 | 400 |
! |
401 |
||
402 |
privateMethodSignal |
|
403 |
"return the signal used for privateMethod - error handling" |
|
404 |
||
405 |
^ MessageNotUnderstoodSignal |
|
406 |
! |
|
407 |
||
10460 | 408 |
recursionInterruptSignal |
5755 | 409 |
"return the signal used for recursion overflow error handling" |
410 |
||
411 |
^ RecursionInterruptSignal |
|
412 |
! |
|
413 |
||
414 |
recursiveStoreStringSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
415 |
"return the notification used to report storeString generation of recursive objects" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
416 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
417 |
^ RecursiveStoreError |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
418 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
419 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
420 |
RecursiveStoreError handle:[:ex | |
10460 | 421 |
self halt |
5755 | 422 |
] do:[ |
10460 | 423 |
|a| |
424 |
||
425 |
a := Array new:1. |
|
426 |
a at:1 put:a. |
|
427 |
a storeOn:Transcript |
|
5755 | 428 |
] |
429 |
" |
|
430 |
||
431 |
" |
|
432 |
|a| |
|
433 |
||
434 |
a := Array new:1. |
|
435 |
a at:1 put:a. |
|
436 |
a storeOn:Transcript |
|
437 |
" |
|
438 |
! |
|
439 |
||
5980 | 440 |
subclassResponsibilitySignal |
441 |
"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
|
442 |
(this signal is used to signal incomplete subclasses - i.e. a programmers error)" |
5980 | 443 |
|
444 |
^ SubclassResponsibilityError |
|
445 |
! |
|
446 |
||
5755 | 447 |
subscriptOutOfBoundsSignal |
448 |
"return the signal used for subscript error reporting. |
|
449 |
(this signal is used for example when an array is accessed with an |
|
450 |
index less than 1 or greater than the array size)" |
|
451 |
||
452 |
^ SubscriptOutOfBoundsSignal |
|
453 |
! |
|
454 |
||
455 |
userInterruptSignal |
|
456 |
"return the signal used for ^C interrupts handling" |
|
457 |
||
458 |
^ UserInterruptSignal |
|
459 |
! |
|
460 |
||
461 |
userNotificationSignal |
|
462 |
"the parent signal used with information and warnings. |
|
463 |
Handling this allows handling of both information- and warning notifications." |
|
464 |
||
465 |
^ UserNotificationSignal |
|
466 |
! |
|
467 |
||
10460 | 468 |
warningSignal |
5755 | 469 |
"return the signal used for warnings. |
470 |
A handler for this signal gets all #warn: sends" |
|
471 |
||
472 |
^ WarningSignal |
|
473 |
! ! |
|
474 |
||
475 |
!Object class methodsFor:'info messages'! |
|
476 |
||
477 |
infoPrinting |
|
478 |
"return the flag which controls information messages." |
|
479 |
||
480 |
^ InfoPrinting |
|
481 |
! |
|
482 |
||
483 |
infoPrinting:aBoolean |
|
484 |
"{ Pragma: +optSpace }" |
|
485 |
||
486 |
"turn on/off printing of information messages. |
|
487 |
If the argument, aBoolean is false, infoPrint will not output |
|
488 |
messages. The default is true." |
|
489 |
||
490 |
InfoPrinting := aBoolean |
|
491 |
! ! |
|
492 |
||
493 |
!Object class methodsFor:'queries'! |
|
494 |
||
8892 | 495 |
isAbstract |
496 |
^ self == Object |
|
497 |
! |
|
498 |
||
5755 | 499 |
isBuiltInClass |
500 |
"return true, if this class is known by the run-time-system, |
|
501 |
i.e. you cannot add/remove instance variables without recompiling |
|
502 |
the VM. |
|
503 |
Here, true is returned for myself, false for subclasses." |
|
504 |
||
505 |
^ self == Object |
|
506 |
||
507 |
"Modified: 23.4.1996 / 16:00:07 / cg" |
|
508 |
! ! |
|
509 |
||
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
510 |
!Object methodsFor:'Compatibility-Dolphin'! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
511 |
|
10460 | 512 |
trigger:anAspect |
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
513 |
self changed:anAspect |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
514 |
! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
515 |
|
10460 | 516 |
trigger:anAspect with:anArgument |
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
517 |
self changed:anAspect with:anArgument |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
518 |
! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
519 |
|
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
520 |
when:anAspect sendTo:anObject |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
521 |
self expressInterestIn:anAspect for:anObject sendBack:anAspect |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
522 |
! ! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
523 |
|
9375 | 524 |
!Object methodsFor:'Compatibility-ST/V'! |
525 |
||
526 |
triggerEvent:aSymbol |
|
527 |
self changed:aSymbol |
|
528 |
! ! |
|
529 |
||
7261 | 530 |
!Object methodsFor:'Compatibility-ST80'! |
5755 | 531 |
|
532 |
isMetaclass |
|
533 |
^ self isMeta |
|
534 |
! ! |
|
535 |
||
7261 | 536 |
!Object methodsFor:'Compatibility-Squeak'! |
5755 | 537 |
|
538 |
asString |
|
539 |
^ self printString |
|
540 |
! |
|
541 |
||
9071 | 542 |
becomeForward:anotherObject |
543 |
self becomeSameAs:anotherObject |
|
544 |
! |
|
545 |
||
546 |
becomeForward:anotherObject copyHash:copyHash |
|
547 |
copyHash ifTrue:[ self error:'unsupported operation' ]. |
|
548 |
self becomeSameAs:anotherObject |
|
549 |
! |
|
550 |
||
5755 | 551 |
clone |
552 |
^ self shallowCopy |
|
553 |
! |
|
554 |
||
6146 | 555 |
copyTwoLevel |
556 |
"one more level than a shallowCopy" |
|
557 |
||
558 |
^ self copyToLevel:2 |
|
559 |
||
560 |
" |
|
561 |
|original copy elL1 elL2 elL3 copyOfElL1| |
|
562 |
||
563 |
original := Array new:3. |
|
564 |
original at:1 put:1234. |
|
565 |
original at:2 put:'hello'. |
|
566 |
original at:3 put:(elL1 := Array new:3). |
|
567 |
||
568 |
elL1 at:1 put:1234. |
|
569 |
elL1 at:2 put:'hello'. |
|
570 |
elL1 at:3 put:(elL2 := Array new:3). |
|
571 |
||
572 |
elL2 at:1 put:1234. |
|
573 |
elL2 at:2 put:'hello'. |
|
574 |
elL2 at:3 put:(elL3 := Array new:3). |
|
575 |
||
576 |
elL3 at:1 put:1234. |
|
577 |
elL3 at:2 put:'hello'. |
|
578 |
elL3 at:3 put:(Array new:3). |
|
579 |
||
580 |
copy := original copyTwoLevel. |
|
581 |
(original at:2) ~~ (copy at:2) ifFalse:[self halt]. |
|
582 |
(original at:3) ~~ (copy at:3) ifFalse:[self halt]. |
|
583 |
||
584 |
copyOfElL1 := copy at:3. |
|
585 |
(elL1 at:2) == (copyOfElL1 at:2) ifFalse:[self halt]. |
|
586 |
(elL1 at:3) == (copyOfElL1 at:3) ifFalse:[self halt]. |
|
587 |
" |
|
588 |
! |
|
589 |
||
7320 | 590 |
explore |
591 |
(self confirm:'The Squeak explorer has not yet been ported to ST/X\\Inspect instead ?' withCRs) |
|
592 |
ifTrue:[ |
|
10460 | 593 |
self inspect |
7320 | 594 |
] |
595 |
! |
|
596 |
||
9335 | 597 |
isInMemory |
598 |
"All normal objects are." |
|
599 |
||
600 |
^ true |
|
601 |
! |
|
602 |
||
5755 | 603 |
stringForReadout |
10460 | 604 |
^ self stringRepresentation |
5755 | 605 |
! |
606 |
||
607 |
stringRepresentation |
|
10460 | 608 |
"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" |
609 |
||
610 |
^ self printString |
|
5755 | 611 |
! |
612 |
||
9146
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
613 |
valueWithPossibleArguments:argArray |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
614 |
^ self |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
615 |
! |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
616 |
|
5755 | 617 |
veryDeepCopy |
8383 | 618 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 619 |
! ! |
620 |
||
7567 | 621 |
!Object methodsFor:'Compatibility-VW'! |
622 |
||
8637 | 623 |
isCharacters |
624 |
"added for visual works compatibility" |
|
625 |
^ false |
|
626 |
! |
|
627 |
||
7567 | 628 |
keyNotFoundError:aKey |
629 |
"VW compatibility" |
|
630 |
||
631 |
self errorKeyNotFound:aKey. |
|
632 |
! |
|
633 |
||
634 |
oneWayBecome:anotherObject |
|
635 |
^ self becomeSameAs:anotherObject |
|
636 |
||
637 |
" |
|
638 |
|arr o1 o2| |
|
639 |
||
640 |
arr := Array new:2. |
|
641 |
arr at:1 put:(o1 := Object new). |
|
642 |
arr at:2 put:(o2 := Point new). |
|
643 |
o1 oneWayBecome:o2. |
|
644 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
645 |
" |
|
646 |
" |
|
647 |
|arr o1 o2| |
|
648 |
||
649 |
arr := Array new:2. |
|
650 |
arr at:1 put:(o1 := Object new). |
|
651 |
arr at:2 put:(o2 := Point new). |
|
652 |
o1 becomeSameAs:o2. |
|
653 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
654 |
" |
|
655 |
! ! |
|
656 |
||
5755 | 657 |
!Object methodsFor:'accessing'! |
658 |
||
659 |
at:index |
|
660 |
"return the indexed instance variable with index, anInteger; |
|
661 |
this method can be redefined in subclasses." |
|
662 |
||
663 |
^ self basicAt:index |
|
664 |
! |
|
665 |
||
666 |
at:index put:anObject |
|
667 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
668 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
|
669 |
||
670 |
^ self basicAt:index put:anObject |
|
671 |
||
672 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
|
673 |
! |
|
674 |
||
675 |
basicAt:index |
|
676 |
"return the indexed instance variable with index, anInteger. |
|
677 |
Trigger an error if the receiver has no indexed instance variables. |
|
678 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
679 |
||
680 |
%{ /* NOCONTEXT */ |
|
681 |
||
682 |
REGISTER int nbytes, indx; |
|
683 |
OBJ myClass; |
|
684 |
REGISTER char *pFirst; |
|
685 |
REGISTER int n; |
|
686 |
||
687 |
/* |
|
688 |
* notice the missing test for self being a nonNilObject - |
|
689 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
690 |
* and SmallInteger |
|
691 |
*/ |
|
692 |
if (__isSmallInteger(index)) { |
|
10460 | 693 |
myClass = __qClass(self); |
694 |
indx = __intVal(index) - 1; |
|
695 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
696 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
697 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
698 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
699 |
||
700 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
701 |
case __MASKSMALLINT(POINTERARRAY): |
|
702 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
703 |
/* |
|
704 |
* pointers |
|
705 |
*/ |
|
706 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
707 |
OBJ *op; |
|
708 |
||
709 |
op = (OBJ *)pFirst + indx; |
|
710 |
RETURN ( *op ); |
|
711 |
} |
|
712 |
break; |
|
713 |
||
714 |
case __MASKSMALLINT(BYTEARRAY): |
|
715 |
/* |
|
716 |
* (unsigned) bytes |
|
717 |
*/ |
|
718 |
if ((unsigned)indx < nbytes) { |
|
719 |
unsigned char *cp; |
|
720 |
||
721 |
cp = (unsigned char *)pFirst + indx; |
|
722 |
RETURN ( __mkSmallInteger( (*cp & 0xFF)) ); |
|
723 |
} |
|
724 |
break; |
|
725 |
||
726 |
case __MASKSMALLINT(FLOATARRAY): |
|
727 |
/* |
|
728 |
* native floats |
|
729 |
*/ |
|
730 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
731 |
float *fp; |
|
732 |
float f; |
|
733 |
OBJ v; |
|
734 |
||
735 |
fp = (float *)pFirst + indx; |
|
736 |
f = *fp; |
|
737 |
if (f == 0.0) { |
|
738 |
v = __float0; |
|
739 |
} else { |
|
740 |
__qMKSFLOAT(v, f); |
|
741 |
} |
|
742 |
RETURN (v); |
|
743 |
} |
|
744 |
break; |
|
745 |
||
746 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
747 |
/* |
|
748 |
* native doubles |
|
749 |
*/ |
|
5755 | 750 |
#ifdef __NEED_DOUBLE_ALIGN |
10460 | 751 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
752 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
753 |
||
754 |
pFirst += delta; |
|
755 |
nbytes -= delta; |
|
756 |
} |
|
5755 | 757 |
#endif |
10460 | 758 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
759 |
double *dp; |
|
760 |
double d; |
|
761 |
OBJ v; |
|
762 |
||
763 |
dp = (double *)pFirst + indx; |
|
764 |
d = *dp; |
|
765 |
if (d == 0.0) { |
|
766 |
v = __float0; |
|
767 |
} else { |
|
768 |
__qMKFLOAT(v, d); |
|
769 |
} |
|
770 |
RETURN (v); |
|
771 |
} |
|
772 |
break; |
|
773 |
||
774 |
case __MASKSMALLINT(WORDARRAY): |
|
775 |
/* |
|
776 |
* unsigned 16bit ints |
|
777 |
*/ |
|
778 |
/* Notice: the hard coded shifts are by purpose; |
|
779 |
* it makes us independent of the short-size of the machine |
|
780 |
*/ |
|
781 |
if ((unsigned)indx < (nbytes>>1)) { |
|
782 |
unsigned short *sp; |
|
783 |
||
784 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
785 |
RETURN ( __mkSmallInteger( (*sp & 0xFFFF)) ); |
|
786 |
} |
|
787 |
break; |
|
788 |
||
789 |
case __MASKSMALLINT(SWORDARRAY): |
|
790 |
/* |
|
791 |
* signed 16bit ints |
|
792 |
*/ |
|
793 |
/* Notice: the hard coded shifts are by purpose; |
|
794 |
* it makes us independent of the short-size of the machine |
|
795 |
*/ |
|
796 |
if ((unsigned)indx < (nbytes>>1)) { |
|
797 |
short *ssp; |
|
798 |
||
799 |
ssp = (short *)(pFirst + (indx<<1)); |
|
800 |
RETURN ( __mkSmallInteger( (*ssp) )); |
|
801 |
} |
|
802 |
break; |
|
803 |
||
804 |
case __MASKSMALLINT(LONGARRAY): |
|
805 |
/* |
|
806 |
* unsigned 32bit ints |
|
807 |
*/ |
|
808 |
/* Notice: the hard coded shifts are by purpose; |
|
809 |
* it makes us independent of the int-size of the machine |
|
810 |
*/ |
|
811 |
if ((unsigned)indx < (nbytes>>2)) { |
|
812 |
unsigned int32 ul; |
|
813 |
unsigned int32 *lp; |
|
814 |
||
815 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
816 |
ul = *lp; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
817 |
#if __POINTER_SIZE__ == 8 |
10460 | 818 |
{ |
819 |
unsigned INT ull = (unsigned INT)ul; |
|
820 |
RETURN ( __mkSmallInteger(ull) ); |
|
821 |
} |
|
5755 | 822 |
#else |
10460 | 823 |
if (ul <= _MAX_INT) { |
824 |
RETURN ( __mkSmallInteger(ul) ); |
|
825 |
} |
|
826 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 827 |
#endif |
10460 | 828 |
} |
829 |
break; |
|
830 |
||
831 |
case __MASKSMALLINT(SLONGARRAY): |
|
832 |
/* |
|
833 |
* signed 32bit ints |
|
834 |
*/ |
|
835 |
/* Notice: the hard coded shifts are by purpose; |
|
836 |
* it makes us independent of the int-size of the machine |
|
837 |
*/ |
|
838 |
if ((unsigned)indx < (nbytes>>2)) { |
|
839 |
int32 *slp; |
|
840 |
int32 l; |
|
841 |
||
842 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
843 |
l = *slp; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
844 |
#if __POINTER_SIZE__ == 8 |
10460 | 845 |
{ |
846 |
INT ll = (INT)l; |
|
847 |
RETURN ( __mkSmallInteger(ll) ); |
|
848 |
} |
|
5755 | 849 |
#else |
10460 | 850 |
if (__ISVALIDINTEGER(l)) { |
851 |
RETURN ( __mkSmallInteger(l) ); |
|
852 |
} |
|
853 |
RETURN ( __MKLARGEINT(l) ); |
|
5755 | 854 |
#endif |
10460 | 855 |
} |
856 |
break; |
|
857 |
||
858 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
859 |
/* |
|
860 |
* signed 64bit longlongs |
|
861 |
*/ |
|
5755 | 862 |
#ifdef __NEED_LONGLONG_ALIGN |
10460 | 863 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
864 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
865 |
||
866 |
pFirst += delta; |
|
867 |
nbytes -= delta; |
|
868 |
} |
|
5755 | 869 |
#endif |
10460 | 870 |
/* Notice: the hard coded shifts are by purpose; |
871 |
* it makes us independent of the long/longlong-size of the machine |
|
872 |
*/ |
|
873 |
if ((unsigned)indx < (nbytes>>3)) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
874 |
#if __POINTER_SIZE__ == 8 |
10460 | 875 |
INT *slp, ll; |
876 |
||
877 |
slp = (INT *)(pFirst + (indx<<3)); |
|
878 |
ll = *slp; |
|
879 |
if (__ISVALIDINTEGER(ll)) { |
|
880 |
RETURN ( __mkSmallInteger(ll) ); |
|
881 |
} |
|
882 |
RETURN ( __MKLARGEINT(ll) ); |
|
5755 | 883 |
#else |
10460 | 884 |
__int64__ *llp; |
885 |
||
886 |
llp = (__int64__ *)(pFirst + (indx<<3)); |
|
887 |
RETURN (__MKINT64(llp)); |
|
5755 | 888 |
#endif |
10460 | 889 |
} |
890 |
break; |
|
891 |
||
892 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
893 |
/* |
|
894 |
* unsigned 64bit longlongs |
|
895 |
*/ |
|
5755 | 896 |
#ifdef __NEED_LONGLONG_ALIGN |
10460 | 897 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
898 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
899 |
||
900 |
pFirst += delta; |
|
901 |
nbytes -= delta; |
|
902 |
} |
|
5755 | 903 |
#endif |
10460 | 904 |
/* Notice: the hard coded shifts are by purpose; |
905 |
* it makes us independent of the long/longlong-size of the machine |
|
906 |
*/ |
|
907 |
if ((unsigned)indx < (nbytes>>3)) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
908 |
#if __POINTER_SIZE__ == 8 |
10460 | 909 |
unsigned INT *ulp, ul; |
910 |
||
911 |
ulp = (unsigned INT *)(pFirst + (indx<<3)); |
|
912 |
ul = *ulp; |
|
913 |
if (ul <= _MAX_INT) { |
|
914 |
RETURN ( __mkSmallInteger(ul) ); |
|
915 |
} |
|
916 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 917 |
#else |
10460 | 918 |
__uint64__ *llp; |
919 |
||
920 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
921 |
RETURN (__MKUINT64(llp)); |
|
5755 | 922 |
#endif |
10460 | 923 |
} |
924 |
break; |
|
925 |
} |
|
5755 | 926 |
} |
927 |
%}. |
|
7216 | 928 |
^ self indexNotIntegerOrOutOfBounds:index |
5755 | 929 |
! |
930 |
||
931 |
basicAt:index put:anObject |
|
932 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
933 |
Returns anObject (sigh). |
|
934 |
Trigger an error if the receiver has no indexed instance variables. |
|
935 |
||
936 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
937 |
||
938 |
%{ /* NOCONTEXT */ |
|
939 |
||
940 |
register int nbytes, indx; |
|
941 |
OBJ myClass; |
|
942 |
register char *pFirst; |
|
943 |
/* int nInstBytes, ninstvars, flags; */ |
|
944 |
REGISTER int n; |
|
945 |
unsigned int u; |
|
946 |
int val; |
|
947 |
||
948 |
/* notice the missing test for self being a nonNilObject - |
|
949 |
this can be done since basicAt: is defined both in UndefinedObject |
|
950 |
and SmallInteger */ |
|
951 |
||
952 |
if (__isSmallInteger(index)) { |
|
10460 | 953 |
indx = __intVal(index) - 1; |
954 |
myClass = __qClass(self); |
|
955 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
956 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
957 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
958 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
959 |
||
960 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
961 |
case __MASKSMALLINT(POINTERARRAY): |
|
962 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
963 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
964 |
OBJ *op; |
|
965 |
||
966 |
op = (OBJ *)pFirst + indx; |
|
967 |
*op = anObject; |
|
968 |
__STORE(self, anObject); |
|
969 |
RETURN ( anObject ); |
|
970 |
} |
|
971 |
break; |
|
972 |
||
973 |
case __MASKSMALLINT(BYTEARRAY): |
|
974 |
if (__isSmallInteger(anObject)) { |
|
975 |
val = __intVal(anObject); |
|
976 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
977 |
if ((unsigned)indx < nbytes) { |
|
978 |
char *cp; |
|
979 |
||
980 |
cp = pFirst + indx; |
|
981 |
*cp = val; |
|
982 |
RETURN ( anObject ); |
|
983 |
} |
|
984 |
} |
|
985 |
} |
|
986 |
break; |
|
987 |
||
988 |
case __MASKSMALLINT(FLOATARRAY): |
|
989 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
990 |
float *fp; |
|
991 |
||
992 |
fp = (float *)pFirst + indx; |
|
993 |
if (anObject != nil) { |
|
994 |
if (! __isSmallInteger(anObject)) { |
|
995 |
if (__qIsFloatLike(anObject)) { |
|
996 |
*fp = (float)(__floatVal(anObject)); |
|
997 |
RETURN ( anObject ); |
|
998 |
} |
|
999 |
if (__qIsShortFloat(anObject)) { |
|
1000 |
*fp = __shortFloatVal(anObject); |
|
1001 |
RETURN ( anObject ); |
|
1002 |
} |
|
1003 |
} else { |
|
1004 |
*fp = (float) __intVal(anObject); |
|
1005 |
RETURN ( anObject ); |
|
1006 |
} |
|
1007 |
} |
|
1008 |
} |
|
1009 |
break; |
|
1010 |
||
1011 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1012 |
#ifdef __NEED_DOUBLE_ALIGN |
10460 | 1013 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1014 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1015 |
||
1016 |
pFirst += delta; |
|
1017 |
nbytes -= delta; |
|
1018 |
} |
|
5755 | 1019 |
#endif |
10460 | 1020 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
1021 |
double *dp; |
|
1022 |
||
1023 |
dp = (double *)pFirst + indx; |
|
1024 |
if (anObject != nil) { |
|
1025 |
if (! __isSmallInteger(anObject)) { |
|
1026 |
if (__qIsFloatLike(anObject)) { |
|
1027 |
*dp = __floatVal(anObject); |
|
1028 |
RETURN ( anObject ); |
|
1029 |
} |
|
1030 |
if (__qIsShortFloat(anObject)) { |
|
1031 |
*dp = (double)__shortFloatVal(anObject); |
|
1032 |
RETURN ( anObject ); |
|
1033 |
} |
|
1034 |
} else { |
|
1035 |
*dp = (double) __intVal(anObject); |
|
1036 |
RETURN ( anObject ); |
|
1037 |
} |
|
1038 |
} |
|
1039 |
} |
|
1040 |
break; |
|
1041 |
||
1042 |
case __MASKSMALLINT(WORDARRAY): |
|
1043 |
if (__isSmallInteger(anObject)) { |
|
1044 |
val = __intVal(anObject); |
|
1045 |
if ((unsigned)val <= 0xFFFF) { |
|
1046 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1047 |
unsigned short *sp; |
|
1048 |
||
1049 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
1050 |
*sp = val; |
|
1051 |
RETURN ( anObject ); |
|
1052 |
} |
|
1053 |
} |
|
1054 |
} |
|
1055 |
break; |
|
1056 |
||
1057 |
case __MASKSMALLINT(SWORDARRAY): |
|
1058 |
if (__isSmallInteger(anObject)) { |
|
1059 |
val = __intVal(anObject); |
|
1060 |
if ((val >= -32768) && (val < 32768)) { |
|
1061 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1062 |
short *ssp; |
|
1063 |
||
1064 |
ssp = (short *)(pFirst + (indx<<1)); |
|
1065 |
*ssp = val; |
|
1066 |
RETURN ( anObject ); |
|
1067 |
} |
|
1068 |
} |
|
1069 |
} |
|
1070 |
break; |
|
1071 |
||
1072 |
case __MASKSMALLINT(SLONGARRAY): |
|
1073 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1074 |
int32 *slp; |
|
1075 |
||
1076 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
1077 |
if (__isSmallInteger(anObject)) { |
|
1078 |
*slp = __intVal(anObject); |
|
1079 |
RETURN ( anObject ); |
|
1080 |
} |
|
1081 |
n = __signedLongIntVal(anObject); |
|
1082 |
/* |
|
1083 |
* zero means failure for an int larger than 4 bytes |
|
1084 |
* (would be a smallInteger) |
|
1085 |
*/ |
|
1086 |
if (n) { |
|
1087 |
*slp = n; |
|
1088 |
RETURN ( anObject ); |
|
1089 |
} |
|
1090 |
} |
|
1091 |
break; |
|
1092 |
||
1093 |
case __MASKSMALLINT(LONGARRAY): |
|
1094 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1095 |
unsigned int32 *lp; |
|
1096 |
||
1097 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
1098 |
if (anObject == __mkSmallInteger(0)) { |
|
1099 |
*lp = 0; |
|
1100 |
RETURN ( anObject ); |
|
1101 |
} |
|
1102 |
u = __longIntVal(anObject); |
|
1103 |
/* |
|
1104 |
* zero means failure for an int larger than 4 bytes |
|
1105 |
* (would be a smallInteger) |
|
1106 |
*/ |
|
1107 |
if (u) { |
|
1108 |
*lp = u; |
|
1109 |
RETURN ( anObject ); |
|
1110 |
} |
|
1111 |
} |
|
1112 |
break; |
|
1113 |
||
1114 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1115 |
#ifdef __NEED_LONGLONG_ALIGN |
10460 | 1116 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1117 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1118 |
||
1119 |
pFirst += delta; |
|
1120 |
nbytes -= delta; |
|
1121 |
} |
|
5755 | 1122 |
#endif |
10460 | 1123 |
if ((unsigned)indx < (nbytes>>3)) { |
1124 |
__int64__ ll; |
|
1125 |
__int64__ *sllp; |
|
1126 |
||
1127 |
sllp = (__int64__ *)(pFirst + (indx<<3)); |
|
1128 |
||
1129 |
if (anObject == __mkSmallInteger(0)) { |
|
1130 |
ll.lo = ll.hi = 0; |
|
1131 |
*sllp = ll; |
|
1132 |
RETURN ( anObject ); |
|
1133 |
} |
|
1134 |
if (__signedLong64IntVal(anObject, &ll)) { |
|
1135 |
*sllp = ll; |
|
1136 |
RETURN ( anObject ); |
|
1137 |
} |
|
1138 |
} |
|
1139 |
break; |
|
1140 |
||
1141 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
5755 | 1142 |
#ifdef __NEED_LONGLONG_ALIGN |
10460 | 1143 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1144 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1145 |
||
1146 |
pFirst += delta; |
|
1147 |
nbytes -= delta; |
|
1148 |
} |
|
5755 | 1149 |
#endif |
10460 | 1150 |
if ((unsigned)indx < (nbytes>>3)) { |
1151 |
__uint64__ ll; |
|
1152 |
__uint64__ *llp; |
|
1153 |
||
1154 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
1155 |
if (anObject == __mkSmallInteger(0)) { |
|
1156 |
ll.lo = ll.hi = 0; |
|
1157 |
*llp = ll; |
|
1158 |
RETURN ( anObject ); |
|
1159 |
} |
|
1160 |
if (__unsignedLong64IntVal(anObject, &ll)) { |
|
1161 |
*llp = ll; |
|
1162 |
RETURN ( anObject ); |
|
1163 |
} |
|
1164 |
} |
|
1165 |
break; |
|
1166 |
} |
|
5755 | 1167 |
} |
1168 |
%}. |
|
1169 |
index isInteger ifFalse:[ |
|
10460 | 1170 |
" |
1171 |
the index should be an integer number |
|
1172 |
" |
|
1173 |
^ self indexNotInteger:index |
|
5755 | 1174 |
]. |
1175 |
(index between:1 and:self size) ifFalse:[ |
|
10460 | 1176 |
" |
1177 |
the index is less than 1 or greater than the size of the |
|
1178 |
receiver collection |
|
1179 |
" |
|
1180 |
^ self subscriptBoundsError:index |
|
5755 | 1181 |
]. |
1182 |
(self class isFloatsOrDoubles) ifTrue:[ |
|
10460 | 1183 |
anObject isNumber ifTrue:[ |
1184 |
^ self basicAt:index put:(anObject asFloat) |
|
1185 |
] |
|
5755 | 1186 |
]. |
1187 |
anObject isInteger ifFalse:[ |
|
10460 | 1188 |
" |
1189 |
the object to put into the receiver collection |
|
1190 |
should be an integer number |
|
1191 |
" |
|
1192 |
^ self elementNotInteger |
|
5755 | 1193 |
]. |
1194 |
" |
|
1195 |
the object to put into the receiver collection |
|
1196 |
is not an instance of the expected element class, |
|
1197 |
or the value is not within the elements valid range. |
|
1198 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1199 |
^ self elementBoundsError:anObject |
5755 | 1200 |
|
1201 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
|
1202 |
! |
|
1203 |
||
1204 |
byteAt:index |
|
10460 | 1205 |
"return the byte at index. |
5755 | 1206 |
This is only allowed for non-pointer indexed objects |
1207 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1208 |
The receivers indexed instvars are treated as an uninterpreted |
|
1209 |
collection of bytes. |
|
1210 |
Only useful with binary storage." |
|
1211 |
||
1212 |
%{ /* NOCONTEXT */ |
|
1213 |
||
1214 |
REGISTER int indx; |
|
1215 |
int nIndex; |
|
1216 |
REGISTER OBJ slf; |
|
1217 |
REGISTER OBJ cls; |
|
1218 |
||
1219 |
if (__isSmallInteger(index)) { |
|
10460 | 1220 |
slf = self; |
1221 |
if (__isNonNilObject(slf)) { |
|
1222 |
unsigned char *pFirst; |
|
1223 |
int nIndex; |
|
1224 |
||
1225 |
cls = __qClass(slf); |
|
1226 |
||
1227 |
pFirst = __byteArrayVal(slf); |
|
1228 |
pFirst += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1229 |
nIndex = __byteArraySize(slf); |
|
1230 |
indx = __intVal(index) - 1; |
|
1231 |
||
1232 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1233 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1234 |
#ifdef __NEED_DOUBLE_ALIGN |
10460 | 1235 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1236 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1237 |
||
1238 |
pFirst += delta; |
|
1239 |
nIndex -= delta; |
|
1240 |
} |
|
5755 | 1241 |
#endif |
10460 | 1242 |
/* fall into */ |
1243 |
case __MASKSMALLINT(BYTEARRAY): |
|
1244 |
case __MASKSMALLINT(WORDARRAY): |
|
1245 |
case __MASKSMALLINT(LONGARRAY): |
|
1246 |
case __MASKSMALLINT(SWORDARRAY): |
|
1247 |
case __MASKSMALLINT(SLONGARRAY): |
|
1248 |
case __MASKSMALLINT(FLOATARRAY): |
|
1249 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1250 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
|
1251 |
} |
|
1252 |
break; |
|
1253 |
||
1254 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1255 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1256 |
#ifdef __NEED_LONGLONG_ALIGN |
10460 | 1257 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1258 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1259 |
||
1260 |
pFirst += delta; |
|
1261 |
nIndex -= delta; |
|
1262 |
} |
|
5755 | 1263 |
#endif |
10460 | 1264 |
if ((unsigned)indx < (unsigned)nIndex) { |
1265 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
|
1266 |
} |
|
1267 |
break; |
|
1268 |
} |
|
1269 |
} |
|
5755 | 1270 |
} |
1271 |
%}. |
|
1272 |
"/ index not integer or index out of range |
|
1273 |
"/ or non-byte indexable receiver |
|
1274 |
||
1275 |
^ self primitiveFailed |
|
1276 |
||
1277 |
" |
|
1278 |
Point new byteAt:1 |
|
1279 |
(ByteArray with:1 with:2) byteAt:2 |
|
10460 | 1280 |
(WordArray with:1) byteAt:1 |
1281 |
(FloatArray with:1.0) byteAt:2 |
|
1282 |
'hello' byteAt:1 |
|
5755 | 1283 |
" |
1284 |
! |
|
1285 |
||
1286 |
byteAt:index put:byteValue |
|
10460 | 1287 |
"set the byte at index. |
5755 | 1288 |
This is only allowed for non-pointer indexed objects |
1289 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1290 |
The receivers indexed instvars are treated as an uninterpreted |
|
1291 |
collection of bytes. |
|
1292 |
Only useful with binary storage." |
|
1293 |
||
1294 |
%{ /* NOCONTEXT */ |
|
1295 |
||
1296 |
REGISTER int indx; |
|
1297 |
int val, nIndex; |
|
1298 |
REGISTER OBJ slf; |
|
1299 |
REGISTER OBJ cls; |
|
1300 |
||
1301 |
if (__bothSmallInteger(index, byteValue)) { |
|
10460 | 1302 |
val = __intVal(byteValue); |
1303 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
1304 |
slf = self; |
|
1305 |
if (__isNonNilObject(slf)) { |
|
1306 |
cls = __qClass(slf); |
|
1307 |
||
1308 |
indx = __intVal(index) - 1; |
|
1309 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1310 |
case __MASKSMALLINT(BYTEARRAY): |
|
1311 |
case __MASKSMALLINT(WORDARRAY): |
|
1312 |
case __MASKSMALLINT(LONGARRAY): |
|
1313 |
case __MASKSMALLINT(SWORDARRAY): |
|
1314 |
case __MASKSMALLINT(SLONGARRAY): |
|
1315 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1316 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1317 |
case __MASKSMALLINT(FLOATARRAY): |
|
1318 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
1319 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1320 |
nIndex = __byteArraySize(slf); |
|
1321 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1322 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
1323 |
RETURN ( byteValue ); |
|
1324 |
} |
|
1325 |
break; |
|
1326 |
} |
|
1327 |
} |
|
1328 |
} |
|
5755 | 1329 |
} |
1330 |
%}. |
|
1331 |
"/ index not integer or index out of range |
|
1332 |
"/ or non-byte indexable receiver |
|
1333 |
||
1334 |
^ self primitiveFailed |
|
1335 |
||
1336 |
" |
|
1337 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
|
10460 | 1338 |
'hello' copy byteAt:1 put:105; yourself |
5755 | 1339 |
" |
1340 |
! |
|
1341 |
||
1342 |
instVarAt:index |
|
1343 |
"return a non-indexed instance variable; |
|
10460 | 1344 |
peeking into an object this way is not very object oriented |
5755 | 1345 |
- use with care (needed for copy, inspector etc.)" |
1346 |
||
1347 |
%{ /* NOCONTEXT */ |
|
1348 |
||
1349 |
OBJ myClass; |
|
1350 |
int idx, ninstvars; |
|
1351 |
||
1352 |
if (__isSmallInteger(index)) { |
|
10460 | 1353 |
myClass = __Class(self); |
1354 |
idx = __intVal(index) - 1; |
|
1355 |
/* |
|
1356 |
* do not allow returning of non-object fields. |
|
1357 |
* if subclass did not make privisions for that, |
|
1358 |
* we wont do so here ... |
|
1359 |
*/ |
|
1360 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1361 |
if (idx == 0) { |
|
1362 |
RETURN ( nil ) |
|
1363 |
} |
|
1364 |
} |
|
1365 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1366 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1367 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
|
1368 |
} |
|
5755 | 1369 |
} |
7216 | 1370 |
%}. |
1371 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1372 |
! |
1373 |
||
1374 |
instVarAt:index put:value |
|
1375 |
"change a non-indexed instance variable; |
|
10460 | 1376 |
peeking into an object this way is not very object oriented |
5755 | 1377 |
- use with care (needed for copy, inspector etc.)" |
1378 |
||
1379 |
%{ /* NOCONTEXT */ |
|
1380 |
||
1381 |
OBJ myClass; |
|
1382 |
int idx, ninstvars; |
|
1383 |
||
1384 |
if (__isSmallInteger(index)) { |
|
10460 | 1385 |
myClass = __Class(self); |
1386 |
idx = __intVal(index) - 1; |
|
1387 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1388 |
/* |
|
1389 |
* do not allow setting of non-object fields. |
|
1390 |
* if subclass did not make privisions for that, |
|
1391 |
* we wont do so here ... |
|
1392 |
*/ |
|
1393 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1394 |
if (idx == 0) { |
|
1395 |
RETURN ( nil ) |
|
1396 |
} |
|
1397 |
} |
|
1398 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1399 |
__InstPtr(self)->i_instvars[idx] = value; |
|
1400 |
__STORE(self, value); |
|
1401 |
RETURN ( value ); |
|
1402 |
} |
|
5755 | 1403 |
} |
7216 | 1404 |
%}. |
1405 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1406 |
! |
1407 |
||
10460 | 1408 |
instVarNamed:name |
5755 | 1409 |
"return a non-indexed instance variables value by name; |
10460 | 1410 |
peeking into an object this way is not very object oriented |
5755 | 1411 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1412 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1413 |
parsed ad runtime)" |
|
1414 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1415 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1416 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1417 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1418 |
idx isNil ifTrue:[ |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1419 |
^ self errorKeyNotFound:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1420 |
]. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1421 |
^ self instVarAt:idx. |
5755 | 1422 |
|
1423 |
||
1424 |
" |
|
1425 |
|p| |
|
1426 |
||
1427 |
p := Point x:10 y:20. |
|
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1428 |
p instVarNamed:'cx' |
5755 | 1429 |
" |
1430 |
||
1431 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
|
1432 |
! |
|
1433 |
||
1434 |
instVarNamed:name ifAbsent:exceptionBlock |
|
1435 |
"return a non-indexed instance variables value by name, |
|
1436 |
or the value of exceptionBlock, if there is no such instance variable. |
|
10460 | 1437 |
peeking into an object this way is not very object oriented |
5755 | 1438 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1439 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1440 |
parsed ad runtime)" |
|
1441 |
||
1442 |
|idx| |
|
1443 |
||
1444 |
idx := self class instVarOffsetOf:name. |
|
1445 |
idx isNil ifTrue:[^ exceptionBlock value]. |
|
1446 |
^ self instVarAt:idx |
|
1447 |
||
1448 |
||
1449 |
" |
|
1450 |
|p| |
|
1451 |
||
1452 |
p := Point x:10 y:20. |
|
10460 | 1453 |
p instVarNamed:'x' |
5755 | 1454 |
" |
1455 |
||
1456 |
"Created: 6.7.1996 / 23:02:49 / cg" |
|
1457 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
|
1458 |
! |
|
1459 |
||
1460 |
instVarNamed:name put:value |
|
1461 |
"set a non-indexed instance variable by name; |
|
10460 | 1462 |
peeking into an object this way is not very object oriented |
5755 | 1463 |
- if at all, use with care (provided for protocol completeness). |
1464 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1465 |
parsed ad runtime)" |
|
1466 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1467 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1468 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1469 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1470 |
idx isNil ifTrue:[ |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1471 |
^ self errorKeyNotFound:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1472 |
]. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1473 |
^ self instVarAt:idx put:value. |
5755 | 1474 |
|
1475 |
" |
|
1476 |
|p| |
|
1477 |
||
1478 |
p := Point x:10 y:20. |
|
1479 |
p instVarNamed:'x' put:30. |
|
10460 | 1480 |
p |
5755 | 1481 |
" |
1482 |
||
1483 |
"Modified: 19.4.1996 / 11:12:49 / cg" |
|
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1484 |
! |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1485 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1486 |
instVarNamed:name put:anObject ifAbsent:exceptionBlock |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1487 |
"return a non-indexed instance variables value by name, |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1488 |
or the value of exceptionBlock, if there is no such instance variable. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1489 |
peeking into an object this way is not very object oriented |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1490 |
- use with care if at all (provided for inspectors and memory usage monitor). |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1491 |
Notice, this access is very slow (because the classes instVar-description has to be |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1492 |
parsed ad runtime)" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1493 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1494 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1495 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1496 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1497 |
idx isNil ifTrue:[^ exceptionBlock value]. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1498 |
^ self instVarAt:idx put:anObject. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1499 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1500 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1501 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1502 |
|p| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1503 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1504 |
p := Point x:10 y:20. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1505 |
p instVarNamed:'x' put:4711 ifAbsent:[self halt:'no such instvar']. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1506 |
p instVarNamed:'bla' put:4712 ifAbsent:[self halt:'no such instvar']. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1507 |
p inspect. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1508 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1509 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1510 |
"Created: 6.7.1996 / 23:02:49 / cg" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1511 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
5755 | 1512 |
! ! |
1513 |
||
1514 |
!Object methodsFor:'attributes access'! |
|
1515 |
||
10460 | 1516 |
objectAttributeAt:attributeKey |
5755 | 1517 |
"return the attribute for a given key or nil if not found" |
1518 |
||
1519 |
| attrs | |
|
1520 |
||
1521 |
attrs := self objectAttributes. |
|
1522 |
(attrs notNil and:[attrs size > 0]) ifTrue:[ |
|
10460 | 1523 |
^ attrs at:attributeKey ifAbsent:[] |
5755 | 1524 |
]. |
1525 |
^ nil |
|
1526 |
||
1527 |
"Created: / 22.1.1998 / 21:29:17 / av" |
|
1528 |
"Modified: / 3.2.1998 / 18:55:55 / cg" |
|
1529 |
! |
|
1530 |
||
6323 | 1531 |
objectAttributeAt:attributeKey put:anObject |
5755 | 1532 |
"store the attribute anObject referenced by key into the receiver" |
1533 |
||
1534 |
"/ must do this save from interrupts, since the attributes collection |
|
1535 |
"/ is possibly accessed from multiple threads ... |
|
1536 |
[ |
|
10460 | 1537 |
| attrs | |
1538 |
||
1539 |
attrs := self objectAttributes. |
|
1540 |
(attrs isNil or:[attrs size == 0]) ifTrue:[ |
|
1541 |
attrs := WeakIdentityDictionary new. |
|
1542 |
attrs at:attributeKey put:anObject. |
|
1543 |
self objectAttributes:attrs. |
|
1544 |
] ifFalse:[ |
|
1545 |
attrs at:attributeKey put:anObject. |
|
1546 |
]. |
|
6323 | 1547 |
] valueUninterruptably |
5755 | 1548 |
|
1549 |
"Attaching additional attributes (slots) to an arbitrary object: |
|
1550 |
||
1551 |
|p| |
|
1552 |
||
1553 |
p := Point new. |
|
1554 |
p objectAttributeAt:#color put:#green. |
|
1555 |
||
1556 |
p objectAttributeAt:#color |
|
1557 |
" |
|
1558 |
||
1559 |
"Created: / 22.1.1998 / 21:29:25 / av" |
|
1560 |
"Modified: / 3.2.1998 / 18:57:58 / cg" |
|
1561 |
! |
|
1562 |
||
1563 |
objectAttributes |
|
1564 |
"return a Collection of attributes - nil if there is none. |
|
1565 |
The default implementation here uses a global WeakDictionary to store |
|
1566 |
attributes |
|
1567 |
This may be too slow for high frequency slot access, |
|
1568 |
therefore, some classes may redefine this for better performance. |
|
1569 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
1570 |
||
1571 |
^ ObjectAttributes at:self ifAbsent:[nil] |
|
1572 |
||
1573 |
"Created: / 22.1.1998 / 21:29:30 / av" |
|
1574 |
"Modified: / 18.2.2000 / 11:34:16 / cg" |
|
1575 |
! |
|
1576 |
||
1577 |
objectAttributes:aCollection |
|
1578 |
"set the collection of attributes. |
|
1579 |
The default implementation here uses a global Dictionary to store |
|
1580 |
attributes which may be too slow for high frequency change&update. |
|
1581 |
Therefore, some classes may redefine this for better performance." |
|
1582 |
||
1583 |
"/ must do this save from interrupts, since the attributes collection |
|
1584 |
"/ is possibly accessed from multiple threads. |
|
1585 |
||
1586 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
10460 | 1587 |
"/ the common case - already blocked |
1588 |
||
1589 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
1590 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1591 |
] ifFalse:[ |
|
1592 |
ObjectAttributes at:self put:aCollection |
|
1593 |
]. |
|
1594 |
^ self |
|
5755 | 1595 |
]. |
1596 |
||
1597 |
[ |
|
10460 | 1598 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
1599 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1600 |
] ifFalse:[ |
|
1601 |
ObjectAttributes at:self put:aCollection |
|
1602 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
1603 |
] ensure:[ |
10460 | 1604 |
OperatingSystem unblockInterrupts |
5755 | 1605 |
] |
1606 |
||
1607 |
"Created: / 22.1.1998 / 21:29:35 / av" |
|
1608 |
"Modified: / 3.2.1998 / 18:58:10 / cg" |
|
1609 |
! |
|
1610 |
||
6323 | 1611 |
removeObjectAttribute:attributeKey |
5755 | 1612 |
"make the argument, anObject be no attribute of the receiver" |
1613 |
||
1614 |
"/ must do this save from interrupts, since the attributes collection |
|
1615 |
"/ is possibly accessed from multiple threads. |
|
1616 |
[ |
|
10460 | 1617 |
|attrs n a| |
1618 |
||
1619 |
attrs := self objectAttributes. |
|
1620 |
attrs size == 0 ifTrue:[ |
|
1621 |
self objectAttributes:nil |
|
1622 |
] ifFalse:[ |
|
1623 |
attrs removeKey:attributeKey ifAbsent:nil. |
|
1624 |
attrs size == 0 ifTrue:[ |
|
1625 |
self objectAttributes:nil |
|
1626 |
] |
|
1627 |
] |
|
6323 | 1628 |
] valueUninterruptably |
5755 | 1629 |
|
1630 |
"Created: / 22.1.1998 / 21:29:39 / av" |
|
1631 |
"Modified: / 18.2.2000 / 11:32:19 / cg" |
|
1632 |
! ! |
|
1633 |
||
11021 | 1634 |
|
5755 | 1635 |
!Object methodsFor:'change & update'! |
1636 |
||
1637 |
broadcast:aSelectorSymbol |
|
1638 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1639 |
||
10460 | 1640 |
self dependentsDo:[:dependent | |
1641 |
dependent perform:aSelectorSymbol |
|
5755 | 1642 |
] |
1643 |
! |
|
1644 |
||
1645 |
broadcast:aSelectorSymbol with:anArgument |
|
1646 |
"send a message with selector aSelectorSymbol with an additional |
|
1647 |
argument anArgument to all my dependents." |
|
1648 |
||
10460 | 1649 |
self dependentsDo:[:dependent | |
1650 |
dependent perform:aSelectorSymbol with:anArgument |
|
5755 | 1651 |
] |
1652 |
! |
|
1653 |
||
1654 |
changeRequest |
|
1655 |
"the receiver wants to change - check if all dependents |
|
1656 |
grant the request, and return true if so" |
|
1657 |
||
10460 | 1658 |
self dependentsDo:[:dependent | |
1659 |
dependent updateRequest ifFalse:[^ false]. |
|
5755 | 1660 |
]. |
1661 |
^ true |
|
1662 |
! |
|
1663 |
||
1664 |
changeRequest:aParameter |
|
1665 |
"the receiver wants to change - check if all dependents |
|
1666 |
grant the request, and return true if so" |
|
1667 |
||
10460 | 1668 |
self dependentsDo:[:dependent | |
1669 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
5755 | 1670 |
]. |
1671 |
^ true |
|
1672 |
! |
|
1673 |
||
1674 |
changeRequest:aParameter from:anObject |
|
1675 |
"the receiver wants to change - check if all dependents |
|
1676 |
except anObject grant the request, and return true if so. |
|
1677 |
The argument anObject is typically going to be the one who is |
|
1678 |
about to send the change request." |
|
1679 |
||
10460 | 1680 |
self dependentsDo:[:dependent | |
1681 |
dependent == anObject ifFalse:[ |
|
1682 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
1683 |
] |
|
5755 | 1684 |
]. |
1685 |
^ true |
|
1686 |
! |
|
1687 |
||
1688 |
changeRequestFrom:anObject |
|
1689 |
"the receiver wants to change - check if all dependents |
|
1690 |
except anObject grant the request, and return true if so. |
|
1691 |
The argument anObject is typically going to be the one who is |
|
1692 |
about to send the change request." |
|
1693 |
||
10460 | 1694 |
self dependentsDo:[:dependent | |
1695 |
dependent == anObject ifFalse:[ |
|
1696 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1697 |
] |
|
5755 | 1698 |
]. |
1699 |
^ true |
|
1700 |
! |
|
1701 |
||
1702 |
changed |
|
1703 |
"notify all dependents that the receiver has changed. |
|
1704 |
Each dependent gets a '#update:'-message with the original |
|
1705 |
receiver as argument." |
|
1706 |
||
1707 |
self changed:nil |
|
1708 |
! |
|
1709 |
||
1710 |
changed:aParameter |
|
1711 |
"notify all dependents that the receiver has changed somehow. |
|
1712 |
Each dependent gets a '#update:'-message with aParameter |
|
1713 |
as argument." |
|
1714 |
||
1715 |
self changed:aParameter with:nil |
|
1716 |
! |
|
1717 |
||
1718 |
changed:aParameter with:anArgument |
|
1719 |
"notify all dependents that the receiver has changed somehow. |
|
1720 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
|
1721 |
and anArgument as arguments." |
|
1722 |
||
10460 | 1723 |
self dependentsDo:[:dependent | |
1724 |
dependent update:aParameter with:anArgument from:self |
|
5755 | 1725 |
] |
1726 |
! |
|
1727 |
||
1728 |
update:aParameter |
|
1729 |
"the message is sent to a dependent, when one of the objects |
|
1730 |
on whom the receiver depends, has changed. The argument aParameter |
|
1731 |
is either the changed object or the argument to the #changed: message. |
|
1732 |
||
1733 |
Default behavior here is to do nothing" |
|
1734 |
||
1735 |
^ self |
|
1736 |
! |
|
1737 |
||
1738 |
update:aParameter with:anArgument |
|
1739 |
"dependent is notified of some change - |
|
1740 |
Default is to try update:" |
|
1741 |
||
1742 |
^ self update:aParameter |
|
1743 |
! |
|
1744 |
||
1745 |
update:aParameter with:anArgument from:sender |
|
1746 |
"dependent is notified of some change - |
|
1747 |
Default is to try update:with:" |
|
1748 |
||
1749 |
^ self update:aParameter with:anArgument |
|
1750 |
! |
|
1751 |
||
1752 |
updateRequest |
|
1753 |
"return true, if an update request is granted. |
|
1754 |
Default here is to grant updates - may be used |
|
1755 |
to lock updates if someone is making other changes |
|
1756 |
from within an update. Or if someone has locked its |
|
1757 |
state and does not want others to change things. |
|
1758 |
However, these dependents must all honor the |
|
1759 |
changeRequest - ifTrue - change protocol. I.e. they |
|
1760 |
must first ask all others via changeRequest, and only do the change |
|
1761 |
it returns true. The others must decide in updateRequest and |
|
1762 |
return true if they think a change is ok." |
|
1763 |
||
1764 |
^ true |
|
1765 |
! |
|
1766 |
||
1767 |
updateRequest:aSymbol |
|
1768 |
"return true, if an update request is granted. |
|
1769 |
Default here a simple updateRequest" |
|
1770 |
||
1771 |
^ self updateRequest |
|
7177 | 1772 |
! |
1773 |
||
1774 |
withoutUpdating:someone do:aBlock |
|
1775 |
"evaluate a block but remove someone from my dependents temporarily" |
|
1776 |
||
1777 |
(self dependents includesIdentical:someone) |
|
1778 |
ifFalse:[ |
|
10460 | 1779 |
^ aBlock value. |
7177 | 1780 |
]. |
1781 |
self removeDependent:someone. |
|
1782 |
^ aBlock ensure:[ self addDependent:someone ] |
|
5755 | 1783 |
! ! |
1784 |
||
1785 |
!Object methodsFor:'cleanup'! |
|
1786 |
||
1787 |
lowSpaceCleanup |
|
1788 |
"ignored here - redefined in some classes to |
|
1789 |
cleanup in low-memory situations" |
|
1790 |
||
1791 |
^ self |
|
1792 |
! ! |
|
1793 |
||
1794 |
!Object methodsFor:'comparing'! |
|
1795 |
||
1796 |
= anObject |
|
1797 |
"return true, if the receiver and the arg have the same structure. |
|
1798 |
Notice: |
|
10460 | 1799 |
This method is partially open coded (inlined) by the compiler(s) |
1800 |
identical objects are always considered equal. |
|
1801 |
redefining it may not work as expected." |
|
5755 | 1802 |
|
1803 |
^ self == anObject |
|
1804 |
! |
|
1805 |
||
1806 |
== anObject |
|
1807 |
"return true, if the receiver and the arg are the same object. |
|
1808 |
Never redefine this in any class. |
|
1809 |
Notice: |
|
10460 | 1810 |
This method is open coded (inlined) by the compiler(s) |
1811 |
- redefining it may not work as expected." |
|
5755 | 1812 |
|
1813 |
%{ /* NOCONTEXT */ |
|
1814 |
||
1815 |
RETURN ( (self == anObject) ? true : false ); |
|
1816 |
%} |
|
1817 |
! |
|
1818 |
||
5814 | 1819 |
deepSameContentsAs:anObject |
1820 |
"return true, if the receiver and the arg have the same contents |
|
1821 |
in both the named instance vars and any indexed instVars. |
|
1822 |
This method descends into referenced objects, where #sameContentsAs: does not descend" |
|
1823 |
||
5821 | 1824 |
|myClass val |
5814 | 1825 |
sz "{ Class: SmallInteger }" | |
1826 |
||
1827 |
myClass := self class. |
|
1828 |
myClass isVariable ifTrue:[ |
|
10460 | 1829 |
sz := self basicSize. |
1830 |
||
1831 |
"compare the indexed variables" |
|
1832 |
1 to:sz do:[:i | |
|
1833 |
val := self basicAt:i. |
|
1834 |
val isLiteral ifTrue:[ |
|
1835 |
val = (anObject basicAt:i) ifFalse:[^ false]. |
|
1836 |
] ifFalse:[ |
|
1837 |
(val deepSameContentsAs:(anObject basicAt:i)) ifFalse:[^ false]. |
|
1838 |
] |
|
1839 |
] |
|
5814 | 1840 |
]. |
1841 |
||
1842 |
"compare the instance variables" |
|
1843 |
sz := myClass instSize. |
|
10460 | 1844 |
1 to:sz do:[:i | |
1845 |
val := self instVarAt:i. |
|
1846 |
val isLiteral ifTrue:[ |
|
1847 |
val = (anObject instVarAt:i) ifFalse:[^ false]. |
|
1848 |
] ifFalse:[ |
|
1849 |
(val deepSameContentsAs:(anObject instVarAt:i)) ifFalse:[^ false]. |
|
1850 |
] |
|
5814 | 1851 |
]. |
1852 |
||
1853 |
^ true |
|
1854 |
||
1855 |
" |
|
10460 | 1856 |
#(1 2 3 4) deepSameContentsAs:#[1 2 3 4] asArray |
5814 | 1857 |
(1@2) deepSameContentsAs:(1->2) |
1858 |
" |
|
1859 |
! |
|
1860 |
||
5755 | 1861 |
hash |
1862 |
"return an Integer useful as a hash key for the receiver. |
|
1863 |
This hash should return same values for objects with same |
|
1864 |
contents (i.e. use this to hash on structure)" |
|
1865 |
||
1866 |
^ self identityHash |
|
1867 |
! |
|
1868 |
||
1869 |
identityHash |
|
1870 |
"return an Integer useful as a hash key for the receiver. |
|
1871 |
This hash should return same values for the same object (i.e. use |
|
1872 |
this to hash on identity of objects). |
|
1873 |
||
1874 |
We cannot use the Objects address (as other smalltalks do) since |
|
1875 |
no object-table exists and the hashval must not change when objects |
|
1876 |
are moved by the collector. Therefore we assign each object a unique |
|
1877 |
Id in the object header itself as its hashed upon. |
|
1878 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
1879 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
1880 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
1881 |
hashed-upon objects could add an instvar containing the hash value." |
|
1882 |
||
1883 |
%{ /* NOCONTEXT */ |
|
1884 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1885 |
REGISTER unsigned INT hash; |
5755 | 1886 |
static unsigned nextHash = 0; |
1887 |
||
1888 |
if (__isNonNilObject(self)) { |
|
10460 | 1889 |
hash = __GET_HASH(self); |
1890 |
if (hash == 0) { |
|
1891 |
/* has no hash yet */ |
|
1892 |
||
1893 |
if (++nextHash > __MAX_HASH__) { |
|
1894 |
nextHash = 1; |
|
1895 |
} |
|
1896 |
hash = nextHash; |
|
1897 |
__SET_HASH(self, hash); |
|
1898 |
} |
|
1899 |
||
1900 |
/* |
|
1901 |
* now, we got 11 bits for hashing; |
|
1902 |
* make it as large as possible; since most hashers use the returned |
|
1903 |
* key and take it modulo some prime number, this will allow for |
|
1904 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
1905 |
*/ |
|
1906 |
hash = __MAKE_HASH__(hash); |
|
1907 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 1908 |
} |
1909 |
%}. |
|
1910 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
1911 |
! |
|
1912 |
||
1913 |
identityHashForBinaryStore |
|
1914 |
"hash which is usable if the object does not change its class |
|
1915 |
and does not #become something else, while the hash is used. |
|
1916 |
This is only used by the binary storage mechanism, during the |
|
1917 |
object writing phase." |
|
1918 |
||
1919 |
%{ /* NOCONTEXT */ |
|
1920 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1921 |
REGISTER unsigned INT hash, hash1, hash2, sz; |
5755 | 1922 |
OBJ o; |
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1923 |
static unsigned INT nextHash = 0; |
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1924 |
static unsigned INT nextClassHash = 0; |
5755 | 1925 |
|
1926 |
if (__isNonNilObject(self)) { |
|
10460 | 1927 |
/* |
1928 |
* my own identityHash |
|
1929 |
*/ |
|
1930 |
hash1 = __GET_HASH(self); |
|
1931 |
if (hash1 == 0) { |
|
1932 |
/* has no hash yet */ |
|
1933 |
||
1934 |
if (++nextHash > __MAX_HASH__) { |
|
1935 |
nextHash = 1; |
|
1936 |
} |
|
1937 |
hash1 = nextHash; |
|
1938 |
__SET_HASH(self, hash1); |
|
1939 |
} |
|
1940 |
/* |
|
1941 |
* my classes identityHash |
|
1942 |
*/ |
|
1943 |
o = __qClass(self); |
|
1944 |
hash2 = __GET_HASH(o); |
|
1945 |
if (hash2 == 0) { |
|
1946 |
/* has no hash yet */ |
|
1947 |
||
1948 |
if (++nextClassHash > __MAX_HASH__) { |
|
1949 |
nextClassHash = 1; |
|
1950 |
} |
|
1951 |
hash2 = nextClassHash; |
|
1952 |
__SET_HASH(o, hash2); |
|
1953 |
} |
|
1954 |
||
1955 |
/* |
|
1956 |
* some bits of my size |
|
1957 |
*/ |
|
1958 |
sz = __qSize(self); |
|
1959 |
||
1960 |
/* |
|
1961 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
1962 |
* make it as large as possible; since most hashers use the returned |
|
1963 |
* key and take it modulo some prime number, this will allow for |
|
1964 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
1965 |
*/ |
|
1966 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
1967 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
1968 |
||
1969 |
while ((hash & 0x20000000) == 0) { |
|
1970 |
hash <<= 1; |
|
1971 |
} |
|
1972 |
||
1973 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 1974 |
} |
1975 |
%}. |
|
1976 |
"never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
|
1977 |
^ self identityHash |
|
1978 |
! |
|
1979 |
||
1980 |
sameContentsAs:anObject |
|
1981 |
"return true, if the receiver and the arg have the same contents |
|
7121 | 1982 |
in both the named instance vars and any indexed instVars. |
1983 |
The code here only checks if values present in the receiver are also |
|
1984 |
present in the arg, not vice versa. |
|
1985 |
I.e. the argument may be bigger and/or have more instance variables." |
|
5755 | 1986 |
|
5821 | 1987 |
|myClass |
5755 | 1988 |
sz "{ Class: SmallInteger }" | |
1989 |
||
1990 |
myClass := self class. |
|
1991 |
myClass isVariable ifTrue:[ |
|
10460 | 1992 |
sz := self basicSize. |
1993 |
anObject basicSize >= sz ifFalse:[^ false]. |
|
1994 |
||
1995 |
"compare the indexed variables" |
|
1996 |
1 to:sz do:[:i | |
|
1997 |
(self basicAt:i) == (anObject basicAt:i) ifFalse:[^ false]. |
|
1998 |
] |
|
5755 | 1999 |
]. |
2000 |
||
2001 |
"compare the instance variables" |
|
2002 |
sz := myClass instSize. |
|
7121 | 2003 |
anObject instSize >= sz ifFalse:[^ false]. |
2004 |
||
10460 | 2005 |
1 to:sz do:[:i | |
2006 |
(self instVarAt:i) == (anObject instVarAt:i) ifFalse:[^ false]. |
|
5755 | 2007 |
]. |
2008 |
||
2009 |
^ true |
|
2010 |
||
2011 |
" |
|
10460 | 2012 |
#(1 2 3 4) sameContentsAs:#[1 2 3 4] asArray |
5814 | 2013 |
(1@2) sameContentsAs:(1->2) |
5755 | 2014 |
" |
2015 |
||
2016 |
"Created: / 21.4.1998 / 15:56:40 / cg" |
|
2017 |
"Modified: / 21.4.1998 / 15:58:15 / cg" |
|
2018 |
! |
|
2019 |
||
2020 |
~= anObject |
|
2021 |
"return true, if the receiver and the arg do not have the same structure. |
|
2022 |
Notice: |
|
10460 | 2023 |
This method is partially open coded (inlined) by the compiler(s) |
2024 |
identical objects are never considered unequal. |
|
2025 |
redefining it may not work as expected." |
|
5755 | 2026 |
|
2027 |
^ (self = anObject) not |
|
2028 |
! |
|
2029 |
||
2030 |
~~ anObject |
|
2031 |
"return true, if the receiver and the arg are not the same object. |
|
2032 |
Never redefine this in any class. |
|
2033 |
Notice: |
|
10460 | 2034 |
This method is open coded (inlined) by the compiler(s) |
2035 |
- redefining it may not work as expected." |
|
5755 | 2036 |
|
2037 |
%{ /* NOCONTEXT */ |
|
2038 |
RETURN ( (self == anObject) ? false : true ); |
|
2039 |
%} |
|
2040 |
! ! |
|
2041 |
||
2042 |
!Object methodsFor:'converting'! |
|
2043 |
||
2044 |
-> anObject |
|
2045 |
"return an association with the receiver as key and |
|
2046 |
the argument as value" |
|
2047 |
||
2048 |
^ Association key:self value:anObject |
|
2049 |
! |
|
2050 |
||
10062 | 2051 |
as:aSimilarClass |
2052 |
"If the receivers class is not aSimilarClass, |
|
10460 | 2053 |
create and return an object of class aSimilarClass that has the same contents |
10062 | 2054 |
as the receiver. |
2055 |
Otherwise, return the receiver." |
|
2056 |
||
2057 |
self class == aSimilarClass ifTrue:[^ self]. |
|
2058 |
^ aSimilarClass newFrom:self |
|
2059 |
||
2060 |
" |
|
2061 |
#[1 2 3 4] as:ByteArray |
|
2062 |
#[1 2 3 4] as:Array |
|
10539 | 2063 |
#[81 82 83 84] as:String |
2064 |
#[81 82 83 84] as:Symbol |
|
10062 | 2065 |
" |
2066 |
! |
|
2067 |
||
5755 | 2068 |
asCollection |
2069 |
"return myself as a Collection. |
|
2070 |
Redefined in collection to return themself." |
|
2071 |
||
2072 |
^ Array with:self |
|
2073 |
! |
|
2074 |
||
2075 |
asSequenceableCollection |
|
2076 |
"return myself as a SequenceableCollection. |
|
2077 |
Redefined in SequenceableCollection" |
|
2078 |
||
2079 |
^ Array with:self |
|
2080 |
! |
|
2081 |
||
2082 |
asValue |
|
2083 |
"return a valueHolder for for the receiver" |
|
2084 |
||
2085 |
^ ValueHolder with:self |
|
6146 | 2086 |
! |
2087 |
||
2088 |
collect |
|
2089 |
"return mySelf" |
|
2090 |
||
2091 |
^ self |
|
2092 |
! |
|
2093 |
||
2094 |
deepCollect |
|
2095 |
"return mySelf" |
|
2096 |
||
2097 |
^ self |
|
2098 |
! |
|
2099 |
||
2100 |
deepSelect |
|
2101 |
"return mySelf" |
|
2102 |
||
2103 |
^ self |
|
2104 |
! |
|
2105 |
||
2106 |
select |
|
2107 |
"return mySelf" |
|
2108 |
||
2109 |
^ self |
|
5755 | 2110 |
! ! |
2111 |
||
2112 |
!Object methodsFor:'copying'! |
|
2113 |
||
10460 | 2114 |
cloneFrom:anObject |
5755 | 2115 |
"Helper for copy: |
2116 |
copy all instance variables from anObject into the receiver, |
|
2117 |
which should be of the same class as the argument." |
|
2118 |
||
2119 |
self cloneFrom:anObject performing:#yourself |
|
2120 |
||
2121 |
" |
|
2122 |
|x| |
|
2123 |
||
2124 |
x := Array new:3. |
|
2125 |
x cloneFrom:#(1 2 3). |
|
2126 |
" |
|
2127 |
! |
|
2128 |
||
2129 |
cloneFrom:anObject performing:aSymbol |
|
2130 |
"Helper for copy: |
|
8383 | 2131 |
for each instance variable from anObject, send it aSymbol |
5755 | 2132 |
and store the result into the receiver, |
2133 |
which should be of the same class as the argument." |
|
2134 |
||
2135 |
|myClass sz "{ Class: SmallInteger }" t | |
|
2136 |
||
2137 |
myClass := self class. |
|
2138 |
myClass isVariable ifTrue:[ |
|
10460 | 2139 |
sz := self basicSize. |
2140 |
||
2141 |
"process the indexed instance variables" |
|
2142 |
1 to:sz do:[:i | |
|
2143 |
t := anObject basicAt:i. |
|
2144 |
aSymbol ~~ #yourself ifTrue:[ |
|
2145 |
t := t perform:aSymbol. |
|
2146 |
]. |
|
2147 |
self basicAt:i put:t. |
|
2148 |
] |
|
5755 | 2149 |
]. |
2150 |
||
8383 | 2151 |
"process the named instance variables" |
5755 | 2152 |
sz := myClass instSize. |
10460 | 2153 |
1 to:sz do:[:i | |
2154 |
t := anObject instVarAt:i. |
|
2155 |
aSymbol ~~ #yourself ifTrue:[ |
|
2156 |
t := t perform:aSymbol |
|
2157 |
]. |
|
2158 |
self instVarAt:i put:t |
|
5755 | 2159 |
]. |
2160 |
||
2161 |
^ self |
|
2162 |
! |
|
2163 |
||
2164 |
cloneInstanceVariablesFrom:aPrototype |
|
2165 |
"Shallow copy variables from a prototype into myself. |
|
2166 |
This copies instVars by name - i.e. same-named variables are |
|
2167 |
copied, others are not. |
|
10460 | 2168 |
The variable slots are copied as available |
5755 | 2169 |
(i.e. the min of both indexed sizes is used)." |
10460 | 2170 |
|
5755 | 2171 |
|myInfo otherInfo| |
2172 |
||
2173 |
myInfo := self class instanceVariableOffsets. |
|
2174 |
otherInfo := aPrototype class instanceVariableOffsets. |
|
2175 |
myInfo keysAndValuesDo:[:name :index | |varIndexAssoc| |
|
10460 | 2176 |
varIndexAssoc := otherInfo at:name ifAbsent:[]. |
2177 |
varIndexAssoc notNil ifTrue:[ |
|
2178 |
self instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
2179 |
] |
|
5755 | 2180 |
]. |
2181 |
self isVariable ifTrue:[ |
|
10460 | 2182 |
1 to:(self basicSize min:aPrototype basicSize) do:[:index | |
2183 |
self basicAt:index put:(aPrototype basicAt:index) |
|
2184 |
]. |
|
5755 | 2185 |
]. |
2186 |
||
2187 |
" |
|
2188 |
Class withoutUpdatingChangesDo:[ |
|
10460 | 2189 |
Point subclass:#Point3D |
2190 |
instanceVariableNames:'z' |
|
2191 |
classVariableNames:'' |
|
2192 |
poolDictionaries:'' |
|
2193 |
category:'testing'. |
|
2194 |
(Point3D new cloneInstanceVariablesFrom:1@2) inspect. |
|
5755 | 2195 |
] |
2196 |
" |
|
2197 |
||
2198 |
" |
|
2199 |
Class withoutUpdatingChangesDo:[ |
|
10460 | 2200 |
Point variableSubclass:#Point3D |
2201 |
instanceVariableNames:'z' |
|
2202 |
classVariableNames:'' |
|
2203 |
poolDictionaries:'' |
|
2204 |
category:'testing'. |
|
2205 |
((Point3D new:2) cloneInstanceVariablesFrom:#(1 2 3)) inspect. |
|
5755 | 2206 |
] |
2207 |
" |
|
2208 |
||
2209 |
" |
|
2210 |
|someObject| |
|
2211 |
||
2212 |
Class withoutUpdatingChangesDo:[ |
|
10460 | 2213 |
Object subclass:#TestClass1 |
2214 |
instanceVariableNames:'foo bar' |
|
2215 |
classVariableNames:'' |
|
2216 |
poolDictionaries:'' |
|
2217 |
category:'testing'. |
|
2218 |
someObject := TestClass1 new. |
|
2219 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
2220 |
Object subclass:#TestClass2 |
|
2221 |
instanceVariableNames:'bar foo' |
|
2222 |
classVariableNames:'' |
|
2223 |
poolDictionaries:'' |
|
2224 |
category:'testing'. |
|
2225 |
(TestClass2 new cloneInstanceVariablesFrom:someObject) inspect. |
|
5755 | 2226 |
] |
2227 |
" |
|
2228 |
||
2229 |
" |
|
2230 |
|top b b1| |
|
2231 |
||
2232 |
top := StandardSystemView new. |
|
2233 |
top extent:100@100. |
|
2234 |
||
2235 |
b := Button in:top. |
|
2236 |
b label:'hello'. |
|
2237 |
||
2238 |
b1 := ArrowButton new cloneInstanceVariablesFrom:b. |
|
2239 |
||
2240 |
top open. |
|
2241 |
b1 inspect |
|
2242 |
" |
|
2243 |
! |
|
2244 |
||
2245 |
copy |
|
2246 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
2247 |
Notice, that copy does not copy dependents." |
|
2248 |
||
2249 |
^ self shallowCopy postCopy |
|
2250 |
! |
|
2251 |
||
6146 | 2252 |
copyToLevel:level |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2253 |
"a controlled deepCopy, where the number of levels can be specified. |
10460 | 2254 |
Notice: |
2255 |
This method DOES NOT handle cycles/self-refs and does NOT preserve object identity; |
|
2256 |
i.e. identical references in the source are copied multiple times into the copy." |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2257 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2258 |
|newObject class index| |
6146 | 2259 |
|
2260 |
level == 1 ifTrue:[^ self shallowCopy]. |
|
2261 |
||
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2262 |
class := self class. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2263 |
newObject := self clone. |
6146 | 2264 |
newObject == self ifTrue: [^ self]. |
10460 | 2265 |
class isVariable ifTrue:[ |
2266 |
index := self basicSize. |
|
2267 |
[index > 0] whileTrue:[ |
|
2268 |
newObject basicAt: index put: ((self basicAt: index) copyToLevel:(level-1)). |
|
2269 |
index := index - 1 |
|
2270 |
] |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2271 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2272 |
index := class instSize. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2273 |
[index > 0] whileTrue:[ |
10460 | 2274 |
newObject instVarAt: index put: ((self instVarAt: index) copyToLevel:(level-1)). |
2275 |
index := index - 1 |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2276 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2277 |
^ newObject |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2278 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2279 |
" |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2280 |
|a b| |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2281 |
|
10460 | 2282 |
a := #( |
2283 |
'1.1' |
|
2284 |
'1.2' |
|
2285 |
'1.3' |
|
2286 |
( |
|
2287 |
'1.41' |
|
2288 |
'1.42' |
|
2289 |
'1.43' |
|
2290 |
( |
|
2291 |
'1.441' |
|
2292 |
'1.442' |
|
2293 |
'1.443' |
|
2294 |
( '1.4441' '1.4442' '1.4443' ) |
|
2295 |
'1.445' |
|
2296 |
) |
|
2297 |
'1.45' |
|
2298 |
) |
|
2299 |
'1.5' |
|
2300 |
). |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2301 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2302 |
b := a copyToLevel:1. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2303 |
self assert: ( (a at:1) == (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2304 |
self assert: ( (a at:4) == (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2305 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2306 |
b := a copyToLevel:2. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2307 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2308 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2309 |
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
|
2310 |
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
|
2311 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2312 |
b := a copyToLevel:3. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2313 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2314 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2315 |
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
|
2316 |
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
|
2317 |
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
|
2318 |
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
|
2319 |
" |
6146 | 2320 |
! |
2321 |
||
5755 | 2322 |
deepCopy |
2323 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2324 |
This method DOES handle cycles/self-refs and preserves object identity; |
5755 | 2325 |
however the receivers class is not copied (to avoid the 'total' copy). |
2326 |
||
2327 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
2328 |
keeps track of already copied objects. If you are sure, that your |
|
2329 |
copied object does not include duplicates (or you do not care) and |
|
10460 | 2330 |
no cycles are involved, you can use the old simpleDeepCopy, |
5755 | 2331 |
which avoids this overhead (but may run into trouble). |
2332 |
Notice, that deepCopy does not copy dependents." |
|
2333 |
||
8383 | 2334 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 2335 |
|
2336 |
"an example which is not handled by the old deepCopy: |
|
10460 | 2337 |
|
5755 | 2338 |
|a| |
2339 |
a := Array new:3. |
|
2340 |
a at:3 put:a. |
|
2341 |
a deepCopy inspect |
|
2342 |
" |
|
2343 |
||
2344 |
" |
|
2345 |
|a| |
|
2346 |
a := Color black onDevice:Screen current. |
|
2347 |
a deepCopy inspect |
|
2348 |
" |
|
2349 |
||
2350 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
2351 |
! |
|
2352 |
||
2353 |
deepCopyError |
|
2354 |
"{ Pragma: +optSpace }" |
|
2355 |
||
2356 |
"raise a signal, that deepCopy is not allowed for this object" |
|
2357 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
2358 |
^ DeepCopyError raise |
5755 | 2359 |
! |
2360 |
||
2361 |
deepCopyUsing:aDictionary |
|
10460 | 2362 |
"a helper for deepCopy; return a copy of the object with |
2363 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
5755 | 2364 |
use the value found there. The class of the receiver is not copied. |
2365 |
This method DOES handle cycles/self references." |
|
2366 |
||
10941 | 2367 |
^ self deepCopyUsing:aDictionary postCopySelector:#postDeepCopyFrom:. |
2368 |
||
5755 | 2369 |
|
2370 |
" |
|
2371 |
|a b c copyOfC| |
|
2372 |
||
2373 |
a := Array with:'hello' with:'world' with:nil. |
|
2374 |
b := 99 @ 999. |
|
2375 |
a at:3 put:b. |
|
2376 |
c := Array with:a with:b with:a. |
|
2377 |
||
2378 |
Transcript showCR: (c at:1) == (c at:3). |
|
2379 |
copyOfC := c deepCopy. |
|
2380 |
Transcript showCR: (copyOfC at:1) == (copyOfC at:3) |
|
2381 |
" |
|
2382 |
! |
|
2383 |
||
10954 | 2384 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
2385 |
"a helper for deepCopy; return a copy of the object with |
|
2386 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
2387 |
use the value found there. The class of the receiver is not copied. |
|
2388 |
This method DOES handle cycles/self references." |
|
2389 |
||
2390 |
|myClass aCopy |
|
2391 |
sz "{ Class: SmallInteger }" |
|
2392 |
iOrig iCopy| |
|
2393 |
||
2394 |
myClass := self class. |
|
2395 |
"/ (myClass whichClassImplements:#deepCopyUsing:) ~~ Object ifTrue:[ |
|
2396 |
"/ ^ self deepCopyUsing:aDictionary. |
|
2397 |
"/ ]. |
|
2398 |
||
2399 |
myClass isVariable ifTrue:[ |
|
2400 |
sz := self basicSize. |
|
2401 |
aCopy := myClass basicNew:sz. |
|
2402 |
] ifFalse:[ |
|
2403 |
sz := 0. |
|
2404 |
aCopy := myClass basicNew |
|
2405 |
]. |
|
2406 |
aCopy setHashFrom:self. |
|
2407 |
aDictionary at:self put:aCopy. |
|
2408 |
||
2409 |
" |
|
2410 |
copy indexed instvars - if any |
|
2411 |
" |
|
2412 |
sz ~~ 0 ifTrue:[ |
|
2413 |
myClass isBits ifTrue:[ |
|
2414 |
"block-copy indexed instvars" |
|
2415 |
aCopy replaceFrom:1 to:sz with:self startingAt:1 |
|
2416 |
] ifFalse:[ |
|
2417 |
"individual deep copy the indexed variables" |
|
2418 |
1 to:sz do:[:i | |
|
2419 |
iOrig := self basicAt:i. |
|
2420 |
iOrig notNil ifTrue:[ |
|
2421 |
"/ used to be dict-includesKey-ifTrue[dict-at:], |
|
2422 |
"/ changed to use dict-at:ifAbsent:, to avoid double lookup in dictionary |
|
2423 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2424 |
iCopy isNil ifTrue:[ |
|
2425 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2426 |
]. |
|
2427 |
aCopy basicAt:i put:iCopy |
|
2428 |
] |
|
2429 |
] |
|
2430 |
] |
|
2431 |
]. |
|
2432 |
||
2433 |
" |
|
2434 |
copy the instance variables |
|
2435 |
" |
|
2436 |
sz := myClass instSize. |
|
2437 |
1 to:sz do:[:i | |
|
2438 |
(self skipInstvarIndexInDeepCopy:i) ifFalse:[ |
|
2439 |
iOrig := self instVarAt:i. |
|
2440 |
iOrig notNil ifTrue:[ |
|
2441 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2442 |
iCopy isNil ifTrue:[ |
|
2443 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2444 |
]. |
|
2445 |
aCopy instVarAt:i put:iCopy |
|
2446 |
] |
|
2447 |
] |
|
2448 |
]. |
|
2449 |
aCopy perform:postCopySelector with:self "ifNotUnderstood:[]". |
|
2450 |
^ aCopy |
|
2451 |
! |
|
2452 |
||
5755 | 2453 |
postCopy |
2454 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
2455 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
2456 |
(see there)" |
|
2457 |
||
2458 |
^ self |
|
2459 |
! |
|
2460 |
||
2461 |
postDeepCopy |
|
8930
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2462 |
"allows for cleanup after deep copying. |
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2463 |
To be redefined in subclasses." |
5755 | 2464 |
! |
2465 |
||
2466 |
postDeepCopyFrom:aSource |
|
2467 |
"allows for cleanup after deep copying" |
|
2468 |
||
2469 |
^ self postDeepCopy |
|
2470 |
! |
|
2471 |
||
2472 |
setHashFrom:anObject |
|
10460 | 2473 |
"set my identity-hash key to be the same as anObjects hash key. |
2474 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
5755 | 2475 |
Smalltalks, and may not be available in future ST/X versions. |
2476 |
DO NEVER use this for normal application code." |
|
2477 |
||
2478 |
%{ /* NOCONTEXT */ |
|
2479 |
||
2480 |
REGISTER unsigned h; |
|
2481 |
||
2482 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
10460 | 2483 |
h = __GET_HASH(anObject); |
2484 |
__SET_HASH(self, h); |
|
2485 |
RETURN (self); |
|
5755 | 2486 |
} |
2487 |
%}. |
|
2488 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
2489 |
! |
|
2490 |
||
2491 |
shallowCopy |
|
2492 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2493 |
i.e. the copy shares referenced instvars with its original." |
|
2494 |
||
2495 |
%{ /* NOCONTEXT */ |
|
2496 |
int ninsts, spc; |
|
2497 |
int sz; |
|
2498 |
OBJ theCopy; |
|
2499 |
OBJ cls; |
|
2500 |
int flags; |
|
2501 |
||
2502 |
cls = __qClass(self); |
|
2503 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
2504 |
||
2505 |
/* |
|
2506 |
* bail out for special objects .. |
|
2507 |
*/ |
|
2508 |
if (((flags & ~ARRAYMASK) == 0) |
|
2509 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
10460 | 2510 |
sz = __qSize(self); |
2511 |
__PROTECT__(self); |
|
2512 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
2513 |
__UNPROTECT__(self); |
|
2514 |
if (theCopy) { |
|
2515 |
cls = __qClass(self); |
|
2516 |
spc = __qSpace(theCopy); |
|
2517 |
||
2518 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
2519 |
||
2520 |
sz = sz - OHDR_SIZE; |
|
2521 |
if (sz) { |
|
2522 |
char *src, *dst; |
|
2523 |
||
2524 |
src = (char *)(__InstPtr(self)->i_instvars); |
|
2525 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
5755 | 2526 |
#ifdef bcopy4 |
10460 | 2527 |
{ |
2528 |
/* care for odd-number of longs */ |
|
2529 |
int nW = sz >> 2; |
|
2530 |
||
2531 |
if (sz & 3) { |
|
2532 |
nW++; |
|
2533 |
} |
|
2534 |
||
2535 |
bcopy4(src, dst, nW); |
|
2536 |
} |
|
5755 | 2537 |
#else |
10460 | 2538 |
bcopy(src, dst, sz); |
5755 | 2539 |
#endif |
2540 |
||
10460 | 2541 |
flags &= ARRAYMASK; |
2542 |
if (flags == POINTERARRAY) { |
|
2543 |
ninsts = __BYTES2OBJS__(sz); |
|
2544 |
} else { |
|
2545 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
2546 |
} |
|
2547 |
if (ninsts) { |
|
2548 |
do { |
|
2549 |
OBJ el; |
|
2550 |
||
2551 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
2552 |
__STORE_SPC(theCopy, el, spc); |
|
2553 |
} while (--ninsts); |
|
2554 |
} |
|
2555 |
} |
|
2556 |
RETURN (theCopy); |
|
2557 |
} |
|
5755 | 2558 |
} |
2559 |
%}. |
|
2560 |
"/ fallBack for special objects & memoryAllocation failure case |
|
2561 |
||
2562 |
^ self slowShallowCopy |
|
2563 |
! |
|
2564 |
||
2565 |
simpleDeepCopy |
|
2566 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2567 |
This method does NOT handle cycles - but is included to allow this |
5755 | 2568 |
slightly faster copy in situations where it is known that |
2569 |
no recursive references occur (LargeIntegers for example). |
|
2570 |
NOTICE: you will run into trouble, when trying this with recursive |
|
2571 |
objects (usually recursionInterrupt or memory-alert). |
|
8383 | 2572 |
This method corresponds to the 'traditional' deepCopy found in the Blue book." |
5755 | 2573 |
|
2574 |
|myClass aCopy| |
|
2575 |
||
2576 |
(myClass := self class) isVariable ifTrue:[ |
|
10460 | 2577 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2578 |
] ifFalse:[ |
10460 | 2579 |
aCopy := myClass basicNew |
5755 | 2580 |
]. |
2581 |
||
2582 |
"copy the instance variables" |
|
2583 |
aCopy cloneFrom:self performing:#simpleDeepCopy. |
|
2584 |
^ aCopy |
|
2585 |
||
2586 |
"a bad example (but ST/X should survive ...)" |
|
2587 |
" |
|
2588 |
|a| |
|
2589 |
a := Array new:3. |
|
2590 |
a at:3 put:a. |
|
2591 |
a simpleDeepCopy |
|
2592 |
" |
|
2593 |
! |
|
2594 |
||
2595 |
skipInstvarIndexInDeepCopy:index |
|
2596 |
"a helper for deepCopy; only indices for which this method returns |
|
2597 |
false are copied in a deep copy. |
|
2598 |
The default is false here - which means that everything is copied. |
|
2599 |
Can be redefined in subclasses for partial copies" |
|
2600 |
||
2601 |
^ false |
|
2602 |
! |
|
2603 |
||
2604 |
slowShallowCopy |
|
2605 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2606 |
i.e. the copy shares referenced instvars with its original. |
|
2607 |
This method is only invoked as a fallback from #shallowCopy." |
|
2608 |
||
2609 |
|myClass aCopy| |
|
2610 |
||
2611 |
(myClass := self class) isVariable ifTrue:[ |
|
10460 | 2612 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2613 |
] ifFalse:[ |
10460 | 2614 |
aCopy := myClass basicNew |
5755 | 2615 |
]. |
2616 |
||
2617 |
"copy the instance variables" |
|
2618 |
aCopy cloneFrom:self performing:#yourself. |
|
2619 |
^ aCopy |
|
2620 |
! ! |
|
2621 |
||
2622 |
!Object methodsFor:'debugging'! |
|
2623 |
||
7621 | 2624 |
assert:aBooleanOrBlock |
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2625 |
"fail, if the argument does not evaluate to true and report an error" |
6964 | 2626 |
|
11021 | 2627 |
<resource: #skipInDebuggersWalkBack> |
2628 |
||
8876 | 2629 |
aBooleanOrBlock == true ifTrue:[^ self]. |
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2630 |
|
8876 | 2631 |
"/ could still be a block or false. |
10460 | 2632 |
self |
11021 | 2633 |
assert:aBooleanOrBlock |
2634 |
message:('Assertion failed in ' , thisContext sender printString) |
|
7621 | 2635 |
! |
2636 |
||
2637 |
assert:aBooleanOrBlock message:messageIfFailing |
|
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2638 |
"fail, if the argument does not evaluate to true and report an error" |
6961 | 2639 |
|
2640 |
"{ Pragma: +optSpace }" |
|
2641 |
||
11021 | 2642 |
<resource: #skipInDebuggersWalkBack> |
2643 |
||
7621 | 2644 |
(aBooleanOrBlock value) ifFalse:[ |
10651 | 2645 |
AssertionFailedError raiseRequestWith:self errorString:messageIfFailing |
2646 |
]. |
|
2647 |
||
2648 |
" |
|
2649 |
self assert:false |
|
2650 |
" |
|
6961 | 2651 |
! |
2652 |
||
5755 | 2653 |
basicInspect |
2654 |
"{ Pragma: +optSpace }" |
|
2655 |
||
2656 |
"launch an inspector on the receiver. |
|
2657 |
this method should NOT be redefined in subclasses." |
|
2658 |
||
2659 |
Inspector isNil ifTrue:[ |
|
10460 | 2660 |
" |
2661 |
for systems without GUI |
|
2662 |
" |
|
2663 |
self warn:'No Inspector defined (Inspector is nil).' |
|
5755 | 2664 |
] ifFalse:[ |
10460 | 2665 |
Inspector openOn:self |
5755 | 2666 |
] |
2667 |
||
2668 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
2669 |
! |
|
2670 |
||
11025 | 2671 |
breakPoint:someKey |
6954 | 2672 |
"{ Pragma: +optSpace }" |
2673 |
||
2674 |
"Like halt, but disabled by default. |
|
2675 |
Can be easily enabled. |
|
2676 |
Can be filtered on the arguments value (typically: a symbol). |
|
2677 |
Code with breakpoints may be even checked into the source repository" |
|
2678 |
||
2679 |
"Example: nil breakPoint:#stefan" |
|
2680 |
||
11025 | 2681 |
<resource: #skipInDebuggersWalkBack> |
2682 |
||
2683 |
^ self breakPoint:someKey info:'Breakpoint encountered: %1' |
|
2684 |
||
2685 |
" |
|
2686 |
nil breakPoint:#stefan |
|
2687 |
nil breakPoint:#stefan info:'Hello' |
|
2688 |
Smalltalk enableBreakPoint:#stefan. |
|
2689 |
Smalltalk disableBreakPoint:#stefan. |
|
2690 |
" |
|
2691 |
! |
|
2692 |
||
2693 |
breakPoint:someKey info:infoString |
|
2694 |
"{ Pragma: +optSpace }" |
|
2695 |
||
2696 |
"Like halt, but disabled by default. |
|
2697 |
Can be easily enabled. |
|
2698 |
Can be filtered on the arguments value (typically: a symbol). |
|
2699 |
Code with breakpoints may be even checked into the source repository" |
|
2700 |
||
2701 |
"Example: nil breakPoint:#stefan" |
|
2702 |
||
2703 |
<resource: #skipInDebuggersWalkBack> |
|
2704 |
||
2705 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
2706 |
^ HaltSignal |
|
2707 |
raiseRequestWith:someKey |
|
2708 |
errorString:(infoString bindWith:someKey) |
|
2709 |
]. |
|
6954 | 2710 |
! |
2711 |
||
5995 | 2712 |
browse |
2713 |
"open a browser on the receivers class" |
|
2714 |
||
2715 |
self class theNonMetaclass browse |
|
2716 |
||
2717 |
" |
|
2718 |
10 browse |
|
2719 |
Collection browse |
|
2720 |
Collection class browse |
|
2721 |
" |
|
2722 |
! |
|
2723 |
||
11025 | 2724 |
disableBreakPoint:someKey |
2725 |
"disable a breakPoint" |
|
2726 |
||
2727 |
"{ Pragma: +optSpace }" |
|
2728 |
||
2729 |
EnabledBreakPoints notNil ifTrue:[ |
|
2730 |
EnabledBreakPoints remove:someKey. |
|
2731 |
EnabledBreakPoints isEmpty ifTrue:[ |
|
2732 |
EnabledBreakPoints := nil |
|
2733 |
]. |
|
2734 |
]. |
|
2735 |
||
2736 |
" |
|
2737 |
nil enableBreakPoint:#cg. |
|
2738 |
nil breakPoint:#cg. |
|
2739 |
nil disableBreakPoint:#cg |
|
2740 |
nil breakPoint:#cg. |
|
2741 |
" |
|
2742 |
! |
|
2743 |
||
2744 |
enableBreakPoint:someKey |
|
2745 |
"enable a breakPoint" |
|
2746 |
||
2747 |
"{ Pragma: +optSpace }" |
|
2748 |
||
2749 |
EnabledBreakPoints isNil ifTrue:[ |
|
2750 |
EnabledBreakPoints := Set new. |
|
2751 |
]. |
|
2752 |
EnabledBreakPoints add:someKey. |
|
2753 |
||
2754 |
" |
|
2755 |
nil enableBreakPoint:#cg. |
|
2756 |
nil breakPoint:#cg. |
|
2757 |
nil disableBreakPoint:#cg |
|
2758 |
nil breakPoint:#cg. |
|
2759 |
" |
|
2760 |
! |
|
2761 |
||
5755 | 2762 |
inspect |
2763 |
"{ Pragma: +optSpace }" |
|
2764 |
||
2765 |
"launch an inspector on the receiver. |
|
10460 | 2766 |
this method (or better: inspectorClass) can be redefined in subclasses |
5755 | 2767 |
to start special inspectors." |
2768 |
||
2769 |
|cls| |
|
2770 |
||
2771 |
cls := self inspectorClass. |
|
2772 |
cls isNil ifTrue:[ |
|
10460 | 2773 |
^ self basicInspect |
5755 | 2774 |
]. |
2775 |
cls openOn:self |
|
2776 |
||
2777 |
" |
|
2778 |
Object new inspect |
|
2779 |
(1 @ 2) inspect |
|
2780 |
Smalltalk inspect |
|
2781 |
#(1 2 3) asOrderedCollection inspect |
|
2782 |
(Color red) inspect |
|
2783 |
(Image fromFile:'bitmaps/garfield.gif') inspect |
|
2784 |
" |
|
2785 |
! |
|
2786 |
||
2787 |
inspectorClass |
|
2788 |
"{ Pragma: +optSpace }" |
|
2789 |
||
10460 | 2790 |
"return the class to use for inspect. |
5755 | 2791 |
Can (should) be redefined in classes for which a better inspector is available" |
2792 |
||
2793 |
^ Inspector |
|
2794 |
! |
|
2795 |
||
11025 | 2796 |
isBreakPointEnabled:someKey |
2797 |
"{ Pragma: +optSpace }" |
|
2798 |
||
2799 |
"controls which breakpoints to be enabled." |
|
2800 |
||
2801 |
"/ something = OperatingSystem getLoginName ifTrue:[^ true]. |
|
2802 |
"/ something = 'testThis' ifTrue:[^ true]. |
|
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2803 |
EncounteredBreakPoints notNil ifTrue:[ |
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2804 |
EncounteredBreakPoints add:someKey |
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2805 |
]. |
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2806 |
|
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2807 |
^ (EnabledBreakPoints notNil and:[ EnabledBreakPoints includes:someKey ]) |
11025 | 2808 |
|
2809 |
" |
|
2810 |
nil enableBreakPoint:#cg. |
|
2811 |
nil breakPoint:#cg. |
|
2812 |
nil disableBreakPoint:#cg |
|
2813 |
nil breakPoint:#cg. |
|
2814 |
" |
|
2815 |
! |
|
2816 |
||
5755 | 2817 |
mustBeBoolean |
2818 |
"this message is sent by the VM, if a non-Boolean receiver is encountered |
|
2819 |
in an if* or while* message. |
|
2820 |
Caveat: for now, this is only sent by the interpreter; |
|
2821 |
both the JIT and the stc compiler treat it as undefined." |
|
2822 |
||
11021 | 2823 |
<resource: #skipInDebuggersWalkBack> |
2824 |
||
5755 | 2825 |
self error:'Non boolean receiver - proceed for truth' mayProceed:true. |
2826 |
^ true |
|
2827 |
! |
|
2828 |
||
2829 |
mustBeKindOf:aClass |
|
10460 | 2830 |
"for compatibility & debugging support: |
5755 | 2831 |
check if the receiver isKindOf:aClass and raise an error if not. |
2832 |
Notice: |
|
11021 | 2833 |
it is VERY questionable, if it makes sense to add manual |
2834 |
type checks to a dynamically typed language like smalltalk. |
|
2835 |
It will, at least, slow down performance, |
|
2836 |
make your code less reusable and clutter your code with stupid sends |
|
2837 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
2838 |
use of isXXX check methods. |
|
5755 | 2839 |
You see: The author does not like this at all ..." |
2840 |
||
11021 | 2841 |
<resource: #skipInDebuggersWalkBack> |
2842 |
||
5755 | 2843 |
(self isKindOf:aClass) ifFalse:[ |
11021 | 2844 |
self error:'argument is not of expected type' |
5755 | 2845 |
] |
2846 |
! |
|
2847 |
||
6950 | 2848 |
obsoleteFeatureWarning |
2849 |
"{ Pragma: +optSpace }" |
|
2850 |
||
2851 |
"in methods which are going to be changed, a send to |
|
2852 |
this method is used to tell programmers that some feature/semantics is |
|
2853 |
used which is going to be changed in later ST/X versions. |
|
6963 | 2854 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)." |
6950 | 2855 |
|
2856 |
self obsoleteFeatureWarning:nil from:thisContext sender |
|
2857 |
! |
|
2858 |
||
2859 |
obsoleteFeatureWarning:message |
|
2860 |
"{ Pragma: +optSpace }" |
|
2861 |
||
2862 |
"in methods which are going to be changed, a send to |
|
2863 |
this method is used to tell programmers that some feature/semantics is |
|
2864 |
used which is going to be changed in later ST/X versions. |
|
6963 | 2865 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
2866 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 2867 |
|
2868 |
self obsoleteFeatureWarning:message from:thisContext sender |
|
2869 |
! |
|
2870 |
||
2871 |
obsoleteFeatureWarning:message from:aContext |
|
2872 |
"{ Pragma: +optSpace }" |
|
2873 |
||
2874 |
"in methods which are going to be changed, a send to |
|
2875 |
this method is used to tell programmers that some feature/semantics is |
|
2876 |
used which is going to be changed in later ST/X versions. |
|
6963 | 2877 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
2878 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 2879 |
|
2880 |
|spec| |
|
2881 |
||
2882 |
spec := aContext methodPrintString. |
|
2883 |
('WARNING: the ''' , spec , ''' semantics will be changed.') infoPrintCR. |
|
2884 |
(' Its behavior may be different in future ST/X versions.') infoPrintCR. |
|
2885 |
(' called from ' , aContext sender printString) infoPrintCR. |
|
7204 | 2886 |
(aContext sender selector startsWith:'perform:') ifTrue:[ |
2887 |
(' called from ' , aContext sender sender printString) infoPrintCR. |
|
2888 |
]. |
|
6950 | 2889 |
message notNil ifTrue:[ |
10460 | 2890 |
'------> ' infoPrint. message infoPrintCR |
6950 | 2891 |
] |
2892 |
||
2893 |
" |
|
2894 |
Object obsoleteFeatureWarning:'foo' from:thisContext sender sender |
|
2895 |
" |
|
2896 |
! |
|
2897 |
||
5755 | 2898 |
obsoleteMethodWarning |
2899 |
"{ Pragma: +optSpace }" |
|
2900 |
||
2901 |
"in methods which are going to be obsoleted, a self send to |
|
2902 |
this method is used to tell programmers that a method is |
|
2903 |
used which is going to be removed in later ST/X versions. |
|
6963 | 2904 |
Find all methods which will be obsolete soon by looking at senders of this message. |
2905 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 2906 |
|
2907 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
2908 |
! |
|
2909 |
||
2910 |
obsoleteMethodWarning:message |
|
2911 |
"{ Pragma: +optSpace }" |
|
2912 |
||
2913 |
"in methods which are going to be obsoleted, a self send to |
|
2914 |
this method is used to tell programmers that a method is |
|
2915 |
used which is going to be removed in later ST/X versions. |
|
6963 | 2916 |
Find all methods which will be obsolete soon by looking at senders of this message. |
2917 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 2918 |
|
2919 |
self obsoleteMethodWarning:message from:thisContext sender |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2920 |
! |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2921 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2922 |
obsoleteMethodWarning:message from:aContext |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2923 |
"{ Pragma: +optSpace }" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2924 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2925 |
"in methods which are going to be obsoleted, a self-send to |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2926 |
this method is used to tell programmers that a method is |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2927 |
used which is going to be removed in later ST/X versions. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2928 |
Find all methods which will be obsolete soon by looking at senders of this message. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2929 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2930 |
This message is intended for application developers, so its printed as info message." |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2931 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2932 |
|spec sender| |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2933 |
|
9509 | 2934 |
Smalltalk isSmalltalkDevelopmentSystem ifFalse:[ |
10460 | 2935 |
"ignore in production systems" |
2936 |
^ self. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2937 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2938 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2939 |
spec := aContext methodPrintString. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2940 |
sender := aContext sender. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2941 |
('WARNING: the ''' , spec , ''' method is obsolete.') infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2942 |
(' And may not be present in future ST/X versions.') infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2943 |
(' called from ' , sender printString) infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2944 |
(sender selector startsWith:'perform:') ifTrue:[ |
10460 | 2945 |
sender := sender sender. |
2946 |
(sender selector startsWith:'perform:') ifTrue:[ |
|
2947 |
sender := sender sender. |
|
2948 |
]. |
|
2949 |
(' called from ' , sender printString) infoPrintCR. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2950 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2951 |
message notNil ifTrue:[ |
10460 | 2952 |
'------> ' infoPrint. message infoPrintCR |
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2953 |
] |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2954 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2955 |
" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2956 |
Object obsoleteMethodWarning:'foo' from:thisContext sender sender |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2957 |
" |
9509 | 2958 |
|
2959 |
"Modified: / 10-08-2006 / 13:13:11 / cg" |
|
10558 | 2960 |
! |
2961 |
||
2962 |
todo:aBlock |
|
2963 |
"used to mark code pieces that have to be implemented" |
|
2964 |
||
2965 |
"/ self halt. |
|
2966 |
"/ aBlock value. |
|
2967 |
||
2968 |
" |
|
2969 |
example: |
|
2970 |
||
2971 |
... |
|
2972 |
self todo:[ |
|
2973 |
code which needs more work ... |
|
2974 |
]. |
|
2975 |
... |
|
2976 |
" |
|
2977 |
||
2978 |
"Created: / 25-05-2007 / 21:34:39 / cg" |
|
2979 |
"Modified: / 29-05-2007 / 12:11:33 / cg" |
|
5755 | 2980 |
! ! |
2981 |
||
2982 |
!Object methodsFor:'dependents access'! |
|
2983 |
||
2984 |
addDependent:anObject |
|
2985 |
"make the argument, anObject be a dependent of the receiver" |
|
2986 |
||
2987 |
|wasBlocked| |
|
2988 |
||
2989 |
"/ must do this save from interrupts, since the dependents collection |
|
2990 |
"/ is possibly accessed from multiple threads. |
|
2991 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
2992 |
"/ faster execution. |
|
2993 |
||
2994 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2995 |
[ |
|
10460 | 2996 |
|deps dep| |
2997 |
||
2998 |
deps := self dependents. |
|
2999 |
||
3000 |
"/ to save a fair amount of memory in case of |
|
3001 |
"/ many dependencies, we store a single dependent in |
|
3002 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3003 |
"/ added. |
|
3004 |
||
3005 |
(deps isNil or:[deps size == 0]) ifTrue:[ |
|
3006 |
self dependents:(WeakArray with:anObject) |
|
3007 |
] ifFalse:[ |
|
3008 |
deps class == WeakArray ifTrue:[ |
|
3009 |
dep := deps at:1. |
|
3010 |
dep ~~ anObject ifTrue:[ |
|
3011 |
(dep isNil or:[dep == 0]) ifTrue:[ |
|
3012 |
deps at:1 put:anObject |
|
3013 |
] ifFalse:[ |
|
3014 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
3015 |
] |
|
3016 |
] |
|
3017 |
] ifFalse:[ |
|
3018 |
deps add:anObject |
|
3019 |
] |
|
3020 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3021 |
] ensure:[ |
10460 | 3022 |
wasBlocked ifFalse:[ |
3023 |
OperatingSystem unblockInterrupts |
|
3024 |
] |
|
5755 | 3025 |
] |
3026 |
||
3027 |
"Modified: / 27.10.1997 / 19:35:52 / cg" |
|
3028 |
! |
|
3029 |
||
3030 |
breakDependents |
|
3031 |
"remove all dependencies from the receiver" |
|
3032 |
||
3033 |
self dependents:nil. |
|
3034 |
self nonWeakDependents:nil |
|
3035 |
||
3036 |
"Modified: / 19.4.1996 / 10:55:36 / cg" |
|
3037 |
"Created: / 27.2.1998 / 11:26:11 / stefan" |
|
3038 |
! |
|
3039 |
||
8542 | 3040 |
breakDependentsRecursively |
10460 | 3041 |
"remove all dependencies from the receiver and |
8542 | 3042 |
recursively from all objects referred to by the receiver." |
3043 |
||
3044 |
self breakDependents. |
|
10460 | 3045 |
1 to:self class instSize do:[:idx | |
3046 |
(self instVarAt:idx) breakDependentsRecursively. |
|
3047 |
]. |
|
3048 |
1 to:self basicSize do:[:idx | |
|
3049 |
(self basicAt:idx) breakDependentsRecursively. |
|
8542 | 3050 |
] |
3051 |
! |
|
3052 |
||
5755 | 3053 |
dependents |
3054 |
"return a Collection of dependents. |
|
3055 |
The default implementation here uses a global WeakDictionary to store |
|
10460 | 3056 |
dependents |
5755 | 3057 |
This may be too slow for high frequency change&update, |
3058 |
therefore, some classes (Model) redefine this for better performance. |
|
3059 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
3060 |
||
3061 |
|deps| |
|
3062 |
||
3063 |
(deps := Dependencies at:self ifAbsent:nil) isNil ifTrue:[ |
|
10460 | 3064 |
^ #(). |
5755 | 3065 |
]. |
3066 |
^ deps |
|
3067 |
||
3068 |
"Modified: / 26.1.1998 / 11:18:15 / cg" |
|
3069 |
! |
|
3070 |
||
3071 |
dependents:aCollection |
|
3072 |
"set the collection of dependents. |
|
3073 |
The default implementation here uses a global Dictionary to store |
|
3074 |
dependents which may be too slow for high frequency change&update. |
|
3075 |
Therefore, some classes (Model) redefine this for better performance." |
|
3076 |
||
3077 |
"/ must do this save from interrupts, since the dependents collection |
|
3078 |
"/ is possibly accessed from multiple threads. |
|
3079 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3080 |
"/ faster execution (and to avoid creation of garbage blocks). |
|
3081 |
||
3082 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
10460 | 3083 |
"/ the common case - already blocked |
3084 |
||
3085 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
3086 |
Dependencies removeKey:self ifAbsent:nil |
|
3087 |
] ifFalse:[ |
|
3088 |
Dependencies at:self put:aCollection |
|
3089 |
]. |
|
3090 |
^ self |
|
5755 | 3091 |
]. |
3092 |
||
3093 |
[ |
|
10460 | 3094 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3095 |
Dependencies removeKey:self ifAbsent:nil |
|
3096 |
] ifFalse:[ |
|
3097 |
Dependencies at:self put:aCollection |
|
3098 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3099 |
] ensure:[ |
10460 | 3100 |
OperatingSystem unblockInterrupts |
5755 | 3101 |
] |
3102 |
||
3103 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
|
3104 |
! |
|
3105 |
||
3106 |
dependentsDo:aBlock |
|
3107 |
"evaluate aBlock for all of my dependents" |
|
3108 |
||
3109 |
|deps nwDeps| |
|
3110 |
||
3111 |
deps := self dependents. |
|
3112 |
deps size ~~ 0 ifTrue:[ |
|
10460 | 3113 |
deps do:[:d | |
3114 |
(d notNil and:[d ~~ 0]) ifTrue:[ |
|
3115 |
aBlock value:d |
|
3116 |
] |
|
3117 |
] |
|
5755 | 3118 |
]. |
3119 |
nwDeps := self nonWeakDependents. |
|
3120 |
(nwDeps ~~ deps and:[nwDeps size ~~ 0]) ifTrue:[ |
|
10460 | 3121 |
nwDeps do:aBlock |
5755 | 3122 |
]. |
3123 |
||
3124 |
"Modified: / 30.1.1998 / 14:03:40 / cg" |
|
3125 |
! |
|
3126 |
||
3127 |
myDependents |
|
3128 |
"same as dependents - ST-80 compatibility" |
|
3129 |
||
3130 |
^ self dependents |
|
3131 |
! |
|
3132 |
||
3133 |
release |
|
3134 |
"remove all references to objects that may refer to self. |
|
3135 |
Subclasses may redefine this method but should do a 'super release'." |
|
3136 |
||
3137 |
self breakDependents |
|
3138 |
||
3139 |
"Modified: / 27.2.1998 / 11:29:35 / stefan" |
|
3140 |
! |
|
3141 |
||
3142 |
removeDependent:anObject |
|
3143 |
"make the argument, anObject be independent of the receiver" |
|
3144 |
||
3145 |
|wasBlocked| |
|
3146 |
||
3147 |
"/ must do this save from interrupts, since the dependents collection |
|
3148 |
"/ is possibly accessed from multiple threads. |
|
3149 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3150 |
"/ faster execution. |
|
3151 |
||
3152 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3153 |
[ |
|
10460 | 3154 |
|deps n d| |
3155 |
||
3156 |
deps := self dependents. |
|
3157 |
deps size ~~ 0 ifTrue:[ |
|
3158 |
||
3159 |
"/ to save a fair amount of memory in case of |
|
3160 |
"/ many dependencies, we store a single dependent in |
|
3161 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3162 |
"/ added. Here we have to do the inverse ... |
|
3163 |
||
3164 |
((deps class == WeakArray) or:[deps class == Array]) ifTrue:[ |
|
3165 |
((d := deps at:1) == anObject |
|
3166 |
or:[d isNil |
|
3167 |
or:[d == 0]]) ifTrue:[ |
|
3168 |
self dependents:nil |
|
3169 |
] |
|
3170 |
] ifFalse:[ |
|
3171 |
deps remove:anObject ifAbsent:[]. |
|
3172 |
(n := deps size) == 0 ifTrue:[ |
|
3173 |
self dependents:nil |
|
3174 |
] ifFalse:[ |
|
3175 |
n == 1 ifTrue:[ |
|
3176 |
d := deps firstIfEmpty:nil. |
|
3177 |
d notNil ifTrue:[ |
|
3178 |
deps := (deps isWeakCollection ifTrue:WeakArray ifFalse:Array) with:d |
|
3179 |
] ifFalse:[ |
|
3180 |
deps := nil |
|
3181 |
]. |
|
3182 |
self dependents:deps. |
|
3183 |
] |
|
3184 |
] |
|
3185 |
] |
|
3186 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3187 |
] ensure:[ |
10460 | 3188 |
wasBlocked ifFalse:[ |
3189 |
OperatingSystem unblockInterrupts |
|
3190 |
] |
|
5755 | 3191 |
] |
3192 |
||
3193 |
"Modified: / 26.1.1998 / 19:51:50 / cg" |
|
3194 |
! ! |
|
3195 |
||
7266 | 3196 |
!Object methodsFor:'dependents access (non weak)'! |
5755 | 3197 |
|
3198 |
addNonWeakDependent:anObject |
|
3199 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
|
10460 | 3200 |
Be careful: this nonWeakDependency will prevent the dependent from being |
5755 | 3201 |
garbage collected unless the dependency is removed. |
3202 |
This is a private mechanism, for directed dependencies." |
|
3203 |
||
3204 |
|wasBlocked| |
|
3205 |
||
3206 |
"/ must do this save from interrupts, since the dependents collection |
|
3207 |
"/ is possibly accessed from multiple threads. |
|
3208 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3209 |
"/ faster execution. |
|
3210 |
||
3211 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3212 |
[ |
|
10460 | 3213 |
|deps dep| |
3214 |
||
3215 |
deps := self nonWeakDependents. |
|
3216 |
||
3217 |
"/ to save a fair amount of memory in case of |
|
3218 |
"/ many dependencies, we store a single dependent in |
|
3219 |
"/ an Array, and switch to a Set if more dependents are |
|
3220 |
"/ added. |
|
3221 |
||
3222 |
deps size == 0 ifTrue:[ |
|
3223 |
anObject notNil ifTrue:[ |
|
3224 |
self nonWeakDependents:(Array with:anObject). |
|
3225 |
] ifFalse:[ |
|
3226 |
"adding nil causes problems when adding the next one |
|
3227 |
(see below: trying to add nil to IdentitySet)" |
|
9442 | 3228 |
"/ self halt:'try to add nil to list of dependents'. |
10460 | 3229 |
]. |
3230 |
] ifFalse:[ |
|
3231 |
deps class == Array ifTrue:[ |
|
3232 |
dep := deps at:1. |
|
3233 |
dep ~~ anObject ifTrue:[ |
|
3234 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
3235 |
] |
|
3236 |
] ifFalse:[ |
|
3237 |
deps add:anObject |
|
3238 |
] |
|
3239 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3240 |
] ensure:[ |
10460 | 3241 |
wasBlocked ifFalse:[ |
3242 |
OperatingSystem unblockInterrupts |
|
3243 |
] |
|
5755 | 3244 |
] |
3245 |
||
3246 |
"Created: / 19.4.1996 / 10:54:08 / cg" |
|
3247 |
"Modified: / 30.1.1998 / 14:03:08 / cg" |
|
3248 |
! |
|
3249 |
||
3250 |
nonWeakDependents |
|
3251 |
"return a Collection of nonWeakDependents - empty if there is none. |
|
3252 |
This is a private mechanism for directed dependencies." |
|
3253 |
||
3254 |
NonWeakDependencies isNil ifTrue:[^ #()]. |
|
3255 |
^ NonWeakDependencies at:self ifAbsent:#() |
|
3256 |
||
3257 |
"Created: / 19.4.1996 / 10:55:06 / cg" |
|
3258 |
"Modified: / 30.1.1998 / 14:06:47 / cg" |
|
3259 |
! |
|
3260 |
||
3261 |
nonWeakDependents:aCollection |
|
3262 |
"set the collection of nonWeak dependents. |
|
3263 |
This is a private helper for directed dependencies." |
|
3264 |
||
3265 |
[ |
|
10460 | 3266 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3267 |
NonWeakDependencies removeKey:self ifAbsent:nil |
|
3268 |
] ifFalse:[ |
|
3269 |
NonWeakDependencies at:self put:aCollection |
|
3270 |
] |
|
5755 | 3271 |
] valueUninterruptably |
3272 |
||
3273 |
"Created: 19.4.1996 / 11:07:47 / cg" |
|
3274 |
! |
|
3275 |
||
3276 |
removeNonWeakDependent:anObject |
|
3277 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
|
3278 |
(i.e. make it independent of the receiver)" |
|
3279 |
||
3280 |
|wasBlocked| |
|
3281 |
||
3282 |
"/ must do this save from interrupts, since the dependents collection |
|
3283 |
"/ is possibly accessed from multiple threads. |
|
3284 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3285 |
"/ faster execution. |
|
3286 |
||
3287 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3288 |
[ |
|
10460 | 3289 |
|deps n| |
3290 |
||
3291 |
deps := self nonWeakDependents. |
|
3292 |
deps size ~~ 0 ifTrue:[ |
|
3293 |
deps class == Array ifTrue:[ |
|
3294 |
(deps at:1) == anObject ifTrue:[ |
|
3295 |
self nonWeakDependents:nil |
|
3296 |
] |
|
3297 |
] ifFalse:[ |
|
3298 |
deps remove:anObject ifAbsent:[]. |
|
3299 |
(n := deps size) == 0 ifTrue:[ |
|
3300 |
self nonWeakDependents:nil |
|
3301 |
] ifFalse:[ |
|
3302 |
n == 1 ifTrue:[ |
|
3303 |
self nonWeakDependents:(Array with:(deps first)) |
|
3304 |
] |
|
3305 |
] |
|
3306 |
] |
|
3307 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3308 |
] ensure:[ |
10460 | 3309 |
wasBlocked ifFalse:[ |
3310 |
OperatingSystem unblockInterrupts |
|
3311 |
] |
|
5755 | 3312 |
] |
3313 |
||
3314 |
"Created: / 19.4.1996 / 11:44:44 / cg" |
|
3315 |
"Modified: / 30.1.1998 / 14:04:01 / cg" |
|
3316 |
! ! |
|
3317 |
||
9279 | 3318 |
|
3319 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
3320 |
||
3321 |
removeActionsForEvent:eventName |
|
3322 |
"remove ST/V-style event triggers." |
|
3323 |
||
3324 |
self retractInterestsIn:eventName |
|
3325 |
! |
|
3326 |
||
3327 |
removeAllActionsWithReceiver:anObject |
|
3328 |
"remove ST/V-style event triggers." |
|
3329 |
||
3330 |
self retractInterestsFor:anObject |
|
3331 |
! |
|
3332 |
||
3333 |
triggerEvent:eventSymbol withArguments:parameters |
|
3334 |
"perform ST/V-style event triggering." |
|
3335 |
||
3336 |
self changed:eventSymbol with:parameters. |
|
3337 |
! ! |
|
3338 |
||
5755 | 3339 |
!Object methodsFor:'displaying'! |
3340 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3341 |
ascentOn:aGC |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3342 |
"when displayed via displayOn:, some objects assume that the given y coordinate |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3343 |
is the baseline (strings, text etc. do), while others assume that the topY |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3344 |
coordinate is given by y. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3345 |
In other words: some draw above the given y coordinate. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3346 |
This method returns the number of pixels by which the receiver will draw above |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3347 |
the given y coordinate." |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3348 |
|
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3349 |
^ (aGC font onDevice:aGC device) ascent |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3350 |
! |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3351 |
|
6900 | 3352 |
displayOn:aGCOrStream |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3353 |
"Compatibility |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3354 |
append a printed desription on some stream (Dolphin, Squeak) |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3355 |
OR: |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3356 |
display the receiver in a graphicsContext at 0@0 (ST80). |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3357 |
This method allows for any object to be displayed in some view |
5755 | 3358 |
(although the fallBack is to display its printString ...)" |
3359 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3360 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3361 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
6900 | 3362 |
(aGCOrStream isStream or:[aGCOrStream == Transcript]) ifTrue:[ |
10460 | 3363 |
self printOn:aGCOrStream. |
3364 |
^ self |
|
6900 | 3365 |
]. |
3366 |
^ self displayOn:aGCOrStream x:0 y:0. |
|
5755 | 3367 |
|
3368 |
"Created: 29.5.1996 / 16:28:58 / cg" |
|
3369 |
! |
|
3370 |
||
3371 |
displayOn:aGC at:aPoint |
|
3372 |
"ST-80 Compatibility |
|
3373 |
display the receiver in a graphicsContext - this method allows |
|
3374 |
for any object to be displayed in a ListView - for example." |
|
3375 |
||
3376 |
^ self displayOn:aGC x:(aPoint x) y:(aPoint y). |
|
3377 |
! |
|
3378 |
||
3379 |
displayOn:aGC x:x y:y |
|
3380 |
"display the receiver in a graphicsContext - this method allows |
|
3381 |
for any object to be displayed in a ListView - for example." |
|
3382 |
||
3383 |
self displayOn:aGC x:x y:y opaque:false |
|
3384 |
||
3385 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3386 |
! |
|
3387 |
||
3388 |
displayOn:aGc x:x y:y opaque:opaque |
|
3389 |
"display the receiver in a graphicsContext - this method allows |
|
3390 |
for any object to be displayed in a ListView - for example. |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3391 |
The fallBack here shows the receivers displayString. |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3392 |
Notice, that the string is displayed on the baseLine; |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3393 |
ask using #ascentOn: if required" |
5755 | 3394 |
|
3395 |
|s yBaseline| |
|
3396 |
||
3397 |
s := self displayString. |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3398 |
yBaseline := y "+ aGc font ascent". |
5755 | 3399 |
opaque ifTrue:[ |
10460 | 3400 |
aGc displayOpaqueString:s x:x y:yBaseline. |
5755 | 3401 |
] ifFalse:[ |
10460 | 3402 |
aGc displayString:s x:x y:yBaseline. |
5755 | 3403 |
]. |
3404 |
||
3405 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3406 |
! |
|
3407 |
||
3408 |
displayOpaqueOn:aGC x:x y:y |
|
3409 |
"display the receiver in a graphicsContext - this method allows |
|
3410 |
for any object to be displayed in a ListView - for example." |
|
3411 |
||
3412 |
self displayOn:aGC x:x y:y opaque:true |
|
3413 |
||
3414 |
"Modified: / 29.5.1996 / 16:29:38 / cg" |
|
3415 |
"Created: / 26.10.1997 / 15:01:36 / cg" |
|
3416 |
! |
|
3417 |
||
3418 |
displayString |
|
3419 |
"return a string used when displaying the receiver in a view; |
|
3420 |
for example an Inspector. This is usually the same as printString, |
|
3421 |
but sometimes redefined for a better look." |
|
3422 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3423 |
|s| |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3424 |
|
8322
95ca965f65ed
Handle unicode in #displayString
Stefan Vogel <sv@exept.de>
parents:
8300
diff
changeset
|
3425 |
s := CharacterWriteStream on:(String new:32). |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3426 |
self displayOn:s. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3427 |
^ s contents |
5755 | 3428 |
|
3429 |
" |
|
10460 | 3430 |
#(1 2 3) printString |
3431 |
#(1 2 3) displayString |
|
5755 | 3432 |
#(1 2 3) storeString |
3433 |
" |
|
3434 |
! |
|
3435 |
||
3436 |
heightOn:aGC |
|
3437 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
3438 |
||
3439 |
^ (aGC font onDevice:aGC device) heightOf:(self displayString) |
|
3440 |
! |
|
3441 |
||
6654 | 3442 |
widthFrom:startIndex to:endIndex on:aGC |
3443 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3444 |
||
3445 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) from:startIndex to:endIndex |
|
3446 |
! |
|
3447 |
||
5755 | 3448 |
widthOn:aGC |
3449 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3450 |
||
3451 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) |
|
3452 |
! ! |
|
3453 |
||
7359 | 3454 |
!Object methodsFor:'double dispatching'! |
3455 |
||
3456 |
equalFromComplex:aComplex |
|
3457 |
"adding this method here allows for any non-number to be compared to a complex |
|
3458 |
and return false from this comparison. |
|
3459 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3460 |
which uses #= (i.e. a Set or Dictionary)." |
|
3461 |
||
3462 |
^ false |
|
3463 |
! |
|
3464 |
||
3465 |
equalFromFixedPoint:aFixedPoint |
|
3466 |
"adding this method here allows for any non-number to be compared to a fixedPoint |
|
3467 |
and return false from this comparison. |
|
3468 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3469 |
which uses #= (i.e. a Set or Dictionary)." |
|
3470 |
||
3471 |
^ false |
|
3472 |
! |
|
3473 |
||
3474 |
equalFromFloat:aFloat |
|
3475 |
"adding this method here allows for any non-number to be compared to a float |
|
3476 |
and return false from this comparison. |
|
3477 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3478 |
which uses #= (i.e. a Set or Dictionary)." |
|
3479 |
||
3480 |
^ false |
|
3481 |
! |
|
3482 |
||
3483 |
equalFromFraction:aFraction |
|
3484 |
"adding this method here allows for any non-number to be compared to a fraction |
|
3485 |
and return false from this comparison. |
|
3486 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3487 |
which uses #= (i.e. a Set or Dictionary)." |
|
3488 |
||
3489 |
^ false |
|
3490 |
! |
|
3491 |
||
3492 |
equalFromInteger:anInteger |
|
3493 |
"adding this method here allows for any non-number to be compared to an integer |
|
3494 |
and return false from this comparison. |
|
3495 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3496 |
which uses #= (i.e. a Set or Dictionary)." |
|
3497 |
||
3498 |
^ false |
|
3499 |
! |
|
3500 |
||
7455 | 3501 |
equalFromLargeFloat:aLargeFloat |
3502 |
"adding this method here allows for any non-number to be compared to a largeFloat |
|
3503 |
and return false from this comparison. |
|
3504 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3505 |
which uses #= (i.e. a Set or Dictionary)." |
|
3506 |
||
3507 |
^ false |
|
3508 |
! |
|
3509 |
||
7359 | 3510 |
equalFromLongFloat:aLongFloat |
3511 |
"adding this method here allows for any non-number to be compared to a longFloat |
|
3512 |
and return false from this comparison. |
|
3513 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3514 |
which uses #= (i.e. a Set or Dictionary)." |
|
3515 |
||
3516 |
^ false |
|
3517 |
! |
|
3518 |
||
3519 |
equalFromShortFloat:aShortFloat |
|
3520 |
"adding this method here allows for any non-number to be compared to a shortFloat |
|
3521 |
and return false from this comparison. |
|
3522 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3523 |
which uses #= (i.e. a Set or Dictionary)." |
|
3524 |
||
3525 |
^ false |
|
3526 |
! ! |
|
3527 |
||
5755 | 3528 |
!Object methodsFor:'encoding & decoding'! |
3529 |
||
3530 |
decodeAsLiteralArray |
|
8832 | 3531 |
"given a literalEncoding in the receiver, |
3532 |
create & return the corresponding object. |
|
3533 |
The inverse operation to #literalArrayEncoding." |
|
3534 |
||
5755 | 3535 |
^ self |
3536 |
! |
|
3537 |
||
3538 |
encodeOn:anEncoder with:aParameter |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3539 |
"not used any longer. Kept for backward comaptibility" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3540 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3541 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3542 |
|
8404 | 3543 |
self acceptVisitor:anEncoder with:aParameter |
6718 | 3544 |
! |
3545 |
||
3546 |
encodingVectorForInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3547 |
"OBSOLETE, use elementDescriptorForInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3548 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3549 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3550 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3551 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
6718 | 3552 |
|
3553 |
" |
|
3554 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
3555 |
Dictionary new encodingVectorForInstanceVariables |
|
3556 |
(5 @ nil) encodingVectorForInstanceVariables |
|
3557 |
" |
|
3558 |
! |
|
3559 |
||
3560 |
encodingVectorForNonNilInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3561 |
"OBSOLETE, use elementDescriptorForNonNilInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3562 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3563 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3564 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3565 |
^ self elementDescriptorForInstanceVariablesMatching:[:varVal | varVal notNil]. |
6718 | 3566 |
|
3567 |
" |
|
3568 |
#(1 2 3 nil true symbol) encodingVectorForNonNilInstanceVariables |
|
3569 |
(5 @ nil) encodingVectorForNonNilInstanceVariables |
|
3570 |
" |
|
3571 |
! |
|
3572 |
||
5755 | 3573 |
fromLiteralArrayEncoding:aSpecArray |
8798 | 3574 |
"read my attributes from aSpecArray. |
3575 |
Recursively decodes arguments." |
|
3576 |
||
3577 |
|sel litVal val |
|
5755 | 3578 |
stop "{ Class:SmallInteger }" | |
3579 |
||
3580 |
stop := aSpecArray size. |
|
3581 |
||
3582 |
2 to:stop by:2 do:[:i| |
|
10460 | 3583 |
sel := aSpecArray at:i. |
3584 |
litVal := aSpecArray at:i + 1. |
|
3585 |
||
3586 |
(self respondsTo:sel) ifTrue:[ |
|
3587 |
val := litVal decodeAsLiteralArray. |
|
3588 |
self perform:sel with:val |
|
3589 |
] ifFalse:[ |
|
3590 |
Transcript show:self class name; show:': unhandled literalArrayEncoding attribute: '. |
|
3591 |
Transcript showCR:sel. |
|
3592 |
||
3593 |
"/ thats a debug halt, |
|
3594 |
"/ it should probably be removed (to simply ignore unhandled attributes)... |
|
3595 |
"/ for now, it is left in, in order to easily find incompatibilities between |
|
3596 |
"/ VW and ST/X. |
|
3597 |
self halt:('Unrecognized attribute in spec: #', sel). "/ value is: val / litVal. |
|
3598 |
] |
|
5755 | 3599 |
] |
3600 |
! |
|
3601 |
||
3602 |
literalArrayEncoding |
|
3603 |
"generate a literalArrayEncoding array for myself. |
|
3604 |
This uses #literalArrayEncodingSlotOrder which defines the slots and |
|
3605 |
order and #skippedInLiteralEncoding which defines slots to skip. |
|
3606 |
For most subclasses, there is no need to redefine those." |
|
3607 |
||
8832 | 3608 |
|names encoding cls skipped slots| |
5755 | 3609 |
|
3610 |
self isLiteral ifTrue:[ |
|
10460 | 3611 |
^ self |
5755 | 3612 |
]. |
3613 |
||
8832 | 3614 |
slots := self literalArrayEncodingSlotOrder. |
5755 | 3615 |
skipped := self skippedInLiteralEncoding. |
3616 |
cls := self class. |
|
3617 |
names := cls allInstVarNames. |
|
8832 | 3618 |
encoding := OrderedCollection new:(1 + (2 * (slots size - skipped size))). |
8839
c4471cb2799f
stefan: bitte vor Einchecken Testen !
Claus Gittinger <cg@exept.de>
parents:
8833
diff
changeset
|
3619 |
encoding add:cls name. |
8832 | 3620 |
|
3621 |
slots do:[:instSlot | |
|
10460 | 3622 |
|value nm| |
3623 |
||
3624 |
nm := names at:instSlot. |
|
3625 |
(skipped includes:nm) ifFalse:[ |
|
3626 |
(value := self instVarAt:instSlot) notNil ifTrue:[ |
|
3627 |
encoding add:(nm , ':') asSymbol. |
|
3628 |
encoding add:value literalArrayEncoding |
|
3629 |
] |
|
3630 |
] |
|
5755 | 3631 |
]. |
3632 |
^ encoding asArray |
|
8841 | 3633 |
|
3634 |
" |
|
10460 | 3635 |
(1 -> 2) literalArrayEncoding |
3636 |
DebugView menuSpec decodeAsLiteralArray literalArrayEncoding = |
|
3637 |
DebugView menuSpec |
|
8841 | 3638 |
" |
5755 | 3639 |
! |
3640 |
||
3641 |
literalArrayEncodingSlotOrder |
|
3642 |
"define the order in which inst-slots are saved when generating |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3643 |
a literalArrayEncoding" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3644 |
|
5755 | 3645 |
^ 1 to:self class instSize |
3646 |
! |
|
3647 |
||
7112 | 3648 |
postDecodeFrom:aDecoder aspect:aspectSymbol |
3649 |
"invoked by xmlDecoder (and others in the future), after an |
|
3650 |
object has been decoded (i.e. its instance variables have been restored)" |
|
3651 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3652 |
^ self |
7112 | 3653 |
! |
3654 |
||
5755 | 3655 |
skippedInLiteralEncoding |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3656 |
"return a Collection with it's elements are slots for skipping" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3657 |
|
5755 | 3658 |
^ #() |
3659 |
! ! |
|
3660 |
||
3661 |
!Object methodsFor:'error handling'! |
|
3662 |
||
3663 |
appropriateDebugger:aSelector |
|
3664 |
"{ Pragma: +optSpace }" |
|
3665 |
||
3666 |
"return an appropriate debugger to use. |
|
3667 |
If there is already a debugger active on the stack, and it is |
|
3668 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
3669 |
||
3670 |
|context| |
|
3671 |
||
3672 |
"DebugView cannot run without system processes" |
|
3673 |
||
10460 | 3674 |
(Processor isNil |
5755 | 3675 |
or:[Processor activeProcessIsSystemProcess |
3676 |
or:[Smalltalk isInitialized not]]) ifTrue:[ |
|
10460 | 3677 |
^ MiniDebugger |
5755 | 3678 |
]. |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
3679 |
(Screen isNil or:[Screen default isNil or:[Screen default isOpen not]]) ifTrue:[ |
10460 | 3680 |
Debugger isNil ifTrue:[^ nil]. |
3681 |
^ MiniDebugger |
|
5755 | 3682 |
]. |
3683 |
||
3684 |
context := thisContext. |
|
3685 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
3686 |
[context notNil] whileTrue:[ |
|
10460 | 3687 |
((context receiver class == Debugger) |
3688 |
and:[context selector == aSelector]) ifTrue:[ |
|
3689 |
"we are already in some Debugger" |
|
3690 |
(Debugger == MiniDebugger) ifTrue:[ |
|
3691 |
"we are already in the MiniDebugger" |
|
3692 |
ErrorRecursion ifFalse:[ |
|
3693 |
Smalltalk fatalAbort:'recursive error ...' |
|
3694 |
] |
|
3695 |
]. |
|
3696 |
MiniDebugger isNil ifTrue:[ |
|
3697 |
Smalltalk fatalAbort:'no debugger' |
|
3698 |
]. |
|
3699 |
||
3700 |
"ok, an error occured while in the graphical debugger; |
|
3701 |
lets try MiniDebugger" |
|
3702 |
^ MiniDebugger |
|
3703 |
]. |
|
3704 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
5755 | 3705 |
]. |
3706 |
"not within Debugger - no problem" |
|
3707 |
^ Debugger |
|
3708 |
||
3709 |
"Modified: / 23.9.1996 / 12:14:52 / stefan" |
|
3710 |
"Modified: / 19.5.1999 / 18:05:00 / cg" |
|
3711 |
! |
|
3712 |
||
3713 |
cannotSendMessage:aMessage to:someReceiver |
|
3714 |
"this message is sent by the runtime system (VM), |
|
3715 |
when a message is sent to some object, whose class is not |
|
3716 |
a valid behavior (see documentation in Behavior)." |
|
3717 |
||
11021 | 3718 |
<resource: #skipInDebuggersWalkBack> |
3719 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3720 |
^ VMInternalError |
11021 | 3721 |
raiseWith:someReceiver |
3722 |
errorString:('bad class in send of #' , aMessage selector) |
|
5755 | 3723 |
|
3724 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
3725 |
! |
|
3726 |
||
3727 |
doesNotUnderstand:aMessage |
|
3728 |
"this message is sent by the runtime system (VM) when |
|
3729 |
a message is not understood by some object (i.e. there |
|
3730 |
is no method for that selector). The original message has |
|
3731 |
been packed into aMessage (i.e. the receiver, selector and |
|
3732 |
any arguments) and the original receiver is then sent the |
|
3733 |
#doesNotUnderstand: message. |
|
3734 |
Here, we raise another signal which usually enters the debugger. |
|
3735 |
You can of course redefine #doesNotUnderstand: in your classes |
|
10460 | 3736 |
to implement message delegation, |
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
3737 |
or handle the MessageNotUnderstood exception gracefully." |
5755 | 3738 |
|
3739 |
<context: #return> |
|
11021 | 3740 |
<resource: #skipInDebuggersWalkBack> |
5755 | 3741 |
|
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
3742 |
^ MessageNotUnderstood raiseRequestWith:aMessage |
5755 | 3743 |
! |
3744 |
||
3745 |
elementBoundsError |
|
3746 |
"{ Pragma: +optSpace }" |
|
3747 |
||
10460 | 3748 |
"report an error that badElement is out of bounds |
5755 | 3749 |
(i.e. cannot be put into that collection). |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3750 |
The error is reported by raising the ElementBoundsError exception." |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3751 |
|
11021 | 3752 |
<resource: #skipInDebuggersWalkBack> |
3753 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3754 |
^ ElementBoundsError raise |
5755 | 3755 |
|
3756 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
3757 |
! |
|
3758 |
||
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3759 |
elementBoundsError:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3760 |
"{ Pragma: +optSpace }" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3761 |
|
10460 | 3762 |
"report an error that aValue is not valid as element |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3763 |
(i.e. cannot be put into that collection). |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3764 |
The error is reported by raising the ElementBoundsError exception." |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3765 |
|
11021 | 3766 |
<resource: #skipInDebuggersWalkBack> |
3767 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3768 |
^ ElementBoundsError raiseWith:aValue |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3769 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3770 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3771 |
! |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3772 |
|
5755 | 3773 |
elementNotCharacter |
3774 |
"{ Pragma: +optSpace }" |
|
3775 |
||
3776 |
"report an error that object to be stored is no Character. |
|
3777 |
(usually when storing into Strings). |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3778 |
The error is reported by raising the ElementBoundsError exception." |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3779 |
|
11021 | 3780 |
<resource: #skipInDebuggersWalkBack> |
3781 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3782 |
^ ElementBoundsError raise |
5755 | 3783 |
|
3784 |
"Modified: 8.5.1996 / 09:12:49 / cg" |
|
3785 |
! |
|
3786 |
||
3787 |
elementNotInteger |
|
3788 |
"{ Pragma: +optSpace }" |
|
3789 |
||
3790 |
"report an error that object to be stored is not Integer. |
|
3791 |
(in collections that store integers only). |
|
3792 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3793 |
||
11021 | 3794 |
<resource: #skipInDebuggersWalkBack> |
3795 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3796 |
^ ElementBoundsError raise |
5755 | 3797 |
|
3798 |
"Modified: 8.5.1996 / 09:12:51 / cg" |
|
3799 |
! |
|
3800 |
||
3801 |
error |
|
3802 |
"{ Pragma: +optSpace }" |
|
3803 |
||
3804 |
"report error that an error occured. |
|
3805 |
The error is reported by raising the Error exception, |
|
3806 |
which is non-proceedable. |
|
3807 |
If no handler has been setup, a debugger is entered." |
|
3808 |
||
11021 | 3809 |
<context: #return> |
3810 |
<resource: #skipInDebuggersWalkBack> |
|
3811 |
||
5755 | 3812 |
Error raiseWith:#error: |
3813 |
||
3814 |
" |
|
3815 |
nil error |
|
3816 |
" |
|
3817 |
||
3818 |
"Modified: / 8.5.1996 / 09:13:01 / cg" |
|
3819 |
"Modified: / 2.8.1999 / 17:00:19 / stefan" |
|
3820 |
! |
|
3821 |
||
3822 |
error:aString |
|
3823 |
"{ Pragma: +optSpace }" |
|
3824 |
||
3825 |
"Raise an error with error message aString. |
|
3826 |
The error is reported by raising the Error exception, |
|
3827 |
which is non-proceedable. |
|
3828 |
If no handler has been setup, a debugger is entered." |
|
3829 |
||
11021 | 3830 |
<context: #return> |
3831 |
<resource: #skipInDebuggersWalkBack> |
|
3832 |
||
10460 | 3833 |
Error raiseWith:#error: errorString:aString |
5755 | 3834 |
|
3835 |
" |
|
3836 |
nil error:' bad bad bad' |
|
3837 |
" |
|
3838 |
||
3839 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
3840 |
! |
|
3841 |
||
3842 |
error:aString mayProceed:mayProceed |
|
3843 |
"{ Pragma: +optSpace }" |
|
3844 |
||
3845 |
"enter debugger with error-message aString. |
|
10460 | 3846 |
The error is reported by raising either the |
5755 | 3847 |
non-proceedable Error exception, |
3848 |
or the ProceedableError exception." |
|
3849 |
||
11021 | 3850 |
<resource: #skipInDebuggersWalkBack> |
3851 |
||
5755 | 3852 |
mayProceed ifTrue:[ |
11021 | 3853 |
^ ProceedableError raiseRequestWith:#error: errorString:aString |
10460 | 3854 |
]. |
3855 |
||
3856 |
Error raiseWith:#error: errorString:aString |
|
5755 | 3857 |
|
3858 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
3859 |
! |
|
3860 |
||
6900 | 3861 |
errorInvalidFormat |
3862 |
"{ Pragma: +optSpace }" |
|
3863 |
||
3864 |
"report an error that some conversion to/from string representation failed |
|
3865 |
typically when converting numbers, date, time etc." |
|
3866 |
||
11021 | 3867 |
<context: #return> |
3868 |
<resource: #skipInDebuggersWalkBack> |
|
3869 |
||
6900 | 3870 |
^ ConversionError raiseErrorString:'invalid format' |
3871 |
! |
|
3872 |
||
5755 | 3873 |
errorKeyNotFound:aKey |
3874 |
"{ Pragma: +optSpace }" |
|
3875 |
||
3876 |
"report an error that a key was not found in a collection. |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3877 |
The error is reported by raising the KeyNotFoundError exception." |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3878 |
|
11021 | 3879 |
<resource: #skipInDebuggersWalkBack> |
3880 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
3881 |
^ KeyNotFoundError raiseRequestWith:aKey errorString:(' ', aKey printString) |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3882 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3883 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3884 |
Dictionary new at:#nonExistantElement |
5755 | 3885 |
" |
3886 |
! |
|
3887 |
||
3888 |
errorNotFound |
|
3889 |
"{ Pragma: +optSpace }" |
|
3890 |
||
3891 |
"report an error that no element was found in a collection. |
|
3892 |
The error is reported by raising the NotFoundSignal exception." |
|
3893 |
||
11021 | 3894 |
<resource: #skipInDebuggersWalkBack> |
3895 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
3896 |
^ NotFoundError raiseRequestWith:nil |
5755 | 3897 |
|
3898 |
"Modified: / 8.5.1996 / 09:13:11 / cg" |
|
3899 |
"Modified: / 26.7.1999 / 10:51:50 / stefan" |
|
3900 |
! |
|
3901 |
||
6874 | 3902 |
errorNotFound:errorString |
3903 |
"{ Pragma: +optSpace }" |
|
3904 |
||
3905 |
"report an error that no element was found in a collection. |
|
3906 |
The error is reported by raising the NotFoundSignal exception." |
|
3907 |
||
11021 | 3908 |
<resource: #skipInDebuggersWalkBack> |
3909 |
||
10837
63d19c75d762
changed #errorNotFound: raise it proceedable
Stefan Vogel <sv@exept.de>
parents:
10834
diff
changeset
|
3910 |
^ NotFoundError raiseRequestErrorString:errorString |
6874 | 3911 |
! |
3912 |
||
5755 | 3913 |
errorSignal |
3914 |
^ self class errorSignal |
|
3915 |
||
3916 |
"Created: / 19.6.1998 / 02:32:32 / cg" |
|
3917 |
! |
|
3918 |
||
3919 |
halt |
|
3920 |
"{ Pragma: +optSpace }" |
|
3921 |
||
3922 |
"enter debugger with halt-message. |
|
3923 |
The error is reported by raising the HaltSignal exception." |
|
3924 |
||
11021 | 3925 |
<resource: #skipInDebuggersWalkBack> |
3926 |
||
6716
7e2bac4221d1
allow for halts to be ignored
Claus Gittinger <cg@exept.de>
parents:
6708
diff
changeset
|
3927 |
(Smalltalk at:#IgnoreHalt ifAbsent:false) == true ifTrue:[^ self]. |
6221 | 3928 |
^ HaltInterrupt raiseRequestWith:#halt |
3929 |
||
5755 | 3930 |
"Modified: / 2.8.1999 / 17:00:29 / stefan" |
6221 | 3931 |
"Modified: / 17.11.2001 / 22:47:44 / cg" |
5755 | 3932 |
! |
3933 |
||
3934 |
halt:aString |
|
3935 |
"{ Pragma: +optSpace }" |
|
3936 |
||
3937 |
"enter debugger with halt-message. |
|
3938 |
The error is reported by raising the HaltSignal exception." |
|
3939 |
||
11021 | 3940 |
<resource: #skipInDebuggersWalkBack> |
3941 |
||
6716
7e2bac4221d1
allow for halts to be ignored
Claus Gittinger <cg@exept.de>
parents:
6708
diff
changeset
|
3942 |
(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
|
3943 |
^ HaltInterrupt raiseRequestWith:#halt: errorString:aString |
5755 | 3944 |
|
3945 |
"Modified: 8.5.1996 / 09:13:23 / cg" |
|
3946 |
! |
|
3947 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3948 |
handlerForSignal:exceptionHandler context:theContext originator:originator |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3949 |
" should never be invoked for non-blocks/non-exceptions/non-signals" |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3950 |
|
7566 | 3951 |
thisContext isRecursive ifTrue:[^ nil]. |
3952 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3953 |
'Warning: handlerForSignal invoked for: ' print. self printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3954 |
' context: ' print. theContext printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3955 |
' originator: ' print. originator printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3956 |
' sender: ' print. thisContext sender printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3957 |
|
7566 | 3958 |
"/ MiniDebugger enter:thisContext withMessage:'oops' mayProceed:true. |
3959 |
self error:'this method should only be invoked for blocks, exceptions and signals'. |
|
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3960 |
! |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3961 |
|
5755 | 3962 |
implementedBySubclass |
3963 |
"{ Pragma: +optSpace }" |
|
3964 |
||
3965 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
3966 |
||
11021 | 3967 |
<resource: #skipInDebuggersWalkBack> |
3968 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
3969 |
^ self subclassResponsibility:'method must be reimplemented in ST/V subclass' |
5755 | 3970 |
! |
3971 |
||
3972 |
indexNotInteger |
|
3973 |
"{ Pragma: +optSpace }" |
|
3974 |
||
3975 |
"report an error that index is not an Integer. |
|
3976 |
(when accessing collections indexed by an integer key). |
|
3977 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
3978 |
||
11021 | 3979 |
<resource: #skipInDebuggersWalkBack> |
3980 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
3981 |
^ NonIntegerIndexError raiseRequestWith:nil |
5755 | 3982 |
|
3983 |
"Modified: / 8.5.1996 / 09:13:37 / cg" |
|
3984 |
"Modified: / 26.7.1999 / 10:57:43 / stefan" |
|
3985 |
! |
|
3986 |
||
3987 |
indexNotInteger:anIndex |
|
3988 |
"{ Pragma: +optSpace }" |
|
3989 |
||
3990 |
"report an error that index is not an Integer. |
|
3991 |
(when accessing collections indexed by an integer key). |
|
3992 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
3993 |
||
11021 | 3994 |
<resource: #skipInDebuggersWalkBack> |
3995 |
||
10460 | 3996 |
^ NonIntegerIndexError raiseRequestWith:anIndex |
5755 | 3997 |
|
3998 |
"Created: / 16.5.1998 / 19:39:41 / cg" |
|
3999 |
! |
|
4000 |
||
7216 | 4001 |
indexNotIntegerOrOutOfBounds:index |
4002 |
"{ Pragma: +optSpace }" |
|
4003 |
||
4004 |
"report an error that index is either non-integral or out of bounds" |
|
4005 |
||
11021 | 4006 |
<resource: #skipInDebuggersWalkBack> |
4007 |
||
7216 | 4008 |
index isInteger ifFalse:[ |
11021 | 4009 |
^ self indexNotInteger:index |
7216 | 4010 |
]. |
4011 |
^ self subscriptBoundsError:index |
|
4012 |
! |
|
4013 |
||
5755 | 4014 |
integerCheckError |
4015 |
"{ Pragma: +optSpace }" |
|
4016 |
||
4017 |
"generated when a variable declared with an integer type gets a bad |
|
4018 |
value assigned" |
|
4019 |
||
11021 | 4020 |
<resource: #skipInDebuggersWalkBack> |
4021 |
||
10460 | 4022 |
^ self error:'bad assign of ' , self printString , |
11021 | 4023 |
' (' , self class name , ') to integer-typed variable' |
5755 | 4024 |
! |
4025 |
||
4026 |
invalidCodeObject |
|
4027 |
"{ Pragma: +optSpace }" |
|
4028 |
||
11021 | 4029 |
<resource: #skipInDebuggersWalkBack> |
4030 |
||
5755 | 4031 |
self error:'not an executable code object' |
4032 |
||
4033 |
"Created: 1.8.1997 / 00:16:44 / cg" |
|
4034 |
! |
|
4035 |
||
10460 | 4036 |
invalidMessage |
5755 | 4037 |
"{ Pragma: +optSpace }" |
4038 |
||
4039 |
"this is sent by ST/V code - its the same as #shouldNotImplement" |
|
4040 |
||
11021 | 4041 |
<resource: #skipInDebuggersWalkBack> |
4042 |
||
5755 | 4043 |
^ self shouldNotImplement |
4044 |
! |
|
4045 |
||
4046 |
mustBeRectangle |
|
4047 |
"{ Pragma: +optSpace }" |
|
4048 |
||
4049 |
"report an argument-not-rectangle-error" |
|
4050 |
||
11021 | 4051 |
<resource: #skipInDebuggersWalkBack> |
4052 |
||
5755 | 4053 |
^ self error:'argument must be a Rectangle' |
4054 |
! |
|
4055 |
||
4056 |
mustBeString |
|
4057 |
"{ Pragma: +optSpace }" |
|
4058 |
||
4059 |
"report an argument-not-string-error" |
|
4060 |
||
11021 | 4061 |
<resource: #skipInDebuggersWalkBack> |
4062 |
||
5755 | 4063 |
^ self error:'argument must be a String' |
4064 |
! |
|
4065 |
||
4066 |
notIndexed |
|
4067 |
"{ Pragma: +optSpace }" |
|
4068 |
||
4069 |
"report an error that receiver has no indexed instance variables. |
|
4070 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4071 |
||
11021 | 4072 |
<context: #return> |
4073 |
<resource: #skipInDebuggersWalkBack> |
|
4074 |
||
10460 | 4075 |
^ SubscriptOutOfBoundsError |
11021 | 4076 |
raiseErrorString:'receiver has no indexed variables' |
5755 | 4077 |
|
4078 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
|
4079 |
! |
|
4080 |
||
4081 |
openDebuggerOnException:ex |
|
4082 |
"{ Pragma: +optSpace }" |
|
4083 |
||
4084 |
"enter the debugger on some unhandled exception" |
|
4085 |
||
6884 | 4086 |
|msgString debugger answer| |
5755 | 4087 |
|
7208 | 4088 |
msgString := ex description. |
5755 | 4089 |
" |
4090 |
if there is no debugger, |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4091 |
ask for ignore or exit. Exit will terminate the application. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4092 |
ignore will raise an AbortOperationRequest. |
5755 | 4093 |
" |
4094 |
Debugger isNil ifTrue:[ |
|
10732
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4095 |
msgString := 'Error: ' , msgString. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4096 |
|
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4097 |
thisContext isRecursive ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4098 |
msgString errorPrintCR. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4099 |
Smalltalk fatalAbort:'recursive unhandled exception' |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4100 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4101 |
|
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4102 |
Smalltalk isStandAloneApp ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4103 |
(ex signal == NoHandlerError and:[HaltInterrupt handles:ex unhandledException]) ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4104 |
"/ 'Halt ignored' infoPrintCR. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4105 |
^ self |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4106 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4107 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4108 |
|
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4109 |
Smalltalk isSmalltalkDevelopmentSystem ifFalse:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4110 |
(Dialog notNil and:[Screen default notNil]) ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4111 |
AbortOperationRequest isHandled ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4112 |
answer := OptionBox |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4113 |
request:msgString |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4114 |
label:msgString |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4115 |
buttonLabels:#('Exit' 'Terminate Thread' 'Ignore' 'Abort' ) |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4116 |
values:#(exit terminate ignore abort) |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4117 |
default:#abort. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4118 |
] ifFalse:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4119 |
answer := OptionBox |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4120 |
request:msgString |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4121 |
label:msgString |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4122 |
buttonLabels:#('Exit' 'Terminate Thread' 'Ignore' ) |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4123 |
values:#(exit terminate ignore ) |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4124 |
default:#terminate. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4125 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4126 |
answer isNil ifTrue:[ answer := #ignore]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4127 |
|
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4128 |
answer == #abort ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4129 |
^ AbortOperationRequest raiseRequest |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4130 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4131 |
answer == #ignore ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4132 |
^ nil |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4133 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4134 |
answer == #terminate ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4135 |
Processor activeProcess isSystemProcess ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4136 |
(Dialog confirm:'Are you sure (this might finish the application)') ifFalse:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4137 |
^ nil |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4138 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4139 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4140 |
^ Processor activeProcess terminate. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4141 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4142 |
"asking second time here to prevent the user from accidently closing his app" |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4143 |
answer == #exit ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4144 |
answer := OptionBox |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4145 |
request:'Do you really wish to exit this application (all changes will be lost)?' |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4146 |
label:msgString |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4147 |
buttonLabels:#('Yes' 'No' ) |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4148 |
values:#(exit abort) |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4149 |
default:#abort. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4150 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4151 |
answer == #abort ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4152 |
^ AbortOperationRequest raiseRequest |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4153 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4154 |
|
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4155 |
(Dialog confirm:'Are you sure you want to finish the application ?') ifFalse:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4156 |
^ nil |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4157 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4158 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4159 |
|
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4160 |
"don't output the message, if the exception is a UserInterrupt (CTRL-C)" |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4161 |
(ex signal == NoHandlerError |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4162 |
and:[ex unhandledException signal == UserInterrupt]) ifTrue:[ |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4163 |
OperatingSystem exit:130. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4164 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4165 |
msgString errorPrintCR. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4166 |
thisContext fullPrintAll. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4167 |
OperatingSystem exit:1 |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4168 |
]. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4169 |
|
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4170 |
msgString errorPrintCR. |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4171 |
Smalltalk fatalAbort:'no Debugger defined' |
5755 | 4172 |
]. |
4173 |
||
4174 |
" |
|
4175 |
find an appropriate debugger to use |
|
4176 |
" |
|
4177 |
debugger := self appropriateDebugger:(thisContext selector). |
|
4178 |
debugger isNil ifTrue:[ |
|
10732
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4179 |
^ AbortOperationRequest raiseRequest |
10460 | 4180 |
]. |
4181 |
||
4182 |
^ debugger |
|
10732
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4183 |
enter:ex returnableSuspendedContext |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4184 |
withMessage:msgString |
cb163e107c24
changed #openDebuggerOnException:
Stefan Vogel <sv@exept.de>
parents:
10651
diff
changeset
|
4185 |
mayProceed:(ex mayProceed). |
5755 | 4186 |
|
10234 | 4187 |
"Modified: / 06-12-2006 / 18:51:55 / cg" |
5755 | 4188 |
! |
4189 |
||
4190 |
primitiveFailed |
|
4191 |
"{ Pragma: +optSpace }" |
|
4192 |
||
4193 |
"report an error that some primitive code failed. |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4194 |
The error is reported by raising the PrimitiveFailure exception." |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4195 |
|
11021 | 4196 |
<resource: #skipInDebuggersWalkBack> |
4197 |
||
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4198 |
|sender| |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4199 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4200 |
sender := thisContext sender. |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4201 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4202 |
^ PrimitiveFailure raiseRequestWith:(Message selector:sender selector arguments:sender args) |
11021 | 4203 |
in:sender. |
5755 | 4204 |
|
6005 | 4205 |
" |
4206 |
1234 primitiveFailed |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4207 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4208 |
[ |
11021 | 4209 |
ExternalBytes new basicAt:40 |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4210 |
] on:PrimitiveFailure do:[:ex| |
11021 | 4211 |
ex inspect |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4212 |
] |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4213 |
" |
5755 | 4214 |
! |
4215 |
||
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4216 |
primitiveFailed:messageString |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4217 |
"{ Pragma: +optSpace }" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4218 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4219 |
"report an error that some primitive code failed. |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4220 |
The error is reported by raising the PrimitiveFailureSignal exception." |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4221 |
|
11021 | 4222 |
<resource: #skipInDebuggersWalkBack> |
4223 |
||
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4224 |
|sender| |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4225 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4226 |
sender := thisContext sender. |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4227 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4228 |
^ PrimitiveFailure raiseRequestWith:(Message selector:sender selector arguments:sender args) |
11021 | 4229 |
errorString:messageString |
4230 |
in:sender. |
|
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4231 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4232 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4233 |
1234 primitiveFailed:'this is a test' |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4234 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4235 |
! |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4236 |
|
6815 | 4237 |
shouldImplement |
4238 |
"{ Pragma: +optSpace }" |
|
4239 |
||
4240 |
"report an error that this message should be implemented. |
|
4241 |
This is send by automatically generated method bodies" |
|
4242 |
||
11021 | 4243 |
<resource: #skipInDebuggersWalkBack> |
4244 |
||
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4245 |
|sender| |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4246 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4247 |
sender := thisContext sender. |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4248 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4249 |
^ UnimplementedFunctionalityError raiseRequestWith:(Message selector:sender selector arguments:sender args) |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4250 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4251 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4252 |
" |
11021 | 4253 |
self shouldImplement |
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4254 |
" |
6815 | 4255 |
! |
4256 |
||
5755 | 4257 |
shouldNotImplement |
4258 |
"{ Pragma: +optSpace }" |
|
4259 |
||
4260 |
"report an error that this message should not be implemented" |
|
4261 |
||
11021 | 4262 |
<resource: #skipInDebuggersWalkBack> |
4263 |
||
8729 | 4264 |
^ self error:'method/functionality not appropriate for this class' |
5755 | 4265 |
|
4266 |
"Modified: 8.5.1996 / 09:09:44 / cg" |
|
4267 |
! |
|
4268 |
||
4269 |
subclassResponsibility |
|
4270 |
"{ Pragma: +optSpace }" |
|
4271 |
||
4272 |
"report an error that this message should have been reimplemented in a |
|
4273 |
subclass" |
|
4274 |
||
11021 | 4275 |
<resource: #skipInDebuggersWalkBack> |
4276 |
||
10877
0666d48f91d1
show the affected method-selector in the subclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
10856
diff
changeset
|
4277 |
^ SubclassResponsibilityError raiseRequestWith:thisContext sender selector |
5755 | 4278 |
! |
4279 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4280 |
subclassResponsibility:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4281 |
"{ Pragma: +optSpace }" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4282 |
|
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4283 |
"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
|
4284 |
|
11021 | 4285 |
<resource: #skipInDebuggersWalkBack> |
4286 |
||
7334 | 4287 |
^ SubclassResponsibilityError raiseRequestErrorString:msg |
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4288 |
! |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4289 |
|
5755 | 4290 |
subscriptBoundsError |
4291 |
"{ Pragma: +optSpace }" |
|
4292 |
||
4293 |
"report an error that some index is out of bounds. |
|
4294 |
(when accessing indexable collections). |
|
4295 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4296 |
||
11021 | 4297 |
<resource: #skipInDebuggersWalkBack> |
4298 |
||
5755 | 4299 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:nil |
4300 |
||
4301 |
"Modified: / 26.7.1996 / 16:45:42 / cg" |
|
4302 |
"Modified: / 26.7.1999 / 10:58:27 / stefan" |
|
4303 |
! |
|
4304 |
||
4305 |
subscriptBoundsError:anIndex |
|
4306 |
"{ Pragma: +optSpace }" |
|
4307 |
||
4308 |
"report an error that anIndex is out of bounds. |
|
4309 |
(when accessing indexable collections). |
|
4310 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4311 |
||
11021 | 4312 |
<resource: #skipInDebuggersWalkBack> |
4313 |
||
10460 | 4314 |
^ SubscriptOutOfBoundsError |
11021 | 4315 |
raiseRequestWith:anIndex |
4316 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
5755 | 4317 |
|
6221 | 4318 |
"Modified: / 17.11.2001 / 22:49:56 / cg" |
5755 | 4319 |
! |
4320 |
||
4321 |
typeCheckError |
|
4322 |
"{ Pragma: +optSpace }" |
|
4323 |
||
4324 |
"generated when a variable declared with a type hint gets a bad |
|
4325 |
value assigned" |
|
4326 |
||
11021 | 4327 |
<resource: #skipInDebuggersWalkBack> |
4328 |
||
5755 | 4329 |
^ self error:'bad assign of ' , self printString , |
11021 | 4330 |
' (' , self class name , ') to typed variable' |
5755 | 4331 |
! ! |
4332 |
||
4333 |
!Object methodsFor:'evaluation'! |
|
4334 |
||
8690
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4335 |
argumentCount |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4336 |
"compatibility with Blocks and Messages. |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4337 |
Answer 0, since we only understand #value. |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4338 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4339 |
By implementing this, you can pass any object as an exception handler." |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4340 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4341 |
^ 0 |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4342 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4343 |
" |
10460 | 4344 |
[1 // 0] on:ArithmeticError do:9999 |
8690
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4345 |
" |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4346 |
! |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4347 |
|
5755 | 4348 |
value |
4349 |
"return the receiver itself. |
|
4350 |
This allows every object to be used where blocks or valueHolders |
|
4351 |
are typically used, and allows for valueHolders and blocks to be |
|
4352 |
used interchangably in some situations. |
|
4353 |
||
4354 |
Time will show, if this is a good idea or leads to sloppy programming |
|
4355 |
style ... (the idea was borrowed from the Self language). |
|
4356 |
||
10460 | 4357 |
WARNING: dont 'optimize' away ifXXX: blocks |
4358 |
(i.e. do NOT replace |
|
4359 |
foo ifTrue:[var1] ifFalse:[var2] |
|
4360 |
by: |
|
4361 |
foo ifTrue:var1 ifFalse:var2 |
|
4362 |
) |
|
4363 |
- the compilers will only generate inline code for the if, |
|
4364 |
iff the argument(s) are blocks - otherwise, a true send is |
|
4365 |
generated. |
|
4366 |
This 'oprimization' will work semantically correct, |
|
4367 |
but execute SLOWER instead." |
|
5755 | 4368 |
|
4369 |
^ self |
|
4370 |
||
4371 |
" |
|
10460 | 4372 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
4373 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
4374 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
4375 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
5755 | 4376 |
" |
4377 |
||
4378 |
"DO NOT DO THIS (its slower) |
|
7458 | 4379 |
(1 > 4) ifTrue:a ifFalse:b |
5755 | 4380 |
|
4381 |
USE (the compiler optimizes blocks in if/while): |
|
7458 | 4382 |
(1 > 4) ifTrue:[a] ifFalse:[b] |
5755 | 4383 |
" |
4384 |
||
4385 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
4386 |
! ! |
|
4387 |
||
4388 |
!Object methodsFor:'finalization'! |
|
4389 |
||
4390 |
disposed |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4391 |
"OBSOLETE INTERFACE: use #finalize |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4392 |
this is invoked for objects which have been registered |
5755 | 4393 |
in a Registry, when the original object dies. |
4394 |
Subclasses may redefine this method" |
|
4395 |
||
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4396 |
<resource: #obsolete> |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4397 |
|
5755 | 4398 |
^ self |
4399 |
! |
|
4400 |
||
4401 |
executor |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4402 |
"Return the object which does the finalization for me. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4403 |
This interface is also VW & Sqeak compatible," |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4404 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4405 |
"for now, send #shallowCopyForFinalization, to be compatible with |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4406 |
classes designed for old ST/X versions" |
5755 | 4407 |
|
4408 |
^ self shallowCopyForFinalization |
|
4409 |
! |
|
4410 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4411 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4412 |
"answer a Registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4413 |
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
|
4414 |
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
|
4415 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4416 |
^ FinalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4417 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4418 |
|
5755 | 4419 |
finalize |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4420 |
"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
|
4421 |
in a Registry, when the original object dies. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4422 |
Subclasses may redefine this method |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4423 |
This interface is also VW-compatible" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4424 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4425 |
"send #disposed for compatibility with existing classes that still |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4426 |
implement the obsolete #disposed message" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4427 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4428 |
^ self disposed |
5755 | 4429 |
! |
4430 |
||
4431 |
reRegisterForFinalization |
|
4432 |
"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
|
4433 |
This will create a new executor, which will receive a #finalize message when |
5755 | 4434 |
the receiver is garbage collected." |
4435 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4436 |
self finalizationLobby registerChange:self |
5755 | 4437 |
! |
4438 |
||
4439 |
registerForFinalization |
|
4440 |
"register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4441 |
Once registered, the executor of the receiver will receive a #finalize message when |
5755 | 4442 |
the receiver is garbage collected." |
4443 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4444 |
self finalizationLobby register:self |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4445 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4446 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4447 |
shallowCopyForFinalization |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4448 |
"OBSOLETE INTERFACE: use #executor. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4449 |
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
|
4450 |
(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
|
4451 |
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
|
4452 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4453 |
<resource: #obsolete> |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4454 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4455 |
^ self shallowCopy |
5755 | 4456 |
! |
4457 |
||
4458 |
unregisterForFinalization |
|
4459 |
"unregister mySelf from later finalization" |
|
4460 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4461 |
self finalizationLobby unregister:self |
5755 | 4462 |
! ! |
4463 |
||
4464 |
!Object methodsFor:'initialization'! |
|
4465 |
||
4466 |
initialize |
|
4467 |
"just to ignore initialize to objects which do not need it" |
|
4468 |
||
4469 |
^ self |
|
4470 |
! ! |
|
4471 |
||
4472 |
!Object methodsFor:'interrupt handling'! |
|
4473 |
||
4474 |
childSignalInterrupt |
|
4475 |
"death of a child process (unix process) - do nothing" |
|
4476 |
||
4477 |
^ self |
|
4478 |
! |
|
4479 |
||
4480 |
customInterrupt |
|
4481 |
"{ Pragma: +optSpace }" |
|
4482 |
||
4483 |
"a custom interrupt - but no handler has defined" |
|
4484 |
||
4485 |
self error:'custom interrupt' mayProceed:true |
|
4486 |
! |
|
4487 |
||
4488 |
errorInterrupt:errorID with:aParameter |
|
4489 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
10460 | 4490 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
5755 | 4491 |
which can be called from C subsystems to raise an (asynchronous) |
4492 |
error exception. |
|
4493 |
||
4494 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
4495 |
used from other C subsystems too, to upcast errors. |
|
4496 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
4497 |
IDs (currently) used: |
|
10460 | 4498 |
#DisplayError ..... x-error interrupt |
4499 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
5755 | 4500 |
" |
4501 |
||
6263
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4502 |
|handlers handler| |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4503 |
|
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4504 |
handlers := ObjectMemory registeredErrorInterruptHandlers. |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4505 |
handlers notNil ifTrue:[ |
10460 | 4506 |
handler := handlers at:errorID ifAbsent:nil. |
4507 |
handler notNil ifTrue:[ |
|
4508 |
"/ |
|
4509 |
"/ handler found; let it do whatever it wants ... |
|
4510 |
"/ |
|
4511 |
handler errorInterrupt:errorID with:aParameter. |
|
4512 |
^ self |
|
4513 |
]. |
|
5755 | 4514 |
]. |
4515 |
||
4516 |
"/ |
|
4517 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
4518 |
"/ |
|
10460 | 4519 |
^ Error |
4520 |
raiseRequestWith:errorID |
|
4521 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
5755 | 4522 |
! |
4523 |
||
4524 |
exceptionInterrupt |
|
4525 |
"{ Pragma: +optSpace }" |
|
4526 |
||
4527 |
"exception interrupt - enter debugger" |
|
4528 |
||
4529 |
self error:'exception Interrupt' mayProceed:true |
|
4530 |
! |
|
4531 |
||
4532 |
fpExceptionInterrupt |
|
4533 |
"{ Pragma: +optSpace }" |
|
4534 |
||
4535 |
"a floating point exception occured - this one |
|
4536 |
has to be handled differently since it comes asynchronous |
|
4537 |
on some machines (for example, on machines with a separate FPU |
|
4538 |
or superscalar architectures. Also, errors from within primitive code |
|
4539 |
(or library functions such as GL) are sent via the Unix-signal |
|
4540 |
mechanism this way." |
|
4541 |
||
4542 |
|where rec| |
|
4543 |
||
4544 |
where := thisContext sender. |
|
4545 |
rec := where receiver. |
|
4546 |
rec isNumber ifTrue:[ |
|
10460 | 4547 |
^ rec class |
4548 |
raise:#domainErrorSignal |
|
4549 |
receiver:rec |
|
4550 |
selector:where selector |
|
4551 |
arguments:(where args asArray) |
|
4552 |
errorString:'floating point exception' |
|
5755 | 4553 |
]. |
4554 |
||
4555 |
"/ could be in some C-library ... |
|
7402 | 4556 |
^ DomainError raise |
5755 | 4557 |
! |
4558 |
||
4559 |
internalError:msg |
|
4560 |
"{ Pragma: +optSpace }" |
|
4561 |
||
4562 |
"this is triggered, when VM hits some bad error, |
|
4563 |
such as corrupted class, corrupted method/selector array |
|
4564 |
etc. The argument string gives some more information on what happened. |
|
4565 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
|
4566 |
Its not guaranteed, that the system is in a working condition once |
|
4567 |
this error occurred ...." |
|
4568 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4569 |
VMInternalError raiseWith:self errorString:msg |
5755 | 4570 |
! |
4571 |
||
4572 |
ioInterrupt |
|
4573 |
"{ Pragma: +optSpace }" |
|
4574 |
||
4575 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
|
4576 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
4577 |
or it does not understand the ioInterrupt message. |
|
4578 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
4579 |
||
4580 |
self error:'I/O Interrupt - but no handler' mayProceed:true |
|
4581 |
! |
|
4582 |
||
4583 |
memoryInterrupt |
|
4584 |
"{ Pragma: +optSpace }" |
|
4585 |
||
4586 |
"out-of-memory interrupt and no handler - enter debugger" |
|
4587 |
||
4588 |
self error:'almost out of memory' mayProceed:true |
|
4589 |
! |
|
4590 |
||
4591 |
recursionInterrupt |
|
4592 |
"{ Pragma: +optSpace }" |
|
4593 |
||
4594 |
"recursion limit (actually: stack overflow) interrupt. |
|
4595 |
This interrupt is triggered, when a process stack grows above |
|
4596 |
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
|
4597 |
could be caught. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4598 |
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
|
4599 |
and the exception can be resumed. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4600 |
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
|
4601 |
is not proceedable. |
10460 | 4602 |
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
|
4603 |
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
|
4604 |
or debug for a while. |
5755 | 4605 |
If the signal is ignored, and the stack continues to grow, there |
4606 |
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
|
4607 |
terminates the process." |
5755 | 4608 |
|
7838
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4609 |
|con remaining sender nSkipped| |
5755 | 4610 |
|
4611 |
(con := thisContext) isRecursive ifFalse:[ |
|
4612 |
"/ Processor activeProcess usedStackSize < Processor activeProcess maximumStackSize ifTrue:[ |
|
4613 |
"/ "/ mhmh - it hit me, but I am not responsible ... |
|
4614 |
"/ 'Stray recursionInterrupt ...' infoPrintCR. |
|
4615 |
"/ ^ self |
|
4616 |
"/ ]. |
|
10460 | 4617 |
ObjectMemory infoPrinting ifTrue:[ |
4618 |
'Object [info]: recursionInterrupt from:' printCR. |
|
4619 |
con := con sender. |
|
4620 |
remaining := 50. |
|
4621 |
[con notNil and:[remaining > 0]] whileTrue:[ |
|
4622 |
sender := con sender. |
|
4623 |
'| ' print. con fullPrint. |
|
4624 |
||
4625 |
nSkipped := 0. |
|
4626 |
[sender notNil and:[sender sender notNil |
|
4627 |
and:[sender selector == con selector |
|
4628 |
and:[sender sender selector == con selector |
|
4629 |
and:[sender method == con method]]]]] whileTrue:[ |
|
4630 |
nSkipped := nSkipped + 1. |
|
4631 |
con := sender. |
|
4632 |
sender := con sender. |
|
4633 |
]. |
|
4634 |
nSkipped > 0 ifTrue:[ |
|
4635 |
'| ... ***** ' print. nSkipped print. ' recursive contexts skipped *****' printCR. |
|
4636 |
]. |
|
4637 |
con := sender. |
|
4638 |
remaining := remaining - 1 |
|
4639 |
]. |
|
4640 |
]. |
|
4641 |
^ RecursionInterruptSignal raiseSignal |
|
5755 | 4642 |
] |
4643 |
||
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4644 |
"Modified: / 10.11.2001 / 15:15:56 / cg" |
5755 | 4645 |
! |
4646 |
||
4647 |
schedulerInterrupt |
|
4648 |
"{ Pragma: +optSpace }" |
|
4649 |
||
4650 |
"scheduler interrupt (supposed to be sent to Processor). |
|
4651 |
If we arrive here, either the Processor does not understand it, |
|
4652 |
or it has been set to nil. In any case, this is a sign of some |
|
4653 |
big trouble. Enter debugger." |
|
4654 |
||
4655 |
self error:'schedulerInterrupt - but no Processor' mayProceed:true |
|
4656 |
! |
|
4657 |
||
4658 |
signalInterrupt:signalNumber |
|
4659 |
"{ Pragma: +optSpace }" |
|
4660 |
||
10460 | 4661 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
10016 | 4662 |
(SIGPIPE), others (SIGBUS) are rather fatal... |
5755 | 4663 |
In any case, IF a smalltalk-signal has been connected to the OS signal, |
4664 |
that one is raised. |
|
4665 |
Otherwise, a dialog is shown, asking the user on how to handle the |
|
4666 |
signal. |
|
4667 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
|
4668 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
4669 |
Currently (temporary kludge), these are passed as global variables." |
|
4670 |
||
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4671 |
|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
|
4672 |
action title screen| |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4673 |
|
5755 | 4674 |
"if there has been an ST-signal installed, use it ..." |
4675 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
4676 |
sig notNil ifTrue:[ |
|
10922 | 4677 |
sig raiseSignalWith:signalNumber. |
4678 |
^ self. |
|
5755 | 4679 |
]. |
4680 |
||
4681 |
"/ if handled, raise OSSignalInterruptSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4682 |
OSSignalInterrupt isHandled ifTrue:[ |
10922 | 4683 |
OSSignalInterrupt raiseRequestWith:signalNumber. |
4684 |
^ self. |
|
10460 | 4685 |
]. |
4686 |
||
4687 |
" |
|
4688 |
special cases |
|
10922 | 4689 |
- SIGPWR: power failure - write a crash image and continue |
4690 |
- SIGHUP: hang up - write a crash image and exit |
|
4691 |
" |
|
4692 |
(signalNumber == OperatingSystem sigPWR) ifTrue:[ |
|
4693 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
|
4694 |
^ self. |
|
4695 |
]. |
|
4696 |
(signalNumber == OperatingSystem sigHUP) ifTrue:[ |
|
4697 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
|
4698 |
'Object [info]: exit due to hangup signal.' errorPrintCR. |
|
4699 |
Smalltalk exit:1. |
|
7031 | 4700 |
]. |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4701 |
|
5755 | 4702 |
name := OperatingSystem nameForSignal:signalNumber. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4703 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4704 |
"if there is no screen at all, bring up a mini debugger" |
10460 | 4705 |
(Screen isNil |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4706 |
or:[(screen := Screen current) isNil |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
4707 |
or:[(screen := Screen default) isNil |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
4708 |
or:[screen isOpen not]]]) ifTrue:[ |
10922 | 4709 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4710 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4711 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4712 |
"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
|
4713 |
otherwise display stays locked" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4714 |
screen ungrabPointer; ungrabKeyboard. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4715 |
|
7031 | 4716 |
here := thisContext. |
4717 |
badContext := here sender. "the context, in which the signal occurred" |
|
4718 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4719 |
"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
|
4720 |
Screen currentScreenQuerySignal answer:screen do:[ |
10922 | 4721 |
" |
4722 |
SIGBUS, SIGSEGV and SIGILL do not make sense to ignore (i.e. continue) |
|
4723 |
since the system will retry the faulty instruction, which leads to |
|
4724 |
another signal - to avoid frustration, better not offer this option. |
|
4725 |
" |
|
4726 |
fatal := OperatingSystem isFatalSignal:signalNumber. |
|
4727 |
fatal ifTrue:[ |
|
4728 |
(Debugger isNil or:[here isRecursive]) ifTrue:[ |
|
4729 |
'Object [hard error]: signal ' errorPrint. signalNumber errorPrintCR. |
|
4730 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
4731 |
]. |
|
4732 |
" |
|
4733 |
a hard signal - go into debugger immediately |
|
4734 |
" |
|
4735 |
msg := 'OS-signal: ', name. |
|
4736 |
||
4737 |
"/ the IRQ-PC is passed as low-hi, to avoid the need |
|
4738 |
"/ to allocate a LargeInteger in the VM during signal |
|
4739 |
"/ time. I know, this is ugly. |
|
4740 |
||
4741 |
InterruptPcLow notNil ifTrue:[ |
|
4742 |
pc := InterruptPcLow + (InterruptPcHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
4743 |
pc ~~ 0 ifTrue:[ |
|
4744 |
msg := msg , ' PC=' , (pc printStringRadix:16) |
|
4745 |
]. |
|
4746 |
]. |
|
4747 |
InterruptAddrLow notNil ifTrue:[ |
|
4748 |
addr := InterruptAddrLow + (InterruptAddrHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
4749 |
addr ~~ 0 ifTrue:[ |
|
4750 |
msg := msg , ' ADDR=' , (addr printStringRadix:16) |
|
4751 |
]. |
|
4752 |
]. |
|
4753 |
Debugger enter:here withMessage:msg mayProceed:false. |
|
4754 |
"unreachable" |
|
4755 |
^ nil. |
|
4756 |
]. |
|
4757 |
||
4758 |
"if possible, open an option box asking the user what do. |
|
4759 |
Otherwise, start a debugger" |
|
4760 |
Dialog notNil ifTrue:[ |
|
4761 |
titles := #('save crash image' 'dump core' 'exit ST/X' 'debug'). |
|
4762 |
actions := #(save core exit debug). |
|
4763 |
||
4764 |
action := nil. |
|
4765 |
title := 'OS Signal caught (' , name, ')'. |
|
4766 |
title := (title , '\[in ST-process: ' , Processor activeProcess nameOrId ,']') withCRs. |
|
4767 |
||
4768 |
"/ if cought while in the scheduler or event dispatcher, |
|
4769 |
"/ a modal dialog is not possible ... |
|
4770 |
"/ (therefore, abort & return does not makes sense) |
|
4771 |
||
4772 |
Processor activeProcess isSystemProcess ifFalse:[ |
|
4773 |
titles := #('abort') , titles. |
|
4774 |
actions := #(abort), actions. |
|
4775 |
||
4776 |
badContext canReturn ifTrue:[ |
|
4777 |
titles := #('return') , titles. |
|
4778 |
actions := #(return), actions. |
|
4779 |
]. |
|
4780 |
]. |
|
4781 |
||
4782 |
fatal ifFalse:[ |
|
4783 |
titles := titles, #('ignore'). |
|
4784 |
actions := actions , #(ignore). |
|
4785 |
]. |
|
4786 |
action := Dialog choose:title |
|
4787 |
labels:titles |
|
4788 |
values:actions |
|
4789 |
default:(fatal ifTrue:[nil] ifFalse:[#ignore]). |
|
4790 |
||
4791 |
"Dialog may fail (if system process), default action is debug" |
|
4792 |
action isEmptyOrNil ifTrue:[action := #debug]. |
|
4793 |
] ifFalse:[ |
|
4794 |
action := #debug. |
|
4795 |
]. |
|
4796 |
||
4797 |
action == #save ifTrue:[ |
|
4798 |
ObjectMemory writeCrashImage |
|
4799 |
]. |
|
4800 |
action == #core ifTrue:[ |
|
4801 |
Smalltalk fatalAbort |
|
4802 |
]. |
|
4803 |
action == #exit ifTrue:[ |
|
4804 |
Smalltalk exit |
|
4805 |
]. |
|
4806 |
action == #return ifTrue:[ |
|
4807 |
badContext return |
|
4808 |
]. |
|
4809 |
action == #abort ifTrue:[ |
|
4810 |
AbortOperationRequest raise. |
|
4811 |
]. |
|
4812 |
||
4813 |
action == #debug ifTrue:[ |
|
4814 |
Debugger isNil ifTrue:[ |
|
4815 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
4816 |
]. |
|
4817 |
Debugger enter:here withMessage:('OS-Signal ', name) mayProceed:true. |
|
4818 |
]. |
|
4819 |
"action == #ignore" |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4820 |
]. |
10016 | 4821 |
|
4822 |
"Modified: / 29-09-2006 / 12:27:20 / cg" |
|
5755 | 4823 |
! |
4824 |
||
4825 |
spyInterrupt |
|
4826 |
"{ Pragma: +optSpace }" |
|
4827 |
||
4828 |
"spy interrupt and no handler - enter debugger" |
|
4829 |
||
4830 |
self error:'spy Interrupt - but no handler' mayProceed:true |
|
4831 |
! |
|
4832 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4833 |
startMiniDebuggerOrExit:text |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4834 |
"some critical condition happened. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4835 |
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
|
4836 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4837 |
MiniDebugger isNil ifTrue:[ |
10460 | 4838 |
"a system without debugging facilities (i.e. a standalone system) |
4839 |
output a message and exit." |
|
4840 |
('Object [error]: exit due to ', text, ' - and no debugger.') errorPrintCR. |
|
4841 |
OperatingSystem exit:99. |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4842 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4843 |
MiniDebugger enterWithMessage:text mayProceed:true. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4844 |
! |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4845 |
|
5755 | 4846 |
timerInterrupt |
4847 |
"{ Pragma: +optSpace }" |
|
4848 |
||
4849 |
"timer interrupt and no handler - enter debugger" |
|
4850 |
||
4851 |
self error:'timer Interrupt - but no handler' mayProceed:true |
|
4852 |
! |
|
4853 |
||
4854 |
userInterrupt |
|
4855 |
"{ Pragma: +optSpace }" |
|
4856 |
||
4857 |
"user (^c) interrupt. |
|
4858 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
4859 |
controlling tty (i.e. in the xterm)." |
|
4860 |
||
6466 | 4861 |
UserInterruptSignal raiseRequest |
5755 | 4862 |
! |
4863 |
||
4864 |
userInterruptIn:aContext |
|
4865 |
"{ Pragma: +optSpace }" |
|
4866 |
||
4867 |
"user (^c) interrupt - enter debugger, but show aContext |
|
10460 | 4868 |
as top-context. |
4869 |
This is used to hide any intermediate scheduler contexts, |
|
5755 | 4870 |
in case of an interrupted process. Typically, this is sent by |
4871 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
4872 |
processed." |
|
4873 |
||
4874 |
<context: #return> |
|
4875 |
||
4876 |
UserInterruptSignal raiseRequestWith:nil errorString:nil in:aContext |
|
4877 |
||
4878 |
"Created: / 18.10.1996 / 20:46:04 / cg" |
|
4879 |
"Modified: / 20.10.1996 / 13:06:38 / cg" |
|
4880 |
"Modified: / 26.7.1999 / 10:58:49 / stefan" |
|
4881 |
! ! |
|
4882 |
||
4883 |
!Object methodsFor:'message sending'! |
|
4884 |
||
4885 |
perform:aSelector |
|
4886 |
"send the message aSelector to the receiver" |
|
4887 |
||
4888 |
%{ |
|
4889 |
REGISTER OBJ sel = aSelector; |
|
4890 |
||
4891 |
if (InterruptPending == nil) { |
|
10460 | 4892 |
struct inlineCache *pIlc; |
4893 |
static struct inlineCache ilc_0 = __ILCPERF0(@line); |
|
4894 |
static struct inlineCache ilc_1 = __ILCPERF0(@line); |
|
4895 |
static struct inlineCache ilc_2 = __ILCPERF0(@line); |
|
4896 |
static struct inlineCache ilc_3 = __ILCPERF0(@line); |
|
4897 |
static struct inlineCache ilc_4 = __ILCPERF0(@line); |
|
4898 |
static OBJ last_0 = nil; |
|
4899 |
static OBJ last_1 = nil; |
|
4900 |
static OBJ last_2 = nil; |
|
4901 |
static OBJ last_3 = nil; |
|
4902 |
static OBJ last_4 = nil; |
|
4903 |
static flip = 0; |
|
4904 |
||
4905 |
if (sel == last_0) { |
|
4906 |
pIlc = &ilc_0; |
|
4907 |
} else if (sel == last_1) { |
|
4908 |
pIlc = &ilc_1; |
|
4909 |
} else if (sel == last_2) { |
|
4910 |
pIlc = &ilc_2; |
|
4911 |
} else if (sel == last_3) { |
|
4912 |
pIlc = &ilc_3; |
|
4913 |
} else if (sel == last_4) { |
|
4914 |
pIlc = &ilc_4; |
|
4915 |
} else { |
|
4916 |
if (flip == 0) { |
|
4917 |
pIlc = &ilc_0; |
|
4918 |
flip = 1; |
|
4919 |
last_0 = sel; |
|
4920 |
} else if (flip == 1) { |
|
4921 |
pIlc = &ilc_1; |
|
4922 |
flip = 2; |
|
4923 |
last_1 = sel; |
|
4924 |
} else if (flip == 2) { |
|
4925 |
pIlc = &ilc_2; |
|
4926 |
flip = 3; |
|
4927 |
last_2 = sel; |
|
4928 |
} else if (flip == 3) { |
|
4929 |
pIlc = &ilc_3; |
|
4930 |
flip = 4; |
|
4931 |
last_3 = sel; |
|
4932 |
} else { |
|
4933 |
pIlc = &ilc_4; |
|
4934 |
flip = 0; |
|
4935 |
last_4 = sel; |
|
4936 |
} |
|
4937 |
pIlc->ilc_func = __SEND0ADDR__; |
|
4938 |
if (pIlc->ilc_poly) { |
|
4939 |
__flushPolyCache(pIlc->ilc_poly); |
|
4940 |
pIlc->ilc_poly = 0; |
|
4941 |
} |
|
4942 |
} |
|
4943 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
|
5755 | 4944 |
} else { |
10460 | 4945 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
4946 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5755 | 4947 |
} |
4948 |
%}. |
|
4949 |
^ self perform:aSelector withArguments:#() |
|
4950 |
! |
|
4951 |
||
4952 |
perform:aSelector inClass:aClass withArguments:argArray |
|
10460 | 4953 |
"send the message aSelector with all args taken from argArray |
5755 | 4954 |
to the receiver as a super-send message. |
4955 |
This is actually more flexible than the normal super-send, since it allows |
|
4956 |
to execute a method in ANY superclass of the receiver (not just the |
|
4957 |
immediate superclass). |
|
10460 | 4958 |
Thus, it is (theoretically) possible to do |
4959 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
|
5755 | 4960 |
and evaluate Magnitudes compare method even if there was one in Number. |
4961 |
This method is used by the interpreter to evaluate super sends |
|
4962 |
and could be used for very special behavior (language extension ?). |
|
4963 |
||
4964 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
4965 |
||
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
4966 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 myClass| |
5755 | 4967 |
|
4968 |
" |
|
4969 |
check, if aClass is really a superclass of the receiver |
|
4970 |
" |
|
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
4971 |
myClass := self class. |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
4972 |
(myClass == aClass or:[myClass isSubclassOf:aClass]) ifFalse:[ |
10460 | 4973 |
self error:'lookup-class argument is not a superclass of the receiver'. |
4974 |
^ nil |
|
5755 | 4975 |
]. |
4976 |
%{ |
|
4977 |
REGISTER OBJ *argP; |
|
4978 |
int nargs, i; |
|
4979 |
||
8934 | 4980 |
if (__isArrayLike(argArray)) { |
10460 | 4981 |
nargs = __arraySize(argArray); |
4982 |
argP = __arrayVal(argArray); |
|
5755 | 4983 |
} else { |
10460 | 4984 |
if (__isNonNilObject(argArray)) { |
4985 |
static struct inlineCache ilcSize = __ILC0(@line+1); |
|
4986 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
4987 |
if (!__isSmallInteger(numberOfArgs)) |
|
4988 |
goto bad; |
|
4989 |
nargs = __intVal(numberOfArgs); |
|
4990 |
argP = (OBJ *)(&a1); |
|
4991 |
for (i=1; i <= nargs; i++) { |
|
4992 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
4993 |
} |
|
4994 |
argP = (OBJ *)(&a1); |
|
4995 |
} else { |
|
4996 |
nargs = 0; |
|
4997 |
} |
|
5755 | 4998 |
} |
4999 |
switch (nargs) { |
|
10460 | 5000 |
case 0: |
5001 |
{ |
|
5002 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5003 |
RETURN ( _SEND0(self, aSelector, aClass, &ilc0)); |
|
5004 |
} |
|
5005 |
||
5006 |
case 1: |
|
5007 |
{ |
|
5008 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5009 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, argP[0])); |
|
5010 |
} |
|
5011 |
||
5012 |
case 2: |
|
5013 |
{ |
|
5014 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5015 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, argP[0], argP[1])); |
|
5016 |
} |
|
5017 |
||
5018 |
case 3: |
|
5019 |
{ |
|
5020 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5021 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, |
|
5022 |
argP[0], argP[1], argP[2])); |
|
5023 |
} |
|
5024 |
||
5025 |
case 4: |
|
5026 |
{ |
|
5027 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
5028 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, |
|
5029 |
argP[0], argP[1], argP[2], argP[3])); |
|
5030 |
} |
|
5031 |
||
5032 |
case 5: |
|
5033 |
{ |
|
5034 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
5035 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
5036 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5037 |
} |
|
5038 |
||
5039 |
case 6: |
|
5040 |
{ |
|
5041 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
5042 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
5043 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5])); |
|
5044 |
} |
|
5045 |
||
5046 |
case 7: |
|
5047 |
{ |
|
5048 |
static struct inlineCache ilc7 = __DUMMYILCSELF7(@line+1); |
|
5049 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
5050 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5051 |
argP[6])); |
|
5052 |
} |
|
5053 |
||
5054 |
case 8: |
|
5055 |
{ |
|
5056 |
static struct inlineCache ilc8 = __DUMMYILCSELF8(@line+1); |
|
5057 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
5058 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5059 |
argP[6], argP[7])); |
|
5060 |
} |
|
5061 |
||
5062 |
case 9: |
|
5063 |
{ |
|
5064 |
static struct inlineCache ilc9 = __DUMMYILCSELF9(@line+1); |
|
5065 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
5066 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5067 |
argP[6], argP[7], argP[8])); |
|
5068 |
} |
|
5069 |
||
5070 |
case 10: |
|
5071 |
{ |
|
5072 |
static struct inlineCache ilc10 = __DUMMYILCSELF10(@line+1); |
|
5073 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
5074 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5075 |
argP[6], argP[7], argP[8], argP[9])); |
|
5076 |
} |
|
5077 |
||
5078 |
case 11: |
|
5079 |
{ |
|
5080 |
static struct inlineCache ilc11 = __DUMMYILCSELF11(@line+1); |
|
5081 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
5082 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5083 |
argP[6], argP[7], argP[8], argP[9], argP[10])); |
|
5084 |
} |
|
5085 |
||
5086 |
case 12: |
|
5087 |
{ |
|
5088 |
static struct inlineCache ilc12 = __DUMMYILCSELF12(@line+1); |
|
5089 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
5090 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5091 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5092 |
argP[11])); |
|
5093 |
} |
|
5094 |
||
5095 |
case 13: |
|
5096 |
{ |
|
5097 |
static struct inlineCache ilc13 = __DUMMYILCSELF13(@line+1); |
|
5098 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
5099 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5100 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5101 |
argP[11], argP[12])); |
|
5102 |
} |
|
5103 |
||
5104 |
case 14: |
|
5105 |
{ |
|
5106 |
static struct inlineCache ilc14 = __DUMMYILCSELF14(@line+1); |
|
5107 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
5108 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5109 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5110 |
argP[11], argP[12], argP[13])); |
|
5111 |
} |
|
5112 |
||
5113 |
case 15: |
|
5114 |
{ |
|
5115 |
static struct inlineCache ilc15 = __DUMMYILCSELF15(@line+1); |
|
5116 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
5117 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5118 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5119 |
argP[11], argP[12], argP[13], argP[14])); |
|
5120 |
} |
|
5755 | 5121 |
|
5122 |
#ifdef _SEND16 |
|
10460 | 5123 |
case 16: |
5124 |
{ |
|
5125 |
static struct inlineCache ilc16 = __DUMMYILCSELF16(@line+1); |
|
5126 |
RETURN ( _SEND16(self, aSelector, aClass, &ilc15, |
|
5127 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5128 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5129 |
argP[11], argP[12], argP[13], argP[14], argP[15])); |
|
5130 |
} |
|
5755 | 5131 |
#endif |
5132 |
#ifdef _SEND17 |
|
10460 | 5133 |
case 17: |
5134 |
{ |
|
5135 |
static struct inlineCache ilc17 = __DUMMYILCSELF17(@line+1); |
|
5136 |
RETURN ( _SEND17(self, aSelector, aClass, &ilc15, |
|
5137 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5138 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5139 |
argP[11], argP[12], argP[13], argP[14], argP[15], argP[16])); |
|
5140 |
} |
|
5755 | 5141 |
#endif |
5142 |
||
5143 |
||
5144 |
} |
|
5145 |
bad:; |
|
5146 |
%}. |
|
5147 |
"/ arrive here, if bad number of arguments (too many) |
|
5148 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5149 |
||
5150 |
^ self primitiveFailed |
|
5151 |
! |
|
5152 |
||
5153 |
perform:aSelector with:arg |
|
5154 |
"send the one-arg-message aSelector to the receiver" |
|
5155 |
||
5156 |
%{ |
|
5157 |
REGISTER OBJ sel = aSelector; |
|
5158 |
||
5159 |
if (InterruptPending == nil) { |
|
10460 | 5160 |
struct inlineCache *pIlc; |
5161 |
static struct inlineCache ilc_0 = __ILCPERF1(@line); |
|
5162 |
static struct inlineCache ilc_1 = __ILCPERF1(@line); |
|
5163 |
static struct inlineCache ilc_2 = __ILCPERF1(@line); |
|
5164 |
static struct inlineCache ilc_3 = __ILCPERF1(@line); |
|
5165 |
static struct inlineCache ilc_4 = __ILCPERF1(@line); |
|
5166 |
static OBJ last_0 = nil; |
|
5167 |
static OBJ last_1 = nil; |
|
5168 |
static OBJ last_2 = nil; |
|
5169 |
static OBJ last_3 = nil; |
|
5170 |
static OBJ last_4 = nil; |
|
5171 |
static flip = 0; |
|
5172 |
||
5173 |
if (sel == last_0) { |
|
5174 |
pIlc = &ilc_0; |
|
5175 |
} else if (sel == last_1) { |
|
5176 |
pIlc = &ilc_1; |
|
5177 |
} else if (sel == last_2) { |
|
5178 |
pIlc = &ilc_2; |
|
5179 |
} else if (sel == last_3) { |
|
5180 |
pIlc = &ilc_3; |
|
5181 |
} else if (sel == last_4) { |
|
5182 |
pIlc = &ilc_4; |
|
5183 |
} else { |
|
5184 |
if (flip == 0) { |
|
5185 |
pIlc = &ilc_0; |
|
5186 |
flip = 1; |
|
5187 |
last_0 = sel; |
|
5188 |
} else if (flip == 1) { |
|
5189 |
pIlc = &ilc_1; |
|
5190 |
flip = 2; |
|
5191 |
last_1 = sel; |
|
5192 |
} else if (flip == 2) { |
|
5193 |
pIlc = &ilc_2; |
|
5194 |
flip = 3; |
|
5195 |
last_2 = sel; |
|
5196 |
} else if (flip == 3) { |
|
5197 |
pIlc = &ilc_3; |
|
5198 |
flip = 4; |
|
5199 |
last_3 = sel; |
|
5200 |
} else { |
|
5201 |
pIlc = &ilc_4; |
|
5202 |
flip = 0; |
|
5203 |
last_4 = sel; |
|
5204 |
} |
|
5205 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5206 |
if (pIlc->ilc_poly) { |
|
5207 |
__flushPolyCache(pIlc->ilc_poly); |
|
5208 |
pIlc->ilc_poly = 0; |
|
5209 |
} |
|
5210 |
} |
|
5211 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
|
5755 | 5212 |
} else { |
10460 | 5213 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
5214 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
5755 | 5215 |
} |
5216 |
%}. |
|
5217 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5218 |
||
5219 |
! |
|
5220 |
||
5221 |
perform:aSelector with:arg1 with:arg2 |
|
5222 |
"send the two-arg-message aSelector to the receiver" |
|
5223 |
||
5224 |
%{ |
|
5225 |
struct inlineCache *pIlc; |
|
5226 |
||
5227 |
if (InterruptPending == nil) { |
|
10460 | 5228 |
static struct inlineCache ilc_0 = __ILCPERF2(@line); |
5229 |
static struct inlineCache ilc_1 = __ILCPERF2(@line); |
|
5230 |
static OBJ last_0 = nil; |
|
5231 |
static OBJ last_1 = nil; |
|
5232 |
static flip = 0; |
|
5233 |
||
5234 |
if (aSelector == last_0) { |
|
5235 |
pIlc = &ilc_0; |
|
5236 |
} else if (aSelector == last_1) { |
|
5237 |
pIlc = &ilc_1; |
|
5238 |
} else { |
|
5239 |
if (flip == 0) { |
|
5240 |
pIlc = &ilc_0; |
|
5241 |
flip = 1; |
|
5242 |
last_0 = aSelector; |
|
5243 |
} else { |
|
5244 |
pIlc = &ilc_1; |
|
5245 |
flip = 0; |
|
5246 |
last_1 = aSelector; |
|
5247 |
} |
|
5248 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5249 |
if (pIlc->ilc_poly) { |
|
5250 |
__flushPolyCache(pIlc->ilc_poly); |
|
5251 |
pIlc->ilc_poly = 0; |
|
5252 |
} |
|
5253 |
} |
|
5254 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
|
5755 | 5255 |
} else { |
10460 | 5256 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
5257 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, arg1, arg2)); |
|
5755 | 5258 |
} |
5259 |
%}. |
|
5260 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2) |
|
5261 |
||
5262 |
! |
|
5263 |
||
5264 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
|
5265 |
"send the three-arg-message aSelector to the receiver" |
|
5266 |
||
5267 |
%{ |
|
5268 |
struct inlineCache *pIlc; |
|
5269 |
static struct inlineCache ilc_0 = __ILCPERF3(@line); |
|
5270 |
static struct inlineCache ilc_1 = __ILCPERF3(@line); |
|
5271 |
static OBJ last_0 = nil; |
|
5272 |
static OBJ last_1 = nil; |
|
5273 |
static flip = 0; |
|
5274 |
||
5275 |
if (InterruptPending == nil) { |
|
10460 | 5276 |
if (aSelector != last_0) { |
5277 |
if (aSelector != last_1) { |
|
5278 |
if (flip) { |
|
5279 |
pIlc = &ilc_0; |
|
5280 |
flip = 0; |
|
5281 |
last_0 = aSelector; |
|
5282 |
} else { |
|
5283 |
pIlc = &ilc_1; |
|
5284 |
flip = 1; |
|
5285 |
last_1 = aSelector; |
|
5286 |
} |
|
5287 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5288 |
if (pIlc->ilc_poly) { |
|
5289 |
__flushPolyCache(pIlc->ilc_poly); |
|
5290 |
pIlc->ilc_poly = 0; |
|
5291 |
} |
|
5292 |
} else { |
|
5293 |
pIlc = &ilc_1; |
|
5294 |
} |
|
5295 |
} else { |
|
5296 |
pIlc = &ilc_0; |
|
5297 |
} |
|
5298 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
|
5755 | 5299 |
} else { |
10460 | 5300 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
5301 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, arg1, arg2, arg3)); |
|
5755 | 5302 |
} |
5303 |
%}. |
|
5304 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3) |
|
5305 |
||
5306 |
! |
|
5307 |
||
5308 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
5309 |
"send the four-arg-message aSelector to the receiver" |
|
5310 |
||
5311 |
%{ |
|
5312 |
struct inlineCache *pIlc; |
|
5313 |
static struct inlineCache ilc_0 = __ILCPERF4(@line); |
|
5314 |
static struct inlineCache ilc_1 = __ILCPERF4(@line); |
|
5315 |
static OBJ last_0 = nil; |
|
5316 |
static OBJ last_1 = nil; |
|
5317 |
static flip = 0; |
|
5318 |
||
5319 |
if (InterruptPending == nil) { |
|
10460 | 5320 |
if (aSelector != last_0) { |
5321 |
if (aSelector != last_1) { |
|
5322 |
if (flip) { |
|
5323 |
pIlc = &ilc_0; |
|
5324 |
flip = 0; |
|
5325 |
last_0 = aSelector; |
|
5326 |
} else { |
|
5327 |
pIlc = &ilc_1; |
|
5328 |
flip = 1; |
|
5329 |
last_1 = aSelector; |
|
5330 |
} |
|
5331 |
pIlc->ilc_func = __SEND4ADDR__; |
|
5332 |
if (pIlc->ilc_poly) { |
|
5333 |
__flushPolyCache(pIlc->ilc_poly); |
|
5334 |
pIlc->ilc_poly = 0; |
|
5335 |
} |
|
5336 |
} else { |
|
5337 |
pIlc = &ilc_1; |
|
5338 |
} |
|
5339 |
} else { |
|
5340 |
pIlc = &ilc_0; |
|
5341 |
} |
|
5342 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5343 |
arg1, arg2, arg3, arg4) ); |
|
5755 | 5344 |
} else { |
10460 | 5345 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
5346 |
RETURN (_SEND4(self, aSelector, nil, &ilc4, |
|
5347 |
arg1, arg2, arg3, arg4)); |
|
5755 | 5348 |
} |
5349 |
%}. |
|
5350 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
5351 |
||
5352 |
! |
|
5353 |
||
5354 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
5355 |
"send the five-arg-message aSelector to the receiver" |
|
5356 |
||
5357 |
%{ |
|
5358 |
struct inlineCache *pIlc; |
|
5359 |
static struct inlineCache ilc_0 = __ILCPERF5(@line); |
|
5360 |
static struct inlineCache ilc_1 = __ILCPERF5(@line); |
|
5361 |
static OBJ last_0 = nil; |
|
5362 |
static OBJ last_1 = nil; |
|
5363 |
static flip = 0; |
|
5364 |
||
5365 |
if (InterruptPending == nil) { |
|
10460 | 5366 |
if (aSelector != last_0) { |
5367 |
if (aSelector != last_1) { |
|
5368 |
if (flip) { |
|
5369 |
pIlc = &ilc_0; |
|
5370 |
flip = 0; |
|
5371 |
last_0 = aSelector; |
|
5372 |
} else { |
|
5373 |
pIlc = &ilc_1; |
|
5374 |
flip = 1; |
|
5375 |
last_1 = aSelector; |
|
5376 |
} |
|
5377 |
pIlc->ilc_func = __SEND5ADDR__; |
|
5378 |
if (pIlc->ilc_poly) { |
|
5379 |
__flushPolyCache(pIlc->ilc_poly); |
|
5380 |
pIlc->ilc_poly = 0; |
|
5381 |
} |
|
5382 |
} else { |
|
5383 |
pIlc = &ilc_1; |
|
5384 |
} |
|
5385 |
} else { |
|
5386 |
pIlc = &ilc_0; |
|
5387 |
} |
|
5388 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5389 |
arg1, arg2, arg3, arg4, arg5) ); |
|
5755 | 5390 |
} else { |
10460 | 5391 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
5392 |
RETURN (_SEND5(self, aSelector, nil, &ilc5, |
|
5393 |
arg1, arg2, arg3, arg4, arg5)); |
|
5755 | 5394 |
} |
5395 |
%}. |
|
5396 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
10460 | 5397 |
with:arg5) |
5755 | 5398 |
|
5399 |
! |
|
5400 |
||
5401 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
|
5402 |
"send the six-arg-message aSelector to the receiver" |
|
5403 |
||
5404 |
%{ |
|
5405 |
struct inlineCache *pIlc; |
|
5406 |
static struct inlineCache ilc_0 = __ILCPERF6(@line); |
|
5407 |
static struct inlineCache ilc_1 = __ILCPERF6(@line); |
|
5408 |
static OBJ last_0 = nil; |
|
5409 |
static OBJ last_1 = nil; |
|
5410 |
static flip = 0; |
|
5411 |
||
5412 |
if (InterruptPending == nil) { |
|
10460 | 5413 |
if (aSelector != last_0) { |
5414 |
if (aSelector != last_1) { |
|
5415 |
if (flip) { |
|
5416 |
pIlc = &ilc_0; |
|
5417 |
flip = 0; |
|
5418 |
last_0 = aSelector; |
|
5419 |
} else { |
|
5420 |
pIlc = &ilc_1; |
|
5421 |
flip = 1; |
|
5422 |
last_1 = aSelector; |
|
5423 |
} |
|
5424 |
pIlc->ilc_func = __SEND6ADDR__; |
|
5425 |
if (pIlc->ilc_poly) { |
|
5426 |
__flushPolyCache(pIlc->ilc_poly); |
|
5427 |
pIlc->ilc_poly = 0; |
|
5428 |
} |
|
5429 |
} else { |
|
5430 |
pIlc = &ilc_1; |
|
5431 |
} |
|
5432 |
} else { |
|
5433 |
pIlc = &ilc_0; |
|
5434 |
} |
|
5435 |
||
5436 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5437 |
arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
5755 | 5438 |
} else { |
10460 | 5439 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
5440 |
RETURN (_SEND6(self, aSelector, nil, &ilc6, |
|
5441 |
arg1, arg2, arg3, arg4, arg5, arg6)); |
|
5755 | 5442 |
} |
5443 |
%}. |
|
5444 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
10460 | 5445 |
with:arg5 with:arg6) |
5755 | 5446 |
|
5447 |
! |
|
5448 |
||
5449 |
perform:aSelector withArguments:argArray |
|
10460 | 5450 |
"send the message aSelector with all args taken from argArray |
5755 | 5451 |
to the receiver." |
5452 |
||
5453 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
5454 |
||
5455 |
%{ |
|
5456 |
REGISTER OBJ *argP; |
|
5457 |
int nargs; |
|
5458 |
OBJ l; |
|
5459 |
||
8934 | 5460 |
if (__isArrayLike(argArray)) { |
10460 | 5461 |
nargs = __arraySize(argArray); |
5462 |
argP = __arrayVal(argArray); |
|
5755 | 5463 |
} else { |
10460 | 5464 |
if (__isNonNilObject(argArray)) { |
5465 |
static struct inlineCache ilcSize = __ILC0(@line); |
|
5466 |
int i; |
|
5467 |
||
5468 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5469 |
if (!__isSmallInteger(numberOfArgs)) |
|
5470 |
goto bad; |
|
5471 |
nargs = __intVal(numberOfArgs); |
|
5472 |
argP = (OBJ *)(&a1); |
|
5473 |
for (i=1; i <= nargs; i++) { |
|
5474 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
5475 |
} |
|
5476 |
argP = (OBJ *)(&a1); |
|
5477 |
} else { |
|
5478 |
nargs = 0; |
|
5479 |
} |
|
5755 | 5480 |
} |
5481 |
switch (nargs) { |
|
10460 | 5482 |
case 0: |
5483 |
if (InterruptPending == nil) { |
|
5484 |
static OBJ last0_0 = nil; static struct inlineCache ilc0_0 = __ILCPERF0(@line); |
|
5485 |
static OBJ last0_1 = nil; static struct inlineCache ilc0_1 = __ILCPERF0(@line); |
|
5486 |
static OBJ last0_2 = nil; static struct inlineCache ilc0_2 = __ILCPERF0(@line); |
|
5487 |
static OBJ last0_3 = nil; static struct inlineCache ilc0_3 = __ILCPERF0(@line); |
|
5488 |
static int flip0 = 0; |
|
5489 |
struct inlineCache *pIlc; |
|
5490 |
||
5491 |
if (aSelector == last0_0) { |
|
5492 |
pIlc = &ilc0_0; |
|
5493 |
} else if (aSelector == last0_1) { |
|
5494 |
pIlc = &ilc0_1; |
|
5495 |
} else if (aSelector == last0_2) { |
|
5496 |
pIlc = &ilc0_2; |
|
5497 |
} else if (aSelector == last0_3) { |
|
5498 |
pIlc = &ilc0_3; |
|
5499 |
} else { |
|
5500 |
if (flip0 == 0) { |
|
5501 |
pIlc = &ilc0_0; |
|
5502 |
flip0 = 1; |
|
5503 |
last0_0 = aSelector; |
|
5504 |
} else if (flip0 == 1) { |
|
5505 |
pIlc = &ilc0_1; |
|
5506 |
flip0 = 2; |
|
5507 |
last0_1 = aSelector; |
|
5508 |
} else if (flip0 == 2) { |
|
5509 |
pIlc = &ilc0_2; |
|
5510 |
flip0 = 3; |
|
5511 |
last0_2 = aSelector; |
|
5512 |
} else { |
|
5513 |
pIlc = &ilc0_3; |
|
5514 |
flip0 = 0; |
|
5515 |
last0_3 = aSelector; |
|
5516 |
} |
|
5517 |
||
5518 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5519 |
if (pIlc->ilc_poly) { |
|
5520 |
__flushPolyCache(pIlc->ilc_poly); |
|
5521 |
pIlc->ilc_poly = 0; |
|
5522 |
} |
|
5523 |
} |
|
5524 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc)); |
|
5525 |
} else { |
|
5526 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5527 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5528 |
} |
|
5529 |
||
5530 |
case 1: |
|
5531 |
if (InterruptPending == nil) { |
|
5532 |
static OBJ last1_0 = nil; static struct inlineCache ilc1_0 = __ILCPERF1(@line); |
|
5533 |
static OBJ last1_1 = nil; static struct inlineCache ilc1_1 = __ILCPERF1(@line); |
|
5534 |
static OBJ last1_2 = nil; static struct inlineCache ilc1_2 = __ILCPERF1(@line); |
|
5535 |
static OBJ last1_3 = nil; static struct inlineCache ilc1_3 = __ILCPERF1(@line); |
|
5536 |
static int flip1 = 0; |
|
5537 |
struct inlineCache *pIlc; |
|
5538 |
||
5539 |
if (aSelector == last1_0) { |
|
5540 |
pIlc = &ilc1_0; |
|
5541 |
} else if (aSelector == last1_1) { |
|
5542 |
pIlc = &ilc1_1; |
|
5543 |
} else if (aSelector == last1_2) { |
|
5544 |
pIlc = &ilc1_2; |
|
5545 |
} else if (aSelector == last1_3) { |
|
5546 |
pIlc = &ilc1_3; |
|
5547 |
} else { |
|
5548 |
if (flip1 == 0) { |
|
5549 |
pIlc = &ilc1_0; |
|
5550 |
flip1 = 1; |
|
5551 |
last1_0 = aSelector; |
|
5552 |
} else if (flip1 == 1) { |
|
5553 |
pIlc = &ilc1_1; |
|
5554 |
flip1 = 2; |
|
5555 |
last1_1 = aSelector; |
|
5556 |
} else if (flip1 == 2) { |
|
5557 |
pIlc = &ilc1_2; |
|
5558 |
flip1 = 3; |
|
5559 |
last1_2 = aSelector; |
|
5560 |
} else { |
|
5561 |
pIlc = &ilc1_3; |
|
5562 |
flip1 = 0; |
|
5563 |
last1_3 = aSelector; |
|
5564 |
} |
|
5565 |
||
5566 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5567 |
if (pIlc->ilc_poly) { |
|
5568 |
__flushPolyCache(pIlc->ilc_poly); |
|
5569 |
pIlc->ilc_poly = 0; |
|
5570 |
} |
|
5571 |
} |
|
5572 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0])); |
|
5573 |
} else { |
|
5574 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5575 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, argP[0])); |
|
5576 |
} |
|
5577 |
||
5578 |
case 2: |
|
5579 |
if (InterruptPending == nil) { |
|
5580 |
static OBJ last2_0 = nil; static struct inlineCache ilc2_0 = __ILCPERF2(@line); |
|
5581 |
static OBJ last2_1 = nil; static struct inlineCache ilc2_1 = __ILCPERF2(@line); |
|
5582 |
static int flip2 = 0; |
|
5583 |
struct inlineCache *pIlc; |
|
5584 |
||
5585 |
if (aSelector == last2_0) { |
|
5586 |
pIlc = &ilc2_0; |
|
5587 |
} else if (aSelector == last2_1) { |
|
5588 |
pIlc = &ilc2_1; |
|
5589 |
} else { |
|
5590 |
if (flip2 == 0) { |
|
5591 |
pIlc = &ilc2_0; |
|
5592 |
flip2 = 1; |
|
5593 |
last2_0 = aSelector; |
|
5594 |
} else { |
|
5595 |
pIlc = &ilc2_1; |
|
5596 |
flip2 = 0; |
|
5597 |
last2_1 = aSelector; |
|
5598 |
} |
|
5599 |
||
5600 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5601 |
if (pIlc->ilc_poly) { |
|
5602 |
__flushPolyCache(pIlc->ilc_poly); |
|
5603 |
pIlc->ilc_poly = 0; |
|
5604 |
} |
|
5605 |
} |
|
5606 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1])); |
|
5607 |
} else { |
|
5608 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5609 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, argP[0], argP[1])); |
|
5610 |
} |
|
5611 |
||
5612 |
case 3: |
|
5613 |
if (InterruptPending == nil) { |
|
5614 |
static OBJ last3_0 = nil; static struct inlineCache ilc3_0 = __ILCPERF3(@line); |
|
5615 |
static OBJ last3_1 = nil; static struct inlineCache ilc3_1 = __ILCPERF3(@line); |
|
5616 |
static int flip3 = 0; |
|
5617 |
struct inlineCache *pIlc; |
|
5618 |
||
5619 |
if (aSelector == last3_0) { |
|
5620 |
pIlc = &ilc3_0; |
|
5621 |
} else if (aSelector == last3_1) { |
|
5622 |
pIlc = &ilc3_1; |
|
5623 |
} else { |
|
5624 |
if (flip3 == 0) { |
|
5625 |
pIlc = &ilc3_0; |
|
5626 |
flip3 = 1; |
|
5627 |
last3_0 = aSelector; |
|
5628 |
} else { |
|
5629 |
pIlc = &ilc3_1; |
|
5630 |
flip3 = 0; |
|
5631 |
last3_1 = aSelector; |
|
5632 |
} |
|
5633 |
||
5634 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5635 |
if (pIlc->ilc_poly) { |
|
5636 |
__flushPolyCache(pIlc->ilc_poly); |
|
5637 |
pIlc->ilc_poly = 0; |
|
5638 |
} |
|
5639 |
} |
|
5640 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1], argP[2])); |
|
5641 |
} else { |
|
5642 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5643 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, argP[0], argP[1], argP[2])); |
|
5644 |
} |
|
5645 |
||
5646 |
case 4: |
|
5647 |
{ |
|
5648 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(@line); |
|
5649 |
||
5650 |
if ((InterruptPending != nil) || (aSelector != last4)) { |
|
5651 |
ilc4.ilc_func = __SEND4ADDR__; |
|
5652 |
if (ilc4.ilc_poly) { |
|
5653 |
__flushPolyCache(ilc4.ilc_poly); |
|
5654 |
ilc4.ilc_poly = 0; |
|
5655 |
} |
|
5656 |
last4 = aSelector; |
|
5657 |
} |
|
5658 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
|
5659 |
argP[0], argP[1], argP[2], argP[3])); |
|
5660 |
} |
|
5661 |
||
5662 |
case 5: |
|
5663 |
{ |
|
5664 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(@line); |
|
5665 |
||
5666 |
if ((InterruptPending != nil) || (aSelector != last5)) { |
|
5667 |
ilc5.ilc_func = __SEND5ADDR__; |
|
5668 |
if (ilc5.ilc_poly) { |
|
5669 |
__flushPolyCache(ilc5.ilc_poly); |
|
5670 |
ilc5.ilc_poly = 0; |
|
5671 |
} |
|
5672 |
last5 = aSelector; |
|
5673 |
} |
|
5674 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
|
5675 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5676 |
} |
|
5677 |
||
5678 |
case 6: |
|
5679 |
{ |
|
5680 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(@line); |
|
5681 |
||
5682 |
if ((InterruptPending != nil) || (aSelector != last6)) { |
|
5683 |
ilc6.ilc_func = __SEND6ADDR__; |
|
5684 |
if (ilc6.ilc_poly) { |
|
5685 |
__flushPolyCache(ilc6.ilc_poly); |
|
5686 |
ilc6.ilc_poly = 0; |
|
5687 |
} |
|
5688 |
last6 = aSelector; |
|
5689 |
} |
|
5690 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
|
5691 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5692 |
argP[5])); |
|
5693 |
} |
|
5694 |
||
5695 |
case 7: |
|
5696 |
{ |
|
5697 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(@line); |
|
5698 |
||
5699 |
if ((InterruptPending != nil) || (aSelector != last7)) { |
|
5700 |
ilc7.ilc_func = __SEND7ADDR__; |
|
5701 |
if (ilc7.ilc_poly) { |
|
5702 |
__flushPolyCache(ilc7.ilc_poly); |
|
5703 |
ilc7.ilc_poly = 0; |
|
5704 |
} |
|
5705 |
last7 = aSelector; |
|
5706 |
} |
|
5707 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
|
5708 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5709 |
argP[5], argP[6])); |
|
5710 |
} |
|
5711 |
||
5712 |
case 8: |
|
5713 |
{ |
|
5714 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(@line); |
|
5715 |
||
5716 |
if ((InterruptPending != nil) || (aSelector != last8)) { |
|
5717 |
ilc8.ilc_func = __SEND8ADDR__; |
|
5718 |
if (ilc8.ilc_poly) { |
|
5719 |
__flushPolyCache(ilc8.ilc_poly); |
|
5720 |
ilc8.ilc_poly = 0; |
|
5721 |
} |
|
5722 |
last8 = aSelector; |
|
5723 |
} |
|
5724 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
|
5725 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5726 |
argP[5], argP[6], argP[7])); |
|
5727 |
} |
|
5728 |
||
5729 |
case 9: |
|
5730 |
{ |
|
5731 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(@line); |
|
5732 |
||
5733 |
if ((InterruptPending != nil) || (aSelector != last9)) { |
|
5734 |
ilc9.ilc_func = __SEND9ADDR__; |
|
5735 |
if (ilc9.ilc_poly) { |
|
5736 |
__flushPolyCache(ilc9.ilc_poly); |
|
5737 |
ilc9.ilc_poly = 0; |
|
5738 |
} |
|
5739 |
last9 = aSelector; |
|
5740 |
} |
|
5741 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
|
5742 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5743 |
argP[5], argP[6], argP[7], argP[8])); |
|
5744 |
} |
|
5745 |
||
5746 |
case 10: |
|
5747 |
{ |
|
5748 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(@line); |
|
5749 |
||
5750 |
if ((InterruptPending != nil) || (aSelector != last10)) { |
|
5751 |
ilc10.ilc_func = __SEND10ADDR__; |
|
5752 |
if (ilc10.ilc_poly) { |
|
5753 |
__flushPolyCache(ilc10.ilc_poly); |
|
5754 |
ilc10.ilc_poly = 0; |
|
5755 |
} |
|
5756 |
last10 = aSelector; |
|
5757 |
} |
|
5758 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
|
5759 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5760 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
5761 |
} |
|
5762 |
||
5763 |
case 11: |
|
5764 |
{ |
|
5765 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(@line); |
|
5766 |
||
5767 |
if ((InterruptPending != nil) || (aSelector != last11)) { |
|
5768 |
ilc11.ilc_func = __SEND11ADDR__; |
|
5769 |
if (ilc11.ilc_poly) { |
|
5770 |
__flushPolyCache(ilc11.ilc_poly); |
|
5771 |
ilc11.ilc_poly = 0; |
|
5772 |
} |
|
5773 |
last11 = aSelector; |
|
5774 |
} |
|
5775 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
|
5776 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5777 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5778 |
argP[10])); |
|
5779 |
} |
|
5780 |
||
5781 |
case 12: |
|
5782 |
{ |
|
5783 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(@line); |
|
5784 |
||
5785 |
if ((InterruptPending != nil) || (aSelector != last12)) { |
|
5786 |
ilc12.ilc_func = __SEND12ADDR__; |
|
5787 |
if (ilc12.ilc_poly) { |
|
5788 |
__flushPolyCache(ilc12.ilc_poly); |
|
5789 |
ilc12.ilc_poly = 0; |
|
5790 |
} |
|
5791 |
last12 = aSelector; |
|
5792 |
} |
|
5793 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
|
5794 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5795 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5796 |
argP[10], argP[11])); |
|
5797 |
} |
|
5798 |
||
5799 |
case 13: |
|
5800 |
{ |
|
5801 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(@line); |
|
5802 |
||
5803 |
if ((InterruptPending != nil) || (aSelector != last13)) { |
|
5804 |
ilc13.ilc_func = __SEND13ADDR__; |
|
5805 |
if (ilc13.ilc_poly) { |
|
5806 |
__flushPolyCache(ilc13.ilc_poly); |
|
5807 |
ilc13.ilc_poly = 0; |
|
5808 |
} |
|
5809 |
last13 = aSelector; |
|
5810 |
} |
|
5811 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
|
5812 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5813 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5814 |
argP[10], argP[11], argP[12])); |
|
5815 |
} |
|
5816 |
||
5817 |
case 14: |
|
5818 |
{ |
|
5819 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(@line); |
|
5820 |
||
5821 |
if ((InterruptPending != nil) || (aSelector != last14)) { |
|
5822 |
ilc14.ilc_func = __SEND14ADDR__; |
|
5823 |
if (ilc14.ilc_poly) { |
|
5824 |
__flushPolyCache(ilc14.ilc_poly); |
|
5825 |
ilc14.ilc_poly = 0; |
|
5826 |
} |
|
5827 |
last14 = aSelector; |
|
5828 |
} |
|
5829 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
|
5830 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5831 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5832 |
argP[10], argP[11], argP[12], argP[13])); |
|
5833 |
} |
|
5834 |
||
5835 |
case 15: |
|
5836 |
{ |
|
5837 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(@line); |
|
5838 |
||
5839 |
if ((InterruptPending != nil) || (aSelector != last15)) { |
|
5840 |
ilc15.ilc_func = __SEND15ADDR__; |
|
5841 |
if (ilc15.ilc_poly) { |
|
5842 |
__flushPolyCache(ilc15.ilc_poly); |
|
5843 |
ilc15.ilc_poly = 0; |
|
5844 |
} |
|
5845 |
last15 = aSelector; |
|
5846 |
} |
|
5847 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
|
5848 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5849 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5850 |
argP[10], argP[11], argP[12], argP[13], |
|
5851 |
argP[14])); |
|
5852 |
} |
|
5755 | 5853 |
} |
5854 |
bad:; |
|
5855 |
%}. |
|
5856 |
||
5857 |
"/ arrive here, if bad number of arguments (too many) |
|
5858 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5859 |
||
5860 |
^ self primitiveFailed |
|
5861 |
! |
|
5862 |
||
6316 | 5863 |
perform:aSelector withOptionalArgument:arg |
5864 |
"send aSelector-message to the receiver. |
|
6318 | 5865 |
If the message expects an argument, pass arg." |
6316 | 5866 |
|
5867 |
aSelector numArgs == 1 ifTrue:[ |
|
10460 | 5868 |
^ self perform:aSelector with:arg |
6316 | 5869 |
]. |
5870 |
^ self perform:aSelector |
|
6319 | 5871 |
|
5872 |
" |
|
5873 |
|rec sel| |
|
5874 |
||
5875 |
rec := -1. |
|
5876 |
sel := #abs. |
|
5877 |
rec perform:sel withOptionalArgument:2. |
|
5878 |
||
5879 |
sel := #max:. |
|
5880 |
rec perform:sel withOptionalArgument:2. |
|
5881 |
" |
|
6316 | 5882 |
! |
5883 |
||
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5884 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5885 |
"send aSelector-message to the receiver. |
6728 | 5886 |
Depending on the number of arguments the message expects, |
5887 |
pass either none, 1, or 2 arguments." |
|
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5888 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5889 |
|numArgs| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5890 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5891 |
numArgs := aSelector numArgs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5892 |
numArgs == 0 ifTrue:[ |
10460 | 5893 |
^ self perform:aSelector |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5894 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5895 |
numArgs == 1 ifTrue:[ |
10460 | 5896 |
^ self perform:aSelector with:optionalArg1 |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5897 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5898 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5899 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5900 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5901 |
|rec sel| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5902 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5903 |
rec := -1. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5904 |
sel := #abs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5905 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5906 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5907 |
sel := #max:. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5908 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5909 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5910 |
! |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
5911 |
|
6728 | 5912 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 |
5913 |
"send aSelector-message to the receiver. |
|
5914 |
Depending on the number of arguments the message expects, |
|
5915 |
pass either none, 1, 2 or 3 arguments." |
|
5916 |
||
5917 |
|numArgs| |
|
5918 |
||
5919 |
numArgs := aSelector numArgs. |
|
5920 |
numArgs == 0 ifTrue:[ |
|
10460 | 5921 |
^ self perform:aSelector |
6728 | 5922 |
]. |
5923 |
numArgs == 1 ifTrue:[ |
|
10460 | 5924 |
^ self perform:aSelector with:optionalArg1 |
6728 | 5925 |
]. |
5926 |
numArgs == 2 ifTrue:[ |
|
10460 | 5927 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6728 | 5928 |
]. |
5929 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3. |
|
5930 |
||
5931 |
" |
|
5932 |
|rec sel| |
|
5933 |
||
5934 |
rec := -1. |
|
5935 |
sel := #abs. |
|
5936 |
rec perform:sel withOptionalArgument:2. |
|
5937 |
||
5938 |
sel := #max:. |
|
5939 |
rec perform:sel withOptionalArgument:2. |
|
5940 |
" |
|
5941 |
! |
|
5942 |
||
6764 | 5943 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 and:optionalArg4 |
5944 |
"send aSelector-message to the receiver. |
|
5945 |
Depending on the number of arguments the message expects, |
|
5946 |
pass either none, 1, 2, 3 or 4 arguments." |
|
5947 |
||
5948 |
|numArgs| |
|
5949 |
||
5950 |
numArgs := aSelector numArgs. |
|
5951 |
numArgs == 0 ifTrue:[ |
|
10460 | 5952 |
^ self perform:aSelector |
6764 | 5953 |
]. |
5954 |
numArgs == 1 ifTrue:[ |
|
10460 | 5955 |
^ self perform:aSelector with:optionalArg1 |
6764 | 5956 |
]. |
5957 |
numArgs == 2 ifTrue:[ |
|
10460 | 5958 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6764 | 5959 |
]. |
5960 |
numArgs == 3 ifTrue:[ |
|
10460 | 5961 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 |
6764 | 5962 |
]. |
5963 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 with:optionalArg4. |
|
5964 |
||
5965 |
" |
|
5966 |
|rec sel| |
|
5967 |
||
5968 |
rec := -1. |
|
5969 |
sel := #abs. |
|
5970 |
rec perform:sel withOptionalArgument:2. |
|
5971 |
||
5972 |
sel := #max:. |
|
5973 |
rec perform:sel withOptionalArgument:2. |
|
5974 |
" |
|
5975 |
! |
|
5976 |
||
5755 | 5977 |
performMethod:aMethod |
5978 |
"invoke aMethod on the receiver. |
|
5979 |
The method should be a zero-argument method. |
|
5980 |
This is a non-object-oriented entry, applying a method |
|
5981 |
in a functional way on a receiver. |
|
5982 |
Warning: |
|
10460 | 5983 |
Take care for the method to be appropriate for the |
5984 |
receiver - no checking is done by the VM." |
|
5755 | 5985 |
|
5986 |
^ aMethod valueWithReceiver:self arguments:#() |
|
5987 |
||
5988 |
" |
|
5989 |
|mthd| |
|
5990 |
||
5991 |
mthd := SmallInteger compiledMethodAt:#negated. |
|
5992 |
Transcript showCR:(1 performMethod:mthd) |
|
5993 |
" |
|
5994 |
||
5995 |
"BAD USE example: |
|
5996 |
||
5997 |
|mthd| |
|
5998 |
||
5999 |
mthd := Point compiledMethodAt:#x. |
|
6000 |
Transcript showCR:((1->2) performMethod:mthd) |
|
6001 |
" |
|
6002 |
||
6003 |
"Modified: 31.7.1997 / 17:41:50 / cg" |
|
6004 |
! |
|
6005 |
||
6006 |
performMethod:aMethod arguments:argumentArray |
|
6007 |
"invoke aMethod on the receiver, passing an argumentArray. |
|
6008 |
The size of the argumentArray should match the number of args |
|
6009 |
expected by the method. |
|
6010 |
This is a non-object-oriented entry, applying a method |
|
6011 |
in a functional way on a receiver. |
|
6012 |
Warning: |
|
10460 | 6013 |
Take care for the method to be appropriate for the |
6014 |
receiver - no checking is done by the VM." |
|
5755 | 6015 |
|
6016 |
^ aMethod valueWithReceiver:self arguments:argumentArray |
|
6017 |
||
6018 |
" |
|
6019 |
|mthd| |
|
6020 |
||
6021 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6022 |
Transcript showCR:(1 performMethod:mthd arguments:#(2)) |
|
6023 |
" |
|
6024 |
||
6025 |
"Created: 31.7.1997 / 17:46:31 / cg" |
|
6026 |
! |
|
6027 |
||
6028 |
performMethod:aMethod with:arg |
|
6029 |
"invoke aMethod on the receiver, passing an argument. |
|
6030 |
The method should be a one-argument method. |
|
6031 |
This is a non-object-oriented entry, applying a method |
|
6032 |
in a functional way on a receiver. |
|
6033 |
Warning: |
|
10460 | 6034 |
Take care for the method to be appropriate for the |
6035 |
receiver - no checking is done by the VM." |
|
5755 | 6036 |
|
6037 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg) |
|
6038 |
||
6039 |
" |
|
6040 |
|mthd| |
|
6041 |
||
6042 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6043 |
Transcript showCR:(1 performMethod:mthd with:2) |
|
6044 |
" |
|
6045 |
||
6046 |
"Modified: 31.7.1997 / 17:42:32 / cg" |
|
6047 |
! |
|
6048 |
||
6049 |
performMethod:aMethod with:arg1 with:arg2 |
|
6050 |
"invoke aMethod on the receiver, passing two arguments. |
|
6051 |
The method should be a two-argument method. |
|
6052 |
This is a non-object-oriented entry, applying a method |
|
6053 |
in a functional way on a receiver. |
|
6054 |
Warning: |
|
10460 | 6055 |
Take care for the method to be appropriate for the |
6056 |
receiver - no checking is done by the VM." |
|
5755 | 6057 |
|
6058 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) |
|
6059 |
||
6060 |
" |
|
6061 |
|mthd arr| |
|
6062 |
||
6063 |
arr := Array new:1. |
|
6064 |
mthd := Array compiledMethodAt:#basicAt:put:. |
|
6065 |
arr performMethod:mthd with:1 with:'foo'. |
|
6066 |
Transcript showCR:arr |
|
6067 |
" |
|
6068 |
||
6069 |
"Modified: 31.7.1997 / 17:44:54 / cg" |
|
6070 |
! |
|
6071 |
||
6072 |
performMethod:aMethod with:arg1 with:arg2 with:arg3 |
|
6073 |
"invoke aMethod on the receiver, passing three arguments. |
|
6074 |
The method should be a three-argument method. |
|
6075 |
This is a non-object-oriented entry, applying a method |
|
6076 |
in a functional way on a receiver. |
|
6077 |
Warning: |
|
10460 | 6078 |
Take care for the method to be appropriate for the |
6079 |
receiver - no checking is done by the VM." |
|
5755 | 6080 |
|
6081 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3) |
|
6082 |
||
6083 |
"Created: 31.7.1997 / 17:45:20 / cg" |
|
6084 |
! ! |
|
6085 |
||
10834 | 6086 |
!Object methodsFor:'object persistency'! |
6087 |
||
6088 |
elementDescriptorFor:anAspectSymbol |
|
6089 |
"support for persistency: |
|
6090 |
answer a collection of associations containing the |
|
6091 |
objects state to be encoded for aspect. |
|
6092 |
Association key is the instance variable name or access selector, |
|
6093 |
association value is the contents of the instance variable. |
|
6094 |
||
6095 |
The default is to return the contents of all non-nil instance variables" |
|
6096 |
||
6097 |
|ret| |
|
6098 |
||
6099 |
ret := 0. |
|
6100 |
anAspectSymbol notNil ifTrue:[ |
|
6101 |
ret := self perform:anAspectSymbol ifNotUnderstood:[0]. |
|
6102 |
]. |
|
6103 |
ret == 0 ifTrue:[ |
|
6104 |
^ self elementDescriptorForNonNilInstanceVariables |
|
6105 |
]. |
|
6106 |
^ ret. |
|
6107 |
! |
|
6108 |
||
6109 |
elementDescriptorForInstanceVariables |
|
6110 |
"return all instance variables for visiting/encoding" |
|
6111 |
||
6112 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
|
6113 |
||
6114 |
" |
|
6115 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
6116 |
Dictionary new elementDescriptorForInstanceVariables |
|
6117 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
6118 |
" |
|
6119 |
! |
|
6120 |
||
6121 |
elementDescriptorForInstanceVariablesMatching:aBlock |
|
6122 |
"return all instance variables which conform to aBlock, for encoding/visiting. |
|
6123 |
Indexed vars are all included." |
|
6124 |
||
6125 |
|instVarNames theClass children |
|
6126 |
instSize "{ Class: SmallInteger }" |
|
6127 |
varSize "{ Class: SmallInteger }"| |
|
6128 |
||
6129 |
theClass := self class. |
|
6130 |
||
6131 |
instSize := theClass instSize. |
|
6132 |
varSize := theClass isVariable ifTrue:[self basicSize] ifFalse:[0]. |
|
6133 |
children := OrderedCollection new:(instSize + varSize). |
|
6134 |
||
6135 |
instVarNames := theClass allInstVarNames. |
|
6136 |
1 to:instSize do:[:i | |var| |
|
6137 |
var := self instVarAt:i. |
|
6138 |
(aBlock value:var) ifTrue:[ |
|
6139 |
children add:((instVarNames at:i) -> var) |
|
6140 |
] |
|
6141 |
]. |
|
6142 |
||
6143 |
varSize ~~ 0 ifTrue:[ |
|
6144 |
1 to:varSize do:[:i | |
|
6145 |
children add:(i -> (self basicAt:i)) |
|
6146 |
] |
|
6147 |
]. |
|
6148 |
||
6149 |
^ children. |
|
6150 |
||
6151 |
" |
|
6152 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
6153 |
Dictionary new elementDescriptorForInstanceVariables |
|
6154 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
6155 |
" |
|
6156 |
! |
|
6157 |
||
6158 |
elementDescriptorForNonNilInstanceVariables |
|
6159 |
"return all non-nil instance variables for visiting/encoding" |
|
6160 |
||
6161 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | val notNil]. |
|
6162 |
||
6163 |
" |
|
6164 |
#(1 2 3 nil true symbol) elementDescriptorForNonNilInstanceVariables |
|
6165 |
Dictionary new elementDescriptorForNonNilInstanceVariables |
|
6166 |
(5 @ nil) elementDescriptorForNonNilInstanceVariables |
|
6167 |
" |
|
6168 |
! ! |
|
6169 |
||
5755 | 6170 |
!Object methodsFor:'printing & storing'! |
6171 |
||
6235 | 6172 |
basicPrintOn:aStream |
6173 |
"append the receivers className with an articel to the argument, aStream" |
|
6174 |
||
6175 |
aStream nextPutAll:self classNameWithArticle |
|
6176 |
! |
|
6177 |
||
5755 | 6178 |
className |
6179 |
"return the classname of the receivers class" |
|
6180 |
||
6181 |
^ self class name |
|
6182 |
||
6183 |
" |
|
6184 |
1 className |
|
10460 | 6185 |
1 class className |
5755 | 6186 |
$a className |
9105 | 6187 |
$a class className |
5755 | 6188 |
" |
6189 |
! |
|
6190 |
||
6191 |
classNameWithArticle |
|
6192 |
"return a string consisting of classname preceeded by an article. |
|
6193 |
(dont expect me to write national variants for this ... :-) |
|
6194 |
If you have special preferences, redefine it ..." |
|
6195 |
||
6829 | 6196 |
| cls| |
5755 | 6197 |
|
6198 |
(cls := self class) == self ifTrue:[ |
|
10460 | 6199 |
^ 'a funny object' |
5755 | 6200 |
]. |
6829 | 6201 |
^ cls nameWithArticle |
5755 | 6202 |
|
6203 |
" |
|
10460 | 6204 |
1 classNameWithArticle |
6205 |
(1->2) classNameWithArticle |
|
5755 | 6206 |
XWorkstation basicNew classNameWithArticle |
10460 | 6207 |
XWorkstation classNameWithArticle |
5755 | 6208 |
" |
6209 |
||
6210 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
6211 |
! |
|
6212 |
||
6213 |
errorPrint |
|
10530
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
6214 |
"print the receiver on the Transcript. |
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
6215 |
The Transcript is directed to the standard error stream on |
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
6216 |
headless applications." |
5755 | 6217 |
|
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6218 |
|s| |
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6219 |
|
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6220 |
s := Processor activeProcess isSystemProcess |
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6221 |
ifTrue:Stderr |
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6222 |
ifFalse:Transcript. |
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
6223 |
StreamError catch:[ |
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6224 |
self printOn:s |
5755 | 6225 |
] |
6226 |
||
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6227 |
"Modified: / 29-05-2007 / 20:00:54 / cg" |
5755 | 6228 |
! |
6229 |
||
6230 |
errorPrintCR |
|
6231 |
"{ Pragma: +optSpace }" |
|
6232 |
||
10530
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
6233 |
"print the receiver followed by a cr on the standard error stream. |
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
6234 |
The Transcript is directed to the standard error stream on |
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
6235 |
headless applications." |
5755 | 6236 |
|
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6237 |
|s| |
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6238 |
|
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6239 |
s := Processor activeProcess isSystemProcess |
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6240 |
ifTrue:Stderr |
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6241 |
ifFalse:Transcript. |
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
6242 |
StreamError catch:[ |
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6243 |
self printOn:s. |
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6244 |
s cr |
5755 | 6245 |
] |
6246 |
||
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6247 |
"Created: / 20-05-1996 / 10:20:41 / cg" |
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6248 |
"Modified: / 29-05-2007 / 20:00:49 / cg" |
5755 | 6249 |
! |
6250 |
||
6251 |
errorPrintNL |
|
6252 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6253 |
<resource:#obsolete> |
5755 | 6254 |
|
6255 |
"print the receiver followed by a cr on the standard error stream. |
|
6256 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6257 |
||
6258 |
^ self errorPrintCR |
|
6259 |
||
6260 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
6261 |
! |
|
6262 |
||
6263 |
errorPrintNewline |
|
6264 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6265 |
<resource:#obsolete> |
5755 | 6266 |
|
6267 |
"print the receiver followed by a cr on the standard error stream. |
|
6268 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6269 |
||
6270 |
self errorPrintCR. |
|
6271 |
||
6272 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
6273 |
! |
|
6274 |
||
6275 |
infoPrint |
|
6276 |
"{ Pragma: +optSpace }" |
|
6277 |
||
6278 |
"print the receiver on the standard error stream. |
|
6279 |
This is meant for information messages which are not warnings |
|
6280 |
or fatal messages. |
|
6281 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6282 |
||
6283 |
InfoPrinting == true ifTrue:[ |
|
10460 | 6284 |
self errorPrint |
5755 | 6285 |
] |
6286 |
! |
|
6287 |
||
6288 |
infoPrintCR |
|
6289 |
"{ Pragma: +optSpace }" |
|
6290 |
||
6291 |
"print the receiver followed by a cr on the standard error stream. |
|
6292 |
This is meant for information messages which are not warnings |
|
6293 |
or fatal messages. |
|
6294 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6295 |
||
6296 |
InfoPrinting == true ifTrue:[ |
|
10460 | 6297 |
self errorPrintCR |
5755 | 6298 |
] |
6299 |
||
6300 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
6301 |
! |
|
6302 |
||
6303 |
infoPrintNL |
|
6304 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6305 |
<resource:#obsolete> |
5755 | 6306 |
|
6307 |
"print the receiver followed by a cr on the standard error stream. |
|
6308 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
6309 |
||
6310 |
^ self infoPrintCR |
|
6311 |
! |
|
6312 |
||
6313 |
||
6314 |
"print the receiver on the standard output stream (which is not the Transcript)" |
|
6315 |
||
6316 |
"/ the following allows printCR to be used during |
|
6317 |
"/ the early init-phase, when no Stdout has been set up. |
|
6318 |
"/ (depends on string to respond to #print) |
|
6319 |
||
6320 |
Stdout isNil ifTrue:[ |
|
10460 | 6321 |
self printString print. |
6322 |
^ self |
|
5755 | 6323 |
]. |
6324 |
self printOn:Stdout |
|
6325 |
||
6326 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
6327 |
! |
|
6328 |
||
6329 |
printCR |
|
6330 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
|
6331 |
||
6332 |
"/ the following allows printCR to be used during |
|
6333 |
"/ the early init-phase, when no Stdout has been set up. |
|
6334 |
"/ (depends on string to respond to #printCR) |
|
6335 |
||
6336 |
Stdout isNil ifTrue:[ |
|
10460 | 6337 |
self printString printCR. |
6338 |
^ self |
|
5755 | 6339 |
]. |
6340 |
self printOn:Stdout. |
|
6341 |
Stdout cr |
|
6342 |
||
6343 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
6344 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
|
6345 |
! |
|
6346 |
||
6347 |
printNL |
|
6348 |
"print the receiver followed by a cr on the standard output stream |
|
6349 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
6350 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6351 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6352 |
|
5755 | 6353 |
^ self printCR |
6354 |
||
6355 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
6356 |
! |
|
6357 |
||
6358 |
printNewline |
|
6359 |
"print the receiver followed by a cr on the standard output stream. |
|
6360 |
This exists for backward compatibility - please use #printCR." |
|
6361 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6362 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6363 |
|
5755 | 6364 |
self printCR |
6365 |
||
6366 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
6367 |
! |
|
6368 |
||
6369 |
printOn:aStream |
|
6370 |
"append a user printed representation of the receiver to aStream. |
|
6371 |
The format is suitable for a human - not meant to be read back. |
|
6372 |
||
6373 |
The default here is to output the receivers class name. |
|
6374 |
BUT: this method is heavily redefined for objects which |
|
6375 |
can print prettier." |
|
6376 |
||
6235 | 6377 |
self basicPrintOn:aStream. |
6378 |
||
6379 |
" |
|
6380 |
(1@2) printOn:Transcript |
|
6381 |
(1@2) basicPrintOn:Transcript |
|
6382 |
" |
|
5755 | 6383 |
! |
6384 |
||
6385 |
printOn:aStream leftPaddedTo:size |
|
6386 |
"print the receiver on aStream, padding with spaces up to size. |
|
6387 |
padding is done on the left." |
|
6388 |
||
6389 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
6390 |
||
6391 |
" |
|
6392 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
6393 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
6394 |
" |
|
6395 |
! |
|
6396 |
||
6397 |
printOn:aStream leftPaddedTo:size with:padCharacter |
|
6398 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
6399 |
padding is done on the left." |
|
6400 |
||
6401 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
6402 |
||
6403 |
" |
|
6404 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
6405 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
6406 |
" |
|
6407 |
! |
|
6408 |
||
6409 |
printOn:aStream paddedTo:size |
|
6410 |
"print the receiver on aStream, padding with spaces up to size." |
|
6411 |
||
6412 |
self printOn:aStream paddedTo:size with:(Character space) |
|
6413 |
||
6414 |
" |
|
6415 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
6416 |
" |
|
6417 |
! |
|
6418 |
||
6419 |
printOn:aStream paddedTo:size with:padCharacter |
|
6420 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
6421 |
||
6422 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
6423 |
||
6424 |
" |
|
6425 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
6426 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
6427 |
" |
|
6428 |
! |
|
6429 |
||
6430 |
printOn:aStream zeroPaddedTo:size |
|
6431 |
"print the receiver on aStream, padding with zeros up to size. |
|
6432 |
Usually used with float numbers." |
|
6433 |
||
6434 |
self printOn:aStream paddedTo:size with:$0. |
|
6435 |
||
6436 |
" |
|
6437 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
6438 |
" |
|
6439 |
! |
|
6440 |
||
6441 |
printRightAdjustLen:size |
|
6442 |
"obsolete - just a name confusion. |
|
6443 |
This method will go away ..." |
|
6444 |
||
6445 |
(self printStringLeftPaddedTo:size) printOn:Stdout |
|
6446 |
! |
|
6447 |
||
6448 |
printString |
|
6449 |
"return a string for printing the receiver. |
|
6450 |
Since we now use printOn: as the basic print mechanism, |
|
6451 |
we have to create a stream and print into it." |
|
6452 |
||
6453 |
|s| |
|
6454 |
||
8300
d15ead94361f
Use CharacterWriteStream in #printString (speedup)
Stefan Vogel <sv@exept.de>
parents:
8287
diff
changeset
|
6455 |
s := CharacterWriteStream on:(String basicNew:30). |
5755 | 6456 |
self printOn:s. |
8300
d15ead94361f
Use CharacterWriteStream in #printString (speedup)
Stefan Vogel <sv@exept.de>
parents:
8287
diff
changeset
|
6457 |
^ s contents. |
7978
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6458 |
|
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6459 |
" |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6460 |
Date today printString. |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6461 |
" |
5755 | 6462 |
! |
6463 |
||
6464 |
printStringLeftPaddedTo:size |
|
6465 |
"return my printString as a right-adjusted string of length size; |
|
6466 |
characters on the left are filled with spaces. |
|
10460 | 6467 |
If the printString is longer than size, |
5755 | 6468 |
it is returned unchanged (i.e. not truncated)" |
6469 |
||
6470 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
6471 |
||
6472 |
" |
|
6473 |
10 printStringLeftPaddedTo:10 |
|
6474 |
1 printStringLeftPaddedTo:10 |
|
6475 |
" |
|
6476 |
! |
|
6477 |
||
6478 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
6479 |
"return my printString as a right-adjusted string of length size; |
|
6480 |
characters on the left are filled with spaces. |
|
6481 |
If the printString is larger than size, |
|
6482 |
return the result from evaluating alternative." |
|
6483 |
||
6484 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
6485 |
||
6486 |
" |
|
6487 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6488 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6489 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6490 |
" |
|
6491 |
! |
|
6492 |
||
6493 |
printStringLeftPaddedTo:size with:padCharacter |
|
6494 |
"return my printString as a right-adjusted string of length size; |
|
6495 |
characters on the left are filled with padCharacter. |
|
10460 | 6496 |
If the printString is longer than size, |
5755 | 6497 |
it is returned unchanged (i.e. not truncated)" |
6498 |
||
6499 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
6500 |
||
6501 |
" |
|
10460 | 6502 |
123 printStringLeftPaddedTo:10 with:$. |
6503 |
1 printStringLeftPaddedTo:10 with:$. |
|
5755 | 6504 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
6505 |
" |
|
6506 |
! |
|
6507 |
||
6508 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
6509 |
"return my printString as a right-adjusted string of length size; |
|
6510 |
characters on the left are filled with padCharacter. |
|
6511 |
If the printString is larger than size, |
|
6512 |
return the result from evaluating alternative." |
|
6513 |
||
6514 |
|s| |
|
6515 |
||
6516 |
s := self printString. |
|
6517 |
s size > size ifTrue:[^ alternative value]. |
|
6518 |
^ s leftPaddedTo:size with:padCharacter |
|
6519 |
||
6520 |
" |
|
10460 | 6521 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
6522 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6523 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
5755 | 6524 |
" |
6525 |
! |
|
6526 |
||
8576 | 6527 |
printStringLimitedTo:sizeLimit |
6528 |
"return a string for printing the receiver, but limit the result string in its size." |
|
6529 |
||
6530 |
|s| |
|
6531 |
||
6532 |
s := CharacterWriteStream on:(String basicNew:30). |
|
6533 |
s writeLimit:sizeLimit. |
|
6534 |
self printOn:s. |
|
6535 |
^ s contents. |
|
6536 |
||
6537 |
" |
|
6538 |
Date today printStringLimitedTo:5. |
|
10460 | 6539 |
'12345678901234567890' printStringLimitedTo:5. |
8576 | 6540 |
" |
6541 |
! |
|
6542 |
||
5755 | 6543 |
printStringOnError:exceptionBlock |
6544 |
"return a string for printing the receiver; if any error occurs, return the result from |
|
6545 |
evaluating exceptionBlock. Useful to print something in an exceptionHandler or other |
|
6546 |
cleanup code." |
|
6547 |
||
6548 |
|rslt| |
|
6549 |
||
6550 |
Error handle:[:ex | |
|
10460 | 6551 |
rslt := exceptionBlock value |
5755 | 6552 |
] do:[ |
10460 | 6553 |
rslt := self printString |
5755 | 6554 |
]. |
6555 |
^ rslt |
|
6556 |
! |
|
6557 |
||
6558 |
printStringPaddedTo:size |
|
6559 |
"return a printed representation of the receiver, |
|
6560 |
padded with spaces (at the right) up to size. |
|
10460 | 6561 |
If the printString is longer than size, |
5755 | 6562 |
it is returned unchanged (i.e. not truncated)" |
6563 |
||
6564 |
^ self printStringPaddedTo:size with:(Character space) |
|
6565 |
||
6566 |
" |
|
10460 | 6567 |
123 printStringPaddedTo:10 |
6568 |
1234567890123456 printStringPaddedTo:10 |
|
6569 |
'hello' printStringPaddedTo:10 |
|
5755 | 6570 |
" |
6571 |
! |
|
6572 |
||
6573 |
printStringPaddedTo:size ifLarger:alternative |
|
6574 |
"return a printed representation of the receiver, |
|
6575 |
padded with spaces (at the right) up to size. |
|
10460 | 6576 |
If the resulting printString is too large, |
5755 | 6577 |
return the result from evaluating alternative." |
6578 |
||
6579 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
6580 |
||
6581 |
" |
|
10460 | 6582 |
12 printStringPaddedTo:3 ifLarger:['***'] |
6583 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
6584 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
5755 | 6585 |
" |
6586 |
! |
|
6587 |
||
6588 |
printStringPaddedTo:size with:padCharacter |
|
6589 |
"return a printed representation of the receiver, |
|
6590 |
padded with padCharacter (at the right) up to size. |
|
10460 | 6591 |
If the printString is longer than size, |
5755 | 6592 |
it is returned unchanged (i.e. not truncated)" |
6593 |
||
6594 |
^ (self printString) paddedTo:size with:padCharacter |
|
6595 |
||
6596 |
" |
|
6597 |
123 printStringPaddedTo:10 with:$. |
|
6598 |
123 printStringPaddedTo:10 with:$* |
|
10460 | 6599 |
123 printStringPaddedTo:3 with:$* |
6600 |
1234 printStringPaddedTo:3 with:$* |
|
5755 | 6601 |
" |
6602 |
! |
|
6603 |
||
6604 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
6605 |
"return a printed representation of the receiver, |
|
6606 |
padded with padCharacter (at the right) up to size. |
|
10460 | 6607 |
If the resulting printString is too large, |
5755 | 6608 |
return the result from evaluating alternative." |
6609 |
||
6610 |
|s| |
|
6611 |
||
6612 |
s := self printString. |
|
6613 |
s size > size ifTrue:[^ alternative value]. |
|
6614 |
^ s paddedTo:size with:padCharacter |
|
6615 |
||
6616 |
" |
|
6617 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6618 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6619 |
" |
|
6620 |
! |
|
6621 |
||
6622 |
printStringRightAdjustLen:size |
|
6623 |
"obsolete - just a name confusion. |
|
6624 |
This method will go away ..." |
|
6625 |
||
6626 |
^ self printStringLeftPaddedTo:size |
|
6627 |
! |
|
6628 |
||
6629 |
printStringZeroPaddedTo:size |
|
10460 | 6630 |
"return a printed representation of the receiver, |
5755 | 6631 |
padded with zero (at the right) characters up to size. |
6632 |
Usually used with float numbers." |
|
6633 |
||
6634 |
^ self printStringPaddedTo:size with:$0 |
|
6635 |
||
6636 |
" |
|
10460 | 6637 |
123.0 printStringZeroPaddedTo:10 |
5755 | 6638 |
" |
6639 |
! |
|
6640 |
||
8287 | 6641 |
printfPrintString:ignoredFormat |
6642 |
"fallback to default printString |
|
6643 |
(for compatibility with float and integer-printing)" |
|
6644 |
||
6645 |
^ self printString |
|
6646 |
! |
|
6647 |
||
5755 | 6648 |
store |
6649 |
"store the receiver on standard output. |
|
6650 |
this method is useless, but included for compatibility." |
|
6651 |
||
6652 |
self storeOn:Stdout |
|
6653 |
! |
|
6654 |
||
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6655 |
storeArrayElementOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6656 |
"store an object as an Array element. |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6657 |
Subclasses may redefine this to omit a leading '#'" |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6658 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6659 |
^ self storeOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6660 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6661 |
|
5755 | 6662 |
storeCR |
6663 |
"store the receiver on standard output; append a carriage return." |
|
6664 |
||
6665 |
self store. |
|
6666 |
Character cr print |
|
6667 |
||
6668 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
6669 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
6670 |
! |
|
6671 |
||
6672 |
storeNl |
|
6673 |
"store the receiver on standard output; append a newline. |
|
6674 |
This method is included for backward compatibility- use #storeCR." |
|
6675 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6676 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6677 |
|
5755 | 6678 |
self storeCR. |
6679 |
||
6680 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
6681 |
! |
|
6682 |
||
6683 |
storeOn:aStream |
|
6684 |
"store the receiver on aStream; i.e. print an expression which will |
|
6685 |
reconstruct the receiver. |
|
6686 |
Notice, that no self referencing or cyclic objects can be represented |
|
6687 |
in this format. |
|
6688 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6689 |
||
6690 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
6691 |
||
6692 |
thisContext isRecursive ifTrue:[ |
|
10460 | 6693 |
Object recursiveStoreStringSignal raiseRequestWith:self. |
6694 |
('Object [error]: storeString of self referencing object.') errorPrintCR. |
|
6695 |
aStream nextPutAll:'#("recursive")'. |
|
6696 |
^ self |
|
5755 | 6697 |
]. |
6698 |
||
6699 |
myClass := self class. |
|
6700 |
aStream nextPut:$(. |
|
6701 |
aStream nextPutAll:self class name. |
|
6702 |
||
6703 |
hasSemi := false. |
|
6704 |
myClass isVariable ifTrue:[ |
|
10460 | 6705 |
aStream nextPutAll:' basicNew:'. |
6706 |
self basicSize printOn:aStream |
|
5755 | 6707 |
] ifFalse:[ |
10460 | 6708 |
aStream nextPutAll:' basicNew' |
5755 | 6709 |
]. |
6710 |
||
6711 |
sz := myClass instSize. |
|
10460 | 6712 |
1 to:sz do:[:i | |
6713 |
aStream nextPutAll:' instVarAt:'. |
|
6714 |
i printOn:aStream. |
|
6715 |
aStream nextPutAll:' put:'. |
|
6716 |
(self instVarAt:i) storeOn:aStream. |
|
6717 |
aStream nextPut:$;. |
|
6718 |
hasSemi := true |
|
5755 | 6719 |
]. |
6720 |
myClass isVariable ifTrue:[ |
|
10460 | 6721 |
sz := self basicSize. |
6722 |
1 to:sz do:[:i | |
|
6723 |
aStream nextPutAll:' basicAt:'. |
|
6724 |
i printOn:aStream. |
|
6725 |
aStream nextPutAll:' put:'. |
|
6726 |
(self basicAt:i) storeOn:aStream. |
|
6727 |
aStream nextPut:$;. |
|
6728 |
hasSemi := true |
|
6729 |
] |
|
5755 | 6730 |
]. |
6731 |
hasSemi ifTrue:[ |
|
10460 | 6732 |
aStream nextPutAll:' yourself' |
5755 | 6733 |
]. |
6734 |
aStream nextPut:$). |
|
6735 |
||
6736 |
" |
|
6737 |
|s| |
|
6738 |
||
6739 |
s := WriteStream on:(String new). |
|
6740 |
('hello' -> 'world') storeOn:s. |
|
6741 |
s := ReadStream on:(s contents). |
|
6742 |
(Object readFrom:s) inspect |
|
6743 |
" |
|
6744 |
" |
|
6745 |
|s| |
|
6746 |
||
6747 |
s := 'data' asFilename writeStream. |
|
6748 |
('hello' -> 'world') storeOn:s. |
|
6749 |
s close. |
|
6750 |
||
6751 |
s := 'data' asFilename readStream. |
|
6752 |
(Object readFrom:s) inspect |
|
6753 |
" |
|
6754 |
||
6755 |
"does not work example:" |
|
6756 |
" |
|
6757 |
|s a| |
|
6758 |
||
6759 |
a := Array new:2. |
|
6760 |
a at:1 put:a. |
|
6761 |
||
6762 |
s := 'data' asFilename writeStream. |
|
6763 |
a storeOn:s. |
|
6764 |
s close. |
|
6765 |
||
6766 |
s := 'data' asFilename readStream. |
|
6767 |
(Object readFrom:s) inspect |
|
6768 |
" |
|
6769 |
||
6770 |
"Modified: 28.1.1997 / 00:36:12 / cg" |
|
6771 |
! |
|
6772 |
||
6773 |
storeString |
|
6774 |
"return a string representing an expression to reconstruct the receiver. |
|
6775 |
Notice, that no self referencing or cyclic objects can be represented |
|
6776 |
in this format. |
|
6777 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6778 |
||
6779 |
|s| |
|
6780 |
||
6781 |
s := WriteStream on:(String new:50). |
|
6782 |
self storeOn:s. |
|
6783 |
^ s contents |
|
6784 |
! ! |
|
6785 |
||
6786 |
!Object methodsFor:'queries'! |
|
6787 |
||
6788 |
basicSize |
|
6789 |
"return the number of the receivers indexed instance variables, |
|
6790 |
0 if it has none. |
|
6791 |
||
6792 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
6793 |
||
6794 |
%{ /* NOCONTEXT */ |
|
6795 |
||
8909 | 6796 |
REGISTER INT nbytes; |
5755 | 6797 |
REGISTER OBJ myClass; |
6798 |
int nInstBytes; |
|
6799 |
||
6800 |
/* |
|
6801 |
* notice the missing test for self being a nonNilObject - |
|
6802 |
* this can be done since basicSize is defined both in UndefinedObject |
|
6803 |
* and SmallInteger |
|
6804 |
*/ |
|
6805 |
myClass = __qClass(self); |
|
6806 |
nbytes = __qSize(self); |
|
6807 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) ); |
|
6808 |
||
6809 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
10460 | 6810 |
case __MASKSMALLINT(POINTERARRAY): |
6811 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
6812 |
nbytes -= nInstBytes; |
|
6813 |
RETURN ( __mkSmallInteger(__BYTES2OBJS__(nbytes)) ); |
|
6814 |
||
6815 |
case __MASKSMALLINT(BYTEARRAY): |
|
6816 |
nbytes -= nInstBytes; |
|
6817 |
RETURN ( __mkSmallInteger(nbytes / sizeof(char)) ); |
|
6818 |
||
6819 |
case __MASKSMALLINT(FLOATARRAY): |
|
6820 |
nbytes -= nInstBytes; |
|
6821 |
RETURN ( __mkSmallInteger(nbytes / sizeof(float)) ); |
|
6822 |
||
6823 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 6824 |
#ifdef __NEED_DOUBLE_ALIGN |
10460 | 6825 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
5755 | 6826 |
#endif |
10460 | 6827 |
nbytes -= nInstBytes; |
6828 |
RETURN ( __mkSmallInteger(nbytes / sizeof(double)) ); |
|
6829 |
||
6830 |
case __MASKSMALLINT(WORDARRAY): |
|
6831 |
case __MASKSMALLINT(SWORDARRAY): |
|
6832 |
nbytes -= nInstBytes; |
|
6833 |
RETURN ( __mkSmallInteger(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */ |
|
6834 |
||
6835 |
case __MASKSMALLINT(LONGARRAY): |
|
6836 |
case __MASKSMALLINT(SLONGARRAY): |
|
6837 |
nbytes -= nInstBytes; |
|
6838 |
RETURN ( __mkSmallInteger(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */ |
|
6839 |
||
6840 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
6841 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 6842 |
#ifdef __NEED_LONGLONG_ALIGN |
10460 | 6843 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
5755 | 6844 |
#endif |
10460 | 6845 |
nbytes -= nInstBytes; |
6846 |
RETURN ( __mkSmallInteger(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */ |
|
5755 | 6847 |
} |
6848 |
%}. |
|
6849 |
^ 0 |
|
6850 |
! |
|
6851 |
||
6852 |
byteSize |
|
6853 |
"return the number of bytes in the receivers indexed instance variables, |
|
6854 |
0 if it has none. This only returns non-zero for non-pointer indexed |
|
6855 |
instvars i.e. byteArrays, wordArrays etc. |
|
6856 |
Notice: for Strings the returned size may look strange. |
|
6857 |
Only useful with binary storage." |
|
6858 |
||
6859 |
|myClass| |
|
6860 |
||
6861 |
myClass := self class. |
|
6862 |
myClass isVariable ifTrue:[ |
|
10460 | 6863 |
myClass isPointers ifFalse:[ |
6864 |
myClass isBytes ifTrue:[ |
|
6865 |
^ self basicSize. |
|
6866 |
]. |
|
6867 |
myClass isWords ifTrue:[ |
|
6868 |
^ self basicSize * 2. |
|
6869 |
]. |
|
6870 |
myClass isSignedWords ifTrue:[ |
|
6871 |
^ self basicSize * 2. |
|
6872 |
]. |
|
6873 |
myClass isLongs ifTrue:[ |
|
6874 |
^ self basicSize * 4. |
|
6875 |
]. |
|
6876 |
myClass isSignedLongs ifTrue:[ |
|
6877 |
^ self basicSize * 4. |
|
6878 |
]. |
|
6879 |
myClass isLongLongs ifTrue:[ |
|
6880 |
^ self basicSize * 8. |
|
6881 |
]. |
|
6882 |
myClass isSignedLongLongs ifTrue:[ |
|
6883 |
^ self basicSize * 8. |
|
6884 |
]. |
|
6885 |
myClass isFloats ifTrue:[ |
|
6886 |
^ self basicSize * (ExternalBytes sizeofFloat) |
|
6887 |
]. |
|
6888 |
myClass isDoubles ifTrue:[ |
|
6889 |
^ self basicSize * (ExternalBytes sizeofDouble) |
|
6890 |
]. |
|
6891 |
self error:'unknown variable size class species'. |
|
6892 |
] |
|
5755 | 6893 |
]. |
6894 |
^ 0 |
|
6895 |
||
6896 |
" |
|
10460 | 6897 |
Point new byteSize |
6898 |
'hello' byteSize |
|
6899 |
(ByteArray with:1 with:2) byteSize |
|
6900 |
(FloatArray with:1.5) byteSize |
|
6901 |
(DoubleArray with:1.5) byteSize |
|
6902 |
(WordArray with:1 with:2) byteSize |
|
5755 | 6903 |
" |
6904 |
! |
|
6905 |
||
6906 |
class |
|
6907 |
"return the receivers class" |
|
6908 |
||
6909 |
%{ /* NOCONTEXT */ |
|
6910 |
||
6911 |
RETURN ( __Class(self) ); |
|
6912 |
%} |
|
6913 |
! |
|
6914 |
||
6915 |
respondsTo:aSelector |
|
6916 |
"return true, if the receiver implements a method with selector equal |
|
6917 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
6918 |
receivers class or one of its superclasses. |
|
6919 |
||
6920 |
Notice, that this does not imply, that such a message can be sent without |
|
6921 |
an error being raised. For example, an implementation could send |
|
6922 |
#shouldNotImplement or #subclassResponsibility." |
|
6923 |
||
6924 |
" |
|
6925 |
should we go via the cache, or search (by class) ? |
|
6926 |
The first is faster, most of the time; while the 2nd fills |
|
6927 |
the cache with useless data if this is sent in a loop over all objects. |
|
6928 |
For now, use the cache ... |
|
6929 |
" |
|
6930 |
%{ /* NOCONTEXT */ |
|
6931 |
||
6932 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
10460 | 6933 |
RETURN ( false ); |
5755 | 6934 |
} |
6935 |
RETURN ( true ); |
|
6936 |
%} |
|
6937 |
. |
|
6938 |
^ self class canUnderstand:aSelector |
|
6939 |
||
6940 |
||
6941 |
"'aString' respondsTo:#+" |
|
6942 |
"'aString' respondsTo:#," |
|
6943 |
"'aString' respondsTo:#collect:" |
|
6944 |
! |
|
6945 |
||
6946 |
respondsToArithmetic |
|
6947 |
"return true, if the receiver responds to arithmetic messages. |
|
6948 |
false is returned here - the method is redefined in ArithmeticValue." |
|
6949 |
||
6950 |
^ false |
|
6951 |
! |
|
6952 |
||
6953 |
size |
|
6954 |
"return the number of the receivers indexed instance variables; |
|
6955 |
this method may be redefined in subclasses" |
|
6956 |
||
6957 |
^ self basicSize |
|
6958 |
! |
|
6959 |
||
6960 |
species |
|
6961 |
"return a class which is similar to (or the same as) the receivers class. |
|
6962 |
This is used to create an appropriate object when creating derived |
|
6963 |
copies in the collection classes (sometimes redefined)." |
|
6964 |
||
6965 |
^ self class |
|
6966 |
! |
|
6967 |
||
6968 |
yourself |
|
6969 |
"return the receiver - used for cascades to return self at the end" |
|
6970 |
||
6971 |
^ self |
|
6972 |
! ! |
|
6973 |
||
6974 |
!Object methodsFor:'secure message sending'! |
|
6975 |
||
6976 |
askFor:aSelector |
|
6977 |
"try to send the receiver the message, aSelector. |
|
10460 | 6978 |
If it does not understand it, return false. |
5755 | 6979 |
Otherwise the real value returned. |
6980 |
Useful to send messages such as: #isColor to unknown |
|
6981 |
receivers." |
|
6982 |
||
6983 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
6984 |
||
6985 |
" |
|
10460 | 6986 |
1 askFor:#isColor |
6987 |
Color red askFor:#isColor |
|
6988 |
||
6989 |
1 askFor:#isFoo |
|
6990 |
Color red askFor:#isFoo |
|
5755 | 6991 |
" |
6992 |
! |
|
6993 |
||
6994 |
perform:aSelector ifNotUnderstood:exceptionBlock |
|
6995 |
"try to send message aSelector to the receiver. |
|
6996 |
If its understood, return the methods returned value, |
|
6997 |
otherwise return the value of the exceptionBlock" |
|
6998 |
||
6999 |
|val ok| |
|
7000 |
||
6146 | 7001 |
MessageNotUnderstood handle:[:ex | |
10460 | 7002 |
"/ reject, if the bad message is not the one |
7003 |
"/ we have sent originally |
|
7004 |
ex selector == aSelector ifFalse:[ |
|
7005 |
ex reject |
|
7006 |
]. |
|
7007 |
ex receiver == self ifFalse:[ |
|
7008 |
ex reject |
|
7009 |
]. |
|
5755 | 7010 |
] do:[ |
10460 | 7011 |
val := self perform:aSelector. |
7012 |
ok := true. |
|
5755 | 7013 |
]. |
7014 |
ok isNil ifTrue:[ |
|
10460 | 7015 |
^ exceptionBlock value |
5755 | 7016 |
]. |
7017 |
^ val |
|
7018 |
||
7019 |
" |
|
10460 | 7020 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
7021 |
1.2345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7022 |
12345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
5755 | 7023 |
" |
7024 |
! |
|
7025 |
||
7026 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
7027 |
"try to send message aSelector to the receiver. |
|
7028 |
If its understood, return the methods returned value, |
|
7029 |
otherwise return the value of the exceptionBlock" |
|
7030 |
||
7031 |
|val ok| |
|
7032 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7033 |
MessageNotUnderstood handle:[:ex | |
10460 | 7034 |
"/ reject, if the bad message is not the one |
7035 |
"/ we have sent originally |
|
7036 |
ex selector == aSelector ifFalse:[ |
|
7037 |
ex reject |
|
7038 |
]. |
|
7039 |
ex receiver == self ifFalse:[ |
|
7040 |
ex reject |
|
7041 |
] |
|
5755 | 7042 |
] do:[ |
10460 | 7043 |
val := self perform:aSelector with:argument. |
7044 |
ok := true. |
|
5755 | 7045 |
]. |
7046 |
ok isNil ifTrue:[ |
|
10460 | 7047 |
^ exceptionBlock value |
5755 | 7048 |
]. |
7049 |
^ val |
|
7050 |
||
7051 |
" |
|
7052 |
|unknown| |
|
7053 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7054 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7055 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 7056 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7057 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 7058 |
" |
7059 |
! |
|
7060 |
||
5926 | 7061 |
perform:aSelector with:arg1 with:arg2 ifNotUnderstood:exceptionBlock |
7062 |
"try to send message aSelector to the receiver. |
|
7063 |
If its understood, return the methods returned value, |
|
7064 |
otherwise return the value of the exceptionBlock" |
|
7065 |
||
7066 |
|val ok| |
|
7067 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7068 |
MessageNotUnderstood handle:[:ex | |
10460 | 7069 |
"/ reject, if the bad message is not the one |
7070 |
"/ we have sent originally |
|
7071 |
ex selector == aSelector ifFalse:[ |
|
7072 |
ex reject |
|
7073 |
]. |
|
7074 |
ex receiver == self ifFalse:[ |
|
7075 |
ex reject |
|
7076 |
] |
|
5926 | 7077 |
] do:[ |
10460 | 7078 |
val := self perform:aSelector with:arg1 with:arg2. |
7079 |
ok := true. |
|
5926 | 7080 |
]. |
7081 |
ok isNil ifTrue:[ |
|
10460 | 7082 |
^ exceptionBlock value |
5926 | 7083 |
]. |
7084 |
^ val |
|
7085 |
! |
|
7086 |
||
5755 | 7087 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
7088 |
"try to send message aSelector to the receiver. |
|
7089 |
If its understood, return the methods returned value, |
|
7090 |
otherwise return the value of the exceptionBlock" |
|
7091 |
||
7092 |
|val ok| |
|
7093 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7094 |
MessageNotUnderstood handle:[:ex | |
10460 | 7095 |
"/ reject, if the bad message is not the one |
7096 |
"/ we have sent originally |
|
7097 |
ex selector == aSelector ifFalse:[ |
|
7098 |
ex reject |
|
7099 |
]. |
|
7100 |
ex receiver == self ifFalse:[ |
|
7101 |
ex reject |
|
7102 |
] |
|
5755 | 7103 |
] do:[ |
10460 | 7104 |
val := self perform:aSelector withArguments:argumentArray. |
7105 |
ok := true. |
|
5755 | 7106 |
]. |
7107 |
ok isNil ifTrue:[ |
|
10460 | 7108 |
^ exceptionBlock value |
5755 | 7109 |
]. |
7110 |
^ val |
|
7111 |
||
7112 |
" |
|
7113 |
|unknown| |
|
7114 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7115 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7116 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 7117 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7118 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 7119 |
" |
7120 |
||
7121 |
"Modified: 27.3.1997 / 14:13:16 / cg" |
|
7122 |
! ! |
|
7123 |
||
7124 |
!Object methodsFor:'signal constants'! |
|
7125 |
||
7126 |
messageNotUnderstoodSignal |
|
6146 | 7127 |
^ MessageNotUnderstood |
5755 | 7128 |
|
7129 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
7130 |
! ! |
|
7131 |
||
7132 |
!Object methodsFor:'special queries'! |
|
7133 |
||
7134 |
allOwners |
|
7135 |
"return a collection of all objects referencing the receiver" |
|
7136 |
||
7137 |
^ ObjectMemory whoReferences:self |
|
7138 |
! |
|
7139 |
||
7140 |
references:anObject |
|
7141 |
"return true, if the receiver refers to the argument, anObject. |
|
7142 |
- for debugging only" |
|
7143 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7144 |
^ self referencesObject:anObject |
5755 | 7145 |
|
7146 |
" |
|
7147 |
|v| |
|
7148 |
||
7149 |
v := View new initialize. |
|
10460 | 7150 |
v references:Display. |
5755 | 7151 |
" |
7152 |
! |
|
7153 |
||
7154 |
referencesAny:aCollection |
|
10460 | 7155 |
"return true, if the receiver refers to any object from |
5755 | 7156 |
the argument, aCollection. |
7157 |
- for debugging only" |
|
7158 |
||
10460 | 7159 |
%{ |
5755 | 7160 |
OBJ cls, flags; |
7161 |
int nInsts, inst; |
|
7162 |
||
7163 |
if (! __isNonNilObject(self)) { |
|
10460 | 7164 |
RETURN (false); |
5755 | 7165 |
} |
7166 |
||
8934 | 7167 |
if (__isArrayLike(aCollection)) { |
10460 | 7168 |
int nObjs = __arraySize(aCollection); |
7169 |
char *minAddr = 0, *maxAddr = 0; |
|
7170 |
||
7171 |
if (nObjs == 0) { |
|
7172 |
RETURN (false); |
|
7173 |
} |
|
7174 |
||
7175 |
/* |
|
7176 |
* a little optimization: use the fact that all old objects |
|
7177 |
* refering to a new object are on the remSet; if I am not, |
|
7178 |
* a trivial reject is possible, if all objects are newbees. |
|
7179 |
* as a side effect, gather min/max addresses |
|
7180 |
*/ |
|
7181 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
7182 |
int allNewBees = 1; |
|
7183 |
int i; |
|
7184 |
||
7185 |
minAddr = (char *)(__ArrayInstPtr(aCollection)->a_element[0]); |
|
7186 |
maxAddr = minAddr; |
|
7187 |
||
7188 |
for (i=0; i<nObjs; i++) { |
|
7189 |
OBJ anObject; |
|
7190 |
||
7191 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7192 |
||
7193 |
if (__isNonNilObject(anObject)) { |
|
7194 |
int spc; |
|
7195 |
||
7196 |
if (((spc = __qSpace(anObject)) != NEWSPACE) && (spc != SURVSPACE)) { |
|
7197 |
allNewBees = 0; |
|
7198 |
} |
|
7199 |
} |
|
7200 |
||
7201 |
if ((char *)anObject < minAddr) { |
|
7202 |
minAddr = (char *)anObject; |
|
7203 |
} else if ((char *)anObject > maxAddr) { |
|
7204 |
maxAddr = (char *)anObject; |
|
7205 |
} |
|
7206 |
} |
|
7207 |
if (allNewBees) { |
|
7208 |
RETURN (false); |
|
7209 |
} |
|
7210 |
} |
|
7211 |
||
7212 |
/* |
|
7213 |
* fetch min/max in searchList (if not already done) |
|
7214 |
*/ |
|
7215 |
if (minAddr == 0) { |
|
7216 |
int i; |
|
7217 |
||
7218 |
for (i=0; i<nObjs; i++) { |
|
7219 |
OBJ anObject; |
|
7220 |
||
7221 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7222 |
if ((char *)anObject < minAddr) { |
|
7223 |
minAddr = (char *)anObject; |
|
7224 |
} else if ((char *)anObject > maxAddr) { |
|
7225 |
maxAddr = (char *)anObject; |
|
7226 |
} |
|
7227 |
} |
|
7228 |
} |
|
7229 |
||
7230 |
cls = __qClass(self); |
|
7231 |
if (((char *)cls >= minAddr) && ((char *)cls <= maxAddr)) { |
|
5755 | 7232 |
#if defined(memsrch4) |
10460 | 7233 |
if (memsrch4(__arrayVal(aCollection), (INT)cls, nObjs)) { |
7234 |
RETURN (true); |
|
7235 |
} |
|
5755 | 7236 |
#else |
10460 | 7237 |
int i; |
7238 |
||
7239 |
for (i=0; i<nObjs; i++) { |
|
7240 |
OBJ anObject; |
|
7241 |
||
7242 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7243 |
if (cls == anObject) { |
|
7244 |
RETURN (true); |
|
7245 |
} |
|
7246 |
} |
|
5755 | 7247 |
#endif /* memsrch4 */ |
10460 | 7248 |
} |
7249 |
||
7250 |
flags = __ClassInstPtr(cls)->c_flags; |
|
7251 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
7252 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
7253 |
} else { |
|
7254 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
7255 |
} |
|
7256 |
if (! nInsts) { |
|
7257 |
RETURN (false); |
|
7258 |
} |
|
7259 |
||
7260 |
if (nObjs == 1) { |
|
7261 |
/* better reverse the loop */ |
|
7262 |
OBJ anObject; |
|
7263 |
||
7264 |
anObject = __ArrayInstPtr(aCollection)->a_element[0]; |
|
5755 | 7265 |
#if defined(memsrch4) |
10460 | 7266 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
7267 |
RETURN (true); |
|
7268 |
} |
|
5755 | 7269 |
#else |
10460 | 7270 |
for (inst=0; inst<nInsts; inst++) { |
7271 |
if ((__InstPtr(self)->i_instvars[inst]) == anObject) { |
|
7272 |
RETURN (true); |
|
7273 |
} |
|
7274 |
} |
|
5755 | 7275 |
#endif |
10460 | 7276 |
RETURN (false); |
7277 |
} |
|
7278 |
||
7279 |
for (inst=0; inst<nInsts; inst++) { |
|
7280 |
OBJ instVar = __InstPtr(self)->i_instvars[inst]; |
|
7281 |
int i; |
|
7282 |
||
7283 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
5755 | 7284 |
#if defined(memsrch4) |
10460 | 7285 |
if (memsrch4(__arrayVal(aCollection), (INT)instVar, nObjs)) { |
7286 |
RETURN (true); |
|
7287 |
} |
|
5755 | 7288 |
#else |
10460 | 7289 |
for (i=0; i<nObjs; i++) { |
7290 |
OBJ anObject; |
|
7291 |
||
7292 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7293 |
if (instVar == anObject) { |
|
7294 |
RETURN (true); |
|
7295 |
} |
|
7296 |
} |
|
5755 | 7297 |
#endif /* memsrch4 */ |
10460 | 7298 |
} |
7299 |
} |
|
7300 |
RETURN (false); |
|
5755 | 7301 |
} |
7302 |
%}. |
|
7303 |
||
7304 |
aCollection do:[:el | |
|
10460 | 7305 |
(self referencesObject:el) ifTrue:[^ true]. |
5755 | 7306 |
]. |
7307 |
^ false |
|
7308 |
! |
|
7309 |
||
7310 |
referencesDerivedInstanceOf:aClass |
|
7311 |
"return true, if the receiver refers to an instance of |
|
7312 |
the argument, aClass or its subclass. This method exists |
|
7313 |
to support searching for users of a class." |
|
7314 |
||
10460 | 7315 |
|myClass |
5755 | 7316 |
numInst "{ Class: SmallInteger }" | |
7317 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7318 |
"check the class" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7319 |
(self isKindOf:aClass) ifTrue:[^ true]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7320 |
|
5755 | 7321 |
myClass := self class. |
7322 |
"check the instance variables" |
|
7323 |
numInst := myClass instSize. |
|
10460 | 7324 |
1 to:numInst do:[:i | |
7325 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
5755 | 7326 |
]. |
7327 |
||
7328 |
"check the indexed variables" |
|
7329 |
myClass isVariable ifTrue:[ |
|
10460 | 7330 |
myClass isPointers ifFalse:[ |
7331 |
"no need to search in non pointer fields" |
|
7332 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
|
7333 |
]. |
|
7334 |
numInst := self basicSize. |
|
7335 |
1 to:numInst do:[:i | |
|
7336 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
7337 |
] |
|
5755 | 7338 |
]. |
7339 |
^ false |
|
7340 |
||
7341 |
" |
|
10460 | 7342 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
7343 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
7344 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
5755 | 7345 |
" |
7346 |
! |
|
7347 |
||
9279 | 7348 |
referencesForWhich:checkBlock do:actionBlock |
7349 |
|myClass inst |
|
7350 |
numInst "{ Class: SmallInteger }" | |
|
7351 |
||
7352 |
myClass := self class. |
|
7353 |
"check the instance variables" |
|
7354 |
numInst := myClass instSize. |
|
10460 | 7355 |
1 to:numInst do:[:i | |
7356 |
inst := self instVarAt:i. |
|
7357 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
9279 | 7358 |
]. |
7359 |
||
7360 |
"check the indexed variables" |
|
7361 |
myClass isVariable ifTrue:[ |
|
10460 | 7362 |
myClass isPointers ifTrue:[ |
7363 |
"no need to search in non pointer fields" |
|
7364 |
||
7365 |
numInst := self basicSize. |
|
7366 |
1 to:numInst do:[:i | |
|
7367 |
inst := self basicAt:i. |
|
7368 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
7369 |
] |
|
7370 |
] |
|
7371 |
]. |
|
7372 |
||
7373 |
" |
|
7374 |
(1 @ 3.4) referencesForWhich:[:i | i isFloat] do:[:i | Transcript showCR:i] |
|
9279 | 7375 |
" |
7376 |
! |
|
7377 |
||
5755 | 7378 |
referencesInstanceOf:aClass |
7379 |
"return true, if the receiver refers to an instance of |
|
7380 |
the argument, aClass.This method exists |
|
7381 |
to support searching for users of a class." |
|
7382 |
||
10460 | 7383 |
|myClass |
5755 | 7384 |
numInst "{ Class: SmallInteger }" | |
7385 |
||
7386 |
myClass := self class. |
|
7387 |
||
7388 |
"check the class" |
|
7389 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
7390 |
||
7391 |
"check the instance variables" |
|
7392 |
numInst := myClass instSize. |
|
10460 | 7393 |
1 to:numInst do:[:i | |
7394 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
5755 | 7395 |
]. |
7396 |
||
7397 |
"check the indexed variables" |
|
7398 |
myClass isVariable ifTrue:[ |
|
10460 | 7399 |
myClass isPointers ifFalse:[ |
7400 |
"no need to search in non-pointer indexed fields" |
|
7401 |
myClass isLongs ifTrue:[ |
|
7402 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
7403 |
] ifFalse:[ |
|
7404 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
7405 |
^ aClass == SmallInteger |
|
7406 |
] |
|
7407 |
]. |
|
7408 |
numInst := self basicSize. |
|
7409 |
1 to:numInst do:[:i | |
|
7410 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
7411 |
] |
|
5755 | 7412 |
]. |
7413 |
^ false |
|
7414 |
||
7415 |
" |
|
10460 | 7416 |
(1 @ 3.4) referencesInstanceOf:Float |
7417 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
7418 |
View new initialize referencesInstanceOf:(Display class) |
|
5755 | 7419 |
" |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7420 |
! |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7421 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7422 |
referencesObject:anObject |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7423 |
"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
|
7424 |
- for debugging only" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7425 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7426 |
%{ /* NOCONTEXT */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7427 |
OBJ cls, flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7428 |
int nInsts, i; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7429 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7430 |
if (! __isNonNilObject(self)) { |
10460 | 7431 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7432 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7433 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7434 |
/* |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7435 |
* 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
|
7436 |
* 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
|
7437 |
* 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
|
7438 |
*/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7439 |
if (__isNonNilObject(anObject)) { |
10460 | 7440 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7441 |
int spc; |
|
7442 |
||
7443 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7444 |
RETURN (false); |
|
7445 |
} |
|
7446 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7447 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7448 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7449 |
cls = __qClass(self); |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7450 |
if (cls == anObject) { |
10460 | 7451 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7452 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7453 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7454 |
flags = __ClassInstPtr(cls)->c_flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7455 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
10460 | 7456 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7457 |
} else { |
10460 | 7458 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7459 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7460 |
if (! nInsts) { |
10460 | 7461 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7462 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7463 |
#if defined(memsrch4) |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7464 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
10460 | 7465 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7466 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7467 |
#else |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7468 |
for (i=0; i<nInsts; i++) { |
10460 | 7469 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7470 |
RETURN (true); |
|
7471 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7472 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7473 |
#endif /* memsrch4 */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7474 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7475 |
%}. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7476 |
|
10460 | 7477 |
"/ |myClass |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7478 |
"/ numInst "{ Class: SmallInteger }" | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7479 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7480 |
"/ myClass := self class. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7481 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7482 |
"/ "check the class" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7483 |
"/ (myClass == anObject) ifTrue:[^ true]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7484 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7485 |
"/ "check the instance variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7486 |
"/ numInst := myClass instSize. |
10460 | 7487 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7488 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7489 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7490 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7491 |
"/ "check the indexed variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7492 |
"/ myClass isVariable ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7493 |
"/ myClass isPointers ifFalse:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7494 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7495 |
"/ "/ 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
|
7496 |
"/ "/ 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
|
7497 |
"/ "/ 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
|
7498 |
"/ "/ 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
|
7499 |
"/ "/ 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
|
7500 |
"/ "/ 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
|
7501 |
"/ "/ 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
|
7502 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7503 |
"/ ^ false. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7504 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7505 |
"/ "/ alternative: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7506 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7507 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7508 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7509 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7510 |
"/ "/ 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
|
7511 |
"/ "/ idenitytIndex method, use it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7512 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7513 |
"/ myClass == Array ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7514 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7515 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7516 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7517 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7518 |
"/ "/ otherwise, do it the slow way |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7519 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7520 |
"/ numInst := self basicSize. |
10460 | 7521 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7522 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7523 |
"/ ] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7524 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7525 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7526 |
^ false |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7527 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7528 |
" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7529 |
|v| |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7530 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7531 |
v := View new initialize. |
10460 | 7532 |
v references:Display. |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7533 |
" |
5755 | 7534 |
! ! |
7535 |
||
7536 |
!Object methodsFor:'synchronized evaluation'! |
|
7537 |
||
10460 | 7538 |
freeSynchronizationSemaphore |
5755 | 7539 |
"free synchronizationSemaphore. May be used, to save memory when |
7540 |
an object is no longer used synchronized." |
|
7541 |
||
7542 |
|sema| |
|
7543 |
||
7544 |
sema := self synchronizationSemaphore. |
|
7545 |
sema notNil ifTrue:[ |
|
10460 | 7546 |
sema wait. "/ get lock |
7547 |
self synchronizationSemaphore:nil. |
|
5755 | 7548 |
]. |
7549 |
||
7550 |
" |
|
7551 |
self synchronized:[]. |
|
7552 |
self synchronizationSemaphore. |
|
7553 |
self freeSynchronizationSemaphore. |
|
7554 |
" |
|
7555 |
||
7556 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
7557 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
7558 |
! |
|
7559 |
||
7560 |
synchronizationSemaphore |
|
7561 |
"return the synchronization semaphore for myself. |
|
7562 |
subclasses may redefine" |
|
7563 |
||
7564 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
7565 |
||
7566 |
" |
|
7567 |
self synchronizationSemaphore |
|
7568 |
" |
|
7569 |
||
7570 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
7571 |
! |
|
7572 |
||
7573 |
synchronizationSemaphore:aSemaphore |
|
7574 |
"set the synchronisationSemaphore for myself. |
|
7575 |
subclasses may redefine this method" |
|
7576 |
||
7577 |
aSemaphore isNil ifTrue:[ |
|
10460 | 7578 |
"/ remove Semaphore |
7579 |
SynchronizationSemaphores removeKey:self ifAbsent:nil. |
|
5755 | 7580 |
] ifFalse:[ |
10460 | 7581 |
SynchronizationSemaphores at:self put:aSemaphore. |
5755 | 7582 |
]. |
7583 |
||
7584 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
7585 |
! |
|
7586 |
||
7587 |
synchronized:aBlock |
|
7588 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
7589 |
||
6600 | 7590 |
|sema wasBlocked| |
7591 |
||
7592 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5755 | 7593 |
|
7594 |
sema := self synchronizationSemaphore. |
|
7595 |
sema isNil ifTrue:[ |
|
10460 | 7596 |
sema := RecursionLock new name:self className. |
7597 |
self synchronizationSemaphore:sema. |
|
5755 | 7598 |
]. |
7599 |
||
6600 | 7600 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
7211
87f5d25b5c3d
Make synchronizationSemaphore a recursionLock
Stefan Vogel <sv@exept.de>
parents:
7208
diff
changeset
|
7601 |
sema critical:aBlock. |
5755 | 7602 |
|
7603 |
" |
|
7604 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
7605 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
7606 |
" |
|
7607 |
||
7608 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
7609 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
|
7610 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
|
7611 |
! ! |
|
7612 |
||
7613 |
!Object methodsFor:'system primitives'! |
|
7614 |
||
7615 |
asOop |
|
7616 |
"ST-80 compatibility: |
|
7617 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
7618 |
or index); since ST/X has no such thing, and the objects address cannot |
|
10460 | 7619 |
be used (since its changing over time), we return the objects identityHash |
5755 | 7620 |
key, which provides (at least) some identity indication. |
7621 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
7622 |
key of two non-identical objects may be the same. |
|
7623 |
You'd better not use it - especially do not misuse it." |
|
7624 |
||
7625 |
^ self identityHash |
|
7626 |
||
7627 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
7628 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
7629 |
! |
|
7630 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7631 |
beImmutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7632 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7633 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7634 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7635 |
if (! __isNonNilObject(self)) { |
10460 | 7636 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7637 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7638 |
__beImmutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7639 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7640 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7641 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7642 |
beMutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7643 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7644 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7645 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7646 |
if (! __isNonNilObject(self)) { |
10460 | 7647 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7648 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7649 |
__beMutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7650 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7651 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7652 |
|
5755 | 7653 |
become:anotherObject |
7654 |
"make all references to the receiver become references to anotherObject |
|
7655 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
|
7656 |
This can be a very dangerous operation - be warned. |
|
10460 | 7657 |
In general, using #become: should be avoided if possible, since it may |
5755 | 7658 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
7659 |
||
10460 | 7660 |
This may also be an expensive (i.e. slow) operation, |
7661 |
since in the worst case, the whole memory has to be searched for |
|
5755 | 7662 |
references to the two objects (although the primitive tries hard to |
10460 | 7663 |
limit the search, for acceptable performance in most cases). |
7664 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7665 |
or nil, or is a context of a living method (i.e. one that has not already |
|
5755 | 7666 |
returned). |
10460 | 7667 |
(notice that #become: is not used heavily by the system |
5755 | 7668 |
- the Collection-classes have been rewritten to not use it.)" |
7669 |
%{ |
|
7670 |
if (__primBecome(self, anotherObject)) { |
|
10460 | 7671 |
RETURN ( self ); |
5755 | 7672 |
} |
7673 |
%}. |
|
7674 |
self primitiveFailed |
|
7675 |
! |
|
7676 |
||
7677 |
becomeNil |
|
7678 |
"make all references to the receiver become nil - effectively getting |
|
10460 | 7679 |
rid of the receiver. |
5755 | 7680 |
This can be a very dangerous operation - be warned. |
7681 |
||
7682 |
This may be an expensive (i.e. slow) operation. |
|
7683 |
The receiver may not be a SmallInteger or a context of a living method." |
|
7684 |
||
7685 |
%{ |
|
7686 |
if (__primBecomeNil(self)) { |
|
10460 | 7687 |
RETURN ( nil ); |
5755 | 7688 |
} |
7689 |
%}. |
|
7690 |
self primitiveFailed |
|
7691 |
! |
|
7692 |
||
7693 |
becomeSameAs:anotherObject |
|
7694 |
"make all references to the receiver become references to anotherObject |
|
7695 |
but NOT vice versa (as done in #become:). |
|
7696 |
This can be a very dangerous operation - be warned. |
|
10460 | 7697 |
In general, using #become: should be avoided if possible, since it may |
5755 | 7698 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
7699 |
||
7700 |
This may also be an expensive (i.e. slow) operation, |
|
7701 |
since in the worst case, the whole memory has to be searched for |
|
7702 |
references to the two objects (although the primitive tries hard to |
|
7703 |
limit the search, for acceptable performance in most cases). |
|
7704 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7705 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
7706 |
%{ |
|
7707 |
if (__primBecomeSameAs(self, anotherObject)) { |
|
10460 | 7708 |
RETURN ( self ); |
5755 | 7709 |
} |
7710 |
%}. |
|
7711 |
self primitiveFailed |
|
7712 |
! |
|
7713 |
||
7714 |
changeClassTo:otherClass |
|
7715 |
"changes the class of the receiver to the argument, otherClass. |
|
7716 |
This is only allowed (possible), if the receivers class and the argument |
|
7717 |
have the same structure (i.e. number of named instance variables and |
|
10460 | 7718 |
type of indexed instance variables). |
5755 | 7719 |
If the structures do not match, or any of the original class or new class |
7720 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
7721 |
||
7722 |
|myClass ok| |
|
7723 |
||
9405 | 7724 |
otherClass autoload. |
7725 |
||
5755 | 7726 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
7727 |
%{ |
|
7728 |
{ |
|
10460 | 7729 |
OBJ other = otherClass; |
7730 |
||
7731 |
if (__isNonNilObject(self) |
|
7732 |
&& __isNonNilObject(other) |
|
7733 |
&& (other != UndefinedObject) |
|
7734 |
&& (other != SmallInteger)) { |
|
7735 |
ok = true; |
|
7736 |
} else { |
|
7737 |
ok = false; |
|
7738 |
} |
|
5755 | 7739 |
} |
7740 |
%}. |
|
7741 |
ok ifTrue:[ |
|
10460 | 7742 |
ok := false. |
7743 |
myClass := self class. |
|
7744 |
myClass flags == otherClass flags ifTrue:[ |
|
7745 |
myClass instSize == otherClass instSize ifTrue:[ |
|
7746 |
"same instance layout and types: its ok to do it" |
|
7747 |
ok := true. |
|
7748 |
] ifFalse:[ |
|
7749 |
myClass isPointers ifTrue:[ |
|
7750 |
myClass isVariable ifTrue:[ |
|
7751 |
ok := true |
|
7752 |
] |
|
7753 |
] |
|
7754 |
] |
|
7755 |
] ifFalse:[ |
|
7756 |
myClass isPointers ifTrue:[ |
|
7757 |
"if newClass is a variable class, with instSize <= my instsize, |
|
7758 |
we can do it (effectively mapping additional instvars into the |
|
7759 |
variable part) - usefulness is questionable, though" |
|
7760 |
||
7761 |
otherClass isPointers ifTrue:[ |
|
7762 |
otherClass isVariable ifTrue:[ |
|
7763 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
7764 |
ifTrue:[ |
|
7765 |
ok := true |
|
7766 |
] |
|
7767 |
] ifFalse:[ |
|
7768 |
otherClass instSize == (myClass instSize + self basicSize) |
|
7769 |
ifTrue:[ |
|
7770 |
ok := true |
|
7771 |
] |
|
7772 |
] |
|
7773 |
] ifFalse:[ |
|
7774 |
"it does not make sense to convert pointers to bytes ..." |
|
7775 |
] |
|
7776 |
] ifFalse:[ |
|
7777 |
"does it make sense, to convert bits ?" |
|
7778 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
7779 |
(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[ |
|
7780 |
ok := true |
|
7781 |
] |
|
7782 |
] |
|
7783 |
] |
|
5755 | 7784 |
]. |
7785 |
ok ifTrue:[ |
|
10460 | 7786 |
"now, change the receivers class ..." |
5755 | 7787 |
%{ |
10460 | 7788 |
{ |
7789 |
OBJ me = self; |
|
7790 |
||
7791 |
__qClass(me) = otherClass; |
|
7792 |
__STORE(me, otherClass); |
|
7793 |
RETURN (me); |
|
7794 |
} |
|
5755 | 7795 |
%}. |
7796 |
]. |
|
9405 | 7797 |
|
5755 | 7798 |
" |
7799 |
the receiver cannot be represented as a instance of |
|
7800 |
the desired class. |
|
10460 | 7801 |
For example, you cannot change a bitInstance (byteArray etc.) |
5755 | 7802 |
into a pointer object and vice versa. |
7803 |
" |
|
7804 |
self primitiveFailed |
|
7805 |
! |
|
7806 |
||
7807 |
changeClassToThatOf:anObject |
|
7808 |
"changes the class of the receiver to that of the argument, anObject. |
|
7809 |
This is only allowed (possible), if the receivers class and the arguments |
|
10460 | 7810 |
class have the same structure (i.e. number of named instance variables and |
5755 | 7811 |
type of indexed instance variables). If the structures do not match, or any |
7812 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
7813 |
||
7814 |
self changeClassTo:(anObject class) |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7815 |
! |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7816 |
|
8935 | 7817 |
isImmutable |
7818 |
"experimental - not yet usable; do not use" |
|
7819 |
||
7820 |
%{ /* NOCONTEXT */ |
|
7821 |
if (! __isNonNilObject(self)) { |
|
10460 | 7822 |
RETURN (true); |
8935 | 7823 |
} |
7824 |
RETURN (__isImmutable(self) ? true : false); |
|
7825 |
%} |
|
7826 |
! |
|
7827 |
||
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7828 |
replaceReferencesTo:anObject with:newRef |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7829 |
"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
|
7830 |
Return true, if any reference was changed. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7831 |
Notice: this does not change the class-reference." |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7832 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7833 |
%{ /* NOCONTEXT */ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7834 |
OBJ cls, flags, anyChange; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7835 |
int nInsts, i; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7836 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7837 |
if (! __isNonNilObject(self)) { |
10460 | 7838 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7839 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7840 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7841 |
/* |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7842 |
* a little optimization: use the fact that all old objects |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7843 |
* 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
|
7844 |
* a trivial reject is possible, if anObject is a newbee |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7845 |
*/ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7846 |
if (__isNonNilObject(anObject)) { |
10460 | 7847 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7848 |
int spc; |
|
7849 |
||
7850 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7851 |
RETURN (false); |
|
7852 |
} |
|
7853 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7854 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7855 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7856 |
cls = __qClass(self); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7857 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7858 |
flags = __ClassInstPtr(cls)->c_flags; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7859 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
10460 | 7860 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7861 |
} else { |
10460 | 7862 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7863 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7864 |
if (! nInsts) { |
10460 | 7865 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7866 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7867 |
anyChange = false; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7868 |
for (i=0; i<nInsts; i++) { |
10460 | 7869 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7870 |
__InstPtr(self)->i_instvars[i] = newRef; |
|
7871 |
__STORE(self, newRef); |
|
7872 |
anyChange = true; |
|
7873 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7874 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7875 |
RETURN (anyChange); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7876 |
%}. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7877 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7878 |
" |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7879 |
|v| |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7880 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7881 |
v := Array with:1234 with:'hello' with:Array. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7882 |
v replaceReferencesTo:Array with:ByteArray. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7883 |
v inspect |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7884 |
" |
5755 | 7885 |
! ! |
7886 |
||
7887 |
!Object methodsFor:'testing'! |
|
7888 |
||
7889 |
? defaultValue |
|
7890 |
"a syntactic shugar-piece: |
|
7891 |
if the receiver is nil, return the defaultValue; |
|
7892 |
otherwise, return the receiver. |
|
7893 |
This method is only redefined in UndefinedObject - therefore, |
|
7894 |
the recevier is retuned here. |
|
7895 |
||
7896 |
Thus, if foo and bar are simple variables or constants, |
|
10460 | 7897 |
foo ? bar |
5755 | 7898 |
is the same as: |
10460 | 7899 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
5755 | 7900 |
|
7901 |
if they are message sends, the equivalent code is: |
|
10460 | 7902 |
[ |
7903 |
|t1 t2| |
|
7904 |
||
7905 |
t1 := foo. |
|
7906 |
t2 := bar. |
|
7907 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
7908 |
] value |
|
5755 | 7909 |
|
7910 |
Can be used to provide defaultValues to variables, |
|
7911 |
as in: |
|
10460 | 7912 |
foo := arg ? #defaultValue |
5755 | 7913 |
|
7914 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
7915 |
Notice: |
|
10460 | 7916 |
This method is open coded (inlined) by the compiler(s) |
7917 |
- redefining it may not work as expected." |
|
5755 | 7918 |
|
7919 |
^ self |
|
7920 |
||
7921 |
" |
|
7922 |
1 ? #default |
|
7923 |
nil ? #default |
|
7924 |
" |
|
7925 |
||
7926 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
7927 |
"Modified: / 19.5.1998 / 17:39:56 / cg" |
|
7928 |
! |
|
7929 |
||
7930 |
?? defaultValue |
|
7931 |
"a syntactic shugar-piece: |
|
7932 |
much like ?, but sends #value to the argument if required. |
|
7933 |
(i.e. its the same as #ifNil:) |
|
7934 |
If the receiver is nil, return the defaultValues value; |
|
7935 |
otherwise, return the receiver. |
|
7936 |
This method is only redefined in UndefinedObject - therefore, |
|
7937 |
the recevier is retuned here. |
|
7938 |
||
7939 |
Thus, if foo and bar are simple variables or constants, |
|
10460 | 7940 |
foo ?? bar |
5755 | 7941 |
is the same as: |
10460 | 7942 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
5755 | 7943 |
|
7944 |
if they are message sends, the equivalent code is: |
|
10460 | 7945 |
[ |
7946 |
|t t2| |
|
7947 |
||
7948 |
t := foo. |
|
7949 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
7950 |
] value |
|
5755 | 7951 |
|
7952 |
Can be used to provide defaultValues to variables, |
|
7953 |
as in: |
|
10460 | 7954 |
foo := arg ?? [ self computeDefault ] |
5755 | 7955 |
|
7956 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
7957 |
" |
|
7958 |
||
7959 |
^ self |
|
7960 |
||
7961 |
" |
|
10460 | 7962 |
1 ?? #default |
5755 | 7963 |
nil ?? #default |
10460 | 7964 |
1 ?? [ self halt. 1 + 2 ] |
7965 |
nil ?? [ self halt. 1 + 2 ] |
|
7966 |
1 ?? [Date today] |
|
7967 |
nil ?? [Date today] |
|
5755 | 7968 |
" |
7969 |
||
7970 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
7971 |
"Modified: / 19.5.1998 / 17:42:56 / cg" |
|
7972 |
! |
|
7973 |
||
7974 |
ifNil:aBlockOrValue |
|
7975 |
"return myself, or the result from evaluating the argument, if I am nil. |
|
7976 |
This is much like #?, but sends #value to the argument in case of a nil |
|
7977 |
receiver. |
|
7978 |
Notice: |
|
10460 | 7979 |
This method is open coded (inlined) by the compiler(s) |
7980 |
- redefining it may not work as expected." |
|
5755 | 7981 |
|
7982 |
^ self |
|
7983 |
! |
|
7984 |
||
7985 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
|
7986 |
"return the value of the first arg, if I am nil, |
|
7987 |
the result from evaluating the 2nd argument, if I am not nil. |
|
7988 |
Notice: |
|
10460 | 7989 |
This method is open coded (inlined) by the compiler(s) |
7990 |
- redefining it may not work as expected." |
|
5755 | 7991 |
|
7992 |
^ notNilBlockOrValue value |
|
7993 |
||
7994 |
! |
|
7995 |
||
7996 |
ifNotNil:aBlockOrValue |
|
10460 | 7997 |
"return myself if nil, or the result from evaluating the argument, |
5755 | 7998 |
if I am not nil. |
7999 |
Notice: |
|
10460 | 8000 |
This method is open coded (inlined) by the compiler(s) |
8001 |
- redefining it may not work as expected." |
|
5755 | 8002 |
|
8003 |
^ aBlockOrValue value |
|
8004 |
||
8005 |
! |
|
8006 |
||
8007 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
|
8008 |
"return the value of the 2nd arg, if I am nil, |
|
8009 |
the result from evaluating the 1st argument, if I am not nil. |
|
8010 |
Notice: |
|
10460 | 8011 |
This method is open coded (inlined) by the compiler(s) |
8012 |
- redefining it may not work as expected." |
|
5755 | 8013 |
|
8014 |
^ notNilBlockOrValue value |
|
8015 |
||
8016 |
||
8017 |
! |
|
8018 |
||
8574 | 8019 |
ifNotNilDo:aBlock |
8020 |
"if the reciever is non-nil, return the value of aBlock, passing myself as argument. |
|
8021 |
Otherwise do nothing and return nil." |
|
8022 |
||
8023 |
^ aBlock value:self |
|
8024 |
! |
|
8025 |
||
5755 | 8026 |
isArray |
8027 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
8028 |
false is returned here - the method is only redefined in Array." |
|
8029 |
||
8030 |
^ false |
|
8031 |
! |
|
8032 |
||
8033 |
isAssociation |
|
8034 |
"return true, if the receiver is some kind of association; |
|
8035 |
false is returned here - the method is only redefined in Association." |
|
8036 |
||
8037 |
^ false |
|
8038 |
||
8039 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
8040 |
! |
|
8041 |
||
8042 |
isBehavior |
|
9221 | 8043 |
"return true, if the receiver is describing another objects behavior. |
8044 |
False is returned here - the method is only redefined in Behavior." |
|
5755 | 8045 |
|
8046 |
^ false |
|
8047 |
! |
|
8048 |
||
8049 |
isBlock |
|
8050 |
"return true, if the receiver is some kind of block; |
|
8051 |
false returned here - the method is only redefined in Block." |
|
8052 |
||
8053 |
^ false |
|
8054 |
! |
|
8055 |
||
5824 | 8056 |
isBoolean |
8057 |
"return true, if the receiver is a boolean; |
|
8058 |
false is returned here - the method is only redefined in Boolean." |
|
8059 |
||
8060 |
^ false |
|
8061 |
! |
|
8062 |
||
5755 | 8063 |
isByteArray |
8064 |
"return true, if the receiver is some kind of bytearray; |
|
8065 |
false is returned here - the method is only redefined in ByteArray." |
|
8066 |
||
8067 |
^ false |
|
8068 |
! |
|
8069 |
||
8986 | 8070 |
isByteCollection |
8071 |
"return true, if the receiver is some kind of byte collection, |
|
10460 | 8072 |
i.e. #at: and #at:put: accesses a byte. This is different from 'self class isBytes', |
8986 | 8073 |
since e.g. in BitArray single bits are accessed, but it is implemented as variableBytes class. |
10460 | 8074 |
|
8986 | 8075 |
false is returned here - the method is only redefined in UninterpretedBytes." |
8076 |
||
8077 |
^ false |
|
8078 |
! |
|
8079 |
||
5755 | 8080 |
isCharacter |
8081 |
"return true, if the receiver is some kind of character; |
|
8082 |
false is returned here - the method is only redefined in Character." |
|
8083 |
||
8084 |
^ false |
|
8085 |
! |
|
8086 |
||
8087 |
isClass |
|
9405 | 8088 |
"return true, if the receiver is some kind of class |
8089 |
(real class, not just behavior); |
|
5755 | 8090 |
false is returned here - the method is only redefined in Class." |
8091 |
||
8092 |
^ false |
|
8093 |
! |
|
8094 |
||
8095 |
isCollection |
|
8096 |
"return true, if the receiver is some kind of collection; |
|
8097 |
false is returned here - the method is only redefined in Collection." |
|
8098 |
||
8099 |
^ false |
|
8100 |
! |
|
8101 |
||
8102 |
isColor |
|
8103 |
"return true, if the receiver is some kind of color; |
|
8104 |
false is returned here - the method is only redefined in Color." |
|
8105 |
||
8106 |
^ false |
|
8107 |
! |
|
8108 |
||
6567 | 8109 |
isCons |
8110 |
"return true, if the receiver is a cons (pair); |
|
8111 |
false is returned here - the method is only redefined in Cons." |
|
8112 |
||
8113 |
^ false |
|
8114 |
! |
|
8115 |
||
5755 | 8116 |
isContext |
8117 |
"return true, if the receiver is some kind of context; |
|
8118 |
false returned here - the method is only redefined in Context." |
|
8119 |
||
8120 |
^ false |
|
8121 |
! |
|
8122 |
||
6181 | 8123 |
isEmptyOrNil |
8833 | 8124 |
"return true if I am nil or an empty collection - return false here. |
8125 |
(from Squeak)" |
|
6181 | 8126 |
|
8127 |
^ false |
|
8128 |
||
8129 |
"Created: / 13.11.2001 / 13:17:04 / cg" |
|
6182 | 8130 |
"Modified: / 13.11.2001 / 13:28:40 / cg" |
6181 | 8131 |
! |
8132 |
||
6221 | 8133 |
isException |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8134 |
"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
|
8135 |
|
6221 | 8136 |
^ false |
8137 |
||
8138 |
"Created: / 17.11.2001 / 18:37:44 / cg" |
|
8139 |
! |
|
8140 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8141 |
isExceptionCreator |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8142 |
"return true, if the receiver can create exceptions, |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8143 |
this includes #raise, #raiseRequest as well as the behavior of |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8144 |
an exception handler, such as the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8145 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8146 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8147 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8148 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8149 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8150 |
"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
|
8151 |
especially to the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8152 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8153 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8154 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8155 |
|
10480 | 8156 |
isExternalLibraryFunction |
8157 |
"return true, if the receiver is some kind of externalLibrary function; |
|
8158 |
false is returned here - the method is only redefined in ExternalLibraryFunction." |
|
8159 |
||
8160 |
^false |
|
8161 |
! |
|
8162 |
||
5755 | 8163 |
isExternalStream |
8164 |
"return true, if the receiver is some kind of externalStream; |
|
8165 |
false is returned here - the method is only redefined in ExternalStream." |
|
8166 |
||
8167 |
^false |
|
8168 |
! |
|
8169 |
||
8170 |
isFileStream |
|
8171 |
"return true, if the receiver is some kind of fileStream; |
|
8172 |
false is returned here - the method is only redefined in FileStream." |
|
8173 |
||
8174 |
^false |
|
8175 |
! |
|
8176 |
||
8177 |
isFilename |
|
8178 |
"return true, if the receiver is some kind of filename; |
|
8179 |
false is returned here - the method is only redefined in Filename." |
|
8180 |
||
8181 |
^false |
|
8182 |
! |
|
8183 |
||
8184 |
isFixedPoint |
|
8185 |
"return true, if the receiver is some kind of fixedPoint number; |
|
8186 |
false is returned here - the method is only redefined in FixedPoint." |
|
8187 |
||
8188 |
^ false |
|
8189 |
||
8190 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
8191 |
! |
|
8192 |
||
8193 |
isFixedSize |
|
10460 | 8194 |
"return true if the receiver cannot grow easily |
5755 | 8195 |
(i.e. a grow may be expensive, since it involves a become:)" |
8196 |
||
8197 |
^ true |
|
8198 |
! |
|
8199 |
||
6185 | 8200 |
isFloat |
8201 |
"return true, if the receiver is some kind of floating point number; |
|
8202 |
false is returned here. |
|
8203 |
Same as #isLimitedPrecisionReal, but a better name ;-)" |
|
8204 |
||
8205 |
^ false |
|
8206 |
||
8207 |
"Modified: / 14.11.2001 / 14:57:46 / cg" |
|
8208 |
! |
|
8209 |
||
5755 | 8210 |
isForm |
8211 |
"return true, if the receiver is some kind of form; |
|
8212 |
false is returned here - the method is only redefined in Form." |
|
8213 |
||
8214 |
^ false |
|
8215 |
! |
|
8216 |
||
8217 |
isFraction |
|
8218 |
"return true, if the receiver is some kind of fraction; |
|
8219 |
false is returned here - the method is only redefined in Fraction." |
|
8220 |
||
8221 |
^ false |
|
8222 |
! |
|
8223 |
||
9293 | 8224 |
isHierarchicalItem |
8225 |
"used to decide if the parent is a hierarchical item or the model" |
|
8226 |
||
8227 |
^ false |
|
8228 |
! |
|
8229 |
||
5755 | 8230 |
isImage |
8231 |
"return true, if the receiver is some kind of image; |
|
8232 |
false is returned here - the method is only redefined in Image." |
|
8233 |
||
8234 |
^ false |
|
8235 |
! |
|
8236 |
||
8237 |
isImageOrForm |
|
8238 |
"return true, if the receiver is some kind of image or form; |
|
8239 |
false is returned here - the method is only redefined in Image and Form." |
|
8240 |
||
8241 |
^ false |
|
8242 |
! |
|
8243 |
||
8244 |
isImmediate |
|
8245 |
"return true if I am an immediate object |
|
8246 |
i.e. I am represented in the pointer itself and |
|
8247 |
no real object header/storage is used me. |
|
8248 |
(currently, only SmallIntegers, some characters and nil return true)" |
|
8249 |
||
8250 |
^ self class hasImmediateInstances |
|
8251 |
||
8252 |
"Created: 3.6.1997 / 12:00:18 / cg" |
|
8253 |
! |
|
8254 |
||
8255 |
isInteger |
|
8256 |
"return true, if the receiver is some kind of integer number; |
|
8257 |
false is returned here - the method is only redefined in Integer." |
|
8258 |
||
8259 |
^ false |
|
8260 |
! |
|
8261 |
||
9279 | 8262 |
isInterestConverter |
8263 |
"return true if I am a kind of interest forwarder" |
|
8264 |
||
8265 |
^ false |
|
8266 |
! |
|
8267 |
||
10576 | 8268 |
isInternalByteStream |
8269 |
"return true, if the receiver is some kind of Stream for reading bytes; |
|
8270 |
false is returned here - the method is only redefined in PeekableStream." |
|
8271 |
||
8272 |
^false |
|
8273 |
||
8274 |
"Created: / 30-05-2007 / 16:15:33 / cg" |
|
8275 |
! |
|
8276 |
||
5755 | 8277 |
isJavaClass |
8278 |
"return true, if this is a javaClass. |
|
8279 |
false is returned here - the method is only redefined in JavaClass." |
|
8280 |
||
8281 |
^ false |
|
8282 |
||
8283 |
"Created: / 26.3.1997 / 13:34:54 / cg" |
|
8284 |
"Modified: / 8.5.1998 / 21:25:21 / cg" |
|
8285 |
! |
|
8286 |
||
8287 |
isJavaClassRef |
|
8288 |
"return true, if this is a JavaClassRef. |
|
8289 |
false is returned here - the method is only redefined in JavaClassRef." |
|
8290 |
||
8291 |
^ false |
|
8292 |
||
8293 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8294 |
"Created: / 24.12.1999 / 01:46:28 / cg" |
|
8295 |
! |
|
8296 |
||
8297 |
isJavaContext |
|
8298 |
"return true, if this is a javaContext. |
|
8299 |
false is returned here - the method is only redefined in JavaContext." |
|
8300 |
||
8301 |
^ false |
|
8302 |
||
8303 |
"Created: / 8.5.1998 / 21:24:27 / cg" |
|
8304 |
"Modified: / 8.5.1998 / 21:25:35 / cg" |
|
8305 |
! |
|
8306 |
||
8307 |
isJavaMethod |
|
8308 |
"return true, if this is a JavaMethod. |
|
8309 |
false is returned here - the method is only redefined in JavaMethod." |
|
8310 |
||
8311 |
^ false |
|
8312 |
||
8313 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8314 |
"Created: / 25.9.1999 / 23:26:12 / cg" |
|
8315 |
! |
|
8316 |
||
8317 |
isJavaMethodRef |
|
8318 |
"return true, if this is a JavaMethodRef. |
|
8319 |
false is returned here - the method is only redefined in JavaMethodRef." |
|
8320 |
||
8321 |
^ false |
|
8322 |
||
8323 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8324 |
"Created: / 23.12.1999 / 19:44:51 / cg" |
|
8325 |
! |
|
8326 |
||
8327 |
isJavaObject |
|
8328 |
"return true, if this is a javaObject. |
|
8329 |
false is returned here - the method is only redefined in JavaObject." |
|
8330 |
||
8331 |
^ false |
|
8332 |
||
8333 |
"Created: / 26.3.1997 / 13:34:48 / cg" |
|
8334 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8335 |
! |
|
8336 |
||
8337 |
isJavaScriptClass |
|
8338 |
"return true, if this is a javaScriptClass. |
|
8339 |
false is returned here - the method is only redefined in JavaScriptClass." |
|
8340 |
||
8341 |
^ false |
|
8342 |
! |
|
8343 |
||
8935 | 8344 |
isJavaScriptMetaclass |
8345 |
"return true, if this is a javaScript Metaclass. |
|
8346 |
false is returned here - the method is only redefined in JavaScriptMetaclass." |
|
8347 |
||
8348 |
^ false |
|
8349 |
! |
|
8350 |
||
5755 | 8351 |
isKindOf:aClass |
8352 |
"return true, if the receiver is an instance of aClass or one of its |
|
8353 |
subclasses, false otherwise. |
|
10460 | 8354 |
Advice: |
8355 |
use of this to check objects for certain attributes/protocoll should |
|
8356 |
be avoided; it limits the reusability of your classes by limiting use |
|
8357 |
to instances of certain classes and fences you into a specific inheritance |
|
8358 |
hierarchy. |
|
8359 |
Use check-methods to check an object for a certain attributes/protocol |
|
8360 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
8361 |
||
8362 |
Using #isKindOf: is considered BAD STYLE. |
|
5755 | 8363 |
|
8364 |
Advice2: |
|
10460 | 8365 |
Be aware, that using an #isXXX method is usually much faster than |
8366 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
8367 |
hierarchy, comparing every class on the way. |
|
8368 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
8369 |
a single function call. |
|
5755 | 8370 |
" |
8371 |
||
8372 |
%{ /* NOCONTEXT */ |
|
8373 |
register OBJ thisClass; |
|
8374 |
||
8375 |
thisClass = __Class(self); |
|
8376 |
while (thisClass != nil) { |
|
10460 | 8377 |
if (thisClass == aClass) { |
8378 |
RETURN ( true ); |
|
8379 |
} |
|
8380 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
5755 | 8381 |
} |
8382 |
RETURN ( false ); |
|
8383 |
%} |
|
8384 |
||
8385 |
"/ |
|
8386 |
"/ the above code is equivalent to: |
|
8387 |
"/ |
|
8388 |
"/ thisClass := self class. |
|
8389 |
"/ [thisClass notNil] whileTrue:[ |
|
8390 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
8391 |
"/ thisClass := thisClass superclass |
|
8392 |
"/ ]. |
|
8393 |
"/ ^ false |
|
8394 |
"/ |
|
8395 |
||
8396 |
! |
|
8397 |
||
8398 |
isLayout |
|
8399 |
"return true, if the receiver is some kind of layout; |
|
8400 |
false is returned here - the method is only redefined in Layout." |
|
8401 |
||
8402 |
^ false |
|
8403 |
! |
|
8404 |
||
6567 | 8405 |
isLazyValue |
8406 |
^ false |
|
8407 |
! |
|
8408 |
||
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8409 |
isLimitedPrecisionReal |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8410 |
"return true, if the receiver is some kind of floating point number; |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8411 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8412 |
|
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8413 |
^ false |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8414 |
! |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8415 |
|
5755 | 8416 |
isList |
8417 |
"return true, if the receiver is some kind of list collection; |
|
8418 |
false is returned here - the method is only redefined in List." |
|
8419 |
||
8420 |
^ false |
|
8421 |
||
8422 |
"Created: / 11.2.2000 / 01:37:05 / cg" |
|
8423 |
! |
|
8424 |
||
8425 |
isLiteral |
|
8426 |
"return true, if the receiver can be represented as a literal constant in ST syntax; |
|
8427 |
false is returned here - the method is redefined in some classes." |
|
8428 |
||
8429 |
^ false |
|
8430 |
! |
|
8431 |
||
8432 |
isMemberOf:aClass |
|
8433 |
"return true, if the receiver is an instance of aClass, false otherwise. |
|
10460 | 8434 |
Advice: |
8435 |
use of this to check objects for certain attributes/protocol should |
|
8436 |
be avoided; it limits the reusability of your classes by limiting use |
|
8437 |
to instances of a certain class. |
|
8438 |
Use check-methods to check an object for a certain attributes/protocol |
|
8439 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
8440 |
||
8441 |
Using #isMemberOf: is considered BAD STYLE. |
|
5755 | 8442 |
Notice: |
10460 | 8443 |
This method is open coded (inlined) by the compiler(s) |
8444 |
- redefining it may not work as expected." |
|
5755 | 8445 |
|
8446 |
^ (self class) == aClass |
|
8447 |
! |
|
8448 |
||
8449 |
isMeta |
|
8450 |
"return true, if the receiver is some kind of metaclass; |
|
8451 |
false is returned here - the method is only redefined in Metaclass." |
|
8452 |
||
8453 |
^ false |
|
8454 |
! |
|
8455 |
||
8456 |
isMethod |
|
8457 |
"return true, if the receiver is some kind of method; |
|
8458 |
false returned here - the method is only redefined in Method." |
|
8459 |
||
8460 |
^ false |
|
8461 |
! |
|
8462 |
||
8463 |
isMorph |
|
8464 |
"return true, if the receiver is some kind of morph; |
|
8465 |
false is returned here - the method is only redefined in Morph." |
|
8466 |
||
8467 |
^ false |
|
8468 |
! |
|
8469 |
||
8470 |
isNameSpace |
|
9221 | 8471 |
"return true, if the receiver is a nameSpace. |
8472 |
False is returned here - the method is only redefined in Namespace." |
|
5755 | 8473 |
|
8474 |
^ false |
|
8475 |
||
8476 |
"Created: / 11.10.1996 / 18:08:56 / cg" |
|
8477 |
"Modified: / 8.5.1998 / 21:26:05 / cg" |
|
8478 |
! |
|
8479 |
||
8480 |
isNamespace |
|
8481 |
"return true, if this is a nameSpace. |
|
8482 |
false is returned here - the method is only redefined in Namespace." |
|
8483 |
||
5869 | 8484 |
<resource:#obsolete> |
8485 |
||
5755 | 8486 |
self obsoleteMethodWarning:'use #isNameSpace'. |
6805 | 8487 |
^ self isNameSpace |
5755 | 8488 |
! |
8489 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8490 |
isNil |
9221 | 8491 |
"Return true, if the receiver is nil. |
8492 |
Because isNil is redefined in UndefinedObject, |
|
8493 |
the receiver is definitely not nil here, so unconditionally return false. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8494 |
Notice: |
10460 | 8495 |
This method is open coded (inlined) by the compiler(s) |
8496 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8497 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8498 |
^ false |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8499 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8500 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8501 |
isNilOrEmptyCollection |
6182 | 8502 |
"return true if I am nil or an empty collection - false here. |
8833 | 8503 |
Obsolete, use isEmptyOrNil." |
8504 |
||
8505 |
<resource:#obsolete> |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8506 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8507 |
^ false |
6182 | 8508 |
|
8509 |
"Modified: / 13.11.2001 / 13:28:06 / cg" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8510 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8511 |
|
9005 | 8512 |
isNonByteCollection |
8513 |
"return true, if the receiver is some kind of collection, but not a String, ByteArray etc.; |
|
8514 |
false is returned here - the method is redefined in Collection and UninterpretedBytes." |
|
8515 |
||
8516 |
^ false |
|
8517 |
||
8518 |
" |
|
10460 | 8519 |
21 isNonByteCollection |
8520 |
'abc' isNonByteCollection |
|
8521 |
#'abc' isNonByteCollection |
|
8522 |
#[1 2 3] isNonByteCollection |
|
8523 |
#(1 2 3) isNonByteCollection |
|
9005 | 8524 |
" |
8525 |
! |
|
8526 |
||
5755 | 8527 |
isNumber |
8528 |
"return true, if the receiver is some kind of number; |
|
8529 |
false is returned here - the method is only redefined in Number." |
|
8530 |
||
8531 |
^ false |
|
8532 |
! |
|
8533 |
||
8534 |
isOrderedCollection |
|
8535 |
"return true, if the receiver is some kind of ordered collection (or list etc); |
|
8536 |
false is returned here - the method is only redefined in OrderedCollection." |
|
8537 |
||
8538 |
^ false |
|
8539 |
! |
|
8540 |
||
8541 |
isPoint |
|
8542 |
"return true, if the receiver is some kind of point; |
|
8543 |
false is returned here - the method is only redefined in Point." |
|
8544 |
||
8545 |
^ false |
|
8546 |
! |
|
8547 |
||
10532 | 8548 |
isPrinterContext |
8549 |
||
8550 |
^false |
|
8551 |
! |
|
8552 |
||
9515 | 8553 |
isProjectDefinition |
8554 |
"return true, if the receiver is a projectDefinition. |
|
8555 |
False is returned here - the method is only redefined in ProjectDefinition." |
|
8556 |
||
8557 |
^ false |
|
8558 |
||
8559 |
"Created: / 10-08-2006 / 16:24:53 / cg" |
|
8560 |
! |
|
8561 |
||
10171 | 8562 |
isRealNameSpace |
8563 |
"return true, if the receiver is really a nameSpace (i.e. a NameSpace, but not Smalltalk). |
|
8564 |
False is returned here - the method is only redefined in Namespace." |
|
8565 |
||
8566 |
^ false |
|
8567 |
||
8568 |
"Created: / 10-11-2006 / 17:05:43 / cg" |
|
8569 |
! |
|
8570 |
||
5755 | 8571 |
isRectangle |
8572 |
"return true, if the receiver is some kind of rectangle; |
|
8573 |
false is returned here - the method is only redefined in Rectangle." |
|
8574 |
||
8575 |
^ false |
|
8576 |
! |
|
8577 |
||
8578 |
isRemoteObject |
|
8579 |
"return true, if the receiver is some kind of remoteObject, |
|
8580 |
false if its local - the method is only redefined in RemoteObject." |
|
8581 |
||
8582 |
^ false |
|
8583 |
||
8584 |
"Created: 28.10.1996 / 15:18:45 / cg" |
|
8585 |
"Modified: 28.10.1996 / 15:20:57 / cg" |
|
8586 |
! |
|
8587 |
||
8588 |
isSequenceable |
|
8589 |
"return true, if the receiver is some kind of sequenceable collection; |
|
8590 |
false is returned here - the method is only redefined in SequenceableCollection." |
|
8591 |
||
8592 |
^ false |
|
8593 |
! |
|
8594 |
||
8595 |
isSequenceableCollection |
|
8596 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
8597 |
This method is a historic leftover and will be removed soon ... |
|
8598 |
(although its name is much better than #isSequenceable - sigh)" |
|
8599 |
||
5869 | 8600 |
<resource:#obsolete> |
8601 |
||
5755 | 8602 |
self obsoleteMethodWarning:'use #isSequenceable'. |
8603 |
^ false |
|
8604 |
! |
|
8605 |
||
10856 | 8606 |
isSharedPool |
8607 |
"return true, if the receiver is a sharedPool. |
|
8608 |
False is returned here - the method is only redefined in SharedPool." |
|
8609 |
||
8610 |
^ false |
|
8611 |
! |
|
8612 |
||
5755 | 8613 |
isStream |
8614 |
"return true, if the receiver is some kind of stream; |
|
8615 |
false is returned here - the method is only redefined in Stream." |
|
8616 |
||
8617 |
^ false |
|
8618 |
! |
|
8619 |
||
8620 |
isString |
|
8621 |
"return true, if the receiver is some kind of string; |
|
8622 |
false is returned here - the method is only redefined in CharacterArray." |
|
8623 |
||
8624 |
^ false |
|
8625 |
! |
|
8626 |
||
8627 |
isStringCollection |
|
8628 |
"return true, if the receiver is some kind of stringCollection; |
|
8629 |
false is returned here - the method is only redefined in StringCollection." |
|
8630 |
||
8631 |
^ false |
|
8632 |
! |
|
8633 |
||
8634 |
isSymbol |
|
8635 |
"return true, if the receiver is some kind of symbol; |
|
8636 |
false is returned here - the method is only redefined in Symbol." |
|
8637 |
||
8638 |
^ false |
|
8639 |
! |
|
8640 |
||
8641 |
isText |
|
8642 |
"return true, if the receiver is some kind of text object; |
|
8643 |
false is returned here - the method is only redefined in Text." |
|
8644 |
||
8645 |
^ false |
|
8646 |
||
8647 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
8648 |
! |
|
8649 |
||
8650 |
isValueModel |
|
8651 |
"return true, if the receiver is some kind of valueModel; |
|
8652 |
false is returned here - the method is only redefined in ValueModel." |
|
8653 |
||
8654 |
^ false |
|
8655 |
||
8656 |
! |
|
8657 |
||
8658 |
isVariable |
|
8659 |
"return true if the receiver has indexed instance variables, |
|
8660 |
false otherwise." |
|
8661 |
||
8662 |
^ self class isVariable |
|
8663 |
! |
|
8664 |
||
8665 |
isVariableBinding |
|
8666 |
"return true, if this is a binding for a variable. |
|
8667 |
false is returned here - the method is only redefined in Binding." |
|
8668 |
||
8669 |
^ false |
|
8670 |
||
8671 |
"Created: / 19.6.1997 / 17:38:44 / cg" |
|
8672 |
"Modified: / 8.5.1998 / 21:26:55 / cg" |
|
8673 |
! |
|
8674 |
||
8675 |
isView |
|
8676 |
"return true, if the receiver is some kind of view; |
|
8677 |
false is returned here - the method is only redefined in View." |
|
8678 |
||
8679 |
^ false |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8680 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8681 |
|
6932 | 8682 |
notEmptyOrNil |
8683 |
"Squeak compatibility: |
|
8684 |
return true if I am neither nil nor an empty collection. |
|
8685 |
Return true here." |
|
8686 |
||
8687 |
^ true |
|
8688 |
! |
|
8689 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8690 |
notNil |
9221 | 8691 |
"Return true, if the receiver is not nil. |
8692 |
Because notNil is redefined in UndefinedObject, |
|
8693 |
the receiver is definitely not nil here, so unconditionally return true. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8694 |
Notice: |
10460 | 8695 |
This method is open coded (inlined) by the compiler(s) |
8696 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8697 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8698 |
^ true |
5755 | 8699 |
! ! |
8700 |
||
8701 |
!Object methodsFor:'tracing'! |
|
8702 |
||
8703 |
traceInto:aRequestor level:level from:referrer |
|
8704 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
8705 |
||
8706 |
^ aRequestor traceObject:self level:level from:referrer |
|
8707 |
||
8708 |
"Created: / 2.9.1999 / 09:05:17 / stefan" |
|
8709 |
! ! |
|
8710 |
||
8711 |
!Object methodsFor:'user interaction & notifications'! |
|
8712 |
||
8713 |
activityNotification:aString |
|
8714 |
"this can be sent from deeply nested methods, which are going to perform |
|
8715 |
some long-time activity. |
|
8716 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
8717 |
passing the argument. The handler should show this message whereever it likes, |
|
8718 |
and proceed. If there is no handler, this is simply ignored. |
|
8719 |
||
8720 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
8721 |
which likes to display that message in its label or a busy-box. |
|
8722 |
It could also be put into some logfile or printed on the standard output/error." |
|
8723 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8724 |
ActivityNotification isHandled ifTrue:[ |
10460 | 8725 |
^ ActivityNotification raiseRequestWith:self errorString:aString |
5755 | 8726 |
]. |
8727 |
||
8728 |
" |
|
8729 |
nil activityNotification:'hello there' |
|
8730 |
self activityNotification:'hello there' |
|
8731 |
" |
|
8732 |
||
8733 |
" |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8734 |
ActivityNotification handle:[:ex | |
10460 | 8735 |
ex errorString printCR. |
8736 |
ex proceed. |
|
5755 | 8737 |
] do:[ |
10460 | 8738 |
'hello' printCR. |
8739 |
self activityNotification:'doing some long time computation'. |
|
8740 |
'world' printCR. |
|
5755 | 8741 |
] |
8742 |
" |
|
8743 |
||
8744 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
8745 |
! |
|
8746 |
||
8747 |
confirm:aString |
|
9694 | 8748 |
"open a modal yes-no dialog. |
8749 |
Return true for yes, false for no. |
|
10527
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8750 |
If no GUI is present (headless applications), true is returned. |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8751 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8752 |
Someone in the sender chain may redefine the confirmation handler |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8753 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8754 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8755 |
^ UserConfirmation raiseRequestErrorString:aString |
10460 | 8756 |
|
5755 | 8757 |
" |
8758 |
nil confirm:'hello' |
|
8759 |
self confirm:'hello' |
|
8760 |
" |
|
8761 |
! |
|
8762 |
||
8763 |
confirm:aString orCancel:cancelBlock |
|
8764 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8765 |
return true for yes, false for no, or the value from cancelBlock for cancel. |
|
8766 |
If no GUI is present (headless applications), cancelBlock is returned." |
|
8767 |
||
8768 |
|answer| |
|
8769 |
||
8770 |
answer := self confirmWithCancel:aString. |
|
8771 |
answer isNil ifTrue:[ |
|
10460 | 8772 |
^ cancelBlock value |
5755 | 8773 |
]. |
8774 |
^ answer |
|
10460 | 8775 |
|
5755 | 8776 |
" |
8777 |
self confirm:'hello' orCancel:[self halt] |
|
8778 |
" |
|
8779 |
||
8780 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8781 |
! |
|
8782 |
||
8783 |
confirmWithCancel:aString |
|
8784 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8785 |
return true for yes, false for no, nil for cancel. |
|
10527
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8786 |
If no GUI is present (headless applications), nil is returned. |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8787 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8788 |
Someone in the sender chain may redefine the confirmation handler |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8789 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8790 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8791 |
^ UserConfirmation new |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8792 |
canCancel:true; |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8793 |
errorString:aString; |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8794 |
raiseRequest |
10460 | 8795 |
|
8796 |
" |
|
8797 |
nil confirmWithCancel:'hello' |
|
5755 | 8798 |
self confirmWithCancel:'hello' |
8799 |
" |
|
8800 |
! |
|
8801 |
||
8802 |
errorNotify:aString |
|
8803 |
"launch a Notifier, showing top stack, telling user something |
|
8804 |
and give user a chance to enter debugger." |
|
8805 |
||
8806 |
^ self |
|
10460 | 8807 |
errorNotify:aString |
8808 |
from:thisContext sender |
|
8809 |
allowDebug:true |
|
5755 | 8810 |
|
8811 |
" |
|
8812 |
nil errorNotify:'hello there' |
|
8813 |
self errorNotify:'hello there' |
|
8814 |
" |
|
8815 |
||
6199 | 8816 |
"Modified: / 16.11.2001 / 15:36:49 / cg" |
5755 | 8817 |
! |
8818 |
||
8819 |
errorNotify:aString from:aContext |
|
10460 | 8820 |
"launch a Notifier, showing top stack (above aContext), |
5755 | 8821 |
telling user something and give user a chance to enter debugger." |
8822 |
||
8823 |
^ self errorNotify:aString from:aContext allowDebug:true |
|
8824 |
||
8825 |
"Modified: / 17.8.1998 / 10:09:27 / cg" |
|
8826 |
! |
|
8827 |
||
8828 |
errorNotify:aString from:aContext allowDebug:allowDebug |
|
10460 | 8829 |
"launch a Notifier, showing top stack (above aContext), |
5755 | 8830 |
telling user something and optionally give the user a chance to enter debugger." |
8831 |
||
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8832 |
|currentScreen con sender action boxLabels boxValues default| |
5755 | 8833 |
|
8834 |
Smalltalk isInitialized ifFalse:[ |
|
10460 | 8835 |
'errorNotification: ' print. aString printCR. |
8836 |
^ nil |
|
8837 |
]. |
|
8838 |
(Dialog isNil |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8839 |
or:[Screen isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8840 |
or:[(currentScreen := Screen current) isNil |
10460 | 8841 |
or:[currentScreen isOpen not]]]) ifTrue:[ |
8842 |
" |
|
8843 |
on systems without GUI, simply show |
|
8844 |
the message on the Transcript and abort. |
|
8845 |
" |
|
8846 |
Transcript showCR:aString. |
|
8847 |
AbortOperationRequest raise. |
|
8848 |
"not reached" |
|
8849 |
^ nil |
|
5755 | 8850 |
]. |
8851 |
||
8852 |
Processor activeProcessIsSystemProcess ifTrue:[ |
|
10460 | 8853 |
action := #debug. |
8854 |
sender := aContext. |
|
8855 |
Debugger isNil ifTrue:[ |
|
8856 |
'****************** Cought Error while in SystemProcess ****************' errorPrintCR. |
|
8857 |
thisContext fullPrintAll. |
|
8858 |
action := #abort. |
|
8859 |
]. |
|
5755 | 8860 |
] ifFalse:[ |
10460 | 8861 |
Dialog autoload. "in case it's autoloaded" |
8862 |
||
8863 |
Error handle:[:ex | |
|
8864 |
"/ a recursive error - quickly enter debugger |
|
8865 |
"/ this happened, when I corrupted the Dialog class ... |
|
8866 |
('Object [error]: ' , ex description , ' caught in errorNotification') errorPrintCR. |
|
8867 |
action := #debug. |
|
8868 |
ex return. |
|
8869 |
] do:[ |s| |
|
8870 |
sender := aContext. |
|
8871 |
sender isNil ifTrue:[ |
|
8872 |
sender := thisContext sender. |
|
8873 |
]. |
|
8874 |
con := sender. |
|
8875 |
||
8876 |
"/ skip intermediate (signal & exception) contexts |
|
8877 |
DebugView notNil ifTrue:[ |
|
8878 |
con := DebugView interestingContextFrom:sender |
|
8879 |
]. |
|
8880 |
||
8881 |
"/ show the first few contexts |
|
8882 |
||
8883 |
s := WriteStream with:aString. |
|
8884 |
s cr; cr. |
|
8885 |
1 to:15 do:[:n | |
|
8886 |
con notNil ifTrue:[ |
|
8887 |
con printOn:s. |
|
8888 |
s cr. |
|
8889 |
con := con sender |
|
8890 |
] |
|
8891 |
]. |
|
8892 |
||
8893 |
(allowDebug and:[Debugger notNil]) ifTrue:[ |
|
8894 |
boxLabels := #('Proceed' 'Abort' 'Copy Trace and Abort' 'Debug'). |
|
8895 |
boxValues := #(#proceed #abort #copy #debug). |
|
8896 |
default := #debug. |
|
8897 |
] ifFalse:[ |
|
8898 |
boxLabels := #('Proceed' 'Abort' 'Copy Trace and Abort'). |
|
8899 |
boxValues := #(#proceed #abort #copy). |
|
8900 |
default := #abort. |
|
8901 |
]. |
|
8902 |
||
8903 |
action := Dialog |
|
8904 |
choose:s contents |
|
8905 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
|
8906 |
image:WarningBox errorIconBitmap |
|
8907 |
labels:boxLabels |
|
8908 |
values:boxValues |
|
8909 |
default:default |
|
8910 |
onCancel:nil. |
|
8911 |
]. |
|
5755 | 8912 |
]. |
8913 |
||
8914 |
action == #debug ifTrue:[ |
|
10460 | 8915 |
^ Debugger enter:sender withMessage:aString mayProceed:true |
5755 | 8916 |
] ifFalse:[ |
10460 | 8917 |
action == #proceed ifTrue:[ |
8918 |
^ nil. |
|
8919 |
]. |
|
8920 |
action == #copy ifTrue:[ |s| |
|
8921 |
s := '' writeStream. |
|
8922 |
sender fullPrintAllOn:s. |
|
8923 |
currentScreen rootView setClipboardText:s contents. |
|
8924 |
]. |
|
8925 |
AbortOperationRequest raise. |
|
8926 |
"not reached" |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8927 |
]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8928 |
|
5755 | 8929 |
|
8930 |
" |
|
8931 |
nil errorNotify:'hello there' |
|
8932 |
self errorNotify:'hello there' |
|
8933 |
" |
|
8934 |
||
8935 |
"Created: / 17.8.1998 / 10:09:26 / cg" |
|
6199 | 8936 |
"Modified: / 16.11.2001 / 15:40:12 / cg" |
5755 | 8937 |
! |
8938 |
||
8939 |
information:aString |
|
10460 | 8940 |
"launch an InfoBox, telling user something. |
8941 |
These info-boxes can be suppressed by handling |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8942 |
UserNotification or InformationSignal and proceeding in the handler. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8943 |
Use #notify: for more important messages. |
8371 | 8944 |
If nobody handles the exception, the default action of UserNotification |
10527
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8945 |
pops up an info dialog." |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8946 |
|
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
8947 |
UserInformation raiseRequestWith:self errorString:aString |
5755 | 8948 |
|
8949 |
" |
|
8950 |
nil information:'hello there' |
|
8951 |
self information:'hello there' |
|
8952 |
" |
|
8953 |
||
8954 |
" |
|
8955 |
InformationSignal handle:[:ex | |
|
10527
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8956 |
'no box popped' printCR. |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8957 |
ex proceed. |
5755 | 8958 |
] do:[ |
10527
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8959 |
'hello' printCR. |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8960 |
self information:'some info'. |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
8961 |
'world' printCR. |
5755 | 8962 |
] |
8963 |
" |
|
8964 |
||
8965 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
8966 |
! |
|
8967 |
||
8968 |
notify:aString |
|
8969 |
"launch a Notifier, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8970 |
Use #information: for ignorable messages. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8971 |
If nobody handles the exception, the dafault action of UserNotification |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8972 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8973 |
|
5755 | 8974 |
|
8975 |
Smalltalk isInitialized ifFalse:[ |
|
10460 | 8976 |
"/ thisContext fullPrintAll. |
8977 |
'information: ' print. aString printCR. |
|
8978 |
^ self |
|
5755 | 8979 |
]. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8980 |
UserNotification raiseRequestWith:self errorString:aString. |
5755 | 8981 |
|
8982 |
" |
|
8983 |
nil notify:'hello there' |
|
8984 |
self notify:'hello there' |
|
8985 |
" |
|
8986 |
||
8987 |
"Modified: 20.5.1996 / 10:28:48 / cg" |
|
8988 |
! |
|
8989 |
||
8990 |
warn:aString |
|
8991 |
"launch a WarningBox, telling user something. |
|
10460 | 8992 |
These warn-boxes can be suppressed by handling the |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8993 |
UserNotification- or WarningSignal and proceeding in the handler. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8994 |
If nobody handles the exception, the dafault action of Warning |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8995 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8996 |
|
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8997 |
Warning raiseRequestWith:self errorString:aString |
5755 | 8998 |
|
8999 |
" |
|
9000 |
nil warn:'hello there' |
|
9001 |
self warn:'hello there' |
|
9002 |
" |
|
9003 |
||
9004 |
" |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9005 |
Warning handle:[:ex | |
10460 | 9006 |
Transcript showCR:ex description. |
9007 |
ex proceed. |
|
5755 | 9008 |
] do:[ |
10460 | 9009 |
'hello' printCR. |
9010 |
self warn:'some info'. |
|
9011 |
'world' printCR. |
|
5755 | 9012 |
] |
9013 |
" |
|
9014 |
||
9015 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
|
9016 |
! ! |
|
9017 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9018 |
!Object methodsFor:'visiting'! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9019 |
|
8426 | 9020 |
acceptVisitor:aVisitor |
9021 |
"double-dispatch onto a Visitor." |
|
9022 |
||
9023 |
^ self acceptVisitor:aVisitor with:nil |
|
9024 |
! |
|
9025 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9026 |
acceptVisitor:aVisitor with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9027 |
"double-dispatch onto a Visitor. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9028 |
Subclasses redefine this" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9029 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9030 |
^ aVisitor visitObject:self with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9031 |
! ! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9032 |
|
5755 | 9033 |
!Object class methodsFor:'documentation'! |
1 | 9034 |
|
5754 | 9035 |
version |
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
9036 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.603 2008-06-04 15:19:28 cg Exp $' |
1 | 9037 |
! ! |
6764 | 9038 |
|
5755 | 9039 |
Object initialize! |