author | Claus Gittinger <cg@exept.de> |
Mon, 16 May 2016 08:46:28 +0200 | |
changeset 19846 | 08805f2c0810 |
parent 19841 | b0023122a5aa |
child 19863 | 513bd7237fe7 |
child 20027 | 5be764ee44fb |
permissions | -rw-r--r-- |
5755 | 1 |
" |
2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
19846 | 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 |
||
17261 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
5755 | 16 |
nil subclass:#Object |
19846 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'AbortAllSignal AbortSignal ActivityNotificationSignal |
|
19 |
DebuggerHooks DeepCopyErrorSignal Dependencies |
|
20 |
ElementOutOfBoundsSignal EnabledBreakPoints ErrorRecursion |
|
21 |
ErrorSignal FinalizationLobby HaltSignal IndexNotFoundSignal |
|
22 |
InfoPrinting InformationSignal InternalErrorSignal |
|
23 |
KeyNotFoundSignal MessageNotUnderstoodSignal |
|
24 |
NonIntegerIndexSignal NonWeakDependencies NotFoundSignal |
|
25 |
OSSignalInterruptSignal ObjectAttributes |
|
26 |
ObjectAttributesAccessLock PrimitiveFailureSignal |
|
27 |
RecursionInterruptSignal RecursiveStoreStringSignal |
|
28 |
SubscriptOutOfBoundsSignal SynchronizationSemaphores |
|
29 |
UserInterruptSignal UserNotificationSignal WarningSignal' |
|
30 |
poolDictionaries:'' |
|
31 |
category:'Kernel-Objects' |
|
5755 | 32 |
! |
33 |
||
34 |
!Object class methodsFor:'documentation'! |
|
3023
674376809496
general listView support (#displayOn / widthOn / heightOn)
ca
parents:
3010
diff
changeset
|
35 |
|
5754 | 36 |
copyright |
5755 | 37 |
" |
38 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
19846 | 39 |
All Rights Reserved |
5755 | 40 |
|
41 |
This software is furnished under a license and may be used |
|
42 |
only in accordance with the terms of that license and with the |
|
43 |
inclusion of the above copyright notice. This software may not |
|
44 |
be provided or otherwise made available to, or used by, any |
|
45 |
other person. No title to or ownership of the software is |
|
46 |
hereby transferred. |
|
47 |
" |
|
48 |
! |
|
49 |
||
50 |
dependencies |
|
51 |
" |
|
10460 | 52 |
ST/X dependencies are slightly modified from ST-80's |
5755 | 53 |
(we think they are better ;-). |
54 |
||
55 |
One problem occuring very often in ST-80 is that some object |
|
56 |
cannot be garbage collected because some dependency is present, |
|
57 |
having the object as a dependent of some other object. |
|
58 |
In ST-80, this association remains alive (because a Dictionary |
|
59 |
is used to hold dependents) - even if no other references exist to |
|
60 |
to dependent or the dependee. |
|
61 |
||
62 |
This means, that in ST-80, a #release is mandatory in order to |
|
63 |
prevent memory leaks. |
|
64 |
We think, that this is a bad solution, since after all, exactly that |
|
65 |
kind of work should be performed by a garbage collector - you should not |
|
66 |
need to care about dependencies. |
|
10460 | 67 |
From a philosophical point of view, why should some object depend on |
5755 | 68 |
something that the programmer considers a dead object ? |
69 |
(well - worse than that: it seems that some ST-80 code even depends on |
|
70 |
that behavior) |
|
71 |
||
72 |
In order to limit the trouble, ST-80 reimplemented the way dependents |
|
73 |
are stored in the model class - this one keeps the dependents locally, |
|
74 |
so these dependents go away, once the model is reclaimed. |
|
75 |
That may make things even more confusing: with models, no #release is |
|
76 |
needed, with general objects it is mandatory. |
|
77 |
||
78 |
||
79 |
In ST/X, dependencies are implemented using a WeakDictionary; this means, |
|
80 |
that once the dependee dies, the dependency association is removed automatically, |
|
81 |
and the dependent can be reclaimed by the garbage collector, if no other |
|
82 |
references exist to the dependent. |
|
83 |
In order to (at least) provide a mechanism for the old behavior |
|
84 |
(in case your application heavily depends on the ST-80 mechanism), complementary |
|
10460 | 85 |
protocol to add nonWeak dependencies is provided |
5755 | 86 |
(see #addNonWeakDependent / #removeNonWeakDependent). |
87 |
||
88 |
||
89 |
Caveat: |
|
90 |
since interests are implemented using InterestConverter (which are simply |
|
91 |
forwarding messages), these must use the nonWeak mechanism (as done in ST-80 |
|
92 |
automatically). |
|
93 |
The reason is that there are usually no direct references to the converters, |
|
94 |
and those would be reclaimed if stored in a weakDictionary. |
|
95 |
This means, that those interests MUST be removed with #retractInterest |
|
10460 | 96 |
(which is bug-compatible to ST-80). |
5755 | 97 |
We rewrite things to provide a more convenient mechanism in the future ... |
98 |
||
99 |
||
100 |
I like to hear comments on the above - do you think its better ? |
|
101 |
" |
|
102 |
! |
|
103 |
||
104 |
documentation |
|
105 |
" |
|
10460 | 106 |
Object is the superclass of most other classes. |
5755 | 107 |
(except for nil-subclasses, which inherit nothing, |
108 |
to catch any message into their #doesNotUnderstand: method) |
|
109 |
||
110 |
Protocol which is common to every object is defined here. |
|
111 |
Also some utility stuff (like notify) and error handling is implemented here. |
|
112 |
||
113 |
Object has no instance variables (and may not get any added). One reason is, that |
|
10460 | 114 |
UndefinedObject and SmallInteger are also inheriting from Object - these two cannot |
115 |
have instance variables (due to their implementation). |
|
116 |
The other reason is that the runtime system (VM) knows about the layout of some built-in |
|
117 |
classes (think of Class, Method, Block and also Integer or Float). |
|
118 |
If you were allowed to add instance variables to Object, the VM had to be recompiled |
|
5755 | 119 |
(and also rewritten in some places). |
120 |
||
121 |
[Class variables:] |
|
122 |
||
19846 | 123 |
ErrorSignal <Signal> Signal raised for error/error: messages |
124 |
also, parent of all other signals. |
|
125 |
||
126 |
HaltSignal <Signal> Signal raised for halt/halt: messages |
|
127 |
||
128 |
MessageNotUnderstoodSignal Signals raised for various error conditions |
|
129 |
UserInterruptSignal |
|
130 |
RecursionInterruptSignal |
|
131 |
ExceptionInterruptSignal |
|
132 |
SubscriptOutOfBoundsSignal |
|
133 |
NonIntegerIndexSignal |
|
134 |
NotFoundSignal |
|
135 |
KeyNotFoundSignal |
|
136 |
ElementOutOfBoundsSignal |
|
137 |
InformationSignal |
|
138 |
WarningSignal |
|
139 |
DeepCopyErrorSignal |
|
140 |
InternalErrorSignal |
|
141 |
||
142 |
AbortSignal <Signal> Signal raised by debugger, to abort a computation |
|
143 |
BUT, the debugger will only raise it if it is handled. |
|
144 |
By handling the abortSignal, you can control where the |
|
145 |
debuggers abort-function resumes execution in case of |
|
146 |
an error. |
|
147 |
||
148 |
ErrorRecursion <Boolean> controls behavior when recursive errors occur (i.e. |
|
149 |
an error while handling an error). |
|
150 |
||
151 |
Dependencies <WeakDependencyDictionary> |
|
152 |
keeps track of object dependencies. |
|
153 |
||
154 |
InfoPrinting <Boolean> controls weather informational messages |
|
155 |
are printed. |
|
156 |
||
157 |
ActivityNotificationSignal <QuerySignal> |
|
158 |
raised on #activityNotification: |
|
159 |
||
160 |
NonWeakDependencies <Dictionary> keeps track of object dependencies. |
|
161 |
Dependents stay alive. |
|
162 |
||
163 |
SynchronizationSemaphores <WeakIdentityDictionary> |
|
164 |
Semaphores for per-object-monitor. |
|
10460 | 165 |
|
5755 | 166 |
|
167 |
[author:] |
|
19846 | 168 |
Claus Gittinger |
5755 | 169 |
|
170 |
" |
|
171 |
! ! |
|
172 |
||
173 |
!Object class methodsFor:'initialization'! |
|
174 |
||
5971 | 175 |
initSignals |
176 |
"called only once - initialize signals" |
|
177 |
||
15193 | 178 |
"/ notice: the class variables here are a leftover from times |
179 |
"/ when errors where signal-instance, not class based. |
|
180 |
"/ then, signal instances where created here and kept as class vars, |
|
181 |
"/ to be fetched from the class var or via signal-getter methods. |
|
15586 | 182 |
"/ Nowadays, we use class based exceptions, where the exception class |
15193 | 183 |
"/ is directly referenced. |
184 |
"/ the classvars here are kept for backward compatibility, but they now |
|
185 |
"/ simply alias the corresponding exception class. |
|
186 |
"/ Old code should be rewritten to access the error class. |
|
187 |
||
5971 | 188 |
ErrorSignal := Error. |
189 |
HaltSignal := HaltInterrupt. |
|
5977 | 190 |
MessageNotUnderstoodSignal := MessageNotUnderstood. |
6000 | 191 |
PrimitiveFailureSignal := PrimitiveFailure. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
192 |
InternalErrorSignal := VMInternalError. |
5971 | 193 |
UserInterruptSignal := UserInterrupt. |
6146 | 194 |
RecursionInterruptSignal := RecursionError. |
5977 | 195 |
NotFoundSignal := NotFoundError. |
196 |
IndexNotFoundSignal := IndexNotFoundError. |
|
197 |
SubscriptOutOfBoundsSignal := SubscriptOutOfBoundsError. |
|
198 |
NonIntegerIndexSignal := NonIntegerIndexError. |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
199 |
KeyNotFoundSignal := KeyNotFoundError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
200 |
ElementOutOfBoundsSignal := ElementBoundsError. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
201 |
UserNotificationSignal := UserNotification. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
202 |
WarningSignal := Warning. |
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
203 |
InformationSignal := UserInformation. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
204 |
ActivityNotificationSignal := ActivityNotification. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
205 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
206 |
DeepCopyErrorSignal := DeepCopyError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
207 |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
208 |
AbortSignal := AbortOperationRequest. |
6877
ab4e7d42f9f8
AbortAllOperation - now class based
Claus Gittinger <cg@exept.de>
parents:
6874
diff
changeset
|
209 |
AbortAllSignal := AbortAllOperationRequest. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
210 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
211 |
OSSignalInterruptSignal := OSSignalInterrupt. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
212 |
RecursiveStoreStringSignal := RecursiveStoreError. |
5971 | 213 |
|
5980 | 214 |
" |
215 |
Object initSignals |
|
216 |
" |
|
5971 | 217 |
|
218 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
219 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
220 |
"Modified: / 16.11.2001 / 16:30:08 / cg" |
5971 | 221 |
! |
222 |
||
5755 | 223 |
initialize |
224 |
"called only once - initialize signals" |
|
225 |
||
226 |
ErrorSignal isNil ifTrue:[ |
|
19846 | 227 |
self initSignals. |
228 |
ErrorRecursion := true. |
|
5971 | 229 |
]. |
230 |
||
231 |
ObjectAttributes isNil ifTrue:[ |
|
19846 | 232 |
ObjectAttributes := WeakIdentityDictionary new. |
233 |
ObjectAttributesAccessLock := RecursionLock new. |
|
5971 | 234 |
]. |
235 |
Dependencies isNil ifTrue:[ |
|
19846 | 236 |
Dependencies := WeakDependencyDictionary new. |
5971 | 237 |
]. |
238 |
NonWeakDependencies isNil ifTrue:[ |
|
19846 | 239 |
NonWeakDependencies := IdentityDictionary new. |
5971 | 240 |
]. |
241 |
SynchronizationSemaphores isNil ifTrue:[ |
|
19846 | 242 |
SynchronizationSemaphores := WeakIdentityDictionary new. |
5971 | 243 |
]. |
5755 | 244 |
FinalizationLobby isNil ifTrue:[ |
19846 | 245 |
FinalizationLobby := Registry new. |
5755 | 246 |
]. |
247 |
||
248 |
"/ initialize InfoPrinting to the VM's infoPrint setting |
|
249 |
"/ (which can be turned off via a command line argument) |
|
250 |
InfoPrinting := ObjectMemory infoPrinting. |
|
251 |
||
252 |
"Object initialize" |
|
253 |
||
254 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
255 |
"Modified: / 3.2.1998 / 18:55:09 / cg" |
|
256 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
257 |
! ! |
|
258 |
||
7303 | 259 |
!Object class methodsFor:'Compatibility-ST80'! |
5755 | 260 |
|
261 |
rootError |
|
262 |
"return the signal used for error/error: - handling. |
|
263 |
Same as errorSignal for ST80 compatibility." |
|
264 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
265 |
^ Error |
5755 | 266 |
|
267 |
"Created: / 15.1.1998 / 23:47:05 / stefan" |
|
268 |
! ! |
|
269 |
||
270 |
!Object class methodsFor:'Signal constants'! |
|
271 |
||
10460 | 272 |
abortAllSignal |
5755 | 273 |
"return the signal used to abort user actions (much like AbortSignal). |
274 |
This signal is supposed to abort multiple operation actions, and get out of |
|
275 |
the loop (such as when confirming multiple class deletions etc.)" |
|
276 |
||
15903
7de2ea21e054
AbortSignal -> AbortOperationRequest
Stefan Vogel <sv@exept.de>
parents:
15891
diff
changeset
|
277 |
^ AbortAllOperationRequest |
5755 | 278 |
! |
279 |
||
10460 | 280 |
abortSignal |
5755 | 281 |
"return the signal used to abort user actions. This signal is only |
282 |
raised if caught (by the debugger), and will lead way out of the |
|
283 |
currently active doIt/printIt or inspectIt. (also some others use |
|
284 |
this for a save abort)" |
|
285 |
||
8521 | 286 |
^ AbortOperationRequest |
5755 | 287 |
! |
288 |
||
289 |
activityNotificationSignal |
|
290 |
"return the signal used for activity notifications. |
|
291 |
A handler for this signal gets all #activityNotification: sends" |
|
292 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
293 |
^ ActivityNotification |
5755 | 294 |
! |
295 |
||
13416 | 296 |
ambiguousMessageSignal |
297 |
"return the signal used for ambiguousMessage: - error handling" |
|
298 |
||
299 |
^ AmbiguousMessage |
|
300 |
||
301 |
"Created: / 21-07-2010 / 15:39:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
302 |
! |
|
303 |
||
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
304 |
conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
305 |
"return the signal used for conversion error handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
306 |
|
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
307 |
^ ConversionError |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
308 |
! |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
309 |
|
10460 | 310 |
deepCopyErrorSignal |
5755 | 311 |
"return the signal raised when a deepcopy is asked for |
312 |
an object which cannot do this (for example, BlockClosures |
|
313 |
or Contexts)." |
|
314 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
315 |
^ DeepCopyError |
5755 | 316 |
! |
317 |
||
318 |
elementOutOfBoundsSignal |
|
319 |
"return the signal used for element error reporting |
|
320 |
(this signal is used for example when a value not in 0..255 is to |
|
321 |
be put into a bytearray)" |
|
322 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
323 |
^ ElementBoundsError |
5755 | 324 |
! |
325 |
||
326 |
errorSignal |
|
327 |
"return the signal used for error/error: - handling" |
|
328 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
329 |
^ Error |
5755 | 330 |
! |
331 |
||
332 |
haltSignal |
|
333 |
"return the signal used for halt/halt: - handling" |
|
334 |
||
335 |
^ HaltSignal |
|
336 |
! |
|
337 |
||
338 |
indexNotFoundSignal |
|
339 |
"return the signal used for bad index error reporting. |
|
340 |
This is also the parentSignal of the nonIntegerIndex- and |
|
341 |
subscriptOutOfBoundsSignal" |
|
342 |
||
343 |
^ IndexNotFoundSignal |
|
344 |
||
345 |
"Created: / 8.11.1997 / 19:15:48 / cg" |
|
346 |
! |
|
347 |
||
10460 | 348 |
informationSignal |
349 |
"return the signal used for informations. |
|
5755 | 350 |
A handler for this signal gets all #information: sends" |
351 |
||
352 |
^ InformationSignal |
|
353 |
! |
|
354 |
||
355 |
internalErrorSignal |
|
356 |
"return the signal used to report internal (VM-) errors." |
|
357 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
358 |
^ VMInternalError |
5755 | 359 |
! |
360 |
||
10460 | 361 |
keyNotFoundSignal |
5755 | 362 |
"return the signal used for no such key error reporting" |
363 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
364 |
^ KeyNotFoundError |
5755 | 365 |
! |
366 |
||
367 |
messageNotUnderstoodSignal |
|
368 |
"return the signal used for doesNotUnderstand: - error handling" |
|
369 |
||
15193 | 370 |
^ MessageNotUnderstood |
5755 | 371 |
! |
372 |
||
10460 | 373 |
nonIntegerIndexSignal |
5755 | 374 |
"return the signal used for bad subscript error reporting" |
375 |
||
376 |
^ NonIntegerIndexSignal |
|
377 |
! |
|
378 |
||
10460 | 379 |
notFoundSignal |
5755 | 380 |
"return the signal used for no element found error reporting" |
381 |
||
382 |
^ NotFoundSignal |
|
383 |
! |
|
384 |
||
7644
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
385 |
notifySignal |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
386 |
"return the parent of all notification signals." |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
387 |
|
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
388 |
^ Notification |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
389 |
! |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
390 |
|
10460 | 391 |
osSignalInterruptSignal |
5755 | 392 |
"return the signal used for OS-signal error reporting; |
393 |
This is only raised if handled - otherwise, a debugger is entered." |
|
394 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
395 |
^ OSSignalInterrupt |
5755 | 396 |
|
397 |
"Modified: / 12.6.1998 / 16:27:26 / cg" |
|
398 |
! |
|
399 |
||
400 |
primitiveFailureSignal |
|
401 |
"return the signal used for primitiveFailed - error handling" |
|
402 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
403 |
^ PrimitiveFailure |
5755 | 404 |
! |
405 |
||
406 |
privateMethodSignal |
|
407 |
"return the signal used for privateMethod - error handling" |
|
408 |
||
409 |
^ MessageNotUnderstoodSignal |
|
410 |
! |
|
411 |
||
10460 | 412 |
recursionInterruptSignal |
5755 | 413 |
"return the signal used for recursion overflow error handling" |
414 |
||
415 |
^ RecursionInterruptSignal |
|
416 |
! |
|
417 |
||
418 |
recursiveStoreStringSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
419 |
"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
|
420 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
421 |
^ RecursiveStoreError |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
422 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
423 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
424 |
RecursiveStoreError handle:[:ex | |
19846 | 425 |
self halt |
5755 | 426 |
] do:[ |
19846 | 427 |
|a| |
428 |
||
429 |
a := Array new:1. |
|
430 |
a at:1 put:a. |
|
431 |
a storeOn:Transcript |
|
5755 | 432 |
] |
433 |
" |
|
434 |
||
435 |
" |
|
436 |
|a| |
|
437 |
||
438 |
a := Array new:1. |
|
439 |
a at:1 put:a. |
|
440 |
a storeOn:Transcript |
|
441 |
" |
|
442 |
! |
|
443 |
||
5980 | 444 |
subclassResponsibilitySignal |
445 |
"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
|
446 |
(this signal is used to signal incomplete subclasses - i.e. a programmers error)" |
5980 | 447 |
|
448 |
^ SubclassResponsibilityError |
|
449 |
! |
|
450 |
||
5755 | 451 |
subscriptOutOfBoundsSignal |
452 |
"return the signal used for subscript error reporting. |
|
453 |
(this signal is used for example when an array is accessed with an |
|
454 |
index less than 1 or greater than the array size)" |
|
455 |
||
456 |
^ SubscriptOutOfBoundsSignal |
|
457 |
! |
|
458 |
||
459 |
userInterruptSignal |
|
460 |
"return the signal used for ^C interrupts handling" |
|
461 |
||
462 |
^ UserInterruptSignal |
|
463 |
! |
|
464 |
||
465 |
userNotificationSignal |
|
466 |
"the parent signal used with information and warnings. |
|
467 |
Handling this allows handling of both information- and warning notifications." |
|
468 |
||
469 |
^ UserNotificationSignal |
|
470 |
! |
|
471 |
||
10460 | 472 |
warningSignal |
5755 | 473 |
"return the signal used for warnings. |
474 |
A handler for this signal gets all #warn: sends" |
|
475 |
||
476 |
^ WarningSignal |
|
477 |
! ! |
|
478 |
||
479 |
!Object class methodsFor:'info messages'! |
|
480 |
||
481 |
infoPrinting |
|
482 |
"return the flag which controls information messages." |
|
483 |
||
484 |
^ InfoPrinting |
|
485 |
! |
|
486 |
||
487 |
infoPrinting:aBoolean |
|
488 |
"{ Pragma: +optSpace }" |
|
489 |
||
490 |
"turn on/off printing of information messages. |
|
491 |
If the argument, aBoolean is false, infoPrint will not output |
|
492 |
messages. The default is true." |
|
493 |
||
494 |
InfoPrinting := aBoolean |
|
495 |
! ! |
|
496 |
||
497 |
!Object class methodsFor:'queries'! |
|
498 |
||
8892 | 499 |
isAbstract |
11221 | 500 |
"Return if this class is an abstract class. |
501 |
True is returned for Object here; false for subclasses. |
|
19451 | 502 |
Abstract subclasses must redefine this again." |
11221 | 503 |
|
8892 | 504 |
^ self == Object |
505 |
! |
|
506 |
||
5755 | 507 |
isBuiltInClass |
508 |
"return true, if this class is known by the run-time-system, |
|
509 |
i.e. you cannot add/remove instance variables without recompiling |
|
510 |
the VM. |
|
511 |
Here, true is returned for myself, false for subclasses." |
|
512 |
||
513 |
^ self == Object |
|
514 |
||
515 |
"Modified: 23.4.1996 / 16:00:07 / cg" |
|
516 |
! ! |
|
517 |
||
14296 | 518 |
|
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
519 |
!Object methodsFor:'Compatibility-Dolphin'! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
520 |
|
11161 | 521 |
stbFixup: anSTBInFiler at: newObjectIndex |
522 |
"Answer the true object that must be used to represent the receiver when read from anSTBInFiler. |
|
523 |
Typically this is overridden by subclasses of STBProxy to answer the proxied object. Other classes |
|
524 |
may also override this method to effectively 'one way become' the receiver to some other object" |
|
525 |
||
526 |
^ self |
|
8441
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
527 |
! ! |
728c887f2532
Dolphin compatibility: #trigger...
Stefan Vogel <sv@exept.de>
parents:
8426
diff
changeset
|
528 |
|
14682 | 529 |
!Object methodsFor:'Compatibility-GNU'! |
530 |
||
531 |
display |
|
532 |
"print the receiver on the standard output stream (which is not the Transcript). |
|
533 |
Added for GNU-ST compatibility" |
|
534 |
||
535 |
self print |
|
536 |
! |
|
537 |
||
538 |
displayNl |
|
539 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript). |
|
540 |
Added for GNU-ST compatibility" |
|
541 |
||
542 |
self printCR |
|
543 |
! ! |
|
544 |
||
7261 | 545 |
!Object methodsFor:'Compatibility-ST80'! |
5755 | 546 |
|
547 |
isMetaclass |
|
548 |
^ self isMeta |
|
549 |
! ! |
|
550 |
||
7261 | 551 |
!Object methodsFor:'Compatibility-Squeak'! |
5755 | 552 |
|
9071 | 553 |
becomeForward:anotherObject |
554 |
self becomeSameAs:anotherObject |
|
555 |
! |
|
556 |
||
557 |
becomeForward:anotherObject copyHash:copyHash |
|
558 |
copyHash ifTrue:[ self error:'unsupported operation' ]. |
|
559 |
self becomeSameAs:anotherObject |
|
560 |
! |
|
561 |
||
5755 | 562 |
clone |
563 |
^ self shallowCopy |
|
564 |
! |
|
565 |
||
6146 | 566 |
copyTwoLevel |
567 |
"one more level than a shallowCopy" |
|
568 |
||
569 |
^ self copyToLevel:2 |
|
570 |
||
571 |
" |
|
572 |
|original copy elL1 elL2 elL3 copyOfElL1| |
|
573 |
||
574 |
original := Array new:3. |
|
575 |
original at:1 put:1234. |
|
576 |
original at:2 put:'hello'. |
|
577 |
original at:3 put:(elL1 := Array new:3). |
|
578 |
||
579 |
elL1 at:1 put:1234. |
|
580 |
elL1 at:2 put:'hello'. |
|
581 |
elL1 at:3 put:(elL2 := Array new:3). |
|
582 |
||
583 |
elL2 at:1 put:1234. |
|
584 |
elL2 at:2 put:'hello'. |
|
585 |
elL2 at:3 put:(elL3 := Array new:3). |
|
586 |
||
587 |
elL3 at:1 put:1234. |
|
588 |
elL3 at:2 put:'hello'. |
|
589 |
elL3 at:3 put:(Array new:3). |
|
590 |
||
591 |
copy := original copyTwoLevel. |
|
14534 | 592 |
self assert:((original at:2) ~~ (copy at:2)). |
593 |
self assert:((original at:3) ~~ (copy at:3)). |
|
6146 | 594 |
|
595 |
copyOfElL1 := copy at:3. |
|
14534 | 596 |
self assert:((elL1 at:2) == (copyOfElL1 at:2)). |
597 |
self assert:((elL1 at:3) == (copyOfElL1 at:3)). |
|
6146 | 598 |
" |
599 |
! |
|
600 |
||
7320 | 601 |
explore |
602 |
(self confirm:'The Squeak explorer has not yet been ported to ST/X\\Inspect instead ?' withCRs) |
|
603 |
ifTrue:[ |
|
19846 | 604 |
self inspect |
7320 | 605 |
] |
606 |
! |
|
607 |
||
12285
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
608 |
inform: aString |
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
609 |
"Display a message for the user to read and then dismiss." |
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
610 |
|
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
611 |
self information:aString |
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
612 |
! |
54773840f621
added: #inform: - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
12158
diff
changeset
|
613 |
|
16021 | 614 |
isCompiledMethod |
615 |
"same as isMethod - for squeak compatibility" |
|
616 |
||
617 |
^ false |
|
618 |
! |
|
619 |
||
9335 | 620 |
isInMemory |
621 |
"All normal objects are." |
|
622 |
||
623 |
^ true |
|
624 |
! |
|
625 |
||
5755 | 626 |
stringForReadout |
19846 | 627 |
^ self stringRepresentation |
5755 | 628 |
! |
629 |
||
630 |
stringRepresentation |
|
19846 | 631 |
"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" |
632 |
||
633 |
^ self printString |
|
5755 | 634 |
! |
635 |
||
9146
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
636 |
valueWithPossibleArguments:argArray |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
637 |
^ self |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
638 |
! |
56176a7bf685
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9105
diff
changeset
|
639 |
|
5755 | 640 |
veryDeepCopy |
8383 | 641 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 642 |
! ! |
643 |
||
7567 | 644 |
!Object methodsFor:'Compatibility-VW'! |
645 |
||
8637 | 646 |
isCharacters |
647 |
"added for visual works compatibility" |
|
648 |
^ false |
|
649 |
! |
|
650 |
||
18151 | 651 |
isSignalledException |
652 |
"VW compatibility" |
|
653 |
||
654 |
^ self isException |
|
655 |
! |
|
656 |
||
7567 | 657 |
keyNotFoundError:aKey |
658 |
"VW compatibility" |
|
659 |
||
660 |
self errorKeyNotFound:aKey. |
|
661 |
! |
|
662 |
||
663 |
oneWayBecome:anotherObject |
|
664 |
^ self becomeSameAs:anotherObject |
|
665 |
||
666 |
" |
|
667 |
|arr o1 o2| |
|
668 |
||
669 |
arr := Array new:2. |
|
670 |
arr at:1 put:(o1 := Object new). |
|
671 |
arr at:2 put:(o2 := Point new). |
|
672 |
o1 oneWayBecome:o2. |
|
673 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
674 |
" |
|
675 |
" |
|
676 |
|arr o1 o2| |
|
677 |
||
678 |
arr := Array new:2. |
|
679 |
arr at:1 put:(o1 := Object new). |
|
680 |
arr at:2 put:(o2 := Point new). |
|
681 |
o1 becomeSameAs:o2. |
|
682 |
(arr at:1) ~~ o2 ifTrue:[self halt]. |
|
683 |
" |
|
684 |
! ! |
|
685 |
||
5755 | 686 |
!Object methodsFor:'accessing'! |
687 |
||
13320 | 688 |
_at:index |
689 |
"experimental: |
|
690 |
this is a synthetic selector, generated by the compiler, |
|
691 |
if a construct of the form expr[idx...] is parsed. |
|
692 |
I.e. |
|
19846 | 693 |
v[n] |
13320 | 694 |
generates |
19846 | 695 |
v _at: n |
13320 | 696 |
" |
697 |
||
698 |
^ self at:index |
|
699 |
||
700 |
"Created: / 21-03-2011 / 14:07:57 / cg" |
|
701 |
! |
|
702 |
||
703 |
_at:index put:value |
|
704 |
"experimental: |
|
705 |
this is a synthetic selector, generated by the compiler, |
|
706 |
if a construct of the form expr[idx...] is parsed. |
|
707 |
I.e. |
|
19846 | 708 |
v[n] |
13320 | 709 |
generates |
19846 | 710 |
v _at: n |
13320 | 711 |
" |
712 |
||
713 |
^ self at:index put:value |
|
714 |
||
715 |
"Created: / 21-03-2011 / 14:10:12 / cg" |
|
716 |
! |
|
717 |
||
14705 | 718 |
addSlot: slotName |
719 |
"dynamically add a new slot to the receiver. |
|
720 |
The receiver must be a real object, not nil or a smallInteger" |
|
721 |
||
722 |
|classGetter myClass anonCls newObj| |
|
723 |
||
724 |
myClass := self class. |
|
725 |
classGetter := ('%__get_',slotName,'__') asSymbol. |
|
726 |
||
727 |
anonCls := self perform:classGetter ifNotUnderstood:nil. |
|
728 |
anonCls isNil ifTrue:[ |
|
19846 | 729 |
anonCls := myClass |
730 |
subclass:(myClass name,'+',slotName) asSymbol |
|
731 |
instanceVariableNames:slotName |
|
732 |
classVariableNames:'' |
|
733 |
poolDictionaries:'' category:nil |
|
734 |
inEnvironment:nil. |
|
735 |
anonCls compile:('%1 ^ %1' bindWith:slotName). |
|
736 |
anonCls compile:('%1:v %1 := v' bindWith:slotName). |
|
737 |
Class withoutUpdatingChangesDo:[ |
|
738 |
|m| |
|
739 |
m := Compiler compile:('__get_',slotName,' ^ #fooBar' bindWith:slotName) forClass:myClass install:false. |
|
740 |
m literalAt:(m literals indexOf:#fooBar) put:anonCls. |
|
741 |
myClass addSelector:classGetter withMethod:m. |
|
742 |
]. |
|
14705 | 743 |
]. |
744 |
newObj := anonCls cloneFrom:self. |
|
745 |
self become:newObj. |
|
746 |
||
747 |
" |
|
748 |
|p1 p2 p3| |
|
749 |
||
750 |
p1 := Point x:10 y:20. |
|
751 |
p2 := Point x:100 y:200. |
|
752 |
Transcript show:'p1 is '; showCR:p1. |
|
753 |
Transcript show:'p2 is '; showCR:p2. |
|
754 |
p1 addSlot:'z'. |
|
755 |
p1 z:30. |
|
756 |
Transcript show:'p1 is '; showCR:p1. |
|
757 |
Transcript show:'p2 is '; showCR:p2. |
|
758 |
ObjectMemory dumpObject:p1. |
|
759 |
ObjectMemory dumpObject:p2. |
|
760 |
||
761 |
p1 addSlot:'t'. |
|
762 |
p1 t:30. |
|
763 |
Transcript show:'p1 is '; showCR:p1. |
|
764 |
ObjectMemory dumpObject:p1. |
|
765 |
||
766 |
p3 := Point x:110 y:120. |
|
767 |
p3 addSlot:'z'. |
|
768 |
p3 addSlot:'t'. |
|
769 |
p1 inspect. |
|
770 |
p2 inspect. |
|
771 |
p3 inspect. |
|
772 |
" |
|
773 |
! |
|
774 |
||
5755 | 775 |
at:index |
776 |
"return the indexed instance variable with index, anInteger; |
|
777 |
this method can be redefined in subclasses." |
|
778 |
||
779 |
^ self basicAt:index |
|
780 |
! |
|
781 |
||
782 |
at:index put:anObject |
|
783 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
784 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
|
785 |
||
786 |
^ self basicAt:index put:anObject |
|
787 |
||
788 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
|
789 |
! |
|
790 |
||
791 |
basicAt:index |
|
792 |
"return the indexed instance variable with index, anInteger. |
|
793 |
Trigger an error if the receiver has no indexed instance variables. |
|
794 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
795 |
||
796 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
797 |
#ifdef __SCHTEAM__ |
18215 | 798 |
{ |
19846 | 799 |
int idx1Based = index.intValue(); // st index is 1 based |
800 |
return context._RETURN( self.basicAt( idx1Based )); |
|
18215 | 801 |
} |
802 |
/* NOTREACHED */ |
|
803 |
#else |
|
5755 | 804 |
REGISTER int nbytes, indx; |
805 |
OBJ myClass; |
|
806 |
REGISTER char *pFirst; |
|
807 |
REGISTER int n; |
|
808 |
||
809 |
/* |
|
810 |
* notice the missing test for self being a nonNilObject - |
|
811 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
812 |
* and SmallInteger |
|
813 |
*/ |
|
814 |
if (__isSmallInteger(index)) { |
|
19846 | 815 |
myClass = __qClass(self); |
816 |
indx = __intVal(index) - 1; |
|
817 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
818 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
819 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
820 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
821 |
||
822 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
823 |
case __MASKSMALLINT(POINTERARRAY): |
|
824 |
/* |
|
825 |
* pointers |
|
826 |
*/ |
|
827 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
828 |
OBJ *op; |
|
829 |
||
830 |
op = (OBJ *)pFirst + indx; |
|
831 |
RETURN ( *op ); |
|
832 |
} |
|
833 |
break; |
|
834 |
||
835 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
836 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
837 |
OBJ *op; |
|
838 |
OBJ el; |
|
839 |
||
840 |
op = (OBJ *)pFirst + indx; |
|
841 |
el = *op; |
|
842 |
el = __WEAK_READ__(self, el); |
|
843 |
RETURN ( el ); |
|
844 |
} |
|
845 |
break; |
|
846 |
||
847 |
case __MASKSMALLINT(BYTEARRAY): |
|
848 |
/* |
|
849 |
* (unsigned) bytes |
|
850 |
*/ |
|
851 |
if ((unsigned)indx < nbytes) { |
|
852 |
unsigned char *cp; |
|
853 |
||
854 |
cp = (unsigned char *)pFirst + indx; |
|
855 |
RETURN ( __mkSmallInteger( (*cp & 0xFF)) ); |
|
856 |
} |
|
857 |
break; |
|
858 |
||
859 |
case __MASKSMALLINT(FLOATARRAY): |
|
860 |
/* |
|
861 |
* native floats |
|
862 |
*/ |
|
863 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
864 |
float *fp; |
|
865 |
float f; |
|
866 |
OBJ v; |
|
867 |
||
868 |
fp = (float *)pFirst + indx; |
|
869 |
f = *fp; |
|
870 |
if (f == 0.0) { |
|
871 |
v = STX__float0; |
|
872 |
} else { |
|
873 |
__qMKSFLOAT(v, f); |
|
874 |
} |
|
875 |
RETURN (v); |
|
876 |
} |
|
877 |
break; |
|
878 |
||
879 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
880 |
/* |
|
881 |
* native doubles |
|
882 |
*/ |
|
18215 | 883 |
# ifdef __NEED_DOUBLE_ALIGN |
19846 | 884 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
885 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
886 |
||
887 |
pFirst += delta; |
|
888 |
nbytes -= delta; |
|
889 |
} |
|
18215 | 890 |
# endif |
19846 | 891 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
892 |
double *dp; |
|
893 |
double d; |
|
894 |
OBJ v; |
|
895 |
||
896 |
dp = (double *)pFirst + indx; |
|
897 |
d = *dp; |
|
898 |
if (d == 0.0) { |
|
899 |
v = STX__float0; |
|
900 |
} else { |
|
901 |
__qMKFLOAT(v, d); |
|
902 |
} |
|
903 |
RETURN (v); |
|
904 |
} |
|
905 |
break; |
|
906 |
||
907 |
case __MASKSMALLINT(WORDARRAY): |
|
908 |
/* |
|
909 |
* unsigned 16bit ints |
|
910 |
*/ |
|
911 |
/* Notice: the hard coded shifts are by purpose; |
|
912 |
* it makes us independent of the short-size of the machine |
|
913 |
*/ |
|
914 |
if ((unsigned)indx < (nbytes>>1)) { |
|
915 |
unsigned short *sp; |
|
916 |
||
917 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
918 |
RETURN ( __mkSmallInteger( (*sp & 0xFFFF)) ); |
|
919 |
} |
|
920 |
break; |
|
921 |
||
922 |
case __MASKSMALLINT(SWORDARRAY): |
|
923 |
/* |
|
924 |
* signed 16bit ints |
|
925 |
*/ |
|
926 |
/* Notice: the hard coded shifts are by purpose; |
|
927 |
* it makes us independent of the short-size of the machine |
|
928 |
*/ |
|
929 |
if ((unsigned)indx < (nbytes>>1)) { |
|
930 |
short *ssp; |
|
931 |
||
932 |
ssp = (short *)(pFirst + (indx<<1)); |
|
933 |
RETURN ( __mkSmallInteger( (*ssp) )); |
|
934 |
} |
|
935 |
break; |
|
936 |
||
937 |
case __MASKSMALLINT(LONGARRAY): |
|
938 |
/* |
|
939 |
* unsigned 32bit ints |
|
940 |
*/ |
|
941 |
/* Notice: the hard coded shifts are by purpose; |
|
942 |
* it makes us independent of the int-size of the machine |
|
943 |
*/ |
|
944 |
if ((unsigned)indx < (nbytes>>2)) { |
|
945 |
unsigned int32 ul; |
|
946 |
unsigned int32 *lp; |
|
947 |
||
948 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
949 |
ul = *lp; |
|
18215 | 950 |
# if __POINTER_SIZE__ == 8 |
19846 | 951 |
{ |
952 |
unsigned INT ull = (unsigned INT)ul; |
|
953 |
RETURN ( __mkSmallInteger(ull) ); |
|
954 |
} |
|
18215 | 955 |
# else |
19846 | 956 |
if (ul <= _MAX_INT) { |
957 |
RETURN ( __mkSmallInteger(ul) ); |
|
958 |
} |
|
959 |
RETURN ( __MKULARGEINT(ul) ); |
|
18215 | 960 |
# endif |
19846 | 961 |
} |
962 |
break; |
|
963 |
||
964 |
case __MASKSMALLINT(SLONGARRAY): |
|
965 |
/* |
|
966 |
* signed 32bit ints |
|
967 |
*/ |
|
968 |
/* Notice: the hard coded shifts are by purpose; |
|
969 |
* it makes us independent of the int-size of the machine |
|
970 |
*/ |
|
971 |
if ((unsigned)indx < (nbytes>>2)) { |
|
972 |
int32 *slp; |
|
973 |
int32 l; |
|
974 |
||
975 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
976 |
l = *slp; |
|
18215 | 977 |
# if __POINTER_SIZE__ == 8 |
19846 | 978 |
{ |
979 |
INT ll = (INT)l; |
|
980 |
RETURN ( __mkSmallInteger(ll) ); |
|
981 |
} |
|
18215 | 982 |
# else |
19846 | 983 |
if (__ISVALIDINTEGER(l)) { |
984 |
RETURN ( __mkSmallInteger(l) ); |
|
985 |
} |
|
986 |
RETURN ( __MKLARGEINT(l) ); |
|
18215 | 987 |
# endif |
19846 | 988 |
} |
989 |
break; |
|
990 |
||
991 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
992 |
/* |
|
993 |
* signed 64bit longlongs |
|
994 |
*/ |
|
18215 | 995 |
# ifdef __NEED_LONGLONG_ALIGN |
19846 | 996 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
997 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
998 |
||
999 |
pFirst += delta; |
|
1000 |
nbytes -= delta; |
|
1001 |
} |
|
18215 | 1002 |
# endif |
19846 | 1003 |
/* Notice: the hard coded shifts are by purpose; |
1004 |
* it makes us independent of the long/longlong-size of the machine |
|
1005 |
*/ |
|
1006 |
if ((unsigned)indx < (nbytes>>3)) { |
|
18215 | 1007 |
# if __POINTER_SIZE__ == 8 |
19846 | 1008 |
INT *slp, ll; |
1009 |
||
1010 |
slp = (INT *)(pFirst + (indx<<3)); |
|
1011 |
ll = *slp; |
|
1012 |
if (__ISVALIDINTEGER(ll)) { |
|
1013 |
RETURN ( __mkSmallInteger(ll) ); |
|
1014 |
} |
|
1015 |
RETURN ( __MKLARGEINT(ll) ); |
|
18215 | 1016 |
# else |
19846 | 1017 |
__int64__ *llp; |
1018 |
||
1019 |
llp = (__int64__ *)(pFirst + (indx<<3)); |
|
1020 |
RETURN (__MKINT64(llp)); |
|
18215 | 1021 |
# endif |
19846 | 1022 |
} |
1023 |
break; |
|
1024 |
||
1025 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1026 |
/* |
|
1027 |
* unsigned 64bit longlongs |
|
1028 |
*/ |
|
18215 | 1029 |
# ifdef __NEED_LONGLONG_ALIGN |
19846 | 1030 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1031 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1032 |
||
1033 |
pFirst += delta; |
|
1034 |
nbytes -= delta; |
|
1035 |
} |
|
18215 | 1036 |
# endif |
19846 | 1037 |
/* Notice: the hard coded shifts are by purpose; |
1038 |
* it makes us independent of the long/longlong-size of the machine |
|
1039 |
*/ |
|
1040 |
if ((unsigned)indx < (nbytes>>3)) { |
|
18215 | 1041 |
# if __POINTER_SIZE__ == 8 |
19846 | 1042 |
unsigned INT *ulp, ul; |
1043 |
||
1044 |
ulp = (unsigned INT *)(pFirst + (indx<<3)); |
|
1045 |
ul = *ulp; |
|
1046 |
if (ul <= _MAX_INT) { |
|
1047 |
RETURN ( __mkSmallInteger(ul) ); |
|
1048 |
} |
|
1049 |
RETURN ( __MKULARGEINT(ul) ); |
|
18215 | 1050 |
# else |
19846 | 1051 |
__uint64__ *llp; |
1052 |
||
1053 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
1054 |
RETURN (__MKUINT64(llp)); |
|
18215 | 1055 |
# endif |
19846 | 1056 |
} |
1057 |
break; |
|
1058 |
} |
|
5755 | 1059 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
1060 |
#endif /* ! __SCHTEAM__ */ |
5755 | 1061 |
%}. |
7216 | 1062 |
^ self indexNotIntegerOrOutOfBounds:index |
5755 | 1063 |
! |
1064 |
||
1065 |
basicAt:index put:anObject |
|
1066 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
1067 |
Returns anObject (sigh). |
|
1068 |
Trigger an error if the receiver has no indexed instance variables. |
|
1069 |
||
1070 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
1071 |
||
1072 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
1073 |
#ifdef __SCHTEAM__ |
18215 | 1074 |
{ |
19846 | 1075 |
int idx1Based = index.intValue(); // st index is 1 based |
1076 |
||
1077 |
self.basicAt_put(idx1Based, anObject ); |
|
1078 |
return context._RETURN( anObject ); |
|
18215 | 1079 |
} |
1080 |
/* NOTREACHED */ |
|
1081 |
#else |
|
5755 | 1082 |
register int nbytes, indx; |
1083 |
OBJ myClass; |
|
1084 |
register char *pFirst; |
|
18215 | 1085 |
/* int nInstBytes, ninstvars, flags; */ |
5755 | 1086 |
REGISTER int n; |
1087 |
unsigned int u; |
|
1088 |
int val; |
|
1089 |
||
1090 |
/* notice the missing test for self being a nonNilObject - |
|
1091 |
this can be done since basicAt: is defined both in UndefinedObject |
|
1092 |
and SmallInteger */ |
|
1093 |
||
1094 |
if (__isSmallInteger(index)) { |
|
19846 | 1095 |
indx = __intVal(index) - 1; |
1096 |
myClass = __qClass(self); |
|
1097 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1098 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
1099 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
1100 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
1101 |
||
1102 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1103 |
case __MASKSMALLINT(POINTERARRAY): |
|
1104 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
1105 |
OBJ *op; |
|
1106 |
||
1107 |
op = (OBJ *)pFirst + indx; |
|
1108 |
*op = anObject; |
|
1109 |
__STORE(self, anObject); |
|
1110 |
RETURN ( anObject ); |
|
1111 |
} |
|
1112 |
break; |
|
1113 |
||
1114 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
1115 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
1116 |
OBJ *op; |
|
1117 |
||
1118 |
op = (OBJ *)pFirst + indx; |
|
1119 |
*op = anObject; |
|
1120 |
__STORE(self, anObject); |
|
1121 |
__WEAK_WRITE__(self, anObject); |
|
1122 |
RETURN ( anObject ); |
|
1123 |
} |
|
1124 |
break; |
|
1125 |
||
1126 |
case __MASKSMALLINT(BYTEARRAY): |
|
1127 |
if (__isSmallInteger(anObject)) { |
|
1128 |
val = __intVal(anObject); |
|
1129 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
1130 |
if ((unsigned)indx < nbytes) { |
|
1131 |
char *cp; |
|
1132 |
||
1133 |
cp = pFirst + indx; |
|
1134 |
*cp = val; |
|
1135 |
RETURN ( anObject ); |
|
1136 |
} |
|
1137 |
} |
|
1138 |
} |
|
1139 |
break; |
|
1140 |
||
1141 |
case __MASKSMALLINT(FLOATARRAY): |
|
1142 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
1143 |
float *fp; |
|
1144 |
||
1145 |
fp = (float *)pFirst + indx; |
|
1146 |
if (anObject != nil) { |
|
1147 |
if (! __isSmallInteger(anObject)) { |
|
1148 |
if (__qIsFloatLike(anObject)) { |
|
1149 |
*fp = (float)(__floatVal(anObject)); |
|
1150 |
RETURN ( anObject ); |
|
1151 |
} |
|
1152 |
if (__qIsShortFloat(anObject)) { |
|
1153 |
*fp = __shortFloatVal(anObject); |
|
1154 |
RETURN ( anObject ); |
|
1155 |
} |
|
1156 |
} else { |
|
1157 |
*fp = (float) __intVal(anObject); |
|
1158 |
RETURN ( anObject ); |
|
1159 |
} |
|
1160 |
} |
|
1161 |
} |
|
1162 |
break; |
|
1163 |
||
1164 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
18215 | 1165 |
# ifdef __NEED_DOUBLE_ALIGN |
19846 | 1166 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1167 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1168 |
||
1169 |
pFirst += delta; |
|
1170 |
nbytes -= delta; |
|
1171 |
} |
|
18215 | 1172 |
# endif |
19846 | 1173 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
1174 |
double *dp; |
|
1175 |
||
1176 |
dp = (double *)pFirst + indx; |
|
1177 |
if (anObject != nil) { |
|
1178 |
if (! __isSmallInteger(anObject)) { |
|
1179 |
if (__qIsFloatLike(anObject)) { |
|
1180 |
*dp = __floatVal(anObject); |
|
1181 |
RETURN ( anObject ); |
|
1182 |
} |
|
1183 |
if (__qIsShortFloat(anObject)) { |
|
1184 |
*dp = (double)__shortFloatVal(anObject); |
|
1185 |
RETURN ( anObject ); |
|
1186 |
} |
|
1187 |
} else { |
|
1188 |
*dp = (double) __intVal(anObject); |
|
1189 |
RETURN ( anObject ); |
|
1190 |
} |
|
1191 |
} |
|
1192 |
} |
|
1193 |
break; |
|
1194 |
||
1195 |
case __MASKSMALLINT(WORDARRAY): |
|
1196 |
if (__isSmallInteger(anObject)) { |
|
1197 |
val = __intVal(anObject); |
|
1198 |
if ((unsigned)val <= 0xFFFF) { |
|
1199 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1200 |
unsigned short *sp; |
|
1201 |
||
1202 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
1203 |
*sp = val; |
|
1204 |
RETURN ( anObject ); |
|
1205 |
} |
|
1206 |
} |
|
1207 |
} |
|
1208 |
break; |
|
1209 |
||
1210 |
case __MASKSMALLINT(SWORDARRAY): |
|
1211 |
if (__isSmallInteger(anObject)) { |
|
1212 |
val = __intVal(anObject); |
|
1213 |
if ((val >= -32768) && (val < 32768)) { |
|
1214 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1215 |
short *ssp; |
|
1216 |
||
1217 |
ssp = (short *)(pFirst + (indx<<1)); |
|
1218 |
*ssp = val; |
|
1219 |
RETURN ( anObject ); |
|
1220 |
} |
|
1221 |
} |
|
1222 |
} |
|
1223 |
break; |
|
1224 |
||
1225 |
case __MASKSMALLINT(SLONGARRAY): |
|
1226 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1227 |
int32 *slp; |
|
1228 |
||
1229 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
1230 |
if (__isSmallInteger(anObject)) { |
|
1231 |
*slp = __intVal(anObject); |
|
1232 |
RETURN ( anObject ); |
|
1233 |
} |
|
1234 |
n = __signedLongIntVal(anObject); |
|
1235 |
/* |
|
1236 |
* zero means failure for an int larger than INT-size bytes |
|
1237 |
* (would be a smallInteger) |
|
1238 |
*/ |
|
1239 |
if (n) { |
|
18215 | 1240 |
# if __POINTER_SIZE__ == 8 |
19846 | 1241 |
if ((n >= -0x80000000) && (n < 0x80000000)) |
18215 | 1242 |
# endif |
19846 | 1243 |
{ |
1244 |
*slp = n; |
|
1245 |
RETURN ( anObject ); |
|
1246 |
} |
|
1247 |
} |
|
1248 |
} |
|
1249 |
break; |
|
1250 |
||
1251 |
case __MASKSMALLINT(LONGARRAY): |
|
1252 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1253 |
unsigned int32 *lp; |
|
1254 |
||
1255 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
1256 |
if (anObject == __mkSmallInteger(0)) { |
|
1257 |
*lp = 0; |
|
1258 |
RETURN ( anObject ); |
|
1259 |
} |
|
1260 |
u = __longIntVal(anObject); |
|
1261 |
/* |
|
1262 |
* zero means failure for an int larger than 4 bytes |
|
1263 |
* (would be a smallInteger) |
|
1264 |
*/ |
|
1265 |
if (u) { |
|
18215 | 1266 |
# if __POINTER_SIZE__ == 8 |
19846 | 1267 |
if (u <= 0xFFFFFFFF) |
18215 | 1268 |
# endif |
19846 | 1269 |
{ |
1270 |
*lp = u; |
|
1271 |
RETURN ( anObject ); |
|
1272 |
} |
|
1273 |
} |
|
1274 |
} |
|
1275 |
break; |
|
1276 |
||
1277 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
18215 | 1278 |
# ifdef __NEED_LONGLONG_ALIGN |
19846 | 1279 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1280 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1281 |
||
1282 |
pFirst += delta; |
|
1283 |
nbytes -= delta; |
|
1284 |
} |
|
18215 | 1285 |
# endif |
19846 | 1286 |
if ((unsigned)indx < (nbytes>>3)) { |
1287 |
__int64__ ll; |
|
1288 |
__int64__ *sllp; |
|
1289 |
||
1290 |
sllp = (__int64__ *)(pFirst + (indx<<3)); |
|
14632 | 1291 |
|
18215 | 1292 |
# if __POINTER_SIZE__ == 8 |
19846 | 1293 |
if (__isSmallInteger(anObject)) { |
1294 |
*sllp = __intVal(anObject); |
|
1295 |
RETURN ( anObject ); |
|
1296 |
} |
|
1297 |
n = __signedLongIntVal(anObject); |
|
1298 |
if (n) { |
|
1299 |
*sllp = n; |
|
1300 |
RETURN ( anObject ); |
|
1301 |
} |
|
18215 | 1302 |
# else |
19846 | 1303 |
if (anObject == __mkSmallInteger(0)) { |
1304 |
ll.lo = ll.hi = 0; |
|
1305 |
*sllp = ll; |
|
1306 |
RETURN ( anObject ); |
|
1307 |
} |
|
1308 |
if (__signedLong64IntVal(anObject, &ll)) { |
|
1309 |
*sllp = ll; |
|
1310 |
RETURN ( anObject ); |
|
1311 |
} |
|
18215 | 1312 |
# endif |
19846 | 1313 |
} |
1314 |
break; |
|
1315 |
||
1316 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
18215 | 1317 |
# ifdef __NEED_LONGLONG_ALIGN |
19846 | 1318 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1319 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1320 |
||
1321 |
pFirst += delta; |
|
1322 |
nbytes -= delta; |
|
1323 |
} |
|
18215 | 1324 |
# endif |
19846 | 1325 |
if ((unsigned)indx < (nbytes>>3)) { |
1326 |
__uint64__ ll; |
|
1327 |
__uint64__ *llp; |
|
1328 |
||
1329 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
18215 | 1330 |
# if __POINTER_SIZE__ == 8 |
19846 | 1331 |
if (__isSmallInteger(anObject)) { |
1332 |
*llp = __intVal(anObject); |
|
1333 |
RETURN ( anObject ); |
|
1334 |
} |
|
1335 |
ll = __longIntVal(anObject); |
|
1336 |
if (ll) { |
|
1337 |
*llp = ll; |
|
1338 |
RETURN ( anObject ); |
|
1339 |
} |
|
18215 | 1340 |
# else |
19846 | 1341 |
if (anObject == __mkSmallInteger(0)) { |
1342 |
ll.lo = ll.hi = 0; |
|
1343 |
*llp = ll; |
|
1344 |
RETURN ( anObject ); |
|
1345 |
} |
|
1346 |
if (__unsignedLong64IntVal(anObject, &ll)) { |
|
1347 |
*llp = ll; |
|
1348 |
RETURN ( anObject ); |
|
1349 |
} |
|
18215 | 1350 |
# endif |
19846 | 1351 |
} |
1352 |
break; |
|
1353 |
} |
|
5755 | 1354 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
1355 |
#endif /* ! __SCHTEAM__ */ |
5755 | 1356 |
%}. |
1357 |
index isInteger ifFalse:[ |
|
19846 | 1358 |
" |
1359 |
the index should be an integer number |
|
1360 |
" |
|
1361 |
^ self indexNotInteger:index |
|
5755 | 1362 |
]. |
1363 |
(index between:1 and:self size) ifFalse:[ |
|
19846 | 1364 |
" |
1365 |
the index is less than 1 or greater than the size of the |
|
1366 |
receiver collection |
|
1367 |
" |
|
1368 |
^ self subscriptBoundsError:index |
|
5755 | 1369 |
]. |
1370 |
(self class isFloatsOrDoubles) ifTrue:[ |
|
19846 | 1371 |
anObject isNumber ifTrue:[ |
1372 |
^ self basicAt:index put:(anObject asFloat) |
|
1373 |
] |
|
5755 | 1374 |
]. |
1375 |
anObject isInteger ifFalse:[ |
|
19846 | 1376 |
" |
1377 |
the object to put into the receiver collection |
|
1378 |
should be an integer number |
|
1379 |
" |
|
1380 |
^ self elementNotInteger |
|
5755 | 1381 |
]. |
1382 |
" |
|
1383 |
the object to put into the receiver collection |
|
1384 |
is not an instance of the expected element class, |
|
1385 |
or the value is not within the elements valid range. |
|
1386 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1387 |
^ self elementBoundsError:anObject |
5755 | 1388 |
|
1389 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
|
1390 |
! |
|
1391 |
||
1392 |
byteAt:index |
|
10460 | 1393 |
"return the byte at index. |
5755 | 1394 |
This is only allowed for non-pointer indexed objects |
1395 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
19451 | 1396 |
The receiver's indexed instvars are treated as an uninterpreted |
5755 | 1397 |
collection of bytes. |
1398 |
Only useful with binary storage." |
|
1399 |
||
1400 |
%{ /* NOCONTEXT */ |
|
1401 |
||
1402 |
if (__isSmallInteger(index)) { |
|
19841 | 1403 |
OBJ slf = self; |
19451 | 1404 |
if (__isNonNilObject(slf)) { |
19841 | 1405 |
OBJ cls = __qClass(slf); |
1406 |
INT indx = __intVal(index) - 1; |
|
1407 |
INT nIndex = __byteArraySize(slf); |
|
1408 |
unsigned char *pFirst = __byteArrayVal(slf) + __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
19451 | 1409 |
|
1410 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1411 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1412 |
#ifdef __NEED_DOUBLE_ALIGN |
19451 | 1413 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1414 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1415 |
||
1416 |
pFirst += delta; |
|
1417 |
nIndex -= delta; |
|
1418 |
} |
|
5755 | 1419 |
#endif |
19451 | 1420 |
/* fall into */ |
1421 |
case __MASKSMALLINT(BYTEARRAY): |
|
1422 |
case __MASKSMALLINT(WORDARRAY): |
|
1423 |
case __MASKSMALLINT(LONGARRAY): |
|
1424 |
case __MASKSMALLINT(SWORDARRAY): |
|
1425 |
case __MASKSMALLINT(SLONGARRAY): |
|
1426 |
case __MASKSMALLINT(FLOATARRAY): |
|
1427 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1428 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
|
1429 |
} |
|
1430 |
break; |
|
1431 |
||
1432 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1433 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1434 |
#ifdef __NEED_LONGLONG_ALIGN |
19451 | 1435 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1436 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1437 |
||
1438 |
pFirst += delta; |
|
1439 |
nIndex -= delta; |
|
1440 |
} |
|
5755 | 1441 |
#endif |
19451 | 1442 |
if ((unsigned)indx < (unsigned)nIndex) { |
1443 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
|
1444 |
} |
|
1445 |
break; |
|
1446 |
} |
|
1447 |
} |
|
5755 | 1448 |
} |
1449 |
%}. |
|
1450 |
"/ index not integer or index out of range |
|
1451 |
"/ or non-byte indexable receiver |
|
1452 |
||
1453 |
^ self primitiveFailed |
|
1454 |
||
1455 |
" |
|
1456 |
Point new byteAt:1 |
|
1457 |
(ByteArray with:1 with:2) byteAt:2 |
|
10460 | 1458 |
(WordArray with:1) byteAt:1 |
19841 | 1459 |
(WordArray with:1) byteAt:2 |
10460 | 1460 |
(FloatArray with:1.0) byteAt:2 |
1461 |
'hello' byteAt:1 |
|
5755 | 1462 |
" |
1463 |
! |
|
1464 |
||
1465 |
byteAt:index put:byteValue |
|
10460 | 1466 |
"set the byte at index. |
5755 | 1467 |
This is only allowed for non-pointer indexed objects |
1468 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
19451 | 1469 |
The receiver's indexed instvars are treated as an uninterpreted |
5755 | 1470 |
collection of bytes. |
1471 |
Only useful with binary storage." |
|
1472 |
||
1473 |
%{ /* NOCONTEXT */ |
|
1474 |
||
1475 |
REGISTER int indx; |
|
1476 |
int val, nIndex; |
|
1477 |
REGISTER OBJ slf; |
|
1478 |
REGISTER OBJ cls; |
|
1479 |
||
1480 |
if (__bothSmallInteger(index, byteValue)) { |
|
19451 | 1481 |
val = __intVal(byteValue); |
1482 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
1483 |
slf = self; |
|
1484 |
if (__isNonNilObject(slf)) { |
|
1485 |
cls = __qClass(slf); |
|
1486 |
||
1487 |
indx = __intVal(index) - 1; |
|
1488 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1489 |
case __MASKSMALLINT(BYTEARRAY): |
|
1490 |
case __MASKSMALLINT(WORDARRAY): |
|
1491 |
case __MASKSMALLINT(LONGARRAY): |
|
1492 |
case __MASKSMALLINT(SWORDARRAY): |
|
1493 |
case __MASKSMALLINT(SLONGARRAY): |
|
1494 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1495 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1496 |
case __MASKSMALLINT(FLOATARRAY): |
|
1497 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
1498 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1499 |
nIndex = __byteArraySize(slf); |
|
1500 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1501 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
1502 |
RETURN ( byteValue ); |
|
1503 |
} |
|
1504 |
break; |
|
1505 |
} |
|
1506 |
} |
|
1507 |
} |
|
5755 | 1508 |
} |
1509 |
%}. |
|
1510 |
"/ index not integer or index out of range |
|
1511 |
"/ or non-byte indexable receiver |
|
1512 |
||
1513 |
^ self primitiveFailed |
|
1514 |
||
1515 |
" |
|
1516 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
|
10460 | 1517 |
'hello' copy byteAt:1 put:105; yourself |
5755 | 1518 |
" |
1519 |
! |
|
1520 |
||
1521 |
instVarAt:index |
|
1522 |
"return a non-indexed instance variable; |
|
10460 | 1523 |
peeking into an object this way is not very object oriented |
5755 | 1524 |
- use with care (needed for copy, inspector etc.)" |
1525 |
||
1526 |
%{ /* NOCONTEXT */ |
|
18254 | 1527 |
#ifdef __SCHTEAM__ |
1528 |
return context._RETURN( self.instVarAt(index.intValue()-1) ); |
|
1529 |
#else |
|
5755 | 1530 |
OBJ myClass; |
1531 |
int idx, ninstvars; |
|
1532 |
||
1533 |
if (__isSmallInteger(index)) { |
|
19846 | 1534 |
myClass = __Class(self); |
1535 |
idx = __intVal(index) - 1; |
|
1536 |
/* |
|
1537 |
* do not allow returning of non-object fields. |
|
1538 |
* if subclass did not make provisions for that, |
|
1539 |
* we won't do so here ... |
|
1540 |
*/ |
|
1541 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1542 |
if (idx == 0) { |
|
1543 |
RETURN ( nil ) |
|
1544 |
} |
|
1545 |
} |
|
1546 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1547 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1548 |
// do not trust the ninstvars slot - verify |
|
1549 |
if ((__OBJS2BYTES__(ninstvars) + OHDR_SIZE) <= __qSize(self)) { |
|
1550 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
|
1551 |
} |
|
1552 |
console_printf("[VM] warning: bad ninsts in class\n"); |
|
1553 |
} |
|
5755 | 1554 |
} |
18254 | 1555 |
#endif /* not SCHTEAM */ |
7216 | 1556 |
%}. |
1557 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1558 |
! |
1559 |
||
1560 |
instVarAt:index put:value |
|
1561 |
"change a non-indexed instance variable; |
|
10460 | 1562 |
peeking into an object this way is not very object oriented |
5755 | 1563 |
- use with care (needed for copy, inspector etc.)" |
1564 |
||
1565 |
%{ /* NOCONTEXT */ |
|
18254 | 1566 |
#ifdef __SCHTEAM__ |
1567 |
self.instVarAt_put(index.intValue()-1, value); |
|
1568 |
return context._RETURN( value ); |
|
1569 |
#else |
|
5755 | 1570 |
OBJ myClass; |
1571 |
int idx, ninstvars; |
|
1572 |
||
1573 |
if (__isSmallInteger(index)) { |
|
19846 | 1574 |
myClass = __Class(self); |
1575 |
idx = __intVal(index) - 1; |
|
1576 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1577 |
/* |
|
1578 |
* do not allow setting of non-object fields. |
|
1579 |
* if subclass did not make provisions for that, |
|
1580 |
* we won't do so here ... |
|
1581 |
*/ |
|
1582 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1583 |
if (idx == 0) { |
|
1584 |
RETURN ( nil ) |
|
1585 |
} |
|
1586 |
} |
|
1587 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1588 |
// do not trust the ninstvars slot - verify |
|
1589 |
if ((__OBJS2BYTES__(ninstvars) + OHDR_SIZE) <= __qSize(self)) { |
|
1590 |
__InstPtr(self)->i_instvars[idx] = value; |
|
1591 |
__STORE(self, value); |
|
1592 |
RETURN ( value ); |
|
1593 |
} |
|
1594 |
console_printf("[VM] warning: bad ninsts in class\n"); |
|
1595 |
} |
|
5755 | 1596 |
} |
18254 | 1597 |
#endif /* not SCHTEAM */ |
7216 | 1598 |
%}. |
1599 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1600 |
! |
1601 |
||
10460 | 1602 |
instVarNamed:name |
5755 | 1603 |
"return a non-indexed instance variables value by name; |
10460 | 1604 |
peeking into an object this way is not very object oriented |
5755 | 1605 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1606 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1607 |
parsed ad runtime)" |
|
1608 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1609 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1610 |
|
15449 | 1611 |
idx := self class instVarIndexFor:name. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1612 |
idx isNil ifTrue:[ |
19846 | 1613 |
^ self errorKeyNotFound:name. |
11335 | 1614 |
]. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1615 |
^ self instVarAt:idx. |
5755 | 1616 |
|
1617 |
||
1618 |
" |
|
1619 |
|p| |
|
1620 |
||
1621 |
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
|
1622 |
p instVarNamed:'cx' |
5755 | 1623 |
" |
1624 |
||
1625 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
|
1626 |
! |
|
1627 |
||
1628 |
instVarNamed:name ifAbsent:exceptionBlock |
|
1629 |
"return a non-indexed instance variables value by name, |
|
1630 |
or the value of exceptionBlock, if there is no such instance variable. |
|
10460 | 1631 |
peeking into an object this way is not very object oriented |
5755 | 1632 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1633 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1634 |
parsed ad runtime)" |
|
1635 |
||
1636 |
|idx| |
|
1637 |
||
15449 | 1638 |
idx := self class instVarIndexFor:name. |
5755 | 1639 |
idx isNil ifTrue:[^ exceptionBlock value]. |
1640 |
^ self instVarAt:idx |
|
1641 |
||
1642 |
||
1643 |
" |
|
1644 |
|p| |
|
1645 |
||
1646 |
p := Point x:10 y:20. |
|
10460 | 1647 |
p instVarNamed:'x' |
5755 | 1648 |
" |
1649 |
||
1650 |
"Created: 6.7.1996 / 23:02:49 / cg" |
|
1651 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
|
1652 |
! |
|
1653 |
||
1654 |
instVarNamed:name put:value |
|
1655 |
"set a non-indexed instance variable by name; |
|
10460 | 1656 |
peeking into an object this way is not very object oriented |
5755 | 1657 |
- if at all, use with care (provided for protocol completeness). |
1658 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1659 |
parsed ad runtime)" |
|
1660 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1661 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1662 |
|
15449 | 1663 |
idx := self class instVarIndexFor:name. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1664 |
idx isNil ifTrue:[ |
19846 | 1665 |
^ self errorKeyNotFound:name. |
11335 | 1666 |
]. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1667 |
^ self instVarAt:idx put:value. |
5755 | 1668 |
|
1669 |
" |
|
1670 |
|p| |
|
1671 |
||
1672 |
p := Point x:10 y:20. |
|
1673 |
p instVarNamed:'x' put:30. |
|
10460 | 1674 |
p |
5755 | 1675 |
" |
1676 |
||
1677 |
"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
|
1678 |
! |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1679 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1680 |
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
|
1681 |
"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
|
1682 |
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
|
1683 |
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
|
1684 |
- 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
|
1685 |
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
|
1686 |
parsed ad runtime)" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1687 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1688 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1689 |
|
15449 | 1690 |
idx := self class instVarIndexFor:name. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1691 |
idx isNil ifTrue:[^ exceptionBlock value]. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1692 |
^ self instVarAt:idx put:anObject. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1693 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1694 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1695 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1696 |
|p| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1697 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1698 |
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
|
1699 |
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
|
1700 |
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
|
1701 |
p inspect. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1702 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1703 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1704 |
"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
|
1705 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
16125 | 1706 |
! |
1707 |
||
1708 |
nilAllInstvars |
|
18254 | 1709 |
"overwrite all inst vars of the object with nil. |
1710 |
Used by the crypto package to clear objects with |
|
1711 |
keys when no longer in use." |
|
16230 | 1712 |
|
16125 | 1713 |
%{ /* NOCONTEXT */ |
1714 |
int flags; |
|
1715 |
||
1716 |
if (!__isNonNilObject(self)) { |
|
19846 | 1717 |
RETURN(self); |
16125 | 1718 |
} |
1719 |
/* |
|
1720 |
* bail out for special (weak) objects .. |
|
1721 |
*/ |
|
1722 |
flags = __intVal(__ClassInstPtr(__qClass(self))->c_flags); |
|
1723 |
if (((flags & ~ARRAYMASK) == 0) |
|
19846 | 1724 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY) |
16125 | 1725 |
) { |
19846 | 1726 |
bzero((void *)__InstPtr(self)->i_instvars, __qSize(self)-OHDR_SIZE); |
1727 |
RETURN(self); |
|
16125 | 1728 |
} |
1729 |
%}. |
|
1730 |
"/ fail for special objects |
|
1731 |
^ self primitiveFailed |
|
1732 |
||
1733 |
" |
|
1734 |
'abcdef' copy nilAllInstvars |
|
1735 |
100 factorial nilAllInstvars |
|
1736 |
" |
|
5755 | 1737 |
! ! |
1738 |
||
1739 |
!Object methodsFor:'attributes access'! |
|
1740 |
||
10460 | 1741 |
objectAttributeAt:attributeKey |
5755 | 1742 |
"return the attribute for a given key or nil if not found" |
1743 |
||
1744 |
| attrs | |
|
1745 |
||
1746 |
attrs := self objectAttributes. |
|
17174 | 1747 |
attrs size ~~ 0 ifTrue:[ |
19846 | 1748 |
^ attrs at:attributeKey ifAbsent:[] |
5755 | 1749 |
]. |
1750 |
^ nil |
|
1751 |
||
1752 |
"Created: / 22.1.1998 / 21:29:17 / av" |
|
1753 |
"Modified: / 3.2.1998 / 18:55:55 / cg" |
|
1754 |
! |
|
1755 |
||
6323 | 1756 |
objectAttributeAt:attributeKey put:anObject |
5755 | 1757 |
"store the attribute anObject referenced by key into the receiver" |
1758 |
||
16291 | 1759 |
"/ must do this save from being reentered, since the attributes collection |
1760 |
"/ is possibly accessed from multiple threads... |
|
1761 |
ObjectAttributesAccessLock critical:[ |
|
19846 | 1762 |
| attrs | |
1763 |
||
1764 |
attrs := self objectAttributes. |
|
1765 |
"/ only need a WeakIdentityDictionary, if there are any non-symbol keys in |
|
1766 |
"/ it. Start with a regular IDDict, and migrate to WeakIDDict if ever required. |
|
1767 |
"/ Typically, this never happens (but does in the UIPainter!!) |
|
1768 |
attrs isEmptyOrNil ifTrue:[ |
|
1769 |
attributeKey isSymbol ifTrue:[ |
|
1770 |
attrs := IdentityDictionary new. |
|
1771 |
] ifFalse:[ |
|
1772 |
attrs := WeakIdentityDictionary new. |
|
1773 |
]. |
|
1774 |
attrs at:attributeKey put:anObject. |
|
1775 |
self objectAttributes:attrs. |
|
1776 |
] ifFalse:[ |
|
1777 |
attributeKey isSymbol ifFalse:[ |
|
1778 |
attrs isWeakCollection ifFalse:[ |
|
1779 |
"first non-symbol attributeKey - convert to WeakIdentityDictionary" |
|
1780 |
attrs := WeakIdentityDictionary new declareAllFrom:attrs. |
|
1781 |
self objectAttributes:attrs. |
|
1782 |
]. |
|
1783 |
]. |
|
1784 |
attrs at:attributeKey put:anObject. |
|
1785 |
]. |
|
16291 | 1786 |
] |
5755 | 1787 |
|
1788 |
"Attaching additional attributes (slots) to an arbitrary object: |
|
1789 |
||
1790 |
|p| |
|
1791 |
||
1792 |
p := Point new. |
|
1793 |
p objectAttributeAt:#color put:#green. |
|
1794 |
||
1795 |
p objectAttributeAt:#color |
|
1796 |
" |
|
1797 |
||
1798 |
"Created: / 22.1.1998 / 21:29:25 / av" |
|
1799 |
"Modified: / 3.2.1998 / 18:57:58 / cg" |
|
1800 |
! |
|
1801 |
||
1802 |
objectAttributes |
|
1803 |
"return a Collection of attributes - nil if there is none. |
|
1804 |
The default implementation here uses a global WeakDictionary to store |
|
1805 |
attributes |
|
1806 |
This may be too slow for high frequency slot access, |
|
13416 | 1807 |
therefore, some classes may redefine this for better performnce. |
5755 | 1808 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
1809 |
||
1810 |
^ ObjectAttributes at:self ifAbsent:[nil] |
|
1811 |
||
1812 |
"Created: / 22.1.1998 / 21:29:30 / av" |
|
1813 |
"Modified: / 18.2.2000 / 11:34:16 / cg" |
|
1814 |
! |
|
1815 |
||
1816 |
objectAttributes:aCollection |
|
1817 |
"set the collection of attributes. |
|
1818 |
The default implementation here uses a global Dictionary to store |
|
1819 |
attributes which may be too slow for high frequency change&update. |
|
1820 |
Therefore, some classes may redefine this for better performance." |
|
1821 |
||
16291 | 1822 |
"/ must do this save from being reentered, since the attributes collection |
5755 | 1823 |
"/ is possibly accessed from multiple threads. |
1824 |
||
16291 | 1825 |
ObjectAttributesAccessLock critical:[ |
19846 | 1826 |
aCollection isEmptyOrNil ifTrue:[ |
1827 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1828 |
] ifFalse:[ |
|
1829 |
ObjectAttributes at:self put:aCollection |
|
1830 |
]. |
|
5755 | 1831 |
] |
1832 |
||
1833 |
"Created: / 22.1.1998 / 21:29:35 / av" |
|
1834 |
"Modified: / 3.2.1998 / 18:58:10 / cg" |
|
1835 |
! |
|
1836 |
||
6323 | 1837 |
removeObjectAttribute:attributeKey |
19846 | 1838 |
"remove an object attribute; |
1839 |
return the value previously stored there, or nil. |
|
1840 |
(make the argument, anObject be no longer an attribute of the receiver)" |
|
1841 |
||
1842 |
|oldVal| |
|
1843 |
||
16291 | 1844 |
"/ must do this save from being reentered, since the attributes collection |
5755 | 1845 |
"/ is possibly accessed from multiple threads. |
16291 | 1846 |
ObjectAttributesAccessLock critical:[ |
19846 | 1847 |
|attrs| |
1848 |
||
1849 |
attrs := self objectAttributes. |
|
1850 |
attrs notNil ifTrue:[ |
|
1851 |
attrs size ~~ 0 ifTrue:[ |
|
1852 |
oldVal := attrs removeKey:attributeKey ifAbsent:nil. |
|
1853 |
]. |
|
1854 |
attrs size == 0 ifTrue:[ |
|
1855 |
self objectAttributes:nil |
|
1856 |
]. |
|
1857 |
] |
|
1858 |
]. |
|
1859 |
^ oldVal |
|
5755 | 1860 |
|
1861 |
"Created: / 22.1.1998 / 21:29:39 / av" |
|
1862 |
"Modified: / 18.2.2000 / 11:32:19 / cg" |
|
1863 |
! ! |
|
1864 |
||
13500 | 1865 |
|
5755 | 1866 |
!Object methodsFor:'change & update'! |
1867 |
||
1868 |
broadcast:aSelectorSymbol |
|
1869 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1870 |
||
10460 | 1871 |
self dependentsDo:[:dependent | |
19846 | 1872 |
dependent perform:aSelectorSymbol |
5755 | 1873 |
] |
1874 |
! |
|
1875 |
||
1876 |
broadcast:aSelectorSymbol with:anArgument |
|
1877 |
"send a message with selector aSelectorSymbol with an additional |
|
1878 |
argument anArgument to all my dependents." |
|
1879 |
||
10460 | 1880 |
self dependentsDo:[:dependent | |
19846 | 1881 |
dependent perform:aSelectorSymbol with:anArgument |
5755 | 1882 |
] |
1883 |
! |
|
1884 |
||
1885 |
changeRequest |
|
1886 |
"the receiver wants to change - check if all dependents |
|
1887 |
grant the request, and return true if so" |
|
1888 |
||
10460 | 1889 |
self dependentsDo:[:dependent | |
19846 | 1890 |
dependent updateRequest ifFalse:[^ false]. |
5755 | 1891 |
]. |
1892 |
^ true |
|
1893 |
! |
|
1894 |
||
11551 | 1895 |
changeRequest:aSymbol |
5755 | 1896 |
"the receiver wants to change - check if all dependents |
1897 |
grant the request, and return true if so" |
|
1898 |
||
10460 | 1899 |
self dependentsDo:[:dependent | |
19846 | 1900 |
(dependent updateRequest:aSymbol) ifFalse:[^ false]. |
5755 | 1901 |
]. |
1902 |
^ true |
|
1903 |
! |
|
1904 |
||
11551 | 1905 |
changeRequest:aSymbol from:anObject |
1906 |
"the receiver wants to change - check if all dependents |
|
1907 |
except anObject grant the request, and return true if so. |
|
1908 |
The argument anObject is typically going to be the one who is |
|
1909 |
about to send the change request." |
|
1910 |
||
1911 |
^ self changeRequest:aSymbol with:nil from:anObject |
|
1912 |
! |
|
1913 |
||
1914 |
changeRequest:aSymbol with:aParameter |
|
1915 |
"the receiver wants to change - check if all dependents |
|
1916 |
grant the request, and return true if so" |
|
1917 |
||
11573 | 1918 |
^ self changeRequest:aSymbol with:aParameter from:self |
11551 | 1919 |
! |
1920 |
||
1921 |
changeRequest:aSymbol with:aParameter from:anObject |
|
5755 | 1922 |
"the receiver wants to change - check if all dependents |
1923 |
except anObject grant the request, and return true if so. |
|
1924 |
The argument anObject is typically going to be the one who is |
|
1925 |
about to send the change request." |
|
1926 |
||
10460 | 1927 |
self dependentsDo:[:dependent | |
19846 | 1928 |
dependent == anObject ifFalse:[ |
1929 |
(dependent updateRequest:aSymbol with:aParameter from:anObject) ifFalse:[^ false]. |
|
1930 |
] |
|
5755 | 1931 |
]. |
1932 |
^ true |
|
1933 |
! |
|
1934 |
||
1935 |
changeRequestFrom:anObject |
|
1936 |
"the receiver wants to change - check if all dependents |
|
1937 |
except anObject grant the request, and return true if so. |
|
1938 |
The argument anObject is typically going to be the one who is |
|
1939 |
about to send the change request." |
|
1940 |
||
10460 | 1941 |
self dependentsDo:[:dependent | |
19846 | 1942 |
dependent == anObject ifFalse:[ |
1943 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1944 |
] |
|
5755 | 1945 |
]. |
1946 |
^ true |
|
1947 |
! |
|
1948 |
||
1949 |
changed |
|
1950 |
"notify all dependents that the receiver has changed. |
|
1951 |
Each dependent gets a '#update:'-message with the original |
|
1952 |
receiver as argument." |
|
1953 |
||
1954 |
self changed:nil |
|
1955 |
! |
|
1956 |
||
1957 |
changed:aParameter |
|
1958 |
"notify all dependents that the receiver has changed somehow. |
|
1959 |
Each dependent gets a '#update:'-message with aParameter |
|
1960 |
as argument." |
|
1961 |
||
1962 |
self changed:aParameter with:nil |
|
1963 |
! |
|
1964 |
||
1965 |
changed:aParameter with:anArgument |
|
1966 |
"notify all dependents that the receiver has changed somehow. |
|
19583 | 1967 |
Each dependent gets an '#update:with:from:'-message, with aParameter |
5755 | 1968 |
and anArgument as arguments." |
1969 |
||
10460 | 1970 |
self dependentsDo:[:dependent | |
19583 | 1971 |
dependent update:aParameter with:anArgument from:self |
5755 | 1972 |
] |
1973 |
! |
|
1974 |
||
1975 |
update:aParameter |
|
1976 |
"the message is sent to a dependent, when one of the objects |
|
1977 |
on whom the receiver depends, has changed. The argument aParameter |
|
1978 |
is either the changed object or the argument to the #changed: message. |
|
1979 |
||
1980 |
Default behavior here is to do nothing" |
|
1981 |
||
1982 |
^ self |
|
1983 |
! |
|
1984 |
||
1985 |
update:aParameter with:anArgument |
|
1986 |
"dependent is notified of some change - |
|
1987 |
Default is to try update:" |
|
1988 |
||
1989 |
^ self update:aParameter |
|
1990 |
! |
|
1991 |
||
1992 |
update:aParameter with:anArgument from:sender |
|
1993 |
"dependent is notified of some change - |
|
1994 |
Default is to try update:with:" |
|
1995 |
||
1996 |
^ self update:aParameter with:anArgument |
|
1997 |
! |
|
1998 |
||
1999 |
updateRequest |
|
2000 |
"return true, if an update request is granted. |
|
2001 |
Default here is to grant updates - may be used |
|
2002 |
to lock updates if someone is making other changes |
|
2003 |
from within an update. Or if someone has locked its |
|
2004 |
state and does not want others to change things. |
|
2005 |
However, these dependents must all honor the |
|
2006 |
changeRequest - ifTrue - change protocol. I.e. they |
|
2007 |
must first ask all others via changeRequest, and only do the change |
|
2008 |
it returns true. The others must decide in updateRequest and |
|
2009 |
return true if they think a change is ok." |
|
2010 |
||
2011 |
^ true |
|
2012 |
! |
|
2013 |
||
2014 |
updateRequest:aSymbol |
|
2015 |
"return true, if an update request is granted. |
|
2016 |
Default here a simple updateRequest" |
|
2017 |
||
2018 |
^ self updateRequest |
|
7177 | 2019 |
! |
2020 |
||
11551 | 2021 |
updateRequest:aSymbol with:aParameter |
2022 |
"return true, if an update request is granted. |
|
2023 |
Default here a simple updateRequest" |
|
2024 |
||
2025 |
^ self updateRequest:aSymbol |
|
2026 |
! |
|
2027 |
||
2028 |
updateRequest:aSymbol with:aParameter from:sender |
|
2029 |
"return true, if an update request is granted. |
|
2030 |
Default here a simple updateRequest" |
|
2031 |
||
2032 |
^ self updateRequest:aSymbol with:aParameter |
|
2033 |
! |
|
2034 |
||
7177 | 2035 |
withoutUpdating:someone do:aBlock |
2036 |
"evaluate a block but remove someone from my dependents temporarily" |
|
2037 |
||
2038 |
(self dependents includesIdentical:someone) |
|
2039 |
ifFalse:[ |
|
19846 | 2040 |
^ aBlock value. |
7177 | 2041 |
]. |
2042 |
self removeDependent:someone. |
|
2043 |
^ aBlock ensure:[ self addDependent:someone ] |
|
5755 | 2044 |
! ! |
2045 |
||
2046 |
!Object methodsFor:'comparing'! |
|
2047 |
||
14975 | 2048 |
= anObject |
2049 |
"return true, if the receiver and the arg have the same structure. |
|
2050 |
Notice: |
|
19846 | 2051 |
This method is partially open coded (inlined) by the compiler(s) |
2052 |
identical objects are always considered equal. |
|
2053 |
redefining it may not work as expected." |
|
14975 | 2054 |
|
2055 |
^ self == anObject |
|
2056 |
! |
|
2057 |
||
5755 | 2058 |
== anObject |
2059 |
"return true, if the receiver and the arg are the same object. |
|
2060 |
Never redefine this in any class. |
|
2061 |
Notice: |
|
19846 | 2062 |
This method is open coded (inlined) by the compiler(s) |
2063 |
- redefining it may not work as expected." |
|
5755 | 2064 |
|
2065 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
2066 |
#ifdef __SCHTEAM__ |
18361 | 2067 |
return context._RETURN( (self == anObject) ? STObject.True : STObject.False ); |
18231 | 2068 |
#else |
5755 | 2069 |
RETURN ( (self == anObject) ? true : false ); |
18231 | 2070 |
#endif |
5755 | 2071 |
%} |
2072 |
! |
|
2073 |
||
5814 | 2074 |
deepSameContentsAs:anObject |
2075 |
"return true, if the receiver and the arg have the same contents |
|
2076 |
in both the named instance vars and any indexed instVars. |
|
2077 |
This method descends into referenced objects, where #sameContentsAs: does not descend" |
|
2078 |
||
5821 | 2079 |
|myClass val |
5814 | 2080 |
sz "{ Class: SmallInteger }" | |
2081 |
||
2082 |
myClass := self class. |
|
2083 |
myClass isVariable ifTrue:[ |
|
19846 | 2084 |
sz := self basicSize. |
2085 |
||
2086 |
"compare the indexed variables" |
|
2087 |
1 to:sz do:[:i | |
|
2088 |
val := self basicAt:i. |
|
2089 |
val isLiteral ifTrue:[ |
|
2090 |
val = (anObject basicAt:i) ifFalse:[^ false]. |
|
2091 |
] ifFalse:[ |
|
2092 |
(val deepSameContentsAs:(anObject basicAt:i)) ifFalse:[^ false]. |
|
2093 |
] |
|
2094 |
] |
|
5814 | 2095 |
]. |
2096 |
||
2097 |
"compare the instance variables" |
|
2098 |
sz := myClass instSize. |
|
10460 | 2099 |
1 to:sz do:[:i | |
19846 | 2100 |
val := self instVarAt:i. |
2101 |
val isLiteral ifTrue:[ |
|
2102 |
val = (anObject instVarAt:i) ifFalse:[^ false]. |
|
2103 |
] ifFalse:[ |
|
2104 |
(val deepSameContentsAs:(anObject instVarAt:i)) ifFalse:[^ false]. |
|
2105 |
] |
|
5814 | 2106 |
]. |
2107 |
||
2108 |
^ true |
|
2109 |
||
2110 |
" |
|
10460 | 2111 |
#(1 2 3 4) deepSameContentsAs:#[1 2 3 4] asArray |
5814 | 2112 |
(1@2) deepSameContentsAs:(1->2) |
2113 |
" |
|
2114 |
! |
|
2115 |
||
5755 | 2116 |
hash |
2117 |
"return an Integer useful as a hash key for the receiver. |
|
2118 |
This hash should return same values for objects with same |
|
2119 |
contents (i.e. use this to hash on structure)" |
|
2120 |
||
2121 |
^ self identityHash |
|
2122 |
! |
|
2123 |
||
2124 |
identityHash |
|
2125 |
"return an Integer useful as a hash key for the receiver. |
|
2126 |
This hash should return same values for the same object (i.e. use |
|
2127 |
this to hash on identity of objects). |
|
2128 |
||
2129 |
We cannot use the Objects address (as other smalltalks do) since |
|
2130 |
no object-table exists and the hashval must not change when objects |
|
2131 |
are moved by the collector. Therefore we assign each object a unique |
|
2132 |
Id in the object header itself as its hashed upon. |
|
2133 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
2134 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
2135 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
2136 |
hashed-upon objects could add an instvar containing the hash value." |
|
2137 |
||
2138 |
%{ /* NOCONTEXT */ |
|
2139 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2140 |
REGISTER unsigned INT hash; |
5755 | 2141 |
static unsigned nextHash = 0; |
2142 |
||
2143 |
if (__isNonNilObject(self)) { |
|
19846 | 2144 |
hash = __GET_HASH(self); |
2145 |
if (hash == 0) { |
|
2146 |
/* has no hash yet */ |
|
2147 |
||
2148 |
if (++nextHash > __MAX_HASH__) { |
|
2149 |
nextHash = 1; |
|
2150 |
} |
|
2151 |
hash = nextHash; |
|
2152 |
__SET_HASH(self, hash); |
|
2153 |
} |
|
2154 |
||
2155 |
/* |
|
2156 |
* now, we got 11 bits for hashing; |
|
2157 |
* make it as large as possible; since most hashers use the returned |
|
2158 |
* key and take it modulo some prime number, this will allow for |
|
2159 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2160 |
*/ |
|
2161 |
hash = __MAKE_HASH__(hash); |
|
2162 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 2163 |
} |
2164 |
%}. |
|
2165 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
2166 |
! |
|
2167 |
||
2168 |
identityHashForBinaryStore |
|
2169 |
"hash which is usable if the object does not change its class |
|
2170 |
and does not #become something else, while the hash is used. |
|
2171 |
This is only used by the binary storage mechanism, during the |
|
2172 |
object writing phase." |
|
2173 |
||
2174 |
%{ /* NOCONTEXT */ |
|
2175 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2176 |
REGISTER unsigned INT hash, hash1, hash2, sz; |
5755 | 2177 |
OBJ o; |
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2178 |
static unsigned INT nextHash = 0; |
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2179 |
static unsigned INT nextClassHash = 0; |
5755 | 2180 |
|
2181 |
if (__isNonNilObject(self)) { |
|
19846 | 2182 |
/* |
2183 |
* my own identityHash |
|
2184 |
*/ |
|
2185 |
hash1 = __GET_HASH(self); |
|
2186 |
if (hash1 == 0) { |
|
2187 |
/* has no hash yet */ |
|
2188 |
||
2189 |
if (++nextHash > __MAX_HASH__) { |
|
2190 |
nextHash = 1; |
|
2191 |
} |
|
2192 |
hash1 = nextHash; |
|
2193 |
__SET_HASH(self, hash1); |
|
2194 |
} |
|
2195 |
/* |
|
2196 |
* my classes identityHash |
|
2197 |
*/ |
|
2198 |
o = __qClass(self); |
|
2199 |
hash2 = __GET_HASH(o); |
|
2200 |
if (hash2 == 0) { |
|
2201 |
/* has no hash yet */ |
|
2202 |
||
2203 |
if (++nextClassHash > __MAX_HASH__) { |
|
2204 |
nextClassHash = 1; |
|
2205 |
} |
|
2206 |
hash2 = nextClassHash; |
|
2207 |
__SET_HASH(o, hash2); |
|
2208 |
} |
|
2209 |
||
2210 |
/* |
|
2211 |
* some bits of my size |
|
2212 |
*/ |
|
2213 |
sz = __qSize(self); |
|
2214 |
||
2215 |
/* |
|
2216 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
2217 |
* make it as large as possible; since most hashers use the returned |
|
2218 |
* key and take it modulo some prime number, this will allow for |
|
2219 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2220 |
*/ |
|
2221 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
2222 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
2223 |
||
2224 |
while ((hash & 0x20000000) == 0) { |
|
2225 |
hash <<= 1; |
|
2226 |
} |
|
2227 |
||
2228 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 2229 |
} |
2230 |
%}. |
|
2231 |
"never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
|
2232 |
^ self identityHash |
|
2233 |
! |
|
2234 |
||
2235 |
sameContentsAs:anObject |
|
2236 |
"return true, if the receiver and the arg have the same contents |
|
7121 | 2237 |
in both the named instance vars and any indexed instVars. |
2238 |
The code here only checks if values present in the receiver are also |
|
2239 |
present in the arg, not vice versa. |
|
2240 |
I.e. the argument may be bigger and/or have more instance variables." |
|
5755 | 2241 |
|
5821 | 2242 |
|myClass |
5755 | 2243 |
sz "{ Class: SmallInteger }" | |
2244 |
||
2245 |
myClass := self class. |
|
2246 |
myClass isVariable ifTrue:[ |
|
19846 | 2247 |
sz := self basicSize. |
2248 |
anObject basicSize >= sz ifFalse:[^ false]. |
|
2249 |
||
2250 |
"compare the indexed variables" |
|
2251 |
1 to:sz do:[:i | |
|
2252 |
(self basicAt:i) == (anObject basicAt:i) ifFalse:[^ false]. |
|
2253 |
] |
|
5755 | 2254 |
]. |
2255 |
||
2256 |
"compare the instance variables" |
|
2257 |
sz := myClass instSize. |
|
12997 | 2258 |
anObject class instSize >= sz ifFalse:[^ false]. |
7121 | 2259 |
|
10460 | 2260 |
1 to:sz do:[:i | |
19846 | 2261 |
(self instVarAt:i) == (anObject instVarAt:i) ifFalse:[^ false]. |
5755 | 2262 |
]. |
2263 |
||
2264 |
^ true |
|
2265 |
||
2266 |
" |
|
10460 | 2267 |
#(1 2 3 4) sameContentsAs:#[1 2 3 4] asArray |
5814 | 2268 |
(1@2) sameContentsAs:(1->2) |
5755 | 2269 |
" |
2270 |
||
12997 | 2271 |
"Created: / 21-04-1998 / 15:56:40 / cg" |
2272 |
"Modified: / 05-08-2010 / 16:44:09 / sr" |
|
5755 | 2273 |
! |
2274 |
||
2275 |
~= anObject |
|
2276 |
"return true, if the receiver and the arg do not have the same structure. |
|
2277 |
Notice: |
|
19846 | 2278 |
This method is partially open coded (inlined) by the compiler(s) |
2279 |
identical objects are never considered unequal. |
|
2280 |
redefining it may not work as expected." |
|
5755 | 2281 |
|
2282 |
^ (self = anObject) not |
|
2283 |
! |
|
2284 |
||
2285 |
~~ anObject |
|
2286 |
"return true, if the receiver and the arg are not the same object. |
|
2287 |
Never redefine this in any class. |
|
2288 |
Notice: |
|
19846 | 2289 |
This method is open coded (inlined) by the compiler(s) |
2290 |
- redefining it may not work as expected." |
|
5755 | 2291 |
|
2292 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
2293 |
#ifdef __SCHTEAM__ |
18361 | 2294 |
return context._RETURN( (self == anObject) ? STObject.False : STObject.True ); |
18231 | 2295 |
#else |
5755 | 2296 |
RETURN ( (self == anObject) ? false : true ); |
18231 | 2297 |
#endif |
5755 | 2298 |
%} |
2299 |
! ! |
|
2300 |
||
2301 |
!Object methodsFor:'converting'! |
|
2302 |
||
2303 |
-> anObject |
|
2304 |
"return an association with the receiver as key and |
|
2305 |
the argument as value" |
|
2306 |
||
2307 |
^ Association key:self value:anObject |
|
2308 |
! |
|
2309 |
||
10062 | 2310 |
as:aSimilarClass |
16052 | 2311 |
"If the receiver's class is not aSimilarClass, |
2312 |
create and return an instance of aSimilarClass that has the same contents |
|
10062 | 2313 |
as the receiver. |
2314 |
Otherwise, return the receiver." |
|
2315 |
||
2316 |
self class == aSimilarClass ifTrue:[^ self]. |
|
2317 |
^ aSimilarClass newFrom:self |
|
2318 |
||
2319 |
" |
|
2320 |
#[1 2 3 4] as:ByteArray |
|
2321 |
#[1 2 3 4] as:Array |
|
10539 | 2322 |
#[81 82 83 84] as:String |
2323 |
#[81 82 83 84] as:Symbol |
|
16052 | 2324 |
'hello' as:Unicode16String |
10062 | 2325 |
" |
2326 |
! |
|
2327 |
||
5755 | 2328 |
asCollection |
2329 |
"return myself as a Collection. |
|
2330 |
Redefined in collection to return themself." |
|
2331 |
||
2332 |
^ Array with:self |
|
2333 |
! |
|
2334 |
||
17261 | 2335 |
asLink |
2336 |
"return a valueLink for the receiver. |
|
2337 |
Used to make sure the receiver can be added to a linked list" |
|
2338 |
||
2339 |
^ ValueLink value:self |
|
2340 |
! |
|
2341 |
||
5755 | 2342 |
asSequenceableCollection |
2343 |
"return myself as a SequenceableCollection. |
|
2344 |
Redefined in SequenceableCollection" |
|
2345 |
||
2346 |
^ Array with:self |
|
2347 |
! |
|
2348 |
||
14355 | 2349 |
asString |
2350 |
^ self printString |
|
2351 |
! |
|
2352 |
||
5755 | 2353 |
asValue |
2354 |
"return a valueHolder for for the receiver" |
|
2355 |
||
2356 |
^ ValueHolder with:self |
|
2357 |
! ! |
|
2358 |
||
2359 |
!Object methodsFor:'copying'! |
|
2360 |
||
10460 | 2361 |
cloneFrom:anObject |
5755 | 2362 |
"Helper for copy: |
2363 |
copy all instance variables from anObject into the receiver, |
|
2364 |
which should be of the same class as the argument." |
|
2365 |
||
2366 |
self cloneFrom:anObject performing:#yourself |
|
2367 |
||
2368 |
" |
|
2369 |
|x| |
|
2370 |
||
2371 |
x := Array new:3. |
|
2372 |
x cloneFrom:#(1 2 3). |
|
2373 |
" |
|
2374 |
! |
|
2375 |
||
2376 |
cloneFrom:anObject performing:aSymbol |
|
2377 |
"Helper for copy: |
|
8383 | 2378 |
for each instance variable from anObject, send it aSymbol |
5755 | 2379 |
and store the result into the receiver, |
2380 |
which should be of the same class as the argument." |
|
2381 |
||
2382 |
|myClass sz "{ Class: SmallInteger }" t | |
|
2383 |
||
2384 |
myClass := self class. |
|
14532 | 2385 |
|
2386 |
"process the named instance variables" |
|
2387 |
sz := myClass instSize. |
|
2388 |
1 to:sz do:[:i | |
|
19846 | 2389 |
t := anObject instVarAt:i. |
2390 |
aSymbol ~~ #yourself ifTrue:[ |
|
2391 |
t := t perform:aSymbol |
|
2392 |
]. |
|
2393 |
self instVarAt:i put:t |
|
14532 | 2394 |
]. |
2395 |
||
5755 | 2396 |
myClass isVariable ifTrue:[ |
19846 | 2397 |
sz := self basicSize. |
2398 |
||
2399 |
"process the indexed instance variables" |
|
2400 |
1 to:sz do:[:i | |
|
2401 |
t := anObject basicAt:i. |
|
2402 |
aSymbol ~~ #yourself ifTrue:[ |
|
2403 |
t := t perform:aSymbol. |
|
2404 |
]. |
|
2405 |
self basicAt:i put:t. |
|
2406 |
] |
|
5755 | 2407 |
]. |
2408 |
! |
|
2409 |
||
2410 |
cloneInstanceVariablesFrom:aPrototype |
|
2411 |
"Shallow copy variables from a prototype into myself. |
|
2412 |
This copies instVars by name - i.e. same-named variables are |
|
2413 |
copied, others are not. |
|
10460 | 2414 |
The variable slots are copied as available |
5755 | 2415 |
(i.e. the min of both indexed sizes is used)." |
10460 | 2416 |
|
19272 | 2417 |
|myClass prototypesClass myInfo prototypesInfo |
2418 |
sz "{ Class: SmallInteger }"| |
|
14676 | 2419 |
|
2420 |
myClass := self class. |
|
2421 |
prototypesClass := aPrototype class. |
|
2422 |
(myClass == prototypesClass |
|
19272 | 2423 |
or:[myClass isSubclassOf:prototypesClass]) ifTrue:[ |
2424 |
"/ can do better, if my class is a subclass of the prototype's class |
|
2425 |
sz := prototypesClass instSize. |
|
2426 |
1 to: sz do:[:index | |
|
2427 |
self instVarAt:index put:(aPrototype instVarAt:index) |
|
2428 |
] |
|
14676 | 2429 |
] ifFalse:[ |
19272 | 2430 |
"/ map instvars by name |
2431 |
myInfo := myClass instanceVariableOffsets. |
|
2432 |
prototypesInfo := prototypesClass instanceVariableOffsets. |
|
2433 |
myInfo keysAndValuesDo:[:name :index | |varIndexAssoc| |
|
2434 |
varIndexAssoc := prototypesInfo at:name ifAbsent:[]. |
|
2435 |
varIndexAssoc notNil ifTrue:[ |
|
2436 |
self instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
2437 |
] |
|
2438 |
] |
|
14676 | 2439 |
]. |
2440 |
myClass isVariable ifTrue:[ |
|
19272 | 2441 |
prototypesClass isVariable ifTrue:[ |
2442 |
sz := self basicSize min:aPrototype basicSize. |
|
2443 |
1 to:sz do:[:index | |
|
2444 |
self basicAt:index put:(aPrototype basicAt:index) |
|
2445 |
]. |
|
2446 |
]. |
|
5755 | 2447 |
]. |
2448 |
||
2449 |
" |
|
2450 |
Class withoutUpdatingChangesDo:[ |
|
19272 | 2451 |
|point3D| |
2452 |
||
2453 |
point3D := Point subclass:#Point3D |
|
2454 |
instanceVariableNames:'z' |
|
2455 |
classVariableNames:'' |
|
2456 |
poolDictionaries:'' |
|
2457 |
category:'testing' |
|
2458 |
inEnvironment:nil. |
|
2459 |
(point3D new cloneInstanceVariablesFrom:1@2) inspect. |
|
5755 | 2460 |
] |
2461 |
" |
|
2462 |
||
2463 |
" |
|
2464 |
Class withoutUpdatingChangesDo:[ |
|
19272 | 2465 |
Point variableSubclass:#Point3D_test |
2466 |
instanceVariableNames:'z' |
|
2467 |
classVariableNames:'' |
|
2468 |
poolDictionaries:'' |
|
2469 |
category:'testing'. |
|
2470 |
(((Smalltalk at:#Point3D_test) new:2) cloneInstanceVariablesFrom:#(1 2 3)) inspect. |
|
5755 | 2471 |
] |
2472 |
" |
|
2473 |
||
2474 |
" |
|
2475 |
|someObject| |
|
2476 |
||
2477 |
Class withoutUpdatingChangesDo:[ |
|
19272 | 2478 |
Object subclass:#TestClass1 |
2479 |
instanceVariableNames:'foo bar' |
|
2480 |
classVariableNames:'' |
|
2481 |
poolDictionaries:'' |
|
2482 |
category:'testing'. |
|
2483 |
someObject := TestClass1 new. |
|
2484 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
2485 |
Object subclass:#TestClass2 |
|
2486 |
instanceVariableNames:'bar foo' |
|
2487 |
classVariableNames:'' |
|
2488 |
poolDictionaries:'' |
|
2489 |
category:'testing'. |
|
2490 |
(TestClass2 new cloneInstanceVariablesFrom:someObject) inspect. |
|
5755 | 2491 |
] |
2492 |
" |
|
2493 |
||
2494 |
" |
|
2495 |
|top b b1| |
|
2496 |
||
2497 |
top := StandardSystemView new. |
|
2498 |
top extent:100@100. |
|
2499 |
||
2500 |
b := Button in:top. |
|
2501 |
b label:'hello'. |
|
2502 |
||
2503 |
b1 := ArrowButton new cloneInstanceVariablesFrom:b. |
|
2504 |
||
2505 |
top open. |
|
2506 |
b1 inspect |
|
2507 |
" |
|
2508 |
! |
|
2509 |
||
2510 |
copy |
|
2511 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
2512 |
Notice, that copy does not copy dependents." |
|
2513 |
||
2514 |
^ self shallowCopy postCopy |
|
2515 |
! |
|
2516 |
||
6146 | 2517 |
copyToLevel:level |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2518 |
"a controlled deepCopy, where the number of levels can be specified. |
10460 | 2519 |
Notice: |
19846 | 2520 |
This method DOES NOT handle cycles/self-refs and does NOT preserve object identity; |
2521 |
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
|
2522 |
|
14534 | 2523 |
|newObject newLevel class sz "{Class: SmallInteger}" newInst| |
2524 |
||
2525 |
newObject := self copy. |
|
2526 |
newObject == self ifTrue: [^ self]. "copy of nil, true, false, ... is self" |
|
2527 |
level == 1 ifTrue:[^ newObject]. |
|
2528 |
newLevel := level - 1. |
|
2529 |
||
2530 |
class := newObject class. |
|
2531 |
||
2532 |
"process the named instance variables" |
|
2533 |
sz := class instSize. |
|
2534 |
1 to:sz do:[:i | |
|
19846 | 2535 |
newInst := newObject instVarAt:i. |
2536 |
newInst notNil ifTrue:[ |
|
2537 |
newObject instVarAt:i put:(newInst copyToLevel:newLevel). |
|
2538 |
]. |
|
14534 | 2539 |
]. |
2540 |
||
10460 | 2541 |
class isVariable ifTrue:[ |
19846 | 2542 |
sz := newObject basicSize. |
2543 |
||
2544 |
"process the indexed instance variables" |
|
2545 |
1 to:sz do:[:i | |
|
2546 |
newInst := newObject basicAt:i. |
|
2547 |
newInst notNil ifTrue:[ |
|
2548 |
newObject basicAt:i put:(newInst copyToLevel:newLevel). |
|
2549 |
]. |
|
2550 |
] |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2551 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2552 |
^ newObject |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2553 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2554 |
" |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2555 |
|a b| |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2556 |
|
10460 | 2557 |
a := #( |
19846 | 2558 |
'1.1' |
2559 |
'1.2' |
|
2560 |
'1.3' |
|
2561 |
( |
|
2562 |
'1.41' |
|
2563 |
'1.42' |
|
2564 |
'1.43' |
|
2565 |
( |
|
2566 |
'1.441' |
|
2567 |
'1.442' |
|
2568 |
'1.443' |
|
2569 |
( '1.4441' '1.4442' '1.4443' ) |
|
2570 |
'1.445' |
|
2571 |
) |
|
2572 |
'1.45' |
|
2573 |
) |
|
2574 |
'1.5' |
|
2575 |
). |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2576 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2577 |
b := a copyToLevel:1. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2578 |
self assert: ( (a at:1) == (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2579 |
self assert: ( (a at:4) == (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2580 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2581 |
b := a copyToLevel:2. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2582 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2583 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2584 |
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
|
2585 |
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
|
2586 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2587 |
b := a copyToLevel:3. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2588 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2589 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2590 |
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
|
2591 |
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
|
2592 |
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
|
2593 |
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
|
2594 |
" |
6146 | 2595 |
! |
2596 |
||
5755 | 2597 |
deepCopy |
2598 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2599 |
This method DOES handle cycles/self-refs and preserves object identity; |
19451 | 2600 |
however the receiver's class is not copied (to avoid the 'total' copy). |
5755 | 2601 |
|
2602 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
2603 |
keeps track of already copied objects. If you are sure, that your |
|
2604 |
copied object does not include duplicates (or you do not care) and |
|
10460 | 2605 |
no cycles are involved, you can use the old simpleDeepCopy, |
5755 | 2606 |
which avoids this overhead (but may run into trouble). |
2607 |
Notice, that deepCopy does not copy dependents." |
|
2608 |
||
8383 | 2609 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 2610 |
|
2611 |
"an example which is not handled by the old deepCopy: |
|
10460 | 2612 |
|
5755 | 2613 |
|a| |
2614 |
a := Array new:3. |
|
2615 |
a at:3 put:a. |
|
2616 |
a deepCopy inspect |
|
2617 |
" |
|
2618 |
||
2619 |
" |
|
2620 |
|a| |
|
2621 |
a := Color black onDevice:Screen current. |
|
2622 |
a deepCopy inspect |
|
2623 |
" |
|
2624 |
||
2625 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
2626 |
! |
|
2627 |
||
2628 |
deepCopyError |
|
2629 |
"{ Pragma: +optSpace }" |
|
2630 |
||
2631 |
"raise a signal, that deepCopy is not allowed for this object" |
|
2632 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
2633 |
^ DeepCopyError raise |
5755 | 2634 |
! |
2635 |
||
2636 |
deepCopyUsing:aDictionary |
|
10460 | 2637 |
"a helper for deepCopy; return a copy of the object with |
2638 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
5755 | 2639 |
use the value found there. The class of the receiver is not copied. |
2640 |
This method DOES handle cycles/self references." |
|
2641 |
||
10941 | 2642 |
^ self deepCopyUsing:aDictionary postCopySelector:#postDeepCopyFrom:. |
2643 |
||
5755 | 2644 |
|
2645 |
" |
|
2646 |
|a b c copyOfC| |
|
2647 |
||
2648 |
a := Array with:'hello' with:'world' with:nil. |
|
2649 |
b := 99 @ 999. |
|
2650 |
a at:3 put:b. |
|
2651 |
c := Array with:a with:b with:a. |
|
2652 |
||
2653 |
Transcript showCR: (c at:1) == (c at:3). |
|
2654 |
copyOfC := c deepCopy. |
|
2655 |
Transcript showCR: (copyOfC at:1) == (copyOfC at:3) |
|
2656 |
" |
|
2657 |
! |
|
2658 |
||
10954 | 2659 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
11335 | 2660 |
"a helper for deepCopy; return a copy of the object with |
2661 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
10954 | 2662 |
use the value found there. The class of the receiver is not copied. |
2663 |
This method DOES handle cycles/self references." |
|
2664 |
||
2665 |
|myClass aCopy |
|
14527 | 2666 |
basicSize "{ Class: SmallInteger }" |
2667 |
instSize "{ Class: SmallInteger }" |
|
10954 | 2668 |
iOrig iCopy| |
2669 |
||
2670 |
myClass := self class. |
|
2671 |
myClass isVariable ifTrue:[ |
|
19846 | 2672 |
basicSize := self basicSize. |
2673 |
aCopy := self speciesForCopy basicNew:basicSize. |
|
10954 | 2674 |
] ifFalse:[ |
19846 | 2675 |
basicSize := 0. |
2676 |
aCopy := self speciesForCopy basicNew |
|
10954 | 2677 |
]. |
2678 |
aCopy setHashFrom:self. |
|
2679 |
aDictionary at:self put:aCopy. |
|
2680 |
||
2681 |
" |
|
14527 | 2682 |
copy the instance variables |
2683 |
" |
|
2684 |
instSize := myClass instSize. |
|
2685 |
1 to:instSize do:[:i | |
|
19846 | 2686 |
(self skipInstvarIndexInDeepCopy:i) ifFalse:[ |
2687 |
iOrig := self instVarAt:i. |
|
2688 |
iOrig notNil ifTrue:[ |
|
2689 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2690 |
iCopy isNil ifTrue:[ |
|
2691 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2692 |
]. |
|
2693 |
aCopy instVarAt:i put:iCopy |
|
2694 |
] |
|
2695 |
] |
|
14527 | 2696 |
]. |
2697 |
||
2698 |
" |
|
10954 | 2699 |
copy indexed instvars - if any |
2700 |
" |
|
14527 | 2701 |
basicSize ~~ 0 ifTrue:[ |
19846 | 2702 |
myClass isBits ifTrue:[ |
2703 |
"block-copy indexed instvars" |
|
2704 |
aCopy replaceFrom:1 to:basicSize with:self startingAt:1 |
|
2705 |
] ifFalse:[ |
|
2706 |
"individual deep copy the indexed variables" |
|
2707 |
1 to:basicSize do:[:i | |
|
2708 |
iOrig := self basicAt:i. |
|
2709 |
iOrig notNil ifTrue:[ |
|
2710 |
"/ used to be dict-includesKey-ifTrue[dict-at:], |
|
2711 |
"/ changed to use dict-at:ifAbsent:, to avoid double lookup in dictionary |
|
2712 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2713 |
iCopy isNil ifTrue:[ |
|
2714 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2715 |
]. |
|
2716 |
aCopy basicAt:i put:iCopy |
|
2717 |
] |
|
2718 |
] |
|
2719 |
] |
|
10954 | 2720 |
]. |
2721 |
||
13515
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2722 |
aCopy perform:postCopySelector withOptionalArgument:self and:aDictionary. |
10954 | 2723 |
^ aCopy |
13515
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2724 |
|
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2725 |
"Modified: / 21-07-2011 / 13:30:52 / cg" |
10954 | 2726 |
! |
2727 |
||
5755 | 2728 |
postCopy |
2729 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
2730 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
2731 |
(see there)" |
|
2732 |
||
2733 |
^ self |
|
2734 |
! |
|
2735 |
||
2736 |
postDeepCopy |
|
8930
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2737 |
"allows for cleanup after deep copying. |
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2738 |
To be redefined in subclasses." |
5755 | 2739 |
! |
2740 |
||
2741 |
postDeepCopyFrom:aSource |
|
2742 |
"allows for cleanup after deep copying" |
|
2743 |
||
2744 |
^ self postDeepCopy |
|
2745 |
! |
|
2746 |
||
2747 |
setHashFrom:anObject |
|
10460 | 2748 |
"set my identity-hash key to be the same as anObjects hash key. |
2749 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
5755 | 2750 |
Smalltalks, and may not be available in future ST/X versions. |
2751 |
DO NEVER use this for normal application code." |
|
2752 |
||
2753 |
%{ /* NOCONTEXT */ |
|
2754 |
||
2755 |
REGISTER unsigned h; |
|
2756 |
||
2757 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
19846 | 2758 |
h = __GET_HASH(anObject); |
2759 |
__SET_HASH(self, h); |
|
2760 |
RETURN (self); |
|
5755 | 2761 |
} |
2762 |
%}. |
|
2763 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
2764 |
! |
|
2765 |
||
2766 |
shallowCopy |
|
2767 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2768 |
i.e. the copy shares referenced instvars with its original." |
|
2769 |
||
2770 |
%{ /* NOCONTEXT */ |
|
2771 |
int ninsts, spc; |
|
2772 |
int sz; |
|
2773 |
OBJ theCopy; |
|
2774 |
OBJ cls; |
|
2775 |
int flags; |
|
2776 |
||
2777 |
cls = __qClass(self); |
|
2778 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
2779 |
||
2780 |
/* |
|
2781 |
* bail out for special objects .. |
|
2782 |
*/ |
|
2783 |
if (((flags & ~ARRAYMASK) == 0) |
|
2784 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
19846 | 2785 |
sz = __qSize(self); |
2786 |
__PROTECT__(self); |
|
2787 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
2788 |
__UNPROTECT__(self); |
|
2789 |
if (theCopy) { |
|
2790 |
cls = __qClass(self); |
|
2791 |
spc = __qSpace(theCopy); |
|
2792 |
||
2793 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
2794 |
||
2795 |
sz = sz - OHDR_SIZE; |
|
2796 |
if (sz) { |
|
2797 |
char *src, *dst; |
|
2798 |
||
2799 |
src = (char *)(__InstPtr(self)->i_instvars); |
|
2800 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
5755 | 2801 |
#ifdef bcopy4 |
19846 | 2802 |
{ |
2803 |
/* care for odd-number of longs */ |
|
2804 |
int nW = sz >> 2; |
|
2805 |
||
2806 |
if (sz & 3) { |
|
2807 |
nW++; |
|
2808 |
} |
|
2809 |
||
2810 |
bcopy4(src, dst, nW); |
|
2811 |
} |
|
5755 | 2812 |
#else |
19846 | 2813 |
bcopy(src, dst, sz); |
5755 | 2814 |
#endif |
2815 |
||
19846 | 2816 |
flags &= ARRAYMASK; |
2817 |
if (flags == POINTERARRAY) { |
|
2818 |
ninsts = __BYTES2OBJS__(sz); |
|
2819 |
} else { |
|
2820 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
2821 |
} |
|
2822 |
if (ninsts) { |
|
2823 |
do { |
|
2824 |
OBJ el; |
|
2825 |
||
2826 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
2827 |
__STORE_SPC(theCopy, el, spc); |
|
2828 |
} while (--ninsts); |
|
2829 |
} |
|
2830 |
} |
|
2831 |
RETURN (theCopy); |
|
2832 |
} |
|
5755 | 2833 |
} |
2834 |
%}. |
|
2835 |
"/ fallBack for special objects & memoryAllocation failure case |
|
2836 |
||
2837 |
^ self slowShallowCopy |
|
2838 |
! |
|
2839 |
||
2840 |
simpleDeepCopy |
|
2841 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2842 |
This method does NOT handle cycles - but is included to allow this |
5755 | 2843 |
slightly faster copy in situations where it is known that |
2844 |
no recursive references occur (LargeIntegers for example). |
|
2845 |
NOTICE: you will run into trouble, when trying this with recursive |
|
2846 |
objects (usually recursionInterrupt or memory-alert). |
|
8383 | 2847 |
This method corresponds to the 'traditional' deepCopy found in the Blue book." |
5755 | 2848 |
|
2849 |
|myClass aCopy| |
|
2850 |
||
2851 |
(myClass := self class) isVariable ifTrue:[ |
|
19846 | 2852 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2853 |
] ifFalse:[ |
19846 | 2854 |
aCopy := myClass basicNew |
5755 | 2855 |
]. |
2856 |
||
2857 |
"copy the instance variables" |
|
2858 |
aCopy cloneFrom:self performing:#simpleDeepCopy. |
|
2859 |
^ aCopy |
|
2860 |
||
2861 |
"a bad example (but ST/X should survive ...)" |
|
2862 |
" |
|
2863 |
|a| |
|
2864 |
a := Array new:3. |
|
2865 |
a at:3 put:a. |
|
2866 |
a simpleDeepCopy |
|
2867 |
" |
|
2868 |
! |
|
2869 |
||
2870 |
skipInstvarIndexInDeepCopy:index |
|
2871 |
"a helper for deepCopy; only indices for which this method returns |
|
2872 |
false are copied in a deep copy. |
|
2873 |
The default is false here - which means that everything is copied. |
|
2874 |
Can be redefined in subclasses for partial copies" |
|
2875 |
||
2876 |
^ false |
|
2877 |
! |
|
2878 |
||
2879 |
slowShallowCopy |
|
2880 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2881 |
i.e. the copy shares referenced instvars with its original. |
|
2882 |
This method is only invoked as a fallback from #shallowCopy." |
|
2883 |
||
2884 |
|myClass aCopy| |
|
2885 |
||
2886 |
(myClass := self class) isVariable ifTrue:[ |
|
19846 | 2887 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2888 |
] ifFalse:[ |
19846 | 2889 |
aCopy := myClass basicNew |
5755 | 2890 |
]. |
2891 |
||
2892 |
"copy the instance variables" |
|
2893 |
aCopy cloneFrom:self performing:#yourself. |
|
2894 |
^ aCopy |
|
2895 |
! ! |
|
2896 |
||
2897 |
!Object methodsFor:'debugging'! |
|
2898 |
||
7621 | 2899 |
assert:aBooleanOrBlock |
13800 | 2900 |
"fail and report an error, if the argument does not evaluate to true" |
6964 | 2901 |
|
11662 | 2902 |
"{ Pragma: +optSpace }" |
2903 |
||
11021 | 2904 |
<resource: #skipInDebuggersWalkBack> |
2905 |
||
8876 | 2906 |
aBooleanOrBlock == true ifTrue:[^ self]. |
17437 | 2907 |
(Smalltalk ignoreAssertions) ifTrue:[^ self]. |
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2908 |
|
8876 | 2909 |
"/ could still be a block or false. |
11662 | 2910 |
(aBooleanOrBlock value) ifFalse:[ |
19846 | 2911 |
AssertionFailedError |
2912 |
raiseRequestWith:self |
|
2913 |
errorString:('Assertion failed in ', |
|
2914 |
thisContext methodHome sender printString, |
|
2915 |
'[', thisContext methodHome sender lineNumber printString,']') |
|
11662 | 2916 |
]. |
2917 |
||
2918 |
" |
|
2919 |
self assert:false |
|
2920 |
" |
|
13039 | 2921 |
|
2922 |
"Modified: / 20-08-2010 / 17:13:06 / cg" |
|
7621 | 2923 |
! |
2924 |
||
19287 | 2925 |
assert:aBooleanOrBlock description:messageIfFailing |
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2926 |
"fail, if the argument does not evaluate to true and report an error" |
6961 | 2927 |
|
2928 |
"{ Pragma: +optSpace }" |
|
2929 |
||
11021 | 2930 |
<resource: #skipInDebuggersWalkBack> |
2931 |
||
11141
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2932 |
aBooleanOrBlock == true ifTrue:[^ self]. |
17437 | 2933 |
(Smalltalk ignoreAssertions) ifTrue:[^ self]. |
2934 |
||
2935 |
"/ could still be a block or false. |
|
7621 | 2936 |
(aBooleanOrBlock value) ifFalse:[ |
19287 | 2937 |
AssertionFailedError |
2938 |
raiseRequestWith:self |
|
2939 |
errorString:(messageIfFailing, ' {',thisContext methodHome sender "methodHome" printString,' }') |
|
2940 |
]. |
|
2941 |
||
2942 |
" |
|
2943 |
self assert:false description:'xxx' |
|
2944 |
" |
|
2945 |
||
2946 |
"Modified (comment): / 06-03-2012 / 11:26:48 / cg" |
|
2947 |
! |
|
2948 |
||
2949 |
assert:aBooleanOrBlock message:messageIfFailing |
|
2950 |
"fail, if the argument does not evaluate to true and report an error" |
|
2951 |
||
2952 |
"{ Pragma: +optSpace }" |
|
2953 |
||
2954 |
<resource: #skipInDebuggersWalkBack> |
|
2955 |
||
2956 |
^ self assert: aBooleanOrBlock description: messageIfFailing |
|
11662 | 2957 |
|
2958 |
" |
|
2959 |
self assert:false message:'xxx' |
|
10651 | 2960 |
" |
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2961 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2962 |
"Modified (comment): / 06-03-2012 / 11:26:48 / cg" |
6961 | 2963 |
! |
2964 |
||
5755 | 2965 |
basicInspect |
2966 |
"{ Pragma: +optSpace }" |
|
2967 |
||
2968 |
"launch an inspector on the receiver. |
|
2969 |
this method should NOT be redefined in subclasses." |
|
2970 |
||
2971 |
Inspector isNil ifTrue:[ |
|
19846 | 2972 |
" |
2973 |
for systems without GUI |
|
2974 |
" |
|
2975 |
self warn:'No Inspector defined (Inspector is nil).' |
|
5755 | 2976 |
] ifFalse:[ |
19846 | 2977 |
Inspector openOn:self |
5755 | 2978 |
] |
2979 |
||
2980 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
2981 |
! |
|
2982 |
||
11025 | 2983 |
breakPoint:someKey |
6954 | 2984 |
"{ Pragma: +optSpace }" |
2985 |
||
2986 |
"Like halt, but disabled by default. |
|
2987 |
Can be easily enabled. |
|
2988 |
Can be filtered on the arguments value (typically: a symbol). |
|
2989 |
Code with breakpoints may be even checked into the source repository" |
|
2990 |
||
2991 |
"Example: nil breakPoint:#stefan" |
|
2992 |
||
11025 | 2993 |
<resource: #skipInDebuggersWalkBack> |
2994 |
||
11048 | 2995 |
"/ dont send #breakPoint:info: here - ask cg why. |
2996 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
19846 | 2997 |
^ HaltSignal |
2998 |
raiseRequestWith:someKey |
|
2999 |
errorString:('Breakpoint encountered: %1' bindWith:someKey) |
|
11048 | 3000 |
]. |
11025 | 3001 |
|
3002 |
" |
|
3003 |
nil breakPoint:#stefan |
|
3004 |
nil breakPoint:#stefan info:'Hello' |
|
3005 |
Smalltalk enableBreakPoint:#stefan. |
|
3006 |
Smalltalk disableBreakPoint:#stefan. |
|
11048 | 3007 |
|
3008 |
EncounteredBreakPoints. |
|
3009 |
Smalltalk enableBreakPoint:#cg. |
|
3010 |
Smalltalk disableBreakPoint:#cg. |
|
11025 | 3011 |
" |
3012 |
! |
|
3013 |
||
3014 |
breakPoint:someKey info:infoString |
|
3015 |
"{ Pragma: +optSpace }" |
|
3016 |
||
3017 |
"Like halt, but disabled by default. |
|
3018 |
Can be easily enabled. |
|
3019 |
Can be filtered on the arguments value (typically: a symbol). |
|
3020 |
Code with breakpoints may be even checked into the source repository" |
|
3021 |
||
3022 |
"Example: nil breakPoint:#stefan" |
|
3023 |
||
3024 |
<resource: #skipInDebuggersWalkBack> |
|
3025 |
||
3026 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
19846 | 3027 |
^ HaltSignal |
3028 |
raiseRequestWith:someKey |
|
3029 |
errorString:(infoString bindWith:someKey) |
|
11025 | 3030 |
]. |
6954 | 3031 |
! |
3032 |
||
11244 | 3033 |
debuggingCodeFor:someKey is:aBlock |
3034 |
"{ Pragma: +optSpace }" |
|
3035 |
||
3036 |
"aBlock is evaluated if breakPoints for somekey are enabled. |
|
3037 |
Allows for debugging code to be enabled/disabled via the breakpoint browser. |
|
3038 |
Can be easily enabled. |
|
3039 |
Can be filtered on the arguments value (typically: a symbol). |
|
3040 |
Code with breakpoints may be even checked into the source repository" |
|
3041 |
||
3042 |
"Example: nil debuggingCodeFor:#cg is:[ self halt ]" |
|
3043 |
||
3044 |
<resource: #skipInDebuggersWalkBack> |
|
3045 |
||
3046 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
19846 | 3047 |
aBlock value |
11244 | 3048 |
]. |
3049 |
||
3050 |
" |
|
3051 |
Smalltalk disableBreakPoint:#cg. |
|
12340
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
3052 |
nil debuggingCodeFor:#cg is:[ Transcript showCR:'here is some debug message for cg' ]. |
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
3053 |
nil debuggingCodeFor:#stefan is:[ Transcript showCR:'here is some debug message for sv' ]. |
11244 | 3054 |
Smalltalk enableBreakPoint:#cg. |
12340
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
3055 |
nil debuggingCodeFor:#cg is:[ Transcript showCR:'here is some debug message for cg' ]. |
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
3056 |
nil debuggingCodeFor:#stefan is:[ Transcript showCR:'here is some debug message for sv' ]. |
11244 | 3057 |
Smalltalk disableBreakPoint:#cg. |
3058 |
||
3059 |
" |
|
3060 |
! |
|
3061 |
||
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3062 |
disableAllBreakPoints |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3063 |
"disable all parametrized breakPoints (with any key as parameter)" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3064 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3065 |
EnabledBreakPoints := nil |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3066 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3067 |
" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3068 |
nil enableBreakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3069 |
nil breakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3070 |
nil disableAllBreakPoints. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3071 |
nil breakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3072 |
" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3073 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3074 |
"Created: / 06-03-2012 / 15:32:28 / cg" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3075 |
! |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3076 |
|
11025 | 3077 |
disableBreakPoint:someKey |
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3078 |
"disable parametrized breakPoints with someKey as parameter" |
11025 | 3079 |
|
3080 |
"{ Pragma: +optSpace }" |
|
3081 |
||
3082 |
EnabledBreakPoints notNil ifTrue:[ |
|
19846 | 3083 |
EnabledBreakPoints remove:someKey ifAbsent:[]. |
3084 |
EnabledBreakPoints := EnabledBreakPoints asNilIfEmpty. |
|
11025 | 3085 |
]. |
3086 |
||
3087 |
" |
|
3088 |
nil enableBreakPoint:#cg. |
|
3089 |
nil breakPoint:#cg. |
|
3090 |
nil disableBreakPoint:#cg |
|
3091 |
nil breakPoint:#cg. |
|
3092 |
" |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3093 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3094 |
"Modified (comment): / 06-03-2012 / 15:31:51 / cg" |
11025 | 3095 |
! |
3096 |
||
3097 |
enableBreakPoint:someKey |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3098 |
"enable parametrized breakPoints with someKey as parameter" |
11025 | 3099 |
|
3100 |
"{ Pragma: +optSpace }" |
|
3101 |
||
3102 |
EnabledBreakPoints isNil ifTrue:[ |
|
19846 | 3103 |
EnabledBreakPoints := Set new. |
11025 | 3104 |
]. |
3105 |
EnabledBreakPoints add:someKey. |
|
3106 |
||
3107 |
" |
|
3108 |
nil enableBreakPoint:#cg. |
|
3109 |
nil breakPoint:#cg. |
|
3110 |
nil disableBreakPoint:#cg |
|
3111 |
nil breakPoint:#cg. |
|
3112 |
" |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3113 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3114 |
"Modified (comment): / 06-03-2012 / 15:31:47 / cg" |
11025 | 3115 |
! |
3116 |
||
11048 | 3117 |
halt |
3118 |
"{ Pragma: +optSpace }" |
|
3119 |
||
3120 |
"enter debugger with halt-message. |
|
3121 |
The error is reported by raising the HaltSignal exception." |
|
3122 |
||
3123 |
<resource: #skipInDebuggersWalkBack> |
|
3124 |
||
13136 | 3125 |
Smalltalk ignoreHalt ifTrue:[^ self]. |
14830 | 3126 |
"/ don't send #halt: here - ask cg why. |
14974 | 3127 |
HaltInterrupt raiseRequestWith:#halt. |
3128 |
^ self |
|
3129 |
||
3130 |
" |
|
19846 | 3131 |
(3 halt * 5) |
14974 | 3132 |
" |
11048 | 3133 |
|
13136 | 3134 |
"Modified: / 02-08-1999 / 17:00:29 / stefan" |
3135 |
"Modified: / 18-11-2010 / 11:21:51 / cg" |
|
11048 | 3136 |
! |
3137 |
||
3138 |
halt:aString |
|
3139 |
"{ Pragma: +optSpace }" |
|
3140 |
||
3141 |
"enter debugger with halt-message. |
|
3142 |
The error is reported by raising the HaltSignal exception." |
|
3143 |
||
3144 |
<resource: #skipInDebuggersWalkBack> |
|
3145 |
||
13136 | 3146 |
Smalltalk ignoreHalt ifTrue:[^ self]. |
14974 | 3147 |
HaltInterrupt raiseRequestWith:#halt: errorString:aString. |
3148 |
^ self |
|
11048 | 3149 |
|
13136 | 3150 |
"Modified: / 18-11-2010 / 11:22:16 / cg" |
11048 | 3151 |
! |
3152 |
||
11025 | 3153 |
isBreakPointEnabled:someKey |
3154 |
"{ Pragma: +optSpace }" |
|
3155 |
||
3156 |
"controls which breakpoints to be enabled." |
|
3157 |
||
3158 |
"/ something = OperatingSystem getLoginName ifTrue:[^ true]. |
|
3159 |
"/ something = 'testThis' ifTrue:[^ true]. |
|
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
3160 |
EncounteredBreakPoints notNil ifTrue:[ |
19846 | 3161 |
EncounteredBreakPoints add:someKey |
11335 | 3162 |
]. |
3163 |
||
3164 |
^ (EnabledBreakPoints notNil and:[ EnabledBreakPoints includes:someKey ]) |
|
11025 | 3165 |
|
3166 |
" |
|
3167 |
nil enableBreakPoint:#cg. |
|
3168 |
nil breakPoint:#cg. |
|
3169 |
nil disableBreakPoint:#cg |
|
3170 |
nil breakPoint:#cg. |
|
11045
85315d8893e4
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11044
diff
changeset
|
3171 |
|
85315d8893e4
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11044
diff
changeset
|
3172 |
EncounteredBreakPoints := Set new. |
11025 | 3173 |
" |
3174 |
! |
|
3175 |
||
5755 | 3176 |
mustBeBoolean |
3177 |
"this message is sent by the VM, if a non-Boolean receiver is encountered |
|
3178 |
in an if* or while* message. |
|
3179 |
Caveat: for now, this is only sent by the interpreter; |
|
3180 |
both the JIT and the stc compiler treat it as undefined." |
|
3181 |
||
11021 | 3182 |
<resource: #skipInDebuggersWalkBack> |
3183 |
||
5755 | 3184 |
self error:'Non boolean receiver - proceed for truth' mayProceed:true. |
3185 |
^ true |
|
3186 |
! |
|
3187 |
||
3188 |
mustBeKindOf:aClass |
|
10460 | 3189 |
"for compatibility & debugging support: |
5755 | 3190 |
check if the receiver isKindOf:aClass and raise an error if not. |
3191 |
Notice: |
|
19846 | 3192 |
it is VERY questionable, if it makes sense to add manual |
3193 |
type checks to a dynamically typed language like smalltalk. |
|
3194 |
It will, at least, slow down performance, |
|
3195 |
make your code less reusable and clutter your code with stupid sends |
|
3196 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
3197 |
use of isXXX check methods. |
|
5755 | 3198 |
You see: The author does not like this at all ..." |
3199 |
||
11021 | 3200 |
<resource: #skipInDebuggersWalkBack> |
3201 |
||
5755 | 3202 |
(self isKindOf:aClass) ifFalse:[ |
19846 | 3203 |
self error:'argument is not of expected type' |
5755 | 3204 |
] |
3205 |
! |
|
3206 |
||
6950 | 3207 |
obsoleteFeatureWarning |
3208 |
"{ Pragma: +optSpace }" |
|
3209 |
||
3210 |
"in methods which are going to be changed, a send to |
|
3211 |
this method is used to tell programmers that some feature/semantics is |
|
3212 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3213 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)." |
6950 | 3214 |
|
3215 |
self obsoleteFeatureWarning:nil from:thisContext sender |
|
3216 |
! |
|
3217 |
||
3218 |
obsoleteFeatureWarning:message |
|
3219 |
"{ Pragma: +optSpace }" |
|
3220 |
||
3221 |
"in methods which are going to be changed, a send to |
|
3222 |
this method is used to tell programmers that some feature/semantics is |
|
3223 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3224 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3225 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3226 |
|
3227 |
self obsoleteFeatureWarning:message from:thisContext sender |
|
3228 |
! |
|
3229 |
||
3230 |
obsoleteFeatureWarning:message from:aContext |
|
3231 |
"{ Pragma: +optSpace }" |
|
3232 |
||
3233 |
"in methods which are going to be changed, a send to |
|
3234 |
this method is used to tell programmers that some feature/semantics is |
|
3235 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3236 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3237 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3238 |
|
11527 | 3239 |
|spec sender| |
6950 | 3240 |
|
3241 |
spec := aContext methodPrintString. |
|
11527 | 3242 |
sender := aContext sender. |
3243 |
||
6950 | 3244 |
('WARNING: the ''' , spec , ''' semantics will be changed.') infoPrintCR. |
3245 |
(' Its behavior may be different in future ST/X versions.') infoPrintCR. |
|
11527 | 3246 |
(' called from ' , sender printString) infoPrintCR. |
3247 |
((sender selector ? '') startsWith:'perform:') ifTrue:[ |
|
3248 |
(' called from ' , sender sender printString) infoPrintCR. |
|
7204 | 3249 |
]. |
6950 | 3250 |
message notNil ifTrue:[ |
19846 | 3251 |
'------> ' infoPrint. message infoPrintCR |
6950 | 3252 |
] |
3253 |
||
3254 |
" |
|
3255 |
Object obsoleteFeatureWarning:'foo' from:thisContext sender sender |
|
3256 |
" |
|
3257 |
! |
|
3258 |
||
5755 | 3259 |
obsoleteMethodWarning |
3260 |
"{ Pragma: +optSpace }" |
|
3261 |
||
3262 |
"in methods which are going to be obsoleted, a self send to |
|
3263 |
this method is used to tell programmers that a method is |
|
3264 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3265 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3266 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3267 |
|
3268 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
3269 |
! |
|
3270 |
||
3271 |
obsoleteMethodWarning:message |
|
3272 |
"{ Pragma: +optSpace }" |
|
3273 |
||
3274 |
"in methods which are going to be obsoleted, a self send to |
|
3275 |
this method is used to tell programmers that a method is |
|
3276 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3277 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3278 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3279 |
|
3280 |
self obsoleteMethodWarning:message from:thisContext sender |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3281 |
! |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3282 |
|
16470 | 3283 |
obsoleteMethodWarning:messageOrNil from:aContext |
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3284 |
"{ Pragma: +optSpace }" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3285 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3286 |
"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
|
3287 |
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
|
3288 |
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
|
3289 |
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
|
3290 |
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
|
3291 |
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
|
3292 |
|
16470 | 3293 |
|spec sender message| |
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3294 |
|
9509 | 3295 |
Smalltalk isSmalltalkDevelopmentSystem ifFalse:[ |
19719 | 3296 |
"ignore in production systems" |
3297 |
^ self. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3298 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3299 |
|
16470 | 3300 |
message := messageOrNil ? 'Obsolete method called'. |
3301 |
||
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3302 |
spec := aContext methodPrintString. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3303 |
sender := aContext sender. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3304 |
('WARNING: the ''' , spec , ''' method is obsolete.') infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3305 |
(' 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
|
3306 |
(' called from ' , sender printString) infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3307 |
(sender selector startsWith:'perform:') ifTrue:[ |
19719 | 3308 |
sender := sender sender. |
3309 |
(sender selector startsWith:'perform:') ifTrue:[ |
|
3310 |
sender := sender sender. |
|
3311 |
]. |
|
3312 |
(' called from ' , sender printString) infoPrintCR. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3313 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3314 |
message notNil ifTrue:[ |
19719 | 3315 |
'------> ' infoPrint. message infoPrintCR |
16383 | 3316 |
]. |
3317 |
||
3318 |
"CG: care for standalone non-GUI progs, which have no userPreferences class" |
|
3319 |
(Smalltalk isInitialized |
|
3320 |
and:[ UserPreferences notNil |
|
3321 |
and:[ UserPreferences current haltInObsoleteMethod]]) ifTrue:[ |
|
19719 | 3322 |
"/ cg: nice try, stefan, but I don't want halts in system processes (fly by help and others) |
3323 |
Processor activeProcess isSystemProcess ifTrue:[ |
|
3324 |
(message , ' - please fix this now (no halt in system process)') infoPrintCR |
|
3325 |
] ifFalse:[ |
|
3326 |
"/ please check for the sender of the obsoleteMethodWarning, |
|
3327 |
"/ and fix the code there. |
|
3328 |
ObsoleteMethodCallWarning raiseRequestErrorString:(message , ' - please fix this now!!') |
|
3329 |
]. |
|
15716 | 3330 |
]. |
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3331 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3332 |
" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3333 |
Object obsoleteMethodWarning:'foo' from:thisContext sender sender |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3334 |
" |
9509 | 3335 |
|
3336 |
"Modified: / 10-08-2006 / 13:13:11 / cg" |
|
10558 | 3337 |
! |
3338 |
||
12341 | 3339 |
todo |
3340 |
"used to mark code pieces that have to be implemented" |
|
3341 |
||
3342 |
<resource: #skipInDebuggersWalkBack> |
|
3343 |
||
3344 |
self halt:'more work needed here'. |
|
3345 |
||
3346 |
" |
|
3347 |
example: |
|
3348 |
||
19846 | 3349 |
... |
3350 |
self todo. |
|
3351 |
... |
|
12341 | 3352 |
" |
3353 |
! |
|
3354 |
||
10558 | 3355 |
todo:aBlock |
3356 |
"used to mark code pieces that have to be implemented" |
|
3357 |
||
12341 | 3358 |
<resource: #skipInDebuggersWalkBack> |
3359 |
||
10558 | 3360 |
"/ self halt. |
3361 |
"/ aBlock value. |
|
3362 |
||
3363 |
" |
|
3364 |
example: |
|
3365 |
||
19846 | 3366 |
... |
3367 |
self todo:[ |
|
3368 |
code which needs more work ... |
|
3369 |
]. |
|
3370 |
... |
|
10558 | 3371 |
" |
3372 |
||
3373 |
"Created: / 25-05-2007 / 21:34:39 / cg" |
|
3374 |
"Modified: / 29-05-2007 / 12:11:33 / cg" |
|
15683 | 3375 |
! |
3376 |
||
3377 |
tracePoint:someKey |
|
3378 |
"{ Pragma: +optSpace }" |
|
3379 |
||
3380 |
"Like transcript show, but disabled by default. |
|
3381 |
Can be easily enabled. |
|
3382 |
Can be filtered on the arguments value (typically: a symbol). |
|
3383 |
Code with tracepoints may be even checked into the source repository" |
|
3384 |
||
3385 |
"Example: nil tracePoint:#stefan" |
|
3386 |
||
3387 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
19846 | 3388 |
^ Transcript showCR:('Tracepoint (at %1 for %3 from %2)' |
3389 |
bindWith:(Timestamp now printString) |
|
3390 |
with:(thisContext sender printString) |
|
3391 |
with:someKey) |
|
15683 | 3392 |
]. |
3393 |
||
3394 |
" |
|
3395 |
nil tracePoint:#stefan |
|
3396 |
nil tracePoint:#stefan message:'Hello' |
|
3397 |
Smalltalk enableBreakPoint:#stefan. |
|
3398 |
Smalltalk disableBreakPoint:#stefan. |
|
3399 |
" |
|
15723 | 3400 |
|
3401 |
"Modified: / 28-08-2013 / 21:41:54 / cg" |
|
15683 | 3402 |
! |
3403 |
||
15804 | 3404 |
tracePoint:someKey message:messageBlockOrString |
15683 | 3405 |
"{ Pragma: +optSpace }" |
3406 |
||
3407 |
"Like transcript show, but disabled by default. |
|
3408 |
Can be easily enabled. |
|
3409 |
Can be filtered on the arguments value (typically: a symbol). |
|
3410 |
Code with tracepoints may be even checked into the source repository" |
|
3411 |
||
3412 |
"Example: nil tracePoint:#stefan" |
|
3413 |
||
3414 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
19846 | 3415 |
Transcript showCR:('Tracepoint: %4 (at %1 for %3 from %2)' |
3416 |
bindWith:(Timestamp now printString) |
|
3417 |
with:(thisContext sender printString) |
|
3418 |
with:someKey |
|
3419 |
with:messageBlockOrString value) |
|
15804 | 3420 |
]. |
3421 |
||
3422 |
" |
|
15683 | 3423 |
Smalltalk enableBreakPoint:#stefan. |
15804 | 3424 |
nil tracePoint:#stefan. |
3425 |
nil tracePoint:#stefan message:'Hello'. |
|
3426 |
nil tracePoint:#stefan message:['Hello from block']. |
|
15683 | 3427 |
Smalltalk disableBreakPoint:#stefan. |
3428 |
" |
|
15723 | 3429 |
|
3430 |
"Modified: / 28-08-2013 / 21:41:47 / cg" |
|
5755 | 3431 |
! ! |
3432 |
||
3433 |
!Object methodsFor:'dependents access'! |
|
3434 |
||
3435 |
addDependent:anObject |
|
3436 |
"make the argument, anObject be a dependent of the receiver" |
|
3437 |
||
3438 |
|wasBlocked| |
|
3439 |
||
3440 |
"/ must do this save from interrupts, since the dependents collection |
|
3441 |
"/ is possibly accessed from multiple threads. |
|
3442 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3443 |
"/ faster execution. |
|
3444 |
||
3445 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3446 |
[ |
|
19846 | 3447 |
|deps dep| |
3448 |
||
3449 |
deps := self dependents. |
|
3450 |
||
3451 |
"/ to save a fair amount of memory in case of |
|
3452 |
"/ many dependencies, we store a single dependent in |
|
3453 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3454 |
"/ added. |
|
3455 |
||
3456 |
(deps isNil or:[deps size == 0]) ifTrue:[ |
|
3457 |
self dependents:(WeakArray with:anObject) |
|
3458 |
] ifFalse:[ |
|
3459 |
deps class == WeakArray ifTrue:[ |
|
3460 |
dep := deps at:1. |
|
3461 |
dep ~~ anObject ifTrue:[ |
|
3462 |
(dep isNil or:[dep class == SmallInteger]) ifTrue:[ |
|
3463 |
deps at:1 put:anObject |
|
3464 |
] ifFalse:[ |
|
3465 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
3466 |
] |
|
3467 |
] |
|
3468 |
] ifFalse:[ |
|
3469 |
deps add:anObject |
|
3470 |
] |
|
3471 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3472 |
] ensure:[ |
19846 | 3473 |
wasBlocked ifFalse:[ |
3474 |
OperatingSystem unblockInterrupts |
|
3475 |
] |
|
5755 | 3476 |
] |
3477 |
||
3478 |
"Modified: / 27.10.1997 / 19:35:52 / cg" |
|
3479 |
! |
|
3480 |
||
3481 |
breakDependents |
|
3482 |
"remove all dependencies from the receiver" |
|
3483 |
||
3484 |
self dependents:nil. |
|
3485 |
self nonWeakDependents:nil |
|
3486 |
||
3487 |
"Modified: / 19.4.1996 / 10:55:36 / cg" |
|
3488 |
"Created: / 27.2.1998 / 11:26:11 / stefan" |
|
3489 |
! |
|
3490 |
||
8542 | 3491 |
breakDependentsRecursively |
10460 | 3492 |
"remove all dependencies from the receiver and |
8542 | 3493 |
recursively from all objects referred to by the receiver." |
3494 |
||
3495 |
self breakDependents. |
|
10460 | 3496 |
1 to:self class instSize do:[:idx | |
19846 | 3497 |
(self instVarAt:idx) breakDependentsRecursively. |
10460 | 3498 |
]. |
3499 |
1 to:self basicSize do:[:idx | |
|
19846 | 3500 |
(self basicAt:idx) breakDependentsRecursively. |
8542 | 3501 |
] |
3502 |
! |
|
3503 |
||
5755 | 3504 |
dependents |
3505 |
"return a Collection of dependents. |
|
3506 |
The default implementation here uses a global WeakDictionary to store |
|
10460 | 3507 |
dependents |
5755 | 3508 |
This may be too slow for high frequency change&update, |
3509 |
therefore, some classes (Model) redefine this for better performance. |
|
3510 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
3511 |
||
3512 |
|deps| |
|
3513 |
||
3514 |
(deps := Dependencies at:self ifAbsent:nil) isNil ifTrue:[ |
|
19846 | 3515 |
^ #(). |
5755 | 3516 |
]. |
3517 |
^ deps |
|
3518 |
||
3519 |
"Modified: / 26.1.1998 / 11:18:15 / cg" |
|
3520 |
! |
|
3521 |
||
3522 |
dependents:aCollection |
|
3523 |
"set the collection of dependents. |
|
3524 |
The default implementation here uses a global Dictionary to store |
|
3525 |
dependents which may be too slow for high frequency change&update. |
|
3526 |
Therefore, some classes (Model) redefine this for better performance." |
|
3527 |
||
3528 |
"/ must do this save from interrupts, since the dependents collection |
|
3529 |
"/ is possibly accessed from multiple threads. |
|
3530 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3531 |
"/ faster execution (and to avoid creation of garbage blocks). |
|
3532 |
||
3533 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
19846 | 3534 |
"/ the common case - already blocked |
3535 |
||
3536 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
3537 |
Dependencies removeKey:self ifAbsent:nil |
|
3538 |
] ifFalse:[ |
|
3539 |
Dependencies at:self put:aCollection |
|
3540 |
]. |
|
3541 |
^ self |
|
5755 | 3542 |
]. |
3543 |
||
3544 |
[ |
|
19846 | 3545 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3546 |
Dependencies removeKey:self ifAbsent:nil |
|
3547 |
] ifFalse:[ |
|
3548 |
Dependencies at:self put:aCollection |
|
3549 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3550 |
] ensure:[ |
19846 | 3551 |
OperatingSystem unblockInterrupts |
5755 | 3552 |
] |
3553 |
||
3554 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
|
3555 |
! |
|
3556 |
||
3557 |
dependentsDo:aBlock |
|
3558 |
"evaluate aBlock for all of my dependents" |
|
3559 |
||
3560 |
|deps nwDeps| |
|
3561 |
||
3562 |
deps := self dependents. |
|
3563 |
deps size ~~ 0 ifTrue:[ |
|
19846 | 3564 |
deps do:[:d | |
3565 |
(d notNil and:[d class ~~ SmallInteger]) ifTrue:[ |
|
3566 |
aBlock value:d |
|
3567 |
] |
|
3568 |
] |
|
5755 | 3569 |
]. |
3570 |
nwDeps := self nonWeakDependents. |
|
3571 |
(nwDeps ~~ deps and:[nwDeps size ~~ 0]) ifTrue:[ |
|
19846 | 3572 |
nwDeps do:aBlock |
5755 | 3573 |
]. |
3574 |
||
3575 |
"Modified: / 30.1.1998 / 14:03:40 / cg" |
|
3576 |
! |
|
3577 |
||
3578 |
myDependents |
|
3579 |
"same as dependents - ST-80 compatibility" |
|
3580 |
||
3581 |
^ self dependents |
|
3582 |
! |
|
3583 |
||
3584 |
release |
|
3585 |
"remove all references to objects that may refer to self. |
|
3586 |
Subclasses may redefine this method but should do a 'super release'." |
|
3587 |
||
3588 |
self breakDependents |
|
3589 |
||
3590 |
"Modified: / 27.2.1998 / 11:29:35 / stefan" |
|
3591 |
! |
|
3592 |
||
3593 |
removeDependent:anObject |
|
3594 |
"make the argument, anObject be independent of the receiver" |
|
3595 |
||
3596 |
|wasBlocked| |
|
3597 |
||
3598 |
"/ must do this save from interrupts, since the dependents collection |
|
3599 |
"/ is possibly accessed from multiple threads. |
|
3600 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3601 |
"/ faster execution. |
|
3602 |
||
3603 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3604 |
[ |
|
19846 | 3605 |
|deps n d| |
3606 |
||
3607 |
deps := self dependents. |
|
3608 |
deps size ~~ 0 ifTrue:[ |
|
3609 |
||
3610 |
"/ to save a fair amount of memory in case of |
|
3611 |
"/ many dependencies, we store a single dependent in |
|
3612 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3613 |
"/ added. Here we have to do the inverse ... |
|
3614 |
||
3615 |
((deps class == WeakArray) or:[deps class == Array]) ifTrue:[ |
|
3616 |
((d := deps at:1) == anObject |
|
3617 |
or:[d isNil |
|
3618 |
or:[d class == SmallInteger]]) ifTrue:[ |
|
3619 |
self dependents:nil |
|
3620 |
] |
|
3621 |
] ifFalse:[ |
|
3622 |
deps remove:anObject ifAbsent:[]. |
|
3623 |
(n := deps size) == 0 ifTrue:[ |
|
3624 |
self dependents:nil |
|
3625 |
] ifFalse:[ |
|
3626 |
n == 1 ifTrue:[ |
|
3627 |
d := deps firstIfEmpty:nil. |
|
3628 |
d notNil ifTrue:[ |
|
3629 |
deps := (deps isWeakCollection ifTrue:[WeakArray] ifFalse:[Array]) with:d |
|
3630 |
] ifFalse:[ |
|
3631 |
deps := nil |
|
3632 |
]. |
|
3633 |
self dependents:deps. |
|
3634 |
] |
|
3635 |
] |
|
3636 |
] |
|
3637 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3638 |
] ensure:[ |
19846 | 3639 |
wasBlocked ifFalse:[ |
3640 |
OperatingSystem unblockInterrupts |
|
3641 |
] |
|
5755 | 3642 |
] |
3643 |
||
13500 | 3644 |
"Modified: / 05-07-2011 / 22:49:31 / cg" |
5755 | 3645 |
! ! |
3646 |
||
7266 | 3647 |
!Object methodsFor:'dependents access (non weak)'! |
5755 | 3648 |
|
3649 |
addNonWeakDependent:anObject |
|
3650 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
|
10460 | 3651 |
Be careful: this nonWeakDependency will prevent the dependent from being |
5755 | 3652 |
garbage collected unless the dependency is removed. |
3653 |
This is a private mechanism, for directed dependencies." |
|
3654 |
||
3655 |
|wasBlocked| |
|
3656 |
||
3657 |
"/ must do this save from interrupts, since the dependents collection |
|
3658 |
"/ is possibly accessed from multiple threads. |
|
3659 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3660 |
"/ faster execution. |
|
3661 |
||
3662 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3663 |
[ |
|
19846 | 3664 |
|deps dep| |
3665 |
||
3666 |
deps := self nonWeakDependents. |
|
3667 |
||
3668 |
"/ to save a fair amount of memory in case of |
|
3669 |
"/ many dependencies, we store a single dependent in |
|
3670 |
"/ an Array, and switch to a Set if more dependents are |
|
3671 |
"/ added. |
|
3672 |
||
3673 |
deps size == 0 ifTrue:[ |
|
3674 |
anObject notNil ifTrue:[ |
|
3675 |
self nonWeakDependents:(Array with:anObject). |
|
3676 |
] ifFalse:[ |
|
3677 |
"adding nil causes problems when adding the next one |
|
3678 |
(see below: trying to add nil to IdentitySet)" |
|
9442 | 3679 |
"/ self halt:'try to add nil to list of dependents'. |
19846 | 3680 |
]. |
3681 |
] ifFalse:[ |
|
3682 |
deps class == Array ifTrue:[ |
|
3683 |
dep := deps at:1. |
|
3684 |
dep ~~ anObject ifTrue:[ |
|
3685 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
3686 |
] |
|
3687 |
] ifFalse:[ |
|
3688 |
deps add:anObject |
|
3689 |
] |
|
3690 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3691 |
] ensure:[ |
19846 | 3692 |
wasBlocked ifFalse:[ |
3693 |
OperatingSystem unblockInterrupts |
|
3694 |
] |
|
5755 | 3695 |
] |
3696 |
||
3697 |
"Created: / 19.4.1996 / 10:54:08 / cg" |
|
3698 |
"Modified: / 30.1.1998 / 14:03:08 / cg" |
|
3699 |
! |
|
3700 |
||
3701 |
nonWeakDependents |
|
3702 |
"return a Collection of nonWeakDependents - empty if there is none. |
|
3703 |
This is a private mechanism for directed dependencies." |
|
3704 |
||
3705 |
NonWeakDependencies isNil ifTrue:[^ #()]. |
|
3706 |
^ NonWeakDependencies at:self ifAbsent:#() |
|
3707 |
||
3708 |
"Created: / 19.4.1996 / 10:55:06 / cg" |
|
3709 |
"Modified: / 30.1.1998 / 14:06:47 / cg" |
|
3710 |
! |
|
3711 |
||
3712 |
nonWeakDependents:aCollection |
|
3713 |
"set the collection of nonWeak dependents. |
|
3714 |
This is a private helper for directed dependencies." |
|
3715 |
||
3716 |
[ |
|
19846 | 3717 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3718 |
NonWeakDependencies removeKey:self ifAbsent:nil |
|
3719 |
] ifFalse:[ |
|
3720 |
NonWeakDependencies at:self put:aCollection |
|
3721 |
] |
|
5755 | 3722 |
] valueUninterruptably |
3723 |
||
3724 |
"Created: 19.4.1996 / 11:07:47 / cg" |
|
3725 |
! |
|
3726 |
||
3727 |
removeNonWeakDependent:anObject |
|
3728 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
|
3729 |
(i.e. make it independent of the receiver)" |
|
3730 |
||
3731 |
|wasBlocked| |
|
3732 |
||
3733 |
"/ must do this save from interrupts, since the dependents collection |
|
3734 |
"/ is possibly accessed from multiple threads. |
|
3735 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3736 |
"/ faster execution. |
|
3737 |
||
3738 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3739 |
[ |
|
19846 | 3740 |
|deps n| |
3741 |
||
3742 |
deps := self nonWeakDependents. |
|
3743 |
deps size ~~ 0 ifTrue:[ |
|
3744 |
deps class == Array ifTrue:[ |
|
3745 |
(deps at:1) == anObject ifTrue:[ |
|
3746 |
self nonWeakDependents:nil |
|
3747 |
] |
|
3748 |
] ifFalse:[ |
|
3749 |
deps remove:anObject ifAbsent:[]. |
|
3750 |
(n := deps size) == 0 ifTrue:[ |
|
3751 |
self nonWeakDependents:nil |
|
3752 |
] ifFalse:[ |
|
3753 |
n == 1 ifTrue:[ |
|
3754 |
self nonWeakDependents:(Array with:(deps first)) |
|
3755 |
] |
|
3756 |
] |
|
3757 |
] |
|
3758 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3759 |
] ensure:[ |
19846 | 3760 |
wasBlocked ifFalse:[ |
3761 |
OperatingSystem unblockInterrupts |
|
3762 |
] |
|
5755 | 3763 |
] |
3764 |
||
3765 |
"Created: / 19.4.1996 / 11:44:44 / cg" |
|
3766 |
"Modified: / 30.1.1998 / 14:04:01 / cg" |
|
3767 |
! ! |
|
3768 |
||
9279 | 3769 |
|
3770 |
||
5755 | 3771 |
!Object methodsFor:'displaying'! |
3772 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3773 |
ascentOn:aGC |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3774 |
"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
|
3775 |
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
|
3776 |
coordinate is given by y. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3777 |
In other words: some draw above the given y coordinate. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3778 |
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
|
3779 |
the given y coordinate." |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3780 |
|
11065
17c01b01000f
Simplify (and speed up) #ascentOn:
Stefan Vogel <sv@exept.de>
parents:
11048
diff
changeset
|
3781 |
^ aGC fontAscent |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3782 |
! |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3783 |
|
6900 | 3784 |
displayOn:aGCOrStream |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3785 |
"Compatibility |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3786 |
append a printed desription on some stream (Dolphin, Squeak) |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3787 |
OR: |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3788 |
display the receiver in a graphicsContext at 0@0 (ST80). |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3789 |
This method allows for any object to be displayed in some view |
5755 | 3790 |
(although the fallBack is to display its printString ...)" |
3791 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3792 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3793 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
14292
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3794 |
aGCOrStream isStream ifTrue:[ |
19846 | 3795 |
self printOn:aGCOrStream. |
3796 |
^ self |
|
6900 | 3797 |
]. |
3798 |
^ self displayOn:aGCOrStream x:0 y:0. |
|
5755 | 3799 |
|
3800 |
"Created: 29.5.1996 / 16:28:58 / cg" |
|
3801 |
! |
|
3802 |
||
3803 |
displayOn:aGC at:aPoint |
|
3804 |
"ST-80 Compatibility |
|
3805 |
display the receiver in a graphicsContext - this method allows |
|
3806 |
for any object to be displayed in a ListView - for example." |
|
3807 |
||
3808 |
^ self displayOn:aGC x:(aPoint x) y:(aPoint y). |
|
3809 |
! |
|
3810 |
||
3811 |
displayOn:aGC x:x y:y |
|
3812 |
"display the receiver in a graphicsContext - this method allows |
|
3813 |
for any object to be displayed in a ListView - for example." |
|
3814 |
||
3815 |
self displayOn:aGC x:x y:y opaque:false |
|
3816 |
||
3817 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3818 |
! |
|
3819 |
||
3820 |
displayOn:aGc x:x y:y opaque:opaque |
|
3821 |
"display the receiver in a graphicsContext - this method allows |
|
3822 |
for any object to be displayed in a ListView - for example. |
|
19451 | 3823 |
The fallBack here shows the receiver's displayString. |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3824 |
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
|
3825 |
ask using #ascentOn: if required" |
5755 | 3826 |
|
3827 |
|s yBaseline| |
|
3828 |
||
15368 | 3829 |
s := self isString ifTrue:[self] ifFalse:[self displayString]. |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3830 |
yBaseline := y "+ aGc font ascent". |
5755 | 3831 |
opaque ifTrue:[ |
19451 | 3832 |
aGc displayOpaqueString:s x:x y:yBaseline. |
5755 | 3833 |
] ifFalse:[ |
19451 | 3834 |
aGc displayString:s x:x y:yBaseline. |
5755 | 3835 |
]. |
3836 |
||
3837 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3838 |
! |
|
3839 |
||
3840 |
displayOpaqueOn:aGC x:x y:y |
|
3841 |
"display the receiver in a graphicsContext - this method allows |
|
3842 |
for any object to be displayed in a ListView - for example." |
|
3843 |
||
3844 |
self displayOn:aGC x:x y:y opaque:true |
|
3845 |
||
3846 |
"Modified: / 29.5.1996 / 16:29:38 / cg" |
|
3847 |
"Created: / 26.10.1997 / 15:01:36 / cg" |
|
3848 |
! |
|
3849 |
||
3850 |
displayString |
|
3851 |
"return a string used when displaying the receiver in a view; |
|
3852 |
for example an Inspector. This is usually the same as printString, |
|
14292
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3853 |
but sometimes redefined for a better look. |
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3854 |
|
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3855 |
Note: the base method (used by the inspector) is #displayOn:. |
19846 | 3856 |
So you should implement #displayOn: instead of #displayString in subclasses." |
5755 | 3857 |
|
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3858 |
|s| |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3859 |
|
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
3860 |
"/ attention: TextStream is not present in ultra-mini standalone apps |
15932
61bf45ec26c9
fixed displayString for systems without libbasic2
Claus Gittinger <cg@exept.de>
parents:
15931
diff
changeset
|
3861 |
s := TextStream isNil |
19846 | 3862 |
ifTrue:['' writeStream] |
3863 |
ifFalse:[TextStream on:(String new:32)]. |
|
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3864 |
self displayOn:s. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3865 |
^ s contents |
5755 | 3866 |
|
3867 |
" |
|
10460 | 3868 |
#(1 2 3) printString |
3869 |
#(1 2 3) displayString |
|
5755 | 3870 |
#(1 2 3) storeString |
3871 |
" |
|
3872 |
! |
|
3873 |
||
3874 |
heightOn:aGC |
|
3875 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
3876 |
||
3877 |
^ (aGC font onDevice:aGC device) heightOf:(self displayString) |
|
3878 |
! |
|
3879 |
||
16010 | 3880 |
printStringForPrintIt |
3881 |
"for compatibility (used to be displayString), now the printIt menu function now sends this message" |
|
3882 |
||
3883 |
^ self displayString |
|
3884 |
||
3885 |
" |
|
3886 |
#(1 2 3) printString |
|
3887 |
#(1 2 3) printStringForPrintIt |
|
3888 |
#(1 2 3) storeString |
|
3889 |
" |
|
3890 |
! |
|
3891 |
||
6654 | 3892 |
widthFrom:startIndex to:endIndex on:aGC |
3893 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3894 |
||
3895 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) from:startIndex to:endIndex |
|
3896 |
! |
|
3897 |
||
5755 | 3898 |
widthOn:aGC |
3899 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3900 |
||
3901 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) |
|
3902 |
! ! |
|
3903 |
||
7359 | 3904 |
!Object methodsFor:'double dispatching'! |
3905 |
||
3906 |
equalFromComplex:aComplex |
|
3907 |
"adding this method here allows for any non-number to be compared to a complex |
|
3908 |
and return false from this comparison. |
|
3909 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3910 |
which uses #= (i.e. a Set or Dictionary)." |
|
3911 |
||
3912 |
^ false |
|
3913 |
! |
|
3914 |
||
3915 |
equalFromFixedPoint:aFixedPoint |
|
3916 |
"adding this method here allows for any non-number to be compared to a fixedPoint |
|
3917 |
and return false from this comparison. |
|
3918 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3919 |
which uses #= (i.e. a Set or Dictionary)." |
|
3920 |
||
3921 |
^ false |
|
3922 |
! |
|
3923 |
||
3924 |
equalFromFloat:aFloat |
|
3925 |
"adding this method here allows for any non-number to be compared to a float |
|
3926 |
and return false from this comparison. |
|
3927 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3928 |
which uses #= (i.e. a Set or Dictionary)." |
|
3929 |
||
3930 |
^ false |
|
3931 |
! |
|
3932 |
||
3933 |
equalFromFraction:aFraction |
|
3934 |
"adding this method here allows for any non-number to be compared to a fraction |
|
3935 |
and return false from this comparison. |
|
3936 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3937 |
which uses #= (i.e. a Set or Dictionary)." |
|
3938 |
||
3939 |
^ false |
|
3940 |
! |
|
3941 |
||
3942 |
equalFromInteger:anInteger |
|
3943 |
"adding this method here allows for any non-number to be compared to an integer |
|
3944 |
and return false from this comparison. |
|
3945 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3946 |
which uses #= (i.e. a Set or Dictionary)." |
|
3947 |
||
3948 |
^ false |
|
3949 |
! |
|
3950 |
||
7455 | 3951 |
equalFromLargeFloat:aLargeFloat |
3952 |
"adding this method here allows for any non-number to be compared to a largeFloat |
|
3953 |
and return false from this comparison. |
|
3954 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3955 |
which uses #= (i.e. a Set or Dictionary)." |
|
3956 |
||
3957 |
^ false |
|
3958 |
! |
|
3959 |
||
7359 | 3960 |
equalFromLongFloat:aLongFloat |
3961 |
"adding this method here allows for any non-number to be compared to a longFloat |
|
3962 |
and return false from this comparison. |
|
3963 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3964 |
which uses #= (i.e. a Set or Dictionary)." |
|
3965 |
||
3966 |
^ false |
|
3967 |
! |
|
3968 |
||
3969 |
equalFromShortFloat:aShortFloat |
|
3970 |
"adding this method here allows for any non-number to be compared to a shortFloat |
|
3971 |
and return false from this comparison. |
|
3972 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3973 |
which uses #= (i.e. a Set or Dictionary)." |
|
3974 |
||
3975 |
^ false |
|
3976 |
! ! |
|
3977 |
||
5755 | 3978 |
!Object methodsFor:'encoding & decoding'! |
3979 |
||
3980 |
decodeAsLiteralArray |
|
8832 | 3981 |
"given a literalEncoding in the receiver, |
3982 |
create & return the corresponding object. |
|
3983 |
The inverse operation to #literalArrayEncoding." |
|
3984 |
||
5755 | 3985 |
^ self |
3986 |
! |
|
3987 |
||
3988 |
encodeOn:anEncoder with:aParameter |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3989 |
"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
|
3990 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3991 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3992 |
|
8404 | 3993 |
self acceptVisitor:anEncoder with:aParameter |
6718 | 3994 |
! |
3995 |
||
3996 |
encodingVectorForInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3997 |
"OBSOLETE, use elementDescriptorForInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3998 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
3999 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4000 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4001 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
6718 | 4002 |
|
4003 |
" |
|
4004 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
4005 |
Dictionary new encodingVectorForInstanceVariables |
|
4006 |
(5 @ nil) encodingVectorForInstanceVariables |
|
4007 |
" |
|
4008 |
! |
|
4009 |
||
4010 |
encodingVectorForNonNilInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4011 |
"OBSOLETE, use elementDescriptorForNonNilInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4012 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4013 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4014 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4015 |
^ self elementDescriptorForInstanceVariablesMatching:[:varVal | varVal notNil]. |
6718 | 4016 |
|
4017 |
" |
|
4018 |
#(1 2 3 nil true symbol) encodingVectorForNonNilInstanceVariables |
|
4019 |
(5 @ nil) encodingVectorForNonNilInstanceVariables |
|
4020 |
" |
|
4021 |
! |
|
4022 |
||
5755 | 4023 |
fromLiteralArrayEncoding:aSpecArray |
8798 | 4024 |
"read my attributes from aSpecArray. |
4025 |
Recursively decodes arguments." |
|
4026 |
||
19802 | 4027 |
|sel litVal val msg ex |
5755 | 4028 |
stop "{ Class:SmallInteger }" | |
4029 |
||
4030 |
stop := aSpecArray size. |
|
4031 |
||
4032 |
2 to:stop by:2 do:[:i| |
|
19799 | 4033 |
sel := aSpecArray at:i. |
4034 |
litVal := aSpecArray at:i + 1. |
|
4035 |
||
4036 |
(self respondsTo:sel) ifTrue:[ |
|
4037 |
val := litVal decodeAsLiteralArray. |
|
4038 |
self perform:sel with:val |
|
4039 |
] ifFalse:[ |
|
4040 |
"/ that's a debug halt, |
|
4041 |
"/ it should probably be removed (to simply ignore unhandled attributes)... |
|
4042 |
"/ for now, it is left in, in order to easily find incompatibilities between |
|
4043 |
"/ VW and ST/X. |
|
4044 |
self breakPoint:#cg. |
|
4045 |
||
4046 |
msg := '%1: unhandled literalArrayEncoding attribute:' |
|
4047 |
bindWith:self class name |
|
4048 |
with:sel. |
|
4049 |
UnhandledAttributeInLiteralArrayErrorSignal isHandled ifTrue:[ |
|
19802 | 4050 |
ex := UnhandledAttributeInLiteralArrayErrorSignal new. |
4051 |
ex badLiteralArray:self. |
|
4052 |
ex parameter:sel. |
|
4053 |
ex notify:msg. |
|
19799 | 4054 |
] ifFalse:[ |
4055 |
msg infoPrintCR. |
|
4056 |
]. |
|
4057 |
] |
|
5755 | 4058 |
] |
4059 |
! |
|
4060 |
||
4061 |
literalArrayEncoding |
|
4062 |
"generate a literalArrayEncoding array for myself. |
|
4063 |
This uses #literalArrayEncodingSlotOrder which defines the slots and |
|
4064 |
order and #skippedInLiteralEncoding which defines slots to skip. |
|
4065 |
For most subclasses, there is no need to redefine those." |
|
4066 |
||
8832 | 4067 |
|names encoding cls skipped slots| |
5755 | 4068 |
|
4069 |
self isLiteral ifTrue:[ |
|
19846 | 4070 |
^ self |
5755 | 4071 |
]. |
4072 |
||
8832 | 4073 |
slots := self literalArrayEncodingSlotOrder. |
5755 | 4074 |
skipped := self skippedInLiteralEncoding. |
4075 |
cls := self class. |
|
4076 |
names := cls allInstVarNames. |
|
8832 | 4077 |
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
|
4078 |
encoding add:cls name. |
8832 | 4079 |
|
4080 |
slots do:[:instSlot | |
|
19846 | 4081 |
|value nm| |
4082 |
||
4083 |
nm := names at:instSlot. |
|
4084 |
(skipped includes:nm) ifFalse:[ |
|
4085 |
(value := self instVarAt:instSlot) notNil ifTrue:[ |
|
4086 |
encoding add:(nm asMutator). |
|
4087 |
encoding add:value literalArrayEncoding |
|
4088 |
] |
|
4089 |
] |
|
5755 | 4090 |
]. |
4091 |
^ encoding asArray |
|
8841 | 4092 |
|
4093 |
" |
|
19846 | 4094 |
(1 -> 2) literalArrayEncoding |
4095 |
DebugView menuSpec decodeAsLiteralArray literalArrayEncoding = |
|
4096 |
DebugView menuSpec |
|
8841 | 4097 |
" |
5755 | 4098 |
! |
4099 |
||
4100 |
literalArrayEncodingSlotOrder |
|
4101 |
"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
|
4102 |
a literalArrayEncoding" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4103 |
|
5755 | 4104 |
^ 1 to:self class instSize |
4105 |
! |
|
4106 |
||
7112 | 4107 |
postDecodeFrom:aDecoder aspect:aspectSymbol |
4108 |
"invoked by xmlDecoder (and others in the future), after an |
|
4109 |
object has been decoded (i.e. its instance variables have been restored)" |
|
4110 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4111 |
^ self |
7112 | 4112 |
! |
4113 |
||
5755 | 4114 |
skippedInLiteralEncoding |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4115 |
"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
|
4116 |
|
5755 | 4117 |
^ #() |
4118 |
! ! |
|
4119 |
||
4120 |
!Object methodsFor:'error handling'! |
|
4121 |
||
16012 | 4122 |
abortOperation |
4123 |
"{ Pragma: +optSpace }" |
|
4124 |
||
4125 |
"raise the AbortOperationRequest signal. |
|
4126 |
This will unwind and bring the current thread back to the event-handling loop, |
|
4127 |
effectively aborting any current menu, user, doIt, printIt or other operation." |
|
4128 |
||
4129 |
<resource: #skipInDebuggersWalkBack> |
|
4130 |
||
4131 |
^ AbortOperationRequest raise |
|
4132 |
! |
|
4133 |
||
13416 | 4134 |
ambiguousMessage:aMessage |
4135 |
"this message is sent by the system in case that it |
|
4136 |
is not clear which method to execute in response to |
|
14632 | 4137 |
aMessage. |
13416 | 4138 |
Such situation may occur when a current selector namespace |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4139 |
imports two namespaces and both define a method with the |
13416 | 4140 |
requested selector." |
4141 |
||
4142 |
<context: #return> |
|
4143 |
<resource: #skipInDebuggersWalkBack> |
|
4144 |
||
4145 |
^ AmbiguousMessage raiseRequestWith:aMessage |
|
4146 |
||
4147 |
"Created: / 21-07-2010 / 15:44:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4148 |
"Modified (comment): / 02-11-2012 / 10:14:42 / cg" |
13416 | 4149 |
! |
4150 |
||
5755 | 4151 |
cannotSendMessage:aMessage to:someReceiver |
4152 |
"this message is sent by the runtime system (VM), |
|
4153 |
when a message is sent to some object, whose class is not |
|
4154 |
a valid behavior (see documentation in Behavior)." |
|
4155 |
||
11021 | 4156 |
<resource: #skipInDebuggersWalkBack> |
4157 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4158 |
^ VMInternalError |
19846 | 4159 |
raiseWith:someReceiver |
4160 |
errorString:('bad class in send of #' , aMessage selector) |
|
5755 | 4161 |
|
4162 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
4163 |
! |
|
4164 |
||
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4165 |
conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4166 |
"return the signal used for conversion error handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4167 |
|
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4168 |
^ self class conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4169 |
! |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4170 |
|
5755 | 4171 |
doesNotUnderstand:aMessage |
4172 |
"this message is sent by the runtime system (VM) when |
|
4173 |
a message is not understood by some object (i.e. there |
|
4174 |
is no method for that selector). The original message has |
|
4175 |
been packed into aMessage (i.e. the receiver, selector and |
|
4176 |
any arguments) and the original receiver is then sent the |
|
4177 |
#doesNotUnderstand: message. |
|
4178 |
Here, we raise another signal which usually enters the debugger. |
|
4179 |
You can of course redefine #doesNotUnderstand: in your classes |
|
10460 | 4180 |
to implement message delegation, |
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
4181 |
or handle the MessageNotUnderstood exception gracefully." |
5755 | 4182 |
|
4183 |
<context: #return> |
|
11021 | 4184 |
<resource: #skipInDebuggersWalkBack> |
5755 | 4185 |
|
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
4186 |
^ MessageNotUnderstood raiseRequestWith:aMessage |
5755 | 4187 |
! |
4188 |
||
4189 |
elementBoundsError |
|
4190 |
"{ Pragma: +optSpace }" |
|
4191 |
||
10460 | 4192 |
"report an error that badElement is out of bounds |
5755 | 4193 |
(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
|
4194 |
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
|
4195 |
|
11021 | 4196 |
<resource: #skipInDebuggersWalkBack> |
4197 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4198 |
^ ElementBoundsError raise |
5755 | 4199 |
|
4200 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
4201 |
! |
|
4202 |
||
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4203 |
elementBoundsError:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4204 |
"{ Pragma: +optSpace }" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4205 |
|
10460 | 4206 |
"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
|
4207 |
(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
|
4208 |
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
|
4209 |
|
11021 | 4210 |
<resource: #skipInDebuggersWalkBack> |
4211 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4212 |
^ ElementBoundsError raiseWith:aValue |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4213 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4214 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4215 |
! |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4216 |
|
5755 | 4217 |
elementNotCharacter |
4218 |
"{ Pragma: +optSpace }" |
|
4219 |
||
4220 |
"report an error that object to be stored is no Character. |
|
4221 |
(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
|
4222 |
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
|
4223 |
|
11021 | 4224 |
<resource: #skipInDebuggersWalkBack> |
4225 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4226 |
^ ElementBoundsError raise |
5755 | 4227 |
|
4228 |
"Modified: 8.5.1996 / 09:12:49 / cg" |
|
4229 |
! |
|
4230 |
||
4231 |
elementNotInteger |
|
4232 |
"{ Pragma: +optSpace }" |
|
4233 |
||
4234 |
"report an error that object to be stored is not Integer. |
|
4235 |
(in collections that store integers only). |
|
4236 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
4237 |
||
11021 | 4238 |
<resource: #skipInDebuggersWalkBack> |
4239 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4240 |
^ ElementBoundsError raise |
5755 | 4241 |
|
4242 |
"Modified: 8.5.1996 / 09:12:51 / cg" |
|
4243 |
! |
|
4244 |
||
4245 |
error |
|
4246 |
"{ Pragma: +optSpace }" |
|
4247 |
||
4248 |
"report error that an error occured. |
|
4249 |
The error is reported by raising the Error exception, |
|
4250 |
which is non-proceedable. |
|
4251 |
If no handler has been setup, a debugger is entered." |
|
4252 |
||
11021 | 4253 |
<context: #return> |
4254 |
<resource: #skipInDebuggersWalkBack> |
|
4255 |
||
5755 | 4256 |
Error raiseWith:#error: |
4257 |
||
4258 |
" |
|
4259 |
nil error |
|
4260 |
" |
|
4261 |
||
4262 |
"Modified: / 8.5.1996 / 09:13:01 / cg" |
|
4263 |
"Modified: / 2.8.1999 / 17:00:19 / stefan" |
|
4264 |
! |
|
4265 |
||
4266 |
error:aString |
|
4267 |
"{ Pragma: +optSpace }" |
|
4268 |
||
4269 |
"Raise an error with error message aString. |
|
4270 |
The error is reported by raising the Error exception, |
|
4271 |
which is non-proceedable. |
|
4272 |
If no handler has been setup, a debugger is entered." |
|
4273 |
||
11021 | 4274 |
<context: #return> |
4275 |
<resource: #skipInDebuggersWalkBack> |
|
4276 |
||
10460 | 4277 |
Error raiseWith:#error: errorString:aString |
5755 | 4278 |
|
4279 |
" |
|
4280 |
nil error:' bad bad bad' |
|
4281 |
" |
|
4282 |
||
4283 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
4284 |
! |
|
4285 |
||
4286 |
error:aString mayProceed:mayProceed |
|
4287 |
"{ Pragma: +optSpace }" |
|
4288 |
||
4289 |
"enter debugger with error-message aString. |
|
10460 | 4290 |
The error is reported by raising either the |
5755 | 4291 |
non-proceedable Error exception, |
4292 |
or the ProceedableError exception." |
|
4293 |
||
11021 | 4294 |
<resource: #skipInDebuggersWalkBack> |
4295 |
||
5755 | 4296 |
mayProceed ifTrue:[ |
19846 | 4297 |
^ ProceedableError raiseRequestWith:#error: errorString:aString |
10460 | 4298 |
]. |
4299 |
||
4300 |
Error raiseWith:#error: errorString:aString |
|
5755 | 4301 |
|
4302 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
4303 |
! |
|
4304 |
||
6900 | 4305 |
errorInvalidFormat |
4306 |
"{ Pragma: +optSpace }" |
|
4307 |
||
4308 |
"report an error that some conversion to/from string representation failed |
|
4309 |
typically when converting numbers, date, time etc." |
|
4310 |
||
11021 | 4311 |
<context: #return> |
4312 |
<resource: #skipInDebuggersWalkBack> |
|
4313 |
||
6900 | 4314 |
^ ConversionError raiseErrorString:'invalid format' |
4315 |
! |
|
4316 |
||
5755 | 4317 |
errorKeyNotFound:aKey |
4318 |
"{ Pragma: +optSpace }" |
|
4319 |
||
4320 |
"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
|
4321 |
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
|
4322 |
|
11021 | 4323 |
<resource: #skipInDebuggersWalkBack> |
4324 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
4325 |
^ 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
|
4326 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4327 |
" |
18685 | 4328 |
Dictionary new at:#nonExistentElement |
5755 | 4329 |
" |
4330 |
! |
|
4331 |
||
4332 |
errorNotFound |
|
4333 |
"{ Pragma: +optSpace }" |
|
4334 |
||
4335 |
"report an error that no element was found in a collection. |
|
4336 |
The error is reported by raising the NotFoundSignal exception." |
|
4337 |
||
11021 | 4338 |
<resource: #skipInDebuggersWalkBack> |
4339 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4340 |
^ NotFoundError raiseRequestWith:nil |
5755 | 4341 |
|
4342 |
"Modified: / 8.5.1996 / 09:13:11 / cg" |
|
4343 |
"Modified: / 26.7.1999 / 10:51:50 / stefan" |
|
4344 |
! |
|
4345 |
||
6874 | 4346 |
errorNotFound:errorString |
4347 |
"{ Pragma: +optSpace }" |
|
4348 |
||
4349 |
"report an error that no element was found in a collection. |
|
4350 |
The error is reported by raising the NotFoundSignal exception." |
|
4351 |
||
11021 | 4352 |
<resource: #skipInDebuggersWalkBack> |
4353 |
||
10837
63d19c75d762
changed #errorNotFound: raise it proceedable
Stefan Vogel <sv@exept.de>
parents:
10834
diff
changeset
|
4354 |
^ NotFoundError raiseRequestErrorString:errorString |
6874 | 4355 |
! |
4356 |
||
5755 | 4357 |
errorSignal |
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4358 |
"return the signal used for error/error: handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4359 |
|
5755 | 4360 |
^ self class errorSignal |
4361 |
||
4362 |
"Created: / 19.6.1998 / 02:32:32 / cg" |
|
4363 |
! |
|
4364 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4365 |
handlerForSignal:exceptionHandler context:theContext originator:originator |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4366 |
" 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
|
4367 |
|
7566 | 4368 |
thisContext isRecursive ifTrue:[^ nil]. |
4369 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4370 |
'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
|
4371 |
' context: ' print. theContext printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4372 |
' originator: ' print. originator printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4373 |
' sender: ' print. thisContext sender printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4374 |
|
7566 | 4375 |
"/ MiniDebugger enter:thisContext withMessage:'oops' mayProceed:true. |
4376 |
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
|
4377 |
! |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4378 |
|
5755 | 4379 |
implementedBySubclass |
4380 |
"{ Pragma: +optSpace }" |
|
4381 |
||
4382 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
4383 |
||
11021 | 4384 |
<resource: #skipInDebuggersWalkBack> |
4385 |
||
12322 | 4386 |
^ SubclassResponsibilityError raiseRequestErrorString:'method must be reimplemented in ST/V subclass' |
5755 | 4387 |
! |
4388 |
||
4389 |
indexNotInteger |
|
4390 |
"{ Pragma: +optSpace }" |
|
4391 |
||
4392 |
"report an error that index is not an Integer. |
|
4393 |
(when accessing collections indexed by an integer key). |
|
4394 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4395 |
||
11021 | 4396 |
<resource: #skipInDebuggersWalkBack> |
4397 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4398 |
^ NonIntegerIndexError raiseRequestWith:nil |
5755 | 4399 |
|
4400 |
"Modified: / 8.5.1996 / 09:13:37 / cg" |
|
4401 |
"Modified: / 26.7.1999 / 10:57:43 / stefan" |
|
4402 |
! |
|
4403 |
||
4404 |
indexNotInteger:anIndex |
|
4405 |
"{ Pragma: +optSpace }" |
|
4406 |
||
4407 |
"report an error that index is not an Integer. |
|
4408 |
(when accessing collections indexed by an integer key). |
|
4409 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4410 |
||
11021 | 4411 |
<resource: #skipInDebuggersWalkBack> |
4412 |
||
10460 | 4413 |
^ NonIntegerIndexError raiseRequestWith:anIndex |
5755 | 4414 |
|
4415 |
"Created: / 16.5.1998 / 19:39:41 / cg" |
|
4416 |
! |
|
4417 |
||
7216 | 4418 |
indexNotIntegerOrOutOfBounds:index |
4419 |
"{ Pragma: +optSpace }" |
|
4420 |
||
4421 |
"report an error that index is either non-integral or out of bounds" |
|
4422 |
||
11021 | 4423 |
<resource: #skipInDebuggersWalkBack> |
4424 |
||
7216 | 4425 |
index isInteger ifFalse:[ |
19846 | 4426 |
^ self indexNotInteger:index |
7216 | 4427 |
]. |
4428 |
^ self subscriptBoundsError:index |
|
4429 |
! |
|
4430 |
||
5755 | 4431 |
integerCheckError |
4432 |
"{ Pragma: +optSpace }" |
|
4433 |
||
12321 | 4434 |
"generated when a variable declared with an integer type gets a bad value assigned" |
5755 | 4435 |
|
11021 | 4436 |
<resource: #skipInDebuggersWalkBack> |
4437 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4438 |
"/ ^ self error:'bad assign of ' , self printString , |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4439 |
"/ ' (' , self class name , ') to integer-typed variable' |
14632 | 4440 |
^ InvalidTypeError |
19846 | 4441 |
raiseRequestErrorString:( |
4442 |
'bad assign of ' , self printString , |
|
4443 |
' (' , self class name , ') to integer-typed variable') |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4444 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4445 |
"Modified: / 02-11-2012 / 10:25:36 / cg" |
5755 | 4446 |
! |
4447 |
||
4448 |
invalidCodeObject |
|
4449 |
"{ Pragma: +optSpace }" |
|
4450 |
||
12321 | 4451 |
"this is sent by VM if it encounters some non-method for execution" |
4452 |
||
11021 | 4453 |
<resource: #skipInDebuggersWalkBack> |
4454 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4455 |
"/ self error:'not an executable code object' |
14632 | 4456 |
^ ExecutionError |
19846 | 4457 |
raiseRequestErrorString:'not an executable code object' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4458 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4459 |
"Created: / 01-08-1997 / 00:16:44 / cg" |
5755 | 4460 |
! |
4461 |
||
10460 | 4462 |
invalidMessage |
5755 | 4463 |
"{ Pragma: +optSpace }" |
4464 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4465 |
"this is sent by ST/V code - it's the same as #shouldNotImplement" |
5755 | 4466 |
|
11021 | 4467 |
<resource: #skipInDebuggersWalkBack> |
4468 |
||
5755 | 4469 |
^ self shouldNotImplement |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4470 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4471 |
"Modified (comment): / 02-11-2012 / 10:11:18 / cg" |
5755 | 4472 |
! |
4473 |
||
4474 |
mustBeRectangle |
|
4475 |
"{ Pragma: +optSpace }" |
|
4476 |
||
4477 |
"report an argument-not-rectangle-error" |
|
4478 |
||
11021 | 4479 |
<resource: #skipInDebuggersWalkBack> |
4480 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4481 |
"/ ^ self error:'argument must be a Rectangle' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4482 |
^ InvalidTypeError |
19846 | 4483 |
raiseRequestErrorString:'argument must be a Rectangle' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4484 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4485 |
"Modified: / 02-11-2012 / 10:24:53 / cg" |
5755 | 4486 |
! |
4487 |
||
4488 |
mustBeString |
|
4489 |
"{ Pragma: +optSpace }" |
|
4490 |
||
4491 |
"report an argument-not-string-error" |
|
4492 |
||
11021 | 4493 |
<resource: #skipInDebuggersWalkBack> |
4494 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4495 |
"/ ^ self error:'argument must be a String' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4496 |
^ InvalidTypeError |
19846 | 4497 |
raiseRequestErrorString:'argument must be a String' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4498 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4499 |
"Modified: / 02-11-2012 / 10:24:35 / cg" |
5755 | 4500 |
! |
4501 |
||
4502 |
notIndexed |
|
4503 |
"{ Pragma: +optSpace }" |
|
4504 |
||
4505 |
"report an error that receiver has no indexed instance variables. |
|
4506 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4507 |
||
11021 | 4508 |
<context: #return> |
4509 |
<resource: #skipInDebuggersWalkBack> |
|
4510 |
||
10460 | 4511 |
^ SubscriptOutOfBoundsError |
19846 | 4512 |
raiseRequestErrorString:'receiver has no indexed variables' |
5755 | 4513 |
|
14539 | 4514 |
" |
4515 |
1234 at:4 |
|
4516 |
" |
|
4517 |
||
5755 | 4518 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
4519 |
! |
|
4520 |
||
12050 | 4521 |
notYetImplemented |
4522 |
"{ Pragma: +optSpace }" |
|
4523 |
||
12321 | 4524 |
"report an error that some functionality is not yet implemented. |
4525 |
This is here only for compatibility - it has the same meaning as shouldImplement." |
|
12050 | 4526 |
|
4527 |
<resource: #skipInDebuggersWalkBack> |
|
4528 |
||
15891 | 4529 |
|sender| |
4530 |
||
4531 |
sender := thisContext sender. |
|
4532 |
||
4533 |
^ UnimplementedFunctionalityError |
|
19846 | 4534 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4535 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4536 |
"Modified: / 02-11-2012 / 10:24:12 / cg" |
12050 | 4537 |
! |
4538 |
||
5755 | 4539 |
primitiveFailed |
4540 |
"{ Pragma: +optSpace }" |
|
4541 |
||
4542 |
"report an error that some primitive code failed. |
|
14539 | 4543 |
The error is reported by raising the PrimitiveFailure exception. |
4544 |
Sorry for the code duplication: it avoids the extra frame in the debugger." |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4545 |
|
11021 | 4546 |
<resource: #skipInDebuggersWalkBack> |
4547 |
||
15891 | 4548 |
|sender selector| |
4549 |
||
4550 |
"do loop to take care of super sends" |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4551 |
sender := thisContext sender. |
15891 | 4552 |
[ |
19846 | 4553 |
selector := sender selector. |
4554 |
selector == #primitiveFailed: or:[selector == #primitiveFailed] |
|
15891 | 4555 |
] whileTrue:[sender := sender sender]. |
4556 |
||
4557 |
^ PrimitiveFailure raiseRequestWith:(Message selector:selector arguments:sender args) |
|
19846 | 4558 |
in:sender. |
5755 | 4559 |
|
6005 | 4560 |
" |
4561 |
1234 primitiveFailed |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4562 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4563 |
[ |
19846 | 4564 |
ExternalBytes new basicAt:40 |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4565 |
] on:PrimitiveFailure do:[:ex| |
19846 | 4566 |
ex inspect |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4567 |
] |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4568 |
" |
5755 | 4569 |
! |
4570 |
||
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4571 |
primitiveFailed:messageString |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4572 |
"{ Pragma: +optSpace }" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4573 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4574 |
"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
|
4575 |
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
|
4576 |
|
11021 | 4577 |
<resource: #skipInDebuggersWalkBack> |
4578 |
||
15891 | 4579 |
|sender selector| |
4580 |
||
4581 |
"do loop to take care of super sends" |
|
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4582 |
sender := thisContext sender. |
15891 | 4583 |
[ |
19846 | 4584 |
selector := sender selector. |
4585 |
selector == #primitiveFailed: or:[selector == #primitiveFailed] |
|
15891 | 4586 |
] whileTrue:[sender := sender sender]. |
4587 |
||
4588 |
^ PrimitiveFailure raiseRequestWith:(Message selector:selector arguments:sender args) |
|
19846 | 4589 |
errorString:messageString |
4590 |
in:sender. |
|
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4591 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4592 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4593 |
1234 primitiveFailed:'this is a test' |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4594 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4595 |
! |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4596 |
|
6815 | 4597 |
shouldImplement |
4598 |
"{ Pragma: +optSpace }" |
|
4599 |
||
12321 | 4600 |
"report an error that this message/functionality should be implemented. |
4601 |
This is send by automatically generated method bodies or inside as-yet-uncoded |
|
4602 |
branches of existing methods." |
|
6815 | 4603 |
|
11021 | 4604 |
<resource: #skipInDebuggersWalkBack> |
4605 |
||
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4606 |
|sender| |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4607 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4608 |
sender := thisContext sender. |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4609 |
|
12841 | 4610 |
^ UnimplementedFunctionalityError |
19846 | 4611 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4612 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4613 |
" |
12321 | 4614 |
self shouldImplement |
4615 |
" |
|
4616 |
! |
|
4617 |
||
4618 |
shouldImplement:what |
|
4619 |
"{ Pragma: +optSpace }" |
|
4620 |
||
4621 |
"report an error that this message/functionality should be implemented. |
|
4622 |
This is send by automatically generated method bodies or inside as-yet-uncoded |
|
4623 |
branches of existing methods." |
|
4624 |
||
4625 |
<resource: #skipInDebuggersWalkBack> |
|
4626 |
||
4627 |
|sender| |
|
4628 |
||
4629 |
sender := thisContext sender. |
|
4630 |
||
12841 | 4631 |
^ UnimplementedFunctionalityError |
19846 | 4632 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
4633 |
errorString:what |
|
12321 | 4634 |
|
4635 |
" |
|
4636 |
self shouldImplement:'foobar' |
|
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4637 |
" |
6815 | 4638 |
! |
4639 |
||
11976 | 4640 |
shouldNeverBeReached |
12321 | 4641 |
"report an error that this point may never be reached." |
12841 | 4642 |
|
14499 | 4643 |
<resource: #skipInDebuggersWalkBack> |
4644 |
||
4645 |
^ ExecutionError |
|
19846 | 4646 |
raiseRequestErrorString:'Oops, this may never reached. Something somewhere was terribly wrong.'. |
11976 | 4647 |
|
4648 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
4649 |
! |
|
4650 |
||
4651 |
shouldNeverBeSent |
|
12321 | 4652 |
"report an error that this message may never be sent to the reciever" |
12841 | 4653 |
|
14499 | 4654 |
<resource: #skipInDebuggersWalkBack> |
4655 |
||
14632 | 4656 |
^ MethodNotAppropriateError |
19846 | 4657 |
raiseRequestErrorString:'This message never may be sent to me'. |
11976 | 4658 |
|
4659 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4660 |
"Modified: / 02-11-2012 / 10:10:42 / cg" |
11976 | 4661 |
! |
4662 |
||
5755 | 4663 |
shouldNotImplement |
4664 |
"{ Pragma: +optSpace }" |
|
4665 |
||
12841 | 4666 |
"report an error that this message should not be implemented - |
12733
48cc66ac5d52
comment/format in: #shouldNotImplement
Claus Gittinger <cg@exept.de>
parents:
12718
diff
changeset
|
4667 |
i.e. that a method is invoked which is not appropriate for the receiver." |
5755 | 4668 |
|
11021 | 4669 |
<resource: #skipInDebuggersWalkBack> |
4670 |
||
14632 | 4671 |
^ MethodNotAppropriateError |
19846 | 4672 |
raiseRequestErrorString:'method/functionality is not appropriate for class'. |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4673 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4674 |
"Modified: / 02-11-2012 / 10:02:25 / cg" |
5755 | 4675 |
! |
4676 |
||
4677 |
subclassResponsibility |
|
4678 |
"{ Pragma: +optSpace }" |
|
4679 |
||
12321 | 4680 |
"report an error that this message should have been reimplemented in a subclass" |
5755 | 4681 |
|
11021 | 4682 |
<resource: #skipInDebuggersWalkBack> |
4683 |
||
10877
0666d48f91d1
show the affected method-selector in the subclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
10856
diff
changeset
|
4684 |
^ SubclassResponsibilityError raiseRequestWith:thisContext sender selector |
5755 | 4685 |
! |
4686 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4687 |
subclassResponsibility:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4688 |
"{ Pragma: +optSpace }" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4689 |
|
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4690 |
"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
|
4691 |
|
11021 | 4692 |
<resource: #skipInDebuggersWalkBack> |
4693 |
||
7334 | 4694 |
^ SubclassResponsibilityError raiseRequestErrorString:msg |
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4695 |
! |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4696 |
|
5755 | 4697 |
subscriptBoundsError |
4698 |
"{ Pragma: +optSpace }" |
|
4699 |
||
4700 |
"report an error that some index is out of bounds. |
|
4701 |
(when accessing indexable collections). |
|
4702 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4703 |
||
11021 | 4704 |
<resource: #skipInDebuggersWalkBack> |
4705 |
||
5755 | 4706 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:nil |
4707 |
||
4708 |
"Modified: / 26.7.1996 / 16:45:42 / cg" |
|
4709 |
"Modified: / 26.7.1999 / 10:58:27 / stefan" |
|
4710 |
! |
|
4711 |
||
4712 |
subscriptBoundsError:anIndex |
|
4713 |
"{ Pragma: +optSpace }" |
|
4714 |
||
4715 |
"report an error that anIndex is out of bounds. |
|
4716 |
(when accessing indexable collections). |
|
4717 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4718 |
||
11021 | 4719 |
<resource: #skipInDebuggersWalkBack> |
4720 |
||
10460 | 4721 |
^ SubscriptOutOfBoundsError |
19846 | 4722 |
raiseRequestWith:anIndex |
4723 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
5755 | 4724 |
|
6221 | 4725 |
"Modified: / 17.11.2001 / 22:49:56 / cg" |
5755 | 4726 |
! |
4727 |
||
4728 |
typeCheckError |
|
4729 |
"{ Pragma: +optSpace }" |
|
4730 |
||
4731 |
"generated when a variable declared with a type hint gets a bad |
|
4732 |
value assigned" |
|
4733 |
||
11021 | 4734 |
<resource: #skipInDebuggersWalkBack> |
4735 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4736 |
"/ ^ self error:'bad assign of ' , self printString , |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4737 |
"/ ' (' , self class name , ') to typed variable' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4738 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4739 |
^ InvalidTypeError |
19846 | 4740 |
raiseRequestErrorString: |
4741 |
('bad assign of ' , self printString , |
|
4742 |
' (' , self class name , ') to typed variable') |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4743 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4744 |
"Modified: / 02-11-2012 / 10:19:15 / cg" |
5755 | 4745 |
! ! |
4746 |
||
16311 | 4747 |
!Object methodsFor:'error handling - debugger'! |
4748 |
||
4749 |
addDebuggerHook:aBlock |
|
4750 |
"add a debugger hook. Any registered hook is evaluated with the exception as |
|
16560 | 4751 |
argument before a real debugger is entered. |
16311 | 4752 |
Hooks can be used for two purposes: |
19846 | 4753 |
- record exception information in a log file |
4754 |
- filter exceptions and either decide to ignore them or to open an alternative |
|
4755 |
debugger (depending on the exception type, maybe)" |
|
16311 | 4756 |
|
4757 |
DebuggerHooks isNil ifTrue:[ |
|
19846 | 4758 |
DebuggerHooks := OrderedCollection new. |
16311 | 4759 |
]. |
4760 |
DebuggerHooks add:aBlock |
|
4761 |
||
4762 |
" |
|
4763 |
Object addDebuggerHook:[:ex | AbortSignal raise]. |
|
4764 |
(1 / (1-1)). |
|
4765 |
Object removeDebuggerHook:(DebuggerHooks first). |
|
4766 |
" |
|
4767 |
" |
|
4768 |
Object addDebuggerHook:[:ex | Transcript showCR:ex ]. |
|
4769 |
(1 / (1-1)). |
|
4770 |
Object removeDebuggerHook:(DebuggerHooks first). |
|
4771 |
" |
|
4772 |
" |
|
4773 |
Object addDebuggerHook:[:ex | ex suspendedContext fullPrintAllOn:Transcript ]. |
|
4774 |
(1 / (1-1)). |
|
4775 |
Object removeDebuggerHook:(DebuggerHooks first). |
|
4776 |
" |
|
4777 |
" |
|
4778 |
Object addDebuggerHook:[:ex | '/tmp/stx.log' asFilename |
|
19846 | 4779 |
appendingFileDo:[:s | |
4780 |
s nextPutLine:'----------------------'. |
|
4781 |
(Timestamp now printOn:s). s cr. |
|
4782 |
ex suspendedContext fullPrintAllOn:s |
|
4783 |
]]. |
|
16311 | 4784 |
(1 / (1-1)). |
4785 |
Object removeDebuggerHook:(DebuggerHooks first). |
|
4786 |
" |
|
4787 |
! |
|
4788 |
||
4789 |
appropriateDebugger:aSelector |
|
4790 |
"{ Pragma: +optSpace }" |
|
4791 |
||
4792 |
"return an appropriate debugger to use. |
|
4793 |
If there is already a debugger active on the stack, and it is |
|
4794 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
4795 |
||
4796 |
|context| |
|
4797 |
||
4798 |
"DebugView cannot run without system processes" |
|
4799 |
||
4800 |
(Processor isNil |
|
4801 |
or:[Processor activeProcessIsSystemProcess |
|
4802 |
or:[Smalltalk isInitialized not]]) ifTrue:[ |
|
19846 | 4803 |
^ MiniDebugger |
16311 | 4804 |
]. |
4805 |
(Screen isNil or:[Screen default isNil or:[Screen default isOpen not]]) ifTrue:[ |
|
19846 | 4806 |
Debugger isNil ifTrue:[^ nil]. |
4807 |
^ MiniDebugger |
|
16311 | 4808 |
]. |
4809 |
||
4810 |
context := thisContext. |
|
4811 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
4812 |
[context notNil] whileTrue:[ |
|
19846 | 4813 |
((context receiver class == Debugger) |
4814 |
and:[context selector == aSelector]) ifTrue:[ |
|
4815 |
"we are already in some Debugger" |
|
4816 |
(Debugger == MiniDebugger) ifTrue:[ |
|
4817 |
"we are already in the MiniDebugger" |
|
4818 |
ErrorRecursion ifFalse:[ |
|
4819 |
Smalltalk fatalAbort:'recursive error ...' |
|
4820 |
] |
|
4821 |
]. |
|
4822 |
MiniDebugger isNil ifTrue:[ |
|
4823 |
Smalltalk fatalAbort:'no debugger' |
|
4824 |
]. |
|
4825 |
||
4826 |
"ok, an error occured while in the graphical debugger; |
|
4827 |
lets try MiniDebugger" |
|
4828 |
^ MiniDebugger |
|
4829 |
]. |
|
4830 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
16311 | 4831 |
]. |
4832 |
"not within Debugger - no problem" |
|
4833 |
^ Debugger |
|
4834 |
||
4835 |
"Modified: / 23.9.1996 / 12:14:52 / stefan" |
|
4836 |
"Modified: / 19.5.1999 / 18:05:00 / cg" |
|
4837 |
! |
|
4838 |
||
4839 |
openDebuggerOnException:ex |
|
4840 |
"{ Pragma: +optSpace }" |
|
4841 |
||
4842 |
"enter the debugger on some unhandled exception" |
|
4843 |
||
4844 |
|msgString debugger| |
|
4845 |
||
4846 |
msgString := ex descriptionForDebugger. |
|
4847 |
||
4848 |
" |
|
16560 | 4849 |
if there is no debugger, ask for ignore or exit. |
16311 | 4850 |
Exit will terminate the application. |
4851 |
ignore will raise an AbortOperationRequest. |
|
4852 |
" |
|
4853 |
Debugger isNil ifTrue:[ |
|
19846 | 4854 |
msgString := 'Error: ' , msgString. |
4855 |
||
4856 |
thisContext isRecursive ifTrue:[ |
|
4857 |
msgString errorPrintCR. |
|
4858 |
Smalltalk fatalAbort:'recursive unhandled exception' |
|
4859 |
]. |
|
4860 |
||
4861 |
Smalltalk isStandAloneApp ifTrue:[ |
|
4862 |
(ex creator == NoHandlerError) ifTrue:[ |
|
4863 |
(HaltInterrupt handles:ex exception) ifTrue:[ |
|
4864 |
"/ 'Halt ignored' infoPrintCR. |
|
4865 |
^ nil |
|
4866 |
]. |
|
4867 |
"don't output the message, if the exception is a UserInterrupt (CTRL-C)" |
|
4868 |
(ex exception creator == UserInterrupt) ifTrue:[ |
|
4869 |
ex description errorPrintCR. |
|
4870 |
OperatingSystem exit:130. |
|
4871 |
]. |
|
4872 |
]. |
|
4873 |
]. |
|
4874 |
||
4875 |
(Dialog notNil and:[Screen default notNil]) ifTrue:[ |
|
4876 |
self |
|
4877 |
errorNotify:msgString |
|
4878 |
from:ex suspendedContext |
|
4879 |
allowDebug:false |
|
4880 |
mayProceed:ex willProceed. |
|
4881 |
||
4882 |
"/ arrive here if proceeded... |
|
4883 |
^ nil |
|
4884 |
]. |
|
4885 |
||
4886 |
"don't output the message, if the exception is a UserInterrupt (CTRL-C)" |
|
4887 |
(ex creator == NoHandlerError |
|
4888 |
and:[ex exception creator == UserInterrupt]) ifTrue:[ |
|
4889 |
OperatingSystem exit:130. |
|
4890 |
]. |
|
4891 |
msgString errorPrintCR. |
|
4892 |
'Backtrace:' errorPrintCR. |
|
4893 |
thisContext fullPrintAll. |
|
4894 |
OperatingSystem exit:1 |
|
16311 | 4895 |
]. |
4896 |
||
4897 |
" |
|
4898 |
find an appropriate debugger to use |
|
4899 |
" |
|
4900 |
debugger := self appropriateDebugger:(thisContext selector). |
|
4901 |
debugger isNil ifTrue:[ |
|
19846 | 4902 |
^ AbortOperationRequest raiseRequest |
16311 | 4903 |
]. |
4904 |
||
4905 |
"/ call any registered debug hooks. |
|
4906 |
"/ These may record or further filter the exception. Each hook gets the exception object and may send any |
|
4907 |
"/ ex-message (ex proceed, ex return etc.) or raise an Abort signal. |
|
4908 |
"/ However, the real intent for hooks is to allow saving exceptions in a log file... |
|
4909 |
DebuggerHooks notNil ifTrue:[ |
|
19846 | 4910 |
DebuggerHooks do:[:eachHook | |
4911 |
eachHook value:ex. |
|
4912 |
]. |
|
16311 | 4913 |
]. |
4914 |
^ debugger enterException:ex. |
|
4915 |
||
4916 |
"Modified: / 05-12-2011 / 11:53:10 / cg" |
|
4917 |
! |
|
4918 |
||
4919 |
removeDebuggerHook:aBlock |
|
4920 |
"remove a debugger hook." |
|
4921 |
||
4922 |
DebuggerHooks notNil ifTrue:[ |
|
19846 | 4923 |
DebuggerHooks removeIdentical:aBlock. |
4924 |
DebuggerHooks isNil ifTrue:[ DebuggerHooks := nil ]. |
|
16311 | 4925 |
]. |
4926 |
! ! |
|
4927 |
||
5755 | 4928 |
!Object methodsFor:'evaluation'! |
4929 |
||
8690
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4930 |
argumentCount |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4931 |
"compatibility with Blocks and Messages. |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4932 |
Answer 0, since we only understand #value. |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4933 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4934 |
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
|
4935 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4936 |
^ 0 |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4937 |
|
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4938 |
" |
19846 | 4939 |
[1 // 0] on:ArithmeticError do:9999 |
8690
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4940 |
" |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4941 |
! |
5894d98a4a61
Implement #argumentCount for Block-compatibility.
Stefan Vogel <sv@exept.de>
parents:
8637
diff
changeset
|
4942 |
|
5755 | 4943 |
value |
4944 |
"return the receiver itself. |
|
4945 |
This allows every object to be used where blocks or valueHolders |
|
4946 |
are typically used, and allows for valueHolders and blocks to be |
|
4947 |
used interchangably in some situations. |
|
4948 |
||
4949 |
Time will show, if this is a good idea or leads to sloppy programming |
|
4950 |
style ... (the idea was borrowed from the Self language). |
|
4951 |
||
10460 | 4952 |
WARNING: dont 'optimize' away ifXXX: blocks |
19846 | 4953 |
(i.e. do NOT replace |
4954 |
foo ifTrue:[var1] ifFalse:[var2] |
|
4955 |
by: |
|
4956 |
foo ifTrue:var1 ifFalse:var2 |
|
4957 |
) |
|
4958 |
- the compilers will only generate inline code for the if, |
|
4959 |
iff the argument(s) are blocks - otherwise, a true send is |
|
4960 |
generated. |
|
4961 |
This 'oprimization' will work semantically correct, |
|
4962 |
but execute SLOWER instead." |
|
5755 | 4963 |
|
4964 |
^ self |
|
4965 |
||
4966 |
" |
|
10460 | 4967 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
4968 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
4969 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
4970 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
5755 | 4971 |
" |
4972 |
||
4973 |
"DO NOT DO THIS (its slower) |
|
7458 | 4974 |
(1 > 4) ifTrue:a ifFalse:b |
5755 | 4975 |
|
4976 |
USE (the compiler optimizes blocks in if/while): |
|
7458 | 4977 |
(1 > 4) ifTrue:[a] ifFalse:[b] |
5755 | 4978 |
" |
4979 |
||
4980 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
4981 |
! ! |
|
4982 |
||
4983 |
!Object methodsFor:'finalization'! |
|
4984 |
||
4985 |
disposed |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4986 |
"OBSOLETE INTERFACE: use #finalize |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4987 |
this is invoked for objects which have been registered |
5755 | 4988 |
in a Registry, when the original object dies. |
4989 |
Subclasses may redefine this method" |
|
4990 |
||
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4991 |
<resource: #obsolete> |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4992 |
|
5755 | 4993 |
^ self |
4994 |
! |
|
4995 |
||
4996 |
executor |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4997 |
"Return the object which does the finalization for me. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4998 |
This interface is also VW & Sqeak compatible," |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
4999 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5000 |
"for now, send #shallowCopyForFinalization, to be compatible with |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5001 |
classes designed for old ST/X versions" |
5755 | 5002 |
|
5003 |
^ self shallowCopyForFinalization |
|
5004 |
! |
|
5005 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5006 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5007 |
"answer a Registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5008 |
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
|
5009 |
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
|
5010 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5011 |
^ FinalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5012 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5013 |
|
5755 | 5014 |
finalize |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5015 |
"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
|
5016 |
in a Registry, when the original object dies. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5017 |
Subclasses may redefine this method |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5018 |
This interface is also VW-compatible" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5019 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5020 |
"send #disposed for compatibility with existing classes that still |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5021 |
implement the obsolete #disposed message" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5022 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5023 |
^ self disposed |
5755 | 5024 |
! |
5025 |
||
5026 |
reRegisterForFinalization |
|
5027 |
"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
|
5028 |
This will create a new executor, which will receive a #finalize message when |
5755 | 5029 |
the receiver is garbage collected." |
5030 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5031 |
self finalizationLobby registerChange:self |
5755 | 5032 |
! |
5033 |
||
5034 |
registerForFinalization |
|
5035 |
"register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5036 |
Once registered, the executor of the receiver will receive a #finalize message when |
5755 | 5037 |
the receiver is garbage collected." |
5038 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5039 |
self finalizationLobby register:self |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5040 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5041 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5042 |
shallowCopyForFinalization |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5043 |
"OBSOLETE INTERFACE: use #executor. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5044 |
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
|
5045 |
(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
|
5046 |
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
|
5047 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5048 |
<resource: #obsolete> |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5049 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5050 |
^ self shallowCopy |
5755 | 5051 |
! |
5052 |
||
5053 |
unregisterForFinalization |
|
5054 |
"unregister mySelf from later finalization" |
|
5055 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5056 |
self finalizationLobby unregister:self |
5755 | 5057 |
! ! |
5058 |
||
5059 |
!Object methodsFor:'initialization'! |
|
5060 |
||
5061 |
initialize |
|
5062 |
"just to ignore initialize to objects which do not need it" |
|
5063 |
||
5064 |
^ self |
|
5065 |
! ! |
|
5066 |
||
17677 | 5067 |
|
5755 | 5068 |
!Object methodsFor:'interrupt handling'! |
5069 |
||
5070 |
childSignalInterrupt |
|
5071 |
"death of a child process (unix process) - do nothing" |
|
5072 |
||
5073 |
^ self |
|
5074 |
! |
|
5075 |
||
5076 |
customInterrupt |
|
5077 |
"{ Pragma: +optSpace }" |
|
5078 |
||
5079 |
"a custom interrupt - but no handler has defined" |
|
5080 |
||
5081 |
self error:'custom interrupt' mayProceed:true |
|
5082 |
! |
|
5083 |
||
5084 |
errorInterrupt:errorID with:aParameter |
|
5085 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
10460 | 5086 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
5755 | 5087 |
which can be called from C subsystems to raise an (asynchronous) |
5088 |
error exception. |
|
5089 |
||
5090 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
5091 |
used from other C subsystems too, to upcast errors. |
|
5092 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
5093 |
IDs (currently) used: |
|
19846 | 5094 |
#DisplayError ..... x-error interrupt |
5095 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
5755 | 5096 |
" |
5097 |
||
6263
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
5098 |
|handlers handler| |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
5099 |
|
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
5100 |
handlers := ObjectMemory registeredErrorInterruptHandlers. |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
5101 |
handlers notNil ifTrue:[ |
19846 | 5102 |
handler := handlers at:errorID ifAbsent:nil. |
5103 |
handler notNil ifTrue:[ |
|
5104 |
"/ |
|
5105 |
"/ handler found; let it do whatever it wants ... |
|
5106 |
"/ |
|
5107 |
handler errorInterrupt:errorID with:aParameter. |
|
5108 |
^ self |
|
5109 |
]. |
|
5755 | 5110 |
]. |
5111 |
||
5112 |
"/ |
|
5113 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
5114 |
"/ |
|
10460 | 5115 |
^ Error |
19846 | 5116 |
raiseRequestWith:errorID |
5117 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
5755 | 5118 |
! |
5119 |
||
5120 |
exceptionInterrupt |
|
5121 |
"{ Pragma: +optSpace }" |
|
5122 |
||
5123 |
"exception interrupt - enter debugger" |
|
5124 |
||
5125 |
self error:'exception Interrupt' mayProceed:true |
|
5126 |
! |
|
5127 |
||
5128 |
fpExceptionInterrupt |
|
5129 |
"{ Pragma: +optSpace }" |
|
5130 |
||
5131 |
"a floating point exception occured - this one |
|
5132 |
has to be handled differently since it comes asynchronous |
|
5133 |
on some machines (for example, on machines with a separate FPU |
|
5134 |
or superscalar architectures. Also, errors from within primitive code |
|
5135 |
(or library functions such as GL) are sent via the Unix-signal |
|
5136 |
mechanism this way." |
|
5137 |
||
5138 |
|where rec| |
|
5139 |
||
5140 |
where := thisContext sender. |
|
5141 |
rec := where receiver. |
|
5142 |
rec isNumber ifTrue:[ |
|
19846 | 5143 |
^ rec class |
5144 |
raise:#domainErrorSignal |
|
5145 |
receiver:rec |
|
5146 |
selector:where selector |
|
5147 |
arguments:(where args asArray) |
|
5148 |
errorString:'floating point exception' |
|
5755 | 5149 |
]. |
5150 |
||
5151 |
"/ could be in some C-library ... |
|
7402 | 5152 |
^ DomainError raise |
5755 | 5153 |
! |
5154 |
||
5155 |
internalError:msg |
|
5156 |
"{ Pragma: +optSpace }" |
|
5157 |
||
5158 |
"this is triggered, when VM hits some bad error, |
|
5159 |
such as corrupted class, corrupted method/selector array |
|
5160 |
etc. The argument string gives some more information on what happened. |
|
5161 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
|
5162 |
Its not guaranteed, that the system is in a working condition once |
|
5163 |
this error occurred ...." |
|
5164 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
5165 |
VMInternalError raiseWith:self errorString:msg |
5755 | 5166 |
! |
5167 |
||
5168 |
ioInterrupt |
|
5169 |
"{ Pragma: +optSpace }" |
|
5170 |
||
5171 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
|
5172 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
5173 |
or it does not understand the ioInterrupt message. |
|
5174 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
5175 |
||
5176 |
self error:'I/O Interrupt - but no handler' mayProceed:true |
|
5177 |
! |
|
5178 |
||
5179 |
memoryInterrupt |
|
5180 |
"{ Pragma: +optSpace }" |
|
5181 |
||
5182 |
"out-of-memory interrupt and no handler - enter debugger" |
|
5183 |
||
5184 |
self error:'almost out of memory' mayProceed:true |
|
5185 |
! |
|
5186 |
||
5187 |
recursionInterrupt |
|
5188 |
"{ Pragma: +optSpace }" |
|
5189 |
||
5190 |
"recursion limit (actually: stack overflow) interrupt. |
|
5191 |
This interrupt is triggered, when a process stack grows above |
|
5192 |
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
|
5193 |
could be caught. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5194 |
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
|
5195 |
and the exception can be resumed. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5196 |
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
|
5197 |
is not proceedable. |
10460 | 5198 |
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
|
5199 |
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
|
5200 |
or debug for a while. |
5755 | 5201 |
If the signal is ignored, and the stack continues to grow, there |
5202 |
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
|
5203 |
terminates the process." |
5755 | 5204 |
|
16408 | 5205 |
|con remaining sender nSkipped caller level n| |
5755 | 5206 |
|
5207 |
(con := thisContext) isRecursive ifFalse:[ |
|
5208 |
"/ Processor activeProcess usedStackSize < Processor activeProcess maximumStackSize ifTrue:[ |
|
5209 |
"/ "/ mhmh - it hit me, but I am not responsible ... |
|
5210 |
"/ 'Stray recursionInterrupt ...' infoPrintCR. |
|
5211 |
"/ ^ self |
|
5212 |
"/ ]. |
|
19846 | 5213 |
ObjectMemory infoPrinting ifTrue:[ |
5214 |
level := 0. |
|
5215 |
caller := thisContext sender. |
|
5216 |
[caller notNil] whileTrue:[ |
|
5217 |
level := level + 1. |
|
5218 |
caller := caller sender. |
|
5219 |
]. |
|
5220 |
||
5221 |
'Object [info]: recursionInterrupt from:' printCR. |
|
5222 |
con := con sender. |
|
5223 |
remaining := 500. |
|
5224 |
n := 0. |
|
5225 |
[con notNil and:[remaining > 0]] whileTrue:[ |
|
5226 |
sender := con sender. |
|
5227 |
'| ' print. con fullPrint. |
|
5228 |
||
5229 |
nSkipped := 0. |
|
5230 |
[sender notNil and:[sender sender notNil |
|
5231 |
and:[sender selector == con selector |
|
5232 |
and:[sender sender selector == con selector |
|
5233 |
and:[sender method == con method]]]]] whileTrue:[ |
|
5234 |
nSkipped := nSkipped + 1. |
|
5235 |
con := sender. |
|
5236 |
sender := con sender. |
|
5237 |
]. |
|
5238 |
nSkipped > 0 ifTrue:[ |
|
5239 |
'| ... ***** ' print. nSkipped print. ' recursive contexts skipped *****' printCR. |
|
5240 |
]. |
|
5241 |
con := sender. |
|
5242 |
remaining := remaining - 1 |
|
5243 |
]. |
|
5244 |
]. |
|
5245 |
^ RecursionInterruptSignal raiseSignal |
|
5755 | 5246 |
] |
5247 |
||
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5248 |
"Modified: / 10.11.2001 / 15:15:56 / cg" |
5755 | 5249 |
! |
5250 |
||
5251 |
schedulerInterrupt |
|
5252 |
"{ Pragma: +optSpace }" |
|
5253 |
||
5254 |
"scheduler interrupt (supposed to be sent to Processor). |
|
5255 |
If we arrive here, either the Processor does not understand it, |
|
5256 |
or it has been set to nil. In any case, this is a sign of some |
|
5257 |
big trouble. Enter debugger." |
|
5258 |
||
5259 |
self error:'schedulerInterrupt - but no Processor' mayProceed:true |
|
5260 |
! |
|
5261 |
||
5262 |
signalInterrupt:signalNumber |
|
5263 |
"{ Pragma: +optSpace }" |
|
5264 |
||
10460 | 5265 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
10016 | 5266 |
(SIGPIPE), others (SIGBUS) are rather fatal... |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
5267 |
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
|
5268 |
Otherwise, a dialog is shown, asking the user on how to handle the signal. |
5755 | 5269 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
5270 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
5271 |
Currently (temporary kludge), these are passed as global variables." |
|
5272 |
||
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5273 |
|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
|
5274 |
action title screen| |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5275 |
|
13254 | 5276 |
thisContext isRecursive ifTrue:[ |
19846 | 5277 |
'Severe error: signalInterrupt while processing a signalInterrupt.' errorPrintCR. |
5278 |
'Terminating process ' errorPrint. Processor activeProcess errorPrintCR. |
|
13710 | 5279 |
"/ GenericException handle:[:ex | |
5280 |
"/ "/ ignore any error during termination |
|
5281 |
"/ ] do:[ |
|
5282 |
"/ Processor activeProcess terminate. |
|
5283 |
"/ ]. |
|
19846 | 5284 |
MiniDebugger enter. |
5285 |
Processor activeProcess terminateNoSignal. |
|
13254 | 5286 |
]. |
5287 |
||
5755 | 5288 |
"if there has been an ST-signal installed, use it ..." |
5289 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
5290 |
sig notNil ifTrue:[ |
|
19846 | 5291 |
sig raiseSignalWith:signalNumber. |
5292 |
^ self. |
|
5755 | 5293 |
]. |
5294 |
||
5295 |
"/ if handled, raise OSSignalInterruptSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
5296 |
OSSignalInterrupt isHandled ifTrue:[ |
19846 | 5297 |
OSSignalInterrupt raiseRequestWith:signalNumber. |
5298 |
^ self. |
|
10460 | 5299 |
]. |
5300 |
||
5301 |
" |
|
5302 |
special cases |
|
19846 | 5303 |
- SIGPWR: power failure - write a crash image and continue |
5304 |
- SIGHUP: hang up - write a crash image and exit |
|
10922 | 5305 |
" |
5306 |
(signalNumber == OperatingSystem sigPWR) ifTrue:[ |
|
19846 | 5307 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
5308 |
^ self. |
|
10922 | 5309 |
]. |
5310 |
(signalNumber == OperatingSystem sigHUP) ifTrue:[ |
|
19846 | 5311 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
5312 |
'Object [info]: exit due to hangup signal.' errorPrintCR. |
|
5313 |
Smalltalk exit:1. |
|
7031 | 5314 |
]. |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
5315 |
|
5755 | 5316 |
name := OperatingSystem nameForSignal:signalNumber. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5317 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5318 |
"if there is no screen at all, bring up a mini debugger" |
10460 | 5319 |
(Screen isNil |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5320 |
or:[(screen := Screen current) isNil |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5321 |
or:[(screen := Screen default) isNil |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5322 |
or:[screen isOpen not]]]) ifTrue:[ |
19846 | 5323 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5324 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5325 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5326 |
"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
|
5327 |
otherwise display stays locked" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5328 |
screen ungrabPointer; ungrabKeyboard. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5329 |
|
7031 | 5330 |
here := thisContext. |
5331 |
badContext := here sender. "the context, in which the signal occurred" |
|
5332 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5333 |
"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
|
5334 |
Screen currentScreenQuerySignal answer:screen do:[ |
19846 | 5335 |
" |
5336 |
SIGBUS, SIGSEGV and SIGILL do not make sense to ignore (i.e. continue) |
|
5337 |
since the system will retry the faulty instruction, which leads to |
|
5338 |
another signal - to avoid frustration, better not offer this option. |
|
5339 |
" |
|
5340 |
fatal := OperatingSystem isFatalSignal:signalNumber. |
|
5341 |
fatal ifTrue:[ |
|
5342 |
(Debugger isNil or:[here isRecursive]) ifTrue:[ |
|
5343 |
'Object [hard error]: signal ' errorPrint. signalNumber errorPrintCR. |
|
5344 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
5345 |
]. |
|
5346 |
" |
|
5347 |
a hard signal - go into debugger immediately |
|
5348 |
" |
|
5349 |
msg := 'OS-signal: ', name. |
|
5350 |
||
5351 |
"/ the IRQ-PC is passed as low-hi, to avoid the need |
|
5352 |
"/ to allocate a LargeInteger in the VM during signal |
|
5353 |
"/ time. I know, this is ugly. |
|
5354 |
||
5355 |
InterruptPcLow notNil ifTrue:[ |
|
5356 |
pc := InterruptPcLow + (InterruptPcHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
5357 |
pc ~~ 0 ifTrue:[ |
|
5358 |
msg := msg , ' PC=' , (pc printStringRadix:16) |
|
5359 |
]. |
|
5360 |
]. |
|
5361 |
InterruptAddrLow notNil ifTrue:[ |
|
5362 |
addr := InterruptAddrLow + (InterruptAddrHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
5363 |
addr ~~ 0 ifTrue:[ |
|
5364 |
msg := msg , ' ADDR=' , (addr printStringRadix:16) |
|
5365 |
]. |
|
5366 |
]. |
|
5367 |
Debugger enter:here withMessage:msg mayProceed:false. |
|
5368 |
"unreachable" |
|
5369 |
^ nil. |
|
5370 |
]. |
|
5371 |
||
5372 |
"if possible, open an option box asking the user what do. |
|
5373 |
Otherwise, start a debugger" |
|
5374 |
Dialog notNil ifTrue:[ |
|
5375 |
OperatingSystem isOSXlike ifTrue:[ |
|
5376 |
titles := #('Save crash image' 'Dump core' 'GDB' 'Exit ST/X' 'Debug'). |
|
5377 |
actions := #(save core gdb exit debug). |
|
5378 |
] ifFalse:[ |
|
5379 |
titles := #('Save crash image' 'Dump core' 'Exit ST/X' 'Debug'). |
|
5380 |
actions := #(save core exit debug). |
|
5381 |
]. |
|
5382 |
action := nil. |
|
5383 |
title := 'OS Signal caught (' , name, ')'. |
|
5384 |
title := (title , '\[in ST-process: ' , Processor activeProcess nameOrId ,']') withCRs. |
|
5385 |
||
5386 |
"/ if caught while in the scheduler or event dispatcher, |
|
5387 |
"/ a modal dialog is not possible ... |
|
5388 |
"/ (therefore, abort & return does not makes sense) |
|
5389 |
||
5390 |
Processor activeProcess isSystemProcess ifFalse:[ |
|
5391 |
titles := #('Abort') , titles. |
|
5392 |
actions := #(abort), actions. |
|
5393 |
||
5394 |
badContext canReturn ifTrue:[ |
|
5395 |
titles := #('Return') , titles. |
|
5396 |
actions := #(return), actions. |
|
5397 |
]. |
|
5398 |
]. |
|
5399 |
||
5400 |
fatal ifFalse:[ |
|
5401 |
titles := titles, #('Ignore'). |
|
5402 |
actions := actions , #(ignore). |
|
5403 |
]. |
|
5404 |
action := Dialog choose:title |
|
5405 |
labels:titles |
|
5406 |
values:actions |
|
5407 |
default:(fatal ifTrue:[nil] ifFalse:[#ignore]). |
|
5408 |
||
5409 |
"Dialog may fail (if system process), default action is debug" |
|
5410 |
action isEmptyOrNil ifTrue:[action := #debug]. |
|
5411 |
] ifFalse:[ |
|
5412 |
action := #debug. |
|
5413 |
]. |
|
5414 |
||
5415 |
action == #save ifTrue:[ |
|
5416 |
ObjectMemory writeCrashImage |
|
5417 |
]. |
|
5418 |
action == #gdb ifTrue:[ |
|
5419 |
|pid| |
|
5420 |
||
5421 |
pid := OperatingSystem getProcessId. |
|
5422 |
OperatingSystem openTerminalWithCommand:('gdb -p %1' bindWith:pid) inBackground:true. |
|
5423 |
MiniDebugger enter. "/ to stop, so gdb can show where we are |
|
5424 |
AbortOperationRequest raise. |
|
5425 |
]. |
|
5426 |
action == #core ifTrue:[ |
|
5427 |
Smalltalk fatalAbort |
|
5428 |
]. |
|
5429 |
action == #exit ifTrue:[ |
|
5430 |
Smalltalk exit:10. |
|
5431 |
]. |
|
5432 |
action == #return ifTrue:[ |
|
5433 |
badContext return |
|
5434 |
]. |
|
5435 |
action == #abort ifTrue:[ |
|
5436 |
AbortOperationRequest raise. |
|
5437 |
]. |
|
5438 |
||
5439 |
action == #debug ifTrue:[ |
|
5440 |
Debugger isNil ifTrue:[ |
|
5441 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
5442 |
]. |
|
5443 |
Debugger enter:here withMessage:('OS-Signal ', name) mayProceed:true. |
|
5444 |
]. |
|
5445 |
"action == #ignore" |
|
13261 | 5446 |
]. |
5447 |
||
13710 | 5448 |
"Modified: / 15-09-2011 / 16:38:14 / cg" |
5755 | 5449 |
! |
5450 |
||
5451 |
spyInterrupt |
|
5452 |
"{ Pragma: +optSpace }" |
|
5453 |
||
5454 |
"spy interrupt and no handler - enter debugger" |
|
5455 |
||
5456 |
self error:'spy Interrupt - but no handler' mayProceed:true |
|
5457 |
! |
|
5458 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5459 |
startMiniDebuggerOrExit:text |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5460 |
"some critical condition happened. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5461 |
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
|
5462 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5463 |
MiniDebugger isNil ifTrue:[ |
19846 | 5464 |
"a system without debugging facilities (i.e. a standalone system) |
5465 |
output a message and exit." |
|
5466 |
('Object [error]: exit due to ', text, ' - and no debugger.') errorPrintCR. |
|
5467 |
OperatingSystem exit:99. |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5468 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5469 |
MiniDebugger enterWithMessage:text mayProceed:true. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5470 |
! |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5471 |
|
5755 | 5472 |
timerInterrupt |
5473 |
"{ Pragma: +optSpace }" |
|
5474 |
||
5475 |
"timer interrupt and no handler - enter debugger" |
|
5476 |
||
5477 |
self error:'timer Interrupt - but no handler' mayProceed:true |
|
5478 |
! |
|
5479 |
||
5480 |
userInterrupt |
|
5481 |
"{ Pragma: +optSpace }" |
|
5482 |
||
5483 |
"user (^c) interrupt. |
|
5484 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
5485 |
controlling tty (i.e. in the xterm)." |
|
5486 |
||
6466 | 5487 |
UserInterruptSignal raiseRequest |
5755 | 5488 |
! |
5489 |
||
5490 |
userInterruptIn:aContext |
|
5491 |
"{ Pragma: +optSpace }" |
|
5492 |
||
5493 |
"user (^c) interrupt - enter debugger, but show aContext |
|
10460 | 5494 |
as top-context. |
5495 |
This is used to hide any intermediate scheduler contexts, |
|
5755 | 5496 |
in case of an interrupted process. Typically, this is sent by |
5497 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
5498 |
processed." |
|
5499 |
||
5500 |
<context: #return> |
|
5501 |
||
5502 |
UserInterruptSignal raiseRequestWith:nil errorString:nil in:aContext |
|
5503 |
||
5504 |
"Created: / 18.10.1996 / 20:46:04 / cg" |
|
5505 |
"Modified: / 20.10.1996 / 13:06:38 / cg" |
|
5506 |
"Modified: / 26.7.1999 / 10:58:49 / stefan" |
|
5507 |
! ! |
|
5508 |
||
5509 |
!Object methodsFor:'message sending'! |
|
5510 |
||
5511 |
perform:aSelector |
|
5512 |
"send the message aSelector to the receiver" |
|
5513 |
||
11335 | 5514 |
<resource: #skipInDebuggersWalkBack> |
5515 |
||
5755 | 5516 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5517 |
#ifdef __SCHTEAM__ |
18238 | 5518 |
return context.PERFORM(self, aSelector); |
18231 | 5519 |
#else |
5755 | 5520 |
REGISTER OBJ sel = aSelector; |
16588
eb24b473a3ba
Fix for bug in Object>>perform(with:(with:)) - care for nil or SmallInteger selectors.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16583
diff
changeset
|
5521 |
int hash0; |
5755 | 5522 |
|
5523 |
if (InterruptPending == nil) { |
|
19846 | 5524 |
struct inlineCache *pIlc; |
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5525 |
|
18231 | 5526 |
# define nways 2 |
5527 |
# define nilcs 131 |
|
5528 |
||
5529 |
# define SEL_AND_ILC_INIT_1(l) { { nil, nil } , { __ILCPERF0(l) , __ILCPERF0(l) } , 0 } |
|
5530 |
# define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5531 |
# define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5532 |
# define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5533 |
# define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5534 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5535 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5536 |
# define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5537 |
# define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5538 |
# define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5539 |
||
5540 |
# define SEL_AND_ILC_INIT_131(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_1(l) |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5541 |
|
19846 | 5542 |
static struct { OBJ sel[nways]; struct inlineCache ilc[nways]; int flip; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_131(@line) }; |
13416 | 5543 |
|
18231 | 5544 |
# undef SEL_AND_ILC_INIT_1 |
5545 |
# undef SEL_AND_ILC_INIT_2 |
|
5546 |
# undef SEL_AND_ILC_INIT_4 |
|
5547 |
# undef SEL_AND_ILC_INIT_8 |
|
5548 |
# undef SEL_AND_ILC_INIT_16 |
|
5549 |
# undef SEL_AND_ILC_INIT_32 |
|
5550 |
# undef SEL_AND_ILC_INIT_64 |
|
5551 |
# undef SEL_AND_ILC_INIT_128 |
|
5552 |
# undef SEL_AND_ILC_INIT_256 |
|
5553 |
||
5554 |
# undef SEL_AND_ILC_INIT_131 |
|
5555 |
# undef SEL_AND_ILC_INIT_257 |
|
5556 |
||
5557 |
# define TRY(n) \ |
|
19846 | 5558 |
if (sel == sel_and_ilc[hash0].sel[n]) { \ |
5559 |
pIlc = &sel_and_ilc[hash0].ilc[n]; \ |
|
5560 |
goto perform0_send_and_return; \ |
|
5561 |
} |
|
5562 |
||
5563 |
if (__isNonNilObject(sel)) { |
|
5564 |
hash0 = __MAKE_HASH__(__GET_HASH(sel)) % nilcs; |
|
5565 |
} else { |
|
5566 |
/* sel is either nil or smallint, use its value as hash */ |
|
5567 |
hash0 = (INT)sel % nilcs; |
|
5568 |
} |
|
5569 |
||
5570 |
TRY(0); |
|
5571 |
TRY(1); |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5572 |
|
18231 | 5573 |
# undef TRY |
19846 | 5574 |
/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/ |
5575 |
||
5576 |
pIlc = &sel_and_ilc[hash0].ilc[sel_and_ilc[hash0].flip]; |
|
5577 |
sel_and_ilc[hash0].sel[sel_and_ilc[hash0].flip] = sel; |
|
5578 |
sel_and_ilc[hash0].flip = (sel_and_ilc[hash0].flip + 1) % nways; |
|
5579 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5580 |
if (pIlc->ilc_poly) { |
|
5581 |
__flushPolyCache(pIlc->ilc_poly); |
|
5582 |
pIlc->ilc_poly = 0; |
|
5583 |
} |
|
13416 | 5584 |
perform0_send_and_return: |
19846 | 5585 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
5755 | 5586 |
} else { |
19846 | 5587 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
5588 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5755 | 5589 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5590 |
#endif /* not __SCHTEAM__ */ |
5755 | 5591 |
%}. |
5592 |
^ self perform:aSelector withArguments:#() |
|
5593 |
! |
|
5594 |
||
5595 |
perform:aSelector inClass:aClass withArguments:argArray |
|
10460 | 5596 |
"send the message aSelector with all args taken from argArray |
5755 | 5597 |
to the receiver as a super-send message. |
5598 |
This is actually more flexible than the normal super-send, since it allows |
|
5599 |
to execute a method in ANY superclass of the receiver (not just the |
|
5600 |
immediate superclass). |
|
10460 | 5601 |
Thus, it is (theoretically) possible to do |
19846 | 5602 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
5755 | 5603 |
and evaluate Magnitudes compare method even if there was one in Number. |
5604 |
This method is used by the interpreter to evaluate super sends |
|
5605 |
and could be used for very special behavior (language extension ?). |
|
5606 |
||
5607 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
5608 |
||
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5609 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 myClass| |
5755 | 5610 |
|
5611 |
" |
|
5612 |
check, if aClass is really a superclass of the receiver |
|
5613 |
" |
|
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5614 |
myClass := self class. |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5615 |
(myClass == aClass or:[myClass isSubclassOf:aClass]) ifFalse:[ |
19846 | 5616 |
self error:'lookup-class argument is not a superclass of the receiver'. |
5617 |
^ nil |
|
5755 | 5618 |
]. |
5619 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5620 |
#ifdef __SCHTEAM__ |
18231 | 5621 |
#else |
5755 | 5622 |
REGISTER OBJ *argP; |
5623 |
int nargs, i; |
|
5624 |
||
8934 | 5625 |
if (__isArrayLike(argArray)) { |
19846 | 5626 |
nargs = __arraySize(argArray); |
5627 |
argP = __arrayVal(argArray); |
|
5755 | 5628 |
} else { |
19846 | 5629 |
if (__isNonNilObject(argArray)) { |
5630 |
static struct inlineCache ilcSize = __ILC0(@line+1); |
|
5631 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5632 |
if (!__isSmallInteger(numberOfArgs)) |
|
5633 |
goto bad; |
|
5634 |
nargs = __intVal(numberOfArgs); |
|
5635 |
argP = (OBJ *)(&a1); |
|
5636 |
for (i=1; i <= nargs; i++) { |
|
5637 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
5638 |
} |
|
5639 |
argP = (OBJ *)(&a1); |
|
5640 |
} else { |
|
5641 |
nargs = 0; |
|
5642 |
} |
|
5755 | 5643 |
} |
5644 |
switch (nargs) { |
|
19846 | 5645 |
case 0: |
5646 |
{ |
|
5647 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5648 |
RETURN ( _SEND0(self, aSelector, aClass, &ilc0)); |
|
5649 |
} |
|
5650 |
||
5651 |
case 1: |
|
5652 |
{ |
|
5653 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5654 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, argP[0])); |
|
5655 |
} |
|
5656 |
||
5657 |
case 2: |
|
5658 |
{ |
|
5659 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5660 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, argP[0], argP[1])); |
|
5661 |
} |
|
5662 |
||
5663 |
case 3: |
|
5664 |
{ |
|
5665 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5666 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, |
|
5667 |
argP[0], argP[1], argP[2])); |
|
5668 |
} |
|
5669 |
||
5670 |
case 4: |
|
5671 |
{ |
|
5672 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
5673 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, |
|
5674 |
argP[0], argP[1], argP[2], argP[3])); |
|
5675 |
} |
|
5676 |
||
5677 |
case 5: |
|
5678 |
{ |
|
5679 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
5680 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
5681 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5682 |
} |
|
5683 |
||
5684 |
case 6: |
|
5685 |
{ |
|
5686 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
5687 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
5688 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5])); |
|
5689 |
} |
|
5690 |
||
5691 |
case 7: |
|
5692 |
{ |
|
5693 |
static struct inlineCache ilc7 = __DUMMYILCSELF7(@line+1); |
|
5694 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
5695 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5696 |
argP[6])); |
|
5697 |
} |
|
5698 |
||
5699 |
case 8: |
|
5700 |
{ |
|
5701 |
static struct inlineCache ilc8 = __DUMMYILCSELF8(@line+1); |
|
5702 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
5703 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5704 |
argP[6], argP[7])); |
|
5705 |
} |
|
5706 |
||
5707 |
case 9: |
|
5708 |
{ |
|
5709 |
static struct inlineCache ilc9 = __DUMMYILCSELF9(@line+1); |
|
5710 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
5711 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5712 |
argP[6], argP[7], argP[8])); |
|
5713 |
} |
|
5714 |
||
5715 |
case 10: |
|
5716 |
{ |
|
5717 |
static struct inlineCache ilc10 = __DUMMYILCSELF10(@line+1); |
|
5718 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
5719 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5720 |
argP[6], argP[7], argP[8], argP[9])); |
|
5721 |
} |
|
5722 |
||
5723 |
case 11: |
|
5724 |
{ |
|
5725 |
static struct inlineCache ilc11 = __DUMMYILCSELF11(@line+1); |
|
5726 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
5727 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5728 |
argP[6], argP[7], argP[8], argP[9], argP[10])); |
|
5729 |
} |
|
5730 |
||
5731 |
case 12: |
|
5732 |
{ |
|
5733 |
static struct inlineCache ilc12 = __DUMMYILCSELF12(@line+1); |
|
5734 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
5735 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5736 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5737 |
argP[11])); |
|
5738 |
} |
|
5739 |
||
5740 |
case 13: |
|
5741 |
{ |
|
5742 |
static struct inlineCache ilc13 = __DUMMYILCSELF13(@line+1); |
|
5743 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
5744 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5745 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5746 |
argP[11], argP[12])); |
|
5747 |
} |
|
5748 |
||
5749 |
case 14: |
|
5750 |
{ |
|
5751 |
static struct inlineCache ilc14 = __DUMMYILCSELF14(@line+1); |
|
5752 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
5753 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5754 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5755 |
argP[11], argP[12], argP[13])); |
|
5756 |
} |
|
5757 |
||
5758 |
case 15: |
|
5759 |
{ |
|
5760 |
static struct inlineCache ilc15 = __DUMMYILCSELF15(@line+1); |
|
5761 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
5762 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5763 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5764 |
argP[11], argP[12], argP[13], argP[14])); |
|
5765 |
} |
|
5755 | 5766 |
|
18231 | 5767 |
# ifdef _SEND16 |
19846 | 5768 |
case 16: |
5769 |
{ |
|
5770 |
static struct inlineCache ilc16 = __DUMMYILCSELF16(@line+1); |
|
5771 |
RETURN ( _SEND16(self, aSelector, aClass, &ilc15, |
|
5772 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5773 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5774 |
argP[11], argP[12], argP[13], argP[14], argP[15])); |
|
5775 |
} |
|
18231 | 5776 |
# endif |
5777 |
# ifdef _SEND17 |
|
19846 | 5778 |
case 17: |
5779 |
{ |
|
5780 |
static struct inlineCache ilc17 = __DUMMYILCSELF17(@line+1); |
|
5781 |
RETURN ( _SEND17(self, aSelector, aClass, &ilc15, |
|
5782 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5783 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5784 |
argP[11], argP[12], argP[13], argP[14], argP[15], argP[16])); |
|
5785 |
} |
|
18231 | 5786 |
# endif |
5755 | 5787 |
|
5788 |
||
5789 |
} |
|
5790 |
bad:; |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5791 |
#endif /* not __SCHTEAM__ */ |
5755 | 5792 |
%}. |
5793 |
"/ arrive here, if bad number of arguments (too many) |
|
5794 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5795 |
||
5796 |
^ self primitiveFailed |
|
5797 |
! |
|
5798 |
||
5799 |
perform:aSelector with:arg |
|
5800 |
"send the one-arg-message aSelector to the receiver" |
|
5801 |
||
5802 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5803 |
#ifdef __SCHTEAM__ |
18238 | 5804 |
return context.PERFORM_WITH(self, aSelector, arg); |
18231 | 5805 |
#else |
5755 | 5806 |
REGISTER OBJ sel = aSelector; |
16588
eb24b473a3ba
Fix for bug in Object>>perform(with:(with:)) - care for nil or SmallInteger selectors.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16583
diff
changeset
|
5807 |
int hash0; |
5755 | 5808 |
|
5809 |
if (InterruptPending == nil) { |
|
19846 | 5810 |
struct inlineCache *pIlc; |
18231 | 5811 |
# undef nways |
5812 |
# define nways 2 |
|
5813 |
# undef nilcs |
|
5814 |
# define nilcs 131 |
|
5815 |
||
5816 |
# define SEL_AND_ILC_INIT_1(l) { { nil, nil } , { __ILCPERF1(l) , __ILCPERF1(l) } , 0 } |
|
5817 |
# define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5818 |
# define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5819 |
# define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5820 |
# define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5821 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5822 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5823 |
# define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5824 |
# define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5825 |
# define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5826 |
||
5827 |
# define SEL_AND_ILC_INIT_131(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_1(l) |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5828 |
|
19846 | 5829 |
static struct { OBJ sel[nways]; struct inlineCache ilc[nways]; int flip; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_131(@line) }; |
13416 | 5830 |
|
18231 | 5831 |
# undef SEL_AND_ILC_INIT_1 |
5832 |
# undef SEL_AND_ILC_INIT_2 |
|
5833 |
# undef SEL_AND_ILC_INIT_4 |
|
5834 |
# undef SEL_AND_ILC_INIT_8 |
|
5835 |
# undef SEL_AND_ILC_INIT_16 |
|
5836 |
# undef SEL_AND_ILC_INIT_32 |
|
5837 |
# undef SEL_AND_ILC_INIT_64 |
|
5838 |
# undef SEL_AND_ILC_INIT_128 |
|
5839 |
# undef SEL_AND_ILC_INIT_256 |
|
5840 |
||
5841 |
# undef SEL_AND_ILC_INIT_131 |
|
5842 |
# undef SEL_AND_ILC_INIT_257 |
|
5843 |
||
5844 |
# define TRY(n) \ |
|
19846 | 5845 |
if (sel == sel_and_ilc[hash0].sel[n]) { \ |
5846 |
pIlc = &sel_and_ilc[hash0].ilc[n]; \ |
|
5847 |
goto perform1_send_and_return; \ |
|
5848 |
} |
|
5849 |
||
5850 |
if (__isNonNilObject(sel)) { |
|
5851 |
hash0 = __MAKE_HASH__(__GET_HASH(sel)) % nilcs; |
|
5852 |
} else { |
|
5853 |
/* sel is either nil or smallint, use its value as hash */ |
|
5854 |
hash0 = (INT)sel % nilcs; |
|
5855 |
} |
|
5856 |
||
5857 |
TRY(0); |
|
5858 |
TRY(1); |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5859 |
|
18231 | 5860 |
# undef TRY |
19846 | 5861 |
/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/ |
5862 |
||
5863 |
pIlc = &sel_and_ilc[hash0].ilc[sel_and_ilc[hash0].flip]; |
|
5864 |
sel_and_ilc[hash0].sel[sel_and_ilc[hash0].flip] = sel; |
|
5865 |
sel_and_ilc[hash0].flip = (sel_and_ilc[hash0].flip + 1) % nways; |
|
5866 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5867 |
if (pIlc->ilc_poly) { |
|
5868 |
__flushPolyCache(pIlc->ilc_poly); |
|
5869 |
pIlc->ilc_poly = 0; |
|
5870 |
} |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5871 |
|
13416 | 5872 |
perform1_send_and_return: |
19846 | 5873 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
5755 | 5874 |
} else { |
19846 | 5875 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
5876 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
5755 | 5877 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5878 |
#endif /* not __SCHTEAM__ */ |
5755 | 5879 |
%}. |
5880 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5881 |
! |
|
5882 |
||
5883 |
perform:aSelector with:arg1 with:arg2 |
|
5884 |
"send the two-arg-message aSelector to the receiver" |
|
5885 |
||
5886 |
%{ |
|
18263 | 5887 |
#ifdef __SCHTEAM__ |
5888 |
return context.PERFORM_WITH2(self, aSelector, arg1, arg2); |
|
5889 |
#else |
|
13416 | 5890 |
REGISTER OBJ sel = aSelector; |
5755 | 5891 |
struct inlineCache *pIlc; |
16588
eb24b473a3ba
Fix for bug in Object>>perform(with:(with:)) - care for nil or SmallInteger selectors.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16583
diff
changeset
|
5892 |
int hash0; |
5755 | 5893 |
|
5894 |
if (InterruptPending == nil) { |
|
18231 | 5895 |
# undef nways |
5896 |
# define nways 2 |
|
5897 |
# undef nilcs |
|
5898 |
# define nilcs 131 |
|
5899 |
||
5900 |
# define SEL_AND_ILC_INIT_1(l) { { nil, nil } , { __ILCPERF2(l) , __ILCPERF2(l) } , 0 } |
|
5901 |
# define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5902 |
# define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5903 |
# define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5904 |
# define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5905 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5906 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5907 |
# define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5908 |
# define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5909 |
# define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5910 |
||
5911 |
# define SEL_AND_ILC_INIT_131(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_1(l) |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5912 |
|
19846 | 5913 |
static struct { OBJ sel[nways]; struct inlineCache ilc[nways]; int flip; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_131(@line) }; |
13416 | 5914 |
|
18231 | 5915 |
# undef SEL_AND_ILC_INIT_1 |
5916 |
# undef SEL_AND_ILC_INIT_2 |
|
5917 |
# undef SEL_AND_ILC_INIT_4 |
|
5918 |
# undef SEL_AND_ILC_INIT_8 |
|
5919 |
# undef SEL_AND_ILC_INIT_16 |
|
5920 |
# undef SEL_AND_ILC_INIT_32 |
|
5921 |
# undef SEL_AND_ILC_INIT_64 |
|
5922 |
# undef SEL_AND_ILC_INIT_128 |
|
5923 |
# undef SEL_AND_ILC_INIT_256 |
|
5924 |
||
5925 |
# undef SEL_AND_ILC_INIT_131 |
|
5926 |
# undef SEL_AND_ILC_INIT_257 |
|
5927 |
||
5928 |
# define TRY(n) \ |
|
19846 | 5929 |
if (sel == sel_and_ilc[hash0].sel[n]) { \ |
5930 |
pIlc = &sel_and_ilc[hash0].ilc[n]; \ |
|
5931 |
goto perform2_send_and_return; \ |
|
5932 |
} |
|
5933 |
||
5934 |
if (__isNonNilObject(sel)) { |
|
5935 |
hash0 = __MAKE_HASH__(__GET_HASH(sel)) % nilcs; |
|
5936 |
} else { |
|
5937 |
/* sel is either nil or smallint, use its value as hash */ |
|
5938 |
hash0 = (INT)sel % nilcs; |
|
5939 |
} |
|
5940 |
||
5941 |
TRY(0); |
|
5942 |
TRY(1); |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5943 |
|
18231 | 5944 |
# undef TRY |
19846 | 5945 |
/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/ |
5946 |
||
5947 |
pIlc = &sel_and_ilc[hash0].ilc[sel_and_ilc[hash0].flip]; |
|
5948 |
sel_and_ilc[hash0].sel[sel_and_ilc[hash0].flip] = sel; |
|
5949 |
sel_and_ilc[hash0].flip = (sel_and_ilc[hash0].flip + 1) % nways; |
|
5950 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5951 |
if (pIlc->ilc_poly) { |
|
5952 |
__flushPolyCache(pIlc->ilc_poly); |
|
5953 |
pIlc->ilc_poly = 0; |
|
5954 |
} |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5955 |
|
13416 | 5956 |
perform2_send_and_return: |
19846 | 5957 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
5755 | 5958 |
} else { |
19846 | 5959 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
5960 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, arg1, arg2)); |
|
5755 | 5961 |
} |
18263 | 5962 |
#endif /* not SCHTEAM */ |
5755 | 5963 |
%}. |
5964 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2) |
|
5965 |
! |
|
5966 |
||
5967 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
|
5968 |
"send the three-arg-message aSelector to the receiver" |
|
5969 |
||
5970 |
%{ |
|
18263 | 5971 |
#ifdef __SCHTEAM__ |
5972 |
return context.PERFORM_WITH3(self, aSelector, arg1, arg2, arg3); |
|
5973 |
#else |
|
5755 | 5974 |
struct inlineCache *pIlc; |
5975 |
static struct inlineCache ilc_0 = __ILCPERF3(@line); |
|
5976 |
static struct inlineCache ilc_1 = __ILCPERF3(@line); |
|
5977 |
static OBJ last_0 = nil; |
|
5978 |
static OBJ last_1 = nil; |
|
18185 | 5979 |
static int flip = 0; |
5755 | 5980 |
|
5981 |
if (InterruptPending == nil) { |
|
19846 | 5982 |
if (aSelector != last_0) { |
5983 |
if (aSelector != last_1) { |
|
5984 |
if (flip) { |
|
5985 |
pIlc = &ilc_0; |
|
5986 |
flip = 0; |
|
5987 |
last_0 = aSelector; |
|
5988 |
} else { |
|
5989 |
pIlc = &ilc_1; |
|
5990 |
flip = 1; |
|
5991 |
last_1 = aSelector; |
|
5992 |
} |
|
5993 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5994 |
if (pIlc->ilc_poly) { |
|
5995 |
__flushPolyCache(pIlc->ilc_poly); |
|
5996 |
pIlc->ilc_poly = 0; |
|
5997 |
} |
|
5998 |
} else { |
|
5999 |
pIlc = &ilc_1; |
|
6000 |
} |
|
6001 |
} else { |
|
6002 |
pIlc = &ilc_0; |
|
6003 |
} |
|
6004 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
|
5755 | 6005 |
} else { |
19846 | 6006 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
6007 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, arg1, arg2, arg3)); |
|
5755 | 6008 |
} |
18263 | 6009 |
#endif /* not SCHTEAM */ |
5755 | 6010 |
%}. |
6011 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3) |
|
6012 |
||
6013 |
! |
|
6014 |
||
6015 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
6016 |
"send the four-arg-message aSelector to the receiver" |
|
6017 |
||
6018 |
%{ |
|
6019 |
struct inlineCache *pIlc; |
|
6020 |
static struct inlineCache ilc_0 = __ILCPERF4(@line); |
|
6021 |
static struct inlineCache ilc_1 = __ILCPERF4(@line); |
|
6022 |
static OBJ last_0 = nil; |
|
6023 |
static OBJ last_1 = nil; |
|
18185 | 6024 |
static int flip = 0; |
5755 | 6025 |
|
6026 |
if (InterruptPending == nil) { |
|
19846 | 6027 |
if (aSelector != last_0) { |
6028 |
if (aSelector != last_1) { |
|
6029 |
if (flip) { |
|
6030 |
pIlc = &ilc_0; |
|
6031 |
flip = 0; |
|
6032 |
last_0 = aSelector; |
|
6033 |
} else { |
|
6034 |
pIlc = &ilc_1; |
|
6035 |
flip = 1; |
|
6036 |
last_1 = aSelector; |
|
6037 |
} |
|
6038 |
pIlc->ilc_func = __SEND4ADDR__; |
|
6039 |
if (pIlc->ilc_poly) { |
|
6040 |
__flushPolyCache(pIlc->ilc_poly); |
|
6041 |
pIlc->ilc_poly = 0; |
|
6042 |
} |
|
6043 |
} else { |
|
6044 |
pIlc = &ilc_1; |
|
6045 |
} |
|
6046 |
} else { |
|
6047 |
pIlc = &ilc_0; |
|
6048 |
} |
|
6049 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
6050 |
arg1, arg2, arg3, arg4) ); |
|
5755 | 6051 |
} else { |
19846 | 6052 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
6053 |
RETURN (_SEND4(self, aSelector, nil, &ilc4, |
|
6054 |
arg1, arg2, arg3, arg4)); |
|
5755 | 6055 |
} |
6056 |
%}. |
|
6057 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
6058 |
||
6059 |
! |
|
6060 |
||
6061 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
6062 |
"send the five-arg-message aSelector to the receiver" |
|
6063 |
||
6064 |
%{ |
|
6065 |
struct inlineCache *pIlc; |
|
6066 |
static struct inlineCache ilc_0 = __ILCPERF5(@line); |
|
6067 |
static struct inlineCache ilc_1 = __ILCPERF5(@line); |
|
6068 |
static OBJ last_0 = nil; |
|
6069 |
static OBJ last_1 = nil; |
|
18185 | 6070 |
static int flip = 0; |
5755 | 6071 |
|
6072 |
if (InterruptPending == nil) { |
|
19846 | 6073 |
if (aSelector != last_0) { |
6074 |
if (aSelector != last_1) { |
|
6075 |
if (flip) { |
|
6076 |
pIlc = &ilc_0; |
|
6077 |
flip = 0; |
|
6078 |
last_0 = aSelector; |
|
6079 |
} else { |
|
6080 |
pIlc = &ilc_1; |
|
6081 |
flip = 1; |
|
6082 |
last_1 = aSelector; |
|
6083 |
} |
|
6084 |
pIlc->ilc_func = __SEND5ADDR__; |
|
6085 |
if (pIlc->ilc_poly) { |
|
6086 |
__flushPolyCache(pIlc->ilc_poly); |
|
6087 |
pIlc->ilc_poly = 0; |
|
6088 |
} |
|
6089 |
} else { |
|
6090 |
pIlc = &ilc_1; |
|
6091 |
} |
|
6092 |
} else { |
|
6093 |
pIlc = &ilc_0; |
|
6094 |
} |
|
6095 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
6096 |
arg1, arg2, arg3, arg4, arg5) ); |
|
5755 | 6097 |
} else { |
19846 | 6098 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
6099 |
RETURN (_SEND5(self, aSelector, nil, &ilc5, |
|
6100 |
arg1, arg2, arg3, arg4, arg5)); |
|
5755 | 6101 |
} |
6102 |
%}. |
|
6103 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
19846 | 6104 |
with:arg5) |
5755 | 6105 |
|
6106 |
! |
|
6107 |
||
6108 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
|
6109 |
"send the six-arg-message aSelector to the receiver" |
|
6110 |
||
6111 |
%{ |
|
6112 |
struct inlineCache *pIlc; |
|
6113 |
static struct inlineCache ilc_0 = __ILCPERF6(@line); |
|
6114 |
static struct inlineCache ilc_1 = __ILCPERF6(@line); |
|
6115 |
static OBJ last_0 = nil; |
|
6116 |
static OBJ last_1 = nil; |
|
18185 | 6117 |
static int flip = 0; |
5755 | 6118 |
|
6119 |
if (InterruptPending == nil) { |
|
19846 | 6120 |
if (aSelector != last_0) { |
6121 |
if (aSelector != last_1) { |
|
6122 |
if (flip) { |
|
6123 |
pIlc = &ilc_0; |
|
6124 |
flip = 0; |
|
6125 |
last_0 = aSelector; |
|
6126 |
} else { |
|
6127 |
pIlc = &ilc_1; |
|
6128 |
flip = 1; |
|
6129 |
last_1 = aSelector; |
|
6130 |
} |
|
6131 |
pIlc->ilc_func = __SEND6ADDR__; |
|
6132 |
if (pIlc->ilc_poly) { |
|
6133 |
__flushPolyCache(pIlc->ilc_poly); |
|
6134 |
pIlc->ilc_poly = 0; |
|
6135 |
} |
|
6136 |
} else { |
|
6137 |
pIlc = &ilc_1; |
|
6138 |
} |
|
6139 |
} else { |
|
6140 |
pIlc = &ilc_0; |
|
6141 |
} |
|
6142 |
||
6143 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
6144 |
arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
5755 | 6145 |
} else { |
19846 | 6146 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
6147 |
RETURN (_SEND6(self, aSelector, nil, &ilc6, |
|
6148 |
arg1, arg2, arg3, arg4, arg5, arg6)); |
|
5755 | 6149 |
} |
6150 |
%}. |
|
6151 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
19846 | 6152 |
with:arg5 with:arg6) |
5755 | 6153 |
|
6154 |
! |
|
6155 |
||
6156 |
perform:aSelector withArguments:argArray |
|
10460 | 6157 |
"send the message aSelector with all args taken from argArray |
5755 | 6158 |
to the receiver." |
6159 |
||
6160 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
6161 |
||
6162 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
6163 |
#ifdef __SCHTEAM__ |
18238 | 6164 |
return context.PERFORM_WITH_ARGUMENTS(self, aSelector, argArray); |
6165 |
#else |
|
5755 | 6166 |
REGISTER OBJ *argP; |
6167 |
int nargs; |
|
6168 |
OBJ l; |
|
6169 |
||
8934 | 6170 |
if (__isArrayLike(argArray)) { |
19846 | 6171 |
nargs = __arraySize(argArray); |
6172 |
argP = __arrayVal(argArray); |
|
5755 | 6173 |
} else { |
19846 | 6174 |
if (__isNonNilObject(argArray)) { |
6175 |
static struct inlineCache ilcSize = __ILC0(@line); |
|
6176 |
int i; |
|
6177 |
||
6178 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
6179 |
if (!__isSmallInteger(numberOfArgs)) |
|
6180 |
goto bad; |
|
6181 |
nargs = __intVal(numberOfArgs); |
|
6182 |
argP = (OBJ *)(&a1); |
|
6183 |
for (i=1; i <= nargs; i++) { |
|
6184 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
6185 |
} |
|
6186 |
argP = (OBJ *)(&a1); |
|
6187 |
} else { |
|
6188 |
nargs = 0; |
|
6189 |
} |
|
5755 | 6190 |
} |
6191 |
switch (nargs) { |
|
19846 | 6192 |
case 0: |
6193 |
if (InterruptPending == nil) { |
|
6194 |
static OBJ last0_0 = nil; static struct inlineCache ilc0_0 = __ILCPERF0(@line); |
|
6195 |
static OBJ last0_1 = nil; static struct inlineCache ilc0_1 = __ILCPERF0(@line); |
|
6196 |
static OBJ last0_2 = nil; static struct inlineCache ilc0_2 = __ILCPERF0(@line); |
|
6197 |
static OBJ last0_3 = nil; static struct inlineCache ilc0_3 = __ILCPERF0(@line); |
|
6198 |
static int flip0 = 0; |
|
6199 |
struct inlineCache *pIlc; |
|
6200 |
||
6201 |
if (aSelector == last0_0) { |
|
6202 |
pIlc = &ilc0_0; |
|
6203 |
} else if (aSelector == last0_1) { |
|
6204 |
pIlc = &ilc0_1; |
|
6205 |
} else if (aSelector == last0_2) { |
|
6206 |
pIlc = &ilc0_2; |
|
6207 |
} else if (aSelector == last0_3) { |
|
6208 |
pIlc = &ilc0_3; |
|
6209 |
} else { |
|
6210 |
if (flip0 == 0) { |
|
6211 |
pIlc = &ilc0_0; |
|
6212 |
flip0 = 1; |
|
6213 |
last0_0 = aSelector; |
|
6214 |
} else if (flip0 == 1) { |
|
6215 |
pIlc = &ilc0_1; |
|
6216 |
flip0 = 2; |
|
6217 |
last0_1 = aSelector; |
|
6218 |
} else if (flip0 == 2) { |
|
6219 |
pIlc = &ilc0_2; |
|
6220 |
flip0 = 3; |
|
6221 |
last0_2 = aSelector; |
|
6222 |
} else { |
|
6223 |
pIlc = &ilc0_3; |
|
6224 |
flip0 = 0; |
|
6225 |
last0_3 = aSelector; |
|
6226 |
} |
|
6227 |
||
6228 |
pIlc->ilc_func = __SEND0ADDR__; |
|
6229 |
if (pIlc->ilc_poly) { |
|
6230 |
__flushPolyCache(pIlc->ilc_poly); |
|
6231 |
pIlc->ilc_poly = 0; |
|
6232 |
} |
|
6233 |
} |
|
6234 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc)); |
|
6235 |
} else { |
|
6236 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
6237 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
6238 |
} |
|
6239 |
||
6240 |
case 1: |
|
6241 |
if (InterruptPending == nil) { |
|
6242 |
static OBJ last1_0 = nil; static struct inlineCache ilc1_0 = __ILCPERF1(@line); |
|
6243 |
static OBJ last1_1 = nil; static struct inlineCache ilc1_1 = __ILCPERF1(@line); |
|
6244 |
static OBJ last1_2 = nil; static struct inlineCache ilc1_2 = __ILCPERF1(@line); |
|
6245 |
static OBJ last1_3 = nil; static struct inlineCache ilc1_3 = __ILCPERF1(@line); |
|
6246 |
static int flip1 = 0; |
|
6247 |
struct inlineCache *pIlc; |
|
6248 |
||
6249 |
if (aSelector == last1_0) { |
|
6250 |
pIlc = &ilc1_0; |
|
6251 |
} else if (aSelector == last1_1) { |
|
6252 |
pIlc = &ilc1_1; |
|
6253 |
} else if (aSelector == last1_2) { |
|
6254 |
pIlc = &ilc1_2; |
|
6255 |
} else if (aSelector == last1_3) { |
|
6256 |
pIlc = &ilc1_3; |
|
6257 |
} else { |
|
6258 |
if (flip1 == 0) { |
|
6259 |
pIlc = &ilc1_0; |
|
6260 |
flip1 = 1; |
|
6261 |
last1_0 = aSelector; |
|
6262 |
} else if (flip1 == 1) { |
|
6263 |
pIlc = &ilc1_1; |
|
6264 |
flip1 = 2; |
|
6265 |
last1_1 = aSelector; |
|
6266 |
} else if (flip1 == 2) { |
|
6267 |
pIlc = &ilc1_2; |
|
6268 |
flip1 = 3; |
|
6269 |
last1_2 = aSelector; |
|
6270 |
} else { |
|
6271 |
pIlc = &ilc1_3; |
|
6272 |
flip1 = 0; |
|
6273 |
last1_3 = aSelector; |
|
6274 |
} |
|
6275 |
||
6276 |
pIlc->ilc_func = __SEND1ADDR__; |
|
6277 |
if (pIlc->ilc_poly) { |
|
6278 |
__flushPolyCache(pIlc->ilc_poly); |
|
6279 |
pIlc->ilc_poly = 0; |
|
6280 |
} |
|
6281 |
} |
|
6282 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0])); |
|
6283 |
} else { |
|
6284 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
6285 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, argP[0])); |
|
6286 |
} |
|
6287 |
||
6288 |
case 2: |
|
6289 |
if (InterruptPending == nil) { |
|
6290 |
static OBJ last2_0 = nil; static struct inlineCache ilc2_0 = __ILCPERF2(@line); |
|
6291 |
static OBJ last2_1 = nil; static struct inlineCache ilc2_1 = __ILCPERF2(@line); |
|
6292 |
static int flip2 = 0; |
|
6293 |
struct inlineCache *pIlc; |
|
6294 |
||
6295 |
if (aSelector == last2_0) { |
|
6296 |
pIlc = &ilc2_0; |
|
6297 |
} else if (aSelector == last2_1) { |
|
6298 |
pIlc = &ilc2_1; |
|
6299 |
} else { |
|
6300 |
if (flip2 == 0) { |
|
6301 |
pIlc = &ilc2_0; |
|
6302 |
flip2 = 1; |
|
6303 |
last2_0 = aSelector; |
|
6304 |
} else { |
|
6305 |
pIlc = &ilc2_1; |
|
6306 |
flip2 = 0; |
|
6307 |
last2_1 = aSelector; |
|
6308 |
} |
|
6309 |
||
6310 |
pIlc->ilc_func = __SEND2ADDR__; |
|
6311 |
if (pIlc->ilc_poly) { |
|
6312 |
__flushPolyCache(pIlc->ilc_poly); |
|
6313 |
pIlc->ilc_poly = 0; |
|
6314 |
} |
|
6315 |
} |
|
6316 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1])); |
|
6317 |
} else { |
|
6318 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
6319 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, argP[0], argP[1])); |
|
6320 |
} |
|
6321 |
||
6322 |
case 3: |
|
6323 |
if (InterruptPending == nil) { |
|
6324 |
static OBJ last3_0 = nil; static struct inlineCache ilc3_0 = __ILCPERF3(@line); |
|
6325 |
static OBJ last3_1 = nil; static struct inlineCache ilc3_1 = __ILCPERF3(@line); |
|
6326 |
static int flip3 = 0; |
|
6327 |
struct inlineCache *pIlc; |
|
6328 |
||
6329 |
if (aSelector == last3_0) { |
|
6330 |
pIlc = &ilc3_0; |
|
6331 |
} else if (aSelector == last3_1) { |
|
6332 |
pIlc = &ilc3_1; |
|
6333 |
} else { |
|
6334 |
if (flip3 == 0) { |
|
6335 |
pIlc = &ilc3_0; |
|
6336 |
flip3 = 1; |
|
6337 |
last3_0 = aSelector; |
|
6338 |
} else { |
|
6339 |
pIlc = &ilc3_1; |
|
6340 |
flip3 = 0; |
|
6341 |
last3_1 = aSelector; |
|
6342 |
} |
|
6343 |
||
6344 |
pIlc->ilc_func = __SEND3ADDR__; |
|
6345 |
if (pIlc->ilc_poly) { |
|
6346 |
__flushPolyCache(pIlc->ilc_poly); |
|
6347 |
pIlc->ilc_poly = 0; |
|
6348 |
} |
|
6349 |
} |
|
6350 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1], argP[2])); |
|
6351 |
} else { |
|
6352 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
6353 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, argP[0], argP[1], argP[2])); |
|
6354 |
} |
|
6355 |
||
6356 |
case 4: |
|
6357 |
{ |
|
6358 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(@line); |
|
6359 |
||
6360 |
if ((InterruptPending != nil) || (aSelector != last4)) { |
|
6361 |
ilc4.ilc_func = __SEND4ADDR__; |
|
6362 |
if (ilc4.ilc_poly) { |
|
6363 |
__flushPolyCache(ilc4.ilc_poly); |
|
6364 |
ilc4.ilc_poly = 0; |
|
6365 |
} |
|
6366 |
last4 = aSelector; |
|
6367 |
} |
|
6368 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
|
6369 |
argP[0], argP[1], argP[2], argP[3])); |
|
6370 |
} |
|
6371 |
||
6372 |
case 5: |
|
6373 |
{ |
|
6374 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(@line); |
|
6375 |
||
6376 |
if ((InterruptPending != nil) || (aSelector != last5)) { |
|
6377 |
ilc5.ilc_func = __SEND5ADDR__; |
|
6378 |
if (ilc5.ilc_poly) { |
|
6379 |
__flushPolyCache(ilc5.ilc_poly); |
|
6380 |
ilc5.ilc_poly = 0; |
|
6381 |
} |
|
6382 |
last5 = aSelector; |
|
6383 |
} |
|
6384 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
|
6385 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
6386 |
} |
|
6387 |
||
6388 |
case 6: |
|
6389 |
{ |
|
6390 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(@line); |
|
6391 |
||
6392 |
if ((InterruptPending != nil) || (aSelector != last6)) { |
|
6393 |
ilc6.ilc_func = __SEND6ADDR__; |
|
6394 |
if (ilc6.ilc_poly) { |
|
6395 |
__flushPolyCache(ilc6.ilc_poly); |
|
6396 |
ilc6.ilc_poly = 0; |
|
6397 |
} |
|
6398 |
last6 = aSelector; |
|
6399 |
} |
|
6400 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
|
6401 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6402 |
argP[5])); |
|
6403 |
} |
|
6404 |
||
6405 |
case 7: |
|
6406 |
{ |
|
6407 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(@line); |
|
6408 |
||
6409 |
if ((InterruptPending != nil) || (aSelector != last7)) { |
|
6410 |
ilc7.ilc_func = __SEND7ADDR__; |
|
6411 |
if (ilc7.ilc_poly) { |
|
6412 |
__flushPolyCache(ilc7.ilc_poly); |
|
6413 |
ilc7.ilc_poly = 0; |
|
6414 |
} |
|
6415 |
last7 = aSelector; |
|
6416 |
} |
|
6417 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
|
6418 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6419 |
argP[5], argP[6])); |
|
6420 |
} |
|
6421 |
||
6422 |
case 8: |
|
6423 |
{ |
|
6424 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(@line); |
|
6425 |
||
6426 |
if ((InterruptPending != nil) || (aSelector != last8)) { |
|
6427 |
ilc8.ilc_func = __SEND8ADDR__; |
|
6428 |
if (ilc8.ilc_poly) { |
|
6429 |
__flushPolyCache(ilc8.ilc_poly); |
|
6430 |
ilc8.ilc_poly = 0; |
|
6431 |
} |
|
6432 |
last8 = aSelector; |
|
6433 |
} |
|
6434 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
|
6435 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6436 |
argP[5], argP[6], argP[7])); |
|
6437 |
} |
|
6438 |
||
6439 |
case 9: |
|
6440 |
{ |
|
6441 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(@line); |
|
6442 |
||
6443 |
if ((InterruptPending != nil) || (aSelector != last9)) { |
|
6444 |
ilc9.ilc_func = __SEND9ADDR__; |
|
6445 |
if (ilc9.ilc_poly) { |
|
6446 |
__flushPolyCache(ilc9.ilc_poly); |
|
6447 |
ilc9.ilc_poly = 0; |
|
6448 |
} |
|
6449 |
last9 = aSelector; |
|
6450 |
} |
|
6451 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
|
6452 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6453 |
argP[5], argP[6], argP[7], argP[8])); |
|
6454 |
} |
|
6455 |
||
6456 |
case 10: |
|
6457 |
{ |
|
6458 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(@line); |
|
6459 |
||
6460 |
if ((InterruptPending != nil) || (aSelector != last10)) { |
|
6461 |
ilc10.ilc_func = __SEND10ADDR__; |
|
6462 |
if (ilc10.ilc_poly) { |
|
6463 |
__flushPolyCache(ilc10.ilc_poly); |
|
6464 |
ilc10.ilc_poly = 0; |
|
6465 |
} |
|
6466 |
last10 = aSelector; |
|
6467 |
} |
|
6468 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
|
6469 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6470 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
6471 |
} |
|
6472 |
||
6473 |
case 11: |
|
6474 |
{ |
|
6475 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(@line); |
|
6476 |
||
6477 |
if ((InterruptPending != nil) || (aSelector != last11)) { |
|
6478 |
ilc11.ilc_func = __SEND11ADDR__; |
|
6479 |
if (ilc11.ilc_poly) { |
|
6480 |
__flushPolyCache(ilc11.ilc_poly); |
|
6481 |
ilc11.ilc_poly = 0; |
|
6482 |
} |
|
6483 |
last11 = aSelector; |
|
6484 |
} |
|
6485 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
|
6486 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6487 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6488 |
argP[10])); |
|
6489 |
} |
|
6490 |
||
6491 |
case 12: |
|
6492 |
{ |
|
6493 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(@line); |
|
6494 |
||
6495 |
if ((InterruptPending != nil) || (aSelector != last12)) { |
|
6496 |
ilc12.ilc_func = __SEND12ADDR__; |
|
6497 |
if (ilc12.ilc_poly) { |
|
6498 |
__flushPolyCache(ilc12.ilc_poly); |
|
6499 |
ilc12.ilc_poly = 0; |
|
6500 |
} |
|
6501 |
last12 = aSelector; |
|
6502 |
} |
|
6503 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
|
6504 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6505 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6506 |
argP[10], argP[11])); |
|
6507 |
} |
|
6508 |
||
6509 |
case 13: |
|
6510 |
{ |
|
6511 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(@line); |
|
6512 |
||
6513 |
if ((InterruptPending != nil) || (aSelector != last13)) { |
|
6514 |
ilc13.ilc_func = __SEND13ADDR__; |
|
6515 |
if (ilc13.ilc_poly) { |
|
6516 |
__flushPolyCache(ilc13.ilc_poly); |
|
6517 |
ilc13.ilc_poly = 0; |
|
6518 |
} |
|
6519 |
last13 = aSelector; |
|
6520 |
} |
|
6521 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
|
6522 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6523 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6524 |
argP[10], argP[11], argP[12])); |
|
6525 |
} |
|
6526 |
||
6527 |
case 14: |
|
6528 |
{ |
|
6529 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(@line); |
|
6530 |
||
6531 |
if ((InterruptPending != nil) || (aSelector != last14)) { |
|
6532 |
ilc14.ilc_func = __SEND14ADDR__; |
|
6533 |
if (ilc14.ilc_poly) { |
|
6534 |
__flushPolyCache(ilc14.ilc_poly); |
|
6535 |
ilc14.ilc_poly = 0; |
|
6536 |
} |
|
6537 |
last14 = aSelector; |
|
6538 |
} |
|
6539 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
|
6540 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6541 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6542 |
argP[10], argP[11], argP[12], argP[13])); |
|
6543 |
} |
|
6544 |
||
6545 |
case 15: |
|
6546 |
{ |
|
6547 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(@line); |
|
6548 |
||
6549 |
if ((InterruptPending != nil) || (aSelector != last15)) { |
|
6550 |
ilc15.ilc_func = __SEND15ADDR__; |
|
6551 |
if (ilc15.ilc_poly) { |
|
6552 |
__flushPolyCache(ilc15.ilc_poly); |
|
6553 |
ilc15.ilc_poly = 0; |
|
6554 |
} |
|
6555 |
last15 = aSelector; |
|
6556 |
} |
|
6557 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
|
6558 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6559 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6560 |
argP[10], argP[11], argP[12], argP[13], |
|
6561 |
argP[14])); |
|
6562 |
} |
|
5755 | 6563 |
} |
6564 |
bad:; |
|
18238 | 6565 |
#endif |
5755 | 6566 |
%}. |
6567 |
||
6568 |
"/ arrive here, if bad number of arguments (too many) |
|
6569 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
6570 |
||
6571 |
^ self primitiveFailed |
|
6572 |
! |
|
6573 |
||
6316 | 6574 |
perform:aSelector withOptionalArgument:arg |
6575 |
"send aSelector-message to the receiver. |
|
6318 | 6576 |
If the message expects an argument, pass arg." |
6316 | 6577 |
|
18440 | 6578 |
aSelector argumentCount == 1 ifTrue:[ |
19846 | 6579 |
^ self perform:aSelector with:arg |
6316 | 6580 |
]. |
6581 |
^ self perform:aSelector |
|
6319 | 6582 |
|
6583 |
" |
|
6584 |
|rec sel| |
|
6585 |
||
6586 |
rec := -1. |
|
6587 |
sel := #abs. |
|
6588 |
rec perform:sel withOptionalArgument:2. |
|
6589 |
||
6590 |
sel := #max:. |
|
6591 |
rec perform:sel withOptionalArgument:2. |
|
6592 |
" |
|
6316 | 6593 |
! |
6594 |
||
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6595 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6596 |
"send aSelector-message to the receiver. |
6728 | 6597 |
Depending on the number of arguments the message expects, |
6598 |
pass either none, 1, or 2 arguments." |
|
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6599 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6600 |
|numArgs| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6601 |
|
18440 | 6602 |
numArgs := aSelector argumentCount. |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6603 |
numArgs == 0 ifTrue:[ |
19846 | 6604 |
^ self perform:aSelector |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6605 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6606 |
numArgs == 1 ifTrue:[ |
19846 | 6607 |
^ self perform:aSelector with:optionalArg1 |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6608 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6609 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6610 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6611 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6612 |
|rec sel| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6613 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6614 |
rec := -1. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6615 |
sel := #abs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6616 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6617 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6618 |
sel := #max:. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6619 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6620 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6621 |
! |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6622 |
|
6728 | 6623 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 |
6624 |
"send aSelector-message to the receiver. |
|
6625 |
Depending on the number of arguments the message expects, |
|
6626 |
pass either none, 1, 2 or 3 arguments." |
|
6627 |
||
6628 |
|numArgs| |
|
6629 |
||
18440 | 6630 |
numArgs := aSelector argumentCount. |
6728 | 6631 |
numArgs == 0 ifTrue:[ |
19846 | 6632 |
^ self perform:aSelector |
6728 | 6633 |
]. |
6634 |
numArgs == 1 ifTrue:[ |
|
19846 | 6635 |
^ self perform:aSelector with:optionalArg1 |
6728 | 6636 |
]. |
6637 |
numArgs == 2 ifTrue:[ |
|
19846 | 6638 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6728 | 6639 |
]. |
6640 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3. |
|
6641 |
||
6642 |
" |
|
6643 |
|rec sel| |
|
6644 |
||
6645 |
rec := -1. |
|
6646 |
sel := #abs. |
|
6647 |
rec perform:sel withOptionalArgument:2. |
|
6648 |
||
6649 |
sel := #max:. |
|
6650 |
rec perform:sel withOptionalArgument:2. |
|
6651 |
" |
|
6652 |
! |
|
6653 |
||
6764 | 6654 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 and:optionalArg4 |
6655 |
"send aSelector-message to the receiver. |
|
6656 |
Depending on the number of arguments the message expects, |
|
6657 |
pass either none, 1, 2, 3 or 4 arguments." |
|
6658 |
||
6659 |
|numArgs| |
|
6660 |
||
18440 | 6661 |
numArgs := aSelector argumentCount. |
6764 | 6662 |
numArgs == 0 ifTrue:[ |
19846 | 6663 |
^ self perform:aSelector |
6764 | 6664 |
]. |
6665 |
numArgs == 1 ifTrue:[ |
|
19846 | 6666 |
^ self perform:aSelector with:optionalArg1 |
6764 | 6667 |
]. |
6668 |
numArgs == 2 ifTrue:[ |
|
19846 | 6669 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6764 | 6670 |
]. |
6671 |
numArgs == 3 ifTrue:[ |
|
19846 | 6672 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 |
6764 | 6673 |
]. |
6674 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 with:optionalArg4. |
|
6675 |
||
6676 |
" |
|
6677 |
|rec sel| |
|
6678 |
||
6679 |
rec := -1. |
|
6680 |
sel := #abs. |
|
6681 |
rec perform:sel withOptionalArgument:2. |
|
6682 |
||
6683 |
sel := #max:. |
|
6684 |
rec perform:sel withOptionalArgument:2. |
|
6685 |
" |
|
6686 |
! |
|
6687 |
||
17524 | 6688 |
performMessage:aMessage |
6689 |
"Send aMessage, an object which provides a selector and arguments to the |
|
6690 |
receiver object. |
|
6691 |
Added for Ansi compatibility" |
|
6692 |
||
6693 |
^ self perform:(aMessage selector) withArguments:(aMessage arguments). |
|
6694 |
||
6695 |
" |
|
6696 |
123 performMessage:(Message selector:#+ argument:100) |
|
6697 |
" |
|
6698 |
! |
|
6699 |
||
5755 | 6700 |
performMethod:aMethod |
6701 |
"invoke aMethod on the receiver. |
|
6702 |
The method should be a zero-argument method. |
|
6703 |
This is a non-object-oriented entry, applying a method |
|
6704 |
in a functional way on a receiver. |
|
6705 |
Warning: |
|
19846 | 6706 |
Take care for the method to be appropriate for the |
6707 |
receiver - no checking is done by the VM." |
|
5755 | 6708 |
|
6709 |
^ aMethod valueWithReceiver:self arguments:#() |
|
6710 |
||
6711 |
" |
|
6712 |
|mthd| |
|
6713 |
||
6714 |
mthd := SmallInteger compiledMethodAt:#negated. |
|
6715 |
Transcript showCR:(1 performMethod:mthd) |
|
6716 |
" |
|
6717 |
||
6718 |
"BAD USE example: |
|
6719 |
||
6720 |
|mthd| |
|
6721 |
||
6722 |
mthd := Point compiledMethodAt:#x. |
|
6723 |
Transcript showCR:((1->2) performMethod:mthd) |
|
6724 |
" |
|
6725 |
||
6726 |
"Modified: 31.7.1997 / 17:41:50 / cg" |
|
6727 |
! |
|
6728 |
||
6729 |
performMethod:aMethod arguments:argumentArray |
|
6730 |
"invoke aMethod on the receiver, passing an argumentArray. |
|
6731 |
The size of the argumentArray should match the number of args |
|
6732 |
expected by the method. |
|
6733 |
This is a non-object-oriented entry, applying a method |
|
6734 |
in a functional way on a receiver. |
|
6735 |
Warning: |
|
19846 | 6736 |
Take care for the method to be appropriate for the |
6737 |
receiver - no checking is done by the VM." |
|
5755 | 6738 |
|
6739 |
^ aMethod valueWithReceiver:self arguments:argumentArray |
|
6740 |
||
6741 |
" |
|
6742 |
|mthd| |
|
6743 |
||
6744 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6745 |
Transcript showCR:(1 performMethod:mthd arguments:#(2)) |
|
6746 |
" |
|
6747 |
||
6748 |
"Created: 31.7.1997 / 17:46:31 / cg" |
|
6749 |
! |
|
6750 |
||
6751 |
performMethod:aMethod with:arg |
|
6752 |
"invoke aMethod on the receiver, passing an argument. |
|
6753 |
The method should be a one-argument method. |
|
6754 |
This is a non-object-oriented entry, applying a method |
|
6755 |
in a functional way on a receiver. |
|
6756 |
Warning: |
|
19846 | 6757 |
Take care for the method to be appropriate for the |
6758 |
receiver - no checking is done by the VM." |
|
5755 | 6759 |
|
6760 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg) |
|
6761 |
||
6762 |
" |
|
6763 |
|mthd| |
|
6764 |
||
6765 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6766 |
Transcript showCR:(1 performMethod:mthd with:2) |
|
6767 |
" |
|
6768 |
||
6769 |
"Modified: 31.7.1997 / 17:42:32 / cg" |
|
6770 |
! |
|
6771 |
||
6772 |
performMethod:aMethod with:arg1 with:arg2 |
|
6773 |
"invoke aMethod on the receiver, passing two arguments. |
|
6774 |
The method should be a two-argument method. |
|
6775 |
This is a non-object-oriented entry, applying a method |
|
6776 |
in a functional way on a receiver. |
|
6777 |
Warning: |
|
19846 | 6778 |
Take care for the method to be appropriate for the |
6779 |
receiver - no checking is done by the VM." |
|
5755 | 6780 |
|
6781 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) |
|
6782 |
||
6783 |
" |
|
6784 |
|mthd arr| |
|
6785 |
||
6786 |
arr := Array new:1. |
|
6787 |
mthd := Array compiledMethodAt:#basicAt:put:. |
|
6788 |
arr performMethod:mthd with:1 with:'foo'. |
|
6789 |
Transcript showCR:arr |
|
6790 |
" |
|
6791 |
||
6792 |
"Modified: 31.7.1997 / 17:44:54 / cg" |
|
6793 |
! |
|
6794 |
||
6795 |
performMethod:aMethod with:arg1 with:arg2 with:arg3 |
|
6796 |
"invoke aMethod on the receiver, passing three arguments. |
|
6797 |
The method should be a three-argument method. |
|
6798 |
This is a non-object-oriented entry, applying a method |
|
6799 |
in a functional way on a receiver. |
|
6800 |
Warning: |
|
19846 | 6801 |
Take care for the method to be appropriate for the |
6802 |
receiver - no checking is done by the VM." |
|
5755 | 6803 |
|
6804 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3) |
|
6805 |
||
6806 |
"Created: 31.7.1997 / 17:45:20 / cg" |
|
15586 | 6807 |
! |
6808 |
||
6809 |
performX:aSelector |
|
18231 | 6810 |
"send the message aSelector to the receiver |
6811 |
This is the original implementation of #perform, for reference (before Jan's changes for Ruby tuning)." |
|
15586 | 6812 |
|
6813 |
<resource: #skipInDebuggersWalkBack> |
|
6814 |
||
6815 |
%{ |
|
6816 |
REGISTER OBJ sel = aSelector; |
|
6817 |
||
6818 |
if (InterruptPending == nil) { |
|
19846 | 6819 |
struct inlineCache *pIlc; |
15586 | 6820 |
|
6821 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF0(l) } |
|
6822 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
6823 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
6824 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
6825 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
6826 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
6827 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
6828 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
6829 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
6830 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
16230 | 6831 |
#undef nilcs |
15586 | 6832 |
#define nilcs 256 |
6833 |
||
19846 | 6834 |
static struct sel_and_ilc { |
6835 |
OBJ sel; |
|
6836 |
struct inlineCache ilc; |
|
6837 |
struct sel_and_ilc *next; |
|
6838 |
} sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
|
15586 | 6839 |
|
6840 |
#undef SEL_AND_ILC_INIT_1 |
|
6841 |
#undef SEL_AND_ILC_INIT_2 |
|
6842 |
#undef SEL_AND_ILC_INIT_4 |
|
6843 |
#undef SEL_AND_ILC_INIT_8 |
|
6844 |
#undef SEL_AND_ILC_INIT_16 |
|
6845 |
#undef SEL_AND_ILC_INIT_32 |
|
6846 |
#undef SEL_AND_ILC_INIT_64 |
|
6847 |
#undef SEL_AND_ILC_INIT_128 |
|
6848 |
#undef SEL_AND_ILC_INIT_256 |
|
6849 |
||
19846 | 6850 |
static struct sel_and_ilc *nextFree = sel_and_ilc; |
6851 |
static struct sel_and_ilc *lastUsed = 0; |
|
6852 |
int n; |
|
6853 |
struct sel_and_ilc *slot, *prev, *prevPrev; |
|
6854 |
||
6855 |
for (n=0, slot = lastUsed, prev = prevPrev = 0; slot; n++, slot = slot->next) { |
|
6856 |
if (sel == slot->sel) { |
|
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6857 |
#ifdef XXDEBUG |
15586 | 6858 |
printf("cached slot %d (len=%d)\n", slot-sel_and_ilc, n); |
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6859 |
#endif |
19846 | 6860 |
pIlc = &(slot->ilc); |
6861 |
// move to front |
|
6862 |
if (prev) { |
|
6863 |
prev->next = slot->next; |
|
6864 |
} |
|
6865 |
slot->next = lastUsed; |
|
6866 |
lastUsed = slot; |
|
6867 |
pIlc = &(slot->ilc); |
|
6868 |
goto perform0_send_and_return; |
|
6869 |
} |
|
6870 |
prevPrev = prev; |
|
6871 |
prev = slot; |
|
6872 |
} |
|
6873 |
// not recently used... |
|
6874 |
if (nextFree) { |
|
6875 |
// another free one |
|
6876 |
slot = nextFree; |
|
6877 |
nextFree = nextFree + 1; |
|
6878 |
if (nextFree >= &(sel_and_ilc[nilcs])) nextFree = 0; |
|
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6879 |
#ifdef XXDEBUG |
15586 | 6880 |
printf("new slot %d\n", slot-sel_and_ilc); |
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6881 |
#endif |
19846 | 6882 |
} else { |
6883 |
// no more for reuse - use least recently used |
|
6884 |
slot = prev; |
|
6885 |
prevPrev->next = 0; |
|
6886 |
slot->next = lastUsed; |
|
6887 |
lastUsed = slot; |
|
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6888 |
#ifdef XXDEBUG |
15586 | 6889 |
printf("reuse last slot %d\n", slot-sel_and_ilc); |
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6890 |
#endif |
19846 | 6891 |
} |
6892 |
||
6893 |
/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/ |
|
6894 |
pIlc = &(slot->ilc); |
|
6895 |
slot->sel = sel; |
|
6896 |
pIlc->ilc_func = __SEND0ADDR__; |
|
6897 |
if (pIlc->ilc_poly) { |
|
6898 |
__flushPolyCache(pIlc->ilc_poly); |
|
6899 |
pIlc->ilc_poly = 0; |
|
6900 |
} |
|
15586 | 6901 |
perform0_send_and_return: |
19846 | 6902 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
15586 | 6903 |
} else { |
19846 | 6904 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
6905 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
15586 | 6906 |
} |
6907 |
%}. |
|
6908 |
^ self perform:aSelector withArguments:#() |
|
15797 | 6909 |
! |
6910 |
||
6911 |
returnablePerform:aSelector with:arg |
|
6912 |
"send the one-arg-message aSelector to the receiver. |
|
6913 |
This is the same as #perform:with: but the context can return." |
|
6914 |
||
6915 |
<context: #return> |
|
6916 |
%{ |
|
6917 |
REGISTER OBJ sel = aSelector; |
|
6918 |
||
6919 |
if (InterruptPending == nil) { |
|
19846 | 6920 |
struct inlineCache *pIlc; |
15797 | 6921 |
/* JV @ 2010-22-07: To improve performance I use 256 ILCs instead |
6922 |
of default 4. For details, see comment in perform: */ |
|
6923 |
||
6924 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF1(l) } |
|
6925 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
6926 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
6927 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
6928 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
6929 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
6930 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
6931 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
6932 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
6933 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
16230 | 6934 |
#undef nilcs |
15797 | 6935 |
#define nilcs 256 |
6936 |
||
19846 | 6937 |
static struct { OBJ sel; struct inlineCache ilc; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
15797 | 6938 |
|
6939 |
#undef SEL_AND_ILC_INIT_1 |
|
6940 |
#undef SEL_AND_ILC_INIT_2 |
|
6941 |
#undef SEL_AND_ILC_INIT_4 |
|
6942 |
#undef SEL_AND_ILC_INIT_8 |
|
6943 |
#undef SEL_AND_ILC_INIT_16 |
|
6944 |
#undef SEL_AND_ILC_INIT_32 |
|
6945 |
#undef SEL_AND_ILC_INIT_64 |
|
6946 |
#undef SEL_AND_ILC_INIT_128 |
|
6947 |
#undef SEL_AND_ILC_INIT_256 |
|
6948 |
||
19846 | 6949 |
static int flip = 0; |
6950 |
int i; |
|
6951 |
for (i = 0; i < nilcs; i++) { |
|
6952 |
if (sel == sel_and_ilc[i].sel) { |
|
6953 |
pIlc = &sel_and_ilc[i].ilc; |
|
6954 |
goto perform1_send_and_return; |
|
6955 |
} |
|
6956 |
} |
|
6957 |
/*printf("Object >> #perform: #%s with: arg --> no PIC found\n", __symbolVal(aSelector));*/ |
|
6958 |
pIlc = &sel_and_ilc[flip].ilc; |
|
6959 |
sel_and_ilc[flip].sel = sel; |
|
6960 |
flip = (flip + 1) % nilcs; |
|
6961 |
pIlc->ilc_func = __SEND1ADDR__; |
|
6962 |
if (pIlc->ilc_poly) { |
|
6963 |
__flushPolyCache(pIlc->ilc_poly); |
|
6964 |
pIlc->ilc_poly = 0; |
|
6965 |
} |
|
15797 | 6966 |
perform1_send_and_return: |
19846 | 6967 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
15797 | 6968 |
} else { |
19846 | 6969 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
6970 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
15797 | 6971 |
} |
6972 |
%}. |
|
6973 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5755 | 6974 |
! ! |
6975 |
||
17677 | 6976 |
!Object methodsFor:'misc ui support'! |
6977 |
||
6978 |
browse |
|
6979 |
"open a browser on the receiver's class" |
|
6980 |
||
6981 |
self class theNonMetaclass browse |
|
6982 |
||
6983 |
" |
|
6984 |
10 browse |
|
6985 |
Collection browse |
|
6986 |
Collection class browse |
|
6987 |
" |
|
6988 |
! ! |
|
6989 |
||
10834 | 6990 |
!Object methodsFor:'object persistency'! |
6991 |
||
6992 |
elementDescriptorFor:anAspectSymbol |
|
6993 |
"support for persistency: |
|
6994 |
answer a collection of associations containing the |
|
6995 |
objects state to be encoded for aspect. |
|
6996 |
Association key is the instance variable name or access selector, |
|
6997 |
association value is the contents of the instance variable. |
|
6998 |
||
6999 |
The default is to return the contents of all non-nil instance variables" |
|
7000 |
||
7001 |
|ret| |
|
7002 |
||
7003 |
ret := 0. |
|
7004 |
anAspectSymbol notNil ifTrue:[ |
|
19846 | 7005 |
ret := self perform:anAspectSymbol ifNotUnderstood:[0]. |
10834 | 7006 |
]. |
7007 |
ret == 0 ifTrue:[ |
|
19846 | 7008 |
^ self elementDescriptorForNonNilInstanceVariables |
10834 | 7009 |
]. |
7010 |
^ ret. |
|
7011 |
! |
|
7012 |
||
7013 |
elementDescriptorForInstanceVariables |
|
7014 |
"return all instance variables for visiting/encoding" |
|
7015 |
||
7016 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
|
7017 |
||
7018 |
" |
|
7019 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
7020 |
Dictionary new elementDescriptorForInstanceVariables |
|
7021 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
7022 |
" |
|
7023 |
! |
|
7024 |
||
7025 |
elementDescriptorForInstanceVariablesMatching:aBlock |
|
7026 |
"return all instance variables which conform to aBlock, for encoding/visiting. |
|
7027 |
Indexed vars are all included." |
|
7028 |
||
7029 |
|instVarNames theClass children |
|
7030 |
instSize "{ Class: SmallInteger }" |
|
7031 |
varSize "{ Class: SmallInteger }"| |
|
7032 |
||
7033 |
theClass := self class. |
|
7034 |
||
7035 |
instSize := theClass instSize. |
|
7036 |
varSize := theClass isVariable ifTrue:[self basicSize] ifFalse:[0]. |
|
7037 |
children := OrderedCollection new:(instSize + varSize). |
|
7038 |
||
7039 |
instVarNames := theClass allInstVarNames. |
|
7040 |
1 to:instSize do:[:i | |var| |
|
19846 | 7041 |
var := self instVarAt:i. |
7042 |
(aBlock value:var) ifTrue:[ |
|
7043 |
children add:((instVarNames at:i) -> var) |
|
7044 |
] |
|
10834 | 7045 |
]. |
7046 |
||
7047 |
varSize ~~ 0 ifTrue:[ |
|
19846 | 7048 |
1 to:varSize do:[:i | |
7049 |
children add:(i -> (self basicAt:i)) |
|
7050 |
] |
|
10834 | 7051 |
]. |
7052 |
||
7053 |
^ children. |
|
7054 |
||
7055 |
" |
|
7056 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
7057 |
Dictionary new elementDescriptorForInstanceVariables |
|
7058 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
7059 |
" |
|
7060 |
! |
|
7061 |
||
7062 |
elementDescriptorForNonNilInstanceVariables |
|
7063 |
"return all non-nil instance variables for visiting/encoding" |
|
7064 |
||
7065 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | val notNil]. |
|
7066 |
||
7067 |
" |
|
7068 |
#(1 2 3 nil true symbol) elementDescriptorForNonNilInstanceVariables |
|
7069 |
Dictionary new elementDescriptorForNonNilInstanceVariables |
|
7070 |
(5 @ nil) elementDescriptorForNonNilInstanceVariables |
|
7071 |
" |
|
7072 |
! ! |
|
7073 |
||
5755 | 7074 |
!Object methodsFor:'printing & storing'! |
7075 |
||
6235 | 7076 |
basicPrintOn:aStream |
19451 | 7077 |
"append the receiver's className with an article to the argument, aStream" |
6235 | 7078 |
|
7079 |
aStream nextPutAll:self classNameWithArticle |
|
7080 |
! |
|
7081 |
||
18984 | 7082 |
basicStoreString |
7083 |
"defined here for compatibility with CharacterArray, which redefines this" |
|
7084 |
||
7085 |
^ self storeString |
|
7086 |
! |
|
7087 |
||
5755 | 7088 |
className |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
7089 |
"return the classname of the receiver's class" |
5755 | 7090 |
|
7091 |
^ self class name |
|
7092 |
||
7093 |
" |
|
7094 |
1 className |
|
10460 | 7095 |
1 class className |
5755 | 7096 |
$a className |
9105 | 7097 |
$a class className |
5755 | 7098 |
" |
7099 |
! |
|
7100 |
||
7101 |
classNameWithArticle |
|
7102 |
"return a string consisting of classname preceeded by an article. |
|
7103 |
(dont expect me to write national variants for this ... :-) |
|
7104 |
If you have special preferences, redefine it ..." |
|
7105 |
||
6829 | 7106 |
| cls| |
5755 | 7107 |
|
7108 |
(cls := self class) == self ifTrue:[ |
|
19846 | 7109 |
^ 'a funny object' |
5755 | 7110 |
]. |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
7111 |
cls isNil ifTrue:[ |
19846 | 7112 |
^ 'a nil-classes object' "/ cannot happen |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
7113 |
]. |
6829 | 7114 |
^ cls nameWithArticle |
5755 | 7115 |
|
7116 |
" |
|
10460 | 7117 |
1 classNameWithArticle |
7118 |
(1->2) classNameWithArticle |
|
5755 | 7119 |
XWorkstation basicNew classNameWithArticle |
10460 | 7120 |
XWorkstation classNameWithArticle |
5755 | 7121 |
" |
7122 |
||
7123 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
7124 |
! |
|
7125 |
||
7126 |
errorPrint |
|
12703 | 7127 |
"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
|
7128 |
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
|
7129 |
headless applications." |
5755 | 7130 |
|
14165 | 7131 |
Stderr isNil ifTrue:[ |
19846 | 7132 |
"/ the following allows errorPrint to be used during |
7133 |
"/ the early init-phase, when no Stderr has been set up. |
|
7134 |
"/ (depends on string to respond to #errorPrint) |
|
7135 |
self printString utf8Encoded errorPrint. |
|
7136 |
^ self. |
|
14165 | 7137 |
]. |
7138 |
||
13350 | 7139 |
self withErrorStreamDo:[:s | self printOn:s]. |
7140 |
||
7141 |
"Modified: / 21-04-2011 / 12:46:42 / cg" |
|
5755 | 7142 |
! |
7143 |
||
7144 |
errorPrintCR |
|
7145 |
"{ Pragma: +optSpace }" |
|
7146 |
||
12703 | 7147 |
"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
|
7148 |
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
|
7149 |
headless applications." |
5755 | 7150 |
|
14165 | 7151 |
Stderr isNil ifTrue:[ |
19846 | 7152 |
"/ the following allows errorPrintCR to be used during |
7153 |
"/ the early init-phase, when no Stderr has been set up. |
|
7154 |
"/ (depends on string to respond to #errorPrintCR) |
|
7155 |
self printString utf8Encoded errorPrintCR. |
|
7156 |
^ self. |
|
14165 | 7157 |
]. |
7158 |
||
13350 | 7159 |
self withErrorStreamDo:[:s | self printOn:s. s cr]. |
7160 |
||
7161 |
" |
|
7162 |
'hello' errorPrintCR |
|
7163 |
" |
|
5755 | 7164 |
|
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
7165 |
"Created: / 20-05-1996 / 10:20:41 / cg" |
13350 | 7166 |
"Modified: / 21-04-2011 / 12:47:13 / cg" |
5755 | 7167 |
! |
7168 |
||
7169 |
errorPrintNL |
|
7170 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7171 |
<resource:#obsolete> |
5755 | 7172 |
|
7173 |
"print the receiver followed by a cr on the standard error stream. |
|
7174 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
7175 |
||
7176 |
^ self errorPrintCR |
|
7177 |
||
7178 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
7179 |
! |
|
7180 |
||
7181 |
errorPrintNewline |
|
7182 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7183 |
<resource:#obsolete> |
5755 | 7184 |
|
7185 |
"print the receiver followed by a cr on the standard error stream. |
|
7186 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
7187 |
||
7188 |
self errorPrintCR. |
|
7189 |
||
7190 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
7191 |
! |
|
7192 |
||
7193 |
infoPrint |
|
7194 |
"{ Pragma: +optSpace }" |
|
7195 |
||
7196 |
"print the receiver on the standard error stream. |
|
7197 |
This is meant for information messages which are not warnings |
|
7198 |
or fatal messages. |
|
7199 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
7200 |
||
7201 |
InfoPrinting == true ifTrue:[ |
|
19846 | 7202 |
self errorPrint |
5755 | 7203 |
] |
7204 |
! |
|
7205 |
||
7206 |
infoPrintCR |
|
7207 |
"{ Pragma: +optSpace }" |
|
7208 |
||
7209 |
"print the receiver followed by a cr on the standard error stream. |
|
7210 |
This is meant for information messages which are not warnings |
|
7211 |
or fatal messages. |
|
7212 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
7213 |
||
7214 |
InfoPrinting == true ifTrue:[ |
|
19846 | 7215 |
self errorPrintCR |
5755 | 7216 |
] |
7217 |
||
7218 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
7219 |
! |
|
7220 |
||
7221 |
infoPrintNL |
|
7222 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7223 |
<resource:#obsolete> |
5755 | 7224 |
|
7225 |
"print the receiver followed by a cr on the standard error stream. |
|
7226 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
7227 |
||
7228 |
^ self infoPrintCR |
|
7229 |
! |
|
7230 |
||
7231 |
||
7232 |
"print the receiver on the standard output stream (which is not the Transcript)" |
|
7233 |
||
19382 | 7234 |
"/ the following allows print/printCR to be used during |
5755 | 7235 |
"/ the early init-phase, when no Stdout has been set up. |
19382 | 7236 |
"/ (depends on String to respond to #print, without recurring back to here) |
5755 | 7237 |
|
7238 |
Stdout isNil ifTrue:[ |
|
19382 | 7239 |
self printString utf8Encoded print. |
7240 |
^ self |
|
7241 |
]. |
|
7242 |
self printOn:Processor activeProcess stdout |
|
5755 | 7243 |
|
7244 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
7245 |
! |
|
7246 |
||
7247 |
printCR |
|
7248 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
|
7249 |
||
7250 |
"/ the following allows printCR to be used during |
|
7251 |
"/ the early init-phase, when no Stdout has been set up. |
|
7252 |
"/ (depends on string to respond to #printCR) |
|
7253 |
||
19382 | 7254 |
|stdout| |
7255 |
||
5755 | 7256 |
Stdout isNil ifTrue:[ |
19382 | 7257 |
self printString utf8Encoded printCR. |
7258 |
^ self |
|
7259 |
]. |
|
7260 |
stdout := Processor activeProcess stdout. |
|
7261 |
self printOn:stdout. |
|
7262 |
stdout cr |
|
5755 | 7263 |
|
7264 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
7265 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
|
7266 |
! |
|
7267 |
||
7268 |
printNL |
|
7269 |
"print the receiver followed by a cr on the standard output stream |
|
7270 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
7271 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7272 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7273 |
|
5755 | 7274 |
^ self printCR |
7275 |
||
7276 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
7277 |
! |
|
7278 |
||
7279 |
printNewline |
|
7280 |
"print the receiver followed by a cr on the standard output stream. |
|
7281 |
This exists for backward compatibility - please use #printCR." |
|
7282 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7283 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7284 |
|
5755 | 7285 |
self printCR |
7286 |
||
7287 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
7288 |
! |
|
7289 |
||
7290 |
printOn:aStream |
|
7291 |
"append a user printed representation of the receiver to aStream. |
|
7292 |
The format is suitable for a human - not meant to be read back. |
|
7293 |
||
19451 | 7294 |
The default here is to output the receiver's class name. |
5755 | 7295 |
BUT: this method is heavily redefined for objects which |
7296 |
can print prettier." |
|
7297 |
||
6235 | 7298 |
self basicPrintOn:aStream. |
7299 |
||
7300 |
" |
|
7301 |
(1@2) printOn:Transcript |
|
7302 |
(1@2) basicPrintOn:Transcript |
|
7303 |
" |
|
5755 | 7304 |
! |
7305 |
||
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7306 |
printOn:aStream format:format |
11335 | 7307 |
"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
|
7308 |
Defined here for compatibility with subclasses" |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7309 |
|
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7310 |
self printOn:aStream. |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7311 |
! |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7312 |
|
5755 | 7313 |
printOn:aStream leftPaddedTo:size |
7314 |
"print the receiver on aStream, padding with spaces up to size. |
|
7315 |
padding is done on the left." |
|
7316 |
||
7317 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
7318 |
||
7319 |
" |
|
7320 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
7321 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
7322 |
" |
|
7323 |
! |
|
7324 |
||
7325 |
printOn:aStream leftPaddedTo:size with:padCharacter |
|
7326 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
7327 |
padding is done on the left." |
|
7328 |
||
7329 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
7330 |
||
7331 |
" |
|
7332 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
7333 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
7334 |
" |
|
7335 |
! |
|
7336 |
||
7337 |
printOn:aStream paddedTo:size |
|
7338 |
"print the receiver on aStream, padding with spaces up to size." |
|
7339 |
||
7340 |
self printOn:aStream paddedTo:size with:(Character space) |
|
7341 |
||
7342 |
" |
|
7343 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
7344 |
" |
|
7345 |
! |
|
7346 |
||
7347 |
printOn:aStream paddedTo:size with:padCharacter |
|
7348 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
7349 |
||
7350 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
7351 |
||
7352 |
" |
|
7353 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
7354 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
7355 |
" |
|
7356 |
! |
|
7357 |
||
7358 |
printOn:aStream zeroPaddedTo:size |
|
7359 |
"print the receiver on aStream, padding with zeros up to size. |
|
7360 |
Usually used with float numbers." |
|
7361 |
||
7362 |
self printOn:aStream paddedTo:size with:$0. |
|
7363 |
||
7364 |
" |
|
7365 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
7366 |
" |
|
7367 |
! |
|
7368 |
||
7369 |
printRightAdjustLen:size |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7370 |
<resource: #obsolete> |
5755 | 7371 |
"obsolete - just a name confusion. |
7372 |
This method will go away ..." |
|
7373 |
||
19382 | 7374 |
(self printStringLeftPaddedTo:size) print |
5755 | 7375 |
! |
7376 |
||
7377 |
printString |
|
7378 |
"return a string for printing the receiver. |
|
7379 |
Since we now use printOn: as the basic print mechanism, |
|
7380 |
we have to create a stream and print into it." |
|
7381 |
||
7382 |
|s| |
|
7383 |
||
19340 | 7384 |
"allocate at least 40 bytes for fast UUID conversion. |
7385 |
cg: who did that? If that's a bottleneck, it ought to be done in UUID, not here!!" |
|
7386 |
||
7387 |
s := CharacterWriteStream on:(String basicNew:40). |
|
5755 | 7388 |
self printOn:s. |
8300
d15ead94361f
Use CharacterWriteStream in #printString (speedup)
Stefan Vogel <sv@exept.de>
parents:
8287
diff
changeset
|
7389 |
^ s contents. |
7978
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
7390 |
|
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
7391 |
" |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
7392 |
Date today printString. |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
7393 |
" |
5755 | 7394 |
! |
7395 |
||
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7396 |
printStringFormat:orintFormat |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7397 |
"subclasses may redefine this. |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7398 |
Defined here to avoid type checks" |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7399 |
|
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7400 |
^ self printString |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7401 |
! |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7402 |
|
5755 | 7403 |
printStringLeftPaddedTo:size |
7404 |
"return my printString as a right-adjusted string of length size; |
|
7405 |
characters on the left are filled with spaces. |
|
10460 | 7406 |
If the printString is longer than size, |
5755 | 7407 |
it is returned unchanged (i.e. not truncated)" |
7408 |
||
7409 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
7410 |
||
7411 |
" |
|
7412 |
10 printStringLeftPaddedTo:10 |
|
7413 |
1 printStringLeftPaddedTo:10 |
|
7414 |
" |
|
7415 |
! |
|
7416 |
||
7417 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
7418 |
"return my printString as a right-adjusted string of length size; |
|
7419 |
characters on the left are filled with spaces. |
|
7420 |
If the printString is larger than size, |
|
7421 |
return the result from evaluating alternative." |
|
7422 |
||
7423 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
7424 |
||
7425 |
" |
|
7426 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
7427 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
7428 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
7429 |
" |
|
7430 |
! |
|
7431 |
||
7432 |
printStringLeftPaddedTo:size with:padCharacter |
|
7433 |
"return my printString as a right-adjusted string of length size; |
|
7434 |
characters on the left are filled with padCharacter. |
|
10460 | 7435 |
If the printString is longer than size, |
5755 | 7436 |
it is returned unchanged (i.e. not truncated)" |
7437 |
||
7438 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
7439 |
||
7440 |
" |
|
10460 | 7441 |
123 printStringLeftPaddedTo:10 with:$. |
7442 |
1 printStringLeftPaddedTo:10 with:$. |
|
5755 | 7443 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
7444 |
" |
|
7445 |
! |
|
7446 |
||
7447 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
7448 |
"return my printString as a right-adjusted string of length size; |
|
7449 |
characters on the left are filled with padCharacter. |
|
7450 |
If the printString is larger than size, |
|
7451 |
return the result from evaluating alternative." |
|
7452 |
||
7453 |
|s| |
|
7454 |
||
7455 |
s := self printString. |
|
7456 |
s size > size ifTrue:[^ alternative value]. |
|
7457 |
^ s leftPaddedTo:size with:padCharacter |
|
7458 |
||
7459 |
" |
|
10460 | 7460 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
7461 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
7462 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
5755 | 7463 |
" |
7464 |
! |
|
7465 |
||
8576 | 7466 |
printStringLimitedTo:sizeLimit |
7467 |
"return a string for printing the receiver, but limit the result string in its size." |
|
7468 |
||
7469 |
|s| |
|
7470 |
||
7471 |
s := CharacterWriteStream on:(String basicNew:30). |
|
7472 |
s writeLimit:sizeLimit. |
|
7473 |
self printOn:s. |
|
7474 |
^ s contents. |
|
7475 |
||
7476 |
" |
|
7477 |
Date today printStringLimitedTo:5. |
|
10460 | 7478 |
'12345678901234567890' printStringLimitedTo:5. |
8576 | 7479 |
" |
7480 |
! |
|
7481 |
||
5755 | 7482 |
printStringOnError:exceptionBlock |
7483 |
"return a string for printing the receiver; if any error occurs, return the result from |
|
7484 |
evaluating exceptionBlock. Useful to print something in an exceptionHandler or other |
|
7485 |
cleanup code." |
|
7486 |
||
7487 |
|rslt| |
|
7488 |
||
7489 |
Error handle:[:ex | |
|
19846 | 7490 |
rslt := exceptionBlock value |
5755 | 7491 |
] do:[ |
19846 | 7492 |
rslt := self printString |
5755 | 7493 |
]. |
7494 |
^ rslt |
|
7495 |
! |
|
7496 |
||
7497 |
printStringPaddedTo:size |
|
7498 |
"return a printed representation of the receiver, |
|
7499 |
padded with spaces (at the right) up to size. |
|
10460 | 7500 |
If the printString is longer than size, |
5755 | 7501 |
it is returned unchanged (i.e. not truncated)" |
7502 |
||
7503 |
^ self printStringPaddedTo:size with:(Character space) |
|
7504 |
||
7505 |
" |
|
10460 | 7506 |
123 printStringPaddedTo:10 |
7507 |
1234567890123456 printStringPaddedTo:10 |
|
7508 |
'hello' printStringPaddedTo:10 |
|
5755 | 7509 |
" |
7510 |
! |
|
7511 |
||
7512 |
printStringPaddedTo:size ifLarger:alternative |
|
7513 |
"return a printed representation of the receiver, |
|
7514 |
padded with spaces (at the right) up to size. |
|
10460 | 7515 |
If the resulting printString is too large, |
5755 | 7516 |
return the result from evaluating alternative." |
7517 |
||
7518 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
7519 |
||
7520 |
" |
|
10460 | 7521 |
12 printStringPaddedTo:3 ifLarger:['***'] |
7522 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
7523 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
5755 | 7524 |
" |
7525 |
! |
|
7526 |
||
7527 |
printStringPaddedTo:size with:padCharacter |
|
7528 |
"return a printed representation of the receiver, |
|
7529 |
padded with padCharacter (at the right) up to size. |
|
10460 | 7530 |
If the printString is longer than size, |
5755 | 7531 |
it is returned unchanged (i.e. not truncated)" |
7532 |
||
7533 |
^ (self printString) paddedTo:size with:padCharacter |
|
7534 |
||
7535 |
" |
|
7536 |
123 printStringPaddedTo:10 with:$. |
|
7537 |
123 printStringPaddedTo:10 with:$* |
|
10460 | 7538 |
123 printStringPaddedTo:3 with:$* |
7539 |
1234 printStringPaddedTo:3 with:$* |
|
5755 | 7540 |
" |
7541 |
! |
|
7542 |
||
7543 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
7544 |
"return a printed representation of the receiver, |
|
7545 |
padded with padCharacter (at the right) up to size. |
|
10460 | 7546 |
If the resulting printString is too large, |
5755 | 7547 |
return the result from evaluating alternative." |
7548 |
||
7549 |
|s| |
|
7550 |
||
7551 |
s := self printString. |
|
7552 |
s size > size ifTrue:[^ alternative value]. |
|
7553 |
^ s paddedTo:size with:padCharacter |
|
7554 |
||
7555 |
" |
|
7556 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
7557 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
7558 |
" |
|
7559 |
! |
|
7560 |
||
7561 |
printStringRightAdjustLen:size |
|
7562 |
"obsolete - just a name confusion. |
|
7563 |
This method will go away ..." |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7564 |
<resource: #obsolete> |
5755 | 7565 |
|
7566 |
^ self printStringLeftPaddedTo:size |
|
7567 |
! |
|
7568 |
||
7569 |
printStringZeroPaddedTo:size |
|
10460 | 7570 |
"return a printed representation of the receiver, |
5755 | 7571 |
padded with zero (at the right) characters up to size. |
7572 |
Usually used with float numbers." |
|
7573 |
||
7574 |
^ self printStringPaddedTo:size with:$0 |
|
7575 |
||
7576 |
" |
|
10460 | 7577 |
123.0 printStringZeroPaddedTo:10 |
5755 | 7578 |
" |
7579 |
! |
|
7580 |
||
8287 | 7581 |
printfPrintString:ignoredFormat |
7582 |
"fallback to default printString |
|
7583 |
(for compatibility with float and integer-printing)" |
|
7584 |
||
7585 |
^ self printString |
|
7586 |
! |
|
7587 |
||
5755 | 7588 |
store |
7589 |
"store the receiver on standard output. |
|
7590 |
this method is useless, but included for compatibility." |
|
7591 |
||
19382 | 7592 |
self storeOn:Processor activeProcess stdout |
5755 | 7593 |
! |
7594 |
||
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7595 |
storeArrayElementOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7596 |
"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
|
7597 |
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
|
7598 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7599 |
^ 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
|
7600 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7601 |
|
5755 | 7602 |
storeCR |
7603 |
"store the receiver on standard output; append a carriage return." |
|
7604 |
||
19382 | 7605 |
|stdout| |
7606 |
||
7607 |
stdout := Processor activeProcess stdout. |
|
7608 |
self storeOn:stdout. |
|
7609 |
stdout cr. |
|
5755 | 7610 |
|
7611 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
7612 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
7613 |
! |
|
7614 |
||
7615 |
storeNl |
|
7616 |
"store the receiver on standard output; append a newline. |
|
7617 |
This method is included for backward compatibility- use #storeCR." |
|
7618 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7619 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7620 |
|
5755 | 7621 |
self storeCR. |
7622 |
||
7623 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
7624 |
! |
|
7625 |
||
7626 |
storeOn:aStream |
|
7627 |
"store the receiver on aStream; i.e. print an expression which will |
|
7628 |
reconstruct the receiver. |
|
7629 |
Notice, that no self referencing or cyclic objects can be represented |
|
7630 |
in this format. |
|
7631 |
Use storeBinaryOn:, which handles these cases correctly." |
|
7632 |
||
7633 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
7634 |
||
7635 |
thisContext isRecursive ifTrue:[ |
|
19846 | 7636 |
RecursiveStoreError raiseRequestWith:self. |
7637 |
'Object [error]: storeString of self referencing object (' errorPrint. |
|
7638 |
self class name errorPrint. |
|
7639 |
')' errorPrintCR. |
|
7640 |
aStream nextPutAll:'#("recursive")'. |
|
7641 |
^ self |
|
5755 | 7642 |
]. |
7643 |
||
7644 |
myClass := self class. |
|
7645 |
aStream nextPut:$(. |
|
7646 |
aStream nextPutAll:self class name. |
|
7647 |
||
7648 |
hasSemi := false. |
|
7649 |
myClass isVariable ifTrue:[ |
|
19846 | 7650 |
aStream nextPutAll:' basicNew:'. |
7651 |
self basicSize printOn:aStream |
|
5755 | 7652 |
] ifFalse:[ |
19846 | 7653 |
aStream nextPutAll:' basicNew' |
5755 | 7654 |
]. |
7655 |
||
7656 |
sz := myClass instSize. |
|
10460 | 7657 |
1 to:sz do:[:i | |
19846 | 7658 |
|ref| |
7659 |
||
7660 |
ref := (self instVarAt:i). |
|
7661 |
"/ no need to store nil entries, because the object has been instantiated |
|
7662 |
"/ with basicNew just a moment ago (so the fields are already nil) |
|
7663 |
ref notNil ifTrue:[ |
|
7664 |
aStream nextPutAll:' instVarAt:'. |
|
7665 |
i printOn:aStream. |
|
7666 |
aStream nextPutAll:' put:'. |
|
7667 |
ref storeOn:aStream. |
|
7668 |
aStream nextPut:$;. |
|
7669 |
hasSemi := true |
|
7670 |
]. |
|
5755 | 7671 |
]. |
7672 |
myClass isVariable ifTrue:[ |
|
19846 | 7673 |
sz := self basicSize. |
7674 |
1 to:sz do:[:i | |
|
7675 |
|ref| |
|
7676 |
||
7677 |
ref := (self basicAt:i). |
|
7678 |
"/ no need to store nil entries, because the object has been instantiated |
|
7679 |
"/ with basicNew just a moment ago (so the fields are already nil) |
|
7680 |
ref notNil ifTrue:[ |
|
7681 |
aStream nextPutAll:' basicAt:'. |
|
7682 |
i printOn:aStream. |
|
7683 |
aStream nextPutAll:' put:'. |
|
7684 |
ref storeOn:aStream. |
|
7685 |
aStream nextPut:$;. |
|
7686 |
hasSemi := true |
|
7687 |
] |
|
7688 |
] |
|
5755 | 7689 |
]. |
7690 |
hasSemi ifTrue:[ |
|
19846 | 7691 |
aStream nextPutAll:' yourself' |
5755 | 7692 |
]. |
7693 |
aStream nextPut:$). |
|
7694 |
||
7695 |
" |
|
7696 |
|s| |
|
7697 |
||
7698 |
s := WriteStream on:(String new). |
|
7699 |
('hello' -> 'world') storeOn:s. |
|
7700 |
s := ReadStream on:(s contents). |
|
7701 |
(Object readFrom:s) inspect |
|
7702 |
" |
|
7703 |
" |
|
7704 |
|s| |
|
7705 |
||
7706 |
s := 'data' asFilename writeStream. |
|
7707 |
('hello' -> 'world') storeOn:s. |
|
7708 |
s close. |
|
7709 |
||
7710 |
s := 'data' asFilename readStream. |
|
7711 |
(Object readFrom:s) inspect |
|
7712 |
" |
|
7713 |
||
16590 | 7714 |
"does not work example (cyclic):" |
5755 | 7715 |
" |
7716 |
|s a| |
|
7717 |
||
7718 |
a := Array new:2. |
|
7719 |
a at:1 put:a. |
|
7720 |
||
7721 |
s := 'data' asFilename writeStream. |
|
7722 |
a storeOn:s. |
|
7723 |
s close. |
|
7724 |
||
7725 |
s := 'data' asFilename readStream. |
|
7726 |
(Object readFrom:s) inspect |
|
7727 |
" |
|
7728 |
||
13162 | 7729 |
"Modified: / 03-12-2010 / 13:27:51 / cg" |
5755 | 7730 |
! |
7731 |
||
7732 |
storeString |
|
7733 |
"return a string representing an expression to reconstruct the receiver. |
|
7734 |
Notice, that no self referencing or cyclic objects can be represented |
|
7735 |
in this format. |
|
7736 |
Use storeBinaryOn:, which handles these cases correctly." |
|
7737 |
||
7738 |
|s| |
|
7739 |
||
7740 |
s := WriteStream on:(String new:50). |
|
7741 |
self storeOn:s. |
|
7742 |
^ s contents |
|
13350 | 7743 |
! |
7744 |
||
7745 |
withErrorStreamDo:aBlock |
|
7746 |
"{ Pragma: +optSpace }" |
|
7747 |
||
16560 | 7748 |
"helper for error messages - evaluate aBlock, |
19784 | 7749 |
passing it a stream on which to put error messages. |
7750 |
Notice that the block might be called twice, |
|
7751 |
to print both on stderr and onto the Transcript" |
|
13350 | 7752 |
|
19428 | 7753 |
|stream stderr activeProcess| |
7754 |
||
7755 |
activeProcess := Processor activeProcess. |
|
7756 |
stderr := activeProcess stderr. |
|
19382 | 7757 |
|
16383 | 7758 |
"CG: care for standalone non-GUI progs, which have no userPreferences class" |
7759 |
(Smalltalk isInitialized |
|
7760 |
and:[ UserPreferences notNil |
|
7761 |
and:[ UserPreferences current sendMessagesAlsoToTranscript]]) ifTrue:[ |
|
19428 | 7762 |
stream := activeProcess isSystemProcess |
19784 | 7763 |
ifTrue:[stderr] |
7764 |
ifFalse:[activeProcess transcript]. |
|
16378 | 7765 |
]. |
7766 |
stream notNil ifTrue:[ |
|
19382 | 7767 |
StreamError catch:[ |
7768 |
aBlock value:stream. |
|
7769 |
]. |
|
7770 |
]. |
|
7771 |
stream ~~ stderr ifTrue:[ |
|
19784 | 7772 |
UserPreferences current sendMessagesOnlyToTranscript ifFalse:[ |
7773 |
aBlock value:stderr. |
|
7774 |
]. |
|
13350 | 7775 |
]. |
7776 |
||
7777 |
"Created: / 21-04-2011 / 12:46:21 / cg" |
|
5755 | 7778 |
! ! |
7779 |
||
7780 |
!Object methodsFor:'queries'! |
|
7781 |
||
7782 |
basicSize |
|
19451 | 7783 |
"return the number of the receiver's indexed instance variables, |
5755 | 7784 |
0 if it has none. |
7785 |
||
7786 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
7787 |
||
7788 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
7789 |
#ifdef __SCHTEAM__ |
18404 | 7790 |
return context._RETURN( STInteger._new( self.basicSize() ) ); |
18215 | 7791 |
#else |
8909 | 7792 |
REGISTER INT nbytes; |
5755 | 7793 |
REGISTER OBJ myClass; |
7794 |
int nInstBytes; |
|
7795 |
||
7796 |
/* |
|
7797 |
* notice the missing test for self being a nonNilObject - |
|
7798 |
* this can be done since basicSize is defined both in UndefinedObject |
|
7799 |
* and SmallInteger |
|
7800 |
*/ |
|
7801 |
myClass = __qClass(self); |
|
7802 |
nbytes = __qSize(self); |
|
7803 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) ); |
|
7804 |
||
7805 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
19451 | 7806 |
case __MASKSMALLINT(POINTERARRAY): |
7807 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
7808 |
nbytes -= nInstBytes; |
|
7809 |
RETURN ( __mkSmallInteger(__BYTES2OBJS__(nbytes)) ); |
|
7810 |
||
7811 |
case __MASKSMALLINT(BYTEARRAY): |
|
7812 |
nbytes -= nInstBytes; |
|
7813 |
RETURN ( __mkSmallInteger(nbytes / sizeof(char)) ); |
|
7814 |
||
7815 |
case __MASKSMALLINT(FLOATARRAY): |
|
7816 |
nbytes -= nInstBytes; |
|
7817 |
RETURN ( __mkSmallInteger(nbytes / sizeof(float)) ); |
|
7818 |
||
7819 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
18215 | 7820 |
# ifdef __NEED_DOUBLE_ALIGN |
19451 | 7821 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
18215 | 7822 |
# endif |
19451 | 7823 |
nbytes -= nInstBytes; |
7824 |
RETURN ( __mkSmallInteger(nbytes / sizeof(double)) ); |
|
7825 |
||
7826 |
case __MASKSMALLINT(WORDARRAY): |
|
7827 |
case __MASKSMALLINT(SWORDARRAY): |
|
7828 |
nbytes -= nInstBytes; |
|
7829 |
RETURN ( __mkSmallInteger(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */ |
|
7830 |
||
7831 |
case __MASKSMALLINT(LONGARRAY): |
|
7832 |
case __MASKSMALLINT(SLONGARRAY): |
|
7833 |
nbytes -= nInstBytes; |
|
7834 |
RETURN ( __mkSmallInteger(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */ |
|
7835 |
||
7836 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
7837 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
18215 | 7838 |
# ifdef __NEED_LONGLONG_ALIGN |
19451 | 7839 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
18215 | 7840 |
# endif |
19451 | 7841 |
nbytes -= nInstBytes; |
7842 |
RETURN ( __mkSmallInteger(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */ |
|
5755 | 7843 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
7844 |
#endif /* not __SCHTEAM__ */ |
5755 | 7845 |
%}. |
7846 |
^ 0 |
|
7847 |
! |
|
7848 |
||
7849 |
byteSize |
|
19451 | 7850 |
"return the number of bytes in the receiver's indexed instance variables, |
5755 | 7851 |
0 if it has none. This only returns non-zero for non-pointer indexed |
7852 |
instvars i.e. byteArrays, wordArrays etc. |
|
7853 |
Notice: for Strings the returned size may look strange. |
|
7854 |
Only useful with binary storage." |
|
7855 |
||
7856 |
|myClass| |
|
7857 |
||
7858 |
myClass := self class. |
|
7859 |
myClass isVariable ifTrue:[ |
|
19451 | 7860 |
myClass isPointers ifFalse:[ |
7861 |
myClass isBytes ifTrue:[ |
|
7862 |
^ self basicSize. |
|
7863 |
]. |
|
7864 |
myClass isWords ifTrue:[ |
|
7865 |
^ self basicSize * 2. |
|
7866 |
]. |
|
7867 |
myClass isSignedWords ifTrue:[ |
|
7868 |
^ self basicSize * 2. |
|
7869 |
]. |
|
7870 |
myClass isLongs ifTrue:[ |
|
7871 |
^ self basicSize * 4. |
|
7872 |
]. |
|
7873 |
myClass isSignedLongs ifTrue:[ |
|
7874 |
^ self basicSize * 4. |
|
7875 |
]. |
|
7876 |
myClass isLongLongs ifTrue:[ |
|
7877 |
^ self basicSize * 8. |
|
7878 |
]. |
|
7879 |
myClass isSignedLongLongs ifTrue:[ |
|
7880 |
^ self basicSize * 8. |
|
7881 |
]. |
|
7882 |
myClass isFloats ifTrue:[ |
|
7883 |
^ self basicSize * (ExternalBytes sizeofFloat) |
|
7884 |
]. |
|
7885 |
myClass isDoubles ifTrue:[ |
|
7886 |
^ self basicSize * (ExternalBytes sizeofDouble) |
|
7887 |
]. |
|
7888 |
self error:'unknown variable size class species'. |
|
7889 |
] |
|
5755 | 7890 |
]. |
7891 |
^ 0 |
|
7892 |
||
7893 |
" |
|
10460 | 7894 |
Point new byteSize |
14632 | 7895 |
'hello' byteSize |
7896 |
'hello' asUnicode16String byteSize |
|
10460 | 7897 |
(ByteArray with:1 with:2) byteSize |
7898 |
(FloatArray with:1.5) byteSize |
|
7899 |
(DoubleArray with:1.5) byteSize |
|
7900 |
(WordArray with:1 with:2) byteSize |
|
5755 | 7901 |
" |
7902 |
! |
|
7903 |
||
7904 |
class |
|
19679 | 7905 |
"return the receiver's class" |
5755 | 7906 |
|
7907 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
7908 |
#ifdef __SCHTEAM__ |
18215 | 7909 |
return context._RETURN(self.clazz()); |
7910 |
#else |
|
5755 | 7911 |
RETURN ( __Class(self) ); |
18215 | 7912 |
#endif |
5755 | 7913 |
%} |
19679 | 7914 |
|
7915 |
"Modified (comment): / 30-04-2016 / 15:51:17 / cg" |
|
5755 | 7916 |
! |
7917 |
||
7918 |
respondsTo:aSelector |
|
7919 |
"return true, if the receiver implements a method with selector equal |
|
7920 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
19451 | 7921 |
receiver's class or one of its superclasses. |
5755 | 7922 |
|
7923 |
Notice, that this does not imply, that such a message can be sent without |
|
7924 |
an error being raised. For example, an implementation could send |
|
7925 |
#shouldNotImplement or #subclassResponsibility." |
|
7926 |
||
7927 |
" |
|
7928 |
should we go via the cache, or search (by class) ? |
|
7929 |
The first is faster, most of the time; while the 2nd fills |
|
7930 |
the cache with useless data if this is sent in a loop over all objects. |
|
7931 |
For now, use the cache ... |
|
7932 |
" |
|
7933 |
%{ /* NOCONTEXT */ |
|
7934 |
||
7935 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
19451 | 7936 |
RETURN ( false ); |
5755 | 7937 |
} |
7938 |
RETURN ( true ); |
|
7939 |
%} |
|
7940 |
. |
|
7941 |
^ self class canUnderstand:aSelector |
|
7942 |
||
7943 |
||
7944 |
"'aString' respondsTo:#+" |
|
7945 |
"'aString' respondsTo:#," |
|
7946 |
"'aString' respondsTo:#collect:" |
|
7947 |
! |
|
7948 |
||
7949 |
respondsToArithmetic |
|
7950 |
"return true, if the receiver responds to arithmetic messages. |
|
7951 |
false is returned here - the method is redefined in ArithmeticValue." |
|
7952 |
||
7953 |
^ false |
|
7954 |
! |
|
7955 |
||
7956 |
size |
|
19451 | 7957 |
"return the number of the receiver's indexed instance variables; |
5755 | 7958 |
this method may be redefined in subclasses" |
7959 |
||
7960 |
^ self basicSize |
|
7961 |
! |
|
7962 |
||
7963 |
species |
|
19451 | 7964 |
"return a class which is similar to (or the same as) the receiver's class. |
5755 | 7965 |
This is used to create an appropriate object when creating derived |
7966 |
copies in the collection classes (sometimes redefined)." |
|
7967 |
||
7968 |
^ self class |
|
7969 |
! |
|
7970 |
||
16401 | 7971 |
speciesForCopy |
7972 |
"return a class which is the receiver's class, except for readonly objects, |
|
7973 |
such as immutable collections. |
|
7974 |
This is only to be used by copy methods" |
|
7975 |
||
7976 |
^ self class |
|
7977 |
! |
|
7978 |
||
5755 | 7979 |
yourself |
7980 |
"return the receiver - used for cascades to return self at the end" |
|
7981 |
||
7982 |
^ self |
|
7983 |
! ! |
|
7984 |
||
7985 |
!Object methodsFor:'secure message sending'! |
|
7986 |
||
18215 | 7987 |
?:selector |
13099 | 7988 |
"try to send a message to the receiver; |
7989 |
if understood, return the value; |
|
7990 |
if not, return nil." |
|
18215 | 7991 |
|
13099 | 7992 |
^ self perform:selector ifNotUnderstood:nil |
7993 |
||
7994 |
" |
|
7995 |
ApplicationModel new masterApplication resources first - error |
|
7996 |
ApplicationModel new ?: #masterApplication ?: #resources ?: #first - nil |
|
7997 |
" |
|
7998 |
"Modified: / 20-10-2010 / 10:45:21 / cg" |
|
7999 |
! |
|
8000 |
||
5755 | 8001 |
askFor:aSelector |
8002 |
"try to send the receiver the message, aSelector. |
|
10460 | 8003 |
If it does not understand it, return false. |
5755 | 8004 |
Otherwise the real value returned. |
11398 | 8005 |
Useful to send messages such as: #isColor to unknown receivers." |
5755 | 8006 |
|
8007 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
8008 |
||
8009 |
" |
|
10460 | 8010 |
1 askFor:#isColor |
8011 |
Color red askFor:#isColor |
|
8012 |
||
8013 |
1 askFor:#isFoo |
|
8014 |
Color red askFor:#isFoo |
|
5755 | 8015 |
" |
8016 |
! |
|
8017 |
||
11398 | 8018 |
askFor:aSelector with:argument |
8019 |
"try to send the receiver the message, aSelector. |
|
8020 |
If it does not understand it, return false. |
|
8021 |
Otherwise the real value returned. |
|
8022 |
Useful to send messages such as: #isXXX: to unknown receivers." |
|
8023 |
||
8024 |
^ self perform:aSelector with:argument ifNotUnderstood:[false] |
|
8025 |
! |
|
8026 |
||
11401 | 8027 |
askFor:aSelector with:arg1 with:arg2 |
8028 |
"try to send the receiver the message, aSelector. |
|
8029 |
If it does not understand it, return false. |
|
8030 |
Otherwise the real value returned. |
|
8031 |
Useful to send messages such as: #isXXX: to unknown receivers." |
|
8032 |
||
8033 |
^ self perform:aSelector with:arg1 with:arg2 ifNotUnderstood:[false] |
|
8034 |
! |
|
8035 |
||
5755 | 8036 |
perform:aSelector ifNotUnderstood:exceptionBlock |
8037 |
"try to send message aSelector to the receiver. |
|
12157 | 8038 |
If its understood, return the method's returned value, |
8039 |
otherwise return the value of the exceptionBlock. |
|
8040 |
Read this: |
|
8041 |
Many programmers do an Error-handle to perform a similar |
|
8042 |
checked-message send. However, this method is more specific, |
|
16560 | 8043 |
in that only errors for the given selector are caught - not any other |
12157 | 8044 |
doesNotUnderstand, and especially not any other error." |
5755 | 8045 |
|
8046 |
|val ok| |
|
8047 |
||
6146 | 8048 |
MessageNotUnderstood handle:[:ex | |
19846 | 8049 |
"/ reject, if the bad message is not the one |
8050 |
"/ we have sent originally |
|
8051 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
8052 |
ex reject |
|
8053 |
]. |
|
5755 | 8054 |
] do:[ |
19846 | 8055 |
val := self perform:aSelector. |
8056 |
ok := true. |
|
5755 | 8057 |
]. |
8058 |
ok isNil ifTrue:[ |
|
19846 | 8059 |
^ exceptionBlock value |
5755 | 8060 |
]. |
8061 |
^ val |
|
8062 |
||
8063 |
" |
|
10460 | 8064 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
8065 |
1.2345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
8066 |
12345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
5755 | 8067 |
" |
8068 |
! |
|
8069 |
||
8070 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
8071 |
"try to send message aSelector to the receiver. |
|
12157 | 8072 |
If its understood, return the method's returned value, |
8073 |
otherwise return the value of the exceptionBlock. |
|
8074 |
Read this: |
|
8075 |
Many programmers do an Error-handle to perform a similar |
|
8076 |
checked-message send. However, this method is more specific, |
|
16560 | 8077 |
in that only errors for the given selector are caught - not any other |
12157 | 8078 |
doesNotUnderstand, and especially not any other error." |
5755 | 8079 |
|
8080 |
|val ok| |
|
8081 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8082 |
MessageNotUnderstood handle:[:ex | |
19846 | 8083 |
"/ reject, if the bad message is not the one |
8084 |
"/ we have sent originally |
|
8085 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
8086 |
ex reject |
|
8087 |
] |
|
5755 | 8088 |
] do:[ |
19846 | 8089 |
val := self perform:aSelector with:argument. |
8090 |
ok := true. |
|
5755 | 8091 |
]. |
8092 |
ok isNil ifTrue:[ |
|
19846 | 8093 |
^ exceptionBlock value |
5755 | 8094 |
]. |
8095 |
^ val |
|
8096 |
||
8097 |
" |
|
8098 |
|unknown| |
|
8099 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8100 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8101 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 8102 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8103 |
(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printNewline. |
5755 | 8104 |
" |
8105 |
! |
|
8106 |
||
5926 | 8107 |
perform:aSelector with:arg1 with:arg2 ifNotUnderstood:exceptionBlock |
8108 |
"try to send message aSelector to the receiver. |
|
12157 | 8109 |
If its understood, return the method's returned value, |
8110 |
otherwise return the value of the exceptionBlock. |
|
8111 |
Read this: |
|
8112 |
Many programmers do an Error-handle to perform a similar |
|
8113 |
checked-message send. However, this method is more specific, |
|
16560 | 8114 |
in that only errors for the given selector are caught - not any other |
12157 | 8115 |
doesNotUnderstand, and especially not any other error." |
5926 | 8116 |
|
8117 |
|val ok| |
|
8118 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8119 |
MessageNotUnderstood handle:[:ex | |
19846 | 8120 |
"/ reject, if the bad message is not the one |
8121 |
"/ we have sent originally |
|
8122 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
8123 |
ex reject |
|
8124 |
] |
|
5926 | 8125 |
] do:[ |
19846 | 8126 |
val := self perform:aSelector with:arg1 with:arg2. |
8127 |
ok := true. |
|
5926 | 8128 |
]. |
8129 |
ok isNil ifTrue:[ |
|
19846 | 8130 |
^ exceptionBlock value |
5926 | 8131 |
]. |
8132 |
^ val |
|
8133 |
! |
|
8134 |
||
5755 | 8135 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
8136 |
"try to send message aSelector to the receiver. |
|
12157 | 8137 |
If its understood, return the method's returned value, |
8138 |
otherwise return the value of the exceptionBlock. |
|
8139 |
Read this: |
|
8140 |
Many programmers do an Error-handle to perform a similar |
|
8141 |
checked-message send. However, this method is more specific, |
|
16560 | 8142 |
in that only errors for the given selector are caught - not any other |
12157 | 8143 |
doesNotUnderstand, and especially not any other error." |
5755 | 8144 |
|
8145 |
|val ok| |
|
8146 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8147 |
MessageNotUnderstood handle:[:ex | |
19846 | 8148 |
"/ reject, if the bad message is not the one |
8149 |
"/ we have sent originally. |
|
8150 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
8151 |
ex reject |
|
8152 |
] |
|
5755 | 8153 |
] do:[ |
19846 | 8154 |
val := self perform:aSelector withArguments:argumentArray. |
8155 |
ok := true. |
|
5755 | 8156 |
]. |
8157 |
ok isNil ifTrue:[ |
|
19846 | 8158 |
^ exceptionBlock value |
5755 | 8159 |
]. |
8160 |
^ val |
|
8161 |
||
8162 |
" |
|
8163 |
|unknown| |
|
8164 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8165 |
unknown := 4. |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8166 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 8167 |
unknown := 'high there'. |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8168 |
(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
5755 | 8169 |
" |
8170 |
||
8171 |
"Modified: 27.3.1997 / 14:13:16 / cg" |
|
8172 |
! ! |
|
8173 |
||
8174 |
!Object methodsFor:'signal constants'! |
|
8175 |
||
8176 |
messageNotUnderstoodSignal |
|
6146 | 8177 |
^ MessageNotUnderstood |
5755 | 8178 |
|
8179 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
8180 |
! ! |
|
8181 |
||
8182 |
!Object methodsFor:'special queries'! |
|
8183 |
||
8184 |
allOwners |
|
8185 |
"return a collection of all objects referencing the receiver" |
|
8186 |
||
8187 |
^ ObjectMemory whoReferences:self |
|
8188 |
! |
|
8189 |
||
8190 |
references:anObject |
|
8191 |
"return true, if the receiver refers to the argument, anObject. |
|
8192 |
- for debugging only" |
|
8193 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8194 |
^ self referencesObject:anObject |
5755 | 8195 |
|
8196 |
" |
|
8197 |
|v| |
|
8198 |
||
8199 |
v := View new initialize. |
|
10460 | 8200 |
v references:Display. |
5755 | 8201 |
" |
8202 |
! |
|
8203 |
||
8204 |
referencesAny:aCollection |
|
10460 | 8205 |
"return true, if the receiver refers to any object from |
5755 | 8206 |
the argument, aCollection. |
8207 |
- for debugging only" |
|
8208 |
||
10460 | 8209 |
%{ |
5755 | 8210 |
OBJ cls, flags; |
8211 |
int nInsts, inst; |
|
8212 |
||
8213 |
if (! __isNonNilObject(self)) { |
|
19846 | 8214 |
RETURN (false); |
5755 | 8215 |
} |
8216 |
||
8934 | 8217 |
if (__isArrayLike(aCollection)) { |
19846 | 8218 |
int nObjs = __arraySize(aCollection); |
8219 |
char *minAddr = 0, *maxAddr = 0; |
|
8220 |
||
8221 |
if (nObjs == 0) { |
|
8222 |
RETURN (false); |
|
8223 |
} |
|
8224 |
||
8225 |
cls = __qClass(self); |
|
8226 |
flags = __ClassInstPtr(cls)->c_flags; |
|
8227 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
8228 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
8229 |
} else { |
|
8230 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
8231 |
} |
|
8232 |
||
8233 |
if (nObjs == 1) { |
|
8234 |
/* better reverse the loop */ |
|
8235 |
OBJ anObject = __arrayVal(aCollection)[0]; |
|
8236 |
||
8237 |
if (anObject == cls) { |
|
8238 |
RETURN(true); |
|
8239 |
} |
|
8240 |
if (! nInsts) { |
|
8241 |
RETURN (false); |
|
8242 |
} |
|
8243 |
||
8244 |
if ((__qSpace(self) <= OLDSPACE) |
|
8245 |
&& !__isRemembered(self) |
|
8246 |
&& __isNonNilObject(anObject)) { |
|
8247 |
int spc = __qSpace(anObject); |
|
8248 |
||
8249 |
if ((spc == NEWSPACE) || (spc == SURVSPACE)) { |
|
8250 |
RETURN(false); |
|
8251 |
} |
|
8252 |
} |
|
16325 | 8253 |
|
18231 | 8254 |
# if defined(memsrch4) |
19846 | 8255 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
8256 |
RETURN (true); |
|
8257 |
} |
|
18231 | 8258 |
# else |
19846 | 8259 |
for (inst=0; inst<nInsts; inst++) { |
8260 |
if ((__InstPtr(self)->i_instvars[inst]) == anObject) { |
|
8261 |
RETURN (true); |
|
8262 |
} |
|
8263 |
} |
|
18231 | 8264 |
# endif |
19846 | 8265 |
RETURN (false); |
8266 |
} |
|
8267 |
||
8268 |
/* |
|
8269 |
* a little optimization: use the fact that all old objects |
|
8270 |
* refering to a new object are on the remSet; if I am not, |
|
8271 |
* a trivial reject is possible, if all objects are newbees. |
|
8272 |
* as a side effect, gather min/max addresses |
|
8273 |
*/ |
|
8274 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
8275 |
int allNewBees = 1; |
|
8276 |
int i; |
|
8277 |
||
8278 |
minAddr = (char *)(__arrayVal(aCollection)[0]); |
|
8279 |
maxAddr = minAddr; |
|
8280 |
||
8281 |
for (i=0; i<nObjs; i++) { |
|
8282 |
OBJ anObject = __arrayVal(aCollection)[i]; |
|
8283 |
||
8284 |
if (__isNonNilObject(anObject)) { |
|
8285 |
int spc = __qSpace(anObject); |
|
8286 |
||
8287 |
if ((spc != NEWSPACE) && (spc != SURVSPACE)) { |
|
8288 |
allNewBees = 0; |
|
8289 |
} |
|
8290 |
} |
|
8291 |
||
8292 |
if ((char *)anObject < minAddr) { |
|
8293 |
minAddr = (char *)anObject; |
|
8294 |
} else if ((char *)anObject > maxAddr) { |
|
8295 |
maxAddr = (char *)anObject; |
|
8296 |
} |
|
8297 |
} |
|
8298 |
if (allNewBees) { |
|
8299 |
RETURN (false); |
|
8300 |
} |
|
8301 |
} |
|
8302 |
||
8303 |
/* |
|
8304 |
* fetch min/max in searchList (if not already done above) |
|
8305 |
*/ |
|
8306 |
if (minAddr == 0) { |
|
8307 |
int i; |
|
8308 |
||
8309 |
for (i=0; i<nObjs; i++) { |
|
8310 |
char *anObject = (char *)__arrayVal(aCollection)[i]; |
|
8311 |
||
8312 |
if (anObject < minAddr) { |
|
8313 |
minAddr = anObject; |
|
8314 |
} else if (anObject > maxAddr) { |
|
8315 |
maxAddr = anObject; |
|
8316 |
} |
|
8317 |
} |
|
8318 |
} |
|
8319 |
||
8320 |
if (((char *)cls >= minAddr) && ((char *)cls <= maxAddr)) { |
|
18231 | 8321 |
# if defined(memsrch4) |
19846 | 8322 |
if (memsrch4(__arrayVal(aCollection), (INT)cls, nObjs)) { |
8323 |
RETURN (true); |
|
8324 |
} |
|
18231 | 8325 |
# else |
19846 | 8326 |
int i; |
8327 |
||
8328 |
for (i=0; i<nObjs; i++) { |
|
8329 |
if (cls == __arrayVal(aCollection)[i]) { |
|
8330 |
RETURN (true); |
|
8331 |
} |
|
8332 |
} |
|
18231 | 8333 |
# endif /* memsrch4 */ |
19846 | 8334 |
} |
8335 |
||
8336 |
for (inst=0; inst<nInsts; inst++) { |
|
8337 |
OBJ instVar = __InstPtr(self)->i_instvars[inst]; |
|
8338 |
int i; |
|
8339 |
||
8340 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
18231 | 8341 |
# if defined(memsrch4) |
19846 | 8342 |
if (memsrch4(__arrayVal(aCollection), (INT)instVar, nObjs)) { |
8343 |
RETURN (true); |
|
8344 |
} |
|
18231 | 8345 |
# else |
19846 | 8346 |
for (i=0; i<nObjs; i++) { |
8347 |
if (instVar == __arrayVal(aCollection)[i]) { |
|
8348 |
RETURN (true); |
|
8349 |
} |
|
8350 |
} |
|
18231 | 8351 |
# endif /* memsrch4 */ |
19846 | 8352 |
} |
8353 |
} |
|
8354 |
RETURN (false); |
|
5755 | 8355 |
} |
8356 |
%}. |
|
8357 |
||
8358 |
aCollection do:[:el | |
|
19846 | 8359 |
(self referencesObject:el) ifTrue:[^ true]. |
5755 | 8360 |
]. |
8361 |
^ false |
|
8362 |
! |
|
8363 |
||
8364 |
referencesDerivedInstanceOf:aClass |
|
8365 |
"return true, if the receiver refers to an instance of |
|
8366 |
the argument, aClass or its subclass. This method exists |
|
8367 |
to support searching for users of a class." |
|
8368 |
||
10460 | 8369 |
|myClass |
5755 | 8370 |
numInst "{ Class: SmallInteger }" | |
8371 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8372 |
"check the class" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8373 |
(self isKindOf:aClass) ifTrue:[^ true]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8374 |
|
5755 | 8375 |
myClass := self class. |
8376 |
"check the instance variables" |
|
8377 |
numInst := myClass instSize. |
|
10460 | 8378 |
1 to:numInst do:[:i | |
19846 | 8379 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
5755 | 8380 |
]. |
8381 |
||
8382 |
"check the indexed variables" |
|
8383 |
myClass isVariable ifTrue:[ |
|
19846 | 8384 |
myClass isPointers ifFalse:[ |
8385 |
"no need to search in non pointer fields" |
|
8386 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
|
8387 |
]. |
|
8388 |
numInst := self basicSize. |
|
8389 |
1 to:numInst do:[:i | |
|
8390 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
8391 |
] |
|
5755 | 8392 |
]. |
8393 |
^ false |
|
8394 |
||
8395 |
" |
|
10460 | 8396 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
8397 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
8398 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
5755 | 8399 |
" |
8400 |
! |
|
8401 |
||
9279 | 8402 |
referencesForWhich:checkBlock do:actionBlock |
8403 |
|myClass inst |
|
8404 |
numInst "{ Class: SmallInteger }" | |
|
8405 |
||
8406 |
myClass := self class. |
|
8407 |
"check the instance variables" |
|
8408 |
numInst := myClass instSize. |
|
10460 | 8409 |
1 to:numInst do:[:i | |
19846 | 8410 |
inst := self instVarAt:i. |
8411 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
9279 | 8412 |
]. |
8413 |
||
8414 |
"check the indexed variables" |
|
8415 |
myClass isVariable ifTrue:[ |
|
19846 | 8416 |
myClass isPointers ifTrue:[ |
8417 |
"no need to search in non pointer fields" |
|
8418 |
||
8419 |
numInst := self basicSize. |
|
8420 |
1 to:numInst do:[:i | |
|
8421 |
inst := self basicAt:i. |
|
8422 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
8423 |
] |
|
8424 |
] |
|
10460 | 8425 |
]. |
8426 |
||
8427 |
" |
|
8428 |
(1 @ 3.4) referencesForWhich:[:i | i isFloat] do:[:i | Transcript showCR:i] |
|
9279 | 8429 |
" |
8430 |
! |
|
8431 |
||
5755 | 8432 |
referencesInstanceOf:aClass |
8433 |
"return true, if the receiver refers to an instance of |
|
8434 |
the argument, aClass.This method exists |
|
8435 |
to support searching for users of a class." |
|
8436 |
||
10460 | 8437 |
|myClass |
5755 | 8438 |
numInst "{ Class: SmallInteger }" | |
8439 |
||
8440 |
myClass := self class. |
|
8441 |
||
8442 |
"check the class" |
|
8443 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
8444 |
||
8445 |
"check the instance variables" |
|
8446 |
numInst := myClass instSize. |
|
10460 | 8447 |
1 to:numInst do:[:i | |
19846 | 8448 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
5755 | 8449 |
]. |
8450 |
||
8451 |
"check the indexed variables" |
|
8452 |
myClass isVariable ifTrue:[ |
|
19846 | 8453 |
myClass isPointers ifFalse:[ |
8454 |
"no need to search in non-pointer indexed fields" |
|
8455 |
myClass isLongs ifTrue:[ |
|
8456 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
8457 |
] ifFalse:[ |
|
8458 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
8459 |
^ aClass == SmallInteger |
|
8460 |
] |
|
8461 |
]. |
|
8462 |
numInst := self basicSize. |
|
8463 |
1 to:numInst do:[:i | |
|
8464 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
8465 |
] |
|
5755 | 8466 |
]. |
8467 |
^ false |
|
8468 |
||
8469 |
" |
|
10460 | 8470 |
(1 @ 3.4) referencesInstanceOf:Float |
8471 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
8472 |
View new initialize referencesInstanceOf:(Display class) |
|
5755 | 8473 |
" |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8474 |
! |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8475 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8476 |
referencesObject:anObject |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8477 |
"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
|
8478 |
- for debugging only" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8479 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8480 |
%{ /* NOCONTEXT */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8481 |
OBJ cls, flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8482 |
int nInsts, i; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8483 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8484 |
if (! __isNonNilObject(self)) { |
19846 | 8485 |
RETURN (false); |
16325 | 8486 |
} |
8487 |
cls = __qClass(self); |
|
8488 |
if (cls == anObject) { |
|
19846 | 8489 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8490 |
} |
16325 | 8491 |
flags = __ClassInstPtr(cls)->c_flags; |
8492 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
19846 | 8493 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
16325 | 8494 |
} else { |
19846 | 8495 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
16325 | 8496 |
} |
8497 |
if (! nInsts) { |
|
19846 | 8498 |
RETURN (false); |
16325 | 8499 |
} |
8500 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8501 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8502 |
/* |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8503 |
* 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
|
8504 |
* 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
|
8505 |
* 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
|
8506 |
*/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8507 |
if (__isNonNilObject(anObject)) { |
19846 | 8508 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
8509 |
int spc; |
|
8510 |
||
8511 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
8512 |
RETURN (false); |
|
8513 |
} |
|
8514 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8515 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8516 |
|
18231 | 8517 |
# if defined(memsrch4) |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8518 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
19846 | 8519 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8520 |
} |
18231 | 8521 |
# else |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8522 |
for (i=0; i<nInsts; i++) { |
19846 | 8523 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
8524 |
RETURN (true); |
|
8525 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8526 |
} |
18231 | 8527 |
# endif /* memsrch4 */ |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8528 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8529 |
%}. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8530 |
|
10460 | 8531 |
"/ |myClass |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8532 |
"/ numInst "{ Class: SmallInteger }" | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8533 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8534 |
"/ myClass := self class. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8535 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8536 |
"/ "check the class" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8537 |
"/ (myClass == anObject) ifTrue:[^ true]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8538 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8539 |
"/ "check the instance variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8540 |
"/ numInst := myClass instSize. |
10460 | 8541 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8542 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8543 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8544 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8545 |
"/ "check the indexed variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8546 |
"/ myClass isVariable ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8547 |
"/ myClass isPointers ifFalse:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8548 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8549 |
"/ "/ 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
|
8550 |
"/ "/ 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
|
8551 |
"/ "/ 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
|
8552 |
"/ "/ 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
|
8553 |
"/ "/ 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
|
8554 |
"/ "/ 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
|
8555 |
"/ "/ 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
|
8556 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8557 |
"/ ^ false. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8558 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8559 |
"/ "/ alternative: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8560 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8561 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8562 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8563 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8564 |
"/ "/ 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
|
8565 |
"/ "/ idenitytIndex method, use it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8566 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8567 |
"/ myClass == Array ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8568 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8569 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8570 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8571 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8572 |
"/ "/ otherwise, do it the slow way |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8573 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8574 |
"/ numInst := self basicSize. |
10460 | 8575 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8576 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8577 |
"/ ] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8578 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8579 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8580 |
^ false |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8581 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8582 |
" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8583 |
|v| |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8584 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8585 |
v := View new initialize. |
10460 | 8586 |
v references:Display. |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8587 |
" |
5755 | 8588 |
! ! |
8589 |
||
8590 |
!Object methodsFor:'synchronized evaluation'! |
|
8591 |
||
10460 | 8592 |
freeSynchronizationSemaphore |
5755 | 8593 |
"free synchronizationSemaphore. May be used, to save memory when |
8594 |
an object is no longer used synchronized." |
|
8595 |
||
8596 |
|sema| |
|
8597 |
||
8598 |
sema := self synchronizationSemaphore. |
|
8599 |
sema notNil ifTrue:[ |
|
19846 | 8600 |
sema wait. "/ get lock |
8601 |
self synchronizationSemaphore:nil. |
|
5755 | 8602 |
]. |
8603 |
||
8604 |
" |
|
8605 |
self synchronized:[]. |
|
8606 |
self synchronizationSemaphore. |
|
8607 |
self freeSynchronizationSemaphore. |
|
8608 |
" |
|
8609 |
||
8610 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
8611 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
8612 |
! |
|
8613 |
||
8614 |
synchronizationSemaphore |
|
8615 |
"return the synchronization semaphore for myself. |
|
8616 |
subclasses may redefine" |
|
8617 |
||
8618 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
8619 |
||
8620 |
" |
|
8621 |
self synchronizationSemaphore |
|
8622 |
" |
|
8623 |
||
8624 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
8625 |
! |
|
8626 |
||
8627 |
synchronizationSemaphore:aSemaphore |
|
8628 |
"set the synchronisationSemaphore for myself. |
|
8629 |
subclasses may redefine this method" |
|
8630 |
||
8631 |
aSemaphore isNil ifTrue:[ |
|
19846 | 8632 |
"/ remove Semaphore |
8633 |
SynchronizationSemaphores removeKey:self ifAbsent:nil. |
|
5755 | 8634 |
] ifFalse:[ |
19846 | 8635 |
SynchronizationSemaphores at:self put:aSemaphore. |
5755 | 8636 |
]. |
8637 |
||
8638 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
8639 |
! |
|
8640 |
||
8641 |
synchronized:aBlock |
|
8642 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
8643 |
||
6600 | 8644 |
|sema wasBlocked| |
8645 |
||
8646 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5755 | 8647 |
|
8648 |
sema := self synchronizationSemaphore. |
|
8649 |
sema isNil ifTrue:[ |
|
18799 | 8650 |
sema := RecursionLock new name:self className. |
8651 |
self synchronizationSemaphore:sema. |
|
5755 | 8652 |
]. |
8653 |
||
6600 | 8654 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
18799 | 8655 |
^ sema critical:aBlock. |
5755 | 8656 |
|
8657 |
" |
|
8658 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
8659 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
8660 |
" |
|
8661 |
||
8662 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
8663 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
|
8664 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
|
8665 |
! ! |
|
8666 |
||
8667 |
!Object methodsFor:'system primitives'! |
|
8668 |
||
8669 |
asOop |
|
8670 |
"ST-80 compatibility: |
|
8671 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
8672 |
or index); since ST/X has no such thing, and the objects address cannot |
|
10460 | 8673 |
be used (since its changing over time), we return the objects identityHash |
5755 | 8674 |
key, which provides (at least) some identity indication. |
8675 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
8676 |
key of two non-identical objects may be the same. |
|
8677 |
You'd better not use it - especially do not misuse it." |
|
8678 |
||
8679 |
^ self identityHash |
|
8680 |
||
8681 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
8682 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
8683 |
! |
|
8684 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8685 |
beImmutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8686 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8687 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8688 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8689 |
if (! __isNonNilObject(self)) { |
19846 | 8690 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8691 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8692 |
__beImmutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8693 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8694 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8695 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8696 |
beMutable |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8697 |
"experimental - not yet usable; do not use" |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8698 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8699 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8700 |
if (! __isNonNilObject(self)) { |
19846 | 8701 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8702 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8703 |
__beMutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8704 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8705 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8706 |
|
5755 | 8707 |
become:anotherObject |
8708 |
"make all references to the receiver become references to anotherObject |
|
8709 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
|
8710 |
This can be a very dangerous operation - be warned. |
|
10460 | 8711 |
In general, using #become: should be avoided if possible, since it may |
5755 | 8712 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
8713 |
||
10460 | 8714 |
This may also be an expensive (i.e. slow) operation, |
8715 |
since in the worst case, the whole memory has to be searched for |
|
5755 | 8716 |
references to the two objects (although the primitive tries hard to |
10460 | 8717 |
limit the search, for acceptable performance in most cases). |
8718 |
This method fails, if the receiver or the argument is a SmallInteger |
|
8719 |
or nil, or is a context of a living method (i.e. one that has not already |
|
5755 | 8720 |
returned). |
10460 | 8721 |
(notice that #become: is not used heavily by the system |
5755 | 8722 |
- the Collection-classes have been rewritten to not use it.)" |
8723 |
%{ |
|
8724 |
if (__primBecome(self, anotherObject)) { |
|
19846 | 8725 |
RETURN ( self ); |
5755 | 8726 |
} |
8727 |
%}. |
|
8728 |
self primitiveFailed |
|
8729 |
! |
|
8730 |
||
8731 |
becomeNil |
|
8732 |
"make all references to the receiver become nil - effectively getting |
|
10460 | 8733 |
rid of the receiver. |
5755 | 8734 |
This can be a very dangerous operation - be warned. |
8735 |
||
8736 |
This may be an expensive (i.e. slow) operation. |
|
8737 |
The receiver may not be a SmallInteger or a context of a living method." |
|
8738 |
||
8739 |
%{ |
|
8740 |
if (__primBecomeNil(self)) { |
|
19846 | 8741 |
RETURN ( nil ); |
5755 | 8742 |
} |
8743 |
%}. |
|
8744 |
self primitiveFailed |
|
8745 |
! |
|
8746 |
||
8747 |
becomeSameAs:anotherObject |
|
8748 |
"make all references to the receiver become references to anotherObject |
|
8749 |
but NOT vice versa (as done in #become:). |
|
8750 |
This can be a very dangerous operation - be warned. |
|
10460 | 8751 |
In general, using #become: should be avoided if possible, since it may |
5755 | 8752 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
8753 |
||
8754 |
This may also be an expensive (i.e. slow) operation, |
|
8755 |
since in the worst case, the whole memory has to be searched for |
|
8756 |
references to the two objects (although the primitive tries hard to |
|
8757 |
limit the search, for acceptable performance in most cases). |
|
8758 |
This method fails, if the receiver or the argument is a SmallInteger |
|
8759 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
8760 |
%{ |
|
8761 |
if (__primBecomeSameAs(self, anotherObject)) { |
|
19846 | 8762 |
RETURN ( self ); |
5755 | 8763 |
} |
8764 |
%}. |
|
8765 |
self primitiveFailed |
|
8766 |
! |
|
8767 |
||
8768 |
changeClassTo:otherClass |
|
8769 |
"changes the class of the receiver to the argument, otherClass. |
|
19451 | 8770 |
This is only allowed (possible), if the receiver's class and the argument |
5755 | 8771 |
have the same structure (i.e. number of named instance variables and |
10460 | 8772 |
type of indexed instance variables). |
5755 | 8773 |
If the structures do not match, or any of the original class or new class |
8774 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
8775 |
||
8776 |
|myClass ok| |
|
8777 |
||
9405 | 8778 |
otherClass autoload. |
8779 |
||
5755 | 8780 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
8781 |
%{ |
|
18371 | 8782 |
#ifdef __SCHTEAM__ |
8783 |
ok = (self.isSTInstance() && otherClass.isSTInstance()) |
|
19451 | 8784 |
? STObject.True : STObject.False; |
18371 | 8785 |
#else |
5755 | 8786 |
{ |
19451 | 8787 |
OBJ other = otherClass; |
8788 |
||
8789 |
if (__isNonNilObject(self) |
|
8790 |
&& __isNonNilObject(other) |
|
8791 |
&& (other != UndefinedObject) |
|
8792 |
&& (other != SmallInteger)) { |
|
8793 |
ok = true; |
|
8794 |
} else { |
|
8795 |
ok = false; |
|
8796 |
} |
|
5755 | 8797 |
} |
18371 | 8798 |
#endif /* not SCHTEAM */ |
5755 | 8799 |
%}. |
18231 | 8800 |
ok == true ifTrue:[ |
19451 | 8801 |
ok := false. |
8802 |
myClass := self class. |
|
8803 |
myClass == otherClass ifTrue:[ |
|
8804 |
"nothing to change" |
|
8805 |
^ self. |
|
8806 |
]. |
|
8807 |
myClass flags == otherClass flags ifTrue:[ |
|
8808 |
myClass instSize == otherClass instSize ifTrue:[ |
|
8809 |
"same instance layout and types: its ok to do it" |
|
8810 |
ok := true. |
|
8811 |
] ifFalse:[ |
|
8812 |
myClass isPointers ifTrue:[ |
|
8813 |
myClass isVariable ifTrue:[ |
|
8814 |
ok := true |
|
8815 |
] |
|
8816 |
] |
|
8817 |
] |
|
8818 |
] ifFalse:[ |
|
8819 |
myClass isPointers ifTrue:[ |
|
8820 |
"if newClass is a variable class, with instSize <= my instsize, |
|
8821 |
we can do it (effectively mapping additional instvars into the |
|
8822 |
variable part) - usefulness is questionable, though" |
|
8823 |
||
8824 |
otherClass isPointers ifTrue:[ |
|
8825 |
otherClass isVariable ifTrue:[ |
|
8826 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
8827 |
ifTrue:[ |
|
8828 |
ok := true |
|
8829 |
] |
|
8830 |
] ifFalse:[ |
|
8831 |
otherClass instSize == (myClass instSize + self basicSize) |
|
8832 |
ifTrue:[ |
|
8833 |
ok := true |
|
8834 |
] |
|
8835 |
] |
|
8836 |
] ifFalse:[ |
|
8837 |
"it does not make sense to convert pointers to bytes ..." |
|
8838 |
] |
|
8839 |
] ifFalse:[ |
|
8840 |
"does it make sense, to convert bits ?" |
|
8841 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
8842 |
(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[ |
|
8843 |
ok := true |
|
8844 |
] |
|
8845 |
] |
|
8846 |
] |
|
5755 | 8847 |
]. |
18231 | 8848 |
ok == true ifTrue:[ |
19451 | 8849 |
"now, change the receiver's class ..." |
5755 | 8850 |
%{ |
18371 | 8851 |
#ifdef __SCHTEAM__ |
19451 | 8852 |
((STInstance)self).clazz = (STClass)otherClass; |
8853 |
return __c__._RETURN(self); |
|
18371 | 8854 |
#else |
19451 | 8855 |
{ |
8856 |
OBJ me = self; |
|
8857 |
||
8858 |
// gcc4.4 does not like this: |
|
8859 |
// __qClass(me) = otherClass; |
|
8860 |
__objPtr(me)->o_class = (CLASS_OBJ)otherClass; |
|
8861 |
__STORE(me, otherClass); |
|
8862 |
RETURN (me); |
|
8863 |
} |
|
18371 | 8864 |
#endif /* not SCHTEAM */ |
5755 | 8865 |
%}. |
8866 |
]. |
|
9405 | 8867 |
|
5755 | 8868 |
" |
8869 |
the receiver cannot be represented as a instance of |
|
8870 |
the desired class. |
|
10460 | 8871 |
For example, you cannot change a bitInstance (byteArray etc.) |
5755 | 8872 |
into a pointer object and vice versa. |
8873 |
" |
|
8874 |
self primitiveFailed |
|
8875 |
! |
|
8876 |
||
8877 |
changeClassToThatOf:anObject |
|
8878 |
"changes the class of the receiver to that of the argument, anObject. |
|
19451 | 8879 |
This is only allowed (possible), if the receiver's class and the arguments |
10460 | 8880 |
class have the same structure (i.e. number of named instance variables and |
5755 | 8881 |
type of indexed instance variables). If the structures do not match, or any |
8882 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
8883 |
||
8884 |
self changeClassTo:(anObject class) |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8885 |
! |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8886 |
|
8935 | 8887 |
isImmutable |
8888 |
"experimental - not yet usable; do not use" |
|
8889 |
||
8890 |
%{ /* NOCONTEXT */ |
|
8891 |
if (! __isNonNilObject(self)) { |
|
19646 | 8892 |
RETURN (true); |
8935 | 8893 |
} |
19646 | 8894 |
if (__isImmutable(self)) { |
8895 |
RETURN (true); |
|
8896 |
} |
|
8897 |
%}. |
|
8898 |
^ false |
|
8935 | 8899 |
! |
8900 |
||
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8901 |
replaceReferencesTo:anObject with:newRef |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8902 |
"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
|
8903 |
Return true, if any reference was changed. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8904 |
Notice: this does not change the class-reference." |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8905 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8906 |
%{ /* NOCONTEXT */ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8907 |
OBJ cls, flags, anyChange; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8908 |
int nInsts, i; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8909 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8910 |
if (! __isNonNilObject(self)) { |
19846 | 8911 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8912 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8913 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8914 |
/* |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8915 |
* a little optimization: use the fact that all old objects |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8916 |
* 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
|
8917 |
* a trivial reject is possible, if anObject is a newbee |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8918 |
*/ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8919 |
if (__isNonNilObject(anObject)) { |
19846 | 8920 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
8921 |
int spc; |
|
8922 |
||
8923 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
8924 |
RETURN (false); |
|
8925 |
} |
|
8926 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8927 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8928 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8929 |
cls = __qClass(self); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8930 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8931 |
flags = __ClassInstPtr(cls)->c_flags; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8932 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
19846 | 8933 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8934 |
} else { |
19846 | 8935 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8936 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8937 |
if (! nInsts) { |
19846 | 8938 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8939 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8940 |
anyChange = false; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8941 |
for (i=0; i<nInsts; i++) { |
19846 | 8942 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
8943 |
__InstPtr(self)->i_instvars[i] = newRef; |
|
8944 |
__STORE(self, newRef); |
|
8945 |
// __dumpObject__(self, __LINE__); |
|
8946 |
anyChange = true; |
|
8947 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8948 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8949 |
RETURN (anyChange); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8950 |
%}. |
18231 | 8951 |
self primitiveFailed |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8952 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8953 |
" |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8954 |
|v| |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8955 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8956 |
v := Array with:1234 with:'hello' with:Array. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8957 |
v replaceReferencesTo:Array with:ByteArray. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8958 |
v inspect |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
8959 |
" |
15586 | 8960 |
|
8961 |
"Modified: / 30-07-2013 / 21:48:06 / cg" |
|
5755 | 8962 |
! ! |
8963 |
||
8964 |
!Object methodsFor:'testing'! |
|
8965 |
||
8966 |
? defaultValue |
|
11634 | 8967 |
"a syntactic sugar-piece: |
5755 | 8968 |
if the receiver is nil, return the defaultValue; |
8969 |
otherwise, return the receiver. |
|
8970 |
This method is only redefined in UndefinedObject - therefore, |
|
19451 | 8971 |
the receiver is retuned here. |
5755 | 8972 |
|
8973 |
Thus, if foo and bar are simple variables or constants, |
|
19451 | 8974 |
foo ? bar |
5755 | 8975 |
is the same as: |
19451 | 8976 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
5755 | 8977 |
|
8978 |
if they are message sends, the equivalent code is: |
|
19451 | 8979 |
[ |
8980 |
|t1 t2| |
|
8981 |
||
8982 |
t1 := foo. |
|
8983 |
t2 := bar. |
|
8984 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
8985 |
] value |
|
5755 | 8986 |
|
8987 |
Can be used to provide defaultValues to variables, |
|
8988 |
as in: |
|
19451 | 8989 |
foo := arg ? #defaultValue |
5755 | 8990 |
|
8991 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
8992 |
Notice: |
|
19451 | 8993 |
This method is open coded (inlined) by the compiler(s) |
8994 |
- redefining it may not work as expected." |
|
5755 | 8995 |
|
8996 |
^ self |
|
8997 |
||
8998 |
" |
|
8999 |
1 ? #default |
|
9000 |
nil ? #default |
|
9001 |
" |
|
9002 |
||
9003 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
9004 |
"Modified: / 19.5.1998 / 17:39:56 / cg" |
|
9005 |
! |
|
9006 |
||
16126 | 9007 |
?+ aOneArgBlock |
9008 |
"a syntactic sugar-piece: |
|
9009 |
aOneArgBlock is executed with self as argument |
|
9010 |
if self is not nil. |
|
9011 |
||
9012 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
9013 |
" |
|
9014 |
||
9015 |
^ aOneArgBlock value:self |
|
9016 |
||
9017 |
" |
|
9018 |
1 ?+ [:v| v + 5] |
|
9019 |
nil ?+ [:v| v + 5] |
|
9020 |
" |
|
9021 |
! |
|
9022 |
||
5755 | 9023 |
?? defaultValue |
11634 | 9024 |
"a syntactic sugar-piece: |
5755 | 9025 |
much like ?, but sends #value to the argument if required. |
15758 | 9026 |
(i.e. it's the same as #ifNil:) |
5755 | 9027 |
If the receiver is nil, return the defaultValues value; |
9028 |
otherwise, return the receiver. |
|
9029 |
This method is only redefined in UndefinedObject - therefore, |
|
15758 | 9030 |
the receiver is retuned here. |
5755 | 9031 |
|
9032 |
Thus, if foo and bar are simple variables or constants, |
|
19846 | 9033 |
foo ?? bar |
5755 | 9034 |
is the same as: |
19846 | 9035 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
5755 | 9036 |
|
9037 |
if they are message sends, the equivalent code is: |
|
19846 | 9038 |
[ |
9039 |
|t t2| |
|
9040 |
||
9041 |
t := foo. |
|
9042 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
9043 |
] value |
|
5755 | 9044 |
|
9045 |
Can be used to provide defaultValues to variables, |
|
9046 |
as in: |
|
19846 | 9047 |
foo := arg ?? [ self computeDefault ] |
5755 | 9048 |
|
9049 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
9050 |
" |
|
9051 |
||
9052 |
^ self |
|
9053 |
||
9054 |
" |
|
10460 | 9055 |
1 ?? #default |
5755 | 9056 |
nil ?? #default |
10460 | 9057 |
1 ?? [ self halt. 1 + 2 ] |
9058 |
nil ?? [ self halt. 1 + 2 ] |
|
9059 |
1 ?? [Date today] |
|
9060 |
nil ?? [Date today] |
|
5755 | 9061 |
" |
9062 |
||
9063 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
9064 |
"Modified: / 19.5.1998 / 17:42:56 / cg" |
|
9065 |
! |
|
9066 |
||
9067 |
ifNil:aBlockOrValue |
|
9068 |
"return myself, or the result from evaluating the argument, if I am nil. |
|
9069 |
This is much like #?, but sends #value to the argument in case of a nil |
|
9070 |
receiver. |
|
9071 |
Notice: |
|
19846 | 9072 |
This method is open coded (inlined) by the compiler(s) |
9073 |
- redefining it may not work as expected." |
|
5755 | 9074 |
|
9075 |
^ self |
|
9076 |
! |
|
9077 |
||
9078 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
|
9079 |
"return the value of the first arg, if I am nil, |
|
9080 |
the result from evaluating the 2nd argument, if I am not nil. |
|
9081 |
Notice: |
|
19846 | 9082 |
This method is open coded (inlined) by the compiler(s) |
9083 |
- redefining it may not work as expected." |
|
18440 | 9084 |
|
9085 |
(notNilBlockOrValue isBlock and:[notNilBlockOrValue argumentCount == 1]) ifTrue:[ |
|
19846 | 9086 |
^ notNilBlockOrValue value:self. |
15501 | 9087 |
]. |
5755 | 9088 |
^ notNilBlockOrValue value |
9089 |
! |
|
9090 |
||
9091 |
ifNotNil:aBlockOrValue |
|
10460 | 9092 |
"return myself if nil, or the result from evaluating the argument, |
5755 | 9093 |
if I am not nil. |
9094 |
Notice: |
|
19846 | 9095 |
This method is open coded (inlined) by the compiler(s) |
9096 |
- redefining it may not work as expected." |
|
18440 | 9097 |
|
9098 |
(aBlockOrValue isBlock and:[aBlockOrValue argumentCount == 1]) ifTrue:[ |
|
19846 | 9099 |
^ aBlockOrValue value:self. |
15501 | 9100 |
]. |
5755 | 9101 |
^ aBlockOrValue value |
9102 |
! |
|
9103 |
||
9104 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
|
9105 |
"return the value of the 2nd arg, if I am nil, |
|
9106 |
the result from evaluating the 1st argument, if I am not nil. |
|
9107 |
Notice: |
|
19846 | 9108 |
This method is open coded (inlined) by the compiler(s) |
9109 |
- redefining it may not work as expected." |
|
18440 | 9110 |
|
9111 |
(notNilBlockOrValue isBlock and:[notNilBlockOrValue argumentCount == 1]) ifTrue:[ |
|
19846 | 9112 |
^ notNilBlockOrValue value:self. |
15501 | 9113 |
]. |
5755 | 9114 |
^ notNilBlockOrValue value |
9115 |
! |
|
9116 |
||
8574 | 9117 |
ifNotNilDo:aBlock |
9118 |
"if the reciever is non-nil, return the value of aBlock, passing myself as argument. |
|
9119 |
Otherwise do nothing and return nil." |
|
9120 |
||
9121 |
^ aBlock value:self |
|
9122 |
! |
|
9123 |
||
5755 | 9124 |
isArray |
9125 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
9126 |
false is returned here - the method is only redefined in Array." |
|
9127 |
||
9128 |
^ false |
|
9129 |
! |
|
9130 |
||
9131 |
isAssociation |
|
9132 |
"return true, if the receiver is some kind of association; |
|
9133 |
false is returned here - the method is only redefined in Association." |
|
9134 |
||
9135 |
^ false |
|
9136 |
||
9137 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
9138 |
! |
|
9139 |
||
9140 |
isBehavior |
|
18352 | 9141 |
"return true, if the receiver is describing another object's behavior. |
9221 | 9142 |
False is returned here - the method is only redefined in Behavior." |
5755 | 9143 |
|
9144 |
^ false |
|
9145 |
! |
|
9146 |
||
9147 |
isBlock |
|
9148 |
"return true, if the receiver is some kind of block; |
|
9149 |
false returned here - the method is only redefined in Block." |
|
9150 |
||
9151 |
^ false |
|
9152 |
! |
|
9153 |
||
5824 | 9154 |
isBoolean |
9155 |
"return true, if the receiver is a boolean; |
|
9156 |
false is returned here - the method is only redefined in Boolean." |
|
9157 |
||
9158 |
^ false |
|
9159 |
! |
|
9160 |
||
5755 | 9161 |
isByteArray |
9162 |
"return true, if the receiver is some kind of bytearray; |
|
9163 |
false is returned here - the method is only redefined in ByteArray." |
|
9164 |
||
9165 |
^ false |
|
9166 |
! |
|
9167 |
||
8986 | 9168 |
isByteCollection |
9169 |
"return true, if the receiver is some kind of byte collection, |
|
10460 | 9170 |
i.e. #at: and #at:put: accesses a byte. This is different from 'self class isBytes', |
8986 | 9171 |
since e.g. in BitArray single bits are accessed, but it is implemented as variableBytes class. |
10460 | 9172 |
|
8986 | 9173 |
false is returned here - the method is only redefined in UninterpretedBytes." |
9174 |
||
9175 |
^ false |
|
9176 |
! |
|
9177 |
||
5755 | 9178 |
isCharacter |
9179 |
"return true, if the receiver is some kind of character; |
|
9180 |
false is returned here - the method is only redefined in Character." |
|
9181 |
||
9182 |
^ false |
|
9183 |
! |
|
9184 |
||
9185 |
isClass |
|
9405 | 9186 |
"return true, if the receiver is some kind of class |
9187 |
(real class, not just behavior); |
|
5755 | 9188 |
false is returned here - the method is only redefined in Class." |
9189 |
||
9190 |
^ false |
|
9191 |
! |
|
9192 |
||
9193 |
isCollection |
|
9194 |
"return true, if the receiver is some kind of collection; |
|
9195 |
false is returned here - the method is only redefined in Collection." |
|
9196 |
||
9197 |
^ false |
|
9198 |
! |
|
9199 |
||
9200 |
isColor |
|
9201 |
"return true, if the receiver is some kind of color; |
|
9202 |
false is returned here - the method is only redefined in Color." |
|
9203 |
||
9204 |
^ false |
|
9205 |
! |
|
9206 |
||
6567 | 9207 |
isCons |
9208 |
"return true, if the receiver is a cons (pair); |
|
9209 |
false is returned here - the method is only redefined in Cons." |
|
9210 |
||
9211 |
^ false |
|
9212 |
! |
|
9213 |
||
5755 | 9214 |
isContext |
15362 | 9215 |
"return true, if the receiver is some kind of Context; |
5755 | 9216 |
false returned here - the method is only redefined in Context." |
9217 |
||
9218 |
^ false |
|
9219 |
! |
|
9220 |
||
15362 | 9221 |
isDictionary |
9222 |
"return true, if the receiver is some kind of dictionary; |
|
9223 |
false returned here - the method is only redefined in Dictionary." |
|
9224 |
||
9225 |
^ false |
|
9226 |
! |
|
9227 |
||
6181 | 9228 |
isEmptyOrNil |
8833 | 9229 |
"return true if I am nil or an empty collection - return false here. |
9230 |
(from Squeak)" |
|
6181 | 9231 |
|
9232 |
^ false |
|
9233 |
||
9234 |
"Created: / 13.11.2001 / 13:17:04 / cg" |
|
6182 | 9235 |
"Modified: / 13.11.2001 / 13:28:40 / cg" |
6181 | 9236 |
! |
9237 |
||
6221 | 9238 |
isException |
15362 | 9239 |
"answer true, if this is an Exception" |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9240 |
|
6221 | 9241 |
^ false |
9242 |
||
9243 |
"Created: / 17.11.2001 / 18:37:44 / cg" |
|
9244 |
! |
|
9245 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9246 |
isExceptionCreator |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9247 |
"return true, if the receiver can create exceptions, |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9248 |
this includes #raise, #raiseRequest as well as the behavior of |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9249 |
an exception handler, such as the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9250 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9251 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9252 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9253 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9254 |
isExceptionHandler |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9255 |
"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
|
9256 |
especially to the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9257 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9258 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9259 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9260 |
|
13187 | 9261 |
isExternalAddress |
9262 |
"return true, if the receiver is some kind of externalAddress; |
|
9263 |
false is returned here - the method is only redefined in ExternalAddress." |
|
9264 |
||
9265 |
^ false |
|
9266 |
||
9267 |
"Created: / 22-12-2010 / 17:20:36 / cg" |
|
9268 |
! |
|
9269 |
||
14079 | 9270 |
isExternalBytes |
9271 |
^ false |
|
9272 |
! |
|
9273 |
||
10480 | 9274 |
isExternalLibraryFunction |
9275 |
"return true, if the receiver is some kind of externalLibrary function; |
|
9276 |
false is returned here - the method is only redefined in ExternalLibraryFunction." |
|
9277 |
||
9278 |
^false |
|
9279 |
! |
|
9280 |
||
5755 | 9281 |
isExternalStream |
9282 |
"return true, if the receiver is some kind of externalStream; |
|
9283 |
false is returned here - the method is only redefined in ExternalStream." |
|
9284 |
||
9285 |
^false |
|
9286 |
! |
|
9287 |
||
19550 | 9288 |
isExternalStructure |
9289 |
^ false |
|
9290 |
! |
|
9291 |
||
5755 | 9292 |
isFileStream |
9293 |
"return true, if the receiver is some kind of fileStream; |
|
9294 |
false is returned here - the method is only redefined in FileStream." |
|
9295 |
||
9296 |
^false |
|
9297 |
! |
|
9298 |
||
9299 |
isFilename |
|
9300 |
"return true, if the receiver is some kind of filename; |
|
9301 |
false is returned here - the method is only redefined in Filename." |
|
9302 |
||
9303 |
^false |
|
9304 |
! |
|
9305 |
||
9306 |
isFixedPoint |
|
9307 |
"return true, if the receiver is some kind of fixedPoint number; |
|
9308 |
false is returned here - the method is only redefined in FixedPoint." |
|
9309 |
||
9310 |
^ false |
|
9311 |
||
9312 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
9313 |
! |
|
9314 |
||
9315 |
isFixedSize |
|
10460 | 9316 |
"return true if the receiver cannot grow easily |
5755 | 9317 |
(i.e. a grow may be expensive, since it involves a become:)" |
9318 |
||
9319 |
^ true |
|
9320 |
! |
|
9321 |
||
6185 | 9322 |
isFloat |
9323 |
"return true, if the receiver is some kind of floating point number; |
|
9324 |
false is returned here. |
|
9325 |
Same as #isLimitedPrecisionReal, but a better name ;-)" |
|
9326 |
||
9327 |
^ false |
|
9328 |
||
9329 |
"Modified: / 14.11.2001 / 14:57:46 / cg" |
|
9330 |
! |
|
9331 |
||
5755 | 9332 |
isForm |
9333 |
"return true, if the receiver is some kind of form; |
|
9334 |
false is returned here - the method is only redefined in Form." |
|
9335 |
||
9336 |
^ false |
|
9337 |
! |
|
9338 |
||
9339 |
isFraction |
|
9340 |
"return true, if the receiver is some kind of fraction; |
|
9341 |
false is returned here - the method is only redefined in Fraction." |
|
9342 |
||
9343 |
^ false |
|
9344 |
! |
|
9345 |
||
9293 | 9346 |
isHierarchicalItem |
9347 |
"used to decide if the parent is a hierarchical item or the model" |
|
9348 |
||
9349 |
^ false |
|
9350 |
! |
|
9351 |
||
5755 | 9352 |
isImage |
9353 |
"return true, if the receiver is some kind of image; |
|
9354 |
false is returned here - the method is only redefined in Image." |
|
9355 |
||
9356 |
^ false |
|
9357 |
! |
|
9358 |
||
9359 |
isImageOrForm |
|
9360 |
"return true, if the receiver is some kind of image or form; |
|
9361 |
false is returned here - the method is only redefined in Image and Form." |
|
9362 |
||
9363 |
^ false |
|
9364 |
! |
|
9365 |
||
9366 |
isImmediate |
|
9367 |
"return true if I am an immediate object |
|
9368 |
i.e. I am represented in the pointer itself and |
|
9369 |
no real object header/storage is used me. |
|
9370 |
(currently, only SmallIntegers, some characters and nil return true)" |
|
9371 |
||
9372 |
^ self class hasImmediateInstances |
|
9373 |
||
9374 |
"Created: 3.6.1997 / 12:00:18 / cg" |
|
9375 |
! |
|
9376 |
||
9377 |
isInteger |
|
9378 |
"return true, if the receiver is some kind of integer number; |
|
9379 |
false is returned here - the method is only redefined in Integer." |
|
9380 |
||
9381 |
^ false |
|
9382 |
! |
|
9383 |
||
9279 | 9384 |
isInterestConverter |
9385 |
"return true if I am a kind of interest forwarder" |
|
9386 |
||
9387 |
^ false |
|
9388 |
! |
|
9389 |
||
10576 | 9390 |
isInternalByteStream |
9391 |
"return true, if the receiver is some kind of Stream for reading bytes; |
|
9392 |
false is returned here - the method is only redefined in PeekableStream." |
|
9393 |
||
9394 |
^false |
|
9395 |
||
9396 |
"Created: / 30-05-2007 / 16:15:33 / cg" |
|
9397 |
! |
|
9398 |
||
5755 | 9399 |
isJavaClass |
9400 |
"return true, if this is a javaClass. |
|
9401 |
false is returned here - the method is only redefined in JavaClass." |
|
9402 |
||
9403 |
^ false |
|
9404 |
||
9405 |
"Created: / 26.3.1997 / 13:34:54 / cg" |
|
9406 |
"Modified: / 8.5.1998 / 21:25:21 / cg" |
|
9407 |
! |
|
9408 |
||
9409 |
isJavaClassRef |
|
9410 |
"return true, if this is a JavaClassRef. |
|
9411 |
false is returned here - the method is only redefined in JavaClassRef." |
|
9412 |
||
9413 |
^ false |
|
9414 |
||
9415 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
9416 |
"Created: / 24.12.1999 / 01:46:28 / cg" |
|
9417 |
! |
|
9418 |
||
9419 |
isJavaContext |
|
9420 |
"return true, if this is a javaContext. |
|
9421 |
false is returned here - the method is only redefined in JavaContext." |
|
9422 |
||
9423 |
^ false |
|
9424 |
||
9425 |
"Created: / 8.5.1998 / 21:24:27 / cg" |
|
9426 |
"Modified: / 8.5.1998 / 21:25:35 / cg" |
|
9427 |
! |
|
9428 |
||
9429 |
isJavaMethod |
|
9430 |
"return true, if this is a JavaMethod. |
|
9431 |
false is returned here - the method is only redefined in JavaMethod." |
|
9432 |
||
9433 |
^ false |
|
9434 |
||
9435 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
9436 |
"Created: / 25.9.1999 / 23:26:12 / cg" |
|
9437 |
! |
|
9438 |
||
9439 |
isJavaMethodRef |
|
9440 |
"return true, if this is a JavaMethodRef. |
|
9441 |
false is returned here - the method is only redefined in JavaMethodRef." |
|
9442 |
||
9443 |
^ false |
|
9444 |
||
9445 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
9446 |
"Created: / 23.12.1999 / 19:44:51 / cg" |
|
9447 |
! |
|
9448 |
||
9449 |
isJavaObject |
|
9450 |
"return true, if this is a javaObject. |
|
9451 |
false is returned here - the method is only redefined in JavaObject." |
|
9452 |
||
9453 |
^ false |
|
9454 |
||
9455 |
"Created: / 26.3.1997 / 13:34:48 / cg" |
|
9456 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
9457 |
! |
|
9458 |
||
9459 |
isJavaScriptClass |
|
9460 |
"return true, if this is a javaScriptClass. |
|
9461 |
false is returned here - the method is only redefined in JavaScriptClass." |
|
9462 |
||
9463 |
^ false |
|
9464 |
! |
|
9465 |
||
8935 | 9466 |
isJavaScriptMetaclass |
9467 |
"return true, if this is a javaScript Metaclass. |
|
9468 |
false is returned here - the method is only redefined in JavaScriptMetaclass." |
|
9469 |
||
9470 |
^ false |
|
9471 |
! |
|
9472 |
||
5755 | 9473 |
isKindOf:aClass |
9474 |
"return true, if the receiver is an instance of aClass or one of its |
|
9475 |
subclasses, false otherwise. |
|
10460 | 9476 |
Advice: |
19846 | 9477 |
use of this to check objects for certain attributes/protocol should |
9478 |
be avoided; it limits the reusability of your classes by limiting use |
|
9479 |
to instances of certain classes and fences you into a specific inheritance |
|
9480 |
hierarchy. |
|
9481 |
Use check-methods to check an object for a certain attributes/protocol |
|
9482 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
9483 |
||
9484 |
Using #isKindOf: is considered BAD STYLE. |
|
5755 | 9485 |
|
9486 |
Advice2: |
|
19846 | 9487 |
Be aware, that using an #isXXX method is usually much faster than |
9488 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
9489 |
hierarchy, comparing every class on the way. |
|
9490 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
9491 |
a single function call. |
|
5755 | 9492 |
" |
9493 |
||
9494 |
%{ /* NOCONTEXT */ |
|
9495 |
register OBJ thisClass; |
|
9496 |
||
9497 |
thisClass = __Class(self); |
|
9498 |
while (thisClass != nil) { |
|
19846 | 9499 |
if (thisClass == aClass) { |
9500 |
RETURN ( true ); |
|
9501 |
} |
|
9502 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
5755 | 9503 |
} |
9504 |
RETURN ( false ); |
|
9505 |
%} |
|
9506 |
||
9507 |
"/ |
|
9508 |
"/ the above code is equivalent to: |
|
9509 |
"/ |
|
9510 |
"/ thisClass := self class. |
|
9511 |
"/ [thisClass notNil] whileTrue:[ |
|
9512 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
9513 |
"/ thisClass := thisClass superclass |
|
9514 |
"/ ]. |
|
9515 |
"/ ^ false |
|
9516 |
"/ |
|
9517 |
! |
|
9518 |
||
17168 | 9519 |
isLabelAndIcon |
9520 |
"return true, if the receiver is a labelAndIcon; |
|
9521 |
false is returned here - the method is only redefined in LabelAndIcon." |
|
9522 |
||
9523 |
^ false |
|
9524 |
! |
|
9525 |
||
5755 | 9526 |
isLayout |
9527 |
"return true, if the receiver is some kind of layout; |
|
9528 |
false is returned here - the method is only redefined in Layout." |
|
9529 |
||
9530 |
^ false |
|
9531 |
! |
|
9532 |
||
6567 | 9533 |
isLazyValue |
9534 |
^ false |
|
9535 |
! |
|
9536 |
||
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9537 |
isLimitedPrecisionReal |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9538 |
"return true, if the receiver is some kind of floating point number; |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9539 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9540 |
|
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9541 |
^ false |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9542 |
! |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9543 |
|
5755 | 9544 |
isList |
9545 |
"return true, if the receiver is some kind of list collection; |
|
9546 |
false is returned here - the method is only redefined in List." |
|
9547 |
||
9548 |
^ false |
|
9549 |
||
9550 |
"Created: / 11.2.2000 / 01:37:05 / cg" |
|
9551 |
! |
|
9552 |
||
9553 |
isLiteral |
|
9554 |
"return true, if the receiver can be represented as a literal constant in ST syntax; |
|
9555 |
false is returned here - the method is redefined in some classes." |
|
9556 |
||
9557 |
^ false |
|
9558 |
! |
|
9559 |
||
9560 |
isMemberOf:aClass |
|
9561 |
"return true, if the receiver is an instance of aClass, false otherwise. |
|
10460 | 9562 |
Advice: |
19846 | 9563 |
use of this to check objects for certain attributes/protocol should |
9564 |
be avoided; it limits the reusability of your classes by limiting use |
|
9565 |
to instances of a certain class. |
|
9566 |
Use check-methods to check an object for a certain attributes/protocol |
|
9567 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
9568 |
||
9569 |
Using #isMemberOf: is considered BAD STYLE. |
|
5755 | 9570 |
Notice: |
19846 | 9571 |
This method is open coded (inlined) by the compiler(s) |
9572 |
- redefining it may not work as expected." |
|
5755 | 9573 |
|
9574 |
^ (self class) == aClass |
|
9575 |
! |
|
9576 |
||
18319 | 9577 |
isMenuItem |
9578 |
"return true, if the receiver is a menu item inside a MenuPanel, Menu or PopUpmenu. |
|
9579 |
false is returned here - the method is redefined in some classes." |
|
9580 |
||
9581 |
^ false |
|
9582 |
! |
|
9583 |
||
5755 | 9584 |
isMeta |
9585 |
"return true, if the receiver is some kind of metaclass; |
|
9586 |
false is returned here - the method is only redefined in Metaclass." |
|
9587 |
||
9588 |
^ false |
|
9589 |
! |
|
9590 |
||
9591 |
isMethod |
|
9592 |
"return true, if the receiver is some kind of method; |
|
16021 | 9593 |
false returned here - this method is only redefined in Method." |
5755 | 9594 |
|
9595 |
^ false |
|
9596 |
! |
|
9597 |
||
9598 |
isMorph |
|
9599 |
"return true, if the receiver is some kind of morph; |
|
9600 |
false is returned here - the method is only redefined in Morph." |
|
9601 |
||
9602 |
^ false |
|
9603 |
! |
|
9604 |
||
9605 |
isNameSpace |
|
9221 | 9606 |
"return true, if the receiver is a nameSpace. |
9607 |
False is returned here - the method is only redefined in Namespace." |
|
5755 | 9608 |
|
9609 |
^ false |
|
9610 |
||
9611 |
"Created: / 11.10.1996 / 18:08:56 / cg" |
|
9612 |
"Modified: / 8.5.1998 / 21:26:05 / cg" |
|
9613 |
! |
|
9614 |
||
9615 |
isNamespace |
|
9616 |
"return true, if this is a nameSpace. |
|
9617 |
false is returned here - the method is only redefined in Namespace." |
|
9618 |
||
5869 | 9619 |
<resource:#obsolete> |
9620 |
||
5755 | 9621 |
self obsoleteMethodWarning:'use #isNameSpace'. |
6805 | 9622 |
^ self isNameSpace |
5755 | 9623 |
! |
9624 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9625 |
isNil |
9221 | 9626 |
"Return true, if the receiver is nil. |
9627 |
Because isNil is redefined in UndefinedObject, |
|
9628 |
the receiver is definitely not nil here, so unconditionally return false. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9629 |
Notice: |
19846 | 9630 |
This method is open coded (inlined) by the compiler(s) |
9631 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9632 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9633 |
^ false |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9634 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9635 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9636 |
isNilOrEmptyCollection |
6182 | 9637 |
"return true if I am nil or an empty collection - false here. |
8833 | 9638 |
Obsolete, use isEmptyOrNil." |
9639 |
||
9640 |
<resource:#obsolete> |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9641 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9642 |
^ false |
6182 | 9643 |
|
9644 |
"Modified: / 13.11.2001 / 13:28:06 / cg" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9645 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9646 |
|
9005 | 9647 |
isNonByteCollection |
9648 |
"return true, if the receiver is some kind of collection, but not a String, ByteArray etc.; |
|
9649 |
false is returned here - the method is redefined in Collection and UninterpretedBytes." |
|
9650 |
||
9651 |
^ false |
|
9652 |
||
9653 |
" |
|
19846 | 9654 |
21 isNonByteCollection |
9655 |
'abc' isNonByteCollection |
|
9656 |
#'abc' isNonByteCollection |
|
9657 |
#[1 2 3] isNonByteCollection |
|
9658 |
#(1 2 3) isNonByteCollection |
|
9005 | 9659 |
" |
9660 |
! |
|
9661 |
||
16907
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9662 |
isNotNil |
19781 | 9663 |
<resource: #obsolete> |
9664 |
||
16907
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9665 |
"Return true, if the receiver not nil. |
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9666 |
Because isNotNil is redefined in UndefinedObject, |
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9667 |
the receiver is definitely not nil here, so unconditionally return true." |
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9668 |
|
19781 | 9669 |
self obsoleteMethodWarning:'use #notNil'. |
16907
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9670 |
^ true |
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9671 |
|
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9672 |
"Created: / 26-10-2014 / 01:30:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9673 |
! |
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9674 |
|
5755 | 9675 |
isNumber |
9676 |
"return true, if the receiver is some kind of number; |
|
9677 |
false is returned here - the method is only redefined in Number." |
|
9678 |
||
9679 |
^ false |
|
9680 |
! |
|
9681 |
||
9682 |
isOrderedCollection |
|
9683 |
"return true, if the receiver is some kind of ordered collection (or list etc); |
|
9684 |
false is returned here - the method is only redefined in OrderedCollection." |
|
9685 |
||
9686 |
^ false |
|
9687 |
! |
|
9688 |
||
16342 | 9689 |
isOsHandle |
9690 |
^ false |
|
9691 |
! |
|
9692 |
||
18894 | 9693 |
isPlainString |
9694 |
"return true, if the receiver is a plain string - without attributes; |
|
9695 |
false is returned here - the method is redefined in CharacterArray and Text." |
|
9696 |
||
9697 |
^ false |
|
9698 |
! |
|
9699 |
||
5755 | 9700 |
isPoint |
9701 |
"return true, if the receiver is some kind of point; |
|
9702 |
false is returned here - the method is only redefined in Point." |
|
9703 |
||
9704 |
^ false |
|
9705 |
! |
|
9706 |
||
10532 | 9707 |
isPrinterContext |
9708 |
||
9709 |
^false |
|
9710 |
! |
|
9711 |
||
13416 | 9712 |
isProgrammingLanguage |
9713 |
"return true, if the receiver is a programming language. |
|
14632 | 9714 |
False is returned here - the method is only redefined in |
13416 | 9715 |
ProgrammingLanguage." |
9716 |
||
9717 |
^ false |
|
9718 |
||
9719 |
"Created: / 21-07-2010 / 15:13:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
9720 |
! |
|
9721 |
||
9515 | 9722 |
isProjectDefinition |
9723 |
"return true, if the receiver is a projectDefinition. |
|
9724 |
False is returned here - the method is only redefined in ProjectDefinition." |
|
9725 |
||
9726 |
^ false |
|
9727 |
||
9728 |
"Created: / 10-08-2006 / 16:24:53 / cg" |
|
9729 |
! |
|
9730 |
||
13140 | 9731 |
isProxy |
9732 |
"return true, if the receiver is a proxy for another (lazy loaded) object. |
|
9733 |
False is returned here." |
|
9734 |
||
9735 |
^ false |
|
9736 |
||
9737 |
"Created: / 21-11-2010 / 11:15:46 / cg" |
|
9738 |
! |
|
9739 |
||
10171 | 9740 |
isRealNameSpace |
15439 | 9741 |
"return true, if the receiver is a nameSpace, but not Smalltalk (which is also a class). |
9742 |
False is returned here - the method is redefined in Namespace and Smalltalk." |
|
10171 | 9743 |
|
9744 |
^ false |
|
9745 |
||
9746 |
"Created: / 10-11-2006 / 17:05:43 / cg" |
|
9747 |
! |
|
9748 |
||
5755 | 9749 |
isRectangle |
9750 |
"return true, if the receiver is some kind of rectangle; |
|
9751 |
false is returned here - the method is only redefined in Rectangle." |
|
9752 |
||
9753 |
^ false |
|
9754 |
! |
|
9755 |
||
9756 |
isRemoteObject |
|
9757 |
"return true, if the receiver is some kind of remoteObject, |
|
9758 |
false if its local - the method is only redefined in RemoteObject." |
|
9759 |
||
9760 |
^ false |
|
9761 |
||
9762 |
"Created: 28.10.1996 / 15:18:45 / cg" |
|
9763 |
"Modified: 28.10.1996 / 15:20:57 / cg" |
|
9764 |
! |
|
9765 |
||
9766 |
isSequenceable |
|
9767 |
"return true, if the receiver is some kind of sequenceable collection; |
|
9768 |
false is returned here - the method is only redefined in SequenceableCollection." |
|
9769 |
||
9770 |
^ false |
|
9771 |
! |
|
9772 |
||
9773 |
isSequenceableCollection |
|
9774 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
9775 |
This method is a historic leftover and will be removed soon ... |
|
9776 |
(although its name is much better than #isSequenceable - sigh)" |
|
9777 |
||
5869 | 9778 |
<resource:#obsolete> |
9779 |
||
5755 | 9780 |
self obsoleteMethodWarning:'use #isSequenceable'. |
17365 | 9781 |
^ self isSequenceable |
5755 | 9782 |
! |
9783 |
||
10856 | 9784 |
isSharedPool |
9785 |
"return true, if the receiver is a sharedPool. |
|
9786 |
False is returned here - the method is only redefined in SharedPool." |
|
9787 |
||
9788 |
^ false |
|
9789 |
! |
|
9790 |
||
16770 | 9791 |
isSingleByteString |
9792 |
"return true, if the receiver is a string or immutableString. |
|
16772 | 9793 |
false is returned here - the method is only redefined in String. |
9794 |
Must replace foo isMemberOf:String and foo class == String" |
|
16770 | 9795 |
|
9796 |
^ false |
|
9797 |
! |
|
9798 |
||
15514 | 9799 |
isSocketAddress |
9800 |
^ false |
|
9801 |
! |
|
9802 |
||
13565
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9803 |
isSpecialInstrumentationInfoLiteral |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9804 |
"return true, if the receiver is a special instrumentation info |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9805 |
object as placed into the literal array of instrumented methods" |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9806 |
|
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9807 |
^ false |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9808 |
|
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9809 |
"Created: / 07-08-2011 / 17:03:41 / cg" |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9810 |
! |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9811 |
|
5755 | 9812 |
isStream |
9813 |
"return true, if the receiver is some kind of stream; |
|
9814 |
false is returned here - the method is only redefined in Stream." |
|
9815 |
||
9816 |
^ false |
|
9817 |
! |
|
9818 |
||
9819 |
isString |
|
9820 |
"return true, if the receiver is some kind of string; |
|
9821 |
false is returned here - the method is only redefined in CharacterArray." |
|
9822 |
||
9823 |
^ false |
|
9824 |
! |
|
9825 |
||
9826 |
isStringCollection |
|
9827 |
"return true, if the receiver is some kind of stringCollection; |
|
9828 |
false is returned here - the method is only redefined in StringCollection." |
|
9829 |
||
9830 |
^ false |
|
9831 |
! |
|
9832 |
||
9833 |
isSymbol |
|
9834 |
"return true, if the receiver is some kind of symbol; |
|
9835 |
false is returned here - the method is only redefined in Symbol." |
|
9836 |
||
9837 |
^ false |
|
9838 |
! |
|
9839 |
||
9840 |
isText |
|
9841 |
"return true, if the receiver is some kind of text object; |
|
9842 |
false is returned here - the method is only redefined in Text." |
|
9843 |
||
9844 |
^ false |
|
9845 |
||
9846 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
9847 |
! |
|
9848 |
||
13656 | 9849 |
isTextView |
9850 |
"return true, if the receiver is some kind of textView; |
|
9851 |
false is returned here - the method is only redefined in TextViews." |
|
9852 |
||
9853 |
^ false |
|
9854 |
||
9855 |
"Modified (comment): / 08-09-2011 / 05:12:37 / cg" |
|
9856 |
! |
|
9857 |
||
16349 | 9858 |
isTimeDuration |
9859 |
"return true, if the receiver is some kind of time duration; |
|
9860 |
false is returned here - the method is only redefined in TimeDuration." |
|
9861 |
||
9862 |
^ false |
|
9863 |
! |
|
9864 |
||
13229 | 9865 |
isTimestamp |
16349 | 9866 |
"return true, if the receiver is some kind of time duration; |
9867 |
false is returned here - the method is only redefined in Timestamp." |
|
9868 |
||
13229 | 9869 |
^ false |
9870 |
! |
|
9871 |
||
13626 | 9872 |
isTrait |
9873 |
"Return true if the receiver is a trait. |
|
9874 |
Note: Do not override in any class except TraitBehavior." |
|
9875 |
||
9876 |
^ false |
|
9877 |
||
9878 |
"Created: / 04-09-2011 / 20:04:43 / cg" |
|
9879 |
! |
|
9880 |
||
14296 | 9881 |
isUUID |
16349 | 9882 |
"Return true if the receiver is a uuid. |
9883 |
Note: Do not override in any class except UUID." |
|
9884 |
||
14296 | 9885 |
^ false |
9886 |
! |
|
9887 |
||
5755 | 9888 |
isValueModel |
9889 |
"return true, if the receiver is some kind of valueModel; |
|
9890 |
false is returned here - the method is only redefined in ValueModel." |
|
9891 |
||
9892 |
^ false |
|
9893 |
||
9894 |
! |
|
9895 |
||
9896 |
isVariable |
|
9897 |
"return true if the receiver has indexed instance variables, |
|
9898 |
false otherwise." |
|
9899 |
||
9900 |
^ self class isVariable |
|
9901 |
! |
|
9902 |
||
9903 |
isVariableBinding |
|
9904 |
"return true, if this is a binding for a variable. |
|
9905 |
false is returned here - the method is only redefined in Binding." |
|
9906 |
||
9907 |
^ false |
|
9908 |
||
9909 |
"Created: / 19.6.1997 / 17:38:44 / cg" |
|
9910 |
"Modified: / 8.5.1998 / 21:26:55 / cg" |
|
9911 |
! |
|
9912 |
||
9913 |
isView |
|
9914 |
"return true, if the receiver is some kind of view; |
|
9915 |
false is returned here - the method is only redefined in View." |
|
9916 |
||
9917 |
^ false |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9918 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9919 |
|
15943 | 9920 |
isViewBackground |
9921 |
"return false here; to be redefined in subclass(es)" |
|
9922 |
||
9923 |
^ false |
|
9924 |
! |
|
9925 |
||
18802 | 9926 |
isWeakCollection |
9927 |
"return true, if the receiver has weak references to its elements." |
|
9928 |
||
9929 |
^ false |
|
9930 |
! |
|
9931 |
||
6932 | 9932 |
notEmptyOrNil |
9933 |
"Squeak compatibility: |
|
9934 |
return true if I am neither nil nor an empty collection. |
|
9935 |
Return true here." |
|
9936 |
||
9937 |
^ true |
|
9938 |
! |
|
9939 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9940 |
notNil |
9221 | 9941 |
"Return true, if the receiver is not nil. |
9942 |
Because notNil is redefined in UndefinedObject, |
|
9943 |
the receiver is definitely not nil here, so unconditionally return true. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9944 |
Notice: |
19846 | 9945 |
This method is open coded (inlined) by the compiler(s) |
9946 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9947 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9948 |
^ true |
5755 | 9949 |
! ! |
9950 |
||
9951 |
!Object methodsFor:'tracing'! |
|
9952 |
||
9953 |
traceInto:aRequestor level:level from:referrer |
|
9954 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
9955 |
||
9956 |
^ aRequestor traceObject:self level:level from:referrer |
|
9957 |
||
9958 |
"Created: / 2.9.1999 / 09:05:17 / stefan" |
|
9959 |
! ! |
|
9960 |
||
9961 |
!Object methodsFor:'user interaction & notifications'! |
|
9962 |
||
9963 |
activityNotification:aString |
|
9964 |
"this can be sent from deeply nested methods, which are going to perform |
|
9965 |
some long-time activity. |
|
9966 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
9967 |
passing the argument. The handler should show this message whereever it likes, |
|
9968 |
and proceed. If there is no handler, this is simply ignored. |
|
9969 |
||
9970 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
9971 |
which likes to display that message in its label or a busy-box. |
|
9972 |
It could also be put into some logfile or printed on the standard output/error." |
|
9973 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
9974 |
ActivityNotification isHandled ifTrue:[ |
19846 | 9975 |
^ ActivityNotification raiseRequestWith:self errorString:aString |
5755 | 9976 |
]. |
9977 |
||
9978 |
" |
|
9979 |
nil activityNotification:'hello there' |
|
9980 |
self activityNotification:'hello there' |
|
9981 |
" |
|
9982 |
||
9983 |
" |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
9984 |
ActivityNotification handle:[:ex | |
19846 | 9985 |
ex errorString printCR. |
9986 |
ex proceed. |
|
5755 | 9987 |
] do:[ |
19846 | 9988 |
'hello' printCR. |
9989 |
self activityNotification:'doing some long time computation'. |
|
9990 |
'world' printCR. |
|
5755 | 9991 |
] |
9992 |
" |
|
9993 |
||
9994 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
9995 |
! |
|
9996 |
||
9997 |
confirm:aString |
|
9694 | 9998 |
"open a modal yes-no dialog. |
9999 |
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
|
10000 |
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
|
10001 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10002 |
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
|
10003 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10004 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10005 |
^ UserConfirmation raiseRequestErrorString:aString |
10460 | 10006 |
|
5755 | 10007 |
" |
10008 |
nil confirm:'hello' |
|
10009 |
self confirm:'hello' |
|
10010 |
" |
|
10011 |
! |
|
10012 |
||
10013 |
confirm:aString orCancel:cancelBlock |
|
10014 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
10015 |
return true for yes, false for no, or the value from cancelBlock for cancel. |
|
10016 |
If no GUI is present (headless applications), cancelBlock is returned." |
|
10017 |
||
10018 |
|answer| |
|
10019 |
||
10020 |
answer := self confirmWithCancel:aString. |
|
10021 |
answer isNil ifTrue:[ |
|
19846 | 10022 |
^ cancelBlock value |
5755 | 10023 |
]. |
10024 |
^ answer |
|
10460 | 10025 |
|
5755 | 10026 |
" |
10027 |
self confirm:'hello' orCancel:[self halt] |
|
10028 |
" |
|
10029 |
||
10030 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
10031 |
! |
|
10032 |
||
10033 |
confirmWithCancel:aString |
|
10034 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
10035 |
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
|
10036 |
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
|
10037 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10038 |
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
|
10039 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10040 |
|
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10041 |
^ self confirmWithCancel:aString defaultAnswer:nil |
10460 | 10042 |
|
10043 |
" |
|
10044 |
nil confirmWithCancel:'hello' |
|
5755 | 10045 |
self confirmWithCancel:'hello' |
10046 |
" |
|
10047 |
! |
|
10048 |
||
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10049 |
confirmWithCancel:aString defaultAnswer:defaultAnswerOrNil |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10050 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10051 |
return true for yes, false for no, nil for cancel. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10052 |
If no GUI is present (headless applications), nil is returned. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10053 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10054 |
Someone in the sender chain may redefine the confirmation handler |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10055 |
by handling the UserConfirmation." |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10056 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10057 |
^ UserConfirmation new |
19846 | 10058 |
defaultAnswer:defaultAnswerOrNil; |
10059 |
canCancel:true; |
|
10060 |
errorString:aString; |
|
10061 |
raiseRequest |
|
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10062 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10063 |
" |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10064 |
nil confirmWithCancel:'hello' defaultAnswer:true |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10065 |
self confirmWithCancel:'hello' defaultAnswer:false |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10066 |
" |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10067 |
! |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10068 |
|
5755 | 10069 |
errorNotify:aString |
10070 |
"launch a Notifier, showing top stack, telling user something |
|
10071 |
and give user a chance to enter debugger." |
|
10072 |
||
10073 |
^ self |
|
19846 | 10074 |
errorNotify:aString |
10075 |
from:thisContext sender |
|
10076 |
allowDebug:true |
|
10077 |
mayProceed:true |
|
5755 | 10078 |
|
10079 |
" |
|
10080 |
nil errorNotify:'hello there' |
|
10081 |
self errorNotify:'hello there' |
|
10082 |
" |
|
10083 |
||
6199 | 10084 |
"Modified: / 16.11.2001 / 15:36:49 / cg" |
5755 | 10085 |
! |
10086 |
||
10087 |
errorNotify:aString from:aContext |
|
10460 | 10088 |
"launch a Notifier, showing top stack (above aContext), |
5755 | 10089 |
telling user something and give user a chance to enter debugger." |
10090 |
||
15255 | 10091 |
^ self errorNotify:aString from:aContext allowDebug:true mayProceed:true |
5755 | 10092 |
|
10093 |
"Modified: / 17.8.1998 / 10:09:27 / cg" |
|
10094 |
! |
|
10095 |
||
10096 |
errorNotify:aString from:aContext allowDebug:allowDebug |
|
10460 | 10097 |
"launch a Notifier, showing top stack (above aContext), |
15255 | 10098 |
telling user something and give user a chance to enter debugger." |
10099 |
||
10100 |
^ self errorNotify:aString from:aContext allowDebug:allowDebug mayProceed:true |
|
10101 |
! |
|
10102 |
||
10103 |
errorNotify:aString from:aContext allowDebug:allowDebug mayProceed:mayProceed |
|
10104 |
"launch a Notifier, showing top stack (above aContext), |
|
5755 | 10105 |
telling user something and optionally give the user a chance to enter debugger." |
10106 |
||
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
10107 |
|currentScreen con sender action boxLabels boxValues default s| |
5755 | 10108 |
|
10109 |
Smalltalk isInitialized ifFalse:[ |
|
19846 | 10110 |
'errorNotification: ' print. aString printCR. |
10111 |
con := aContext ? thisContext methodHome. |
|
10112 |
con sender printAllLevels:10. |
|
10113 |
^ nil |
|
10460 | 10114 |
]. |
11531 | 10115 |
|
10460 | 10116 |
(Dialog isNil |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
10117 |
or:[Screen isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
10118 |
or:[(currentScreen := Screen current) isNil |
10460 | 10119 |
or:[currentScreen isOpen not]]]) ifTrue:[ |
19846 | 10120 |
" |
10121 |
on systems without GUI, simply show |
|
10122 |
the message on the Transcript and abort. |
|
10123 |
" |
|
10124 |
Transcript showCR:aString. |
|
10125 |
AbortOperationRequest raise. |
|
10126 |
"not reached" |
|
10127 |
^ nil |
|
5755 | 10128 |
]. |
10129 |
||
10130 |
Processor activeProcessIsSystemProcess ifTrue:[ |
|
19846 | 10131 |
action := #debug. |
10132 |
sender := aContext. |
|
10133 |
Debugger isNil ifTrue:[ |
|
10134 |
'****************** Caught Error while in SystemProcess ****************' errorPrintCR. |
|
10135 |
aString errorPrintCR. |
|
10136 |
Exception handle:[:ex | |
|
10137 |
'Caught recursive error while printing backtrace:' errorPrintCR. |
|
10138 |
ex description errorPrintCR. |
|
10139 |
] do:[ |
|
10140 |
thisContext fullPrintAll. |
|
10141 |
]. |
|
10142 |
action := #abort. |
|
10143 |
]. |
|
5755 | 10144 |
] ifFalse:[ |
19846 | 10145 |
Dialog autoload. "in case it's autoloaded" |
10146 |
||
10147 |
Error handle:[:ex | |
|
10148 |
"/ a recursive error - quickly enter debugger |
|
10149 |
"/ this happened, when I corrupted the Dialog class ... |
|
10150 |
('Object [error]: ' , ex description , ' caught in errorNotification') errorPrintCR. |
|
10151 |
action := #debug. |
|
10152 |
ex return. |
|
10153 |
] do:[ |s| |
|
10154 |
sender := aContext. |
|
10155 |
sender isNil ifTrue:[ |
|
10156 |
sender := thisContext methodHome sender. |
|
10157 |
]. |
|
10158 |
con := sender. |
|
10159 |
||
10160 |
"/ skip intermediate (signal & exception) contexts |
|
10161 |
DebugView notNil ifTrue:[ |
|
10162 |
con := DebugView interestingContextFrom:sender |
|
10163 |
]. |
|
10164 |
||
10165 |
"/ show the first few contexts |
|
10166 |
||
10167 |
s := CharacterWriteStream with:aString. |
|
10168 |
s cr; cr. |
|
10169 |
s nextPutLine:'Calling Chain:'. |
|
10170 |
s nextPutLine:'--------------------------------------------------------------'. |
|
10171 |
1 to:25 do:[:n | |
|
10172 |
con notNil ifTrue:[ |
|
10173 |
con printOn:s. |
|
10174 |
s cr. |
|
10175 |
con := con sender |
|
10176 |
] |
|
10177 |
]. |
|
10178 |
||
10179 |
mayProceed ifTrue:[ |
|
10180 |
boxLabels := #('Proceed'). |
|
10181 |
boxValues := #(#proceed). |
|
10182 |
default := #proceed. |
|
10183 |
] ifFalse:[ |
|
10184 |
boxLabels := #(). |
|
10185 |
boxValues := #(). |
|
10186 |
]. |
|
10187 |
||
10188 |
AbortOperationRequest isHandled ifTrue:[ |
|
10189 |
default := #abort. |
|
10190 |
boxLabels := boxLabels , #('Abort'). |
|
10191 |
boxValues := boxValues , #(#abort). |
|
10192 |
AbortAllOperationRequest isHandled ifTrue:[ |
|
10193 |
boxLabels := boxLabels , #('Abort All'). |
|
10194 |
boxValues := boxValues , #(#abortAll). |
|
10195 |
]. |
|
10196 |
true "allowDebug" ifTrue:[ |
|
10197 |
boxLabels := boxLabels , #('Copy Trace and Abort'). |
|
10198 |
boxValues := boxValues , #(#copyAndAbort). |
|
10199 |
]. |
|
10200 |
] ifFalse:[ |
|
10201 |
mayProceed "and:[allowDebug]" ifTrue:[ |
|
10202 |
boxLabels := boxLabels , #('Copy Trace and Proceed'). |
|
10203 |
boxValues := boxValues , #(#copyAndProceed). |
|
10204 |
]. |
|
10205 |
]. |
|
10206 |
||
10207 |
(allowDebug and:[Debugger notNil]) ifTrue:[ |
|
10208 |
boxLabels := boxLabels , #('Debug'). |
|
10209 |
boxValues := boxValues , #(#debug). |
|
10210 |
default := #debug. |
|
10211 |
]. |
|
10212 |
||
10213 |
action := Dialog |
|
10214 |
choose:s contents |
|
10215 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
|
10216 |
image:WarningBox errorIconBitmap |
|
10217 |
labels:boxLabels |
|
10218 |
values:boxValues |
|
10219 |
default:default |
|
10220 |
onCancel:nil. |
|
10221 |
]. |
|
5755 | 10222 |
]. |
10223 |
||
10224 |
action == #debug ifTrue:[ |
|
19846 | 10225 |
^ Debugger enter:sender withMessage:aString mayProceed:mayProceed |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
10226 |
]. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
10227 |
action == #proceed ifTrue:[ |
19846 | 10228 |
^ nil. |
11335 | 10229 |
]. |
10230 |
(action == #copyAndProceed |
|
10231 |
or:[action == #copyAndAbort]) ifTrue:[ |
|
19846 | 10232 |
s := '' writeStream. |
10233 |
Exception handle:[:ex | |
|
10234 |
'Caught recursive error while printing backtrace' errorPrintCR. |
|
10235 |
] do:[ |
|
10236 |
sender fullPrintAllOn:s. |
|
10237 |
]. |
|
10238 |
currentScreen rootView setClipboardText:s contents. |
|
10239 |
action == #copyAndProceed ifTrue:[ |
|
10240 |
^ nil |
|
10241 |
]. |
|
17306 | 10242 |
]. |
10243 |
(action == #abortAll) ifTrue:[ |
|
19846 | 10244 |
AbortAllOperationRequest raise |
18215 | 10245 |
]. |
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
10246 |
|
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
10247 |
AbortOperationRequest raise. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
10248 |
"not reached" |
5755 | 10249 |
|
10250 |
" |
|
10251 |
nil errorNotify:'hello there' |
|
10252 |
self errorNotify:'hello there' |
|
10253 |
" |
|
10254 |
||
13165
66a6b37405d1
changed: #errorNotify:from:allowDebug:
Claus Gittinger <cg@exept.de>
parents:
13162
diff
changeset
|
10255 |
"Created: / 17-08-1998 / 10:09:26 / cg" |
13566 | 10256 |
"Modified: / 08-08-2011 / 11:26:17 / sr" |
13844
f03a655457f4
changed: #errorNotify:from:allowDebug:
Claus Gittinger <cg@exept.de>
parents:
13812
diff
changeset
|
10257 |
"Modified: / 05-12-2011 / 03:50:59 / cg" |
5755 | 10258 |
! |
10259 |
||
10260 |
information:aString |
|
10460 | 10261 |
"launch an InfoBox, telling user something. |
10262 |
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
|
10263 |
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
|
10264 |
Use #notify: for more important messages. |
8371 | 10265 |
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
|
10266 |
pops up an info dialog." |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10267 |
|
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
10268 |
UserInformation raiseRequestWith:self errorString:aString |
5755 | 10269 |
|
10270 |
" |
|
10271 |
nil information:'hello there' |
|
10272 |
self information:'hello there' |
|
10273 |
" |
|
10274 |
||
10275 |
" |
|
10276 |
InformationSignal handle:[:ex | |
|
19846 | 10277 |
'no box popped' printCR. |
10278 |
ex proceed. |
|
5755 | 10279 |
] do:[ |
19846 | 10280 |
'hello' printCR. |
10281 |
self information:'some info'. |
|
10282 |
'world' printCR. |
|
5755 | 10283 |
] |
10284 |
" |
|
10285 |
||
10286 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
10287 |
! |
|
10288 |
||
10289 |
notify:aString |
|
10290 |
"launch a Notifier, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10291 |
Use #information: for ignorable messages. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10292 |
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
|
10293 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10294 |
|
5755 | 10295 |
|
10296 |
Smalltalk isInitialized ifFalse:[ |
|
19846 | 10297 |
"/ thisContext fullPrintAll. |
10298 |
'information: ' print. aString printCR. |
|
10299 |
^ self |
|
5755 | 10300 |
]. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10301 |
UserNotification raiseRequestWith:self errorString:aString. |
5755 | 10302 |
|
10303 |
" |
|
10304 |
nil notify:'hello there' |
|
10305 |
self notify:'hello there' |
|
10306 |
" |
|
10307 |
||
10308 |
"Modified: 20.5.1996 / 10:28:48 / cg" |
|
10309 |
! |
|
10310 |
||
10311 |
warn:aString |
|
10312 |
"launch a WarningBox, telling user something. |
|
10460 | 10313 |
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
|
10314 |
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
|
10315 |
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
|
10316 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10317 |
|
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10318 |
Warning raiseRequestWith:self errorString:aString |
5755 | 10319 |
|
10320 |
" |
|
10321 |
nil warn:'hello there' |
|
10322 |
self warn:'hello there' |
|
10323 |
" |
|
10324 |
||
10325 |
" |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10326 |
Warning handle:[:ex | |
19846 | 10327 |
Transcript showCR:ex description. |
10328 |
ex proceed. |
|
5755 | 10329 |
] do:[ |
19846 | 10330 |
'hello' printCR. |
10331 |
self warn:'some info'. |
|
10332 |
'world' printCR. |
|
5755 | 10333 |
] |
10334 |
" |
|
10335 |
||
10336 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
|
10337 |
! ! |
|
10338 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10339 |
!Object methodsFor:'visiting'! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10340 |
|
8426 | 10341 |
acceptVisitor:aVisitor |
10342 |
"double-dispatch onto a Visitor." |
|
10343 |
||
10344 |
^ self acceptVisitor:aVisitor with:nil |
|
10345 |
! |
|
10346 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10347 |
acceptVisitor:aVisitor with:aParameter |
16732 | 10348 |
"double-dispatch via visitObject:with: into a Visitor. |
10349 |
Subclasses redefine this to pass their type in the message name (i.e. visitXXX:)" |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10350 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10351 |
^ aVisitor visitObject:self with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10352 |
! ! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10353 |
|
5755 | 10354 |
!Object class methodsFor:'documentation'! |
1 | 10355 |
|
14056
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
10356 |
version |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18440
diff
changeset
|
10357 |
^ '$Header$' |
14056
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
10358 |
! |
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
10359 |
|
12050 | 10360 |
version_CVS |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18440
diff
changeset
|
10361 |
^ '$Header$' |
13416 | 10362 |
! |
10363 |
||
10364 |
version_SVN |
|
15243 | 10365 |
^ '$ Id: Object.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
1 | 10366 |
! ! |
6764 | 10367 |
|
14661 | 10368 |
|
5755 | 10369 |
Object initialize! |