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