author | Claus Gittinger <cg@exept.de> |
Fri, 07 Sep 2001 13:14:21 +0200 | |
changeset 5982 | 2965b58b4258 |
parent 5951 | ef7dcd567b6f |
child 6142 | 702cc4a95a86 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
154 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5349 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
4299 | 15 |
CompiledCode variableSubclass:#Block |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
16 |
instanceVariableNames:'home nargs sourcePos initialPC' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
17 |
classVariableNames:'InvalidNewSignal' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
18 |
poolDictionaries:'' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
19 |
category:'Kernel-Methods' |
1 | 20 |
! |
21 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
22 |
!Block class methodsFor:'documentation'! |
1 | 23 |
|
92 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 27 |
All Rights Reserved |
92 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
1 | 38 |
documentation |
39 |
" |
|
67 | 40 |
Blocks are pieces of executable code which can be evaluated by sending |
41 |
them a value-message (''value'', ''value:'', ''value:value:'' etc). |
|
1 | 42 |
|
1265 | 43 |
In smalltalk, Blocks provide the basic (and heavily used) mechanism |
44 |
for looping, enumerating collection elements, visitors, exception |
|
45 |
handling, unwinding, delayed execution and processes. |
|
46 |
||
1254 | 47 |
Blocks are never created explicitely; the only creation |
48 |
is done by the compilers, when some sourceCode is compiled to either |
|
49 |
machine or byteCode. |
|
50 |
||
67 | 51 |
Blocks with arguments need a message of type ''value:arg1 ... value:argn'' |
52 |
for evaluation; the number of arguments passed when evaluating must match |
|
53 |
the number of arguments the block was declared with otherwise an error is |
|
54 |
raised. Blocks without args need a ''value'' message for evaluation. |
|
1 | 55 |
|
154 | 56 |
Blocks keep a reference to the context where the block was declared - |
67 | 57 |
this allows blocks to access the methods arguments and/or variables. |
154 | 58 |
This is still true after the method has returned - since the |
67 | 59 |
block keeps this reference, the methods context will NOT die in this case. |
222 | 60 |
(i.e. Blocks are closures in Smalltalk/X) |
1 | 61 |
|
67 | 62 |
A return (via ^-statement) out of a block will force a return from the |
63 |
blocks method context (if it is still living) - this make the implementation |
|
64 |
of long-jumps and control structures possible. |
|
154 | 65 |
(If the method is not alive (i.e. has already returned), a return out of the |
66 |
block will trigger an error) |
|
1 | 67 |
|
67 | 68 |
Long-jump is done by defining a catchBlock as ''[^ self]'' |
69 |
somewhere up in the calling-tree. Then, to do the long-jump from out of some |
|
70 |
deeply nested method, simply do: ''catchBlock value''. |
|
1 | 71 |
|
1293 | 72 |
[Instance variables:] |
1 | 73 |
|
222 | 74 |
home <Context> the context where this block was created (i.e. defined) |
2238 | 75 |
this may be a blockContext or a methodContext |
222 | 76 |
nargs <SmallInteger> the number of arguments the block expects |
77 |
sourcePos <SmallInteger> the character position of its source, in chars |
|
2238 | 78 |
relative to methods source beginning |
222 | 79 |
initialPC <SmallInteger> the start position within the byteCode |
2238 | 80 |
for compiled blocks, this is nil. |
222 | 81 |
|
82 |
||
1293 | 83 |
[Class variables:] |
222 | 84 |
|
85 |
InvalidNewSignal raised if a Block is tried to be created |
|
2238 | 86 |
with new (which is not allowed). |
87 |
Only the VM is allowed to create Blocks. |
|
1 | 88 |
|
1293 | 89 |
|
67 | 90 |
NOTICE: layout known by runtime system and compiler - do not change |
1293 | 91 |
|
92 |
[author:] |
|
2238 | 93 |
Claus Gittinger |
1293 | 94 |
|
95 |
[see also:] |
|
2238 | 96 |
Process Context |
97 |
Collection |
|
98 |
( contexts. blocks & unwinding : programming/contexts.html) |
|
1 | 99 |
" |
1265 | 100 |
! |
101 |
||
102 |
examples |
|
103 |
" |
|
1293 | 104 |
define a block and evaluate it: |
2238 | 105 |
[exBegin] |
106 |
|b| |
|
1265 | 107 |
|
2238 | 108 |
b := [ Transcript showCR:'hello' ]. |
1293 | 109 |
|
2238 | 110 |
Transcript showCR:'now evaluating the block ...'. |
111 |
b value. |
|
112 |
[exEnd] |
|
1265 | 113 |
|
114 |
||
1293 | 115 |
|
1265 | 116 |
even here, blocks are involved: |
117 |
(although, the compiler optimizes things if possible) |
|
2238 | 118 |
[exBegin] |
119 |
Transcript showCR:'now evaluating one of two blocks ...'. |
|
120 |
1 > 4 ifTrue:[ |
|
121 |
Transcript showCR:'foo' |
|
122 |
] ifFalse:[ |
|
123 |
Transcript showCR:'bar' |
|
124 |
] |
|
125 |
[exEnd] |
|
1265 | 126 |
|
127 |
||
1293 | 128 |
|
1265 | 129 |
here things become obvious: |
2238 | 130 |
[exBegin] |
131 |
|yesBlock noBlock| |
|
1265 | 132 |
|
2238 | 133 |
yesBlock := [ Transcript showCR:'foo' ]. |
134 |
noBlock := [ Transcript showCR:'bar' ]. |
|
1265 | 135 |
|
2238 | 136 |
Transcript showCR:'now evaluating one of two blocks ...'. |
137 |
1 > 4 ifTrue:yesBlock |
|
138 |
ifFalse:noBlock |
|
139 |
[exEnd] |
|
1265 | 140 |
|
141 |
||
1293 | 142 |
|
1265 | 143 |
simple loops: |
144 |
not very objectOriented: |
|
2238 | 145 |
[exBegin] |
146 |
|i| |
|
1265 | 147 |
|
2238 | 148 |
i := 1. |
149 |
[i < 10] whileTrue:[ |
|
150 |
Transcript showCR:i. |
|
151 |
i := i + 1 |
|
152 |
] |
|
153 |
[exEnd] |
|
1265 | 154 |
|
155 |
||
156 |
using integer protocol: |
|
2238 | 157 |
[exBegin] |
158 |
1 to:10 do:[:i | |
|
159 |
Transcript showCR:i. |
|
160 |
] |
|
161 |
[exEnd] |
|
1265 | 162 |
|
163 |
||
164 |
interval protocol: |
|
2238 | 165 |
[exBegin] |
166 |
(1 to:10) do:[:i | |
|
167 |
Transcript showCR:i. |
|
168 |
] |
|
169 |
[exEnd] |
|
1265 | 170 |
|
171 |
||
1293 | 172 |
|
1265 | 173 |
looping over collections: |
174 |
||
1293 | 175 |
bad code: |
176 |
(only works with numeric-indexable collections) |
|
2238 | 177 |
[exBegin] |
178 |
|i coll| |
|
1265 | 179 |
|
2238 | 180 |
coll := #(9 8 7 6 5). |
181 |
i := 1. |
|
182 |
[i <= coll size] whileTrue:[ |
|
183 |
Transcript showCR:(coll at:i). |
|
184 |
i := i + 1. |
|
185 |
] |
|
186 |
[exEnd] |
|
1265 | 187 |
|
188 |
||
189 |
||
1293 | 190 |
just as bad (well, marginally better ;-): |
191 |
(only works with numeric-indexable collections) |
|
2238 | 192 |
[exBegin] |
193 |
|coll| |
|
1265 | 194 |
|
2238 | 195 |
coll := #(9 8 7 6 5). |
196 |
1 to:coll size do:[:i | |
|
197 |
Transcript showCR:(coll at:i). |
|
198 |
] |
|
199 |
[exEnd] |
|
1265 | 200 |
|
201 |
||
202 |
||
1293 | 203 |
the smalltalk way: |
204 |
(works with any collection) |
|
2238 | 205 |
[exBegin] |
206 |
|coll| |
|
1265 | 207 |
|
2238 | 208 |
coll := #(9 8 7 6 5). |
209 |
coll do:[:element | |
|
210 |
Transcript showCR:element. |
|
211 |
] |
|
212 |
[exEnd] |
|
1265 | 213 |
|
214 |
Rule: use enumeration protocol of the collection instead of |
|
2238 | 215 |
manually indexing it. [with few exceptions] |
1265 | 216 |
|
217 |
||
218 |
||
219 |
processes: |
|
220 |
||
221 |
forking a lightweight process (thread): |
|
2238 | 222 |
[exBegin] |
223 |
[ |
|
224 |
Transcript showCR:'waiting ...'. |
|
225 |
Delay waitForSeconds:2. |
|
226 |
Transcript showCR:'here I am'. |
|
227 |
] fork |
|
228 |
[exEnd] |
|
1265 | 229 |
|
230 |
||
231 |
||
232 |
some with low prio: |
|
2238 | 233 |
[exBegin] |
234 |
[ |
|
235 |
Transcript showCR:'computing ...'. |
|
236 |
10000 factorial. |
|
237 |
Transcript showCR:'here I am'. |
|
238 |
] forkAt:(Processor userBackgroundPriority) |
|
239 |
[exEnd] |
|
1265 | 240 |
|
241 |
||
1293 | 242 |
|
243 |
handling exceptions: |
|
2238 | 244 |
[exBegin] |
245 |
Object errorSignal handle:[:ex | |
|
246 |
Transcript showCR:'exception handler forces return'. |
|
247 |
ex return |
|
248 |
] do:[ |
|
249 |
Transcript showCR:'now, doing something bad ...'. |
|
250 |
1 / 0. |
|
251 |
Transcript showCR:'not reached' |
|
252 |
] |
|
253 |
[exEnd] |
|
1265 | 254 |
|
255 |
||
1293 | 256 |
|
257 |
performing cleanup actions: |
|
2238 | 258 |
[exBegin] |
259 |
Object errorSignal handle:[:ex | |
|
260 |
Transcript showCR:'exception handler forces return'. |
|
261 |
ex return |
|
262 |
] do:[ |
|
263 |
[ |
|
264 |
Transcript showCR:'doing something bad ...'. |
|
265 |
1 / 0. |
|
266 |
Transcript showCR:'not reached' |
|
267 |
] valueOnUnwindDo:[ |
|
268 |
Transcript showCR:'cleanup' |
|
269 |
] |
|
270 |
] |
|
271 |
[exEnd] |
|
1265 | 272 |
|
273 |
||
1293 | 274 |
delayed execution (visitor pattern): |
275 |
(looking carefully into the example, |
|
276 |
C/C++ programmers may raise their eyes ;-) |
|
2238 | 277 |
[exBegin] |
278 |
|showBlock countBlock |
|
279 |
howMany |
|
280 |
top panel b1 b2| |
|
1265 | 281 |
|
2238 | 282 |
howMany := 0. |
1265 | 283 |
|
2238 | 284 |
showBlock := [ Transcript showCR:howMany ]. |
285 |
countBlock := [ howMany := howMany + 1 ]. |
|
1265 | 286 |
|
2238 | 287 |
top := StandardSystemView extent:200@200. |
288 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
1265 | 289 |
|
2238 | 290 |
b1 := Button label:'count up' in:panel. |
291 |
b1 action:countBlock. |
|
1265 | 292 |
|
2238 | 293 |
b2 := Button label:'show value' in:panel. |
294 |
b2 action:showBlock. |
|
1265 | 295 |
|
2238 | 296 |
top open. |
1265 | 297 |
|
2238 | 298 |
Transcript showCR:'new process started;'. |
299 |
Transcript showCR:'notice: the blocks can still access the'. |
|
300 |
Transcript showCR:' howMany local variable.'. |
|
301 |
[exEnd] |
|
1265 | 302 |
" |
1 | 303 |
! ! |
304 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
305 |
!Block class methodsFor:'initialization'! |
1 | 306 |
|
307 |
initialize |
|
1254 | 308 |
"create signals raised by various errors" |
1 | 309 |
|
48 | 310 |
InvalidNewSignal isNil ifTrue:[ |
2238 | 311 |
InvalidNewSignal := ErrorSignal newSignalMayProceed:false. |
312 |
InvalidNewSignal nameClass:self message:#invalidNewSignal. |
|
313 |
InvalidNewSignal notifierString:'blocks are only created by the system'. |
|
48 | 314 |
] |
1254 | 315 |
|
316 |
"Modified: 22.4.1996 / 16:34:20 / cg" |
|
1 | 317 |
! ! |
318 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
319 |
!Block class methodsFor:'instance creation'! |
1 | 320 |
|
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
321 |
byteCode:bCode numArgs:numArgs numStack:nStack sourcePosition:sourcePos initialPC:initialPC literals:literals |
1 | 322 |
"create a new cheap (homeless) block. |
222 | 323 |
Not for public use - this is a special hook for the compiler." |
1 | 324 |
|
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
325 |
^ self |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
326 |
byteCode:bCode numArgs:numArgs numVars:0 numStack:nStack sourcePosition:sourcePos initialPC:initialPC literals:literals |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
327 |
! |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
328 |
|
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
329 |
byteCode:bCode numArgs:numArgs numVars:numVars numStack:nStack sourcePosition:sourcePos initialPC:initialPC literals:literals |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
330 |
"create a new cheap (homeless) block. |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
331 |
Not for public use - this is a special hook for the compiler." |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
332 |
|
1 | 333 |
|newBlock| |
334 |
||
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
335 |
newBlock := (super basicNew:(literals size)) |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
336 |
byteCode:bCode |
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
337 |
numArgs:numArgs |
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
338 |
numVars:numVars |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
339 |
numStack:nStack |
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
340 |
sourcePosition:sourcePos |
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
341 |
initialPC:initialPC |
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
342 |
literals:literals. |
1 | 343 |
^ newBlock |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
344 |
|
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
345 |
"Modified: 24.6.1996 / 12:36:48 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
346 |
"Created: 13.4.1997 / 00:04:09 / cg" |
1 | 347 |
! |
348 |
||
22 | 349 |
new |
4299 | 350 |
"catch creation of blocks - only the system creates blocks. |
351 |
If you really need a block (assuming, you are some compiler), |
|
352 |
use basicNew and setup the instance carefully" |
|
1 | 353 |
|
128 | 354 |
^ InvalidNewSignal raise. |
1 | 355 |
! |
356 |
||
22 | 357 |
new:size |
1 | 358 |
"catch creation of blocks - only the system creates blocks" |
359 |
||
128 | 360 |
^ InvalidNewSignal raise. |
1 | 361 |
! ! |
362 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
363 |
!Block class methodsFor:'queries'! |
1 | 364 |
|
623 | 365 |
isBuiltInClass |
1264 | 366 |
"return true if this class is known by the run-time-system. |
367 |
Here, true is returned for myself, false for subclasses." |
|
11 | 368 |
|
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
369 |
^ self == Block |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
370 |
|
1264 | 371 |
"Modified: 23.4.1996 / 15:55:58 / cg" |
1 | 372 |
! ! |
373 |
||
5744 | 374 |
|
5349 | 375 |
!Block methodsFor:'Compatibility - ANSI'! |
376 |
||
5944 | 377 |
argumentCount |
378 |
"VisualAge compatibility: alias for #numArgs. |
|
379 |
return the number of arguments I expect for evaluation" |
|
380 |
||
381 |
^ nargs |
|
382 |
||
383 |
"Created: 15.11.1996 / 11:22:02 / cg" |
|
384 |
! |
|
385 |
||
5349 | 386 |
ensure:aBlock |
387 |
"evaluate the receiver and return its result. |
|
388 |
After evaluation, also evaluate aBlock but ignore its result. |
|
389 |
aBlock is also evaluated in case of abnormal termination. |
|
390 |
(the same as #valueNowOrOnUnwindDo:)" |
|
391 |
||
5666
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
392 |
<exception: #unwind> |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
393 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
394 |
|v| |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
395 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
396 |
v := self value. "the real logic is in Context>>unwind" |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
397 |
thisContext unmarkForUnwind. |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
398 |
aBlock value. |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
399 |
^ v |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
400 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
401 |
"/ the above is the same as in #valueNowOrOnUnwindDo: |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
402 |
"/ (actually, the previous implementation was: |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
403 |
"/ ^ self valueNowOrOnUnwindDo:aBlock |
5349 | 404 |
|
405 |
" |
|
406 |
[ |
|
407 |
[ |
|
408 |
Transcript showCR:'one'. |
|
409 |
Processor activeProcess terminate. |
|
410 |
Transcript showCR:'two'. |
|
411 |
] ensure:[ |
|
412 |
Transcript showCR:'three'. |
|
413 |
]. |
|
414 |
] fork. |
|
415 |
" |
|
416 |
||
417 |
" |
|
418 |
[ |
|
419 |
[ |
|
420 |
Transcript showCR:'one'. |
|
421 |
Transcript showCR:'two'. |
|
422 |
] ensure:[ |
|
423 |
Transcript showCR:'three'. |
|
424 |
]. |
|
425 |
] fork. |
|
426 |
" |
|
5951 | 427 |
! |
428 |
||
429 |
ifCurtailed:aBlock |
|
430 |
"evaluate the receiver - when some method sent within unwinds (i.e. does |
|
431 |
a long return), evaluate the argument, aBlock. |
|
432 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
433 |
executed regardless of error actions. |
|
434 |
This is the same as #valueOnUnwindDo:" |
|
435 |
||
436 |
<exception: #unwind> |
|
437 |
||
438 |
|v| |
|
439 |
||
440 |
"/ thisContext markForUnwind. -- same as above pragma |
|
441 |
v := self value. "the real logic is in Context>>unwind" |
|
442 |
thisContext unmarkForUnwind. |
|
443 |
^ v |
|
444 |
||
445 |
" |
|
446 |
|s| |
|
447 |
||
448 |
s := 'Makefile' asFilename readStream. |
|
449 |
[ |
|
450 |
^ self |
|
451 |
] ifCurtailed:[ |
|
452 |
Transcript showCR:'closing the stream - even though a return occurred'. |
|
453 |
s close |
|
454 |
] |
|
455 |
" |
|
456 |
" |
|
457 |
[ |
|
458 |
|s| |
|
459 |
||
460 |
s := 'Makefile' asFilename readStream. |
|
461 |
[ |
|
462 |
Processor activeProcess terminate |
|
463 |
] ifCurtailed:[ |
|
464 |
Transcript showCR:'closing the stream - even though process was terminated'. |
|
465 |
s close |
|
466 |
] |
|
467 |
] fork |
|
468 |
" |
|
5349 | 469 |
! ! |
470 |
||
5015 | 471 |
!Block methodsFor:'Compatibility - Squeak'! |
472 |
||
473 |
ifError:handlerBlock |
|
474 |
^ self on:Error do:handlerBlock |
|
475 |
! ! |
|
476 |
||
1979 | 477 |
!Block methodsFor:'Compatibility - V''Age'! |
478 |
||
479 |
valueOnReturnDo:aBlock |
|
480 |
"VisualAge compatibility: alias for #valueOnUnwindDo: |
|
481 |
evaluate the receiver - when some method sent within unwinds |
|
482 |
(i.e. does a long return), evaluate the argument, aBlock. |
|
483 |
This is used to make certain that cleanup actions |
|
484 |
(for example closing files etc.) are executed regardless of error actions. |
|
485 |
||
486 |
Q: is this the exact semantics of V'Ages method ? |
|
2238 | 487 |
the documentation is unclean; it could be a valueNowOrOnUnwindDo: ..." |
1979 | 488 |
|
489 |
^ self valueOnUnwindDo:aBlock |
|
490 |
||
491 |
"Created: 15.11.1996 / 11:38:37 / cg" |
|
492 |
! ! |
|
493 |
||
623 | 494 |
!Block methodsFor:'accessing'! |
154 | 495 |
|
496 |
home |
|
497 |
"return the receivers home context (the context where it was |
|
498 |
created). For cheap blocks, nil is returned" |
|
499 |
||
500 |
^ home |
|
161 | 501 |
! |
502 |
||
2694
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
503 |
homeMethod |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
504 |
"return the receivers home method. |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
505 |
Thats the method where the block was created." |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
506 |
|
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
507 |
home notNil ifTrue:[ |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
508 |
^ home method |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
509 |
]. |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
510 |
^ nil |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
511 |
|
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
512 |
"Created: 19.6.1997 / 16:14:57 / cg" |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
513 |
! |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
514 |
|
161 | 515 |
method |
516 |
"return the receivers method |
|
2694
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
517 |
(the method where the block was created). |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
518 |
Obsolete: use #homeMethod for ST80 compatibility." |
161 | 519 |
|
2694
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
520 |
^ self homeMethod |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
521 |
|
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
522 |
"Modified: 19.6.1997 / 16:15:24 / cg" |
623 | 523 |
! |
11 | 524 |
|
623 | 525 |
methodHome |
526 |
"return the receivers method home context (the context where it was |
|
527 |
defined). For cheap blocks, nil is returned" |
|
528 |
||
529 |
home notNil ifTrue:[ |
|
530 |
^ home methodHome |
|
531 |
]. |
|
532 |
^ home |
|
11 | 533 |
! |
534 |
||
623 | 535 |
numArgs |
536 |
"return the number of arguments I expect for evaluation" |
|
1 | 537 |
|
623 | 538 |
^ nargs |
539 |
! ! |
|
1 | 540 |
|
5931
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
541 |
!Block methodsFor:'binary storage'! |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
542 |
|
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
543 |
storeBinaryDefinitionOn:stream manager:manager |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
544 |
byteCode isNil ifTrue:[ |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
545 |
self halt:'cannot preserve semantics of block'. |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
546 |
]. |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
547 |
^ super storeBinaryDefinitionOn:stream manager:manager |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
548 |
! ! |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
549 |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
550 |
!Block methodsFor:'conversion'! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
551 |
|
5349 | 552 |
asVarArgBlock |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
553 |
"convert myself into a varArg block; |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
554 |
this one has 1 formal argument, which gets the list |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
555 |
of actual arguments when evaluated." |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
556 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
557 |
nargs ~~ 1 ifTrue:[ |
2241 | 558 |
self error:'vararg blocks must take exactly 1 argument - the arg list'. |
559 |
^ nil |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
560 |
]. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
561 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
562 |
self changeClassTo:VarArgBlock. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
563 |
^ self |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
564 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
565 |
" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
566 |
|b| |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
567 |
|
5349 | 568 |
b := [:argList | Transcript |
569 |
show:'invoked with args:'; |
|
570 |
showCR:argList |
|
571 |
] asVarArgBlock. |
|
572 |
b value. |
|
573 |
b value:'arg1'. |
|
574 |
b value:'arg1' value:'arg2' value:'arg3' value:'arg4' |
|
575 |
" |
|
576 |
||
577 |
"Created: 23.1.1997 / 13:35:28 / cg" |
|
578 |
"Modified: 23.1.1997 / 13:35:48 / cg" |
|
579 |
! |
|
580 |
||
581 |
beVarArg |
|
582 |
"convert myself into a varArg block; |
|
583 |
this one has 1 formal argument, which gets the list |
|
584 |
of actual arguments when evaluated." |
|
585 |
||
586 |
^ self asVarArgBlock. |
|
587 |
||
588 |
" |
|
589 |
|b| |
|
590 |
||
2241 | 591 |
b := [:argList | argList printCR] beVarArg. |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
592 |
b value. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
593 |
b value:'arg1' value:'arg2' value:'arg3' value:'arg4' |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
594 |
" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
595 |
|
2241 | 596 |
"Created: 23.1.1997 / 13:35:28 / cg" |
597 |
"Modified: 23.1.1997 / 13:35:48 / cg" |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
598 |
! ! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
599 |
|
623 | 600 |
!Block methodsFor:'copying'! |
1 | 601 |
|
3349
84a92126a268
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
2841
diff
changeset
|
602 |
deepCopyUsing:aDictionary |
623 | 603 |
"raise an error - deepCopy is not allowed for blocks" |
1 | 604 |
|
623 | 605 |
^ self deepCopyError |
3349
84a92126a268
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
2841
diff
changeset
|
606 |
|
84a92126a268
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
2841
diff
changeset
|
607 |
"Created: / 31.3.1998 / 15:46:17 / cg" |
1 | 608 |
! ! |
609 |
||
610 |
!Block methodsFor:'error handling'! |
|
611 |
||
328 | 612 |
invalidCodeObject |
1874 | 613 |
"{ Pragma: +optSpace }" |
614 |
||
67 | 615 |
"this error is triggered by the interpreter when a non-Block object |
616 |
is about to be executed. |
|
617 |
In this case, the VM sends this to the bad method (the receiver). |
|
618 |
Can only happen when the Compiler/runtime system is broken or |
|
619 |
someone played around." |
|
1 | 620 |
|
128 | 621 |
^ InvalidCodeSignal |
2238 | 622 |
raiseRequestWith:self |
623 |
errorString:'invalid block - not executable' |
|
1874 | 624 |
|
625 |
"Modified: 4.11.1996 / 22:46:39 / cg" |
|
1 | 626 |
! ! |
627 |
||
628 |
!Block methodsFor:'evaluation'! |
|
629 |
||
630 |
value |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
631 |
"evaluate the receiver with no block args. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
632 |
The receiver must be a block without arguments." |
1 | 633 |
|
634 |
%{ /* NOCONTEXT */ |
|
635 |
||
636 |
REGISTER OBJFUNC thecode; |
|
637 |
OBJ home; |
|
638 |
||
1133 | 639 |
if (__INST(nargs) == __MKSMALLINT(0)) { |
1 | 640 |
#if defined(THIS_CONTEXT) |
328 | 641 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 642 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 643 |
#endif |
328 | 644 |
|
1133 | 645 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 646 |
#ifdef NEW_BLOCK_CALL |
154 | 647 |
if (thecode != (OBJFUNC)nil) { |
648 |
/* compiled machine code */ |
|
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
649 |
RETURN ( (*thecode)(self) ); |
154 | 650 |
} |
651 |
/* interpreted code */ |
|
328 | 652 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
653 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
328 | 654 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
655 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
328 | 656 |
# endif |
11 | 657 |
#else |
1133 | 658 |
home = __BlockInstPtr(self)->b_home; |
154 | 659 |
if (thecode != (OBJFUNC)nil) { |
660 |
/* compiled machine code */ |
|
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
661 |
RETURN ( (*thecode)(home) ); |
154 | 662 |
} |
663 |
/* interpreted code */ |
|
328 | 664 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
665 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
328 | 666 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
667 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
328 | 668 |
# endif |
11 | 669 |
#endif |
1 | 670 |
} |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
671 |
%}. |
103 | 672 |
^ self wrongNumberOfArguments:0 |
1 | 673 |
! |
674 |
||
675 |
value:arg |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
676 |
"evaluate the receiver with one argument. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
677 |
The receiver must be a 1-arg block." |
1 | 678 |
|
679 |
%{ /* NOCONTEXT */ |
|
680 |
||
681 |
REGISTER OBJFUNC thecode; |
|
682 |
OBJ home; |
|
683 |
||
1133 | 684 |
if (__INST(nargs) == __MKSMALLINT(1)) { |
1 | 685 |
#if defined(THIS_CONTEXT) |
328 | 686 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 687 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 688 |
#endif |
1133 | 689 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 690 |
#ifdef NEW_BLOCK_CALL |
154 | 691 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
692 |
RETURN ( (*thecode)(self, arg) ); |
154 | 693 |
} |
694 |
/* interpreted code */ |
|
328 | 695 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
696 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, &arg) ); |
328 | 697 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
698 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, arg) ); |
328 | 699 |
# endif |
1 | 700 |
#else |
1133 | 701 |
home = __BlockInstPtr(self)->b_home; |
154 | 702 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
703 |
RETURN ( (*thecode)(home, arg) ); |
154 | 704 |
} |
705 |
/* interpreted code */ |
|
328 | 706 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
707 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, &arg) ); |
328 | 708 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
709 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, arg) ); |
328 | 710 |
# endif |
1 | 711 |
#endif |
712 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
713 |
%}. |
103 | 714 |
^ self wrongNumberOfArguments:1 |
1 | 715 |
! |
716 |
||
717 |
value:arg1 value:arg2 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
718 |
"evaluate the receiver with two arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
719 |
The receiver must be a 2-arg block." |
1 | 720 |
|
721 |
%{ /* NOCONTEXT */ |
|
722 |
||
723 |
REGISTER OBJFUNC thecode; |
|
724 |
OBJ home; |
|
725 |
||
1133 | 726 |
if (__INST(nargs) == __MKSMALLINT(2)) { |
1 | 727 |
#if defined(THIS_CONTEXT) |
328 | 728 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 729 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 730 |
#endif |
1133 | 731 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 732 |
#ifdef NEW_BLOCK_CALL |
154 | 733 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
734 |
RETURN ( (*thecode)(self, arg1, arg2) ); |
154 | 735 |
} |
328 | 736 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
737 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, &arg1) ); |
328 | 738 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
739 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, arg1, arg2) ); |
328 | 740 |
# endif |
1 | 741 |
#else |
1133 | 742 |
home = __BlockInstPtr(self)->b_home; |
154 | 743 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
744 |
RETURN ( (*thecode)(home, arg1, arg2) ); |
154 | 745 |
} |
328 | 746 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
747 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, &arg1) ); |
328 | 748 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
749 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, arg1, arg2) ); |
328 | 750 |
# endif |
1 | 751 |
#endif |
752 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
753 |
%}. |
103 | 754 |
^ self wrongNumberOfArguments:2 |
1 | 755 |
! |
756 |
||
757 |
value:arg1 value:arg2 value:arg3 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
758 |
"evaluate the receiver with three arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
759 |
The receiver must be a 3-arg block." |
1 | 760 |
|
761 |
%{ /* NOCONTEXT */ |
|
762 |
||
763 |
REGISTER OBJFUNC thecode; |
|
764 |
OBJ home; |
|
765 |
||
1133 | 766 |
if (__INST(nargs) == __MKSMALLINT(3)) { |
1 | 767 |
#if defined(THIS_CONTEXT) |
328 | 768 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 769 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 770 |
#endif |
1133 | 771 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 772 |
#ifdef NEW_BLOCK_CALL |
154 | 773 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
774 |
RETURN ( (*thecode)(self, arg1, arg2, arg3) ); |
154 | 775 |
} |
328 | 776 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
777 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, &arg1) ); |
328 | 778 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
779 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, arg1, arg2, arg3) ); |
328 | 780 |
# endif |
1 | 781 |
#else |
1133 | 782 |
home = __BlockInstPtr(self)->b_home; |
154 | 783 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
784 |
RETURN ( (*thecode)(home, arg1, arg2, arg3) ); |
154 | 785 |
} |
328 | 786 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
787 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, &arg1) ); |
328 | 788 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
789 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, arg1, arg2, arg3) ); |
328 | 790 |
# endif |
1 | 791 |
#endif |
792 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
793 |
%}. |
103 | 794 |
^ self wrongNumberOfArguments:3 |
1 | 795 |
! |
796 |
||
797 |
value:arg1 value:arg2 value:arg3 value:arg4 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
798 |
"evaluate the receiver with four arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
799 |
The receiver must be a 4-arg block." |
1 | 800 |
|
801 |
%{ /* NOCONTEXT */ |
|
802 |
||
803 |
REGISTER OBJFUNC thecode; |
|
804 |
OBJ home; |
|
805 |
||
1133 | 806 |
if (__INST(nargs) == __MKSMALLINT(4)) { |
1 | 807 |
#if defined(THIS_CONTEXT) |
328 | 808 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 809 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 810 |
#endif |
1133 | 811 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 812 |
#ifdef NEW_BLOCK_CALL |
154 | 813 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
814 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4) ); |
154 | 815 |
} |
328 | 816 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
817 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, &arg1) ); |
328 | 818 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
819 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 820 |
# endif |
1 | 821 |
#else |
1133 | 822 |
home = __BlockInstPtr(self)->b_home; |
154 | 823 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
824 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4) ); |
154 | 825 |
} |
328 | 826 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
827 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, &arg1) ); |
328 | 828 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
829 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 830 |
# endif |
1 | 831 |
#endif |
832 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
833 |
%}. |
103 | 834 |
^ self wrongNumberOfArguments:4 |
1 | 835 |
! |
836 |
||
837 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
838 |
"evaluate the receiver with five arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
839 |
The receiver must be a 5-arg block." |
1 | 840 |
|
841 |
%{ /* NOCONTEXT */ |
|
842 |
||
843 |
REGISTER OBJFUNC thecode; |
|
844 |
OBJ home; |
|
845 |
||
1133 | 846 |
if (__INST(nargs) == __MKSMALLINT(5)) { |
1 | 847 |
#if defined(THIS_CONTEXT) |
328 | 848 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 849 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 850 |
#endif |
1133 | 851 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 852 |
#ifdef NEW_BLOCK_CALL |
154 | 853 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
854 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5) ); |
154 | 855 |
} |
328 | 856 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
857 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, &arg1) ); |
328 | 858 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
859 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 860 |
# endif |
1 | 861 |
#else |
1133 | 862 |
home = __BlockInstPtr(self)->b_home; |
154 | 863 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
864 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5) ); |
154 | 865 |
} |
328 | 866 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
867 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, &arg1) ); |
328 | 868 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
869 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 870 |
# endif |
1 | 871 |
#endif |
872 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
873 |
%}. |
103 | 874 |
^ self wrongNumberOfArguments:5 |
1 | 875 |
! |
876 |
||
877 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
878 |
"evaluate the receiver with six arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
879 |
The receiver must be a 6-arg block." |
1 | 880 |
|
881 |
%{ /* NOCONTEXT */ |
|
882 |
||
883 |
REGISTER OBJFUNC thecode; |
|
884 |
OBJ home; |
|
885 |
||
1133 | 886 |
if (__INST(nargs) == __MKSMALLINT(6)) { |
1 | 887 |
#if defined(THIS_CONTEXT) |
328 | 888 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 889 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 890 |
#endif |
1133 | 891 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 892 |
#ifdef NEW_BLOCK_CALL |
154 | 893 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
894 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6) ); |
154 | 895 |
} |
328 | 896 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
897 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, &arg1) ); |
328 | 898 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
899 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 900 |
# endif |
1 | 901 |
#else |
1133 | 902 |
home = __BlockInstPtr(self)->b_home; |
154 | 903 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
904 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6) ); |
154 | 905 |
} |
328 | 906 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
907 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, &arg1) ); |
328 | 908 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
909 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 910 |
# endif |
1 | 911 |
#endif |
912 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
913 |
%}. |
103 | 914 |
^ self wrongNumberOfArguments:6 |
1 | 915 |
! |
916 |
||
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
917 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
918 |
"evaluate the receiver with seven arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
919 |
The receiver must be a 7-arg block." |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
920 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
921 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
922 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
923 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
924 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
925 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
926 |
if (__INST(nargs) == __MKSMALLINT(7)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
927 |
#if defined(THIS_CONTEXT) |
2238 | 928 |
if (__ISVALID_ILC_LNO(__pilc)) |
929 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
930 |
#endif |
2238 | 931 |
thecode = __BlockInstPtr(self)->b_code; |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
932 |
#ifdef NEW_BLOCK_CALL |
2238 | 933 |
if (thecode != (OBJFUNC)nil) { |
934 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
935 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
936 |
# ifdef PASS_ARG_POINTER |
2238 | 937 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
938 |
# else |
2238 | 939 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
940 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
941 |
#else |
2238 | 942 |
home = __BlockInstPtr(self)->b_home; |
943 |
if (thecode != (OBJFUNC)nil) { |
|
944 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
945 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
946 |
# ifdef PASS_ARG_POINTER |
2238 | 947 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
948 |
# else |
2238 | 949 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
950 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
951 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
952 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
953 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
954 |
^ self wrongNumberOfArguments:7 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
955 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
956 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
957 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
958 |
"evaluate the receiver with eight arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
959 |
The receiver must be a 8-arg block." |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
960 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
961 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
962 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
963 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
964 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
965 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
966 |
if (__INST(nargs) == __MKSMALLINT(8)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
967 |
#if defined(THIS_CONTEXT) |
2238 | 968 |
if (__ISVALID_ILC_LNO(__pilc)) |
969 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
970 |
#endif |
2238 | 971 |
thecode = __BlockInstPtr(self)->b_code; |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
972 |
#ifdef NEW_BLOCK_CALL |
2238 | 973 |
if (thecode != (OBJFUNC)nil) { |
974 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
975 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
976 |
# ifdef PASS_ARG_POINTER |
2238 | 977 |
RETURN ( __interpret(self, 8, nil, nil, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
978 |
# else |
2238 | 979 |
RETURN ( __interpret(self, 8, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
980 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
981 |
#else |
2238 | 982 |
home = __BlockInstPtr(self)->b_home; |
983 |
if (thecode != (OBJFUNC)nil) { |
|
984 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
985 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
986 |
# ifdef PASS_ARG_POINTER |
2238 | 987 |
RETURN ( __interpret(self, 8, nil, home, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
988 |
# else |
2238 | 989 |
RETURN ( __interpret(self, 8, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
990 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
991 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
992 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
993 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
994 |
^ self wrongNumberOfArguments:8 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
995 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
996 |
|
3688 | 997 |
valueAt:priority |
998 |
"evaluate the receiver, at the given prioriy; |
|
999 |
i.e. change the priority for the execution of the receiver." |
|
1000 |
||
1001 |
|oldPrio retVal| |
|
1002 |
||
1003 |
oldPrio := Processor activePriority. |
|
1004 |
[ |
|
1005 |
Processor activeProcess priority:priority. |
|
1006 |
retVal := self value. |
|
1007 |
] valueNowOrOnUnwindDo:[ |
|
1008 |
Processor activeProcess priority:oldPrio |
|
1009 |
]. |
|
1010 |
^ retVal |
|
1011 |
||
1012 |
" |
|
1013 |
[ |
|
1014 |
1000 timesRepeat:[ |
|
1015 |
1000 factorial |
|
1016 |
] |
|
1017 |
] valueAt:3 |
|
1018 |
" |
|
1019 |
||
1020 |
"Created: / 29.7.1998 / 19:19:48 / cg" |
|
1021 |
! |
|
1022 |
||
1 | 1023 |
valueWithArguments:argArray |
1024 |
"evaluate the receiver with arguments taken from argArray. |
|
313 | 1025 |
ArgArray must be either an Array or nil. |
1 | 1026 |
The size of the argArray must match the number of arguments the receiver expects." |
1027 |
||
3497 | 1028 |
|a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12| |
1 | 1029 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1030 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
3497 | 1031 |
^ self badArgumentArry |
1 | 1032 |
]. |
1033 |
(argArray size == nargs) ifFalse:[ |
|
3497 | 1034 |
^ self wrongNumberOfArguments:(argArray size) |
1 | 1035 |
]. |
1036 |
%{ |
|
1037 |
||
1038 |
REGISTER OBJFUNC thecode; |
|
1039 |
OBJ home; |
|
67 | 1040 |
REGISTER OBJ *ap; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1041 |
int __nargs; |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1042 |
OBJ nA; |
1 | 1043 |
|
1044 |
#if defined(THIS_CONTEXT) |
|
328 | 1045 |
if (__ISVALID_ILC_LNO(__pilc)) |
3497 | 1046 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 1047 |
#endif |
1133 | 1048 |
thecode = __BlockInstPtr(self)->b_code; |
1037 | 1049 |
|
1050 |
#ifndef NEW_BLOCK_CALL |
|
1133 | 1051 |
home = __BlockInstPtr(self)->b_home; |
1037 | 1052 |
if (thecode != (OBJFUNC)nil) { |
3497 | 1053 |
if ((nA = __INST(nargs)) == __MKSMALLINT(0)) { |
1054 |
RETURN ( (*thecode)(home) ); |
|
1055 |
} |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1056 |
|
3497 | 1057 |
switch (__intVal(__INST(nargs))) { |
1058 |
default: |
|
1059 |
goto error; |
|
1060 |
case 12: |
|
1061 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1062 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10], ap[11]) ); |
|
1063 |
case 11: |
|
1064 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1065 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10]) ); |
|
1066 |
case 10: |
|
1067 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1068 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) ); |
|
1069 |
case 9: |
|
1070 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1071 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) ); |
|
1072 |
case 8: |
|
1073 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1074 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
|
1075 |
case 7: |
|
1076 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1077 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
1078 |
case 6: |
|
1079 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1080 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
1081 |
case 5: |
|
1082 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1083 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1084 |
case 4: |
|
1085 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1086 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) ); |
|
1087 |
case 3: |
|
1088 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1089 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) ); |
|
1090 |
case 2: |
|
1091 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1092 |
RETURN ( (*thecode)(home, ap[0], ap[1]) ); |
|
1093 |
case 1: |
|
1094 |
RETURN ( (*thecode)(home, __ArrayInstPtr(argArray)->a_element[0]) ); |
|
1095 |
case 0: |
|
1096 |
RETURN ( (*thecode)(home) ); |
|
1097 |
break; |
|
1098 |
} |
|
1037 | 1099 |
} |
1100 |
#endif |
|
1101 |
||
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1102 |
__nargs = __intVal(__INST(nargs)); |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1103 |
if (__nargs) { |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1104 |
switch (__nargs) { |
3497 | 1105 |
default: |
1106 |
goto error; |
|
1107 |
case 12: |
|
1108 |
a12 = __ArrayInstPtr(argArray)->a_element[11]; |
|
1109 |
case 11: |
|
1110 |
a11 = __ArrayInstPtr(argArray)->a_element[10]; |
|
1111 |
case 10: |
|
1112 |
a10 = __ArrayInstPtr(argArray)->a_element[9]; |
|
1113 |
case 9: |
|
1114 |
a9 = __ArrayInstPtr(argArray)->a_element[8]; |
|
1115 |
case 8: |
|
1116 |
a8 = __ArrayInstPtr(argArray)->a_element[7]; |
|
1117 |
case 7: |
|
1118 |
a7 = __ArrayInstPtr(argArray)->a_element[6]; |
|
1119 |
case 6: |
|
1120 |
a6 = __ArrayInstPtr(argArray)->a_element[5]; |
|
1121 |
case 5: |
|
1122 |
a5 = __ArrayInstPtr(argArray)->a_element[4]; |
|
1123 |
case 4: |
|
1124 |
a4 = __ArrayInstPtr(argArray)->a_element[3]; |
|
1125 |
case 3: |
|
1126 |
a3 = __ArrayInstPtr(argArray)->a_element[2]; |
|
1127 |
case 2: |
|
1128 |
a2 = __ArrayInstPtr(argArray)->a_element[1]; |
|
1129 |
case 1: |
|
1130 |
a1 = __ArrayInstPtr(argArray)->a_element[0]; |
|
1131 |
case 0: |
|
1132 |
break; |
|
1133 |
} |
|
1 | 1134 |
} |
1133 | 1135 |
|
11 | 1136 |
#ifdef NEW_BLOCK_CALL |
1 | 1137 |
if (thecode != (OBJFUNC)nil) { |
3497 | 1138 |
RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
11 | 1139 |
} |
328 | 1140 |
# ifdef PASS_ARG_POINTER |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1141 |
RETURN ( __interpret(self, __nargs, nil, nil, nil, nil, &a1) ); |
328 | 1142 |
# else |
3497 | 1143 |
RETURN ( __interpret(self, __nargs, nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
328 | 1144 |
# endif |
1037 | 1145 |
|
1 | 1146 |
#else |
1037 | 1147 |
|
328 | 1148 |
# ifdef PASS_ARG_POINTER |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1149 |
RETURN ( __interpret(self, __nargs, nil, home, nil, nil, &a1) ); |
328 | 1150 |
# else |
3497 | 1151 |
RETURN ( __interpret(self, __nargs, nil, home, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
328 | 1152 |
# endif |
1037 | 1153 |
|
1 | 1154 |
#endif |
67 | 1155 |
|
11 | 1156 |
error: ; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1157 |
%}. |
138 | 1158 |
" |
3497 | 1159 |
the above code only supports up-to 12 arguments |
138 | 1160 |
" |
128 | 1161 |
^ ArgumentSignal |
3497 | 1162 |
raiseRequestWith:self |
1163 |
errorString:'only blocks with up-to 12 arguments supported' |
|
154 | 1164 |
! ! |
1165 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1166 |
!Block methodsFor:'exception handling'! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1167 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1168 |
handlerForSignal:signal context:theContext originator:originator |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1169 |
"answer the handler block for the signal from originator. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1170 |
The handler block is retrieved from aContext. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1171 |
Answer nil if the signal is not handled." |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1172 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1173 |
|sig handler| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1174 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1175 |
theContext selector == #on:do: ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1176 |
sig := theContext argAt:1. |
5931
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
1177 |
sig isNil ifTrue:[ |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
1178 |
'oops - nil arg in on:do:-context (undefined Exception)' errorPrintCR. |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
1179 |
theContext fullPrint. |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
1180 |
^ nil. |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
1181 |
]. |
4513 | 1182 |
(sig == signal or:[sig accepts:signal]) ifTrue:[ |
4471
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1183 |
handler := theContext argAt:2. |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1184 |
"/ this is for backward compatibility when no ex-arg |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1185 |
"/ is expected in the block. Is it worth the effort ? |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1186 |
handler numArgs == 0 ifTrue:[ |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1187 |
^ [:ex | handler value] |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1188 |
]. |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1189 |
^ handler |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1190 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1191 |
] ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1192 |
"must be #valueWithExceptionHandler:" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1193 |
handler := theContext argAt:1. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1194 |
^ handler handlerForSignal:signal. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1195 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1196 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1197 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1198 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1199 |
"Created: / 25.7.1999 / 19:52:58 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1200 |
"Modified: / 26.7.1999 / 14:30:42 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1201 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1202 |
|
4542
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1203 |
handlerProtectedBlock:doBlock inContext:context |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1204 |
"set the handlerProtectedBlock in context. |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1205 |
Needed for #restartDo:" |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1206 |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
1207 |
"theContext selector must be #on:do: or #valueWithExceptionHandler:" |
4542
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1208 |
context receiver:doBlock |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1209 |
|
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1210 |
" |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1211 |
[1/0] on:Error do:[:ex| ex restartDo:[55]] |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1212 |
" |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1213 |
|
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1214 |
|
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1215 |
|
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1216 |
! |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1217 |
|
4476 | 1218 |
handlingExceptionInContext:theContext |
4471
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1219 |
"answer the handling signal from aContext." |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1220 |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
1221 |
"theContext selector must be #on:do: or #valueWithExceptionHandler:" |
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
1222 |
^ theContext argAt:1. |
4471
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1223 |
|
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1224 |
! |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1225 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1226 |
on:aSignal do:exceptionBlock |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1227 |
"added for ST/V compatibility; evaluate the receiver, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1228 |
handling aSignal. The argument, exceptionBlock is evaluated |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1229 |
if the signal is raised during evaluation. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1230 |
Warning: no warranty, if the code below mimics ST/V's behavior |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1231 |
correctly - give me a note if it does not ." |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1232 |
|
4542
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1233 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1234 |
<exception: #handle> |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1235 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1236 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1237 |
^ self value. "the real logic is in Exception>>doRaise" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1238 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1239 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1240 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1241 |
1 foo |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1242 |
] on:MessageNotUnderstoodSignal do:[:ex | self halt] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1243 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1244 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1245 |
1 foo |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1246 |
] on:SignalSet anySignal do:[:ex| 2 bar. self halt] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1247 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1248 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1249 |
"Modified: / 26.7.1999 / 15:30:48 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1250 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1251 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1252 |
valueWithExceptionHandler:handler |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1253 |
"evaluate myself. If any of the signals in handler is raised, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1254 |
evaluate the corresponding handler block." |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1255 |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
1256 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1257 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1258 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1259 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1260 |
^ self value. "the real logic is in Exception>>doRaise" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1261 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1262 |
"Created: / 26.7.1999 / 11:23:45 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1263 |
"Modified: / 26.7.1999 / 11:24:06 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1264 |
! ! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1265 |
|
623 | 1266 |
!Block methodsFor:'looping'! |
325 | 1267 |
|
623 | 1268 |
doUntil:aBlock |
1269 |
"repeat the receiver block until aBlock evaluates to true. |
|
1270 |
The receiver is evaluated at least once. |
|
1271 |
This is the same as '... doWhile:[... not]' " |
|
325 | 1272 |
|
623 | 1273 |
"this implementation is for purists ... :-)" |
1274 |
||
1275 |
self value. |
|
1276 |
aBlock value ifTrue:[^ nil]. |
|
1277 |
thisContext restart |
|
325 | 1278 |
|
1279 |
" |
|
623 | 1280 |
|n| |
154 | 1281 |
|
623 | 1282 |
n := 1. |
1283 |
[n printNewline] doUntil:[ (n := n + 1) > 5 ] |
|
154 | 1284 |
" |
1 | 1285 |
! |
1286 |
||
623 | 1287 |
doWhile:aBlock |
1288 |
"repeat the receiver block until aBlock evaluates to false. |
|
1289 |
The receiver is evaluated at least once." |
|
67 | 1290 |
|
154 | 1291 |
"this implementation is for purists ... :-)" |
1292 |
||
623 | 1293 |
self value. |
1294 |
aBlock value ifFalse:[^ nil]. |
|
1295 |
thisContext restart |
|
1296 |
||
1297 |
" |
|
1298 |
|n| |
|
1299 |
||
1300 |
n := 1. |
|
1301 |
[n printNewline] doWhile:[ (n := n + 1) <= 5 ] |
|
1302 |
" |
|
1303 |
! |
|
1304 |
||
1305 |
loop |
|
1211 | 1306 |
"repeat the receiver forever |
1307 |
(the receiver block should contain a return somewhere). |
|
1308 |
The implementation below was inspired by a corresponding Self method." |
|
623 | 1309 |
|
1310 |
self value. |
|
67 | 1311 |
thisContext restart |
1312 |
||
1313 |
" |
|
1314 |
|n| |
|
1315 |
||
1316 |
n := 1. |
|
623 | 1317 |
[ |
2238 | 1318 |
n printNewline. |
1319 |
n >= 10 ifTrue:[^ nil]. |
|
1320 |
n := n + 1 |
|
623 | 1321 |
] loop |
1322 |
" |
|
1211 | 1323 |
|
1324 |
"Modified: 18.4.1996 / 13:50:40 / cg" |
|
623 | 1325 |
! |
1326 |
||
1327 |
loopWithExit |
|
1328 |
"the receiver must be a block of one argument. It is evaluated in a loop forever, |
|
1329 |
and is passed a block, which, if sent a value:-message, will exit the receiver block, |
|
1330 |
returning the parameter of the value:-message. Used for loops with exit in the middle. |
|
1331 |
Inspired by a corresponding Self method." |
|
1332 |
||
1333 |
|exitBlock| |
|
1334 |
||
1335 |
exitBlock := [:exitValue | ^ exitValue]. |
|
1336 |
[true] whileTrue:[self value:exitBlock] |
|
1337 |
||
1338 |
" |
|
1339 |
|i| |
|
1340 |
i := 1. |
|
1341 |
[:exit | |
|
1422 | 1342 |
Transcript showCR:i. |
623 | 1343 |
i == 5 ifTrue:[exit value:'thats it']. |
1344 |
i := i + 1 |
|
1345 |
] loopWithExit |
|
1346 |
" |
|
1347 |
! |
|
1348 |
||
1349 |
repeat |
|
1211 | 1350 |
"repeat the receiver forever - same as loop, for ST-80 compatibility. |
1351 |
(the receiver block should contain a return somewhere)." |
|
623 | 1352 |
|
1353 |
self value. |
|
1354 |
thisContext restart |
|
1211 | 1355 |
|
1356 |
"Modified: 18.4.1996 / 13:50:55 / cg" |
|
623 | 1357 |
! |
1358 |
||
1359 |
valueWithExit |
|
1360 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
|
1361 |
which, if sent a value:-message, will exit the receiver block, returning the parameter of the |
|
1362 |
value:-message. Used for premature returns to the caller. |
|
1363 |
Taken from a manchester goody (a similar construct also appears in Self)." |
|
1364 |
||
1211 | 1365 |
^ self value:[:exitValue | ^exitValue] |
623 | 1366 |
|
1367 |
" |
|
1368 |
[:exit | |
|
2238 | 1369 |
1 to:10 do:[:i | |
1370 |
Transcript showCR:i. |
|
1371 |
i == 5 ifTrue:[exit value:'thats it'] |
|
1372 |
]. |
|
1373 |
'regular block-value; never returned' |
|
623 | 1374 |
] valueWithExit |
1375 |
" |
|
1211 | 1376 |
|
1377 |
"Modified: 18.4.1996 / 13:51:38 / cg" |
|
623 | 1378 |
! |
1379 |
||
5215 | 1380 |
valueWithRestart |
1381 |
|myContext restartAction| |
|
1382 |
||
1383 |
myContext := thisContext. |
|
1384 |
restartAction := [ myContext restart ]. |
|
1385 |
^ self value:restartAction. |
|
1386 |
||
1387 |
" |
|
1388 |
[:restart | |
|
1389 |
(self confirm:'try again ?') ifTrue:[ |
|
1390 |
restart value. |
|
1391 |
] |
|
1392 |
] valueWithRestart |
|
1393 |
" |
|
1394 |
||
1395 |
"Modified: / 25.1.2000 / 21:47:50 / cg" |
|
1396 |
! |
|
1397 |
||
623 | 1398 |
whileFalse |
1399 |
"evaluate the receiver while it evaluates to false (ST80 compatibility)" |
|
1400 |
||
1401 |
"this implementation is for purists ... :-)" |
|
1402 |
||
1403 |
self value ifTrue:[^ nil]. |
|
1404 |
thisContext restart |
|
1405 |
||
1406 |
" |
|
1407 |
|n| |
|
1408 |
||
1409 |
n := 1. |
|
1410 |
[n printNewline. (n := n + 1) > 10] whileFalse |
|
67 | 1411 |
" |
1412 |
! |
|
1 | 1413 |
|
67 | 1414 |
whileFalse:aBlock |
1415 |
"evaluate the argument, aBlock while the receiver evaluates to false. |
|
1416 |
- usually open coded by compilers, but needed here for #perform |
|
1417 |
and expression evaluation." |
|
1418 |
||
154 | 1419 |
"this implementation is for purists ... :-)" |
1420 |
||
67 | 1421 |
self value ifTrue:[^ nil]. |
1422 |
aBlock value. |
|
1423 |
thisContext restart |
|
1424 |
||
1425 |
" |
|
1426 |
|n| |
|
1427 |
||
1428 |
n := 1. |
|
1429 |
[n > 10] whileFalse:[ |
|
154 | 1430 |
n printNewline. |
1431 |
n := n + 1 |
|
67 | 1432 |
] |
1433 |
" |
|
1 | 1434 |
! |
1435 |
||
1436 |
whileTrue |
|
67 | 1437 |
"evaluate the receiver while it evaluates to true (ST80 compatibility)" |
1 | 1438 |
|
154 | 1439 |
"this implementation is for purists ... :-)" |
1440 |
||
67 | 1441 |
self value ifFalse:[^ nil]. |
1442 |
thisContext restart |
|
1 | 1443 |
|
67 | 1444 |
" |
1445 |
|n| |
|
1 | 1446 |
|
67 | 1447 |
n := 1. |
1448 |
[n printNewline. (n := n + 1) <= 10] whileTrue |
|
1449 |
" |
|
1 | 1450 |
! |
1451 |
||
623 | 1452 |
whileTrue:aBlock |
1453 |
"evaluate the argument, aBlock while the receiver evaluates to true. |
|
1454 |
- usually open coded by compilers, but needed here for #perform |
|
1455 |
and expression evaluation." |
|
1 | 1456 |
|
154 | 1457 |
"this implementation is for purists ... :-)" |
1458 |
||
623 | 1459 |
self value ifFalse:[^ nil]. |
1460 |
aBlock value. |
|
67 | 1461 |
thisContext restart |
1462 |
||
1463 |
" |
|
1464 |
|n| |
|
1 | 1465 |
|
67 | 1466 |
n := 1. |
623 | 1467 |
[n <= 10] whileTrue:[ |
154 | 1468 |
n printNewline. |
1469 |
n := n + 1 |
|
623 | 1470 |
] |
68 | 1471 |
" |
67 | 1472 |
! ! |
1473 |
||
92 | 1474 |
!Block methodsFor:'printing & storing'! |
1 | 1475 |
|
1476 |
printOn:aStream |
|
44 | 1477 |
"append a a printed representation of the block to aStream" |
1478 |
||
213 | 1479 |
|homeClass h sel methodClass| |
54 | 1480 |
|
1481 |
"cheap blocks have no home context, but a method instead" |
|
1482 |
||
1483 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
154 | 1484 |
aStream nextPutAll:'[] in '. |
1 | 1485 |
|
154 | 1486 |
" |
1487 |
currently, some cheap blocks don't know where they have been created |
|
1488 |
" |
|
1489 |
aStream nextPutAll:' ??? (optimized)'. |
|
1490 |
^ self |
|
54 | 1491 |
]. |
1492 |
||
1493 |
"a full blown block (with home, but without method)" |
|
1494 |
||
1495 |
aStream nextPutAll:'[] in '. |
|
154 | 1496 |
h := self methodHome. |
1497 |
sel := h selector. |
|
1498 |
"/ old: |
|
1499 |
"/ home receiver class name printOn:aStream. |
|
1500 |
"/ new: |
|
212 | 1501 |
"/ (h searchClass whichClassImplements:sel) name printOn:aStream. |
213 | 1502 |
methodClass := h methodClass. |
1503 |
methodClass isNil ifTrue:[ |
|
1504 |
'UnboundMethod' printOn:aStream. |
|
1505 |
] ifFalse:[ |
|
1506 |
methodClass name printOn:aStream. |
|
1507 |
]. |
|
54 | 1508 |
aStream nextPut:$-. |
154 | 1509 |
sel printOn:aStream. |
54 | 1510 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1511 |
"/ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1512 |
"/ aStream nextPutAll:'[] in '. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1513 |
"/ homeClass := home containingClass. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1514 |
"/ homeClass notNil ifTrue:[ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1515 |
"/ homeClass name printOn:aStream. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1516 |
"/ aStream space. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1517 |
"/ (homeClass selectorForMethod:home) printOn:aStream |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1518 |
"/ ] ifFalse:[ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1519 |
"/ aStream nextPutAll:' ???' |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1520 |
"/ ] |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1521 |
"/ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1522 |
|
1 | 1523 |
! ! |
623 | 1524 |
|
1525 |
!Block methodsFor:'private accessing'! |
|
1526 |
||
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
1527 |
byteCode:bCode numArgs:numArgs numVars:numVars numStack:numStack sourcePosition:srcPos initialPC:iPC literals:lits |
1265 | 1528 |
"set all relevant internals. |
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1529 |
DANGER ALERT: this interface is strictly private." |
623 | 1530 |
|
1531 |
byteCode := bCode. |
|
1532 |
nargs := numArgs. |
|
1533 |
sourcePos := srcPos. |
|
1534 |
initialPC := iPC. |
|
1777 | 1535 |
flags := 0. |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
1536 |
self stackSize:numStack. |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1537 |
self literals:lits. |
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
1538 |
self numberOfArgs:numArgs. "/ must set the compiledCode flags as well |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
1539 |
self numberOfVars:numVars. "/ must set the compiledCode flags as well |
1265 | 1540 |
|
1541 |
"Modified: 23.4.1996 / 16:05:30 / cg" |
|
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1542 |
"Modified: 24.6.1996 / 12:37:37 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
1543 |
"Created: 13.4.1997 / 00:00:57 / cg" |
623 | 1544 |
! |
1545 |
||
5779 | 1546 |
initialPC |
1547 |
"return the initial pc for evaluation." |
|
1548 |
||
1549 |
^ initialPC |
|
1550 |
! |
|
1551 |
||
623 | 1552 |
initialPC:initial |
1265 | 1553 |
"set the initial pc for evaluation. |
1554 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1555 |
|
1556 |
initialPC := initial |
|
1265 | 1557 |
|
1558 |
"Modified: 23.4.1996 / 16:05:39 / cg" |
|
623 | 1559 |
! |
1560 |
||
1561 |
numArgs:numArgs |
|
1265 | 1562 |
"set the number of arguments the receiver expects for evaluation. |
1563 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1564 |
|
1565 |
nargs := numArgs |
|
1265 | 1566 |
|
1567 |
"Modified: 23.4.1996 / 16:05:52 / cg" |
|
623 | 1568 |
! |
1569 |
||
5744 | 1570 |
setHome:aContext |
1571 |
home := aContext |
|
1572 |
! |
|
1573 |
||
623 | 1574 |
sourcePosition:position |
1265 | 1575 |
"set the position of the source within my method. |
1576 |
This interface is for the compiler only." |
|
623 | 1577 |
|
1578 |
sourcePos := position |
|
1265 | 1579 |
|
1580 |
"Modified: 23.4.1996 / 16:06:19 / cg" |
|
623 | 1581 |
! ! |
1582 |
||
1583 |
!Block methodsFor:'privileged evaluation'! |
|
1584 |
||
1585 |
valueUninterruptably |
|
1586 |
"evaluate the receiver with interrupts blocked. |
|
1587 |
This does not prevent preemption by a higher priority processes |
|
1588 |
if any becomes runnable due to the evaluation of the receiver |
|
1589 |
(i.e. if a semaphore is signalled)." |
|
1590 |
||
2301 | 1591 |
"we must keep track of blocking-state if this is called nested" |
1592 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
1593 |
"/ already blocked. |
|
1594 |
^ self value |
|
1595 |
]. |
|
864 | 1596 |
|
2301 | 1597 |
^ self valueNowOrOnUnwindDo:[OperatingSystem unblockInterrupts]. |
623 | 1598 |
! |
1599 |
||
1600 |
valueUnpreemptively |
|
1601 |
"evaluate the receiver without the possiblity of preemption |
|
1602 |
(i.e. at a very high priority)" |
|
1603 |
||
1604 |
|oldPrio activeProcess| |
|
1605 |
||
1606 |
activeProcess := Processor activeProcess. |
|
1607 |
oldPrio := activeProcess changePriority:(Processor highestPriority). |
|
864 | 1608 |
^ self valueNowOrOnUnwindDo:[ |
623 | 1609 |
activeProcess priority:oldPrio |
1610 |
] |
|
1611 |
! ! |
|
1612 |
||
1613 |
!Block methodsFor:'process creation'! |
|
1614 |
||
1615 |
fork |
|
1616 |
"create a new process executing the receiver at the current priority." |
|
1617 |
||
1618 |
^ self newProcess resume |
|
1619 |
! |
|
1620 |
||
1621 |
forkAt:priority |
|
1622 |
"create a new process executing the receiver at a different priority." |
|
1623 |
||
1624 |
^ (self newProcess priority:priority) resume |
|
1625 |
! |
|
1626 |
||
1627 |
forkWith:argArray |
|
1628 |
"create a new process executing the receiver, |
|
1629 |
passing elements in argArray as arguments to the receiver block." |
|
1630 |
||
1631 |
^ [self valueWithArguments:argArray] fork. |
|
1632 |
! |
|
1633 |
||
1634 |
newProcess |
|
1635 |
"create a new (unscheduled) process executing the receiver" |
|
1636 |
||
1637 |
^ Process for:self priority:(Processor activePriority) |
|
1638 |
! |
|
1639 |
||
1640 |
newProcessWithArguments:argArray |
|
1641 |
"create a new (unscheduled) process executing the receiver, |
|
1642 |
passing the elements in argArray as arguments to the receiver block." |
|
1643 |
||
1644 |
^ [self valueWithArguments:argArray] newProcess |
|
1645 |
! |
|
1646 |
||
1647 |
promise |
|
1648 |
"create a promise on the receiver. The promise will evaluate the |
|
1649 |
receiver and promise to return the value with the #value message. |
|
1650 |
The evaluation will be performed as a separate process. |
|
1651 |
Asking the promise for its value will either block the asking process |
|
1652 |
(if the evaluation has not yet been finished) or return the value |
|
1653 |
immediately." |
|
1654 |
||
1655 |
^ Promise value:self |
|
1656 |
||
1657 |
" |
|
1658 |
|p| |
|
1659 |
||
1660 |
p := [1000 factorial] promise. |
|
1661 |
'do something else ...'. |
|
1662 |
p value |
|
1663 |
" |
|
1664 |
! |
|
1665 |
||
1666 |
promiseAt:prio |
|
1667 |
"create a promise on the receiver. The promise will evaluate the |
|
1668 |
receiver and promise to return the value with the #value message. |
|
1669 |
The evaluation will be performed as a separate process running at prio. |
|
1670 |
Asking the promise for its value will either block the asking process |
|
1671 |
(if the evaluation has not yet been finished) or return the value |
|
1672 |
immediately." |
|
1673 |
||
1674 |
^ Promise value:self priority:prio |
|
1675 |
! ! |
|
1676 |
||
1677 |
!Block methodsFor:'testing'! |
|
1678 |
||
1679 |
isBlock |
|
1680 |
"return true, if this is a block - yes I am" |
|
1681 |
||
1682 |
^ true |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1683 |
! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1684 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1685 |
isVarArgBlock |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1686 |
"return true, if this block accepts a variable number of arguments" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1687 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1688 |
^ false |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1689 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1690 |
"Created: 23.1.1997 / 04:59:51 / cg" |
623 | 1691 |
! ! |
1692 |
||
1693 |
!Block methodsFor:'unwinding'! |
|
1694 |
||
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1695 |
unwindHandlerInContext:aContext |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1696 |
"given a context which has been marked for unwind, |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1697 |
retrieve the handler block. |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1698 |
This avoids hardwiring access to the first argument in |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1699 |
#unwind methods (and theoretically allows for other unwinding |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1700 |
methods to be added)" |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1701 |
|
4896 | 1702 |
aContext selector == #'value:onUnwindDo:' ifTrue:[ |
1703 |
^ aContext argAt:2 |
|
1704 |
]. |
|
1705 |
||
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1706 |
"/ for now, only #valueNowOrOnUnwindDo: |
4896 | 1707 |
"/ or #valueOnUnwindDo: |
5666
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
1708 |
"/ or #ensure: |
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1709 |
|
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1710 |
^ aContext argAt:1 |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1711 |
! |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1712 |
|
4896 | 1713 |
value:arg onUnwindDo:aBlock |
1714 |
"evaluate the receiver, passing it one argument |
|
1715 |
- when some method sent within unwinds (i.e. does |
|
1716 |
a long return), evaluate the argument, aBlock. |
|
1717 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1718 |
executed regardless of error actions" |
|
1719 |
||
1720 |
<exception: #unwind> |
|
1721 |
||
1722 |
|v| |
|
1723 |
||
1724 |
"/ thisContext markForUnwind. -- same as above pragma |
|
1725 |
v := self value:arg. "the real logic is in Context>>unwind" |
|
1726 |
thisContext unmarkForUnwind. |
|
1727 |
^ v |
|
1728 |
||
1729 |
" |
|
1730 |
|s| |
|
1731 |
||
1732 |
s := 'Makefile' asFilename readStream. |
|
1733 |
[:arg | |
|
1734 |
^ self |
|
1735 |
] value:12345 onUnwindDo:[ |
|
1736 |
Transcript showCR:'closing the stream - even though a return occurred'. |
|
1737 |
s close |
|
1738 |
] |
|
1739 |
" |
|
1740 |
" |
|
1741 |
[ |
|
1742 |
|s| |
|
1743 |
||
1744 |
s := 'Makefile' asFilename readStream. |
|
1745 |
[:arg | |
|
1746 |
Processor activeProcess terminate |
|
1747 |
] value:12345 onUnwindDo:[ |
|
1748 |
Transcript showCR:'closing the stream - even though process was terminated'. |
|
1749 |
s close |
|
1750 |
] |
|
1751 |
] fork |
|
1752 |
" |
|
1753 |
||
1754 |
! |
|
1755 |
||
623 | 1756 |
valueNowOrOnUnwindDo:aBlock |
1757 |
"evaluate the receiver - after that, or when some method sent within unwinds (i.e. does |
|
1758 |
a long return), evaluate the argument, aBlock. |
|
1759 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1760 |
executed regardless of error actions" |
|
1761 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1762 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1763 |
|
623 | 1764 |
|v| |
1765 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1766 |
"/ thisContext markForUnwind. -- same as above pragma |
623 | 1767 |
v := self value. "the real logic is in Context>>unwind" |
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1768 |
thisContext unmarkForUnwind. |
623 | 1769 |
aBlock value. |
1770 |
^ v |
|
1771 |
||
1772 |
" |
|
1773 |
in the following example, f will be closed even if the block |
|
1774 |
returns with 'oops'. There are many more applications of this kind |
|
1775 |
found in the system. |
|
1776 |
" |
|
1777 |
" |
|
1778 |
|f| |
|
1779 |
||
1780 |
f := 'Makefile' asFilename readStream. |
|
1781 |
[ |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1782 |
l := f nextLine. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1783 |
l isNil ifTrue:[^ 'oops'] |
623 | 1784 |
] valueNowOrOnUnwindDo:[ |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1785 |
f close |
623 | 1786 |
] |
1787 |
" |
|
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1788 |
|
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1789 |
"Modified: 16.4.1996 / 11:05:26 / stefan" |
623 | 1790 |
! |
1791 |
||
1792 |
valueOnUnwindDo:aBlock |
|
1793 |
"evaluate the receiver - when some method sent within unwinds (i.e. does |
|
1794 |
a long return), evaluate the argument, aBlock. |
|
1795 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1796 |
executed regardless of error actions" |
|
1797 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1798 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1799 |
|
2286 | 1800 |
|v| |
1801 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1802 |
"/ thisContext markForUnwind. -- same as above pragma |
2286 | 1803 |
v := self value. "the real logic is in Context>>unwind" |
1804 |
thisContext unmarkForUnwind. |
|
1805 |
^ v |
|
1806 |
||
4896 | 1807 |
" |
1808 |
|s| |
|
1809 |
||
1810 |
s := 'Makefile' asFilename readStream. |
|
1811 |
[ |
|
1812 |
^ self |
|
1813 |
] valueOnUnwindDo:[ |
|
1814 |
Transcript showCR:'closing the stream - even though a return occurred'. |
|
1815 |
s close |
|
1816 |
] |
|
1817 |
" |
|
1818 |
" |
|
1819 |
[ |
|
1820 |
|s| |
|
1821 |
||
1822 |
s := 'Makefile' asFilename readStream. |
|
1823 |
[ |
|
1824 |
Processor activeProcess terminate |
|
1825 |
] valueOnUnwindDo:[ |
|
1826 |
Transcript showCR:'closing the stream - even though process was terminated'. |
|
1827 |
s close |
|
1828 |
] |
|
1829 |
] fork |
|
1830 |
" |
|
1831 |
||
623 | 1832 |
! ! |
1833 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1834 |
!Block class methodsFor:'documentation'! |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1835 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1836 |
version |
5951 | 1837 |
^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.104 2001-09-04 10:36:21 cg Exp $' |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1838 |
! ! |
623 | 1839 |
Block initialize! |