author | Claus Gittinger <cg@exept.de> |
Wed, 29 May 1996 15:19:03 +0200 | |
changeset 1444 | cb2493aa4d0c |
parent 1293 | 02fb05148c98 |
child 1852 | 89b2328f4203 |
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 |
" |
|
12 |
||
13 |
Context subclass:#BlockContext |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
14 |
instanceVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
15 |
classVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
16 |
poolDictionaries:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
17 |
category:'Kernel-Methods' |
1 | 18 |
! |
19 |
||
88 | 20 |
!BlockContext class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
165 | 25 |
All Rights Reserved |
1 | 26 |
|
88 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
1 | 35 |
|
88 | 36 |
documentation |
37 |
" |
|
38 |
BlockContexts represent the stack context objects of blocks. |
|
39 |
The layout is the same as for other contexts - this class has been added |
|
40 |
to avoid a flag in an instance variable. |
|
41 |
(has become necessary with cheap blocks, which have no home). |
|
42 |
||
43 |
WARNING: layout and size known by compiler and runtime system - |
|
1293 | 44 |
do not change. |
45 |
||
46 |
[author:] |
|
47 |
Claus Gittinger |
|
48 |
||
49 |
[see also:] |
|
50 |
Context Block Method |
|
51 |
Exception Signal |
|
88 | 52 |
" |
53 |
! ! |
|
1 | 54 |
|
55 |
!BlockContext methodsFor:'accessing'! |
|
56 |
||
623 | 57 |
canReturn |
58 |
"return true, if the receiver allows returning through it. |
|
59 |
For normal method contexts, this normally returns true; |
|
60 |
for blocks, it (currently) always returns false." |
|
61 |
||
62 |
^ false |
|
63 |
! |
|
64 |
||
65 |
home |
|
66 |
"return the immediate home of the receiver. |
|
67 |
normally this is the methodcontext, where the block was created, |
|
68 |
for nested block contexts, this is the surrounding blocks context." |
|
69 |
||
70 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
|
71 |
^ home |
|
72 |
! |
|
73 |
||
1 | 74 |
isBlockContext |
75 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
76 |
||
77 |
^ true |
|
78 |
! |
|
79 |
||
623 | 80 |
method |
81 |
"return the method in which the current contexts block was created." |
|
360 | 82 |
|
623 | 83 |
home notNil ifTrue:[^ home method]. |
84 |
^ nil |
|
360 | 85 |
! |
86 |
||
1 | 87 |
methodHome |
88 |
"return the method-home for block contexts" |
|
89 |
||
90 |
|con h| |
|
91 |
||
92 |
home isNil ifTrue:[^ nil]. "XXX will change soon" |
|
93 |
home isContext ifFalse:[^ nil]. "copying blocks have no method home" |
|
94 |
||
95 |
con := self. |
|
96 |
h := home. |
|
97 |
[h notNil] whileTrue:[ |
|
165 | 98 |
con := h. |
99 |
h := con home |
|
1 | 100 |
]. |
101 |
^ con |
|
102 |
! |
|
103 |
||
104 |
selector |
|
105 |
"return the selector of the context - which is one of the value |
|
281 | 106 |
selectors. This selector is not found in the context, but synthesized." |
1 | 107 |
|
108 |
|nargs| |
|
109 |
||
154 | 110 |
nargs := self numArgs. |
1 | 111 |
(nargs == 0) ifTrue:[^ #value]. |
112 |
(nargs == 1) ifTrue:[^ #value:]. |
|
113 |
(nargs == 2) ifTrue:[^ #value:value:]. |
|
114 |
(nargs == 3) ifTrue:[^ #value:value:value:]. |
|
115 |
(nargs == 4) ifTrue:[^ #value:value:value:value:]. |
|
116 |
(nargs == 5) ifTrue:[^ #value:value:value:value:value:]. |
|
117 |
^ nil |
|
118 |
! ! |
|
119 |
||
92 | 120 |
!BlockContext methodsFor:'printing & storing'! |
1 | 121 |
|
122 |
receiverPrintString |
|
281 | 123 |
"return a printString describing the contexts receiver. |
357 | 124 |
|
125 |
Since this is also used by the debugger(s), be very careful to |
|
281 | 126 |
return something useful, even in case internals of the system |
127 |
got corrupted ... (i.e. avoid messageNotUnderstood here)" |
|
128 |
||
357 | 129 |
|cls who mHome m className |
130 |
sender selSender tryVars possibleBlocks method mWho| |
|
131 |
||
132 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
133 |
" |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
134 |
mhmh - an optimized blocks context |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
135 |
should get the block here, and get the method from |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
136 |
that one ... |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
137 |
... but in 2.10.x, there is no easy way to get to the block |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
138 |
since that one is not in the context. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
139 |
Starting with 2.11, the new block calling scheme will fix this. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
140 |
" |
241 | 141 |
|
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
142 |
"temporary kludge - peek into the sender context. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
143 |
If its a do-like method and there is a single block variable |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
144 |
in the args or temporaries, that must be the one. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
145 |
This helps in some cases. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
146 |
" |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
147 |
(sender := self sender) notNil ifTrue:[ |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
148 |
tryVars := false. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
149 |
(selSender := sender selector) notNil ifTrue:[ |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
150 |
(selSender endsWith:'do:') ifTrue:[ |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
151 |
tryVars := true. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
152 |
] ifFalse:[ |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
153 |
(selSender endsWith:'Do:') ifTrue:[ |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
154 |
tryVars := true. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
155 |
] |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
156 |
] |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
157 |
]. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
158 |
tryVars ifTrue:[ |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
159 |
possibleBlocks := sender argsAndVars select:[:v | v isBlock]. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
160 |
possibleBlocks := possibleBlocks select:[:b | b home isNil]. |
357 | 161 |
|
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
162 |
possibleBlocks size == 1 ifTrue:[ |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
163 |
method := possibleBlocks first method. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
164 |
" |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
165 |
change the line in the upper-listview |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
166 |
according the information we have now |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
167 |
" |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
168 |
mWho := method who. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
169 |
mWho isNil ifTrue:[ |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
170 |
^ '[] (optimized) in ???'. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
171 |
]. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
172 |
^ '[] (optimized) in ' , |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
173 |
(mWho at:1) name , '-' , (mWho at:2). |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
174 |
]. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
175 |
] |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
176 |
]. |
357 | 177 |
|
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
178 |
^ '[] (optimized)' |
1 | 179 |
]. |
180 |
||
281 | 181 |
mHome := self methodHome. |
182 |
mHome isNil ifTrue:[ |
|
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
183 |
'BCONTEXT: no methodHome' errorPrintNL. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
184 |
^ '[] in ???' |
281 | 185 |
]. |
186 |
||
293 | 187 |
" |
188 |
kludge to avoid slow search for containing class |
|
189 |
" |
|
190 |
mHome selector == #doIt ifTrue:[ |
|
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
191 |
who := Array with:mHome receiver class |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
192 |
with:#doIt |
293 | 193 |
] ifFalse:[ |
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
194 |
m := mHome method. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
195 |
m isNil ifTrue:[ |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
196 |
'BCONTEXT: no method' errorPrintNL. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
197 |
^ '[] in ???' |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
198 |
]. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
199 |
who := m who. |
281 | 200 |
]. |
241 | 201 |
who notNil ifTrue:[ |
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
202 |
cls := who at:1 |
241 | 203 |
] ifFalse:[ |
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
204 |
cls := receiver class. |
241 | 205 |
]. |
281 | 206 |
className := cls name. |
207 |
className isNil ifTrue:[ |
|
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
208 |
'BCONTEXT: nameless class' errorPrintNL. |
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
209 |
className := '???' |
281 | 210 |
]. |
211 |
^ '[] in ' , className , '-' , mHome selector printString |
|
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
212 |
|
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
213 |
"Modified: 29.5.1996 / 13:56:47 / cg" |
1 | 214 |
! ! |
623 | 215 |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
216 |
!BlockContext class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
217 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
218 |
version |
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
219 |
^ '$Header: /cvs/stx/stx/libbasic/BlockContext.st,v 1.22 1996-05-29 13:19:03 cg Exp $' |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
220 |
! ! |