author | Claus Gittinger <cg@exept.de> |
Mon, 13 Feb 2017 20:05:49 +0100 | |
changeset 21418 | 674ea83c00b9 |
parent 20889 | 15225da02dc3 |
child 22530 | 4af6ed4920e8 |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
165 | 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 |
" |
|
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
13 |
|
18433 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
4623 | 16 |
Context variableSubclass:#BlockContext |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
17 |
instanceVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
18 |
classVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
19 |
poolDictionaries:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
20 |
category:'Kernel-Methods' |
1 | 21 |
! |
22 |
||
88 | 23 |
!BlockContext class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
165 | 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 |
" |
|
8666 | 41 |
BlockContexts represent the stack context objects of blocks. |
42 |
The layout is the same as for other contexts - this class has been added |
|
88 | 43 |
to avoid a flag in an instance variable. |
44 |
(has become necessary with cheap blocks, which have no home). |
|
45 |
||
8666 | 46 |
WARNING: layout and size known by compiler and runtime system - |
47 |
do not change. |
|
1293 | 48 |
|
49 |
[author:] |
|
8666 | 50 |
Claus Gittinger |
1293 | 51 |
|
52 |
[see also:] |
|
8666 | 53 |
Context Block Method |
54 |
Exception Signal |
|
88 | 55 |
" |
56 |
! ! |
|
1 | 57 |
|
58 |
!BlockContext methodsFor:'accessing'! |
|
59 |
||
623 | 60 |
canReturn |
61 |
"return true, if the receiver allows returning through it. |
|
62 |
For normal method contexts, this normally returns true; |
|
63 |
for blocks, it (currently) always returns false." |
|
64 |
||
65 |
^ false |
|
66 |
! |
|
67 |
||
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
68 |
guessedHome |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
69 |
"a temporary kludge: optimized block contexts do (currently) not provide |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
70 |
any home info. The code below tries to guess the home." |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
71 |
|
8666 | 72 |
|sender tryVars selSender possibleBlocks method| |
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
73 |
|
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
74 |
(home isNil or:[home isContext not]) ifTrue:[ |
8666 | 75 |
(sender := self sender) notNil ifTrue:[ |
76 |
tryVars := false. |
|
77 |
(selSender := sender selector) notNil ifTrue:[ |
|
78 |
(selSender endsWith:'do:') ifTrue:[ |
|
79 |
tryVars := true. |
|
80 |
] ifFalse:[ |
|
81 |
(selSender endsWith:'Do:') ifTrue:[ |
|
82 |
tryVars := true. |
|
83 |
] |
|
84 |
] |
|
85 |
]. |
|
86 |
tryVars ifTrue:[ |
|
87 |
possibleBlocks := sender argsAndVars select:[:v | v isBlock]. |
|
88 |
possibleBlocks := possibleBlocks select:[:b | b home isNil]. |
|
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
89 |
|
8666 | 90 |
possibleBlocks size == 1 ifTrue:[ |
91 |
method := possibleBlocks first method. |
|
92 |
^ method. |
|
93 |
]. |
|
94 |
] |
|
95 |
]. |
|
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
96 |
]. |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
97 |
^ nil |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
98 |
! |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
99 |
|
623 | 100 |
home |
101 |
"return the immediate home of the receiver. |
|
102 |
normally this is the methodcontext, where the block was created, |
|
103 |
for nested block contexts, this is the surrounding blocks context." |
|
104 |
||
105 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
|
106 |
^ home |
|
107 |
! |
|
108 |
||
3324
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
109 |
homeReceiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
110 |
"return the receiver from the context, where the receiver was defined" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
111 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
112 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
113 |
^ home receiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
114 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
115 |
"Created: / 5.3.1998 / 16:20:31 / stefan" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
116 |
! |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
117 |
|
623 | 118 |
method |
119 |
"return the method in which the current contexts block was created." |
|
360 | 120 |
|
623 | 121 |
home notNil ifTrue:[^ home method]. |
14213 | 122 |
^ super method |
123 |
||
124 |
"Modified: / 19-07-2012 / 10:58:55 / cg" |
|
360 | 125 |
! |
126 |
||
1 | 127 |
methodHome |
128 |
"return the method-home for block contexts" |
|
129 |
||
130 |
|con h| |
|
131 |
||
15267 | 132 |
home isNil ifTrue:[^ nil]. |
1 | 133 |
home isContext ifFalse:[^ nil]. "copying blocks have no method home" |
134 |
||
15267 | 135 |
con := self. |
1 | 136 |
h := home. |
15267 | 137 |
[h notNil] whileTrue:[ |
15220 | 138 |
con := h. |
139 |
h := con home |
|
15267 | 140 |
]. |
1 | 141 |
^ con |
142 |
! |
|
143 |
||
144 |
selector |
|
145 |
"return the selector of the context - which is one of the value |
|
281 | 146 |
selectors. This selector is not found in the context, but synthesized." |
1 | 147 |
|
148 |
|nargs| |
|
149 |
||
18433 | 150 |
nargs := self argumentCount. |
1 | 151 |
(nargs == 0) ifTrue:[^ #value]. |
152 |
(nargs == 1) ifTrue:[^ #value:]. |
|
153 |
(nargs == 2) ifTrue:[^ #value:value:]. |
|
154 |
(nargs == 3) ifTrue:[^ #value:value:value:]. |
|
155 |
(nargs == 4) ifTrue:[^ #value:value:value:value:]. |
|
156 |
(nargs == 5) ifTrue:[^ #value:value:value:value:value:]. |
|
11168
44fef5d29484
Support up to 8 args in #selector
Stefan Vogel <sv@exept.de>
parents:
8666
diff
changeset
|
157 |
(nargs == 6) ifTrue:[^ #value:value:value:value:value:value:]. |
44fef5d29484
Support up to 8 args in #selector
Stefan Vogel <sv@exept.de>
parents:
8666
diff
changeset
|
158 |
(nargs == 7) ifTrue:[^ #value:value:value:value:value:value:value:]. |
44fef5d29484
Support up to 8 args in #selector
Stefan Vogel <sv@exept.de>
parents:
8666
diff
changeset
|
159 |
(nargs == 8) ifTrue:[^ #value:value:value:value:value:value:value:value:]. |
15454 | 160 |
(nargs == 9) ifTrue:[^ #value:value:value:value:value:value:value:value:value:]. |
161 |
(nargs == 10) ifTrue:[^ #value:value:value:value:value:value:value:value:value:value:]. |
|
162 |
(nargs == 11) ifTrue:[^ #value:value:value:value:value:value:value:value:value:value:value:]. |
|
163 |
(nargs == 12) ifTrue:[^ #value:value:value:value:value:value:value:value:value:value:value:value:]. |
|
1 | 164 |
^ nil |
165 |
! ! |
|
166 |
||
92 | 167 |
!BlockContext methodsFor:'printing & storing'! |
1 | 168 |
|
15382 | 169 |
printReceiverOn:aStream |
170 |
"print a string describing the receiver of the context on aStream |
|
357 | 171 |
|
172 |
Since this is also used by the debugger(s), be very careful to |
|
281 | 173 |
return something useful, even in case internals of the system |
174 |
got corrupted ... (i.e. avoid messageNotUnderstood here)" |
|
175 |
||
15382 | 176 |
|cls who mHome m className homeSel| |
357 | 177 |
|
15382 | 178 |
home isContext ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
179 |
" |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
180 |
mhmh - an optimized blocks context |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
181 |
should get the block here, and get the method from |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
182 |
that one ... |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
183 |
... but in 2.x, there is no easy way to get to the block |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
184 |
since that one is not in the context. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
185 |
Starting with 3.x, the new block calling scheme will fix this. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
186 |
" |
241 | 187 |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
188 |
"temporary kludge - peek into the sender context. |
21418 | 189 |
If it's a do-like method and there is a single block variable |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
190 |
in the args or temporaries, that must be the one. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
191 |
This helps in some cases. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
192 |
" |
14213 | 193 |
m := self method. |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
194 |
m isNil ifTrue:[ |
15382 | 195 |
aStream nextPutAll:'[] (optimized) in ???'. |
196 |
] ifFalse:[ |
|
197 |
aStream nextPutAll:'[] in '. |
|
20889 | 198 |
cls := m mclass. |
199 |
cls isNil ifTrue:[ |
|
200 |
cls := m getMclass. |
|
201 |
cls isNil ifTrue:[ |
|
202 |
className := '*Unbound*' |
|
203 |
] ifFalse:[ |
|
204 |
className := '(previously in) ',cls name |
|
205 |
]. |
|
206 |
] ifFalse:[ |
|
207 |
className := cls name. |
|
208 |
]. |
|
209 |
className printOn:aStream. |
|
15382 | 210 |
aStream nextPutAll:'>>'. |
211 |
m selector printOn:aStream. |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
212 |
]. |
15382 | 213 |
^ self. |
1 | 214 |
]. |
215 |
||
281 | 216 |
mHome := self methodHome. |
217 |
mHome isNil ifTrue:[ |
|
15382 | 218 |
aStream nextPutAll:'[] (no methodHome!!) in ???'. |
219 |
^ self. |
|
281 | 220 |
]. |
221 |
||
293 | 222 |
" |
223 |
kludge to avoid slow search for containing class |
|
224 |
" |
|
15382 | 225 |
homeSel := mHome selector. |
226 |
(homeSel == #doIt or:[homeSel == #doIt:]) ifTrue:[ |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
227 |
cls := mHome receiver class. |
15382 | 228 |
homeSel := #doIt. |
293 | 229 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
230 |
m := mHome method. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
231 |
m isNil ifTrue:[ |
15382 | 232 |
aStream nextPutAll:'[] (no method!!) in ???'. |
233 |
^ self. |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
234 |
]. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
235 |
who := m who. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
236 |
who notNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
237 |
cls := who methodClass |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
238 |
] ifFalse:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
239 |
cls := receiver class. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
240 |
]. |
241 | 241 |
]. |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
242 |
|
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
243 |
cls isNil ifTrue:[ |
15382 | 244 |
className := '???(no home class!!)' |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
245 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
246 |
className := cls name. |
15382 | 247 |
className isEmptyOrNil ifTrue:[ |
248 |
className := '???(nameless class!!)' |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
249 |
] |
281 | 250 |
]. |
15382 | 251 |
aStream nextPutAll:'[] in '; nextPutAll:className; nextPutAll:'>>'. |
252 |
homeSel printOn:aStream. |
|
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
253 |
|
14213 | 254 |
"Modified: / 19-07-2012 / 11:02:41 / cg" |
21418 | 255 |
"Modified (format): / 13-02-2017 / 19:56:14 / cg" |
1 | 256 |
! ! |
623 | 257 |
|
14215 | 258 |
!BlockContext methodsFor:'testing'! |
259 |
||
260 |
isBlockContext |
|
261 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
262 |
||
263 |
^ true |
|
264 |
! |
|
265 |
||
266 |
isCheapBlockContext |
|
267 |
"return true, iff the receiver is a BlockContext, for a cheap block, false otherwise. |
|
268 |
Cheap blocks do not refer to their home" |
|
269 |
||
270 |
^ home isNil |
|
271 |
||
272 |
"Created: / 19-07-2012 / 11:22:23 / cg" |
|
273 |
! ! |
|
274 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
275 |
!BlockContext class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
276 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
277 |
version |
20889 | 278 |
^ '$Header$' |
14215 | 279 |
! |
280 |
||
281 |
version_CVS |
|
20889 | 282 |
^ '$Header$' |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
283 |
! ! |
15220 | 284 |