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