author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 24 May 2013 18:52:05 +0100 | |
branch | jv |
changeset 18060 | 3708e12e9aa8 |
parent 18059 | b882507b9fdf |
parent 15255 | 62f7d4655ba8 |
child 18063 | 4a8226cd76ab |
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 |
||
15193 | 493 |
|
5755 | 494 |
!Object class methodsFor:'queries'! |
495 |
||
8892 | 496 |
isAbstract |
11221 | 497 |
"Return if this class is an abstract class. |
498 |
True is returned for Object here; false for subclasses. |
|
499 |
Abstract subclasses must redefine again." |
|
500 |
||
8892 | 501 |
^ self == Object |
502 |
! |
|
503 |
||
5755 | 504 |
isBuiltInClass |
505 |
"return true, if this class is known by the run-time-system, |
|
506 |
i.e. you cannot add/remove instance variables without recompiling |
|
507 |
the VM. |
|
508 |
Here, true is returned for myself, false for subclasses." |
|
509 |
||
510 |
^ self == Object |
|
511 |
||
512 |
"Modified: 23.4.1996 / 16:00:07 / cg" |
|
513 |
! ! |
|
514 |
||
14296 | 515 |
|
15193 | 516 |
|
517 |
||
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
518 |
!Object methodsFor:'Compatibility-Dolphin'! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
519 |
|
11161 | 520 |
stbFixup: anSTBInFiler at: newObjectIndex |
521 |
"Answer the true object that must be used to represent the receiver when read from anSTBInFiler. |
|
522 |
Typically this is overridden by subclasses of STBProxy to answer the proxied object. Other classes |
|
523 |
may also override this method to effectively 'one way become' the receiver to some other object" |
|
524 |
||
525 |
^ self |
|
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
526 |
! ! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
527 |
|
14682 | 528 |
!Object methodsFor:'Compatibility-GNU'! |
529 |
||
530 |
display |
|
531 |
"print the receiver on the standard output stream (which is not the Transcript). |
|
532 |
Added for GNU-ST compatibility" |
|
533 |
||
534 |
self print |
|
535 |
! |
|
536 |
||
537 |
displayNl |
|
538 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript). |
|
539 |
Added for GNU-ST compatibility" |
|
540 |
||
541 |
self printCR |
|
542 |
! ! |
|
543 |
||
7261 | 544 |
!Object methodsFor:'Compatibility-ST80'! |
5755 | 545 |
|
546 |
isMetaclass |
|
547 |
^ self isMeta |
|
548 |
! ! |
|
549 |
||
7261 | 550 |
!Object methodsFor:'Compatibility-Squeak'! |
5755 | 551 |
|
9071 | 552 |
becomeForward:anotherObject |
553 |
self becomeSameAs:anotherObject |
|
554 |
! |
|
555 |
||
556 |
becomeForward:anotherObject copyHash:copyHash |
|
557 |
copyHash ifTrue:[ self error:'unsupported operation' ]. |
|
558 |
self becomeSameAs:anotherObject |
|
559 |
! |
|
560 |
||
5755 | 561 |
clone |
562 |
^ self shallowCopy |
|
563 |
! |
|
564 |
||
6146 | 565 |
copyTwoLevel |
566 |
"one more level than a shallowCopy" |
|
567 |
||
568 |
^ self copyToLevel:2 |
|
569 |
||
570 |
" |
|
571 |
|original copy elL1 elL2 elL3 copyOfElL1| |
|
572 |
||
573 |
original := Array new:3. |
|
574 |
original at:1 put:1234. |
|
575 |
original at:2 put:'hello'. |
|
576 |
original at:3 put:(elL1 := Array new:3). |
|
577 |
||
578 |
elL1 at:1 put:1234. |
|
579 |
elL1 at:2 put:'hello'. |
|
580 |
elL1 at:3 put:(elL2 := Array new:3). |
|
581 |
||
582 |
elL2 at:1 put:1234. |
|
583 |
elL2 at:2 put:'hello'. |
|
584 |
elL2 at:3 put:(elL3 := Array new:3). |
|
585 |
||
586 |
elL3 at:1 put:1234. |
|
587 |
elL3 at:2 put:'hello'. |
|
588 |
elL3 at:3 put:(Array new:3). |
|
589 |
||
590 |
copy := original copyTwoLevel. |
|
14534 | 591 |
self assert:((original at:2) ~~ (copy at:2)). |
592 |
self assert:((original at:3) ~~ (copy at:3)). |
|
6146 | 593 |
|
594 |
copyOfElL1 := copy at:3. |
|
14534 | 595 |
self assert:((elL1 at:2) == (copyOfElL1 at:2)). |
596 |
self assert:((elL1 at:3) == (copyOfElL1 at:3)). |
|
6146 | 597 |
" |
598 |
! |
|
599 |
||
7320 | 600 |
explore |
601 |
(self confirm:'The Squeak explorer has not yet been ported to ST/X\\Inspect instead ?' withCRs) |
|
602 |
ifTrue:[ |
|
14975 | 603 |
self inspect |
7320 | 604 |
] |
605 |
! |
|
606 |
||
12285
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
607 |
inform: aString |
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
608 |
"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
|
609 |
|
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
610 |
self information:aString |
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
611 |
! |
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
612 |
|
9335 | 613 |
isInMemory |
614 |
"All normal objects are." |
|
615 |
||
616 |
^ true |
|
617 |
! |
|
618 |
||
5755 | 619 |
stringForReadout |
14975 | 620 |
^ self stringRepresentation |
5755 | 621 |
! |
622 |
||
623 |
stringRepresentation |
|
14975 | 624 |
"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" |
625 |
||
626 |
^ self printString |
|
5755 | 627 |
! |
628 |
||
9146
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
629 |
valueWithPossibleArguments:argArray |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
630 |
^ self |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
631 |
! |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
632 |
|
5755 | 633 |
veryDeepCopy |
8383 | 634 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 635 |
! ! |
636 |
||
7567 | 637 |
!Object methodsFor:'Compatibility-VW'! |
638 |
||
8637 | 639 |
isCharacters |
640 |
"added for visual works compatibility" |
|
641 |
^ false |
|
642 |
! |
|
643 |
||
7567 | 644 |
keyNotFoundError:aKey |
645 |
"VW compatibility" |
|
646 |
||
647 |
self errorKeyNotFound:aKey. |
|
648 |
! |
|
649 |
||
650 |
oneWayBecome:anotherObject |
|
651 |
^ self becomeSameAs:anotherObject |
|
652 |
||
653 |
" |
|
654 |
|arr o1 o2| |
|
655 |
||
656 |
arr := Array new:2. |
|
657 |
arr at:1 put:(o1 := Object new). |
|
658 |
arr at:2 put:(o2 := Point new). |
|
659 |
o1 oneWayBecome:o2. |
|
660 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
661 |
" |
|
662 |
" |
|
663 |
|arr o1 o2| |
|
664 |
||
665 |
arr := Array new:2. |
|
666 |
arr at:1 put:(o1 := Object new). |
|
667 |
arr at:2 put:(o2 := Point new). |
|
668 |
o1 becomeSameAs:o2. |
|
669 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
670 |
" |
|
671 |
! ! |
|
672 |
||
15193 | 673 |
|
15219 | 674 |
|
5755 | 675 |
!Object methodsFor:'accessing'! |
676 |
||
13320 | 677 |
_at:index |
678 |
"experimental: |
|
679 |
this is a synthetic selector, generated by the compiler, |
|
680 |
if a construct of the form expr[idx...] is parsed. |
|
681 |
I.e. |
|
14975 | 682 |
v[n] |
13320 | 683 |
generates |
14975 | 684 |
v _at: n |
13320 | 685 |
" |
686 |
||
687 |
^ self at:index |
|
688 |
||
689 |
"Created: / 21-03-2011 / 14:07:57 / cg" |
|
690 |
! |
|
691 |
||
692 |
_at:index put:value |
|
693 |
"experimental: |
|
694 |
this is a synthetic selector, generated by the compiler, |
|
695 |
if a construct of the form expr[idx...] is parsed. |
|
696 |
I.e. |
|
14975 | 697 |
v[n] |
13320 | 698 |
generates |
14975 | 699 |
v _at: n |
13320 | 700 |
" |
701 |
||
702 |
^ self at:index put:value |
|
703 |
||
704 |
"Created: / 21-03-2011 / 14:10:12 / cg" |
|
705 |
! |
|
706 |
||
14705 | 707 |
addSlot: slotName |
708 |
"dynamically add a new slot to the receiver. |
|
709 |
The receiver must be a real object, not nil or a smallInteger" |
|
710 |
||
711 |
|classGetter myClass anonCls newObj| |
|
712 |
||
713 |
myClass := self class. |
|
714 |
classGetter := ('%__get_',slotName,'__') asSymbol. |
|
715 |
||
716 |
anonCls := self perform:classGetter ifNotUnderstood:nil. |
|
717 |
anonCls isNil ifTrue:[ |
|
718 |
anonCls := myClass |
|
719 |
subclass:(myClass name,'+',slotName) asSymbol |
|
720 |
instanceVariableNames:slotName |
|
721 |
classVariableNames:'' |
|
722 |
poolDictionaries:'' category:nil |
|
723 |
inEnvironment:nil. |
|
724 |
anonCls compile:('%1 ^ %1' bindWith:slotName). |
|
725 |
anonCls compile:('%1:v %1 := v' bindWith:slotName). |
|
726 |
Class withoutUpdatingChangesDo:[ |
|
727 |
|m| |
|
728 |
m := Compiler compile:('__get_',slotName,' ^ #fooBar' bindWith:slotName) forClass:myClass install:false. |
|
729 |
m literalAt:(m literals indexOf:#fooBar) put:anonCls. |
|
730 |
myClass addSelector:classGetter withMethod:m. |
|
731 |
]. |
|
732 |
]. |
|
733 |
newObj := anonCls cloneFrom:self. |
|
734 |
self become:newObj. |
|
735 |
||
736 |
" |
|
737 |
|p1 p2 p3| |
|
738 |
||
739 |
p1 := Point x:10 y:20. |
|
740 |
p2 := Point x:100 y:200. |
|
741 |
Transcript show:'p1 is '; showCR:p1. |
|
742 |
Transcript show:'p2 is '; showCR:p2. |
|
743 |
p1 addSlot:'z'. |
|
744 |
p1 z:30. |
|
745 |
Transcript show:'p1 is '; showCR:p1. |
|
746 |
Transcript show:'p2 is '; showCR:p2. |
|
747 |
ObjectMemory dumpObject:p1. |
|
748 |
ObjectMemory dumpObject:p2. |
|
749 |
||
750 |
p1 addSlot:'t'. |
|
751 |
p1 t:30. |
|
752 |
Transcript show:'p1 is '; showCR:p1. |
|
753 |
ObjectMemory dumpObject:p1. |
|
754 |
||
755 |
p3 := Point x:110 y:120. |
|
756 |
p3 addSlot:'z'. |
|
757 |
p3 addSlot:'t'. |
|
758 |
p1 inspect. |
|
759 |
p2 inspect. |
|
760 |
p3 inspect. |
|
761 |
" |
|
762 |
! |
|
763 |
||
5755 | 764 |
at:index |
765 |
"return the indexed instance variable with index, anInteger; |
|
766 |
this method can be redefined in subclasses." |
|
767 |
||
768 |
^ self basicAt:index |
|
769 |
! |
|
770 |
||
771 |
at:index put:anObject |
|
772 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
773 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
|
774 |
||
775 |
^ self basicAt:index put:anObject |
|
776 |
||
777 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
|
778 |
! |
|
779 |
||
780 |
basicAt:index |
|
781 |
"return the indexed instance variable with index, anInteger. |
|
782 |
Trigger an error if the receiver has no indexed instance variables. |
|
783 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
784 |
||
785 |
%{ /* NOCONTEXT */ |
|
786 |
||
787 |
REGISTER int nbytes, indx; |
|
788 |
OBJ myClass; |
|
789 |
REGISTER char *pFirst; |
|
790 |
REGISTER int n; |
|
791 |
||
792 |
/* |
|
793 |
* notice the missing test for self being a nonNilObject - |
|
794 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
795 |
* and SmallInteger |
|
796 |
*/ |
|
797 |
if (__isSmallInteger(index)) { |
|
14975 | 798 |
myClass = __qClass(self); |
799 |
indx = __intVal(index) - 1; |
|
800 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
801 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
802 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
803 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
804 |
||
805 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
806 |
case __MASKSMALLINT(POINTERARRAY): |
|
807 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
808 |
/* |
|
809 |
* pointers |
|
810 |
*/ |
|
811 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
812 |
OBJ *op; |
|
813 |
||
814 |
op = (OBJ *)pFirst + indx; |
|
815 |
RETURN ( *op ); |
|
816 |
} |
|
817 |
break; |
|
818 |
||
819 |
case __MASKSMALLINT(BYTEARRAY): |
|
820 |
/* |
|
821 |
* (unsigned) bytes |
|
822 |
*/ |
|
823 |
if ((unsigned)indx < nbytes) { |
|
824 |
unsigned char *cp; |
|
825 |
||
826 |
cp = (unsigned char *)pFirst + indx; |
|
827 |
RETURN ( __mkSmallInteger( (*cp & 0xFF)) ); |
|
828 |
} |
|
829 |
break; |
|
830 |
||
831 |
case __MASKSMALLINT(FLOATARRAY): |
|
832 |
/* |
|
833 |
* native floats |
|
834 |
*/ |
|
835 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
836 |
float *fp; |
|
837 |
float f; |
|
838 |
OBJ v; |
|
839 |
||
840 |
fp = (float *)pFirst + indx; |
|
841 |
f = *fp; |
|
842 |
if (f == 0.0) { |
|
843 |
v = __float0; |
|
844 |
} else { |
|
845 |
__qMKSFLOAT(v, f); |
|
846 |
} |
|
847 |
RETURN (v); |
|
848 |
} |
|
849 |
break; |
|
850 |
||
851 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
852 |
/* |
|
853 |
* native doubles |
|
854 |
*/ |
|
5755 | 855 |
#ifdef __NEED_DOUBLE_ALIGN |
14975 | 856 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
857 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
858 |
||
859 |
pFirst += delta; |
|
860 |
nbytes -= delta; |
|
861 |
} |
|
5755 | 862 |
#endif |
14975 | 863 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
864 |
double *dp; |
|
865 |
double d; |
|
866 |
OBJ v; |
|
867 |
||
868 |
dp = (double *)pFirst + indx; |
|
869 |
d = *dp; |
|
870 |
if (d == 0.0) { |
|
871 |
v = __float0; |
|
872 |
} else { |
|
873 |
__qMKFLOAT(v, d); |
|
874 |
} |
|
875 |
RETURN (v); |
|
876 |
} |
|
877 |
break; |
|
878 |
||
879 |
case __MASKSMALLINT(WORDARRAY): |
|
880 |
/* |
|
881 |
* unsigned 16bit ints |
|
882 |
*/ |
|
883 |
/* Notice: the hard coded shifts are by purpose; |
|
884 |
* it makes us independent of the short-size of the machine |
|
885 |
*/ |
|
886 |
if ((unsigned)indx < (nbytes>>1)) { |
|
887 |
unsigned short *sp; |
|
888 |
||
889 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
890 |
RETURN ( __mkSmallInteger( (*sp & 0xFFFF)) ); |
|
891 |
} |
|
892 |
break; |
|
893 |
||
894 |
case __MASKSMALLINT(SWORDARRAY): |
|
895 |
/* |
|
896 |
* signed 16bit ints |
|
897 |
*/ |
|
898 |
/* Notice: the hard coded shifts are by purpose; |
|
899 |
* it makes us independent of the short-size of the machine |
|
900 |
*/ |
|
901 |
if ((unsigned)indx < (nbytes>>1)) { |
|
902 |
short *ssp; |
|
903 |
||
904 |
ssp = (short *)(pFirst + (indx<<1)); |
|
905 |
RETURN ( __mkSmallInteger( (*ssp) )); |
|
906 |
} |
|
907 |
break; |
|
908 |
||
909 |
case __MASKSMALLINT(LONGARRAY): |
|
910 |
/* |
|
911 |
* unsigned 32bit ints |
|
912 |
*/ |
|
913 |
/* Notice: the hard coded shifts are by purpose; |
|
914 |
* it makes us independent of the int-size of the machine |
|
915 |
*/ |
|
916 |
if ((unsigned)indx < (nbytes>>2)) { |
|
917 |
unsigned int32 ul; |
|
918 |
unsigned int32 *lp; |
|
919 |
||
920 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
921 |
ul = *lp; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
922 |
#if __POINTER_SIZE__ == 8 |
14975 | 923 |
{ |
924 |
unsigned INT ull = (unsigned INT)ul; |
|
925 |
RETURN ( __mkSmallInteger(ull) ); |
|
926 |
} |
|
5755 | 927 |
#else |
14975 | 928 |
if (ul <= _MAX_INT) { |
929 |
RETURN ( __mkSmallInteger(ul) ); |
|
930 |
} |
|
931 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 932 |
#endif |
14975 | 933 |
} |
934 |
break; |
|
935 |
||
936 |
case __MASKSMALLINT(SLONGARRAY): |
|
937 |
/* |
|
938 |
* signed 32bit ints |
|
939 |
*/ |
|
940 |
/* Notice: the hard coded shifts are by purpose; |
|
941 |
* it makes us independent of the int-size of the machine |
|
942 |
*/ |
|
943 |
if ((unsigned)indx < (nbytes>>2)) { |
|
944 |
int32 *slp; |
|
945 |
int32 l; |
|
946 |
||
947 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
948 |
l = *slp; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
949 |
#if __POINTER_SIZE__ == 8 |
14975 | 950 |
{ |
951 |
INT ll = (INT)l; |
|
952 |
RETURN ( __mkSmallInteger(ll) ); |
|
953 |
} |
|
5755 | 954 |
#else |
14975 | 955 |
if (__ISVALIDINTEGER(l)) { |
956 |
RETURN ( __mkSmallInteger(l) ); |
|
957 |
} |
|
958 |
RETURN ( __MKLARGEINT(l) ); |
|
5755 | 959 |
#endif |
14975 | 960 |
} |
961 |
break; |
|
962 |
||
963 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
964 |
/* |
|
965 |
* signed 64bit longlongs |
|
966 |
*/ |
|
5755 | 967 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 968 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
969 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
970 |
||
971 |
pFirst += delta; |
|
972 |
nbytes -= delta; |
|
973 |
} |
|
5755 | 974 |
#endif |
14975 | 975 |
/* Notice: the hard coded shifts are by purpose; |
976 |
* it makes us independent of the long/longlong-size of the machine |
|
977 |
*/ |
|
978 |
if ((unsigned)indx < (nbytes>>3)) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
979 |
#if __POINTER_SIZE__ == 8 |
14975 | 980 |
INT *slp, ll; |
981 |
||
982 |
slp = (INT *)(pFirst + (indx<<3)); |
|
983 |
ll = *slp; |
|
984 |
if (__ISVALIDINTEGER(ll)) { |
|
985 |
RETURN ( __mkSmallInteger(ll) ); |
|
986 |
} |
|
987 |
RETURN ( __MKLARGEINT(ll) ); |
|
5755 | 988 |
#else |
14975 | 989 |
__int64__ *llp; |
990 |
||
991 |
llp = (__int64__ *)(pFirst + (indx<<3)); |
|
992 |
RETURN (__MKINT64(llp)); |
|
5755 | 993 |
#endif |
14975 | 994 |
} |
995 |
break; |
|
996 |
||
997 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
998 |
/* |
|
999 |
* unsigned 64bit longlongs |
|
1000 |
*/ |
|
5755 | 1001 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 1002 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1003 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1004 |
||
1005 |
pFirst += delta; |
|
1006 |
nbytes -= delta; |
|
1007 |
} |
|
5755 | 1008 |
#endif |
14975 | 1009 |
/* Notice: the hard coded shifts are by purpose; |
1010 |
* it makes us independent of the long/longlong-size of the machine |
|
1011 |
*/ |
|
1012 |
if ((unsigned)indx < (nbytes>>3)) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
1013 |
#if __POINTER_SIZE__ == 8 |
14975 | 1014 |
unsigned INT *ulp, ul; |
1015 |
||
1016 |
ulp = (unsigned INT *)(pFirst + (indx<<3)); |
|
1017 |
ul = *ulp; |
|
1018 |
if (ul <= _MAX_INT) { |
|
1019 |
RETURN ( __mkSmallInteger(ul) ); |
|
1020 |
} |
|
1021 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 1022 |
#else |
14975 | 1023 |
__uint64__ *llp; |
1024 |
||
1025 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
1026 |
RETURN (__MKUINT64(llp)); |
|
5755 | 1027 |
#endif |
14975 | 1028 |
} |
1029 |
break; |
|
1030 |
} |
|
5755 | 1031 |
} |
1032 |
%}. |
|
7216 | 1033 |
^ self indexNotIntegerOrOutOfBounds:index |
5755 | 1034 |
! |
1035 |
||
1036 |
basicAt:index put:anObject |
|
1037 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
1038 |
Returns anObject (sigh). |
|
1039 |
Trigger an error if the receiver has no indexed instance variables. |
|
1040 |
||
1041 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
1042 |
||
1043 |
%{ /* NOCONTEXT */ |
|
1044 |
||
1045 |
register int nbytes, indx; |
|
1046 |
OBJ myClass; |
|
1047 |
register char *pFirst; |
|
1048 |
/* int nInstBytes, ninstvars, flags; */ |
|
1049 |
REGISTER int n; |
|
1050 |
unsigned int u; |
|
1051 |
int val; |
|
1052 |
||
1053 |
/* notice the missing test for self being a nonNilObject - |
|
1054 |
this can be done since basicAt: is defined both in UndefinedObject |
|
1055 |
and SmallInteger */ |
|
1056 |
||
1057 |
if (__isSmallInteger(index)) { |
|
14975 | 1058 |
indx = __intVal(index) - 1; |
1059 |
myClass = __qClass(self); |
|
1060 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1061 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
1062 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
1063 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
1064 |
||
1065 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1066 |
case __MASKSMALLINT(POINTERARRAY): |
|
1067 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
1068 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
1069 |
OBJ *op; |
|
1070 |
||
1071 |
op = (OBJ *)pFirst + indx; |
|
1072 |
*op = anObject; |
|
1073 |
__STORE(self, anObject); |
|
1074 |
RETURN ( anObject ); |
|
1075 |
} |
|
1076 |
break; |
|
1077 |
||
1078 |
case __MASKSMALLINT(BYTEARRAY): |
|
1079 |
if (__isSmallInteger(anObject)) { |
|
1080 |
val = __intVal(anObject); |
|
1081 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
1082 |
if ((unsigned)indx < nbytes) { |
|
1083 |
char *cp; |
|
1084 |
||
1085 |
cp = pFirst + indx; |
|
1086 |
*cp = val; |
|
1087 |
RETURN ( anObject ); |
|
1088 |
} |
|
1089 |
} |
|
1090 |
} |
|
1091 |
break; |
|
1092 |
||
1093 |
case __MASKSMALLINT(FLOATARRAY): |
|
1094 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
1095 |
float *fp; |
|
1096 |
||
1097 |
fp = (float *)pFirst + indx; |
|
1098 |
if (anObject != nil) { |
|
1099 |
if (! __isSmallInteger(anObject)) { |
|
1100 |
if (__qIsFloatLike(anObject)) { |
|
1101 |
*fp = (float)(__floatVal(anObject)); |
|
1102 |
RETURN ( anObject ); |
|
1103 |
} |
|
1104 |
if (__qIsShortFloat(anObject)) { |
|
1105 |
*fp = __shortFloatVal(anObject); |
|
1106 |
RETURN ( anObject ); |
|
1107 |
} |
|
1108 |
} else { |
|
1109 |
*fp = (float) __intVal(anObject); |
|
1110 |
RETURN ( anObject ); |
|
1111 |
} |
|
1112 |
} |
|
1113 |
} |
|
1114 |
break; |
|
1115 |
||
1116 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1117 |
#ifdef __NEED_DOUBLE_ALIGN |
14975 | 1118 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1119 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1120 |
||
1121 |
pFirst += delta; |
|
1122 |
nbytes -= delta; |
|
1123 |
} |
|
5755 | 1124 |
#endif |
14975 | 1125 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
1126 |
double *dp; |
|
1127 |
||
1128 |
dp = (double *)pFirst + indx; |
|
1129 |
if (anObject != nil) { |
|
1130 |
if (! __isSmallInteger(anObject)) { |
|
1131 |
if (__qIsFloatLike(anObject)) { |
|
1132 |
*dp = __floatVal(anObject); |
|
1133 |
RETURN ( anObject ); |
|
1134 |
} |
|
1135 |
if (__qIsShortFloat(anObject)) { |
|
1136 |
*dp = (double)__shortFloatVal(anObject); |
|
1137 |
RETURN ( anObject ); |
|
1138 |
} |
|
1139 |
} else { |
|
1140 |
*dp = (double) __intVal(anObject); |
|
1141 |
RETURN ( anObject ); |
|
1142 |
} |
|
1143 |
} |
|
1144 |
} |
|
1145 |
break; |
|
1146 |
||
1147 |
case __MASKSMALLINT(WORDARRAY): |
|
1148 |
if (__isSmallInteger(anObject)) { |
|
1149 |
val = __intVal(anObject); |
|
1150 |
if ((unsigned)val <= 0xFFFF) { |
|
1151 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1152 |
unsigned short *sp; |
|
1153 |
||
1154 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
1155 |
*sp = val; |
|
1156 |
RETURN ( anObject ); |
|
1157 |
} |
|
1158 |
} |
|
1159 |
} |
|
1160 |
break; |
|
1161 |
||
1162 |
case __MASKSMALLINT(SWORDARRAY): |
|
1163 |
if (__isSmallInteger(anObject)) { |
|
1164 |
val = __intVal(anObject); |
|
1165 |
if ((val >= -32768) && (val < 32768)) { |
|
1166 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1167 |
short *ssp; |
|
1168 |
||
1169 |
ssp = (short *)(pFirst + (indx<<1)); |
|
1170 |
*ssp = val; |
|
1171 |
RETURN ( anObject ); |
|
1172 |
} |
|
1173 |
} |
|
1174 |
} |
|
1175 |
break; |
|
1176 |
||
1177 |
case __MASKSMALLINT(SLONGARRAY): |
|
1178 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1179 |
int32 *slp; |
|
1180 |
||
1181 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
1182 |
if (__isSmallInteger(anObject)) { |
|
1183 |
*slp = __intVal(anObject); |
|
1184 |
RETURN ( anObject ); |
|
1185 |
} |
|
1186 |
n = __signedLongIntVal(anObject); |
|
1187 |
/* |
|
1188 |
* zero means failure for an int larger than INT-size bytes |
|
1189 |
* (would be a smallInteger) |
|
1190 |
*/ |
|
1191 |
if (n) { |
|
14632 | 1192 |
#if __POINTER_SIZE__ == 8 |
14975 | 1193 |
if ((n >= -0x80000000) && (n < 0x80000000)) |
14632 | 1194 |
#endif |
14975 | 1195 |
{ |
1196 |
*slp = n; |
|
1197 |
RETURN ( anObject ); |
|
1198 |
} |
|
1199 |
} |
|
1200 |
} |
|
1201 |
break; |
|
1202 |
||
1203 |
case __MASKSMALLINT(LONGARRAY): |
|
1204 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1205 |
unsigned int32 *lp; |
|
1206 |
||
1207 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
1208 |
if (anObject == __mkSmallInteger(0)) { |
|
1209 |
*lp = 0; |
|
1210 |
RETURN ( anObject ); |
|
1211 |
} |
|
1212 |
u = __longIntVal(anObject); |
|
1213 |
/* |
|
1214 |
* zero means failure for an int larger than 4 bytes |
|
1215 |
* (would be a smallInteger) |
|
1216 |
*/ |
|
1217 |
if (u) { |
|
14632 | 1218 |
#if __POINTER_SIZE__ == 8 |
14975 | 1219 |
if (u <= 0xFFFFFFFF) |
14632 | 1220 |
#endif |
14975 | 1221 |
{ |
1222 |
*lp = u; |
|
1223 |
RETURN ( anObject ); |
|
1224 |
} |
|
1225 |
} |
|
1226 |
} |
|
1227 |
break; |
|
1228 |
||
1229 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1230 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 1231 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1232 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1233 |
||
1234 |
pFirst += delta; |
|
1235 |
nbytes -= delta; |
|
1236 |
} |
|
14632 | 1237 |
#endif |
14975 | 1238 |
if ((unsigned)indx < (nbytes>>3)) { |
1239 |
__int64__ ll; |
|
1240 |
__int64__ *sllp; |
|
1241 |
||
1242 |
sllp = (__int64__ *)(pFirst + (indx<<3)); |
|
14632 | 1243 |
|
1244 |
#if __POINTER_SIZE__ == 8 |
|
14975 | 1245 |
if (__isSmallInteger(anObject)) { |
1246 |
*sllp = __intVal(anObject); |
|
1247 |
RETURN ( anObject ); |
|
1248 |
} |
|
1249 |
n = __signedLongIntVal(anObject); |
|
1250 |
if (n) { |
|
1251 |
*sllp = n; |
|
1252 |
RETURN ( anObject ); |
|
1253 |
} |
|
14632 | 1254 |
#else |
14975 | 1255 |
if (anObject == __mkSmallInteger(0)) { |
1256 |
ll.lo = ll.hi = 0; |
|
1257 |
*sllp = ll; |
|
1258 |
RETURN ( anObject ); |
|
1259 |
} |
|
1260 |
if (__signedLong64IntVal(anObject, &ll)) { |
|
1261 |
*sllp = ll; |
|
1262 |
RETURN ( anObject ); |
|
1263 |
} |
|
5755 | 1264 |
#endif |
14975 | 1265 |
} |
1266 |
break; |
|
1267 |
||
1268 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
5755 | 1269 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 1270 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1271 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1272 |
||
1273 |
pFirst += delta; |
|
1274 |
nbytes -= delta; |
|
1275 |
} |
|
5755 | 1276 |
#endif |
14975 | 1277 |
if ((unsigned)indx < (nbytes>>3)) { |
1278 |
__uint64__ ll; |
|
1279 |
__uint64__ *llp; |
|
1280 |
||
1281 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
14632 | 1282 |
#if __POINTER_SIZE__ == 8 |
14975 | 1283 |
if (__isSmallInteger(anObject)) { |
1284 |
*llp = __intVal(anObject); |
|
1285 |
RETURN ( anObject ); |
|
1286 |
} |
|
1287 |
ll = __longIntVal(anObject); |
|
1288 |
if (ll) { |
|
1289 |
*llp = ll; |
|
1290 |
RETURN ( anObject ); |
|
1291 |
} |
|
14632 | 1292 |
#else |
14975 | 1293 |
if (anObject == __mkSmallInteger(0)) { |
1294 |
ll.lo = ll.hi = 0; |
|
1295 |
*llp = ll; |
|
1296 |
RETURN ( anObject ); |
|
1297 |
} |
|
1298 |
if (__unsignedLong64IntVal(anObject, &ll)) { |
|
1299 |
*llp = ll; |
|
1300 |
RETURN ( anObject ); |
|
1301 |
} |
|
14632 | 1302 |
#endif |
14975 | 1303 |
} |
1304 |
break; |
|
1305 |
} |
|
5755 | 1306 |
} |
1307 |
%}. |
|
1308 |
index isInteger ifFalse:[ |
|
14975 | 1309 |
" |
1310 |
the index should be an integer number |
|
1311 |
" |
|
1312 |
^ self indexNotInteger:index |
|
5755 | 1313 |
]. |
1314 |
(index between:1 and:self size) ifFalse:[ |
|
14975 | 1315 |
" |
1316 |
the index is less than 1 or greater than the size of the |
|
1317 |
receiver collection |
|
1318 |
" |
|
1319 |
^ self subscriptBoundsError:index |
|
5755 | 1320 |
]. |
1321 |
(self class isFloatsOrDoubles) ifTrue:[ |
|
14975 | 1322 |
anObject isNumber ifTrue:[ |
1323 |
^ self basicAt:index put:(anObject asFloat) |
|
1324 |
] |
|
5755 | 1325 |
]. |
1326 |
anObject isInteger ifFalse:[ |
|
14975 | 1327 |
" |
1328 |
the object to put into the receiver collection |
|
1329 |
should be an integer number |
|
1330 |
" |
|
1331 |
^ self elementNotInteger |
|
5755 | 1332 |
]. |
1333 |
" |
|
1334 |
the object to put into the receiver collection |
|
1335 |
is not an instance of the expected element class, |
|
1336 |
or the value is not within the elements valid range. |
|
1337 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1338 |
^ self elementBoundsError:anObject |
5755 | 1339 |
|
1340 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
|
1341 |
! |
|
1342 |
||
1343 |
byteAt:index |
|
10460 | 1344 |
"return the byte at index. |
5755 | 1345 |
This is only allowed for non-pointer indexed objects |
1346 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1347 |
The receivers indexed instvars are treated as an uninterpreted |
|
1348 |
collection of bytes. |
|
1349 |
Only useful with binary storage." |
|
1350 |
||
1351 |
%{ /* NOCONTEXT */ |
|
1352 |
||
1353 |
REGISTER int indx; |
|
1354 |
int nIndex; |
|
1355 |
REGISTER OBJ slf; |
|
1356 |
REGISTER OBJ cls; |
|
1357 |
||
1358 |
if (__isSmallInteger(index)) { |
|
14975 | 1359 |
slf = self; |
1360 |
if (__isNonNilObject(slf)) { |
|
1361 |
unsigned char *pFirst; |
|
1362 |
int nIndex; |
|
1363 |
||
1364 |
cls = __qClass(slf); |
|
1365 |
||
1366 |
pFirst = __byteArrayVal(slf); |
|
1367 |
pFirst += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1368 |
nIndex = __byteArraySize(slf); |
|
1369 |
indx = __intVal(index) - 1; |
|
1370 |
||
1371 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1372 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1373 |
#ifdef __NEED_DOUBLE_ALIGN |
14975 | 1374 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1375 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1376 |
||
1377 |
pFirst += delta; |
|
1378 |
nIndex -= delta; |
|
1379 |
} |
|
5755 | 1380 |
#endif |
14975 | 1381 |
/* fall into */ |
1382 |
case __MASKSMALLINT(BYTEARRAY): |
|
1383 |
case __MASKSMALLINT(WORDARRAY): |
|
1384 |
case __MASKSMALLINT(LONGARRAY): |
|
1385 |
case __MASKSMALLINT(SWORDARRAY): |
|
1386 |
case __MASKSMALLINT(SLONGARRAY): |
|
1387 |
case __MASKSMALLINT(FLOATARRAY): |
|
1388 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1389 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
|
1390 |
} |
|
1391 |
break; |
|
1392 |
||
1393 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1394 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1395 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 1396 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1397 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1398 |
||
1399 |
pFirst += delta; |
|
1400 |
nIndex -= delta; |
|
1401 |
} |
|
5755 | 1402 |
#endif |
14975 | 1403 |
if ((unsigned)indx < (unsigned)nIndex) { |
1404 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
|
1405 |
} |
|
1406 |
break; |
|
1407 |
} |
|
1408 |
} |
|
5755 | 1409 |
} |
1410 |
%}. |
|
1411 |
"/ index not integer or index out of range |
|
1412 |
"/ or non-byte indexable receiver |
|
1413 |
||
1414 |
^ self primitiveFailed |
|
1415 |
||
1416 |
" |
|
1417 |
Point new byteAt:1 |
|
1418 |
(ByteArray with:1 with:2) byteAt:2 |
|
10460 | 1419 |
(WordArray with:1) byteAt:1 |
1420 |
(FloatArray with:1.0) byteAt:2 |
|
1421 |
'hello' byteAt:1 |
|
5755 | 1422 |
" |
1423 |
! |
|
1424 |
||
1425 |
byteAt:index put:byteValue |
|
10460 | 1426 |
"set the byte at index. |
5755 | 1427 |
This is only allowed for non-pointer indexed objects |
1428 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1429 |
The receivers indexed instvars are treated as an uninterpreted |
|
1430 |
collection of bytes. |
|
1431 |
Only useful with binary storage." |
|
1432 |
||
1433 |
%{ /* NOCONTEXT */ |
|
1434 |
||
1435 |
REGISTER int indx; |
|
1436 |
int val, nIndex; |
|
1437 |
REGISTER OBJ slf; |
|
1438 |
REGISTER OBJ cls; |
|
1439 |
||
1440 |
if (__bothSmallInteger(index, byteValue)) { |
|
14975 | 1441 |
val = __intVal(byteValue); |
1442 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
1443 |
slf = self; |
|
1444 |
if (__isNonNilObject(slf)) { |
|
1445 |
cls = __qClass(slf); |
|
1446 |
||
1447 |
indx = __intVal(index) - 1; |
|
1448 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1449 |
case __MASKSMALLINT(BYTEARRAY): |
|
1450 |
case __MASKSMALLINT(WORDARRAY): |
|
1451 |
case __MASKSMALLINT(LONGARRAY): |
|
1452 |
case __MASKSMALLINT(SWORDARRAY): |
|
1453 |
case __MASKSMALLINT(SLONGARRAY): |
|
1454 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1455 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1456 |
case __MASKSMALLINT(FLOATARRAY): |
|
1457 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
1458 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1459 |
nIndex = __byteArraySize(slf); |
|
1460 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1461 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
1462 |
RETURN ( byteValue ); |
|
1463 |
} |
|
1464 |
break; |
|
1465 |
} |
|
1466 |
} |
|
1467 |
} |
|
5755 | 1468 |
} |
1469 |
%}. |
|
1470 |
"/ index not integer or index out of range |
|
1471 |
"/ or non-byte indexable receiver |
|
1472 |
||
1473 |
^ self primitiveFailed |
|
1474 |
||
1475 |
" |
|
1476 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
|
10460 | 1477 |
'hello' copy byteAt:1 put:105; yourself |
5755 | 1478 |
" |
1479 |
! |
|
1480 |
||
1481 |
instVarAt:index |
|
1482 |
"return a non-indexed instance variable; |
|
10460 | 1483 |
peeking into an object this way is not very object oriented |
5755 | 1484 |
- use with care (needed for copy, inspector etc.)" |
1485 |
||
1486 |
%{ /* NOCONTEXT */ |
|
1487 |
||
1488 |
OBJ myClass; |
|
1489 |
int idx, ninstvars; |
|
1490 |
||
1491 |
if (__isSmallInteger(index)) { |
|
14975 | 1492 |
myClass = __Class(self); |
1493 |
idx = __intVal(index) - 1; |
|
1494 |
/* |
|
1495 |
* do not allow returning of non-object fields. |
|
1496 |
* if subclass did not make provisions for that, |
|
1497 |
* we won't do so here ... |
|
1498 |
*/ |
|
1499 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1500 |
if (idx == 0) { |
|
1501 |
RETURN ( nil ) |
|
1502 |
} |
|
1503 |
} |
|
1504 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1505 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1506 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
|
1507 |
} |
|
5755 | 1508 |
} |
7216 | 1509 |
%}. |
1510 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1511 |
! |
1512 |
||
1513 |
instVarAt:index put:value |
|
1514 |
"change a non-indexed instance variable; |
|
10460 | 1515 |
peeking into an object this way is not very object oriented |
5755 | 1516 |
- use with care (needed for copy, inspector etc.)" |
1517 |
||
1518 |
%{ /* NOCONTEXT */ |
|
1519 |
||
1520 |
OBJ myClass; |
|
1521 |
int idx, ninstvars; |
|
1522 |
||
1523 |
if (__isSmallInteger(index)) { |
|
14975 | 1524 |
myClass = __Class(self); |
1525 |
idx = __intVal(index) - 1; |
|
1526 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1527 |
/* |
|
1528 |
* do not allow setting of non-object fields. |
|
1529 |
* if subclass did not make provisions for that, |
|
1530 |
* we won't do so here ... |
|
1531 |
*/ |
|
1532 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1533 |
if (idx == 0) { |
|
1534 |
RETURN ( nil ) |
|
1535 |
} |
|
1536 |
} |
|
1537 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1538 |
__InstPtr(self)->i_instvars[idx] = value; |
|
1539 |
__STORE(self, value); |
|
1540 |
RETURN ( value ); |
|
1541 |
} |
|
5755 | 1542 |
} |
7216 | 1543 |
%}. |
1544 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1545 |
! |
1546 |
||
10460 | 1547 |
instVarNamed:name |
5755 | 1548 |
"return a non-indexed instance variables value by name; |
10460 | 1549 |
peeking into an object this way is not very object oriented |
5755 | 1550 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1551 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1552 |
parsed ad runtime)" |
|
1553 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1554 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1555 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1556 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1557 |
idx isNil ifTrue:[ |
14975 | 1558 |
^ self errorKeyNotFound:name. |
11335 | 1559 |
]. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1560 |
^ self instVarAt:idx. |
5755 | 1561 |
|
1562 |
||
1563 |
" |
|
1564 |
|p| |
|
1565 |
||
1566 |
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
|
1567 |
p instVarNamed:'cx' |
5755 | 1568 |
" |
1569 |
||
1570 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
|
1571 |
! |
|
1572 |
||
1573 |
instVarNamed:name ifAbsent:exceptionBlock |
|
1574 |
"return a non-indexed instance variables value by name, |
|
1575 |
or the value of exceptionBlock, if there is no such instance variable. |
|
10460 | 1576 |
peeking into an object this way is not very object oriented |
5755 | 1577 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1578 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1579 |
parsed ad runtime)" |
|
1580 |
||
1581 |
|idx| |
|
1582 |
||
1583 |
idx := self class instVarOffsetOf:name. |
|
1584 |
idx isNil ifTrue:[^ exceptionBlock value]. |
|
1585 |
^ self instVarAt:idx |
|
1586 |
||
1587 |
||
1588 |
" |
|
1589 |
|p| |
|
1590 |
||
1591 |
p := Point x:10 y:20. |
|
10460 | 1592 |
p instVarNamed:'x' |
5755 | 1593 |
" |
1594 |
||
1595 |
"Created: 6.7.1996 / 23:02:49 / cg" |
|
1596 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
|
1597 |
! |
|
1598 |
||
1599 |
instVarNamed:name put:value |
|
1600 |
"set a non-indexed instance variable by name; |
|
10460 | 1601 |
peeking into an object this way is not very object oriented |
5755 | 1602 |
- if at all, use with care (provided for protocol completeness). |
1603 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1604 |
parsed ad runtime)" |
|
1605 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1606 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1607 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1608 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1609 |
idx isNil ifTrue:[ |
14975 | 1610 |
^ self errorKeyNotFound:name. |
11335 | 1611 |
]. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1612 |
^ self instVarAt:idx put:value. |
5755 | 1613 |
|
1614 |
" |
|
1615 |
|p| |
|
1616 |
||
1617 |
p := Point x:10 y:20. |
|
1618 |
p instVarNamed:'x' put:30. |
|
10460 | 1619 |
p |
5755 | 1620 |
" |
1621 |
||
1622 |
"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
|
1623 |
! |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1624 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1625 |
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
|
1626 |
"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
|
1627 |
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
|
1628 |
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
|
1629 |
- 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
|
1630 |
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
|
1631 |
parsed ad runtime)" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1632 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1633 |
|idx| |
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 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1636 |
idx isNil ifTrue:[^ exceptionBlock value]. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1637 |
^ self instVarAt:idx put:anObject. |
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 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1640 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1641 |
|p| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1642 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1643 |
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
|
1644 |
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
|
1645 |
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
|
1646 |
p inspect. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1647 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1648 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1649 |
"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
|
1650 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
5755 | 1651 |
! ! |
1652 |
||
15193 | 1653 |
|
5755 | 1654 |
!Object methodsFor:'attributes access'! |
1655 |
||
10460 | 1656 |
objectAttributeAt:attributeKey |
5755 | 1657 |
"return the attribute for a given key or nil if not found" |
1658 |
||
1659 |
| attrs | |
|
1660 |
||
1661 |
attrs := self objectAttributes. |
|
1662 |
(attrs notNil and:[attrs size > 0]) ifTrue:[ |
|
14975 | 1663 |
^ attrs at:attributeKey ifAbsent:[] |
5755 | 1664 |
]. |
1665 |
^ nil |
|
1666 |
||
1667 |
"Created: / 22.1.1998 / 21:29:17 / av" |
|
1668 |
"Modified: / 3.2.1998 / 18:55:55 / cg" |
|
1669 |
! |
|
1670 |
||
6323 | 1671 |
objectAttributeAt:attributeKey put:anObject |
5755 | 1672 |
"store the attribute anObject referenced by key into the receiver" |
1673 |
||
1674 |
"/ must do this save from interrupts, since the attributes collection |
|
1675 |
"/ is possibly accessed from multiple threads ... |
|
1676 |
[ |
|
14975 | 1677 |
| attrs | |
1678 |
||
1679 |
attrs := self objectAttributes. |
|
1680 |
(attrs isNil or:[attrs size == 0]) ifTrue:[ |
|
1681 |
attrs := WeakIdentityDictionary new. |
|
1682 |
attrs at:attributeKey put:anObject. |
|
1683 |
self objectAttributes:attrs. |
|
1684 |
] ifFalse:[ |
|
1685 |
attrs at:attributeKey put:anObject. |
|
1686 |
]. |
|
6323 | 1687 |
] valueUninterruptably |
5755 | 1688 |
|
1689 |
"Attaching additional attributes (slots) to an arbitrary object: |
|
1690 |
||
1691 |
|p| |
|
1692 |
||
1693 |
p := Point new. |
|
1694 |
p objectAttributeAt:#color put:#green. |
|
1695 |
||
1696 |
p objectAttributeAt:#color |
|
1697 |
" |
|
1698 |
||
1699 |
"Created: / 22.1.1998 / 21:29:25 / av" |
|
1700 |
"Modified: / 3.2.1998 / 18:57:58 / cg" |
|
1701 |
! |
|
1702 |
||
1703 |
objectAttributes |
|
1704 |
"return a Collection of attributes - nil if there is none. |
|
1705 |
The default implementation here uses a global WeakDictionary to store |
|
1706 |
attributes |
|
1707 |
This may be too slow for high frequency slot access, |
|
13416 | 1708 |
therefore, some classes may redefine this for better performnce. |
5755 | 1709 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
1710 |
||
1711 |
^ ObjectAttributes at:self ifAbsent:[nil] |
|
1712 |
||
1713 |
"Created: / 22.1.1998 / 21:29:30 / av" |
|
1714 |
"Modified: / 18.2.2000 / 11:34:16 / cg" |
|
1715 |
! |
|
1716 |
||
1717 |
objectAttributes:aCollection |
|
1718 |
"set the collection of attributes. |
|
1719 |
The default implementation here uses a global Dictionary to store |
|
1720 |
attributes which may be too slow for high frequency change&update. |
|
1721 |
Therefore, some classes may redefine this for better performance." |
|
1722 |
||
1723 |
"/ must do this save from interrupts, since the attributes collection |
|
1724 |
"/ is possibly accessed from multiple threads. |
|
1725 |
||
1726 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
14975 | 1727 |
"/ the common case - already blocked |
1728 |
||
1729 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
1730 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1731 |
] ifFalse:[ |
|
1732 |
ObjectAttributes at:self put:aCollection |
|
1733 |
]. |
|
1734 |
^ self |
|
5755 | 1735 |
]. |
1736 |
||
1737 |
[ |
|
14975 | 1738 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
1739 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1740 |
] ifFalse:[ |
|
1741 |
ObjectAttributes at:self put:aCollection |
|
1742 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
1743 |
] ensure:[ |
14975 | 1744 |
OperatingSystem unblockInterrupts |
5755 | 1745 |
] |
1746 |
||
1747 |
"Created: / 22.1.1998 / 21:29:35 / av" |
|
1748 |
"Modified: / 3.2.1998 / 18:58:10 / cg" |
|
1749 |
! |
|
1750 |
||
6323 | 1751 |
removeObjectAttribute:attributeKey |
5755 | 1752 |
"make the argument, anObject be no attribute of the receiver" |
1753 |
||
1754 |
"/ must do this save from interrupts, since the attributes collection |
|
1755 |
"/ is possibly accessed from multiple threads. |
|
1756 |
[ |
|
14975 | 1757 |
|attrs n a| |
1758 |
||
1759 |
attrs := self objectAttributes. |
|
1760 |
attrs notNil ifTrue:[ |
|
1761 |
attrs size == 0 ifTrue:[ |
|
1762 |
self objectAttributes:nil |
|
1763 |
] ifFalse:[ |
|
1764 |
attrs removeKey:attributeKey ifAbsent:nil. |
|
1765 |
attrs size == 0 ifTrue:[ |
|
1766 |
self objectAttributes:nil |
|
1767 |
] |
|
1768 |
] |
|
1769 |
] |
|
6323 | 1770 |
] valueUninterruptably |
5755 | 1771 |
|
1772 |
"Created: / 22.1.1998 / 21:29:39 / av" |
|
1773 |
"Modified: / 18.2.2000 / 11:32:19 / cg" |
|
1774 |
! ! |
|
1775 |
||
13500 | 1776 |
|
15193 | 1777 |
|
5755 | 1778 |
!Object methodsFor:'change & update'! |
1779 |
||
1780 |
broadcast:aSelectorSymbol |
|
1781 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1782 |
||
10460 | 1783 |
self dependentsDo:[:dependent | |
14975 | 1784 |
dependent perform:aSelectorSymbol |
5755 | 1785 |
] |
1786 |
! |
|
1787 |
||
1788 |
broadcast:aSelectorSymbol with:anArgument |
|
1789 |
"send a message with selector aSelectorSymbol with an additional |
|
1790 |
argument anArgument to all my dependents." |
|
1791 |
||
10460 | 1792 |
self dependentsDo:[:dependent | |
14975 | 1793 |
dependent perform:aSelectorSymbol with:anArgument |
5755 | 1794 |
] |
1795 |
! |
|
1796 |
||
1797 |
changeRequest |
|
1798 |
"the receiver wants to change - check if all dependents |
|
1799 |
grant the request, and return true if so" |
|
1800 |
||
10460 | 1801 |
self dependentsDo:[:dependent | |
14975 | 1802 |
dependent updateRequest ifFalse:[^ false]. |
5755 | 1803 |
]. |
1804 |
^ true |
|
1805 |
! |
|
1806 |
||
11551 | 1807 |
changeRequest:aSymbol |
5755 | 1808 |
"the receiver wants to change - check if all dependents |
1809 |
grant the request, and return true if so" |
|
1810 |
||
10460 | 1811 |
self dependentsDo:[:dependent | |
14975 | 1812 |
(dependent updateRequest:aSymbol) ifFalse:[^ false]. |
5755 | 1813 |
]. |
1814 |
^ true |
|
1815 |
! |
|
1816 |
||
11551 | 1817 |
changeRequest:aSymbol from:anObject |
1818 |
"the receiver wants to change - check if all dependents |
|
1819 |
except anObject grant the request, and return true if so. |
|
1820 |
The argument anObject is typically going to be the one who is |
|
1821 |
about to send the change request." |
|
1822 |
||
1823 |
^ self changeRequest:aSymbol with:nil from:anObject |
|
1824 |
! |
|
1825 |
||
1826 |
changeRequest:aSymbol with:aParameter |
|
1827 |
"the receiver wants to change - check if all dependents |
|
1828 |
grant the request, and return true if so" |
|
1829 |
||
11573 | 1830 |
^ self changeRequest:aSymbol with:aParameter from:self |
11551 | 1831 |
! |
1832 |
||
1833 |
changeRequest:aSymbol with:aParameter from:anObject |
|
5755 | 1834 |
"the receiver wants to change - check if all dependents |
1835 |
except anObject grant the request, and return true if so. |
|
1836 |
The argument anObject is typically going to be the one who is |
|
1837 |
about to send the change request." |
|
1838 |
||
10460 | 1839 |
self dependentsDo:[:dependent | |
14975 | 1840 |
dependent == anObject ifFalse:[ |
1841 |
(dependent updateRequest:aSymbol with:aParameter from:anObject) ifFalse:[^ false]. |
|
1842 |
] |
|
5755 | 1843 |
]. |
1844 |
^ true |
|
1845 |
! |
|
1846 |
||
1847 |
changeRequestFrom:anObject |
|
1848 |
"the receiver wants to change - check if all dependents |
|
1849 |
except anObject grant the request, and return true if so. |
|
1850 |
The argument anObject is typically going to be the one who is |
|
1851 |
about to send the change request." |
|
1852 |
||
10460 | 1853 |
self dependentsDo:[:dependent | |
14975 | 1854 |
dependent == anObject ifFalse:[ |
1855 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1856 |
] |
|
5755 | 1857 |
]. |
1858 |
^ true |
|
1859 |
! |
|
1860 |
||
1861 |
changed |
|
1862 |
"notify all dependents that the receiver has changed. |
|
1863 |
Each dependent gets a '#update:'-message with the original |
|
1864 |
receiver as argument." |
|
1865 |
||
1866 |
self changed:nil |
|
1867 |
! |
|
1868 |
||
1869 |
changed:aParameter |
|
1870 |
"notify all dependents that the receiver has changed somehow. |
|
1871 |
Each dependent gets a '#update:'-message with aParameter |
|
1872 |
as argument." |
|
1873 |
||
1874 |
self changed:aParameter with:nil |
|
1875 |
! |
|
1876 |
||
1877 |
changed:aParameter with:anArgument |
|
1878 |
"notify all dependents that the receiver has changed somehow. |
|
1879 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
|
1880 |
and anArgument as arguments." |
|
1881 |
||
10460 | 1882 |
self dependentsDo:[:dependent | |
14975 | 1883 |
dependent update:aParameter with:anArgument from:self |
5755 | 1884 |
] |
1885 |
! |
|
1886 |
||
1887 |
update:aParameter |
|
1888 |
"the message is sent to a dependent, when one of the objects |
|
1889 |
on whom the receiver depends, has changed. The argument aParameter |
|
1890 |
is either the changed object or the argument to the #changed: message. |
|
1891 |
||
1892 |
Default behavior here is to do nothing" |
|
1893 |
||
1894 |
^ self |
|
1895 |
! |
|
1896 |
||
1897 |
update:aParameter with:anArgument |
|
1898 |
"dependent is notified of some change - |
|
1899 |
Default is to try update:" |
|
1900 |
||
1901 |
^ self update:aParameter |
|
1902 |
! |
|
1903 |
||
1904 |
update:aParameter with:anArgument from:sender |
|
1905 |
"dependent is notified of some change - |
|
1906 |
Default is to try update:with:" |
|
1907 |
||
1908 |
^ self update:aParameter with:anArgument |
|
1909 |
! |
|
1910 |
||
1911 |
updateRequest |
|
1912 |
"return true, if an update request is granted. |
|
1913 |
Default here is to grant updates - may be used |
|
1914 |
to lock updates if someone is making other changes |
|
1915 |
from within an update. Or if someone has locked its |
|
1916 |
state and does not want others to change things. |
|
1917 |
However, these dependents must all honor the |
|
1918 |
changeRequest - ifTrue - change protocol. I.e. they |
|
1919 |
must first ask all others via changeRequest, and only do the change |
|
1920 |
it returns true. The others must decide in updateRequest and |
|
1921 |
return true if they think a change is ok." |
|
1922 |
||
1923 |
^ true |
|
1924 |
! |
|
1925 |
||
1926 |
updateRequest:aSymbol |
|
1927 |
"return true, if an update request is granted. |
|
1928 |
Default here a simple updateRequest" |
|
1929 |
||
1930 |
^ self updateRequest |
|
7177 | 1931 |
! |
1932 |
||
11551 | 1933 |
updateRequest:aSymbol with:aParameter |
1934 |
"return true, if an update request is granted. |
|
1935 |
Default here a simple updateRequest" |
|
1936 |
||
1937 |
^ self updateRequest:aSymbol |
|
1938 |
! |
|
1939 |
||
1940 |
updateRequest:aSymbol with:aParameter from:sender |
|
1941 |
"return true, if an update request is granted. |
|
1942 |
Default here a simple updateRequest" |
|
1943 |
||
1944 |
^ self updateRequest:aSymbol with:aParameter |
|
1945 |
! |
|
1946 |
||
7177 | 1947 |
withoutUpdating:someone do:aBlock |
1948 |
"evaluate a block but remove someone from my dependents temporarily" |
|
1949 |
||
1950 |
(self dependents includesIdentical:someone) |
|
1951 |
ifFalse:[ |
|
14975 | 1952 |
^ aBlock value. |
7177 | 1953 |
]. |
1954 |
self removeDependent:someone. |
|
1955 |
^ aBlock ensure:[ self addDependent:someone ] |
|
5755 | 1956 |
! ! |
1957 |
||
1958 |
!Object methodsFor:'cleanup'! |
|
1959 |
||
1960 |
lowSpaceCleanup |
|
1961 |
"ignored here - redefined in some classes to |
|
1962 |
cleanup in low-memory situations" |
|
1963 |
||
1964 |
^ self |
|
1965 |
! ! |
|
1966 |
||
15193 | 1967 |
|
5755 | 1968 |
!Object methodsFor:'comparing'! |
1969 |
||
14975 | 1970 |
= anObject |
1971 |
"return true, if the receiver and the arg have the same structure. |
|
1972 |
Notice: |
|
1973 |
This method is partially open coded (inlined) by the compiler(s) |
|
1974 |
identical objects are always considered equal. |
|
1975 |
redefining it may not work as expected." |
|
1976 |
||
1977 |
^ self == anObject |
|
1978 |
! |
|
1979 |
||
5755 | 1980 |
== anObject |
1981 |
"return true, if the receiver and the arg are the same object. |
|
1982 |
Never redefine this in any class. |
|
1983 |
Notice: |
|
14975 | 1984 |
This method is open coded (inlined) by the compiler(s) |
1985 |
- redefining it may not work as expected." |
|
5755 | 1986 |
|
1987 |
%{ /* NOCONTEXT */ |
|
1988 |
||
1989 |
RETURN ( (self == anObject) ? true : false ); |
|
1990 |
%} |
|
1991 |
! |
|
1992 |
||
5814 | 1993 |
deepSameContentsAs:anObject |
1994 |
"return true, if the receiver and the arg have the same contents |
|
1995 |
in both the named instance vars and any indexed instVars. |
|
1996 |
This method descends into referenced objects, where #sameContentsAs: does not descend" |
|
1997 |
||
5821 | 1998 |
|myClass val |
5814 | 1999 |
sz "{ Class: SmallInteger }" | |
2000 |
||
2001 |
myClass := self class. |
|
2002 |
myClass isVariable ifTrue:[ |
|
14975 | 2003 |
sz := self basicSize. |
2004 |
||
2005 |
"compare the indexed variables" |
|
2006 |
1 to:sz do:[:i | |
|
2007 |
val := self basicAt:i. |
|
2008 |
val isLiteral ifTrue:[ |
|
2009 |
val = (anObject basicAt:i) ifFalse:[^ false]. |
|
2010 |
] ifFalse:[ |
|
2011 |
(val deepSameContentsAs:(anObject basicAt:i)) ifFalse:[^ false]. |
|
2012 |
] |
|
2013 |
] |
|
5814 | 2014 |
]. |
2015 |
||
2016 |
"compare the instance variables" |
|
2017 |
sz := myClass instSize. |
|
10460 | 2018 |
1 to:sz do:[:i | |
14975 | 2019 |
val := self instVarAt:i. |
2020 |
val isLiteral ifTrue:[ |
|
2021 |
val = (anObject instVarAt:i) ifFalse:[^ false]. |
|
2022 |
] ifFalse:[ |
|
2023 |
(val deepSameContentsAs:(anObject instVarAt:i)) ifFalse:[^ false]. |
|
2024 |
] |
|
5814 | 2025 |
]. |
2026 |
||
2027 |
^ true |
|
2028 |
||
2029 |
" |
|
10460 | 2030 |
#(1 2 3 4) deepSameContentsAs:#[1 2 3 4] asArray |
5814 | 2031 |
(1@2) deepSameContentsAs:(1->2) |
2032 |
" |
|
2033 |
! |
|
2034 |
||
5755 | 2035 |
hash |
2036 |
"return an Integer useful as a hash key for the receiver. |
|
2037 |
This hash should return same values for objects with same |
|
2038 |
contents (i.e. use this to hash on structure)" |
|
2039 |
||
2040 |
^ self identityHash |
|
2041 |
! |
|
2042 |
||
2043 |
identityHash |
|
2044 |
"return an Integer useful as a hash key for the receiver. |
|
2045 |
This hash should return same values for the same object (i.e. use |
|
2046 |
this to hash on identity of objects). |
|
2047 |
||
2048 |
We cannot use the Objects address (as other smalltalks do) since |
|
2049 |
no object-table exists and the hashval must not change when objects |
|
2050 |
are moved by the collector. Therefore we assign each object a unique |
|
2051 |
Id in the object header itself as its hashed upon. |
|
2052 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
2053 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
2054 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
2055 |
hashed-upon objects could add an instvar containing the hash value." |
|
2056 |
||
2057 |
%{ /* NOCONTEXT */ |
|
2058 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2059 |
REGISTER unsigned INT hash; |
5755 | 2060 |
static unsigned nextHash = 0; |
2061 |
||
2062 |
if (__isNonNilObject(self)) { |
|
14975 | 2063 |
hash = __GET_HASH(self); |
2064 |
if (hash == 0) { |
|
2065 |
/* has no hash yet */ |
|
2066 |
||
2067 |
if (++nextHash > __MAX_HASH__) { |
|
2068 |
nextHash = 1; |
|
2069 |
} |
|
2070 |
hash = nextHash; |
|
2071 |
__SET_HASH(self, hash); |
|
2072 |
} |
|
2073 |
||
2074 |
/* |
|
2075 |
* now, we got 11 bits for hashing; |
|
2076 |
* make it as large as possible; since most hashers use the returned |
|
2077 |
* key and take it modulo some prime number, this will allow for |
|
2078 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2079 |
*/ |
|
2080 |
hash = __MAKE_HASH__(hash); |
|
2081 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 2082 |
} |
2083 |
%}. |
|
2084 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
2085 |
! |
|
2086 |
||
2087 |
identityHashForBinaryStore |
|
2088 |
"hash which is usable if the object does not change its class |
|
2089 |
and does not #become something else, while the hash is used. |
|
2090 |
This is only used by the binary storage mechanism, during the |
|
2091 |
object writing phase." |
|
2092 |
||
2093 |
%{ /* NOCONTEXT */ |
|
2094 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2095 |
REGISTER unsigned INT hash, hash1, hash2, sz; |
5755 | 2096 |
OBJ o; |
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2097 |
static unsigned INT nextHash = 0; |
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2098 |
static unsigned INT nextClassHash = 0; |
5755 | 2099 |
|
2100 |
if (__isNonNilObject(self)) { |
|
14975 | 2101 |
/* |
2102 |
* my own identityHash |
|
2103 |
*/ |
|
2104 |
hash1 = __GET_HASH(self); |
|
2105 |
if (hash1 == 0) { |
|
2106 |
/* has no hash yet */ |
|
2107 |
||
2108 |
if (++nextHash > __MAX_HASH__) { |
|
2109 |
nextHash = 1; |
|
2110 |
} |
|
2111 |
hash1 = nextHash; |
|
2112 |
__SET_HASH(self, hash1); |
|
2113 |
} |
|
2114 |
/* |
|
2115 |
* my classes identityHash |
|
2116 |
*/ |
|
2117 |
o = __qClass(self); |
|
2118 |
hash2 = __GET_HASH(o); |
|
2119 |
if (hash2 == 0) { |
|
2120 |
/* has no hash yet */ |
|
2121 |
||
2122 |
if (++nextClassHash > __MAX_HASH__) { |
|
2123 |
nextClassHash = 1; |
|
2124 |
} |
|
2125 |
hash2 = nextClassHash; |
|
2126 |
__SET_HASH(o, hash2); |
|
2127 |
} |
|
2128 |
||
2129 |
/* |
|
2130 |
* some bits of my size |
|
2131 |
*/ |
|
2132 |
sz = __qSize(self); |
|
2133 |
||
2134 |
/* |
|
2135 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
2136 |
* make it as large as possible; since most hashers use the returned |
|
2137 |
* key and take it modulo some prime number, this will allow for |
|
2138 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2139 |
*/ |
|
2140 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
2141 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
2142 |
||
2143 |
while ((hash & 0x20000000) == 0) { |
|
2144 |
hash <<= 1; |
|
2145 |
} |
|
2146 |
||
2147 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 2148 |
} |
2149 |
%}. |
|
2150 |
"never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
|
2151 |
^ self identityHash |
|
2152 |
! |
|
2153 |
||
2154 |
sameContentsAs:anObject |
|
2155 |
"return true, if the receiver and the arg have the same contents |
|
7121 | 2156 |
in both the named instance vars and any indexed instVars. |
2157 |
The code here only checks if values present in the receiver are also |
|
2158 |
present in the arg, not vice versa. |
|
2159 |
I.e. the argument may be bigger and/or have more instance variables." |
|
5755 | 2160 |
|
5821 | 2161 |
|myClass |
5755 | 2162 |
sz "{ Class: SmallInteger }" | |
2163 |
||
2164 |
myClass := self class. |
|
2165 |
myClass isVariable ifTrue:[ |
|
14975 | 2166 |
sz := self basicSize. |
2167 |
anObject basicSize >= sz ifFalse:[^ false]. |
|
2168 |
||
2169 |
"compare the indexed variables" |
|
2170 |
1 to:sz do:[:i | |
|
2171 |
(self basicAt:i) == (anObject basicAt:i) ifFalse:[^ false]. |
|
2172 |
] |
|
5755 | 2173 |
]. |
2174 |
||
2175 |
"compare the instance variables" |
|
2176 |
sz := myClass instSize. |
|
12997 | 2177 |
anObject class instSize >= sz ifFalse:[^ false]. |
7121 | 2178 |
|
10460 | 2179 |
1 to:sz do:[:i | |
14975 | 2180 |
(self instVarAt:i) == (anObject instVarAt:i) ifFalse:[^ false]. |
5755 | 2181 |
]. |
2182 |
||
2183 |
^ true |
|
2184 |
||
2185 |
" |
|
10460 | 2186 |
#(1 2 3 4) sameContentsAs:#[1 2 3 4] asArray |
5814 | 2187 |
(1@2) sameContentsAs:(1->2) |
5755 | 2188 |
" |
2189 |
||
12997 | 2190 |
"Created: / 21-04-1998 / 15:56:40 / cg" |
2191 |
"Modified: / 05-08-2010 / 16:44:09 / sr" |
|
5755 | 2192 |
! |
2193 |
||
2194 |
~= anObject |
|
2195 |
"return true, if the receiver and the arg do not have the same structure. |
|
2196 |
Notice: |
|
14975 | 2197 |
This method is partially open coded (inlined) by the compiler(s) |
2198 |
identical objects are never considered unequal. |
|
2199 |
redefining it may not work as expected." |
|
5755 | 2200 |
|
2201 |
^ (self = anObject) not |
|
2202 |
! |
|
2203 |
||
2204 |
~~ anObject |
|
2205 |
"return true, if the receiver and the arg are not the same object. |
|
2206 |
Never redefine this in any class. |
|
2207 |
Notice: |
|
14975 | 2208 |
This method is open coded (inlined) by the compiler(s) |
2209 |
- redefining it may not work as expected." |
|
5755 | 2210 |
|
2211 |
%{ /* NOCONTEXT */ |
|
2212 |
RETURN ( (self == anObject) ? false : true ); |
|
2213 |
%} |
|
2214 |
! ! |
|
2215 |
||
2216 |
!Object methodsFor:'converting'! |
|
2217 |
||
2218 |
-> anObject |
|
2219 |
"return an association with the receiver as key and |
|
2220 |
the argument as value" |
|
2221 |
||
2222 |
^ Association key:self value:anObject |
|
2223 |
! |
|
2224 |
||
10062 | 2225 |
as:aSimilarClass |
2226 |
"If the receivers class is not aSimilarClass, |
|
10460 | 2227 |
create and return an object of class aSimilarClass that has the same contents |
10062 | 2228 |
as the receiver. |
2229 |
Otherwise, return the receiver." |
|
2230 |
||
2231 |
self class == aSimilarClass ifTrue:[^ self]. |
|
2232 |
^ aSimilarClass newFrom:self |
|
2233 |
||
2234 |
" |
|
2235 |
#[1 2 3 4] as:ByteArray |
|
2236 |
#[1 2 3 4] as:Array |
|
10539 | 2237 |
#[81 82 83 84] as:String |
2238 |
#[81 82 83 84] as:Symbol |
|
10062 | 2239 |
" |
2240 |
! |
|
2241 |
||
5755 | 2242 |
asCollection |
2243 |
"return myself as a Collection. |
|
2244 |
Redefined in collection to return themself." |
|
2245 |
||
2246 |
^ Array with:self |
|
2247 |
! |
|
2248 |
||
2249 |
asSequenceableCollection |
|
2250 |
"return myself as a SequenceableCollection. |
|
2251 |
Redefined in SequenceableCollection" |
|
2252 |
||
2253 |
^ Array with:self |
|
2254 |
! |
|
2255 |
||
14355 | 2256 |
asString |
2257 |
^ self printString |
|
2258 |
! |
|
2259 |
||
5755 | 2260 |
asValue |
2261 |
"return a valueHolder for for the receiver" |
|
2262 |
||
2263 |
^ ValueHolder with:self |
|
2264 |
! ! |
|
2265 |
||
2266 |
!Object methodsFor:'copying'! |
|
2267 |
||
10460 | 2268 |
cloneFrom:anObject |
5755 | 2269 |
"Helper for copy: |
2270 |
copy all instance variables from anObject into the receiver, |
|
2271 |
which should be of the same class as the argument." |
|
2272 |
||
2273 |
self cloneFrom:anObject performing:#yourself |
|
2274 |
||
2275 |
" |
|
2276 |
|x| |
|
2277 |
||
2278 |
x := Array new:3. |
|
2279 |
x cloneFrom:#(1 2 3). |
|
2280 |
" |
|
2281 |
! |
|
2282 |
||
2283 |
cloneFrom:anObject performing:aSymbol |
|
2284 |
"Helper for copy: |
|
8383 | 2285 |
for each instance variable from anObject, send it aSymbol |
5755 | 2286 |
and store the result into the receiver, |
2287 |
which should be of the same class as the argument." |
|
2288 |
||
2289 |
|myClass sz "{ Class: SmallInteger }" t | |
|
2290 |
||
2291 |
myClass := self class. |
|
14532 | 2292 |
|
2293 |
"process the named instance variables" |
|
2294 |
sz := myClass instSize. |
|
2295 |
1 to:sz do:[:i | |
|
14975 | 2296 |
t := anObject instVarAt:i. |
2297 |
aSymbol ~~ #yourself ifTrue:[ |
|
2298 |
t := t perform:aSymbol |
|
2299 |
]. |
|
2300 |
self instVarAt:i put:t |
|
14532 | 2301 |
]. |
2302 |
||
5755 | 2303 |
myClass isVariable ifTrue:[ |
14975 | 2304 |
sz := self basicSize. |
2305 |
||
2306 |
"process the indexed instance variables" |
|
2307 |
1 to:sz do:[:i | |
|
2308 |
t := anObject basicAt:i. |
|
2309 |
aSymbol ~~ #yourself ifTrue:[ |
|
2310 |
t := t perform:aSymbol. |
|
2311 |
]. |
|
2312 |
self basicAt:i put:t. |
|
2313 |
] |
|
5755 | 2314 |
]. |
2315 |
! |
|
2316 |
||
2317 |
cloneInstanceVariablesFrom:aPrototype |
|
2318 |
"Shallow copy variables from a prototype into myself. |
|
2319 |
This copies instVars by name - i.e. same-named variables are |
|
2320 |
copied, others are not. |
|
10460 | 2321 |
The variable slots are copied as available |
5755 | 2322 |
(i.e. the min of both indexed sizes is used)." |
10460 | 2323 |
|
14676 | 2324 |
|myClass prototypesClass myInfo prototypesInfo| |
2325 |
||
2326 |
||
2327 |
myClass := self class. |
|
2328 |
prototypesClass := aPrototype class. |
|
2329 |
(myClass == prototypesClass |
|
2330 |
or:[ myClass isSubclassOf:prototypesClass ]) ifTrue:[ |
|
2331 |
"/ can do better, if my class is a subclass of the prototype's class |
|
2332 |
1 to: prototypesClass instSize do:[:index | |
|
2333 |
self instVarAt:index put:(aPrototype instVarAt:index) |
|
2334 |
] |
|
2335 |
] ifFalse:[ |
|
2336 |
"/ map instvars by name |
|
2337 |
myInfo := myClass instanceVariableOffsets. |
|
2338 |
prototypesInfo := prototypesClass instanceVariableOffsets. |
|
2339 |
myInfo keysAndValuesDo:[:name :index | |varIndexAssoc| |
|
2340 |
varIndexAssoc := prototypesInfo at:name ifAbsent:[]. |
|
2341 |
varIndexAssoc notNil ifTrue:[ |
|
2342 |
self instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
2343 |
] |
|
2344 |
] |
|
2345 |
]. |
|
2346 |
myClass isVariable ifTrue:[ |
|
2347 |
prototypesClass isVariable ifTrue:[ |
|
2348 |
1 to:(self basicSize min:aPrototype basicSize) do:[:index | |
|
2349 |
self basicAt:index put:(aPrototype basicAt:index) |
|
2350 |
]. |
|
2351 |
]. |
|
5755 | 2352 |
]. |
2353 |
||
2354 |
" |
|
2355 |
Class withoutUpdatingChangesDo:[ |
|
14676 | 2356 |
|point3D| |
2357 |
||
2358 |
point3D := Point subclass:#Point3D |
|
2359 |
instanceVariableNames:'z' |
|
2360 |
classVariableNames:'' |
|
2361 |
poolDictionaries:'' |
|
2362 |
category:'testing' |
|
2363 |
inEnvironment:nil. |
|
2364 |
(point3D new cloneInstanceVariablesFrom:1@2) inspect. |
|
5755 | 2365 |
] |
2366 |
" |
|
2367 |
||
2368 |
" |
|
2369 |
Class withoutUpdatingChangesDo:[ |
|
14676 | 2370 |
Point variableSubclass:#Point3D_test |
2371 |
instanceVariableNames:'z' |
|
2372 |
classVariableNames:'' |
|
2373 |
poolDictionaries:'' |
|
2374 |
category:'testing'. |
|
2375 |
(((Smalltalk at:#Point3D_test) new:2) cloneInstanceVariablesFrom:#(1 2 3)) inspect. |
|
5755 | 2376 |
] |
2377 |
" |
|
2378 |
||
2379 |
" |
|
2380 |
|someObject| |
|
2381 |
||
2382 |
Class withoutUpdatingChangesDo:[ |
|
14676 | 2383 |
Object subclass:#TestClass1 |
2384 |
instanceVariableNames:'foo bar' |
|
2385 |
classVariableNames:'' |
|
2386 |
poolDictionaries:'' |
|
2387 |
category:'testing'. |
|
2388 |
someObject := TestClass1 new. |
|
2389 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
2390 |
Object subclass:#TestClass2 |
|
2391 |
instanceVariableNames:'bar foo' |
|
2392 |
classVariableNames:'' |
|
2393 |
poolDictionaries:'' |
|
2394 |
category:'testing'. |
|
2395 |
(TestClass2 new cloneInstanceVariablesFrom:someObject) inspect. |
|
5755 | 2396 |
] |
2397 |
" |
|
2398 |
||
2399 |
" |
|
2400 |
|top b b1| |
|
2401 |
||
2402 |
top := StandardSystemView new. |
|
2403 |
top extent:100@100. |
|
2404 |
||
2405 |
b := Button in:top. |
|
2406 |
b label:'hello'. |
|
2407 |
||
2408 |
b1 := ArrowButton new cloneInstanceVariablesFrom:b. |
|
2409 |
||
2410 |
top open. |
|
2411 |
b1 inspect |
|
2412 |
" |
|
2413 |
! |
|
2414 |
||
2415 |
copy |
|
2416 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
2417 |
Notice, that copy does not copy dependents." |
|
2418 |
||
2419 |
^ self shallowCopy postCopy |
|
2420 |
! |
|
2421 |
||
6146 | 2422 |
copyToLevel:level |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2423 |
"a controlled deepCopy, where the number of levels can be specified. |
10460 | 2424 |
Notice: |
14975 | 2425 |
This method DOES NOT handle cycles/self-refs and does NOT preserve object identity; |
2426 |
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
|
2427 |
|
14534 | 2428 |
|newObject newLevel class sz "{Class: SmallInteger}" newInst| |
2429 |
||
2430 |
newObject := self copy. |
|
2431 |
newObject == self ifTrue: [^ self]. "copy of nil, true, false, ... is self" |
|
2432 |
level == 1 ifTrue:[^ newObject]. |
|
2433 |
newLevel := level - 1. |
|
2434 |
||
2435 |
class := newObject class. |
|
2436 |
||
2437 |
"process the named instance variables" |
|
2438 |
sz := class instSize. |
|
2439 |
1 to:sz do:[:i | |
|
14975 | 2440 |
newInst := newObject instVarAt:i. |
2441 |
newInst notNil ifTrue:[ |
|
2442 |
newObject instVarAt:i put:(newInst copyToLevel:newLevel). |
|
2443 |
]. |
|
14534 | 2444 |
]. |
2445 |
||
10460 | 2446 |
class isVariable ifTrue:[ |
14975 | 2447 |
sz := newObject basicSize. |
2448 |
||
2449 |
"process the indexed instance variables" |
|
2450 |
1 to:sz do:[:i | |
|
2451 |
newInst := newObject basicAt:i. |
|
2452 |
newInst notNil ifTrue:[ |
|
2453 |
newObject basicAt:i put:(newInst copyToLevel:newLevel). |
|
2454 |
]. |
|
2455 |
] |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2456 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2457 |
^ newObject |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2458 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2459 |
" |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2460 |
|a b| |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2461 |
|
10460 | 2462 |
a := #( |
14975 | 2463 |
'1.1' |
2464 |
'1.2' |
|
2465 |
'1.3' |
|
2466 |
( |
|
2467 |
'1.41' |
|
2468 |
'1.42' |
|
2469 |
'1.43' |
|
2470 |
( |
|
2471 |
'1.441' |
|
2472 |
'1.442' |
|
2473 |
'1.443' |
|
2474 |
( '1.4441' '1.4442' '1.4443' ) |
|
2475 |
'1.445' |
|
2476 |
) |
|
2477 |
'1.45' |
|
2478 |
) |
|
2479 |
'1.5' |
|
2480 |
). |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2481 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2482 |
b := a copyToLevel:1. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2483 |
self assert: ( (a at:1) == (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2484 |
self assert: ( (a at:4) == (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2485 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2486 |
b := a copyToLevel:2. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2487 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2488 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2489 |
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
|
2490 |
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
|
2491 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2492 |
b := a copyToLevel:3. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2493 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2494 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2495 |
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
|
2496 |
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
|
2497 |
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
|
2498 |
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
|
2499 |
" |
6146 | 2500 |
! |
2501 |
||
5755 | 2502 |
deepCopy |
2503 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2504 |
This method DOES handle cycles/self-refs and preserves object identity; |
5755 | 2505 |
however the receivers class is not copied (to avoid the 'total' copy). |
2506 |
||
2507 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
2508 |
keeps track of already copied objects. If you are sure, that your |
|
2509 |
copied object does not include duplicates (or you do not care) and |
|
10460 | 2510 |
no cycles are involved, you can use the old simpleDeepCopy, |
5755 | 2511 |
which avoids this overhead (but may run into trouble). |
2512 |
Notice, that deepCopy does not copy dependents." |
|
2513 |
||
8383 | 2514 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 2515 |
|
2516 |
"an example which is not handled by the old deepCopy: |
|
10460 | 2517 |
|
5755 | 2518 |
|a| |
2519 |
a := Array new:3. |
|
2520 |
a at:3 put:a. |
|
2521 |
a deepCopy inspect |
|
2522 |
" |
|
2523 |
||
2524 |
" |
|
2525 |
|a| |
|
2526 |
a := Color black onDevice:Screen current. |
|
2527 |
a deepCopy inspect |
|
2528 |
" |
|
2529 |
||
2530 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
2531 |
! |
|
2532 |
||
2533 |
deepCopyError |
|
2534 |
"{ Pragma: +optSpace }" |
|
2535 |
||
2536 |
"raise a signal, that deepCopy is not allowed for this object" |
|
2537 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
2538 |
^ DeepCopyError raise |
5755 | 2539 |
! |
2540 |
||
2541 |
deepCopyUsing:aDictionary |
|
10460 | 2542 |
"a helper for deepCopy; return a copy of the object with |
2543 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
5755 | 2544 |
use the value found there. The class of the receiver is not copied. |
2545 |
This method DOES handle cycles/self references." |
|
2546 |
||
10941 | 2547 |
^ self deepCopyUsing:aDictionary postCopySelector:#postDeepCopyFrom:. |
2548 |
||
5755 | 2549 |
|
2550 |
" |
|
2551 |
|a b c copyOfC| |
|
2552 |
||
2553 |
a := Array with:'hello' with:'world' with:nil. |
|
2554 |
b := 99 @ 999. |
|
2555 |
a at:3 put:b. |
|
2556 |
c := Array with:a with:b with:a. |
|
2557 |
||
2558 |
Transcript showCR: (c at:1) == (c at:3). |
|
2559 |
copyOfC := c deepCopy. |
|
2560 |
Transcript showCR: (copyOfC at:1) == (copyOfC at:3) |
|
2561 |
" |
|
2562 |
! |
|
2563 |
||
10954 | 2564 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
11335 | 2565 |
"a helper for deepCopy; return a copy of the object with |
2566 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
10954 | 2567 |
use the value found there. The class of the receiver is not copied. |
2568 |
This method DOES handle cycles/self references." |
|
2569 |
||
2570 |
|myClass aCopy |
|
14527 | 2571 |
basicSize "{ Class: SmallInteger }" |
2572 |
instSize "{ Class: SmallInteger }" |
|
10954 | 2573 |
iOrig iCopy| |
2574 |
||
2575 |
myClass := self class. |
|
2576 |
myClass isVariable ifTrue:[ |
|
14975 | 2577 |
basicSize := self basicSize. |
2578 |
aCopy := myClass basicNew:basicSize. |
|
10954 | 2579 |
] ifFalse:[ |
14975 | 2580 |
basicSize := 0. |
2581 |
aCopy := myClass basicNew |
|
10954 | 2582 |
]. |
2583 |
aCopy setHashFrom:self. |
|
2584 |
aDictionary at:self put:aCopy. |
|
2585 |
||
2586 |
" |
|
14527 | 2587 |
copy the instance variables |
2588 |
" |
|
2589 |
instSize := myClass instSize. |
|
2590 |
1 to:instSize do:[:i | |
|
14975 | 2591 |
(self skipInstvarIndexInDeepCopy:i) ifFalse:[ |
2592 |
iOrig := self instVarAt:i. |
|
2593 |
iOrig notNil ifTrue:[ |
|
2594 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2595 |
iCopy isNil ifTrue:[ |
|
2596 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2597 |
]. |
|
2598 |
aCopy instVarAt:i put:iCopy |
|
2599 |
] |
|
2600 |
] |
|
14527 | 2601 |
]. |
2602 |
||
2603 |
" |
|
10954 | 2604 |
copy indexed instvars - if any |
2605 |
" |
|
14527 | 2606 |
basicSize ~~ 0 ifTrue:[ |
14975 | 2607 |
myClass isBits ifTrue:[ |
2608 |
"block-copy indexed instvars" |
|
2609 |
aCopy replaceFrom:1 to:basicSize with:self startingAt:1 |
|
2610 |
] ifFalse:[ |
|
2611 |
"individual deep copy the indexed variables" |
|
2612 |
1 to:basicSize do:[:i | |
|
2613 |
iOrig := self basicAt:i. |
|
2614 |
iOrig notNil ifTrue:[ |
|
2615 |
"/ used to be dict-includesKey-ifTrue[dict-at:], |
|
2616 |
"/ changed to use dict-at:ifAbsent:, to avoid double lookup in dictionary |
|
2617 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2618 |
iCopy isNil ifTrue:[ |
|
2619 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2620 |
]. |
|
2621 |
aCopy basicAt:i put:iCopy |
|
2622 |
] |
|
2623 |
] |
|
2624 |
] |
|
10954 | 2625 |
]. |
2626 |
||
13515
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2627 |
aCopy perform:postCopySelector withOptionalArgument:self and:aDictionary. |
10954 | 2628 |
^ aCopy |
13515
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2629 |
|
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2630 |
"Modified: / 21-07-2011 / 13:30:52 / cg" |
10954 | 2631 |
! |
2632 |
||
5755 | 2633 |
postCopy |
2634 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
2635 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
2636 |
(see there)" |
|
2637 |
||
2638 |
^ self |
|
2639 |
! |
|
2640 |
||
2641 |
postDeepCopy |
|
8930
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2642 |
"allows for cleanup after deep copying. |
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2643 |
To be redefined in subclasses." |
5755 | 2644 |
! |
2645 |
||
2646 |
postDeepCopyFrom:aSource |
|
2647 |
"allows for cleanup after deep copying" |
|
2648 |
||
2649 |
^ self postDeepCopy |
|
2650 |
! |
|
2651 |
||
2652 |
setHashFrom:anObject |
|
10460 | 2653 |
"set my identity-hash key to be the same as anObjects hash key. |
2654 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
5755 | 2655 |
Smalltalks, and may not be available in future ST/X versions. |
2656 |
DO NEVER use this for normal application code." |
|
2657 |
||
2658 |
%{ /* NOCONTEXT */ |
|
2659 |
||
2660 |
REGISTER unsigned h; |
|
2661 |
||
2662 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
14975 | 2663 |
h = __GET_HASH(anObject); |
2664 |
__SET_HASH(self, h); |
|
2665 |
RETURN (self); |
|
5755 | 2666 |
} |
2667 |
%}. |
|
2668 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
2669 |
! |
|
2670 |
||
2671 |
shallowCopy |
|
2672 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2673 |
i.e. the copy shares referenced instvars with its original." |
|
2674 |
||
2675 |
%{ /* NOCONTEXT */ |
|
2676 |
int ninsts, spc; |
|
2677 |
int sz; |
|
2678 |
OBJ theCopy; |
|
2679 |
OBJ cls; |
|
2680 |
int flags; |
|
2681 |
||
2682 |
cls = __qClass(self); |
|
2683 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
2684 |
||
2685 |
/* |
|
2686 |
* bail out for special objects .. |
|
2687 |
*/ |
|
2688 |
if (((flags & ~ARRAYMASK) == 0) |
|
2689 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
14975 | 2690 |
sz = __qSize(self); |
2691 |
__PROTECT__(self); |
|
2692 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
2693 |
__UNPROTECT__(self); |
|
2694 |
if (theCopy) { |
|
2695 |
cls = __qClass(self); |
|
2696 |
spc = __qSpace(theCopy); |
|
2697 |
||
2698 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
2699 |
||
2700 |
sz = sz - OHDR_SIZE; |
|
2701 |
if (sz) { |
|
2702 |
char *src, *dst; |
|
2703 |
||
2704 |
src = (char *)(__InstPtr(self)->i_instvars); |
|
2705 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
5755 | 2706 |
#ifdef bcopy4 |
14975 | 2707 |
{ |
2708 |
/* care for odd-number of longs */ |
|
2709 |
int nW = sz >> 2; |
|
2710 |
||
2711 |
if (sz & 3) { |
|
2712 |
nW++; |
|
2713 |
} |
|
2714 |
||
2715 |
bcopy4(src, dst, nW); |
|
2716 |
} |
|
5755 | 2717 |
#else |
14975 | 2718 |
bcopy(src, dst, sz); |
5755 | 2719 |
#endif |
2720 |
||
14975 | 2721 |
flags &= ARRAYMASK; |
2722 |
if (flags == POINTERARRAY) { |
|
2723 |
ninsts = __BYTES2OBJS__(sz); |
|
2724 |
} else { |
|
2725 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
2726 |
} |
|
2727 |
if (ninsts) { |
|
2728 |
do { |
|
2729 |
OBJ el; |
|
2730 |
||
2731 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
2732 |
__STORE_SPC(theCopy, el, spc); |
|
2733 |
} while (--ninsts); |
|
2734 |
} |
|
2735 |
} |
|
2736 |
RETURN (theCopy); |
|
2737 |
} |
|
5755 | 2738 |
} |
2739 |
%}. |
|
2740 |
"/ fallBack for special objects & memoryAllocation failure case |
|
2741 |
||
2742 |
^ self slowShallowCopy |
|
2743 |
! |
|
2744 |
||
2745 |
simpleDeepCopy |
|
2746 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2747 |
This method does NOT handle cycles - but is included to allow this |
5755 | 2748 |
slightly faster copy in situations where it is known that |
2749 |
no recursive references occur (LargeIntegers for example). |
|
2750 |
NOTICE: you will run into trouble, when trying this with recursive |
|
2751 |
objects (usually recursionInterrupt or memory-alert). |
|
8383 | 2752 |
This method corresponds to the 'traditional' deepCopy found in the Blue book." |
5755 | 2753 |
|
2754 |
|myClass aCopy| |
|
2755 |
||
2756 |
(myClass := self class) isVariable ifTrue:[ |
|
14975 | 2757 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2758 |
] ifFalse:[ |
14975 | 2759 |
aCopy := myClass basicNew |
5755 | 2760 |
]. |
2761 |
||
2762 |
"copy the instance variables" |
|
2763 |
aCopy cloneFrom:self performing:#simpleDeepCopy. |
|
2764 |
^ aCopy |
|
2765 |
||
2766 |
"a bad example (but ST/X should survive ...)" |
|
2767 |
" |
|
2768 |
|a| |
|
2769 |
a := Array new:3. |
|
2770 |
a at:3 put:a. |
|
2771 |
a simpleDeepCopy |
|
2772 |
" |
|
2773 |
! |
|
2774 |
||
2775 |
skipInstvarIndexInDeepCopy:index |
|
2776 |
"a helper for deepCopy; only indices for which this method returns |
|
2777 |
false are copied in a deep copy. |
|
2778 |
The default is false here - which means that everything is copied. |
|
2779 |
Can be redefined in subclasses for partial copies" |
|
2780 |
||
2781 |
^ false |
|
2782 |
! |
|
2783 |
||
2784 |
slowShallowCopy |
|
2785 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2786 |
i.e. the copy shares referenced instvars with its original. |
|
2787 |
This method is only invoked as a fallback from #shallowCopy." |
|
2788 |
||
2789 |
|myClass aCopy| |
|
2790 |
||
2791 |
(myClass := self class) isVariable ifTrue:[ |
|
14975 | 2792 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2793 |
] ifFalse:[ |
14975 | 2794 |
aCopy := myClass basicNew |
5755 | 2795 |
]. |
2796 |
||
2797 |
"copy the instance variables" |
|
2798 |
aCopy cloneFrom:self performing:#yourself. |
|
2799 |
^ aCopy |
|
2800 |
! ! |
|
2801 |
||
2802 |
!Object methodsFor:'debugging'! |
|
2803 |
||
7621 | 2804 |
assert:aBooleanOrBlock |
13800 | 2805 |
"fail and report an error, if the argument does not evaluate to true" |
6964 | 2806 |
|
11662 | 2807 |
"{ Pragma: +optSpace }" |
2808 |
||
11021 | 2809 |
<resource: #skipInDebuggersWalkBack> |
2810 |
||
8876 | 2811 |
aBooleanOrBlock == true ifTrue:[^ self]. |
11141
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2812 |
(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
|
2813 |
|
8876 | 2814 |
"/ could still be a block or false. |
11662 | 2815 |
(aBooleanOrBlock value) ifFalse:[ |
14975 | 2816 |
AssertionFailedError |
2817 |
raiseRequestWith:self |
|
2818 |
errorString:('Assertion failed in ', |
|
15219 | 2819 |
thisContext methodHome sender printString, |
2820 |
'[', thisContext methodHome sender lineNumber printString,']') |
|
11662 | 2821 |
]. |
2822 |
||
2823 |
" |
|
2824 |
self assert:false |
|
2825 |
" |
|
13039 | 2826 |
|
2827 |
"Modified: / 20-08-2010 / 17:13:06 / cg" |
|
7621 | 2828 |
! |
2829 |
||
2830 |
assert:aBooleanOrBlock message:messageIfFailing |
|
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2831 |
"fail, if the argument does not evaluate to true and report an error" |
6961 | 2832 |
|
2833 |
"{ Pragma: +optSpace }" |
|
2834 |
||
11021 | 2835 |
<resource: #skipInDebuggersWalkBack> |
2836 |
||
11141
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2837 |
aBooleanOrBlock == true ifTrue:[^ self]. |
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2838 |
(Smalltalk at:#IgnoreAssertion ifAbsent:false) == true ifTrue:[^ self]. |
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2839 |
|
7621 | 2840 |
(aBooleanOrBlock value) ifFalse:[ |
14975 | 2841 |
AssertionFailedError |
2842 |
raiseRequestWith:self |
|
15219 | 2843 |
errorString:(messageIfFailing, ' {',thisContext methodHome sender "methodHome" printString,' }') |
11662 | 2844 |
]. |
2845 |
||
2846 |
" |
|
2847 |
self assert:false message:'xxx' |
|
10651 | 2848 |
" |
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2849 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2850 |
"Modified (comment): / 06-03-2012 / 11:26:48 / cg" |
6961 | 2851 |
! |
2852 |
||
5755 | 2853 |
basicInspect |
2854 |
"{ Pragma: +optSpace }" |
|
2855 |
||
2856 |
"launch an inspector on the receiver. |
|
2857 |
this method should NOT be redefined in subclasses." |
|
2858 |
||
2859 |
Inspector isNil ifTrue:[ |
|
14975 | 2860 |
" |
2861 |
for systems without GUI |
|
2862 |
" |
|
2863 |
self warn:'No Inspector defined (Inspector is nil).' |
|
5755 | 2864 |
] ifFalse:[ |
14975 | 2865 |
Inspector openOn:self |
5755 | 2866 |
] |
2867 |
||
2868 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
2869 |
! |
|
2870 |
||
11025 | 2871 |
breakPoint:someKey |
6954 | 2872 |
"{ Pragma: +optSpace }" |
2873 |
||
2874 |
"Like halt, but disabled by default. |
|
2875 |
Can be easily enabled. |
|
2876 |
Can be filtered on the arguments value (typically: a symbol). |
|
2877 |
Code with breakpoints may be even checked into the source repository" |
|
2878 |
||
2879 |
"Example: nil breakPoint:#stefan" |
|
2880 |
||
11025 | 2881 |
<resource: #skipInDebuggersWalkBack> |
2882 |
||
11048 | 2883 |
"/ dont send #breakPoint:info: here - ask cg why. |
2884 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
14975 | 2885 |
^ HaltSignal |
2886 |
raiseRequestWith:someKey |
|
2887 |
errorString:('Breakpoint encountered: %1' bindWith:someKey) |
|
11048 | 2888 |
]. |
11025 | 2889 |
|
2890 |
" |
|
2891 |
nil breakPoint:#stefan |
|
2892 |
nil breakPoint:#stefan info:'Hello' |
|
2893 |
Smalltalk enableBreakPoint:#stefan. |
|
2894 |
Smalltalk disableBreakPoint:#stefan. |
|
11048 | 2895 |
|
2896 |
EncounteredBreakPoints. |
|
2897 |
Smalltalk enableBreakPoint:#cg. |
|
2898 |
Smalltalk disableBreakPoint:#cg. |
|
11025 | 2899 |
" |
2900 |
! |
|
2901 |
||
2902 |
breakPoint:someKey info:infoString |
|
2903 |
"{ Pragma: +optSpace }" |
|
2904 |
||
2905 |
"Like halt, but disabled by default. |
|
2906 |
Can be easily enabled. |
|
2907 |
Can be filtered on the arguments value (typically: a symbol). |
|
2908 |
Code with breakpoints may be even checked into the source repository" |
|
2909 |
||
2910 |
"Example: nil breakPoint:#stefan" |
|
2911 |
||
2912 |
<resource: #skipInDebuggersWalkBack> |
|
2913 |
||
2914 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
14975 | 2915 |
^ HaltSignal |
2916 |
raiseRequestWith:someKey |
|
2917 |
errorString:(infoString bindWith:someKey) |
|
11025 | 2918 |
]. |
6954 | 2919 |
! |
2920 |
||
5995 | 2921 |
browse |
2922 |
"open a browser on the receivers class" |
|
2923 |
||
2924 |
self class theNonMetaclass browse |
|
2925 |
||
2926 |
" |
|
2927 |
10 browse |
|
2928 |
Collection browse |
|
2929 |
Collection class browse |
|
2930 |
" |
|
2931 |
! |
|
2932 |
||
11244 | 2933 |
debuggingCodeFor:someKey is:aBlock |
2934 |
"{ Pragma: +optSpace }" |
|
2935 |
||
2936 |
"aBlock is evaluated if breakPoints for somekey are enabled. |
|
2937 |
Allows for debugging code to be enabled/disabled via the breakpoint browser. |
|
2938 |
Can be easily enabled. |
|
2939 |
Can be filtered on the arguments value (typically: a symbol). |
|
2940 |
Code with breakpoints may be even checked into the source repository" |
|
2941 |
||
2942 |
"Example: nil debuggingCodeFor:#cg is:[ self halt ]" |
|
2943 |
||
2944 |
<resource: #skipInDebuggersWalkBack> |
|
2945 |
||
2946 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
14975 | 2947 |
aBlock value |
11244 | 2948 |
]. |
2949 |
||
2950 |
" |
|
2951 |
Smalltalk disableBreakPoint:#cg. |
|
12340
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
2952 |
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
|
2953 |
nil debuggingCodeFor:#stefan is:[ Transcript showCR:'here is some debug message for sv' ]. |
11244 | 2954 |
Smalltalk enableBreakPoint:#cg. |
12340
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
2955 |
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
|
2956 |
nil debuggingCodeFor:#stefan is:[ Transcript showCR:'here is some debug message for sv' ]. |
11244 | 2957 |
Smalltalk disableBreakPoint:#cg. |
2958 |
||
2959 |
" |
|
2960 |
! |
|
2961 |
||
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2962 |
disableAllBreakPoints |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2963 |
"disable all parametrized breakPoints (with any key as parameter)" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2964 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2965 |
EnabledBreakPoints := nil |
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 |
" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2968 |
nil enableBreakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2969 |
nil breakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2970 |
nil disableAllBreakPoints. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2971 |
nil breakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2972 |
" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2973 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2974 |
"Created: / 06-03-2012 / 15:32:28 / cg" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2975 |
! |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2976 |
|
11025 | 2977 |
disableBreakPoint:someKey |
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2978 |
"disable parametrized breakPoints with someKey as parameter" |
11025 | 2979 |
|
2980 |
"{ Pragma: +optSpace }" |
|
2981 |
||
2982 |
EnabledBreakPoints notNil ifTrue:[ |
|
14975 | 2983 |
EnabledBreakPoints remove:someKey ifAbsent:[]. |
2984 |
EnabledBreakPoints isEmpty ifTrue:[ |
|
2985 |
EnabledBreakPoints := nil |
|
2986 |
]. |
|
11025 | 2987 |
]. |
2988 |
||
2989 |
" |
|
2990 |
nil enableBreakPoint:#cg. |
|
2991 |
nil breakPoint:#cg. |
|
2992 |
nil disableBreakPoint:#cg |
|
2993 |
nil breakPoint:#cg. |
|
2994 |
" |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2995 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2996 |
"Modified (comment): / 06-03-2012 / 15:31:51 / cg" |
11025 | 2997 |
! |
2998 |
||
2999 |
enableBreakPoint:someKey |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3000 |
"enable parametrized breakPoints with someKey as parameter" |
11025 | 3001 |
|
3002 |
"{ Pragma: +optSpace }" |
|
3003 |
||
3004 |
EnabledBreakPoints isNil ifTrue:[ |
|
14975 | 3005 |
EnabledBreakPoints := Set new. |
11025 | 3006 |
]. |
3007 |
EnabledBreakPoints add:someKey. |
|
3008 |
||
3009 |
" |
|
3010 |
nil enableBreakPoint:#cg. |
|
3011 |
nil breakPoint:#cg. |
|
3012 |
nil disableBreakPoint:#cg |
|
3013 |
nil breakPoint:#cg. |
|
3014 |
" |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3015 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3016 |
"Modified (comment): / 06-03-2012 / 15:31:47 / cg" |
11025 | 3017 |
! |
3018 |
||
11048 | 3019 |
halt |
3020 |
"{ Pragma: +optSpace }" |
|
3021 |
||
3022 |
"enter debugger with halt-message. |
|
3023 |
The error is reported by raising the HaltSignal exception." |
|
3024 |
||
3025 |
<resource: #skipInDebuggersWalkBack> |
|
3026 |
||
13136 | 3027 |
Smalltalk ignoreHalt ifTrue:[^ self]. |
14830 | 3028 |
"/ don't send #halt: here - ask cg why. |
14974 | 3029 |
HaltInterrupt raiseRequestWith:#halt. |
3030 |
^ self |
|
3031 |
||
3032 |
" |
|
3033 |
(3 halt * 5) |
|
3034 |
" |
|
11048 | 3035 |
|
13136 | 3036 |
"Modified: / 02-08-1999 / 17:00:29 / stefan" |
3037 |
"Modified: / 18-11-2010 / 11:21:51 / cg" |
|
11048 | 3038 |
! |
3039 |
||
3040 |
halt:aString |
|
3041 |
"{ Pragma: +optSpace }" |
|
3042 |
||
3043 |
"enter debugger with halt-message. |
|
3044 |
The error is reported by raising the HaltSignal exception." |
|
3045 |
||
3046 |
<resource: #skipInDebuggersWalkBack> |
|
3047 |
||
13136 | 3048 |
Smalltalk ignoreHalt ifTrue:[^ self]. |
14974 | 3049 |
HaltInterrupt raiseRequestWith:#halt: errorString:aString. |
3050 |
^ self |
|
11048 | 3051 |
|
13136 | 3052 |
"Modified: / 18-11-2010 / 11:22:16 / cg" |
11048 | 3053 |
! |
3054 |
||
11025 | 3055 |
isBreakPointEnabled:someKey |
3056 |
"{ Pragma: +optSpace }" |
|
3057 |
||
3058 |
"controls which breakpoints to be enabled." |
|
3059 |
||
3060 |
"/ something = OperatingSystem getLoginName ifTrue:[^ true]. |
|
3061 |
"/ something = 'testThis' ifTrue:[^ true]. |
|
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
3062 |
EncounteredBreakPoints notNil ifTrue:[ |
14975 | 3063 |
EncounteredBreakPoints add:someKey |
11335 | 3064 |
]. |
3065 |
||
3066 |
^ (EnabledBreakPoints notNil and:[ EnabledBreakPoints includes:someKey ]) |
|
11025 | 3067 |
|
3068 |
" |
|
3069 |
nil enableBreakPoint:#cg. |
|
3070 |
nil breakPoint:#cg. |
|
3071 |
nil disableBreakPoint:#cg |
|
3072 |
nil breakPoint:#cg. |
|
11045
85315d8893e4
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11044
diff
changeset
|
3073 |
|
85315d8893e4
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11044
diff
changeset
|
3074 |
EncounteredBreakPoints := Set new. |
11025 | 3075 |
" |
3076 |
! |
|
3077 |
||
5755 | 3078 |
mustBeBoolean |
3079 |
"this message is sent by the VM, if a non-Boolean receiver is encountered |
|
3080 |
in an if* or while* message. |
|
3081 |
Caveat: for now, this is only sent by the interpreter; |
|
3082 |
both the JIT and the stc compiler treat it as undefined." |
|
3083 |
||
11021 | 3084 |
<resource: #skipInDebuggersWalkBack> |
3085 |
||
5755 | 3086 |
self error:'Non boolean receiver - proceed for truth' mayProceed:true. |
3087 |
^ true |
|
3088 |
! |
|
3089 |
||
3090 |
mustBeKindOf:aClass |
|
10460 | 3091 |
"for compatibility & debugging support: |
5755 | 3092 |
check if the receiver isKindOf:aClass and raise an error if not. |
3093 |
Notice: |
|
14975 | 3094 |
it is VERY questionable, if it makes sense to add manual |
3095 |
type checks to a dynamically typed language like smalltalk. |
|
3096 |
It will, at least, slow down performance, |
|
3097 |
make your code less reusable and clutter your code with stupid sends |
|
3098 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
3099 |
use of isXXX check methods. |
|
5755 | 3100 |
You see: The author does not like this at all ..." |
3101 |
||
11021 | 3102 |
<resource: #skipInDebuggersWalkBack> |
3103 |
||
5755 | 3104 |
(self isKindOf:aClass) ifFalse:[ |
14975 | 3105 |
self error:'argument is not of expected type' |
5755 | 3106 |
] |
3107 |
! |
|
3108 |
||
6950 | 3109 |
obsoleteFeatureWarning |
3110 |
"{ Pragma: +optSpace }" |
|
3111 |
||
3112 |
"in methods which are going to be changed, a send to |
|
3113 |
this method is used to tell programmers that some feature/semantics is |
|
3114 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3115 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)." |
6950 | 3116 |
|
3117 |
self obsoleteFeatureWarning:nil from:thisContext sender |
|
3118 |
! |
|
3119 |
||
3120 |
obsoleteFeatureWarning:message |
|
3121 |
"{ Pragma: +optSpace }" |
|
3122 |
||
3123 |
"in methods which are going to be changed, a send to |
|
3124 |
this method is used to tell programmers that some feature/semantics is |
|
3125 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3126 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3127 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3128 |
|
3129 |
self obsoleteFeatureWarning:message from:thisContext sender |
|
3130 |
! |
|
3131 |
||
3132 |
obsoleteFeatureWarning:message from:aContext |
|
3133 |
"{ Pragma: +optSpace }" |
|
3134 |
||
3135 |
"in methods which are going to be changed, a send to |
|
3136 |
this method is used to tell programmers that some feature/semantics is |
|
3137 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3138 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3139 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3140 |
|
11527 | 3141 |
|spec sender| |
6950 | 3142 |
|
3143 |
spec := aContext methodPrintString. |
|
11527 | 3144 |
sender := aContext sender. |
3145 |
||
6950 | 3146 |
('WARNING: the ''' , spec , ''' semantics will be changed.') infoPrintCR. |
3147 |
(' Its behavior may be different in future ST/X versions.') infoPrintCR. |
|
11527 | 3148 |
(' called from ' , sender printString) infoPrintCR. |
3149 |
((sender selector ? '') startsWith:'perform:') ifTrue:[ |
|
3150 |
(' called from ' , sender sender printString) infoPrintCR. |
|
7204 | 3151 |
]. |
6950 | 3152 |
message notNil ifTrue:[ |
14975 | 3153 |
'------> ' infoPrint. message infoPrintCR |
6950 | 3154 |
] |
3155 |
||
3156 |
" |
|
3157 |
Object obsoleteFeatureWarning:'foo' from:thisContext sender sender |
|
3158 |
" |
|
3159 |
! |
|
3160 |
||
5755 | 3161 |
obsoleteMethodWarning |
3162 |
"{ Pragma: +optSpace }" |
|
3163 |
||
3164 |
"in methods which are going to be obsoleted, a self send to |
|
3165 |
this method is used to tell programmers that a method is |
|
3166 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3167 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3168 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3169 |
|
3170 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
3171 |
! |
|
3172 |
||
3173 |
obsoleteMethodWarning:message |
|
3174 |
"{ Pragma: +optSpace }" |
|
3175 |
||
3176 |
"in methods which are going to be obsoleted, a self send to |
|
3177 |
this method is used to tell programmers that a method is |
|
3178 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3179 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3180 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3181 |
|
3182 |
self obsoleteMethodWarning:message from:thisContext sender |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3183 |
! |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3184 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3185 |
obsoleteMethodWarning:message from:aContext |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3186 |
"{ Pragma: +optSpace }" |
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 |
"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
|
3189 |
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
|
3190 |
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
|
3191 |
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
|
3192 |
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
|
3193 |
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
|
3194 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3195 |
|spec sender| |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3196 |
|
9509 | 3197 |
Smalltalk isSmalltalkDevelopmentSystem ifFalse:[ |
14975 | 3198 |
"ignore in production systems" |
3199 |
^ self. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3200 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3201 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3202 |
spec := aContext methodPrintString. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3203 |
sender := aContext sender. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3204 |
('WARNING: the ''' , spec , ''' method is obsolete.') infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3205 |
(' 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
|
3206 |
(' called from ' , sender printString) infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3207 |
(sender selector startsWith:'perform:') ifTrue:[ |
14975 | 3208 |
sender := sender sender. |
3209 |
(sender selector startsWith:'perform:') ifTrue:[ |
|
3210 |
sender := sender sender. |
|
3211 |
]. |
|
3212 |
(' called from ' , sender printString) infoPrintCR. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3213 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3214 |
message notNil ifTrue:[ |
14975 | 3215 |
'------> ' infoPrint. message infoPrintCR |
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3216 |
] |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3217 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3218 |
" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3219 |
Object obsoleteMethodWarning:'foo' from:thisContext sender sender |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3220 |
" |
9509 | 3221 |
|
3222 |
"Modified: / 10-08-2006 / 13:13:11 / cg" |
|
10558 | 3223 |
! |
3224 |
||
12341 | 3225 |
todo |
3226 |
"used to mark code pieces that have to be implemented" |
|
3227 |
||
3228 |
<resource: #skipInDebuggersWalkBack> |
|
3229 |
||
3230 |
self halt:'more work needed here'. |
|
3231 |
||
3232 |
" |
|
3233 |
example: |
|
3234 |
||
14975 | 3235 |
... |
3236 |
self todo. |
|
3237 |
... |
|
12341 | 3238 |
" |
3239 |
! |
|
3240 |
||
10558 | 3241 |
todo:aBlock |
3242 |
"used to mark code pieces that have to be implemented" |
|
3243 |
||
12341 | 3244 |
<resource: #skipInDebuggersWalkBack> |
3245 |
||
10558 | 3246 |
"/ self halt. |
3247 |
"/ aBlock value. |
|
3248 |
||
3249 |
" |
|
3250 |
example: |
|
3251 |
||
14975 | 3252 |
... |
3253 |
self todo:[ |
|
3254 |
code which needs more work ... |
|
3255 |
]. |
|
3256 |
... |
|
10558 | 3257 |
" |
3258 |
||
3259 |
"Created: / 25-05-2007 / 21:34:39 / cg" |
|
3260 |
"Modified: / 29-05-2007 / 12:11:33 / cg" |
|
5755 | 3261 |
! ! |
3262 |
||
3263 |
!Object methodsFor:'dependents access'! |
|
3264 |
||
3265 |
addDependent:anObject |
|
3266 |
"make the argument, anObject be a dependent of the receiver" |
|
3267 |
||
3268 |
|wasBlocked| |
|
3269 |
||
3270 |
"/ must do this save from interrupts, since the dependents collection |
|
3271 |
"/ is possibly accessed from multiple threads. |
|
3272 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3273 |
"/ faster execution. |
|
3274 |
||
3275 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3276 |
[ |
|
14975 | 3277 |
|deps dep| |
3278 |
||
3279 |
deps := self dependents. |
|
3280 |
||
3281 |
"/ to save a fair amount of memory in case of |
|
3282 |
"/ many dependencies, we store a single dependent in |
|
3283 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3284 |
"/ added. |
|
3285 |
||
3286 |
(deps isNil or:[deps size == 0]) ifTrue:[ |
|
3287 |
self dependents:(WeakArray with:anObject) |
|
3288 |
] ifFalse:[ |
|
3289 |
deps class == WeakArray ifTrue:[ |
|
3290 |
dep := deps at:1. |
|
3291 |
dep ~~ anObject ifTrue:[ |
|
3292 |
(dep isNil or:[dep == 0]) ifTrue:[ |
|
3293 |
deps at:1 put:anObject |
|
3294 |
] ifFalse:[ |
|
3295 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
3296 |
] |
|
3297 |
] |
|
3298 |
] ifFalse:[ |
|
3299 |
deps add:anObject |
|
3300 |
] |
|
3301 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3302 |
] ensure:[ |
14975 | 3303 |
wasBlocked ifFalse:[ |
3304 |
OperatingSystem unblockInterrupts |
|
3305 |
] |
|
5755 | 3306 |
] |
3307 |
||
3308 |
"Modified: / 27.10.1997 / 19:35:52 / cg" |
|
3309 |
! |
|
3310 |
||
3311 |
breakDependents |
|
3312 |
"remove all dependencies from the receiver" |
|
3313 |
||
3314 |
self dependents:nil. |
|
3315 |
self nonWeakDependents:nil |
|
3316 |
||
3317 |
"Modified: / 19.4.1996 / 10:55:36 / cg" |
|
3318 |
"Created: / 27.2.1998 / 11:26:11 / stefan" |
|
3319 |
! |
|
3320 |
||
8542 | 3321 |
breakDependentsRecursively |
10460 | 3322 |
"remove all dependencies from the receiver and |
8542 | 3323 |
recursively from all objects referred to by the receiver." |
3324 |
||
3325 |
self breakDependents. |
|
10460 | 3326 |
1 to:self class instSize do:[:idx | |
14975 | 3327 |
(self instVarAt:idx) breakDependentsRecursively. |
10460 | 3328 |
]. |
3329 |
1 to:self basicSize do:[:idx | |
|
14975 | 3330 |
(self basicAt:idx) breakDependentsRecursively. |
8542 | 3331 |
] |
3332 |
! |
|
3333 |
||
5755 | 3334 |
dependents |
3335 |
"return a Collection of dependents. |
|
3336 |
The default implementation here uses a global WeakDictionary to store |
|
10460 | 3337 |
dependents |
5755 | 3338 |
This may be too slow for high frequency change&update, |
3339 |
therefore, some classes (Model) redefine this for better performance. |
|
3340 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
3341 |
||
3342 |
|deps| |
|
3343 |
||
3344 |
(deps := Dependencies at:self ifAbsent:nil) isNil ifTrue:[ |
|
14975 | 3345 |
^ #(). |
5755 | 3346 |
]. |
3347 |
^ deps |
|
3348 |
||
3349 |
"Modified: / 26.1.1998 / 11:18:15 / cg" |
|
3350 |
! |
|
3351 |
||
3352 |
dependents:aCollection |
|
3353 |
"set the collection of dependents. |
|
3354 |
The default implementation here uses a global Dictionary to store |
|
3355 |
dependents which may be too slow for high frequency change&update. |
|
3356 |
Therefore, some classes (Model) redefine this for better performance." |
|
3357 |
||
3358 |
"/ must do this save from interrupts, since the dependents collection |
|
3359 |
"/ is possibly accessed from multiple threads. |
|
3360 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3361 |
"/ faster execution (and to avoid creation of garbage blocks). |
|
3362 |
||
3363 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
14975 | 3364 |
"/ the common case - already blocked |
3365 |
||
3366 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
3367 |
Dependencies removeKey:self ifAbsent:nil |
|
3368 |
] ifFalse:[ |
|
3369 |
Dependencies at:self put:aCollection |
|
3370 |
]. |
|
3371 |
^ self |
|
5755 | 3372 |
]. |
3373 |
||
3374 |
[ |
|
14975 | 3375 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3376 |
Dependencies removeKey:self ifAbsent:nil |
|
3377 |
] ifFalse:[ |
|
3378 |
Dependencies at:self put:aCollection |
|
3379 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3380 |
] ensure:[ |
14975 | 3381 |
OperatingSystem unblockInterrupts |
5755 | 3382 |
] |
3383 |
||
3384 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
|
3385 |
! |
|
3386 |
||
3387 |
dependentsDo:aBlock |
|
3388 |
"evaluate aBlock for all of my dependents" |
|
3389 |
||
3390 |
|deps nwDeps| |
|
3391 |
||
3392 |
deps := self dependents. |
|
3393 |
deps size ~~ 0 ifTrue:[ |
|
14975 | 3394 |
deps do:[:d | |
3395 |
(d notNil and:[d ~~ 0]) ifTrue:[ |
|
3396 |
aBlock value:d |
|
3397 |
] |
|
3398 |
] |
|
5755 | 3399 |
]. |
3400 |
nwDeps := self nonWeakDependents. |
|
3401 |
(nwDeps ~~ deps and:[nwDeps size ~~ 0]) ifTrue:[ |
|
14975 | 3402 |
nwDeps do:aBlock |
5755 | 3403 |
]. |
3404 |
||
3405 |
"Modified: / 30.1.1998 / 14:03:40 / cg" |
|
3406 |
! |
|
3407 |
||
3408 |
myDependents |
|
3409 |
"same as dependents - ST-80 compatibility" |
|
3410 |
||
3411 |
^ self dependents |
|
3412 |
! |
|
3413 |
||
3414 |
release |
|
3415 |
"remove all references to objects that may refer to self. |
|
3416 |
Subclasses may redefine this method but should do a 'super release'." |
|
3417 |
||
3418 |
self breakDependents |
|
3419 |
||
3420 |
"Modified: / 27.2.1998 / 11:29:35 / stefan" |
|
3421 |
! |
|
3422 |
||
3423 |
removeDependent:anObject |
|
3424 |
"make the argument, anObject be independent of the receiver" |
|
3425 |
||
3426 |
|wasBlocked| |
|
3427 |
||
3428 |
"/ must do this save from interrupts, since the dependents collection |
|
3429 |
"/ is possibly accessed from multiple threads. |
|
3430 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3431 |
"/ faster execution. |
|
3432 |
||
3433 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3434 |
[ |
|
14975 | 3435 |
|deps n d| |
3436 |
||
3437 |
deps := self dependents. |
|
3438 |
deps size ~~ 0 ifTrue:[ |
|
3439 |
||
3440 |
"/ to save a fair amount of memory in case of |
|
3441 |
"/ many dependencies, we store a single dependent in |
|
3442 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3443 |
"/ added. Here we have to do the inverse ... |
|
3444 |
||
3445 |
((deps class == WeakArray) or:[deps class == Array]) ifTrue:[ |
|
3446 |
((d := deps at:1) == anObject |
|
3447 |
or:[d isNil |
|
3448 |
or:[d == 0]]) ifTrue:[ |
|
3449 |
self dependents:nil |
|
3450 |
] |
|
3451 |
] ifFalse:[ |
|
3452 |
deps remove:anObject ifAbsent:[]. |
|
3453 |
(n := deps size) == 0 ifTrue:[ |
|
3454 |
self dependents:nil |
|
3455 |
] ifFalse:[ |
|
3456 |
n == 1 ifTrue:[ |
|
3457 |
d := deps firstIfEmpty:nil. |
|
3458 |
d notNil ifTrue:[ |
|
3459 |
deps := (deps isWeakCollection ifTrue:[WeakArray] ifFalse:[Array]) with:d |
|
3460 |
] ifFalse:[ |
|
3461 |
deps := nil |
|
3462 |
]. |
|
3463 |
self dependents:deps. |
|
3464 |
] |
|
3465 |
] |
|
3466 |
] |
|
3467 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3468 |
] ensure:[ |
14975 | 3469 |
wasBlocked ifFalse:[ |
3470 |
OperatingSystem unblockInterrupts |
|
3471 |
] |
|
5755 | 3472 |
] |
3473 |
||
13500 | 3474 |
"Modified: / 05-07-2011 / 22:49:31 / cg" |
5755 | 3475 |
! ! |
3476 |
||
7266 | 3477 |
!Object methodsFor:'dependents access (non weak)'! |
5755 | 3478 |
|
3479 |
addNonWeakDependent:anObject |
|
3480 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
|
10460 | 3481 |
Be careful: this nonWeakDependency will prevent the dependent from being |
5755 | 3482 |
garbage collected unless the dependency is removed. |
3483 |
This is a private mechanism, for directed dependencies." |
|
3484 |
||
3485 |
|wasBlocked| |
|
3486 |
||
3487 |
"/ must do this save from interrupts, since the dependents collection |
|
3488 |
"/ is possibly accessed from multiple threads. |
|
3489 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3490 |
"/ faster execution. |
|
3491 |
||
3492 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3493 |
[ |
|
14975 | 3494 |
|deps dep| |
3495 |
||
3496 |
deps := self nonWeakDependents. |
|
3497 |
||
3498 |
"/ to save a fair amount of memory in case of |
|
3499 |
"/ many dependencies, we store a single dependent in |
|
3500 |
"/ an Array, and switch to a Set if more dependents are |
|
3501 |
"/ added. |
|
3502 |
||
3503 |
deps size == 0 ifTrue:[ |
|
3504 |
anObject notNil ifTrue:[ |
|
3505 |
self nonWeakDependents:(Array with:anObject). |
|
3506 |
] ifFalse:[ |
|
3507 |
"adding nil causes problems when adding the next one |
|
3508 |
(see below: trying to add nil to IdentitySet)" |
|
9442 | 3509 |
"/ self halt:'try to add nil to list of dependents'. |
14975 | 3510 |
]. |
3511 |
] ifFalse:[ |
|
3512 |
deps class == Array ifTrue:[ |
|
3513 |
dep := deps at:1. |
|
3514 |
dep ~~ anObject ifTrue:[ |
|
3515 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
3516 |
] |
|
3517 |
] ifFalse:[ |
|
3518 |
deps add:anObject |
|
3519 |
] |
|
3520 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3521 |
] ensure:[ |
14975 | 3522 |
wasBlocked ifFalse:[ |
3523 |
OperatingSystem unblockInterrupts |
|
3524 |
] |
|
5755 | 3525 |
] |
3526 |
||
3527 |
"Created: / 19.4.1996 / 10:54:08 / cg" |
|
3528 |
"Modified: / 30.1.1998 / 14:03:08 / cg" |
|
3529 |
! |
|
3530 |
||
3531 |
nonWeakDependents |
|
3532 |
"return a Collection of nonWeakDependents - empty if there is none. |
|
3533 |
This is a private mechanism for directed dependencies." |
|
3534 |
||
3535 |
NonWeakDependencies isNil ifTrue:[^ #()]. |
|
3536 |
^ NonWeakDependencies at:self ifAbsent:#() |
|
3537 |
||
3538 |
"Created: / 19.4.1996 / 10:55:06 / cg" |
|
3539 |
"Modified: / 30.1.1998 / 14:06:47 / cg" |
|
3540 |
! |
|
3541 |
||
3542 |
nonWeakDependents:aCollection |
|
3543 |
"set the collection of nonWeak dependents. |
|
3544 |
This is a private helper for directed dependencies." |
|
3545 |
||
3546 |
[ |
|
14975 | 3547 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3548 |
NonWeakDependencies removeKey:self ifAbsent:nil |
|
3549 |
] ifFalse:[ |
|
3550 |
NonWeakDependencies at:self put:aCollection |
|
3551 |
] |
|
5755 | 3552 |
] valueUninterruptably |
3553 |
||
3554 |
"Created: 19.4.1996 / 11:07:47 / cg" |
|
3555 |
! |
|
3556 |
||
3557 |
removeNonWeakDependent:anObject |
|
3558 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
|
3559 |
(i.e. make it independent of the receiver)" |
|
3560 |
||
3561 |
|wasBlocked| |
|
3562 |
||
3563 |
"/ must do this save from interrupts, since the dependents collection |
|
3564 |
"/ is possibly accessed from multiple threads. |
|
3565 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3566 |
"/ faster execution. |
|
3567 |
||
3568 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3569 |
[ |
|
14975 | 3570 |
|deps n| |
3571 |
||
3572 |
deps := self nonWeakDependents. |
|
3573 |
deps size ~~ 0 ifTrue:[ |
|
3574 |
deps class == Array ifTrue:[ |
|
3575 |
(deps at:1) == anObject ifTrue:[ |
|
3576 |
self nonWeakDependents:nil |
|
3577 |
] |
|
3578 |
] ifFalse:[ |
|
3579 |
deps remove:anObject ifAbsent:[]. |
|
3580 |
(n := deps size) == 0 ifTrue:[ |
|
3581 |
self nonWeakDependents:nil |
|
3582 |
] ifFalse:[ |
|
3583 |
n == 1 ifTrue:[ |
|
3584 |
self nonWeakDependents:(Array with:(deps first)) |
|
3585 |
] |
|
3586 |
] |
|
3587 |
] |
|
3588 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3589 |
] ensure:[ |
14975 | 3590 |
wasBlocked ifFalse:[ |
3591 |
OperatingSystem unblockInterrupts |
|
3592 |
] |
|
5755 | 3593 |
] |
3594 |
||
3595 |
"Created: / 19.4.1996 / 11:44:44 / cg" |
|
3596 |
"Modified: / 30.1.1998 / 14:04:01 / cg" |
|
3597 |
! ! |
|
3598 |
||
9279 | 3599 |
|
3600 |
||
5755 | 3601 |
!Object methodsFor:'displaying'! |
3602 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3603 |
ascentOn:aGC |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3604 |
"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
|
3605 |
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
|
3606 |
coordinate is given by y. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3607 |
In other words: some draw above the given y coordinate. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3608 |
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
|
3609 |
the given y coordinate." |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3610 |
|
11065
17c01b01000f
Simplify (and speed up) #ascentOn:
Stefan Vogel <sv@exept.de>
parents:
11048
diff
changeset
|
3611 |
^ aGC fontAscent |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3612 |
! |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3613 |
|
6900 | 3614 |
displayOn:aGCOrStream |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3615 |
"Compatibility |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3616 |
append a printed desription on some stream (Dolphin, Squeak) |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3617 |
OR: |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3618 |
display the receiver in a graphicsContext at 0@0 (ST80). |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3619 |
This method allows for any object to be displayed in some view |
5755 | 3620 |
(although the fallBack is to display its printString ...)" |
3621 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3622 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3623 |
"/ 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
|
3624 |
aGCOrStream isStream ifTrue:[ |
14975 | 3625 |
self printOn:aGCOrStream. |
3626 |
^ self |
|
6900 | 3627 |
]. |
3628 |
^ self displayOn:aGCOrStream x:0 y:0. |
|
5755 | 3629 |
|
3630 |
"Created: 29.5.1996 / 16:28:58 / cg" |
|
3631 |
! |
|
3632 |
||
3633 |
displayOn:aGC at:aPoint |
|
3634 |
"ST-80 Compatibility |
|
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:(aPoint x) y:(aPoint y). |
|
3639 |
! |
|
3640 |
||
3641 |
displayOn:aGC x:x y:y |
|
3642 |
"display the receiver in a graphicsContext - this method allows |
|
3643 |
for any object to be displayed in a ListView - for example." |
|
3644 |
||
3645 |
self displayOn:aGC x:x y:y opaque:false |
|
3646 |
||
3647 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3648 |
! |
|
3649 |
||
3650 |
displayOn:aGc x:x y:y opaque:opaque |
|
3651 |
"display the receiver in a graphicsContext - this method allows |
|
3652 |
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
|
3653 |
The fallBack here shows the receivers displayString. |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3654 |
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
|
3655 |
ask using #ascentOn: if required" |
5755 | 3656 |
|
3657 |
|s yBaseline| |
|
3658 |
||
3659 |
s := self displayString. |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3660 |
yBaseline := y "+ aGc font ascent". |
5755 | 3661 |
opaque ifTrue:[ |
14975 | 3662 |
aGc displayOpaqueString:s x:x y:yBaseline. |
5755 | 3663 |
] ifFalse:[ |
14975 | 3664 |
aGc displayString:s x:x y:yBaseline. |
5755 | 3665 |
]. |
3666 |
||
3667 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3668 |
! |
|
3669 |
||
3670 |
displayOpaqueOn:aGC x:x y:y |
|
3671 |
"display the receiver in a graphicsContext - this method allows |
|
3672 |
for any object to be displayed in a ListView - for example." |
|
3673 |
||
3674 |
self displayOn:aGC x:x y:y opaque:true |
|
3675 |
||
3676 |
"Modified: / 29.5.1996 / 16:29:38 / cg" |
|
3677 |
"Created: / 26.10.1997 / 15:01:36 / cg" |
|
3678 |
! |
|
3679 |
||
3680 |
displayString |
|
3681 |
"return a string used when displaying the receiver in a view; |
|
3682 |
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
|
3683 |
but sometimes redefined for a better look. |
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3684 |
|
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3685 |
Note: the base method (used by the inspector) is #displayOn:. |
14975 | 3686 |
So you should implement #displayOn: instead of #displayString in subclasses." |
5755 | 3687 |
|
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3688 |
|s| |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3689 |
|
8322
95ca965f65ed
Handle unicode in #displayString
Stefan Vogel <sv@exept.de>
parents:
8300
diff
changeset
|
3690 |
s := CharacterWriteStream on:(String new:32). |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3691 |
self displayOn:s. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3692 |
^ s contents |
5755 | 3693 |
|
3694 |
" |
|
10460 | 3695 |
#(1 2 3) printString |
3696 |
#(1 2 3) displayString |
|
5755 | 3697 |
#(1 2 3) storeString |
3698 |
" |
|
3699 |
! |
|
3700 |
||
3701 |
heightOn:aGC |
|
3702 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
3703 |
||
3704 |
^ (aGC font onDevice:aGC device) heightOf:(self displayString) |
|
3705 |
! |
|
3706 |
||
6654 | 3707 |
widthFrom:startIndex to:endIndex on:aGC |
3708 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3709 |
||
3710 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) from:startIndex to:endIndex |
|
3711 |
! |
|
3712 |
||
5755 | 3713 |
widthOn:aGC |
3714 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3715 |
||
3716 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) |
|
3717 |
! ! |
|
3718 |
||
7359 | 3719 |
!Object methodsFor:'double dispatching'! |
3720 |
||
3721 |
equalFromComplex:aComplex |
|
3722 |
"adding this method here allows for any non-number to be compared to a complex |
|
3723 |
and return false from this comparison. |
|
3724 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3725 |
which uses #= (i.e. a Set or Dictionary)." |
|
3726 |
||
3727 |
^ false |
|
3728 |
! |
|
3729 |
||
3730 |
equalFromFixedPoint:aFixedPoint |
|
3731 |
"adding this method here allows for any non-number to be compared to a fixedPoint |
|
3732 |
and return false from this comparison. |
|
3733 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3734 |
which uses #= (i.e. a Set or Dictionary)." |
|
3735 |
||
3736 |
^ false |
|
3737 |
! |
|
3738 |
||
3739 |
equalFromFloat:aFloat |
|
3740 |
"adding this method here allows for any non-number to be compared to a float |
|
3741 |
and return false from this comparison. |
|
3742 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3743 |
which uses #= (i.e. a Set or Dictionary)." |
|
3744 |
||
3745 |
^ false |
|
3746 |
! |
|
3747 |
||
3748 |
equalFromFraction:aFraction |
|
3749 |
"adding this method here allows for any non-number to be compared to a fraction |
|
3750 |
and return false from this comparison. |
|
3751 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3752 |
which uses #= (i.e. a Set or Dictionary)." |
|
3753 |
||
3754 |
^ false |
|
3755 |
! |
|
3756 |
||
3757 |
equalFromInteger:anInteger |
|
3758 |
"adding this method here allows for any non-number to be compared to an integer |
|
3759 |
and return false from this comparison. |
|
3760 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3761 |
which uses #= (i.e. a Set or Dictionary)." |
|
3762 |
||
3763 |
^ false |
|
3764 |
! |
|
3765 |
||
7455 | 3766 |
equalFromLargeFloat:aLargeFloat |
3767 |
"adding this method here allows for any non-number to be compared to a largeFloat |
|
3768 |
and return false from this comparison. |
|
3769 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3770 |
which uses #= (i.e. a Set or Dictionary)." |
|
3771 |
||
3772 |
^ false |
|
3773 |
! |
|
3774 |
||
7359 | 3775 |
equalFromLongFloat:aLongFloat |
3776 |
"adding this method here allows for any non-number to be compared to a longFloat |
|
3777 |
and return false from this comparison. |
|
3778 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3779 |
which uses #= (i.e. a Set or Dictionary)." |
|
3780 |
||
3781 |
^ false |
|
3782 |
! |
|
3783 |
||
3784 |
equalFromShortFloat:aShortFloat |
|
3785 |
"adding this method here allows for any non-number to be compared to a shortFloat |
|
3786 |
and return false from this comparison. |
|
3787 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3788 |
which uses #= (i.e. a Set or Dictionary)." |
|
3789 |
||
3790 |
^ false |
|
3791 |
! ! |
|
3792 |
||
5755 | 3793 |
!Object methodsFor:'encoding & decoding'! |
3794 |
||
3795 |
decodeAsLiteralArray |
|
8832 | 3796 |
"given a literalEncoding in the receiver, |
3797 |
create & return the corresponding object. |
|
3798 |
The inverse operation to #literalArrayEncoding." |
|
3799 |
||
5755 | 3800 |
^ self |
3801 |
! |
|
3802 |
||
3803 |
encodeOn:anEncoder with:aParameter |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3804 |
"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
|
3805 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3806 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3807 |
|
8404 | 3808 |
self acceptVisitor:anEncoder with:aParameter |
6718 | 3809 |
! |
3810 |
||
3811 |
encodingVectorForInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3812 |
"OBSOLETE, use elementDescriptorForInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3813 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3814 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3815 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3816 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
6718 | 3817 |
|
3818 |
" |
|
3819 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
3820 |
Dictionary new encodingVectorForInstanceVariables |
|
3821 |
(5 @ nil) encodingVectorForInstanceVariables |
|
3822 |
" |
|
3823 |
! |
|
3824 |
||
3825 |
encodingVectorForNonNilInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3826 |
"OBSOLETE, use elementDescriptorForNonNilInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3827 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3828 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3829 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3830 |
^ self elementDescriptorForInstanceVariablesMatching:[:varVal | varVal notNil]. |
6718 | 3831 |
|
3832 |
" |
|
3833 |
#(1 2 3 nil true symbol) encodingVectorForNonNilInstanceVariables |
|
3834 |
(5 @ nil) encodingVectorForNonNilInstanceVariables |
|
3835 |
" |
|
3836 |
! |
|
3837 |
||
5755 | 3838 |
fromLiteralArrayEncoding:aSpecArray |
8798 | 3839 |
"read my attributes from aSpecArray. |
3840 |
Recursively decodes arguments." |
|
3841 |
||
3842 |
|sel litVal val |
|
5755 | 3843 |
stop "{ Class:SmallInteger }" | |
3844 |
||
3845 |
stop := aSpecArray size. |
|
3846 |
||
3847 |
2 to:stop by:2 do:[:i| |
|
14975 | 3848 |
sel := aSpecArray at:i. |
3849 |
litVal := aSpecArray at:i + 1. |
|
3850 |
||
3851 |
(self respondsTo:sel) ifTrue:[ |
|
3852 |
val := litVal decodeAsLiteralArray. |
|
3853 |
self perform:sel with:val |
|
3854 |
] ifFalse:[ |
|
3855 |
Transcript show:self class name; show:': unhandled literalArrayEncoding attribute: '. |
|
3856 |
Transcript showCR:sel. |
|
3857 |
||
3858 |
"/ thats a debug halt, |
|
3859 |
"/ it should probably be removed (to simply ignore unhandled attributes)... |
|
3860 |
"/ for now, it is left in, in order to easily find incompatibilities between |
|
3861 |
"/ VW and ST/X. |
|
3862 |
self breakPoint:#cg. |
|
3863 |
] |
|
5755 | 3864 |
] |
3865 |
! |
|
3866 |
||
3867 |
literalArrayEncoding |
|
3868 |
"generate a literalArrayEncoding array for myself. |
|
3869 |
This uses #literalArrayEncodingSlotOrder which defines the slots and |
|
3870 |
order and #skippedInLiteralEncoding which defines slots to skip. |
|
3871 |
For most subclasses, there is no need to redefine those." |
|
3872 |
||
8832 | 3873 |
|names encoding cls skipped slots| |
5755 | 3874 |
|
3875 |
self isLiteral ifTrue:[ |
|
14975 | 3876 |
^ self |
5755 | 3877 |
]. |
3878 |
||
8832 | 3879 |
slots := self literalArrayEncodingSlotOrder. |
5755 | 3880 |
skipped := self skippedInLiteralEncoding. |
3881 |
cls := self class. |
|
3882 |
names := cls allInstVarNames. |
|
8832 | 3883 |
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
|
3884 |
encoding add:cls name. |
8832 | 3885 |
|
3886 |
slots do:[:instSlot | |
|
14975 | 3887 |
|value nm| |
3888 |
||
3889 |
nm := names at:instSlot. |
|
3890 |
(skipped includes:nm) ifFalse:[ |
|
3891 |
(value := self instVarAt:instSlot) notNil ifTrue:[ |
|
3892 |
encoding add:(nm , ':') asSymbol. |
|
3893 |
encoding add:value literalArrayEncoding |
|
3894 |
] |
|
3895 |
] |
|
5755 | 3896 |
]. |
3897 |
^ encoding asArray |
|
8841 | 3898 |
|
3899 |
" |
|
14975 | 3900 |
(1 -> 2) literalArrayEncoding |
3901 |
DebugView menuSpec decodeAsLiteralArray literalArrayEncoding = |
|
3902 |
DebugView menuSpec |
|
8841 | 3903 |
" |
5755 | 3904 |
! |
3905 |
||
3906 |
literalArrayEncodingSlotOrder |
|
3907 |
"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
|
3908 |
a literalArrayEncoding" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3909 |
|
5755 | 3910 |
^ 1 to:self class instSize |
3911 |
! |
|
3912 |
||
7112 | 3913 |
postDecodeFrom:aDecoder aspect:aspectSymbol |
3914 |
"invoked by xmlDecoder (and others in the future), after an |
|
3915 |
object has been decoded (i.e. its instance variables have been restored)" |
|
3916 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3917 |
^ self |
7112 | 3918 |
! |
3919 |
||
5755 | 3920 |
skippedInLiteralEncoding |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3921 |
"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
|
3922 |
|
5755 | 3923 |
^ #() |
3924 |
! ! |
|
3925 |
||
3926 |
!Object methodsFor:'error handling'! |
|
3927 |
||
13416 | 3928 |
ambiguousMessage:aMessage |
3929 |
"this message is sent by the system in case that it |
|
3930 |
is not clear which method to execute in response to |
|
14632 | 3931 |
aMessage. |
13416 | 3932 |
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
|
3933 |
imports two namespaces and both define a method with the |
13416 | 3934 |
requested selector." |
3935 |
||
3936 |
<context: #return> |
|
3937 |
<resource: #skipInDebuggersWalkBack> |
|
3938 |
||
3939 |
^ AmbiguousMessage raiseRequestWith:aMessage |
|
3940 |
||
3941 |
"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
|
3942 |
"Modified (comment): / 02-11-2012 / 10:14:42 / cg" |
13416 | 3943 |
! |
3944 |
||
5755 | 3945 |
appropriateDebugger:aSelector |
3946 |
"{ Pragma: +optSpace }" |
|
3947 |
||
3948 |
"return an appropriate debugger to use. |
|
3949 |
If there is already a debugger active on the stack, and it is |
|
3950 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
3951 |
||
3952 |
|context| |
|
3953 |
||
3954 |
"DebugView cannot run without system processes" |
|
3955 |
||
10460 | 3956 |
(Processor isNil |
5755 | 3957 |
or:[Processor activeProcessIsSystemProcess |
3958 |
or:[Smalltalk isInitialized not]]) ifTrue:[ |
|
14975 | 3959 |
^ MiniDebugger |
5755 | 3960 |
]. |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
3961 |
(Screen isNil or:[Screen default isNil or:[Screen default isOpen not]]) ifTrue:[ |
14975 | 3962 |
Debugger isNil ifTrue:[^ nil]. |
3963 |
^ MiniDebugger |
|
5755 | 3964 |
]. |
3965 |
||
3966 |
context := thisContext. |
|
3967 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
3968 |
[context notNil] whileTrue:[ |
|
14975 | 3969 |
((context receiver class == Debugger) |
3970 |
and:[context selector == aSelector]) ifTrue:[ |
|
3971 |
"we are already in some Debugger" |
|
3972 |
(Debugger == MiniDebugger) ifTrue:[ |
|
3973 |
"we are already in the MiniDebugger" |
|
3974 |
ErrorRecursion ifFalse:[ |
|
3975 |
Smalltalk fatalAbort:'recursive error ...' |
|
3976 |
] |
|
3977 |
]. |
|
3978 |
MiniDebugger isNil ifTrue:[ |
|
3979 |
Smalltalk fatalAbort:'no debugger' |
|
3980 |
]. |
|
3981 |
||
3982 |
"ok, an error occured while in the graphical debugger; |
|
3983 |
lets try MiniDebugger" |
|
3984 |
^ MiniDebugger |
|
3985 |
]. |
|
3986 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
5755 | 3987 |
]. |
3988 |
"not within Debugger - no problem" |
|
3989 |
^ Debugger |
|
3990 |
||
3991 |
"Modified: / 23.9.1996 / 12:14:52 / stefan" |
|
3992 |
"Modified: / 19.5.1999 / 18:05:00 / cg" |
|
3993 |
! |
|
3994 |
||
3995 |
cannotSendMessage:aMessage to:someReceiver |
|
3996 |
"this message is sent by the runtime system (VM), |
|
3997 |
when a message is sent to some object, whose class is not |
|
3998 |
a valid behavior (see documentation in Behavior)." |
|
3999 |
||
11021 | 4000 |
<resource: #skipInDebuggersWalkBack> |
4001 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4002 |
^ VMInternalError |
14975 | 4003 |
raiseWith:someReceiver |
4004 |
errorString:('bad class in send of #' , aMessage selector) |
|
5755 | 4005 |
|
4006 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
4007 |
! |
|
4008 |
||
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4009 |
conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4010 |
"return the signal used for conversion error handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4011 |
|
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4012 |
^ self class conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4013 |
! |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4014 |
|
5755 | 4015 |
doesNotUnderstand:aMessage |
4016 |
"this message is sent by the runtime system (VM) when |
|
4017 |
a message is not understood by some object (i.e. there |
|
4018 |
is no method for that selector). The original message has |
|
4019 |
been packed into aMessage (i.e. the receiver, selector and |
|
4020 |
any arguments) and the original receiver is then sent the |
|
4021 |
#doesNotUnderstand: message. |
|
4022 |
Here, we raise another signal which usually enters the debugger. |
|
4023 |
You can of course redefine #doesNotUnderstand: in your classes |
|
10460 | 4024 |
to implement message delegation, |
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
4025 |
or handle the MessageNotUnderstood exception gracefully." |
5755 | 4026 |
|
4027 |
<context: #return> |
|
11021 | 4028 |
<resource: #skipInDebuggersWalkBack> |
5755 | 4029 |
|
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
4030 |
^ MessageNotUnderstood raiseRequestWith:aMessage |
5755 | 4031 |
! |
4032 |
||
4033 |
elementBoundsError |
|
4034 |
"{ Pragma: +optSpace }" |
|
4035 |
||
10460 | 4036 |
"report an error that badElement is out of bounds |
5755 | 4037 |
(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
|
4038 |
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
|
4039 |
|
11021 | 4040 |
<resource: #skipInDebuggersWalkBack> |
4041 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4042 |
^ ElementBoundsError raise |
5755 | 4043 |
|
4044 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
4045 |
! |
|
4046 |
||
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4047 |
elementBoundsError:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4048 |
"{ Pragma: +optSpace }" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4049 |
|
10460 | 4050 |
"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
|
4051 |
(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
|
4052 |
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
|
4053 |
|
11021 | 4054 |
<resource: #skipInDebuggersWalkBack> |
4055 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4056 |
^ ElementBoundsError raiseWith:aValue |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4057 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4058 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4059 |
! |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4060 |
|
5755 | 4061 |
elementNotCharacter |
4062 |
"{ Pragma: +optSpace }" |
|
4063 |
||
4064 |
"report an error that object to be stored is no Character. |
|
4065 |
(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
|
4066 |
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
|
4067 |
|
11021 | 4068 |
<resource: #skipInDebuggersWalkBack> |
4069 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4070 |
^ ElementBoundsError raise |
5755 | 4071 |
|
4072 |
"Modified: 8.5.1996 / 09:12:49 / cg" |
|
4073 |
! |
|
4074 |
||
4075 |
elementNotInteger |
|
4076 |
"{ Pragma: +optSpace }" |
|
4077 |
||
4078 |
"report an error that object to be stored is not Integer. |
|
4079 |
(in collections that store integers only). |
|
4080 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
4081 |
||
11021 | 4082 |
<resource: #skipInDebuggersWalkBack> |
4083 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4084 |
^ ElementBoundsError raise |
5755 | 4085 |
|
4086 |
"Modified: 8.5.1996 / 09:12:51 / cg" |
|
4087 |
! |
|
4088 |
||
4089 |
error |
|
4090 |
"{ Pragma: +optSpace }" |
|
4091 |
||
4092 |
"report error that an error occured. |
|
4093 |
The error is reported by raising the Error exception, |
|
4094 |
which is non-proceedable. |
|
4095 |
If no handler has been setup, a debugger is entered." |
|
4096 |
||
11021 | 4097 |
<context: #return> |
4098 |
<resource: #skipInDebuggersWalkBack> |
|
4099 |
||
5755 | 4100 |
Error raiseWith:#error: |
4101 |
||
4102 |
" |
|
4103 |
nil error |
|
4104 |
" |
|
4105 |
||
4106 |
"Modified: / 8.5.1996 / 09:13:01 / cg" |
|
4107 |
"Modified: / 2.8.1999 / 17:00:19 / stefan" |
|
4108 |
! |
|
4109 |
||
4110 |
error:aString |
|
4111 |
"{ Pragma: +optSpace }" |
|
4112 |
||
4113 |
"Raise an error with error message aString. |
|
4114 |
The error is reported by raising the Error exception, |
|
4115 |
which is non-proceedable. |
|
4116 |
If no handler has been setup, a debugger is entered." |
|
4117 |
||
11021 | 4118 |
<context: #return> |
4119 |
<resource: #skipInDebuggersWalkBack> |
|
4120 |
||
10460 | 4121 |
Error raiseWith:#error: errorString:aString |
5755 | 4122 |
|
4123 |
" |
|
4124 |
nil error:' bad bad bad' |
|
4125 |
" |
|
4126 |
||
4127 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
4128 |
! |
|
4129 |
||
4130 |
error:aString mayProceed:mayProceed |
|
4131 |
"{ Pragma: +optSpace }" |
|
4132 |
||
4133 |
"enter debugger with error-message aString. |
|
10460 | 4134 |
The error is reported by raising either the |
5755 | 4135 |
non-proceedable Error exception, |
4136 |
or the ProceedableError exception." |
|
4137 |
||
11021 | 4138 |
<resource: #skipInDebuggersWalkBack> |
4139 |
||
5755 | 4140 |
mayProceed ifTrue:[ |
14975 | 4141 |
^ ProceedableError raiseRequestWith:#error: errorString:aString |
10460 | 4142 |
]. |
4143 |
||
4144 |
Error raiseWith:#error: errorString:aString |
|
5755 | 4145 |
|
4146 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
4147 |
! |
|
4148 |
||
6900 | 4149 |
errorInvalidFormat |
4150 |
"{ Pragma: +optSpace }" |
|
4151 |
||
4152 |
"report an error that some conversion to/from string representation failed |
|
4153 |
typically when converting numbers, date, time etc." |
|
4154 |
||
11021 | 4155 |
<context: #return> |
4156 |
<resource: #skipInDebuggersWalkBack> |
|
4157 |
||
6900 | 4158 |
^ ConversionError raiseErrorString:'invalid format' |
4159 |
! |
|
4160 |
||
5755 | 4161 |
errorKeyNotFound:aKey |
4162 |
"{ Pragma: +optSpace }" |
|
4163 |
||
4164 |
"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
|
4165 |
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
|
4166 |
|
11021 | 4167 |
<resource: #skipInDebuggersWalkBack> |
4168 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
4169 |
^ 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
|
4170 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4171 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4172 |
Dictionary new at:#nonExistantElement |
5755 | 4173 |
" |
4174 |
! |
|
4175 |
||
4176 |
errorNotFound |
|
4177 |
"{ Pragma: +optSpace }" |
|
4178 |
||
4179 |
"report an error that no element was found in a collection. |
|
4180 |
The error is reported by raising the NotFoundSignal exception." |
|
4181 |
||
11021 | 4182 |
<resource: #skipInDebuggersWalkBack> |
4183 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4184 |
^ NotFoundError raiseRequestWith:nil |
5755 | 4185 |
|
4186 |
"Modified: / 8.5.1996 / 09:13:11 / cg" |
|
4187 |
"Modified: / 26.7.1999 / 10:51:50 / stefan" |
|
4188 |
! |
|
4189 |
||
6874 | 4190 |
errorNotFound:errorString |
4191 |
"{ Pragma: +optSpace }" |
|
4192 |
||
4193 |
"report an error that no element was found in a collection. |
|
4194 |
The error is reported by raising the NotFoundSignal exception." |
|
4195 |
||
11021 | 4196 |
<resource: #skipInDebuggersWalkBack> |
4197 |
||
10837
63d19c75d762
changed #errorNotFound: raise it proceedable
Stefan Vogel <sv@exept.de>
parents:
10834
diff
changeset
|
4198 |
^ NotFoundError raiseRequestErrorString:errorString |
6874 | 4199 |
! |
4200 |
||
5755 | 4201 |
errorSignal |
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4202 |
"return the signal used for error/error: handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4203 |
|
5755 | 4204 |
^ self class errorSignal |
4205 |
||
4206 |
"Created: / 19.6.1998 / 02:32:32 / cg" |
|
4207 |
! |
|
4208 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4209 |
handlerForSignal:exceptionHandler context:theContext originator:originator |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4210 |
" 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
|
4211 |
|
7566 | 4212 |
thisContext isRecursive ifTrue:[^ nil]. |
4213 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4214 |
'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
|
4215 |
' context: ' print. theContext printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4216 |
' originator: ' print. originator printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4217 |
' sender: ' print. thisContext sender printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4218 |
|
7566 | 4219 |
"/ MiniDebugger enter:thisContext withMessage:'oops' mayProceed:true. |
4220 |
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
|
4221 |
! |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4222 |
|
5755 | 4223 |
implementedBySubclass |
4224 |
"{ Pragma: +optSpace }" |
|
4225 |
||
4226 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
4227 |
||
11021 | 4228 |
<resource: #skipInDebuggersWalkBack> |
4229 |
||
12322 | 4230 |
^ SubclassResponsibilityError raiseRequestErrorString:'method must be reimplemented in ST/V subclass' |
5755 | 4231 |
! |
4232 |
||
4233 |
indexNotInteger |
|
4234 |
"{ Pragma: +optSpace }" |
|
4235 |
||
4236 |
"report an error that index is not an Integer. |
|
4237 |
(when accessing collections indexed by an integer key). |
|
4238 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4239 |
||
11021 | 4240 |
<resource: #skipInDebuggersWalkBack> |
4241 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4242 |
^ NonIntegerIndexError raiseRequestWith:nil |
5755 | 4243 |
|
4244 |
"Modified: / 8.5.1996 / 09:13:37 / cg" |
|
4245 |
"Modified: / 26.7.1999 / 10:57:43 / stefan" |
|
4246 |
! |
|
4247 |
||
4248 |
indexNotInteger:anIndex |
|
4249 |
"{ Pragma: +optSpace }" |
|
4250 |
||
4251 |
"report an error that index is not an Integer. |
|
4252 |
(when accessing collections indexed by an integer key). |
|
4253 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4254 |
||
11021 | 4255 |
<resource: #skipInDebuggersWalkBack> |
4256 |
||
10460 | 4257 |
^ NonIntegerIndexError raiseRequestWith:anIndex |
5755 | 4258 |
|
4259 |
"Created: / 16.5.1998 / 19:39:41 / cg" |
|
4260 |
! |
|
4261 |
||
7216 | 4262 |
indexNotIntegerOrOutOfBounds:index |
4263 |
"{ Pragma: +optSpace }" |
|
4264 |
||
4265 |
"report an error that index is either non-integral or out of bounds" |
|
4266 |
||
11021 | 4267 |
<resource: #skipInDebuggersWalkBack> |
4268 |
||
7216 | 4269 |
index isInteger ifFalse:[ |
14975 | 4270 |
^ self indexNotInteger:index |
7216 | 4271 |
]. |
4272 |
^ self subscriptBoundsError:index |
|
4273 |
! |
|
4274 |
||
5755 | 4275 |
integerCheckError |
4276 |
"{ Pragma: +optSpace }" |
|
4277 |
||
12321 | 4278 |
"generated when a variable declared with an integer type gets a bad value assigned" |
5755 | 4279 |
|
11021 | 4280 |
<resource: #skipInDebuggersWalkBack> |
4281 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4282 |
"/ ^ self error:'bad assign of ' , self printString , |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4283 |
"/ ' (' , self class name , ') to integer-typed variable' |
14632 | 4284 |
^ InvalidTypeError |
14975 | 4285 |
raiseRequestErrorString:( |
4286 |
'bad assign of ' , self printString , |
|
4287 |
' (' , 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
|
4288 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4289 |
"Modified: / 02-11-2012 / 10:25:36 / cg" |
5755 | 4290 |
! |
4291 |
||
4292 |
invalidCodeObject |
|
4293 |
"{ Pragma: +optSpace }" |
|
4294 |
||
12321 | 4295 |
"this is sent by VM if it encounters some non-method for execution" |
4296 |
||
11021 | 4297 |
<resource: #skipInDebuggersWalkBack> |
4298 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4299 |
"/ self error:'not an executable code object' |
14632 | 4300 |
^ ExecutionError |
14975 | 4301 |
raiseRequestErrorString:'not an executable code object' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4302 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4303 |
"Created: / 01-08-1997 / 00:16:44 / cg" |
5755 | 4304 |
! |
4305 |
||
10460 | 4306 |
invalidMessage |
5755 | 4307 |
"{ Pragma: +optSpace }" |
4308 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4309 |
"this is sent by ST/V code - it's the same as #shouldNotImplement" |
5755 | 4310 |
|
11021 | 4311 |
<resource: #skipInDebuggersWalkBack> |
4312 |
||
5755 | 4313 |
^ self shouldNotImplement |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4314 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4315 |
"Modified (comment): / 02-11-2012 / 10:11:18 / cg" |
5755 | 4316 |
! |
4317 |
||
4318 |
mustBeRectangle |
|
4319 |
"{ Pragma: +optSpace }" |
|
4320 |
||
4321 |
"report an argument-not-rectangle-error" |
|
4322 |
||
11021 | 4323 |
<resource: #skipInDebuggersWalkBack> |
4324 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4325 |
"/ ^ self error:'argument must be a Rectangle' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4326 |
^ InvalidTypeError |
14975 | 4327 |
raiseRequestErrorString:'argument must be a Rectangle' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4328 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4329 |
"Modified: / 02-11-2012 / 10:24:53 / cg" |
5755 | 4330 |
! |
4331 |
||
4332 |
mustBeString |
|
4333 |
"{ Pragma: +optSpace }" |
|
4334 |
||
4335 |
"report an argument-not-string-error" |
|
4336 |
||
11021 | 4337 |
<resource: #skipInDebuggersWalkBack> |
4338 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4339 |
"/ ^ self error:'argument must be a String' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4340 |
^ InvalidTypeError |
14975 | 4341 |
raiseRequestErrorString:'argument must be a String' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4342 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4343 |
"Modified: / 02-11-2012 / 10:24:35 / cg" |
5755 | 4344 |
! |
4345 |
||
4346 |
notIndexed |
|
4347 |
"{ Pragma: +optSpace }" |
|
4348 |
||
4349 |
"report an error that receiver has no indexed instance variables. |
|
4350 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4351 |
||
11021 | 4352 |
<context: #return> |
4353 |
<resource: #skipInDebuggersWalkBack> |
|
4354 |
||
10460 | 4355 |
^ SubscriptOutOfBoundsError |
14975 | 4356 |
raiseRequestErrorString:'receiver has no indexed variables' |
5755 | 4357 |
|
14539 | 4358 |
" |
4359 |
1234 at:4 |
|
4360 |
" |
|
4361 |
||
5755 | 4362 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
4363 |
! |
|
4364 |
||
12050 | 4365 |
notYetImplemented |
4366 |
"{ Pragma: +optSpace }" |
|
4367 |
||
12321 | 4368 |
"report an error that some functionality is not yet implemented. |
4369 |
This is here only for compatibility - it has the same meaning as shouldImplement." |
|
12050 | 4370 |
|
4371 |
<resource: #skipInDebuggersWalkBack> |
|
4372 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4373 |
"/ ^ self error:'method/functionality is not yet implemented' |
14632 | 4374 |
^ MethodNotAppropriateError |
14975 | 4375 |
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
|
4376 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4377 |
"Modified: / 02-11-2012 / 10:24:12 / cg" |
12050 | 4378 |
! |
4379 |
||
5755 | 4380 |
openDebuggerOnException:ex |
4381 |
"{ Pragma: +optSpace }" |
|
4382 |
||
4383 |
"enter the debugger on some unhandled exception" |
|
4384 |
||
6884 | 4385 |
|msgString debugger answer| |
5755 | 4386 |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4387 |
msgString := ex descriptionForDebugger. |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
4388 |
|
5755 | 4389 |
" |
4390 |
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
|
4391 |
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
|
4392 |
ignore will raise an AbortOperationRequest. |
5755 | 4393 |
" |
4394 |
Debugger isNil ifTrue:[ |
|
14965 | 4395 |
msgString := 'Error: ' , msgString. |
4396 |
||
4397 |
thisContext isRecursive ifTrue:[ |
|
4398 |
msgString errorPrintCR. |
|
4399 |
Smalltalk fatalAbort:'recursive unhandled exception' |
|
4400 |
]. |
|
4401 |
||
4402 |
Smalltalk isStandAloneApp ifTrue:[ |
|
15116 | 4403 |
(ex creator == NoHandlerError and:[HaltInterrupt handles:ex exception]) ifTrue:[ |
14965 | 4404 |
"/ 'Halt ignored' infoPrintCR. |
4405 |
^ nil |
|
4406 |
]. |
|
4407 |
"don't output the message, if the exception is a UserInterrupt (CTRL-C)" |
|
15116 | 4408 |
(ex creator == NoHandlerError |
4409 |
and:[ex exception creator == UserInterrupt]) ifTrue:[ |
|
14965 | 4410 |
ex description errorPrintCR. |
4411 |
OperatingSystem exit:130. |
|
4412 |
]. |
|
4413 |
]. |
|
4414 |
||
4415 |
(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
|
4416 |
false "oldCode" ifTrue:[ |
14965 | 4417 |
AbortOperationRequest isHandled ifTrue:[ |
4418 |
answer := OptionBox |
|
4419 |
request:msgString |
|
4420 |
label:msgString |
|
4421 |
buttonLabels:#('Exit' 'Terminate Thread' 'Ignore' 'Abort' ) |
|
4422 |
values:#(exit terminate ignore abort) |
|
4423 |
default:#abort. |
|
4424 |
] ifFalse:[ |
|
4425 |
answer := OptionBox |
|
4426 |
request:msgString |
|
4427 |
label:msgString |
|
4428 |
buttonLabels:#('Exit' 'Terminate Thread' 'Ignore' ) |
|
4429 |
values:#(exit terminate ignore ) |
|
4430 |
default:#terminate. |
|
4431 |
]. |
|
4432 |
answer isNil ifTrue:[ answer := #ignore]. |
|
4433 |
||
4434 |
answer == #abort ifTrue:[ |
|
4435 |
^ AbortOperationRequest raiseRequest |
|
4436 |
]. |
|
4437 |
answer == #ignore ifTrue:[ |
|
4438 |
^ nil |
|
4439 |
]. |
|
4440 |
answer == #terminate ifTrue:[ |
|
4441 |
Processor activeProcess isSystemProcess ifTrue:[ |
|
4442 |
(Dialog confirm:'Are you sure (this might finish the application)') ifFalse:[ |
|
4443 |
^ nil |
|
4444 |
]. |
|
4445 |
]. |
|
4446 |
^ Processor activeProcess terminate. |
|
4447 |
]. |
|
4448 |
"asking second time here to prevent the user from accidently closing his app" |
|
4449 |
answer == #exit ifTrue:[ |
|
4450 |
answer := OptionBox |
|
4451 |
request:'Do you really wish to exit this application (all changes will be lost)?' |
|
4452 |
label:msgString |
|
4453 |
buttonLabels:#('Yes' 'No' ) |
|
4454 |
values:#(exit abort) |
|
4455 |
default:#abort. |
|
4456 |
]. |
|
4457 |
answer == #abort ifTrue:[ |
|
4458 |
^ AbortOperationRequest raiseRequest |
|
4459 |
]. |
|
4460 |
||
4461 |
(Dialog confirm:'Are you sure you want to finish the application ?') ifFalse:[ |
|
4462 |
^ nil |
|
4463 |
]. |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4464 |
] ifFalse:[ |
14965 | 4465 |
self |
4466 |
errorNotify:msgString |
|
4467 |
from:ex suspendedContext |
|
15255 | 4468 |
allowDebug:false |
4469 |
mayProceed:ex willProceed. |
|
14965 | 4470 |
|
4471 |
"/ arrive here if proceeded... |
|
4472 |
^ nil |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4473 |
]. |
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4474 |
|
14965 | 4475 |
]. |
4476 |
||
4477 |
"don't output the message, if the exception is a UserInterrupt (CTRL-C)" |
|
15116 | 4478 |
(ex creator == NoHandlerError |
4479 |
and:[ex exception creator == UserInterrupt]) ifTrue:[ |
|
14965 | 4480 |
OperatingSystem exit:130. |
4481 |
]. |
|
4482 |
msgString errorPrintCR. |
|
4483 |
thisContext fullPrintAll. |
|
4484 |
OperatingSystem exit:1 |
|
5755 | 4485 |
]. |
4486 |
||
4487 |
" |
|
4488 |
find an appropriate debugger to use |
|
4489 |
" |
|
4490 |
debugger := self appropriateDebugger:(thisContext selector). |
|
4491 |
debugger isNil ifTrue:[ |
|
14965 | 4492 |
^ AbortOperationRequest raiseRequest |
4493 |
]. |
|
4494 |
||
4495 |
^ debugger enterException:ex. |
|
4496 |
"/ ^ debugger |
|
4497 |
"/ enter:ex returnableSuspendedContext |
|
4498 |
"/ withMessage:ex descriptionForDebugger |
|
4499 |
"/ mayProceed:(ex mayProceed). |
|
5755 | 4500 |
|
13849
01e27cdbf2bb
changed: #openDebuggerOnException:
Claus Gittinger <cg@exept.de>
parents:
13848
diff
changeset
|
4501 |
"Modified: / 05-12-2011 / 11:53:10 / cg" |
5755 | 4502 |
! |
4503 |
||
4504 |
primitiveFailed |
|
4505 |
"{ Pragma: +optSpace }" |
|
4506 |
||
4507 |
"report an error that some primitive code failed. |
|
14539 | 4508 |
The error is reported by raising the PrimitiveFailure exception. |
4509 |
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
|
4510 |
|
11021 | 4511 |
<resource: #skipInDebuggersWalkBack> |
4512 |
||
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4513 |
|sender| |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4514 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4515 |
sender := thisContext sender. |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4516 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4517 |
^ PrimitiveFailure raiseRequestWith:(Message selector:sender selector arguments:sender args) |
14975 | 4518 |
in:sender. |
5755 | 4519 |
|
6005 | 4520 |
" |
4521 |
1234 primitiveFailed |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4522 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4523 |
[ |
14975 | 4524 |
ExternalBytes new basicAt:40 |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4525 |
] on:PrimitiveFailure do:[:ex| |
14975 | 4526 |
ex inspect |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4527 |
] |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4528 |
" |
5755 | 4529 |
! |
4530 |
||
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4531 |
primitiveFailed:messageString |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4532 |
"{ Pragma: +optSpace }" |
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 |
"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
|
4535 |
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
|
4536 |
|
11021 | 4537 |
<resource: #skipInDebuggersWalkBack> |
4538 |
||
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4539 |
|sender| |
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 |
sender := thisContext sender. |
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 |
^ PrimitiveFailure raiseRequestWith:(Message selector:sender selector arguments:sender args) |
14975 | 4544 |
errorString:messageString |
4545 |
in:sender. |
|
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4546 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4547 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4548 |
1234 primitiveFailed:'this is a test' |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4549 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4550 |
! |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4551 |
|
6815 | 4552 |
shouldImplement |
4553 |
"{ Pragma: +optSpace }" |
|
4554 |
||
12321 | 4555 |
"report an error that this message/functionality should be implemented. |
4556 |
This is send by automatically generated method bodies or inside as-yet-uncoded |
|
4557 |
branches of existing methods." |
|
6815 | 4558 |
|
11021 | 4559 |
<resource: #skipInDebuggersWalkBack> |
4560 |
||
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4561 |
|sender| |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4562 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4563 |
sender := thisContext sender. |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4564 |
|
12841 | 4565 |
^ UnimplementedFunctionalityError |
14975 | 4566 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4567 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4568 |
" |
12321 | 4569 |
self shouldImplement |
4570 |
" |
|
4571 |
! |
|
4572 |
||
4573 |
shouldImplement:what |
|
4574 |
"{ Pragma: +optSpace }" |
|
4575 |
||
4576 |
"report an error that this message/functionality should be implemented. |
|
4577 |
This is send by automatically generated method bodies or inside as-yet-uncoded |
|
4578 |
branches of existing methods." |
|
4579 |
||
4580 |
<resource: #skipInDebuggersWalkBack> |
|
4581 |
||
4582 |
|sender| |
|
4583 |
||
4584 |
sender := thisContext sender. |
|
4585 |
||
12841 | 4586 |
^ UnimplementedFunctionalityError |
14975 | 4587 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
4588 |
errorString:what |
|
12321 | 4589 |
|
4590 |
" |
|
4591 |
self shouldImplement:'foobar' |
|
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4592 |
" |
6815 | 4593 |
! |
4594 |
||
11976 | 4595 |
shouldNeverBeReached |
12321 | 4596 |
"report an error that this point may never be reached." |
12841 | 4597 |
|
14499 | 4598 |
<resource: #skipInDebuggersWalkBack> |
4599 |
||
4600 |
^ ExecutionError |
|
14975 | 4601 |
raiseRequestErrorString:'Oops, this may never reached. Something somewhere was terribly wrong.'. |
11976 | 4602 |
|
4603 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
4604 |
! |
|
4605 |
||
4606 |
shouldNeverBeSent |
|
12321 | 4607 |
"report an error that this message may never be sent to the reciever" |
12841 | 4608 |
|
14499 | 4609 |
<resource: #skipInDebuggersWalkBack> |
4610 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4611 |
"/ ^ self error:'This message never may be sent to me!!'. |
14632 | 4612 |
^ MethodNotAppropriateError |
14975 | 4613 |
raiseRequestErrorString:'This message never may be sent to me!!' |
11976 | 4614 |
|
4615 |
"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
|
4616 |
"Modified: / 02-11-2012 / 10:10:42 / cg" |
11976 | 4617 |
! |
4618 |
||
5755 | 4619 |
shouldNotImplement |
4620 |
"{ Pragma: +optSpace }" |
|
4621 |
||
12841 | 4622 |
"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
|
4623 |
i.e. that a method is invoked which is not appropriate for the receiver." |
5755 | 4624 |
|
11021 | 4625 |
<resource: #skipInDebuggersWalkBack> |
4626 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4627 |
"/ self error:'method/functionality not appropriate for this class' |
14632 | 4628 |
^ MethodNotAppropriateError |
14975 | 4629 |
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
|
4630 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4631 |
"Modified: / 02-11-2012 / 10:02:25 / cg" |
5755 | 4632 |
! |
4633 |
||
4634 |
subclassResponsibility |
|
4635 |
"{ Pragma: +optSpace }" |
|
4636 |
||
12321 | 4637 |
"report an error that this message should have been reimplemented in a subclass" |
5755 | 4638 |
|
11021 | 4639 |
<resource: #skipInDebuggersWalkBack> |
4640 |
||
10877
0666d48f91d1
show the affected method-selector in the subclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
10856
diff
changeset
|
4641 |
^ SubclassResponsibilityError raiseRequestWith:thisContext sender selector |
5755 | 4642 |
! |
4643 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4644 |
subclassResponsibility:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4645 |
"{ Pragma: +optSpace }" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4646 |
|
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4647 |
"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
|
4648 |
|
11021 | 4649 |
<resource: #skipInDebuggersWalkBack> |
4650 |
||
7334 | 4651 |
^ SubclassResponsibilityError raiseRequestErrorString:msg |
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4652 |
! |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4653 |
|
5755 | 4654 |
subscriptBoundsError |
4655 |
"{ Pragma: +optSpace }" |
|
4656 |
||
4657 |
"report an error that some index is out of bounds. |
|
4658 |
(when accessing indexable collections). |
|
4659 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4660 |
||
11021 | 4661 |
<resource: #skipInDebuggersWalkBack> |
4662 |
||
5755 | 4663 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:nil |
4664 |
||
4665 |
"Modified: / 26.7.1996 / 16:45:42 / cg" |
|
4666 |
"Modified: / 26.7.1999 / 10:58:27 / stefan" |
|
4667 |
! |
|
4668 |
||
4669 |
subscriptBoundsError:anIndex |
|
4670 |
"{ Pragma: +optSpace }" |
|
4671 |
||
4672 |
"report an error that anIndex is out of bounds. |
|
4673 |
(when accessing indexable collections). |
|
4674 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4675 |
||
11021 | 4676 |
<resource: #skipInDebuggersWalkBack> |
4677 |
||
10460 | 4678 |
^ SubscriptOutOfBoundsError |
14975 | 4679 |
raiseRequestWith:anIndex |
4680 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
5755 | 4681 |
|
6221 | 4682 |
"Modified: / 17.11.2001 / 22:49:56 / cg" |
5755 | 4683 |
! |
4684 |
||
4685 |
typeCheckError |
|
4686 |
"{ Pragma: +optSpace }" |
|
4687 |
||
4688 |
"generated when a variable declared with a type hint gets a bad |
|
4689 |
value assigned" |
|
4690 |
||
11021 | 4691 |
<resource: #skipInDebuggersWalkBack> |
4692 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4693 |
"/ ^ self error:'bad assign of ' , self printString , |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4694 |
"/ ' (' , self class name , ') to typed variable' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4695 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4696 |
^ InvalidTypeError |
14975 | 4697 |
raiseRequestErrorString: |
4698 |
('bad assign of ' , self printString , |
|
4699 |
' (' , self class name , ') to typed variable') |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4700 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4701 |
"Modified: / 02-11-2012 / 10:19:15 / cg" |
5755 | 4702 |
! ! |
4703 |
||
4704 |
!Object methodsFor:'evaluation'! |
|
4705 |
||
8690
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4706 |
argumentCount |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4707 |
"compatibility with Blocks and Messages. |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4708 |
Answer 0, since we only understand #value. |
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 |
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
|
4711 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4712 |
^ 0 |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4713 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4714 |
" |
14975 | 4715 |
[1 // 0] on:ArithmeticError do:9999 |
8690
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4716 |
" |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4717 |
! |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4718 |
|
5755 | 4719 |
value |
4720 |
"return the receiver itself. |
|
4721 |
This allows every object to be used where blocks or valueHolders |
|
4722 |
are typically used, and allows for valueHolders and blocks to be |
|
4723 |
used interchangably in some situations. |
|
4724 |
||
4725 |
Time will show, if this is a good idea or leads to sloppy programming |
|
4726 |
style ... (the idea was borrowed from the Self language). |
|
4727 |
||
10460 | 4728 |
WARNING: dont 'optimize' away ifXXX: blocks |
14975 | 4729 |
(i.e. do NOT replace |
4730 |
foo ifTrue:[var1] ifFalse:[var2] |
|
4731 |
by: |
|
4732 |
foo ifTrue:var1 ifFalse:var2 |
|
4733 |
) |
|
4734 |
- the compilers will only generate inline code for the if, |
|
4735 |
iff the argument(s) are blocks - otherwise, a true send is |
|
4736 |
generated. |
|
4737 |
This 'oprimization' will work semantically correct, |
|
4738 |
but execute SLOWER instead." |
|
5755 | 4739 |
|
4740 |
^ self |
|
4741 |
||
4742 |
" |
|
10460 | 4743 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
4744 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
4745 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
4746 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
5755 | 4747 |
" |
4748 |
||
4749 |
"DO NOT DO THIS (its slower) |
|
7458 | 4750 |
(1 > 4) ifTrue:a ifFalse:b |
5755 | 4751 |
|
4752 |
USE (the compiler optimizes blocks in if/while): |
|
7458 | 4753 |
(1 > 4) ifTrue:[a] ifFalse:[b] |
5755 | 4754 |
" |
4755 |
||
4756 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
4757 |
! ! |
|
4758 |
||
4759 |
!Object methodsFor:'finalization'! |
|
4760 |
||
4761 |
disposed |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4762 |
"OBSOLETE INTERFACE: use #finalize |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4763 |
this is invoked for objects which have been registered |
5755 | 4764 |
in a Registry, when the original object dies. |
4765 |
Subclasses may redefine this method" |
|
4766 |
||
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4767 |
<resource: #obsolete> |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4768 |
|
5755 | 4769 |
^ self |
4770 |
! |
|
4771 |
||
4772 |
executor |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4773 |
"Return the object which does the finalization for me. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4774 |
This interface is also VW & Sqeak compatible," |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4775 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4776 |
"for now, send #shallowCopyForFinalization, to be compatible with |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4777 |
classes designed for old ST/X versions" |
5755 | 4778 |
|
4779 |
^ self shallowCopyForFinalization |
|
4780 |
! |
|
4781 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4782 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4783 |
"answer a Registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4784 |
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
|
4785 |
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
|
4786 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4787 |
^ FinalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4788 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4789 |
|
5755 | 4790 |
finalize |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4791 |
"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
|
4792 |
in a Registry, when the original object dies. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4793 |
Subclasses may redefine this method |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4794 |
This interface is also VW-compatible" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4795 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4796 |
"send #disposed for compatibility with existing classes that still |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4797 |
implement the obsolete #disposed message" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4798 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4799 |
^ self disposed |
5755 | 4800 |
! |
4801 |
||
4802 |
reRegisterForFinalization |
|
4803 |
"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
|
4804 |
This will create a new executor, which will receive a #finalize message when |
5755 | 4805 |
the receiver is garbage collected." |
4806 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4807 |
self finalizationLobby registerChange:self |
5755 | 4808 |
! |
4809 |
||
4810 |
registerForFinalization |
|
4811 |
"register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4812 |
Once registered, the executor of the receiver will receive a #finalize message when |
5755 | 4813 |
the receiver is garbage collected." |
4814 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4815 |
self finalizationLobby register:self |
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 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4818 |
shallowCopyForFinalization |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4819 |
"OBSOLETE INTERFACE: use #executor. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4820 |
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
|
4821 |
(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
|
4822 |
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
|
4823 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4824 |
<resource: #obsolete> |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4825 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4826 |
^ self shallowCopy |
5755 | 4827 |
! |
4828 |
||
4829 |
unregisterForFinalization |
|
4830 |
"unregister mySelf from later finalization" |
|
4831 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4832 |
self finalizationLobby unregister:self |
5755 | 4833 |
! ! |
4834 |
||
4835 |
!Object methodsFor:'initialization'! |
|
4836 |
||
4837 |
initialize |
|
4838 |
"just to ignore initialize to objects which do not need it" |
|
4839 |
||
4840 |
^ self |
|
4841 |
! ! |
|
4842 |
||
13190
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4843 |
!Object methodsFor:'inspecting'! |
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4844 |
|
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4845 |
inspectorClass |
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4846 |
"{ Pragma: +optSpace }" |
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 |
"return the class to use for inspect. |
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4849 |
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
|
4850 |
|
14055 | 4851 |
^ Inspector ? InspectorView |
4852 |
||
4853 |
"Modified: / 08-03-2012 / 16:09:38 / cg" |
|
13190
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4854 |
! ! |
1e2813b585c9
category of: #inspectorClass
Claus Gittinger <cg@exept.de>
parents:
13187
diff
changeset
|
4855 |
|
5755 | 4856 |
!Object methodsFor:'interrupt handling'! |
4857 |
||
4858 |
childSignalInterrupt |
|
4859 |
"death of a child process (unix process) - do nothing" |
|
4860 |
||
4861 |
^ self |
|
4862 |
! |
|
4863 |
||
4864 |
customInterrupt |
|
4865 |
"{ Pragma: +optSpace }" |
|
4866 |
||
4867 |
"a custom interrupt - but no handler has defined" |
|
4868 |
||
4869 |
self error:'custom interrupt' mayProceed:true |
|
4870 |
! |
|
4871 |
||
4872 |
errorInterrupt:errorID with:aParameter |
|
4873 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
10460 | 4874 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
5755 | 4875 |
which can be called from C subsystems to raise an (asynchronous) |
4876 |
error exception. |
|
4877 |
||
4878 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
4879 |
used from other C subsystems too, to upcast errors. |
|
4880 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
4881 |
IDs (currently) used: |
|
14975 | 4882 |
#DisplayError ..... x-error interrupt |
4883 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
5755 | 4884 |
" |
4885 |
||
6263
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4886 |
|handlers handler| |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4887 |
|
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4888 |
handlers := ObjectMemory registeredErrorInterruptHandlers. |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4889 |
handlers notNil ifTrue:[ |
14975 | 4890 |
handler := handlers at:errorID ifAbsent:nil. |
4891 |
handler notNil ifTrue:[ |
|
4892 |
"/ |
|
4893 |
"/ handler found; let it do whatever it wants ... |
|
4894 |
"/ |
|
4895 |
handler errorInterrupt:errorID with:aParameter. |
|
4896 |
^ self |
|
4897 |
]. |
|
5755 | 4898 |
]. |
4899 |
||
4900 |
"/ |
|
4901 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
4902 |
"/ |
|
10460 | 4903 |
^ Error |
14975 | 4904 |
raiseRequestWith:errorID |
4905 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
5755 | 4906 |
! |
4907 |
||
4908 |
exceptionInterrupt |
|
4909 |
"{ Pragma: +optSpace }" |
|
4910 |
||
4911 |
"exception interrupt - enter debugger" |
|
4912 |
||
4913 |
self error:'exception Interrupt' mayProceed:true |
|
4914 |
! |
|
4915 |
||
4916 |
fpExceptionInterrupt |
|
4917 |
"{ Pragma: +optSpace }" |
|
4918 |
||
4919 |
"a floating point exception occured - this one |
|
4920 |
has to be handled differently since it comes asynchronous |
|
4921 |
on some machines (for example, on machines with a separate FPU |
|
4922 |
or superscalar architectures. Also, errors from within primitive code |
|
4923 |
(or library functions such as GL) are sent via the Unix-signal |
|
4924 |
mechanism this way." |
|
4925 |
||
4926 |
|where rec| |
|
4927 |
||
4928 |
where := thisContext sender. |
|
4929 |
rec := where receiver. |
|
4930 |
rec isNumber ifTrue:[ |
|
14975 | 4931 |
^ rec class |
4932 |
raise:#domainErrorSignal |
|
4933 |
receiver:rec |
|
4934 |
selector:where selector |
|
4935 |
arguments:(where args asArray) |
|
4936 |
errorString:'floating point exception' |
|
5755 | 4937 |
]. |
4938 |
||
4939 |
"/ could be in some C-library ... |
|
7402 | 4940 |
^ DomainError raise |
5755 | 4941 |
! |
4942 |
||
4943 |
internalError:msg |
|
4944 |
"{ Pragma: +optSpace }" |
|
4945 |
||
4946 |
"this is triggered, when VM hits some bad error, |
|
4947 |
such as corrupted class, corrupted method/selector array |
|
4948 |
etc. The argument string gives some more information on what happened. |
|
4949 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
|
4950 |
Its not guaranteed, that the system is in a working condition once |
|
4951 |
this error occurred ...." |
|
4952 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4953 |
VMInternalError raiseWith:self errorString:msg |
5755 | 4954 |
! |
4955 |
||
4956 |
ioInterrupt |
|
4957 |
"{ Pragma: +optSpace }" |
|
4958 |
||
4959 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
|
4960 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
4961 |
or it does not understand the ioInterrupt message. |
|
4962 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
4963 |
||
4964 |
self error:'I/O Interrupt - but no handler' mayProceed:true |
|
4965 |
! |
|
4966 |
||
4967 |
memoryInterrupt |
|
4968 |
"{ Pragma: +optSpace }" |
|
4969 |
||
4970 |
"out-of-memory interrupt and no handler - enter debugger" |
|
4971 |
||
4972 |
self error:'almost out of memory' mayProceed:true |
|
4973 |
! |
|
4974 |
||
4975 |
recursionInterrupt |
|
4976 |
"{ Pragma: +optSpace }" |
|
4977 |
||
4978 |
"recursion limit (actually: stack overflow) interrupt. |
|
4979 |
This interrupt is triggered, when a process stack grows above |
|
4980 |
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
|
4981 |
could be caught. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4982 |
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
|
4983 |
and the exception can be resumed. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4984 |
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
|
4985 |
is not proceedable. |
10460 | 4986 |
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
|
4987 |
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
|
4988 |
or debug for a while. |
5755 | 4989 |
If the signal is ignored, and the stack continues to grow, there |
4990 |
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
|
4991 |
terminates the process." |
5755 | 4992 |
|
7838
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4993 |
|con remaining sender nSkipped| |
5755 | 4994 |
|
4995 |
(con := thisContext) isRecursive ifFalse:[ |
|
4996 |
"/ Processor activeProcess usedStackSize < Processor activeProcess maximumStackSize ifTrue:[ |
|
4997 |
"/ "/ mhmh - it hit me, but I am not responsible ... |
|
4998 |
"/ 'Stray recursionInterrupt ...' infoPrintCR. |
|
4999 |
"/ ^ self |
|
5000 |
"/ ]. |
|
14975 | 5001 |
ObjectMemory infoPrinting ifTrue:[ |
5002 |
'Object [info]: recursionInterrupt from:' printCR. |
|
5003 |
con := con sender. |
|
5004 |
remaining := 50. |
|
5005 |
[con notNil and:[remaining > 0]] whileTrue:[ |
|
5006 |
sender := con sender. |
|
5007 |
'| ' print. con fullPrint. |
|
5008 |
||
5009 |
nSkipped := 0. |
|
5010 |
[sender notNil and:[sender sender notNil |
|
5011 |
and:[sender selector == con selector |
|
5012 |
and:[sender sender selector == con selector |
|
5013 |
and:[sender method == con method]]]]] whileTrue:[ |
|
5014 |
nSkipped := nSkipped + 1. |
|
5015 |
con := sender. |
|
5016 |
sender := con sender. |
|
5017 |
]. |
|
5018 |
nSkipped > 0 ifTrue:[ |
|
5019 |
'| ... ***** ' print. nSkipped print. ' recursive contexts skipped *****' printCR. |
|
5020 |
]. |
|
5021 |
con := sender. |
|
5022 |
remaining := remaining - 1 |
|
5023 |
]. |
|
5024 |
]. |
|
5025 |
^ RecursionInterruptSignal raiseSignal |
|
5755 | 5026 |
] |
5027 |
||
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5028 |
"Modified: / 10.11.2001 / 15:15:56 / cg" |
5755 | 5029 |
! |
5030 |
||
5031 |
schedulerInterrupt |
|
5032 |
"{ Pragma: +optSpace }" |
|
5033 |
||
5034 |
"scheduler interrupt (supposed to be sent to Processor). |
|
5035 |
If we arrive here, either the Processor does not understand it, |
|
5036 |
or it has been set to nil. In any case, this is a sign of some |
|
5037 |
big trouble. Enter debugger." |
|
5038 |
||
5039 |
self error:'schedulerInterrupt - but no Processor' mayProceed:true |
|
5040 |
! |
|
5041 |
||
5042 |
signalInterrupt:signalNumber |
|
5043 |
"{ Pragma: +optSpace }" |
|
5044 |
||
10460 | 5045 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
10016 | 5046 |
(SIGPIPE), others (SIGBUS) are rather fatal... |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
5047 |
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
|
5048 |
Otherwise, a dialog is shown, asking the user on how to handle the signal. |
5755 | 5049 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
5050 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
5051 |
Currently (temporary kludge), these are passed as global variables." |
|
5052 |
||
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5053 |
|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
|
5054 |
action title screen| |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5055 |
|
13254 | 5056 |
thisContext isRecursive ifTrue:[ |
14975 | 5057 |
'Severe error: signalInterrupt while processing a signalInterrupt.' errorPrintCR. |
5058 |
'Terminating process ' errorPrint. Processor activeProcess errorPrintCR. |
|
13710 | 5059 |
"/ GenericException handle:[:ex | |
5060 |
"/ "/ ignore any error during termination |
|
5061 |
"/ ] do:[ |
|
5062 |
"/ Processor activeProcess terminate. |
|
5063 |
"/ ]. |
|
14975 | 5064 |
Processor activeProcess terminateNoSignal. |
13254 | 5065 |
]. |
5066 |
||
5755 | 5067 |
"if there has been an ST-signal installed, use it ..." |
5068 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
5069 |
sig notNil ifTrue:[ |
|
14975 | 5070 |
sig raiseSignalWith:signalNumber. |
5071 |
^ self. |
|
5755 | 5072 |
]. |
5073 |
||
5074 |
"/ if handled, raise OSSignalInterruptSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
5075 |
OSSignalInterrupt isHandled ifTrue:[ |
14975 | 5076 |
OSSignalInterrupt raiseRequestWith:signalNumber. |
5077 |
^ self. |
|
10460 | 5078 |
]. |
5079 |
||
5080 |
" |
|
5081 |
special cases |
|
14975 | 5082 |
- SIGPWR: power failure - write a crash image and continue |
5083 |
- SIGHUP: hang up - write a crash image and exit |
|
10922 | 5084 |
" |
5085 |
(signalNumber == OperatingSystem sigPWR) ifTrue:[ |
|
14975 | 5086 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
5087 |
^ self. |
|
10922 | 5088 |
]. |
5089 |
(signalNumber == OperatingSystem sigHUP) ifTrue:[ |
|
14975 | 5090 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
5091 |
'Object [info]: exit due to hangup signal.' errorPrintCR. |
|
5092 |
Smalltalk exit:1. |
|
7031 | 5093 |
]. |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
5094 |
|
5755 | 5095 |
name := OperatingSystem nameForSignal:signalNumber. |
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 |
"if there is no screen at all, bring up a mini debugger" |
10460 | 5098 |
(Screen isNil |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5099 |
or:[(screen := Screen current) isNil |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5100 |
or:[(screen := Screen default) isNil |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5101 |
or:[screen isOpen not]]]) ifTrue:[ |
14975 | 5102 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5103 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5104 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5105 |
"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
|
5106 |
otherwise display stays locked" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5107 |
screen ungrabPointer; ungrabKeyboard. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5108 |
|
7031 | 5109 |
here := thisContext. |
5110 |
badContext := here sender. "the context, in which the signal occurred" |
|
5111 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5112 |
"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
|
5113 |
Screen currentScreenQuerySignal answer:screen do:[ |
14975 | 5114 |
" |
5115 |
SIGBUS, SIGSEGV and SIGILL do not make sense to ignore (i.e. continue) |
|
5116 |
since the system will retry the faulty instruction, which leads to |
|
5117 |
another signal - to avoid frustration, better not offer this option. |
|
5118 |
" |
|
5119 |
fatal := OperatingSystem isFatalSignal:signalNumber. |
|
5120 |
fatal ifTrue:[ |
|
5121 |
(Debugger isNil or:[here isRecursive]) ifTrue:[ |
|
5122 |
'Object [hard error]: signal ' errorPrint. signalNumber errorPrintCR. |
|
5123 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
5124 |
]. |
|
5125 |
" |
|
5126 |
a hard signal - go into debugger immediately |
|
5127 |
" |
|
5128 |
msg := 'OS-signal: ', name. |
|
5129 |
||
5130 |
"/ the IRQ-PC is passed as low-hi, to avoid the need |
|
5131 |
"/ to allocate a LargeInteger in the VM during signal |
|
5132 |
"/ time. I know, this is ugly. |
|
5133 |
||
5134 |
InterruptPcLow notNil ifTrue:[ |
|
5135 |
pc := InterruptPcLow + (InterruptPcHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
5136 |
pc ~~ 0 ifTrue:[ |
|
5137 |
msg := msg , ' PC=' , (pc printStringRadix:16) |
|
5138 |
]. |
|
5139 |
]. |
|
5140 |
InterruptAddrLow notNil ifTrue:[ |
|
5141 |
addr := InterruptAddrLow + (InterruptAddrHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
5142 |
addr ~~ 0 ifTrue:[ |
|
5143 |
msg := msg , ' ADDR=' , (addr printStringRadix:16) |
|
5144 |
]. |
|
5145 |
]. |
|
5146 |
Debugger enter:here withMessage:msg mayProceed:false. |
|
5147 |
"unreachable" |
|
5148 |
^ nil. |
|
5149 |
]. |
|
5150 |
||
5151 |
"if possible, open an option box asking the user what do. |
|
5152 |
Otherwise, start a debugger" |
|
5153 |
Dialog notNil ifTrue:[ |
|
5154 |
titles := #('save crash image' 'dump core' 'exit ST/X' 'debug'). |
|
5155 |
actions := #(save core exit debug). |
|
5156 |
||
5157 |
action := nil. |
|
5158 |
title := 'OS Signal caught (' , name, ')'. |
|
5159 |
title := (title , '\[in ST-process: ' , Processor activeProcess nameOrId ,']') withCRs. |
|
5160 |
||
5161 |
"/ if cought while in the scheduler or event dispatcher, |
|
5162 |
"/ a modal dialog is not possible ... |
|
5163 |
"/ (therefore, abort & return does not makes sense) |
|
5164 |
||
5165 |
Processor activeProcess isSystemProcess ifFalse:[ |
|
5166 |
titles := #('abort') , titles. |
|
5167 |
actions := #(abort), actions. |
|
5168 |
||
5169 |
badContext canReturn ifTrue:[ |
|
5170 |
titles := #('return') , titles. |
|
5171 |
actions := #(return), actions. |
|
5172 |
]. |
|
5173 |
]. |
|
5174 |
||
5175 |
fatal ifFalse:[ |
|
5176 |
titles := titles, #('ignore'). |
|
5177 |
actions := actions , #(ignore). |
|
5178 |
]. |
|
5179 |
action := Dialog choose:title |
|
5180 |
labels:titles |
|
5181 |
values:actions |
|
5182 |
default:(fatal ifTrue:[nil] ifFalse:[#ignore]). |
|
5183 |
||
5184 |
"Dialog may fail (if system process), default action is debug" |
|
5185 |
action isEmptyOrNil ifTrue:[action := #debug]. |
|
5186 |
] ifFalse:[ |
|
5187 |
action := #debug. |
|
5188 |
]. |
|
5189 |
||
5190 |
action == #save ifTrue:[ |
|
5191 |
ObjectMemory writeCrashImage |
|
5192 |
]. |
|
5193 |
action == #core ifTrue:[ |
|
5194 |
Smalltalk fatalAbort |
|
5195 |
]. |
|
5196 |
action == #exit ifTrue:[ |
|
5197 |
Smalltalk exit |
|
5198 |
]. |
|
5199 |
action == #return ifTrue:[ |
|
5200 |
badContext return |
|
5201 |
]. |
|
5202 |
action == #abort ifTrue:[ |
|
5203 |
AbortOperationRequest raise. |
|
5204 |
]. |
|
5205 |
||
5206 |
action == #debug ifTrue:[ |
|
5207 |
Debugger isNil ifTrue:[ |
|
5208 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
5209 |
]. |
|
5210 |
Debugger enter:here withMessage:('OS-Signal ', name) mayProceed:true. |
|
5211 |
]. |
|
5212 |
"action == #ignore" |
|
13261 | 5213 |
]. |
5214 |
||
13710 | 5215 |
"Modified: / 15-09-2011 / 16:38:14 / cg" |
5755 | 5216 |
! |
5217 |
||
5218 |
spyInterrupt |
|
5219 |
"{ Pragma: +optSpace }" |
|
5220 |
||
5221 |
"spy interrupt and no handler - enter debugger" |
|
5222 |
||
5223 |
self error:'spy Interrupt - but no handler' mayProceed:true |
|
5224 |
! |
|
5225 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5226 |
startMiniDebuggerOrExit:text |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5227 |
"some critical condition happened. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5228 |
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
|
5229 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5230 |
MiniDebugger isNil ifTrue:[ |
14975 | 5231 |
"a system without debugging facilities (i.e. a standalone system) |
5232 |
output a message and exit." |
|
5233 |
('Object [error]: exit due to ', text, ' - and no debugger.') errorPrintCR. |
|
5234 |
OperatingSystem exit:99. |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5235 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5236 |
MiniDebugger enterWithMessage:text mayProceed:true. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5237 |
! |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5238 |
|
5755 | 5239 |
timerInterrupt |
5240 |
"{ Pragma: +optSpace }" |
|
5241 |
||
5242 |
"timer interrupt and no handler - enter debugger" |
|
5243 |
||
5244 |
self error:'timer Interrupt - but no handler' mayProceed:true |
|
5245 |
! |
|
5246 |
||
5247 |
userInterrupt |
|
5248 |
"{ Pragma: +optSpace }" |
|
5249 |
||
5250 |
"user (^c) interrupt. |
|
5251 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
5252 |
controlling tty (i.e. in the xterm)." |
|
5253 |
||
6466 | 5254 |
UserInterruptSignal raiseRequest |
5755 | 5255 |
! |
5256 |
||
5257 |
userInterruptIn:aContext |
|
5258 |
"{ Pragma: +optSpace }" |
|
5259 |
||
5260 |
"user (^c) interrupt - enter debugger, but show aContext |
|
10460 | 5261 |
as top-context. |
5262 |
This is used to hide any intermediate scheduler contexts, |
|
5755 | 5263 |
in case of an interrupted process. Typically, this is sent by |
5264 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
5265 |
processed." |
|
5266 |
||
5267 |
<context: #return> |
|
5268 |
||
5269 |
UserInterruptSignal raiseRequestWith:nil errorString:nil in:aContext |
|
5270 |
||
5271 |
"Created: / 18.10.1996 / 20:46:04 / cg" |
|
5272 |
"Modified: / 20.10.1996 / 13:06:38 / cg" |
|
5273 |
"Modified: / 26.7.1999 / 10:58:49 / stefan" |
|
5274 |
! ! |
|
5275 |
||
5276 |
!Object methodsFor:'message sending'! |
|
5277 |
||
5278 |
perform:aSelector |
|
5279 |
"send the message aSelector to the receiver" |
|
5280 |
||
11335 | 5281 |
<resource: #skipInDebuggersWalkBack> |
5282 |
||
5755 | 5283 |
%{ |
5284 |
REGISTER OBJ sel = aSelector; |
|
5285 |
||
5286 |
if (InterruptPending == nil) { |
|
14975 | 5287 |
struct inlineCache *pIlc; |
13416 | 5288 |
/* JV @ 2010-22-07: To improve performance I use 256 ILCs instead |
14632 | 5289 |
of default 4. This significantly reduces ILC misses. The code |
5290 |
should be further optimized by remembering last selector index and |
|
5291 |
try a first shot on that index. Another option is to use kind of |
|
5292 |
hashing on lower bits of sel variable. However, a more detailed |
|
13416 | 5293 |
statistical data should be gathered before doing further optimizations. |
5294 |
*/ |
|
5295 |
||
5296 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF0(l) } |
|
5297 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5298 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5299 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5300 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5301 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5302 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5303 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5304 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5305 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5306 |
#define nilcs 256 |
|
5307 |
||
14975 | 5308 |
static struct { OBJ sel; struct inlineCache ilc; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
13416 | 5309 |
|
5310 |
#undef SEL_AND_ILC_INIT_1 |
|
5311 |
#undef SEL_AND_ILC_INIT_2 |
|
5312 |
#undef SEL_AND_ILC_INIT_4 |
|
5313 |
#undef SEL_AND_ILC_INIT_8 |
|
5314 |
#undef SEL_AND_ILC_INIT_16 |
|
5315 |
#undef SEL_AND_ILC_INIT_32 |
|
5316 |
#undef SEL_AND_ILC_INIT_64 |
|
5317 |
#undef SEL_AND_ILC_INIT_128 |
|
5318 |
#undef SEL_AND_ILC_INIT_256 |
|
5319 |
||
14975 | 5320 |
static flip = 0; |
5321 |
int i; |
|
5322 |
for (i = 0; i < nilcs; i++) { |
|
5323 |
if (sel == sel_and_ilc[i].sel) { |
|
5324 |
pIlc = &sel_and_ilc[i].ilc; |
|
5325 |
goto perform0_send_and_return; |
|
5326 |
} |
|
5327 |
} |
|
5328 |
/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/ |
|
5329 |
pIlc = &sel_and_ilc[flip].ilc; |
|
5330 |
sel_and_ilc[flip].sel = sel; |
|
5331 |
flip = (flip + 1) % nilcs; |
|
5332 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5333 |
if (pIlc->ilc_poly) { |
|
5334 |
__flushPolyCache(pIlc->ilc_poly); |
|
5335 |
pIlc->ilc_poly = 0; |
|
5336 |
} |
|
13416 | 5337 |
perform0_send_and_return: |
14975 | 5338 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
5755 | 5339 |
} else { |
14975 | 5340 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
5341 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5755 | 5342 |
} |
5343 |
%}. |
|
5344 |
^ self perform:aSelector withArguments:#() |
|
5345 |
! |
|
5346 |
||
5347 |
perform:aSelector inClass:aClass withArguments:argArray |
|
10460 | 5348 |
"send the message aSelector with all args taken from argArray |
5755 | 5349 |
to the receiver as a super-send message. |
5350 |
This is actually more flexible than the normal super-send, since it allows |
|
5351 |
to execute a method in ANY superclass of the receiver (not just the |
|
5352 |
immediate superclass). |
|
10460 | 5353 |
Thus, it is (theoretically) possible to do |
14975 | 5354 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
5755 | 5355 |
and evaluate Magnitudes compare method even if there was one in Number. |
5356 |
This method is used by the interpreter to evaluate super sends |
|
5357 |
and could be used for very special behavior (language extension ?). |
|
5358 |
||
5359 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
5360 |
||
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5361 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 myClass| |
5755 | 5362 |
|
5363 |
" |
|
5364 |
check, if aClass is really a superclass of the receiver |
|
5365 |
" |
|
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5366 |
myClass := self class. |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5367 |
(myClass == aClass or:[myClass isSubclassOf:aClass]) ifFalse:[ |
14975 | 5368 |
self error:'lookup-class argument is not a superclass of the receiver'. |
5369 |
^ nil |
|
5755 | 5370 |
]. |
5371 |
%{ |
|
5372 |
REGISTER OBJ *argP; |
|
5373 |
int nargs, i; |
|
5374 |
||
8934 | 5375 |
if (__isArrayLike(argArray)) { |
14975 | 5376 |
nargs = __arraySize(argArray); |
5377 |
argP = __arrayVal(argArray); |
|
5755 | 5378 |
} else { |
14975 | 5379 |
if (__isNonNilObject(argArray)) { |
5380 |
static struct inlineCache ilcSize = __ILC0(@line+1); |
|
5381 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5382 |
if (!__isSmallInteger(numberOfArgs)) |
|
5383 |
goto bad; |
|
5384 |
nargs = __intVal(numberOfArgs); |
|
5385 |
argP = (OBJ *)(&a1); |
|
5386 |
for (i=1; i <= nargs; i++) { |
|
5387 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
5388 |
} |
|
5389 |
argP = (OBJ *)(&a1); |
|
5390 |
} else { |
|
5391 |
nargs = 0; |
|
5392 |
} |
|
5755 | 5393 |
} |
5394 |
switch (nargs) { |
|
14975 | 5395 |
case 0: |
5396 |
{ |
|
5397 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5398 |
RETURN ( _SEND0(self, aSelector, aClass, &ilc0)); |
|
5399 |
} |
|
5400 |
||
5401 |
case 1: |
|
5402 |
{ |
|
5403 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5404 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, argP[0])); |
|
5405 |
} |
|
5406 |
||
5407 |
case 2: |
|
5408 |
{ |
|
5409 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5410 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, argP[0], argP[1])); |
|
5411 |
} |
|
5412 |
||
5413 |
case 3: |
|
5414 |
{ |
|
5415 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5416 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, |
|
5417 |
argP[0], argP[1], argP[2])); |
|
5418 |
} |
|
5419 |
||
5420 |
case 4: |
|
5421 |
{ |
|
5422 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
5423 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, |
|
5424 |
argP[0], argP[1], argP[2], argP[3])); |
|
5425 |
} |
|
5426 |
||
5427 |
case 5: |
|
5428 |
{ |
|
5429 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
5430 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
5431 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5432 |
} |
|
5433 |
||
5434 |
case 6: |
|
5435 |
{ |
|
5436 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
5437 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
5438 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5])); |
|
5439 |
} |
|
5440 |
||
5441 |
case 7: |
|
5442 |
{ |
|
5443 |
static struct inlineCache ilc7 = __DUMMYILCSELF7(@line+1); |
|
5444 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
5445 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5446 |
argP[6])); |
|
5447 |
} |
|
5448 |
||
5449 |
case 8: |
|
5450 |
{ |
|
5451 |
static struct inlineCache ilc8 = __DUMMYILCSELF8(@line+1); |
|
5452 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
5453 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5454 |
argP[6], argP[7])); |
|
5455 |
} |
|
5456 |
||
5457 |
case 9: |
|
5458 |
{ |
|
5459 |
static struct inlineCache ilc9 = __DUMMYILCSELF9(@line+1); |
|
5460 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
5461 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5462 |
argP[6], argP[7], argP[8])); |
|
5463 |
} |
|
5464 |
||
5465 |
case 10: |
|
5466 |
{ |
|
5467 |
static struct inlineCache ilc10 = __DUMMYILCSELF10(@line+1); |
|
5468 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
5469 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5470 |
argP[6], argP[7], argP[8], argP[9])); |
|
5471 |
} |
|
5472 |
||
5473 |
case 11: |
|
5474 |
{ |
|
5475 |
static struct inlineCache ilc11 = __DUMMYILCSELF11(@line+1); |
|
5476 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
5477 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5478 |
argP[6], argP[7], argP[8], argP[9], argP[10])); |
|
5479 |
} |
|
5480 |
||
5481 |
case 12: |
|
5482 |
{ |
|
5483 |
static struct inlineCache ilc12 = __DUMMYILCSELF12(@line+1); |
|
5484 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
5485 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5486 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5487 |
argP[11])); |
|
5488 |
} |
|
5489 |
||
5490 |
case 13: |
|
5491 |
{ |
|
5492 |
static struct inlineCache ilc13 = __DUMMYILCSELF13(@line+1); |
|
5493 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
5494 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5495 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5496 |
argP[11], argP[12])); |
|
5497 |
} |
|
5498 |
||
5499 |
case 14: |
|
5500 |
{ |
|
5501 |
static struct inlineCache ilc14 = __DUMMYILCSELF14(@line+1); |
|
5502 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
5503 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5504 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5505 |
argP[11], argP[12], argP[13])); |
|
5506 |
} |
|
5507 |
||
5508 |
case 15: |
|
5509 |
{ |
|
5510 |
static struct inlineCache ilc15 = __DUMMYILCSELF15(@line+1); |
|
5511 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
5512 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5513 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5514 |
argP[11], argP[12], argP[13], argP[14])); |
|
5515 |
} |
|
5755 | 5516 |
|
5517 |
#ifdef _SEND16 |
|
14975 | 5518 |
case 16: |
5519 |
{ |
|
5520 |
static struct inlineCache ilc16 = __DUMMYILCSELF16(@line+1); |
|
5521 |
RETURN ( _SEND16(self, aSelector, aClass, &ilc15, |
|
5522 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5523 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5524 |
argP[11], argP[12], argP[13], argP[14], argP[15])); |
|
5525 |
} |
|
5755 | 5526 |
#endif |
5527 |
#ifdef _SEND17 |
|
14975 | 5528 |
case 17: |
5529 |
{ |
|
5530 |
static struct inlineCache ilc17 = __DUMMYILCSELF17(@line+1); |
|
5531 |
RETURN ( _SEND17(self, aSelector, aClass, &ilc15, |
|
5532 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5533 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5534 |
argP[11], argP[12], argP[13], argP[14], argP[15], argP[16])); |
|
5535 |
} |
|
5755 | 5536 |
#endif |
5537 |
||
5538 |
||
5539 |
} |
|
5540 |
bad:; |
|
5541 |
%}. |
|
5542 |
"/ arrive here, if bad number of arguments (too many) |
|
5543 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5544 |
||
5545 |
^ self primitiveFailed |
|
5546 |
! |
|
5547 |
||
5548 |
perform:aSelector with:arg |
|
5549 |
"send the one-arg-message aSelector to the receiver" |
|
5550 |
||
5551 |
%{ |
|
5552 |
REGISTER OBJ sel = aSelector; |
|
5553 |
||
5554 |
if (InterruptPending == nil) { |
|
14975 | 5555 |
struct inlineCache *pIlc; |
13416 | 5556 |
/* JV @ 2010-22-07: To improve performance I use 256 ILCs instead |
5557 |
of default 4. For details, see comment in perform: */ |
|
5558 |
||
5559 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF1(l) } |
|
5560 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5561 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5562 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5563 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5564 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5565 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5566 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5567 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5568 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5569 |
#define nilcs 256 |
|
5570 |
||
14975 | 5571 |
static struct { OBJ sel; struct inlineCache ilc; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
13416 | 5572 |
|
5573 |
#undef SEL_AND_ILC_INIT_1 |
|
5574 |
#undef SEL_AND_ILC_INIT_2 |
|
5575 |
#undef SEL_AND_ILC_INIT_4 |
|
5576 |
#undef SEL_AND_ILC_INIT_8 |
|
5577 |
#undef SEL_AND_ILC_INIT_16 |
|
5578 |
#undef SEL_AND_ILC_INIT_32 |
|
5579 |
#undef SEL_AND_ILC_INIT_64 |
|
5580 |
#undef SEL_AND_ILC_INIT_128 |
|
5581 |
#undef SEL_AND_ILC_INIT_256 |
|
5582 |
||
14975 | 5583 |
static flip = 0; |
5584 |
int i; |
|
5585 |
for (i = 0; i < nilcs; i++) { |
|
5586 |
if (sel == sel_and_ilc[i].sel) { |
|
5587 |
pIlc = &sel_and_ilc[i].ilc; |
|
5588 |
goto perform1_send_and_return; |
|
5589 |
} |
|
5590 |
} |
|
5591 |
/*printf("Object >> #perform: #%s with: arg --> no PIC found\n", __symbolVal(aSelector));*/ |
|
5592 |
pIlc = &sel_and_ilc[flip].ilc; |
|
5593 |
sel_and_ilc[flip].sel = sel; |
|
5594 |
flip = (flip + 1) % nilcs; |
|
5595 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5596 |
if (pIlc->ilc_poly) { |
|
5597 |
__flushPolyCache(pIlc->ilc_poly); |
|
5598 |
pIlc->ilc_poly = 0; |
|
5599 |
} |
|
13416 | 5600 |
perform1_send_and_return: |
14975 | 5601 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
5755 | 5602 |
} else { |
14975 | 5603 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
5604 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
5755 | 5605 |
} |
5606 |
%}. |
|
5607 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5608 |
||
5609 |
! |
|
5610 |
||
5611 |
perform:aSelector with:arg1 with:arg2 |
|
5612 |
"send the two-arg-message aSelector to the receiver" |
|
5613 |
||
5614 |
%{ |
|
13416 | 5615 |
REGISTER OBJ sel = aSelector; |
5755 | 5616 |
struct inlineCache *pIlc; |
5617 |
||
5618 |
if (InterruptPending == nil) { |
|
13416 | 5619 |
|
5620 |
/* JV @ 2010-22-07: To improve performance I use 256 ILCs instead |
|
5621 |
of default 4. For details, see comment in perform: */ |
|
5622 |
||
5623 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF2(l) } |
|
5624 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5625 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5626 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5627 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5628 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5629 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5630 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5631 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5632 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5633 |
#define nilcs 256 |
|
5634 |
||
14975 | 5635 |
static struct { OBJ sel; struct inlineCache ilc; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
13416 | 5636 |
|
5637 |
#undef SEL_AND_ILC_INIT_1 |
|
5638 |
#undef SEL_AND_ILC_INIT_2 |
|
5639 |
#undef SEL_AND_ILC_INIT_4 |
|
5640 |
#undef SEL_AND_ILC_INIT_8 |
|
5641 |
#undef SEL_AND_ILC_INIT_16 |
|
5642 |
#undef SEL_AND_ILC_INIT_32 |
|
5643 |
#undef SEL_AND_ILC_INIT_64 |
|
5644 |
#undef SEL_AND_ILC_INIT_128 |
|
5645 |
#undef SEL_AND_ILC_INIT_256 |
|
5646 |
||
14975 | 5647 |
static flip = 0; |
5648 |
int i; |
|
5649 |
for (i = 0; i < nilcs; i++) { |
|
5650 |
if (sel == sel_and_ilc[i].sel) { |
|
5651 |
pIlc = &sel_and_ilc[i].ilc; |
|
5652 |
goto perform2_send_and_return; |
|
5653 |
} |
|
5654 |
} |
|
5655 |
/*printf("Object >> #perform: #%s with: with: --> no PIC found\n", __symbolVal(aSelector));*/ |
|
5656 |
pIlc = &sel_and_ilc[flip].ilc; |
|
5657 |
sel_and_ilc[flip].sel = sel; |
|
5658 |
flip = (flip + 1) % nilcs; |
|
5659 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5660 |
if (pIlc->ilc_poly) { |
|
5661 |
__flushPolyCache(pIlc->ilc_poly); |
|
5662 |
pIlc->ilc_poly = 0; |
|
5663 |
} |
|
13416 | 5664 |
perform2_send_and_return: |
14975 | 5665 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
5755 | 5666 |
} else { |
14975 | 5667 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
5668 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, arg1, arg2)); |
|
5755 | 5669 |
} |
5670 |
%}. |
|
5671 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2) |
|
5672 |
||
5673 |
! |
|
5674 |
||
5675 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
|
5676 |
"send the three-arg-message aSelector to the receiver" |
|
5677 |
||
5678 |
%{ |
|
5679 |
struct inlineCache *pIlc; |
|
5680 |
static struct inlineCache ilc_0 = __ILCPERF3(@line); |
|
5681 |
static struct inlineCache ilc_1 = __ILCPERF3(@line); |
|
5682 |
static OBJ last_0 = nil; |
|
5683 |
static OBJ last_1 = nil; |
|
5684 |
static flip = 0; |
|
5685 |
||
5686 |
if (InterruptPending == nil) { |
|
14975 | 5687 |
if (aSelector != last_0) { |
5688 |
if (aSelector != last_1) { |
|
5689 |
if (flip) { |
|
5690 |
pIlc = &ilc_0; |
|
5691 |
flip = 0; |
|
5692 |
last_0 = aSelector; |
|
5693 |
} else { |
|
5694 |
pIlc = &ilc_1; |
|
5695 |
flip = 1; |
|
5696 |
last_1 = aSelector; |
|
5697 |
} |
|
5698 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5699 |
if (pIlc->ilc_poly) { |
|
5700 |
__flushPolyCache(pIlc->ilc_poly); |
|
5701 |
pIlc->ilc_poly = 0; |
|
5702 |
} |
|
5703 |
} else { |
|
5704 |
pIlc = &ilc_1; |
|
5705 |
} |
|
5706 |
} else { |
|
5707 |
pIlc = &ilc_0; |
|
5708 |
} |
|
5709 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
|
5755 | 5710 |
} else { |
14975 | 5711 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
5712 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, arg1, arg2, arg3)); |
|
5755 | 5713 |
} |
5714 |
%}. |
|
5715 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3) |
|
5716 |
||
5717 |
! |
|
5718 |
||
5719 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
5720 |
"send the four-arg-message aSelector to the receiver" |
|
5721 |
||
5722 |
%{ |
|
5723 |
struct inlineCache *pIlc; |
|
5724 |
static struct inlineCache ilc_0 = __ILCPERF4(@line); |
|
5725 |
static struct inlineCache ilc_1 = __ILCPERF4(@line); |
|
5726 |
static OBJ last_0 = nil; |
|
5727 |
static OBJ last_1 = nil; |
|
5728 |
static flip = 0; |
|
5729 |
||
5730 |
if (InterruptPending == nil) { |
|
14975 | 5731 |
if (aSelector != last_0) { |
5732 |
if (aSelector != last_1) { |
|
5733 |
if (flip) { |
|
5734 |
pIlc = &ilc_0; |
|
5735 |
flip = 0; |
|
5736 |
last_0 = aSelector; |
|
5737 |
} else { |
|
5738 |
pIlc = &ilc_1; |
|
5739 |
flip = 1; |
|
5740 |
last_1 = aSelector; |
|
5741 |
} |
|
5742 |
pIlc->ilc_func = __SEND4ADDR__; |
|
5743 |
if (pIlc->ilc_poly) { |
|
5744 |
__flushPolyCache(pIlc->ilc_poly); |
|
5745 |
pIlc->ilc_poly = 0; |
|
5746 |
} |
|
5747 |
} else { |
|
5748 |
pIlc = &ilc_1; |
|
5749 |
} |
|
5750 |
} else { |
|
5751 |
pIlc = &ilc_0; |
|
5752 |
} |
|
5753 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5754 |
arg1, arg2, arg3, arg4) ); |
|
5755 | 5755 |
} else { |
14975 | 5756 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
5757 |
RETURN (_SEND4(self, aSelector, nil, &ilc4, |
|
5758 |
arg1, arg2, arg3, arg4)); |
|
5755 | 5759 |
} |
5760 |
%}. |
|
5761 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
5762 |
||
5763 |
! |
|
5764 |
||
5765 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
5766 |
"send the five-arg-message aSelector to the receiver" |
|
5767 |
||
5768 |
%{ |
|
5769 |
struct inlineCache *pIlc; |
|
5770 |
static struct inlineCache ilc_0 = __ILCPERF5(@line); |
|
5771 |
static struct inlineCache ilc_1 = __ILCPERF5(@line); |
|
5772 |
static OBJ last_0 = nil; |
|
5773 |
static OBJ last_1 = nil; |
|
5774 |
static flip = 0; |
|
5775 |
||
5776 |
if (InterruptPending == nil) { |
|
14975 | 5777 |
if (aSelector != last_0) { |
5778 |
if (aSelector != last_1) { |
|
5779 |
if (flip) { |
|
5780 |
pIlc = &ilc_0; |
|
5781 |
flip = 0; |
|
5782 |
last_0 = aSelector; |
|
5783 |
} else { |
|
5784 |
pIlc = &ilc_1; |
|
5785 |
flip = 1; |
|
5786 |
last_1 = aSelector; |
|
5787 |
} |
|
5788 |
pIlc->ilc_func = __SEND5ADDR__; |
|
5789 |
if (pIlc->ilc_poly) { |
|
5790 |
__flushPolyCache(pIlc->ilc_poly); |
|
5791 |
pIlc->ilc_poly = 0; |
|
5792 |
} |
|
5793 |
} else { |
|
5794 |
pIlc = &ilc_1; |
|
5795 |
} |
|
5796 |
} else { |
|
5797 |
pIlc = &ilc_0; |
|
5798 |
} |
|
5799 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5800 |
arg1, arg2, arg3, arg4, arg5) ); |
|
5755 | 5801 |
} else { |
14975 | 5802 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
5803 |
RETURN (_SEND5(self, aSelector, nil, &ilc5, |
|
5804 |
arg1, arg2, arg3, arg4, arg5)); |
|
5755 | 5805 |
} |
5806 |
%}. |
|
5807 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
14975 | 5808 |
with:arg5) |
5755 | 5809 |
|
5810 |
! |
|
5811 |
||
5812 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
|
5813 |
"send the six-arg-message aSelector to the receiver" |
|
5814 |
||
5815 |
%{ |
|
5816 |
struct inlineCache *pIlc; |
|
5817 |
static struct inlineCache ilc_0 = __ILCPERF6(@line); |
|
5818 |
static struct inlineCache ilc_1 = __ILCPERF6(@line); |
|
5819 |
static OBJ last_0 = nil; |
|
5820 |
static OBJ last_1 = nil; |
|
5821 |
static flip = 0; |
|
5822 |
||
5823 |
if (InterruptPending == nil) { |
|
14975 | 5824 |
if (aSelector != last_0) { |
5825 |
if (aSelector != last_1) { |
|
5826 |
if (flip) { |
|
5827 |
pIlc = &ilc_0; |
|
5828 |
flip = 0; |
|
5829 |
last_0 = aSelector; |
|
5830 |
} else { |
|
5831 |
pIlc = &ilc_1; |
|
5832 |
flip = 1; |
|
5833 |
last_1 = aSelector; |
|
5834 |
} |
|
5835 |
pIlc->ilc_func = __SEND6ADDR__; |
|
5836 |
if (pIlc->ilc_poly) { |
|
5837 |
__flushPolyCache(pIlc->ilc_poly); |
|
5838 |
pIlc->ilc_poly = 0; |
|
5839 |
} |
|
5840 |
} else { |
|
5841 |
pIlc = &ilc_1; |
|
5842 |
} |
|
5843 |
} else { |
|
5844 |
pIlc = &ilc_0; |
|
5845 |
} |
|
5846 |
||
5847 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5848 |
arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
5755 | 5849 |
} else { |
14975 | 5850 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
5851 |
RETURN (_SEND6(self, aSelector, nil, &ilc6, |
|
5852 |
arg1, arg2, arg3, arg4, arg5, arg6)); |
|
5755 | 5853 |
} |
5854 |
%}. |
|
5855 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
14975 | 5856 |
with:arg5 with:arg6) |
5755 | 5857 |
|
5858 |
! |
|
5859 |
||
5860 |
perform:aSelector withArguments:argArray |
|
10460 | 5861 |
"send the message aSelector with all args taken from argArray |
5755 | 5862 |
to the receiver." |
5863 |
||
5864 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
5865 |
||
5866 |
%{ |
|
5867 |
REGISTER OBJ *argP; |
|
5868 |
int nargs; |
|
5869 |
OBJ l; |
|
5870 |
||
8934 | 5871 |
if (__isArrayLike(argArray)) { |
14975 | 5872 |
nargs = __arraySize(argArray); |
5873 |
argP = __arrayVal(argArray); |
|
5755 | 5874 |
} else { |
14975 | 5875 |
if (__isNonNilObject(argArray)) { |
5876 |
static struct inlineCache ilcSize = __ILC0(@line); |
|
5877 |
int i; |
|
5878 |
||
5879 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5880 |
if (!__isSmallInteger(numberOfArgs)) |
|
5881 |
goto bad; |
|
5882 |
nargs = __intVal(numberOfArgs); |
|
5883 |
argP = (OBJ *)(&a1); |
|
5884 |
for (i=1; i <= nargs; i++) { |
|
5885 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
5886 |
} |
|
5887 |
argP = (OBJ *)(&a1); |
|
5888 |
} else { |
|
5889 |
nargs = 0; |
|
5890 |
} |
|
5755 | 5891 |
} |
5892 |
switch (nargs) { |
|
14975 | 5893 |
case 0: |
5894 |
if (InterruptPending == nil) { |
|
5895 |
static OBJ last0_0 = nil; static struct inlineCache ilc0_0 = __ILCPERF0(@line); |
|
5896 |
static OBJ last0_1 = nil; static struct inlineCache ilc0_1 = __ILCPERF0(@line); |
|
5897 |
static OBJ last0_2 = nil; static struct inlineCache ilc0_2 = __ILCPERF0(@line); |
|
5898 |
static OBJ last0_3 = nil; static struct inlineCache ilc0_3 = __ILCPERF0(@line); |
|
5899 |
static int flip0 = 0; |
|
5900 |
struct inlineCache *pIlc; |
|
5901 |
||
5902 |
if (aSelector == last0_0) { |
|
5903 |
pIlc = &ilc0_0; |
|
5904 |
} else if (aSelector == last0_1) { |
|
5905 |
pIlc = &ilc0_1; |
|
5906 |
} else if (aSelector == last0_2) { |
|
5907 |
pIlc = &ilc0_2; |
|
5908 |
} else if (aSelector == last0_3) { |
|
5909 |
pIlc = &ilc0_3; |
|
5910 |
} else { |
|
5911 |
if (flip0 == 0) { |
|
5912 |
pIlc = &ilc0_0; |
|
5913 |
flip0 = 1; |
|
5914 |
last0_0 = aSelector; |
|
5915 |
} else if (flip0 == 1) { |
|
5916 |
pIlc = &ilc0_1; |
|
5917 |
flip0 = 2; |
|
5918 |
last0_1 = aSelector; |
|
5919 |
} else if (flip0 == 2) { |
|
5920 |
pIlc = &ilc0_2; |
|
5921 |
flip0 = 3; |
|
5922 |
last0_2 = aSelector; |
|
5923 |
} else { |
|
5924 |
pIlc = &ilc0_3; |
|
5925 |
flip0 = 0; |
|
5926 |
last0_3 = aSelector; |
|
5927 |
} |
|
5928 |
||
5929 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5930 |
if (pIlc->ilc_poly) { |
|
5931 |
__flushPolyCache(pIlc->ilc_poly); |
|
5932 |
pIlc->ilc_poly = 0; |
|
5933 |
} |
|
5934 |
} |
|
5935 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc)); |
|
5936 |
} else { |
|
5937 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5938 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5939 |
} |
|
5940 |
||
5941 |
case 1: |
|
5942 |
if (InterruptPending == nil) { |
|
5943 |
static OBJ last1_0 = nil; static struct inlineCache ilc1_0 = __ILCPERF1(@line); |
|
5944 |
static OBJ last1_1 = nil; static struct inlineCache ilc1_1 = __ILCPERF1(@line); |
|
5945 |
static OBJ last1_2 = nil; static struct inlineCache ilc1_2 = __ILCPERF1(@line); |
|
5946 |
static OBJ last1_3 = nil; static struct inlineCache ilc1_3 = __ILCPERF1(@line); |
|
5947 |
static int flip1 = 0; |
|
5948 |
struct inlineCache *pIlc; |
|
5949 |
||
5950 |
if (aSelector == last1_0) { |
|
5951 |
pIlc = &ilc1_0; |
|
5952 |
} else if (aSelector == last1_1) { |
|
5953 |
pIlc = &ilc1_1; |
|
5954 |
} else if (aSelector == last1_2) { |
|
5955 |
pIlc = &ilc1_2; |
|
5956 |
} else if (aSelector == last1_3) { |
|
5957 |
pIlc = &ilc1_3; |
|
5958 |
} else { |
|
5959 |
if (flip1 == 0) { |
|
5960 |
pIlc = &ilc1_0; |
|
5961 |
flip1 = 1; |
|
5962 |
last1_0 = aSelector; |
|
5963 |
} else if (flip1 == 1) { |
|
5964 |
pIlc = &ilc1_1; |
|
5965 |
flip1 = 2; |
|
5966 |
last1_1 = aSelector; |
|
5967 |
} else if (flip1 == 2) { |
|
5968 |
pIlc = &ilc1_2; |
|
5969 |
flip1 = 3; |
|
5970 |
last1_2 = aSelector; |
|
5971 |
} else { |
|
5972 |
pIlc = &ilc1_3; |
|
5973 |
flip1 = 0; |
|
5974 |
last1_3 = aSelector; |
|
5975 |
} |
|
5976 |
||
5977 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5978 |
if (pIlc->ilc_poly) { |
|
5979 |
__flushPolyCache(pIlc->ilc_poly); |
|
5980 |
pIlc->ilc_poly = 0; |
|
5981 |
} |
|
5982 |
} |
|
5983 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0])); |
|
5984 |
} else { |
|
5985 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5986 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, argP[0])); |
|
5987 |
} |
|
5988 |
||
5989 |
case 2: |
|
5990 |
if (InterruptPending == nil) { |
|
5991 |
static OBJ last2_0 = nil; static struct inlineCache ilc2_0 = __ILCPERF2(@line); |
|
5992 |
static OBJ last2_1 = nil; static struct inlineCache ilc2_1 = __ILCPERF2(@line); |
|
5993 |
static int flip2 = 0; |
|
5994 |
struct inlineCache *pIlc; |
|
5995 |
||
5996 |
if (aSelector == last2_0) { |
|
5997 |
pIlc = &ilc2_0; |
|
5998 |
} else if (aSelector == last2_1) { |
|
5999 |
pIlc = &ilc2_1; |
|
6000 |
} else { |
|
6001 |
if (flip2 == 0) { |
|
6002 |
pIlc = &ilc2_0; |
|
6003 |
flip2 = 1; |
|
6004 |
last2_0 = aSelector; |
|
6005 |
} else { |
|
6006 |
pIlc = &ilc2_1; |
|
6007 |
flip2 = 0; |
|
6008 |
last2_1 = aSelector; |
|
6009 |
} |
|
6010 |
||
6011 |
pIlc->ilc_func = __SEND2ADDR__; |
|
6012 |
if (pIlc->ilc_poly) { |
|
6013 |
__flushPolyCache(pIlc->ilc_poly); |
|
6014 |
pIlc->ilc_poly = 0; |
|
6015 |
} |
|
6016 |
} |
|
6017 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1])); |
|
6018 |
} else { |
|
6019 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
6020 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, argP[0], argP[1])); |
|
6021 |
} |
|
6022 |
||
6023 |
case 3: |
|
6024 |
if (InterruptPending == nil) { |
|
6025 |
static OBJ last3_0 = nil; static struct inlineCache ilc3_0 = __ILCPERF3(@line); |
|
6026 |
static OBJ last3_1 = nil; static struct inlineCache ilc3_1 = __ILCPERF3(@line); |
|
6027 |
static int flip3 = 0; |
|
6028 |
struct inlineCache *pIlc; |
|
6029 |
||
6030 |
if (aSelector == last3_0) { |
|
6031 |
pIlc = &ilc3_0; |
|
6032 |
} else if (aSelector == last3_1) { |
|
6033 |
pIlc = &ilc3_1; |
|
6034 |
} else { |
|
6035 |
if (flip3 == 0) { |
|
6036 |
pIlc = &ilc3_0; |
|
6037 |
flip3 = 1; |
|
6038 |
last3_0 = aSelector; |
|
6039 |
} else { |
|
6040 |
pIlc = &ilc3_1; |
|
6041 |
flip3 = 0; |
|
6042 |
last3_1 = aSelector; |
|
6043 |
} |
|
6044 |
||
6045 |
pIlc->ilc_func = __SEND3ADDR__; |
|
6046 |
if (pIlc->ilc_poly) { |
|
6047 |
__flushPolyCache(pIlc->ilc_poly); |
|
6048 |
pIlc->ilc_poly = 0; |
|
6049 |
} |
|
6050 |
} |
|
6051 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1], argP[2])); |
|
6052 |
} else { |
|
6053 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
6054 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, argP[0], argP[1], argP[2])); |
|
6055 |
} |
|
6056 |
||
6057 |
case 4: |
|
6058 |
{ |
|
6059 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(@line); |
|
6060 |
||
6061 |
if ((InterruptPending != nil) || (aSelector != last4)) { |
|
6062 |
ilc4.ilc_func = __SEND4ADDR__; |
|
6063 |
if (ilc4.ilc_poly) { |
|
6064 |
__flushPolyCache(ilc4.ilc_poly); |
|
6065 |
ilc4.ilc_poly = 0; |
|
6066 |
} |
|
6067 |
last4 = aSelector; |
|
6068 |
} |
|
6069 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
|
6070 |
argP[0], argP[1], argP[2], argP[3])); |
|
6071 |
} |
|
6072 |
||
6073 |
case 5: |
|
6074 |
{ |
|
6075 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(@line); |
|
6076 |
||
6077 |
if ((InterruptPending != nil) || (aSelector != last5)) { |
|
6078 |
ilc5.ilc_func = __SEND5ADDR__; |
|
6079 |
if (ilc5.ilc_poly) { |
|
6080 |
__flushPolyCache(ilc5.ilc_poly); |
|
6081 |
ilc5.ilc_poly = 0; |
|
6082 |
} |
|
6083 |
last5 = aSelector; |
|
6084 |
} |
|
6085 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
|
6086 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
6087 |
} |
|
6088 |
||
6089 |
case 6: |
|
6090 |
{ |
|
6091 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(@line); |
|
6092 |
||
6093 |
if ((InterruptPending != nil) || (aSelector != last6)) { |
|
6094 |
ilc6.ilc_func = __SEND6ADDR__; |
|
6095 |
if (ilc6.ilc_poly) { |
|
6096 |
__flushPolyCache(ilc6.ilc_poly); |
|
6097 |
ilc6.ilc_poly = 0; |
|
6098 |
} |
|
6099 |
last6 = aSelector; |
|
6100 |
} |
|
6101 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
|
6102 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6103 |
argP[5])); |
|
6104 |
} |
|
6105 |
||
6106 |
case 7: |
|
6107 |
{ |
|
6108 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(@line); |
|
6109 |
||
6110 |
if ((InterruptPending != nil) || (aSelector != last7)) { |
|
6111 |
ilc7.ilc_func = __SEND7ADDR__; |
|
6112 |
if (ilc7.ilc_poly) { |
|
6113 |
__flushPolyCache(ilc7.ilc_poly); |
|
6114 |
ilc7.ilc_poly = 0; |
|
6115 |
} |
|
6116 |
last7 = aSelector; |
|
6117 |
} |
|
6118 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
|
6119 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6120 |
argP[5], argP[6])); |
|
6121 |
} |
|
6122 |
||
6123 |
case 8: |
|
6124 |
{ |
|
6125 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(@line); |
|
6126 |
||
6127 |
if ((InterruptPending != nil) || (aSelector != last8)) { |
|
6128 |
ilc8.ilc_func = __SEND8ADDR__; |
|
6129 |
if (ilc8.ilc_poly) { |
|
6130 |
__flushPolyCache(ilc8.ilc_poly); |
|
6131 |
ilc8.ilc_poly = 0; |
|
6132 |
} |
|
6133 |
last8 = aSelector; |
|
6134 |
} |
|
6135 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
|
6136 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6137 |
argP[5], argP[6], argP[7])); |
|
6138 |
} |
|
6139 |
||
6140 |
case 9: |
|
6141 |
{ |
|
6142 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(@line); |
|
6143 |
||
6144 |
if ((InterruptPending != nil) || (aSelector != last9)) { |
|
6145 |
ilc9.ilc_func = __SEND9ADDR__; |
|
6146 |
if (ilc9.ilc_poly) { |
|
6147 |
__flushPolyCache(ilc9.ilc_poly); |
|
6148 |
ilc9.ilc_poly = 0; |
|
6149 |
} |
|
6150 |
last9 = aSelector; |
|
6151 |
} |
|
6152 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
|
6153 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6154 |
argP[5], argP[6], argP[7], argP[8])); |
|
6155 |
} |
|
6156 |
||
6157 |
case 10: |
|
6158 |
{ |
|
6159 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(@line); |
|
6160 |
||
6161 |
if ((InterruptPending != nil) || (aSelector != last10)) { |
|
6162 |
ilc10.ilc_func = __SEND10ADDR__; |
|
6163 |
if (ilc10.ilc_poly) { |
|
6164 |
__flushPolyCache(ilc10.ilc_poly); |
|
6165 |
ilc10.ilc_poly = 0; |
|
6166 |
} |
|
6167 |
last10 = aSelector; |
|
6168 |
} |
|
6169 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
|
6170 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6171 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
6172 |
} |
|
6173 |
||
6174 |
case 11: |
|
6175 |
{ |
|
6176 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(@line); |
|
6177 |
||
6178 |
if ((InterruptPending != nil) || (aSelector != last11)) { |
|
6179 |
ilc11.ilc_func = __SEND11ADDR__; |
|
6180 |
if (ilc11.ilc_poly) { |
|
6181 |
__flushPolyCache(ilc11.ilc_poly); |
|
6182 |
ilc11.ilc_poly = 0; |
|
6183 |
} |
|
6184 |
last11 = aSelector; |
|
6185 |
} |
|
6186 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
|
6187 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6188 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6189 |
argP[10])); |
|
6190 |
} |
|
6191 |
||
6192 |
case 12: |
|
6193 |
{ |
|
6194 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(@line); |
|
6195 |
||
6196 |
if ((InterruptPending != nil) || (aSelector != last12)) { |
|
6197 |
ilc12.ilc_func = __SEND12ADDR__; |
|
6198 |
if (ilc12.ilc_poly) { |
|
6199 |
__flushPolyCache(ilc12.ilc_poly); |
|
6200 |
ilc12.ilc_poly = 0; |
|
6201 |
} |
|
6202 |
last12 = aSelector; |
|
6203 |
} |
|
6204 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
|
6205 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6206 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6207 |
argP[10], argP[11])); |
|
6208 |
} |
|
6209 |
||
6210 |
case 13: |
|
6211 |
{ |
|
6212 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(@line); |
|
6213 |
||
6214 |
if ((InterruptPending != nil) || (aSelector != last13)) { |
|
6215 |
ilc13.ilc_func = __SEND13ADDR__; |
|
6216 |
if (ilc13.ilc_poly) { |
|
6217 |
__flushPolyCache(ilc13.ilc_poly); |
|
6218 |
ilc13.ilc_poly = 0; |
|
6219 |
} |
|
6220 |
last13 = aSelector; |
|
6221 |
} |
|
6222 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
|
6223 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6224 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6225 |
argP[10], argP[11], argP[12])); |
|
6226 |
} |
|
6227 |
||
6228 |
case 14: |
|
6229 |
{ |
|
6230 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(@line); |
|
6231 |
||
6232 |
if ((InterruptPending != nil) || (aSelector != last14)) { |
|
6233 |
ilc14.ilc_func = __SEND14ADDR__; |
|
6234 |
if (ilc14.ilc_poly) { |
|
6235 |
__flushPolyCache(ilc14.ilc_poly); |
|
6236 |
ilc14.ilc_poly = 0; |
|
6237 |
} |
|
6238 |
last14 = aSelector; |
|
6239 |
} |
|
6240 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
|
6241 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6242 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6243 |
argP[10], argP[11], argP[12], argP[13])); |
|
6244 |
} |
|
6245 |
||
6246 |
case 15: |
|
6247 |
{ |
|
6248 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(@line); |
|
6249 |
||
6250 |
if ((InterruptPending != nil) || (aSelector != last15)) { |
|
6251 |
ilc15.ilc_func = __SEND15ADDR__; |
|
6252 |
if (ilc15.ilc_poly) { |
|
6253 |
__flushPolyCache(ilc15.ilc_poly); |
|
6254 |
ilc15.ilc_poly = 0; |
|
6255 |
} |
|
6256 |
last15 = aSelector; |
|
6257 |
} |
|
6258 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
|
6259 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6260 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6261 |
argP[10], argP[11], argP[12], argP[13], |
|
6262 |
argP[14])); |
|
6263 |
} |
|
5755 | 6264 |
} |
6265 |
bad:; |
|
6266 |
%}. |
|
6267 |
||
6268 |
"/ arrive here, if bad number of arguments (too many) |
|
6269 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
6270 |
||
6271 |
^ self primitiveFailed |
|
6272 |
! |
|
6273 |
||
6316 | 6274 |
perform:aSelector withOptionalArgument:arg |
6275 |
"send aSelector-message to the receiver. |
|
6318 | 6276 |
If the message expects an argument, pass arg." |
6316 | 6277 |
|
6278 |
aSelector numArgs == 1 ifTrue:[ |
|
14975 | 6279 |
^ self perform:aSelector with:arg |
6316 | 6280 |
]. |
6281 |
^ self perform:aSelector |
|
6319 | 6282 |
|
6283 |
" |
|
6284 |
|rec sel| |
|
6285 |
||
6286 |
rec := -1. |
|
6287 |
sel := #abs. |
|
6288 |
rec perform:sel withOptionalArgument:2. |
|
6289 |
||
6290 |
sel := #max:. |
|
6291 |
rec perform:sel withOptionalArgument:2. |
|
6292 |
" |
|
6316 | 6293 |
! |
6294 |
||
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6295 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6296 |
"send aSelector-message to the receiver. |
6728 | 6297 |
Depending on the number of arguments the message expects, |
6298 |
pass either none, 1, or 2 arguments." |
|
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6299 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6300 |
|numArgs| |
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 |
numArgs := aSelector numArgs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6303 |
numArgs == 0 ifTrue:[ |
14975 | 6304 |
^ self perform:aSelector |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6305 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6306 |
numArgs == 1 ifTrue:[ |
14975 | 6307 |
^ self perform:aSelector with:optionalArg1 |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6308 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6309 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2. |
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 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6312 |
|rec sel| |
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 |
rec := -1. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6315 |
sel := #abs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6316 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6317 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6318 |
sel := #max:. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6319 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6320 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6321 |
! |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6322 |
|
6728 | 6323 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 |
6324 |
"send aSelector-message to the receiver. |
|
6325 |
Depending on the number of arguments the message expects, |
|
6326 |
pass either none, 1, 2 or 3 arguments." |
|
6327 |
||
6328 |
|numArgs| |
|
6329 |
||
6330 |
numArgs := aSelector numArgs. |
|
6331 |
numArgs == 0 ifTrue:[ |
|
14975 | 6332 |
^ self perform:aSelector |
6728 | 6333 |
]. |
6334 |
numArgs == 1 ifTrue:[ |
|
14975 | 6335 |
^ self perform:aSelector with:optionalArg1 |
6728 | 6336 |
]. |
6337 |
numArgs == 2 ifTrue:[ |
|
14975 | 6338 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6728 | 6339 |
]. |
6340 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3. |
|
6341 |
||
6342 |
" |
|
6343 |
|rec sel| |
|
6344 |
||
6345 |
rec := -1. |
|
6346 |
sel := #abs. |
|
6347 |
rec perform:sel withOptionalArgument:2. |
|
6348 |
||
6349 |
sel := #max:. |
|
6350 |
rec perform:sel withOptionalArgument:2. |
|
6351 |
" |
|
6352 |
! |
|
6353 |
||
6764 | 6354 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 and:optionalArg4 |
6355 |
"send aSelector-message to the receiver. |
|
6356 |
Depending on the number of arguments the message expects, |
|
6357 |
pass either none, 1, 2, 3 or 4 arguments." |
|
6358 |
||
6359 |
|numArgs| |
|
6360 |
||
6361 |
numArgs := aSelector numArgs. |
|
6362 |
numArgs == 0 ifTrue:[ |
|
14975 | 6363 |
^ self perform:aSelector |
6764 | 6364 |
]. |
6365 |
numArgs == 1 ifTrue:[ |
|
14975 | 6366 |
^ self perform:aSelector with:optionalArg1 |
6764 | 6367 |
]. |
6368 |
numArgs == 2 ifTrue:[ |
|
14975 | 6369 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6764 | 6370 |
]. |
6371 |
numArgs == 3 ifTrue:[ |
|
14975 | 6372 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 |
6764 | 6373 |
]. |
6374 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 with:optionalArg4. |
|
6375 |
||
6376 |
" |
|
6377 |
|rec sel| |
|
6378 |
||
6379 |
rec := -1. |
|
6380 |
sel := #abs. |
|
6381 |
rec perform:sel withOptionalArgument:2. |
|
6382 |
||
6383 |
sel := #max:. |
|
6384 |
rec perform:sel withOptionalArgument:2. |
|
6385 |
" |
|
6386 |
! |
|
6387 |
||
5755 | 6388 |
performMethod:aMethod |
6389 |
"invoke aMethod on the receiver. |
|
6390 |
The method should be a zero-argument method. |
|
6391 |
This is a non-object-oriented entry, applying a method |
|
6392 |
in a functional way on a receiver. |
|
6393 |
Warning: |
|
14975 | 6394 |
Take care for the method to be appropriate for the |
6395 |
receiver - no checking is done by the VM." |
|
5755 | 6396 |
|
6397 |
^ aMethod valueWithReceiver:self arguments:#() |
|
6398 |
||
6399 |
" |
|
6400 |
|mthd| |
|
6401 |
||
6402 |
mthd := SmallInteger compiledMethodAt:#negated. |
|
6403 |
Transcript showCR:(1 performMethod:mthd) |
|
6404 |
" |
|
6405 |
||
6406 |
"BAD USE example: |
|
6407 |
||
6408 |
|mthd| |
|
6409 |
||
6410 |
mthd := Point compiledMethodAt:#x. |
|
6411 |
Transcript showCR:((1->2) performMethod:mthd) |
|
6412 |
" |
|
6413 |
||
6414 |
"Modified: 31.7.1997 / 17:41:50 / cg" |
|
6415 |
! |
|
6416 |
||
6417 |
performMethod:aMethod arguments:argumentArray |
|
6418 |
"invoke aMethod on the receiver, passing an argumentArray. |
|
6419 |
The size of the argumentArray should match the number of args |
|
6420 |
expected by the method. |
|
6421 |
This is a non-object-oriented entry, applying a method |
|
6422 |
in a functional way on a receiver. |
|
6423 |
Warning: |
|
14975 | 6424 |
Take care for the method to be appropriate for the |
6425 |
receiver - no checking is done by the VM." |
|
5755 | 6426 |
|
6427 |
^ aMethod valueWithReceiver:self arguments:argumentArray |
|
6428 |
||
6429 |
" |
|
6430 |
|mthd| |
|
6431 |
||
6432 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6433 |
Transcript showCR:(1 performMethod:mthd arguments:#(2)) |
|
6434 |
" |
|
6435 |
||
6436 |
"Created: 31.7.1997 / 17:46:31 / cg" |
|
6437 |
! |
|
6438 |
||
6439 |
performMethod:aMethod with:arg |
|
6440 |
"invoke aMethod on the receiver, passing an argument. |
|
6441 |
The method should be a one-argument method. |
|
6442 |
This is a non-object-oriented entry, applying a method |
|
6443 |
in a functional way on a receiver. |
|
6444 |
Warning: |
|
14975 | 6445 |
Take care for the method to be appropriate for the |
6446 |
receiver - no checking is done by the VM." |
|
5755 | 6447 |
|
6448 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg) |
|
6449 |
||
6450 |
" |
|
6451 |
|mthd| |
|
6452 |
||
6453 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6454 |
Transcript showCR:(1 performMethod:mthd with:2) |
|
6455 |
" |
|
6456 |
||
6457 |
"Modified: 31.7.1997 / 17:42:32 / cg" |
|
6458 |
! |
|
6459 |
||
6460 |
performMethod:aMethod with:arg1 with:arg2 |
|
6461 |
"invoke aMethod on the receiver, passing two arguments. |
|
6462 |
The method should be a two-argument method. |
|
6463 |
This is a non-object-oriented entry, applying a method |
|
6464 |
in a functional way on a receiver. |
|
6465 |
Warning: |
|
14975 | 6466 |
Take care for the method to be appropriate for the |
6467 |
receiver - no checking is done by the VM." |
|
5755 | 6468 |
|
6469 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) |
|
6470 |
||
6471 |
" |
|
6472 |
|mthd arr| |
|
6473 |
||
6474 |
arr := Array new:1. |
|
6475 |
mthd := Array compiledMethodAt:#basicAt:put:. |
|
6476 |
arr performMethod:mthd with:1 with:'foo'. |
|
6477 |
Transcript showCR:arr |
|
6478 |
" |
|
6479 |
||
6480 |
"Modified: 31.7.1997 / 17:44:54 / cg" |
|
6481 |
! |
|
6482 |
||
6483 |
performMethod:aMethod with:arg1 with:arg2 with:arg3 |
|
6484 |
"invoke aMethod on the receiver, passing three arguments. |
|
6485 |
The method should be a three-argument method. |
|
6486 |
This is a non-object-oriented entry, applying a method |
|
6487 |
in a functional way on a receiver. |
|
6488 |
Warning: |
|
14975 | 6489 |
Take care for the method to be appropriate for the |
6490 |
receiver - no checking is done by the VM." |
|
5755 | 6491 |
|
6492 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3) |
|
6493 |
||
6494 |
"Created: 31.7.1997 / 17:45:20 / cg" |
|
6495 |
! ! |
|
6496 |
||
10834 | 6497 |
!Object methodsFor:'object persistency'! |
6498 |
||
6499 |
elementDescriptorFor:anAspectSymbol |
|
6500 |
"support for persistency: |
|
6501 |
answer a collection of associations containing the |
|
6502 |
objects state to be encoded for aspect. |
|
6503 |
Association key is the instance variable name or access selector, |
|
6504 |
association value is the contents of the instance variable. |
|
6505 |
||
6506 |
The default is to return the contents of all non-nil instance variables" |
|
6507 |
||
6508 |
|ret| |
|
6509 |
||
6510 |
ret := 0. |
|
6511 |
anAspectSymbol notNil ifTrue:[ |
|
14975 | 6512 |
ret := self perform:anAspectSymbol ifNotUnderstood:[0]. |
10834 | 6513 |
]. |
6514 |
ret == 0 ifTrue:[ |
|
14975 | 6515 |
^ self elementDescriptorForNonNilInstanceVariables |
10834 | 6516 |
]. |
6517 |
^ ret. |
|
6518 |
! |
|
6519 |
||
6520 |
elementDescriptorForInstanceVariables |
|
6521 |
"return all instance variables for visiting/encoding" |
|
6522 |
||
6523 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
|
6524 |
||
6525 |
" |
|
6526 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
6527 |
Dictionary new elementDescriptorForInstanceVariables |
|
6528 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
6529 |
" |
|
6530 |
! |
|
6531 |
||
6532 |
elementDescriptorForInstanceVariablesMatching:aBlock |
|
6533 |
"return all instance variables which conform to aBlock, for encoding/visiting. |
|
6534 |
Indexed vars are all included." |
|
6535 |
||
6536 |
|instVarNames theClass children |
|
6537 |
instSize "{ Class: SmallInteger }" |
|
6538 |
varSize "{ Class: SmallInteger }"| |
|
6539 |
||
6540 |
theClass := self class. |
|
6541 |
||
6542 |
instSize := theClass instSize. |
|
6543 |
varSize := theClass isVariable ifTrue:[self basicSize] ifFalse:[0]. |
|
6544 |
children := OrderedCollection new:(instSize + varSize). |
|
6545 |
||
6546 |
instVarNames := theClass allInstVarNames. |
|
6547 |
1 to:instSize do:[:i | |var| |
|
14975 | 6548 |
var := self instVarAt:i. |
6549 |
(aBlock value:var) ifTrue:[ |
|
6550 |
children add:((instVarNames at:i) -> var) |
|
6551 |
] |
|
10834 | 6552 |
]. |
6553 |
||
6554 |
varSize ~~ 0 ifTrue:[ |
|
14975 | 6555 |
1 to:varSize do:[:i | |
6556 |
children add:(i -> (self basicAt:i)) |
|
6557 |
] |
|
10834 | 6558 |
]. |
6559 |
||
6560 |
^ children. |
|
6561 |
||
6562 |
" |
|
6563 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
6564 |
Dictionary new elementDescriptorForInstanceVariables |
|
6565 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
6566 |
" |
|
6567 |
! |
|
6568 |
||
6569 |
elementDescriptorForNonNilInstanceVariables |
|
6570 |
"return all non-nil instance variables for visiting/encoding" |
|
6571 |
||
6572 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | val notNil]. |
|
6573 |
||
6574 |
" |
|
6575 |
#(1 2 3 nil true symbol) elementDescriptorForNonNilInstanceVariables |
|
6576 |
Dictionary new elementDescriptorForNonNilInstanceVariables |
|
6577 |
(5 @ nil) elementDescriptorForNonNilInstanceVariables |
|
6578 |
" |
|
6579 |
! ! |
|
6580 |
||
5755 | 6581 |
!Object methodsFor:'printing & storing'! |
6582 |
||
6235 | 6583 |
basicPrintOn:aStream |
6584 |
"append the receivers className with an articel to the argument, aStream" |
|
6585 |
||
6586 |
aStream nextPutAll:self classNameWithArticle |
|
6587 |
! |
|
6588 |
||
5755 | 6589 |
className |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
6590 |
"return the classname of the receiver's class" |
5755 | 6591 |
|
6592 |
^ self class name |
|
6593 |
||
6594 |
" |
|
6595 |
1 className |
|
10460 | 6596 |
1 class className |
5755 | 6597 |
$a className |
9105 | 6598 |
$a class className |
5755 | 6599 |
" |
6600 |
! |
|
6601 |
||
6602 |
classNameWithArticle |
|
6603 |
"return a string consisting of classname preceeded by an article. |
|
6604 |
(dont expect me to write national variants for this ... :-) |
|
6605 |
If you have special preferences, redefine it ..." |
|
6606 |
||
6829 | 6607 |
| cls| |
5755 | 6608 |
|
6609 |
(cls := self class) == self ifTrue:[ |
|
14975 | 6610 |
^ 'a funny object' |
5755 | 6611 |
]. |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
6612 |
cls isNil ifTrue:[ |
14975 | 6613 |
^ 'a nil-classes object' "/ cannot happen |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
6614 |
]. |
6829 | 6615 |
^ cls nameWithArticle |
5755 | 6616 |
|
6617 |
" |
|
10460 | 6618 |
1 classNameWithArticle |
6619 |
(1->2) classNameWithArticle |
|
5755 | 6620 |
XWorkstation basicNew classNameWithArticle |
10460 | 6621 |
XWorkstation classNameWithArticle |
5755 | 6622 |
" |
6623 |
||
6624 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
6625 |
! |
|
6626 |
||
6627 |
errorPrint |
|
12703 | 6628 |
"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
|
6629 |
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
|
6630 |
headless applications." |
5755 | 6631 |
|
14165 | 6632 |
Stderr isNil ifTrue:[ |
14661 | 6633 |
"/ the following allows errorPrint to be used during |
6634 |
"/ the early init-phase, when no Stderr has been set up. |
|
6635 |
"/ (depends on string to respond to #errorPrint) |
|
6636 |
self printString utf8Encoded errorPrint. |
|
6637 |
^ self. |
|
14165 | 6638 |
]. |
6639 |
||
13350 | 6640 |
self withErrorStreamDo:[:s | self printOn:s]. |
6641 |
||
6642 |
"Modified: / 21-04-2011 / 12:46:42 / cg" |
|
5755 | 6643 |
! |
6644 |
||
6645 |
errorPrintCR |
|
6646 |
"{ Pragma: +optSpace }" |
|
6647 |
||
12703 | 6648 |
"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
|
6649 |
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
|
6650 |
headless applications." |
5755 | 6651 |
|
14165 | 6652 |
Stderr isNil ifTrue:[ |
14661 | 6653 |
"/ the following allows errorPrintCR to be used during |
6654 |
"/ the early init-phase, when no Stderr has been set up. |
|
6655 |
"/ (depends on string to respond to #errorPrintCR) |
|
6656 |
self printString utf8Encoded errorPrintCR. |
|
6657 |
^ self. |
|
14165 | 6658 |
]. |
6659 |
||
13350 | 6660 |
self withErrorStreamDo:[:s | self printOn:s. s cr]. |
6661 |
||
6662 |
" |
|
6663 |
'hello' errorPrintCR |
|
6664 |
" |
|
5755 | 6665 |
|
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6666 |
"Created: / 20-05-1996 / 10:20:41 / cg" |
13350 | 6667 |
"Modified: / 21-04-2011 / 12:47:13 / cg" |
5755 | 6668 |
! |
6669 |
||
6670 |
errorPrintNL |
|
6671 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6672 |
<resource:#obsolete> |
5755 | 6673 |
|
6674 |
"print the receiver followed by a cr on the standard error stream. |
|
6675 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6676 |
||
6677 |
^ self errorPrintCR |
|
6678 |
||
6679 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
6680 |
! |
|
6681 |
||
6682 |
errorPrintNewline |
|
6683 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6684 |
<resource:#obsolete> |
5755 | 6685 |
|
6686 |
"print the receiver followed by a cr on the standard error stream. |
|
6687 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6688 |
||
6689 |
self errorPrintCR. |
|
6690 |
||
6691 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
6692 |
! |
|
6693 |
||
6694 |
infoPrint |
|
6695 |
"{ Pragma: +optSpace }" |
|
6696 |
||
6697 |
"print the receiver on the standard error stream. |
|
6698 |
This is meant for information messages which are not warnings |
|
6699 |
or fatal messages. |
|
6700 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6701 |
||
6702 |
InfoPrinting == true ifTrue:[ |
|
14975 | 6703 |
self errorPrint |
5755 | 6704 |
] |
6705 |
! |
|
6706 |
||
6707 |
infoPrintCR |
|
6708 |
"{ Pragma: +optSpace }" |
|
6709 |
||
6710 |
"print the receiver followed by a cr on the standard error stream. |
|
6711 |
This is meant for information messages which are not warnings |
|
6712 |
or fatal messages. |
|
6713 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6714 |
||
6715 |
InfoPrinting == true ifTrue:[ |
|
14975 | 6716 |
self errorPrintCR |
5755 | 6717 |
] |
6718 |
||
6719 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
6720 |
! |
|
6721 |
||
6722 |
infoPrintNL |
|
6723 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6724 |
<resource:#obsolete> |
5755 | 6725 |
|
6726 |
"print the receiver followed by a cr on the standard error stream. |
|
6727 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
6728 |
||
6729 |
^ self infoPrintCR |
|
6730 |
! |
|
6731 |
||
6732 |
||
6733 |
"print the receiver on the standard output stream (which is not the Transcript)" |
|
6734 |
||
6735 |
"/ the following allows printCR to be used during |
|
6736 |
"/ the early init-phase, when no Stdout has been set up. |
|
6737 |
"/ (depends on string to respond to #print) |
|
6738 |
||
6739 |
Stdout isNil ifTrue:[ |
|
14661 | 6740 |
self printString utf8Encoded print. |
6741 |
^ self |
|
5755 | 6742 |
]. |
6743 |
self printOn:Stdout |
|
6744 |
||
6745 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
6746 |
! |
|
6747 |
||
6748 |
printCR |
|
6749 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
|
6750 |
||
6751 |
"/ the following allows printCR to be used during |
|
6752 |
"/ the early init-phase, when no Stdout has been set up. |
|
6753 |
"/ (depends on string to respond to #printCR) |
|
6754 |
||
6755 |
Stdout isNil ifTrue:[ |
|
14661 | 6756 |
self printString utf8Encoded printCR. |
6757 |
^ self |
|
5755 | 6758 |
]. |
6759 |
self printOn:Stdout. |
|
6760 |
Stdout cr |
|
6761 |
||
6762 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
6763 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
|
6764 |
! |
|
6765 |
||
6766 |
printNL |
|
6767 |
"print the receiver followed by a cr on the standard output stream |
|
6768 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
6769 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6770 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6771 |
|
5755 | 6772 |
^ self printCR |
6773 |
||
6774 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
6775 |
! |
|
6776 |
||
6777 |
printNewline |
|
6778 |
"print the receiver followed by a cr on the standard output stream. |
|
6779 |
This exists for backward compatibility - please use #printCR." |
|
6780 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6781 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6782 |
|
5755 | 6783 |
self printCR |
6784 |
||
6785 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
6786 |
! |
|
6787 |
||
6788 |
printOn:aStream |
|
6789 |
"append a user printed representation of the receiver to aStream. |
|
6790 |
The format is suitable for a human - not meant to be read back. |
|
6791 |
||
6792 |
The default here is to output the receivers class name. |
|
6793 |
BUT: this method is heavily redefined for objects which |
|
6794 |
can print prettier." |
|
6795 |
||
6235 | 6796 |
self basicPrintOn:aStream. |
6797 |
||
6798 |
" |
|
6799 |
(1@2) printOn:Transcript |
|
6800 |
(1@2) basicPrintOn:Transcript |
|
6801 |
" |
|
5755 | 6802 |
! |
6803 |
||
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6804 |
printOn:aStream format:format |
11335 | 6805 |
"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
|
6806 |
Defined here for compatibility with subclasses" |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6807 |
|
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6808 |
self printOn:aStream. |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6809 |
! |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6810 |
|
5755 | 6811 |
printOn:aStream leftPaddedTo:size |
6812 |
"print the receiver on aStream, padding with spaces up to size. |
|
6813 |
padding is done on the left." |
|
6814 |
||
6815 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
6816 |
||
6817 |
" |
|
6818 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
6819 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
6820 |
" |
|
6821 |
! |
|
6822 |
||
6823 |
printOn:aStream leftPaddedTo:size with:padCharacter |
|
6824 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
6825 |
padding is done on the left." |
|
6826 |
||
6827 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
6828 |
||
6829 |
" |
|
6830 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
6831 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
6832 |
" |
|
6833 |
! |
|
6834 |
||
6835 |
printOn:aStream paddedTo:size |
|
6836 |
"print the receiver on aStream, padding with spaces up to size." |
|
6837 |
||
6838 |
self printOn:aStream paddedTo:size with:(Character space) |
|
6839 |
||
6840 |
" |
|
6841 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
6842 |
" |
|
6843 |
! |
|
6844 |
||
6845 |
printOn:aStream paddedTo:size with:padCharacter |
|
6846 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
6847 |
||
6848 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
6849 |
||
6850 |
" |
|
6851 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
6852 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
6853 |
" |
|
6854 |
! |
|
6855 |
||
6856 |
printOn:aStream zeroPaddedTo:size |
|
6857 |
"print the receiver on aStream, padding with zeros up to size. |
|
6858 |
Usually used with float numbers." |
|
6859 |
||
6860 |
self printOn:aStream paddedTo:size with:$0. |
|
6861 |
||
6862 |
" |
|
6863 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
6864 |
" |
|
6865 |
! |
|
6866 |
||
6867 |
printRightAdjustLen:size |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6868 |
<resource: #obsolete> |
5755 | 6869 |
"obsolete - just a name confusion. |
6870 |
This method will go away ..." |
|
6871 |
||
6872 |
(self printStringLeftPaddedTo:size) printOn:Stdout |
|
6873 |
! |
|
6874 |
||
6875 |
printString |
|
6876 |
"return a string for printing the receiver. |
|
6877 |
Since we now use printOn: as the basic print mechanism, |
|
6878 |
we have to create a stream and print into it." |
|
6879 |
||
6880 |
|s| |
|
6881 |
||
11790
6dcd44bc2ff9
Larger default for #printString
Stefan Vogel <sv@exept.de>
parents:
11738
diff
changeset
|
6882 |
s := CharacterWriteStream on:(String basicNew:40). "allocate at least 46 bytes for fast UUID conversion" |
5755 | 6883 |
self printOn:s. |
8300
d15ead94361f
Use CharacterWriteStream in #printString (speedup)
Stefan Vogel <sv@exept.de>
parents:
8287
diff
changeset
|
6884 |
^ s contents. |
7978
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6885 |
|
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6886 |
" |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6887 |
Date today printString. |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6888 |
" |
5755 | 6889 |
! |
6890 |
||
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6891 |
printStringFormat:orintFormat |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6892 |
"subclasses may redefine this. |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6893 |
Defined here to avoid type checks" |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6894 |
|
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6895 |
^ self printString |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6896 |
! |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6897 |
|
5755 | 6898 |
printStringLeftPaddedTo:size |
6899 |
"return my printString as a right-adjusted string of length size; |
|
6900 |
characters on the left are filled with spaces. |
|
10460 | 6901 |
If the printString is longer than size, |
5755 | 6902 |
it is returned unchanged (i.e. not truncated)" |
6903 |
||
6904 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
6905 |
||
6906 |
" |
|
6907 |
10 printStringLeftPaddedTo:10 |
|
6908 |
1 printStringLeftPaddedTo:10 |
|
6909 |
" |
|
6910 |
! |
|
6911 |
||
6912 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
6913 |
"return my printString as a right-adjusted string of length size; |
|
6914 |
characters on the left are filled with spaces. |
|
6915 |
If the printString is larger than size, |
|
6916 |
return the result from evaluating alternative." |
|
6917 |
||
6918 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
6919 |
||
6920 |
" |
|
6921 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6922 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6923 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6924 |
" |
|
6925 |
! |
|
6926 |
||
6927 |
printStringLeftPaddedTo:size with:padCharacter |
|
6928 |
"return my printString as a right-adjusted string of length size; |
|
6929 |
characters on the left are filled with padCharacter. |
|
10460 | 6930 |
If the printString is longer than size, |
5755 | 6931 |
it is returned unchanged (i.e. not truncated)" |
6932 |
||
6933 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
6934 |
||
6935 |
" |
|
10460 | 6936 |
123 printStringLeftPaddedTo:10 with:$. |
6937 |
1 printStringLeftPaddedTo:10 with:$. |
|
5755 | 6938 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
6939 |
" |
|
6940 |
! |
|
6941 |
||
6942 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
6943 |
"return my printString as a right-adjusted string of length size; |
|
6944 |
characters on the left are filled with padCharacter. |
|
6945 |
If the printString is larger than size, |
|
6946 |
return the result from evaluating alternative." |
|
6947 |
||
6948 |
|s| |
|
6949 |
||
6950 |
s := self printString. |
|
6951 |
s size > size ifTrue:[^ alternative value]. |
|
6952 |
^ s leftPaddedTo:size with:padCharacter |
|
6953 |
||
6954 |
" |
|
10460 | 6955 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
6956 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6957 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
5755 | 6958 |
" |
6959 |
! |
|
6960 |
||
8576 | 6961 |
printStringLimitedTo:sizeLimit |
6962 |
"return a string for printing the receiver, but limit the result string in its size." |
|
6963 |
||
6964 |
|s| |
|
6965 |
||
6966 |
s := CharacterWriteStream on:(String basicNew:30). |
|
6967 |
s writeLimit:sizeLimit. |
|
6968 |
self printOn:s. |
|
6969 |
^ s contents. |
|
6970 |
||
6971 |
" |
|
6972 |
Date today printStringLimitedTo:5. |
|
10460 | 6973 |
'12345678901234567890' printStringLimitedTo:5. |
8576 | 6974 |
" |
6975 |
! |
|
6976 |
||
5755 | 6977 |
printStringOnError:exceptionBlock |
6978 |
"return a string for printing the receiver; if any error occurs, return the result from |
|
6979 |
evaluating exceptionBlock. Useful to print something in an exceptionHandler or other |
|
6980 |
cleanup code." |
|
6981 |
||
6982 |
|rslt| |
|
6983 |
||
6984 |
Error handle:[:ex | |
|
14975 | 6985 |
rslt := exceptionBlock value |
5755 | 6986 |
] do:[ |
14975 | 6987 |
rslt := self printString |
5755 | 6988 |
]. |
6989 |
^ rslt |
|
6990 |
! |
|
6991 |
||
6992 |
printStringPaddedTo:size |
|
6993 |
"return a printed representation of the receiver, |
|
6994 |
padded with spaces (at the right) up to size. |
|
10460 | 6995 |
If the printString is longer than size, |
5755 | 6996 |
it is returned unchanged (i.e. not truncated)" |
6997 |
||
6998 |
^ self printStringPaddedTo:size with:(Character space) |
|
6999 |
||
7000 |
" |
|
10460 | 7001 |
123 printStringPaddedTo:10 |
7002 |
1234567890123456 printStringPaddedTo:10 |
|
7003 |
'hello' printStringPaddedTo:10 |
|
5755 | 7004 |
" |
7005 |
! |
|
7006 |
||
7007 |
printStringPaddedTo:size ifLarger:alternative |
|
7008 |
"return a printed representation of the receiver, |
|
7009 |
padded with spaces (at the right) up to size. |
|
10460 | 7010 |
If the resulting printString is too large, |
5755 | 7011 |
return the result from evaluating alternative." |
7012 |
||
7013 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
7014 |
||
7015 |
" |
|
10460 | 7016 |
12 printStringPaddedTo:3 ifLarger:['***'] |
7017 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
7018 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
5755 | 7019 |
" |
7020 |
! |
|
7021 |
||
7022 |
printStringPaddedTo:size with:padCharacter |
|
7023 |
"return a printed representation of the receiver, |
|
7024 |
padded with padCharacter (at the right) up to size. |
|
10460 | 7025 |
If the printString is longer than size, |
5755 | 7026 |
it is returned unchanged (i.e. not truncated)" |
7027 |
||
7028 |
^ (self printString) paddedTo:size with:padCharacter |
|
7029 |
||
7030 |
" |
|
7031 |
123 printStringPaddedTo:10 with:$. |
|
7032 |
123 printStringPaddedTo:10 with:$* |
|
10460 | 7033 |
123 printStringPaddedTo:3 with:$* |
7034 |
1234 printStringPaddedTo:3 with:$* |
|
5755 | 7035 |
" |
7036 |
! |
|
7037 |
||
7038 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
7039 |
"return a printed representation of the receiver, |
|
7040 |
padded with padCharacter (at the right) up to size. |
|
10460 | 7041 |
If the resulting printString is too large, |
5755 | 7042 |
return the result from evaluating alternative." |
7043 |
||
7044 |
|s| |
|
7045 |
||
7046 |
s := self printString. |
|
7047 |
s size > size ifTrue:[^ alternative value]. |
|
7048 |
^ s paddedTo:size with:padCharacter |
|
7049 |
||
7050 |
" |
|
7051 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
7052 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
7053 |
" |
|
7054 |
! |
|
7055 |
||
7056 |
printStringRightAdjustLen:size |
|
7057 |
"obsolete - just a name confusion. |
|
7058 |
This method will go away ..." |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7059 |
<resource: #obsolete> |
5755 | 7060 |
|
7061 |
^ self printStringLeftPaddedTo:size |
|
7062 |
! |
|
7063 |
||
7064 |
printStringZeroPaddedTo:size |
|
10460 | 7065 |
"return a printed representation of the receiver, |
5755 | 7066 |
padded with zero (at the right) characters up to size. |
7067 |
Usually used with float numbers." |
|
7068 |
||
7069 |
^ self printStringPaddedTo:size with:$0 |
|
7070 |
||
7071 |
" |
|
10460 | 7072 |
123.0 printStringZeroPaddedTo:10 |
5755 | 7073 |
" |
7074 |
! |
|
7075 |
||
8287 | 7076 |
printfPrintString:ignoredFormat |
7077 |
"fallback to default printString |
|
7078 |
(for compatibility with float and integer-printing)" |
|
7079 |
||
7080 |
^ self printString |
|
7081 |
! |
|
7082 |
||
5755 | 7083 |
store |
7084 |
"store the receiver on standard output. |
|
7085 |
this method is useless, but included for compatibility." |
|
7086 |
||
7087 |
self storeOn:Stdout |
|
7088 |
! |
|
7089 |
||
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7090 |
storeArrayElementOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7091 |
"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
|
7092 |
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
|
7093 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7094 |
^ 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
|
7095 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7096 |
|
5755 | 7097 |
storeCR |
7098 |
"store the receiver on standard output; append a carriage return." |
|
7099 |
||
7100 |
self store. |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7101 |
Stdout cr. |
5755 | 7102 |
|
7103 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
7104 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
7105 |
! |
|
7106 |
||
7107 |
storeNl |
|
7108 |
"store the receiver on standard output; append a newline. |
|
7109 |
This method is included for backward compatibility- use #storeCR." |
|
7110 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7111 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7112 |
|
5755 | 7113 |
self storeCR. |
7114 |
||
7115 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
7116 |
! |
|
7117 |
||
7118 |
storeOn:aStream |
|
7119 |
"store the receiver on aStream; i.e. print an expression which will |
|
7120 |
reconstruct the receiver. |
|
7121 |
Notice, that no self referencing or cyclic objects can be represented |
|
7122 |
in this format. |
|
7123 |
Use storeBinaryOn:, which handles these cases correctly." |
|
7124 |
||
7125 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
7126 |
||
7127 |
thisContext isRecursive ifTrue:[ |
|
14975 | 7128 |
Object recursiveStoreStringSignal raiseRequestWith:self. |
7129 |
'Object [error]: storeString of self referencing object (' errorPrint. |
|
7130 |
self class name errorPrint. |
|
7131 |
')' errorPrintCR. |
|
7132 |
aStream nextPutAll:'#("recursive")'. |
|
7133 |
^ self |
|
5755 | 7134 |
]. |
7135 |
||
7136 |
myClass := self class. |
|
7137 |
aStream nextPut:$(. |
|
7138 |
aStream nextPutAll:self class name. |
|
7139 |
||
7140 |
hasSemi := false. |
|
7141 |
myClass isVariable ifTrue:[ |
|
14975 | 7142 |
aStream nextPutAll:' basicNew:'. |
7143 |
self basicSize printOn:aStream |
|
5755 | 7144 |
] ifFalse:[ |
14975 | 7145 |
aStream nextPutAll:' basicNew' |
5755 | 7146 |
]. |
7147 |
||
7148 |
sz := myClass instSize. |
|
10460 | 7149 |
1 to:sz do:[:i | |
14975 | 7150 |
aStream nextPutAll:' instVarAt:'. |
7151 |
i printOn:aStream. |
|
7152 |
aStream nextPutAll:' put:'. |
|
7153 |
(self instVarAt:i) storeOn:aStream. |
|
7154 |
aStream nextPut:$;. |
|
7155 |
hasSemi := true |
|
5755 | 7156 |
]. |
7157 |
myClass isVariable ifTrue:[ |
|
14975 | 7158 |
sz := self basicSize. |
7159 |
1 to:sz do:[:i | |
|
7160 |
aStream nextPutAll:' basicAt:'. |
|
7161 |
i printOn:aStream. |
|
7162 |
aStream nextPutAll:' put:'. |
|
7163 |
(self basicAt:i) storeOn:aStream. |
|
7164 |
aStream nextPut:$;. |
|
7165 |
hasSemi := true |
|
7166 |
] |
|
5755 | 7167 |
]. |
7168 |
hasSemi ifTrue:[ |
|
14975 | 7169 |
aStream nextPutAll:' yourself' |
5755 | 7170 |
]. |
7171 |
aStream nextPut:$). |
|
7172 |
||
7173 |
" |
|
7174 |
|s| |
|
7175 |
||
7176 |
s := WriteStream on:(String new). |
|
7177 |
('hello' -> 'world') storeOn:s. |
|
7178 |
s := ReadStream on:(s contents). |
|
7179 |
(Object readFrom:s) inspect |
|
7180 |
" |
|
7181 |
" |
|
7182 |
|s| |
|
7183 |
||
7184 |
s := 'data' asFilename writeStream. |
|
7185 |
('hello' -> 'world') storeOn:s. |
|
7186 |
s close. |
|
7187 |
||
7188 |
s := 'data' asFilename readStream. |
|
7189 |
(Object readFrom:s) inspect |
|
7190 |
" |
|
7191 |
||
7192 |
"does not work example:" |
|
7193 |
" |
|
7194 |
|s a| |
|
7195 |
||
7196 |
a := Array new:2. |
|
7197 |
a at:1 put:a. |
|
7198 |
||
7199 |
s := 'data' asFilename writeStream. |
|
7200 |
a storeOn:s. |
|
7201 |
s close. |
|
7202 |
||
7203 |
s := 'data' asFilename readStream. |
|
7204 |
(Object readFrom:s) inspect |
|
7205 |
" |
|
7206 |
||
13162 | 7207 |
"Modified: / 03-12-2010 / 13:27:51 / cg" |
5755 | 7208 |
! |
7209 |
||
7210 |
storeString |
|
7211 |
"return a string representing an expression to reconstruct the receiver. |
|
7212 |
Notice, that no self referencing or cyclic objects can be represented |
|
7213 |
in this format. |
|
7214 |
Use storeBinaryOn:, which handles these cases correctly." |
|
7215 |
||
7216 |
|s| |
|
7217 |
||
7218 |
s := WriteStream on:(String new:50). |
|
7219 |
self storeOn:s. |
|
7220 |
^ s contents |
|
13350 | 7221 |
! |
7222 |
||
7223 |
withErrorStreamDo:aBlock |
|
7224 |
"{ Pragma: +optSpace }" |
|
7225 |
||
14162 | 7226 |
"helper for error messages - evaluate aBlock, passing it a stream on which to put |
13350 | 7227 |
error messages." |
7228 |
||
13578
aa9827cafc2c
signalInterrupt: - tell which process was killed
Claus Gittinger <cg@exept.de>
parents:
13566
diff
changeset
|
7229 |
|stream| |
aa9827cafc2c
signalInterrupt: - tell which process was killed
Claus Gittinger <cg@exept.de>
parents:
13566
diff
changeset
|
7230 |
|
aa9827cafc2c
signalInterrupt: - tell which process was killed
Claus Gittinger <cg@exept.de>
parents:
13566
diff
changeset
|
7231 |
stream := Processor activeProcess isSystemProcess |
14975 | 7232 |
ifTrue:[Stderr] |
7233 |
ifFalse:[Transcript]. |
|
13350 | 7234 |
StreamError catch:[ |
14975 | 7235 |
aBlock value:stream. |
13578
aa9827cafc2c
signalInterrupt: - tell which process was killed
Claus Gittinger <cg@exept.de>
parents:
13566
diff
changeset
|
7236 |
]. |
14162 | 7237 |
stream ~~ Stderr ifTrue:[ |
14975 | 7238 |
aBlock value:Stderr. |
13350 | 7239 |
]. |
7240 |
||
7241 |
"Created: / 21-04-2011 / 12:46:21 / cg" |
|
5755 | 7242 |
! ! |
7243 |
||
7244 |
!Object methodsFor:'queries'! |
|
7245 |
||
7246 |
basicSize |
|
7247 |
"return the number of the receivers indexed instance variables, |
|
7248 |
0 if it has none. |
|
7249 |
||
7250 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
7251 |
||
7252 |
%{ /* NOCONTEXT */ |
|
7253 |
||
8909 | 7254 |
REGISTER INT nbytes; |
5755 | 7255 |
REGISTER OBJ myClass; |
7256 |
int nInstBytes; |
|
7257 |
||
7258 |
/* |
|
7259 |
* notice the missing test for self being a nonNilObject - |
|
7260 |
* this can be done since basicSize is defined both in UndefinedObject |
|
7261 |
* and SmallInteger |
|
7262 |
*/ |
|
7263 |
myClass = __qClass(self); |
|
7264 |
nbytes = __qSize(self); |
|
7265 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) ); |
|
7266 |
||
7267 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
14975 | 7268 |
case __MASKSMALLINT(POINTERARRAY): |
7269 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
7270 |
nbytes -= nInstBytes; |
|
7271 |
RETURN ( __mkSmallInteger(__BYTES2OBJS__(nbytes)) ); |
|
7272 |
||
7273 |
case __MASKSMALLINT(BYTEARRAY): |
|
7274 |
nbytes -= nInstBytes; |
|
7275 |
RETURN ( __mkSmallInteger(nbytes / sizeof(char)) ); |
|
7276 |
||
7277 |
case __MASKSMALLINT(FLOATARRAY): |
|
7278 |
nbytes -= nInstBytes; |
|
7279 |
RETURN ( __mkSmallInteger(nbytes / sizeof(float)) ); |
|
7280 |
||
7281 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 7282 |
#ifdef __NEED_DOUBLE_ALIGN |
14975 | 7283 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
5755 | 7284 |
#endif |
14975 | 7285 |
nbytes -= nInstBytes; |
7286 |
RETURN ( __mkSmallInteger(nbytes / sizeof(double)) ); |
|
7287 |
||
7288 |
case __MASKSMALLINT(WORDARRAY): |
|
7289 |
case __MASKSMALLINT(SWORDARRAY): |
|
7290 |
nbytes -= nInstBytes; |
|
7291 |
RETURN ( __mkSmallInteger(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */ |
|
7292 |
||
7293 |
case __MASKSMALLINT(LONGARRAY): |
|
7294 |
case __MASKSMALLINT(SLONGARRAY): |
|
7295 |
nbytes -= nInstBytes; |
|
7296 |
RETURN ( __mkSmallInteger(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */ |
|
7297 |
||
7298 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
7299 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 7300 |
#ifdef __NEED_LONGLONG_ALIGN |
14975 | 7301 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
5755 | 7302 |
#endif |
14975 | 7303 |
nbytes -= nInstBytes; |
7304 |
RETURN ( __mkSmallInteger(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */ |
|
5755 | 7305 |
} |
7306 |
%}. |
|
7307 |
^ 0 |
|
7308 |
! |
|
7309 |
||
7310 |
byteSize |
|
7311 |
"return the number of bytes in the receivers indexed instance variables, |
|
7312 |
0 if it has none. This only returns non-zero for non-pointer indexed |
|
7313 |
instvars i.e. byteArrays, wordArrays etc. |
|
7314 |
Notice: for Strings the returned size may look strange. |
|
7315 |
Only useful with binary storage." |
|
7316 |
||
7317 |
|myClass| |
|
7318 |
||
7319 |
myClass := self class. |
|
7320 |
myClass isVariable ifTrue:[ |
|
14975 | 7321 |
myClass isPointers ifFalse:[ |
7322 |
myClass isBytes ifTrue:[ |
|
7323 |
^ self basicSize. |
|
7324 |
]. |
|
7325 |
myClass isWords ifTrue:[ |
|
7326 |
^ self basicSize * 2. |
|
7327 |
]. |
|
7328 |
myClass isSignedWords ifTrue:[ |
|
7329 |
^ self basicSize * 2. |
|
7330 |
]. |
|
7331 |
myClass isLongs ifTrue:[ |
|
7332 |
^ self basicSize * 4. |
|
7333 |
]. |
|
7334 |
myClass isSignedLongs ifTrue:[ |
|
7335 |
^ self basicSize * 4. |
|
7336 |
]. |
|
7337 |
myClass isLongLongs ifTrue:[ |
|
7338 |
^ self basicSize * 8. |
|
7339 |
]. |
|
7340 |
myClass isSignedLongLongs ifTrue:[ |
|
7341 |
^ self basicSize * 8. |
|
7342 |
]. |
|
7343 |
myClass isFloats ifTrue:[ |
|
7344 |
^ self basicSize * (ExternalBytes sizeofFloat) |
|
7345 |
]. |
|
7346 |
myClass isDoubles ifTrue:[ |
|
7347 |
^ self basicSize * (ExternalBytes sizeofDouble) |
|
7348 |
]. |
|
7349 |
self error:'unknown variable size class species'. |
|
7350 |
] |
|
5755 | 7351 |
]. |
7352 |
^ 0 |
|
7353 |
||
7354 |
" |
|
10460 | 7355 |
Point new byteSize |
14632 | 7356 |
'hello' byteSize |
7357 |
'hello' asUnicode16String byteSize |
|
10460 | 7358 |
(ByteArray with:1 with:2) byteSize |
7359 |
(FloatArray with:1.5) byteSize |
|
7360 |
(DoubleArray with:1.5) byteSize |
|
7361 |
(WordArray with:1 with:2) byteSize |
|
5755 | 7362 |
" |
7363 |
! |
|
7364 |
||
7365 |
class |
|
7366 |
"return the receivers class" |
|
7367 |
||
7368 |
%{ /* NOCONTEXT */ |
|
7369 |
||
7370 |
RETURN ( __Class(self) ); |
|
7371 |
%} |
|
7372 |
! |
|
7373 |
||
7374 |
respondsTo:aSelector |
|
7375 |
"return true, if the receiver implements a method with selector equal |
|
7376 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
7377 |
receivers class or one of its superclasses. |
|
7378 |
||
7379 |
Notice, that this does not imply, that such a message can be sent without |
|
7380 |
an error being raised. For example, an implementation could send |
|
7381 |
#shouldNotImplement or #subclassResponsibility." |
|
7382 |
||
7383 |
" |
|
7384 |
should we go via the cache, or search (by class) ? |
|
7385 |
The first is faster, most of the time; while the 2nd fills |
|
7386 |
the cache with useless data if this is sent in a loop over all objects. |
|
7387 |
For now, use the cache ... |
|
7388 |
" |
|
7389 |
%{ /* NOCONTEXT */ |
|
7390 |
||
7391 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
14975 | 7392 |
RETURN ( false ); |
5755 | 7393 |
} |
7394 |
RETURN ( true ); |
|
7395 |
%} |
|
7396 |
. |
|
7397 |
^ self class canUnderstand:aSelector |
|
7398 |
||
7399 |
||
7400 |
"'aString' respondsTo:#+" |
|
7401 |
"'aString' respondsTo:#," |
|
7402 |
"'aString' respondsTo:#collect:" |
|
7403 |
! |
|
7404 |
||
7405 |
respondsToArithmetic |
|
7406 |
"return true, if the receiver responds to arithmetic messages. |
|
7407 |
false is returned here - the method is redefined in ArithmeticValue." |
|
7408 |
||
7409 |
^ false |
|
7410 |
! |
|
7411 |
||
7412 |
size |
|
7413 |
"return the number of the receivers indexed instance variables; |
|
7414 |
this method may be redefined in subclasses" |
|
7415 |
||
7416 |
^ self basicSize |
|
7417 |
! |
|
7418 |
||
7419 |
species |
|
7420 |
"return a class which is similar to (or the same as) the receivers class. |
|
7421 |
This is used to create an appropriate object when creating derived |
|
7422 |
copies in the collection classes (sometimes redefined)." |
|
7423 |
||
7424 |
^ self class |
|
7425 |
! |
|
7426 |
||
7427 |
yourself |
|
7428 |
"return the receiver - used for cascades to return self at the end" |
|
7429 |
||
7430 |
^ self |
|
7431 |
! ! |
|
7432 |
||
15193 | 7433 |
|
5755 | 7434 |
!Object methodsFor:'secure message sending'! |
7435 |
||
13099 | 7436 |
?: selector |
7437 |
"try to send a message to the receiver; |
|
7438 |
if understood, return the value; |
|
7439 |
if not, return nil." |
|
7440 |
||
7441 |
^ self perform:selector ifNotUnderstood:nil |
|
7442 |
||
7443 |
" |
|
7444 |
ApplicationModel new masterApplication resources first - error |
|
7445 |
ApplicationModel new ?: #masterApplication ?: #resources ?: #first - nil |
|
7446 |
" |
|
7447 |
||
7448 |
"Modified: / 20-10-2010 / 10:45:21 / cg" |
|
7449 |
! |
|
7450 |
||
5755 | 7451 |
askFor:aSelector |
7452 |
"try to send the receiver the message, aSelector. |
|
10460 | 7453 |
If it does not understand it, return false. |
5755 | 7454 |
Otherwise the real value returned. |
11398 | 7455 |
Useful to send messages such as: #isColor to unknown receivers." |
5755 | 7456 |
|
7457 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
7458 |
||
7459 |
" |
|
10460 | 7460 |
1 askFor:#isColor |
7461 |
Color red askFor:#isColor |
|
7462 |
||
7463 |
1 askFor:#isFoo |
|
7464 |
Color red askFor:#isFoo |
|
5755 | 7465 |
" |
7466 |
! |
|
7467 |
||
11398 | 7468 |
askFor:aSelector with:argument |
7469 |
"try to send the receiver the message, aSelector. |
|
7470 |
If it does not understand it, return false. |
|
7471 |
Otherwise the real value returned. |
|
7472 |
Useful to send messages such as: #isXXX: to unknown receivers." |
|
7473 |
||
7474 |
^ self perform:aSelector with:argument ifNotUnderstood:[false] |
|
7475 |
! |
|
7476 |
||
11401 | 7477 |
askFor:aSelector with:arg1 with:arg2 |
7478 |
"try to send the receiver the message, aSelector. |
|
7479 |
If it does not understand it, return false. |
|
7480 |
Otherwise the real value returned. |
|
7481 |
Useful to send messages such as: #isXXX: to unknown receivers." |
|
7482 |
||
7483 |
^ self perform:aSelector with:arg1 with:arg2 ifNotUnderstood:[false] |
|
7484 |
! |
|
7485 |
||
5755 | 7486 |
perform:aSelector ifNotUnderstood:exceptionBlock |
7487 |
"try to send message aSelector to the receiver. |
|
12157 | 7488 |
If its understood, return the method's returned value, |
7489 |
otherwise return the value of the exceptionBlock. |
|
7490 |
Read this: |
|
7491 |
Many programmers do an Error-handle to perform a similar |
|
7492 |
checked-message send. However, this method is more specific, |
|
7493 |
in that only errors for the given selector are cought - not any other |
|
7494 |
doesNotUnderstand, and especially not any other error." |
|
5755 | 7495 |
|
7496 |
|val ok| |
|
7497 |
||
6146 | 7498 |
MessageNotUnderstood handle:[:ex | |
14975 | 7499 |
"/ reject, if the bad message is not the one |
7500 |
"/ we have sent originally |
|
7501 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
7502 |
ex reject |
|
7503 |
]. |
|
5755 | 7504 |
] do:[ |
14975 | 7505 |
val := self perform:aSelector. |
7506 |
ok := true. |
|
5755 | 7507 |
]. |
7508 |
ok isNil ifTrue:[ |
|
14975 | 7509 |
^ exceptionBlock value |
5755 | 7510 |
]. |
7511 |
^ val |
|
7512 |
||
7513 |
" |
|
10460 | 7514 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
7515 |
1.2345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7516 |
12345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
5755 | 7517 |
" |
7518 |
! |
|
7519 |
||
7520 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
7521 |
"try to send message aSelector to the receiver. |
|
12157 | 7522 |
If its understood, return the method's returned value, |
7523 |
otherwise return the value of the exceptionBlock. |
|
7524 |
Read this: |
|
7525 |
Many programmers do an Error-handle to perform a similar |
|
7526 |
checked-message send. However, this method is more specific, |
|
7527 |
in that only errors for the given selector are cought - not any other |
|
7528 |
doesNotUnderstand, and especially not any other error." |
|
5755 | 7529 |
|
7530 |
|val ok| |
|
7531 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7532 |
MessageNotUnderstood handle:[:ex | |
14975 | 7533 |
"/ reject, if the bad message is not the one |
7534 |
"/ we have sent originally |
|
7535 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
7536 |
ex reject |
|
7537 |
] |
|
5755 | 7538 |
] do:[ |
14975 | 7539 |
val := self perform:aSelector with:argument. |
7540 |
ok := true. |
|
5755 | 7541 |
]. |
7542 |
ok isNil ifTrue:[ |
|
14975 | 7543 |
^ exceptionBlock value |
5755 | 7544 |
]. |
7545 |
^ val |
|
7546 |
||
7547 |
" |
|
7548 |
|unknown| |
|
7549 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7550 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7551 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 7552 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7553 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 7554 |
" |
7555 |
! |
|
7556 |
||
5926 | 7557 |
perform:aSelector with:arg1 with:arg2 ifNotUnderstood:exceptionBlock |
7558 |
"try to send message aSelector to the receiver. |
|
12157 | 7559 |
If its understood, return the method's returned value, |
7560 |
otherwise return the value of the exceptionBlock. |
|
7561 |
Read this: |
|
7562 |
Many programmers do an Error-handle to perform a similar |
|
7563 |
checked-message send. However, this method is more specific, |
|
7564 |
in that only errors for the given selector are cought - not any other |
|
7565 |
doesNotUnderstand, and especially not any other error." |
|
5926 | 7566 |
|
7567 |
|val ok| |
|
7568 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7569 |
MessageNotUnderstood handle:[:ex | |
14975 | 7570 |
"/ reject, if the bad message is not the one |
7571 |
"/ we have sent originally |
|
7572 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
7573 |
ex reject |
|
7574 |
] |
|
5926 | 7575 |
] do:[ |
14975 | 7576 |
val := self perform:aSelector with:arg1 with:arg2. |
7577 |
ok := true. |
|
5926 | 7578 |
]. |
7579 |
ok isNil ifTrue:[ |
|
14975 | 7580 |
^ exceptionBlock value |
5926 | 7581 |
]. |
7582 |
^ val |
|
7583 |
! |
|
7584 |
||
5755 | 7585 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
7586 |
"try to send message aSelector to the receiver. |
|
12157 | 7587 |
If its understood, return the method's returned value, |
7588 |
otherwise return the value of the exceptionBlock. |
|
7589 |
Read this: |
|
7590 |
Many programmers do an Error-handle to perform a similar |
|
7591 |
checked-message send. However, this method is more specific, |
|
7592 |
in that only errors for the given selector are cought - not any other |
|
7593 |
doesNotUnderstand, and especially not any other error." |
|
5755 | 7594 |
|
7595 |
|val ok| |
|
7596 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7597 |
MessageNotUnderstood handle:[:ex | |
14975 | 7598 |
"/ reject, if the bad message is not the one |
7599 |
"/ we have sent originally. |
|
7600 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
7601 |
ex reject |
|
7602 |
] |
|
5755 | 7603 |
] do:[ |
14975 | 7604 |
val := self perform:aSelector withArguments:argumentArray. |
7605 |
ok := true. |
|
5755 | 7606 |
]. |
7607 |
ok isNil ifTrue:[ |
|
14975 | 7608 |
^ exceptionBlock value |
5755 | 7609 |
]. |
7610 |
^ val |
|
7611 |
||
7612 |
" |
|
7613 |
|unknown| |
|
7614 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7615 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7616 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 7617 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7618 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 7619 |
" |
7620 |
||
7621 |
"Modified: 27.3.1997 / 14:13:16 / cg" |
|
7622 |
! ! |
|
7623 |
||
7624 |
!Object methodsFor:'signal constants'! |
|
7625 |
||
7626 |
messageNotUnderstoodSignal |
|
6146 | 7627 |
^ MessageNotUnderstood |
5755 | 7628 |
|
7629 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
7630 |
! ! |
|
7631 |
||
7632 |
!Object methodsFor:'special queries'! |
|
7633 |
||
7634 |
allOwners |
|
7635 |
"return a collection of all objects referencing the receiver" |
|
7636 |
||
7637 |
^ ObjectMemory whoReferences:self |
|
7638 |
! |
|
7639 |
||
7640 |
references:anObject |
|
7641 |
"return true, if the receiver refers to the argument, anObject. |
|
7642 |
- for debugging only" |
|
7643 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7644 |
^ self referencesObject:anObject |
5755 | 7645 |
|
7646 |
" |
|
7647 |
|v| |
|
7648 |
||
7649 |
v := View new initialize. |
|
10460 | 7650 |
v references:Display. |
5755 | 7651 |
" |
7652 |
! |
|
7653 |
||
7654 |
referencesAny:aCollection |
|
10460 | 7655 |
"return true, if the receiver refers to any object from |
5755 | 7656 |
the argument, aCollection. |
7657 |
- for debugging only" |
|
7658 |
||
10460 | 7659 |
%{ |
5755 | 7660 |
OBJ cls, flags; |
7661 |
int nInsts, inst; |
|
7662 |
||
7663 |
if (! __isNonNilObject(self)) { |
|
14975 | 7664 |
RETURN (false); |
5755 | 7665 |
} |
7666 |
||
8934 | 7667 |
if (__isArrayLike(aCollection)) { |
14975 | 7668 |
int nObjs = __arraySize(aCollection); |
7669 |
char *minAddr = 0, *maxAddr = 0; |
|
7670 |
||
7671 |
if (nObjs == 0) { |
|
7672 |
RETURN (false); |
|
7673 |
} |
|
7674 |
||
7675 |
/* |
|
7676 |
* a little optimization: use the fact that all old objects |
|
7677 |
* refering to a new object are on the remSet; if I am not, |
|
7678 |
* a trivial reject is possible, if all objects are newbees. |
|
7679 |
* as a side effect, gather min/max addresses |
|
7680 |
*/ |
|
7681 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
7682 |
int allNewBees = 1; |
|
7683 |
int i; |
|
7684 |
||
7685 |
minAddr = (char *)(__ArrayInstPtr(aCollection)->a_element[0]); |
|
7686 |
maxAddr = minAddr; |
|
7687 |
||
7688 |
for (i=0; i<nObjs; i++) { |
|
7689 |
OBJ anObject; |
|
7690 |
||
7691 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7692 |
||
7693 |
if (__isNonNilObject(anObject)) { |
|
7694 |
int spc; |
|
7695 |
||
7696 |
if (((spc = __qSpace(anObject)) != NEWSPACE) && (spc != SURVSPACE)) { |
|
7697 |
allNewBees = 0; |
|
7698 |
} |
|
7699 |
} |
|
7700 |
||
7701 |
if ((char *)anObject < minAddr) { |
|
7702 |
minAddr = (char *)anObject; |
|
7703 |
} else if ((char *)anObject > maxAddr) { |
|
7704 |
maxAddr = (char *)anObject; |
|
7705 |
} |
|
7706 |
} |
|
7707 |
if (allNewBees) { |
|
7708 |
RETURN (false); |
|
7709 |
} |
|
7710 |
} |
|
7711 |
||
7712 |
/* |
|
7713 |
* fetch min/max in searchList (if not already done) |
|
7714 |
*/ |
|
7715 |
if (minAddr == 0) { |
|
7716 |
int i; |
|
7717 |
||
7718 |
for (i=0; i<nObjs; i++) { |
|
7719 |
OBJ anObject; |
|
7720 |
||
7721 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7722 |
if ((char *)anObject < minAddr) { |
|
7723 |
minAddr = (char *)anObject; |
|
7724 |
} else if ((char *)anObject > maxAddr) { |
|
7725 |
maxAddr = (char *)anObject; |
|
7726 |
} |
|
7727 |
} |
|
7728 |
} |
|
7729 |
||
7730 |
cls = __qClass(self); |
|
7731 |
if (((char *)cls >= minAddr) && ((char *)cls <= maxAddr)) { |
|
5755 | 7732 |
#if defined(memsrch4) |
14975 | 7733 |
if (memsrch4(__arrayVal(aCollection), (INT)cls, nObjs)) { |
7734 |
RETURN (true); |
|
7735 |
} |
|
5755 | 7736 |
#else |
14975 | 7737 |
int i; |
7738 |
||
7739 |
for (i=0; i<nObjs; i++) { |
|
7740 |
OBJ anObject; |
|
7741 |
||
7742 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7743 |
if (cls == anObject) { |
|
7744 |
RETURN (true); |
|
7745 |
} |
|
7746 |
} |
|
5755 | 7747 |
#endif /* memsrch4 */ |
14975 | 7748 |
} |
7749 |
||
7750 |
flags = __ClassInstPtr(cls)->c_flags; |
|
7751 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
7752 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
7753 |
} else { |
|
7754 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
7755 |
} |
|
7756 |
if (! nInsts) { |
|
7757 |
RETURN (false); |
|
7758 |
} |
|
7759 |
||
7760 |
if (nObjs == 1) { |
|
7761 |
/* better reverse the loop */ |
|
7762 |
OBJ anObject; |
|
7763 |
||
7764 |
anObject = __ArrayInstPtr(aCollection)->a_element[0]; |
|
5755 | 7765 |
#if defined(memsrch4) |
14975 | 7766 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
7767 |
RETURN (true); |
|
7768 |
} |
|
5755 | 7769 |
#else |
14975 | 7770 |
for (inst=0; inst<nInsts; inst++) { |
7771 |
if ((__InstPtr(self)->i_instvars[inst]) == anObject) { |
|
7772 |
RETURN (true); |
|
7773 |
} |
|
7774 |
} |
|
5755 | 7775 |
#endif |
14975 | 7776 |
RETURN (false); |
7777 |
} |
|
7778 |
||
7779 |
for (inst=0; inst<nInsts; inst++) { |
|
7780 |
OBJ instVar = __InstPtr(self)->i_instvars[inst]; |
|
7781 |
int i; |
|
7782 |
||
7783 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
5755 | 7784 |
#if defined(memsrch4) |
14975 | 7785 |
if (memsrch4(__arrayVal(aCollection), (INT)instVar, nObjs)) { |
7786 |
RETURN (true); |
|
7787 |
} |
|
5755 | 7788 |
#else |
14975 | 7789 |
for (i=0; i<nObjs; i++) { |
7790 |
OBJ anObject; |
|
7791 |
||
7792 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7793 |
if (instVar == anObject) { |
|
7794 |
RETURN (true); |
|
7795 |
} |
|
7796 |
} |
|
5755 | 7797 |
#endif /* memsrch4 */ |
14975 | 7798 |
} |
7799 |
} |
|
7800 |
RETURN (false); |
|
5755 | 7801 |
} |
7802 |
%}. |
|
7803 |
||
7804 |
aCollection do:[:el | |
|
14975 | 7805 |
(self referencesObject:el) ifTrue:[^ true]. |
5755 | 7806 |
]. |
7807 |
^ false |
|
7808 |
! |
|
7809 |
||
7810 |
referencesDerivedInstanceOf:aClass |
|
7811 |
"return true, if the receiver refers to an instance of |
|
7812 |
the argument, aClass or its subclass. This method exists |
|
7813 |
to support searching for users of a class." |
|
7814 |
||
10460 | 7815 |
|myClass |
5755 | 7816 |
numInst "{ Class: SmallInteger }" | |
7817 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7818 |
"check the class" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7819 |
(self isKindOf:aClass) ifTrue:[^ true]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7820 |
|
5755 | 7821 |
myClass := self class. |
7822 |
"check the instance variables" |
|
7823 |
numInst := myClass instSize. |
|
10460 | 7824 |
1 to:numInst do:[:i | |
14975 | 7825 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
5755 | 7826 |
]. |
7827 |
||
7828 |
"check the indexed variables" |
|
7829 |
myClass isVariable ifTrue:[ |
|
14975 | 7830 |
myClass isPointers ifFalse:[ |
7831 |
"no need to search in non pointer fields" |
|
7832 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
|
7833 |
]. |
|
7834 |
numInst := self basicSize. |
|
7835 |
1 to:numInst do:[:i | |
|
7836 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
7837 |
] |
|
5755 | 7838 |
]. |
7839 |
^ false |
|
7840 |
||
7841 |
" |
|
10460 | 7842 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
7843 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
7844 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
5755 | 7845 |
" |
7846 |
! |
|
7847 |
||
9279 | 7848 |
referencesForWhich:checkBlock do:actionBlock |
7849 |
|myClass inst |
|
7850 |
numInst "{ Class: SmallInteger }" | |
|
7851 |
||
7852 |
myClass := self class. |
|
7853 |
"check the instance variables" |
|
7854 |
numInst := myClass instSize. |
|
10460 | 7855 |
1 to:numInst do:[:i | |
14975 | 7856 |
inst := self instVarAt:i. |
7857 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
9279 | 7858 |
]. |
7859 |
||
7860 |
"check the indexed variables" |
|
7861 |
myClass isVariable ifTrue:[ |
|
14975 | 7862 |
myClass isPointers ifTrue:[ |
7863 |
"no need to search in non pointer fields" |
|
7864 |
||
7865 |
numInst := self basicSize. |
|
7866 |
1 to:numInst do:[:i | |
|
7867 |
inst := self basicAt:i. |
|
7868 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
7869 |
] |
|
7870 |
] |
|
10460 | 7871 |
]. |
7872 |
||
7873 |
" |
|
7874 |
(1 @ 3.4) referencesForWhich:[:i | i isFloat] do:[:i | Transcript showCR:i] |
|
9279 | 7875 |
" |
7876 |
! |
|
7877 |
||
5755 | 7878 |
referencesInstanceOf:aClass |
7879 |
"return true, if the receiver refers to an instance of |
|
7880 |
the argument, aClass.This method exists |
|
7881 |
to support searching for users of a class." |
|
7882 |
||
10460 | 7883 |
|myClass |
5755 | 7884 |
numInst "{ Class: SmallInteger }" | |
7885 |
||
7886 |
myClass := self class. |
|
7887 |
||
7888 |
"check the class" |
|
7889 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
7890 |
||
7891 |
"check the instance variables" |
|
7892 |
numInst := myClass instSize. |
|
10460 | 7893 |
1 to:numInst do:[:i | |
14975 | 7894 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
5755 | 7895 |
]. |
7896 |
||
7897 |
"check the indexed variables" |
|
7898 |
myClass isVariable ifTrue:[ |
|
14975 | 7899 |
myClass isPointers ifFalse:[ |
7900 |
"no need to search in non-pointer indexed fields" |
|
7901 |
myClass isLongs ifTrue:[ |
|
7902 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
7903 |
] ifFalse:[ |
|
7904 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
7905 |
^ aClass == SmallInteger |
|
7906 |
] |
|
7907 |
]. |
|
7908 |
numInst := self basicSize. |
|
7909 |
1 to:numInst do:[:i | |
|
7910 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
7911 |
] |
|
5755 | 7912 |
]. |
7913 |
^ false |
|
7914 |
||
7915 |
" |
|
10460 | 7916 |
(1 @ 3.4) referencesInstanceOf:Float |
7917 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
7918 |
View new initialize referencesInstanceOf:(Display class) |
|
5755 | 7919 |
" |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7920 |
! |
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 |
referencesObject:anObject |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7923 |
"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
|
7924 |
- for debugging only" |
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 |
%{ /* NOCONTEXT */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7927 |
OBJ cls, flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7928 |
int nInsts, i; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7929 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7930 |
if (! __isNonNilObject(self)) { |
14975 | 7931 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7932 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7933 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7934 |
/* |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7935 |
* 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
|
7936 |
* 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
|
7937 |
* 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
|
7938 |
*/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7939 |
if (__isNonNilObject(anObject)) { |
14975 | 7940 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7941 |
int spc; |
|
7942 |
||
7943 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7944 |
RETURN (false); |
|
7945 |
} |
|
7946 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7947 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7948 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7949 |
cls = __qClass(self); |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7950 |
if (cls == anObject) { |
14975 | 7951 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7952 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7953 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7954 |
flags = __ClassInstPtr(cls)->c_flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7955 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
14975 | 7956 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7957 |
} else { |
14975 | 7958 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7959 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7960 |
if (! nInsts) { |
14975 | 7961 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7962 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7963 |
#if defined(memsrch4) |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7964 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
14975 | 7965 |
RETURN (true); |
6074
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 |
#else |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7968 |
for (i=0; i<nInsts; i++) { |
14975 | 7969 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7970 |
RETURN (true); |
|
7971 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7972 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7973 |
#endif /* memsrch4 */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7974 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7975 |
%}. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7976 |
|
10460 | 7977 |
"/ |myClass |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7978 |
"/ numInst "{ Class: SmallInteger }" | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7979 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7980 |
"/ myClass := self class. |
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 |
"/ "check the class" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7983 |
"/ (myClass == anObject) ifTrue:[^ true]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7984 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7985 |
"/ "check the instance variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7986 |
"/ numInst := myClass instSize. |
10460 | 7987 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7988 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7989 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7990 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7991 |
"/ "check the indexed variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7992 |
"/ myClass isVariable ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7993 |
"/ myClass isPointers ifFalse:[ |
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 |
"/ "/ 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
|
7996 |
"/ "/ 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
|
7997 |
"/ "/ 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
|
7998 |
"/ "/ 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
|
7999 |
"/ "/ 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
|
8000 |
"/ "/ 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
|
8001 |
"/ "/ 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
|
8002 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8003 |
"/ ^ false. |
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 |
"/ "/ alternative: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8006 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
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 |
"/ "/ 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
|
8011 |
"/ "/ idenitytIndex method, use it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8012 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8013 |
"/ myClass == Array ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8014 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
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 |
"/ "/ otherwise, do it the slow way |
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 |
"/ numInst := self basicSize. |
10460 | 8021 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8022 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8023 |
"/ ] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8024 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8025 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8026 |
^ false |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8027 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8028 |
" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8029 |
|v| |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8030 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8031 |
v := View new initialize. |
10460 | 8032 |
v references:Display. |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8033 |
" |
5755 | 8034 |
! ! |
8035 |
||
15193 | 8036 |
|
5755 | 8037 |
!Object methodsFor:'synchronized evaluation'! |
8038 |
||
10460 | 8039 |
freeSynchronizationSemaphore |
5755 | 8040 |
"free synchronizationSemaphore. May be used, to save memory when |
8041 |
an object is no longer used synchronized." |
|
8042 |
||
8043 |
|sema| |
|
8044 |
||
8045 |
sema := self synchronizationSemaphore. |
|
8046 |
sema notNil ifTrue:[ |
|
14975 | 8047 |
sema wait. "/ get lock |
8048 |
self synchronizationSemaphore:nil. |
|
5755 | 8049 |
]. |
8050 |
||
8051 |
" |
|
8052 |
self synchronized:[]. |
|
8053 |
self synchronizationSemaphore. |
|
8054 |
self freeSynchronizationSemaphore. |
|
8055 |
" |
|
8056 |
||
8057 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
8058 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
8059 |
! |
|
8060 |
||
8061 |
synchronizationSemaphore |
|
8062 |
"return the synchronization semaphore for myself. |
|
8063 |
subclasses may redefine" |
|
8064 |
||
8065 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
8066 |
||
8067 |
" |
|
8068 |
self synchronizationSemaphore |
|
8069 |
" |
|
8070 |
||
8071 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
8072 |
! |
|
8073 |
||
8074 |
synchronizationSemaphore:aSemaphore |
|
8075 |
"set the synchronisationSemaphore for myself. |
|
8076 |
subclasses may redefine this method" |
|
8077 |
||
8078 |
aSemaphore isNil ifTrue:[ |
|
14975 | 8079 |
"/ remove Semaphore |
8080 |
SynchronizationSemaphores removeKey:self ifAbsent:nil. |
|
5755 | 8081 |
] ifFalse:[ |
14975 | 8082 |
SynchronizationSemaphores at:self put:aSemaphore. |
5755 | 8083 |
]. |
8084 |
||
8085 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
8086 |
! |
|
8087 |
||
8088 |
synchronized:aBlock |
|
8089 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
8090 |
||
6600 | 8091 |
|sema wasBlocked| |
8092 |
||
8093 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5755 | 8094 |
|
8095 |
sema := self synchronizationSemaphore. |
|
8096 |
sema isNil ifTrue:[ |
|
14975 | 8097 |
sema := RecursionLock new name:self className. |
8098 |
self synchronizationSemaphore:sema. |
|
5755 | 8099 |
]. |
8100 |
||
6600 | 8101 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
7211
87f5d25b5c3d
Make synchronizationSemaphore a recursionLock
Stefan Vogel <sv@exept.de>
parents:
7208
diff
changeset
|
8102 |
sema critical:aBlock. |
5755 | 8103 |
|
8104 |
" |
|
8105 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
8106 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
8107 |
" |
|
8108 |
||
8109 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
8110 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
|
8111 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
|
8112 |
! ! |
|
8113 |
||
8114 |
!Object methodsFor:'system primitives'! |
|
8115 |
||
8116 |
asOop |
|
8117 |
"ST-80 compatibility: |
|
8118 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
8119 |
or index); since ST/X has no such thing, and the objects address cannot |
|
10460 | 8120 |
be used (since its changing over time), we return the objects identityHash |
5755 | 8121 |
key, which provides (at least) some identity indication. |
8122 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
8123 |
key of two non-identical objects may be the same. |
|
8124 |
You'd better not use it - especially do not misuse it." |
|
8125 |
||
8126 |
^ self identityHash |
|
8127 |
||
8128 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
8129 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
8130 |
! |
|
8131 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8132 |
beImmutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8133 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8134 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8135 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8136 |
if (! __isNonNilObject(self)) { |
14975 | 8137 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8138 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8139 |
__beImmutable(self); |
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 |
! |
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 |
beMutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8144 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8145 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8146 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8147 |
if (! __isNonNilObject(self)) { |
14975 | 8148 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8149 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8150 |
__beMutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8151 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8152 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8153 |
|
5755 | 8154 |
become:anotherObject |
8155 |
"make all references to the receiver become references to anotherObject |
|
8156 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
|
8157 |
This can be a very dangerous operation - be warned. |
|
10460 | 8158 |
In general, using #become: should be avoided if possible, since it may |
5755 | 8159 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
8160 |
||
10460 | 8161 |
This may also be an expensive (i.e. slow) operation, |
8162 |
since in the worst case, the whole memory has to be searched for |
|
5755 | 8163 |
references to the two objects (although the primitive tries hard to |
10460 | 8164 |
limit the search, for acceptable performance in most cases). |
8165 |
This method fails, if the receiver or the argument is a SmallInteger |
|
8166 |
or nil, or is a context of a living method (i.e. one that has not already |
|
5755 | 8167 |
returned). |
10460 | 8168 |
(notice that #become: is not used heavily by the system |
5755 | 8169 |
- the Collection-classes have been rewritten to not use it.)" |
8170 |
%{ |
|
8171 |
if (__primBecome(self, anotherObject)) { |
|
14975 | 8172 |
RETURN ( self ); |
5755 | 8173 |
} |
8174 |
%}. |
|
8175 |
self primitiveFailed |
|
8176 |
! |
|
8177 |
||
8178 |
becomeNil |
|
8179 |
"make all references to the receiver become nil - effectively getting |
|
10460 | 8180 |
rid of the receiver. |
5755 | 8181 |
This can be a very dangerous operation - be warned. |
8182 |
||
8183 |
This may be an expensive (i.e. slow) operation. |
|
8184 |
The receiver may not be a SmallInteger or a context of a living method." |
|
8185 |
||
8186 |
%{ |
|
8187 |
if (__primBecomeNil(self)) { |
|
14975 | 8188 |
RETURN ( nil ); |
5755 | 8189 |
} |
8190 |
%}. |
|
8191 |
self primitiveFailed |
|
8192 |
! |
|
8193 |
||
8194 |
becomeSameAs:anotherObject |
|
8195 |
"make all references to the receiver become references to anotherObject |
|
8196 |
but NOT vice versa (as done in #become:). |
|
8197 |
This can be a very dangerous operation - be warned. |
|
10460 | 8198 |
In general, using #become: should be avoided if possible, since it may |
5755 | 8199 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
8200 |
||
8201 |
This may also be an expensive (i.e. slow) operation, |
|
8202 |
since in the worst case, the whole memory has to be searched for |
|
8203 |
references to the two objects (although the primitive tries hard to |
|
8204 |
limit the search, for acceptable performance in most cases). |
|
8205 |
This method fails, if the receiver or the argument is a SmallInteger |
|
8206 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
8207 |
%{ |
|
8208 |
if (__primBecomeSameAs(self, anotherObject)) { |
|
14975 | 8209 |
RETURN ( self ); |
5755 | 8210 |
} |
8211 |
%}. |
|
8212 |
self primitiveFailed |
|
8213 |
! |
|
8214 |
||
8215 |
changeClassTo:otherClass |
|
8216 |
"changes the class of the receiver to the argument, otherClass. |
|
8217 |
This is only allowed (possible), if the receivers class and the argument |
|
8218 |
have the same structure (i.e. number of named instance variables and |
|
10460 | 8219 |
type of indexed instance variables). |
5755 | 8220 |
If the structures do not match, or any of the original class or new class |
8221 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
8222 |
||
8223 |
|myClass ok| |
|
8224 |
||
9405 | 8225 |
otherClass autoload. |
8226 |
||
5755 | 8227 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
8228 |
%{ |
|
8229 |
{ |
|
14975 | 8230 |
OBJ other = otherClass; |
8231 |
||
8232 |
if (__isNonNilObject(self) |
|
8233 |
&& __isNonNilObject(other) |
|
8234 |
&& (other != UndefinedObject) |
|
8235 |
&& (other != SmallInteger)) { |
|
8236 |
ok = true; |
|
8237 |
} else { |
|
8238 |
ok = false; |
|
8239 |
} |
|
5755 | 8240 |
} |
8241 |
%}. |
|
8242 |
ok ifTrue:[ |
|
14975 | 8243 |
ok := false. |
8244 |
myClass := self class. |
|
8245 |
myClass flags == otherClass flags ifTrue:[ |
|
8246 |
myClass instSize == otherClass instSize ifTrue:[ |
|
8247 |
"same instance layout and types: its ok to do it" |
|
8248 |
ok := true. |
|
8249 |
] ifFalse:[ |
|
8250 |
myClass isPointers ifTrue:[ |
|
8251 |
myClass isVariable ifTrue:[ |
|
8252 |
ok := true |
|
8253 |
] |
|
8254 |
] |
|
8255 |
] |
|
8256 |
] ifFalse:[ |
|
8257 |
myClass isPointers ifTrue:[ |
|
8258 |
"if newClass is a variable class, with instSize <= my instsize, |
|
8259 |
we can do it (effectively mapping additional instvars into the |
|
8260 |
variable part) - usefulness is questionable, though" |
|
8261 |
||
8262 |
otherClass isPointers ifTrue:[ |
|
8263 |
otherClass isVariable ifTrue:[ |
|
8264 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
8265 |
ifTrue:[ |
|
8266 |
ok := true |
|
8267 |
] |
|
8268 |
] ifFalse:[ |
|
8269 |
otherClass instSize == (myClass instSize + self basicSize) |
|
8270 |
ifTrue:[ |
|
8271 |
ok := true |
|
8272 |
] |
|
8273 |
] |
|
8274 |
] ifFalse:[ |
|
8275 |
"it does not make sense to convert pointers to bytes ..." |
|
8276 |
] |
|
8277 |
] ifFalse:[ |
|
8278 |
"does it make sense, to convert bits ?" |
|
8279 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
8280 |
(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[ |
|
8281 |
ok := true |
|
8282 |
] |
|
8283 |
] |
|
8284 |
] |
|
5755 | 8285 |
]. |
8286 |
ok ifTrue:[ |
|
14975 | 8287 |
"now, change the receivers class ..." |
5755 | 8288 |
%{ |
14975 | 8289 |
{ |
8290 |
OBJ me = self; |
|
8291 |
||
15128 | 8292 |
// gcc4.4 does not like this: |
8293 |
// __qClass(me) = otherClass; |
|
14975 | 8294 |
__objPtr(me)->o_class = (CLASS_OBJ)otherClass; |
8295 |
__STORE(me, otherClass); |
|
8296 |
RETURN (me); |
|
8297 |
} |
|
5755 | 8298 |
%}. |
8299 |
]. |
|
9405 | 8300 |
|
5755 | 8301 |
" |
8302 |
the receiver cannot be represented as a instance of |
|
8303 |
the desired class. |
|
10460 | 8304 |
For example, you cannot change a bitInstance (byteArray etc.) |
5755 | 8305 |
into a pointer object and vice versa. |
8306 |
" |
|
8307 |
self primitiveFailed |
|
8308 |
! |
|
8309 |
||
8310 |
changeClassToThatOf:anObject |
|
8311 |
"changes the class of the receiver to that of the argument, anObject. |
|
8312 |
This is only allowed (possible), if the receivers class and the arguments |
|
10460 | 8313 |
class have the same structure (i.e. number of named instance variables and |
5755 | 8314 |
type of indexed instance variables). If the structures do not match, or any |
8315 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
8316 |
||
8317 |
self changeClassTo:(anObject class) |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8318 |
! |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8319 |
|
8935 | 8320 |
isImmutable |
8321 |
"experimental - not yet usable; do not use" |
|
8322 |
||
8323 |
%{ /* NOCONTEXT */ |
|
8324 |
if (! __isNonNilObject(self)) { |
|
14975 | 8325 |
RETURN (true); |
8935 | 8326 |
} |
8327 |
RETURN (__isImmutable(self) ? true : false); |
|
8328 |
%} |
|
8329 |
! |
|
8330 |
||
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8331 |
replaceReferencesTo:anObject with:newRef |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8332 |
"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
|
8333 |
Return true, if any reference was changed. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8334 |
Notice: this does not change the class-reference." |
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 |
%{ /* NOCONTEXT */ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8337 |
OBJ cls, flags, anyChange; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8338 |
int nInsts, i; |
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(self)) { |
14975 | 8341 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8342 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8343 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8344 |
/* |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8345 |
* a little optimization: use the fact that all old objects |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8346 |
* 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
|
8347 |
* a trivial reject is possible, if anObject is a newbee |
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 |
if (__isNonNilObject(anObject)) { |
14975 | 8350 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
8351 |
int spc; |
|
8352 |
||
8353 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
8354 |
RETURN (false); |
|
8355 |
} |
|
8356 |
} |
|
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 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8359 |
cls = __qClass(self); |
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 |
flags = __ClassInstPtr(cls)->c_flags; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8362 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
14975 | 8363 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8364 |
} else { |
14975 | 8365 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8366 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8367 |
if (! nInsts) { |
14975 | 8368 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8369 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8370 |
anyChange = false; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8371 |
for (i=0; i<nInsts; i++) { |
14975 | 8372 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
8373 |
__InstPtr(self)->i_instvars[i] = newRef; |
|
8374 |
__STORE(self, newRef); |
|
8375 |
anyChange = true; |
|
8376 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8377 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8378 |
RETURN (anyChange); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8379 |
%}. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8380 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8381 |
" |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8382 |
|v| |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8383 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8384 |
v := Array with:1234 with:'hello' with:Array. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8385 |
v replaceReferencesTo:Array with:ByteArray. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8386 |
v inspect |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8387 |
" |
5755 | 8388 |
! ! |
8389 |
||
8390 |
!Object methodsFor:'testing'! |
|
8391 |
||
8392 |
? defaultValue |
|
11634 | 8393 |
"a syntactic sugar-piece: |
5755 | 8394 |
if the receiver is nil, return the defaultValue; |
8395 |
otherwise, return the receiver. |
|
8396 |
This method is only redefined in UndefinedObject - therefore, |
|
8397 |
the recevier is retuned here. |
|
8398 |
||
8399 |
Thus, if foo and bar are simple variables or constants, |
|
14975 | 8400 |
foo ? bar |
5755 | 8401 |
is the same as: |
14975 | 8402 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
5755 | 8403 |
|
8404 |
if they are message sends, the equivalent code is: |
|
14975 | 8405 |
[ |
8406 |
|t1 t2| |
|
8407 |
||
8408 |
t1 := foo. |
|
8409 |
t2 := bar. |
|
8410 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
8411 |
] value |
|
5755 | 8412 |
|
8413 |
Can be used to provide defaultValues to variables, |
|
8414 |
as in: |
|
14975 | 8415 |
foo := arg ? #defaultValue |
5755 | 8416 |
|
8417 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8418 |
Notice: |
|
14975 | 8419 |
This method is open coded (inlined) by the compiler(s) |
8420 |
- redefining it may not work as expected." |
|
5755 | 8421 |
|
8422 |
^ self |
|
8423 |
||
8424 |
" |
|
8425 |
1 ? #default |
|
8426 |
nil ? #default |
|
8427 |
" |
|
8428 |
||
8429 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8430 |
"Modified: / 19.5.1998 / 17:39:56 / cg" |
|
8431 |
! |
|
8432 |
||
8433 |
?? defaultValue |
|
11634 | 8434 |
"a syntactic sugar-piece: |
5755 | 8435 |
much like ?, but sends #value to the argument if required. |
8436 |
(i.e. its the same as #ifNil:) |
|
8437 |
If the receiver is nil, return the defaultValues value; |
|
8438 |
otherwise, return the receiver. |
|
8439 |
This method is only redefined in UndefinedObject - therefore, |
|
8440 |
the recevier is retuned here. |
|
8441 |
||
8442 |
Thus, if foo and bar are simple variables or constants, |
|
14975 | 8443 |
foo ?? bar |
5755 | 8444 |
is the same as: |
14975 | 8445 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
5755 | 8446 |
|
8447 |
if they are message sends, the equivalent code is: |
|
14975 | 8448 |
[ |
8449 |
|t t2| |
|
8450 |
||
8451 |
t := foo. |
|
8452 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
8453 |
] value |
|
5755 | 8454 |
|
8455 |
Can be used to provide defaultValues to variables, |
|
8456 |
as in: |
|
14975 | 8457 |
foo := arg ?? [ self computeDefault ] |
5755 | 8458 |
|
8459 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8460 |
" |
|
8461 |
||
8462 |
^ self |
|
8463 |
||
8464 |
" |
|
10460 | 8465 |
1 ?? #default |
5755 | 8466 |
nil ?? #default |
10460 | 8467 |
1 ?? [ self halt. 1 + 2 ] |
8468 |
nil ?? [ self halt. 1 + 2 ] |
|
8469 |
1 ?? [Date today] |
|
8470 |
nil ?? [Date today] |
|
5755 | 8471 |
" |
8472 |
||
8473 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8474 |
"Modified: / 19.5.1998 / 17:42:56 / cg" |
|
8475 |
! |
|
8476 |
||
8477 |
ifNil:aBlockOrValue |
|
8478 |
"return myself, or the result from evaluating the argument, if I am nil. |
|
8479 |
This is much like #?, but sends #value to the argument in case of a nil |
|
8480 |
receiver. |
|
8481 |
Notice: |
|
14975 | 8482 |
This method is open coded (inlined) by the compiler(s) |
8483 |
- redefining it may not work as expected." |
|
5755 | 8484 |
|
8485 |
^ self |
|
8486 |
! |
|
8487 |
||
8488 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
|
8489 |
"return the value of the first arg, if I am nil, |
|
8490 |
the result from evaluating the 2nd argument, if I am not nil. |
|
8491 |
Notice: |
|
14975 | 8492 |
This method is open coded (inlined) by the compiler(s) |
8493 |
- redefining it may not work as expected." |
|
5755 | 8494 |
|
8495 |
^ notNilBlockOrValue value |
|
8496 |
||
8497 |
! |
|
8498 |
||
8499 |
ifNotNil:aBlockOrValue |
|
10460 | 8500 |
"return myself if nil, or the result from evaluating the argument, |
5755 | 8501 |
if I am not nil. |
8502 |
Notice: |
|
14975 | 8503 |
This method is open coded (inlined) by the compiler(s) |
8504 |
- redefining it may not work as expected." |
|
5755 | 8505 |
|
8506 |
^ aBlockOrValue value |
|
8507 |
||
8508 |
! |
|
8509 |
||
8510 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
|
8511 |
"return the value of the 2nd arg, if I am nil, |
|
8512 |
the result from evaluating the 1st argument, if I am not nil. |
|
8513 |
Notice: |
|
14975 | 8514 |
This method is open coded (inlined) by the compiler(s) |
8515 |
- redefining it may not work as expected." |
|
5755 | 8516 |
|
8517 |
^ notNilBlockOrValue value |
|
8518 |
||
8519 |
||
8520 |
! |
|
8521 |
||
8574 | 8522 |
ifNotNilDo:aBlock |
8523 |
"if the reciever is non-nil, return the value of aBlock, passing myself as argument. |
|
8524 |
Otherwise do nothing and return nil." |
|
8525 |
||
8526 |
^ aBlock value:self |
|
8527 |
! |
|
8528 |
||
5755 | 8529 |
isArray |
8530 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
8531 |
false is returned here - the method is only redefined in Array." |
|
8532 |
||
8533 |
^ false |
|
8534 |
! |
|
8535 |
||
8536 |
isAssociation |
|
8537 |
"return true, if the receiver is some kind of association; |
|
8538 |
false is returned here - the method is only redefined in Association." |
|
8539 |
||
8540 |
^ false |
|
8541 |
||
8542 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
8543 |
! |
|
8544 |
||
8545 |
isBehavior |
|
9221 | 8546 |
"return true, if the receiver is describing another objects behavior. |
8547 |
False is returned here - the method is only redefined in Behavior." |
|
5755 | 8548 |
|
8549 |
^ false |
|
8550 |
! |
|
8551 |
||
8552 |
isBlock |
|
8553 |
"return true, if the receiver is some kind of block; |
|
8554 |
false returned here - the method is only redefined in Block." |
|
8555 |
||
8556 |
^ false |
|
8557 |
! |
|
8558 |
||
5824 | 8559 |
isBoolean |
8560 |
"return true, if the receiver is a boolean; |
|
8561 |
false is returned here - the method is only redefined in Boolean." |
|
8562 |
||
8563 |
^ false |
|
8564 |
! |
|
8565 |
||
5755 | 8566 |
isByteArray |
8567 |
"return true, if the receiver is some kind of bytearray; |
|
8568 |
false is returned here - the method is only redefined in ByteArray." |
|
8569 |
||
8570 |
^ false |
|
8571 |
! |
|
8572 |
||
8986 | 8573 |
isByteCollection |
8574 |
"return true, if the receiver is some kind of byte collection, |
|
10460 | 8575 |
i.e. #at: and #at:put: accesses a byte. This is different from 'self class isBytes', |
8986 | 8576 |
since e.g. in BitArray single bits are accessed, but it is implemented as variableBytes class. |
10460 | 8577 |
|
8986 | 8578 |
false is returned here - the method is only redefined in UninterpretedBytes." |
8579 |
||
8580 |
^ false |
|
8581 |
! |
|
8582 |
||
5755 | 8583 |
isCharacter |
8584 |
"return true, if the receiver is some kind of character; |
|
8585 |
false is returned here - the method is only redefined in Character." |
|
8586 |
||
8587 |
^ false |
|
8588 |
! |
|
8589 |
||
8590 |
isClass |
|
9405 | 8591 |
"return true, if the receiver is some kind of class |
8592 |
(real class, not just behavior); |
|
5755 | 8593 |
false is returned here - the method is only redefined in Class." |
8594 |
||
8595 |
^ false |
|
8596 |
! |
|
8597 |
||
8598 |
isCollection |
|
8599 |
"return true, if the receiver is some kind of collection; |
|
8600 |
false is returned here - the method is only redefined in Collection." |
|
8601 |
||
8602 |
^ false |
|
8603 |
! |
|
8604 |
||
8605 |
isColor |
|
8606 |
"return true, if the receiver is some kind of color; |
|
8607 |
false is returned here - the method is only redefined in Color." |
|
8608 |
||
8609 |
^ false |
|
8610 |
! |
|
8611 |
||
6567 | 8612 |
isCons |
8613 |
"return true, if the receiver is a cons (pair); |
|
8614 |
false is returned here - the method is only redefined in Cons." |
|
8615 |
||
8616 |
^ false |
|
8617 |
! |
|
8618 |
||
5755 | 8619 |
isContext |
8620 |
"return true, if the receiver is some kind of context; |
|
8621 |
false returned here - the method is only redefined in Context." |
|
8622 |
||
8623 |
^ false |
|
8624 |
! |
|
8625 |
||
6181 | 8626 |
isEmptyOrNil |
8833 | 8627 |
"return true if I am nil or an empty collection - return false here. |
8628 |
(from Squeak)" |
|
6181 | 8629 |
|
8630 |
^ false |
|
8631 |
||
8632 |
"Created: / 13.11.2001 / 13:17:04 / cg" |
|
6182 | 8633 |
"Modified: / 13.11.2001 / 13:28:40 / cg" |
6181 | 8634 |
! |
8635 |
||
6221 | 8636 |
isException |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8637 |
"answer true, if this ia an Exception, that may be queried about its type" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8638 |
|
6221 | 8639 |
^ false |
8640 |
||
8641 |
"Created: / 17.11.2001 / 18:37:44 / cg" |
|
8642 |
! |
|
8643 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8644 |
isExceptionCreator |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8645 |
"return true, if the receiver can create exceptions, |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8646 |
this includes #raise, #raiseRequest as well as the behavior of |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8647 |
an exception handler, such as the #accepts: and #handles: messages" |
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 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8650 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8651 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8652 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8653 |
"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
|
8654 |
especially to the #accepts: and #handles: messages" |
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 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8657 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8658 |
|
13187 | 8659 |
isExternalAddress |
8660 |
"return true, if the receiver is some kind of externalAddress; |
|
8661 |
false is returned here - the method is only redefined in ExternalAddress." |
|
8662 |
||
8663 |
^ false |
|
8664 |
||
8665 |
"Created: / 22-12-2010 / 17:20:36 / cg" |
|
8666 |
! |
|
8667 |
||
14079 | 8668 |
isExternalBytes |
8669 |
^ false |
|
8670 |
! |
|
8671 |
||
10480 | 8672 |
isExternalLibraryFunction |
8673 |
"return true, if the receiver is some kind of externalLibrary function; |
|
8674 |
false is returned here - the method is only redefined in ExternalLibraryFunction." |
|
8675 |
||
8676 |
^false |
|
8677 |
! |
|
8678 |
||
5755 | 8679 |
isExternalStream |
8680 |
"return true, if the receiver is some kind of externalStream; |
|
8681 |
false is returned here - the method is only redefined in ExternalStream." |
|
8682 |
||
8683 |
^false |
|
8684 |
! |
|
8685 |
||
8686 |
isFileStream |
|
8687 |
"return true, if the receiver is some kind of fileStream; |
|
8688 |
false is returned here - the method is only redefined in FileStream." |
|
8689 |
||
8690 |
^false |
|
8691 |
! |
|
8692 |
||
8693 |
isFilename |
|
8694 |
"return true, if the receiver is some kind of filename; |
|
8695 |
false is returned here - the method is only redefined in Filename." |
|
8696 |
||
8697 |
^false |
|
8698 |
! |
|
8699 |
||
8700 |
isFixedPoint |
|
8701 |
"return true, if the receiver is some kind of fixedPoint number; |
|
8702 |
false is returned here - the method is only redefined in FixedPoint." |
|
8703 |
||
8704 |
^ false |
|
8705 |
||
8706 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
8707 |
! |
|
8708 |
||
8709 |
isFixedSize |
|
10460 | 8710 |
"return true if the receiver cannot grow easily |
5755 | 8711 |
(i.e. a grow may be expensive, since it involves a become:)" |
8712 |
||
8713 |
^ true |
|
8714 |
! |
|
8715 |
||
6185 | 8716 |
isFloat |
8717 |
"return true, if the receiver is some kind of floating point number; |
|
8718 |
false is returned here. |
|
8719 |
Same as #isLimitedPrecisionReal, but a better name ;-)" |
|
8720 |
||
8721 |
^ false |
|
8722 |
||
8723 |
"Modified: / 14.11.2001 / 14:57:46 / cg" |
|
8724 |
! |
|
8725 |
||
5755 | 8726 |
isForm |
8727 |
"return true, if the receiver is some kind of form; |
|
8728 |
false is returned here - the method is only redefined in Form." |
|
8729 |
||
8730 |
^ false |
|
8731 |
! |
|
8732 |
||
8733 |
isFraction |
|
8734 |
"return true, if the receiver is some kind of fraction; |
|
8735 |
false is returned here - the method is only redefined in Fraction." |
|
8736 |
||
8737 |
^ false |
|
8738 |
! |
|
8739 |
||
9293 | 8740 |
isHierarchicalItem |
8741 |
"used to decide if the parent is a hierarchical item or the model" |
|
8742 |
||
8743 |
^ false |
|
8744 |
! |
|
8745 |
||
5755 | 8746 |
isImage |
8747 |
"return true, if the receiver is some kind of image; |
|
8748 |
false is returned here - the method is only redefined in Image." |
|
8749 |
||
8750 |
^ false |
|
8751 |
! |
|
8752 |
||
8753 |
isImageOrForm |
|
8754 |
"return true, if the receiver is some kind of image or form; |
|
8755 |
false is returned here - the method is only redefined in Image and Form." |
|
8756 |
||
8757 |
^ false |
|
8758 |
! |
|
8759 |
||
8760 |
isImmediate |
|
8761 |
"return true if I am an immediate object |
|
8762 |
i.e. I am represented in the pointer itself and |
|
8763 |
no real object header/storage is used me. |
|
8764 |
(currently, only SmallIntegers, some characters and nil return true)" |
|
8765 |
||
8766 |
^ self class hasImmediateInstances |
|
8767 |
||
8768 |
"Created: 3.6.1997 / 12:00:18 / cg" |
|
8769 |
! |
|
8770 |
||
8771 |
isInteger |
|
8772 |
"return true, if the receiver is some kind of integer number; |
|
8773 |
false is returned here - the method is only redefined in Integer." |
|
8774 |
||
8775 |
^ false |
|
8776 |
! |
|
8777 |
||
9279 | 8778 |
isInterestConverter |
8779 |
"return true if I am a kind of interest forwarder" |
|
8780 |
||
8781 |
^ false |
|
8782 |
! |
|
8783 |
||
10576 | 8784 |
isInternalByteStream |
8785 |
"return true, if the receiver is some kind of Stream for reading bytes; |
|
8786 |
false is returned here - the method is only redefined in PeekableStream." |
|
8787 |
||
8788 |
^false |
|
8789 |
||
8790 |
"Created: / 30-05-2007 / 16:15:33 / cg" |
|
8791 |
! |
|
8792 |
||
5755 | 8793 |
isJavaClass |
8794 |
"return true, if this is a javaClass. |
|
8795 |
false is returned here - the method is only redefined in JavaClass." |
|
8796 |
||
8797 |
^ false |
|
8798 |
||
8799 |
"Created: / 26.3.1997 / 13:34:54 / cg" |
|
8800 |
"Modified: / 8.5.1998 / 21:25:21 / cg" |
|
8801 |
! |
|
8802 |
||
8803 |
isJavaClassRef |
|
8804 |
"return true, if this is a JavaClassRef. |
|
8805 |
false is returned here - the method is only redefined in JavaClassRef." |
|
8806 |
||
8807 |
^ false |
|
8808 |
||
8809 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8810 |
"Created: / 24.12.1999 / 01:46:28 / cg" |
|
8811 |
! |
|
8812 |
||
8813 |
isJavaContext |
|
8814 |
"return true, if this is a javaContext. |
|
8815 |
false is returned here - the method is only redefined in JavaContext." |
|
8816 |
||
8817 |
^ false |
|
8818 |
||
8819 |
"Created: / 8.5.1998 / 21:24:27 / cg" |
|
8820 |
"Modified: / 8.5.1998 / 21:25:35 / cg" |
|
8821 |
! |
|
8822 |
||
8823 |
isJavaMethod |
|
8824 |
"return true, if this is a JavaMethod. |
|
8825 |
false is returned here - the method is only redefined in JavaMethod." |
|
8826 |
||
8827 |
^ false |
|
8828 |
||
8829 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8830 |
"Created: / 25.9.1999 / 23:26:12 / cg" |
|
8831 |
! |
|
8832 |
||
8833 |
isJavaMethodRef |
|
8834 |
"return true, if this is a JavaMethodRef. |
|
8835 |
false is returned here - the method is only redefined in JavaMethodRef." |
|
8836 |
||
8837 |
^ false |
|
8838 |
||
8839 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8840 |
"Created: / 23.12.1999 / 19:44:51 / cg" |
|
8841 |
! |
|
8842 |
||
8843 |
isJavaObject |
|
8844 |
"return true, if this is a javaObject. |
|
8845 |
false is returned here - the method is only redefined in JavaObject." |
|
8846 |
||
8847 |
^ false |
|
8848 |
||
8849 |
"Created: / 26.3.1997 / 13:34:48 / cg" |
|
8850 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8851 |
! |
|
8852 |
||
8853 |
isJavaScriptClass |
|
8854 |
"return true, if this is a javaScriptClass. |
|
8855 |
false is returned here - the method is only redefined in JavaScriptClass." |
|
8856 |
||
8857 |
^ false |
|
8858 |
! |
|
8859 |
||
8935 | 8860 |
isJavaScriptMetaclass |
8861 |
"return true, if this is a javaScript Metaclass. |
|
8862 |
false is returned here - the method is only redefined in JavaScriptMetaclass." |
|
8863 |
||
8864 |
^ false |
|
8865 |
! |
|
8866 |
||
5755 | 8867 |
isKindOf:aClass |
8868 |
"return true, if the receiver is an instance of aClass or one of its |
|
8869 |
subclasses, false otherwise. |
|
10460 | 8870 |
Advice: |
15243 | 8871 |
use of this to check objects for certain attributes/protocol should |
14975 | 8872 |
be avoided; it limits the reusability of your classes by limiting use |
8873 |
to instances of certain classes and fences you into a specific inheritance |
|
8874 |
hierarchy. |
|
8875 |
Use check-methods to check an object for a certain attributes/protocol |
|
8876 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
8877 |
||
8878 |
Using #isKindOf: is considered BAD STYLE. |
|
5755 | 8879 |
|
8880 |
Advice2: |
|
14975 | 8881 |
Be aware, that using an #isXXX method is usually much faster than |
8882 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
8883 |
hierarchy, comparing every class on the way. |
|
8884 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
8885 |
a single function call. |
|
5755 | 8886 |
" |
8887 |
||
8888 |
%{ /* NOCONTEXT */ |
|
8889 |
register OBJ thisClass; |
|
8890 |
||
8891 |
thisClass = __Class(self); |
|
8892 |
while (thisClass != nil) { |
|
14975 | 8893 |
if (thisClass == aClass) { |
8894 |
RETURN ( true ); |
|
8895 |
} |
|
8896 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
5755 | 8897 |
} |
8898 |
RETURN ( false ); |
|
8899 |
%} |
|
8900 |
||
8901 |
"/ |
|
8902 |
"/ the above code is equivalent to: |
|
8903 |
"/ |
|
8904 |
"/ thisClass := self class. |
|
8905 |
"/ [thisClass notNil] whileTrue:[ |
|
8906 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
8907 |
"/ thisClass := thisClass superclass |
|
8908 |
"/ ]. |
|
8909 |
"/ ^ false |
|
8910 |
"/ |
|
8911 |
! |
|
8912 |
||
8913 |
isLayout |
|
8914 |
"return true, if the receiver is some kind of layout; |
|
8915 |
false is returned here - the method is only redefined in Layout." |
|
8916 |
||
8917 |
^ false |
|
8918 |
! |
|
8919 |
||
6567 | 8920 |
isLazyValue |
8921 |
^ false |
|
8922 |
! |
|
8923 |
||
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8924 |
isLimitedPrecisionReal |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8925 |
"return true, if the receiver is some kind of floating point number; |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8926 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
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 |
^ false |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8929 |
! |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8930 |
|
5755 | 8931 |
isList |
8932 |
"return true, if the receiver is some kind of list collection; |
|
8933 |
false is returned here - the method is only redefined in List." |
|
8934 |
||
8935 |
^ false |
|
8936 |
||
8937 |
"Created: / 11.2.2000 / 01:37:05 / cg" |
|
8938 |
! |
|
8939 |
||
8940 |
isLiteral |
|
8941 |
"return true, if the receiver can be represented as a literal constant in ST syntax; |
|
8942 |
false is returned here - the method is redefined in some classes." |
|
8943 |
||
8944 |
^ false |
|
8945 |
! |
|
8946 |
||
8947 |
isMemberOf:aClass |
|
8948 |
"return true, if the receiver is an instance of aClass, false otherwise. |
|
10460 | 8949 |
Advice: |
14975 | 8950 |
use of this to check objects for certain attributes/protocol should |
8951 |
be avoided; it limits the reusability of your classes by limiting use |
|
8952 |
to instances of a certain class. |
|
8953 |
Use check-methods to check an object for a certain attributes/protocol |
|
8954 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
8955 |
||
8956 |
Using #isMemberOf: is considered BAD STYLE. |
|
5755 | 8957 |
Notice: |
14975 | 8958 |
This method is open coded (inlined) by the compiler(s) |
8959 |
- redefining it may not work as expected." |
|
5755 | 8960 |
|
8961 |
^ (self class) == aClass |
|
8962 |
! |
|
8963 |
||
8964 |
isMeta |
|
8965 |
"return true, if the receiver is some kind of metaclass; |
|
8966 |
false is returned here - the method is only redefined in Metaclass." |
|
8967 |
||
8968 |
^ false |
|
8969 |
! |
|
8970 |
||
8971 |
isMethod |
|
8972 |
"return true, if the receiver is some kind of method; |
|
8973 |
false returned here - the method is only redefined in Method." |
|
8974 |
||
8975 |
^ false |
|
8976 |
! |
|
8977 |
||
8978 |
isMorph |
|
8979 |
"return true, if the receiver is some kind of morph; |
|
8980 |
false is returned here - the method is only redefined in Morph." |
|
8981 |
||
8982 |
^ false |
|
8983 |
! |
|
8984 |
||
8985 |
isNameSpace |
|
9221 | 8986 |
"return true, if the receiver is a nameSpace. |
8987 |
False is returned here - the method is only redefined in Namespace." |
|
5755 | 8988 |
|
8989 |
^ false |
|
8990 |
||
8991 |
"Created: / 11.10.1996 / 18:08:56 / cg" |
|
8992 |
"Modified: / 8.5.1998 / 21:26:05 / cg" |
|
8993 |
! |
|
8994 |
||
8995 |
isNamespace |
|
8996 |
"return true, if this is a nameSpace. |
|
8997 |
false is returned here - the method is only redefined in Namespace." |
|
8998 |
||
5869 | 8999 |
<resource:#obsolete> |
9000 |
||
5755 | 9001 |
self obsoleteMethodWarning:'use #isNameSpace'. |
6805 | 9002 |
^ self isNameSpace |
5755 | 9003 |
! |
9004 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9005 |
isNil |
9221 | 9006 |
"Return true, if the receiver is nil. |
9007 |
Because isNil is redefined in UndefinedObject, |
|
9008 |
the receiver is definitely not nil here, so unconditionally return false. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9009 |
Notice: |
14975 | 9010 |
This method is open coded (inlined) by the compiler(s) |
9011 |
- redefining it may not work as expected." |
|
6068
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 |
^ false |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9014 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9015 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9016 |
isNilOrEmptyCollection |
6182 | 9017 |
"return true if I am nil or an empty collection - false here. |
8833 | 9018 |
Obsolete, use isEmptyOrNil." |
9019 |
||
9020 |
<resource:#obsolete> |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9021 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9022 |
^ false |
6182 | 9023 |
|
9024 |
"Modified: / 13.11.2001 / 13:28:06 / cg" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9025 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9026 |
|
9005 | 9027 |
isNonByteCollection |
9028 |
"return true, if the receiver is some kind of collection, but not a String, ByteArray etc.; |
|
9029 |
false is returned here - the method is redefined in Collection and UninterpretedBytes." |
|
9030 |
||
9031 |
^ false |
|
9032 |
||
9033 |
" |
|
14975 | 9034 |
21 isNonByteCollection |
9035 |
'abc' isNonByteCollection |
|
9036 |
#'abc' isNonByteCollection |
|
9037 |
#[1 2 3] isNonByteCollection |
|
9038 |
#(1 2 3) isNonByteCollection |
|
9005 | 9039 |
" |
9040 |
! |
|
9041 |
||
5755 | 9042 |
isNumber |
9043 |
"return true, if the receiver is some kind of number; |
|
9044 |
false is returned here - the method is only redefined in Number." |
|
9045 |
||
9046 |
^ false |
|
9047 |
! |
|
9048 |
||
9049 |
isOrderedCollection |
|
9050 |
"return true, if the receiver is some kind of ordered collection (or list etc); |
|
9051 |
false is returned here - the method is only redefined in OrderedCollection." |
|
9052 |
||
9053 |
^ false |
|
9054 |
! |
|
9055 |
||
9056 |
isPoint |
|
9057 |
"return true, if the receiver is some kind of point; |
|
9058 |
false is returned here - the method is only redefined in Point." |
|
9059 |
||
9060 |
^ false |
|
9061 |
! |
|
9062 |
||
10532 | 9063 |
isPrinterContext |
9064 |
||
9065 |
^false |
|
9066 |
! |
|
9067 |
||
13416 | 9068 |
isProgrammingLanguage |
9069 |
"return true, if the receiver is a programming language. |
|
14632 | 9070 |
False is returned here - the method is only redefined in |
13416 | 9071 |
ProgrammingLanguage." |
9072 |
||
9073 |
^ false |
|
9074 |
||
9075 |
"Created: / 21-07-2010 / 15:13:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
9076 |
! |
|
9077 |
||
9515 | 9078 |
isProjectDefinition |
9079 |
"return true, if the receiver is a projectDefinition. |
|
9080 |
False is returned here - the method is only redefined in ProjectDefinition." |
|
9081 |
||
9082 |
^ false |
|
9083 |
||
9084 |
"Created: / 10-08-2006 / 16:24:53 / cg" |
|
9085 |
! |
|
9086 |
||
13140 | 9087 |
isProxy |
9088 |
"return true, if the receiver is a proxy for another (lazy loaded) object. |
|
9089 |
False is returned here." |
|
9090 |
||
9091 |
^ false |
|
9092 |
||
9093 |
"Created: / 21-11-2010 / 11:15:46 / cg" |
|
9094 |
! |
|
9095 |
||
10171 | 9096 |
isRealNameSpace |
9097 |
"return true, if the receiver is really a nameSpace (i.e. a NameSpace, but not Smalltalk). |
|
9098 |
False is returned here - the method is only redefined in Namespace." |
|
9099 |
||
9100 |
^ false |
|
9101 |
||
9102 |
"Created: / 10-11-2006 / 17:05:43 / cg" |
|
9103 |
! |
|
9104 |
||
5755 | 9105 |
isRectangle |
9106 |
"return true, if the receiver is some kind of rectangle; |
|
9107 |
false is returned here - the method is only redefined in Rectangle." |
|
9108 |
||
9109 |
^ false |
|
9110 |
! |
|
9111 |
||
9112 |
isRemoteObject |
|
9113 |
"return true, if the receiver is some kind of remoteObject, |
|
9114 |
false if its local - the method is only redefined in RemoteObject." |
|
9115 |
||
9116 |
^ false |
|
9117 |
||
9118 |
"Created: 28.10.1996 / 15:18:45 / cg" |
|
9119 |
"Modified: 28.10.1996 / 15:20:57 / cg" |
|
9120 |
! |
|
9121 |
||
9122 |
isSequenceable |
|
9123 |
"return true, if the receiver is some kind of sequenceable collection; |
|
9124 |
false is returned here - the method is only redefined in SequenceableCollection." |
|
9125 |
||
9126 |
^ false |
|
9127 |
! |
|
9128 |
||
9129 |
isSequenceableCollection |
|
9130 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
9131 |
This method is a historic leftover and will be removed soon ... |
|
9132 |
(although its name is much better than #isSequenceable - sigh)" |
|
9133 |
||
5869 | 9134 |
<resource:#obsolete> |
9135 |
||
5755 | 9136 |
self obsoleteMethodWarning:'use #isSequenceable'. |
9137 |
^ false |
|
9138 |
! |
|
9139 |
||
10856 | 9140 |
isSharedPool |
9141 |
"return true, if the receiver is a sharedPool. |
|
9142 |
False is returned here - the method is only redefined in SharedPool." |
|
9143 |
||
9144 |
^ false |
|
9145 |
! |
|
9146 |
||
13565
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9147 |
isSpecialInstrumentationInfoLiteral |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9148 |
"return true, if the receiver is a special instrumentation info |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9149 |
object as placed into the literal array of instrumented methods" |
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 |
^ false |
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 |
"Created: / 07-08-2011 / 17:03:41 / cg" |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9154 |
! |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9155 |
|
5755 | 9156 |
isStream |
9157 |
"return true, if the receiver is some kind of stream; |
|
9158 |
false is returned here - the method is only redefined in Stream." |
|
9159 |
||
9160 |
^ false |
|
9161 |
! |
|
9162 |
||
9163 |
isString |
|
9164 |
"return true, if the receiver is some kind of string; |
|
9165 |
false is returned here - the method is only redefined in CharacterArray." |
|
9166 |
||
9167 |
^ false |
|
9168 |
! |
|
9169 |
||
9170 |
isStringCollection |
|
9171 |
"return true, if the receiver is some kind of stringCollection; |
|
9172 |
false is returned here - the method is only redefined in StringCollection." |
|
9173 |
||
9174 |
^ false |
|
9175 |
! |
|
9176 |
||
9177 |
isSymbol |
|
9178 |
"return true, if the receiver is some kind of symbol; |
|
9179 |
false is returned here - the method is only redefined in Symbol." |
|
9180 |
||
9181 |
^ false |
|
9182 |
! |
|
9183 |
||
9184 |
isText |
|
9185 |
"return true, if the receiver is some kind of text object; |
|
9186 |
false is returned here - the method is only redefined in Text." |
|
9187 |
||
9188 |
^ false |
|
9189 |
||
9190 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
9191 |
! |
|
9192 |
||
13656 | 9193 |
isTextView |
9194 |
"return true, if the receiver is some kind of textView; |
|
9195 |
false is returned here - the method is only redefined in TextViews." |
|
9196 |
||
9197 |
^ false |
|
9198 |
||
9199 |
"Modified (comment): / 08-09-2011 / 05:12:37 / cg" |
|
9200 |
! |
|
9201 |
||
13229 | 9202 |
isTimestamp |
9203 |
^ false |
|
9204 |
! |
|
9205 |
||
13626 | 9206 |
isTrait |
9207 |
"Return true if the receiver is a trait. |
|
9208 |
Note: Do not override in any class except TraitBehavior." |
|
9209 |
||
9210 |
^ false |
|
9211 |
||
9212 |
"Created: / 04-09-2011 / 20:04:43 / cg" |
|
9213 |
! |
|
9214 |
||
14296 | 9215 |
isUUID |
9216 |
^ false |
|
9217 |
! |
|
9218 |
||
5755 | 9219 |
isValueModel |
9220 |
"return true, if the receiver is some kind of valueModel; |
|
9221 |
false is returned here - the method is only redefined in ValueModel." |
|
9222 |
||
9223 |
^ false |
|
9224 |
||
9225 |
! |
|
9226 |
||
9227 |
isVariable |
|
9228 |
"return true if the receiver has indexed instance variables, |
|
9229 |
false otherwise." |
|
9230 |
||
9231 |
^ self class isVariable |
|
9232 |
! |
|
9233 |
||
9234 |
isVariableBinding |
|
9235 |
"return true, if this is a binding for a variable. |
|
9236 |
false is returned here - the method is only redefined in Binding." |
|
9237 |
||
9238 |
^ false |
|
9239 |
||
9240 |
"Created: / 19.6.1997 / 17:38:44 / cg" |
|
9241 |
"Modified: / 8.5.1998 / 21:26:55 / cg" |
|
9242 |
! |
|
9243 |
||
9244 |
isView |
|
9245 |
"return true, if the receiver is some kind of view; |
|
9246 |
false is returned here - the method is only redefined in View." |
|
9247 |
||
9248 |
^ false |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9249 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9250 |
|
6932 | 9251 |
notEmptyOrNil |
9252 |
"Squeak compatibility: |
|
9253 |
return true if I am neither nil nor an empty collection. |
|
9254 |
Return true here." |
|
9255 |
||
9256 |
^ true |
|
9257 |
! |
|
9258 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9259 |
notNil |
9221 | 9260 |
"Return true, if the receiver is not nil. |
9261 |
Because notNil is redefined in UndefinedObject, |
|
9262 |
the receiver is definitely not nil here, so unconditionally return true. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9263 |
Notice: |
14975 | 9264 |
This method is open coded (inlined) by the compiler(s) |
9265 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9266 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9267 |
^ true |
5755 | 9268 |
! ! |
9269 |
||
9270 |
!Object methodsFor:'tracing'! |
|
9271 |
||
9272 |
traceInto:aRequestor level:level from:referrer |
|
9273 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
9274 |
||
9275 |
^ aRequestor traceObject:self level:level from:referrer |
|
9276 |
||
9277 |
"Created: / 2.9.1999 / 09:05:17 / stefan" |
|
9278 |
! ! |
|
9279 |
||
9280 |
!Object methodsFor:'user interaction & notifications'! |
|
9281 |
||
9282 |
activityNotification:aString |
|
9283 |
"this can be sent from deeply nested methods, which are going to perform |
|
9284 |
some long-time activity. |
|
9285 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
9286 |
passing the argument. The handler should show this message whereever it likes, |
|
9287 |
and proceed. If there is no handler, this is simply ignored. |
|
9288 |
||
9289 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
9290 |
which likes to display that message in its label or a busy-box. |
|
9291 |
It could also be put into some logfile or printed on the standard output/error." |
|
9292 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
9293 |
ActivityNotification isHandled ifTrue:[ |
14975 | 9294 |
^ ActivityNotification raiseRequestWith:self errorString:aString |
5755 | 9295 |
]. |
9296 |
||
9297 |
" |
|
9298 |
nil activityNotification:'hello there' |
|
9299 |
self activityNotification:'hello there' |
|
9300 |
" |
|
9301 |
||
9302 |
" |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
9303 |
ActivityNotification handle:[:ex | |
14975 | 9304 |
ex errorString printCR. |
9305 |
ex proceed. |
|
5755 | 9306 |
] do:[ |
14975 | 9307 |
'hello' printCR. |
9308 |
self activityNotification:'doing some long time computation'. |
|
9309 |
'world' printCR. |
|
5755 | 9310 |
] |
9311 |
" |
|
9312 |
||
9313 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
9314 |
! |
|
9315 |
||
9316 |
confirm:aString |
|
9694 | 9317 |
"open a modal yes-no dialog. |
9318 |
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
|
9319 |
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
|
9320 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9321 |
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
|
9322 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9323 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9324 |
^ UserConfirmation raiseRequestErrorString:aString |
10460 | 9325 |
|
5755 | 9326 |
" |
9327 |
nil confirm:'hello' |
|
9328 |
self confirm:'hello' |
|
9329 |
" |
|
9330 |
! |
|
9331 |
||
9332 |
confirm:aString orCancel:cancelBlock |
|
9333 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
9334 |
return true for yes, false for no, or the value from cancelBlock for cancel. |
|
9335 |
If no GUI is present (headless applications), cancelBlock is returned." |
|
9336 |
||
9337 |
|answer| |
|
9338 |
||
9339 |
answer := self confirmWithCancel:aString. |
|
9340 |
answer isNil ifTrue:[ |
|
14975 | 9341 |
^ cancelBlock value |
5755 | 9342 |
]. |
9343 |
^ answer |
|
10460 | 9344 |
|
5755 | 9345 |
" |
9346 |
self confirm:'hello' orCancel:[self halt] |
|
9347 |
" |
|
9348 |
||
9349 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
9350 |
! |
|
9351 |
||
9352 |
confirmWithCancel:aString |
|
9353 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
9354 |
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
|
9355 |
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
|
9356 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9357 |
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
|
9358 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9359 |
|
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9360 |
^ self confirmWithCancel:aString defaultAnswer:nil |
10460 | 9361 |
|
9362 |
" |
|
9363 |
nil confirmWithCancel:'hello' |
|
5755 | 9364 |
self confirmWithCancel:'hello' |
9365 |
" |
|
9366 |
! |
|
9367 |
||
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9368 |
confirmWithCancel:aString defaultAnswer:defaultAnswerOrNil |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9369 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9370 |
return true for yes, false for no, nil for cancel. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9371 |
If no GUI is present (headless applications), nil is returned. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9372 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9373 |
Someone in the sender chain may redefine the confirmation handler |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9374 |
by handling the UserConfirmation." |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9375 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9376 |
^ UserConfirmation new |
14975 | 9377 |
defaultAnswer:defaultAnswerOrNil; |
9378 |
canCancel:true; |
|
9379 |
errorString:aString; |
|
9380 |
raiseRequest |
|
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9381 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9382 |
" |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9383 |
nil confirmWithCancel:'hello' defaultAnswer:true |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9384 |
self confirmWithCancel:'hello' defaultAnswer:false |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9385 |
" |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9386 |
! |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9387 |
|
5755 | 9388 |
errorNotify:aString |
9389 |
"launch a Notifier, showing top stack, telling user something |
|
9390 |
and give user a chance to enter debugger." |
|
9391 |
||
9392 |
^ self |
|
14975 | 9393 |
errorNotify:aString |
9394 |
from:thisContext sender |
|
9395 |
allowDebug:true |
|
15255 | 9396 |
mayProceed:true |
5755 | 9397 |
|
9398 |
" |
|
9399 |
nil errorNotify:'hello there' |
|
9400 |
self errorNotify:'hello there' |
|
9401 |
" |
|
9402 |
||
6199 | 9403 |
"Modified: / 16.11.2001 / 15:36:49 / cg" |
5755 | 9404 |
! |
9405 |
||
9406 |
errorNotify:aString from:aContext |
|
10460 | 9407 |
"launch a Notifier, showing top stack (above aContext), |
5755 | 9408 |
telling user something and give user a chance to enter debugger." |
9409 |
||
15255 | 9410 |
^ self errorNotify:aString from:aContext allowDebug:true mayProceed:true |
5755 | 9411 |
|
9412 |
"Modified: / 17.8.1998 / 10:09:27 / cg" |
|
9413 |
! |
|
9414 |
||
9415 |
errorNotify:aString from:aContext allowDebug:allowDebug |
|
10460 | 9416 |
"launch a Notifier, showing top stack (above aContext), |
15255 | 9417 |
telling user something and give user a chance to enter debugger." |
9418 |
||
9419 |
^ self errorNotify:aString from:aContext allowDebug:allowDebug mayProceed:true |
|
9420 |
! |
|
9421 |
||
9422 |
errorNotify:aString from:aContext allowDebug:allowDebug mayProceed:mayProceed |
|
9423 |
"launch a Notifier, showing top stack (above aContext), |
|
5755 | 9424 |
telling user something and optionally give the user a chance to enter debugger." |
9425 |
||
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
9426 |
|currentScreen con sender action boxLabels boxValues default s| |
5755 | 9427 |
|
9428 |
Smalltalk isInitialized ifFalse:[ |
|
14975 | 9429 |
'errorNotification: ' print. aString printCR. |
15219 | 9430 |
con := aContext ? thisContext methodHome. |
9431 |
con sender printAllLevels:10. |
|
14975 | 9432 |
^ nil |
10460 | 9433 |
]. |
11531 | 9434 |
|
10460 | 9435 |
(Dialog isNil |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
9436 |
or:[Screen isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
9437 |
or:[(currentScreen := Screen current) isNil |
10460 | 9438 |
or:[currentScreen isOpen not]]]) ifTrue:[ |
14975 | 9439 |
" |
9440 |
on systems without GUI, simply show |
|
9441 |
the message on the Transcript and abort. |
|
9442 |
" |
|
9443 |
Transcript showCR:aString. |
|
9444 |
AbortOperationRequest raise. |
|
9445 |
"not reached" |
|
9446 |
^ nil |
|
5755 | 9447 |
]. |
9448 |
||
9449 |
Processor activeProcessIsSystemProcess ifTrue:[ |
|
14975 | 9450 |
action := #debug. |
9451 |
sender := aContext. |
|
9452 |
Debugger isNil ifTrue:[ |
|
9453 |
'****************** Cought Error while in SystemProcess ****************' errorPrintCR. |
|
9454 |
aString errorPrintCR. |
|
9455 |
Exception handle:[:ex | |
|
9456 |
'Cought recursive error while printing backtrace:' errorPrintCR. |
|
9457 |
ex description errorPrintCR. |
|
9458 |
] do:[ |
|
9459 |
thisContext fullPrintAll. |
|
9460 |
]. |
|
9461 |
action := #abort. |
|
9462 |
]. |
|
5755 | 9463 |
] ifFalse:[ |
14975 | 9464 |
Dialog autoload. "in case it's autoloaded" |
9465 |
||
9466 |
Error handle:[:ex | |
|
9467 |
"/ a recursive error - quickly enter debugger |
|
9468 |
"/ this happened, when I corrupted the Dialog class ... |
|
9469 |
('Object [error]: ' , ex description , ' caught in errorNotification') errorPrintCR. |
|
9470 |
action := #debug. |
|
9471 |
ex return. |
|
9472 |
] do:[ |s| |
|
9473 |
sender := aContext. |
|
9474 |
sender isNil ifTrue:[ |
|
15219 | 9475 |
sender := thisContext methodHome sender. |
14975 | 9476 |
]. |
9477 |
con := sender. |
|
9478 |
||
9479 |
"/ skip intermediate (signal & exception) contexts |
|
9480 |
DebugView notNil ifTrue:[ |
|
9481 |
con := DebugView interestingContextFrom:sender |
|
9482 |
]. |
|
9483 |
||
9484 |
"/ show the first few contexts |
|
9485 |
||
9486 |
s := WriteStream with:aString. |
|
9487 |
s cr; cr. |
|
9488 |
s nextPutLine:'Calling Chain:'. |
|
9489 |
s nextPutLine:'--------------------------------------------------------------'. |
|
9490 |
1 to:25 do:[:n | |
|
9491 |
con notNil ifTrue:[ |
|
9492 |
con printOn:s. |
|
9493 |
s cr. |
|
9494 |
con := con sender |
|
9495 |
] |
|
9496 |
]. |
|
9497 |
||
15255 | 9498 |
mayProceed ifTrue:[ |
9499 |
boxLabels := #('Proceed'). |
|
9500 |
boxValues := #(#proceed). |
|
9501 |
default := #proceed. |
|
9502 |
] ifFalse:[ |
|
9503 |
boxLabels := #(). |
|
9504 |
boxValues := #(). |
|
9505 |
]. |
|
14975 | 9506 |
|
9507 |
AbortOperationRequest isHandled ifTrue:[ |
|
9508 |
default := #abort. |
|
9509 |
boxLabels := boxLabels , #('Abort'). |
|
9510 |
boxValues := boxValues , #(#abort). |
|
9511 |
true "allowDebug" ifTrue:[ |
|
9512 |
boxLabels := boxLabels , #('Copy Trace and Abort'). |
|
9513 |
boxValues := boxValues , #(#copyAndAbort). |
|
9514 |
] |
|
9515 |
] ifFalse:[ |
|
15255 | 9516 |
mayProceed "and:[allowDebug]" ifTrue:[ |
14975 | 9517 |
boxLabels := boxLabels , #('Copy Trace and Proceed'). |
9518 |
boxValues := boxValues , #(#copyAndProceed). |
|
9519 |
]. |
|
9520 |
]. |
|
9521 |
||
9522 |
(allowDebug and:[Debugger notNil]) ifTrue:[ |
|
9523 |
boxLabels := boxLabels , #('Debug'). |
|
9524 |
boxValues := boxValues , #(#debug). |
|
9525 |
default := #debug. |
|
9526 |
]. |
|
9527 |
||
9528 |
action := Dialog |
|
9529 |
choose:s contents |
|
9530 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
|
9531 |
image:WarningBox errorIconBitmap |
|
9532 |
labels:boxLabels |
|
9533 |
values:boxValues |
|
9534 |
default:default |
|
9535 |
onCancel:nil. |
|
9536 |
]. |
|
5755 | 9537 |
]. |
9538 |
||
9539 |
action == #debug ifTrue:[ |
|
15255 | 9540 |
^ Debugger enter:sender withMessage:aString mayProceed:mayProceed |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9541 |
]. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9542 |
action == #proceed ifTrue:[ |
14975 | 9543 |
^ nil. |
11335 | 9544 |
]. |
9545 |
(action == #copyAndProceed |
|
9546 |
or:[action == #copyAndAbort]) ifTrue:[ |
|
14975 | 9547 |
s := '' writeStream. |
9548 |
Exception handle:[:ex | |
|
9549 |
'Cought recursive error while printing backtrace' errorPrintCR. |
|
9550 |
] do:[ |
|
9551 |
sender fullPrintAllOn:s. |
|
9552 |
]. |
|
9553 |
currentScreen rootView setClipboardText:s contents. |
|
9554 |
action == #copyAndProceed ifTrue:[ |
|
9555 |
^ nil |
|
9556 |
]. |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
9557 |
]. |
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
9558 |
|
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9559 |
AbortOperationRequest raise. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9560 |
"not reached" |
5755 | 9561 |
|
9562 |
" |
|
9563 |
nil errorNotify:'hello there' |
|
9564 |
self errorNotify:'hello there' |
|
9565 |
" |
|
9566 |
||
13165
66a6b37405d1
changed: #errorNotify:from:allowDebug:
Claus Gittinger <cg@exept.de>
parents:
13162
diff
changeset
|
9567 |
"Created: / 17-08-1998 / 10:09:26 / cg" |
13566 | 9568 |
"Modified: / 08-08-2011 / 11:26:17 / sr" |
13844
f03a655457f4
changed: #errorNotify:from:allowDebug:
Claus Gittinger <cg@exept.de>
parents:
13812
diff
changeset
|
9569 |
"Modified: / 05-12-2011 / 03:50:59 / cg" |
5755 | 9570 |
! |
9571 |
||
9572 |
information:aString |
|
10460 | 9573 |
"launch an InfoBox, telling user something. |
9574 |
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
|
9575 |
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
|
9576 |
Use #notify: for more important messages. |
8371 | 9577 |
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
|
9578 |
pops up an info dialog." |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9579 |
|
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
9580 |
UserInformation raiseRequestWith:self errorString:aString |
5755 | 9581 |
|
9582 |
" |
|
9583 |
nil information:'hello there' |
|
9584 |
self information:'hello there' |
|
9585 |
" |
|
9586 |
||
9587 |
" |
|
9588 |
InformationSignal handle:[:ex | |
|
14975 | 9589 |
'no box popped' printCR. |
9590 |
ex proceed. |
|
5755 | 9591 |
] do:[ |
14975 | 9592 |
'hello' printCR. |
9593 |
self information:'some info'. |
|
9594 |
'world' printCR. |
|
5755 | 9595 |
] |
9596 |
" |
|
9597 |
||
9598 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
9599 |
! |
|
9600 |
||
9601 |
notify:aString |
|
9602 |
"launch a Notifier, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9603 |
Use #information: for ignorable messages. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9604 |
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
|
9605 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9606 |
|
5755 | 9607 |
|
9608 |
Smalltalk isInitialized ifFalse:[ |
|
14975 | 9609 |
"/ thisContext fullPrintAll. |
9610 |
'information: ' print. aString printCR. |
|
9611 |
^ self |
|
5755 | 9612 |
]. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9613 |
UserNotification raiseRequestWith:self errorString:aString. |
5755 | 9614 |
|
9615 |
" |
|
9616 |
nil notify:'hello there' |
|
9617 |
self notify:'hello there' |
|
9618 |
" |
|
9619 |
||
9620 |
"Modified: 20.5.1996 / 10:28:48 / cg" |
|
9621 |
! |
|
9622 |
||
9623 |
warn:aString |
|
9624 |
"launch a WarningBox, telling user something. |
|
10460 | 9625 |
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
|
9626 |
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
|
9627 |
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
|
9628 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9629 |
|
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9630 |
Warning raiseRequestWith:self errorString:aString |
5755 | 9631 |
|
9632 |
" |
|
9633 |
nil warn:'hello there' |
|
9634 |
self warn:'hello there' |
|
9635 |
" |
|
9636 |
||
9637 |
" |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9638 |
Warning handle:[:ex | |
14975 | 9639 |
Transcript showCR:ex description. |
9640 |
ex proceed. |
|
5755 | 9641 |
] do:[ |
14975 | 9642 |
'hello' printCR. |
9643 |
self warn:'some info'. |
|
9644 |
'world' printCR. |
|
5755 | 9645 |
] |
9646 |
" |
|
9647 |
||
9648 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
|
9649 |
! ! |
|
9650 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9651 |
!Object methodsFor:'visiting'! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9652 |
|
8426 | 9653 |
acceptVisitor:aVisitor |
9654 |
"double-dispatch onto a Visitor." |
|
9655 |
||
9656 |
^ self acceptVisitor:aVisitor with:nil |
|
9657 |
! |
|
9658 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9659 |
acceptVisitor:aVisitor with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9660 |
"double-dispatch onto a Visitor. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9661 |
Subclasses redefine this" |
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 |
^ aVisitor visitObject:self with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9664 |
! ! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9665 |
|
5755 | 9666 |
!Object class methodsFor:'documentation'! |
1 | 9667 |
|
14056
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
9668 |
version |
15255 | 9669 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.722 2013-05-16 10:39:47 stefan Exp $' |
14056
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
9670 |
! |
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
9671 |
|
12050 | 9672 |
version_CVS |
15255 | 9673 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.722 2013-05-16 10:39:47 stefan Exp $' |
13416 | 9674 |
! |
9675 |
||
9676 |
version_SVN |
|
15243 | 9677 |
^ '$ Id: Object.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
1 | 9678 |
! ! |
6764 | 9679 |
|
14661 | 9680 |
|
5755 | 9681 |
Object initialize! |