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