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