author | Claus Gittinger <cg@exept.de> |
Tue, 07 Nov 2006 14:00:21 +0100 | |
changeset 10156 | d35f30a7fde5 |
parent 10136 | 5e82e27705cc |
child 10537 | 9ebc87dd0738 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
154 | 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 |
" |
|
5422 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
1 | 14 |
Object variableSubclass:#Context |
2646 | 15 |
instanceVariableNames:'flags sender* home receiver selector searchClass lineNr |
16 |
retvalTemp handle*' |
|
1334
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
17 |
classVariableNames:'InvalidReturnSignal SingleStepInterruptRequest' |
749 | 18 |
poolDictionaries:'' |
19 |
category:'Kernel-Methods' |
|
1 | 20 |
! |
21 |
||
1810 | 22 |
!Context class methodsFor:'documentation'! |
54 | 23 |
|
88 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
154 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
54 | 38 |
documentation |
39 |
" |
|
402 | 40 |
Contexts represent the stack frame objects, which keep the processing |
41 |
state of a method or block (i.e. its local variables, temporaries etc.) |
|
42 |
Every message send adds a context to a chain, which can be traced back via |
|
43 |
the sender field. The context of the currently active method is always |
|
44 |
accessable via the pseuodoVariable called 'thisContext'. |
|
141 | 45 |
(The actual implementation uses the machines stack for this, building real |
402 | 46 |
contexts on demand only). |
54 | 47 |
|
69 | 48 |
For both method- and block-contexts, the layout is the same. |
402 | 49 |
For method contexts, the home-field is nil, while for block contexts the home- |
141 | 50 |
field is either the context of its surrounding block (i.e. the context of the |
51 |
block, in which the receiving block was created, if its a nested block) or of |
|
52 |
its home method. |
|
53 |
||
54 |
Contexts of cheap blocks do not have a home context - their home field is |
|
55 |
also nil. |
|
54 | 56 |
|
141 | 57 |
Currently, contexts do not contain a reference to the method or block which |
58 |
created it - this is not needed for program execution, but could get the debugger |
|
59 |
somewhat into trouble: it has to search the class hierarchy for receiver/selector |
|
60 |
combinations to find the method. This usually works, but fails in case of methods |
|
61 |
which are not anchored in any class - especially leading to problems with wrapper- |
|
62 |
and lazy methods. Also, Method>>valueWithReceiver - type of invocations cannot |
|
63 |
be easily debugged. |
|
402 | 64 |
Therefore, the implementation may be changed in the near future, to include a |
141 | 65 |
field for the method/block, and set it in the VM during program execution. |
66 |
(there may be some small performance penalty for this, though). |
|
67 |
||
402 | 68 |
LineNumbers vs. program counter: |
69 |
||
70 |
Due to the compilation to machine code, methods and/or block do not |
|
216 | 71 |
always (actually: do seldom) contain bytecodes. Thus, there is no such concept |
72 |
as a bytecode p-counter. To support debugging, the linenumber within the |
|
73 |
original source is instead remembered when a send or loop entry is performed. |
|
74 |
Since linenumbers are not always sufficient for debugging (multiple sends in one |
|
402 | 75 |
line), this may be changed in future versions to a character offset, giving |
216 | 76 |
the position of the selector in the source. |
1 | 77 |
|
402 | 78 |
Restartable / Returnable contexts: |
79 |
||
80 |
In previous versions (up to ST/X 2.10.5), every method stored enough |
|
81 |
information in the context for that one to be restartable later (for example, |
|
82 |
via the debuggers restart button). With 2.10.6, this is now an stc-compiler |
|
83 |
option, and the system as delivered is compiled to only create restartable |
|
84 |
contexts for those which contain blocks. This resulted in an overall speedup of |
|
85 |
roughly 10-20% percent, depending on the type of CPU. However, it makes most |
|
86 |
methods non-restartable (however, abort, signal handling and unwind blocks work |
|
87 |
as usual). |
|
88 |
In practice, this was reported to be not a severe limitation and all users were happy |
|
89 |
to trade the increased performance for that slight inconvenience. |
|
90 |
(during development, this is seldom a problem, since interpreted methods are always |
|
91 |
returnable and restartable) |
|
92 |
If you do not like this (and you are a happy owner of the full distribution), you |
|
93 |
should recompile all classes with stc's '-optContext' flag. |
|
94 |
||
95 |
Resuming contexts: |
|
96 |
||
97 |
Strictly speaking, ST/X does not support a context to be resumed. However, |
|
98 |
it does support a forced return (i.e. non-local-return) from a context. |
|
99 |
Thus, resume of a context is implemented by forcing a return from the context |
|
100 |
which was created by the method called from the first one. The effect is the same. |
|
101 |
||
102 |
Returning from a dead method: |
|
103 |
||
104 |
Blocksreturn from an outlived context (i.e. its home method has already returned) |
|
105 |
is now rewarded by an invalidReturn exception - it used to be a noop in previous |
|
106 |
releases (The blue book described this to be a noop, but other smalltalk implementations |
|
107 |
changed this to be an invalid operation - good decision) |
|
108 |
||
109 |
||
1282 | 110 |
[instance variables:] |
6003 | 111 |
flags <SmallInteger> used by the VM; never touch. |
112 |
contains info about number of args, |
|
113 |
locals and temporaries. |
|
216 | 114 |
|
6003 | 115 |
sender <Context> the 'calling / sending' context |
116 |
This is not directly accessable, since it may |
|
117 |
be a lazy context (i.e. an empty frame). |
|
118 |
The #sender method cares for this. |
|
216 | 119 |
|
6003 | 120 |
home <Context> the context, where this block was |
121 |
created, or nil if its a method context |
|
122 |
There are also cheap blocks, which do |
|
123 |
not need a reference to the home context, |
|
124 |
for those, its nil too. |
|
216 | 125 |
|
6003 | 126 |
receiver <Object> the receiver of this message |
216 | 127 |
|
6003 | 128 |
selector <Symbol> the selector of this message |
216 | 129 |
|
6003 | 130 |
searchClass <Class> the class, where the message lookup started |
131 |
(for super sends) or nil, for regular sends. |
|
141 | 132 |
|
6003 | 133 |
lineNr <SmallInteger> the position where the context left off |
134 |
(kind of p-counter). Only the low 16bits |
|
135 |
are valid. |
|
141 | 136 |
|
6003 | 137 |
retValTemp nil temporary - always nil, when you see the context |
138 |
(used in the VM as temporary) |
|
216 | 139 |
|
6003 | 140 |
handle *noObject* used by the VM; not accessable, not an object |
141 | 141 |
|
6003 | 142 |
<indexed> arguments of the send followed by |
143 |
locals of the method/block followed by |
|
144 |
temporaries. |
|
1 | 145 |
|
6003 | 146 |
[errors:] |
147 |
CannotReturnError raised when a block tries |
|
148 |
to return ('^') from a method context |
|
149 |
which itself has already returned |
|
150 |
(i.e. there is no place to return to) |
|
216 | 151 |
|
69 | 152 |
WARNING: layout and size known by the compiler and runtime system - do not change. |
1282 | 153 |
|
1293 | 154 |
|
155 |
[author:] |
|
6003 | 156 |
Claus Gittinger |
1293 | 157 |
|
1282 | 158 |
[see also:] |
6003 | 159 |
Block Process Method |
160 |
( contexts, stacks & unwinding : programming/contexts.html) |
|
54 | 161 |
" |
162 |
! ! |
|
1 | 163 |
|
1810 | 164 |
!Context class methodsFor:'initialization'! |
105 | 165 |
|
166 |
initialize |
|
6000 | 167 |
"/ InvalidReturnSignal isNil ifTrue:[ |
168 |
"/ InvalidReturnSignal := ErrorSignal newSignalMayProceed:true. |
|
169 |
"/ InvalidReturnSignal nameClass:self message:#invalidReturnSignal. |
|
170 |
"/ InvalidReturnSignal notifierString:'invalid return; method cannot return twice'. |
|
171 |
"/ |
|
172 |
CannotReturnError notifierString:'invalid return; method cannot return twice'. |
|
173 |
CannotResumeError notifierString:'invalid resume'. |
|
1334
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
174 |
|
6000 | 175 |
SingleStepInterruptRequest isNil ifTrue:[ |
176 |
SingleStepInterruptRequest := QuerySignal new. |
|
177 |
SingleStepInterruptRequest nameClass:self message:#singleStepInterruptRequest. |
|
178 |
SingleStepInterruptRequest notifierString:'single step'. |
|
105 | 179 |
] |
1334
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
180 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
181 |
"Modified: 6.5.1996 / 16:46:03 / cg" |
105 | 182 |
! ! |
183 |
||
1810 | 184 |
!Context class methodsFor:'Signal constants'! |
105 | 185 |
|
6000 | 186 |
cannotResumeSignal |
187 |
"return the signal used when a method is tried to be resumed, which cannot" |
|
188 |
||
189 |
^ CannotResumeError |
|
190 |
! |
|
191 |
||
192 |
cannotReturnSignal |
|
193 |
"return the signal used when a method is tried to be returned twice |
|
194 |
or, when some dead context is unwound or restarted." |
|
195 |
||
196 |
^ CannotReturnError |
|
197 |
! |
|
198 |
||
105 | 199 |
invalidReturnSignal |
141 | 200 |
"return the signal used when a method is tried to be returned twice |
201 |
or, when some dead context is unwound or restarted." |
|
202 |
||
8357 | 203 |
<resource: #obsolete> |
6000 | 204 |
self obsoleteMethodWarning:'use #cannotReturnSignal'. |
205 |
^ self cannotReturnSignal. |
|
1334
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
206 |
! |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
207 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
208 |
singleStepInterruptRequest |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
209 |
"return the dummy query signal to ask for single stepping" |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
210 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
211 |
^ SingleStepInterruptRequest |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
212 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
213 |
"Created: 6.5.1996 / 16:46:32 / cg" |
105 | 214 |
! ! |
215 |
||
1810 | 216 |
!Context class methodsFor:'queries'! |
3 | 217 |
|
218 |
isBuiltInClass |
|
1264 | 219 |
"return true if this class is known by the run-time-system. |
220 |
Here, true is returned." |
|
3 | 221 |
|
222 |
^ true |
|
1264 | 223 |
|
224 |
"Modified: 23.4.1996 / 15:58:00 / cg" |
|
3 | 225 |
! ! |
226 |
||
4485 | 227 |
!Context class methodsFor:'special searching'! |
228 |
||
229 |
findFirstSpecialHandle:searchForHandle raise:searchForRaise |
|
230 |
|c| |
|
231 |
||
232 |
%{ |
|
233 |
OBJ __c__; |
|
234 |
||
235 |
__c__ = __ContextInstPtr(__thisContext)->c_sender; |
|
236 |
if (__isLazy(__c__)) { |
|
237 |
__PATCHUPCONTEXT(__c__); |
|
238 |
} |
|
239 |
c = __c__; |
|
240 |
%}. |
|
241 |
^ c findSpecialHandle:searchForHandle raise:searchForRaise |
|
242 |
||
243 |
||
244 |
! ! |
|
245 |
||
7261 | 246 |
!Context methodsFor:'Compatibility-VW'! |
5983 | 247 |
|
248 |
resumeWith:value |
|
249 |
"same as #resume: - visualWorks compatibility" |
|
250 |
||
251 |
self resume:value |
|
252 |
! ! |
|
253 |
||
623 | 254 |
!Context methodsFor:'accessing'! |
255 |
||
256 |
argAt:n |
|
257 |
"return the n'th argument" |
|
258 |
||
1726 | 259 |
n > self numArgs ifTrue:[ |
3143 | 260 |
^ self error:'invalid arg access' |
1726 | 261 |
]. |
623 | 262 |
^ self at:n |
1726 | 263 |
|
264 |
"Modified: 12.10.1996 / 21:44:28 / cg" |
|
623 | 265 |
! |
266 |
||
267 |
argAt:n put:value |
|
268 |
"set the n'th argument - useful when the receiver should be restarted" |
|
154 | 269 |
|
1726 | 270 |
n > self numArgs ifTrue:[ |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
271 |
^ self error:'invalid arg access' |
1726 | 272 |
]. |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
273 |
self at:n put:value. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
274 |
^ value |
1726 | 275 |
|
276 |
"Modified: 12.10.1996 / 21:44:32 / cg" |
|
623 | 277 |
! |
278 |
||
279 |
args |
|
280 |
"return an array filled with the arguments of this context" |
|
281 |
||
282 |
|n| |
|
283 |
||
284 |
n := self numArgs. |
|
3130 | 285 |
n == 0 ifTrue:[ |
286 |
"/ little optimization here - avaoid creating empty containers |
|
287 |
^ #() |
|
288 |
]. |
|
623 | 289 |
^ (Array new:n) replaceFrom:1 to:n with:self. |
290 |
! |
|
154 | 291 |
|
623 | 292 |
argsAndVars |
293 |
"return an array filled with the arguments and variables of this context" |
|
294 |
||
295 |
|n| |
|
296 |
||
1810 | 297 |
n := self numArgs + self numVars. |
3130 | 298 |
n == 0 ifTrue:[ |
3143 | 299 |
"/ little optimization here - avoid creating empty containers |
3130 | 300 |
^ #() |
301 |
]. |
|
623 | 302 |
^ (Array new:n) replaceFrom:1 to:n with:self. |
1810 | 303 |
|
304 |
"Modified: 23.10.1996 / 16:19:41 / cg" |
|
623 | 305 |
! |
154 | 306 |
|
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
307 |
argumentCount |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
308 |
"ANSI alias for numArgs: return the number of arguments to the Block/Method" |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
309 |
|
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
310 |
%{ /* NOCONTEXT */ |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
311 |
|
8913 | 312 |
RETURN ( __mkSmallInteger( (__intVal(__INST(flags)) >> __NARG_SHIFT) & __NARG_MASK) ); |
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
313 |
%} |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
314 |
! |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
315 |
|
7324
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
316 |
at:n put:value |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
317 |
super at:n put:value. |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
318 |
|
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
319 |
"/ need some aid for optimized code - |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
320 |
"/ some machines have the arguments/receiver etc. kept in register vars ... |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
321 |
"/ the unfix updates the machine-stack version of the receiver. |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
322 |
%{ |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
323 |
__UNFIXCONTEXT(self, 0); |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
324 |
%}. |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
325 |
^ value |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
326 |
! |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
327 |
|
623 | 328 |
home |
329 |
"return the immediate home of the receiver. |
|
330 |
for block contexts, this is the methodcontext, where the block was created, |
|
331 |
for nested block contexts, its the surrounding blocks context. |
|
332 |
for method-contexts this is nil." |
|
25 | 333 |
|
623 | 334 |
^ nil "home" |
335 |
! |
|
1 | 336 |
|
3324
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
337 |
homeReceiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
338 |
"return the receiver from the context, where the receiver was defined" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
339 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
340 |
^ receiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
341 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
342 |
"Created: / 5.3.1998 / 16:18:26 / stefan" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
343 |
! |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
344 |
|
1 | 345 |
instVarAt:index |
69 | 346 |
"have to catch instVar access to retVal and handle - they are invalid. |
347 |
Notice, that one of the next ST/X versions will get some syntactic |
|
348 |
extension to get this automatically)." |
|
1 | 349 |
|
3508 | 350 |
(index == 2) ifTrue:[^ self sender]."/ sender - must be accessed specially |
3182
2526de1e5030
dont allow setting of the sender via instVarAt:put:
Claus Gittinger <cg@exept.de>
parents:
3143
diff
changeset
|
351 |
(index == 8) ifTrue:[^ nil]. "/ retvalTemp - invisible |
2526de1e5030
dont allow setting of the sender via instVarAt:put:
Claus Gittinger <cg@exept.de>
parents:
3143
diff
changeset
|
352 |
(index == 9) ifTrue:[^ nil]. "/ handle to machine stack - invisible |
1 | 353 |
^ super instVarAt:index |
354 |
! |
|
355 |
||
356 |
instVarAt:index put:value |
|
69 | 357 |
"have to catch instVar access to retVal and handle - they are invalid. |
358 |
Notice, that one of the next ST/X versions will get some syntactic |
|
359 |
extension to get this automatically)." |
|
1 | 360 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
361 |
(index == 2) ifTrue:[^ nil]. "/ sender - not allowed to change |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
362 |
(index == 8) ifTrue:[^ nil]. "/ retvalTemp - not allowed to change |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
363 |
(index == 9) ifTrue:[^ nil]. "/ handle to machine stack - not allowed to change |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
364 |
super instVarAt:index put:value. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
365 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
366 |
"/ need some aid for optimized code - |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
367 |
"/ some machines have the arguments kept in register vars ... |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
368 |
"/ the unfix updates the machine-stack version of the receiver. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
369 |
%{ |
4570 | 370 |
__UNFIXCONTEXT(self, 0); |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
371 |
%}. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
372 |
^ value |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
373 |
|
1 | 374 |
! |
375 |
||
4328
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
376 |
javaLineNumber |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
377 |
|nr pc| |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
378 |
|
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
379 |
lineNr notNil ifTrue:[ |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
380 |
pc := lineNr bitAnd:16rFFFF. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
381 |
]. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
382 |
|
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
383 |
"/ 'ask line for pc:' print. pc printCR. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
384 |
pc isNil ifTrue:[ |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
385 |
nr := self lineNumberFromMethod. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
386 |
nr notNil ifTrue:[ |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
387 |
^ nr |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
388 |
]. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
389 |
" '-> 0 [a]' printCR. " |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
390 |
^0 |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
391 |
]. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
392 |
|
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
393 |
nr := self method lineNumberForPC:pc. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
394 |
nr isNil ifTrue:[ |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
395 |
nr := self lineNumberFromMethod. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
396 |
nr notNil ifTrue:[ |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
397 |
^ nr |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
398 |
]. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
399 |
" '-> 0 [b]' printCR. " |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
400 |
^ 0 |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
401 |
]. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
402 |
"/ '-> ' print. nr printCR. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
403 |
^ nr. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
404 |
|
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
405 |
! |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
406 |
|
623 | 407 |
lineNumber |
408 |
"this returns the lineNumber within the methods source, where the context was |
|
409 |
interrupted or called another method. (currently, sometimes this information |
|
410 |
is not available - in this case 0 is returned)" |
|
1 | 411 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
412 |
|l| |
3923 | 413 |
|
4328
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
414 |
receiver isJavaObject ifTrue:[ |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
415 |
"/ chances are good that I am a javContext ... |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
416 |
self method isJavaMethod ifTrue:[ |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
417 |
^ self javaLineNumber |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
418 |
] |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
419 |
]. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
420 |
|
3923 | 421 |
lineNr notNil ifTrue:[ |
422 |
l := lineNr bitAnd:16rFFFF. |
|
423 |
]. |
|
424 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
425 |
"/ self isJavaContext ifTrue:[ |nr m| |
3923 | 426 |
"/ m := self method. |
427 |
"/ l isNil ifTrue:[ |
|
428 |
"/ m notNil ifTrue:[ |
|
429 |
"/ nr := m lineNumber |
|
430 |
"/ ]. |
|
431 |
"/ nr notNil ifTrue:[ |
|
432 |
"/ ^ nr |
|
433 |
"/ ]. |
|
434 |
"/ ^0 |
|
435 |
"/ ]. |
|
436 |
"/ nr := self method lineNumberForPC:l. |
|
437 |
"/ nr isNil ifTrue:[ |
|
438 |
"/ m notNil ifTrue:[ |
|
439 |
"/ nr := m lineNumber |
|
440 |
"/ ]. |
|
441 |
"/ nr notNil ifTrue:[ |
|
442 |
"/ ^ nr |
|
443 |
"/ ]. |
|
444 |
"/ ^ 0 |
|
445 |
"/ ]. |
|
446 |
"/ ^ nr. |
|
447 |
"/ ]. |
|
448 |
||
449 |
^ l |
|
450 |
||
451 |
"Modified: / 10.11.1998 / 13:19:48 / cg" |
|
1 | 452 |
! |
453 |
||
4450 | 454 |
lineNumberFromMethod |
455 |
^ 1 |
|
456 |
! |
|
457 |
||
8488 | 458 |
message |
459 |
^ Message selector:selector arguments:self args |
|
460 |
||
461 |
" |
|
9355 | 462 |
thisContext methodHome message |
463 |
thisContext message |
|
8488 | 464 |
" |
465 |
! |
|
466 |
||
1 | 467 |
method |
54 | 468 |
"return the method for which the receiver was created. |
469 |
To save time during normal execution, this information is not held in the |
|
470 |
context, but computed here on request." |
|
1 | 471 |
|
3508 | 472 |
|c sender sendersSelector m| |
1 | 473 |
|
325 | 474 |
c := self searchClass. |
475 |
" |
|
476 |
the below cannot happen in normal circumstances |
|
477 |
(added to avoid recursive errors in case of a broken sender chain) |
|
478 |
" |
|
479 |
c isBehavior ifFalse:[ |
|
3143 | 480 |
'Context [error]: non class in searchClass' errorPrintCR. |
481 |
' selector: ' errorPrint. selector errorPrint. |
|
482 |
' receiver: ' errorPrint. receiver errorPrintCR. |
|
483 |
^ nil |
|
325 | 484 |
]. |
485 |
||
328 | 486 |
c := c whichClassIncludesSelector:selector. |
1 | 487 |
c notNil ifTrue:[ |
3143 | 488 |
^ c compiledMethodAt:selector |
1 | 489 |
]. |
216 | 490 |
|
3508 | 491 |
"mhmh - seems to be a context for an unbound method (as generated by doIt); |
216 | 492 |
look in the senders context. Consider this a kludge. |
3143 | 493 |
(maybe it was not too good of an idea to NOT keep the current |
494 |
method in the context ...) |
|
495 |
Future versions of ST/X's message lookup may store the method in |
|
496 |
the context. |
|
216 | 497 |
" |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
498 |
sender := self sender. |
3143 | 499 |
sender notNil ifTrue:[ |
500 |
sendersSelector := sender selector. |
|
501 |
sendersSelector notNil ifTrue:[ |
|
502 |
(sendersSelector startsWith:'valueWithReceiver:') ifTrue:[ |
|
3508 | 503 |
m := sender receiver. |
504 |
m isMethod ifTrue:[ |
|
505 |
^ m |
|
506 |
] |
|
3143 | 507 |
] |
508 |
] |
|
216 | 509 |
]. |
510 |
||
1 | 511 |
^ nil |
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
512 |
|
3143 | 513 |
"Modified: / 4.1.1998 / 21:15:32 / cg" |
1 | 514 |
! |
515 |
||
212 | 516 |
methodClass |
517 |
"return the class in which the method for which the receiver was created is." |
|
518 |
||
1456 | 519 |
|cls m| |
520 |
||
521 |
cls := self searchClass. |
|
3923 | 522 |
(cls isMeta |
523 |
and:[cls soleInstance isJavaClass]) ifTrue:[ |
|
524 |
cls := cls soleInstance |
|
525 |
]. |
|
1456 | 526 |
|
3923 | 527 |
[cls notNil] whileTrue:[ |
528 |
cls := cls whichClassIncludesSelector:selector. |
|
529 |
cls isNil ifTrue:[^ nil]. |
|
530 |
||
531 |
m := cls compiledMethodAt:selector. |
|
532 |
m notNil ifTrue:[ |
|
533 |
m isIgnored ifFalse:[^ cls]. |
|
534 |
]. |
|
535 |
cls := cls superclass |
|
1456 | 536 |
]. |
537 |
^ cls |
|
538 |
||
3923 | 539 |
"Modified: / 5.11.1998 / 19:07:43 / cg" |
212 | 540 |
! |
541 |
||
623 | 542 |
methodHome |
543 |
"return the method-home - for method contexts this is the receiver" |
|
544 |
||
545 |
^ self |
|
546 |
! |
|
547 |
||
548 |
ntemp |
|
549 |
"return the number of temporary variables of the Block/Method. |
|
1810 | 550 |
(for debugging only). |
551 |
I dont like the name of this method; its here for compatibility." |
|
623 | 552 |
|
1810 | 553 |
^ self numTemps |
554 |
||
555 |
"Modified: 23.10.1996 / 16:19:06 / cg" |
|
623 | 556 |
! |
557 |
||
558 |
numArgs |
|
559 |
"return the number of arguments to the Block/Method" |
|
560 |
||
561 |
%{ /* NOCONTEXT */ |
|
562 |
||
8913 | 563 |
RETURN ( __mkSmallInteger( (__intVal(__INST(flags)) >> __NARG_SHIFT) & __NARG_MASK) ); |
623 | 564 |
%} |
565 |
! |
|
566 |
||
1810 | 567 |
numTemps |
568 |
"return the number of temporary variables of the Block/Method. |
|
569 |
(for debugging only)" |
|
570 |
||
571 |
^ self size - self numArgs - self numVars |
|
572 |
||
573 |
"Created: 23.10.1996 / 16:19:10 / cg" |
|
574 |
"Modified: 23.10.1996 / 16:19:48 / cg" |
|
575 |
! |
|
576 |
||
577 |
numVars |
|
623 | 578 |
"return the number of local variables of the Block/Method" |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
579 |
|
623 | 580 |
%{ /* NOCONTEXT */ |
581 |
||
8913 | 582 |
RETURN ( __mkSmallInteger( (__intVal(__INST(flags)) >> __NVAR_SHIFT) & __NVAR_MASK) ); |
623 | 583 |
%} |
584 |
! |
|
585 |
||
1810 | 586 |
nvars |
587 |
"return the number of local variables of the Block/Method. |
|
588 |
I dont like the name of this method; its here for compatibility." |
|
589 |
||
590 |
^ self numVars |
|
591 |
||
592 |
"Modified: 23.10.1996 / 16:18:44 / cg" |
|
593 |
! |
|
594 |
||
623 | 595 |
receiver |
596 |
"return the receiver of the context" |
|
597 |
||
598 |
^ receiver |
|
599 |
! |
|
600 |
||
4543 | 601 |
receiver:aCompiledCode |
602 |
"set the receiver of the message" |
|
603 |
||
4560
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
604 |
receiver := aCompiledCode. |
4543 | 605 |
|
4560
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
606 |
"/ need some aid for optimized code - |
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
607 |
"/ some machines have the arguments kept in register vars ... |
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
608 |
"/ the unfix updates the machine-stack version of the receiver. |
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
609 |
%{ |
4570 | 610 |
__UNFIXCONTEXT(self, 0); |
4560
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
611 |
%}. |
4543 | 612 |
|
613 |
! |
|
614 |
||
623 | 615 |
searchClass |
616 |
"this is the class where the method-lookup started; |
|
617 |
for normal sends, it is nil (or sometimes the receivers class). |
|
618 |
For supersends, its the superclass of the one, in which the |
|
619 |
caller was defined." |
|
620 |
||
621 |
searchClass notNil ifTrue:[^ searchClass]. |
|
622 |
^ receiver class |
|
623 |
! |
|
624 |
||
625 |
selector |
|
626 |
"return the selector of the method for which the context was created" |
|
627 |
||
628 |
^ selector |
|
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
629 |
! |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
630 |
|
1 | 631 |
sender |
632 |
"return the sender of the context" |
|
633 |
||
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
634 |
%{ /* NOCONTEXT */ |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
635 |
OBJ theContext; |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
636 |
|
3508 | 637 |
theContext = __INST(sender_); |
949 | 638 |
/* |
639 |
* this special nil test is for the very first context (startup-context); |
|
640 |
* actually, its cosmetics, to avoid a visible nil>>nil context in the debugger. |
|
641 |
*/ |
|
2205 | 642 |
if (__isNonNilObject(theContext)) { |
949 | 643 |
|
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
644 |
if (__isLazy(theContext)) { |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
645 |
/* |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
646 |
* this cannot happen |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
647 |
*/ |
2212 | 648 |
__PATCHUPCONTEXT(theContext); |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
649 |
} |
3508 | 650 |
if (! __isNonLIFO(theContext)) { |
651 |
/* |
|
652 |
* to be prepared for the worst situation |
|
653 |
* (the sender is not stored, so the trap wont catch it) |
|
654 |
* make the writeBarrier trigger manually. |
|
655 |
* We'll see, if this is really required. |
|
656 |
*/ |
|
657 |
theContext->o_space |= CATCHMARK; |
|
658 |
_markNonLIFO(theContext); |
|
659 |
} |
|
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
660 |
} |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
661 |
RETURN (theContext); |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
662 |
%} |
1 | 663 |
! |
664 |
||
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
665 |
senderIsNil |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
666 |
"return true, if I have no sender" |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
667 |
|
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
668 |
%{ /* NOCONTEXT */ |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
669 |
if ( __INST(sender_) == nil ) { |
5422 | 670 |
RETURN (true); |
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
671 |
} |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
672 |
RETURN (false); |
5422 | 673 |
%}. |
674 |
^ self sender isNil |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
675 |
! |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
676 |
|
623 | 677 |
setLineNumber:aNumber |
678 |
"private entry for uncompiledCodeObject ..." |
|
1 | 679 |
|
623 | 680 |
lineNr := aNumber |
340 | 681 |
! |
682 |
||
5749 | 683 |
setNumArgs:nA numVars:nV |
684 |
"set the number of arguments and variables" |
|
685 |
||
686 |
%{ /* NOCONTEXT */ |
|
8910 | 687 |
INT flg; |
5749 | 688 |
|
689 |
flg = __intVal(__INST(flags)); |
|
690 |
flg = flg & ~(__NARG_MASK << __NARG_SHIFT); |
|
691 |
flg = flg & ~(__NVAR_MASK << __NVAR_SHIFT); |
|
692 |
flg = flg | __intVal(nA) << __NARG_SHIFT; |
|
693 |
flg = flg | __intVal(nV) << __NVAR_SHIFT; |
|
8913 | 694 |
__INST(flags) = __mkSmallInteger(flg); |
5749 | 695 |
%} |
696 |
! |
|
697 |
||
8578 | 698 |
tempAt:index |
699 |
"return the n'th stack-temporary variable" |
|
700 |
||
701 |
^ self at:index |
|
702 |
! |
|
703 |
||
202 | 704 |
temporaries |
705 |
"return an array filled with the temporaries of this context" |
|
706 |
||
308 | 707 |
|nonTemps mySize| |
202 | 708 |
|
1810 | 709 |
nonTemps := self numArgs + self numVars. |
710 |
mySize := self numTemps. |
|
3130 | 711 |
mySize == 0 ifTrue:[ |
712 |
"/ little optimization here - avaoid creating empty containers |
|
713 |
^ #() |
|
714 |
]. |
|
308 | 715 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonTemps+1 |
1810 | 716 |
|
717 |
"Modified: 23.10.1996 / 16:20:00 / cg" |
|
202 | 718 |
! |
719 |
||
10 | 720 |
varAt:n |
721 |
"return the n'th local variable" |
|
722 |
||
154 | 723 |
^ self at:(n + self numArgs) |
10 | 724 |
! |
725 |
||
726 |
varAt:n put:value |
|
727 |
"set the n'th local variable - useful when the receiver should be restarted |
|
54 | 728 |
or continued" |
10 | 729 |
|
154 | 730 |
self at:(n + self numArgs) put:value |
10 | 731 |
! |
732 |
||
623 | 733 |
vars |
734 |
"return an array filled with the local variables of this context" |
|
375 | 735 |
|
623 | 736 |
|nonVars mySize| |
360 | 737 |
|
623 | 738 |
nonVars := self numArgs. |
1810 | 739 |
mySize := self numVars. |
3130 | 740 |
mySize == 0 ifTrue:[ |
741 |
"/ little optimization here - avaoid creating empty containers |
|
742 |
^ #() |
|
743 |
]. |
|
623 | 744 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonVars+1 |
1810 | 745 |
|
746 |
"Modified: 23.10.1996 / 16:20:06 / cg" |
|
1 | 747 |
! ! |
748 |
||
623 | 749 |
!Context methodsFor:'copying'! |
415 | 750 |
|
3350
40dc4807a6d4
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
3324
diff
changeset
|
751 |
deepCopyUsing:aDictionary |
623 | 752 |
"raise an error - deepCopy is not allowed for contexts" |
37 | 753 |
|
10136 | 754 |
|copyOfMe| |
3350
40dc4807a6d4
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
3324
diff
changeset
|
755 |
|
10136 | 756 |
copyOfMe := self shallowCopy. |
757 |
copyOfMe setSender:nil. |
|
758 |
^ copyOfMe |
|
759 |
||
760 |
"Created: / 31-03-1998 / 15:51:14 / cg" |
|
761 |
"Modified: / 20-10-2006 / 14:54:12 / User" |
|
1 | 762 |
! ! |
763 |
||
77 | 764 |
!Context methodsFor:'error handling'! |
765 |
||
766 |
invalidReturn:returnValue |
|
767 |
"this message is sent by the VM, when a methods context |
|
768 |
which has already returned is about to return again. |
|
769 |
(i.e. about to execute a return from an already returned |
|
105 | 770 |
method in a block). |
141 | 771 |
We raise a signal here, to allow catching of that situation." |
77 | 772 |
|
406 | 773 |
" |
774 |
in previous versions of ST/X and ST-80, this was no error; |
|
775 |
(instead, a normal blockreturn was performed to the value-sender). |
|
776 |
From a note in comp.lang.smalltalk, I conclude that new ST-80 versions |
|
777 |
now raise an error if this happens. |
|
778 |
Comment out the raise below to get that (old) behavior |
|
779 |
BETTER REWRITE YOUR APPLICATION |
|
780 |
" |
|
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
781 |
"/ old behavior: |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
782 |
"/ ^ returnValue |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
783 |
|
282 | 784 |
"/ new behavior: |
785 |
||
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
786 |
"/ if this context is one of another process, |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
787 |
"/ use another error message. |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
788 |
|
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
789 |
(home notNil and:[home sender notNil]) ifTrue:[ |
6002 | 790 |
^ CannotReturnError |
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
791 |
raiseRequestWith:returnValue |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
792 |
errorString:'cannot return from another process''s context'. |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
793 |
]. |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
794 |
|
6002 | 795 |
^ CannotReturnError |
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
796 |
raiseRequestWith:returnValue. |
282 | 797 |
|
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
798 |
"Modified: / 2.2.1998 / 15:19:52 / cg" |
406 | 799 |
! |
800 |
||
801 |
invalidReturnOrRestart:returnValue |
|
802 |
"this message is sent by the VM, when a methods context |
|
803 |
which was compiled non-returnable is about to return again. |
|
804 |
We raise a signal here, to allow catching of that situation." |
|
805 |
||
6002 | 806 |
^ CannotReturnError |
807 |
raiseRequestWith:returnValue |
|
808 |
errorString:'method was compiled non-resumable' |
|
360 | 809 |
! |
810 |
||
811 |
invalidReturnOrRestartError:how with:value |
|
812 |
"common error reporter for restart/return errors" |
|
813 |
||
814 |
self canReturn ifTrue:[ |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
815 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
816 |
tried to return from/restart a context which is already dead |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
817 |
(i.e. the method/block has already executed a return) |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
818 |
" |
6002 | 819 |
^ CannotReturnError |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
820 |
raiseRequestWith:value |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
821 |
errorString:(how , ' context not on calling chain') |
360 | 822 |
]. |
823 |
" |
|
824 |
tried to return from/restart a context of a method which was compiled |
|
825 |
unrestartable or of a block (which is never restartable) |
|
826 |
" |
|
6002 | 827 |
^ CannotReturnError |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
828 |
raiseRequestWith:value |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
829 |
errorString:(how , ' context cannot be restarted/returned from') |
77 | 830 |
! ! |
831 |
||
6404 | 832 |
!Context methodsFor:'fixups'! |
833 |
||
834 |
fixAllLineNumbers |
|
835 |
%{ |
|
836 |
__PATCHUPCONTEXTS(__thisContext); |
|
6424 | 837 |
__CONTEXTLINENOS(self); |
6404 | 838 |
%} |
839 |
! ! |
|
840 |
||
623 | 841 |
!Context methodsFor:'minidebugger printing'! |
842 |
||
843 |
fullPrint |
|
844 |
"print the receiver, selector and args of the context |
|
845 |
- used only for MiniDebuggers walkback print" |
|
846 |
||
847 |
self receiverPrintString print. ' ' print. selector print. |
|
848 |
self size ~~ 0 ifTrue: [ |
|
3143 | 849 |
' ' print. self argsDisplayString print |
623 | 850 |
]. |
1426 | 851 |
' [' print. self lineNumber print. ']' printCR |
623 | 852 |
|
853 |
" |
|
854 |
thisContext fullPrint |
|
855 |
" |
|
1426 | 856 |
|
857 |
"Modified: 20.5.1996 / 10:27:14 / cg" |
|
623 | 858 |
! |
859 |
||
860 |
fullPrintAll |
|
861 |
"print a full walkback starting at the receiver |
|
862 |
- used only for MiniDebuggers walkback print" |
|
863 |
||
864 |
|context| |
|
865 |
||
866 |
context := self. |
|
867 |
[context notNil] whileTrue: [ |
|
868 |
context fullPrint. |
|
869 |
context := context sender |
|
870 |
] |
|
871 |
||
872 |
" |
|
873 |
thisContext fullPrintAll |
|
874 |
" |
|
2173 | 875 |
! |
876 |
||
4674 | 877 |
fullPrintAllLevels:nOrNil |
878 |
"print a full walkback starting at the receiver, only print n levels |
|
879 |
- used only for MiniDebuggers walkback print" |
|
880 |
||
881 |
|context count| |
|
882 |
||
883 |
count := 0. |
|
884 |
context := self. |
|
885 |
[context notNil] whileTrue: [ |
|
886 |
context fullPrint. |
|
887 |
context := context sender. |
|
5911 | 888 |
nOrNil notNil ifTrue:[ |
4674 | 889 |
(count := count+1) > nOrNil ifTrue:[^self]. |
890 |
] |
|
891 |
] |
|
892 |
||
893 |
" |
|
6648 | 894 |
thisContext fullPrintAllLevels:5 |
4674 | 895 |
" |
896 |
||
897 |
"Created: / 3.9.1999 / 14:02:38 / ps" |
|
623 | 898 |
! ! |
899 |
||
1 | 900 |
!Context methodsFor:'non local control flow'! |
901 |
||
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
902 |
evaluateUnwindActionsUpTo:aContext |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
903 |
"walk up the calling chain, looking for unwind-cleanup actions to |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
904 |
be performed. This depends upon those contexts being specially |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
905 |
marked using #markForUnwind. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
906 |
Returns the argument (i.e. non-nil), if all went well, |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
907 |
nil if aContext is not on the caller chain (definitely an error)" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
908 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
909 |
|con unwindBlock| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
910 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
911 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
912 |
start with this context, moving up, looking for unwind actions |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
913 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
914 |
con := self findNextUnwindContextOr:aContext. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
915 |
[con notNil and:[con ~~ aContext]] whileTrue:[ |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
916 |
unwindBlock := con receiver unwindHandlerInContext:con. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
917 |
con unmarkForUnwind. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
918 |
unwindBlock value. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
919 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
920 |
con := con findNextUnwindContextOr:aContext. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
921 |
]. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
922 |
^ con |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
923 |
! |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
924 |
|
1 | 925 |
restart |
926 |
"restart the receiver - i.e. the method is evaluated again. |
|
402 | 927 |
if the context to restart already died, trigger an error. |
141 | 928 |
This is a low level helper for unwindAndRestart. |
929 |
||
930 |
NOTICE: |
|
154 | 931 |
NO unwind actions are performed - this is usually not |
932 |
what you want (see Context>>unwindAndRestart). |
|
141 | 933 |
|
934 |
LIMITATION: |
|
154 | 935 |
currently a context can only be restarted by |
928 | 936 |
the owning process - not from outside. |
937 |
Also, the compiler has an option (+optcontext) to create |
|
938 |
non-restartable contexts (which are faster). |
|
939 |
If such a context is restarted, a runtime error is raised." |
|
1 | 940 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
941 |
%{ /* NOCONTEXT */ |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
942 |
if (__INST(sender_) != nil) { |
3143 | 943 |
__RESUMECONTEXT__(self, RESTART_VALUE, 0); |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
944 |
} |
360 | 945 |
%}. |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
946 |
self sender isNil ifTrue:[^ nil]. |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
947 |
|
69 | 948 |
" |
360 | 949 |
when we arrive here, something went wrong. |
69 | 950 |
debugging ... |
951 |
" |
|
360 | 952 |
^ self invalidReturnOrRestartError:#restart with:nil |
1 | 953 |
! |
954 |
||
623 | 955 |
resume |
956 |
"resume execution in this context. I.e. as if the method called |
|
957 |
last by the receiver did a ^ nil. |
|
958 |
If the context has already returned, report an error. |
|
959 |
||
960 |
NOTICE: |
|
961 |
NO unwind actions are performed (see Context>>unwind). |
|
962 |
||
963 |
LIMITATION: |
|
964 |
currently a context can only be resumed by |
|
928 | 965 |
the owning process - not from outside. |
966 |
Also, the compiler has an option (+optcontext) to create |
|
967 |
non-resumable contexts (which are faster). |
|
968 |
If such a context is restarted, a runtime error is raised." |
|
623 | 969 |
|
970 |
^ self resume:nil |
|
971 |
! |
|
972 |
||
973 |
resume:value |
|
974 |
"resume the receiver - as if it got 'value' from whatever |
|
975 |
it called. This continues execution in the receivers method |
|
976 |
after the point where it did its last send. |
|
977 |
If the context has already returned - report an error. |
|
978 |
||
979 |
NOTICE: |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
980 |
NO unwind actions are performed (see Context>>unwind:). |
623 | 981 |
|
982 |
LIMITATION: |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
983 |
currently a context can only be resumed by |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
984 |
the owning process - not from outside. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
985 |
Also, the compiler has an option (+optcontext) to create |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
986 |
non-resumable contexts (which are faster). |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
987 |
If such a context is restarted, a runtime error is raised." |
623 | 988 |
|
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
989 |
|theContext| |
623 | 990 |
|
991 |
" |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
992 |
starting with this context, find the one below |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
993 |
(i.e. the one that I have called) and return from it. |
623 | 994 |
" |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
995 |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
996 |
%{ |
4557 | 997 |
OBJ sndr; |
998 |
||
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
999 |
theContext = __thisContext; |
4557 | 1000 |
while (theContext != nil) { |
1001 |
sndr = __ContextInstPtr(theContext)->c_sender; |
|
1002 |
if (sndr == self) break; |
|
1003 |
theContext = sndr; |
|
623 | 1004 |
} |
3508 | 1005 |
if (theContext != nil) { |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1006 |
if (__isLazy(theContext)) { |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1007 |
__PATCHUPCONTEXT(theContext); |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1008 |
} |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1009 |
} |
623 | 1010 |
%}. |
1011 |
||
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
1012 |
theContext isNil ifTrue:[ |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1013 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1014 |
tried to resume in context which is already dead |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1015 |
(i.e. the method/block has already executed a return) |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1016 |
" |
4557 | 1017 |
^ thisContext invalidReturnOrRestartError:#'resume:' with:value |
623 | 1018 |
]. |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
1019 |
^ theContext return:value |
623 | 1020 |
! |
1021 |
||
4557 | 1022 |
resumeIgnoringErrors:value |
1023 |
"resume the receiver - as if it got 'value' from whatever |
|
1024 |
it called. This continues execution in the receivers method |
|
1025 |
after the point where it did its last send. |
|
1026 |
If the context has already returned - simply return. |
|
1027 |
||
1028 |
NOTICE: |
|
1029 |
NO unwind actions are performed (see Context>>unwind:). |
|
1030 |
||
1031 |
LIMITATION: |
|
1032 |
currently a context can only be resumed by |
|
1033 |
the owning process - not from outside. |
|
1034 |
Also, the compiler has an option (+optcontext) to create |
|
1035 |
non-resumable contexts (which are faster). |
|
1036 |
If such a context is restarted, a runtime error is raised." |
|
1037 |
||
1038 |
" |
|
1039 |
starting with this context, find the one below |
|
1040 |
(i.e. the one that I have called) and return from it. |
|
1041 |
" |
|
1042 |
||
1043 |
%{ |
|
1044 |
OBJ theContext, sndr; |
|
1045 |
||
1046 |
theContext = __thisContext; |
|
1047 |
while (theContext != nil) { |
|
1048 |
sndr = __ContextInstPtr(theContext)->c_sender; |
|
1049 |
if (sndr == self) break; |
|
1050 |
theContext = sndr; |
|
1051 |
} |
|
1052 |
if (theContext != nil) { |
|
1053 |
if (__ContextInstPtr(theContext)->c_sender) { |
|
4635 | 1054 |
if (!((INT)(__ContextInstPtr(theContext)->c_flags) & __MASKSMALLINT(__CANNOT_RETURN))) { |
1055 |
__RESUMECONTEXT__(theContext, value, 0); |
|
1056 |
} |
|
4557 | 1057 |
} |
1058 |
} |
|
1059 |
%}. |
|
1060 |
||
1061 |
"/ no error reporting |
|
1062 |
! |
|
1063 |
||
1064 |
resumeOnErrorProceed:value |
|
1065 |
"resume the receiver - as if it got 'value' from whatever |
|
1066 |
it called. This continues execution in the receivers method |
|
1067 |
after the point where it did its last send. |
|
1068 |
If the context has already returned - simply return. |
|
1069 |
||
1070 |
NOTICE: |
|
1071 |
NO unwind actions are performed (see Context>>unwind:). |
|
1072 |
||
1073 |
LIMITATION: |
|
1074 |
currently a context can only be resumed by |
|
1075 |
the owning process - not from outside. |
|
1076 |
Also, the compiler has an option (+optcontext) to create |
|
1077 |
non-resumable contexts (which are faster). |
|
1078 |
If such a context is restarted, a runtime error is raised." |
|
1079 |
||
1080 |
" |
|
1081 |
starting with this context, find the one below |
|
1082 |
(i.e. the one that I have called) and return from it. |
|
1083 |
" |
|
1084 |
||
1085 |
%{ |
|
1086 |
OBJ theContext, sndr; |
|
1087 |
||
1088 |
theContext = __thisContext; |
|
1089 |
while (theContext != nil) { |
|
1090 |
sndr = __ContextInstPtr(theContext)->c_sender; |
|
1091 |
if (sndr == self) break; |
|
1092 |
theContext = sndr; |
|
1093 |
} |
|
1094 |
if (theContext != nil) { |
|
1095 |
if (__ContextInstPtr(theContext)->c_sender) { |
|
1096 |
__RESUMECONTEXT__(theContext, value, 0); |
|
1097 |
} |
|
1098 |
} |
|
1099 |
%}. |
|
1100 |
||
1101 |
"/ no error reporting |
|
1102 |
! |
|
1103 |
||
69 | 1104 |
return |
141 | 1105 |
"return from this context with nil. I.e. as if it did a ^ nil. |
1106 |
NOTICE: |
|
154 | 1107 |
NO unwind actions are performed - this is usually not |
1108 |
what you want (See Context>>unwind). |
|
1109 |
This is a low level method - a helper for unwind. |
|
1 | 1110 |
|
141 | 1111 |
LIMITATION: |
154 | 1112 |
currently a context can only be returned by |
928 | 1113 |
the owning process - not from outside. |
1114 |
Also, the compiler has an option (+optcontext) to create |
|
1115 |
non-returnable contexts (which are faster). |
|
1116 |
If such a context is restarted, a runtime error is raised." |
|
141 | 1117 |
|
1118 |
^ self return:nil |
|
1 | 1119 |
! |
1120 |
||
69 | 1121 |
return:value |
1122 |
"return from this context as if it did a '^ value'. |
|
141 | 1123 |
NOTICE: |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1124 |
NO unwind actions are performed - this is usually not |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1125 |
what you want (See Context>>unwind:). |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1126 |
This is a low level method - a helper for unwind. |
141 | 1127 |
|
1128 |
LIMITATION: |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1129 |
currently a context can only be returned by |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1130 |
the owning process - not from outside. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1131 |
Also, the compiler has an option (+optcontext) to create |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1132 |
non-returnable contexts (which are faster). |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1133 |
If such a context is restarted, a runtime error is raised." |
1 | 1134 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1135 |
%{ /* NOCONTEXT */ |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1136 |
if (__INST(sender_) != nil) { |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1137 |
__RESUMECONTEXT__(self, value, 0); |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1138 |
} |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1139 |
%}. |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1140 |
self sender isNil ifTrue:[^ nil]. |
1 | 1141 |
|
69 | 1142 |
" |
360 | 1143 |
when we arrive here, something went wrong. |
69 | 1144 |
debugging ... |
1145 |
" |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1146 |
^ self invalidReturnOrRestartError:#'return' with:value |
1 | 1147 |
! |
1148 |
||
328 | 1149 |
returnDoing:aBlock |
1150 |
"return from this context as if it did a '^ aBlock value'. |
|
1151 |
The block is evaluated as if called by the receiver context; |
|
1152 |
NOT the true executing context. |
|
1153 |
NOTICE: |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1154 |
NO unwind actions are performed - this is usually not |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1155 |
what you want (See Context>>unwindThenDo:). |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1156 |
This is a low level method - a helper for unwind. |
328 | 1157 |
|
1158 |
LIMITATION: |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1159 |
currently a context can only be returned by |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1160 |
the owning process - not from outside. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1161 |
Also, the compiler has an option (+optcontext) to create |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1162 |
non-returnable contexts (which are faster). |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1163 |
If such a context is restarted, a runtime error is raised." |
328 | 1164 |
|
4557 | 1165 |
%{ |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1166 |
if (__INST(sender_) != nil) { |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1167 |
__RESUMECONTEXT__(self, aBlock, 2); |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1168 |
} |
360 | 1169 |
%}. |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1170 |
self sender isNil ifTrue:[^ nil]. |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1171 |
|
328 | 1172 |
" |
360 | 1173 |
when we arrive here, something went wrong. |
328 | 1174 |
debugging ... |
1175 |
" |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1176 |
^ self invalidReturnOrRestartError:#'returnDoing' with:aBlock |
328 | 1177 |
! |
1178 |
||
1 | 1179 |
unwind |
69 | 1180 |
"return nil from the receiver - i.e. simulate a '^ nil'. |
360 | 1181 |
If the context has already retruned, report an error. |
1 | 1182 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
69 | 1183 |
and Block>>valueOnUnwindDo: on the way. |
1 | 1184 |
|
141 | 1185 |
LIMITATION: |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1186 |
currently a context can only be unwound by |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1187 |
the owning process - not from outside. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1188 |
i.e. it is not possible for one thread to unwind |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1189 |
another threads context - which does not make sense anyway. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1190 |
However, you can force another thread to do this in its own process |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1191 |
context, by giving it an interrupt action - this does make sense. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1192 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1193 |
Also, the compiler has an option (+optcontext) to create |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1194 |
non-returnable contexts (which are faster). |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1195 |
If such a context is restarted, a runtime error is raised." |
141 | 1196 |
|
1197 |
^ self unwind:nil |
|
1 | 1198 |
! |
1199 |
||
1200 |
unwind:value |
|
69 | 1201 |
"return value from the receiver - i.e. simulate a '^ value'. |
360 | 1202 |
If the context has already returned , report an error. |
1 | 1203 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
69 | 1204 |
and Block>>valueOnUnwindDo: on the way. |
141 | 1205 |
|
1206 |
LIMITATION: |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1207 |
currently a context can only be unwound by |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1208 |
the owning process - not from outside. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1209 |
i.e. it is not possible for one thread to unwind |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1210 |
another threads context - which does not make sense anyway. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1211 |
However, you can force another thread to do this in its own process |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1212 |
context, by giving it an interrupt action - this does make sense. |
1 | 1213 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1214 |
Also, the compiler has an option (+optcontext) to create |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1215 |
non-returnable contexts (which are faster). |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1216 |
If such a context is restarted, a runtime error is raised." |
1 | 1217 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1218 |
|con| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1219 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1220 |
self senderIsNil ifFalse:[ |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1221 |
con := thisContext evaluateUnwindActionsUpTo:self. |
141 | 1222 |
]. |
1 | 1223 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1224 |
"oops, if nil, I am not on the calling chain; |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1225 |
(bad bad, unwind action have already been performed. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1226 |
should we check for this situation first and NOT evaluate |
141 | 1227 |
the unwind actions in this case ?) |
1228 |
" |
|
69 | 1229 |
con isNil ifTrue:[ |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1230 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1231 |
tried to return to a context which is already dead |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1232 |
(i.e. the method/block has already executed a return) |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1233 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1234 |
^ self invalidReturnOrRestartError:#'unwind:' with:value |
69 | 1235 |
]. |
141 | 1236 |
" |
1237 |
now, that all unwind-actions are done, I can use the |
|
1238 |
low-level return ... |
|
1239 |
" |
|
1240 |
^ self return:value |
|
1241 |
! |
|
1242 |
||
1243 |
unwindAndRestart |
|
1244 |
"restart the receiver - i.e. the method is evaluated again. |
|
402 | 1245 |
if the context to restart already died report an error. |
141 | 1246 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
1247 |
and Block>>valueOnUnwindDo: before restarting. |
|
1248 |
||
1249 |
LIMITATION: |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1250 |
a context can only be restarted by |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1251 |
the owning process - not from outside. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1252 |
i.e. it is not possible for one thread to unwindAndRestart |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1253 |
another threads context - which does not make sense anyway. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1254 |
However, you can force another thread to do this in its own process |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1255 |
context, by giving it an interrupt action - this does make sense. |
141 | 1256 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1257 |
Also, the compiler has an option (+optcontext) to create |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1258 |
non-restartable contexts (which are faster). |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1259 |
If such a context is restarted, a runtime error is raised." |
552
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1260 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1261 |
|con| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1262 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1263 |
self senderIsNil ifFalse:[ |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1264 |
con := thisContext evaluateUnwindActionsUpTo:self. |
141 | 1265 |
]. |
1266 |
||
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1267 |
"oops, if nil, I am not on the calling chain; |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1268 |
(bad bad, unwind action have already been performed. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1269 |
should we check for this situation first and NOT evaluate |
141 | 1270 |
the unwind actions in this case ?) |
1271 |
" |
|
1272 |
con isNil ifTrue:[ |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1273 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1274 |
tried to return to a context which is already dead |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1275 |
(i.e. the method/block has already executed a return) |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1276 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1277 |
^ self invalidReturnOrRestartError:#'unwindAndRestart:' with:nil |
141 | 1278 |
]. |
1279 |
" |
|
1280 |
now, that all unwind-actions are done, I can use the |
|
1281 |
low-level restart ... |
|
1282 |
" |
|
1283 |
^ self restart |
|
328 | 1284 |
! |
1285 |
||
4485 | 1286 |
unwindAndResume:value |
1287 |
"resume execution in the the receiver - i.e. simulate a '^ value' |
|
1288 |
from whatever it called last. |
|
1289 |
If the context has already returned , report an error. |
|
1290 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
|
1291 |
and Block>>valueOnUnwindDo: on the way. |
|
1292 |
||
1293 |
LIMITATION: |
|
1294 |
currently a context can only be unwound by |
|
1295 |
the owning process - not from outside. |
|
1296 |
i.e. it is not possible for one thread to unwind |
|
1297 |
another threads context - which does not make sense anyway. |
|
1298 |
However, you can force another thread to do this in its own process |
|
1299 |
context, by giving it an interrupt action - this does make sense. |
|
1300 |
||
1301 |
Also, the compiler has an option (+optcontext) to create |
|
1302 |
non-returnable contexts (which are faster). |
|
1303 |
If such a context is restarted, a runtime error is raised." |
|
1304 |
||
1305 |
|con| |
|
1306 |
||
1307 |
self senderIsNil ifFalse:[ |
|
1308 |
con := thisContext evaluateUnwindActionsUpTo:self. |
|
1309 |
]. |
|
1310 |
||
1311 |
"oops, if nil, I am not on the calling chain; |
|
1312 |
(bad bad, unwind action have already been performed. |
|
1313 |
should we check for this situation first and NOT evaluate |
|
1314 |
the unwind actions in this case ?) |
|
1315 |
" |
|
1316 |
con isNil ifTrue:[ |
|
1317 |
" |
|
1318 |
tried to return to a context which is already dead |
|
1319 |
(i.e. the method/block has already executed a return) |
|
1320 |
" |
|
1321 |
^ self invalidReturnOrRestartError:#'unwindAndResume:' with:value |
|
1322 |
]. |
|
1323 |
" |
|
1324 |
now, that all unwind-actions are done, I can use the |
|
1325 |
low-level resume ... |
|
1326 |
" |
|
1327 |
^ self resume:value |
|
1328 |
! |
|
1329 |
||
328 | 1330 |
unwindThenDo:aBlock |
1331 |
"return the value of aBlock from the receiver - i.e. simulate a '^ aBlock value'. |
|
360 | 1332 |
If the context has already returned , report an error. |
328 | 1333 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
1334 |
and Block>>valueOnUnwindDo: on the way. |
|
1335 |
The block is evaluated AFTER all unwind actions are performed |
|
1336 |
(i.e. the blocks sender will be the receiving context, not the |
|
402 | 1337 |
currently executing context) |
328 | 1338 |
|
1339 |
LIMITATION: |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1340 |
currently a context can only be unwound by |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1341 |
the owning process - not from outside |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1342 |
i.e. it is not possible for one thread to unwindThenDo |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1343 |
another threads context - which does not make sense anyway. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1344 |
However, you can force another thread to do this in its own process |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1345 |
context, by giving it an interrupt action - this does make sense. |
328 | 1346 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1347 |
Also, the compiler has an option (+optcontext) to create |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1348 |
non-returnable contexts (which are faster). |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1349 |
If such a context is restarted, a runtime error is raised." |
328 | 1350 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1351 |
|con| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1352 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1353 |
self senderIsNil ifFalse:[ |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1354 |
con := thisContext evaluateUnwindActionsUpTo:self. |
328 | 1355 |
]. |
1356 |
||
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1357 |
"oops, if nil, I am not on the calling chain; |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1358 |
(bad bad, unwind action have already been performed. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1359 |
should we check for this situation first and NOT evaluate |
328 | 1360 |
the unwind actions in this case ?) |
1361 |
" |
|
1362 |
con isNil ifTrue:[ |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1363 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1364 |
tried to return to a context which is already dead |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1365 |
(i.e. the method/block has already executed a return) |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1366 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1367 |
^ self invalidReturnOrRestartError:#'unwindThenDo:' with:aBlock |
328 | 1368 |
]. |
1369 |
" |
|
1370 |
now, that all unwind-actions are done, I can use the |
|
1371 |
low-level return ... |
|
1372 |
" |
|
1373 |
^ self returnDoing:aBlock |
|
1 | 1374 |
! ! |
623 | 1375 |
|
1376 |
!Context methodsFor:'printing & storing'! |
|
1377 |
||
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1378 |
argStringFor:someObject |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1379 |
|
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1380 |
|name| |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1381 |
%{ |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1382 |
/* |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1383 |
* special handling for (invalid) free objects. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1384 |
* these only appear if some primitiveCode does not correctly use SEND macros, |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1385 |
* which may lead to sends to free objects. In normal operation, this 'cannot' happen. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1386 |
*/ |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1387 |
if (__isNonNilObject(someObject) && (__qClass(someObject)==nil)) { |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1388 |
name = __MKSTRING("FreeObject"); |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1389 |
} |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1390 |
%}. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1391 |
name notNil ifTrue:[^ name]. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1392 |
^ someObject displayString |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1393 |
! |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1394 |
|
623 | 1395 |
argsDisplayString |
1396 |
|fullString n "{ Class: SmallInteger }" | |
|
1397 |
||
1398 |
fullString := ''. |
|
1399 |
n := self numArgs. |
|
1400 |
1 to:n do:[:index | |
|
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1401 |
fullString := fullString , ' ' , (self argStringFor:(self at:index)) |
623 | 1402 |
]. |
1403 |
^ fullString |
|
1404 |
! |
|
1405 |
||
6648 | 1406 |
displayArgsOn:aStream |
1407 |
| n "{ Class: SmallInteger }" | |
|
1408 |
||
1409 |
n := self numArgs. |
|
1410 |
1 to:n do:[:index | |
|
1411 |
aStream nextPutAll:(self argStringFor:(self at:index)). |
|
8578 | 1412 |
aStream nextPutAll:' '. |
6648 | 1413 |
]. |
1414 |
! |
|
1415 |
||
623 | 1416 |
displayString |
1417 |
"return a string describing the context - for display in Inspector" |
|
1418 |
||
1419 |
^ self class name , '(' , self printString , ')' |
|
1420 |
! |
|
1421 |
||
6648 | 1422 |
fullPrintAllOn:aStream |
1423 |
"print a full walkback starting at the receiver" |
|
1424 |
||
1425 |
|context| |
|
1426 |
||
1427 |
context := self. |
|
1428 |
[context notNil] whileTrue: [ |
|
1429 |
context fullPrintOn:aStream. |
|
1430 |
aStream cr. |
|
1431 |
context := context sender |
|
1432 |
] |
|
1433 |
||
1434 |
" |
|
1435 |
thisContext fullPrintAllOn:Transcript |
|
1436 |
" |
|
1437 |
||
1438 |
"Created: 15.1.1997 / 18:09:05 / cg" |
|
1439 |
! |
|
1440 |
||
1441 |
fullPrintOn:aStream |
|
1442 |
"print the receiver, selector and args of the context" |
|
1443 |
||
8578 | 1444 |
self receiverPrintString printOn:aStream. |
1445 |
aStream nextPutAll:' '. |
|
1446 |
selector printOn:aStream. |
|
1447 |
||
6648 | 1448 |
self size ~~ 0 ifTrue: [ |
8578 | 1449 |
aStream nextPutAll:' '. |
6648 | 1450 |
self displayArgsOn:aStream |
1451 |
]. |
|
1452 |
aStream nextPutAll:' ['. |
|
1453 |
self lineNumber printOn:aStream. |
|
8578 | 1454 |
aStream nextPutAll:']'. |
6648 | 1455 |
|
1456 |
" |
|
1457 |
thisContext fullPrintOn:Transcript |
|
1458 |
" |
|
1459 |
||
1460 |
"Modified: 20.5.1996 / 10:27:14 / cg" |
|
1461 |
"Created: 15.1.1997 / 18:09:06 / cg" |
|
1462 |
! |
|
1463 |
||
623 | 1464 |
fullPrintString |
1465 |
"return a string describing the context - this includes the linenumber, |
|
1466 |
receiver printString and argument printString" |
|
1467 |
||
1468 |
|s| |
|
1469 |
||
1470 |
s := WriteStream on:String new. |
|
6648 | 1471 |
self fullPrintOn:s. |
623 | 1472 |
^ s contents |
1473 |
||
1474 |
" |
|
1475 |
thisContext fullPrintString |
|
1476 |
" |
|
1477 |
! |
|
1478 |
||
1479 |
methodPrintString |
|
1480 |
"return a string describing the contexts method as 'implementorClass>>selector'" |
|
1481 |
||
1853
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1482 |
|mthd who| |
623 | 1483 |
|
1484 |
mthd := self method. |
|
1485 |
mthd notNil ifTrue:[ |
|
3143 | 1486 |
who := mthd who. |
1487 |
who notNil ifTrue:[ |
|
1488 |
^ who methodClass name , '>>' , who methodSelector |
|
1489 |
] |
|
623 | 1490 |
]. |
1491 |
^ mthd displayString. |
|
1492 |
||
1493 |
" |
|
1494 |
thisContext methodPrintString |
|
1495 |
thisContext sender methodPrintString |
|
1496 |
" |
|
1853
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1497 |
|
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1498 |
"Modified: 1.11.1996 / 16:21:49 / cg" |
623 | 1499 |
! |
1500 |
||
1501 |
printOn:aStream |
|
1502 |
"append a printed description of the receiver onto aStream" |
|
1503 |
||
1504 |
aStream nextPutAll:(self receiverPrintString). |
|
1505 |
aStream space. |
|
4393 | 1506 |
self selector printOn:aStream. |
1507 |
aStream space. |
|
1508 |
aStream nextPutAll:' ['; nextPutAll:self lineNumber printString; nextPutAll:']' . |
|
1509 |
||
623 | 1510 |
! |
1511 |
||
1512 |
receiverPrintString |
|
1513 |
"return a string describing the receiver of the context" |
|
1514 |
||
1515 |
|receiverClass receiverClassName newString implementorClass| |
|
1516 |
||
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1517 |
%{ |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1518 |
/* |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1519 |
* special handling for (invalid) free objects. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1520 |
* these only appear if some primitiveCode does not correctly use SEND macros, |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1521 |
* which may lead to sends to free objects. In normal operation, this 'cannot' happen. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1522 |
*/ |
1133 | 1523 |
if (__isNonNilObject(__INST(receiver)) && (__qClass(__INST(receiver))==nil)) { |
3923 | 1524 |
receiverClassName = __MKSTRING("FreeObject"); |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1525 |
} |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1526 |
%}. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1527 |
receiverClassName notNil ifTrue:[^ receiverClassName]. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1528 |
|
623 | 1529 |
receiverClass := receiver class. |
3923 | 1530 |
receiverClass isJavaClass ifTrue:[ |
1531 |
receiverClassName := receiverClass displayString |
|
1532 |
] ifFalse:[ |
|
1533 |
(receiverClass isBehavior |
|
1534 |
and:[receiverClass isMeta |
|
1535 |
and:[receiverClass soleInstance isJavaClass]]) ifTrue:[ |
|
1536 |
"/ receiverClassName := receiverClass soleInstance fullName. |
|
1537 |
receiverClassName := receiverClass name. |
|
1538 |
] ifFalse:[ |
|
1539 |
receiverClassName := receiverClass name. |
|
1540 |
] |
|
1541 |
]. |
|
6197 | 1542 |
(receiverClass == SmallInteger |
1543 |
or:[receiverClass == Float]) ifTrue:[ |
|
3923 | 1544 |
newString := '(' , receiver printString , ') ' , receiverClassName |
623 | 1545 |
] ifFalse:[ |
3923 | 1546 |
newString := receiverClassName |
623 | 1547 |
]. |
1548 |
||
1549 |
selector notNil ifTrue:[ |
|
1550 |
"/ implementorClass := self searchClass whichClassIncludesSelector:selector. |
|
1551 |
||
3923 | 1552 |
" |
1553 |
kludge to avoid slow search for containing class |
|
1554 |
" |
|
1555 |
(selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[ |
|
1556 |
implementorClass := self methodClass. |
|
1557 |
]. |
|
1558 |
||
1559 |
implementorClass notNil ifTrue: [ |
|
1560 |
(implementorClass ~~ receiverClass) ifTrue: [ |
|
1561 |
newString := newString , '>>>', |
|
1562 |
implementorClass name printString |
|
1563 |
] |
|
1564 |
] ifFalse:[ |
|
1565 |
self searchClass ~~ receiverClass ifTrue:[ |
|
1566 |
newString := newString , '>>>' , self searchClass name |
|
1567 |
]. |
|
1568 |
" |
|
1569 |
kludge for doIt - these unbound methods are not |
|
1570 |
found in the classes methodDictionary |
|
1571 |
" |
|
1572 |
(selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[ |
|
1573 |
newString := newString , '>>>**NONE**' |
|
1574 |
] |
|
1575 |
] |
|
623 | 1576 |
]. |
1577 |
||
1578 |
^ newString |
|
6197 | 1579 |
|
1580 |
"Modified: / 16.11.2001 / 16:04:21 / cg" |
|
623 | 1581 |
! ! |
1582 |
||
7257 | 1583 |
!Context methodsFor:'private-accessing'! |
623 | 1584 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1585 |
markForHandle |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1586 |
"set the mark for exception handle flag in the receiver. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1587 |
The VM needs this to know that some special action is to be performed with |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1588 |
this context - a highly internal mechanism and not for public use." |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1589 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1590 |
%{ /* NOCONTEXT */ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1591 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__HANDLE_MARK)); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1592 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1593 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1594 |
"Modified: 13.12.1995 / 19:05:22 / cg" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1595 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1596 |
|
753
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1597 |
markForInterrupt |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1598 |
"set the interrupt flag. |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1599 |
The VM needs this to know that some special action is to be performed with |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1600 |
this context upon return - a highly internal mechanism and not for public use." |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1601 |
|
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1602 |
%{ /* NOCONTEXT */ |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1603 |
__markInterrupted(__ContextInstPtr(self)); |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1604 |
%} |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1605 |
! |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1606 |
|
1727 | 1607 |
markForInterruptOnUnwind |
1608 |
"set the interrupt-on-unwind flag in the receiver. |
|
1609 |
The VM will generate a stepInterrupt, when this context returns or |
|
1610 |
is unwound. This is used by the debugger for faster single-stepping; |
|
1611 |
- a highly internal mechanism and not for public use." |
|
1612 |
||
1613 |
%{ /* NOCONTEXT */ |
|
3508 | 1614 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__IRQ_ON_UNWIND)); |
1727 | 1615 |
%} |
1616 |
! |
|
1617 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1618 |
markForRaise |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1619 |
"set the mark for exception raise flag in the receiver. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1620 |
The VM needs this to know that some special action is to be performed with |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1621 |
this context - a highly internal mechanism and not for public use." |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1622 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1623 |
%{ /* NOCONTEXT */ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1624 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__RAISE_MARK)); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1625 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1626 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1627 |
"Modified: 13.12.1995 / 19:05:22 / cg" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1628 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1629 |
|
623 | 1630 |
markForUnwind |
749 | 1631 |
"set the mark for unwind flag in the receiver. |
1632 |
The VM needs this to know that some special action is to be performed with |
|
1633 |
this context - a highly internal mechanism and not for public use." |
|
1634 |
||
623 | 1635 |
%{ /* NOCONTEXT */ |
1133 | 1636 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__UNWIND_MARK)); |
623 | 1637 |
%} |
749 | 1638 |
|
1639 |
"Modified: 13.12.1995 / 19:05:22 / cg" |
|
623 | 1640 |
! |
1641 |
||
5780 | 1642 |
setHome:aContext |
1643 |
"set the homeContext. |
|
1644 |
DANGER: this is for experimental, internal use only (byteCode interpreters)" |
|
1645 |
||
1646 |
home := aContext. |
|
1647 |
! |
|
1648 |
||
1649 |
setSender:aContext |
|
1650 |
"set the sender of the context. |
|
1651 |
DANGER: this is for experimental, internal use only (byteCode interpreters)" |
|
1652 |
||
1653 |
%{ /* NOCONTEXT */ |
|
1654 |
__INST(sender_) = aContext; |
|
1655 |
%} |
|
1656 |
! |
|
1657 |
||
623 | 1658 |
unmarkForUnwind |
749 | 1659 |
"clear the mark for unwind flag in the receiver. |
1660 |
The VM needs this to know that some special action is to be performed with |
|
1661 |
this context - a highly internal mechanism and not for public use." |
|
1662 |
||
623 | 1663 |
%{ /* NOCONTEXT */ |
1133 | 1664 |
__INST(flags) = (OBJ)((INT)__INST(flags) & ~__MASKSMALLINT(__UNWIND_MARK)); |
623 | 1665 |
%} |
1666 |
! ! |
|
1667 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1668 |
!Context methodsFor:'searching'! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1669 |
|
8284 | 1670 |
findExceptional |
1671 |
"walk along the sender chain (starting with the sender), |
|
1672 |
for a context which is marked as handle or raise context. |
|
1673 |
This non-standard interface is only to be used by exception" |
|
1674 |
||
1675 |
"/ this could have been (actually: was) implemented as: |
|
1676 |
"/ |
|
1677 |
"/ |con| |
|
1678 |
"/ |
|
1679 |
"/ con := self. |
|
1680 |
"/ [con notNil] whileTrue:[ |
|
1681 |
"/ [con isHandleContext] ifTrue:[^con]. |
|
1682 |
"/ [con isRaiseContext] ifTrue:[^con]. |
|
1683 |
"/ con := con sender. |
|
1684 |
"/ ]. |
|
1685 |
"/ ^ nil |
|
1686 |
"/ |
|
1687 |
"/ and the code below does exactly this (somewhat faster, though). |
|
1688 |
"/ |
|
1689 |
"/ (it avoids referencing all intermediate contexts, which would mark them special, |
|
1690 |
"/ although they aren't really - this is expert knowledge, no need to understand that ...) |
|
1691 |
||
1692 |
%{ /* NOCONTEXT */ |
|
1693 |
||
1694 |
OBJ theContext; |
|
1695 |
||
1696 |
theContext = self; |
|
1697 |
while (__isNonNilObject(theContext)) { |
|
1698 |
if ((INT)(__ContextInstPtr(theContext)->c_flags) & __MASKSMALLINT(__HANDLE_MARK|__RAISE_MARK)) { |
|
1699 |
if (__isLazy(theContext)) { |
|
1700 |
__PATCHUPCONTEXT(theContext); |
|
1701 |
} |
|
1702 |
||
1703 |
if (! __isNonLIFO(theContext)) { |
|
1704 |
/* |
|
1705 |
* to be prepared for the worst situation |
|
1706 |
* (the sender is not stored, so the trap won't catch it) |
|
1707 |
* make the writeBarrier trigger manually. |
|
1708 |
* We'll see, if this is really required. |
|
1709 |
*/ |
|
1710 |
theContext->o_space |= CATCHMARK; |
|
1711 |
#if 0 |
|
1712 |
_markNonLIFO(theContext); |
|
1713 |
#endif |
|
1714 |
} |
|
1715 |
RETURN (theContext); |
|
1716 |
} |
|
1717 |
theContext = __ContextInstPtr(theContext)->c_sender; |
|
1718 |
} |
|
1719 |
%}. |
|
1720 |
^ nil |
|
1721 |
! |
|
1722 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1723 |
findNextContextWithSelector:selector1 or:selector2 or:selector3 |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1724 |
"walk along the sender chain (starting with the sender), |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1725 |
for a context with either one of the given selectors. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1726 |
This non-standard interface is only to be used by exception" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1727 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1728 |
"/ this could have been (actually: was) implemented as: |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1729 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1730 |
"/ |con| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1731 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1732 |
"/ con := self sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1733 |
"/ [con notNil] whileTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1734 |
"/ con selector == aSelector ifTrue:[^ con]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1735 |
"/ con := con sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1736 |
"/ ]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1737 |
"/ ^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1738 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1739 |
"/ and the code below does exactly this (somewhat faster, though). |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1740 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1741 |
"/ (it avoids referencing all intermediate contexts, which would mark them special, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1742 |
"/ although they aren't really - this is expert knowledge, no need to understand that ...) |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1743 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1744 |
%{ /* NOCONTEXT */ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1745 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1746 |
OBJ theContext; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1747 |
OBJ sel; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1748 |
OBJ __FETCHSELECTOR(); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1749 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1750 |
theContext = __INST(sender_); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1751 |
while (__isNonNilObject(theContext)) { |
5422 | 1752 |
if (__isLazy(theContext)) { |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1753 |
#ifdef TRADITIONAL_STACK_FRAME |
5422 | 1754 |
sel = __FETCHSELECTOR(theContext); |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1755 |
#else |
5422 | 1756 |
/* mhmh - not really needed */ |
1757 |
__PATCHUPCONTEXT(theContext); |
|
1758 |
sel = __ContextInstPtr(theContext)->c_selector; |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1759 |
#endif |
5422 | 1760 |
} else { |
1761 |
sel = __ContextInstPtr(theContext)->c_selector; |
|
1762 |
} |
|
1763 |
||
1764 |
if ((sel == selector1) |
|
1765 |
|| ((selector2 != nil) && (sel == selector2)) |
|
1766 |
|| ((selector3 != nil) && (sel == selector3))) { |
|
1767 |
if (__isLazy(theContext)) { |
|
1768 |
__PATCHUPCONTEXT(theContext); |
|
1769 |
} |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1770 |
|
5422 | 1771 |
if (! __isNonLIFO(theContext)) { |
1772 |
/* |
|
1773 |
* to be prepared for the worst situation |
|
1774 |
* (the sender is not stored, so the trap wont catch it) |
|
1775 |
* make the writeBarrier trigger manually. |
|
1776 |
* We'll see, if this is really required. |
|
1777 |
*/ |
|
1778 |
theContext->o_space |= CATCHMARK; |
|
1779 |
_markNonLIFO(theContext); |
|
1780 |
} |
|
1781 |
RETURN (theContext); |
|
1782 |
} |
|
1783 |
theContext = __ContextInstPtr(theContext)->c_sender; |
|
1784 |
} |
|
1785 |
RETURN (nil); |
|
1786 |
%}. |
|
1787 |
" |
|
1788 |
|con sel| |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1789 |
|
5422 | 1790 |
con := self sender. |
1791 |
[con notNil] whileTrue:[ |
|
1792 |
sel := con selector. |
|
1793 |
sel == selector1 ifTrue:[^ con]. |
|
1794 |
(selector2 notNil and:[sel == selector2]) ifTrue:[^ con]. |
|
1795 |
(selector3 notNil and:[sel == selector3]) ifTrue:[^ con]. |
|
1796 |
con := con sender. |
|
1797 |
]. |
|
1798 |
^ nil |
|
1799 |
" |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1800 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1801 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1802 |
findNextUnwindContextOr:aContext |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1803 |
"walk along the sender chain (starting at the sender), |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1804 |
for a context marked for unwindAction or aContext. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1805 |
This non-standard interface is only to be used by mySelf" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1806 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1807 |
"/ this could have been (actually: was) implemented as: |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1808 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1809 |
"/ |con| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1810 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1811 |
"/ con := self sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1812 |
"/ [con notNil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1813 |
"/ and:[con ~~ aContext |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1814 |
"/ and:[con isUnwindContext not]]] whileTrue:[con := con sender]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1815 |
"/ ^ con |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1816 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1817 |
"/ and the code below does exactly this (somewhat faster, though). |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1818 |
"/ (it avoids referencing all intermediate contexts, which would mark them special, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1819 |
"/ although they aren't really - this is expert knowledge, no need to understand that ...) |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1820 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1821 |
%{ /* NOCONTEXT */ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1822 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1823 |
OBJ theContext; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1824 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1825 |
if (self == aContext) { |
4485 | 1826 |
RETURN (self); |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1827 |
} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1828 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1829 |
theContext = __INST(sender_); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1830 |
while (__isNonNilObject(theContext)) { |
4485 | 1831 |
if ((theContext == aContext) |
1832 |
|| ((INT)(__ContextInstPtr(theContext)->c_flags) & __MASKSMALLINT(__UNWIND_MARK))) { |
|
1833 |
if (__isLazy(theContext)) { |
|
1834 |
__PATCHUPCONTEXT(theContext); |
|
1835 |
} |
|
1836 |
if (! __isNonLIFO(theContext)) { |
|
1837 |
/* |
|
1838 |
* to be prepared for the worst situation |
|
1839 |
* (the sender is not stored, so the trap wont catch it) |
|
1840 |
* make the writeBarrier trigger manually. |
|
1841 |
* We'll see, if this is really required. |
|
1842 |
*/ |
|
1843 |
theContext->o_space |= CATCHMARK; |
|
1844 |
#if 0 |
|
1845 |
_markNonLIFO(theContext); |
|
1846 |
#endif |
|
1847 |
} |
|
1848 |
RETURN (theContext); |
|
1849 |
} |
|
1850 |
theContext = __ContextInstPtr(theContext)->c_sender; |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1851 |
} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1852 |
%}. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1853 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1854 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1855 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1856 |
findSpecialHandle:findHandleContext raise:findRaiseContext |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1857 |
"walk along the sender chain (starting with the sender), |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1858 |
for a context which is marked as handle or raise context. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1859 |
This non-standard interface is only to be used by exception" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1860 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1861 |
"/ this could have been (actually: was) implemented as: |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1862 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1863 |
"/ |con| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1864 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1865 |
"/ con := self sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1866 |
"/ [con notNil] whileTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1867 |
"/ (findHandleContext and:[con isHandleContext]) ifTrue:[^con]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1868 |
"/ (findRaiseContext and:[con isRaiseContext]) ifTrue:[^con]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1869 |
"/ con := con sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1870 |
"/ ]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1871 |
"/ ^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1872 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1873 |
"/ and the code below does exactly this (somewhat faster, though). |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1874 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1875 |
"/ (it avoids referencing all intermediate contexts, which would mark them special, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1876 |
"/ although they aren't really - this is expert knowledge, no need to understand that ...) |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1877 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1878 |
%{ /* NOCONTEXT */ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1879 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1880 |
OBJ theContext; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1881 |
int flagMask = 0; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1882 |
INT mask; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1883 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1884 |
if (findHandleContext == true) |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1885 |
flagMask = __HANDLE_MARK; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1886 |
if (findRaiseContext == true) |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1887 |
flagMask |= __RAISE_MARK; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1888 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1889 |
mask = __MASKSMALLINT(flagMask); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1890 |
theContext = __INST(sender_); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1891 |
while (__isNonNilObject(theContext)) { |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1892 |
if ((INT)(__ContextInstPtr(theContext)->c_flags) & mask) { |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1893 |
if (__isLazy(theContext)) { |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1894 |
__PATCHUPCONTEXT(theContext); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1895 |
} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1896 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1897 |
if (! __isNonLIFO(theContext)) { |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1898 |
/* |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1899 |
* to be prepared for the worst situation |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1900 |
* (the sender is not stored, so the trap won't catch it) |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1901 |
* make the writeBarrier trigger manually. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1902 |
* We'll see, if this is really required. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1903 |
*/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1904 |
theContext->o_space |= CATCHMARK; |
4485 | 1905 |
#if 0 |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1906 |
_markNonLIFO(theContext); |
4485 | 1907 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1908 |
} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1909 |
RETURN (theContext); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1910 |
} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1911 |
theContext = __ContextInstPtr(theContext)->c_sender; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1912 |
} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1913 |
%}. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1914 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1915 |
! ! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
1916 |
|
1051 | 1917 |
!Context methodsFor:'special accessing'! |
1918 |
||
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1919 |
argAndVarNames |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1920 |
"helper: given a context, return a collection of arg&var names" |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1921 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1922 |
|homeContext method block numArgs numVars m src |
8217 | 1923 |
sel isDoIt blocksLineNr extractFromBlock sender| |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1924 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1925 |
numArgs := self numArgs. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1926 |
numVars := self numVars. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1927 |
(numArgs == 0 and:[numVars == 0]) ifTrue:[^ #()]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1928 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1929 |
homeContext := self methodHome. |
7652 | 1930 |
homeContext notNil ifTrue:[ |
1931 |
sel := homeContext selector. |
|
1932 |
method := homeContext method. |
|
1933 |
]. |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1934 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1935 |
extractFromBlock := |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1936 |
[ |
8772
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1937 |
|blockNode argNames varNames vars args blocksHome| |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1938 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1939 |
blockNode := Compiler |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1940 |
blockAtLine:blocksLineNr |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1941 |
in:m |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1942 |
orSource:src |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1943 |
numArgs:numArgs |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1944 |
numVars:numVars. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1945 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1946 |
blockNode notNil ifTrue:[ |
8772
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1947 |
"/ a kludge |
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1948 |
blockNode lineNumber == blocksLineNr ifTrue:[ |
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1949 |
blocksHome := blockNode home. |
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1950 |
(blocksHome notNil and:[blocksHome isBlockNode]) ifTrue:[ |
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1951 |
(blocksHome numArgs == numArgs |
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1952 |
and:[ blocksHome numVars == numVars ]) ifTrue:[ |
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1953 |
blockNode := blocksHome |
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1954 |
]. |
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1955 |
]. |
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1956 |
]. |
9a5d7a368a34
kludge for a blocks context arg-and-var names
Claus Gittinger <cg@exept.de>
parents:
8687
diff
changeset
|
1957 |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1958 |
argNames := #(). |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1959 |
varNames := #(). |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1960 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1961 |
numArgs > 0 ifTrue:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1962 |
vars := blockNode arguments. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1963 |
vars size > 0 ifTrue:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1964 |
argNames := vars collect:[:var | var name] |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1965 |
] |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1966 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1967 |
numVars > 0 ifTrue:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1968 |
vars := blockNode variables. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1969 |
vars size > 0 ifTrue:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1970 |
varNames := vars collect:[:var | var name]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1971 |
] |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1972 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1973 |
^ argNames , varNames |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1974 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1975 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1976 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1977 |
"/ #doIt needs special handling below |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1978 |
isDoIt := (sel == #'doIt') or:[sel == #'doIt:']. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1979 |
self isBlockContext ifFalse:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1980 |
isDoIt ifTrue:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1981 |
method notNil ifTrue:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1982 |
"/ special for #doIt |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1983 |
m := nil. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1984 |
src := ('[' , method source , '\]') withCRs. |
8217 | 1985 |
"/ blocksLineNr := self lineNumber. |
8242
594cfd2150f7
oops - must care for doIt contexts
Claus Gittinger <cg@exept.de>
parents:
8217
diff
changeset
|
1986 |
blocksLineNr := (self home ? self) lineNumber. |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1987 |
extractFromBlock value. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1988 |
] |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1989 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1990 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1991 |
method notNil ifTrue:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1992 |
^ method methodArgAndVarNames. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1993 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1994 |
^ #() |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1995 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1996 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1997 |
method notNil ifTrue:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1998 |
isDoIt ifTrue:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
1999 |
"/ special for #doIt |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2000 |
"/ my source is found in the method. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2001 |
m := nil. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2002 |
src := ('[' , method source , '\]') withCRs. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2003 |
] ifFalse:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2004 |
m := method. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2005 |
src := nil. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2006 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2007 |
blocksLineNr := self lineNumber. |
8020 | 2008 |
extractFromBlock value. |
7747
27be5f627b03
fixed argAndVarNames for inner blocks.
Claus Gittinger <cg@exept.de>
parents:
7652
diff
changeset
|
2009 |
blocksLineNr := self home lineNumber. |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2010 |
extractFromBlock value. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2011 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2012 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2013 |
blocksLineNr isNil ifTrue:[ |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2014 |
self isBlockContext ifTrue:[ |
8217 | 2015 |
sender := self sender. |
2016 |
(sender notNil |
|
2017 |
and:[sender receiver isBlock |
|
2018 |
and:[sender selector startsWith:'value']]) |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2019 |
ifTrue:[ |
8217 | 2020 |
block := sender receiver. |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2021 |
src := block source. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2022 |
src isNil ifTrue:[ |
8488 | 2023 |
self error:'no source'. |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2024 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2025 |
blocksLineNr := 1. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2026 |
extractFromBlock value. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2027 |
]. |
8217 | 2028 |
sender := nil. |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2029 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2030 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2031 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2032 |
^ #() |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2033 |
! |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2034 |
|
4557 | 2035 |
canResume |
2036 |
"return true, if the receiver allows to be resumed. |
|
2037 |
Due to the implementation, this requires that the context which |
|
2038 |
is right below the receiver is returnable." |
|
2039 |
||
2040 |
|theContext| |
|
2041 |
||
2042 |
" |
|
2043 |
starting with this context, find the one below |
|
2044 |
(i.e. the one that I have called) and return from it. |
|
2045 |
" |
|
2046 |
%{ |
|
2047 |
OBJ sndr; |
|
2048 |
||
2049 |
theContext = __thisContext; |
|
2050 |
while (theContext != nil) { |
|
2051 |
sndr = __ContextInstPtr(theContext)->c_sender; |
|
2052 |
if (sndr == self) break; |
|
2053 |
theContext = sndr; |
|
2054 |
} |
|
2055 |
if (theContext != nil) { |
|
2056 |
if (__isLazy(theContext)) { |
|
2057 |
__PATCHUPCONTEXT(theContext); |
|
2058 |
} |
|
2059 |
} |
|
2060 |
%}. |
|
2061 |
theContext isNil ifTrue:[ |
|
2062 |
^ false |
|
2063 |
]. |
|
2064 |
^ theContext canReturn |
|
2065 |
! |
|
2066 |
||
1051 | 2067 |
canReturn |
2068 |
"return true, if the receiver allows returning through it. |
|
4557 | 2069 |
Blocks, (currently) always return false. |
2646 | 2070 |
Methods which contain a (non-inlined) block are always |
2071 |
returnable - for other methods, it depends on how the system |
|
2072 |
was compiled (stc flag +/-optContext). |
|
2073 |
If it was compiled with +optContext, methods are compiled |
|
4557 | 2074 |
non returnable, unless a return-pragma was present in the method. |
2646 | 2075 |
Since this saves some administrative work in every method |
2076 |
invocation and makes overall execution faster, the system classes |
|
2077 |
are all compiled with this flag turned on." |
|
1051 | 2078 |
|
2079 |
%{ /* NOCONTEXT */ |
|
2080 |
||
3508 | 2081 |
RETURN ( ((INT)(__INST(flags)) & __MASKSMALLINT(__CANNOT_RETURN)) ? false : true ); |
5441 | 2082 |
%}. |
2083 |
^ true |
|
1051 | 2084 |
! |
2085 |
||
1492 | 2086 |
hasStackToShow |
2646 | 2087 |
"private interface to the debugger. |
2088 |
Smalltalk contexts return false here - other language frames |
|
2089 |
(i.e. Java frames) may want to show the evaluation stack" |
|
2090 |
||
1492 | 2091 |
^ false |
2092 |
||
2093 |
"Created: 28.6.1996 / 14:48:39 / cg" |
|
2646 | 2094 |
"Modified: 13.5.1997 / 16:31:12 / cg" |
1492 | 2095 |
! |
2096 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2097 |
isHandleContext |
4505 | 2098 |
"return true, if this is a context with exception-handle flag set" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2099 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2100 |
%{ /* NOCONTEXT */ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2101 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__HANDLE_MARK)) ? true : false ); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2102 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2103 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2104 |
|
1051 | 2105 |
isNonLifo |
2646 | 2106 |
"return true, if this is a nonLifo context. |
2107 |
A nonLifo context is one that is still on the machine stack, |
|
2108 |
but has a reference taken and needs to be converted to a real |
|
2109 |
object (in objectMemory) when the method/block returns. |
|
2110 |
You dont have to understand this - this is a special ST/X |
|
2111 |
debug query, which may be removed without notice." |
|
1051 | 2112 |
|
2113 |
%{ /* NOCONTEXT */ |
|
1133 | 2114 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__NONLIFO)) ? true : false ); |
1051 | 2115 |
%} |
2116 |
! |
|
2117 |
||
2118 |
isOnMachineStack |
|
2119 |
"return true, if this is a machine stack context as opposed to a |
|
2646 | 2120 |
real heap context. |
2121 |
You dont have to understand this - this is a special ST/X |
|
2122 |
debug query, which may be removed without notice." |
|
1051 | 2123 |
|
2124 |
%{ /* NOCONTEXT */ |
|
2125 |
RETURN ( (__qSpace(self) >= STACKSPACE) ? true : false ); |
|
2126 |
%} |
|
2127 |
! |
|
2128 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2129 |
isRaiseContext |
4505 | 2130 |
"return true, if this is a context with exception-raise flag set" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2131 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2132 |
%{ /* NOCONTEXT */ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2133 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__RAISE_MARK)) ? true : false ); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2134 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2135 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2136 |
|
1051 | 2137 |
isSpecial |
2138 |
"return true, if this is either a nonLifo or interrupted context" |
|
2139 |
||
2140 |
%{ /* NOCONTEXT */ |
|
1133 | 2141 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__SPECIAL)) ? true : false ); |
1051 | 2142 |
%} |
2143 |
! |
|
2144 |
||
2145 |
isUnwindContext |
|
2146 |
"return true, if this is an unwindContext" |
|
2147 |
||
2148 |
%{ /* NOCONTEXT */ |
|
1133 | 2149 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__UNWIND_MARK)) ? true : false ); |
1051 | 2150 |
%} |
8578 | 2151 |
! |
2152 |
||
2153 |
tempNames |
|
2154 |
"helper: given a context, return a collection of arg, var and temporary names" |
|
2155 |
||
2156 |
|names nTemps| |
|
2157 |
||
2158 |
names := self argAndVarNames. |
|
2159 |
(nTemps := self numTemps) > 0 ifTrue:[ |
|
2160 |
^ names , ((1 to:nTemps) collect:[:idx | '_tmp' , idx printString]). |
|
2161 |
]. |
|
2162 |
^ names. |
|
1051 | 2163 |
! ! |
2164 |
||
623 | 2165 |
!Context methodsFor:'testing'! |
2166 |
||
2167 |
isBlockContext |
|
2168 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
2169 |
||
2170 |
^ false |
|
2171 |
! |
|
2172 |
||
2173 |
isContext |
|
2174 |
"return true, iff the receiver is a Context, false otherwise" |
|
2175 |
||
2176 |
^ true |
|
2177 |
! |
|
2178 |
||
2179 |
isRecursive |
|
2180 |
"return true, if this context is one of a recursive send of the same |
|
1483 | 2181 |
selector to the same receiver before. |
2182 |
Here, different arguments are ignored - i.e. only the same method |
|
2183 |
counts for recursiveness. |
|
623 | 2184 |
Used to detect recursive errors or recursive printing - for example." |
2185 |
||
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
2186 |
|c count "{Class: SmallInteger }" myMethodsClass| |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
2187 |
|
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
2188 |
count := 0. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
2189 |
|
2893 | 2190 |
c := self findNextContextWithSelector:selector or:nil or:nil. |
623 | 2191 |
[c notNil] whileTrue:[ |
3143 | 2192 |
(c receiver == receiver) ifTrue:[ |
2193 |
" |
|
2194 |
stupid: the current ST/X context does not include |
|
2195 |
the method, but the class, in which the search started ... |
|
2196 |
" |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
2197 |
myMethodsClass isNil ifTrue:[ |
3143 | 2198 |
myMethodsClass := self methodClass. |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
2199 |
]. |
3143 | 2200 |
c methodClass == myMethodsClass ifTrue:[ |
2201 |
^ true |
|
2202 |
] |
|
2203 |
]. |
|
2204 |
c := c findNextContextWithSelector:selector or:nil or:nil. |
|
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
2205 |
|
3143 | 2206 |
" |
2207 |
this special test was added to get out after a while |
|
2208 |
if the sender chain is corrupt - this gives us at least |
|
2209 |
a chance to find those errors. |
|
2210 |
" |
|
2211 |
count := count + 1. |
|
2212 |
count >= 100000 ifTrue:[ |
|
2213 |
'Context [warning]: bad context chain' errorPrintCR. |
|
2214 |
^ true |
|
2215 |
] |
|
623 | 2216 |
]. |
2217 |
^ false |
|
1483 | 2218 |
|
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
2219 |
"Modified: 10.1.1997 / 17:34:26 / cg" |
623 | 2220 |
! ! |
2221 |
||
1810 | 2222 |
!Context class methodsFor:'documentation'! |
749 | 2223 |
|
2224 |
version |
|
10136 | 2225 |
^ '$Header: /cvs/stx/stx/libbasic/Context.st,v 1.134 2006-10-24 10:40:39 fm Exp $' |
749 | 2226 |
! ! |
7257 | 2227 |
|
623 | 2228 |
Context initialize! |