author | Stefan Vogel <sv@exept.de> |
Mon, 30 Aug 2004 20:00:25 +0200 | |
changeset 8500 | 10d47cede03c |
parent 8481 | d12d202b6ddb |
child 8502 | 7720740cf40f |
permissions | -rw-r--r-- |
5755 | 1 |
" |
2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
6654 | 3 |
All Rights Reserved |
5755 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
"{ Package: 'stx:libbasic' }" |
|
14 |
||
15 |
nil subclass:#Object |
|
6697 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'ErrorSignal HaltSignal MessageNotUnderstoodSignal |
|
18 |
UserInterruptSignal RecursionInterruptSignal |
|
19 |
ExceptionInterruptSignal SubscriptOutOfBoundsSignal |
|
20 |
IndexNotFoundSignal NonIntegerIndexSignal NotFoundSignal |
|
21 |
KeyNotFoundSignal ElementOutOfBoundsSignal UserNotificationSignal |
|
22 |
InformationSignal WarningSignal PrimitiveFailureSignal |
|
23 |
DeepCopyErrorSignal AbortSignal ErrorRecursion Dependencies |
|
24 |
InfoPrinting ActivityNotificationSignal InternalErrorSignal |
|
25 |
NonWeakDependencies SynchronizationSemaphores ObjectAttributes |
|
26 |
OSSignalInterruptSignal FinalizationLobby |
|
27 |
RecursiveStoreStringSignal AbortAllSignal' |
|
28 |
poolDictionaries:'' |
|
29 |
category:'Kernel-Objects' |
|
5755 | 30 |
! |
31 |
||
32 |
!Object class methodsFor:'documentation'! |
|
3023
674376809496
general listView support (#displayOn / widthOn / heightOn)
ca
parents:
3010
diff
changeset
|
33 |
|
5754 | 34 |
copyright |
5755 | 35 |
" |
36 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
6654 | 37 |
All Rights Reserved |
5755 | 38 |
|
39 |
This software is furnished under a license and may be used |
|
40 |
only in accordance with the terms of that license and with the |
|
41 |
inclusion of the above copyright notice. This software may not |
|
42 |
be provided or otherwise made available to, or used by, any |
|
43 |
other person. No title to or ownership of the software is |
|
44 |
hereby transferred. |
|
45 |
" |
|
46 |
! |
|
47 |
||
48 |
dependencies |
|
49 |
" |
|
50 |
ST/X dependencies are slightly modified from ST-80's |
|
51 |
(we think they are better ;-). |
|
52 |
||
53 |
One problem occuring very often in ST-80 is that some object |
|
54 |
cannot be garbage collected because some dependency is present, |
|
55 |
having the object as a dependent of some other object. |
|
56 |
In ST-80, this association remains alive (because a Dictionary |
|
57 |
is used to hold dependents) - even if no other references exist to |
|
58 |
to dependent or the dependee. |
|
59 |
||
60 |
This means, that in ST-80, a #release is mandatory in order to |
|
61 |
prevent memory leaks. |
|
62 |
We think, that this is a bad solution, since after all, exactly that |
|
63 |
kind of work should be performed by a garbage collector - you should not |
|
64 |
need to care about dependencies. |
|
65 |
From a philosophical point of view, why should some object depend on |
|
66 |
something that the programmer considers a dead object ? |
|
67 |
(well - worse than that: it seems that some ST-80 code even depends on |
|
68 |
that behavior) |
|
69 |
||
70 |
In order to limit the trouble, ST-80 reimplemented the way dependents |
|
71 |
are stored in the model class - this one keeps the dependents locally, |
|
72 |
so these dependents go away, once the model is reclaimed. |
|
73 |
That may make things even more confusing: with models, no #release is |
|
74 |
needed, with general objects it is mandatory. |
|
75 |
||
76 |
||
77 |
In ST/X, dependencies are implemented using a WeakDictionary; this means, |
|
78 |
that once the dependee dies, the dependency association is removed automatically, |
|
79 |
and the dependent can be reclaimed by the garbage collector, if no other |
|
80 |
references exist to the dependent. |
|
81 |
In order to (at least) provide a mechanism for the old behavior |
|
82 |
(in case your application heavily depends on the ST-80 mechanism), complementary |
|
83 |
protocol to add nonWeak dependencies is provided |
|
84 |
(see #addNonWeakDependent / #removeNonWeakDependent). |
|
85 |
||
86 |
||
87 |
Caveat: |
|
88 |
since interests are implemented using InterestConverter (which are simply |
|
89 |
forwarding messages), these must use the nonWeak mechanism (as done in ST-80 |
|
90 |
automatically). |
|
91 |
The reason is that there are usually no direct references to the converters, |
|
92 |
and those would be reclaimed if stored in a weakDictionary. |
|
93 |
This means, that those interests MUST be removed with #retractInterest |
|
94 |
(which is bug-compatible to ST-80). |
|
95 |
We rewrite things to provide a more convenient mechanism in the future ... |
|
96 |
||
97 |
||
98 |
I like to hear comments on the above - do you think its better ? |
|
99 |
" |
|
100 |
! |
|
101 |
||
102 |
documentation |
|
103 |
" |
|
104 |
Object is the superclass of most other classes. |
|
105 |
(except for nil-subclasses, which inherit nothing, |
|
106 |
to catch any message into their #doesNotUnderstand: method) |
|
107 |
||
108 |
Protocol which is common to every object is defined here. |
|
109 |
Also some utility stuff (like notify) and error handling is implemented here. |
|
110 |
||
111 |
Object has no instance variables (and may not get any added). One reason is, that |
|
112 |
UndefinedObject and SmallInteger are also inheriting from Object - these two cannot |
|
113 |
have instance variables (due to their implementation). |
|
114 |
The other reason is that the runtime system (VM) knows about the layout of some built-in |
|
115 |
classes (think of Class, Method, Block and also Integer or Float). |
|
116 |
If you were allowed to add instance variables to Object, the VM had to be recompiled |
|
117 |
(and also rewritten in some places). |
|
118 |
||
119 |
[Class variables:] |
|
120 |
||
6654 | 121 |
ErrorSignal <Signal> Signal raised for error/error: messages |
122 |
also, parent of all other signals. |
|
123 |
||
124 |
HaltSignal <Signal> Signal raised for halt/halt: messages |
|
125 |
||
126 |
MessageNotUnderstoodSignal Signals raised for various error conditions |
|
127 |
UserInterruptSignal |
|
128 |
RecursionInterruptSignal |
|
129 |
ExceptionInterruptSignal |
|
130 |
SubscriptOutOfBoundsSignal |
|
131 |
NonIntegerIndexSignal |
|
132 |
NotFoundSignal |
|
133 |
KeyNotFoundSignal |
|
134 |
ElementOutOfBoundsSignal |
|
135 |
InformationSignal |
|
136 |
WarningSignal |
|
137 |
DeepCopyErrorSignal |
|
138 |
InternalErrorSignal |
|
139 |
||
140 |
AbortSignal <Signal> Signal raised by debugger, to abort a computation |
|
141 |
BUT, the debugger will only raise it if it is handled. |
|
142 |
By handling the abortSignal, you can control where the |
|
143 |
debuggers abort-function resumes execution in case of |
|
144 |
an error. |
|
145 |
||
146 |
ErrorRecursion <Boolean> controls behavior when recursive errors occur (i.e. |
|
147 |
an error while handling an error). |
|
148 |
||
149 |
Dependencies <WeakDependencyDictionary> |
|
150 |
keeps track of object dependencies. |
|
151 |
||
152 |
InfoPrinting <Boolean> controls weather informational messages |
|
153 |
are printed. |
|
154 |
||
155 |
ActivityNotificationSignal <QuerySignal> |
|
156 |
raised on #activityNotification: |
|
157 |
||
158 |
NonWeakDependencies <Dictionary> keeps track of object dependencies. |
|
159 |
Dependents stay alive. |
|
160 |
||
161 |
SynchronizationSemaphores <WeakIdentityDictionary> |
|
162 |
Semaphores for per-object-monitor. |
|
5755 | 163 |
|
164 |
||
165 |
[author:] |
|
6654 | 166 |
Claus Gittinger |
5755 | 167 |
|
168 |
" |
|
169 |
! ! |
|
170 |
||
171 |
!Object class methodsFor:'initialization'! |
|
172 |
||
5971 | 173 |
initSignals |
174 |
"called only once - initialize signals" |
|
175 |
||
176 |
ErrorSignal := Error. |
|
177 |
||
178 |
ControlInterrupt notifierString:'control interrupted'. |
|
179 |
||
180 |
HaltSignal := HaltInterrupt. |
|
181 |
HaltSignal notifierString:'halt encountered'. |
|
182 |
||
5977 | 183 |
MessageNotUnderstoodSignal := MessageNotUnderstood. |
5971 | 184 |
MessageNotUnderstoodSignal notifierString:'message not understood'. |
185 |
||
6000 | 186 |
PrimitiveFailureSignal := PrimitiveFailure. |
5971 | 187 |
PrimitiveFailureSignal notifierString:'primitive failed'. |
188 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
189 |
InternalErrorSignal := VMInternalError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
190 |
|
5971 | 191 |
UserInterruptSignal := UserInterrupt. |
192 |
UserInterruptSignal notifierString:'user Interrupt'. |
|
193 |
||
6146 | 194 |
RecursionInterruptSignal := RecursionError. |
5971 | 195 |
RecursionInterruptSignal notifierString:'recursion limit reached'. |
196 |
||
5977 | 197 |
NotFoundSignal := NotFoundError. |
5971 | 198 |
NotFoundSignal notifierString:'no such element'. |
199 |
||
5977 | 200 |
IndexNotFoundSignal := IndexNotFoundError. |
5971 | 201 |
IndexNotFoundSignal notifierString:'bad index: '. |
202 |
||
5977 | 203 |
SubscriptOutOfBoundsSignal := SubscriptOutOfBoundsError. |
5971 | 204 |
SubscriptOutOfBoundsSignal notifierString:'subscript out of bounds: '. |
205 |
||
5977 | 206 |
NonIntegerIndexSignal := NonIntegerIndexError. |
207 |
NonIntegerIndexSignal notifierString:'index must be integer'. |
|
208 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
209 |
KeyNotFoundSignal := KeyNotFoundError. |
5977 | 210 |
KeyNotFoundSignal notifierString:'no such key: '. |
211 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
212 |
ElementOutOfBoundsSignal := ElementBoundsError. |
5971 | 213 |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
214 |
UserNotificationSignal := UserNotification. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
215 |
WarningSignal := Warning. |
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
216 |
InformationSignal := UserInformation. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
217 |
ActivityNotificationSignal := ActivityNotification. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
218 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
219 |
DeepCopyErrorSignal := DeepCopyError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
220 |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
221 |
AbortSignal := AbortOperationRequest. |
6877
ab4e7d42f9f8
AbortAllOperation - now class based
Claus Gittinger <cg@exept.de>
parents:
6874
diff
changeset
|
222 |
AbortAllSignal := AbortAllOperationRequest. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
223 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
224 |
OSSignalInterruptSignal := OSSignalInterrupt. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
225 |
RecursiveStoreStringSignal := RecursiveStoreError. |
5971 | 226 |
|
5980 | 227 |
" |
228 |
Object initSignals |
|
229 |
" |
|
5971 | 230 |
|
231 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
232 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
233 |
"Modified: / 16.11.2001 / 16:30:08 / cg" |
5971 | 234 |
! |
235 |
||
5755 | 236 |
initialize |
237 |
"called only once - initialize signals" |
|
238 |
||
239 |
ErrorSignal isNil ifTrue:[ |
|
6654 | 240 |
self initSignals |
5971 | 241 |
]. |
242 |
||
243 |
ObjectAttributes isNil ifTrue:[ |
|
6654 | 244 |
ObjectAttributes := WeakIdentityDictionary new. |
5971 | 245 |
]. |
246 |
Dependencies isNil ifTrue:[ |
|
6654 | 247 |
Dependencies := WeakDependencyDictionary new. |
5971 | 248 |
]. |
249 |
NonWeakDependencies isNil ifTrue:[ |
|
6654 | 250 |
NonWeakDependencies := IdentityDictionary new. |
5971 | 251 |
]. |
252 |
SynchronizationSemaphores isNil ifTrue:[ |
|
6654 | 253 |
SynchronizationSemaphores := WeakIdentityDictionary new. |
5971 | 254 |
]. |
5755 | 255 |
FinalizationLobby isNil ifTrue:[ |
6654 | 256 |
FinalizationLobby := Registry new. |
5755 | 257 |
]. |
258 |
||
259 |
"/ initialize InfoPrinting to the VM's infoPrint setting |
|
260 |
"/ (which can be turned off via a command line argument) |
|
261 |
InfoPrinting := ObjectMemory infoPrinting. |
|
262 |
||
263 |
"Object initialize" |
|
264 |
||
265 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
266 |
"Modified: / 3.2.1998 / 18:55:09 / cg" |
|
267 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
268 |
! ! |
|
269 |
||
7303 | 270 |
!Object class methodsFor:'Compatibility-ST80'! |
5755 | 271 |
|
272 |
rootError |
|
273 |
"return the signal used for error/error: - handling. |
|
274 |
Same as errorSignal for ST80 compatibility." |
|
275 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
276 |
^ Error |
5755 | 277 |
|
278 |
"Created: / 15.1.1998 / 23:47:05 / stefan" |
|
279 |
! ! |
|
280 |
||
281 |
!Object class methodsFor:'Signal constants'! |
|
282 |
||
283 |
abortAllSignal |
|
284 |
"return the signal used to abort user actions (much like AbortSignal). |
|
285 |
This signal is supposed to abort multiple operation actions, and get out of |
|
286 |
the loop (such as when confirming multiple class deletions etc.)" |
|
287 |
||
288 |
^ AbortAllSignal |
|
289 |
! |
|
290 |
||
291 |
abortSignal |
|
292 |
"return the signal used to abort user actions. This signal is only |
|
293 |
raised if caught (by the debugger), and will lead way out of the |
|
294 |
currently active doIt/printIt or inspectIt. (also some others use |
|
295 |
this for a save abort)" |
|
296 |
||
297 |
^ AbortSignal |
|
298 |
! |
|
299 |
||
300 |
activityNotificationSignal |
|
301 |
"return the signal used for activity notifications. |
|
302 |
A handler for this signal gets all #activityNotification: sends" |
|
303 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
304 |
^ ActivityNotification |
5755 | 305 |
! |
306 |
||
307 |
deepCopyErrorSignal |
|
308 |
"return the signal raised when a deepcopy is asked for |
|
309 |
an object which cannot do this (for example, BlockClosures |
|
310 |
or Contexts)." |
|
311 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
312 |
^ DeepCopyError |
5755 | 313 |
! |
314 |
||
315 |
elementOutOfBoundsSignal |
|
316 |
"return the signal used for element error reporting |
|
317 |
(this signal is used for example when a value not in 0..255 is to |
|
318 |
be put into a bytearray)" |
|
319 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
320 |
^ ElementBoundsError |
5755 | 321 |
! |
322 |
||
323 |
errorSignal |
|
324 |
"return the signal used for error/error: - handling" |
|
325 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
326 |
^ Error |
5755 | 327 |
! |
328 |
||
329 |
haltSignal |
|
330 |
"return the signal used for halt/halt: - handling" |
|
331 |
||
332 |
^ HaltSignal |
|
333 |
! |
|
334 |
||
335 |
indexNotFoundSignal |
|
336 |
"return the signal used for bad index error reporting. |
|
337 |
This is also the parentSignal of the nonIntegerIndex- and |
|
338 |
subscriptOutOfBoundsSignal" |
|
339 |
||
340 |
^ IndexNotFoundSignal |
|
341 |
||
342 |
"Created: / 8.11.1997 / 19:15:48 / cg" |
|
343 |
! |
|
344 |
||
345 |
informationSignal |
|
346 |
"return the signal used for informations. |
|
347 |
A handler for this signal gets all #information: sends" |
|
348 |
||
349 |
^ InformationSignal |
|
350 |
! |
|
351 |
||
352 |
internalErrorSignal |
|
353 |
"return the signal used to report internal (VM-) errors." |
|
354 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
355 |
^ VMInternalError |
5755 | 356 |
! |
357 |
||
358 |
keyNotFoundSignal |
|
359 |
"return the signal used for no such key error reporting" |
|
360 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
361 |
^ KeyNotFoundError |
5755 | 362 |
! |
363 |
||
364 |
messageNotUnderstoodSignal |
|
365 |
"return the signal used for doesNotUnderstand: - error handling" |
|
366 |
||
367 |
^ MessageNotUnderstoodSignal |
|
368 |
! |
|
369 |
||
370 |
nonIntegerIndexSignal |
|
371 |
"return the signal used for bad subscript error reporting" |
|
372 |
||
373 |
^ NonIntegerIndexSignal |
|
374 |
! |
|
375 |
||
376 |
notFoundSignal |
|
377 |
"return the signal used for no element found error reporting" |
|
378 |
||
379 |
^ NotFoundSignal |
|
380 |
! |
|
381 |
||
7644
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
382 |
notifySignal |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
383 |
"return the parent of all notification signals." |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
384 |
|
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
385 |
^ Notification |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
386 |
! |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
387 |
|
5755 | 388 |
osSignalInterruptSignal |
389 |
"return the signal used for OS-signal error reporting; |
|
390 |
This is only raised if handled - otherwise, a debugger is entered." |
|
391 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
392 |
^ OSSignalInterrupt |
5755 | 393 |
|
394 |
"Modified: / 12.6.1998 / 16:27:26 / cg" |
|
395 |
! |
|
396 |
||
397 |
primitiveFailureSignal |
|
398 |
"return the signal used for primitiveFailed - error handling" |
|
399 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
400 |
^ PrimitiveFailure |
5755 | 401 |
! |
402 |
||
403 |
privateMethodSignal |
|
404 |
"return the signal used for privateMethod - error handling" |
|
405 |
||
406 |
^ MessageNotUnderstoodSignal |
|
407 |
! |
|
408 |
||
409 |
recursionInterruptSignal |
|
410 |
"return the signal used for recursion overflow error handling" |
|
411 |
||
412 |
^ RecursionInterruptSignal |
|
413 |
! |
|
414 |
||
415 |
recursiveStoreStringSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
416 |
"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
|
417 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
418 |
^ RecursiveStoreError |
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 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
421 |
RecursiveStoreError handle:[:ex | |
6654 | 422 |
self halt |
5755 | 423 |
] do:[ |
6654 | 424 |
|a| |
425 |
||
426 |
a := Array new:1. |
|
427 |
a at:1 put:a. |
|
428 |
a storeOn:Transcript |
|
5755 | 429 |
] |
430 |
" |
|
431 |
||
432 |
" |
|
433 |
|a| |
|
434 |
||
435 |
a := Array new:1. |
|
436 |
a at:1 put:a. |
|
437 |
a storeOn:Transcript |
|
438 |
" |
|
439 |
! |
|
440 |
||
5980 | 441 |
subclassResponsibilitySignal |
442 |
"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
|
443 |
(this signal is used to signal incomplete subclasses - i.e. a programmers error)" |
5980 | 444 |
|
445 |
^ SubclassResponsibilityError |
|
446 |
! |
|
447 |
||
5755 | 448 |
subscriptOutOfBoundsSignal |
449 |
"return the signal used for subscript error reporting. |
|
450 |
(this signal is used for example when an array is accessed with an |
|
451 |
index less than 1 or greater than the array size)" |
|
452 |
||
453 |
^ SubscriptOutOfBoundsSignal |
|
454 |
! |
|
455 |
||
456 |
userInterruptSignal |
|
457 |
"return the signal used for ^C interrupts handling" |
|
458 |
||
459 |
^ UserInterruptSignal |
|
460 |
! |
|
461 |
||
462 |
userNotificationSignal |
|
463 |
"the parent signal used with information and warnings. |
|
464 |
Handling this allows handling of both information- and warning notifications." |
|
465 |
||
466 |
^ UserNotificationSignal |
|
467 |
! |
|
468 |
||
469 |
warningSignal |
|
470 |
"return the signal used for warnings. |
|
471 |
A handler for this signal gets all #warn: sends" |
|
472 |
||
473 |
^ WarningSignal |
|
474 |
! ! |
|
475 |
||
476 |
!Object class methodsFor:'info messages'! |
|
477 |
||
478 |
infoPrinting |
|
479 |
"return the flag which controls information messages." |
|
480 |
||
481 |
^ InfoPrinting |
|
482 |
! |
|
483 |
||
484 |
infoPrinting:aBoolean |
|
485 |
"{ Pragma: +optSpace }" |
|
486 |
||
487 |
"turn on/off printing of information messages. |
|
488 |
If the argument, aBoolean is false, infoPrint will not output |
|
489 |
messages. The default is true." |
|
490 |
||
491 |
InfoPrinting := aBoolean |
|
492 |
! ! |
|
493 |
||
494 |
!Object class methodsFor:'queries'! |
|
495 |
||
496 |
isBuiltInClass |
|
497 |
"return true, if this class is known by the run-time-system, |
|
498 |
i.e. you cannot add/remove instance variables without recompiling |
|
499 |
the VM. |
|
500 |
Here, true is returned for myself, false for subclasses." |
|
501 |
||
502 |
^ self == Object |
|
503 |
||
504 |
"Modified: 23.4.1996 / 16:00:07 / cg" |
|
505 |
! ! |
|
506 |
||
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
507 |
!Object methodsFor:'Compatibility-Dolphin'! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
508 |
|
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
509 |
trigger:anAspect |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
510 |
self changed:anAspect |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
511 |
! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
512 |
|
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
513 |
trigger:anAspect with:anArgument |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
514 |
self changed:anAspect with:anArgument |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
515 |
! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
516 |
|
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
517 |
when:anAspect sendTo:anObject |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
518 |
self expressInterestIn:anAspect for:anObject sendBack:anAspect |
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 |
|
7261 | 521 |
!Object methodsFor:'Compatibility-ST80'! |
5755 | 522 |
|
523 |
isMetaclass |
|
524 |
^ self isMeta |
|
525 |
! ! |
|
526 |
||
7261 | 527 |
!Object methodsFor:'Compatibility-Squeak'! |
5755 | 528 |
|
6549
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
529 |
as:aSimilarClass |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
530 |
"If the receivers class is not aSimilarClass, |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
531 |
create and return an object of class aSimilarClass that has the same contents |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
532 |
as the receiver. |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
533 |
Otherwise, return the receiver." |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
534 |
|
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
535 |
self class == aSimilarClass ifTrue:[^ self]. |
5755 | 536 |
^ aSimilarClass newFrom:self |
537 |
||
538 |
" |
|
539 |
#[1 2 3 4] as:ByteArray |
|
6549
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
540 |
#[1 2 3 4] as:Array |
5755 | 541 |
" |
542 |
! |
|
543 |
||
544 |
asString |
|
545 |
^ self printString |
|
546 |
! |
|
547 |
||
548 |
clone |
|
549 |
^ self shallowCopy |
|
550 |
! |
|
551 |
||
6146 | 552 |
copyTwoLevel |
553 |
"one more level than a shallowCopy" |
|
554 |
||
555 |
^ self copyToLevel:2 |
|
556 |
||
557 |
" |
|
558 |
|original copy elL1 elL2 elL3 copyOfElL1| |
|
559 |
||
560 |
original := Array new:3. |
|
561 |
original at:1 put:1234. |
|
562 |
original at:2 put:'hello'. |
|
563 |
original at:3 put:(elL1 := Array new:3). |
|
564 |
||
565 |
elL1 at:1 put:1234. |
|
566 |
elL1 at:2 put:'hello'. |
|
567 |
elL1 at:3 put:(elL2 := Array new:3). |
|
568 |
||
569 |
elL2 at:1 put:1234. |
|
570 |
elL2 at:2 put:'hello'. |
|
571 |
elL2 at:3 put:(elL3 := Array new:3). |
|
572 |
||
573 |
elL3 at:1 put:1234. |
|
574 |
elL3 at:2 put:'hello'. |
|
575 |
elL3 at:3 put:(Array new:3). |
|
576 |
||
577 |
copy := original copyTwoLevel. |
|
578 |
(original at:2) ~~ (copy at:2) ifFalse:[self halt]. |
|
579 |
(original at:3) ~~ (copy at:3) ifFalse:[self halt]. |
|
580 |
||
581 |
copyOfElL1 := copy at:3. |
|
582 |
(elL1 at:2) == (copyOfElL1 at:2) ifFalse:[self halt]. |
|
583 |
(elL1 at:3) == (copyOfElL1 at:3) ifFalse:[self halt]. |
|
584 |
" |
|
585 |
! |
|
586 |
||
5755 | 587 |
currentHand |
5912 | 588 |
"Return a usable HandMorph -- the one associated with the object's current environment. This method will always return a hand, even if it has to conjure one up as a last resort. If a particular hand is actually handling events at the moment (such as a remote hand or a ghost hand), it will be returned." |
589 |
||
590 |
|w h| |
|
591 |
||
592 |
w := self currentWorld. |
|
593 |
h := w activeHand. |
|
594 |
h isNil ifTrue:[ |
|
6654 | 595 |
h := w hands first |
5912 | 596 |
]. |
597 |
^ h |
|
5755 | 598 |
! |
599 |
||
600 |
currentWorld |
|
7159
7964c345d74c
Object currentWorld - recursion if Utilities is unloaded
Claus Gittinger <cg@exept.de>
parents:
7121
diff
changeset
|
601 |
Utilities autoload. |
7964c345d74c
Object currentWorld - recursion if Utilities is unloaded
Claus Gittinger <cg@exept.de>
parents:
7121
diff
changeset
|
602 |
^ Utilities currentWorld |
5755 | 603 |
! |
604 |
||
7320 | 605 |
explore |
606 |
(self confirm:'The Squeak explorer has not yet been ported to ST/X\\Inspect instead ?' withCRs) |
|
607 |
ifTrue:[ |
|
608 |
self inspect |
|
609 |
] |
|
610 |
! |
|
611 |
||
5755 | 612 |
newTileMorphRepresentative |
6654 | 613 |
^ TileMorph new setLiteral: self |
5755 | 614 |
! |
615 |
||
616 |
stringForReadout |
|
6654 | 617 |
^ self stringRepresentation |
5755 | 618 |
! |
619 |
||
620 |
stringRepresentation |
|
6654 | 621 |
"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" |
622 |
||
623 |
^ self printString |
|
5755 | 624 |
! |
625 |
||
626 |
veryDeepCopy |
|
8383 | 627 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 628 |
! ! |
629 |
||
7567 | 630 |
!Object methodsFor:'Compatibility-VW'! |
631 |
||
632 |
keyNotFoundError:aKey |
|
633 |
"VW compatibility" |
|
634 |
||
635 |
self errorKeyNotFound:aKey. |
|
636 |
! |
|
637 |
||
638 |
oneWayBecome:anotherObject |
|
639 |
^ self becomeSameAs:anotherObject |
|
640 |
||
641 |
" |
|
642 |
|arr o1 o2| |
|
643 |
||
644 |
arr := Array new:2. |
|
645 |
arr at:1 put:(o1 := Object new). |
|
646 |
arr at:2 put:(o2 := Point new). |
|
647 |
o1 oneWayBecome:o2. |
|
648 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
649 |
" |
|
650 |
" |
|
651 |
|arr o1 o2| |
|
652 |
||
653 |
arr := Array new:2. |
|
654 |
arr at:1 put:(o1 := Object new). |
|
655 |
arr at:2 put:(o2 := Point new). |
|
656 |
o1 becomeSameAs:o2. |
|
657 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
658 |
" |
|
659 |
! ! |
|
660 |
||
5755 | 661 |
!Object methodsFor:'accessing'! |
662 |
||
663 |
at:index |
|
664 |
"return the indexed instance variable with index, anInteger; |
|
665 |
this method can be redefined in subclasses." |
|
666 |
||
667 |
^ self basicAt:index |
|
668 |
! |
|
669 |
||
670 |
at:index put:anObject |
|
671 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
672 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
|
673 |
||
674 |
^ self basicAt:index put:anObject |
|
675 |
||
676 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
|
677 |
! |
|
678 |
||
679 |
basicAt:index |
|
680 |
"return the indexed instance variable with index, anInteger. |
|
681 |
Trigger an error if the receiver has no indexed instance variables. |
|
682 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
683 |
||
684 |
%{ /* NOCONTEXT */ |
|
685 |
||
686 |
REGISTER int nbytes, indx; |
|
687 |
OBJ myClass; |
|
688 |
REGISTER char *pFirst; |
|
689 |
REGISTER int n; |
|
690 |
||
691 |
/* |
|
692 |
* notice the missing test for self being a nonNilObject - |
|
693 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
694 |
* and SmallInteger |
|
695 |
*/ |
|
696 |
if (__isSmallInteger(index)) { |
|
6654 | 697 |
myClass = __qClass(self); |
698 |
indx = __intVal(index) - 1; |
|
699 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
700 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
701 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
702 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
703 |
||
704 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
705 |
case __MASKSMALLINT(POINTERARRAY): |
|
706 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
707 |
/* |
|
708 |
* pointers |
|
709 |
*/ |
|
710 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
711 |
OBJ *op; |
|
712 |
||
713 |
op = (OBJ *)pFirst + indx; |
|
714 |
RETURN ( *op ); |
|
715 |
} |
|
716 |
break; |
|
717 |
||
718 |
case __MASKSMALLINT(BYTEARRAY): |
|
719 |
/* |
|
720 |
* (unsigned) bytes |
|
721 |
*/ |
|
722 |
if ((unsigned)indx < nbytes) { |
|
723 |
unsigned char *cp; |
|
724 |
||
725 |
cp = (unsigned char *)pFirst + indx; |
|
726 |
RETURN ( __MKSMALLINT( (INT)(*cp & 0xFF)) ); |
|
727 |
} |
|
728 |
break; |
|
729 |
||
730 |
case __MASKSMALLINT(FLOATARRAY): |
|
731 |
/* |
|
732 |
* native floats |
|
733 |
*/ |
|
734 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
735 |
float *fp; |
|
736 |
float f; |
|
737 |
OBJ v; |
|
738 |
||
739 |
fp = (float *)pFirst + indx; |
|
740 |
f = *fp; |
|
741 |
if (f == 0.0) { |
|
742 |
v = __float0; |
|
743 |
} else { |
|
744 |
__qMKSFLOAT(v, f); |
|
745 |
} |
|
746 |
RETURN (v); |
|
747 |
} |
|
748 |
break; |
|
749 |
||
750 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
751 |
/* |
|
752 |
* native doubles |
|
753 |
*/ |
|
5755 | 754 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 755 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
756 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
757 |
||
758 |
pFirst += delta; |
|
759 |
nbytes -= delta; |
|
760 |
} |
|
5755 | 761 |
#endif |
6654 | 762 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
763 |
double *dp; |
|
764 |
double d; |
|
765 |
OBJ v; |
|
766 |
||
767 |
dp = (double *)pFirst + indx; |
|
768 |
d = *dp; |
|
769 |
if (d == 0.0) { |
|
770 |
v = __float0; |
|
771 |
} else { |
|
772 |
__qMKFLOAT(v, d); |
|
773 |
} |
|
774 |
RETURN (v); |
|
775 |
} |
|
776 |
break; |
|
777 |
||
778 |
case __MASKSMALLINT(WORDARRAY): |
|
779 |
/* |
|
780 |
* unsigned 16bit ints |
|
781 |
*/ |
|
782 |
/* Notice: the hard coded shifts are by purpose; |
|
783 |
* it makes us independent of the short-size of the machine |
|
784 |
*/ |
|
785 |
if ((unsigned)indx < (nbytes>>1)) { |
|
786 |
unsigned short *sp; |
|
787 |
||
788 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
789 |
RETURN ( __MKSMALLINT( (INT)(*sp & 0xFFFF)) ); |
|
790 |
} |
|
791 |
break; |
|
792 |
||
793 |
case __MASKSMALLINT(SWORDARRAY): |
|
794 |
/* |
|
795 |
* signed 16bit ints |
|
796 |
*/ |
|
797 |
/* Notice: the hard coded shifts are by purpose; |
|
798 |
* it makes us independent of the short-size of the machine |
|
799 |
*/ |
|
800 |
if ((unsigned)indx < (nbytes>>1)) { |
|
801 |
short *ssp; |
|
802 |
||
803 |
ssp = (short *)(pFirst + (indx<<1)); |
|
804 |
RETURN ( __MKSMALLINT( (INT)(*ssp) )); |
|
805 |
} |
|
806 |
break; |
|
807 |
||
808 |
case __MASKSMALLINT(LONGARRAY): |
|
809 |
/* |
|
810 |
* unsigned 32bit ints |
|
811 |
*/ |
|
812 |
/* Notice: the hard coded shifts are by purpose; |
|
813 |
* it makes us independent of the int-size of the machine |
|
814 |
*/ |
|
815 |
if ((unsigned)indx < (nbytes>>2)) { |
|
816 |
unsigned int32 ul; |
|
817 |
unsigned int32 *lp; |
|
818 |
||
819 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
820 |
ul = *lp; |
|
5755 | 821 |
#ifdef alpha64 |
6654 | 822 |
{ |
823 |
unsigned INT ull = (unsigned INT)ul; |
|
824 |
RETURN ( __MKSMALLINT(ull) ); |
|
825 |
} |
|
5755 | 826 |
#else |
6654 | 827 |
if (ul <= _MAX_INT) { |
828 |
RETURN ( __MKSMALLINT(ul) ); |
|
829 |
} |
|
830 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 831 |
#endif |
6654 | 832 |
} |
833 |
break; |
|
834 |
||
835 |
case __MASKSMALLINT(SLONGARRAY): |
|
836 |
/* |
|
837 |
* signed 32bit ints |
|
838 |
*/ |
|
839 |
/* Notice: the hard coded shifts are by purpose; |
|
840 |
* it makes us independent of the int-size of the machine |
|
841 |
*/ |
|
842 |
if ((unsigned)indx < (nbytes>>2)) { |
|
843 |
int32 *slp; |
|
844 |
int32 l; |
|
845 |
||
846 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
847 |
l = *slp; |
|
5755 | 848 |
#ifdef alpha64 |
6654 | 849 |
{ |
850 |
INT ll = (INT)l; |
|
851 |
RETURN ( __MKSMALLINT(ll) ); |
|
852 |
} |
|
5755 | 853 |
#else |
6654 | 854 |
if (__ISVALIDINTEGER(l)) { |
855 |
RETURN ( __MKSMALLINT(l) ); |
|
856 |
} |
|
857 |
RETURN ( __MKLARGEINT(l) ); |
|
5755 | 858 |
#endif |
6654 | 859 |
} |
860 |
break; |
|
861 |
||
862 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
863 |
/* |
|
864 |
* signed 64bit longlongs |
|
865 |
*/ |
|
5755 | 866 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 867 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
868 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
869 |
||
870 |
pFirst += delta; |
|
871 |
nbytes -= delta; |
|
872 |
} |
|
5755 | 873 |
#endif |
6654 | 874 |
/* Notice: the hard coded shifts are by purpose; |
875 |
* it makes us independent of the long/longlong-size of the machine |
|
876 |
*/ |
|
877 |
if ((unsigned)indx < (nbytes>>3)) { |
|
5755 | 878 |
#ifdef alpha64 |
6654 | 879 |
INT *slp, ll; |
880 |
||
881 |
slp = (INT *)(pFirst + (indx<<3)); |
|
882 |
ll = *slp; |
|
883 |
if (__ISVALIDINTEGER(ll)) { |
|
884 |
RETURN ( __MKSMALLINT(ll) ); |
|
885 |
} |
|
886 |
RETURN ( __MKLARGEINT(ll) ); |
|
5755 | 887 |
#else |
6654 | 888 |
__int64__ *llp; |
889 |
||
890 |
llp = (__int64__ *)(pFirst + (indx<<3)); |
|
891 |
RETURN (__MKINT64(llp)); |
|
5755 | 892 |
#endif |
6654 | 893 |
} |
894 |
break; |
|
895 |
||
896 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
897 |
/* |
|
898 |
* unsigned 64bit longlongs |
|
899 |
*/ |
|
5755 | 900 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 901 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
902 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
903 |
||
904 |
pFirst += delta; |
|
905 |
nbytes -= delta; |
|
906 |
} |
|
5755 | 907 |
#endif |
6654 | 908 |
/* Notice: the hard coded shifts are by purpose; |
909 |
* it makes us independent of the long/longlong-size of the machine |
|
910 |
*/ |
|
911 |
if ((unsigned)indx < (nbytes>>3)) { |
|
5755 | 912 |
#ifdef alpha64 |
6654 | 913 |
unsigned INT *ulp, ul; |
914 |
||
915 |
ulp = (unsigned INT *)(pFirst + (indx<<3)); |
|
916 |
ul = *ulp; |
|
917 |
if (ul <= _MAX_INT) { |
|
918 |
RETURN ( __MKSMALLINT(ul) ); |
|
919 |
} |
|
920 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 921 |
#else |
6654 | 922 |
__uint64__ *llp; |
923 |
||
924 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
925 |
RETURN (__MKUINT64(llp)); |
|
5755 | 926 |
#endif |
6654 | 927 |
} |
928 |
break; |
|
929 |
} |
|
5755 | 930 |
} |
931 |
%}. |
|
7216 | 932 |
^ self indexNotIntegerOrOutOfBounds:index |
5755 | 933 |
! |
934 |
||
935 |
basicAt:index put:anObject |
|
936 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
937 |
Returns anObject (sigh). |
|
938 |
Trigger an error if the receiver has no indexed instance variables. |
|
939 |
||
940 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
941 |
||
942 |
%{ /* NOCONTEXT */ |
|
943 |
||
944 |
register int nbytes, indx; |
|
945 |
OBJ myClass; |
|
946 |
register char *pFirst; |
|
947 |
/* int nInstBytes, ninstvars, flags; */ |
|
948 |
REGISTER int n; |
|
949 |
unsigned int u; |
|
950 |
int val; |
|
951 |
||
952 |
/* notice the missing test for self being a nonNilObject - |
|
953 |
this can be done since basicAt: is defined both in UndefinedObject |
|
954 |
and SmallInteger */ |
|
955 |
||
956 |
if (__isSmallInteger(index)) { |
|
6654 | 957 |
indx = __intVal(index) - 1; |
958 |
myClass = __qClass(self); |
|
959 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
960 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
961 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
962 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
963 |
||
964 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
965 |
case __MASKSMALLINT(POINTERARRAY): |
|
966 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
967 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
968 |
OBJ *op; |
|
969 |
||
970 |
op = (OBJ *)pFirst + indx; |
|
971 |
*op = anObject; |
|
972 |
__STORE(self, anObject); |
|
973 |
RETURN ( anObject ); |
|
974 |
} |
|
975 |
break; |
|
976 |
||
977 |
case __MASKSMALLINT(BYTEARRAY): |
|
978 |
if (__isSmallInteger(anObject)) { |
|
979 |
val = __intVal(anObject); |
|
980 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
981 |
if ((unsigned)indx < nbytes) { |
|
982 |
char *cp; |
|
983 |
||
984 |
cp = pFirst + indx; |
|
985 |
*cp = val; |
|
986 |
RETURN ( anObject ); |
|
987 |
} |
|
988 |
} |
|
989 |
} |
|
990 |
break; |
|
991 |
||
992 |
case __MASKSMALLINT(FLOATARRAY): |
|
993 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
994 |
float *fp; |
|
995 |
||
996 |
fp = (float *)pFirst + indx; |
|
997 |
if (anObject != nil) { |
|
998 |
if (! __isSmallInteger(anObject)) { |
|
999 |
if (__qIsFloatLike(anObject)) { |
|
1000 |
*fp = (float)(__floatVal(anObject)); |
|
1001 |
RETURN ( anObject ); |
|
1002 |
} |
|
1003 |
if (__qIsShortFloat(anObject)) { |
|
1004 |
*fp = __shortFloatVal(anObject); |
|
1005 |
RETURN ( anObject ); |
|
1006 |
} |
|
1007 |
} else { |
|
1008 |
*fp = (float) __intVal(anObject); |
|
1009 |
RETURN ( anObject ); |
|
1010 |
} |
|
1011 |
} |
|
1012 |
} |
|
1013 |
break; |
|
1014 |
||
1015 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1016 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 1017 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1018 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1019 |
||
1020 |
pFirst += delta; |
|
1021 |
nbytes -= delta; |
|
1022 |
} |
|
5755 | 1023 |
#endif |
6654 | 1024 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
1025 |
double *dp; |
|
1026 |
||
1027 |
dp = (double *)pFirst + indx; |
|
1028 |
if (anObject != nil) { |
|
1029 |
if (! __isSmallInteger(anObject)) { |
|
1030 |
if (__qIsFloatLike(anObject)) { |
|
1031 |
*dp = __floatVal(anObject); |
|
1032 |
RETURN ( anObject ); |
|
1033 |
} |
|
1034 |
if (__qIsShortFloat(anObject)) { |
|
1035 |
*dp = (double)__shortFloatVal(anObject); |
|
1036 |
RETURN ( anObject ); |
|
1037 |
} |
|
1038 |
} else { |
|
1039 |
*dp = (double) __intVal(anObject); |
|
1040 |
RETURN ( anObject ); |
|
1041 |
} |
|
1042 |
} |
|
1043 |
} |
|
1044 |
break; |
|
1045 |
||
1046 |
case __MASKSMALLINT(WORDARRAY): |
|
1047 |
if (__isSmallInteger(anObject)) { |
|
1048 |
val = __intVal(anObject); |
|
1049 |
if ((unsigned)val <= 0xFFFF) { |
|
1050 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1051 |
unsigned short *sp; |
|
1052 |
||
1053 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
1054 |
*sp = val; |
|
1055 |
RETURN ( anObject ); |
|
1056 |
} |
|
1057 |
} |
|
1058 |
} |
|
1059 |
break; |
|
1060 |
||
1061 |
case __MASKSMALLINT(SWORDARRAY): |
|
1062 |
if (__isSmallInteger(anObject)) { |
|
1063 |
val = __intVal(anObject); |
|
1064 |
if ((val >= -32768) && (val < 32768)) { |
|
1065 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1066 |
short *ssp; |
|
1067 |
||
1068 |
ssp = (short *)(pFirst + (indx<<1)); |
|
1069 |
*ssp = val; |
|
1070 |
RETURN ( anObject ); |
|
1071 |
} |
|
1072 |
} |
|
1073 |
} |
|
1074 |
break; |
|
1075 |
||
1076 |
case __MASKSMALLINT(SLONGARRAY): |
|
1077 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1078 |
int32 *slp; |
|
1079 |
||
1080 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
1081 |
if (__isSmallInteger(anObject)) { |
|
1082 |
*slp = __intVal(anObject); |
|
1083 |
RETURN ( anObject ); |
|
1084 |
} |
|
1085 |
n = __signedLongIntVal(anObject); |
|
1086 |
/* |
|
1087 |
* zero means failure for an int larger than 4 bytes |
|
1088 |
* (would be a smallInteger) |
|
1089 |
*/ |
|
1090 |
if (n) { |
|
1091 |
*slp = n; |
|
1092 |
RETURN ( anObject ); |
|
1093 |
} |
|
1094 |
} |
|
1095 |
break; |
|
1096 |
||
1097 |
case __MASKSMALLINT(LONGARRAY): |
|
1098 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1099 |
unsigned int32 *lp; |
|
1100 |
||
1101 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
1102 |
if (anObject == __MKSMALLINT(0)) { |
|
1103 |
*lp = 0; |
|
1104 |
RETURN ( anObject ); |
|
1105 |
} |
|
1106 |
u = __longIntVal(anObject); |
|
1107 |
/* |
|
1108 |
* zero means failure for an int larger than 4 bytes |
|
1109 |
* (would be a smallInteger) |
|
1110 |
*/ |
|
1111 |
if (u) { |
|
1112 |
*lp = u; |
|
1113 |
RETURN ( anObject ); |
|
1114 |
} |
|
1115 |
} |
|
1116 |
break; |
|
1117 |
||
1118 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1119 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1120 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1121 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1122 |
||
1123 |
pFirst += delta; |
|
1124 |
nbytes -= delta; |
|
1125 |
} |
|
5755 | 1126 |
#endif |
6654 | 1127 |
if ((unsigned)indx < (nbytes>>3)) { |
1128 |
__int64__ ll; |
|
1129 |
__int64__ *sllp; |
|
1130 |
||
1131 |
sllp = (__int64__ *)(pFirst + (indx<<3)); |
|
1132 |
||
1133 |
if (anObject == __MKSMALLINT(0)) { |
|
1134 |
ll.lo = ll.hi = 0; |
|
1135 |
*sllp = ll; |
|
1136 |
RETURN ( anObject ); |
|
1137 |
} |
|
1138 |
if (__signedLong64IntVal(anObject, &ll)) { |
|
1139 |
*sllp = ll; |
|
1140 |
RETURN ( anObject ); |
|
1141 |
} |
|
1142 |
} |
|
1143 |
break; |
|
1144 |
||
1145 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
5755 | 1146 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1147 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1148 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1149 |
||
1150 |
pFirst += delta; |
|
1151 |
nbytes -= delta; |
|
1152 |
} |
|
5755 | 1153 |
#endif |
6654 | 1154 |
if ((unsigned)indx < (nbytes>>3)) { |
1155 |
__uint64__ ll; |
|
1156 |
__uint64__ *llp; |
|
1157 |
||
1158 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
1159 |
if (anObject == __MKSMALLINT(0)) { |
|
1160 |
ll.lo = ll.hi = 0; |
|
1161 |
*llp = ll; |
|
1162 |
RETURN ( anObject ); |
|
1163 |
} |
|
1164 |
if (__unsignedLong64IntVal(anObject, &ll)) { |
|
1165 |
*llp = ll; |
|
1166 |
RETURN ( anObject ); |
|
1167 |
} |
|
1168 |
} |
|
1169 |
break; |
|
1170 |
} |
|
5755 | 1171 |
} |
1172 |
%}. |
|
1173 |
index isInteger ifFalse:[ |
|
6654 | 1174 |
" |
1175 |
the index should be an integer number |
|
1176 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1177 |
^ self indexNotInteger:index |
5755 | 1178 |
]. |
1179 |
(index between:1 and:self size) ifFalse:[ |
|
6654 | 1180 |
" |
1181 |
the index is less than 1 or greater than the size of the |
|
1182 |
receiver collection |
|
1183 |
" |
|
1184 |
^ self subscriptBoundsError:index |
|
5755 | 1185 |
]. |
1186 |
(self class isFloatsOrDoubles) ifTrue:[ |
|
6654 | 1187 |
anObject isNumber ifTrue:[ |
1188 |
^ self basicAt:index put:(anObject asFloat) |
|
1189 |
] |
|
5755 | 1190 |
]. |
1191 |
anObject isInteger ifFalse:[ |
|
6654 | 1192 |
" |
1193 |
the object to put into the receiver collection |
|
1194 |
should be an integer number |
|
1195 |
" |
|
1196 |
^ self elementNotInteger |
|
5755 | 1197 |
]. |
1198 |
" |
|
1199 |
the object to put into the receiver collection |
|
1200 |
is not an instance of the expected element class, |
|
1201 |
or the value is not within the elements valid range. |
|
1202 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1203 |
^ self elementBoundsError:anObject |
5755 | 1204 |
|
1205 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
|
1206 |
! |
|
1207 |
||
1208 |
byteAt:index |
|
1209 |
"return the byte at index. |
|
1210 |
This is only allowed for non-pointer indexed objects |
|
1211 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1212 |
The receivers indexed instvars are treated as an uninterpreted |
|
1213 |
collection of bytes. |
|
1214 |
Only useful with binary storage." |
|
1215 |
||
1216 |
%{ /* NOCONTEXT */ |
|
1217 |
||
1218 |
REGISTER int indx; |
|
1219 |
int nIndex; |
|
1220 |
REGISTER OBJ slf; |
|
1221 |
REGISTER OBJ cls; |
|
1222 |
||
1223 |
if (__isSmallInteger(index)) { |
|
6654 | 1224 |
slf = self; |
1225 |
if (__isNonNilObject(slf)) { |
|
1226 |
unsigned char *pFirst; |
|
1227 |
int nIndex; |
|
1228 |
||
1229 |
cls = __qClass(slf); |
|
1230 |
||
1231 |
pFirst = __byteArrayVal(slf); |
|
1232 |
pFirst += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1233 |
nIndex = __byteArraySize(slf); |
|
1234 |
indx = __intVal(index) - 1; |
|
1235 |
||
1236 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1237 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1238 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 1239 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1240 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1241 |
||
1242 |
pFirst += delta; |
|
1243 |
nIndex -= delta; |
|
1244 |
} |
|
5755 | 1245 |
#endif |
6654 | 1246 |
/* fall into */ |
1247 |
case __MASKSMALLINT(BYTEARRAY): |
|
1248 |
case __MASKSMALLINT(WORDARRAY): |
|
1249 |
case __MASKSMALLINT(LONGARRAY): |
|
1250 |
case __MASKSMALLINT(SWORDARRAY): |
|
1251 |
case __MASKSMALLINT(SLONGARRAY): |
|
1252 |
case __MASKSMALLINT(FLOATARRAY): |
|
1253 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1254 |
RETURN ( __MKSMALLINT( (INT)(pFirst[indx])) ); |
|
1255 |
} |
|
1256 |
break; |
|
1257 |
||
1258 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1259 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1260 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1261 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1262 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1263 |
||
1264 |
pFirst += delta; |
|
1265 |
nIndex -= delta; |
|
1266 |
} |
|
5755 | 1267 |
#endif |
6654 | 1268 |
if ((unsigned)indx < (unsigned)nIndex) { |
1269 |
RETURN ( __MKSMALLINT( (INT)(pFirst[indx])) ); |
|
1270 |
} |
|
1271 |
break; |
|
1272 |
} |
|
1273 |
} |
|
5755 | 1274 |
} |
1275 |
%}. |
|
1276 |
"/ index not integer or index out of range |
|
1277 |
"/ or non-byte indexable receiver |
|
1278 |
||
1279 |
^ self primitiveFailed |
|
1280 |
||
1281 |
" |
|
1282 |
Point new byteAt:1 |
|
1283 |
(ByteArray with:1 with:2) byteAt:2 |
|
1284 |
(WordArray with:1) byteAt:1 |
|
1285 |
(FloatArray with:1.0) byteAt:2 |
|
1286 |
'hello' byteAt:1 |
|
1287 |
" |
|
1288 |
! |
|
1289 |
||
1290 |
byteAt:index put:byteValue |
|
1291 |
"set the byte at index. |
|
1292 |
This is only allowed for non-pointer indexed objects |
|
1293 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1294 |
The receivers indexed instvars are treated as an uninterpreted |
|
1295 |
collection of bytes. |
|
1296 |
Only useful with binary storage." |
|
1297 |
||
1298 |
%{ /* NOCONTEXT */ |
|
1299 |
||
1300 |
REGISTER int indx; |
|
1301 |
int val, nIndex; |
|
1302 |
REGISTER OBJ slf; |
|
1303 |
REGISTER OBJ cls; |
|
1304 |
||
1305 |
if (__bothSmallInteger(index, byteValue)) { |
|
6654 | 1306 |
val = __intVal(byteValue); |
1307 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
1308 |
slf = self; |
|
1309 |
if (__isNonNilObject(slf)) { |
|
1310 |
cls = __qClass(slf); |
|
1311 |
||
1312 |
indx = __intVal(index) - 1; |
|
1313 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1314 |
case __MASKSMALLINT(BYTEARRAY): |
|
1315 |
case __MASKSMALLINT(WORDARRAY): |
|
1316 |
case __MASKSMALLINT(LONGARRAY): |
|
1317 |
case __MASKSMALLINT(SWORDARRAY): |
|
1318 |
case __MASKSMALLINT(SLONGARRAY): |
|
1319 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1320 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1321 |
case __MASKSMALLINT(FLOATARRAY): |
|
1322 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
1323 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1324 |
nIndex = __byteArraySize(slf); |
|
1325 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1326 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
1327 |
RETURN ( byteValue ); |
|
1328 |
} |
|
1329 |
break; |
|
1330 |
} |
|
1331 |
} |
|
1332 |
} |
|
5755 | 1333 |
} |
1334 |
%}. |
|
1335 |
"/ index not integer or index out of range |
|
1336 |
"/ or non-byte indexable receiver |
|
1337 |
||
1338 |
^ self primitiveFailed |
|
1339 |
||
1340 |
" |
|
1341 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
|
1342 |
'hello' copy byteAt:1 put:105; yourself |
|
1343 |
" |
|
1344 |
! |
|
1345 |
||
1346 |
instVarAt:index |
|
1347 |
"return a non-indexed instance variable; |
|
1348 |
peeking into an object this way is not very object oriented |
|
1349 |
- use with care (needed for copy, inspector etc.)" |
|
1350 |
||
1351 |
%{ /* NOCONTEXT */ |
|
1352 |
||
1353 |
OBJ myClass; |
|
1354 |
int idx, ninstvars; |
|
1355 |
||
1356 |
if (__isSmallInteger(index)) { |
|
6654 | 1357 |
myClass = __Class(self); |
1358 |
idx = __intVal(index) - 1; |
|
1359 |
/* |
|
1360 |
* do not allow returning of non-object fields. |
|
1361 |
* if subclass did not make privisions for that, |
|
1362 |
* we wont do so here ... |
|
1363 |
*/ |
|
1364 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1365 |
if (idx == 0) { |
|
1366 |
RETURN ( nil ) |
|
1367 |
} |
|
1368 |
} |
|
1369 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1370 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1371 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
|
1372 |
} |
|
5755 | 1373 |
} |
7216 | 1374 |
%}. |
1375 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1376 |
! |
1377 |
||
1378 |
instVarAt:index put:value |
|
1379 |
"change a non-indexed instance variable; |
|
1380 |
peeking into an object this way is not very object oriented |
|
1381 |
- use with care (needed for copy, inspector etc.)" |
|
1382 |
||
1383 |
%{ /* NOCONTEXT */ |
|
1384 |
||
1385 |
OBJ myClass; |
|
1386 |
int idx, ninstvars; |
|
1387 |
||
1388 |
if (__isSmallInteger(index)) { |
|
6654 | 1389 |
myClass = __Class(self); |
1390 |
idx = __intVal(index) - 1; |
|
1391 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1392 |
/* |
|
1393 |
* do not allow setting of non-object fields. |
|
1394 |
* if subclass did not make privisions for that, |
|
1395 |
* we wont do so here ... |
|
1396 |
*/ |
|
1397 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1398 |
if (idx == 0) { |
|
1399 |
RETURN ( nil ) |
|
1400 |
} |
|
1401 |
} |
|
1402 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1403 |
__InstPtr(self)->i_instvars[idx] = value; |
|
1404 |
__STORE(self, value); |
|
1405 |
RETURN ( value ); |
|
1406 |
} |
|
5755 | 1407 |
} |
7216 | 1408 |
%}. |
1409 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1410 |
! |
1411 |
||
1412 |
instVarNamed:name |
|
1413 |
"return a non-indexed instance variables value by name; |
|
1414 |
peeking into an object this way is not very object oriented |
|
1415 |
- use with care if at all (provided for inspectors and memory usage monitor). |
|
1416 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1417 |
parsed ad runtime)" |
|
1418 |
||
1419 |
^ self instVarAt:(self class instVarOffsetOf:name) |
|
1420 |
||
1421 |
||
1422 |
" |
|
1423 |
|p| |
|
1424 |
||
1425 |
p := Point x:10 y:20. |
|
1426 |
p instVarNamed:'x' |
|
1427 |
" |
|
1428 |
||
1429 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
|
1430 |
! |
|
1431 |
||
1432 |
instVarNamed:name ifAbsent:exceptionBlock |
|
1433 |
"return a non-indexed instance variables value by name, |
|
1434 |
or the value of exceptionBlock, if there is no such instance variable. |
|
1435 |
peeking into an object this way is not very object oriented |
|
1436 |
- use with care if at all (provided for inspectors and memory usage monitor). |
|
1437 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1438 |
parsed ad runtime)" |
|
1439 |
||
1440 |
|idx| |
|
1441 |
||
1442 |
idx := self class instVarOffsetOf:name. |
|
1443 |
idx isNil ifTrue:[^ exceptionBlock value]. |
|
1444 |
^ self instVarAt:idx |
|
1445 |
||
1446 |
||
1447 |
" |
|
1448 |
|p| |
|
1449 |
||
1450 |
p := Point x:10 y:20. |
|
1451 |
p instVarNamed:'x' |
|
1452 |
" |
|
1453 |
||
1454 |
"Created: 6.7.1996 / 23:02:49 / cg" |
|
1455 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
|
1456 |
! |
|
1457 |
||
1458 |
instVarNamed:name put:value |
|
1459 |
"set a non-indexed instance variable by name; |
|
1460 |
peeking into an object this way is not very object oriented |
|
1461 |
- if at all, use with care (provided for protocol completeness). |
|
1462 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1463 |
parsed ad runtime)" |
|
1464 |
||
1465 |
^ self instVarAt:(self class instVarOffsetOf:name) put:value |
|
1466 |
||
1467 |
" |
|
1468 |
|p| |
|
1469 |
||
1470 |
p := Point x:10 y:20. |
|
1471 |
p instVarNamed:'x' put:30. |
|
1472 |
p |
|
1473 |
" |
|
1474 |
||
1475 |
"Modified: 19.4.1996 / 11:12:49 / cg" |
|
1476 |
! ! |
|
1477 |
||
1478 |
!Object methodsFor:'attributes access'! |
|
1479 |
||
6323 | 1480 |
objectAttributeAt:attributeKey |
5755 | 1481 |
"return the attribute for a given key or nil if not found" |
1482 |
||
1483 |
| attrs | |
|
1484 |
||
1485 |
attrs := self objectAttributes. |
|
1486 |
(attrs notNil and:[attrs size > 0]) ifTrue:[ |
|
6654 | 1487 |
^ attrs at:attributeKey ifAbsent:[] |
5755 | 1488 |
]. |
1489 |
^ nil |
|
1490 |
||
1491 |
"Created: / 22.1.1998 / 21:29:17 / av" |
|
1492 |
"Modified: / 3.2.1998 / 18:55:55 / cg" |
|
1493 |
! |
|
1494 |
||
6323 | 1495 |
objectAttributeAt:attributeKey put:anObject |
5755 | 1496 |
"store the attribute anObject referenced by key into the receiver" |
1497 |
||
1498 |
"/ must do this save from interrupts, since the attributes collection |
|
1499 |
"/ is possibly accessed from multiple threads ... |
|
1500 |
[ |
|
6654 | 1501 |
| attrs | |
1502 |
||
1503 |
attrs := self objectAttributes. |
|
1504 |
(attrs isNil or:[attrs size == 0]) ifTrue:[ |
|
1505 |
attrs := WeakIdentityDictionary new. |
|
1506 |
attrs at:attributeKey put:anObject. |
|
1507 |
self objectAttributes:attrs. |
|
1508 |
] ifFalse:[ |
|
1509 |
attrs at:attributeKey put:anObject. |
|
1510 |
]. |
|
6323 | 1511 |
] valueUninterruptably |
5755 | 1512 |
|
1513 |
"Attaching additional attributes (slots) to an arbitrary object: |
|
1514 |
||
1515 |
|p| |
|
1516 |
||
1517 |
p := Point new. |
|
1518 |
p objectAttributeAt:#color put:#green. |
|
1519 |
||
1520 |
p objectAttributeAt:#color |
|
1521 |
" |
|
1522 |
||
1523 |
"Created: / 22.1.1998 / 21:29:25 / av" |
|
1524 |
"Modified: / 3.2.1998 / 18:57:58 / cg" |
|
1525 |
! |
|
1526 |
||
1527 |
objectAttributes |
|
1528 |
"return a Collection of attributes - nil if there is none. |
|
1529 |
The default implementation here uses a global WeakDictionary to store |
|
1530 |
attributes |
|
1531 |
This may be too slow for high frequency slot access, |
|
1532 |
therefore, some classes may redefine this for better performance. |
|
1533 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
1534 |
||
1535 |
^ ObjectAttributes at:self ifAbsent:[nil] |
|
1536 |
||
1537 |
"Created: / 22.1.1998 / 21:29:30 / av" |
|
1538 |
"Modified: / 18.2.2000 / 11:34:16 / cg" |
|
1539 |
! |
|
1540 |
||
1541 |
objectAttributes:aCollection |
|
1542 |
"set the collection of attributes. |
|
1543 |
The default implementation here uses a global Dictionary to store |
|
1544 |
attributes which may be too slow for high frequency change&update. |
|
1545 |
Therefore, some classes may redefine this for better performance." |
|
1546 |
||
1547 |
"/ must do this save from interrupts, since the attributes collection |
|
1548 |
"/ is possibly accessed from multiple threads. |
|
1549 |
||
1550 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
6654 | 1551 |
"/ the common case - already blocked |
1552 |
||
1553 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
1554 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1555 |
] ifFalse:[ |
|
1556 |
ObjectAttributes at:self put:aCollection |
|
1557 |
]. |
|
1558 |
^ self |
|
5755 | 1559 |
]. |
1560 |
||
1561 |
[ |
|
6654 | 1562 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
1563 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1564 |
] ifFalse:[ |
|
1565 |
ObjectAttributes at:self put:aCollection |
|
1566 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
1567 |
] ensure:[ |
6654 | 1568 |
OperatingSystem unblockInterrupts |
5755 | 1569 |
] |
1570 |
||
1571 |
"Created: / 22.1.1998 / 21:29:35 / av" |
|
1572 |
"Modified: / 3.2.1998 / 18:58:10 / cg" |
|
1573 |
! |
|
1574 |
||
6323 | 1575 |
removeObjectAttribute:attributeKey |
5755 | 1576 |
"make the argument, anObject be no attribute of the receiver" |
1577 |
||
1578 |
"/ must do this save from interrupts, since the attributes collection |
|
1579 |
"/ is possibly accessed from multiple threads. |
|
1580 |
[ |
|
6654 | 1581 |
|attrs n a| |
1582 |
||
1583 |
attrs := self objectAttributes. |
|
1584 |
attrs size == 0 ifTrue:[ |
|
1585 |
self objectAttributes:nil |
|
1586 |
] ifFalse:[ |
|
1587 |
attrs removeKey:attributeKey ifAbsent:nil. |
|
1588 |
attrs size == 0 ifTrue:[ |
|
1589 |
self objectAttributes:nil |
|
1590 |
] |
|
1591 |
] |
|
6323 | 1592 |
] valueUninterruptably |
5755 | 1593 |
|
1594 |
"Created: / 22.1.1998 / 21:29:39 / av" |
|
1595 |
"Modified: / 18.2.2000 / 11:32:19 / cg" |
|
1596 |
! ! |
|
1597 |
||
1598 |
!Object methodsFor:'binary storage'! |
|
1599 |
||
6900 | 1600 |
binaryStoreBytes |
1601 |
^ ByteArray streamContents:[:s | self storeBinaryOn:s]. |
|
1602 |
||
1603 |
" |
|
1604 |
#('hello' 1 1.234) binaryStoreBytes |
|
8409 | 1605 |
'hello' asUnicode16String binaryStoreBytes |
1606 |
||
1607 |
Object fromBinaryStoreBytes: |
|
1608 |
('hello' asUnicode16String binaryStoreBytes) |
|
6900 | 1609 |
" |
1610 |
! |
|
1611 |
||
5755 | 1612 |
hasSpecialBinaryRepresentation |
1613 |
"return true, if the receiver has a special binary representation; |
|
1614 |
default here is false, but can be redefined in class which provide |
|
1615 |
their own storeBinary/readBinary methods. |
|
1616 |
||
1617 |
Normal user classes should not use this, it is meant as a hook for |
|
1618 |
special classes such as True, False, UndefinedObject or SmallInteger. |
|
1619 |
||
1620 |
If your instances should be stored in a special way, see |
|
1621 |
#representBinaryOn: and #readBinaryContentsFromdata:manager:." |
|
1622 |
||
1623 |
^ false |
|
1624 |
! |
|
1625 |
||
1626 |
readBinaryContentsFrom:stream manager:manager |
|
1627 |
"reconstruct the receivers instance variables by reading a binary |
|
1628 |
binary representation from stream. |
|
1629 |
This is a general implementation, walking over instances |
|
1630 |
and loading each recursively using manager. |
|
1631 |
Redefined by some classes to read a more compact representations |
|
1632 |
(see String, SmallInteger etc). |
|
1633 |
||
1634 |
Notice, that the object is already recreated as an empty corps |
|
1635 |
with instance variables all nil and bit-instances (bytes, words etc.) |
|
1636 |
already read and restored. |
|
1637 |
||
1638 |
Also notice: this method is not called for if a private representation |
|
1639 |
has been stored (see representBinaryOn:). |
|
1640 |
In that case, #readBinaryContentsFromData:manager: is called, which |
|
1641 |
has to be reimplemented in the objects class." |
|
1642 |
||
1643 |
|size "{ Class: SmallInteger }" |
|
1644 |
instvarArray| |
|
1645 |
||
1646 |
stream next == 1 ifTrue:[ |
|
6654 | 1647 |
"/ |
1648 |
"/ special representation ... |
|
1649 |
"/ |
|
1650 |
instvarArray := Array new:(size := stream nextNumber:3). |
|
1651 |
1 to:size do:[:i | |
|
1652 |
instvarArray basicAt:i put:(manager nextObject) |
|
1653 |
]. |
|
1654 |
self readBinaryContentsFromData:instvarArray manager:manager. |
|
1655 |
^ self |
|
5755 | 1656 |
]. |
1657 |
||
1658 |
"/ |
|
1659 |
"/ standard representation |
|
1660 |
"/ |
|
1661 |
size := self basicSize. |
|
1662 |
size ~~ 0 ifTrue:[ |
|
6654 | 1663 |
self class isPointers ifTrue:[ |
1664 |
1 to:size do:[:i | |
|
1665 |
self basicAt:i put:(manager nextObject) |
|
1666 |
] |
|
1667 |
] |
|
5755 | 1668 |
]. |
1669 |
size := self class instSize. |
|
1670 |
1 to:size do:[:i | |
|
6654 | 1671 |
self instVarAt:i put:(manager nextObject) |
5755 | 1672 |
]. |
1673 |
! |
|
1674 |
||
1675 |
readBinaryContentsFromData:instvarArray manager:manager |
|
1676 |
"reconstruct the receivers instance variables by filling instance |
|
1677 |
variables with values from instvarArray. This array contains the instvars |
|
1678 |
as specified in #representBinaryOn: when the object was stored. |
|
1679 |
It is the receivers responsibility to set its instance variables in the |
|
1680 |
same order from that array." |
|
1681 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
1682 |
^ self subclassResponsibility:'method must be reimplemented in subclass for binary storage' |
5755 | 1683 |
|
1684 |
"typical implementation (see also comment in #representBinaryOn:) |
|
1685 |
(for an object with foo, bar and baz as instance variables, |
|
1686 |
which did not store baz and wants baz to be reinitialized to |
|
1687 |
some constant string) |
|
1688 |
||
6654 | 1689 |
foo := instvarArray at:1. |
1690 |
bar := instvarArray at:2. |
|
1691 |
baz := 'aConstant'. |
|
5755 | 1692 |
" |
1693 |
! |
|
1694 |
||
1695 |
representBinaryOn:manager |
|
1696 |
"this method is called by the storage manager to ask objects |
|
1697 |
if they wish to provide their own binary representation. |
|
1698 |
||
1699 |
If they want to do so, they should return an array containing all |
|
1700 |
instance variables (named & indexed pointer) to be stored. |
|
1701 |
If not redefined, this method returns nil which means that all |
|
1702 |
instance variables are to be stored. |
|
1703 |
||
1704 |
It should be redefined in objects which do not want all instance variables |
|
1705 |
to be stored (for example: objects which keep references to a view etc.). |
|
1706 |
||
1707 |
If this is redefined returning non-nil, the corresponding class needs |
|
1708 |
a redefined instance method named #readBinaryContentsFromData:manager: |
|
1709 |
which has to fill the receivers named (and optionally indexed pointer) |
|
1710 |
instance variables with corresponding values from a data array." |
|
1711 |
||
1712 |
^ nil |
|
1713 |
||
1714 |
"typical implementation: |
|
1715 |
(see also comment in #readBinaryContentsFromData:manager:) |
|
1716 |
for an object with foo, bar and baz as instance variables, |
|
1717 |
which does not want to store baz: |
|
1718 |
||
1719 |
representBinaryOn:manager |
|
6654 | 1720 |
|data| |
1721 |
||
1722 |
data := Array new:2. |
|
1723 |
data at:1 put:foo. |
|
1724 |
data at:2 put:bar. |
|
1725 |
^ data |
|
5755 | 1726 |
" |
1727 |
! |
|
1728 |
||
1729 |
storeBinaryDefinitionBodyOn:stream manager:manager |
|
1730 |
"append a binary representation of the receivers body onto stream. |
|
1731 |
This is a general implementation walking over instances storing |
|
1732 |
each recursively as an ID using manager. |
|
1733 |
Can be redefined in subclasses." |
|
1734 |
||
1735 |
|basicSize "{ Class: SmallInteger }" |
|
1736 |
instSize "{ Class: SmallInteger }" |
|
1737 |
specialSize "{ Class: SmallInteger }" |
|
1738 |
myClass specialRep pointers| |
|
1739 |
||
1740 |
myClass := self class. |
|
1741 |
instSize := myClass instSize. |
|
1742 |
||
1743 |
(pointers := myClass isPointers) ifTrue:[ |
|
6654 | 1744 |
"/ |
1745 |
"/ inst size not needed - if you uncomment the line below, |
|
1746 |
"/ also uncomment the corresponding line in |
|
1747 |
"/ Object>>binaryDefinitionFrom:manager: |
|
1748 |
"/ |
|
1749 |
"/ stream nextPut:instSize. "mhmh this limits us to 255 named instvars" |
|
1750 |
||
1751 |
myClass isVariable ifTrue:[ |
|
1752 |
stream nextNumber:3 put:(basicSize := self basicSize) |
|
1753 |
] ifFalse:[ |
|
1754 |
basicSize := 0 |
|
1755 |
]. |
|
5755 | 1756 |
] ifFalse: [ |
6654 | 1757 |
stream nextNumber:4 put:(basicSize := self basicSize). |
1758 |
myClass isBytes ifTrue:[ |
|
1759 |
1 to:basicSize do:[:i | |
|
1760 |
stream nextPut:(self basicAt:i) |
|
1761 |
] |
|
1762 |
] ifFalse:[ |
|
1763 |
myClass isWords ifTrue:[ |
|
1764 |
1 to:basicSize do:[:i | |
|
1765 |
stream nextNumber:2 put:(self basicAt: i) |
|
1766 |
] |
|
1767 |
] ifFalse:[ |
|
1768 |
myClass isLongs ifTrue:[ |
|
1769 |
1 to:basicSize do:[:i | |
|
1770 |
stream nextNumber:4 put:(self basicAt: i) |
|
1771 |
] |
|
1772 |
] ifFalse:[ |
|
1773 |
myClass isFloats ifTrue:[ |
|
1774 |
"could do it in one big write on machines which use IEEE floats ..." |
|
1775 |
1 to:basicSize do:[:i | |
|
7359 | 1776 |
ShortFloat storeBinaryIEEESingle:(self basicAt:i) on:stream |
6654 | 1777 |
] |
1778 |
] ifFalse:[ |
|
1779 |
myClass isDoubles ifTrue:[ |
|
1780 |
"could do it in one big write on machines which use IEEE doubles ..." |
|
1781 |
1 to:basicSize do:[:i | |
|
1782 |
Float storeBinaryIEEEDouble:(self basicAt:i) on:stream |
|
1783 |
] |
|
1784 |
] ifFalse:[ |
|
1785 |
"/ should never be reached ... |
|
1786 |
1 to:basicSize do:[:i | |
|
1787 |
manager putIdOf:(self basicAt:i) on:stream |
|
1788 |
] |
|
1789 |
] |
|
1790 |
] |
|
1791 |
] |
|
1792 |
] |
|
1793 |
]. |
|
5755 | 1794 |
]. |
1795 |
||
1796 |
(pointers or:[instSize ~~ 0]) ifTrue:[ |
|
6654 | 1797 |
specialRep := self representBinaryOn:manager. |
1798 |
specialRep notNil ifTrue:[ |
|
1799 |
specialSize := specialRep basicSize. |
|
1800 |
stream nextPut:1. "/ means: private representation follows |
|
1801 |
stream nextNumber:3 put:specialSize. |
|
1802 |
||
1803 |
1 to:specialSize do:[:i | |
|
1804 |
manager putIdOf:(specialRep at:i) on:stream |
|
1805 |
]. |
|
1806 |
] ifFalse:[ |
|
1807 |
stream nextPut:0. "/ means: normal representation follows |
|
1808 |
"/ index pointers followed by named instanceVars |
|
1809 |
pointers ifTrue:[ |
|
1810 |
basicSize ~~ 0 ifTrue:[ |
|
1811 |
1 to:basicSize do:[:i | |
|
1812 |
manager putIdOf:(self basicAt:i) on:stream |
|
1813 |
]. |
|
1814 |
]. |
|
1815 |
]. |
|
1816 |
instSize ~~ 0 ifTrue:[ |
|
1817 |
1 to:instSize do:[:i | |
|
1818 |
manager putIdOf:(self instVarAt:i) on:stream |
|
1819 |
] |
|
1820 |
]. |
|
1821 |
] |
|
5755 | 1822 |
] |
1823 |
||
1824 |
"Modified: / 2.11.1997 / 14:43:29 / cg" |
|
1825 |
! |
|
1826 |
||
1827 |
storeBinaryDefinitionOn:stream manager:manager |
|
1828 |
"append a binary representation of the receiver onto stream. |
|
1829 |
This is an internal interface for binary storage mechanism. |
|
1830 |
This method first stores the class, then the body, which is done |
|
1831 |
in a separate method to allow redefinition of the bodies format. |
|
1832 |
Can be redefined in subclasses to write more compact representations |
|
1833 |
(see String, SmallInteger etc)." |
|
1834 |
||
1835 |
manager putIdOfClass:(self class) on:stream. |
|
1836 |
self storeBinaryDefinitionBodyOn:stream manager:manager |
|
1837 |
||
1838 |
"Modified: 23.4.1996 / 09:31:12 / cg" |
|
1839 |
! |
|
1840 |
||
1841 |
storeBinaryOn:aStreamOrFilename |
|
1842 |
"Writes a description of the receiver onto aStreamOrFilename, in a way that allows |
|
1843 |
the object's structure to be reconstructed from the stream's contents" |
|
1844 |
||
1845 |
BinaryOutputManager store:self on:aStreamOrFilename |
|
1846 |
||
1847 |
" |
|
1848 |
|a s1 s2| |
|
1849 |
||
1850 |
s1 := 'hello'. |
|
1851 |
s2 := 'world'. |
|
1852 |
a := Array new:5. |
|
1853 |
a at:1 put:s1. |
|
1854 |
a at:2 put:s2. |
|
1855 |
a at:3 put:s1. |
|
1856 |
a at:4 put:s2. |
|
1857 |
a storeBinaryOn:'test.boss' |
|
1858 |
" |
|
1859 |
||
1860 |
" |
|
1861 |
(BinaryObjectStorage onOld:'test.boss' asFilename readStream) |
|
6654 | 1862 |
next |
1863 |
inspect |
|
5755 | 1864 |
" |
1865 |
||
1866 |
"Modified: / 1.11.1997 / 21:16:24 / cg" |
|
1867 |
! |
|
1868 |
||
1869 |
storeBinaryOn:stream manager:manager |
|
1870 |
"append a binary representation of the receiver onto stream." |
|
1871 |
||
1872 |
manager putIdOf:self on:stream |
|
1873 |
! ! |
|
1874 |
||
1875 |
!Object methodsFor:'change & update'! |
|
1876 |
||
1877 |
broadcast:aSelectorSymbol |
|
1878 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1879 |
||
1880 |
self dependentsDo:[:dependent | |
|
6654 | 1881 |
dependent perform:aSelectorSymbol |
5755 | 1882 |
] |
1883 |
! |
|
1884 |
||
1885 |
broadcast:aSelectorSymbol with:anArgument |
|
1886 |
"send a message with selector aSelectorSymbol with an additional |
|
1887 |
argument anArgument to all my dependents." |
|
1888 |
||
1889 |
self dependentsDo:[:dependent | |
|
6654 | 1890 |
dependent perform:aSelectorSymbol with:anArgument |
5755 | 1891 |
] |
1892 |
! |
|
1893 |
||
1894 |
changeRequest |
|
1895 |
"the receiver wants to change - check if all dependents |
|
1896 |
grant the request, and return true if so" |
|
1897 |
||
1898 |
self dependentsDo:[:dependent | |
|
6654 | 1899 |
dependent updateRequest ifFalse:[^ false]. |
5755 | 1900 |
]. |
1901 |
^ true |
|
1902 |
! |
|
1903 |
||
1904 |
changeRequest:aParameter |
|
1905 |
"the receiver wants to change - check if all dependents |
|
1906 |
grant the request, and return true if so" |
|
1907 |
||
1908 |
self dependentsDo:[:dependent | |
|
6654 | 1909 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
5755 | 1910 |
]. |
1911 |
^ true |
|
1912 |
! |
|
1913 |
||
1914 |
changeRequest:aParameter from:anObject |
|
1915 |
"the receiver wants to change - check if all dependents |
|
1916 |
except anObject grant the request, and return true if so. |
|
1917 |
The argument anObject is typically going to be the one who is |
|
1918 |
about to send the change request." |
|
1919 |
||
1920 |
self dependentsDo:[:dependent | |
|
6654 | 1921 |
dependent == anObject ifFalse:[ |
1922 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
1923 |
] |
|
5755 | 1924 |
]. |
1925 |
^ true |
|
1926 |
! |
|
1927 |
||
1928 |
changeRequestFrom:anObject |
|
1929 |
"the receiver wants to change - check if all dependents |
|
1930 |
except anObject grant the request, and return true if so. |
|
1931 |
The argument anObject is typically going to be the one who is |
|
1932 |
about to send the change request." |
|
1933 |
||
1934 |
self dependentsDo:[:dependent | |
|
6654 | 1935 |
dependent == anObject ifFalse:[ |
1936 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1937 |
] |
|
5755 | 1938 |
]. |
1939 |
^ true |
|
1940 |
! |
|
1941 |
||
1942 |
changed |
|
1943 |
"notify all dependents that the receiver has changed. |
|
1944 |
Each dependent gets a '#update:'-message with the original |
|
1945 |
receiver as argument." |
|
1946 |
||
1947 |
self changed:nil |
|
1948 |
! |
|
1949 |
||
1950 |
changed:aParameter |
|
1951 |
"notify all dependents that the receiver has changed somehow. |
|
1952 |
Each dependent gets a '#update:'-message with aParameter |
|
1953 |
as argument." |
|
1954 |
||
1955 |
self changed:aParameter with:nil |
|
1956 |
! |
|
1957 |
||
1958 |
changed:aParameter with:anArgument |
|
1959 |
"notify all dependents that the receiver has changed somehow. |
|
1960 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
|
1961 |
and anArgument as arguments." |
|
1962 |
||
1963 |
self dependentsDo:[:dependent | |
|
6654 | 1964 |
dependent update:aParameter with:anArgument from:self |
5755 | 1965 |
] |
1966 |
! |
|
1967 |
||
1968 |
update:aParameter |
|
1969 |
"the message is sent to a dependent, when one of the objects |
|
1970 |
on whom the receiver depends, has changed. The argument aParameter |
|
1971 |
is either the changed object or the argument to the #changed: message. |
|
1972 |
||
1973 |
Default behavior here is to do nothing" |
|
1974 |
||
1975 |
^ self |
|
1976 |
! |
|
1977 |
||
1978 |
update:aParameter with:anArgument |
|
1979 |
"dependent is notified of some change - |
|
1980 |
Default is to try update:" |
|
1981 |
||
1982 |
^ self update:aParameter |
|
1983 |
! |
|
1984 |
||
1985 |
update:aParameter with:anArgument from:sender |
|
1986 |
"dependent is notified of some change - |
|
1987 |
Default is to try update:with:" |
|
1988 |
||
1989 |
^ self update:aParameter with:anArgument |
|
1990 |
! |
|
1991 |
||
1992 |
updateRequest |
|
1993 |
"return true, if an update request is granted. |
|
1994 |
Default here is to grant updates - may be used |
|
1995 |
to lock updates if someone is making other changes |
|
1996 |
from within an update. Or if someone has locked its |
|
1997 |
state and does not want others to change things. |
|
1998 |
However, these dependents must all honor the |
|
1999 |
changeRequest - ifTrue - change protocol. I.e. they |
|
2000 |
must first ask all others via changeRequest, and only do the change |
|
2001 |
it returns true. The others must decide in updateRequest and |
|
2002 |
return true if they think a change is ok." |
|
2003 |
||
2004 |
^ true |
|
2005 |
! |
|
2006 |
||
2007 |
updateRequest:aSymbol |
|
2008 |
"return true, if an update request is granted. |
|
2009 |
Default here a simple updateRequest" |
|
2010 |
||
2011 |
^ self updateRequest |
|
7177 | 2012 |
! |
2013 |
||
2014 |
withoutUpdating:someone do:aBlock |
|
2015 |
"evaluate a block but remove someone from my dependents temporarily" |
|
2016 |
||
2017 |
(self dependents includesIdentical:someone) |
|
2018 |
ifFalse:[ |
|
2019 |
^ aBlock value. |
|
2020 |
]. |
|
2021 |
self removeDependent:someone. |
|
2022 |
^ aBlock ensure:[ self addDependent:someone ] |
|
5755 | 2023 |
! ! |
2024 |
||
2025 |
!Object methodsFor:'cleanup'! |
|
2026 |
||
2027 |
lowSpaceCleanup |
|
2028 |
"ignored here - redefined in some classes to |
|
2029 |
cleanup in low-memory situations" |
|
2030 |
||
2031 |
^ self |
|
2032 |
! ! |
|
2033 |
||
2034 |
!Object methodsFor:'comparing'! |
|
2035 |
||
2036 |
= anObject |
|
2037 |
"return true, if the receiver and the arg have the same structure. |
|
2038 |
Notice: |
|
6654 | 2039 |
This method is partially open coded (inlined) by the compiler(s) |
2040 |
identical objects are always considered equal. |
|
2041 |
redefining it may not work as expected." |
|
5755 | 2042 |
|
2043 |
^ self == anObject |
|
2044 |
! |
|
2045 |
||
2046 |
== anObject |
|
2047 |
"return true, if the receiver and the arg are the same object. |
|
2048 |
Never redefine this in any class. |
|
2049 |
Notice: |
|
6654 | 2050 |
This method is open coded (inlined) by the compiler(s) |
2051 |
- redefining it may not work as expected." |
|
5755 | 2052 |
|
2053 |
%{ /* NOCONTEXT */ |
|
2054 |
||
2055 |
RETURN ( (self == anObject) ? true : false ); |
|
2056 |
%} |
|
2057 |
! |
|
2058 |
||
5814 | 2059 |
deepSameContentsAs:anObject |
2060 |
"return true, if the receiver and the arg have the same contents |
|
2061 |
in both the named instance vars and any indexed instVars. |
|
2062 |
This method descends into referenced objects, where #sameContentsAs: does not descend" |
|
2063 |
||
5821 | 2064 |
|myClass val |
5814 | 2065 |
sz "{ Class: SmallInteger }" | |
2066 |
||
2067 |
myClass := self class. |
|
2068 |
myClass isVariable ifTrue:[ |
|
6654 | 2069 |
sz := self basicSize. |
2070 |
||
2071 |
"compare the indexed variables" |
|
2072 |
1 to:sz do:[:i | |
|
2073 |
val := self basicAt:i. |
|
2074 |
val isLiteral ifTrue:[ |
|
2075 |
val = (anObject basicAt:i) ifFalse:[^ false]. |
|
2076 |
] ifFalse:[ |
|
2077 |
(val deepSameContentsAs:(anObject basicAt:i)) ifFalse:[^ false]. |
|
2078 |
] |
|
2079 |
] |
|
5814 | 2080 |
]. |
2081 |
||
2082 |
"compare the instance variables" |
|
2083 |
sz := myClass instSize. |
|
2084 |
1 to:sz do:[:i | |
|
6654 | 2085 |
val := self instVarAt:i. |
2086 |
val isLiteral ifTrue:[ |
|
2087 |
val = (anObject instVarAt:i) ifFalse:[^ false]. |
|
2088 |
] ifFalse:[ |
|
2089 |
(val deepSameContentsAs:(anObject instVarAt:i)) ifFalse:[^ false]. |
|
2090 |
] |
|
5814 | 2091 |
]. |
2092 |
||
2093 |
^ true |
|
2094 |
||
2095 |
" |
|
2096 |
#(1 2 3 4) deepSameContentsAs:#[1 2 3 4] asArray |
|
2097 |
(1@2) deepSameContentsAs:(1->2) |
|
2098 |
" |
|
2099 |
! |
|
2100 |
||
5755 | 2101 |
hash |
2102 |
"return an Integer useful as a hash key for the receiver. |
|
2103 |
This hash should return same values for objects with same |
|
2104 |
contents (i.e. use this to hash on structure)" |
|
2105 |
||
2106 |
^ self identityHash |
|
2107 |
! |
|
2108 |
||
2109 |
identityHash |
|
2110 |
"return an Integer useful as a hash key for the receiver. |
|
2111 |
This hash should return same values for the same object (i.e. use |
|
2112 |
this to hash on identity of objects). |
|
2113 |
||
2114 |
We cannot use the Objects address (as other smalltalks do) since |
|
2115 |
no object-table exists and the hashval must not change when objects |
|
2116 |
are moved by the collector. Therefore we assign each object a unique |
|
2117 |
Id in the object header itself as its hashed upon. |
|
2118 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
2119 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
2120 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
2121 |
hashed-upon objects could add an instvar containing the hash value." |
|
2122 |
||
2123 |
%{ /* NOCONTEXT */ |
|
2124 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2125 |
REGISTER unsigned INT hash; |
5755 | 2126 |
static unsigned nextHash = 0; |
2127 |
||
2128 |
if (__isNonNilObject(self)) { |
|
6654 | 2129 |
hash = __GET_HASH(self); |
2130 |
if (hash == 0) { |
|
2131 |
/* has no hash yet */ |
|
2132 |
||
2133 |
if (++nextHash > __MAX_HASH__) { |
|
2134 |
nextHash = 1; |
|
2135 |
} |
|
2136 |
hash = nextHash; |
|
2137 |
__SET_HASH(self, hash); |
|
2138 |
} |
|
2139 |
||
2140 |
/* |
|
2141 |
* now, we got 11 bits for hashing; |
|
2142 |
* make it as large as possible; since most hashers use the returned |
|
2143 |
* key and take it modulo some prime number, this will allow for |
|
2144 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2145 |
*/ |
|
2146 |
hash = __MAKE_HASH__(hash); |
|
2147 |
RETURN ( __MKSMALLINT(hash) ); |
|
5755 | 2148 |
} |
2149 |
%}. |
|
2150 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
2151 |
! |
|
2152 |
||
2153 |
identityHashForBinaryStore |
|
2154 |
"hash which is usable if the object does not change its class |
|
2155 |
and does not #become something else, while the hash is used. |
|
2156 |
This is only used by the binary storage mechanism, during the |
|
2157 |
object writing phase." |
|
2158 |
||
2159 |
%{ /* NOCONTEXT */ |
|
2160 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2161 |
REGISTER unsigned INT hash, hash1, hash2, sz; |
5755 | 2162 |
OBJ o; |
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2163 |
static unsigned INT nextHash = 0; |
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2164 |
static unsigned INT nextClassHash = 0; |
5755 | 2165 |
|
2166 |
if (__isNonNilObject(self)) { |
|
6654 | 2167 |
/* |
2168 |
* my own identityHash |
|
2169 |
*/ |
|
2170 |
hash1 = __GET_HASH(self); |
|
2171 |
if (hash1 == 0) { |
|
2172 |
/* has no hash yet */ |
|
2173 |
||
2174 |
if (++nextHash > __MAX_HASH__) { |
|
2175 |
nextHash = 1; |
|
2176 |
} |
|
2177 |
hash1 = nextHash; |
|
2178 |
__SET_HASH(self, hash1); |
|
2179 |
} |
|
2180 |
/* |
|
2181 |
* my classes identityHash |
|
2182 |
*/ |
|
2183 |
o = __qClass(self); |
|
2184 |
hash2 = __GET_HASH(o); |
|
2185 |
if (hash2 == 0) { |
|
2186 |
/* has no hash yet */ |
|
2187 |
||
2188 |
if (++nextClassHash > __MAX_HASH__) { |
|
2189 |
nextClassHash = 1; |
|
2190 |
} |
|
2191 |
hash2 = nextClassHash; |
|
2192 |
__SET_HASH(o, hash2); |
|
2193 |
} |
|
2194 |
||
2195 |
/* |
|
2196 |
* some bits of my size |
|
2197 |
*/ |
|
2198 |
sz = __qSize(self); |
|
2199 |
||
2200 |
/* |
|
2201 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
2202 |
* make it as large as possible; since most hashers use the returned |
|
2203 |
* key and take it modulo some prime number, this will allow for |
|
2204 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2205 |
*/ |
|
2206 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
2207 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
2208 |
||
2209 |
while ((hash & 0x20000000) == 0) { |
|
2210 |
hash <<= 1; |
|
2211 |
} |
|
2212 |
||
2213 |
RETURN ( __MKSMALLINT(hash) ); |
|
5755 | 2214 |
} |
2215 |
%}. |
|
2216 |
"never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
|
2217 |
^ self identityHash |
|
2218 |
! |
|
2219 |
||
2220 |
sameContentsAs:anObject |
|
2221 |
"return true, if the receiver and the arg have the same contents |
|
7121 | 2222 |
in both the named instance vars and any indexed instVars. |
2223 |
The code here only checks if values present in the receiver are also |
|
2224 |
present in the arg, not vice versa. |
|
2225 |
I.e. the argument may be bigger and/or have more instance variables." |
|
5755 | 2226 |
|
5821 | 2227 |
|myClass |
5755 | 2228 |
sz "{ Class: SmallInteger }" | |
2229 |
||
2230 |
myClass := self class. |
|
2231 |
myClass isVariable ifTrue:[ |
|
6654 | 2232 |
sz := self basicSize. |
7121 | 2233 |
anObject basicSize >= sz ifFalse:[^ false]. |
6654 | 2234 |
|
2235 |
"compare the indexed variables" |
|
2236 |
1 to:sz do:[:i | |
|
2237 |
(self basicAt:i) == (anObject basicAt:i) ifFalse:[^ false]. |
|
2238 |
] |
|
5755 | 2239 |
]. |
2240 |
||
2241 |
"compare the instance variables" |
|
2242 |
sz := myClass instSize. |
|
7121 | 2243 |
anObject instSize >= sz ifFalse:[^ false]. |
2244 |
||
5755 | 2245 |
1 to:sz do:[:i | |
6654 | 2246 |
(self instVarAt:i) == (anObject instVarAt:i) ifFalse:[^ false]. |
5755 | 2247 |
]. |
2248 |
||
2249 |
^ true |
|
2250 |
||
2251 |
" |
|
5814 | 2252 |
#(1 2 3 4) sameContentsAs:#[1 2 3 4] asArray |
2253 |
(1@2) sameContentsAs:(1->2) |
|
5755 | 2254 |
" |
2255 |
||
2256 |
"Created: / 21.4.1998 / 15:56:40 / cg" |
|
2257 |
"Modified: / 21.4.1998 / 15:58:15 / cg" |
|
2258 |
! |
|
2259 |
||
2260 |
~= anObject |
|
2261 |
"return true, if the receiver and the arg do not have the same structure. |
|
2262 |
Notice: |
|
6654 | 2263 |
This method is partially open coded (inlined) by the compiler(s) |
2264 |
identical objects are never considered unequal. |
|
2265 |
redefining it may not work as expected." |
|
5755 | 2266 |
|
2267 |
^ (self = anObject) not |
|
2268 |
! |
|
2269 |
||
2270 |
~~ anObject |
|
2271 |
"return true, if the receiver and the arg are not the same object. |
|
2272 |
Never redefine this in any class. |
|
2273 |
Notice: |
|
6654 | 2274 |
This method is open coded (inlined) by the compiler(s) |
2275 |
- redefining it may not work as expected." |
|
5755 | 2276 |
|
2277 |
%{ /* NOCONTEXT */ |
|
2278 |
RETURN ( (self == anObject) ? false : true ); |
|
2279 |
%} |
|
2280 |
! ! |
|
2281 |
||
2282 |
!Object methodsFor:'converting'! |
|
2283 |
||
6696
36eaa6c17e2c
use excla for conses (looks better);
Claus Gittinger <cg@exept.de>
parents:
6656
diff
changeset
|
2284 |
!! anObject |
6652
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2285 |
"return a cons with the receiver as car and the argument as cdr" |
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2286 |
|
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2287 |
^ Cons car:self cdr:anObject |
6697 | 2288 |
|
2289 |
" |
|
6698 | 2290 |
(1 !! 2) |
2291 |
(#car !! #cdr) |
|
2292 |
(1 !! (2 !! (3 !! nil))) |
|
2293 |
(1 !! 2) !! (2 !! 3) |
|
6697 | 2294 |
" |
6652
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2295 |
! |
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
2296 |
|
5755 | 2297 |
-> anObject |
2298 |
"return an association with the receiver as key and |
|
2299 |
the argument as value" |
|
2300 |
||
2301 |
^ Association key:self value:anObject |
|
2302 |
! |
|
2303 |
||
2304 |
asCollection |
|
2305 |
"return myself as a Collection. |
|
2306 |
Redefined in collection to return themself." |
|
2307 |
||
2308 |
^ Array with:self |
|
2309 |
! |
|
2310 |
||
2311 |
asSequenceableCollection |
|
2312 |
"return myself as a SequenceableCollection. |
|
2313 |
Redefined in SequenceableCollection" |
|
2314 |
||
2315 |
^ Array with:self |
|
2316 |
! |
|
2317 |
||
2318 |
asValue |
|
2319 |
"return a valueHolder for for the receiver" |
|
2320 |
||
2321 |
^ ValueHolder with:self |
|
6146 | 2322 |
! |
2323 |
||
2324 |
collect |
|
2325 |
"return mySelf" |
|
2326 |
||
2327 |
^ self |
|
2328 |
! |
|
2329 |
||
2330 |
deepCollect |
|
2331 |
"return mySelf" |
|
2332 |
||
2333 |
^ self |
|
2334 |
! |
|
2335 |
||
2336 |
deepSelect |
|
2337 |
"return mySelf" |
|
2338 |
||
2339 |
^ self |
|
2340 |
! |
|
2341 |
||
2342 |
select |
|
2343 |
"return mySelf" |
|
2344 |
||
2345 |
^ self |
|
5755 | 2346 |
! ! |
2347 |
||
2348 |
!Object methodsFor:'copying'! |
|
2349 |
||
2350 |
cloneFrom:anObject |
|
2351 |
"Helper for copy: |
|
2352 |
copy all instance variables from anObject into the receiver, |
|
2353 |
which should be of the same class as the argument." |
|
2354 |
||
2355 |
self cloneFrom:anObject performing:#yourself |
|
2356 |
||
2357 |
" |
|
2358 |
|x| |
|
2359 |
||
2360 |
x := Array new:3. |
|
2361 |
x cloneFrom:#(1 2 3). |
|
2362 |
" |
|
2363 |
! |
|
2364 |
||
2365 |
cloneFrom:anObject performing:aSymbol |
|
2366 |
"Helper for copy: |
|
8383 | 2367 |
for each instance variable from anObject, send it aSymbol |
5755 | 2368 |
and store the result into the receiver, |
2369 |
which should be of the same class as the argument." |
|
2370 |
||
2371 |
|myClass sz "{ Class: SmallInteger }" t | |
|
2372 |
||
2373 |
myClass := self class. |
|
2374 |
myClass isVariable ifTrue:[ |
|
6654 | 2375 |
sz := self basicSize. |
2376 |
||
8383 | 2377 |
"process the indexed instance variables" |
6654 | 2378 |
1 to:sz do:[:i | |
2379 |
t := anObject basicAt:i. |
|
2380 |
aSymbol ~~ #yourself ifTrue:[ |
|
2381 |
t := t perform:aSymbol. |
|
2382 |
]. |
|
2383 |
self basicAt:i put:t. |
|
2384 |
] |
|
5755 | 2385 |
]. |
2386 |
||
8383 | 2387 |
"process the named instance variables" |
5755 | 2388 |
sz := myClass instSize. |
2389 |
1 to:sz do:[:i | |
|
6654 | 2390 |
t := anObject instVarAt:i. |
2391 |
aSymbol ~~ #yourself ifTrue:[ |
|
2392 |
t := t perform:aSymbol |
|
2393 |
]. |
|
2394 |
self instVarAt:i put:t |
|
5755 | 2395 |
]. |
2396 |
||
2397 |
^ self |
|
2398 |
! |
|
2399 |
||
2400 |
cloneInstanceVariablesFrom:aPrototype |
|
2401 |
"Shallow copy variables from a prototype into myself. |
|
2402 |
This copies instVars by name - i.e. same-named variables are |
|
2403 |
copied, others are not. |
|
2404 |
The variable slots are copied as available |
|
2405 |
(i.e. the min of both indexed sizes is used)." |
|
2406 |
||
2407 |
|myInfo otherInfo| |
|
2408 |
||
2409 |
myInfo := self class instanceVariableOffsets. |
|
2410 |
otherInfo := aPrototype class instanceVariableOffsets. |
|
2411 |
myInfo keysAndValuesDo:[:name :index | |varIndexAssoc| |
|
6654 | 2412 |
varIndexAssoc := otherInfo at:name ifAbsent:[]. |
2413 |
varIndexAssoc notNil ifTrue:[ |
|
2414 |
self instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
2415 |
] |
|
5755 | 2416 |
]. |
2417 |
self isVariable ifTrue:[ |
|
6654 | 2418 |
1 to:(self basicSize min:aPrototype basicSize) do:[:index | |
2419 |
self basicAt:index put:(aPrototype basicAt:index) |
|
2420 |
]. |
|
5755 | 2421 |
]. |
2422 |
||
2423 |
" |
|
2424 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2425 |
Point subclass:#Point3D |
2426 |
instanceVariableNames:'z' |
|
2427 |
classVariableNames:'' |
|
2428 |
poolDictionaries:'' |
|
2429 |
category:'testing'. |
|
2430 |
(Point3D new cloneInstanceVariablesFrom:1@2) inspect. |
|
5755 | 2431 |
] |
2432 |
" |
|
2433 |
||
2434 |
" |
|
2435 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2436 |
Point variableSubclass:#Point3D |
2437 |
instanceVariableNames:'z' |
|
2438 |
classVariableNames:'' |
|
2439 |
poolDictionaries:'' |
|
2440 |
category:'testing'. |
|
2441 |
((Point3D new:2) cloneInstanceVariablesFrom:#(1 2 3)) inspect. |
|
5755 | 2442 |
] |
2443 |
" |
|
2444 |
||
2445 |
" |
|
2446 |
|someObject| |
|
2447 |
||
2448 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2449 |
Object subclass:#TestClass1 |
2450 |
instanceVariableNames:'foo bar' |
|
2451 |
classVariableNames:'' |
|
2452 |
poolDictionaries:'' |
|
2453 |
category:'testing'. |
|
2454 |
someObject := TestClass1 new. |
|
2455 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
2456 |
Object subclass:#TestClass2 |
|
2457 |
instanceVariableNames:'bar foo' |
|
2458 |
classVariableNames:'' |
|
2459 |
poolDictionaries:'' |
|
2460 |
category:'testing'. |
|
2461 |
(TestClass2 new cloneInstanceVariablesFrom:someObject) inspect. |
|
5755 | 2462 |
] |
2463 |
" |
|
2464 |
||
2465 |
" |
|
2466 |
|top b b1| |
|
2467 |
||
2468 |
top := StandardSystemView new. |
|
2469 |
top extent:100@100. |
|
2470 |
||
2471 |
b := Button in:top. |
|
2472 |
b label:'hello'. |
|
2473 |
||
2474 |
b1 := ArrowButton new cloneInstanceVariablesFrom:b. |
|
2475 |
||
2476 |
top open. |
|
2477 |
b1 inspect |
|
2478 |
" |
|
2479 |
! |
|
2480 |
||
2481 |
copy |
|
2482 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
2483 |
Notice, that copy does not copy dependents." |
|
2484 |
||
2485 |
^ self shallowCopy postCopy |
|
2486 |
! |
|
2487 |
||
6146 | 2488 |
copyToLevel:level |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2489 |
"a controlled deepCopy, where the number of levels can be specified. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2490 |
Notice: |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2491 |
This method DOES NOT handle cycles/self-refs and does NOT preserve object identity; |
8383 | 2492 |
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
|
2493 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2494 |
|newObject class index| |
6146 | 2495 |
|
2496 |
level == 1 ifTrue:[^ self shallowCopy]. |
|
2497 |
||
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2498 |
class := self class. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2499 |
newObject := self clone. |
6146 | 2500 |
newObject == self ifTrue: [^ self]. |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2501 |
class isVariable ifTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2502 |
index := self basicSize. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2503 |
[index > 0] whileTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2504 |
newObject basicAt: index put: ((self basicAt: index) copyToLevel:(level-1)). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2505 |
index := index - 1 |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2506 |
] |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2507 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2508 |
index := class instSize. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2509 |
[index > 0] whileTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2510 |
newObject instVarAt: index put: ((self instVarAt: index) copyToLevel:(level-1)). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2511 |
index := index - 1 |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2512 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2513 |
^ newObject |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2514 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2515 |
" |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2516 |
|a b| |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2517 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2518 |
a := #( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2519 |
'1.1' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2520 |
'1.2' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2521 |
'1.3' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2522 |
( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2523 |
'1.41' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2524 |
'1.42' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2525 |
'1.43' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2526 |
( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2527 |
'1.441' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2528 |
'1.442' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2529 |
'1.443' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2530 |
( '1.4441' '1.4442' '1.4443' ) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2531 |
'1.445' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2532 |
) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2533 |
'1.45' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2534 |
) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2535 |
'1.5' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2536 |
). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2537 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2538 |
b := a copyToLevel:1. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2539 |
self assert: ( (a at:1) == (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2540 |
self assert: ( (a at:4) == (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2541 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2542 |
b := a copyToLevel:2. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2543 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2544 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2545 |
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
|
2546 |
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
|
2547 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2548 |
b := a copyToLevel:3. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2549 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2550 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2551 |
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
|
2552 |
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
|
2553 |
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
|
2554 |
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
|
2555 |
" |
6146 | 2556 |
! |
2557 |
||
5755 | 2558 |
deepCopy |
2559 |
"return a copy of the object with all subobjects also copied. |
|
2560 |
This method DOES handle cycles/self-refs and preserves object identity; |
|
2561 |
however the receivers class is not copied (to avoid the 'total' copy). |
|
2562 |
||
2563 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
2564 |
keeps track of already copied objects. If you are sure, that your |
|
2565 |
copied object does not include duplicates (or you do not care) and |
|
2566 |
no cycles are involved, you can use the old simpleDeepCopy, |
|
2567 |
which avoids this overhead (but may run into trouble). |
|
2568 |
Notice, that deepCopy does not copy dependents." |
|
2569 |
||
8383 | 2570 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 2571 |
|
2572 |
"an example which is not handled by the old deepCopy: |
|
2573 |
||
2574 |
|a| |
|
2575 |
a := Array new:3. |
|
2576 |
a at:3 put:a. |
|
2577 |
a deepCopy inspect |
|
2578 |
" |
|
2579 |
||
2580 |
" |
|
2581 |
|a| |
|
2582 |
a := Color black onDevice:Screen current. |
|
2583 |
a deepCopy inspect |
|
2584 |
" |
|
2585 |
||
2586 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
2587 |
! |
|
2588 |
||
2589 |
deepCopyError |
|
2590 |
"{ Pragma: +optSpace }" |
|
2591 |
||
2592 |
"raise a signal, that deepCopy is not allowed for this object" |
|
2593 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
2594 |
^ DeepCopyError raise |
5755 | 2595 |
! |
2596 |
||
2597 |
deepCopyUsing:aDictionary |
|
2598 |
"a helper for deepCopy; return a copy of the object with |
|
2599 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
2600 |
use the value found there. The class of the receiver is not copied. |
|
2601 |
This method DOES handle cycles/self references." |
|
2602 |
||
2603 |
|myClass aCopy |
|
2604 |
sz "{ Class: SmallInteger }" |
|
2605 |
iOrig iCopy| |
|
2606 |
||
2607 |
myClass := self class. |
|
2608 |
myClass isVariable ifTrue:[ |
|
6654 | 2609 |
sz := self basicSize. |
2610 |
aCopy := myClass basicNew:sz. |
|
5755 | 2611 |
] ifFalse:[ |
6654 | 2612 |
sz := 0. |
2613 |
aCopy := myClass basicNew |
|
5755 | 2614 |
]. |
2615 |
aCopy setHashFrom:self. |
|
2616 |
aDictionary at:self put:aCopy. |
|
2617 |
||
2618 |
" |
|
2619 |
copy indexed instvars - if any |
|
2620 |
" |
|
2621 |
sz ~~ 0 ifTrue:[ |
|
6654 | 2622 |
myClass isBits ifTrue:[ |
2623 |
"block-copy indexed instvars" |
|
2624 |
aCopy replaceFrom:1 to:sz with:self startingAt:1 |
|
2625 |
] ifFalse:[ |
|
2626 |
"individual deep copy the indexed variables" |
|
2627 |
1 to:sz do:[:i | |
|
2628 |
iOrig := self basicAt:i. |
|
2629 |
iOrig notNil ifTrue:[ |
|
8372 | 2630 |
"/ used to be dict-includesKey-ifTrue[dict-at:], |
2631 |
"/ changed to use dict-at:ifAbsent:, to avoid double lookup in dictionary |
|
2632 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2633 |
iCopy isNil ifTrue:[ |
|
8383 | 2634 |
iCopy := iOrig deepCopyUsing:aDictionary |
6654 | 2635 |
]. |
2636 |
aCopy basicAt:i put:iCopy |
|
2637 |
] |
|
2638 |
] |
|
2639 |
] |
|
5755 | 2640 |
]. |
2641 |
||
2642 |
" |
|
2643 |
copy the instance variables |
|
2644 |
" |
|
2645 |
sz := myClass instSize. |
|
2646 |
1 to:sz do:[:i | |
|
6654 | 2647 |
(self skipInstvarIndexInDeepCopy:i) ifFalse:[ |
2648 |
iOrig := self instVarAt:i. |
|
2649 |
iOrig notNil ifTrue:[ |
|
8372 | 2650 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
2651 |
iCopy isNil ifTrue:[ |
|
8383 | 2652 |
iCopy := iOrig deepCopyUsing:aDictionary |
6654 | 2653 |
]. |
2654 |
aCopy instVarAt:i put:iCopy |
|
2655 |
] |
|
2656 |
] |
|
5755 | 2657 |
]. |
8383 | 2658 |
aCopy postDeepCopyFrom:self. |
5755 | 2659 |
^ aCopy |
2660 |
||
2661 |
" |
|
2662 |
|a b c copyOfC| |
|
2663 |
||
2664 |
a := Array with:'hello' with:'world' with:nil. |
|
2665 |
b := 99 @ 999. |
|
2666 |
a at:3 put:b. |
|
2667 |
c := Array with:a with:b with:a. |
|
2668 |
||
2669 |
Transcript showCR: (c at:1) == (c at:3). |
|
2670 |
copyOfC := c deepCopy. |
|
2671 |
Transcript showCR: (copyOfC at:1) == (copyOfC at:3) |
|
2672 |
" |
|
2673 |
! |
|
2674 |
||
2675 |
postCopy |
|
2676 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
2677 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
2678 |
(see there)" |
|
2679 |
||
2680 |
^ self |
|
2681 |
! |
|
2682 |
||
2683 |
postDeepCopy |
|
2684 |
"allows for cleanup after deep copying" |
|
2685 |
||
2686 |
^ self postCopy |
|
2687 |
! |
|
2688 |
||
2689 |
postDeepCopyFrom:aSource |
|
2690 |
"allows for cleanup after deep copying" |
|
2691 |
||
2692 |
^ self postDeepCopy |
|
2693 |
! |
|
2694 |
||
2695 |
setHashFrom:anObject |
|
2696 |
"set my identity-hash key to be the same as anObjects hash key. |
|
2697 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
2698 |
Smalltalks, and may not be available in future ST/X versions. |
|
2699 |
DO NEVER use this for normal application code." |
|
2700 |
||
2701 |
%{ /* NOCONTEXT */ |
|
2702 |
||
2703 |
REGISTER unsigned h; |
|
2704 |
||
2705 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
6654 | 2706 |
h = __GET_HASH(anObject); |
2707 |
__SET_HASH(self, h); |
|
2708 |
RETURN (self); |
|
5755 | 2709 |
} |
2710 |
%}. |
|
2711 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
2712 |
! |
|
2713 |
||
2714 |
shallowCopy |
|
2715 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2716 |
i.e. the copy shares referenced instvars with its original." |
|
2717 |
||
2718 |
%{ /* NOCONTEXT */ |
|
2719 |
int ninsts, spc; |
|
2720 |
int sz; |
|
2721 |
OBJ theCopy; |
|
2722 |
OBJ cls; |
|
2723 |
int flags; |
|
2724 |
||
2725 |
cls = __qClass(self); |
|
2726 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
2727 |
||
2728 |
/* |
|
2729 |
* bail out for special objects .. |
|
2730 |
*/ |
|
2731 |
if (((flags & ~ARRAYMASK) == 0) |
|
2732 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
6654 | 2733 |
sz = __qSize(self); |
2734 |
__PROTECT__(self); |
|
2735 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
2736 |
__UNPROTECT__(self); |
|
2737 |
if (theCopy) { |
|
2738 |
cls = __qClass(self); |
|
2739 |
spc = __qSpace(theCopy); |
|
2740 |
||
2741 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
2742 |
||
2743 |
sz = sz - OHDR_SIZE; |
|
2744 |
if (sz) { |
|
2745 |
char *src, *dst; |
|
2746 |
||
2747 |
src = (char *)(__InstPtr(self)->i_instvars); |
|
2748 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
5755 | 2749 |
#ifdef bcopy4 |
6654 | 2750 |
{ |
2751 |
/* care for odd-number of longs */ |
|
2752 |
int nW = sz >> 2; |
|
2753 |
||
2754 |
if (sz & 3) { |
|
2755 |
nW++; |
|
2756 |
} |
|
2757 |
||
2758 |
bcopy4(src, dst, nW); |
|
2759 |
} |
|
5755 | 2760 |
#else |
6654 | 2761 |
bcopy(src, dst, sz); |
5755 | 2762 |
#endif |
2763 |
||
6654 | 2764 |
flags &= ARRAYMASK; |
2765 |
if (flags == POINTERARRAY) { |
|
2766 |
ninsts = __BYTES2OBJS__(sz); |
|
2767 |
} else { |
|
2768 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
2769 |
} |
|
2770 |
if (ninsts) { |
|
2771 |
do { |
|
2772 |
OBJ el; |
|
2773 |
||
2774 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
2775 |
__STORE_SPC(theCopy, el, spc); |
|
2776 |
} while (--ninsts); |
|
2777 |
} |
|
2778 |
} |
|
2779 |
RETURN (theCopy); |
|
2780 |
} |
|
5755 | 2781 |
} |
2782 |
%}. |
|
2783 |
"/ fallBack for special objects & memoryAllocation failure case |
|
2784 |
||
2785 |
^ self slowShallowCopy |
|
2786 |
! |
|
2787 |
||
2788 |
simpleDeepCopy |
|
2789 |
"return a copy of the object with all subobjects also copied. |
|
2790 |
This method does NOT handle cycles - but is included to allow this |
|
2791 |
slightly faster copy in situations where it is known that |
|
2792 |
no recursive references occur (LargeIntegers for example). |
|
2793 |
NOTICE: you will run into trouble, when trying this with recursive |
|
2794 |
objects (usually recursionInterrupt or memory-alert). |
|
8383 | 2795 |
This method corresponds to the 'traditional' deepCopy found in the Blue book." |
5755 | 2796 |
|
2797 |
|myClass aCopy| |
|
2798 |
||
2799 |
(myClass := self class) isVariable ifTrue:[ |
|
6654 | 2800 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2801 |
] ifFalse:[ |
6654 | 2802 |
aCopy := myClass basicNew |
5755 | 2803 |
]. |
2804 |
||
2805 |
"copy the instance variables" |
|
2806 |
aCopy cloneFrom:self performing:#simpleDeepCopy. |
|
2807 |
^ aCopy |
|
2808 |
||
2809 |
"a bad example (but ST/X should survive ...)" |
|
2810 |
" |
|
2811 |
|a| |
|
2812 |
a := Array new:3. |
|
2813 |
a at:3 put:a. |
|
2814 |
a simpleDeepCopy |
|
2815 |
" |
|
2816 |
! |
|
2817 |
||
2818 |
skipInstvarIndexInDeepCopy:index |
|
2819 |
"a helper for deepCopy; only indices for which this method returns |
|
2820 |
false are copied in a deep copy. |
|
2821 |
The default is false here - which means that everything is copied. |
|
2822 |
Can be redefined in subclasses for partial copies" |
|
2823 |
||
2824 |
^ false |
|
2825 |
! |
|
2826 |
||
2827 |
slowShallowCopy |
|
2828 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2829 |
i.e. the copy shares referenced instvars with its original. |
|
2830 |
This method is only invoked as a fallback from #shallowCopy." |
|
2831 |
||
2832 |
|myClass aCopy| |
|
2833 |
||
2834 |
(myClass := self class) isVariable ifTrue:[ |
|
6654 | 2835 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2836 |
] ifFalse:[ |
6654 | 2837 |
aCopy := myClass basicNew |
5755 | 2838 |
]. |
2839 |
||
2840 |
"copy the instance variables" |
|
2841 |
aCopy cloneFrom:self performing:#yourself. |
|
2842 |
^ aCopy |
|
2843 |
! ! |
|
2844 |
||
2845 |
!Object methodsFor:'debugging'! |
|
2846 |
||
7621 | 2847 |
assert:aBooleanOrBlock |
6964 | 2848 |
"fail, if the argument is not true and report an error" |
2849 |
||
6961 | 2850 |
"{ Pragma: +optSpace }" |
2851 |
||
7621 | 2852 |
self assert:aBooleanOrBlock message:'Assertion failed' |
2853 |
! |
|
2854 |
||
2855 |
assert:aBooleanOrBlock message:messageIfFailing |
|
6964 | 2856 |
"fail, if the argument is not true and report an error" |
6961 | 2857 |
|
2858 |
"{ Pragma: +optSpace }" |
|
2859 |
||
7621 | 2860 |
(aBooleanOrBlock value) ifFalse:[ |
8273 | 2861 |
self error:messageIfFailing mayProceed:true |
6961 | 2862 |
]. |
2863 |
! |
|
2864 |
||
5755 | 2865 |
basicInspect |
2866 |
"{ Pragma: +optSpace }" |
|
2867 |
||
2868 |
"launch an inspector on the receiver. |
|
2869 |
this method should NOT be redefined in subclasses." |
|
2870 |
||
2871 |
Inspector isNil ifTrue:[ |
|
6654 | 2872 |
" |
2873 |
for systems without GUI |
|
2874 |
" |
|
6926 | 2875 |
self warn:'No Inspector defined (Inspector is nil).' |
5755 | 2876 |
] ifFalse:[ |
6654 | 2877 |
Inspector openOn:self |
5755 | 2878 |
] |
2879 |
||
2880 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
2881 |
! |
|
2882 |
||
6954 | 2883 |
breakPoint:something |
2884 |
"{ Pragma: +optSpace }" |
|
2885 |
||
2886 |
"Like halt, but disabled by default. |
|
2887 |
Can be easily enabled. |
|
2888 |
Can be filtered on the arguments value (typically: a symbol). |
|
2889 |
Code with breakpoints may be even checked into the source repository" |
|
2890 |
||
2891 |
"Example: nil breakPoint:#stefan" |
|
2892 |
||
2893 |
"/ something = OperatingSystem getLoginName ifTrue:[ |
|
2894 |
"/ ^ HaltSignal raiseRequestWith:something errorString:'Breakpoint encountered: ', something printString |
|
2895 |
"/ ]. |
|
2896 |
||
2897 |
"/ something = 'testThis' ifTrue:[ |
|
2898 |
"/ ^ HaltSignal raiseRequestWith:something errorString:'Breakpoint encountered: ', something printString |
|
2899 |
"/ ]. |
|
2900 |
! |
|
2901 |
||
5995 | 2902 |
browse |
2903 |
"open a browser on the receivers class" |
|
2904 |
||
2905 |
self class theNonMetaclass browse |
|
2906 |
||
2907 |
" |
|
2908 |
10 browse |
|
2909 |
Collection browse |
|
2910 |
Collection class browse |
|
2911 |
" |
|
2912 |
! |
|
2913 |
||
5755 | 2914 |
inspect |
2915 |
"{ Pragma: +optSpace }" |
|
2916 |
||
2917 |
"launch an inspector on the receiver. |
|
2918 |
this method (or better: inspectorClass) can be redefined in subclasses |
|
2919 |
to start special inspectors." |
|
2920 |
||
2921 |
|cls| |
|
2922 |
||
2923 |
cls := self inspectorClass. |
|
2924 |
cls isNil ifTrue:[ |
|
6654 | 2925 |
^ self basicInspect |
5755 | 2926 |
]. |
2927 |
cls openOn:self |
|
2928 |
||
2929 |
" |
|
2930 |
Object new inspect |
|
2931 |
(1 @ 2) inspect |
|
2932 |
Smalltalk inspect |
|
2933 |
#(1 2 3) asOrderedCollection inspect |
|
2934 |
(Color red) inspect |
|
2935 |
(Image fromFile:'bitmaps/garfield.gif') inspect |
|
2936 |
" |
|
2937 |
! |
|
2938 |
||
2939 |
inspectorClass |
|
2940 |
"{ Pragma: +optSpace }" |
|
2941 |
||
2942 |
"return the class to use for inspect. |
|
2943 |
Can (should) be redefined in classes for which a better inspector is available" |
|
2944 |
||
2945 |
^ Inspector |
|
2946 |
! |
|
2947 |
||
2948 |
mustBeBoolean |
|
2949 |
"this message is sent by the VM, if a non-Boolean receiver is encountered |
|
2950 |
in an if* or while* message. |
|
2951 |
Caveat: for now, this is only sent by the interpreter; |
|
2952 |
both the JIT and the stc compiler treat it as undefined." |
|
2953 |
||
2954 |
self error:'Non boolean receiver - proceed for truth' mayProceed:true. |
|
2955 |
^ true |
|
2956 |
! |
|
2957 |
||
2958 |
mustBeKindOf:aClass |
|
2959 |
"for compatibility & debugging support: |
|
2960 |
check if the receiver isKindOf:aClass and raise an error if not. |
|
2961 |
Notice: |
|
6654 | 2962 |
it is VERY questionable, if it makes sense to add manual |
2963 |
type checks to a dynamically typed language like smalltalk. |
|
2964 |
It will, at least, slow down performance, |
|
2965 |
make your code less reusable and clutter your code with stupid sends |
|
2966 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
2967 |
use of isXXX check methods. |
|
5755 | 2968 |
You see: The author does not like this at all ..." |
2969 |
||
2970 |
(self isKindOf:aClass) ifFalse:[ |
|
6654 | 2971 |
self error:'argument is not of expected type' |
5755 | 2972 |
] |
2973 |
! |
|
2974 |
||
6950 | 2975 |
obsoleteFeatureWarning |
2976 |
"{ Pragma: +optSpace }" |
|
2977 |
||
2978 |
"in methods which are going to be changed, a send to |
|
2979 |
this method is used to tell programmers that some feature/semantics is |
|
2980 |
used which is going to be changed in later ST/X versions. |
|
6963 | 2981 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)." |
6950 | 2982 |
|
2983 |
self obsoleteFeatureWarning:nil from:thisContext sender |
|
2984 |
! |
|
2985 |
||
2986 |
obsoleteFeatureWarning:message |
|
2987 |
"{ Pragma: +optSpace }" |
|
2988 |
||
2989 |
"in methods which are going to be changed, a send to |
|
2990 |
this method is used to tell programmers that some feature/semantics is |
|
2991 |
used which is going to be changed in later ST/X versions. |
|
6963 | 2992 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
2993 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 2994 |
|
2995 |
self obsoleteFeatureWarning:message from:thisContext sender |
|
2996 |
! |
|
2997 |
||
2998 |
obsoleteFeatureWarning:message from:aContext |
|
2999 |
"{ Pragma: +optSpace }" |
|
3000 |
||
3001 |
"in methods which are going to be changed, a send to |
|
3002 |
this method is used to tell programmers that some feature/semantics is |
|
3003 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3004 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3005 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3006 |
|
3007 |
|spec| |
|
3008 |
||
3009 |
spec := aContext methodPrintString. |
|
3010 |
('WARNING: the ''' , spec , ''' semantics will be changed.') infoPrintCR. |
|
3011 |
(' Its behavior may be different in future ST/X versions.') infoPrintCR. |
|
3012 |
(' called from ' , aContext sender printString) infoPrintCR. |
|
7204 | 3013 |
(aContext sender selector startsWith:'perform:') ifTrue:[ |
3014 |
(' called from ' , aContext sender sender printString) infoPrintCR. |
|
3015 |
]. |
|
6950 | 3016 |
message notNil ifTrue:[ |
3017 |
'------> ' infoPrint. message infoPrintCR |
|
3018 |
] |
|
3019 |
||
3020 |
" |
|
3021 |
Object obsoleteFeatureWarning:'foo' from:thisContext sender sender |
|
3022 |
" |
|
3023 |
! |
|
3024 |
||
5755 | 3025 |
obsoleteMethodWarning |
3026 |
"{ Pragma: +optSpace }" |
|
3027 |
||
3028 |
"in methods which are going to be obsoleted, a self send to |
|
3029 |
this method is used to tell programmers that a method is |
|
3030 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3031 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3032 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3033 |
|
3034 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
3035 |
! |
|
3036 |
||
3037 |
obsoleteMethodWarning:message |
|
3038 |
"{ Pragma: +optSpace }" |
|
3039 |
||
3040 |
"in methods which are going to be obsoleted, a self send to |
|
3041 |
this method is used to tell programmers that a method is |
|
3042 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3043 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3044 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3045 |
|
3046 |
self obsoleteMethodWarning:message from:thisContext sender |
|
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3047 |
! |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3048 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3049 |
obsoleteMethodWarning:message from:aContext |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3050 |
"{ Pragma: +optSpace }" |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3051 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3052 |
"in methods which are going to be obsoleted, a self-send to |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3053 |
this method is used to tell programmers that a method is |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3054 |
used which is going to be removed in later ST/X versions. |
6963 | 3055 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3056 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
|
3057 |
This message is intended for application developers, so its printed as info message." |
|
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3058 |
|
8413 | 3059 |
|spec sender| |
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3060 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3061 |
spec := aContext methodPrintString. |
8413 | 3062 |
sender := aContext sender. |
6405
bbee0a853e2f
#obsoleteMethodWarning now uses infoPrint instead of errorPrint.
Stefan Vogel <sv@exept.de>
parents:
6388
diff
changeset
|
3063 |
('WARNING: the ''' , spec , ''' method is obsolete.') infoPrintCR. |
bbee0a853e2f
#obsoleteMethodWarning now uses infoPrint instead of errorPrint.
Stefan Vogel <sv@exept.de>
parents:
6388
diff
changeset
|
3064 |
(' And may not be present in future ST/X versions.') infoPrintCR. |
8413 | 3065 |
(' called from ' , sender printString) infoPrintCR. |
3066 |
(sender selector startsWith:'perform:') ifTrue:[ |
|
3067 |
sender := sender sender. |
|
3068 |
(sender selector startsWith:'perform:') ifTrue:[ |
|
3069 |
sender := sender sender. |
|
3070 |
]. |
|
3071 |
(' called from ' , sender printString) infoPrintCR. |
|
7204 | 3072 |
]. |
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3073 |
message notNil ifTrue:[ |
6654 | 3074 |
'------> ' infoPrint. message infoPrintCR |
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3075 |
] |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3076 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3077 |
" |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3078 |
Object obsoleteMethodWarning:'foo' from:thisContext sender sender |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
3079 |
" |
5755 | 3080 |
! ! |
3081 |
||
3082 |
!Object methodsFor:'dependents access'! |
|
3083 |
||
3084 |
addDependent:anObject |
|
3085 |
"make the argument, anObject be a dependent of the receiver" |
|
3086 |
||
3087 |
|wasBlocked| |
|
3088 |
||
3089 |
"/ must do this save from interrupts, since the dependents collection |
|
3090 |
"/ is possibly accessed from multiple threads. |
|
3091 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3092 |
"/ faster execution. |
|
3093 |
||
3094 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3095 |
[ |
|
6654 | 3096 |
|deps dep| |
3097 |
||
3098 |
deps := self dependents. |
|
3099 |
||
3100 |
"/ to save a fair amount of memory in case of |
|
3101 |
"/ many dependencies, we store a single dependent in |
|
3102 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3103 |
"/ added. |
|
3104 |
||
3105 |
(deps isNil or:[deps size == 0]) ifTrue:[ |
|
3106 |
self dependents:(WeakArray with:anObject) |
|
3107 |
] ifFalse:[ |
|
3108 |
deps class == WeakArray ifTrue:[ |
|
3109 |
dep := deps at:1. |
|
3110 |
dep ~~ anObject ifTrue:[ |
|
3111 |
(dep isNil or:[dep == 0]) ifTrue:[ |
|
3112 |
deps at:1 put:anObject |
|
3113 |
] ifFalse:[ |
|
3114 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
3115 |
] |
|
3116 |
] |
|
3117 |
] ifFalse:[ |
|
3118 |
deps add:anObject |
|
3119 |
] |
|
3120 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3121 |
] ensure:[ |
6654 | 3122 |
wasBlocked ifFalse:[ |
3123 |
OperatingSystem unblockInterrupts |
|
3124 |
] |
|
5755 | 3125 |
] |
3126 |
||
3127 |
"Modified: / 27.10.1997 / 19:35:52 / cg" |
|
3128 |
! |
|
3129 |
||
3130 |
breakDependents |
|
3131 |
"remove all dependencies from the receiver" |
|
3132 |
||
3133 |
self dependents:nil. |
|
3134 |
self nonWeakDependents:nil |
|
3135 |
||
3136 |
"Modified: / 19.4.1996 / 10:55:36 / cg" |
|
3137 |
"Created: / 27.2.1998 / 11:26:11 / stefan" |
|
3138 |
! |
|
3139 |
||
3140 |
dependents |
|
3141 |
"return a Collection of dependents. |
|
3142 |
The default implementation here uses a global WeakDictionary to store |
|
3143 |
dependents |
|
3144 |
This may be too slow for high frequency change&update, |
|
3145 |
therefore, some classes (Model) redefine this for better performance. |
|
3146 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
3147 |
||
3148 |
|deps| |
|
3149 |
||
3150 |
(deps := Dependencies at:self ifAbsent:nil) isNil ifTrue:[ |
|
6654 | 3151 |
^ #(). |
5755 | 3152 |
]. |
3153 |
^ deps |
|
3154 |
||
3155 |
"Modified: / 26.1.1998 / 11:18:15 / cg" |
|
3156 |
! |
|
3157 |
||
3158 |
dependents:aCollection |
|
3159 |
"set the collection of dependents. |
|
3160 |
The default implementation here uses a global Dictionary to store |
|
3161 |
dependents which may be too slow for high frequency change&update. |
|
3162 |
Therefore, some classes (Model) redefine this for better performance." |
|
3163 |
||
3164 |
"/ must do this save from interrupts, since the dependents collection |
|
3165 |
"/ is possibly accessed from multiple threads. |
|
3166 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3167 |
"/ faster execution (and to avoid creation of garbage blocks). |
|
3168 |
||
3169 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
6654 | 3170 |
"/ the common case - already blocked |
3171 |
||
3172 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
3173 |
Dependencies removeKey:self ifAbsent:nil |
|
3174 |
] ifFalse:[ |
|
3175 |
Dependencies at:self put:aCollection |
|
3176 |
]. |
|
3177 |
^ self |
|
5755 | 3178 |
]. |
3179 |
||
3180 |
[ |
|
6654 | 3181 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3182 |
Dependencies removeKey:self ifAbsent:nil |
|
3183 |
] ifFalse:[ |
|
3184 |
Dependencies at:self put:aCollection |
|
3185 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3186 |
] ensure:[ |
6654 | 3187 |
OperatingSystem unblockInterrupts |
5755 | 3188 |
] |
3189 |
||
3190 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
|
3191 |
! |
|
3192 |
||
3193 |
dependentsDo:aBlock |
|
3194 |
"evaluate aBlock for all of my dependents" |
|
3195 |
||
3196 |
|deps nwDeps| |
|
3197 |
||
3198 |
deps := self dependents. |
|
3199 |
deps size ~~ 0 ifTrue:[ |
|
6654 | 3200 |
deps do:[:d | |
3201 |
(d notNil and:[d ~~ 0]) ifTrue:[ |
|
3202 |
aBlock value:d |
|
3203 |
] |
|
3204 |
] |
|
5755 | 3205 |
]. |
3206 |
nwDeps := self nonWeakDependents. |
|
3207 |
(nwDeps ~~ deps and:[nwDeps size ~~ 0]) ifTrue:[ |
|
6654 | 3208 |
nwDeps do:aBlock |
5755 | 3209 |
]. |
3210 |
||
3211 |
"Modified: / 30.1.1998 / 14:03:40 / cg" |
|
3212 |
! |
|
3213 |
||
3214 |
myDependents |
|
3215 |
"same as dependents - ST-80 compatibility" |
|
3216 |
||
3217 |
^ self dependents |
|
3218 |
! |
|
3219 |
||
3220 |
release |
|
3221 |
"remove all references to objects that may refer to self. |
|
3222 |
Subclasses may redefine this method but should do a 'super release'." |
|
3223 |
||
3224 |
self breakDependents |
|
3225 |
||
3226 |
"Modified: / 27.2.1998 / 11:29:35 / stefan" |
|
3227 |
! |
|
3228 |
||
3229 |
removeDependent:anObject |
|
3230 |
"make the argument, anObject be independent of the receiver" |
|
3231 |
||
3232 |
|wasBlocked| |
|
3233 |
||
3234 |
"/ must do this save from interrupts, since the dependents collection |
|
3235 |
"/ is possibly accessed from multiple threads. |
|
3236 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3237 |
"/ faster execution. |
|
3238 |
||
3239 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3240 |
[ |
|
6654 | 3241 |
|deps n d| |
3242 |
||
3243 |
deps := self dependents. |
|
3244 |
deps size ~~ 0 ifTrue:[ |
|
3245 |
||
3246 |
"/ to save a fair amount of memory in case of |
|
3247 |
"/ many dependencies, we store a single dependent in |
|
3248 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3249 |
"/ added. Here we have to do the inverse ... |
|
3250 |
||
3251 |
deps class == WeakArray ifTrue:[ |
|
3252 |
((d := deps at:1) == anObject |
|
3253 |
or:[d isNil |
|
3254 |
or:[d == 0]]) ifTrue:[ |
|
3255 |
self dependents:nil |
|
3256 |
] |
|
3257 |
] ifFalse:[ |
|
3258 |
deps remove:anObject ifAbsent:[]. |
|
3259 |
(n := deps size) == 0 ifTrue:[ |
|
3260 |
self dependents:nil |
|
3261 |
] ifFalse:[ |
|
3262 |
n == 1 ifTrue:[ |
|
3263 |
d := deps firstIfEmpty:nil. |
|
3264 |
d notNil ifTrue:[ |
|
3265 |
deps := WeakArray with:d |
|
3266 |
] ifFalse:[ |
|
3267 |
deps := nil |
|
3268 |
]. |
|
3269 |
self dependents:deps. |
|
3270 |
] |
|
3271 |
] |
|
3272 |
] |
|
3273 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3274 |
] ensure:[ |
6654 | 3275 |
wasBlocked ifFalse:[ |
3276 |
OperatingSystem unblockInterrupts |
|
3277 |
] |
|
5755 | 3278 |
] |
3279 |
||
3280 |
"Modified: / 26.1.1998 / 19:51:50 / cg" |
|
3281 |
! ! |
|
3282 |
||
7266 | 3283 |
!Object methodsFor:'dependents access (non weak)'! |
5755 | 3284 |
|
3285 |
addNonWeakDependent:anObject |
|
3286 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
|
3287 |
Be careful: this nonWeakDependency will prevent the dependent from being |
|
3288 |
garbage collected unless the dependency is removed. |
|
3289 |
This is a private mechanism, for directed dependencies." |
|
3290 |
||
3291 |
|wasBlocked| |
|
3292 |
||
3293 |
"/ must do this save from interrupts, since the dependents collection |
|
3294 |
"/ is possibly accessed from multiple threads. |
|
3295 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3296 |
"/ faster execution. |
|
3297 |
||
3298 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3299 |
[ |
|
6654 | 3300 |
|deps dep| |
3301 |
||
3302 |
deps := self nonWeakDependents. |
|
3303 |
||
3304 |
"/ to save a fair amount of memory in case of |
|
3305 |
"/ many dependencies, we store a single dependent in |
|
3306 |
"/ an Array, and switch to a Set if more dependents are |
|
3307 |
"/ added. |
|
3308 |
||
3309 |
deps size == 0 ifTrue:[ |
|
3310 |
self nonWeakDependents:(Array with:anObject) |
|
3311 |
] ifFalse:[ |
|
3312 |
deps class == Array ifTrue:[ |
|
3313 |
dep := deps at:1. |
|
3314 |
dep ~~ anObject ifTrue:[ |
|
3315 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
3316 |
] |
|
3317 |
] ifFalse:[ |
|
3318 |
deps add:anObject |
|
3319 |
] |
|
3320 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3321 |
] ensure:[ |
6654 | 3322 |
wasBlocked ifFalse:[ |
3323 |
OperatingSystem unblockInterrupts |
|
3324 |
] |
|
5755 | 3325 |
] |
3326 |
||
3327 |
"Created: / 19.4.1996 / 10:54:08 / cg" |
|
3328 |
"Modified: / 30.1.1998 / 14:03:08 / cg" |
|
3329 |
! |
|
3330 |
||
3331 |
nonWeakDependents |
|
3332 |
"return a Collection of nonWeakDependents - empty if there is none. |
|
3333 |
This is a private mechanism for directed dependencies." |
|
3334 |
||
3335 |
NonWeakDependencies isNil ifTrue:[^ #()]. |
|
3336 |
^ NonWeakDependencies at:self ifAbsent:#() |
|
3337 |
||
3338 |
"Created: / 19.4.1996 / 10:55:06 / cg" |
|
3339 |
"Modified: / 30.1.1998 / 14:06:47 / cg" |
|
3340 |
! |
|
3341 |
||
3342 |
nonWeakDependents:aCollection |
|
3343 |
"set the collection of nonWeak dependents. |
|
3344 |
This is a private helper for directed dependencies." |
|
3345 |
||
3346 |
[ |
|
6654 | 3347 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3348 |
NonWeakDependencies removeKey:self ifAbsent:nil |
|
3349 |
] ifFalse:[ |
|
3350 |
NonWeakDependencies at:self put:aCollection |
|
3351 |
] |
|
5755 | 3352 |
] valueUninterruptably |
3353 |
||
3354 |
"Created: 19.4.1996 / 11:07:47 / cg" |
|
3355 |
! |
|
3356 |
||
3357 |
removeNonWeakDependent:anObject |
|
3358 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
|
3359 |
(i.e. make it independent of the receiver)" |
|
3360 |
||
3361 |
|wasBlocked| |
|
3362 |
||
3363 |
"/ must do this save from interrupts, since the dependents collection |
|
3364 |
"/ is possibly accessed from multiple threads. |
|
3365 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3366 |
"/ faster execution. |
|
3367 |
||
3368 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3369 |
[ |
|
6654 | 3370 |
|deps n| |
3371 |
||
3372 |
deps := self nonWeakDependents. |
|
3373 |
deps size ~~ 0 ifTrue:[ |
|
3374 |
deps class == Array ifTrue:[ |
|
3375 |
(deps at:1) == anObject ifTrue:[ |
|
3376 |
self nonWeakDependents:nil |
|
3377 |
] |
|
3378 |
] ifFalse:[ |
|
3379 |
deps remove:anObject ifAbsent:[]. |
|
3380 |
(n := deps size) == 0 ifTrue:[ |
|
3381 |
self nonWeakDependents:nil |
|
3382 |
] ifFalse:[ |
|
3383 |
n == 1 ifTrue:[ |
|
3384 |
self nonWeakDependents:(Array with:(deps first)) |
|
3385 |
] |
|
3386 |
] |
|
3387 |
] |
|
3388 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3389 |
] ensure:[ |
6654 | 3390 |
wasBlocked ifFalse:[ |
3391 |
OperatingSystem unblockInterrupts |
|
3392 |
] |
|
5755 | 3393 |
] |
3394 |
||
3395 |
"Created: / 19.4.1996 / 11:44:44 / cg" |
|
3396 |
"Modified: / 30.1.1998 / 14:04:01 / cg" |
|
3397 |
! ! |
|
3398 |
||
3399 |
!Object methodsFor:'displaying'! |
|
3400 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3401 |
ascentOn:aGC |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3402 |
"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
|
3403 |
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
|
3404 |
coordinate is given by y. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3405 |
In other words: some draw above the given y coordinate. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3406 |
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
|
3407 |
the given y coordinate." |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3408 |
|
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3409 |
^ (aGC font onDevice:aGC device) ascent |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3410 |
! |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3411 |
|
6900 | 3412 |
displayOn:aGCOrStream |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3413 |
"Compatibility |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3414 |
append a printed desription on some stream (Dolphin, Squeak) |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3415 |
OR: |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3416 |
display the receiver in a graphicsContext at 0@0 (ST80). |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3417 |
This method allows for any object to be displayed in some view |
5755 | 3418 |
(although the fallBack is to display its printString ...)" |
3419 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3420 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3421 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
6900 | 3422 |
(aGCOrStream isStream or:[aGCOrStream == Transcript]) ifTrue:[ |
3423 |
self printOn:aGCOrStream. |
|
3424 |
^ self |
|
3425 |
]. |
|
3426 |
^ self displayOn:aGCOrStream x:0 y:0. |
|
5755 | 3427 |
|
3428 |
"Created: 29.5.1996 / 16:28:58 / cg" |
|
3429 |
! |
|
3430 |
||
3431 |
displayOn:aGC at:aPoint |
|
3432 |
"ST-80 Compatibility |
|
3433 |
display the receiver in a graphicsContext - this method allows |
|
3434 |
for any object to be displayed in a ListView - for example." |
|
3435 |
||
3436 |
^ self displayOn:aGC x:(aPoint x) y:(aPoint y). |
|
3437 |
! |
|
3438 |
||
3439 |
displayOn:aGC x:x y:y |
|
3440 |
"display the receiver in a graphicsContext - this method allows |
|
3441 |
for any object to be displayed in a ListView - for example." |
|
3442 |
||
3443 |
self displayOn:aGC x:x y:y opaque:false |
|
3444 |
||
3445 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3446 |
! |
|
3447 |
||
3448 |
displayOn:aGc x:x y:y opaque:opaque |
|
3449 |
"display the receiver in a graphicsContext - this method allows |
|
3450 |
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
|
3451 |
The fallBack here shows the receivers displayString. |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3452 |
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
|
3453 |
ask using #ascentOn: if required" |
5755 | 3454 |
|
3455 |
|s yBaseline| |
|
3456 |
||
3457 |
s := self displayString. |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3458 |
yBaseline := y "+ aGc font ascent". |
5755 | 3459 |
opaque ifTrue:[ |
6654 | 3460 |
aGc displayOpaqueString:s x:x y:yBaseline. |
5755 | 3461 |
] ifFalse:[ |
6654 | 3462 |
aGc displayString:s x:x y:yBaseline. |
5755 | 3463 |
]. |
3464 |
||
3465 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3466 |
! |
|
3467 |
||
3468 |
displayOpaqueOn:aGC x:x y:y |
|
3469 |
"display the receiver in a graphicsContext - this method allows |
|
3470 |
for any object to be displayed in a ListView - for example." |
|
3471 |
||
3472 |
self displayOn:aGC x:x y:y opaque:true |
|
3473 |
||
3474 |
"Modified: / 29.5.1996 / 16:29:38 / cg" |
|
3475 |
"Created: / 26.10.1997 / 15:01:36 / cg" |
|
3476 |
! |
|
3477 |
||
3478 |
displayString |
|
3479 |
"return a string used when displaying the receiver in a view; |
|
3480 |
for example an Inspector. This is usually the same as printString, |
|
3481 |
but sometimes redefined for a better look." |
|
3482 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3483 |
|s| |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3484 |
|
8322
95ca965f65ed
Handle unicode in #displayString
Stefan Vogel <sv@exept.de>
parents:
8300
diff
changeset
|
3485 |
s := CharacterWriteStream on:(String new:32). |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3486 |
self displayOn:s. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3487 |
^ s contents |
5755 | 3488 |
|
3489 |
" |
|
3490 |
#(1 2 3) printString |
|
3491 |
#(1 2 3) displayString |
|
3492 |
#(1 2 3) storeString |
|
3493 |
" |
|
3494 |
! |
|
3495 |
||
3496 |
heightOn:aGC |
|
3497 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
3498 |
||
3499 |
^ (aGC font onDevice:aGC device) heightOf:(self displayString) |
|
3500 |
! |
|
3501 |
||
6654 | 3502 |
widthFrom:startIndex to:endIndex on:aGC |
3503 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3504 |
||
3505 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) from:startIndex to:endIndex |
|
3506 |
! |
|
3507 |
||
5755 | 3508 |
widthOn:aGC |
3509 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3510 |
||
3511 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) |
|
3512 |
! ! |
|
3513 |
||
7359 | 3514 |
!Object methodsFor:'double dispatching'! |
3515 |
||
3516 |
equalFromComplex:aComplex |
|
3517 |
"adding this method here allows for any non-number to be compared to a complex |
|
3518 |
and return false from this comparison. |
|
3519 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3520 |
which uses #= (i.e. a Set or Dictionary)." |
|
3521 |
||
3522 |
^ false |
|
3523 |
! |
|
3524 |
||
3525 |
equalFromFixedPoint:aFixedPoint |
|
3526 |
"adding this method here allows for any non-number to be compared to a fixedPoint |
|
3527 |
and return false from this comparison. |
|
3528 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3529 |
which uses #= (i.e. a Set or Dictionary)." |
|
3530 |
||
3531 |
^ false |
|
3532 |
! |
|
3533 |
||
3534 |
equalFromFloat:aFloat |
|
3535 |
"adding this method here allows for any non-number to be compared to a float |
|
3536 |
and return false from this comparison. |
|
3537 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3538 |
which uses #= (i.e. a Set or Dictionary)." |
|
3539 |
||
3540 |
^ false |
|
3541 |
! |
|
3542 |
||
3543 |
equalFromFraction:aFraction |
|
3544 |
"adding this method here allows for any non-number to be compared to a fraction |
|
3545 |
and return false from this comparison. |
|
3546 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3547 |
which uses #= (i.e. a Set or Dictionary)." |
|
3548 |
||
3549 |
^ false |
|
3550 |
! |
|
3551 |
||
3552 |
equalFromInteger:anInteger |
|
3553 |
"adding this method here allows for any non-number to be compared to an integer |
|
3554 |
and return false from this comparison. |
|
3555 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3556 |
which uses #= (i.e. a Set or Dictionary)." |
|
3557 |
||
3558 |
^ false |
|
3559 |
! |
|
3560 |
||
7455 | 3561 |
equalFromLargeFloat:aLargeFloat |
3562 |
"adding this method here allows for any non-number to be compared to a largeFloat |
|
3563 |
and return false from this comparison. |
|
3564 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3565 |
which uses #= (i.e. a Set or Dictionary)." |
|
3566 |
||
3567 |
^ false |
|
3568 |
! |
|
3569 |
||
7359 | 3570 |
equalFromLongFloat:aLongFloat |
3571 |
"adding this method here allows for any non-number to be compared to a longFloat |
|
3572 |
and return false from this comparison. |
|
3573 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3574 |
which uses #= (i.e. a Set or Dictionary)." |
|
3575 |
||
3576 |
^ false |
|
3577 |
! |
|
3578 |
||
3579 |
equalFromShortFloat:aShortFloat |
|
3580 |
"adding this method here allows for any non-number to be compared to a shortFloat |
|
3581 |
and return false from this comparison. |
|
3582 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3583 |
which uses #= (i.e. a Set or Dictionary)." |
|
3584 |
||
3585 |
^ false |
|
3586 |
! ! |
|
3587 |
||
5755 | 3588 |
!Object methodsFor:'encoding & decoding'! |
3589 |
||
3590 |
decodeAsLiteralArray |
|
3591 |
^ self |
|
3592 |
! |
|
3593 |
||
3594 |
encodeOn:anEncoder with:aParameter |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3595 |
"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
|
3596 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3597 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3598 |
|
8404 | 3599 |
self acceptVisitor:anEncoder with:aParameter |
6718 | 3600 |
! |
3601 |
||
3602 |
encodingVectorForInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3603 |
"OBSOLETE, use elementDescriptorForInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3604 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3605 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3606 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3607 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
6718 | 3608 |
|
3609 |
" |
|
3610 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
3611 |
Dictionary new encodingVectorForInstanceVariables |
|
3612 |
(5 @ nil) encodingVectorForInstanceVariables |
|
3613 |
" |
|
3614 |
! |
|
3615 |
||
3616 |
encodingVectorForNonNilInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3617 |
"OBSOLETE, use elementDescriptorForNonNilInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3618 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3619 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3620 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3621 |
^ self elementDescriptorForInstanceVariablesMatching:[:varVal | varVal notNil]. |
6718 | 3622 |
|
3623 |
" |
|
3624 |
#(1 2 3 nil true symbol) encodingVectorForNonNilInstanceVariables |
|
3625 |
(5 @ nil) encodingVectorForNonNilInstanceVariables |
|
3626 |
" |
|
3627 |
! |
|
3628 |
||
5755 | 3629 |
fromLiteralArrayEncoding:aSpecArray |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3630 |
"read my attributes from aSpecArray" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3631 |
|
5755 | 3632 |
|sel val |
3633 |
stop "{ Class:SmallInteger }" | |
|
3634 |
||
3635 |
stop := aSpecArray size. |
|
3636 |
||
3637 |
2 to:stop by:2 do:[:i| |
|
6654 | 3638 |
sel := aSpecArray at:i. |
3639 |
val := aSpecArray at:i + 1. |
|
3640 |
||
3641 |
(self respondsTo:sel) ifTrue:[ |
|
3642 |
self perform:sel with:(val decodeAsLiteralArray) |
|
3643 |
] ifFalse:[ |
|
3644 |
Transcript show:self class name; show:': unhandled literalArrayEncoding attribute: '. |
|
3645 |
Transcript showCR:sel. |
|
3646 |
] |
|
5755 | 3647 |
] |
3648 |
! |
|
3649 |
||
3650 |
literalArrayEncoding |
|
3651 |
"generate a literalArrayEncoding array for myself. |
|
3652 |
This uses #literalArrayEncodingSlotOrder which defines the slots and |
|
3653 |
order and #skippedInLiteralEncoding which defines slots to skip. |
|
3654 |
For most subclasses, there is no need to redefine those." |
|
3655 |
||
3656 |
|names encoding cls skipped| |
|
3657 |
||
3658 |
self isLiteral ifTrue:[ |
|
6654 | 3659 |
^ self |
5755 | 3660 |
]. |
3661 |
||
3662 |
skipped := self skippedInLiteralEncoding. |
|
3663 |
cls := self class. |
|
3664 |
names := cls allInstVarNames. |
|
3665 |
encoding := OrderedCollection with:(cls name). |
|
3666 |
||
3667 |
(self literalArrayEncodingSlotOrder) do:[:instSlot | |
|
6654 | 3668 |
|value nm| |
3669 |
||
3670 |
nm := names at:instSlot. |
|
3671 |
||
3672 |
(skipped includes:nm) ifFalse:[ |
|
3673 |
(value := self instVarAt:instSlot) notNil ifTrue:[ |
|
3674 |
encoding add:(nm , ':') asSymbol. |
|
3675 |
encoding add:value literalArrayEncoding |
|
3676 |
] |
|
3677 |
] |
|
5755 | 3678 |
]. |
3679 |
^ encoding asArray |
|
3680 |
||
3681 |
||
3682 |
! |
|
3683 |
||
3684 |
literalArrayEncodingSlotOrder |
|
3685 |
"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
|
3686 |
a literalArrayEncoding" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3687 |
|
5755 | 3688 |
^ 1 to:self class instSize |
3689 |
! |
|
3690 |
||
7112 | 3691 |
postDecodeFrom:aDecoder aspect:aspectSymbol |
3692 |
"invoked by xmlDecoder (and others in the future), after an |
|
3693 |
object has been decoded (i.e. its instance variables have been restored)" |
|
3694 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3695 |
^ self |
7112 | 3696 |
! |
3697 |
||
5755 | 3698 |
skippedInLiteralEncoding |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3699 |
"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
|
3700 |
|
5755 | 3701 |
^ #() |
3702 |
! ! |
|
3703 |
||
3704 |
!Object methodsFor:'error handling'! |
|
3705 |
||
3706 |
appropriateDebugger:aSelector |
|
3707 |
"{ Pragma: +optSpace }" |
|
3708 |
||
3709 |
"return an appropriate debugger to use. |
|
3710 |
If there is already a debugger active on the stack, and it is |
|
3711 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
3712 |
||
3713 |
|context| |
|
3714 |
||
3715 |
"DebugView cannot run without system processes" |
|
3716 |
||
3717 |
(Processor isNil |
|
3718 |
or:[Processor activeProcessIsSystemProcess |
|
3719 |
or:[Smalltalk isInitialized not]]) ifTrue:[ |
|
6654 | 3720 |
^ MiniDebugger |
5755 | 3721 |
]. |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
3722 |
(Screen isNil or:[Screen default isNil or:[Screen default isOpen not]]) ifTrue:[ |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
3723 |
Debugger isNil ifTrue:[^ nil]. |
6654 | 3724 |
^ MiniDebugger |
5755 | 3725 |
]. |
3726 |
||
3727 |
context := thisContext. |
|
3728 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
3729 |
[context notNil] whileTrue:[ |
|
6654 | 3730 |
((context receiver class == Debugger) |
3731 |
and:[context selector == aSelector]) ifTrue:[ |
|
3732 |
"we are already in some Debugger" |
|
3733 |
(Debugger == MiniDebugger) ifTrue:[ |
|
3734 |
"we are already in the MiniDebugger" |
|
3735 |
ErrorRecursion ifFalse:[ |
|
3736 |
Smalltalk fatalAbort:'recursive error ...' |
|
3737 |
] |
|
3738 |
]. |
|
3739 |
MiniDebugger isNil ifTrue:[ |
|
3740 |
Smalltalk fatalAbort:'no debugger' |
|
3741 |
]. |
|
3742 |
||
3743 |
"ok, an error occured while in the graphical debugger; |
|
3744 |
lets try MiniDebugger" |
|
3745 |
^ MiniDebugger |
|
3746 |
]. |
|
3747 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
5755 | 3748 |
]. |
3749 |
"not within Debugger - no problem" |
|
3750 |
^ Debugger |
|
3751 |
||
3752 |
"Modified: / 23.9.1996 / 12:14:52 / stefan" |
|
3753 |
"Modified: / 19.5.1999 / 18:05:00 / cg" |
|
3754 |
! |
|
3755 |
||
3756 |
cannotSendMessage:aMessage to:someReceiver |
|
3757 |
"this message is sent by the runtime system (VM), |
|
3758 |
when a message is sent to some object, whose class is not |
|
3759 |
a valid behavior (see documentation in Behavior)." |
|
3760 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3761 |
^ VMInternalError |
6654 | 3762 |
raiseWith:someReceiver |
3763 |
errorString:('bad class in send of #' , aMessage selector) |
|
5755 | 3764 |
|
3765 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
3766 |
! |
|
3767 |
||
3768 |
doesNotUnderstand:aMessage |
|
3769 |
"this message is sent by the runtime system (VM) when |
|
3770 |
a message is not understood by some object (i.e. there |
|
3771 |
is no method for that selector). The original message has |
|
3772 |
been packed into aMessage (i.e. the receiver, selector and |
|
3773 |
any arguments) and the original receiver is then sent the |
|
3774 |
#doesNotUnderstand: message. |
|
3775 |
Here, we raise another signal which usually enters the debugger. |
|
3776 |
You can of course redefine #doesNotUnderstand: in your classes |
|
3777 |
to implement message delegation, |
|
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
3778 |
or handle the MessageNotUnderstood exception gracefully." |
5755 | 3779 |
|
3780 |
<context: #return> |
|
3781 |
||
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
3782 |
^ MessageNotUnderstood raiseRequestWith:aMessage |
5755 | 3783 |
! |
3784 |
||
3785 |
elementBoundsError |
|
3786 |
"{ Pragma: +optSpace }" |
|
3787 |
||
3788 |
"report an error that badElement is out of bounds |
|
3789 |
(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
|
3790 |
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
|
3791 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3792 |
^ ElementBoundsError raise |
5755 | 3793 |
|
3794 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
3795 |
! |
|
3796 |
||
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3797 |
elementBoundsError:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3798 |
"{ Pragma: +optSpace }" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3799 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3800 |
"report an error that aValue is not valid as element |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3801 |
(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
|
3802 |
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
|
3803 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3804 |
^ ElementBoundsError raiseWith:aValue |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3805 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3806 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3807 |
! |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3808 |
|
5755 | 3809 |
elementNotCharacter |
3810 |
"{ Pragma: +optSpace }" |
|
3811 |
||
3812 |
"report an error that object to be stored is no Character. |
|
3813 |
(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
|
3814 |
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
|
3815 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3816 |
^ ElementBoundsError raise |
5755 | 3817 |
|
3818 |
"Modified: 8.5.1996 / 09:12:49 / cg" |
|
3819 |
! |
|
3820 |
||
3821 |
elementNotInteger |
|
3822 |
"{ Pragma: +optSpace }" |
|
3823 |
||
3824 |
"report an error that object to be stored is not Integer. |
|
3825 |
(in collections that store integers only). |
|
3826 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3827 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3828 |
^ ElementBoundsError raise |
5755 | 3829 |
|
3830 |
"Modified: 8.5.1996 / 09:12:51 / cg" |
|
3831 |
! |
|
3832 |
||
3833 |
error |
|
3834 |
"{ Pragma: +optSpace }" |
|
3835 |
||
3836 |
<context: #return> |
|
3837 |
||
3838 |
"report error that an error occured. |
|
3839 |
The error is reported by raising the Error exception, |
|
3840 |
which is non-proceedable. |
|
3841 |
If no handler has been setup, a debugger is entered." |
|
3842 |
||
3843 |
Error raiseWith:#error: |
|
3844 |
||
3845 |
" |
|
3846 |
nil error |
|
3847 |
" |
|
3848 |
||
3849 |
"Modified: / 8.5.1996 / 09:13:01 / cg" |
|
3850 |
"Modified: / 2.8.1999 / 17:00:19 / stefan" |
|
3851 |
! |
|
3852 |
||
3853 |
error:aString |
|
3854 |
"{ Pragma: +optSpace }" |
|
3855 |
||
3856 |
<context: #return> |
|
3857 |
||
3858 |
"Raise an error with error message aString. |
|
3859 |
The error is reported by raising the Error exception, |
|
3860 |
which is non-proceedable. |
|
3861 |
If no handler has been setup, a debugger is entered." |
|
3862 |
||
3863 |
Error raiseWith:#error: errorString:aString |
|
3864 |
||
3865 |
" |
|
3866 |
nil error:' bad bad bad' |
|
3867 |
" |
|
3868 |
||
3869 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
3870 |
! |
|
3871 |
||
3872 |
error:aString mayProceed:mayProceed |
|
3873 |
"{ Pragma: +optSpace }" |
|
3874 |
||
3875 |
"enter debugger with error-message aString. |
|
3876 |
The error is reported by raising either the |
|
3877 |
non-proceedable Error exception, |
|
3878 |
or the ProceedableError exception." |
|
3879 |
||
3880 |
mayProceed ifTrue:[ |
|
6654 | 3881 |
^ ProceedableError raiseRequestWith:#error: errorString:aString |
5755 | 3882 |
]. |
3883 |
||
3884 |
Error raiseWith:#error: errorString:aString |
|
3885 |
||
3886 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
3887 |
! |
|
3888 |
||
6900 | 3889 |
errorInvalidFormat |
3890 |
"{ Pragma: +optSpace }" |
|
3891 |
||
3892 |
<context: #return> |
|
3893 |
||
3894 |
"report an error that some conversion to/from string representation failed |
|
3895 |
typically when converting numbers, date, time etc." |
|
3896 |
||
3897 |
^ ConversionError raiseErrorString:'invalid format' |
|
3898 |
! |
|
3899 |
||
5755 | 3900 |
errorKeyNotFound:aKey |
3901 |
"{ Pragma: +optSpace }" |
|
3902 |
||
3903 |
"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
|
3904 |
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
|
3905 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3906 |
^ KeyNotFoundError raiseRequestWith:aKey |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3907 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3908 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3909 |
Dictionary new at:#nonExistantElement |
5755 | 3910 |
" |
3911 |
! |
|
3912 |
||
3913 |
errorNotFound |
|
3914 |
"{ Pragma: +optSpace }" |
|
3915 |
||
3916 |
"report an error that no element was found in a collection. |
|
3917 |
The error is reported by raising the NotFoundSignal exception." |
|
3918 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
3919 |
^ NotFoundError raiseRequestWith:nil |
5755 | 3920 |
|
3921 |
"Modified: / 8.5.1996 / 09:13:11 / cg" |
|
3922 |
"Modified: / 26.7.1999 / 10:51:50 / stefan" |
|
3923 |
! |
|
3924 |
||
6874 | 3925 |
errorNotFound:errorString |
3926 |
"{ Pragma: +optSpace }" |
|
3927 |
||
3928 |
"report an error that no element was found in a collection. |
|
3929 |
The error is reported by raising the NotFoundSignal exception." |
|
3930 |
||
3931 |
^ NotFoundError raiseErrorString:errorString |
|
3932 |
! |
|
3933 |
||
5755 | 3934 |
errorSignal |
3935 |
^ self class errorSignal |
|
3936 |
||
3937 |
"Created: / 19.6.1998 / 02:32:32 / cg" |
|
3938 |
! |
|
3939 |
||
3940 |
halt |
|
3941 |
"{ Pragma: +optSpace }" |
|
3942 |
||
3943 |
"enter debugger with halt-message. |
|
3944 |
The error is reported by raising the HaltSignal exception." |
|
3945 |
||
6716
7e2bac4221d1
allow for halts to be ignored
Claus Gittinger <cg@exept.de>
parents:
6708
diff
changeset
|
3946 |
(Smalltalk at:#IgnoreHalt ifAbsent:false) == true ifTrue:[^ self]. |
6221 | 3947 |
^ HaltInterrupt raiseRequestWith:#halt |
3948 |
||
5755 | 3949 |
"Modified: / 2.8.1999 / 17:00:29 / stefan" |
6221 | 3950 |
"Modified: / 17.11.2001 / 22:47:44 / cg" |
5755 | 3951 |
! |
3952 |
||
3953 |
halt:aString |
|
3954 |
"{ Pragma: +optSpace }" |
|
3955 |
||
3956 |
"enter debugger with halt-message. |
|
3957 |
The error is reported by raising the HaltSignal exception." |
|
3958 |
||
6716
7e2bac4221d1
allow for halts to be ignored
Claus Gittinger <cg@exept.de>
parents:
6708
diff
changeset
|
3959 |
(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
|
3960 |
^ HaltInterrupt raiseRequestWith:#halt: errorString:aString |
5755 | 3961 |
|
3962 |
"Modified: 8.5.1996 / 09:13:23 / cg" |
|
3963 |
! |
|
3964 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3965 |
handlerForSignal:exceptionHandler context:theContext originator:originator |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3966 |
" 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
|
3967 |
|
7566 | 3968 |
thisContext isRecursive ifTrue:[^ nil]. |
3969 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3970 |
'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
|
3971 |
' context: ' print. theContext printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3972 |
' originator: ' print. originator printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3973 |
' sender: ' print. thisContext sender printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3974 |
|
7566 | 3975 |
"/ MiniDebugger enter:thisContext withMessage:'oops' mayProceed:true. |
3976 |
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
|
3977 |
! |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
3978 |
|
5755 | 3979 |
implementedBySubclass |
3980 |
"{ Pragma: +optSpace }" |
|
3981 |
||
3982 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
3983 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
3984 |
^ self subclassResponsibility:'method must be reimplemented in ST/V subclass' |
5755 | 3985 |
! |
3986 |
||
3987 |
indexNotInteger |
|
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 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
3994 |
^ NonIntegerIndexError raiseRequestWith:nil |
5755 | 3995 |
|
3996 |
"Modified: / 8.5.1996 / 09:13:37 / cg" |
|
3997 |
"Modified: / 26.7.1999 / 10:57:43 / stefan" |
|
3998 |
! |
|
3999 |
||
4000 |
indexNotInteger:anIndex |
|
4001 |
"{ Pragma: +optSpace }" |
|
4002 |
||
4003 |
"report an error that index is not an Integer. |
|
4004 |
(when accessing collections indexed by an integer key). |
|
4005 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4006 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4007 |
^ NonIntegerIndexError raiseRequestWith:anIndex |
5755 | 4008 |
|
4009 |
"Created: / 16.5.1998 / 19:39:41 / cg" |
|
4010 |
! |
|
4011 |
||
7216 | 4012 |
indexNotIntegerOrOutOfBounds:index |
4013 |
"{ Pragma: +optSpace }" |
|
4014 |
||
4015 |
"report an error that index is either non-integral or out of bounds" |
|
4016 |
||
4017 |
index isInteger ifFalse:[ |
|
4018 |
^ self indexNotInteger:index |
|
4019 |
]. |
|
4020 |
^ self subscriptBoundsError:index |
|
4021 |
! |
|
4022 |
||
5755 | 4023 |
integerCheckError |
4024 |
"{ Pragma: +optSpace }" |
|
4025 |
||
4026 |
"generated when a variable declared with an integer type gets a bad |
|
4027 |
value assigned" |
|
4028 |
||
4029 |
^ self error:'bad assign of ' , self printString , |
|
6654 | 4030 |
' (' , self class name , ') to integer-typed variable' |
5755 | 4031 |
! |
4032 |
||
4033 |
invalidCodeObject |
|
4034 |
"{ Pragma: +optSpace }" |
|
4035 |
||
4036 |
self error:'not an executable code object' |
|
4037 |
||
4038 |
"Created: 1.8.1997 / 00:16:44 / cg" |
|
4039 |
! |
|
4040 |
||
4041 |
invalidMessage |
|
4042 |
"{ Pragma: +optSpace }" |
|
4043 |
||
4044 |
"this is sent by ST/V code - its the same as #shouldNotImplement" |
|
4045 |
||
4046 |
^ self shouldNotImplement |
|
4047 |
! |
|
4048 |
||
4049 |
mustBeRectangle |
|
4050 |
"{ Pragma: +optSpace }" |
|
4051 |
||
4052 |
"report an argument-not-rectangle-error" |
|
4053 |
||
4054 |
^ self error:'argument must be a Rectangle' |
|
4055 |
! |
|
4056 |
||
4057 |
mustBeString |
|
4058 |
"{ Pragma: +optSpace }" |
|
4059 |
||
4060 |
"report an argument-not-string-error" |
|
4061 |
||
4062 |
^ self error:'argument must be a String' |
|
4063 |
! |
|
4064 |
||
4065 |
notIndexed |
|
4066 |
"{ Pragma: +optSpace }" |
|
4067 |
||
4068 |
<context: #return> |
|
4069 |
||
4070 |
"report an error that receiver has no indexed instance variables. |
|
4071 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4072 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4073 |
^ SubscriptOutOfBoundsError |
6654 | 4074 |
raiseErrorString:'receiver has no indexed variables' |
5755 | 4075 |
|
4076 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
|
4077 |
! |
|
4078 |
||
4079 |
openDebuggerOnException:ex |
|
4080 |
"{ Pragma: +optSpace }" |
|
4081 |
||
4082 |
"enter the debugger on some unhandled exception" |
|
4083 |
||
6884 | 4084 |
|msgString debugger answer| |
5755 | 4085 |
|
7208 | 4086 |
msgString := ex description. |
5755 | 4087 |
" |
4088 |
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
|
4089 |
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
|
4090 |
ignore will raise an AbortOperationRequest. |
5755 | 4091 |
" |
4092 |
Debugger isNil ifTrue:[ |
|
6840 | 4093 |
msgString := 'Error: ' , msgString. |
6654 | 4094 |
|
7562
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4095 |
thisContext isRecursive ifTrue:[ |
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4096 |
msgString errorPrintCR. |
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4097 |
Smalltalk fatalAbort:'recursive unhandled exception' |
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4098 |
]. |
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4099 |
|
6654 | 4100 |
Smalltalk isStandAloneApp ifTrue:[ |
7562
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4101 |
(Dialog notNil and:[Screen default notNil]) ifTrue:[ |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4102 |
AbortOperationRequest isHandled ifTrue:[ |
7208 | 4103 |
answer := OptionBox |
4104 |
request:msgString |
|
4105 |
label:msgString |
|
4106 |
buttonLabels:#('Ignore' 'Abort' 'Exit') |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4107 |
values:#(ignore abort exit) |
7208 | 4108 |
default:#exit. |
4109 |
] ifFalse:[ |
|
4110 |
answer := OptionBox |
|
4111 |
request:msgString |
|
4112 |
label:msgString |
|
4113 |
buttonLabels:#('Ignore' 'Exit') |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4114 |
values:#(ignore exit) |
7208 | 4115 |
default:#exit. |
4116 |
]. |
|
7562
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4117 |
|
6884 | 4118 |
answer == #abort ifTrue:[ |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4119 |
^ AbortOperationRequest raiseRequest |
6884 | 4120 |
]. |
7208 | 4121 |
answer == #ignore ifTrue:[ |
6884 | 4122 |
^ nil |
4123 |
]. |
|
6654 | 4124 |
]. |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4125 |
"don't output the message, if its a CTRL-C (userInterrupt)" |
6845
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4126 |
ex signal == NoHandlerError ifTrue:[ |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4127 |
ex parameter signal == UserInterrupt ifTrue:[ |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4128 |
OperatingSystem exit:130 |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4129 |
]. |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4130 |
]. |
6654 | 4131 |
msgString errorPrintCR. |
4132 |
OperatingSystem exit:1 |
|
4133 |
]. |
|
4134 |
||
4135 |
msgString errorPrintCR. |
|
4136 |
Smalltalk fatalAbort:'no Debugger defined' |
|
5755 | 4137 |
]. |
4138 |
||
4139 |
" |
|
4140 |
find an appropriate debugger to use |
|
4141 |
" |
|
4142 |
debugger := self appropriateDebugger:(thisContext selector). |
|
4143 |
debugger isNil ifTrue:[ |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4144 |
^ AbortOperationRequest raiseRequest |
5755 | 4145 |
]. |
4146 |
||
4147 |
^ debugger |
|
6654 | 4148 |
enter:ex suspendedContext |
4149 |
withMessage:msgString |
|
4150 |
mayProceed:(ex mayProceed). |
|
5755 | 4151 |
|
4152 |
"Modified: 24.7.1997 / 10:09:20 / cg" |
|
4153 |
! |
|
4154 |
||
4155 |
primitiveFailed |
|
4156 |
"{ Pragma: +optSpace }" |
|
4157 |
||
4158 |
"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
|
4159 |
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
|
4160 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4161 |
|sender| |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4162 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4163 |
sender := thisContext sender. |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4164 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4165 |
^ PrimitiveFailure raiseRequestWith:(Message selector:sender selector arguments:sender args) |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4166 |
in:sender. |
5755 | 4167 |
|
6005 | 4168 |
" |
4169 |
1234 primitiveFailed |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4170 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4171 |
[ |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4172 |
ExternalBytes new basicAt:40 |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4173 |
] on:PrimitiveFailure do:[:ex| |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4174 |
ex inspect |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4175 |
] |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4176 |
" |
5755 | 4177 |
! |
4178 |
||
6005 | 4179 |
primitiveFailed:messageString |
4180 |
"{ Pragma: +optSpace }" |
|
4181 |
||
4182 |
"report an error that some primitive code failed. |
|
4183 |
The error is reported by raising the PrimitiveFailureSignal exception." |
|
4184 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4185 |
^ PrimitiveFailure raiseRequestWith:nil errorString:messageString |
6005 | 4186 |
|
4187 |
" |
|
4188 |
1234 primitiveFailed:'this is a test' |
|
4189 |
" |
|
4190 |
! |
|
4191 |
||
6815 | 4192 |
shouldImplement |
4193 |
"{ Pragma: +optSpace }" |
|
4194 |
||
4195 |
"report an error that this message should be implemented. |
|
4196 |
This is send by automatically generated method bodies" |
|
4197 |
||
4198 |
^ self error:'method not yet implemented by class' |
|
4199 |
! |
|
4200 |
||
5755 | 4201 |
shouldNotImplement |
4202 |
"{ Pragma: +optSpace }" |
|
4203 |
||
4204 |
"report an error that this message should not be implemented" |
|
4205 |
||
4206 |
^ self error:'method not appropriate for this class' |
|
4207 |
||
4208 |
"Modified: 8.5.1996 / 09:09:44 / cg" |
|
4209 |
! |
|
4210 |
||
4211 |
subclassResponsibility |
|
4212 |
"{ Pragma: +optSpace }" |
|
4213 |
||
4214 |
"report an error that this message should have been reimplemented in a |
|
4215 |
subclass" |
|
4216 |
||
7334 | 4217 |
^ SubclassResponsibilityError raiseRequest |
5755 | 4218 |
! |
4219 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4220 |
subclassResponsibility:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4221 |
"{ Pragma: +optSpace }" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4222 |
|
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4223 |
"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
|
4224 |
|
7334 | 4225 |
^ SubclassResponsibilityError raiseRequestErrorString:msg |
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4226 |
! |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4227 |
|
5755 | 4228 |
subscriptBoundsError |
4229 |
"{ Pragma: +optSpace }" |
|
4230 |
||
4231 |
"report an error that some index is out of bounds. |
|
4232 |
(when accessing indexable collections). |
|
4233 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4234 |
||
4235 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:nil |
|
4236 |
||
4237 |
"Modified: / 26.7.1996 / 16:45:42 / cg" |
|
4238 |
"Modified: / 26.7.1999 / 10:58:27 / stefan" |
|
4239 |
! |
|
4240 |
||
4241 |
subscriptBoundsError:anIndex |
|
4242 |
"{ Pragma: +optSpace }" |
|
4243 |
||
4244 |
"report an error that anIndex is out of bounds. |
|
4245 |
(when accessing indexable collections). |
|
4246 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4247 |
||
6221 | 4248 |
^ SubscriptOutOfBoundsError |
6654 | 4249 |
raiseRequestWith:anIndex |
4250 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
5755 | 4251 |
|
6221 | 4252 |
"Modified: / 17.11.2001 / 22:49:56 / cg" |
5755 | 4253 |
! |
4254 |
||
4255 |
typeCheckError |
|
4256 |
"{ Pragma: +optSpace }" |
|
4257 |
||
4258 |
"generated when a variable declared with a type hint gets a bad |
|
4259 |
value assigned" |
|
4260 |
||
4261 |
^ self error:'bad assign of ' , self printString , |
|
6654 | 4262 |
' (' , self class name , ') to typed variable' |
5755 | 4263 |
! ! |
4264 |
||
4265 |
!Object methodsFor:'evaluation'! |
|
4266 |
||
4267 |
value |
|
4268 |
"return the receiver itself. |
|
4269 |
This allows every object to be used where blocks or valueHolders |
|
4270 |
are typically used, and allows for valueHolders and blocks to be |
|
4271 |
used interchangably in some situations. |
|
4272 |
||
4273 |
Time will show, if this is a good idea or leads to sloppy programming |
|
4274 |
style ... (the idea was borrowed from the Self language). |
|
4275 |
||
4276 |
WARNING: dont 'optimize' away ifXXX: blocks |
|
6654 | 4277 |
(i.e. do NOT replace |
4278 |
foo ifTrue:[var1] ifFalse:[var2] |
|
4279 |
by: |
|
4280 |
foo ifTrue:var1 ifFalse:var2 |
|
4281 |
) |
|
4282 |
- the compilers will only generate inline code for the if, |
|
4283 |
iff the argument(s) are blocks - otherwise, a true send is |
|
4284 |
generated. |
|
4285 |
This 'oprimization' will work semantically correct, |
|
4286 |
but execute SLOWER instead." |
|
5755 | 4287 |
|
4288 |
^ self |
|
4289 |
||
4290 |
" |
|
4291 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
|
4292 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
4293 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
4294 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
4295 |
" |
|
4296 |
||
4297 |
"DO NOT DO THIS (its slower) |
|
7458 | 4298 |
(1 > 4) ifTrue:a ifFalse:b |
5755 | 4299 |
|
4300 |
USE (the compiler optimizes blocks in if/while): |
|
7458 | 4301 |
(1 > 4) ifTrue:[a] ifFalse:[b] |
5755 | 4302 |
" |
4303 |
||
4304 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
4305 |
! ! |
|
4306 |
||
4307 |
!Object methodsFor:'finalization'! |
|
4308 |
||
4309 |
disposed |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4310 |
"OBSOLETE INTERFACE: use #finalize |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4311 |
this is invoked for objects which have been registered |
5755 | 4312 |
in a Registry, when the original object dies. |
4313 |
Subclasses may redefine this method" |
|
4314 |
||
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4315 |
<resource: #obsolete> |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4316 |
|
5755 | 4317 |
^ self |
4318 |
! |
|
4319 |
||
4320 |
executor |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4321 |
"Return the object which does the finalization for me. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4322 |
This interface is also VW & Sqeak compatible," |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4323 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4324 |
"for now, send #shallowCopyForFinalization, to be compatible with |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4325 |
classes designed for old ST/X versions" |
5755 | 4326 |
|
4327 |
^ self shallowCopyForFinalization |
|
4328 |
! |
|
4329 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4330 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4331 |
"answer a Registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4332 |
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
|
4333 |
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
|
4334 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4335 |
^ FinalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4336 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4337 |
|
5755 | 4338 |
finalize |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4339 |
"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
|
4340 |
in a Registry, when the original object dies. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4341 |
Subclasses may redefine this method |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4342 |
This interface is also VW-compatible" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4343 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4344 |
"send #disposed for compatibility with existing classes that still |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4345 |
implement the obsolete #disposed message" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4346 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4347 |
^ self disposed |
5755 | 4348 |
! |
4349 |
||
4350 |
reRegisterForFinalization |
|
4351 |
"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
|
4352 |
This will create a new executor, which will receive a #finalize message when |
5755 | 4353 |
the receiver is garbage collected." |
4354 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4355 |
self finalizationLobby registerChange:self |
5755 | 4356 |
! |
4357 |
||
4358 |
registerForFinalization |
|
4359 |
"register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4360 |
Once registered, the executor of the receiver will receive a #finalize message when |
5755 | 4361 |
the receiver is garbage collected." |
4362 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4363 |
self finalizationLobby register:self |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4364 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4365 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4366 |
shallowCopyForFinalization |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4367 |
"OBSOLETE INTERFACE: use #executor. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4368 |
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
|
4369 |
(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
|
4370 |
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
|
4371 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4372 |
<resource: #obsolete> |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4373 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4374 |
^ self shallowCopy |
5755 | 4375 |
! |
4376 |
||
4377 |
unregisterForFinalization |
|
4378 |
"unregister mySelf from later finalization" |
|
4379 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4380 |
self finalizationLobby unregister:self |
5755 | 4381 |
! ! |
4382 |
||
4383 |
!Object methodsFor:'initialization'! |
|
4384 |
||
4385 |
initialize |
|
4386 |
"just to ignore initialize to objects which do not need it" |
|
4387 |
||
4388 |
^ self |
|
4389 |
! ! |
|
4390 |
||
4391 |
!Object methodsFor:'interest'! |
|
4392 |
||
4393 |
addInterest:anInterest |
|
4394 |
"install an interest forwarder. |
|
4395 |
Here, we use the nonWeakDependencies." |
|
4396 |
||
4397 |
self addNonWeakDependent:anInterest |
|
4398 |
||
4399 |
"Created: 14.10.1996 / 22:27:34 / stefan" |
|
4400 |
! |
|
4401 |
||
4402 |
expressInterestIn:aspect for:anObject sendBack:aSelector |
|
4403 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
4404 |
changes aspect." |
|
4405 |
||
4406 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
4407 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4408 |
||
4409 |
self addInterest:(InterestConverter |
|
6654 | 4410 |
destination:anObject |
4411 |
selector:aSelector |
|
4412 |
aspect:aspect) |
|
5755 | 4413 |
|
4414 |
" |
|
4415 |
|p b| |
|
4416 |
||
4417 |
b := [Transcript showCR:' -> the point changed']. |
|
4418 |
||
4419 |
p := Point new. |
|
4420 |
Transcript showCR:'interest in #foo:'. |
|
4421 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4422 |
p x:1. |
|
4423 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
4424 |
p changed:#bar. |
|
4425 |
Transcript cr. |
|
4426 |
||
4427 |
Delay waitForSeconds:1. |
|
4428 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
4429 |
p changed:#foo. |
|
4430 |
Transcript cr. |
|
4431 |
||
4432 |
Delay waitForSeconds:1. |
|
4433 |
Transcript showCR:'no more interest in #foo:'. |
|
4434 |
p retractInterestIn:#foo for:b. |
|
4435 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4436 |
p changed:#foo. |
|
4437 |
Transcript cr. |
|
4438 |
||
4439 |
Delay waitForSeconds:1. |
|
4440 |
Transcript showCR:'interest in #bar now:'. |
|
4441 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
4442 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4443 |
p changed:#foo. |
|
4444 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
4445 |
p changed:#bar. |
|
4446 |
Transcript cr. |
|
4447 |
||
4448 |
Delay waitForSeconds:1. |
|
4449 |
Transcript showCR:'interest in #foo now:'. |
|
4450 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4451 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
4452 |
p changed:#foo. |
|
4453 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
4454 |
p changed:#bar. |
|
4455 |
Transcript cr. |
|
4456 |
||
4457 |
Delay waitForSeconds:1. |
|
4458 |
Transcript showCR:'no more interests:'. |
|
4459 |
p retractInterestsFor:b. |
|
4460 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4461 |
p changed:#foo. |
|
4462 |
Transcript showCR:'now changing #bar... (expect no notification)'. |
|
4463 |
p changed:#bar. |
|
4464 |
Transcript cr. |
|
4465 |
||
4466 |
p release. |
|
4467 |
" |
|
4468 |
||
4469 |
"Created: 19.4.1996 / 10:26:22 / cg" |
|
4470 |
"Modified: 19.4.1996 / 12:34:08 / cg" |
|
4471 |
"Modified: 14.10.1996 / 22:28:20 / stefan" |
|
4472 |
! |
|
4473 |
||
4474 |
interests |
|
4475 |
"return a Collection of interests - empty if there is none. |
|
4476 |
Here, we use the nonWeakDependents for interests." |
|
4477 |
||
4478 |
^ self nonWeakDependents |
|
4479 |
||
4480 |
"Created: / 14.10.1996 / 22:20:51 / stefan" |
|
4481 |
"Modified: / 30.1.1998 / 14:07:35 / cg" |
|
4482 |
! |
|
4483 |
||
4484 |
interestsFor:someOne |
|
4485 |
"return a collection of interests of someOne - empty if there is none." |
|
4486 |
||
4487 |
|coll deps| |
|
4488 |
||
4489 |
deps := self interests. |
|
4490 |
deps size == 0 ifTrue:[^ #()]. |
|
4491 |
||
4492 |
coll := IdentitySet new. |
|
4493 |
||
4494 |
deps do:[:dep | |
|
6654 | 4495 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
4496 |
dep destination == someOne ifTrue:[ |
|
4497 |
coll add:dep. |
|
4498 |
] |
|
4499 |
] |
|
5755 | 4500 |
]. |
4501 |
^ coll |
|
4502 |
||
4503 |
"Created: / 30.1.1998 / 14:02:26 / cg" |
|
4504 |
"Modified: / 30.1.1998 / 14:08:24 / cg" |
|
4505 |
! |
|
4506 |
||
4507 |
onChangeEvaluate:aBlock |
|
4508 |
"arrange for aBlock to be evaluated whenever the receiver changes." |
|
4509 |
||
4510 |
^ self onChangeSend:#value to:aBlock |
|
4511 |
||
4512 |
"Created: / 29.1.1999 / 16:01:22 / cg" |
|
4513 |
! |
|
4514 |
||
7345
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4515 |
onChangeSend:aSelector to:anObject |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4516 |
"arrange for aSelector to be sent to anObject whenever the receiver |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4517 |
changes." |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4518 |
|
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4519 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4520 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4521 |
|
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4522 |
((self interests ? #()) |
7539 | 4523 |
contains:[:anInterest | |
4524 |
(anInterest isKindOf:InterestConverter) |
|
4525 |
and:[ anInterest destination == anObject |
|
4526 |
and:[ anInterest selector == aSelector]] |
|
7345
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4527 |
]) |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4528 |
ifTrue:[^ self]. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4529 |
|
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4530 |
self addInterest:(InterestConverter |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4531 |
destination:anObject |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4532 |
selector:aSelector) |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4533 |
|
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4534 |
" |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4535 |
|p b| |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4536 |
|
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4537 |
b := [Transcript showCR:'the point changed']. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4538 |
|
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4539 |
p := Point new. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4540 |
p onChangeSend:#value to:b. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4541 |
p x:1. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4542 |
Transcript showCR:'now changing'. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4543 |
p changed. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4544 |
Transcript cr. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4545 |
|
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4546 |
Delay waitForSeconds:1. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4547 |
Transcript showCR:'now changing'. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4548 |
p changed. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4549 |
Transcript cr. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4550 |
|
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4551 |
Delay waitForSeconds:1. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4552 |
Transcript showCR:'no more interest'. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4553 |
p retractInterestsFor:b. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4554 |
Transcript showCR:'now changing again'. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4555 |
p changed. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4556 |
Transcript cr. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4557 |
|
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4558 |
Delay waitForSeconds:1. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4559 |
Transcript showCR:'interest again'. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4560 |
p onChangeSend:#value to:b. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4561 |
Transcript showCR:'now changing again'. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4562 |
p changed. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4563 |
Transcript cr. |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4564 |
" |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4565 |
|
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4566 |
"Created: 19.4.1996 / 10:26:38 / cg" |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4567 |
"Modified: 19.4.1996 / 12:34:26 / cg" |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4568 |
"Modified: 14.10.1996 / 22:28:27 / stefan" |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4569 |
! |
f6a5cd6db5c5
onChangeSend:aSelector to:anObject add the interrests only if the selector for the object not
penk
parents:
7344
diff
changeset
|
4570 |
|
5755 | 4571 |
removeInterest:anInterest |
4572 |
"remove an interest forwarder. |
|
4573 |
Here, we use the nonWeakDependencies." |
|
4574 |
||
4575 |
self removeNonWeakDependent:anInterest |
|
4576 |
||
4577 |
"Created: 14.10.1996 / 22:21:59 / stefan" |
|
4578 |
! |
|
4579 |
||
4580 |
retractInterestIn:aspect for:someOne |
|
4581 |
"remove the interest of someOne in the receiver changing aspect |
|
4582 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
4583 |
||
4584 |
"/ for now, remove the interestConverter. |
|
4585 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4586 |
||
4587 |
"/ cannot removeDependent within the loop - the collection rehashes |
|
4588 |
||
4589 |
|deps coll| |
|
4590 |
||
4591 |
deps := self interests. |
|
4592 |
deps size ~~ 0 ifTrue:[ |
|
6654 | 4593 |
coll := IdentitySet new. |
4594 |
||
4595 |
deps do:[:dep | |
|
4596 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
|
4597 |
dep destination == someOne ifTrue:[ |
|
4598 |
dep aspect == aspect ifTrue:[ |
|
4599 |
self removeInterest:dep. |
|
4600 |
^ self |
|
4601 |
] |
|
4602 |
] |
|
4603 |
] |
|
4604 |
]. |
|
4605 |
coll do:[:dep | |
|
4606 |
self removeInterest:dep. |
|
4607 |
]. |
|
5755 | 4608 |
]. |
4609 |
||
4610 |
||
4611 |
" |
|
4612 |
|p b| |
|
4613 |
||
4614 |
b := [Transcript showCR:'the point changed']. |
|
4615 |
||
4616 |
p := Point new. |
|
4617 |
Transcript showCR:'interest in #foo'. |
|
4618 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4619 |
p x:1. |
|
4620 |
Transcript showCR:'now changing #bar'. |
|
4621 |
p changed:#bar. |
|
4622 |
Transcript cr. |
|
4623 |
||
4624 |
Delay waitForSeconds:1. |
|
4625 |
Transcript showCR:'now changing #foo'. |
|
4626 |
p changed:#foo. |
|
4627 |
Transcript cr. |
|
4628 |
||
4629 |
Delay waitForSeconds:1. |
|
4630 |
Transcript showCR:'no more interest in #foo'. |
|
4631 |
p retractInterestIn:#foo for:b. |
|
4632 |
Transcript showCR:'now changing #foo'. |
|
4633 |
p changed:#foo. |
|
4634 |
Transcript cr. |
|
4635 |
||
4636 |
Delay waitForSeconds:1. |
|
4637 |
Transcript showCR:'interest in #bar now'. |
|
4638 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
4639 |
Transcript showCR:'now changing #foo'. |
|
4640 |
p changed:#foo. |
|
4641 |
Transcript showCR:'now changing #bar'. |
|
4642 |
p changed:#bar. |
|
4643 |
Transcript cr. |
|
4644 |
||
4645 |
Delay waitForSeconds:1. |
|
4646 |
Transcript showCR:'interest in #foo now'. |
|
4647 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4648 |
Transcript showCR:'now changing #foo'. |
|
4649 |
p changed:#foo. |
|
4650 |
Transcript showCR:'now changing #bar'. |
|
4651 |
p changed:#bar. |
|
4652 |
Transcript cr. |
|
4653 |
||
4654 |
Delay waitForSeconds:1. |
|
4655 |
Transcript showCR:'no more interests'. |
|
4656 |
p retractInterestsFor:b. |
|
4657 |
Transcript showCR:'now changing #foo'. |
|
4658 |
p changed:#foo. |
|
4659 |
Transcript showCR:'now changing #bar'. |
|
4660 |
p changed:#bar. |
|
4661 |
Transcript cr. |
|
4662 |
" |
|
4663 |
||
4664 |
"Created: / 19.4.1996 / 10:27:11 / cg" |
|
4665 |
"Modified: / 14.10.1996 / 22:21:19 / stefan" |
|
4666 |
"Modified: / 30.1.1998 / 14:05:34 / cg" |
|
4667 |
! |
|
4668 |
||
4669 |
retractInterestsFor:someOne |
|
4670 |
"remove the interest of someOne in the receiver |
|
4671 |
(as installed with #onChangeSend:to:)." |
|
4672 |
||
4673 |
"/ for now, remove the interestConverter. |
|
4674 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4675 |
||
4676 |
|coll deps| |
|
4677 |
||
4678 |
"/ cannot removeDependent within the loop - the collection rehashes |
|
4679 |
||
4680 |
deps := self interests. |
|
4681 |
deps size ~~ 0 ifTrue:[ |
|
6654 | 4682 |
coll := IdentitySet new. |
4683 |
||
4684 |
deps do:[:dep | |
|
4685 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
|
4686 |
dep destination == someOne ifTrue:[ |
|
4687 |
coll add:dep. |
|
4688 |
] |
|
4689 |
] |
|
4690 |
]. |
|
4691 |
coll do:[:dep | |
|
4692 |
self removeInterest:dep. |
|
4693 |
]. |
|
5755 | 4694 |
]. |
4695 |
||
4696 |
||
4697 |
||
4698 |
" |
|
4699 |
|p b| |
|
4700 |
||
4701 |
b := [Transcript showCR:'the point changed']. |
|
4702 |
||
4703 |
p := Point new. |
|
4704 |
p onChangeSend:#value to:b. |
|
4705 |
p x:1. |
|
4706 |
Transcript showCR:'now changing'. |
|
4707 |
p changed. |
|
4708 |
Transcript cr. |
|
4709 |
||
4710 |
Delay waitForSeconds:1. |
|
4711 |
Transcript showCR:'now changing'. |
|
4712 |
p changed. |
|
4713 |
Transcript cr. |
|
4714 |
||
4715 |
Delay waitForSeconds:1. |
|
4716 |
Transcript showCR:'no more interest'. |
|
4717 |
p retractInterestsFor:b. |
|
4718 |
Transcript showCR:'now changing again'. |
|
4719 |
p changed. |
|
4720 |
Transcript cr. |
|
4721 |
||
4722 |
Delay waitForSeconds:1. |
|
4723 |
Transcript showCR:'interest again'. |
|
4724 |
p onChangeSend:#value to:b. |
|
4725 |
Transcript showCR:'now changing again'. |
|
4726 |
p changed. |
|
4727 |
Transcript cr. |
|
4728 |
" |
|
4729 |
||
4730 |
"Created: / 19.4.1996 / 10:23:46 / cg" |
|
4731 |
"Modified: / 14.10.1996 / 22:21:25 / stefan" |
|
4732 |
"Modified: / 30.1.1998 / 14:04:52 / cg" |
|
4733 |
! ! |
|
4734 |
||
4735 |
!Object methodsFor:'interrupt handling'! |
|
4736 |
||
4737 |
childSignalInterrupt |
|
4738 |
"death of a child process (unix process) - do nothing" |
|
4739 |
||
4740 |
^ self |
|
4741 |
! |
|
4742 |
||
4743 |
customInterrupt |
|
4744 |
"{ Pragma: +optSpace }" |
|
4745 |
||
4746 |
"a custom interrupt - but no handler has defined" |
|
4747 |
||
4748 |
self error:'custom interrupt' mayProceed:true |
|
4749 |
! |
|
4750 |
||
4751 |
errorInterrupt:errorID with:aParameter |
|
4752 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
4753 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
|
4754 |
which can be called from C subsystems to raise an (asynchronous) |
|
4755 |
error exception. |
|
4756 |
||
4757 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
4758 |
used from other C subsystems too, to upcast errors. |
|
4759 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
4760 |
IDs (currently) used: |
|
6654 | 4761 |
#DisplayError ..... x-error interrupt |
4762 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
5755 | 4763 |
" |
4764 |
||
6263
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4765 |
|handlers handler| |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4766 |
|
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4767 |
handlers := ObjectMemory registeredErrorInterruptHandlers. |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4768 |
handlers notNil ifTrue:[ |
6654 | 4769 |
handler := handlers at:errorID ifAbsent:nil. |
4770 |
handler notNil ifTrue:[ |
|
4771 |
"/ |
|
4772 |
"/ handler found; let it do whatever it wants ... |
|
4773 |
"/ |
|
4774 |
handler errorInterrupt:errorID with:aParameter. |
|
4775 |
^ self |
|
4776 |
]. |
|
5755 | 4777 |
]. |
4778 |
||
4779 |
"/ |
|
4780 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
4781 |
"/ |
|
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
4782 |
^ Error |
6654 | 4783 |
raiseRequestWith:errorID |
4784 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
5755 | 4785 |
! |
4786 |
||
4787 |
exceptionInterrupt |
|
4788 |
"{ Pragma: +optSpace }" |
|
4789 |
||
4790 |
"exception interrupt - enter debugger" |
|
4791 |
||
4792 |
self error:'exception Interrupt' mayProceed:true |
|
4793 |
! |
|
4794 |
||
4795 |
fpExceptionInterrupt |
|
4796 |
"{ Pragma: +optSpace }" |
|
4797 |
||
4798 |
"a floating point exception occured - this one |
|
4799 |
has to be handled differently since it comes asynchronous |
|
4800 |
on some machines (for example, on machines with a separate FPU |
|
4801 |
or superscalar architectures. Also, errors from within primitive code |
|
4802 |
(or library functions such as GL) are sent via the Unix-signal |
|
4803 |
mechanism this way." |
|
4804 |
||
4805 |
|where rec| |
|
4806 |
||
4807 |
where := thisContext sender. |
|
4808 |
rec := where receiver. |
|
4809 |
rec isNumber ifTrue:[ |
|
6654 | 4810 |
^ rec class |
4811 |
raise:#domainErrorSignal |
|
4812 |
receiver:rec |
|
4813 |
selector:where selector |
|
4814 |
arguments:(where args asArray) |
|
4815 |
errorString:'floating point exception' |
|
5755 | 4816 |
]. |
4817 |
||
4818 |
"/ could be in some C-library ... |
|
7402 | 4819 |
^ DomainError raise |
5755 | 4820 |
! |
4821 |
||
4822 |
internalError:msg |
|
4823 |
"{ Pragma: +optSpace }" |
|
4824 |
||
4825 |
"this is triggered, when VM hits some bad error, |
|
4826 |
such as corrupted class, corrupted method/selector array |
|
4827 |
etc. The argument string gives some more information on what happened. |
|
4828 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
|
4829 |
Its not guaranteed, that the system is in a working condition once |
|
4830 |
this error occurred ...." |
|
4831 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4832 |
VMInternalError raiseWith:self errorString:msg |
5755 | 4833 |
! |
4834 |
||
4835 |
ioInterrupt |
|
4836 |
"{ Pragma: +optSpace }" |
|
4837 |
||
4838 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
|
4839 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
4840 |
or it does not understand the ioInterrupt message. |
|
4841 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
4842 |
||
4843 |
self error:'I/O Interrupt - but no handler' mayProceed:true |
|
4844 |
! |
|
4845 |
||
4846 |
memoryInterrupt |
|
4847 |
"{ Pragma: +optSpace }" |
|
4848 |
||
4849 |
"out-of-memory interrupt and no handler - enter debugger" |
|
4850 |
||
4851 |
self error:'almost out of memory' mayProceed:true |
|
4852 |
! |
|
4853 |
||
4854 |
recursionInterrupt |
|
4855 |
"{ Pragma: +optSpace }" |
|
4856 |
||
4857 |
"recursion limit (actually: stack overflow) interrupt. |
|
4858 |
This interrupt is triggered, when a process stack grows above |
|
4859 |
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
|
4860 |
could be caught. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4861 |
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
|
4862 |
and the exception can be resumed. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4863 |
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
|
4864 |
is not proceedable. |
5755 | 4865 |
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
|
4866 |
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
|
4867 |
or debug for a while. |
5755 | 4868 |
If the signal is ignored, and the stack continues to grow, there |
4869 |
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
|
4870 |
terminates the process." |
5755 | 4871 |
|
7838
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4872 |
|con remaining sender nSkipped| |
5755 | 4873 |
|
4874 |
(con := thisContext) isRecursive ifFalse:[ |
|
4875 |
"/ Processor activeProcess usedStackSize < Processor activeProcess maximumStackSize ifTrue:[ |
|
4876 |
"/ "/ mhmh - it hit me, but I am not responsible ... |
|
4877 |
"/ 'Stray recursionInterrupt ...' infoPrintCR. |
|
4878 |
"/ ^ self |
|
4879 |
"/ ]. |
|
6654 | 4880 |
ObjectMemory infoPrinting ifTrue:[ |
4881 |
'Object [info]: recursionInterrupt from:' printCR. |
|
4882 |
con := con sender. |
|
4883 |
remaining := 50. |
|
4884 |
[con notNil and:[remaining > 0]] whileTrue:[ |
|
7838
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4885 |
sender := con sender. |
6654 | 4886 |
'| ' print. con fullPrint. |
7838
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4887 |
|
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4888 |
nSkipped := 0. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4889 |
[sender notNil and:[sender sender notNil |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4890 |
and:[sender selector == con selector |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4891 |
and:[sender sender selector == con selector |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4892 |
and:[sender method == con method]]]]] whileTrue:[ |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4893 |
nSkipped := nSkipped + 1. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4894 |
con := sender. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4895 |
sender := con sender. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4896 |
]. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4897 |
nSkipped > 0 ifTrue:[ |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4898 |
'| ... ***** ' print. nSkipped print. ' recursive contexts skipped *****' printCR. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4899 |
]. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4900 |
con := sender. |
6654 | 4901 |
remaining := remaining - 1 |
4902 |
]. |
|
4903 |
]. |
|
4904 |
^ RecursionInterruptSignal raiseSignal |
|
5755 | 4905 |
] |
4906 |
||
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4907 |
"Modified: / 10.11.2001 / 15:15:56 / cg" |
5755 | 4908 |
! |
4909 |
||
4910 |
schedulerInterrupt |
|
4911 |
"{ Pragma: +optSpace }" |
|
4912 |
||
4913 |
"scheduler interrupt (supposed to be sent to Processor). |
|
4914 |
If we arrive here, either the Processor does not understand it, |
|
4915 |
or it has been set to nil. In any case, this is a sign of some |
|
4916 |
big trouble. Enter debugger." |
|
4917 |
||
4918 |
self error:'schedulerInterrupt - but no Processor' mayProceed:true |
|
4919 |
! |
|
4920 |
||
4921 |
signalInterrupt:signalNumber |
|
4922 |
"{ Pragma: +optSpace }" |
|
4923 |
||
4924 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
|
4925 |
(SIGPIPE), others (SIGBUS) are rather fatal ... |
|
4926 |
In any case, IF a smalltalk-signal has been connected to the OS signal, |
|
4927 |
that one is raised. |
|
4928 |
Otherwise, a dialog is shown, asking the user on how to handle the |
|
4929 |
signal. |
|
4930 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
|
4931 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
4932 |
Currently (temporary kludge), these are passed as global variables." |
|
4933 |
||
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4934 |
|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
|
4935 |
action title screen| |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4936 |
|
5755 | 4937 |
"if there has been an ST-signal installed, use it ..." |
4938 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
4939 |
sig notNil ifTrue:[ |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4940 |
sig raiseSignalWith:signalNumber. |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4941 |
^ self. |
5755 | 4942 |
]. |
4943 |
||
4944 |
"/ if handled, raise OSSignalInterruptSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4945 |
OSSignalInterrupt isHandled ifTrue:[ |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4946 |
OSSignalInterrupt raiseRequestWith:signalNumber. |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4947 |
^ self. |
5755 | 4948 |
]. |
4949 |
||
4950 |
" |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4951 |
special case - SIGPWR: power failure - write a crash image and continue |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4952 |
- SIGHUP: hang up - write a crash image and exit |
7031 | 4953 |
" |
4954 |
signalNumber == 30 "OperatingSystem sigPWR" ifTrue:[ |
|
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4955 |
ObjectMemory snapShotOn:'crash.img'. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4956 |
^ self. |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4957 |
]. |
7031 | 4958 |
(signalNumber == 1 "OperatingSystem sigHUP") ifTrue:[ |
4959 |
ObjectMemory snapShotOn:'crash.img'. |
|
4960 |
Smalltalk exit. |
|
4961 |
]. |
|
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4962 |
|
5755 | 4963 |
name := OperatingSystem nameForSignal:signalNumber. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4964 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4965 |
"if there is no screen at all, bring up a mini debugger" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4966 |
(Screen isNil |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4967 |
or:[(screen := Screen current) isNil |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
4968 |
or:[(screen := Screen default) isNil |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
4969 |
or:[screen isOpen not]]]) ifTrue:[ |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4970 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4971 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4972 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4973 |
"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
|
4974 |
otherwise display stays locked" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4975 |
screen ungrabPointer; ungrabKeyboard. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4976 |
|
7031 | 4977 |
here := thisContext. |
4978 |
badContext := here sender. "the context, in which the signal occurred" |
|
4979 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4980 |
"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
|
4981 |
Screen currentScreenQuerySignal answer:screen do:[ |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4982 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4983 |
SIGBUS, SIGSEGV and SIGILL do not make sense to ignore (i.e. continue) |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4984 |
since the system will retry the faulty instruction, which leads to |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4985 |
another signal - to avoid frustration, better not offer this option. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4986 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4987 |
fatal := OperatingSystem isFatalSignal:signalNumber. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4988 |
fatal ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4989 |
(Debugger isNil or:[here isRecursive]) ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4990 |
'Object [hard error]: signal ' errorPrint. signalNumber errorPrintCR. |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4991 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4992 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4993 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4994 |
a hard signal - go into debugger immediately |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4995 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4996 |
msg := 'OS-signal: ', name. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4997 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4998 |
"/ the IRQ-PC is passed as low-hi, to avoid the need |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4999 |
"/ to allocate a LargeInteger in the VM during signal |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5000 |
"/ time. I know, this is ugly. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5001 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5002 |
InterruptPcLow notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5003 |
pc := InterruptPcLow + (InterruptPcHi bitShift:(SmallInteger maxBits + 1 // 2)). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5004 |
pc ~~ 0 ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5005 |
msg := msg , ' PC=' , (pc printStringRadix:16) |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5006 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5007 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5008 |
InterruptAddrLow notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5009 |
addr := InterruptAddrLow + (InterruptAddrHi bitShift:(SmallInteger maxBits + 1 // 2)). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5010 |
addr ~~ 0 ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5011 |
msg := msg , ' ADDR=' , (addr printStringRadix:16) |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5012 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5013 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5014 |
Debugger enter:here withMessage:msg mayProceed:false. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5015 |
"unreachable" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5016 |
^ nil. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5017 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5018 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5019 |
"if possible, open an option box asking the user what do. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5020 |
Otherwise, start a debugger" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5021 |
Dialog notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5022 |
titles := #('save crash image' 'dump core' 'exit ST/X' 'debug'). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5023 |
actions := #(save core exit debug). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5024 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5025 |
action := nil. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5026 |
title := 'OS Signal caught (' , name, ')'. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5027 |
title := (title , '\[in ST-process: ' , Processor activeProcess nameOrId ,']') withCRs. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5028 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5029 |
"/ if cought while in the scheduler or event dispatcher, |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5030 |
"/ a modal dialog is not possible ... |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5031 |
"/ (therefore, abort & return does not makes sense) |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5032 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5033 |
Processor activeProcess isSystemProcess ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5034 |
titles := #('abort') , titles. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5035 |
actions := #(abort), actions. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5036 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5037 |
badContext canReturn ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5038 |
titles := #('return') , titles. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5039 |
actions := #(return), actions. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5040 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5041 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5042 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5043 |
fatal ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5044 |
titles := titles, #('ignore'). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5045 |
actions := actions , #(ignore). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5046 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5047 |
action := Dialog choose:title |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5048 |
labels:titles |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5049 |
values:actions |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5050 |
default:(fatal ifTrue:[nil] ifFalse:[#ignore]). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5051 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5052 |
"Dialog may fail (if system process), default action is debug" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5053 |
action size == 0 ifTrue:[action := #debug]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5054 |
] ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5055 |
action := #debug. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5056 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5057 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5058 |
action == #save ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5059 |
ObjectMemory snapShotOn:'crash.img' |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5060 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5061 |
action == #core ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5062 |
Smalltalk fatalAbort |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5063 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5064 |
action == #exit ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5065 |
Smalltalk exit |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5066 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5067 |
action == #return ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5068 |
badContext return |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5069 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5070 |
action == #abort ifTrue:[ |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
5071 |
AbortOperationRequest raise. |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5072 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5073 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5074 |
action == #debug ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5075 |
Debugger isNil ifTrue:[ |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
5076 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5077 |
]. |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
5078 |
Debugger enter:here withMessage:('OS-Signal ', name) mayProceed:true. |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5079 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5080 |
"action == #ignore" |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5081 |
]. |
5755 | 5082 |
! |
5083 |
||
5084 |
spyInterrupt |
|
5085 |
"{ Pragma: +optSpace }" |
|
5086 |
||
5087 |
"spy interrupt and no handler - enter debugger" |
|
5088 |
||
5089 |
self error:'spy Interrupt - but no handler' mayProceed:true |
|
5090 |
! |
|
5091 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5092 |
startMiniDebuggerOrExit:text |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5093 |
"some critical condition happened. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5094 |
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
|
5095 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5096 |
MiniDebugger isNil ifTrue:[ |
6654 | 5097 |
"a system without debugging facilities (i.e. a standalone system) |
5098 |
output a message and exit." |
|
5099 |
('Object [error]: exit due to ', text, ' - and no debugger.') errorPrintCR. |
|
5100 |
OperatingSystem exit:99. |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5101 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5102 |
MiniDebugger enterWithMessage:text mayProceed:true. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5103 |
! |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5104 |
|
5755 | 5105 |
timerInterrupt |
5106 |
"{ Pragma: +optSpace }" |
|
5107 |
||
5108 |
"timer interrupt and no handler - enter debugger" |
|
5109 |
||
5110 |
self error:'timer Interrupt - but no handler' mayProceed:true |
|
5111 |
! |
|
5112 |
||
5113 |
userInterrupt |
|
5114 |
"{ Pragma: +optSpace }" |
|
5115 |
||
5116 |
"user (^c) interrupt. |
|
5117 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
5118 |
controlling tty (i.e. in the xterm)." |
|
5119 |
||
6466 | 5120 |
UserInterruptSignal raiseRequest |
5755 | 5121 |
! |
5122 |
||
5123 |
userInterruptIn:aContext |
|
5124 |
"{ Pragma: +optSpace }" |
|
5125 |
||
5126 |
"user (^c) interrupt - enter debugger, but show aContext |
|
5127 |
as top-context. |
|
5128 |
This is used to hide any intermediate scheduler contexts, |
|
5129 |
in case of an interrupted process. Typically, this is sent by |
|
5130 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
5131 |
processed." |
|
5132 |
||
5133 |
<context: #return> |
|
5134 |
||
5135 |
UserInterruptSignal raiseRequestWith:nil errorString:nil in:aContext |
|
5136 |
||
5137 |
"Created: / 18.10.1996 / 20:46:04 / cg" |
|
5138 |
"Modified: / 20.10.1996 / 13:06:38 / cg" |
|
5139 |
"Modified: / 26.7.1999 / 10:58:49 / stefan" |
|
5140 |
! ! |
|
5141 |
||
5142 |
!Object methodsFor:'message sending'! |
|
5143 |
||
5144 |
perform:aSelector |
|
5145 |
"send the message aSelector to the receiver" |
|
5146 |
||
5147 |
%{ |
|
5148 |
REGISTER OBJ sel = aSelector; |
|
5149 |
||
5150 |
if (InterruptPending == nil) { |
|
6654 | 5151 |
struct inlineCache *pIlc; |
5152 |
static struct inlineCache ilc_0 = __ILCPERF0(@line); |
|
5153 |
static struct inlineCache ilc_1 = __ILCPERF0(@line); |
|
5154 |
static struct inlineCache ilc_2 = __ILCPERF0(@line); |
|
5155 |
static struct inlineCache ilc_3 = __ILCPERF0(@line); |
|
5156 |
static struct inlineCache ilc_4 = __ILCPERF0(@line); |
|
5157 |
static OBJ last_0 = nil; |
|
5158 |
static OBJ last_1 = nil; |
|
5159 |
static OBJ last_2 = nil; |
|
5160 |
static OBJ last_3 = nil; |
|
5161 |
static OBJ last_4 = nil; |
|
5162 |
static flip = 0; |
|
5163 |
||
5164 |
if (sel == last_0) { |
|
5165 |
pIlc = &ilc_0; |
|
5166 |
} else if (sel == last_1) { |
|
5167 |
pIlc = &ilc_1; |
|
5168 |
} else if (sel == last_2) { |
|
5169 |
pIlc = &ilc_2; |
|
5170 |
} else if (sel == last_3) { |
|
5171 |
pIlc = &ilc_3; |
|
5172 |
} else if (sel == last_4) { |
|
5173 |
pIlc = &ilc_4; |
|
5174 |
} else { |
|
5175 |
if (flip == 0) { |
|
5176 |
pIlc = &ilc_0; |
|
5177 |
flip = 1; |
|
5178 |
last_0 = sel; |
|
5179 |
} else if (flip == 1) { |
|
5180 |
pIlc = &ilc_1; |
|
5181 |
flip = 2; |
|
5182 |
last_1 = sel; |
|
5183 |
} else if (flip == 2) { |
|
5184 |
pIlc = &ilc_2; |
|
5185 |
flip = 3; |
|
5186 |
last_2 = sel; |
|
5187 |
} else if (flip == 3) { |
|
5188 |
pIlc = &ilc_3; |
|
5189 |
flip = 4; |
|
5190 |
last_3 = sel; |
|
5191 |
} else { |
|
5192 |
pIlc = &ilc_4; |
|
5193 |
flip = 0; |
|
5194 |
last_4 = sel; |
|
5195 |
} |
|
5196 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5197 |
if (pIlc->ilc_poly) { |
|
5198 |
__flushPolyCache(pIlc->ilc_poly); |
|
5199 |
pIlc->ilc_poly = 0; |
|
5200 |
} |
|
5201 |
} |
|
5202 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
|
5755 | 5203 |
} else { |
6654 | 5204 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
5205 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5755 | 5206 |
} |
5207 |
%}. |
|
5208 |
^ self perform:aSelector withArguments:#() |
|
5209 |
! |
|
5210 |
||
5211 |
perform:aSelector inClass:aClass withArguments:argArray |
|
5212 |
"send the message aSelector with all args taken from argArray |
|
5213 |
to the receiver as a super-send message. |
|
5214 |
This is actually more flexible than the normal super-send, since it allows |
|
5215 |
to execute a method in ANY superclass of the receiver (not just the |
|
5216 |
immediate superclass). |
|
5217 |
Thus, it is (theoretically) possible to do |
|
6654 | 5218 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
5755 | 5219 |
and evaluate Magnitudes compare method even if there was one in Number. |
5220 |
This method is used by the interpreter to evaluate super sends |
|
5221 |
and could be used for very special behavior (language extension ?). |
|
5222 |
||
5223 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
5224 |
||
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5225 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 myClass| |
5755 | 5226 |
|
5227 |
" |
|
5228 |
check, if aClass is really a superclass of the receiver |
|
5229 |
" |
|
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5230 |
myClass := self class. |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5231 |
(myClass == aClass or:[myClass isSubclassOf:aClass]) ifFalse:[ |
6654 | 5232 |
self error:'lookup-class argument is not a superclass of the receiver'. |
5233 |
^ nil |
|
5755 | 5234 |
]. |
5235 |
%{ |
|
5236 |
REGISTER OBJ *argP; |
|
5237 |
int nargs, i; |
|
5238 |
||
5239 |
if (__isArray(argArray)) { |
|
6654 | 5240 |
nargs = __arraySize(argArray); |
5241 |
argP = __arrayVal(argArray); |
|
5755 | 5242 |
} else { |
6654 | 5243 |
if (__isNonNilObject(argArray)) { |
5244 |
static struct inlineCache ilcSize = __ILC0(@line+1); |
|
5245 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5246 |
if (!__isSmallInteger(numberOfArgs)) |
|
5247 |
goto bad; |
|
5248 |
nargs = __intVal(numberOfArgs); |
|
5249 |
argP = (OBJ *)(&a1); |
|
5250 |
for (i=1; i <= nargs; i++) { |
|
5251 |
*argP++ = __AT_(argArray, __MKSMALLINT((INT)i)); |
|
5252 |
} |
|
5253 |
argP = (OBJ *)(&a1); |
|
5254 |
} else { |
|
5255 |
nargs = 0; |
|
5256 |
} |
|
5755 | 5257 |
} |
5258 |
switch (nargs) { |
|
6654 | 5259 |
case 0: |
5260 |
{ |
|
5261 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5262 |
RETURN ( _SEND0(self, aSelector, aClass, &ilc0)); |
|
5263 |
} |
|
5264 |
||
5265 |
case 1: |
|
5266 |
{ |
|
5267 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5268 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, argP[0])); |
|
5269 |
} |
|
5270 |
||
5271 |
case 2: |
|
5272 |
{ |
|
5273 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5274 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, argP[0], argP[1])); |
|
5275 |
} |
|
5276 |
||
5277 |
case 3: |
|
5278 |
{ |
|
5279 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5280 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, |
|
5281 |
argP[0], argP[1], argP[2])); |
|
5282 |
} |
|
5283 |
||
5284 |
case 4: |
|
5285 |
{ |
|
5286 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
5287 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, |
|
5288 |
argP[0], argP[1], argP[2], argP[3])); |
|
5289 |
} |
|
5290 |
||
5291 |
case 5: |
|
5292 |
{ |
|
5293 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
5294 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
5295 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5296 |
} |
|
5297 |
||
5298 |
case 6: |
|
5299 |
{ |
|
5300 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
5301 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
5302 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5])); |
|
5303 |
} |
|
5304 |
||
5305 |
case 7: |
|
5306 |
{ |
|
5307 |
static struct inlineCache ilc7 = __DUMMYILCSELF7(@line+1); |
|
5308 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
5309 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5310 |
argP[6])); |
|
5311 |
} |
|
5312 |
||
5313 |
case 8: |
|
5314 |
{ |
|
5315 |
static struct inlineCache ilc8 = __DUMMYILCSELF8(@line+1); |
|
5316 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
5317 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5318 |
argP[6], argP[7])); |
|
5319 |
} |
|
5320 |
||
5321 |
case 9: |
|
5322 |
{ |
|
5323 |
static struct inlineCache ilc9 = __DUMMYILCSELF9(@line+1); |
|
5324 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
5325 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5326 |
argP[6], argP[7], argP[8])); |
|
5327 |
} |
|
5328 |
||
5329 |
case 10: |
|
5330 |
{ |
|
5331 |
static struct inlineCache ilc10 = __DUMMYILCSELF10(@line+1); |
|
5332 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
5333 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5334 |
argP[6], argP[7], argP[8], argP[9])); |
|
5335 |
} |
|
5336 |
||
5337 |
case 11: |
|
5338 |
{ |
|
5339 |
static struct inlineCache ilc11 = __DUMMYILCSELF11(@line+1); |
|
5340 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
5341 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5342 |
argP[6], argP[7], argP[8], argP[9], argP[10])); |
|
5343 |
} |
|
5344 |
||
5345 |
case 12: |
|
5346 |
{ |
|
5347 |
static struct inlineCache ilc12 = __DUMMYILCSELF12(@line+1); |
|
5348 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
5349 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5350 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5351 |
argP[11])); |
|
5352 |
} |
|
5353 |
||
5354 |
case 13: |
|
5355 |
{ |
|
5356 |
static struct inlineCache ilc13 = __DUMMYILCSELF13(@line+1); |
|
5357 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
5358 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5359 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5360 |
argP[11], argP[12])); |
|
5361 |
} |
|
5362 |
||
5363 |
case 14: |
|
5364 |
{ |
|
5365 |
static struct inlineCache ilc14 = __DUMMYILCSELF14(@line+1); |
|
5366 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
5367 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5368 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5369 |
argP[11], argP[12], argP[13])); |
|
5370 |
} |
|
5371 |
||
5372 |
case 15: |
|
5373 |
{ |
|
5374 |
static struct inlineCache ilc15 = __DUMMYILCSELF15(@line+1); |
|
5375 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
5376 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5377 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5378 |
argP[11], argP[12], argP[13], argP[14])); |
|
5379 |
} |
|
5755 | 5380 |
|
5381 |
#ifdef _SEND16 |
|
6654 | 5382 |
case 16: |
5383 |
{ |
|
5384 |
static struct inlineCache ilc16 = __DUMMYILCSELF16(@line+1); |
|
5385 |
RETURN ( _SEND16(self, aSelector, aClass, &ilc15, |
|
5386 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5387 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5388 |
argP[11], argP[12], argP[13], argP[14], argP[15])); |
|
5389 |
} |
|
5755 | 5390 |
#endif |
5391 |
#ifdef _SEND17 |
|
6654 | 5392 |
case 17: |
5393 |
{ |
|
5394 |
static struct inlineCache ilc17 = __DUMMYILCSELF17(@line+1); |
|
5395 |
RETURN ( _SEND17(self, aSelector, aClass, &ilc15, |
|
5396 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5397 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5398 |
argP[11], argP[12], argP[13], argP[14], argP[15], argP[16])); |
|
5399 |
} |
|
5755 | 5400 |
#endif |
5401 |
||
5402 |
||
5403 |
} |
|
5404 |
bad:; |
|
5405 |
%}. |
|
5406 |
"/ arrive here, if bad number of arguments (too many) |
|
5407 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5408 |
||
5409 |
^ self primitiveFailed |
|
5410 |
! |
|
5411 |
||
5412 |
perform:aSelector with:arg |
|
5413 |
"send the one-arg-message aSelector to the receiver" |
|
5414 |
||
5415 |
%{ |
|
5416 |
REGISTER OBJ sel = aSelector; |
|
5417 |
||
5418 |
if (InterruptPending == nil) { |
|
6654 | 5419 |
struct inlineCache *pIlc; |
5420 |
static struct inlineCache ilc_0 = __ILCPERF1(@line); |
|
5421 |
static struct inlineCache ilc_1 = __ILCPERF1(@line); |
|
5422 |
static struct inlineCache ilc_2 = __ILCPERF1(@line); |
|
5423 |
static struct inlineCache ilc_3 = __ILCPERF1(@line); |
|
5424 |
static struct inlineCache ilc_4 = __ILCPERF1(@line); |
|
5425 |
static OBJ last_0 = nil; |
|
5426 |
static OBJ last_1 = nil; |
|
5427 |
static OBJ last_2 = nil; |
|
5428 |
static OBJ last_3 = nil; |
|
5429 |
static OBJ last_4 = nil; |
|
5430 |
static flip = 0; |
|
5431 |
||
5432 |
if (sel == last_0) { |
|
5433 |
pIlc = &ilc_0; |
|
5434 |
} else if (sel == last_1) { |
|
5435 |
pIlc = &ilc_1; |
|
5436 |
} else if (sel == last_2) { |
|
5437 |
pIlc = &ilc_2; |
|
5438 |
} else if (sel == last_3) { |
|
5439 |
pIlc = &ilc_3; |
|
5440 |
} else if (sel == last_4) { |
|
5441 |
pIlc = &ilc_4; |
|
5442 |
} else { |
|
5443 |
if (flip == 0) { |
|
5444 |
pIlc = &ilc_0; |
|
5445 |
flip = 1; |
|
5446 |
last_0 = sel; |
|
5447 |
} else if (flip == 1) { |
|
5448 |
pIlc = &ilc_1; |
|
5449 |
flip = 2; |
|
5450 |
last_1 = sel; |
|
5451 |
} else if (flip == 2) { |
|
5452 |
pIlc = &ilc_2; |
|
5453 |
flip = 3; |
|
5454 |
last_2 = sel; |
|
5455 |
} else if (flip == 3) { |
|
5456 |
pIlc = &ilc_3; |
|
5457 |
flip = 4; |
|
5458 |
last_3 = sel; |
|
5459 |
} else { |
|
5460 |
pIlc = &ilc_4; |
|
5461 |
flip = 0; |
|
5462 |
last_4 = sel; |
|
5463 |
} |
|
5464 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5465 |
if (pIlc->ilc_poly) { |
|
5466 |
__flushPolyCache(pIlc->ilc_poly); |
|
5467 |
pIlc->ilc_poly = 0; |
|
5468 |
} |
|
5469 |
} |
|
5470 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
|
5755 | 5471 |
} else { |
6654 | 5472 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
5473 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
5755 | 5474 |
} |
5475 |
%}. |
|
5476 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5477 |
||
5478 |
! |
|
5479 |
||
5480 |
perform:aSelector with:arg1 with:arg2 |
|
5481 |
"send the two-arg-message aSelector to the receiver" |
|
5482 |
||
5483 |
%{ |
|
5484 |
struct inlineCache *pIlc; |
|
5485 |
||
5486 |
if (InterruptPending == nil) { |
|
6654 | 5487 |
static struct inlineCache ilc_0 = __ILCPERF2(@line); |
5488 |
static struct inlineCache ilc_1 = __ILCPERF2(@line); |
|
5489 |
static OBJ last_0 = nil; |
|
5490 |
static OBJ last_1 = nil; |
|
5491 |
static flip = 0; |
|
5492 |
||
5493 |
if (aSelector == last_0) { |
|
5494 |
pIlc = &ilc_0; |
|
5495 |
} else if (aSelector == last_1) { |
|
5496 |
pIlc = &ilc_1; |
|
5497 |
} else { |
|
5498 |
if (flip == 0) { |
|
5499 |
pIlc = &ilc_0; |
|
5500 |
flip = 1; |
|
5501 |
last_0 = aSelector; |
|
5502 |
} else { |
|
5503 |
pIlc = &ilc_1; |
|
5504 |
flip = 0; |
|
5505 |
last_1 = aSelector; |
|
5506 |
} |
|
5507 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5508 |
if (pIlc->ilc_poly) { |
|
5509 |
__flushPolyCache(pIlc->ilc_poly); |
|
5510 |
pIlc->ilc_poly = 0; |
|
5511 |
} |
|
5512 |
} |
|
5513 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
|
5755 | 5514 |
} else { |
6654 | 5515 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
5516 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, arg1, arg2)); |
|
5755 | 5517 |
} |
5518 |
%}. |
|
5519 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2) |
|
5520 |
||
5521 |
! |
|
5522 |
||
5523 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
|
5524 |
"send the three-arg-message aSelector to the receiver" |
|
5525 |
||
5526 |
%{ |
|
5527 |
struct inlineCache *pIlc; |
|
5528 |
static struct inlineCache ilc_0 = __ILCPERF3(@line); |
|
5529 |
static struct inlineCache ilc_1 = __ILCPERF3(@line); |
|
5530 |
static OBJ last_0 = nil; |
|
5531 |
static OBJ last_1 = nil; |
|
5532 |
static flip = 0; |
|
5533 |
||
5534 |
if (InterruptPending == nil) { |
|
6654 | 5535 |
if (aSelector != last_0) { |
5536 |
if (aSelector != last_1) { |
|
5537 |
if (flip) { |
|
5538 |
pIlc = &ilc_0; |
|
5539 |
flip = 0; |
|
5540 |
last_0 = aSelector; |
|
5541 |
} else { |
|
5542 |
pIlc = &ilc_1; |
|
5543 |
flip = 1; |
|
5544 |
last_1 = aSelector; |
|
5545 |
} |
|
5546 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5547 |
if (pIlc->ilc_poly) { |
|
5548 |
__flushPolyCache(pIlc->ilc_poly); |
|
5549 |
pIlc->ilc_poly = 0; |
|
5550 |
} |
|
5551 |
} else { |
|
5552 |
pIlc = &ilc_1; |
|
5553 |
} |
|
5554 |
} else { |
|
5555 |
pIlc = &ilc_0; |
|
5556 |
} |
|
5557 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
|
5755 | 5558 |
} else { |
6654 | 5559 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
5560 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, arg1, arg2, arg3)); |
|
5755 | 5561 |
} |
5562 |
%}. |
|
5563 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3) |
|
5564 |
||
5565 |
! |
|
5566 |
||
5567 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
5568 |
"send the four-arg-message aSelector to the receiver" |
|
5569 |
||
5570 |
%{ |
|
5571 |
struct inlineCache *pIlc; |
|
5572 |
static struct inlineCache ilc_0 = __ILCPERF4(@line); |
|
5573 |
static struct inlineCache ilc_1 = __ILCPERF4(@line); |
|
5574 |
static OBJ last_0 = nil; |
|
5575 |
static OBJ last_1 = nil; |
|
5576 |
static flip = 0; |
|
5577 |
||
5578 |
if (InterruptPending == nil) { |
|
6654 | 5579 |
if (aSelector != last_0) { |
5580 |
if (aSelector != last_1) { |
|
5581 |
if (flip) { |
|
5582 |
pIlc = &ilc_0; |
|
5583 |
flip = 0; |
|
5584 |
last_0 = aSelector; |
|
5585 |
} else { |
|
5586 |
pIlc = &ilc_1; |
|
5587 |
flip = 1; |
|
5588 |
last_1 = aSelector; |
|
5589 |
} |
|
5590 |
pIlc->ilc_func = __SEND4ADDR__; |
|
5591 |
if (pIlc->ilc_poly) { |
|
5592 |
__flushPolyCache(pIlc->ilc_poly); |
|
5593 |
pIlc->ilc_poly = 0; |
|
5594 |
} |
|
5595 |
} else { |
|
5596 |
pIlc = &ilc_1; |
|
5597 |
} |
|
5598 |
} else { |
|
5599 |
pIlc = &ilc_0; |
|
5600 |
} |
|
5601 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5602 |
arg1, arg2, arg3, arg4) ); |
|
5755 | 5603 |
} else { |
6654 | 5604 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
5605 |
RETURN (_SEND4(self, aSelector, nil, &ilc4, |
|
5606 |
arg1, arg2, arg3, arg4)); |
|
5755 | 5607 |
} |
5608 |
%}. |
|
5609 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
5610 |
||
5611 |
! |
|
5612 |
||
5613 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
5614 |
"send the five-arg-message aSelector to the receiver" |
|
5615 |
||
5616 |
%{ |
|
5617 |
struct inlineCache *pIlc; |
|
5618 |
static struct inlineCache ilc_0 = __ILCPERF5(@line); |
|
5619 |
static struct inlineCache ilc_1 = __ILCPERF5(@line); |
|
5620 |
static OBJ last_0 = nil; |
|
5621 |
static OBJ last_1 = nil; |
|
5622 |
static flip = 0; |
|
5623 |
||
5624 |
if (InterruptPending == nil) { |
|
6654 | 5625 |
if (aSelector != last_0) { |
5626 |
if (aSelector != last_1) { |
|
5627 |
if (flip) { |
|
5628 |
pIlc = &ilc_0; |
|
5629 |
flip = 0; |
|
5630 |
last_0 = aSelector; |
|
5631 |
} else { |
|
5632 |
pIlc = &ilc_1; |
|
5633 |
flip = 1; |
|
5634 |
last_1 = aSelector; |
|
5635 |
} |
|
5636 |
pIlc->ilc_func = __SEND5ADDR__; |
|
5637 |
if (pIlc->ilc_poly) { |
|
5638 |
__flushPolyCache(pIlc->ilc_poly); |
|
5639 |
pIlc->ilc_poly = 0; |
|
5640 |
} |
|
5641 |
} else { |
|
5642 |
pIlc = &ilc_1; |
|
5643 |
} |
|
5644 |
} else { |
|
5645 |
pIlc = &ilc_0; |
|
5646 |
} |
|
5647 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5648 |
arg1, arg2, arg3, arg4, arg5) ); |
|
5755 | 5649 |
} else { |
6654 | 5650 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
5651 |
RETURN (_SEND5(self, aSelector, nil, &ilc5, |
|
5652 |
arg1, arg2, arg3, arg4, arg5)); |
|
5755 | 5653 |
} |
5654 |
%}. |
|
5655 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
6654 | 5656 |
with:arg5) |
5755 | 5657 |
|
5658 |
! |
|
5659 |
||
5660 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
|
5661 |
"send the six-arg-message aSelector to the receiver" |
|
5662 |
||
5663 |
%{ |
|
5664 |
struct inlineCache *pIlc; |
|
5665 |
static struct inlineCache ilc_0 = __ILCPERF6(@line); |
|
5666 |
static struct inlineCache ilc_1 = __ILCPERF6(@line); |
|
5667 |
static OBJ last_0 = nil; |
|
5668 |
static OBJ last_1 = nil; |
|
5669 |
static flip = 0; |
|
5670 |
||
5671 |
if (InterruptPending == nil) { |
|
6654 | 5672 |
if (aSelector != last_0) { |
5673 |
if (aSelector != last_1) { |
|
5674 |
if (flip) { |
|
5675 |
pIlc = &ilc_0; |
|
5676 |
flip = 0; |
|
5677 |
last_0 = aSelector; |
|
5678 |
} else { |
|
5679 |
pIlc = &ilc_1; |
|
5680 |
flip = 1; |
|
5681 |
last_1 = aSelector; |
|
5682 |
} |
|
5683 |
pIlc->ilc_func = __SEND6ADDR__; |
|
5684 |
if (pIlc->ilc_poly) { |
|
5685 |
__flushPolyCache(pIlc->ilc_poly); |
|
5686 |
pIlc->ilc_poly = 0; |
|
5687 |
} |
|
5688 |
} else { |
|
5689 |
pIlc = &ilc_1; |
|
5690 |
} |
|
5691 |
} else { |
|
5692 |
pIlc = &ilc_0; |
|
5693 |
} |
|
5694 |
||
5695 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5696 |
arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
5755 | 5697 |
} else { |
6654 | 5698 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
5699 |
RETURN (_SEND6(self, aSelector, nil, &ilc6, |
|
5700 |
arg1, arg2, arg3, arg4, arg5, arg6)); |
|
5755 | 5701 |
} |
5702 |
%}. |
|
5703 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
6654 | 5704 |
with:arg5 with:arg6) |
5755 | 5705 |
|
5706 |
! |
|
5707 |
||
5708 |
perform:aSelector withArguments:argArray |
|
5709 |
"send the message aSelector with all args taken from argArray |
|
5710 |
to the receiver." |
|
5711 |
||
5712 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
5713 |
||
5714 |
%{ |
|
5715 |
REGISTER OBJ *argP; |
|
5716 |
int nargs; |
|
5717 |
OBJ l; |
|
5718 |
||
5719 |
if (__isArray(argArray)) { |
|
6654 | 5720 |
nargs = __arraySize(argArray); |
5721 |
argP = __arrayVal(argArray); |
|
5755 | 5722 |
} else { |
6654 | 5723 |
if (__isNonNilObject(argArray)) { |
5724 |
static struct inlineCache ilcSize = __ILC0(@line); |
|
5725 |
int i; |
|
5726 |
||
5727 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5728 |
if (!__isSmallInteger(numberOfArgs)) |
|
5729 |
goto bad; |
|
5730 |
nargs = __intVal(numberOfArgs); |
|
5731 |
argP = (OBJ *)(&a1); |
|
5732 |
for (i=1; i <= nargs; i++) { |
|
5733 |
*argP++ = __AT_(argArray, __MKSMALLINT((INT)i)); |
|
5734 |
} |
|
5735 |
argP = (OBJ *)(&a1); |
|
5736 |
} else { |
|
5737 |
nargs = 0; |
|
5738 |
} |
|
5755 | 5739 |
} |
5740 |
switch (nargs) { |
|
6654 | 5741 |
case 0: |
5742 |
if (InterruptPending == nil) { |
|
5743 |
static OBJ last0_0 = nil; static struct inlineCache ilc0_0 = __ILCPERF0(@line); |
|
5744 |
static OBJ last0_1 = nil; static struct inlineCache ilc0_1 = __ILCPERF0(@line); |
|
5745 |
static OBJ last0_2 = nil; static struct inlineCache ilc0_2 = __ILCPERF0(@line); |
|
5746 |
static OBJ last0_3 = nil; static struct inlineCache ilc0_3 = __ILCPERF0(@line); |
|
5747 |
static int flip0 = 0; |
|
5748 |
struct inlineCache *pIlc; |
|
5749 |
||
5750 |
if (aSelector == last0_0) { |
|
5751 |
pIlc = &ilc0_0; |
|
5752 |
} else if (aSelector == last0_1) { |
|
5753 |
pIlc = &ilc0_1; |
|
5754 |
} else if (aSelector == last0_2) { |
|
5755 |
pIlc = &ilc0_2; |
|
5756 |
} else if (aSelector == last0_3) { |
|
5757 |
pIlc = &ilc0_3; |
|
5758 |
} else { |
|
5759 |
if (flip0 == 0) { |
|
5760 |
pIlc = &ilc0_0; |
|
5761 |
flip0 = 1; |
|
5762 |
last0_0 = aSelector; |
|
5763 |
} else if (flip0 == 1) { |
|
5764 |
pIlc = &ilc0_1; |
|
5765 |
flip0 = 2; |
|
5766 |
last0_1 = aSelector; |
|
5767 |
} else if (flip0 == 2) { |
|
5768 |
pIlc = &ilc0_2; |
|
5769 |
flip0 = 3; |
|
5770 |
last0_2 = aSelector; |
|
5771 |
} else { |
|
5772 |
pIlc = &ilc0_3; |
|
5773 |
flip0 = 0; |
|
5774 |
last0_3 = aSelector; |
|
5775 |
} |
|
5776 |
||
5777 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5778 |
if (pIlc->ilc_poly) { |
|
5779 |
__flushPolyCache(pIlc->ilc_poly); |
|
5780 |
pIlc->ilc_poly = 0; |
|
5781 |
} |
|
5782 |
} |
|
5783 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc)); |
|
5784 |
} else { |
|
5785 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5786 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5787 |
} |
|
5788 |
||
5789 |
case 1: |
|
5790 |
if (InterruptPending == nil) { |
|
5791 |
static OBJ last1_0 = nil; static struct inlineCache ilc1_0 = __ILCPERF1(@line); |
|
5792 |
static OBJ last1_1 = nil; static struct inlineCache ilc1_1 = __ILCPERF1(@line); |
|
5793 |
static OBJ last1_2 = nil; static struct inlineCache ilc1_2 = __ILCPERF1(@line); |
|
5794 |
static OBJ last1_3 = nil; static struct inlineCache ilc1_3 = __ILCPERF1(@line); |
|
5795 |
static int flip1 = 0; |
|
5796 |
struct inlineCache *pIlc; |
|
5797 |
||
5798 |
if (aSelector == last1_0) { |
|
5799 |
pIlc = &ilc1_0; |
|
5800 |
} else if (aSelector == last1_1) { |
|
5801 |
pIlc = &ilc1_1; |
|
5802 |
} else if (aSelector == last1_2) { |
|
5803 |
pIlc = &ilc1_2; |
|
5804 |
} else if (aSelector == last1_3) { |
|
5805 |
pIlc = &ilc1_3; |
|
5806 |
} else { |
|
5807 |
if (flip1 == 0) { |
|
5808 |
pIlc = &ilc1_0; |
|
5809 |
flip1 = 1; |
|
5810 |
last1_0 = aSelector; |
|
5811 |
} else if (flip1 == 1) { |
|
5812 |
pIlc = &ilc1_1; |
|
5813 |
flip1 = 2; |
|
5814 |
last1_1 = aSelector; |
|
5815 |
} else if (flip1 == 2) { |
|
5816 |
pIlc = &ilc1_2; |
|
5817 |
flip1 = 3; |
|
5818 |
last1_2 = aSelector; |
|
5819 |
} else { |
|
5820 |
pIlc = &ilc1_3; |
|
5821 |
flip1 = 0; |
|
5822 |
last1_3 = aSelector; |
|
5823 |
} |
|
5824 |
||
5825 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5826 |
if (pIlc->ilc_poly) { |
|
5827 |
__flushPolyCache(pIlc->ilc_poly); |
|
5828 |
pIlc->ilc_poly = 0; |
|
5829 |
} |
|
5830 |
} |
|
5831 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0])); |
|
5832 |
} else { |
|
5833 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5834 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, argP[0])); |
|
5835 |
} |
|
5836 |
||
5837 |
case 2: |
|
5838 |
if (InterruptPending == nil) { |
|
5839 |
static OBJ last2_0 = nil; static struct inlineCache ilc2_0 = __ILCPERF2(@line); |
|
5840 |
static OBJ last2_1 = nil; static struct inlineCache ilc2_1 = __ILCPERF2(@line); |
|
5841 |
static int flip2 = 0; |
|
5842 |
struct inlineCache *pIlc; |
|
5843 |
||
5844 |
if (aSelector == last2_0) { |
|
5845 |
pIlc = &ilc2_0; |
|
5846 |
} else if (aSelector == last2_1) { |
|
5847 |
pIlc = &ilc2_1; |
|
5848 |
} else { |
|
5849 |
if (flip2 == 0) { |
|
5850 |
pIlc = &ilc2_0; |
|
5851 |
flip2 = 1; |
|
5852 |
last2_0 = aSelector; |
|
5853 |
} else { |
|
5854 |
pIlc = &ilc2_1; |
|
5855 |
flip2 = 0; |
|
5856 |
last2_1 = aSelector; |
|
5857 |
} |
|
5858 |
||
5859 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5860 |
if (pIlc->ilc_poly) { |
|
5861 |
__flushPolyCache(pIlc->ilc_poly); |
|
5862 |
pIlc->ilc_poly = 0; |
|
5863 |
} |
|
5864 |
} |
|
5865 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1])); |
|
5866 |
} else { |
|
5867 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5868 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, argP[0], argP[1])); |
|
5869 |
} |
|
5870 |
||
5871 |
case 3: |
|
5872 |
if (InterruptPending == nil) { |
|
5873 |
static OBJ last3_0 = nil; static struct inlineCache ilc3_0 = __ILCPERF3(@line); |
|
5874 |
static OBJ last3_1 = nil; static struct inlineCache ilc3_1 = __ILCPERF3(@line); |
|
5875 |
static int flip3 = 0; |
|
5876 |
struct inlineCache *pIlc; |
|
5877 |
||
5878 |
if (aSelector == last3_0) { |
|
5879 |
pIlc = &ilc3_0; |
|
5880 |
} else if (aSelector == last3_1) { |
|
5881 |
pIlc = &ilc3_1; |
|
5882 |
} else { |
|
5883 |
if (flip3 == 0) { |
|
5884 |
pIlc = &ilc3_0; |
|
5885 |
flip3 = 1; |
|
5886 |
last3_0 = aSelector; |
|
5887 |
} else { |
|
5888 |
pIlc = &ilc3_1; |
|
5889 |
flip3 = 0; |
|
5890 |
last3_1 = aSelector; |
|
5891 |
} |
|
5892 |
||
5893 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5894 |
if (pIlc->ilc_poly) { |
|
5895 |
__flushPolyCache(pIlc->ilc_poly); |
|
5896 |
pIlc->ilc_poly = 0; |
|
5897 |
} |
|
5898 |
} |
|
5899 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1], argP[2])); |
|
5900 |
} else { |
|
5901 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5902 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, argP[0], argP[1], argP[2])); |
|
5903 |
} |
|
5904 |
||
5905 |
case 4: |
|
5906 |
{ |
|
5907 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(@line); |
|
5908 |
||
5909 |
if ((InterruptPending != nil) || (aSelector != last4)) { |
|
5910 |
ilc4.ilc_func = __SEND4ADDR__; |
|
5911 |
if (ilc4.ilc_poly) { |
|
5912 |
__flushPolyCache(ilc4.ilc_poly); |
|
5913 |
ilc4.ilc_poly = 0; |
|
5914 |
} |
|
5915 |
last4 = aSelector; |
|
5916 |
} |
|
5917 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
|
5918 |
argP[0], argP[1], argP[2], argP[3])); |
|
5919 |
} |
|
5920 |
||
5921 |
case 5: |
|
5922 |
{ |
|
5923 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(@line); |
|
5924 |
||
5925 |
if ((InterruptPending != nil) || (aSelector != last5)) { |
|
5926 |
ilc5.ilc_func = __SEND5ADDR__; |
|
5927 |
if (ilc5.ilc_poly) { |
|
5928 |
__flushPolyCache(ilc5.ilc_poly); |
|
5929 |
ilc5.ilc_poly = 0; |
|
5930 |
} |
|
5931 |
last5 = aSelector; |
|
5932 |
} |
|
5933 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
|
5934 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5935 |
} |
|
5936 |
||
5937 |
case 6: |
|
5938 |
{ |
|
5939 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(@line); |
|
5940 |
||
5941 |
if ((InterruptPending != nil) || (aSelector != last6)) { |
|
5942 |
ilc6.ilc_func = __SEND6ADDR__; |
|
5943 |
if (ilc6.ilc_poly) { |
|
5944 |
__flushPolyCache(ilc6.ilc_poly); |
|
5945 |
ilc6.ilc_poly = 0; |
|
5946 |
} |
|
5947 |
last6 = aSelector; |
|
5948 |
} |
|
5949 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
|
5950 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5951 |
argP[5])); |
|
5952 |
} |
|
5953 |
||
5954 |
case 7: |
|
5955 |
{ |
|
5956 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(@line); |
|
5957 |
||
5958 |
if ((InterruptPending != nil) || (aSelector != last7)) { |
|
5959 |
ilc7.ilc_func = __SEND7ADDR__; |
|
5960 |
if (ilc7.ilc_poly) { |
|
5961 |
__flushPolyCache(ilc7.ilc_poly); |
|
5962 |
ilc7.ilc_poly = 0; |
|
5963 |
} |
|
5964 |
last7 = aSelector; |
|
5965 |
} |
|
5966 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
|
5967 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5968 |
argP[5], argP[6])); |
|
5969 |
} |
|
5970 |
||
5971 |
case 8: |
|
5972 |
{ |
|
5973 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(@line); |
|
5974 |
||
5975 |
if ((InterruptPending != nil) || (aSelector != last8)) { |
|
5976 |
ilc8.ilc_func = __SEND8ADDR__; |
|
5977 |
if (ilc8.ilc_poly) { |
|
5978 |
__flushPolyCache(ilc8.ilc_poly); |
|
5979 |
ilc8.ilc_poly = 0; |
|
5980 |
} |
|
5981 |
last8 = aSelector; |
|
5982 |
} |
|
5983 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
|
5984 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5985 |
argP[5], argP[6], argP[7])); |
|
5986 |
} |
|
5987 |
||
5988 |
case 9: |
|
5989 |
{ |
|
5990 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(@line); |
|
5991 |
||
5992 |
if ((InterruptPending != nil) || (aSelector != last9)) { |
|
5993 |
ilc9.ilc_func = __SEND9ADDR__; |
|
5994 |
if (ilc9.ilc_poly) { |
|
5995 |
__flushPolyCache(ilc9.ilc_poly); |
|
5996 |
ilc9.ilc_poly = 0; |
|
5997 |
} |
|
5998 |
last9 = aSelector; |
|
5999 |
} |
|
6000 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
|
6001 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6002 |
argP[5], argP[6], argP[7], argP[8])); |
|
6003 |
} |
|
6004 |
||
6005 |
case 10: |
|
6006 |
{ |
|
6007 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(@line); |
|
6008 |
||
6009 |
if ((InterruptPending != nil) || (aSelector != last10)) { |
|
6010 |
ilc10.ilc_func = __SEND10ADDR__; |
|
6011 |
if (ilc10.ilc_poly) { |
|
6012 |
__flushPolyCache(ilc10.ilc_poly); |
|
6013 |
ilc10.ilc_poly = 0; |
|
6014 |
} |
|
6015 |
last10 = aSelector; |
|
6016 |
} |
|
6017 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
|
6018 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6019 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
6020 |
} |
|
6021 |
||
6022 |
case 11: |
|
6023 |
{ |
|
6024 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(@line); |
|
6025 |
||
6026 |
if ((InterruptPending != nil) || (aSelector != last11)) { |
|
6027 |
ilc11.ilc_func = __SEND11ADDR__; |
|
6028 |
if (ilc11.ilc_poly) { |
|
6029 |
__flushPolyCache(ilc11.ilc_poly); |
|
6030 |
ilc11.ilc_poly = 0; |
|
6031 |
} |
|
6032 |
last11 = aSelector; |
|
6033 |
} |
|
6034 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
|
6035 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6036 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6037 |
argP[10])); |
|
6038 |
} |
|
6039 |
||
6040 |
case 12: |
|
6041 |
{ |
|
6042 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(@line); |
|
6043 |
||
6044 |
if ((InterruptPending != nil) || (aSelector != last12)) { |
|
6045 |
ilc12.ilc_func = __SEND12ADDR__; |
|
6046 |
if (ilc12.ilc_poly) { |
|
6047 |
__flushPolyCache(ilc12.ilc_poly); |
|
6048 |
ilc12.ilc_poly = 0; |
|
6049 |
} |
|
6050 |
last12 = aSelector; |
|
6051 |
} |
|
6052 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
|
6053 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6054 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6055 |
argP[10], argP[11])); |
|
6056 |
} |
|
6057 |
||
6058 |
case 13: |
|
6059 |
{ |
|
6060 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(@line); |
|
6061 |
||
6062 |
if ((InterruptPending != nil) || (aSelector != last13)) { |
|
6063 |
ilc13.ilc_func = __SEND13ADDR__; |
|
6064 |
if (ilc13.ilc_poly) { |
|
6065 |
__flushPolyCache(ilc13.ilc_poly); |
|
6066 |
ilc13.ilc_poly = 0; |
|
6067 |
} |
|
6068 |
last13 = aSelector; |
|
6069 |
} |
|
6070 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
|
6071 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6072 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6073 |
argP[10], argP[11], argP[12])); |
|
6074 |
} |
|
6075 |
||
6076 |
case 14: |
|
6077 |
{ |
|
6078 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(@line); |
|
6079 |
||
6080 |
if ((InterruptPending != nil) || (aSelector != last14)) { |
|
6081 |
ilc14.ilc_func = __SEND14ADDR__; |
|
6082 |
if (ilc14.ilc_poly) { |
|
6083 |
__flushPolyCache(ilc14.ilc_poly); |
|
6084 |
ilc14.ilc_poly = 0; |
|
6085 |
} |
|
6086 |
last14 = aSelector; |
|
6087 |
} |
|
6088 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
|
6089 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6090 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6091 |
argP[10], argP[11], argP[12], argP[13])); |
|
6092 |
} |
|
6093 |
||
6094 |
case 15: |
|
6095 |
{ |
|
6096 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(@line); |
|
6097 |
||
6098 |
if ((InterruptPending != nil) || (aSelector != last15)) { |
|
6099 |
ilc15.ilc_func = __SEND15ADDR__; |
|
6100 |
if (ilc15.ilc_poly) { |
|
6101 |
__flushPolyCache(ilc15.ilc_poly); |
|
6102 |
ilc15.ilc_poly = 0; |
|
6103 |
} |
|
6104 |
last15 = aSelector; |
|
6105 |
} |
|
6106 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
|
6107 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6108 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6109 |
argP[10], argP[11], argP[12], argP[13], |
|
6110 |
argP[14])); |
|
6111 |
} |
|
5755 | 6112 |
} |
6113 |
bad:; |
|
6114 |
%}. |
|
6115 |
||
6116 |
"/ arrive here, if bad number of arguments (too many) |
|
6117 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
6118 |
||
6119 |
^ self primitiveFailed |
|
6120 |
! |
|
6121 |
||
6316 | 6122 |
perform:aSelector withOptionalArgument:arg |
6123 |
"send aSelector-message to the receiver. |
|
6318 | 6124 |
If the message expects an argument, pass arg." |
6316 | 6125 |
|
6126 |
aSelector numArgs == 1 ifTrue:[ |
|
6654 | 6127 |
^ self perform:aSelector with:arg |
6316 | 6128 |
]. |
6129 |
^ self perform:aSelector |
|
6319 | 6130 |
|
6131 |
" |
|
6132 |
|rec sel| |
|
6133 |
||
6134 |
rec := -1. |
|
6135 |
sel := #abs. |
|
6136 |
rec perform:sel withOptionalArgument:2. |
|
6137 |
||
6138 |
sel := #max:. |
|
6139 |
rec perform:sel withOptionalArgument:2. |
|
6140 |
" |
|
6316 | 6141 |
! |
6142 |
||
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6143 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6144 |
"send aSelector-message to the receiver. |
6728 | 6145 |
Depending on the number of arguments the message expects, |
6146 |
pass either none, 1, or 2 arguments." |
|
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6147 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6148 |
|numArgs| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6149 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6150 |
numArgs := aSelector numArgs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6151 |
numArgs == 0 ifTrue:[ |
6654 | 6152 |
^ self perform:aSelector |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6153 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6154 |
numArgs == 1 ifTrue:[ |
6654 | 6155 |
^ self perform:aSelector with:optionalArg1 |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6156 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6157 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6158 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6159 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6160 |
|rec sel| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6161 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6162 |
rec := -1. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6163 |
sel := #abs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6164 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6165 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6166 |
sel := #max:. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6167 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6168 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6169 |
! |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6170 |
|
6728 | 6171 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 |
6172 |
"send aSelector-message to the receiver. |
|
6173 |
Depending on the number of arguments the message expects, |
|
6174 |
pass either none, 1, 2 or 3 arguments." |
|
6175 |
||
6176 |
|numArgs| |
|
6177 |
||
6178 |
numArgs := aSelector numArgs. |
|
6179 |
numArgs == 0 ifTrue:[ |
|
6180 |
^ self perform:aSelector |
|
6181 |
]. |
|
6182 |
numArgs == 1 ifTrue:[ |
|
6183 |
^ self perform:aSelector with:optionalArg1 |
|
6184 |
]. |
|
6185 |
numArgs == 2 ifTrue:[ |
|
6186 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
|
6187 |
]. |
|
6188 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3. |
|
6189 |
||
6190 |
" |
|
6191 |
|rec sel| |
|
6192 |
||
6193 |
rec := -1. |
|
6194 |
sel := #abs. |
|
6195 |
rec perform:sel withOptionalArgument:2. |
|
6196 |
||
6197 |
sel := #max:. |
|
6198 |
rec perform:sel withOptionalArgument:2. |
|
6199 |
" |
|
6200 |
! |
|
6201 |
||
6764 | 6202 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 and:optionalArg4 |
6203 |
"send aSelector-message to the receiver. |
|
6204 |
Depending on the number of arguments the message expects, |
|
6205 |
pass either none, 1, 2, 3 or 4 arguments." |
|
6206 |
||
6207 |
|numArgs| |
|
6208 |
||
6209 |
numArgs := aSelector numArgs. |
|
6210 |
numArgs == 0 ifTrue:[ |
|
6211 |
^ self perform:aSelector |
|
6212 |
]. |
|
6213 |
numArgs == 1 ifTrue:[ |
|
6214 |
^ self perform:aSelector with:optionalArg1 |
|
6215 |
]. |
|
6216 |
numArgs == 2 ifTrue:[ |
|
6217 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
|
6218 |
]. |
|
6219 |
numArgs == 3 ifTrue:[ |
|
6220 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 |
|
6221 |
]. |
|
6222 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 with:optionalArg4. |
|
6223 |
||
6224 |
" |
|
6225 |
|rec sel| |
|
6226 |
||
6227 |
rec := -1. |
|
6228 |
sel := #abs. |
|
6229 |
rec perform:sel withOptionalArgument:2. |
|
6230 |
||
6231 |
sel := #max:. |
|
6232 |
rec perform:sel withOptionalArgument:2. |
|
6233 |
" |
|
6234 |
! |
|
6235 |
||
5755 | 6236 |
performMethod:aMethod |
6237 |
"invoke aMethod on the receiver. |
|
6238 |
The method should be a zero-argument method. |
|
6239 |
This is a non-object-oriented entry, applying a method |
|
6240 |
in a functional way on a receiver. |
|
6241 |
Warning: |
|
6654 | 6242 |
Take care for the method to be appropriate for the |
6243 |
receiver - no checking is done by the VM." |
|
5755 | 6244 |
|
6245 |
^ aMethod valueWithReceiver:self arguments:#() |
|
6246 |
||
6247 |
" |
|
6248 |
|mthd| |
|
6249 |
||
6250 |
mthd := SmallInteger compiledMethodAt:#negated. |
|
6251 |
Transcript showCR:(1 performMethod:mthd) |
|
6252 |
" |
|
6253 |
||
6254 |
"BAD USE example: |
|
6255 |
||
6256 |
|mthd| |
|
6257 |
||
6258 |
mthd := Point compiledMethodAt:#x. |
|
6259 |
Transcript showCR:((1->2) performMethod:mthd) |
|
6260 |
" |
|
6261 |
||
6262 |
"Modified: 31.7.1997 / 17:41:50 / cg" |
|
6263 |
! |
|
6264 |
||
6265 |
performMethod:aMethod arguments:argumentArray |
|
6266 |
"invoke aMethod on the receiver, passing an argumentArray. |
|
6267 |
The size of the argumentArray should match the number of args |
|
6268 |
expected by the method. |
|
6269 |
This is a non-object-oriented entry, applying a method |
|
6270 |
in a functional way on a receiver. |
|
6271 |
Warning: |
|
6654 | 6272 |
Take care for the method to be appropriate for the |
6273 |
receiver - no checking is done by the VM." |
|
5755 | 6274 |
|
6275 |
^ aMethod valueWithReceiver:self arguments:argumentArray |
|
6276 |
||
6277 |
" |
|
6278 |
|mthd| |
|
6279 |
||
6280 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6281 |
Transcript showCR:(1 performMethod:mthd arguments:#(2)) |
|
6282 |
" |
|
6283 |
||
6284 |
"Created: 31.7.1997 / 17:46:31 / cg" |
|
6285 |
! |
|
6286 |
||
6287 |
performMethod:aMethod with:arg |
|
6288 |
"invoke aMethod on the receiver, passing an argument. |
|
6289 |
The method should be a one-argument method. |
|
6290 |
This is a non-object-oriented entry, applying a method |
|
6291 |
in a functional way on a receiver. |
|
6292 |
Warning: |
|
6654 | 6293 |
Take care for the method to be appropriate for the |
6294 |
receiver - no checking is done by the VM." |
|
5755 | 6295 |
|
6296 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg) |
|
6297 |
||
6298 |
" |
|
6299 |
|mthd| |
|
6300 |
||
6301 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6302 |
Transcript showCR:(1 performMethod:mthd with:2) |
|
6303 |
" |
|
6304 |
||
6305 |
"Modified: 31.7.1997 / 17:42:32 / cg" |
|
6306 |
! |
|
6307 |
||
6308 |
performMethod:aMethod with:arg1 with:arg2 |
|
6309 |
"invoke aMethod on the receiver, passing two arguments. |
|
6310 |
The method should be a two-argument method. |
|
6311 |
This is a non-object-oriented entry, applying a method |
|
6312 |
in a functional way on a receiver. |
|
6313 |
Warning: |
|
6654 | 6314 |
Take care for the method to be appropriate for the |
6315 |
receiver - no checking is done by the VM." |
|
5755 | 6316 |
|
6317 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) |
|
6318 |
||
6319 |
" |
|
6320 |
|mthd arr| |
|
6321 |
||
6322 |
arr := Array new:1. |
|
6323 |
mthd := Array compiledMethodAt:#basicAt:put:. |
|
6324 |
arr performMethod:mthd with:1 with:'foo'. |
|
6325 |
Transcript showCR:arr |
|
6326 |
" |
|
6327 |
||
6328 |
"Modified: 31.7.1997 / 17:44:54 / cg" |
|
6329 |
! |
|
6330 |
||
6331 |
performMethod:aMethod with:arg1 with:arg2 with:arg3 |
|
6332 |
"invoke aMethod on the receiver, passing three arguments. |
|
6333 |
The method should be a three-argument method. |
|
6334 |
This is a non-object-oriented entry, applying a method |
|
6335 |
in a functional way on a receiver. |
|
6336 |
Warning: |
|
6654 | 6337 |
Take care for the method to be appropriate for the |
6338 |
receiver - no checking is done by the VM." |
|
5755 | 6339 |
|
6340 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3) |
|
6341 |
||
6342 |
"Created: 31.7.1997 / 17:45:20 / cg" |
|
6343 |
! ! |
|
6344 |
||
6345 |
!Object methodsFor:'printing & storing'! |
|
6346 |
||
6235 | 6347 |
basicPrintOn:aStream |
6348 |
"append the receivers className with an articel to the argument, aStream" |
|
6349 |
||
6350 |
aStream nextPutAll:self classNameWithArticle |
|
6351 |
! |
|
6352 |
||
5755 | 6353 |
className |
6354 |
"return the classname of the receivers class" |
|
6355 |
||
6356 |
^ self class name |
|
6357 |
||
6358 |
" |
|
6359 |
1 className |
|
6360 |
1 class className 'this may change ...' |
|
6361 |
$a className |
|
6362 |
$a class className 'this may change ...' |
|
6363 |
" |
|
6364 |
! |
|
6365 |
||
6366 |
classNameWithArticle |
|
6367 |
"return a string consisting of classname preceeded by an article. |
|
6368 |
(dont expect me to write national variants for this ... :-) |
|
6369 |
If you have special preferences, redefine it ..." |
|
6370 |
||
6829 | 6371 |
| cls| |
5755 | 6372 |
|
6373 |
(cls := self class) == self ifTrue:[ |
|
6654 | 6374 |
^ 'a funny object' |
5755 | 6375 |
]. |
6829 | 6376 |
^ cls nameWithArticle |
5755 | 6377 |
|
6378 |
" |
|
6418 | 6379 |
1 classNameWithArticle |
6380 |
(1->2) classNameWithArticle |
|
5755 | 6381 |
XWorkstation basicNew classNameWithArticle |
6418 | 6382 |
XWorkstation classNameWithArticle |
5755 | 6383 |
" |
6384 |
||
6385 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
6386 |
! |
|
6387 |
||
6388 |
errorPrint |
|
6389 |
"print the receiver on the standard error stream." |
|
6390 |
||
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
6391 |
StreamError catch:[ |
6654 | 6392 |
self printOn:Stderr |
5755 | 6393 |
] |
6394 |
||
6395 |
"Modified: 7.3.1996 / 19:11:29 / cg" |
|
6396 |
! |
|
6397 |
||
6398 |
errorPrintCR |
|
6399 |
"{ Pragma: +optSpace }" |
|
6400 |
||
6401 |
"print the receiver followed by a cr on the standard error stream." |
|
6402 |
||
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
6403 |
StreamError catch:[ |
6654 | 6404 |
self printOn:Stderr. |
6405 |
Stderr cr |
|
5755 | 6406 |
] |
6407 |
||
6408 |
"Modified: 7.3.1996 / 19:13:01 / cg" |
|
6409 |
"Created: 20.5.1996 / 10:20:41 / cg" |
|
6410 |
! |
|
6411 |
||
6412 |
errorPrintNL |
|
6413 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6414 |
<resource:#obsolete> |
5755 | 6415 |
|
6416 |
"print the receiver followed by a cr on the standard error stream. |
|
6417 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6418 |
||
6419 |
^ self errorPrintCR |
|
6420 |
||
6421 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
6422 |
! |
|
6423 |
||
6424 |
errorPrintNewline |
|
6425 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6426 |
<resource:#obsolete> |
5755 | 6427 |
|
6428 |
"print the receiver followed by a cr on the standard error stream. |
|
6429 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6430 |
||
6431 |
self errorPrintCR. |
|
6432 |
||
6433 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
6434 |
! |
|
6435 |
||
6436 |
infoPrint |
|
6437 |
"{ Pragma: +optSpace }" |
|
6438 |
||
6439 |
"print the receiver on the standard error stream. |
|
6440 |
This is meant for information messages which are not warnings |
|
6441 |
or fatal messages. |
|
6442 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6443 |
||
6444 |
InfoPrinting == true ifTrue:[ |
|
6654 | 6445 |
self errorPrint |
5755 | 6446 |
] |
6447 |
! |
|
6448 |
||
6449 |
infoPrintCR |
|
6450 |
"{ Pragma: +optSpace }" |
|
6451 |
||
6452 |
"print the receiver followed by a cr on the standard error stream. |
|
6453 |
This is meant for information messages which are not warnings |
|
6454 |
or fatal messages. |
|
6455 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6456 |
||
6457 |
InfoPrinting == true ifTrue:[ |
|
6654 | 6458 |
self errorPrintCR |
5755 | 6459 |
] |
6460 |
||
6461 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
6462 |
! |
|
6463 |
||
6464 |
infoPrintNL |
|
6465 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6466 |
<resource:#obsolete> |
5755 | 6467 |
|
6468 |
"print the receiver followed by a cr on the standard error stream. |
|
6469 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
6470 |
||
6471 |
^ self infoPrintCR |
|
6472 |
! |
|
6473 |
||
6474 |
||
6475 |
"print the receiver on the standard output stream (which is not the Transcript)" |
|
6476 |
||
6477 |
"/ the following allows printCR to be used during |
|
6478 |
"/ the early init-phase, when no Stdout has been set up. |
|
6479 |
"/ (depends on string to respond to #print) |
|
6480 |
||
6481 |
Stdout isNil ifTrue:[ |
|
6654 | 6482 |
self printString print. |
6483 |
^ self |
|
5755 | 6484 |
]. |
6485 |
self printOn:Stdout |
|
6486 |
||
6487 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
6488 |
! |
|
6489 |
||
6490 |
printCR |
|
6491 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
|
6492 |
||
6493 |
"/ the following allows printCR to be used during |
|
6494 |
"/ the early init-phase, when no Stdout has been set up. |
|
6495 |
"/ (depends on string to respond to #printCR) |
|
6496 |
||
6497 |
Stdout isNil ifTrue:[ |
|
6654 | 6498 |
self printString printCR. |
6499 |
^ self |
|
5755 | 6500 |
]. |
6501 |
self printOn:Stdout. |
|
6502 |
Stdout cr |
|
6503 |
||
6504 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
6505 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
|
6506 |
! |
|
6507 |
||
6508 |
printNL |
|
6509 |
"print the receiver followed by a cr on the standard output stream |
|
6510 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
6511 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6512 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6513 |
|
5755 | 6514 |
^ self printCR |
6515 |
||
6516 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
6517 |
! |
|
6518 |
||
6519 |
printNewline |
|
6520 |
"print the receiver followed by a cr on the standard output stream. |
|
6521 |
This exists for backward compatibility - please use #printCR." |
|
6522 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6523 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6524 |
|
5755 | 6525 |
self printCR |
6526 |
||
6527 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
6528 |
! |
|
6529 |
||
6530 |
printOn:aStream |
|
6531 |
"append a user printed representation of the receiver to aStream. |
|
6532 |
The format is suitable for a human - not meant to be read back. |
|
6533 |
||
6534 |
The default here is to output the receivers class name. |
|
6535 |
BUT: this method is heavily redefined for objects which |
|
6536 |
can print prettier." |
|
6537 |
||
6235 | 6538 |
self basicPrintOn:aStream. |
6539 |
||
6540 |
" |
|
6541 |
(1@2) printOn:Transcript |
|
6542 |
(1@2) basicPrintOn:Transcript |
|
6543 |
" |
|
5755 | 6544 |
! |
6545 |
||
6546 |
printOn:aStream leftPaddedTo:size |
|
6547 |
"print the receiver on aStream, padding with spaces up to size. |
|
6548 |
padding is done on the left." |
|
6549 |
||
6550 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
6551 |
||
6552 |
" |
|
6553 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
6554 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
6555 |
" |
|
6556 |
! |
|
6557 |
||
6558 |
printOn:aStream leftPaddedTo:size with:padCharacter |
|
6559 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
6560 |
padding is done on the left." |
|
6561 |
||
6562 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
6563 |
||
6564 |
" |
|
6565 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
6566 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
6567 |
" |
|
6568 |
! |
|
6569 |
||
6570 |
printOn:aStream paddedTo:size |
|
6571 |
"print the receiver on aStream, padding with spaces up to size." |
|
6572 |
||
6573 |
self printOn:aStream paddedTo:size with:(Character space) |
|
6574 |
||
6575 |
" |
|
6576 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
6577 |
" |
|
6578 |
! |
|
6579 |
||
6580 |
printOn:aStream paddedTo:size with:padCharacter |
|
6581 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
6582 |
||
6583 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
6584 |
||
6585 |
" |
|
6586 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
6587 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
6588 |
" |
|
6589 |
! |
|
6590 |
||
6591 |
printOn:aStream zeroPaddedTo:size |
|
6592 |
"print the receiver on aStream, padding with zeros up to size. |
|
6593 |
Usually used with float numbers." |
|
6594 |
||
6595 |
self printOn:aStream paddedTo:size with:$0. |
|
6596 |
||
6597 |
" |
|
6598 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
6599 |
" |
|
6600 |
! |
|
6601 |
||
6602 |
printRightAdjustLen:size |
|
6603 |
"obsolete - just a name confusion. |
|
6604 |
This method will go away ..." |
|
6605 |
||
6606 |
(self printStringLeftPaddedTo:size) printOn:Stdout |
|
6607 |
! |
|
6608 |
||
6609 |
printString |
|
6610 |
"return a string for printing the receiver. |
|
6611 |
Since we now use printOn: as the basic print mechanism, |
|
6612 |
we have to create a stream and print into it." |
|
6613 |
||
6614 |
|s| |
|
6615 |
||
8300
d15ead94361f
Use CharacterWriteStream in #printString (speedup)
Stefan Vogel <sv@exept.de>
parents:
8287
diff
changeset
|
6616 |
s := CharacterWriteStream on:(String basicNew:30). |
5755 | 6617 |
self printOn:s. |
8300
d15ead94361f
Use CharacterWriteStream in #printString (speedup)
Stefan Vogel <sv@exept.de>
parents:
8287
diff
changeset
|
6618 |
^ s contents. |
7978
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6619 |
|
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6620 |
" |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6621 |
Date today printString. |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6622 |
" |
5755 | 6623 |
! |
6624 |
||
6625 |
printStringLeftPaddedTo:size |
|
6626 |
"return my printString as a right-adjusted string of length size; |
|
6627 |
characters on the left are filled with spaces. |
|
6628 |
If the printString is longer than size, |
|
6629 |
it is returned unchanged (i.e. not truncated)" |
|
6630 |
||
6631 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
6632 |
||
6633 |
" |
|
6634 |
10 printStringLeftPaddedTo:10 |
|
6635 |
1 printStringLeftPaddedTo:10 |
|
6636 |
" |
|
6637 |
! |
|
6638 |
||
6639 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
6640 |
"return my printString as a right-adjusted string of length size; |
|
6641 |
characters on the left are filled with spaces. |
|
6642 |
If the printString is larger than size, |
|
6643 |
return the result from evaluating alternative." |
|
6644 |
||
6645 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
6646 |
||
6647 |
" |
|
6648 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6649 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6650 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6651 |
" |
|
6652 |
! |
|
6653 |
||
6654 |
printStringLeftPaddedTo:size with:padCharacter |
|
6655 |
"return my printString as a right-adjusted string of length size; |
|
6656 |
characters on the left are filled with padCharacter. |
|
6657 |
If the printString is longer than size, |
|
6658 |
it is returned unchanged (i.e. not truncated)" |
|
6659 |
||
6660 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
6661 |
||
6662 |
" |
|
6663 |
123 printStringLeftPaddedTo:10 with:$. |
|
6664 |
1 printStringLeftPaddedTo:10 with:$. |
|
6665 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
|
6666 |
" |
|
6667 |
! |
|
6668 |
||
6669 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
6670 |
"return my printString as a right-adjusted string of length size; |
|
6671 |
characters on the left are filled with padCharacter. |
|
6672 |
If the printString is larger than size, |
|
6673 |
return the result from evaluating alternative." |
|
6674 |
||
6675 |
|s| |
|
6676 |
||
6677 |
s := self printString. |
|
6678 |
s size > size ifTrue:[^ alternative value]. |
|
6679 |
^ s leftPaddedTo:size with:padCharacter |
|
6680 |
||
6681 |
" |
|
6682 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6683 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6684 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6685 |
" |
|
6686 |
! |
|
6687 |
||
6688 |
printStringOnError:exceptionBlock |
|
6689 |
"return a string for printing the receiver; if any error occurs, return the result from |
|
6690 |
evaluating exceptionBlock. Useful to print something in an exceptionHandler or other |
|
6691 |
cleanup code." |
|
6692 |
||
6693 |
|rslt| |
|
6694 |
||
6695 |
Error handle:[:ex | |
|
6654 | 6696 |
rslt := exceptionBlock value |
5755 | 6697 |
] do:[ |
6654 | 6698 |
rslt := self printString |
5755 | 6699 |
]. |
6700 |
^ rslt |
|
6701 |
! |
|
6702 |
||
6703 |
printStringPaddedTo:size |
|
6704 |
"return a printed representation of the receiver, |
|
6705 |
padded with spaces (at the right) up to size. |
|
6706 |
If the printString is longer than size, |
|
6707 |
it is returned unchanged (i.e. not truncated)" |
|
6708 |
||
6709 |
^ self printStringPaddedTo:size with:(Character space) |
|
6710 |
||
6711 |
" |
|
6712 |
123 printStringPaddedTo:10 |
|
6713 |
1234567890123456 printStringPaddedTo:10 |
|
6714 |
'hello' printStringPaddedTo:10 |
|
6715 |
" |
|
6716 |
! |
|
6717 |
||
6718 |
printStringPaddedTo:size ifLarger:alternative |
|
6719 |
"return a printed representation of the receiver, |
|
6720 |
padded with spaces (at the right) up to size. |
|
6721 |
If the resulting printString is too large, |
|
6722 |
return the result from evaluating alternative." |
|
6723 |
||
6724 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
6725 |
||
6726 |
" |
|
6727 |
12 printStringPaddedTo:3 ifLarger:['***'] |
|
6728 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
6729 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
6730 |
" |
|
6731 |
! |
|
6732 |
||
6733 |
printStringPaddedTo:size with:padCharacter |
|
6734 |
"return a printed representation of the receiver, |
|
6735 |
padded with padCharacter (at the right) up to size. |
|
6736 |
If the printString is longer than size, |
|
6737 |
it is returned unchanged (i.e. not truncated)" |
|
6738 |
||
6739 |
^ (self printString) paddedTo:size with:padCharacter |
|
6740 |
||
6741 |
" |
|
6742 |
123 printStringPaddedTo:10 with:$. |
|
6743 |
123 printStringPaddedTo:10 with:$* |
|
6744 |
123 printStringPaddedTo:3 with:$* |
|
6745 |
1234 printStringPaddedTo:3 with:$* |
|
6746 |
" |
|
6747 |
! |
|
6748 |
||
6749 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
6750 |
"return a printed representation of the receiver, |
|
6751 |
padded with padCharacter (at the right) up to size. |
|
6752 |
If the resulting printString is too large, |
|
6753 |
return the result from evaluating alternative." |
|
6754 |
||
6755 |
|s| |
|
6756 |
||
6757 |
s := self printString. |
|
6758 |
s size > size ifTrue:[^ alternative value]. |
|
6759 |
^ s paddedTo:size with:padCharacter |
|
6760 |
||
6761 |
" |
|
6762 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6763 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6764 |
" |
|
6765 |
! |
|
6766 |
||
6767 |
printStringRightAdjustLen:size |
|
6768 |
"obsolete - just a name confusion. |
|
6769 |
This method will go away ..." |
|
6770 |
||
6771 |
^ self printStringLeftPaddedTo:size |
|
6772 |
! |
|
6773 |
||
6774 |
printStringZeroPaddedTo:size |
|
6775 |
"return a printed representation of the receiver, |
|
6776 |
padded with zero (at the right) characters up to size. |
|
6777 |
Usually used with float numbers." |
|
6778 |
||
6779 |
^ self printStringPaddedTo:size with:$0 |
|
6780 |
||
6781 |
" |
|
6782 |
123.0 printStringZeroPaddedTo:10 |
|
6783 |
" |
|
6784 |
! |
|
6785 |
||
8287 | 6786 |
printfPrintString:ignoredFormat |
6787 |
"fallback to default printString |
|
6788 |
(for compatibility with float and integer-printing)" |
|
6789 |
||
6790 |
^ self printString |
|
6791 |
! |
|
6792 |
||
5755 | 6793 |
store |
6794 |
"store the receiver on standard output. |
|
6795 |
this method is useless, but included for compatibility." |
|
6796 |
||
6797 |
self storeOn:Stdout |
|
6798 |
! |
|
6799 |
||
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6800 |
storeArrayElementOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6801 |
"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
|
6802 |
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
|
6803 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6804 |
^ 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
|
6805 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6806 |
|
5755 | 6807 |
storeCR |
6808 |
"store the receiver on standard output; append a carriage return." |
|
6809 |
||
6810 |
self store. |
|
6811 |
Character cr print |
|
6812 |
||
6813 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
6814 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
6815 |
! |
|
6816 |
||
6817 |
storeNl |
|
6818 |
"store the receiver on standard output; append a newline. |
|
6819 |
This method is included for backward compatibility- use #storeCR." |
|
6820 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6821 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6822 |
|
5755 | 6823 |
self storeCR. |
6824 |
||
6825 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
6826 |
! |
|
6827 |
||
6828 |
storeOn:aStream |
|
6829 |
"store the receiver on aStream; i.e. print an expression which will |
|
6830 |
reconstruct the receiver. |
|
6831 |
Notice, that no self referencing or cyclic objects can be represented |
|
6832 |
in this format. |
|
6833 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6834 |
||
6835 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
6836 |
||
6837 |
thisContext isRecursive ifTrue:[ |
|
6654 | 6838 |
Object recursiveStoreStringSignal raiseRequestWith:self. |
6839 |
('Object [error]: storeString of self referencing object.') errorPrintCR. |
|
6840 |
aStream nextPutAll:'#("recursive")'. |
|
6841 |
^ self |
|
5755 | 6842 |
]. |
6843 |
||
6844 |
myClass := self class. |
|
6845 |
aStream nextPut:$(. |
|
6846 |
aStream nextPutAll:self class name. |
|
6847 |
||
6848 |
hasSemi := false. |
|
6849 |
myClass isVariable ifTrue:[ |
|
6654 | 6850 |
aStream nextPutAll:' basicNew:'. |
6851 |
self basicSize printOn:aStream |
|
5755 | 6852 |
] ifFalse:[ |
6654 | 6853 |
aStream nextPutAll:' basicNew' |
5755 | 6854 |
]. |
6855 |
||
6856 |
sz := myClass instSize. |
|
6857 |
1 to:sz do:[:i | |
|
6654 | 6858 |
aStream nextPutAll:' instVarAt:'. |
6859 |
i printOn:aStream. |
|
6860 |
aStream nextPutAll:' put:'. |
|
6861 |
(self instVarAt:i) storeOn:aStream. |
|
6862 |
aStream nextPut:$;. |
|
6863 |
hasSemi := true |
|
5755 | 6864 |
]. |
6865 |
myClass isVariable ifTrue:[ |
|
6654 | 6866 |
sz := self basicSize. |
6867 |
1 to:sz do:[:i | |
|
6868 |
aStream nextPutAll:' basicAt:'. |
|
6869 |
i printOn:aStream. |
|
6870 |
aStream nextPutAll:' put:'. |
|
6871 |
(self basicAt:i) storeOn:aStream. |
|
6872 |
aStream nextPut:$;. |
|
6873 |
hasSemi := true |
|
6874 |
] |
|
5755 | 6875 |
]. |
6876 |
hasSemi ifTrue:[ |
|
6654 | 6877 |
aStream nextPutAll:' yourself' |
5755 | 6878 |
]. |
6879 |
aStream nextPut:$). |
|
6880 |
||
6881 |
" |
|
6882 |
|s| |
|
6883 |
||
6884 |
s := WriteStream on:(String new). |
|
6885 |
('hello' -> 'world') storeOn:s. |
|
6886 |
s := ReadStream on:(s contents). |
|
6887 |
(Object readFrom:s) inspect |
|
6888 |
" |
|
6889 |
" |
|
6890 |
|s| |
|
6891 |
||
6892 |
s := 'data' asFilename writeStream. |
|
6893 |
('hello' -> 'world') storeOn:s. |
|
6894 |
s close. |
|
6895 |
||
6896 |
s := 'data' asFilename readStream. |
|
6897 |
(Object readFrom:s) inspect |
|
6898 |
" |
|
6899 |
||
6900 |
"does not work example:" |
|
6901 |
" |
|
6902 |
|s a| |
|
6903 |
||
6904 |
a := Array new:2. |
|
6905 |
a at:1 put:a. |
|
6906 |
||
6907 |
s := 'data' asFilename writeStream. |
|
6908 |
a storeOn:s. |
|
6909 |
s close. |
|
6910 |
||
6911 |
s := 'data' asFilename readStream. |
|
6912 |
(Object readFrom:s) inspect |
|
6913 |
" |
|
6914 |
||
6915 |
"Modified: 28.1.1997 / 00:36:12 / cg" |
|
6916 |
! |
|
6917 |
||
6918 |
storeString |
|
6919 |
"return a string representing an expression to reconstruct the receiver. |
|
6920 |
Notice, that no self referencing or cyclic objects can be represented |
|
6921 |
in this format. |
|
6922 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6923 |
||
6924 |
|s| |
|
6925 |
||
6926 |
s := WriteStream on:(String new:50). |
|
6927 |
self storeOn:s. |
|
6928 |
^ s contents |
|
6929 |
! ! |
|
6930 |
||
6931 |
!Object methodsFor:'private'! |
|
6932 |
||
6933 |
isHierarchicalItem |
|
6934 |
"used to decide if the parent is a hierarchical item |
|
6935 |
or the model |
|
6936 |
" |
|
6937 |
^ false |
|
6938 |
! ! |
|
6939 |
||
6940 |
!Object methodsFor:'queries'! |
|
6941 |
||
6942 |
basicSize |
|
6943 |
"return the number of the receivers indexed instance variables, |
|
6944 |
0 if it has none. |
|
6945 |
||
6946 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
6947 |
||
6948 |
%{ /* NOCONTEXT */ |
|
6949 |
||
6950 |
REGISTER int nbytes; |
|
6951 |
REGISTER OBJ myClass; |
|
6952 |
int nInstBytes; |
|
6953 |
||
6954 |
/* |
|
6955 |
* notice the missing test for self being a nonNilObject - |
|
6956 |
* this can be done since basicSize is defined both in UndefinedObject |
|
6957 |
* and SmallInteger |
|
6958 |
*/ |
|
6959 |
myClass = __qClass(self); |
|
6960 |
nbytes = __qSize(self); |
|
6961 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) ); |
|
6962 |
||
6963 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
6654 | 6964 |
case __MASKSMALLINT(POINTERARRAY): |
6965 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
6966 |
nbytes -= nInstBytes; |
|
6967 |
RETURN ( __MKSMALLINT(__BYTES2OBJS__(nbytes)) ); |
|
6968 |
||
6969 |
case __MASKSMALLINT(BYTEARRAY): |
|
6970 |
nbytes -= nInstBytes; |
|
6971 |
RETURN ( __MKSMALLINT(nbytes / sizeof(char)) ); |
|
6972 |
||
6973 |
case __MASKSMALLINT(FLOATARRAY): |
|
6974 |
nbytes -= nInstBytes; |
|
6975 |
RETURN ( __MKSMALLINT(nbytes / sizeof(float)) ); |
|
6976 |
||
6977 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 6978 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 6979 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
5755 | 6980 |
#endif |
6654 | 6981 |
nbytes -= nInstBytes; |
6982 |
RETURN ( __MKSMALLINT(nbytes / sizeof(double)) ); |
|
6983 |
||
6984 |
case __MASKSMALLINT(WORDARRAY): |
|
6985 |
case __MASKSMALLINT(SWORDARRAY): |
|
6986 |
nbytes -= nInstBytes; |
|
6987 |
RETURN ( __MKSMALLINT(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */ |
|
6988 |
||
6989 |
case __MASKSMALLINT(LONGARRAY): |
|
6990 |
case __MASKSMALLINT(SLONGARRAY): |
|
6991 |
nbytes -= nInstBytes; |
|
6992 |
RETURN ( __MKSMALLINT(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */ |
|
6993 |
||
6994 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
6995 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 6996 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 6997 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
5755 | 6998 |
#endif |
6654 | 6999 |
nbytes -= nInstBytes; |
7000 |
RETURN ( __MKSMALLINT(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */ |
|
5755 | 7001 |
} |
7002 |
%}. |
|
7003 |
^ 0 |
|
7004 |
! |
|
7005 |
||
7006 |
byteSize |
|
7007 |
"return the number of bytes in the receivers indexed instance variables, |
|
7008 |
0 if it has none. This only returns non-zero for non-pointer indexed |
|
7009 |
instvars i.e. byteArrays, wordArrays etc. |
|
7010 |
Notice: for Strings the returned size may look strange. |
|
7011 |
Only useful with binary storage." |
|
7012 |
||
7013 |
|myClass| |
|
7014 |
||
7015 |
myClass := self class. |
|
7016 |
myClass isVariable ifTrue:[ |
|
6654 | 7017 |
myClass isPointers ifFalse:[ |
7018 |
myClass isBytes ifTrue:[ |
|
7019 |
^ self basicSize. |
|
7020 |
]. |
|
7021 |
myClass isWords ifTrue:[ |
|
7022 |
^ self basicSize * 2. |
|
7023 |
]. |
|
7024 |
myClass isSignedWords ifTrue:[ |
|
7025 |
^ self basicSize * 2. |
|
7026 |
]. |
|
7027 |
myClass isLongs ifTrue:[ |
|
7028 |
^ self basicSize * 4. |
|
7029 |
]. |
|
7030 |
myClass isSignedLongs ifTrue:[ |
|
7031 |
^ self basicSize * 4. |
|
7032 |
]. |
|
7033 |
myClass isLongLongs ifTrue:[ |
|
7034 |
^ self basicSize * 8. |
|
7035 |
]. |
|
7036 |
myClass isSignedLongLongs ifTrue:[ |
|
7037 |
^ self basicSize * 8. |
|
7038 |
]. |
|
7039 |
myClass isFloats ifTrue:[ |
|
7040 |
^ self basicSize * (ExternalBytes sizeofFloat) |
|
7041 |
]. |
|
7042 |
myClass isDoubles ifTrue:[ |
|
7043 |
^ self basicSize * (ExternalBytes sizeofDouble) |
|
7044 |
]. |
|
7045 |
self halt:'oops'. |
|
7046 |
] |
|
5755 | 7047 |
]. |
7048 |
^ 0 |
|
7049 |
||
7050 |
" |
|
7051 |
Point new byteSize |
|
7052 |
'hello' byteSize |
|
7053 |
(ByteArray with:1 with:2) byteSize |
|
7054 |
(FloatArray with:1.5) byteSize |
|
7055 |
(DoubleArray with:1.5) byteSize |
|
7056 |
(WordArray with:1 with:2) byteSize |
|
7057 |
" |
|
7058 |
! |
|
7059 |
||
7060 |
class |
|
7061 |
"return the receivers class" |
|
7062 |
||
7063 |
%{ /* NOCONTEXT */ |
|
7064 |
||
7065 |
RETURN ( __Class(self) ); |
|
7066 |
%} |
|
7067 |
! |
|
7068 |
||
7069 |
respondsTo:aSelector |
|
7070 |
"return true, if the receiver implements a method with selector equal |
|
7071 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
7072 |
receivers class or one of its superclasses. |
|
7073 |
||
7074 |
Notice, that this does not imply, that such a message can be sent without |
|
7075 |
an error being raised. For example, an implementation could send |
|
7076 |
#shouldNotImplement or #subclassResponsibility." |
|
7077 |
||
7078 |
" |
|
7079 |
should we go via the cache, or search (by class) ? |
|
7080 |
The first is faster, most of the time; while the 2nd fills |
|
7081 |
the cache with useless data if this is sent in a loop over all objects. |
|
7082 |
For now, use the cache ... |
|
7083 |
" |
|
7084 |
%{ /* NOCONTEXT */ |
|
7085 |
||
7086 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
6654 | 7087 |
RETURN ( false ); |
5755 | 7088 |
} |
7089 |
RETURN ( true ); |
|
7090 |
%} |
|
7091 |
. |
|
7092 |
^ self class canUnderstand:aSelector |
|
7093 |
||
7094 |
||
7095 |
"'aString' respondsTo:#+" |
|
7096 |
"'aString' respondsTo:#," |
|
7097 |
"'aString' respondsTo:#collect:" |
|
7098 |
! |
|
7099 |
||
7100 |
respondsToArithmetic |
|
7101 |
"return true, if the receiver responds to arithmetic messages. |
|
7102 |
false is returned here - the method is redefined in ArithmeticValue." |
|
7103 |
||
7104 |
^ false |
|
7105 |
! |
|
7106 |
||
7107 |
size |
|
7108 |
"return the number of the receivers indexed instance variables; |
|
7109 |
this method may be redefined in subclasses" |
|
7110 |
||
7111 |
^ self basicSize |
|
7112 |
! |
|
7113 |
||
7114 |
species |
|
7115 |
"return a class which is similar to (or the same as) the receivers class. |
|
7116 |
This is used to create an appropriate object when creating derived |
|
7117 |
copies in the collection classes (sometimes redefined)." |
|
7118 |
||
7119 |
^ self class |
|
7120 |
! |
|
7121 |
||
7122 |
yourself |
|
7123 |
"return the receiver - used for cascades to return self at the end" |
|
7124 |
||
7125 |
^ self |
|
7126 |
! ! |
|
7127 |
||
7128 |
!Object methodsFor:'secure message sending'! |
|
7129 |
||
7130 |
askFor:aSelector |
|
7131 |
"try to send the receiver the message, aSelector. |
|
7132 |
If it does not understand it, return false. |
|
7133 |
Otherwise the real value returned. |
|
7134 |
Useful to send messages such as: #isColor to unknown |
|
7135 |
receivers." |
|
7136 |
||
7137 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
7138 |
||
7139 |
" |
|
7140 |
1 askFor:#isColor |
|
7141 |
Color red askFor:#isColor |
|
7142 |
||
7143 |
1 askFor:#isFoo |
|
7144 |
Color red askFor:#isFoo |
|
7145 |
" |
|
7146 |
! |
|
7147 |
||
7148 |
perform:aSelector ifNotUnderstood:exceptionBlock |
|
7149 |
"try to send message aSelector to the receiver. |
|
7150 |
If its understood, return the methods returned value, |
|
7151 |
otherwise return the value of the exceptionBlock" |
|
7152 |
||
7153 |
|val ok| |
|
7154 |
||
6146 | 7155 |
MessageNotUnderstood handle:[:ex | |
6654 | 7156 |
"/ reject, if the bad message is not the one |
7157 |
"/ we have sent originally |
|
7158 |
ex parameter selector == aSelector ifFalse:[ |
|
7159 |
ex reject |
|
6741
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7160 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7161 |
ex receiver == self ifFalse:[ |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7162 |
ex reject |
8413 | 7163 |
]. |
5755 | 7164 |
] do:[ |
6654 | 7165 |
val := self perform:aSelector. |
7166 |
ok := true. |
|
5755 | 7167 |
]. |
7168 |
ok isNil ifTrue:[ |
|
6654 | 7169 |
^ exceptionBlock value |
5755 | 7170 |
]. |
7171 |
^ val |
|
7172 |
||
7173 |
" |
|
7174 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
|
7175 |
1.2345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7176 |
12345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7177 |
" |
|
7178 |
! |
|
7179 |
||
7180 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
7181 |
"try to send message aSelector to the receiver. |
|
7182 |
If its understood, return the methods returned value, |
|
7183 |
otherwise return the value of the exceptionBlock" |
|
7184 |
||
7185 |
|val ok| |
|
7186 |
||
7187 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6654 | 7188 |
"/ reject, if the bad message is not the one |
7189 |
"/ we have sent originally |
|
7190 |
ex parameter selector == aSelector ifFalse:[ |
|
7191 |
ex reject |
|
6741
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7192 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7193 |
ex receiver == self ifFalse:[ |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7194 |
ex reject |
6654 | 7195 |
] |
5755 | 7196 |
] do:[ |
6654 | 7197 |
val := self perform:aSelector with:argument. |
7198 |
ok := true. |
|
5755 | 7199 |
]. |
7200 |
ok isNil ifTrue:[ |
|
6654 | 7201 |
^ exceptionBlock value |
5755 | 7202 |
]. |
7203 |
^ val |
|
7204 |
||
7205 |
" |
|
7206 |
|unknown| |
|
7207 |
||
7208 |
unknown := 1. |
|
7209 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7210 |
unknown := 'high there'. |
|
7211 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7212 |
" |
|
7213 |
! |
|
7214 |
||
5926 | 7215 |
perform:aSelector with:arg1 with:arg2 ifNotUnderstood:exceptionBlock |
7216 |
"try to send message aSelector to the receiver. |
|
7217 |
If its understood, return the methods returned value, |
|
7218 |
otherwise return the value of the exceptionBlock" |
|
7219 |
||
7220 |
|val ok| |
|
7221 |
||
7222 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6654 | 7223 |
"/ reject, if the bad message is not the one |
7224 |
"/ we have sent originally |
|
7225 |
ex parameter selector == aSelector ifFalse:[ |
|
7226 |
ex reject |
|
6741
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7227 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7228 |
ex receiver == self ifFalse:[ |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7229 |
ex reject |
6654 | 7230 |
] |
5926 | 7231 |
] do:[ |
6654 | 7232 |
val := self perform:aSelector with:arg1 with:arg2. |
7233 |
ok := true. |
|
5926 | 7234 |
]. |
7235 |
ok isNil ifTrue:[ |
|
6654 | 7236 |
^ exceptionBlock value |
5926 | 7237 |
]. |
7238 |
^ val |
|
7239 |
||
7240 |
" |
|
7241 |
|unknown| |
|
7242 |
||
7243 |
unknown := 1. |
|
7244 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7245 |
unknown := 'high there'. |
|
7246 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
7247 |
" |
|
7248 |
! |
|
7249 |
||
5755 | 7250 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
7251 |
"try to send message aSelector to the receiver. |
|
7252 |
If its understood, return the methods returned value, |
|
7253 |
otherwise return the value of the exceptionBlock" |
|
7254 |
||
7255 |
|val ok| |
|
7256 |
||
7257 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6654 | 7258 |
"/ reject, if the bad message is not the one |
7259 |
"/ we have sent originally |
|
7260 |
ex parameter selector == aSelector ifFalse:[ |
|
7261 |
ex reject |
|
6741
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7262 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7263 |
ex receiver == self ifFalse:[ |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7264 |
ex reject |
6654 | 7265 |
] |
5755 | 7266 |
] do:[ |
6654 | 7267 |
val := self perform:aSelector withArguments:argumentArray. |
7268 |
ok := true. |
|
5755 | 7269 |
]. |
7270 |
ok isNil ifTrue:[ |
|
6654 | 7271 |
^ exceptionBlock value |
5755 | 7272 |
]. |
7273 |
^ val |
|
7274 |
||
7275 |
" |
|
7276 |
|unknown| |
|
7277 |
||
7278 |
unknown := 1. |
|
7279 |
(unknown perform:#+ withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
|
7280 |
unknown := 'high there'. |
|
7281 |
(unknown perform:#+ withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
|
7282 |
" |
|
7283 |
||
7284 |
"Modified: 27.3.1997 / 14:13:16 / cg" |
|
7285 |
! ! |
|
7286 |
||
7287 |
!Object methodsFor:'signal constants'! |
|
7288 |
||
7289 |
messageNotUnderstoodSignal |
|
6146 | 7290 |
^ MessageNotUnderstood |
5755 | 7291 |
|
7292 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
7293 |
! ! |
|
7294 |
||
7295 |
!Object methodsFor:'special queries'! |
|
7296 |
||
7297 |
allOwners |
|
7298 |
"return a collection of all objects referencing the receiver" |
|
7299 |
||
7300 |
^ ObjectMemory whoReferences:self |
|
7301 |
! |
|
7302 |
||
7303 |
references:anObject |
|
7304 |
"return true, if the receiver refers to the argument, anObject. |
|
7305 |
- for debugging only" |
|
7306 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7307 |
^ self referencesObject:anObject |
5755 | 7308 |
|
7309 |
" |
|
7310 |
|v| |
|
7311 |
||
7312 |
v := View new initialize. |
|
7313 |
v references:Display. |
|
7314 |
" |
|
7315 |
! |
|
7316 |
||
7317 |
referencesAny:aCollection |
|
7318 |
"return true, if the receiver refers to any object from |
|
7319 |
the argument, aCollection. |
|
7320 |
- for debugging only" |
|
7321 |
||
7322 |
%{ |
|
7323 |
OBJ cls, flags; |
|
7324 |
int nInsts, inst; |
|
7325 |
||
7326 |
if (! __isNonNilObject(self)) { |
|
6654 | 7327 |
RETURN (false); |
5755 | 7328 |
} |
7329 |
||
7330 |
if (__isArray(aCollection)) { |
|
6654 | 7331 |
int nObjs = __arraySize(aCollection); |
7332 |
char *minAddr = 0, *maxAddr = 0; |
|
7333 |
||
7334 |
if (nObjs == 0) { |
|
7335 |
RETURN (false); |
|
7336 |
} |
|
7337 |
||
7338 |
/* |
|
7339 |
* a little optimization: use the fact that all old objects |
|
7340 |
* refering to a new object are on the remSet; if I am not, |
|
7341 |
* a trivial reject is possible, if all objects are newbees. |
|
7342 |
* as a side effect, gather min/max addresses |
|
7343 |
*/ |
|
7344 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
7345 |
int allNewBees = 1; |
|
7346 |
int i; |
|
7347 |
||
7348 |
minAddr = (char *)(__ArrayInstPtr(aCollection)->a_element[0]); |
|
7349 |
maxAddr = minAddr; |
|
7350 |
||
7351 |
for (i=0; i<nObjs; i++) { |
|
7352 |
OBJ anObject; |
|
7353 |
||
7354 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7355 |
||
7356 |
if (__isNonNilObject(anObject)) { |
|
7357 |
int spc; |
|
7358 |
||
7359 |
if (((spc = __qSpace(anObject)) != NEWSPACE) && (spc != SURVSPACE)) { |
|
7360 |
allNewBees = 0; |
|
7361 |
} |
|
7362 |
} |
|
7363 |
||
7364 |
if ((char *)anObject < minAddr) { |
|
7365 |
minAddr = (char *)anObject; |
|
7366 |
} else if ((char *)anObject > maxAddr) { |
|
7367 |
maxAddr = (char *)anObject; |
|
7368 |
} |
|
7369 |
} |
|
7370 |
if (allNewBees) { |
|
7371 |
RETURN (false); |
|
7372 |
} |
|
7373 |
} |
|
7374 |
||
7375 |
/* |
|
7376 |
* fetch min/max in searchList (if not already done) |
|
7377 |
*/ |
|
7378 |
if (minAddr == 0) { |
|
7379 |
int i; |
|
7380 |
||
7381 |
for (i=0; i<nObjs; i++) { |
|
7382 |
OBJ anObject; |
|
7383 |
||
7384 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7385 |
if ((char *)anObject < minAddr) { |
|
7386 |
minAddr = (char *)anObject; |
|
7387 |
} else if ((char *)anObject > maxAddr) { |
|
7388 |
maxAddr = (char *)anObject; |
|
7389 |
} |
|
7390 |
} |
|
7391 |
} |
|
7392 |
||
7393 |
cls = __qClass(self); |
|
7394 |
if (((char *)cls >= minAddr) && ((char *)cls <= maxAddr)) { |
|
5755 | 7395 |
#if defined(memsrch4) |
6654 | 7396 |
if (memsrch4(__arrayVal(aCollection), (INT)cls, nObjs)) { |
7397 |
RETURN (true); |
|
7398 |
} |
|
5755 | 7399 |
#else |
6654 | 7400 |
int i; |
7401 |
||
7402 |
for (i=0; i<nObjs; i++) { |
|
7403 |
OBJ anObject; |
|
7404 |
||
7405 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7406 |
if (cls == anObject) { |
|
7407 |
RETURN (true); |
|
7408 |
} |
|
7409 |
} |
|
5755 | 7410 |
#endif /* memsrch4 */ |
6654 | 7411 |
} |
7412 |
||
7413 |
flags = __ClassInstPtr(cls)->c_flags; |
|
7414 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
7415 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
7416 |
} else { |
|
7417 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
7418 |
} |
|
7419 |
if (! nInsts) { |
|
7420 |
RETURN (false); |
|
7421 |
} |
|
7422 |
||
7423 |
if (nObjs == 1) { |
|
7424 |
/* better reverse the loop */ |
|
7425 |
OBJ anObject; |
|
7426 |
||
7427 |
anObject = __ArrayInstPtr(aCollection)->a_element[0]; |
|
5755 | 7428 |
#if defined(memsrch4) |
6654 | 7429 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
7430 |
RETURN (true); |
|
7431 |
} |
|
5755 | 7432 |
#else |
6654 | 7433 |
for (inst=0; inst<nInsts; inst++) { |
7434 |
if ((__InstPtr(self)->i_instvars[inst]) == anObject) { |
|
7435 |
RETURN (true); |
|
7436 |
} |
|
7437 |
} |
|
5755 | 7438 |
#endif |
6654 | 7439 |
RETURN (false); |
7440 |
} |
|
7441 |
||
7442 |
for (inst=0; inst<nInsts; inst++) { |
|
7443 |
OBJ instVar = __InstPtr(self)->i_instvars[inst]; |
|
7444 |
int i; |
|
7445 |
||
7446 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
5755 | 7447 |
#if defined(memsrch4) |
6654 | 7448 |
if (memsrch4(__arrayVal(aCollection), (INT)instVar, nObjs)) { |
7449 |
RETURN (true); |
|
7450 |
} |
|
5755 | 7451 |
#else |
6654 | 7452 |
for (i=0; i<nObjs; i++) { |
7453 |
OBJ anObject; |
|
7454 |
||
7455 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7456 |
if (instVar == anObject) { |
|
7457 |
RETURN (true); |
|
7458 |
} |
|
7459 |
} |
|
5755 | 7460 |
#endif /* memsrch4 */ |
6654 | 7461 |
} |
7462 |
} |
|
7463 |
RETURN (false); |
|
5755 | 7464 |
} |
7465 |
%}. |
|
7466 |
||
7467 |
aCollection do:[:el | |
|
6654 | 7468 |
(self references:el) ifTrue:[^ true]. |
5755 | 7469 |
]. |
7470 |
^ false |
|
7471 |
! |
|
7472 |
||
7473 |
referencesDerivedInstanceOf:aClass |
|
7474 |
"return true, if the receiver refers to an instance of |
|
7475 |
the argument, aClass or its subclass. This method exists |
|
7476 |
to support searching for users of a class." |
|
7477 |
||
7478 |
|myClass |
|
7479 |
numInst "{ Class: SmallInteger }" | |
|
7480 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7481 |
"check the class" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7482 |
(self isKindOf:aClass) ifTrue:[^ true]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7483 |
|
5755 | 7484 |
myClass := self class. |
7485 |
"check the instance variables" |
|
7486 |
numInst := myClass instSize. |
|
7487 |
1 to:numInst do:[:i | |
|
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7488 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
5755 | 7489 |
]. |
7490 |
||
7491 |
"check the indexed variables" |
|
7492 |
myClass isVariable ifTrue:[ |
|
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7493 |
myClass isPointers ifFalse:[ |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7494 |
"no need to search in non pointer fields" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7495 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7496 |
]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7497 |
numInst := self basicSize. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7498 |
1 to:numInst do:[:i | |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7499 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7500 |
] |
5755 | 7501 |
]. |
7502 |
^ false |
|
7503 |
||
7504 |
" |
|
7505 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
|
7506 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
7507 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
7508 |
" |
|
7509 |
! |
|
7510 |
||
7511 |
referencesInstanceOf:aClass |
|
7512 |
"return true, if the receiver refers to an instance of |
|
7513 |
the argument, aClass.This method exists |
|
7514 |
to support searching for users of a class." |
|
7515 |
||
7516 |
|myClass |
|
7517 |
numInst "{ Class: SmallInteger }" | |
|
7518 |
||
7519 |
myClass := self class. |
|
7520 |
||
7521 |
"check the class" |
|
7522 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
7523 |
||
7524 |
"check the instance variables" |
|
7525 |
numInst := myClass instSize. |
|
7526 |
1 to:numInst do:[:i | |
|
6654 | 7527 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
5755 | 7528 |
]. |
7529 |
||
7530 |
"check the indexed variables" |
|
7531 |
myClass isVariable ifTrue:[ |
|
6654 | 7532 |
myClass isPointers ifFalse:[ |
7533 |
"no need to search in non-pointer indexed fields" |
|
7534 |
myClass isLongs ifTrue:[ |
|
7535 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
7536 |
] ifFalse:[ |
|
7537 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
7538 |
^ aClass == SmallInteger |
|
7539 |
] |
|
7540 |
]. |
|
7541 |
numInst := self basicSize. |
|
7542 |
1 to:numInst do:[:i | |
|
7543 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
7544 |
] |
|
5755 | 7545 |
]. |
7546 |
^ false |
|
7547 |
||
7548 |
" |
|
7549 |
(1 @ 3.4) referencesInstanceOf:Float |
|
7550 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
7551 |
View new initialize referencesInstanceOf:(Display class) |
|
7552 |
" |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7553 |
! |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7554 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7555 |
referencesObject:anObject |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7556 |
"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
|
7557 |
- for debugging only" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7558 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7559 |
%{ /* NOCONTEXT */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7560 |
OBJ cls, flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7561 |
int nInsts, i; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7562 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7563 |
if (! __isNonNilObject(self)) { |
6654 | 7564 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7565 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7566 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7567 |
/* |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7568 |
* 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
|
7569 |
* 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
|
7570 |
* 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
|
7571 |
*/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7572 |
if (__isNonNilObject(anObject)) { |
6654 | 7573 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7574 |
int spc; |
|
7575 |
||
7576 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7577 |
RETURN (false); |
|
7578 |
} |
|
7579 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7580 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7581 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7582 |
cls = __qClass(self); |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7583 |
if (cls == anObject) { |
6654 | 7584 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7585 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7586 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7587 |
flags = __ClassInstPtr(cls)->c_flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7588 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
6654 | 7589 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7590 |
} else { |
6654 | 7591 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7592 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7593 |
if (! nInsts) { |
6654 | 7594 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7595 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7596 |
#if defined(memsrch4) |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7597 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
6654 | 7598 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7599 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7600 |
#else |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7601 |
for (i=0; i<nInsts; i++) { |
6654 | 7602 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7603 |
RETURN (true); |
|
7604 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7605 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7606 |
#endif /* memsrch4 */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7607 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7608 |
%}. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7609 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7610 |
"/ |myClass |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7611 |
"/ numInst "{ Class: SmallInteger }" | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7612 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7613 |
"/ myClass := self class. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7614 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7615 |
"/ "check the class" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7616 |
"/ (myClass == anObject) ifTrue:[^ true]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7617 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7618 |
"/ "check the instance variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7619 |
"/ numInst := myClass instSize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7620 |
"/ 1 to:numInst do:[:i | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7621 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7622 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7623 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7624 |
"/ "check the indexed variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7625 |
"/ myClass isVariable ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7626 |
"/ myClass isPointers ifFalse:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7627 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7628 |
"/ "/ 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
|
7629 |
"/ "/ 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
|
7630 |
"/ "/ 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
|
7631 |
"/ "/ 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
|
7632 |
"/ "/ 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
|
7633 |
"/ "/ 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
|
7634 |
"/ "/ 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
|
7635 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7636 |
"/ ^ false. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7637 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7638 |
"/ "/ alternative: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7639 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7640 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7641 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7642 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7643 |
"/ "/ 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
|
7644 |
"/ "/ idenitytIndex method, use it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7645 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7646 |
"/ myClass == Array ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7647 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7648 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7649 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7650 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7651 |
"/ "/ otherwise, do it the slow way |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7652 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7653 |
"/ numInst := self basicSize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7654 |
"/ 1 to:numInst do:[:i | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7655 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7656 |
"/ ] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7657 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7658 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7659 |
^ false |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7660 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7661 |
" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7662 |
|v| |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7663 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7664 |
v := View new initialize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7665 |
v references:Display. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7666 |
" |
5755 | 7667 |
! ! |
7668 |
||
7669 |
!Object methodsFor:'synchronized evaluation'! |
|
7670 |
||
7671 |
freeSynchronizationSemaphore |
|
7672 |
"free synchronizationSemaphore. May be used, to save memory when |
|
7673 |
an object is no longer used synchronized." |
|
7674 |
||
7675 |
|sema| |
|
7676 |
||
7677 |
sema := self synchronizationSemaphore. |
|
7678 |
sema notNil ifTrue:[ |
|
6654 | 7679 |
sema wait. "/ get lock |
7680 |
self synchronizationSemaphore:nil. |
|
5755 | 7681 |
]. |
7682 |
||
7683 |
" |
|
7684 |
self synchronized:[]. |
|
7685 |
self synchronizationSemaphore. |
|
7686 |
self freeSynchronizationSemaphore. |
|
7687 |
" |
|
7688 |
||
7689 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
7690 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
7691 |
! |
|
7692 |
||
7693 |
synchronizationSemaphore |
|
7694 |
"return the synchronization semaphore for myself. |
|
7695 |
subclasses may redefine" |
|
7696 |
||
7697 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
7698 |
||
7699 |
" |
|
7700 |
self synchronizationSemaphore |
|
7701 |
" |
|
7702 |
||
7703 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
7704 |
! |
|
7705 |
||
7706 |
synchronizationSemaphore:aSemaphore |
|
7707 |
"set the synchronisationSemaphore for myself. |
|
7708 |
subclasses may redefine this method" |
|
7709 |
||
7710 |
aSemaphore isNil ifTrue:[ |
|
6654 | 7711 |
"/ remove Semaphore |
7712 |
SynchronizationSemaphores removeKey:self ifAbsent:nil. |
|
5755 | 7713 |
] ifFalse:[ |
6654 | 7714 |
SynchronizationSemaphores at:self put:aSemaphore. |
5755 | 7715 |
]. |
7716 |
||
7717 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
7718 |
! |
|
7719 |
||
7720 |
synchronized:aBlock |
|
7721 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
7722 |
||
6600 | 7723 |
|sema wasBlocked| |
7724 |
||
7725 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5755 | 7726 |
|
7727 |
sema := self synchronizationSemaphore. |
|
7728 |
sema isNil ifTrue:[ |
|
8481
d12d202b6ddb
Set name of synchronization sema
Stefan Vogel <sv@exept.de>
parents:
8441
diff
changeset
|
7729 |
sema := RecursionLock new name:self className. |
6600 | 7730 |
self synchronizationSemaphore:sema. |
5755 | 7731 |
]. |
7732 |
||
6600 | 7733 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
7211
87f5d25b5c3d
Make synchronizationSemaphore a recursionLock
Stefan Vogel <sv@exept.de>
parents:
7208
diff
changeset
|
7734 |
sema critical:aBlock. |
5755 | 7735 |
|
7736 |
" |
|
7737 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
7738 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
7739 |
" |
|
7740 |
||
7741 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
7742 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
|
7743 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
|
7744 |
! ! |
|
7745 |
||
7746 |
!Object methodsFor:'system primitives'! |
|
7747 |
||
7748 |
asOop |
|
7749 |
"ST-80 compatibility: |
|
7750 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
7751 |
or index); since ST/X has no such thing, and the objects address cannot |
|
7752 |
be used (since its changing over time), we return the objects identityHash |
|
7753 |
key, which provides (at least) some identity indication. |
|
7754 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
7755 |
key of two non-identical objects may be the same. |
|
7756 |
You'd better not use it - especially do not misuse it." |
|
7757 |
||
7758 |
^ self identityHash |
|
7759 |
||
7760 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
7761 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
7762 |
! |
|
7763 |
||
7764 |
become:anotherObject |
|
7765 |
"make all references to the receiver become references to anotherObject |
|
7766 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
|
7767 |
This can be a very dangerous operation - be warned. |
|
7768 |
In general, using #become: should be avoided if possible, since it may |
|
7769 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
7770 |
||
7771 |
This may also be an expensive (i.e. slow) operation, |
|
7772 |
since in the worst case, the whole memory has to be searched for |
|
7773 |
references to the two objects (although the primitive tries hard to |
|
7774 |
limit the search, for acceptable performance in most cases). |
|
7775 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7776 |
or nil, or is a context of a living method (i.e. one that has not already |
|
7777 |
returned). |
|
7778 |
(notice that #become: is not used heavily by the system |
|
7779 |
- the Collection-classes have been rewritten to not use it.)" |
|
7780 |
%{ |
|
7781 |
if (__primBecome(self, anotherObject)) { |
|
6654 | 7782 |
RETURN ( self ); |
5755 | 7783 |
} |
7784 |
%}. |
|
7785 |
self primitiveFailed |
|
7786 |
! |
|
7787 |
||
7788 |
becomeNil |
|
7789 |
"make all references to the receiver become nil - effectively getting |
|
7790 |
rid of the receiver. |
|
7791 |
This can be a very dangerous operation - be warned. |
|
7792 |
||
7793 |
This may be an expensive (i.e. slow) operation. |
|
7794 |
The receiver may not be a SmallInteger or a context of a living method." |
|
7795 |
||
7796 |
%{ |
|
7797 |
if (__primBecomeNil(self)) { |
|
6654 | 7798 |
RETURN ( nil ); |
5755 | 7799 |
} |
7800 |
%}. |
|
7801 |
self primitiveFailed |
|
7802 |
! |
|
7803 |
||
7804 |
becomeSameAs:anotherObject |
|
7805 |
"make all references to the receiver become references to anotherObject |
|
7806 |
but NOT vice versa (as done in #become:). |
|
7807 |
This can be a very dangerous operation - be warned. |
|
7808 |
In general, using #become: should be avoided if possible, since it may |
|
7809 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
7810 |
||
7811 |
This may also be an expensive (i.e. slow) operation, |
|
7812 |
since in the worst case, the whole memory has to be searched for |
|
7813 |
references to the two objects (although the primitive tries hard to |
|
7814 |
limit the search, for acceptable performance in most cases). |
|
7815 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7816 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
7817 |
%{ |
|
7818 |
if (__primBecomeSameAs(self, anotherObject)) { |
|
6654 | 7819 |
RETURN ( self ); |
5755 | 7820 |
} |
7821 |
%}. |
|
7822 |
self primitiveFailed |
|
7823 |
! |
|
7824 |
||
7825 |
changeClassTo:otherClass |
|
7826 |
"changes the class of the receiver to the argument, otherClass. |
|
7827 |
This is only allowed (possible), if the receivers class and the argument |
|
7828 |
have the same structure (i.e. number of named instance variables and |
|
7829 |
type of indexed instance variables). |
|
7830 |
If the structures do not match, or any of the original class or new class |
|
7831 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
7832 |
||
7833 |
|myClass ok| |
|
7834 |
||
7835 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
|
7202
85178c4cefe0
ensure that other class is autoloaded in changeClassTo:
penk
parents:
7177
diff
changeset
|
7836 |
otherClass autoload. |
5755 | 7837 |
%{ |
7838 |
{ |
|
6533 | 7839 |
OBJ other = otherClass; |
7840 |
||
7841 |
if (__isNonNilObject(self) |
|
7842 |
&& __isNonNilObject(other) |
|
7843 |
&& (other != UndefinedObject) |
|
7844 |
&& (other != SmallInteger)) { |
|
7845 |
ok = true; |
|
7846 |
} else { |
|
7847 |
ok = false; |
|
7848 |
} |
|
5755 | 7849 |
} |
7850 |
%}. |
|
7851 |
ok ifTrue:[ |
|
6533 | 7852 |
ok := false. |
7853 |
myClass := self class. |
|
7854 |
myClass flags == otherClass flags ifTrue:[ |
|
7855 |
myClass instSize == otherClass instSize ifTrue:[ |
|
7856 |
"same instance layout and types: its ok to do it" |
|
7857 |
ok := true. |
|
7858 |
] ifFalse:[ |
|
7859 |
myClass isPointers ifTrue:[ |
|
7860 |
myClass isVariable ifTrue:[ |
|
7861 |
ok := true |
|
7862 |
] |
|
7863 |
] |
|
7864 |
] |
|
7865 |
] ifFalse:[ |
|
7866 |
myClass isPointers ifTrue:[ |
|
7867 |
"if newClass is a variable class, with instSize <= my instsize, |
|
7868 |
we can do it (effectively mapping additional instvars into the |
|
7869 |
variable part) - usefulness is questionable, though" |
|
7870 |
||
7871 |
otherClass isPointers ifTrue:[ |
|
7872 |
otherClass isVariable ifTrue:[ |
|
7873 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
7874 |
ifTrue:[ |
|
7875 |
ok := true |
|
7876 |
] |
|
7877 |
] ifFalse:[ |
|
7878 |
otherClass instSize == (myClass instSize + self basicSize) |
|
7879 |
ifTrue:[ |
|
7880 |
ok := true |
|
7881 |
] |
|
7882 |
] |
|
7883 |
] ifFalse:[ |
|
7884 |
"it does not make sense to convert pointers to bytes ..." |
|
7885 |
] |
|
7886 |
] ifFalse:[ |
|
7887 |
"does it make sense, to convert bits ?" |
|
7888 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
7889 |
(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[ |
|
7890 |
ok := true |
|
7891 |
] |
|
7892 |
] |
|
7893 |
] |
|
5755 | 7894 |
]. |
7895 |
ok ifTrue:[ |
|
6533 | 7896 |
"now, change the receivers class ..." |
5755 | 7897 |
%{ |
6533 | 7898 |
{ |
7899 |
OBJ me = self; |
|
7900 |
||
7901 |
__qClass(me) = otherClass; |
|
7902 |
__STORE(me, otherClass); |
|
7903 |
RETURN (me); |
|
7904 |
} |
|
5755 | 7905 |
%}. |
7906 |
]. |
|
6533 | 7907 |
otherClass isLoaded ifFalse:[ |
7908 |
^ self changeClassTo:(otherClass autoload). |
|
7909 |
]. |
|
5755 | 7910 |
" |
7911 |
the receiver cannot be represented as a instance of |
|
7912 |
the desired class. |
|
7913 |
For example, you cannot change a bitInstance (byteArray etc.) |
|
7914 |
into a pointer object and vice versa. |
|
7915 |
" |
|
7916 |
self primitiveFailed |
|
7917 |
! |
|
7918 |
||
7919 |
changeClassToThatOf:anObject |
|
7920 |
"changes the class of the receiver to that of the argument, anObject. |
|
7921 |
This is only allowed (possible), if the receivers class and the arguments |
|
7922 |
class have the same structure (i.e. number of named instance variables and |
|
7923 |
type of indexed instance variables). If the structures do not match, or any |
|
7924 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
7925 |
||
7926 |
self changeClassTo:(anObject class) |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7927 |
! |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7928 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7929 |
replaceReferencesTo:anObject with:newRef |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7930 |
"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
|
7931 |
Return true, if any reference was changed. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7932 |
Notice: this does not change the class-reference." |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7933 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7934 |
%{ /* NOCONTEXT */ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7935 |
OBJ cls, flags, anyChange; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7936 |
int nInsts, i; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7937 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7938 |
if (! __isNonNilObject(self)) { |
6654 | 7939 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7940 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7941 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7942 |
/* |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7943 |
* a little optimization: use the fact that all old objects |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7944 |
* 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
|
7945 |
* a trivial reject is possible, if anObject is a newbee |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7946 |
*/ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7947 |
if (__isNonNilObject(anObject)) { |
6654 | 7948 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7949 |
int spc; |
|
7950 |
||
7951 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7952 |
RETURN (false); |
|
7953 |
} |
|
7954 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7955 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7956 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7957 |
cls = __qClass(self); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7958 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7959 |
flags = __ClassInstPtr(cls)->c_flags; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7960 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
6654 | 7961 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7962 |
} else { |
6654 | 7963 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7964 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7965 |
if (! nInsts) { |
6654 | 7966 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7967 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7968 |
anyChange = false; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7969 |
for (i=0; i<nInsts; i++) { |
6654 | 7970 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7971 |
__InstPtr(self)->i_instvars[i] = newRef; |
|
7972 |
__STORE(self, newRef); |
|
7973 |
anyChange = true; |
|
7974 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7975 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7976 |
RETURN (anyChange); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7977 |
%}. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7978 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7979 |
" |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7980 |
|v| |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7981 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7982 |
v := Array with:1234 with:'hello' with:Array. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7983 |
v replaceReferencesTo:Array with:ByteArray. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7984 |
v inspect |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7985 |
" |
5755 | 7986 |
! ! |
7987 |
||
7988 |
!Object methodsFor:'testing'! |
|
7989 |
||
7990 |
? defaultValue |
|
7991 |
"a syntactic shugar-piece: |
|
7992 |
if the receiver is nil, return the defaultValue; |
|
7993 |
otherwise, return the receiver. |
|
7994 |
This method is only redefined in UndefinedObject - therefore, |
|
7995 |
the recevier is retuned here. |
|
7996 |
||
7997 |
Thus, if foo and bar are simple variables or constants, |
|
6654 | 7998 |
foo ? bar |
5755 | 7999 |
is the same as: |
6654 | 8000 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
5755 | 8001 |
|
8002 |
if they are message sends, the equivalent code is: |
|
6654 | 8003 |
[ |
8004 |
|t1 t2| |
|
8005 |
||
8006 |
t1 := foo. |
|
8007 |
t2 := bar. |
|
8008 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
8009 |
] value |
|
5755 | 8010 |
|
8011 |
Can be used to provide defaultValues to variables, |
|
8012 |
as in: |
|
6654 | 8013 |
foo := arg ? #defaultValue |
5755 | 8014 |
|
8015 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8016 |
Notice: |
|
6654 | 8017 |
This method is open coded (inlined) by the compiler(s) |
8018 |
- redefining it may not work as expected." |
|
5755 | 8019 |
|
8020 |
^ self |
|
8021 |
||
8022 |
" |
|
8023 |
1 ? #default |
|
8024 |
nil ? #default |
|
8025 |
" |
|
8026 |
||
8027 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8028 |
"Modified: / 19.5.1998 / 17:39:56 / cg" |
|
8029 |
! |
|
8030 |
||
8031 |
?? defaultValue |
|
8032 |
"a syntactic shugar-piece: |
|
8033 |
much like ?, but sends #value to the argument if required. |
|
8034 |
(i.e. its the same as #ifNil:) |
|
8035 |
If the receiver is nil, return the defaultValues value; |
|
8036 |
otherwise, return the receiver. |
|
8037 |
This method is only redefined in UndefinedObject - therefore, |
|
8038 |
the recevier is retuned here. |
|
8039 |
||
8040 |
Thus, if foo and bar are simple variables or constants, |
|
6654 | 8041 |
foo ?? bar |
5755 | 8042 |
is the same as: |
6654 | 8043 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
5755 | 8044 |
|
8045 |
if they are message sends, the equivalent code is: |
|
6654 | 8046 |
[ |
8047 |
|t t2| |
|
8048 |
||
8049 |
t := foo. |
|
8050 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
8051 |
] value |
|
5755 | 8052 |
|
8053 |
Can be used to provide defaultValues to variables, |
|
8054 |
as in: |
|
6654 | 8055 |
foo := arg ?? [ self computeDefault ] |
5755 | 8056 |
|
8057 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8058 |
" |
|
8059 |
||
8060 |
^ self |
|
8061 |
||
8062 |
" |
|
8063 |
1 ?? #default |
|
8064 |
nil ?? #default |
|
8065 |
1 ?? [ self halt. 1 + 2 ] |
|
8066 |
nil ?? [ self halt. 1 + 2 ] |
|
6069 | 8067 |
1 ?? [Date today] |
8068 |
nil ?? [Date today] |
|
5755 | 8069 |
" |
8070 |
||
8071 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8072 |
"Modified: / 19.5.1998 / 17:42:56 / cg" |
|
8073 |
! |
|
8074 |
||
8075 |
ifNil:aBlockOrValue |
|
8076 |
"return myself, or the result from evaluating the argument, if I am nil. |
|
8077 |
This is much like #?, but sends #value to the argument in case of a nil |
|
8078 |
receiver. |
|
8079 |
Notice: |
|
6654 | 8080 |
This method is open coded (inlined) by the compiler(s) |
8081 |
- redefining it may not work as expected." |
|
5755 | 8082 |
|
8083 |
^ self |
|
8084 |
! |
|
8085 |
||
8086 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
|
8087 |
"return the value of the first arg, if I am nil, |
|
8088 |
the result from evaluating the 2nd argument, if I am not nil. |
|
8089 |
Notice: |
|
6654 | 8090 |
This method is open coded (inlined) by the compiler(s) |
8091 |
- redefining it may not work as expected." |
|
5755 | 8092 |
|
8093 |
^ notNilBlockOrValue value |
|
8094 |
||
8095 |
! |
|
8096 |
||
8097 |
ifNotNil:aBlockOrValue |
|
8098 |
"return myself if nil, or the result from evaluating the argument, |
|
8099 |
if I am not nil. |
|
8100 |
Notice: |
|
6654 | 8101 |
This method is open coded (inlined) by the compiler(s) |
8102 |
- redefining it may not work as expected." |
|
5755 | 8103 |
|
8104 |
^ aBlockOrValue value |
|
8105 |
||
8106 |
! |
|
8107 |
||
8108 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
|
8109 |
"return the value of the 2nd arg, if I am nil, |
|
8110 |
the result from evaluating the 1st argument, if I am not nil. |
|
8111 |
Notice: |
|
6654 | 8112 |
This method is open coded (inlined) by the compiler(s) |
8113 |
- redefining it may not work as expected." |
|
5755 | 8114 |
|
8115 |
^ notNilBlockOrValue value |
|
8116 |
||
8117 |
||
8118 |
! |
|
8119 |
||
8120 |
isArray |
|
8121 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
8122 |
false is returned here - the method is only redefined in Array." |
|
8123 |
||
8124 |
^ false |
|
8125 |
! |
|
8126 |
||
8127 |
isAssociation |
|
8128 |
"return true, if the receiver is some kind of association; |
|
8129 |
false is returned here - the method is only redefined in Association." |
|
8130 |
||
8131 |
^ false |
|
8132 |
||
8133 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
8134 |
! |
|
8135 |
||
8136 |
isBehavior |
|
8137 |
"return true, if the receiver is some kind of class (i.e. behavior); |
|
8138 |
false is returned here - the method is only redefined in Behavior." |
|
8139 |
||
8140 |
^ false |
|
8141 |
! |
|
8142 |
||
8143 |
isBlock |
|
8144 |
"return true, if the receiver is some kind of block; |
|
8145 |
false returned here - the method is only redefined in Block." |
|
8146 |
||
8147 |
^ false |
|
8148 |
! |
|
8149 |
||
5824 | 8150 |
isBoolean |
8151 |
"return true, if the receiver is a boolean; |
|
8152 |
false is returned here - the method is only redefined in Boolean." |
|
8153 |
||
8154 |
^ false |
|
8155 |
! |
|
8156 |
||
5755 | 8157 |
isByteArray |
8158 |
"return true, if the receiver is some kind of bytearray; |
|
8159 |
false is returned here - the method is only redefined in ByteArray." |
|
8160 |
||
8161 |
^ false |
|
8162 |
! |
|
8163 |
||
8164 |
isCharacter |
|
8165 |
"return true, if the receiver is some kind of character; |
|
8166 |
false is returned here - the method is only redefined in Character." |
|
8167 |
||
8168 |
^ false |
|
8169 |
! |
|
8170 |
||
8171 |
isClass |
|
8172 |
"return true, if the receiver is some kind of class (real class, |
|
8173 |
not just behavior); |
|
8174 |
false is returned here - the method is only redefined in Class." |
|
8175 |
||
8176 |
^ false |
|
8177 |
! |
|
8178 |
||
8179 |
isCollection |
|
8180 |
"return true, if the receiver is some kind of collection; |
|
8181 |
false is returned here - the method is only redefined in Collection." |
|
8182 |
||
8183 |
^ false |
|
8184 |
! |
|
8185 |
||
8186 |
isColor |
|
8187 |
"return true, if the receiver is some kind of color; |
|
8188 |
false is returned here - the method is only redefined in Color." |
|
8189 |
||
8190 |
^ false |
|
8191 |
! |
|
8192 |
||
6567 | 8193 |
isCons |
8194 |
"return true, if the receiver is a cons (pair); |
|
8195 |
false is returned here - the method is only redefined in Cons." |
|
8196 |
||
8197 |
^ false |
|
8198 |
! |
|
8199 |
||
5755 | 8200 |
isContext |
8201 |
"return true, if the receiver is some kind of context; |
|
8202 |
false returned here - the method is only redefined in Context." |
|
8203 |
||
8204 |
^ false |
|
8205 |
! |
|
8206 |
||
6181 | 8207 |
isEmptyOrNil |
8208 |
"Squeak compatibility: |
|
6182 | 8209 |
return true if I am nil or an empty collection - return false here. |
8210 |
Sigh: the same as ST/X isNilOrEmptyCollection - which one should be kept in the long run ?" |
|
6181 | 8211 |
|
8212 |
^ false |
|
8213 |
||
8214 |
"Created: / 13.11.2001 / 13:17:04 / cg" |
|
6182 | 8215 |
"Modified: / 13.11.2001 / 13:28:40 / cg" |
6181 | 8216 |
! |
8217 |
||
6221 | 8218 |
isException |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8219 |
"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
|
8220 |
|
6221 | 8221 |
^ false |
8222 |
||
8223 |
"Created: / 17.11.2001 / 18:37:44 / cg" |
|
8224 |
! |
|
8225 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8226 |
isExceptionCreator |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8227 |
"return true, if the receiver can create exceptions, |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8228 |
this includes #raise, #raiseRequest as well as the behavior of |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8229 |
an exception handler, such as the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8230 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8231 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8232 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8233 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8234 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8235 |
"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
|
8236 |
especially to the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8237 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8238 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8239 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8240 |
|
5755 | 8241 |
isExternalStream |
8242 |
"return true, if the receiver is some kind of externalStream; |
|
8243 |
false is returned here - the method is only redefined in ExternalStream." |
|
8244 |
||
8245 |
^false |
|
8246 |
! |
|
8247 |
||
8248 |
isFileStream |
|
8249 |
"return true, if the receiver is some kind of fileStream; |
|
8250 |
false is returned here - the method is only redefined in FileStream." |
|
8251 |
||
8252 |
^false |
|
8253 |
! |
|
8254 |
||
8255 |
isFilename |
|
8256 |
"return true, if the receiver is some kind of filename; |
|
8257 |
false is returned here - the method is only redefined in Filename." |
|
8258 |
||
8259 |
^false |
|
8260 |
! |
|
8261 |
||
8262 |
isFixedPoint |
|
8263 |
"return true, if the receiver is some kind of fixedPoint number; |
|
8264 |
false is returned here - the method is only redefined in FixedPoint." |
|
8265 |
||
8266 |
^ false |
|
8267 |
||
8268 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
8269 |
! |
|
8270 |
||
8271 |
isFixedSize |
|
8272 |
"return true if the receiver cannot grow easily |
|
8273 |
(i.e. a grow may be expensive, since it involves a become:)" |
|
8274 |
||
8275 |
^ true |
|
8276 |
! |
|
8277 |
||
6185 | 8278 |
isFloat |
8279 |
"return true, if the receiver is some kind of floating point number; |
|
8280 |
false is returned here. |
|
8281 |
Same as #isLimitedPrecisionReal, but a better name ;-)" |
|
8282 |
||
8283 |
^ false |
|
8284 |
||
8285 |
"Modified: / 14.11.2001 / 14:57:46 / cg" |
|
8286 |
! |
|
8287 |
||
5755 | 8288 |
isForm |
8289 |
"return true, if the receiver is some kind of form; |
|
8290 |
false is returned here - the method is only redefined in Form." |
|
8291 |
||
8292 |
^ false |
|
8293 |
! |
|
8294 |
||
8295 |
isFraction |
|
8296 |
"return true, if the receiver is some kind of fraction; |
|
8297 |
false is returned here - the method is only redefined in Fraction." |
|
8298 |
||
8299 |
^ false |
|
8300 |
! |
|
8301 |
||
8302 |
isImage |
|
8303 |
"return true, if the receiver is some kind of image; |
|
8304 |
false is returned here - the method is only redefined in Image." |
|
8305 |
||
8306 |
^ false |
|
8307 |
! |
|
8308 |
||
8309 |
isImageOrForm |
|
8310 |
"return true, if the receiver is some kind of image or form; |
|
8311 |
false is returned here - the method is only redefined in Image and Form." |
|
8312 |
||
8313 |
^ false |
|
8314 |
! |
|
8315 |
||
8316 |
isImmediate |
|
8317 |
"return true if I am an immediate object |
|
8318 |
i.e. I am represented in the pointer itself and |
|
8319 |
no real object header/storage is used me. |
|
8320 |
(currently, only SmallIntegers, some characters and nil return true)" |
|
8321 |
||
8322 |
^ self class hasImmediateInstances |
|
8323 |
||
8324 |
"Created: 3.6.1997 / 12:00:18 / cg" |
|
8325 |
! |
|
8326 |
||
8327 |
isInteger |
|
8328 |
"return true, if the receiver is some kind of integer number; |
|
8329 |
false is returned here - the method is only redefined in Integer." |
|
8330 |
||
8331 |
^ false |
|
8332 |
! |
|
8333 |
||
8334 |
isJavaClass |
|
8335 |
"return true, if this is a javaClass. |
|
8336 |
false is returned here - the method is only redefined in JavaClass." |
|
8337 |
||
8338 |
^ false |
|
8339 |
||
8340 |
"Created: / 26.3.1997 / 13:34:54 / cg" |
|
8341 |
"Modified: / 8.5.1998 / 21:25:21 / cg" |
|
8342 |
! |
|
8343 |
||
8344 |
isJavaClassRef |
|
8345 |
"return true, if this is a JavaClassRef. |
|
8346 |
false is returned here - the method is only redefined in JavaClassRef." |
|
8347 |
||
8348 |
^ false |
|
8349 |
||
8350 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8351 |
"Created: / 24.12.1999 / 01:46:28 / cg" |
|
8352 |
! |
|
8353 |
||
8354 |
isJavaContext |
|
8355 |
"return true, if this is a javaContext. |
|
8356 |
false is returned here - the method is only redefined in JavaContext." |
|
8357 |
||
8358 |
^ false |
|
8359 |
||
8360 |
"Created: / 8.5.1998 / 21:24:27 / cg" |
|
8361 |
"Modified: / 8.5.1998 / 21:25:35 / cg" |
|
8362 |
! |
|
8363 |
||
8364 |
isJavaMethod |
|
8365 |
"return true, if this is a JavaMethod. |
|
8366 |
false is returned here - the method is only redefined in JavaMethod." |
|
8367 |
||
8368 |
^ false |
|
8369 |
||
8370 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8371 |
"Created: / 25.9.1999 / 23:26:12 / cg" |
|
8372 |
! |
|
8373 |
||
8374 |
isJavaMethodRef |
|
8375 |
"return true, if this is a JavaMethodRef. |
|
8376 |
false is returned here - the method is only redefined in JavaMethodRef." |
|
8377 |
||
8378 |
^ false |
|
8379 |
||
8380 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8381 |
"Created: / 23.12.1999 / 19:44:51 / cg" |
|
8382 |
! |
|
8383 |
||
8384 |
isJavaObject |
|
8385 |
"return true, if this is a javaObject. |
|
8386 |
false is returned here - the method is only redefined in JavaObject." |
|
8387 |
||
8388 |
^ false |
|
8389 |
||
8390 |
"Created: / 26.3.1997 / 13:34:48 / cg" |
|
8391 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8392 |
! |
|
8393 |
||
8394 |
isJavaScriptClass |
|
8395 |
"return true, if this is a javaScriptClass. |
|
8396 |
false is returned here - the method is only redefined in JavaScriptClass." |
|
8397 |
||
8398 |
^ false |
|
8399 |
! |
|
8400 |
||
8401 |
isKindOf:aClass |
|
8402 |
"return true, if the receiver is an instance of aClass or one of its |
|
8403 |
subclasses, false otherwise. |
|
8404 |
Advice: |
|
6654 | 8405 |
use of this to check objects for certain attributes/protocoll should |
8406 |
be avoided; it limits the reusability of your classes by limiting use |
|
8407 |
to instances of certain classes and fences you into a specific inheritance |
|
8408 |
hierarchy. |
|
8409 |
Use check-methods to check an object for a certain attributes/protocol |
|
8410 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
8411 |
||
8412 |
Using #isKindOf: is considered BAD STYLE. |
|
5755 | 8413 |
|
8414 |
Advice2: |
|
6654 | 8415 |
Be aware, that using an #isXXX method is usually much faster than |
8416 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
8417 |
hierarchy, comparing every class on the way. |
|
8418 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
8419 |
a single function call. |
|
5755 | 8420 |
" |
8421 |
||
8422 |
%{ /* NOCONTEXT */ |
|
8423 |
register OBJ thisClass; |
|
8424 |
||
8425 |
thisClass = __Class(self); |
|
8426 |
while (thisClass != nil) { |
|
6654 | 8427 |
if (thisClass == aClass) { |
8428 |
RETURN ( true ); |
|
8429 |
} |
|
8430 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
5755 | 8431 |
} |
8432 |
RETURN ( false ); |
|
8433 |
%} |
|
8434 |
||
8435 |
"/ |
|
8436 |
"/ the above code is equivalent to: |
|
8437 |
"/ |
|
8438 |
"/ thisClass := self class. |
|
8439 |
"/ [thisClass notNil] whileTrue:[ |
|
8440 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
8441 |
"/ thisClass := thisClass superclass |
|
8442 |
"/ ]. |
|
8443 |
"/ ^ false |
|
8444 |
"/ |
|
8445 |
||
8446 |
! |
|
8447 |
||
8448 |
isLayout |
|
8449 |
"return true, if the receiver is some kind of layout; |
|
8450 |
false is returned here - the method is only redefined in Layout." |
|
8451 |
||
8452 |
^ false |
|
8453 |
! |
|
8454 |
||
6567 | 8455 |
isLazyValue |
8456 |
^ false |
|
8457 |
! |
|
8458 |
||
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8459 |
isLimitedPrecisionReal |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8460 |
"return true, if the receiver is some kind of floating point number; |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8461 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8462 |
|
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8463 |
^ false |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8464 |
! |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8465 |
|
5755 | 8466 |
isList |
8467 |
"return true, if the receiver is some kind of list collection; |
|
8468 |
false is returned here - the method is only redefined in List." |
|
8469 |
||
8470 |
^ false |
|
8471 |
||
8472 |
"Created: / 11.2.2000 / 01:37:05 / cg" |
|
8473 |
! |
|
8474 |
||
8475 |
isLiteral |
|
8476 |
"return true, if the receiver can be represented as a literal constant in ST syntax; |
|
8477 |
false is returned here - the method is redefined in some classes." |
|
8478 |
||
8479 |
^ false |
|
8480 |
! |
|
8481 |
||
8482 |
isMemberOf:aClass |
|
8483 |
"return true, if the receiver is an instance of aClass, false otherwise. |
|
8484 |
Advice: |
|
6654 | 8485 |
use of this to check objects for certain attributes/protocoll should |
8486 |
be avoided; it limits the reusability of your classes by limiting use |
|
8487 |
to instances of a certain class. |
|
8488 |
Use check-methods to check an object for a certain attributes/protocol |
|
8489 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
8490 |
||
8491 |
Using #isMemberOf: is considered BAD STYLE. |
|
5755 | 8492 |
Notice: |
6654 | 8493 |
This method is open coded (inlined) by the compiler(s) |
8494 |
- redefining it may not work as expected." |
|
5755 | 8495 |
|
8496 |
^ (self class) == aClass |
|
8497 |
! |
|
8498 |
||
8499 |
isMeta |
|
8500 |
"return true, if the receiver is some kind of metaclass; |
|
8501 |
false is returned here - the method is only redefined in Metaclass." |
|
8502 |
||
8503 |
^ false |
|
8504 |
! |
|
8505 |
||
8506 |
isMethod |
|
8507 |
"return true, if the receiver is some kind of method; |
|
8508 |
false returned here - the method is only redefined in Method." |
|
8509 |
||
8510 |
^ false |
|
8511 |
! |
|
8512 |
||
8513 |
isMorph |
|
8514 |
"return true, if the receiver is some kind of morph; |
|
8515 |
false is returned here - the method is only redefined in Morph." |
|
8516 |
||
8517 |
^ false |
|
8518 |
! |
|
8519 |
||
8520 |
isNameSpace |
|
8521 |
"return true, if this is a nameSpace. |
|
8522 |
false is returned here - the method is only redefined in Namespace." |
|
8523 |
||
8524 |
^ false |
|
8525 |
||
8526 |
"Created: / 11.10.1996 / 18:08:56 / cg" |
|
8527 |
"Modified: / 8.5.1998 / 21:26:05 / cg" |
|
8528 |
! |
|
8529 |
||
8530 |
isNamespace |
|
8531 |
"return true, if this is a nameSpace. |
|
8532 |
false is returned here - the method is only redefined in Namespace." |
|
8533 |
||
5869 | 8534 |
<resource:#obsolete> |
8535 |
||
5755 | 8536 |
self obsoleteMethodWarning:'use #isNameSpace'. |
6805 | 8537 |
^ self isNameSpace |
5755 | 8538 |
! |
8539 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8540 |
isNil |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8541 |
"return true, if the receiver is nil. |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8542 |
Notice: |
6654 | 8543 |
This method is open coded (inlined) by the compiler(s) |
8544 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8545 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8546 |
^ false |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8547 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8548 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8549 |
isNilOrEmptyCollection |
6182 | 8550 |
"return true if I am nil or an empty collection - false here. |
8551 |
Sigh: the same as Squeaks isEmptyOrNil - which one should be kept in the long run ?" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8552 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8553 |
^ false |
6182 | 8554 |
|
8555 |
"Modified: / 13.11.2001 / 13:28:06 / cg" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8556 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8557 |
|
5755 | 8558 |
isNumber |
8559 |
"return true, if the receiver is some kind of number; |
|
8560 |
false is returned here - the method is only redefined in Number." |
|
8561 |
||
8562 |
^ false |
|
8563 |
! |
|
8564 |
||
8565 |
isOrderedCollection |
|
8566 |
"return true, if the receiver is some kind of ordered collection (or list etc); |
|
8567 |
false is returned here - the method is only redefined in OrderedCollection." |
|
8568 |
||
8569 |
^ false |
|
8570 |
! |
|
8571 |
||
8572 |
isPoint |
|
8573 |
"return true, if the receiver is some kind of point; |
|
8574 |
false is returned here - the method is only redefined in Point." |
|
8575 |
||
8576 |
^ false |
|
8577 |
! |
|
8578 |
||
8579 |
isRectangle |
|
8580 |
"return true, if the receiver is some kind of rectangle; |
|
8581 |
false is returned here - the method is only redefined in Rectangle." |
|
8582 |
||
8583 |
^ false |
|
8584 |
! |
|
8585 |
||
8586 |
isRemoteObject |
|
8587 |
"return true, if the receiver is some kind of remoteObject, |
|
8588 |
false if its local - the method is only redefined in RemoteObject." |
|
8589 |
||
8590 |
^ false |
|
8591 |
||
8592 |
"Created: 28.10.1996 / 15:18:45 / cg" |
|
8593 |
"Modified: 28.10.1996 / 15:20:57 / cg" |
|
8594 |
! |
|
8595 |
||
8596 |
isSequenceable |
|
8597 |
"return true, if the receiver is some kind of sequenceable collection; |
|
8598 |
false is returned here - the method is only redefined in SequenceableCollection." |
|
8599 |
||
8600 |
^ false |
|
8601 |
! |
|
8602 |
||
8603 |
isSequenceableCollection |
|
8604 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
8605 |
This method is a historic leftover and will be removed soon ... |
|
8606 |
(although its name is much better than #isSequenceable - sigh)" |
|
8607 |
||
5869 | 8608 |
<resource:#obsolete> |
8609 |
||
5755 | 8610 |
self obsoleteMethodWarning:'use #isSequenceable'. |
8611 |
^ false |
|
8612 |
! |
|
8613 |
||
8614 |
isStream |
|
8615 |
"return true, if the receiver is some kind of stream; |
|
8616 |
false is returned here - the method is only redefined in Stream." |
|
8617 |
||
8618 |
^ false |
|
8619 |
! |
|
8620 |
||
8621 |
isString |
|
8622 |
"return true, if the receiver is some kind of string; |
|
8623 |
false is returned here - the method is only redefined in CharacterArray." |
|
8624 |
||
8625 |
^ false |
|
8626 |
! |
|
8627 |
||
8628 |
isStringCollection |
|
8629 |
"return true, if the receiver is some kind of stringCollection; |
|
8630 |
false is returned here - the method is only redefined in StringCollection." |
|
8631 |
||
8632 |
^ false |
|
8633 |
! |
|
8634 |
||
8635 |
isSymbol |
|
8636 |
"return true, if the receiver is some kind of symbol; |
|
8637 |
false is returned here - the method is only redefined in Symbol." |
|
8638 |
||
8639 |
^ false |
|
8640 |
! |
|
8641 |
||
8642 |
isText |
|
8643 |
"return true, if the receiver is some kind of text object; |
|
8644 |
false is returned here - the method is only redefined in Text." |
|
8645 |
||
8646 |
^ false |
|
8647 |
||
8648 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
8649 |
! |
|
8650 |
||
8651 |
isValueModel |
|
8652 |
"return true, if the receiver is some kind of valueModel; |
|
8653 |
false is returned here - the method is only redefined in ValueModel." |
|
8654 |
||
8655 |
^ false |
|
8656 |
||
8657 |
! |
|
8658 |
||
8659 |
isVariable |
|
8660 |
"return true if the receiver has indexed instance variables, |
|
8661 |
false otherwise." |
|
8662 |
||
8663 |
^ self class isVariable |
|
8664 |
! |
|
8665 |
||
8666 |
isVariableBinding |
|
8667 |
"return true, if this is a binding for a variable. |
|
8668 |
false is returned here - the method is only redefined in Binding." |
|
8669 |
||
8670 |
^ false |
|
8671 |
||
8672 |
"Created: / 19.6.1997 / 17:38:44 / cg" |
|
8673 |
"Modified: / 8.5.1998 / 21:26:55 / cg" |
|
8674 |
! |
|
8675 |
||
8676 |
isView |
|
8677 |
"return true, if the receiver is some kind of view; |
|
8678 |
false is returned here - the method is only redefined in View." |
|
8679 |
||
8680 |
^ false |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8681 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8682 |
|
6932 | 8683 |
notEmptyOrNil |
8684 |
"Squeak compatibility: |
|
8685 |
return true if I am neither nil nor an empty collection. |
|
8686 |
Return true here." |
|
8687 |
||
8688 |
^ true |
|
8689 |
! |
|
8690 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8691 |
notNil |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8692 |
"return true, if the receiver is not nil. |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8693 |
Notice: |
6654 | 8694 |
This method is open coded (inlined) by the compiler(s) |
8695 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8696 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8697 |
^ true |
5755 | 8698 |
! ! |
8699 |
||
8700 |
!Object methodsFor:'tracing'! |
|
8701 |
||
8702 |
traceInto:aRequestor level:level from:referrer |
|
8703 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
8704 |
||
8705 |
^ aRequestor traceObject:self level:level from:referrer |
|
8706 |
||
8707 |
"Created: / 2.9.1999 / 09:05:17 / stefan" |
|
8708 |
! ! |
|
8709 |
||
8710 |
!Object methodsFor:'user interaction & notifications'! |
|
8711 |
||
8712 |
activityNotification:aString |
|
8713 |
"this can be sent from deeply nested methods, which are going to perform |
|
8714 |
some long-time activity. |
|
8715 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
8716 |
passing the argument. The handler should show this message whereever it likes, |
|
8717 |
and proceed. If there is no handler, this is simply ignored. |
|
8718 |
||
8719 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
8720 |
which likes to display that message in its label or a busy-box. |
|
8721 |
It could also be put into some logfile or printed on the standard output/error." |
|
8722 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8723 |
ActivityNotification isHandled ifTrue:[ |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8724 |
^ ActivityNotification raiseRequestWith:self errorString:aString |
5755 | 8725 |
]. |
8726 |
||
8727 |
" |
|
8728 |
nil activityNotification:'hello there' |
|
8729 |
self activityNotification:'hello there' |
|
8730 |
" |
|
8731 |
||
8732 |
" |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8733 |
ActivityNotification handle:[:ex | |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8734 |
ex errorString printCR. |
6654 | 8735 |
ex proceed. |
5755 | 8736 |
] do:[ |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8737 |
'hello' printCR. |
6654 | 8738 |
self activityNotification:'doing some long time computation'. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8739 |
'world' printCR. |
5755 | 8740 |
] |
8741 |
" |
|
8742 |
||
8743 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
8744 |
! |
|
8745 |
||
8746 |
confirm:aString |
|
8747 |
"launch a confirmer, which allows user to enter yes or no. |
|
8748 |
return true for yes, false for no. |
|
8749 |
If no GUI is present (headless applications), true is returned." |
|
8750 |
||
8751 |
" |
|
8752 |
on systems without GUI, or during startup, output a message |
|
8753 |
and return true (as if yes was answered) |
|
8754 |
Q: should we ask user by reading Stdin ? |
|
8755 |
" |
|
8756 |
Smalltalk isInitialized ifFalse:[ |
|
6654 | 8757 |
'*** confirmation requested during initialization:' errorPrintCR. |
8758 |
aString errorPrintCR. |
|
8759 |
'*** I''ll continue, assuming <yes> ...' errorPrintCR. |
|
8760 |
^ true |
|
5755 | 8761 |
]. |
8762 |
||
8763 |
(Dialog isNil |
|
8764 |
or:[Screen isNil |
|
8765 |
or:[Screen current isNil |
|
8766 |
or:[Screen current isOpen not]]]) ifTrue:[ |
|
6654 | 8767 |
'confirm: ' infoPrint. |
8768 |
aString infoPrintCR. |
|
8769 |
'continue, assuming <yes>' infoPrintCR. |
|
8770 |
^ true |
|
5755 | 8771 |
]. |
8772 |
||
8773 |
Dialog autoload. "in case its autoloaded" |
|
8774 |
^ Dialog confirm:aString |
|
8775 |
||
8776 |
" |
|
8777 |
nil confirm:'hello' |
|
8778 |
self confirm:'hello' |
|
8779 |
" |
|
8780 |
||
8781 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8782 |
! |
|
8783 |
||
8784 |
confirm:aString orCancel:cancelBlock |
|
8785 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8786 |
return true for yes, false for no, or the value from cancelBlock for cancel. |
|
8787 |
If no GUI is present (headless applications), cancelBlock is returned." |
|
8788 |
||
8789 |
|answer| |
|
8790 |
||
8791 |
answer := self confirmWithCancel:aString. |
|
8792 |
answer isNil ifTrue:[ |
|
6654 | 8793 |
^ cancelBlock value |
5755 | 8794 |
]. |
8795 |
^ answer |
|
8796 |
||
8797 |
" |
|
8798 |
self confirm:'hello' orCancel:[self halt] |
|
8799 |
" |
|
8800 |
||
8801 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8802 |
! |
|
8803 |
||
8804 |
confirmWithCancel:aString |
|
8805 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8806 |
return true for yes, false for no, nil for cancel. |
|
8807 |
If no GUI is present (headless applications), nil is returned." |
|
8808 |
||
8809 |
" |
|
8810 |
on systems without GUI, or during startup, output a message |
|
8811 |
and return true (as if yes was answered) |
|
8812 |
Q: should we ask user by reading Stdin ? |
|
8813 |
" |
|
8814 |
Smalltalk isInitialized ifFalse:[ |
|
6654 | 8815 |
'*** confirmation requested during initialization:' errorPrintCR. |
8816 |
aString errorPrintCR. |
|
8817 |
'*** I''ll continue, assuming <cancel> ...' errorPrintCR. |
|
8818 |
^ nil |
|
5755 | 8819 |
]. |
8820 |
||
8821 |
(Dialog isNil |
|
8822 |
or:[Screen isNil |
|
8823 |
or:[Screen current isNil |
|
8824 |
or:[Screen current isOpen not]]]) ifTrue:[ |
|
6654 | 8825 |
'confirm: ' infoPrint. |
8826 |
aString infoPrintCR. |
|
8827 |
'continue, assuming <cancel>' infoPrintCR. |
|
8828 |
^ nil |
|
5755 | 8829 |
]. |
8830 |
||
8831 |
Dialog autoload. "in case its autoloaded" |
|
8832 |
^ Dialog confirmWithCancel:aString |
|
8833 |
||
8834 |
" |
|
8835 |
nil confirmWithCancel:'hello' |
|
8836 |
self confirmWithCancel:'hello' |
|
8837 |
" |
|
8838 |
||
8839 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8840 |
! |
|
8841 |
||
8842 |
errorNotify:aString |
|
8843 |
"launch a Notifier, showing top stack, telling user something |
|
8844 |
and give user a chance to enter debugger." |
|
8845 |
||
8846 |
^ self |
|
6654 | 8847 |
errorNotify:aString |
8848 |
from:thisContext sender |
|
8849 |
allowDebug:true |
|
5755 | 8850 |
|
8851 |
" |
|
8852 |
nil errorNotify:'hello there' |
|
8853 |
self errorNotify:'hello there' |
|
8854 |
" |
|
8855 |
||
6199 | 8856 |
"Modified: / 16.11.2001 / 15:36:49 / cg" |
5755 | 8857 |
! |
8858 |
||
8859 |
errorNotify:aString from:aContext |
|
8860 |
"launch a Notifier, showing top stack (above aContext), |
|
8861 |
telling user something and give user a chance to enter debugger." |
|
8862 |
||
8863 |
^ self errorNotify:aString from:aContext allowDebug:true |
|
8864 |
||
8865 |
"Modified: / 17.8.1998 / 10:09:27 / cg" |
|
8866 |
! |
|
8867 |
||
8868 |
errorNotify:aString from:aContext allowDebug:allowDebug |
|
8869 |
"launch a Notifier, showing top stack (above aContext), |
|
8870 |
telling user something and optionally give the user a chance to enter debugger." |
|
8871 |
||
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8872 |
|currentScreen con sender action boxLabels boxValues default| |
5755 | 8873 |
|
8874 |
Smalltalk isInitialized ifFalse:[ |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8875 |
'errorNotification: ' print. aString printCR. |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8876 |
^ nil |
5755 | 8877 |
]. |
8878 |
(Dialog isNil |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8879 |
or:[Screen isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8880 |
or:[(currentScreen := Screen current) isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8881 |
or:[currentScreen isOpen not]]]) ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8882 |
" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8883 |
on systems without GUI, simply show |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8884 |
the message on the Transcript and abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8885 |
" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8886 |
Transcript showCR:aString. |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8887 |
AbortOperationRequest raise. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8888 |
"not reached" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8889 |
^ nil |
5755 | 8890 |
]. |
8891 |
||
8892 |
Processor activeProcessIsSystemProcess ifTrue:[ |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8893 |
action := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8894 |
sender := aContext. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8895 |
Debugger isNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8896 |
'****************** Cought Error while in SystemProcess ****************' errorPrintCR. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8897 |
thisContext fullPrintAll. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8898 |
action := #abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8899 |
]. |
5755 | 8900 |
] ifFalse:[ |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8901 |
Dialog autoload. "in case it's autoloaded" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8902 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8903 |
Error handle:[:ex | |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8904 |
"/ a recursive error - quickly enter debugger |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8905 |
"/ this happened, when I corrupted the Dialog class ... |
7208 | 8906 |
('Object [error]: ' , ex description , ' caught in errorNotification') errorPrintCR. |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8907 |
action := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8908 |
ex return. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8909 |
] do:[ |s| |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8910 |
sender := aContext. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8911 |
sender isNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8912 |
sender := thisContext sender. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8913 |
]. |
7576
7e2e97bd0973
interrestingContextFrom - duplicated code removed
Claus Gittinger <cg@exept.de>
parents:
7567
diff
changeset
|
8914 |
con := sender. |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8915 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8916 |
"/ skip intermediate (signal & exception) contexts |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8917 |
DebugView notNil ifTrue:[ |
7576
7e2e97bd0973
interrestingContextFrom - duplicated code removed
Claus Gittinger <cg@exept.de>
parents:
7567
diff
changeset
|
8918 |
con := DebugView interestingContextFrom:sender |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8919 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8920 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8921 |
"/ show the first few contexts |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8922 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8923 |
s := WriteStream with:aString. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8924 |
s cr; cr. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8925 |
1 to:15 do:[:n | |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8926 |
con notNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8927 |
con printOn:s. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8928 |
s cr. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8929 |
con := con sender |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8930 |
] |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8931 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8932 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8933 |
(allowDebug and:[Debugger notNil]) ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8934 |
boxLabels := #('Proceed' 'Abort' 'Copy Trace and Abort' 'Debug'). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8935 |
boxValues := #(#proceed #abort #copy #debug). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8936 |
default := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8937 |
] ifFalse:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8938 |
boxLabels := #('Proceed' 'Abort' 'Copy Trace and Abort'). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8939 |
boxValues := #(#proceed #abort #copy). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8940 |
default := #abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8941 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8942 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8943 |
action := Dialog |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8944 |
choose:s contents |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8945 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8946 |
image:WarningBox errorIconBitmap |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8947 |
labels:boxLabels |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8948 |
values:boxValues |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8949 |
default:default |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8950 |
onCancel:nil. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8951 |
]. |
5755 | 8952 |
]. |
8953 |
||
8954 |
action == #debug ifTrue:[ |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8955 |
^ Debugger enter:sender withMessage:aString mayProceed:true |
5755 | 8956 |
] ifFalse:[ |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8957 |
action == #proceed ifTrue:[ |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8958 |
^ nil. |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8959 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8960 |
action == #copy ifTrue:[ |s| |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8961 |
s := '' writeStream. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8962 |
sender fullPrintAllOn:s. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8963 |
currentScreen rootView setTextSelection:s contents. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8964 |
]. |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8965 |
AbortOperationRequest raise. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8966 |
"not reached" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8967 |
]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8968 |
|
5755 | 8969 |
|
8970 |
" |
|
8971 |
nil errorNotify:'hello there' |
|
8972 |
self errorNotify:'hello there' |
|
8973 |
" |
|
8974 |
||
8975 |
"Created: / 17.8.1998 / 10:09:26 / cg" |
|
6199 | 8976 |
"Modified: / 16.11.2001 / 15:40:12 / cg" |
5755 | 8977 |
! |
8978 |
||
8979 |
information:aString |
|
8980 |
"launch an InfoBox, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8981 |
These info-boxes can be suppressed by handling |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8982 |
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
|
8983 |
Use #notify: for more important messages. |
8371 | 8984 |
If nobody handles the exception, the default action of UserNotification |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8985 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8986 |
|
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
8987 |
UserInformation raiseRequestWith:self errorString:aString |
5755 | 8988 |
|
8989 |
" |
|
8990 |
nil information:'hello there' |
|
8991 |
self information:'hello there' |
|
8992 |
" |
|
8993 |
||
8994 |
" |
|
8995 |
InformationSignal handle:[:ex | |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8996 |
'no box popped' printCR. |
6654 | 8997 |
ex proceed. |
5755 | 8998 |
] do:[ |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8999 |
'hello' printCR. |
6654 | 9000 |
self information:'some info'. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9001 |
'world' printCR. |
5755 | 9002 |
] |
9003 |
" |
|
9004 |
||
9005 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
9006 |
! |
|
9007 |
||
9008 |
notify:aString |
|
9009 |
"launch a Notifier, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9010 |
Use #information: for ignorable messages. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9011 |
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
|
9012 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9013 |
|
5755 | 9014 |
|
9015 |
Smalltalk isInitialized ifFalse:[ |
|
6656 | 9016 |
"/ thisContext fullPrintAll. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9017 |
'information: ' print. aString printCR. |
6654 | 9018 |
^ self |
5755 | 9019 |
]. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9020 |
UserNotification raiseRequestWith:self errorString:aString. |
5755 | 9021 |
|
9022 |
" |
|
9023 |
nil notify:'hello there' |
|
9024 |
self notify:'hello there' |
|
9025 |
" |
|
9026 |
||
9027 |
"Modified: 20.5.1996 / 10:28:48 / cg" |
|
9028 |
! |
|
9029 |
||
9030 |
warn:aString |
|
9031 |
"launch a WarningBox, telling user something. |
|
9032 |
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
|
9033 |
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
|
9034 |
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
|
9035 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9036 |
|
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9037 |
Warning raiseRequestWith:self errorString:aString |
5755 | 9038 |
|
9039 |
" |
|
9040 |
nil warn:'hello there' |
|
9041 |
self warn:'hello there' |
|
9042 |
" |
|
9043 |
||
9044 |
" |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9045 |
Warning handle:[:ex | |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9046 |
Transcript showCR:ex description. |
6654 | 9047 |
ex proceed. |
5755 | 9048 |
] do:[ |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9049 |
'hello' printCR. |
6654 | 9050 |
self warn:'some info'. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9051 |
'world' printCR. |
5755 | 9052 |
] |
9053 |
" |
|
9054 |
||
9055 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
|
9056 |
! ! |
|
9057 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9058 |
!Object methodsFor:'visiting'! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9059 |
|
8426 | 9060 |
acceptVisitor:aVisitor |
9061 |
"double-dispatch onto a Visitor." |
|
9062 |
||
9063 |
^ self acceptVisitor:aVisitor with:nil |
|
9064 |
! |
|
9065 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9066 |
acceptVisitor:aVisitor with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9067 |
"double-dispatch onto a Visitor. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9068 |
Subclasses redefine this" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9069 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9070 |
^ aVisitor visitObject:self with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9071 |
! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9072 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9073 |
elementDescriptorFor:aspect |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9074 |
"answer a collection of associations containing the |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9075 |
objects state to be encoded for aspect. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9076 |
Association key is the instance variable name or access selector, |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9077 |
association value is the contents of the instance variable. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9078 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9079 |
The default is to return the contents of all non-nil instance variables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9080 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9081 |
|ret| |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9082 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9083 |
ret := self perform:aspect ifNotUnderstood:[0]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9084 |
ret == 0 ifTrue:[ |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9085 |
^ self elementDescriptorForNonNilInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9086 |
]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9087 |
^ ret. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9088 |
! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9089 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9090 |
elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9091 |
"return all instance variables for visiting/encoding" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9092 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9093 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9094 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9095 |
" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9096 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9097 |
Dictionary new elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9098 |
(5 @ nil) elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9099 |
" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9100 |
! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9101 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9102 |
elementDescriptorForInstanceVariablesMatching:aBlock |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9103 |
"return all instance variables which conform to aBlock, for encoding/visiting. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9104 |
Indexed vars are all included." |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9105 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9106 |
|instVarNames theClass children |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9107 |
instSize "{ Class: SmallInteger }" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9108 |
varSize "{ Class: SmallInteger }"| |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9109 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9110 |
theClass := self class. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9111 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9112 |
instSize := theClass instSize. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9113 |
varSize := theClass isVariable ifTrue:[self basicSize] ifFalse:[0]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9114 |
children := OrderedCollection new:(instSize + varSize). |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9115 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9116 |
instVarNames := theClass allInstVarNames. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9117 |
1 to:instSize do:[:i | |var| |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9118 |
var := self instVarAt:i. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9119 |
(aBlock value:var) ifTrue:[ |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9120 |
children add:((instVarNames at:i) -> var) |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9121 |
] |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9122 |
]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9123 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9124 |
varSize ~~ 0 ifTrue:[ |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9125 |
1 to:varSize do:[:i | |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9126 |
children add:(i -> (self basicAt:i)) |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9127 |
] |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9128 |
]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9129 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9130 |
^ children. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9131 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9132 |
" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9133 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9134 |
Dictionary new elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9135 |
(5 @ nil) elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9136 |
" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9137 |
! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9138 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9139 |
elementDescriptorForNonNilInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9140 |
"return all non-nil instance variables for visiting/encoding" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9141 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9142 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | val notNil]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9143 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9144 |
" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9145 |
#(1 2 3 nil true symbol) elementDescriptorForNonNilInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9146 |
Dictionary new elementDescriptorForNonNilInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9147 |
(5 @ nil) elementDescriptorForNonNilInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9148 |
" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9149 |
! ! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9150 |
|
5755 | 9151 |
!Object class methodsFor:'documentation'! |
1 | 9152 |
|
5754 | 9153 |
version |
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
9154 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.507 2004-08-30 17:59:26 stefan Exp $' |
1 | 9155 |
! ! |
6764 | 9156 |
|
5755 | 9157 |
Object initialize! |