author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 16:34:40 +0200 | |
changeset 24379 | 852be153b0ec |
parent 23132 | 8c4ef3c21488 |
child 24740 | 7fdaf3987d8f |
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 |
||
135 |
h := home. |
|
22530 | 136 |
[ |
15220 | 137 |
con := h. |
22530 | 138 |
h := con home. |
139 |
h notNil |
|
140 |
] whileTrue. |
|
141 |
||
1 | 142 |
^ con |
22530 | 143 |
|
144 |
"Modified: / 02-02-2018 / 14:01:32 / stefan" |
|
1 | 145 |
! |
146 |
||
147 |
selector |
|
148 |
"return the selector of the context - which is one of the value |
|
281 | 149 |
selectors. This selector is not found in the context, but synthesized." |
1 | 150 |
|
151 |
|nargs| |
|
152 |
||
18433 | 153 |
nargs := self argumentCount. |
1 | 154 |
(nargs == 0) ifTrue:[^ #value]. |
155 |
(nargs == 1) ifTrue:[^ #value:]. |
|
156 |
(nargs == 2) ifTrue:[^ #value:value:]. |
|
157 |
(nargs == 3) ifTrue:[^ #value:value:value:]. |
|
158 |
(nargs == 4) ifTrue:[^ #value:value:value:value:]. |
|
159 |
(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
|
160 |
(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
|
161 |
(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
|
162 |
(nargs == 8) ifTrue:[^ #value:value:value:value:value:value:value:value:]. |
15454 | 163 |
(nargs == 9) ifTrue:[^ #value:value:value:value:value:value:value:value:value:]. |
164 |
(nargs == 10) ifTrue:[^ #value:value:value:value:value:value:value:value:value:value:]. |
|
165 |
(nargs == 11) ifTrue:[^ #value:value:value:value:value:value:value:value:value:value:value:]. |
|
166 |
(nargs == 12) ifTrue:[^ #value:value:value:value:value:value:value:value:value:value:value:value:]. |
|
1 | 167 |
^ nil |
168 |
! ! |
|
169 |
||
92 | 170 |
!BlockContext methodsFor:'printing & storing'! |
1 | 171 |
|
15382 | 172 |
printReceiverOn:aStream |
173 |
"print a string describing the receiver of the context on aStream |
|
357 | 174 |
|
175 |
Since this is also used by the debugger(s), be very careful to |
|
281 | 176 |
return something useful, even in case internals of the system |
177 |
got corrupted ... (i.e. avoid messageNotUnderstood here)" |
|
178 |
||
15382 | 179 |
|cls who mHome m className homeSel| |
357 | 180 |
|
15382 | 181 |
home isContext ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
182 |
" |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
183 |
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
|
184 |
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
|
185 |
that one ... |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
186 |
... 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
|
187 |
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
|
188 |
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
|
189 |
" |
241 | 190 |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
191 |
"temporary kludge - peek into the sender context. |
21418 | 192 |
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
|
193 |
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
|
194 |
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
|
195 |
" |
14213 | 196 |
m := self method. |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
197 |
m isNil ifTrue:[ |
15382 | 198 |
aStream nextPutAll:'[] (optimized) in ???'. |
199 |
] ifFalse:[ |
|
200 |
aStream nextPutAll:'[] in '. |
|
20889 | 201 |
cls := m mclass. |
202 |
cls isNil ifTrue:[ |
|
203 |
cls := m getMclass. |
|
204 |
cls isNil ifTrue:[ |
|
205 |
className := '*Unbound*' |
|
206 |
] ifFalse:[ |
|
207 |
className := '(previously in) ',cls name |
|
208 |
]. |
|
209 |
] ifFalse:[ |
|
210 |
className := cls name. |
|
211 |
]. |
|
212 |
className printOn:aStream. |
|
15382 | 213 |
aStream nextPutAll:'>>'. |
23132 | 214 |
aStream bold. |
15382 | 215 |
m selector printOn:aStream. |
23132 | 216 |
aStream normal. |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
217 |
]. |
15382 | 218 |
^ self. |
1 | 219 |
]. |
220 |
||
281 | 221 |
mHome := self methodHome. |
222 |
mHome isNil ifTrue:[ |
|
15382 | 223 |
aStream nextPutAll:'[] (no methodHome!!) in ???'. |
224 |
^ self. |
|
281 | 225 |
]. |
226 |
||
293 | 227 |
" |
228 |
kludge to avoid slow search for containing class |
|
229 |
" |
|
15382 | 230 |
homeSel := mHome selector. |
231 |
(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
|
232 |
cls := mHome receiver class. |
15382 | 233 |
homeSel := #doIt. |
293 | 234 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
235 |
m := mHome method. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
236 |
m isNil ifTrue:[ |
15382 | 237 |
aStream nextPutAll:'[] (no method!!) in ???'. |
238 |
^ self. |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
239 |
]. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
240 |
who := m who. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
241 |
who notNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
242 |
cls := who methodClass |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
243 |
] ifFalse:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
244 |
cls := receiver class. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
245 |
]. |
241 | 246 |
]. |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
247 |
|
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
248 |
cls isNil ifTrue:[ |
15382 | 249 |
className := '???(no home class!!)' |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
250 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
251 |
className := cls name. |
15382 | 252 |
className isEmptyOrNil ifTrue:[ |
253 |
className := '???(nameless class!!)' |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
254 |
] |
281 | 255 |
]. |
15382 | 256 |
aStream nextPutAll:'[] in '; nextPutAll:className; nextPutAll:'>>'. |
23132 | 257 |
aStream bold. |
15382 | 258 |
homeSel printOn:aStream. |
23132 | 259 |
aStream normal. |
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
260 |
|
14213 | 261 |
"Modified: / 19-07-2012 / 11:02:41 / cg" |
21418 | 262 |
"Modified (format): / 13-02-2017 / 19:56:14 / cg" |
23132 | 263 |
"Modified: / 26-06-2018 / 19:25:02 / Claus Gittinger" |
1 | 264 |
! ! |
623 | 265 |
|
14215 | 266 |
!BlockContext methodsFor:'testing'! |
267 |
||
268 |
isBlockContext |
|
269 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
270 |
||
271 |
^ true |
|
272 |
! |
|
273 |
||
274 |
isCheapBlockContext |
|
275 |
"return true, iff the receiver is a BlockContext, for a cheap block, false otherwise. |
|
276 |
Cheap blocks do not refer to their home" |
|
277 |
||
278 |
^ home isNil |
|
279 |
||
280 |
"Created: / 19-07-2012 / 11:22:23 / cg" |
|
281 |
! ! |
|
282 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
283 |
!BlockContext class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
284 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
285 |
version |
20889 | 286 |
^ '$Header$' |
14215 | 287 |
! |
288 |
||
289 |
version_CVS |
|
20889 | 290 |
^ '$Header$' |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
291 |
! ! |
15220 | 292 |