author | Claus Gittinger <cg@exept.de> |
Tue, 23 Apr 1996 16:47:53 +0200 | |
changeset 1268 | 38b3714d9eaf |
parent 1183 | e3d58d115e53 |
child 1293 | 02fb05148c98 |
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 - |
|
165 | 44 |
do not change. |
88 | 45 |
" |
46 |
! ! |
|
1 | 47 |
|
48 |
!BlockContext methodsFor:'accessing'! |
|
49 |
||
623 | 50 |
canReturn |
51 |
"return true, if the receiver allows returning through it. |
|
52 |
For normal method contexts, this normally returns true; |
|
53 |
for blocks, it (currently) always returns false." |
|
54 |
||
55 |
^ false |
|
56 |
! |
|
57 |
||
58 |
home |
|
59 |
"return the immediate home of the receiver. |
|
60 |
normally this is the methodcontext, where the block was created, |
|
61 |
for nested block contexts, this is the surrounding blocks context." |
|
62 |
||
63 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
|
64 |
^ home |
|
65 |
! |
|
66 |
||
1 | 67 |
isBlockContext |
68 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
69 |
||
70 |
^ true |
|
71 |
! |
|
72 |
||
623 | 73 |
method |
74 |
"return the method in which the current contexts block was created." |
|
360 | 75 |
|
623 | 76 |
home notNil ifTrue:[^ home method]. |
77 |
^ nil |
|
360 | 78 |
! |
79 |
||
1 | 80 |
methodHome |
81 |
"return the method-home for block contexts" |
|
82 |
||
83 |
|con h| |
|
84 |
||
85 |
home isNil ifTrue:[^ nil]. "XXX will change soon" |
|
86 |
home isContext ifFalse:[^ nil]. "copying blocks have no method home" |
|
87 |
||
88 |
con := self. |
|
89 |
h := home. |
|
90 |
[h notNil] whileTrue:[ |
|
165 | 91 |
con := h. |
92 |
h := con home |
|
1 | 93 |
]. |
94 |
^ con |
|
95 |
! |
|
96 |
||
97 |
selector |
|
98 |
"return the selector of the context - which is one of the value |
|
281 | 99 |
selectors. This selector is not found in the context, but synthesized." |
1 | 100 |
|
101 |
|nargs| |
|
102 |
||
154 | 103 |
nargs := self numArgs. |
1 | 104 |
(nargs == 0) ifTrue:[^ #value]. |
105 |
(nargs == 1) ifTrue:[^ #value:]. |
|
106 |
(nargs == 2) ifTrue:[^ #value:value:]. |
|
107 |
(nargs == 3) ifTrue:[^ #value:value:value:]. |
|
108 |
(nargs == 4) ifTrue:[^ #value:value:value:value:]. |
|
109 |
(nargs == 5) ifTrue:[^ #value:value:value:value:value:]. |
|
110 |
^ nil |
|
111 |
! ! |
|
112 |
||
92 | 113 |
!BlockContext methodsFor:'printing & storing'! |
1 | 114 |
|
115 |
receiverPrintString |
|
281 | 116 |
"return a printString describing the contexts receiver. |
357 | 117 |
|
118 |
Since this is also used by the debugger(s), be very careful to |
|
281 | 119 |
return something useful, even in case internals of the system |
120 |
got corrupted ... (i.e. avoid messageNotUnderstood here)" |
|
121 |
||
357 | 122 |
|cls who mHome m className |
123 |
sender selSender tryVars possibleBlocks method mWho| |
|
124 |
||
125 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
126 |
" |
|
127 |
mhmh - an optimized blocks context |
|
128 |
should get the block here, and get the method from |
|
129 |
that one ... |
|
130 |
... but in 2.10.x, there is no easy way to get to the block |
|
131 |
since that one is not in the context. |
|
132 |
Starting with 2.11, the new block calling scheme will fix this. |
|
133 |
" |
|
241 | 134 |
|
357 | 135 |
"temporary kludge - peek into the sender context. |
136 |
If its a do-like method and there is a single block variable |
|
137 |
in the args or temporaries, that must be the one. |
|
138 |
This helps in some cases. |
|
139 |
" |
|
140 |
(sender := self sender) notNil ifTrue:[ |
|
141 |
tryVars := false. |
|
142 |
(selSender := sender selector) notNil ifTrue:[ |
|
143 |
(selSender endsWith:'do:') ifTrue:[ |
|
144 |
tryVars := true. |
|
145 |
] ifFalse:[ |
|
146 |
(selSender endsWith:'Do:') ifTrue:[ |
|
147 |
tryVars := true. |
|
148 |
] |
|
149 |
] |
|
150 |
]. |
|
151 |
tryVars ifTrue:[ |
|
152 |
possibleBlocks := sender argsAndVars select:[:v | v isBlock]. |
|
153 |
possibleBlocks := possibleBlocks select:[:b | b home isNil]. |
|
154 |
||
155 |
possibleBlocks size == 1 ifTrue:[ |
|
156 |
method := possibleBlocks first method. |
|
157 |
" |
|
158 |
change the line in the upper-listview |
|
159 |
according the information we have now |
|
160 |
" |
|
161 |
mWho := method who. |
|
162 |
^ '[] (optimized) in ' , |
|
163 |
(mWho at:1) name , '-' , (mWho at:2). |
|
164 |
]. |
|
165 |
] |
|
166 |
]. |
|
167 |
||
165 | 168 |
^ '[] optimized' |
1 | 169 |
]. |
170 |
||
281 | 171 |
mHome := self methodHome. |
172 |
mHome isNil ifTrue:[ |
|
173 |
'BCONTEXT: no methodHome' errorPrintNL. |
|
174 |
^ '[] in ???' |
|
175 |
]. |
|
176 |
||
293 | 177 |
" |
178 |
kludge to avoid slow search for containing class |
|
179 |
" |
|
180 |
mHome selector == #doIt ifTrue:[ |
|
181 |
who := Array with:mHome receiver class |
|
182 |
with:#doIt |
|
183 |
] ifFalse:[ |
|
184 |
m := mHome method. |
|
185 |
m isNil ifTrue:[ |
|
186 |
'BCONTEXT: no method' errorPrintNL. |
|
187 |
^ '[] in ???' |
|
188 |
]. |
|
189 |
who := m who. |
|
281 | 190 |
]. |
241 | 191 |
who notNil ifTrue:[ |
192 |
cls := who at:1 |
|
193 |
] ifFalse:[ |
|
194 |
cls := receiver class. |
|
195 |
]. |
|
281 | 196 |
className := cls name. |
197 |
className isNil ifTrue:[ |
|
198 |
'BCONTEXT: nameless class' errorPrintNL. |
|
199 |
className := '???' |
|
200 |
]. |
|
201 |
^ '[] in ' , className , '-' , mHome selector printString |
|
1 | 202 |
! ! |
623 | 203 |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
204 |
!BlockContext class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
205 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
206 |
version |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
207 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/BContext.st,v 1.20 1996-04-16 09:28:38 cg Exp $' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
208 |
! ! |