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