author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 15:21:18 +0200 | |
changeset 24377 | 2fbcb2fa6c43 |
parent 21530 | 655a47664154 |
child 24389 | 3ec8fdee7d8e |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
362 | 3 |
All Rights Reserved |
1 | 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 |
" |
|
5591 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17523 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1 | 16 |
Object subclass:#Message |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
17 |
instanceVariableNames:'selector args' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
18 |
classVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
19 |
poolDictionaries:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
20 |
category:'Kernel-Methods' |
1 | 21 |
! |
22 |
||
88 | 23 |
!Message class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
362 | 28 |
All Rights Reserved |
1 | 29 |
|
88 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
1 | 38 |
|
88 | 39 |
documentation |
40 |
" |
|
17523 | 41 |
Instances of Message represent a message being sent, consisting of |
42 |
the message selector and the message arguments. |
|
43 |
||
1268 | 44 |
During normal execution, message objects are NEVER used - |
45 |
instead, argument passing is done more performant via the stack |
|
46 |
or in registers (depends on how your C compiler passes arguments). |
|
47 |
||
48 |
However, messageObjects ARE created, when a message send fails |
|
88 | 49 |
(i.e. some message is not understood). |
17523 | 50 |
In this case, the selector and arguments of the failing message |
1268 | 51 |
are squashed into a new instance of Message, and a #doesNotUnderstand: |
52 |
message is sent to the original receiver, passing the message object |
|
53 |
as argument. |
|
88 | 54 |
|
17523 | 55 |
Typically, #doesNotUnderstand: is not redefined in the receiver's class, |
56 |
so the lookup finds Object>>doesNotUnderstand: and this is evaluated. |
|
57 |
There, a debugger is opened on the suspended thread (actually, it is a little |
|
58 |
more complicated: actually a MessageNotUnderstood exception is raised there, |
|
59 |
which - if not handled by an exception handler - opens the debugger). |
|
60 |
||
61 |
However, it is possible and common to redefine the doesNotUnderstand method, |
|
62 |
which allows for re-evaluation of the failed send (after some cleanup), |
|
63 |
to upload some code, to forward the message to another destination, |
|
64 |
or to simply ignore the error. |
|
93 | 65 |
|
66 |
As an example of its use, see the implementation of the Autoload-class, |
|
67 |
or how ScrollableView forwards unknown messages to its slave-view. |
|
68 |
||
17523 | 69 |
Elegance hint: as mentioned above, Object>>doesNotUnderstand: actually |
70 |
raises an exception which can be handled. In many situations, providing |
|
71 |
an exception handler instead of redefining #doesNotUnderstand is the |
|
72 |
better way to do things. |
|
1268 | 73 |
|
74 |
||
93 | 75 |
Notice: |
17523 | 76 |
The layout of Message-objects is known by the runtime system (VM) |
1268 | 77 |
(it has to create those objects in case of a failure) |
17523 | 78 |
so it is not allowed to change the definition of this class. |
1268 | 79 |
|
80 |
[See also:] |
|
81 |
Signal Exception MessageSend |
|
1293 | 82 |
|
83 |
[author:] |
|
84 |
Claus Gittinger |
|
88 | 85 |
" |
86 |
! ! |
|
1 | 87 |
|
88 |
!Message class methodsFor:'instance creation'! |
|
89 |
||
90 |
selector:aSymbol |
|
91 |
"return a new message object for a send without arguments" |
|
92 |
||
159 | 93 |
^ self basicNew setSelector:aSymbol arguments:nil |
1 | 94 |
! |
95 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
96 |
selector:aSymbol argument:anArg |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
97 |
"return a new message object for a send with one argument" |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
98 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
99 |
^ self basicNew setSelector:aSymbol arguments:(Array with:anArg) |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
100 |
! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
101 |
|
5751 | 102 |
selector:aSymbol argument:arg1 argument:arg2 |
103 |
"return a new message object for a send with two arguments" |
|
104 |
||
105 |
^ self basicNew setSelector:aSymbol arguments:(Array with:arg1 with:arg2) |
|
106 |
! |
|
107 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
108 |
selector:aSymbol arguments:argArray |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
109 |
"return a new message object for a send with many arguments" |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
110 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
111 |
^ self basicNew setSelector:aSymbol arguments:argArray |
8323 | 112 |
! ! |
113 |
||
114 |
!Message class methodsFor:'obsolete'! |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
115 |
|
1 | 116 |
selector:aSymbol with:anArg |
159 | 117 |
"return a new message object for a send with one argument. |
118 |
OBSOLETE: use #selector:argument: for ST-80 compatibility." |
|
1 | 119 |
|
8323 | 120 |
<resource:#obsolete> |
121 |
||
159 | 122 |
^ self basicNew setSelector:aSymbol arguments:(Array with:anArg) |
1 | 123 |
! |
124 |
||
125 |
selector:aSymbol with:arg1 with:arg2 |
|
159 | 126 |
"return a new message object for a send with two arguments. |
127 |
OBSOLETE: use #selector:arguments: for ST-80 compatibility." |
|
1 | 128 |
|
8323 | 129 |
<resource:#obsolete> |
130 |
||
159 | 131 |
^ self basicNew setSelector:aSymbol arguments:(Array with:arg1 with:arg2) |
1 | 132 |
! |
133 |
||
134 |
selector:aSymbol withAll:argArray |
|
93 | 135 |
"return a new message object for a send with many arguments. |
159 | 136 |
OBSOLETE: use #selector:arguments: for ST-80 compatibilty." |
137 |
||
8323 | 138 |
<resource:#obsolete> |
139 |
||
159 | 140 |
^ self basicNew setSelector:aSymbol arguments:argArray |
93 | 141 |
! ! |
142 |
||
143 |
!Message class methodsFor:'queries'! |
|
144 |
||
145 |
isBuiltInClass |
|
1264 | 146 |
"return true if this class is known by the run-time-system. |
147 |
Here, true is returned for myself, false for subclasses." |
|
93 | 148 |
|
149 |
^ self == Message |
|
1264 | 150 |
|
151 |
"Modified: 23.4.1996 / 15:59:30 / cg" |
|
1 | 152 |
! ! |
153 |
||
8439 | 154 |
!Message methodsFor:'Compatibility-Dolphin'! |
155 |
||
156 |
value:aReceiver |
|
157 |
"evaluate myself for receiver. |
|
158 |
Same as #sendTo: - compatibility with Dolphin" |
|
159 |
||
160 |
^ aReceiver perform:selector withArguments:args |
|
161 |
! ! |
|
162 |
||
163 |
!Message methodsFor:'Compatibility-GNU'! |
|
164 |
||
8489 | 165 |
reinvokeFor:aReceiver |
166 |
"send the selector with argument to a receiver. |
|
167 |
Same as sendTo: - for GNU-ST compatibility." |
|
8439 | 168 |
|
8489 | 169 |
^ self sendTo:aReceiver |
8439 | 170 |
! ! |
171 |
||
8579 | 172 |
!Message methodsFor:'Compatibility-Squeak'! |
173 |
||
174 |
argument |
|
175 |
"return the 1st argument of the message" |
|
176 |
||
177 |
args size == 1 ifFalse:[ |
|
178 |
self error:'Not a 1-arg message' |
|
179 |
]. |
|
180 |
^ args at:1 |
|
181 |
! ! |
|
182 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
183 |
!Message methodsFor:'accessing'! |
10 | 184 |
|
6253 | 185 |
arg1 |
186 |
"return the first argument of the message" |
|
187 |
||
188 |
^ args at:1 |
|
189 |
! |
|
190 |
||
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
191 |
argumentCount |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
192 |
"VisualAge/ANSI compatibility: return the number of arguments of the message" |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
193 |
|
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
194 |
^ args size |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
195 |
! |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
196 |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
197 |
arguments |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
198 |
"return the arguments of the message" |
19888 | 199 |
|
200 |
args isNil ifTrue:[^ #()]. |
|
201 |
^ args. |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
202 |
! |
1 | 203 |
|
10584 | 204 |
arguments:argArray |
205 |
"set arguments of the receiver" |
|
206 |
||
207 |
args := argArray |
|
208 |
||
209 |
"Created: / 31-05-2007 / 17:53:10 / cg" |
|
210 |
! |
|
211 |
||
6253 | 212 |
numArgs |
213 |
"return the number of arguments of the message" |
|
214 |
||
215 |
^ args size |
|
216 |
! |
|
217 |
||
1 | 218 |
selector |
219 |
"return the selector of the message" |
|
220 |
||
221 |
^ selector |
|
10584 | 222 |
! |
223 |
||
224 |
selector:aSymbol |
|
225 |
selector := aSymbol |
|
226 |
||
227 |
"Created: / 31-05-2007 / 17:53:06 / cg" |
|
1 | 228 |
! ! |
229 |
||
93 | 230 |
!Message methodsFor:'printing & storing'! |
1 | 231 |
|
14287
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
232 |
displayOn:aGCOrStream |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
233 |
"Compatibility |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
234 |
append a printed desription on some stream (Dolphin, Squeak) |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
235 |
OR: |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
236 |
display the receiver in a graphicsContext at 0@0 (ST80). |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
237 |
This method allows for any object to be displayed in some view |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
238 |
(although the fallBack is to display its printString ...)" |
56 | 239 |
|
14287
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
240 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
21530 | 241 |
"/ old ST80 means: draw-yourself on a GC. |
14287
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
242 |
aGCOrStream isStream ifFalse:[ |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
243 |
^ super displayOn:aGCOrStream. |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
244 |
]. |
1833 | 245 |
|
14287
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
246 |
aGCOrStream |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
247 |
nextPutAll:self class name; |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
248 |
nextPut:$(. |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
249 |
selector storeOn:aGCOrStream. |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
250 |
aGCOrStream nextPut:$) |
21530 | 251 |
|
252 |
"Modified (comment): / 22-02-2017 / 16:46:38 / cg" |
|
56 | 253 |
! |
254 |
||
255 |
printOn:aStream |
|
4392 | 256 |
"append a user printed representation of the receiver to aStream. |
257 |
The format is suitable for a human - not meant to be read back." |
|
1 | 258 |
|
56 | 259 |
selector printOn:aStream |
1 | 260 |
! ! |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
261 |
|
7257 | 262 |
!Message methodsFor:'private-accessing'! |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
263 |
|
6933 | 264 |
setSelector:aSymbol |
265 |
selector := aSymbol. |
|
266 |
! |
|
267 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
268 |
setSelector:aSymbol arguments:argArray |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
269 |
"set selector and arguments of the receiver" |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
270 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
271 |
selector := aSymbol. |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
272 |
args := argArray |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
273 |
! ! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
274 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
275 |
!Message methodsFor:'sending'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
276 |
|
8489 | 277 |
sendTo:aReceiver |
17523 | 278 |
"send the selector with argument(s) to aReceiver" |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
279 |
|
8489 | 280 |
^ aReceiver perform:selector withArguments:args |
20183 | 281 |
! |
282 |
||
283 |
sendTo:aReceiver usingClass:aClass |
|
284 |
"send the selector with argument(s) to aReceiver using the method named by selector from aClass" |
|
285 |
||
286 |
^ (aClass compiledMethodAt:selector) valueWithReceiver:aReceiver arguments:args selector:selector |
|
287 |
! |
|
288 |
||
289 |
sendTo:aReceiver usingMethod:aMethod |
|
290 |
"send the selector with argument(s) to aReceiver using compiledMethod aMethod" |
|
291 |
||
292 |
^ aMethod valueWithReceiver:aReceiver arguments:args selector:selector |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
293 |
! ! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
294 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
295 |
!Message class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
296 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
297 |
version |
19888 | 298 |
^ '$Header$' |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
299 |
! ! |
17523 | 300 |