author | Stefan Vogel <sv@exept.de> |
Wed, 22 Sep 2004 16:42:22 +0200 | |
changeset 8586 | a38e882affa5 |
parent 8579 | da7c9101e7a4 |
child 8687 | d6e6e2c0c27c |
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 |
" |
|
12 |
||
5591 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
1 | 15 |
Object subclass:#Message |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
16 |
instanceVariableNames:'selector args' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
17 |
classVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
18 |
poolDictionaries:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
19 |
category:'Kernel-Methods' |
1 | 20 |
! |
21 |
||
88 | 22 |
!Message class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
362 | 27 |
All Rights Reserved |
1 | 28 |
|
88 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
1 | 37 |
|
88 | 38 |
documentation |
39 |
" |
|
1268 | 40 |
Instances of Message represent a message being sent. |
41 |
During normal execution, message objects are NEVER used - |
|
42 |
instead, argument passing is done more performant via the stack |
|
43 |
or in registers (depends on how your C compiler passes arguments). |
|
44 |
||
45 |
However, messageObjects ARE created, when a message send fails |
|
88 | 46 |
(i.e. some message is not understood). |
1268 | 47 |
In this case, the selector and arguments of the failing messare |
48 |
are squashed into a new instance of Message, and a #doesNotUnderstand: |
|
49 |
message is sent to the original receiver, passing the message object |
|
50 |
as argument. |
|
88 | 51 |
|
1268 | 52 |
Typically, #doesNotUnderstand: is not redefined in the receivers class, |
53 |
therefore Object>>doesNotUnderstand: gets evaluated. |
|
54 |
There, a debugger is opened and the thread is suspended. |
|
55 |
However, it is possible to redefine this method, which |
|
56 |
allows for re-evaluation of the failed send (after some cleanup), |
|
57 |
to upload some code or to simply ignore the error. |
|
93 | 58 |
|
59 |
As an example of its use, see the implementation of the Autoload-class, |
|
60 |
or how ScrollableView forwards unknown messages to its slave-view. |
|
61 |
||
1268 | 62 |
Elegance hint: actually, Object>>doesNotUnderstand: raises an exception |
63 |
which can be handled - in most situations, providing an exception handler |
|
64 |
instead of redefining #doesNotUnderstand is the better way to do things. |
|
65 |
||
66 |
||
93 | 67 |
Notice: |
1268 | 68 |
Since the layout of Message-objects is known by the runtime system |
69 |
(it has to create those objects in case of a failure) |
|
70 |
it is not allowed to change the definition of this class. |
|
71 |
||
72 |
[See also:] |
|
73 |
Signal Exception MessageSend |
|
1293 | 74 |
|
75 |
[author:] |
|
76 |
Claus Gittinger |
|
88 | 77 |
" |
78 |
! ! |
|
1 | 79 |
|
80 |
!Message class methodsFor:'instance creation'! |
|
81 |
||
82 |
selector:aSymbol |
|
83 |
"return a new message object for a send without arguments" |
|
84 |
||
159 | 85 |
^ self basicNew setSelector:aSymbol arguments:nil |
1 | 86 |
! |
87 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
88 |
selector:aSymbol argument:anArg |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
89 |
"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
|
90 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
91 |
^ 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
|
92 |
! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
93 |
|
5751 | 94 |
selector:aSymbol argument:arg1 argument:arg2 |
95 |
"return a new message object for a send with two arguments" |
|
96 |
||
97 |
^ self basicNew setSelector:aSymbol arguments:(Array with:arg1 with:arg2) |
|
98 |
! |
|
99 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
100 |
selector:aSymbol arguments:argArray |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
101 |
"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
|
102 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
103 |
^ self basicNew setSelector:aSymbol arguments:argArray |
8323 | 104 |
! ! |
105 |
||
106 |
!Message class methodsFor:'obsolete'! |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
107 |
|
1 | 108 |
selector:aSymbol with:anArg |
159 | 109 |
"return a new message object for a send with one argument. |
110 |
OBSOLETE: use #selector:argument: for ST-80 compatibility." |
|
1 | 111 |
|
8323 | 112 |
<resource:#obsolete> |
113 |
||
159 | 114 |
^ self basicNew setSelector:aSymbol arguments:(Array with:anArg) |
1 | 115 |
! |
116 |
||
117 |
selector:aSymbol with:arg1 with:arg2 |
|
159 | 118 |
"return a new message object for a send with two arguments. |
119 |
OBSOLETE: use #selector:arguments: for ST-80 compatibility." |
|
1 | 120 |
|
8323 | 121 |
<resource:#obsolete> |
122 |
||
159 | 123 |
^ self basicNew setSelector:aSymbol arguments:(Array with:arg1 with:arg2) |
1 | 124 |
! |
125 |
||
126 |
selector:aSymbol withAll:argArray |
|
93 | 127 |
"return a new message object for a send with many arguments. |
159 | 128 |
OBSOLETE: use #selector:arguments: for ST-80 compatibilty." |
129 |
||
8323 | 130 |
<resource:#obsolete> |
131 |
||
159 | 132 |
^ self basicNew setSelector:aSymbol arguments:argArray |
93 | 133 |
! ! |
134 |
||
135 |
!Message class methodsFor:'queries'! |
|
136 |
||
137 |
isBuiltInClass |
|
1264 | 138 |
"return true if this class is known by the run-time-system. |
139 |
Here, true is returned for myself, false for subclasses." |
|
93 | 140 |
|
141 |
^ self == Message |
|
1264 | 142 |
|
143 |
"Modified: 23.4.1996 / 15:59:30 / cg" |
|
1 | 144 |
! ! |
145 |
||
8439 | 146 |
!Message methodsFor:'Compatibility-Dolphin'! |
147 |
||
148 |
value:aReceiver |
|
149 |
"evaluate myself for receiver. |
|
150 |
Same as #sendTo: - compatibility with Dolphin" |
|
151 |
||
152 |
^ aReceiver perform:selector withArguments:args |
|
153 |
! ! |
|
154 |
||
155 |
!Message methodsFor:'Compatibility-GNU'! |
|
156 |
||
8489 | 157 |
reinvokeFor:aReceiver |
158 |
"send the selector with argument to a receiver. |
|
159 |
Same as sendTo: - for GNU-ST compatibility." |
|
8439 | 160 |
|
8489 | 161 |
^ self sendTo:aReceiver |
8439 | 162 |
! ! |
163 |
||
8579 | 164 |
!Message methodsFor:'Compatibility-Squeak'! |
165 |
||
166 |
argument |
|
167 |
"return the 1st argument of the message" |
|
168 |
||
169 |
args size == 1 ifFalse:[ |
|
170 |
self error:'Not a 1-arg message' |
|
171 |
]. |
|
172 |
^ args at:1 |
|
173 |
! ! |
|
174 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
175 |
!Message methodsFor:'accessing'! |
10 | 176 |
|
6253 | 177 |
arg1 |
178 |
"return the first argument of the 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 |
arguments |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
184 |
"return the arguments of the message" |
85 | 185 |
|
6062
c8b8b9d382f1
always return a colelction from #arguments.
Claus Gittinger <cg@exept.de>
parents:
5751
diff
changeset
|
186 |
^ args ? #() |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
187 |
! |
1 | 188 |
|
6253 | 189 |
numArgs |
190 |
"return the number of arguments of the message" |
|
191 |
||
192 |
^ args size |
|
193 |
! |
|
194 |
||
1 | 195 |
selector |
196 |
"return the selector of the message" |
|
197 |
||
198 |
^ selector |
|
199 |
! ! |
|
200 |
||
93 | 201 |
!Message methodsFor:'printing & storing'! |
1 | 202 |
|
56 | 203 |
displayString |
204 |
"return a string for display in inspectors etc." |
|
205 |
||
5591 | 206 |
^ self class name , '(' , selector printString , ')' |
1833 | 207 |
|
208 |
"Modified: 28.10.1996 / 17:04:29 / cg" |
|
56 | 209 |
! |
210 |
||
211 |
printOn:aStream |
|
4392 | 212 |
"append a user printed representation of the receiver to aStream. |
213 |
The format is suitable for a human - not meant to be read back." |
|
1 | 214 |
|
56 | 215 |
selector printOn:aStream |
1 | 216 |
! ! |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
217 |
|
7257 | 218 |
!Message methodsFor:'private-accessing'! |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
219 |
|
6933 | 220 |
setSelector:aSymbol |
221 |
selector := aSymbol. |
|
222 |
! |
|
223 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
224 |
setSelector:aSymbol arguments:argArray |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
225 |
"set selector and arguments of the receiver" |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
226 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
227 |
selector := aSymbol. |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
228 |
args := argArray |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
229 |
! ! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
230 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
231 |
!Message methodsFor:'sending'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
232 |
|
8489 | 233 |
sendTo:aReceiver |
234 |
"send the selector with argument to aReceiver" |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
235 |
|
8489 | 236 |
^ aReceiver perform:selector withArguments:args |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
237 |
! ! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
238 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
239 |
!Message class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
240 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
241 |
version |
8579 | 242 |
^ '$Header: /cvs/stx/stx/libbasic/Message.st,v 1.31 2004-09-22 09:55:56 cg Exp $' |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
243 |
! ! |