author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 10 Aug 2010 09:55:15 +0100 | |
branch | jv |
changeset 17795 | 569eec7576f1 |
parent 17789 | 338675f49dd6 |
child 17797 | 71451ae83564 |
permissions | -rw-r--r-- |
5755 | 1 |
" |
2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
17757 | 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 |
|
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
15 |
instanceVariableNames:'' |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
16 |
classVariableNames:'ErrorSignal HaltSignal MessageNotUnderstoodSignal |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
17 |
UserInterruptSignal RecursionInterruptSignal |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
18 |
ExceptionInterruptSignal SubscriptOutOfBoundsSignal |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
19 |
IndexNotFoundSignal NonIntegerIndexSignal NotFoundSignal |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
20 |
KeyNotFoundSignal ElementOutOfBoundsSignal UserNotificationSignal |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
21 |
InformationSignal WarningSignal PrimitiveFailureSignal |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
22 |
DeepCopyErrorSignal AbortSignal ErrorRecursion Dependencies |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
23 |
InfoPrinting ActivityNotificationSignal InternalErrorSignal |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
24 |
NonWeakDependencies SynchronizationSemaphores ObjectAttributes |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
25 |
OSSignalInterruptSignal FinalizationLobby |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
26 |
RecursiveStoreStringSignal AbortAllSignal EnabledBreakPoints' |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
27 |
poolDictionaries:'' |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
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 |
|
17757 | 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 |
||
17757 | 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:] |
|
17757 | 165 |
Claus Gittinger |
5755 | 166 |
|
167 |
" |
|
168 |
! ! |
|
169 |
||
170 |
!Object class methodsFor:'initialization'! |
|
171 |
||
5971 | 172 |
initSignals |
173 |
"called only once - initialize signals" |
|
174 |
||
175 |
ErrorSignal := Error. |
|
176 |
||
177 |
ControlInterrupt notifierString:'control interrupted'. |
|
178 |
||
179 |
HaltSignal := HaltInterrupt. |
|
180 |
HaltSignal notifierString:'halt encountered'. |
|
181 |
||
5977 | 182 |
MessageNotUnderstoodSignal := MessageNotUnderstood. |
5971 | 183 |
MessageNotUnderstoodSignal notifierString:'message not understood'. |
184 |
||
6000 | 185 |
PrimitiveFailureSignal := PrimitiveFailure. |
5971 | 186 |
PrimitiveFailureSignal notifierString:'primitive failed'. |
187 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
188 |
InternalErrorSignal := VMInternalError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
189 |
|
5971 | 190 |
UserInterruptSignal := UserInterrupt. |
191 |
UserInterruptSignal notifierString:'user Interrupt'. |
|
192 |
||
6146 | 193 |
RecursionInterruptSignal := RecursionError. |
5971 | 194 |
RecursionInterruptSignal notifierString:'recursion limit reached'. |
195 |
||
5977 | 196 |
NotFoundSignal := NotFoundError. |
5971 | 197 |
NotFoundSignal notifierString:'no such element'. |
198 |
||
5977 | 199 |
IndexNotFoundSignal := IndexNotFoundError. |
5971 | 200 |
IndexNotFoundSignal notifierString:'bad index: '. |
201 |
||
5977 | 202 |
SubscriptOutOfBoundsSignal := SubscriptOutOfBoundsError. |
5971 | 203 |
SubscriptOutOfBoundsSignal notifierString:'subscript out of bounds: '. |
204 |
||
5977 | 205 |
NonIntegerIndexSignal := NonIntegerIndexError. |
206 |
NonIntegerIndexSignal notifierString:'index must be integer'. |
|
207 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
208 |
KeyNotFoundSignal := KeyNotFoundError. |
5977 | 209 |
KeyNotFoundSignal notifierString:'no such key: '. |
210 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
211 |
ElementOutOfBoundsSignal := ElementBoundsError. |
5971 | 212 |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
213 |
UserNotificationSignal := UserNotification. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
214 |
WarningSignal := Warning. |
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
215 |
InformationSignal := UserInformation. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
216 |
ActivityNotificationSignal := ActivityNotification. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
217 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
218 |
DeepCopyErrorSignal := DeepCopyError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
219 |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
220 |
AbortSignal := AbortOperationRequest. |
6877
ab4e7d42f9f8
AbortAllOperation - now class based
Claus Gittinger <cg@exept.de>
parents:
6874
diff
changeset
|
221 |
AbortAllSignal := AbortAllOperationRequest. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
222 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
223 |
OSSignalInterruptSignal := OSSignalInterrupt. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
224 |
RecursiveStoreStringSignal := RecursiveStoreError. |
5971 | 225 |
|
5980 | 226 |
" |
227 |
Object initSignals |
|
228 |
" |
|
5971 | 229 |
|
230 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
231 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
232 |
"Modified: / 16.11.2001 / 16:30:08 / cg" |
5971 | 233 |
! |
234 |
||
5755 | 235 |
initialize |
236 |
"called only once - initialize signals" |
|
237 |
||
238 |
ErrorSignal isNil ifTrue:[ |
|
17757 | 239 |
self initSignals |
5971 | 240 |
]. |
241 |
||
242 |
ObjectAttributes isNil ifTrue:[ |
|
17757 | 243 |
ObjectAttributes := WeakIdentityDictionary new. |
5971 | 244 |
]. |
245 |
Dependencies isNil ifTrue:[ |
|
17757 | 246 |
Dependencies := WeakDependencyDictionary new. |
5971 | 247 |
]. |
248 |
NonWeakDependencies isNil ifTrue:[ |
|
17757 | 249 |
NonWeakDependencies := IdentityDictionary new. |
5971 | 250 |
]. |
251 |
SynchronizationSemaphores isNil ifTrue:[ |
|
17757 | 252 |
SynchronizationSemaphores := WeakIdentityDictionary new. |
5971 | 253 |
]. |
5755 | 254 |
FinalizationLobby isNil ifTrue:[ |
17757 | 255 |
FinalizationLobby := Registry new. |
5755 | 256 |
]. |
257 |
||
258 |
"/ initialize InfoPrinting to the VM's infoPrint setting |
|
259 |
"/ (which can be turned off via a command line argument) |
|
260 |
InfoPrinting := ObjectMemory infoPrinting. |
|
261 |
||
262 |
"Object initialize" |
|
263 |
||
264 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
265 |
"Modified: / 3.2.1998 / 18:55:09 / cg" |
|
266 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
267 |
! ! |
|
268 |
||
7303 | 269 |
!Object class methodsFor:'Compatibility-ST80'! |
5755 | 270 |
|
271 |
rootError |
|
272 |
"return the signal used for error/error: - handling. |
|
273 |
Same as errorSignal for ST80 compatibility." |
|
274 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
275 |
^ Error |
5755 | 276 |
|
277 |
"Created: / 15.1.1998 / 23:47:05 / stefan" |
|
278 |
! ! |
|
279 |
||
280 |
!Object class methodsFor:'Signal constants'! |
|
281 |
||
10460 | 282 |
abortAllSignal |
5755 | 283 |
"return the signal used to abort user actions (much like AbortSignal). |
284 |
This signal is supposed to abort multiple operation actions, and get out of |
|
285 |
the loop (such as when confirming multiple class deletions etc.)" |
|
286 |
||
287 |
^ AbortAllSignal |
|
288 |
! |
|
289 |
||
10460 | 290 |
abortSignal |
5755 | 291 |
"return the signal used to abort user actions. This signal is only |
292 |
raised if caught (by the debugger), and will lead way out of the |
|
293 |
currently active doIt/printIt or inspectIt. (also some others use |
|
294 |
this for a save abort)" |
|
295 |
||
8521 | 296 |
^ AbortOperationRequest |
5755 | 297 |
! |
298 |
||
299 |
activityNotificationSignal |
|
300 |
"return the signal used for activity notifications. |
|
301 |
A handler for this signal gets all #activityNotification: sends" |
|
302 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
303 |
^ ActivityNotification |
5755 | 304 |
! |
305 |
||
17786 | 306 |
ambiguousMessageSignal |
307 |
"return the signal used for ambiguousMessage: - error handling" |
|
308 |
||
309 |
^ AmbiguousMessage |
|
310 |
||
311 |
"Created: / 21-07-2010 / 15:39:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
312 |
! |
|
313 |
||
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
314 |
conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
315 |
"return the signal used for conversion error handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
316 |
|
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
317 |
^ ConversionError |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
318 |
! |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
319 |
|
10460 | 320 |
deepCopyErrorSignal |
5755 | 321 |
"return the signal raised when a deepcopy is asked for |
322 |
an object which cannot do this (for example, BlockClosures |
|
323 |
or Contexts)." |
|
324 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
325 |
^ DeepCopyError |
5755 | 326 |
! |
327 |
||
328 |
elementOutOfBoundsSignal |
|
329 |
"return the signal used for element error reporting |
|
330 |
(this signal is used for example when a value not in 0..255 is to |
|
331 |
be put into a bytearray)" |
|
332 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
333 |
^ ElementBoundsError |
5755 | 334 |
! |
335 |
||
336 |
errorSignal |
|
337 |
"return the signal used for error/error: - handling" |
|
338 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
339 |
^ Error |
5755 | 340 |
! |
341 |
||
342 |
haltSignal |
|
343 |
"return the signal used for halt/halt: - handling" |
|
344 |
||
345 |
^ HaltSignal |
|
346 |
! |
|
347 |
||
348 |
indexNotFoundSignal |
|
349 |
"return the signal used for bad index error reporting. |
|
350 |
This is also the parentSignal of the nonIntegerIndex- and |
|
351 |
subscriptOutOfBoundsSignal" |
|
352 |
||
353 |
^ IndexNotFoundSignal |
|
354 |
||
355 |
"Created: / 8.11.1997 / 19:15:48 / cg" |
|
356 |
! |
|
357 |
||
10460 | 358 |
informationSignal |
359 |
"return the signal used for informations. |
|
5755 | 360 |
A handler for this signal gets all #information: sends" |
361 |
||
362 |
^ InformationSignal |
|
363 |
! |
|
364 |
||
365 |
internalErrorSignal |
|
366 |
"return the signal used to report internal (VM-) errors." |
|
367 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
368 |
^ VMInternalError |
5755 | 369 |
! |
370 |
||
10460 | 371 |
keyNotFoundSignal |
5755 | 372 |
"return the signal used for no such key error reporting" |
373 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
374 |
^ KeyNotFoundError |
5755 | 375 |
! |
376 |
||
377 |
messageNotUnderstoodSignal |
|
378 |
"return the signal used for doesNotUnderstand: - error handling" |
|
379 |
||
380 |
^ MessageNotUnderstoodSignal |
|
381 |
! |
|
382 |
||
10460 | 383 |
nonIntegerIndexSignal |
5755 | 384 |
"return the signal used for bad subscript error reporting" |
385 |
||
386 |
^ NonIntegerIndexSignal |
|
387 |
! |
|
388 |
||
10460 | 389 |
notFoundSignal |
5755 | 390 |
"return the signal used for no element found error reporting" |
391 |
||
392 |
^ NotFoundSignal |
|
393 |
! |
|
394 |
||
7644
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
395 |
notifySignal |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
396 |
"return the parent of all notification signals." |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
397 |
|
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
398 |
^ Notification |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
399 |
! |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
400 |
|
10460 | 401 |
osSignalInterruptSignal |
5755 | 402 |
"return the signal used for OS-signal error reporting; |
403 |
This is only raised if handled - otherwise, a debugger is entered." |
|
404 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
405 |
^ OSSignalInterrupt |
5755 | 406 |
|
407 |
"Modified: / 12.6.1998 / 16:27:26 / cg" |
|
408 |
! |
|
409 |
||
410 |
primitiveFailureSignal |
|
411 |
"return the signal used for primitiveFailed - error handling" |
|
412 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
413 |
^ PrimitiveFailure |
5755 | 414 |
! |
415 |
||
416 |
privateMethodSignal |
|
417 |
"return the signal used for privateMethod - error handling" |
|
418 |
||
419 |
^ MessageNotUnderstoodSignal |
|
420 |
! |
|
421 |
||
10460 | 422 |
recursionInterruptSignal |
5755 | 423 |
"return the signal used for recursion overflow error handling" |
424 |
||
425 |
^ RecursionInterruptSignal |
|
426 |
! |
|
427 |
||
428 |
recursiveStoreStringSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
429 |
"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
|
430 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
431 |
^ RecursiveStoreError |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
432 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
433 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
434 |
RecursiveStoreError handle:[:ex | |
17757 | 435 |
self halt |
5755 | 436 |
] do:[ |
17757 | 437 |
|a| |
438 |
||
439 |
a := Array new:1. |
|
440 |
a at:1 put:a. |
|
441 |
a storeOn:Transcript |
|
5755 | 442 |
] |
443 |
" |
|
444 |
||
445 |
" |
|
446 |
|a| |
|
447 |
||
448 |
a := Array new:1. |
|
449 |
a at:1 put:a. |
|
450 |
a storeOn:Transcript |
|
451 |
" |
|
452 |
! |
|
453 |
||
5980 | 454 |
subclassResponsibilitySignal |
455 |
"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
|
456 |
(this signal is used to signal incomplete subclasses - i.e. a programmers error)" |
5980 | 457 |
|
458 |
^ SubclassResponsibilityError |
|
459 |
! |
|
460 |
||
5755 | 461 |
subscriptOutOfBoundsSignal |
462 |
"return the signal used for subscript error reporting. |
|
463 |
(this signal is used for example when an array is accessed with an |
|
464 |
index less than 1 or greater than the array size)" |
|
465 |
||
466 |
^ SubscriptOutOfBoundsSignal |
|
467 |
! |
|
468 |
||
469 |
userInterruptSignal |
|
470 |
"return the signal used for ^C interrupts handling" |
|
471 |
||
472 |
^ UserInterruptSignal |
|
473 |
! |
|
474 |
||
475 |
userNotificationSignal |
|
476 |
"the parent signal used with information and warnings. |
|
477 |
Handling this allows handling of both information- and warning notifications." |
|
478 |
||
479 |
^ UserNotificationSignal |
|
480 |
! |
|
481 |
||
10460 | 482 |
warningSignal |
5755 | 483 |
"return the signal used for warnings. |
484 |
A handler for this signal gets all #warn: sends" |
|
485 |
||
486 |
^ WarningSignal |
|
487 |
! ! |
|
488 |
||
489 |
!Object class methodsFor:'info messages'! |
|
490 |
||
491 |
infoPrinting |
|
492 |
"return the flag which controls information messages." |
|
493 |
||
494 |
^ InfoPrinting |
|
495 |
! |
|
496 |
||
497 |
infoPrinting:aBoolean |
|
498 |
"{ Pragma: +optSpace }" |
|
499 |
||
500 |
"turn on/off printing of information messages. |
|
501 |
If the argument, aBoolean is false, infoPrint will not output |
|
502 |
messages. The default is true." |
|
503 |
||
504 |
InfoPrinting := aBoolean |
|
505 |
! ! |
|
506 |
||
507 |
!Object class methodsFor:'queries'! |
|
508 |
||
8892 | 509 |
isAbstract |
11221 | 510 |
"Return if this class is an abstract class. |
511 |
True is returned for Object here; false for subclasses. |
|
512 |
Abstract subclasses must redefine again." |
|
513 |
||
8892 | 514 |
^ self == Object |
515 |
! |
|
516 |
||
5755 | 517 |
isBuiltInClass |
518 |
"return true, if this class is known by the run-time-system, |
|
519 |
i.e. you cannot add/remove instance variables without recompiling |
|
520 |
the VM. |
|
521 |
Here, true is returned for myself, false for subclasses." |
|
522 |
||
523 |
^ self == Object |
|
524 |
||
525 |
"Modified: 23.4.1996 / 16:00:07 / cg" |
|
526 |
! ! |
|
527 |
||
17751 | 528 |
|
17795 | 529 |
|
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
530 |
!Object methodsFor:'Compatibility-Dolphin'! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
531 |
|
11161 | 532 |
stbFixup: anSTBInFiler at: newObjectIndex |
533 |
"Answer the true object that must be used to represent the receiver when read from anSTBInFiler. |
|
534 |
Typically this is overridden by subclasses of STBProxy to answer the proxied object. Other classes |
|
535 |
may also override this method to effectively 'one way become' the receiver to some other object" |
|
536 |
||
537 |
^ self |
|
538 |
! |
|
539 |
||
10460 | 540 |
trigger:anAspect |
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
541 |
self changed:anAspect |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
542 |
! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
543 |
|
10460 | 544 |
trigger:anAspect with:anArgument |
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
545 |
self changed:anAspect with:anArgument |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
546 |
! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
547 |
|
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
548 |
when:anAspect sendTo:anObject |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
549 |
self expressInterestIn:anAspect for:anObject sendBack:anAspect |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
550 |
! ! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
551 |
|
9375 | 552 |
!Object methodsFor:'Compatibility-ST/V'! |
553 |
||
554 |
triggerEvent:aSymbol |
|
555 |
self changed:aSymbol |
|
556 |
! ! |
|
557 |
||
7261 | 558 |
!Object methodsFor:'Compatibility-ST80'! |
5755 | 559 |
|
560 |
isMetaclass |
|
561 |
^ self isMeta |
|
562 |
! ! |
|
563 |
||
7261 | 564 |
!Object methodsFor:'Compatibility-Squeak'! |
5755 | 565 |
|
566 |
asString |
|
567 |
^ self printString |
|
568 |
! |
|
569 |
||
9071 | 570 |
becomeForward:anotherObject |
571 |
self becomeSameAs:anotherObject |
|
572 |
! |
|
573 |
||
574 |
becomeForward:anotherObject copyHash:copyHash |
|
575 |
copyHash ifTrue:[ self error:'unsupported operation' ]. |
|
576 |
self becomeSameAs:anotherObject |
|
577 |
! |
|
578 |
||
5755 | 579 |
clone |
580 |
^ self shallowCopy |
|
581 |
! |
|
582 |
||
6146 | 583 |
copyTwoLevel |
584 |
"one more level than a shallowCopy" |
|
585 |
||
586 |
^ self copyToLevel:2 |
|
587 |
||
588 |
" |
|
589 |
|original copy elL1 elL2 elL3 copyOfElL1| |
|
590 |
||
591 |
original := Array new:3. |
|
592 |
original at:1 put:1234. |
|
593 |
original at:2 put:'hello'. |
|
594 |
original at:3 put:(elL1 := Array new:3). |
|
595 |
||
596 |
elL1 at:1 put:1234. |
|
597 |
elL1 at:2 put:'hello'. |
|
598 |
elL1 at:3 put:(elL2 := Array new:3). |
|
599 |
||
600 |
elL2 at:1 put:1234. |
|
601 |
elL2 at:2 put:'hello'. |
|
602 |
elL2 at:3 put:(elL3 := Array new:3). |
|
603 |
||
604 |
elL3 at:1 put:1234. |
|
605 |
elL3 at:2 put:'hello'. |
|
606 |
elL3 at:3 put:(Array new:3). |
|
607 |
||
608 |
copy := original copyTwoLevel. |
|
609 |
(original at:2) ~~ (copy at:2) ifFalse:[self halt]. |
|
610 |
(original at:3) ~~ (copy at:3) ifFalse:[self halt]. |
|
611 |
||
612 |
copyOfElL1 := copy at:3. |
|
613 |
(elL1 at:2) == (copyOfElL1 at:2) ifFalse:[self halt]. |
|
614 |
(elL1 at:3) == (copyOfElL1 at:3) ifFalse:[self halt]. |
|
615 |
" |
|
616 |
! |
|
617 |
||
7320 | 618 |
explore |
619 |
(self confirm:'The Squeak explorer has not yet been ported to ST/X\\Inspect instead ?' withCRs) |
|
620 |
ifTrue:[ |
|
17757 | 621 |
self inspect |
7320 | 622 |
] |
623 |
! |
|
624 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
625 |
inform: aString |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
626 |
"Display a message for the user to read and then dismiss." |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
627 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
628 |
self information:aString |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
629 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
630 |
|
9335 | 631 |
isInMemory |
632 |
"All normal objects are." |
|
633 |
||
634 |
^ true |
|
635 |
! |
|
636 |
||
5755 | 637 |
stringForReadout |
17757 | 638 |
^ self stringRepresentation |
5755 | 639 |
! |
640 |
||
641 |
stringRepresentation |
|
17757 | 642 |
"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" |
643 |
||
644 |
^ self printString |
|
5755 | 645 |
! |
646 |
||
9146
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
647 |
valueWithPossibleArguments:argArray |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
648 |
^ self |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
649 |
! |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
650 |
|
5755 | 651 |
veryDeepCopy |
8383 | 652 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 653 |
! ! |
654 |
||
7567 | 655 |
!Object methodsFor:'Compatibility-VW'! |
656 |
||
8637 | 657 |
isCharacters |
658 |
"added for visual works compatibility" |
|
659 |
^ false |
|
660 |
! |
|
661 |
||
7567 | 662 |
keyNotFoundError:aKey |
663 |
"VW compatibility" |
|
664 |
||
665 |
self errorKeyNotFound:aKey. |
|
666 |
! |
|
667 |
||
668 |
oneWayBecome:anotherObject |
|
669 |
^ self becomeSameAs:anotherObject |
|
670 |
||
671 |
" |
|
672 |
|arr o1 o2| |
|
673 |
||
674 |
arr := Array new:2. |
|
675 |
arr at:1 put:(o1 := Object new). |
|
676 |
arr at:2 put:(o2 := Point new). |
|
677 |
o1 oneWayBecome:o2. |
|
678 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
679 |
" |
|
680 |
" |
|
681 |
|arr o1 o2| |
|
682 |
||
683 |
arr := Array new:2. |
|
684 |
arr at:1 put:(o1 := Object new). |
|
685 |
arr at:2 put:(o2 := Point new). |
|
686 |
o1 becomeSameAs:o2. |
|
687 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
688 |
" |
|
689 |
! ! |
|
690 |
||
17795 | 691 |
|
692 |
||
5755 | 693 |
!Object methodsFor:'accessing'! |
694 |
||
695 |
at:index |
|
696 |
"return the indexed instance variable with index, anInteger; |
|
697 |
this method can be redefined in subclasses." |
|
698 |
||
699 |
^ self basicAt:index |
|
700 |
! |
|
701 |
||
702 |
at:index put:anObject |
|
703 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
704 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
|
705 |
||
706 |
^ self basicAt:index put:anObject |
|
707 |
||
708 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
|
709 |
! |
|
710 |
||
711 |
basicAt:index |
|
712 |
"return the indexed instance variable with index, anInteger. |
|
713 |
Trigger an error if the receiver has no indexed instance variables. |
|
714 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
715 |
||
716 |
%{ /* NOCONTEXT */ |
|
717 |
||
718 |
REGISTER int nbytes, indx; |
|
719 |
OBJ myClass; |
|
720 |
REGISTER char *pFirst; |
|
721 |
REGISTER int n; |
|
722 |
||
723 |
/* |
|
724 |
* notice the missing test for self being a nonNilObject - |
|
725 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
726 |
* and SmallInteger |
|
727 |
*/ |
|
728 |
if (__isSmallInteger(index)) { |
|
17757 | 729 |
myClass = __qClass(self); |
730 |
indx = __intVal(index) - 1; |
|
731 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
732 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
733 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
734 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
735 |
||
736 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
737 |
case __MASKSMALLINT(POINTERARRAY): |
|
738 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
739 |
/* |
|
740 |
* pointers |
|
741 |
*/ |
|
742 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
743 |
OBJ *op; |
|
744 |
||
745 |
op = (OBJ *)pFirst + indx; |
|
746 |
RETURN ( *op ); |
|
747 |
} |
|
748 |
break; |
|
749 |
||
750 |
case __MASKSMALLINT(BYTEARRAY): |
|
751 |
/* |
|
752 |
* (unsigned) bytes |
|
753 |
*/ |
|
754 |
if ((unsigned)indx < nbytes) { |
|
755 |
unsigned char *cp; |
|
756 |
||
757 |
cp = (unsigned char *)pFirst + indx; |
|
758 |
RETURN ( __mkSmallInteger( (*cp & 0xFF)) ); |
|
759 |
} |
|
760 |
break; |
|
761 |
||
762 |
case __MASKSMALLINT(FLOATARRAY): |
|
763 |
/* |
|
764 |
* native floats |
|
765 |
*/ |
|
766 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
767 |
float *fp; |
|
768 |
float f; |
|
769 |
OBJ v; |
|
770 |
||
771 |
fp = (float *)pFirst + indx; |
|
772 |
f = *fp; |
|
773 |
if (f == 0.0) { |
|
774 |
v = __float0; |
|
775 |
} else { |
|
776 |
__qMKSFLOAT(v, f); |
|
777 |
} |
|
778 |
RETURN (v); |
|
779 |
} |
|
780 |
break; |
|
781 |
||
782 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
783 |
/* |
|
784 |
* native doubles |
|
785 |
*/ |
|
5755 | 786 |
#ifdef __NEED_DOUBLE_ALIGN |
17757 | 787 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
788 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
789 |
||
790 |
pFirst += delta; |
|
791 |
nbytes -= delta; |
|
792 |
} |
|
5755 | 793 |
#endif |
17757 | 794 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
795 |
double *dp; |
|
796 |
double d; |
|
797 |
OBJ v; |
|
798 |
||
799 |
dp = (double *)pFirst + indx; |
|
800 |
d = *dp; |
|
801 |
if (d == 0.0) { |
|
802 |
v = __float0; |
|
803 |
} else { |
|
804 |
__qMKFLOAT(v, d); |
|
805 |
} |
|
806 |
RETURN (v); |
|
807 |
} |
|
808 |
break; |
|
809 |
||
810 |
case __MASKSMALLINT(WORDARRAY): |
|
811 |
/* |
|
812 |
* unsigned 16bit ints |
|
813 |
*/ |
|
814 |
/* Notice: the hard coded shifts are by purpose; |
|
815 |
* it makes us independent of the short-size of the machine |
|
816 |
*/ |
|
817 |
if ((unsigned)indx < (nbytes>>1)) { |
|
818 |
unsigned short *sp; |
|
819 |
||
820 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
821 |
RETURN ( __mkSmallInteger( (*sp & 0xFFFF)) ); |
|
822 |
} |
|
823 |
break; |
|
824 |
||
825 |
case __MASKSMALLINT(SWORDARRAY): |
|
826 |
/* |
|
827 |
* signed 16bit ints |
|
828 |
*/ |
|
829 |
/* Notice: the hard coded shifts are by purpose; |
|
830 |
* it makes us independent of the short-size of the machine |
|
831 |
*/ |
|
832 |
if ((unsigned)indx < (nbytes>>1)) { |
|
833 |
short *ssp; |
|
834 |
||
835 |
ssp = (short *)(pFirst + (indx<<1)); |
|
836 |
RETURN ( __mkSmallInteger( (*ssp) )); |
|
837 |
} |
|
838 |
break; |
|
839 |
||
840 |
case __MASKSMALLINT(LONGARRAY): |
|
841 |
/* |
|
842 |
* unsigned 32bit ints |
|
843 |
*/ |
|
844 |
/* Notice: the hard coded shifts are by purpose; |
|
845 |
* it makes us independent of the int-size of the machine |
|
846 |
*/ |
|
847 |
if ((unsigned)indx < (nbytes>>2)) { |
|
848 |
unsigned int32 ul; |
|
849 |
unsigned int32 *lp; |
|
850 |
||
851 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
852 |
ul = *lp; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
853 |
#if __POINTER_SIZE__ == 8 |
17757 | 854 |
{ |
855 |
unsigned INT ull = (unsigned INT)ul; |
|
856 |
RETURN ( __mkSmallInteger(ull) ); |
|
857 |
} |
|
5755 | 858 |
#else |
17757 | 859 |
if (ul <= _MAX_INT) { |
860 |
RETURN ( __mkSmallInteger(ul) ); |
|
861 |
} |
|
862 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 863 |
#endif |
17757 | 864 |
} |
865 |
break; |
|
866 |
||
867 |
case __MASKSMALLINT(SLONGARRAY): |
|
868 |
/* |
|
869 |
* signed 32bit ints |
|
870 |
*/ |
|
871 |
/* Notice: the hard coded shifts are by purpose; |
|
872 |
* it makes us independent of the int-size of the machine |
|
873 |
*/ |
|
874 |
if ((unsigned)indx < (nbytes>>2)) { |
|
875 |
int32 *slp; |
|
876 |
int32 l; |
|
877 |
||
878 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
879 |
l = *slp; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
880 |
#if __POINTER_SIZE__ == 8 |
17757 | 881 |
{ |
882 |
INT ll = (INT)l; |
|
883 |
RETURN ( __mkSmallInteger(ll) ); |
|
884 |
} |
|
5755 | 885 |
#else |
17757 | 886 |
if (__ISVALIDINTEGER(l)) { |
887 |
RETURN ( __mkSmallInteger(l) ); |
|
888 |
} |
|
889 |
RETURN ( __MKLARGEINT(l) ); |
|
5755 | 890 |
#endif |
17757 | 891 |
} |
892 |
break; |
|
893 |
||
894 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
895 |
/* |
|
896 |
* signed 64bit longlongs |
|
897 |
*/ |
|
5755 | 898 |
#ifdef __NEED_LONGLONG_ALIGN |
17757 | 899 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
900 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
901 |
||
902 |
pFirst += delta; |
|
903 |
nbytes -= delta; |
|
904 |
} |
|
5755 | 905 |
#endif |
17757 | 906 |
/* Notice: the hard coded shifts are by purpose; |
907 |
* it makes us independent of the long/longlong-size of the machine |
|
908 |
*/ |
|
909 |
if ((unsigned)indx < (nbytes>>3)) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
910 |
#if __POINTER_SIZE__ == 8 |
17757 | 911 |
INT *slp, ll; |
912 |
||
913 |
slp = (INT *)(pFirst + (indx<<3)); |
|
914 |
ll = *slp; |
|
915 |
if (__ISVALIDINTEGER(ll)) { |
|
916 |
RETURN ( __mkSmallInteger(ll) ); |
|
917 |
} |
|
918 |
RETURN ( __MKLARGEINT(ll) ); |
|
5755 | 919 |
#else |
17757 | 920 |
__int64__ *llp; |
921 |
||
922 |
llp = (__int64__ *)(pFirst + (indx<<3)); |
|
923 |
RETURN (__MKINT64(llp)); |
|
5755 | 924 |
#endif |
17757 | 925 |
} |
926 |
break; |
|
927 |
||
928 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
929 |
/* |
|
930 |
* unsigned 64bit longlongs |
|
931 |
*/ |
|
5755 | 932 |
#ifdef __NEED_LONGLONG_ALIGN |
17757 | 933 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
934 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
935 |
||
936 |
pFirst += delta; |
|
937 |
nbytes -= delta; |
|
938 |
} |
|
5755 | 939 |
#endif |
17757 | 940 |
/* Notice: the hard coded shifts are by purpose; |
941 |
* it makes us independent of the long/longlong-size of the machine |
|
942 |
*/ |
|
943 |
if ((unsigned)indx < (nbytes>>3)) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8892
diff
changeset
|
944 |
#if __POINTER_SIZE__ == 8 |
17757 | 945 |
unsigned INT *ulp, ul; |
946 |
||
947 |
ulp = (unsigned INT *)(pFirst + (indx<<3)); |
|
948 |
ul = *ulp; |
|
949 |
if (ul <= _MAX_INT) { |
|
950 |
RETURN ( __mkSmallInteger(ul) ); |
|
951 |
} |
|
952 |
RETURN ( __MKULARGEINT(ul) ); |
|
5755 | 953 |
#else |
17757 | 954 |
__uint64__ *llp; |
955 |
||
956 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
957 |
RETURN (__MKUINT64(llp)); |
|
5755 | 958 |
#endif |
17757 | 959 |
} |
960 |
break; |
|
961 |
} |
|
5755 | 962 |
} |
963 |
%}. |
|
7216 | 964 |
^ self indexNotIntegerOrOutOfBounds:index |
5755 | 965 |
! |
966 |
||
967 |
basicAt:index put:anObject |
|
968 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
969 |
Returns anObject (sigh). |
|
970 |
Trigger an error if the receiver has no indexed instance variables. |
|
971 |
||
972 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
973 |
||
974 |
%{ /* NOCONTEXT */ |
|
975 |
||
976 |
register int nbytes, indx; |
|
977 |
OBJ myClass; |
|
978 |
register char *pFirst; |
|
979 |
/* int nInstBytes, ninstvars, flags; */ |
|
980 |
REGISTER int n; |
|
981 |
unsigned int u; |
|
982 |
int val; |
|
983 |
||
984 |
/* notice the missing test for self being a nonNilObject - |
|
985 |
this can be done since basicAt: is defined both in UndefinedObject |
|
986 |
and SmallInteger */ |
|
987 |
||
988 |
if (__isSmallInteger(index)) { |
|
17757 | 989 |
indx = __intVal(index) - 1; |
990 |
myClass = __qClass(self); |
|
991 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
992 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
993 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
994 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
995 |
||
996 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
997 |
case __MASKSMALLINT(POINTERARRAY): |
|
998 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
999 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
1000 |
OBJ *op; |
|
1001 |
||
1002 |
op = (OBJ *)pFirst + indx; |
|
1003 |
*op = anObject; |
|
1004 |
__STORE(self, anObject); |
|
1005 |
RETURN ( anObject ); |
|
1006 |
} |
|
1007 |
break; |
|
1008 |
||
1009 |
case __MASKSMALLINT(BYTEARRAY): |
|
1010 |
if (__isSmallInteger(anObject)) { |
|
1011 |
val = __intVal(anObject); |
|
1012 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
1013 |
if ((unsigned)indx < nbytes) { |
|
1014 |
char *cp; |
|
1015 |
||
1016 |
cp = pFirst + indx; |
|
1017 |
*cp = val; |
|
1018 |
RETURN ( anObject ); |
|
1019 |
} |
|
1020 |
} |
|
1021 |
} |
|
1022 |
break; |
|
1023 |
||
1024 |
case __MASKSMALLINT(FLOATARRAY): |
|
1025 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
1026 |
float *fp; |
|
1027 |
||
1028 |
fp = (float *)pFirst + indx; |
|
1029 |
if (anObject != nil) { |
|
1030 |
if (! __isSmallInteger(anObject)) { |
|
1031 |
if (__qIsFloatLike(anObject)) { |
|
1032 |
*fp = (float)(__floatVal(anObject)); |
|
1033 |
RETURN ( anObject ); |
|
1034 |
} |
|
1035 |
if (__qIsShortFloat(anObject)) { |
|
1036 |
*fp = __shortFloatVal(anObject); |
|
1037 |
RETURN ( anObject ); |
|
1038 |
} |
|
1039 |
} else { |
|
1040 |
*fp = (float) __intVal(anObject); |
|
1041 |
RETURN ( anObject ); |
|
1042 |
} |
|
1043 |
} |
|
1044 |
} |
|
1045 |
break; |
|
1046 |
||
1047 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1048 |
#ifdef __NEED_DOUBLE_ALIGN |
17757 | 1049 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1050 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1051 |
||
1052 |
pFirst += delta; |
|
1053 |
nbytes -= delta; |
|
1054 |
} |
|
5755 | 1055 |
#endif |
17757 | 1056 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
1057 |
double *dp; |
|
1058 |
||
1059 |
dp = (double *)pFirst + indx; |
|
1060 |
if (anObject != nil) { |
|
1061 |
if (! __isSmallInteger(anObject)) { |
|
1062 |
if (__qIsFloatLike(anObject)) { |
|
1063 |
*dp = __floatVal(anObject); |
|
1064 |
RETURN ( anObject ); |
|
1065 |
} |
|
1066 |
if (__qIsShortFloat(anObject)) { |
|
1067 |
*dp = (double)__shortFloatVal(anObject); |
|
1068 |
RETURN ( anObject ); |
|
1069 |
} |
|
1070 |
} else { |
|
1071 |
*dp = (double) __intVal(anObject); |
|
1072 |
RETURN ( anObject ); |
|
1073 |
} |
|
1074 |
} |
|
1075 |
} |
|
1076 |
break; |
|
1077 |
||
1078 |
case __MASKSMALLINT(WORDARRAY): |
|
1079 |
if (__isSmallInteger(anObject)) { |
|
1080 |
val = __intVal(anObject); |
|
1081 |
if ((unsigned)val <= 0xFFFF) { |
|
1082 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1083 |
unsigned short *sp; |
|
1084 |
||
1085 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
1086 |
*sp = val; |
|
1087 |
RETURN ( anObject ); |
|
1088 |
} |
|
1089 |
} |
|
1090 |
} |
|
1091 |
break; |
|
1092 |
||
1093 |
case __MASKSMALLINT(SWORDARRAY): |
|
1094 |
if (__isSmallInteger(anObject)) { |
|
1095 |
val = __intVal(anObject); |
|
1096 |
if ((val >= -32768) && (val < 32768)) { |
|
1097 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1098 |
short *ssp; |
|
1099 |
||
1100 |
ssp = (short *)(pFirst + (indx<<1)); |
|
1101 |
*ssp = val; |
|
1102 |
RETURN ( anObject ); |
|
1103 |
} |
|
1104 |
} |
|
1105 |
} |
|
1106 |
break; |
|
1107 |
||
1108 |
case __MASKSMALLINT(SLONGARRAY): |
|
1109 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1110 |
int32 *slp; |
|
1111 |
||
1112 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
1113 |
if (__isSmallInteger(anObject)) { |
|
1114 |
*slp = __intVal(anObject); |
|
1115 |
RETURN ( anObject ); |
|
1116 |
} |
|
1117 |
n = __signedLongIntVal(anObject); |
|
1118 |
/* |
|
1119 |
* zero means failure for an int larger than 4 bytes |
|
1120 |
* (would be a smallInteger) |
|
1121 |
*/ |
|
1122 |
if (n) { |
|
1123 |
*slp = n; |
|
1124 |
RETURN ( anObject ); |
|
1125 |
} |
|
1126 |
} |
|
1127 |
break; |
|
1128 |
||
1129 |
case __MASKSMALLINT(LONGARRAY): |
|
1130 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1131 |
unsigned int32 *lp; |
|
1132 |
||
1133 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
1134 |
if (anObject == __mkSmallInteger(0)) { |
|
1135 |
*lp = 0; |
|
1136 |
RETURN ( anObject ); |
|
1137 |
} |
|
1138 |
u = __longIntVal(anObject); |
|
1139 |
/* |
|
1140 |
* zero means failure for an int larger than 4 bytes |
|
1141 |
* (would be a smallInteger) |
|
1142 |
*/ |
|
1143 |
if (u) { |
|
1144 |
*lp = u; |
|
1145 |
RETURN ( anObject ); |
|
1146 |
} |
|
1147 |
} |
|
1148 |
break; |
|
1149 |
||
1150 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1151 |
#ifdef __NEED_LONGLONG_ALIGN |
17757 | 1152 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1153 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1154 |
||
1155 |
pFirst += delta; |
|
1156 |
nbytes -= delta; |
|
1157 |
} |
|
5755 | 1158 |
#endif |
17757 | 1159 |
if ((unsigned)indx < (nbytes>>3)) { |
1160 |
__int64__ ll; |
|
1161 |
__int64__ *sllp; |
|
1162 |
||
1163 |
sllp = (__int64__ *)(pFirst + (indx<<3)); |
|
1164 |
||
1165 |
if (anObject == __mkSmallInteger(0)) { |
|
1166 |
ll.lo = ll.hi = 0; |
|
1167 |
*sllp = ll; |
|
1168 |
RETURN ( anObject ); |
|
1169 |
} |
|
1170 |
if (__signedLong64IntVal(anObject, &ll)) { |
|
1171 |
*sllp = ll; |
|
1172 |
RETURN ( anObject ); |
|
1173 |
} |
|
1174 |
} |
|
1175 |
break; |
|
1176 |
||
1177 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
5755 | 1178 |
#ifdef __NEED_LONGLONG_ALIGN |
17757 | 1179 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1180 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1181 |
||
1182 |
pFirst += delta; |
|
1183 |
nbytes -= delta; |
|
1184 |
} |
|
5755 | 1185 |
#endif |
17757 | 1186 |
if ((unsigned)indx < (nbytes>>3)) { |
1187 |
__uint64__ ll; |
|
1188 |
__uint64__ *llp; |
|
1189 |
||
1190 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
1191 |
if (anObject == __mkSmallInteger(0)) { |
|
1192 |
ll.lo = ll.hi = 0; |
|
1193 |
*llp = ll; |
|
1194 |
RETURN ( anObject ); |
|
1195 |
} |
|
1196 |
if (__unsignedLong64IntVal(anObject, &ll)) { |
|
1197 |
*llp = ll; |
|
1198 |
RETURN ( anObject ); |
|
1199 |
} |
|
1200 |
} |
|
1201 |
break; |
|
1202 |
} |
|
5755 | 1203 |
} |
1204 |
%}. |
|
1205 |
index isInteger ifFalse:[ |
|
17757 | 1206 |
" |
1207 |
the index should be an integer number |
|
1208 |
" |
|
1209 |
^ self indexNotInteger:index |
|
5755 | 1210 |
]. |
1211 |
(index between:1 and:self size) ifFalse:[ |
|
17757 | 1212 |
" |
1213 |
the index is less than 1 or greater than the size of the |
|
1214 |
receiver collection |
|
1215 |
" |
|
1216 |
^ self subscriptBoundsError:index |
|
5755 | 1217 |
]. |
1218 |
(self class isFloatsOrDoubles) ifTrue:[ |
|
17757 | 1219 |
anObject isNumber ifTrue:[ |
1220 |
^ self basicAt:index put:(anObject asFloat) |
|
1221 |
] |
|
5755 | 1222 |
]. |
1223 |
anObject isInteger ifFalse:[ |
|
17757 | 1224 |
" |
1225 |
the object to put into the receiver collection |
|
1226 |
should be an integer number |
|
1227 |
" |
|
1228 |
^ self elementNotInteger |
|
5755 | 1229 |
]. |
1230 |
" |
|
1231 |
the object to put into the receiver collection |
|
1232 |
is not an instance of the expected element class, |
|
1233 |
or the value is not within the elements valid range. |
|
1234 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1235 |
^ self elementBoundsError:anObject |
5755 | 1236 |
|
1237 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
|
1238 |
! |
|
1239 |
||
1240 |
byteAt:index |
|
10460 | 1241 |
"return the byte at index. |
5755 | 1242 |
This is only allowed for non-pointer indexed objects |
1243 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1244 |
The receivers indexed instvars are treated as an uninterpreted |
|
1245 |
collection of bytes. |
|
1246 |
Only useful with binary storage." |
|
1247 |
||
1248 |
%{ /* NOCONTEXT */ |
|
1249 |
||
1250 |
REGISTER int indx; |
|
1251 |
int nIndex; |
|
1252 |
REGISTER OBJ slf; |
|
1253 |
REGISTER OBJ cls; |
|
1254 |
||
1255 |
if (__isSmallInteger(index)) { |
|
17757 | 1256 |
slf = self; |
1257 |
if (__isNonNilObject(slf)) { |
|
1258 |
unsigned char *pFirst; |
|
1259 |
int nIndex; |
|
1260 |
||
1261 |
cls = __qClass(slf); |
|
1262 |
||
1263 |
pFirst = __byteArrayVal(slf); |
|
1264 |
pFirst += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1265 |
nIndex = __byteArraySize(slf); |
|
1266 |
indx = __intVal(index) - 1; |
|
1267 |
||
1268 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1269 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1270 |
#ifdef __NEED_DOUBLE_ALIGN |
17757 | 1271 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1272 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1273 |
||
1274 |
pFirst += delta; |
|
1275 |
nIndex -= delta; |
|
1276 |
} |
|
5755 | 1277 |
#endif |
17757 | 1278 |
/* fall into */ |
1279 |
case __MASKSMALLINT(BYTEARRAY): |
|
1280 |
case __MASKSMALLINT(WORDARRAY): |
|
1281 |
case __MASKSMALLINT(LONGARRAY): |
|
1282 |
case __MASKSMALLINT(SWORDARRAY): |
|
1283 |
case __MASKSMALLINT(SLONGARRAY): |
|
1284 |
case __MASKSMALLINT(FLOATARRAY): |
|
1285 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1286 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
|
1287 |
} |
|
1288 |
break; |
|
1289 |
||
1290 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1291 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1292 |
#ifdef __NEED_LONGLONG_ALIGN |
17757 | 1293 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1294 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1295 |
||
1296 |
pFirst += delta; |
|
1297 |
nIndex -= delta; |
|
1298 |
} |
|
5755 | 1299 |
#endif |
17757 | 1300 |
if ((unsigned)indx < (unsigned)nIndex) { |
1301 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
|
1302 |
} |
|
1303 |
break; |
|
1304 |
} |
|
1305 |
} |
|
5755 | 1306 |
} |
1307 |
%}. |
|
1308 |
"/ index not integer or index out of range |
|
1309 |
"/ or non-byte indexable receiver |
|
1310 |
||
1311 |
^ self primitiveFailed |
|
1312 |
||
1313 |
" |
|
1314 |
Point new byteAt:1 |
|
1315 |
(ByteArray with:1 with:2) byteAt:2 |
|
10460 | 1316 |
(WordArray with:1) byteAt:1 |
1317 |
(FloatArray with:1.0) byteAt:2 |
|
1318 |
'hello' byteAt:1 |
|
5755 | 1319 |
" |
1320 |
! |
|
1321 |
||
1322 |
byteAt:index put:byteValue |
|
10460 | 1323 |
"set the byte at index. |
5755 | 1324 |
This is only allowed for non-pointer indexed objects |
1325 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1326 |
The receivers indexed instvars are treated as an uninterpreted |
|
1327 |
collection of bytes. |
|
1328 |
Only useful with binary storage." |
|
1329 |
||
1330 |
%{ /* NOCONTEXT */ |
|
1331 |
||
1332 |
REGISTER int indx; |
|
1333 |
int val, nIndex; |
|
1334 |
REGISTER OBJ slf; |
|
1335 |
REGISTER OBJ cls; |
|
1336 |
||
1337 |
if (__bothSmallInteger(index, byteValue)) { |
|
17757 | 1338 |
val = __intVal(byteValue); |
1339 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
1340 |
slf = self; |
|
1341 |
if (__isNonNilObject(slf)) { |
|
1342 |
cls = __qClass(slf); |
|
1343 |
||
1344 |
indx = __intVal(index) - 1; |
|
1345 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1346 |
case __MASKSMALLINT(BYTEARRAY): |
|
1347 |
case __MASKSMALLINT(WORDARRAY): |
|
1348 |
case __MASKSMALLINT(LONGARRAY): |
|
1349 |
case __MASKSMALLINT(SWORDARRAY): |
|
1350 |
case __MASKSMALLINT(SLONGARRAY): |
|
1351 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1352 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1353 |
case __MASKSMALLINT(FLOATARRAY): |
|
1354 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
1355 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1356 |
nIndex = __byteArraySize(slf); |
|
1357 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1358 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
1359 |
RETURN ( byteValue ); |
|
1360 |
} |
|
1361 |
break; |
|
1362 |
} |
|
1363 |
} |
|
1364 |
} |
|
5755 | 1365 |
} |
1366 |
%}. |
|
1367 |
"/ index not integer or index out of range |
|
1368 |
"/ or non-byte indexable receiver |
|
1369 |
||
1370 |
^ self primitiveFailed |
|
1371 |
||
1372 |
" |
|
1373 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
|
10460 | 1374 |
'hello' copy byteAt:1 put:105; yourself |
5755 | 1375 |
" |
1376 |
! |
|
1377 |
||
1378 |
instVarAt:index |
|
1379 |
"return a non-indexed instance variable; |
|
10460 | 1380 |
peeking into an object this way is not very object oriented |
5755 | 1381 |
- use with care (needed for copy, inspector etc.)" |
1382 |
||
1383 |
%{ /* NOCONTEXT */ |
|
1384 |
||
1385 |
OBJ myClass; |
|
1386 |
int idx, ninstvars; |
|
1387 |
||
1388 |
if (__isSmallInteger(index)) { |
|
17757 | 1389 |
myClass = __Class(self); |
1390 |
idx = __intVal(index) - 1; |
|
1391 |
/* |
|
1392 |
* do not allow returning of non-object fields. |
|
1393 |
* if subclass did not make provisions for that, |
|
1394 |
* we won't do so here ... |
|
1395 |
*/ |
|
1396 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1397 |
if (idx == 0) { |
|
1398 |
RETURN ( nil ) |
|
1399 |
} |
|
1400 |
} |
|
1401 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1402 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1403 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
|
1404 |
} |
|
5755 | 1405 |
} |
7216 | 1406 |
%}. |
1407 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1408 |
! |
1409 |
||
1410 |
instVarAt:index put:value |
|
1411 |
"change a non-indexed instance variable; |
|
10460 | 1412 |
peeking into an object this way is not very object oriented |
5755 | 1413 |
- use with care (needed for copy, inspector etc.)" |
1414 |
||
1415 |
%{ /* NOCONTEXT */ |
|
1416 |
||
1417 |
OBJ myClass; |
|
1418 |
int idx, ninstvars; |
|
1419 |
||
1420 |
if (__isSmallInteger(index)) { |
|
17757 | 1421 |
myClass = __Class(self); |
1422 |
idx = __intVal(index) - 1; |
|
1423 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1424 |
/* |
|
1425 |
* do not allow setting of non-object fields. |
|
1426 |
* if subclass did not make provisions for that, |
|
1427 |
* we won't do so here ... |
|
1428 |
*/ |
|
1429 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1430 |
if (idx == 0) { |
|
1431 |
RETURN ( nil ) |
|
1432 |
} |
|
1433 |
} |
|
1434 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1435 |
__InstPtr(self)->i_instvars[idx] = value; |
|
1436 |
__STORE(self, value); |
|
1437 |
RETURN ( value ); |
|
1438 |
} |
|
5755 | 1439 |
} |
7216 | 1440 |
%}. |
1441 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1442 |
! |
1443 |
||
10460 | 1444 |
instVarNamed:name |
5755 | 1445 |
"return a non-indexed instance variables value by name; |
10460 | 1446 |
peeking into an object this way is not very object oriented |
5755 | 1447 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1448 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1449 |
parsed ad runtime)" |
|
1450 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1451 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1452 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1453 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1454 |
idx isNil ifTrue:[ |
17757 | 1455 |
^ self errorKeyNotFound:name. |
11335 | 1456 |
]. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1457 |
^ self instVarAt:idx. |
5755 | 1458 |
|
1459 |
||
1460 |
" |
|
1461 |
|p| |
|
1462 |
||
1463 |
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
|
1464 |
p instVarNamed:'cx' |
5755 | 1465 |
" |
1466 |
||
1467 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
|
1468 |
! |
|
1469 |
||
1470 |
instVarNamed:name ifAbsent:exceptionBlock |
|
1471 |
"return a non-indexed instance variables value by name, |
|
1472 |
or the value of exceptionBlock, if there is no such instance variable. |
|
10460 | 1473 |
peeking into an object this way is not very object oriented |
5755 | 1474 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1475 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1476 |
parsed ad runtime)" |
|
1477 |
||
1478 |
|idx| |
|
1479 |
||
1480 |
idx := self class instVarOffsetOf:name. |
|
1481 |
idx isNil ifTrue:[^ exceptionBlock value]. |
|
1482 |
^ self instVarAt:idx |
|
1483 |
||
1484 |
||
1485 |
" |
|
1486 |
|p| |
|
1487 |
||
1488 |
p := Point x:10 y:20. |
|
10460 | 1489 |
p instVarNamed:'x' |
5755 | 1490 |
" |
1491 |
||
1492 |
"Created: 6.7.1996 / 23:02:49 / cg" |
|
1493 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
|
1494 |
! |
|
1495 |
||
1496 |
instVarNamed:name put:value |
|
1497 |
"set a non-indexed instance variable by name; |
|
10460 | 1498 |
peeking into an object this way is not very object oriented |
5755 | 1499 |
- if at all, use with care (provided for protocol completeness). |
1500 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1501 |
parsed ad runtime)" |
|
1502 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1503 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1504 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1505 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1506 |
idx isNil ifTrue:[ |
17757 | 1507 |
^ self errorKeyNotFound:name. |
11335 | 1508 |
]. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1509 |
^ self instVarAt:idx put:value. |
5755 | 1510 |
|
1511 |
" |
|
1512 |
|p| |
|
1513 |
||
1514 |
p := Point x:10 y:20. |
|
1515 |
p instVarNamed:'x' put:30. |
|
10460 | 1516 |
p |
5755 | 1517 |
" |
1518 |
||
1519 |
"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
|
1520 |
! |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1521 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1522 |
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
|
1523 |
"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
|
1524 |
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
|
1525 |
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
|
1526 |
- 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
|
1527 |
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
|
1528 |
parsed ad runtime)" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1529 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1530 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1531 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1532 |
idx := self class instVarOffsetOf:name. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1533 |
idx isNil ifTrue:[^ exceptionBlock value]. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1534 |
^ self instVarAt:idx put:anObject. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1535 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1536 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1537 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1538 |
|p| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1539 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1540 |
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
|
1541 |
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
|
1542 |
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
|
1543 |
p inspect. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1544 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1545 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1546 |
"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
|
1547 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
5755 | 1548 |
! ! |
1549 |
||
1550 |
!Object methodsFor:'attributes access'! |
|
1551 |
||
10460 | 1552 |
objectAttributeAt:attributeKey |
5755 | 1553 |
"return the attribute for a given key or nil if not found" |
1554 |
||
1555 |
| attrs | |
|
1556 |
||
1557 |
attrs := self objectAttributes. |
|
1558 |
(attrs notNil and:[attrs size > 0]) ifTrue:[ |
|
17757 | 1559 |
^ attrs at:attributeKey ifAbsent:[] |
5755 | 1560 |
]. |
1561 |
^ nil |
|
1562 |
||
1563 |
"Created: / 22.1.1998 / 21:29:17 / av" |
|
1564 |
"Modified: / 3.2.1998 / 18:55:55 / cg" |
|
1565 |
! |
|
1566 |
||
6323 | 1567 |
objectAttributeAt:attributeKey put:anObject |
5755 | 1568 |
"store the attribute anObject referenced by key into the receiver" |
1569 |
||
1570 |
"/ must do this save from interrupts, since the attributes collection |
|
1571 |
"/ is possibly accessed from multiple threads ... |
|
1572 |
[ |
|
17757 | 1573 |
| attrs | |
1574 |
||
1575 |
attrs := self objectAttributes. |
|
1576 |
(attrs isNil or:[attrs size == 0]) ifTrue:[ |
|
1577 |
attrs := WeakIdentityDictionary new. |
|
1578 |
attrs at:attributeKey put:anObject. |
|
1579 |
self objectAttributes:attrs. |
|
1580 |
] ifFalse:[ |
|
1581 |
attrs at:attributeKey put:anObject. |
|
1582 |
]. |
|
6323 | 1583 |
] valueUninterruptably |
5755 | 1584 |
|
1585 |
"Attaching additional attributes (slots) to an arbitrary object: |
|
1586 |
||
1587 |
|p| |
|
1588 |
||
1589 |
p := Point new. |
|
1590 |
p objectAttributeAt:#color put:#green. |
|
1591 |
||
1592 |
p objectAttributeAt:#color |
|
1593 |
" |
|
1594 |
||
1595 |
"Created: / 22.1.1998 / 21:29:25 / av" |
|
1596 |
"Modified: / 3.2.1998 / 18:57:58 / cg" |
|
1597 |
! |
|
1598 |
||
1599 |
objectAttributes |
|
1600 |
"return a Collection of attributes - nil if there is none. |
|
1601 |
The default implementation here uses a global WeakDictionary to store |
|
1602 |
attributes |
|
1603 |
This may be too slow for high frequency slot access, |
|
17789
338675f49dd6
Removed debug prints from perform: methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17788
diff
changeset
|
1604 |
therefore, some classes may redefine this for better performnce. |
5755 | 1605 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
1606 |
||
1607 |
^ ObjectAttributes at:self ifAbsent:[nil] |
|
1608 |
||
1609 |
"Created: / 22.1.1998 / 21:29:30 / av" |
|
1610 |
"Modified: / 18.2.2000 / 11:34:16 / cg" |
|
1611 |
! |
|
1612 |
||
1613 |
objectAttributes:aCollection |
|
1614 |
"set the collection of attributes. |
|
1615 |
The default implementation here uses a global Dictionary to store |
|
1616 |
attributes which may be too slow for high frequency change&update. |
|
1617 |
Therefore, some classes may redefine this for better performance." |
|
1618 |
||
1619 |
"/ must do this save from interrupts, since the attributes collection |
|
1620 |
"/ is possibly accessed from multiple threads. |
|
1621 |
||
1622 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
17757 | 1623 |
"/ the common case - already blocked |
1624 |
||
1625 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
1626 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1627 |
] ifFalse:[ |
|
1628 |
ObjectAttributes at:self put:aCollection |
|
1629 |
]. |
|
1630 |
^ self |
|
5755 | 1631 |
]. |
1632 |
||
1633 |
[ |
|
17757 | 1634 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
1635 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1636 |
] ifFalse:[ |
|
1637 |
ObjectAttributes at:self put:aCollection |
|
1638 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
1639 |
] ensure:[ |
17757 | 1640 |
OperatingSystem unblockInterrupts |
5755 | 1641 |
] |
1642 |
||
1643 |
"Created: / 22.1.1998 / 21:29:35 / av" |
|
1644 |
"Modified: / 3.2.1998 / 18:58:10 / cg" |
|
1645 |
! |
|
1646 |
||
6323 | 1647 |
removeObjectAttribute:attributeKey |
5755 | 1648 |
"make the argument, anObject be no attribute of the receiver" |
1649 |
||
1650 |
"/ must do this save from interrupts, since the attributes collection |
|
1651 |
"/ is possibly accessed from multiple threads. |
|
1652 |
[ |
|
17757 | 1653 |
|attrs n a| |
1654 |
||
1655 |
attrs := self objectAttributes. |
|
1656 |
attrs size == 0 ifTrue:[ |
|
1657 |
self objectAttributes:nil |
|
1658 |
] ifFalse:[ |
|
1659 |
attrs removeKey:attributeKey ifAbsent:nil. |
|
1660 |
attrs size == 0 ifTrue:[ |
|
1661 |
self objectAttributes:nil |
|
1662 |
] |
|
1663 |
] |
|
6323 | 1664 |
] valueUninterruptably |
5755 | 1665 |
|
1666 |
"Created: / 22.1.1998 / 21:29:39 / av" |
|
1667 |
"Modified: / 18.2.2000 / 11:32:19 / cg" |
|
1668 |
! ! |
|
1669 |
||
11398 | 1670 |
|
5755 | 1671 |
!Object methodsFor:'change & update'! |
1672 |
||
1673 |
broadcast:aSelectorSymbol |
|
1674 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1675 |
||
10460 | 1676 |
self dependentsDo:[:dependent | |
17757 | 1677 |
dependent perform:aSelectorSymbol |
5755 | 1678 |
] |
1679 |
! |
|
1680 |
||
1681 |
broadcast:aSelectorSymbol with:anArgument |
|
1682 |
"send a message with selector aSelectorSymbol with an additional |
|
1683 |
argument anArgument to all my dependents." |
|
1684 |
||
10460 | 1685 |
self dependentsDo:[:dependent | |
17757 | 1686 |
dependent perform:aSelectorSymbol with:anArgument |
5755 | 1687 |
] |
1688 |
! |
|
1689 |
||
1690 |
changeRequest |
|
1691 |
"the receiver wants to change - check if all dependents |
|
1692 |
grant the request, and return true if so" |
|
1693 |
||
10460 | 1694 |
self dependentsDo:[:dependent | |
17757 | 1695 |
dependent updateRequest ifFalse:[^ false]. |
5755 | 1696 |
]. |
1697 |
^ true |
|
1698 |
! |
|
1699 |
||
11551 | 1700 |
changeRequest:aSymbol |
5755 | 1701 |
"the receiver wants to change - check if all dependents |
1702 |
grant the request, and return true if so" |
|
1703 |
||
10460 | 1704 |
self dependentsDo:[:dependent | |
11551 | 1705 |
(dependent updateRequest:aSymbol) ifFalse:[^ false]. |
5755 | 1706 |
]. |
1707 |
^ true |
|
1708 |
! |
|
1709 |
||
11551 | 1710 |
changeRequest:aSymbol from:anObject |
1711 |
"the receiver wants to change - check if all dependents |
|
1712 |
except anObject grant the request, and return true if so. |
|
1713 |
The argument anObject is typically going to be the one who is |
|
1714 |
about to send the change request." |
|
1715 |
||
1716 |
^ self changeRequest:aSymbol with:nil from:anObject |
|
1717 |
! |
|
1718 |
||
1719 |
changeRequest:aSymbol with:aParameter |
|
1720 |
"the receiver wants to change - check if all dependents |
|
1721 |
grant the request, and return true if so" |
|
1722 |
||
11573 | 1723 |
^ self changeRequest:aSymbol with:aParameter from:self |
11551 | 1724 |
! |
1725 |
||
1726 |
changeRequest:aSymbol with:aParameter from:anObject |
|
5755 | 1727 |
"the receiver wants to change - check if all dependents |
1728 |
except anObject grant the request, and return true if so. |
|
1729 |
The argument anObject is typically going to be the one who is |
|
1730 |
about to send the change request." |
|
1731 |
||
10460 | 1732 |
self dependentsDo:[:dependent | |
11551 | 1733 |
dependent == anObject ifFalse:[ |
1734 |
(dependent updateRequest:aSymbol with:aParameter from:anObject) ifFalse:[^ false]. |
|
1735 |
] |
|
5755 | 1736 |
]. |
1737 |
^ true |
|
1738 |
! |
|
1739 |
||
1740 |
changeRequestFrom:anObject |
|
1741 |
"the receiver wants to change - check if all dependents |
|
1742 |
except anObject grant the request, and return true if so. |
|
1743 |
The argument anObject is typically going to be the one who is |
|
1744 |
about to send the change request." |
|
1745 |
||
10460 | 1746 |
self dependentsDo:[:dependent | |
17757 | 1747 |
dependent == anObject ifFalse:[ |
1748 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1749 |
] |
|
5755 | 1750 |
]. |
1751 |
^ true |
|
1752 |
! |
|
1753 |
||
1754 |
changed |
|
1755 |
"notify all dependents that the receiver has changed. |
|
1756 |
Each dependent gets a '#update:'-message with the original |
|
1757 |
receiver as argument." |
|
1758 |
||
1759 |
self changed:nil |
|
1760 |
! |
|
1761 |
||
1762 |
changed:aParameter |
|
1763 |
"notify all dependents that the receiver has changed somehow. |
|
1764 |
Each dependent gets a '#update:'-message with aParameter |
|
1765 |
as argument." |
|
1766 |
||
1767 |
self changed:aParameter with:nil |
|
1768 |
! |
|
1769 |
||
1770 |
changed:aParameter with:anArgument |
|
1771 |
"notify all dependents that the receiver has changed somehow. |
|
1772 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
|
1773 |
and anArgument as arguments." |
|
1774 |
||
10460 | 1775 |
self dependentsDo:[:dependent | |
17757 | 1776 |
dependent update:aParameter with:anArgument from:self |
5755 | 1777 |
] |
1778 |
! |
|
1779 |
||
1780 |
update:aParameter |
|
1781 |
"the message is sent to a dependent, when one of the objects |
|
1782 |
on whom the receiver depends, has changed. The argument aParameter |
|
1783 |
is either the changed object or the argument to the #changed: message. |
|
1784 |
||
1785 |
Default behavior here is to do nothing" |
|
1786 |
||
1787 |
^ self |
|
1788 |
! |
|
1789 |
||
1790 |
update:aParameter with:anArgument |
|
1791 |
"dependent is notified of some change - |
|
1792 |
Default is to try update:" |
|
1793 |
||
1794 |
^ self update:aParameter |
|
1795 |
! |
|
1796 |
||
1797 |
update:aParameter with:anArgument from:sender |
|
1798 |
"dependent is notified of some change - |
|
1799 |
Default is to try update:with:" |
|
1800 |
||
1801 |
^ self update:aParameter with:anArgument |
|
1802 |
! |
|
1803 |
||
1804 |
updateRequest |
|
1805 |
"return true, if an update request is granted. |
|
1806 |
Default here is to grant updates - may be used |
|
1807 |
to lock updates if someone is making other changes |
|
1808 |
from within an update. Or if someone has locked its |
|
1809 |
state and does not want others to change things. |
|
1810 |
However, these dependents must all honor the |
|
1811 |
changeRequest - ifTrue - change protocol. I.e. they |
|
1812 |
must first ask all others via changeRequest, and only do the change |
|
1813 |
it returns true. The others must decide in updateRequest and |
|
1814 |
return true if they think a change is ok." |
|
1815 |
||
1816 |
^ true |
|
1817 |
! |
|
1818 |
||
1819 |
updateRequest:aSymbol |
|
1820 |
"return true, if an update request is granted. |
|
1821 |
Default here a simple updateRequest" |
|
1822 |
||
1823 |
^ self updateRequest |
|
7177 | 1824 |
! |
1825 |
||
11551 | 1826 |
updateRequest:aSymbol with:aParameter |
1827 |
"return true, if an update request is granted. |
|
1828 |
Default here a simple updateRequest" |
|
1829 |
||
1830 |
^ self updateRequest:aSymbol |
|
1831 |
! |
|
1832 |
||
1833 |
updateRequest:aSymbol with:aParameter from:sender |
|
1834 |
"return true, if an update request is granted. |
|
1835 |
Default here a simple updateRequest" |
|
1836 |
||
1837 |
^ self updateRequest:aSymbol with:aParameter |
|
1838 |
! |
|
1839 |
||
7177 | 1840 |
withoutUpdating:someone do:aBlock |
1841 |
"evaluate a block but remove someone from my dependents temporarily" |
|
1842 |
||
1843 |
(self dependents includesIdentical:someone) |
|
1844 |
ifFalse:[ |
|
17757 | 1845 |
^ aBlock value. |
7177 | 1846 |
]. |
1847 |
self removeDependent:someone. |
|
1848 |
^ aBlock ensure:[ self addDependent:someone ] |
|
5755 | 1849 |
! ! |
1850 |
||
1851 |
!Object methodsFor:'cleanup'! |
|
1852 |
||
1853 |
lowSpaceCleanup |
|
1854 |
"ignored here - redefined in some classes to |
|
1855 |
cleanup in low-memory situations" |
|
1856 |
||
1857 |
^ self |
|
1858 |
! ! |
|
1859 |
||
17795 | 1860 |
|
5755 | 1861 |
!Object methodsFor:'comparing'! |
1862 |
||
1863 |
= anObject |
|
1864 |
"return true, if the receiver and the arg have the same structure. |
|
1865 |
Notice: |
|
17757 | 1866 |
This method is partially open coded (inlined) by the compiler(s) |
1867 |
identical objects are always considered equal. |
|
1868 |
redefining it may not work as expected." |
|
5755 | 1869 |
|
1870 |
^ self == anObject |
|
1871 |
! |
|
1872 |
||
1873 |
== anObject |
|
1874 |
"return true, if the receiver and the arg are the same object. |
|
1875 |
Never redefine this in any class. |
|
1876 |
Notice: |
|
17757 | 1877 |
This method is open coded (inlined) by the compiler(s) |
1878 |
- redefining it may not work as expected." |
|
5755 | 1879 |
|
1880 |
%{ /* NOCONTEXT */ |
|
1881 |
||
1882 |
RETURN ( (self == anObject) ? true : false ); |
|
1883 |
%} |
|
1884 |
! |
|
1885 |
||
5814 | 1886 |
deepSameContentsAs:anObject |
1887 |
"return true, if the receiver and the arg have the same contents |
|
1888 |
in both the named instance vars and any indexed instVars. |
|
1889 |
This method descends into referenced objects, where #sameContentsAs: does not descend" |
|
1890 |
||
5821 | 1891 |
|myClass val |
5814 | 1892 |
sz "{ Class: SmallInteger }" | |
1893 |
||
1894 |
myClass := self class. |
|
1895 |
myClass isVariable ifTrue:[ |
|
17757 | 1896 |
sz := self basicSize. |
1897 |
||
1898 |
"compare the indexed variables" |
|
1899 |
1 to:sz do:[:i | |
|
1900 |
val := self basicAt:i. |
|
1901 |
val isLiteral ifTrue:[ |
|
1902 |
val = (anObject basicAt:i) ifFalse:[^ false]. |
|
1903 |
] ifFalse:[ |
|
1904 |
(val deepSameContentsAs:(anObject basicAt:i)) ifFalse:[^ false]. |
|
1905 |
] |
|
1906 |
] |
|
5814 | 1907 |
]. |
1908 |
||
1909 |
"compare the instance variables" |
|
1910 |
sz := myClass instSize. |
|
10460 | 1911 |
1 to:sz do:[:i | |
17757 | 1912 |
val := self instVarAt:i. |
1913 |
val isLiteral ifTrue:[ |
|
1914 |
val = (anObject instVarAt:i) ifFalse:[^ false]. |
|
1915 |
] ifFalse:[ |
|
1916 |
(val deepSameContentsAs:(anObject instVarAt:i)) ifFalse:[^ false]. |
|
1917 |
] |
|
5814 | 1918 |
]. |
1919 |
||
1920 |
^ true |
|
1921 |
||
1922 |
" |
|
10460 | 1923 |
#(1 2 3 4) deepSameContentsAs:#[1 2 3 4] asArray |
5814 | 1924 |
(1@2) deepSameContentsAs:(1->2) |
1925 |
" |
|
1926 |
! |
|
1927 |
||
5755 | 1928 |
hash |
1929 |
"return an Integer useful as a hash key for the receiver. |
|
1930 |
This hash should return same values for objects with same |
|
1931 |
contents (i.e. use this to hash on structure)" |
|
1932 |
||
1933 |
^ self identityHash |
|
1934 |
! |
|
1935 |
||
1936 |
identityHash |
|
1937 |
"return an Integer useful as a hash key for the receiver. |
|
1938 |
This hash should return same values for the same object (i.e. use |
|
1939 |
this to hash on identity of objects). |
|
1940 |
||
1941 |
We cannot use the Objects address (as other smalltalks do) since |
|
1942 |
no object-table exists and the hashval must not change when objects |
|
1943 |
are moved by the collector. Therefore we assign each object a unique |
|
1944 |
Id in the object header itself as its hashed upon. |
|
1945 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
1946 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
1947 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
1948 |
hashed-upon objects could add an instvar containing the hash value." |
|
1949 |
||
1950 |
%{ /* NOCONTEXT */ |
|
1951 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1952 |
REGISTER unsigned INT hash; |
5755 | 1953 |
static unsigned nextHash = 0; |
1954 |
||
1955 |
if (__isNonNilObject(self)) { |
|
17757 | 1956 |
hash = __GET_HASH(self); |
1957 |
if (hash == 0) { |
|
1958 |
/* has no hash yet */ |
|
1959 |
||
1960 |
if (++nextHash > __MAX_HASH__) { |
|
1961 |
nextHash = 1; |
|
1962 |
} |
|
1963 |
hash = nextHash; |
|
1964 |
__SET_HASH(self, hash); |
|
1965 |
} |
|
1966 |
||
1967 |
/* |
|
1968 |
* now, we got 11 bits for hashing; |
|
1969 |
* make it as large as possible; since most hashers use the returned |
|
1970 |
* key and take it modulo some prime number, this will allow for |
|
1971 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
1972 |
*/ |
|
1973 |
hash = __MAKE_HASH__(hash); |
|
1974 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 1975 |
} |
1976 |
%}. |
|
1977 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
1978 |
! |
|
1979 |
||
1980 |
identityHashForBinaryStore |
|
1981 |
"hash which is usable if the object does not change its class |
|
1982 |
and does not #become something else, while the hash is used. |
|
1983 |
This is only used by the binary storage mechanism, during the |
|
1984 |
object writing phase." |
|
1985 |
||
1986 |
%{ /* NOCONTEXT */ |
|
1987 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1988 |
REGISTER unsigned INT hash, hash1, hash2, sz; |
5755 | 1989 |
OBJ o; |
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1990 |
static unsigned INT nextHash = 0; |
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1991 |
static unsigned INT nextClassHash = 0; |
5755 | 1992 |
|
1993 |
if (__isNonNilObject(self)) { |
|
17757 | 1994 |
/* |
1995 |
* my own identityHash |
|
1996 |
*/ |
|
1997 |
hash1 = __GET_HASH(self); |
|
1998 |
if (hash1 == 0) { |
|
1999 |
/* has no hash yet */ |
|
2000 |
||
2001 |
if (++nextHash > __MAX_HASH__) { |
|
2002 |
nextHash = 1; |
|
2003 |
} |
|
2004 |
hash1 = nextHash; |
|
2005 |
__SET_HASH(self, hash1); |
|
2006 |
} |
|
2007 |
/* |
|
2008 |
* my classes identityHash |
|
2009 |
*/ |
|
2010 |
o = __qClass(self); |
|
2011 |
hash2 = __GET_HASH(o); |
|
2012 |
if (hash2 == 0) { |
|
2013 |
/* has no hash yet */ |
|
2014 |
||
2015 |
if (++nextClassHash > __MAX_HASH__) { |
|
2016 |
nextClassHash = 1; |
|
2017 |
} |
|
2018 |
hash2 = nextClassHash; |
|
2019 |
__SET_HASH(o, hash2); |
|
2020 |
} |
|
2021 |
||
2022 |
/* |
|
2023 |
* some bits of my size |
|
2024 |
*/ |
|
2025 |
sz = __qSize(self); |
|
2026 |
||
2027 |
/* |
|
2028 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
2029 |
* make it as large as possible; since most hashers use the returned |
|
2030 |
* key and take it modulo some prime number, this will allow for |
|
2031 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2032 |
*/ |
|
2033 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
2034 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
2035 |
||
2036 |
while ((hash & 0x20000000) == 0) { |
|
2037 |
hash <<= 1; |
|
2038 |
} |
|
2039 |
||
2040 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 2041 |
} |
2042 |
%}. |
|
2043 |
"never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
|
2044 |
^ self identityHash |
|
2045 |
! |
|
2046 |
||
2047 |
sameContentsAs:anObject |
|
2048 |
"return true, if the receiver and the arg have the same contents |
|
7121 | 2049 |
in both the named instance vars and any indexed instVars. |
2050 |
The code here only checks if values present in the receiver are also |
|
2051 |
present in the arg, not vice versa. |
|
2052 |
I.e. the argument may be bigger and/or have more instance variables." |
|
5755 | 2053 |
|
5821 | 2054 |
|myClass |
5755 | 2055 |
sz "{ Class: SmallInteger }" | |
2056 |
||
2057 |
myClass := self class. |
|
2058 |
myClass isVariable ifTrue:[ |
|
17757 | 2059 |
sz := self basicSize. |
2060 |
anObject basicSize >= sz ifFalse:[^ false]. |
|
2061 |
||
2062 |
"compare the indexed variables" |
|
2063 |
1 to:sz do:[:i | |
|
2064 |
(self basicAt:i) == (anObject basicAt:i) ifFalse:[^ false]. |
|
2065 |
] |
|
5755 | 2066 |
]. |
2067 |
||
2068 |
"compare the instance variables" |
|
2069 |
sz := myClass instSize. |
|
17795 | 2070 |
anObject class instSize >= sz ifFalse:[^ false]. |
7121 | 2071 |
|
10460 | 2072 |
1 to:sz do:[:i | |
17757 | 2073 |
(self instVarAt:i) == (anObject instVarAt:i) ifFalse:[^ false]. |
5755 | 2074 |
]. |
2075 |
||
2076 |
^ true |
|
2077 |
||
2078 |
" |
|
10460 | 2079 |
#(1 2 3 4) sameContentsAs:#[1 2 3 4] asArray |
5814 | 2080 |
(1@2) sameContentsAs:(1->2) |
5755 | 2081 |
" |
2082 |
||
17795 | 2083 |
"Created: / 21-04-1998 / 15:56:40 / cg" |
2084 |
"Modified: / 05-08-2010 / 16:44:09 / sr" |
|
5755 | 2085 |
! |
2086 |
||
2087 |
~= anObject |
|
2088 |
"return true, if the receiver and the arg do not have the same structure. |
|
2089 |
Notice: |
|
17757 | 2090 |
This method is partially open coded (inlined) by the compiler(s) |
2091 |
identical objects are never considered unequal. |
|
2092 |
redefining it may not work as expected." |
|
5755 | 2093 |
|
2094 |
^ (self = anObject) not |
|
2095 |
! |
|
2096 |
||
2097 |
~~ anObject |
|
2098 |
"return true, if the receiver and the arg are not the same object. |
|
2099 |
Never redefine this in any class. |
|
2100 |
Notice: |
|
17757 | 2101 |
This method is open coded (inlined) by the compiler(s) |
2102 |
- redefining it may not work as expected." |
|
5755 | 2103 |
|
2104 |
%{ /* NOCONTEXT */ |
|
2105 |
RETURN ( (self == anObject) ? false : true ); |
|
2106 |
%} |
|
2107 |
! ! |
|
2108 |
||
2109 |
!Object methodsFor:'converting'! |
|
2110 |
||
2111 |
-> anObject |
|
2112 |
"return an association with the receiver as key and |
|
2113 |
the argument as value" |
|
2114 |
||
2115 |
^ Association key:self value:anObject |
|
2116 |
! |
|
2117 |
||
10062 | 2118 |
as:aSimilarClass |
2119 |
"If the receivers class is not aSimilarClass, |
|
10460 | 2120 |
create and return an object of class aSimilarClass that has the same contents |
10062 | 2121 |
as the receiver. |
2122 |
Otherwise, return the receiver." |
|
2123 |
||
2124 |
self class == aSimilarClass ifTrue:[^ self]. |
|
2125 |
^ aSimilarClass newFrom:self |
|
2126 |
||
2127 |
" |
|
2128 |
#[1 2 3 4] as:ByteArray |
|
2129 |
#[1 2 3 4] as:Array |
|
10539 | 2130 |
#[81 82 83 84] as:String |
2131 |
#[81 82 83 84] as:Symbol |
|
10062 | 2132 |
" |
2133 |
! |
|
2134 |
||
5755 | 2135 |
asCollection |
2136 |
"return myself as a Collection. |
|
2137 |
Redefined in collection to return themself." |
|
2138 |
||
2139 |
^ Array with:self |
|
2140 |
! |
|
2141 |
||
2142 |
asSequenceableCollection |
|
2143 |
"return myself as a SequenceableCollection. |
|
2144 |
Redefined in SequenceableCollection" |
|
2145 |
||
2146 |
^ Array with:self |
|
2147 |
! |
|
2148 |
||
2149 |
asValue |
|
2150 |
"return a valueHolder for for the receiver" |
|
2151 |
||
2152 |
^ ValueHolder with:self |
|
2153 |
! ! |
|
2154 |
||
2155 |
!Object methodsFor:'copying'! |
|
2156 |
||
10460 | 2157 |
cloneFrom:anObject |
5755 | 2158 |
"Helper for copy: |
2159 |
copy all instance variables from anObject into the receiver, |
|
2160 |
which should be of the same class as the argument." |
|
2161 |
||
2162 |
self cloneFrom:anObject performing:#yourself |
|
2163 |
||
2164 |
" |
|
2165 |
|x| |
|
2166 |
||
2167 |
x := Array new:3. |
|
2168 |
x cloneFrom:#(1 2 3). |
|
2169 |
" |
|
2170 |
! |
|
2171 |
||
2172 |
cloneFrom:anObject performing:aSymbol |
|
2173 |
"Helper for copy: |
|
8383 | 2174 |
for each instance variable from anObject, send it aSymbol |
5755 | 2175 |
and store the result into the receiver, |
2176 |
which should be of the same class as the argument." |
|
2177 |
||
2178 |
|myClass sz "{ Class: SmallInteger }" t | |
|
2179 |
||
2180 |
myClass := self class. |
|
2181 |
myClass isVariable ifTrue:[ |
|
17757 | 2182 |
sz := self basicSize. |
2183 |
||
2184 |
"process the indexed instance variables" |
|
2185 |
1 to:sz do:[:i | |
|
2186 |
t := anObject basicAt:i. |
|
2187 |
aSymbol ~~ #yourself ifTrue:[ |
|
2188 |
t := t perform:aSymbol. |
|
2189 |
]. |
|
2190 |
self basicAt:i put:t. |
|
2191 |
] |
|
5755 | 2192 |
]. |
2193 |
||
8383 | 2194 |
"process the named instance variables" |
5755 | 2195 |
sz := myClass instSize. |
10460 | 2196 |
1 to:sz do:[:i | |
17757 | 2197 |
t := anObject instVarAt:i. |
2198 |
aSymbol ~~ #yourself ifTrue:[ |
|
2199 |
t := t perform:aSymbol |
|
2200 |
]. |
|
2201 |
self instVarAt:i put:t |
|
5755 | 2202 |
]. |
2203 |
||
2204 |
^ self |
|
2205 |
! |
|
2206 |
||
2207 |
cloneInstanceVariablesFrom:aPrototype |
|
2208 |
"Shallow copy variables from a prototype into myself. |
|
2209 |
This copies instVars by name - i.e. same-named variables are |
|
2210 |
copied, others are not. |
|
10460 | 2211 |
The variable slots are copied as available |
5755 | 2212 |
(i.e. the min of both indexed sizes is used)." |
10460 | 2213 |
|
5755 | 2214 |
|myInfo otherInfo| |
2215 |
||
2216 |
myInfo := self class instanceVariableOffsets. |
|
2217 |
otherInfo := aPrototype class instanceVariableOffsets. |
|
2218 |
myInfo keysAndValuesDo:[:name :index | |varIndexAssoc| |
|
17757 | 2219 |
varIndexAssoc := otherInfo at:name ifAbsent:[]. |
2220 |
varIndexAssoc notNil ifTrue:[ |
|
2221 |
self instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
2222 |
] |
|
5755 | 2223 |
]. |
2224 |
self isVariable ifTrue:[ |
|
17757 | 2225 |
1 to:(self basicSize min:aPrototype basicSize) do:[:index | |
2226 |
self basicAt:index put:(aPrototype basicAt:index) |
|
2227 |
]. |
|
5755 | 2228 |
]. |
2229 |
||
2230 |
" |
|
2231 |
Class withoutUpdatingChangesDo:[ |
|
17757 | 2232 |
Point subclass:#Point3D |
2233 |
instanceVariableNames:'z' |
|
2234 |
classVariableNames:'' |
|
2235 |
poolDictionaries:'' |
|
2236 |
category:'testing'. |
|
2237 |
(Point3D new cloneInstanceVariablesFrom:1@2) inspect. |
|
5755 | 2238 |
] |
2239 |
" |
|
2240 |
||
2241 |
" |
|
2242 |
Class withoutUpdatingChangesDo:[ |
|
17757 | 2243 |
Point variableSubclass:#Point3D |
2244 |
instanceVariableNames:'z' |
|
2245 |
classVariableNames:'' |
|
2246 |
poolDictionaries:'' |
|
2247 |
category:'testing'. |
|
2248 |
((Point3D new:2) cloneInstanceVariablesFrom:#(1 2 3)) inspect. |
|
5755 | 2249 |
] |
2250 |
" |
|
2251 |
||
2252 |
" |
|
2253 |
|someObject| |
|
2254 |
||
2255 |
Class withoutUpdatingChangesDo:[ |
|
17757 | 2256 |
Object subclass:#TestClass1 |
2257 |
instanceVariableNames:'foo bar' |
|
2258 |
classVariableNames:'' |
|
2259 |
poolDictionaries:'' |
|
2260 |
category:'testing'. |
|
2261 |
someObject := TestClass1 new. |
|
2262 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
2263 |
Object subclass:#TestClass2 |
|
2264 |
instanceVariableNames:'bar foo' |
|
2265 |
classVariableNames:'' |
|
2266 |
poolDictionaries:'' |
|
2267 |
category:'testing'. |
|
2268 |
(TestClass2 new cloneInstanceVariablesFrom:someObject) inspect. |
|
5755 | 2269 |
] |
2270 |
" |
|
2271 |
||
2272 |
" |
|
2273 |
|top b b1| |
|
2274 |
||
2275 |
top := StandardSystemView new. |
|
2276 |
top extent:100@100. |
|
2277 |
||
2278 |
b := Button in:top. |
|
2279 |
b label:'hello'. |
|
2280 |
||
2281 |
b1 := ArrowButton new cloneInstanceVariablesFrom:b. |
|
2282 |
||
2283 |
top open. |
|
2284 |
b1 inspect |
|
2285 |
" |
|
2286 |
! |
|
2287 |
||
2288 |
copy |
|
2289 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
2290 |
Notice, that copy does not copy dependents." |
|
2291 |
||
2292 |
^ self shallowCopy postCopy |
|
2293 |
! |
|
2294 |
||
6146 | 2295 |
copyToLevel:level |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2296 |
"a controlled deepCopy, where the number of levels can be specified. |
10460 | 2297 |
Notice: |
17757 | 2298 |
This method DOES NOT handle cycles/self-refs and does NOT preserve object identity; |
2299 |
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
|
2300 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2301 |
|newObject class index| |
6146 | 2302 |
|
2303 |
level == 1 ifTrue:[^ self shallowCopy]. |
|
2304 |
||
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2305 |
class := self class. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2306 |
newObject := self clone. |
6146 | 2307 |
newObject == self ifTrue: [^ self]. |
10460 | 2308 |
class isVariable ifTrue:[ |
17757 | 2309 |
index := self basicSize. |
2310 |
[index > 0] whileTrue:[ |
|
2311 |
newObject basicAt: index put: ((self basicAt: index) copyToLevel:(level-1)). |
|
2312 |
index := index - 1 |
|
2313 |
] |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2314 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2315 |
index := class instSize. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2316 |
[index > 0] whileTrue:[ |
17757 | 2317 |
newObject instVarAt: index put: ((self instVarAt: index) copyToLevel:(level-1)). |
2318 |
index := index - 1 |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2319 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2320 |
^ newObject |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2321 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2322 |
" |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2323 |
|a b| |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2324 |
|
10460 | 2325 |
a := #( |
17757 | 2326 |
'1.1' |
2327 |
'1.2' |
|
2328 |
'1.3' |
|
2329 |
( |
|
2330 |
'1.41' |
|
2331 |
'1.42' |
|
2332 |
'1.43' |
|
2333 |
( |
|
2334 |
'1.441' |
|
2335 |
'1.442' |
|
2336 |
'1.443' |
|
2337 |
( '1.4441' '1.4442' '1.4443' ) |
|
2338 |
'1.445' |
|
2339 |
) |
|
2340 |
'1.45' |
|
2341 |
) |
|
2342 |
'1.5' |
|
2343 |
). |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2344 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2345 |
b := a copyToLevel:1. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2346 |
self assert: ( (a at:1) == (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2347 |
self assert: ( (a at:4) == (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2348 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2349 |
b := a copyToLevel:2. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2350 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2351 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2352 |
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
|
2353 |
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
|
2354 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2355 |
b := a copyToLevel:3. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2356 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2357 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2358 |
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
|
2359 |
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
|
2360 |
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
|
2361 |
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
|
2362 |
" |
6146 | 2363 |
! |
2364 |
||
5755 | 2365 |
deepCopy |
2366 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2367 |
This method DOES handle cycles/self-refs and preserves object identity; |
5755 | 2368 |
however the receivers class is not copied (to avoid the 'total' copy). |
2369 |
||
2370 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
2371 |
keeps track of already copied objects. If you are sure, that your |
|
2372 |
copied object does not include duplicates (or you do not care) and |
|
10460 | 2373 |
no cycles are involved, you can use the old simpleDeepCopy, |
5755 | 2374 |
which avoids this overhead (but may run into trouble). |
2375 |
Notice, that deepCopy does not copy dependents." |
|
2376 |
||
8383 | 2377 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 2378 |
|
2379 |
"an example which is not handled by the old deepCopy: |
|
10460 | 2380 |
|
5755 | 2381 |
|a| |
2382 |
a := Array new:3. |
|
2383 |
a at:3 put:a. |
|
2384 |
a deepCopy inspect |
|
2385 |
" |
|
2386 |
||
2387 |
" |
|
2388 |
|a| |
|
2389 |
a := Color black onDevice:Screen current. |
|
2390 |
a deepCopy inspect |
|
2391 |
" |
|
2392 |
||
2393 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
2394 |
! |
|
2395 |
||
2396 |
deepCopyError |
|
2397 |
"{ Pragma: +optSpace }" |
|
2398 |
||
2399 |
"raise a signal, that deepCopy is not allowed for this object" |
|
2400 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
2401 |
^ DeepCopyError raise |
5755 | 2402 |
! |
2403 |
||
2404 |
deepCopyUsing:aDictionary |
|
10460 | 2405 |
"a helper for deepCopy; return a copy of the object with |
2406 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
5755 | 2407 |
use the value found there. The class of the receiver is not copied. |
2408 |
This method DOES handle cycles/self references." |
|
2409 |
||
10941 | 2410 |
^ self deepCopyUsing:aDictionary postCopySelector:#postDeepCopyFrom:. |
2411 |
||
5755 | 2412 |
|
2413 |
" |
|
2414 |
|a b c copyOfC| |
|
2415 |
||
2416 |
a := Array with:'hello' with:'world' with:nil. |
|
2417 |
b := 99 @ 999. |
|
2418 |
a at:3 put:b. |
|
2419 |
c := Array with:a with:b with:a. |
|
2420 |
||
2421 |
Transcript showCR: (c at:1) == (c at:3). |
|
2422 |
copyOfC := c deepCopy. |
|
2423 |
Transcript showCR: (copyOfC at:1) == (copyOfC at:3) |
|
2424 |
" |
|
2425 |
! |
|
2426 |
||
10954 | 2427 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
11335 | 2428 |
"a helper for deepCopy; return a copy of the object with |
2429 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
10954 | 2430 |
use the value found there. The class of the receiver is not copied. |
2431 |
This method DOES handle cycles/self references." |
|
2432 |
||
2433 |
|myClass aCopy |
|
11335 | 2434 |
sz "{ Class: SmallInteger }" |
10954 | 2435 |
iOrig iCopy| |
2436 |
||
2437 |
myClass := self class. |
|
2438 |
"/ (myClass whichClassImplements:#deepCopyUsing:) ~~ Object ifTrue:[ |
|
2439 |
"/ ^ self deepCopyUsing:aDictionary. |
|
2440 |
"/ ]. |
|
2441 |
||
2442 |
myClass isVariable ifTrue:[ |
|
17757 | 2443 |
sz := self basicSize. |
2444 |
aCopy := myClass basicNew:sz. |
|
10954 | 2445 |
] ifFalse:[ |
17757 | 2446 |
sz := 0. |
2447 |
aCopy := myClass basicNew |
|
10954 | 2448 |
]. |
2449 |
aCopy setHashFrom:self. |
|
2450 |
aDictionary at:self put:aCopy. |
|
2451 |
||
2452 |
" |
|
2453 |
copy indexed instvars - if any |
|
2454 |
" |
|
2455 |
sz ~~ 0 ifTrue:[ |
|
17757 | 2456 |
myClass isBits ifTrue:[ |
2457 |
"block-copy indexed instvars" |
|
2458 |
aCopy replaceFrom:1 to:sz with:self startingAt:1 |
|
2459 |
] ifFalse:[ |
|
2460 |
"individual deep copy the indexed variables" |
|
2461 |
1 to:sz do:[:i | |
|
2462 |
iOrig := self basicAt:i. |
|
2463 |
iOrig notNil ifTrue:[ |
|
2464 |
"/ used to be dict-includesKey-ifTrue[dict-at:], |
|
2465 |
"/ changed to use dict-at:ifAbsent:, to avoid double lookup in dictionary |
|
2466 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2467 |
iCopy isNil ifTrue:[ |
|
2468 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2469 |
]. |
|
2470 |
aCopy basicAt:i put:iCopy |
|
2471 |
] |
|
2472 |
] |
|
2473 |
] |
|
10954 | 2474 |
]. |
2475 |
||
2476 |
" |
|
2477 |
copy the instance variables |
|
2478 |
" |
|
2479 |
sz := myClass instSize. |
|
2480 |
1 to:sz do:[:i | |
|
17757 | 2481 |
(self skipInstvarIndexInDeepCopy:i) ifFalse:[ |
2482 |
iOrig := self instVarAt:i. |
|
2483 |
iOrig notNil ifTrue:[ |
|
2484 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2485 |
iCopy isNil ifTrue:[ |
|
2486 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2487 |
]. |
|
2488 |
aCopy instVarAt:i put:iCopy |
|
2489 |
] |
|
2490 |
] |
|
10954 | 2491 |
]. |
2492 |
aCopy perform:postCopySelector with:self "ifNotUnderstood:[]". |
|
2493 |
^ aCopy |
|
2494 |
! |
|
2495 |
||
5755 | 2496 |
postCopy |
2497 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
2498 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
2499 |
(see there)" |
|
2500 |
||
2501 |
^ self |
|
2502 |
! |
|
2503 |
||
2504 |
postDeepCopy |
|
8930
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2505 |
"allows for cleanup after deep copying. |
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2506 |
To be redefined in subclasses." |
5755 | 2507 |
! |
2508 |
||
2509 |
postDeepCopyFrom:aSource |
|
2510 |
"allows for cleanup after deep copying" |
|
2511 |
||
2512 |
^ self postDeepCopy |
|
2513 |
! |
|
2514 |
||
2515 |
setHashFrom:anObject |
|
10460 | 2516 |
"set my identity-hash key to be the same as anObjects hash key. |
2517 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
5755 | 2518 |
Smalltalks, and may not be available in future ST/X versions. |
2519 |
DO NEVER use this for normal application code." |
|
2520 |
||
2521 |
%{ /* NOCONTEXT */ |
|
2522 |
||
2523 |
REGISTER unsigned h; |
|
2524 |
||
2525 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
17757 | 2526 |
h = __GET_HASH(anObject); |
2527 |
__SET_HASH(self, h); |
|
2528 |
RETURN (self); |
|
5755 | 2529 |
} |
2530 |
%}. |
|
2531 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
2532 |
! |
|
2533 |
||
2534 |
shallowCopy |
|
2535 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2536 |
i.e. the copy shares referenced instvars with its original." |
|
2537 |
||
2538 |
%{ /* NOCONTEXT */ |
|
2539 |
int ninsts, spc; |
|
2540 |
int sz; |
|
2541 |
OBJ theCopy; |
|
2542 |
OBJ cls; |
|
2543 |
int flags; |
|
2544 |
||
2545 |
cls = __qClass(self); |
|
2546 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
2547 |
||
2548 |
/* |
|
2549 |
* bail out for special objects .. |
|
2550 |
*/ |
|
2551 |
if (((flags & ~ARRAYMASK) == 0) |
|
2552 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
17757 | 2553 |
sz = __qSize(self); |
2554 |
__PROTECT__(self); |
|
2555 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
2556 |
__UNPROTECT__(self); |
|
2557 |
if (theCopy) { |
|
2558 |
cls = __qClass(self); |
|
2559 |
spc = __qSpace(theCopy); |
|
2560 |
||
2561 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
2562 |
||
2563 |
sz = sz - OHDR_SIZE; |
|
2564 |
if (sz) { |
|
2565 |
char *src, *dst; |
|
2566 |
||
2567 |
src = (char *)(__InstPtr(self)->i_instvars); |
|
2568 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
5755 | 2569 |
#ifdef bcopy4 |
17757 | 2570 |
{ |
2571 |
/* care for odd-number of longs */ |
|
2572 |
int nW = sz >> 2; |
|
2573 |
||
2574 |
if (sz & 3) { |
|
2575 |
nW++; |
|
2576 |
} |
|
2577 |
||
2578 |
bcopy4(src, dst, nW); |
|
2579 |
} |
|
5755 | 2580 |
#else |
17757 | 2581 |
bcopy(src, dst, sz); |
5755 | 2582 |
#endif |
2583 |
||
17757 | 2584 |
flags &= ARRAYMASK; |
2585 |
if (flags == POINTERARRAY) { |
|
2586 |
ninsts = __BYTES2OBJS__(sz); |
|
2587 |
} else { |
|
2588 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
2589 |
} |
|
2590 |
if (ninsts) { |
|
2591 |
do { |
|
2592 |
OBJ el; |
|
2593 |
||
2594 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
2595 |
__STORE_SPC(theCopy, el, spc); |
|
2596 |
} while (--ninsts); |
|
2597 |
} |
|
2598 |
} |
|
2599 |
RETURN (theCopy); |
|
2600 |
} |
|
5755 | 2601 |
} |
2602 |
%}. |
|
2603 |
"/ fallBack for special objects & memoryAllocation failure case |
|
2604 |
||
2605 |
^ self slowShallowCopy |
|
2606 |
! |
|
2607 |
||
2608 |
simpleDeepCopy |
|
2609 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2610 |
This method does NOT handle cycles - but is included to allow this |
5755 | 2611 |
slightly faster copy in situations where it is known that |
2612 |
no recursive references occur (LargeIntegers for example). |
|
2613 |
NOTICE: you will run into trouble, when trying this with recursive |
|
2614 |
objects (usually recursionInterrupt or memory-alert). |
|
8383 | 2615 |
This method corresponds to the 'traditional' deepCopy found in the Blue book." |
5755 | 2616 |
|
2617 |
|myClass aCopy| |
|
2618 |
||
2619 |
(myClass := self class) isVariable ifTrue:[ |
|
17757 | 2620 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2621 |
] ifFalse:[ |
17757 | 2622 |
aCopy := myClass basicNew |
5755 | 2623 |
]. |
2624 |
||
2625 |
"copy the instance variables" |
|
2626 |
aCopy cloneFrom:self performing:#simpleDeepCopy. |
|
2627 |
^ aCopy |
|
2628 |
||
2629 |
"a bad example (but ST/X should survive ...)" |
|
2630 |
" |
|
2631 |
|a| |
|
2632 |
a := Array new:3. |
|
2633 |
a at:3 put:a. |
|
2634 |
a simpleDeepCopy |
|
2635 |
" |
|
2636 |
! |
|
2637 |
||
2638 |
skipInstvarIndexInDeepCopy:index |
|
2639 |
"a helper for deepCopy; only indices for which this method returns |
|
2640 |
false are copied in a deep copy. |
|
2641 |
The default is false here - which means that everything is copied. |
|
2642 |
Can be redefined in subclasses for partial copies" |
|
2643 |
||
2644 |
^ false |
|
2645 |
! |
|
2646 |
||
2647 |
slowShallowCopy |
|
2648 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2649 |
i.e. the copy shares referenced instvars with its original. |
|
2650 |
This method is only invoked as a fallback from #shallowCopy." |
|
2651 |
||
2652 |
|myClass aCopy| |
|
2653 |
||
2654 |
(myClass := self class) isVariable ifTrue:[ |
|
17757 | 2655 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2656 |
] ifFalse:[ |
17757 | 2657 |
aCopy := myClass basicNew |
5755 | 2658 |
]. |
2659 |
||
2660 |
"copy the instance variables" |
|
2661 |
aCopy cloneFrom:self performing:#yourself. |
|
2662 |
^ aCopy |
|
2663 |
! ! |
|
2664 |
||
2665 |
!Object methodsFor:'debugging'! |
|
2666 |
||
7621 | 2667 |
assert:aBooleanOrBlock |
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2668 |
"fail, if the argument does not evaluate to true and report an error" |
6964 | 2669 |
|
11662 | 2670 |
"{ Pragma: +optSpace }" |
2671 |
||
11021 | 2672 |
<resource: #skipInDebuggersWalkBack> |
2673 |
||
8876 | 2674 |
aBooleanOrBlock == true ifTrue:[^ self]. |
11141
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2675 |
(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
|
2676 |
|
8876 | 2677 |
"/ could still be a block or false. |
11662 | 2678 |
(aBooleanOrBlock value) ifFalse:[ |
17757 | 2679 |
AssertionFailedError |
2680 |
raiseRequestWith:self |
|
11662 | 2681 |
errorString:('Assertion failed', ' { ',thisContext sender printString,' }') |
2682 |
]. |
|
2683 |
||
2684 |
" |
|
2685 |
self assert:false |
|
2686 |
" |
|
7621 | 2687 |
! |
2688 |
||
2689 |
assert:aBooleanOrBlock message:messageIfFailing |
|
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2690 |
"fail, if the argument does not evaluate to true and report an error" |
6961 | 2691 |
|
2692 |
"{ Pragma: +optSpace }" |
|
2693 |
||
11021 | 2694 |
<resource: #skipInDebuggersWalkBack> |
2695 |
||
11141
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2696 |
aBooleanOrBlock == true ifTrue:[^ self]. |
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2697 |
(Smalltalk at:#IgnoreAssertion ifAbsent:false) == true ifTrue:[^ self]. |
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2698 |
|
7621 | 2699 |
(aBooleanOrBlock value) ifFalse:[ |
17757 | 2700 |
AssertionFailedError |
2701 |
raiseRequestWith:self |
|
11662 | 2702 |
errorString:(messageIfFailing, ' {',thisContext sender printString,' }') |
2703 |
]. |
|
2704 |
||
2705 |
" |
|
2706 |
self assert:false message:'xxx' |
|
10651 | 2707 |
" |
6961 | 2708 |
! |
2709 |
||
5755 | 2710 |
basicInspect |
2711 |
"{ Pragma: +optSpace }" |
|
2712 |
||
2713 |
"launch an inspector on the receiver. |
|
2714 |
this method should NOT be redefined in subclasses." |
|
2715 |
||
2716 |
Inspector isNil ifTrue:[ |
|
17757 | 2717 |
" |
2718 |
for systems without GUI |
|
2719 |
" |
|
2720 |
self warn:'No Inspector defined (Inspector is nil).' |
|
5755 | 2721 |
] ifFalse:[ |
17757 | 2722 |
Inspector openOn:self |
5755 | 2723 |
] |
2724 |
||
2725 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
2726 |
! |
|
2727 |
||
11025 | 2728 |
breakPoint:someKey |
6954 | 2729 |
"{ Pragma: +optSpace }" |
2730 |
||
2731 |
"Like halt, but disabled by default. |
|
2732 |
Can be easily enabled. |
|
2733 |
Can be filtered on the arguments value (typically: a symbol). |
|
2734 |
Code with breakpoints may be even checked into the source repository" |
|
2735 |
||
2736 |
"Example: nil breakPoint:#stefan" |
|
2737 |
||
11025 | 2738 |
<resource: #skipInDebuggersWalkBack> |
2739 |
||
11048 | 2740 |
"/ dont send #breakPoint:info: here - ask cg why. |
2741 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
17757 | 2742 |
^ HaltSignal |
2743 |
raiseRequestWith:someKey |
|
2744 |
errorString:('Breakpoint encountered: %1' bindWith:someKey) |
|
11048 | 2745 |
]. |
11025 | 2746 |
|
2747 |
" |
|
2748 |
nil breakPoint:#stefan |
|
2749 |
nil breakPoint:#stefan info:'Hello' |
|
2750 |
Smalltalk enableBreakPoint:#stefan. |
|
2751 |
Smalltalk disableBreakPoint:#stefan. |
|
11048 | 2752 |
|
2753 |
EncounteredBreakPoints. |
|
2754 |
Smalltalk enableBreakPoint:#cg. |
|
2755 |
Smalltalk disableBreakPoint:#cg. |
|
11025 | 2756 |
" |
2757 |
! |
|
2758 |
||
2759 |
breakPoint:someKey info:infoString |
|
2760 |
"{ Pragma: +optSpace }" |
|
2761 |
||
2762 |
"Like halt, but disabled by default. |
|
2763 |
Can be easily enabled. |
|
2764 |
Can be filtered on the arguments value (typically: a symbol). |
|
2765 |
Code with breakpoints may be even checked into the source repository" |
|
2766 |
||
2767 |
"Example: nil breakPoint:#stefan" |
|
2768 |
||
2769 |
<resource: #skipInDebuggersWalkBack> |
|
2770 |
||
2771 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
17757 | 2772 |
^ HaltSignal |
2773 |
raiseRequestWith:someKey |
|
2774 |
errorString:(infoString bindWith:someKey) |
|
11025 | 2775 |
]. |
6954 | 2776 |
! |
2777 |
||
5995 | 2778 |
browse |
2779 |
"open a browser on the receivers class" |
|
2780 |
||
2781 |
self class theNonMetaclass browse |
|
2782 |
||
2783 |
" |
|
2784 |
10 browse |
|
2785 |
Collection browse |
|
2786 |
Collection class browse |
|
2787 |
" |
|
2788 |
! |
|
2789 |
||
11244 | 2790 |
debuggingCodeFor:someKey is:aBlock |
2791 |
"{ Pragma: +optSpace }" |
|
2792 |
||
2793 |
"aBlock is evaluated if breakPoints for somekey are enabled. |
|
2794 |
Allows for debugging code to be enabled/disabled via the breakpoint browser. |
|
2795 |
Can be easily enabled. |
|
2796 |
Can be filtered on the arguments value (typically: a symbol). |
|
2797 |
Code with breakpoints may be even checked into the source repository" |
|
2798 |
||
2799 |
"Example: nil debuggingCodeFor:#cg is:[ self halt ]" |
|
2800 |
||
2801 |
<resource: #skipInDebuggersWalkBack> |
|
2802 |
||
2803 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
2804 |
aBlock value |
11244 | 2805 |
]. |
2806 |
||
2807 |
" |
|
2808 |
Smalltalk disableBreakPoint:#cg. |
|
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
2809 |
nil debuggingCodeFor:#cg is:[ Transcript showCR:'here is some debug message for cg' ]. |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
2810 |
nil debuggingCodeFor:#stefan is:[ Transcript showCR:'here is some debug message for sv' ]. |
11244 | 2811 |
Smalltalk enableBreakPoint:#cg. |
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
2812 |
nil debuggingCodeFor:#cg is:[ Transcript showCR:'here is some debug message for cg' ]. |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
2813 |
nil debuggingCodeFor:#stefan is:[ Transcript showCR:'here is some debug message for sv' ]. |
11244 | 2814 |
Smalltalk disableBreakPoint:#cg. |
2815 |
||
2816 |
" |
|
2817 |
! |
|
2818 |
||
11025 | 2819 |
disableBreakPoint:someKey |
2820 |
"disable a breakPoint" |
|
2821 |
||
2822 |
"{ Pragma: +optSpace }" |
|
2823 |
||
2824 |
EnabledBreakPoints notNil ifTrue:[ |
|
17757 | 2825 |
EnabledBreakPoints remove:someKey ifAbsent:[]. |
2826 |
EnabledBreakPoints isEmpty ifTrue:[ |
|
2827 |
EnabledBreakPoints := nil |
|
2828 |
]. |
|
11025 | 2829 |
]. |
2830 |
||
2831 |
" |
|
2832 |
nil enableBreakPoint:#cg. |
|
2833 |
nil breakPoint:#cg. |
|
2834 |
nil disableBreakPoint:#cg |
|
2835 |
nil breakPoint:#cg. |
|
2836 |
" |
|
2837 |
! |
|
2838 |
||
2839 |
enableBreakPoint:someKey |
|
2840 |
"enable a breakPoint" |
|
2841 |
||
2842 |
"{ Pragma: +optSpace }" |
|
2843 |
||
2844 |
EnabledBreakPoints isNil ifTrue:[ |
|
17757 | 2845 |
EnabledBreakPoints := Set new. |
11025 | 2846 |
]. |
2847 |
EnabledBreakPoints add:someKey. |
|
2848 |
||
2849 |
" |
|
2850 |
nil enableBreakPoint:#cg. |
|
2851 |
nil breakPoint:#cg. |
|
2852 |
nil disableBreakPoint:#cg |
|
2853 |
nil breakPoint:#cg. |
|
2854 |
" |
|
2855 |
! |
|
2856 |
||
11048 | 2857 |
halt |
2858 |
"{ Pragma: +optSpace }" |
|
2859 |
||
2860 |
"enter debugger with halt-message. |
|
2861 |
The error is reported by raising the HaltSignal exception." |
|
2862 |
||
2863 |
<resource: #skipInDebuggersWalkBack> |
|
2864 |
||
2865 |
"/ dont send #halt: here - ask cg why. |
|
2866 |
(Smalltalk at:#IgnoreHalt ifAbsent:false) == true ifTrue:[^ self]. |
|
2867 |
^ HaltInterrupt raiseRequestWith:#halt |
|
2868 |
||
2869 |
"Modified: / 2.8.1999 / 17:00:29 / stefan" |
|
2870 |
"Modified: / 17.11.2001 / 22:47:44 / cg" |
|
2871 |
! |
|
2872 |
||
2873 |
halt:aString |
|
2874 |
"{ Pragma: +optSpace }" |
|
2875 |
||
2876 |
"enter debugger with halt-message. |
|
2877 |
The error is reported by raising the HaltSignal exception." |
|
2878 |
||
2879 |
<resource: #skipInDebuggersWalkBack> |
|
2880 |
||
2881 |
(Smalltalk at:#IgnoreHalt ifAbsent:false) == true ifTrue:[^ self]. |
|
2882 |
^ HaltInterrupt raiseRequestWith:#halt: errorString:aString |
|
2883 |
||
2884 |
"Modified: 8.5.1996 / 09:13:23 / cg" |
|
2885 |
! |
|
2886 |
||
5755 | 2887 |
inspectorClass |
2888 |
"{ Pragma: +optSpace }" |
|
2889 |
||
10460 | 2890 |
"return the class to use for inspect. |
5755 | 2891 |
Can (should) be redefined in classes for which a better inspector is available" |
2892 |
||
2893 |
^ Inspector |
|
2894 |
! |
|
2895 |
||
11025 | 2896 |
isBreakPointEnabled:someKey |
2897 |
"{ Pragma: +optSpace }" |
|
2898 |
||
2899 |
"controls which breakpoints to be enabled." |
|
2900 |
||
2901 |
"/ something = OperatingSystem getLoginName ifTrue:[^ true]. |
|
2902 |
"/ something = 'testThis' ifTrue:[^ true]. |
|
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2903 |
EncounteredBreakPoints notNil ifTrue:[ |
17757 | 2904 |
EncounteredBreakPoints add:someKey |
11335 | 2905 |
]. |
2906 |
||
2907 |
^ (EnabledBreakPoints notNil and:[ EnabledBreakPoints includes:someKey ]) |
|
11025 | 2908 |
|
2909 |
" |
|
2910 |
nil enableBreakPoint:#cg. |
|
2911 |
nil breakPoint:#cg. |
|
2912 |
nil disableBreakPoint:#cg |
|
2913 |
nil breakPoint:#cg. |
|
11045
85315d8893e4
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11044
diff
changeset
|
2914 |
|
85315d8893e4
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11044
diff
changeset
|
2915 |
EncounteredBreakPoints := Set new. |
11025 | 2916 |
" |
2917 |
! |
|
2918 |
||
5755 | 2919 |
mustBeBoolean |
2920 |
"this message is sent by the VM, if a non-Boolean receiver is encountered |
|
2921 |
in an if* or while* message. |
|
2922 |
Caveat: for now, this is only sent by the interpreter; |
|
2923 |
both the JIT and the stc compiler treat it as undefined." |
|
2924 |
||
11021 | 2925 |
<resource: #skipInDebuggersWalkBack> |
2926 |
||
5755 | 2927 |
self error:'Non boolean receiver - proceed for truth' mayProceed:true. |
2928 |
^ true |
|
2929 |
! |
|
2930 |
||
2931 |
mustBeKindOf:aClass |
|
10460 | 2932 |
"for compatibility & debugging support: |
5755 | 2933 |
check if the receiver isKindOf:aClass and raise an error if not. |
2934 |
Notice: |
|
17757 | 2935 |
it is VERY questionable, if it makes sense to add manual |
2936 |
type checks to a dynamically typed language like smalltalk. |
|
2937 |
It will, at least, slow down performance, |
|
2938 |
make your code less reusable and clutter your code with stupid sends |
|
2939 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
2940 |
use of isXXX check methods. |
|
5755 | 2941 |
You see: The author does not like this at all ..." |
2942 |
||
11021 | 2943 |
<resource: #skipInDebuggersWalkBack> |
2944 |
||
5755 | 2945 |
(self isKindOf:aClass) ifFalse:[ |
17757 | 2946 |
self error:'argument is not of expected type' |
5755 | 2947 |
] |
2948 |
! |
|
2949 |
||
6950 | 2950 |
obsoleteFeatureWarning |
2951 |
"{ Pragma: +optSpace }" |
|
2952 |
||
2953 |
"in methods which are going to be changed, a send to |
|
2954 |
this method is used to tell programmers that some feature/semantics is |
|
2955 |
used which is going to be changed in later ST/X versions. |
|
6963 | 2956 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)." |
6950 | 2957 |
|
2958 |
self obsoleteFeatureWarning:nil from:thisContext sender |
|
2959 |
! |
|
2960 |
||
2961 |
obsoleteFeatureWarning:message |
|
2962 |
"{ Pragma: +optSpace }" |
|
2963 |
||
2964 |
"in methods which are going to be changed, a send to |
|
2965 |
this method is used to tell programmers that some feature/semantics is |
|
2966 |
used which is going to be changed in later ST/X versions. |
|
6963 | 2967 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
2968 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 2969 |
|
2970 |
self obsoleteFeatureWarning:message from:thisContext sender |
|
2971 |
! |
|
2972 |
||
2973 |
obsoleteFeatureWarning:message from:aContext |
|
2974 |
"{ Pragma: +optSpace }" |
|
2975 |
||
2976 |
"in methods which are going to be changed, a send to |
|
2977 |
this method is used to tell programmers that some feature/semantics is |
|
2978 |
used which is going to be changed in later ST/X versions. |
|
6963 | 2979 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
2980 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 2981 |
|
11527 | 2982 |
|spec sender| |
6950 | 2983 |
|
2984 |
spec := aContext methodPrintString. |
|
11527 | 2985 |
sender := aContext sender. |
2986 |
||
6950 | 2987 |
('WARNING: the ''' , spec , ''' semantics will be changed.') infoPrintCR. |
2988 |
(' Its behavior may be different in future ST/X versions.') infoPrintCR. |
|
11527 | 2989 |
(' called from ' , sender printString) infoPrintCR. |
2990 |
((sender selector ? '') startsWith:'perform:') ifTrue:[ |
|
2991 |
(' called from ' , sender sender printString) infoPrintCR. |
|
7204 | 2992 |
]. |
6950 | 2993 |
message notNil ifTrue:[ |
11527 | 2994 |
'------> ' infoPrint. message infoPrintCR |
6950 | 2995 |
] |
2996 |
||
2997 |
" |
|
2998 |
Object obsoleteFeatureWarning:'foo' from:thisContext sender sender |
|
2999 |
" |
|
3000 |
! |
|
3001 |
||
5755 | 3002 |
obsoleteMethodWarning |
3003 |
"{ Pragma: +optSpace }" |
|
3004 |
||
3005 |
"in methods which are going to be obsoleted, a self send to |
|
3006 |
this method is used to tell programmers that a method is |
|
3007 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3008 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3009 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3010 |
|
3011 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
3012 |
! |
|
3013 |
||
3014 |
obsoleteMethodWarning:message |
|
3015 |
"{ Pragma: +optSpace }" |
|
3016 |
||
3017 |
"in methods which are going to be obsoleted, a self send to |
|
3018 |
this method is used to tell programmers that a method is |
|
3019 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3020 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3021 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3022 |
|
3023 |
self obsoleteMethodWarning:message from:thisContext sender |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3024 |
! |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3025 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3026 |
obsoleteMethodWarning:message from:aContext |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3027 |
"{ Pragma: +optSpace }" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3028 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3029 |
"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
|
3030 |
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
|
3031 |
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
|
3032 |
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
|
3033 |
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
|
3034 |
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
|
3035 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3036 |
|spec sender| |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3037 |
|
9509 | 3038 |
Smalltalk isSmalltalkDevelopmentSystem ifFalse:[ |
17757 | 3039 |
"ignore in production systems" |
3040 |
^ self. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3041 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3042 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3043 |
spec := aContext methodPrintString. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3044 |
sender := aContext sender. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3045 |
('WARNING: the ''' , spec , ''' method is obsolete.') infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3046 |
(' 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
|
3047 |
(' called from ' , sender printString) infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3048 |
(sender selector startsWith:'perform:') ifTrue:[ |
17757 | 3049 |
sender := sender sender. |
3050 |
(sender selector startsWith:'perform:') ifTrue:[ |
|
3051 |
sender := sender sender. |
|
3052 |
]. |
|
3053 |
(' called from ' , sender printString) infoPrintCR. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3054 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3055 |
message notNil ifTrue:[ |
17757 | 3056 |
'------> ' infoPrint. message infoPrintCR |
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3057 |
] |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3058 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3059 |
" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3060 |
Object obsoleteMethodWarning:'foo' from:thisContext sender sender |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3061 |
" |
9509 | 3062 |
|
3063 |
"Modified: / 10-08-2006 / 13:13:11 / cg" |
|
10558 | 3064 |
! |
3065 |
||
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3066 |
todo |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3067 |
"used to mark code pieces that have to be implemented" |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3068 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3069 |
<resource: #skipInDebuggersWalkBack> |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3070 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3071 |
self halt:'more work needed here'. |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3072 |
"/ aBlock value. |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3073 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3074 |
" |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3075 |
example: |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3076 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3077 |
... |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3078 |
self todo. |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3079 |
... |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3080 |
" |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3081 |
! |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3082 |
|
10558 | 3083 |
todo:aBlock |
3084 |
"used to mark code pieces that have to be implemented" |
|
3085 |
||
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3086 |
<resource: #skipInDebuggersWalkBack> |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3087 |
|
10558 | 3088 |
"/ self halt. |
3089 |
"/ aBlock value. |
|
3090 |
||
3091 |
" |
|
3092 |
example: |
|
3093 |
||
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3094 |
... |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3095 |
self todo:[ |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3096 |
code which needs more work ... |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3097 |
]. |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
3098 |
... |
10558 | 3099 |
" |
3100 |
||
3101 |
"Created: / 25-05-2007 / 21:34:39 / cg" |
|
3102 |
"Modified: / 29-05-2007 / 12:11:33 / cg" |
|
5755 | 3103 |
! ! |
3104 |
||
3105 |
!Object methodsFor:'dependents access'! |
|
3106 |
||
3107 |
addDependent:anObject |
|
3108 |
"make the argument, anObject be a dependent of the receiver" |
|
3109 |
||
3110 |
|wasBlocked| |
|
3111 |
||
3112 |
"/ must do this save from interrupts, since the dependents collection |
|
3113 |
"/ is possibly accessed from multiple threads. |
|
3114 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3115 |
"/ faster execution. |
|
3116 |
||
3117 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3118 |
[ |
|
17757 | 3119 |
|deps dep| |
3120 |
||
3121 |
deps := self dependents. |
|
3122 |
||
3123 |
"/ to save a fair amount of memory in case of |
|
3124 |
"/ many dependencies, we store a single dependent in |
|
3125 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3126 |
"/ added. |
|
3127 |
||
3128 |
(deps isNil or:[deps size == 0]) ifTrue:[ |
|
3129 |
self dependents:(WeakArray with:anObject) |
|
3130 |
] ifFalse:[ |
|
3131 |
deps class == WeakArray ifTrue:[ |
|
3132 |
dep := deps at:1. |
|
3133 |
dep ~~ anObject ifTrue:[ |
|
3134 |
(dep isNil or:[dep == 0]) ifTrue:[ |
|
3135 |
deps at:1 put:anObject |
|
3136 |
] ifFalse:[ |
|
3137 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
3138 |
] |
|
3139 |
] |
|
3140 |
] ifFalse:[ |
|
3141 |
deps add:anObject |
|
3142 |
] |
|
3143 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3144 |
] ensure:[ |
17757 | 3145 |
wasBlocked ifFalse:[ |
3146 |
OperatingSystem unblockInterrupts |
|
3147 |
] |
|
5755 | 3148 |
] |
3149 |
||
3150 |
"Modified: / 27.10.1997 / 19:35:52 / cg" |
|
3151 |
! |
|
3152 |
||
3153 |
breakDependents |
|
3154 |
"remove all dependencies from the receiver" |
|
3155 |
||
3156 |
self dependents:nil. |
|
3157 |
self nonWeakDependents:nil |
|
3158 |
||
3159 |
"Modified: / 19.4.1996 / 10:55:36 / cg" |
|
3160 |
"Created: / 27.2.1998 / 11:26:11 / stefan" |
|
3161 |
! |
|
3162 |
||
8542 | 3163 |
breakDependentsRecursively |
10460 | 3164 |
"remove all dependencies from the receiver and |
8542 | 3165 |
recursively from all objects referred to by the receiver." |
3166 |
||
3167 |
self breakDependents. |
|
10460 | 3168 |
1 to:self class instSize do:[:idx | |
17757 | 3169 |
(self instVarAt:idx) breakDependentsRecursively. |
10460 | 3170 |
]. |
3171 |
1 to:self basicSize do:[:idx | |
|
17757 | 3172 |
(self basicAt:idx) breakDependentsRecursively. |
8542 | 3173 |
] |
3174 |
! |
|
3175 |
||
5755 | 3176 |
dependents |
3177 |
"return a Collection of dependents. |
|
3178 |
The default implementation here uses a global WeakDictionary to store |
|
10460 | 3179 |
dependents |
5755 | 3180 |
This may be too slow for high frequency change&update, |
3181 |
therefore, some classes (Model) redefine this for better performance. |
|
3182 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
3183 |
||
3184 |
|deps| |
|
3185 |
||
3186 |
(deps := Dependencies at:self ifAbsent:nil) isNil ifTrue:[ |
|
17757 | 3187 |
^ #(). |
5755 | 3188 |
]. |
3189 |
^ deps |
|
3190 |
||
3191 |
"Modified: / 26.1.1998 / 11:18:15 / cg" |
|
3192 |
! |
|
3193 |
||
3194 |
dependents:aCollection |
|
3195 |
"set the collection of dependents. |
|
3196 |
The default implementation here uses a global Dictionary to store |
|
3197 |
dependents which may be too slow for high frequency change&update. |
|
3198 |
Therefore, some classes (Model) redefine this for better performance." |
|
3199 |
||
3200 |
"/ must do this save from interrupts, since the dependents collection |
|
3201 |
"/ is possibly accessed from multiple threads. |
|
3202 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3203 |
"/ faster execution (and to avoid creation of garbage blocks). |
|
3204 |
||
3205 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
17757 | 3206 |
"/ the common case - already blocked |
3207 |
||
3208 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
3209 |
Dependencies removeKey:self ifAbsent:nil |
|
3210 |
] ifFalse:[ |
|
3211 |
Dependencies at:self put:aCollection |
|
3212 |
]. |
|
3213 |
^ self |
|
5755 | 3214 |
]. |
3215 |
||
3216 |
[ |
|
17757 | 3217 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3218 |
Dependencies removeKey:self ifAbsent:nil |
|
3219 |
] ifFalse:[ |
|
3220 |
Dependencies at:self put:aCollection |
|
3221 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3222 |
] ensure:[ |
17757 | 3223 |
OperatingSystem unblockInterrupts |
5755 | 3224 |
] |
3225 |
||
3226 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
|
3227 |
! |
|
3228 |
||
3229 |
dependentsDo:aBlock |
|
3230 |
"evaluate aBlock for all of my dependents" |
|
3231 |
||
3232 |
|deps nwDeps| |
|
3233 |
||
3234 |
deps := self dependents. |
|
3235 |
deps size ~~ 0 ifTrue:[ |
|
17757 | 3236 |
deps do:[:d | |
3237 |
(d notNil and:[d ~~ 0]) ifTrue:[ |
|
3238 |
aBlock value:d |
|
3239 |
] |
|
3240 |
] |
|
5755 | 3241 |
]. |
3242 |
nwDeps := self nonWeakDependents. |
|
3243 |
(nwDeps ~~ deps and:[nwDeps size ~~ 0]) ifTrue:[ |
|
17757 | 3244 |
nwDeps do:aBlock |
5755 | 3245 |
]. |
3246 |
||
3247 |
"Modified: / 30.1.1998 / 14:03:40 / cg" |
|
3248 |
! |
|
3249 |
||
3250 |
myDependents |
|
3251 |
"same as dependents - ST-80 compatibility" |
|
3252 |
||
3253 |
^ self dependents |
|
3254 |
! |
|
3255 |
||
3256 |
release |
|
3257 |
"remove all references to objects that may refer to self. |
|
3258 |
Subclasses may redefine this method but should do a 'super release'." |
|
3259 |
||
3260 |
self breakDependents |
|
3261 |
||
3262 |
"Modified: / 27.2.1998 / 11:29:35 / stefan" |
|
3263 |
! |
|
3264 |
||
3265 |
removeDependent:anObject |
|
3266 |
"make the argument, anObject be independent 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 |
[ |
|
17757 | 3277 |
|deps n d| |
3278 |
||
3279 |
deps := self dependents. |
|
3280 |
deps size ~~ 0 ifTrue:[ |
|
3281 |
||
3282 |
"/ to save a fair amount of memory in case of |
|
3283 |
"/ many dependencies, we store a single dependent in |
|
3284 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3285 |
"/ added. Here we have to do the inverse ... |
|
3286 |
||
3287 |
((deps class == WeakArray) or:[deps class == Array]) ifTrue:[ |
|
3288 |
((d := deps at:1) == anObject |
|
3289 |
or:[d isNil |
|
3290 |
or:[d == 0]]) ifTrue:[ |
|
3291 |
self dependents:nil |
|
3292 |
] |
|
3293 |
] ifFalse:[ |
|
3294 |
deps remove:anObject ifAbsent:[]. |
|
3295 |
(n := deps size) == 0 ifTrue:[ |
|
3296 |
self dependents:nil |
|
3297 |
] ifFalse:[ |
|
3298 |
n == 1 ifTrue:[ |
|
3299 |
d := deps firstIfEmpty:nil. |
|
3300 |
d notNil ifTrue:[ |
|
3301 |
deps := (deps isWeakCollection ifTrue:WeakArray ifFalse:Array) with:d |
|
3302 |
] ifFalse:[ |
|
3303 |
deps := nil |
|
3304 |
]. |
|
3305 |
self dependents:deps. |
|
3306 |
] |
|
3307 |
] |
|
3308 |
] |
|
3309 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3310 |
] ensure:[ |
17757 | 3311 |
wasBlocked ifFalse:[ |
3312 |
OperatingSystem unblockInterrupts |
|
3313 |
] |
|
5755 | 3314 |
] |
3315 |
||
3316 |
"Modified: / 26.1.1998 / 19:51:50 / cg" |
|
3317 |
! ! |
|
3318 |
||
7266 | 3319 |
!Object methodsFor:'dependents access (non weak)'! |
5755 | 3320 |
|
3321 |
addNonWeakDependent:anObject |
|
3322 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
|
10460 | 3323 |
Be careful: this nonWeakDependency will prevent the dependent from being |
5755 | 3324 |
garbage collected unless the dependency is removed. |
3325 |
This is a private mechanism, for directed dependencies." |
|
3326 |
||
3327 |
|wasBlocked| |
|
3328 |
||
3329 |
"/ must do this save from interrupts, since the dependents collection |
|
3330 |
"/ is possibly accessed from multiple threads. |
|
3331 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3332 |
"/ faster execution. |
|
3333 |
||
3334 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3335 |
[ |
|
17757 | 3336 |
|deps dep| |
3337 |
||
3338 |
deps := self nonWeakDependents. |
|
3339 |
||
3340 |
"/ to save a fair amount of memory in case of |
|
3341 |
"/ many dependencies, we store a single dependent in |
|
3342 |
"/ an Array, and switch to a Set if more dependents are |
|
3343 |
"/ added. |
|
3344 |
||
3345 |
deps size == 0 ifTrue:[ |
|
3346 |
anObject notNil ifTrue:[ |
|
3347 |
self nonWeakDependents:(Array with:anObject). |
|
3348 |
] ifFalse:[ |
|
3349 |
"adding nil causes problems when adding the next one |
|
3350 |
(see below: trying to add nil to IdentitySet)" |
|
9442 | 3351 |
"/ self halt:'try to add nil to list of dependents'. |
17757 | 3352 |
]. |
3353 |
] ifFalse:[ |
|
3354 |
deps class == Array ifTrue:[ |
|
3355 |
dep := deps at:1. |
|
3356 |
dep ~~ anObject ifTrue:[ |
|
3357 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
3358 |
] |
|
3359 |
] ifFalse:[ |
|
3360 |
deps add:anObject |
|
3361 |
] |
|
3362 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3363 |
] ensure:[ |
17757 | 3364 |
wasBlocked ifFalse:[ |
3365 |
OperatingSystem unblockInterrupts |
|
3366 |
] |
|
5755 | 3367 |
] |
3368 |
||
3369 |
"Created: / 19.4.1996 / 10:54:08 / cg" |
|
3370 |
"Modified: / 30.1.1998 / 14:03:08 / cg" |
|
3371 |
! |
|
3372 |
||
3373 |
nonWeakDependents |
|
3374 |
"return a Collection of nonWeakDependents - empty if there is none. |
|
3375 |
This is a private mechanism for directed dependencies." |
|
3376 |
||
3377 |
NonWeakDependencies isNil ifTrue:[^ #()]. |
|
3378 |
^ NonWeakDependencies at:self ifAbsent:#() |
|
3379 |
||
3380 |
"Created: / 19.4.1996 / 10:55:06 / cg" |
|
3381 |
"Modified: / 30.1.1998 / 14:06:47 / cg" |
|
3382 |
! |
|
3383 |
||
3384 |
nonWeakDependents:aCollection |
|
3385 |
"set the collection of nonWeak dependents. |
|
3386 |
This is a private helper for directed dependencies." |
|
3387 |
||
3388 |
[ |
|
17757 | 3389 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3390 |
NonWeakDependencies removeKey:self ifAbsent:nil |
|
3391 |
] ifFalse:[ |
|
3392 |
NonWeakDependencies at:self put:aCollection |
|
3393 |
] |
|
5755 | 3394 |
] valueUninterruptably |
3395 |
||
3396 |
"Created: 19.4.1996 / 11:07:47 / cg" |
|
3397 |
! |
|
3398 |
||
3399 |
removeNonWeakDependent:anObject |
|
3400 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
|
3401 |
(i.e. make it independent of the receiver)" |
|
3402 |
||
3403 |
|wasBlocked| |
|
3404 |
||
3405 |
"/ must do this save from interrupts, since the dependents collection |
|
3406 |
"/ is possibly accessed from multiple threads. |
|
3407 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3408 |
"/ faster execution. |
|
3409 |
||
3410 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3411 |
[ |
|
17757 | 3412 |
|deps n| |
3413 |
||
3414 |
deps := self nonWeakDependents. |
|
3415 |
deps size ~~ 0 ifTrue:[ |
|
3416 |
deps class == Array ifTrue:[ |
|
3417 |
(deps at:1) == anObject ifTrue:[ |
|
3418 |
self nonWeakDependents:nil |
|
3419 |
] |
|
3420 |
] ifFalse:[ |
|
3421 |
deps remove:anObject ifAbsent:[]. |
|
3422 |
(n := deps size) == 0 ifTrue:[ |
|
3423 |
self nonWeakDependents:nil |
|
3424 |
] ifFalse:[ |
|
3425 |
n == 1 ifTrue:[ |
|
3426 |
self nonWeakDependents:(Array with:(deps first)) |
|
3427 |
] |
|
3428 |
] |
|
3429 |
] |
|
3430 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3431 |
] ensure:[ |
17757 | 3432 |
wasBlocked ifFalse:[ |
3433 |
OperatingSystem unblockInterrupts |
|
3434 |
] |
|
5755 | 3435 |
] |
3436 |
||
3437 |
"Created: / 19.4.1996 / 11:44:44 / cg" |
|
3438 |
"Modified: / 30.1.1998 / 14:04:01 / cg" |
|
3439 |
! ! |
|
3440 |
||
9279 | 3441 |
|
3442 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
3443 |
||
3444 |
removeActionsForEvent:eventName |
|
3445 |
"remove ST/V-style event triggers." |
|
3446 |
||
3447 |
self retractInterestsIn:eventName |
|
3448 |
! |
|
3449 |
||
3450 |
removeAllActionsWithReceiver:anObject |
|
3451 |
"remove ST/V-style event triggers." |
|
3452 |
||
3453 |
self retractInterestsFor:anObject |
|
3454 |
! |
|
3455 |
||
3456 |
triggerEvent:eventSymbol withArguments:parameters |
|
3457 |
"perform ST/V-style event triggering." |
|
3458 |
||
3459 |
self changed:eventSymbol with:parameters. |
|
3460 |
! ! |
|
3461 |
||
5755 | 3462 |
!Object methodsFor:'displaying'! |
3463 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3464 |
ascentOn:aGC |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3465 |
"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
|
3466 |
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
|
3467 |
coordinate is given by y. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3468 |
In other words: some draw above the given y coordinate. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3469 |
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
|
3470 |
the given y coordinate." |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3471 |
|
11065
17c01b01000f
Simplify (and speed up) #ascentOn:
Stefan Vogel <sv@exept.de>
parents:
11048
diff
changeset
|
3472 |
^ aGC fontAscent |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3473 |
! |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3474 |
|
6900 | 3475 |
displayOn:aGCOrStream |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3476 |
"Compatibility |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3477 |
append a printed desription on some stream (Dolphin, Squeak) |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3478 |
OR: |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3479 |
display the receiver in a graphicsContext at 0@0 (ST80). |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3480 |
This method allows for any object to be displayed in some view |
5755 | 3481 |
(although the fallBack is to display its printString ...)" |
3482 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3483 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3484 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
6900 | 3485 |
(aGCOrStream isStream or:[aGCOrStream == Transcript]) ifTrue:[ |
17757 | 3486 |
self printOn:aGCOrStream. |
3487 |
^ self |
|
6900 | 3488 |
]. |
3489 |
^ self displayOn:aGCOrStream x:0 y:0. |
|
5755 | 3490 |
|
3491 |
"Created: 29.5.1996 / 16:28:58 / cg" |
|
3492 |
! |
|
3493 |
||
3494 |
displayOn:aGC at:aPoint |
|
3495 |
"ST-80 Compatibility |
|
3496 |
display the receiver in a graphicsContext - this method allows |
|
3497 |
for any object to be displayed in a ListView - for example." |
|
3498 |
||
3499 |
^ self displayOn:aGC x:(aPoint x) y:(aPoint y). |
|
3500 |
! |
|
3501 |
||
3502 |
displayOn:aGC x:x y:y |
|
3503 |
"display the receiver in a graphicsContext - this method allows |
|
3504 |
for any object to be displayed in a ListView - for example." |
|
3505 |
||
3506 |
self displayOn:aGC x:x y:y opaque:false |
|
3507 |
||
3508 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3509 |
! |
|
3510 |
||
3511 |
displayOn:aGc x:x y:y opaque:opaque |
|
3512 |
"display the receiver in a graphicsContext - this method allows |
|
3513 |
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
|
3514 |
The fallBack here shows the receivers displayString. |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3515 |
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
|
3516 |
ask using #ascentOn: if required" |
5755 | 3517 |
|
3518 |
|s yBaseline| |
|
3519 |
||
3520 |
s := self displayString. |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3521 |
yBaseline := y "+ aGc font ascent". |
5755 | 3522 |
opaque ifTrue:[ |
17757 | 3523 |
aGc displayOpaqueString:s x:x y:yBaseline. |
5755 | 3524 |
] ifFalse:[ |
17757 | 3525 |
aGc displayString:s x:x y:yBaseline. |
5755 | 3526 |
]. |
3527 |
||
3528 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3529 |
! |
|
3530 |
||
3531 |
displayOpaqueOn:aGC x:x y:y |
|
3532 |
"display the receiver in a graphicsContext - this method allows |
|
3533 |
for any object to be displayed in a ListView - for example." |
|
3534 |
||
3535 |
self displayOn:aGC x:x y:y opaque:true |
|
3536 |
||
3537 |
"Modified: / 29.5.1996 / 16:29:38 / cg" |
|
3538 |
"Created: / 26.10.1997 / 15:01:36 / cg" |
|
3539 |
! |
|
3540 |
||
3541 |
displayString |
|
3542 |
"return a string used when displaying the receiver in a view; |
|
3543 |
for example an Inspector. This is usually the same as printString, |
|
3544 |
but sometimes redefined for a better look." |
|
3545 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3546 |
|s| |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3547 |
|
8322
95ca965f65ed
Handle unicode in #displayString
Stefan Vogel <sv@exept.de>
parents:
8300
diff
changeset
|
3548 |
s := CharacterWriteStream on:(String new:32). |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3549 |
self displayOn:s. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3550 |
^ s contents |
5755 | 3551 |
|
3552 |
" |
|
10460 | 3553 |
#(1 2 3) printString |
3554 |
#(1 2 3) displayString |
|
5755 | 3555 |
#(1 2 3) storeString |
3556 |
" |
|
3557 |
! |
|
3558 |
||
3559 |
heightOn:aGC |
|
3560 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
3561 |
||
3562 |
^ (aGC font onDevice:aGC device) heightOf:(self displayString) |
|
3563 |
! |
|
3564 |
||
6654 | 3565 |
widthFrom:startIndex to:endIndex on:aGC |
3566 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3567 |
||
3568 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) from:startIndex to:endIndex |
|
3569 |
! |
|
3570 |
||
5755 | 3571 |
widthOn:aGC |
3572 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3573 |
||
3574 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) |
|
3575 |
! ! |
|
3576 |
||
7359 | 3577 |
!Object methodsFor:'double dispatching'! |
3578 |
||
3579 |
equalFromComplex:aComplex |
|
3580 |
"adding this method here allows for any non-number to be compared to a complex |
|
3581 |
and return false from this comparison. |
|
3582 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3583 |
which uses #= (i.e. a Set or Dictionary)." |
|
3584 |
||
3585 |
^ false |
|
3586 |
! |
|
3587 |
||
3588 |
equalFromFixedPoint:aFixedPoint |
|
3589 |
"adding this method here allows for any non-number to be compared to a fixedPoint |
|
3590 |
and return false from this comparison. |
|
3591 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3592 |
which uses #= (i.e. a Set or Dictionary)." |
|
3593 |
||
3594 |
^ false |
|
3595 |
! |
|
3596 |
||
3597 |
equalFromFloat:aFloat |
|
3598 |
"adding this method here allows for any non-number to be compared to a float |
|
3599 |
and return false from this comparison. |
|
3600 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3601 |
which uses #= (i.e. a Set or Dictionary)." |
|
3602 |
||
3603 |
^ false |
|
3604 |
! |
|
3605 |
||
3606 |
equalFromFraction:aFraction |
|
3607 |
"adding this method here allows for any non-number to be compared to a fraction |
|
3608 |
and return false from this comparison. |
|
3609 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3610 |
which uses #= (i.e. a Set or Dictionary)." |
|
3611 |
||
3612 |
^ false |
|
3613 |
! |
|
3614 |
||
3615 |
equalFromInteger:anInteger |
|
3616 |
"adding this method here allows for any non-number to be compared to an integer |
|
3617 |
and return false from this comparison. |
|
3618 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3619 |
which uses #= (i.e. a Set or Dictionary)." |
|
3620 |
||
3621 |
^ false |
|
3622 |
! |
|
3623 |
||
7455 | 3624 |
equalFromLargeFloat:aLargeFloat |
3625 |
"adding this method here allows for any non-number to be compared to a largeFloat |
|
3626 |
and return false from this comparison. |
|
3627 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3628 |
which uses #= (i.e. a Set or Dictionary)." |
|
3629 |
||
3630 |
^ false |
|
3631 |
! |
|
3632 |
||
7359 | 3633 |
equalFromLongFloat:aLongFloat |
3634 |
"adding this method here allows for any non-number to be compared to a longFloat |
|
3635 |
and return false from this comparison. |
|
3636 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3637 |
which uses #= (i.e. a Set or Dictionary)." |
|
3638 |
||
3639 |
^ false |
|
3640 |
! |
|
3641 |
||
3642 |
equalFromShortFloat:aShortFloat |
|
3643 |
"adding this method here allows for any non-number to be compared to a shortFloat |
|
3644 |
and return false from this comparison. |
|
3645 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3646 |
which uses #= (i.e. a Set or Dictionary)." |
|
3647 |
||
3648 |
^ false |
|
3649 |
! ! |
|
3650 |
||
5755 | 3651 |
!Object methodsFor:'encoding & decoding'! |
3652 |
||
3653 |
decodeAsLiteralArray |
|
8832 | 3654 |
"given a literalEncoding in the receiver, |
3655 |
create & return the corresponding object. |
|
3656 |
The inverse operation to #literalArrayEncoding." |
|
3657 |
||
5755 | 3658 |
^ self |
3659 |
! |
|
3660 |
||
3661 |
encodeOn:anEncoder with:aParameter |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3662 |
"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
|
3663 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3664 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3665 |
|
8404 | 3666 |
self acceptVisitor:anEncoder with:aParameter |
6718 | 3667 |
! |
3668 |
||
3669 |
encodingVectorForInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3670 |
"OBSOLETE, use elementDescriptorForInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3671 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3672 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3673 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3674 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
6718 | 3675 |
|
3676 |
" |
|
3677 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
3678 |
Dictionary new encodingVectorForInstanceVariables |
|
3679 |
(5 @ nil) encodingVectorForInstanceVariables |
|
3680 |
" |
|
3681 |
! |
|
3682 |
||
3683 |
encodingVectorForNonNilInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3684 |
"OBSOLETE, use elementDescriptorForNonNilInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3685 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3686 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3687 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3688 |
^ self elementDescriptorForInstanceVariablesMatching:[:varVal | varVal notNil]. |
6718 | 3689 |
|
3690 |
" |
|
3691 |
#(1 2 3 nil true symbol) encodingVectorForNonNilInstanceVariables |
|
3692 |
(5 @ nil) encodingVectorForNonNilInstanceVariables |
|
3693 |
" |
|
3694 |
! |
|
3695 |
||
5755 | 3696 |
fromLiteralArrayEncoding:aSpecArray |
8798 | 3697 |
"read my attributes from aSpecArray. |
3698 |
Recursively decodes arguments." |
|
3699 |
||
3700 |
|sel litVal val |
|
5755 | 3701 |
stop "{ Class:SmallInteger }" | |
3702 |
||
3703 |
stop := aSpecArray size. |
|
3704 |
||
3705 |
2 to:stop by:2 do:[:i| |
|
17757 | 3706 |
sel := aSpecArray at:i. |
3707 |
litVal := aSpecArray at:i + 1. |
|
3708 |
||
3709 |
(self respondsTo:sel) ifTrue:[ |
|
3710 |
val := litVal decodeAsLiteralArray. |
|
3711 |
self perform:sel with:val |
|
3712 |
] ifFalse:[ |
|
3713 |
Transcript show:self class name; show:': unhandled literalArrayEncoding attribute: '. |
|
3714 |
Transcript showCR:sel. |
|
3715 |
||
3716 |
"/ thats a debug halt, |
|
3717 |
"/ it should probably be removed (to simply ignore unhandled attributes)... |
|
3718 |
"/ for now, it is left in, in order to easily find incompatibilities between |
|
3719 |
"/ VW and ST/X. |
|
3720 |
self halt:('Unrecognized attribute in spec: #', sel). "/ value is: val / litVal. |
|
3721 |
] |
|
5755 | 3722 |
] |
3723 |
! |
|
3724 |
||
3725 |
literalArrayEncoding |
|
3726 |
"generate a literalArrayEncoding array for myself. |
|
3727 |
This uses #literalArrayEncodingSlotOrder which defines the slots and |
|
3728 |
order and #skippedInLiteralEncoding which defines slots to skip. |
|
3729 |
For most subclasses, there is no need to redefine those." |
|
3730 |
||
8832 | 3731 |
|names encoding cls skipped slots| |
5755 | 3732 |
|
3733 |
self isLiteral ifTrue:[ |
|
17757 | 3734 |
^ self |
5755 | 3735 |
]. |
3736 |
||
8832 | 3737 |
slots := self literalArrayEncodingSlotOrder. |
5755 | 3738 |
skipped := self skippedInLiteralEncoding. |
3739 |
cls := self class. |
|
3740 |
names := cls allInstVarNames. |
|
8832 | 3741 |
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
|
3742 |
encoding add:cls name. |
8832 | 3743 |
|
3744 |
slots do:[:instSlot | |
|
17757 | 3745 |
|value nm| |
3746 |
||
3747 |
nm := names at:instSlot. |
|
3748 |
(skipped includes:nm) ifFalse:[ |
|
3749 |
(value := self instVarAt:instSlot) notNil ifTrue:[ |
|
3750 |
encoding add:(nm , ':') asSymbol. |
|
3751 |
encoding add:value literalArrayEncoding |
|
3752 |
] |
|
3753 |
] |
|
5755 | 3754 |
]. |
3755 |
^ encoding asArray |
|
8841 | 3756 |
|
3757 |
" |
|
17757 | 3758 |
(1 -> 2) literalArrayEncoding |
3759 |
DebugView menuSpec decodeAsLiteralArray literalArrayEncoding = |
|
3760 |
DebugView menuSpec |
|
8841 | 3761 |
" |
5755 | 3762 |
! |
3763 |
||
3764 |
literalArrayEncodingSlotOrder |
|
3765 |
"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
|
3766 |
a literalArrayEncoding" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3767 |
|
5755 | 3768 |
^ 1 to:self class instSize |
3769 |
! |
|
3770 |
||
7112 | 3771 |
postDecodeFrom:aDecoder aspect:aspectSymbol |
3772 |
"invoked by xmlDecoder (and others in the future), after an |
|
3773 |
object has been decoded (i.e. its instance variables have been restored)" |
|
3774 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3775 |
^ self |
7112 | 3776 |
! |
3777 |
||
5755 | 3778 |
skippedInLiteralEncoding |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3779 |
"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
|
3780 |
|
5755 | 3781 |
^ #() |
3782 |
! ! |
|
3783 |
||
3784 |
!Object methodsFor:'error handling'! |
|
3785 |
||
17786 | 3786 |
ambiguousMessage:aMessage |
3787 |
"this message is sent by the system in case that it |
|
3788 |
is not clear which method to execute in response to |
|
3789 |
aMessage. |
|
3790 |
Such situation may occur when a current selector namespace |
|
3791 |
imports two namespaces and both defines method with |
|
3792 |
requested selector." |
|
3793 |
||
3794 |
<context: #return> |
|
3795 |
<resource: #skipInDebuggersWalkBack> |
|
3796 |
||
3797 |
^ AmbiguousMessage raiseRequestWith:aMessage |
|
3798 |
||
3799 |
"Created: / 21-07-2010 / 15:44:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3800 |
! |
|
3801 |
||
5755 | 3802 |
appropriateDebugger:aSelector |
3803 |
"{ Pragma: +optSpace }" |
|
3804 |
||
3805 |
"return an appropriate debugger to use. |
|
3806 |
If there is already a debugger active on the stack, and it is |
|
3807 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
3808 |
||
3809 |
|context| |
|
3810 |
||
3811 |
"DebugView cannot run without system processes" |
|
3812 |
||
10460 | 3813 |
(Processor isNil |
5755 | 3814 |
or:[Processor activeProcessIsSystemProcess |
3815 |
or:[Smalltalk isInitialized not]]) ifTrue:[ |
|
17757 | 3816 |
^ MiniDebugger |
5755 | 3817 |
]. |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
3818 |
(Screen isNil or:[Screen default isNil or:[Screen default isOpen not]]) ifTrue:[ |
17757 | 3819 |
Debugger isNil ifTrue:[^ nil]. |
3820 |
^ MiniDebugger |
|
5755 | 3821 |
]. |
3822 |
||
3823 |
context := thisContext. |
|
3824 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
3825 |
[context notNil] whileTrue:[ |
|
17757 | 3826 |
((context receiver class == Debugger) |
3827 |
and:[context selector == aSelector]) ifTrue:[ |
|
3828 |
"we are already in some Debugger" |
|
3829 |
(Debugger == MiniDebugger) ifTrue:[ |
|
3830 |
"we are already in the MiniDebugger" |
|
3831 |
ErrorRecursion ifFalse:[ |
|
3832 |
Smalltalk fatalAbort:'recursive error ...' |
|
3833 |
] |
|
3834 |
]. |
|
3835 |
MiniDebugger isNil ifTrue:[ |
|
3836 |
Smalltalk fatalAbort:'no debugger' |
|
3837 |
]. |
|
3838 |
||
3839 |
"ok, an error occured while in the graphical debugger; |
|
3840 |
lets try MiniDebugger" |
|
3841 |
^ MiniDebugger |
|
3842 |
]. |
|
3843 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
5755 | 3844 |
]. |
3845 |
"not within Debugger - no problem" |
|
3846 |
^ Debugger |
|
3847 |
||
3848 |
"Modified: / 23.9.1996 / 12:14:52 / stefan" |
|
3849 |
"Modified: / 19.5.1999 / 18:05:00 / cg" |
|
3850 |
! |
|
3851 |
||
3852 |
cannotSendMessage:aMessage to:someReceiver |
|
3853 |
"this message is sent by the runtime system (VM), |
|
3854 |
when a message is sent to some object, whose class is not |
|
3855 |
a valid behavior (see documentation in Behavior)." |
|
3856 |
||
11021 | 3857 |
<resource: #skipInDebuggersWalkBack> |
3858 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3859 |
^ VMInternalError |
17757 | 3860 |
raiseWith:someReceiver |
3861 |
errorString:('bad class in send of #' , aMessage selector) |
|
5755 | 3862 |
|
3863 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
3864 |
! |
|
3865 |
||
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
3866 |
conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
3867 |
"return the signal used for conversion error handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
3868 |
|
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
3869 |
^ self class conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
3870 |
! |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
3871 |
|
5755 | 3872 |
doesNotUnderstand:aMessage |
3873 |
"this message is sent by the runtime system (VM) when |
|
3874 |
a message is not understood by some object (i.e. there |
|
3875 |
is no method for that selector). The original message has |
|
3876 |
been packed into aMessage (i.e. the receiver, selector and |
|
3877 |
any arguments) and the original receiver is then sent the |
|
3878 |
#doesNotUnderstand: message. |
|
3879 |
Here, we raise another signal which usually enters the debugger. |
|
3880 |
You can of course redefine #doesNotUnderstand: in your classes |
|
10460 | 3881 |
to implement message delegation, |
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
3882 |
or handle the MessageNotUnderstood exception gracefully." |
5755 | 3883 |
|
3884 |
<context: #return> |
|
11021 | 3885 |
<resource: #skipInDebuggersWalkBack> |
5755 | 3886 |
|
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
3887 |
^ MessageNotUnderstood raiseRequestWith:aMessage |
5755 | 3888 |
! |
3889 |
||
3890 |
elementBoundsError |
|
3891 |
"{ Pragma: +optSpace }" |
|
3892 |
||
10460 | 3893 |
"report an error that badElement is out of bounds |
5755 | 3894 |
(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
|
3895 |
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
|
3896 |
|
11021 | 3897 |
<resource: #skipInDebuggersWalkBack> |
3898 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3899 |
^ ElementBoundsError raise |
5755 | 3900 |
|
3901 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
3902 |
! |
|
3903 |
||
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3904 |
elementBoundsError:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3905 |
"{ Pragma: +optSpace }" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3906 |
|
10460 | 3907 |
"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
|
3908 |
(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
|
3909 |
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
|
3910 |
|
11021 | 3911 |
<resource: #skipInDebuggersWalkBack> |
3912 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3913 |
^ ElementBoundsError raiseWith:aValue |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3914 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3915 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3916 |
! |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3917 |
|
5755 | 3918 |
elementNotCharacter |
3919 |
"{ Pragma: +optSpace }" |
|
3920 |
||
3921 |
"report an error that object to be stored is no Character. |
|
3922 |
(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
|
3923 |
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
|
3924 |
|
11021 | 3925 |
<resource: #skipInDebuggersWalkBack> |
3926 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3927 |
^ ElementBoundsError raise |
5755 | 3928 |
|
3929 |
"Modified: 8.5.1996 / 09:12:49 / cg" |
|
3930 |
! |
|
3931 |
||
3932 |
elementNotInteger |
|
3933 |
"{ Pragma: +optSpace }" |
|
3934 |
||
3935 |
"report an error that object to be stored is not Integer. |
|
3936 |
(in collections that store integers only). |
|
3937 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3938 |
||
11021 | 3939 |
<resource: #skipInDebuggersWalkBack> |
3940 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
3941 |
^ ElementBoundsError raise |
5755 | 3942 |
|
3943 |
"Modified: 8.5.1996 / 09:12:51 / cg" |
|
3944 |
! |
|
3945 |
||
3946 |
error |
|
3947 |
"{ Pragma: +optSpace }" |
|
3948 |
||
3949 |
"report error that an error occured. |
|
3950 |
The error is reported by raising the Error exception, |
|
3951 |
which is non-proceedable. |
|
3952 |
If no handler has been setup, a debugger is entered." |
|
3953 |
||
11021 | 3954 |
<context: #return> |
3955 |
<resource: #skipInDebuggersWalkBack> |
|
3956 |
||
5755 | 3957 |
Error raiseWith:#error: |
3958 |
||
3959 |
" |
|
3960 |
nil error |
|
3961 |
" |
|
3962 |
||
3963 |
"Modified: / 8.5.1996 / 09:13:01 / cg" |
|
3964 |
"Modified: / 2.8.1999 / 17:00:19 / stefan" |
|
3965 |
! |
|
3966 |
||
3967 |
error:aString |
|
3968 |
"{ Pragma: +optSpace }" |
|
3969 |
||
3970 |
"Raise an error with error message aString. |
|
3971 |
The error is reported by raising the Error exception, |
|
3972 |
which is non-proceedable. |
|
3973 |
If no handler has been setup, a debugger is entered." |
|
3974 |
||
11021 | 3975 |
<context: #return> |
3976 |
<resource: #skipInDebuggersWalkBack> |
|
3977 |
||
10460 | 3978 |
Error raiseWith:#error: errorString:aString |
5755 | 3979 |
|
3980 |
" |
|
3981 |
nil error:' bad bad bad' |
|
3982 |
" |
|
3983 |
||
3984 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
3985 |
! |
|
3986 |
||
3987 |
error:aString mayProceed:mayProceed |
|
3988 |
"{ Pragma: +optSpace }" |
|
3989 |
||
3990 |
"enter debugger with error-message aString. |
|
10460 | 3991 |
The error is reported by raising either the |
5755 | 3992 |
non-proceedable Error exception, |
3993 |
or the ProceedableError exception." |
|
3994 |
||
11021 | 3995 |
<resource: #skipInDebuggersWalkBack> |
3996 |
||
5755 | 3997 |
mayProceed ifTrue:[ |
17757 | 3998 |
^ ProceedableError raiseRequestWith:#error: errorString:aString |
10460 | 3999 |
]. |
4000 |
||
4001 |
Error raiseWith:#error: errorString:aString |
|
5755 | 4002 |
|
4003 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
4004 |
! |
|
4005 |
||
6900 | 4006 |
errorInvalidFormat |
4007 |
"{ Pragma: +optSpace }" |
|
4008 |
||
4009 |
"report an error that some conversion to/from string representation failed |
|
4010 |
typically when converting numbers, date, time etc." |
|
4011 |
||
11021 | 4012 |
<context: #return> |
4013 |
<resource: #skipInDebuggersWalkBack> |
|
4014 |
||
6900 | 4015 |
^ ConversionError raiseErrorString:'invalid format' |
4016 |
! |
|
4017 |
||
5755 | 4018 |
errorKeyNotFound:aKey |
4019 |
"{ Pragma: +optSpace }" |
|
4020 |
||
4021 |
"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
|
4022 |
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
|
4023 |
|
11021 | 4024 |
<resource: #skipInDebuggersWalkBack> |
4025 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
4026 |
^ 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
|
4027 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4028 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4029 |
Dictionary new at:#nonExistantElement |
5755 | 4030 |
" |
4031 |
! |
|
4032 |
||
4033 |
errorNotFound |
|
4034 |
"{ Pragma: +optSpace }" |
|
4035 |
||
4036 |
"report an error that no element was found in a collection. |
|
4037 |
The error is reported by raising the NotFoundSignal exception." |
|
4038 |
||
11021 | 4039 |
<resource: #skipInDebuggersWalkBack> |
4040 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4041 |
^ NotFoundError raiseRequestWith:nil |
5755 | 4042 |
|
4043 |
"Modified: / 8.5.1996 / 09:13:11 / cg" |
|
4044 |
"Modified: / 26.7.1999 / 10:51:50 / stefan" |
|
4045 |
! |
|
4046 |
||
6874 | 4047 |
errorNotFound:errorString |
4048 |
"{ Pragma: +optSpace }" |
|
4049 |
||
4050 |
"report an error that no element was found in a collection. |
|
4051 |
The error is reported by raising the NotFoundSignal exception." |
|
4052 |
||
11021 | 4053 |
<resource: #skipInDebuggersWalkBack> |
4054 |
||
10837
63d19c75d762
changed #errorNotFound: raise it proceedable
Stefan Vogel <sv@exept.de>
parents:
10834
diff
changeset
|
4055 |
^ NotFoundError raiseRequestErrorString:errorString |
6874 | 4056 |
! |
4057 |
||
5755 | 4058 |
errorSignal |
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4059 |
"return the signal used for error/error: handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4060 |
|
5755 | 4061 |
^ self class errorSignal |
4062 |
||
4063 |
"Created: / 19.6.1998 / 02:32:32 / cg" |
|
4064 |
! |
|
4065 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4066 |
handlerForSignal:exceptionHandler context:theContext originator:originator |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4067 |
" 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
|
4068 |
|
7566 | 4069 |
thisContext isRecursive ifTrue:[^ nil]. |
4070 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4071 |
'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
|
4072 |
' context: ' print. theContext printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4073 |
' originator: ' print. originator printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4074 |
' sender: ' print. thisContext sender printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4075 |
|
7566 | 4076 |
"/ MiniDebugger enter:thisContext withMessage:'oops' mayProceed:true. |
4077 |
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
|
4078 |
! |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4079 |
|
5755 | 4080 |
implementedBySubclass |
4081 |
"{ Pragma: +optSpace }" |
|
4082 |
||
4083 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
4084 |
||
11021 | 4085 |
<resource: #skipInDebuggersWalkBack> |
4086 |
||
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4087 |
^ SubclassResponsibilityError raiseRequestErrorString:'method must be reimplemented in ST/V subclass' |
5755 | 4088 |
! |
4089 |
||
4090 |
indexNotInteger |
|
4091 |
"{ Pragma: +optSpace }" |
|
4092 |
||
4093 |
"report an error that index is not an Integer. |
|
4094 |
(when accessing collections indexed by an integer key). |
|
4095 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4096 |
||
11021 | 4097 |
<resource: #skipInDebuggersWalkBack> |
4098 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4099 |
^ NonIntegerIndexError raiseRequestWith:nil |
5755 | 4100 |
|
4101 |
"Modified: / 8.5.1996 / 09:13:37 / cg" |
|
4102 |
"Modified: / 26.7.1999 / 10:57:43 / stefan" |
|
4103 |
! |
|
4104 |
||
4105 |
indexNotInteger:anIndex |
|
4106 |
"{ Pragma: +optSpace }" |
|
4107 |
||
4108 |
"report an error that index is not an Integer. |
|
4109 |
(when accessing collections indexed by an integer key). |
|
4110 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4111 |
||
11021 | 4112 |
<resource: #skipInDebuggersWalkBack> |
4113 |
||
10460 | 4114 |
^ NonIntegerIndexError raiseRequestWith:anIndex |
5755 | 4115 |
|
4116 |
"Created: / 16.5.1998 / 19:39:41 / cg" |
|
4117 |
! |
|
4118 |
||
7216 | 4119 |
indexNotIntegerOrOutOfBounds:index |
4120 |
"{ Pragma: +optSpace }" |
|
4121 |
||
4122 |
"report an error that index is either non-integral or out of bounds" |
|
4123 |
||
11021 | 4124 |
<resource: #skipInDebuggersWalkBack> |
4125 |
||
7216 | 4126 |
index isInteger ifFalse:[ |
17757 | 4127 |
^ self indexNotInteger:index |
7216 | 4128 |
]. |
4129 |
^ self subscriptBoundsError:index |
|
4130 |
! |
|
4131 |
||
5755 | 4132 |
integerCheckError |
4133 |
"{ Pragma: +optSpace }" |
|
4134 |
||
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4135 |
"generated when a variable declared with an integer type gets a bad value assigned" |
5755 | 4136 |
|
11021 | 4137 |
<resource: #skipInDebuggersWalkBack> |
4138 |
||
10460 | 4139 |
^ self error:'bad assign of ' , self printString , |
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4140 |
' (' , self class name , ') to integer-typed variable' |
5755 | 4141 |
! |
4142 |
||
4143 |
invalidCodeObject |
|
4144 |
"{ Pragma: +optSpace }" |
|
4145 |
||
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4146 |
"this is sent by VM if it encounters some non-method for execution" |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4147 |
|
11021 | 4148 |
<resource: #skipInDebuggersWalkBack> |
4149 |
||
5755 | 4150 |
self error:'not an executable code object' |
4151 |
||
4152 |
"Created: 1.8.1997 / 00:16:44 / cg" |
|
4153 |
! |
|
4154 |
||
10460 | 4155 |
invalidMessage |
5755 | 4156 |
"{ Pragma: +optSpace }" |
4157 |
||
4158 |
"this is sent by ST/V code - its the same as #shouldNotImplement" |
|
4159 |
||
11021 | 4160 |
<resource: #skipInDebuggersWalkBack> |
4161 |
||
5755 | 4162 |
^ self shouldNotImplement |
4163 |
! |
|
4164 |
||
4165 |
mustBeRectangle |
|
4166 |
"{ Pragma: +optSpace }" |
|
4167 |
||
4168 |
"report an argument-not-rectangle-error" |
|
4169 |
||
11021 | 4170 |
<resource: #skipInDebuggersWalkBack> |
4171 |
||
5755 | 4172 |
^ self error:'argument must be a Rectangle' |
4173 |
! |
|
4174 |
||
4175 |
mustBeString |
|
4176 |
"{ Pragma: +optSpace }" |
|
4177 |
||
4178 |
"report an argument-not-string-error" |
|
4179 |
||
11021 | 4180 |
<resource: #skipInDebuggersWalkBack> |
4181 |
||
5755 | 4182 |
^ self error:'argument must be a String' |
4183 |
! |
|
4184 |
||
4185 |
notIndexed |
|
4186 |
"{ Pragma: +optSpace }" |
|
4187 |
||
4188 |
"report an error that receiver has no indexed instance variables. |
|
4189 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4190 |
||
11021 | 4191 |
<context: #return> |
4192 |
<resource: #skipInDebuggersWalkBack> |
|
4193 |
||
10460 | 4194 |
^ SubscriptOutOfBoundsError |
17757 | 4195 |
raiseErrorString:'receiver has no indexed variables' |
5755 | 4196 |
|
4197 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
|
4198 |
! |
|
4199 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4200 |
notYetImplemented |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4201 |
"{ Pragma: +optSpace }" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4202 |
|
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4203 |
"report an error that some functionality is not yet implemented. |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4204 |
This is here only for compatibility - it has the same meaning as shouldImplement." |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4205 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4206 |
<resource: #skipInDebuggersWalkBack> |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4207 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4208 |
^ self error:'method/functionality is not yet implemented' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4209 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4210 |
|
5755 | 4211 |
openDebuggerOnException:ex |
4212 |
"{ Pragma: +optSpace }" |
|
4213 |
||
4214 |
"enter the debugger on some unhandled exception" |
|
4215 |
||
6884 | 4216 |
|msgString debugger answer| |
5755 | 4217 |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4218 |
msgString := ex descriptionForDebugger. |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
4219 |
|
5755 | 4220 |
" |
4221 |
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
|
4222 |
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
|
4223 |
ignore will raise an AbortOperationRequest. |
5755 | 4224 |
" |
4225 |
Debugger isNil ifTrue:[ |
|
11339 | 4226 |
msgString := 'Error: ' , msgString. |
4227 |
||
4228 |
thisContext isRecursive ifTrue:[ |
|
4229 |
msgString errorPrintCR. |
|
4230 |
Smalltalk fatalAbort:'recursive unhandled exception' |
|
4231 |
]. |
|
4232 |
||
4233 |
Smalltalk isStandAloneApp ifTrue:[ |
|
4234 |
(ex signal == NoHandlerError and:[HaltInterrupt handles:ex unhandledException]) ifTrue:[ |
|
4235 |
"/ 'Halt ignored' infoPrintCR. |
|
4236 |
^ self |
|
4237 |
]. |
|
4238 |
]. |
|
4239 |
||
4240 |
(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
|
4241 |
false "oldCode" ifTrue:[ |
11339 | 4242 |
AbortOperationRequest isHandled ifTrue:[ |
4243 |
answer := OptionBox |
|
4244 |
request:msgString |
|
4245 |
label:msgString |
|
4246 |
buttonLabels:#('Exit' 'Terminate Thread' 'Ignore' 'Abort' ) |
|
4247 |
values:#(exit terminate ignore abort) |
|
4248 |
default:#abort. |
|
4249 |
] ifFalse:[ |
|
4250 |
answer := OptionBox |
|
4251 |
request:msgString |
|
4252 |
label:msgString |
|
4253 |
buttonLabels:#('Exit' 'Terminate Thread' 'Ignore' ) |
|
4254 |
values:#(exit terminate ignore ) |
|
4255 |
default:#terminate. |
|
4256 |
]. |
|
4257 |
answer isNil ifTrue:[ answer := #ignore]. |
|
4258 |
||
4259 |
answer == #abort ifTrue:[ |
|
4260 |
^ AbortOperationRequest raiseRequest |
|
4261 |
]. |
|
4262 |
answer == #ignore ifTrue:[ |
|
4263 |
^ nil |
|
4264 |
]. |
|
4265 |
answer == #terminate ifTrue:[ |
|
4266 |
Processor activeProcess isSystemProcess ifTrue:[ |
|
4267 |
(Dialog confirm:'Are you sure (this might finish the application)') ifFalse:[ |
|
4268 |
^ nil |
|
4269 |
]. |
|
4270 |
]. |
|
4271 |
^ Processor activeProcess terminate. |
|
4272 |
]. |
|
4273 |
"asking second time here to prevent the user from accidently closing his app" |
|
4274 |
answer == #exit ifTrue:[ |
|
4275 |
answer := OptionBox |
|
4276 |
request:'Do you really wish to exit this application (all changes will be lost)?' |
|
4277 |
label:msgString |
|
4278 |
buttonLabels:#('Yes' 'No' ) |
|
4279 |
values:#(exit abort) |
|
4280 |
default:#abort. |
|
4281 |
]. |
|
4282 |
answer == #abort ifTrue:[ |
|
4283 |
^ AbortOperationRequest raiseRequest |
|
4284 |
]. |
|
4285 |
||
4286 |
(Dialog confirm:'Are you sure you want to finish the application ?') ifFalse:[ |
|
4287 |
^ nil |
|
4288 |
]. |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4289 |
] ifFalse:[ |
11339 | 4290 |
self |
4291 |
errorNotify:msgString |
|
4292 |
from:ex suspendedContext |
|
4293 |
allowDebug:false. |
|
4294 |
||
4295 |
"/ arrive here if proceeded... |
|
4296 |
^ nil |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4297 |
]. |
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
4298 |
|
11339 | 4299 |
]. |
4300 |
||
4301 |
"don't output the message, if the exception is a UserInterrupt (CTRL-C)" |
|
4302 |
(ex signal == NoHandlerError |
|
4303 |
and:[ex unhandledException signal == UserInterrupt]) ifTrue:[ |
|
4304 |
OperatingSystem exit:130. |
|
4305 |
]. |
|
4306 |
msgString errorPrintCR. |
|
4307 |
thisContext fullPrintAll. |
|
4308 |
OperatingSystem exit:1 |
|
5755 | 4309 |
]. |
4310 |
||
4311 |
" |
|
4312 |
find an appropriate debugger to use |
|
4313 |
" |
|
4314 |
debugger := self appropriateDebugger:(thisContext selector). |
|
4315 |
debugger isNil ifTrue:[ |
|
11339 | 4316 |
^ AbortOperationRequest raiseRequest |
10460 | 4317 |
]. |
4318 |
||
4319 |
^ debugger |
|
11339 | 4320 |
enter:ex returnableSuspendedContext |
4321 |
withMessage:ex descriptionForDebugger |
|
4322 |
mayProceed:(ex mayProceed). |
|
5755 | 4323 |
|
10234 | 4324 |
"Modified: / 06-12-2006 / 18:51:55 / cg" |
5755 | 4325 |
! |
4326 |
||
4327 |
primitiveFailed |
|
4328 |
"{ Pragma: +optSpace }" |
|
4329 |
||
4330 |
"report an error that some primitive code failed. |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4331 |
The error is reported by raising the PrimitiveFailure exception." |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4332 |
|
11021 | 4333 |
<resource: #skipInDebuggersWalkBack> |
4334 |
||
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4335 |
|sender| |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4336 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4337 |
sender := thisContext sender. |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4338 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4339 |
^ PrimitiveFailure raiseRequestWith:(Message selector:sender selector arguments:sender args) |
17757 | 4340 |
in:sender. |
5755 | 4341 |
|
6005 | 4342 |
" |
4343 |
1234 primitiveFailed |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4344 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4345 |
[ |
17757 | 4346 |
ExternalBytes new basicAt:40 |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4347 |
] on:PrimitiveFailure do:[:ex| |
17757 | 4348 |
ex inspect |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4349 |
] |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4350 |
" |
5755 | 4351 |
! |
4352 |
||
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4353 |
primitiveFailed:messageString |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4354 |
"{ Pragma: +optSpace }" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4355 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4356 |
"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
|
4357 |
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
|
4358 |
|
11021 | 4359 |
<resource: #skipInDebuggersWalkBack> |
4360 |
||
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4361 |
|sender| |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4362 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4363 |
sender := thisContext sender. |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4364 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4365 |
^ PrimitiveFailure raiseRequestWith:(Message selector:sender selector arguments:sender args) |
17757 | 4366 |
errorString:messageString |
4367 |
in:sender. |
|
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4368 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4369 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4370 |
1234 primitiveFailed:'this is a test' |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4371 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4372 |
! |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4373 |
|
6815 | 4374 |
shouldImplement |
4375 |
"{ Pragma: +optSpace }" |
|
4376 |
||
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4377 |
"report an error that this message/functionality should be implemented. |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4378 |
This is send by automatically generated method bodies or inside as-yet-uncoded |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4379 |
branches of existing methods." |
6815 | 4380 |
|
11021 | 4381 |
<resource: #skipInDebuggersWalkBack> |
4382 |
||
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4383 |
|sender| |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4384 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4385 |
sender := thisContext sender. |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4386 |
|
17757 | 4387 |
^ UnimplementedFunctionalityError |
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4388 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4389 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4390 |
" |
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4391 |
self shouldImplement |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4392 |
" |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4393 |
! |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4394 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4395 |
shouldImplement:what |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4396 |
"{ Pragma: +optSpace }" |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4397 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4398 |
"report an error that this message/functionality should be implemented. |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4399 |
This is send by automatically generated method bodies or inside as-yet-uncoded |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4400 |
branches of existing methods." |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4401 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4402 |
<resource: #skipInDebuggersWalkBack> |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4403 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4404 |
|sender| |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4405 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4406 |
sender := thisContext sender. |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4407 |
|
17757 | 4408 |
^ UnimplementedFunctionalityError |
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4409 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4410 |
errorString:what |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4411 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4412 |
" |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4413 |
self shouldImplement:'foobar' |
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4414 |
" |
6815 | 4415 |
! |
4416 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4417 |
shouldNeverBeReached |
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4418 |
"report an error that this point may never be reached." |
17757 | 4419 |
|
4420 |
^ self |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4421 |
error:'Oops, this may never reached. Something somewhere was terribly wrong.'. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4422 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4423 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4424 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4425 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4426 |
shouldNeverBeSent |
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4427 |
"report an error that this message may never be sent to the reciever" |
17757 | 4428 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4429 |
^ self error:'This message never may be sent to me!!'. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4430 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4431 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4432 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
4433 |
|
5755 | 4434 |
shouldNotImplement |
4435 |
"{ Pragma: +optSpace }" |
|
4436 |
||
17757 | 4437 |
"report an error that this message should not be implemented - |
17754 | 4438 |
i.e. that a method is invoked which is not appropriate for the receiver." |
5755 | 4439 |
|
11021 | 4440 |
<resource: #skipInDebuggersWalkBack> |
4441 |
||
8729 | 4442 |
^ self error:'method/functionality not appropriate for this class' |
5755 | 4443 |
|
4444 |
"Modified: 8.5.1996 / 09:09:44 / cg" |
|
4445 |
! |
|
4446 |
||
4447 |
subclassResponsibility |
|
4448 |
"{ Pragma: +optSpace }" |
|
4449 |
||
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
4450 |
"report an error that this message should have been reimplemented in a subclass" |
5755 | 4451 |
|
11021 | 4452 |
<resource: #skipInDebuggersWalkBack> |
4453 |
||
10877
0666d48f91d1
show the affected method-selector in the subclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
10856
diff
changeset
|
4454 |
^ SubclassResponsibilityError raiseRequestWith:thisContext sender selector |
5755 | 4455 |
! |
4456 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4457 |
subclassResponsibility:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4458 |
"{ Pragma: +optSpace }" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4459 |
|
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4460 |
"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
|
4461 |
|
11021 | 4462 |
<resource: #skipInDebuggersWalkBack> |
4463 |
||
7334 | 4464 |
^ SubclassResponsibilityError raiseRequestErrorString:msg |
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4465 |
! |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4466 |
|
5755 | 4467 |
subscriptBoundsError |
4468 |
"{ Pragma: +optSpace }" |
|
4469 |
||
4470 |
"report an error that some index is out of bounds. |
|
4471 |
(when accessing indexable collections). |
|
4472 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4473 |
||
11021 | 4474 |
<resource: #skipInDebuggersWalkBack> |
4475 |
||
5755 | 4476 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:nil |
4477 |
||
4478 |
"Modified: / 26.7.1996 / 16:45:42 / cg" |
|
4479 |
"Modified: / 26.7.1999 / 10:58:27 / stefan" |
|
4480 |
! |
|
4481 |
||
4482 |
subscriptBoundsError:anIndex |
|
4483 |
"{ Pragma: +optSpace }" |
|
4484 |
||
4485 |
"report an error that anIndex is out of bounds. |
|
4486 |
(when accessing indexable collections). |
|
4487 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4488 |
||
11021 | 4489 |
<resource: #skipInDebuggersWalkBack> |
4490 |
||
10460 | 4491 |
^ SubscriptOutOfBoundsError |
17757 | 4492 |
raiseRequestWith:anIndex |
4493 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
5755 | 4494 |
|
6221 | 4495 |
"Modified: / 17.11.2001 / 22:49:56 / cg" |
5755 | 4496 |
! |
4497 |
||
4498 |
typeCheckError |
|
4499 |
"{ Pragma: +optSpace }" |
|
4500 |
||
4501 |
"generated when a variable declared with a type hint gets a bad |
|
4502 |
value assigned" |
|
4503 |
||
11021 | 4504 |
<resource: #skipInDebuggersWalkBack> |
4505 |
||
5755 | 4506 |
^ self error:'bad assign of ' , self printString , |
17757 | 4507 |
' (' , self class name , ') to typed variable' |
5755 | 4508 |
! ! |
4509 |
||
4510 |
!Object methodsFor:'evaluation'! |
|
4511 |
||
8690
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4512 |
argumentCount |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4513 |
"compatibility with Blocks and Messages. |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4514 |
Answer 0, since we only understand #value. |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4515 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4516 |
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
|
4517 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4518 |
^ 0 |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4519 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4520 |
" |
17757 | 4521 |
[1 // 0] on:ArithmeticError do:9999 |
8690
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4522 |
" |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4523 |
! |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4524 |
|
5755 | 4525 |
value |
4526 |
"return the receiver itself. |
|
4527 |
This allows every object to be used where blocks or valueHolders |
|
4528 |
are typically used, and allows for valueHolders and blocks to be |
|
4529 |
used interchangably in some situations. |
|
4530 |
||
4531 |
Time will show, if this is a good idea or leads to sloppy programming |
|
4532 |
style ... (the idea was borrowed from the Self language). |
|
4533 |
||
10460 | 4534 |
WARNING: dont 'optimize' away ifXXX: blocks |
17757 | 4535 |
(i.e. do NOT replace |
4536 |
foo ifTrue:[var1] ifFalse:[var2] |
|
4537 |
by: |
|
4538 |
foo ifTrue:var1 ifFalse:var2 |
|
4539 |
) |
|
4540 |
- the compilers will only generate inline code for the if, |
|
4541 |
iff the argument(s) are blocks - otherwise, a true send is |
|
4542 |
generated. |
|
4543 |
This 'oprimization' will work semantically correct, |
|
4544 |
but execute SLOWER instead." |
|
5755 | 4545 |
|
4546 |
^ self |
|
4547 |
||
4548 |
" |
|
10460 | 4549 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
4550 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
4551 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
4552 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
5755 | 4553 |
" |
4554 |
||
4555 |
"DO NOT DO THIS (its slower) |
|
7458 | 4556 |
(1 > 4) ifTrue:a ifFalse:b |
5755 | 4557 |
|
4558 |
USE (the compiler optimizes blocks in if/while): |
|
7458 | 4559 |
(1 > 4) ifTrue:[a] ifFalse:[b] |
5755 | 4560 |
" |
4561 |
||
4562 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
4563 |
! ! |
|
4564 |
||
4565 |
!Object methodsFor:'finalization'! |
|
4566 |
||
4567 |
disposed |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4568 |
"OBSOLETE INTERFACE: use #finalize |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4569 |
this is invoked for objects which have been registered |
5755 | 4570 |
in a Registry, when the original object dies. |
4571 |
Subclasses may redefine this method" |
|
4572 |
||
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4573 |
<resource: #obsolete> |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4574 |
|
5755 | 4575 |
^ self |
4576 |
! |
|
4577 |
||
4578 |
executor |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4579 |
"Return the object which does the finalization for me. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4580 |
This interface is also VW & Sqeak compatible," |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4581 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4582 |
"for now, send #shallowCopyForFinalization, to be compatible with |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4583 |
classes designed for old ST/X versions" |
5755 | 4584 |
|
4585 |
^ self shallowCopyForFinalization |
|
4586 |
! |
|
4587 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4588 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4589 |
"answer a Registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4590 |
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
|
4591 |
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
|
4592 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4593 |
^ FinalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4594 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4595 |
|
5755 | 4596 |
finalize |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4597 |
"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
|
4598 |
in a Registry, when the original object dies. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4599 |
Subclasses may redefine this method |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4600 |
This interface is also VW-compatible" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4601 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4602 |
"send #disposed for compatibility with existing classes that still |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4603 |
implement the obsolete #disposed message" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4604 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4605 |
^ self disposed |
5755 | 4606 |
! |
4607 |
||
4608 |
reRegisterForFinalization |
|
4609 |
"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
|
4610 |
This will create a new executor, which will receive a #finalize message when |
5755 | 4611 |
the receiver is garbage collected." |
4612 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4613 |
self finalizationLobby registerChange:self |
5755 | 4614 |
! |
4615 |
||
4616 |
registerForFinalization |
|
4617 |
"register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4618 |
Once registered, the executor of the receiver will receive a #finalize message when |
5755 | 4619 |
the receiver is garbage collected." |
4620 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4621 |
self finalizationLobby register:self |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4622 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4623 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4624 |
shallowCopyForFinalization |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4625 |
"OBSOLETE INTERFACE: use #executor. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4626 |
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
|
4627 |
(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
|
4628 |
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
|
4629 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4630 |
<resource: #obsolete> |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4631 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4632 |
^ self shallowCopy |
5755 | 4633 |
! |
4634 |
||
4635 |
unregisterForFinalization |
|
4636 |
"unregister mySelf from later finalization" |
|
4637 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
4638 |
self finalizationLobby unregister:self |
5755 | 4639 |
! ! |
4640 |
||
4641 |
!Object methodsFor:'initialization'! |
|
4642 |
||
4643 |
initialize |
|
4644 |
"just to ignore initialize to objects which do not need it" |
|
4645 |
||
4646 |
^ self |
|
4647 |
! ! |
|
4648 |
||
4649 |
!Object methodsFor:'interrupt handling'! |
|
4650 |
||
4651 |
childSignalInterrupt |
|
4652 |
"death of a child process (unix process) - do nothing" |
|
4653 |
||
4654 |
^ self |
|
4655 |
! |
|
4656 |
||
4657 |
customInterrupt |
|
4658 |
"{ Pragma: +optSpace }" |
|
4659 |
||
4660 |
"a custom interrupt - but no handler has defined" |
|
4661 |
||
4662 |
self error:'custom interrupt' mayProceed:true |
|
4663 |
! |
|
4664 |
||
4665 |
errorInterrupt:errorID with:aParameter |
|
4666 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
10460 | 4667 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
5755 | 4668 |
which can be called from C subsystems to raise an (asynchronous) |
4669 |
error exception. |
|
4670 |
||
4671 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
4672 |
used from other C subsystems too, to upcast errors. |
|
4673 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
4674 |
IDs (currently) used: |
|
17757 | 4675 |
#DisplayError ..... x-error interrupt |
4676 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
5755 | 4677 |
" |
4678 |
||
6263
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4679 |
|handlers handler| |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4680 |
|
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4681 |
handlers := ObjectMemory registeredErrorInterruptHandlers. |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
4682 |
handlers notNil ifTrue:[ |
17757 | 4683 |
handler := handlers at:errorID ifAbsent:nil. |
4684 |
handler notNil ifTrue:[ |
|
4685 |
"/ |
|
4686 |
"/ handler found; let it do whatever it wants ... |
|
4687 |
"/ |
|
4688 |
handler errorInterrupt:errorID with:aParameter. |
|
4689 |
^ self |
|
4690 |
]. |
|
5755 | 4691 |
]. |
4692 |
||
4693 |
"/ |
|
4694 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
4695 |
"/ |
|
10460 | 4696 |
^ Error |
17757 | 4697 |
raiseRequestWith:errorID |
4698 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
5755 | 4699 |
! |
4700 |
||
4701 |
exceptionInterrupt |
|
4702 |
"{ Pragma: +optSpace }" |
|
4703 |
||
4704 |
"exception interrupt - enter debugger" |
|
4705 |
||
4706 |
self error:'exception Interrupt' mayProceed:true |
|
4707 |
! |
|
4708 |
||
4709 |
fpExceptionInterrupt |
|
4710 |
"{ Pragma: +optSpace }" |
|
4711 |
||
4712 |
"a floating point exception occured - this one |
|
4713 |
has to be handled differently since it comes asynchronous |
|
4714 |
on some machines (for example, on machines with a separate FPU |
|
4715 |
or superscalar architectures. Also, errors from within primitive code |
|
4716 |
(or library functions such as GL) are sent via the Unix-signal |
|
4717 |
mechanism this way." |
|
4718 |
||
4719 |
|where rec| |
|
4720 |
||
4721 |
where := thisContext sender. |
|
4722 |
rec := where receiver. |
|
4723 |
rec isNumber ifTrue:[ |
|
17757 | 4724 |
^ rec class |
4725 |
raise:#domainErrorSignal |
|
4726 |
receiver:rec |
|
4727 |
selector:where selector |
|
4728 |
arguments:(where args asArray) |
|
4729 |
errorString:'floating point exception' |
|
5755 | 4730 |
]. |
4731 |
||
4732 |
"/ could be in some C-library ... |
|
7402 | 4733 |
^ DomainError raise |
5755 | 4734 |
! |
4735 |
||
4736 |
internalError:msg |
|
4737 |
"{ Pragma: +optSpace }" |
|
4738 |
||
4739 |
"this is triggered, when VM hits some bad error, |
|
4740 |
such as corrupted class, corrupted method/selector array |
|
4741 |
etc. The argument string gives some more information on what happened. |
|
4742 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
|
4743 |
Its not guaranteed, that the system is in a working condition once |
|
4744 |
this error occurred ...." |
|
4745 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4746 |
VMInternalError raiseWith:self errorString:msg |
5755 | 4747 |
! |
4748 |
||
4749 |
ioInterrupt |
|
4750 |
"{ Pragma: +optSpace }" |
|
4751 |
||
4752 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
|
4753 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
4754 |
or it does not understand the ioInterrupt message. |
|
4755 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
4756 |
||
4757 |
self error:'I/O Interrupt - but no handler' mayProceed:true |
|
4758 |
! |
|
4759 |
||
4760 |
memoryInterrupt |
|
4761 |
"{ Pragma: +optSpace }" |
|
4762 |
||
4763 |
"out-of-memory interrupt and no handler - enter debugger" |
|
4764 |
||
4765 |
self error:'almost out of memory' mayProceed:true |
|
4766 |
! |
|
4767 |
||
4768 |
recursionInterrupt |
|
4769 |
"{ Pragma: +optSpace }" |
|
4770 |
||
4771 |
"recursion limit (actually: stack overflow) interrupt. |
|
4772 |
This interrupt is triggered, when a process stack grows above |
|
4773 |
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
|
4774 |
could be caught. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4775 |
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
|
4776 |
and the exception can be resumed. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4777 |
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
|
4778 |
is not proceedable. |
10460 | 4779 |
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
|
4780 |
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
|
4781 |
or debug for a while. |
5755 | 4782 |
If the signal is ignored, and the stack continues to grow, there |
4783 |
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
|
4784 |
terminates the process." |
5755 | 4785 |
|
7838
4cf3d0dad430
skip recursive contexts when shwing backtrace of recursionInterrupt
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
4786 |
|con remaining sender nSkipped| |
5755 | 4787 |
|
4788 |
(con := thisContext) isRecursive ifFalse:[ |
|
4789 |
"/ Processor activeProcess usedStackSize < Processor activeProcess maximumStackSize ifTrue:[ |
|
4790 |
"/ "/ mhmh - it hit me, but I am not responsible ... |
|
4791 |
"/ 'Stray recursionInterrupt ...' infoPrintCR. |
|
4792 |
"/ ^ self |
|
4793 |
"/ ]. |
|
17757 | 4794 |
ObjectMemory infoPrinting ifTrue:[ |
4795 |
'Object [info]: recursionInterrupt from:' printCR. |
|
4796 |
con := con sender. |
|
4797 |
remaining := 50. |
|
4798 |
[con notNil and:[remaining > 0]] whileTrue:[ |
|
4799 |
sender := con sender. |
|
4800 |
'| ' print. con fullPrint. |
|
4801 |
||
4802 |
nSkipped := 0. |
|
4803 |
[sender notNil and:[sender sender notNil |
|
4804 |
and:[sender selector == con selector |
|
4805 |
and:[sender sender selector == con selector |
|
4806 |
and:[sender method == con method]]]]] whileTrue:[ |
|
4807 |
nSkipped := nSkipped + 1. |
|
4808 |
con := sender. |
|
4809 |
sender := con sender. |
|
4810 |
]. |
|
4811 |
nSkipped > 0 ifTrue:[ |
|
4812 |
'| ... ***** ' print. nSkipped print. ' recursive contexts skipped *****' printCR. |
|
4813 |
]. |
|
4814 |
con := sender. |
|
4815 |
remaining := remaining - 1 |
|
4816 |
]. |
|
4817 |
]. |
|
4818 |
^ RecursionInterruptSignal raiseSignal |
|
5755 | 4819 |
] |
4820 |
||
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
4821 |
"Modified: / 10.11.2001 / 15:15:56 / cg" |
5755 | 4822 |
! |
4823 |
||
4824 |
schedulerInterrupt |
|
4825 |
"{ Pragma: +optSpace }" |
|
4826 |
||
4827 |
"scheduler interrupt (supposed to be sent to Processor). |
|
4828 |
If we arrive here, either the Processor does not understand it, |
|
4829 |
or it has been set to nil. In any case, this is a sign of some |
|
4830 |
big trouble. Enter debugger." |
|
4831 |
||
4832 |
self error:'schedulerInterrupt - but no Processor' mayProceed:true |
|
4833 |
! |
|
4834 |
||
4835 |
signalInterrupt:signalNumber |
|
4836 |
"{ Pragma: +optSpace }" |
|
4837 |
||
10460 | 4838 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
10016 | 4839 |
(SIGPIPE), others (SIGBUS) are rather fatal... |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
4840 |
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
|
4841 |
Otherwise, a dialog is shown, asking the user on how to handle the signal. |
5755 | 4842 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
4843 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
4844 |
Currently (temporary kludge), these are passed as global variables." |
|
4845 |
||
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
4846 |
|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
|
4847 |
action title screen| |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4848 |
|
5755 | 4849 |
"if there has been an ST-signal installed, use it ..." |
4850 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
4851 |
sig notNil ifTrue:[ |
|
17757 | 4852 |
sig raiseSignalWith:signalNumber. |
4853 |
^ self. |
|
5755 | 4854 |
]. |
4855 |
||
4856 |
"/ if handled, raise OSSignalInterruptSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4857 |
OSSignalInterrupt isHandled ifTrue:[ |
17757 | 4858 |
OSSignalInterrupt raiseRequestWith:signalNumber. |
4859 |
^ self. |
|
10460 | 4860 |
]. |
4861 |
||
4862 |
" |
|
4863 |
special cases |
|
17757 | 4864 |
- SIGPWR: power failure - write a crash image and continue |
4865 |
- SIGHUP: hang up - write a crash image and exit |
|
10922 | 4866 |
" |
4867 |
(signalNumber == OperatingSystem sigPWR) ifTrue:[ |
|
17757 | 4868 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
4869 |
^ self. |
|
10922 | 4870 |
]. |
4871 |
(signalNumber == OperatingSystem sigHUP) ifTrue:[ |
|
17757 | 4872 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
4873 |
'Object [info]: exit due to hangup signal.' errorPrintCR. |
|
4874 |
Smalltalk exit:1. |
|
7031 | 4875 |
]. |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4876 |
|
5755 | 4877 |
name := OperatingSystem nameForSignal:signalNumber. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4878 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4879 |
"if there is no screen at all, bring up a mini debugger" |
10460 | 4880 |
(Screen isNil |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4881 |
or:[(screen := Screen current) isNil |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
4882 |
or:[(screen := Screen default) isNil |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
4883 |
or:[screen isOpen not]]]) ifTrue:[ |
17757 | 4884 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4885 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4886 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4887 |
"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
|
4888 |
otherwise display stays locked" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4889 |
screen ungrabPointer; ungrabKeyboard. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4890 |
|
7031 | 4891 |
here := thisContext. |
4892 |
badContext := here sender. "the context, in which the signal occurred" |
|
4893 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4894 |
"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
|
4895 |
Screen currentScreenQuerySignal answer:screen do:[ |
17757 | 4896 |
" |
4897 |
SIGBUS, SIGSEGV and SIGILL do not make sense to ignore (i.e. continue) |
|
4898 |
since the system will retry the faulty instruction, which leads to |
|
4899 |
another signal - to avoid frustration, better not offer this option. |
|
4900 |
" |
|
4901 |
fatal := OperatingSystem isFatalSignal:signalNumber. |
|
4902 |
fatal ifTrue:[ |
|
4903 |
(Debugger isNil or:[here isRecursive]) ifTrue:[ |
|
4904 |
'Object [hard error]: signal ' errorPrint. signalNumber errorPrintCR. |
|
4905 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
4906 |
]. |
|
4907 |
" |
|
4908 |
a hard signal - go into debugger immediately |
|
4909 |
" |
|
4910 |
msg := 'OS-signal: ', name. |
|
4911 |
||
4912 |
"/ the IRQ-PC is passed as low-hi, to avoid the need |
|
4913 |
"/ to allocate a LargeInteger in the VM during signal |
|
4914 |
"/ time. I know, this is ugly. |
|
4915 |
||
4916 |
InterruptPcLow notNil ifTrue:[ |
|
4917 |
pc := InterruptPcLow + (InterruptPcHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
4918 |
pc ~~ 0 ifTrue:[ |
|
4919 |
msg := msg , ' PC=' , (pc printStringRadix:16) |
|
4920 |
]. |
|
4921 |
]. |
|
4922 |
InterruptAddrLow notNil ifTrue:[ |
|
4923 |
addr := InterruptAddrLow + (InterruptAddrHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
4924 |
addr ~~ 0 ifTrue:[ |
|
4925 |
msg := msg , ' ADDR=' , (addr printStringRadix:16) |
|
4926 |
]. |
|
4927 |
]. |
|
4928 |
Debugger enter:here withMessage:msg mayProceed:false. |
|
4929 |
"unreachable" |
|
4930 |
^ nil. |
|
4931 |
]. |
|
4932 |
||
4933 |
"if possible, open an option box asking the user what do. |
|
4934 |
Otherwise, start a debugger" |
|
4935 |
Dialog notNil ifTrue:[ |
|
4936 |
titles := #('save crash image' 'dump core' 'exit ST/X' 'debug'). |
|
4937 |
actions := #(save core exit debug). |
|
4938 |
||
4939 |
action := nil. |
|
4940 |
title := 'OS Signal caught (' , name, ')'. |
|
4941 |
title := (title , '\[in ST-process: ' , Processor activeProcess nameOrId ,']') withCRs. |
|
4942 |
||
4943 |
"/ if cought while in the scheduler or event dispatcher, |
|
4944 |
"/ a modal dialog is not possible ... |
|
4945 |
"/ (therefore, abort & return does not makes sense) |
|
4946 |
||
4947 |
Processor activeProcess isSystemProcess ifFalse:[ |
|
4948 |
titles := #('abort') , titles. |
|
4949 |
actions := #(abort), actions. |
|
4950 |
||
4951 |
badContext canReturn ifTrue:[ |
|
4952 |
titles := #('return') , titles. |
|
4953 |
actions := #(return), actions. |
|
4954 |
]. |
|
4955 |
]. |
|
4956 |
||
4957 |
fatal ifFalse:[ |
|
4958 |
titles := titles, #('ignore'). |
|
4959 |
actions := actions , #(ignore). |
|
4960 |
]. |
|
4961 |
action := Dialog choose:title |
|
4962 |
labels:titles |
|
4963 |
values:actions |
|
4964 |
default:(fatal ifTrue:[nil] ifFalse:[#ignore]). |
|
4965 |
||
4966 |
"Dialog may fail (if system process), default action is debug" |
|
4967 |
action isEmptyOrNil ifTrue:[action := #debug]. |
|
4968 |
] ifFalse:[ |
|
4969 |
action := #debug. |
|
4970 |
]. |
|
4971 |
||
4972 |
action == #save ifTrue:[ |
|
4973 |
ObjectMemory writeCrashImage |
|
4974 |
]. |
|
4975 |
action == #core ifTrue:[ |
|
4976 |
Smalltalk fatalAbort |
|
4977 |
]. |
|
4978 |
action == #exit ifTrue:[ |
|
4979 |
Smalltalk exit |
|
4980 |
]. |
|
4981 |
action == #return ifTrue:[ |
|
4982 |
badContext return |
|
4983 |
]. |
|
4984 |
action == #abort ifTrue:[ |
|
4985 |
AbortOperationRequest raise. |
|
4986 |
]. |
|
4987 |
||
4988 |
action == #debug ifTrue:[ |
|
4989 |
Debugger isNil ifTrue:[ |
|
4990 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
4991 |
]. |
|
4992 |
Debugger enter:here withMessage:('OS-Signal ', name) mayProceed:true. |
|
4993 |
]. |
|
4994 |
"action == #ignore" |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
4995 |
]. |
10016 | 4996 |
|
4997 |
"Modified: / 29-09-2006 / 12:27:20 / cg" |
|
5755 | 4998 |
! |
4999 |
||
5000 |
spyInterrupt |
|
5001 |
"{ Pragma: +optSpace }" |
|
5002 |
||
5003 |
"spy interrupt and no handler - enter debugger" |
|
5004 |
||
5005 |
self error:'spy Interrupt - but no handler' mayProceed:true |
|
5006 |
! |
|
5007 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5008 |
startMiniDebuggerOrExit:text |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5009 |
"some critical condition happened. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5010 |
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
|
5011 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5012 |
MiniDebugger isNil ifTrue:[ |
17757 | 5013 |
"a system without debugging facilities (i.e. a standalone system) |
5014 |
output a message and exit." |
|
5015 |
('Object [error]: exit due to ', text, ' - and no debugger.') errorPrintCR. |
|
5016 |
OperatingSystem exit:99. |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5017 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5018 |
MiniDebugger enterWithMessage:text mayProceed:true. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5019 |
! |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5020 |
|
5755 | 5021 |
timerInterrupt |
5022 |
"{ Pragma: +optSpace }" |
|
5023 |
||
5024 |
"timer interrupt and no handler - enter debugger" |
|
5025 |
||
5026 |
self error:'timer Interrupt - but no handler' mayProceed:true |
|
5027 |
! |
|
5028 |
||
5029 |
userInterrupt |
|
5030 |
"{ Pragma: +optSpace }" |
|
5031 |
||
5032 |
"user (^c) interrupt. |
|
5033 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
5034 |
controlling tty (i.e. in the xterm)." |
|
5035 |
||
6466 | 5036 |
UserInterruptSignal raiseRequest |
5755 | 5037 |
! |
5038 |
||
5039 |
userInterruptIn:aContext |
|
5040 |
"{ Pragma: +optSpace }" |
|
5041 |
||
5042 |
"user (^c) interrupt - enter debugger, but show aContext |
|
10460 | 5043 |
as top-context. |
5044 |
This is used to hide any intermediate scheduler contexts, |
|
5755 | 5045 |
in case of an interrupted process. Typically, this is sent by |
5046 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
5047 |
processed." |
|
5048 |
||
5049 |
<context: #return> |
|
5050 |
||
5051 |
UserInterruptSignal raiseRequestWith:nil errorString:nil in:aContext |
|
5052 |
||
5053 |
"Created: / 18.10.1996 / 20:46:04 / cg" |
|
5054 |
"Modified: / 20.10.1996 / 13:06:38 / cg" |
|
5055 |
"Modified: / 26.7.1999 / 10:58:49 / stefan" |
|
5056 |
! ! |
|
5057 |
||
5058 |
!Object methodsFor:'message sending'! |
|
5059 |
||
5060 |
perform:aSelector |
|
5061 |
"send the message aSelector to the receiver" |
|
5062 |
||
11335 | 5063 |
<resource: #skipInDebuggersWalkBack> |
5064 |
||
5755 | 5065 |
%{ |
5066 |
REGISTER OBJ sel = aSelector; |
|
5067 |
||
5068 |
if (InterruptPending == nil) { |
|
17757 | 5069 |
struct inlineCache *pIlc; |
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5070 |
/* JV @ 2010-22-07: To improve performance I use 256 ILCs instead |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5071 |
of default 4. This significantly reduces ILC misses. The code |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5072 |
should be further optimized by remembering last selector index and |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5073 |
try a first shot on that index. Another option is to use kind of |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5074 |
hashing on lower bits of sel variable. However, a more detailed |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5075 |
statistical data should be gathered before doing further optimizations. |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5076 |
*/ |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5077 |
|
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5078 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF0(l) } |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5079 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5080 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5081 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5082 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5083 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5084 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5085 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5086 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5087 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5088 |
#define nilcs 256 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5089 |
|
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5090 |
static struct { OBJ sel; struct inlineCache ilc; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5091 |
|
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5092 |
#undef SEL_AND_ILC_INIT_1 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5093 |
#undef SEL_AND_ILC_INIT_2 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5094 |
#undef SEL_AND_ILC_INIT_4 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5095 |
#undef SEL_AND_ILC_INIT_8 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5096 |
#undef SEL_AND_ILC_INIT_16 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5097 |
#undef SEL_AND_ILC_INIT_32 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5098 |
#undef SEL_AND_ILC_INIT_64 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5099 |
#undef SEL_AND_ILC_INIT_128 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5100 |
#undef SEL_AND_ILC_INIT_256 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5101 |
|
17757 | 5102 |
static flip = 0; |
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5103 |
int i; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5104 |
for (i = 0; i < nilcs; i++) { |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5105 |
if (sel == sel_and_ilc[i].sel) { |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5106 |
pIlc = &sel_and_ilc[i].ilc; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5107 |
goto perform0_send_and_return; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5108 |
} |
17757 | 5109 |
} |
17789
338675f49dd6
Removed debug prints from perform: methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17788
diff
changeset
|
5110 |
/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/ |
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5111 |
pIlc = &sel_and_ilc[flip].ilc; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5112 |
sel_and_ilc[flip].sel = sel; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5113 |
flip = (flip + 1) % nilcs; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5114 |
pIlc->ilc_func = __SEND0ADDR__; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5115 |
if (pIlc->ilc_poly) { |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5116 |
__flushPolyCache(pIlc->ilc_poly); |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5117 |
pIlc->ilc_poly = 0; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5118 |
} |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5119 |
perform0_send_and_return: |
17757 | 5120 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
5755 | 5121 |
} else { |
17757 | 5122 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
5123 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5755 | 5124 |
} |
5125 |
%}. |
|
5126 |
^ self perform:aSelector withArguments:#() |
|
5127 |
! |
|
5128 |
||
5129 |
perform:aSelector inClass:aClass withArguments:argArray |
|
10460 | 5130 |
"send the message aSelector with all args taken from argArray |
5755 | 5131 |
to the receiver as a super-send message. |
5132 |
This is actually more flexible than the normal super-send, since it allows |
|
5133 |
to execute a method in ANY superclass of the receiver (not just the |
|
5134 |
immediate superclass). |
|
10460 | 5135 |
Thus, it is (theoretically) possible to do |
17757 | 5136 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
5755 | 5137 |
and evaluate Magnitudes compare method even if there was one in Number. |
5138 |
This method is used by the interpreter to evaluate super sends |
|
5139 |
and could be used for very special behavior (language extension ?). |
|
5140 |
||
5141 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
5142 |
||
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5143 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 myClass| |
5755 | 5144 |
|
5145 |
" |
|
5146 |
check, if aClass is really a superclass of the receiver |
|
5147 |
" |
|
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5148 |
myClass := self class. |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5149 |
(myClass == aClass or:[myClass isSubclassOf:aClass]) ifFalse:[ |
17757 | 5150 |
self error:'lookup-class argument is not a superclass of the receiver'. |
5151 |
^ nil |
|
5755 | 5152 |
]. |
5153 |
%{ |
|
5154 |
REGISTER OBJ *argP; |
|
5155 |
int nargs, i; |
|
5156 |
||
8934 | 5157 |
if (__isArrayLike(argArray)) { |
17757 | 5158 |
nargs = __arraySize(argArray); |
5159 |
argP = __arrayVal(argArray); |
|
5755 | 5160 |
} else { |
17757 | 5161 |
if (__isNonNilObject(argArray)) { |
5162 |
static struct inlineCache ilcSize = __ILC0(@line+1); |
|
5163 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5164 |
if (!__isSmallInteger(numberOfArgs)) |
|
5165 |
goto bad; |
|
5166 |
nargs = __intVal(numberOfArgs); |
|
5167 |
argP = (OBJ *)(&a1); |
|
5168 |
for (i=1; i <= nargs; i++) { |
|
5169 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
5170 |
} |
|
5171 |
argP = (OBJ *)(&a1); |
|
5172 |
} else { |
|
5173 |
nargs = 0; |
|
5174 |
} |
|
5755 | 5175 |
} |
5176 |
switch (nargs) { |
|
17757 | 5177 |
case 0: |
5178 |
{ |
|
5179 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5180 |
RETURN ( _SEND0(self, aSelector, aClass, &ilc0)); |
|
5181 |
} |
|
5182 |
||
5183 |
case 1: |
|
5184 |
{ |
|
5185 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5186 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, argP[0])); |
|
5187 |
} |
|
5188 |
||
5189 |
case 2: |
|
5190 |
{ |
|
5191 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5192 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, argP[0], argP[1])); |
|
5193 |
} |
|
5194 |
||
5195 |
case 3: |
|
5196 |
{ |
|
5197 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5198 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, |
|
5199 |
argP[0], argP[1], argP[2])); |
|
5200 |
} |
|
5201 |
||
5202 |
case 4: |
|
5203 |
{ |
|
5204 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
5205 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, |
|
5206 |
argP[0], argP[1], argP[2], argP[3])); |
|
5207 |
} |
|
5208 |
||
5209 |
case 5: |
|
5210 |
{ |
|
5211 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
5212 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
5213 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5214 |
} |
|
5215 |
||
5216 |
case 6: |
|
5217 |
{ |
|
5218 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
5219 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
5220 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5])); |
|
5221 |
} |
|
5222 |
||
5223 |
case 7: |
|
5224 |
{ |
|
5225 |
static struct inlineCache ilc7 = __DUMMYILCSELF7(@line+1); |
|
5226 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
5227 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5228 |
argP[6])); |
|
5229 |
} |
|
5230 |
||
5231 |
case 8: |
|
5232 |
{ |
|
5233 |
static struct inlineCache ilc8 = __DUMMYILCSELF8(@line+1); |
|
5234 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
5235 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5236 |
argP[6], argP[7])); |
|
5237 |
} |
|
5238 |
||
5239 |
case 9: |
|
5240 |
{ |
|
5241 |
static struct inlineCache ilc9 = __DUMMYILCSELF9(@line+1); |
|
5242 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
5243 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5244 |
argP[6], argP[7], argP[8])); |
|
5245 |
} |
|
5246 |
||
5247 |
case 10: |
|
5248 |
{ |
|
5249 |
static struct inlineCache ilc10 = __DUMMYILCSELF10(@line+1); |
|
5250 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
5251 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5252 |
argP[6], argP[7], argP[8], argP[9])); |
|
5253 |
} |
|
5254 |
||
5255 |
case 11: |
|
5256 |
{ |
|
5257 |
static struct inlineCache ilc11 = __DUMMYILCSELF11(@line+1); |
|
5258 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
5259 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5260 |
argP[6], argP[7], argP[8], argP[9], argP[10])); |
|
5261 |
} |
|
5262 |
||
5263 |
case 12: |
|
5264 |
{ |
|
5265 |
static struct inlineCache ilc12 = __DUMMYILCSELF12(@line+1); |
|
5266 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
5267 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5268 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5269 |
argP[11])); |
|
5270 |
} |
|
5271 |
||
5272 |
case 13: |
|
5273 |
{ |
|
5274 |
static struct inlineCache ilc13 = __DUMMYILCSELF13(@line+1); |
|
5275 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
5276 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5277 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5278 |
argP[11], argP[12])); |
|
5279 |
} |
|
5280 |
||
5281 |
case 14: |
|
5282 |
{ |
|
5283 |
static struct inlineCache ilc14 = __DUMMYILCSELF14(@line+1); |
|
5284 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
5285 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5286 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5287 |
argP[11], argP[12], argP[13])); |
|
5288 |
} |
|
5289 |
||
5290 |
case 15: |
|
5291 |
{ |
|
5292 |
static struct inlineCache ilc15 = __DUMMYILCSELF15(@line+1); |
|
5293 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
5294 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5295 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5296 |
argP[11], argP[12], argP[13], argP[14])); |
|
5297 |
} |
|
5755 | 5298 |
|
5299 |
#ifdef _SEND16 |
|
17757 | 5300 |
case 16: |
5301 |
{ |
|
5302 |
static struct inlineCache ilc16 = __DUMMYILCSELF16(@line+1); |
|
5303 |
RETURN ( _SEND16(self, aSelector, aClass, &ilc15, |
|
5304 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5305 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5306 |
argP[11], argP[12], argP[13], argP[14], argP[15])); |
|
5307 |
} |
|
5755 | 5308 |
#endif |
5309 |
#ifdef _SEND17 |
|
17757 | 5310 |
case 17: |
5311 |
{ |
|
5312 |
static struct inlineCache ilc17 = __DUMMYILCSELF17(@line+1); |
|
5313 |
RETURN ( _SEND17(self, aSelector, aClass, &ilc15, |
|
5314 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5315 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5316 |
argP[11], argP[12], argP[13], argP[14], argP[15], argP[16])); |
|
5317 |
} |
|
5755 | 5318 |
#endif |
5319 |
||
5320 |
||
5321 |
} |
|
5322 |
bad:; |
|
5323 |
%}. |
|
5324 |
"/ arrive here, if bad number of arguments (too many) |
|
5325 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5326 |
||
5327 |
^ self primitiveFailed |
|
5328 |
! |
|
5329 |
||
5330 |
perform:aSelector with:arg |
|
5331 |
"send the one-arg-message aSelector to the receiver" |
|
5332 |
||
5333 |
%{ |
|
5334 |
REGISTER OBJ sel = aSelector; |
|
5335 |
||
5336 |
if (InterruptPending == nil) { |
|
17757 | 5337 |
struct inlineCache *pIlc; |
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5338 |
/* JV @ 2010-22-07: To improve performance I use 256 ILCs instead |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5339 |
of default 4. For details, see comment in perform: */ |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5340 |
|
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5341 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF1(l) } |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5342 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5343 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5344 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5345 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5346 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5347 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5348 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5349 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5350 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5351 |
#define nilcs 256 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5352 |
|
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5353 |
static struct { OBJ sel; struct inlineCache ilc; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5354 |
|
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5355 |
#undef SEL_AND_ILC_INIT_1 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5356 |
#undef SEL_AND_ILC_INIT_2 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5357 |
#undef SEL_AND_ILC_INIT_4 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5358 |
#undef SEL_AND_ILC_INIT_8 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5359 |
#undef SEL_AND_ILC_INIT_16 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5360 |
#undef SEL_AND_ILC_INIT_32 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5361 |
#undef SEL_AND_ILC_INIT_64 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5362 |
#undef SEL_AND_ILC_INIT_128 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5363 |
#undef SEL_AND_ILC_INIT_256 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5364 |
|
17757 | 5365 |
static flip = 0; |
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5366 |
int i; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5367 |
for (i = 0; i < nilcs; i++) { |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5368 |
if (sel == sel_and_ilc[i].sel) { |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5369 |
pIlc = &sel_and_ilc[i].ilc; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5370 |
goto perform1_send_and_return; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5371 |
} |
17757 | 5372 |
} |
17789
338675f49dd6
Removed debug prints from perform: methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17788
diff
changeset
|
5373 |
/*printf("Object >> #perform: #%s with: arg --> no PIC found\n", __symbolVal(aSelector));*/ |
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5374 |
pIlc = &sel_and_ilc[flip].ilc; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5375 |
sel_and_ilc[flip].sel = sel; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5376 |
flip = (flip + 1) % nilcs; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5377 |
pIlc->ilc_func = __SEND1ADDR__; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5378 |
if (pIlc->ilc_poly) { |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5379 |
__flushPolyCache(pIlc->ilc_poly); |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5380 |
pIlc->ilc_poly = 0; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5381 |
} |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5382 |
perform1_send_and_return: |
17757 | 5383 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
5755 | 5384 |
} else { |
17757 | 5385 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
5386 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
5755 | 5387 |
} |
5388 |
%}. |
|
5389 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5390 |
||
5391 |
! |
|
5392 |
||
5393 |
perform:aSelector with:arg1 with:arg2 |
|
5394 |
"send the two-arg-message aSelector to the receiver" |
|
5395 |
||
5396 |
%{ |
|
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5397 |
REGISTER OBJ sel = aSelector; |
5755 | 5398 |
struct inlineCache *pIlc; |
5399 |
||
5400 |
if (InterruptPending == nil) { |
|
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5401 |
|
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5402 |
/* JV @ 2010-22-07: To improve performance I use 256 ILCs instead |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5403 |
of default 4. For details, see comment in perform: */ |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5404 |
|
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5405 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF2(l) } |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5406 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5407 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5408 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5409 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5410 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5411 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5412 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5413 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5414 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5415 |
#define nilcs 256 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5416 |
|
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5417 |
static struct { OBJ sel; struct inlineCache ilc; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5418 |
|
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5419 |
#undef SEL_AND_ILC_INIT_1 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5420 |
#undef SEL_AND_ILC_INIT_2 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5421 |
#undef SEL_AND_ILC_INIT_4 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5422 |
#undef SEL_AND_ILC_INIT_8 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5423 |
#undef SEL_AND_ILC_INIT_16 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5424 |
#undef SEL_AND_ILC_INIT_32 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5425 |
#undef SEL_AND_ILC_INIT_64 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5426 |
#undef SEL_AND_ILC_INIT_128 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5427 |
#undef SEL_AND_ILC_INIT_256 |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5428 |
|
17757 | 5429 |
static flip = 0; |
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5430 |
int i; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5431 |
for (i = 0; i < nilcs; i++) { |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5432 |
if (sel == sel_and_ilc[i].sel) { |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5433 |
pIlc = &sel_and_ilc[i].ilc; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5434 |
goto perform2_send_and_return; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5435 |
} |
17757 | 5436 |
} |
17789
338675f49dd6
Removed debug prints from perform: methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17788
diff
changeset
|
5437 |
/*printf("Object >> #perform: #%s with: with: --> no PIC found\n", __symbolVal(aSelector));*/ |
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5438 |
pIlc = &sel_and_ilc[flip].ilc; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5439 |
sel_and_ilc[flip].sel = sel; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5440 |
flip = (flip + 1) % nilcs; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5441 |
pIlc->ilc_func = __SEND2ADDR__; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5442 |
if (pIlc->ilc_poly) { |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5443 |
__flushPolyCache(pIlc->ilc_poly); |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5444 |
pIlc->ilc_poly = 0; |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5445 |
} |
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5446 |
perform2_send_and_return: |
17757 | 5447 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
5755 | 5448 |
} else { |
17757 | 5449 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
5450 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, arg1, arg2)); |
|
5755 | 5451 |
} |
5452 |
%}. |
|
5453 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2) |
|
5454 |
||
5455 |
! |
|
5456 |
||
5457 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
|
5458 |
"send the three-arg-message aSelector to the receiver" |
|
5459 |
||
5460 |
%{ |
|
5461 |
struct inlineCache *pIlc; |
|
5462 |
static struct inlineCache ilc_0 = __ILCPERF3(@line); |
|
5463 |
static struct inlineCache ilc_1 = __ILCPERF3(@line); |
|
5464 |
static OBJ last_0 = nil; |
|
5465 |
static OBJ last_1 = nil; |
|
5466 |
static flip = 0; |
|
5467 |
||
5468 |
if (InterruptPending == nil) { |
|
17757 | 5469 |
if (aSelector != last_0) { |
5470 |
if (aSelector != last_1) { |
|
5471 |
if (flip) { |
|
5472 |
pIlc = &ilc_0; |
|
5473 |
flip = 0; |
|
5474 |
last_0 = aSelector; |
|
5475 |
} else { |
|
5476 |
pIlc = &ilc_1; |
|
5477 |
flip = 1; |
|
5478 |
last_1 = aSelector; |
|
5479 |
} |
|
5480 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5481 |
if (pIlc->ilc_poly) { |
|
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5482 |
printf("Object >> #perform:with:3 flushing PIC\n"); |
17757 | 5483 |
__flushPolyCache(pIlc->ilc_poly); |
5484 |
pIlc->ilc_poly = 0; |
|
5485 |
} |
|
5486 |
} else { |
|
5487 |
pIlc = &ilc_1; |
|
5488 |
} |
|
5489 |
} else { |
|
5490 |
pIlc = &ilc_0; |
|
5491 |
} |
|
5492 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
|
5755 | 5493 |
} else { |
17757 | 5494 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
5495 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, arg1, arg2, arg3)); |
|
5755 | 5496 |
} |
5497 |
%}. |
|
5498 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3) |
|
5499 |
||
5500 |
! |
|
5501 |
||
5502 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
5503 |
"send the four-arg-message aSelector to the receiver" |
|
5504 |
||
5505 |
%{ |
|
5506 |
struct inlineCache *pIlc; |
|
5507 |
static struct inlineCache ilc_0 = __ILCPERF4(@line); |
|
5508 |
static struct inlineCache ilc_1 = __ILCPERF4(@line); |
|
5509 |
static OBJ last_0 = nil; |
|
5510 |
static OBJ last_1 = nil; |
|
5511 |
static flip = 0; |
|
5512 |
||
5513 |
if (InterruptPending == nil) { |
|
17757 | 5514 |
if (aSelector != last_0) { |
5515 |
if (aSelector != last_1) { |
|
5516 |
if (flip) { |
|
5517 |
pIlc = &ilc_0; |
|
5518 |
flip = 0; |
|
5519 |
last_0 = aSelector; |
|
5520 |
} else { |
|
5521 |
pIlc = &ilc_1; |
|
5522 |
flip = 1; |
|
5523 |
last_1 = aSelector; |
|
5524 |
} |
|
5525 |
pIlc->ilc_func = __SEND4ADDR__; |
|
5526 |
if (pIlc->ilc_poly) { |
|
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5527 |
printf("Object >> #perform:with:4 flushing PIC\n"); |
17757 | 5528 |
__flushPolyCache(pIlc->ilc_poly); |
5529 |
pIlc->ilc_poly = 0; |
|
5530 |
} |
|
5531 |
} else { |
|
5532 |
pIlc = &ilc_1; |
|
5533 |
} |
|
5534 |
} else { |
|
5535 |
pIlc = &ilc_0; |
|
5536 |
} |
|
5537 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5538 |
arg1, arg2, arg3, arg4) ); |
|
5755 | 5539 |
} else { |
17757 | 5540 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
5541 |
RETURN (_SEND4(self, aSelector, nil, &ilc4, |
|
5542 |
arg1, arg2, arg3, arg4)); |
|
5755 | 5543 |
} |
5544 |
%}. |
|
5545 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
5546 |
||
5547 |
! |
|
5548 |
||
5549 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
5550 |
"send the five-arg-message aSelector to the receiver" |
|
5551 |
||
5552 |
%{ |
|
5553 |
struct inlineCache *pIlc; |
|
5554 |
static struct inlineCache ilc_0 = __ILCPERF5(@line); |
|
5555 |
static struct inlineCache ilc_1 = __ILCPERF5(@line); |
|
5556 |
static OBJ last_0 = nil; |
|
5557 |
static OBJ last_1 = nil; |
|
5558 |
static flip = 0; |
|
5559 |
||
5560 |
if (InterruptPending == nil) { |
|
17757 | 5561 |
if (aSelector != last_0) { |
5562 |
if (aSelector != last_1) { |
|
5563 |
if (flip) { |
|
5564 |
pIlc = &ilc_0; |
|
5565 |
flip = 0; |
|
5566 |
last_0 = aSelector; |
|
5567 |
} else { |
|
5568 |
pIlc = &ilc_1; |
|
5569 |
flip = 1; |
|
5570 |
last_1 = aSelector; |
|
5571 |
} |
|
5572 |
pIlc->ilc_func = __SEND5ADDR__; |
|
5573 |
if (pIlc->ilc_poly) { |
|
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5574 |
printf("Object >> #perform:with:5 flushing PIC\n"); |
17757 | 5575 |
__flushPolyCache(pIlc->ilc_poly); |
5576 |
pIlc->ilc_poly = 0; |
|
5577 |
} |
|
5578 |
} else { |
|
5579 |
pIlc = &ilc_1; |
|
5580 |
} |
|
5581 |
} else { |
|
5582 |
pIlc = &ilc_0; |
|
5583 |
} |
|
5584 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5585 |
arg1, arg2, arg3, arg4, arg5) ); |
|
5755 | 5586 |
} else { |
17757 | 5587 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
5588 |
RETURN (_SEND5(self, aSelector, nil, &ilc5, |
|
5589 |
arg1, arg2, arg3, arg4, arg5)); |
|
5755 | 5590 |
} |
5591 |
%}. |
|
5592 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
17757 | 5593 |
with:arg5) |
5755 | 5594 |
|
5595 |
! |
|
5596 |
||
5597 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
|
5598 |
"send the six-arg-message aSelector to the receiver" |
|
5599 |
||
5600 |
%{ |
|
5601 |
struct inlineCache *pIlc; |
|
5602 |
static struct inlineCache ilc_0 = __ILCPERF6(@line); |
|
5603 |
static struct inlineCache ilc_1 = __ILCPERF6(@line); |
|
5604 |
static OBJ last_0 = nil; |
|
5605 |
static OBJ last_1 = nil; |
|
5606 |
static flip = 0; |
|
5607 |
||
5608 |
if (InterruptPending == nil) { |
|
17757 | 5609 |
if (aSelector != last_0) { |
5610 |
if (aSelector != last_1) { |
|
5611 |
if (flip) { |
|
5612 |
pIlc = &ilc_0; |
|
5613 |
flip = 0; |
|
5614 |
last_0 = aSelector; |
|
5615 |
} else { |
|
5616 |
pIlc = &ilc_1; |
|
5617 |
flip = 1; |
|
5618 |
last_1 = aSelector; |
|
5619 |
} |
|
5620 |
pIlc->ilc_func = __SEND6ADDR__; |
|
5621 |
if (pIlc->ilc_poly) { |
|
17788
c4f89c6602a5
Improved performance of perform:, perform:with: and perform:with:with. There is still a room for improvements
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17786
diff
changeset
|
5622 |
printf("Object >> #perform:with:6 flushing PIC\n"); |
17757 | 5623 |
__flushPolyCache(pIlc->ilc_poly); |
5624 |
pIlc->ilc_poly = 0; |
|
5625 |
} |
|
5626 |
} else { |
|
5627 |
pIlc = &ilc_1; |
|
5628 |
} |
|
5629 |
} else { |
|
5630 |
pIlc = &ilc_0; |
|
5631 |
} |
|
5632 |
||
5633 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5634 |
arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
5755 | 5635 |
} else { |
17757 | 5636 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
5637 |
RETURN (_SEND6(self, aSelector, nil, &ilc6, |
|
5638 |
arg1, arg2, arg3, arg4, arg5, arg6)); |
|
5755 | 5639 |
} |
5640 |
%}. |
|
5641 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
17757 | 5642 |
with:arg5 with:arg6) |
5755 | 5643 |
|
5644 |
! |
|
5645 |
||
5646 |
perform:aSelector withArguments:argArray |
|
10460 | 5647 |
"send the message aSelector with all args taken from argArray |
5755 | 5648 |
to the receiver." |
5649 |
||
5650 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
5651 |
||
5652 |
%{ |
|
5653 |
REGISTER OBJ *argP; |
|
5654 |
int nargs; |
|
5655 |
OBJ l; |
|
5656 |
||
8934 | 5657 |
if (__isArrayLike(argArray)) { |
17757 | 5658 |
nargs = __arraySize(argArray); |
5659 |
argP = __arrayVal(argArray); |
|
5755 | 5660 |
} else { |
17757 | 5661 |
if (__isNonNilObject(argArray)) { |
5662 |
static struct inlineCache ilcSize = __ILC0(@line); |
|
5663 |
int i; |
|
5664 |
||
5665 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5666 |
if (!__isSmallInteger(numberOfArgs)) |
|
5667 |
goto bad; |
|
5668 |
nargs = __intVal(numberOfArgs); |
|
5669 |
argP = (OBJ *)(&a1); |
|
5670 |
for (i=1; i <= nargs; i++) { |
|
5671 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
5672 |
} |
|
5673 |
argP = (OBJ *)(&a1); |
|
5674 |
} else { |
|
5675 |
nargs = 0; |
|
5676 |
} |
|
5755 | 5677 |
} |
5678 |
switch (nargs) { |
|
17757 | 5679 |
case 0: |
5680 |
if (InterruptPending == nil) { |
|
5681 |
static OBJ last0_0 = nil; static struct inlineCache ilc0_0 = __ILCPERF0(@line); |
|
5682 |
static OBJ last0_1 = nil; static struct inlineCache ilc0_1 = __ILCPERF0(@line); |
|
5683 |
static OBJ last0_2 = nil; static struct inlineCache ilc0_2 = __ILCPERF0(@line); |
|
5684 |
static OBJ last0_3 = nil; static struct inlineCache ilc0_3 = __ILCPERF0(@line); |
|
5685 |
static int flip0 = 0; |
|
5686 |
struct inlineCache *pIlc; |
|
5687 |
||
5688 |
if (aSelector == last0_0) { |
|
5689 |
pIlc = &ilc0_0; |
|
5690 |
} else if (aSelector == last0_1) { |
|
5691 |
pIlc = &ilc0_1; |
|
5692 |
} else if (aSelector == last0_2) { |
|
5693 |
pIlc = &ilc0_2; |
|
5694 |
} else if (aSelector == last0_3) { |
|
5695 |
pIlc = &ilc0_3; |
|
5696 |
} else { |
|
5697 |
if (flip0 == 0) { |
|
5698 |
pIlc = &ilc0_0; |
|
5699 |
flip0 = 1; |
|
5700 |
last0_0 = aSelector; |
|
5701 |
} else if (flip0 == 1) { |
|
5702 |
pIlc = &ilc0_1; |
|
5703 |
flip0 = 2; |
|
5704 |
last0_1 = aSelector; |
|
5705 |
} else if (flip0 == 2) { |
|
5706 |
pIlc = &ilc0_2; |
|
5707 |
flip0 = 3; |
|
5708 |
last0_2 = aSelector; |
|
5709 |
} else { |
|
5710 |
pIlc = &ilc0_3; |
|
5711 |
flip0 = 0; |
|
5712 |
last0_3 = aSelector; |
|
5713 |
} |
|
5714 |
||
5715 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5716 |
if (pIlc->ilc_poly) { |
|
5717 |
__flushPolyCache(pIlc->ilc_poly); |
|
5718 |
pIlc->ilc_poly = 0; |
|
5719 |
} |
|
5720 |
} |
|
5721 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc)); |
|
5722 |
} else { |
|
5723 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5724 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5725 |
} |
|
5726 |
||
5727 |
case 1: |
|
5728 |
if (InterruptPending == nil) { |
|
5729 |
static OBJ last1_0 = nil; static struct inlineCache ilc1_0 = __ILCPERF1(@line); |
|
5730 |
static OBJ last1_1 = nil; static struct inlineCache ilc1_1 = __ILCPERF1(@line); |
|
5731 |
static OBJ last1_2 = nil; static struct inlineCache ilc1_2 = __ILCPERF1(@line); |
|
5732 |
static OBJ last1_3 = nil; static struct inlineCache ilc1_3 = __ILCPERF1(@line); |
|
5733 |
static int flip1 = 0; |
|
5734 |
struct inlineCache *pIlc; |
|
5735 |
||
5736 |
if (aSelector == last1_0) { |
|
5737 |
pIlc = &ilc1_0; |
|
5738 |
} else if (aSelector == last1_1) { |
|
5739 |
pIlc = &ilc1_1; |
|
5740 |
} else if (aSelector == last1_2) { |
|
5741 |
pIlc = &ilc1_2; |
|
5742 |
} else if (aSelector == last1_3) { |
|
5743 |
pIlc = &ilc1_3; |
|
5744 |
} else { |
|
5745 |
if (flip1 == 0) { |
|
5746 |
pIlc = &ilc1_0; |
|
5747 |
flip1 = 1; |
|
5748 |
last1_0 = aSelector; |
|
5749 |
} else if (flip1 == 1) { |
|
5750 |
pIlc = &ilc1_1; |
|
5751 |
flip1 = 2; |
|
5752 |
last1_1 = aSelector; |
|
5753 |
} else if (flip1 == 2) { |
|
5754 |
pIlc = &ilc1_2; |
|
5755 |
flip1 = 3; |
|
5756 |
last1_2 = aSelector; |
|
5757 |
} else { |
|
5758 |
pIlc = &ilc1_3; |
|
5759 |
flip1 = 0; |
|
5760 |
last1_3 = aSelector; |
|
5761 |
} |
|
5762 |
||
5763 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5764 |
if (pIlc->ilc_poly) { |
|
5765 |
__flushPolyCache(pIlc->ilc_poly); |
|
5766 |
pIlc->ilc_poly = 0; |
|
5767 |
} |
|
5768 |
} |
|
5769 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0])); |
|
5770 |
} else { |
|
5771 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5772 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, argP[0])); |
|
5773 |
} |
|
5774 |
||
5775 |
case 2: |
|
5776 |
if (InterruptPending == nil) { |
|
5777 |
static OBJ last2_0 = nil; static struct inlineCache ilc2_0 = __ILCPERF2(@line); |
|
5778 |
static OBJ last2_1 = nil; static struct inlineCache ilc2_1 = __ILCPERF2(@line); |
|
5779 |
static int flip2 = 0; |
|
5780 |
struct inlineCache *pIlc; |
|
5781 |
||
5782 |
if (aSelector == last2_0) { |
|
5783 |
pIlc = &ilc2_0; |
|
5784 |
} else if (aSelector == last2_1) { |
|
5785 |
pIlc = &ilc2_1; |
|
5786 |
} else { |
|
5787 |
if (flip2 == 0) { |
|
5788 |
pIlc = &ilc2_0; |
|
5789 |
flip2 = 1; |
|
5790 |
last2_0 = aSelector; |
|
5791 |
} else { |
|
5792 |
pIlc = &ilc2_1; |
|
5793 |
flip2 = 0; |
|
5794 |
last2_1 = aSelector; |
|
5795 |
} |
|
5796 |
||
5797 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5798 |
if (pIlc->ilc_poly) { |
|
5799 |
__flushPolyCache(pIlc->ilc_poly); |
|
5800 |
pIlc->ilc_poly = 0; |
|
5801 |
} |
|
5802 |
} |
|
5803 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1])); |
|
5804 |
} else { |
|
5805 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5806 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, argP[0], argP[1])); |
|
5807 |
} |
|
5808 |
||
5809 |
case 3: |
|
5810 |
if (InterruptPending == nil) { |
|
5811 |
static OBJ last3_0 = nil; static struct inlineCache ilc3_0 = __ILCPERF3(@line); |
|
5812 |
static OBJ last3_1 = nil; static struct inlineCache ilc3_1 = __ILCPERF3(@line); |
|
5813 |
static int flip3 = 0; |
|
5814 |
struct inlineCache *pIlc; |
|
5815 |
||
5816 |
if (aSelector == last3_0) { |
|
5817 |
pIlc = &ilc3_0; |
|
5818 |
} else if (aSelector == last3_1) { |
|
5819 |
pIlc = &ilc3_1; |
|
5820 |
} else { |
|
5821 |
if (flip3 == 0) { |
|
5822 |
pIlc = &ilc3_0; |
|
5823 |
flip3 = 1; |
|
5824 |
last3_0 = aSelector; |
|
5825 |
} else { |
|
5826 |
pIlc = &ilc3_1; |
|
5827 |
flip3 = 0; |
|
5828 |
last3_1 = aSelector; |
|
5829 |
} |
|
5830 |
||
5831 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5832 |
if (pIlc->ilc_poly) { |
|
5833 |
__flushPolyCache(pIlc->ilc_poly); |
|
5834 |
pIlc->ilc_poly = 0; |
|
5835 |
} |
|
5836 |
} |
|
5837 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1], argP[2])); |
|
5838 |
} else { |
|
5839 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5840 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, argP[0], argP[1], argP[2])); |
|
5841 |
} |
|
5842 |
||
5843 |
case 4: |
|
5844 |
{ |
|
5845 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(@line); |
|
5846 |
||
5847 |
if ((InterruptPending != nil) || (aSelector != last4)) { |
|
5848 |
ilc4.ilc_func = __SEND4ADDR__; |
|
5849 |
if (ilc4.ilc_poly) { |
|
5850 |
__flushPolyCache(ilc4.ilc_poly); |
|
5851 |
ilc4.ilc_poly = 0; |
|
5852 |
} |
|
5853 |
last4 = aSelector; |
|
5854 |
} |
|
5855 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
|
5856 |
argP[0], argP[1], argP[2], argP[3])); |
|
5857 |
} |
|
5858 |
||
5859 |
case 5: |
|
5860 |
{ |
|
5861 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(@line); |
|
5862 |
||
5863 |
if ((InterruptPending != nil) || (aSelector != last5)) { |
|
5864 |
ilc5.ilc_func = __SEND5ADDR__; |
|
5865 |
if (ilc5.ilc_poly) { |
|
5866 |
__flushPolyCache(ilc5.ilc_poly); |
|
5867 |
ilc5.ilc_poly = 0; |
|
5868 |
} |
|
5869 |
last5 = aSelector; |
|
5870 |
} |
|
5871 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
|
5872 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5873 |
} |
|
5874 |
||
5875 |
case 6: |
|
5876 |
{ |
|
5877 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(@line); |
|
5878 |
||
5879 |
if ((InterruptPending != nil) || (aSelector != last6)) { |
|
5880 |
ilc6.ilc_func = __SEND6ADDR__; |
|
5881 |
if (ilc6.ilc_poly) { |
|
5882 |
__flushPolyCache(ilc6.ilc_poly); |
|
5883 |
ilc6.ilc_poly = 0; |
|
5884 |
} |
|
5885 |
last6 = aSelector; |
|
5886 |
} |
|
5887 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
|
5888 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5889 |
argP[5])); |
|
5890 |
} |
|
5891 |
||
5892 |
case 7: |
|
5893 |
{ |
|
5894 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(@line); |
|
5895 |
||
5896 |
if ((InterruptPending != nil) || (aSelector != last7)) { |
|
5897 |
ilc7.ilc_func = __SEND7ADDR__; |
|
5898 |
if (ilc7.ilc_poly) { |
|
5899 |
__flushPolyCache(ilc7.ilc_poly); |
|
5900 |
ilc7.ilc_poly = 0; |
|
5901 |
} |
|
5902 |
last7 = aSelector; |
|
5903 |
} |
|
5904 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
|
5905 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5906 |
argP[5], argP[6])); |
|
5907 |
} |
|
5908 |
||
5909 |
case 8: |
|
5910 |
{ |
|
5911 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(@line); |
|
5912 |
||
5913 |
if ((InterruptPending != nil) || (aSelector != last8)) { |
|
5914 |
ilc8.ilc_func = __SEND8ADDR__; |
|
5915 |
if (ilc8.ilc_poly) { |
|
5916 |
__flushPolyCache(ilc8.ilc_poly); |
|
5917 |
ilc8.ilc_poly = 0; |
|
5918 |
} |
|
5919 |
last8 = aSelector; |
|
5920 |
} |
|
5921 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
|
5922 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5923 |
argP[5], argP[6], argP[7])); |
|
5924 |
} |
|
5925 |
||
5926 |
case 9: |
|
5927 |
{ |
|
5928 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(@line); |
|
5929 |
||
5930 |
if ((InterruptPending != nil) || (aSelector != last9)) { |
|
5931 |
ilc9.ilc_func = __SEND9ADDR__; |
|
5932 |
if (ilc9.ilc_poly) { |
|
5933 |
__flushPolyCache(ilc9.ilc_poly); |
|
5934 |
ilc9.ilc_poly = 0; |
|
5935 |
} |
|
5936 |
last9 = aSelector; |
|
5937 |
} |
|
5938 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
|
5939 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5940 |
argP[5], argP[6], argP[7], argP[8])); |
|
5941 |
} |
|
5942 |
||
5943 |
case 10: |
|
5944 |
{ |
|
5945 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(@line); |
|
5946 |
||
5947 |
if ((InterruptPending != nil) || (aSelector != last10)) { |
|
5948 |
ilc10.ilc_func = __SEND10ADDR__; |
|
5949 |
if (ilc10.ilc_poly) { |
|
5950 |
__flushPolyCache(ilc10.ilc_poly); |
|
5951 |
ilc10.ilc_poly = 0; |
|
5952 |
} |
|
5953 |
last10 = aSelector; |
|
5954 |
} |
|
5955 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
|
5956 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5957 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
5958 |
} |
|
5959 |
||
5960 |
case 11: |
|
5961 |
{ |
|
5962 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(@line); |
|
5963 |
||
5964 |
if ((InterruptPending != nil) || (aSelector != last11)) { |
|
5965 |
ilc11.ilc_func = __SEND11ADDR__; |
|
5966 |
if (ilc11.ilc_poly) { |
|
5967 |
__flushPolyCache(ilc11.ilc_poly); |
|
5968 |
ilc11.ilc_poly = 0; |
|
5969 |
} |
|
5970 |
last11 = aSelector; |
|
5971 |
} |
|
5972 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
|
5973 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5974 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5975 |
argP[10])); |
|
5976 |
} |
|
5977 |
||
5978 |
case 12: |
|
5979 |
{ |
|
5980 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(@line); |
|
5981 |
||
5982 |
if ((InterruptPending != nil) || (aSelector != last12)) { |
|
5983 |
ilc12.ilc_func = __SEND12ADDR__; |
|
5984 |
if (ilc12.ilc_poly) { |
|
5985 |
__flushPolyCache(ilc12.ilc_poly); |
|
5986 |
ilc12.ilc_poly = 0; |
|
5987 |
} |
|
5988 |
last12 = aSelector; |
|
5989 |
} |
|
5990 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
|
5991 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5992 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5993 |
argP[10], argP[11])); |
|
5994 |
} |
|
5995 |
||
5996 |
case 13: |
|
5997 |
{ |
|
5998 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(@line); |
|
5999 |
||
6000 |
if ((InterruptPending != nil) || (aSelector != last13)) { |
|
6001 |
ilc13.ilc_func = __SEND13ADDR__; |
|
6002 |
if (ilc13.ilc_poly) { |
|
6003 |
__flushPolyCache(ilc13.ilc_poly); |
|
6004 |
ilc13.ilc_poly = 0; |
|
6005 |
} |
|
6006 |
last13 = aSelector; |
|
6007 |
} |
|
6008 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
|
6009 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6010 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6011 |
argP[10], argP[11], argP[12])); |
|
6012 |
} |
|
6013 |
||
6014 |
case 14: |
|
6015 |
{ |
|
6016 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(@line); |
|
6017 |
||
6018 |
if ((InterruptPending != nil) || (aSelector != last14)) { |
|
6019 |
ilc14.ilc_func = __SEND14ADDR__; |
|
6020 |
if (ilc14.ilc_poly) { |
|
6021 |
__flushPolyCache(ilc14.ilc_poly); |
|
6022 |
ilc14.ilc_poly = 0; |
|
6023 |
} |
|
6024 |
last14 = aSelector; |
|
6025 |
} |
|
6026 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
|
6027 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6028 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6029 |
argP[10], argP[11], argP[12], argP[13])); |
|
6030 |
} |
|
6031 |
||
6032 |
case 15: |
|
6033 |
{ |
|
6034 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(@line); |
|
6035 |
||
6036 |
if ((InterruptPending != nil) || (aSelector != last15)) { |
|
6037 |
ilc15.ilc_func = __SEND15ADDR__; |
|
6038 |
if (ilc15.ilc_poly) { |
|
6039 |
__flushPolyCache(ilc15.ilc_poly); |
|
6040 |
ilc15.ilc_poly = 0; |
|
6041 |
} |
|
6042 |
last15 = aSelector; |
|
6043 |
} |
|
6044 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
|
6045 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6046 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6047 |
argP[10], argP[11], argP[12], argP[13], |
|
6048 |
argP[14])); |
|
6049 |
} |
|
5755 | 6050 |
} |
6051 |
bad:; |
|
6052 |
%}. |
|
6053 |
||
6054 |
"/ arrive here, if bad number of arguments (too many) |
|
6055 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
6056 |
||
6057 |
^ self primitiveFailed |
|
6058 |
! |
|
6059 |
||
6316 | 6060 |
perform:aSelector withOptionalArgument:arg |
6061 |
"send aSelector-message to the receiver. |
|
6318 | 6062 |
If the message expects an argument, pass arg." |
6316 | 6063 |
|
6064 |
aSelector numArgs == 1 ifTrue:[ |
|
17757 | 6065 |
^ self perform:aSelector with:arg |
6316 | 6066 |
]. |
6067 |
^ self perform:aSelector |
|
6319 | 6068 |
|
6069 |
" |
|
6070 |
|rec sel| |
|
6071 |
||
6072 |
rec := -1. |
|
6073 |
sel := #abs. |
|
6074 |
rec perform:sel withOptionalArgument:2. |
|
6075 |
||
6076 |
sel := #max:. |
|
6077 |
rec perform:sel withOptionalArgument:2. |
|
6078 |
" |
|
6316 | 6079 |
! |
6080 |
||
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6081 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6082 |
"send aSelector-message to the receiver. |
6728 | 6083 |
Depending on the number of arguments the message expects, |
6084 |
pass either none, 1, or 2 arguments." |
|
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6085 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6086 |
|numArgs| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6087 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6088 |
numArgs := aSelector numArgs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6089 |
numArgs == 0 ifTrue:[ |
17757 | 6090 |
^ self perform:aSelector |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6091 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6092 |
numArgs == 1 ifTrue:[ |
17757 | 6093 |
^ self perform:aSelector with:optionalArg1 |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6094 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6095 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6096 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6097 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6098 |
|rec sel| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6099 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6100 |
rec := -1. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6101 |
sel := #abs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6102 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6103 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6104 |
sel := #max:. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6105 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6106 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6107 |
! |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6108 |
|
6728 | 6109 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 |
6110 |
"send aSelector-message to the receiver. |
|
6111 |
Depending on the number of arguments the message expects, |
|
6112 |
pass either none, 1, 2 or 3 arguments." |
|
6113 |
||
6114 |
|numArgs| |
|
6115 |
||
6116 |
numArgs := aSelector numArgs. |
|
6117 |
numArgs == 0 ifTrue:[ |
|
17757 | 6118 |
^ self perform:aSelector |
6728 | 6119 |
]. |
6120 |
numArgs == 1 ifTrue:[ |
|
17757 | 6121 |
^ self perform:aSelector with:optionalArg1 |
6728 | 6122 |
]. |
6123 |
numArgs == 2 ifTrue:[ |
|
17757 | 6124 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6728 | 6125 |
]. |
6126 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3. |
|
6127 |
||
6128 |
" |
|
6129 |
|rec sel| |
|
6130 |
||
6131 |
rec := -1. |
|
6132 |
sel := #abs. |
|
6133 |
rec perform:sel withOptionalArgument:2. |
|
6134 |
||
6135 |
sel := #max:. |
|
6136 |
rec perform:sel withOptionalArgument:2. |
|
6137 |
" |
|
6138 |
! |
|
6139 |
||
6764 | 6140 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 and:optionalArg4 |
6141 |
"send aSelector-message to the receiver. |
|
6142 |
Depending on the number of arguments the message expects, |
|
6143 |
pass either none, 1, 2, 3 or 4 arguments." |
|
6144 |
||
6145 |
|numArgs| |
|
6146 |
||
6147 |
numArgs := aSelector numArgs. |
|
6148 |
numArgs == 0 ifTrue:[ |
|
17757 | 6149 |
^ self perform:aSelector |
6764 | 6150 |
]. |
6151 |
numArgs == 1 ifTrue:[ |
|
17757 | 6152 |
^ self perform:aSelector with:optionalArg1 |
6764 | 6153 |
]. |
6154 |
numArgs == 2 ifTrue:[ |
|
17757 | 6155 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6764 | 6156 |
]. |
6157 |
numArgs == 3 ifTrue:[ |
|
17757 | 6158 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 |
6764 | 6159 |
]. |
6160 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 with:optionalArg4. |
|
6161 |
||
6162 |
" |
|
6163 |
|rec sel| |
|
6164 |
||
6165 |
rec := -1. |
|
6166 |
sel := #abs. |
|
6167 |
rec perform:sel withOptionalArgument:2. |
|
6168 |
||
6169 |
sel := #max:. |
|
6170 |
rec perform:sel withOptionalArgument:2. |
|
6171 |
" |
|
6172 |
! |
|
6173 |
||
5755 | 6174 |
performMethod:aMethod |
6175 |
"invoke aMethod on the receiver. |
|
6176 |
The method should be a zero-argument method. |
|
6177 |
This is a non-object-oriented entry, applying a method |
|
6178 |
in a functional way on a receiver. |
|
6179 |
Warning: |
|
17757 | 6180 |
Take care for the method to be appropriate for the |
6181 |
receiver - no checking is done by the VM." |
|
5755 | 6182 |
|
6183 |
^ aMethod valueWithReceiver:self arguments:#() |
|
6184 |
||
6185 |
" |
|
6186 |
|mthd| |
|
6187 |
||
6188 |
mthd := SmallInteger compiledMethodAt:#negated. |
|
6189 |
Transcript showCR:(1 performMethod:mthd) |
|
6190 |
" |
|
6191 |
||
6192 |
"BAD USE example: |
|
6193 |
||
6194 |
|mthd| |
|
6195 |
||
6196 |
mthd := Point compiledMethodAt:#x. |
|
6197 |
Transcript showCR:((1->2) performMethod:mthd) |
|
6198 |
" |
|
6199 |
||
6200 |
"Modified: 31.7.1997 / 17:41:50 / cg" |
|
6201 |
! |
|
6202 |
||
6203 |
performMethod:aMethod arguments:argumentArray |
|
6204 |
"invoke aMethod on the receiver, passing an argumentArray. |
|
6205 |
The size of the argumentArray should match the number of args |
|
6206 |
expected by the method. |
|
6207 |
This is a non-object-oriented entry, applying a method |
|
6208 |
in a functional way on a receiver. |
|
6209 |
Warning: |
|
17757 | 6210 |
Take care for the method to be appropriate for the |
6211 |
receiver - no checking is done by the VM." |
|
5755 | 6212 |
|
6213 |
^ aMethod valueWithReceiver:self arguments:argumentArray |
|
6214 |
||
6215 |
" |
|
6216 |
|mthd| |
|
6217 |
||
6218 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6219 |
Transcript showCR:(1 performMethod:mthd arguments:#(2)) |
|
6220 |
" |
|
6221 |
||
6222 |
"Created: 31.7.1997 / 17:46:31 / cg" |
|
6223 |
! |
|
6224 |
||
6225 |
performMethod:aMethod with:arg |
|
6226 |
"invoke aMethod on the receiver, passing an argument. |
|
6227 |
The method should be a one-argument method. |
|
6228 |
This is a non-object-oriented entry, applying a method |
|
6229 |
in a functional way on a receiver. |
|
6230 |
Warning: |
|
17757 | 6231 |
Take care for the method to be appropriate for the |
6232 |
receiver - no checking is done by the VM." |
|
5755 | 6233 |
|
6234 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg) |
|
6235 |
||
6236 |
" |
|
6237 |
|mthd| |
|
6238 |
||
6239 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6240 |
Transcript showCR:(1 performMethod:mthd with:2) |
|
6241 |
" |
|
6242 |
||
6243 |
"Modified: 31.7.1997 / 17:42:32 / cg" |
|
6244 |
! |
|
6245 |
||
6246 |
performMethod:aMethod with:arg1 with:arg2 |
|
6247 |
"invoke aMethod on the receiver, passing two arguments. |
|
6248 |
The method should be a two-argument method. |
|
6249 |
This is a non-object-oriented entry, applying a method |
|
6250 |
in a functional way on a receiver. |
|
6251 |
Warning: |
|
17757 | 6252 |
Take care for the method to be appropriate for the |
6253 |
receiver - no checking is done by the VM." |
|
5755 | 6254 |
|
6255 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) |
|
6256 |
||
6257 |
" |
|
6258 |
|mthd arr| |
|
6259 |
||
6260 |
arr := Array new:1. |
|
6261 |
mthd := Array compiledMethodAt:#basicAt:put:. |
|
6262 |
arr performMethod:mthd with:1 with:'foo'. |
|
6263 |
Transcript showCR:arr |
|
6264 |
" |
|
6265 |
||
6266 |
"Modified: 31.7.1997 / 17:44:54 / cg" |
|
6267 |
! |
|
6268 |
||
6269 |
performMethod:aMethod with:arg1 with:arg2 with:arg3 |
|
6270 |
"invoke aMethod on the receiver, passing three arguments. |
|
6271 |
The method should be a three-argument method. |
|
6272 |
This is a non-object-oriented entry, applying a method |
|
6273 |
in a functional way on a receiver. |
|
6274 |
Warning: |
|
17757 | 6275 |
Take care for the method to be appropriate for the |
6276 |
receiver - no checking is done by the VM." |
|
5755 | 6277 |
|
6278 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3) |
|
6279 |
||
6280 |
"Created: 31.7.1997 / 17:45:20 / cg" |
|
6281 |
! ! |
|
6282 |
||
10834 | 6283 |
!Object methodsFor:'object persistency'! |
6284 |
||
6285 |
elementDescriptorFor:anAspectSymbol |
|
6286 |
"support for persistency: |
|
6287 |
answer a collection of associations containing the |
|
6288 |
objects state to be encoded for aspect. |
|
6289 |
Association key is the instance variable name or access selector, |
|
6290 |
association value is the contents of the instance variable. |
|
6291 |
||
6292 |
The default is to return the contents of all non-nil instance variables" |
|
6293 |
||
6294 |
|ret| |
|
6295 |
||
6296 |
ret := 0. |
|
6297 |
anAspectSymbol notNil ifTrue:[ |
|
17757 | 6298 |
ret := self perform:anAspectSymbol ifNotUnderstood:[0]. |
10834 | 6299 |
]. |
6300 |
ret == 0 ifTrue:[ |
|
17757 | 6301 |
^ self elementDescriptorForNonNilInstanceVariables |
10834 | 6302 |
]. |
6303 |
^ ret. |
|
6304 |
! |
|
6305 |
||
6306 |
elementDescriptorForInstanceVariables |
|
6307 |
"return all instance variables for visiting/encoding" |
|
6308 |
||
6309 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
|
6310 |
||
6311 |
" |
|
6312 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
6313 |
Dictionary new elementDescriptorForInstanceVariables |
|
6314 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
6315 |
" |
|
6316 |
! |
|
6317 |
||
6318 |
elementDescriptorForInstanceVariablesMatching:aBlock |
|
6319 |
"return all instance variables which conform to aBlock, for encoding/visiting. |
|
6320 |
Indexed vars are all included." |
|
6321 |
||
6322 |
|instVarNames theClass children |
|
6323 |
instSize "{ Class: SmallInteger }" |
|
6324 |
varSize "{ Class: SmallInteger }"| |
|
6325 |
||
6326 |
theClass := self class. |
|
6327 |
||
6328 |
instSize := theClass instSize. |
|
6329 |
varSize := theClass isVariable ifTrue:[self basicSize] ifFalse:[0]. |
|
6330 |
children := OrderedCollection new:(instSize + varSize). |
|
6331 |
||
6332 |
instVarNames := theClass allInstVarNames. |
|
6333 |
1 to:instSize do:[:i | |var| |
|
17757 | 6334 |
var := self instVarAt:i. |
6335 |
(aBlock value:var) ifTrue:[ |
|
6336 |
children add:((instVarNames at:i) -> var) |
|
6337 |
] |
|
10834 | 6338 |
]. |
6339 |
||
6340 |
varSize ~~ 0 ifTrue:[ |
|
17757 | 6341 |
1 to:varSize do:[:i | |
6342 |
children add:(i -> (self basicAt:i)) |
|
6343 |
] |
|
10834 | 6344 |
]. |
6345 |
||
6346 |
^ children. |
|
6347 |
||
6348 |
" |
|
6349 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
6350 |
Dictionary new elementDescriptorForInstanceVariables |
|
6351 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
6352 |
" |
|
6353 |
! |
|
6354 |
||
6355 |
elementDescriptorForNonNilInstanceVariables |
|
6356 |
"return all non-nil instance variables for visiting/encoding" |
|
6357 |
||
6358 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | val notNil]. |
|
6359 |
||
6360 |
" |
|
6361 |
#(1 2 3 nil true symbol) elementDescriptorForNonNilInstanceVariables |
|
6362 |
Dictionary new elementDescriptorForNonNilInstanceVariables |
|
6363 |
(5 @ nil) elementDescriptorForNonNilInstanceVariables |
|
6364 |
" |
|
6365 |
! ! |
|
6366 |
||
5755 | 6367 |
!Object methodsFor:'printing & storing'! |
6368 |
||
6235 | 6369 |
basicPrintOn:aStream |
6370 |
"append the receivers className with an articel to the argument, aStream" |
|
6371 |
||
6372 |
aStream nextPutAll:self classNameWithArticle |
|
6373 |
! |
|
6374 |
||
5755 | 6375 |
className |
6376 |
"return the classname of the receivers class" |
|
6377 |
||
6378 |
^ self class name |
|
6379 |
||
6380 |
" |
|
6381 |
1 className |
|
10460 | 6382 |
1 class className |
5755 | 6383 |
$a className |
9105 | 6384 |
$a class className |
5755 | 6385 |
" |
6386 |
! |
|
6387 |
||
6388 |
classNameWithArticle |
|
6389 |
"return a string consisting of classname preceeded by an article. |
|
6390 |
(dont expect me to write national variants for this ... :-) |
|
6391 |
If you have special preferences, redefine it ..." |
|
6392 |
||
6829 | 6393 |
| cls| |
5755 | 6394 |
|
6395 |
(cls := self class) == self ifTrue:[ |
|
17757 | 6396 |
^ 'a funny object' |
5755 | 6397 |
]. |
6829 | 6398 |
^ cls nameWithArticle |
5755 | 6399 |
|
6400 |
" |
|
10460 | 6401 |
1 classNameWithArticle |
6402 |
(1->2) classNameWithArticle |
|
5755 | 6403 |
XWorkstation basicNew classNameWithArticle |
10460 | 6404 |
XWorkstation classNameWithArticle |
5755 | 6405 |
" |
6406 |
||
6407 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
6408 |
! |
|
6409 |
||
6410 |
errorPrint |
|
17751 | 6411 |
"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
|
6412 |
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
|
6413 |
headless applications." |
5755 | 6414 |
|
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6415 |
|s| |
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6416 |
|
11335 | 6417 |
s := Processor activeProcess isSystemProcess |
17751 | 6418 |
ifTrue:Stderr |
6419 |
ifFalse:Transcript. |
|
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
6420 |
StreamError catch:[ |
17751 | 6421 |
self printOn:s |
6422 |
]. |
|
6423 |
"/ s ~~ Stderr ifTrue:[ |
|
6424 |
"/ self printOn:Stderr |
|
6425 |
"/ ]. |
|
5755 | 6426 |
|
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6427 |
"Modified: / 29-05-2007 / 20:00:54 / cg" |
5755 | 6428 |
! |
6429 |
||
6430 |
errorPrintCR |
|
6431 |
"{ Pragma: +optSpace }" |
|
6432 |
||
17751 | 6433 |
"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
|
6434 |
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
|
6435 |
headless applications." |
5755 | 6436 |
|
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6437 |
|s| |
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6438 |
|
11335 | 6439 |
s := Processor activeProcess isSystemProcess |
17751 | 6440 |
ifTrue:Stderr |
6441 |
ifFalse:Transcript. |
|
7285
76ff65cdd7e7
Stream streamErrorSignal -> StreamError
Stefan Vogel <sv@exept.de>
parents:
7266
diff
changeset
|
6442 |
StreamError catch:[ |
17751 | 6443 |
self printOn:s. |
6444 |
s cr |
|
6445 |
]. |
|
6446 |
"/ s ~~ Stderr ifTrue:[ |
|
6447 |
"/ self printOn:Stderr. |
|
6448 |
"/ Stderr cr |
|
6449 |
"/ ]. |
|
5755 | 6450 |
|
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6451 |
"Created: / 20-05-1996 / 10:20:41 / cg" |
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
6452 |
"Modified: / 29-05-2007 / 20:00:49 / cg" |
5755 | 6453 |
! |
6454 |
||
6455 |
errorPrintNL |
|
6456 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6457 |
<resource:#obsolete> |
5755 | 6458 |
|
6459 |
"print the receiver followed by a cr on the standard error stream. |
|
6460 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6461 |
||
6462 |
^ self errorPrintCR |
|
6463 |
||
6464 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
6465 |
! |
|
6466 |
||
6467 |
errorPrintNewline |
|
6468 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6469 |
<resource:#obsolete> |
5755 | 6470 |
|
6471 |
"print the receiver followed by a cr on the standard error stream. |
|
6472 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
6473 |
||
6474 |
self errorPrintCR. |
|
6475 |
||
6476 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
6477 |
! |
|
6478 |
||
6479 |
infoPrint |
|
6480 |
"{ Pragma: +optSpace }" |
|
6481 |
||
6482 |
"print the receiver on the standard error stream. |
|
6483 |
This is meant for information messages which are not warnings |
|
6484 |
or fatal messages. |
|
6485 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6486 |
||
6487 |
InfoPrinting == true ifTrue:[ |
|
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
6488 |
self errorPrint |
5755 | 6489 |
] |
6490 |
! |
|
6491 |
||
6492 |
infoPrintCR |
|
6493 |
"{ Pragma: +optSpace }" |
|
6494 |
||
6495 |
"print the receiver followed by a cr on the standard error stream. |
|
6496 |
This is meant for information messages which are not warnings |
|
6497 |
or fatal messages. |
|
6498 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
6499 |
||
6500 |
InfoPrinting == true ifTrue:[ |
|
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
6501 |
self errorPrintCR |
5755 | 6502 |
] |
6503 |
||
6504 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
6505 |
! |
|
6506 |
||
6507 |
infoPrintNL |
|
6508 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6509 |
<resource:#obsolete> |
5755 | 6510 |
|
6511 |
"print the receiver followed by a cr on the standard error stream. |
|
6512 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
6513 |
||
6514 |
^ self infoPrintCR |
|
6515 |
! |
|
6516 |
||
6517 |
||
6518 |
"print the receiver on the standard output stream (which is not the Transcript)" |
|
6519 |
||
6520 |
"/ the following allows printCR to be used during |
|
6521 |
"/ the early init-phase, when no Stdout has been set up. |
|
6522 |
"/ (depends on string to respond to #print) |
|
6523 |
||
6524 |
Stdout isNil ifTrue:[ |
|
17757 | 6525 |
self printString print. |
6526 |
^ self |
|
5755 | 6527 |
]. |
6528 |
self printOn:Stdout |
|
6529 |
||
6530 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
6531 |
! |
|
6532 |
||
6533 |
printCR |
|
6534 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
|
6535 |
||
6536 |
"/ the following allows printCR to be used during |
|
6537 |
"/ the early init-phase, when no Stdout has been set up. |
|
6538 |
"/ (depends on string to respond to #printCR) |
|
6539 |
||
6540 |
Stdout isNil ifTrue:[ |
|
17757 | 6541 |
self printString printCR. |
6542 |
^ self |
|
5755 | 6543 |
]. |
6544 |
self printOn:Stdout. |
|
6545 |
Stdout cr |
|
6546 |
||
6547 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
6548 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
|
6549 |
! |
|
6550 |
||
6551 |
printNL |
|
6552 |
"print the receiver followed by a cr on the standard output stream |
|
6553 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
6554 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6555 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6556 |
|
5755 | 6557 |
^ self printCR |
6558 |
||
6559 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
6560 |
! |
|
6561 |
||
6562 |
printNewline |
|
6563 |
"print the receiver followed by a cr on the standard output stream. |
|
6564 |
This exists for backward compatibility - please use #printCR." |
|
6565 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6566 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6567 |
|
5755 | 6568 |
self printCR |
6569 |
||
6570 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
6571 |
! |
|
6572 |
||
6573 |
printOn:aStream |
|
6574 |
"append a user printed representation of the receiver to aStream. |
|
6575 |
The format is suitable for a human - not meant to be read back. |
|
6576 |
||
6577 |
The default here is to output the receivers class name. |
|
6578 |
BUT: this method is heavily redefined for objects which |
|
6579 |
can print prettier." |
|
6580 |
||
6235 | 6581 |
self basicPrintOn:aStream. |
6582 |
||
6583 |
" |
|
6584 |
(1@2) printOn:Transcript |
|
6585 |
(1@2) basicPrintOn:Transcript |
|
6586 |
" |
|
5755 | 6587 |
! |
6588 |
||
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6589 |
printOn:aStream format:format |
11335 | 6590 |
"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
|
6591 |
Defined here for compatibility with subclasses" |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6592 |
|
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6593 |
self printOn:aStream. |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6594 |
! |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6595 |
|
5755 | 6596 |
printOn:aStream leftPaddedTo:size |
6597 |
"print the receiver on aStream, padding with spaces up to size. |
|
6598 |
padding is done on the left." |
|
6599 |
||
6600 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
6601 |
||
6602 |
" |
|
6603 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
6604 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
6605 |
" |
|
6606 |
! |
|
6607 |
||
6608 |
printOn:aStream leftPaddedTo:size with:padCharacter |
|
6609 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
6610 |
padding is done on the left." |
|
6611 |
||
6612 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
6613 |
||
6614 |
" |
|
6615 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
6616 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
6617 |
" |
|
6618 |
! |
|
6619 |
||
6620 |
printOn:aStream paddedTo:size |
|
6621 |
"print the receiver on aStream, padding with spaces up to size." |
|
6622 |
||
6623 |
self printOn:aStream paddedTo:size with:(Character space) |
|
6624 |
||
6625 |
" |
|
6626 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
6627 |
" |
|
6628 |
! |
|
6629 |
||
6630 |
printOn:aStream paddedTo:size with:padCharacter |
|
6631 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
6632 |
||
6633 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
6634 |
||
6635 |
" |
|
6636 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
6637 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
6638 |
" |
|
6639 |
! |
|
6640 |
||
6641 |
printOn:aStream zeroPaddedTo:size |
|
6642 |
"print the receiver on aStream, padding with zeros up to size. |
|
6643 |
Usually used with float numbers." |
|
6644 |
||
6645 |
self printOn:aStream paddedTo:size with:$0. |
|
6646 |
||
6647 |
" |
|
6648 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
6649 |
" |
|
6650 |
! |
|
6651 |
||
6652 |
printRightAdjustLen:size |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6653 |
<resource: #obsolete> |
5755 | 6654 |
"obsolete - just a name confusion. |
6655 |
This method will go away ..." |
|
6656 |
||
6657 |
(self printStringLeftPaddedTo:size) printOn:Stdout |
|
6658 |
! |
|
6659 |
||
6660 |
printString |
|
6661 |
"return a string for printing the receiver. |
|
6662 |
Since we now use printOn: as the basic print mechanism, |
|
6663 |
we have to create a stream and print into it." |
|
6664 |
||
6665 |
|s| |
|
6666 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
6667 |
s := CharacterWriteStream on:(String basicNew:40). "allocate at least 46 bytes for fast UUID conversion" |
5755 | 6668 |
self printOn:s. |
8300
d15ead94361f
Use CharacterWriteStream in #printString (speedup)
Stefan Vogel <sv@exept.de>
parents:
8287
diff
changeset
|
6669 |
^ s contents. |
7978
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6670 |
|
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6671 |
" |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6672 |
Date today printString. |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
6673 |
" |
5755 | 6674 |
! |
6675 |
||
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6676 |
printStringFormat:orintFormat |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6677 |
"subclasses may redefine this. |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6678 |
Defined here to avoid type checks" |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6679 |
|
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6680 |
^ self printString |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6681 |
! |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6682 |
|
5755 | 6683 |
printStringLeftPaddedTo:size |
6684 |
"return my printString as a right-adjusted string of length size; |
|
6685 |
characters on the left are filled with spaces. |
|
10460 | 6686 |
If the printString is longer than size, |
5755 | 6687 |
it is returned unchanged (i.e. not truncated)" |
6688 |
||
6689 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
6690 |
||
6691 |
" |
|
6692 |
10 printStringLeftPaddedTo:10 |
|
6693 |
1 printStringLeftPaddedTo:10 |
|
6694 |
" |
|
6695 |
! |
|
6696 |
||
6697 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
6698 |
"return my printString as a right-adjusted string of length size; |
|
6699 |
characters on the left are filled with spaces. |
|
6700 |
If the printString is larger than size, |
|
6701 |
return the result from evaluating alternative." |
|
6702 |
||
6703 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
6704 |
||
6705 |
" |
|
6706 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6707 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6708 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6709 |
" |
|
6710 |
! |
|
6711 |
||
6712 |
printStringLeftPaddedTo:size with:padCharacter |
|
6713 |
"return my printString as a right-adjusted string of length size; |
|
6714 |
characters on the left are filled with padCharacter. |
|
10460 | 6715 |
If the printString is longer than size, |
5755 | 6716 |
it is returned unchanged (i.e. not truncated)" |
6717 |
||
6718 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
6719 |
||
6720 |
" |
|
10460 | 6721 |
123 printStringLeftPaddedTo:10 with:$. |
6722 |
1 printStringLeftPaddedTo:10 with:$. |
|
5755 | 6723 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
6724 |
" |
|
6725 |
! |
|
6726 |
||
6727 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
6728 |
"return my printString as a right-adjusted string of length size; |
|
6729 |
characters on the left are filled with padCharacter. |
|
6730 |
If the printString is larger than size, |
|
6731 |
return the result from evaluating alternative." |
|
6732 |
||
6733 |
|s| |
|
6734 |
||
6735 |
s := self printString. |
|
6736 |
s size > size ifTrue:[^ alternative value]. |
|
6737 |
^ s leftPaddedTo:size with:padCharacter |
|
6738 |
||
6739 |
" |
|
10460 | 6740 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
6741 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6742 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
5755 | 6743 |
" |
6744 |
! |
|
6745 |
||
8576 | 6746 |
printStringLimitedTo:sizeLimit |
6747 |
"return a string for printing the receiver, but limit the result string in its size." |
|
6748 |
||
6749 |
|s| |
|
6750 |
||
6751 |
s := CharacterWriteStream on:(String basicNew:30). |
|
6752 |
s writeLimit:sizeLimit. |
|
6753 |
self printOn:s. |
|
6754 |
^ s contents. |
|
6755 |
||
6756 |
" |
|
6757 |
Date today printStringLimitedTo:5. |
|
10460 | 6758 |
'12345678901234567890' printStringLimitedTo:5. |
8576 | 6759 |
" |
6760 |
! |
|
6761 |
||
5755 | 6762 |
printStringOnError:exceptionBlock |
6763 |
"return a string for printing the receiver; if any error occurs, return the result from |
|
6764 |
evaluating exceptionBlock. Useful to print something in an exceptionHandler or other |
|
6765 |
cleanup code." |
|
6766 |
||
6767 |
|rslt| |
|
6768 |
||
6769 |
Error handle:[:ex | |
|
17757 | 6770 |
rslt := exceptionBlock value |
5755 | 6771 |
] do:[ |
17757 | 6772 |
rslt := self printString |
5755 | 6773 |
]. |
6774 |
^ rslt |
|
6775 |
! |
|
6776 |
||
6777 |
printStringPaddedTo:size |
|
6778 |
"return a printed representation of the receiver, |
|
6779 |
padded with spaces (at the right) up to size. |
|
10460 | 6780 |
If the printString is longer than size, |
5755 | 6781 |
it is returned unchanged (i.e. not truncated)" |
6782 |
||
6783 |
^ self printStringPaddedTo:size with:(Character space) |
|
6784 |
||
6785 |
" |
|
10460 | 6786 |
123 printStringPaddedTo:10 |
6787 |
1234567890123456 printStringPaddedTo:10 |
|
6788 |
'hello' printStringPaddedTo:10 |
|
5755 | 6789 |
" |
6790 |
! |
|
6791 |
||
6792 |
printStringPaddedTo:size ifLarger:alternative |
|
6793 |
"return a printed representation of the receiver, |
|
6794 |
padded with spaces (at the right) up to size. |
|
10460 | 6795 |
If the resulting printString is too large, |
5755 | 6796 |
return the result from evaluating alternative." |
6797 |
||
6798 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
6799 |
||
6800 |
" |
|
10460 | 6801 |
12 printStringPaddedTo:3 ifLarger:['***'] |
6802 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
6803 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
5755 | 6804 |
" |
6805 |
! |
|
6806 |
||
6807 |
printStringPaddedTo:size with:padCharacter |
|
6808 |
"return a printed representation of the receiver, |
|
6809 |
padded with padCharacter (at the right) up to size. |
|
10460 | 6810 |
If the printString is longer than size, |
5755 | 6811 |
it is returned unchanged (i.e. not truncated)" |
6812 |
||
6813 |
^ (self printString) paddedTo:size with:padCharacter |
|
6814 |
||
6815 |
" |
|
6816 |
123 printStringPaddedTo:10 with:$. |
|
6817 |
123 printStringPaddedTo:10 with:$* |
|
10460 | 6818 |
123 printStringPaddedTo:3 with:$* |
6819 |
1234 printStringPaddedTo:3 with:$* |
|
5755 | 6820 |
" |
6821 |
! |
|
6822 |
||
6823 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
6824 |
"return a printed representation of the receiver, |
|
6825 |
padded with padCharacter (at the right) up to size. |
|
10460 | 6826 |
If the resulting printString is too large, |
5755 | 6827 |
return the result from evaluating alternative." |
6828 |
||
6829 |
|s| |
|
6830 |
||
6831 |
s := self printString. |
|
6832 |
s size > size ifTrue:[^ alternative value]. |
|
6833 |
^ s paddedTo:size with:padCharacter |
|
6834 |
||
6835 |
" |
|
6836 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6837 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6838 |
" |
|
6839 |
! |
|
6840 |
||
6841 |
printStringRightAdjustLen:size |
|
6842 |
"obsolete - just a name confusion. |
|
6843 |
This method will go away ..." |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6844 |
<resource: #obsolete> |
5755 | 6845 |
|
6846 |
^ self printStringLeftPaddedTo:size |
|
6847 |
! |
|
6848 |
||
6849 |
printStringZeroPaddedTo:size |
|
10460 | 6850 |
"return a printed representation of the receiver, |
5755 | 6851 |
padded with zero (at the right) characters up to size. |
6852 |
Usually used with float numbers." |
|
6853 |
||
6854 |
^ self printStringPaddedTo:size with:$0 |
|
6855 |
||
6856 |
" |
|
10460 | 6857 |
123.0 printStringZeroPaddedTo:10 |
5755 | 6858 |
" |
6859 |
! |
|
6860 |
||
8287 | 6861 |
printfPrintString:ignoredFormat |
6862 |
"fallback to default printString |
|
6863 |
(for compatibility with float and integer-printing)" |
|
6864 |
||
6865 |
^ self printString |
|
6866 |
! |
|
6867 |
||
5755 | 6868 |
store |
6869 |
"store the receiver on standard output. |
|
6870 |
this method is useless, but included for compatibility." |
|
6871 |
||
6872 |
self storeOn:Stdout |
|
6873 |
! |
|
6874 |
||
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6875 |
storeArrayElementOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6876 |
"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
|
6877 |
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
|
6878 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6879 |
^ 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
|
6880 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
6881 |
|
5755 | 6882 |
storeCR |
6883 |
"store the receiver on standard output; append a carriage return." |
|
6884 |
||
6885 |
self store. |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
6886 |
Stdout cr. |
5755 | 6887 |
|
6888 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
6889 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
6890 |
! |
|
6891 |
||
6892 |
storeNl |
|
6893 |
"store the receiver on standard output; append a newline. |
|
6894 |
This method is included for backward compatibility- use #storeCR." |
|
6895 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6896 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6897 |
|
5755 | 6898 |
self storeCR. |
6899 |
||
6900 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
6901 |
! |
|
6902 |
||
6903 |
storeOn:aStream |
|
6904 |
"store the receiver on aStream; i.e. print an expression which will |
|
6905 |
reconstruct the receiver. |
|
6906 |
Notice, that no self referencing or cyclic objects can be represented |
|
6907 |
in this format. |
|
6908 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6909 |
||
6910 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
6911 |
||
6912 |
thisContext isRecursive ifTrue:[ |
|
17757 | 6913 |
Object recursiveStoreStringSignal raiseRequestWith:self. |
6914 |
('Object [error]: storeString of self referencing object.') errorPrintCR. |
|
6915 |
aStream nextPutAll:'#("recursive")'. |
|
6916 |
^ self |
|
5755 | 6917 |
]. |
6918 |
||
6919 |
myClass := self class. |
|
6920 |
aStream nextPut:$(. |
|
6921 |
aStream nextPutAll:self class name. |
|
6922 |
||
6923 |
hasSemi := false. |
|
6924 |
myClass isVariable ifTrue:[ |
|
17757 | 6925 |
aStream nextPutAll:' basicNew:'. |
6926 |
self basicSize printOn:aStream |
|
5755 | 6927 |
] ifFalse:[ |
17757 | 6928 |
aStream nextPutAll:' basicNew' |
5755 | 6929 |
]. |
6930 |
||
6931 |
sz := myClass instSize. |
|
10460 | 6932 |
1 to:sz do:[:i | |
17757 | 6933 |
aStream nextPutAll:' instVarAt:'. |
6934 |
i printOn:aStream. |
|
6935 |
aStream nextPutAll:' put:'. |
|
6936 |
(self instVarAt:i) storeOn:aStream. |
|
6937 |
aStream nextPut:$;. |
|
6938 |
hasSemi := true |
|
5755 | 6939 |
]. |
6940 |
myClass isVariable ifTrue:[ |
|
17757 | 6941 |
sz := self basicSize. |
6942 |
1 to:sz do:[:i | |
|
6943 |
aStream nextPutAll:' basicAt:'. |
|
6944 |
i printOn:aStream. |
|
6945 |
aStream nextPutAll:' put:'. |
|
6946 |
(self basicAt:i) storeOn:aStream. |
|
6947 |
aStream nextPut:$;. |
|
6948 |
hasSemi := true |
|
6949 |
] |
|
5755 | 6950 |
]. |
6951 |
hasSemi ifTrue:[ |
|
17757 | 6952 |
aStream nextPutAll:' yourself' |
5755 | 6953 |
]. |
6954 |
aStream nextPut:$). |
|
6955 |
||
6956 |
" |
|
6957 |
|s| |
|
6958 |
||
6959 |
s := WriteStream on:(String new). |
|
6960 |
('hello' -> 'world') storeOn:s. |
|
6961 |
s := ReadStream on:(s contents). |
|
6962 |
(Object readFrom:s) inspect |
|
6963 |
" |
|
6964 |
" |
|
6965 |
|s| |
|
6966 |
||
6967 |
s := 'data' asFilename writeStream. |
|
6968 |
('hello' -> 'world') storeOn:s. |
|
6969 |
s close. |
|
6970 |
||
6971 |
s := 'data' asFilename readStream. |
|
6972 |
(Object readFrom:s) inspect |
|
6973 |
" |
|
6974 |
||
6975 |
"does not work example:" |
|
6976 |
" |
|
6977 |
|s a| |
|
6978 |
||
6979 |
a := Array new:2. |
|
6980 |
a at:1 put:a. |
|
6981 |
||
6982 |
s := 'data' asFilename writeStream. |
|
6983 |
a storeOn:s. |
|
6984 |
s close. |
|
6985 |
||
6986 |
s := 'data' asFilename readStream. |
|
6987 |
(Object readFrom:s) inspect |
|
6988 |
" |
|
6989 |
||
6990 |
"Modified: 28.1.1997 / 00:36:12 / cg" |
|
6991 |
! |
|
6992 |
||
6993 |
storeString |
|
6994 |
"return a string representing an expression to reconstruct the receiver. |
|
6995 |
Notice, that no self referencing or cyclic objects can be represented |
|
6996 |
in this format. |
|
6997 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6998 |
||
6999 |
|s| |
|
7000 |
||
7001 |
s := WriteStream on:(String new:50). |
|
7002 |
self storeOn:s. |
|
7003 |
^ s contents |
|
7004 |
! ! |
|
7005 |
||
7006 |
!Object methodsFor:'queries'! |
|
7007 |
||
7008 |
basicSize |
|
7009 |
"return the number of the receivers indexed instance variables, |
|
7010 |
0 if it has none. |
|
7011 |
||
7012 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
7013 |
||
7014 |
%{ /* NOCONTEXT */ |
|
7015 |
||
8909 | 7016 |
REGISTER INT nbytes; |
5755 | 7017 |
REGISTER OBJ myClass; |
7018 |
int nInstBytes; |
|
7019 |
||
7020 |
/* |
|
7021 |
* notice the missing test for self being a nonNilObject - |
|
7022 |
* this can be done since basicSize is defined both in UndefinedObject |
|
7023 |
* and SmallInteger |
|
7024 |
*/ |
|
7025 |
myClass = __qClass(self); |
|
7026 |
nbytes = __qSize(self); |
|
7027 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) ); |
|
7028 |
||
7029 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
17757 | 7030 |
case __MASKSMALLINT(POINTERARRAY): |
7031 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
7032 |
nbytes -= nInstBytes; |
|
7033 |
RETURN ( __mkSmallInteger(__BYTES2OBJS__(nbytes)) ); |
|
7034 |
||
7035 |
case __MASKSMALLINT(BYTEARRAY): |
|
7036 |
nbytes -= nInstBytes; |
|
7037 |
RETURN ( __mkSmallInteger(nbytes / sizeof(char)) ); |
|
7038 |
||
7039 |
case __MASKSMALLINT(FLOATARRAY): |
|
7040 |
nbytes -= nInstBytes; |
|
7041 |
RETURN ( __mkSmallInteger(nbytes / sizeof(float)) ); |
|
7042 |
||
7043 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 7044 |
#ifdef __NEED_DOUBLE_ALIGN |
17757 | 7045 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
5755 | 7046 |
#endif |
17757 | 7047 |
nbytes -= nInstBytes; |
7048 |
RETURN ( __mkSmallInteger(nbytes / sizeof(double)) ); |
|
7049 |
||
7050 |
case __MASKSMALLINT(WORDARRAY): |
|
7051 |
case __MASKSMALLINT(SWORDARRAY): |
|
7052 |
nbytes -= nInstBytes; |
|
7053 |
RETURN ( __mkSmallInteger(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */ |
|
7054 |
||
7055 |
case __MASKSMALLINT(LONGARRAY): |
|
7056 |
case __MASKSMALLINT(SLONGARRAY): |
|
7057 |
nbytes -= nInstBytes; |
|
7058 |
RETURN ( __mkSmallInteger(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */ |
|
7059 |
||
7060 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
7061 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 7062 |
#ifdef __NEED_LONGLONG_ALIGN |
17757 | 7063 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
5755 | 7064 |
#endif |
17757 | 7065 |
nbytes -= nInstBytes; |
7066 |
RETURN ( __mkSmallInteger(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */ |
|
5755 | 7067 |
} |
7068 |
%}. |
|
7069 |
^ 0 |
|
7070 |
! |
|
7071 |
||
7072 |
byteSize |
|
7073 |
"return the number of bytes in the receivers indexed instance variables, |
|
7074 |
0 if it has none. This only returns non-zero for non-pointer indexed |
|
7075 |
instvars i.e. byteArrays, wordArrays etc. |
|
7076 |
Notice: for Strings the returned size may look strange. |
|
7077 |
Only useful with binary storage." |
|
7078 |
||
7079 |
|myClass| |
|
7080 |
||
7081 |
myClass := self class. |
|
7082 |
myClass isVariable ifTrue:[ |
|
17757 | 7083 |
myClass isPointers ifFalse:[ |
7084 |
myClass isBytes ifTrue:[ |
|
7085 |
^ self basicSize. |
|
7086 |
]. |
|
7087 |
myClass isWords ifTrue:[ |
|
7088 |
^ self basicSize * 2. |
|
7089 |
]. |
|
7090 |
myClass isSignedWords ifTrue:[ |
|
7091 |
^ self basicSize * 2. |
|
7092 |
]. |
|
7093 |
myClass isLongs ifTrue:[ |
|
7094 |
^ self basicSize * 4. |
|
7095 |
]. |
|
7096 |
myClass isSignedLongs ifTrue:[ |
|
7097 |
^ self basicSize * 4. |
|
7098 |
]. |
|
7099 |
myClass isLongLongs ifTrue:[ |
|
7100 |
^ self basicSize * 8. |
|
7101 |
]. |
|
7102 |
myClass isSignedLongLongs ifTrue:[ |
|
7103 |
^ self basicSize * 8. |
|
7104 |
]. |
|
7105 |
myClass isFloats ifTrue:[ |
|
7106 |
^ self basicSize * (ExternalBytes sizeofFloat) |
|
7107 |
]. |
|
7108 |
myClass isDoubles ifTrue:[ |
|
7109 |
^ self basicSize * (ExternalBytes sizeofDouble) |
|
7110 |
]. |
|
7111 |
self error:'unknown variable size class species'. |
|
7112 |
] |
|
5755 | 7113 |
]. |
7114 |
^ 0 |
|
7115 |
||
7116 |
" |
|
10460 | 7117 |
Point new byteSize |
7118 |
'hello' byteSize |
|
7119 |
(ByteArray with:1 with:2) byteSize |
|
7120 |
(FloatArray with:1.5) byteSize |
|
7121 |
(DoubleArray with:1.5) byteSize |
|
7122 |
(WordArray with:1 with:2) byteSize |
|
5755 | 7123 |
" |
7124 |
! |
|
7125 |
||
7126 |
class |
|
7127 |
"return the receivers class" |
|
7128 |
||
7129 |
%{ /* NOCONTEXT */ |
|
7130 |
||
7131 |
RETURN ( __Class(self) ); |
|
7132 |
%} |
|
7133 |
! |
|
7134 |
||
7135 |
respondsTo:aSelector |
|
7136 |
"return true, if the receiver implements a method with selector equal |
|
7137 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
7138 |
receivers class or one of its superclasses. |
|
7139 |
||
7140 |
Notice, that this does not imply, that such a message can be sent without |
|
7141 |
an error being raised. For example, an implementation could send |
|
7142 |
#shouldNotImplement or #subclassResponsibility." |
|
7143 |
||
7144 |
" |
|
7145 |
should we go via the cache, or search (by class) ? |
|
7146 |
The first is faster, most of the time; while the 2nd fills |
|
7147 |
the cache with useless data if this is sent in a loop over all objects. |
|
7148 |
For now, use the cache ... |
|
7149 |
" |
|
7150 |
%{ /* NOCONTEXT */ |
|
7151 |
||
7152 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
17757 | 7153 |
RETURN ( false ); |
5755 | 7154 |
} |
7155 |
RETURN ( true ); |
|
7156 |
%} |
|
7157 |
. |
|
7158 |
^ self class canUnderstand:aSelector |
|
7159 |
||
7160 |
||
7161 |
"'aString' respondsTo:#+" |
|
7162 |
"'aString' respondsTo:#," |
|
7163 |
"'aString' respondsTo:#collect:" |
|
7164 |
! |
|
7165 |
||
7166 |
respondsToArithmetic |
|
7167 |
"return true, if the receiver responds to arithmetic messages. |
|
7168 |
false is returned here - the method is redefined in ArithmeticValue." |
|
7169 |
||
7170 |
^ false |
|
7171 |
! |
|
7172 |
||
7173 |
size |
|
7174 |
"return the number of the receivers indexed instance variables; |
|
7175 |
this method may be redefined in subclasses" |
|
7176 |
||
7177 |
^ self basicSize |
|
7178 |
! |
|
7179 |
||
7180 |
species |
|
7181 |
"return a class which is similar to (or the same as) the receivers class. |
|
7182 |
This is used to create an appropriate object when creating derived |
|
7183 |
copies in the collection classes (sometimes redefined)." |
|
7184 |
||
7185 |
^ self class |
|
7186 |
! |
|
7187 |
||
7188 |
yourself |
|
7189 |
"return the receiver - used for cascades to return self at the end" |
|
7190 |
||
7191 |
^ self |
|
7192 |
! ! |
|
7193 |
||
17795 | 7194 |
|
5755 | 7195 |
!Object methodsFor:'secure message sending'! |
7196 |
||
7197 |
askFor:aSelector |
|
7198 |
"try to send the receiver the message, aSelector. |
|
10460 | 7199 |
If it does not understand it, return false. |
5755 | 7200 |
Otherwise the real value returned. |
11398 | 7201 |
Useful to send messages such as: #isColor to unknown receivers." |
5755 | 7202 |
|
7203 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
7204 |
||
7205 |
" |
|
10460 | 7206 |
1 askFor:#isColor |
7207 |
Color red askFor:#isColor |
|
7208 |
||
7209 |
1 askFor:#isFoo |
|
7210 |
Color red askFor:#isFoo |
|
5755 | 7211 |
" |
7212 |
! |
|
7213 |
||
11398 | 7214 |
askFor:aSelector with:argument |
7215 |
"try to send the receiver the message, aSelector. |
|
7216 |
If it does not understand it, return false. |
|
7217 |
Otherwise the real value returned. |
|
7218 |
Useful to send messages such as: #isXXX: to unknown receivers." |
|
7219 |
||
7220 |
^ self perform:aSelector with:argument ifNotUnderstood:[false] |
|
7221 |
! |
|
7222 |
||
11401 | 7223 |
askFor:aSelector with:arg1 with:arg2 |
7224 |
"try to send the receiver the message, aSelector. |
|
7225 |
If it does not understand it, return false. |
|
7226 |
Otherwise the real value returned. |
|
7227 |
Useful to send messages such as: #isXXX: to unknown receivers." |
|
7228 |
||
7229 |
^ self perform:aSelector with:arg1 with:arg2 ifNotUnderstood:[false] |
|
7230 |
! |
|
7231 |
||
5755 | 7232 |
perform:aSelector ifNotUnderstood:exceptionBlock |
7233 |
"try to send message aSelector to the receiver. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7234 |
If its understood, return the method's returned value, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7235 |
otherwise return the value of the exceptionBlock. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7236 |
Read this: |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7237 |
Many programmers do an Error-handle to perform a similar |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7238 |
checked-message send. However, this method is more specific, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7239 |
in that only errors for the given selector are cought - not any other |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7240 |
doesNotUnderstand, and especially not any other error." |
5755 | 7241 |
|
7242 |
|val ok| |
|
7243 |
||
6146 | 7244 |
MessageNotUnderstood handle:[:ex | |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7245 |
"/ reject, if the bad message is not the one |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7246 |
"/ we have sent originally |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7247 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7248 |
ex reject |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7249 |
]. |
5755 | 7250 |
] do:[ |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7251 |
val := self perform:aSelector. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7252 |
ok := true. |
5755 | 7253 |
]. |
7254 |
ok isNil ifTrue:[ |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7255 |
^ exceptionBlock value |
5755 | 7256 |
]. |
7257 |
^ val |
|
7258 |
||
7259 |
" |
|
10460 | 7260 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
7261 |
1.2345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
7262 |
12345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
5755 | 7263 |
" |
7264 |
! |
|
7265 |
||
7266 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
7267 |
"try to send message aSelector to the receiver. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7268 |
If its understood, return the method's returned value, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7269 |
otherwise return the value of the exceptionBlock. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7270 |
Read this: |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7271 |
Many programmers do an Error-handle to perform a similar |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7272 |
checked-message send. However, this method is more specific, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7273 |
in that only errors for the given selector are cought - not any other |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7274 |
doesNotUnderstand, and especially not any other error." |
5755 | 7275 |
|
7276 |
|val ok| |
|
7277 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7278 |
MessageNotUnderstood handle:[:ex | |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7279 |
"/ reject, if the bad message is not the one |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7280 |
"/ we have sent originally |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7281 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7282 |
ex reject |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7283 |
] |
5755 | 7284 |
] do:[ |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7285 |
val := self perform:aSelector with:argument. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7286 |
ok := true. |
5755 | 7287 |
]. |
7288 |
ok isNil ifTrue:[ |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7289 |
^ exceptionBlock value |
5755 | 7290 |
]. |
7291 |
^ val |
|
7292 |
||
7293 |
" |
|
7294 |
|unknown| |
|
7295 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7296 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7297 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 7298 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7299 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 7300 |
" |
7301 |
! |
|
7302 |
||
5926 | 7303 |
perform:aSelector with:arg1 with:arg2 ifNotUnderstood:exceptionBlock |
7304 |
"try to send message aSelector to the receiver. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7305 |
If its understood, return the method's returned value, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7306 |
otherwise return the value of the exceptionBlock. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7307 |
Read this: |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7308 |
Many programmers do an Error-handle to perform a similar |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7309 |
checked-message send. However, this method is more specific, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7310 |
in that only errors for the given selector are cought - not any other |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7311 |
doesNotUnderstand, and especially not any other error." |
5926 | 7312 |
|
7313 |
|val ok| |
|
7314 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7315 |
MessageNotUnderstood handle:[:ex | |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7316 |
"/ reject, if the bad message is not the one |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7317 |
"/ we have sent originally |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7318 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7319 |
ex reject |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7320 |
] |
5926 | 7321 |
] do:[ |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7322 |
val := self perform:aSelector with:arg1 with:arg2. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7323 |
ok := true. |
5926 | 7324 |
]. |
7325 |
ok isNil ifTrue:[ |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7326 |
^ exceptionBlock value |
5926 | 7327 |
]. |
7328 |
^ val |
|
7329 |
! |
|
7330 |
||
5755 | 7331 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
7332 |
"try to send message aSelector to the receiver. |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7333 |
If its understood, return the method's returned value, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7334 |
otherwise return the value of the exceptionBlock. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7335 |
Read this: |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7336 |
Many programmers do an Error-handle to perform a similar |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7337 |
checked-message send. However, this method is more specific, |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7338 |
in that only errors for the given selector are cought - not any other |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7339 |
doesNotUnderstand, and especially not any other error." |
5755 | 7340 |
|
7341 |
|val ok| |
|
7342 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7343 |
MessageNotUnderstood handle:[:ex | |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7344 |
"/ reject, if the bad message is not the one |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7345 |
"/ we have sent originally. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7346 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7347 |
ex reject |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7348 |
] |
5755 | 7349 |
] do:[ |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7350 |
val := self perform:aSelector withArguments:argumentArray. |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7351 |
ok := true. |
5755 | 7352 |
]. |
7353 |
ok isNil ifTrue:[ |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
7354 |
^ exceptionBlock value |
5755 | 7355 |
]. |
7356 |
^ val |
|
7357 |
||
7358 |
" |
|
7359 |
|unknown| |
|
7360 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7361 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7362 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 7363 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7364 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 7365 |
" |
7366 |
||
7367 |
"Modified: 27.3.1997 / 14:13:16 / cg" |
|
7368 |
! ! |
|
7369 |
||
7370 |
!Object methodsFor:'signal constants'! |
|
7371 |
||
7372 |
messageNotUnderstoodSignal |
|
6146 | 7373 |
^ MessageNotUnderstood |
5755 | 7374 |
|
7375 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
7376 |
! ! |
|
7377 |
||
7378 |
!Object methodsFor:'special queries'! |
|
7379 |
||
7380 |
allOwners |
|
7381 |
"return a collection of all objects referencing the receiver" |
|
7382 |
||
7383 |
^ ObjectMemory whoReferences:self |
|
7384 |
! |
|
7385 |
||
7386 |
references:anObject |
|
7387 |
"return true, if the receiver refers to the argument, anObject. |
|
7388 |
- for debugging only" |
|
7389 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7390 |
^ self referencesObject:anObject |
5755 | 7391 |
|
7392 |
" |
|
7393 |
|v| |
|
7394 |
||
7395 |
v := View new initialize. |
|
10460 | 7396 |
v references:Display. |
5755 | 7397 |
" |
7398 |
! |
|
7399 |
||
7400 |
referencesAny:aCollection |
|
10460 | 7401 |
"return true, if the receiver refers to any object from |
5755 | 7402 |
the argument, aCollection. |
7403 |
- for debugging only" |
|
7404 |
||
10460 | 7405 |
%{ |
5755 | 7406 |
OBJ cls, flags; |
7407 |
int nInsts, inst; |
|
7408 |
||
7409 |
if (! __isNonNilObject(self)) { |
|
17757 | 7410 |
RETURN (false); |
5755 | 7411 |
} |
7412 |
||
8934 | 7413 |
if (__isArrayLike(aCollection)) { |
17757 | 7414 |
int nObjs = __arraySize(aCollection); |
7415 |
char *minAddr = 0, *maxAddr = 0; |
|
7416 |
||
7417 |
if (nObjs == 0) { |
|
7418 |
RETURN (false); |
|
7419 |
} |
|
7420 |
||
7421 |
/* |
|
7422 |
* a little optimization: use the fact that all old objects |
|
7423 |
* refering to a new object are on the remSet; if I am not, |
|
7424 |
* a trivial reject is possible, if all objects are newbees. |
|
7425 |
* as a side effect, gather min/max addresses |
|
7426 |
*/ |
|
7427 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
7428 |
int allNewBees = 1; |
|
7429 |
int i; |
|
7430 |
||
7431 |
minAddr = (char *)(__ArrayInstPtr(aCollection)->a_element[0]); |
|
7432 |
maxAddr = minAddr; |
|
7433 |
||
7434 |
for (i=0; i<nObjs; i++) { |
|
7435 |
OBJ anObject; |
|
7436 |
||
7437 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7438 |
||
7439 |
if (__isNonNilObject(anObject)) { |
|
7440 |
int spc; |
|
7441 |
||
7442 |
if (((spc = __qSpace(anObject)) != NEWSPACE) && (spc != SURVSPACE)) { |
|
7443 |
allNewBees = 0; |
|
7444 |
} |
|
7445 |
} |
|
7446 |
||
7447 |
if ((char *)anObject < minAddr) { |
|
7448 |
minAddr = (char *)anObject; |
|
7449 |
} else if ((char *)anObject > maxAddr) { |
|
7450 |
maxAddr = (char *)anObject; |
|
7451 |
} |
|
7452 |
} |
|
7453 |
if (allNewBees) { |
|
7454 |
RETURN (false); |
|
7455 |
} |
|
7456 |
} |
|
7457 |
||
7458 |
/* |
|
7459 |
* fetch min/max in searchList (if not already done) |
|
7460 |
*/ |
|
7461 |
if (minAddr == 0) { |
|
7462 |
int i; |
|
7463 |
||
7464 |
for (i=0; i<nObjs; i++) { |
|
7465 |
OBJ anObject; |
|
7466 |
||
7467 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7468 |
if ((char *)anObject < minAddr) { |
|
7469 |
minAddr = (char *)anObject; |
|
7470 |
} else if ((char *)anObject > maxAddr) { |
|
7471 |
maxAddr = (char *)anObject; |
|
7472 |
} |
|
7473 |
} |
|
7474 |
} |
|
7475 |
||
7476 |
cls = __qClass(self); |
|
7477 |
if (((char *)cls >= minAddr) && ((char *)cls <= maxAddr)) { |
|
5755 | 7478 |
#if defined(memsrch4) |
17757 | 7479 |
if (memsrch4(__arrayVal(aCollection), (INT)cls, nObjs)) { |
7480 |
RETURN (true); |
|
7481 |
} |
|
5755 | 7482 |
#else |
17757 | 7483 |
int i; |
7484 |
||
7485 |
for (i=0; i<nObjs; i++) { |
|
7486 |
OBJ anObject; |
|
7487 |
||
7488 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7489 |
if (cls == anObject) { |
|
7490 |
RETURN (true); |
|
7491 |
} |
|
7492 |
} |
|
5755 | 7493 |
#endif /* memsrch4 */ |
17757 | 7494 |
} |
7495 |
||
7496 |
flags = __ClassInstPtr(cls)->c_flags; |
|
7497 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
7498 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
7499 |
} else { |
|
7500 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
7501 |
} |
|
7502 |
if (! nInsts) { |
|
7503 |
RETURN (false); |
|
7504 |
} |
|
7505 |
||
7506 |
if (nObjs == 1) { |
|
7507 |
/* better reverse the loop */ |
|
7508 |
OBJ anObject; |
|
7509 |
||
7510 |
anObject = __ArrayInstPtr(aCollection)->a_element[0]; |
|
5755 | 7511 |
#if defined(memsrch4) |
17757 | 7512 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
7513 |
RETURN (true); |
|
7514 |
} |
|
5755 | 7515 |
#else |
17757 | 7516 |
for (inst=0; inst<nInsts; inst++) { |
7517 |
if ((__InstPtr(self)->i_instvars[inst]) == anObject) { |
|
7518 |
RETURN (true); |
|
7519 |
} |
|
7520 |
} |
|
5755 | 7521 |
#endif |
17757 | 7522 |
RETURN (false); |
7523 |
} |
|
7524 |
||
7525 |
for (inst=0; inst<nInsts; inst++) { |
|
7526 |
OBJ instVar = __InstPtr(self)->i_instvars[inst]; |
|
7527 |
int i; |
|
7528 |
||
7529 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
5755 | 7530 |
#if defined(memsrch4) |
17757 | 7531 |
if (memsrch4(__arrayVal(aCollection), (INT)instVar, nObjs)) { |
7532 |
RETURN (true); |
|
7533 |
} |
|
5755 | 7534 |
#else |
17757 | 7535 |
for (i=0; i<nObjs; i++) { |
7536 |
OBJ anObject; |
|
7537 |
||
7538 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
7539 |
if (instVar == anObject) { |
|
7540 |
RETURN (true); |
|
7541 |
} |
|
7542 |
} |
|
5755 | 7543 |
#endif /* memsrch4 */ |
17757 | 7544 |
} |
7545 |
} |
|
7546 |
RETURN (false); |
|
5755 | 7547 |
} |
7548 |
%}. |
|
7549 |
||
7550 |
aCollection do:[:el | |
|
17757 | 7551 |
(self referencesObject:el) ifTrue:[^ true]. |
5755 | 7552 |
]. |
7553 |
^ false |
|
7554 |
! |
|
7555 |
||
7556 |
referencesDerivedInstanceOf:aClass |
|
7557 |
"return true, if the receiver refers to an instance of |
|
7558 |
the argument, aClass or its subclass. This method exists |
|
7559 |
to support searching for users of a class." |
|
7560 |
||
10460 | 7561 |
|myClass |
5755 | 7562 |
numInst "{ Class: SmallInteger }" | |
7563 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7564 |
"check the class" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7565 |
(self isKindOf:aClass) ifTrue:[^ true]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
7566 |
|
5755 | 7567 |
myClass := self class. |
7568 |
"check the instance variables" |
|
7569 |
numInst := myClass instSize. |
|
10460 | 7570 |
1 to:numInst do:[:i | |
17757 | 7571 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
5755 | 7572 |
]. |
7573 |
||
7574 |
"check the indexed variables" |
|
7575 |
myClass isVariable ifTrue:[ |
|
17757 | 7576 |
myClass isPointers ifFalse:[ |
7577 |
"no need to search in non pointer fields" |
|
7578 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
|
7579 |
]. |
|
7580 |
numInst := self basicSize. |
|
7581 |
1 to:numInst do:[:i | |
|
7582 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
7583 |
] |
|
5755 | 7584 |
]. |
7585 |
^ false |
|
7586 |
||
7587 |
" |
|
10460 | 7588 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
7589 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
7590 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
5755 | 7591 |
" |
7592 |
! |
|
7593 |
||
9279 | 7594 |
referencesForWhich:checkBlock do:actionBlock |
7595 |
|myClass inst |
|
7596 |
numInst "{ Class: SmallInteger }" | |
|
7597 |
||
7598 |
myClass := self class. |
|
7599 |
"check the instance variables" |
|
7600 |
numInst := myClass instSize. |
|
10460 | 7601 |
1 to:numInst do:[:i | |
17757 | 7602 |
inst := self instVarAt:i. |
7603 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
9279 | 7604 |
]. |
7605 |
||
7606 |
"check the indexed variables" |
|
7607 |
myClass isVariable ifTrue:[ |
|
17757 | 7608 |
myClass isPointers ifTrue:[ |
7609 |
"no need to search in non pointer fields" |
|
7610 |
||
7611 |
numInst := self basicSize. |
|
7612 |
1 to:numInst do:[:i | |
|
7613 |
inst := self basicAt:i. |
|
7614 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
7615 |
] |
|
7616 |
] |
|
10460 | 7617 |
]. |
7618 |
||
7619 |
" |
|
7620 |
(1 @ 3.4) referencesForWhich:[:i | i isFloat] do:[:i | Transcript showCR:i] |
|
9279 | 7621 |
" |
7622 |
! |
|
7623 |
||
5755 | 7624 |
referencesInstanceOf:aClass |
7625 |
"return true, if the receiver refers to an instance of |
|
7626 |
the argument, aClass.This method exists |
|
7627 |
to support searching for users of a class." |
|
7628 |
||
10460 | 7629 |
|myClass |
5755 | 7630 |
numInst "{ Class: SmallInteger }" | |
7631 |
||
7632 |
myClass := self class. |
|
7633 |
||
7634 |
"check the class" |
|
7635 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
7636 |
||
7637 |
"check the instance variables" |
|
7638 |
numInst := myClass instSize. |
|
10460 | 7639 |
1 to:numInst do:[:i | |
17757 | 7640 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
5755 | 7641 |
]. |
7642 |
||
7643 |
"check the indexed variables" |
|
7644 |
myClass isVariable ifTrue:[ |
|
17757 | 7645 |
myClass isPointers ifFalse:[ |
7646 |
"no need to search in non-pointer indexed fields" |
|
7647 |
myClass isLongs ifTrue:[ |
|
7648 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
7649 |
] ifFalse:[ |
|
7650 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
7651 |
^ aClass == SmallInteger |
|
7652 |
] |
|
7653 |
]. |
|
7654 |
numInst := self basicSize. |
|
7655 |
1 to:numInst do:[:i | |
|
7656 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
7657 |
] |
|
5755 | 7658 |
]. |
7659 |
^ false |
|
7660 |
||
7661 |
" |
|
10460 | 7662 |
(1 @ 3.4) referencesInstanceOf:Float |
7663 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
7664 |
View new initialize referencesInstanceOf:(Display class) |
|
5755 | 7665 |
" |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7666 |
! |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7667 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7668 |
referencesObject:anObject |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7669 |
"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
|
7670 |
- for debugging only" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7671 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7672 |
%{ /* NOCONTEXT */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7673 |
OBJ cls, flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7674 |
int nInsts, i; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7675 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7676 |
if (! __isNonNilObject(self)) { |
17757 | 7677 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7678 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7679 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7680 |
/* |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7681 |
* 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
|
7682 |
* 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
|
7683 |
* 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
|
7684 |
*/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7685 |
if (__isNonNilObject(anObject)) { |
17757 | 7686 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
7687 |
int spc; |
|
7688 |
||
7689 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
7690 |
RETURN (false); |
|
7691 |
} |
|
7692 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7693 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7694 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7695 |
cls = __qClass(self); |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7696 |
if (cls == anObject) { |
17757 | 7697 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7698 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7699 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7700 |
flags = __ClassInstPtr(cls)->c_flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7701 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
17757 | 7702 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7703 |
} else { |
17757 | 7704 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7705 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7706 |
if (! nInsts) { |
17757 | 7707 |
RETURN (false); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7708 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7709 |
#if defined(memsrch4) |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7710 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
17757 | 7711 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7712 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7713 |
#else |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7714 |
for (i=0; i<nInsts; i++) { |
17757 | 7715 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
7716 |
RETURN (true); |
|
7717 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7718 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7719 |
#endif /* memsrch4 */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7720 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7721 |
%}. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7722 |
|
10460 | 7723 |
"/ |myClass |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7724 |
"/ numInst "{ Class: SmallInteger }" | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7725 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7726 |
"/ myClass := self class. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7727 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7728 |
"/ "check the class" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7729 |
"/ (myClass == anObject) ifTrue:[^ true]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7730 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7731 |
"/ "check the instance variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7732 |
"/ numInst := myClass instSize. |
10460 | 7733 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7734 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7735 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7736 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7737 |
"/ "check the indexed variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7738 |
"/ myClass isVariable ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7739 |
"/ myClass isPointers ifFalse:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7740 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7741 |
"/ "/ 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
|
7742 |
"/ "/ 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
|
7743 |
"/ "/ 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
|
7744 |
"/ "/ 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
|
7745 |
"/ "/ 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
|
7746 |
"/ "/ 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
|
7747 |
"/ "/ 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
|
7748 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7749 |
"/ ^ false. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7750 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7751 |
"/ "/ alternative: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7752 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7753 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7754 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7755 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7756 |
"/ "/ 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
|
7757 |
"/ "/ idenitytIndex method, use it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7758 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7759 |
"/ myClass == Array ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7760 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7761 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7762 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7763 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7764 |
"/ "/ otherwise, do it the slow way |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7765 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7766 |
"/ numInst := self basicSize. |
10460 | 7767 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7768 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7769 |
"/ ] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7770 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7771 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7772 |
^ false |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7773 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7774 |
" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7775 |
|v| |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7776 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7777 |
v := View new initialize. |
10460 | 7778 |
v references:Display. |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
7779 |
" |
5755 | 7780 |
! ! |
7781 |
||
7782 |
!Object methodsFor:'synchronized evaluation'! |
|
7783 |
||
10460 | 7784 |
freeSynchronizationSemaphore |
5755 | 7785 |
"free synchronizationSemaphore. May be used, to save memory when |
7786 |
an object is no longer used synchronized." |
|
7787 |
||
7788 |
|sema| |
|
7789 |
||
7790 |
sema := self synchronizationSemaphore. |
|
7791 |
sema notNil ifTrue:[ |
|
17757 | 7792 |
sema wait. "/ get lock |
7793 |
self synchronizationSemaphore:nil. |
|
5755 | 7794 |
]. |
7795 |
||
7796 |
" |
|
7797 |
self synchronized:[]. |
|
7798 |
self synchronizationSemaphore. |
|
7799 |
self freeSynchronizationSemaphore. |
|
7800 |
" |
|
7801 |
||
7802 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
7803 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
7804 |
! |
|
7805 |
||
7806 |
synchronizationSemaphore |
|
7807 |
"return the synchronization semaphore for myself. |
|
7808 |
subclasses may redefine" |
|
7809 |
||
7810 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
7811 |
||
7812 |
" |
|
7813 |
self synchronizationSemaphore |
|
7814 |
" |
|
7815 |
||
7816 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
7817 |
! |
|
7818 |
||
7819 |
synchronizationSemaphore:aSemaphore |
|
7820 |
"set the synchronisationSemaphore for myself. |
|
7821 |
subclasses may redefine this method" |
|
7822 |
||
7823 |
aSemaphore isNil ifTrue:[ |
|
17757 | 7824 |
"/ remove Semaphore |
7825 |
SynchronizationSemaphores removeKey:self ifAbsent:nil. |
|
5755 | 7826 |
] ifFalse:[ |
17757 | 7827 |
SynchronizationSemaphores at:self put:aSemaphore. |
5755 | 7828 |
]. |
7829 |
||
7830 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
7831 |
! |
|
7832 |
||
7833 |
synchronized:aBlock |
|
7834 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
7835 |
||
6600 | 7836 |
|sema wasBlocked| |
7837 |
||
7838 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5755 | 7839 |
|
7840 |
sema := self synchronizationSemaphore. |
|
7841 |
sema isNil ifTrue:[ |
|
17757 | 7842 |
sema := RecursionLock new name:self className. |
7843 |
self synchronizationSemaphore:sema. |
|
5755 | 7844 |
]. |
7845 |
||
6600 | 7846 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
7211
87f5d25b5c3d
Make synchronizationSemaphore a recursionLock
Stefan Vogel <sv@exept.de>
parents:
7208
diff
changeset
|
7847 |
sema critical:aBlock. |
5755 | 7848 |
|
7849 |
" |
|
7850 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
7851 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
7852 |
" |
|
7853 |
||
7854 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
7855 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
|
7856 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
|
7857 |
! ! |
|
7858 |
||
7859 |
!Object methodsFor:'system primitives'! |
|
7860 |
||
7861 |
asOop |
|
7862 |
"ST-80 compatibility: |
|
7863 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
7864 |
or index); since ST/X has no such thing, and the objects address cannot |
|
10460 | 7865 |
be used (since its changing over time), we return the objects identityHash |
5755 | 7866 |
key, which provides (at least) some identity indication. |
7867 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
7868 |
key of two non-identical objects may be the same. |
|
7869 |
You'd better not use it - especially do not misuse it." |
|
7870 |
||
7871 |
^ self identityHash |
|
7872 |
||
7873 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
7874 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
7875 |
! |
|
7876 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7877 |
beImmutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7878 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7879 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7880 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7881 |
if (! __isNonNilObject(self)) { |
17757 | 7882 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7883 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7884 |
__beImmutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7885 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7886 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7887 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7888 |
beMutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7889 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7890 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7891 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7892 |
if (! __isNonNilObject(self)) { |
17757 | 7893 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7894 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7895 |
__beMutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7896 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7897 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
7898 |
|
5755 | 7899 |
become:anotherObject |
7900 |
"make all references to the receiver become references to anotherObject |
|
7901 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
|
7902 |
This can be a very dangerous operation - be warned. |
|
10460 | 7903 |
In general, using #become: should be avoided if possible, since it may |
5755 | 7904 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
7905 |
||
10460 | 7906 |
This may also be an expensive (i.e. slow) operation, |
7907 |
since in the worst case, the whole memory has to be searched for |
|
5755 | 7908 |
references to the two objects (although the primitive tries hard to |
10460 | 7909 |
limit the search, for acceptable performance in most cases). |
7910 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7911 |
or nil, or is a context of a living method (i.e. one that has not already |
|
5755 | 7912 |
returned). |
10460 | 7913 |
(notice that #become: is not used heavily by the system |
5755 | 7914 |
- the Collection-classes have been rewritten to not use it.)" |
7915 |
%{ |
|
7916 |
if (__primBecome(self, anotherObject)) { |
|
17757 | 7917 |
RETURN ( self ); |
5755 | 7918 |
} |
7919 |
%}. |
|
7920 |
self primitiveFailed |
|
7921 |
! |
|
7922 |
||
7923 |
becomeNil |
|
7924 |
"make all references to the receiver become nil - effectively getting |
|
10460 | 7925 |
rid of the receiver. |
5755 | 7926 |
This can be a very dangerous operation - be warned. |
7927 |
||
7928 |
This may be an expensive (i.e. slow) operation. |
|
7929 |
The receiver may not be a SmallInteger or a context of a living method." |
|
7930 |
||
7931 |
%{ |
|
7932 |
if (__primBecomeNil(self)) { |
|
17757 | 7933 |
RETURN ( nil ); |
5755 | 7934 |
} |
7935 |
%}. |
|
7936 |
self primitiveFailed |
|
7937 |
! |
|
7938 |
||
7939 |
becomeSameAs:anotherObject |
|
7940 |
"make all references to the receiver become references to anotherObject |
|
7941 |
but NOT vice versa (as done in #become:). |
|
7942 |
This can be a very dangerous operation - be warned. |
|
10460 | 7943 |
In general, using #become: should be avoided if possible, since it may |
5755 | 7944 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
7945 |
||
7946 |
This may also be an expensive (i.e. slow) operation, |
|
7947 |
since in the worst case, the whole memory has to be searched for |
|
7948 |
references to the two objects (although the primitive tries hard to |
|
7949 |
limit the search, for acceptable performance in most cases). |
|
7950 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7951 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
7952 |
%{ |
|
7953 |
if (__primBecomeSameAs(self, anotherObject)) { |
|
17757 | 7954 |
RETURN ( self ); |
5755 | 7955 |
} |
7956 |
%}. |
|
7957 |
self primitiveFailed |
|
7958 |
! |
|
7959 |
||
7960 |
changeClassTo:otherClass |
|
7961 |
"changes the class of the receiver to the argument, otherClass. |
|
7962 |
This is only allowed (possible), if the receivers class and the argument |
|
7963 |
have the same structure (i.e. number of named instance variables and |
|
10460 | 7964 |
type of indexed instance variables). |
5755 | 7965 |
If the structures do not match, or any of the original class or new class |
7966 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
7967 |
||
7968 |
|myClass ok| |
|
7969 |
||
9405 | 7970 |
otherClass autoload. |
7971 |
||
5755 | 7972 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
7973 |
%{ |
|
7974 |
{ |
|
17757 | 7975 |
OBJ other = otherClass; |
7976 |
||
7977 |
if (__isNonNilObject(self) |
|
7978 |
&& __isNonNilObject(other) |
|
7979 |
&& (other != UndefinedObject) |
|
7980 |
&& (other != SmallInteger)) { |
|
7981 |
ok = true; |
|
7982 |
} else { |
|
7983 |
ok = false; |
|
7984 |
} |
|
5755 | 7985 |
} |
7986 |
%}. |
|
7987 |
ok ifTrue:[ |
|
17757 | 7988 |
ok := false. |
7989 |
myClass := self class. |
|
7990 |
myClass flags == otherClass flags ifTrue:[ |
|
7991 |
myClass instSize == otherClass instSize ifTrue:[ |
|
7992 |
"same instance layout and types: its ok to do it" |
|
7993 |
ok := true. |
|
7994 |
] ifFalse:[ |
|
7995 |
myClass isPointers ifTrue:[ |
|
7996 |
myClass isVariable ifTrue:[ |
|
7997 |
ok := true |
|
7998 |
] |
|
7999 |
] |
|
8000 |
] |
|
8001 |
] ifFalse:[ |
|
8002 |
myClass isPointers ifTrue:[ |
|
8003 |
"if newClass is a variable class, with instSize <= my instsize, |
|
8004 |
we can do it (effectively mapping additional instvars into the |
|
8005 |
variable part) - usefulness is questionable, though" |
|
8006 |
||
8007 |
otherClass isPointers ifTrue:[ |
|
8008 |
otherClass isVariable ifTrue:[ |
|
8009 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
8010 |
ifTrue:[ |
|
8011 |
ok := true |
|
8012 |
] |
|
8013 |
] ifFalse:[ |
|
8014 |
otherClass instSize == (myClass instSize + self basicSize) |
|
8015 |
ifTrue:[ |
|
8016 |
ok := true |
|
8017 |
] |
|
8018 |
] |
|
8019 |
] ifFalse:[ |
|
8020 |
"it does not make sense to convert pointers to bytes ..." |
|
8021 |
] |
|
8022 |
] ifFalse:[ |
|
8023 |
"does it make sense, to convert bits ?" |
|
8024 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
8025 |
(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[ |
|
8026 |
ok := true |
|
8027 |
] |
|
8028 |
] |
|
8029 |
] |
|
5755 | 8030 |
]. |
8031 |
ok ifTrue:[ |
|
17757 | 8032 |
"now, change the receivers class ..." |
5755 | 8033 |
%{ |
17757 | 8034 |
{ |
8035 |
OBJ me = self; |
|
8036 |
||
8037 |
__qClass(me) = otherClass; |
|
8038 |
__STORE(me, otherClass); |
|
8039 |
RETURN (me); |
|
8040 |
} |
|
5755 | 8041 |
%}. |
8042 |
]. |
|
9405 | 8043 |
|
5755 | 8044 |
" |
8045 |
the receiver cannot be represented as a instance of |
|
8046 |
the desired class. |
|
10460 | 8047 |
For example, you cannot change a bitInstance (byteArray etc.) |
5755 | 8048 |
into a pointer object and vice versa. |
8049 |
" |
|
8050 |
self primitiveFailed |
|
8051 |
! |
|
8052 |
||
8053 |
changeClassToThatOf:anObject |
|
8054 |
"changes the class of the receiver to that of the argument, anObject. |
|
8055 |
This is only allowed (possible), if the receivers class and the arguments |
|
10460 | 8056 |
class have the same structure (i.e. number of named instance variables and |
5755 | 8057 |
type of indexed instance variables). If the structures do not match, or any |
8058 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
8059 |
||
8060 |
self changeClassTo:(anObject class) |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8061 |
! |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8062 |
|
8935 | 8063 |
isImmutable |
8064 |
"experimental - not yet usable; do not use" |
|
8065 |
||
8066 |
%{ /* NOCONTEXT */ |
|
8067 |
if (! __isNonNilObject(self)) { |
|
17757 | 8068 |
RETURN (true); |
8935 | 8069 |
} |
8070 |
RETURN (__isImmutable(self) ? true : false); |
|
8071 |
%} |
|
8072 |
! |
|
8073 |
||
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8074 |
replaceReferencesTo:anObject with:newRef |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8075 |
"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
|
8076 |
Return true, if any reference was changed. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8077 |
Notice: this does not change the class-reference." |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8078 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8079 |
%{ /* NOCONTEXT */ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8080 |
OBJ cls, flags, anyChange; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8081 |
int nInsts, i; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8082 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8083 |
if (! __isNonNilObject(self)) { |
17757 | 8084 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8085 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8086 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8087 |
/* |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8088 |
* a little optimization: use the fact that all old objects |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8089 |
* 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
|
8090 |
* a trivial reject is possible, if anObject is a newbee |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8091 |
*/ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8092 |
if (__isNonNilObject(anObject)) { |
17757 | 8093 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
8094 |
int spc; |
|
8095 |
||
8096 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
8097 |
RETURN (false); |
|
8098 |
} |
|
8099 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8100 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8101 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8102 |
cls = __qClass(self); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8103 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8104 |
flags = __ClassInstPtr(cls)->c_flags; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8105 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
17757 | 8106 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8107 |
} else { |
17757 | 8108 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8109 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8110 |
if (! nInsts) { |
17757 | 8111 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8112 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8113 |
anyChange = false; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8114 |
for (i=0; i<nInsts; i++) { |
17757 | 8115 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
8116 |
__InstPtr(self)->i_instvars[i] = newRef; |
|
8117 |
__STORE(self, newRef); |
|
8118 |
anyChange = true; |
|
8119 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8120 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8121 |
RETURN (anyChange); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8122 |
%}. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8123 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8124 |
" |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8125 |
|v| |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8126 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8127 |
v := Array with:1234 with:'hello' with:Array. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8128 |
v replaceReferencesTo:Array with:ByteArray. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8129 |
v inspect |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8130 |
" |
5755 | 8131 |
! ! |
8132 |
||
8133 |
!Object methodsFor:'testing'! |
|
8134 |
||
8135 |
? defaultValue |
|
11634 | 8136 |
"a syntactic sugar-piece: |
5755 | 8137 |
if the receiver is nil, return the defaultValue; |
8138 |
otherwise, return the receiver. |
|
8139 |
This method is only redefined in UndefinedObject - therefore, |
|
8140 |
the recevier is retuned here. |
|
8141 |
||
8142 |
Thus, if foo and bar are simple variables or constants, |
|
11634 | 8143 |
foo ? bar |
5755 | 8144 |
is the same as: |
11634 | 8145 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
5755 | 8146 |
|
8147 |
if they are message sends, the equivalent code is: |
|
11634 | 8148 |
[ |
8149 |
|t1 t2| |
|
8150 |
||
8151 |
t1 := foo. |
|
8152 |
t2 := bar. |
|
8153 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
8154 |
] value |
|
5755 | 8155 |
|
8156 |
Can be used to provide defaultValues to variables, |
|
8157 |
as in: |
|
11634 | 8158 |
foo := arg ? #defaultValue |
5755 | 8159 |
|
8160 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8161 |
Notice: |
|
11634 | 8162 |
This method is open coded (inlined) by the compiler(s) |
8163 |
- redefining it may not work as expected." |
|
5755 | 8164 |
|
8165 |
^ self |
|
8166 |
||
8167 |
" |
|
8168 |
1 ? #default |
|
8169 |
nil ? #default |
|
8170 |
" |
|
8171 |
||
8172 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8173 |
"Modified: / 19.5.1998 / 17:39:56 / cg" |
|
8174 |
! |
|
8175 |
||
8176 |
?? defaultValue |
|
11634 | 8177 |
"a syntactic sugar-piece: |
5755 | 8178 |
much like ?, but sends #value to the argument if required. |
8179 |
(i.e. its the same as #ifNil:) |
|
8180 |
If the receiver is nil, return the defaultValues value; |
|
8181 |
otherwise, return the receiver. |
|
8182 |
This method is only redefined in UndefinedObject - therefore, |
|
8183 |
the recevier is retuned here. |
|
8184 |
||
8185 |
Thus, if foo and bar are simple variables or constants, |
|
11634 | 8186 |
foo ?? bar |
5755 | 8187 |
is the same as: |
11634 | 8188 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
5755 | 8189 |
|
8190 |
if they are message sends, the equivalent code is: |
|
11634 | 8191 |
[ |
8192 |
|t t2| |
|
8193 |
||
8194 |
t := foo. |
|
8195 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
8196 |
] value |
|
5755 | 8197 |
|
8198 |
Can be used to provide defaultValues to variables, |
|
8199 |
as in: |
|
11634 | 8200 |
foo := arg ?? [ self computeDefault ] |
5755 | 8201 |
|
8202 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8203 |
" |
|
8204 |
||
8205 |
^ self |
|
8206 |
||
8207 |
" |
|
10460 | 8208 |
1 ?? #default |
5755 | 8209 |
nil ?? #default |
10460 | 8210 |
1 ?? [ self halt. 1 + 2 ] |
8211 |
nil ?? [ self halt. 1 + 2 ] |
|
8212 |
1 ?? [Date today] |
|
8213 |
nil ?? [Date today] |
|
5755 | 8214 |
" |
8215 |
||
8216 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
8217 |
"Modified: / 19.5.1998 / 17:42:56 / cg" |
|
8218 |
! |
|
8219 |
||
8220 |
ifNil:aBlockOrValue |
|
8221 |
"return myself, or the result from evaluating the argument, if I am nil. |
|
8222 |
This is much like #?, but sends #value to the argument in case of a nil |
|
8223 |
receiver. |
|
8224 |
Notice: |
|
17757 | 8225 |
This method is open coded (inlined) by the compiler(s) |
8226 |
- redefining it may not work as expected." |
|
5755 | 8227 |
|
8228 |
^ self |
|
8229 |
! |
|
8230 |
||
8231 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
|
8232 |
"return the value of the first arg, if I am nil, |
|
8233 |
the result from evaluating the 2nd argument, if I am not nil. |
|
8234 |
Notice: |
|
17757 | 8235 |
This method is open coded (inlined) by the compiler(s) |
8236 |
- redefining it may not work as expected." |
|
5755 | 8237 |
|
8238 |
^ notNilBlockOrValue value |
|
8239 |
||
8240 |
! |
|
8241 |
||
8242 |
ifNotNil:aBlockOrValue |
|
10460 | 8243 |
"return myself if nil, or the result from evaluating the argument, |
5755 | 8244 |
if I am not nil. |
8245 |
Notice: |
|
17757 | 8246 |
This method is open coded (inlined) by the compiler(s) |
8247 |
- redefining it may not work as expected." |
|
5755 | 8248 |
|
8249 |
^ aBlockOrValue value |
|
8250 |
||
8251 |
! |
|
8252 |
||
8253 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
|
8254 |
"return the value of the 2nd arg, if I am nil, |
|
8255 |
the result from evaluating the 1st argument, if I am not nil. |
|
8256 |
Notice: |
|
17757 | 8257 |
This method is open coded (inlined) by the compiler(s) |
8258 |
- redefining it may not work as expected." |
|
5755 | 8259 |
|
8260 |
^ notNilBlockOrValue value |
|
8261 |
||
8262 |
||
8263 |
! |
|
8264 |
||
8574 | 8265 |
ifNotNilDo:aBlock |
8266 |
"if the reciever is non-nil, return the value of aBlock, passing myself as argument. |
|
8267 |
Otherwise do nothing and return nil." |
|
8268 |
||
8269 |
^ aBlock value:self |
|
8270 |
! |
|
8271 |
||
5755 | 8272 |
isArray |
8273 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
8274 |
false is returned here - the method is only redefined in Array." |
|
8275 |
||
8276 |
^ false |
|
8277 |
! |
|
8278 |
||
8279 |
isAssociation |
|
8280 |
"return true, if the receiver is some kind of association; |
|
8281 |
false is returned here - the method is only redefined in Association." |
|
8282 |
||
8283 |
^ false |
|
8284 |
||
8285 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
8286 |
! |
|
8287 |
||
8288 |
isBehavior |
|
9221 | 8289 |
"return true, if the receiver is describing another objects behavior. |
8290 |
False is returned here - the method is only redefined in Behavior." |
|
5755 | 8291 |
|
8292 |
^ false |
|
8293 |
! |
|
8294 |
||
8295 |
isBlock |
|
8296 |
"return true, if the receiver is some kind of block; |
|
8297 |
false returned here - the method is only redefined in Block." |
|
8298 |
||
8299 |
^ false |
|
8300 |
! |
|
8301 |
||
5824 | 8302 |
isBoolean |
8303 |
"return true, if the receiver is a boolean; |
|
8304 |
false is returned here - the method is only redefined in Boolean." |
|
8305 |
||
8306 |
^ false |
|
8307 |
! |
|
8308 |
||
5755 | 8309 |
isByteArray |
8310 |
"return true, if the receiver is some kind of bytearray; |
|
8311 |
false is returned here - the method is only redefined in ByteArray." |
|
8312 |
||
8313 |
^ false |
|
8314 |
! |
|
8315 |
||
8986 | 8316 |
isByteCollection |
8317 |
"return true, if the receiver is some kind of byte collection, |
|
10460 | 8318 |
i.e. #at: and #at:put: accesses a byte. This is different from 'self class isBytes', |
8986 | 8319 |
since e.g. in BitArray single bits are accessed, but it is implemented as variableBytes class. |
10460 | 8320 |
|
8986 | 8321 |
false is returned here - the method is only redefined in UninterpretedBytes." |
8322 |
||
8323 |
^ false |
|
8324 |
! |
|
8325 |
||
5755 | 8326 |
isCharacter |
8327 |
"return true, if the receiver is some kind of character; |
|
8328 |
false is returned here - the method is only redefined in Character." |
|
8329 |
||
8330 |
^ false |
|
8331 |
! |
|
8332 |
||
8333 |
isClass |
|
9405 | 8334 |
"return true, if the receiver is some kind of class |
8335 |
(real class, not just behavior); |
|
5755 | 8336 |
false is returned here - the method is only redefined in Class." |
8337 |
||
8338 |
^ false |
|
8339 |
! |
|
8340 |
||
8341 |
isCollection |
|
8342 |
"return true, if the receiver is some kind of collection; |
|
8343 |
false is returned here - the method is only redefined in Collection." |
|
8344 |
||
8345 |
^ false |
|
8346 |
! |
|
8347 |
||
8348 |
isColor |
|
8349 |
"return true, if the receiver is some kind of color; |
|
8350 |
false is returned here - the method is only redefined in Color." |
|
8351 |
||
8352 |
^ false |
|
8353 |
! |
|
8354 |
||
6567 | 8355 |
isCons |
8356 |
"return true, if the receiver is a cons (pair); |
|
8357 |
false is returned here - the method is only redefined in Cons." |
|
8358 |
||
8359 |
^ false |
|
8360 |
! |
|
8361 |
||
5755 | 8362 |
isContext |
8363 |
"return true, if the receiver is some kind of context; |
|
8364 |
false returned here - the method is only redefined in Context." |
|
8365 |
||
8366 |
^ false |
|
8367 |
! |
|
8368 |
||
6181 | 8369 |
isEmptyOrNil |
8833 | 8370 |
"return true if I am nil or an empty collection - return false here. |
8371 |
(from Squeak)" |
|
6181 | 8372 |
|
8373 |
^ false |
|
8374 |
||
8375 |
"Created: / 13.11.2001 / 13:17:04 / cg" |
|
6182 | 8376 |
"Modified: / 13.11.2001 / 13:28:40 / cg" |
6181 | 8377 |
! |
8378 |
||
6221 | 8379 |
isException |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8380 |
"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
|
8381 |
|
6221 | 8382 |
^ false |
8383 |
||
8384 |
"Created: / 17.11.2001 / 18:37:44 / cg" |
|
8385 |
! |
|
8386 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8387 |
isExceptionCreator |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8388 |
"return true, if the receiver can create exceptions, |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8389 |
this includes #raise, #raiseRequest as well as the behavior of |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8390 |
an exception handler, such as the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8391 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8392 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8393 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8394 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8395 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8396 |
"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
|
8397 |
especially to the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8398 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8399 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8400 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8401 |
|
10480 | 8402 |
isExternalLibraryFunction |
8403 |
"return true, if the receiver is some kind of externalLibrary function; |
|
8404 |
false is returned here - the method is only redefined in ExternalLibraryFunction." |
|
8405 |
||
8406 |
^false |
|
8407 |
! |
|
8408 |
||
5755 | 8409 |
isExternalStream |
8410 |
"return true, if the receiver is some kind of externalStream; |
|
8411 |
false is returned here - the method is only redefined in ExternalStream." |
|
8412 |
||
8413 |
^false |
|
8414 |
! |
|
8415 |
||
8416 |
isFileStream |
|
8417 |
"return true, if the receiver is some kind of fileStream; |
|
8418 |
false is returned here - the method is only redefined in FileStream." |
|
8419 |
||
8420 |
^false |
|
8421 |
! |
|
8422 |
||
8423 |
isFilename |
|
8424 |
"return true, if the receiver is some kind of filename; |
|
8425 |
false is returned here - the method is only redefined in Filename." |
|
8426 |
||
8427 |
^false |
|
8428 |
! |
|
8429 |
||
8430 |
isFixedPoint |
|
8431 |
"return true, if the receiver is some kind of fixedPoint number; |
|
8432 |
false is returned here - the method is only redefined in FixedPoint." |
|
8433 |
||
8434 |
^ false |
|
8435 |
||
8436 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
8437 |
! |
|
8438 |
||
8439 |
isFixedSize |
|
10460 | 8440 |
"return true if the receiver cannot grow easily |
5755 | 8441 |
(i.e. a grow may be expensive, since it involves a become:)" |
8442 |
||
8443 |
^ true |
|
8444 |
! |
|
8445 |
||
6185 | 8446 |
isFloat |
8447 |
"return true, if the receiver is some kind of floating point number; |
|
8448 |
false is returned here. |
|
8449 |
Same as #isLimitedPrecisionReal, but a better name ;-)" |
|
8450 |
||
8451 |
^ false |
|
8452 |
||
8453 |
"Modified: / 14.11.2001 / 14:57:46 / cg" |
|
8454 |
! |
|
8455 |
||
5755 | 8456 |
isForm |
8457 |
"return true, if the receiver is some kind of form; |
|
8458 |
false is returned here - the method is only redefined in Form." |
|
8459 |
||
8460 |
^ false |
|
8461 |
! |
|
8462 |
||
8463 |
isFraction |
|
8464 |
"return true, if the receiver is some kind of fraction; |
|
8465 |
false is returned here - the method is only redefined in Fraction." |
|
8466 |
||
8467 |
^ false |
|
8468 |
! |
|
8469 |
||
9293 | 8470 |
isHierarchicalItem |
8471 |
"used to decide if the parent is a hierarchical item or the model" |
|
8472 |
||
8473 |
^ false |
|
8474 |
! |
|
8475 |
||
5755 | 8476 |
isImage |
8477 |
"return true, if the receiver is some kind of image; |
|
8478 |
false is returned here - the method is only redefined in Image." |
|
8479 |
||
8480 |
^ false |
|
8481 |
! |
|
8482 |
||
8483 |
isImageOrForm |
|
8484 |
"return true, if the receiver is some kind of image or form; |
|
8485 |
false is returned here - the method is only redefined in Image and Form." |
|
8486 |
||
8487 |
^ false |
|
8488 |
! |
|
8489 |
||
8490 |
isImmediate |
|
8491 |
"return true if I am an immediate object |
|
8492 |
i.e. I am represented in the pointer itself and |
|
8493 |
no real object header/storage is used me. |
|
8494 |
(currently, only SmallIntegers, some characters and nil return true)" |
|
8495 |
||
8496 |
^ self class hasImmediateInstances |
|
8497 |
||
8498 |
"Created: 3.6.1997 / 12:00:18 / cg" |
|
8499 |
! |
|
8500 |
||
8501 |
isInteger |
|
8502 |
"return true, if the receiver is some kind of integer number; |
|
8503 |
false is returned here - the method is only redefined in Integer." |
|
8504 |
||
8505 |
^ false |
|
8506 |
! |
|
8507 |
||
9279 | 8508 |
isInterestConverter |
8509 |
"return true if I am a kind of interest forwarder" |
|
8510 |
||
8511 |
^ false |
|
8512 |
! |
|
8513 |
||
10576 | 8514 |
isInternalByteStream |
8515 |
"return true, if the receiver is some kind of Stream for reading bytes; |
|
8516 |
false is returned here - the method is only redefined in PeekableStream." |
|
8517 |
||
8518 |
^false |
|
8519 |
||
8520 |
"Created: / 30-05-2007 / 16:15:33 / cg" |
|
8521 |
! |
|
8522 |
||
5755 | 8523 |
isJavaClass |
8524 |
"return true, if this is a javaClass. |
|
8525 |
false is returned here - the method is only redefined in JavaClass." |
|
8526 |
||
8527 |
^ false |
|
8528 |
||
8529 |
"Created: / 26.3.1997 / 13:34:54 / cg" |
|
8530 |
"Modified: / 8.5.1998 / 21:25:21 / cg" |
|
8531 |
! |
|
8532 |
||
8533 |
isJavaClassRef |
|
8534 |
"return true, if this is a JavaClassRef. |
|
8535 |
false is returned here - the method is only redefined in JavaClassRef." |
|
8536 |
||
8537 |
^ false |
|
8538 |
||
8539 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8540 |
"Created: / 24.12.1999 / 01:46:28 / cg" |
|
8541 |
! |
|
8542 |
||
8543 |
isJavaContext |
|
8544 |
"return true, if this is a javaContext. |
|
8545 |
false is returned here - the method is only redefined in JavaContext." |
|
8546 |
||
8547 |
^ false |
|
8548 |
||
8549 |
"Created: / 8.5.1998 / 21:24:27 / cg" |
|
8550 |
"Modified: / 8.5.1998 / 21:25:35 / cg" |
|
8551 |
! |
|
8552 |
||
8553 |
isJavaMethod |
|
8554 |
"return true, if this is a JavaMethod. |
|
8555 |
false is returned here - the method is only redefined in JavaMethod." |
|
8556 |
||
8557 |
^ false |
|
8558 |
||
8559 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8560 |
"Created: / 25.9.1999 / 23:26:12 / cg" |
|
8561 |
! |
|
8562 |
||
8563 |
isJavaMethodRef |
|
8564 |
"return true, if this is a JavaMethodRef. |
|
8565 |
false is returned here - the method is only redefined in JavaMethodRef." |
|
8566 |
||
8567 |
^ false |
|
8568 |
||
8569 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8570 |
"Created: / 23.12.1999 / 19:44:51 / cg" |
|
8571 |
! |
|
8572 |
||
8573 |
isJavaObject |
|
8574 |
"return true, if this is a javaObject. |
|
8575 |
false is returned here - the method is only redefined in JavaObject." |
|
8576 |
||
8577 |
^ false |
|
8578 |
||
8579 |
"Created: / 26.3.1997 / 13:34:48 / cg" |
|
8580 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
8581 |
! |
|
8582 |
||
8583 |
isJavaScriptClass |
|
8584 |
"return true, if this is a javaScriptClass. |
|
8585 |
false is returned here - the method is only redefined in JavaScriptClass." |
|
8586 |
||
8587 |
^ false |
|
8588 |
! |
|
8589 |
||
8935 | 8590 |
isJavaScriptMetaclass |
8591 |
"return true, if this is a javaScript Metaclass. |
|
8592 |
false is returned here - the method is only redefined in JavaScriptMetaclass." |
|
8593 |
||
8594 |
^ false |
|
8595 |
! |
|
8596 |
||
5755 | 8597 |
isKindOf:aClass |
8598 |
"return true, if the receiver is an instance of aClass or one of its |
|
8599 |
subclasses, false otherwise. |
|
10460 | 8600 |
Advice: |
17757 | 8601 |
use of this to check objects for certain attributes/protocoll should |
8602 |
be avoided; it limits the reusability of your classes by limiting use |
|
8603 |
to instances of certain classes and fences you into a specific inheritance |
|
8604 |
hierarchy. |
|
8605 |
Use check-methods to check an object for a certain attributes/protocol |
|
8606 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
8607 |
||
8608 |
Using #isKindOf: is considered BAD STYLE. |
|
5755 | 8609 |
|
8610 |
Advice2: |
|
17757 | 8611 |
Be aware, that using an #isXXX method is usually much faster than |
8612 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
8613 |
hierarchy, comparing every class on the way. |
|
8614 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
8615 |
a single function call. |
|
5755 | 8616 |
" |
8617 |
||
8618 |
%{ /* NOCONTEXT */ |
|
8619 |
register OBJ thisClass; |
|
8620 |
||
8621 |
thisClass = __Class(self); |
|
8622 |
while (thisClass != nil) { |
|
17757 | 8623 |
if (thisClass == aClass) { |
8624 |
RETURN ( true ); |
|
8625 |
} |
|
8626 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
5755 | 8627 |
} |
8628 |
RETURN ( false ); |
|
8629 |
%} |
|
8630 |
||
8631 |
"/ |
|
8632 |
"/ the above code is equivalent to: |
|
8633 |
"/ |
|
8634 |
"/ thisClass := self class. |
|
8635 |
"/ [thisClass notNil] whileTrue:[ |
|
8636 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
8637 |
"/ thisClass := thisClass superclass |
|
8638 |
"/ ]. |
|
8639 |
"/ ^ false |
|
8640 |
"/ |
|
8641 |
||
8642 |
! |
|
8643 |
||
8644 |
isLayout |
|
8645 |
"return true, if the receiver is some kind of layout; |
|
8646 |
false is returned here - the method is only redefined in Layout." |
|
8647 |
||
8648 |
^ false |
|
8649 |
! |
|
8650 |
||
6567 | 8651 |
isLazyValue |
8652 |
^ false |
|
8653 |
! |
|
8654 |
||
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8655 |
isLimitedPrecisionReal |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8656 |
"return true, if the receiver is some kind of floating point number; |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8657 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8658 |
|
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8659 |
^ false |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8660 |
! |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
8661 |
|
5755 | 8662 |
isList |
8663 |
"return true, if the receiver is some kind of list collection; |
|
8664 |
false is returned here - the method is only redefined in List." |
|
8665 |
||
8666 |
^ false |
|
8667 |
||
8668 |
"Created: / 11.2.2000 / 01:37:05 / cg" |
|
8669 |
! |
|
8670 |
||
8671 |
isLiteral |
|
8672 |
"return true, if the receiver can be represented as a literal constant in ST syntax; |
|
8673 |
false is returned here - the method is redefined in some classes." |
|
8674 |
||
8675 |
^ false |
|
8676 |
! |
|
8677 |
||
8678 |
isMemberOf:aClass |
|
8679 |
"return true, if the receiver is an instance of aClass, false otherwise. |
|
10460 | 8680 |
Advice: |
17757 | 8681 |
use of this to check objects for certain attributes/protocol should |
8682 |
be avoided; it limits the reusability of your classes by limiting use |
|
8683 |
to instances of a certain class. |
|
8684 |
Use check-methods to check an object for a certain attributes/protocol |
|
8685 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
8686 |
||
8687 |
Using #isMemberOf: is considered BAD STYLE. |
|
5755 | 8688 |
Notice: |
17757 | 8689 |
This method is open coded (inlined) by the compiler(s) |
8690 |
- redefining it may not work as expected." |
|
5755 | 8691 |
|
8692 |
^ (self class) == aClass |
|
8693 |
! |
|
8694 |
||
8695 |
isMeta |
|
8696 |
"return true, if the receiver is some kind of metaclass; |
|
8697 |
false is returned here - the method is only redefined in Metaclass." |
|
8698 |
||
8699 |
^ false |
|
8700 |
! |
|
8701 |
||
8702 |
isMethod |
|
8703 |
"return true, if the receiver is some kind of method; |
|
8704 |
false returned here - the method is only redefined in Method." |
|
8705 |
||
8706 |
^ false |
|
8707 |
! |
|
8708 |
||
8709 |
isMorph |
|
8710 |
"return true, if the receiver is some kind of morph; |
|
8711 |
false is returned here - the method is only redefined in Morph." |
|
8712 |
||
8713 |
^ false |
|
8714 |
! |
|
8715 |
||
8716 |
isNameSpace |
|
9221 | 8717 |
"return true, if the receiver is a nameSpace. |
8718 |
False is returned here - the method is only redefined in Namespace." |
|
5755 | 8719 |
|
8720 |
^ false |
|
8721 |
||
8722 |
"Created: / 11.10.1996 / 18:08:56 / cg" |
|
8723 |
"Modified: / 8.5.1998 / 21:26:05 / cg" |
|
8724 |
! |
|
8725 |
||
8726 |
isNamespace |
|
8727 |
"return true, if this is a nameSpace. |
|
8728 |
false is returned here - the method is only redefined in Namespace." |
|
8729 |
||
5869 | 8730 |
<resource:#obsolete> |
8731 |
||
5755 | 8732 |
self obsoleteMethodWarning:'use #isNameSpace'. |
6805 | 8733 |
^ self isNameSpace |
5755 | 8734 |
! |
8735 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8736 |
isNil |
9221 | 8737 |
"Return true, if the receiver is nil. |
8738 |
Because isNil is redefined in UndefinedObject, |
|
8739 |
the receiver is definitely not nil here, so unconditionally return false. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8740 |
Notice: |
17757 | 8741 |
This method is open coded (inlined) by the compiler(s) |
8742 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8743 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8744 |
^ false |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8745 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8746 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8747 |
isNilOrEmptyCollection |
6182 | 8748 |
"return true if I am nil or an empty collection - false here. |
8833 | 8749 |
Obsolete, use isEmptyOrNil." |
8750 |
||
8751 |
<resource:#obsolete> |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8752 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8753 |
^ false |
6182 | 8754 |
|
8755 |
"Modified: / 13.11.2001 / 13:28:06 / cg" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8756 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8757 |
|
9005 | 8758 |
isNonByteCollection |
8759 |
"return true, if the receiver is some kind of collection, but not a String, ByteArray etc.; |
|
8760 |
false is returned here - the method is redefined in Collection and UninterpretedBytes." |
|
8761 |
||
8762 |
^ false |
|
8763 |
||
8764 |
" |
|
17757 | 8765 |
21 isNonByteCollection |
8766 |
'abc' isNonByteCollection |
|
8767 |
#'abc' isNonByteCollection |
|
8768 |
#[1 2 3] isNonByteCollection |
|
8769 |
#(1 2 3) isNonByteCollection |
|
9005 | 8770 |
" |
8771 |
! |
|
8772 |
||
5755 | 8773 |
isNumber |
8774 |
"return true, if the receiver is some kind of number; |
|
8775 |
false is returned here - the method is only redefined in Number." |
|
8776 |
||
8777 |
^ false |
|
8778 |
! |
|
8779 |
||
8780 |
isOrderedCollection |
|
8781 |
"return true, if the receiver is some kind of ordered collection (or list etc); |
|
8782 |
false is returned here - the method is only redefined in OrderedCollection." |
|
8783 |
||
8784 |
^ false |
|
8785 |
! |
|
8786 |
||
8787 |
isPoint |
|
8788 |
"return true, if the receiver is some kind of point; |
|
8789 |
false is returned here - the method is only redefined in Point." |
|
8790 |
||
8791 |
^ false |
|
8792 |
! |
|
8793 |
||
10532 | 8794 |
isPrinterContext |
8795 |
||
8796 |
^false |
|
8797 |
! |
|
8798 |
||
17786 | 8799 |
isProgrammingLanguage |
8800 |
"return true, if the receiver is a programming language. |
|
8801 |
False is returned here - the method is only redefined in |
|
8802 |
ProgrammingLanguage." |
|
8803 |
||
8804 |
^ false |
|
8805 |
||
8806 |
"Created: / 21-07-2010 / 15:13:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
8807 |
! |
|
8808 |
||
9515 | 8809 |
isProjectDefinition |
8810 |
"return true, if the receiver is a projectDefinition. |
|
8811 |
False is returned here - the method is only redefined in ProjectDefinition." |
|
8812 |
||
8813 |
^ false |
|
8814 |
||
8815 |
"Created: / 10-08-2006 / 16:24:53 / cg" |
|
8816 |
! |
|
8817 |
||
10171 | 8818 |
isRealNameSpace |
8819 |
"return true, if the receiver is really a nameSpace (i.e. a NameSpace, but not Smalltalk). |
|
8820 |
False is returned here - the method is only redefined in Namespace." |
|
8821 |
||
8822 |
^ false |
|
8823 |
||
8824 |
"Created: / 10-11-2006 / 17:05:43 / cg" |
|
8825 |
! |
|
8826 |
||
5755 | 8827 |
isRectangle |
8828 |
"return true, if the receiver is some kind of rectangle; |
|
8829 |
false is returned here - the method is only redefined in Rectangle." |
|
8830 |
||
8831 |
^ false |
|
8832 |
! |
|
8833 |
||
8834 |
isRemoteObject |
|
8835 |
"return true, if the receiver is some kind of remoteObject, |
|
8836 |
false if its local - the method is only redefined in RemoteObject." |
|
8837 |
||
8838 |
^ false |
|
8839 |
||
8840 |
"Created: 28.10.1996 / 15:18:45 / cg" |
|
8841 |
"Modified: 28.10.1996 / 15:20:57 / cg" |
|
8842 |
! |
|
8843 |
||
8844 |
isSequenceable |
|
8845 |
"return true, if the receiver is some kind of sequenceable collection; |
|
8846 |
false is returned here - the method is only redefined in SequenceableCollection." |
|
8847 |
||
8848 |
^ false |
|
8849 |
! |
|
8850 |
||
8851 |
isSequenceableCollection |
|
8852 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
8853 |
This method is a historic leftover and will be removed soon ... |
|
8854 |
(although its name is much better than #isSequenceable - sigh)" |
|
8855 |
||
5869 | 8856 |
<resource:#obsolete> |
8857 |
||
5755 | 8858 |
self obsoleteMethodWarning:'use #isSequenceable'. |
8859 |
^ false |
|
8860 |
! |
|
8861 |
||
10856 | 8862 |
isSharedPool |
8863 |
"return true, if the receiver is a sharedPool. |
|
8864 |
False is returned here - the method is only redefined in SharedPool." |
|
8865 |
||
8866 |
^ false |
|
8867 |
! |
|
8868 |
||
5755 | 8869 |
isStream |
8870 |
"return true, if the receiver is some kind of stream; |
|
8871 |
false is returned here - the method is only redefined in Stream." |
|
8872 |
||
8873 |
^ false |
|
8874 |
! |
|
8875 |
||
8876 |
isString |
|
8877 |
"return true, if the receiver is some kind of string; |
|
8878 |
false is returned here - the method is only redefined in CharacterArray." |
|
8879 |
||
8880 |
^ false |
|
8881 |
! |
|
8882 |
||
8883 |
isStringCollection |
|
8884 |
"return true, if the receiver is some kind of stringCollection; |
|
8885 |
false is returned here - the method is only redefined in StringCollection." |
|
8886 |
||
8887 |
^ false |
|
8888 |
! |
|
8889 |
||
8890 |
isSymbol |
|
8891 |
"return true, if the receiver is some kind of symbol; |
|
8892 |
false is returned here - the method is only redefined in Symbol." |
|
8893 |
||
8894 |
^ false |
|
8895 |
! |
|
8896 |
||
8897 |
isText |
|
8898 |
"return true, if the receiver is some kind of text object; |
|
8899 |
false is returned here - the method is only redefined in Text." |
|
8900 |
||
8901 |
^ false |
|
8902 |
||
8903 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
8904 |
! |
|
8905 |
||
8906 |
isValueModel |
|
8907 |
"return true, if the receiver is some kind of valueModel; |
|
8908 |
false is returned here - the method is only redefined in ValueModel." |
|
8909 |
||
8910 |
^ false |
|
8911 |
||
8912 |
! |
|
8913 |
||
8914 |
isVariable |
|
8915 |
"return true if the receiver has indexed instance variables, |
|
8916 |
false otherwise." |
|
8917 |
||
8918 |
^ self class isVariable |
|
8919 |
! |
|
8920 |
||
8921 |
isVariableBinding |
|
8922 |
"return true, if this is a binding for a variable. |
|
8923 |
false is returned here - the method is only redefined in Binding." |
|
8924 |
||
8925 |
^ false |
|
8926 |
||
8927 |
"Created: / 19.6.1997 / 17:38:44 / cg" |
|
8928 |
"Modified: / 8.5.1998 / 21:26:55 / cg" |
|
8929 |
! |
|
8930 |
||
8931 |
isView |
|
8932 |
"return true, if the receiver is some kind of view; |
|
8933 |
false is returned here - the method is only redefined in View." |
|
8934 |
||
8935 |
^ false |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8936 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8937 |
|
6932 | 8938 |
notEmptyOrNil |
8939 |
"Squeak compatibility: |
|
8940 |
return true if I am neither nil nor an empty collection. |
|
8941 |
Return true here." |
|
8942 |
||
8943 |
^ true |
|
8944 |
! |
|
8945 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8946 |
notNil |
9221 | 8947 |
"Return true, if the receiver is not nil. |
8948 |
Because notNil is redefined in UndefinedObject, |
|
8949 |
the receiver is definitely not nil here, so unconditionally return true. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8950 |
Notice: |
17757 | 8951 |
This method is open coded (inlined) by the compiler(s) |
8952 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8953 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
8954 |
^ true |
5755 | 8955 |
! ! |
8956 |
||
8957 |
!Object methodsFor:'tracing'! |
|
8958 |
||
8959 |
traceInto:aRequestor level:level from:referrer |
|
8960 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
8961 |
||
8962 |
^ aRequestor traceObject:self level:level from:referrer |
|
8963 |
||
8964 |
"Created: / 2.9.1999 / 09:05:17 / stefan" |
|
8965 |
! ! |
|
8966 |
||
8967 |
!Object methodsFor:'user interaction & notifications'! |
|
8968 |
||
8969 |
activityNotification:aString |
|
8970 |
"this can be sent from deeply nested methods, which are going to perform |
|
8971 |
some long-time activity. |
|
8972 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
8973 |
passing the argument. The handler should show this message whereever it likes, |
|
8974 |
and proceed. If there is no handler, this is simply ignored. |
|
8975 |
||
8976 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
8977 |
which likes to display that message in its label or a busy-box. |
|
8978 |
It could also be put into some logfile or printed on the standard output/error." |
|
8979 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8980 |
ActivityNotification isHandled ifTrue:[ |
17757 | 8981 |
^ ActivityNotification raiseRequestWith:self errorString:aString |
5755 | 8982 |
]. |
8983 |
||
8984 |
" |
|
8985 |
nil activityNotification:'hello there' |
|
8986 |
self activityNotification:'hello there' |
|
8987 |
" |
|
8988 |
||
8989 |
" |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
8990 |
ActivityNotification handle:[:ex | |
17757 | 8991 |
ex errorString printCR. |
8992 |
ex proceed. |
|
5755 | 8993 |
] do:[ |
17757 | 8994 |
'hello' printCR. |
8995 |
self activityNotification:'doing some long time computation'. |
|
8996 |
'world' printCR. |
|
5755 | 8997 |
] |
8998 |
" |
|
8999 |
||
9000 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
9001 |
! |
|
9002 |
||
9003 |
confirm:aString |
|
9694 | 9004 |
"open a modal yes-no dialog. |
9005 |
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
|
9006 |
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
|
9007 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9008 |
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
|
9009 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9010 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9011 |
^ UserConfirmation raiseRequestErrorString:aString |
10460 | 9012 |
|
5755 | 9013 |
" |
9014 |
nil confirm:'hello' |
|
9015 |
self confirm:'hello' |
|
9016 |
" |
|
9017 |
! |
|
9018 |
||
9019 |
confirm:aString orCancel:cancelBlock |
|
9020 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
9021 |
return true for yes, false for no, or the value from cancelBlock for cancel. |
|
9022 |
If no GUI is present (headless applications), cancelBlock is returned." |
|
9023 |
||
9024 |
|answer| |
|
9025 |
||
9026 |
answer := self confirmWithCancel:aString. |
|
9027 |
answer isNil ifTrue:[ |
|
17757 | 9028 |
^ cancelBlock value |
5755 | 9029 |
]. |
9030 |
^ answer |
|
10460 | 9031 |
|
5755 | 9032 |
" |
9033 |
self confirm:'hello' orCancel:[self halt] |
|
9034 |
" |
|
9035 |
||
9036 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
9037 |
! |
|
9038 |
||
9039 |
confirmWithCancel:aString |
|
9040 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
9041 |
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
|
9042 |
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
|
9043 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9044 |
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
|
9045 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
9046 |
|
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9047 |
^ self confirmWithCancel:aString defaultAnswer:nil |
10460 | 9048 |
|
9049 |
" |
|
9050 |
nil confirmWithCancel:'hello' |
|
5755 | 9051 |
self confirmWithCancel:'hello' |
9052 |
" |
|
9053 |
! |
|
9054 |
||
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9055 |
confirmWithCancel:aString defaultAnswer:defaultAnswerOrNil |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9056 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9057 |
return true for yes, false for no, nil for cancel. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9058 |
If no GUI is present (headless applications), nil is returned. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9059 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9060 |
Someone in the sender chain may redefine the confirmation handler |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9061 |
by handling the UserConfirmation." |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9062 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9063 |
^ UserConfirmation new |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9064 |
defaultAnswer:defaultAnswerOrNil; |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9065 |
canCancel:true; |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9066 |
errorString:aString; |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9067 |
raiseRequest |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9068 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9069 |
" |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9070 |
nil confirmWithCancel:'hello' defaultAnswer:true |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9071 |
self confirmWithCancel:'hello' defaultAnswer:false |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9072 |
" |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9073 |
! |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
9074 |
|
5755 | 9075 |
errorNotify:aString |
9076 |
"launch a Notifier, showing top stack, telling user something |
|
9077 |
and give user a chance to enter debugger." |
|
9078 |
||
9079 |
^ self |
|
17757 | 9080 |
errorNotify:aString |
9081 |
from:thisContext sender |
|
9082 |
allowDebug:true |
|
5755 | 9083 |
|
9084 |
" |
|
9085 |
nil errorNotify:'hello there' |
|
9086 |
self errorNotify:'hello there' |
|
9087 |
" |
|
9088 |
||
6199 | 9089 |
"Modified: / 16.11.2001 / 15:36:49 / cg" |
5755 | 9090 |
! |
9091 |
||
9092 |
errorNotify:aString from:aContext |
|
10460 | 9093 |
"launch a Notifier, showing top stack (above aContext), |
5755 | 9094 |
telling user something and give user a chance to enter debugger." |
9095 |
||
9096 |
^ self errorNotify:aString from:aContext allowDebug:true |
|
9097 |
||
9098 |
"Modified: / 17.8.1998 / 10:09:27 / cg" |
|
9099 |
! |
|
9100 |
||
9101 |
errorNotify:aString from:aContext allowDebug:allowDebug |
|
10460 | 9102 |
"launch a Notifier, showing top stack (above aContext), |
5755 | 9103 |
telling user something and optionally give the user a chance to enter debugger." |
9104 |
||
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
9105 |
|currentScreen con sender action boxLabels boxValues default s| |
5755 | 9106 |
|
9107 |
Smalltalk isInitialized ifFalse:[ |
|
11531 | 9108 |
'errorNotification: ' print. aString printCR. |
11541 | 9109 |
aContext sender printAllLevels:10. |
11530 | 9110 |
^ nil |
10460 | 9111 |
]. |
11531 | 9112 |
|
10460 | 9113 |
(Dialog isNil |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
9114 |
or:[Screen isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
9115 |
or:[(currentScreen := Screen current) isNil |
10460 | 9116 |
or:[currentScreen isOpen not]]]) ifTrue:[ |
11530 | 9117 |
" |
9118 |
on systems without GUI, simply show |
|
9119 |
the message on the Transcript and abort. |
|
9120 |
" |
|
9121 |
Transcript showCR:aString. |
|
9122 |
AbortOperationRequest raise. |
|
9123 |
"not reached" |
|
9124 |
^ nil |
|
5755 | 9125 |
]. |
9126 |
||
9127 |
Processor activeProcessIsSystemProcess ifTrue:[ |
|
11530 | 9128 |
action := #debug. |
9129 |
sender := aContext. |
|
9130 |
Debugger isNil ifTrue:[ |
|
9131 |
'****************** Cought Error while in SystemProcess ****************' errorPrintCR. |
|
9132 |
thisContext fullPrintAll. |
|
9133 |
action := #abort. |
|
9134 |
]. |
|
5755 | 9135 |
] ifFalse:[ |
11530 | 9136 |
Dialog autoload. "in case it's autoloaded" |
9137 |
||
9138 |
Error handle:[:ex | |
|
9139 |
"/ a recursive error - quickly enter debugger |
|
9140 |
"/ this happened, when I corrupted the Dialog class ... |
|
9141 |
('Object [error]: ' , ex description , ' caught in errorNotification') errorPrintCR. |
|
9142 |
action := #debug. |
|
9143 |
ex return. |
|
9144 |
] do:[ |s| |
|
9145 |
sender := aContext. |
|
9146 |
sender isNil ifTrue:[ |
|
9147 |
sender := thisContext sender. |
|
9148 |
]. |
|
9149 |
con := sender. |
|
9150 |
||
9151 |
"/ skip intermediate (signal & exception) contexts |
|
9152 |
DebugView notNil ifTrue:[ |
|
9153 |
con := DebugView interestingContextFrom:sender |
|
9154 |
]. |
|
9155 |
||
9156 |
"/ show the first few contexts |
|
9157 |
||
9158 |
s := WriteStream with:aString. |
|
9159 |
s cr; cr. |
|
9160 |
s nextPutLine:'Calling Chain (Support Information):'. |
|
9161 |
s nextPutLine:'--------------------------------------------------------------'. |
|
9162 |
1 to:25 do:[:n | |
|
9163 |
con notNil ifTrue:[ |
|
9164 |
con printOn:s. |
|
9165 |
s cr. |
|
9166 |
con := con sender |
|
9167 |
] |
|
9168 |
]. |
|
9169 |
||
9170 |
boxLabels := #('Proceed'). |
|
9171 |
boxValues := #(#proceed). |
|
9172 |
default := #proceed. |
|
9173 |
||
9174 |
AbortOperationRequest isHandled ifTrue:[ |
|
9175 |
default := #abort. |
|
9176 |
boxLabels := boxLabels , #('Abort'). |
|
9177 |
boxValues := boxValues , #(#abort). |
|
11707
b8409bd15e03
added a copy-walkback button to the error notifier
Claus Gittinger <cg@exept.de>
parents:
11662
diff
changeset
|
9178 |
true "allowDebug" ifTrue:[ |
11530 | 9179 |
boxLabels := boxLabels , #('Copy Trace and Abort'). |
9180 |
boxValues := boxValues , #(#copyAndAbort). |
|
9181 |
] |
|
9182 |
] ifFalse:[ |
|
11707
b8409bd15e03
added a copy-walkback button to the error notifier
Claus Gittinger <cg@exept.de>
parents:
11662
diff
changeset
|
9183 |
true "allowDebug" ifTrue:[ |
11530 | 9184 |
boxLabels := boxLabels , #('Copy Trace and Proceed'). |
9185 |
boxValues := boxValues , #(#copyAndProceed). |
|
9186 |
]. |
|
9187 |
]. |
|
9188 |
||
9189 |
(allowDebug and:[Debugger notNil]) ifTrue:[ |
|
9190 |
boxLabels := boxLabels , #('Debug'). |
|
9191 |
boxValues := boxValues , #(#debug). |
|
9192 |
default := #debug. |
|
9193 |
]. |
|
9194 |
||
9195 |
action := Dialog |
|
9196 |
choose:s contents |
|
9197 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
|
9198 |
image:WarningBox errorIconBitmap |
|
9199 |
labels:boxLabels |
|
9200 |
values:boxValues |
|
9201 |
default:default |
|
9202 |
onCancel:nil. |
|
9203 |
]. |
|
5755 | 9204 |
]. |
9205 |
||
9206 |
action == #debug ifTrue:[ |
|
11530 | 9207 |
^ Debugger enter:sender withMessage:aString mayProceed:true |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9208 |
]. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9209 |
action == #proceed ifTrue:[ |
11530 | 9210 |
^ nil. |
11335 | 9211 |
]. |
9212 |
(action == #copyAndProceed |
|
9213 |
or:[action == #copyAndAbort]) ifTrue:[ |
|
11530 | 9214 |
s := '' writeStream. |
9215 |
sender fullPrintAllOn:s. |
|
9216 |
currentScreen rootView setClipboardText:s contents. |
|
9217 |
action == #copyAndProceed ifTrue:[ |
|
9218 |
^ nil |
|
9219 |
]. |
|
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
9220 |
]. |
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
9221 |
|
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9222 |
AbortOperationRequest raise. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
9223 |
"not reached" |
5755 | 9224 |
|
9225 |
" |
|
9226 |
nil errorNotify:'hello there' |
|
9227 |
self errorNotify:'hello there' |
|
9228 |
" |
|
9229 |
||
9230 |
"Created: / 17.8.1998 / 10:09:26 / cg" |
|
6199 | 9231 |
"Modified: / 16.11.2001 / 15:40:12 / cg" |
5755 | 9232 |
! |
9233 |
||
9234 |
information:aString |
|
10460 | 9235 |
"launch an InfoBox, telling user something. |
9236 |
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
|
9237 |
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
|
9238 |
Use #notify: for more important messages. |
8371 | 9239 |
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
|
9240 |
pops up an info dialog." |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9241 |
|
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
9242 |
UserInformation raiseRequestWith:self errorString:aString |
5755 | 9243 |
|
9244 |
" |
|
9245 |
nil information:'hello there' |
|
9246 |
self information:'hello there' |
|
9247 |
" |
|
9248 |
||
9249 |
" |
|
9250 |
InformationSignal handle:[:ex | |
|
17757 | 9251 |
'no box popped' printCR. |
9252 |
ex proceed. |
|
5755 | 9253 |
] do:[ |
17757 | 9254 |
'hello' printCR. |
9255 |
self information:'some info'. |
|
9256 |
'world' printCR. |
|
5755 | 9257 |
] |
9258 |
" |
|
9259 |
||
9260 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
9261 |
! |
|
9262 |
||
9263 |
notify:aString |
|
9264 |
"launch a Notifier, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9265 |
Use #information: for ignorable messages. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9266 |
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
|
9267 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9268 |
|
5755 | 9269 |
|
9270 |
Smalltalk isInitialized ifFalse:[ |
|
17757 | 9271 |
"/ thisContext fullPrintAll. |
9272 |
'information: ' print. aString printCR. |
|
9273 |
^ self |
|
5755 | 9274 |
]. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9275 |
UserNotification raiseRequestWith:self errorString:aString. |
5755 | 9276 |
|
9277 |
" |
|
9278 |
nil notify:'hello there' |
|
9279 |
self notify:'hello there' |
|
9280 |
" |
|
9281 |
||
9282 |
"Modified: 20.5.1996 / 10:28:48 / cg" |
|
9283 |
! |
|
9284 |
||
9285 |
warn:aString |
|
9286 |
"launch a WarningBox, telling user something. |
|
10460 | 9287 |
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
|
9288 |
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
|
9289 |
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
|
9290 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9291 |
|
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9292 |
Warning raiseRequestWith:self errorString:aString |
5755 | 9293 |
|
9294 |
" |
|
9295 |
nil warn:'hello there' |
|
9296 |
self warn:'hello there' |
|
9297 |
" |
|
9298 |
||
9299 |
" |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
9300 |
Warning handle:[:ex | |
17757 | 9301 |
Transcript showCR:ex description. |
9302 |
ex proceed. |
|
5755 | 9303 |
] do:[ |
17757 | 9304 |
'hello' printCR. |
9305 |
self warn:'some info'. |
|
9306 |
'world' printCR. |
|
5755 | 9307 |
] |
9308 |
" |
|
9309 |
||
9310 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
|
9311 |
! ! |
|
9312 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9313 |
!Object methodsFor:'visiting'! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9314 |
|
8426 | 9315 |
acceptVisitor:aVisitor |
9316 |
"double-dispatch onto a Visitor." |
|
9317 |
||
9318 |
^ self acceptVisitor:aVisitor with:nil |
|
9319 |
! |
|
9320 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9321 |
acceptVisitor:aVisitor with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9322 |
"double-dispatch onto a Visitor. |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9323 |
Subclasses redefine this" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9324 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9325 |
^ aVisitor visitObject:self with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9326 |
! ! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
9327 |
|
5755 | 9328 |
!Object class methodsFor:'documentation'! |
1 | 9329 |
|
5754 | 9330 |
version |
17795 | 9331 |
^ '$Id: Object.st 10564 2010-08-10 08:55:15Z vranyj1 $' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
9332 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
9333 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
9334 |
version_CVS |
17795 | 9335 |
^ 'Header: /cvs/stx/stx/libbasic/Object.st,v 1.651 2010/08/05 15:40:40 sr Exp ' |
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
9336 |
! |
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
9337 |
|
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17757
diff
changeset
|
9338 |
version_SVN |
17795 | 9339 |
^ '$Id: Object.st 10564 2010-08-10 08:55:15Z vranyj1 $' |
1 | 9340 |
! ! |
6764 | 9341 |
|
5755 | 9342 |
Object initialize! |
17795 | 9343 |