author | Claus Gittinger <cg@exept.de> |
Tue, 04 Jun 2013 15:52:42 +0200 | |
changeset 15368 | 1509922b75ec |
parent 15362 | f64a9683658b |
child 15399 | a407945aad8e |
child 18066 | 89d51443ba6f |
permissions | -rw-r--r-- |
5755 | 1 |
" |
2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
14975 | 3 |
All Rights Reserved |
5755 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
"{ Package: 'stx:libbasic' }" |
|
13 |
||
14 |
nil subclass:#Object |
|
15034 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'ErrorSignal HaltSignal MessageNotUnderstoodSignal |
|
17 |
UserInterruptSignal RecursionInterruptSignal |
|
15222 | 18 |
SubscriptOutOfBoundsSignal IndexNotFoundSignal |
19 |
NonIntegerIndexSignal NotFoundSignal KeyNotFoundSignal |
|
20 |
ElementOutOfBoundsSignal UserNotificationSignal InformationSignal |
|
21 |
WarningSignal PrimitiveFailureSignal DeepCopyErrorSignal |
|
22 |
AbortSignal ErrorRecursion Dependencies InfoPrinting |
|
23 |
ActivityNotificationSignal InternalErrorSignal |
|
15034 | 24 |
NonWeakDependencies SynchronizationSemaphores ObjectAttributes |
25 |
OSSignalInterruptSignal FinalizationLobby |
|
26 |
RecursiveStoreStringSignal AbortAllSignal EnabledBreakPoints' |
|
27 |
poolDictionaries:'' |
|
28 |
category:'Kernel-Objects' |
|
5755 | 29 |
! |
30 |
||
31 |
!Object class methodsFor:'documentation'! |
|
3023
674376809496
general listView support (#displayOn / widthOn / heightOn)
ca
parents:
3010
diff
changeset
|
32 |
|
5754 | 33 |
copyright |
5755 | 34 |
" |
35 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
14975 | 36 |
All Rights Reserved |
5755 | 37 |
|
38 |
This software is furnished under a license and may be used |
|
39 |
only in accordance with the terms of that license and with the |
|
40 |
inclusion of the above copyright notice. This software may not |
|
41 |
be provided or otherwise made available to, or used by, any |
|
42 |
other person. No title to or ownership of the software is |
|
43 |
hereby transferred. |
|
44 |
" |
|
45 |
! |
|
46 |
||
47 |
dependencies |
|
48 |
" |
|
10460 | 49 |
ST/X dependencies are slightly modified from ST-80's |
5755 | 50 |
(we think they are better ;-). |
51 |
||
52 |
One problem occuring very often in ST-80 is that some object |
|
53 |
cannot be garbage collected because some dependency is present, |
|
54 |
having the object as a dependent of some other object. |
|
55 |
In ST-80, this association remains alive (because a Dictionary |
|
56 |
is used to hold dependents) - even if no other references exist to |
|
57 |
to dependent or the dependee. |
|
58 |
||
59 |
This means, that in ST-80, a #release is mandatory in order to |
|
60 |
prevent memory leaks. |
|
61 |
We think, that this is a bad solution, since after all, exactly that |
|
62 |
kind of work should be performed by a garbage collector - you should not |
|
63 |
need to care about dependencies. |
|
10460 | 64 |
From a philosophical point of view, why should some object depend on |
5755 | 65 |
something that the programmer considers a dead object ? |
66 |
(well - worse than that: it seems that some ST-80 code even depends on |
|
67 |
that behavior) |
|
68 |
||
69 |
In order to limit the trouble, ST-80 reimplemented the way dependents |
|
70 |
are stored in the model class - this one keeps the dependents locally, |
|
71 |
so these dependents go away, once the model is reclaimed. |
|
72 |
That may make things even more confusing: with models, no #release is |
|
73 |
needed, with general objects it is mandatory. |
|
74 |
||
75 |
||
76 |
In ST/X, dependencies are implemented using a WeakDictionary; this means, |
|
77 |
that once the dependee dies, the dependency association is removed automatically, |
|
78 |
and the dependent can be reclaimed by the garbage collector, if no other |
|
79 |
references exist to the dependent. |
|
80 |
In order to (at least) provide a mechanism for the old behavior |
|
81 |
(in case your application heavily depends on the ST-80 mechanism), complementary |
|
10460 | 82 |
protocol to add nonWeak dependencies is provided |
5755 | 83 |
(see #addNonWeakDependent / #removeNonWeakDependent). |
84 |
||
85 |
||
86 |
Caveat: |
|
87 |
since interests are implemented using InterestConverter (which are simply |
|
88 |
forwarding messages), these must use the nonWeak mechanism (as done in ST-80 |
|
89 |
automatically). |
|
90 |
The reason is that there are usually no direct references to the converters, |
|
91 |
and those would be reclaimed if stored in a weakDictionary. |
|
92 |
This means, that those interests MUST be removed with #retractInterest |
|
10460 | 93 |
(which is bug-compatible to ST-80). |
5755 | 94 |
We rewrite things to provide a more convenient mechanism in the future ... |
95 |
||
96 |
||
97 |
I like to hear comments on the above - do you think its better ? |
|
98 |
" |
|
99 |
! |
|
100 |
||
101 |
documentation |
|
102 |
" |
|
10460 | 103 |
Object is the superclass of most other classes. |
5755 | 104 |
(except for nil-subclasses, which inherit nothing, |
105 |
to catch any message into their #doesNotUnderstand: method) |
|
106 |
||
107 |
Protocol which is common to every object is defined here. |
|
108 |
Also some utility stuff (like notify) and error handling is implemented here. |
|
109 |
||
110 |
Object has no instance variables (and may not get any added). One reason is, that |
|
10460 | 111 |
UndefinedObject and SmallInteger are also inheriting from Object - these two cannot |
112 |
have instance variables (due to their implementation). |
|
113 |
The other reason is that the runtime system (VM) knows about the layout of some built-in |
|
114 |
classes (think of Class, Method, Block and also Integer or Float). |
|
115 |
If you were allowed to add instance variables to Object, the VM had to be recompiled |
|
5755 | 116 |
(and also rewritten in some places). |
117 |
||
118 |
[Class variables:] |
|
119 |
||
14975 | 120 |
ErrorSignal <Signal> Signal raised for error/error: messages |
121 |
also, parent of all other signals. |
|
122 |
||
123 |
HaltSignal <Signal> Signal raised for halt/halt: messages |
|
124 |
||
125 |
MessageNotUnderstoodSignal Signals raised for various error conditions |
|
126 |
UserInterruptSignal |
|
127 |
RecursionInterruptSignal |
|
128 |
ExceptionInterruptSignal |
|
129 |
SubscriptOutOfBoundsSignal |
|
130 |
NonIntegerIndexSignal |
|
131 |
NotFoundSignal |
|
132 |
KeyNotFoundSignal |
|
133 |
ElementOutOfBoundsSignal |
|
134 |
InformationSignal |
|
135 |
WarningSignal |
|
136 |
DeepCopyErrorSignal |
|
137 |
InternalErrorSignal |
|
138 |
||
139 |
AbortSignal <Signal> Signal raised by debugger, to abort a computation |
|
140 |
BUT, the debugger will only raise it if it is handled. |
|
141 |
By handling the abortSignal, you can control where the |
|
142 |
debuggers abort-function resumes execution in case of |
|
143 |
an error. |
|
144 |
||
145 |
ErrorRecursion <Boolean> controls behavior when recursive errors occur (i.e. |
|
146 |
an error while handling an error). |
|
147 |
||
148 |
Dependencies <WeakDependencyDictionary> |
|
149 |
keeps track of object dependencies. |
|
150 |
||
151 |
InfoPrinting <Boolean> controls weather informational messages |
|
152 |
are printed. |
|
153 |
||
154 |
ActivityNotificationSignal <QuerySignal> |
|
155 |
raised on #activityNotification: |
|
156 |
||
157 |
NonWeakDependencies <Dictionary> keeps track of object dependencies. |
|
158 |
Dependents stay alive. |
|
159 |
||
160 |
SynchronizationSemaphores <WeakIdentityDictionary> |
|
161 |
Semaphores for per-object-monitor. |
|
10460 | 162 |
|
5755 | 163 |
|
164 |
[author:] |
|
14975 | 165 |
Claus Gittinger |
5755 | 166 |
|
167 |
" |
|
168 |
! ! |
|
169 |
||
170 |
!Object class methodsFor:'initialization'! |
|
171 |
||
5971 | 172 |
initSignals |
173 |
"called only once - initialize signals" |
|
174 |
||
15193 | 175 |
"/ notice: the class variables here are a leftover from times |
176 |
"/ when errors where signal-instance, not class based. |
|
177 |
"/ then, signal instances where created here and kept as class vars, |
|
178 |
"/ to be fetched from the class var or via signal-getter methods. |
|
179 |
"/ Nowadays, we use class based exceptions, where the exception class |
|
180 |
"/ is directly referenced. |
|
181 |
"/ the classvars here are kept for backward compatibility, but they now |
|
182 |
"/ simply alias the corresponding exception class. |
|
183 |
"/ Old code should be rewritten to access the error class. |
|
184 |
||
5971 | 185 |
ErrorSignal := Error. |
186 |
HaltSignal := HaltInterrupt. |
|
5977 | 187 |
MessageNotUnderstoodSignal := MessageNotUnderstood. |
6000 | 188 |
PrimitiveFailureSignal := PrimitiveFailure. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
189 |
InternalErrorSignal := VMInternalError. |
5971 | 190 |
UserInterruptSignal := UserInterrupt. |
6146 | 191 |
RecursionInterruptSignal := RecursionError. |
5977 | 192 |
NotFoundSignal := NotFoundError. |
193 |
IndexNotFoundSignal := IndexNotFoundError. |
|
194 |
SubscriptOutOfBoundsSignal := SubscriptOutOfBoundsError. |
|
195 |
NonIntegerIndexSignal := NonIntegerIndexError. |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
196 |
KeyNotFoundSignal := KeyNotFoundError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
197 |
ElementOutOfBoundsSignal := ElementBoundsError. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
198 |
UserNotificationSignal := UserNotification. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
199 |
WarningSignal := Warning. |
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
200 |
InformationSignal := UserInformation. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
201 |
ActivityNotificationSignal := ActivityNotification. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
202 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
203 |
DeepCopyErrorSignal := DeepCopyError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
204 |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
205 |
AbortSignal := AbortOperationRequest. |
6877
ab4e7d42f9f8
AbortAllOperation - now class based
Claus Gittinger <cg@exept.de>
parents:
6874
diff
changeset
|
206 |
AbortAllSignal := AbortAllOperationRequest. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
207 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
208 |
OSSignalInterruptSignal := OSSignalInterrupt. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
209 |
RecursiveStoreStringSignal := RecursiveStoreError. |
5971 | 210 |
|
5980 | 211 |
" |
212 |
Object initSignals |
|
213 |
" |
|
5971 | 214 |
|
215 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
216 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
217 |
"Modified: / 16.11.2001 / 16:30:08 / cg" |
5971 | 218 |
! |
219 |
||
5755 | 220 |
initialize |
221 |
"called only once - initialize signals" |
|
222 |
||
223 |
ErrorSignal isNil ifTrue:[ |
|
15222 | 224 |
self initSignals. |
225 |
ErrorRecursion := true. |
|
5971 | 226 |
]. |
227 |
||
228 |
ObjectAttributes isNil ifTrue:[ |
|
14975 | 229 |
ObjectAttributes := WeakIdentityDictionary new. |
5971 | 230 |
]. |
231 |
Dependencies isNil ifTrue:[ |
|
14975 | 232 |
Dependencies := WeakDependencyDictionary new. |
5971 | 233 |
]. |
234 |
NonWeakDependencies isNil ifTrue:[ |
|
14975 | 235 |
NonWeakDependencies := IdentityDictionary new. |
5971 | 236 |
]. |
237 |
SynchronizationSemaphores isNil ifTrue:[ |
|
14975 | 238 |
SynchronizationSemaphores := WeakIdentityDictionary new. |
5971 | 239 |
]. |
5755 | 240 |
FinalizationLobby isNil ifTrue:[ |
14975 | 241 |
FinalizationLobby := Registry new. |
5755 | 242 |
]. |
243 |
||
244 |
"/ initialize InfoPrinting to the VM's infoPrint setting |
|
245 |
"/ (which can be turned off via a command line argument) |
|
246 |
InfoPrinting := ObjectMemory infoPrinting. |
|
247 |
||
248 |
"Object initialize" |
|
249 |
||
250 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
251 |
"Modified: / 3.2.1998 / 18:55:09 / cg" |
|
252 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
253 |
! ! |
|
254 |
||
7303 | 255 |
!Object class methodsFor:'Compatibility-ST80'! |
5755 | 256 |
|
257 |
rootError |
|
258 |
"return the signal used for error/error: - handling. |
|
259 |
Same as errorSignal for ST80 compatibility." |
|
260 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
261 |
^ Error |
5755 | 262 |
|
263 |
"Created: / 15.1.1998 / 23:47:05 / stefan" |
|
264 |
! ! |
|
265 |
||
266 |
!Object class methodsFor:'Signal constants'! |
|
267 |
||
10460 | 268 |
abortAllSignal |
5755 | 269 |
"return the signal used to abort user actions (much like AbortSignal). |
270 |
This signal is supposed to abort multiple operation actions, and get out of |
|
271 |
the loop (such as when confirming multiple class deletions etc.)" |
|
272 |
||
273 |
^ AbortAllSignal |
|
274 |
! |
|
275 |
||
10460 | 276 |
abortSignal |
5755 | 277 |
"return the signal used to abort user actions. This signal is only |
278 |
raised if caught (by the debugger), and will lead way out of the |
|
279 |
currently active doIt/printIt or inspectIt. (also some others use |
|
280 |
this for a save abort)" |
|
281 |
||
8521 | 282 |
^ AbortOperationRequest |
5755 | 283 |
! |
284 |
||
285 |
activityNotificationSignal |
|
286 |
"return the signal used for activity notifications. |
|
287 |
A handler for this signal gets all #activityNotification: sends" |
|
288 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
289 |
^ ActivityNotification |
5755 | 290 |
! |
291 |
||
13416 | 292 |
ambiguousMessageSignal |
293 |
"return the signal used for ambiguousMessage: - error handling" |
|
294 |
||
295 |
^ AmbiguousMessage |
|
296 |
||
297 |
"Created: / 21-07-2010 / 15:39:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
298 |
! |
|
299 |
||
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
300 |
conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
301 |
"return the signal used for conversion error handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
302 |
|
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
303 |
^ ConversionError |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
304 |
! |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
305 |
|
10460 | 306 |
deepCopyErrorSignal |
5755 | 307 |
"return the signal raised when a deepcopy is asked for |
308 |
an object which cannot do this (for example, BlockClosures |
|
309 |
or Contexts)." |
|
310 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
311 |
^ DeepCopyError |
5755 | 312 |
! |
313 |
||
314 |
elementOutOfBoundsSignal |
|
315 |
"return the signal used for element error reporting |
|
316 |
(this signal is used for example when a value not in 0..255 is to |
|
317 |
be put into a bytearray)" |
|
318 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
319 |
^ ElementBoundsError |
5755 | 320 |
! |
321 |
||
322 |
errorSignal |
|
323 |
"return the signal used for error/error: - handling" |
|
324 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
325 |
^ Error |
5755 | 326 |
! |
327 |
||
328 |
haltSignal |
|
329 |
"return the signal used for halt/halt: - handling" |
|
330 |
||
331 |
^ HaltSignal |
|
332 |
! |
|
333 |
||
334 |
indexNotFoundSignal |
|
335 |
"return the signal used for bad index error reporting. |
|
336 |
This is also the parentSignal of the nonIntegerIndex- and |
|
337 |
subscriptOutOfBoundsSignal" |
|
338 |
||
339 |
^ IndexNotFoundSignal |
|
340 |
||
341 |
"Created: / 8.11.1997 / 19:15:48 / cg" |
|
342 |
! |
|
343 |
||
10460 | 344 |
informationSignal |
345 |
"return the signal used for informations. |
|
5755 | 346 |
A handler for this signal gets all #information: sends" |
347 |
||
348 |
^ InformationSignal |
|
349 |
! |
|
350 |
||
351 |
internalErrorSignal |
|
352 |
"return the signal used to report internal (VM-) errors." |
|
353 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
354 |
^ VMInternalError |
5755 | 355 |
! |
356 |
||
10460 | 357 |
keyNotFoundSignal |
5755 | 358 |
"return the signal used for no such key error reporting" |
359 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
360 |
^ KeyNotFoundError |
5755 | 361 |
! |
362 |
||
363 |
messageNotUnderstoodSignal |
|
364 |
"return the signal used for doesNotUnderstand: - error handling" |
|
365 |
||
15193 | 366 |
^ MessageNotUnderstood |
5755 | 367 |
! |
368 |
||
10460 | 369 |
nonIntegerIndexSignal |
5755 | 370 |
"return the signal used for bad subscript error reporting" |
371 |
||
372 |
^ NonIntegerIndexSignal |
|
373 |
! |
|
374 |
||
10460 | 375 |
notFoundSignal |
5755 | 376 |
"return the signal used for no element found error reporting" |
377 |
||
378 |
^ NotFoundSignal |
|
379 |
! |
|
380 |
||
7644
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
381 |
notifySignal |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
382 |
"return the parent of all notification signals." |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
383 |
|
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
384 |
^ Notification |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
385 |
! |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
386 |
|
10460 | 387 |
osSignalInterruptSignal |
5755 | 388 |
"return the signal used for OS-signal error reporting; |
389 |
This is only raised if handled - otherwise, a debugger is entered." |
|
390 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
391 |
^ OSSignalInterrupt |
5755 | 392 |
|
393 |
"Modified: / 12.6.1998 / 16:27:26 / cg" |
|
394 |
! |
|
395 |
||
396 |
primitiveFailureSignal |
|
397 |
"return the signal used for primitiveFailed - error handling" |
|
398 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
399 |
^ PrimitiveFailure |
5755 | 400 |
! |
401 |
||
402 |
privateMethodSignal |
|
403 |
"return the signal used for privateMethod - error handling" |
|
404 |
||
405 |
^ MessageNotUnderstoodSignal |
|
406 |
! |
|
407 |
||
10460 | 408 |
recursionInterruptSignal |
5755 | 409 |
"return the signal used for recursion overflow error handling" |
410 |
||
411 |
^ RecursionInterruptSignal |
|
412 |
! |
|
413 |
||
414 |
recursiveStoreStringSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
415 |
"return the notification used to report storeString generation of recursive objects" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
416 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
417 |
^ RecursiveStoreError |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
418 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
419 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
420 |
RecursiveStoreError handle:[:ex | |
14975 | 421 |
self halt |
5755 | 422 |
] do:[ |
14975 | 423 |
|a| |
424 |
||
425 |
a := Array new:1. |
|
426 |
a at:1 put:a. |
|
427 |
a storeOn:Transcript |
|
5755 | 428 |
] |
429 |
" |
|
430 |
||
431 |
" |
|
432 |
|a| |
|
433 |
||
434 |
a := Array new:1. |
|
435 |
a at:1 put:a. |
|
436 |
a storeOn:Transcript |
|
437 |
" |
|
438 |
! |
|
439 |
||
5980 | 440 |
subclassResponsibilitySignal |
441 |
"return the signal used for subclassResponsibility error reporting. |
|
6652
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
442 |
(this signal is used to signal incomplete subclasses - i.e. a programmers error)" |
5980 | 443 |
|
444 |
^ SubclassResponsibilityError |
|
445 |
! |
|
446 |
||
5755 | 447 |
subscriptOutOfBoundsSignal |
448 |
"return the signal used for subscript error reporting. |
|
449 |
(this signal is used for example when an array is accessed with an |
|
450 |
index less than 1 or greater than the array size)" |
|
451 |
||
452 |
^ SubscriptOutOfBoundsSignal |
|
453 |
! |
|
454 |
||
455 |
userInterruptSignal |
|
456 |
"return the signal used for ^C interrupts handling" |
|
457 |
||
458 |
^ UserInterruptSignal |
|
459 |
! |
|
460 |
||
461 |
userNotificationSignal |
|
462 |
"the parent signal used with information and warnings. |
|
463 |
Handling this allows handling of both information- and warning notifications." |
|
464 |
||
465 |
^ UserNotificationSignal |
|
466 |
! |
|
467 |
||
10460 | 468 |
warningSignal |
5755 | 469 |
"return the signal used for warnings. |
470 |
A handler for this signal gets all #warn: sends" |
|
471 |
||
472 |
^ WarningSignal |
|
473 |
! ! |
|
474 |
||
475 |
!Object class methodsFor:'info messages'! |
|
476 |
||
477 |
infoPrinting |
|
478 |
"return the flag which controls information messages." |
|
479 |
||
480 |
^ InfoPrinting |
|
481 |
! |
|
482 |
||
483 |
infoPrinting:aBoolean |
|
484 |
"{ Pragma: +optSpace }" |
|
485 |
||
486 |
"turn on/off printing of information messages. |
|
487 |
If the argument, aBoolean is false, infoPrint will not output |
|
488 |
messages. The default is true." |
|
489 |
||
490 |
InfoPrinting := aBoolean |
|
491 |
! ! |
|
492 |
||
493 |
!Object class methodsFor:'queries'! |
|
494 |
||
8892 | 495 |
isAbstract |
11221 | 496 |
"Return if this class is an abstract class. |
497 |
True is returned for Object here; false for subclasses. |
|
498 |
Abstract subclasses must redefine again." |
|
499 |
||
8892 | 500 |
^ self == Object |
501 |
! |
|
502 |
||
5755 | 503 |
isBuiltInClass |
504 |
"return true, if this class is known by the run-time-system, |
|
505 |
i.e. you cannot add/remove instance variables without recompiling |
|
506 |
the VM. |
|
507 |
Here, true is returned for myself, false for subclasses." |
|
508 |
||
509 |
^ self == Object |
|
510 |
||
511 |
"Modified: 23.4.1996 / 16:00:07 / cg" |
|
512 |
! ! |
|
513 |
||
14296 | 514 |
|
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
515 |
!Object methodsFor:'Compatibility-Dolphin'! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
516 |
|
11161 | 517 |
stbFixup: anSTBInFiler at: newObjectIndex |
518 |
"Answer the true object that must be used to represent the receiver when read from anSTBInFiler. |
|
519 |
Typically this is overridden by subclasses of STBProxy to answer the proxied object. Other classes |
|
520 |
may also override this method to effectively 'one way become' the receiver to some other object" |
|
521 |
||
522 |
^ self |
|
8441
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 |
|
14682 | 525 |
!Object methodsFor:'Compatibility-GNU'! |
526 |
||
527 |
display |
|
528 |
"print the receiver on the standard output stream (which is not the Transcript). |
|
529 |
Added for GNU-ST compatibility" |
|
530 |
||
531 |
self print |
|
532 |
! |
|
533 |
||
534 |
displayNl |
|
535 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript). |
|
536 |
Added for GNU-ST compatibility" |
|
537 |
||
538 |
self printCR |
|
539 |
! ! |
|
540 |
||
7261 | 541 |
!Object methodsFor:'Compatibility-ST80'! |
5755 | 542 |
|
543 |
isMetaclass |
|
544 |
^ self isMeta |
|
545 |
! ! |
|
546 |
||
7261 | 547 |
!Object methodsFor:'Compatibility-Squeak'! |
5755 | 548 |
|
9071 | 549 |
becomeForward:anotherObject |
550 |
self becomeSameAs:anotherObject |
|
551 |
! |
|
552 |
||
553 |
becomeForward:anotherObject copyHash:copyHash |
|
554 |
copyHash ifTrue:[ self error:'unsupported operation' ]. |
|
555 |
self becomeSameAs:anotherObject |
|
556 |
! |
|
557 |
||
5755 | 558 |
clone |
559 |
^ self shallowCopy |
|
560 |
! |
|
561 |
||
6146 | 562 |
copyTwoLevel |
563 |
"one more level than a shallowCopy" |
|
564 |
||
565 |
^ self copyToLevel:2 |
|
566 |
||
567 |
" |
|
568 |
|original copy elL1 elL2 elL3 copyOfElL1| |
|
569 |
||
570 |
original := Array new:3. |
|
571 |
original at:1 put:1234. |
|
572 |
original at:2 put:'hello'. |
|
573 |
original at:3 put:(elL1 := Array new:3). |
|
574 |
||
575 |
elL1 at:1 put:1234. |
|
576 |
elL1 at:2 put:'hello'. |
|
577 |
elL1 at:3 put:(elL2 := Array new:3). |
|
578 |
||
579 |
elL2 at:1 put:1234. |
|
580 |
elL2 at:2 put:'hello'. |
|
581 |
elL2 at:3 put:(elL3 := Array new:3). |
|
582 |
||
583 |
elL3 at:1 put:1234. |
|
584 |
elL3 at:2 put:'hello'. |
|
585 |
elL3 at:3 put:(Array new:3). |
|
586 |
||
587 |
copy := original copyTwoLevel. |
|
14534 | 588 |
self assert:((original at:2) ~~ (copy at:2)). |
589 |
self assert:((original at:3) ~~ (copy at:3)). |
|
6146 | 590 |
|
591 |
copyOfElL1 := copy at:3. |
|
14534 | 592 |
self assert:((elL1 at:2) == (copyOfElL1 at:2)). |
593 |
self assert:((elL1 at:3) == (copyOfElL1 at:3)). |
|
6146 | 594 |
" |
595 |
! |
|
596 |
||
7320 | 597 |
explore |
598 |
(self confirm:'The Squeak explorer has not yet been ported to ST/X\\Inspect instead ?' withCRs) |
|
599 |
ifTrue:[ |
|
14975 | 600 |
self inspect |
7320 | 601 |
] |
602 |
! |
|
603 |
||
12285
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
604 |
inform: aString |
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
605 |
"Display a message for the user to read and then dismiss." |
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
606 |
|
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
607 |
self information:aString |
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
608 |
! |
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
609 |
|
9335 | 610 |
isInMemory |
611 |
"All normal objects are." |
|
612 |
||
613 |
^ true |
|
614 |
! |
|
615 |
||
5755 | 616 |
stringForReadout |
14975 | 617 |
^ self stringRepresentation |
5755 | 618 |
! |
619 |
||
620 |
stringRepresentation |
|
14975 | 621 |
"Answer a string that represents the receiver. For most objects this is simply its printString, but for strings themselves, it's themselves. 6/12/96 sw" |
622 |
||
623 |
^ self printString |
|
5755 | 624 |
! |
625 |
||
9146
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
626 |
valueWithPossibleArguments:argArray |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
627 |
^ self |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
628 |
! |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
629 |
|
5755 | 630 |
veryDeepCopy |
8383 | 631 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 632 |
! ! |
633 |
||
7567 | 634 |
!Object methodsFor:'Compatibility-VW'! |
635 |
||
8637 | 636 |
isCharacters |
637 |
"added for visual works compatibility" |
|
638 |
^ false |
|
639 |
! |
|
640 |
||
7567 | 641 |
keyNotFoundError:aKey |
642 |
"VW compatibility" |
|
643 |
||
644 |
self errorKeyNotFound:aKey. |
|
645 |
! |
|
646 |
||
647 |
oneWayBecome:anotherObject |
|
648 |
^ self becomeSameAs:anotherObject |
|
649 |
||
650 |
" |
|
651 |
|arr o1 o2| |
|
652 |
||
653 |
arr := Array new:2. |
|
654 |
arr at:1 put:(o1 := Object new). |
|
655 |
arr at:2 put:(o2 := Point new). |
|
656 |
o1 oneWayBecome:o2. |
|
657 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
658 |
" |
|
659 |
" |
|
660 |
|arr o1 o2| |
|
661 |
||
662 |
arr := Array new:2. |
|
663 |
arr at:1 put:(o1 := Object new). |
|
664 |
arr at:2 put:(o2 := Point new). |
|
665 |
o1 becomeSameAs:o2. |
|
666 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
667 |
" |
|
668 |
! ! |
|
669 |
||
15193 | 670 |
|
5755 | 671 |
!Object methodsFor:'accessing'! |
672 |
||
13320 | 673 |
_at:index |
674 |
"experimental: |
|
675 |
this is a synthetic selector, generated by the compiler, |
|
676 |
if a construct of the form expr[idx...] is parsed. |
|
677 |
I.e. |
|
14975 | 678 |
v[n] |
13320 | 679 |
generates |
14975 | 680 |
v _at: n |
13320 | 681 |
" |
682 |
||
683 |
^ self at:index |
|
684 |
||
685 |
"Created: / 21-03-2011 / 14:07:57 / cg" |
|
686 |
! |
|
687 |
||
688 |
_at:index put:value |
|
689 |
"experimental: |
|
690 |
this is a synthetic selector, generated by the compiler, |
|
691 |
if a construct of the form expr[idx...] is parsed. |
|
692 |
I.e. |
|
14975 | 693 |
v[n] |
13320 | 694 |
generates |
14975 | 695 |
v _at: n |
13320 | 696 |
" |
697 |
||
698 |
^ self at:index put:value |
|
699 |
||
700 |
"Created: / 21-03-2011 / 14:10:12 / cg" |
|
701 |
! |
|
702 |
||
14705 | 703 |
addSlot: slotName |
704 |
"dynamically add a new slot to the receiver. |
|
705 |
The receiver must be a real object, not nil or a smallInteger" |
|
706 |
||
707 |
|classGetter myClass anonCls newObj| |
|
708 |
||
709 |
myClass := self class. |
|
710 |
classGetter := ('%__get_',slotName,'__') asSymbol. |
|
711 |
||
712 |
anonCls := self perform:classGetter ifNotUnderstood:nil. |
|
713 |
anonCls isNil ifTrue:[ |
|
714 |
anonCls := myClass |
|
715 |
subclass:(myClass name,'+',slotName) asSymbol |
|
716 |
instanceVariableNames:slotName |
|
717 |
classVariableNames:'' |
|
718 |
poolDictionaries:'' category:nil |
|
719 |
inEnvironment:nil. |
|
720 |
anonCls compile:('%1 ^ %1' bindWith:slotName). |
|
721 |
anonCls compile:('%1:v %1 := v' bindWith:slotName). |
|
722 |
Class withoutUpdatingChangesDo:[ |
|
723 |
|m| |
|
724 |
m := Compiler compile:('__get_',slotName,' ^ #fooBar' bindWith:slotName) forClass:myClass install:false. |
|
725 |
m literalAt:(m literals indexOf:#fooBar) put:anonCls. |
|
726 |
myClass addSelector:classGetter withMethod:m. |
|
727 |
]. |
|
728 |
]. |
|
729 |
newObj := anonCls cloneFrom:self. |
|
730 |
self become:newObj. |
|
731 |
||
732 |
" |
|
733 |
|p1 p2 p3| |
|
734 |
||
735 |
p1 := Point x:10 y:20. |
|
736 |
p2 := Point x:100 y:200. |
|
737 |
Transcript show:'p1 is '; showCR:p1. |
|
738 |
Transcript show:'p2 is '; showCR:p2. |
|
739 |
p1 addSlot:'z'. |
|
740 |
p1 z:30. |
|
741 |
Transcript show:'p1 is '; showCR:p1. |
|
742 |
Transcript show:'p2 is '; showCR:p2. |
|
743 |
ObjectMemory dumpObject:p1. |
|
744 |
ObjectMemory dumpObject:p2. |
|
745 |
||
746 |
p1 addSlot:'t'. |
|
747 |
p1 t:30. |
|
748 |
Transcript show:'p1 is '; showCR:p1. |
|
749 |
ObjectMemory dumpObject:p1. |
|
750 |
||
751 |
p3 := Point x:110 y:120. |
|
752 |
p3 addSlot:'z'. |
|
753 |
p3 addSlot:'t'. |
|
754 |
p1 inspect. |
|
755 |
p2 inspect. |
|
756 |
p3 inspect. |
|
757 |
" |
|
758 |
! |
|
759 |
||
5755 | 760 |
at:index |
761 |
"return the indexed instance variable with index, anInteger; |
|
762 |
this method can be redefined in subclasses." |
|
763 |
||
764 |
^ self basicAt:index |
|
765 |
! |
|
766 |
||
767 |
at:index put:anObject |
|
768 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
769 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
|
770 |
||
771 |
^ self basicAt:index put:anObject |
|
772 |
||
773 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
|
774 |
! |
|
775 |
||
776 |
basicAt:index |
|
777 |
"return the indexed instance variable with index, anInteger. |
|
778 |
Trigger an error if the receiver has no indexed instance variables. |
|
779 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
780 |
||
781 |
%{ /* NOCONTEXT */ |
|
782 |
||
783 |
REGISTER int nbytes, indx; |
|
784 |
OBJ myClass; |
|
785 |
REGISTER char *pFirst; |
|
786 |
REGISTER int n; |
|
787 |
||
788 |
/* |
|
789 |
* notice the missing test for self being a nonNilObject - |
|
790 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
791 |
* and SmallInteger |
|
792 |
*/ |
|
793 |
if (__isSmallInteger(index)) { |
|
14975 | 794 |
myClass = __qClass(self); |
795 |
indx = __intVal(index) - 1; |
|
796 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
797 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
798 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
799 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
800 |
||
801 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
802 |
case __MASKSMALLINT(POINTERARRAY): |
|
803 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
804 |
/* |
|
805 |
* pointers |
|
806 |
*/ |
|
807 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
808 |
OBJ *op; |
|
809 |
||
810 |
op = (OBJ *)pFirst + indx; |
|
811 |
RETURN ( *op ); |
|
812 |
} |
|
813 |
break; |
|
814 |
||
815 |
case __MASKSMALLINT(BYTEARRAY): |
|
816 |
/* |
|
817 |
* (unsigned) bytes |
|
818 |
*/ |
|
819 |
if ((unsigned)indx < nbytes) { |
|
820 |
unsigned char *cp; |
|
821 |
||
822 |
cp = (unsigned char *)pFirst + indx; |
|
823 |
RETURN ( __mkSmallInteger( (*cp & 0xFF)) ); |
|
824 |
} |
|
825 |
break; |
|
826 |
||
827 |
case __MASKSMALLINT(FLOATARRAY): |
|
828 |
/* |
|
829 |
* native floats |
|
830 |
*/ |
|
831 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
832 |
float *fp; |
|
833 |
float f; |
|
834 |
OBJ v; |
|
835 |
||
836 |
fp = (float *)pFirst + indx; |
|
837 |
f = *fp; |
|
838 |
if (f == 0.0) { |
|
839 |
v = __float0; |
|
840 |
} else { |
|
841 |
__qMKSFLOAT(v, f); |
|
842 |
} |
|
843 |
RETURN (v); |
|
844 |
} |
|
845 |
break; |
|
846 |
||
847 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
848 |
/* |
|
849 |
* native doubles |
|
850 |
*/ |
|
5755 | 851 |
#ifdef __NEED_DOUBLE_ALIGN |
14975 | 852 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
853 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
854 |
||
855 |
pFirst += delta; |
|
856 |
nbytes -= delta; |
|
857 |
} |
|
5755 | 858 |
#endif |
14975 | 859 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
860 |
double *dp; |
|
861 |
double d; |
|
862 |
OBJ v; |
|
863 |
||
864 |
dp = (double *)pFirst + indx; |
|
865 |
d = *dp; |
|
866 |
if (d == 0.0) { |
|
867 |
v = __float0; |
|
868 |
} else { |
|
869 |
__qMKFLOAT(v, d); |
|
870 |
} |
|
871 |
RETURN (v); |
|
872 |
} |
|
873 |
break; |
|
874 |
||
875 |
case __MASKSMALLINT(WORDARRAY): |
|
876 |
/* |
|
877 |
* unsigned 16bit ints |
|
878 |
*/ |
|
879 |
/* Notice: the hard coded shifts are by purpose; |
|
880 |
* it makes us independent of the short-size of the machine |
|
881 |
*/ |
|
882 |
if ((unsigned)indx < (nbytes>>1)) { |
|
883 |
unsigned short *sp; |
|
884 |
||
885 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
886 |
RETURN ( __mkSmallInteger( (*sp & 0xFFFF)) ); |
|
887 |
} |
|
888 |
break; |
|
889 |
||
890 |
case __MASKSMALLINT(SWORDARRAY): |
|
891 |
/* |
|
892 |
* signed 16bit ints |
|
893 |
*/ |
|
894 |
/* Notice: the hard coded shifts are by purpose; |
|
895 |
* it makes us independent of the short-size of the machine |
|
896 |
*/ |
|
897 |
if ((unsigned)indx < (nbytes>>1)) { |
|
898 |
short *ssp; |
|
899 |
||
900 |
ssp = (short *)(pFirst + (indx<<1)); |
|
901 |
RETURN ( __mkSmallInteger( (*ssp) )); |
|
902 |
} |
|
903 |
break; |
|
904 |
||
905 |
case __MASKSMALLINT(LONGARRAY): |
|
906 |
/* |
|
907 |
* unsigned 32bit ints |
|
908 |
*/ |
|
909 |
/* Notice: the hard coded shifts are by purpose; |
|
910 |
* it makes us independent of the int-size of the machine |
|
911 |
*/ |
|
912 |
if ((unsigned)indx < (nbytes>>2)) { |
|
913 |
unsigned int32 ul; |
|
914 |
unsigned int32 *lp; |
|
915 |
||
916 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
917 |
ul = *lp; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
918 |
#if __POINTER_SIZE__ == 8 |
14975 | 919 |
{ |
920 |
unsigned INT ull = (unsigned INT)ul; |
|
921 |
RETURN ( __mkSmallInteger(ull) ); |
|
922 |
} |
|
5755 | 923 |
#else |
14975 | 924 |
if (ul <= _MAX_INT) { |
925 |
RETURN ( __mkSmallInteger(ul) ); |
|
926 |
} |
|
927 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 928 |
#endif |
14975 | 929 |
} |
930 |
break; |
|
931 |
||
932 |
case __MASKSMALLINT(SLONGARRAY): |
|
933 |
/* |
|
934 |
* signed 32bit ints |
|
935 |
*/ |
|
936 |
/* Notice: the hard coded shifts are by purpose; |
|
937 |
* it makes us independent of the int-size of the machine |
|
938 |
*/ |
|
939 |
if ((unsigned)indx < (nbytes>>2)) { |
|
940 |
int32 *slp; |
|
941 |
int32 l; |
|
942 |
||
943 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
944 |
l = *slp; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
945 |
#if __POINTER_SIZE__ == 8 |
14975 | 946 |
{ |
947 |
INT ll = (INT)l; |
|
948 |
RETURN ( __mkSmallInteger(ll) ); |
|
949 |
} |
|
5755 | 950 |
#else |
14975 | 951 |
if (__ISVALIDINTEGER(l)) { |
952 |
RETURN ( __mkSmallInteger(l) ); |
|
953 |
} |
|
954 |
RETURN ( __MKLARGEINT(l) ); |
|
5755 | 955 |
#endif |
14975 | 956 |
} |
957 |
break; |
|
958 |
||
959 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
960 |
/* |
|
961 |
* signed 64bit longlongs |
|
962 |
*/ |
|
5755 | 963 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 964 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
965 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
966 |
||
967 |
pFirst += delta; |
|
968 |
nbytes -= delta; |
|
969 |
} |
|
5755 | 970 |
#endif |
14975 | 971 |
/* Notice: the hard coded shifts are by purpose; |
972 |
* it makes us independent of the long/longlong-size of the machine |
|
973 |
*/ |
|
974 |
if ((unsigned)indx < (nbytes>>3)) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
975 |
#if __POINTER_SIZE__ == 8 |
14975 | 976 |
INT *slp, ll; |
977 |
||
978 |
slp = (INT *)(pFirst + (indx<<3)); |
|
979 |
ll = *slp; |
|
980 |
if (__ISVALIDINTEGER(ll)) { |
|
981 |
RETURN ( __mkSmallInteger(ll) ); |
|
982 |
} |
|
983 |
RETURN ( __MKLARGEINT(ll) ); |
|
5755 | 984 |
#else |
14975 | 985 |
__int64__ *llp; |
986 |
||
987 |
llp = (__int64__ *)(pFirst + (indx<<3)); |
|
988 |
RETURN (__MKINT64(llp)); |
|
5755 | 989 |
#endif |
14975 | 990 |
} |
991 |
break; |
|
992 |
||
993 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
994 |
/* |
|
995 |
* unsigned 64bit longlongs |
|
996 |
*/ |
|
5755 | 997 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 998 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
999 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1000 |
||
1001 |
pFirst += delta; |
|
1002 |
nbytes -= delta; |
|
1003 |
} |
|
5755 | 1004 |
#endif |
14975 | 1005 |
/* Notice: the hard coded shifts are by purpose; |
1006 |
* it makes us independent of the long/longlong-size of the machine |
|
1007 |
*/ |
|
1008 |
if ((unsigned)indx < (nbytes>>3)) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
1009 |
#if __POINTER_SIZE__ == 8 |
14975 | 1010 |
unsigned INT *ulp, ul; |
1011 |
||
1012 |
ulp = (unsigned INT *)(pFirst + (indx<<3)); |
|
1013 |
ul = *ulp; |
|
1014 |
if (ul <= _MAX_INT) { |
|
1015 |
RETURN ( __mkSmallInteger(ul) ); |
|
1016 |
} |
|
1017 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 1018 |
#else |
14975 | 1019 |
__uint64__ *llp; |
1020 |
||
1021 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
1022 |
RETURN (__MKUINT64(llp)); |
|
5755 | 1023 |
#endif |
14975 | 1024 |
} |
1025 |
break; |
|
1026 |
} |
|
5755 | 1027 |
} |
1028 |
%}. |
|
7216 | 1029 |
^ self indexNotIntegerOrOutOfBounds:index |
5755 | 1030 |
! |
1031 |
||
1032 |
basicAt:index put:anObject |
|
1033 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
1034 |
Returns anObject (sigh). |
|
1035 |
Trigger an error if the receiver has no indexed instance variables. |
|
1036 |
||
1037 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
1038 |
||
1039 |
%{ /* NOCONTEXT */ |
|
1040 |
||
1041 |
register int nbytes, indx; |
|
1042 |
OBJ myClass; |
|
1043 |
register char *pFirst; |
|
1044 |
/* int nInstBytes, ninstvars, flags; */ |
|
1045 |
REGISTER int n; |
|
1046 |
unsigned int u; |
|
1047 |
int val; |
|
1048 |
||
1049 |
/* notice the missing test for self being a nonNilObject - |
|
1050 |
this can be done since basicAt: is defined both in UndefinedObject |
|
1051 |
and SmallInteger */ |
|
1052 |
||
1053 |
if (__isSmallInteger(index)) { |
|
14975 | 1054 |
indx = __intVal(index) - 1; |
1055 |
myClass = __qClass(self); |
|
1056 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1057 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
1058 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
1059 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
1060 |
||
1061 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1062 |
case __MASKSMALLINT(POINTERARRAY): |
|
1063 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
1064 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
1065 |
OBJ *op; |
|
1066 |
||
1067 |
op = (OBJ *)pFirst + indx; |
|
1068 |
*op = anObject; |
|
1069 |
__STORE(self, anObject); |
|
1070 |
RETURN ( anObject ); |
|
1071 |
} |
|
1072 |
break; |
|
1073 |
||
1074 |
case __MASKSMALLINT(BYTEARRAY): |
|
1075 |
if (__isSmallInteger(anObject)) { |
|
1076 |
val = __intVal(anObject); |
|
1077 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
1078 |
if ((unsigned)indx < nbytes) { |
|
1079 |
char *cp; |
|
1080 |
||
1081 |
cp = pFirst + indx; |
|
1082 |
*cp = val; |
|
1083 |
RETURN ( anObject ); |
|
1084 |
} |
|
1085 |
} |
|
1086 |
} |
|
1087 |
break; |
|
1088 |
||
1089 |
case __MASKSMALLINT(FLOATARRAY): |
|
1090 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
1091 |
float *fp; |
|
1092 |
||
1093 |
fp = (float *)pFirst + indx; |
|
1094 |
if (anObject != nil) { |
|
1095 |
if (! __isSmallInteger(anObject)) { |
|
1096 |
if (__qIsFloatLike(anObject)) { |
|
1097 |
*fp = (float)(__floatVal(anObject)); |
|
1098 |
RETURN ( anObject ); |
|
1099 |
} |
|
1100 |
if (__qIsShortFloat(anObject)) { |
|
1101 |
*fp = __shortFloatVal(anObject); |
|
1102 |
RETURN ( anObject ); |
|
1103 |
} |
|
1104 |
} else { |
|
1105 |
*fp = (float) __intVal(anObject); |
|
1106 |
RETURN ( anObject ); |
|
1107 |
} |
|
1108 |
} |
|
1109 |
} |
|
1110 |
break; |
|
1111 |
||
1112 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1113 |
#ifdef __NEED_DOUBLE_ALIGN |
14975 | 1114 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1115 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1116 |
||
1117 |
pFirst += delta; |
|
1118 |
nbytes -= delta; |
|
1119 |
} |
|
5755 | 1120 |
#endif |
14975 | 1121 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
1122 |
double *dp; |
|
1123 |
||
1124 |
dp = (double *)pFirst + indx; |
|
1125 |
if (anObject != nil) { |
|
1126 |
if (! __isSmallInteger(anObject)) { |
|
1127 |
if (__qIsFloatLike(anObject)) { |
|
1128 |
*dp = __floatVal(anObject); |
|
1129 |
RETURN ( anObject ); |
|
1130 |
} |
|
1131 |
if (__qIsShortFloat(anObject)) { |
|
1132 |
*dp = (double)__shortFloatVal(anObject); |
|
1133 |
RETURN ( anObject ); |
|
1134 |
} |
|
1135 |
} else { |
|
1136 |
*dp = (double) __intVal(anObject); |
|
1137 |
RETURN ( anObject ); |
|
1138 |
} |
|
1139 |
} |
|
1140 |
} |
|
1141 |
break; |
|
1142 |
||
1143 |
case __MASKSMALLINT(WORDARRAY): |
|
1144 |
if (__isSmallInteger(anObject)) { |
|
1145 |
val = __intVal(anObject); |
|
1146 |
if ((unsigned)val <= 0xFFFF) { |
|
1147 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1148 |
unsigned short *sp; |
|
1149 |
||
1150 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
1151 |
*sp = val; |
|
1152 |
RETURN ( anObject ); |
|
1153 |
} |
|
1154 |
} |
|
1155 |
} |
|
1156 |
break; |
|
1157 |
||
1158 |
case __MASKSMALLINT(SWORDARRAY): |
|
1159 |
if (__isSmallInteger(anObject)) { |
|
1160 |
val = __intVal(anObject); |
|
1161 |
if ((val >= -32768) && (val < 32768)) { |
|
1162 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1163 |
short *ssp; |
|
1164 |
||
1165 |
ssp = (short *)(pFirst + (indx<<1)); |
|
1166 |
*ssp = val; |
|
1167 |
RETURN ( anObject ); |
|
1168 |
} |
|
1169 |
} |
|
1170 |
} |
|
1171 |
break; |
|
1172 |
||
1173 |
case __MASKSMALLINT(SLONGARRAY): |
|
1174 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1175 |
int32 *slp; |
|
1176 |
||
1177 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
1178 |
if (__isSmallInteger(anObject)) { |
|
1179 |
*slp = __intVal(anObject); |
|
1180 |
RETURN ( anObject ); |
|
1181 |
} |
|
1182 |
n = __signedLongIntVal(anObject); |
|
1183 |
/* |
|
1184 |
* zero means failure for an int larger than INT-size bytes |
|
1185 |
* (would be a smallInteger) |
|
1186 |
*/ |
|
1187 |
if (n) { |
|
14632 | 1188 |
#if __POINTER_SIZE__ == 8 |
14975 | 1189 |
if ((n >= -0x80000000) && (n < 0x80000000)) |
14632 | 1190 |
#endif |
14975 | 1191 |
{ |
1192 |
*slp = n; |
|
1193 |
RETURN ( anObject ); |
|
1194 |
} |
|
1195 |
} |
|
1196 |
} |
|
1197 |
break; |
|
1198 |
||
1199 |
case __MASKSMALLINT(LONGARRAY): |
|
1200 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1201 |
unsigned int32 *lp; |
|
1202 |
||
1203 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
1204 |
if (anObject == __mkSmallInteger(0)) { |
|
1205 |
*lp = 0; |
|
1206 |
RETURN ( anObject ); |
|
1207 |
} |
|
1208 |
u = __longIntVal(anObject); |
|
1209 |
/* |
|
1210 |
* zero means failure for an int larger than 4 bytes |
|
1211 |
* (would be a smallInteger) |
|
1212 |
*/ |
|
1213 |
if (u) { |
|
14632 | 1214 |
#if __POINTER_SIZE__ == 8 |
14975 | 1215 |
if (u <= 0xFFFFFFFF) |
14632 | 1216 |
#endif |
14975 | 1217 |
{ |
1218 |
*lp = u; |
|
1219 |
RETURN ( anObject ); |
|
1220 |
} |
|
1221 |
} |
|
1222 |
} |
|
1223 |
break; |
|
1224 |
||
1225 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1226 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 1227 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1228 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1229 |
||
1230 |
pFirst += delta; |
|
1231 |
nbytes -= delta; |
|
1232 |
} |
|
14632 | 1233 |
#endif |
14975 | 1234 |
if ((unsigned)indx < (nbytes>>3)) { |
1235 |
__int64__ ll; |
|
1236 |
__int64__ *sllp; |
|
1237 |
||
1238 |
sllp = (__int64__ *)(pFirst + (indx<<3)); |
|
14632 | 1239 |
|
1240 |
#if __POINTER_SIZE__ == 8 |
|
14975 | 1241 |
if (__isSmallInteger(anObject)) { |
1242 |
*sllp = __intVal(anObject); |
|
1243 |
RETURN ( anObject ); |
|
1244 |
} |
|
1245 |
n = __signedLongIntVal(anObject); |
|
1246 |
if (n) { |
|
1247 |
*sllp = n; |
|
1248 |
RETURN ( anObject ); |
|
1249 |
} |
|
14632 | 1250 |
#else |
14975 | 1251 |
if (anObject == __mkSmallInteger(0)) { |
1252 |
ll.lo = ll.hi = 0; |
|
1253 |
*sllp = ll; |
|
1254 |
RETURN ( anObject ); |
|
1255 |
} |
|
1256 |
if (__signedLong64IntVal(anObject, &ll)) { |
|
1257 |
*sllp = ll; |
|
1258 |
RETURN ( anObject ); |
|
1259 |
} |
|
5755 | 1260 |
#endif |
14975 | 1261 |
} |
1262 |
break; |
|
1263 |
||
1264 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
5755 | 1265 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 1266 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1267 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1268 |
||
1269 |
pFirst += delta; |
|
1270 |
nbytes -= delta; |
|
1271 |
} |
|
5755 | 1272 |
#endif |
14975 | 1273 |
if ((unsigned)indx < (nbytes>>3)) { |
1274 |
__uint64__ ll; |
|
1275 |
__uint64__ *llp; |
|
1276 |
||
1277 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
14632 | 1278 |
#if __POINTER_SIZE__ == 8 |
14975 | 1279 |
if (__isSmallInteger(anObject)) { |
1280 |
*llp = __intVal(anObject); |
|
1281 |
RETURN ( anObject ); |
|
1282 |
} |
|
1283 |
ll = __longIntVal(anObject); |
|
1284 |
if (ll) { |
|
1285 |
*llp = ll; |
|
1286 |
RETURN ( anObject ); |
|
1287 |
} |
|
14632 | 1288 |
#else |
14975 | 1289 |
if (anObject == __mkSmallInteger(0)) { |
1290 |
ll.lo = ll.hi = 0; |
|
1291 |
*llp = ll; |
|
1292 |
RETURN ( anObject ); |
|
1293 |
} |
|
1294 |
if (__unsignedLong64IntVal(anObject, &ll)) { |
|
1295 |
*llp = ll; |
|
1296 |
RETURN ( anObject ); |
|
1297 |
} |
|
14632 | 1298 |
#endif |
14975 | 1299 |
} |
1300 |
break; |
|
1301 |
} |
|
5755 | 1302 |
} |
1303 |
%}. |
|
1304 |
index isInteger ifFalse:[ |
|
14975 | 1305 |
" |
1306 |
the index should be an integer number |
|
1307 |
" |
|
1308 |
^ self indexNotInteger:index |
|
5755 | 1309 |
]. |
1310 |
(index between:1 and:self size) ifFalse:[ |
|
14975 | 1311 |
" |
1312 |
the index is less than 1 or greater than the size of the |
|
1313 |
receiver collection |
|
1314 |
" |
|
1315 |
^ self subscriptBoundsError:index |
|
5755 | 1316 |
]. |
1317 |
(self class isFloatsOrDoubles) ifTrue:[ |
|
14975 | 1318 |
anObject isNumber ifTrue:[ |
1319 |
^ self basicAt:index put:(anObject asFloat) |
|
1320 |
] |
|
5755 | 1321 |
]. |
1322 |
anObject isInteger ifFalse:[ |
|
14975 | 1323 |
" |
1324 |
the object to put into the receiver collection |
|
1325 |
should be an integer number |
|
1326 |
" |
|
1327 |
^ self elementNotInteger |
|
5755 | 1328 |
]. |
1329 |
" |
|
1330 |
the object to put into the receiver collection |
|
1331 |
is not an instance of the expected element class, |
|
1332 |
or the value is not within the elements valid range. |
|
1333 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1334 |
^ self elementBoundsError:anObject |
5755 | 1335 |
|
1336 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
|
1337 |
! |
|
1338 |
||
1339 |
byteAt:index |
|
10460 | 1340 |
"return the byte at index. |
5755 | 1341 |
This is only allowed for non-pointer indexed objects |
1342 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1343 |
The receivers indexed instvars are treated as an uninterpreted |
|
1344 |
collection of bytes. |
|
1345 |
Only useful with binary storage." |
|
1346 |
||
1347 |
%{ /* NOCONTEXT */ |
|
1348 |
||
1349 |
REGISTER int indx; |
|
1350 |
int nIndex; |
|
1351 |
REGISTER OBJ slf; |
|
1352 |
REGISTER OBJ cls; |
|
1353 |
||
1354 |
if (__isSmallInteger(index)) { |
|
14975 | 1355 |
slf = self; |
1356 |
if (__isNonNilObject(slf)) { |
|
1357 |
unsigned char *pFirst; |
|
1358 |
int nIndex; |
|
1359 |
||
1360 |
cls = __qClass(slf); |
|
1361 |
||
1362 |
pFirst = __byteArrayVal(slf); |
|
1363 |
pFirst += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1364 |
nIndex = __byteArraySize(slf); |
|
1365 |
indx = __intVal(index) - 1; |
|
1366 |
||
1367 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1368 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1369 |
#ifdef __NEED_DOUBLE_ALIGN |
14975 | 1370 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1371 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1372 |
||
1373 |
pFirst += delta; |
|
1374 |
nIndex -= delta; |
|
1375 |
} |
|
5755 | 1376 |
#endif |
14975 | 1377 |
/* fall into */ |
1378 |
case __MASKSMALLINT(BYTEARRAY): |
|
1379 |
case __MASKSMALLINT(WORDARRAY): |
|
1380 |
case __MASKSMALLINT(LONGARRAY): |
|
1381 |
case __MASKSMALLINT(SWORDARRAY): |
|
1382 |
case __MASKSMALLINT(SLONGARRAY): |
|
1383 |
case __MASKSMALLINT(FLOATARRAY): |
|
1384 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1385 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
|
1386 |
} |
|
1387 |
break; |
|
1388 |
||
1389 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1390 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1391 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 1392 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1393 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1394 |
||
1395 |
pFirst += delta; |
|
1396 |
nIndex -= delta; |
|
1397 |
} |
|
5755 | 1398 |
#endif |
14975 | 1399 |
if ((unsigned)indx < (unsigned)nIndex) { |
1400 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
|
1401 |
} |
|
1402 |
break; |
|
1403 |
} |
|
1404 |
} |
|
5755 | 1405 |
} |
1406 |
%}. |
|
1407 |
"/ index not integer or index out of range |
|
1408 |
"/ or non-byte indexable receiver |
|
1409 |
||
1410 |
^ self primitiveFailed |
|
1411 |
||
1412 |
" |
|
1413 |
Point new byteAt:1 |
|
1414 |
(ByteArray with:1 with:2) byteAt:2 |
|
10460 | 1415 |
(WordArray with:1) byteAt:1 |
1416 |
(FloatArray with:1.0) byteAt:2 |
|
1417 |
'hello' byteAt:1 |
|
5755 | 1418 |
" |
1419 |
! |
|
1420 |
||
1421 |
byteAt:index put:byteValue |
|
10460 | 1422 |
"set the byte at index. |
5755 | 1423 |
This is only allowed for non-pointer indexed objects |
1424 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1425 |
The receivers indexed instvars are treated as an uninterpreted |
|
1426 |
collection of bytes. |
|
1427 |
Only useful with binary storage." |
|
1428 |
||
1429 |
%{ /* NOCONTEXT */ |
|
1430 |
||
1431 |
REGISTER int indx; |
|
1432 |
int val, nIndex; |
|
1433 |
REGISTER OBJ slf; |
|
1434 |
REGISTER OBJ cls; |
|
1435 |
||
1436 |
if (__bothSmallInteger(index, byteValue)) { |
|
14975 | 1437 |
val = __intVal(byteValue); |
1438 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
1439 |
slf = self; |
|
1440 |
if (__isNonNilObject(slf)) { |
|
1441 |
cls = __qClass(slf); |
|
1442 |
||
1443 |
indx = __intVal(index) - 1; |
|
1444 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1445 |
case __MASKSMALLINT(BYTEARRAY): |
|
1446 |
case __MASKSMALLINT(WORDARRAY): |
|
1447 |
case __MASKSMALLINT(LONGARRAY): |
|
1448 |
case __MASKSMALLINT(SWORDARRAY): |
|
1449 |
case __MASKSMALLINT(SLONGARRAY): |
|
1450 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1451 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1452 |
case __MASKSMALLINT(FLOATARRAY): |
|
1453 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
1454 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1455 |
nIndex = __byteArraySize(slf); |
|
1456 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1457 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
1458 |
RETURN ( byteValue ); |
|
1459 |
} |
|
1460 |
break; |
|
1461 |
} |
|
1462 |
} |
|
1463 |
} |
|
5755 | 1464 |
} |
1465 |
%}. |
|
1466 |
"/ index not integer or index out of range |
|
1467 |
"/ or non-byte indexable receiver |
|
1468 |
||
1469 |
^ self primitiveFailed |
|
1470 |
||
1471 |
" |
|
1472 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
|
10460 | 1473 |
'hello' copy byteAt:1 put:105; yourself |
5755 | 1474 |
" |
1475 |
! |
|
1476 |
||
1477 |
instVarAt:index |
|
1478 |
"return a non-indexed instance variable; |
|
10460 | 1479 |
peeking into an object this way is not very object oriented |
5755 | 1480 |
- use with care (needed for copy, inspector etc.)" |
1481 |
||
1482 |
%{ /* NOCONTEXT */ |
|
1483 |
||
1484 |
OBJ myClass; |
|
1485 |
int idx, ninstvars; |
|
1486 |
||
1487 |
if (__isSmallInteger(index)) { |
|
14975 | 1488 |
myClass = __Class(self); |
1489 |
idx = __intVal(index) - 1; |
|
1490 |
/* |
|
1491 |
* do not allow returning of non-object fields. |
|
1492 |
* if subclass did not make provisions for that, |
|
1493 |
* we won't do so here ... |
|
1494 |
*/ |
|
1495 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1496 |
if (idx == 0) { |
|
1497 |
RETURN ( nil ) |
|
1498 |
} |
|
1499 |
} |
|
1500 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1501 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1502 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
|
1503 |
} |
|
5755 | 1504 |
} |
7216 | 1505 |
%}. |
1506 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1507 |
! |
1508 |
||
1509 |
instVarAt:index put:value |
|
1510 |
"change a non-indexed instance variable; |
|
10460 | 1511 |
peeking into an object this way is not very object oriented |
5755 | 1512 |
- use with care (needed for copy, inspector etc.)" |
1513 |
||
1514 |
%{ /* NOCONTEXT */ |
|
1515 |
||
1516 |
OBJ myClass; |
|
1517 |
int idx, ninstvars; |
|
1518 |
||
1519 |
if (__isSmallInteger(index)) { |
|
14975 | 1520 |
myClass = __Class(self); |
1521 |
idx = __intVal(index) - 1; |
|
1522 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1523 |
/* |
|
1524 |
* do not allow setting of non-object fields. |
|
1525 |
* if subclass did not make provisions for that, |
|
1526 |
* we won't do so here ... |
|
1527 |
*/ |
|
1528 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1529 |
if (idx == 0) { |
|
1530 |
RETURN ( nil ) |
|
1531 |
} |
|
1532 |
} |
|
1533 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1534 |
__InstPtr(self)->i_instvars[idx] = value; |
|
1535 |
__STORE(self, value); |
|
1536 |
RETURN ( value ); |
|
1537 |
} |
|
5755 | 1538 |
} |
7216 | 1539 |
%}. |
1540 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1541 |
! |
1542 |
||
10460 | 1543 |
instVarNamed:name |
5755 | 1544 |
"return a non-indexed instance variables value by name; |
10460 | 1545 |
peeking into an object this way is not very object oriented |
5755 | 1546 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1547 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1548 |
parsed ad runtime)" |
|
1549 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1550 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1551 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1552 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1553 |
idx isNil ifTrue:[ |
14975 | 1554 |
^ self errorKeyNotFound:name. |
11335 | 1555 |
]. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1556 |
^ self instVarAt:idx. |
5755 | 1557 |
|
1558 |
||
1559 |
" |
|
1560 |
|p| |
|
1561 |
||
1562 |
p := Point x:10 y:20. |
|
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1563 |
p instVarNamed:'cx' |
5755 | 1564 |
" |
1565 |
||
1566 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
|
1567 |
! |
|
1568 |
||
1569 |
instVarNamed:name ifAbsent:exceptionBlock |
|
1570 |
"return a non-indexed instance variables value by name, |
|
1571 |
or the value of exceptionBlock, if there is no such instance variable. |
|
10460 | 1572 |
peeking into an object this way is not very object oriented |
5755 | 1573 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1574 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1575 |
parsed ad runtime)" |
|
1576 |
||
1577 |
|idx| |
|
1578 |
||
1579 |
idx := self class instVarOffsetOf:name. |
|
1580 |
idx isNil ifTrue:[^ exceptionBlock value]. |
|
1581 |
^ self instVarAt:idx |
|
1582 |
||
1583 |
||
1584 |
" |
|
1585 |
|p| |
|
1586 |
||
1587 |
p := Point x:10 y:20. |
|
10460 | 1588 |
p instVarNamed:'x' |
5755 | 1589 |
" |
1590 |
||
1591 |
"Created: 6.7.1996 / 23:02:49 / cg" |
|
1592 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
|
1593 |
! |
|
1594 |
||
1595 |
instVarNamed:name put:value |
|
1596 |
"set a non-indexed instance variable by name; |
|
10460 | 1597 |
peeking into an object this way is not very object oriented |
5755 | 1598 |
- if at all, use with care (provided for protocol completeness). |
1599 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1600 |
parsed ad runtime)" |
|
1601 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1602 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1603 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1604 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1605 |
idx isNil ifTrue:[ |
14975 | 1606 |
^ self errorKeyNotFound:name. |
11335 | 1607 |
]. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1608 |
^ self instVarAt:idx put:value. |
5755 | 1609 |
|
1610 |
" |
|
1611 |
|p| |
|
1612 |
||
1613 |
p := Point x:10 y:20. |
|
1614 |
p instVarNamed:'x' put:30. |
|
10460 | 1615 |
p |
5755 | 1616 |
" |
1617 |
||
1618 |
"Modified: 19.4.1996 / 11:12:49 / cg" |
|
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1619 |
! |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1620 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1621 |
instVarNamed:name put:anObject ifAbsent:exceptionBlock |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1622 |
"return a non-indexed instance variables value by name, |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1623 |
or the value of exceptionBlock, if there is no such instance variable. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1624 |
peeking into an object this way is not very object oriented |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1625 |
- use with care if at all (provided for inspectors and memory usage monitor). |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1626 |
Notice, this access is very slow (because the classes instVar-description has to be |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1627 |
parsed ad runtime)" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1628 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1629 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1630 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1631 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1632 |
idx isNil ifTrue:[^ exceptionBlock value]. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1633 |
^ self instVarAt:idx put:anObject. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1634 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1635 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1636 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1637 |
|p| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1638 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1639 |
p := Point x:10 y:20. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1640 |
p instVarNamed:'x' put:4711 ifAbsent:[self halt:'no such instvar']. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1641 |
p instVarNamed:'bla' put:4712 ifAbsent:[self halt:'no such instvar']. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1642 |
p inspect. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1643 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1644 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1645 |
"Created: 6.7.1996 / 23:02:49 / cg" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1646 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
5755 | 1647 |
! ! |
1648 |
||
1649 |
!Object methodsFor:'attributes access'! |
|
1650 |
||
10460 | 1651 |
objectAttributeAt:attributeKey |
5755 | 1652 |
"return the attribute for a given key or nil if not found" |
1653 |
||
1654 |
| attrs | |
|
1655 |
||
1656 |
attrs := self objectAttributes. |
|
1657 |
(attrs notNil and:[attrs size > 0]) ifTrue:[ |
|
14975 | 1658 |
^ attrs at:attributeKey ifAbsent:[] |
5755 | 1659 |
]. |
1660 |
^ nil |
|
1661 |
||
1662 |
"Created: / 22.1.1998 / 21:29:17 / av" |
|
1663 |
"Modified: / 3.2.1998 / 18:55:55 / cg" |
|
1664 |
! |
|
1665 |
||
6323 | 1666 |
objectAttributeAt:attributeKey put:anObject |
5755 | 1667 |
"store the attribute anObject referenced by key into the receiver" |
1668 |
||
1669 |
"/ must do this save from interrupts, since the attributes collection |
|
1670 |
"/ is possibly accessed from multiple threads ... |
|
1671 |
[ |
|
14975 | 1672 |
| attrs | |
1673 |
||
1674 |
attrs := self objectAttributes. |
|
1675 |
(attrs isNil or:[attrs size == 0]) ifTrue:[ |
|
1676 |
attrs := WeakIdentityDictionary new. |
|
1677 |
attrs at:attributeKey put:anObject. |
|
1678 |
self objectAttributes:attrs. |
|
1679 |
] ifFalse:[ |
|
1680 |
attrs at:attributeKey put:anObject. |
|
1681 |
]. |
|
6323 | 1682 |
] valueUninterruptably |
5755 | 1683 |
|
1684 |
"Attaching additional attributes (slots) to an arbitrary object: |
|
1685 |
||
1686 |
|p| |
|
1687 |
||
1688 |
p := Point new. |
|
1689 |
p objectAttributeAt:#color put:#green. |
|
1690 |
||
1691 |
p objectAttributeAt:#color |
|
1692 |
" |
|
1693 |
||
1694 |
"Created: / 22.1.1998 / 21:29:25 / av" |
|
1695 |
"Modified: / 3.2.1998 / 18:57:58 / cg" |
|
1696 |
! |
|
1697 |
||
1698 |
objectAttributes |
|
1699 |
"return a Collection of attributes - nil if there is none. |
|
1700 |
The default implementation here uses a global WeakDictionary to store |
|
1701 |
attributes |
|
1702 |
This may be too slow for high frequency slot access, |
|
13416 | 1703 |
therefore, some classes may redefine this for better performnce. |
5755 | 1704 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
1705 |
||
1706 |
^ ObjectAttributes at:self ifAbsent:[nil] |
|
1707 |
||
1708 |
"Created: / 22.1.1998 / 21:29:30 / av" |
|
1709 |
"Modified: / 18.2.2000 / 11:34:16 / cg" |
|
1710 |
! |
|
1711 |
||
1712 |
objectAttributes:aCollection |
|
1713 |
"set the collection of attributes. |
|
1714 |
The default implementation here uses a global Dictionary to store |
|
1715 |
attributes which may be too slow for high frequency change&update. |
|
1716 |
Therefore, some classes may redefine this for better performance." |
|
1717 |
||
1718 |
"/ must do this save from interrupts, since the attributes collection |
|
1719 |
"/ is possibly accessed from multiple threads. |
|
1720 |
||
1721 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
14975 | 1722 |
"/ the common case - already blocked |
1723 |
||
1724 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
1725 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1726 |
] ifFalse:[ |
|
1727 |
ObjectAttributes at:self put:aCollection |
|
1728 |
]. |
|
1729 |
^ self |
|
5755 | 1730 |
]. |
1731 |
||
1732 |
[ |
|
14975 | 1733 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
1734 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1735 |
] ifFalse:[ |
|
1736 |
ObjectAttributes at:self put:aCollection |
|
1737 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
1738 |
] ensure:[ |
14975 | 1739 |
OperatingSystem unblockInterrupts |
5755 | 1740 |
] |
1741 |
||
1742 |
"Created: / 22.1.1998 / 21:29:35 / av" |
|
1743 |
"Modified: / 3.2.1998 / 18:58:10 / cg" |
|
1744 |
! |
|
1745 |
||
6323 | 1746 |
removeObjectAttribute:attributeKey |
5755 | 1747 |
"make the argument, anObject be no attribute of the receiver" |
1748 |
||
1749 |
"/ must do this save from interrupts, since the attributes collection |
|
1750 |
"/ is possibly accessed from multiple threads. |
|
1751 |
[ |
|
14975 | 1752 |
|attrs n a| |
1753 |
||
1754 |
attrs := self objectAttributes. |
|
1755 |
attrs notNil ifTrue:[ |
|
1756 |
attrs size == 0 ifTrue:[ |
|
1757 |
self objectAttributes:nil |
|
1758 |
] ifFalse:[ |
|
1759 |
attrs removeKey:attributeKey ifAbsent:nil. |
|
1760 |
attrs size == 0 ifTrue:[ |
|
1761 |
self objectAttributes:nil |
|
1762 |
] |
|
1763 |
] |
|
1764 |
] |
|
6323 | 1765 |
] valueUninterruptably |
5755 | 1766 |
|
1767 |
"Created: / 22.1.1998 / 21:29:39 / av" |
|
1768 |
"Modified: / 18.2.2000 / 11:32:19 / cg" |
|
1769 |
! ! |
|
1770 |
||
13500 | 1771 |
|
5755 | 1772 |
!Object methodsFor:'change & update'! |
1773 |
||
1774 |
broadcast:aSelectorSymbol |
|
1775 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1776 |
||
10460 | 1777 |
self dependentsDo:[:dependent | |
14975 | 1778 |
dependent perform:aSelectorSymbol |
5755 | 1779 |
] |
1780 |
! |
|
1781 |
||
1782 |
broadcast:aSelectorSymbol with:anArgument |
|
1783 |
"send a message with selector aSelectorSymbol with an additional |
|
1784 |
argument anArgument to all my dependents." |
|
1785 |
||
10460 | 1786 |
self dependentsDo:[:dependent | |
14975 | 1787 |
dependent perform:aSelectorSymbol with:anArgument |
5755 | 1788 |
] |
1789 |
! |
|
1790 |
||
1791 |
changeRequest |
|
1792 |
"the receiver wants to change - check if all dependents |
|
1793 |
grant the request, and return true if so" |
|
1794 |
||
10460 | 1795 |
self dependentsDo:[:dependent | |
14975 | 1796 |
dependent updateRequest ifFalse:[^ false]. |
5755 | 1797 |
]. |
1798 |
^ true |
|
1799 |
! |
|
1800 |
||
11551 | 1801 |
changeRequest:aSymbol |
5755 | 1802 |
"the receiver wants to change - check if all dependents |
1803 |
grant the request, and return true if so" |
|
1804 |
||
10460 | 1805 |
self dependentsDo:[:dependent | |
14975 | 1806 |
(dependent updateRequest:aSymbol) ifFalse:[^ false]. |
5755 | 1807 |
]. |
1808 |
^ true |
|
1809 |
! |
|
1810 |
||
11551 | 1811 |
changeRequest:aSymbol from:anObject |
1812 |
"the receiver wants to change - check if all dependents |
|
1813 |
except anObject grant the request, and return true if so. |
|
1814 |
The argument anObject is typically going to be the one who is |
|
1815 |
about to send the change request." |
|
1816 |
||
1817 |
^ self changeRequest:aSymbol with:nil from:anObject |
|
1818 |
! |
|
1819 |
||
1820 |
changeRequest:aSymbol with:aParameter |
|
1821 |
"the receiver wants to change - check if all dependents |
|
1822 |
grant the request, and return true if so" |
|
1823 |
||
11573 | 1824 |
^ self changeRequest:aSymbol with:aParameter from:self |
11551 | 1825 |
! |
1826 |
||
1827 |
changeRequest:aSymbol with:aParameter from:anObject |
|
5755 | 1828 |
"the receiver wants to change - check if all dependents |
1829 |
except anObject grant the request, and return true if so. |
|
1830 |
The argument anObject is typically going to be the one who is |
|
1831 |
about to send the change request." |
|
1832 |
||
10460 | 1833 |
self dependentsDo:[:dependent | |
14975 | 1834 |
dependent == anObject ifFalse:[ |
1835 |
(dependent updateRequest:aSymbol with:aParameter from:anObject) ifFalse:[^ false]. |
|
1836 |
] |
|
5755 | 1837 |
]. |
1838 |
^ true |
|
1839 |
! |
|
1840 |
||
1841 |
changeRequestFrom:anObject |
|
1842 |
"the receiver wants to change - check if all dependents |
|
1843 |
except anObject grant the request, and return true if so. |
|
1844 |
The argument anObject is typically going to be the one who is |
|
1845 |
about to send the change request." |
|
1846 |
||
10460 | 1847 |
self dependentsDo:[:dependent | |
14975 | 1848 |
dependent == anObject ifFalse:[ |
1849 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1850 |
] |
|
5755 | 1851 |
]. |
1852 |
^ true |
|
1853 |
! |
|
1854 |
||
1855 |
changed |
|
1856 |
"notify all dependents that the receiver has changed. |
|
1857 |
Each dependent gets a '#update:'-message with the original |
|
1858 |
receiver as argument." |
|
1859 |
||
1860 |
self changed:nil |
|
1861 |
! |
|
1862 |
||
1863 |
changed:aParameter |
|
1864 |
"notify all dependents that the receiver has changed somehow. |
|
1865 |
Each dependent gets a '#update:'-message with aParameter |
|
1866 |
as argument." |
|
1867 |
||
1868 |
self changed:aParameter with:nil |
|
1869 |
! |
|
1870 |
||
1871 |
changed:aParameter with:anArgument |
|
1872 |
"notify all dependents that the receiver has changed somehow. |
|
1873 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
|
1874 |
and anArgument as arguments." |
|
1875 |
||
10460 | 1876 |
self dependentsDo:[:dependent | |
14975 | 1877 |
dependent update:aParameter with:anArgument from:self |
5755 | 1878 |
] |
1879 |
! |
|
1880 |
||
1881 |
update:aParameter |
|
1882 |
"the message is sent to a dependent, when one of the objects |
|
1883 |
on whom the receiver depends, has changed. The argument aParameter |
|
1884 |
is either the changed object or the argument to the #changed: message. |
|
1885 |
||
1886 |
Default behavior here is to do nothing" |
|
1887 |
||
1888 |
^ self |
|
1889 |
! |
|
1890 |
||
1891 |
update:aParameter with:anArgument |
|
1892 |
"dependent is notified of some change - |
|
1893 |
Default is to try update:" |
|
1894 |
||
1895 |
^ self update:aParameter |
|
1896 |
! |
|
1897 |
||
1898 |
update:aParameter with:anArgument from:sender |
|
1899 |
"dependent is notified of some change - |
|
1900 |
Default is to try update:with:" |
|
1901 |
||
1902 |
^ self update:aParameter with:anArgument |
|
1903 |
! |
|
1904 |
||
1905 |
updateRequest |
|
1906 |
"return true, if an update request is granted. |
|
1907 |
Default here is to grant updates - may be used |
|
1908 |
to lock updates if someone is making other changes |
|
1909 |
from within an update. Or if someone has locked its |
|
1910 |
state and does not want others to change things. |
|
1911 |
However, these dependents must all honor the |
|
1912 |
changeRequest - ifTrue - change protocol. I.e. they |
|
1913 |
must first ask all others via changeRequest, and only do the change |
|
1914 |
it returns true. The others must decide in updateRequest and |
|
1915 |
return true if they think a change is ok." |
|
1916 |
||
1917 |
^ true |
|
1918 |
! |
|
1919 |
||
1920 |
updateRequest:aSymbol |
|
1921 |
"return true, if an update request is granted. |
|
1922 |
Default here a simple updateRequest" |
|
1923 |
||
1924 |
^ self updateRequest |
|
7177 | 1925 |
! |
1926 |
||
11551 | 1927 |
updateRequest:aSymbol with:aParameter |
1928 |
"return true, if an update request is granted. |
|
1929 |
Default here a simple updateRequest" |
|
1930 |
||
1931 |
^ self updateRequest:aSymbol |
|
1932 |
! |
|
1933 |
||
1934 |
updateRequest:aSymbol with:aParameter from:sender |
|
1935 |
"return true, if an update request is granted. |
|
1936 |
Default here a simple updateRequest" |
|
1937 |
||
1938 |
^ self updateRequest:aSymbol with:aParameter |
|
1939 |
! |
|
1940 |
||
7177 | 1941 |
withoutUpdating:someone do:aBlock |
1942 |
"evaluate a block but remove someone from my dependents temporarily" |
|
1943 |
||
1944 |
(self dependents includesIdentical:someone) |
|
1945 |
ifFalse:[ |
|
14975 | 1946 |
^ aBlock value. |
7177 | 1947 |
]. |
1948 |
self removeDependent:someone. |
|
1949 |
^ aBlock ensure:[ self addDependent:someone ] |
|
5755 | 1950 |
! ! |
1951 |
||
1952 |
!Object methodsFor:'cleanup'! |
|
1953 |
||
1954 |
lowSpaceCleanup |
|
1955 |
"ignored here - redefined in some classes to |
|
1956 |
cleanup in low-memory situations" |
|
1957 |
||
1958 |
^ self |
|
1959 |
! ! |
|
1960 |
||
1961 |
!Object methodsFor:'comparing'! |
|
1962 |
||
14975 | 1963 |
= anObject |
1964 |
"return true, if the receiver and the arg have the same structure. |
|
1965 |
Notice: |
|
1966 |
This method is partially open coded (inlined) by the compiler(s) |
|
1967 |
identical objects are always considered equal. |
|
1968 |
redefining it may not work as expected." |
|
1969 |
||
1970 |
^ self == anObject |
|
1971 |
! |
|
1972 |
||
5755 | 1973 |
== anObject |
1974 |
"return true, if the receiver and the arg are the same object. |
|
1975 |
Never redefine this in any class. |
|
1976 |
Notice: |
|
14975 | 1977 |
This method is open coded (inlined) by the compiler(s) |
1978 |
- redefining it may not work as expected." |
|
5755 | 1979 |
|
1980 |
%{ /* NOCONTEXT */ |
|
1981 |
||
1982 |
RETURN ( (self == anObject) ? true : false ); |
|
1983 |
%} |
|
1984 |
! |
|
1985 |
||
5814 | 1986 |
deepSameContentsAs:anObject |
1987 |
"return true, if the receiver and the arg have the same contents |
|
1988 |
in both the named instance vars and any indexed instVars. |
|
1989 |
This method descends into referenced objects, where #sameContentsAs: does not descend" |
|
1990 |
||
5821 | 1991 |
|myClass val |
5814 | 1992 |
sz "{ Class: SmallInteger }" | |
1993 |
||
1994 |
myClass := self class. |
|
1995 |
myClass isVariable ifTrue:[ |
|
14975 | 1996 |
sz := self basicSize. |
1997 |
||
1998 |
"compare the indexed variables" |
|
1999 |
1 to:sz do:[:i | |
|
2000 |
val := self basicAt:i. |
|
2001 |
val isLiteral ifTrue:[ |
|
2002 |
val = (anObject basicAt:i) ifFalse:[^ false]. |
|
2003 |
] ifFalse:[ |
|
2004 |
(val deepSameContentsAs:(anObject basicAt:i)) ifFalse:[^ false]. |
|
2005 |
] |
|
2006 |
] |
|
5814 | 2007 |
]. |
2008 |
||
2009 |
"compare the instance variables" |
|
2010 |
sz := myClass instSize. |
|
10460 | 2011 |
1 to:sz do:[:i | |
14975 | 2012 |
val := self instVarAt:i. |
2013 |
val isLiteral ifTrue:[ |
|
2014 |
val = (anObject instVarAt:i) ifFalse:[^ false]. |
|
2015 |
] ifFalse:[ |
|
2016 |
(val deepSameContentsAs:(anObject instVarAt:i)) ifFalse:[^ false]. |
|
2017 |
] |
|
5814 | 2018 |
]. |
2019 |
||
2020 |
^ true |
|
2021 |
||
2022 |
" |
|
10460 | 2023 |
#(1 2 3 4) deepSameContentsAs:#[1 2 3 4] asArray |
5814 | 2024 |
(1@2) deepSameContentsAs:(1->2) |
2025 |
" |
|
2026 |
! |
|
2027 |
||
5755 | 2028 |
hash |
2029 |
"return an Integer useful as a hash key for the receiver. |
|
2030 |
This hash should return same values for objects with same |
|
2031 |
contents (i.e. use this to hash on structure)" |
|
2032 |
||
2033 |
^ self identityHash |
|
2034 |
! |
|
2035 |
||
2036 |
identityHash |
|
2037 |
"return an Integer useful as a hash key for the receiver. |
|
2038 |
This hash should return same values for the same object (i.e. use |
|
2039 |
this to hash on identity of objects). |
|
2040 |
||
2041 |
We cannot use the Objects address (as other smalltalks do) since |
|
2042 |
no object-table exists and the hashval must not change when objects |
|
2043 |
are moved by the collector. Therefore we assign each object a unique |
|
2044 |
Id in the object header itself as its hashed upon. |
|
2045 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
2046 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
2047 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
2048 |
hashed-upon objects could add an instvar containing the hash value." |
|
2049 |
||
2050 |
%{ /* NOCONTEXT */ |
|
2051 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2052 |
REGISTER unsigned INT hash; |
5755 | 2053 |
static unsigned nextHash = 0; |
2054 |
||
2055 |
if (__isNonNilObject(self)) { |
|
14975 | 2056 |
hash = __GET_HASH(self); |
2057 |
if (hash == 0) { |
|
2058 |
/* has no hash yet */ |
|
2059 |
||
2060 |
if (++nextHash > __MAX_HASH__) { |
|
2061 |
nextHash = 1; |
|
2062 |
} |
|
2063 |
hash = nextHash; |
|
2064 |
__SET_HASH(self, hash); |
|
2065 |
} |
|
2066 |
||
2067 |
/* |
|
2068 |
* now, we got 11 bits for hashing; |
|
2069 |
* make it as large as possible; since most hashers use the returned |
|
2070 |
* key and take it modulo some prime number, this will allow for |
|
2071 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2072 |
*/ |
|
2073 |
hash = __MAKE_HASH__(hash); |
|
2074 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 2075 |
} |
2076 |
%}. |
|
2077 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
2078 |
! |
|
2079 |
||
2080 |
identityHashForBinaryStore |
|
2081 |
"hash which is usable if the object does not change its class |
|
2082 |
and does not #become something else, while the hash is used. |
|
2083 |
This is only used by the binary storage mechanism, during the |
|
2084 |
object writing phase." |
|
2085 |
||
2086 |
%{ /* NOCONTEXT */ |
|
2087 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2088 |
REGISTER unsigned INT hash, hash1, hash2, sz; |
5755 | 2089 |
OBJ o; |
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2090 |
static unsigned INT nextHash = 0; |
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2091 |
static unsigned INT nextClassHash = 0; |
5755 | 2092 |
|
2093 |
if (__isNonNilObject(self)) { |
|
14975 | 2094 |
/* |
2095 |
* my own identityHash |
|
2096 |
*/ |
|
2097 |
hash1 = __GET_HASH(self); |
|
2098 |
if (hash1 == 0) { |
|
2099 |
/* has no hash yet */ |
|
2100 |
||
2101 |
if (++nextHash > __MAX_HASH__) { |
|
2102 |
nextHash = 1; |
|
2103 |
} |
|
2104 |
hash1 = nextHash; |
|
2105 |
__SET_HASH(self, hash1); |
|
2106 |
} |
|
2107 |
/* |
|
2108 |
* my classes identityHash |
|
2109 |
*/ |
|
2110 |
o = __qClass(self); |
|
2111 |
hash2 = __GET_HASH(o); |
|
2112 |
if (hash2 == 0) { |
|
2113 |
/* has no hash yet */ |
|
2114 |
||
2115 |
if (++nextClassHash > __MAX_HASH__) { |
|
2116 |
nextClassHash = 1; |
|
2117 |
} |
|
2118 |
hash2 = nextClassHash; |
|
2119 |
__SET_HASH(o, hash2); |
|
2120 |
} |
|
2121 |
||
2122 |
/* |
|
2123 |
* some bits of my size |
|
2124 |
*/ |
|
2125 |
sz = __qSize(self); |
|
2126 |
||
2127 |
/* |
|
2128 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
2129 |
* make it as large as possible; since most hashers use the returned |
|
2130 |
* key and take it modulo some prime number, this will allow for |
|
2131 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2132 |
*/ |
|
2133 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
2134 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
2135 |
||
2136 |
while ((hash & 0x20000000) == 0) { |
|
2137 |
hash <<= 1; |
|
2138 |
} |
|
2139 |
||
2140 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 2141 |
} |
2142 |
%}. |
|
2143 |
"never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
|
2144 |
^ self identityHash |
|
2145 |
! |
|
2146 |
||
2147 |
sameContentsAs:anObject |
|
2148 |
"return true, if the receiver and the arg have the same contents |
|
7121 | 2149 |
in both the named instance vars and any indexed instVars. |
2150 |
The code here only checks if values present in the receiver are also |
|
2151 |
present in the arg, not vice versa. |
|
2152 |
I.e. the argument may be bigger and/or have more instance variables." |
|
5755 | 2153 |
|
5821 | 2154 |
|myClass |
5755 | 2155 |
sz "{ Class: SmallInteger }" | |
2156 |
||
2157 |
myClass := self class. |
|
2158 |
myClass isVariable ifTrue:[ |
|
14975 | 2159 |
sz := self basicSize. |
2160 |
anObject basicSize >= sz ifFalse:[^ false]. |
|
2161 |
||
2162 |
"compare the indexed variables" |
|
2163 |
1 to:sz do:[:i | |
|
2164 |
(self basicAt:i) == (anObject basicAt:i) ifFalse:[^ false]. |
|
2165 |
] |
|
5755 | 2166 |
]. |
2167 |
||
2168 |
"compare the instance variables" |
|
2169 |
sz := myClass instSize. |
|
12997 | 2170 |
anObject class instSize >= sz ifFalse:[^ false]. |
7121 | 2171 |
|
10460 | 2172 |
1 to:sz do:[:i | |
14975 | 2173 |
(self instVarAt:i) == (anObject instVarAt:i) ifFalse:[^ false]. |
5755 | 2174 |
]. |
2175 |
||
2176 |
^ true |
|
2177 |
||
2178 |
" |
|
10460 | 2179 |
#(1 2 3 4) sameContentsAs:#[1 2 3 4] asArray |
5814 | 2180 |
(1@2) sameContentsAs:(1->2) |
5755 | 2181 |
" |
2182 |
||
12997 | 2183 |
"Created: / 21-04-1998 / 15:56:40 / cg" |
2184 |
"Modified: / 05-08-2010 / 16:44:09 / sr" |
|
5755 | 2185 |
! |
2186 |
||
2187 |
~= anObject |
|
2188 |
"return true, if the receiver and the arg do not have the same structure. |
|
2189 |
Notice: |
|
14975 | 2190 |
This method is partially open coded (inlined) by the compiler(s) |
2191 |
identical objects are never considered unequal. |
|
2192 |
redefining it may not work as expected." |
|
5755 | 2193 |
|
2194 |
^ (self = anObject) not |
|
2195 |
! |
|
2196 |
||
2197 |
~~ anObject |
|
2198 |
"return true, if the receiver and the arg are not the same object. |
|
2199 |
Never redefine this in any class. |
|
2200 |
Notice: |
|
14975 | 2201 |
This method is open coded (inlined) by the compiler(s) |
2202 |
- redefining it may not work as expected." |
|
5755 | 2203 |
|
2204 |
%{ /* NOCONTEXT */ |
|
2205 |
RETURN ( (self == anObject) ? false : true ); |
|
2206 |
%} |
|
2207 |
! ! |
|
2208 |
||
2209 |
!Object methodsFor:'converting'! |
|
2210 |
||
2211 |
-> anObject |
|
2212 |
"return an association with the receiver as key and |
|
2213 |
the argument as value" |
|
2214 |
||
2215 |
^ Association key:self value:anObject |
|
2216 |
! |
|
2217 |
||
10062 | 2218 |
as:aSimilarClass |
2219 |
"If the receivers class is not aSimilarClass, |
|
10460 | 2220 |
create and return an object of class aSimilarClass that has the same contents |
10062 | 2221 |
as the receiver. |
2222 |
Otherwise, return the receiver." |
|
2223 |
||
2224 |
self class == aSimilarClass ifTrue:[^ self]. |
|
2225 |
^ aSimilarClass newFrom:self |
|
2226 |
||
2227 |
" |
|
2228 |
#[1 2 3 4] as:ByteArray |
|
2229 |
#[1 2 3 4] as:Array |
|
10539 | 2230 |
#[81 82 83 84] as:String |
2231 |
#[81 82 83 84] as:Symbol |
|
10062 | 2232 |
" |
2233 |
! |
|
2234 |
||
5755 | 2235 |
asCollection |
2236 |
"return myself as a Collection. |
|
2237 |
Redefined in collection to return themself." |
|
2238 |
||
2239 |
^ Array with:self |
|
2240 |
! |
|
2241 |
||
2242 |
asSequenceableCollection |
|
2243 |
"return myself as a SequenceableCollection. |
|
2244 |
Redefined in SequenceableCollection" |
|
2245 |
||
2246 |
^ Array with:self |
|
2247 |
! |
|
2248 |
||
14355 | 2249 |
asString |
2250 |
^ self printString |
|
2251 |
! |
|
2252 |
||
5755 | 2253 |
asValue |
2254 |
"return a valueHolder for for the receiver" |
|
2255 |
||
2256 |
^ ValueHolder with:self |
|
2257 |
! ! |
|
2258 |
||
2259 |
!Object methodsFor:'copying'! |
|
2260 |
||
10460 | 2261 |
cloneFrom:anObject |
5755 | 2262 |
"Helper for copy: |
2263 |
copy all instance variables from anObject into the receiver, |
|
2264 |
which should be of the same class as the argument." |
|
2265 |
||
2266 |
self cloneFrom:anObject performing:#yourself |
|
2267 |
||
2268 |
" |
|
2269 |
|x| |
|
2270 |
||
2271 |
x := Array new:3. |
|
2272 |
x cloneFrom:#(1 2 3). |
|
2273 |
" |
|
2274 |
! |
|
2275 |
||
2276 |
cloneFrom:anObject performing:aSymbol |
|
2277 |
"Helper for copy: |
|
8383 | 2278 |
for each instance variable from anObject, send it aSymbol |
5755 | 2279 |
and store the result into the receiver, |
2280 |
which should be of the same class as the argument." |
|
2281 |
||
2282 |
|myClass sz "{ Class: SmallInteger }" t | |
|
2283 |
||
2284 |
myClass := self class. |
|
14532 | 2285 |
|
2286 |
"process the named instance variables" |
|
2287 |
sz := myClass instSize. |
|
2288 |
1 to:sz do:[:i | |
|
14975 | 2289 |
t := anObject instVarAt:i. |
2290 |
aSymbol ~~ #yourself ifTrue:[ |
|
2291 |
t := t perform:aSymbol |
|
2292 |
]. |
|
2293 |
self instVarAt:i put:t |
|
14532 | 2294 |
]. |
2295 |
||
5755 | 2296 |
myClass isVariable ifTrue:[ |
14975 | 2297 |
sz := self basicSize. |
2298 |
||
2299 |
"process the indexed instance variables" |
|
2300 |
1 to:sz do:[:i | |
|
2301 |
t := anObject basicAt:i. |
|
2302 |
aSymbol ~~ #yourself ifTrue:[ |
|
2303 |
t := t perform:aSymbol. |
|
2304 |
]. |
|
2305 |
self basicAt:i put:t. |
|
2306 |
] |
|
5755 | 2307 |
]. |
2308 |
! |
|
2309 |
||
2310 |
cloneInstanceVariablesFrom:aPrototype |
|
2311 |
"Shallow copy variables from a prototype into myself. |
|
2312 |
This copies instVars by name - i.e. same-named variables are |
|
2313 |
copied, others are not. |
|
10460 | 2314 |
The variable slots are copied as available |
5755 | 2315 |
(i.e. the min of both indexed sizes is used)." |
10460 | 2316 |
|
14676 | 2317 |
|myClass prototypesClass myInfo prototypesInfo| |
2318 |
||
2319 |
||
2320 |
myClass := self class. |
|
2321 |
prototypesClass := aPrototype class. |
|
2322 |
(myClass == prototypesClass |
|
2323 |
or:[ myClass isSubclassOf:prototypesClass ]) ifTrue:[ |
|
2324 |
"/ can do better, if my class is a subclass of the prototype's class |
|
2325 |
1 to: prototypesClass instSize do:[:index | |
|
2326 |
self instVarAt:index put:(aPrototype instVarAt:index) |
|
2327 |
] |
|
2328 |
] ifFalse:[ |
|
2329 |
"/ map instvars by name |
|
2330 |
myInfo := myClass instanceVariableOffsets. |
|
2331 |
prototypesInfo := prototypesClass instanceVariableOffsets. |
|
2332 |
myInfo keysAndValuesDo:[:name :index | |varIndexAssoc| |
|
2333 |
varIndexAssoc := prototypesInfo at:name ifAbsent:[]. |
|
2334 |
varIndexAssoc notNil ifTrue:[ |
|
2335 |
self instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
2336 |
] |
|
2337 |
] |
|
2338 |
]. |
|
2339 |
myClass isVariable ifTrue:[ |
|
2340 |
prototypesClass isVariable ifTrue:[ |
|
2341 |
1 to:(self basicSize min:aPrototype basicSize) do:[:index | |
|
2342 |
self basicAt:index put:(aPrototype basicAt:index) |
|
2343 |
]. |
|
2344 |
]. |
|
5755 | 2345 |
]. |
2346 |
||
2347 |
" |
|
2348 |
Class withoutUpdatingChangesDo:[ |
|
14676 | 2349 |
|point3D| |
2350 |
||
2351 |
point3D := Point subclass:#Point3D |
|
2352 |
instanceVariableNames:'z' |
|
2353 |
classVariableNames:'' |
|
2354 |
poolDictionaries:'' |
|
2355 |
category:'testing' |
|
2356 |
inEnvironment:nil. |
|
2357 |
(point3D new cloneInstanceVariablesFrom:1@2) inspect. |
|
5755 | 2358 |
] |
2359 |
" |
|
2360 |
||
2361 |
" |
|
2362 |
Class withoutUpdatingChangesDo:[ |
|
14676 | 2363 |
Point variableSubclass:#Point3D_test |
2364 |
instanceVariableNames:'z' |
|
2365 |
classVariableNames:'' |
|
2366 |
poolDictionaries:'' |
|
2367 |
category:'testing'. |
|
2368 |
(((Smalltalk at:#Point3D_test) new:2) cloneInstanceVariablesFrom:#(1 2 3)) inspect. |
|
5755 | 2369 |
] |
2370 |
" |
|
2371 |
||
2372 |
" |
|
2373 |
|someObject| |
|
2374 |
||
2375 |
Class withoutUpdatingChangesDo:[ |
|
14676 | 2376 |
Object subclass:#TestClass1 |
2377 |
instanceVariableNames:'foo bar' |
|
2378 |
classVariableNames:'' |
|
2379 |
poolDictionaries:'' |
|
2380 |
category:'testing'. |
|
2381 |
someObject := TestClass1 new. |
|
2382 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
2383 |
Object subclass:#TestClass2 |
|
2384 |
instanceVariableNames:'bar foo' |
|
2385 |
classVariableNames:'' |
|
2386 |
poolDictionaries:'' |
|
2387 |
category:'testing'. |
|
2388 |
(TestClass2 new cloneInstanceVariablesFrom:someObject) inspect. |
|
5755 | 2389 |
] |
2390 |
" |
|
2391 |
||
2392 |
" |
|
2393 |
|top b b1| |
|
2394 |
||
2395 |
top := StandardSystemView new. |
|
2396 |
top extent:100@100. |
|
2397 |
||
2398 |
b := Button in:top. |
|
2399 |
b label:'hello'. |
|
2400 |
||
2401 |
b1 := ArrowButton new cloneInstanceVariablesFrom:b. |
|
2402 |
||
2403 |
top open. |
|
2404 |
b1 inspect |
|
2405 |
" |
|
2406 |
! |
|
2407 |
||
2408 |
copy |
|
2409 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
2410 |
Notice, that copy does not copy dependents." |
|
2411 |
||
2412 |
^ self shallowCopy postCopy |
|
2413 |
! |
|
2414 |
||
6146 | 2415 |
copyToLevel:level |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2416 |
"a controlled deepCopy, where the number of levels can be specified. |
10460 | 2417 |
Notice: |
14975 | 2418 |
This method DOES NOT handle cycles/self-refs and does NOT preserve object identity; |
2419 |
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
|
2420 |
|
14534 | 2421 |
|newObject newLevel class sz "{Class: SmallInteger}" newInst| |
2422 |
||
2423 |
newObject := self copy. |
|
2424 |
newObject == self ifTrue: [^ self]. "copy of nil, true, false, ... is self" |
|
2425 |
level == 1 ifTrue:[^ newObject]. |
|
2426 |
newLevel := level - 1. |
|
2427 |
||
2428 |
class := newObject class. |
|
2429 |
||
2430 |
"process the named instance variables" |
|
2431 |
sz := class instSize. |
|
2432 |
1 to:sz do:[:i | |
|
14975 | 2433 |
newInst := newObject instVarAt:i. |
2434 |
newInst notNil ifTrue:[ |
|
2435 |
newObject instVarAt:i put:(newInst copyToLevel:newLevel). |
|
2436 |
]. |
|
14534 | 2437 |
]. |
2438 |
||
10460 | 2439 |
class isVariable ifTrue:[ |
14975 | 2440 |
sz := newObject basicSize. |
2441 |
||
2442 |
"process the indexed instance variables" |
|
2443 |
1 to:sz do:[:i | |
|
2444 |
newInst := newObject basicAt:i. |
|
2445 |
newInst notNil ifTrue:[ |
|
2446 |
newObject basicAt:i put:(newInst copyToLevel:newLevel). |
|
2447 |
]. |
|
2448 |
] |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2449 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2450 |
^ newObject |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2451 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2452 |
" |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2453 |
|a b| |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2454 |
|
10460 | 2455 |
a := #( |
14975 | 2456 |
'1.1' |
2457 |
'1.2' |
|
2458 |
'1.3' |
|
2459 |
( |
|
2460 |
'1.41' |
|
2461 |
'1.42' |
|
2462 |
'1.43' |
|
2463 |
( |
|
2464 |
'1.441' |
|
2465 |
'1.442' |
|
2466 |
'1.443' |
|
2467 |
( '1.4441' '1.4442' '1.4443' ) |
|
2468 |
'1.445' |
|
2469 |
) |
|
2470 |
'1.45' |
|
2471 |
) |
|
2472 |
'1.5' |
|
2473 |
). |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2474 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2475 |
b := a copyToLevel:1. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2476 |
self assert: ( (a at:1) == (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2477 |
self assert: ( (a at:4) == (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2478 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2479 |
b := a copyToLevel:2. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2480 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2481 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2482 |
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
|
2483 |
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
|
2484 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2485 |
b := a copyToLevel:3. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2486 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2487 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2488 |
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
|
2489 |
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
|
2490 |
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
|
2491 |
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
|
2492 |
" |
6146 | 2493 |
! |
2494 |
||
5755 | 2495 |
deepCopy |
2496 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2497 |
This method DOES handle cycles/self-refs and preserves object identity; |
5755 | 2498 |
however the receivers class is not copied (to avoid the 'total' copy). |
2499 |
||
2500 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
2501 |
keeps track of already copied objects. If you are sure, that your |
|
2502 |
copied object does not include duplicates (or you do not care) and |
|
10460 | 2503 |
no cycles are involved, you can use the old simpleDeepCopy, |
5755 | 2504 |
which avoids this overhead (but may run into trouble). |
2505 |
Notice, that deepCopy does not copy dependents." |
|
2506 |
||
8383 | 2507 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 2508 |
|
2509 |
"an example which is not handled by the old deepCopy: |
|
10460 | 2510 |
|
5755 | 2511 |
|a| |
2512 |
a := Array new:3. |
|
2513 |
a at:3 put:a. |
|
2514 |
a deepCopy inspect |
|
2515 |
" |
|
2516 |
||
2517 |
" |
|
2518 |
|a| |
|
2519 |
a := Color black onDevice:Screen current. |
|
2520 |
a deepCopy inspect |
|
2521 |
" |
|
2522 |
||
2523 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
2524 |
! |
|
2525 |
||
2526 |
deepCopyError |
|
2527 |
"{ Pragma: +optSpace }" |
|
2528 |
||
2529 |
"raise a signal, that deepCopy is not allowed for this object" |
|
2530 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
2531 |
^ DeepCopyError raise |
5755 | 2532 |
! |
2533 |
||
2534 |
deepCopyUsing:aDictionary |
|
10460 | 2535 |
"a helper for deepCopy; return a copy of the object with |
2536 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
5755 | 2537 |
use the value found there. The class of the receiver is not copied. |
2538 |
This method DOES handle cycles/self references." |
|
2539 |
||
10941 | 2540 |
^ self deepCopyUsing:aDictionary postCopySelector:#postDeepCopyFrom:. |
2541 |
||
5755 | 2542 |
|
2543 |
" |
|
2544 |
|a b c copyOfC| |
|
2545 |
||
2546 |
a := Array with:'hello' with:'world' with:nil. |
|
2547 |
b := 99 @ 999. |
|
2548 |
a at:3 put:b. |
|
2549 |
c := Array with:a with:b with:a. |
|
2550 |
||
2551 |
Transcript showCR: (c at:1) == (c at:3). |
|
2552 |
copyOfC := c deepCopy. |
|
2553 |
Transcript showCR: (copyOfC at:1) == (copyOfC at:3) |
|
2554 |
" |
|
2555 |
! |
|
2556 |
||
10954 | 2557 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
11335 | 2558 |
"a helper for deepCopy; return a copy of the object with |
2559 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
10954 | 2560 |
use the value found there. The class of the receiver is not copied. |
2561 |
This method DOES handle cycles/self references." |
|
2562 |
||
2563 |
|myClass aCopy |
|
14527 | 2564 |
basicSize "{ Class: SmallInteger }" |
2565 |
instSize "{ Class: SmallInteger }" |
|
10954 | 2566 |
iOrig iCopy| |
2567 |
||
2568 |
myClass := self class. |
|
2569 |
myClass isVariable ifTrue:[ |
|
14975 | 2570 |
basicSize := self basicSize. |
2571 |
aCopy := myClass basicNew:basicSize. |
|
10954 | 2572 |
] ifFalse:[ |
14975 | 2573 |
basicSize := 0. |
2574 |
aCopy := myClass basicNew |
|
10954 | 2575 |
]. |
2576 |
aCopy setHashFrom:self. |
|
2577 |
aDictionary at:self put:aCopy. |
|
2578 |
||
2579 |
" |
|
14527 | 2580 |
copy the instance variables |
2581 |
" |
|
2582 |
instSize := myClass instSize. |
|
2583 |
1 to:instSize do:[:i | |
|
14975 | 2584 |
(self skipInstvarIndexInDeepCopy:i) ifFalse:[ |
2585 |
iOrig := self instVarAt:i. |
|
2586 |
iOrig notNil ifTrue:[ |
|
2587 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2588 |
iCopy isNil ifTrue:[ |
|
2589 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2590 |
]. |
|
2591 |
aCopy instVarAt:i put:iCopy |
|
2592 |
] |
|
2593 |
] |
|
14527 | 2594 |
]. |
2595 |
||
2596 |
" |
|
10954 | 2597 |
copy indexed instvars - if any |
2598 |
" |
|
14527 | 2599 |
basicSize ~~ 0 ifTrue:[ |
14975 | 2600 |
myClass isBits ifTrue:[ |
2601 |
"block-copy indexed instvars" |
|
2602 |
aCopy replaceFrom:1 to:basicSize with:self startingAt:1 |
|
2603 |
] ifFalse:[ |
|
2604 |
"individual deep copy the indexed variables" |
|
2605 |
1 to:basicSize do:[:i | |
|
2606 |
iOrig := self basicAt:i. |
|
2607 |
iOrig notNil ifTrue:[ |
|
2608 |
"/ used to be dict-includesKey-ifTrue[dict-at:], |
|
2609 |
"/ changed to use dict-at:ifAbsent:, to avoid double lookup in dictionary |
|
2610 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2611 |
iCopy isNil ifTrue:[ |
|
2612 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2613 |
]. |
|
2614 |
aCopy basicAt:i put:iCopy |
|
2615 |
] |
|
2616 |
] |
|
2617 |
] |
|
10954 | 2618 |
]. |
2619 |
||
13515
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2620 |
aCopy perform:postCopySelector withOptionalArgument:self and:aDictionary. |
10954 | 2621 |
^ aCopy |
13515
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2622 |
|
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2623 |
"Modified: / 21-07-2011 / 13:30:52 / cg" |
10954 | 2624 |
! |
2625 |
||
5755 | 2626 |
postCopy |
2627 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
2628 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
2629 |
(see there)" |
|
2630 |
||
2631 |
^ self |
|
2632 |
! |
|
2633 |
||
2634 |
postDeepCopy |
|
8930
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2635 |
"allows for cleanup after deep copying. |
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2636 |
To be redefined in subclasses." |
5755 | 2637 |
! |
2638 |
||
2639 |
postDeepCopyFrom:aSource |
|
2640 |
"allows for cleanup after deep copying" |
|
2641 |
||
2642 |
^ self postDeepCopy |
|
2643 |
! |
|
2644 |
||
2645 |
setHashFrom:anObject |
|
10460 | 2646 |
"set my identity-hash key to be the same as anObjects hash key. |
2647 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
5755 | 2648 |
Smalltalks, and may not be available in future ST/X versions. |
2649 |
DO NEVER use this for normal application code." |
|
2650 |
||
2651 |
%{ /* NOCONTEXT */ |
|
2652 |
||
2653 |
REGISTER unsigned h; |
|
2654 |
||
2655 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
14975 | 2656 |
h = __GET_HASH(anObject); |
2657 |
__SET_HASH(self, h); |
|
2658 |
RETURN (self); |
|
5755 | 2659 |
} |
2660 |
%}. |
|
2661 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
2662 |
! |
|
2663 |
||
2664 |
shallowCopy |
|
2665 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2666 |
i.e. the copy shares referenced instvars with its original." |
|
2667 |
||
2668 |
%{ /* NOCONTEXT */ |
|
2669 |
int ninsts, spc; |
|
2670 |
int sz; |
|
2671 |
OBJ theCopy; |
|
2672 |
OBJ cls; |
|
2673 |
int flags; |
|
2674 |
||
2675 |
cls = __qClass(self); |
|
2676 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
2677 |
||
2678 |
/* |
|
2679 |
* bail out for special objects .. |
|
2680 |
*/ |
|
2681 |
if (((flags & ~ARRAYMASK) == 0) |
|
2682 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
14975 | 2683 |
sz = __qSize(self); |
2684 |
__PROTECT__(self); |
|
2685 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
2686 |
__UNPROTECT__(self); |
|
2687 |
if (theCopy) { |
|
2688 |
cls = __qClass(self); |
|
2689 |
spc = __qSpace(theCopy); |
|
2690 |
||
2691 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
2692 |
||
2693 |
sz = sz - OHDR_SIZE; |
|
2694 |
if (sz) { |
|
2695 |
char *src, *dst; |
|
2696 |
||
2697 |
src = (char *)(__InstPtr(self)->i_instvars); |
|
2698 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
5755 | 2699 |
#ifdef bcopy4 |
14975 | 2700 |
{ |
2701 |
/* care for odd-number of longs */ |
|
2702 |
int nW = sz >> 2; |
|
2703 |
||
2704 |
if (sz & 3) { |
|
2705 |
nW++; |
|
2706 |
} |
|
2707 |
||
2708 |
bcopy4(src, dst, nW); |
|
2709 |
} |
|
5755 | 2710 |
#else |
14975 | 2711 |
bcopy(src, dst, sz); |
5755 | 2712 |
#endif |
2713 |
||
14975 | 2714 |
flags &= ARRAYMASK; |
2715 |
if (flags == POINTERARRAY) { |
|
2716 |
ninsts = __BYTES2OBJS__(sz); |
|
2717 |
} else { |
|
2718 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
2719 |
} |
|
2720 |
if (ninsts) { |
|
2721 |
do { |
|
2722 |
OBJ el; |
|
2723 |
||
2724 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
2725 |
__STORE_SPC(theCopy, el, spc); |
|
2726 |
} while (--ninsts); |
|
2727 |
} |
|
2728 |
} |
|
2729 |
RETURN (theCopy); |
|
2730 |
} |
|
5755 | 2731 |
} |
2732 |
%}. |
|
2733 |
"/ fallBack for special objects & memoryAllocation failure case |
|
2734 |
||
2735 |
^ self slowShallowCopy |
|
2736 |
! |
|
2737 |
||
2738 |
simpleDeepCopy |
|
2739 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2740 |
This method does NOT handle cycles - but is included to allow this |
5755 | 2741 |
slightly faster copy in situations where it is known that |
2742 |
no recursive references occur (LargeIntegers for example). |
|
2743 |
NOTICE: you will run into trouble, when trying this with recursive |
|
2744 |
objects (usually recursionInterrupt or memory-alert). |
|
8383 | 2745 |
This method corresponds to the 'traditional' deepCopy found in the Blue book." |
5755 | 2746 |
|
2747 |
|myClass aCopy| |
|
2748 |
||
2749 |
(myClass := self class) isVariable ifTrue:[ |
|
14975 | 2750 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2751 |
] ifFalse:[ |
14975 | 2752 |
aCopy := myClass basicNew |
5755 | 2753 |
]. |
2754 |
||
2755 |
"copy the instance variables" |
|
2756 |
aCopy cloneFrom:self performing:#simpleDeepCopy. |
|
2757 |
^ aCopy |
|
2758 |
||
2759 |
"a bad example (but ST/X should survive ...)" |
|
2760 |
" |
|
2761 |
|a| |
|
2762 |
a := Array new:3. |
|
2763 |
a at:3 put:a. |
|
2764 |
a simpleDeepCopy |
|
2765 |
" |
|
2766 |
! |
|
2767 |
||
2768 |
skipInstvarIndexInDeepCopy:index |
|
2769 |
"a helper for deepCopy; only indices for which this method returns |
|
2770 |
false are copied in a deep copy. |
|
2771 |
The default is false here - which means that everything is copied. |
|
2772 |
Can be redefined in subclasses for partial copies" |
|
2773 |
||
2774 |
^ false |
|
2775 |
! |
|
2776 |
||
2777 |
slowShallowCopy |
|
2778 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2779 |
i.e. the copy shares referenced instvars with its original. |
|
2780 |
This method is only invoked as a fallback from #shallowCopy." |
|
2781 |
||
2782 |
|myClass aCopy| |
|
2783 |
||
2784 |
(myClass := self class) isVariable ifTrue:[ |
|
14975 | 2785 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2786 |
] ifFalse:[ |
14975 | 2787 |
aCopy := myClass basicNew |
5755 | 2788 |
]. |
2789 |
||
2790 |
"copy the instance variables" |
|
2791 |
aCopy cloneFrom:self performing:#yourself. |
|
2792 |
^ aCopy |
|
2793 |
! ! |
|
2794 |
||
2795 |
!Object methodsFor:'debugging'! |
|
2796 |
||
7621 | 2797 |
assert:aBooleanOrBlock |
13800 | 2798 |
"fail and report an error, if the argument does not evaluate to true" |
6964 | 2799 |
|
11662 | 2800 |
"{ Pragma: +optSpace }" |
2801 |
||
11021 | 2802 |
<resource: #skipInDebuggersWalkBack> |
2803 |
||
8876 | 2804 |
aBooleanOrBlock == true ifTrue:[^ self]. |
11141
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2805 |
(Smalltalk at:#IgnoreAssertion ifAbsent:false) == true ifTrue:[^ self]. |
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2806 |
|
8876 | 2807 |
"/ could still be a block or false. |
11662 | 2808 |
(aBooleanOrBlock value) ifFalse:[ |
14975 | 2809 |
AssertionFailedError |
2810 |
raiseRequestWith:self |
|
2811 |
errorString:('Assertion failed in ', |
|
15219 | 2812 |
thisContext methodHome sender printString, |
2813 |
'[', thisContext methodHome sender lineNumber printString,']') |
|
11662 | 2814 |
]. |
2815 |
||
2816 |
" |
|
2817 |
self assert:false |
|
2818 |
" |
|
13039 | 2819 |
|
2820 |
"Modified: / 20-08-2010 / 17:13:06 / cg" |
|
7621 | 2821 |
! |
2822 |
||
2823 |
assert:aBooleanOrBlock message:messageIfFailing |
|
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2824 |
"fail, if the argument does not evaluate to true and report an error" |
6961 | 2825 |
|
2826 |
"{ Pragma: +optSpace }" |
|
2827 |
||
11021 | 2828 |
<resource: #skipInDebuggersWalkBack> |
2829 |
||
11141
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2830 |
aBooleanOrBlock == true ifTrue:[^ self]. |
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2831 |
(Smalltalk at:#IgnoreAssertion ifAbsent:false) == true ifTrue:[^ self]. |
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2832 |
|
7621 | 2833 |
(aBooleanOrBlock value) ifFalse:[ |
14975 | 2834 |
AssertionFailedError |
2835 |
raiseRequestWith:self |
|
15219 | 2836 |
errorString:(messageIfFailing, ' {',thisContext methodHome sender "methodHome" printString,' }') |
11662 | 2837 |
]. |
2838 |
||
2839 |
" |
|
2840 |
self assert:false message:'xxx' |
|
10651 | 2841 |
" |
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2842 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2843 |
"Modified (comment): / 06-03-2012 / 11:26:48 / cg" |
6961 | 2844 |
! |
2845 |
||
5755 | 2846 |
basicInspect |
2847 |
"{ Pragma: +optSpace }" |
|
2848 |
||
2849 |
"launch an inspector on the receiver. |
|
2850 |
this method should NOT be redefined in subclasses." |
|
2851 |
||
2852 |
Inspector isNil ifTrue:[ |
|
14975 | 2853 |
" |
2854 |
for systems without GUI |
|
2855 |
" |
|
2856 |
self warn:'No Inspector defined (Inspector is nil).' |
|
5755 | 2857 |
] ifFalse:[ |
14975 | 2858 |
Inspector openOn:self |
5755 | 2859 |
] |
2860 |
||
2861 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
2862 |
! |
|
2863 |
||
11025 | 2864 |
breakPoint:someKey |
6954 | 2865 |
"{ Pragma: +optSpace }" |
2866 |
||
2867 |
"Like halt, but disabled by default. |
|
2868 |
Can be easily enabled. |
|
2869 |
Can be filtered on the arguments value (typically: a symbol). |
|
2870 |
Code with breakpoints may be even checked into the source repository" |
|
2871 |
||
2872 |
"Example: nil breakPoint:#stefan" |
|
2873 |
||
11025 | 2874 |
<resource: #skipInDebuggersWalkBack> |
2875 |
||
11048 | 2876 |
"/ dont send #breakPoint:info: here - ask cg why. |
2877 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
14975 | 2878 |
^ HaltSignal |
2879 |
raiseRequestWith:someKey |
|
2880 |
errorString:('Breakpoint encountered: %1' bindWith:someKey) |
|
11048 | 2881 |
]. |
11025 | 2882 |
|
2883 |
" |
|
2884 |
nil breakPoint:#stefan |
|
2885 |
nil breakPoint:#stefan info:'Hello' |
|
2886 |
Smalltalk enableBreakPoint:#stefan. |
|
2887 |
Smalltalk disableBreakPoint:#stefan. |
|
11048 | 2888 |
|
2889 |
EncounteredBreakPoints. |
|
2890 |
Smalltalk enableBreakPoint:#cg. |
|
2891 |
Smalltalk disableBreakPoint:#cg. |
|
11025 | 2892 |
" |
2893 |
! |
|
2894 |
||
2895 |
breakPoint:someKey info:infoString |
|
2896 |
"{ Pragma: +optSpace }" |
|
2897 |
||
2898 |
"Like halt, but disabled by default. |
|
2899 |
Can be easily enabled. |
|
2900 |
Can be filtered on the arguments value (typically: a symbol). |
|
2901 |
Code with breakpoints may be even checked into the source repository" |
|
2902 |
||
2903 |
"Example: nil breakPoint:#stefan" |
|
2904 |
||
2905 |
<resource: #skipInDebuggersWalkBack> |
|
2906 |
||
2907 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
14975 | 2908 |
^ HaltSignal |
2909 |
raiseRequestWith:someKey |
|
2910 |
errorString:(infoString bindWith:someKey) |
|
11025 | 2911 |
]. |
6954 | 2912 |
! |
2913 |
||
5995 | 2914 |
browse |
2915 |
"open a browser on the receivers class" |
|
2916 |
||
2917 |
self class theNonMetaclass browse |
|
2918 |
||
2919 |
" |
|
2920 |
10 browse |
|
2921 |
Collection browse |
|
2922 |
Collection class browse |
|
2923 |
" |
|
2924 |
! |
|
2925 |
||
11244 | 2926 |
debuggingCodeFor:someKey is:aBlock |
2927 |
"{ Pragma: +optSpace }" |
|
2928 |
||
2929 |
"aBlock is evaluated if breakPoints for somekey are enabled. |
|
2930 |
Allows for debugging code to be enabled/disabled via the breakpoint browser. |
|
2931 |
Can be easily enabled. |
|
2932 |
Can be filtered on the arguments value (typically: a symbol). |
|
2933 |
Code with breakpoints may be even checked into the source repository" |
|
2934 |
||
2935 |
"Example: nil debuggingCodeFor:#cg is:[ self halt ]" |
|
2936 |
||
2937 |
<resource: #skipInDebuggersWalkBack> |
|
2938 |
||
2939 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
14975 | 2940 |
aBlock value |
11244 | 2941 |
]. |
2942 |
||
2943 |
" |
|
2944 |
Smalltalk disableBreakPoint:#cg. |
|
12340
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
2945 |
nil debuggingCodeFor:#cg is:[ Transcript showCR:'here is some debug message for cg' ]. |
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
2946 |
nil debuggingCodeFor:#stefan is:[ Transcript showCR:'here is some debug message for sv' ]. |
11244 | 2947 |
Smalltalk enableBreakPoint:#cg. |
12340
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
2948 |
nil debuggingCodeFor:#cg is:[ Transcript showCR:'here is some debug message for cg' ]. |
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
2949 |
nil debuggingCodeFor:#stefan is:[ Transcript showCR:'here is some debug message for sv' ]. |
11244 | 2950 |
Smalltalk disableBreakPoint:#cg. |
2951 |
||
2952 |
" |
|
2953 |
! |
|
2954 |
||
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2955 |
disableAllBreakPoints |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2956 |
"disable all parametrized breakPoints (with any key as parameter)" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2957 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2958 |
EnabledBreakPoints := nil |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2959 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2960 |
" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2961 |
nil enableBreakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2962 |
nil breakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2963 |
nil disableAllBreakPoints. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2964 |
nil breakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2965 |
" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2966 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2967 |
"Created: / 06-03-2012 / 15:32:28 / cg" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2968 |
! |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2969 |
|
11025 | 2970 |
disableBreakPoint:someKey |
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2971 |
"disable parametrized breakPoints with someKey as parameter" |
11025 | 2972 |
|
2973 |
"{ Pragma: +optSpace }" |
|
2974 |
||
2975 |
EnabledBreakPoints notNil ifTrue:[ |
|
14975 | 2976 |
EnabledBreakPoints remove:someKey ifAbsent:[]. |
2977 |
EnabledBreakPoints isEmpty ifTrue:[ |
|
2978 |
EnabledBreakPoints := nil |
|
2979 |
]. |
|
11025 | 2980 |
]. |
2981 |
||
2982 |
" |
|
2983 |
nil enableBreakPoint:#cg. |
|
2984 |
nil breakPoint:#cg. |
|
2985 |
nil disableBreakPoint:#cg |
|
2986 |
nil breakPoint:#cg. |
|
2987 |
" |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2988 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2989 |
"Modified (comment): / 06-03-2012 / 15:31:51 / cg" |
11025 | 2990 |
! |
2991 |
||
2992 |
enableBreakPoint:someKey |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2993 |
"enable parametrized breakPoints with someKey as parameter" |
11025 | 2994 |
|
2995 |
"{ Pragma: +optSpace }" |
|
2996 |
||
2997 |
EnabledBreakPoints isNil ifTrue:[ |
|
14975 | 2998 |
EnabledBreakPoints := Set new. |
11025 | 2999 |
]. |
3000 |
EnabledBreakPoints add:someKey. |
|
3001 |
||
3002 |
" |
|
3003 |
nil enableBreakPoint:#cg. |
|
3004 |
nil breakPoint:#cg. |
|
3005 |
nil disableBreakPoint:#cg |
|
3006 |
nil breakPoint:#cg. |
|
3007 |
" |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3008 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3009 |
"Modified (comment): / 06-03-2012 / 15:31:47 / cg" |
11025 | 3010 |
! |
3011 |
||
11048 | 3012 |
halt |
3013 |
"{ Pragma: +optSpace }" |
|
3014 |
||
3015 |
"enter debugger with halt-message. |
|
3016 |
The error is reported by raising the HaltSignal exception." |
|
3017 |
||
3018 |
<resource: #skipInDebuggersWalkBack> |
|
3019 |
||
13136 | 3020 |
Smalltalk ignoreHalt ifTrue:[^ self]. |
14830 | 3021 |
"/ don't send #halt: here - ask cg why. |
14974 | 3022 |
HaltInterrupt raiseRequestWith:#halt. |
3023 |
^ self |
|
3024 |
||
3025 |
" |
|
3026 |
(3 halt * 5) |
|
3027 |
" |
|
11048 | 3028 |
|
13136 | 3029 |
"Modified: / 02-08-1999 / 17:00:29 / stefan" |
3030 |
"Modified: / 18-11-2010 / 11:21:51 / cg" |
|
11048 | 3031 |
! |
3032 |
||
3033 |
halt:aString |
|
3034 |
"{ Pragma: +optSpace }" |
|
3035 |
||
3036 |
"enter debugger with halt-message. |
|
3037 |
The error is reported by raising the HaltSignal exception." |
|
3038 |
||
3039 |
<resource: #skipInDebuggersWalkBack> |
|
3040 |
||
13136 | 3041 |
Smalltalk ignoreHalt ifTrue:[^ self]. |
14974 | 3042 |
HaltInterrupt raiseRequestWith:#halt: errorString:aString. |
3043 |
^ self |
|
11048 | 3044 |
|
13136 | 3045 |
"Modified: / 18-11-2010 / 11:22:16 / cg" |
11048 | 3046 |
! |
3047 |
||
11025 | 3048 |
isBreakPointEnabled:someKey |
3049 |
"{ Pragma: +optSpace }" |
|
3050 |
||
3051 |
"controls which breakpoints to be enabled." |
|
3052 |
||
3053 |
"/ something = OperatingSystem getLoginName ifTrue:[^ true]. |
|
3054 |
"/ something = 'testThis' ifTrue:[^ true]. |
|
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
3055 |
EncounteredBreakPoints notNil ifTrue:[ |
14975 | 3056 |
EncounteredBreakPoints add:someKey |
11335 | 3057 |
]. |
3058 |
||
3059 |
^ (EnabledBreakPoints notNil and:[ EnabledBreakPoints includes:someKey ]) |
|
11025 | 3060 |
|
3061 |
" |
|
3062 |
nil enableBreakPoint:#cg. |
|
3063 |
nil breakPoint:#cg. |
|
3064 |
nil disableBreakPoint:#cg |
|
3065 |
nil breakPoint:#cg. |
|
11045
85315d8893e4
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11044
diff
changeset
|
3066 |
|
85315d8893e4
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11044
diff
changeset
|
3067 |
EncounteredBreakPoints := Set new. |
11025 | 3068 |
" |
3069 |
! |
|
3070 |
||
5755 | 3071 |
mustBeBoolean |
3072 |
"this message is sent by the VM, if a non-Boolean receiver is encountered |
|
3073 |
in an if* or while* message. |
|
3074 |
Caveat: for now, this is only sent by the interpreter; |
|
3075 |
both the JIT and the stc compiler treat it as undefined." |
|
3076 |
||
11021 | 3077 |
<resource: #skipInDebuggersWalkBack> |
3078 |
||
5755 | 3079 |
self error:'Non boolean receiver - proceed for truth' mayProceed:true. |
3080 |
^ true |
|
3081 |
! |
|
3082 |
||
3083 |
mustBeKindOf:aClass |
|
10460 | 3084 |
"for compatibility & debugging support: |
5755 | 3085 |
check if the receiver isKindOf:aClass and raise an error if not. |
3086 |
Notice: |
|
14975 | 3087 |
it is VERY questionable, if it makes sense to add manual |
3088 |
type checks to a dynamically typed language like smalltalk. |
|
3089 |
It will, at least, slow down performance, |
|
3090 |
make your code less reusable and clutter your code with stupid sends |
|
3091 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
3092 |
use of isXXX check methods. |
|
5755 | 3093 |
You see: The author does not like this at all ..." |
3094 |
||
11021 | 3095 |
<resource: #skipInDebuggersWalkBack> |
3096 |
||
5755 | 3097 |
(self isKindOf:aClass) ifFalse:[ |
14975 | 3098 |
self error:'argument is not of expected type' |
5755 | 3099 |
] |
3100 |
! |
|
3101 |
||
6950 | 3102 |
obsoleteFeatureWarning |
3103 |
"{ Pragma: +optSpace }" |
|
3104 |
||
3105 |
"in methods which are going to be changed, a send to |
|
3106 |
this method is used to tell programmers that some feature/semantics is |
|
3107 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3108 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)." |
6950 | 3109 |
|
3110 |
self obsoleteFeatureWarning:nil from:thisContext sender |
|
3111 |
! |
|
3112 |
||
3113 |
obsoleteFeatureWarning:message |
|
3114 |
"{ Pragma: +optSpace }" |
|
3115 |
||
3116 |
"in methods which are going to be changed, a send to |
|
3117 |
this method is used to tell programmers that some feature/semantics is |
|
3118 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3119 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3120 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3121 |
|
3122 |
self obsoleteFeatureWarning:message from:thisContext sender |
|
3123 |
! |
|
3124 |
||
3125 |
obsoleteFeatureWarning:message from:aContext |
|
3126 |
"{ Pragma: +optSpace }" |
|
3127 |
||
3128 |
"in methods which are going to be changed, a send to |
|
3129 |
this method is used to tell programmers that some feature/semantics is |
|
3130 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3131 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3132 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3133 |
|
11527 | 3134 |
|spec sender| |
6950 | 3135 |
|
3136 |
spec := aContext methodPrintString. |
|
11527 | 3137 |
sender := aContext sender. |
3138 |
||
6950 | 3139 |
('WARNING: the ''' , spec , ''' semantics will be changed.') infoPrintCR. |
3140 |
(' Its behavior may be different in future ST/X versions.') infoPrintCR. |
|
11527 | 3141 |
(' called from ' , sender printString) infoPrintCR. |
3142 |
((sender selector ? '') startsWith:'perform:') ifTrue:[ |
|
3143 |
(' called from ' , sender sender printString) infoPrintCR. |
|
7204 | 3144 |
]. |
6950 | 3145 |
message notNil ifTrue:[ |
14975 | 3146 |
'------> ' infoPrint. message infoPrintCR |
6950 | 3147 |
] |
3148 |
||
3149 |
" |
|
3150 |
Object obsoleteFeatureWarning:'foo' from:thisContext sender sender |
|
3151 |
" |
|
3152 |
! |
|
3153 |
||
5755 | 3154 |
obsoleteMethodWarning |
3155 |
"{ Pragma: +optSpace }" |
|
3156 |
||
3157 |
"in methods which are going to be obsoleted, a self send to |
|
3158 |
this method is used to tell programmers that a method is |
|
3159 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3160 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3161 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3162 |
|
3163 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
3164 |
! |
|
3165 |
||
3166 |
obsoleteMethodWarning:message |
|
3167 |
"{ Pragma: +optSpace }" |
|
3168 |
||
3169 |
"in methods which are going to be obsoleted, a self send to |
|
3170 |
this method is used to tell programmers that a method is |
|
3171 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3172 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3173 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3174 |
|
3175 |
self obsoleteMethodWarning:message from:thisContext sender |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3176 |
! |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3177 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3178 |
obsoleteMethodWarning:message from:aContext |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3179 |
"{ Pragma: +optSpace }" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3180 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3181 |
"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
|
3182 |
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
|
3183 |
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
|
3184 |
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
|
3185 |
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
|
3186 |
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
|
3187 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3188 |
|spec sender| |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3189 |
|
9509 | 3190 |
Smalltalk isSmalltalkDevelopmentSystem ifFalse:[ |
14975 | 3191 |
"ignore in production systems" |
3192 |
^ self. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3193 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3194 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3195 |
spec := aContext methodPrintString. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3196 |
sender := aContext sender. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3197 |
('WARNING: the ''' , spec , ''' method is obsolete.') infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3198 |
(' 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
|
3199 |
(' called from ' , sender printString) infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3200 |
(sender selector startsWith:'perform:') ifTrue:[ |
14975 | 3201 |
sender := sender sender. |
3202 |
(sender selector startsWith:'perform:') ifTrue:[ |
|
3203 |
sender := sender sender. |
|
3204 |
]. |
|
3205 |
(' called from ' , sender printString) infoPrintCR. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3206 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3207 |
message notNil ifTrue:[ |
14975 | 3208 |
'------> ' infoPrint. message infoPrintCR |
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3209 |
] |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3210 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3211 |
" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3212 |
Object obsoleteMethodWarning:'foo' from:thisContext sender sender |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3213 |
" |
9509 | 3214 |
|
3215 |
"Modified: / 10-08-2006 / 13:13:11 / cg" |
|
10558 | 3216 |
! |
3217 |
||
12341 | 3218 |
todo |
3219 |
"used to mark code pieces that have to be implemented" |
|
3220 |
||
3221 |
<resource: #skipInDebuggersWalkBack> |
|
3222 |
||
3223 |
self halt:'more work needed here'. |
|
3224 |
||
3225 |
" |
|
3226 |
example: |
|
3227 |
||
14975 | 3228 |
... |
3229 |
self todo. |
|
3230 |
... |
|
12341 | 3231 |
" |
3232 |
! |
|
3233 |
||
10558 | 3234 |
todo:aBlock |
3235 |
"used to mark code pieces that have to be implemented" |
|
3236 |
||
12341 | 3237 |
<resource: #skipInDebuggersWalkBack> |
3238 |
||
10558 | 3239 |
"/ self halt. |
3240 |
"/ aBlock value. |
|
3241 |
||
3242 |
" |
|
3243 |
example: |
|
3244 |
||
14975 | 3245 |
... |
3246 |
self todo:[ |
|
3247 |
code which needs more work ... |
|
3248 |
]. |
|
3249 |
... |
|
10558 | 3250 |
" |
3251 |
||
3252 |
"Created: / 25-05-2007 / 21:34:39 / cg" |
|
3253 |
"Modified: / 29-05-2007 / 12:11:33 / cg" |
|
5755 | 3254 |
! ! |
3255 |
||
3256 |
!Object methodsFor:'dependents access'! |
|
3257 |
||
3258 |
addDependent:anObject |
|
3259 |
"make the argument, anObject be a dependent of the receiver" |
|
3260 |
||
3261 |
|wasBlocked| |
|
3262 |
||
3263 |
"/ must do this save from interrupts, since the dependents collection |
|
3264 |
"/ is possibly accessed from multiple threads. |
|
3265 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3266 |
"/ faster execution. |
|
3267 |
||
3268 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3269 |
[ |
|
14975 | 3270 |
|deps dep| |
3271 |
||
3272 |
deps := self dependents. |
|
3273 |
||
3274 |
"/ to save a fair amount of memory in case of |
|
3275 |
"/ many dependencies, we store a single dependent in |
|
3276 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3277 |
"/ added. |
|
3278 |
||
3279 |
(deps isNil or:[deps size == 0]) ifTrue:[ |
|
3280 |
self dependents:(WeakArray with:anObject) |
|
3281 |
] ifFalse:[ |
|
3282 |
deps class == WeakArray ifTrue:[ |
|
3283 |
dep := deps at:1. |
|
3284 |
dep ~~ anObject ifTrue:[ |
|
3285 |
(dep isNil or:[dep == 0]) ifTrue:[ |
|
3286 |
deps at:1 put:anObject |
|
3287 |
] ifFalse:[ |
|
3288 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
3289 |
] |
|
3290 |
] |
|
3291 |
] ifFalse:[ |
|
3292 |
deps add:anObject |
|
3293 |
] |
|
3294 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3295 |
] ensure:[ |
14975 | 3296 |
wasBlocked ifFalse:[ |
3297 |
OperatingSystem unblockInterrupts |
|
3298 |
] |
|
5755 | 3299 |
] |
3300 |
||
3301 |
"Modified: / 27.10.1997 / 19:35:52 / cg" |
|
3302 |
! |
|
3303 |
||
3304 |
breakDependents |
|
3305 |
"remove all dependencies from the receiver" |
|
3306 |
||
3307 |
self dependents:nil. |
|
3308 |
self nonWeakDependents:nil |
|
3309 |
||
3310 |
"Modified: / 19.4.1996 / 10:55:36 / cg" |
|
3311 |
"Created: / 27.2.1998 / 11:26:11 / stefan" |
|
3312 |
! |
|
3313 |
||
8542 | 3314 |
breakDependentsRecursively |
10460 | 3315 |
"remove all dependencies from the receiver and |
8542 | 3316 |
recursively from all objects referred to by the receiver." |
3317 |
||
3318 |
self breakDependents. |
|
10460 | 3319 |
1 to:self class instSize do:[:idx | |
14975 | 3320 |
(self instVarAt:idx) breakDependentsRecursively. |
10460 | 3321 |
]. |
3322 |
1 to:self basicSize do:[:idx | |
|
14975 | 3323 |
(self basicAt:idx) breakDependentsRecursively. |
8542 | 3324 |
] |
3325 |
! |
|
3326 |
||
5755 | 3327 |
dependents |
3328 |
"return a Collection of dependents. |
|
3329 |
The default implementation here uses a global WeakDictionary to store |
|
10460 | 3330 |
dependents |
5755 | 3331 |
This may be too slow for high frequency change&update, |
3332 |
therefore, some classes (Model) redefine this for better performance. |
|
3333 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
3334 |
||
3335 |
|deps| |
|
3336 |
||
3337 |
(deps := Dependencies at:self ifAbsent:nil) isNil ifTrue:[ |
|
14975 | 3338 |
^ #(). |
5755 | 3339 |
]. |
3340 |
^ deps |
|
3341 |
||
3342 |
"Modified: / 26.1.1998 / 11:18:15 / cg" |
|
3343 |
! |
|
3344 |
||
3345 |
dependents:aCollection |
|
3346 |
"set the collection of dependents. |
|
3347 |
The default implementation here uses a global Dictionary to store |
|
3348 |
dependents which may be too slow for high frequency change&update. |
|
3349 |
Therefore, some classes (Model) redefine this for better performance." |
|
3350 |
||
3351 |
"/ must do this save from interrupts, since the dependents collection |
|
3352 |
"/ is possibly accessed from multiple threads. |
|
3353 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3354 |
"/ faster execution (and to avoid creation of garbage blocks). |
|
3355 |
||
3356 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
14975 | 3357 |
"/ the common case - already blocked |
3358 |
||
3359 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
3360 |
Dependencies removeKey:self ifAbsent:nil |
|
3361 |
] ifFalse:[ |
|
3362 |
Dependencies at:self put:aCollection |
|
3363 |
]. |
|
3364 |
^ self |
|
5755 | 3365 |
]. |
3366 |
||
3367 |
[ |
|
14975 | 3368 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3369 |
Dependencies removeKey:self ifAbsent:nil |
|
3370 |
] ifFalse:[ |
|
3371 |
Dependencies at:self put:aCollection |
|
3372 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3373 |
] ensure:[ |
14975 | 3374 |
OperatingSystem unblockInterrupts |
5755 | 3375 |
] |
3376 |
||
3377 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
|
3378 |
! |
|
3379 |
||
3380 |
dependentsDo:aBlock |
|
3381 |
"evaluate aBlock for all of my dependents" |
|
3382 |
||
3383 |
|deps nwDeps| |
|
3384 |
||
3385 |
deps := self dependents. |
|
3386 |
deps size ~~ 0 ifTrue:[ |
|
14975 | 3387 |
deps do:[:d | |
3388 |
(d notNil and:[d ~~ 0]) ifTrue:[ |
|
3389 |
aBlock value:d |
|
3390 |
] |
|
3391 |
] |
|
5755 | 3392 |
]. |
3393 |
nwDeps := self nonWeakDependents. |
|
3394 |
(nwDeps ~~ deps and:[nwDeps size ~~ 0]) ifTrue:[ |
|
14975 | 3395 |
nwDeps do:aBlock |
5755 | 3396 |
]. |
3397 |
||
3398 |
"Modified: / 30.1.1998 / 14:03:40 / cg" |
|
3399 |
! |
|
3400 |
||
3401 |
myDependents |
|
3402 |
"same as dependents - ST-80 compatibility" |
|
3403 |
||
3404 |
^ self dependents |
|
3405 |
! |
|
3406 |
||
3407 |
release |
|
3408 |
"remove all references to objects that may refer to self. |
|
3409 |
Subclasses may redefine this method but should do a 'super release'." |
|
3410 |
||
3411 |
self breakDependents |
|
3412 |
||
3413 |
"Modified: / 27.2.1998 / 11:29:35 / stefan" |
|
3414 |
! |
|
3415 |
||
3416 |
removeDependent:anObject |
|
3417 |
"make the argument, anObject be independent of the receiver" |
|
3418 |
||
3419 |
|wasBlocked| |
|
3420 |
||
3421 |
"/ must do this save from interrupts, since the dependents collection |
|
3422 |
"/ is possibly accessed from multiple threads. |
|
3423 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3424 |
"/ faster execution. |
|
3425 |
||
3426 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3427 |
[ |
|
14975 | 3428 |
|deps n d| |
3429 |
||
3430 |
deps := self dependents. |
|
3431 |
deps size ~~ 0 ifTrue:[ |
|
3432 |
||
3433 |
"/ to save a fair amount of memory in case of |
|
3434 |
"/ many dependencies, we store a single dependent in |
|
3435 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3436 |
"/ added. Here we have to do the inverse ... |
|
3437 |
||
3438 |
((deps class == WeakArray) or:[deps class == Array]) ifTrue:[ |
|
3439 |
((d := deps at:1) == anObject |
|
3440 |
or:[d isNil |
|
3441 |
or:[d == 0]]) ifTrue:[ |
|
3442 |
self dependents:nil |
|
3443 |
] |
|
3444 |
] ifFalse:[ |
|
3445 |
deps remove:anObject ifAbsent:[]. |
|
3446 |
(n := deps size) == 0 ifTrue:[ |
|
3447 |
self dependents:nil |
|
3448 |
] ifFalse:[ |
|
3449 |
n == 1 ifTrue:[ |
|
3450 |
d := deps firstIfEmpty:nil. |
|
3451 |
d notNil ifTrue:[ |
|
3452 |
deps := (deps isWeakCollection ifTrue:[WeakArray] ifFalse:[Array]) with:d |
|
3453 |
] ifFalse:[ |
|
3454 |
deps := nil |
|
3455 |
]. |
|
3456 |
self dependents:deps. |
|
3457 |
] |
|
3458 |
] |
|
3459 |
] |
|
3460 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3461 |
] ensure:[ |
14975 | 3462 |
wasBlocked ifFalse:[ |
3463 |
OperatingSystem unblockInterrupts |
|
3464 |
] |
|
5755 | 3465 |
] |
3466 |
||
13500 | 3467 |
"Modified: / 05-07-2011 / 22:49:31 / cg" |
5755 | 3468 |
! ! |
3469 |
||
7266 | 3470 |
!Object methodsFor:'dependents access (non weak)'! |
5755 | 3471 |
|
3472 |
addNonWeakDependent:anObject |
|
3473 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
|
10460 | 3474 |
Be careful: this nonWeakDependency will prevent the dependent from being |
5755 | 3475 |
garbage collected unless the dependency is removed. |
3476 |
This is a private mechanism, for directed dependencies." |
|
3477 |
||
3478 |
|wasBlocked| |
|
3479 |
||
3480 |
"/ must do this save from interrupts, since the dependents collection |
|
3481 |
"/ is possibly accessed from multiple threads. |
|
3482 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3483 |
"/ faster execution. |
|
3484 |
||
3485 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3486 |
[ |
|
14975 | 3487 |
|deps dep| |
3488 |
||
3489 |
deps := self nonWeakDependents. |
|
3490 |
||
3491 |
"/ to save a fair amount of memory in case of |
|
3492 |
"/ many dependencies, we store a single dependent in |
|
3493 |
"/ an Array, and switch to a Set if more dependents are |
|
3494 |
"/ added. |
|
3495 |
||
3496 |
deps size == 0 ifTrue:[ |
|
3497 |
anObject notNil ifTrue:[ |
|
3498 |
self nonWeakDependents:(Array with:anObject). |
|
3499 |
] ifFalse:[ |
|
3500 |
"adding nil causes problems when adding the next one |
|
3501 |
(see below: trying to add nil to IdentitySet)" |
|
9442 | 3502 |
"/ self halt:'try to add nil to list of dependents'. |
14975 | 3503 |
]. |
3504 |
] ifFalse:[ |
|
3505 |
deps class == Array ifTrue:[ |
|
3506 |
dep := deps at:1. |
|
3507 |
dep ~~ anObject ifTrue:[ |
|
3508 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
3509 |
] |
|
3510 |
] ifFalse:[ |
|
3511 |
deps add:anObject |
|
3512 |
] |
|
3513 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3514 |
] ensure:[ |
14975 | 3515 |
wasBlocked ifFalse:[ |
3516 |
OperatingSystem unblockInterrupts |
|
3517 |
] |
|
5755 | 3518 |
] |
3519 |
||
3520 |
"Created: / 19.4.1996 / 10:54:08 / cg" |
|
3521 |
"Modified: / 30.1.1998 / 14:03:08 / cg" |
|
3522 |
! |
|
3523 |
||
3524 |
nonWeakDependents |
|
3525 |
"return a Collection of nonWeakDependents - empty if there is none. |
|
3526 |
This is a private mechanism for directed dependencies." |
|
3527 |
||
3528 |
NonWeakDependencies isNil ifTrue:[^ #()]. |
|
3529 |
^ NonWeakDependencies at:self ifAbsent:#() |
|
3530 |
||
3531 |
"Created: / 19.4.1996 / 10:55:06 / cg" |
|
3532 |
"Modified: / 30.1.1998 / 14:06:47 / cg" |
|
3533 |
! |
|
3534 |
||
3535 |
nonWeakDependents:aCollection |
|
3536 |
"set the collection of nonWeak dependents. |
|
3537 |
This is a private helper for directed dependencies." |
|
3538 |
||
3539 |
[ |
|
14975 | 3540 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3541 |
NonWeakDependencies removeKey:self ifAbsent:nil |
|
3542 |
] ifFalse:[ |
|
3543 |
NonWeakDependencies at:self put:aCollection |
|
3544 |
] |
|
5755 | 3545 |
] valueUninterruptably |
3546 |
||
3547 |
"Created: 19.4.1996 / 11:07:47 / cg" |
|
3548 |
! |
|
3549 |
||
3550 |
removeNonWeakDependent:anObject |
|
3551 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
|
3552 |
(i.e. make it independent of the receiver)" |
|
3553 |
||
3554 |
|wasBlocked| |
|
3555 |
||
3556 |
"/ must do this save from interrupts, since the dependents collection |
|
3557 |
"/ is possibly accessed from multiple threads. |
|
3558 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3559 |
"/ faster execution. |
|
3560 |
||
3561 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3562 |
[ |
|
14975 | 3563 |
|deps n| |
3564 |
||
3565 |
deps := self nonWeakDependents. |
|
3566 |
deps size ~~ 0 ifTrue:[ |
|
3567 |
deps class == Array ifTrue:[ |
|
3568 |
(deps at:1) == anObject ifTrue:[ |
|
3569 |
self nonWeakDependents:nil |
|
3570 |
] |
|
3571 |
] ifFalse:[ |
|
3572 |
deps remove:anObject ifAbsent:[]. |
|
3573 |
(n := deps size) == 0 ifTrue:[ |
|
3574 |
self nonWeakDependents:nil |
|
3575 |
] ifFalse:[ |
|
3576 |
n == 1 ifTrue:[ |
|
3577 |
self nonWeakDependents:(Array with:(deps first)) |
|
3578 |
] |
|
3579 |
] |
|
3580 |
] |
|
3581 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3582 |
] ensure:[ |
14975 | 3583 |
wasBlocked ifFalse:[ |
3584 |
OperatingSystem unblockInterrupts |
|
3585 |
] |
|
5755 | 3586 |
] |
3587 |
||
3588 |
"Created: / 19.4.1996 / 11:44:44 / cg" |
|
3589 |
"Modified: / 30.1.1998 / 14:04:01 / cg" |
|
3590 |
! ! |
|
3591 |
||
9279 | 3592 |
|
3593 |
||
5755 | 3594 |
!Object methodsFor:'displaying'! |
3595 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3596 |
ascentOn:aGC |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3597 |
"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
|
3598 |
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
|
3599 |
coordinate is given by y. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3600 |
In other words: some draw above the given y coordinate. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3601 |
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
|
3602 |
the given y coordinate." |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3603 |
|
11065
17c01b01000f
Simplify (and speed up) #ascentOn:
Stefan Vogel <sv@exept.de>
parents:
11048
diff
changeset
|
3604 |
^ aGC fontAscent |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3605 |
! |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3606 |
|
6900 | 3607 |
displayOn:aGCOrStream |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3608 |
"Compatibility |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3609 |
append a printed desription on some stream (Dolphin, Squeak) |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3610 |
OR: |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3611 |
display the receiver in a graphicsContext at 0@0 (ST80). |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3612 |
This method allows for any object to be displayed in some view |
5755 | 3613 |
(although the fallBack is to display its printString ...)" |
3614 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3615 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3616 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
14292
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3617 |
aGCOrStream isStream ifTrue:[ |
14975 | 3618 |
self printOn:aGCOrStream. |
3619 |
^ self |
|
6900 | 3620 |
]. |
3621 |
^ self displayOn:aGCOrStream x:0 y:0. |
|
5755 | 3622 |
|
3623 |
"Created: 29.5.1996 / 16:28:58 / cg" |
|
3624 |
! |
|
3625 |
||
3626 |
displayOn:aGC at:aPoint |
|
3627 |
"ST-80 Compatibility |
|
3628 |
display the receiver in a graphicsContext - this method allows |
|
3629 |
for any object to be displayed in a ListView - for example." |
|
3630 |
||
3631 |
^ self displayOn:aGC x:(aPoint x) y:(aPoint y). |
|
3632 |
! |
|
3633 |
||
3634 |
displayOn:aGC x:x y:y |
|
3635 |
"display the receiver in a graphicsContext - this method allows |
|
3636 |
for any object to be displayed in a ListView - for example." |
|
3637 |
||
3638 |
self displayOn:aGC x:x y:y opaque:false |
|
3639 |
||
3640 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3641 |
! |
|
3642 |
||
3643 |
displayOn:aGc x:x y:y opaque:opaque |
|
3644 |
"display the receiver in a graphicsContext - this method allows |
|
3645 |
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
|
3646 |
The fallBack here shows the receivers displayString. |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3647 |
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
|
3648 |
ask using #ascentOn: if required" |
5755 | 3649 |
|
3650 |
|s yBaseline| |
|
3651 |
||
15368 | 3652 |
s := self isString ifTrue:[self] ifFalse:[self displayString]. |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3653 |
yBaseline := y "+ aGc font ascent". |
5755 | 3654 |
opaque ifTrue:[ |
14975 | 3655 |
aGc displayOpaqueString:s x:x y:yBaseline. |
5755 | 3656 |
] ifFalse:[ |
14975 | 3657 |
aGc displayString:s x:x y:yBaseline. |
5755 | 3658 |
]. |
3659 |
||
3660 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3661 |
! |
|
3662 |
||
3663 |
displayOpaqueOn:aGC x:x y:y |
|
3664 |
"display the receiver in a graphicsContext - this method allows |
|
3665 |
for any object to be displayed in a ListView - for example." |
|
3666 |
||
3667 |
self displayOn:aGC x:x y:y opaque:true |
|
3668 |
||
3669 |
"Modified: / 29.5.1996 / 16:29:38 / cg" |
|
3670 |
"Created: / 26.10.1997 / 15:01:36 / cg" |
|
3671 |
! |
|
3672 |
||
3673 |
displayString |
|
3674 |
"return a string used when displaying the receiver in a view; |
|
3675 |
for example an Inspector. This is usually the same as printString, |
|
14292
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3676 |
but sometimes redefined for a better look. |
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3677 |
|
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3678 |
Note: the base method (used by the inspector) is #displayOn:. |
14975 | 3679 |
So you should implement #displayOn: instead of #displayString in subclasses." |
5755 | 3680 |
|
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3681 |
|s| |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3682 |
|
8322
95ca965f65ed
Handle unicode in #displayString
Stefan Vogel <sv@exept.de>
parents:
8300
diff
changeset
|
3683 |
s := CharacterWriteStream on:(String new:32). |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3684 |
self displayOn:s. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3685 |
^ s contents |
5755 | 3686 |
|
3687 |
" |
|
10460 | 3688 |
#(1 2 3) printString |
3689 |
#(1 2 3) displayString |
|
5755 | 3690 |
#(1 2 3) storeString |
3691 |
" |
|
3692 |
! |
|
3693 |
||
3694 |
heightOn:aGC |
|
3695 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
3696 |
||
3697 |
^ (aGC font onDevice:aGC device) heightOf:(self displayString) |
|
3698 |
! |
|
3699 |
||
6654 | 3700 |
widthFrom:startIndex to:endIndex on:aGC |
3701 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3702 |
||
3703 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) from:startIndex to:endIndex |
|
3704 |
! |
|
3705 |
||
5755 | 3706 |
widthOn:aGC |
3707 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3708 |
||
3709 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) |
|
3710 |
! ! |
|
3711 |
||
7359 | 3712 |
!Object methodsFor:'double dispatching'! |
3713 |
||
3714 |
equalFromComplex:aComplex |
|
3715 |
"adding this method here allows for any non-number to be compared to a complex |
|
3716 |
and return false from this comparison. |
|
3717 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3718 |
which uses #= (i.e. a Set or Dictionary)." |
|
3719 |
||
3720 |
^ false |
|
3721 |
! |
|
3722 |
||
3723 |
equalFromFixedPoint:aFixedPoint |
|
3724 |
"adding this method here allows for any non-number to be compared to a fixedPoint |
|
3725 |
and return false from this comparison. |
|
3726 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3727 |
which uses #= (i.e. a Set or Dictionary)." |
|
3728 |
||
3729 |
^ false |
|
3730 |
! |
|
3731 |
||
3732 |
equalFromFloat:aFloat |
|
3733 |
"adding this method here allows for any non-number to be compared to a float |
|
3734 |
and return false from this comparison. |
|
3735 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3736 |
which uses #= (i.e. a Set or Dictionary)." |
|
3737 |
||
3738 |
^ false |
|
3739 |
! |
|
3740 |
||
3741 |
equalFromFraction:aFraction |
|
3742 |
"adding this method here allows for any non-number to be compared to a fraction |
|
3743 |
and return false from this comparison. |
|
3744 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3745 |
which uses #= (i.e. a Set or Dictionary)." |
|
3746 |
||
3747 |
^ false |
|
3748 |
! |
|
3749 |
||
3750 |
equalFromInteger:anInteger |
|
3751 |
"adding this method here allows for any non-number to be compared to an integer |
|
3752 |
and return false from this comparison. |
|
3753 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3754 |
which uses #= (i.e. a Set or Dictionary)." |
|
3755 |
||
3756 |
^ false |
|
3757 |
! |
|
3758 |
||
7455 | 3759 |
equalFromLargeFloat:aLargeFloat |
3760 |
"adding this method here allows for any non-number to be compared to a largeFloat |
|
3761 |
and return false from this comparison. |
|
3762 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3763 |
which uses #= (i.e. a Set or Dictionary)." |
|
3764 |
||
3765 |
^ false |
|
3766 |
! |
|
3767 |
||
7359 | 3768 |
equalFromLongFloat:aLongFloat |
3769 |
"adding this method here allows for any non-number to be compared to a longFloat |
|
3770 |
and return false from this comparison. |
|
3771 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3772 |
which uses #= (i.e. a Set or Dictionary)." |
|
3773 |
||
3774 |
^ false |
|
3775 |
! |
|
3776 |
||
3777 |
equalFromShortFloat:aShortFloat |
|
3778 |
"adding this method here allows for any non-number to be compared to a shortFloat |
|
3779 |
and return false from this comparison. |
|
3780 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3781 |
which uses #= (i.e. a Set or Dictionary)." |
|
3782 |
||
3783 |
^ false |
|
3784 |
! ! |
|
3785 |
||
5755 | 3786 |
!Object methodsFor:'encoding & decoding'! |
3787 |
||
3788 |
decodeAsLiteralArray |
|
8832 | 3789 |
"given a literalEncoding in the receiver, |
3790 |
create & return the corresponding object. |
|
3791 |
The inverse operation to #literalArrayEncoding." |
|
3792 |
||
5755 | 3793 |
^ self |
3794 |
! |
|
3795 |
||
3796 |
encodeOn:anEncoder with:aParameter |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3797 |
"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
|
3798 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3799 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3800 |
|
8404 | 3801 |
self acceptVisitor:anEncoder with:aParameter |
6718 | 3802 |
! |
3803 |
||
3804 |
encodingVectorForInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3805 |
"OBSOLETE, use elementDescriptorForInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3806 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3807 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3808 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3809 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
6718 | 3810 |
|
3811 |
" |
|
3812 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
3813 |
Dictionary new encodingVectorForInstanceVariables |
|
3814 |
(5 @ nil) encodingVectorForInstanceVariables |
|
3815 |
" |
|
3816 |
! |
|
3817 |
||
3818 |
encodingVectorForNonNilInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3819 |
"OBSOLETE, use elementDescriptorForNonNilInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3820 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3821 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3822 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3823 |
^ self elementDescriptorForInstanceVariablesMatching:[:varVal | varVal notNil]. |
6718 | 3824 |
|
3825 |
" |
|
3826 |
#(1 2 3 nil true symbol) encodingVectorForNonNilInstanceVariables |
|
3827 |
(5 @ nil) encodingVectorForNonNilInstanceVariables |
|
3828 |
" |
|
3829 |
! |
|
3830 |
||
5755 | 3831 |
fromLiteralArrayEncoding:aSpecArray |
8798 | 3832 |
"read my attributes from aSpecArray. |
3833 |
Recursively decodes arguments." |
|
3834 |
||
3835 |
|sel litVal val |
|
5755 | 3836 |
stop "{ Class:SmallInteger }" | |
3837 |
||
3838 |
stop := aSpecArray size. |
|
3839 |
||
3840 |
2 to:stop by:2 do:[:i| |
|
14975 | 3841 |
sel := aSpecArray at:i. |
3842 |
litVal := aSpecArray at:i + 1. |
|
3843 |
||
3844 |
(self respondsTo:sel) ifTrue:[ |
|
3845 |
val := litVal decodeAsLiteralArray. |
|
3846 |
self perform:sel with:val |
|
3847 |
] ifFalse:[ |
|
3848 |
Transcript show:self class name; show:': unhandled literalArrayEncoding attribute: '. |
|
3849 |
Transcript showCR:sel. |
|
3850 |
||
3851 |
"/ thats a debug halt, |
|
3852 |
"/ it should probably be removed (to simply ignore unhandled attributes)... |
|
3853 |
"/ for now, it is left in, in order to easily find incompatibilities between |
|
3854 |
"/ VW and ST/X. |
|
3855 |
self breakPoint:#cg. |
|
3856 |
] |
|
5755 | 3857 |
] |
3858 |
! |
|
3859 |
||
3860 |
literalArrayEncoding |
|
3861 |
"generate a literalArrayEncoding array for myself. |
|
3862 |
This uses #literalArrayEncodingSlotOrder which defines the slots and |
|
3863 |
order and #skippedInLiteralEncoding which defines slots to skip. |
|
3864 |
For most subclasses, there is no need to redefine those." |
|
3865 |
||
8832 | 3866 |
|names encoding cls skipped slots| |
5755 | 3867 |
|
3868 |
self isLiteral ifTrue:[ |
|
14975 | 3869 |
^ self |
5755 | 3870 |
]. |
3871 |
||
8832 | 3872 |
slots := self literalArrayEncodingSlotOrder. |
5755 | 3873 |
skipped := self skippedInLiteralEncoding. |
3874 |
cls := self class. |
|
3875 |
names := cls allInstVarNames. |
|
8832 | 3876 |
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
|
3877 |
encoding add:cls name. |
8832 | 3878 |
|
3879 |
slots do:[:instSlot | |
|
14975 | 3880 |
|value nm| |
3881 |
||
3882 |
nm := names at:instSlot. |
|
3883 |
(skipped includes:nm) ifFalse:[ |
|
3884 |
(value := self instVarAt:instSlot) notNil ifTrue:[ |
|
3885 |
encoding add:(nm , ':') asSymbol. |
|
3886 |
encoding add:value literalArrayEncoding |
|
3887 |
] |
|
3888 |
] |
|
5755 | 3889 |
]. |
3890 |
^ encoding asArray |
|
8841 | 3891 |
|
3892 |
" |
|
14975 | 3893 |
(1 -> 2) literalArrayEncoding |
3894 |
DebugView menuSpec decodeAsLiteralArray literalArrayEncoding = |
|
3895 |
DebugView menuSpec |
|
8841 | 3896 |
" |
5755 | 3897 |
! |
3898 |
||
3899 |
literalArrayEncodingSlotOrder |
|
3900 |
"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
|
3901 |
a literalArrayEncoding" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3902 |
|
5755 | 3903 |
^ 1 to:self class instSize |
3904 |
! |
|
3905 |
||
7112 | 3906 |
postDecodeFrom:aDecoder aspect:aspectSymbol |
3907 |
"invoked by xmlDecoder (and others in the future), after an |
|
3908 |
object has been decoded (i.e. its instance variables have been restored)" |
|
3909 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3910 |
^ self |
7112 | 3911 |
! |
3912 |
||
5755 | 3913 |
skippedInLiteralEncoding |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3914 |
"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
|
3915 |
|
5755 | 3916 |
^ #() |
3917 |
! ! |
|
3918 |
||
3919 |
!Object methodsFor:'error handling'! |
|
3920 |
||
13416 | 3921 |
ambiguousMessage:aMessage |
3922 |
"this message is sent by the system in case that it |
|
3923 |
is not clear which method to execute in response to |
|
14632 | 3924 |
aMessage. |
13416 | 3925 |
Such situation may occur when a current selector namespace |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
3926 |
imports two namespaces and both define a method with the |
13416 | 3927 |
requested selector." |
3928 |
||
3929 |
<context: #return> |
|
3930 |
<resource: #skipInDebuggersWalkBack> |
|
3931 |
||
3932 |
^ AmbiguousMessage raiseRequestWith:aMessage |
|
3933 |
||
3934 |
"Created: / 21-07-2010 / 15:44:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
3935 |
"Modified (comment): / 02-11-2012 / 10:14:42 / cg" |
13416 | 3936 |
! |
3937 |
||
5755 | 3938 |
appropriateDebugger:aSelector |
3939 |
"{ Pragma: +optSpace }" |
|
3940 |
||
3941 |
"return an appropriate debugger to use. |
|
3942 |
If there is already a debugger active on the stack, and it is |
|
3943 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
3944 |
||
3945 |
|context| |
|
3946 |
||
3947 |
"DebugView cannot run without system processes" |
|
3948 |
||
10460 | 3949 |
(Processor isNil |
5755 | 3950 |
or:[Processor activeProcessIsSystemProcess |
3951 |
or:[Smalltalk isInitialized not]]) ifTrue:[ |
|
14975 | 3952 |
^ MiniDebugger |
5755 | 3953 |
]. |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
3954 |
(Screen isNil or:[Screen default isNil or:[Screen default isOpen not]]) ifTrue:[ |
14975 | 3955 |
Debugger isNil ifTrue:[^ nil]. |
3956 |
^ MiniDebugger |
|
5755 | 3957 |
]. |
3958 |
||
3959 |
context := thisContext. |
|
3960 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
3961 |
[context notNil] whileTrue:[ |
|
14975 | 3962 |
((context receiver class == Debugger) |
3963 |
and:[context selector == aSelector]) ifTrue:[ |
|
3964 |
"we are already in some Debugger" |
|
3965 |
(Debugger == MiniDebugger) ifTrue:[ |
|
3966 |
"we are already in the MiniDebugger" |
|
3967 |
ErrorRecursion ifFalse:[ |
|
3968 |
Smalltalk fatalAbort:'recursive error ...' |
|
3969 |
] |
|
3970 |
]. |
|
3971 |
MiniDebugger isNil ifTrue:[ |
|
3972 |
Smalltalk fatalAbort:'no debugger' |
|
3973 |
]. |
|
3974 |
||
3975 |
"ok, an error occured while in the graphical debugger; |
|
3976 |
lets try MiniDebugger" |
|
3977 |
^ MiniDebugger |
|
3978 |
]. |
|
3979 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
5755 | 3980 |
]. |
3981 |
"not within Debugger - no problem" |
|
3982 |
^ Debugger |
|
3983 |
||
3984 |
"Modified: / 23.9.1996 / 12:14:52 / stefan" |
|
3985 |
"Modified: / 19.5.1999 / 18:05:00 / cg" |
|
3986 |
! |
|
3987 |
||
3988 |
cannotSendMessage:aMessage to:someReceiver |
|
3989 |
"this message is sent by the runtime system (VM), |
|
3990 |
when a message is sent to some object, whose class is not |
|
3991 |
a valid behavior (see documentation in Behavior)." |
|
3992 |
||
11021 | 3993 |
<resource: #skipInDebuggersWalkBack> |
3994 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3995 |
^ VMInternalError |
14975 | 3996 |
raiseWith:someReceiver |
3997 |
errorString:('bad class in send of #' , aMessage selector) |
|
5755 | 3998 |
|
3999 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
4000 |
! |
|
4001 |
||
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4002 |
conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4003 |
"return the signal used for conversion error handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4004 |
|
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4005 |
^ self class conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4006 |
! |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4007 |
|
5755 | 4008 |
doesNotUnderstand:aMessage |
4009 |
"this message is sent by the runtime system (VM) when |
|
4010 |
a message is not understood by some object (i.e. there |
|
4011 |
is no method for that selector). The original message has |
|
4012 |
been packed into aMessage (i.e. the receiver, selector and |
|
4013 |
any arguments) and the original receiver is then sent the |
|
4014 |
#doesNotUnderstand: message. |
|
4015 |
Here, we raise another signal which usually enters the debugger. |
|
4016 |
You can of course redefine #doesNotUnderstand: in your classes |
|
10460 | 4017 |
to implement message delegation, |
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
4018 |
or handle the MessageNotUnderstood exception gracefully." |
5755 | 4019 |
|
4020 |
<context: #return> |
|
11021 | 4021 |
<resource: #skipInDebuggersWalkBack> |
5755 | 4022 |
|
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
4023 |
^ MessageNotUnderstood raiseRequestWith:aMessage |
5755 | 4024 |
! |
4025 |
||
4026 |
elementBoundsError |
|
4027 |
"{ Pragma: +optSpace }" |
|
4028 |
||
10460 | 4029 |
"report an error that badElement is out of bounds |
5755 | 4030 |
(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
|
4031 |
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
|
4032 |
|
11021 | 4033 |
<resource: #skipInDebuggersWalkBack> |
4034 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4035 |
^ ElementBoundsError raise |
5755 | 4036 |
|
4037 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
4038 |
! |
|
4039 |
||
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4040 |
elementBoundsError:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4041 |
"{ Pragma: +optSpace }" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4042 |
|
10460 | 4043 |
"report an error that aValue is not valid as element |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4044 |
(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
|
4045 |
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
|
4046 |
|
11021 | 4047 |
<resource: #skipInDebuggersWalkBack> |
4048 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4049 |
^ ElementBoundsError raiseWith:aValue |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4050 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4051 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4052 |
! |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4053 |
|
5755 | 4054 |
elementNotCharacter |
4055 |
"{ Pragma: +optSpace }" |
|
4056 |
||
4057 |
"report an error that object to be stored is no Character. |
|
4058 |
(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
|
4059 |
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
|
4060 |
|
11021 | 4061 |
<resource: #skipInDebuggersWalkBack> |
4062 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4063 |
^ ElementBoundsError raise |
5755 | 4064 |
|
4065 |
"Modified: 8.5.1996 / 09:12:49 / cg" |
|
4066 |
! |
|
4067 |
||
4068 |
elementNotInteger |
|
4069 |
"{ Pragma: +optSpace }" |
|
4070 |
||
4071 |
"report an error that object to be stored is not Integer. |
|
4072 |
(in collections that store integers only). |
|
4073 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
4074 |
||
11021 | 4075 |
<resource: #skipInDebuggersWalkBack> |
4076 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4077 |
^ ElementBoundsError raise |
5755 | 4078 |
|
4079 |
"Modified: 8.5.1996 / 09:12:51 / cg" |
|
4080 |
! |
|
4081 |
||
4082 |
error |
|
4083 |
"{ Pragma: +optSpace }" |
|
4084 |
||
4085 |
"report error that an error occured. |
|
4086 |
The error is reported by raising the Error exception, |
|
4087 |
which is non-proceedable. |
|
4088 |
If no handler has been setup, a debugger is entered." |
|
4089 |
||
11021 | 4090 |
<context: #return> |
4091 |
<resource: #skipInDebuggersWalkBack> |
|
4092 |
||
5755 | 4093 |
Error raiseWith:#error: |
4094 |
||
4095 |
" |
|
4096 |
nil error |
|
4097 |
" |
|
4098 |
||
4099 |
"Modified: / 8.5.1996 / 09:13:01 / cg" |
|
4100 |
"Modified: / 2.8.1999 / 17:00:19 / stefan" |
|
4101 |
! |
|
4102 |
||
4103 |
error:aString |
|
4104 |
"{ Pragma: +optSpace }" |
|
4105 |
||
4106 |
"Raise an error with error message aString. |
|
4107 |
The error is reported by raising the Error exception, |
|
4108 |
which is non-proceedable. |
|
4109 |
If no handler has been setup, a debugger is entered." |
|
4110 |
||
11021 | 4111 |
<context: #return> |
4112 |
<resource: #skipInDebuggersWalkBack> |
|
4113 |
||
10460 | 4114 |
Error raiseWith:#error: errorString:aString |
5755 | 4115 |
|
4116 |
" |
|
4117 |
nil error:' bad bad bad' |
|
4118 |
" |
|
4119 |
||
4120 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
4121 |
! |
|
4122 |
||
4123 |
error:aString mayProceed:mayProceed |
|
4124 |
"{ Pragma: +optSpace }" |
|
4125 |
||
4126 |
"enter debugger with error-message aString. |
|
10460 | 4127 |
The error is reported by raising either the |
5755 | 4128 |
non-proceedable Error exception, |
4129 |
or the ProceedableError exception." |
|
4130 |
||
11021 | 4131 |
<resource: #skipInDebuggersWalkBack> |
4132 |
||
5755 | 4133 |
mayProceed ifTrue:[ |
14975 | 4134 |
^ ProceedableError raiseRequestWith:#error: errorString:aString |
10460 | 4135 |
]. |
4136 |
||
4137 |
Error raiseWith:#error: errorString:aString |
|
5755 | 4138 |
|
4139 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
4140 |
! |
|
4141 |
||
6900 | 4142 |
errorInvalidFormat |
4143 |
"{ Pragma: +optSpace }" |
|
4144 |
||
4145 |
"report an error that some conversion to/from string representation failed |
|
4146 |
typically when converting numbers, date, time etc." |
|
4147 |
||
11021 | 4148 |
<context: #return> |
4149 |
<resource: #skipInDebuggersWalkBack> |
|
4150 |
||
6900 | 4151 |
^ ConversionError raiseErrorString:'invalid format' |
4152 |
! |
|
4153 |
||
5755 | 4154 |
errorKeyNotFound:aKey |
4155 |
"{ Pragma: +optSpace }" |
|
4156 |
||
4157 |
"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
|
4158 |
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
|
4159 |
|
11021 | 4160 |
<resource: #skipInDebuggersWalkBack> |
4161 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
4162 |
^ KeyNotFoundError raiseRequestWith:aKey errorString:(' ', aKey printString) |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4163 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4164 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4165 |
Dictionary new at:#nonExistantElement |
5755 | 4166 |
" |
4167 |
! |
|
4168 |
||
4169 |
errorNotFound |
|
4170 |
"{ Pragma: +optSpace }" |
|
4171 |
||
4172 |
"report an error that no element was found in a collection. |
|
4173 |
The error is reported by raising the NotFoundSignal exception." |
|
4174 |
||
11021 | 4175 |
<resource: #skipInDebuggersWalkBack> |
4176 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4177 |
^ NotFoundError raiseRequestWith:nil |
5755 | 4178 |
|
4179 |
"Modified: / 8.5.1996 / 09:13:11 / cg" |
|
4180 |
"Modified: / 26.7.1999 / 10:51:50 / stefan" |
|
4181 |
! |
|
4182 |
||
6874 | 4183 |
errorNotFound:errorString |
4184 |
"{ Pragma: +optSpace }" |
|
4185 |
||
4186 |
"report an error that no element was found in a collection. |
|
4187 |
The error is reported by raising the NotFoundSignal exception." |
|
4188 |
||
11021 | 4189 |
<resource: #skipInDebuggersWalkBack> |
4190 |
||
10837
63d19c75d762
changed #errorNotFound: raise it proceedable
Stefan Vogel <sv@exept.de>
parents:
10834
diff
changeset
|
4191 |
^ NotFoundError raiseRequestErrorString:errorString |
6874 | 4192 |
! |
4193 |
||
5755 | 4194 |
errorSignal |
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4195 |
"return the signal used for error/error: handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4196 |
|
5755 | 4197 |
^ self class errorSignal |
4198 |
||
4199 |
"Created: / 19.6.1998 / 02:32:32 / cg" |
|
4200 |
! |
|
4201 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4202 |
handlerForSignal:exceptionHandler context:theContext originator:originator |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4203 |
" 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
|
4204 |
|
7566 | 4205 |
thisContext isRecursive ifTrue:[^ nil]. |
4206 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4207 |
'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
|
4208 |
' context: ' print. theContext printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4209 |
' originator: ' print. originator printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4210 |
' sender: ' print. thisContext sender printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4211 |
|
7566 | 4212 |
"/ MiniDebugger enter:thisContext withMessage:'oops' mayProceed:true. |
4213 |
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
|
4214 |
! |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4215 |
|
5755 | 4216 |
implementedBySubclass |
4217 |
"{ Pragma: +optSpace }" |
|
4218 |
||
4219 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
4220 |
||
11021 | 4221 |
<resource: #skipInDebuggersWalkBack> |
4222 |
||
12322 | 4223 |
^ SubclassResponsibilityError raiseRequestErrorString:'method must be reimplemented in ST/V subclass' |
5755 | 4224 |
! |
4225 |
||
4226 |
indexNotInteger |
|
4227 |
"{ Pragma: +optSpace }" |
|
4228 |
||
4229 |
"report an error that index is not an Integer. |
|
4230 |
(when accessing collections indexed by an integer key). |
|
4231 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4232 |
||
11021 | 4233 |
<resource: #skipInDebuggersWalkBack> |
4234 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4235 |
^ NonIntegerIndexError raiseRequestWith:nil |
5755 | 4236 |
|
4237 |
"Modified: / 8.5.1996 / 09:13:37 / cg" |
|
4238 |
"Modified: / 26.7.1999 / 10:57:43 / stefan" |
|
4239 |
! |
|
4240 |
||
4241 |
indexNotInteger:anIndex |
|
4242 |
"{ Pragma: +optSpace }" |
|
4243 |
||
4244 |
"report an error that index is not an Integer. |
|
4245 |
(when accessing collections indexed by an integer key). |
|
4246 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4247 |
||
11021 | 4248 |
<resource: #skipInDebuggersWalkBack> |
4249 |
||
10460 | 4250 |
^ NonIntegerIndexError raiseRequestWith:anIndex |
5755 | 4251 |
|
4252 |
"Created: / 16.5.1998 / 19:39:41 / cg" |
|
4253 |
! |
|
4254 |
||
7216 | 4255 |
indexNotIntegerOrOutOfBounds:index |
4256 |
"{ Pragma: +optSpace }" |
|
4257 |
||
4258 |
"report an error that index is either non-integral or out of bounds" |
|
4259 |
||
11021 | 4260 |
<resource: #skipInDebuggersWalkBack> |
4261 |
||
7216 | 4262 |
index isInteger ifFalse:[ |
14975 | 4263 |
^ self indexNotInteger:index |
7216 | 4264 |
]. |
4265 |
^ self subscriptBoundsError:index |
|
4266 |
! |
|
4267 |
||
5755 | 4268 |
integerCheckError |
4269 |
"{ Pragma: +optSpace }" |
|
4270 |
||
12321 | 4271 |
"generated when a variable declared with an integer type gets a bad value assigned" |
5755 | 4272 |
|
11021 | 4273 |
<resource: #skipInDebuggersWalkBack> |
4274 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4275 |
"/ ^ self error:'bad assign of ' , self printString , |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4276 |
"/ ' (' , self class name , ') to integer-typed variable' |
14632 | 4277 |
^ InvalidTypeError |
14975 | 4278 |
raiseRequestErrorString:( |
4279 |
'bad assign of ' , self printString , |
|
4280 |
' (' , self class name , ') to integer-typed variable') |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4281 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4282 |
"Modified: / 02-11-2012 / 10:25:36 / cg" |
5755 | 4283 |
! |
4284 |
||
4285 |
invalidCodeObject |
|
4286 |
"{ Pragma: +optSpace }" |
|
4287 |
||
12321 | 4288 |
"this is sent by VM if it encounters some non-method for execution" |
4289 |
||
11021 | 4290 |
<resource: #skipInDebuggersWalkBack> |
4291 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4292 |
"/ self error:'not an executable code object' |
14632 | 4293 |
^ ExecutionError |
14975 | 4294 |
raiseRequestErrorString:'not an executable code object' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4295 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4296 |
"Created: / 01-08-1997 / 00:16:44 / cg" |
5755 | 4297 |
! |
4298 |
||
10460 | 4299 |
invalidMessage |
5755 | 4300 |
"{ Pragma: +optSpace }" |
4301 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4302 |
"this is sent by ST/V code - it's the same as #shouldNotImplement" |
5755 | 4303 |
|
11021 | 4304 |
<resource: #skipInDebuggersWalkBack> |
4305 |
||
5755 | 4306 |
^ self shouldNotImplement |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4307 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4308 |
"Modified (comment): / 02-11-2012 / 10:11:18 / cg" |
5755 | 4309 |
! |
4310 |
||
4311 |
mustBeRectangle |
|
4312 |
"{ Pragma: +optSpace }" |
|
4313 |
||
4314 |
"report an argument-not-rectangle-error" |
|
4315 |
||
11021 | 4316 |
<resource: #skipInDebuggersWalkBack> |
4317 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4318 |
"/ ^ self error:'argument must be a Rectangle' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4319 |
^ InvalidTypeError |
14975 | 4320 |
raiseRequestErrorString:'argument must be a Rectangle' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4321 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4322 |
"Modified: / 02-11-2012 / 10:24:53 / cg" |
5755 | 4323 |
! |
4324 |
||
4325 |
mustBeString |
|
4326 |
"{ Pragma: +optSpace }" |
|
4327 |
||
4328 |
"report an argument-not-string-error" |
|
4329 |
||
11021 | 4330 |
<resource: #skipInDebuggersWalkBack> |
4331 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4332 |
"/ ^ self error:'argument must be a String' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4333 |
^ InvalidTypeError |
14975 | 4334 |
raiseRequestErrorString:'argument must be a String' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4335 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4336 |
"Modified: / 02-11-2012 / 10:24:35 / cg" |
5755 | 4337 |
! |
4338 |
||
4339 |
notIndexed |
|
4340 |
"{ Pragma: +optSpace }" |
|
4341 |
||
4342 |
"report an error that receiver has no indexed instance variables. |
|
4343 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4344 |
||
11021 | 4345 |
<context: #return> |
4346 |
<resource: #skipInDebuggersWalkBack> |
|
4347 |
||
10460 | 4348 |
^ SubscriptOutOfBoundsError |
14975 | 4349 |
raiseRequestErrorString:'receiver has no indexed variables' |
5755 | 4350 |
|
14539 | 4351 |
" |
4352 |
1234 at:4 |
|
4353 |
" |
|
4354 |
||
5755 | 4355 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
4356 |
! |
|
4357 |
||
12050 | 4358 |
notYetImplemented |
4359 |
"{ Pragma: +optSpace }" |
|
4360 |
||
12321 | 4361 |
"report an error that some functionality is not yet implemented. |
4362 |
This is here only for compatibility - it has the same meaning as shouldImplement." |
|
12050 | 4363 |
|
4364 |
<resource: #skipInDebuggersWalkBack> |
|
4365 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4366 |
"/ ^ self error:'method/functionality is not yet implemented' |
14632 | 4367 |
^ MethodNotAppropriateError |
14975 | 4368 |
raiseRequestErrorString:'method/functionality is not yet implemented' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4369 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4370 |
"Modified: / 02-11-2012 / 10:24:12 / cg" |
12050 | 4371 |
! |
4372 |
||
5755 | 4373 |
openDebuggerOnException:ex |
4374 |
"{ Pragma: +optSpace }" |
|
4375 |
||
4376 |
"enter the debugger on some unhandled exception" |
|
4377 |
||
6884 | 4378 |
|msgString debugger answer| |
5755 | 4379 |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4380 |
msgString := ex descriptionForDebugger. |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
4381 |
|
5755 | 4382 |
" |
4383 |
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
|
4384 |
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
|
4385 |
ignore will raise an AbortOperationRequest. |
5755 | 4386 |
" |
4387 |
Debugger isNil ifTrue:[ |
|
14965 | 4388 |
msgString := 'Error: ' , msgString. |
4389 |
||
4390 |
thisContext isRecursive ifTrue:[ |
|
4391 |
msgString errorPrintCR. |
|
4392 |
Smalltalk fatalAbort:'recursive unhandled exception' |
|
4393 |
]. |
|
4394 |
||
4395 |
Smalltalk isStandAloneApp ifTrue:[ |
|
15116 | 4396 |
(ex creator == NoHandlerError and:[HaltInterrupt handles:ex exception]) ifTrue:[ |
14965 | 4397 |
"/ 'Halt ignored' infoPrintCR. |
4398 |
^ nil |
|
4399 |
]. |
|
4400 |
"don't output the message, if the exception is a UserInterrupt (CTRL-C)" |
|
15116 | 4401 |
(ex creator == NoHandlerError |
4402 |
and:[ex exception creator == UserInterrupt]) ifTrue:[ |
|
14965 | 4403 |
ex description errorPrintCR. |
4404 |
OperatingSystem exit:130. |
|
4405 |
]. |
|
4406 |
]. |
|
4407 |
||
4408 |
(Dialog notNil and:[Screen default notNil]) ifTrue:[ |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4409 |
false "oldCode" ifTrue:[ |
14965 | 4410 |
AbortOperationRequest isHandled ifTrue:[ |
4411 |
answer := OptionBox |
|
4412 |
request:msgString |
|
4413 |
label:msgString |
|
4414 |
buttonLabels:#('Exit' 'Terminate Thread' 'Ignore' 'Abort' ) |
|
4415 |
values:#(exit terminate ignore abort) |
|
4416 |
default:#abort. |
|
4417 |
] ifFalse:[ |
|
4418 |
answer := OptionBox |
|
4419 |
request:msgString |
|
4420 |
label:msgString |
|
4421 |
buttonLabels:#('Exit' 'Terminate Thread' 'Ignore' ) |
|
4422 |
values:#(exit terminate ignore ) |
|
4423 |
default:#terminate. |
|
4424 |
]. |
|
4425 |
answer isNil ifTrue:[ answer := #ignore]. |
|
4426 |
||
4427 |
answer == #abort ifTrue:[ |
|
4428 |
^ AbortOperationRequest raiseRequest |
|
4429 |
]. |
|
4430 |
answer == #ignore ifTrue:[ |
|
4431 |
^ nil |
|
4432 |
]. |
|
4433 |
answer == #terminate ifTrue:[ |
|
4434 |
Processor activeProcess isSystemProcess ifTrue:[ |
|
4435 |
(Dialog confirm:'Are you sure (this might finish the application)') ifFalse:[ |
|
4436 |
^ nil |
|
4437 |
]. |
|
4438 |
]. |
|
4439 |
^ Processor activeProcess terminate. |
|
4440 |
]. |
|
4441 |
"asking second time here to prevent the user from accidently closing his app" |
|
4442 |
answer == #exit ifTrue:[ |
|
4443 |
answer := OptionBox |
|
4444 |
request:'Do you really wish to exit this application (all changes will be lost)?' |
|
4445 |
label:msgString |
|
4446 |
buttonLabels:#('Yes' 'No' ) |
|
4447 |
values:#(exit abort) |
|
4448 |
default:#abort. |
|
4449 |
]. |
|
4450 |
answer == #abort ifTrue:[ |
|
4451 |
^ AbortOperationRequest raiseRequest |
|
4452 |
]. |
|
4453 |
||
4454 |
(Dialog confirm:'Are you sure you want to finish the application ?') ifFalse:[ |
|
4455 |
^ nil |
|
4456 |
]. |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4457 |
] ifFalse:[ |
14965 | 4458 |
self |
4459 |
errorNotify:msgString |
|
4460 |
from:ex suspendedContext |
|
15255 | 4461 |
allowDebug:false |
4462 |
mayProceed:ex willProceed. |
|
14965 | 4463 |
|
4464 |
"/ arrive here if proceeded... |
|
4465 |
^ nil |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4466 |
]. |
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4467 |
|
14965 | 4468 |
]. |
4469 |
||
4470 |
"don't output the message, if the exception is a UserInterrupt (CTRL-C)" |
|
15116 | 4471 |
(ex creator == NoHandlerError |
4472 |
and:[ex exception creator == UserInterrupt]) ifTrue:[ |
|
14965 | 4473 |
OperatingSystem exit:130. |
4474 |
]. |
|
4475 |
msgString errorPrintCR. |
|
4476 |
thisContext fullPrintAll. |
|
4477 |
OperatingSystem exit:1 |
|
5755 | 4478 |
]. |
4479 |
||
4480 |
" |
|
4481 |
find an appropriate debugger to use |
|
4482 |
" |
|
4483 |
debugger := self appropriateDebugger:(thisContext selector). |
|
4484 |
debugger isNil ifTrue:[ |
|
14965 | 4485 |
^ AbortOperationRequest raiseRequest |
4486 |
]. |
|
4487 |
||
4488 |
^ debugger enterException:ex. |
|
4489 |
"/ ^ debugger |
|
4490 |
"/ enter:ex returnableSuspendedContext |
|
4491 |
"/ withMessage:ex descriptionForDebugger |
|
4492 |
"/ mayProceed:(ex mayProceed). |
|
5755 | 4493 |
|
13849
01e27cdbf2bb
changed: #openDebuggerOnException:
Claus Gittinger <cg@exept.de>
parents:
13848
diff
changeset
|
4494 |
"Modified: / 05-12-2011 / 11:53:10 / cg" |
5755 | 4495 |
! |
4496 |
||
4497 |
primitiveFailed |
|
4498 |
"{ Pragma: +optSpace }" |
|
4499 |
||
4500 |
"report an error that some primitive code failed. |
|
14539 | 4501 |
The error is reported by raising the PrimitiveFailure exception. |
4502 |
Sorry for the code duplication: it avoids the extra frame in the debugger." |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4503 |
|
11021 | 4504 |
<resource: #skipInDebuggersWalkBack> |
4505 |
||
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4506 |
|sender| |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4507 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4508 |
sender := thisContext sender. |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4509 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4510 |
^ PrimitiveFailure raiseRequestWith:(Message selector:sender selector arguments:sender args) |
14975 | 4511 |
in:sender. |
5755 | 4512 |
|
6005 | 4513 |
" |
4514 |
1234 primitiveFailed |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4515 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4516 |
[ |
14975 | 4517 |
ExternalBytes new basicAt:40 |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4518 |
] on:PrimitiveFailure do:[:ex| |
14975 | 4519 |
ex inspect |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4520 |
] |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4521 |
" |
5755 | 4522 |
! |
4523 |
||
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4524 |
primitiveFailed:messageString |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4525 |
"{ Pragma: +optSpace }" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4526 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4527 |
"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
|
4528 |
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
|
4529 |
|
11021 | 4530 |
<resource: #skipInDebuggersWalkBack> |
4531 |
||
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4532 |
|sender| |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4533 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4534 |
sender := thisContext sender. |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4535 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4536 |
^ PrimitiveFailure raiseRequestWith:(Message selector:sender selector arguments:sender args) |
14975 | 4537 |
errorString:messageString |
4538 |
in:sender. |
|
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4539 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4540 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4541 |
1234 primitiveFailed:'this is a test' |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4542 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4543 |
! |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4544 |
|
6815 | 4545 |
shouldImplement |
4546 |
"{ Pragma: +optSpace }" |
|
4547 |
||
12321 | 4548 |
"report an error that this message/functionality should be implemented. |
4549 |
This is send by automatically generated method bodies or inside as-yet-uncoded |
|
4550 |
branches of existing methods." |
|
6815 | 4551 |
|
11021 | 4552 |
<resource: #skipInDebuggersWalkBack> |
4553 |
||
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4554 |
|sender| |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4555 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4556 |
sender := thisContext sender. |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4557 |
|
12841 | 4558 |
^ UnimplementedFunctionalityError |
14975 | 4559 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4560 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4561 |
" |
12321 | 4562 |
self shouldImplement |
4563 |
" |
|
4564 |
! |
|
4565 |
||
4566 |
shouldImplement:what |
|
4567 |
"{ Pragma: +optSpace }" |
|
4568 |
||
4569 |
"report an error that this message/functionality should be implemented. |
|
4570 |
This is send by automatically generated method bodies or inside as-yet-uncoded |
|
4571 |
branches of existing methods." |
|
4572 |
||
4573 |
<resource: #skipInDebuggersWalkBack> |
|
4574 |
||
4575 |
|sender| |
|
4576 |
||
4577 |
sender := thisContext sender. |
|
4578 |
||
12841 | 4579 |
^ UnimplementedFunctionalityError |
14975 | 4580 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
4581 |
errorString:what |
|
12321 | 4582 |
|
4583 |
" |
|
4584 |
self shouldImplement:'foobar' |
|
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4585 |
" |
6815 | 4586 |
! |
4587 |
||
11976 | 4588 |
shouldNeverBeReached |
12321 | 4589 |
"report an error that this point may never be reached." |
12841 | 4590 |
|
14499 | 4591 |
<resource: #skipInDebuggersWalkBack> |
4592 |
||
4593 |
^ ExecutionError |
|
14975 | 4594 |
raiseRequestErrorString:'Oops, this may never reached. Something somewhere was terribly wrong.'. |
11976 | 4595 |
|
4596 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
4597 |
! |
|
4598 |
||
4599 |
shouldNeverBeSent |
|
12321 | 4600 |
"report an error that this message may never be sent to the reciever" |
12841 | 4601 |
|
14499 | 4602 |
<resource: #skipInDebuggersWalkBack> |
4603 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4604 |
"/ ^ self error:'This message never may be sent to me!!'. |
14632 | 4605 |
^ MethodNotAppropriateError |
14975 | 4606 |
raiseRequestErrorString:'This message never may be sent to me!!' |
11976 | 4607 |
|
4608 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4609 |
"Modified: / 02-11-2012 / 10:10:42 / cg" |
11976 | 4610 |
! |
4611 |
||
5755 | 4612 |
shouldNotImplement |
4613 |
"{ Pragma: +optSpace }" |
|
4614 |
||
12841 | 4615 |
"report an error that this message should not be implemented - |
12733
48cc66ac5d52
comment/format in: #shouldNotImplement
Claus Gittinger <cg@exept.de>
parents:
12718
diff
changeset
|
4616 |
i.e. that a method is invoked which is not appropriate for the receiver." |
5755 | 4617 |
|
11021 | 4618 |
<resource: #skipInDebuggersWalkBack> |
4619 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4620 |
"/ self error:'method/functionality not appropriate for this class' |
14632 | 4621 |
^ MethodNotAppropriateError |
14975 | 4622 |
raiseRequestErrorString:'method/functionality not appropriate for this class' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4623 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4624 |
"Modified: / 02-11-2012 / 10:02:25 / cg" |
5755 | 4625 |
! |
4626 |
||
4627 |
subclassResponsibility |
|
4628 |
"{ Pragma: +optSpace }" |
|
4629 |
||
12321 | 4630 |
"report an error that this message should have been reimplemented in a subclass" |
5755 | 4631 |
|
11021 | 4632 |
<resource: #skipInDebuggersWalkBack> |
4633 |
||
10877
0666d48f91d1
show the affected method-selector in the subclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
10856
diff
changeset
|
4634 |
^ SubclassResponsibilityError raiseRequestWith:thisContext sender selector |
5755 | 4635 |
! |
4636 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4637 |
subclassResponsibility:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4638 |
"{ Pragma: +optSpace }" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4639 |
|
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4640 |
"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
|
4641 |
|
11021 | 4642 |
<resource: #skipInDebuggersWalkBack> |
4643 |
||
7334 | 4644 |
^ SubclassResponsibilityError raiseRequestErrorString:msg |
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4645 |
! |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4646 |
|
5755 | 4647 |
subscriptBoundsError |
4648 |
"{ Pragma: +optSpace }" |
|
4649 |
||
4650 |
"report an error that some index is out of bounds. |
|
4651 |
(when accessing indexable collections). |
|
4652 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4653 |
||
11021 | 4654 |
<resource: #skipInDebuggersWalkBack> |
4655 |
||
5755 | 4656 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:nil |
4657 |
||
4658 |
"Modified: / 26.7.1996 / 16:45:42 / cg" |
|
4659 |
"Modified: / 26.7.1999 / 10:58:27 / stefan" |
|
4660 |
! |
|
4661 |
||
4662 |
subscriptBoundsError:anIndex |
|
4663 |
"{ Pragma: +optSpace }" |
|
4664 |
||
4665 |
"report an error that anIndex is out of bounds. |
|
4666 |
(when accessing indexable collections). |
|
4667 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4668 |
||
11021 | 4669 |
<resource: #skipInDebuggersWalkBack> |
4670 |
||
10460 | 4671 |
^ SubscriptOutOfBoundsError |
14975 | 4672 |
raiseRequestWith:anIndex |
4673 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
5755 | 4674 |
|
6221 | 4675 |
"Modified: / 17.11.2001 / 22:49:56 / cg" |
5755 | 4676 |
! |
4677 |
||
4678 |
typeCheckError |
|
4679 |
"{ Pragma: +optSpace }" |
|
4680 |
||
4681 |
"generated when a variable declared with a type hint gets a bad |
|
4682 |
value assigned" |
|
4683 |
||
11021 | 4684 |
<resource: #skipInDebuggersWalkBack> |
4685 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4686 |
"/ ^ self error:'bad assign of ' , self printString , |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4687 |
"/ ' (' , self class name , ') to typed variable' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4688 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4689 |
^ InvalidTypeError |
14975 | 4690 |
raiseRequestErrorString: |
4691 |
('bad assign of ' , self printString , |
|
4692 |
' (' , self class name , ') to typed variable') |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4693 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4694 |
"Modified: / 02-11-2012 / 10:19:15 / cg" |
5755 | 4695 |
! ! |
4696 |
||
4697 |
!Object methodsFor:'evaluation'! |
|
4698 |
||
8690
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4699 |
argumentCount |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4700 |
"compatibility with Blocks and Messages. |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4701 |
Answer 0, since we only understand #value. |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4702 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4703 |
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
|
4704 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4705 |
^ 0 |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4706 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4707 |
" |
14975 | 4708 |
[1 // 0] on:ArithmeticError do:9999 |
8690
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4709 |
" |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4710 |
! |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4711 |
|
5755 | 4712 |
value |
4713 |
"return the receiver itself. |
|
4714 |
This allows every object to be used where blocks or valueHolders |
|
4715 |
are typically used, and allows for valueHolders and blocks to be |
|
4716 |
used interchangably in some situations. |
|
4717 |
||
4718 |
Time will show, if this is a good idea or leads to sloppy programming |
|
4719 |
style ... (the idea was borrowed from the Self language). |
|
4720 |
||
10460 | 4721 |
WARNING: dont 'optimize' away ifXXX: blocks |
14975 | 4722 |
(i.e. do NOT replace |
4723 |
foo ifTrue:[var1] ifFalse:[var2] |
|
4724 |
by: |
|
4725 |
foo ifTrue:var1 ifFalse:var2 |
|
4726 |
) |
|
4727 |
- the compilers will only generate inline code for the if, |
|
4728 |
iff the argument(s) are blocks - otherwise, a true send is |
|
4729 |
generated. |
|
4730 |
This 'oprimization' will work semantically correct, |
|
4731 |
but execute SLOWER instead." |
|
5755 | 4732 |
|
4733 |
^ self |
|
4734 |
||
4735 |
" |
|
10460 | 4736 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
4737 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
4738 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
4739 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
5755 | 4740 |
" |
4741 |
||
4742 |
"DO NOT DO THIS (its slower) |
|
7458 | 4743 |
(1 > 4) ifTrue:a ifFalse:b |
5755 | 4744 |
|
4745 |
USE (the compiler optimizes blocks in if/while): |
|
7458 | 4746 |
(1 > 4) ifTrue:[a] ifFalse:[b] |
5755 | 4747 |
" |
4748 |
||
4749 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
4750 |
! ! |
|
4751 |
||
4752 |
!Object methodsFor:'finalization'! |
|
4753 |
||
4754 |
disposed |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4755 |
"OBSOLETE INTERFACE: use #finalize |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4756 |
this is invoked for objects which have been registered |
5755 | 4757 |
in a Registry, when the original object dies. |
4758 |
Subclasses may redefine this method" |
|
4759 |
||
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4760 |
<resource: #obsolete> |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4761 |
|
5755 | 4762 |
^ self |
4763 |
! |
|
4764 |
||
4765 |
executor |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4766 |
"Return the object which does the finalization for me. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4767 |
This interface is also VW & Sqeak compatible," |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4768 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4769 |
"for now, send #shallowCopyForFinalization, to be compatible with |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4770 |
classes designed for old ST/X versions" |
5755 | 4771 |
|
4772 |
^ self shallowCopyForFinalization |
|
4773 |
! |
|
4774 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4775 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4776 |
"answer a Registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4777 |
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
|
4778 |
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
|
4779 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4780 |
^ FinalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4781 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4782 |
|
5755 | 4783 |
finalize |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4784 |
"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
|
4785 |
in a Registry, when the original object dies. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4786 |
Subclasses may redefine this method |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4787 |
This interface is also VW-compatible" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4788 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4789 |
"send #disposed for compatibility with existing classes that still |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4790 |
implement the obsolete #disposed message" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4791 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4792 |
^ self disposed |
5755 | 4793 |
! |
4794 |
||
4795 |
reRegisterForFinalization |
|
4796 |
"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
|
4797 |
This will create a new executor, which will receive a #finalize message when |
5755 | 4798 |
the receiver is garbage collected." |
4799 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4800 |
self finalizationLobby registerChange:self |
5755 | 4801 |
! |
4802 |
||
4803 |
registerForFinalization |
|
4804 |
"register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4805 |
Once registered, the executor of the receiver will receive a #finalize message when |
5755 | 4806 |
the receiver is garbage collected." |
4807 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4808 |
self finalizationLobby register:self |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4809 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4810 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4811 |
shallowCopyForFinalization |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4812 |
"OBSOLETE INTERFACE: use #executor. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4813 |
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
|
4814 |
(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
|
4815 |
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
|
4816 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4817 |
<resource: #obsolete> |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4818 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4819 |
^ self shallowCopy |
5755 | 4820 |
! |
4821 |
||
4822 |
unregisterForFinalization |
|
4823 |
"unregister mySelf from later finalization" |
|
4824 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4825 |
self finalizationLobby unregister:self |
5755 | 4826 |
! ! |
4827 |
||
4828 |
!Object methodsFor:'initialization'! |
|
4829 |
||
4830 |
initialize |
|
4831 |
"just to ignore initialize to objects which do not need it" |
|
4832 |
||
4833 |
^ self |
|
4834 |
! ! |
|
4835 |
||
13190
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4836 |
!Object methodsFor:'inspecting'! |
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4837 |
|
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4838 |
inspectorClass |
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4839 |
"{ Pragma: +optSpace }" |
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4840 |
|
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4841 |
"return the class to use for inspect. |
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4842 |
Can (should) be redefined in classes for which a better inspector is available" |
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4843 |
|
14055 | 4844 |
^ Inspector ? InspectorView |
4845 |
||
4846 |
"Modified: / 08-03-2012 / 16:09:38 / cg" |
|
13190
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4847 |
! ! |
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4848 |
|
5755 | 4849 |
!Object methodsFor:'interrupt handling'! |
4850 |
||
4851 |
childSignalInterrupt |
|
4852 |
"death of a child process (unix process) - do nothing" |
|
4853 |
||
4854 |
^ self |
|
4855 |
! |
|
4856 |
||
4857 |
customInterrupt |
|
4858 |
"{ Pragma: +optSpace }" |
|
4859 |
||
4860 |
"a custom interrupt - but no handler has defined" |
|
4861 |
||
4862 |
self error:'custom interrupt' mayProceed:true |
|
4863 |
! |
|
4864 |
||
4865 |
errorInterrupt:errorID with:aParameter |
|
4866 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
10460 | 4867 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
5755 | 4868 |
which can be called from C subsystems to raise an (asynchronous) |
4869 |
error exception. |
|
4870 |
||
4871 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
4872 |
used from other C subsystems too, to upcast errors. |
|
4873 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
4874 |
IDs (currently) used: |
|
14975 | 4875 |
#DisplayError ..... x-error interrupt |
4876 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
5755 | 4877 |
" |
4878 |
||
6263
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4879 |
|handlers handler| |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4880 |
|
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4881 |
handlers := ObjectMemory registeredErrorInterruptHandlers. |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4882 |
handlers notNil ifTrue:[ |
14975 | 4883 |
handler := handlers at:errorID ifAbsent:nil. |
4884 |
handler notNil ifTrue:[ |
|
4885 |
"/ |
|
4886 |
"/ handler found; let it do whatever it wants ... |
|
4887 |
"/ |
|
4888 |
handler errorInterrupt:errorID with:aParameter. |
|
4889 |
^ self |
|
4890 |
]. |
|
5755 | 4891 |
]. |
4892 |
||
4893 |
"/ |
|
4894 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
4895 |
"/ |
|
10460 | 4896 |
^ Error |
14975 | 4897 |
raiseRequestWith:errorID |
4898 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
5755 | 4899 |
! |
4900 |
||
4901 |
exceptionInterrupt |
|
4902 |
"{ Pragma: +optSpace }" |
|
4903 |
||
4904 |
"exception interrupt - enter debugger" |
|
4905 |
||
4906 |
self error:'exception Interrupt' mayProceed:true |
|
4907 |
! |
|
4908 |
||
4909 |
fpExceptionInterrupt |
|
4910 |
"{ Pragma: +optSpace }" |
|
4911 |
||
4912 |
"a floating point exception occured - this one |
|
4913 |
has to be handled differently since it comes asynchronous |
|
4914 |
on some machines (for example, on machines with a separate FPU |
|
4915 |
or superscalar architectures. Also, errors from within primitive code |
|
4916 |
(or library functions such as GL) are sent via the Unix-signal |
|
4917 |
mechanism this way." |
|
4918 |
||
4919 |
|where rec| |
|
4920 |
||
4921 |
where := thisContext sender. |
|
4922 |
rec := where receiver. |
|
4923 |
rec isNumber ifTrue:[ |
|
14975 | 4924 |
^ rec class |
4925 |
raise:#domainErrorSignal |
|
4926 |
receiver:rec |
|
4927 |
selector:where selector |
|
4928 |
arguments:(where args asArray) |
|
4929 |
errorString:'floating point exception' |
|
5755 | 4930 |
]. |
4931 |
||
4932 |
"/ could be in some C-library ... |
|
7402 | 4933 |
^ DomainError raise |
5755 | 4934 |
! |
4935 |
||
4936 |
internalError:msg |
|
4937 |
"{ Pragma: +optSpace }" |
|
4938 |
||
4939 |
"this is triggered, when VM hits some bad error, |
|
4940 |
such as corrupted class, corrupted method/selector array |
|
4941 |
etc. The argument string gives some more information on what happened. |
|
4942 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
|
4943 |
Its not guaranteed, that the system is in a working condition once |
|
4944 |
this error occurred ...." |
|
4945 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4946 |
VMInternalError raiseWith:self errorString:msg |
5755 | 4947 |
! |
4948 |
||
4949 |
ioInterrupt |
|
4950 |
"{ Pragma: +optSpace }" |
|
4951 |
||
4952 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
|
4953 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
4954 |
or it does not understand the ioInterrupt message. |
|
4955 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
4956 |
||
4957 |
self error:'I/O Interrupt - but no handler' mayProceed:true |
|
4958 |
! |
|
4959 |
||
4960 |
memoryInterrupt |
|
4961 |
"{ Pragma: +optSpace }" |
|
4962 |
||
4963 |
"out-of-memory interrupt and no handler - enter debugger" |
|
4964 |
||
4965 |
self error:'almost out of memory' mayProceed:true |
|
4966 |
! |
|
4967 |
||
4968 |
recursionInterrupt |
|
4969 |
"{ Pragma: +optSpace }" |
|
4970 |
||
4971 |
"recursion limit (actually: stack overflow) interrupt. |
|
4972 |
This interrupt is triggered, when a process stack grows above |
|
4973 |
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
|
4974 |
could be caught. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4975 |
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
|
4976 |
and the exception can be resumed. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4977 |
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
|
4978 |
is not proceedable. |
10460 | 4979 |
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
|
4980 |
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
|
4981 |
or debug for a while. |
5755 | 4982 |
If the signal is ignored, and the stack continues to grow, there |
4983 |
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
|
4984 |
terminates the process." |
5755 | 4985 |
|
7838
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4986 |
|con remaining sender nSkipped| |
5755 | 4987 |
|
4988 |
(con := thisContext) isRecursive ifFalse:[ |
|
4989 |
"/ Processor activeProcess usedStackSize < Processor activeProcess maximumStackSize ifTrue:[ |
|
4990 |
"/ "/ mhmh - it hit me, but I am not responsible ... |
|
4991 |
"/ 'Stray recursionInterrupt ...' infoPrintCR. |
|
4992 |
"/ ^ self |
|
4993 |
"/ ]. |
|
14975 | 4994 |
ObjectMemory infoPrinting ifTrue:[ |
4995 |
'Object [info]: recursionInterrupt from:' printCR. |
|
4996 |
con := con sender. |
|
4997 |
remaining := 50. |
|
4998 |
[con notNil and:[remaining > 0]] whileTrue:[ |
|
4999 |
sender := con sender. |
|
5000 |
'| ' print. con fullPrint. |
|
5001 |
||
5002 |
nSkipped := 0. |
|
5003 |
[sender notNil and:[sender sender notNil |
|
5004 |
and:[sender selector == con selector |
|
5005 |
and:[sender sender selector == con selector |
|
5006 |
and:[sender method == con method]]]]] whileTrue:[ |
|
5007 |
nSkipped := nSkipped + 1. |
|
5008 |
con := sender. |
|
5009 |
sender := con sender. |
|
5010 |
]. |
|
5011 |
nSkipped > 0 ifTrue:[ |
|
5012 |
'| ... ***** ' print. nSkipped print. ' recursive contexts skipped *****' printCR. |
|
5013 |
]. |
|
5014 |
con := sender. |
|
5015 |
remaining := remaining - 1 |
|
5016 |
]. |
|
5017 |
]. |
|
5018 |
^ RecursionInterruptSignal raiseSignal |
|
5755 | 5019 |
] |
5020 |
||
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5021 |
"Modified: / 10.11.2001 / 15:15:56 / cg" |
5755 | 5022 |
! |
5023 |
||
5024 |
schedulerInterrupt |
|
5025 |
"{ Pragma: +optSpace }" |
|
5026 |
||
5027 |
"scheduler interrupt (supposed to be sent to Processor). |
|
5028 |
If we arrive here, either the Processor does not understand it, |
|
5029 |
or it has been set to nil. In any case, this is a sign of some |
|
5030 |
big trouble. Enter debugger." |
|
5031 |
||
5032 |
self error:'schedulerInterrupt - but no Processor' mayProceed:true |
|
5033 |
! |
|
5034 |
||
5035 |
signalInterrupt:signalNumber |
|
5036 |
"{ Pragma: +optSpace }" |
|
5037 |
||
10460 | 5038 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
10016 | 5039 |
(SIGPIPE), others (SIGBUS) are rather fatal... |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
5040 |
In any case, IF a smalltalk-signal has been connected to the OS signal, that one is raised. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
5041 |
Otherwise, a dialog is shown, asking the user on how to handle the signal. |
5755 | 5042 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
5043 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
5044 |
Currently (temporary kludge), these are passed as global variables." |
|
5045 |
||
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5046 |
|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
|
5047 |
action title screen| |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5048 |
|
13254 | 5049 |
thisContext isRecursive ifTrue:[ |
14975 | 5050 |
'Severe error: signalInterrupt while processing a signalInterrupt.' errorPrintCR. |
5051 |
'Terminating process ' errorPrint. Processor activeProcess errorPrintCR. |
|
13710 | 5052 |
"/ GenericException handle:[:ex | |
5053 |
"/ "/ ignore any error during termination |
|
5054 |
"/ ] do:[ |
|
5055 |
"/ Processor activeProcess terminate. |
|
5056 |
"/ ]. |
|
14975 | 5057 |
Processor activeProcess terminateNoSignal. |
13254 | 5058 |
]. |
5059 |
||
5755 | 5060 |
"if there has been an ST-signal installed, use it ..." |
5061 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
5062 |
sig notNil ifTrue:[ |
|
14975 | 5063 |
sig raiseSignalWith:signalNumber. |
5064 |
^ self. |
|
5755 | 5065 |
]. |
5066 |
||
5067 |
"/ if handled, raise OSSignalInterruptSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
5068 |
OSSignalInterrupt isHandled ifTrue:[ |
14975 | 5069 |
OSSignalInterrupt raiseRequestWith:signalNumber. |
5070 |
^ self. |
|
10460 | 5071 |
]. |
5072 |
||
5073 |
" |
|
5074 |
special cases |
|
14975 | 5075 |
- SIGPWR: power failure - write a crash image and continue |
5076 |
- SIGHUP: hang up - write a crash image and exit |
|
10922 | 5077 |
" |
5078 |
(signalNumber == OperatingSystem sigPWR) ifTrue:[ |
|
14975 | 5079 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
5080 |
^ self. |
|
10922 | 5081 |
]. |
5082 |
(signalNumber == OperatingSystem sigHUP) ifTrue:[ |
|
14975 | 5083 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
5084 |
'Object [info]: exit due to hangup signal.' errorPrintCR. |
|
5085 |
Smalltalk exit:1. |
|
7031 | 5086 |
]. |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
5087 |
|
5755 | 5088 |
name := OperatingSystem nameForSignal:signalNumber. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5089 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5090 |
"if there is no screen at all, bring up a mini debugger" |
10460 | 5091 |
(Screen isNil |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5092 |
or:[(screen := Screen current) isNil |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5093 |
or:[(screen := Screen default) isNil |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5094 |
or:[screen isOpen not]]]) ifTrue:[ |
14975 | 5095 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5096 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5097 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5098 |
"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
|
5099 |
otherwise display stays locked" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5100 |
screen ungrabPointer; ungrabKeyboard. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5101 |
|
7031 | 5102 |
here := thisContext. |
5103 |
badContext := here sender. "the context, in which the signal occurred" |
|
5104 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5105 |
"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
|
5106 |
Screen currentScreenQuerySignal answer:screen do:[ |
14975 | 5107 |
" |
5108 |
SIGBUS, SIGSEGV and SIGILL do not make sense to ignore (i.e. continue) |
|
5109 |
since the system will retry the faulty instruction, which leads to |
|
5110 |
another signal - to avoid frustration, better not offer this option. |
|
5111 |
" |
|
5112 |
fatal := OperatingSystem isFatalSignal:signalNumber. |
|
5113 |
fatal ifTrue:[ |
|
5114 |
(Debugger isNil or:[here isRecursive]) ifTrue:[ |
|
5115 |
'Object [hard error]: signal ' errorPrint. signalNumber errorPrintCR. |
|
5116 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
5117 |
]. |
|
5118 |
" |
|
5119 |
a hard signal - go into debugger immediately |
|
5120 |
" |
|
5121 |
msg := 'OS-signal: ', name. |
|
5122 |
||
5123 |
"/ the IRQ-PC is passed as low-hi, to avoid the need |
|
5124 |
"/ to allocate a LargeInteger in the VM during signal |
|
5125 |
"/ time. I know, this is ugly. |
|
5126 |
||
5127 |
InterruptPcLow notNil ifTrue:[ |
|
5128 |
pc := InterruptPcLow + (InterruptPcHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
5129 |
pc ~~ 0 ifTrue:[ |
|
5130 |
msg := msg , ' PC=' , (pc printStringRadix:16) |
|
5131 |
]. |
|
5132 |
]. |
|
5133 |
InterruptAddrLow notNil ifTrue:[ |
|
5134 |
addr := InterruptAddrLow + (InterruptAddrHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
5135 |
addr ~~ 0 ifTrue:[ |
|
5136 |
msg := msg , ' ADDR=' , (addr printStringRadix:16) |
|
5137 |
]. |
|
5138 |
]. |
|
5139 |
Debugger enter:here withMessage:msg mayProceed:false. |
|
5140 |
"unreachable" |
|
5141 |
^ nil. |
|
5142 |
]. |
|
5143 |
||
5144 |
"if possible, open an option box asking the user what do. |
|
5145 |
Otherwise, start a debugger" |
|
5146 |
Dialog notNil ifTrue:[ |
|
5147 |
titles := #('save crash image' 'dump core' 'exit ST/X' 'debug'). |
|
5148 |
actions := #(save core exit debug). |
|
5149 |
||
5150 |
action := nil. |
|
5151 |
title := 'OS Signal caught (' , name, ')'. |
|
5152 |
title := (title , '\[in ST-process: ' , Processor activeProcess nameOrId ,']') withCRs. |
|
5153 |
||
5154 |
"/ if cought while in the scheduler or event dispatcher, |
|
5155 |
"/ a modal dialog is not possible ... |
|
5156 |
"/ (therefore, abort & return does not makes sense) |
|
5157 |
||
5158 |
Processor activeProcess isSystemProcess ifFalse:[ |
|
5159 |
titles := #('abort') , titles. |
|
5160 |
actions := #(abort), actions. |
|
5161 |
||
5162 |
badContext canReturn ifTrue:[ |
|
5163 |
titles := #('return') , titles. |
|
5164 |
actions := #(return), actions. |
|
5165 |
]. |
|
5166 |
]. |
|
5167 |
||
5168 |
fatal ifFalse:[ |
|
5169 |
titles := titles, #('ignore'). |
|
5170 |
actions := actions , #(ignore). |
|
5171 |
]. |
|
5172 |
action := Dialog choose:title |
|
5173 |
labels:titles |
|
5174 |
values:actions |
|
5175 |
default:(fatal ifTrue:[nil] ifFalse:[#ignore]). |
|
5176 |
||
5177 |
"Dialog may fail (if system process), default action is debug" |
|
5178 |
action isEmptyOrNil ifTrue:[action := #debug]. |
|
5179 |
] ifFalse:[ |
|
5180 |
action := #debug. |
|
5181 |
]. |
|
5182 |
||
5183 |
action == #save ifTrue:[ |
|
5184 |
ObjectMemory writeCrashImage |
|
5185 |
]. |
|
5186 |
action == #core ifTrue:[ |
|
5187 |
Smalltalk fatalAbort |
|
5188 |
]. |
|
5189 |
action == #exit ifTrue:[ |
|
5190 |
Smalltalk exit |
|
5191 |
]. |
|
5192 |
action == #return ifTrue:[ |
|
5193 |
badContext return |
|
5194 |
]. |
|
5195 |
action == #abort ifTrue:[ |
|
5196 |
AbortOperationRequest raise. |
|
5197 |
]. |
|
5198 |
||
5199 |
action == #debug ifTrue:[ |
|
5200 |
Debugger isNil ifTrue:[ |
|
5201 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
5202 |
]. |
|
5203 |
Debugger enter:here withMessage:('OS-Signal ', name) mayProceed:true. |
|
5204 |
]. |
|
5205 |
"action == #ignore" |
|
13261 | 5206 |
]. |
5207 |
||
13710 | 5208 |
"Modified: / 15-09-2011 / 16:38:14 / cg" |
5755 | 5209 |
! |
5210 |
||
5211 |
spyInterrupt |
|
5212 |
"{ Pragma: +optSpace }" |
|
5213 |
||
5214 |
"spy interrupt and no handler - enter debugger" |
|
5215 |
||
5216 |
self error:'spy Interrupt - but no handler' mayProceed:true |
|
5217 |
! |
|
5218 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5219 |
startMiniDebuggerOrExit:text |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5220 |
"some critical condition happened. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5221 |
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
|
5222 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5223 |
MiniDebugger isNil ifTrue:[ |
14975 | 5224 |
"a system without debugging facilities (i.e. a standalone system) |
5225 |
output a message and exit." |
|
5226 |
('Object [error]: exit due to ', text, ' - and no debugger.') errorPrintCR. |
|
5227 |
OperatingSystem exit:99. |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5228 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5229 |
MiniDebugger enterWithMessage:text mayProceed:true. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5230 |
! |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5231 |
|
5755 | 5232 |
timerInterrupt |
5233 |
"{ Pragma: +optSpace }" |
|
5234 |
||
5235 |
"timer interrupt and no handler - enter debugger" |
|
5236 |
||
5237 |
self error:'timer Interrupt - but no handler' mayProceed:true |
|
5238 |
! |
|
5239 |
||
5240 |
userInterrupt |
|
5241 |
"{ Pragma: +optSpace }" |
|
5242 |
||
5243 |
"user (^c) interrupt. |
|
5244 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
5245 |
controlling tty (i.e. in the xterm)." |
|
5246 |
||
6466 | 5247 |
UserInterruptSignal raiseRequest |
5755 | 5248 |
! |
5249 |
||
5250 |
userInterruptIn:aContext |
|
5251 |
"{ Pragma: +optSpace }" |
|
5252 |
||
5253 |
"user (^c) interrupt - enter debugger, but show aContext |
|
10460 | 5254 |
as top-context. |
5255 |
This is used to hide any intermediate scheduler contexts, |
|
5755 | 5256 |
in case of an interrupted process. Typically, this is sent by |
5257 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
5258 |
processed." |
|
5259 |
||
5260 |
<context: #return> |
|
5261 |
||
5262 |
UserInterruptSignal raiseRequestWith:nil errorString:nil in:aContext |
|
5263 |
||
5264 |
"Created: / 18.10.1996 / 20:46:04 / cg" |
|
5265 |
"Modified: / 20.10.1996 / 13:06:38 / cg" |
|
5266 |
"Modified: / 26.7.1999 / 10:58:49 / stefan" |
|
5267 |
! ! |
|
5268 |
||
5269 |
!Object methodsFor:'message sending'! |
|
5270 |
||
5271 |
perform:aSelector |
|
5272 |
"send the message aSelector to the receiver" |
|
5273 |
||
11335 | 5274 |
<resource: #skipInDebuggersWalkBack> |
5275 |
||
5755 | 5276 |
%{ |
5277 |
REGISTER OBJ sel = aSelector; |
|
5278 |
||
5279 |
if (InterruptPending == nil) { |
|
14975 | 5280 |
struct inlineCache *pIlc; |
13416 | 5281 |
/* JV @ 2010-22-07: To improve performance I use 256 ILCs instead |
14632 | 5282 |
of default 4. This significantly reduces ILC misses. The code |
5283 |
should be further optimized by remembering last selector index and |
|
5284 |
try a first shot on that index. Another option is to use kind of |
|
5285 |
hashing on lower bits of sel variable. However, a more detailed |
|
13416 | 5286 |
statistical data should be gathered before doing further optimizations. |
5287 |
*/ |
|
5288 |
||
5289 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF0(l) } |
|
5290 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5291 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5292 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5293 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5294 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5295 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5296 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5297 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5298 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5299 |
#define nilcs 256 |
|
5300 |
||
14975 | 5301 |
static struct { OBJ sel; struct inlineCache ilc; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
13416 | 5302 |
|
5303 |
#undef SEL_AND_ILC_INIT_1 |
|
5304 |
#undef SEL_AND_ILC_INIT_2 |
|
5305 |
#undef SEL_AND_ILC_INIT_4 |
|
5306 |
#undef SEL_AND_ILC_INIT_8 |
|
5307 |
#undef SEL_AND_ILC_INIT_16 |
|
5308 |
#undef SEL_AND_ILC_INIT_32 |
|
5309 |
#undef SEL_AND_ILC_INIT_64 |
|
5310 |
#undef SEL_AND_ILC_INIT_128 |
|
5311 |
#undef SEL_AND_ILC_INIT_256 |
|
5312 |
||
14975 | 5313 |
static flip = 0; |
5314 |
int i; |
|
5315 |
for (i = 0; i < nilcs; i++) { |
|
5316 |
if (sel == sel_and_ilc[i].sel) { |
|
5317 |
pIlc = &sel_and_ilc[i].ilc; |
|
5318 |
goto perform0_send_and_return; |
|
5319 |
} |
|
5320 |
} |
|
5321 |
/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/ |
|
5322 |
pIlc = &sel_and_ilc[flip].ilc; |
|
5323 |
sel_and_ilc[flip].sel = sel; |
|
5324 |
flip = (flip + 1) % nilcs; |
|
5325 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5326 |
if (pIlc->ilc_poly) { |
|
5327 |
__flushPolyCache(pIlc->ilc_poly); |
|
5328 |
pIlc->ilc_poly = 0; |
|
5329 |
} |
|
13416 | 5330 |
perform0_send_and_return: |
14975 | 5331 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
5755 | 5332 |
} else { |
14975 | 5333 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
5334 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5755 | 5335 |
} |
5336 |
%}. |
|
5337 |
^ self perform:aSelector withArguments:#() |
|
5338 |
! |
|
5339 |
||
5340 |
perform:aSelector inClass:aClass withArguments:argArray |
|
10460 | 5341 |
"send the message aSelector with all args taken from argArray |
5755 | 5342 |
to the receiver as a super-send message. |
5343 |
This is actually more flexible than the normal super-send, since it allows |
|
5344 |
to execute a method in ANY superclass of the receiver (not just the |
|
5345 |
immediate superclass). |
|
10460 | 5346 |
Thus, it is (theoretically) possible to do |
14975 | 5347 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
5755 | 5348 |
and evaluate Magnitudes compare method even if there was one in Number. |
5349 |
This method is used by the interpreter to evaluate super sends |
|
5350 |
and could be used for very special behavior (language extension ?). |
|
5351 |
||
5352 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
5353 |
||
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5354 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 myClass| |
5755 | 5355 |
|
5356 |
" |
|
5357 |
check, if aClass is really a superclass of the receiver |
|
5358 |
" |
|
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5359 |
myClass := self class. |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5360 |
(myClass == aClass or:[myClass isSubclassOf:aClass]) ifFalse:[ |
14975 | 5361 |
self error:'lookup-class argument is not a superclass of the receiver'. |
5362 |
^ nil |
|
5755 | 5363 |
]. |
5364 |
%{ |
|
5365 |
REGISTER OBJ *argP; |
|
5366 |
int nargs, i; |
|
5367 |
||
8934 | 5368 |
if (__isArrayLike(argArray)) { |
14975 | 5369 |
nargs = __arraySize(argArray); |
5370 |
argP = __arrayVal(argArray); |
|
5755 | 5371 |
} else { |
14975 | 5372 |
if (__isNonNilObject(argArray)) { |
5373 |
static struct inlineCache ilcSize = __ILC0(@line+1); |
|
5374 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5375 |
if (!__isSmallInteger(numberOfArgs)) |
|
5376 |
goto bad; |
|
5377 |
nargs = __intVal(numberOfArgs); |
|
5378 |
argP = (OBJ *)(&a1); |
|
5379 |
for (i=1; i <= nargs; i++) { |
|
5380 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
5381 |
} |
|
5382 |
argP = (OBJ *)(&a1); |
|
5383 |
} else { |
|
5384 |
nargs = 0; |
|
5385 |
} |
|
5755 | 5386 |
} |
5387 |
switch (nargs) { |
|
14975 | 5388 |
case 0: |
5389 |
{ |
|
5390 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5391 |
RETURN ( _SEND0(self, aSelector, aClass, &ilc0)); |
|
5392 |
} |
|
5393 |
||
5394 |
case 1: |
|
5395 |
{ |
|
5396 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5397 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, argP[0])); |
|
5398 |
} |
|
5399 |
||
5400 |
case 2: |
|
5401 |
{ |
|
5402 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5403 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, argP[0], argP[1])); |
|
5404 |
} |
|
5405 |
||
5406 |
case 3: |
|
5407 |
{ |
|
5408 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5409 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, |
|
5410 |
argP[0], argP[1], argP[2])); |
|
5411 |
} |
|
5412 |
||
5413 |
case 4: |
|
5414 |
{ |
|
5415 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
5416 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, |
|
5417 |
argP[0], argP[1], argP[2], argP[3])); |
|
5418 |
} |
|
5419 |
||
5420 |
case 5: |
|
5421 |
{ |
|
5422 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
5423 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
5424 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5425 |
} |
|
5426 |
||
5427 |
case 6: |
|
5428 |
{ |
|
5429 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
5430 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
5431 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5])); |
|
5432 |
} |
|
5433 |
||
5434 |
case 7: |
|
5435 |
{ |
|
5436 |
static struct inlineCache ilc7 = __DUMMYILCSELF7(@line+1); |
|
5437 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
5438 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5439 |
argP[6])); |
|
5440 |
} |
|
5441 |
||
5442 |
case 8: |
|
5443 |
{ |
|
5444 |
static struct inlineCache ilc8 = __DUMMYILCSELF8(@line+1); |
|
5445 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
5446 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5447 |
argP[6], argP[7])); |
|
5448 |
} |
|
5449 |
||
5450 |
case 9: |
|
5451 |
{ |
|
5452 |
static struct inlineCache ilc9 = __DUMMYILCSELF9(@line+1); |
|
5453 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
5454 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5455 |
argP[6], argP[7], argP[8])); |
|
5456 |
} |
|
5457 |
||
5458 |
case 10: |
|
5459 |
{ |
|
5460 |
static struct inlineCache ilc10 = __DUMMYILCSELF10(@line+1); |
|
5461 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
5462 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5463 |
argP[6], argP[7], argP[8], argP[9])); |
|
5464 |
} |
|
5465 |
||
5466 |
case 11: |
|
5467 |
{ |
|
5468 |
static struct inlineCache ilc11 = __DUMMYILCSELF11(@line+1); |
|
5469 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
5470 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5471 |
argP[6], argP[7], argP[8], argP[9], argP[10])); |
|
5472 |
} |
|
5473 |
||
5474 |
case 12: |
|
5475 |
{ |
|
5476 |
static struct inlineCache ilc12 = __DUMMYILCSELF12(@line+1); |
|
5477 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
5478 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5479 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5480 |
argP[11])); |
|
5481 |
} |
|
5482 |
||
5483 |
case 13: |
|
5484 |
{ |
|
5485 |
static struct inlineCache ilc13 = __DUMMYILCSELF13(@line+1); |
|
5486 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
5487 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5488 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5489 |
argP[11], argP[12])); |
|
5490 |
} |
|
5491 |
||
5492 |
case 14: |
|
5493 |
{ |
|
5494 |
static struct inlineCache ilc14 = __DUMMYILCSELF14(@line+1); |
|
5495 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
5496 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5497 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5498 |
argP[11], argP[12], argP[13])); |
|
5499 |
} |
|
5500 |
||
5501 |
case 15: |
|
5502 |
{ |
|
5503 |
static struct inlineCache ilc15 = __DUMMYILCSELF15(@line+1); |
|
5504 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
5505 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5506 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5507 |
argP[11], argP[12], argP[13], argP[14])); |
|
5508 |
} |
|
5755 | 5509 |
|
5510 |
#ifdef _SEND16 |
|
14975 | 5511 |
case 16: |
5512 |
{ |
|
5513 |
static struct inlineCache ilc16 = __DUMMYILCSELF16(@line+1); |
|
5514 |
RETURN ( _SEND16(self, aSelector, aClass, &ilc15, |
|
5515 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5516 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5517 |
argP[11], argP[12], argP[13], argP[14], argP[15])); |
|
5518 |
} |
|
5755 | 5519 |
#endif |
5520 |
#ifdef _SEND17 |
|
14975 | 5521 |
case 17: |
5522 |
{ |
|
5523 |
static struct inlineCache ilc17 = __DUMMYILCSELF17(@line+1); |
|
5524 |
RETURN ( _SEND17(self, aSelector, aClass, &ilc15, |
|
5525 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5526 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5527 |
argP[11], argP[12], argP[13], argP[14], argP[15], argP[16])); |
|
5528 |
} |
|
5755 | 5529 |
#endif |
5530 |
||
5531 |
||
5532 |
} |
|
5533 |
bad:; |
|
5534 |
%}. |
|
5535 |
"/ arrive here, if bad number of arguments (too many) |
|
5536 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5537 |
||
5538 |
^ self primitiveFailed |
|
5539 |
! |
|
5540 |
||
5541 |
perform:aSelector with:arg |
|
5542 |
"send the one-arg-message aSelector to the receiver" |
|
5543 |
||
5544 |
%{ |
|
5545 |
REGISTER OBJ sel = aSelector; |
|
5546 |
||
5547 |
if (InterruptPending == nil) { |
|
14975 | 5548 |
struct inlineCache *pIlc; |
13416 | 5549 |
/* JV @ 2010-22-07: To improve performance I use 256 ILCs instead |
5550 |
of default 4. For details, see comment in perform: */ |
|
5551 |
||
5552 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF1(l) } |
|
5553 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5554 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5555 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5556 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5557 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5558 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5559 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5560 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5561 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5562 |
#define nilcs 256 |
|
5563 |
||
14975 | 5564 |
static struct { OBJ sel; struct inlineCache ilc; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
13416 | 5565 |
|
5566 |
#undef SEL_AND_ILC_INIT_1 |
|
5567 |
#undef SEL_AND_ILC_INIT_2 |
|
5568 |
#undef SEL_AND_ILC_INIT_4 |
|
5569 |
#undef SEL_AND_ILC_INIT_8 |
|
5570 |
#undef SEL_AND_ILC_INIT_16 |
|
5571 |
#undef SEL_AND_ILC_INIT_32 |
|
5572 |
#undef SEL_AND_ILC_INIT_64 |
|
5573 |
#undef SEL_AND_ILC_INIT_128 |
|
5574 |
#undef SEL_AND_ILC_INIT_256 |
|
5575 |
||
14975 | 5576 |
static flip = 0; |
5577 |
int i; |
|
5578 |
for (i = 0; i < nilcs; i++) { |
|
5579 |
if (sel == sel_and_ilc[i].sel) { |
|
5580 |
pIlc = &sel_and_ilc[i].ilc; |
|
5581 |
goto perform1_send_and_return; |
|
5582 |
} |
|
5583 |
} |
|
5584 |
/*printf("Object >> #perform: #%s with: arg --> no PIC found\n", __symbolVal(aSelector));*/ |
|
5585 |
pIlc = &sel_and_ilc[flip].ilc; |
|
5586 |
sel_and_ilc[flip].sel = sel; |
|
5587 |
flip = (flip + 1) % nilcs; |
|
5588 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5589 |
if (pIlc->ilc_poly) { |
|
5590 |
__flushPolyCache(pIlc->ilc_poly); |
|
5591 |
pIlc->ilc_poly = 0; |
|
5592 |
} |
|
13416 | 5593 |
perform1_send_and_return: |
14975 | 5594 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
5755 | 5595 |
} else { |
14975 | 5596 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
5597 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
5755 | 5598 |
} |
5599 |
%}. |
|
5600 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5601 |
||
5602 |
! |
|
5603 |
||
5604 |
perform:aSelector with:arg1 with:arg2 |
|
5605 |
"send the two-arg-message aSelector to the receiver" |
|
5606 |
||
5607 |
%{ |
|
13416 | 5608 |
REGISTER OBJ sel = aSelector; |
5755 | 5609 |
struct inlineCache *pIlc; |
5610 |
||
5611 |
if (InterruptPending == nil) { |
|
13416 | 5612 |
|
5613 |
/* JV @ 2010-22-07: To improve performance I use 256 ILCs instead |
|
5614 |
of default 4. For details, see comment in perform: */ |
|
5615 |
||
5616 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF2(l) } |
|
5617 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5618 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5619 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5620 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5621 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5622 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5623 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5624 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5625 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5626 |
#define nilcs 256 |
|
5627 |
||
14975 | 5628 |
static struct { OBJ sel; struct inlineCache ilc; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
13416 | 5629 |
|
5630 |
#undef SEL_AND_ILC_INIT_1 |
|
5631 |
#undef SEL_AND_ILC_INIT_2 |
|
5632 |
#undef SEL_AND_ILC_INIT_4 |
|
5633 |
#undef SEL_AND_ILC_INIT_8 |
|
5634 |
#undef SEL_AND_ILC_INIT_16 |
|
5635 |
#undef SEL_AND_ILC_INIT_32 |
|
5636 |
#undef SEL_AND_ILC_INIT_64 |
|
5637 |
#undef SEL_AND_ILC_INIT_128 |
|
5638 |
#undef SEL_AND_ILC_INIT_256 |
|
5639 |
||
14975 | 5640 |
static flip = 0; |
5641 |
int i; |
|
5642 |
for (i = 0; i < nilcs; i++) { |
|
5643 |
if (sel == sel_and_ilc[i].sel) { |
|
5644 |
pIlc = &sel_and_ilc[i].ilc; |
|
5645 |
goto perform2_send_and_return; |
|
5646 |
} |
|
5647 |
} |
|
5648 |
/*printf("Object >> #perform: #%s with: with: --> no PIC found\n", __symbolVal(aSelector));*/ |
|
5649 |
pIlc = &sel_and_ilc[flip].ilc; |
|
5650 |
sel_and_ilc[flip].sel = sel; |
|
5651 |
flip = (flip + 1) % nilcs; |
|
5652 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5653 |
if (pIlc->ilc_poly) { |
|
5654 |
__flushPolyCache(pIlc->ilc_poly); |
|
5655 |
pIlc->ilc_poly = 0; |
|
5656 |
} |
|
13416 | 5657 |
perform2_send_and_return: |
14975 | 5658 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
5755 | 5659 |
} else { |
14975 | 5660 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
5661 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, arg1, arg2)); |
|
5755 | 5662 |
} |
5663 |
%}. |
|
5664 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2) |
|
5665 |
||
5666 |
! |
|
5667 |
||
5668 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
|
5669 |
"send the three-arg-message aSelector to the receiver" |
|
5670 |
||
5671 |
%{ |
|
5672 |
struct inlineCache *pIlc; |
|
5673 |
static struct inlineCache ilc_0 = __ILCPERF3(@line); |
|
5674 |
static struct inlineCache ilc_1 = __ILCPERF3(@line); |
|
5675 |
static OBJ last_0 = nil; |
|
5676 |
static OBJ last_1 = nil; |
|
5677 |
static flip = 0; |
|
5678 |
||
5679 |
if (InterruptPending == nil) { |
|
14975 | 5680 |
if (aSelector != last_0) { |
5681 |
if (aSelector != last_1) { |
|
5682 |
if (flip) { |
|
5683 |
pIlc = &ilc_0; |
|
5684 |
flip = 0; |
|
5685 |
last_0 = aSelector; |
|
5686 |
} else { |
|
5687 |
pIlc = &ilc_1; |
|
5688 |
flip = 1; |
|
5689 |
last_1 = aSelector; |
|
5690 |
} |
|
5691 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5692 |
if (pIlc->ilc_poly) { |
|
5693 |
__flushPolyCache(pIlc->ilc_poly); |
|
5694 |
pIlc->ilc_poly = 0; |
|
5695 |
} |
|
5696 |
} else { |
|
5697 |
pIlc = &ilc_1; |
|
5698 |
} |
|
5699 |
} else { |
|
5700 |
pIlc = &ilc_0; |
|
5701 |
} |
|
5702 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
|
5755 | 5703 |
} else { |
14975 | 5704 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
5705 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, arg1, arg2, arg3)); |
|
5755 | 5706 |
} |
5707 |
%}. |
|
5708 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3) |
|
5709 |
||
5710 |
! |
|
5711 |
||
5712 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
5713 |
"send the four-arg-message aSelector to the receiver" |
|
5714 |
||
5715 |
%{ |
|
5716 |
struct inlineCache *pIlc; |
|
5717 |
static struct inlineCache ilc_0 = __ILCPERF4(@line); |
|
5718 |
static struct inlineCache ilc_1 = __ILCPERF4(@line); |
|
5719 |
static OBJ last_0 = nil; |
|
5720 |
static OBJ last_1 = nil; |
|
5721 |
static flip = 0; |
|
5722 |
||
5723 |
if (InterruptPending == nil) { |
|
14975 | 5724 |
if (aSelector != last_0) { |
5725 |
if (aSelector != last_1) { |
|
5726 |
if (flip) { |
|
5727 |
pIlc = &ilc_0; |
|
5728 |
flip = 0; |
|
5729 |
last_0 = aSelector; |
|
5730 |
} else { |
|
5731 |
pIlc = &ilc_1; |
|
5732 |
flip = 1; |
|
5733 |
last_1 = aSelector; |
|
5734 |
} |
|
5735 |
pIlc->ilc_func = __SEND4ADDR__; |
|
5736 |
if (pIlc->ilc_poly) { |
|
5737 |
__flushPolyCache(pIlc->ilc_poly); |
|
5738 |
pIlc->ilc_poly = 0; |
|
5739 |
} |
|
5740 |
} else { |
|
5741 |
pIlc = &ilc_1; |
|
5742 |
} |
|
5743 |
} else { |
|
5744 |
pIlc = &ilc_0; |
|
5745 |
} |
|
5746 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5747 |
arg1, arg2, arg3, arg4) ); |
|
5755 | 5748 |
} else { |
14975 | 5749 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
5750 |
RETURN (_SEND4(self, aSelector, nil, &ilc4, |
|
5751 |
arg1, arg2, arg3, arg4)); |
|
5755 | 5752 |
} |
5753 |
%}. |
|
5754 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
5755 |
||
5756 |
! |
|
5757 |
||
5758 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
5759 |
"send the five-arg-message aSelector to the receiver" |
|
5760 |
||
5761 |
%{ |
|
5762 |
struct inlineCache *pIlc; |
|
5763 |
static struct inlineCache ilc_0 = __ILCPERF5(@line); |
|
5764 |
static struct inlineCache ilc_1 = __ILCPERF5(@line); |
|
5765 |
static OBJ last_0 = nil; |
|
5766 |
static OBJ last_1 = nil; |
|
5767 |
static flip = 0; |
|
5768 |
||
5769 |
if (InterruptPending == nil) { |
|
14975 | 5770 |
if (aSelector != last_0) { |
5771 |
if (aSelector != last_1) { |
|
5772 |
if (flip) { |
|
5773 |
pIlc = &ilc_0; |
|
5774 |
flip = 0; |
|
5775 |
last_0 = aSelector; |
|
5776 |
} else { |
|
5777 |
pIlc = &ilc_1; |
|
5778 |
flip = 1; |
|
5779 |
last_1 = aSelector; |
|
5780 |
} |
|
5781 |
pIlc->ilc_func = __SEND5ADDR__; |
|
5782 |
if (pIlc->ilc_poly) { |
|
5783 |
__flushPolyCache(pIlc->ilc_poly); |
|
5784 |
pIlc->ilc_poly = 0; |
|
5785 |
} |
|
5786 |
} else { |
|
5787 |
pIlc = &ilc_1; |
|
5788 |
} |
|
5789 |
} else { |
|
5790 |
pIlc = &ilc_0; |
|
5791 |
} |
|
5792 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5793 |
arg1, arg2, arg3, arg4, arg5) ); |
|
5755 | 5794 |
} else { |
14975 | 5795 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
5796 |
RETURN (_SEND5(self, aSelector, nil, &ilc5, |
|
5797 |
arg1, arg2, arg3, arg4, arg5)); |
|
5755 | 5798 |
} |
5799 |
%}. |
|
5800 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
14975 | 5801 |
with:arg5) |
5755 | 5802 |
|
5803 |
! |
|
5804 |
||
5805 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
|
5806 |
"send the six-arg-message aSelector to the receiver" |
|
5807 |
||
5808 |
%{ |
|
5809 |
struct inlineCache *pIlc; |
|
5810 |
static struct inlineCache ilc_0 = __ILCPERF6(@line); |
|
5811 |
static struct inlineCache ilc_1 = __ILCPERF6(@line); |
|
5812 |
static OBJ last_0 = nil; |
|
5813 |
static OBJ last_1 = nil; |
|
5814 |
static flip = 0; |
|
5815 |
||
5816 |
if (InterruptPending == nil) { |
|
14975 | 5817 |
if (aSelector != last_0) { |
5818 |
if (aSelector != last_1) { |
|
5819 |
if (flip) { |
|
5820 |
pIlc = &ilc_0; |
|
5821 |
flip = 0; |
|
5822 |
last_0 = aSelector; |
|
5823 |
} else { |
|
5824 |
pIlc = &ilc_1; |
|
5825 |
flip = 1; |
|
5826 |
last_1 = aSelector; |
|
5827 |
} |
|
5828 |
pIlc->ilc_func = __SEND6ADDR__; |
|
5829 |
if (pIlc->ilc_poly) { |
|
5830 |
__flushPolyCache(pIlc->ilc_poly); |
|
5831 |
pIlc->ilc_poly = 0; |
|
5832 |
} |
|
5833 |
} else { |
|
5834 |
pIlc = &ilc_1; |
|
5835 |
} |
|
5836 |
} else { |
|
5837 |
pIlc = &ilc_0; |
|
5838 |
} |
|
5839 |
||
5840 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5841 |
arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
5755 | 5842 |
} else { |
14975 | 5843 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
5844 |
RETURN (_SEND6(self, aSelector, nil, &ilc6, |
|
5845 |
arg1, arg2, arg3, arg4, arg5, arg6)); |
|
5755 | 5846 |
} |
5847 |
%}. |
|
5848 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
14975 | 5849 |
with:arg5 with:arg6) |
5755 | 5850 |
|
5851 |
! |
|
5852 |
||
5853 |
perform:aSelector withArguments:argArray |
|
10460 | 5854 |
"send the message aSelector with all args taken from argArray |
5755 | 5855 |
to the receiver." |
5856 |
||
5857 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
5858 |
||
5859 |
%{ |
|
5860 |
REGISTER OBJ *argP; |
|
5861 |
int nargs; |
|
5862 |
OBJ l; |
|
5863 |
||
8934 | 5864 |
if (__isArrayLike(argArray)) { |
14975 | 5865 |
nargs = __arraySize(argArray); |
5866 |
argP = __arrayVal(argArray); |
|
5755 | 5867 |
} else { |
14975 | 5868 |
if (__isNonNilObject(argArray)) { |
5869 |
static struct inlineCache ilcSize = __ILC0(@line); |
|
5870 |
int i; |
|
5871 |
||
5872 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5873 |
if (!__isSmallInteger(numberOfArgs)) |
|
5874 |
goto bad; |
|
5875 |
nargs = __intVal(numberOfArgs); |
|
5876 |
argP = (OBJ *)(&a1); |
|
5877 |
for (i=1; i <= nargs; i++) { |
|
5878 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
5879 |
} |
|
5880 |
argP = (OBJ *)(&a1); |
|
5881 |
} else { |
|
5882 |
nargs = 0; |
|
5883 |
} |
|
5755 | 5884 |
} |
5885 |
switch (nargs) { |
|
14975 | 5886 |
case 0: |
5887 |
if (InterruptPending == nil) { |
|
5888 |
static OBJ last0_0 = nil; static struct inlineCache ilc0_0 = __ILCPERF0(@line); |
|
5889 |
static OBJ last0_1 = nil; static struct inlineCache ilc0_1 = __ILCPERF0(@line); |
|
5890 |
static OBJ last0_2 = nil; static struct inlineCache ilc0_2 = __ILCPERF0(@line); |
|
5891 |
static OBJ last0_3 = nil; static struct inlineCache ilc0_3 = __ILCPERF0(@line); |
|
5892 |
static int flip0 = 0; |
|
5893 |
struct inlineCache *pIlc; |
|
5894 |
||
5895 |
if (aSelector == last0_0) { |
|
5896 |
pIlc = &ilc0_0; |
|
5897 |
} else if (aSelector == last0_1) { |
|
5898 |
pIlc = &ilc0_1; |
|
5899 |
} else if (aSelector == last0_2) { |
|
5900 |
pIlc = &ilc0_2; |
|
5901 |
} else if (aSelector == last0_3) { |
|
5902 |
pIlc = &ilc0_3; |
|
5903 |
} else { |
|
5904 |
if (flip0 == 0) { |
|
5905 |
pIlc = &ilc0_0; |
|
5906 |
flip0 = 1; |
|
5907 |
last0_0 = aSelector; |
|
5908 |
} else if (flip0 == 1) { |
|
5909 |
pIlc = &ilc0_1; |
|
5910 |
flip0 = 2; |
|
5911 |
last0_1 = aSelector; |
|
5912 |
} else if (flip0 == 2) { |
|
5913 |
pIlc = &ilc0_2; |
|
5914 |
flip0 = 3; |
|
5915 |
last0_2 = aSelector; |
|
5916 |
} else { |
|
5917 |
pIlc = &ilc0_3; |
|
5918 |
flip0 = 0; |
|
5919 |
last0_3 = aSelector; |
|
5920 |
} |
|
5921 |
||
5922 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5923 |
if (pIlc->ilc_poly) { |
|
5924 |
__flushPolyCache(pIlc->ilc_poly); |
|
5925 |
pIlc->ilc_poly = 0; |
|
5926 |
} |
|
5927 |
} |
|
5928 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc)); |
|
5929 |
} else { |
|
5930 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5931 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5932 |
} |
|
5933 |
||
5934 |
case 1: |
|
5935 |
if (InterruptPending == nil) { |
|
5936 |
static OBJ last1_0 = nil; static struct inlineCache ilc1_0 = __ILCPERF1(@line); |
|
5937 |
static OBJ last1_1 = nil; static struct inlineCache ilc1_1 = __ILCPERF1(@line); |
|
5938 |
static OBJ last1_2 = nil; static struct inlineCache ilc1_2 = __ILCPERF1(@line); |
|
5939 |
static OBJ last1_3 = nil; static struct inlineCache ilc1_3 = __ILCPERF1(@line); |
|
5940 |
static int flip1 = 0; |
|
5941 |
struct inlineCache *pIlc; |
|
5942 |
||
5943 |
if (aSelector == last1_0) { |
|
5944 |
pIlc = &ilc1_0; |
|
5945 |
} else if (aSelector == last1_1) { |
|
5946 |
pIlc = &ilc1_1; |
|
5947 |
} else if (aSelector == last1_2) { |
|
5948 |
pIlc = &ilc1_2; |
|
5949 |
} else if (aSelector == last1_3) { |
|
5950 |
pIlc = &ilc1_3; |
|
5951 |
} else { |
|
5952 |
if (flip1 == 0) { |
|
5953 |
pIlc = &ilc1_0; |
|
5954 |
flip1 = 1; |
|
5955 |
last1_0 = aSelector; |
|
5956 |
} else if (flip1 == 1) { |
|
5957 |
pIlc = &ilc1_1; |
|
5958 |
flip1 = 2; |
|
5959 |
last1_1 = aSelector; |
|
5960 |
} else if (flip1 == 2) { |
|
5961 |
pIlc = &ilc1_2; |
|
5962 |
flip1 = 3; |
|
5963 |
last1_2 = aSelector; |
|
5964 |
} else { |
|
5965 |
pIlc = &ilc1_3; |
|
5966 |
flip1 = 0; |
|
5967 |
last1_3 = aSelector; |
|
5968 |
} |
|
5969 |
||
5970 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5971 |
if (pIlc->ilc_poly) { |
|
5972 |
__flushPolyCache(pIlc->ilc_poly); |
|
5973 |
pIlc->ilc_poly = 0; |
|
5974 |
} |
|
5975 |
} |
|
5976 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0])); |
|
5977 |
} else { |
|
5978 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5979 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, argP[0])); |
|
5980 |
} |
|
5981 |
||
5982 |
case 2: |
|
5983 |
if (InterruptPending == nil) { |
|
5984 |
static OBJ last2_0 = nil; static struct inlineCache ilc2_0 = __ILCPERF2(@line); |
|
5985 |
static OBJ last2_1 = nil; static struct inlineCache ilc2_1 = __ILCPERF2(@line); |
|
5986 |
static int flip2 = 0; |
|
5987 |
struct inlineCache *pIlc; |
|
5988 |
||
5989 |
if (aSelector == last2_0) { |
|
5990 |
pIlc = &ilc2_0; |
|
5991 |
} else if (aSelector == last2_1) { |
|
5992 |
pIlc = &ilc2_1; |
|
5993 |
} else { |
|
5994 |
if (flip2 == 0) { |
|
5995 |
pIlc = &ilc2_0; |
|
5996 |
flip2 = 1; |
|
5997 |
last2_0 = aSelector; |
|
5998 |
} else { |
|
5999 |
pIlc = &ilc2_1; |
|
6000 |
flip2 = 0; |
|
6001 |
last2_1 = aSelector; |
|
6002 |
} |
|
6003 |
||
6004 |
pIlc->ilc_func = __SEND2ADDR__; |
|
6005 |
if (pIlc->ilc_poly) { |
|
6006 |
__flushPolyCache(pIlc->ilc_poly); |
|
6007 |
pIlc->ilc_poly = 0; |
|
6008 |
} |
|
6009 |
} |
|
6010 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1])); |
|
6011 |
} else { |
|
6012 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
6013 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, argP[0], argP[1])); |
|
6014 |
} |
|
6015 |
||
6016 |
case 3: |
|
6017 |
if (InterruptPending == nil) { |
|
6018 |
static OBJ last3_0 = nil; static struct inlineCache ilc3_0 = __ILCPERF3(@line); |
|
6019 |
static OBJ last3_1 = nil; static struct inlineCache ilc3_1 = __ILCPERF3(@line); |
|
6020 |
static int flip3 = 0; |
|
6021 |
struct inlineCache *pIlc; |
|
6022 |
||
6023 |
if (aSelector == last3_0) { |
|
6024 |
pIlc = &ilc3_0; |
|
6025 |
} else if (aSelector == last3_1) { |
|
6026 |
pIlc = &ilc3_1; |
|
6027 |
} else { |
|
6028 |
if (flip3 == 0) { |
|
6029 |
pIlc = &ilc3_0; |
|
6030 |
flip3 = 1; |
|
6031 |
last3_0 = aSelector; |
|
6032 |
} else { |
|
6033 |
pIlc = &ilc3_1; |
|
6034 |
flip3 = 0; |
|
6035 |
last3_1 = aSelector; |
|
6036 |
} |
|
6037 |
||
6038 |
pIlc->ilc_func = __SEND3ADDR__; |
|
6039 |
if (pIlc->ilc_poly) { |
|
6040 |
__flushPolyCache(pIlc->ilc_poly); |
|
6041 |
pIlc->ilc_poly = 0; |
|
6042 |
} |
|
6043 |
} |
|
6044 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1], argP[2])); |
|
6045 |
} else { |
|
6046 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
6047 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, argP[0], argP[1], argP[2])); |
|
6048 |
} |
|
6049 |
||
6050 |
case 4: |
|
6051 |
{ |
|
6052 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(@line); |
|
6053 |
||
6054 |
if ((InterruptPending != nil) || (aSelector != last4)) { |
|
6055 |
ilc4.ilc_func = __SEND4ADDR__; |
|
6056 |
if (ilc4.ilc_poly) { |
|
6057 |
__flushPolyCache(ilc4.ilc_poly); |
|
6058 |
ilc4.ilc_poly = 0; |
|
6059 |
} |
|
6060 |
last4 = aSelector; |
|
6061 |
} |
|
6062 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
|
6063 |
argP[0], argP[1], argP[2], argP[3])); |
|
6064 |
} |
|
6065 |
||
6066 |
case 5: |
|
6067 |
{ |
|
6068 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(@line); |
|
6069 |
||
6070 |
if ((InterruptPending != nil) || (aSelector != last5)) { |
|
6071 |
ilc5.ilc_func = __SEND5ADDR__; |
|
6072 |
if (ilc5.ilc_poly) { |
|
6073 |
__flushPolyCache(ilc5.ilc_poly); |
|
6074 |
ilc5.ilc_poly = 0; |
|
6075 |
} |
|
6076 |
last5 = aSelector; |
|
6077 |
} |
|
6078 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
|
6079 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
6080 |
} |
|
6081 |
||
6082 |
case 6: |
|
6083 |
{ |
|
6084 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(@line); |
|
6085 |
||
6086 |
if ((InterruptPending != nil) || (aSelector != last6)) { |
|
6087 |
ilc6.ilc_func = __SEND6ADDR__; |
|
6088 |
if (ilc6.ilc_poly) { |
|
6089 |
__flushPolyCache(ilc6.ilc_poly); |
|
6090 |
ilc6.ilc_poly = 0; |
|
6091 |
} |
|
6092 |
last6 = aSelector; |
|
6093 |
} |
|
6094 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
|
6095 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6096 |
argP[5])); |
|
6097 |
} |
|
6098 |
||
6099 |
case 7: |
|
6100 |
{ |
|
6101 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(@line); |
|
6102 |
||
6103 |
if ((InterruptPending != nil) || (aSelector != last7)) { |
|
6104 |
ilc7.ilc_func = __SEND7ADDR__; |
|
6105 |
if (ilc7.ilc_poly) { |
|
6106 |
__flushPolyCache(ilc7.ilc_poly); |
|
6107 |
ilc7.ilc_poly = 0; |
|
6108 |
} |
|
6109 |
last7 = aSelector; |
|
6110 |
} |
|
6111 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
|
6112 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6113 |
argP[5], argP[6])); |
|
6114 |
} |
|
6115 |
||
6116 |
case 8: |
|
6117 |
{ |
|
6118 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(@line); |
|
6119 |
||
6120 |
if ((InterruptPending != nil) || (aSelector != last8)) { |
|
6121 |
ilc8.ilc_func = __SEND8ADDR__; |
|
6122 |
if (ilc8.ilc_poly) { |
|
6123 |
__flushPolyCache(ilc8.ilc_poly); |
|
6124 |
ilc8.ilc_poly = 0; |
|
6125 |
} |
|
6126 |
last8 = aSelector; |
|
6127 |
} |
|
6128 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
|
6129 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6130 |
argP[5], argP[6], argP[7])); |
|
6131 |
} |
|
6132 |
||
6133 |
case 9: |
|
6134 |
{ |
|
6135 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(@line); |
|
6136 |
||
6137 |
if ((InterruptPending != nil) || (aSelector != last9)) { |
|
6138 |
ilc9.ilc_func = __SEND9ADDR__; |
|
6139 |
if (ilc9.ilc_poly) { |
|
6140 |
__flushPolyCache(ilc9.ilc_poly); |
|
6141 |
ilc9.ilc_poly = 0; |
|
6142 |
} |
|
6143 |
last9 = aSelector; |
|
6144 |
} |
|
6145 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
|
6146 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6147 |
argP[5], argP[6], argP[7], argP[8])); |
|
6148 |
} |
|
6149 |
||
6150 |
case 10: |
|
6151 |
{ |
|
6152 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(@line); |
|
6153 |
||
6154 |
if ((InterruptPending != nil) || (aSelector != last10)) { |
|
6155 |
ilc10.ilc_func = __SEND10ADDR__; |
|
6156 |
if (ilc10.ilc_poly) { |
|
6157 |
__flushPolyCache(ilc10.ilc_poly); |
|
6158 |
ilc10.ilc_poly = 0; |
|
6159 |
} |
|
6160 |
last10 = aSelector; |
|
6161 |
} |
|
6162 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
|
6163 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6164 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
6165 |
} |
|
6166 |
||
6167 |
case 11: |
|
6168 |
{ |
|
6169 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(@line); |
|
6170 |
||
6171 |
if ((InterruptPending != nil) || (aSelector != last11)) { |
|
6172 |
ilc11.ilc_func = __SEND11ADDR__; |
|
6173 |
if (ilc11.ilc_poly) { |
|
6174 |
__flushPolyCache(ilc11.ilc_poly); |
|
6175 |
ilc11.ilc_poly = 0; |
|
6176 |
} |
|
6177 |
last11 = aSelector; |
|
6178 |
} |
|
6179 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
|
6180 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6181 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6182 |
argP[10])); |
|
6183 |
} |
|
6184 |
||
6185 |
case 12: |
|
6186 |
{ |
|
6187 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(@line); |
|
6188 |
||
6189 |
if ((InterruptPending != nil) || (aSelector != last12)) { |
|
6190 |
ilc12.ilc_func = __SEND12ADDR__; |
|
6191 |
if (ilc12.ilc_poly) { |
|
6192 |
__flushPolyCache(ilc12.ilc_poly); |
|
6193 |
ilc12.ilc_poly = 0; |
|
6194 |
} |
|
6195 |
last12 = aSelector; |
|
6196 |
} |
|
6197 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
|
6198 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6199 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6200 |
argP[10], argP[11])); |
|
6201 |
} |
|
6202 |
||
6203 |
case 13: |
|
6204 |
{ |
|
6205 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(@line); |
|
6206 |
||
6207 |
if ((InterruptPending != nil) || (aSelector != last13)) { |
|
6208 |
ilc13.ilc_func = __SEND13ADDR__; |
|
6209 |
if (ilc13.ilc_poly) { |
|
6210 |
__flushPolyCache(ilc13.ilc_poly); |
|
6211 |
ilc13.ilc_poly = 0; |
|
6212 |
} |
|
6213 |
last13 = aSelector; |
|
6214 |
} |
|
6215 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
|
6216 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6217 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6218 |
argP[10], argP[11], argP[12])); |
|
6219 |
} |
|
6220 |
||
6221 |
case 14: |
|
6222 |
{ |
|
6223 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(@line); |
|
6224 |
||
6225 |
if ((InterruptPending != nil) || (aSelector != last14)) { |
|
6226 |
ilc14.ilc_func = __SEND14ADDR__; |
|
6227 |
if (ilc14.ilc_poly) { |
|
6228 |
__flushPolyCache(ilc14.ilc_poly); |
|
6229 |
ilc14.ilc_poly = 0; |
|
6230 |
} |
|
6231 |
last14 = aSelector; |
|
6232 |
} |
|
6233 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
|
6234 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6235 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6236 |
argP[10], argP[11], argP[12], argP[13])); |
|
6237 |
} |
|
6238 |
||
6239 |
case 15: |
|
6240 |
{ |
|
6241 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(@line); |
|
6242 |
||
6243 |
if ((InterruptPending != nil) || (aSelector != last15)) { |
|
6244 |
ilc15.ilc_func = __SEND15ADDR__; |
|
6245 |
if (ilc15.ilc_poly) { |
|
6246 |
__flushPolyCache(ilc15.ilc_poly); |
|
6247 |
ilc15.ilc_poly = 0; |
|
6248 |
} |
|
6249 |
last15 = aSelector; |
|
6250 |
} |
|
6251 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
|
6252 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6253 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6254 |
argP[10], argP[11], argP[12], argP[13], |
|
6255 |
argP[14])); |
|
6256 |
} |
|
5755 | 6257 |
} |
6258 |
bad:; |
|
6259 |
%}. |
|
6260 |
||
6261 |
"/ arrive here, if bad number of arguments (too many) |
|
6262 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
6263 |
||
6264 |
^ self primitiveFailed |
|
6265 |
! |
|
6266 |
||
6316 | 6267 |
perform:aSelector withOptionalArgument:arg |
6268 |
"send aSelector-message to the receiver. |
|
6318 | 6269 |
If the message expects an argument, pass arg." |
6316 | 6270 |
|
6271 |
aSelector numArgs == 1 ifTrue:[ |
|
14975 | 6272 |
^ self perform:aSelector with:arg |
6316 | 6273 |
]. |
6274 |
^ self perform:aSelector |
|
6319 | 6275 |
|
6276 |
" |
|
6277 |
|rec sel| |
|
6278 |
||
6279 |
rec := -1. |
|
6280 |
sel := #abs. |
|
6281 |
rec perform:sel withOptionalArgument:2. |
|
6282 |
||
6283 |
sel := #max:. |
|
6284 |
rec perform:sel withOptionalArgument:2. |
|
6285 |
" |
|
6316 | 6286 |
! |
6287 |
||
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6288 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6289 |
"send aSelector-message to the receiver. |
6728 | 6290 |
Depending on the number of arguments the message expects, |
6291 |
pass either none, 1, or 2 arguments." |
|
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6292 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6293 |
|numArgs| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6294 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6295 |
numArgs := aSelector numArgs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6296 |
numArgs == 0 ifTrue:[ |
14975 | 6297 |
^ self perform:aSelector |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6298 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6299 |
numArgs == 1 ifTrue:[ |
14975 | 6300 |
^ self perform:aSelector with:optionalArg1 |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6301 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6302 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6303 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6304 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6305 |
|rec sel| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6306 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6307 |
rec := -1. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6308 |
sel := #abs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6309 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6310 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6311 |
sel := #max:. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6312 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6313 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6314 |
! |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6315 |
|
6728 | 6316 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 |
6317 |
"send aSelector-message to the receiver. |
|
6318 |
Depending on the number of arguments the message expects, |
|
6319 |
pass either none, 1, 2 or 3 arguments." |
|
6320 |
||
6321 |
|numArgs| |
|
6322 |
||
6323 |
numArgs := aSelector numArgs. |
|
6324 |
numArgs == 0 ifTrue:[ |
|
14975 | 6325 |
^ self perform:aSelector |
6728 | 6326 |
]. |
6327 |
numArgs == 1 ifTrue:[ |
|
14975 | 6328 |
^ self perform:aSelector with:optionalArg1 |
6728 | 6329 |
]. |
6330 |
numArgs == 2 ifTrue:[ |
|
14975 | 6331 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6728 | 6332 |
]. |
6333 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3. |
|
6334 |
||
6335 |
" |
|
6336 |
|rec sel| |
|
6337 |
||
6338 |
rec := -1. |
|
6339 |
sel := #abs. |
|
6340 |
rec perform:sel withOptionalArgument:2. |
|
6341 |
||
6342 |
sel := #max:. |
|
6343 |
rec perform:sel withOptionalArgument:2. |
|
6344 |
" |
|
6345 |
! |
|
6346 |
||
6764 | 6347 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 and:optionalArg4 |
6348 |
"send aSelector-message to the receiver. |
|
6349 |
Depending on the number of arguments the message expects, |
|
6350 |
pass either none, 1, 2, 3 or 4 arguments." |
|
6351 |
||
6352 |
|numArgs| |
|
6353 |
||
6354 |
numArgs := aSelector numArgs. |
|
6355 |
numArgs == 0 ifTrue:[ |
|
14975 | 6356 |
^ self perform:aSelector |
6764 | 6357 |
]. |
6358 |
numArgs == 1 ifTrue:[ |
|
14975 | 6359 |
^ self perform:aSelector with:optionalArg1 |
6764 | 6360 |
]. |
6361 |
numArgs == 2 ifTrue:[ |
|
14975 | 6362 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6764 | 6363 |
]. |
6364 |
numArgs == 3 ifTrue:[ |
|
14975 | 6365 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 |
6764 | 6366 |
]. |
6367 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 with:optionalArg4. |
|
6368 |
||
6369 |
" |
|
6370 |
|rec sel| |
|
6371 |
||
6372 |
rec := -1. |
|
6373 |
sel := #abs. |
|
6374 |
rec perform:sel withOptionalArgument:2. |
|
6375 |
||
6376 |
sel := #max:. |
|
6377 |
rec perform:sel withOptionalArgument:2. |
|
6378 |
" |
|
6379 |
! |
|
6380 |
||
5755 | 6381 |
performMethod:aMethod |
6382 |
"invoke aMethod on the receiver. |
|
6383 |
The method should be a zero-argument method. |
|
6384 |
This is a non-object-oriented entry, applying a method |
|
6385 |
in a functional way on a receiver. |
|
6386 |
Warning: |
|
14975 | 6387 |
Take care for the method to be appropriate for the |
6388 |
receiver - no checking is done by the VM." |
|
5755 | 6389 |
|
6390 |
^ aMethod valueWithReceiver:self arguments:#() |
|
6391 |
||
6392 |
" |
|
6393 |
|mthd| |
|
6394 |
||
6395 |
mthd := SmallInteger compiledMethodAt:#negated. |
|
6396 |
Transcript showCR:(1 performMethod:mthd) |
|
6397 |
" |
|
6398 |
||
6399 |
"BAD USE example: |
|
6400 |
||
6401 |
|mthd| |
|
6402 |
||
6403 |
mthd := Point compiledMethodAt:#x. |
|
6404 |
Transcript showCR:((1->2) performMethod:mthd) |
|
6405 |
" |
|
6406 |
||
6407 |
"Modified: 31.7.1997 / 17:41:50 / cg" |
|
6408 |
! |
|
6409 |
||
6410 |
performMethod:aMethod arguments:argumentArray |
|
6411 |
"invoke aMethod on the receiver, passing an argumentArray. |
|
6412 |
The size of the argumentArray should match the number of args |
|
6413 |
expected by the method. |
|
6414 |
This is a non-object-oriented entry, applying a method |
|
6415 |
in a functional way on a receiver. |
|
6416 |
Warning: |
|
14975 | 6417 |
Take care for the method to be appropriate for the |
6418 |
receiver - no checking is done by the VM." |
|
5755 | 6419 |
|
6420 |
^ aMethod valueWithReceiver:self arguments:argumentArray |
|
6421 |
||
6422 |
" |
|
6423 |
|mthd| |
|
6424 |
||
6425 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6426 |
Transcript showCR:(1 performMethod:mthd arguments:#(2)) |
|
6427 |
" |
|
6428 |
||
6429 |
"Created: 31.7.1997 / 17:46:31 / cg" |
|
6430 |
! |
|
6431 |
||
6432 |
performMethod:aMethod with:arg |
|
6433 |
"invoke aMethod on the receiver, passing an argument. |
|
6434 |
The method should be a one-argument method. |
|
6435 |
This is a non-object-oriented entry, applying a method |
|
6436 |
in a functional way on a receiver. |
|
6437 |
Warning: |
|
14975 | 6438 |
Take care for the method to be appropriate for the |
6439 |
receiver - no checking is done by the VM." |
|
5755 | 6440 |
|
6441 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg) |
|
6442 |
||
6443 |
" |
|
6444 |
|mthd| |
|
6445 |
||
6446 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6447 |
Transcript showCR:(1 performMethod:mthd with:2) |
|
6448 |
" |
|
6449 |
||
6450 |
"Modified: 31.7.1997 / 17:42:32 / cg" |
|
6451 |
! |
|
6452 |
||
6453 |
performMethod:aMethod with:arg1 with:arg2 |
|
6454 |
"invoke aMethod on the receiver, passing two arguments. |
|
6455 |
The method should be a two-argument method. |
|
6456 |
This is a non-object-oriented entry, applying a method |
|
6457 |
in a functional way on a receiver. |
|
6458 |
Warning: |
|
14975 | 6459 |
Take care for the method to be appropriate for the |
6460 |
receiver - no checking is done by the VM." |
|
5755 | 6461 |
|
6462 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) |
|
6463 |
||
6464 |
" |
|
6465 |
|mthd arr| |
|
6466 |
||
6467 |
arr := Array new:1. |
|
6468 |
mthd := Array compiledMethodAt:#basicAt:put:. |
|
6469 |
arr performMethod:mthd with:1 with:'foo'. |
|
6470 |
Transcript showCR:arr |
|
6471 |
" |
|
6472 |
||
6473 |
"Modified: 31.7.1997 / 17:44:54 / cg" |
|
6474 |
! |
|
6475 |
||
6476 |
performMethod:aMethod with:arg1 with:arg2 with:arg3 |
|
6477 |
"invoke aMethod on the receiver, passing three arguments. |
|
6478 |
The method should be a three-argument method. |
|
6479 |
This is a non-object-oriented entry, applying a method |
|
6480 |
in a functional way on a receiver. |
|
6481 |
Warning: |
|
14975 | 6482 |
Take care for the method to be appropriate for the |
6483 |
receiver - no checking is done by the VM." |
|
5755 | 6484 |
|
6485 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3) |
|
6486 |
||
6487 |
"Created: 31.7.1997 / 17:45:20 / cg" |
|
6488 |
! ! |
|
6489 |
||
10834 | 6490 |
!Object methodsFor:'object persistency'! |
6491 |
||
6492 |
elementDescriptorFor:anAspectSymbol |
|
6493 |
"support for persistency: |
|
6494 |
answer a collection of associations containing the |
|
6495 |
objects state to be encoded for aspect. |
|
6496 |
Association key is the instance variable name or access selector, |
|
6497 |
association value is the contents of the instance variable. |
|
6498 |
||
6499 |
The default is to return the contents of all non-nil instance variables" |
|
6500 |
||
6501 |
|ret| |
|
6502 |
||
6503 |
ret := 0. |
|
6504 |
anAspectSymbol notNil ifTrue:[ |
|
14975 | 6505 |
ret := self perform:anAspectSymbol ifNotUnderstood:[0]. |
10834 | 6506 |
]. |
6507 |
ret == 0 ifTrue:[ |
|
14975 | 6508 |
^ self elementDescriptorForNonNilInstanceVariables |
10834 | 6509 |
]. |
6510 |
^ ret. |
|
6511 |
! |
|
6512 |
||
6513 |
elementDescriptorForInstanceVariables |
|
6514 |
"return all instance variables for visiting/encoding" |
|
6515 |
||
6516 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
|
6517 |
||
6518 |
" |
|
6519 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
6520 |
Dictionary new elementDescriptorForInstanceVariables |
|
6521 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
6522 |
" |
|
6523 |
! |
|
6524 |
||
6525 |
elementDescriptorForInstanceVariablesMatching:aBlock |
|
6526 |
"return all instance variables which conform to aBlock, for encoding/visiting. |
|
6527 |
Indexed vars are all included." |
|
6528 |
||
6529 |
|instVarNames theClass children |
|
6530 |
instSize "{ Class: SmallInteger }" |
|
6531 |
varSize "{ Class: SmallInteger }"| |
|
6532 |
||
6533 |
theClass := self class. |
|
6534 |
||
6535 |
instSize := theClass instSize. |
|
6536 |
varSize := theClass isVariable ifTrue:[self basicSize] ifFalse:[0]. |
|
6537 |
children := OrderedCollection new:(instSize + varSize). |
|
6538 |
||
6539 |
instVarNames := theClass allInstVarNames. |
|
6540 |
1 to:instSize do:[:i | |var| |
|
14975 | 6541 |
var := self instVarAt:i. |
6542 |
(aBlock value:var) ifTrue:[ |
|
6543 |
children add:((instVarNames at:i) -> var) |
|
6544 |
] |
|
10834 | 6545 |
]. |
6546 |
||
6547 |
varSize ~~ 0 ifTrue:[ |
|
14975 | 6548 |
1 to:varSize do:[:i | |
6549 |
children add:(i -> (self basicAt:i)) |
|
6550 |
] |
|
10834 | 6551 |
]. |
6552 |
||
6553 |
^ children. |
|
6554 |
||
6555 |
" |
|
6556 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
6557 |
Dictionary new elementDescriptorForInstanceVariables |
|
6558 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
6559 |
" |
|
6560 |
! |
|
6561 |
||
6562 |
elementDescriptorForNonNilInstanceVariables |
|
6563 |
"return all non-nil instance variables for visiting/encoding" |
|
6564 |
||
6565 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | val notNil]. |
|
6566 |
||
6567 |
" |
|
6568 |
#(1 2 3 nil true symbol) elementDescriptorForNonNilInstanceVariables |
|
6569 |
Dictionary new elementDescriptorForNonNilInstanceVariables |
|
6570 |
(5 @ nil) elementDescriptorForNonNilInstanceVariables |
|
6571 |
" |
|
6572 |
! ! |
|
6573 |
||
5755 | 6574 |
!Object methodsFor:'printing & storing'! |
6575 |
||
6235 | 6576 |
basicPrintOn:aStream |
6577 |
"append the receivers className with an articel to the argument, aStream" |
|
6578 |
||
6579 |
aStream nextPutAll:self classNameWithArticle |
|
6580 |
! |
|
6581 |
||
5755 | 6582 |
className |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
6583 |
"return the classname of the receiver's class" |
5755 | 6584 |
|
6585 |
^ self class name |
|
6586 |
||
6587 |
" |
|
6588 |
1 className |
|
10460 | 6589 |
1 class className |
5755 | 6590 |
$a className |
9105 | 6591 |
$a class className |
5755 | 6592 |
" |
6593 |
! |
|
6594 |
||
6595 |
classNameWithArticle |
|
6596 |
"return a string consisting of classname preceeded by an article. |
|
6597 |
(dont expect me to write national variants for this ... :-) |
|
6598 |
If you have special preferences, redefine it ..." |
|
6599 |
||
6829 | 6600 |
| cls| |
5755 | 6601 |
|
6602 |
(cls := self class) == self ifTrue:[ |
|
14975 | 6603 |
^ 'a funny object' |
5755 | 6604 |
]. |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
6605 |
cls isNil ifTrue:[ |
14975 | 6606 |
^ 'a nil-classes object' "/ cannot happen |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
6607 |
]. |
6829 | 6608 |
^ cls nameWithArticle |
5755 | 6609 |
|
6610 |
" |
|
10460 | 6611 |
1 classNameWithArticle |
6612 |
(1->2) classNameWithArticle |
|
5755 | 6613 |
XWorkstation basicNew classNameWithArticle |
10460 | 6614 |
XWorkstation classNameWithArticle |
5755 | 6615 |
" |
6616 |
||
6617 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
6618 |
! |
|
6619 |
||
6620 |
errorPrint |
|
12703 | 6621 |
"print the receiver on the Transcript and Stderr. |
10530
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
6622 |
The Transcript is directed to the standard error stream on |
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
6623 |
headless applications." |
5755 | 6624 |
|
14165 | 6625 |
Stderr isNil ifTrue:[ |
14661 | 6626 |
"/ the following allows errorPrint to be used during |
6627 |
"/ the early init-phase, when no Stderr has been set up. |
|
6628 |
"/ (depends on string to respond to #errorPrint) |
|
6629 |
self printString utf8Encoded errorPrint. |
|
6630 |
^ self. |
|
14165 | 6631 |
]. |
6632 |
||
13350 | 6633 |
self withErrorStreamDo:[:s | self printOn:s]. |
6634 |
||
6635 |
"Modified: / 21-04-2011 / 12:46:42 / cg" |
|
5755 | 6636 |
! |
6637 |
||
6638 |
errorPrintCR |
|
6639 |
"{ Pragma: +optSpace }" |
|
6640 |
||
12703 | 6641 |
"print the receiver followed by a cr on the error stream(s). |
10530
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
6642 |
The Transcript is directed to the standard error stream on |
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
6643 |
headless applications." |
5755 | 6644 |
|
14165 | 6645 |
Stderr isNil ifTrue:[ |
14661 | 6646 |
"/ the following allows errorPrintCR to be used during |
6647 |
"/ the early init-phase, when no Stderr has been set up. |
|
6648 |
"/ (depends on string to respond to #errorPrintCR) |
|
6649 |
self printString utf8Encoded errorPrintCR. |
|
6650 |
^ self. |
|
14165 | 6651 |
]. |
6652 |
||
13350 | 6653 |
self withErrorStreamDo:[:s | self printOn:s. s cr]. |
6654 |
||
6655 |
" |
|
6656 |
'hello' errorPrintCR |
|
6657 |
" |
|
5755 | 6658 |
|
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6659 |
"Created: / 20-05-1996 / 10:20:41 / cg" |
13350 | 6660 |
"Modified: / 21-04-2011 / 12:47:13 / cg" |
5755 | 6661 |
! |
6662 |
||
6663 |
errorPrintNL |
|
6664 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6665 |
<resource:#obsolete> |
5755 | 6666 |
|
6667 |
"print the receiver followed by a cr on the standard error stream. |
|
6668 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6669 |
||
6670 |
^ self errorPrintCR |
|
6671 |
||
6672 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
6673 |
! |
|
6674 |
||
6675 |
errorPrintNewline |
|
6676 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6677 |
<resource:#obsolete> |
5755 | 6678 |
|
6679 |
"print the receiver followed by a cr on the standard error stream. |
|
6680 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6681 |
||
6682 |
self errorPrintCR. |
|
6683 |
||
6684 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
6685 |
! |
|
6686 |
||
6687 |
infoPrint |
|
6688 |
"{ Pragma: +optSpace }" |
|
6689 |
||
6690 |
"print the receiver on the standard error stream. |
|
6691 |
This is meant for information messages which are not warnings |
|
6692 |
or fatal messages. |
|
6693 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6694 |
||
6695 |
InfoPrinting == true ifTrue:[ |
|
14975 | 6696 |
self errorPrint |
5755 | 6697 |
] |
6698 |
! |
|
6699 |
||
6700 |
infoPrintCR |
|
6701 |
"{ Pragma: +optSpace }" |
|
6702 |
||
6703 |
"print the receiver followed by a cr on the standard error stream. |
|
6704 |
This is meant for information messages which are not warnings |
|
6705 |
or fatal messages. |
|
6706 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6707 |
||
6708 |
InfoPrinting == true ifTrue:[ |
|
14975 | 6709 |
self errorPrintCR |
5755 | 6710 |
] |
6711 |
||
6712 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
6713 |
! |
|
6714 |
||
6715 |
infoPrintNL |
|
6716 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6717 |
<resource:#obsolete> |
5755 | 6718 |
|
6719 |
"print the receiver followed by a cr on the standard error stream. |
|
6720 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
6721 |
||
6722 |
^ self infoPrintCR |
|
6723 |
! |
|
6724 |
||
6725 |
||
6726 |
"print the receiver on the standard output stream (which is not the Transcript)" |
|
6727 |
||
6728 |
"/ the following allows printCR to be used during |
|
6729 |
"/ the early init-phase, when no Stdout has been set up. |
|
6730 |
"/ (depends on string to respond to #print) |
|
6731 |
||
6732 |
Stdout isNil ifTrue:[ |
|
14661 | 6733 |
self printString utf8Encoded print. |
6734 |
^ self |
|
5755 | 6735 |
]. |
6736 |
self printOn:Stdout |
|
6737 |
||
6738 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
6739 |
! |
|
6740 |
||
6741 |
printCR |
|
6742 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
|
6743 |
||
6744 |
"/ the following allows printCR to be used during |
|
6745 |
"/ the early init-phase, when no Stdout has been set up. |
|
6746 |
"/ (depends on string to respond to #printCR) |
|
6747 |
||
6748 |
Stdout isNil ifTrue:[ |
|
14661 | 6749 |
self printString utf8Encoded printCR. |
6750 |
^ self |
|
5755 | 6751 |
]. |
6752 |
self printOn:Stdout. |
|
6753 |
Stdout cr |
|
6754 |
||
6755 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
6756 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
|
6757 |
! |
|
6758 |
||
6759 |
printNL |
|
6760 |
"print the receiver followed by a cr on the standard output stream |
|
6761 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
6762 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6763 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6764 |
|
5755 | 6765 |
^ self printCR |
6766 |
||
6767 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
6768 |
! |
|
6769 |
||
6770 |
printNewline |
|
6771 |
"print the receiver followed by a cr on the standard output stream. |
|
6772 |
This exists for backward compatibility - please use #printCR." |
|
6773 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6774 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6775 |
|
5755 | 6776 |
self printCR |
6777 |
||
6778 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
6779 |
! |
|
6780 |
||
6781 |
printOn:aStream |
|
6782 |
"append a user printed representation of the receiver to aStream. |
|
6783 |
The format is suitable for a human - not meant to be read back. |
|
6784 |
||
6785 |
The default here is to output the receivers class name. |
|
6786 |
BUT: this method is heavily redefined for objects which |
|
6787 |
can print prettier." |
|
6788 |
||
6235 | 6789 |
self basicPrintOn:aStream. |
6790 |
||
6791 |
" |
|
6792 |
(1@2) printOn:Transcript |
|
6793 |
(1@2) basicPrintOn:Transcript |
|
6794 |
" |
|
5755 | 6795 |
! |
6796 |
||
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6797 |
printOn:aStream format:format |
11335 | 6798 |
"this may be redefined in subclasses. |
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6799 |
Defined here for compatibility with subclasses" |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6800 |
|
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6801 |
self printOn:aStream. |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6802 |
! |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6803 |
|
5755 | 6804 |
printOn:aStream leftPaddedTo:size |
6805 |
"print the receiver on aStream, padding with spaces up to size. |
|
6806 |
padding is done on the left." |
|
6807 |
||
6808 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
6809 |
||
6810 |
" |
|
6811 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
6812 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
6813 |
" |
|
6814 |
! |
|
6815 |
||
6816 |
printOn:aStream leftPaddedTo:size with:padCharacter |
|
6817 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
6818 |
padding is done on the left." |
|
6819 |
||
6820 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
6821 |
||
6822 |
" |
|
6823 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
6824 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
6825 |
" |
|
6826 |
! |
|
6827 |
||
6828 |
printOn:aStream paddedTo:size |
|
6829 |
"print the receiver on aStream, padding with spaces up to size." |
|
6830 |
||
6831 |
self printOn:aStream paddedTo:size with:(Character space) |
|
6832 |
||
6833 |
" |
|
6834 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
6835 |
" |
|
6836 |
! |
|
6837 |
||
6838 |
printOn:aStream paddedTo:size with:padCharacter |
|
6839 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
6840 |
||
6841 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
6842 |
||
6843 |
" |
|
6844 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
6845 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
6846 |
" |
|
6847 |
! |
|
6848 |
||
6849 |
printOn:aStream zeroPaddedTo:size |
|
6850 |
"print the receiver on aStream, padding with zeros up to size. |
|
6851 |
Usually used with float numbers." |
|
6852 |
||
6853 |
self printOn:aStream paddedTo:size with:$0. |
|
6854 |
||
6855 |
" |
|
6856 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
6857 |
" |
|
6858 |
! |
|
6859 |
||
6860 |
printRightAdjustLen:size |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6861 |
<resource: #obsolete> |
5755 | 6862 |
"obsolete - just a name confusion. |
6863 |
This method will go away ..." |
|
6864 |
||
6865 |
(self printStringLeftPaddedTo:size) printOn:Stdout |
|
6866 |
! |
|
6867 |
||
6868 |
printString |
|
6869 |
"return a string for printing the receiver. |
|
6870 |
Since we now use printOn: as the basic print mechanism, |
|
6871 |
we have to create a stream and print into it." |
|
6872 |
||
6873 |
|s| |
|
6874 |
||
11790
6dcd44bc2ff9
Larger default for #printString
Stefan Vogel <sv@exept.de>
parents:
11738
diff
changeset
|
6875 |
s := CharacterWriteStream on:(String basicNew:40). "allocate at least 46 bytes for fast UUID conversion" |
5755 | 6876 |
self printOn:s. |
8300
d15ead94361f
Use CharacterWriteStream in #printString (speedup)
Stefan Vogel <sv@exept.de>
parents:
8287
diff
changeset
|
6877 |
^ s contents. |
7978
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6878 |
|
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6879 |
" |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6880 |
Date today printString. |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6881 |
" |
5755 | 6882 |
! |
6883 |
||
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6884 |
printStringFormat:orintFormat |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6885 |
"subclasses may redefine this. |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6886 |
Defined here to avoid type checks" |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6887 |
|
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6888 |
^ self printString |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6889 |
! |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6890 |
|
5755 | 6891 |
printStringLeftPaddedTo:size |
6892 |
"return my printString as a right-adjusted string of length size; |
|
6893 |
characters on the left are filled with spaces. |
|
10460 | 6894 |
If the printString is longer than size, |
5755 | 6895 |
it is returned unchanged (i.e. not truncated)" |
6896 |
||
6897 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
6898 |
||
6899 |
" |
|
6900 |
10 printStringLeftPaddedTo:10 |
|
6901 |
1 printStringLeftPaddedTo:10 |
|
6902 |
" |
|
6903 |
! |
|
6904 |
||
6905 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
6906 |
"return my printString as a right-adjusted string of length size; |
|
6907 |
characters on the left are filled with spaces. |
|
6908 |
If the printString is larger than size, |
|
6909 |
return the result from evaluating alternative." |
|
6910 |
||
6911 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
6912 |
||
6913 |
" |
|
6914 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6915 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6916 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6917 |
" |
|
6918 |
! |
|
6919 |
||
6920 |
printStringLeftPaddedTo:size with:padCharacter |
|
6921 |
"return my printString as a right-adjusted string of length size; |
|
6922 |
characters on the left are filled with padCharacter. |
|
10460 | 6923 |
If the printString is longer than size, |
5755 | 6924 |
it is returned unchanged (i.e. not truncated)" |
6925 |
||
6926 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
6927 |
||
6928 |
" |
|
10460 | 6929 |
123 printStringLeftPaddedTo:10 with:$. |
6930 |
1 printStringLeftPaddedTo:10 with:$. |
|
5755 | 6931 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
6932 |
" |
|
6933 |
! |
|
6934 |
||
6935 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
6936 |
"return my printString as a right-adjusted string of length size; |
|
6937 |
characters on the left are filled with padCharacter. |
|
6938 |
If the printString is larger than size, |
|
6939 |
return the result from evaluating alternative." |
|
6940 |
||
6941 |
|s| |
|
6942 |
||
6943 |
s := self printString. |
|
6944 |
s size > size ifTrue:[^ alternative value]. |
|
6945 |
^ s leftPaddedTo:size with:padCharacter |
|
6946 |
||
6947 |
" |
|
10460 | 6948 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
6949 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6950 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
5755 | 6951 |
" |
6952 |
! |
|
6953 |
||
8576 | 6954 |
printStringLimitedTo:sizeLimit |
6955 |
"return a string for printing the receiver, but limit the result string in its size." |
|
6956 |
||
6957 |
|s| |
|
6958 |
||
6959 |
s := CharacterWriteStream on:(String basicNew:30). |
|
6960 |
s writeLimit:sizeLimit. |
|
6961 |
self printOn:s. |
|
6962 |
^ s contents. |
|
6963 |
||
6964 |
" |
|
6965 |
Date today printStringLimitedTo:5. |
|
10460 | 6966 |
'12345678901234567890' printStringLimitedTo:5. |
8576 | 6967 |
" |
6968 |
! |
|
6969 |
||
5755 | 6970 |
printStringOnError:exceptionBlock |
6971 |
"return a string for printing the receiver; if any error occurs, return the result from |
|
6972 |
evaluating exceptionBlock. Useful to print something in an exceptionHandler or other |
|
6973 |
cleanup code." |
|
6974 |
||
6975 |
|rslt| |
|
6976 |
||
6977 |
Error handle:[:ex | |
|
14975 | 6978 |
rslt := exceptionBlock value |
5755 | 6979 |
] do:[ |
14975 | 6980 |
rslt := self printString |
5755 | 6981 |
]. |
6982 |
^ rslt |
|
6983 |
! |
|
6984 |
||
6985 |
printStringPaddedTo:size |
|
6986 |
"return a printed representation of the receiver, |
|
6987 |
padded with spaces (at the right) up to size. |
|
10460 | 6988 |
If the printString is longer than size, |
5755 | 6989 |
it is returned unchanged (i.e. not truncated)" |
6990 |
||
6991 |
^ self printStringPaddedTo:size with:(Character space) |
|
6992 |
||
6993 |
" |
|
10460 | 6994 |
123 printStringPaddedTo:10 |
6995 |
1234567890123456 printStringPaddedTo:10 |
|
6996 |
'hello' printStringPaddedTo:10 |
|
5755 | 6997 |
" |
6998 |
! |
|
6999 |
||
7000 |
printStringPaddedTo:size ifLarger:alternative |
|
7001 |
"return a printed representation of the receiver, |
|
7002 |
padded with spaces (at the right) up to size. |
|
10460 | 7003 |
If the resulting printString is too large, |
5755 | 7004 |
return the result from evaluating alternative." |
7005 |
||
7006 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
7007 |
||
7008 |
" |
|
10460 | 7009 |
12 printStringPaddedTo:3 ifLarger:['***'] |
7010 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
7011 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
5755 | 7012 |
" |
7013 |
! |
|
7014 |
||
7015 |
printStringPaddedTo:size with:padCharacter |
|
7016 |
"return a printed representation of the receiver, |
|
7017 |
padded with padCharacter (at the right) up to size. |
|
10460 | 7018 |
If the printString is longer than size, |
5755 | 7019 |
it is returned unchanged (i.e. not truncated)" |
7020 |
||
7021 |
^ (self printString) paddedTo:size with:padCharacter |
|
7022 |
||
7023 |
" |
|
7024 |
123 printStringPaddedTo:10 with:$. |
|
7025 |
123 printStringPaddedTo:10 with:$* |
|
10460 | 7026 |
123 printStringPaddedTo:3 with:$* |
7027 |
1234 printStringPaddedTo:3 with:$* |
|
5755 | 7028 |
" |
7029 |
! |
|
7030 |
||
7031 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
7032 |
"return a printed representation of the receiver, |
|
7033 |
padded with padCharacter (at the right) up to size. |
|
10460 | 7034 |
If the resulting printString is too large, |
5755 | 7035 |
return the result from evaluating alternative." |
7036 |
||
7037 |
|s| |
|
7038 |
||
7039 |
s := self printString. |
|
7040 |
s size > size ifTrue:[^ alternative value]. |
|
7041 |
^ s paddedTo:size with:padCharacter |
|
7042 |
||
7043 |
" |
|
7044 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
7045 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
7046 |
" |
|
7047 |
! |
|
7048 |
||
7049 |
printStringRightAdjustLen:size |
|
7050 |
"obsolete - just a name confusion. |
|
7051 |
This method will go away ..." |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7052 |
<resource: #obsolete> |
5755 | 7053 |
|
7054 |
^ self printStringLeftPaddedTo:size |
|
7055 |
! |
|
7056 |
||
7057 |
printStringZeroPaddedTo:size |
|
10460 | 7058 |
"return a printed representation of the receiver, |
5755 | 7059 |
padded with zero (at the right) characters up to size. |
7060 |
Usually used with float numbers." |
|
7061 |
||
7062 |
^ self printStringPaddedTo:size with:$0 |
|
7063 |
||
7064 |
" |
|
10460 | 7065 |
123.0 printStringZeroPaddedTo:10 |
5755 | 7066 |
" |
7067 |
! |
|
7068 |
||
8287 | 7069 |
printfPrintString:ignoredFormat |
7070 |
"fallback to default printString |
|
7071 |
(for compatibility with float and integer-printing)" |
|
7072 |
||
7073 |
^ self printString |
|
7074 |
! |
|
7075 |
||
5755 | 7076 |
store |
7077 |
"store the receiver on standard output. |
|
7078 |
this method is useless, but included for compatibility." |
|
7079 |
||
7080 |
self storeOn:Stdout |
|
7081 |
! |
|
7082 |
||
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7083 |
storeArrayElementOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7084 |
"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
|
7085 |
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
|
7086 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7087 |
^ 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
|
7088 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7089 |
|
5755 | 7090 |
storeCR |
7091 |
"store the receiver on standard output; append a carriage return." |
|
7092 |
||
7093 |
self store. |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7094 |
Stdout cr. |
5755 | 7095 |
|
7096 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
7097 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
7098 |
! |
|
7099 |
||
7100 |
storeNl |
|
7101 |
"store the receiver on standard output; append a newline. |
|
7102 |
This method is included for backward compatibility- use #storeCR." |
|
7103 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7104 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7105 |
|
5755 | 7106 |
self storeCR. |
7107 |
||
7108 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
7109 |
! |
|
7110 |
||
7111 |
storeOn:aStream |
|
7112 |
"store the receiver on aStream; i.e. print an expression which will |
|
7113 |
reconstruct the receiver. |
|
7114 |
Notice, that no self referencing or cyclic objects can be represented |
|
7115 |
in this format. |
|
7116 |
Use storeBinaryOn:, which handles these cases correctly." |
|
7117 |
||
7118 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
7119 |
||
7120 |
thisContext isRecursive ifTrue:[ |
|
14975 | 7121 |
Object recursiveStoreStringSignal raiseRequestWith:self. |
7122 |
'Object [error]: storeString of self referencing object (' errorPrint. |
|
7123 |
self class name errorPrint. |
|
7124 |
')' errorPrintCR. |
|
7125 |
aStream nextPutAll:'#("recursive")'. |
|
7126 |
^ self |
|
5755 | 7127 |
]. |
7128 |
||
7129 |
myClass := self class. |
|
7130 |
aStream nextPut:$(. |
|
7131 |
aStream nextPutAll:self class name. |
|
7132 |
||
7133 |
hasSemi := false. |
|
7134 |
myClass isVariable ifTrue:[ |
|
14975 | 7135 |
aStream nextPutAll:' basicNew:'. |
7136 |
self basicSize printOn:aStream |
|
5755 | 7137 |
] ifFalse:[ |
14975 | 7138 |
aStream nextPutAll:' basicNew' |
5755 | 7139 |
]. |
7140 |
||
7141 |
sz := myClass instSize. |
|
10460 | 7142 |
1 to:sz do:[:i | |
14975 | 7143 |
aStream nextPutAll:' instVarAt:'. |
7144 |
i printOn:aStream. |
|
7145 |
aStream nextPutAll:' put:'. |
|
7146 |
(self instVarAt:i) storeOn:aStream. |
|
7147 |
aStream nextPut:$;. |
|
7148 |
hasSemi := true |
|
5755 | 7149 |
]. |
7150 |
myClass isVariable ifTrue:[ |
|
14975 | 7151 |
sz := self basicSize. |
7152 |
1 to:sz do:[:i | |
|
7153 |
aStream nextPutAll:' basicAt:'. |
|
7154 |
i printOn:aStream. |
|
7155 |
aStream nextPutAll:' put:'. |
|
7156 |
(self basicAt:i) storeOn:aStream. |
|
7157 |
aStream nextPut:$;. |
|
7158 |
hasSemi := true |
|
7159 |
] |
|
5755 | 7160 |
]. |
7161 |
hasSemi ifTrue:[ |
|
14975 | 7162 |
aStream nextPutAll:' yourself' |
5755 | 7163 |
]. |
7164 |
aStream nextPut:$). |
|
7165 |
||
7166 |
" |
|
7167 |
|s| |
|
7168 |
||
7169 |
s := WriteStream on:(String new). |
|
7170 |
('hello' -> 'world') storeOn:s. |
|
7171 |
s := ReadStream on:(s contents). |
|
7172 |
(Object readFrom:s) inspect |
|
7173 |
" |
|
7174 |
" |
|
7175 |
|s| |
|
7176 |
||
7177 |
s := 'data' asFilename writeStream. |
|
7178 |
('hello' -> 'world') storeOn:s. |
|
7179 |
s close. |
|
7180 |
||
7181 |
s := 'data' asFilename readStream. |
|
7182 |
(Object readFrom:s) inspect |
|
7183 |
" |
|
7184 |
||
7185 |
"does not work example:" |
|
7186 |
" |
|
7187 |
|s a| |
|
7188 |
||
7189 |
a := Array new:2. |
|
7190 |
a at:1 put:a. |
|
7191 |
||
7192 |
s := 'data' asFilename writeStream. |
|
7193 |
a storeOn:s. |
|
7194 |
s close. |
|
7195 |
||
7196 |
s := 'data' asFilename readStream. |
|
7197 |
(Object readFrom:s) inspect |
|
7198 |
" |
|
7199 |
||
13162 | 7200 |
"Modified: / 03-12-2010 / 13:27:51 / cg" |
5755 | 7201 |
! |
7202 |
||
7203 |
storeString |
|
7204 |
"return a string representing an expression to reconstruct the receiver. |
|
7205 |
Notice, that no self referencing or cyclic objects can be represented |
|
7206 |
in this format. |
|
7207 |
Use storeBinaryOn:, which handles these cases correctly." |
|
7208 |
||
7209 |
|s| |
|
7210 |
||
7211 |
s := WriteStream on:(String new:50). |
|
7212 |
self storeOn:s. |
|
7213 |
^ s contents |
|
13350 | 7214 |
! |
7215 |
||
7216 |
withErrorStreamDo:aBlock |
|
7217 |
"{ Pragma: +optSpace }" |
|
7218 |
||
14162 | 7219 |
"helper for error messages - evaluate aBlock, passing it a stream on which to put |
13350 | 7220 |
error messages." |
7221 |
||
13578
aa9827cafc2c
signalInterrupt: - tell which process was killed
Claus Gittinger <cg@exept.de>
parents:
13566
diff
changeset
|
7222 |
|stream| |
aa9827cafc2c
signalInterrupt: - tell which process was killed
Claus Gittinger <cg@exept.de>
parents:
13566
diff
changeset
|
7223 |
|
aa9827cafc2c
signalInterrupt: - tell which process was killed
Claus Gittinger <cg@exept.de>
parents:
13566
diff
changeset
|
7224 |
stream := Processor activeProcess isSystemProcess |
14975 | 7225 |
ifTrue:[Stderr] |
7226 |
ifFalse:[Transcript]. |
|
13350 | 7227 |
StreamError catch:[ |
14975 | 7228 |
aBlock value:stream. |
13578
aa9827cafc2c
signalInterrupt: - tell which process was killed
Claus Gittinger <cg@exept.de>
parents:
13566
diff
changeset
|
7229 |
]. |
14162 | 7230 |
stream ~~ Stderr ifTrue:[ |
14975 | 7231 |
aBlock value:Stderr. |
13350 | 7232 |
]. |
7233 |
||
7234 |
"Created: / 21-04-2011 / 12:46:21 / cg" |
|
5755 | 7235 |
! ! |
7236 |
||
7237 |
!Object methodsFor:'queries'! |
|
7238 |
||
7239 |
basicSize |
|
7240 |
"return the number of the receivers indexed instance variables, |
|
7241 |
0 if it has none. |
|
7242 |
||
7243 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
7244 |
||
7245 |
%{ /* NOCONTEXT */ |
|
7246 |
||
8909 | 7247 |
REGISTER INT nbytes; |
5755 | 7248 |
REGISTER OBJ myClass; |
7249 |
int nInstBytes; |
|
7250 |
||
7251 |
/* |
|
7252 |
* notice the missing test for self being a nonNilObject - |
|
7253 |
* this can be done since basicSize is defined both in UndefinedObject |
|
7254 |
* and SmallInteger |
|
7255 |
*/ |
|
7256 |
myClass = __qClass(self); |
|
7257 |
nbytes = __qSize(self); |
|
7258 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) ); |
|
7259 |
||
7260 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
14975 | 7261 |
case __MASKSMALLINT(POINTERARRAY): |
7262 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
7263 |
nbytes -= nInstBytes; |
|
7264 |
RETURN ( __mkSmallInteger(__BYTES2OBJS__(nbytes)) ); |
|
7265 |
||
7266 |
case __MASKSMALLINT(BYTEARRAY): |
|
7267 |
nbytes -= nInstBytes; |
|
7268 |
RETURN ( __mkSmallInteger(nbytes / sizeof(char)) ); |
|
7269 |
||
7270 |
case __MASKSMALLINT(FLOATARRAY): |
|
7271 |
nbytes -= nInstBytes; |
|
7272 |
RETURN ( __mkSmallInteger(nbytes / sizeof(float)) ); |
|
7273 |
||
7274 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 7275 |
#ifdef __NEED_DOUBLE_ALIGN |
14975 | 7276 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
5755 | 7277 |
#endif |
14975 | 7278 |
nbytes -= nInstBytes; |
7279 |
RETURN ( __mkSmallInteger(nbytes / sizeof(double)) ); |
|
7280 |
||
7281 |
case __MASKSMALLINT(WORDARRAY): |
|
7282 |
case __MASKSMALLINT(SWORDARRAY): |
|
7283 |
nbytes -= nInstBytes; |
|
7284 |
RETURN ( __mkSmallInteger(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */ |
|
7285 |
||
7286 |
case __MASKSMALLINT(LONGARRAY): |
|
7287 |
case __MASKSMALLINT(SLONGARRAY): |
|
7288 |
nbytes -= nInstBytes; |
|
7289 |
RETURN ( __mkSmallInteger(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */ |
|
7290 |
||
7291 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
7292 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 7293 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 7294 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
5755 | 7295 |
#endif |
14975 | 7296 |
nbytes -= nInstBytes; |
7297 |
RETURN ( __mkSmallInteger(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */ |
|
5755 | 7298 |
} |
7299 |
%}. |
|
7300 |
^ 0 |
|
7301 |
! |
|
7302 |
||
7303 |
byteSize |
|
7304 |
"return the number of bytes in the receivers indexed instance variables, |
|
7305 |
0 if it has none. This only returns non-zero for non-pointer indexed |
|
7306 |
instvars i.e. byteArrays, wordArrays etc. |
|
7307 |
Notice: for Strings the returned size may look strange. |
|
7308 |
Only useful with binary storage." |
|
7309 |
||
7310 |
|myClass| |
|
7311 |
||
7312 |
myClass := self class. |
|
7313 |
myClass isVariable ifTrue:[ |
|
14975 | 7314 |
myClass isPointers ifFalse:[ |
7315 |
myClass isBytes ifTrue:[ |
|
7316 |
^ self basicSize. |
|
7317 |
]. |
|
7318 |
myClass isWords ifTrue:[ |
|
7319 |
^ self basicSize * 2. |
|
7320 |
]. |
|
7321 |
myClass isSignedWords ifTrue:[ |
|
7322 |
^ self basicSize * 2. |
|
7323 |
]. |
|
7324 |
myClass isLongs ifTrue:[ |
|
7325 |
^ self basicSize * 4. |
|
7326 |
]. |
|
7327 |
myClass isSignedLongs ifTrue:[ |
|
7328 |
^ self basicSize * 4. |
|
7329 |
]. |
|
7330 |
myClass isLongLongs ifTrue:[ |
|
7331 |
^ self basicSize * 8. |
|
7332 |
]. |
|
7333 |
myClass isSignedLongLongs ifTrue:[ |
|
7334 |
^ self basicSize * 8. |
|
7335 |
]. |
|
7336 |
myClass isFloats ifTrue:[ |
|
7337 |
^ self basicSize * (ExternalBytes sizeofFloat) |
|
7338 |
]. |
|
7339 |
myClass isDoubles ifTrue:[ |
|
7340 |
^ self basicSize * (ExternalBytes sizeofDouble) |
|
7341 |
]. |
|
7342 |
self error:'unknown variable size class species'. |
|
7343 |
] |
|
5755 | 7344 |
]. |
7345 |
^ 0 |
|
7346 |
||
7347 |
" |
|
10460 | 7348 |
Point new byteSize |
14632 | 7349 |
'hello' byteSize |
7350 |
'hello' asUnicode16String byteSize |
|
10460 | 7351 |
(ByteArray with:1 with:2) byteSize |
7352 |
(FloatArray with:1.5) byteSize |
|
7353 |
(DoubleArray with:1.5) byteSize |
|
7354 |
(WordArray with:1 with:2) byteSize |
|
5755 | 7355 |
" |
7356 |
! |
|
7357 |
||
7358 |
class |
|
7359 |
"return the receivers class" |
|
7360 |
||
7361 |
%{ /* NOCONTEXT */ |
|
7362 |
||
7363 |
RETURN ( __Class(self) ); |
|
7364 |
%} |
|
7365 |
! |
|
7366 |
||
7367 |
respondsTo:aSelector |
|
7368 |
"return true, if the receiver implements a method with selector equal |
|
7369 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
7370 |
receivers class or one of its superclasses. |
|
7371 |
||
7372 |
Notice, that this does not imply, that such a message can be sent without |
|
7373 |
an error being raised. For example, an implementation could send |
|
7374 |
#shouldNotImplement or #subclassResponsibility." |
|
7375 |
||
7376 |
" |
|
7377 |
should we go via the cache, or search (by class) ? |
|
7378 |
The first is faster, most of the time; while the 2nd fills |
|
7379 |
the cache with useless data if this is sent in a loop over all objects. |
|
7380 |
For now, use the cache ... |
|
7381 |
" |
|
7382 |
%{ /* NOCONTEXT */ |
|
7383 |
||
7384 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
14975 | 7385 |
RETURN ( false ); |
5755 | 7386 |
} |
7387 |
RETURN ( true ); |
|
7388 |
%} |
|
7389 |
. |
|
7390 |
^ self class canUnderstand:aSelector |
|
7391 |
||
7392 |
||
7393 |
"'aString' respondsTo:#+" |
|
7394 |
"'aString' respondsTo:#," |
|
7395 |
"'aString' respondsTo:#collect:" |
|
7396 |
! |
|
7397 |
||
7398 |
respondsToArithmetic |
|
7399 |
"return true, if the receiver responds to arithmetic messages. |
|
7400 |
false is returned here - the method is redefined in ArithmeticValue." |
|
7401 |
||
7402 |
^ false |
|
7403 |
! |
|
7404 |
||
7405 |
size |
|
7406 |
"return the number of the receivers indexed instance variables; |
|
7407 |
this method may be redefined in subclasses" |
|
7408 |
||
7409 |
^ self basicSize |
|
7410 |
! |
|
7411 |
||
7412 |
species |
|
7413 |
"return a class which is similar to (or the same as) the receivers class. |
|
7414 |
This is used to create an appropriate object when creating derived |
|
7415 |
copies in the collection classes (sometimes redefined)." |
|
7416 |
||
7417 |
^ self class |
|
7418 |
! |
|
7419 |
||
7420 |
yourself |
|
7421 |
"return the receiver - used for cascades to return self at the end" |
|
7422 |
||
7423 |
^ self |
|
7424 |
! ! |
|
7425 |
||
7426 |
!Object methodsFor:'secure message sending'! |
|
7427 |
||
13099 | 7428 |
?: selector |
7429 |
"try to send a message to the receiver; |
|
7430 |
if understood, return the value; |
|
7431 |
if not, return nil." |
|
7432 |
||
7433 |
^ self perform:selector ifNotUnderstood:nil |
|
7434 |
||
7435 |
" |
|
7436 |
ApplicationModel new masterApplication resources first - error |
|
7437 |
ApplicationModel new ?: #masterApplication ?: #resources ?: #first - nil |
|
7438 |
" |
|
7439 |
||
7440 |
"Modified: / 20-10-2010 / 10:45:21 / cg" |
|
7441 |
! |
|
7442 |
||
5755 | 7443 |
askFor:aSelector |
7444 |
"try to send the receiver the message, aSelector. |
|
10460 | 7445 |
If it does not understand it, return false. |
5755 | 7446 |
Otherwise the real value returned. |
11398 | 7447 |
Useful to send messages such as: #isColor to unknown receivers." |
5755 | 7448 |
|
7449 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
7450 |
||
7451 |
" |
|
10460 | 7452 |
1 askFor:#isColor |
7453 |
Color red askFor:#isColor |
|
7454 |
||
7455 |
1 askFor:#isFoo |
|
7456 |
Color red askFor:#isFoo |
|
5755 | 7457 |
" |
7458 |
! |
|
7459 |
||
11398 | 7460 |
askFor:aSelector with:argument |
7461 |
"try to send the receiver the message, aSelector. |
|
7462 |
If it does not understand it, return false. |
|
7463 |
Otherwise the real value returned. |
|
7464 |
Useful to send messages such as: #isXXX: to unknown receivers." |
|
7465 |
||
7466 |
^ self perform:aSelector with:argument ifNotUnderstood:[false] |
|
7467 |
! |
|
7468 |
||
11401 | 7469 |
askFor:aSelector with:arg1 with:arg2 |
7470 |
"try to send the receiver the message, aSelector. |
|
7471 |
If it does not understand it, return false. |
|
7472 |
Otherwise the real value returned. |
|
7473 |
Useful to send messages such as: #isXXX: to unknown receivers." |
|
7474 |
||
7475 |
^ self perform:aSelector with:arg1 with:arg2 ifNotUnderstood:[false] |
|
7476 |
! |
|
7477 |
||
5755 | 7478 |
perform:aSelector ifNotUnderstood:exceptionBlock |
7479 |
"try to send message aSelector to the receiver. |
|
12157 | 7480 |
If its understood, return the method's returned value, |
7481 |
otherwise return the value of the exceptionBlock. |
|
7482 |
Read this: |
|
7483 |
Many programmers do an Error-handle to perform a similar |
|
7484 |
checked-message send. However, this method is more specific, |
|
7485 |
in that only errors for the given selector are cought - not any other |
|
7486 |
doesNotUnderstand, and especially not any other error." |
|
5755 | 7487 |
|
7488 |
|val ok| |
|
7489 |
||
6146 | 7490 |
MessageNotUnderstood handle:[:ex | |
14975 | 7491 |
"/ reject, if the bad message is not the one |
7492 |
"/ we have sent originally |
|
7493 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
7494 |
ex reject |
|
7495 |
]. |
|
5755 | 7496 |
] do:[ |
14975 | 7497 |
val := self perform:aSelector. |
7498 |
ok := true. |
|
5755 | 7499 |
]. |
7500 |
ok isNil ifTrue:[ |
|
14975 | 7501 |
^ exceptionBlock value |
5755 | 7502 |
]. |
7503 |
^ val |
|
7504 |
||
7505 |
" |
|
10460 | 7506 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
7507 |
1.2345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7508 |
12345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
5755 | 7509 |
" |
7510 |
! |
|
7511 |
||
7512 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
7513 |
"try to send message aSelector to the receiver. |
|
12157 | 7514 |
If its understood, return the method's returned value, |
7515 |
otherwise return the value of the exceptionBlock. |
|
7516 |
Read this: |
|
7517 |
Many programmers do an Error-handle to perform a similar |
|
7518 |
checked-message send. However, this method is more specific, |
|
7519 |
in that only errors for the given selector are cought - not any other |
|
7520 |
doesNotUnderstand, and especially not any other error." |
|
5755 | 7521 |
|
7522 |
|val ok| |
|
7523 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7524 |
MessageNotUnderstood handle:[:ex | |
14975 | 7525 |
"/ reject, if the bad message is not the one |
7526 |
"/ we have sent originally |
|
7527 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
7528 |
ex reject |
|
7529 |
] |
|
5755 | 7530 |
] do:[ |
14975 | 7531 |
val := self perform:aSelector with:argument. |
7532 |
ok := true. |
|
5755 | 7533 |
]. |
7534 |
ok isNil ifTrue:[ |
|
14975 | 7535 |
^ exceptionBlock value |
5755 | 7536 |
]. |
7537 |
^ val |
|
7538 |
||
7539 |
" |
|
7540 |
|unknown| |
|
7541 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7542 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7543 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 7544 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7545 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 7546 |
" |
7547 |
! |
|
7548 |
||
5926 | 7549 |
perform:aSelector with:arg1 with:arg2 ifNotUnderstood:exceptionBlock |
7550 |
"try to send message aSelector to the receiver. |
|
12157 | 7551 |
If its understood, return the method's returned value, |
7552 |
otherwise return the value of the exceptionBlock. |
|
7553 |
Read this: |
|
7554 |
Many programmers do an Error-handle to perform a similar |
|
7555 |
checked-message send. However, this method is more specific, |
|
7556 |
in that only errors for the given selector are cought - not any other |
|
7557 |
doesNotUnderstand, and especially not any other error." |
|
5926 | 7558 |
|
7559 |
|val ok| |
|
7560 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7561 |
MessageNotUnderstood handle:[:ex | |
14975 | 7562 |
"/ reject, if the bad message is not the one |
7563 |
"/ we have sent originally |
|
7564 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
7565 |
ex reject |
|
7566 |
] |
|
5926 | 7567 |
] do:[ |
14975 | 7568 |
val := self perform:aSelector with:arg1 with:arg2. |
7569 |
ok := true. |
|
5926 | 7570 |
]. |
7571 |
ok isNil ifTrue:[ |
|
14975 | 7572 |
^ exceptionBlock value |
5926 | 7573 |
]. |
7574 |
^ val |
|
7575 |
! |
|
7576 |
||
5755 | 7577 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
7578 |
"try to send message aSelector to the receiver. |
|
12157 | 7579 |
If its understood, return the method's returned value, |
7580 |
otherwise return the value of the exceptionBlock. |
|
7581 |
Read this: |
|
7582 |
Many programmers do an Error-handle to perform a similar |
|
7583 |
checked-message send. However, this method is more specific, |
|
7584 |
in that only errors for the given selector are cought - not any other |
|
7585 |
doesNotUnderstand, and especially not any other error." |
|
5755 | 7586 |
|
7587 |
|val ok| |
|
7588 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7589 |
MessageNotUnderstood handle:[:ex | |
14975 | 7590 |
"/ reject, if the bad message is not the one |
7591 |
"/ we have sent originally. |
|
7592 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
7593 |
ex reject |
|
7594 |
] |
|
5755 | 7595 |
] do:[ |
14975 | 7596 |
val := self perform:aSelector withArguments:argumentArray. |
7597 |
ok := true. |
|
5755 | 7598 |
]. |
7599 |
ok isNil ifTrue:[ |
|
14975 | 7600 |
^ exceptionBlock value |
5755 | 7601 |
]. |
7602 |
^ val |
|
7603 |
||
7604 |
" |
|
7605 |
|unknown| |
|
7606 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7607 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7608 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 7609 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7610 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 7611 |
" |
7612 |
||
7613 |
"Modified: 27.3.1997 / 14:13:16 / cg" |
|
7614 |
! ! |
|
7615 |
||
7616 |
!Object methodsFor:'signal constants'! |
|
7617 |
||
7618 |
messageNotUnderstoodSignal |
|
6146 | 7619 |
^ MessageNotUnderstood |
5755 | 7620 |
|
7621 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
7622 |
! ! |
|
7623 |
||
7624 |
!Object methodsFor:'special queries'! |
|
7625 |
||
7626 |
allOwners |
|
7627 |
"return a collection of all objects referencing the receiver" |
|
7628 |
||
7629 |
^ ObjectMemory whoReferences:self |
|
7630 |
! |
|
7631 |
||
7632 |
references:anObject |
|
7633 |
"return true, if the receiver refers to the argument, anObject. |
|
7634 |
- for debugging only" |
|
7635 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7636 |
^ self referencesObject:anObject |
5755 | 7637 |
|
7638 |
" |
|
7639 |
|v| |
|
7640 |
||
7641 |
v := View new initialize. |
|
10460 | 7642 |
v references:Display. |
5755 | 7643 |
" |
7644 |
! |
|
7645 |
||
7646 |
referencesAny:aCollection |
|
10460 | 7647 |
"return true, if the receiver refers to any object from |
5755 | 7648 |
the argument, aCollection. |
7649 |
- for debugging only" |
|
7650 |
||
10460 | 7651 |
%{ |
5755 | 7652 |
OBJ cls, flags; |
7653 |
int nInsts, inst; |
|
7654 |
||
7655 |
if (! __isNonNilObject(self)) { |
|
14975 | 7656 |
RETURN (false); |
5755 | 7657 |
} |
7658 |
||
8934 | 7659 |
if (__isArrayLike(aCollection)) { |
14975 | 7660 |
int nObjs = __arraySize(aCollection); |
7661 |
char *minAddr = 0, *maxAddr = 0; |
|
7662 |
||
7663 |
if (nObjs == 0) { |
|
7664 |
RETURN (false); |
|
7665 |
} |
|
7666 |
||
7667 |
/* |
|
7668 |
* a little optimization: use the fact that all old objects |
|
7669 |
* refering to a new object are on the remSet; if I am not, |
|
7670 |
* a trivial reject is possible, if all objects are newbees. |
|
7671 |
* as a side effect, gather min/max addresses |
|
7672 |
*/ |
|
7673 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
7674 |
int allNewBees = 1; |
|
7675 |
int i; |
|
7676 |
||
7677 |
minAddr = (char *)(__ArrayInstPtr(aCollection)->a_element[0]); |
|
7678 |
maxAddr = minAddr; |
|
7679 |
||
7680 |
for (i=0; i<nObjs; i++) { |
|
7681 |
OBJ anObject; |
|
7682 |
||
7683 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7684 |
||
7685 |
if (__isNonNilObject(anObject)) { |
|
7686 |
int spc; |
|
7687 |
||
7688 |
if (((spc = __qSpace(anObject)) != NEWSPACE) && (spc != SURVSPACE)) { |
|
7689 |
allNewBees = 0; |
|
7690 |
} |
|
7691 |
} |
|
7692 |
||
7693 |
if ((char *)anObject < minAddr) { |
|
7694 |
minAddr = (char *)anObject; |
|
7695 |
} else if ((char *)anObject > maxAddr) { |
|
7696 |
maxAddr = (char *)anObject; |
|
7697 |
} |
|
7698 |
} |
|
7699 |
if (allNewBees) { |
|
7700 |
RETURN (false); |
|
7701 |
} |
|
7702 |
} |
|
7703 |
||
7704 |
/* |
|
7705 |
* fetch min/max in searchList (if not already done) |
|
7706 |
*/ |
|
7707 |
if (minAddr == 0) { |
|
7708 |
int i; |
|
7709 |
||
7710 |
for (i=0; i<nObjs; i++) { |
|
7711 |
OBJ anObject; |
|
7712 |
||
7713 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7714 |
if ((char *)anObject < minAddr) { |
|
7715 |
minAddr = (char *)anObject; |
|
7716 |
} else if ((char *)anObject > maxAddr) { |
|
7717 |
maxAddr = (char *)anObject; |
|
7718 |
} |
|
7719 |
} |
|
7720 |
} |
|
7721 |
||
7722 |
cls = __qClass(self); |
|
7723 |
if (((char *)cls >= minAddr) && ((char *)cls <= maxAddr)) { |
|
5755 | 7724 |
#if defined(memsrch4) |
14975 | 7725 |
if (memsrch4(__arrayVal(aCollection), (INT)cls, nObjs)) { |
7726 |
RETURN (true); |
|
7727 |
} |
|
5755 | 7728 |
#else |
14975 | 7729 |
int i; |
7730 |
||
7731 |
for (i=0; i<nObjs; i++) { |
|
7732 |
OBJ anObject; |
|
7733 |
||
7734 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7735 |
if (cls == anObject) { |
|
7736 |
RETURN (true); |
|
7737 |
} |
|
7738 |
} |
|
5755 | 7739 |
#endif /* memsrch4 */ |
14975 | 7740 |
} |
7741 |
||
7742 |
flags = __ClassInstPtr(cls)->c_flags; |
|
7743 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
7744 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
7745 |
} else { |
|
7746 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
7747 |
} |
|
7748 |
if (! nInsts) { |
|
7749 |
RETURN (false); |
|
7750 |
} |
|
7751 |
||
7752 |
if (nObjs == 1) { |
|
7753 |
/* better reverse the loop */ |
|
7754 |
OBJ anObject; |
|
7755 |
||
7756 |
anObject = __ArrayInstPtr(aCollection)->a_element[0]; |
|
5755 | 7757 |
#if defined(memsrch4) |
14975 | 7758 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
7759 |
RETURN (true); |
|
7760 |
} |
|
5755 | 7761 |
#else |
14975 | 7762 |
for (inst=0; inst<nInsts; inst++) { |
7763 |
if ((__InstPtr(self)->i_instvars[inst]) == anObject) { |
|
7764 |
RETURN (true); |
|
7765 |
} |
|
7766 |
} |
|
5755 | 7767 |
#endif |
14975 | 7768 |
RETURN (false); |
7769 |
} |
|
7770 |
||
7771 |
for (inst=0; inst<nInsts; inst++) { |
|
7772 |
OBJ instVar = __InstPtr(self)->i_instvars[inst]; |
|
7773 |
int i; |
|
7774 |
||
7775 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
5755 | 7776 |
#if defined(memsrch4) |
14975 | 7777 |
if (memsrch4(__arrayVal(aCollection), (INT)instVar, nObjs)) { |
7778 |
RETURN (true); |
|
7779 |
} |
|
5755 | 7780 |
#else |
14975 | 7781 |
for (i=0; i<nObjs; i++) { |
7782 |
OBJ anObject; |
|
7783 |
||
7784 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7785 |
if (instVar == anObject) { |
|
7786 |
RETURN (true); |
|
7787 |
} |
|
7788 |
} |
|
5755 | 7789 |
#endif /* memsrch4 */ |
14975 | 7790 |
} |
7791 |
} |
|
7792 |
RETURN (false); |
|
5755 | 7793 |
} |
7794 |
%}. |
|
7795 |
||
7796 |
aCollection do:[:el | |
|
14975 | 7797 |
(self referencesObject:el) ifTrue:[^ true]. |
5755 | 7798 |
]. |
7799 |
^ false |
|
7800 |
! |
|
7801 |
||
7802 |
referencesDerivedInstanceOf:aClass |
|
7803 |
"return true, if the receiver refers to an instance of |
|
7804 |
the argument, aClass or its subclass. This method exists |
|
7805 |
to support searching for users of a class." |
|
7806 |
||
10460 | 7807 |
|myClass |
5755 | 7808 |
numInst "{ Class: SmallInteger }" | |
7809 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7810 |
"check the class" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7811 |
(self isKindOf:aClass) ifTrue:[^ true]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7812 |
|
5755 | 7813 |
myClass := self class. |
7814 |
"check the instance variables" |
|
7815 |
numInst := myClass instSize. |
|
10460 | 7816 |
1 to:numInst do:[:i | |
14975 | 7817 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
5755 | 7818 |
]. |
7819 |
||
7820 |
"check the indexed variables" |
|
7821 |
myClass isVariable ifTrue:[ |
|
14975 | 7822 |
myClass isPointers ifFalse:[ |
7823 |
"no need to search in non pointer fields" |
|
7824 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
|
7825 |
]. |
|
7826 |
numInst := self basicSize. |
|
7827 |
1 to:numInst do:[:i | |
|
7828 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
7829 |
] |
|
5755 | 7830 |
]. |
7831 |
^ false |
|
7832 |
||
7833 |
" |
|
10460 | 7834 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
7835 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
7836 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
5755 | 7837 |
" |
7838 |
! |
|
7839 |
||
9279 | 7840 |
referencesForWhich:checkBlock do:actionBlock |
7841 |
|myClass inst |
|
7842 |
numInst "{ Class: SmallInteger }" | |
|
7843 |
||
7844 |
myClass := self class. |
|
7845 |
"check the instance variables" |
|
7846 |
numInst := myClass instSize. |
|
10460 | 7847 |
1 to:numInst do:[:i | |
14975 | 7848 |
inst := self instVarAt:i. |
7849 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
9279 | 7850 |
]. |
7851 |
||
7852 |
"check the indexed variables" |
|
7853 |
myClass isVariable ifTrue:[ |
|
14975 | 7854 |
myClass isPointers ifTrue:[ |
7855 |
"no need to search in non pointer fields" |
|
7856 |
||
7857 |
numInst := self basicSize. |
|
7858 |
1 to:numInst do:[:i | |
|
7859 |
inst := self basicAt:i. |
|
7860 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
7861 |
] |
|
7862 |
] |
|
10460 | 7863 |
]. |
7864 |
||
7865 |
" |
|
7866 |
(1 @ 3.4) referencesForWhich:[:i | i isFloat] do:[:i | Transcript showCR:i] |
|
9279 | 7867 |
" |
7868 |
! |
|
7869 |
||
5755 | 7870 |
referencesInstanceOf:aClass |
7871 |
"return true, if the receiver refers to an instance of |
|
7872 |
the argument, aClass.This method exists |
|
7873 |
to support searching for users of a class." |
|
7874 |
||
10460 | 7875 |
|myClass |
5755 | 7876 |
numInst "{ Class: SmallInteger }" | |
7877 |
||
7878 |
myClass := self class. |
|
7879 |
||
7880 |
"check the class" |
|
7881 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
7882 |
||
7883 |
"check the instance variables" |
|
7884 |
numInst := myClass instSize. |
|
10460 | 7885 |
1 to:numInst do:[:i | |
14975 | 7886 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
5755 | 7887 |
]. |
7888 |
||
7889 |
"check the indexed variables" |
|
7890 |
myClass isVariable ifTrue:[ |
|
14975 | 7891 |
myClass isPointers ifFalse:[ |
7892 |
"no need to search in non-pointer indexed fields" |
|
7893 |
myClass isLongs ifTrue:[ |
|
7894 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
7895 |
] ifFalse:[ |
|
7896 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
7897 |
^ aClass == SmallInteger |
|
7898 |
] |
|
7899 |
]. |
|
7900 |
numInst := self basicSize. |
|
7901 |
1 to:numInst do:[:i | |
|
7902 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
7903 |
] |
|
5755 | 7904 |
]. |
7905 |
^ false |
|
7906 |
||
7907 |
" |
|
10460 | 7908 |
(1 @ 3.4) referencesInstanceOf:Float |
7909 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
7910 |
View new initialize referencesInstanceOf:(Display class) |
|
5755 | 7911 |
" |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7912 |
! |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7913 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7914 |
referencesObject:anObject |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7915 |
"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
|
7916 |
- for debugging only" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7917 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7918 |
%{ /* NOCONTEXT */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7919 |
OBJ cls, flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7920 |
int nInsts, i; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7921 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7922 |
if (! __isNonNilObject(self)) { |
14975 | 7923 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7924 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7925 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7926 |
/* |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7927 |
* 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
|
7928 |
* 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
|
7929 |
* 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
|
7930 |
*/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7931 |
if (__isNonNilObject(anObject)) { |
14975 | 7932 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7933 |
int spc; |
|
7934 |
||
7935 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7936 |
RETURN (false); |
|
7937 |
} |
|
7938 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7939 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7940 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7941 |
cls = __qClass(self); |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7942 |
if (cls == anObject) { |
14975 | 7943 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7944 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7945 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7946 |
flags = __ClassInstPtr(cls)->c_flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7947 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
14975 | 7948 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7949 |
} else { |
14975 | 7950 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7951 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7952 |
if (! nInsts) { |
14975 | 7953 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7954 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7955 |
#if defined(memsrch4) |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7956 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
14975 | 7957 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7958 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7959 |
#else |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7960 |
for (i=0; i<nInsts; i++) { |
14975 | 7961 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7962 |
RETURN (true); |
|
7963 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7964 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7965 |
#endif /* memsrch4 */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7966 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7967 |
%}. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7968 |
|
10460 | 7969 |
"/ |myClass |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7970 |
"/ numInst "{ Class: SmallInteger }" | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7971 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7972 |
"/ myClass := self class. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7973 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7974 |
"/ "check the class" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7975 |
"/ (myClass == anObject) ifTrue:[^ true]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7976 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7977 |
"/ "check the instance variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7978 |
"/ numInst := myClass instSize. |
10460 | 7979 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7980 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7981 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7982 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7983 |
"/ "check the indexed variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7984 |
"/ myClass isVariable ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7985 |
"/ myClass isPointers ifFalse:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7986 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7987 |
"/ "/ 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
|
7988 |
"/ "/ 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
|
7989 |
"/ "/ 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
|
7990 |
"/ "/ 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
|
7991 |
"/ "/ 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
|
7992 |
"/ "/ 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
|
7993 |
"/ "/ 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
|
7994 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7995 |
"/ ^ false. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7996 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7997 |
"/ "/ alternative: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7998 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7999 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8000 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8001 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8002 |
"/ "/ 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
|
8003 |
"/ "/ idenitytIndex method, use it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8004 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8005 |
"/ myClass == Array ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8006 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8007 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8008 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8009 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8010 |
"/ "/ otherwise, do it the slow way |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8011 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8012 |
"/ numInst := self basicSize. |
10460 | 8013 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8014 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8015 |
"/ ] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8016 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8017 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8018 |
^ false |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8019 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8020 |
" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8021 |
|v| |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8022 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8023 |
v := View new initialize. |
10460 | 8024 |
v references:Display. |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8025 |
" |
5755 | 8026 |
! ! |
8027 |
||
8028 |
!Object methodsFor:'synchronized evaluation'! |
|
8029 |
||
10460 | 8030 |
freeSynchronizationSemaphore |
5755 | 8031 |
"free synchronizationSemaphore. May be used, to save memory when |
8032 |
an object is no longer used synchronized." |
|
8033 |
||
8034 |
|sema| |
|
8035 |
||
8036 |
sema := self synchronizationSemaphore. |
|
8037 |
sema notNil ifTrue:[ |
|
14975 | 8038 |
sema wait. "/ get lock |
8039 |
self synchronizationSemaphore:nil. |
|
5755 | 8040 |
]. |
8041 |
||
8042 |
" |
|
8043 |
self synchronized:[]. |
|
8044 |
self synchronizationSemaphore. |
|
8045 |
self freeSynchronizationSemaphore. |
|
8046 |
" |
|
8047 |
||
8048 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
8049 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
8050 |
! |
|
8051 |
||
8052 |
synchronizationSemaphore |
|
8053 |
"return the synchronization semaphore for myself. |
|
8054 |
subclasses may redefine" |
|
8055 |
||
8056 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
8057 |
||
8058 |
" |
|
8059 |
self synchronizationSemaphore |
|
8060 |
" |
|
8061 |
||
8062 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
8063 |
! |
|
8064 |
||
8065 |
synchronizationSemaphore:aSemaphore |
|
8066 |
"set the synchronisationSemaphore for myself. |
|
8067 |
subclasses may redefine this method" |
|
8068 |
||
8069 |
aSemaphore isNil ifTrue:[ |
|
14975 | 8070 |
"/ remove Semaphore |
8071 |
SynchronizationSemaphores removeKey:self ifAbsent:nil. |
|
5755 | 8072 |
] ifFalse:[ |
14975 | 8073 |
SynchronizationSemaphores at:self put:aSemaphore. |
5755 | 8074 |
]. |
8075 |
||
8076 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
8077 |
! |
|
8078 |
||
8079 |
synchronized:aBlock |
|
8080 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
8081 |
||
6600 | 8082 |
|sema wasBlocked| |
8083 |
||
8084 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5755 | 8085 |
|
8086 |
sema := self synchronizationSemaphore. |
|
8087 |
sema isNil ifTrue:[ |
|
14975 | 8088 |
sema := RecursionLock new name:self className. |
8089 |
self synchronizationSemaphore:sema. |
|
5755 | 8090 |
]. |
8091 |
||
6600 | 8092 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
7211
87f5d25b5c3d
Make synchronizationSemaphore a recursionLock
Stefan Vogel <sv@exept.de>
parents:
7208
diff
changeset
|
8093 |
sema critical:aBlock. |
5755 | 8094 |
|
8095 |
" |
|
8096 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
8097 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
8098 |
" |
|
8099 |
||
8100 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
8101 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
|
8102 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
|
8103 |
! ! |
|
8104 |
||
8105 |
!Object methodsFor:'system primitives'! |
|
8106 |
||
8107 |
asOop |
|
8108 |
"ST-80 compatibility: |
|
8109 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
8110 |
or index); since ST/X has no such thing, and the objects address cannot |
|
10460 | 8111 |
be used (since its changing over time), we return the objects identityHash |
5755 | 8112 |
key, which provides (at least) some identity indication. |
8113 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
8114 |
key of two non-identical objects may be the same. |
|
8115 |
You'd better not use it - especially do not misuse it." |
|
8116 |
||
8117 |
^ self identityHash |
|
8118 |
||
8119 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
8120 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
8121 |
! |
|
8122 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8123 |
beImmutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8124 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8125 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8126 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8127 |
if (! __isNonNilObject(self)) { |
14975 | 8128 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8129 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8130 |
__beImmutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8131 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8132 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8133 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8134 |
beMutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8135 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8136 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8137 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8138 |
if (! __isNonNilObject(self)) { |
14975 | 8139 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8140 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8141 |
__beMutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8142 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8143 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8144 |
|
5755 | 8145 |
become:anotherObject |
8146 |
"make all references to the receiver become references to anotherObject |
|
8147 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
|
8148 |
This can be a very dangerous operation - be warned. |
|
10460 | 8149 |
In general, using #become: should be avoided if possible, since it may |
5755 | 8150 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
8151 |
||
10460 | 8152 |
This may also be an expensive (i.e. slow) operation, |
8153 |
since in the worst case, the whole memory has to be searched for |
|
5755 | 8154 |
references to the two objects (although the primitive tries hard to |
10460 | 8155 |
limit the search, for acceptable performance in most cases). |
8156 |
This method fails, if the receiver or the argument is a SmallInteger |
|
8157 |
or nil, or is a context of a living method (i.e. one that has not already |
|
5755 | 8158 |
returned). |
10460 | 8159 |
(notice that #become: is not used heavily by the system |
5755 | 8160 |
- the Collection-classes have been rewritten to not use it.)" |
8161 |
%{ |
|
8162 |
if (__primBecome(self, anotherObject)) { |
|
14975 | 8163 |
RETURN ( self ); |
5755 | 8164 |
} |
8165 |
%}. |
|
8166 |
self primitiveFailed |
|
8167 |
! |
|
8168 |
||
8169 |
becomeNil |
|
8170 |
"make all references to the receiver become nil - effectively getting |
|
10460 | 8171 |
rid of the receiver. |
5755 | 8172 |
This can be a very dangerous operation - be warned. |
8173 |
||
8174 |
This may be an expensive (i.e. slow) operation. |
|
8175 |
The receiver may not be a SmallInteger or a context of a living method." |
|
8176 |
||
8177 |
%{ |
|
8178 |
if (__primBecomeNil(self)) { |
|
14975 | 8179 |
RETURN ( nil ); |
5755 | 8180 |
} |
8181 |
%}. |
|
8182 |
self primitiveFailed |
|
8183 |
! |
|
8184 |
||
8185 |
becomeSameAs:anotherObject |
|
8186 |
"make all references to the receiver become references to anotherObject |
|
8187 |
but NOT vice versa (as done in #become:). |
|
8188 |
This can be a very dangerous operation - be warned. |
|
10460 | 8189 |
In general, using #become: should be avoided if possible, since it may |
5755 | 8190 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
8191 |
||
8192 |
This may also be an expensive (i.e. slow) operation, |
|
8193 |
since in the worst case, the whole memory has to be searched for |
|
8194 |
references to the two objects (although the primitive tries hard to |
|
8195 |
limit the search, for acceptable performance in most cases). |
|
8196 |
This method fails, if the receiver or the argument is a SmallInteger |
|
8197 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
8198 |
%{ |
|
8199 |
if (__primBecomeSameAs(self, anotherObject)) { |
|
14975 | 8200 |
RETURN ( self ); |
5755 | 8201 |
} |
8202 |
%}. |
|
8203 |
self primitiveFailed |
|
8204 |
! |
|
8205 |
||
8206 |
changeClassTo:otherClass |
|
8207 |
"changes the class of the receiver to the argument, otherClass. |
|
8208 |
This is only allowed (possible), if the receivers class and the argument |
|
8209 |
have the same structure (i.e. number of named instance variables and |
|
10460 | 8210 |
type of indexed instance variables). |
5755 | 8211 |
If the structures do not match, or any of the original class or new class |
8212 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
8213 |
||
8214 |
|myClass ok| |
|
8215 |
||
9405 | 8216 |
otherClass autoload. |
8217 |
||
5755 | 8218 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
8219 |
%{ |
|
8220 |
{ |
|
14975 | 8221 |
OBJ other = otherClass; |
8222 |
||
8223 |
if (__isNonNilObject(self) |
|
8224 |
&& __isNonNilObject(other) |
|
8225 |
&& (other != UndefinedObject) |
|
8226 |
&& (other != SmallInteger)) { |
|
8227 |
ok = true; |
|
8228 |
} else { |
|
8229 |
ok = false; |
|
8230 |
} |
|
5755 | 8231 |
} |
8232 |
%}. |
|
8233 |
ok ifTrue:[ |
|
14975 | 8234 |
ok := false. |
8235 |
myClass := self class. |
|
8236 |
myClass flags == otherClass flags ifTrue:[ |
|
8237 |
myClass instSize == otherClass instSize ifTrue:[ |
|
8238 |
"same instance layout and types: its ok to do it" |
|
8239 |
ok := true. |
|
8240 |
] ifFalse:[ |
|
8241 |
myClass isPointers ifTrue:[ |
|
8242 |
myClass isVariable ifTrue:[ |
|
8243 |
ok := true |
|
8244 |
] |
|
8245 |
] |
|
8246 |
] |
|
8247 |
] ifFalse:[ |
|
8248 |
myClass isPointers ifTrue:[ |
|
8249 |
"if newClass is a variable class, with instSize <= my instsize, |
|
8250 |
we can do it (effectively mapping additional instvars into the |
|
8251 |
variable part) - usefulness is questionable, though" |
|
8252 |
||
8253 |
otherClass isPointers ifTrue:[ |
|
8254 |
otherClass isVariable ifTrue:[ |
|
8255 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
8256 |
ifTrue:[ |
|
8257 |
ok := true |
|
8258 |
] |
|
8259 |
] ifFalse:[ |
|
8260 |
otherClass instSize == (myClass instSize + self basicSize) |
|
8261 |
ifTrue:[ |
|
8262 |
ok := true |
|
8263 |
] |
|
8264 |
] |
|
8265 |
] ifFalse:[ |
|
8266 |
"it does not make sense to convert pointers to bytes ..." |
|
8267 |
] |
|
8268 |
] ifFalse:[ |
|
8269 |
"does it make sense, to convert bits ?" |
|
8270 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
8271 |
(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[ |
|
8272 |
ok := true |
|
8273 |
] |
|
8274 |
] |
|
8275 |
] |
|
5755 | 8276 |
]. |
8277 |
ok ifTrue:[ |
|
14975 | 8278 |
"now, change the receivers class ..." |
5755 | 8279 |
%{ |
14975 | 8280 |
{ |
8281 |
OBJ me = self; |
|
8282 |
||
15128 | 8283 |
// gcc4.4 does not like this: |
8284 |
// __qClass(me) = otherClass; |
|
14975 | 8285 |
__objPtr(me)->o_class = (CLASS_OBJ)otherClass; |
8286 |
__STORE(me, otherClass); |
|
8287 |
RETURN (me); |
|
8288 |
} |
|
5755 | 8289 |
%}. |
8290 |
]. |
|
9405 | 8291 |
|
5755 | 8292 |
" |
8293 |
the receiver cannot be represented as a instance of |
|
8294 |
the desired class. |
|
10460 | 8295 |
For example, you cannot change a bitInstance (byteArray etc.) |
5755 | 8296 |
into a pointer object and vice versa. |
8297 |
" |
|
8298 |
self primitiveFailed |
|
8299 |
! |
|
8300 |
||
8301 |
changeClassToThatOf:anObject |
|
8302 |
"changes the class of the receiver to that of the argument, anObject. |
|
8303 |
This is only allowed (possible), if the receivers class and the arguments |
|
10460 | 8304 |
class have the same structure (i.e. number of named instance variables and |
5755 | 8305 |
type of indexed instance variables). If the structures do not match, or any |
8306 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
8307 |
||
8308 |
self changeClassTo:(anObject class) |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8309 |
! |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8310 |
|
8935 | 8311 |
isImmutable |
8312 |
"experimental - not yet usable; do not use" |
|
8313 |
||
8314 |
%{ /* NOCONTEXT */ |
|
8315 |
if (! __isNonNilObject(self)) { |
|
14975 | 8316 |
RETURN (true); |
8935 | 8317 |
} |
8318 |
RETURN (__isImmutable(self) ? true : false); |
|
8319 |
%} |
|
8320 |
! |
|
8321 |
||
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8322 |
replaceReferencesTo:anObject with:newRef |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8323 |
"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
|
8324 |
Return true, if any reference was changed. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8325 |
Notice: this does not change the class-reference." |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8326 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8327 |
%{ /* NOCONTEXT */ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8328 |
OBJ cls, flags, anyChange; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8329 |
int nInsts, i; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8330 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8331 |
if (! __isNonNilObject(self)) { |
14975 | 8332 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8333 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8334 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8335 |
/* |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8336 |
* a little optimization: use the fact that all old objects |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8337 |
* 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
|
8338 |
* a trivial reject is possible, if anObject is a newbee |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8339 |
*/ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8340 |
if (__isNonNilObject(anObject)) { |
14975 | 8341 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
8342 |
int spc; |
|
8343 |
||
8344 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
8345 |
RETURN (false); |
|
8346 |
} |
|
8347 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8348 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8349 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8350 |
cls = __qClass(self); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8351 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8352 |
flags = __ClassInstPtr(cls)->c_flags; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8353 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
14975 | 8354 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8355 |
} else { |
14975 | 8356 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8357 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8358 |
if (! nInsts) { |
14975 | 8359 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8360 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8361 |
anyChange = false; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8362 |
for (i=0; i<nInsts; i++) { |
14975 | 8363 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
8364 |
__InstPtr(self)->i_instvars[i] = newRef; |
|
8365 |
__STORE(self, newRef); |
|
8366 |
anyChange = true; |
|
8367 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8368 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8369 |
RETURN (anyChange); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8370 |
%}. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8371 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8372 |
" |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8373 |
|v| |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8374 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8375 |
v := Array with:1234 with:'hello' with:Array. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8376 |
v replaceReferencesTo:Array with:ByteArray. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8377 |
v inspect |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8378 |
" |
5755 | 8379 |
! ! |
8380 |
||
8381 |
!Object methodsFor:'testing'! |
|
8382 |
||
8383 |
? defaultValue |
|
11634 | 8384 |
"a syntactic sugar-piece: |
5755 | 8385 |
if the receiver is nil, return the defaultValue; |
8386 |
otherwise, return the receiver. |
|
8387 |
This method is only redefined in UndefinedObject - therefore, |
|
8388 |
the recevier is retuned here. |
|
8389 |
||
8390 |
Thus, if foo and bar are simple variables or constants, |
|
14975 | 8391 |
foo ? bar |
5755 | 8392 |
is the same as: |
14975 | 8393 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
5755 | 8394 |
|
8395 |
if they are message sends, the equivalent code is: |
|
14975 | 8396 |
[ |
8397 |
|t1 t2| |
|
8398 |
||
8399 |
t1 := foo. |
|
8400 |
t2 := bar. |
|
8401 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
8402 |
] value |
|
5755 | 8403 |
|
8404 |
Can be used to provide defaultValues to variables, |
|
8405 |
as in: |
|
14975 | 8406 |
foo := arg ? #defaultValue |
5755 | 8407 |
|
8408 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8409 |
Notice: |
|
14975 | 8410 |
This method is open coded (inlined) by the compiler(s) |
8411 |
- redefining it may not work as expected." |
|
5755 | 8412 |
|
8413 |
^ self |
|
8414 |
||
8415 |
" |
|
8416 |
1 ? #default |
|
8417 |
nil ? #default |
|
8418 |
" |
|
8419 |
||
8420 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8421 |
"Modified: / 19.5.1998 / 17:39:56 / cg" |
|
8422 |
! |
|
8423 |
||
8424 |
?? defaultValue |
|
11634 | 8425 |
"a syntactic sugar-piece: |
5755 | 8426 |
much like ?, but sends #value to the argument if required. |
8427 |
(i.e. its the same as #ifNil:) |
|
8428 |
If the receiver is nil, return the defaultValues value; |
|
8429 |
otherwise, return the receiver. |
|
8430 |
This method is only redefined in UndefinedObject - therefore, |
|
8431 |
the recevier is retuned here. |
|
8432 |
||
8433 |
Thus, if foo and bar are simple variables or constants, |
|
14975 | 8434 |
foo ?? bar |
5755 | 8435 |
is the same as: |
14975 | 8436 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
5755 | 8437 |
|
8438 |
if they are message sends, the equivalent code is: |
|
14975 | 8439 |
[ |
8440 |
|t t2| |
|
8441 |
||
8442 |
t := foo. |
|
8443 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
8444 |
] value |
|
5755 | 8445 |
|
8446 |
Can be used to provide defaultValues to variables, |
|
8447 |
as in: |
|
14975 | 8448 |
foo := arg ?? [ self computeDefault ] |
5755 | 8449 |
|
8450 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8451 |
" |
|
8452 |
||
8453 |
^ self |
|
8454 |
||
8455 |
" |
|
10460 | 8456 |
1 ?? #default |
5755 | 8457 |
nil ?? #default |
10460 | 8458 |
1 ?? [ self halt. 1 + 2 ] |
8459 |
nil ?? [ self halt. 1 + 2 ] |
|
8460 |
1 ?? [Date today] |
|
8461 |
nil ?? [Date today] |
|
5755 | 8462 |
" |
8463 |
||
8464 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8465 |
"Modified: / 19.5.1998 / 17:42:56 / cg" |
|
8466 |
! |
|
8467 |
||
8468 |
ifNil:aBlockOrValue |
|
8469 |
"return myself, or the result from evaluating the argument, if I am nil. |
|
8470 |
This is much like #?, but sends #value to the argument in case of a nil |
|
8471 |
receiver. |
|
8472 |
Notice: |
|
14975 | 8473 |
This method is open coded (inlined) by the compiler(s) |
8474 |
- redefining it may not work as expected." |
|
5755 | 8475 |
|
8476 |
^ self |
|
8477 |
! |
|
8478 |
||
8479 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
|
8480 |
"return the value of the first arg, if I am nil, |
|
8481 |
the result from evaluating the 2nd argument, if I am not nil. |
|
8482 |
Notice: |
|
14975 | 8483 |
This method is open coded (inlined) by the compiler(s) |
8484 |
- redefining it may not work as expected." |
|
5755 | 8485 |
|
8486 |
^ notNilBlockOrValue value |
|
8487 |
||
8488 |
! |
|
8489 |
||
8490 |
ifNotNil:aBlockOrValue |
|
10460 | 8491 |
"return myself if nil, or the result from evaluating the argument, |
5755 | 8492 |
if I am not nil. |
8493 |
Notice: |
|
14975 | 8494 |
This method is open coded (inlined) by the compiler(s) |
8495 |
- redefining it may not work as expected." |
|
5755 | 8496 |
|
8497 |
^ aBlockOrValue value |
|
8498 |
||
8499 |
! |
|
8500 |
||
8501 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
|
8502 |
"return the value of the 2nd arg, if I am nil, |
|
8503 |
the result from evaluating the 1st argument, if I am not nil. |
|
8504 |
Notice: |
|
14975 | 8505 |
This method is open coded (inlined) by the compiler(s) |
8506 |
- redefining it may not work as expected." |
|
5755 | 8507 |
|
8508 |
^ notNilBlockOrValue value |
|
8509 |
||
8510 |
||
8511 |
! |
|
8512 |
||
8574 | 8513 |
ifNotNilDo:aBlock |
8514 |
"if the reciever is non-nil, return the value of aBlock, passing myself as argument. |
|
8515 |
Otherwise do nothing and return nil." |
|
8516 |
||
8517 |
^ aBlock value:self |
|
8518 |
! |
|
8519 |
||
5755 | 8520 |
isArray |
8521 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
8522 |
false is returned here - the method is only redefined in Array." |
|
8523 |
||
8524 |
^ false |
|
8525 |
! |
|
8526 |
||
8527 |
isAssociation |
|
8528 |
"return true, if the receiver is some kind of association; |
|
8529 |
false is returned here - the method is only redefined in Association." |
|
8530 |
||
8531 |
^ false |
|
8532 |
||
8533 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
8534 |
! |
|
8535 |
||
8536 |
isBehavior |
|
9221 | 8537 |
"return true, if the receiver is describing another objects behavior. |
8538 |
False is returned here - the method is only redefined in Behavior." |
|
5755 | 8539 |
|
8540 |
^ false |
|
8541 |
! |
|
8542 |
||
8543 |
isBlock |
|
8544 |
"return true, if the receiver is some kind of block; |
|
8545 |
false returned here - the method is only redefined in Block." |
|
8546 |
||
8547 |
^ false |
|
8548 |
! |
|
8549 |
||
5824 | 8550 |
isBoolean |
8551 |
"return true, if the receiver is a boolean; |
|
8552 |
false is returned here - the method is only redefined in Boolean." |
|
8553 |
||
8554 |
^ false |
|
8555 |
! |
|
8556 |
||
5755 | 8557 |
isByteArray |
8558 |
"return true, if the receiver is some kind of bytearray; |
|
8559 |
false is returned here - the method is only redefined in ByteArray." |
|
8560 |
||
8561 |
^ false |
|
8562 |
! |
|
8563 |
||
8986 | 8564 |
isByteCollection |
8565 |
"return true, if the receiver is some kind of byte collection, |
|
10460 | 8566 |
i.e. #at: and #at:put: accesses a byte. This is different from 'self class isBytes', |
8986 | 8567 |
since e.g. in BitArray single bits are accessed, but it is implemented as variableBytes class. |
10460 | 8568 |
|
8986 | 8569 |
false is returned here - the method is only redefined in UninterpretedBytes." |
8570 |
||
8571 |
^ false |
|
8572 |
! |
|
8573 |
||
5755 | 8574 |
isCharacter |
8575 |
"return true, if the receiver is some kind of character; |
|
8576 |
false is returned here - the method is only redefined in Character." |
|
8577 |
||
8578 |
^ false |
|
8579 |
! |
|
8580 |
||
8581 |
isClass |
|
9405 | 8582 |
"return true, if the receiver is some kind of class |
8583 |
(real class, not just behavior); |
|
5755 | 8584 |
false is returned here - the method is only redefined in Class." |
8585 |
||
8586 |
^ false |
|
8587 |
! |
|
8588 |
||
8589 |
isCollection |
|
8590 |
"return true, if the receiver is some kind of collection; |
|
8591 |
false is returned here - the method is only redefined in Collection." |
|
8592 |
||
8593 |
^ false |
|
8594 |
! |
|
8595 |
||
8596 |
isColor |
|
8597 |
"return true, if the receiver is some kind of color; |
|
8598 |
false is returned here - the method is only redefined in Color." |
|
8599 |
||
8600 |
^ false |
|
8601 |
! |
|
8602 |
||
6567 | 8603 |
isCons |
8604 |
"return true, if the receiver is a cons (pair); |
|
8605 |
false is returned here - the method is only redefined in Cons." |
|
8606 |
||
8607 |
^ false |
|
8608 |
! |
|
8609 |
||
5755 | 8610 |
isContext |
15362 | 8611 |
"return true, if the receiver is some kind of Context; |
5755 | 8612 |
false returned here - the method is only redefined in Context." |
8613 |
||
8614 |
^ false |
|
8615 |
! |
|
8616 |
||
15362 | 8617 |
isDictionary |
8618 |
"return true, if the receiver is some kind of dictionary; |
|
8619 |
false returned here - the method is only redefined in Dictionary." |
|
8620 |
||
8621 |
^ false |
|
8622 |
! |
|
8623 |
||
6181 | 8624 |
isEmptyOrNil |
8833 | 8625 |
"return true if I am nil or an empty collection - return false here. |
8626 |
(from Squeak)" |
|
6181 | 8627 |
|
8628 |
^ false |
|
8629 |
||
8630 |
"Created: / 13.11.2001 / 13:17:04 / cg" |
|
6182 | 8631 |
"Modified: / 13.11.2001 / 13:28:40 / cg" |
6181 | 8632 |
! |
8633 |
||
6221 | 8634 |
isException |
15362 | 8635 |
"answer true, if this is an Exception" |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8636 |
|
6221 | 8637 |
^ false |
8638 |
||
8639 |
"Created: / 17.11.2001 / 18:37:44 / cg" |
|
8640 |
! |
|
8641 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8642 |
isExceptionCreator |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8643 |
"return true, if the receiver can create exceptions, |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8644 |
this includes #raise, #raiseRequest as well as the behavior of |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8645 |
an exception handler, such as the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8646 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8647 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8648 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8649 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8650 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8651 |
"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
|
8652 |
especially to the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8653 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8654 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8655 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8656 |
|
13187 | 8657 |
isExternalAddress |
8658 |
"return true, if the receiver is some kind of externalAddress; |
|
8659 |
false is returned here - the method is only redefined in ExternalAddress." |
|
8660 |
||
8661 |
^ false |
|
8662 |
||
8663 |
"Created: / 22-12-2010 / 17:20:36 / cg" |
|
8664 |
! |
|
8665 |
||
14079 | 8666 |
isExternalBytes |
8667 |
^ false |
|
8668 |
! |
|
8669 |
||
10480 | 8670 |
isExternalLibraryFunction |
8671 |
"return true, if the receiver is some kind of externalLibrary function; |
|
8672 |
false is returned here - the method is only redefined in ExternalLibraryFunction." |
|
8673 |
||
8674 |
^false |
|
8675 |
! |
|
8676 |
||
5755 | 8677 |
isExternalStream |
8678 |
"return true, if the receiver is some kind of externalStream; |
|
8679 |
false is returned here - the method is only redefined in ExternalStream." |
|
8680 |
||
8681 |
^false |
|
8682 |
! |
|
8683 |
||
8684 |
isFileStream |
|
8685 |
"return true, if the receiver is some kind of fileStream; |
|
8686 |
false is returned here - the method is only redefined in FileStream." |
|
8687 |
||
8688 |
^false |
|
8689 |
! |
|
8690 |
||
8691 |
isFilename |
|
8692 |
"return true, if the receiver is some kind of filename; |
|
8693 |
false is returned here - the method is only redefined in Filename." |
|
8694 |
||
8695 |
^false |
|
8696 |
! |
|
8697 |
||
8698 |
isFixedPoint |
|
8699 |
"return true, if the receiver is some kind of fixedPoint number; |
|
8700 |
false is returned here - the method is only redefined in FixedPoint." |
|
8701 |
||
8702 |
^ false |
|
8703 |
||
8704 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
8705 |
! |
|
8706 |
||
8707 |
isFixedSize |
|
10460 | 8708 |
"return true if the receiver cannot grow easily |
5755 | 8709 |
(i.e. a grow may be expensive, since it involves a become:)" |
8710 |
||
8711 |
^ true |
|
8712 |
! |
|
8713 |
||
6185 | 8714 |
isFloat |
8715 |
"return true, if the receiver is some kind of floating point number; |
|
8716 |
false is returned here. |
|
8717 |
Same as #isLimitedPrecisionReal, but a better name ;-)" |
|
8718 |
||
8719 |
^ false |
|
8720 |
||
8721 |
"Modified: / 14.11.2001 / 14:57:46 / cg" |
|
8722 |
! |
|
8723 |
||
5755 | 8724 |
isForm |
8725 |
"return true, if the receiver is some kind of form; |
|
8726 |
false is returned here - the method is only redefined in Form." |
|
8727 |
||
8728 |
^ false |
|
8729 |
! |
|
8730 |
||
8731 |
isFraction |
|
8732 |
"return true, if the receiver is some kind of fraction; |
|
8733 |
false is returned here - the method is only redefined in Fraction." |
|
8734 |
||
8735 |
^ false |
|
8736 |
! |
|
8737 |
||
9293 | 8738 |
isHierarchicalItem |
8739 |
"used to decide if the parent is a hierarchical item or the model" |
|
8740 |
||
8741 |
^ false |
|
8742 |
! |
|
8743 |
||
5755 | 8744 |
isImage |
8745 |
"return true, if the receiver is some kind of image; |
|
8746 |
false is returned here - the method is only redefined in Image." |
|
8747 |
||
8748 |
^ false |
|
8749 |
! |
|
8750 |
||
8751 |
isImageOrForm |
|
8752 |
"return true, if the receiver is some kind of image or form; |
|
8753 |
false is returned here - the method is only redefined in Image and Form." |
|
8754 |
||
8755 |
^ false |
|
8756 |
! |
|
8757 |
||
8758 |
isImmediate |
|
8759 |
"return true if I am an immediate object |
|
8760 |
i.e. I am represented in the pointer itself and |
|
8761 |
no real object header/storage is used me. |
|
8762 |
(currently, only SmallIntegers, some characters and nil return true)" |
|
8763 |
||
8764 |
^ self class hasImmediateInstances |
|
8765 |
||
8766 |
"Created: 3.6.1997 / 12:00:18 / cg" |
|
8767 |
! |
|
8768 |
||
8769 |
isInteger |
|
8770 |
"return true, if the receiver is some kind of integer number; |
|
8771 |
false is returned here - the method is only redefined in Integer." |
|
8772 |
||
8773 |
^ false |
|
8774 |
! |
|
8775 |
||
9279 | 8776 |
isInterestConverter |
8777 |
"return true if I am a kind of interest forwarder" |
|
8778 |
||
8779 |
^ false |
|
8780 |
! |
|
8781 |
||
10576 | 8782 |
isInternalByteStream |
8783 |
"return true, if the receiver is some kind of Stream for reading bytes; |
|
8784 |
false is returned here - the method is only redefined in PeekableStream." |
|
8785 |
||
8786 |
^false |
|
8787 |
||
8788 |
"Created: / 30-05-2007 / 16:15:33 / cg" |
|
8789 |
! |
|
8790 |
||
5755 | 8791 |
isJavaClass |
8792 |
"return true, if this is a javaClass. |
|
8793 |
false is returned here - the method is only redefined in JavaClass." |
|
8794 |
||
8795 |
^ false |
|
8796 |
||
8797 |
"Created: / 26.3.1997 / 13:34:54 / cg" |
|
8798 |
"Modified: / 8.5.1998 / 21:25:21 / cg" |
|
8799 |
! |
|
8800 |
||
8801 |
isJavaClassRef |
|
8802 |
"return true, if this is a JavaClassRef. |
|
8803 |
false is returned here - the method is only redefined in JavaClassRef." |
|
8804 |
||
8805 |
^ false |
|
8806 |
||
8807 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8808 |
"Created: / 24.12.1999 / 01:46:28 / cg" |
|
8809 |
! |
|
8810 |
||
8811 |
isJavaContext |
|
8812 |
"return true, if this is a javaContext. |
|
8813 |
false is returned here - the method is only redefined in JavaContext." |
|
8814 |
||
8815 |
^ false |
|
8816 |
||
8817 |
"Created: / 8.5.1998 / 21:24:27 / cg" |
|
8818 |
"Modified: / 8.5.1998 / 21:25:35 / cg" |
|
8819 |
! |
|
8820 |
||
8821 |
isJavaMethod |
|
8822 |
"return true, if this is a JavaMethod. |
|
8823 |
false is returned here - the method is only redefined in JavaMethod." |
|
8824 |
||
8825 |
^ false |
|
8826 |
||
8827 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8828 |
"Created: / 25.9.1999 / 23:26:12 / cg" |
|
8829 |
! |
|
8830 |
||
8831 |
isJavaMethodRef |
|
8832 |
"return true, if this is a JavaMethodRef. |
|
8833 |
false is returned here - the method is only redefined in JavaMethodRef." |
|
8834 |
||
8835 |
^ false |
|
8836 |
||
8837 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8838 |
"Created: / 23.12.1999 / 19:44:51 / cg" |
|
8839 |
! |
|
8840 |
||
8841 |
isJavaObject |
|
8842 |
"return true, if this is a javaObject. |
|
8843 |
false is returned here - the method is only redefined in JavaObject." |
|
8844 |
||
8845 |
^ false |
|
8846 |
||
8847 |
"Created: / 26.3.1997 / 13:34:48 / cg" |
|
8848 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8849 |
! |
|
8850 |
||
8851 |
isJavaScriptClass |
|
8852 |
"return true, if this is a javaScriptClass. |
|
8853 |
false is returned here - the method is only redefined in JavaScriptClass." |
|
8854 |
||
8855 |
^ false |
|
8856 |
! |
|
8857 |
||
8935 | 8858 |
isJavaScriptMetaclass |
8859 |
"return true, if this is a javaScript Metaclass. |
|
8860 |
false is returned here - the method is only redefined in JavaScriptMetaclass." |
|
8861 |
||
8862 |
^ false |
|
8863 |
! |
|
8864 |
||
5755 | 8865 |
isKindOf:aClass |
8866 |
"return true, if the receiver is an instance of aClass or one of its |
|
8867 |
subclasses, false otherwise. |
|
10460 | 8868 |
Advice: |
15243 | 8869 |
use of this to check objects for certain attributes/protocol should |
14975 | 8870 |
be avoided; it limits the reusability of your classes by limiting use |
8871 |
to instances of certain classes and fences you into a specific inheritance |
|
8872 |
hierarchy. |
|
8873 |
Use check-methods to check an object for a certain attributes/protocol |
|
8874 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
8875 |
||
8876 |
Using #isKindOf: is considered BAD STYLE. |
|
5755 | 8877 |
|
8878 |
Advice2: |
|
14975 | 8879 |
Be aware, that using an #isXXX method is usually much faster than |
8880 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
8881 |
hierarchy, comparing every class on the way. |
|
8882 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
8883 |
a single function call. |
|
5755 | 8884 |
" |
8885 |
||
8886 |
%{ /* NOCONTEXT */ |
|
8887 |
register OBJ thisClass; |
|
8888 |
||
8889 |
thisClass = __Class(self); |
|
8890 |
while (thisClass != nil) { |
|
14975 | 8891 |
if (thisClass == aClass) { |
8892 |
RETURN ( true ); |
|
8893 |
} |
|
8894 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
5755 | 8895 |
} |
8896 |
RETURN ( false ); |
|
8897 |
%} |
|
8898 |
||
8899 |
"/ |
|
8900 |
"/ the above code is equivalent to: |
|
8901 |
"/ |
|
8902 |
"/ thisClass := self class. |
|
8903 |
"/ [thisClass notNil] whileTrue:[ |
|
8904 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
8905 |
"/ thisClass := thisClass superclass |
|
8906 |
"/ ]. |
|
8907 |
"/ ^ false |
|
8908 |
"/ |
|
8909 |
! |
|
8910 |
||
8911 |
isLayout |
|
8912 |
"return true, if the receiver is some kind of layout; |
|
8913 |
false is returned here - the method is only redefined in Layout." |
|
8914 |
||
8915 |
^ false |
|
8916 |
! |
|
8917 |
||
6567 | 8918 |
isLazyValue |
8919 |
^ false |
|
8920 |
! |
|
8921 |
||
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8922 |
isLimitedPrecisionReal |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8923 |
"return true, if the receiver is some kind of floating point number; |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8924 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8925 |
|
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8926 |
^ false |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8927 |
! |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8928 |
|
5755 | 8929 |
isList |
8930 |
"return true, if the receiver is some kind of list collection; |
|
8931 |
false is returned here - the method is only redefined in List." |
|
8932 |
||
8933 |
^ false |
|
8934 |
||
8935 |
"Created: / 11.2.2000 / 01:37:05 / cg" |
|
8936 |
! |
|
8937 |
||
8938 |
isLiteral |
|
8939 |
"return true, if the receiver can be represented as a literal constant in ST syntax; |
|
8940 |
false is returned here - the method is redefined in some classes." |
|
8941 |
||
8942 |
^ false |
|
8943 |
! |
|
8944 |
||
8945 |
isMemberOf:aClass |
|
8946 |
"return true, if the receiver is an instance of aClass, false otherwise. |
|
10460 | 8947 |
Advice: |
14975 | 8948 |
use of this to check objects for certain attributes/protocol should |
8949 |
be avoided; it limits the reusability of your classes by limiting use |
|
8950 |
to instances of a certain class. |
|
8951 |
Use check-methods to check an object for a certain attributes/protocol |
|
8952 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
8953 |
||
8954 |
Using #isMemberOf: is considered BAD STYLE. |
|
5755 | 8955 |
Notice: |
14975 | 8956 |
This method is open coded (inlined) by the compiler(s) |
8957 |
- redefining it may not work as expected." |
|
5755 | 8958 |
|
8959 |
^ (self class) == aClass |
|
8960 |
! |
|
8961 |
||
8962 |
isMeta |
|
8963 |
"return true, if the receiver is some kind of metaclass; |
|
8964 |
false is returned here - the method is only redefined in Metaclass." |
|
8965 |
||
8966 |
^ false |
|
8967 |
! |
|
8968 |
||
8969 |
isMethod |
|
8970 |
"return true, if the receiver is some kind of method; |
|
8971 |
false returned here - the method is only redefined in Method." |
|
8972 |
||
8973 |
^ false |
|
8974 |
! |
|
8975 |
||
8976 |
isMorph |
|
8977 |
"return true, if the receiver is some kind of morph; |
|
8978 |
false is returned here - the method is only redefined in Morph." |
|
8979 |
||
8980 |
^ false |
|
8981 |
! |
|
8982 |
||
8983 |
isNameSpace |
|
9221 | 8984 |
"return true, if the receiver is a nameSpace. |
8985 |
False is returned here - the method is only redefined in Namespace." |
|
5755 | 8986 |
|
8987 |
^ false |
|
8988 |
||
8989 |
"Created: / 11.10.1996 / 18:08:56 / cg" |
|
8990 |
"Modified: / 8.5.1998 / 21:26:05 / cg" |
|
8991 |
! |
|
8992 |
||
8993 |
isNamespace |
|
8994 |
"return true, if this is a nameSpace. |
|
8995 |
false is returned here - the method is only redefined in Namespace." |
|
8996 |
||
5869 | 8997 |
<resource:#obsolete> |
8998 |
||
5755 | 8999 |
self obsoleteMethodWarning:'use #isNameSpace'. |
6805 | 9000 |
^ self isNameSpace |
5755 | 9001 |
! |
9002 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9003 |
isNil |
9221 | 9004 |
"Return true, if the receiver is nil. |
9005 |
Because isNil is redefined in UndefinedObject, |
|
9006 |
the receiver is definitely not nil here, so unconditionally return false. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9007 |
Notice: |
14975 | 9008 |
This method is open coded (inlined) by the compiler(s) |
9009 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9010 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9011 |
^ false |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9012 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9013 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9014 |
isNilOrEmptyCollection |
6182 | 9015 |
"return true if I am nil or an empty collection - false here. |
8833 | 9016 |
Obsolete, use isEmptyOrNil." |
9017 |
||
9018 |
<resource:#obsolete> |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9019 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9020 |
^ false |
6182 | 9021 |
|
9022 |
"Modified: / 13.11.2001 / 13:28:06 / cg" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9023 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9024 |
|
9005 | 9025 |
isNonByteCollection |
9026 |
"return true, if the receiver is some kind of collection, but not a String, ByteArray etc.; |
|
9027 |
false is returned here - the method is redefined in Collection and UninterpretedBytes." |
|
9028 |
||
9029 |
^ false |
|
9030 |
||
9031 |
" |
|
14975 | 9032 |
21 isNonByteCollection |
9033 |
'abc' isNonByteCollection |
|
9034 |
#'abc' isNonByteCollection |
|
9035 |
#[1 2 3] isNonByteCollection |
|
9036 |
#(1 2 3) isNonByteCollection |
|
9005 | 9037 |
" |
9038 |
! |
|
9039 |
||
5755 | 9040 |
isNumber |
9041 |
"return true, if the receiver is some kind of number; |
|
9042 |
false is returned here - the method is only redefined in Number." |
|
9043 |
||
9044 |
^ false |
|
9045 |
! |
|
9046 |
||
9047 |
isOrderedCollection |
|
9048 |
"return true, if the receiver is some kind of ordered collection (or list etc); |
|
9049 |
false is returned here - the method is only redefined in OrderedCollection." |
|
9050 |
||
9051 |
^ false |
|
9052 |
! |
|
9053 |
||
9054 |
isPoint |
|
9055 |
"return true, if the receiver is some kind of point; |
|
9056 |
false is returned here - the method is only redefined in Point." |
|
9057 |
||
9058 |
^ false |
|
9059 |
! |
|
9060 |
||
10532 | 9061 |
isPrinterContext |
9062 |
||
9063 |
^false |
|
9064 |
! |
|
9065 |
||
13416 | 9066 |
isProgrammingLanguage |
9067 |
"return true, if the receiver is a programming language. |
|
14632 | 9068 |
False is returned here - the method is only redefined in |
13416 | 9069 |
ProgrammingLanguage." |
9070 |
||
9071 |
^ false |
|
9072 |
||
9073 |
"Created: / 21-07-2010 / 15:13:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
9074 |
! |
|
9075 |
||
9515 | 9076 |
isProjectDefinition |
9077 |
"return true, if the receiver is a projectDefinition. |
|
9078 |
False is returned here - the method is only redefined in ProjectDefinition." |
|
9079 |
||
9080 |
^ false |
|
9081 |
||
9082 |
"Created: / 10-08-2006 / 16:24:53 / cg" |
|
9083 |
! |
|
9084 |
||
13140 | 9085 |
isProxy |
9086 |
"return true, if the receiver is a proxy for another (lazy loaded) object. |
|
9087 |
False is returned here." |
|
9088 |
||
9089 |
^ false |
|
9090 |
||
9091 |
"Created: / 21-11-2010 / 11:15:46 / cg" |
|
9092 |
! |
|
9093 |
||
10171 | 9094 |
isRealNameSpace |
9095 |
"return true, if the receiver is really a nameSpace (i.e. a NameSpace, but not Smalltalk). |
|
9096 |
False is returned here - the method is only redefined in Namespace." |
|
9097 |
||
9098 |
^ false |
|
9099 |
||
9100 |
"Created: / 10-11-2006 / 17:05:43 / cg" |
|
9101 |
! |
|
9102 |
||
5755 | 9103 |
isRectangle |
9104 |
"return true, if the receiver is some kind of rectangle; |
|
9105 |
false is returned here - the method is only redefined in Rectangle." |
|
9106 |
||
9107 |
^ false |
|
9108 |
! |
|
9109 |
||
9110 |
isRemoteObject |
|
9111 |
"return true, if the receiver is some kind of remoteObject, |
|
9112 |
false if its local - the method is only redefined in RemoteObject." |
|
9113 |
||
9114 |
^ false |
|
9115 |
||
9116 |
"Created: 28.10.1996 / 15:18:45 / cg" |
|
9117 |
"Modified: 28.10.1996 / 15:20:57 / cg" |
|
9118 |
! |
|
9119 |
||
9120 |
isSequenceable |
|
9121 |
"return true, if the receiver is some kind of sequenceable collection; |
|
9122 |
false is returned here - the method is only redefined in SequenceableCollection." |
|
9123 |
||
9124 |
^ false |
|
9125 |
! |
|
9126 |
||
9127 |
isSequenceableCollection |
|
9128 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
9129 |
This method is a historic leftover and will be removed soon ... |
|
9130 |
(although its name is much better than #isSequenceable - sigh)" |
|
9131 |
||
5869 | 9132 |
<resource:#obsolete> |
9133 |
||
5755 | 9134 |
self obsoleteMethodWarning:'use #isSequenceable'. |
9135 |
^ false |
|
9136 |
! |
|
9137 |
||
10856 | 9138 |
isSharedPool |
9139 |
"return true, if the receiver is a sharedPool. |
|
9140 |
False is returned here - the method is only redefined in SharedPool." |
|
9141 |
||
9142 |
^ false |
|
9143 |
! |
|
9144 |
||
13565
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9145 |
isSpecialInstrumentationInfoLiteral |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9146 |
"return true, if the receiver is a special instrumentation info |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9147 |
object as placed into the literal array of instrumented methods" |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9148 |
|
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9149 |
^ false |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9150 |
|
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9151 |
"Created: / 07-08-2011 / 17:03:41 / cg" |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9152 |
! |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9153 |
|
5755 | 9154 |
isStream |
9155 |
"return true, if the receiver is some kind of stream; |
|
9156 |
false is returned here - the method is only redefined in Stream." |
|
9157 |
||
9158 |
^ false |
|
9159 |
! |
|
9160 |
||
9161 |
isString |
|
9162 |
"return true, if the receiver is some kind of string; |
|
9163 |
false is returned here - the method is only redefined in CharacterArray." |
|
9164 |
||
9165 |
^ false |
|
9166 |
! |
|
9167 |
||
9168 |
isStringCollection |
|
9169 |
"return true, if the receiver is some kind of stringCollection; |
|
9170 |
false is returned here - the method is only redefined in StringCollection." |
|
9171 |
||
9172 |
^ false |
|
9173 |
! |
|
9174 |
||
9175 |
isSymbol |
|
9176 |
"return true, if the receiver is some kind of symbol; |
|
9177 |
false is returned here - the method is only redefined in Symbol." |
|
9178 |
||
9179 |
^ false |
|
9180 |
! |
|
9181 |
||
9182 |
isText |
|
9183 |
"return true, if the receiver is some kind of text object; |
|
9184 |
false is returned here - the method is only redefined in Text." |
|
9185 |
||
9186 |
^ false |
|
9187 |
||
9188 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
9189 |
! |
|
9190 |
||
13656 | 9191 |
isTextView |
9192 |
"return true, if the receiver is some kind of textView; |
|
9193 |
false is returned here - the method is only redefined in TextViews." |
|
9194 |
||
9195 |
^ false |
|
9196 |
||
9197 |
"Modified (comment): / 08-09-2011 / 05:12:37 / cg" |
|
9198 |
! |
|
9199 |
||
13229 | 9200 |
isTimestamp |
9201 |
^ false |
|
9202 |
! |
|
9203 |
||
13626 | 9204 |
isTrait |
9205 |
"Return true if the receiver is a trait. |
|
9206 |
Note: Do not override in any class except TraitBehavior." |
|
9207 |
||
9208 |
^ false |
|
9209 |
||
9210 |
"Created: / 04-09-2011 / 20:04:43 / cg" |
|
9211 |
! |
|
9212 |
||
14296 | 9213 |
isUUID |
9214 |
^ false |
|
9215 |
! |
|
9216 |
||
5755 | 9217 |
isValueModel |
9218 |
"return true, if the receiver is some kind of valueModel; |
|
9219 |
false is returned here - the method is only redefined in ValueModel." |
|
9220 |
||
9221 |
^ false |
|
9222 |
||
9223 |
! |
|
9224 |
||
9225 |
isVariable |
|
9226 |
"return true if the receiver has indexed instance variables, |
|
9227 |
false otherwise." |
|
9228 |
||
9229 |
^ self class isVariable |
|
9230 |
! |
|
9231 |
||
9232 |
isVariableBinding |
|
9233 |
"return true, if this is a binding for a variable. |
|
9234 |
false is returned here - the method is only redefined in Binding." |
|
9235 |
||
9236 |
^ false |
|
9237 |
||
9238 |
"Created: / 19.6.1997 / 17:38:44 / cg" |
|
9239 |
"Modified: / 8.5.1998 / 21:26:55 / cg" |
|
9240 |
! |
|
9241 |
||
9242 |
isView |
|
9243 |
"return true, if the receiver is some kind of view; |
|
9244 |
false is returned here - the method is only redefined in View." |
|
9245 |
||
9246 |
^ false |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9247 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9248 |
|
6932 | 9249 |
notEmptyOrNil |
9250 |
"Squeak compatibility: |
|
9251 |
return true if I am neither nil nor an empty collection. |
|
9252 |
Return true here." |
|
9253 |
||
9254 |
^ true |
|
9255 |
! |
|
9256 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9257 |
notNil |
9221 | 9258 |
"Return true, if the receiver is not nil. |
9259 |
Because notNil is redefined in UndefinedObject, |
|
9260 |
the receiver is definitely not nil here, so unconditionally return true. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9261 |
Notice: |
14975 | 9262 |
This method is open coded (inlined) by the compiler(s) |
9263 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9264 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9265 |
^ true |
5755 | 9266 |
! ! |
9267 |
||
9268 |
!Object methodsFor:'tracing'! |
|
9269 |
||
9270 |
traceInto:aRequestor level:level from:referrer |
|
9271 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
9272 |
||
9273 |
^ aRequestor traceObject:self level:level from:referrer |
|
9274 |
||
9275 |
"Created: / 2.9.1999 / 09:05:17 / stefan" |
|
9276 |
! ! |
|
9277 |
||
9278 |
!Object methodsFor:'user interaction & notifications'! |
|
9279 |
||
9280 |
activityNotification:aString |
|
9281 |
"this can be sent from deeply nested methods, which are going to perform |
|
9282 |
some long-time activity. |
|
9283 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
9284 |
passing the argument. The handler should show this message whereever it likes, |
|
9285 |
and proceed. If there is no handler, this is simply ignored. |
|
9286 |
||
9287 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
9288 |
which likes to display that message in its label or a busy-box. |
|
9289 |
It could also be put into some logfile or printed on the standard output/error." |
|
9290 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
9291 |
ActivityNotification isHandled ifTrue:[ |
14975 | 9292 |
^ ActivityNotification raiseRequestWith:self errorString:aString |
5755 | 9293 |
]. |
9294 |
||
9295 |
" |
|
9296 |
nil activityNotification:'hello there' |
|
9297 |
self activityNotification:'hello there' |
|
9298 |
" |
|
9299 |
||
9300 |
" |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
9301 |
ActivityNotification handle:[:ex | |
14975 | 9302 |
ex errorString printCR. |
9303 |
ex proceed. |
|
5755 | 9304 |
] do:[ |
14975 | 9305 |
'hello' printCR. |
9306 |
self activityNotification:'doing some long time computation'. |
|
9307 |
'world' printCR. |
|
5755 | 9308 |
] |
9309 |
" |
|
9310 |
||
9311 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
9312 |
! |
|
9313 |
||
9314 |
confirm:aString |
|
9694 | 9315 |
"open a modal yes-no dialog. |
9316 |
Return true for yes, false for no. |
|
10527
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9317 |
If no GUI is present (headless applications), true is returned. |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9318 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9319 |
Someone in the sender chain may redefine the confirmation handler |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9320 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9321 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9322 |
^ UserConfirmation raiseRequestErrorString:aString |
10460 | 9323 |
|
5755 | 9324 |
" |
9325 |
nil confirm:'hello' |
|
9326 |
self confirm:'hello' |
|
9327 |
" |
|
9328 |
! |
|
9329 |
||
9330 |
confirm:aString orCancel:cancelBlock |
|
9331 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
9332 |
return true for yes, false for no, or the value from cancelBlock for cancel. |
|
9333 |
If no GUI is present (headless applications), cancelBlock is returned." |
|
9334 |
||
9335 |
|answer| |
|
9336 |
||
9337 |
answer := self confirmWithCancel:aString. |
|
9338 |
answer isNil ifTrue:[ |
|
14975 | 9339 |
^ cancelBlock value |
5755 | 9340 |
]. |
9341 |
^ answer |
|
10460 | 9342 |
|
5755 | 9343 |
" |
9344 |
self confirm:'hello' orCancel:[self halt] |
|
9345 |
" |
|
9346 |
||
9347 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
9348 |
! |
|
9349 |
||
9350 |
confirmWithCancel:aString |
|
9351 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
9352 |
return true for yes, false for no, nil for cancel. |
|
10527
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9353 |
If no GUI is present (headless applications), nil is returned. |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9354 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9355 |
Someone in the sender chain may redefine the confirmation handler |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9356 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9357 |
|
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9358 |
^ self confirmWithCancel:aString defaultAnswer:nil |
10460 | 9359 |
|
9360 |
" |
|
9361 |
nil confirmWithCancel:'hello' |
|
5755 | 9362 |
self confirmWithCancel:'hello' |
9363 |
" |
|
9364 |
! |
|
9365 |
||
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9366 |
confirmWithCancel:aString defaultAnswer:defaultAnswerOrNil |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9367 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9368 |
return true for yes, false for no, nil for cancel. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9369 |
If no GUI is present (headless applications), nil is returned. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9370 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9371 |
Someone in the sender chain may redefine the confirmation handler |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9372 |
by handling the UserConfirmation." |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9373 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9374 |
^ UserConfirmation new |
14975 | 9375 |
defaultAnswer:defaultAnswerOrNil; |
9376 |
canCancel:true; |
|
9377 |
errorString:aString; |
|
9378 |
raiseRequest |
|
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9379 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9380 |
" |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9381 |
nil confirmWithCancel:'hello' defaultAnswer:true |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9382 |
self confirmWithCancel:'hello' defaultAnswer:false |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9383 |
" |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9384 |
! |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9385 |
|
5755 | 9386 |
errorNotify:aString |
9387 |
"launch a Notifier, showing top stack, telling user something |
|
9388 |
and give user a chance to enter debugger." |
|
9389 |
||
9390 |
^ self |
|
14975 | 9391 |
errorNotify:aString |
9392 |
from:thisContext sender |
|
9393 |
allowDebug:true |
|
15255 | 9394 |
mayProceed:true |
5755 | 9395 |
|
9396 |
" |
|
9397 |
nil errorNotify:'hello there' |
|
9398 |
self errorNotify:'hello there' |
|
9399 |
" |
|
9400 |
||
6199 | 9401 |
"Modified: / 16.11.2001 / 15:36:49 / cg" |
5755 | 9402 |
! |
9403 |
||
9404 |
errorNotify:aString from:aContext |
|
10460 | 9405 |
"launch a Notifier, showing top stack (above aContext), |
5755 | 9406 |
telling user something and give user a chance to enter debugger." |
9407 |
||
15255 | 9408 |
^ self errorNotify:aString from:aContext allowDebug:true mayProceed:true |
5755 | 9409 |
|
9410 |
"Modified: / 17.8.1998 / 10:09:27 / cg" |
|
9411 |
! |
|
9412 |
||
9413 |
errorNotify:aString from:aContext allowDebug:allowDebug |
|
10460 | 9414 |
"launch a Notifier, showing top stack (above aContext), |
15255 | 9415 |
telling user something and give user a chance to enter debugger." |
9416 |
||
9417 |
^ self errorNotify:aString from:aContext allowDebug:allowDebug mayProceed:true |
|
9418 |
! |
|
9419 |
||
9420 |
errorNotify:aString from:aContext allowDebug:allowDebug mayProceed:mayProceed |
|
9421 |
"launch a Notifier, showing top stack (above aContext), |
|
5755 | 9422 |
telling user something and optionally give the user a chance to enter debugger." |
9423 |
||
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
9424 |
|currentScreen con sender action boxLabels boxValues default s| |
5755 | 9425 |
|
9426 |
Smalltalk isInitialized ifFalse:[ |
|
14975 | 9427 |
'errorNotification: ' print. aString printCR. |
15219 | 9428 |
con := aContext ? thisContext methodHome. |
9429 |
con sender printAllLevels:10. |
|
14975 | 9430 |
^ nil |
10460 | 9431 |
]. |
11531 | 9432 |
|
10460 | 9433 |
(Dialog isNil |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
9434 |
or:[Screen isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
9435 |
or:[(currentScreen := Screen current) isNil |
10460 | 9436 |
or:[currentScreen isOpen not]]]) ifTrue:[ |
14975 | 9437 |
" |
9438 |
on systems without GUI, simply show |
|
9439 |
the message on the Transcript and abort. |
|
9440 |
" |
|
9441 |
Transcript showCR:aString. |
|
9442 |
AbortOperationRequest raise. |
|
9443 |
"not reached" |
|
9444 |
^ nil |
|
5755 | 9445 |
]. |
9446 |
||
9447 |
Processor activeProcessIsSystemProcess ifTrue:[ |
|
14975 | 9448 |
action := #debug. |
9449 |
sender := aContext. |
|
9450 |
Debugger isNil ifTrue:[ |
|
9451 |
'****************** Cought Error while in SystemProcess ****************' errorPrintCR. |
|
9452 |
aString errorPrintCR. |
|
9453 |
Exception handle:[:ex | |
|
9454 |
'Cought recursive error while printing backtrace:' errorPrintCR. |
|
9455 |
ex description errorPrintCR. |
|
9456 |
] do:[ |
|
9457 |
thisContext fullPrintAll. |
|
9458 |
]. |
|
9459 |
action := #abort. |
|
9460 |
]. |
|
5755 | 9461 |
] ifFalse:[ |
14975 | 9462 |
Dialog autoload. "in case it's autoloaded" |
9463 |
||
9464 |
Error handle:[:ex | |
|
9465 |
"/ a recursive error - quickly enter debugger |
|
9466 |
"/ this happened, when I corrupted the Dialog class ... |
|
9467 |
('Object [error]: ' , ex description , ' caught in errorNotification') errorPrintCR. |
|
9468 |
action := #debug. |
|
9469 |
ex return. |
|
9470 |
] do:[ |s| |
|
9471 |
sender := aContext. |
|
9472 |
sender isNil ifTrue:[ |
|
15219 | 9473 |
sender := thisContext methodHome sender. |
14975 | 9474 |
]. |
9475 |
con := sender. |
|
9476 |
||
9477 |
"/ skip intermediate (signal & exception) contexts |
|
9478 |
DebugView notNil ifTrue:[ |
|
9479 |
con := DebugView interestingContextFrom:sender |
|
9480 |
]. |
|
9481 |
||
9482 |
"/ show the first few contexts |
|
9483 |
||
9484 |
s := WriteStream with:aString. |
|
9485 |
s cr; cr. |
|
9486 |
s nextPutLine:'Calling Chain:'. |
|
9487 |
s nextPutLine:'--------------------------------------------------------------'. |
|
9488 |
1 to:25 do:[:n | |
|
9489 |
con notNil ifTrue:[ |
|
9490 |
con printOn:s. |
|
9491 |
s cr. |
|
9492 |
con := con sender |
|
9493 |
] |
|
9494 |
]. |
|
9495 |
||
15255 | 9496 |
mayProceed ifTrue:[ |
9497 |
boxLabels := #('Proceed'). |
|
9498 |
boxValues := #(#proceed). |
|
9499 |
default := #proceed. |
|
9500 |
] ifFalse:[ |
|
9501 |
boxLabels := #(). |
|
9502 |
boxValues := #(). |
|
9503 |
]. |
|
14975 | 9504 |
|
9505 |
AbortOperationRequest isHandled ifTrue:[ |
|
9506 |
default := #abort. |
|
9507 |
boxLabels := boxLabels , #('Abort'). |
|
9508 |
boxValues := boxValues , #(#abort). |
|
9509 |
true "allowDebug" ifTrue:[ |
|
9510 |
boxLabels := boxLabels , #('Copy Trace and Abort'). |
|
9511 |
boxValues := boxValues , #(#copyAndAbort). |
|
9512 |
] |
|
9513 |
] ifFalse:[ |
|
15255 | 9514 |
mayProceed "and:[allowDebug]" ifTrue:[ |
14975 | 9515 |
boxLabels := boxLabels , #('Copy Trace and Proceed'). |
9516 |
boxValues := boxValues , #(#copyAndProceed). |
|
9517 |
]. |
|
9518 |
]. |
|
9519 |
||
9520 |
(allowDebug and:[Debugger notNil]) ifTrue:[ |
|
9521 |
boxLabels := boxLabels , #('Debug'). |
|
9522 |
boxValues := boxValues , #(#debug). |
|
9523 |
default := #debug. |
|
9524 |
]. |
|
9525 |
||
9526 |
action := Dialog |
|
9527 |
choose:s contents |
|
9528 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
|
9529 |
image:WarningBox errorIconBitmap |
|
9530 |
labels:boxLabels |
|
9531 |
values:boxValues |
|
9532 |
default:default |
|
9533 |
onCancel:nil. |
|
9534 |
]. |
|
5755 | 9535 |
]. |
9536 |
||
9537 |
action == #debug ifTrue:[ |
|
15255 | 9538 |
^ Debugger enter:sender withMessage:aString mayProceed:mayProceed |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9539 |
]. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9540 |
action == #proceed ifTrue:[ |
14975 | 9541 |
^ nil. |
11335 | 9542 |
]. |
9543 |
(action == #copyAndProceed |
|
9544 |
or:[action == #copyAndAbort]) ifTrue:[ |
|
14975 | 9545 |
s := '' writeStream. |
9546 |
Exception handle:[:ex | |
|
9547 |
'Cought recursive error while printing backtrace' errorPrintCR. |
|
9548 |
] do:[ |
|
9549 |
sender fullPrintAllOn:s. |
|
9550 |
]. |
|
9551 |
currentScreen rootView setClipboardText:s contents. |
|
9552 |
action == #copyAndProceed ifTrue:[ |
|
9553 |
^ nil |
|
9554 |
]. |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
9555 |
]. |
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
9556 |
|
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9557 |
AbortOperationRequest raise. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9558 |
"not reached" |
5755 | 9559 |
|
9560 |
" |
|
9561 |
nil errorNotify:'hello there' |
|
9562 |
self errorNotify:'hello there' |
|
9563 |
" |
|
9564 |
||
13165
66a6b37405d1
changed: #errorNotify:from:allowDebug:
Claus Gittinger <cg@exept.de>
parents:
13162
diff
changeset
|
9565 |
"Created: / 17-08-1998 / 10:09:26 / cg" |
13566 | 9566 |
"Modified: / 08-08-2011 / 11:26:17 / sr" |
13844
f03a655457f4
changed: #errorNotify:from:allowDebug:
Claus Gittinger <cg@exept.de>
parents:
13812
diff
changeset
|
9567 |
"Modified: / 05-12-2011 / 03:50:59 / cg" |
5755 | 9568 |
! |
9569 |
||
9570 |
information:aString |
|
10460 | 9571 |
"launch an InfoBox, telling user something. |
9572 |
These info-boxes can be suppressed by handling |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9573 |
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
|
9574 |
Use #notify: for more important messages. |
8371 | 9575 |
If nobody handles the exception, the default action of UserNotification |
10527
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9576 |
pops up an info dialog." |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9577 |
|
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
9578 |
UserInformation raiseRequestWith:self errorString:aString |
5755 | 9579 |
|
9580 |
" |
|
9581 |
nil information:'hello there' |
|
9582 |
self information:'hello there' |
|
9583 |
" |
|
9584 |
||
9585 |
" |
|
9586 |
InformationSignal handle:[:ex | |
|
14975 | 9587 |
'no box popped' printCR. |
9588 |
ex proceed. |
|
5755 | 9589 |
] do:[ |
14975 | 9590 |
'hello' printCR. |
9591 |
self information:'some info'. |
|
9592 |
'world' printCR. |
|
5755 | 9593 |
] |
9594 |
" |
|
9595 |
||
9596 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
9597 |
! |
|
9598 |
||
9599 |
notify:aString |
|
9600 |
"launch a Notifier, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9601 |
Use #information: for ignorable messages. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9602 |
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
|
9603 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9604 |
|
5755 | 9605 |
|
9606 |
Smalltalk isInitialized ifFalse:[ |
|
14975 | 9607 |
"/ thisContext fullPrintAll. |
9608 |
'information: ' print. aString printCR. |
|
9609 |
^ self |
|
5755 | 9610 |
]. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9611 |
UserNotification raiseRequestWith:self errorString:aString. |
5755 | 9612 |
|
9613 |
" |
|
9614 |
nil notify:'hello there' |
|
9615 |
self notify:'hello there' |
|
9616 |
" |
|
9617 |
||
9618 |
"Modified: 20.5.1996 / 10:28:48 / cg" |
|
9619 |
! |
|
9620 |
||
9621 |
warn:aString |
|
9622 |
"launch a WarningBox, telling user something. |
|
10460 | 9623 |
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
|
9624 |
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
|
9625 |
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
|
9626 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9627 |
|
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9628 |
Warning raiseRequestWith:self errorString:aString |
5755 | 9629 |
|
9630 |
" |
|
9631 |
nil warn:'hello there' |
|
9632 |
self warn:'hello there' |
|
9633 |
" |
|
9634 |
||
9635 |
" |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9636 |
Warning handle:[:ex | |
14975 | 9637 |
Transcript showCR:ex description. |
9638 |
ex proceed. |
|
5755 | 9639 |
] do:[ |
14975 | 9640 |
'hello' printCR. |
9641 |
self warn:'some info'. |
|
9642 |
'world' printCR. |
|
5755 | 9643 |
] |
9644 |
" |
|
9645 |
||
9646 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
|
9647 |
! ! |
|
9648 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9649 |
!Object methodsFor:'visiting'! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9650 |
|
8426 | 9651 |
acceptVisitor:aVisitor |
9652 |
"double-dispatch onto a Visitor." |
|
9653 |
||
9654 |
^ self acceptVisitor:aVisitor with:nil |
|
9655 |
! |
|
9656 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9657 |
acceptVisitor:aVisitor with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9658 |
"double-dispatch onto a Visitor. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9659 |
Subclasses redefine this" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9660 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9661 |
^ aVisitor visitObject:self with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9662 |
! ! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9663 |
|
5755 | 9664 |
!Object class methodsFor:'documentation'! |
1 | 9665 |
|
14056
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
9666 |
version |
15368 | 9667 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.724 2013-06-04 13:52:42 cg Exp $' |
14056
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
9668 |
! |
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
9669 |
|
12050 | 9670 |
version_CVS |
15368 | 9671 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.724 2013-06-04 13:52:42 cg Exp $' |
13416 | 9672 |
! |
9673 |
||
9674 |
version_SVN |
|
15243 | 9675 |
^ '$ Id: Object.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
1 | 9676 |
! ! |
6764 | 9677 |
|
14661 | 9678 |
|
5755 | 9679 |
Object initialize! |