author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 31 Oct 2011 22:19:21 +0000 | |
branch | jv |
changeset 17892 | d86c8bd5ece3 |
parent 17869 | 9610c6c94e71 |
child 17910 | 8d796ca8bd1d |
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 |
|
4623 | 14 |
Context variableSubclass:#BlockContext |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
15 |
instanceVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
16 |
classVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
17 |
poolDictionaries:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
18 |
category:'Kernel-Methods' |
1 | 19 |
! |
20 |
||
88 | 21 |
!BlockContext class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
165 | 26 |
All Rights Reserved |
1 | 27 |
|
88 | 28 |
This software is furnished under a license and may be used |
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
1 | 36 |
|
88 | 37 |
documentation |
38 |
" |
|
8666 | 39 |
BlockContexts represent the stack context objects of blocks. |
40 |
The layout is the same as for other contexts - this class has been added |
|
88 | 41 |
to avoid a flag in an instance variable. |
42 |
(has become necessary with cheap blocks, which have no home). |
|
43 |
||
8666 | 44 |
WARNING: layout and size known by compiler and runtime system - |
45 |
do not change. |
|
1293 | 46 |
|
47 |
[author:] |
|
8666 | 48 |
Claus Gittinger |
1293 | 49 |
|
50 |
[see also:] |
|
8666 | 51 |
Context Block Method |
52 |
Exception Signal |
|
88 | 53 |
" |
54 |
! ! |
|
1 | 55 |
|
17865 | 56 |
|
1 | 57 |
!BlockContext methodsFor:'accessing'! |
58 |
||
623 | 59 |
canReturn |
60 |
"return true, if the receiver allows returning through it. |
|
61 |
For normal method contexts, this normally returns true; |
|
62 |
for blocks, it (currently) always returns false." |
|
63 |
||
64 |
^ false |
|
65 |
! |
|
66 |
||
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
67 |
guessedHome |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
68 |
"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
|
69 |
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
|
70 |
|
8666 | 71 |
|sender tryVars selSender possibleBlocks method| |
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
72 |
|
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
73 |
(home isNil or:[home isContext not]) ifTrue:[ |
8666 | 74 |
(sender := self sender) notNil ifTrue:[ |
75 |
tryVars := false. |
|
76 |
(selSender := sender selector) notNil ifTrue:[ |
|
77 |
(selSender endsWith:'do:') ifTrue:[ |
|
78 |
tryVars := true. |
|
79 |
] ifFalse:[ |
|
80 |
(selSender endsWith:'Do:') ifTrue:[ |
|
81 |
tryVars := true. |
|
82 |
] |
|
83 |
] |
|
84 |
]. |
|
85 |
tryVars ifTrue:[ |
|
86 |
possibleBlocks := sender argsAndVars select:[:v | v isBlock]. |
|
87 |
possibleBlocks := possibleBlocks select:[:b | b home isNil]. |
|
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
88 |
|
8666 | 89 |
possibleBlocks size == 1 ifTrue:[ |
90 |
method := possibleBlocks first method. |
|
91 |
^ method. |
|
92 |
]. |
|
93 |
] |
|
94 |
]. |
|
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
95 |
]. |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
96 |
^ nil |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
97 |
! |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
98 |
|
623 | 99 |
home |
100 |
"return the immediate home of the receiver. |
|
101 |
normally this is the methodcontext, where the block was created, |
|
102 |
for nested block contexts, this is the surrounding blocks context." |
|
103 |
||
104 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
|
105 |
^ home |
|
106 |
! |
|
107 |
||
3324
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
108 |
homeReceiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
109 |
"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
|
110 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
111 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
112 |
^ home receiver |
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 |
"Created: / 5.3.1998 / 16:20:31 / stefan" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
115 |
! |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
116 |
|
1 | 117 |
isBlockContext |
118 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
119 |
||
120 |
^ true |
|
121 |
! |
|
122 |
||
623 | 123 |
method |
124 |
"return the method in which the current contexts block was created." |
|
360 | 125 |
|
623 | 126 |
home notNil ifTrue:[^ home method]. |
127 |
^ nil |
|
360 | 128 |
! |
129 |
||
1 | 130 |
methodHome |
131 |
"return the method-home for block contexts" |
|
132 |
||
133 |
|con h| |
|
134 |
||
135 |
home isNil ifTrue:[^ nil]. "XXX will change soon" |
|
136 |
home isContext ifFalse:[^ nil]. "copying blocks have no method home" |
|
137 |
||
138 |
con := self. |
|
139 |
h := home. |
|
140 |
[h notNil] whileTrue:[ |
|
165 | 141 |
con := h. |
142 |
h := con home |
|
1 | 143 |
]. |
144 |
^ con |
|
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 |
||
154 | 153 |
nargs := self numArgs. |
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:]. |
1 | 163 |
^ nil |
164 |
! ! |
|
165 |
||
92 | 166 |
!BlockContext methodsFor:'printing & storing'! |
1 | 167 |
|
168 |
receiverPrintString |
|
281 | 169 |
"return a printString describing the contexts receiver. |
357 | 170 |
|
171 |
Since this is also used by the debugger(s), be very careful to |
|
281 | 172 |
return something useful, even in case internals of the system |
173 |
got corrupted ... (i.e. avoid messageNotUnderstood here)" |
|
174 |
||
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
175 |
|cls who mHome m className sel homeSel| |
357 | 176 |
|
177 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
178 |
" |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
179 |
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
|
180 |
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
|
181 |
that one ... |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
182 |
... 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
|
183 |
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
|
184 |
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
|
185 |
" |
241 | 186 |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
187 |
"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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
" |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
192 |
m isNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
193 |
^ '[] (optimized) in ???'. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
194 |
]. |
11313 | 195 |
^ '[] (optimized) in ' , m mclass name , ' >> ' , m selector. |
1 | 196 |
]. |
197 |
||
281 | 198 |
mHome := self methodHome. |
199 |
mHome isNil ifTrue:[ |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
200 |
'BlockContext [warning]: no methodHome' errorPrintCR. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
201 |
^ '[] in ???' |
281 | 202 |
]. |
203 |
||
293 | 204 |
" |
205 |
kludge to avoid slow search for containing class |
|
206 |
" |
|
2157
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2128
diff
changeset
|
207 |
((homeSel := mHome selector) == #doIt |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2128
diff
changeset
|
208 |
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
|
209 |
sel := #doIt. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
210 |
cls := mHome receiver class. |
293 | 211 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
212 |
m := mHome method. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
213 |
m isNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
214 |
'BlockContext [warning]: no method' errorPrintCR. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
215 |
^ '[] in ???' |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
216 |
]. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
217 |
who := m who. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
218 |
who notNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
219 |
cls := who methodClass |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
220 |
] ifFalse:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
221 |
cls := receiver class. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
222 |
]. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
223 |
sel := homeSel printString. |
241 | 224 |
]. |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
225 |
|
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
226 |
cls isNil ifTrue:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
227 |
'BlockContext [warning]: no home class' errorPrintCR. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
228 |
className := '???' |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
229 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
230 |
className := cls name. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
231 |
className isNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
232 |
'BlockContext [warning]: nameless class' errorPrintCR. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
233 |
className := '???' |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
234 |
] |
281 | 235 |
]. |
11313 | 236 |
^ '[] in ' , className , ' >> ' , sel |
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
237 |
|
2157
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2128
diff
changeset
|
238 |
"Modified: 10.1.1997 / 21:26:21 / cg" |
1 | 239 |
! ! |
623 | 240 |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
241 |
!BlockContext class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
242 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
243 |
version |
17892 | 244 |
^ '$Header: /cvs/stx/stx/libbasic/BlockContext.st,v 1.33 2008/11/05 14:22:16 cg Exp $' |
17865 | 245 |
! |
246 |
||
247 |
version_SVN |
|
17892 | 248 |
^ '$Id: BlockContext.st 10729 2011-10-31 22:19:21Z vranyj1 $' |
17846 | 249 |
! ! |
17892 | 250 |