author | Claus Gittinger <cg@exept.de> |
Wed, 23 Aug 2006 16:06:59 +0200 | |
changeset 9657 | 3fa7b94ff781 |
parent 9643 | daf683976e1e |
child 9694 | 64f6face84d5 |
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 |
||
8521 | 297 |
^ AbortOperationRequest |
5755 | 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 |
||
8892 | 496 |
isAbstract |
497 |
^ self == Object |
|
498 |
! |
|
499 |
||
5755 | 500 |
isBuiltInClass |
501 |
"return true, if this class is known by the run-time-system, |
|
502 |
i.e. you cannot add/remove instance variables without recompiling |
|
503 |
the VM. |
|
504 |
Here, true is returned for myself, false for subclasses." |
|
505 |
||
506 |
^ self == Object |
|
507 |
||
508 |
"Modified: 23.4.1996 / 16:00:07 / cg" |
|
509 |
! ! |
|
510 |
||
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
511 |
!Object methodsFor:'Compatibility-Dolphin'! |
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 |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
514 |
self changed:anAspect |
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 |
trigger:anAspect with:anArgument |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
518 |
self changed:anAspect with:anArgument |
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 |
|
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
521 |
when:anAspect sendTo:anObject |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
522 |
self expressInterestIn:anAspect for:anObject sendBack:anAspect |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
523 |
! ! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
524 |
|
9375 | 525 |
!Object methodsFor:'Compatibility-ST/V'! |
526 |
||
527 |
triggerEvent:aSymbol |
|
528 |
self changed:aSymbol |
|
529 |
! ! |
|
530 |
||
7261 | 531 |
!Object methodsFor:'Compatibility-ST80'! |
5755 | 532 |
|
533 |
isMetaclass |
|
534 |
^ self isMeta |
|
535 |
! ! |
|
536 |
||
7261 | 537 |
!Object methodsFor:'Compatibility-Squeak'! |
5755 | 538 |
|
6549
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
539 |
as:aSimilarClass |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
540 |
"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
|
541 |
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
|
542 |
as the receiver. |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
543 |
Otherwise, return the receiver." |
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
544 |
|
8664491c4428
#as: returns the receiver if its class already matches
Claus Gittinger <cg@exept.de>
parents:
6537
diff
changeset
|
545 |
self class == aSimilarClass ifTrue:[^ self]. |
5755 | 546 |
^ aSimilarClass newFrom:self |
547 |
||
548 |
" |
|
549 |
#[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
|
550 |
#[1 2 3 4] as:Array |
5755 | 551 |
" |
552 |
! |
|
553 |
||
554 |
asString |
|
555 |
^ self printString |
|
556 |
! |
|
557 |
||
9071 | 558 |
becomeForward:anotherObject |
559 |
self becomeSameAs:anotherObject |
|
560 |
! |
|
561 |
||
562 |
becomeForward:anotherObject copyHash:copyHash |
|
563 |
copyHash ifTrue:[ self error:'unsupported operation' ]. |
|
564 |
self becomeSameAs:anotherObject |
|
565 |
! |
|
566 |
||
5755 | 567 |
clone |
568 |
^ self shallowCopy |
|
569 |
! |
|
570 |
||
6146 | 571 |
copyTwoLevel |
572 |
"one more level than a shallowCopy" |
|
573 |
||
574 |
^ self copyToLevel:2 |
|
575 |
||
576 |
" |
|
577 |
|original copy elL1 elL2 elL3 copyOfElL1| |
|
578 |
||
579 |
original := Array new:3. |
|
580 |
original at:1 put:1234. |
|
581 |
original at:2 put:'hello'. |
|
582 |
original at:3 put:(elL1 := Array new:3). |
|
583 |
||
584 |
elL1 at:1 put:1234. |
|
585 |
elL1 at:2 put:'hello'. |
|
586 |
elL1 at:3 put:(elL2 := Array new:3). |
|
587 |
||
588 |
elL2 at:1 put:1234. |
|
589 |
elL2 at:2 put:'hello'. |
|
590 |
elL2 at:3 put:(elL3 := Array new:3). |
|
591 |
||
592 |
elL3 at:1 put:1234. |
|
593 |
elL3 at:2 put:'hello'. |
|
594 |
elL3 at:3 put:(Array new:3). |
|
595 |
||
596 |
copy := original copyTwoLevel. |
|
597 |
(original at:2) ~~ (copy at:2) ifFalse:[self halt]. |
|
598 |
(original at:3) ~~ (copy at:3) ifFalse:[self halt]. |
|
599 |
||
600 |
copyOfElL1 := copy at:3. |
|
601 |
(elL1 at:2) == (copyOfElL1 at:2) ifFalse:[self halt]. |
|
602 |
(elL1 at:3) == (copyOfElL1 at:3) ifFalse:[self halt]. |
|
603 |
" |
|
604 |
! |
|
605 |
||
5755 | 606 |
currentHand |
5912 | 607 |
"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." |
608 |
||
609 |
|w h| |
|
610 |
||
611 |
w := self currentWorld. |
|
612 |
h := w activeHand. |
|
613 |
h isNil ifTrue:[ |
|
6654 | 614 |
h := w hands first |
5912 | 615 |
]. |
616 |
^ h |
|
5755 | 617 |
! |
618 |
||
619 |
currentWorld |
|
7159
7964c345d74c
Object currentWorld - recursion if Utilities is unloaded
Claus Gittinger <cg@exept.de>
parents:
7121
diff
changeset
|
620 |
Utilities autoload. |
7964c345d74c
Object currentWorld - recursion if Utilities is unloaded
Claus Gittinger <cg@exept.de>
parents:
7121
diff
changeset
|
621 |
^ Utilities currentWorld |
5755 | 622 |
! |
623 |
||
7320 | 624 |
explore |
625 |
(self confirm:'The Squeak explorer has not yet been ported to ST/X\\Inspect instead ?' withCRs) |
|
626 |
ifTrue:[ |
|
627 |
self inspect |
|
628 |
] |
|
629 |
! |
|
630 |
||
9335 | 631 |
isInMemory |
632 |
"All normal objects are." |
|
633 |
||
634 |
^ true |
|
635 |
! |
|
636 |
||
5755 | 637 |
newTileMorphRepresentative |
6654 | 638 |
^ TileMorph new setLiteral: self |
5755 | 639 |
! |
640 |
||
641 |
stringForReadout |
|
6654 | 642 |
^ self stringRepresentation |
5755 | 643 |
! |
644 |
||
645 |
stringRepresentation |
|
6654 | 646 |
"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" |
647 |
||
648 |
^ self printString |
|
5755 | 649 |
! |
650 |
||
9146
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
651 |
valueWithPossibleArguments:argArray |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
652 |
^ self |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
653 |
! |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
654 |
|
5755 | 655 |
veryDeepCopy |
8383 | 656 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 657 |
! ! |
658 |
||
7567 | 659 |
!Object methodsFor:'Compatibility-VW'! |
660 |
||
8637 | 661 |
isCharacters |
662 |
"added for visual works compatibility" |
|
663 |
^ false |
|
664 |
! |
|
665 |
||
7567 | 666 |
keyNotFoundError:aKey |
667 |
"VW compatibility" |
|
668 |
||
669 |
self errorKeyNotFound:aKey. |
|
670 |
! |
|
671 |
||
672 |
oneWayBecome:anotherObject |
|
673 |
^ self becomeSameAs:anotherObject |
|
674 |
||
675 |
" |
|
676 |
|arr o1 o2| |
|
677 |
||
678 |
arr := Array new:2. |
|
679 |
arr at:1 put:(o1 := Object new). |
|
680 |
arr at:2 put:(o2 := Point new). |
|
681 |
o1 oneWayBecome:o2. |
|
682 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
683 |
" |
|
684 |
" |
|
685 |
|arr o1 o2| |
|
686 |
||
687 |
arr := Array new:2. |
|
688 |
arr at:1 put:(o1 := Object new). |
|
689 |
arr at:2 put:(o2 := Point new). |
|
690 |
o1 becomeSameAs:o2. |
|
691 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
692 |
" |
|
693 |
! ! |
|
694 |
||
5755 | 695 |
!Object methodsFor:'accessing'! |
696 |
||
697 |
at:index |
|
698 |
"return the indexed instance variable with index, anInteger; |
|
699 |
this method can be redefined in subclasses." |
|
700 |
||
701 |
^ self basicAt:index |
|
702 |
! |
|
703 |
||
704 |
at:index put:anObject |
|
705 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
706 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
|
707 |
||
708 |
^ self basicAt:index put:anObject |
|
709 |
||
710 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
|
711 |
! |
|
712 |
||
713 |
basicAt:index |
|
714 |
"return the indexed instance variable with index, anInteger. |
|
715 |
Trigger an error if the receiver has no indexed instance variables. |
|
716 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
717 |
||
718 |
%{ /* NOCONTEXT */ |
|
719 |
||
720 |
REGISTER int nbytes, indx; |
|
721 |
OBJ myClass; |
|
722 |
REGISTER char *pFirst; |
|
723 |
REGISTER int n; |
|
724 |
||
725 |
/* |
|
726 |
* notice the missing test for self being a nonNilObject - |
|
727 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
728 |
* and SmallInteger |
|
729 |
*/ |
|
730 |
if (__isSmallInteger(index)) { |
|
6654 | 731 |
myClass = __qClass(self); |
732 |
indx = __intVal(index) - 1; |
|
733 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
734 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
735 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
736 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
737 |
||
738 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
739 |
case __MASKSMALLINT(POINTERARRAY): |
|
740 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
741 |
/* |
|
742 |
* pointers |
|
743 |
*/ |
|
744 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
745 |
OBJ *op; |
|
746 |
||
747 |
op = (OBJ *)pFirst + indx; |
|
748 |
RETURN ( *op ); |
|
749 |
} |
|
750 |
break; |
|
751 |
||
752 |
case __MASKSMALLINT(BYTEARRAY): |
|
753 |
/* |
|
754 |
* (unsigned) bytes |
|
755 |
*/ |
|
756 |
if ((unsigned)indx < nbytes) { |
|
757 |
unsigned char *cp; |
|
758 |
||
759 |
cp = (unsigned char *)pFirst + indx; |
|
8913 | 760 |
RETURN ( __mkSmallInteger( (*cp & 0xFF)) ); |
6654 | 761 |
} |
762 |
break; |
|
763 |
||
764 |
case __MASKSMALLINT(FLOATARRAY): |
|
765 |
/* |
|
766 |
* native floats |
|
767 |
*/ |
|
768 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
769 |
float *fp; |
|
770 |
float f; |
|
771 |
OBJ v; |
|
772 |
||
773 |
fp = (float *)pFirst + indx; |
|
774 |
f = *fp; |
|
775 |
if (f == 0.0) { |
|
776 |
v = __float0; |
|
777 |
} else { |
|
778 |
__qMKSFLOAT(v, f); |
|
779 |
} |
|
780 |
RETURN (v); |
|
781 |
} |
|
782 |
break; |
|
783 |
||
784 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
785 |
/* |
|
786 |
* native doubles |
|
787 |
*/ |
|
5755 | 788 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 789 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
790 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
791 |
||
792 |
pFirst += delta; |
|
793 |
nbytes -= delta; |
|
794 |
} |
|
5755 | 795 |
#endif |
6654 | 796 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
797 |
double *dp; |
|
798 |
double d; |
|
799 |
OBJ v; |
|
800 |
||
801 |
dp = (double *)pFirst + indx; |
|
802 |
d = *dp; |
|
803 |
if (d == 0.0) { |
|
804 |
v = __float0; |
|
805 |
} else { |
|
806 |
__qMKFLOAT(v, d); |
|
807 |
} |
|
808 |
RETURN (v); |
|
809 |
} |
|
810 |
break; |
|
811 |
||
812 |
case __MASKSMALLINT(WORDARRAY): |
|
813 |
/* |
|
814 |
* unsigned 16bit ints |
|
815 |
*/ |
|
816 |
/* Notice: the hard coded shifts are by purpose; |
|
817 |
* it makes us independent of the short-size of the machine |
|
818 |
*/ |
|
819 |
if ((unsigned)indx < (nbytes>>1)) { |
|
820 |
unsigned short *sp; |
|
821 |
||
822 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
8913 | 823 |
RETURN ( __mkSmallInteger( (*sp & 0xFFFF)) ); |
6654 | 824 |
} |
825 |
break; |
|
826 |
||
827 |
case __MASKSMALLINT(SWORDARRAY): |
|
828 |
/* |
|
829 |
* signed 16bit ints |
|
830 |
*/ |
|
831 |
/* Notice: the hard coded shifts are by purpose; |
|
832 |
* it makes us independent of the short-size of the machine |
|
833 |
*/ |
|
834 |
if ((unsigned)indx < (nbytes>>1)) { |
|
835 |
short *ssp; |
|
836 |
||
837 |
ssp = (short *)(pFirst + (indx<<1)); |
|
8913 | 838 |
RETURN ( __mkSmallInteger( (*ssp) )); |
6654 | 839 |
} |
840 |
break; |
|
841 |
||
842 |
case __MASKSMALLINT(LONGARRAY): |
|
843 |
/* |
|
844 |
* unsigned 32bit ints |
|
845 |
*/ |
|
846 |
/* Notice: the hard coded shifts are by purpose; |
|
847 |
* it makes us independent of the int-size of the machine |
|
848 |
*/ |
|
849 |
if ((unsigned)indx < (nbytes>>2)) { |
|
850 |
unsigned int32 ul; |
|
851 |
unsigned int32 *lp; |
|
852 |
||
853 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
854 |
ul = *lp; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
855 |
#if __POINTER_SIZE__ == 8 |
6654 | 856 |
{ |
857 |
unsigned INT ull = (unsigned INT)ul; |
|
8913 | 858 |
RETURN ( __mkSmallInteger(ull) ); |
6654 | 859 |
} |
5755 | 860 |
#else |
6654 | 861 |
if (ul <= _MAX_INT) { |
8913 | 862 |
RETURN ( __mkSmallInteger(ul) ); |
6654 | 863 |
} |
864 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 865 |
#endif |
6654 | 866 |
} |
867 |
break; |
|
868 |
||
869 |
case __MASKSMALLINT(SLONGARRAY): |
|
870 |
/* |
|
871 |
* signed 32bit ints |
|
872 |
*/ |
|
873 |
/* Notice: the hard coded shifts are by purpose; |
|
874 |
* it makes us independent of the int-size of the machine |
|
875 |
*/ |
|
876 |
if ((unsigned)indx < (nbytes>>2)) { |
|
877 |
int32 *slp; |
|
878 |
int32 l; |
|
879 |
||
880 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
881 |
l = *slp; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
882 |
#if __POINTER_SIZE__ == 8 |
6654 | 883 |
{ |
884 |
INT ll = (INT)l; |
|
8913 | 885 |
RETURN ( __mkSmallInteger(ll) ); |
6654 | 886 |
} |
5755 | 887 |
#else |
6654 | 888 |
if (__ISVALIDINTEGER(l)) { |
8913 | 889 |
RETURN ( __mkSmallInteger(l) ); |
6654 | 890 |
} |
891 |
RETURN ( __MKLARGEINT(l) ); |
|
5755 | 892 |
#endif |
6654 | 893 |
} |
894 |
break; |
|
895 |
||
896 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
897 |
/* |
|
898 |
* signed 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)) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
912 |
#if __POINTER_SIZE__ == 8 |
6654 | 913 |
INT *slp, ll; |
914 |
||
915 |
slp = (INT *)(pFirst + (indx<<3)); |
|
916 |
ll = *slp; |
|
917 |
if (__ISVALIDINTEGER(ll)) { |
|
8913 | 918 |
RETURN ( __mkSmallInteger(ll) ); |
6654 | 919 |
} |
920 |
RETURN ( __MKLARGEINT(ll) ); |
|
5755 | 921 |
#else |
6654 | 922 |
__int64__ *llp; |
923 |
||
924 |
llp = (__int64__ *)(pFirst + (indx<<3)); |
|
925 |
RETURN (__MKINT64(llp)); |
|
5755 | 926 |
#endif |
6654 | 927 |
} |
928 |
break; |
|
929 |
||
930 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
931 |
/* |
|
932 |
* unsigned 64bit longlongs |
|
933 |
*/ |
|
5755 | 934 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 935 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
936 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
937 |
||
938 |
pFirst += delta; |
|
939 |
nbytes -= delta; |
|
940 |
} |
|
5755 | 941 |
#endif |
6654 | 942 |
/* Notice: the hard coded shifts are by purpose; |
943 |
* it makes us independent of the long/longlong-size of the machine |
|
944 |
*/ |
|
945 |
if ((unsigned)indx < (nbytes>>3)) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
946 |
#if __POINTER_SIZE__ == 8 |
6654 | 947 |
unsigned INT *ulp, ul; |
948 |
||
949 |
ulp = (unsigned INT *)(pFirst + (indx<<3)); |
|
950 |
ul = *ulp; |
|
951 |
if (ul <= _MAX_INT) { |
|
8913 | 952 |
RETURN ( __mkSmallInteger(ul) ); |
6654 | 953 |
} |
954 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 955 |
#else |
6654 | 956 |
__uint64__ *llp; |
957 |
||
958 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
959 |
RETURN (__MKUINT64(llp)); |
|
5755 | 960 |
#endif |
6654 | 961 |
} |
962 |
break; |
|
963 |
} |
|
5755 | 964 |
} |
965 |
%}. |
|
7216 | 966 |
^ self indexNotIntegerOrOutOfBounds:index |
5755 | 967 |
! |
968 |
||
969 |
basicAt:index put:anObject |
|
970 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
971 |
Returns anObject (sigh). |
|
972 |
Trigger an error if the receiver has no indexed instance variables. |
|
973 |
||
974 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
975 |
||
976 |
%{ /* NOCONTEXT */ |
|
977 |
||
978 |
register int nbytes, indx; |
|
979 |
OBJ myClass; |
|
980 |
register char *pFirst; |
|
981 |
/* int nInstBytes, ninstvars, flags; */ |
|
982 |
REGISTER int n; |
|
983 |
unsigned int u; |
|
984 |
int val; |
|
985 |
||
986 |
/* notice the missing test for self being a nonNilObject - |
|
987 |
this can be done since basicAt: is defined both in UndefinedObject |
|
988 |
and SmallInteger */ |
|
989 |
||
990 |
if (__isSmallInteger(index)) { |
|
6654 | 991 |
indx = __intVal(index) - 1; |
992 |
myClass = __qClass(self); |
|
993 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
994 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
995 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
996 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
997 |
||
998 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
999 |
case __MASKSMALLINT(POINTERARRAY): |
|
1000 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
1001 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
1002 |
OBJ *op; |
|
1003 |
||
1004 |
op = (OBJ *)pFirst + indx; |
|
1005 |
*op = anObject; |
|
1006 |
__STORE(self, anObject); |
|
1007 |
RETURN ( anObject ); |
|
1008 |
} |
|
1009 |
break; |
|
1010 |
||
1011 |
case __MASKSMALLINT(BYTEARRAY): |
|
1012 |
if (__isSmallInteger(anObject)) { |
|
1013 |
val = __intVal(anObject); |
|
1014 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
1015 |
if ((unsigned)indx < nbytes) { |
|
1016 |
char *cp; |
|
1017 |
||
1018 |
cp = pFirst + indx; |
|
1019 |
*cp = val; |
|
1020 |
RETURN ( anObject ); |
|
1021 |
} |
|
1022 |
} |
|
1023 |
} |
|
1024 |
break; |
|
1025 |
||
1026 |
case __MASKSMALLINT(FLOATARRAY): |
|
1027 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
1028 |
float *fp; |
|
1029 |
||
1030 |
fp = (float *)pFirst + indx; |
|
1031 |
if (anObject != nil) { |
|
1032 |
if (! __isSmallInteger(anObject)) { |
|
1033 |
if (__qIsFloatLike(anObject)) { |
|
1034 |
*fp = (float)(__floatVal(anObject)); |
|
1035 |
RETURN ( anObject ); |
|
1036 |
} |
|
1037 |
if (__qIsShortFloat(anObject)) { |
|
1038 |
*fp = __shortFloatVal(anObject); |
|
1039 |
RETURN ( anObject ); |
|
1040 |
} |
|
1041 |
} else { |
|
1042 |
*fp = (float) __intVal(anObject); |
|
1043 |
RETURN ( anObject ); |
|
1044 |
} |
|
1045 |
} |
|
1046 |
} |
|
1047 |
break; |
|
1048 |
||
1049 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1050 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 1051 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1052 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1053 |
||
1054 |
pFirst += delta; |
|
1055 |
nbytes -= delta; |
|
1056 |
} |
|
5755 | 1057 |
#endif |
6654 | 1058 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
1059 |
double *dp; |
|
1060 |
||
1061 |
dp = (double *)pFirst + indx; |
|
1062 |
if (anObject != nil) { |
|
1063 |
if (! __isSmallInteger(anObject)) { |
|
1064 |
if (__qIsFloatLike(anObject)) { |
|
1065 |
*dp = __floatVal(anObject); |
|
1066 |
RETURN ( anObject ); |
|
1067 |
} |
|
1068 |
if (__qIsShortFloat(anObject)) { |
|
1069 |
*dp = (double)__shortFloatVal(anObject); |
|
1070 |
RETURN ( anObject ); |
|
1071 |
} |
|
1072 |
} else { |
|
1073 |
*dp = (double) __intVal(anObject); |
|
1074 |
RETURN ( anObject ); |
|
1075 |
} |
|
1076 |
} |
|
1077 |
} |
|
1078 |
break; |
|
1079 |
||
1080 |
case __MASKSMALLINT(WORDARRAY): |
|
1081 |
if (__isSmallInteger(anObject)) { |
|
1082 |
val = __intVal(anObject); |
|
1083 |
if ((unsigned)val <= 0xFFFF) { |
|
1084 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1085 |
unsigned short *sp; |
|
1086 |
||
1087 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
1088 |
*sp = val; |
|
1089 |
RETURN ( anObject ); |
|
1090 |
} |
|
1091 |
} |
|
1092 |
} |
|
1093 |
break; |
|
1094 |
||
1095 |
case __MASKSMALLINT(SWORDARRAY): |
|
1096 |
if (__isSmallInteger(anObject)) { |
|
1097 |
val = __intVal(anObject); |
|
1098 |
if ((val >= -32768) && (val < 32768)) { |
|
1099 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1100 |
short *ssp; |
|
1101 |
||
1102 |
ssp = (short *)(pFirst + (indx<<1)); |
|
1103 |
*ssp = val; |
|
1104 |
RETURN ( anObject ); |
|
1105 |
} |
|
1106 |
} |
|
1107 |
} |
|
1108 |
break; |
|
1109 |
||
1110 |
case __MASKSMALLINT(SLONGARRAY): |
|
1111 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1112 |
int32 *slp; |
|
1113 |
||
1114 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
1115 |
if (__isSmallInteger(anObject)) { |
|
1116 |
*slp = __intVal(anObject); |
|
1117 |
RETURN ( anObject ); |
|
1118 |
} |
|
1119 |
n = __signedLongIntVal(anObject); |
|
1120 |
/* |
|
1121 |
* zero means failure for an int larger than 4 bytes |
|
1122 |
* (would be a smallInteger) |
|
1123 |
*/ |
|
1124 |
if (n) { |
|
1125 |
*slp = n; |
|
1126 |
RETURN ( anObject ); |
|
1127 |
} |
|
1128 |
} |
|
1129 |
break; |
|
1130 |
||
1131 |
case __MASKSMALLINT(LONGARRAY): |
|
1132 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1133 |
unsigned int32 *lp; |
|
1134 |
||
1135 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
8913 | 1136 |
if (anObject == __mkSmallInteger(0)) { |
6654 | 1137 |
*lp = 0; |
1138 |
RETURN ( anObject ); |
|
1139 |
} |
|
1140 |
u = __longIntVal(anObject); |
|
1141 |
/* |
|
1142 |
* zero means failure for an int larger than 4 bytes |
|
1143 |
* (would be a smallInteger) |
|
1144 |
*/ |
|
1145 |
if (u) { |
|
1146 |
*lp = u; |
|
1147 |
RETURN ( anObject ); |
|
1148 |
} |
|
1149 |
} |
|
1150 |
break; |
|
1151 |
||
1152 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1153 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1154 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1155 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1156 |
||
1157 |
pFirst += delta; |
|
1158 |
nbytes -= delta; |
|
1159 |
} |
|
5755 | 1160 |
#endif |
6654 | 1161 |
if ((unsigned)indx < (nbytes>>3)) { |
1162 |
__int64__ ll; |
|
1163 |
__int64__ *sllp; |
|
1164 |
||
1165 |
sllp = (__int64__ *)(pFirst + (indx<<3)); |
|
1166 |
||
8913 | 1167 |
if (anObject == __mkSmallInteger(0)) { |
6654 | 1168 |
ll.lo = ll.hi = 0; |
1169 |
*sllp = ll; |
|
1170 |
RETURN ( anObject ); |
|
1171 |
} |
|
1172 |
if (__signedLong64IntVal(anObject, &ll)) { |
|
1173 |
*sllp = ll; |
|
1174 |
RETURN ( anObject ); |
|
1175 |
} |
|
1176 |
} |
|
1177 |
break; |
|
1178 |
||
1179 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
5755 | 1180 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1181 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1182 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1183 |
||
1184 |
pFirst += delta; |
|
1185 |
nbytes -= delta; |
|
1186 |
} |
|
5755 | 1187 |
#endif |
6654 | 1188 |
if ((unsigned)indx < (nbytes>>3)) { |
1189 |
__uint64__ ll; |
|
1190 |
__uint64__ *llp; |
|
1191 |
||
1192 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
8913 | 1193 |
if (anObject == __mkSmallInteger(0)) { |
6654 | 1194 |
ll.lo = ll.hi = 0; |
1195 |
*llp = ll; |
|
1196 |
RETURN ( anObject ); |
|
1197 |
} |
|
1198 |
if (__unsignedLong64IntVal(anObject, &ll)) { |
|
1199 |
*llp = ll; |
|
1200 |
RETURN ( anObject ); |
|
1201 |
} |
|
1202 |
} |
|
1203 |
break; |
|
1204 |
} |
|
5755 | 1205 |
} |
1206 |
%}. |
|
1207 |
index isInteger ifFalse:[ |
|
6654 | 1208 |
" |
1209 |
the index should be an integer number |
|
1210 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1211 |
^ self indexNotInteger:index |
5755 | 1212 |
]. |
1213 |
(index between:1 and:self size) ifFalse:[ |
|
6654 | 1214 |
" |
1215 |
the index is less than 1 or greater than the size of the |
|
1216 |
receiver collection |
|
1217 |
" |
|
1218 |
^ self subscriptBoundsError:index |
|
5755 | 1219 |
]. |
1220 |
(self class isFloatsOrDoubles) ifTrue:[ |
|
6654 | 1221 |
anObject isNumber ifTrue:[ |
1222 |
^ self basicAt:index put:(anObject asFloat) |
|
1223 |
] |
|
5755 | 1224 |
]. |
1225 |
anObject isInteger ifFalse:[ |
|
6654 | 1226 |
" |
1227 |
the object to put into the receiver collection |
|
1228 |
should be an integer number |
|
1229 |
" |
|
1230 |
^ self elementNotInteger |
|
5755 | 1231 |
]. |
1232 |
" |
|
1233 |
the object to put into the receiver collection |
|
1234 |
is not an instance of the expected element class, |
|
1235 |
or the value is not within the elements valid range. |
|
1236 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1237 |
^ self elementBoundsError:anObject |
5755 | 1238 |
|
1239 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
|
1240 |
! |
|
1241 |
||
1242 |
byteAt:index |
|
1243 |
"return the byte at index. |
|
1244 |
This is only allowed for non-pointer indexed objects |
|
1245 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1246 |
The receivers indexed instvars are treated as an uninterpreted |
|
1247 |
collection of bytes. |
|
1248 |
Only useful with binary storage." |
|
1249 |
||
1250 |
%{ /* NOCONTEXT */ |
|
1251 |
||
1252 |
REGISTER int indx; |
|
1253 |
int nIndex; |
|
1254 |
REGISTER OBJ slf; |
|
1255 |
REGISTER OBJ cls; |
|
1256 |
||
1257 |
if (__isSmallInteger(index)) { |
|
6654 | 1258 |
slf = self; |
1259 |
if (__isNonNilObject(slf)) { |
|
1260 |
unsigned char *pFirst; |
|
1261 |
int nIndex; |
|
1262 |
||
1263 |
cls = __qClass(slf); |
|
1264 |
||
1265 |
pFirst = __byteArrayVal(slf); |
|
1266 |
pFirst += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1267 |
nIndex = __byteArraySize(slf); |
|
1268 |
indx = __intVal(index) - 1; |
|
1269 |
||
1270 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1271 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1272 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 1273 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1274 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1275 |
||
1276 |
pFirst += delta; |
|
1277 |
nIndex -= delta; |
|
1278 |
} |
|
5755 | 1279 |
#endif |
6654 | 1280 |
/* fall into */ |
1281 |
case __MASKSMALLINT(BYTEARRAY): |
|
1282 |
case __MASKSMALLINT(WORDARRAY): |
|
1283 |
case __MASKSMALLINT(LONGARRAY): |
|
1284 |
case __MASKSMALLINT(SWORDARRAY): |
|
1285 |
case __MASKSMALLINT(SLONGARRAY): |
|
1286 |
case __MASKSMALLINT(FLOATARRAY): |
|
1287 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
8913 | 1288 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
6654 | 1289 |
} |
1290 |
break; |
|
1291 |
||
1292 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1293 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1294 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 1295 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1296 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1297 |
||
1298 |
pFirst += delta; |
|
1299 |
nIndex -= delta; |
|
1300 |
} |
|
5755 | 1301 |
#endif |
6654 | 1302 |
if ((unsigned)indx < (unsigned)nIndex) { |
8913 | 1303 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
6654 | 1304 |
} |
1305 |
break; |
|
1306 |
} |
|
1307 |
} |
|
5755 | 1308 |
} |
1309 |
%}. |
|
1310 |
"/ index not integer or index out of range |
|
1311 |
"/ or non-byte indexable receiver |
|
1312 |
||
1313 |
^ self primitiveFailed |
|
1314 |
||
1315 |
" |
|
1316 |
Point new byteAt:1 |
|
1317 |
(ByteArray with:1 with:2) byteAt:2 |
|
1318 |
(WordArray with:1) byteAt:1 |
|
1319 |
(FloatArray with:1.0) byteAt:2 |
|
1320 |
'hello' byteAt:1 |
|
1321 |
" |
|
1322 |
! |
|
1323 |
||
1324 |
byteAt:index put:byteValue |
|
1325 |
"set the byte at index. |
|
1326 |
This is only allowed for non-pointer indexed objects |
|
1327 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1328 |
The receivers indexed instvars are treated as an uninterpreted |
|
1329 |
collection of bytes. |
|
1330 |
Only useful with binary storage." |
|
1331 |
||
1332 |
%{ /* NOCONTEXT */ |
|
1333 |
||
1334 |
REGISTER int indx; |
|
1335 |
int val, nIndex; |
|
1336 |
REGISTER OBJ slf; |
|
1337 |
REGISTER OBJ cls; |
|
1338 |
||
1339 |
if (__bothSmallInteger(index, byteValue)) { |
|
6654 | 1340 |
val = __intVal(byteValue); |
1341 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
1342 |
slf = self; |
|
1343 |
if (__isNonNilObject(slf)) { |
|
1344 |
cls = __qClass(slf); |
|
1345 |
||
1346 |
indx = __intVal(index) - 1; |
|
1347 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1348 |
case __MASKSMALLINT(BYTEARRAY): |
|
1349 |
case __MASKSMALLINT(WORDARRAY): |
|
1350 |
case __MASKSMALLINT(LONGARRAY): |
|
1351 |
case __MASKSMALLINT(SWORDARRAY): |
|
1352 |
case __MASKSMALLINT(SLONGARRAY): |
|
1353 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1354 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1355 |
case __MASKSMALLINT(FLOATARRAY): |
|
1356 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
1357 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1358 |
nIndex = __byteArraySize(slf); |
|
1359 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1360 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
1361 |
RETURN ( byteValue ); |
|
1362 |
} |
|
1363 |
break; |
|
1364 |
} |
|
1365 |
} |
|
1366 |
} |
|
5755 | 1367 |
} |
1368 |
%}. |
|
1369 |
"/ index not integer or index out of range |
|
1370 |
"/ or non-byte indexable receiver |
|
1371 |
||
1372 |
^ self primitiveFailed |
|
1373 |
||
1374 |
" |
|
1375 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
|
1376 |
'hello' copy byteAt:1 put:105; yourself |
|
1377 |
" |
|
1378 |
! |
|
1379 |
||
1380 |
instVarAt:index |
|
1381 |
"return a non-indexed instance variable; |
|
1382 |
peeking into an object this way is not very object oriented |
|
1383 |
- use with care (needed for copy, inspector etc.)" |
|
1384 |
||
1385 |
%{ /* NOCONTEXT */ |
|
1386 |
||
1387 |
OBJ myClass; |
|
1388 |
int idx, ninstvars; |
|
1389 |
||
1390 |
if (__isSmallInteger(index)) { |
|
6654 | 1391 |
myClass = __Class(self); |
1392 |
idx = __intVal(index) - 1; |
|
1393 |
/* |
|
1394 |
* do not allow returning of non-object fields. |
|
1395 |
* if subclass did not make privisions for that, |
|
1396 |
* we wont do so here ... |
|
1397 |
*/ |
|
1398 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1399 |
if (idx == 0) { |
|
1400 |
RETURN ( nil ) |
|
1401 |
} |
|
1402 |
} |
|
1403 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1404 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1405 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
|
1406 |
} |
|
5755 | 1407 |
} |
7216 | 1408 |
%}. |
1409 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1410 |
! |
1411 |
||
1412 |
instVarAt:index put:value |
|
1413 |
"change a non-indexed instance variable; |
|
1414 |
peeking into an object this way is not very object oriented |
|
1415 |
- use with care (needed for copy, inspector etc.)" |
|
1416 |
||
1417 |
%{ /* NOCONTEXT */ |
|
1418 |
||
1419 |
OBJ myClass; |
|
1420 |
int idx, ninstvars; |
|
1421 |
||
1422 |
if (__isSmallInteger(index)) { |
|
6654 | 1423 |
myClass = __Class(self); |
1424 |
idx = __intVal(index) - 1; |
|
1425 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1426 |
/* |
|
1427 |
* do not allow setting of non-object fields. |
|
1428 |
* if subclass did not make privisions for that, |
|
1429 |
* we wont do so here ... |
|
1430 |
*/ |
|
1431 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1432 |
if (idx == 0) { |
|
1433 |
RETURN ( nil ) |
|
1434 |
} |
|
1435 |
} |
|
1436 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1437 |
__InstPtr(self)->i_instvars[idx] = value; |
|
1438 |
__STORE(self, value); |
|
1439 |
RETURN ( value ); |
|
1440 |
} |
|
5755 | 1441 |
} |
7216 | 1442 |
%}. |
1443 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1444 |
! |
1445 |
||
1446 |
instVarNamed:name |
|
1447 |
"return a non-indexed instance variables value by name; |
|
1448 |
peeking into an object this way is not very object oriented |
|
1449 |
- use with care if at all (provided for inspectors and memory usage monitor). |
|
1450 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1451 |
parsed ad runtime)" |
|
1452 |
||
1453 |
^ self instVarAt:(self class instVarOffsetOf:name) |
|
1454 |
||
1455 |
||
1456 |
" |
|
1457 |
|p| |
|
1458 |
||
1459 |
p := Point x:10 y:20. |
|
1460 |
p instVarNamed:'x' |
|
1461 |
" |
|
1462 |
||
1463 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
|
1464 |
! |
|
1465 |
||
1466 |
instVarNamed:name ifAbsent:exceptionBlock |
|
1467 |
"return a non-indexed instance variables value by name, |
|
1468 |
or the value of exceptionBlock, if there is no such instance variable. |
|
1469 |
peeking into an object this way is not very object oriented |
|
1470 |
- use with care if at all (provided for inspectors and memory usage monitor). |
|
1471 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1472 |
parsed ad runtime)" |
|
1473 |
||
1474 |
|idx| |
|
1475 |
||
1476 |
idx := self class instVarOffsetOf:name. |
|
1477 |
idx isNil ifTrue:[^ exceptionBlock value]. |
|
1478 |
^ self instVarAt:idx |
|
1479 |
||
1480 |
||
1481 |
" |
|
1482 |
|p| |
|
1483 |
||
1484 |
p := Point x:10 y:20. |
|
1485 |
p instVarNamed:'x' |
|
1486 |
" |
|
1487 |
||
1488 |
"Created: 6.7.1996 / 23:02:49 / cg" |
|
1489 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
|
1490 |
! |
|
1491 |
||
1492 |
instVarNamed:name put:value |
|
1493 |
"set a non-indexed instance variable by name; |
|
1494 |
peeking into an object this way is not very object oriented |
|
1495 |
- if at all, use with care (provided for protocol completeness). |
|
1496 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1497 |
parsed ad runtime)" |
|
1498 |
||
1499 |
^ self instVarAt:(self class instVarOffsetOf:name) put:value |
|
1500 |
||
1501 |
" |
|
1502 |
|p| |
|
1503 |
||
1504 |
p := Point x:10 y:20. |
|
1505 |
p instVarNamed:'x' put:30. |
|
1506 |
p |
|
1507 |
" |
|
1508 |
||
1509 |
"Modified: 19.4.1996 / 11:12:49 / cg" |
|
1510 |
! ! |
|
1511 |
||
1512 |
!Object methodsFor:'attributes access'! |
|
1513 |
||
6323 | 1514 |
objectAttributeAt:attributeKey |
5755 | 1515 |
"return the attribute for a given key or nil if not found" |
1516 |
||
1517 |
| attrs | |
|
1518 |
||
1519 |
attrs := self objectAttributes. |
|
1520 |
(attrs notNil and:[attrs size > 0]) ifTrue:[ |
|
6654 | 1521 |
^ attrs at:attributeKey ifAbsent:[] |
5755 | 1522 |
]. |
1523 |
^ nil |
|
1524 |
||
1525 |
"Created: / 22.1.1998 / 21:29:17 / av" |
|
1526 |
"Modified: / 3.2.1998 / 18:55:55 / cg" |
|
1527 |
! |
|
1528 |
||
6323 | 1529 |
objectAttributeAt:attributeKey put:anObject |
5755 | 1530 |
"store the attribute anObject referenced by key into the receiver" |
1531 |
||
1532 |
"/ must do this save from interrupts, since the attributes collection |
|
1533 |
"/ is possibly accessed from multiple threads ... |
|
1534 |
[ |
|
6654 | 1535 |
| attrs | |
1536 |
||
1537 |
attrs := self objectAttributes. |
|
1538 |
(attrs isNil or:[attrs size == 0]) ifTrue:[ |
|
1539 |
attrs := WeakIdentityDictionary new. |
|
1540 |
attrs at:attributeKey put:anObject. |
|
1541 |
self objectAttributes:attrs. |
|
1542 |
] ifFalse:[ |
|
1543 |
attrs at:attributeKey put:anObject. |
|
1544 |
]. |
|
6323 | 1545 |
] valueUninterruptably |
5755 | 1546 |
|
1547 |
"Attaching additional attributes (slots) to an arbitrary object: |
|
1548 |
||
1549 |
|p| |
|
1550 |
||
1551 |
p := Point new. |
|
1552 |
p objectAttributeAt:#color put:#green. |
|
1553 |
||
1554 |
p objectAttributeAt:#color |
|
1555 |
" |
|
1556 |
||
1557 |
"Created: / 22.1.1998 / 21:29:25 / av" |
|
1558 |
"Modified: / 3.2.1998 / 18:57:58 / cg" |
|
1559 |
! |
|
1560 |
||
1561 |
objectAttributes |
|
1562 |
"return a Collection of attributes - nil if there is none. |
|
1563 |
The default implementation here uses a global WeakDictionary to store |
|
1564 |
attributes |
|
1565 |
This may be too slow for high frequency slot access, |
|
1566 |
therefore, some classes may redefine this for better performance. |
|
1567 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
1568 |
||
1569 |
^ ObjectAttributes at:self ifAbsent:[nil] |
|
1570 |
||
1571 |
"Created: / 22.1.1998 / 21:29:30 / av" |
|
1572 |
"Modified: / 18.2.2000 / 11:34:16 / cg" |
|
1573 |
! |
|
1574 |
||
1575 |
objectAttributes:aCollection |
|
1576 |
"set the collection of attributes. |
|
1577 |
The default implementation here uses a global Dictionary to store |
|
1578 |
attributes which may be too slow for high frequency change&update. |
|
1579 |
Therefore, some classes may redefine this for better performance." |
|
1580 |
||
1581 |
"/ must do this save from interrupts, since the attributes collection |
|
1582 |
"/ is possibly accessed from multiple threads. |
|
1583 |
||
1584 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
6654 | 1585 |
"/ the common case - already blocked |
1586 |
||
1587 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
1588 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1589 |
] ifFalse:[ |
|
1590 |
ObjectAttributes at:self put:aCollection |
|
1591 |
]. |
|
1592 |
^ self |
|
5755 | 1593 |
]. |
1594 |
||
1595 |
[ |
|
6654 | 1596 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
1597 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1598 |
] ifFalse:[ |
|
1599 |
ObjectAttributes at:self put:aCollection |
|
1600 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
1601 |
] ensure:[ |
6654 | 1602 |
OperatingSystem unblockInterrupts |
5755 | 1603 |
] |
1604 |
||
1605 |
"Created: / 22.1.1998 / 21:29:35 / av" |
|
1606 |
"Modified: / 3.2.1998 / 18:58:10 / cg" |
|
1607 |
! |
|
1608 |
||
6323 | 1609 |
removeObjectAttribute:attributeKey |
5755 | 1610 |
"make the argument, anObject be no attribute of the receiver" |
1611 |
||
1612 |
"/ must do this save from interrupts, since the attributes collection |
|
1613 |
"/ is possibly accessed from multiple threads. |
|
1614 |
[ |
|
6654 | 1615 |
|attrs n a| |
1616 |
||
1617 |
attrs := self objectAttributes. |
|
1618 |
attrs size == 0 ifTrue:[ |
|
1619 |
self objectAttributes:nil |
|
1620 |
] ifFalse:[ |
|
1621 |
attrs removeKey:attributeKey ifAbsent:nil. |
|
1622 |
attrs size == 0 ifTrue:[ |
|
1623 |
self objectAttributes:nil |
|
1624 |
] |
|
1625 |
] |
|
6323 | 1626 |
] valueUninterruptably |
5755 | 1627 |
|
1628 |
"Created: / 22.1.1998 / 21:29:39 / av" |
|
1629 |
"Modified: / 18.2.2000 / 11:32:19 / cg" |
|
1630 |
! ! |
|
1631 |
||
1632 |
||
1633 |
!Object methodsFor:'change & update'! |
|
1634 |
||
1635 |
broadcast:aSelectorSymbol |
|
1636 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1637 |
||
1638 |
self dependentsDo:[:dependent | |
|
6654 | 1639 |
dependent perform:aSelectorSymbol |
5755 | 1640 |
] |
1641 |
! |
|
1642 |
||
1643 |
broadcast:aSelectorSymbol with:anArgument |
|
1644 |
"send a message with selector aSelectorSymbol with an additional |
|
1645 |
argument anArgument to all my dependents." |
|
1646 |
||
1647 |
self dependentsDo:[:dependent | |
|
6654 | 1648 |
dependent perform:aSelectorSymbol with:anArgument |
5755 | 1649 |
] |
1650 |
! |
|
1651 |
||
1652 |
changeRequest |
|
1653 |
"the receiver wants to change - check if all dependents |
|
1654 |
grant the request, and return true if so" |
|
1655 |
||
1656 |
self dependentsDo:[:dependent | |
|
6654 | 1657 |
dependent updateRequest ifFalse:[^ false]. |
5755 | 1658 |
]. |
1659 |
^ true |
|
1660 |
! |
|
1661 |
||
1662 |
changeRequest:aParameter |
|
1663 |
"the receiver wants to change - check if all dependents |
|
1664 |
grant the request, and return true if so" |
|
1665 |
||
1666 |
self dependentsDo:[:dependent | |
|
6654 | 1667 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
5755 | 1668 |
]. |
1669 |
^ true |
|
1670 |
! |
|
1671 |
||
1672 |
changeRequest:aParameter from:anObject |
|
1673 |
"the receiver wants to change - check if all dependents |
|
1674 |
except anObject grant the request, and return true if so. |
|
1675 |
The argument anObject is typically going to be the one who is |
|
1676 |
about to send the change request." |
|
1677 |
||
1678 |
self dependentsDo:[:dependent | |
|
6654 | 1679 |
dependent == anObject ifFalse:[ |
1680 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
1681 |
] |
|
5755 | 1682 |
]. |
1683 |
^ true |
|
1684 |
! |
|
1685 |
||
1686 |
changeRequestFrom:anObject |
|
1687 |
"the receiver wants to change - check if all dependents |
|
1688 |
except anObject grant the request, and return true if so. |
|
1689 |
The argument anObject is typically going to be the one who is |
|
1690 |
about to send the change request." |
|
1691 |
||
1692 |
self dependentsDo:[:dependent | |
|
6654 | 1693 |
dependent == anObject ifFalse:[ |
1694 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1695 |
] |
|
5755 | 1696 |
]. |
1697 |
^ true |
|
1698 |
! |
|
1699 |
||
1700 |
changed |
|
1701 |
"notify all dependents that the receiver has changed. |
|
1702 |
Each dependent gets a '#update:'-message with the original |
|
1703 |
receiver as argument." |
|
1704 |
||
1705 |
self changed:nil |
|
1706 |
! |
|
1707 |
||
1708 |
changed:aParameter |
|
1709 |
"notify all dependents that the receiver has changed somehow. |
|
1710 |
Each dependent gets a '#update:'-message with aParameter |
|
1711 |
as argument." |
|
1712 |
||
1713 |
self changed:aParameter with:nil |
|
1714 |
! |
|
1715 |
||
1716 |
changed:aParameter with:anArgument |
|
1717 |
"notify all dependents that the receiver has changed somehow. |
|
1718 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
|
1719 |
and anArgument as arguments." |
|
1720 |
||
1721 |
self dependentsDo:[:dependent | |
|
6654 | 1722 |
dependent update:aParameter with:anArgument from:self |
5755 | 1723 |
] |
1724 |
! |
|
1725 |
||
1726 |
update:aParameter |
|
1727 |
"the message is sent to a dependent, when one of the objects |
|
1728 |
on whom the receiver depends, has changed. The argument aParameter |
|
1729 |
is either the changed object or the argument to the #changed: message. |
|
1730 |
||
1731 |
Default behavior here is to do nothing" |
|
1732 |
||
1733 |
^ self |
|
1734 |
! |
|
1735 |
||
1736 |
update:aParameter with:anArgument |
|
1737 |
"dependent is notified of some change - |
|
1738 |
Default is to try update:" |
|
1739 |
||
1740 |
^ self update:aParameter |
|
1741 |
! |
|
1742 |
||
1743 |
update:aParameter with:anArgument from:sender |
|
1744 |
"dependent is notified of some change - |
|
1745 |
Default is to try update:with:" |
|
1746 |
||
1747 |
^ self update:aParameter with:anArgument |
|
1748 |
! |
|
1749 |
||
1750 |
updateRequest |
|
1751 |
"return true, if an update request is granted. |
|
1752 |
Default here is to grant updates - may be used |
|
1753 |
to lock updates if someone is making other changes |
|
1754 |
from within an update. Or if someone has locked its |
|
1755 |
state and does not want others to change things. |
|
1756 |
However, these dependents must all honor the |
|
1757 |
changeRequest - ifTrue - change protocol. I.e. they |
|
1758 |
must first ask all others via changeRequest, and only do the change |
|
1759 |
it returns true. The others must decide in updateRequest and |
|
1760 |
return true if they think a change is ok." |
|
1761 |
||
1762 |
^ true |
|
1763 |
! |
|
1764 |
||
1765 |
updateRequest:aSymbol |
|
1766 |
"return true, if an update request is granted. |
|
1767 |
Default here a simple updateRequest" |
|
1768 |
||
1769 |
^ self updateRequest |
|
7177 | 1770 |
! |
1771 |
||
1772 |
withoutUpdating:someone do:aBlock |
|
1773 |
"evaluate a block but remove someone from my dependents temporarily" |
|
1774 |
||
1775 |
(self dependents includesIdentical:someone) |
|
1776 |
ifFalse:[ |
|
1777 |
^ aBlock value. |
|
1778 |
]. |
|
1779 |
self removeDependent:someone. |
|
1780 |
^ aBlock ensure:[ self addDependent:someone ] |
|
5755 | 1781 |
! ! |
1782 |
||
1783 |
!Object methodsFor:'cleanup'! |
|
1784 |
||
1785 |
lowSpaceCleanup |
|
1786 |
"ignored here - redefined in some classes to |
|
1787 |
cleanup in low-memory situations" |
|
1788 |
||
1789 |
^ self |
|
1790 |
! ! |
|
1791 |
||
1792 |
!Object methodsFor:'comparing'! |
|
1793 |
||
1794 |
= anObject |
|
1795 |
"return true, if the receiver and the arg have the same structure. |
|
1796 |
Notice: |
|
6654 | 1797 |
This method is partially open coded (inlined) by the compiler(s) |
1798 |
identical objects are always considered equal. |
|
1799 |
redefining it may not work as expected." |
|
5755 | 1800 |
|
1801 |
^ self == anObject |
|
1802 |
! |
|
1803 |
||
1804 |
== anObject |
|
1805 |
"return true, if the receiver and the arg are the same object. |
|
1806 |
Never redefine this in any class. |
|
1807 |
Notice: |
|
6654 | 1808 |
This method is open coded (inlined) by the compiler(s) |
1809 |
- redefining it may not work as expected." |
|
5755 | 1810 |
|
1811 |
%{ /* NOCONTEXT */ |
|
1812 |
||
1813 |
RETURN ( (self == anObject) ? true : false ); |
|
1814 |
%} |
|
1815 |
! |
|
1816 |
||
5814 | 1817 |
deepSameContentsAs:anObject |
1818 |
"return true, if the receiver and the arg have the same contents |
|
1819 |
in both the named instance vars and any indexed instVars. |
|
1820 |
This method descends into referenced objects, where #sameContentsAs: does not descend" |
|
1821 |
||
5821 | 1822 |
|myClass val |
5814 | 1823 |
sz "{ Class: SmallInteger }" | |
1824 |
||
1825 |
myClass := self class. |
|
1826 |
myClass isVariable ifTrue:[ |
|
6654 | 1827 |
sz := self basicSize. |
1828 |
||
1829 |
"compare the indexed variables" |
|
1830 |
1 to:sz do:[:i | |
|
1831 |
val := self basicAt:i. |
|
1832 |
val isLiteral ifTrue:[ |
|
1833 |
val = (anObject basicAt:i) ifFalse:[^ false]. |
|
1834 |
] ifFalse:[ |
|
1835 |
(val deepSameContentsAs:(anObject basicAt:i)) ifFalse:[^ false]. |
|
1836 |
] |
|
1837 |
] |
|
5814 | 1838 |
]. |
1839 |
||
1840 |
"compare the instance variables" |
|
1841 |
sz := myClass instSize. |
|
1842 |
1 to:sz do:[:i | |
|
6654 | 1843 |
val := self instVarAt:i. |
1844 |
val isLiteral ifTrue:[ |
|
1845 |
val = (anObject instVarAt:i) ifFalse:[^ false]. |
|
1846 |
] ifFalse:[ |
|
1847 |
(val deepSameContentsAs:(anObject instVarAt:i)) ifFalse:[^ false]. |
|
1848 |
] |
|
5814 | 1849 |
]. |
1850 |
||
1851 |
^ true |
|
1852 |
||
1853 |
" |
|
1854 |
#(1 2 3 4) deepSameContentsAs:#[1 2 3 4] asArray |
|
1855 |
(1@2) deepSameContentsAs:(1->2) |
|
1856 |
" |
|
1857 |
! |
|
1858 |
||
5755 | 1859 |
hash |
1860 |
"return an Integer useful as a hash key for the receiver. |
|
1861 |
This hash should return same values for objects with same |
|
1862 |
contents (i.e. use this to hash on structure)" |
|
1863 |
||
1864 |
^ self identityHash |
|
1865 |
! |
|
1866 |
||
1867 |
identityHash |
|
1868 |
"return an Integer useful as a hash key for the receiver. |
|
1869 |
This hash should return same values for the same object (i.e. use |
|
1870 |
this to hash on identity of objects). |
|
1871 |
||
1872 |
We cannot use the Objects address (as other smalltalks do) since |
|
1873 |
no object-table exists and the hashval must not change when objects |
|
1874 |
are moved by the collector. Therefore we assign each object a unique |
|
1875 |
Id in the object header itself as its hashed upon. |
|
1876 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
1877 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
1878 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
1879 |
hashed-upon objects could add an instvar containing the hash value." |
|
1880 |
||
1881 |
%{ /* NOCONTEXT */ |
|
1882 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1883 |
REGISTER unsigned INT hash; |
5755 | 1884 |
static unsigned nextHash = 0; |
1885 |
||
1886 |
if (__isNonNilObject(self)) { |
|
6654 | 1887 |
hash = __GET_HASH(self); |
1888 |
if (hash == 0) { |
|
1889 |
/* has no hash yet */ |
|
1890 |
||
1891 |
if (++nextHash > __MAX_HASH__) { |
|
1892 |
nextHash = 1; |
|
1893 |
} |
|
1894 |
hash = nextHash; |
|
1895 |
__SET_HASH(self, hash); |
|
1896 |
} |
|
1897 |
||
1898 |
/* |
|
1899 |
* now, we got 11 bits for hashing; |
|
1900 |
* make it as large as possible; since most hashers use the returned |
|
1901 |
* key and take it modulo some prime number, this will allow for |
|
1902 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
1903 |
*/ |
|
1904 |
hash = __MAKE_HASH__(hash); |
|
8913 | 1905 |
RETURN ( __mkSmallInteger(hash) ); |
5755 | 1906 |
} |
1907 |
%}. |
|
1908 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
1909 |
! |
|
1910 |
||
1911 |
identityHashForBinaryStore |
|
1912 |
"hash which is usable if the object does not change its class |
|
1913 |
and does not #become something else, while the hash is used. |
|
1914 |
This is only used by the binary storage mechanism, during the |
|
1915 |
object writing phase." |
|
1916 |
||
1917 |
%{ /* NOCONTEXT */ |
|
1918 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1919 |
REGISTER unsigned INT hash, hash1, hash2, sz; |
5755 | 1920 |
OBJ o; |
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1921 |
static unsigned INT nextHash = 0; |
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1922 |
static unsigned INT nextClassHash = 0; |
5755 | 1923 |
|
1924 |
if (__isNonNilObject(self)) { |
|
6654 | 1925 |
/* |
1926 |
* my own identityHash |
|
1927 |
*/ |
|
1928 |
hash1 = __GET_HASH(self); |
|
1929 |
if (hash1 == 0) { |
|
1930 |
/* has no hash yet */ |
|
1931 |
||
1932 |
if (++nextHash > __MAX_HASH__) { |
|
1933 |
nextHash = 1; |
|
1934 |
} |
|
1935 |
hash1 = nextHash; |
|
1936 |
__SET_HASH(self, hash1); |
|
1937 |
} |
|
1938 |
/* |
|
1939 |
* my classes identityHash |
|
1940 |
*/ |
|
1941 |
o = __qClass(self); |
|
1942 |
hash2 = __GET_HASH(o); |
|
1943 |
if (hash2 == 0) { |
|
1944 |
/* has no hash yet */ |
|
1945 |
||
1946 |
if (++nextClassHash > __MAX_HASH__) { |
|
1947 |
nextClassHash = 1; |
|
1948 |
} |
|
1949 |
hash2 = nextClassHash; |
|
1950 |
__SET_HASH(o, hash2); |
|
1951 |
} |
|
1952 |
||
1953 |
/* |
|
1954 |
* some bits of my size |
|
1955 |
*/ |
|
1956 |
sz = __qSize(self); |
|
1957 |
||
1958 |
/* |
|
1959 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
1960 |
* make it as large as possible; since most hashers use the returned |
|
1961 |
* key and take it modulo some prime number, this will allow for |
|
1962 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
1963 |
*/ |
|
1964 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
1965 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
1966 |
||
1967 |
while ((hash & 0x20000000) == 0) { |
|
1968 |
hash <<= 1; |
|
1969 |
} |
|
1970 |
||
8913 | 1971 |
RETURN ( __mkSmallInteger(hash) ); |
5755 | 1972 |
} |
1973 |
%}. |
|
1974 |
"never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
|
1975 |
^ self identityHash |
|
1976 |
! |
|
1977 |
||
1978 |
sameContentsAs:anObject |
|
1979 |
"return true, if the receiver and the arg have the same contents |
|
7121 | 1980 |
in both the named instance vars and any indexed instVars. |
1981 |
The code here only checks if values present in the receiver are also |
|
1982 |
present in the arg, not vice versa. |
|
1983 |
I.e. the argument may be bigger and/or have more instance variables." |
|
5755 | 1984 |
|
5821 | 1985 |
|myClass |
5755 | 1986 |
sz "{ Class: SmallInteger }" | |
1987 |
||
1988 |
myClass := self class. |
|
1989 |
myClass isVariable ifTrue:[ |
|
6654 | 1990 |
sz := self basicSize. |
7121 | 1991 |
anObject basicSize >= sz ifFalse:[^ false]. |
6654 | 1992 |
|
1993 |
"compare the indexed variables" |
|
1994 |
1 to:sz do:[:i | |
|
1995 |
(self basicAt:i) == (anObject basicAt:i) ifFalse:[^ false]. |
|
1996 |
] |
|
5755 | 1997 |
]. |
1998 |
||
1999 |
"compare the instance variables" |
|
2000 |
sz := myClass instSize. |
|
7121 | 2001 |
anObject instSize >= sz ifFalse:[^ false]. |
2002 |
||
5755 | 2003 |
1 to:sz do:[:i | |
6654 | 2004 |
(self instVarAt:i) == (anObject instVarAt:i) ifFalse:[^ false]. |
5755 | 2005 |
]. |
2006 |
||
2007 |
^ true |
|
2008 |
||
2009 |
" |
|
5814 | 2010 |
#(1 2 3 4) sameContentsAs:#[1 2 3 4] asArray |
2011 |
(1@2) sameContentsAs:(1->2) |
|
5755 | 2012 |
" |
2013 |
||
2014 |
"Created: / 21.4.1998 / 15:56:40 / cg" |
|
2015 |
"Modified: / 21.4.1998 / 15:58:15 / cg" |
|
2016 |
! |
|
2017 |
||
2018 |
~= anObject |
|
2019 |
"return true, if the receiver and the arg do not have the same structure. |
|
2020 |
Notice: |
|
6654 | 2021 |
This method is partially open coded (inlined) by the compiler(s) |
2022 |
identical objects are never considered unequal. |
|
2023 |
redefining it may not work as expected." |
|
5755 | 2024 |
|
2025 |
^ (self = anObject) not |
|
2026 |
! |
|
2027 |
||
2028 |
~~ anObject |
|
2029 |
"return true, if the receiver and the arg are not the same object. |
|
2030 |
Never redefine this in any class. |
|
2031 |
Notice: |
|
6654 | 2032 |
This method is open coded (inlined) by the compiler(s) |
2033 |
- redefining it may not work as expected." |
|
5755 | 2034 |
|
2035 |
%{ /* NOCONTEXT */ |
|
2036 |
RETURN ( (self == anObject) ? false : true ); |
|
2037 |
%} |
|
2038 |
! ! |
|
2039 |
||
2040 |
!Object methodsFor:'converting'! |
|
2041 |
||
2042 |
-> anObject |
|
2043 |
"return an association with the receiver as key and |
|
2044 |
the argument as value" |
|
2045 |
||
2046 |
^ Association key:self value:anObject |
|
2047 |
! |
|
2048 |
||
2049 |
asCollection |
|
2050 |
"return myself as a Collection. |
|
2051 |
Redefined in collection to return themself." |
|
2052 |
||
2053 |
^ Array with:self |
|
2054 |
! |
|
2055 |
||
2056 |
asSequenceableCollection |
|
2057 |
"return myself as a SequenceableCollection. |
|
2058 |
Redefined in SequenceableCollection" |
|
2059 |
||
2060 |
^ Array with:self |
|
2061 |
! |
|
2062 |
||
2063 |
asValue |
|
2064 |
"return a valueHolder for for the receiver" |
|
2065 |
||
2066 |
^ ValueHolder with:self |
|
6146 | 2067 |
! |
2068 |
||
2069 |
collect |
|
2070 |
"return mySelf" |
|
2071 |
||
2072 |
^ self |
|
2073 |
! |
|
2074 |
||
2075 |
deepCollect |
|
2076 |
"return mySelf" |
|
2077 |
||
2078 |
^ self |
|
2079 |
! |
|
2080 |
||
2081 |
deepSelect |
|
2082 |
"return mySelf" |
|
2083 |
||
2084 |
^ self |
|
2085 |
! |
|
2086 |
||
2087 |
select |
|
2088 |
"return mySelf" |
|
2089 |
||
2090 |
^ self |
|
5755 | 2091 |
! ! |
2092 |
||
2093 |
!Object methodsFor:'copying'! |
|
2094 |
||
2095 |
cloneFrom:anObject |
|
2096 |
"Helper for copy: |
|
2097 |
copy all instance variables from anObject into the receiver, |
|
2098 |
which should be of the same class as the argument." |
|
2099 |
||
2100 |
self cloneFrom:anObject performing:#yourself |
|
2101 |
||
2102 |
" |
|
2103 |
|x| |
|
2104 |
||
2105 |
x := Array new:3. |
|
2106 |
x cloneFrom:#(1 2 3). |
|
2107 |
" |
|
2108 |
! |
|
2109 |
||
2110 |
cloneFrom:anObject performing:aSymbol |
|
2111 |
"Helper for copy: |
|
8383 | 2112 |
for each instance variable from anObject, send it aSymbol |
5755 | 2113 |
and store the result into the receiver, |
2114 |
which should be of the same class as the argument." |
|
2115 |
||
2116 |
|myClass sz "{ Class: SmallInteger }" t | |
|
2117 |
||
2118 |
myClass := self class. |
|
2119 |
myClass isVariable ifTrue:[ |
|
6654 | 2120 |
sz := self basicSize. |
2121 |
||
8383 | 2122 |
"process the indexed instance variables" |
6654 | 2123 |
1 to:sz do:[:i | |
2124 |
t := anObject basicAt:i. |
|
2125 |
aSymbol ~~ #yourself ifTrue:[ |
|
2126 |
t := t perform:aSymbol. |
|
2127 |
]. |
|
2128 |
self basicAt:i put:t. |
|
2129 |
] |
|
5755 | 2130 |
]. |
2131 |
||
8383 | 2132 |
"process the named instance variables" |
5755 | 2133 |
sz := myClass instSize. |
2134 |
1 to:sz do:[:i | |
|
6654 | 2135 |
t := anObject instVarAt:i. |
2136 |
aSymbol ~~ #yourself ifTrue:[ |
|
2137 |
t := t perform:aSymbol |
|
2138 |
]. |
|
2139 |
self instVarAt:i put:t |
|
5755 | 2140 |
]. |
2141 |
||
2142 |
^ self |
|
2143 |
! |
|
2144 |
||
2145 |
cloneInstanceVariablesFrom:aPrototype |
|
2146 |
"Shallow copy variables from a prototype into myself. |
|
2147 |
This copies instVars by name - i.e. same-named variables are |
|
2148 |
copied, others are not. |
|
2149 |
The variable slots are copied as available |
|
2150 |
(i.e. the min of both indexed sizes is used)." |
|
2151 |
||
2152 |
|myInfo otherInfo| |
|
2153 |
||
2154 |
myInfo := self class instanceVariableOffsets. |
|
2155 |
otherInfo := aPrototype class instanceVariableOffsets. |
|
2156 |
myInfo keysAndValuesDo:[:name :index | |varIndexAssoc| |
|
6654 | 2157 |
varIndexAssoc := otherInfo at:name ifAbsent:[]. |
2158 |
varIndexAssoc notNil ifTrue:[ |
|
2159 |
self instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
2160 |
] |
|
5755 | 2161 |
]. |
2162 |
self isVariable ifTrue:[ |
|
6654 | 2163 |
1 to:(self basicSize min:aPrototype basicSize) do:[:index | |
2164 |
self basicAt:index put:(aPrototype basicAt:index) |
|
2165 |
]. |
|
5755 | 2166 |
]. |
2167 |
||
2168 |
" |
|
2169 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2170 |
Point subclass:#Point3D |
2171 |
instanceVariableNames:'z' |
|
2172 |
classVariableNames:'' |
|
2173 |
poolDictionaries:'' |
|
2174 |
category:'testing'. |
|
2175 |
(Point3D new cloneInstanceVariablesFrom:1@2) inspect. |
|
5755 | 2176 |
] |
2177 |
" |
|
2178 |
||
2179 |
" |
|
2180 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2181 |
Point variableSubclass:#Point3D |
2182 |
instanceVariableNames:'z' |
|
2183 |
classVariableNames:'' |
|
2184 |
poolDictionaries:'' |
|
2185 |
category:'testing'. |
|
2186 |
((Point3D new:2) cloneInstanceVariablesFrom:#(1 2 3)) inspect. |
|
5755 | 2187 |
] |
2188 |
" |
|
2189 |
||
2190 |
" |
|
2191 |
|someObject| |
|
2192 |
||
2193 |
Class withoutUpdatingChangesDo:[ |
|
6654 | 2194 |
Object subclass:#TestClass1 |
2195 |
instanceVariableNames:'foo bar' |
|
2196 |
classVariableNames:'' |
|
2197 |
poolDictionaries:'' |
|
2198 |
category:'testing'. |
|
2199 |
someObject := TestClass1 new. |
|
2200 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
2201 |
Object subclass:#TestClass2 |
|
2202 |
instanceVariableNames:'bar foo' |
|
2203 |
classVariableNames:'' |
|
2204 |
poolDictionaries:'' |
|
2205 |
category:'testing'. |
|
2206 |
(TestClass2 new cloneInstanceVariablesFrom:someObject) inspect. |
|
5755 | 2207 |
] |
2208 |
" |
|
2209 |
||
2210 |
" |
|
2211 |
|top b b1| |
|
2212 |
||
2213 |
top := StandardSystemView new. |
|
2214 |
top extent:100@100. |
|
2215 |
||
2216 |
b := Button in:top. |
|
2217 |
b label:'hello'. |
|
2218 |
||
2219 |
b1 := ArrowButton new cloneInstanceVariablesFrom:b. |
|
2220 |
||
2221 |
top open. |
|
2222 |
b1 inspect |
|
2223 |
" |
|
2224 |
! |
|
2225 |
||
2226 |
copy |
|
2227 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
2228 |
Notice, that copy does not copy dependents." |
|
2229 |
||
2230 |
^ self shallowCopy postCopy |
|
2231 |
! |
|
2232 |
||
6146 | 2233 |
copyToLevel:level |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2234 |
"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
|
2235 |
Notice: |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2236 |
This method DOES NOT handle cycles/self-refs and does NOT preserve object identity; |
8383 | 2237 |
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
|
2238 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2239 |
|newObject class index| |
6146 | 2240 |
|
2241 |
level == 1 ifTrue:[^ self shallowCopy]. |
|
2242 |
||
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2243 |
class := self class. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2244 |
newObject := self clone. |
6146 | 2245 |
newObject == self ifTrue: [^ self]. |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2246 |
class isVariable ifTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2247 |
index := self basicSize. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2248 |
[index > 0] whileTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2249 |
newObject basicAt: index put: ((self basicAt: index) copyToLevel:(level-1)). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2250 |
index := index - 1 |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2251 |
] |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2252 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2253 |
index := class instSize. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2254 |
[index > 0] whileTrue:[ |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2255 |
newObject instVarAt: index put: ((self instVarAt: index) copyToLevel:(level-1)). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2256 |
index := index - 1 |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2257 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2258 |
^ newObject |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2259 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2260 |
" |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2261 |
|a b| |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2262 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2263 |
a := #( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2264 |
'1.1' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2265 |
'1.2' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2266 |
'1.3' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2267 |
( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2268 |
'1.41' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2269 |
'1.42' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2270 |
'1.43' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2271 |
( |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2272 |
'1.441' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2273 |
'1.442' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2274 |
'1.443' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2275 |
( '1.4441' '1.4442' '1.4443' ) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2276 |
'1.445' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2277 |
) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2278 |
'1.45' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2279 |
) |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2280 |
'1.5' |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2281 |
). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2282 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2283 |
b := a copyToLevel:1. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2284 |
self assert: ( (a at:1) == (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2285 |
self assert: ( (a at:4) == (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2286 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2287 |
b := a copyToLevel:2. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2288 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2289 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2290 |
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
|
2291 |
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
|
2292 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2293 |
b := a copyToLevel:3. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2294 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2295 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2296 |
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
|
2297 |
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
|
2298 |
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
|
2299 |
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
|
2300 |
" |
6146 | 2301 |
! |
2302 |
||
5755 | 2303 |
deepCopy |
2304 |
"return a copy of the object with all subobjects also copied. |
|
2305 |
This method DOES handle cycles/self-refs and preserves object identity; |
|
2306 |
however the receivers class is not copied (to avoid the 'total' copy). |
|
2307 |
||
2308 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
2309 |
keeps track of already copied objects. If you are sure, that your |
|
2310 |
copied object does not include duplicates (or you do not care) and |
|
2311 |
no cycles are involved, you can use the old simpleDeepCopy, |
|
2312 |
which avoids this overhead (but may run into trouble). |
|
2313 |
Notice, that deepCopy does not copy dependents." |
|
2314 |
||
8383 | 2315 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 2316 |
|
2317 |
"an example which is not handled by the old deepCopy: |
|
2318 |
||
2319 |
|a| |
|
2320 |
a := Array new:3. |
|
2321 |
a at:3 put:a. |
|
2322 |
a deepCopy inspect |
|
2323 |
" |
|
2324 |
||
2325 |
" |
|
2326 |
|a| |
|
2327 |
a := Color black onDevice:Screen current. |
|
2328 |
a deepCopy inspect |
|
2329 |
" |
|
2330 |
||
2331 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
2332 |
! |
|
2333 |
||
2334 |
deepCopyError |
|
2335 |
"{ Pragma: +optSpace }" |
|
2336 |
||
2337 |
"raise a signal, that deepCopy is not allowed for this object" |
|
2338 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
2339 |
^ DeepCopyError raise |
5755 | 2340 |
! |
2341 |
||
2342 |
deepCopyUsing:aDictionary |
|
2343 |
"a helper for deepCopy; return a copy of the object with |
|
2344 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
2345 |
use the value found there. The class of the receiver is not copied. |
|
2346 |
This method DOES handle cycles/self references." |
|
2347 |
||
2348 |
|myClass aCopy |
|
2349 |
sz "{ Class: SmallInteger }" |
|
2350 |
iOrig iCopy| |
|
2351 |
||
2352 |
myClass := self class. |
|
2353 |
myClass isVariable ifTrue:[ |
|
6654 | 2354 |
sz := self basicSize. |
2355 |
aCopy := myClass basicNew:sz. |
|
5755 | 2356 |
] ifFalse:[ |
6654 | 2357 |
sz := 0. |
2358 |
aCopy := myClass basicNew |
|
5755 | 2359 |
]. |
2360 |
aCopy setHashFrom:self. |
|
2361 |
aDictionary at:self put:aCopy. |
|
2362 |
||
2363 |
" |
|
2364 |
copy indexed instvars - if any |
|
2365 |
" |
|
2366 |
sz ~~ 0 ifTrue:[ |
|
6654 | 2367 |
myClass isBits ifTrue:[ |
2368 |
"block-copy indexed instvars" |
|
2369 |
aCopy replaceFrom:1 to:sz with:self startingAt:1 |
|
2370 |
] ifFalse:[ |
|
2371 |
"individual deep copy the indexed variables" |
|
2372 |
1 to:sz do:[:i | |
|
2373 |
iOrig := self basicAt:i. |
|
2374 |
iOrig notNil ifTrue:[ |
|
8372 | 2375 |
"/ used to be dict-includesKey-ifTrue[dict-at:], |
2376 |
"/ changed to use dict-at:ifAbsent:, to avoid double lookup in dictionary |
|
2377 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2378 |
iCopy isNil ifTrue:[ |
|
8383 | 2379 |
iCopy := iOrig deepCopyUsing:aDictionary |
6654 | 2380 |
]. |
2381 |
aCopy basicAt:i put:iCopy |
|
2382 |
] |
|
2383 |
] |
|
2384 |
] |
|
5755 | 2385 |
]. |
2386 |
||
2387 |
" |
|
2388 |
copy the instance variables |
|
2389 |
" |
|
2390 |
sz := myClass instSize. |
|
2391 |
1 to:sz do:[:i | |
|
6654 | 2392 |
(self skipInstvarIndexInDeepCopy:i) ifFalse:[ |
2393 |
iOrig := self instVarAt:i. |
|
2394 |
iOrig notNil ifTrue:[ |
|
8372 | 2395 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
2396 |
iCopy isNil ifTrue:[ |
|
8383 | 2397 |
iCopy := iOrig deepCopyUsing:aDictionary |
6654 | 2398 |
]. |
2399 |
aCopy instVarAt:i put:iCopy |
|
2400 |
] |
|
2401 |
] |
|
5755 | 2402 |
]. |
8383 | 2403 |
aCopy postDeepCopyFrom:self. |
5755 | 2404 |
^ aCopy |
2405 |
||
2406 |
" |
|
2407 |
|a b c copyOfC| |
|
2408 |
||
2409 |
a := Array with:'hello' with:'world' with:nil. |
|
2410 |
b := 99 @ 999. |
|
2411 |
a at:3 put:b. |
|
2412 |
c := Array with:a with:b with:a. |
|
2413 |
||
2414 |
Transcript showCR: (c at:1) == (c at:3). |
|
2415 |
copyOfC := c deepCopy. |
|
2416 |
Transcript showCR: (copyOfC at:1) == (copyOfC at:3) |
|
2417 |
" |
|
2418 |
! |
|
2419 |
||
2420 |
postCopy |
|
2421 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
2422 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
2423 |
(see there)" |
|
2424 |
||
2425 |
^ self |
|
2426 |
! |
|
2427 |
||
2428 |
postDeepCopy |
|
8930
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2429 |
"allows for cleanup after deep copying. |
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2430 |
To be redefined in subclasses." |
5755 | 2431 |
! |
2432 |
||
2433 |
postDeepCopyFrom:aSource |
|
2434 |
"allows for cleanup after deep copying" |
|
2435 |
||
2436 |
^ self postDeepCopy |
|
2437 |
! |
|
2438 |
||
2439 |
setHashFrom:anObject |
|
2440 |
"set my identity-hash key to be the same as anObjects hash key. |
|
2441 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
2442 |
Smalltalks, and may not be available in future ST/X versions. |
|
2443 |
DO NEVER use this for normal application code." |
|
2444 |
||
2445 |
%{ /* NOCONTEXT */ |
|
2446 |
||
2447 |
REGISTER unsigned h; |
|
2448 |
||
2449 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
6654 | 2450 |
h = __GET_HASH(anObject); |
2451 |
__SET_HASH(self, h); |
|
2452 |
RETURN (self); |
|
5755 | 2453 |
} |
2454 |
%}. |
|
2455 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
2456 |
! |
|
2457 |
||
2458 |
shallowCopy |
|
2459 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2460 |
i.e. the copy shares referenced instvars with its original." |
|
2461 |
||
2462 |
%{ /* NOCONTEXT */ |
|
2463 |
int ninsts, spc; |
|
2464 |
int sz; |
|
2465 |
OBJ theCopy; |
|
2466 |
OBJ cls; |
|
2467 |
int flags; |
|
2468 |
||
2469 |
cls = __qClass(self); |
|
2470 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
2471 |
||
2472 |
/* |
|
2473 |
* bail out for special objects .. |
|
2474 |
*/ |
|
2475 |
if (((flags & ~ARRAYMASK) == 0) |
|
2476 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
6654 | 2477 |
sz = __qSize(self); |
2478 |
__PROTECT__(self); |
|
2479 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
2480 |
__UNPROTECT__(self); |
|
2481 |
if (theCopy) { |
|
2482 |
cls = __qClass(self); |
|
2483 |
spc = __qSpace(theCopy); |
|
2484 |
||
2485 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
2486 |
||
2487 |
sz = sz - OHDR_SIZE; |
|
2488 |
if (sz) { |
|
2489 |
char *src, *dst; |
|
2490 |
||
2491 |
src = (char *)(__InstPtr(self)->i_instvars); |
|
2492 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
5755 | 2493 |
#ifdef bcopy4 |
6654 | 2494 |
{ |
2495 |
/* care for odd-number of longs */ |
|
2496 |
int nW = sz >> 2; |
|
2497 |
||
2498 |
if (sz & 3) { |
|
2499 |
nW++; |
|
2500 |
} |
|
2501 |
||
2502 |
bcopy4(src, dst, nW); |
|
2503 |
} |
|
5755 | 2504 |
#else |
6654 | 2505 |
bcopy(src, dst, sz); |
5755 | 2506 |
#endif |
2507 |
||
6654 | 2508 |
flags &= ARRAYMASK; |
2509 |
if (flags == POINTERARRAY) { |
|
2510 |
ninsts = __BYTES2OBJS__(sz); |
|
2511 |
} else { |
|
2512 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
2513 |
} |
|
2514 |
if (ninsts) { |
|
2515 |
do { |
|
2516 |
OBJ el; |
|
2517 |
||
2518 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
2519 |
__STORE_SPC(theCopy, el, spc); |
|
2520 |
} while (--ninsts); |
|
2521 |
} |
|
2522 |
} |
|
2523 |
RETURN (theCopy); |
|
2524 |
} |
|
5755 | 2525 |
} |
2526 |
%}. |
|
2527 |
"/ fallBack for special objects & memoryAllocation failure case |
|
2528 |
||
2529 |
^ self slowShallowCopy |
|
2530 |
! |
|
2531 |
||
2532 |
simpleDeepCopy |
|
2533 |
"return a copy of the object with all subobjects also copied. |
|
2534 |
This method does NOT handle cycles - but is included to allow this |
|
2535 |
slightly faster copy in situations where it is known that |
|
2536 |
no recursive references occur (LargeIntegers for example). |
|
2537 |
NOTICE: you will run into trouble, when trying this with recursive |
|
2538 |
objects (usually recursionInterrupt or memory-alert). |
|
8383 | 2539 |
This method corresponds to the 'traditional' deepCopy found in the Blue book." |
5755 | 2540 |
|
2541 |
|myClass aCopy| |
|
2542 |
||
2543 |
(myClass := self class) isVariable ifTrue:[ |
|
6654 | 2544 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2545 |
] ifFalse:[ |
6654 | 2546 |
aCopy := myClass basicNew |
5755 | 2547 |
]. |
2548 |
||
2549 |
"copy the instance variables" |
|
2550 |
aCopy cloneFrom:self performing:#simpleDeepCopy. |
|
2551 |
^ aCopy |
|
2552 |
||
2553 |
"a bad example (but ST/X should survive ...)" |
|
2554 |
" |
|
2555 |
|a| |
|
2556 |
a := Array new:3. |
|
2557 |
a at:3 put:a. |
|
2558 |
a simpleDeepCopy |
|
2559 |
" |
|
2560 |
! |
|
2561 |
||
2562 |
skipInstvarIndexInDeepCopy:index |
|
2563 |
"a helper for deepCopy; only indices for which this method returns |
|
2564 |
false are copied in a deep copy. |
|
2565 |
The default is false here - which means that everything is copied. |
|
2566 |
Can be redefined in subclasses for partial copies" |
|
2567 |
||
2568 |
^ false |
|
2569 |
! |
|
2570 |
||
2571 |
slowShallowCopy |
|
2572 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2573 |
i.e. the copy shares referenced instvars with its original. |
|
2574 |
This method is only invoked as a fallback from #shallowCopy." |
|
2575 |
||
2576 |
|myClass aCopy| |
|
2577 |
||
2578 |
(myClass := self class) isVariable ifTrue:[ |
|
6654 | 2579 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2580 |
] ifFalse:[ |
6654 | 2581 |
aCopy := myClass basicNew |
5755 | 2582 |
]. |
2583 |
||
2584 |
"copy the instance variables" |
|
2585 |
aCopy cloneFrom:self performing:#yourself. |
|
2586 |
^ aCopy |
|
2587 |
! ! |
|
2588 |
||
2589 |
!Object methodsFor:'debugging'! |
|
2590 |
||
7621 | 2591 |
assert:aBooleanOrBlock |
6964 | 2592 |
"fail, if the argument is not true and report an error" |
2593 |
||
8876 | 2594 |
aBooleanOrBlock == true ifTrue:[^ self]. |
2595 |
"/ could still be a block or false. |
|
2596 |
self |
|
2597 |
assert:aBooleanOrBlock |
|
2598 |
message:('Assertion failed in ' , thisContext sender printString) |
|
7621 | 2599 |
! |
2600 |
||
2601 |
assert:aBooleanOrBlock message:messageIfFailing |
|
6964 | 2602 |
"fail, if the argument is not true and report an error" |
6961 | 2603 |
|
2604 |
"{ Pragma: +optSpace }" |
|
2605 |
||
7621 | 2606 |
(aBooleanOrBlock value) ifFalse:[ |
8273 | 2607 |
self error:messageIfFailing mayProceed:true |
6961 | 2608 |
]. |
2609 |
! |
|
2610 |
||
5755 | 2611 |
basicInspect |
2612 |
"{ Pragma: +optSpace }" |
|
2613 |
||
2614 |
"launch an inspector on the receiver. |
|
2615 |
this method should NOT be redefined in subclasses." |
|
2616 |
||
2617 |
Inspector isNil ifTrue:[ |
|
6654 | 2618 |
" |
2619 |
for systems without GUI |
|
2620 |
" |
|
6926 | 2621 |
self warn:'No Inspector defined (Inspector is nil).' |
5755 | 2622 |
] ifFalse:[ |
6654 | 2623 |
Inspector openOn:self |
5755 | 2624 |
] |
2625 |
||
2626 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
2627 |
! |
|
2628 |
||
6954 | 2629 |
breakPoint:something |
2630 |
"{ Pragma: +optSpace }" |
|
2631 |
||
2632 |
"Like halt, but disabled by default. |
|
2633 |
Can be easily enabled. |
|
2634 |
Can be filtered on the arguments value (typically: a symbol). |
|
2635 |
Code with breakpoints may be even checked into the source repository" |
|
2636 |
||
2637 |
"Example: nil breakPoint:#stefan" |
|
2638 |
||
2639 |
"/ something = OperatingSystem getLoginName ifTrue:[ |
|
2640 |
"/ ^ HaltSignal raiseRequestWith:something errorString:'Breakpoint encountered: ', something printString |
|
2641 |
"/ ]. |
|
2642 |
||
2643 |
"/ something = 'testThis' ifTrue:[ |
|
2644 |
"/ ^ HaltSignal raiseRequestWith:something errorString:'Breakpoint encountered: ', something printString |
|
2645 |
"/ ]. |
|
2646 |
! |
|
2647 |
||
5995 | 2648 |
browse |
2649 |
"open a browser on the receivers class" |
|
2650 |
||
2651 |
self class theNonMetaclass browse |
|
2652 |
||
2653 |
" |
|
2654 |
10 browse |
|
2655 |
Collection browse |
|
2656 |
Collection class browse |
|
2657 |
" |
|
2658 |
! |
|
2659 |
||
5755 | 2660 |
inspect |
2661 |
"{ Pragma: +optSpace }" |
|
2662 |
||
2663 |
"launch an inspector on the receiver. |
|
2664 |
this method (or better: inspectorClass) can be redefined in subclasses |
|
2665 |
to start special inspectors." |
|
2666 |
||
2667 |
|cls| |
|
2668 |
||
2669 |
cls := self inspectorClass. |
|
2670 |
cls isNil ifTrue:[ |
|
6654 | 2671 |
^ self basicInspect |
5755 | 2672 |
]. |
2673 |
cls openOn:self |
|
2674 |
||
2675 |
" |
|
2676 |
Object new inspect |
|
2677 |
(1 @ 2) inspect |
|
2678 |
Smalltalk inspect |
|
2679 |
#(1 2 3) asOrderedCollection inspect |
|
2680 |
(Color red) inspect |
|
2681 |
(Image fromFile:'bitmaps/garfield.gif') inspect |
|
2682 |
" |
|
2683 |
! |
|
2684 |
||
2685 |
inspectorClass |
|
2686 |
"{ Pragma: +optSpace }" |
|
2687 |
||
2688 |
"return the class to use for inspect. |
|
2689 |
Can (should) be redefined in classes for which a better inspector is available" |
|
2690 |
||
2691 |
^ Inspector |
|
2692 |
! |
|
2693 |
||
2694 |
mustBeBoolean |
|
2695 |
"this message is sent by the VM, if a non-Boolean receiver is encountered |
|
2696 |
in an if* or while* message. |
|
2697 |
Caveat: for now, this is only sent by the interpreter; |
|
2698 |
both the JIT and the stc compiler treat it as undefined." |
|
2699 |
||
2700 |
self error:'Non boolean receiver - proceed for truth' mayProceed:true. |
|
2701 |
^ true |
|
2702 |
! |
|
2703 |
||
2704 |
mustBeKindOf:aClass |
|
2705 |
"for compatibility & debugging support: |
|
2706 |
check if the receiver isKindOf:aClass and raise an error if not. |
|
2707 |
Notice: |
|
6654 | 2708 |
it is VERY questionable, if it makes sense to add manual |
2709 |
type checks to a dynamically typed language like smalltalk. |
|
2710 |
It will, at least, slow down performance, |
|
2711 |
make your code less reusable and clutter your code with stupid sends |
|
2712 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
2713 |
use of isXXX check methods. |
|
5755 | 2714 |
You see: The author does not like this at all ..." |
2715 |
||
2716 |
(self isKindOf:aClass) ifFalse:[ |
|
6654 | 2717 |
self error:'argument is not of expected type' |
5755 | 2718 |
] |
2719 |
! |
|
2720 |
||
6950 | 2721 |
obsoleteFeatureWarning |
2722 |
"{ Pragma: +optSpace }" |
|
2723 |
||
2724 |
"in methods which are going to be changed, a send to |
|
2725 |
this method is used to tell programmers that some feature/semantics is |
|
2726 |
used which is going to be changed in later ST/X versions. |
|
6963 | 2727 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)." |
6950 | 2728 |
|
2729 |
self obsoleteFeatureWarning:nil from:thisContext sender |
|
2730 |
! |
|
2731 |
||
2732 |
obsoleteFeatureWarning:message |
|
2733 |
"{ Pragma: +optSpace }" |
|
2734 |
||
2735 |
"in methods which are going to be changed, a send to |
|
2736 |
this method is used to tell programmers that some feature/semantics is |
|
2737 |
used which is going to be changed in later ST/X versions. |
|
6963 | 2738 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
2739 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 2740 |
|
2741 |
self obsoleteFeatureWarning:message from:thisContext sender |
|
2742 |
! |
|
2743 |
||
2744 |
obsoleteFeatureWarning:message from:aContext |
|
2745 |
"{ Pragma: +optSpace }" |
|
2746 |
||
2747 |
"in methods which are going to be changed, a send to |
|
2748 |
this method is used to tell programmers that some feature/semantics is |
|
2749 |
used which is going to be changed in later ST/X versions. |
|
6963 | 2750 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
2751 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 2752 |
|
2753 |
|spec| |
|
2754 |
||
2755 |
spec := aContext methodPrintString. |
|
2756 |
('WARNING: the ''' , spec , ''' semantics will be changed.') infoPrintCR. |
|
2757 |
(' Its behavior may be different in future ST/X versions.') infoPrintCR. |
|
2758 |
(' called from ' , aContext sender printString) infoPrintCR. |
|
7204 | 2759 |
(aContext sender selector startsWith:'perform:') ifTrue:[ |
2760 |
(' called from ' , aContext sender sender printString) infoPrintCR. |
|
2761 |
]. |
|
6950 | 2762 |
message notNil ifTrue:[ |
2763 |
'------> ' infoPrint. message infoPrintCR |
|
2764 |
] |
|
2765 |
||
2766 |
" |
|
2767 |
Object obsoleteFeatureWarning:'foo' from:thisContext sender sender |
|
2768 |
" |
|
2769 |
! |
|
2770 |
||
5755 | 2771 |
obsoleteMethodWarning |
2772 |
"{ Pragma: +optSpace }" |
|
2773 |
||
2774 |
"in methods which are going to be obsoleted, a self send to |
|
2775 |
this method is used to tell programmers that a method is |
|
2776 |
used which is going to be removed in later ST/X versions. |
|
6963 | 2777 |
Find all methods which will be obsolete soon by looking at senders of this message. |
2778 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 2779 |
|
2780 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
2781 |
! |
|
2782 |
||
2783 |
obsoleteMethodWarning:message |
|
2784 |
"{ Pragma: +optSpace }" |
|
2785 |
||
2786 |
"in methods which are going to be obsoleted, a self send to |
|
2787 |
this method is used to tell programmers that a method is |
|
2788 |
used which is going to be removed in later ST/X versions. |
|
6963 | 2789 |
Find all methods which will be obsolete soon by looking at senders of this message. |
2790 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 2791 |
|
2792 |
self obsoleteMethodWarning:message from:thisContext sender |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2793 |
! |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2794 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2795 |
obsoleteMethodWarning:message from:aContext |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2796 |
"{ Pragma: +optSpace }" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2797 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2798 |
"in methods which are going to be obsoleted, a self-send to |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2799 |
this method is used to tell programmers that a method is |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2800 |
used which is going to be removed in later ST/X versions. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2801 |
Find all methods which will be obsolete soon by looking at senders of this message. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2802 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2803 |
This message is intended for application developers, so its printed as info message." |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2804 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2805 |
|spec sender| |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2806 |
|
9509 | 2807 |
Smalltalk isSmalltalkDevelopmentSystem ifFalse:[ |
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2808 |
"ignore in production systems" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2809 |
^ self. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2810 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2811 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2812 |
spec := aContext methodPrintString. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2813 |
sender := aContext sender. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2814 |
('WARNING: the ''' , spec , ''' method is obsolete.') infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2815 |
(' And may not be present in future ST/X versions.') infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2816 |
(' called from ' , sender printString) infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2817 |
(sender selector startsWith:'perform:') ifTrue:[ |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2818 |
sender := sender sender. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2819 |
(sender selector startsWith:'perform:') ifTrue:[ |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2820 |
sender := sender sender. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2821 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2822 |
(' called from ' , sender printString) infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2823 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2824 |
message notNil ifTrue:[ |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2825 |
'------> ' infoPrint. message infoPrintCR |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2826 |
] |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2827 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2828 |
" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2829 |
Object obsoleteMethodWarning:'foo' from:thisContext sender sender |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
2830 |
" |
9509 | 2831 |
|
2832 |
"Modified: / 10-08-2006 / 13:13:11 / cg" |
|
5755 | 2833 |
! ! |
2834 |
||
2835 |
!Object methodsFor:'dependents access'! |
|
2836 |
||
2837 |
addDependent:anObject |
|
2838 |
"make the argument, anObject be a dependent of the receiver" |
|
2839 |
||
2840 |
|wasBlocked| |
|
2841 |
||
2842 |
"/ must do this save from interrupts, since the dependents collection |
|
2843 |
"/ is possibly accessed from multiple threads. |
|
2844 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
2845 |
"/ faster execution. |
|
2846 |
||
2847 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2848 |
[ |
|
6654 | 2849 |
|deps dep| |
2850 |
||
2851 |
deps := self dependents. |
|
2852 |
||
2853 |
"/ to save a fair amount of memory in case of |
|
2854 |
"/ many dependencies, we store a single dependent in |
|
2855 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
2856 |
"/ added. |
|
2857 |
||
2858 |
(deps isNil or:[deps size == 0]) ifTrue:[ |
|
2859 |
self dependents:(WeakArray with:anObject) |
|
2860 |
] ifFalse:[ |
|
2861 |
deps class == WeakArray ifTrue:[ |
|
2862 |
dep := deps at:1. |
|
2863 |
dep ~~ anObject ifTrue:[ |
|
2864 |
(dep isNil or:[dep == 0]) ifTrue:[ |
|
2865 |
deps at:1 put:anObject |
|
2866 |
] ifFalse:[ |
|
2867 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
2868 |
] |
|
2869 |
] |
|
2870 |
] ifFalse:[ |
|
2871 |
deps add:anObject |
|
2872 |
] |
|
2873 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
2874 |
] ensure:[ |
6654 | 2875 |
wasBlocked ifFalse:[ |
2876 |
OperatingSystem unblockInterrupts |
|
2877 |
] |
|
5755 | 2878 |
] |
2879 |
||
2880 |
"Modified: / 27.10.1997 / 19:35:52 / cg" |
|
2881 |
! |
|
2882 |
||
2883 |
breakDependents |
|
2884 |
"remove all dependencies from the receiver" |
|
2885 |
||
2886 |
self dependents:nil. |
|
2887 |
self nonWeakDependents:nil |
|
2888 |
||
2889 |
"Modified: / 19.4.1996 / 10:55:36 / cg" |
|
2890 |
"Created: / 27.2.1998 / 11:26:11 / stefan" |
|
2891 |
! |
|
2892 |
||
8542 | 2893 |
breakDependentsRecursively |
2894 |
"remove all dependencies from the receiver and |
|
2895 |
recursively from all objects referred to by the receiver." |
|
2896 |
||
2897 |
self breakDependents. |
|
2898 |
1 to:self class instSize do:[:idx | |
|
2899 |
(self instVarAt:idx) breakDependentsRecursively. |
|
2900 |
]. |
|
2901 |
1 to:self basicSize do:[:idx | |
|
2902 |
(self basicAt:idx) breakDependentsRecursively. |
|
2903 |
] |
|
2904 |
! |
|
2905 |
||
5755 | 2906 |
dependents |
2907 |
"return a Collection of dependents. |
|
2908 |
The default implementation here uses a global WeakDictionary to store |
|
2909 |
dependents |
|
2910 |
This may be too slow for high frequency change&update, |
|
2911 |
therefore, some classes (Model) redefine this for better performance. |
|
2912 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
2913 |
||
2914 |
|deps| |
|
2915 |
||
2916 |
(deps := Dependencies at:self ifAbsent:nil) isNil ifTrue:[ |
|
6654 | 2917 |
^ #(). |
5755 | 2918 |
]. |
2919 |
^ deps |
|
2920 |
||
2921 |
"Modified: / 26.1.1998 / 11:18:15 / cg" |
|
2922 |
! |
|
2923 |
||
2924 |
dependents:aCollection |
|
2925 |
"set the collection of dependents. |
|
2926 |
The default implementation here uses a global Dictionary to store |
|
2927 |
dependents which may be too slow for high frequency change&update. |
|
2928 |
Therefore, some classes (Model) redefine this for better performance." |
|
2929 |
||
2930 |
"/ must do this save from interrupts, since the dependents collection |
|
2931 |
"/ is possibly accessed from multiple threads. |
|
2932 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
2933 |
"/ faster execution (and to avoid creation of garbage blocks). |
|
2934 |
||
2935 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
6654 | 2936 |
"/ the common case - already blocked |
2937 |
||
2938 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
2939 |
Dependencies removeKey:self ifAbsent:nil |
|
2940 |
] ifFalse:[ |
|
2941 |
Dependencies at:self put:aCollection |
|
2942 |
]. |
|
2943 |
^ self |
|
5755 | 2944 |
]. |
2945 |
||
2946 |
[ |
|
6654 | 2947 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
2948 |
Dependencies removeKey:self ifAbsent:nil |
|
2949 |
] ifFalse:[ |
|
2950 |
Dependencies at:self put:aCollection |
|
2951 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
2952 |
] ensure:[ |
6654 | 2953 |
OperatingSystem unblockInterrupts |
5755 | 2954 |
] |
2955 |
||
2956 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
|
2957 |
! |
|
2958 |
||
2959 |
dependentsDo:aBlock |
|
2960 |
"evaluate aBlock for all of my dependents" |
|
2961 |
||
2962 |
|deps nwDeps| |
|
2963 |
||
2964 |
deps := self dependents. |
|
2965 |
deps size ~~ 0 ifTrue:[ |
|
6654 | 2966 |
deps do:[:d | |
2967 |
(d notNil and:[d ~~ 0]) ifTrue:[ |
|
2968 |
aBlock value:d |
|
2969 |
] |
|
2970 |
] |
|
5755 | 2971 |
]. |
2972 |
nwDeps := self nonWeakDependents. |
|
2973 |
(nwDeps ~~ deps and:[nwDeps size ~~ 0]) ifTrue:[ |
|
6654 | 2974 |
nwDeps do:aBlock |
5755 | 2975 |
]. |
2976 |
||
2977 |
"Modified: / 30.1.1998 / 14:03:40 / cg" |
|
2978 |
! |
|
2979 |
||
2980 |
myDependents |
|
2981 |
"same as dependents - ST-80 compatibility" |
|
2982 |
||
2983 |
^ self dependents |
|
2984 |
! |
|
2985 |
||
2986 |
release |
|
2987 |
"remove all references to objects that may refer to self. |
|
2988 |
Subclasses may redefine this method but should do a 'super release'." |
|
2989 |
||
2990 |
self breakDependents |
|
2991 |
||
2992 |
"Modified: / 27.2.1998 / 11:29:35 / stefan" |
|
2993 |
! |
|
2994 |
||
2995 |
removeDependent:anObject |
|
2996 |
"make the argument, anObject be independent of the receiver" |
|
2997 |
||
2998 |
|wasBlocked| |
|
2999 |
||
3000 |
"/ must do this save from interrupts, since the dependents collection |
|
3001 |
"/ is possibly accessed from multiple threads. |
|
3002 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3003 |
"/ faster execution. |
|
3004 |
||
3005 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3006 |
[ |
|
6654 | 3007 |
|deps n d| |
3008 |
||
3009 |
deps := self dependents. |
|
3010 |
deps size ~~ 0 ifTrue:[ |
|
3011 |
||
3012 |
"/ to save a fair amount of memory in case of |
|
3013 |
"/ many dependencies, we store a single dependent in |
|
3014 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3015 |
"/ added. Here we have to do the inverse ... |
|
3016 |
||
9240 | 3017 |
((deps class == WeakArray) or:[deps class == Array]) ifTrue:[ |
6654 | 3018 |
((d := deps at:1) == anObject |
3019 |
or:[d isNil |
|
3020 |
or:[d == 0]]) ifTrue:[ |
|
3021 |
self dependents:nil |
|
3022 |
] |
|
3023 |
] ifFalse:[ |
|
3024 |
deps remove:anObject ifAbsent:[]. |
|
3025 |
(n := deps size) == 0 ifTrue:[ |
|
3026 |
self dependents:nil |
|
3027 |
] ifFalse:[ |
|
3028 |
n == 1 ifTrue:[ |
|
3029 |
d := deps firstIfEmpty:nil. |
|
3030 |
d notNil ifTrue:[ |
|
9246 | 3031 |
deps := (deps isWeakCollection ifTrue:WeakArray ifFalse:Array) with:d |
6654 | 3032 |
] ifFalse:[ |
3033 |
deps := nil |
|
3034 |
]. |
|
3035 |
self dependents:deps. |
|
3036 |
] |
|
3037 |
] |
|
3038 |
] |
|
3039 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3040 |
] ensure:[ |
6654 | 3041 |
wasBlocked ifFalse:[ |
3042 |
OperatingSystem unblockInterrupts |
|
3043 |
] |
|
5755 | 3044 |
] |
3045 |
||
3046 |
"Modified: / 26.1.1998 / 19:51:50 / cg" |
|
3047 |
! ! |
|
3048 |
||
7266 | 3049 |
!Object methodsFor:'dependents access (non weak)'! |
5755 | 3050 |
|
3051 |
addNonWeakDependent:anObject |
|
3052 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
|
3053 |
Be careful: this nonWeakDependency will prevent the dependent from being |
|
3054 |
garbage collected unless the dependency is removed. |
|
3055 |
This is a private mechanism, for directed dependencies." |
|
3056 |
||
3057 |
|wasBlocked| |
|
3058 |
||
3059 |
"/ must do this save from interrupts, since the dependents collection |
|
3060 |
"/ is possibly accessed from multiple threads. |
|
3061 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3062 |
"/ faster execution. |
|
3063 |
||
3064 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3065 |
[ |
|
6654 | 3066 |
|deps dep| |
3067 |
||
3068 |
deps := self nonWeakDependents. |
|
3069 |
||
3070 |
"/ to save a fair amount of memory in case of |
|
3071 |
"/ many dependencies, we store a single dependent in |
|
3072 |
"/ an Array, and switch to a Set if more dependents are |
|
3073 |
"/ added. |
|
3074 |
||
3075 |
deps size == 0 ifTrue:[ |
|
9442 | 3076 |
anObject notNil ifTrue:[ |
3077 |
self nonWeakDependents:(Array with:anObject). |
|
3078 |
] ifFalse:[ |
|
3079 |
"adding nil causes problems when adding the next one |
|
3080 |
(see below: trying to add nil to IdentitySet)" |
|
3081 |
"/ self halt:'try to add nil to list of dependents'. |
|
3082 |
]. |
|
6654 | 3083 |
] ifFalse:[ |
3084 |
deps class == Array ifTrue:[ |
|
3085 |
dep := deps at:1. |
|
3086 |
dep ~~ anObject ifTrue:[ |
|
3087 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
3088 |
] |
|
3089 |
] ifFalse:[ |
|
3090 |
deps add:anObject |
|
3091 |
] |
|
3092 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3093 |
] ensure:[ |
6654 | 3094 |
wasBlocked ifFalse:[ |
3095 |
OperatingSystem unblockInterrupts |
|
3096 |
] |
|
5755 | 3097 |
] |
3098 |
||
3099 |
"Created: / 19.4.1996 / 10:54:08 / cg" |
|
3100 |
"Modified: / 30.1.1998 / 14:03:08 / cg" |
|
3101 |
! |
|
3102 |
||
3103 |
nonWeakDependents |
|
3104 |
"return a Collection of nonWeakDependents - empty if there is none. |
|
3105 |
This is a private mechanism for directed dependencies." |
|
3106 |
||
3107 |
NonWeakDependencies isNil ifTrue:[^ #()]. |
|
3108 |
^ NonWeakDependencies at:self ifAbsent:#() |
|
3109 |
||
3110 |
"Created: / 19.4.1996 / 10:55:06 / cg" |
|
3111 |
"Modified: / 30.1.1998 / 14:06:47 / cg" |
|
3112 |
! |
|
3113 |
||
3114 |
nonWeakDependents:aCollection |
|
3115 |
"set the collection of nonWeak dependents. |
|
3116 |
This is a private helper for directed dependencies." |
|
3117 |
||
3118 |
[ |
|
6654 | 3119 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3120 |
NonWeakDependencies removeKey:self ifAbsent:nil |
|
3121 |
] ifFalse:[ |
|
3122 |
NonWeakDependencies at:self put:aCollection |
|
3123 |
] |
|
5755 | 3124 |
] valueUninterruptably |
3125 |
||
3126 |
"Created: 19.4.1996 / 11:07:47 / cg" |
|
3127 |
! |
|
3128 |
||
3129 |
removeNonWeakDependent:anObject |
|
3130 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
|
3131 |
(i.e. make it independent of the receiver)" |
|
3132 |
||
3133 |
|wasBlocked| |
|
3134 |
||
3135 |
"/ must do this save from interrupts, since the dependents collection |
|
3136 |
"/ is possibly accessed from multiple threads. |
|
3137 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3138 |
"/ faster execution. |
|
3139 |
||
3140 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3141 |
[ |
|
6654 | 3142 |
|deps n| |
3143 |
||
3144 |
deps := self nonWeakDependents. |
|
3145 |
deps size ~~ 0 ifTrue:[ |
|
3146 |
deps class == Array ifTrue:[ |
|
3147 |
(deps at:1) == anObject ifTrue:[ |
|
3148 |
self nonWeakDependents:nil |
|
3149 |
] |
|
3150 |
] ifFalse:[ |
|
3151 |
deps remove:anObject ifAbsent:[]. |
|
3152 |
(n := deps size) == 0 ifTrue:[ |
|
3153 |
self nonWeakDependents:nil |
|
3154 |
] ifFalse:[ |
|
3155 |
n == 1 ifTrue:[ |
|
3156 |
self nonWeakDependents:(Array with:(deps first)) |
|
3157 |
] |
|
3158 |
] |
|
3159 |
] |
|
3160 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3161 |
] ensure:[ |
6654 | 3162 |
wasBlocked ifFalse:[ |
3163 |
OperatingSystem unblockInterrupts |
|
3164 |
] |
|
5755 | 3165 |
] |
3166 |
||
3167 |
"Created: / 19.4.1996 / 11:44:44 / cg" |
|
3168 |
"Modified: / 30.1.1998 / 14:04:01 / cg" |
|
3169 |
! ! |
|
3170 |
||
9279 | 3171 |
!Object methodsFor:'dependents-interests'! |
3172 |
||
3173 |
addInterest:anInterest |
|
3174 |
"install an interest forwarder. |
|
3175 |
Here, we use the nonWeakDependencies." |
|
3176 |
||
3177 |
self addNonWeakDependent:anInterest |
|
3178 |
||
3179 |
"Created: 14.10.1996 / 22:27:34 / stefan" |
|
3180 |
! |
|
3181 |
||
3182 |
expressInterestIn:aspect for:anObject sendBack:aSelector |
|
3183 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
3184 |
changes aspect." |
|
3185 |
||
3186 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
3187 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
3188 |
||
3189 |
self addInterest:(InterestConverter |
|
3190 |
destination:anObject |
|
3191 |
selector:aSelector |
|
3192 |
aspect:aspect) |
|
3193 |
||
3194 |
" |
|
3195 |
|p b| |
|
3196 |
||
3197 |
b := [Transcript showCR:' -> the point changed']. |
|
3198 |
||
3199 |
p := Point new. |
|
3200 |
Transcript showCR:'interest in #foo:'. |
|
3201 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
3202 |
p x:1. |
|
3203 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
3204 |
p changed:#bar. |
|
3205 |
Transcript cr. |
|
3206 |
||
3207 |
Delay waitForSeconds:1. |
|
3208 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
3209 |
p changed:#foo. |
|
3210 |
Transcript cr. |
|
3211 |
||
3212 |
Delay waitForSeconds:1. |
|
3213 |
Transcript showCR:'no more interest in #foo:'. |
|
3214 |
p retractInterestIn:#foo for:b. |
|
3215 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
3216 |
p changed:#foo. |
|
3217 |
Transcript cr. |
|
3218 |
||
3219 |
Delay waitForSeconds:1. |
|
3220 |
Transcript showCR:'interest in #bar now:'. |
|
3221 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
3222 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
3223 |
p changed:#foo. |
|
3224 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
3225 |
p changed:#bar. |
|
3226 |
Transcript cr. |
|
3227 |
||
3228 |
Delay waitForSeconds:1. |
|
3229 |
Transcript showCR:'interest in #foo now:'. |
|
3230 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
3231 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
3232 |
p changed:#foo. |
|
3233 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
3234 |
p changed:#bar. |
|
3235 |
Transcript cr. |
|
3236 |
||
3237 |
Delay waitForSeconds:1. |
|
3238 |
Transcript showCR:'no more interests:'. |
|
3239 |
p retractInterestsFor:b. |
|
3240 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
3241 |
p changed:#foo. |
|
3242 |
Transcript showCR:'now changing #bar... (expect no notification)'. |
|
3243 |
p changed:#bar. |
|
3244 |
Transcript cr. |
|
3245 |
||
3246 |
p release. |
|
3247 |
" |
|
3248 |
||
3249 |
"Created: 19.4.1996 / 10:26:22 / cg" |
|
3250 |
"Modified: 19.4.1996 / 12:34:08 / cg" |
|
3251 |
"Modified: 14.10.1996 / 22:28:20 / stefan" |
|
3252 |
! |
|
3253 |
||
3254 |
interests |
|
3255 |
"return a Collection of interests - empty if there is none. |
|
3256 |
Here, we use the nonWeakDependents for interests." |
|
3257 |
||
3258 |
^ self nonWeakDependents |
|
3259 |
||
3260 |
"Created: / 14.10.1996 / 22:20:51 / stefan" |
|
3261 |
"Modified: / 30.1.1998 / 14:07:35 / cg" |
|
3262 |
! |
|
3263 |
||
3264 |
interestsFor:someOne |
|
3265 |
"return a collection of interests of someOne - empty if there is none." |
|
3266 |
||
3267 |
|coll deps| |
|
3268 |
||
3269 |
deps := self interests. |
|
3270 |
deps size == 0 ifTrue:[^ #()]. |
|
3271 |
||
3272 |
coll := IdentitySet new. |
|
3273 |
||
3274 |
deps do:[:dep | |
|
3275 |
(dep isInterestConverter) ifTrue:[ |
|
3276 |
dep destination == someOne ifTrue:[ |
|
3277 |
coll add:dep. |
|
3278 |
] |
|
3279 |
] |
|
3280 |
]. |
|
3281 |
^ coll |
|
3282 |
||
3283 |
"Created: / 30.1.1998 / 14:02:26 / cg" |
|
3284 |
"Modified: / 30.1.1998 / 14:08:24 / cg" |
|
3285 |
! |
|
3286 |
||
3287 |
onChangeEvaluate:aBlock |
|
3288 |
"arrange for aBlock to be evaluated whenever the receiver changes." |
|
3289 |
||
3290 |
^ self onChangeSend:#value to:aBlock |
|
3291 |
||
3292 |
" |
|
3293 |
|p b| |
|
3294 |
||
3295 |
b := [Transcript showCR:' -> the point changed']. |
|
3296 |
||
3297 |
p := Point new. |
|
3298 |
Transcript showCR:'interest in #foo:'. |
|
3299 |
p onChangeEvaluate:b. |
|
3300 |
p x:1. |
|
3301 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
3302 |
p changed:#bar. |
|
3303 |
||
3304 |
p retractInterests. |
|
3305 |
p changed:#bar. |
|
3306 |
" |
|
3307 |
! |
|
3308 |
||
3309 |
onChangeSend:aSelector to:anObject |
|
3310 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
3311 |
changes." |
|
3312 |
||
3313 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
3314 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
3315 |
||
3316 |
((self interests ? #()) |
|
3317 |
contains:[:anInterest | |
|
3318 |
(anInterest isInterestConverter) |
|
3319 |
and:[ anInterest destination == anObject |
|
3320 |
and:[ anInterest selector == aSelector]] |
|
3321 |
]) |
|
3322 |
ifTrue:[^ self]. |
|
3323 |
||
3324 |
self addInterest:(InterestConverter |
|
3325 |
destination:anObject |
|
3326 |
selector:aSelector) |
|
3327 |
||
3328 |
" |
|
3329 |
|p b| |
|
3330 |
||
3331 |
b := [Transcript showCR:'the point changed']. |
|
3332 |
||
3333 |
p := Point new. |
|
3334 |
p onChangeSend:#value to:b. |
|
3335 |
p x:1. |
|
3336 |
Transcript showCR:'now changing'. |
|
3337 |
p changed. |
|
3338 |
Transcript cr. |
|
3339 |
||
3340 |
Delay waitForSeconds:1. |
|
3341 |
Transcript showCR:'now changing'. |
|
3342 |
p changed. |
|
3343 |
Transcript cr. |
|
3344 |
||
3345 |
Delay waitForSeconds:1. |
|
3346 |
Transcript showCR:'no more interest'. |
|
3347 |
p retractInterestsFor:b. |
|
3348 |
Transcript showCR:'now changing again'. |
|
3349 |
p changed. |
|
3350 |
Transcript cr. |
|
3351 |
||
3352 |
Delay waitForSeconds:1. |
|
3353 |
Transcript showCR:'interest again'. |
|
3354 |
p onChangeSend:#value to:b. |
|
3355 |
Transcript showCR:'now changing again'. |
|
3356 |
p changed. |
|
3357 |
Transcript cr. |
|
3358 |
" |
|
3359 |
||
3360 |
"Created: 19.4.1996 / 10:26:38 / cg" |
|
3361 |
"Modified: 19.4.1996 / 12:34:26 / cg" |
|
3362 |
"Modified: 14.10.1996 / 22:28:27 / stefan" |
|
3363 |
! |
|
3364 |
||
3365 |
removeInterest:anInterest |
|
3366 |
"remove an interest forwarder. |
|
3367 |
Here, we use the nonWeakDependencies." |
|
3368 |
||
3369 |
self removeNonWeakDependent:anInterest |
|
3370 |
||
3371 |
"Created: 14.10.1996 / 22:21:59 / stefan" |
|
3372 |
! |
|
3373 |
||
3374 |
retractInterestIn:aspect for:someOne |
|
3375 |
"remove the interest of someOne in the receiver changing aspect |
|
3376 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
3377 |
||
3378 |
"/ for now, remove the interestConverter. |
|
3379 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
3380 |
||
3381 |
self retractInterestsForWhich:[:i | (i aspect == aspect) and:[i destination == someOne]] |
|
3382 |
||
3383 |
" |
|
3384 |
|p b| |
|
3385 |
||
3386 |
b := [Transcript showCR:'the point changed']. |
|
3387 |
||
3388 |
p := Point new. |
|
3389 |
Transcript showCR:'interest in #foo'. |
|
3390 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
3391 |
p x:1. |
|
3392 |
Transcript showCR:'now changing #bar'. |
|
3393 |
p changed:#bar. |
|
3394 |
Transcript cr. |
|
3395 |
||
3396 |
Delay waitForSeconds:1. |
|
3397 |
Transcript showCR:'now changing #foo'. |
|
3398 |
p changed:#foo. |
|
3399 |
Transcript cr. |
|
3400 |
||
3401 |
Delay waitForSeconds:1. |
|
3402 |
Transcript showCR:'no more interest in #foo'. |
|
3403 |
p retractInterestIn:#foo for:b. |
|
3404 |
Transcript showCR:'now changing #foo'. |
|
3405 |
p changed:#foo. |
|
3406 |
Transcript cr. |
|
3407 |
||
3408 |
Delay waitForSeconds:1. |
|
3409 |
Transcript showCR:'interest in #bar now'. |
|
3410 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
3411 |
Transcript showCR:'now changing #foo'. |
|
3412 |
p changed:#foo. |
|
3413 |
Transcript showCR:'now changing #bar'. |
|
3414 |
p changed:#bar. |
|
3415 |
Transcript cr. |
|
3416 |
||
3417 |
Delay waitForSeconds:1. |
|
3418 |
Transcript showCR:'interest in #foo now'. |
|
3419 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
3420 |
Transcript showCR:'now changing #foo'. |
|
3421 |
p changed:#foo. |
|
3422 |
Transcript showCR:'now changing #bar'. |
|
3423 |
p changed:#bar. |
|
3424 |
Transcript cr. |
|
3425 |
||
3426 |
Delay waitForSeconds:1. |
|
3427 |
Transcript showCR:'no more interests'. |
|
3428 |
p retractInterestsFor:b. |
|
3429 |
Transcript showCR:'now changing #foo'. |
|
3430 |
p changed:#foo. |
|
3431 |
Transcript showCR:'now changing #bar'. |
|
3432 |
p changed:#bar. |
|
3433 |
Transcript cr. |
|
3434 |
" |
|
3435 |
||
3436 |
"Created: / 19.4.1996 / 10:27:11 / cg" |
|
3437 |
"Modified: / 14.10.1996 / 22:21:19 / stefan" |
|
3438 |
"Modified: / 30.1.1998 / 14:05:34 / cg" |
|
3439 |
! |
|
3440 |
||
3441 |
retractInterests |
|
3442 |
"remove all interests in the receiver changing aspect |
|
3443 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
3444 |
||
3445 |
"/ for now, remove the interestConverter. |
|
3446 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
3447 |
||
3448 |
self retractInterestsForWhich:[:i | true ] |
|
3449 |
! |
|
3450 |
||
3451 |
retractInterestsFor:someOne |
|
3452 |
"remove the interest of someOne in the receiver |
|
3453 |
(as installed with #onChangeSend:to:)." |
|
3454 |
||
3455 |
"/ for now, remove the interestConverter. |
|
3456 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
3457 |
||
3458 |
self retractInterestsForWhich:[:i | i destination == someOne ] |
|
3459 |
||
3460 |
" |
|
3461 |
|p b| |
|
3462 |
||
3463 |
b := [Transcript showCR:'the point changed']. |
|
3464 |
||
3465 |
p := Point new. |
|
3466 |
p onChangeSend:#value to:b. |
|
3467 |
p x:1. |
|
3468 |
Transcript showCR:'now changing'. |
|
3469 |
p changed. |
|
3470 |
Transcript cr. |
|
3471 |
||
3472 |
Delay waitForSeconds:1. |
|
3473 |
Transcript showCR:'now changing'. |
|
3474 |
p changed. |
|
3475 |
Transcript cr. |
|
3476 |
||
3477 |
Delay waitForSeconds:1. |
|
3478 |
Transcript showCR:'no more interest'. |
|
3479 |
p retractInterestsFor:b. |
|
3480 |
Transcript showCR:'now changing again'. |
|
3481 |
p changed. |
|
3482 |
Transcript cr. |
|
3483 |
||
3484 |
Delay waitForSeconds:1. |
|
3485 |
Transcript showCR:'interest again'. |
|
3486 |
p onChangeSend:#value to:b. |
|
3487 |
Transcript showCR:'now changing again'. |
|
3488 |
p changed. |
|
3489 |
Transcript cr. |
|
3490 |
" |
|
3491 |
||
3492 |
"Created: / 19.4.1996 / 10:23:46 / cg" |
|
3493 |
"Modified: / 14.10.1996 / 22:21:25 / stefan" |
|
3494 |
"Modified: / 30.1.1998 / 14:04:52 / cg" |
|
3495 |
! |
|
3496 |
||
3497 |
retractInterestsForWhich:aBlock |
|
3498 |
"remove all interests in the receiver changing aspect |
|
3499 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
3500 |
||
3501 |
"/ for now, remove the interestConverter. |
|
3502 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
3503 |
||
3504 |
|deps coll| |
|
3505 |
||
3506 |
deps := self interests. |
|
3507 |
deps size ~~ 0 ifTrue:[ |
|
3508 |
"/ cannot removeDependent within the loop - the interests collection rehashes |
|
3509 |
coll := OrderedCollection new. |
|
3510 |
deps do:[:dep | |
|
3511 |
dep isInterestConverter ifTrue:[ |
|
3512 |
(aBlock value:dep) ifTrue:[coll add:dep]. |
|
3513 |
] |
|
3514 |
]. |
|
3515 |
coll do:[:dep | |
|
3516 |
self removeInterest:dep. |
|
3517 |
]. |
|
3518 |
]. |
|
3519 |
! |
|
3520 |
||
3521 |
retractInterestsIn:aspect |
|
3522 |
"remove all interests in the receiver changing aspect |
|
3523 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
3524 |
||
3525 |
"/ for now, remove the interestConverter. |
|
3526 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
3527 |
||
3528 |
self retractInterestsForWhich:[:i | i aspect == aspect ] |
|
3529 |
! ! |
|
3530 |
||
3531 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
3532 |
||
3533 |
removeActionsForEvent:eventName |
|
3534 |
"remove ST/V-style event triggers." |
|
3535 |
||
3536 |
self retractInterestsIn:eventName |
|
3537 |
! |
|
3538 |
||
3539 |
removeAllActionsWithReceiver:anObject |
|
3540 |
"remove ST/V-style event triggers." |
|
3541 |
||
3542 |
self retractInterestsFor:anObject |
|
3543 |
! |
|
3544 |
||
3545 |
triggerEvent:eventSymbol withArguments:parameters |
|
3546 |
"perform ST/V-style event triggering." |
|
3547 |
||
3548 |
self changed:eventSymbol with:parameters. |
|
3549 |
! ! |
|
3550 |
||
5755 | 3551 |
!Object methodsFor:'displaying'! |
3552 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3553 |
ascentOn:aGC |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3554 |
"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
|
3555 |
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
|
3556 |
coordinate is given by y. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3557 |
In other words: some draw above the given y coordinate. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3558 |
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
|
3559 |
the given y coordinate." |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3560 |
|
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3561 |
^ (aGC font onDevice:aGC device) ascent |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3562 |
! |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3563 |
|
6900 | 3564 |
displayOn:aGCOrStream |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3565 |
"Compatibility |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3566 |
append a printed desription on some stream (Dolphin, Squeak) |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3567 |
OR: |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3568 |
display the receiver in a graphicsContext at 0@0 (ST80). |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3569 |
This method allows for any object to be displayed in some view |
5755 | 3570 |
(although the fallBack is to display its printString ...)" |
3571 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3572 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3573 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
6900 | 3574 |
(aGCOrStream isStream or:[aGCOrStream == Transcript]) ifTrue:[ |
3575 |
self printOn:aGCOrStream. |
|
3576 |
^ self |
|
3577 |
]. |
|
3578 |
^ self displayOn:aGCOrStream x:0 y:0. |
|
5755 | 3579 |
|
3580 |
"Created: 29.5.1996 / 16:28:58 / cg" |
|
3581 |
! |
|
3582 |
||
3583 |
displayOn:aGC at:aPoint |
|
3584 |
"ST-80 Compatibility |
|
3585 |
display the receiver in a graphicsContext - this method allows |
|
3586 |
for any object to be displayed in a ListView - for example." |
|
3587 |
||
3588 |
^ self displayOn:aGC x:(aPoint x) y:(aPoint y). |
|
3589 |
! |
|
3590 |
||
3591 |
displayOn:aGC x:x y:y |
|
3592 |
"display the receiver in a graphicsContext - this method allows |
|
3593 |
for any object to be displayed in a ListView - for example." |
|
3594 |
||
3595 |
self displayOn:aGC x:x y:y opaque:false |
|
3596 |
||
3597 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3598 |
! |
|
3599 |
||
3600 |
displayOn:aGc x:x y:y opaque:opaque |
|
3601 |
"display the receiver in a graphicsContext - this method allows |
|
3602 |
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
|
3603 |
The fallBack here shows the receivers displayString. |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3604 |
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
|
3605 |
ask using #ascentOn: if required" |
5755 | 3606 |
|
3607 |
|s yBaseline| |
|
3608 |
||
3609 |
s := self displayString. |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3610 |
yBaseline := y "+ aGc font ascent". |
5755 | 3611 |
opaque ifTrue:[ |
6654 | 3612 |
aGc displayOpaqueString:s x:x y:yBaseline. |
5755 | 3613 |
] ifFalse:[ |
6654 | 3614 |
aGc displayString:s x:x y:yBaseline. |
5755 | 3615 |
]. |
3616 |
||
3617 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3618 |
! |
|
3619 |
||
3620 |
displayOpaqueOn:aGC x:x y:y |
|
3621 |
"display the receiver in a graphicsContext - this method allows |
|
3622 |
for any object to be displayed in a ListView - for example." |
|
3623 |
||
3624 |
self displayOn:aGC x:x y:y opaque:true |
|
3625 |
||
3626 |
"Modified: / 29.5.1996 / 16:29:38 / cg" |
|
3627 |
"Created: / 26.10.1997 / 15:01:36 / cg" |
|
3628 |
! |
|
3629 |
||
3630 |
displayString |
|
3631 |
"return a string used when displaying the receiver in a view; |
|
3632 |
for example an Inspector. This is usually the same as printString, |
|
3633 |
but sometimes redefined for a better look." |
|
3634 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3635 |
|s| |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3636 |
|
8322
95ca965f65ed
Handle unicode in #displayString
Stefan Vogel <sv@exept.de>
parents:
8300
diff
changeset
|
3637 |
s := CharacterWriteStream on:(String new:32). |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3638 |
self displayOn:s. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3639 |
^ s contents |
5755 | 3640 |
|
3641 |
" |
|
3642 |
#(1 2 3) printString |
|
3643 |
#(1 2 3) displayString |
|
3644 |
#(1 2 3) storeString |
|
3645 |
" |
|
3646 |
! |
|
3647 |
||
3648 |
heightOn:aGC |
|
3649 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
3650 |
||
3651 |
^ (aGC font onDevice:aGC device) heightOf:(self displayString) |
|
3652 |
! |
|
3653 |
||
6654 | 3654 |
widthFrom:startIndex to:endIndex on:aGC |
3655 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3656 |
||
3657 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) from:startIndex to:endIndex |
|
3658 |
! |
|
3659 |
||
5755 | 3660 |
widthOn:aGC |
3661 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3662 |
||
3663 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) |
|
3664 |
! ! |
|
3665 |
||
7359 | 3666 |
!Object methodsFor:'double dispatching'! |
3667 |
||
3668 |
equalFromComplex:aComplex |
|
3669 |
"adding this method here allows for any non-number to be compared to a complex |
|
3670 |
and return false from this comparison. |
|
3671 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3672 |
which uses #= (i.e. a Set or Dictionary)." |
|
3673 |
||
3674 |
^ false |
|
3675 |
! |
|
3676 |
||
3677 |
equalFromFixedPoint:aFixedPoint |
|
3678 |
"adding this method here allows for any non-number to be compared to a fixedPoint |
|
3679 |
and return false from this comparison. |
|
3680 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3681 |
which uses #= (i.e. a Set or Dictionary)." |
|
3682 |
||
3683 |
^ false |
|
3684 |
! |
|
3685 |
||
3686 |
equalFromFloat:aFloat |
|
3687 |
"adding this method here allows for any non-number to be compared to a float |
|
3688 |
and return false from this comparison. |
|
3689 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3690 |
which uses #= (i.e. a Set or Dictionary)." |
|
3691 |
||
3692 |
^ false |
|
3693 |
! |
|
3694 |
||
3695 |
equalFromFraction:aFraction |
|
3696 |
"adding this method here allows for any non-number to be compared to a fraction |
|
3697 |
and return false from this comparison. |
|
3698 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3699 |
which uses #= (i.e. a Set or Dictionary)." |
|
3700 |
||
3701 |
^ false |
|
3702 |
! |
|
3703 |
||
3704 |
equalFromInteger:anInteger |
|
3705 |
"adding this method here allows for any non-number to be compared to an integer |
|
3706 |
and return false from this comparison. |
|
3707 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3708 |
which uses #= (i.e. a Set or Dictionary)." |
|
3709 |
||
3710 |
^ false |
|
3711 |
! |
|
3712 |
||
7455 | 3713 |
equalFromLargeFloat:aLargeFloat |
3714 |
"adding this method here allows for any non-number to be compared to a largeFloat |
|
3715 |
and return false from this comparison. |
|
3716 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3717 |
which uses #= (i.e. a Set or Dictionary)." |
|
3718 |
||
3719 |
^ false |
|
3720 |
! |
|
3721 |
||
7359 | 3722 |
equalFromLongFloat:aLongFloat |
3723 |
"adding this method here allows for any non-number to be compared to a longFloat |
|
3724 |
and return false from this comparison. |
|
3725 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3726 |
which uses #= (i.e. a Set or Dictionary)." |
|
3727 |
||
3728 |
^ false |
|
3729 |
! |
|
3730 |
||
3731 |
equalFromShortFloat:aShortFloat |
|
3732 |
"adding this method here allows for any non-number to be compared to a shortFloat |
|
3733 |
and return false from this comparison. |
|
3734 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3735 |
which uses #= (i.e. a Set or Dictionary)." |
|
3736 |
||
3737 |
^ false |
|
3738 |
! ! |
|
3739 |
||
5755 | 3740 |
!Object methodsFor:'encoding & decoding'! |
3741 |
||
3742 |
decodeAsLiteralArray |
|
8832 | 3743 |
"given a literalEncoding in the receiver, |
3744 |
create & return the corresponding object. |
|
3745 |
The inverse operation to #literalArrayEncoding." |
|
3746 |
||
5755 | 3747 |
^ self |
3748 |
! |
|
3749 |
||
3750 |
encodeOn:anEncoder with:aParameter |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3751 |
"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
|
3752 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3753 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3754 |
|
8404 | 3755 |
self acceptVisitor:anEncoder with:aParameter |
6718 | 3756 |
! |
3757 |
||
3758 |
encodingVectorForInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3759 |
"OBSOLETE, use elementDescriptorForInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3760 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3761 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3762 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3763 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
6718 | 3764 |
|
3765 |
" |
|
3766 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
3767 |
Dictionary new encodingVectorForInstanceVariables |
|
3768 |
(5 @ nil) encodingVectorForInstanceVariables |
|
3769 |
" |
|
3770 |
! |
|
3771 |
||
3772 |
encodingVectorForNonNilInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3773 |
"OBSOLETE, use elementDescriptorForNonNilInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3774 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3775 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3776 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3777 |
^ self elementDescriptorForInstanceVariablesMatching:[:varVal | varVal notNil]. |
6718 | 3778 |
|
3779 |
" |
|
3780 |
#(1 2 3 nil true symbol) encodingVectorForNonNilInstanceVariables |
|
3781 |
(5 @ nil) encodingVectorForNonNilInstanceVariables |
|
3782 |
" |
|
3783 |
! |
|
3784 |
||
5755 | 3785 |
fromLiteralArrayEncoding:aSpecArray |
8798 | 3786 |
"read my attributes from aSpecArray. |
3787 |
Recursively decodes arguments." |
|
3788 |
||
3789 |
|sel litVal val |
|
5755 | 3790 |
stop "{ Class:SmallInteger }" | |
3791 |
||
3792 |
stop := aSpecArray size. |
|
3793 |
||
3794 |
2 to:stop by:2 do:[:i| |
|
6654 | 3795 |
sel := aSpecArray at:i. |
8798 | 3796 |
litVal := aSpecArray at:i + 1. |
6654 | 3797 |
|
3798 |
(self respondsTo:sel) ifTrue:[ |
|
8798 | 3799 |
val := litVal decodeAsLiteralArray. |
3800 |
self perform:sel with:val |
|
6654 | 3801 |
] ifFalse:[ |
3802 |
Transcript show:self class name; show:': unhandled literalArrayEncoding attribute: '. |
|
3803 |
Transcript showCR:sel. |
|
8798 | 3804 |
|
3805 |
"/ thats a debug halt, |
|
3806 |
"/ it should probably be removed (to simply ignore unhandled attributes)... |
|
3807 |
"/ for now, it is left in, in order to easily find incompatibilities between |
|
3808 |
"/ VW and ST/X. |
|
3809 |
self halt:('Unrecognized attribute in spec: #', sel). "/ value is: val / litVal. |
|
6654 | 3810 |
] |
5755 | 3811 |
] |
3812 |
! |
|
3813 |
||
3814 |
literalArrayEncoding |
|
3815 |
"generate a literalArrayEncoding array for myself. |
|
3816 |
This uses #literalArrayEncodingSlotOrder which defines the slots and |
|
3817 |
order and #skippedInLiteralEncoding which defines slots to skip. |
|
3818 |
For most subclasses, there is no need to redefine those." |
|
3819 |
||
8832 | 3820 |
|names encoding cls skipped slots| |
5755 | 3821 |
|
3822 |
self isLiteral ifTrue:[ |
|
6654 | 3823 |
^ self |
5755 | 3824 |
]. |
3825 |
||
8832 | 3826 |
slots := self literalArrayEncodingSlotOrder. |
5755 | 3827 |
skipped := self skippedInLiteralEncoding. |
3828 |
cls := self class. |
|
3829 |
names := cls allInstVarNames. |
|
8832 | 3830 |
encoding := OrderedCollection new:(1 + (2 * (slots size - skipped size))). |
8839
c4471cb2799f
stefan: bitte vor Einchecken Testen !
Claus Gittinger <cg@exept.de>
parents:
8833
diff
changeset
|
3831 |
encoding add:cls name. |
8832 | 3832 |
|
3833 |
slots do:[:instSlot | |
|
6654 | 3834 |
|value nm| |
3835 |
||
3836 |
nm := names at:instSlot. |
|
3837 |
(skipped includes:nm) ifFalse:[ |
|
3838 |
(value := self instVarAt:instSlot) notNil ifTrue:[ |
|
3839 |
encoding add:(nm , ':') asSymbol. |
|
3840 |
encoding add:value literalArrayEncoding |
|
3841 |
] |
|
3842 |
] |
|
5755 | 3843 |
]. |
3844 |
^ encoding asArray |
|
8841 | 3845 |
|
3846 |
" |
|
3847 |
(1 -> 2) literalArrayEncoding |
|
3848 |
DebugView menuSpec decodeAsLiteralArray literalArrayEncoding = |
|
3849 |
DebugView menuSpec |
|
3850 |
" |
|
5755 | 3851 |
! |
3852 |
||
3853 |
literalArrayEncodingSlotOrder |
|
3854 |
"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
|
3855 |
a literalArrayEncoding" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3856 |
|
5755 | 3857 |
^ 1 to:self class instSize |
3858 |
! |
|
3859 |
||
7112 | 3860 |
postDecodeFrom:aDecoder aspect:aspectSymbol |
3861 |
"invoked by xmlDecoder (and others in the future), after an |
|
3862 |
object has been decoded (i.e. its instance variables have been restored)" |
|
3863 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3864 |
^ self |
7112 | 3865 |
! |
3866 |
||
5755 | 3867 |
skippedInLiteralEncoding |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3868 |
"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
|
3869 |
|
5755 | 3870 |
^ #() |
3871 |
! ! |
|
3872 |
||
3873 |
!Object methodsFor:'error handling'! |
|
3874 |
||
3875 |
appropriateDebugger:aSelector |
|
3876 |
"{ Pragma: +optSpace }" |
|
3877 |
||
3878 |
"return an appropriate debugger to use. |
|
3879 |
If there is already a debugger active on the stack, and it is |
|
3880 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
3881 |
||
3882 |
|context| |
|
3883 |
||
3884 |
"DebugView cannot run without system processes" |
|
3885 |
||
3886 |
(Processor isNil |
|
3887 |
or:[Processor activeProcessIsSystemProcess |
|
3888 |
or:[Smalltalk isInitialized not]]) ifTrue:[ |
|
6654 | 3889 |
^ MiniDebugger |
5755 | 3890 |
]. |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
3891 |
(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
|
3892 |
Debugger isNil ifTrue:[^ nil]. |
6654 | 3893 |
^ MiniDebugger |
5755 | 3894 |
]. |
3895 |
||
3896 |
context := thisContext. |
|
3897 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
3898 |
[context notNil] whileTrue:[ |
|
6654 | 3899 |
((context receiver class == Debugger) |
3900 |
and:[context selector == aSelector]) ifTrue:[ |
|
3901 |
"we are already in some Debugger" |
|
3902 |
(Debugger == MiniDebugger) ifTrue:[ |
|
3903 |
"we are already in the MiniDebugger" |
|
3904 |
ErrorRecursion ifFalse:[ |
|
3905 |
Smalltalk fatalAbort:'recursive error ...' |
|
3906 |
] |
|
3907 |
]. |
|
3908 |
MiniDebugger isNil ifTrue:[ |
|
3909 |
Smalltalk fatalAbort:'no debugger' |
|
3910 |
]. |
|
3911 |
||
3912 |
"ok, an error occured while in the graphical debugger; |
|
3913 |
lets try MiniDebugger" |
|
3914 |
^ MiniDebugger |
|
3915 |
]. |
|
3916 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
5755 | 3917 |
]. |
3918 |
"not within Debugger - no problem" |
|
3919 |
^ Debugger |
|
3920 |
||
3921 |
"Modified: / 23.9.1996 / 12:14:52 / stefan" |
|
3922 |
"Modified: / 19.5.1999 / 18:05:00 / cg" |
|
3923 |
! |
|
3924 |
||
3925 |
cannotSendMessage:aMessage to:someReceiver |
|
3926 |
"this message is sent by the runtime system (VM), |
|
3927 |
when a message is sent to some object, whose class is not |
|
3928 |
a valid behavior (see documentation in Behavior)." |
|
3929 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3930 |
^ VMInternalError |
6654 | 3931 |
raiseWith:someReceiver |
3932 |
errorString:('bad class in send of #' , aMessage selector) |
|
5755 | 3933 |
|
3934 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
3935 |
! |
|
3936 |
||
3937 |
doesNotUnderstand:aMessage |
|
3938 |
"this message is sent by the runtime system (VM) when |
|
3939 |
a message is not understood by some object (i.e. there |
|
3940 |
is no method for that selector). The original message has |
|
3941 |
been packed into aMessage (i.e. the receiver, selector and |
|
3942 |
any arguments) and the original receiver is then sent the |
|
3943 |
#doesNotUnderstand: message. |
|
3944 |
Here, we raise another signal which usually enters the debugger. |
|
3945 |
You can of course redefine #doesNotUnderstand: in your classes |
|
3946 |
to implement message delegation, |
|
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
3947 |
or handle the MessageNotUnderstood exception gracefully." |
5755 | 3948 |
|
3949 |
<context: #return> |
|
3950 |
||
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
3951 |
^ MessageNotUnderstood raiseRequestWith:aMessage |
5755 | 3952 |
! |
3953 |
||
3954 |
elementBoundsError |
|
3955 |
"{ Pragma: +optSpace }" |
|
3956 |
||
3957 |
"report an error that badElement is out of bounds |
|
3958 |
(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
|
3959 |
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
|
3960 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3961 |
^ ElementBoundsError raise |
5755 | 3962 |
|
3963 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
3964 |
! |
|
3965 |
||
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3966 |
elementBoundsError:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3967 |
"{ Pragma: +optSpace }" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3968 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3969 |
"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
|
3970 |
(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
|
3971 |
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
|
3972 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3973 |
^ ElementBoundsError raiseWith:aValue |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3974 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3975 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3976 |
! |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3977 |
|
5755 | 3978 |
elementNotCharacter |
3979 |
"{ Pragma: +optSpace }" |
|
3980 |
||
3981 |
"report an error that object to be stored is no Character. |
|
3982 |
(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
|
3983 |
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
|
3984 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3985 |
^ ElementBoundsError raise |
5755 | 3986 |
|
3987 |
"Modified: 8.5.1996 / 09:12:49 / cg" |
|
3988 |
! |
|
3989 |
||
3990 |
elementNotInteger |
|
3991 |
"{ Pragma: +optSpace }" |
|
3992 |
||
3993 |
"report an error that object to be stored is not Integer. |
|
3994 |
(in collections that store integers only). |
|
3995 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3996 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3997 |
^ ElementBoundsError raise |
5755 | 3998 |
|
3999 |
"Modified: 8.5.1996 / 09:12:51 / cg" |
|
4000 |
! |
|
4001 |
||
4002 |
error |
|
4003 |
"{ Pragma: +optSpace }" |
|
4004 |
||
4005 |
<context: #return> |
|
4006 |
||
4007 |
"report error that an error occured. |
|
4008 |
The error is reported by raising the Error exception, |
|
4009 |
which is non-proceedable. |
|
4010 |
If no handler has been setup, a debugger is entered." |
|
4011 |
||
4012 |
Error raiseWith:#error: |
|
4013 |
||
4014 |
" |
|
4015 |
nil error |
|
4016 |
" |
|
4017 |
||
4018 |
"Modified: / 8.5.1996 / 09:13:01 / cg" |
|
4019 |
"Modified: / 2.8.1999 / 17:00:19 / stefan" |
|
4020 |
! |
|
4021 |
||
4022 |
error:aString |
|
4023 |
"{ Pragma: +optSpace }" |
|
4024 |
||
4025 |
<context: #return> |
|
4026 |
||
4027 |
"Raise an error with error message aString. |
|
4028 |
The error is reported by raising the Error exception, |
|
4029 |
which is non-proceedable. |
|
4030 |
If no handler has been setup, a debugger is entered." |
|
4031 |
||
4032 |
Error raiseWith:#error: errorString:aString |
|
4033 |
||
4034 |
" |
|
4035 |
nil error:' bad bad bad' |
|
4036 |
" |
|
4037 |
||
4038 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
4039 |
! |
|
4040 |
||
4041 |
error:aString mayProceed:mayProceed |
|
4042 |
"{ Pragma: +optSpace }" |
|
4043 |
||
4044 |
"enter debugger with error-message aString. |
|
4045 |
The error is reported by raising either the |
|
4046 |
non-proceedable Error exception, |
|
4047 |
or the ProceedableError exception." |
|
4048 |
||
4049 |
mayProceed ifTrue:[ |
|
6654 | 4050 |
^ ProceedableError raiseRequestWith:#error: errorString:aString |
5755 | 4051 |
]. |
4052 |
||
4053 |
Error raiseWith:#error: errorString:aString |
|
4054 |
||
4055 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
4056 |
! |
|
4057 |
||
6900 | 4058 |
errorInvalidFormat |
4059 |
"{ Pragma: +optSpace }" |
|
4060 |
||
4061 |
<context: #return> |
|
4062 |
||
4063 |
"report an error that some conversion to/from string representation failed |
|
4064 |
typically when converting numbers, date, time etc." |
|
4065 |
||
4066 |
^ ConversionError raiseErrorString:'invalid format' |
|
4067 |
! |
|
4068 |
||
5755 | 4069 |
errorKeyNotFound:aKey |
4070 |
"{ Pragma: +optSpace }" |
|
4071 |
||
4072 |
"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
|
4073 |
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
|
4074 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4075 |
^ KeyNotFoundError raiseRequestWith:aKey |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4076 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4077 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4078 |
Dictionary new at:#nonExistantElement |
5755 | 4079 |
" |
4080 |
! |
|
4081 |
||
4082 |
errorNotFound |
|
4083 |
"{ Pragma: +optSpace }" |
|
4084 |
||
4085 |
"report an error that no element was found in a collection. |
|
4086 |
The error is reported by raising the NotFoundSignal exception." |
|
4087 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4088 |
^ NotFoundError raiseRequestWith:nil |
5755 | 4089 |
|
4090 |
"Modified: / 8.5.1996 / 09:13:11 / cg" |
|
4091 |
"Modified: / 26.7.1999 / 10:51:50 / stefan" |
|
4092 |
! |
|
4093 |
||
6874 | 4094 |
errorNotFound:errorString |
4095 |
"{ Pragma: +optSpace }" |
|
4096 |
||
4097 |
"report an error that no element was found in a collection. |
|
4098 |
The error is reported by raising the NotFoundSignal exception." |
|
4099 |
||
4100 |
^ NotFoundError raiseErrorString:errorString |
|
4101 |
! |
|
4102 |
||
5755 | 4103 |
errorSignal |
4104 |
^ self class errorSignal |
|
4105 |
||
4106 |
"Created: / 19.6.1998 / 02:32:32 / cg" |
|
4107 |
! |
|
4108 |
||
4109 |
halt |
|
4110 |
"{ Pragma: +optSpace }" |
|
4111 |
||
4112 |
"enter debugger with halt-message. |
|
4113 |
The error is reported by raising the HaltSignal exception." |
|
4114 |
||
6716
7e2bac4221d1
allow for halts to be ignored
Claus Gittinger <cg@exept.de>
parents:
6708
diff
changeset
|
4115 |
(Smalltalk at:#IgnoreHalt ifAbsent:false) == true ifTrue:[^ self]. |
6221 | 4116 |
^ HaltInterrupt raiseRequestWith:#halt |
4117 |
||
5755 | 4118 |
"Modified: / 2.8.1999 / 17:00:29 / stefan" |
6221 | 4119 |
"Modified: / 17.11.2001 / 22:47:44 / cg" |
5755 | 4120 |
! |
4121 |
||
4122 |
halt:aString |
|
4123 |
"{ Pragma: +optSpace }" |
|
4124 |
||
4125 |
"enter debugger with halt-message. |
|
4126 |
The error is reported by raising the HaltSignal exception." |
|
4127 |
||
6716
7e2bac4221d1
allow for halts to be ignored
Claus Gittinger <cg@exept.de>
parents:
6708
diff
changeset
|
4128 |
(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
|
4129 |
^ HaltInterrupt raiseRequestWith:#halt: errorString:aString |
5755 | 4130 |
|
4131 |
"Modified: 8.5.1996 / 09:13:23 / cg" |
|
4132 |
! |
|
4133 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4134 |
handlerForSignal:exceptionHandler context:theContext originator:originator |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4135 |
" 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
|
4136 |
|
7566 | 4137 |
thisContext isRecursive ifTrue:[^ nil]. |
4138 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4139 |
'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
|
4140 |
' context: ' print. theContext printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4141 |
' originator: ' print. originator printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4142 |
' sender: ' print. thisContext sender printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4143 |
|
7566 | 4144 |
"/ MiniDebugger enter:thisContext withMessage:'oops' mayProceed:true. |
4145 |
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
|
4146 |
! |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4147 |
|
5755 | 4148 |
implementedBySubclass |
4149 |
"{ Pragma: +optSpace }" |
|
4150 |
||
4151 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
4152 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4153 |
^ self subclassResponsibility:'method must be reimplemented in ST/V subclass' |
5755 | 4154 |
! |
4155 |
||
4156 |
indexNotInteger |
|
4157 |
"{ Pragma: +optSpace }" |
|
4158 |
||
4159 |
"report an error that index is not an Integer. |
|
4160 |
(when accessing collections indexed by an integer key). |
|
4161 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4162 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4163 |
^ NonIntegerIndexError raiseRequestWith:nil |
5755 | 4164 |
|
4165 |
"Modified: / 8.5.1996 / 09:13:37 / cg" |
|
4166 |
"Modified: / 26.7.1999 / 10:57:43 / stefan" |
|
4167 |
! |
|
4168 |
||
4169 |
indexNotInteger:anIndex |
|
4170 |
"{ Pragma: +optSpace }" |
|
4171 |
||
4172 |
"report an error that index is not an Integer. |
|
4173 |
(when accessing collections indexed by an integer key). |
|
4174 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4175 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4176 |
^ NonIntegerIndexError raiseRequestWith:anIndex |
5755 | 4177 |
|
4178 |
"Created: / 16.5.1998 / 19:39:41 / cg" |
|
4179 |
! |
|
4180 |
||
7216 | 4181 |
indexNotIntegerOrOutOfBounds:index |
4182 |
"{ Pragma: +optSpace }" |
|
4183 |
||
4184 |
"report an error that index is either non-integral or out of bounds" |
|
4185 |
||
4186 |
index isInteger ifFalse:[ |
|
4187 |
^ self indexNotInteger:index |
|
4188 |
]. |
|
4189 |
^ self subscriptBoundsError:index |
|
4190 |
! |
|
4191 |
||
5755 | 4192 |
integerCheckError |
4193 |
"{ Pragma: +optSpace }" |
|
4194 |
||
4195 |
"generated when a variable declared with an integer type gets a bad |
|
4196 |
value assigned" |
|
4197 |
||
4198 |
^ self error:'bad assign of ' , self printString , |
|
6654 | 4199 |
' (' , self class name , ') to integer-typed variable' |
5755 | 4200 |
! |
4201 |
||
4202 |
invalidCodeObject |
|
4203 |
"{ Pragma: +optSpace }" |
|
4204 |
||
4205 |
self error:'not an executable code object' |
|
4206 |
||
4207 |
"Created: 1.8.1997 / 00:16:44 / cg" |
|
4208 |
! |
|
4209 |
||
4210 |
invalidMessage |
|
4211 |
"{ Pragma: +optSpace }" |
|
4212 |
||
4213 |
"this is sent by ST/V code - its the same as #shouldNotImplement" |
|
4214 |
||
4215 |
^ self shouldNotImplement |
|
4216 |
! |
|
4217 |
||
4218 |
mustBeRectangle |
|
4219 |
"{ Pragma: +optSpace }" |
|
4220 |
||
4221 |
"report an argument-not-rectangle-error" |
|
4222 |
||
4223 |
^ self error:'argument must be a Rectangle' |
|
4224 |
! |
|
4225 |
||
4226 |
mustBeString |
|
4227 |
"{ Pragma: +optSpace }" |
|
4228 |
||
4229 |
"report an argument-not-string-error" |
|
4230 |
||
4231 |
^ self error:'argument must be a String' |
|
4232 |
! |
|
4233 |
||
4234 |
notIndexed |
|
4235 |
"{ Pragma: +optSpace }" |
|
4236 |
||
4237 |
<context: #return> |
|
4238 |
||
4239 |
"report an error that receiver has no indexed instance variables. |
|
4240 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4241 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4242 |
^ SubscriptOutOfBoundsError |
6654 | 4243 |
raiseErrorString:'receiver has no indexed variables' |
5755 | 4244 |
|
4245 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
|
4246 |
! |
|
4247 |
||
4248 |
openDebuggerOnException:ex |
|
4249 |
"{ Pragma: +optSpace }" |
|
4250 |
||
4251 |
"enter the debugger on some unhandled exception" |
|
4252 |
||
6884 | 4253 |
|msgString debugger answer| |
5755 | 4254 |
|
7208 | 4255 |
msgString := ex description. |
5755 | 4256 |
" |
4257 |
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
|
4258 |
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
|
4259 |
ignore will raise an AbortOperationRequest. |
5755 | 4260 |
" |
4261 |
Debugger isNil ifTrue:[ |
|
6840 | 4262 |
msgString := 'Error: ' , msgString. |
6654 | 4263 |
|
7562
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4264 |
thisContext isRecursive ifTrue:[ |
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4265 |
msgString errorPrintCR. |
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4266 |
Smalltalk fatalAbort:'recursive unhandled exception' |
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4267 |
]. |
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4268 |
|
9509 | 4269 |
Smalltalk isSmalltalkDevelopmentSystem ifFalse:[ |
9297 | 4270 |
ex parameter signal == HaltInterrupt ifTrue:[ |
4271 |
"/ 'Halt ignored' infoPrintCR. |
|
4272 |
^ self |
|
4273 |
]. |
|
4274 |
||
7562
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4275 |
(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
|
4276 |
AbortOperationRequest isHandled ifTrue:[ |
7208 | 4277 |
answer := OptionBox |
4278 |
request:msgString |
|
4279 |
label:msgString |
|
9299 | 4280 |
buttonLabels:#('Exit' 'Terminate Thread' 'Ignore' 'Abort' ) |
4281 |
values:#(exit terminate ignore abort) |
|
9298
2629011bf060
added terminate to unhandled exception dialog
Claus Gittinger <cg@exept.de>
parents:
9297
diff
changeset
|
4282 |
default:#abort. |
7208 | 4283 |
] ifFalse:[ |
4284 |
answer := OptionBox |
|
4285 |
request:msgString |
|
4286 |
label:msgString |
|
9299 | 4287 |
buttonLabels:#('Exit' 'Terminate Thread' 'Ignore' ) |
4288 |
values:#(exit terminate ignore ) |
|
9298
2629011bf060
added terminate to unhandled exception dialog
Claus Gittinger <cg@exept.de>
parents:
9297
diff
changeset
|
4289 |
default:#terminate. |
7208 | 4290 |
]. |
7562
869c48046a5c
oops - standAlone debugging fixed
Claus Gittinger <cg@exept.de>
parents:
7539
diff
changeset
|
4291 |
|
6884 | 4292 |
answer == #abort ifTrue:[ |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4293 |
^ AbortOperationRequest raiseRequest |
6884 | 4294 |
]. |
7208 | 4295 |
answer == #ignore ifTrue:[ |
6884 | 4296 |
^ nil |
4297 |
]. |
|
9298
2629011bf060
added terminate to unhandled exception dialog
Claus Gittinger <cg@exept.de>
parents:
9297
diff
changeset
|
4298 |
answer == #terminate ifTrue:[ |
2629011bf060
added terminate to unhandled exception dialog
Claus Gittinger <cg@exept.de>
parents:
9297
diff
changeset
|
4299 |
^ Processor activeProcess terminate. |
2629011bf060
added terminate to unhandled exception dialog
Claus Gittinger <cg@exept.de>
parents:
9297
diff
changeset
|
4300 |
]. |
9314
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4301 |
"asking second time here to prevent the user from accidently closing his app" |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4302 |
answer == #exit ifTrue:[ |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4303 |
answer := OptionBox |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4304 |
request:'Do you really wish to exit this application (all changes will be lost)?' |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4305 |
label:msgString |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4306 |
buttonLabels:#('Yes' 'No' ) |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4307 |
values:#(exit abort) |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4308 |
default:#abort. |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4309 |
]. |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4310 |
answer == #abort ifTrue:[ |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4311 |
^ AbortOperationRequest raiseRequest |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4312 |
]. |
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4313 |
|
93bac344273f
asking twice to exit applicaion after unhandled exception (only standalone app)
Michael Beyl <mb@exept.de>
parents:
9299
diff
changeset
|
4314 |
|
6654 | 4315 |
]. |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4316 |
"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
|
4317 |
ex signal == NoHandlerError ifTrue:[ |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4318 |
ex parameter signal == UserInterrupt ifTrue:[ |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4319 |
OperatingSystem exit:130 |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4320 |
]. |
bc8e45d10f43
dont out the "unhandled exception..." message,
Claus Gittinger <cg@exept.de>
parents:
6840
diff
changeset
|
4321 |
]. |
6654 | 4322 |
msgString errorPrintCR. |
9203 | 4323 |
thisContext fullPrintAll. |
6654 | 4324 |
OperatingSystem exit:1 |
4325 |
]. |
|
4326 |
||
4327 |
msgString errorPrintCR. |
|
4328 |
Smalltalk fatalAbort:'no Debugger defined' |
|
5755 | 4329 |
]. |
4330 |
||
4331 |
" |
|
4332 |
find an appropriate debugger to use |
|
4333 |
" |
|
4334 |
debugger := self appropriateDebugger:(thisContext selector). |
|
4335 |
debugger isNil ifTrue:[ |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4336 |
^ AbortOperationRequest raiseRequest |
5755 | 4337 |
]. |
4338 |
||
4339 |
^ debugger |
|
6654 | 4340 |
enter:ex suspendedContext |
4341 |
withMessage:msgString |
|
4342 |
mayProceed:(ex mayProceed). |
|
5755 | 4343 |
|
9509 | 4344 |
"Modified: / 10-08-2006 / 13:13:22 / cg" |
5755 | 4345 |
! |
4346 |
||
4347 |
primitiveFailed |
|
4348 |
"{ Pragma: +optSpace }" |
|
4349 |
||
4350 |
"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
|
4351 |
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
|
4352 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4353 |
|sender| |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4354 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4355 |
sender := thisContext sender. |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4356 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4357 |
^ 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
|
4358 |
in:sender. |
5755 | 4359 |
|
6005 | 4360 |
" |
4361 |
1234 primitiveFailed |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4362 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4363 |
[ |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4364 |
ExternalBytes new basicAt:40 |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4365 |
] on:PrimitiveFailure do:[:ex| |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4366 |
ex inspect |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4367 |
] |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4368 |
" |
5755 | 4369 |
! |
4370 |
||
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4371 |
primitiveFailed:messageString |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4372 |
"{ Pragma: +optSpace }" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4373 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4374 |
"report an error that some primitive code failed. |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4375 |
The error is reported by raising the PrimitiveFailureSignal exception." |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4376 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4377 |
|sender| |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4378 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4379 |
sender := thisContext sender. |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4380 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4381 |
^ PrimitiveFailure raiseRequestWith:(Message selector:sender selector arguments:sender args) |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4382 |
errorString:messageString |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4383 |
in:sender. |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4384 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4385 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4386 |
1234 primitiveFailed:'this is a test' |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4387 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4388 |
! |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4389 |
|
6815 | 4390 |
shouldImplement |
4391 |
"{ Pragma: +optSpace }" |
|
4392 |
||
4393 |
"report an error that this message should be implemented. |
|
4394 |
This is send by automatically generated method bodies" |
|
4395 |
||
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4396 |
|sender| |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4397 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4398 |
sender := thisContext sender. |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4399 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4400 |
^ UnimplementedFunctionalityError raiseRequestWith:(Message selector:sender selector arguments:sender args) |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4401 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4402 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4403 |
" |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4404 |
self shouldImplement |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4405 |
" |
6815 | 4406 |
! |
4407 |
||
5755 | 4408 |
shouldNotImplement |
4409 |
"{ Pragma: +optSpace }" |
|
4410 |
||
4411 |
"report an error that this message should not be implemented" |
|
4412 |
||
8729 | 4413 |
^ self error:'method/functionality not appropriate for this class' |
5755 | 4414 |
|
4415 |
"Modified: 8.5.1996 / 09:09:44 / cg" |
|
4416 |
! |
|
4417 |
||
4418 |
subclassResponsibility |
|
4419 |
"{ Pragma: +optSpace }" |
|
4420 |
||
4421 |
"report an error that this message should have been reimplemented in a |
|
4422 |
subclass" |
|
4423 |
||
7334 | 4424 |
^ SubclassResponsibilityError raiseRequest |
5755 | 4425 |
! |
4426 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4427 |
subclassResponsibility:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4428 |
"{ Pragma: +optSpace }" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4429 |
|
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4430 |
"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
|
4431 |
|
7334 | 4432 |
^ SubclassResponsibilityError raiseRequestErrorString:msg |
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4433 |
! |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4434 |
|
5755 | 4435 |
subscriptBoundsError |
4436 |
"{ Pragma: +optSpace }" |
|
4437 |
||
4438 |
"report an error that some index is out of bounds. |
|
4439 |
(when accessing indexable collections). |
|
4440 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4441 |
||
4442 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:nil |
|
4443 |
||
4444 |
"Modified: / 26.7.1996 / 16:45:42 / cg" |
|
4445 |
"Modified: / 26.7.1999 / 10:58:27 / stefan" |
|
4446 |
! |
|
4447 |
||
4448 |
subscriptBoundsError:anIndex |
|
4449 |
"{ Pragma: +optSpace }" |
|
4450 |
||
4451 |
"report an error that anIndex is out of bounds. |
|
4452 |
(when accessing indexable collections). |
|
4453 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4454 |
||
6221 | 4455 |
^ SubscriptOutOfBoundsError |
6654 | 4456 |
raiseRequestWith:anIndex |
4457 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
5755 | 4458 |
|
6221 | 4459 |
"Modified: / 17.11.2001 / 22:49:56 / cg" |
5755 | 4460 |
! |
4461 |
||
4462 |
typeCheckError |
|
4463 |
"{ Pragma: +optSpace }" |
|
4464 |
||
4465 |
"generated when a variable declared with a type hint gets a bad |
|
4466 |
value assigned" |
|
4467 |
||
4468 |
^ self error:'bad assign of ' , self printString , |
|
6654 | 4469 |
' (' , self class name , ') to typed variable' |
5755 | 4470 |
! ! |
4471 |
||
4472 |
!Object methodsFor:'evaluation'! |
|
4473 |
||
8690
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4474 |
argumentCount |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4475 |
"compatibility with Blocks and Messages. |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4476 |
Answer 0, since we only understand #value. |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4477 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4478 |
By implementing this, you can pass any object as an exception handler." |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4479 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4480 |
^ 0 |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4481 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4482 |
" |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4483 |
[1 // 0] on:ArithmeticError do:9999 |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4484 |
" |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4485 |
! |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4486 |
|
5755 | 4487 |
value |
4488 |
"return the receiver itself. |
|
4489 |
This allows every object to be used where blocks or valueHolders |
|
4490 |
are typically used, and allows for valueHolders and blocks to be |
|
4491 |
used interchangably in some situations. |
|
4492 |
||
4493 |
Time will show, if this is a good idea or leads to sloppy programming |
|
4494 |
style ... (the idea was borrowed from the Self language). |
|
4495 |
||
4496 |
WARNING: dont 'optimize' away ifXXX: blocks |
|
6654 | 4497 |
(i.e. do NOT replace |
4498 |
foo ifTrue:[var1] ifFalse:[var2] |
|
4499 |
by: |
|
4500 |
foo ifTrue:var1 ifFalse:var2 |
|
4501 |
) |
|
4502 |
- the compilers will only generate inline code for the if, |
|
4503 |
iff the argument(s) are blocks - otherwise, a true send is |
|
4504 |
generated. |
|
4505 |
This 'oprimization' will work semantically correct, |
|
4506 |
but execute SLOWER instead." |
|
5755 | 4507 |
|
4508 |
^ self |
|
4509 |
||
4510 |
" |
|
4511 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
|
4512 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
4513 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
4514 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
4515 |
" |
|
4516 |
||
4517 |
"DO NOT DO THIS (its slower) |
|
7458 | 4518 |
(1 > 4) ifTrue:a ifFalse:b |
5755 | 4519 |
|
4520 |
USE (the compiler optimizes blocks in if/while): |
|
7458 | 4521 |
(1 > 4) ifTrue:[a] ifFalse:[b] |
5755 | 4522 |
" |
4523 |
||
4524 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
4525 |
! ! |
|
4526 |
||
4527 |
!Object methodsFor:'finalization'! |
|
4528 |
||
4529 |
disposed |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4530 |
"OBSOLETE INTERFACE: use #finalize |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4531 |
this is invoked for objects which have been registered |
5755 | 4532 |
in a Registry, when the original object dies. |
4533 |
Subclasses may redefine this method" |
|
4534 |
||
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4535 |
<resource: #obsolete> |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4536 |
|
5755 | 4537 |
^ self |
4538 |
! |
|
4539 |
||
4540 |
executor |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4541 |
"Return the object which does the finalization for me. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4542 |
This interface is also VW & Sqeak compatible," |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4543 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4544 |
"for now, send #shallowCopyForFinalization, to be compatible with |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4545 |
classes designed for old ST/X versions" |
5755 | 4546 |
|
4547 |
^ self shallowCopyForFinalization |
|
4548 |
! |
|
4549 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4550 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4551 |
"answer a Registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4552 |
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
|
4553 |
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
|
4554 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4555 |
^ FinalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4556 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4557 |
|
5755 | 4558 |
finalize |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4559 |
"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
|
4560 |
in a Registry, when the original object dies. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4561 |
Subclasses may redefine this method |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4562 |
This interface is also VW-compatible" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4563 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4564 |
"send #disposed for compatibility with existing classes that still |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4565 |
implement the obsolete #disposed message" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4566 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4567 |
^ self disposed |
5755 | 4568 |
! |
4569 |
||
4570 |
reRegisterForFinalization |
|
4571 |
"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
|
4572 |
This will create a new executor, which will receive a #finalize message when |
5755 | 4573 |
the receiver is garbage collected." |
4574 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4575 |
self finalizationLobby registerChange:self |
5755 | 4576 |
! |
4577 |
||
4578 |
registerForFinalization |
|
4579 |
"register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4580 |
Once registered, the executor of the receiver will receive a #finalize message when |
5755 | 4581 |
the receiver is garbage collected." |
4582 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4583 |
self finalizationLobby register:self |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4584 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4585 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4586 |
shallowCopyForFinalization |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4587 |
"OBSOLETE INTERFACE: use #executor. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4588 |
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
|
4589 |
(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
|
4590 |
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
|
4591 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4592 |
<resource: #obsolete> |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4593 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4594 |
^ self shallowCopy |
5755 | 4595 |
! |
4596 |
||
4597 |
unregisterForFinalization |
|
4598 |
"unregister mySelf from later finalization" |
|
4599 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4600 |
self finalizationLobby unregister:self |
5755 | 4601 |
! ! |
4602 |
||
4603 |
!Object methodsFor:'initialization'! |
|
4604 |
||
4605 |
initialize |
|
4606 |
"just to ignore initialize to objects which do not need it" |
|
4607 |
||
4608 |
^ self |
|
4609 |
! ! |
|
4610 |
||
4611 |
!Object methodsFor:'interrupt handling'! |
|
4612 |
||
4613 |
childSignalInterrupt |
|
4614 |
"death of a child process (unix process) - do nothing" |
|
4615 |
||
4616 |
^ self |
|
4617 |
! |
|
4618 |
||
4619 |
customInterrupt |
|
4620 |
"{ Pragma: +optSpace }" |
|
4621 |
||
4622 |
"a custom interrupt - but no handler has defined" |
|
4623 |
||
4624 |
self error:'custom interrupt' mayProceed:true |
|
4625 |
! |
|
4626 |
||
4627 |
errorInterrupt:errorID with:aParameter |
|
4628 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
4629 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
|
4630 |
which can be called from C subsystems to raise an (asynchronous) |
|
4631 |
error exception. |
|
4632 |
||
4633 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
4634 |
used from other C subsystems too, to upcast errors. |
|
4635 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
4636 |
IDs (currently) used: |
|
6654 | 4637 |
#DisplayError ..... x-error interrupt |
4638 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
5755 | 4639 |
" |
4640 |
||
6263
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4641 |
|handlers handler| |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4642 |
|
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4643 |
handlers := ObjectMemory registeredErrorInterruptHandlers. |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4644 |
handlers notNil ifTrue:[ |
6654 | 4645 |
handler := handlers at:errorID ifAbsent:nil. |
4646 |
handler notNil ifTrue:[ |
|
4647 |
"/ |
|
4648 |
"/ handler found; let it do whatever it wants ... |
|
4649 |
"/ |
|
4650 |
handler errorInterrupt:errorID with:aParameter. |
|
4651 |
^ self |
|
4652 |
]. |
|
5755 | 4653 |
]. |
4654 |
||
4655 |
"/ |
|
4656 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
4657 |
"/ |
|
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
4658 |
^ Error |
6654 | 4659 |
raiseRequestWith:errorID |
4660 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
5755 | 4661 |
! |
4662 |
||
4663 |
exceptionInterrupt |
|
4664 |
"{ Pragma: +optSpace }" |
|
4665 |
||
4666 |
"exception interrupt - enter debugger" |
|
4667 |
||
4668 |
self error:'exception Interrupt' mayProceed:true |
|
4669 |
! |
|
4670 |
||
4671 |
fpExceptionInterrupt |
|
4672 |
"{ Pragma: +optSpace }" |
|
4673 |
||
4674 |
"a floating point exception occured - this one |
|
4675 |
has to be handled differently since it comes asynchronous |
|
4676 |
on some machines (for example, on machines with a separate FPU |
|
4677 |
or superscalar architectures. Also, errors from within primitive code |
|
4678 |
(or library functions such as GL) are sent via the Unix-signal |
|
4679 |
mechanism this way." |
|
4680 |
||
4681 |
|where rec| |
|
4682 |
||
4683 |
where := thisContext sender. |
|
4684 |
rec := where receiver. |
|
4685 |
rec isNumber ifTrue:[ |
|
6654 | 4686 |
^ rec class |
4687 |
raise:#domainErrorSignal |
|
4688 |
receiver:rec |
|
4689 |
selector:where selector |
|
4690 |
arguments:(where args asArray) |
|
4691 |
errorString:'floating point exception' |
|
5755 | 4692 |
]. |
4693 |
||
4694 |
"/ could be in some C-library ... |
|
7402 | 4695 |
^ DomainError raise |
5755 | 4696 |
! |
4697 |
||
4698 |
internalError:msg |
|
4699 |
"{ Pragma: +optSpace }" |
|
4700 |
||
4701 |
"this is triggered, when VM hits some bad error, |
|
4702 |
such as corrupted class, corrupted method/selector array |
|
4703 |
etc. The argument string gives some more information on what happened. |
|
4704 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
|
4705 |
Its not guaranteed, that the system is in a working condition once |
|
4706 |
this error occurred ...." |
|
4707 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4708 |
VMInternalError raiseWith:self errorString:msg |
5755 | 4709 |
! |
4710 |
||
4711 |
ioInterrupt |
|
4712 |
"{ Pragma: +optSpace }" |
|
4713 |
||
4714 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
|
4715 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
4716 |
or it does not understand the ioInterrupt message. |
|
4717 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
4718 |
||
4719 |
self error:'I/O Interrupt - but no handler' mayProceed:true |
|
4720 |
! |
|
4721 |
||
4722 |
memoryInterrupt |
|
4723 |
"{ Pragma: +optSpace }" |
|
4724 |
||
4725 |
"out-of-memory interrupt and no handler - enter debugger" |
|
4726 |
||
4727 |
self error:'almost out of memory' mayProceed:true |
|
4728 |
! |
|
4729 |
||
4730 |
recursionInterrupt |
|
4731 |
"{ Pragma: +optSpace }" |
|
4732 |
||
4733 |
"recursion limit (actually: stack overflow) interrupt. |
|
4734 |
This interrupt is triggered, when a process stack grows above |
|
4735 |
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
|
4736 |
could be caught. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4737 |
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
|
4738 |
and the exception can be resumed. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4739 |
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
|
4740 |
is not proceedable. |
5755 | 4741 |
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
|
4742 |
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
|
4743 |
or debug for a while. |
5755 | 4744 |
If the signal is ignored, and the stack continues to grow, there |
4745 |
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
|
4746 |
terminates the process." |
5755 | 4747 |
|
7838
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4748 |
|con remaining sender nSkipped| |
5755 | 4749 |
|
4750 |
(con := thisContext) isRecursive ifFalse:[ |
|
4751 |
"/ Processor activeProcess usedStackSize < Processor activeProcess maximumStackSize ifTrue:[ |
|
4752 |
"/ "/ mhmh - it hit me, but I am not responsible ... |
|
4753 |
"/ 'Stray recursionInterrupt ...' infoPrintCR. |
|
4754 |
"/ ^ self |
|
4755 |
"/ ]. |
|
6654 | 4756 |
ObjectMemory infoPrinting ifTrue:[ |
4757 |
'Object [info]: recursionInterrupt from:' printCR. |
|
4758 |
con := con sender. |
|
4759 |
remaining := 50. |
|
4760 |
[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
|
4761 |
sender := con sender. |
6654 | 4762 |
'| ' print. con fullPrint. |
7838
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4763 |
|
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4764 |
nSkipped := 0. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4765 |
[sender notNil and:[sender sender notNil |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4766 |
and:[sender selector == con selector |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4767 |
and:[sender sender selector == con selector |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4768 |
and:[sender method == con method]]]]] whileTrue:[ |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4769 |
nSkipped := nSkipped + 1. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4770 |
con := sender. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4771 |
sender := con sender. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4772 |
]. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4773 |
nSkipped > 0 ifTrue:[ |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4774 |
'| ... ***** ' 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
|
4775 |
]. |
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4776 |
con := sender. |
6654 | 4777 |
remaining := remaining - 1 |
4778 |
]. |
|
4779 |
]. |
|
4780 |
^ RecursionInterruptSignal raiseSignal |
|
5755 | 4781 |
] |
4782 |
||
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4783 |
"Modified: / 10.11.2001 / 15:15:56 / cg" |
5755 | 4784 |
! |
4785 |
||
4786 |
schedulerInterrupt |
|
4787 |
"{ Pragma: +optSpace }" |
|
4788 |
||
4789 |
"scheduler interrupt (supposed to be sent to Processor). |
|
4790 |
If we arrive here, either the Processor does not understand it, |
|
4791 |
or it has been set to nil. In any case, this is a sign of some |
|
4792 |
big trouble. Enter debugger." |
|
4793 |
||
4794 |
self error:'schedulerInterrupt - but no Processor' mayProceed:true |
|
4795 |
! |
|
4796 |
||
4797 |
signalInterrupt:signalNumber |
|
4798 |
"{ Pragma: +optSpace }" |
|
4799 |
||
4800 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
|
4801 |
(SIGPIPE), others (SIGBUS) are rather fatal ... |
|
4802 |
In any case, IF a smalltalk-signal has been connected to the OS signal, |
|
4803 |
that one is raised. |
|
4804 |
Otherwise, a dialog is shown, asking the user on how to handle the |
|
4805 |
signal. |
|
4806 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
|
4807 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
4808 |
Currently (temporary kludge), these are passed as global variables." |
|
4809 |
||
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4810 |
|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
|
4811 |
action title screen| |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4812 |
|
5755 | 4813 |
"if there has been an ST-signal installed, use it ..." |
4814 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
4815 |
sig notNil ifTrue:[ |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4816 |
sig raiseSignalWith:signalNumber. |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4817 |
^ self. |
5755 | 4818 |
]. |
4819 |
||
4820 |
"/ if handled, raise OSSignalInterruptSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4821 |
OSSignalInterrupt isHandled ifTrue:[ |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4822 |
OSSignalInterrupt raiseRequestWith:signalNumber. |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4823 |
^ self. |
5755 | 4824 |
]. |
4825 |
||
4826 |
" |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4827 |
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
|
4828 |
- SIGHUP: hang up - write a crash image and exit |
7031 | 4829 |
" |
4830 |
signalNumber == 30 "OperatingSystem sigPWR" ifTrue:[ |
|
8806
03e74cded971
Make snapshot writing more robust against errors.
Stefan Vogel <sv@exept.de>
parents:
8798
diff
changeset
|
4831 |
[ObjectMemory snapShotOn:'crash.img'] on:SnapshotError do:[:ex| ]. |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4832 |
^ self. |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4833 |
]. |
7031 | 4834 |
(signalNumber == 1 "OperatingSystem sigHUP") ifTrue:[ |
8806
03e74cded971
Make snapshot writing more robust against errors.
Stefan Vogel <sv@exept.de>
parents:
8798
diff
changeset
|
4835 |
[ObjectMemory snapShotOn:'crash.img'] on:SnapshotError do:[:ex| ]. |
03e74cded971
Make snapshot writing more robust against errors.
Stefan Vogel <sv@exept.de>
parents:
8798
diff
changeset
|
4836 |
Smalltalk exit:1. |
7031 | 4837 |
]. |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4838 |
|
5755 | 4839 |
name := OperatingSystem nameForSignal:signalNumber. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4840 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4841 |
"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
|
4842 |
(Screen isNil |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4843 |
or:[(screen := Screen current) isNil |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
4844 |
or:[(screen := Screen default) isNil |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
4845 |
or:[screen isOpen not]]]) ifTrue:[ |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4846 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4847 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4848 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4849 |
"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
|
4850 |
otherwise display stays locked" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4851 |
screen ungrabPointer; ungrabKeyboard. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4852 |
|
7031 | 4853 |
here := thisContext. |
4854 |
badContext := here sender. "the context, in which the signal occurred" |
|
4855 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4856 |
"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
|
4857 |
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
|
4858 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4859 |
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
|
4860 |
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
|
4861 |
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
|
4862 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4863 |
fatal := OperatingSystem isFatalSignal:signalNumber. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4864 |
fatal ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4865 |
(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
|
4866 |
'Object [hard error]: signal ' errorPrint. signalNumber errorPrintCR. |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4867 |
^ 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
|
4868 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4869 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4870 |
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
|
4871 |
" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4872 |
msg := 'OS-signal: ', name. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4873 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4874 |
"/ 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
|
4875 |
"/ 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
|
4876 |
"/ 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
|
4877 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4878 |
InterruptPcLow notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4879 |
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
|
4880 |
pc ~~ 0 ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4881 |
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
|
4882 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4883 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4884 |
InterruptAddrLow notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4885 |
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
|
4886 |
addr ~~ 0 ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4887 |
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
|
4888 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4889 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4890 |
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
|
4891 |
"unreachable" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4892 |
^ nil. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4893 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4894 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4895 |
"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
|
4896 |
Otherwise, start a debugger" |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4897 |
Dialog notNil ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4898 |
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
|
4899 |
actions := #(save core exit debug). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4900 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4901 |
action := nil. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4902 |
title := 'OS Signal caught (' , name, ')'. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4903 |
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
|
4904 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4905 |
"/ 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
|
4906 |
"/ 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
|
4907 |
"/ (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
|
4908 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4909 |
Processor activeProcess isSystemProcess ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4910 |
titles := #('abort') , titles. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4911 |
actions := #(abort), actions. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4912 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4913 |
badContext canReturn ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4914 |
titles := #('return') , titles. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4915 |
actions := #(return), actions. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4916 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4917 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4918 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4919 |
fatal ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4920 |
titles := titles, #('ignore'). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4921 |
actions := actions , #(ignore). |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4922 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4923 |
action := Dialog choose:title |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4924 |
labels:titles |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4925 |
values:actions |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4926 |
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
|
4927 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4928 |
"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
|
4929 |
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
|
4930 |
] ifFalse:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4931 |
action := #debug. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4932 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4933 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4934 |
action == #save ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4935 |
ObjectMemory snapShotOn:'crash.img' |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4936 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4937 |
action == #core ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4938 |
Smalltalk fatalAbort |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4939 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4940 |
action == #exit ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4941 |
Smalltalk exit |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4942 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4943 |
action == #return ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4944 |
badContext return |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4945 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4946 |
action == #abort ifTrue:[ |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4947 |
AbortOperationRequest raise. |
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4948 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4949 |
|
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4950 |
action == #debug ifTrue:[ |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4951 |
Debugger isNil ifTrue:[ |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4952 |
^ 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
|
4953 |
]. |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4954 |
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
|
4955 |
]. |
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4956 |
"action == #ignore" |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4957 |
]. |
5755 | 4958 |
! |
4959 |
||
4960 |
spyInterrupt |
|
4961 |
"{ Pragma: +optSpace }" |
|
4962 |
||
4963 |
"spy interrupt and no handler - enter debugger" |
|
4964 |
||
4965 |
self error:'spy Interrupt - but no handler' mayProceed:true |
|
4966 |
! |
|
4967 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4968 |
startMiniDebuggerOrExit:text |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4969 |
"some critical condition happened. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4970 |
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
|
4971 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4972 |
MiniDebugger isNil ifTrue:[ |
6654 | 4973 |
"a system without debugging facilities (i.e. a standalone system) |
4974 |
output a message and exit." |
|
4975 |
('Object [error]: exit due to ', text, ' - and no debugger.') errorPrintCR. |
|
4976 |
OperatingSystem exit:99. |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4977 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4978 |
MiniDebugger enterWithMessage:text mayProceed:true. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4979 |
! |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4980 |
|
5755 | 4981 |
timerInterrupt |
4982 |
"{ Pragma: +optSpace }" |
|
4983 |
||
4984 |
"timer interrupt and no handler - enter debugger" |
|
4985 |
||
4986 |
self error:'timer Interrupt - but no handler' mayProceed:true |
|
4987 |
! |
|
4988 |
||
4989 |
userInterrupt |
|
4990 |
"{ Pragma: +optSpace }" |
|
4991 |
||
4992 |
"user (^c) interrupt. |
|
4993 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
4994 |
controlling tty (i.e. in the xterm)." |
|
4995 |
||
6466 | 4996 |
UserInterruptSignal raiseRequest |
5755 | 4997 |
! |
4998 |
||
4999 |
userInterruptIn:aContext |
|
5000 |
"{ Pragma: +optSpace }" |
|
5001 |
||
5002 |
"user (^c) interrupt - enter debugger, but show aContext |
|
5003 |
as top-context. |
|
5004 |
This is used to hide any intermediate scheduler contexts, |
|
5005 |
in case of an interrupted process. Typically, this is sent by |
|
5006 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
5007 |
processed." |
|
5008 |
||
5009 |
<context: #return> |
|
5010 |
||
5011 |
UserInterruptSignal raiseRequestWith:nil errorString:nil in:aContext |
|
5012 |
||
5013 |
"Created: / 18.10.1996 / 20:46:04 / cg" |
|
5014 |
"Modified: / 20.10.1996 / 13:06:38 / cg" |
|
5015 |
"Modified: / 26.7.1999 / 10:58:49 / stefan" |
|
5016 |
! ! |
|
5017 |
||
5018 |
!Object methodsFor:'message sending'! |
|
5019 |
||
5020 |
perform:aSelector |
|
5021 |
"send the message aSelector to the receiver" |
|
5022 |
||
5023 |
%{ |
|
5024 |
REGISTER OBJ sel = aSelector; |
|
5025 |
||
5026 |
if (InterruptPending == nil) { |
|
6654 | 5027 |
struct inlineCache *pIlc; |
5028 |
static struct inlineCache ilc_0 = __ILCPERF0(@line); |
|
5029 |
static struct inlineCache ilc_1 = __ILCPERF0(@line); |
|
5030 |
static struct inlineCache ilc_2 = __ILCPERF0(@line); |
|
5031 |
static struct inlineCache ilc_3 = __ILCPERF0(@line); |
|
5032 |
static struct inlineCache ilc_4 = __ILCPERF0(@line); |
|
5033 |
static OBJ last_0 = nil; |
|
5034 |
static OBJ last_1 = nil; |
|
5035 |
static OBJ last_2 = nil; |
|
5036 |
static OBJ last_3 = nil; |
|
5037 |
static OBJ last_4 = nil; |
|
5038 |
static flip = 0; |
|
5039 |
||
5040 |
if (sel == last_0) { |
|
5041 |
pIlc = &ilc_0; |
|
5042 |
} else if (sel == last_1) { |
|
5043 |
pIlc = &ilc_1; |
|
5044 |
} else if (sel == last_2) { |
|
5045 |
pIlc = &ilc_2; |
|
5046 |
} else if (sel == last_3) { |
|
5047 |
pIlc = &ilc_3; |
|
5048 |
} else if (sel == last_4) { |
|
5049 |
pIlc = &ilc_4; |
|
5050 |
} else { |
|
5051 |
if (flip == 0) { |
|
5052 |
pIlc = &ilc_0; |
|
5053 |
flip = 1; |
|
5054 |
last_0 = sel; |
|
5055 |
} else if (flip == 1) { |
|
5056 |
pIlc = &ilc_1; |
|
5057 |
flip = 2; |
|
5058 |
last_1 = sel; |
|
5059 |
} else if (flip == 2) { |
|
5060 |
pIlc = &ilc_2; |
|
5061 |
flip = 3; |
|
5062 |
last_2 = sel; |
|
5063 |
} else if (flip == 3) { |
|
5064 |
pIlc = &ilc_3; |
|
5065 |
flip = 4; |
|
5066 |
last_3 = sel; |
|
5067 |
} else { |
|
5068 |
pIlc = &ilc_4; |
|
5069 |
flip = 0; |
|
5070 |
last_4 = sel; |
|
5071 |
} |
|
5072 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5073 |
if (pIlc->ilc_poly) { |
|
5074 |
__flushPolyCache(pIlc->ilc_poly); |
|
5075 |
pIlc->ilc_poly = 0; |
|
5076 |
} |
|
5077 |
} |
|
5078 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
|
5755 | 5079 |
} else { |
6654 | 5080 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
5081 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5755 | 5082 |
} |
5083 |
%}. |
|
5084 |
^ self perform:aSelector withArguments:#() |
|
5085 |
! |
|
5086 |
||
5087 |
perform:aSelector inClass:aClass withArguments:argArray |
|
5088 |
"send the message aSelector with all args taken from argArray |
|
5089 |
to the receiver as a super-send message. |
|
5090 |
This is actually more flexible than the normal super-send, since it allows |
|
5091 |
to execute a method in ANY superclass of the receiver (not just the |
|
5092 |
immediate superclass). |
|
5093 |
Thus, it is (theoretically) possible to do |
|
6654 | 5094 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
5755 | 5095 |
and evaluate Magnitudes compare method even if there was one in Number. |
5096 |
This method is used by the interpreter to evaluate super sends |
|
5097 |
and could be used for very special behavior (language extension ?). |
|
5098 |
||
5099 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
5100 |
||
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5101 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 myClass| |
5755 | 5102 |
|
5103 |
" |
|
5104 |
check, if aClass is really a superclass of the receiver |
|
5105 |
" |
|
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5106 |
myClass := self class. |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5107 |
(myClass == aClass or:[myClass isSubclassOf:aClass]) ifFalse:[ |
6654 | 5108 |
self error:'lookup-class argument is not a superclass of the receiver'. |
5109 |
^ nil |
|
5755 | 5110 |
]. |
5111 |
%{ |
|
5112 |
REGISTER OBJ *argP; |
|
5113 |
int nargs, i; |
|
5114 |
||
8934 | 5115 |
if (__isArrayLike(argArray)) { |
6654 | 5116 |
nargs = __arraySize(argArray); |
5117 |
argP = __arrayVal(argArray); |
|
5755 | 5118 |
} else { |
6654 | 5119 |
if (__isNonNilObject(argArray)) { |
5120 |
static struct inlineCache ilcSize = __ILC0(@line+1); |
|
5121 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5122 |
if (!__isSmallInteger(numberOfArgs)) |
|
5123 |
goto bad; |
|
5124 |
nargs = __intVal(numberOfArgs); |
|
5125 |
argP = (OBJ *)(&a1); |
|
5126 |
for (i=1; i <= nargs; i++) { |
|
8913 | 5127 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
6654 | 5128 |
} |
5129 |
argP = (OBJ *)(&a1); |
|
5130 |
} else { |
|
5131 |
nargs = 0; |
|
5132 |
} |
|
5755 | 5133 |
} |
5134 |
switch (nargs) { |
|
6654 | 5135 |
case 0: |
5136 |
{ |
|
5137 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5138 |
RETURN ( _SEND0(self, aSelector, aClass, &ilc0)); |
|
5139 |
} |
|
5140 |
||
5141 |
case 1: |
|
5142 |
{ |
|
5143 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5144 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, argP[0])); |
|
5145 |
} |
|
5146 |
||
5147 |
case 2: |
|
5148 |
{ |
|
5149 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5150 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, argP[0], argP[1])); |
|
5151 |
} |
|
5152 |
||
5153 |
case 3: |
|
5154 |
{ |
|
5155 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5156 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, |
|
5157 |
argP[0], argP[1], argP[2])); |
|
5158 |
} |
|
5159 |
||
5160 |
case 4: |
|
5161 |
{ |
|
5162 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
5163 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, |
|
5164 |
argP[0], argP[1], argP[2], argP[3])); |
|
5165 |
} |
|
5166 |
||
5167 |
case 5: |
|
5168 |
{ |
|
5169 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
5170 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
5171 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5172 |
} |
|
5173 |
||
5174 |
case 6: |
|
5175 |
{ |
|
5176 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
5177 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
5178 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5])); |
|
5179 |
} |
|
5180 |
||
5181 |
case 7: |
|
5182 |
{ |
|
5183 |
static struct inlineCache ilc7 = __DUMMYILCSELF7(@line+1); |
|
5184 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
5185 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5186 |
argP[6])); |
|
5187 |
} |
|
5188 |
||
5189 |
case 8: |
|
5190 |
{ |
|
5191 |
static struct inlineCache ilc8 = __DUMMYILCSELF8(@line+1); |
|
5192 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
5193 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5194 |
argP[6], argP[7])); |
|
5195 |
} |
|
5196 |
||
5197 |
case 9: |
|
5198 |
{ |
|
5199 |
static struct inlineCache ilc9 = __DUMMYILCSELF9(@line+1); |
|
5200 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
5201 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5202 |
argP[6], argP[7], argP[8])); |
|
5203 |
} |
|
5204 |
||
5205 |
case 10: |
|
5206 |
{ |
|
5207 |
static struct inlineCache ilc10 = __DUMMYILCSELF10(@line+1); |
|
5208 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
5209 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5210 |
argP[6], argP[7], argP[8], argP[9])); |
|
5211 |
} |
|
5212 |
||
5213 |
case 11: |
|
5214 |
{ |
|
5215 |
static struct inlineCache ilc11 = __DUMMYILCSELF11(@line+1); |
|
5216 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
5217 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5218 |
argP[6], argP[7], argP[8], argP[9], argP[10])); |
|
5219 |
} |
|
5220 |
||
5221 |
case 12: |
|
5222 |
{ |
|
5223 |
static struct inlineCache ilc12 = __DUMMYILCSELF12(@line+1); |
|
5224 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
5225 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5226 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5227 |
argP[11])); |
|
5228 |
} |
|
5229 |
||
5230 |
case 13: |
|
5231 |
{ |
|
5232 |
static struct inlineCache ilc13 = __DUMMYILCSELF13(@line+1); |
|
5233 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
5234 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5235 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5236 |
argP[11], argP[12])); |
|
5237 |
} |
|
5238 |
||
5239 |
case 14: |
|
5240 |
{ |
|
5241 |
static struct inlineCache ilc14 = __DUMMYILCSELF14(@line+1); |
|
5242 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
5243 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5244 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5245 |
argP[11], argP[12], argP[13])); |
|
5246 |
} |
|
5247 |
||
5248 |
case 15: |
|
5249 |
{ |
|
5250 |
static struct inlineCache ilc15 = __DUMMYILCSELF15(@line+1); |
|
5251 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
5252 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5253 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5254 |
argP[11], argP[12], argP[13], argP[14])); |
|
5255 |
} |
|
5755 | 5256 |
|
5257 |
#ifdef _SEND16 |
|
6654 | 5258 |
case 16: |
5259 |
{ |
|
5260 |
static struct inlineCache ilc16 = __DUMMYILCSELF16(@line+1); |
|
5261 |
RETURN ( _SEND16(self, aSelector, aClass, &ilc15, |
|
5262 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5263 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5264 |
argP[11], argP[12], argP[13], argP[14], argP[15])); |
|
5265 |
} |
|
5755 | 5266 |
#endif |
5267 |
#ifdef _SEND17 |
|
6654 | 5268 |
case 17: |
5269 |
{ |
|
5270 |
static struct inlineCache ilc17 = __DUMMYILCSELF17(@line+1); |
|
5271 |
RETURN ( _SEND17(self, aSelector, aClass, &ilc15, |
|
5272 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5273 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5274 |
argP[11], argP[12], argP[13], argP[14], argP[15], argP[16])); |
|
5275 |
} |
|
5755 | 5276 |
#endif |
5277 |
||
5278 |
||
5279 |
} |
|
5280 |
bad:; |
|
5281 |
%}. |
|
5282 |
"/ arrive here, if bad number of arguments (too many) |
|
5283 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5284 |
||
5285 |
^ self primitiveFailed |
|
5286 |
! |
|
5287 |
||
5288 |
perform:aSelector with:arg |
|
5289 |
"send the one-arg-message aSelector to the receiver" |
|
5290 |
||
5291 |
%{ |
|
5292 |
REGISTER OBJ sel = aSelector; |
|
5293 |
||
5294 |
if (InterruptPending == nil) { |
|
6654 | 5295 |
struct inlineCache *pIlc; |
5296 |
static struct inlineCache ilc_0 = __ILCPERF1(@line); |
|
5297 |
static struct inlineCache ilc_1 = __ILCPERF1(@line); |
|
5298 |
static struct inlineCache ilc_2 = __ILCPERF1(@line); |
|
5299 |
static struct inlineCache ilc_3 = __ILCPERF1(@line); |
|
5300 |
static struct inlineCache ilc_4 = __ILCPERF1(@line); |
|
5301 |
static OBJ last_0 = nil; |
|
5302 |
static OBJ last_1 = nil; |
|
5303 |
static OBJ last_2 = nil; |
|
5304 |
static OBJ last_3 = nil; |
|
5305 |
static OBJ last_4 = nil; |
|
5306 |
static flip = 0; |
|
5307 |
||
5308 |
if (sel == last_0) { |
|
5309 |
pIlc = &ilc_0; |
|
5310 |
} else if (sel == last_1) { |
|
5311 |
pIlc = &ilc_1; |
|
5312 |
} else if (sel == last_2) { |
|
5313 |
pIlc = &ilc_2; |
|
5314 |
} else if (sel == last_3) { |
|
5315 |
pIlc = &ilc_3; |
|
5316 |
} else if (sel == last_4) { |
|
5317 |
pIlc = &ilc_4; |
|
5318 |
} else { |
|
5319 |
if (flip == 0) { |
|
5320 |
pIlc = &ilc_0; |
|
5321 |
flip = 1; |
|
5322 |
last_0 = sel; |
|
5323 |
} else if (flip == 1) { |
|
5324 |
pIlc = &ilc_1; |
|
5325 |
flip = 2; |
|
5326 |
last_1 = sel; |
|
5327 |
} else if (flip == 2) { |
|
5328 |
pIlc = &ilc_2; |
|
5329 |
flip = 3; |
|
5330 |
last_2 = sel; |
|
5331 |
} else if (flip == 3) { |
|
5332 |
pIlc = &ilc_3; |
|
5333 |
flip = 4; |
|
5334 |
last_3 = sel; |
|
5335 |
} else { |
|
5336 |
pIlc = &ilc_4; |
|
5337 |
flip = 0; |
|
5338 |
last_4 = sel; |
|
5339 |
} |
|
5340 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5341 |
if (pIlc->ilc_poly) { |
|
5342 |
__flushPolyCache(pIlc->ilc_poly); |
|
5343 |
pIlc->ilc_poly = 0; |
|
5344 |
} |
|
5345 |
} |
|
5346 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
|
5755 | 5347 |
} else { |
6654 | 5348 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
5349 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
5755 | 5350 |
} |
5351 |
%}. |
|
5352 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5353 |
||
5354 |
! |
|
5355 |
||
5356 |
perform:aSelector with:arg1 with:arg2 |
|
5357 |
"send the two-arg-message aSelector to the receiver" |
|
5358 |
||
5359 |
%{ |
|
5360 |
struct inlineCache *pIlc; |
|
5361 |
||
5362 |
if (InterruptPending == nil) { |
|
6654 | 5363 |
static struct inlineCache ilc_0 = __ILCPERF2(@line); |
5364 |
static struct inlineCache ilc_1 = __ILCPERF2(@line); |
|
5365 |
static OBJ last_0 = nil; |
|
5366 |
static OBJ last_1 = nil; |
|
5367 |
static flip = 0; |
|
5368 |
||
5369 |
if (aSelector == last_0) { |
|
5370 |
pIlc = &ilc_0; |
|
5371 |
} else if (aSelector == last_1) { |
|
5372 |
pIlc = &ilc_1; |
|
5373 |
} else { |
|
5374 |
if (flip == 0) { |
|
5375 |
pIlc = &ilc_0; |
|
5376 |
flip = 1; |
|
5377 |
last_0 = aSelector; |
|
5378 |
} else { |
|
5379 |
pIlc = &ilc_1; |
|
5380 |
flip = 0; |
|
5381 |
last_1 = aSelector; |
|
5382 |
} |
|
5383 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5384 |
if (pIlc->ilc_poly) { |
|
5385 |
__flushPolyCache(pIlc->ilc_poly); |
|
5386 |
pIlc->ilc_poly = 0; |
|
5387 |
} |
|
5388 |
} |
|
5389 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
|
5755 | 5390 |
} else { |
6654 | 5391 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
5392 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, arg1, arg2)); |
|
5755 | 5393 |
} |
5394 |
%}. |
|
5395 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2) |
|
5396 |
||
5397 |
! |
|
5398 |
||
5399 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
|
5400 |
"send the three-arg-message aSelector to the receiver" |
|
5401 |
||
5402 |
%{ |
|
5403 |
struct inlineCache *pIlc; |
|
5404 |
static struct inlineCache ilc_0 = __ILCPERF3(@line); |
|
5405 |
static struct inlineCache ilc_1 = __ILCPERF3(@line); |
|
5406 |
static OBJ last_0 = nil; |
|
5407 |
static OBJ last_1 = nil; |
|
5408 |
static flip = 0; |
|
5409 |
||
5410 |
if (InterruptPending == nil) { |
|
6654 | 5411 |
if (aSelector != last_0) { |
5412 |
if (aSelector != last_1) { |
|
5413 |
if (flip) { |
|
5414 |
pIlc = &ilc_0; |
|
5415 |
flip = 0; |
|
5416 |
last_0 = aSelector; |
|
5417 |
} else { |
|
5418 |
pIlc = &ilc_1; |
|
5419 |
flip = 1; |
|
5420 |
last_1 = aSelector; |
|
5421 |
} |
|
5422 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5423 |
if (pIlc->ilc_poly) { |
|
5424 |
__flushPolyCache(pIlc->ilc_poly); |
|
5425 |
pIlc->ilc_poly = 0; |
|
5426 |
} |
|
5427 |
} else { |
|
5428 |
pIlc = &ilc_1; |
|
5429 |
} |
|
5430 |
} else { |
|
5431 |
pIlc = &ilc_0; |
|
5432 |
} |
|
5433 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
|
5755 | 5434 |
} else { |
6654 | 5435 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
5436 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, arg1, arg2, arg3)); |
|
5755 | 5437 |
} |
5438 |
%}. |
|
5439 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3) |
|
5440 |
||
5441 |
! |
|
5442 |
||
5443 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
5444 |
"send the four-arg-message aSelector to the receiver" |
|
5445 |
||
5446 |
%{ |
|
5447 |
struct inlineCache *pIlc; |
|
5448 |
static struct inlineCache ilc_0 = __ILCPERF4(@line); |
|
5449 |
static struct inlineCache ilc_1 = __ILCPERF4(@line); |
|
5450 |
static OBJ last_0 = nil; |
|
5451 |
static OBJ last_1 = nil; |
|
5452 |
static flip = 0; |
|
5453 |
||
5454 |
if (InterruptPending == nil) { |
|
6654 | 5455 |
if (aSelector != last_0) { |
5456 |
if (aSelector != last_1) { |
|
5457 |
if (flip) { |
|
5458 |
pIlc = &ilc_0; |
|
5459 |
flip = 0; |
|
5460 |
last_0 = aSelector; |
|
5461 |
} else { |
|
5462 |
pIlc = &ilc_1; |
|
5463 |
flip = 1; |
|
5464 |
last_1 = aSelector; |
|
5465 |
} |
|
5466 |
pIlc->ilc_func = __SEND4ADDR__; |
|
5467 |
if (pIlc->ilc_poly) { |
|
5468 |
__flushPolyCache(pIlc->ilc_poly); |
|
5469 |
pIlc->ilc_poly = 0; |
|
5470 |
} |
|
5471 |
} else { |
|
5472 |
pIlc = &ilc_1; |
|
5473 |
} |
|
5474 |
} else { |
|
5475 |
pIlc = &ilc_0; |
|
5476 |
} |
|
5477 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5478 |
arg1, arg2, arg3, arg4) ); |
|
5755 | 5479 |
} else { |
6654 | 5480 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
5481 |
RETURN (_SEND4(self, aSelector, nil, &ilc4, |
|
5482 |
arg1, arg2, arg3, arg4)); |
|
5755 | 5483 |
} |
5484 |
%}. |
|
5485 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
5486 |
||
5487 |
! |
|
5488 |
||
5489 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
5490 |
"send the five-arg-message aSelector to the receiver" |
|
5491 |
||
5492 |
%{ |
|
5493 |
struct inlineCache *pIlc; |
|
5494 |
static struct inlineCache ilc_0 = __ILCPERF5(@line); |
|
5495 |
static struct inlineCache ilc_1 = __ILCPERF5(@line); |
|
5496 |
static OBJ last_0 = nil; |
|
5497 |
static OBJ last_1 = nil; |
|
5498 |
static flip = 0; |
|
5499 |
||
5500 |
if (InterruptPending == nil) { |
|
6654 | 5501 |
if (aSelector != last_0) { |
5502 |
if (aSelector != last_1) { |
|
5503 |
if (flip) { |
|
5504 |
pIlc = &ilc_0; |
|
5505 |
flip = 0; |
|
5506 |
last_0 = aSelector; |
|
5507 |
} else { |
|
5508 |
pIlc = &ilc_1; |
|
5509 |
flip = 1; |
|
5510 |
last_1 = aSelector; |
|
5511 |
} |
|
5512 |
pIlc->ilc_func = __SEND5ADDR__; |
|
5513 |
if (pIlc->ilc_poly) { |
|
5514 |
__flushPolyCache(pIlc->ilc_poly); |
|
5515 |
pIlc->ilc_poly = 0; |
|
5516 |
} |
|
5517 |
} else { |
|
5518 |
pIlc = &ilc_1; |
|
5519 |
} |
|
5520 |
} else { |
|
5521 |
pIlc = &ilc_0; |
|
5522 |
} |
|
5523 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5524 |
arg1, arg2, arg3, arg4, arg5) ); |
|
5755 | 5525 |
} else { |
6654 | 5526 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
5527 |
RETURN (_SEND5(self, aSelector, nil, &ilc5, |
|
5528 |
arg1, arg2, arg3, arg4, arg5)); |
|
5755 | 5529 |
} |
5530 |
%}. |
|
5531 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
6654 | 5532 |
with:arg5) |
5755 | 5533 |
|
5534 |
! |
|
5535 |
||
5536 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
|
5537 |
"send the six-arg-message aSelector to the receiver" |
|
5538 |
||
5539 |
%{ |
|
5540 |
struct inlineCache *pIlc; |
|
5541 |
static struct inlineCache ilc_0 = __ILCPERF6(@line); |
|
5542 |
static struct inlineCache ilc_1 = __ILCPERF6(@line); |
|
5543 |
static OBJ last_0 = nil; |
|
5544 |
static OBJ last_1 = nil; |
|
5545 |
static flip = 0; |
|
5546 |
||
5547 |
if (InterruptPending == nil) { |
|
6654 | 5548 |
if (aSelector != last_0) { |
5549 |
if (aSelector != last_1) { |
|
5550 |
if (flip) { |
|
5551 |
pIlc = &ilc_0; |
|
5552 |
flip = 0; |
|
5553 |
last_0 = aSelector; |
|
5554 |
} else { |
|
5555 |
pIlc = &ilc_1; |
|
5556 |
flip = 1; |
|
5557 |
last_1 = aSelector; |
|
5558 |
} |
|
5559 |
pIlc->ilc_func = __SEND6ADDR__; |
|
5560 |
if (pIlc->ilc_poly) { |
|
5561 |
__flushPolyCache(pIlc->ilc_poly); |
|
5562 |
pIlc->ilc_poly = 0; |
|
5563 |
} |
|
5564 |
} else { |
|
5565 |
pIlc = &ilc_1; |
|
5566 |
} |
|
5567 |
} else { |
|
5568 |
pIlc = &ilc_0; |
|
5569 |
} |
|
5570 |
||
5571 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5572 |
arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
5755 | 5573 |
} else { |
6654 | 5574 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
5575 |
RETURN (_SEND6(self, aSelector, nil, &ilc6, |
|
5576 |
arg1, arg2, arg3, arg4, arg5, arg6)); |
|
5755 | 5577 |
} |
5578 |
%}. |
|
5579 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
6654 | 5580 |
with:arg5 with:arg6) |
5755 | 5581 |
|
5582 |
! |
|
5583 |
||
5584 |
perform:aSelector withArguments:argArray |
|
5585 |
"send the message aSelector with all args taken from argArray |
|
5586 |
to the receiver." |
|
5587 |
||
5588 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
5589 |
||
5590 |
%{ |
|
5591 |
REGISTER OBJ *argP; |
|
5592 |
int nargs; |
|
5593 |
OBJ l; |
|
5594 |
||
8934 | 5595 |
if (__isArrayLike(argArray)) { |
6654 | 5596 |
nargs = __arraySize(argArray); |
5597 |
argP = __arrayVal(argArray); |
|
5755 | 5598 |
} else { |
6654 | 5599 |
if (__isNonNilObject(argArray)) { |
5600 |
static struct inlineCache ilcSize = __ILC0(@line); |
|
5601 |
int i; |
|
5602 |
||
5603 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5604 |
if (!__isSmallInteger(numberOfArgs)) |
|
5605 |
goto bad; |
|
5606 |
nargs = __intVal(numberOfArgs); |
|
5607 |
argP = (OBJ *)(&a1); |
|
5608 |
for (i=1; i <= nargs; i++) { |
|
8913 | 5609 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
6654 | 5610 |
} |
5611 |
argP = (OBJ *)(&a1); |
|
5612 |
} else { |
|
5613 |
nargs = 0; |
|
5614 |
} |
|
5755 | 5615 |
} |
5616 |
switch (nargs) { |
|
6654 | 5617 |
case 0: |
5618 |
if (InterruptPending == nil) { |
|
5619 |
static OBJ last0_0 = nil; static struct inlineCache ilc0_0 = __ILCPERF0(@line); |
|
5620 |
static OBJ last0_1 = nil; static struct inlineCache ilc0_1 = __ILCPERF0(@line); |
|
5621 |
static OBJ last0_2 = nil; static struct inlineCache ilc0_2 = __ILCPERF0(@line); |
|
5622 |
static OBJ last0_3 = nil; static struct inlineCache ilc0_3 = __ILCPERF0(@line); |
|
5623 |
static int flip0 = 0; |
|
5624 |
struct inlineCache *pIlc; |
|
5625 |
||
5626 |
if (aSelector == last0_0) { |
|
5627 |
pIlc = &ilc0_0; |
|
5628 |
} else if (aSelector == last0_1) { |
|
5629 |
pIlc = &ilc0_1; |
|
5630 |
} else if (aSelector == last0_2) { |
|
5631 |
pIlc = &ilc0_2; |
|
5632 |
} else if (aSelector == last0_3) { |
|
5633 |
pIlc = &ilc0_3; |
|
5634 |
} else { |
|
5635 |
if (flip0 == 0) { |
|
5636 |
pIlc = &ilc0_0; |
|
5637 |
flip0 = 1; |
|
5638 |
last0_0 = aSelector; |
|
5639 |
} else if (flip0 == 1) { |
|
5640 |
pIlc = &ilc0_1; |
|
5641 |
flip0 = 2; |
|
5642 |
last0_1 = aSelector; |
|
5643 |
} else if (flip0 == 2) { |
|
5644 |
pIlc = &ilc0_2; |
|
5645 |
flip0 = 3; |
|
5646 |
last0_2 = aSelector; |
|
5647 |
} else { |
|
5648 |
pIlc = &ilc0_3; |
|
5649 |
flip0 = 0; |
|
5650 |
last0_3 = aSelector; |
|
5651 |
} |
|
5652 |
||
5653 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5654 |
if (pIlc->ilc_poly) { |
|
5655 |
__flushPolyCache(pIlc->ilc_poly); |
|
5656 |
pIlc->ilc_poly = 0; |
|
5657 |
} |
|
5658 |
} |
|
5659 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc)); |
|
5660 |
} else { |
|
5661 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5662 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5663 |
} |
|
5664 |
||
5665 |
case 1: |
|
5666 |
if (InterruptPending == nil) { |
|
5667 |
static OBJ last1_0 = nil; static struct inlineCache ilc1_0 = __ILCPERF1(@line); |
|
5668 |
static OBJ last1_1 = nil; static struct inlineCache ilc1_1 = __ILCPERF1(@line); |
|
5669 |
static OBJ last1_2 = nil; static struct inlineCache ilc1_2 = __ILCPERF1(@line); |
|
5670 |
static OBJ last1_3 = nil; static struct inlineCache ilc1_3 = __ILCPERF1(@line); |
|
5671 |
static int flip1 = 0; |
|
5672 |
struct inlineCache *pIlc; |
|
5673 |
||
5674 |
if (aSelector == last1_0) { |
|
5675 |
pIlc = &ilc1_0; |
|
5676 |
} else if (aSelector == last1_1) { |
|
5677 |
pIlc = &ilc1_1; |
|
5678 |
} else if (aSelector == last1_2) { |
|
5679 |
pIlc = &ilc1_2; |
|
5680 |
} else if (aSelector == last1_3) { |
|
5681 |
pIlc = &ilc1_3; |
|
5682 |
} else { |
|
5683 |
if (flip1 == 0) { |
|
5684 |
pIlc = &ilc1_0; |
|
5685 |
flip1 = 1; |
|
5686 |
last1_0 = aSelector; |
|
5687 |
} else if (flip1 == 1) { |
|
5688 |
pIlc = &ilc1_1; |
|
5689 |
flip1 = 2; |
|
5690 |
last1_1 = aSelector; |
|
5691 |
} else if (flip1 == 2) { |
|
5692 |
pIlc = &ilc1_2; |
|
5693 |
flip1 = 3; |
|
5694 |
last1_2 = aSelector; |
|
5695 |
} else { |
|
5696 |
pIlc = &ilc1_3; |
|
5697 |
flip1 = 0; |
|
5698 |
last1_3 = aSelector; |
|
5699 |
} |
|
5700 |
||
5701 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5702 |
if (pIlc->ilc_poly) { |
|
5703 |
__flushPolyCache(pIlc->ilc_poly); |
|
5704 |
pIlc->ilc_poly = 0; |
|
5705 |
} |
|
5706 |
} |
|
5707 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0])); |
|
5708 |
} else { |
|
5709 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5710 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, argP[0])); |
|
5711 |
} |
|
5712 |
||
5713 |
case 2: |
|
5714 |
if (InterruptPending == nil) { |
|
5715 |
static OBJ last2_0 = nil; static struct inlineCache ilc2_0 = __ILCPERF2(@line); |
|
5716 |
static OBJ last2_1 = nil; static struct inlineCache ilc2_1 = __ILCPERF2(@line); |
|
5717 |
static int flip2 = 0; |
|
5718 |
struct inlineCache *pIlc; |
|
5719 |
||
5720 |
if (aSelector == last2_0) { |
|
5721 |
pIlc = &ilc2_0; |
|
5722 |
} else if (aSelector == last2_1) { |
|
5723 |
pIlc = &ilc2_1; |
|
5724 |
} else { |
|
5725 |
if (flip2 == 0) { |
|
5726 |
pIlc = &ilc2_0; |
|
5727 |
flip2 = 1; |
|
5728 |
last2_0 = aSelector; |
|
5729 |
} else { |
|
5730 |
pIlc = &ilc2_1; |
|
5731 |
flip2 = 0; |
|
5732 |
last2_1 = aSelector; |
|
5733 |
} |
|
5734 |
||
5735 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5736 |
if (pIlc->ilc_poly) { |
|
5737 |
__flushPolyCache(pIlc->ilc_poly); |
|
5738 |
pIlc->ilc_poly = 0; |
|
5739 |
} |
|
5740 |
} |
|
5741 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1])); |
|
5742 |
} else { |
|
5743 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5744 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, argP[0], argP[1])); |
|
5745 |
} |
|
5746 |
||
5747 |
case 3: |
|
5748 |
if (InterruptPending == nil) { |
|
5749 |
static OBJ last3_0 = nil; static struct inlineCache ilc3_0 = __ILCPERF3(@line); |
|
5750 |
static OBJ last3_1 = nil; static struct inlineCache ilc3_1 = __ILCPERF3(@line); |
|
5751 |
static int flip3 = 0; |
|
5752 |
struct inlineCache *pIlc; |
|
5753 |
||
5754 |
if (aSelector == last3_0) { |
|
5755 |
pIlc = &ilc3_0; |
|
5756 |
} else if (aSelector == last3_1) { |
|
5757 |
pIlc = &ilc3_1; |
|
5758 |
} else { |
|
5759 |
if (flip3 == 0) { |
|
5760 |
pIlc = &ilc3_0; |
|
5761 |
flip3 = 1; |
|
5762 |
last3_0 = aSelector; |
|
5763 |
} else { |
|
5764 |
pIlc = &ilc3_1; |
|
5765 |
flip3 = 0; |
|
5766 |
last3_1 = aSelector; |
|
5767 |
} |
|
5768 |
||
5769 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5770 |
if (pIlc->ilc_poly) { |
|
5771 |
__flushPolyCache(pIlc->ilc_poly); |
|
5772 |
pIlc->ilc_poly = 0; |
|
5773 |
} |
|
5774 |
} |
|
5775 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1], argP[2])); |
|
5776 |
} else { |
|
5777 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5778 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, argP[0], argP[1], argP[2])); |
|
5779 |
} |
|
5780 |
||
5781 |
case 4: |
|
5782 |
{ |
|
5783 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(@line); |
|
5784 |
||
5785 |
if ((InterruptPending != nil) || (aSelector != last4)) { |
|
5786 |
ilc4.ilc_func = __SEND4ADDR__; |
|
5787 |
if (ilc4.ilc_poly) { |
|
5788 |
__flushPolyCache(ilc4.ilc_poly); |
|
5789 |
ilc4.ilc_poly = 0; |
|
5790 |
} |
|
5791 |
last4 = aSelector; |
|
5792 |
} |
|
5793 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
|
5794 |
argP[0], argP[1], argP[2], argP[3])); |
|
5795 |
} |
|
5796 |
||
5797 |
case 5: |
|
5798 |
{ |
|
5799 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(@line); |
|
5800 |
||
5801 |
if ((InterruptPending != nil) || (aSelector != last5)) { |
|
5802 |
ilc5.ilc_func = __SEND5ADDR__; |
|
5803 |
if (ilc5.ilc_poly) { |
|
5804 |
__flushPolyCache(ilc5.ilc_poly); |
|
5805 |
ilc5.ilc_poly = 0; |
|
5806 |
} |
|
5807 |
last5 = aSelector; |
|
5808 |
} |
|
5809 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
|
5810 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5811 |
} |
|
5812 |
||
5813 |
case 6: |
|
5814 |
{ |
|
5815 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(@line); |
|
5816 |
||
5817 |
if ((InterruptPending != nil) || (aSelector != last6)) { |
|
5818 |
ilc6.ilc_func = __SEND6ADDR__; |
|
5819 |
if (ilc6.ilc_poly) { |
|
5820 |
__flushPolyCache(ilc6.ilc_poly); |
|
5821 |
ilc6.ilc_poly = 0; |
|
5822 |
} |
|
5823 |
last6 = aSelector; |
|
5824 |
} |
|
5825 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
|
5826 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5827 |
argP[5])); |
|
5828 |
} |
|
5829 |
||
5830 |
case 7: |
|
5831 |
{ |
|
5832 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(@line); |
|
5833 |
||
5834 |
if ((InterruptPending != nil) || (aSelector != last7)) { |
|
5835 |
ilc7.ilc_func = __SEND7ADDR__; |
|
5836 |
if (ilc7.ilc_poly) { |
|
5837 |
__flushPolyCache(ilc7.ilc_poly); |
|
5838 |
ilc7.ilc_poly = 0; |
|
5839 |
} |
|
5840 |
last7 = aSelector; |
|
5841 |
} |
|
5842 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
|
5843 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5844 |
argP[5], argP[6])); |
|
5845 |
} |
|
5846 |
||
5847 |
case 8: |
|
5848 |
{ |
|
5849 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(@line); |
|
5850 |
||
5851 |
if ((InterruptPending != nil) || (aSelector != last8)) { |
|
5852 |
ilc8.ilc_func = __SEND8ADDR__; |
|
5853 |
if (ilc8.ilc_poly) { |
|
5854 |
__flushPolyCache(ilc8.ilc_poly); |
|
5855 |
ilc8.ilc_poly = 0; |
|
5856 |
} |
|
5857 |
last8 = aSelector; |
|
5858 |
} |
|
5859 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
|
5860 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5861 |
argP[5], argP[6], argP[7])); |
|
5862 |
} |
|
5863 |
||
5864 |
case 9: |
|
5865 |
{ |
|
5866 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(@line); |
|
5867 |
||
5868 |
if ((InterruptPending != nil) || (aSelector != last9)) { |
|
5869 |
ilc9.ilc_func = __SEND9ADDR__; |
|
5870 |
if (ilc9.ilc_poly) { |
|
5871 |
__flushPolyCache(ilc9.ilc_poly); |
|
5872 |
ilc9.ilc_poly = 0; |
|
5873 |
} |
|
5874 |
last9 = aSelector; |
|
5875 |
} |
|
5876 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
|
5877 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5878 |
argP[5], argP[6], argP[7], argP[8])); |
|
5879 |
} |
|
5880 |
||
5881 |
case 10: |
|
5882 |
{ |
|
5883 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(@line); |
|
5884 |
||
5885 |
if ((InterruptPending != nil) || (aSelector != last10)) { |
|
5886 |
ilc10.ilc_func = __SEND10ADDR__; |
|
5887 |
if (ilc10.ilc_poly) { |
|
5888 |
__flushPolyCache(ilc10.ilc_poly); |
|
5889 |
ilc10.ilc_poly = 0; |
|
5890 |
} |
|
5891 |
last10 = aSelector; |
|
5892 |
} |
|
5893 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
|
5894 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5895 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
5896 |
} |
|
5897 |
||
5898 |
case 11: |
|
5899 |
{ |
|
5900 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(@line); |
|
5901 |
||
5902 |
if ((InterruptPending != nil) || (aSelector != last11)) { |
|
5903 |
ilc11.ilc_func = __SEND11ADDR__; |
|
5904 |
if (ilc11.ilc_poly) { |
|
5905 |
__flushPolyCache(ilc11.ilc_poly); |
|
5906 |
ilc11.ilc_poly = 0; |
|
5907 |
} |
|
5908 |
last11 = aSelector; |
|
5909 |
} |
|
5910 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
|
5911 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5912 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5913 |
argP[10])); |
|
5914 |
} |
|
5915 |
||
5916 |
case 12: |
|
5917 |
{ |
|
5918 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(@line); |
|
5919 |
||
5920 |
if ((InterruptPending != nil) || (aSelector != last12)) { |
|
5921 |
ilc12.ilc_func = __SEND12ADDR__; |
|
5922 |
if (ilc12.ilc_poly) { |
|
5923 |
__flushPolyCache(ilc12.ilc_poly); |
|
5924 |
ilc12.ilc_poly = 0; |
|
5925 |
} |
|
5926 |
last12 = aSelector; |
|
5927 |
} |
|
5928 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
|
5929 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5930 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5931 |
argP[10], argP[11])); |
|
5932 |
} |
|
5933 |
||
5934 |
case 13: |
|
5935 |
{ |
|
5936 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(@line); |
|
5937 |
||
5938 |
if ((InterruptPending != nil) || (aSelector != last13)) { |
|
5939 |
ilc13.ilc_func = __SEND13ADDR__; |
|
5940 |
if (ilc13.ilc_poly) { |
|
5941 |
__flushPolyCache(ilc13.ilc_poly); |
|
5942 |
ilc13.ilc_poly = 0; |
|
5943 |
} |
|
5944 |
last13 = aSelector; |
|
5945 |
} |
|
5946 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
|
5947 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5948 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5949 |
argP[10], argP[11], argP[12])); |
|
5950 |
} |
|
5951 |
||
5952 |
case 14: |
|
5953 |
{ |
|
5954 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(@line); |
|
5955 |
||
5956 |
if ((InterruptPending != nil) || (aSelector != last14)) { |
|
5957 |
ilc14.ilc_func = __SEND14ADDR__; |
|
5958 |
if (ilc14.ilc_poly) { |
|
5959 |
__flushPolyCache(ilc14.ilc_poly); |
|
5960 |
ilc14.ilc_poly = 0; |
|
5961 |
} |
|
5962 |
last14 = aSelector; |
|
5963 |
} |
|
5964 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
|
5965 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5966 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5967 |
argP[10], argP[11], argP[12], argP[13])); |
|
5968 |
} |
|
5969 |
||
5970 |
case 15: |
|
5971 |
{ |
|
5972 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(@line); |
|
5973 |
||
5974 |
if ((InterruptPending != nil) || (aSelector != last15)) { |
|
5975 |
ilc15.ilc_func = __SEND15ADDR__; |
|
5976 |
if (ilc15.ilc_poly) { |
|
5977 |
__flushPolyCache(ilc15.ilc_poly); |
|
5978 |
ilc15.ilc_poly = 0; |
|
5979 |
} |
|
5980 |
last15 = aSelector; |
|
5981 |
} |
|
5982 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
|
5983 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5984 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5985 |
argP[10], argP[11], argP[12], argP[13], |
|
5986 |
argP[14])); |
|
5987 |
} |
|
5755 | 5988 |
} |
5989 |
bad:; |
|
5990 |
%}. |
|
5991 |
||
5992 |
"/ arrive here, if bad number of arguments (too many) |
|
5993 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5994 |
||
5995 |
^ self primitiveFailed |
|
5996 |
! |
|
5997 |
||
6316 | 5998 |
perform:aSelector withOptionalArgument:arg |
5999 |
"send aSelector-message to the receiver. |
|
6318 | 6000 |
If the message expects an argument, pass arg." |
6316 | 6001 |
|
6002 |
aSelector numArgs == 1 ifTrue:[ |
|
6654 | 6003 |
^ self perform:aSelector with:arg |
6316 | 6004 |
]. |
6005 |
^ self perform:aSelector |
|
6319 | 6006 |
|
6007 |
" |
|
6008 |
|rec sel| |
|
6009 |
||
6010 |
rec := -1. |
|
6011 |
sel := #abs. |
|
6012 |
rec perform:sel withOptionalArgument:2. |
|
6013 |
||
6014 |
sel := #max:. |
|
6015 |
rec perform:sel withOptionalArgument:2. |
|
6016 |
" |
|
6316 | 6017 |
! |
6018 |
||
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6019 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6020 |
"send aSelector-message to the receiver. |
6728 | 6021 |
Depending on the number of arguments the message expects, |
6022 |
pass either none, 1, or 2 arguments." |
|
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6023 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6024 |
|numArgs| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6025 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6026 |
numArgs := aSelector numArgs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6027 |
numArgs == 0 ifTrue:[ |
6654 | 6028 |
^ self perform:aSelector |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6029 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6030 |
numArgs == 1 ifTrue:[ |
6654 | 6031 |
^ self perform:aSelector with:optionalArg1 |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6032 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6033 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6034 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6035 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6036 |
|rec sel| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6037 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6038 |
rec := -1. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6039 |
sel := #abs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6040 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6041 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6042 |
sel := #max:. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6043 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6044 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6045 |
! |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6046 |
|
6728 | 6047 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 |
6048 |
"send aSelector-message to the receiver. |
|
6049 |
Depending on the number of arguments the message expects, |
|
6050 |
pass either none, 1, 2 or 3 arguments." |
|
6051 |
||
6052 |
|numArgs| |
|
6053 |
||
6054 |
numArgs := aSelector numArgs. |
|
6055 |
numArgs == 0 ifTrue:[ |
|
6056 |
^ self perform:aSelector |
|
6057 |
]. |
|
6058 |
numArgs == 1 ifTrue:[ |
|
6059 |
^ self perform:aSelector with:optionalArg1 |
|
6060 |
]. |
|
6061 |
numArgs == 2 ifTrue:[ |
|
6062 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
|
6063 |
]. |
|
6064 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3. |
|
6065 |
||
6066 |
" |
|
6067 |
|rec sel| |
|
6068 |
||
6069 |
rec := -1. |
|
6070 |
sel := #abs. |
|
6071 |
rec perform:sel withOptionalArgument:2. |
|
6072 |
||
6073 |
sel := #max:. |
|
6074 |
rec perform:sel withOptionalArgument:2. |
|
6075 |
" |
|
6076 |
! |
|
6077 |
||
6764 | 6078 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 and:optionalArg4 |
6079 |
"send aSelector-message to the receiver. |
|
6080 |
Depending on the number of arguments the message expects, |
|
6081 |
pass either none, 1, 2, 3 or 4 arguments." |
|
6082 |
||
6083 |
|numArgs| |
|
6084 |
||
6085 |
numArgs := aSelector numArgs. |
|
6086 |
numArgs == 0 ifTrue:[ |
|
6087 |
^ self perform:aSelector |
|
6088 |
]. |
|
6089 |
numArgs == 1 ifTrue:[ |
|
6090 |
^ self perform:aSelector with:optionalArg1 |
|
6091 |
]. |
|
6092 |
numArgs == 2 ifTrue:[ |
|
6093 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
|
6094 |
]. |
|
6095 |
numArgs == 3 ifTrue:[ |
|
6096 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 |
|
6097 |
]. |
|
6098 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 with:optionalArg4. |
|
6099 |
||
6100 |
" |
|
6101 |
|rec sel| |
|
6102 |
||
6103 |
rec := -1. |
|
6104 |
sel := #abs. |
|
6105 |
rec perform:sel withOptionalArgument:2. |
|
6106 |
||
6107 |
sel := #max:. |
|
6108 |
rec perform:sel withOptionalArgument:2. |
|
6109 |
" |
|
6110 |
! |
|
6111 |
||
5755 | 6112 |
performMethod:aMethod |
6113 |
"invoke aMethod on the receiver. |
|
6114 |
The method should be a zero-argument method. |
|
6115 |
This is a non-object-oriented entry, applying a method |
|
6116 |
in a functional way on a receiver. |
|
6117 |
Warning: |
|
6654 | 6118 |
Take care for the method to be appropriate for the |
6119 |
receiver - no checking is done by the VM." |
|
5755 | 6120 |
|
6121 |
^ aMethod valueWithReceiver:self arguments:#() |
|
6122 |
||
6123 |
" |
|
6124 |
|mthd| |
|
6125 |
||
6126 |
mthd := SmallInteger compiledMethodAt:#negated. |
|
6127 |
Transcript showCR:(1 performMethod:mthd) |
|
6128 |
" |
|
6129 |
||
6130 |
"BAD USE example: |
|
6131 |
||
6132 |
|mthd| |
|
6133 |
||
6134 |
mthd := Point compiledMethodAt:#x. |
|
6135 |
Transcript showCR:((1->2) performMethod:mthd) |
|
6136 |
" |
|
6137 |
||
6138 |
"Modified: 31.7.1997 / 17:41:50 / cg" |
|
6139 |
! |
|
6140 |
||
6141 |
performMethod:aMethod arguments:argumentArray |
|
6142 |
"invoke aMethod on the receiver, passing an argumentArray. |
|
6143 |
The size of the argumentArray should match the number of args |
|
6144 |
expected by the method. |
|
6145 |
This is a non-object-oriented entry, applying a method |
|
6146 |
in a functional way on a receiver. |
|
6147 |
Warning: |
|
6654 | 6148 |
Take care for the method to be appropriate for the |
6149 |
receiver - no checking is done by the VM." |
|
5755 | 6150 |
|
6151 |
^ aMethod valueWithReceiver:self arguments:argumentArray |
|
6152 |
||
6153 |
" |
|
6154 |
|mthd| |
|
6155 |
||
6156 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6157 |
Transcript showCR:(1 performMethod:mthd arguments:#(2)) |
|
6158 |
" |
|
6159 |
||
6160 |
"Created: 31.7.1997 / 17:46:31 / cg" |
|
6161 |
! |
|
6162 |
||
6163 |
performMethod:aMethod with:arg |
|
6164 |
"invoke aMethod on the receiver, passing an argument. |
|
6165 |
The method should be a one-argument method. |
|
6166 |
This is a non-object-oriented entry, applying a method |
|
6167 |
in a functional way on a receiver. |
|
6168 |
Warning: |
|
6654 | 6169 |
Take care for the method to be appropriate for the |
6170 |
receiver - no checking is done by the VM." |
|
5755 | 6171 |
|
6172 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg) |
|
6173 |
||
6174 |
" |
|
6175 |
|mthd| |
|
6176 |
||
6177 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6178 |
Transcript showCR:(1 performMethod:mthd with:2) |
|
6179 |
" |
|
6180 |
||
6181 |
"Modified: 31.7.1997 / 17:42:32 / cg" |
|
6182 |
! |
|
6183 |
||
6184 |
performMethod:aMethod with:arg1 with:arg2 |
|
6185 |
"invoke aMethod on the receiver, passing two arguments. |
|
6186 |
The method should be a two-argument method. |
|
6187 |
This is a non-object-oriented entry, applying a method |
|
6188 |
in a functional way on a receiver. |
|
6189 |
Warning: |
|
6654 | 6190 |
Take care for the method to be appropriate for the |
6191 |
receiver - no checking is done by the VM." |
|
5755 | 6192 |
|
6193 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) |
|
6194 |
||
6195 |
" |
|
6196 |
|mthd arr| |
|
6197 |
||
6198 |
arr := Array new:1. |
|
6199 |
mthd := Array compiledMethodAt:#basicAt:put:. |
|
6200 |
arr performMethod:mthd with:1 with:'foo'. |
|
6201 |
Transcript showCR:arr |
|
6202 |
" |
|
6203 |
||
6204 |
"Modified: 31.7.1997 / 17:44:54 / cg" |
|
6205 |
! |
|
6206 |
||
6207 |
performMethod:aMethod with:arg1 with:arg2 with:arg3 |
|
6208 |
"invoke aMethod on the receiver, passing three arguments. |
|
6209 |
The method should be a three-argument method. |
|
6210 |
This is a non-object-oriented entry, applying a method |
|
6211 |
in a functional way on a receiver. |
|
6212 |
Warning: |
|
6654 | 6213 |
Take care for the method to be appropriate for the |
6214 |
receiver - no checking is done by the VM." |
|
5755 | 6215 |
|
6216 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3) |
|
6217 |
||
6218 |
"Created: 31.7.1997 / 17:45:20 / cg" |
|
6219 |
! ! |
|
6220 |
||
6221 |
!Object methodsFor:'printing & storing'! |
|
6222 |
||
6235 | 6223 |
basicPrintOn:aStream |
6224 |
"append the receivers className with an articel to the argument, aStream" |
|
6225 |
||
6226 |
aStream nextPutAll:self classNameWithArticle |
|
6227 |
! |
|
6228 |
||
5755 | 6229 |
className |
6230 |
"return the classname of the receivers class" |
|
6231 |
||
6232 |
^ self class name |
|
6233 |
||
6234 |
" |
|
6235 |
1 className |
|
9105 | 6236 |
1 class className |
5755 | 6237 |
$a className |
9105 | 6238 |
$a class className |
5755 | 6239 |
" |
6240 |
! |
|
6241 |
||
6242 |
classNameWithArticle |
|
6243 |
"return a string consisting of classname preceeded by an article. |
|
6244 |
(dont expect me to write national variants for this ... :-) |
|
6245 |
If you have special preferences, redefine it ..." |
|
6246 |
||
6829 | 6247 |
| cls| |
5755 | 6248 |
|
6249 |
(cls := self class) == self ifTrue:[ |
|
6654 | 6250 |
^ 'a funny object' |
5755 | 6251 |
]. |
6829 | 6252 |
^ cls nameWithArticle |
5755 | 6253 |
|
6254 |
" |
|
6418 | 6255 |
1 classNameWithArticle |
6256 |
(1->2) classNameWithArticle |
|
5755 | 6257 |
XWorkstation basicNew classNameWithArticle |
6418 | 6258 |
XWorkstation classNameWithArticle |
5755 | 6259 |
" |
6260 |
||
6261 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
6262 |
! |
|
6263 |
||
6264 |
errorPrint |
|
6265 |
"print the receiver on the standard error stream." |
|
6266 |
||
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
6267 |
StreamError catch:[ |
6654 | 6268 |
self printOn:Stderr |
5755 | 6269 |
] |
6270 |
||
6271 |
"Modified: 7.3.1996 / 19:11:29 / cg" |
|
6272 |
! |
|
6273 |
||
6274 |
errorPrintCR |
|
6275 |
"{ Pragma: +optSpace }" |
|
6276 |
||
6277 |
"print the receiver followed by a cr on the standard error stream." |
|
6278 |
||
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
6279 |
StreamError catch:[ |
6654 | 6280 |
self printOn:Stderr. |
6281 |
Stderr cr |
|
5755 | 6282 |
] |
6283 |
||
6284 |
"Modified: 7.3.1996 / 19:13:01 / cg" |
|
6285 |
"Created: 20.5.1996 / 10:20:41 / cg" |
|
6286 |
! |
|
6287 |
||
6288 |
errorPrintNL |
|
6289 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6290 |
<resource:#obsolete> |
5755 | 6291 |
|
6292 |
"print the receiver followed by a cr on the standard error stream. |
|
6293 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6294 |
||
6295 |
^ self errorPrintCR |
|
6296 |
||
6297 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
6298 |
! |
|
6299 |
||
6300 |
errorPrintNewline |
|
6301 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6302 |
<resource:#obsolete> |
5755 | 6303 |
|
6304 |
"print the receiver followed by a cr on the standard error stream. |
|
6305 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6306 |
||
6307 |
self errorPrintCR. |
|
6308 |
||
6309 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
6310 |
! |
|
6311 |
||
6312 |
infoPrint |
|
6313 |
"{ Pragma: +optSpace }" |
|
6314 |
||
6315 |
"print the receiver on the standard error stream. |
|
6316 |
This is meant for information messages which are not warnings |
|
6317 |
or fatal messages. |
|
6318 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6319 |
||
6320 |
InfoPrinting == true ifTrue:[ |
|
6654 | 6321 |
self errorPrint |
5755 | 6322 |
] |
6323 |
! |
|
6324 |
||
6325 |
infoPrintCR |
|
6326 |
"{ Pragma: +optSpace }" |
|
6327 |
||
6328 |
"print the receiver followed by a cr on the standard error stream. |
|
6329 |
This is meant for information messages which are not warnings |
|
6330 |
or fatal messages. |
|
6331 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6332 |
||
6333 |
InfoPrinting == true ifTrue:[ |
|
6654 | 6334 |
self errorPrintCR |
5755 | 6335 |
] |
6336 |
||
6337 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
6338 |
! |
|
6339 |
||
6340 |
infoPrintNL |
|
6341 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6342 |
<resource:#obsolete> |
5755 | 6343 |
|
6344 |
"print the receiver followed by a cr on the standard error stream. |
|
6345 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
6346 |
||
6347 |
^ self infoPrintCR |
|
6348 |
! |
|
6349 |
||
6350 |
||
6351 |
"print the receiver on the standard output stream (which is not the Transcript)" |
|
6352 |
||
6353 |
"/ the following allows printCR to be used during |
|
6354 |
"/ the early init-phase, when no Stdout has been set up. |
|
6355 |
"/ (depends on string to respond to #print) |
|
6356 |
||
6357 |
Stdout isNil ifTrue:[ |
|
6654 | 6358 |
self printString print. |
6359 |
^ self |
|
5755 | 6360 |
]. |
6361 |
self printOn:Stdout |
|
6362 |
||
6363 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
6364 |
! |
|
6365 |
||
6366 |
printCR |
|
6367 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
|
6368 |
||
6369 |
"/ the following allows printCR to be used during |
|
6370 |
"/ the early init-phase, when no Stdout has been set up. |
|
6371 |
"/ (depends on string to respond to #printCR) |
|
6372 |
||
6373 |
Stdout isNil ifTrue:[ |
|
6654 | 6374 |
self printString printCR. |
6375 |
^ self |
|
5755 | 6376 |
]. |
6377 |
self printOn:Stdout. |
|
6378 |
Stdout cr |
|
6379 |
||
6380 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
6381 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
|
6382 |
! |
|
6383 |
||
6384 |
printNL |
|
6385 |
"print the receiver followed by a cr on the standard output stream |
|
6386 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
6387 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6388 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6389 |
|
5755 | 6390 |
^ self printCR |
6391 |
||
6392 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
6393 |
! |
|
6394 |
||
6395 |
printNewline |
|
6396 |
"print the receiver followed by a cr on the standard output stream. |
|
6397 |
This exists for backward compatibility - please use #printCR." |
|
6398 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6399 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6400 |
|
5755 | 6401 |
self printCR |
6402 |
||
6403 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
6404 |
! |
|
6405 |
||
6406 |
printOn:aStream |
|
6407 |
"append a user printed representation of the receiver to aStream. |
|
6408 |
The format is suitable for a human - not meant to be read back. |
|
6409 |
||
6410 |
The default here is to output the receivers class name. |
|
6411 |
BUT: this method is heavily redefined for objects which |
|
6412 |
can print prettier." |
|
6413 |
||
6235 | 6414 |
self basicPrintOn:aStream. |
6415 |
||
6416 |
" |
|
6417 |
(1@2) printOn:Transcript |
|
6418 |
(1@2) basicPrintOn:Transcript |
|
6419 |
" |
|
5755 | 6420 |
! |
6421 |
||
6422 |
printOn:aStream leftPaddedTo:size |
|
6423 |
"print the receiver on aStream, padding with spaces up to size. |
|
6424 |
padding is done on the left." |
|
6425 |
||
6426 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
6427 |
||
6428 |
" |
|
6429 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
6430 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
6431 |
" |
|
6432 |
! |
|
6433 |
||
6434 |
printOn:aStream leftPaddedTo:size with:padCharacter |
|
6435 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
6436 |
padding is done on the left." |
|
6437 |
||
6438 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
6439 |
||
6440 |
" |
|
6441 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
6442 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
6443 |
" |
|
6444 |
! |
|
6445 |
||
6446 |
printOn:aStream paddedTo:size |
|
6447 |
"print the receiver on aStream, padding with spaces up to size." |
|
6448 |
||
6449 |
self printOn:aStream paddedTo:size with:(Character space) |
|
6450 |
||
6451 |
" |
|
6452 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
6453 |
" |
|
6454 |
! |
|
6455 |
||
6456 |
printOn:aStream paddedTo:size with:padCharacter |
|
6457 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
6458 |
||
6459 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
6460 |
||
6461 |
" |
|
6462 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
6463 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
6464 |
" |
|
6465 |
! |
|
6466 |
||
6467 |
printOn:aStream zeroPaddedTo:size |
|
6468 |
"print the receiver on aStream, padding with zeros up to size. |
|
6469 |
Usually used with float numbers." |
|
6470 |
||
6471 |
self printOn:aStream paddedTo:size with:$0. |
|
6472 |
||
6473 |
" |
|
6474 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
6475 |
" |
|
6476 |
! |
|
6477 |
||
6478 |
printRightAdjustLen:size |
|
6479 |
"obsolete - just a name confusion. |
|
6480 |
This method will go away ..." |
|
6481 |
||
6482 |
(self printStringLeftPaddedTo:size) printOn:Stdout |
|
6483 |
! |
|
6484 |
||
6485 |
printString |
|
6486 |
"return a string for printing the receiver. |
|
6487 |
Since we now use printOn: as the basic print mechanism, |
|
6488 |
we have to create a stream and print into it." |
|
6489 |
||
6490 |
|s| |
|
6491 |
||
8300
d15ead94361f
Use CharacterWriteStream in #printString (speedup)
Stefan Vogel <sv@exept.de>
parents:
8287
diff
changeset
|
6492 |
s := CharacterWriteStream on:(String basicNew:30). |
5755 | 6493 |
self printOn:s. |
8300
d15ead94361f
Use CharacterWriteStream in #printString (speedup)
Stefan Vogel <sv@exept.de>
parents:
8287
diff
changeset
|
6494 |
^ s contents. |
7978
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6495 |
|
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6496 |
" |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6497 |
Date today printString. |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6498 |
" |
5755 | 6499 |
! |
6500 |
||
6501 |
printStringLeftPaddedTo:size |
|
6502 |
"return my printString as a right-adjusted string of length size; |
|
6503 |
characters on the left are filled with spaces. |
|
6504 |
If the printString is longer than size, |
|
6505 |
it is returned unchanged (i.e. not truncated)" |
|
6506 |
||
6507 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
6508 |
||
6509 |
" |
|
6510 |
10 printStringLeftPaddedTo:10 |
|
6511 |
1 printStringLeftPaddedTo:10 |
|
6512 |
" |
|
6513 |
! |
|
6514 |
||
6515 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
6516 |
"return my printString as a right-adjusted string of length size; |
|
6517 |
characters on the left are filled with spaces. |
|
6518 |
If the printString is larger than size, |
|
6519 |
return the result from evaluating alternative." |
|
6520 |
||
6521 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
6522 |
||
6523 |
" |
|
6524 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6525 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6526 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6527 |
" |
|
6528 |
! |
|
6529 |
||
6530 |
printStringLeftPaddedTo:size with:padCharacter |
|
6531 |
"return my printString as a right-adjusted string of length size; |
|
6532 |
characters on the left are filled with padCharacter. |
|
6533 |
If the printString is longer than size, |
|
6534 |
it is returned unchanged (i.e. not truncated)" |
|
6535 |
||
6536 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
6537 |
||
6538 |
" |
|
6539 |
123 printStringLeftPaddedTo:10 with:$. |
|
6540 |
1 printStringLeftPaddedTo:10 with:$. |
|
6541 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
|
6542 |
" |
|
6543 |
! |
|
6544 |
||
6545 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
6546 |
"return my printString as a right-adjusted string of length size; |
|
6547 |
characters on the left are filled with padCharacter. |
|
6548 |
If the printString is larger than size, |
|
6549 |
return the result from evaluating alternative." |
|
6550 |
||
6551 |
|s| |
|
6552 |
||
6553 |
s := self printString. |
|
6554 |
s size > size ifTrue:[^ alternative value]. |
|
6555 |
^ s leftPaddedTo:size with:padCharacter |
|
6556 |
||
6557 |
" |
|
6558 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6559 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6560 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6561 |
" |
|
6562 |
! |
|
6563 |
||
8576 | 6564 |
printStringLimitedTo:sizeLimit |
6565 |
"return a string for printing the receiver, but limit the result string in its size." |
|
6566 |
||
6567 |
|s| |
|
6568 |
||
6569 |
s := CharacterWriteStream on:(String basicNew:30). |
|
6570 |
s writeLimit:sizeLimit. |
|
6571 |
self printOn:s. |
|
6572 |
^ s contents. |
|
6573 |
||
6574 |
" |
|
6575 |
Date today printStringLimitedTo:5. |
|
6576 |
'12345678901234567890' printStringLimitedTo:5. |
|
6577 |
" |
|
6578 |
! |
|
6579 |
||
5755 | 6580 |
printStringOnError:exceptionBlock |
6581 |
"return a string for printing the receiver; if any error occurs, return the result from |
|
6582 |
evaluating exceptionBlock. Useful to print something in an exceptionHandler or other |
|
6583 |
cleanup code." |
|
6584 |
||
6585 |
|rslt| |
|
6586 |
||
6587 |
Error handle:[:ex | |
|
6654 | 6588 |
rslt := exceptionBlock value |
5755 | 6589 |
] do:[ |
6654 | 6590 |
rslt := self printString |
5755 | 6591 |
]. |
6592 |
^ rslt |
|
6593 |
! |
|
6594 |
||
6595 |
printStringPaddedTo:size |
|
6596 |
"return a printed representation of the receiver, |
|
6597 |
padded with spaces (at the right) up to size. |
|
6598 |
If the printString is longer than size, |
|
6599 |
it is returned unchanged (i.e. not truncated)" |
|
6600 |
||
6601 |
^ self printStringPaddedTo:size with:(Character space) |
|
6602 |
||
6603 |
" |
|
6604 |
123 printStringPaddedTo:10 |
|
6605 |
1234567890123456 printStringPaddedTo:10 |
|
6606 |
'hello' printStringPaddedTo:10 |
|
6607 |
" |
|
6608 |
! |
|
6609 |
||
6610 |
printStringPaddedTo:size ifLarger:alternative |
|
6611 |
"return a printed representation of the receiver, |
|
6612 |
padded with spaces (at the right) up to size. |
|
6613 |
If the resulting printString is too large, |
|
6614 |
return the result from evaluating alternative." |
|
6615 |
||
6616 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
6617 |
||
6618 |
" |
|
6619 |
12 printStringPaddedTo:3 ifLarger:['***'] |
|
6620 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
6621 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
6622 |
" |
|
6623 |
! |
|
6624 |
||
6625 |
printStringPaddedTo:size with:padCharacter |
|
6626 |
"return a printed representation of the receiver, |
|
6627 |
padded with padCharacter (at the right) up to size. |
|
6628 |
If the printString is longer than size, |
|
6629 |
it is returned unchanged (i.e. not truncated)" |
|
6630 |
||
6631 |
^ (self printString) paddedTo:size with:padCharacter |
|
6632 |
||
6633 |
" |
|
6634 |
123 printStringPaddedTo:10 with:$. |
|
6635 |
123 printStringPaddedTo:10 with:$* |
|
6636 |
123 printStringPaddedTo:3 with:$* |
|
6637 |
1234 printStringPaddedTo:3 with:$* |
|
6638 |
" |
|
6639 |
! |
|
6640 |
||
6641 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
6642 |
"return a printed representation of the receiver, |
|
6643 |
padded with padCharacter (at the right) up to size. |
|
6644 |
If the resulting printString is too large, |
|
6645 |
return the result from evaluating alternative." |
|
6646 |
||
6647 |
|s| |
|
6648 |
||
6649 |
s := self printString. |
|
6650 |
s size > size ifTrue:[^ alternative value]. |
|
6651 |
^ s paddedTo:size with:padCharacter |
|
6652 |
||
6653 |
" |
|
6654 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6655 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6656 |
" |
|
6657 |
! |
|
6658 |
||
6659 |
printStringRightAdjustLen:size |
|
6660 |
"obsolete - just a name confusion. |
|
6661 |
This method will go away ..." |
|
6662 |
||
6663 |
^ self printStringLeftPaddedTo:size |
|
6664 |
! |
|
6665 |
||
6666 |
printStringZeroPaddedTo:size |
|
6667 |
"return a printed representation of the receiver, |
|
6668 |
padded with zero (at the right) characters up to size. |
|
6669 |
Usually used with float numbers." |
|
6670 |
||
6671 |
^ self printStringPaddedTo:size with:$0 |
|
6672 |
||
6673 |
" |
|
6674 |
123.0 printStringZeroPaddedTo:10 |
|
6675 |
" |
|
6676 |
! |
|
6677 |
||
8287 | 6678 |
printfPrintString:ignoredFormat |
6679 |
"fallback to default printString |
|
6680 |
(for compatibility with float and integer-printing)" |
|
6681 |
||
6682 |
^ self printString |
|
6683 |
! |
|
6684 |
||
5755 | 6685 |
store |
6686 |
"store the receiver on standard output. |
|
6687 |
this method is useless, but included for compatibility." |
|
6688 |
||
6689 |
self storeOn:Stdout |
|
6690 |
! |
|
6691 |
||
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6692 |
storeArrayElementOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6693 |
"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
|
6694 |
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
|
6695 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6696 |
^ 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
|
6697 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6698 |
|
5755 | 6699 |
storeCR |
6700 |
"store the receiver on standard output; append a carriage return." |
|
6701 |
||
6702 |
self store. |
|
6703 |
Character cr print |
|
6704 |
||
6705 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
6706 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
6707 |
! |
|
6708 |
||
6709 |
storeNl |
|
6710 |
"store the receiver on standard output; append a newline. |
|
6711 |
This method is included for backward compatibility- use #storeCR." |
|
6712 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6713 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6714 |
|
5755 | 6715 |
self storeCR. |
6716 |
||
6717 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
6718 |
! |
|
6719 |
||
6720 |
storeOn:aStream |
|
6721 |
"store the receiver on aStream; i.e. print an expression which will |
|
6722 |
reconstruct the receiver. |
|
6723 |
Notice, that no self referencing or cyclic objects can be represented |
|
6724 |
in this format. |
|
6725 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6726 |
||
6727 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
6728 |
||
6729 |
thisContext isRecursive ifTrue:[ |
|
6654 | 6730 |
Object recursiveStoreStringSignal raiseRequestWith:self. |
6731 |
('Object [error]: storeString of self referencing object.') errorPrintCR. |
|
6732 |
aStream nextPutAll:'#("recursive")'. |
|
6733 |
^ self |
|
5755 | 6734 |
]. |
6735 |
||
6736 |
myClass := self class. |
|
6737 |
aStream nextPut:$(. |
|
6738 |
aStream nextPutAll:self class name. |
|
6739 |
||
6740 |
hasSemi := false. |
|
6741 |
myClass isVariable ifTrue:[ |
|
6654 | 6742 |
aStream nextPutAll:' basicNew:'. |
6743 |
self basicSize printOn:aStream |
|
5755 | 6744 |
] ifFalse:[ |
6654 | 6745 |
aStream nextPutAll:' basicNew' |
5755 | 6746 |
]. |
6747 |
||
6748 |
sz := myClass instSize. |
|
6749 |
1 to:sz do:[:i | |
|
6654 | 6750 |
aStream nextPutAll:' instVarAt:'. |
6751 |
i printOn:aStream. |
|
6752 |
aStream nextPutAll:' put:'. |
|
6753 |
(self instVarAt:i) storeOn:aStream. |
|
6754 |
aStream nextPut:$;. |
|
6755 |
hasSemi := true |
|
5755 | 6756 |
]. |
6757 |
myClass isVariable ifTrue:[ |
|
6654 | 6758 |
sz := self basicSize. |
6759 |
1 to:sz do:[:i | |
|
6760 |
aStream nextPutAll:' basicAt:'. |
|
6761 |
i printOn:aStream. |
|
6762 |
aStream nextPutAll:' put:'. |
|
6763 |
(self basicAt:i) storeOn:aStream. |
|
6764 |
aStream nextPut:$;. |
|
6765 |
hasSemi := true |
|
6766 |
] |
|
5755 | 6767 |
]. |
6768 |
hasSemi ifTrue:[ |
|
6654 | 6769 |
aStream nextPutAll:' yourself' |
5755 | 6770 |
]. |
6771 |
aStream nextPut:$). |
|
6772 |
||
6773 |
" |
|
6774 |
|s| |
|
6775 |
||
6776 |
s := WriteStream on:(String new). |
|
6777 |
('hello' -> 'world') storeOn:s. |
|
6778 |
s := ReadStream on:(s contents). |
|
6779 |
(Object readFrom:s) inspect |
|
6780 |
" |
|
6781 |
" |
|
6782 |
|s| |
|
6783 |
||
6784 |
s := 'data' asFilename writeStream. |
|
6785 |
('hello' -> 'world') storeOn:s. |
|
6786 |
s close. |
|
6787 |
||
6788 |
s := 'data' asFilename readStream. |
|
6789 |
(Object readFrom:s) inspect |
|
6790 |
" |
|
6791 |
||
6792 |
"does not work example:" |
|
6793 |
" |
|
6794 |
|s a| |
|
6795 |
||
6796 |
a := Array new:2. |
|
6797 |
a at:1 put:a. |
|
6798 |
||
6799 |
s := 'data' asFilename writeStream. |
|
6800 |
a storeOn:s. |
|
6801 |
s close. |
|
6802 |
||
6803 |
s := 'data' asFilename readStream. |
|
6804 |
(Object readFrom:s) inspect |
|
6805 |
" |
|
6806 |
||
6807 |
"Modified: 28.1.1997 / 00:36:12 / cg" |
|
6808 |
! |
|
6809 |
||
6810 |
storeString |
|
6811 |
"return a string representing an expression to reconstruct the receiver. |
|
6812 |
Notice, that no self referencing or cyclic objects can be represented |
|
6813 |
in this format. |
|
6814 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6815 |
||
6816 |
|s| |
|
6817 |
||
6818 |
s := WriteStream on:(String new:50). |
|
6819 |
self storeOn:s. |
|
6820 |
^ s contents |
|
6821 |
! ! |
|
6822 |
||
6823 |
!Object methodsFor:'queries'! |
|
6824 |
||
6825 |
basicSize |
|
6826 |
"return the number of the receivers indexed instance variables, |
|
6827 |
0 if it has none. |
|
6828 |
||
6829 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
6830 |
||
6831 |
%{ /* NOCONTEXT */ |
|
6832 |
||
8909 | 6833 |
REGISTER INT nbytes; |
5755 | 6834 |
REGISTER OBJ myClass; |
6835 |
int nInstBytes; |
|
6836 |
||
6837 |
/* |
|
6838 |
* notice the missing test for self being a nonNilObject - |
|
6839 |
* this can be done since basicSize is defined both in UndefinedObject |
|
6840 |
* and SmallInteger |
|
6841 |
*/ |
|
6842 |
myClass = __qClass(self); |
|
6843 |
nbytes = __qSize(self); |
|
6844 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) ); |
|
6845 |
||
6846 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
6654 | 6847 |
case __MASKSMALLINT(POINTERARRAY): |
6848 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
6849 |
nbytes -= nInstBytes; |
|
8913 | 6850 |
RETURN ( __mkSmallInteger(__BYTES2OBJS__(nbytes)) ); |
6654 | 6851 |
|
6852 |
case __MASKSMALLINT(BYTEARRAY): |
|
6853 |
nbytes -= nInstBytes; |
|
8913 | 6854 |
RETURN ( __mkSmallInteger(nbytes / sizeof(char)) ); |
6654 | 6855 |
|
6856 |
case __MASKSMALLINT(FLOATARRAY): |
|
6857 |
nbytes -= nInstBytes; |
|
8913 | 6858 |
RETURN ( __mkSmallInteger(nbytes / sizeof(float)) ); |
6654 | 6859 |
|
6860 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 6861 |
#ifdef __NEED_DOUBLE_ALIGN |
6654 | 6862 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
5755 | 6863 |
#endif |
6654 | 6864 |
nbytes -= nInstBytes; |
8913 | 6865 |
RETURN ( __mkSmallInteger(nbytes / sizeof(double)) ); |
6654 | 6866 |
|
6867 |
case __MASKSMALLINT(WORDARRAY): |
|
6868 |
case __MASKSMALLINT(SWORDARRAY): |
|
6869 |
nbytes -= nInstBytes; |
|
8913 | 6870 |
RETURN ( __mkSmallInteger(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */ |
6654 | 6871 |
|
6872 |
case __MASKSMALLINT(LONGARRAY): |
|
6873 |
case __MASKSMALLINT(SLONGARRAY): |
|
6874 |
nbytes -= nInstBytes; |
|
8913 | 6875 |
RETURN ( __mkSmallInteger(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */ |
6654 | 6876 |
|
6877 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
6878 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 6879 |
#ifdef __NEED_LONGLONG_ALIGN |
6654 | 6880 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
5755 | 6881 |
#endif |
6654 | 6882 |
nbytes -= nInstBytes; |
8913 | 6883 |
RETURN ( __mkSmallInteger(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */ |
5755 | 6884 |
} |
6885 |
%}. |
|
6886 |
^ 0 |
|
6887 |
! |
|
6888 |
||
6889 |
byteSize |
|
6890 |
"return the number of bytes in the receivers indexed instance variables, |
|
6891 |
0 if it has none. This only returns non-zero for non-pointer indexed |
|
6892 |
instvars i.e. byteArrays, wordArrays etc. |
|
6893 |
Notice: for Strings the returned size may look strange. |
|
6894 |
Only useful with binary storage." |
|
6895 |
||
6896 |
|myClass| |
|
6897 |
||
6898 |
myClass := self class. |
|
6899 |
myClass isVariable ifTrue:[ |
|
6654 | 6900 |
myClass isPointers ifFalse:[ |
6901 |
myClass isBytes ifTrue:[ |
|
6902 |
^ self basicSize. |
|
6903 |
]. |
|
6904 |
myClass isWords ifTrue:[ |
|
6905 |
^ self basicSize * 2. |
|
6906 |
]. |
|
6907 |
myClass isSignedWords ifTrue:[ |
|
6908 |
^ self basicSize * 2. |
|
6909 |
]. |
|
6910 |
myClass isLongs ifTrue:[ |
|
6911 |
^ self basicSize * 4. |
|
6912 |
]. |
|
6913 |
myClass isSignedLongs ifTrue:[ |
|
6914 |
^ self basicSize * 4. |
|
6915 |
]. |
|
6916 |
myClass isLongLongs ifTrue:[ |
|
6917 |
^ self basicSize * 8. |
|
6918 |
]. |
|
6919 |
myClass isSignedLongLongs ifTrue:[ |
|
6920 |
^ self basicSize * 8. |
|
6921 |
]. |
|
6922 |
myClass isFloats ifTrue:[ |
|
6923 |
^ self basicSize * (ExternalBytes sizeofFloat) |
|
6924 |
]. |
|
6925 |
myClass isDoubles ifTrue:[ |
|
6926 |
^ self basicSize * (ExternalBytes sizeofDouble) |
|
6927 |
]. |
|
8789 | 6928 |
self error:'unknown variable size class species'. |
6654 | 6929 |
] |
5755 | 6930 |
]. |
6931 |
^ 0 |
|
6932 |
||
6933 |
" |
|
6934 |
Point new byteSize |
|
6935 |
'hello' byteSize |
|
6936 |
(ByteArray with:1 with:2) byteSize |
|
6937 |
(FloatArray with:1.5) byteSize |
|
6938 |
(DoubleArray with:1.5) byteSize |
|
6939 |
(WordArray with:1 with:2) byteSize |
|
6940 |
" |
|
6941 |
! |
|
6942 |
||
6943 |
class |
|
6944 |
"return the receivers class" |
|
6945 |
||
6946 |
%{ /* NOCONTEXT */ |
|
6947 |
||
6948 |
RETURN ( __Class(self) ); |
|
6949 |
%} |
|
6950 |
! |
|
6951 |
||
6952 |
respondsTo:aSelector |
|
6953 |
"return true, if the receiver implements a method with selector equal |
|
6954 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
6955 |
receivers class or one of its superclasses. |
|
6956 |
||
6957 |
Notice, that this does not imply, that such a message can be sent without |
|
6958 |
an error being raised. For example, an implementation could send |
|
6959 |
#shouldNotImplement or #subclassResponsibility." |
|
6960 |
||
6961 |
" |
|
6962 |
should we go via the cache, or search (by class) ? |
|
6963 |
The first is faster, most of the time; while the 2nd fills |
|
6964 |
the cache with useless data if this is sent in a loop over all objects. |
|
6965 |
For now, use the cache ... |
|
6966 |
" |
|
6967 |
%{ /* NOCONTEXT */ |
|
6968 |
||
6969 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
6654 | 6970 |
RETURN ( false ); |
5755 | 6971 |
} |
6972 |
RETURN ( true ); |
|
6973 |
%} |
|
6974 |
. |
|
6975 |
^ self class canUnderstand:aSelector |
|
6976 |
||
6977 |
||
6978 |
"'aString' respondsTo:#+" |
|
6979 |
"'aString' respondsTo:#," |
|
6980 |
"'aString' respondsTo:#collect:" |
|
6981 |
! |
|
6982 |
||
6983 |
respondsToArithmetic |
|
6984 |
"return true, if the receiver responds to arithmetic messages. |
|
6985 |
false is returned here - the method is redefined in ArithmeticValue." |
|
6986 |
||
6987 |
^ false |
|
6988 |
! |
|
6989 |
||
6990 |
size |
|
6991 |
"return the number of the receivers indexed instance variables; |
|
6992 |
this method may be redefined in subclasses" |
|
6993 |
||
6994 |
^ self basicSize |
|
6995 |
! |
|
6996 |
||
6997 |
species |
|
6998 |
"return a class which is similar to (or the same as) the receivers class. |
|
6999 |
This is used to create an appropriate object when creating derived |
|
7000 |
copies in the collection classes (sometimes redefined)." |
|
7001 |
||
7002 |
^ self class |
|
7003 |
! |
|
7004 |
||
7005 |
yourself |
|
7006 |
"return the receiver - used for cascades to return self at the end" |
|
7007 |
||
7008 |
^ self |
|
7009 |
! ! |
|
7010 |
||
7011 |
!Object methodsFor:'secure message sending'! |
|
7012 |
||
7013 |
askFor:aSelector |
|
7014 |
"try to send the receiver the message, aSelector. |
|
7015 |
If it does not understand it, return false. |
|
7016 |
Otherwise the real value returned. |
|
7017 |
Useful to send messages such as: #isColor to unknown |
|
7018 |
receivers." |
|
7019 |
||
7020 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
7021 |
||
7022 |
" |
|
7023 |
1 askFor:#isColor |
|
7024 |
Color red askFor:#isColor |
|
7025 |
||
7026 |
1 askFor:#isFoo |
|
7027 |
Color red askFor:#isFoo |
|
7028 |
" |
|
7029 |
! |
|
7030 |
||
7031 |
perform:aSelector ifNotUnderstood:exceptionBlock |
|
7032 |
"try to send message aSelector to the receiver. |
|
7033 |
If its understood, return the methods returned value, |
|
7034 |
otherwise return the value of the exceptionBlock" |
|
7035 |
||
7036 |
|val ok| |
|
7037 |
||
6146 | 7038 |
MessageNotUnderstood handle:[:ex | |
6654 | 7039 |
"/ reject, if the bad message is not the one |
7040 |
"/ we have sent originally |
|
8502
7720740cf40f
Use MessageNotUnderstood>>#selector
Stefan Vogel <sv@exept.de>
parents:
8500
diff
changeset
|
7041 |
ex selector == aSelector ifFalse:[ |
6654 | 7042 |
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
|
7043 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7044 |
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
|
7045 |
ex reject |
8413 | 7046 |
]. |
5755 | 7047 |
] do:[ |
6654 | 7048 |
val := self perform:aSelector. |
7049 |
ok := true. |
|
5755 | 7050 |
]. |
7051 |
ok isNil ifTrue:[ |
|
6654 | 7052 |
^ exceptionBlock value |
5755 | 7053 |
]. |
7054 |
^ val |
|
7055 |
||
7056 |
" |
|
7057 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
|
7058 |
1.2345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7059 |
12345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7060 |
" |
|
7061 |
! |
|
7062 |
||
7063 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
7064 |
"try to send message aSelector to the receiver. |
|
7065 |
If its understood, return the methods returned value, |
|
7066 |
otherwise return the value of the exceptionBlock" |
|
7067 |
||
7068 |
|val ok| |
|
7069 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7070 |
MessageNotUnderstood handle:[:ex | |
6654 | 7071 |
"/ reject, if the bad message is not the one |
7072 |
"/ we have sent originally |
|
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7073 |
ex selector == aSelector ifFalse:[ |
6654 | 7074 |
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
|
7075 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7076 |
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
|
7077 |
ex reject |
6654 | 7078 |
] |
5755 | 7079 |
] do:[ |
6654 | 7080 |
val := self perform:aSelector with:argument. |
7081 |
ok := true. |
|
5755 | 7082 |
]. |
7083 |
ok isNil ifTrue:[ |
|
6654 | 7084 |
^ exceptionBlock value |
5755 | 7085 |
]. |
7086 |
^ val |
|
7087 |
||
7088 |
" |
|
7089 |
|unknown| |
|
7090 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7091 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7092 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 7093 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7094 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 7095 |
" |
7096 |
! |
|
7097 |
||
5926 | 7098 |
perform:aSelector with:arg1 with:arg2 ifNotUnderstood:exceptionBlock |
7099 |
"try to send message aSelector to the receiver. |
|
7100 |
If its understood, return the methods returned value, |
|
7101 |
otherwise return the value of the exceptionBlock" |
|
7102 |
||
7103 |
|val ok| |
|
7104 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7105 |
MessageNotUnderstood handle:[:ex | |
6654 | 7106 |
"/ reject, if the bad message is not the one |
7107 |
"/ we have sent originally |
|
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7108 |
ex selector == aSelector ifFalse:[ |
6654 | 7109 |
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
|
7110 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7111 |
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
|
7112 |
ex reject |
6654 | 7113 |
] |
5926 | 7114 |
] do:[ |
6654 | 7115 |
val := self perform:aSelector with:arg1 with:arg2. |
7116 |
ok := true. |
|
5926 | 7117 |
]. |
7118 |
ok isNil ifTrue:[ |
|
6654 | 7119 |
^ exceptionBlock value |
5926 | 7120 |
]. |
7121 |
^ val |
|
7122 |
! |
|
7123 |
||
5755 | 7124 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
7125 |
"try to send message aSelector to the receiver. |
|
7126 |
If its understood, return the methods returned value, |
|
7127 |
otherwise return the value of the exceptionBlock" |
|
7128 |
||
7129 |
|val ok| |
|
7130 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7131 |
MessageNotUnderstood handle:[:ex | |
6654 | 7132 |
"/ reject, if the bad message is not the one |
7133 |
"/ we have sent originally |
|
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7134 |
ex selector == aSelector ifFalse:[ |
6654 | 7135 |
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
|
7136 |
]. |
c16f744e4536
reject in *ifNotUnderstood, if the message is not the one for myself
Claus Gittinger <cg@exept.de>
parents:
6728
diff
changeset
|
7137 |
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
|
7138 |
ex reject |
6654 | 7139 |
] |
5755 | 7140 |
] do:[ |
6654 | 7141 |
val := self perform:aSelector withArguments:argumentArray. |
7142 |
ok := true. |
|
5755 | 7143 |
]. |
7144 |
ok isNil ifTrue:[ |
|
6654 | 7145 |
^ exceptionBlock value |
5755 | 7146 |
]. |
7147 |
^ val |
|
7148 |
||
7149 |
" |
|
7150 |
|unknown| |
|
7151 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7152 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7153 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 7154 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7155 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 7156 |
" |
7157 |
||
7158 |
"Modified: 27.3.1997 / 14:13:16 / cg" |
|
7159 |
! ! |
|
7160 |
||
7161 |
!Object methodsFor:'signal constants'! |
|
7162 |
||
7163 |
messageNotUnderstoodSignal |
|
6146 | 7164 |
^ MessageNotUnderstood |
5755 | 7165 |
|
7166 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
7167 |
! ! |
|
7168 |
||
7169 |
!Object methodsFor:'special queries'! |
|
7170 |
||
7171 |
allOwners |
|
7172 |
"return a collection of all objects referencing the receiver" |
|
7173 |
||
7174 |
^ ObjectMemory whoReferences:self |
|
7175 |
! |
|
7176 |
||
7177 |
references:anObject |
|
7178 |
"return true, if the receiver refers to the argument, anObject. |
|
7179 |
- for debugging only" |
|
7180 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7181 |
^ self referencesObject:anObject |
5755 | 7182 |
|
7183 |
" |
|
7184 |
|v| |
|
7185 |
||
7186 |
v := View new initialize. |
|
7187 |
v references:Display. |
|
7188 |
" |
|
7189 |
! |
|
7190 |
||
7191 |
referencesAny:aCollection |
|
7192 |
"return true, if the receiver refers to any object from |
|
7193 |
the argument, aCollection. |
|
7194 |
- for debugging only" |
|
7195 |
||
7196 |
%{ |
|
7197 |
OBJ cls, flags; |
|
7198 |
int nInsts, inst; |
|
7199 |
||
7200 |
if (! __isNonNilObject(self)) { |
|
6654 | 7201 |
RETURN (false); |
5755 | 7202 |
} |
7203 |
||
8934 | 7204 |
if (__isArrayLike(aCollection)) { |
6654 | 7205 |
int nObjs = __arraySize(aCollection); |
7206 |
char *minAddr = 0, *maxAddr = 0; |
|
7207 |
||
7208 |
if (nObjs == 0) { |
|
7209 |
RETURN (false); |
|
7210 |
} |
|
7211 |
||
7212 |
/* |
|
7213 |
* a little optimization: use the fact that all old objects |
|
7214 |
* refering to a new object are on the remSet; if I am not, |
|
7215 |
* a trivial reject is possible, if all objects are newbees. |
|
7216 |
* as a side effect, gather min/max addresses |
|
7217 |
*/ |
|
7218 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
7219 |
int allNewBees = 1; |
|
7220 |
int i; |
|
7221 |
||
7222 |
minAddr = (char *)(__ArrayInstPtr(aCollection)->a_element[0]); |
|
7223 |
maxAddr = minAddr; |
|
7224 |
||
7225 |
for (i=0; i<nObjs; i++) { |
|
7226 |
OBJ anObject; |
|
7227 |
||
7228 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7229 |
||
7230 |
if (__isNonNilObject(anObject)) { |
|
7231 |
int spc; |
|
7232 |
||
7233 |
if (((spc = __qSpace(anObject)) != NEWSPACE) && (spc != SURVSPACE)) { |
|
7234 |
allNewBees = 0; |
|
7235 |
} |
|
7236 |
} |
|
7237 |
||
7238 |
if ((char *)anObject < minAddr) { |
|
7239 |
minAddr = (char *)anObject; |
|
7240 |
} else if ((char *)anObject > maxAddr) { |
|
7241 |
maxAddr = (char *)anObject; |
|
7242 |
} |
|
7243 |
} |
|
7244 |
if (allNewBees) { |
|
7245 |
RETURN (false); |
|
7246 |
} |
|
7247 |
} |
|
7248 |
||
7249 |
/* |
|
7250 |
* fetch min/max in searchList (if not already done) |
|
7251 |
*/ |
|
7252 |
if (minAddr == 0) { |
|
7253 |
int i; |
|
7254 |
||
7255 |
for (i=0; i<nObjs; i++) { |
|
7256 |
OBJ anObject; |
|
7257 |
||
7258 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7259 |
if ((char *)anObject < minAddr) { |
|
7260 |
minAddr = (char *)anObject; |
|
7261 |
} else if ((char *)anObject > maxAddr) { |
|
7262 |
maxAddr = (char *)anObject; |
|
7263 |
} |
|
7264 |
} |
|
7265 |
} |
|
7266 |
||
7267 |
cls = __qClass(self); |
|
7268 |
if (((char *)cls >= minAddr) && ((char *)cls <= maxAddr)) { |
|
5755 | 7269 |
#if defined(memsrch4) |
6654 | 7270 |
if (memsrch4(__arrayVal(aCollection), (INT)cls, nObjs)) { |
7271 |
RETURN (true); |
|
7272 |
} |
|
5755 | 7273 |
#else |
6654 | 7274 |
int i; |
7275 |
||
7276 |
for (i=0; i<nObjs; i++) { |
|
7277 |
OBJ anObject; |
|
7278 |
||
7279 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7280 |
if (cls == anObject) { |
|
7281 |
RETURN (true); |
|
7282 |
} |
|
7283 |
} |
|
5755 | 7284 |
#endif /* memsrch4 */ |
6654 | 7285 |
} |
7286 |
||
7287 |
flags = __ClassInstPtr(cls)->c_flags; |
|
7288 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
7289 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
7290 |
} else { |
|
7291 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
7292 |
} |
|
7293 |
if (! nInsts) { |
|
7294 |
RETURN (false); |
|
7295 |
} |
|
7296 |
||
7297 |
if (nObjs == 1) { |
|
7298 |
/* better reverse the loop */ |
|
7299 |
OBJ anObject; |
|
7300 |
||
7301 |
anObject = __ArrayInstPtr(aCollection)->a_element[0]; |
|
5755 | 7302 |
#if defined(memsrch4) |
6654 | 7303 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
7304 |
RETURN (true); |
|
7305 |
} |
|
5755 | 7306 |
#else |
6654 | 7307 |
for (inst=0; inst<nInsts; inst++) { |
7308 |
if ((__InstPtr(self)->i_instvars[inst]) == anObject) { |
|
7309 |
RETURN (true); |
|
7310 |
} |
|
7311 |
} |
|
5755 | 7312 |
#endif |
6654 | 7313 |
RETURN (false); |
7314 |
} |
|
7315 |
||
7316 |
for (inst=0; inst<nInsts; inst++) { |
|
7317 |
OBJ instVar = __InstPtr(self)->i_instvars[inst]; |
|
7318 |
int i; |
|
7319 |
||
7320 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
5755 | 7321 |
#if defined(memsrch4) |
6654 | 7322 |
if (memsrch4(__arrayVal(aCollection), (INT)instVar, nObjs)) { |
7323 |
RETURN (true); |
|
7324 |
} |
|
5755 | 7325 |
#else |
6654 | 7326 |
for (i=0; i<nObjs; i++) { |
7327 |
OBJ anObject; |
|
7328 |
||
7329 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7330 |
if (instVar == anObject) { |
|
7331 |
RETURN (true); |
|
7332 |
} |
|
7333 |
} |
|
5755 | 7334 |
#endif /* memsrch4 */ |
6654 | 7335 |
} |
7336 |
} |
|
7337 |
RETURN (false); |
|
5755 | 7338 |
} |
7339 |
%}. |
|
7340 |
||
7341 |
aCollection do:[:el | |
|
8555
2bff17ee9c22
Use #referencesObject instead of #references:
Stefan Vogel <sv@exept.de>
parents:
8546
diff
changeset
|
7342 |
(self referencesObject:el) ifTrue:[^ true]. |
5755 | 7343 |
]. |
7344 |
^ false |
|
7345 |
! |
|
7346 |
||
7347 |
referencesDerivedInstanceOf:aClass |
|
7348 |
"return true, if the receiver refers to an instance of |
|
7349 |
the argument, aClass or its subclass. This method exists |
|
7350 |
to support searching for users of a class." |
|
7351 |
||
7352 |
|myClass |
|
7353 |
numInst "{ Class: SmallInteger }" | |
|
7354 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7355 |
"check the class" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7356 |
(self isKindOf:aClass) ifTrue:[^ true]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7357 |
|
5755 | 7358 |
myClass := self class. |
7359 |
"check the instance variables" |
|
7360 |
numInst := myClass instSize. |
|
7361 |
1 to:numInst do:[:i | |
|
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7362 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
5755 | 7363 |
]. |
7364 |
||
7365 |
"check the indexed variables" |
|
7366 |
myClass isVariable ifTrue:[ |
|
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7367 |
myClass isPointers ifFalse:[ |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7368 |
"no need to search in non pointer fields" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7369 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7370 |
]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7371 |
numInst := self basicSize. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7372 |
1 to:numInst do:[:i | |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7373 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7374 |
] |
5755 | 7375 |
]. |
7376 |
^ false |
|
7377 |
||
7378 |
" |
|
7379 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
|
7380 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
7381 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
7382 |
" |
|
7383 |
! |
|
7384 |
||
9279 | 7385 |
referencesForWhich:checkBlock do:actionBlock |
7386 |
|myClass inst |
|
7387 |
numInst "{ Class: SmallInteger }" | |
|
7388 |
||
7389 |
myClass := self class. |
|
7390 |
"check the instance variables" |
|
7391 |
numInst := myClass instSize. |
|
7392 |
1 to:numInst do:[:i | |
|
7393 |
inst := self instVarAt:i. |
|
7394 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
7395 |
]. |
|
7396 |
||
7397 |
"check the indexed variables" |
|
7398 |
myClass isVariable ifTrue:[ |
|
7399 |
myClass isPointers ifTrue:[ |
|
7400 |
"no need to search in non pointer fields" |
|
7401 |
||
7402 |
numInst := self basicSize. |
|
7403 |
1 to:numInst do:[:i | |
|
7404 |
inst := self basicAt:i. |
|
7405 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
7406 |
] |
|
7407 |
] |
|
7408 |
]. |
|
7409 |
||
7410 |
" |
|
7411 |
(1 @ 3.4) referencesForWhich:[:i | i isFloat] do:[:i | Transcript showCR:i] |
|
7412 |
" |
|
7413 |
! |
|
7414 |
||
5755 | 7415 |
referencesInstanceOf:aClass |
7416 |
"return true, if the receiver refers to an instance of |
|
7417 |
the argument, aClass.This method exists |
|
7418 |
to support searching for users of a class." |
|
7419 |
||
7420 |
|myClass |
|
7421 |
numInst "{ Class: SmallInteger }" | |
|
7422 |
||
7423 |
myClass := self class. |
|
7424 |
||
7425 |
"check the class" |
|
7426 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
7427 |
||
7428 |
"check the instance variables" |
|
7429 |
numInst := myClass instSize. |
|
7430 |
1 to:numInst do:[:i | |
|
6654 | 7431 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
5755 | 7432 |
]. |
7433 |
||
7434 |
"check the indexed variables" |
|
7435 |
myClass isVariable ifTrue:[ |
|
6654 | 7436 |
myClass isPointers ifFalse:[ |
7437 |
"no need to search in non-pointer indexed fields" |
|
7438 |
myClass isLongs ifTrue:[ |
|
7439 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
7440 |
] ifFalse:[ |
|
7441 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
7442 |
^ aClass == SmallInteger |
|
7443 |
] |
|
7444 |
]. |
|
7445 |
numInst := self basicSize. |
|
7446 |
1 to:numInst do:[:i | |
|
7447 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
7448 |
] |
|
5755 | 7449 |
]. |
7450 |
^ false |
|
7451 |
||
7452 |
" |
|
7453 |
(1 @ 3.4) referencesInstanceOf:Float |
|
7454 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
7455 |
View new initialize referencesInstanceOf:(Display class) |
|
7456 |
" |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7457 |
! |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7458 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7459 |
referencesObject:anObject |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7460 |
"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
|
7461 |
- for debugging only" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7462 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7463 |
%{ /* NOCONTEXT */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7464 |
OBJ cls, flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7465 |
int nInsts, i; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7466 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7467 |
if (! __isNonNilObject(self)) { |
6654 | 7468 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7469 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7470 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7471 |
/* |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7472 |
* 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
|
7473 |
* 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
|
7474 |
* 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
|
7475 |
*/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7476 |
if (__isNonNilObject(anObject)) { |
6654 | 7477 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7478 |
int spc; |
|
7479 |
||
7480 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7481 |
RETURN (false); |
|
7482 |
} |
|
7483 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7484 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7485 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7486 |
cls = __qClass(self); |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7487 |
if (cls == anObject) { |
6654 | 7488 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7489 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7490 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7491 |
flags = __ClassInstPtr(cls)->c_flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7492 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
6654 | 7493 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7494 |
} else { |
6654 | 7495 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7496 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7497 |
if (! nInsts) { |
6654 | 7498 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7499 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7500 |
#if defined(memsrch4) |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7501 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
6654 | 7502 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7503 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7504 |
#else |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7505 |
for (i=0; i<nInsts; i++) { |
6654 | 7506 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7507 |
RETURN (true); |
|
7508 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7509 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7510 |
#endif /* memsrch4 */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7511 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7512 |
%}. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7513 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7514 |
"/ |myClass |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7515 |
"/ numInst "{ Class: SmallInteger }" | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7516 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7517 |
"/ myClass := self class. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7518 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7519 |
"/ "check the class" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7520 |
"/ (myClass == anObject) ifTrue:[^ true]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7521 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7522 |
"/ "check the instance variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7523 |
"/ numInst := myClass instSize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7524 |
"/ 1 to:numInst do:[:i | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7525 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7526 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7527 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7528 |
"/ "check the indexed variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7529 |
"/ myClass isVariable ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7530 |
"/ myClass isPointers ifFalse:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7531 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7532 |
"/ "/ 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
|
7533 |
"/ "/ 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
|
7534 |
"/ "/ 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
|
7535 |
"/ "/ 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
|
7536 |
"/ "/ 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
|
7537 |
"/ "/ 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
|
7538 |
"/ "/ 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
|
7539 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7540 |
"/ ^ false. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7541 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7542 |
"/ "/ alternative: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7543 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7544 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7545 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7546 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7547 |
"/ "/ 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
|
7548 |
"/ "/ idenitytIndex method, use it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7549 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7550 |
"/ myClass == Array ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7551 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7552 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7553 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7554 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7555 |
"/ "/ otherwise, do it the slow way |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7556 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7557 |
"/ numInst := self basicSize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7558 |
"/ 1 to:numInst do:[:i | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7559 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7560 |
"/ ] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7561 |
"/ ]. |
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 |
^ false |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7564 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7565 |
" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7566 |
|v| |
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 |
v := View new initialize. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7569 |
v references:Display. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7570 |
" |
5755 | 7571 |
! ! |
7572 |
||
7573 |
!Object methodsFor:'synchronized evaluation'! |
|
7574 |
||
7575 |
freeSynchronizationSemaphore |
|
7576 |
"free synchronizationSemaphore. May be used, to save memory when |
|
7577 |
an object is no longer used synchronized." |
|
7578 |
||
7579 |
|sema| |
|
7580 |
||
7581 |
sema := self synchronizationSemaphore. |
|
7582 |
sema notNil ifTrue:[ |
|
6654 | 7583 |
sema wait. "/ get lock |
7584 |
self synchronizationSemaphore:nil. |
|
5755 | 7585 |
]. |
7586 |
||
7587 |
" |
|
7588 |
self synchronized:[]. |
|
7589 |
self synchronizationSemaphore. |
|
7590 |
self freeSynchronizationSemaphore. |
|
7591 |
" |
|
7592 |
||
7593 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
7594 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
7595 |
! |
|
7596 |
||
7597 |
synchronizationSemaphore |
|
7598 |
"return the synchronization semaphore for myself. |
|
7599 |
subclasses may redefine" |
|
7600 |
||
7601 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
7602 |
||
7603 |
" |
|
7604 |
self synchronizationSemaphore |
|
7605 |
" |
|
7606 |
||
7607 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
7608 |
! |
|
7609 |
||
7610 |
synchronizationSemaphore:aSemaphore |
|
7611 |
"set the synchronisationSemaphore for myself. |
|
7612 |
subclasses may redefine this method" |
|
7613 |
||
7614 |
aSemaphore isNil ifTrue:[ |
|
6654 | 7615 |
"/ remove Semaphore |
7616 |
SynchronizationSemaphores removeKey:self ifAbsent:nil. |
|
5755 | 7617 |
] ifFalse:[ |
6654 | 7618 |
SynchronizationSemaphores at:self put:aSemaphore. |
5755 | 7619 |
]. |
7620 |
||
7621 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
7622 |
! |
|
7623 |
||
7624 |
synchronized:aBlock |
|
7625 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
7626 |
||
6600 | 7627 |
|sema wasBlocked| |
7628 |
||
7629 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5755 | 7630 |
|
7631 |
sema := self synchronizationSemaphore. |
|
7632 |
sema isNil ifTrue:[ |
|
8481
d12d202b6ddb
Set name of synchronization sema
Stefan Vogel <sv@exept.de>
parents:
8441
diff
changeset
|
7633 |
sema := RecursionLock new name:self className. |
6600 | 7634 |
self synchronizationSemaphore:sema. |
5755 | 7635 |
]. |
7636 |
||
6600 | 7637 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
7211
87f5d25b5c3d
Make synchronizationSemaphore a recursionLock
Stefan Vogel <sv@exept.de>
parents:
7208
diff
changeset
|
7638 |
sema critical:aBlock. |
5755 | 7639 |
|
7640 |
" |
|
7641 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
7642 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
7643 |
" |
|
7644 |
||
7645 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
7646 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
|
7647 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
|
7648 |
! ! |
|
7649 |
||
7650 |
!Object methodsFor:'system primitives'! |
|
7651 |
||
7652 |
asOop |
|
7653 |
"ST-80 compatibility: |
|
7654 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
7655 |
or index); since ST/X has no such thing, and the objects address cannot |
|
7656 |
be used (since its changing over time), we return the objects identityHash |
|
7657 |
key, which provides (at least) some identity indication. |
|
7658 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
7659 |
key of two non-identical objects may be the same. |
|
7660 |
You'd better not use it - especially do not misuse it." |
|
7661 |
||
7662 |
^ self identityHash |
|
7663 |
||
7664 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
7665 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
7666 |
! |
|
7667 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7668 |
beImmutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7669 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7670 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7671 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7672 |
if (! __isNonNilObject(self)) { |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7673 |
RETURN (self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7674 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7675 |
__beImmutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7676 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7677 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7678 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7679 |
beMutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7680 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7681 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7682 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7683 |
if (! __isNonNilObject(self)) { |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7684 |
RETURN (self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7685 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7686 |
__beMutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7687 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7688 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7689 |
|
5755 | 7690 |
become:anotherObject |
7691 |
"make all references to the receiver become references to anotherObject |
|
7692 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
|
7693 |
This can be a very dangerous operation - be warned. |
|
7694 |
In general, using #become: should be avoided if possible, since it may |
|
7695 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
7696 |
||
7697 |
This may also be an expensive (i.e. slow) operation, |
|
7698 |
since in the worst case, the whole memory has to be searched for |
|
7699 |
references to the two objects (although the primitive tries hard to |
|
7700 |
limit the search, for acceptable performance in most cases). |
|
7701 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7702 |
or nil, or is a context of a living method (i.e. one that has not already |
|
7703 |
returned). |
|
7704 |
(notice that #become: is not used heavily by the system |
|
7705 |
- the Collection-classes have been rewritten to not use it.)" |
|
7706 |
%{ |
|
7707 |
if (__primBecome(self, anotherObject)) { |
|
6654 | 7708 |
RETURN ( self ); |
5755 | 7709 |
} |
7710 |
%}. |
|
7711 |
self primitiveFailed |
|
7712 |
! |
|
7713 |
||
7714 |
becomeNil |
|
7715 |
"make all references to the receiver become nil - effectively getting |
|
7716 |
rid of the receiver. |
|
7717 |
This can be a very dangerous operation - be warned. |
|
7718 |
||
7719 |
This may be an expensive (i.e. slow) operation. |
|
7720 |
The receiver may not be a SmallInteger or a context of a living method." |
|
7721 |
||
7722 |
%{ |
|
7723 |
if (__primBecomeNil(self)) { |
|
6654 | 7724 |
RETURN ( nil ); |
5755 | 7725 |
} |
7726 |
%}. |
|
7727 |
self primitiveFailed |
|
7728 |
! |
|
7729 |
||
7730 |
becomeSameAs:anotherObject |
|
7731 |
"make all references to the receiver become references to anotherObject |
|
7732 |
but NOT vice versa (as done in #become:). |
|
7733 |
This can be a very dangerous operation - be warned. |
|
7734 |
In general, using #become: should be avoided if possible, since it may |
|
7735 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
7736 |
||
7737 |
This may also be an expensive (i.e. slow) operation, |
|
7738 |
since in the worst case, the whole memory has to be searched for |
|
7739 |
references to the two objects (although the primitive tries hard to |
|
7740 |
limit the search, for acceptable performance in most cases). |
|
7741 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7742 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
7743 |
%{ |
|
7744 |
if (__primBecomeSameAs(self, anotherObject)) { |
|
6654 | 7745 |
RETURN ( self ); |
5755 | 7746 |
} |
7747 |
%}. |
|
7748 |
self primitiveFailed |
|
7749 |
! |
|
7750 |
||
7751 |
changeClassTo:otherClass |
|
7752 |
"changes the class of the receiver to the argument, otherClass. |
|
7753 |
This is only allowed (possible), if the receivers class and the argument |
|
7754 |
have the same structure (i.e. number of named instance variables and |
|
7755 |
type of indexed instance variables). |
|
7756 |
If the structures do not match, or any of the original class or new class |
|
7757 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
7758 |
||
7759 |
|myClass ok| |
|
7760 |
||
9405 | 7761 |
otherClass autoload. |
7762 |
||
5755 | 7763 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
7764 |
%{ |
|
7765 |
{ |
|
6533 | 7766 |
OBJ other = otherClass; |
7767 |
||
7768 |
if (__isNonNilObject(self) |
|
7769 |
&& __isNonNilObject(other) |
|
7770 |
&& (other != UndefinedObject) |
|
7771 |
&& (other != SmallInteger)) { |
|
7772 |
ok = true; |
|
7773 |
} else { |
|
7774 |
ok = false; |
|
7775 |
} |
|
5755 | 7776 |
} |
7777 |
%}. |
|
7778 |
ok ifTrue:[ |
|
6533 | 7779 |
ok := false. |
7780 |
myClass := self class. |
|
7781 |
myClass flags == otherClass flags ifTrue:[ |
|
7782 |
myClass instSize == otherClass instSize ifTrue:[ |
|
7783 |
"same instance layout and types: its ok to do it" |
|
7784 |
ok := true. |
|
7785 |
] ifFalse:[ |
|
7786 |
myClass isPointers ifTrue:[ |
|
7787 |
myClass isVariable ifTrue:[ |
|
7788 |
ok := true |
|
7789 |
] |
|
7790 |
] |
|
7791 |
] |
|
7792 |
] ifFalse:[ |
|
7793 |
myClass isPointers ifTrue:[ |
|
7794 |
"if newClass is a variable class, with instSize <= my instsize, |
|
7795 |
we can do it (effectively mapping additional instvars into the |
|
7796 |
variable part) - usefulness is questionable, though" |
|
7797 |
||
7798 |
otherClass isPointers ifTrue:[ |
|
7799 |
otherClass isVariable ifTrue:[ |
|
7800 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
7801 |
ifTrue:[ |
|
7802 |
ok := true |
|
7803 |
] |
|
7804 |
] ifFalse:[ |
|
7805 |
otherClass instSize == (myClass instSize + self basicSize) |
|
7806 |
ifTrue:[ |
|
7807 |
ok := true |
|
7808 |
] |
|
7809 |
] |
|
7810 |
] ifFalse:[ |
|
7811 |
"it does not make sense to convert pointers to bytes ..." |
|
7812 |
] |
|
7813 |
] ifFalse:[ |
|
7814 |
"does it make sense, to convert bits ?" |
|
7815 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
7816 |
(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[ |
|
7817 |
ok := true |
|
7818 |
] |
|
7819 |
] |
|
7820 |
] |
|
5755 | 7821 |
]. |
7822 |
ok ifTrue:[ |
|
6533 | 7823 |
"now, change the receivers class ..." |
5755 | 7824 |
%{ |
6533 | 7825 |
{ |
7826 |
OBJ me = self; |
|
7827 |
||
7828 |
__qClass(me) = otherClass; |
|
7829 |
__STORE(me, otherClass); |
|
7830 |
RETURN (me); |
|
7831 |
} |
|
5755 | 7832 |
%}. |
7833 |
]. |
|
9405 | 7834 |
|
5755 | 7835 |
" |
7836 |
the receiver cannot be represented as a instance of |
|
7837 |
the desired class. |
|
7838 |
For example, you cannot change a bitInstance (byteArray etc.) |
|
7839 |
into a pointer object and vice versa. |
|
7840 |
" |
|
7841 |
self primitiveFailed |
|
7842 |
! |
|
7843 |
||
7844 |
changeClassToThatOf:anObject |
|
7845 |
"changes the class of the receiver to that of the argument, anObject. |
|
7846 |
This is only allowed (possible), if the receivers class and the arguments |
|
7847 |
class have the same structure (i.e. number of named instance variables and |
|
7848 |
type of indexed instance variables). If the structures do not match, or any |
|
7849 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
7850 |
||
7851 |
self changeClassTo:(anObject class) |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7852 |
! |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7853 |
|
8935 | 7854 |
isImmutable |
7855 |
"experimental - not yet usable; do not use" |
|
7856 |
||
7857 |
%{ /* NOCONTEXT */ |
|
7858 |
if (! __isNonNilObject(self)) { |
|
7859 |
RETURN (true); |
|
7860 |
} |
|
7861 |
RETURN (__isImmutable(self) ? true : false); |
|
7862 |
%} |
|
7863 |
! |
|
7864 |
||
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7865 |
replaceReferencesTo:anObject with:newRef |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7866 |
"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
|
7867 |
Return true, if any reference was changed. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7868 |
Notice: this does not change the class-reference." |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7869 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7870 |
%{ /* NOCONTEXT */ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7871 |
OBJ cls, flags, anyChange; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7872 |
int nInsts, i; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7873 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7874 |
if (! __isNonNilObject(self)) { |
6654 | 7875 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7876 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7877 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7878 |
/* |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7879 |
* a little optimization: use the fact that all old objects |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7880 |
* 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
|
7881 |
* a trivial reject is possible, if anObject is a newbee |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7882 |
*/ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7883 |
if (__isNonNilObject(anObject)) { |
6654 | 7884 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7885 |
int spc; |
|
7886 |
||
7887 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7888 |
RETURN (false); |
|
7889 |
} |
|
7890 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7891 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7892 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7893 |
cls = __qClass(self); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7894 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7895 |
flags = __ClassInstPtr(cls)->c_flags; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7896 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
6654 | 7897 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7898 |
} else { |
6654 | 7899 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7900 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7901 |
if (! nInsts) { |
6654 | 7902 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7903 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7904 |
anyChange = false; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7905 |
for (i=0; i<nInsts; i++) { |
6654 | 7906 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7907 |
__InstPtr(self)->i_instvars[i] = newRef; |
|
7908 |
__STORE(self, newRef); |
|
7909 |
anyChange = true; |
|
7910 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7911 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7912 |
RETURN (anyChange); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7913 |
%}. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7914 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7915 |
" |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7916 |
|v| |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7917 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7918 |
v := Array with:1234 with:'hello' with:Array. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7919 |
v replaceReferencesTo:Array with:ByteArray. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7920 |
v inspect |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
7921 |
" |
5755 | 7922 |
! ! |
7923 |
||
7924 |
!Object methodsFor:'testing'! |
|
7925 |
||
7926 |
? defaultValue |
|
7927 |
"a syntactic shugar-piece: |
|
7928 |
if the receiver is nil, return the defaultValue; |
|
7929 |
otherwise, return the receiver. |
|
7930 |
This method is only redefined in UndefinedObject - therefore, |
|
7931 |
the recevier is retuned here. |
|
7932 |
||
7933 |
Thus, if foo and bar are simple variables or constants, |
|
6654 | 7934 |
foo ? bar |
5755 | 7935 |
is the same as: |
6654 | 7936 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
5755 | 7937 |
|
7938 |
if they are message sends, the equivalent code is: |
|
6654 | 7939 |
[ |
7940 |
|t1 t2| |
|
7941 |
||
7942 |
t1 := foo. |
|
7943 |
t2 := bar. |
|
7944 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
7945 |
] value |
|
5755 | 7946 |
|
7947 |
Can be used to provide defaultValues to variables, |
|
7948 |
as in: |
|
6654 | 7949 |
foo := arg ? #defaultValue |
5755 | 7950 |
|
7951 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
7952 |
Notice: |
|
6654 | 7953 |
This method is open coded (inlined) by the compiler(s) |
7954 |
- redefining it may not work as expected." |
|
5755 | 7955 |
|
7956 |
^ self |
|
7957 |
||
7958 |
" |
|
7959 |
1 ? #default |
|
7960 |
nil ? #default |
|
7961 |
" |
|
7962 |
||
7963 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
7964 |
"Modified: / 19.5.1998 / 17:39:56 / cg" |
|
7965 |
! |
|
7966 |
||
7967 |
?? defaultValue |
|
7968 |
"a syntactic shugar-piece: |
|
7969 |
much like ?, but sends #value to the argument if required. |
|
7970 |
(i.e. its the same as #ifNil:) |
|
7971 |
If the receiver is nil, return the defaultValues value; |
|
7972 |
otherwise, return the receiver. |
|
7973 |
This method is only redefined in UndefinedObject - therefore, |
|
7974 |
the recevier is retuned here. |
|
7975 |
||
7976 |
Thus, if foo and bar are simple variables or constants, |
|
6654 | 7977 |
foo ?? bar |
5755 | 7978 |
is the same as: |
6654 | 7979 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
5755 | 7980 |
|
7981 |
if they are message sends, the equivalent code is: |
|
6654 | 7982 |
[ |
7983 |
|t t2| |
|
7984 |
||
7985 |
t := foo. |
|
7986 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
7987 |
] value |
|
5755 | 7988 |
|
7989 |
Can be used to provide defaultValues to variables, |
|
7990 |
as in: |
|
6654 | 7991 |
foo := arg ?? [ self computeDefault ] |
5755 | 7992 |
|
7993 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
7994 |
" |
|
7995 |
||
7996 |
^ self |
|
7997 |
||
7998 |
" |
|
7999 |
1 ?? #default |
|
8000 |
nil ?? #default |
|
8001 |
1 ?? [ self halt. 1 + 2 ] |
|
8002 |
nil ?? [ self halt. 1 + 2 ] |
|
6069 | 8003 |
1 ?? [Date today] |
8004 |
nil ?? [Date today] |
|
5755 | 8005 |
" |
8006 |
||
8007 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8008 |
"Modified: / 19.5.1998 / 17:42:56 / cg" |
|
8009 |
! |
|
8010 |
||
8011 |
ifNil:aBlockOrValue |
|
8012 |
"return myself, or the result from evaluating the argument, if I am nil. |
|
8013 |
This is much like #?, but sends #value to the argument in case of a nil |
|
8014 |
receiver. |
|
8015 |
Notice: |
|
6654 | 8016 |
This method is open coded (inlined) by the compiler(s) |
8017 |
- redefining it may not work as expected." |
|
5755 | 8018 |
|
8019 |
^ self |
|
8020 |
! |
|
8021 |
||
8022 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
|
8023 |
"return the value of the first arg, if I am nil, |
|
8024 |
the result from evaluating the 2nd argument, if I am not nil. |
|
8025 |
Notice: |
|
6654 | 8026 |
This method is open coded (inlined) by the compiler(s) |
8027 |
- redefining it may not work as expected." |
|
5755 | 8028 |
|
8029 |
^ notNilBlockOrValue value |
|
8030 |
||
8031 |
! |
|
8032 |
||
8033 |
ifNotNil:aBlockOrValue |
|
8034 |
"return myself if nil, or the result from evaluating the argument, |
|
8035 |
if I am not nil. |
|
8036 |
Notice: |
|
6654 | 8037 |
This method is open coded (inlined) by the compiler(s) |
8038 |
- redefining it may not work as expected." |
|
5755 | 8039 |
|
8040 |
^ aBlockOrValue value |
|
8041 |
||
8042 |
! |
|
8043 |
||
8044 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
|
8045 |
"return the value of the 2nd arg, if I am nil, |
|
8046 |
the result from evaluating the 1st argument, if I am not nil. |
|
8047 |
Notice: |
|
6654 | 8048 |
This method is open coded (inlined) by the compiler(s) |
8049 |
- redefining it may not work as expected." |
|
5755 | 8050 |
|
8051 |
^ notNilBlockOrValue value |
|
8052 |
||
8053 |
||
8054 |
! |
|
8055 |
||
8574 | 8056 |
ifNotNilDo:aBlock |
8057 |
"if the reciever is non-nil, return the value of aBlock, passing myself as argument. |
|
8058 |
Otherwise do nothing and return nil." |
|
8059 |
||
8060 |
^ aBlock value:self |
|
8061 |
! |
|
8062 |
||
5755 | 8063 |
isArray |
8064 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
8065 |
false is returned here - the method is only redefined in Array." |
|
8066 |
||
8067 |
^ false |
|
8068 |
! |
|
8069 |
||
8070 |
isAssociation |
|
8071 |
"return true, if the receiver is some kind of association; |
|
8072 |
false is returned here - the method is only redefined in Association." |
|
8073 |
||
8074 |
^ false |
|
8075 |
||
8076 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
8077 |
! |
|
8078 |
||
8079 |
isBehavior |
|
9221 | 8080 |
"return true, if the receiver is describing another objects behavior. |
8081 |
False is returned here - the method is only redefined in Behavior." |
|
5755 | 8082 |
|
8083 |
^ false |
|
8084 |
! |
|
8085 |
||
8086 |
isBlock |
|
8087 |
"return true, if the receiver is some kind of block; |
|
8088 |
false returned here - the method is only redefined in Block." |
|
8089 |
||
8090 |
^ false |
|
8091 |
! |
|
8092 |
||
5824 | 8093 |
isBoolean |
8094 |
"return true, if the receiver is a boolean; |
|
8095 |
false is returned here - the method is only redefined in Boolean." |
|
8096 |
||
8097 |
^ false |
|
8098 |
! |
|
8099 |
||
5755 | 8100 |
isByteArray |
8101 |
"return true, if the receiver is some kind of bytearray; |
|
8102 |
false is returned here - the method is only redefined in ByteArray." |
|
8103 |
||
8104 |
^ false |
|
8105 |
! |
|
8106 |
||
8986 | 8107 |
isByteCollection |
8108 |
"return true, if the receiver is some kind of byte collection, |
|
8109 |
i.e. #at: and #at:put: accesses a byte. This is different from 'self class isBytes', |
|
8110 |
since e.g. in BitArray single bits are accessed, but it is implemented as variableBytes class. |
|
8111 |
||
8112 |
false is returned here - the method is only redefined in UninterpretedBytes." |
|
8113 |
||
8114 |
^ false |
|
8115 |
! |
|
8116 |
||
5755 | 8117 |
isCharacter |
8118 |
"return true, if the receiver is some kind of character; |
|
8119 |
false is returned here - the method is only redefined in Character." |
|
8120 |
||
8121 |
^ false |
|
8122 |
! |
|
8123 |
||
8124 |
isClass |
|
9405 | 8125 |
"return true, if the receiver is some kind of class |
8126 |
(real class, not just behavior); |
|
5755 | 8127 |
false is returned here - the method is only redefined in Class." |
8128 |
||
8129 |
^ false |
|
8130 |
! |
|
8131 |
||
8132 |
isCollection |
|
8133 |
"return true, if the receiver is some kind of collection; |
|
8134 |
false is returned here - the method is only redefined in Collection." |
|
8135 |
||
8136 |
^ false |
|
8137 |
! |
|
8138 |
||
8139 |
isColor |
|
8140 |
"return true, if the receiver is some kind of color; |
|
8141 |
false is returned here - the method is only redefined in Color." |
|
8142 |
||
8143 |
^ false |
|
8144 |
! |
|
8145 |
||
6567 | 8146 |
isCons |
8147 |
"return true, if the receiver is a cons (pair); |
|
8148 |
false is returned here - the method is only redefined in Cons." |
|
8149 |
||
8150 |
^ false |
|
8151 |
! |
|
8152 |
||
5755 | 8153 |
isContext |
8154 |
"return true, if the receiver is some kind of context; |
|
8155 |
false returned here - the method is only redefined in Context." |
|
8156 |
||
8157 |
^ false |
|
8158 |
! |
|
8159 |
||
6181 | 8160 |
isEmptyOrNil |
8833 | 8161 |
"return true if I am nil or an empty collection - return false here. |
8162 |
(from Squeak)" |
|
6181 | 8163 |
|
8164 |
^ false |
|
8165 |
||
8166 |
"Created: / 13.11.2001 / 13:17:04 / cg" |
|
6182 | 8167 |
"Modified: / 13.11.2001 / 13:28:40 / cg" |
6181 | 8168 |
! |
8169 |
||
6221 | 8170 |
isException |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8171 |
"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
|
8172 |
|
6221 | 8173 |
^ false |
8174 |
||
8175 |
"Created: / 17.11.2001 / 18:37:44 / cg" |
|
8176 |
! |
|
8177 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8178 |
isExceptionCreator |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8179 |
"return true, if the receiver can create exceptions, |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8180 |
this includes #raise, #raiseRequest as well as the behavior of |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8181 |
an exception handler, such as the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8182 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8183 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8184 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8185 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8186 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8187 |
"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
|
8188 |
especially to the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8189 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8190 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8191 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8192 |
|
5755 | 8193 |
isExternalStream |
8194 |
"return true, if the receiver is some kind of externalStream; |
|
8195 |
false is returned here - the method is only redefined in ExternalStream." |
|
8196 |
||
8197 |
^false |
|
8198 |
! |
|
8199 |
||
8200 |
isFileStream |
|
8201 |
"return true, if the receiver is some kind of fileStream; |
|
8202 |
false is returned here - the method is only redefined in FileStream." |
|
8203 |
||
8204 |
^false |
|
8205 |
! |
|
8206 |
||
8207 |
isFilename |
|
8208 |
"return true, if the receiver is some kind of filename; |
|
8209 |
false is returned here - the method is only redefined in Filename." |
|
8210 |
||
8211 |
^false |
|
8212 |
! |
|
8213 |
||
8214 |
isFixedPoint |
|
8215 |
"return true, if the receiver is some kind of fixedPoint number; |
|
8216 |
false is returned here - the method is only redefined in FixedPoint." |
|
8217 |
||
8218 |
^ false |
|
8219 |
||
8220 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
8221 |
! |
|
8222 |
||
8223 |
isFixedSize |
|
8224 |
"return true if the receiver cannot grow easily |
|
8225 |
(i.e. a grow may be expensive, since it involves a become:)" |
|
8226 |
||
8227 |
^ true |
|
8228 |
! |
|
8229 |
||
6185 | 8230 |
isFloat |
8231 |
"return true, if the receiver is some kind of floating point number; |
|
8232 |
false is returned here. |
|
8233 |
Same as #isLimitedPrecisionReal, but a better name ;-)" |
|
8234 |
||
8235 |
^ false |
|
8236 |
||
8237 |
"Modified: / 14.11.2001 / 14:57:46 / cg" |
|
8238 |
! |
|
8239 |
||
5755 | 8240 |
isForm |
8241 |
"return true, if the receiver is some kind of form; |
|
8242 |
false is returned here - the method is only redefined in Form." |
|
8243 |
||
8244 |
^ false |
|
8245 |
! |
|
8246 |
||
8247 |
isFraction |
|
8248 |
"return true, if the receiver is some kind of fraction; |
|
8249 |
false is returned here - the method is only redefined in Fraction." |
|
8250 |
||
8251 |
^ false |
|
8252 |
! |
|
8253 |
||
9293 | 8254 |
isHierarchicalItem |
8255 |
"used to decide if the parent is a hierarchical item or the model" |
|
8256 |
||
8257 |
^ false |
|
8258 |
! |
|
8259 |
||
5755 | 8260 |
isImage |
8261 |
"return true, if the receiver is some kind of image; |
|
8262 |
false is returned here - the method is only redefined in Image." |
|
8263 |
||
8264 |
^ false |
|
8265 |
! |
|
8266 |
||
8267 |
isImageOrForm |
|
8268 |
"return true, if the receiver is some kind of image or form; |
|
8269 |
false is returned here - the method is only redefined in Image and Form." |
|
8270 |
||
8271 |
^ false |
|
8272 |
! |
|
8273 |
||
8274 |
isImmediate |
|
8275 |
"return true if I am an immediate object |
|
8276 |
i.e. I am represented in the pointer itself and |
|
8277 |
no real object header/storage is used me. |
|
8278 |
(currently, only SmallIntegers, some characters and nil return true)" |
|
8279 |
||
8280 |
^ self class hasImmediateInstances |
|
8281 |
||
8282 |
"Created: 3.6.1997 / 12:00:18 / cg" |
|
8283 |
! |
|
8284 |
||
8285 |
isInteger |
|
8286 |
"return true, if the receiver is some kind of integer number; |
|
8287 |
false is returned here - the method is only redefined in Integer." |
|
8288 |
||
8289 |
^ false |
|
8290 |
! |
|
8291 |
||
9279 | 8292 |
isInterestConverter |
8293 |
"return true if I am a kind of interest forwarder" |
|
8294 |
||
8295 |
^ false |
|
8296 |
! |
|
8297 |
||
5755 | 8298 |
isJavaClass |
8299 |
"return true, if this is a javaClass. |
|
8300 |
false is returned here - the method is only redefined in JavaClass." |
|
8301 |
||
8302 |
^ false |
|
8303 |
||
8304 |
"Created: / 26.3.1997 / 13:34:54 / cg" |
|
8305 |
"Modified: / 8.5.1998 / 21:25:21 / cg" |
|
8306 |
! |
|
8307 |
||
8308 |
isJavaClassRef |
|
8309 |
"return true, if this is a JavaClassRef. |
|
8310 |
false is returned here - the method is only redefined in JavaClassRef." |
|
8311 |
||
8312 |
^ false |
|
8313 |
||
8314 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8315 |
"Created: / 24.12.1999 / 01:46:28 / cg" |
|
8316 |
! |
|
8317 |
||
8318 |
isJavaContext |
|
8319 |
"return true, if this is a javaContext. |
|
8320 |
false is returned here - the method is only redefined in JavaContext." |
|
8321 |
||
8322 |
^ false |
|
8323 |
||
8324 |
"Created: / 8.5.1998 / 21:24:27 / cg" |
|
8325 |
"Modified: / 8.5.1998 / 21:25:35 / cg" |
|
8326 |
! |
|
8327 |
||
8328 |
isJavaMethod |
|
8329 |
"return true, if this is a JavaMethod. |
|
8330 |
false is returned here - the method is only redefined in JavaMethod." |
|
8331 |
||
8332 |
^ false |
|
8333 |
||
8334 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8335 |
"Created: / 25.9.1999 / 23:26:12 / cg" |
|
8336 |
! |
|
8337 |
||
8338 |
isJavaMethodRef |
|
8339 |
"return true, if this is a JavaMethodRef. |
|
8340 |
false is returned here - the method is only redefined in JavaMethodRef." |
|
8341 |
||
8342 |
^ false |
|
8343 |
||
8344 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8345 |
"Created: / 23.12.1999 / 19:44:51 / cg" |
|
8346 |
! |
|
8347 |
||
8348 |
isJavaObject |
|
8349 |
"return true, if this is a javaObject. |
|
8350 |
false is returned here - the method is only redefined in JavaObject." |
|
8351 |
||
8352 |
^ false |
|
8353 |
||
8354 |
"Created: / 26.3.1997 / 13:34:48 / cg" |
|
8355 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8356 |
! |
|
8357 |
||
8358 |
isJavaScriptClass |
|
8359 |
"return true, if this is a javaScriptClass. |
|
8360 |
false is returned here - the method is only redefined in JavaScriptClass." |
|
8361 |
||
8362 |
^ false |
|
8363 |
! |
|
8364 |
||
8935 | 8365 |
isJavaScriptMetaclass |
8366 |
"return true, if this is a javaScript Metaclass. |
|
8367 |
false is returned here - the method is only redefined in JavaScriptMetaclass." |
|
8368 |
||
8369 |
^ false |
|
8370 |
! |
|
8371 |
||
5755 | 8372 |
isKindOf:aClass |
8373 |
"return true, if the receiver is an instance of aClass or one of its |
|
8374 |
subclasses, false otherwise. |
|
8375 |
Advice: |
|
6654 | 8376 |
use of this to check objects for certain attributes/protocoll should |
8377 |
be avoided; it limits the reusability of your classes by limiting use |
|
8378 |
to instances of certain classes and fences you into a specific inheritance |
|
8379 |
hierarchy. |
|
8380 |
Use check-methods to check an object for a certain attributes/protocol |
|
8381 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
8382 |
||
8383 |
Using #isKindOf: is considered BAD STYLE. |
|
5755 | 8384 |
|
8385 |
Advice2: |
|
6654 | 8386 |
Be aware, that using an #isXXX method is usually much faster than |
8387 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
8388 |
hierarchy, comparing every class on the way. |
|
8389 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
8390 |
a single function call. |
|
5755 | 8391 |
" |
8392 |
||
8393 |
%{ /* NOCONTEXT */ |
|
8394 |
register OBJ thisClass; |
|
8395 |
||
8396 |
thisClass = __Class(self); |
|
8397 |
while (thisClass != nil) { |
|
6654 | 8398 |
if (thisClass == aClass) { |
8399 |
RETURN ( true ); |
|
8400 |
} |
|
8401 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
5755 | 8402 |
} |
8403 |
RETURN ( false ); |
|
8404 |
%} |
|
8405 |
||
8406 |
"/ |
|
8407 |
"/ the above code is equivalent to: |
|
8408 |
"/ |
|
8409 |
"/ thisClass := self class. |
|
8410 |
"/ [thisClass notNil] whileTrue:[ |
|
8411 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
8412 |
"/ thisClass := thisClass superclass |
|
8413 |
"/ ]. |
|
8414 |
"/ ^ false |
|
8415 |
"/ |
|
8416 |
||
8417 |
! |
|
8418 |
||
8419 |
isLayout |
|
8420 |
"return true, if the receiver is some kind of layout; |
|
8421 |
false is returned here - the method is only redefined in Layout." |
|
8422 |
||
8423 |
^ false |
|
8424 |
! |
|
8425 |
||
6567 | 8426 |
isLazyValue |
8427 |
^ false |
|
8428 |
! |
|
8429 |
||
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8430 |
isLimitedPrecisionReal |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8431 |
"return true, if the receiver is some kind of floating point number; |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8432 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8433 |
|
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8434 |
^ false |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8435 |
! |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8436 |
|
5755 | 8437 |
isList |
8438 |
"return true, if the receiver is some kind of list collection; |
|
8439 |
false is returned here - the method is only redefined in List." |
|
8440 |
||
8441 |
^ false |
|
8442 |
||
8443 |
"Created: / 11.2.2000 / 01:37:05 / cg" |
|
8444 |
! |
|
8445 |
||
8446 |
isLiteral |
|
8447 |
"return true, if the receiver can be represented as a literal constant in ST syntax; |
|
8448 |
false is returned here - the method is redefined in some classes." |
|
8449 |
||
8450 |
^ false |
|
8451 |
! |
|
8452 |
||
8453 |
isMemberOf:aClass |
|
8454 |
"return true, if the receiver is an instance of aClass, false otherwise. |
|
8455 |
Advice: |
|
8833 | 8456 |
use of this to check objects for certain attributes/protocol should |
6654 | 8457 |
be avoided; it limits the reusability of your classes by limiting use |
8458 |
to instances of a certain class. |
|
8459 |
Use check-methods to check an object for a certain attributes/protocol |
|
8460 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
8461 |
||
8462 |
Using #isMemberOf: is considered BAD STYLE. |
|
5755 | 8463 |
Notice: |
6654 | 8464 |
This method is open coded (inlined) by the compiler(s) |
8465 |
- redefining it may not work as expected." |
|
5755 | 8466 |
|
8467 |
^ (self class) == aClass |
|
8468 |
! |
|
8469 |
||
8470 |
isMeta |
|
8471 |
"return true, if the receiver is some kind of metaclass; |
|
8472 |
false is returned here - the method is only redefined in Metaclass." |
|
8473 |
||
8474 |
^ false |
|
8475 |
! |
|
8476 |
||
8477 |
isMethod |
|
8478 |
"return true, if the receiver is some kind of method; |
|
8479 |
false returned here - the method is only redefined in Method." |
|
8480 |
||
8481 |
^ false |
|
8482 |
! |
|
8483 |
||
8484 |
isMorph |
|
8485 |
"return true, if the receiver is some kind of morph; |
|
8486 |
false is returned here - the method is only redefined in Morph." |
|
8487 |
||
8488 |
^ false |
|
8489 |
! |
|
8490 |
||
8491 |
isNameSpace |
|
9221 | 8492 |
"return true, if the receiver is a nameSpace. |
8493 |
False is returned here - the method is only redefined in Namespace." |
|
5755 | 8494 |
|
8495 |
^ false |
|
8496 |
||
8497 |
"Created: / 11.10.1996 / 18:08:56 / cg" |
|
8498 |
"Modified: / 8.5.1998 / 21:26:05 / cg" |
|
8499 |
! |
|
8500 |
||
8501 |
isNamespace |
|
8502 |
"return true, if this is a nameSpace. |
|
8503 |
false is returned here - the method is only redefined in Namespace." |
|
8504 |
||
5869 | 8505 |
<resource:#obsolete> |
8506 |
||
5755 | 8507 |
self obsoleteMethodWarning:'use #isNameSpace'. |
6805 | 8508 |
^ self isNameSpace |
5755 | 8509 |
! |
8510 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8511 |
isNil |
9221 | 8512 |
"Return true, if the receiver is nil. |
8513 |
Because isNil is redefined in UndefinedObject, |
|
8514 |
the receiver is definitely not nil here, so unconditionally return false. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8515 |
Notice: |
6654 | 8516 |
This method is open coded (inlined) by the compiler(s) |
8517 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8518 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8519 |
^ false |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8520 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8521 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8522 |
isNilOrEmptyCollection |
6182 | 8523 |
"return true if I am nil or an empty collection - false here. |
8833 | 8524 |
Obsolete, use isEmptyOrNil." |
8525 |
||
8526 |
<resource:#obsolete> |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8527 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8528 |
^ false |
6182 | 8529 |
|
8530 |
"Modified: / 13.11.2001 / 13:28:06 / cg" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8531 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8532 |
|
9005 | 8533 |
isNonByteCollection |
8534 |
"return true, if the receiver is some kind of collection, but not a String, ByteArray etc.; |
|
8535 |
false is returned here - the method is redefined in Collection and UninterpretedBytes." |
|
8536 |
||
8537 |
^ false |
|
8538 |
||
8539 |
" |
|
8540 |
21 isNonByteCollection |
|
8541 |
'abc' isNonByteCollection |
|
8542 |
#'abc' isNonByteCollection |
|
8543 |
#[1 2 3] isNonByteCollection |
|
8544 |
#(1 2 3) isNonByteCollection |
|
8545 |
" |
|
8546 |
! |
|
8547 |
||
5755 | 8548 |
isNumber |
8549 |
"return true, if the receiver is some kind of number; |
|
8550 |
false is returned here - the method is only redefined in Number." |
|
8551 |
||
8552 |
^ false |
|
8553 |
! |
|
8554 |
||
8555 |
isOrderedCollection |
|
8556 |
"return true, if the receiver is some kind of ordered collection (or list etc); |
|
8557 |
false is returned here - the method is only redefined in OrderedCollection." |
|
8558 |
||
8559 |
^ false |
|
8560 |
! |
|
8561 |
||
8562 |
isPoint |
|
8563 |
"return true, if the receiver is some kind of point; |
|
8564 |
false is returned here - the method is only redefined in Point." |
|
8565 |
||
8566 |
^ false |
|
8567 |
! |
|
8568 |
||
9515 | 8569 |
isProjectDefinition |
8570 |
"return true, if the receiver is a projectDefinition. |
|
8571 |
False is returned here - the method is only redefined in ProjectDefinition." |
|
8572 |
||
8573 |
^ false |
|
8574 |
||
8575 |
"Created: / 10-08-2006 / 16:24:53 / cg" |
|
8576 |
! |
|
8577 |
||
5755 | 8578 |
isRectangle |
8579 |
"return true, if the receiver is some kind of rectangle; |
|
8580 |
false is returned here - the method is only redefined in Rectangle." |
|
8581 |
||
8582 |
^ false |
|
8583 |
! |
|
8584 |
||
8585 |
isRemoteObject |
|
8586 |
"return true, if the receiver is some kind of remoteObject, |
|
8587 |
false if its local - the method is only redefined in RemoteObject." |
|
8588 |
||
8589 |
^ false |
|
8590 |
||
8591 |
"Created: 28.10.1996 / 15:18:45 / cg" |
|
8592 |
"Modified: 28.10.1996 / 15:20:57 / cg" |
|
8593 |
! |
|
8594 |
||
8595 |
isSequenceable |
|
8596 |
"return true, if the receiver is some kind of sequenceable collection; |
|
8597 |
false is returned here - the method is only redefined in SequenceableCollection." |
|
8598 |
||
8599 |
^ false |
|
8600 |
! |
|
8601 |
||
8602 |
isSequenceableCollection |
|
8603 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
8604 |
This method is a historic leftover and will be removed soon ... |
|
8605 |
(although its name is much better than #isSequenceable - sigh)" |
|
8606 |
||
5869 | 8607 |
<resource:#obsolete> |
8608 |
||
5755 | 8609 |
self obsoleteMethodWarning:'use #isSequenceable'. |
8610 |
^ false |
|
8611 |
! |
|
8612 |
||
8613 |
isStream |
|
8614 |
"return true, if the receiver is some kind of stream; |
|
8615 |
false is returned here - the method is only redefined in Stream." |
|
8616 |
||
8617 |
^ false |
|
8618 |
! |
|
8619 |
||
8620 |
isString |
|
8621 |
"return true, if the receiver is some kind of string; |
|
8622 |
false is returned here - the method is only redefined in CharacterArray." |
|
8623 |
||
8624 |
^ false |
|
8625 |
! |
|
8626 |
||
8627 |
isStringCollection |
|
8628 |
"return true, if the receiver is some kind of stringCollection; |
|
8629 |
false is returned here - the method is only redefined in StringCollection." |
|
8630 |
||
8631 |
^ false |
|
8632 |
! |
|
8633 |
||
8634 |
isSymbol |
|
8635 |
"return true, if the receiver is some kind of symbol; |
|
8636 |
false is returned here - the method is only redefined in Symbol." |
|
8637 |
||
8638 |
^ false |
|
8639 |
! |
|
8640 |
||
8641 |
isText |
|
8642 |
"return true, if the receiver is some kind of text object; |
|
8643 |
false is returned here - the method is only redefined in Text." |
|
8644 |
||
8645 |
^ false |
|
8646 |
||
8647 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
8648 |
! |
|
8649 |
||
8650 |
isValueModel |
|
8651 |
"return true, if the receiver is some kind of valueModel; |
|
8652 |
false is returned here - the method is only redefined in ValueModel." |
|
8653 |
||
8654 |
^ false |
|
8655 |
||
8656 |
! |
|
8657 |
||
8658 |
isVariable |
|
8659 |
"return true if the receiver has indexed instance variables, |
|
8660 |
false otherwise." |
|
8661 |
||
8662 |
^ self class isVariable |
|
8663 |
! |
|
8664 |
||
8665 |
isVariableBinding |
|
8666 |
"return true, if this is a binding for a variable. |
|
8667 |
false is returned here - the method is only redefined in Binding." |
|
8668 |
||
8669 |
^ false |
|
8670 |
||
8671 |
"Created: / 19.6.1997 / 17:38:44 / cg" |
|
8672 |
"Modified: / 8.5.1998 / 21:26:55 / cg" |
|
8673 |
! |
|
8674 |
||
8675 |
isView |
|
8676 |
"return true, if the receiver is some kind of view; |
|
8677 |
false is returned here - the method is only redefined in View." |
|
8678 |
||
8679 |
^ false |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8680 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8681 |
|
6932 | 8682 |
notEmptyOrNil |
8683 |
"Squeak compatibility: |
|
8684 |
return true if I am neither nil nor an empty collection. |
|
8685 |
Return true here." |
|
8686 |
||
8687 |
^ true |
|
8688 |
! |
|
8689 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8690 |
notNil |
9221 | 8691 |
"Return true, if the receiver is not nil. |
8692 |
Because notNil is redefined in UndefinedObject, |
|
8693 |
the receiver is definitely not nil here, so unconditionally return true. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8694 |
Notice: |
6654 | 8695 |
This method is open coded (inlined) by the compiler(s) |
8696 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8697 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8698 |
^ true |
5755 | 8699 |
! ! |
8700 |
||
8701 |
!Object methodsFor:'tracing'! |
|
8702 |
||
8703 |
traceInto:aRequestor level:level from:referrer |
|
8704 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
8705 |
||
8706 |
^ aRequestor traceObject:self level:level from:referrer |
|
8707 |
||
8708 |
"Created: / 2.9.1999 / 09:05:17 / stefan" |
|
8709 |
! ! |
|
8710 |
||
8711 |
!Object methodsFor:'user interaction & notifications'! |
|
8712 |
||
8713 |
activityNotification:aString |
|
8714 |
"this can be sent from deeply nested methods, which are going to perform |
|
8715 |
some long-time activity. |
|
8716 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
8717 |
passing the argument. The handler should show this message whereever it likes, |
|
8718 |
and proceed. If there is no handler, this is simply ignored. |
|
8719 |
||
8720 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
8721 |
which likes to display that message in its label or a busy-box. |
|
8722 |
It could also be put into some logfile or printed on the standard output/error." |
|
8723 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8724 |
ActivityNotification isHandled ifTrue:[ |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8725 |
^ ActivityNotification raiseRequestWith:self errorString:aString |
5755 | 8726 |
]. |
8727 |
||
8728 |
" |
|
8729 |
nil activityNotification:'hello there' |
|
8730 |
self activityNotification:'hello there' |
|
8731 |
" |
|
8732 |
||
8733 |
" |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8734 |
ActivityNotification handle:[:ex | |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8735 |
ex errorString printCR. |
6654 | 8736 |
ex proceed. |
5755 | 8737 |
] do:[ |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8738 |
'hello' printCR. |
6654 | 8739 |
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
|
8740 |
'world' printCR. |
5755 | 8741 |
] |
8742 |
" |
|
8743 |
||
8744 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
8745 |
! |
|
8746 |
||
8747 |
confirm:aString |
|
8748 |
"launch a confirmer, which allows user to enter yes or no. |
|
8749 |
return true for yes, false for no. |
|
8750 |
If no GUI is present (headless applications), true is returned." |
|
8751 |
||
8752 |
" |
|
8753 |
on systems without GUI, or during startup, output a message |
|
8754 |
and return true (as if yes was answered) |
|
8755 |
Q: should we ask user by reading Stdin ? |
|
8756 |
" |
|
8757 |
Smalltalk isInitialized ifFalse:[ |
|
6654 | 8758 |
'*** confirmation requested during initialization:' errorPrintCR. |
8759 |
aString errorPrintCR. |
|
8760 |
'*** I''ll continue, assuming <yes> ...' errorPrintCR. |
|
8761 |
^ true |
|
5755 | 8762 |
]. |
8763 |
||
8764 |
(Dialog isNil |
|
8765 |
or:[Screen isNil |
|
8766 |
or:[Screen current isNil |
|
8767 |
or:[Screen current isOpen not]]]) ifTrue:[ |
|
6654 | 8768 |
'confirm: ' infoPrint. |
8769 |
aString infoPrintCR. |
|
8770 |
'continue, assuming <yes>' infoPrintCR. |
|
8771 |
^ true |
|
5755 | 8772 |
]. |
8773 |
||
8774 |
Dialog autoload. "in case its autoloaded" |
|
8775 |
^ Dialog confirm:aString |
|
8776 |
||
8777 |
" |
|
8778 |
nil confirm:'hello' |
|
8779 |
self confirm:'hello' |
|
8780 |
" |
|
8781 |
||
8782 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8783 |
! |
|
8784 |
||
8785 |
confirm:aString orCancel:cancelBlock |
|
8786 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8787 |
return true for yes, false for no, or the value from cancelBlock for cancel. |
|
8788 |
If no GUI is present (headless applications), cancelBlock is returned." |
|
8789 |
||
8790 |
|answer| |
|
8791 |
||
8792 |
answer := self confirmWithCancel:aString. |
|
8793 |
answer isNil ifTrue:[ |
|
6654 | 8794 |
^ cancelBlock value |
5755 | 8795 |
]. |
8796 |
^ answer |
|
8797 |
||
8798 |
" |
|
8799 |
self confirm:'hello' orCancel:[self halt] |
|
8800 |
" |
|
8801 |
||
8802 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8803 |
! |
|
8804 |
||
8805 |
confirmWithCancel:aString |
|
8806 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8807 |
return true for yes, false for no, nil for cancel. |
|
8808 |
If no GUI is present (headless applications), nil is returned." |
|
8809 |
||
8810 |
" |
|
8811 |
on systems without GUI, or during startup, output a message |
|
8812 |
and return true (as if yes was answered) |
|
8813 |
Q: should we ask user by reading Stdin ? |
|
8814 |
" |
|
8815 |
Smalltalk isInitialized ifFalse:[ |
|
6654 | 8816 |
'*** confirmation requested during initialization:' errorPrintCR. |
8817 |
aString errorPrintCR. |
|
8818 |
'*** I''ll continue, assuming <cancel> ...' errorPrintCR. |
|
8819 |
^ nil |
|
5755 | 8820 |
]. |
8821 |
||
8822 |
(Dialog isNil |
|
8823 |
or:[Screen isNil |
|
8824 |
or:[Screen current isNil |
|
8825 |
or:[Screen current isOpen not]]]) ifTrue:[ |
|
6654 | 8826 |
'confirm: ' infoPrint. |
8827 |
aString infoPrintCR. |
|
8828 |
'continue, assuming <cancel>' infoPrintCR. |
|
8829 |
^ nil |
|
5755 | 8830 |
]. |
8831 |
||
8832 |
Dialog autoload. "in case its autoloaded" |
|
8833 |
^ Dialog confirmWithCancel:aString |
|
8834 |
||
8835 |
" |
|
8836 |
nil confirmWithCancel:'hello' |
|
8837 |
self confirmWithCancel:'hello' |
|
8838 |
" |
|
8839 |
||
8840 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8841 |
! |
|
8842 |
||
8843 |
errorNotify:aString |
|
8844 |
"launch a Notifier, showing top stack, telling user something |
|
8845 |
and give user a chance to enter debugger." |
|
8846 |
||
8847 |
^ self |
|
6654 | 8848 |
errorNotify:aString |
8849 |
from:thisContext sender |
|
8850 |
allowDebug:true |
|
5755 | 8851 |
|
8852 |
" |
|
8853 |
nil errorNotify:'hello there' |
|
8854 |
self errorNotify:'hello there' |
|
8855 |
" |
|
8856 |
||
6199 | 8857 |
"Modified: / 16.11.2001 / 15:36:49 / cg" |
5755 | 8858 |
! |
8859 |
||
8860 |
errorNotify:aString from:aContext |
|
8861 |
"launch a Notifier, showing top stack (above aContext), |
|
8862 |
telling user something and give user a chance to enter debugger." |
|
8863 |
||
8864 |
^ self errorNotify:aString from:aContext allowDebug:true |
|
8865 |
||
8866 |
"Modified: / 17.8.1998 / 10:09:27 / cg" |
|
8867 |
! |
|
8868 |
||
8869 |
errorNotify:aString from:aContext allowDebug:allowDebug |
|
8870 |
"launch a Notifier, showing top stack (above aContext), |
|
8871 |
telling user something and optionally give the user a chance to enter debugger." |
|
8872 |
||
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8873 |
|currentScreen con sender action boxLabels boxValues default| |
5755 | 8874 |
|
8875 |
Smalltalk isInitialized ifFalse:[ |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8876 |
'errorNotification: ' print. aString printCR. |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8877 |
^ nil |
5755 | 8878 |
]. |
8879 |
(Dialog isNil |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8880 |
or:[Screen isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8881 |
or:[(currentScreen := Screen current) isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8882 |
or:[currentScreen isOpen not]]]) ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8883 |
" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8884 |
on systems without GUI, simply show |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8885 |
the message on the Transcript and abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8886 |
" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8887 |
Transcript showCR:aString. |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8888 |
AbortOperationRequest raise. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8889 |
"not reached" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8890 |
^ nil |
5755 | 8891 |
]. |
8892 |
||
8893 |
Processor activeProcessIsSystemProcess ifTrue:[ |
|
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8894 |
action := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8895 |
sender := aContext. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8896 |
Debugger isNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8897 |
'****************** Cought Error while in SystemProcess ****************' errorPrintCR. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8898 |
thisContext fullPrintAll. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8899 |
action := #abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8900 |
]. |
5755 | 8901 |
] ifFalse:[ |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8902 |
Dialog autoload. "in case it's autoloaded" |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8903 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8904 |
Error handle:[:ex | |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8905 |
"/ a recursive error - quickly enter debugger |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8906 |
"/ this happened, when I corrupted the Dialog class ... |
7208 | 8907 |
('Object [error]: ' , ex description , ' caught in errorNotification') errorPrintCR. |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8908 |
action := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8909 |
ex return. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8910 |
] do:[ |s| |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8911 |
sender := aContext. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8912 |
sender isNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8913 |
sender := thisContext sender. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8914 |
]. |
7576
7e2e97bd0973
interrestingContextFrom - duplicated code removed
Claus Gittinger <cg@exept.de>
parents:
7567
diff
changeset
|
8915 |
con := sender. |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8916 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8917 |
"/ skip intermediate (signal & exception) contexts |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8918 |
DebugView notNil ifTrue:[ |
7576
7e2e97bd0973
interrestingContextFrom - duplicated code removed
Claus Gittinger <cg@exept.de>
parents:
7567
diff
changeset
|
8919 |
con := DebugView interestingContextFrom:sender |
6647
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 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8922 |
"/ show the first few contexts |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8923 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8924 |
s := WriteStream with:aString. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8925 |
s cr; cr. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8926 |
1 to:15 do:[:n | |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8927 |
con notNil ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8928 |
con printOn:s. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8929 |
s cr. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8930 |
con := con sender |
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 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8934 |
(allowDebug and:[Debugger notNil]) ifTrue:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8935 |
boxLabels := #('Proceed' 'Abort' 'Copy Trace and Abort' 'Debug'). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8936 |
boxValues := #(#proceed #abort #copy #debug). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8937 |
default := #debug. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8938 |
] ifFalse:[ |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8939 |
boxLabels := #('Proceed' 'Abort' 'Copy Trace and Abort'). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8940 |
boxValues := #(#proceed #abort #copy). |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8941 |
default := #abort. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8942 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8943 |
|
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8944 |
action := Dialog |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8945 |
choose:s contents |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8946 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8947 |
image:WarningBox errorIconBitmap |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8948 |
labels:boxLabels |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8949 |
values:boxValues |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8950 |
default:default |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8951 |
onCancel:nil. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8952 |
]. |
5755 | 8953 |
]. |
8954 |
||
8955 |
action == #debug ifTrue:[ |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8956 |
^ Debugger enter:sender withMessage:aString mayProceed:true |
5755 | 8957 |
] ifFalse:[ |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8958 |
action == #proceed ifTrue:[ |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8959 |
^ nil. |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8960 |
]. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8961 |
action == #copy ifTrue:[ |s| |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8962 |
s := '' writeStream. |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8963 |
sender fullPrintAllOn:s. |
8563 | 8964 |
currentScreen rootView setClipboardText:s contents. |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
8965 |
]. |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8966 |
AbortOperationRequest raise. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8967 |
"not reached" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8968 |
]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
8969 |
|
5755 | 8970 |
|
8971 |
" |
|
8972 |
nil errorNotify:'hello there' |
|
8973 |
self errorNotify:'hello there' |
|
8974 |
" |
|
8975 |
||
8976 |
"Created: / 17.8.1998 / 10:09:26 / cg" |
|
6199 | 8977 |
"Modified: / 16.11.2001 / 15:40:12 / cg" |
5755 | 8978 |
! |
8979 |
||
8980 |
information:aString |
|
8981 |
"launch an InfoBox, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8982 |
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
|
8983 |
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
|
8984 |
Use #notify: for more important messages. |
8371 | 8985 |
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
|
8986 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8987 |
|
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
8988 |
UserInformation raiseRequestWith:self errorString:aString |
5755 | 8989 |
|
8990 |
" |
|
8991 |
nil information:'hello there' |
|
8992 |
self information:'hello there' |
|
8993 |
" |
|
8994 |
||
8995 |
" |
|
8996 |
InformationSignal handle:[:ex | |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
8997 |
'no box popped' printCR. |
6654 | 8998 |
ex proceed. |
5755 | 8999 |
] do:[ |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9000 |
'hello' printCR. |
6654 | 9001 |
self information:'some info'. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9002 |
'world' printCR. |
5755 | 9003 |
] |
9004 |
" |
|
9005 |
||
9006 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
9007 |
! |
|
9008 |
||
9009 |
notify:aString |
|
9010 |
"launch a Notifier, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9011 |
Use #information: for ignorable messages. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9012 |
If nobody handles the exception, the dafault action of UserNotification |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9013 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9014 |
|
5755 | 9015 |
|
9016 |
Smalltalk isInitialized ifFalse:[ |
|
6656 | 9017 |
"/ thisContext fullPrintAll. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9018 |
'information: ' print. aString printCR. |
6654 | 9019 |
^ self |
5755 | 9020 |
]. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9021 |
UserNotification raiseRequestWith:self errorString:aString. |
5755 | 9022 |
|
9023 |
" |
|
9024 |
nil notify:'hello there' |
|
9025 |
self notify:'hello there' |
|
9026 |
" |
|
9027 |
||
9028 |
"Modified: 20.5.1996 / 10:28:48 / cg" |
|
9029 |
! |
|
9030 |
||
9031 |
warn:aString |
|
9032 |
"launch a WarningBox, telling user something. |
|
9033 |
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
|
9034 |
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
|
9035 |
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
|
9036 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9037 |
|
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9038 |
Warning raiseRequestWith:self errorString:aString |
5755 | 9039 |
|
9040 |
" |
|
9041 |
nil warn:'hello there' |
|
9042 |
self warn:'hello there' |
|
9043 |
" |
|
9044 |
||
9045 |
" |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9046 |
Warning handle:[:ex | |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9047 |
Transcript showCR:ex description. |
6654 | 9048 |
ex proceed. |
5755 | 9049 |
] do:[ |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9050 |
'hello' printCR. |
6654 | 9051 |
self warn:'some info'. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9052 |
'world' printCR. |
5755 | 9053 |
] |
9054 |
" |
|
9055 |
||
9056 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
|
9057 |
! ! |
|
9058 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9059 |
!Object methodsFor:'visiting'! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9060 |
|
8426 | 9061 |
acceptVisitor:aVisitor |
9062 |
"double-dispatch onto a Visitor." |
|
9063 |
||
9064 |
^ self acceptVisitor:aVisitor with:nil |
|
9065 |
! |
|
9066 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9067 |
acceptVisitor:aVisitor with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9068 |
"double-dispatch onto a Visitor. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9069 |
Subclasses redefine this" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9070 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9071 |
^ aVisitor visitObject:self with:aParameter |
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 |
|
8879
69a4b8db130c
#elementDescriptorFor: take care vor nil-aspects
Stefan Vogel <sv@exept.de>
parents:
8876
diff
changeset
|
9074 |
elementDescriptorFor:anAspectSymbol |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9075 |
"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
|
9076 |
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
|
9077 |
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
|
9078 |
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
|
9079 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9080 |
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
|
9081 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9082 |
|ret| |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9083 |
|
8879
69a4b8db130c
#elementDescriptorFor: take care vor nil-aspects
Stefan Vogel <sv@exept.de>
parents:
8876
diff
changeset
|
9084 |
ret := 0. |
69a4b8db130c
#elementDescriptorFor: take care vor nil-aspects
Stefan Vogel <sv@exept.de>
parents:
8876
diff
changeset
|
9085 |
anAspectSymbol notNil ifTrue:[ |
69a4b8db130c
#elementDescriptorFor: take care vor nil-aspects
Stefan Vogel <sv@exept.de>
parents:
8876
diff
changeset
|
9086 |
ret := self perform:anAspectSymbol ifNotUnderstood:[0]. |
69a4b8db130c
#elementDescriptorFor: take care vor nil-aspects
Stefan Vogel <sv@exept.de>
parents:
8876
diff
changeset
|
9087 |
]. |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9088 |
ret == 0 ifTrue:[ |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9089 |
^ self elementDescriptorForNonNilInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9090 |
]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9091 |
^ ret. |
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 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9094 |
elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9095 |
"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
|
9096 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9097 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9098 |
|
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 |
#(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
|
9101 |
Dictionary new elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9102 |
(5 @ nil) elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9103 |
" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9104 |
! |
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 |
elementDescriptorForInstanceVariablesMatching:aBlock |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9107 |
"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
|
9108 |
Indexed vars are all included." |
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 |
|instVarNames theClass children |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9111 |
instSize "{ Class: SmallInteger }" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9112 |
varSize "{ Class: SmallInteger }"| |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9113 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9114 |
theClass := self class. |
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 |
instSize := theClass instSize. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9117 |
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
|
9118 |
children := OrderedCollection new:(instSize + varSize). |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9119 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9120 |
instVarNames := theClass allInstVarNames. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9121 |
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
|
9122 |
var := self instVarAt:i. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9123 |
(aBlock value:var) ifTrue:[ |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9124 |
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
|
9125 |
] |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9126 |
]. |
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 |
varSize ~~ 0 ifTrue:[ |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9129 |
1 to:varSize do:[:i | |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9130 |
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
|
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 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9134 |
^ children. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9135 |
|
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 |
#(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
|
9138 |
Dictionary new elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9139 |
(5 @ nil) elementDescriptorForInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9140 |
" |
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 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9143 |
elementDescriptorForNonNilInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9144 |
"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
|
9145 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9146 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | val notNil]. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9147 |
|
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 |
#(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
|
9150 |
Dictionary new elementDescriptorForNonNilInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9151 |
(5 @ nil) elementDescriptorForNonNilInstanceVariables |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9152 |
" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9153 |
! ! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9154 |
|
5755 | 9155 |
!Object class methodsFor:'documentation'! |
1 | 9156 |
|
5754 | 9157 |
version |
9657 | 9158 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.566 2006-08-23 14:06:59 cg Exp $' |
1 | 9159 |
! ! |
6764 | 9160 |
|
5755 | 9161 |
Object initialize! |