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