author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 13 Jun 2018 14:39:23 +0000 | |
branch | jv |
changeset 23108 | 77cd6e1625e1 |
parent 23107 | 40173e082cbc |
child 25392 | c52eeea62763 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
23107 | 3 |
COPYRIGHT (c) 2009-2011 Jan Vrany |
4 |
COPYRIGHT (c) 2015-2017 Jan Vrany |
|
15933 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
12853
3d15dcbe0057
added method-in-context slot.
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
11 |
other person. No t itle to or ownership of the software is |
1 | 12 |
hereby transferred. |
13 |
" |
|
5422 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17304 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1 | 18 |
Object variableSubclass:#Context |
13020 | 19 |
instanceVariableNames:'flags sender* home receiver selector searchClass method lineNr |
20 |
retvalTemp handle*' |
|
15659 | 21 |
classVariableNames:'SingleStepInterruptRequest' |
13020 | 22 |
poolDictionaries:'' |
23 |
category:'Kernel-Methods' |
|
1 | 24 |
! |
25 |
||
1810 | 26 |
!Context class methodsFor:'documentation'! |
54 | 27 |
|
88 | 28 |
copyright |
29 |
" |
|
30 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
23107 | 31 |
COPYRIGHT (c) 2009-2011 Jan Vrany |
32 |
COPYRIGHT (c) 2015-2017 Jan Vrany |
|
15933 | 33 |
All Rights Reserved |
88 | 34 |
|
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
12841 | 39 |
other person. No t itle to or ownership of the software is |
88 | 40 |
hereby transferred. |
41 |
" |
|
42 |
! |
|
43 |
||
54 | 44 |
documentation |
45 |
" |
|
402 | 46 |
Contexts represent the stack frame objects, which keep the processing |
47 |
state of a method or block (i.e. its local variables, temporaries etc.) |
|
12841 | 48 |
Every message send adds a context to a chain, which can be traced back via |
402 | 49 |
the sender field. The context of the currently active method is always |
19110 | 50 |
accessible via the pseuodoVariable called 'thisContext'. |
15688 | 51 |
The actual implementation uses the machines stack for this, building real |
52 |
contexts on demand only, whenever a contexts is needed. Also, initially these are |
|
53 |
allocated on the stack and only moved to the heap, when a context outlives its |
|
54 |
activation. |
|
54 | 55 |
|
12841 | 56 |
For both method- and block-contexts, the layout is the same. |
402 | 57 |
For method contexts, the home-field is nil, while for block contexts the home- |
141 | 58 |
field is either the context of its surrounding block (i.e. the context of the |
59 |
block, in which the receiving block was created, if its a nested block) or of |
|
12841 | 60 |
its home method. |
61 |
||
15688 | 62 |
Cheap blocks are blocks which do not refer to any locals or the receiver (currently), |
63 |
but only access globals, class vars or arguments (for example: [:a :b | a < b] is a cheap block). |
|
64 |
Cheap blocks do not need a home and therefore never require that their home context be moved |
|
65 |
to the heap. Contexts of cheap blocks do not have a home context - their home field is also nil. |
|
141 | 66 |
|
402 | 67 |
LineNumbers vs. program counter: |
68 |
||
69 |
Due to the compilation to machine code, methods and/or block do not |
|
216 | 70 |
always (actually: do seldom) contain bytecodes. Thus, there is no such concept |
71 |
as a bytecode p-counter. To support debugging, the linenumber within the |
|
72 |
original source is instead remembered when a send or loop entry is performed. |
|
73 |
Since linenumbers are not always sufficient for debugging (multiple sends in one |
|
402 | 74 |
line), this may be changed in future versions to a character offset, giving |
216 | 75 |
the position of the selector in the source. |
1 | 76 |
|
402 | 77 |
Restartable / Returnable contexts: |
78 |
||
79 |
In previous versions (up to ST/X 2.10.5), every method stored enough |
|
80 |
information in the context for that one to be restartable later (for example, |
|
15688 | 81 |
via the debugger's restart button). As stc is supposed to generate portable C-code, |
82 |
this means that technically, a setjmp needs to be done at the beginning of the method |
|
83 |
in order to have a resumable (and portable) state (however, inline asm code does this setjmp, |
|
84 |
so it is much faster than the libc-setjmo, which stores a lot of additional state, not needed here). |
|
15933 | 85 |
With 2.10.6, this is now an stc-compiler option, and the system as delivered is compiled |
15688 | 86 |
to only create restartable contexts for those which contain blocks or are marked as special |
15933 | 87 |
via a directive. |
88 |
This resulted in an overall speedup of roughly 10-20% percent, depending on the type of CPU. |
|
89 |
However, it makes most methods non-restartable (however, abort, signal handling and unwind blocks |
|
15688 | 90 |
work as usual). |
402 | 91 |
In practice, this was reported to be not a severe limitation and all users were happy |
92 |
to trade the increased performance for that slight inconvenience. |
|
93 |
(during development, this is seldom a problem, since interpreted methods are always |
|
94 |
returnable and restartable) |
|
15688 | 95 |
If you do not like this, you should recompile all classes with stc's '-optContext' flag. |
402 | 96 |
|
97 |
Resuming contexts: |
|
98 |
||
15688 | 99 |
Strictly speaking, ST/X does not support a context to be resumed (because the setjmp is |
15933 | 100 |
not done on the caller side, but in the callee). |
15688 | 101 |
However, it does support a forced return (i.e. non-local-return) from a context. |
402 | 102 |
Thus, resume of a context is implemented by forcing a return from the context |
103 |
which was created by the method called from the first one. The effect is the same. |
|
104 |
||
105 |
Returning from a dead method: |
|
106 |
||
15688 | 107 |
Block-return from an outlived context (i.e. its home method has already returned) |
402 | 108 |
is now rewarded by an invalidReturn exception - it used to be a noop in previous |
15688 | 109 |
releases. The blue book described this to be a noop, but other Smalltalk implementations |
110 |
changed this to be an invalid operation - a good decision, as it makes debugging much easier. |
|
402 | 111 |
|
112 |
||
1282 | 113 |
[instance variables:] |
19110 | 114 |
flags <SmallInteger> used by the VM; never touch. |
115 |
contains info about number of args, |
|
116 |
locals and temporaries. |
|
117 |
||
118 |
sender <Context> the 'calling / sending' context |
|
119 |
This is not directly accessible, since it may |
|
120 |
be a lazy context (i.e. an empty frame). |
|
121 |
The #sender method cares for this. |
|
122 |
||
123 |
home <Context> the context, where this block was |
|
124 |
created, or nil if its a method context |
|
125 |
There are also cheap blocks, which do |
|
126 |
not need a reference to the home context, |
|
127 |
for those, its nil too. |
|
128 |
||
129 |
receiver <Object> the receiver of this message |
|
130 |
||
131 |
selector <Symbol> the selector of this message |
|
132 |
||
133 |
searchClass <Class> the class, where the message lookup started |
|
134 |
(for super sends) or nil, for regular sends. |
|
135 |
||
136 |
lineNr <SmallInteger> the position where the context left off |
|
137 |
(kind of p-counter). Only the low 16bits |
|
138 |
are valid. |
|
139 |
||
140 |
retValTemp nil temporary - always nil, when you see the context |
|
141 |
(used in the VM as temporary) |
|
142 |
||
143 |
handle *noObject* used by the VM; not accessible, not an object |
|
144 |
||
145 |
method the corresponding method |
|
146 |
||
147 |
<indexed> arguments of the send followed by |
|
148 |
locals of the method/block followed by |
|
149 |
temporaries. |
|
1 | 150 |
|
6003 | 151 |
[errors:] |
19110 | 152 |
CannotReturnError raised when a block tries |
153 |
to return ('^') from a method context |
|
154 |
which itself has already returned |
|
155 |
(i.e. there is no place to return to) |
|
12841 | 156 |
|
69 | 157 |
WARNING: layout and size known by the compiler and runtime system - do not change. |
1282 | 158 |
|
1293 | 159 |
|
160 |
[author:] |
|
19110 | 161 |
Claus Gittinger |
1293 | 162 |
|
1282 | 163 |
[see also:] |
19110 | 164 |
Block Process Method |
165 |
( contexts, stacks & unwinding : programming/contexts.html) |
|
54 | 166 |
" |
167 |
! ! |
|
1 | 168 |
|
1810 | 169 |
!Context class methodsFor:'initialization'! |
105 | 170 |
|
171 |
initialize |
|
6000 | 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:[ |
15933 | 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 |
|
12841 | 219 |
"show the stack backtrace: at least 4 levels, or until the first |
11473 | 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 |
[ |
|
15933 | 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:[ |
|
15933 | 234 |
(' from ' , con printString) errorPrintCR. |
11631 | 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 |
%{ |
|
18406 | 259 |
#ifdef __SCHTEAM__ |
260 |
c = __c__.currentContinuation.sender(); |
|
261 |
if (c == null) c = STObject.Nil; |
|
262 |
#else |
|
4485 | 263 |
OBJ __c__; |
264 |
||
265 |
__c__ = __ContextInstPtr(__thisContext)->c_sender; |
|
10537
9ebc87dd0738
Better check for nil sender...
Stefan Vogel <sv@exept.de>
parents:
10136
diff
changeset
|
266 |
if (!__isNonNilObject(__c__)) { |
15933 | 267 |
RETURN(nil) |
10537
9ebc87dd0738
Better check for nil sender...
Stefan Vogel <sv@exept.de>
parents:
10136
diff
changeset
|
268 |
} |
4485 | 269 |
if (__isLazy(__c__)) { |
15933 | 270 |
__PATCHUPCONTEXT(__c__); |
4485 | 271 |
} |
272 |
c = __c__; |
|
18190 | 273 |
#endif |
4485 | 274 |
%}. |
275 |
^ c findSpecialHandle:searchForHandle raise:searchForRaise |
|
276 |
! ! |
|
277 |
||
12573 | 278 |
!Context methodsFor:'Compatibility-Squeak'! |
279 |
||
280 |
longStack |
|
15644 | 281 |
^ self fullPrintAllString |
12573 | 282 |
! ! |
283 |
||
7261 | 284 |
!Context methodsFor:'Compatibility-VW'! |
5983 | 285 |
|
286 |
resumeWith:value |
|
287 |
"same as #resume: - visualWorks compatibility" |
|
288 |
||
289 |
self resume:value |
|
290 |
! ! |
|
291 |
||
623 | 292 |
!Context methodsFor:'accessing'! |
293 |
||
16489 | 294 |
arg1Index |
16544 | 295 |
"return the index of the 1st arg (redefined in JavaContext)" |
296 |
||
297 |
^ 1 |
|
16489 | 298 |
! |
299 |
||
623 | 300 |
argAt:n |
301 |
"return the n'th argument" |
|
302 |
||
18437 | 303 |
n > self argumentCount ifTrue:[ |
304 |
^ self subscriptBoundsError:n. |
|
1726 | 305 |
]. |
623 | 306 |
^ self at:n |
1726 | 307 |
|
308 |
"Modified: 12.10.1996 / 21:44:28 / cg" |
|
623 | 309 |
! |
310 |
||
311 |
argAt:n put:value |
|
312 |
"set the n'th argument - useful when the receiver should be restarted" |
|
154 | 313 |
|
18437 | 314 |
n > self argumentCount ifTrue:[ |
315 |
^ self subscriptBoundsError:n. |
|
1726 | 316 |
]. |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
317 |
self at:n put:value. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
318 |
^ value |
1726 | 319 |
|
320 |
"Modified: 12.10.1996 / 21:44:32 / cg" |
|
623 | 321 |
! |
322 |
||
323 |
args |
|
324 |
"return an array filled with the arguments of this context" |
|
325 |
||
326 |
|n| |
|
327 |
||
18437 | 328 |
n := self argumentCount. |
3130 | 329 |
n == 0 ifTrue:[ |
18437 | 330 |
"/ little optimization here - avaoid creating empty containers |
331 |
^ #() |
|
3130 | 332 |
]. |
623 | 333 |
^ (Array new:n) replaceFrom:1 to:n with:self. |
334 |
! |
|
154 | 335 |
|
623 | 336 |
argsAndVars |
337 |
"return an array filled with the arguments and variables of this context" |
|
338 |
||
339 |
|n| |
|
340 |
||
18437 | 341 |
n := self argumentCount + self numVars. |
3130 | 342 |
n == 0 ifTrue:[ |
18437 | 343 |
"/ little optimization here - avoid creating empty containers |
344 |
^ #() |
|
3130 | 345 |
]. |
623 | 346 |
^ (Array new:n) replaceFrom:1 to:n with:self. |
1810 | 347 |
|
348 |
"Modified: 23.10.1996 / 16:19:41 / cg" |
|
623 | 349 |
! |
154 | 350 |
|
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
351 |
argumentCount |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
352 |
"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
|
353 |
|
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
354 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
355 |
#ifdef __SCHTEAM__ |
18289 | 356 |
return context._RETURN( STInteger._new( self.asSTContinuation().numStArgs() ) ); |
18190 | 357 |
#else |
8913 | 358 |
RETURN ( __mkSmallInteger( (__intVal(__INST(flags)) >> __NARG_SHIFT) & __NARG_MASK) ); |
18190 | 359 |
#endif |
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
360 |
%} |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
361 |
! |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
362 |
|
7324
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
363 |
at:n put:value |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
364 |
super at:n put:value. |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
365 |
|
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
366 |
"/ need some aid for optimized code - |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
367 |
"/ 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
|
368 |
"/ 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
|
369 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
370 |
#ifndef __SCHTEAM__ |
7324
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
371 |
__UNFIXCONTEXT(self, 0); |
18190 | 372 |
#endif |
7324
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
373 |
%}. |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
374 |
^ value |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
375 |
! |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
376 |
|
623 | 377 |
home |
378 |
"return the immediate home of the receiver. |
|
379 |
for block contexts, this is the methodcontext, where the block was created, |
|
15688 | 380 |
for nested block contexts, it's the surrounding block's context. |
623 | 381 |
for method-contexts this is nil." |
25 | 382 |
|
623 | 383 |
^ nil "home" |
384 |
! |
|
1 | 385 |
|
3324
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
386 |
homeReceiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
387 |
"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
|
388 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
389 |
^ receiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
390 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
391 |
"Created: / 5.3.1998 / 16:18:26 / stefan" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
392 |
! |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
393 |
|
1 | 394 |
instVarAt:index |
69 | 395 |
"have to catch instVar access to retVal and handle - they are invalid. |
12841 | 396 |
Notice, that one of the next ST/X versions might get some syntactic |
69 | 397 |
extension to get this automatically)." |
1 | 398 |
|
18190 | 399 |
|what| |
400 |
||
401 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
402 |
#ifdef __SCHTEAM__ |
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
403 |
{ |
18406 | 404 |
int idx = index.intValue("[instVarAt:]"); |
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
405 |
|
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
406 |
if (idx == I_sender) { |
18406 | 407 |
STContinuation c = self.sender(); |
408 |
if (c == null) { |
|
409 |
return __c__._RETURN_nil(); |
|
410 |
} |
|
411 |
return __c__._RETURN( c ); |
|
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
412 |
} |
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
413 |
if (idx == I_retvalTemp) { |
18406 | 414 |
return __c__._RETURN( Nil ); |
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
415 |
} |
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
416 |
if (idx == I_handle) { |
18406 | 417 |
return __c__._RETURN( Nil ); |
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
418 |
} |
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
419 |
} |
18190 | 420 |
#else |
421 |
if (index == __MKSMALLINT(__SLOT_CONTEXT_SENDER)) { // sender - must be accessed specially |
|
422 |
what = @symbol(sender); |
|
423 |
} else if (index == __MKSMALLINT(__SLOT_CONTEXT_RETVAL)) { // retvalTemp - invisible |
|
424 |
RETURN (nil); |
|
425 |
} else if (index == __MKSMALLINT(__SLOT_CONTEXT_HANDLE)) { // handle to machine stack - invisible |
|
20204
9a24c81d04ff
Context: return value of context's pSelf slot as large integer rather then nil.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19478
diff
changeset
|
426 |
RETURN ( __MKUINT ( (unsigned INT)(__ContextInstPtr(self)->c_pSelf) ) ); |
18190 | 427 |
} |
428 |
#endif |
|
429 |
%}. |
|
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
430 |
what == #sender ifTrue:[ |
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
431 |
^ self sender |
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
432 |
]. |
1 | 433 |
^ super instVarAt:index |
434 |
! |
|
435 |
||
436 |
instVarAt:index put:value |
|
69 | 437 |
"have to catch instVar access to retVal and handle - they are invalid. |
12841 | 438 |
Notice, that one of the next ST/X versions might get some syntactic |
69 | 439 |
extension to get this automatically)." |
1 | 440 |
|
18190 | 441 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
442 |
#ifdef __SCHTEAM__ |
18190 | 443 |
ERROR("unimplemented"); |
444 |
#else |
|
445 |
if (index == __MKSMALLINT(__SLOT_CONTEXT_SENDER)) { // sender - not allowed to change |
|
446 |
RETURN (nil); |
|
447 |
} else if (index == __MKSMALLINT(__SLOT_CONTEXT_RETVAL)) { // retvalTemp - not allowed to change |
|
448 |
RETURN (nil); |
|
449 |
} else if (index == __MKSMALLINT(__SLOT_CONTEXT_HANDLE)) { // handle to machine stack - not allowed to change |
|
450 |
RETURN (nil); |
|
451 |
} |
|
452 |
#endif |
|
453 |
%}. |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
454 |
super instVarAt:index put:value. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
455 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
456 |
"/ need some aid for optimized code - |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
457 |
"/ 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
|
458 |
"/ 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
|
459 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
460 |
#ifndef __SCHTEAM__ |
4570 | 461 |
__UNFIXCONTEXT(self, 0); |
18190 | 462 |
#endif |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
463 |
%}. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
464 |
^ value |
1 | 465 |
! |
466 |
||
4328
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
467 |
javaLineNumber |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
468 |
|nr pc| |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
469 |
|
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
470 |
lineNr notNil ifTrue:[ |
15933 | 471 |
pc := lineNr bitAnd:16rFFFF. |
4328
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
472 |
]. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
473 |
|
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
474 |
"/ '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
|
475 |
pc isNil ifTrue:[ |
15933 | 476 |
nr := self lineNumberFromMethod. |
477 |
nr notNil ifTrue:[ |
|
478 |
^ nr |
|
479 |
]. |
|
480 |
" '-> 0 [a]' printCR. " |
|
481 |
^0 |
|
4328
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
482 |
]. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
483 |
|
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
484 |
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
|
485 |
nr isNil ifTrue:[ |
15933 | 486 |
nr := self lineNumberFromMethod. |
487 |
nr notNil ifTrue:[ |
|
488 |
^ nr |
|
489 |
]. |
|
490 |
" '-> 0 [b]' printCR. " |
|
491 |
^ 0 |
|
4328
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
492 |
]. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
493 |
"/ '-> ' print. nr printCR. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
494 |
^ nr. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
495 |
|
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
496 |
! |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
497 |
|
623 | 498 |
lineNumber |
499 |
"this returns the lineNumber within the methods source, where the context was |
|
500 |
interrupted or called another method. (currently, sometimes this information |
|
501 |
is not available - in this case 0 is returned)" |
|
1 | 502 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
503 |
|l| |
3923 | 504 |
|
4328
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
505 |
receiver isJavaObject ifTrue:[ |
19001
b798921e18e4
Improved Contextr>argAndVarNames to better deal with inlined blocks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18978
diff
changeset
|
506 |
"/ chances are good that I am a javContext ... |
b798921e18e4
Improved Contextr>argAndVarNames to better deal with inlined blocks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18978
diff
changeset
|
507 |
self method isJavaMethod ifTrue:[ |
b798921e18e4
Improved Contextr>argAndVarNames to better deal with inlined blocks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18978
diff
changeset
|
508 |
^ self javaLineNumber |
b798921e18e4
Improved Contextr>argAndVarNames to better deal with inlined blocks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18978
diff
changeset
|
509 |
] |
4328
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
510 |
]. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
511 |
|
3923 | 512 |
lineNr notNil ifTrue:[ |
19001
b798921e18e4
Improved Contextr>argAndVarNames to better deal with inlined blocks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18978
diff
changeset
|
513 |
l := lineNr bitAnd:16rFFFF. |
3923 | 514 |
]. |
515 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
516 |
"/ self isJavaContext ifTrue:[ |nr m| |
3923 | 517 |
"/ m := self method. |
518 |
"/ l isNil ifTrue:[ |
|
519 |
"/ m notNil ifTrue:[ |
|
520 |
"/ nr := m lineNumber |
|
521 |
"/ ]. |
|
522 |
"/ nr notNil ifTrue:[ |
|
523 |
"/ ^ nr |
|
524 |
"/ ]. |
|
525 |
"/ ^0 |
|
526 |
"/ ]. |
|
527 |
"/ nr := self method lineNumberForPC:l. |
|
528 |
"/ nr isNil ifTrue:[ |
|
529 |
"/ m notNil ifTrue:[ |
|
530 |
"/ nr := m lineNumber |
|
531 |
"/ ]. |
|
532 |
"/ nr notNil ifTrue:[ |
|
533 |
"/ ^ nr |
|
534 |
"/ ]. |
|
535 |
"/ ^ 0 |
|
536 |
"/ ]. |
|
537 |
"/ ^ nr. |
|
538 |
"/ ]. |
|
539 |
||
540 |
^ l |
|
541 |
||
542 |
"Modified: / 10.11.1998 / 13:19:48 / cg" |
|
1 | 543 |
! |
544 |
||
4450 | 545 |
lineNumberFromMethod |
546 |
^ 1 |
|
547 |
! |
|
548 |
||
8488 | 549 |
message |
550 |
^ Message selector:selector arguments:self args |
|
551 |
||
552 |
" |
|
9355 | 553 |
thisContext methodHome message |
554 |
thisContext message |
|
8488 | 555 |
" |
556 |
! |
|
557 |
||
15851 | 558 |
messageSend |
559 |
^ MessageSend receiver:receiver selector:selector arguments:self args |
|
560 |
||
561 |
" |
|
562 |
thisContext methodHome messageSend |
|
563 |
thisContext messageSend |
|
564 |
" |
|
565 |
! |
|
566 |
||
1 | 567 |
method |
54 | 568 |
"return the method for which the receiver was created. |
13020 | 569 |
Change with ST/X vsn 6: |
15933 | 570 |
In older versions, the method was not stored in the context, but a lookup |
571 |
was simulated using selector and class. |
|
572 |
(which occasionally returned the wrong method - especially in the debugger, |
|
573 |
when the debugged method was changed). |
|
574 |
This has been changed - especially to support Jan's meta-object protocol. |
|
575 |
It is now stored in the context" |
|
1 | 576 |
|
3508 | 577 |
|c sender sendersSelector m| |
14225 | 578 |
|
579 |
(method notNil and:[method isMethod]) ifTrue:[ |
|
15933 | 580 |
^ method |
14225 | 581 |
]. |
582 |
||
583 |
"mhmh - maybe I am a context for an unbound method (as generated by doIt); |
|
584 |
look in the sender's context. Consider this a kludge. |
|
585 |
Future versions of ST/X's message lookup may store the method in |
|
586 |
the context. |
|
587 |
" |
|
588 |
sender := self sender. |
|
589 |
sender notNil ifTrue:[ |
|
15933 | 590 |
sendersSelector := sender selector. |
591 |
sendersSelector notNil ifTrue:[ |
|
592 |
(sendersSelector startsWith:'valueWithReceiver:') ifTrue:[ |
|
593 |
m := sender receiver. |
|
594 |
m isMethod ifTrue:[ |
|
595 |
method := m. |
|
596 |
^ m |
|
597 |
] |
|
598 |
] |
|
599 |
] |
|
12853
3d15dcbe0057
added method-in-context slot.
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
600 |
]. |
12841 | 601 |
|
325 | 602 |
c := self searchClass. |
603 |
" |
|
604 |
the below cannot happen in normal circumstances |
|
605 |
(added to avoid recursive errors in case of a broken sender chain) |
|
606 |
" |
|
607 |
c isBehavior ifFalse:[ |
|
15933 | 608 |
'Context [error]: non class in searchClass' errorPrintCR. |
609 |
' selector: ' errorPrint. selector errorPrint. |
|
610 |
' receiver: ' errorPrint. receiver errorPrintCR. |
|
611 |
^ nil |
|
325 | 612 |
]. |
613 |
||
328 | 614 |
c := c whichClassIncludesSelector:selector. |
1 | 615 |
c notNil ifTrue:[ |
15933 | 616 |
method := c compiledMethodAt:selector. |
617 |
^ method |
|
1 | 618 |
]. |
216 | 619 |
|
1 | 620 |
^ nil |
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
621 |
|
13426 | 622 |
"Modified: / 28-06-2011 / 20:23:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
14225 | 623 |
"Modified: / 20-07-2012 / 14:46:37 / cg" |
1 | 624 |
! |
625 |
||
212 | 626 |
methodClass |
627 |
"return the class in which the method for which the receiver was created is." |
|
628 |
||
1456 | 629 |
|cls m| |
630 |
||
12853
3d15dcbe0057
added method-in-context slot.
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
631 |
method notNil ifTrue:[ |
15933 | 632 |
method isMethod ifTrue:[ |
633 |
^ method mclass |
|
634 |
] |
|
12853
3d15dcbe0057
added method-in-context slot.
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
635 |
]. |
12841 | 636 |
|
1456 | 637 |
cls := self searchClass. |
3923 | 638 |
(cls isMeta |
639 |
and:[cls soleInstance isJavaClass]) ifTrue:[ |
|
15933 | 640 |
cls := cls soleInstance |
3923 | 641 |
]. |
1456 | 642 |
|
3923 | 643 |
[cls notNil] whileTrue:[ |
15933 | 644 |
cls := cls whichClassIncludesSelector:selector. |
645 |
cls isNil ifTrue:[^ nil]. |
|
646 |
||
647 |
m := cls compiledMethodAt:selector. |
|
648 |
m notNil ifTrue:[ |
|
649 |
m isIgnored ifFalse:[^ cls]. |
|
650 |
]. |
|
651 |
cls := cls superclass |
|
1456 | 652 |
]. |
653 |
^ cls |
|
654 |
||
3923 | 655 |
"Modified: / 5.11.1998 / 19:07:43 / cg" |
212 | 656 |
! |
657 |
||
623 | 658 |
methodHome |
659 |
"return the method-home - for method contexts this is the receiver" |
|
660 |
||
661 |
^ self |
|
662 |
! |
|
663 |
||
15091 | 664 |
methodSelector |
665 |
"return the method's (or home method's) selector" |
|
666 |
||
667 |
^ self methodHome selector |
|
668 |
! |
|
669 |
||
623 | 670 |
ntemp |
671 |
"return the number of temporary variables of the Block/Method. |
|
1810 | 672 |
(for debugging only). |
20792 | 673 |
I don't like the name of this method; its here for compatibility." |
623 | 674 |
|
1810 | 675 |
^ self numTemps |
676 |
||
677 |
"Modified: 23.10.1996 / 16:19:06 / cg" |
|
623 | 678 |
! |
679 |
||
680 |
numArgs |
|
681 |
"return the number of arguments to the Block/Method" |
|
682 |
||
683 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
684 |
#ifdef __SCHTEAM__ |
18289 | 685 |
return context._RETURN(STInteger._new(self.asSTContinuation().numStArgs())); |
18190 | 686 |
#else |
8913 | 687 |
RETURN ( __mkSmallInteger( (__intVal(__INST(flags)) >> __NARG_SHIFT) & __NARG_MASK) ); |
18190 | 688 |
#endif |
623 | 689 |
%} |
690 |
! |
|
691 |
||
1810 | 692 |
numTemps |
693 |
"return the number of temporary variables of the Block/Method. |
|
694 |
(for debugging only)" |
|
695 |
||
18437 | 696 |
^ self size - self argumentCount - self numVars |
1810 | 697 |
|
698 |
"Created: 23.10.1996 / 16:19:10 / cg" |
|
699 |
"Modified: 23.10.1996 / 16:19:48 / cg" |
|
700 |
! |
|
701 |
||
702 |
numVars |
|
623 | 703 |
"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
|
704 |
|
623 | 705 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
706 |
#ifdef __SCHTEAM__ |
18289 | 707 |
return context._RETURN(STInteger._new(self.asSTContinuation().numLocals(context))); |
18190 | 708 |
#else |
8913 | 709 |
RETURN ( __mkSmallInteger( (__intVal(__INST(flags)) >> __NVAR_SHIFT) & __NVAR_MASK) ); |
18190 | 710 |
#endif |
623 | 711 |
%} |
712 |
! |
|
713 |
||
1810 | 714 |
nvars |
715 |
"return the number of local variables of the Block/Method. |
|
20792 | 716 |
I don't like the name of this method; its here for compatibility." |
1810 | 717 |
|
718 |
^ self numVars |
|
719 |
||
720 |
"Modified: 23.10.1996 / 16:18:44 / cg" |
|
721 |
! |
|
722 |
||
13426 | 723 |
programmingLanguage |
724 |
||
15933 | 725 |
^method notNil |
726 |
ifTrue:[method programmingLanguage] |
|
727 |
ifFalse:[SmalltalkLanguage instance] |
|
13426 | 728 |
|
729 |
"Created: / 17-03-2011 / 10:17:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
13543
63c783128bae
changed: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
13519
diff
changeset
|
730 |
"Modified (format): / 02-08-2011 / 09:23:39 / cg" |
13426 | 731 |
! |
732 |
||
623 | 733 |
receiver |
734 |
"return the receiver of the context" |
|
18253 | 735 |
%{ /* NOCONTEXT */ |
736 |
#ifdef __SCHTEAM__ |
|
18289 | 737 |
return context._RETURN( self.asSTContinuation().stSelf(context) ); |
18253 | 738 |
#endif |
739 |
%}. |
|
623 | 740 |
^ receiver |
741 |
! |
|
742 |
||
4543 | 743 |
receiver:aCompiledCode |
744 |
"set the receiver of the message" |
|
745 |
||
4560
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
746 |
receiver := aCompiledCode. |
4543 | 747 |
|
4560
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
748 |
"/ need some aid for optimized code - |
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
749 |
"/ some machines have the arguments kept in register vars ... |
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
750 |
"/ 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
|
751 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
752 |
#ifdef __SCHTEAM__ |
18190 | 753 |
ERROR("unimplemented"); |
754 |
#else |
|
4570 | 755 |
__UNFIXCONTEXT(self, 0); |
18190 | 756 |
#endif |
4560
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
757 |
%}. |
4543 | 758 |
|
759 |
! |
|
760 |
||
623 | 761 |
searchClass |
762 |
"this is the class where the method-lookup started; |
|
19448 | 763 |
for normal sends, it is nil (or sometimes the receiver's class). |
623 | 764 |
For supersends, its the superclass of the one, in which the |
765 |
caller was defined." |
|
766 |
||
767 |
searchClass notNil ifTrue:[^ searchClass]. |
|
768 |
^ receiver class |
|
769 |
! |
|
770 |
||
771 |
selector |
|
772 |
"return the selector of the method for which the context was created" |
|
773 |
||
774 |
^ selector |
|
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
775 |
! |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
776 |
|
1 | 777 |
sender |
778 |
"return the sender of the context" |
|
779 |
||
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
780 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
781 |
#ifdef __SCHTEAM__ |
18406 | 782 |
STContinuation sender = self.sender(); |
783 |
if (sender == null) { |
|
784 |
return __c__._RETURN_nil(); |
|
785 |
} |
|
786 |
return __c__._RETURN(sender); |
|
18253 | 787 |
/* NOTREACHED */ |
18190 | 788 |
#else |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
789 |
OBJ theContext; |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
790 |
|
3508 | 791 |
theContext = __INST(sender_); |
949 | 792 |
/* |
793 |
* this special nil test is for the very first context (startup-context); |
|
794 |
* actually, its cosmetics, to avoid a visible nil>>nil context in the debugger. |
|
795 |
*/ |
|
2205 | 796 |
if (__isNonNilObject(theContext)) { |
949 | 797 |
|
15933 | 798 |
if (__isLazy(theContext)) { |
799 |
/* |
|
800 |
* this cannot happen |
|
801 |
*/ |
|
802 |
__PATCHUPCONTEXT(theContext); |
|
803 |
} |
|
804 |
if (! __isNonLIFO(theContext)) { |
|
805 |
__markNonLIFO(theContext); |
|
806 |
} |
|
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
807 |
} |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
808 |
RETURN (theContext); |
18190 | 809 |
#endif |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
810 |
%} |
1 | 811 |
! |
812 |
||
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
813 |
senderIsNil |
15319 | 814 |
"return true, if I have no sender. |
815 |
This little ugly piece of code is needed (instead of the obvious |
|
816 |
'sender isNil') because sender is a protected field, which cannot be |
|
817 |
directly accessed by smalltalk code. The reason is that the sender field |
|
818 |
is lazily filled in by the VM, in the sender-accessor, and is usually |
|
819 |
invalid until needed." |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
820 |
|
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
821 |
%{ /* NOCONTEXT */ |
18412 | 822 |
#ifdef __SCHTEAM__ |
823 |
if (((STContinuation)self).caller == null) { |
|
824 |
return __c__._RETURN_true(); |
|
825 |
} |
|
826 |
return __c__._RETURN_false(); |
|
827 |
/* NOTREACHED */ |
|
828 |
#else |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
829 |
if ( __INST(sender_) == nil ) { |
15933 | 830 |
RETURN (true); |
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
831 |
} |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
832 |
RETURN (false); |
18412 | 833 |
#endif |
5422 | 834 |
%}. |
18289 | 835 |
^ self sender isNil |
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
836 |
! |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
837 |
|
623 | 838 |
setLineNumber:aNumber |
839 |
"private entry for uncompiledCodeObject ..." |
|
1 | 840 |
|
623 | 841 |
lineNr := aNumber |
340 | 842 |
! |
843 |
||
5749 | 844 |
setNumArgs:nA numVars:nV |
845 |
"set the number of arguments and variables" |
|
846 |
||
847 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
848 |
#ifdef __SCHTEAM__ |
18190 | 849 |
ERROR("unimplemented"); |
850 |
#else |
|
8910 | 851 |
INT flg; |
5749 | 852 |
|
853 |
flg = __intVal(__INST(flags)); |
|
854 |
flg = flg & ~(__NARG_MASK << __NARG_SHIFT); |
|
855 |
flg = flg & ~(__NVAR_MASK << __NVAR_SHIFT); |
|
856 |
flg = flg | __intVal(nA) << __NARG_SHIFT; |
|
857 |
flg = flg | __intVal(nV) << __NVAR_SHIFT; |
|
8913 | 858 |
__INST(flags) = __mkSmallInteger(flg); |
18190 | 859 |
#endif |
5749 | 860 |
%} |
861 |
! |
|
862 |
||
12841 | 863 |
tempAt:index |
8578 | 864 |
"return the n'th stack-temporary variable" |
865 |
||
866 |
^ self at:index |
|
867 |
! |
|
868 |
||
12841 | 869 |
temporaries |
202 | 870 |
"return an array filled with the temporaries of this context" |
871 |
||
308 | 872 |
|nonTemps mySize| |
202 | 873 |
|
18437 | 874 |
nonTemps := self argumentCount + self numVars. |
1810 | 875 |
mySize := self numTemps. |
3130 | 876 |
mySize == 0 ifTrue:[ |
18437 | 877 |
"/ little optimization here - avaoid creating empty containers |
878 |
^ #() |
|
3130 | 879 |
]. |
308 | 880 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonTemps+1 |
1810 | 881 |
|
882 |
"Modified: 23.10.1996 / 16:20:00 / cg" |
|
202 | 883 |
! |
884 |
||
10 | 885 |
varAt:n |
886 |
"return the n'th local variable" |
|
887 |
||
18437 | 888 |
^ self at:(n + self argumentCount) |
10 | 889 |
! |
890 |
||
891 |
varAt:n put:value |
|
892 |
"set the n'th local variable - useful when the receiver should be restarted |
|
54 | 893 |
or continued" |
10 | 894 |
|
18437 | 895 |
self at:(n + self argumentCount) put:value |
10 | 896 |
! |
897 |
||
12841 | 898 |
vars |
623 | 899 |
"return an array filled with the local variables of this context" |
375 | 900 |
|
623 | 901 |
|nonVars mySize| |
360 | 902 |
|
18437 | 903 |
nonVars := self argumentCount. |
1810 | 904 |
mySize := self numVars. |
3130 | 905 |
mySize == 0 ifTrue:[ |
18437 | 906 |
"/ little optimization here - avaoid creating empty containers |
907 |
^ #() |
|
3130 | 908 |
]. |
623 | 909 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonVars+1 |
1810 | 910 |
|
911 |
"Modified: 23.10.1996 / 16:20:06 / cg" |
|
1 | 912 |
! ! |
913 |
||
623 | 914 |
!Context methodsFor:'copying'! |
415 | 915 |
|
10943 | 916 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
10136 | 917 |
|copyOfMe| |
3350
40dc4807a6d4
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
3324
diff
changeset
|
918 |
|
10136 | 919 |
copyOfMe := self shallowCopy. |
920 |
copyOfMe setSender:nil. |
|
13516
9bbdb9d05a51
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13473
diff
changeset
|
921 |
copyOfMe perform:postCopySelector withOptionalArgument:self and:aDictionary. |
10136 | 922 |
^ copyOfMe |
923 |
||
924 |
"Created: / 31-03-1998 / 15:51:14 / cg" |
|
13516
9bbdb9d05a51
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13473
diff
changeset
|
925 |
"Modified: / 21-07-2011 / 13:30:21 / cg" |
1 | 926 |
! ! |
927 |
||
15010 | 928 |
!Context methodsFor:'enumerating'! |
929 |
||
930 |
withAllSendersDo:aBlock |
|
931 |
"evaluate aBlock for me and all contexts of my sender chain" |
|
932 |
||
21146 | 933 |
self withSendersUpToContextForWhich:[:con | false] do:aBlock |
934 |
! |
|
935 |
||
936 |
withSendersThroughContextForWhich:checkBlock do:aBlock |
|
937 |
"evaluate aBlock for me and all contexts of my sender chain, |
|
938 |
until checkBlock returns true (incl. that last one)" |
|
939 |
||
15010 | 940 |
|con| |
941 |
||
942 |
con := self. |
|
943 |
[ con notNil ] whileTrue:[ |
|
21146 | 944 |
aBlock value:con. |
945 |
(checkBlock value:con) ifTrue:[^ self]. |
|
946 |
con := con sender. |
|
947 |
] |
|
948 |
! |
|
949 |
||
950 |
withSendersUpToContextForWhich:checkBlock do:aBlock |
|
951 |
"evaluate aBlock for me and all contexts of my sender chain, |
|
952 |
until checkBlock returns true, excl. that context." |
|
953 |
||
954 |
|con| |
|
955 |
||
956 |
con := self. |
|
957 |
[ con notNil ] whileTrue:[ |
|
958 |
(checkBlock value:con) ifTrue:[^ self]. |
|
959 |
aBlock value:con. |
|
960 |
con := con sender. |
|
15010 | 961 |
] |
962 |
! ! |
|
963 |
||
77 | 964 |
!Context methodsFor:'error handling'! |
965 |
||
966 |
invalidReturn:returnValue |
|
967 |
"this message is sent by the VM, when a methods context |
|
968 |
which has already returned is about to return again. |
|
969 |
(i.e. about to execute a return from an already returned |
|
105 | 970 |
method in a block). |
141 | 971 |
We raise a signal here, to allow catching of that situation." |
77 | 972 |
|
406 | 973 |
" |
974 |
in previous versions of ST/X and ST-80, this was no error; |
|
975 |
(instead, a normal blockreturn was performed to the value-sender). |
|
976 |
From a note in comp.lang.smalltalk, I conclude that new ST-80 versions |
|
977 |
now raise an error if this happens. |
|
978 |
Comment out the raise below to get that (old) behavior |
|
979 |
BETTER REWRITE YOUR APPLICATION |
|
12841 | 980 |
" |
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
981 |
"/ old behavior: |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
982 |
"/ ^ returnValue |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
983 |
|
282 | 984 |
"/ new behavior: |
985 |
||
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
986 |
"/ 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
|
987 |
"/ use another error message. |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
988 |
|
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
989 |
(home notNil and:[home sender notNil]) ifTrue:[ |
15933 | 990 |
^ CannotReturnError |
991 |
raiseRequestWith:returnValue |
|
992 |
errorString:'cannot return from another process''s context'. |
|
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
993 |
]. |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
994 |
|
12841 | 995 |
^ CannotReturnError |
15933 | 996 |
raiseRequestWith:returnValue. |
282 | 997 |
|
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
998 |
"Modified: / 2.2.1998 / 15:19:52 / cg" |
406 | 999 |
! |
1000 |
||
1001 |
invalidReturnOrRestart:returnValue |
|
15268 | 1002 |
"this message is sent by the VM, when a method's or block's context |
1003 |
which was compiled non-returnable is about to return again, |
|
1004 |
or a non-restartable context is tried to be restarted. |
|
1005 |
In ST/X, not all contexts are restartable/returnable. |
|
406 | 1006 |
We raise a signal here, to allow catching of that situation." |
1007 |
||
6002 | 1008 |
^ CannotReturnError |
15933 | 1009 |
raiseRequestWith:returnValue |
1010 |
errorString:'method was compiled non-resumable' |
|
360 | 1011 |
! |
1012 |
||
1013 |
invalidReturnOrRestartError:how with:value |
|
1014 |
"common error reporter for restart/return errors" |
|
12841 | 1015 |
|
360 | 1016 |
self canReturn ifTrue:[ |
15933 | 1017 |
" |
1018 |
tried to return from/restart a context which is already dead |
|
1019 |
(i.e. the method/block has already executed a return) |
|
1020 |
" |
|
1021 |
^ CannotReturnError |
|
1022 |
raiseRequestWith:value |
|
1023 |
errorString:(how , ' context not on calling chain') |
|
360 | 1024 |
]. |
1025 |
" |
|
1026 |
tried to return from/restart a context of a method which was compiled |
|
1027 |
unrestartable or of a block (which is never restartable) |
|
1028 |
" |
|
12841 | 1029 |
^ CannotReturnError |
15933 | 1030 |
raiseRequestWith:value |
1031 |
errorString:(how , ' context cannot be restarted/returned from') |
|
77 | 1032 |
! ! |
1033 |
||
6404 | 1034 |
!Context methodsFor:'fixups'! |
1035 |
||
1036 |
fixAllLineNumbers |
|
1037 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1038 |
#ifdef __SCHTEAM__ |
18190 | 1039 |
ERROR("unimplemented"); |
1040 |
#else |
|
6404 | 1041 |
__PATCHUPCONTEXTS(__thisContext); |
6424 | 1042 |
__CONTEXTLINENOS(self); |
18190 | 1043 |
#endif |
6404 | 1044 |
%} |
1045 |
! ! |
|
1046 |
||
623 | 1047 |
!Context methodsFor:'minidebugger printing'! |
1048 |
||
1049 |
fullPrint |
|
12841 | 1050 |
"print the receiver, selector and args of the context |
20840 | 1051 |
- used only for MiniDebugger's walkback print" |
1052 |
||
1053 |
self receiverPrintString _errorPrint. ' ' _errorPrint. selector _errorPrint. |
|
18437 | 1054 |
self argumentCount ~~ 0 ifTrue: [ |
20840 | 1055 |
' ' _errorPrint. self argsDisplayString _errorPrint |
623 | 1056 |
]. |
20840 | 1057 |
' [' _errorPrint. self lineNumber _errorPrint. ']' _errorPrintCR |
623 | 1058 |
|
1059 |
" |
|
1060 |
thisContext fullPrint |
|
1061 |
" |
|
1426 | 1062 |
|
1063 |
"Modified: 20.5.1996 / 10:27:14 / cg" |
|
623 | 1064 |
! |
1065 |
||
1066 |
fullPrintAll |
|
1067 |
"print a full walkback starting at the receiver |
|
20840 | 1068 |
- used only for MiniDebugger's walkback print" |
623 | 1069 |
|
15010 | 1070 |
self withAllSendersDo:[:con | con fullPrint]. |
623 | 1071 |
|
1072 |
" |
|
1073 |
thisContext fullPrintAll |
|
1074 |
" |
|
2173 | 1075 |
! |
1076 |
||
4674 | 1077 |
fullPrintAllLevels:nOrNil |
1078 |
"print a full walkback starting at the receiver, only print n levels |
|
20840 | 1079 |
- used only for MiniDebugger's walkback print" |
4674 | 1080 |
|
1081 |
|context count| |
|
1082 |
||
1083 |
count := 0. |
|
1084 |
context := self. |
|
1085 |
[context notNil] whileTrue: [ |
|
20840 | 1086 |
context fullPrint. |
1087 |
context := context sender. |
|
1088 |
nOrNil notNil ifTrue:[ |
|
1089 |
(count := count+1) > nOrNil ifTrue:[^self]. |
|
1090 |
] |
|
4674 | 1091 |
] |
1092 |
||
1093 |
" |
|
6648 | 1094 |
thisContext fullPrintAllLevels:5 |
4674 | 1095 |
" |
1096 |
||
1097 |
"Created: / 3.9.1999 / 14:02:38 / ps" |
|
11540 | 1098 |
! |
1099 |
||
11542 | 1100 |
printAll |
1101 |
"print a full walkback starting at the receiver, only print n levels |
|
20840 | 1102 |
- used only for MiniDebugger's walkback print" |
11542 | 1103 |
|
1104 |
self printAllLevels:nil |
|
1105 |
||
1106 |
" |
|
1107 |
thisContext printAll |
|
1108 |
" |
|
1109 |
! |
|
1110 |
||
11540 | 1111 |
printAllLevels:nOrNil |
1112 |
"print a full walkback starting at the receiver, only print n levels |
|
20840 | 1113 |
- used only for MiniDebugger's walkback print" |
11540 | 1114 |
|
1115 |
|context count| |
|
1116 |
||
1117 |
count := 0. |
|
1118 |
context := self. |
|
16247 | 1119 |
'--------------------------' errorPrintCR. |
11540 | 1120 |
[context notNil] whileTrue: [ |
20840 | 1121 |
context errorPrintCR. |
1122 |
context := context sender. |
|
1123 |
nOrNil notNil ifTrue:[ |
|
1124 |
(count := count+1) > nOrNil ifTrue:[ |
|
1125 |
'--------------------------' errorPrintCR. |
|
1126 |
^ self |
|
1127 |
]. |
|
1128 |
] |
|
11545 | 1129 |
]. |
16247 | 1130 |
'--------------------------' errorPrintCR. |
11540 | 1131 |
|
1132 |
" |
|
1133 |
thisContext printAllLevels:5 |
|
1134 |
" |
|
623 | 1135 |
! ! |
1136 |
||
1 | 1137 |
!Context methodsFor:'non local control flow'! |
1138 |
||
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1139 |
evaluateUnwindActionsUpTo:aContext |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1140 |
"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
|
1141 |
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
|
1142 |
marked using #markForUnwind. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1143 |
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
|
1144 |
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
|
1145 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1146 |
|con unwindBlock| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1147 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1148 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1149 |
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
|
1150 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1151 |
con := self findNextUnwindContextOr:aContext. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1152 |
[con notNil and:[con ~~ aContext]] whileTrue:[ |
15933 | 1153 |
unwindBlock := con receiver unwindHandlerInContext:con. |
1154 |
con unmarkForUnwind. |
|
1155 |
unwindBlock value. |
|
1156 |
||
1157 |
con := con findNextUnwindContextOr:aContext. |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1158 |
]. |
11340
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
1159 |
"/ 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
|
1160 |
(con notNil and:[con isMarkedForUnwind]) ifTrue:[ |
15933 | 1161 |
unwindBlock := con receiver unwindHandlerInContext:con. |
1162 |
con unmarkForUnwind. |
|
1163 |
unwindBlock value. |
|
11340
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
1164 |
]. |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1165 |
^ con |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1166 |
! |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1167 |
|
15688 | 1168 |
resend |
1169 |
"EXPERIMENTAL: resend the context's message (to the same receiver). |
|
1170 |
if the method's implementation has been changed in the meanwhile (for example, in the debugger), |
|
1171 |
the new code is executed. Otherwise the same code is reexecuted from the start." |
|
1172 |
||
1173 |
self returnDoing:[ receiver perform:selector withArguments:(self args) ]. |
|
1174 |
||
1175 |
" |
|
1176 |
when we arrive here, something went wrong. |
|
1177 |
debugging ... |
|
1178 |
" |
|
1179 |
^ self invalidReturnOrRestartError:#'resend' with:nil |
|
1180 |
! |
|
1181 |
||
1 | 1182 |
restart |
1183 |
"restart the receiver - i.e. the method is evaluated again. |
|
402 | 1184 |
if the context to restart already died, trigger an error. |
141 | 1185 |
This is a low level helper for unwindAndRestart. |
1186 |
||
12841 | 1187 |
NOTICE: |
15933 | 1188 |
NO unwind actions are performed - this is usually not |
1189 |
what you want (see Context>>unwindAndRestart). |
|
12841 | 1190 |
|
1191 |
LIMITATION: |
|
15933 | 1192 |
currently a context can only be restarted by |
1193 |
the owning process - not from outside. |
|
1194 |
Also, the compiler has an option (+optcontext) to create |
|
1195 |
non-restartable contexts (which are faster). |
|
1196 |
If such a context is restarted, a runtime error is raised." |
|
1 | 1197 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1198 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1199 |
#ifdef __SCHTEAM__ |
18364 | 1200 |
return __c__.RESTART(self); |
1201 |
/* NOTREACHED */ |
|
18190 | 1202 |
#else |
15650 | 1203 |
if (__INST(sender_) == nil) { |
15933 | 1204 |
RETURN(nil); |
15650 | 1205 |
} else { |
15933 | 1206 |
__RESUMECONTEXT__(self, RESTART_VALUE, 0); |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1207 |
} |
18190 | 1208 |
#endif |
360 | 1209 |
%}. |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1210 |
|
69 | 1211 |
" |
360 | 1212 |
when we arrive here, something went wrong. |
69 | 1213 |
debugging ... |
1214 |
" |
|
360 | 1215 |
^ self invalidReturnOrRestartError:#restart with:nil |
1 | 1216 |
! |
1217 |
||
623 | 1218 |
resume |
1219 |
"resume execution in this context. I.e. as if the method called |
|
1220 |
last by the receiver did a ^ nil. |
|
1221 |
If the context has already returned, report an error. |
|
1222 |
||
1223 |
NOTICE: |
|
15933 | 1224 |
NO unwind actions are performed (see Context>>unwind). |
12841 | 1225 |
|
1226 |
LIMITATION: |
|
15933 | 1227 |
currently a context can only be resumed by |
1228 |
the owning process - not from outside. |
|
1229 |
Also, the compiler has an option (+optcontext) to create |
|
1230 |
non-resumable contexts (which are faster). |
|
1231 |
If such a context is restarted, a runtime error is raised." |
|
623 | 1232 |
|
1233 |
^ self resume:nil |
|
1234 |
! |
|
1235 |
||
1236 |
resume:value |
|
1237 |
"resume the receiver - as if it got 'value' from whatever |
|
19448 | 1238 |
it called. This continues execution in the receiver's method |
623 | 1239 |
after the point where it did its last send. |
12841 | 1240 |
If the context has already returned - report an error. |
623 | 1241 |
|
1242 |
NOTICE: |
|
19448 | 1243 |
NO unwind actions are performed (see Context>>unwind:). |
623 | 1244 |
|
12841 | 1245 |
LIMITATION: |
19448 | 1246 |
currently a context can only be resumed by |
1247 |
the owning process - not from outside. |
|
1248 |
Also, the compiler has an option (+optcontext) to create |
|
1249 |
non-resumable contexts (which are faster). |
|
1250 |
If such a context is restarted, a runtime error is raised." |
|
623 | 1251 |
|
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
1252 |
|theContext| |
623 | 1253 |
|
1254 |
" |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
1255 |
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
|
1256 |
(i.e. the one that I have called) and return from it. |
623 | 1257 |
" |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1258 |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
1259 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1260 |
#ifdef __SCHTEAM__ |
18408 | 1261 |
return __c__._RETURN_TO(value, self.asSTContinuation()); |
1262 |
/* NOTREACHED */ |
|
18190 | 1263 |
#else |
4557 | 1264 |
OBJ sndr; |
1265 |
||
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
1266 |
theContext = __thisContext; |
4557 | 1267 |
while (theContext != nil) { |
19448 | 1268 |
sndr = __ContextInstPtr(theContext)->c_sender; |
1269 |
if (sndr == self) break; |
|
1270 |
theContext = sndr; |
|
623 | 1271 |
} |
3508 | 1272 |
if (theContext != nil) { |
19448 | 1273 |
if (__isLazy(theContext)) { |
1274 |
__PATCHUPCONTEXT(theContext); |
|
1275 |
} |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1276 |
} |
18190 | 1277 |
#endif |
623 | 1278 |
%}. |
1279 |
||
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
1280 |
theContext isNil ifTrue:[ |
19448 | 1281 |
" |
1282 |
tried to resume in context which is already dead |
|
1283 |
(i.e. the method/block has already executed a return) |
|
1284 |
" |
|
1285 |
^ thisContext invalidReturnOrRestartError:#'resume:' with:value |
|
623 | 1286 |
]. |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
1287 |
^ theContext return:value |
623 | 1288 |
! |
1289 |
||
4557 | 1290 |
resumeIgnoringErrors:value |
1291 |
"resume the receiver - as if it got 'value' from whatever |
|
19448 | 1292 |
it called. This continues execution in the receiver's method |
4557 | 1293 |
after the point where it did its last send. |
12841 | 1294 |
If the context has already returned - simply return. |
4557 | 1295 |
|
1296 |
NOTICE: |
|
19448 | 1297 |
NO unwind actions are performed (see Context>>unwind:). |
4557 | 1298 |
|
12841 | 1299 |
LIMITATION: |
19448 | 1300 |
currently a context can only be resumed by |
1301 |
the owning process - not from outside. |
|
1302 |
Also, the compiler has an option (+optcontext) to create |
|
1303 |
non-resumable contexts (which are faster). |
|
1304 |
If such a context is restarted, a runtime error is raised." |
|
4557 | 1305 |
|
1306 |
" |
|
1307 |
starting with this context, find the one below |
|
1308 |
(i.e. the one that I have called) and return from it. |
|
1309 |
" |
|
1310 |
||
1311 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1312 |
#ifdef __SCHTEAM__ |
18408 | 1313 |
return __c__._RETURN_TO(value, self.asSTContinuation()); |
1314 |
/* NOTREACHED */ |
|
18190 | 1315 |
#else |
4557 | 1316 |
OBJ theContext, sndr; |
1317 |
||
1318 |
theContext = __thisContext; |
|
1319 |
while (theContext != nil) { |
|
19448 | 1320 |
sndr = __ContextInstPtr(theContext)->c_sender; |
1321 |
if (sndr == self) break; |
|
1322 |
theContext = sndr; |
|
4557 | 1323 |
} |
1324 |
if (theContext != nil) { |
|
19448 | 1325 |
if (__ContextInstPtr(theContext)->c_sender) { |
1326 |
if (!((INT)(__ContextInstPtr(theContext)->c_flags) & __MASKSMALLINT(__CANNOT_RETURN))) { |
|
1327 |
__RESUMECONTEXT__(theContext, value, 0); |
|
1328 |
} |
|
1329 |
} |
|
4557 | 1330 |
} |
18190 | 1331 |
#endif |
4557 | 1332 |
%}. |
1333 |
||
1334 |
"/ no error reporting |
|
1335 |
! |
|
1336 |
||
1337 |
resumeOnErrorProceed:value |
|
1338 |
"resume the receiver - as if it got 'value' from whatever |
|
19448 | 1339 |
it called. This continues execution in the receiver's method |
4557 | 1340 |
after the point where it did its last send. |
12841 | 1341 |
If the context has already returned - simply return. |
4557 | 1342 |
|
1343 |
NOTICE: |
|
19448 | 1344 |
NO unwind actions are performed (see Context>>unwind:). |
4557 | 1345 |
|
12841 | 1346 |
LIMITATION: |
19448 | 1347 |
currently a context can only be resumed by |
1348 |
the owning process - not from outside. |
|
1349 |
Also, the compiler has an option (+optcontext) to create |
|
1350 |
non-resumable contexts (which are faster). |
|
1351 |
If such a context is restarted, a runtime error is raised." |
|
4557 | 1352 |
|
1353 |
" |
|
1354 |
starting with this context, find the one below |
|
1355 |
(i.e. the one that I have called) and return from it. |
|
1356 |
" |
|
1357 |
||
1358 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1359 |
#ifdef __SCHTEAM__ |
18408 | 1360 |
return __c__._RETURN_TO(value, self.asSTContinuation()); |
1361 |
/* NOTREACHED */ |
|
18190 | 1362 |
#else |
4557 | 1363 |
OBJ theContext, sndr; |
1364 |
||
1365 |
theContext = __thisContext; |
|
1366 |
while (theContext != nil) { |
|
19448 | 1367 |
sndr = __ContextInstPtr(theContext)->c_sender; |
1368 |
if (sndr == self) break; |
|
1369 |
theContext = sndr; |
|
4557 | 1370 |
} |
1371 |
if (theContext != nil) { |
|
19448 | 1372 |
if (__ContextInstPtr(theContext)->c_sender) { |
1373 |
__RESUMECONTEXT__(theContext, value, 0); |
|
1374 |
} |
|
4557 | 1375 |
} |
18190 | 1376 |
#endif |
4557 | 1377 |
%}. |
1378 |
||
1379 |
"/ no error reporting |
|
1380 |
! |
|
1381 |
||
69 | 1382 |
return |
141 | 1383 |
"return from this context with nil. I.e. as if it did a ^ nil. |
1384 |
NOTICE: |
|
15933 | 1385 |
NO unwind actions are performed - this is usually not |
1386 |
what you want (See Context>>unwind). |
|
1387 |
This is a low level method - a helper for unwind. |
|
12841 | 1388 |
|
1389 |
LIMITATION: |
|
15933 | 1390 |
currently a context can only be returned by |
1391 |
the owning process - not from outside. |
|
1392 |
Also, the compiler has an option (+optcontext) to create |
|
1393 |
non-returnable contexts (which are faster). |
|
1394 |
If such a context is restarted, a runtime error is raised." |
|
141 | 1395 |
|
1396 |
^ self return:nil |
|
1 | 1397 |
! |
1398 |
||
69 | 1399 |
return:value |
1400 |
"return from this context as if it did a '^ value'. |
|
141 | 1401 |
NOTICE: |
15933 | 1402 |
NO unwind actions are performed - this is usually not |
1403 |
what you want (See Context>>unwind:). |
|
1404 |
This is a low level method - a helper for unwind. |
|
141 | 1405 |
|
12841 | 1406 |
LIMITATION: |
15933 | 1407 |
currently a context can only be returned by |
1408 |
the owning process - not from outside. |
|
1409 |
Also, the compiler has an option (+optcontext) to create |
|
1410 |
non-returnable contexts (which are faster). |
|
1411 |
If such a context is restarted, a runtime error is raised." |
|
1 | 1412 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1413 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1414 |
#ifdef __SCHTEAM__ |
18408 | 1415 |
return __c__._RETURN_FROM(value, self.asSTContinuation()); |
1416 |
/* NOTREACHED */ |
|
18190 | 1417 |
#else |
15651 | 1418 |
if (__INST(sender_) == nil) { |
15933 | 1419 |
RETURN(nil); |
15651 | 1420 |
} else { |
15933 | 1421 |
__RESUMECONTEXT__(self, value, 0); |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1422 |
} |
18190 | 1423 |
#endif |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1424 |
%}. |
1 | 1425 |
|
69 | 1426 |
" |
360 | 1427 |
when we arrive here, something went wrong. |
69 | 1428 |
debugging ... |
1429 |
" |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1430 |
^ self invalidReturnOrRestartError:#'return' with:value |
1 | 1431 |
! |
1432 |
||
328 | 1433 |
returnDoing:aBlock |
1434 |
"return from this context as if it did a '^ aBlock value'. |
|
1435 |
The block is evaluated as if called by the receiver context; |
|
1436 |
NOT the true executing context. |
|
1437 |
NOTICE: |
|
15933 | 1438 |
NO unwind actions are performed - this is usually not |
1439 |
what you want (See Context>>unwindThenDo:). |
|
1440 |
This is a low level method - a helper for unwind. |
|
328 | 1441 |
|
1442 |
LIMITATION: |
|
15933 | 1443 |
currently a context can only be returned by |
1444 |
the owning process - not from outside. |
|
1445 |
Also, the compiler has an option (+optcontext) to create |
|
1446 |
non-returnable contexts (which are faster). |
|
1447 |
If such a context is restarted, a runtime error is raised." |
|
328 | 1448 |
|
12841 | 1449 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1450 |
#ifdef __SCHTEAM__ |
18190 | 1451 |
ERROR("unimplemented"); |
1452 |
#else |
|
15651 | 1453 |
if (__INST(sender_) == nil) { |
15933 | 1454 |
RETURN(nil); |
15651 | 1455 |
} else { |
15933 | 1456 |
__RESUMECONTEXT__(self, aBlock, 2); |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1457 |
} |
18190 | 1458 |
#endif |
360 | 1459 |
%}. |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1460 |
|
328 | 1461 |
" |
360 | 1462 |
when we arrive here, something went wrong. |
328 | 1463 |
debugging ... |
1464 |
" |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1465 |
^ self invalidReturnOrRestartError:#'returnDoing' with:aBlock |
328 | 1466 |
! |
1467 |
||
1 | 1468 |
unwind |
69 | 1469 |
"return nil from the receiver - i.e. simulate a '^ nil'. |
11337 | 1470 |
If the context has already returned, report an error. |
1 | 1471 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
69 | 1472 |
and Block>>valueOnUnwindDo: on the way. |
1 | 1473 |
|
12841 | 1474 |
LIMITATION: |
15933 | 1475 |
currently a context can only be unwound by |
1476 |
the owning process - not from outside. |
|
1477 |
i.e. it is not possible for one thread to unwind |
|
1478 |
another threads context - which does not make sense anyway. |
|
1479 |
However, you can force another thread to do this in its own process |
|
1480 |
context, by giving it an interrupt action - this does make sense. |
|
1481 |
||
1482 |
Also, the compiler has an option (+optcontext) to create |
|
1483 |
non-returnable contexts (which are faster). |
|
1484 |
If such a context is restarted, a runtime error is raised." |
|
141 | 1485 |
|
1486 |
^ self unwind:nil |
|
1 | 1487 |
! |
1488 |
||
1489 |
unwind:value |
|
69 | 1490 |
"return value from the receiver - i.e. simulate a '^ value'. |
360 | 1491 |
If the context has already returned , report an error. |
1 | 1492 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
69 | 1493 |
and Block>>valueOnUnwindDo: on the way. |
141 | 1494 |
|
12841 | 1495 |
LIMITATION: |
15933 | 1496 |
currently a context can only be unwound by |
1497 |
the owning process - not from outside. |
|
1498 |
i.e. it is not possible for one thread to unwind |
|
1499 |
another threads context - which does not make sense anyway. |
|
1500 |
However, you can force another thread to do this in its own process |
|
1501 |
context, by giving it an interrupt action - this does make sense. |
|
1502 |
||
1503 |
Also, the compiler has an option (+optcontext) to create |
|
1504 |
non-returnable contexts (which are faster). |
|
1505 |
If such a context is restarted, a runtime error is raised." |
|
1 | 1506 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1507 |
|con| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1508 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1509 |
self senderIsNil ifFalse:[ |
15933 | 1510 |
con := thisContext evaluateUnwindActionsUpTo:self. |
141 | 1511 |
]. |
1 | 1512 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1513 |
"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
|
1514 |
(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
|
1515 |
should we check for this situation first and NOT evaluate |
141 | 1516 |
the unwind actions in this case ?) |
1517 |
" |
|
69 | 1518 |
con isNil ifTrue:[ |
15933 | 1519 |
" |
1520 |
tried to return to a context which is already dead |
|
1521 |
(i.e. the method/block has already executed a return) |
|
1522 |
" |
|
1523 |
^ self invalidReturnOrRestartError:#'unwind:' with:value |
|
69 | 1524 |
]. |
141 | 1525 |
" |
1526 |
now, that all unwind-actions are done, I can use the |
|
1527 |
low-level return ... |
|
1528 |
" |
|
1529 |
^ self return:value |
|
1530 |
! |
|
1531 |
||
1532 |
unwindAndRestart |
|
1533 |
"restart the receiver - i.e. the method is evaluated again. |
|
13804 | 1534 |
if the context to restart already did report an error. |
141 | 1535 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
1536 |
and Block>>valueOnUnwindDo: before restarting. |
|
1537 |
||
12841 | 1538 |
LIMITATION: |
15933 | 1539 |
a context can only be restarted by |
1540 |
the owning process - not from outside. |
|
1541 |
i.e. it is not possible for one thread to unwindAndRestart |
|
1542 |
another threads context - which does not make sense anyway. |
|
1543 |
However, you can force another thread to do this in its own process |
|
1544 |
context, by giving it an interrupt action - this does make sense. |
|
1545 |
||
1546 |
Also, the compiler has an option (+optcontext) to create |
|
1547 |
non-restartable contexts (which are faster). |
|
1548 |
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
|
1549 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1550 |
|con| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1551 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1552 |
self senderIsNil ifFalse:[ |
15933 | 1553 |
con := thisContext evaluateUnwindActionsUpTo:self. |
141 | 1554 |
]. |
1555 |
||
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1556 |
"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
|
1557 |
(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
|
1558 |
should we check for this situation first and NOT evaluate |
141 | 1559 |
the unwind actions in this case ?) |
1560 |
" |
|
1561 |
con isNil ifTrue:[ |
|
15933 | 1562 |
" |
1563 |
tried to return to a context which is already dead |
|
1564 |
(i.e. the method/block has already executed a return) |
|
1565 |
" |
|
1566 |
^ self invalidReturnOrRestartError:#'unwindAndRestart:' with:nil |
|
141 | 1567 |
]. |
1568 |
" |
|
1569 |
now, that all unwind-actions are done, I can use the |
|
1570 |
low-level restart ... |
|
1571 |
" |
|
1572 |
^ self restart |
|
328 | 1573 |
! |
1574 |
||
4485 | 1575 |
unwindAndResume:value |
1576 |
"resume execution in the the receiver - i.e. simulate a '^ value' |
|
1577 |
from whatever it called last. |
|
1578 |
If the context has already returned , report an error. |
|
1579 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
|
1580 |
and Block>>valueOnUnwindDo: on the way. |
|
1581 |
||
12841 | 1582 |
LIMITATION: |
15933 | 1583 |
currently a context can only be unwound by |
1584 |
the owning process - not from outside. |
|
1585 |
i.e. it is not possible for one thread to unwind |
|
1586 |
another threads context - which does not make sense anyway. |
|
1587 |
However, you can force another thread to do this in its own process |
|
1588 |
context, by giving it an interrupt action - this does make sense. |
|
1589 |
||
1590 |
Also, the compiler has an option (+optcontext) to create |
|
1591 |
non-returnable contexts (which are faster). |
|
1592 |
If such a context is restarted, a runtime error is raised." |
|
4485 | 1593 |
|
1594 |
|con| |
|
1595 |
||
1596 |
self senderIsNil ifFalse:[ |
|
15933 | 1597 |
con := thisContext evaluateUnwindActionsUpTo:self. |
4485 | 1598 |
]. |
1599 |
||
1600 |
"oops, if nil, I am not on the calling chain; |
|
1601 |
(bad bad, unwind action have already been performed. |
|
1602 |
should we check for this situation first and NOT evaluate |
|
1603 |
the unwind actions in this case ?) |
|
1604 |
" |
|
1605 |
con isNil ifTrue:[ |
|
15933 | 1606 |
" |
1607 |
tried to return to a context which is already dead |
|
1608 |
(i.e. the method/block has already executed a return) |
|
1609 |
" |
|
1610 |
^ self invalidReturnOrRestartError:#'unwindAndResume:' with:value |
|
4485 | 1611 |
]. |
1612 |
" |
|
1613 |
now, that all unwind-actions are done, I can use the |
|
1614 |
low-level resume ... |
|
1615 |
" |
|
1616 |
^ self resume:value |
|
1617 |
! |
|
1618 |
||
12841 | 1619 |
unwindThenDo:aBlock |
328 | 1620 |
"return the value of aBlock from the receiver - i.e. simulate a '^ aBlock value'. |
13804 | 1621 |
If the context has already returned, report an error. |
328 | 1622 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
1623 |
and Block>>valueOnUnwindDo: on the way. |
|
1624 |
The block is evaluated AFTER all unwind actions are performed |
|
15688 | 1625 |
(i.e. the block's sender will be the receiving context, not the |
402 | 1626 |
currently executing context) |
328 | 1627 |
|
12841 | 1628 |
LIMITATION: |
15933 | 1629 |
currently a context can only be unwound by |
1630 |
the owning process - not from outside |
|
1631 |
i.e. it is not possible for one thread to unwindThenDo |
|
1632 |
another threads context - which does not make sense anyway. |
|
1633 |
However, you can force another thread to do this in its own process |
|
1634 |
context, by giving it an interrupt action - this does make sense. |
|
1635 |
||
1636 |
Also, the compiler has an option (+optcontext) to create |
|
1637 |
non-returnable contexts (which are faster). |
|
1638 |
If such a context is restarted, a runtime error is raised." |
|
328 | 1639 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1640 |
|con| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1641 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1642 |
self senderIsNil ifFalse:[ |
15933 | 1643 |
con := thisContext evaluateUnwindActionsUpTo:self. |
328 | 1644 |
]. |
1645 |
||
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1646 |
"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
|
1647 |
(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
|
1648 |
should we check for this situation first and NOT evaluate |
328 | 1649 |
the unwind actions in this case ?) |
1650 |
" |
|
1651 |
con isNil ifTrue:[ |
|
15933 | 1652 |
" |
1653 |
tried to return to a context which is already dead |
|
1654 |
(i.e. the method/block has already executed a return) |
|
1655 |
" |
|
1656 |
^ self invalidReturnOrRestartError:#'unwindThenDo:' with:aBlock |
|
328 | 1657 |
]. |
1658 |
" |
|
1659 |
now, that all unwind-actions are done, I can use the |
|
1660 |
low-level return ... |
|
1661 |
" |
|
12841 | 1662 |
^ self returnDoing:aBlock |
15688 | 1663 |
! |
1664 |
||
1665 |
unwindThenResend |
|
1666 |
"EXPERIMENTAL: resend the context's message (to the same receiver). |
|
1667 |
if the method's implementation has been changed in the meanwhile (for example, in the debugger), |
|
1668 |
the new code is executed. Otherwise the same code is reexecuted from the start. |
|
1669 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
|
1670 |
and Block>>valueOnUnwindDo: on the way. |
|
1671 |
The resend happens AFTER all unwind actions are performed |
|
1672 |
||
1673 |
LIMITATION: |
|
15933 | 1674 |
currently a context can only be unwound by |
1675 |
the owning process - not from outside |
|
1676 |
i.e. it is not possible for one thread to unwindThenDo |
|
1677 |
another threads context - which does not make sense anyway. |
|
1678 |
However, you can force another thread to do this in its own process |
|
1679 |
context, by giving it an interrupt action - this does make sense. |
|
1680 |
||
1681 |
Also, the compiler has an option (+optcontext) to create |
|
1682 |
non-returnable contexts (which are faster). |
|
1683 |
If such a context is restarted, a runtime error is raised." |
|
15688 | 1684 |
|
1685 |
|con| |
|
1686 |
||
1687 |
self senderIsNil ifFalse:[ |
|
15933 | 1688 |
con := thisContext evaluateUnwindActionsUpTo:self. |
15688 | 1689 |
]. |
1690 |
||
1691 |
"oops, if nil, I am not on the calling chain; |
|
1692 |
(bad bad, unwind action have already been performed. |
|
1693 |
should we check for this situation first and NOT evaluate |
|
1694 |
the unwind actions in this case ?) |
|
1695 |
" |
|
1696 |
con isNil ifTrue:[ |
|
15933 | 1697 |
" |
1698 |
tried to return to a context which is already dead |
|
1699 |
(i.e. the method/block has already executed a return) |
|
1700 |
" |
|
1701 |
^ self invalidReturnOrRestartError:#'unwindThenResend' with:nil |
|
15688 | 1702 |
]. |
1703 |
||
1704 |
"/ now, that all unwind-actions are done, I can use the low-level resend... |
|
1705 |
^ self resend |
|
1 | 1706 |
! ! |
623 | 1707 |
|
1708 |
!Context methodsFor:'printing & storing'! |
|
1709 |
||
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1710 |
argStringFor:someObject |
15644 | 1711 |
|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
|
1712 |
%{ |
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
1713 |
#ifndef __SCHTEAM__ |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1714 |
/* |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1715 |
* 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
|
1716 |
* 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
|
1717 |
* which may lead to sends to free objects. In normal operation, this 'cannot' happen. |
14051 | 1718 |
* However, these print methods are also invoked for low-level pointer errors, so better be prepared... |
12841 | 1719 |
*/ |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1720 |
if (__isNonNilObject(someObject) && (__qClass(someObject)==nil)) { |
15933 | 1721 |
s = __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
|
1722 |
} |
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
1723 |
#endif /* not SCHTEAM */ |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1724 |
%}. |
11539 | 1725 |
s isNil ifTrue:[ |
15933 | 1726 |
s := someObject displayString. |
1727 |
s isNil ifTrue:[ |
|
1728 |
^ '**************** nil displayString of ',(someObject class name ? '??') |
|
1729 |
]. |
|
11539 | 1730 |
]. |
15933 | 1731 |
"/ JV@2013-04-26: Following is rubbish, the callers must handle string output correctly. |
15644 | 1732 |
"/ moreover storeString does not work on self-referencing structures, but that doesn't matter |
1733 |
"/ for wide strings. |
|
1734 |
"/ SV@2013-08-19: I checked/fixed the callers to use CharacterWriteStreams. |
|
1735 |
"/ s isWideString ifTrue:[ |
|
1736 |
"/ "make sure that the object really returns something we can stream into a string" |
|
1737 |
"/ s := someObject storeString. |
|
1738 |
"/ ]. |
|
11539 | 1739 |
^ 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
|
1740 |
! |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1741 |
|
623 | 1742 |
argsDisplayString |
14051 | 1743 |
^ String streamContents:[:s | self displayArgsOn:s ]. |
1744 |
||
1745 |
"Modified (format): / 07-03-2012 / 13:11:17 / cg" |
|
623 | 1746 |
! |
1747 |
||
6648 | 1748 |
displayArgsOn:aStream |
15933 | 1749 |
| n "{ Class: SmallInteger }" |
15388 | 1750 |
s | |
6648 | 1751 |
|
18437 | 1752 |
n := self argumentCount. |
6648 | 1753 |
1 to:n do:[:index | |
18437 | 1754 |
Error handle:[:ex | |
1755 |
s := '*Error in argString*'. |
|
1756 |
] do:[ |
|
1757 |
s := self argStringFor:(self at:index). |
|
1758 |
s := s contractTo:100. |
|
1759 |
]. |
|
1760 |
||
1761 |
aStream nextPutAll:s asString string. |
|
1762 |
index ~~ n ifTrue:[ aStream space ]. |
|
6648 | 1763 |
]. |
14051 | 1764 |
|
1765 |
"Modified: / 07-03-2012 / 13:09:17 / cg" |
|
6648 | 1766 |
! |
1767 |
||
14293
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1768 |
displayOn:aGCOrStream |
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1769 |
"return a string to display the receiver - for display in Inspector" |
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1770 |
|
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1771 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1772 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1773 |
(aGCOrStream isStream) ifFalse:[ |
15933 | 1774 |
^ super displayOn:aGCOrStream |
14293
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1775 |
]. |
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1776 |
|
15933 | 1777 |
aGCOrStream |
1778 |
nextPutAll:self class name; |
|
1779 |
nextPut:$(. |
|
14293
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1780 |
self printOn:aGCOrStream. |
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1781 |
aGCOrStream nextPut:$). |
623 | 1782 |
! |
1783 |
||
6648 | 1784 |
fullPrintAllOn:aStream |
12789 | 1785 |
"print a full walkback (incl arguments) starting at the receiver" |
6648 | 1786 |
|
15010 | 1787 |
self withAllSendersDo:[:con | con fullPrintOn:aStream. aStream cr]. |
6648 | 1788 |
|
1789 |
" |
|
1790 |
thisContext fullPrintAllOn:Transcript |
|
1791 |
" |
|
1792 |
||
1793 |
"Created: 15.1.1997 / 18:09:05 / cg" |
|
1794 |
! |
|
1795 |
||
18977 | 1796 |
fullPrintAllOn:aStream throughContextForWhich:aBlock |
1797 |
"print a full walkback (incl arguments) starting at the receiver" |
|
1798 |
||
21146 | 1799 |
self withSendersThroughContextForWhich:aBlock do:[:con | |
18977 | 1800 |
con fullPrintOn:aStream. aStream cr. |
1801 |
]. |
|
1802 |
||
1803 |
" |
|
1804 |
thisContext fullPrintAllOn:Transcript throughContextForWhich:[:con | con selector == #doIt]. |
|
1805 |
" |
|
1806 |
! |
|
1807 |
||
1808 |
fullPrintAllOn:aStream upToContextForWhich:aBlock |
|
1809 |
"print a full walkback (incl arguments) starting at the receiver" |
|
1810 |
||
21146 | 1811 |
self withSendersUpToContextForWhich:aBlock do:[:con | |
18977 | 1812 |
con fullPrintOn:aStream. aStream cr. |
1813 |
]. |
|
1814 |
||
1815 |
" |
|
1816 |
thisContext fullPrintAllOn:Transcript upToContextForWhich:[:con | con selector == #doIt]. |
|
1817 |
" |
|
1818 |
! |
|
1819 |
||
13612 | 1820 |
fullPrintAllString |
1821 |
"return a string containing the full walkback (incl. arguments)" |
|
1822 |
||
21146 | 1823 |
|s| |
1824 |
||
1825 |
s := WriteStream on:''. |
|
1826 |
self fullPrintAllOn:s. |
|
1827 |
^ s contents |
|
13612 | 1828 |
|
1829 |
" |
|
1830 |
thisContext fullPrintAllString |
|
1831 |
" |
|
1832 |
||
1833 |
"Created: / 21-08-2011 / 07:37:36 / cg" |
|
1834 |
! |
|
1835 |
||
6648 | 1836 |
fullPrintOn:aStream |
12789 | 1837 |
"append a verbose description (incl. arguments) of the receiver onto aStream" |
6648 | 1838 |
|
15383 | 1839 |
self printReceiverOn:aStream. |
12841 | 1840 |
aStream nextPutAll:' >> '. |
11311 | 1841 |
self selector printOn:aStream. "show as string (as symbol looks too ugly in browser ...)" |
1842 |
"/ self selector storeOn:aStream. "show as symbol" |
|
8578 | 1843 |
|
6648 | 1844 |
self size ~~ 0 ifTrue: [ |
15933 | 1845 |
aStream space. |
1846 |
self displayArgsOn:aStream |
|
6648 | 1847 |
]. |
12841 | 1848 |
aStream nextPutAll:' {'. |
1849 |
self identityHash printOn:aStream. |
|
15383 | 1850 |
aStream nextPut:$}. |
12841 | 1851 |
|
1852 |
aStream nextPutAll:' ['. |
|
6648 | 1853 |
self lineNumber printOn:aStream. |
15383 | 1854 |
aStream nextPut:$]. |
6648 | 1855 |
|
1856 |
" |
|
1857 |
thisContext fullPrintOn:Transcript |
|
1858 |
" |
|
1859 |
||
1860 |
"Modified: 20.5.1996 / 10:27:14 / cg" |
|
1861 |
"Created: 15.1.1997 / 18:09:06 / cg" |
|
1862 |
! |
|
1863 |
||
623 | 1864 |
fullPrintString |
1865 |
"return a string describing the context - this includes the linenumber, |
|
1866 |
receiver printString and argument printString" |
|
1867 |
||
15644 | 1868 |
^ String streamContents:[:s | self fullPrintOn:s] |
623 | 1869 |
|
1870 |
" |
|
1871 |
thisContext fullPrintString |
|
1872 |
" |
|
1873 |
! |
|
1874 |
||
1875 |
methodPrintString |
|
12841 | 1876 |
"return a string describing the contexts method as 'implementorClass>>selector'" |
623 | 1877 |
|
1853
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1878 |
|mthd who| |
623 | 1879 |
|
1880 |
mthd := self method. |
|
1881 |
mthd notNil ifTrue:[ |
|
15933 | 1882 |
who := mthd who. |
1883 |
who notNil ifTrue:[ |
|
1884 |
^ who methodClass name , ' >> #' , who methodSelector |
|
1885 |
] |
|
623 | 1886 |
]. |
1887 |
^ mthd displayString. |
|
1888 |
||
1889 |
" |
|
12841 | 1890 |
thisContext methodPrintString |
1891 |
thisContext sender methodPrintString |
|
623 | 1892 |
" |
1853
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1893 |
|
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1894 |
"Modified: 1.11.1996 / 16:21:49 / cg" |
623 | 1895 |
! |
1896 |
||
12789 | 1897 |
printAllOn:aStream |
1898 |
"print a brief walkback (excl. arguments) starting at the receiver" |
|
1899 |
||
15010 | 1900 |
self withAllSendersDo:[:con | con printOn:aStream. aStream cr]. |
12789 | 1901 |
|
1902 |
" |
|
1903 |
thisContext printAllOn:Transcript |
|
1904 |
" |
|
1905 |
||
1906 |
"Created: 15.1.1997 / 18:09:05 / cg" |
|
1907 |
! |
|
1908 |
||
21146 | 1909 |
printAllOn:aStream throughContextForWhich:aBlock |
1910 |
"print a short walkback (excl. arguments) starting at the receiver" |
|
1911 |
||
1912 |
self withSendersThroughContextForWhich:aBlock do:[:con | |
|
1913 |
con printOn:aStream. aStream cr. |
|
1914 |
]. |
|
1915 |
||
1916 |
" |
|
1917 |
thisContext printAllOn:Transcript throughContextForWhich:[:con | con selector == #doIt]. |
|
1918 |
" |
|
1919 |
! |
|
1920 |
||
1921 |
printAllOn:aStream upToContextForWhich:aBlock |
|
1922 |
"print a short walkback (excl. arguments) starting at the receiver" |
|
1923 |
||
1924 |
self withSendersUpToContextForWhich:aBlock do:[:con | |
|
1925 |
con printOn:aStream. aStream cr. |
|
1926 |
]. |
|
1927 |
||
1928 |
" |
|
1929 |
thisContext printAllOn:Transcript upToContextForWhich:[:con | con selector == #withCursor:do:]. |
|
1930 |
" |
|
1931 |
! |
|
1932 |
||
13612 | 1933 |
printAllString |
1934 |
"return a string containing the walkback (excl. arguments)" |
|
1935 |
||
1936 |
|s| |
|
1937 |
||
15383 | 1938 |
s := WriteStream on:''. |
13612 | 1939 |
self printAllOn:s. |
1940 |
^ s contents |
|
1941 |
||
1942 |
" |
|
1943 |
thisContext printAllString |
|
1944 |
" |
|
1945 |
||
1946 |
"Created: / 21-08-2011 / 07:38:05 / cg" |
|
1947 |
! |
|
1948 |
||
16223 | 1949 |
printClassNameOf:aClass on:aStream |
1950 |
"helper for printing" |
|
1951 |
||
16819
c96b396b7307
Oops, fix in Context >> printClassNameOf:on: for Java static methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16818
diff
changeset
|
1952 |
| nonMeta | |
c96b396b7307
Oops, fix in Context >> printClassNameOf:on: for Java static methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16818
diff
changeset
|
1953 |
|
c96b396b7307
Oops, fix in Context >> printClassNameOf:on: for Java static methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16818
diff
changeset
|
1954 |
(nonMeta := aClass theNonMetaclass) isJavaClass ifTrue:[ |
c96b396b7307
Oops, fix in Context >> printClassNameOf:on: for Java static methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16818
diff
changeset
|
1955 |
nonMeta javaName printOn: aStream |
16223 | 1956 |
] ifFalse:[ |
18190 | 1957 |
(aClass name ? '????') printOn:aStream. |
16223 | 1958 |
]. |
16818
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
1959 |
|
16819
c96b396b7307
Oops, fix in Context >> printClassNameOf:on: for Java static methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16818
diff
changeset
|
1960 |
"Modified: / 08-08-2014 / 09:39:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
16223 | 1961 |
! |
1962 |
||
623 | 1963 |
printOn:aStream |
12789 | 1964 |
"append a brief description (excl. arguments) of the receiver onto aStream" |
623 | 1965 |
|
16818
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
1966 |
| m | |
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
1967 |
|
15383 | 1968 |
self printReceiverOn:aStream. |
10549 | 1969 |
"/ aStream nextPutAll:' '. |
1970 |
aStream nextPutAll:' >> '. |
|
1971 |
||
1972 |
aStream bold. |
|
16818
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
1973 |
m := self method. |
18190 | 1974 |
m isJavaMethod ifTrue:[ |
1975 |
aStream nextPutAll: (m printStringForBrowserWithSelector: self selector). |
|
16818
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
1976 |
] ifFalse:[ |
18190 | 1977 |
self selector printOn:aStream. "show as string (as symbol looks too ugly in browser ...)" |
1978 |
"/ self selector storeOn:aStream. "show as symbol" |
|
16818
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
1979 |
]. |
10549 | 1980 |
aStream normal. |
16569 | 1981 |
|
14225 | 1982 |
(method notNil and:[method isWrapped]) ifTrue:[ |
18190 | 1983 |
aStream nextPutAll:' (wrapped) ' |
14225 | 1984 |
]. |
16818
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
1985 |
aStream nextPutAll:' ['. |
18190 | 1986 |
m isJavaMethod ifTrue:[ |
1987 |
aStream nextPutAll: self method mclass sourceFile ? '???' . |
|
1988 |
m isNative ifTrue:[ |
|
1989 |
aStream nextPutAll: ':in native code' |
|
1990 |
] ifFalse:[ |
|
1991 |
aStream nextPut: $:. |
|
1992 |
(m lineNumberForPC0: lineNr) ? '???' printOn: aStream. |
|
1993 |
]. |
|
16818
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
1994 |
] ifFalse:[ |
18190 | 1995 |
self lineNumber printOn: aStream |
16818
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
1996 |
]. |
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
1997 |
aStream nextPut:$]. |
4393 | 1998 |
|
14302 | 1999 |
"Modified: / 05-08-2012 / 12:00:00 / cg" |
16818
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
2000 |
"Modified: / 08-08-2014 / 07:37:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
623 | 2001 |
! |
2002 |
||
15383 | 2003 |
printReceiverOn:aStream |
2004 |
"print description of the receiver of the context to aStream" |
|
2005 |
||
2006 |
|receiverClass receiverClassName implementorClass| |
|
2007 |
||
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2008 |
receiverClassName := self safeReceiverClassNameIfInvalid. |
15383 | 2009 |
receiverClassName notNil ifTrue:[ |
18190 | 2010 |
"if we come here, this is a context with an illegal class" |
2011 |
receiverClassName printOn:aStream. |
|
2012 |
^ self. |
|
15383 | 2013 |
]. |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
2014 |
|
623 | 2015 |
receiverClass := receiver class. |
15383 | 2016 |
|
2017 |
(receiverClass == SmallInteger or:[receiverClass == Float]) ifTrue:[ |
|
18190 | 2018 |
aStream nextPut:$(. receiver printOn:aStream. aStream nextPutAll:') '. |
15383 | 2019 |
]. |
16223 | 2020 |
self printClassNameOf:receiverClass on:aStream. |
15383 | 2021 |
|
2022 |
(selector notNil or:[method notNil]) ifTrue:[ |
|
18190 | 2023 |
"/ implementorClass := self searchClass whichClassIncludesSelector:selector. |
2024 |
||
2025 |
" |
|
2026 |
kludge to avoid slow search for containing class |
|
2027 |
" |
|
2028 |
(method notNil |
|
2029 |
or:[selector ~~ #doIt and:[selector ~~ #doIt:]]) ifTrue:[ |
|
2030 |
implementorClass := self methodClass. |
|
2031 |
implementorClass isNil ifTrue:[ |
|
2032 |
" |
|
2033 |
kludge for the frame called by a wrappedmethod; |
|
2034 |
the wrappedmethod is in the class, so its mclass is correct. |
|
2035 |
however, the originalmethod is invoked via performMethod, and its mclass |
|
2036 |
is nil. Care for this here. Think about keeping the mclass in the original method. |
|
2037 |
" |
|
2038 |
(method notNil and:[method isWrapped not]) ifTrue:[ |
|
2039 |
WrappedMethod notNil ifTrue:[ |
|
2040 |
WrappedMethod allWrappedMethodsDo:[:wrapped | |
|
2041 |
wrapped originalMethodIfWrapped == method ifTrue:[ |
|
2042 |
implementorClass := wrapped mclass. |
|
2043 |
]. |
|
2044 |
]. |
|
2045 |
]. |
|
2046 |
] |
|
2047 |
]. |
|
2048 |
]. |
|
2049 |
||
2050 |
implementorClass notNil ifTrue: [ |
|
2051 |
(implementorClass ~~ receiverClass) ifTrue: [ |
|
2052 |
aStream nextPut:$(. |
|
2053 |
self printClassNameOf:implementorClass on:aStream. |
|
2054 |
aStream nextPut:$). |
|
2055 |
] |
|
2056 |
] ifFalse:[ |
|
2057 |
| srchClass where | |
|
2058 |
||
2059 |
srchClass := self searchClass. |
|
2060 |
srchClass ~~ receiverClass ifTrue:[ |
|
2061 |
aStream nextPut:$(. |
|
2062 |
self printClassNameOf:srchClass on:aStream. |
|
2063 |
aStream nextPut:$). |
|
2064 |
]. |
|
2065 |
" |
|
2066 |
kludge for doIt - these unbound methods are not |
|
2067 |
found in the classes methodDictionary |
|
2068 |
" |
|
2069 |
true "(selector ~~ #doIt and:[selector ~~ #doIt:])" ifTrue:[ |
|
2070 |
" |
|
2071 |
kludge for methods invoked explicitly via valueWithReceiver... |
|
2072 |
" |
|
2073 |
(self sender notNil |
|
2074 |
and:[ self sender receiver isMethod |
|
2075 |
and:[ self sender selector startsWith:'valueWithReceiver:' ]]) ifTrue:[ |
|
2076 |
where := '(**DIRECTED**)'. |
|
2077 |
] ifFalse:[ |
|
2078 |
where := '(**NONE**)'. |
|
2079 |
]. |
|
2080 |
aStream nextPutAll:where |
|
2081 |
] |
|
2082 |
] |
|
623 | 2083 |
]. |
2084 |
||
15961 | 2085 |
"Created: / 23-10-2013 / 11:13:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2086 |
"Modified: / 05-02-2014 / 17:50:33 / cg" |
|
10549 | 2087 |
! |
2088 |
||
15383 | 2089 |
receiverPrintString |
2090 |
"return a string describing the receiver of the context" |
|
2091 |
||
2092 |
|s| |
|
2093 |
||
2094 |
s := WriteStream on:''. |
|
2095 |
self printReceiverOn:s. |
|
2096 |
^ s contents |
|
2097 |
||
2098 |
" |
|
15933 | 2099 |
thisContext receiverPrintString |
15383 | 2100 |
" |
2101 |
! |
|
2102 |
||
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2103 |
safeReceiverClassNameIfInvalid |
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2104 |
"if the receiver refers to an invalid object, |
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2105 |
return a replacement string. otherwise nil. |
10549 | 2106 |
This cares for invalid (free) objects which may appear with bad primitive code, |
2107 |
and prevents a crash in such a case." |
|
2108 |
||
2109 |
%{ |
|
18412 | 2110 |
#ifdef __SCHTEAM__ |
2111 |
return __c__._RETURN( ((STContinuation)self).stSelf(__c__) ); |
|
2112 |
#else |
|
10549 | 2113 |
/* |
2114 |
* special handling for (invalid) free objects. |
|
2115 |
* these only appear if some primitiveCode does not correctly use SEND macros, |
|
2116 |
* which may lead to sends to free objects. In normal operation, this 'cannot' happen. |
|
12841 | 2117 |
*/ |
10549 | 2118 |
if (__isNonNilObject(__INST(receiver)) && (__qClass(__INST(receiver))==nil)) { |
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2119 |
RETURN( __MKSTRING("FreeObject") ); |
10549 | 2120 |
} |
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2121 |
#endif /* not SCHTEAM */ |
10549 | 2122 |
%}. |
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2123 |
^ nil |
10549 | 2124 |
|
2125 |
"Created: / 21-05-2007 / 13:19:37 / cg" |
|
623 | 2126 |
! ! |
2127 |
||
7257 | 2128 |
!Context methodsFor:'private-accessing'! |
623 | 2129 |
|
11340
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2130 |
isMarkedForUnwind |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2131 |
"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
|
2132 |
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
|
2133 |
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
|
2134 |
|
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2135 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2136 |
#ifdef __SCHTEAM__ |
18412 | 2137 |
return context._RETURN ( ((STContinuation)self).isMarkedForUnwind() ); |
18190 | 2138 |
#else |
18253 | 2139 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__UNWIND_MARK)) ? true : false ); |
18190 | 2140 |
#endif |
11340
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2141 |
%} |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2142 |
" |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2143 |
thisContext isMarkedForUnwind |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2144 |
" |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2145 |
! |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2146 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2147 |
markForHandle |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2148 |
"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
|
2149 |
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
|
2150 |
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
|
2151 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2152 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2153 |
#ifdef __SCHTEAM__ |
18412 | 2154 |
((STContinuation)self).markForHandle(); |
18190 | 2155 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2156 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__HANDLE_MARK)); |
18190 | 2157 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2158 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2159 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2160 |
"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
|
2161 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2162 |
|
753
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2163 |
markForInterrupt |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2164 |
"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
|
2165 |
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
|
2166 |
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
|
2167 |
|
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2168 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2169 |
#ifdef __SCHTEAM__ |
18412 | 2170 |
((STContinuation)self).markForInterrupt(); |
18190 | 2171 |
#else |
753
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2172 |
__markInterrupted(__ContextInstPtr(self)); |
18190 | 2173 |
#endif |
753
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2174 |
%} |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2175 |
! |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2176 |
|
1727 | 2177 |
markForInterruptOnUnwind |
2178 |
"set the interrupt-on-unwind flag in the receiver. |
|
2179 |
The VM will generate a stepInterrupt, when this context returns or |
|
2180 |
is unwound. This is used by the debugger for faster single-stepping; |
|
2181 |
- a highly internal mechanism and not for public use." |
|
2182 |
||
2183 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2184 |
#ifdef __SCHTEAM__ |
18412 | 2185 |
((STContinuation)self).markForInterruptOnUnwind(); |
18190 | 2186 |
#else |
3508 | 2187 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__IRQ_ON_UNWIND)); |
18190 | 2188 |
#endif |
1727 | 2189 |
%} |
2190 |
! |
|
2191 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2192 |
markForRaise |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2193 |
"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
|
2194 |
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
|
2195 |
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
|
2196 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2197 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2198 |
#ifdef __SCHTEAM__ |
18412 | 2199 |
((STContinuation)self).markForRaise(); |
18190 | 2200 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2201 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__RAISE_MARK)); |
18190 | 2202 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2203 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2204 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2205 |
"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
|
2206 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2207 |
|
623 | 2208 |
markForUnwind |
749 | 2209 |
"set the mark for unwind flag in the receiver. |
2210 |
The VM needs this to know that some special action is to be performed with |
|
2211 |
this context - a highly internal mechanism and not for public use." |
|
2212 |
||
623 | 2213 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2214 |
#ifdef __SCHTEAM__ |
18412 | 2215 |
((STContinuation)self).markForUnwind(); |
18190 | 2216 |
#else |
1133 | 2217 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__UNWIND_MARK)); |
18190 | 2218 |
#endif |
623 | 2219 |
%} |
749 | 2220 |
|
2221 |
"Modified: 13.12.1995 / 19:05:22 / cg" |
|
623 | 2222 |
! |
2223 |
||
5780 | 2224 |
setHome:aContext |
2225 |
"set the homeContext. |
|
2226 |
DANGER: this is for experimental, internal use only (byteCode interpreters)" |
|
2227 |
||
2228 |
home := aContext. |
|
2229 |
! |
|
2230 |
||
2231 |
setSender:aContext |
|
2232 |
"set the sender of the context. |
|
2233 |
DANGER: this is for experimental, internal use only (byteCode interpreters)" |
|
2234 |
||
2235 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2236 |
#ifdef __SCHTEAM__ |
18412 | 2237 |
((STContinuation)self).caller = aContext.asSTContinuation(); |
18190 | 2238 |
#else |
5780 | 2239 |
__INST(sender_) = aContext; |
18190 | 2240 |
#endif |
5780 | 2241 |
%} |
2242 |
! |
|
2243 |
||
623 | 2244 |
unmarkForUnwind |
749 | 2245 |
"clear the mark for unwind flag in the receiver. |
2246 |
The VM needs this to know that some special action is to be performed with |
|
2247 |
this context - a highly internal mechanism and not for public use." |
|
2248 |
||
623 | 2249 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2250 |
#ifdef __SCHTEAM__ |
18412 | 2251 |
((STContinuation)self).unmarkForUnwind(); |
18190 | 2252 |
#else |
1133 | 2253 |
__INST(flags) = (OBJ)((INT)__INST(flags) & ~__MASKSMALLINT(__UNWIND_MARK)); |
18190 | 2254 |
#endif |
623 | 2255 |
%} |
2256 |
! ! |
|
2257 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2258 |
!Context methodsFor:'searching'! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2259 |
|
8284 | 2260 |
findExceptional |
12841 | 2261 |
"walk along the sender chain (starting with the sender), |
8284 | 2262 |
for a context which is marked as handle or raise context. |
2263 |
This non-standard interface is only to be used by exception" |
|
2264 |
||
2265 |
"/ this could have been (actually: was) implemented as: |
|
2266 |
"/ |
|
2267 |
"/ |con| |
|
2268 |
"/ |
|
2269 |
"/ con := self. |
|
2270 |
"/ [con notNil] whileTrue:[ |
|
2271 |
"/ [con isHandleContext] ifTrue:[^con]. |
|
2272 |
"/ [con isRaiseContext] ifTrue:[^con]. |
|
2273 |
"/ con := con sender. |
|
2274 |
"/ ]. |
|
2275 |
"/ ^ nil |
|
2276 |
"/ |
|
2277 |
"/ and the code below does exactly this (somewhat faster, though). |
|
2278 |
"/ |
|
2279 |
"/ (it avoids referencing all intermediate contexts, which would mark them special, |
|
2280 |
"/ although they aren't really - this is expert knowledge, no need to understand that ...) |
|
2281 |
||
2282 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2283 |
#ifdef __SCHTEAM__ |
18253 | 2284 |
{ |
18412 | 2285 |
STContinuation lastCallee = (STContinuation)self; |
2286 |
STContinuation caller = lastCallee.caller; |
|
18406 | 2287 |
|
2288 |
while (caller != null) { |
|
18253 | 2289 |
if (caller.isExceptionalSmalltalkContext()) { |
18412 | 2290 |
caller = lastCallee.sender(); // exposed |
18253 | 2291 |
return context._RETURN(caller); |
2292 |
} |
|
18412 | 2293 |
lastCallee = caller; |
2294 |
caller = lastCallee.caller; |
|
18253 | 2295 |
} |
2296 |
return context._RETURN( STObject.Nil ); |
|
2297 |
} |
|
2298 |
/* NOTREACHED */ |
|
18190 | 2299 |
#else |
8284 | 2300 |
OBJ theContext; |
2301 |
||
2302 |
theContext = self; |
|
2303 |
while (__isNonNilObject(theContext)) { |
|
15933 | 2304 |
if ((INT)(__ContextInstPtr(theContext)->c_flags) & __MASKSMALLINT(__HANDLE_MARK|__RAISE_MARK)) { |
2305 |
if (__isLazy(theContext)) { |
|
2306 |
__PATCHUPCONTEXT(theContext); |
|
2307 |
} |
|
2308 |
RETURN (theContext); |
|
2309 |
} |
|
2310 |
theContext = __ContextInstPtr(theContext)->c_sender; |
|
8284 | 2311 |
} |
18253 | 2312 |
#endif /* not SCHTEAM */ |
8284 | 2313 |
%}. |
2314 |
^ nil |
|
2315 |
! |
|
2316 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2317 |
findNextContextWithSelector:selector1 or:selector2 or:selector3 |
12841 | 2318 |
"walk along the sender chain (starting with the sender), |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2319 |
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
|
2320 |
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
|
2321 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2322 |
"/ 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
|
2323 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2324 |
"/ |con| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2325 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2326 |
"/ con := self sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2327 |
"/ [con notNil] whileTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2328 |
"/ 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
|
2329 |
"/ con := con sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2330 |
"/ ]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2331 |
"/ ^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2332 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2333 |
"/ 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
|
2334 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2335 |
"/ (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
|
2336 |
"/ 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
|
2337 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2338 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2339 |
#ifdef __SCHTEAM__ |
18216 | 2340 |
{ |
18412 | 2341 |
STContinuation lastCallee = (STContinuation)self; |
2342 |
STContinuation cont = lastCallee.caller; |
|
2343 |
||
18216 | 2344 |
STObject sel1 = context.stArg(0); |
2345 |
STObject sel2 = context.stArg(1); |
|
2346 |
STObject sel3 = context.stArg(2); |
|
2347 |
||
18406 | 2348 |
while (cont != null) { |
2349 |
if (cont.isSmalltalkContext()) { |
|
2350 |
STObject thisSelector = cont.contextSelector(); |
|
18216 | 2351 |
|
2352 |
if ((thisSelector == sel1) |
|
2353 |
|| (thisSelector == sel2) |
|
2354 |
|| (thisSelector == sel3)) { |
|
2355 |
break; |
|
2356 |
} |
|
2357 |
} |
|
18412 | 2358 |
lastCallee = cont; |
2359 |
cont = lastCallee.caller; |
|
18216 | 2360 |
} |
18406 | 2361 |
if (cont == null) { |
2362 |
return __c__._RETURN_nil(); |
|
2363 |
} |
|
18412 | 2364 |
cont = lastCallee.sender(); // exposed |
18406 | 2365 |
return __c__._RETURN(cont); |
18216 | 2366 |
} |
2367 |
/* NOTREACHED */ |
|
18190 | 2368 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2369 |
OBJ theContext; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2370 |
OBJ sel; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2371 |
OBJ __FETCHSELECTOR(); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2372 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2373 |
theContext = __INST(sender_); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2374 |
while (__isNonNilObject(theContext)) { |
15933 | 2375 |
if (__isLazy(theContext)) { |
18190 | 2376 |
# ifdef TRADITIONAL_STACK_FRAME |
15933 | 2377 |
sel = __FETCHSELECTOR(theContext); |
18190 | 2378 |
# else |
15933 | 2379 |
/* mhmh - not really needed */ |
2380 |
__PATCHUPCONTEXT(theContext); |
|
2381 |
sel = __ContextInstPtr(theContext)->c_selector; |
|
18190 | 2382 |
# endif |
15933 | 2383 |
} else { |
2384 |
sel = __ContextInstPtr(theContext)->c_selector; |
|
2385 |
} |
|
2386 |
||
2387 |
if ((sel == selector1) |
|
2388 |
|| ((selector2 != nil) && (sel == selector2)) |
|
2389 |
|| ((selector3 != nil) && (sel == selector3))) { |
|
2390 |
if (__isLazy(theContext)) { |
|
2391 |
__PATCHUPCONTEXT(theContext); |
|
2392 |
} |
|
2393 |
RETURN (theContext); |
|
2394 |
} |
|
2395 |
theContext = __ContextInstPtr(theContext)->c_sender; |
|
5422 | 2396 |
} |
2397 |
RETURN (nil); |
|
18190 | 2398 |
#endif |
5422 | 2399 |
%}. |
2400 |
" |
|
2401 |
|con sel| |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2402 |
|
5422 | 2403 |
con := self sender. |
2404 |
[con notNil] whileTrue:[ |
|
15933 | 2405 |
sel := con selector. |
2406 |
sel == selector1 ifTrue:[^ con]. |
|
2407 |
(selector2 notNil and:[sel == selector2]) ifTrue:[^ con]. |
|
2408 |
(selector3 notNil and:[sel == selector3]) ifTrue:[^ con]. |
|
2409 |
con := con sender. |
|
5422 | 2410 |
]. |
2411 |
^ nil |
|
2412 |
" |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2413 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2414 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2415 |
findNextUnwindContextOr:aContext |
12841 | 2416 |
"walk along the sender chain (starting at the sender), |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2417 |
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
|
2418 |
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
|
2419 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2420 |
"/ 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
|
2421 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2422 |
"/ |con| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2423 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2424 |
"/ con := self sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2425 |
"/ [con notNil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2426 |
"/ and:[con ~~ aContext |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2427 |
"/ 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
|
2428 |
"/ ^ con |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2429 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2430 |
"/ 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
|
2431 |
"/ (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
|
2432 |
"/ 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
|
2433 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2434 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2435 |
#ifdef __SCHTEAM__ |
18408 | 2436 |
{ |
2437 |
if (self == aContext) { |
|
2438 |
return __c__._RETURN(self); |
|
2439 |
} |
|
2440 |
||
18412 | 2441 |
STContinuation lastCallee = (STContinuation)self; |
2442 |
STContinuation theContext = lastCallee.caller; |
|
18408 | 2443 |
|
2444 |
while (theContext != null) { |
|
2445 |
if ((theContext == aContext) |
|
2446 |
|| theContext.isMarkedForUnwind()) { |
|
18412 | 2447 |
theContext = lastCallee.sender(); // exposed |
18408 | 2448 |
return __c__._RETURN(theContext); |
2449 |
} |
|
18412 | 2450 |
lastCallee = theContext; |
2451 |
theContext = lastCallee.caller; |
|
18408 | 2452 |
} |
2453 |
} |
|
18190 | 2454 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2455 |
OBJ theContext; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2456 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2457 |
if (self == aContext) { |
15933 | 2458 |
RETURN (self); |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2459 |
} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2460 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2461 |
theContext = __INST(sender_); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2462 |
while (__isNonNilObject(theContext)) { |
15933 | 2463 |
if ((theContext == aContext) |
2464 |
|| ((INT)(__ContextInstPtr(theContext)->c_flags) & __MASKSMALLINT(__UNWIND_MARK))) { |
|
2465 |
if (__isLazy(theContext)) { |
|
2466 |
__PATCHUPCONTEXT(theContext); |
|
2467 |
} |
|
2468 |
RETURN (theContext); |
|
2469 |
} |
|
2470 |
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
|
2471 |
} |
18190 | 2472 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2473 |
%}. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2474 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2475 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2476 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2477 |
findSpecialHandle:findHandleContext raise:findRaiseContext |
12841 | 2478 |
"walk along the sender chain (starting with the sender), |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2479 |
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
|
2480 |
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
|
2481 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2482 |
"/ 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
|
2483 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2484 |
"/ |con| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2485 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2486 |
"/ con := self sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2487 |
"/ [con notNil] whileTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2488 |
"/ (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
|
2489 |
"/ (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
|
2490 |
"/ con := con sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2491 |
"/ ]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2492 |
"/ ^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2493 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2494 |
"/ 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
|
2495 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2496 |
"/ (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
|
2497 |
"/ 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
|
2498 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2499 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2500 |
#ifdef __SCHTEAM__ |
18406 | 2501 |
{ |
18412 | 2502 |
STContinuation lastCallee = (STContinuation)self; |
2503 |
STContinuation theContext = lastCallee.caller; |
|
2504 |
||
18406 | 2505 |
while (theContext != null) { |
2506 |
if (theContext.isMarkedSpecial()) { |
|
2507 |
if ((findHandleContext == STObject.True) |
|
2508 |
&& theContext.isMarkedForHandle()) { |
|
18412 | 2509 |
theContext = lastCallee.sender(); // exposed |
18406 | 2510 |
return __c__._RETURN(theContext); |
2511 |
} |
|
2512 |
if ((findRaiseContext == STObject.True) |
|
2513 |
&& theContext.isMarkedForRaise()) { |
|
18412 | 2514 |
theContext = lastCallee.sender(); // exposed |
18406 | 2515 |
return __c__._RETURN(theContext); |
2516 |
} |
|
2517 |
} |
|
18412 | 2518 |
lastCallee = theContext; |
2519 |
theContext = lastCallee.caller; |
|
18406 | 2520 |
} |
2521 |
} |
|
18190 | 2522 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2523 |
OBJ theContext; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2524 |
int flagMask = 0; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2525 |
INT mask; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2526 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2527 |
if (findHandleContext == true) |
15933 | 2528 |
flagMask = __HANDLE_MARK; |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2529 |
if (findRaiseContext == true) |
15933 | 2530 |
flagMask |= __RAISE_MARK; |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2531 |
|
12841 | 2532 |
mask = __MASKSMALLINT(flagMask); |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2533 |
theContext = __INST(sender_); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2534 |
while (__isNonNilObject(theContext)) { |
15933 | 2535 |
if ((INT)(__ContextInstPtr(theContext)->c_flags) & mask) { |
2536 |
if (__isLazy(theContext)) { |
|
2537 |
__PATCHUPCONTEXT(theContext); |
|
2538 |
} |
|
2539 |
RETURN (theContext); |
|
2540 |
} |
|
2541 |
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
|
2542 |
} |
18190 | 2543 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2544 |
%}. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2545 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2546 |
! ! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2547 |
|
1051 | 2548 |
!Context methodsFor:'special accessing'! |
2549 |
||
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2550 |
argAndVarNames |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2551 |
"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
|
2552 |
|
15644 | 2553 |
|homeContext homeMethod block numArgs numVars m src |
8217 | 2554 |
sel isDoIt blocksLineNr extractFromBlock sender| |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2555 |
|
18437 | 2556 |
numArgs := self argumentCount. |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2557 |
numVars := self numVars. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2558 |
(numArgs == 0 and:[numVars == 0]) ifTrue:[^ #()]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2559 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2560 |
homeContext := self methodHome. |
7652 | 2561 |
homeContext notNil ifTrue:[ |
18437 | 2562 |
sel := homeContext selector. |
2563 |
homeMethod := homeContext method. |
|
7652 | 2564 |
]. |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2565 |
|
12841 | 2566 |
extractFromBlock := |
18437 | 2567 |
[ |
2568 |
|blockNode argNames varNames vars args blocksHome| |
|
2569 |
||
2570 |
blockNode := Compiler |
|
2571 |
blockAtLine:blocksLineNr |
|
2572 |
in:m |
|
2573 |
orSource:src |
|
2574 |
numArgs:numArgs |
|
2575 |
numVars:numVars. |
|
2576 |
||
2577 |
blockNode notNil ifTrue:[ |
|
2578 |
"/ a kludge |
|
2579 |
blockNode lineNumber == blocksLineNr ifTrue:[ |
|
2580 |
blocksHome := blockNode home. |
|
2581 |
(blocksHome notNil and:[blocksHome isBlock]) ifTrue:[ |
|
2582 |
(blocksHome numArgs == numArgs |
|
2583 |
and:[ blocksHome numVars == numVars ]) ifTrue:[ |
|
2584 |
blockNode := blocksHome |
|
2585 |
]. |
|
2586 |
]. |
|
2587 |
]. |
|
2588 |
||
2589 |
argNames := #(). |
|
2590 |
varNames := #(). |
|
2591 |
||
2592 |
numArgs > 0 ifTrue:[ |
|
2593 |
vars := blockNode arguments. |
|
2594 |
vars notEmptyOrNil ifTrue:[ |
|
2595 |
argNames := vars collect:[:var | var name] |
|
2596 |
] |
|
2597 |
]. |
|
2598 |
numVars > 0 ifTrue:[ |
|
19001
b798921e18e4
Improved Contextr>argAndVarNames to better deal with inlined blocks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18978
diff
changeset
|
2599 |
vars := blockNode variablesIncludingInlined: (homeMethod hasCode and:[homeMethod isDynamic not]). |
18437 | 2600 |
vars notEmptyOrNil ifTrue:[ |
2601 |
varNames := vars collect:[:var | var name]. |
|
2602 |
] |
|
2603 |
]. |
|
2604 |
^ argNames , varNames |
|
2605 |
]. |
|
2606 |
]. |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2607 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2608 |
"/ #doIt needs special handling below |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2609 |
isDoIt := (sel == #'doIt') or:[sel == #'doIt:']. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2610 |
self isBlockContext ifFalse:[ |
18437 | 2611 |
isDoIt ifTrue:[ |
2612 |
homeMethod notNil ifTrue:[ |
|
2613 |
"/ special for #doIt |
|
2614 |
m := nil. |
|
2615 |
src := ('[' , homeMethod source , '\]') withCRs. |
|
2616 |
"/ blocksLineNr := self lineNumber. |
|
2617 |
blocksLineNr := (self home ? self) lineNumber. |
|
2618 |
extractFromBlock value. |
|
2619 |
] |
|
2620 |
]. |
|
2621 |
||
2622 |
homeMethod notNil ifTrue:[ |
|
2623 |
^ homeMethod methodArgAndVarNamesInContext: self. |
|
2624 |
]. |
|
2625 |
^ #() |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2626 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2627 |
|
15644 | 2628 |
homeMethod notNil ifTrue:[ |
18437 | 2629 |
isDoIt ifTrue:[ |
2630 |
"/ special for #doIt |
|
2631 |
"/ my source is found in the method. |
|
2632 |
m := nil. |
|
2633 |
src := ('[' , homeMethod source , '\]') withCRs. |
|
2634 |
] ifFalse:[ |
|
2635 |
m := homeMethod. |
|
2636 |
src := nil. |
|
2637 |
]. |
|
2638 |
blocksLineNr := self lineNumber. |
|
2639 |
extractFromBlock value. |
|
2640 |
blocksLineNr := self home lineNumber. |
|
2641 |
extractFromBlock value. |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2642 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2643 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2644 |
blocksLineNr isNil ifTrue:[ |
18437 | 2645 |
self isBlockContext ifTrue:[ |
2646 |
sender := self sender. |
|
2647 |
(sender notNil |
|
2648 |
and:[sender receiver isBlock |
|
2649 |
and:[sender selector startsWith:'value']]) |
|
2650 |
ifTrue:[ |
|
2651 |
block := sender receiver. |
|
2652 |
src := block source. |
|
2653 |
src isNil ifTrue:[ |
|
2654 |
self error:'no source'. |
|
2655 |
]. |
|
2656 |
blocksLineNr := 1. |
|
2657 |
extractFromBlock value. |
|
2658 |
]. |
|
2659 |
sender := nil. |
|
2660 |
]. |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2661 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2662 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2663 |
^ #() |
15644 | 2664 |
|
19001
b798921e18e4
Improved Contextr>argAndVarNames to better deal with inlined blocks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18978
diff
changeset
|
2665 |
"Modified: / 26-12-2015 / 08:20:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2666 |
! |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2667 |
|
4557 | 2668 |
canResume |
2669 |
"return true, if the receiver allows to be resumed. |
|
18412 | 2670 |
In ST/X, due to the implementation, this requires that the context which |
2671 |
is right below the receiver is returnable and still active." |
|
4557 | 2672 |
|
2673 |
|theContext| |
|
2674 |
||
2675 |
" |
|
2676 |
starting with this context, find the one below |
|
2677 |
(i.e. the one that I have called) and return from it. |
|
2678 |
" |
|
2679 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2680 |
#ifdef __SCHTEAM__ |
18412 | 2681 |
// in the SCHTEAM-engine, all contexts are resumable |
18289 | 2682 |
return context._RETURN_true(); |
18190 | 2683 |
#else |
4557 | 2684 |
OBJ sndr; |
2685 |
||
2686 |
theContext = __thisContext; |
|
2687 |
while (theContext != nil) { |
|
15933 | 2688 |
sndr = __ContextInstPtr(theContext)->c_sender; |
2689 |
if (sndr == self) break; |
|
2690 |
theContext = sndr; |
|
4557 | 2691 |
} |
2692 |
if (theContext != nil) { |
|
15933 | 2693 |
if (__isLazy(theContext)) { |
2694 |
__PATCHUPCONTEXT(theContext); |
|
2695 |
} |
|
4557 | 2696 |
} |
18190 | 2697 |
#endif |
4557 | 2698 |
%}. |
2699 |
theContext isNil ifTrue:[ |
|
15933 | 2700 |
^ false |
4557 | 2701 |
]. |
2702 |
^ theContext canReturn |
|
2703 |
! |
|
2704 |
||
1051 | 2705 |
canReturn |
2706 |
"return true, if the receiver allows returning through it. |
|
4557 | 2707 |
Blocks, (currently) always return false. |
2646 | 2708 |
Methods which contain a (non-inlined) block are always |
2709 |
returnable - for other methods, it depends on how the system |
|
2710 |
was compiled (stc flag +/-optContext). |
|
2711 |
If it was compiled with +optContext, methods are compiled |
|
4557 | 2712 |
non returnable, unless a return-pragma was present in the method. |
2646 | 2713 |
Since this saves some administrative work in every method |
2714 |
invocation and makes overall execution faster, the system classes |
|
18412 | 2715 |
are all compiled with this flag turned on. |
2716 |
This means, that by default, it is not possible to walk up the |
|
2717 |
calling chain and return to an arbitrary context. |
|
2718 |
For contexts which are known to require this (i.e. handlers as found |
|
2719 |
by the exception walkers, these are marked specially (markForReturn), |
|
2720 |
so compilers know that they should create full featured contexts." |
|
1051 | 2721 |
|
2722 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2723 |
#ifdef __SCHTEAM__ |
18412 | 2724 |
// in the SCHTEAM-engine, all contexts can be returned from |
18289 | 2725 |
return context._RETURN_true(); |
18190 | 2726 |
#else |
3508 | 2727 |
RETURN ( ((INT)(__INST(flags)) & __MASKSMALLINT(__CANNOT_RETURN)) ? false : true ); |
18190 | 2728 |
#endif |
5441 | 2729 |
%}. |
2730 |
^ true |
|
1051 | 2731 |
! |
2732 |
||
1492 | 2733 |
hasStackToShow |
2646 | 2734 |
"private interface to the debugger. |
2735 |
Smalltalk contexts return false here - other language frames |
|
2736 |
(i.e. Java frames) may want to show the evaluation stack" |
|
2737 |
||
1492 | 2738 |
^ false |
2739 |
||
2740 |
"Created: 28.6.1996 / 14:48:39 / cg" |
|
2646 | 2741 |
"Modified: 13.5.1997 / 16:31:12 / cg" |
1492 | 2742 |
! |
2743 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2744 |
isHandleContext |
4505 | 2745 |
"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
|
2746 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2747 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2748 |
#ifdef __SCHTEAM__ |
18412 | 2749 |
return __c__._RETURN ( ((STContinuation)self).isMarkedForHandle() ); |
18190 | 2750 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2751 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__HANDLE_MARK)) ? true : false ); |
18190 | 2752 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2753 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2754 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2755 |
|
1051 | 2756 |
isNonLifo |
2646 | 2757 |
"return true, if this is a nonLifo context. |
2758 |
A nonLifo context is one that is still on the machine stack, |
|
2759 |
but has a reference taken and needs to be converted to a real |
|
2760 |
object (in objectMemory) when the method/block returns. |
|
18412 | 2761 |
You don't have to understand this - this is a special ST/X |
2646 | 2762 |
debug query, which may be removed without notice." |
1051 | 2763 |
|
2764 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2765 |
#ifdef __SCHTEAM__ |
18412 | 2766 |
return __c__._RETURN ( ((STContinuation)self).isNonLifo() ); |
18190 | 2767 |
#else |
1133 | 2768 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__NONLIFO)) ? true : false ); |
18190 | 2769 |
#endif |
1051 | 2770 |
%} |
2771 |
! |
|
2772 |
||
2773 |
isOnMachineStack |
|
12841 | 2774 |
"return true, if this is a machine stack context as opposed to a |
18412 | 2775 |
real heap context (i.e. if it has not been captured and returned from). |
2776 |
You don't have to understand this - this is a special ST/X |
|
2646 | 2777 |
debug query, which may be removed without notice." |
1051 | 2778 |
|
2779 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2780 |
#ifdef __SCHTEAM__ |
18412 | 2781 |
return __c__._RETURN ( ! ((STContinuation)self).isCopiedToHeap() ); |
18190 | 2782 |
#else |
18412 | 2783 |
RETURN ( (__qSpace(self) >= STACKSPACE) ? true : false ); |
18190 | 2784 |
#endif |
1051 | 2785 |
%} |
2786 |
! |
|
2787 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2788 |
isRaiseContext |
4505 | 2789 |
"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
|
2790 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2791 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2792 |
#ifdef __SCHTEAM__ |
18412 | 2793 |
return __c__._RETURN ( ((STContinuation)self).isMarkedForRaise() ); |
18190 | 2794 |
#else |
18412 | 2795 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__RAISE_MARK)) ? true : false ); |
18190 | 2796 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2797 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2798 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2799 |
|
1051 | 2800 |
isSpecial |
2801 |
"return true, if this is either a nonLifo or interrupted context" |
|
2802 |
||
2803 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2804 |
#ifdef __SCHTEAM__ |
18412 | 2805 |
return __c__._RETURN ( ((STContinuation)self).isMarkedSpecial() ); |
18190 | 2806 |
#else |
18412 | 2807 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__SPECIAL)) ? true : false ); |
18190 | 2808 |
#endif |
1051 | 2809 |
%} |
2810 |
! |
|
2811 |
||
2812 |
isUnwindContext |
|
2813 |
"return true, if this is an unwindContext" |
|
2814 |
||
2815 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2816 |
#ifdef __SCHTEAM__ |
18412 | 2817 |
return __c__._RETURN ( ((STContinuation)self).isMarkedForUnwind() ); |
18190 | 2818 |
#else |
18412 | 2819 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__UNWIND_MARK)) ? true : false ); |
18190 | 2820 |
#endif |
1051 | 2821 |
%} |
8578 | 2822 |
! |
2823 |
||
2824 |
tempNames |
|
2825 |
"helper: given a context, return a collection of arg, var and temporary names" |
|
2826 |
||
2827 |
|names nTemps| |
|
2828 |
||
2829 |
names := self argAndVarNames. |
|
2830 |
(nTemps := self numTemps) > 0 ifTrue:[ |
|
15933 | 2831 |
^ names , ((1 to:nTemps) collect:[:idx | '_tmp' , idx printString]). |
8578 | 2832 |
]. |
2833 |
^ names. |
|
1051 | 2834 |
! ! |
2835 |
||
623 | 2836 |
!Context methodsFor:'testing'! |
2837 |
||
2838 |
isBlockContext |
|
2839 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
2840 |
||
2841 |
^ false |
|
2842 |
! |
|
2843 |
||
14214 | 2844 |
isCheapBlockContext |
2845 |
"return true, iff the receiver is a BlockContext, for a cheap block, false otherwise. |
|
2846 |
Cheap blocks do not refer to their home" |
|
2847 |
||
2848 |
^ false |
|
2849 |
||
2850 |
"Created: / 19-07-2012 / 11:22:38 / cg" |
|
2851 |
! |
|
2852 |
||
623 | 2853 |
isContext |
2854 |
"return true, iff the receiver is a Context, false otherwise" |
|
2855 |
||
2856 |
^ true |
|
2857 |
! |
|
2858 |
||
16078 | 2859 |
isReallyRecursive |
2860 |
"return true, if this context is one of a recursive send of the same |
|
2861 |
selector AND same argument(s) to the same receiver before. |
|
2862 |
Here, different arguments are NOT ignored" |
|
2863 |
||
2864 |
|c count "{Class: SmallInteger }" sameArgs| |
|
2865 |
||
2866 |
count := 0. |
|
2867 |
||
2868 |
c := self findNextContextWithSelector:selector or:nil or:nil. |
|
2869 |
[c notNil] whileTrue:[ |
|
18437 | 2870 |
(c receiver == receiver) ifTrue:[ |
2871 |
c method == self method ifTrue:[ |
|
2872 |
sameArgs := true. |
|
2873 |
1 to:self argumentCount do:[:i | |
|
2874 |
(c argAt:1) ~~ (self argAt:i)ifTrue:[ |
|
2875 |
sameArgs := false |
|
2876 |
] |
|
2877 |
]. |
|
2878 |
sameArgs ifTrue:[^ true]. |
|
2879 |
] |
|
2880 |
]. |
|
2881 |
c := c findNextContextWithSelector:selector or:nil or:nil. |
|
2882 |
||
2883 |
" |
|
2884 |
this special test was added to get out after a while |
|
2885 |
if the sender chain is corrupt - this gives us at least |
|
2886 |
a chance to find those errors. |
|
2887 |
" |
|
2888 |
count := count + 1. |
|
2889 |
count >= 100000 ifTrue:[ |
|
2890 |
'Context [warning]: bad context chain' errorPrintCR. |
|
2891 |
^ true |
|
2892 |
] |
|
16078 | 2893 |
]. |
2894 |
^ false |
|
2895 |
! |
|
2896 |
||
623 | 2897 |
isRecursive |
2898 |
"return true, if this context is one of a recursive send of the same |
|
1483 | 2899 |
selector to the same receiver before. |
2900 |
Here, different arguments are ignored - i.e. only the same method |
|
2901 |
counts for recursiveness. |
|
623 | 2902 |
Used to detect recursive errors or recursive printing - for example." |
2903 |
||
16078 | 2904 |
|c count "{Class: SmallInteger }"| |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
2905 |
|
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
2906 |
count := 0. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
2907 |
|
2893 | 2908 |
c := self findNextContextWithSelector:selector or:nil or:nil. |
623 | 2909 |
[c notNil] whileTrue:[ |
18190 | 2910 |
(c receiver == receiver) ifTrue:[ |
16077 | 2911 |
"/ " |
2912 |
"/ stupid: the current ST/X context does not include |
|
2913 |
"/ the method, but the class, in which the search started ... |
|
2914 |
"/ " |
|
2915 |
"/ myMethodsClass isNil ifTrue:[ |
|
2916 |
"/ myMethodsClass := self methodClass. |
|
2917 |
"/ ]. |
|
2918 |
"/ c methodClass == myMethodsClass ifTrue:[ |
|
2919 |
"/ ^ true |
|
2920 |
"/ ]. |
|
18190 | 2921 |
"/ now it does!! |
2922 |
c method == self method ifTrue:[^ true]. |
|
2923 |
]. |
|
2924 |
c := c findNextContextWithSelector:selector or:nil or:nil. |
|
2925 |
||
2926 |
" |
|
2927 |
this special test was added to get out after a while |
|
2928 |
if the sender chain is corrupt - this gives us at least |
|
2929 |
a chance to find those errors. |
|
2930 |
" |
|
2931 |
count := count + 1. |
|
2932 |
count >= 100000 ifTrue:[ |
|
2933 |
'Context [warning]: bad context chain' errorPrintCR. |
|
2934 |
^ true |
|
2935 |
] |
|
623 | 2936 |
]. |
2937 |
^ false |
|
1483 | 2938 |
|
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
2939 |
"Modified: 10.1.1997 / 17:34:26 / cg" |
623 | 2940 |
! ! |
2941 |
||
1810 | 2942 |
!Context class methodsFor:'documentation'! |
749 | 2943 |
|
14418
6558e5c3b32e
changed: #receiverPrintString
Claus Gittinger <cg@exept.de>
parents:
14413
diff
changeset
|
2944 |
version |
18977 | 2945 |
^ '$Header$' |
14418
6558e5c3b32e
changed: #receiverPrintString
Claus Gittinger <cg@exept.de>
parents:
14413
diff
changeset
|
2946 |
! |
6558e5c3b32e
changed: #receiverPrintString
Claus Gittinger <cg@exept.de>
parents:
14413
diff
changeset
|
2947 |
|
13426 | 2948 |
version_CVS |
18977 | 2949 |
^ '$Header$' |
15644 | 2950 |
! |
2951 |
||
2952 |
version_HG |
|
2953 |
||
2954 |
^ '$Changeset: <not expanded> $' |
|
12573 | 2955 |
! |
2956 |
||
13426 | 2957 |
version_SVN |
15232 | 2958 |
^ '$ Id: Context.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
749 | 2959 |
! ! |
7257 | 2960 |
|
14700 | 2961 |
|
623 | 2962 |
Context initialize! |