author | Claus Gittinger <cg@exept.de> |
Sat, 01 Oct 2016 15:14:21 +0200 | |
changeset 20491 | 692f8c7c92f4 |
parent 20178 | f207817327d9 |
child 20205 | 03e626304d06 |
child 20551 | 599e32fb112f |
permissions | -rw-r--r-- |
20178 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
154 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5349 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17301 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
4299 | 18 |
CompiledCode variableSubclass:#Block |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
19 |
instanceVariableNames:'home nargs sourcePos initialPC' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
20 |
classVariableNames:'InvalidNewSignal' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
21 |
poolDictionaries:'' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
22 |
category:'Kernel-Methods' |
1 | 23 |
! |
24 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
25 |
!Block class methodsFor:'documentation'! |
1 | 26 |
|
92 | 27 |
copyright |
28 |
" |
|
29 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 30 |
All Rights Reserved |
92 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
1 | 41 |
documentation |
42 |
" |
|
67 | 43 |
Blocks are pieces of executable code which can be evaluated by sending |
44 |
them a value-message (''value'', ''value:'', ''value:value:'' etc). |
|
1 | 45 |
|
1265 | 46 |
In smalltalk, Blocks provide the basic (and heavily used) mechanism |
47 |
for looping, enumerating collection elements, visitors, exception |
|
48 |
handling, unwinding, delayed execution and processes. |
|
49 |
||
1254 | 50 |
Blocks are never created explicitely; the only creation |
51 |
is done by the compilers, when some sourceCode is compiled to either |
|
52 |
machine or byteCode. |
|
53 |
||
67 | 54 |
Blocks with arguments need a message of type ''value:arg1 ... value:argn'' |
55 |
for evaluation; the number of arguments passed when evaluating must match |
|
56 |
the number of arguments the block was declared with otherwise an error is |
|
57 |
raised. Blocks without args need a ''value'' message for evaluation. |
|
1 | 58 |
|
154 | 59 |
Blocks keep a reference to the context where the block was declared - |
67 | 60 |
this allows blocks to access the methods arguments and/or variables. |
154 | 61 |
This is still true after the method has returned - since the |
67 | 62 |
block keeps this reference, the methods context will NOT die in this case. |
222 | 63 |
(i.e. Blocks are closures in Smalltalk/X) |
1 | 64 |
|
67 | 65 |
A return (via ^-statement) out of a block will force a return from the |
66 |
blocks method context (if it is still living) - this make the implementation |
|
67 |
of long-jumps and control structures possible. |
|
18252 | 68 |
(If the method is not alive (i.e. has already returned), a return out of the |
154 | 69 |
block will trigger an error) |
1 | 70 |
|
67 | 71 |
Long-jump is done by defining a catchBlock as ''[^ self]'' |
18252 | 72 |
somewhere up in the calling-tree. Then, to do the long-jump from out of some |
67 | 73 |
deeply nested method, simply do: ''catchBlock value''. |
1 | 74 |
|
1293 | 75 |
[Instance variables:] |
1 | 76 |
|
222 | 77 |
home <Context> the context where this block was created (i.e. defined) |
2238 | 78 |
this may be a blockContext or a methodContext |
222 | 79 |
nargs <SmallInteger> the number of arguments the block expects |
80 |
sourcePos <SmallInteger> the character position of its source, in chars |
|
2238 | 81 |
relative to methods source beginning |
222 | 82 |
initialPC <SmallInteger> the start position within the byteCode |
2238 | 83 |
for compiled blocks, this is nil. |
222 | 84 |
|
85 |
||
1293 | 86 |
[Class variables:] |
222 | 87 |
|
88 |
InvalidNewSignal raised if a Block is tried to be created |
|
2238 | 89 |
with new (which is not allowed). |
90 |
Only the VM is allowed to create Blocks. |
|
1 | 91 |
|
1293 | 92 |
|
67 | 93 |
NOTICE: layout known by runtime system and compiler - do not change |
1293 | 94 |
|
95 |
[author:] |
|
2238 | 96 |
Claus Gittinger |
1293 | 97 |
|
98 |
[see also:] |
|
2238 | 99 |
Process Context |
100 |
Collection |
|
101 |
( contexts. blocks & unwinding : programming/contexts.html) |
|
1 | 102 |
" |
1265 | 103 |
! |
104 |
||
105 |
examples |
|
106 |
" |
|
1293 | 107 |
define a block and evaluate it: |
18252 | 108 |
[exBegin] |
109 |
|b| |
|
110 |
||
111 |
b := [ Transcript showCR:'hello' ]. |
|
112 |
||
113 |
Transcript showCR:'now evaluating the block ...'. |
|
114 |
b value. |
|
115 |
[exEnd] |
|
116 |
||
117 |
||
118 |
||
119 |
even here, blocks are involved: |
|
1265 | 120 |
(although, the compiler optimizes things if possible) |
18252 | 121 |
[exBegin] |
122 |
Transcript showCR:'now evaluating one of two blocks ...'. |
|
123 |
1 > 4 ifTrue:[ |
|
124 |
Transcript showCR:'foo' |
|
125 |
] ifFalse:[ |
|
126 |
Transcript showCR:'bar' |
|
127 |
] |
|
128 |
[exEnd] |
|
1265 | 129 |
|
130 |
||
1293 | 131 |
|
1265 | 132 |
here things become obvious: |
18252 | 133 |
[exBegin] |
134 |
|yesBlock noBlock| |
|
135 |
||
136 |
yesBlock := [ Transcript showCR:'foo' ]. |
|
137 |
noBlock := [ Transcript showCR:'bar' ]. |
|
138 |
||
139 |
Transcript showCR:'now evaluating one of two blocks ...'. |
|
140 |
1 > 4 ifTrue:yesBlock |
|
141 |
ifFalse:noBlock |
|
142 |
[exEnd] |
|
1265 | 143 |
|
144 |
||
1293 | 145 |
|
1265 | 146 |
simple loops: |
147 |
not very objectOriented: |
|
18252 | 148 |
[exBegin] |
149 |
|i| |
|
150 |
||
151 |
i := 1. |
|
152 |
[i < 10] whileTrue:[ |
|
153 |
Transcript showCR:i. |
|
154 |
i := i + 1 |
|
155 |
] |
|
156 |
[exEnd] |
|
1265 | 157 |
|
158 |
||
159 |
using integer protocol: |
|
18252 | 160 |
[exBegin] |
161 |
1 to:10 do:[:i | |
|
162 |
Transcript showCR:i. |
|
163 |
] |
|
164 |
[exEnd] |
|
1265 | 165 |
|
166 |
||
167 |
interval protocol: |
|
18252 | 168 |
[exBegin] |
169 |
(1 to:10) do:[:i | |
|
170 |
Transcript showCR:i. |
|
171 |
] |
|
172 |
[exEnd] |
|
1265 | 173 |
|
174 |
||
1293 | 175 |
|
1265 | 176 |
looping over collections: |
177 |
||
1293 | 178 |
bad code: |
179 |
(only works with numeric-indexable collections) |
|
18252 | 180 |
[exBegin] |
181 |
|i coll| |
|
182 |
||
183 |
coll := #(9 8 7 6 5). |
|
184 |
i := 1. |
|
185 |
[i <= coll size] whileTrue:[ |
|
186 |
Transcript showCR:(coll at:i). |
|
187 |
i := i + 1. |
|
188 |
] |
|
189 |
[exEnd] |
|
1265 | 190 |
|
191 |
||
192 |
||
1293 | 193 |
just as bad (well, marginally better ;-): |
194 |
(only works with numeric-indexable collections) |
|
18252 | 195 |
[exBegin] |
196 |
|coll| |
|
197 |
||
198 |
coll := #(9 8 7 6 5). |
|
199 |
1 to:coll size do:[:i | |
|
200 |
Transcript showCR:(coll at:i). |
|
201 |
] |
|
202 |
[exEnd] |
|
1265 | 203 |
|
204 |
||
205 |
||
1293 | 206 |
the smalltalk way: |
207 |
(works with any collection) |
|
18252 | 208 |
[exBegin] |
209 |
|coll| |
|
210 |
||
211 |
coll := #(9 8 7 6 5). |
|
212 |
coll do:[:element | |
|
213 |
Transcript showCR:element. |
|
214 |
] |
|
215 |
[exEnd] |
|
216 |
||
1265 | 217 |
Rule: use enumeration protocol of the collection instead of |
18252 | 218 |
manually indexing it. [with few exceptions] |
1265 | 219 |
|
220 |
||
221 |
||
222 |
processes: |
|
223 |
||
224 |
forking a lightweight process (thread): |
|
18252 | 225 |
[exBegin] |
226 |
[ |
|
227 |
Transcript showCR:'waiting ...'. |
|
228 |
Delay waitForSeconds:2. |
|
229 |
Transcript showCR:'here I am'. |
|
230 |
] fork |
|
231 |
[exEnd] |
|
232 |
||
233 |
||
234 |
||
1265 | 235 |
some with low prio: |
18252 | 236 |
[exBegin] |
237 |
[ |
|
238 |
Transcript showCR:'computing ...'. |
|
239 |
10000 factorial. |
|
240 |
Transcript showCR:'here I am'. |
|
241 |
] forkAt:(Processor userBackgroundPriority) |
|
242 |
[exEnd] |
|
1265 | 243 |
|
244 |
||
1293 | 245 |
|
246 |
handling exceptions: |
|
18252 | 247 |
[exBegin] |
248 |
Error handle:[:ex | |
|
249 |
Transcript showCR:'exception handler forces return'. |
|
250 |
ex return |
|
251 |
] do:[ |
|
252 |
Transcript showCR:'now, doing something bad ...'. |
|
253 |
1 / 0. |
|
254 |
Transcript showCR:'not reached' |
|
255 |
] |
|
256 |
[exEnd] |
|
1265 | 257 |
|
258 |
||
1293 | 259 |
|
260 |
performing cleanup actions: |
|
18252 | 261 |
[exBegin] |
262 |
Error handle:[:ex | |
|
263 |
Transcript showCR:'exception handler forces return'. |
|
264 |
ex return |
|
265 |
] do:[ |
|
266 |
[ |
|
267 |
Transcript showCR:'doing something bad ...'. |
|
268 |
1 / 0. |
|
269 |
Transcript showCR:'not reached' |
|
270 |
] ifCurtailed:[ |
|
271 |
Transcript showCR:'cleanup' |
|
272 |
] |
|
273 |
] |
|
274 |
[exEnd] |
|
1265 | 275 |
|
276 |
||
1293 | 277 |
delayed execution (visitor pattern): |
18252 | 278 |
(looking carefully into the example, |
1293 | 279 |
C/C++ programmers may raise their eyes ;-) |
18252 | 280 |
[exBegin] |
281 |
|showBlock countBlock |
|
282 |
howMany |
|
283 |
top panel b1 b2| |
|
284 |
||
285 |
howMany := 0. |
|
286 |
||
287 |
showBlock := [ Transcript showCR:howMany ]. |
|
288 |
countBlock := [ howMany := howMany + 1 ]. |
|
289 |
||
290 |
top := StandardSystemView extent:200@200. |
|
291 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
292 |
||
293 |
b1 := Button label:'count up' in:panel. |
|
294 |
b1 action:countBlock. |
|
295 |
||
296 |
b2 := Button label:'show value' in:panel. |
|
297 |
b2 action:showBlock. |
|
298 |
||
299 |
top open. |
|
300 |
||
301 |
Transcript showCR:'new process started;'. |
|
302 |
Transcript showCR:'notice: the blocks can still access the'. |
|
303 |
Transcript showCR:' howMany local variable.'. |
|
304 |
[exEnd] |
|
1265 | 305 |
" |
1 | 306 |
! ! |
307 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
308 |
!Block class methodsFor:'initialization'! |
1 | 309 |
|
310 |
initialize |
|
1254 | 311 |
"create signals raised by various errors" |
1 | 312 |
|
48 | 313 |
InvalidNewSignal isNil ifTrue:[ |
18252 | 314 |
InvalidNewSignal := Error newSignalMayProceed:false. |
315 |
InvalidNewSignal nameClass:self message:#invalidNewSignal. |
|
316 |
InvalidNewSignal notifierString:'blocks are only created by the system'. |
|
48 | 317 |
] |
1254 | 318 |
|
319 |
"Modified: 22.4.1996 / 16:34:20 / cg" |
|
1 | 320 |
! ! |
321 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
322 |
!Block class methodsFor:'instance creation'! |
1 | 323 |
|
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
324 |
byteCode:bCode numArgs:numArgs numStack:nStack sourcePosition:sourcePos initialPC:initialPC literals:literals |
1 | 325 |
"create a new cheap (homeless) block. |
222 | 326 |
Not for public use - this is a special hook for the compiler." |
1 | 327 |
|
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
328 |
^ self |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
329 |
byteCode:bCode numArgs:numArgs numVars:0 numStack:nStack sourcePosition:sourcePos initialPC:initialPC literals:literals |
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
330 |
! |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
331 |
|
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
332 |
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
|
333 |
"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
|
334 |
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
|
335 |
|
1 | 336 |
|newBlock| |
337 |
||
18252 | 338 |
newBlock := (super basicNew:(literals size)) |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
339 |
byteCode:bCode |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
340 |
numArgs:numArgs |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
341 |
numVars:numVars |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
342 |
numStack:nStack |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
343 |
sourcePosition:sourcePos |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
344 |
initialPC:initialPC |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
345 |
literals:literals. |
1 | 346 |
^ newBlock |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
347 |
|
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
348 |
"Modified: 24.6.1996 / 12:36:48 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
349 |
"Created: 13.4.1997 / 00:04:09 / cg" |
1 | 350 |
! |
351 |
||
22 | 352 |
new |
4299 | 353 |
"catch creation of blocks - only the system creates blocks. |
354 |
If you really need a block (assuming, you are some compiler), |
|
355 |
use basicNew and setup the instance carefully" |
|
1 | 356 |
|
128 | 357 |
^ InvalidNewSignal raise. |
1 | 358 |
! |
359 |
||
22 | 360 |
new:size |
1 | 361 |
"catch creation of blocks - only the system creates blocks" |
362 |
||
128 | 363 |
^ InvalidNewSignal raise. |
1 | 364 |
! ! |
365 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
366 |
!Block class methodsFor:'queries'! |
1 | 367 |
|
623 | 368 |
isBuiltInClass |
1264 | 369 |
"return true if this class is known by the run-time-system. |
370 |
Here, true is returned for myself, false for subclasses." |
|
11 | 371 |
|
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
372 |
^ self == Block |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
373 |
|
1264 | 374 |
"Modified: 23.4.1996 / 15:55:58 / cg" |
1 | 375 |
! ! |
376 |
||
15850 | 377 |
|
7261 | 378 |
!Block methodsFor:'Compatibility-ANSI'! |
5349 | 379 |
|
5944 | 380 |
argumentCount |
7352 | 381 |
"VisualAge/ANSI compatibility: alias for #numArgs. |
5944 | 382 |
return the number of arguments I expect for evaluation" |
383 |
||
384 |
^ nargs |
|
385 |
||
386 |
"Created: 15.11.1996 / 11:22:02 / cg" |
|
387 |
! |
|
388 |
||
5349 | 389 |
ensure:aBlock |
17697 | 390 |
"VisualAge/ANSI compatibility: |
391 |
evaluate the receiver and return its result. |
|
5349 | 392 |
After evaluation, also evaluate aBlock but ignore its result. |
393 |
aBlock is also evaluated in case of abnormal termination. |
|
394 |
(the same as #valueNowOrOnUnwindDo:)" |
|
395 |
||
5666
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
396 |
<exception: #unwind> |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
397 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
398 |
|v| |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
399 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
400 |
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
|
401 |
thisContext unmarkForUnwind. |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
402 |
aBlock value. |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
403 |
^ v |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
404 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
405 |
"/ the above is the same as in #valueNowOrOnUnwindDo: |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
406 |
"/ (actually, the previous implementation was: |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
407 |
"/ ^ self valueNowOrOnUnwindDo:aBlock |
5349 | 408 |
|
409 |
" |
|
410 |
[ |
|
18252 | 411 |
[ |
412 |
Transcript showCR:'one'. |
|
413 |
Processor activeProcess terminate. |
|
414 |
Transcript showCR:'two'. |
|
415 |
] ensure:[ |
|
416 |
Transcript showCR:'three'. |
|
417 |
]. |
|
5349 | 418 |
] fork. |
419 |
" |
|
420 |
||
421 |
" |
|
422 |
[ |
|
18252 | 423 |
[ |
424 |
Transcript showCR:'one'. |
|
425 |
Transcript showCR:'two'. |
|
426 |
] ensure:[ |
|
427 |
Transcript showCR:'three'. |
|
428 |
]. |
|
5349 | 429 |
] fork. |
430 |
" |
|
5951 | 431 |
! |
432 |
||
433 |
ifCurtailed:aBlock |
|
17697 | 434 |
"VisualAge/ANSI compatibility: |
435 |
evaluate the receiver - when some method sent within unwinds (i.e. does |
|
5951 | 436 |
a long return), evaluate the argument, aBlock. |
437 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
438 |
executed regardless of error actions. |
|
439 |
This is the same as #valueOnUnwindDo:" |
|
440 |
||
441 |
<exception: #unwind> |
|
442 |
||
443 |
|v| |
|
444 |
||
445 |
"/ thisContext markForUnwind. -- same as above pragma |
|
446 |
v := self value. "the real logic is in Context>>unwind" |
|
447 |
thisContext unmarkForUnwind. |
|
448 |
^ v |
|
449 |
||
450 |
" |
|
451 |
|s| |
|
452 |
||
453 |
s := 'Makefile' asFilename readStream. |
|
454 |
[ |
|
18252 | 455 |
^ self |
5951 | 456 |
] ifCurtailed:[ |
18252 | 457 |
Transcript showCR:'closing the stream - even though a return occurred'. |
458 |
s close |
|
5951 | 459 |
] |
460 |
" |
|
461 |
" |
|
462 |
[ |
|
18252 | 463 |
|s| |
464 |
||
465 |
s := 'Makefile' asFilename readStream. |
|
466 |
[ |
|
467 |
Processor activeProcess terminate |
|
468 |
] ifCurtailed:[ |
|
469 |
Transcript showCR:'closing the stream - even though process was terminated'. |
|
470 |
s close |
|
471 |
] |
|
5951 | 472 |
] fork |
473 |
" |
|
5349 | 474 |
! ! |
475 |
||
8440
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
476 |
!Block methodsFor:'Compatibility-Dolphin'! |
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
477 |
|
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
478 |
deferredValue |
17697 | 479 |
"Dolphin compatibility method - do not use in new code. |
12118
41ee8ff1908e
comment/format in: #deferredValue
Claus Gittinger <cg@exept.de>
parents:
11998
diff
changeset
|
480 |
Dolphin's alias for futureValue" |
8440
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
481 |
|
13767 | 482 |
^ Future new block:self |
483 |
||
484 |
"Modified: / 04-10-2011 / 14:56:27 / cg" |
|
485 |
! |
|
486 |
||
487 |
deferredValueAt:priority |
|
17697 | 488 |
"Dolphin compatibility method - do not use in new code. |
13767 | 489 |
Dolphin's alias for futureValue" |
490 |
||
18252 | 491 |
^ Future new |
492 |
priority:priority block:self |
|
13767 | 493 |
|
494 |
"Created: / 04-10-2011 / 14:55:56 / cg" |
|
8440
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
495 |
! ! |
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
496 |
|
7261 | 497 |
!Block methodsFor:'Compatibility-Squeak'! |
5015 | 498 |
|
18252 | 499 |
cull: optionalFirstArg |
17697 | 500 |
"activate the receiver with one or zero arguments. |
501 |
Squeak compatibility, but also present in VW Smalltalk" |
|
502 |
||
503 |
nargs >= 1 ifTrue:[^ self value:optionalFirstArg]. |
|
15089 | 504 |
^ self value |
505 |
! |
|
506 |
||
17697 | 507 |
cull: optionalFirstArg cull: optionalSecondArg |
508 |
"activate the receiver with two or less arguments. |
|
509 |
Squeak compatibility, but also present in VW Smalltalk" |
|
510 |
||
511 |
nargs >= 2 ifTrue:[^ self value:optionalFirstArg value:optionalSecondArg]. |
|
512 |
nargs = 1 ifTrue:[^ self value:optionalFirstArg]. |
|
15089 | 513 |
^ self value |
514 |
! |
|
515 |
||
17697 | 516 |
cull: optionalFirstArg cull: optionalSecondArg cull: optionalThirdArg |
517 |
"activate the receiver with three or less arguments. |
|
518 |
Squeak compatibility, but also present in VW Smalltalk" |
|
15089 | 519 |
|
520 |
nargs >= 2 ifTrue:[ |
|
18252 | 521 |
nargs >= 3 ifTrue:[ |
522 |
^ self value:optionalFirstArg value:optionalSecondArg value:optionalThirdArg |
|
523 |
]. |
|
524 |
^ self value:optionalFirstArg value:optionalSecondArg |
|
15089 | 525 |
]. |
17697 | 526 |
nargs = 1 ifTrue:[^ self value:optionalFirstArg]. |
15088 | 527 |
^ self value |
528 |
! |
|
529 |
||
5015 | 530 |
ifError:handlerBlock |
15119 | 531 |
"squeak compatibility: |
19450 | 532 |
Evaluate the receiver block and return its value, if no error occurs. |
15119 | 533 |
If an error is raised, return the value from handlerBlock. |
534 |
The handlerBlock may take 0,1 or 2 args. |
|
6159
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
535 |
(1 arg -> the exception; |
20144 | 536 |
2 args -> the errorString and the erroneous receiver)" |
6159
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
537 |
|
11934 | 538 |
|numArgs| |
539 |
||
18434 | 540 |
numArgs := handlerBlock isBlock ifTrue:[handlerBlock argumentCount] ifFalse:[0]. |
11934 | 541 |
numArgs == 1 ifTrue:[ |
18434 | 542 |
^ self on:Error do:handlerBlock |
6159
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
543 |
]. |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
544 |
|
18252 | 545 |
^ self |
18434 | 546 |
on:Error |
547 |
do:[:ex | |
|
548 |
|errString errReceiver| |
|
549 |
||
550 |
numArgs == 0 ifTrue:[ |
|
551 |
ex return:handlerBlock value |
|
552 |
] ifFalse:[ |
|
553 |
errString := ex description. |
|
554 |
errReceiver := ex suspendedContext receiver. |
|
555 |
ex return:(handlerBlock value:errString value:errReceiver) |
|
556 |
]. |
|
557 |
] |
|
6142 | 558 |
|
559 |
" |
|
560 |
|a| |
|
561 |
||
562 |
a := 0. |
|
563 |
[ 123 / a ] ifError:[:msg :rec | self halt] |
|
564 |
" |
|
6159
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
565 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
566 |
" |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
567 |
|a| |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
568 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
569 |
a := 0. |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
570 |
[ 123 / a ] ifError:[:ex | self halt] |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
571 |
" |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
572 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
573 |
" |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
574 |
|a| |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
575 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
576 |
a := 0. |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
577 |
[ 123 / a ] ifError:[self halt] |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
578 |
" |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
579 |
! |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
580 |
|
15090 | 581 |
timeToRun |
17697 | 582 |
"squeak compatibility: same as millisecondsToRun:" |
583 |
||
15090 | 584 |
^ Time millisecondsToRun:self |
585 |
! |
|
586 |
||
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
587 |
valueWithPossibleArgs:argArray |
17697 | 588 |
"squeak compatibility: same as valueWithOptionalArguments:" |
589 |
||
9602 | 590 |
^ self valueWithOptionalArguments:argArray |
5015 | 591 |
! ! |
592 |
||
7261 | 593 |
!Block methodsFor:'Compatibility-V''Age'! |
1979 | 594 |
|
14139 | 595 |
apply:aCollection from:start to:end |
17697 | 596 |
"VisualAge compatibility: |
18252 | 597 |
Evaluate the receiver for each variable slot of aCollection from start to end. |
14139 | 598 |
Answer aCollection." |
599 |
||
600 |
aCollection from:start to:end do:self. |
|
601 |
^ aCollection |
|
602 |
||
603 |
" |
|
604 |
[:i | Transcript showCR:i ] |
|
18252 | 605 |
apply:#(10 20 30 40 50 60) from:2 to:4 |
14139 | 606 |
" |
607 |
||
608 |
"Created: / 16-05-2012 / 11:20:55 / cg" |
|
609 |
! |
|
610 |
||
611 |
applyWithIndex:aCollection from:start to:end |
|
17697 | 612 |
"VisualAge compatibility: |
18252 | 613 |
Evaluate the receiver for each variable slot and index of aCollection from start to end. |
14139 | 614 |
Answer aCollection." |
615 |
||
616 |
aCollection from:start to:end doWithIndex:self. |
|
617 |
^ aCollection |
|
618 |
||
619 |
" |
|
620 |
[:el :i | Transcript showCR:(i -> el) ] |
|
18252 | 621 |
applyWithIndex:#(10 20 30 40 50 60) from:2 to:4 |
14139 | 622 |
" |
623 |
||
624 |
"Created: / 16-05-2012 / 11:22:01 / cg" |
|
625 |
! |
|
626 |
||
627 |
value:arg1 onReturnDo:aBlock |
|
628 |
"VisualAge compatibility: alias for #ensure: |
|
629 |
evaluate the receiver - when the block returns either a local return |
|
630 |
or an unwind (i.e. does a long return), evaluate the argument, aBlock. |
|
18252 | 631 |
This is used to make certain that cleanup actions |
14139 | 632 |
(for example closing files etc.) are executed regardless of error actions." |
633 |
||
634 |
^ [self value:arg1] ensure:aBlock |
|
635 |
||
636 |
"Created: / 16-05-2012 / 11:29:30 / cg" |
|
637 |
! |
|
638 |
||
639 |
value:arg1 value:arg2 onReturnDo:aBlock |
|
640 |
"VisualAge compatibility: alias for #ensure: |
|
641 |
evaluate the receiver - when the block returns either a local return |
|
642 |
or an unwind (i.e. does a long return), evaluate the argument, aBlock. |
|
18252 | 643 |
This is used to make certain that cleanup actions |
14139 | 644 |
(for example closing files etc.) are executed regardless of error actions." |
645 |
||
646 |
^ [self value:arg1 value:arg2] ensure:aBlock |
|
647 |
||
648 |
"Created: / 16-05-2012 / 11:29:46 / cg" |
|
649 |
! |
|
650 |
||
651 |
value:arg1 value:arg2 value:arg3 onReturnDo:aBlock |
|
652 |
"VisualAge compatibility: alias for #ensure: |
|
653 |
evaluate the receiver - when the block returns either a local return |
|
654 |
or an unwind (i.e. does a long return), evaluate the argument, aBlock. |
|
18252 | 655 |
This is used to make certain that cleanup actions |
14139 | 656 |
(for example closing files etc.) are executed regardless of error actions." |
657 |
||
658 |
^ [self value:arg1 value:arg2 value:arg3] ensure:aBlock |
|
659 |
||
660 |
"Created: / 16-05-2012 / 11:29:59 / cg" |
|
661 |
! |
|
662 |
||
663 |
valueOnReturnDo:aBlock |
|
664 |
"VisualAge compatibility: alias for #ensure: |
|
665 |
evaluate the receiver - when the block returns either a local return |
|
666 |
or an unwind (i.e. does a long return), evaluate the argument, aBlock. |
|
18252 | 667 |
This is used to make certain that cleanup actions |
14139 | 668 |
(for example closing files etc.) are executed regardless of error actions." |
669 |
||
670 |
^ self ensure:aBlock |
|
671 |
||
672 |
"Created: / 15-11-1996 / 11:38:37 / cg" |
|
13054 | 673 |
! |
674 |
||
675 |
when:exceptionClassOrSignal do:handler |
|
17697 | 676 |
"VisualAge compatibility:" |
677 |
||
13054 | 678 |
^ self on:exceptionClassOrSignal do:handler |
679 |
||
680 |
"Created: / 28-08-2010 / 14:41:15 / cg" |
|
1979 | 681 |
! ! |
682 |
||
17697 | 683 |
|
20178 | 684 |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
685 |
!Block methodsFor:'accessing'! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
686 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
687 |
home |
19450 | 688 |
"return the receiver's home context (the context where it was |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
689 |
created). For cheap blocks, nil is returned" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
690 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
691 |
^ home |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
692 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
693 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
694 |
homeMethod |
19450 | 695 |
"return the receiver's home method. |
696 |
That's the method where the block was created." |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
697 |
|
10473 | 698 |
|m| |
699 |
||
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
700 |
home notNil ifTrue:[ |
19450 | 701 |
m := home method. |
702 |
m notNil ifTrue:[^ m]. |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
703 |
]. |
10473 | 704 |
m := self literalAt:1 ifAbsent:nil. |
705 |
m isMethod ifTrue:[^ m]. |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
706 |
^ nil |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
707 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
708 |
"Created: 19.6.1997 / 16:14:57 / cg" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
709 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
710 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
711 |
method |
19450 | 712 |
"return the receiver's method |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
713 |
(the method where the block was created). |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
714 |
Obsolete: use #homeMethod for ST80 compatibility." |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
715 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
716 |
<resource: #obsolete> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
717 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
718 |
^ self homeMethod |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
719 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
720 |
"Modified: 19.6.1997 / 16:15:24 / cg" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
721 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
722 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
723 |
methodHome |
15532 | 724 |
"return the receiver's method home context (the context where it was |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
725 |
defined). For cheap blocks, nil is returned" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
726 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
727 |
home notNil ifTrue:[ |
18252 | 728 |
^ home methodHome |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
729 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
730 |
^ nil |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
731 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
732 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
733 |
numArgs |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
734 |
"return the number of arguments I expect for evaluation. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
735 |
Please use argumentCount, which is ANSI" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
736 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
737 |
"/ <resource: #obsolete> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
738 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
739 |
^ nargs |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
740 |
! ! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
741 |
|
13220
21b4d5e57663
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
13054
diff
changeset
|
742 |
|
10890 | 743 |
!Block methodsFor:'compatibility-Cola & Pepsi'! |
744 |
||
745 |
arity |
|
18434 | 746 |
^ self argumentCount |
10890 | 747 |
! ! |
5931
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
748 |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
749 |
!Block methodsFor:'conversion'! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
750 |
|
5349 | 751 |
asVarArgBlock |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
752 |
"convert myself into a varArg block; |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
753 |
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
|
754 |
of actual arguments when evaluated." |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
755 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
756 |
nargs ~~ 1 ifTrue:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
757 |
self error:'vararg blocks must take exactly 1 argument - the arg list'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
758 |
^ nil |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
759 |
]. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
760 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
761 |
self changeClassTo:VarArgBlock. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
762 |
^ self |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
763 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
764 |
" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
765 |
|b| |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
766 |
|
18252 | 767 |
b := [:argList | Transcript |
768 |
show:'invoked with args:'; |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
769 |
showCR:argList |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
770 |
] asVarArgBlock. |
5349 | 771 |
b value. |
772 |
b value:'arg1'. |
|
773 |
b value:'arg1' value:'arg2' value:'arg3' value:'arg4' |
|
774 |
" |
|
775 |
||
776 |
"Created: 23.1.1997 / 13:35:28 / cg" |
|
777 |
"Modified: 23.1.1997 / 13:35:48 / cg" |
|
778 |
! |
|
779 |
||
7151 | 780 |
beCurryingBlock |
781 |
"make myself a currying block; |
|
12920
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
782 |
that's a block which, if invoked with less-than-expected arguments, |
7151 | 783 |
returns another block which provides the provided argument(s) and expects the remaining args. |
12920
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
784 |
Read any book on functional programming, if you don't understand this." |
7151 | 785 |
|
786 |
self changeClassTo:CurryingBlock. |
|
787 |
^ self |
|
12920
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
788 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
789 |
" |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
790 |
|b b1 b2 b3| |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
791 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
792 |
b := [:a :b :c | a + b + c] beCurryingBlock. |
18252 | 793 |
b numArgs. |
12920
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
794 |
b value:1 value:2 value:3. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
795 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
796 |
b1 := b value:10. |
18252 | 797 |
b1 numArgs. |
798 |
b1 value:2 value:3. |
|
12920
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
799 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
800 |
b2 := b value:10 value:20. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
801 |
b2 numArgs. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
802 |
b2 value:3. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
803 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
804 |
b3 := b1 value:20. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
805 |
b3 numArgs. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
806 |
b3 value:3. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
807 |
" |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
808 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
809 |
"Modified: / 10-05-2010 / 12:56:20 / cg" |
7151 | 810 |
! |
811 |
||
5349 | 812 |
beVarArg |
813 |
"convert myself into a varArg block; |
|
814 |
this one has 1 formal argument, which gets the list |
|
815 |
of actual arguments when evaluated." |
|
816 |
||
817 |
^ self asVarArgBlock. |
|
818 |
||
819 |
" |
|
820 |
|b| |
|
821 |
||
2241 | 822 |
b := [:argList | argList printCR] beVarArg. |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
823 |
b value. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
824 |
b value:'arg1' value:'arg2' value:'arg3' value:'arg4' |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
825 |
" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
826 |
|
2241 | 827 |
"Created: 23.1.1997 / 13:35:28 / cg" |
828 |
"Modified: 23.1.1997 / 13:35:48 / cg" |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
829 |
! ! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
830 |
|
623 | 831 |
!Block methodsFor:'copying'! |
1 | 832 |
|
10942 | 833 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
10135
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
834 |
|copyOfHome copyOfMe| |
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
835 |
|
8638 | 836 |
home isNil ifTrue:[ |
18252 | 837 |
^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector |
8638 | 838 |
]. |
10135
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
839 |
copyOfHome := home deepCopyUsing:aDictionary. |
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
840 |
copyOfMe := self shallowCopy. |
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
841 |
copyOfMe setHome:copyOfHome. |
13517
95a2ffba9880
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13220
diff
changeset
|
842 |
copyOfMe perform:postCopySelector withOptionalArgument:self and:aDictionary. |
10135
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
843 |
^ copyOfMe |
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
844 |
|
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
845 |
"Created: / 31-03-1998 / 15:46:17 / cg" |
13517
95a2ffba9880
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13220
diff
changeset
|
846 |
"Modified: / 21-07-2011 / 13:30:12 / cg" |
1 | 847 |
! ! |
848 |
||
16871 | 849 |
!Block methodsFor:'debugging'! |
850 |
||
851 |
benchmark:anInfoString |
|
852 |
"evaluate myseld and show the timing info on Transcript" |
|
853 |
||
19795 | 854 |
|startTime endTime overhead micros millis| |
855 |
||
856 |
startTime := OperatingSystem getMicrosecondTime. |
|
857 |
[123] value. |
|
858 |
endTime := OperatingSystem getMicrosecondTime. |
|
859 |
overhead := endTime - startTime. |
|
860 |
||
16871 | 861 |
startTime := OperatingSystem getMicrosecondTime. |
862 |
self value. |
|
863 |
endTime := OperatingSystem getMicrosecondTime. |
|
864 |
||
19795 | 865 |
micros := (endTime - startTime - overhead) max:0. |
16871 | 866 |
|
867 |
Transcript show:anInfoString. |
|
17338 | 868 |
micros < 1000 ifTrue:[ |
19795 | 869 |
"/ too stupid: many fonts do not have a mu, |
870 |
"/ so I output it as us here. |
|
871 |
Transcript show:micros; show:' us'. |
|
16871 | 872 |
] ifFalse:[ |
19795 | 873 |
micros < 100000 ifTrue:[ |
874 |
millis := (micros / 1000.0) asFixedPointRoundedToScale:2. |
|
875 |
Transcript show:millis; show:' ms'. |
|
876 |
] ifFalse:[ |
|
877 |
millis := micros // 1000. |
|
878 |
Transcript show:(TimeDuration milliseconds:millis). |
|
879 |
]. |
|
16871 | 880 |
]. |
881 |
Transcript cr. |
|
882 |
||
883 |
" |
|
19795 | 884 |
[10 factorial] benchmark:'10 factorial:' |
885 |
[100 factorial] benchmark:'100 factorial:' |
|
16871 | 886 |
" |
887 |
! ! |
|
888 |
||
1 | 889 |
!Block methodsFor:'error handling'! |
890 |
||
328 | 891 |
invalidCodeObject |
1874 | 892 |
"{ Pragma: +optSpace }" |
893 |
||
67 | 894 |
"this error is triggered by the interpreter when a non-Block object |
895 |
is about to be executed. |
|
896 |
In this case, the VM sends this to the bad method (the receiver). |
|
897 |
Can only happen when the Compiler/runtime system is broken or |
|
898 |
someone played around." |
|
1 | 899 |
|
7602
d048f13cd50a
Exception classes initialize themself.
Stefan Vogel <sv@exept.de>
parents:
7352
diff
changeset
|
900 |
^ InvalidCodeError |
18252 | 901 |
raiseRequestWith:self |
902 |
errorString:'invalid block - not executable' |
|
1874 | 903 |
|
904 |
"Modified: 4.11.1996 / 22:46:39 / cg" |
|
1 | 905 |
! ! |
906 |
||
907 |
!Block methodsFor:'evaluation'! |
|
908 |
||
909 |
value |
|
18252 | 910 |
"evaluate the receiver with no block args. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
911 |
The receiver must be a block without arguments." |
1 | 912 |
|
913 |
%{ /* NOCONTEXT */ |
|
18252 | 914 |
#ifdef __SCHTEAM__ |
915 |
return context.TAILCALL0( self.asSTCallable() ); |
|
916 |
/* NOTREACHED */ |
|
917 |
#else |
|
1 | 918 |
REGISTER OBJFUNC thecode; |
919 |
OBJ home; |
|
920 |
||
8913 | 921 |
if (__INST(nargs) == __mkSmallInteger(0)) { |
18252 | 922 |
# if defined(THIS_CONTEXT) |
923 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
924 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
925 |
# endif |
|
926 |
||
927 |
thecode = __BlockInstPtr(self)->b_code; |
|
928 |
# ifdef NEW_BLOCK_CALL |
|
929 |
if (thecode != (OBJFUNC)nil) { |
|
930 |
/* compiled machine code */ |
|
931 |
RETURN ( (*thecode)(self) ); |
|
932 |
} |
|
933 |
/* interpreted code */ |
|
934 |
# ifdef PASS_ARG_POINTER |
|
935 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
|
936 |
# else |
|
937 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
|
938 |
# endif |
|
328 | 939 |
# else |
18252 | 940 |
home = __BlockInstPtr(self)->b_home; |
941 |
if (thecode != (OBJFUNC)nil) { |
|
942 |
/* compiled machine code */ |
|
943 |
RETURN ( (*thecode)(home) ); |
|
944 |
} |
|
945 |
/* interpreted code */ |
|
946 |
# ifdef PASS_ARG_POINTER |
|
947 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
|
948 |
# else |
|
949 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
|
950 |
# endif |
|
328 | 951 |
# endif |
1 | 952 |
} |
18252 | 953 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
954 |
%}. |
103 | 955 |
^ self wrongNumberOfArguments:0 |
1 | 956 |
! |
957 |
||
958 |
value:arg |
|
18252 | 959 |
"evaluate the receiver with one argument. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
960 |
The receiver must be a 1-arg block." |
1 | 961 |
|
962 |
%{ /* NOCONTEXT */ |
|
18252 | 963 |
#ifdef __SCHTEAM__ |
964 |
return context.TAILCALL1( self.asSTCallable(), arg ); |
|
965 |
/* NOTREACHED */ |
|
966 |
#else |
|
1 | 967 |
|
968 |
REGISTER OBJFUNC thecode; |
|
969 |
OBJ home; |
|
970 |
||
8913 | 971 |
if (__INST(nargs) == __mkSmallInteger(1)) { |
18252 | 972 |
# if defined(THIS_CONTEXT) |
973 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
974 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
975 |
# endif |
|
976 |
thecode = __BlockInstPtr(self)->b_code; |
|
977 |
# ifdef NEW_BLOCK_CALL |
|
978 |
if (thecode != (OBJFUNC)nil) { |
|
979 |
RETURN ( (*thecode)(self, arg) ); |
|
980 |
} |
|
981 |
/* interpreted code */ |
|
982 |
# ifdef PASS_ARG_POINTER |
|
983 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, &arg) ); |
|
984 |
# else |
|
985 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, arg) ); |
|
986 |
# endif |
|
328 | 987 |
# else |
18252 | 988 |
home = __BlockInstPtr(self)->b_home; |
989 |
if (thecode != (OBJFUNC)nil) { |
|
990 |
RETURN ( (*thecode)(home, arg) ); |
|
991 |
} |
|
992 |
/* interpreted code */ |
|
993 |
# ifdef PASS_ARG_POINTER |
|
994 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, &arg) ); |
|
995 |
# else |
|
996 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, arg) ); |
|
997 |
# endif |
|
328 | 998 |
# endif |
1 | 999 |
} |
18252 | 1000 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1001 |
%}. |
103 | 1002 |
^ self wrongNumberOfArguments:1 |
1 | 1003 |
! |
1004 |
||
11998 | 1005 |
value:arg1 optionalArgument:arg2 |
1006 |
"evaluate the receiver. |
|
1007 |
Optionally pass up one or to two arguments (if the receiver is a one/two arg block)." |
|
1008 |
||
1009 |
nargs == 2 ifTrue:[ |
|
18252 | 1010 |
^ self value:arg1 value:arg2 |
11998 | 1011 |
]. |
1012 |
^ self value:arg1 |
|
1013 |
||
1014 |
" |
|
1015 |
|block| |
|
1016 |
||
1017 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1018 |
block value:2 optionalArgument:3. |
11998 | 1019 |
|
1020 |
block := [:arg1 :arg2 | Transcript show:arg1; space; showCR:arg2 ]. |
|
18252 | 1021 |
block value:2 optionalArgument:3. |
11998 | 1022 |
" |
1023 |
! |
|
1024 |
||
1025 |
value:arg1 optionalArgument:arg2 and:arg3 |
|
1026 |
"evaluate the receiver. |
|
1027 |
Optionally pass up one, two or three arguments (if the receiver is a 1/2/3-arg block)." |
|
1028 |
||
1029 |
nargs == 3 ifTrue:[ |
|
18252 | 1030 |
^ self value:arg1 value:arg2 value:arg3 |
11998 | 1031 |
]. |
1032 |
nargs == 2 ifTrue:[ |
|
18252 | 1033 |
^ self value:arg1 value:arg2 |
11998 | 1034 |
]. |
1035 |
^ self value:arg1 |
|
1036 |
||
1037 |
" |
|
1038 |
|block| |
|
1039 |
||
1040 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1041 |
block value:2 optionalArgument:3. |
11998 | 1042 |
|
1043 |
block := [:arg1 :arg2 | Transcript show:arg1; space; showCR:arg2 ]. |
|
18252 | 1044 |
block value:2 optionalArgument:3. |
11998 | 1045 |
" |
1046 |
! |
|
1047 |
||
1 | 1048 |
value:arg1 value:arg2 |
18252 | 1049 |
"evaluate the receiver with two arguments. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1050 |
The receiver must be a 2-arg block." |
1 | 1051 |
|
1052 |
%{ /* NOCONTEXT */ |
|
18252 | 1053 |
#ifdef __SCHTEAM__ |
1054 |
return context.TAILCALL2( self.asSTCallable(), arg1, arg2 ); |
|
1055 |
/* NOTREACHED */ |
|
1056 |
#else |
|
1 | 1057 |
|
1058 |
REGISTER OBJFUNC thecode; |
|
1059 |
OBJ home; |
|
1060 |
||
8913 | 1061 |
if (__INST(nargs) == __mkSmallInteger(2)) { |
18252 | 1062 |
# if defined(THIS_CONTEXT) |
1063 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1064 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1065 |
# endif |
|
1066 |
thecode = __BlockInstPtr(self)->b_code; |
|
1067 |
# ifdef NEW_BLOCK_CALL |
|
1068 |
if (thecode != (OBJFUNC)nil) { |
|
1069 |
RETURN ( (*thecode)(self, arg1, arg2) ); |
|
1070 |
} |
|
1071 |
# ifdef PASS_ARG_POINTER |
|
1072 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, &arg1) ); |
|
1073 |
# else |
|
1074 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, arg1, arg2) ); |
|
1075 |
# endif |
|
328 | 1076 |
# else |
18252 | 1077 |
home = __BlockInstPtr(self)->b_home; |
1078 |
if (thecode != (OBJFUNC)nil) { |
|
1079 |
RETURN ( (*thecode)(home, arg1, arg2) ); |
|
1080 |
} |
|
1081 |
# ifdef PASS_ARG_POINTER |
|
1082 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, &arg1) ); |
|
1083 |
# else |
|
1084 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, arg1, arg2) ); |
|
1085 |
# endif |
|
328 | 1086 |
# endif |
1 | 1087 |
} |
18252 | 1088 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1089 |
%}. |
103 | 1090 |
^ self wrongNumberOfArguments:2 |
1 | 1091 |
! |
1092 |
||
11998 | 1093 |
value:arg1 value:arg2 optionalArgument:arg3 |
1094 |
"evaluate the receiver. |
|
1095 |
Optionally pass two or threearguments (if the receiver is a 2/3-arg block)." |
|
1096 |
||
1097 |
nargs == 3 ifTrue:[ |
|
18252 | 1098 |
^ self value:arg1 value:arg2 value:arg3 |
11998 | 1099 |
]. |
1100 |
^ self value:arg1 value:arg2 |
|
1101 |
! |
|
1102 |
||
1 | 1103 |
value:arg1 value:arg2 value:arg3 |
18252 | 1104 |
"evaluate the receiver with three arguments. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1105 |
The receiver must be a 3-arg block." |
1 | 1106 |
|
1107 |
%{ /* NOCONTEXT */ |
|
18252 | 1108 |
#ifdef __SCHTEAM__ |
1109 |
return context.TAILCALL3( self.asSTCallable(), arg1, arg2, arg3 ); |
|
1110 |
/* NOTREACHED */ |
|
1111 |
#else |
|
1 | 1112 |
|
1113 |
REGISTER OBJFUNC thecode; |
|
1114 |
OBJ home; |
|
1115 |
||
8913 | 1116 |
if (__INST(nargs) == __mkSmallInteger(3)) { |
18252 | 1117 |
# if defined(THIS_CONTEXT) |
1118 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1119 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1120 |
# endif |
|
1121 |
thecode = __BlockInstPtr(self)->b_code; |
|
1122 |
# ifdef NEW_BLOCK_CALL |
|
1123 |
if (thecode != (OBJFUNC)nil) { |
|
1124 |
RETURN ( (*thecode)(self, arg1, arg2, arg3) ); |
|
1125 |
} |
|
1126 |
# ifdef PASS_ARG_POINTER |
|
1127 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, &arg1) ); |
|
1128 |
# else |
|
1129 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, arg1, arg2, arg3) ); |
|
1130 |
# endif |
|
328 | 1131 |
# else |
18252 | 1132 |
home = __BlockInstPtr(self)->b_home; |
1133 |
if (thecode != (OBJFUNC)nil) { |
|
1134 |
RETURN ( (*thecode)(home, arg1, arg2, arg3) ); |
|
1135 |
} |
|
1136 |
# ifdef PASS_ARG_POINTER |
|
1137 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, &arg1) ); |
|
1138 |
# else |
|
1139 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, arg1, arg2, arg3) ); |
|
1140 |
# endif |
|
328 | 1141 |
# endif |
1 | 1142 |
} |
18252 | 1143 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1144 |
%}. |
103 | 1145 |
^ self wrongNumberOfArguments:3 |
1 | 1146 |
! |
1147 |
||
1148 |
value:arg1 value:arg2 value:arg3 value:arg4 |
|
18252 | 1149 |
"evaluate the receiver with four arguments. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1150 |
The receiver must be a 4-arg block." |
1 | 1151 |
|
1152 |
%{ /* NOCONTEXT */ |
|
18252 | 1153 |
#ifdef __SCHTEAM__ |
1154 |
return context.TAILCALL4( self.asSTCallable(), arg1, arg2, arg3, arg4 ); |
|
1155 |
/* NOTREACHED */ |
|
1156 |
#else |
|
1 | 1157 |
|
1158 |
REGISTER OBJFUNC thecode; |
|
1159 |
OBJ home; |
|
1160 |
||
8913 | 1161 |
if (__INST(nargs) == __mkSmallInteger(4)) { |
18252 | 1162 |
# if defined(THIS_CONTEXT) |
1163 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1164 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1165 |
# endif |
|
1166 |
thecode = __BlockInstPtr(self)->b_code; |
|
1167 |
# ifdef NEW_BLOCK_CALL |
|
1168 |
if (thecode != (OBJFUNC)nil) { |
|
1169 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4) ); |
|
1170 |
} |
|
1171 |
# ifdef PASS_ARG_POINTER |
|
1172 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, &arg1) ); |
|
1173 |
# else |
|
1174 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, arg1, arg2, arg3, arg4) ); |
|
1175 |
# endif |
|
328 | 1176 |
# else |
18252 | 1177 |
home = __BlockInstPtr(self)->b_home; |
1178 |
if (thecode != (OBJFUNC)nil) { |
|
1179 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4) ); |
|
1180 |
} |
|
1181 |
# ifdef PASS_ARG_POINTER |
|
1182 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, &arg1) ); |
|
1183 |
# else |
|
1184 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, arg1, arg2, arg3, arg4) ); |
|
1185 |
# endif |
|
328 | 1186 |
# endif |
18252 | 1187 |
} |
1 | 1188 |
#endif |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1189 |
%}. |
103 | 1190 |
^ self wrongNumberOfArguments:4 |
1 | 1191 |
! |
1192 |
||
1193 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 |
|
18252 | 1194 |
"evaluate the receiver with five arguments. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1195 |
The receiver must be a 5-arg block." |
1 | 1196 |
|
1197 |
%{ /* NOCONTEXT */ |
|
18252 | 1198 |
#ifdef __SCHTEAM__ |
1199 |
return context.TAILCALL5( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5 ); |
|
1200 |
/* NOTREACHED */ |
|
1201 |
#else |
|
1 | 1202 |
|
1203 |
REGISTER OBJFUNC thecode; |
|
1204 |
OBJ home; |
|
1205 |
||
8913 | 1206 |
if (__INST(nargs) == __mkSmallInteger(5)) { |
18252 | 1207 |
# if defined(THIS_CONTEXT) |
1208 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1209 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1210 |
# endif |
|
1211 |
thecode = __BlockInstPtr(self)->b_code; |
|
1212 |
# ifdef NEW_BLOCK_CALL |
|
1213 |
if (thecode != (OBJFUNC)nil) { |
|
1214 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5) ); |
|
1215 |
} |
|
1216 |
# ifdef PASS_ARG_POINTER |
|
1217 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, &arg1) ); |
|
1218 |
# else |
|
1219 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
|
1220 |
# endif |
|
328 | 1221 |
# else |
18252 | 1222 |
home = __BlockInstPtr(self)->b_home; |
1223 |
if (thecode != (OBJFUNC)nil) { |
|
1224 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5) ); |
|
1225 |
} |
|
1226 |
# ifdef PASS_ARG_POINTER |
|
1227 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, &arg1) ); |
|
1228 |
# else |
|
1229 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
|
1230 |
# endif |
|
328 | 1231 |
# endif |
1 | 1232 |
} |
18252 | 1233 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1234 |
%}. |
103 | 1235 |
^ self wrongNumberOfArguments:5 |
1 | 1236 |
! |
1237 |
||
1238 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 |
|
18252 | 1239 |
"evaluate the receiver with six arguments. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1240 |
The receiver must be a 6-arg block." |
1 | 1241 |
|
1242 |
%{ /* NOCONTEXT */ |
|
18252 | 1243 |
#ifdef __SCHTEAM__ |
1244 |
return context.TAILCALL6( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5, arg6 ); |
|
1245 |
/* NOTREACHED */ |
|
1246 |
#else |
|
1 | 1247 |
|
1248 |
REGISTER OBJFUNC thecode; |
|
1249 |
OBJ home; |
|
1250 |
||
8913 | 1251 |
if (__INST(nargs) == __mkSmallInteger(6)) { |
18252 | 1252 |
# if defined(THIS_CONTEXT) |
1253 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1254 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1255 |
# endif |
|
1256 |
thecode = __BlockInstPtr(self)->b_code; |
|
1257 |
# ifdef NEW_BLOCK_CALL |
|
1258 |
if (thecode != (OBJFUNC)nil) { |
|
1259 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1260 |
} |
|
1261 |
# ifdef PASS_ARG_POINTER |
|
1262 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, &arg1) ); |
|
1263 |
# else |
|
1264 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1265 |
# endif |
|
328 | 1266 |
# else |
18252 | 1267 |
home = __BlockInstPtr(self)->b_home; |
1268 |
if (thecode != (OBJFUNC)nil) { |
|
1269 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1270 |
} |
|
1271 |
# ifdef PASS_ARG_POINTER |
|
1272 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, &arg1) ); |
|
1273 |
# else |
|
1274 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1275 |
# endif |
|
328 | 1276 |
# endif |
1 | 1277 |
} |
18252 | 1278 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1279 |
%}. |
103 | 1280 |
^ self wrongNumberOfArguments:6 |
1 | 1281 |
! |
1282 |
||
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1283 |
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
|
1284 |
"evaluate the receiver with seven arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1285 |
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
|
1286 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1287 |
%{ /* NOCONTEXT */ |
18252 | 1288 |
#ifdef __SCHTEAM__ |
1289 |
return context.TAILCALL7( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5, arg6, arg7 ); |
|
1290 |
/* NOTREACHED */ |
|
1291 |
#else |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1292 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1293 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1294 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1295 |
|
8913 | 1296 |
if (__INST(nargs) == __mkSmallInteger(7)) { |
18252 | 1297 |
# if defined(THIS_CONTEXT) |
1298 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1299 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1300 |
# endif |
|
1301 |
thecode = __BlockInstPtr(self)->b_code; |
|
1302 |
# ifdef NEW_BLOCK_CALL |
|
1303 |
if (thecode != (OBJFUNC)nil) { |
|
1304 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1305 |
} |
|
1306 |
# ifdef PASS_ARG_POINTER |
|
1307 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, &arg1) ); |
|
1308 |
# else |
|
1309 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1310 |
# endif |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1311 |
# else |
18252 | 1312 |
home = __BlockInstPtr(self)->b_home; |
1313 |
if (thecode != (OBJFUNC)nil) { |
|
1314 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1315 |
} |
|
1316 |
# ifdef PASS_ARG_POINTER |
|
1317 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, &arg1) ); |
|
1318 |
# else |
|
1319 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1320 |
# endif |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1321 |
# endif |
18252 | 1322 |
} |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1323 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1324 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1325 |
^ self wrongNumberOfArguments:7 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1326 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1327 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1328 |
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
|
1329 |
"evaluate the receiver with eight arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1330 |
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
|
1331 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1332 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1333 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1334 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1335 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1336 |
|
8913 | 1337 |
if (__INST(nargs) == __mkSmallInteger(8)) { |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1338 |
#if defined(THIS_CONTEXT) |
18252 | 1339 |
if (__ISVALID_ILC_LNO(__pilc)) |
1340 |
__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
|
1341 |
#endif |
18252 | 1342 |
thecode = __BlockInstPtr(self)->b_code; |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1343 |
#ifdef NEW_BLOCK_CALL |
18252 | 1344 |
if (thecode != (OBJFUNC)nil) { |
1345 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
1346 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1347 |
# ifdef PASS_ARG_POINTER |
18252 | 1348 |
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
|
1349 |
# else |
18252 | 1350 |
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
|
1351 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1352 |
#else |
18252 | 1353 |
home = __BlockInstPtr(self)->b_home; |
1354 |
if (thecode != (OBJFUNC)nil) { |
|
1355 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
1356 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1357 |
# ifdef PASS_ARG_POINTER |
18252 | 1358 |
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
|
1359 |
# else |
18252 | 1360 |
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
|
1361 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1362 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1363 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1364 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1365 |
^ self wrongNumberOfArguments:8 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1366 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1367 |
|
11588 | 1368 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 |
11603 | 1369 |
"evaluate the receiver with 9 arguments. |
1370 |
The receiver must be a 9-arg block." |
|
11588 | 1371 |
|
1372 |
%{ /* NOCONTEXT */ |
|
1373 |
||
1374 |
REGISTER OBJFUNC thecode; |
|
1375 |
OBJ home; |
|
1376 |
||
1377 |
if (__INST(nargs) == __mkSmallInteger(9)) { |
|
1378 |
#if defined(THIS_CONTEXT) |
|
18252 | 1379 |
if (__ISVALID_ILC_LNO(__pilc)) |
1380 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11588 | 1381 |
#endif |
18252 | 1382 |
thecode = __BlockInstPtr(self)->b_code; |
11588 | 1383 |
#ifdef NEW_BLOCK_CALL |
18252 | 1384 |
if (thecode != (OBJFUNC)nil) { |
1385 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
|
1386 |
} |
|
11588 | 1387 |
# ifdef PASS_ARG_POINTER |
18252 | 1388 |
RETURN ( __interpret(self, 9, nil, nil, nil, nil, &arg1) ); |
11588 | 1389 |
# else |
18252 | 1390 |
RETURN ( __interpret(self, 9, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
11588 | 1391 |
# endif |
1392 |
#else |
|
18252 | 1393 |
home = __BlockInstPtr(self)->b_home; |
1394 |
if (thecode != (OBJFUNC)nil) { |
|
1395 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
|
1396 |
} |
|
11588 | 1397 |
# ifdef PASS_ARG_POINTER |
18252 | 1398 |
RETURN ( __interpret(self, 9, nil, home, nil, nil, &arg1) ); |
11588 | 1399 |
# else |
18252 | 1400 |
RETURN ( __interpret(self, 9, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
11588 | 1401 |
# endif |
1402 |
#endif |
|
1403 |
} |
|
1404 |
%}. |
|
1405 |
^ self wrongNumberOfArguments:9 |
|
1406 |
! |
|
1407 |
||
1408 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 value:arg10 |
|
11603 | 1409 |
"evaluate the receiver with 10 arguments. |
11588 | 1410 |
The receiver must be a 10-arg block." |
1411 |
||
1412 |
%{ /* NOCONTEXT */ |
|
1413 |
||
1414 |
REGISTER OBJFUNC thecode; |
|
1415 |
OBJ home; |
|
1416 |
||
1417 |
if (__INST(nargs) == __mkSmallInteger(10)) { |
|
1418 |
#if defined(THIS_CONTEXT) |
|
18252 | 1419 |
if (__ISVALID_ILC_LNO(__pilc)) |
1420 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11588 | 1421 |
#endif |
18252 | 1422 |
thecode = __BlockInstPtr(self)->b_code; |
11588 | 1423 |
#ifdef NEW_BLOCK_CALL |
18252 | 1424 |
if (thecode != (OBJFUNC)nil) { |
1425 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
|
1426 |
} |
|
11588 | 1427 |
# ifdef PASS_ARG_POINTER |
18252 | 1428 |
RETURN ( __interpret(self, 10, nil, nil, nil, nil, &arg1) ); |
11588 | 1429 |
# else |
18252 | 1430 |
RETURN ( __interpret(self, 10, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
11588 | 1431 |
# endif |
1432 |
#else |
|
18252 | 1433 |
home = __BlockInstPtr(self)->b_home; |
1434 |
if (thecode != (OBJFUNC)nil) { |
|
1435 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
|
1436 |
} |
|
11588 | 1437 |
# ifdef PASS_ARG_POINTER |
18252 | 1438 |
RETURN ( __interpret(self, 10, nil, home, nil, nil, &arg1) ); |
11588 | 1439 |
# else |
18252 | 1440 |
RETURN ( __interpret(self, 10, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
11588 | 1441 |
# endif |
1442 |
#endif |
|
1443 |
} |
|
1444 |
%}. |
|
1445 |
^ self wrongNumberOfArguments:10 |
|
1446 |
! |
|
1447 |
||
1448 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 value:arg10 value:arg11 |
|
11603 | 1449 |
"evaluate the receiver with 11 arguments. |
1450 |
The receiver must be a 11-arg block." |
|
11588 | 1451 |
|
1452 |
%{ /* NOCONTEXT */ |
|
1453 |
||
1454 |
REGISTER OBJFUNC thecode; |
|
1455 |
OBJ home; |
|
1456 |
||
1457 |
if (__INST(nargs) == __mkSmallInteger(11)) { |
|
1458 |
#if defined(THIS_CONTEXT) |
|
18252 | 1459 |
if (__ISVALID_ILC_LNO(__pilc)) |
1460 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11588 | 1461 |
#endif |
18252 | 1462 |
thecode = __BlockInstPtr(self)->b_code; |
11588 | 1463 |
#ifdef NEW_BLOCK_CALL |
18252 | 1464 |
if (thecode != (OBJFUNC)nil) { |
1465 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
|
1466 |
} |
|
11588 | 1467 |
# ifdef PASS_ARG_POINTER |
18252 | 1468 |
RETURN ( __interpret(self, 11, nil, nil, nil, nil, &arg1) ); |
11588 | 1469 |
# else |
18252 | 1470 |
RETURN ( __interpret(self, 11, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
11588 | 1471 |
# endif |
1472 |
#else |
|
18252 | 1473 |
home = __BlockInstPtr(self)->b_home; |
1474 |
if (thecode != (OBJFUNC)nil) { |
|
1475 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
|
1476 |
} |
|
11588 | 1477 |
# ifdef PASS_ARG_POINTER |
18252 | 1478 |
RETURN ( __interpret(self, 11, nil, home, nil, nil, &arg1) ); |
11588 | 1479 |
# else |
18252 | 1480 |
RETURN ( __interpret(self, 11, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
11588 | 1481 |
# endif |
1482 |
#endif |
|
1483 |
} |
|
1484 |
%}. |
|
1485 |
^ self wrongNumberOfArguments:11 |
|
1486 |
! |
|
1487 |
||
11603 | 1488 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 value:arg10 value:arg11 value:arg12 |
1489 |
"evaluate the receiver with 12 arguments. |
|
1490 |
The receiver must be a 12-arg block." |
|
1491 |
||
1492 |
%{ /* NOCONTEXT */ |
|
1493 |
||
1494 |
REGISTER OBJFUNC thecode; |
|
1495 |
OBJ home; |
|
1496 |
||
1497 |
if (__INST(nargs) == __mkSmallInteger(12)) { |
|
1498 |
#if defined(THIS_CONTEXT) |
|
18252 | 1499 |
if (__ISVALID_ILC_LNO(__pilc)) |
1500 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11603 | 1501 |
#endif |
18252 | 1502 |
thecode = __BlockInstPtr(self)->b_code; |
11603 | 1503 |
#ifdef NEW_BLOCK_CALL |
18252 | 1504 |
if (thecode != (OBJFUNC)nil) { |
1505 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
|
1506 |
} |
|
11603 | 1507 |
# ifdef PASS_ARG_POINTER |
18252 | 1508 |
RETURN ( __interpret(self, 12, nil, nil, nil, nil, &arg1) ); |
11603 | 1509 |
# else |
18252 | 1510 |
RETURN ( __interpret(self, 12, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
11603 | 1511 |
# endif |
1512 |
#else |
|
18252 | 1513 |
home = __BlockInstPtr(self)->b_home; |
1514 |
if (thecode != (OBJFUNC)nil) { |
|
1515 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
|
1516 |
} |
|
11603 | 1517 |
# ifdef PASS_ARG_POINTER |
18252 | 1518 |
RETURN ( __interpret(self, 12, nil, home, nil, nil, &arg1) ); |
11603 | 1519 |
# else |
18252 | 1520 |
RETURN ( __interpret(self, 12, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
11603 | 1521 |
# endif |
1522 |
#endif |
|
1523 |
} |
|
1524 |
%}. |
|
1525 |
^ self wrongNumberOfArguments:12 |
|
1526 |
! |
|
1527 |
||
3688 | 1528 |
valueAt:priority |
1529 |
"evaluate the receiver, at the given prioriy; |
|
11998 | 1530 |
i.e. change the priority for the execution of the receiver. |
1531 |
Bad name: should be called evaluateWithPriority: or similar" |
|
3688 | 1532 |
|
9042 | 1533 |
|oldPrio retVal activeProcess| |
1534 |
||
1535 |
activeProcess := Processor activeProcess. |
|
3688 | 1536 |
oldPrio := Processor activePriority. |
1537 |
[ |
|
18252 | 1538 |
activeProcess priority:priority. |
1539 |
retVal := self value. |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
1540 |
] ensure:[ |
18252 | 1541 |
activeProcess priority:oldPrio |
3688 | 1542 |
]. |
1543 |
^ retVal |
|
1544 |
||
1545 |
" |
|
1546 |
[ |
|
18252 | 1547 |
1000 timesRepeat:[ |
1548 |
1000 factorial |
|
1549 |
] |
|
3688 | 1550 |
] valueAt:3 |
1551 |
" |
|
1552 |
||
1553 |
"Created: / 29.7.1998 / 19:19:48 / cg" |
|
1554 |
! |
|
1555 |
||
18993 | 1556 |
valueWithArguments:argArrayIn |
1 | 1557 |
"evaluate the receiver with arguments taken from argArray. |
313 | 1558 |
ArgArray must be either an Array or nil. |
1 | 1559 |
The size of the argArray must match the number of arguments the receiver expects." |
1560 |
||
18993 | 1561 |
|argArray a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
1562 |
||
1563 |
argArray := argArrayIn. |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1564 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
18993 | 1565 |
argArray isCollection ifTrue:[ |
1566 |
argArray := argArray asArray |
|
1567 |
] ifFalse:[ |
|
1568 |
^ self badArgumentArray:argArray |
|
1569 |
]. |
|
1 | 1570 |
]. |
18993 | 1571 |
(argArray size ~~ nargs) ifTrue:[ |
1572 |
^ self wrongNumberOfArguments:argArray size |
|
1 | 1573 |
]. |
18993 | 1574 |
|
1 | 1575 |
%{ |
1576 |
REGISTER OBJFUNC thecode; |
|
1577 |
OBJ home; |
|
67 | 1578 |
REGISTER OBJ *ap; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1579 |
OBJ nA; |
1 | 1580 |
|
1581 |
#if defined(THIS_CONTEXT) |
|
328 | 1582 |
if (__ISVALID_ILC_LNO(__pilc)) |
18993 | 1583 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 1584 |
#endif |
1133 | 1585 |
thecode = __BlockInstPtr(self)->b_code; |
1037 | 1586 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1587 |
nA = __INST(nargs); |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1588 |
|
1037 | 1589 |
#ifndef NEW_BLOCK_CALL |
1133 | 1590 |
home = __BlockInstPtr(self)->b_home; |
1037 | 1591 |
if (thecode != (OBJFUNC)nil) { |
18993 | 1592 |
/* the most common case (0 args) here (without a switch) */ |
1593 |
||
1594 |
if (nA == __mkSmallInteger(0)) { |
|
1595 |
RETURN ( (*thecode)(home) ); |
|
1596 |
} |
|
1597 |
||
1598 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
|
1599 |
switch ((INT)(nA)) { |
|
1600 |
default: |
|
1601 |
goto error; |
|
1602 |
case (INT)__mkSmallInteger(15): |
|
1603 |
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], ap[12], ap[13], ap[14]) ); |
|
1604 |
case (INT)__mkSmallInteger(14): |
|
1605 |
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], ap[12], ap[13]) ); |
|
1606 |
case (INT)__mkSmallInteger(13): |
|
1607 |
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], ap[12]) ); |
|
1608 |
case (INT)__mkSmallInteger(12): |
|
1609 |
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]) ); |
|
1610 |
case (INT)__mkSmallInteger(11): |
|
1611 |
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]) ); |
|
1612 |
case (INT)__mkSmallInteger(10): |
|
1613 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) ); |
|
1614 |
case (INT)__mkSmallInteger(9): |
|
1615 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) ); |
|
1616 |
case (INT)__mkSmallInteger(8): |
|
1617 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
|
1618 |
case (INT)__mkSmallInteger(7): |
|
1619 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
1620 |
case (INT)__mkSmallInteger(6): |
|
1621 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
1622 |
case (INT)__mkSmallInteger(5): |
|
1623 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1624 |
case (INT)__mkSmallInteger(4): |
|
1625 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) ); |
|
1626 |
case (INT)__mkSmallInteger(3): |
|
1627 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) ); |
|
1628 |
case (INT)__mkSmallInteger(2): |
|
1629 |
RETURN ( (*thecode)(home, ap[0], ap[1]) ); |
|
1630 |
case (INT)__mkSmallInteger(1): |
|
1631 |
RETURN ( (*thecode)(home, ap[0]) ); |
|
1632 |
case (INT)__mkSmallInteger(0): |
|
1633 |
RETURN ( (*thecode)(home) ); |
|
1634 |
break; |
|
1635 |
} |
|
1037 | 1636 |
} |
1637 |
#endif |
|
1638 |
||
8913 | 1639 |
if (nA != __mkSmallInteger(0)) { |
18993 | 1640 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
1641 |
switch ((INT)nA) { |
|
1642 |
default: |
|
1643 |
goto error; |
|
1644 |
case (INT)__mkSmallInteger(15): |
|
1645 |
a15 = ap[14]; |
|
1646 |
case (INT)__mkSmallInteger(14): |
|
1647 |
a14 = ap[13]; |
|
1648 |
case (INT)__mkSmallInteger(13): |
|
1649 |
a13 = ap[12]; |
|
1650 |
case (INT)__mkSmallInteger(12): |
|
1651 |
a12 = ap[11]; |
|
1652 |
case (INT)__mkSmallInteger(11): |
|
1653 |
a11 = ap[10]; |
|
1654 |
case (INT)__mkSmallInteger(10): |
|
1655 |
a10 = ap[9]; |
|
1656 |
case (INT)__mkSmallInteger(9): |
|
1657 |
a9 = ap[8]; |
|
1658 |
case (INT)__mkSmallInteger(8): |
|
1659 |
a8 = ap[7]; |
|
1660 |
case (INT)__mkSmallInteger(7): |
|
1661 |
a7 = ap[6]; |
|
1662 |
case (INT)__mkSmallInteger(6): |
|
1663 |
a6 = ap[5]; |
|
1664 |
case (INT)__mkSmallInteger(5): |
|
1665 |
a5 = ap[4]; |
|
1666 |
case (INT)__mkSmallInteger(4): |
|
1667 |
a4 = ap[3]; |
|
1668 |
case (INT)__mkSmallInteger(3): |
|
1669 |
a3 = ap[2]; |
|
1670 |
case (INT)__mkSmallInteger(2): |
|
1671 |
a2 = ap[1]; |
|
1672 |
case (INT)__mkSmallInteger(1): |
|
1673 |
a1 = ap[0]; |
|
1674 |
case (INT)__mkSmallInteger(0): |
|
1675 |
break; |
|
1676 |
} |
|
1 | 1677 |
} |
1133 | 1678 |
|
11 | 1679 |
#ifdef NEW_BLOCK_CALL |
1 | 1680 |
if (thecode != (OBJFUNC)nil) { |
18993 | 1681 |
RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
11 | 1682 |
} |
328 | 1683 |
# ifdef PASS_ARG_POINTER |
6553
ce4ca4df3415
oops - last modification created a little bug.
Claus Gittinger <cg@exept.de>
parents:
6512
diff
changeset
|
1684 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) ); |
328 | 1685 |
# else |
8009 | 1686 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
328 | 1687 |
# endif |
1037 | 1688 |
|
1 | 1689 |
#else |
1037 | 1690 |
|
328 | 1691 |
# ifdef PASS_ARG_POINTER |
6553
ce4ca4df3415
oops - last modification created a little bug.
Claus Gittinger <cg@exept.de>
parents:
6512
diff
changeset
|
1692 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, &a1) ); |
328 | 1693 |
# else |
8009 | 1694 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
328 | 1695 |
# endif |
1037 | 1696 |
|
1 | 1697 |
#endif |
67 | 1698 |
|
11 | 1699 |
error: ; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1700 |
%}. |
138 | 1701 |
" |
8009 | 1702 |
the above code only supports up-to 15 arguments |
138 | 1703 |
" |
7602
d048f13cd50a
Exception classes initialize themself.
Stefan Vogel <sv@exept.de>
parents:
7352
diff
changeset
|
1704 |
^ ArgumentError |
18993 | 1705 |
raiseRequestWith:self |
1706 |
errorString:'only blocks with up-to 15 arguments supported' |
|
1707 |
||
1708 |
" |
|
1709 |
[:a :b :c | Transcript showCR:a; showCR:b; showCR:c] valueWithArguments:#(1 2 3). |
|
1710 |
[:a :b :c | Transcript showCR:a; showCR:b; showCR:c] valueWithArguments:#(1 2 3) asOrderedCollection. |
|
1711 |
" |
|
6317 | 1712 |
! |
1713 |
||
1714 |
valueWithOptionalArgument:arg |
|
1715 |
"evaluate the receiver. |
|
6318 | 1716 |
Optionally pass an argument (if the receiver is a one arg block)." |
6317 | 1717 |
|
6628
4d693c525443
#handlerForSignal:context:originator:
Stefan Vogel <sv@exept.de>
parents:
6611
diff
changeset
|
1718 |
nargs == 1 ifTrue:[ |
18252 | 1719 |
^ self value:arg |
6317 | 1720 |
]. |
1721 |
^ self value |
|
6320 | 1722 |
|
1723 |
" |
|
1724 |
|block| |
|
1725 |
||
1726 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1727 |
block valueWithOptionalArgument:2. |
6320 | 1728 |
|
1729 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1730 |
block valueWithOptionalArgument:2. |
6320 | 1731 |
" |
6785 | 1732 |
! |
1733 |
||
1734 |
valueWithOptionalArgument:arg1 and:arg2 |
|
1735 |
"evaluate the receiver. |
|
1736 |
Optionally pass up to two arguments (if the receiver is a one/two arg block)." |
|
1737 |
||
1738 |
nargs == 2 ifTrue:[ |
|
18252 | 1739 |
^ self value:arg1 value:arg2 |
6785 | 1740 |
]. |
1741 |
nargs == 1 ifTrue:[ |
|
18252 | 1742 |
^ self value:arg1 |
6785 | 1743 |
]. |
1744 |
^ self value |
|
1745 |
||
1746 |
" |
|
1747 |
|block| |
|
1748 |
||
1749 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1750 |
block valueWithOptionalArgument:2. |
6785 | 1751 |
|
1752 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1753 |
block valueWithOptionalArgument:2. |
6785 | 1754 |
|
1755 |
block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ]. |
|
18252 | 1756 |
block valueWithOptionalArgument:10 and:20. |
6785 | 1757 |
" |
9010 | 1758 |
! |
1759 |
||
1760 |
valueWithOptionalArgument:arg1 and:arg2 and:arg3 |
|
1761 |
"evaluate the receiver. |
|
1762 |
Optionally pass up to three arguments (if the receiver is a one/two/three arg block)." |
|
1763 |
||
1764 |
nargs == 3 ifTrue:[ |
|
18252 | 1765 |
^ self value:arg1 value:arg2 value:arg3 |
9010 | 1766 |
]. |
1767 |
nargs == 2 ifTrue:[ |
|
18252 | 1768 |
^ self value:arg1 value:arg2 |
9010 | 1769 |
]. |
1770 |
nargs == 1 ifTrue:[ |
|
18252 | 1771 |
^ self value:arg1 |
9010 | 1772 |
]. |
1773 |
^ self value |
|
1774 |
||
1775 |
" |
|
1776 |
|block| |
|
1777 |
||
1778 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1779 |
block valueWithOptionalArgument:2. |
9010 | 1780 |
|
1781 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1782 |
block valueWithOptionalArgument:2. |
9010 | 1783 |
|
1784 |
block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ]. |
|
18252 | 1785 |
block valueWithOptionalArgument:10 and:20. |
9010 | 1786 |
" |
1787 |
! |
|
1788 |
||
1789 |
valueWithOptionalArgument:arg1 and:arg2 and:arg3 and:arg4 |
|
1790 |
"evaluate the receiver. |
|
1791 |
Optionally pass up to four arguments (if the receiver is a one/two/three/four arg block)." |
|
1792 |
||
1793 |
nargs == 4 ifTrue:[ |
|
18252 | 1794 |
^ self value:arg1 value:arg2 value:arg3 value:arg4 |
9010 | 1795 |
]. |
1796 |
nargs == 3 ifTrue:[ |
|
18252 | 1797 |
^ self value:arg1 value:arg2 value:arg3 |
9010 | 1798 |
]. |
1799 |
nargs == 2 ifTrue:[ |
|
18252 | 1800 |
^ self value:arg1 value:arg2 |
9010 | 1801 |
]. |
1802 |
nargs == 1 ifTrue:[ |
|
18252 | 1803 |
^ self value:arg1 |
9010 | 1804 |
]. |
1805 |
^ self value |
|
1806 |
||
1807 |
" |
|
1808 |
|block| |
|
1809 |
||
1810 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1811 |
block valueWithOptionalArgument:2. |
9010 | 1812 |
|
1813 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1814 |
block valueWithOptionalArgument:2. |
9010 | 1815 |
|
1816 |
block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ]. |
|
18252 | 1817 |
block valueWithOptionalArgument:10 and:20. |
9010 | 1818 |
" |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1819 |
! |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1820 |
|
18992 | 1821 |
valueWithOptionalArguments:argArrayIn |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1822 |
"evaluate the receiver with arguments as required taken from argArray. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1823 |
Only the required number of arguments is taken from argArray or nil; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1824 |
(i.e. argArray may be larger than the required number). |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1825 |
If the size of the argArray is smaller than the number of arguments, an error is raised." |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1826 |
|
18992 | 1827 |
|argArray numArgsProvided a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
1828 |
||
1829 |
argArray := argArrayIn. |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1830 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
18992 | 1831 |
argArray isCollection ifTrue:[ |
1832 |
argArray := argArray asArray |
|
1833 |
] ifFalse:[ |
|
1834 |
^ self badArgumentArray:argArray |
|
1835 |
]. |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1836 |
]. |
18992 | 1837 |
|
1838 |
(argArray size < nargs) ifTrue:[ |
|
1839 |
^ self wrongNumberOfArguments:argArray size |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1840 |
]. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1841 |
%{ |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1842 |
REGISTER OBJFUNC thecode; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1843 |
OBJ home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1844 |
REGISTER OBJ *ap; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1845 |
OBJ nA; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1846 |
int __numArgsProvided = __intVal(numArgsProvided); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1847 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1848 |
#if defined(THIS_CONTEXT) |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1849 |
if (__ISVALID_ILC_LNO(__pilc)) |
18992 | 1850 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1851 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1852 |
thecode = __BlockInstPtr(self)->b_code; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1853 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1854 |
nA = __INST(nargs); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1855 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1856 |
if (argArray == nil) { |
18992 | 1857 |
ap = 0; |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1858 |
} else { |
18992 | 1859 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1860 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1861 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1862 |
#ifndef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1863 |
home = __BlockInstPtr(self)->b_home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1864 |
if (thecode != (OBJFUNC)nil) { |
18992 | 1865 |
/* the most common case (0 args) here (without a switch) */ |
1866 |
||
1867 |
if (nA == __mkSmallInteger(0)) { |
|
1868 |
RETURN ( (*thecode)(home) ); |
|
1869 |
} |
|
1870 |
||
1871 |
switch ((INT)(nA)) { |
|
1872 |
default: |
|
1873 |
goto error; |
|
1874 |
case (INT)__mkSmallInteger(15): |
|
1875 |
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], ap[12], ap[13], ap[14]) ); |
|
1876 |
case (INT)__mkSmallInteger(14): |
|
1877 |
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], ap[12], ap[13]) ); |
|
1878 |
case (INT)__mkSmallInteger(13): |
|
1879 |
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], ap[12]) ); |
|
1880 |
case (INT)__mkSmallInteger(12): |
|
1881 |
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]) ); |
|
1882 |
case (INT)__mkSmallInteger(11): |
|
1883 |
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]) ); |
|
1884 |
case (INT)__mkSmallInteger(10): |
|
1885 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) ); |
|
1886 |
case (INT)__mkSmallInteger(9): |
|
1887 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) ); |
|
1888 |
case (INT)__mkSmallInteger(8): |
|
1889 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
|
1890 |
case (INT)__mkSmallInteger(7): |
|
1891 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
1892 |
case (INT)__mkSmallInteger(6): |
|
1893 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
1894 |
case (INT)__mkSmallInteger(5): |
|
1895 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1896 |
case (INT)__mkSmallInteger(4): |
|
1897 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) ); |
|
1898 |
case (INT)__mkSmallInteger(3): |
|
1899 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) ); |
|
1900 |
case (INT)__mkSmallInteger(2): |
|
1901 |
RETURN ( (*thecode)(home, ap[0], ap[1]) ); |
|
1902 |
case (INT)__mkSmallInteger(1): |
|
1903 |
RETURN ( (*thecode)(home, ap[0]) ); |
|
1904 |
case (INT)__mkSmallInteger(0): |
|
1905 |
RETURN ( (*thecode)(home) ); |
|
1906 |
break; |
|
1907 |
} |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1908 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1909 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1910 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1911 |
if (nA != __mkSmallInteger(0)) { |
18992 | 1912 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
1913 |
switch ((INT)nA) { |
|
1914 |
default: |
|
1915 |
goto error; |
|
1916 |
case (INT)__mkSmallInteger(15): |
|
1917 |
a15 = ap[14]; |
|
1918 |
case (INT)__mkSmallInteger(14): |
|
1919 |
a14 = ap[13]; |
|
1920 |
case (INT)__mkSmallInteger(13): |
|
1921 |
a13 = ap[12]; |
|
1922 |
case (INT)__mkSmallInteger(12): |
|
1923 |
a12 = ap[11]; |
|
1924 |
case (INT)__mkSmallInteger(11): |
|
1925 |
a11 = ap[10]; |
|
1926 |
case (INT)__mkSmallInteger(10): |
|
1927 |
a10 = ap[9]; |
|
1928 |
case (INT)__mkSmallInteger(9): |
|
1929 |
a9 = ap[8]; |
|
1930 |
case (INT)__mkSmallInteger(8): |
|
1931 |
a8 = ap[7]; |
|
1932 |
case (INT)__mkSmallInteger(7): |
|
1933 |
a7 = ap[6]; |
|
1934 |
case (INT)__mkSmallInteger(6): |
|
1935 |
a6 = ap[5]; |
|
1936 |
case (INT)__mkSmallInteger(5): |
|
1937 |
a5 = ap[4]; |
|
1938 |
case (INT)__mkSmallInteger(4): |
|
1939 |
a4 = ap[3]; |
|
1940 |
case (INT)__mkSmallInteger(3): |
|
1941 |
a3 = ap[2]; |
|
1942 |
case (INT)__mkSmallInteger(2): |
|
1943 |
a2 = ap[1]; |
|
1944 |
case (INT)__mkSmallInteger(1): |
|
1945 |
a1 = ap[0]; |
|
1946 |
case (INT)__mkSmallInteger(0): |
|
1947 |
break; |
|
1948 |
} |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1949 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1950 |
#ifdef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1951 |
if (thecode != (OBJFUNC)nil) { |
18992 | 1952 |
RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1953 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1954 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1955 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1956 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1957 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1958 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1959 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1960 |
#else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1961 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1962 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1963 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1964 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1965 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1966 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1967 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1968 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1969 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1970 |
error: ; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1971 |
%}. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1972 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1973 |
the above code only supports up-to 15 arguments |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1974 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1975 |
^ ArgumentError |
18992 | 1976 |
raiseRequestWith:self |
1977 |
errorString:'only blocks with up-to 15 arguments supported' |
|
1978 |
||
1979 |
||
1980 |
" |
|
1981 |
[:a :b :c | Transcript showCR:a; showCR:b; showCR:c] valueWithOptionalArguments:#(1 2 3 4). |
|
1982 |
[:a :b :c | Transcript showCR:a; showCR:b; showCR:c] valueWithOptionalArguments:#(1 2 3 4) asOrderedCollection. |
|
1983 |
" |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1984 |
! |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1985 |
|
18992 | 1986 |
valueWithPossibleArguments:argArrayIn |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1987 |
"evaluate the receiver with arguments as required taken from argArray. |
18252 | 1988 |
If argArray provides less than the required number of arguments, |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1989 |
nil is assumed for any remaining argument. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1990 |
(i.e. argArray may be smaller than the required number). |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1991 |
Only the required number of arguments is taken from argArray or nil; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1992 |
(i.e. argArray may be larger than the required number)." |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1993 |
|
18992 | 1994 |
|argArray numArgsProvided a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
1995 |
||
1996 |
argArray := argArrayIn. |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1997 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
18992 | 1998 |
argArray isCollection ifTrue:[ |
1999 |
argArray := argArray asArray |
|
2000 |
] ifFalse:[ |
|
2001 |
^ self badArgumentArray:argArray |
|
2002 |
]. |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2003 |
]. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2004 |
numArgsProvided := argArray size. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2005 |
%{ |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2006 |
REGISTER OBJFUNC thecode; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2007 |
OBJ home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2008 |
REGISTER OBJ *ap; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2009 |
OBJ nA; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2010 |
int __numArgsProvided = __intVal(numArgsProvided); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2011 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2012 |
#if defined(THIS_CONTEXT) |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2013 |
if (__ISVALID_ILC_LNO(__pilc)) |
18992 | 2014 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2015 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2016 |
thecode = __BlockInstPtr(self)->b_code; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2017 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2018 |
nA = __INST(nargs); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2019 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2020 |
if (argArray == nil) { |
18992 | 2021 |
ap = 0; |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2022 |
} else { |
18992 | 2023 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2024 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2025 |
switch (__numArgsProvided) { |
18992 | 2026 |
default: |
2027 |
case 15: a15 = ap[14]; |
|
2028 |
case 14: a14 = ap[13]; |
|
2029 |
case 13: a13 = ap[12]; |
|
2030 |
case 12: a12 = ap[11]; |
|
2031 |
case 11: a11 = ap[10]; |
|
2032 |
case 10: a10 = ap[9]; |
|
2033 |
case 9: a9 = ap[8]; |
|
2034 |
case 8: a8 = ap[7]; |
|
2035 |
case 7: a7 = ap[6]; |
|
2036 |
case 6: a6 = ap[5]; |
|
2037 |
case 5: a5 = ap[4]; |
|
2038 |
case 4: a4 = ap[3]; |
|
2039 |
case 3: a3 = ap[2]; |
|
2040 |
case 2: a2 = ap[1]; |
|
2041 |
case 1: a1 = ap[0]; |
|
2042 |
case 0: ; |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2043 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2044 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2045 |
#ifndef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2046 |
home = __BlockInstPtr(self)->b_home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2047 |
if (thecode != (OBJFUNC)nil) { |
18992 | 2048 |
/* the most common case (0 args) here (without a switch) */ |
2049 |
||
2050 |
if (nA == __mkSmallInteger(0)) { |
|
2051 |
RETURN ( (*thecode)(home) ); |
|
2052 |
} |
|
2053 |
||
2054 |
switch ((INT)(nA)) { |
|
2055 |
default: |
|
2056 |
goto error; |
|
2057 |
case (INT)__mkSmallInteger(15): |
|
2058 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
|
2059 |
case (INT)__mkSmallInteger(14): |
|
2060 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) ); |
|
2061 |
case (INT)__mkSmallInteger(13): |
|
2062 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) ); |
|
2063 |
case (INT)__mkSmallInteger(12): |
|
2064 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
|
2065 |
case (INT)__mkSmallInteger(11): |
|
2066 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) ); |
|
2067 |
case (INT)__mkSmallInteger(10): |
|
2068 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) ); |
|
2069 |
case (INT)__mkSmallInteger(9): |
|
2070 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9) ); |
|
2071 |
case (INT)__mkSmallInteger(8): |
|
2072 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8) ); |
|
2073 |
case (INT)__mkSmallInteger(7): |
|
2074 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7) ); |
|
2075 |
case (INT)__mkSmallInteger(6): |
|
2076 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6) ); |
|
2077 |
case (INT)__mkSmallInteger(5): |
|
2078 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5) ); |
|
2079 |
case (INT)__mkSmallInteger(4): |
|
2080 |
RETURN ( (*thecode)(home, a1, a2, a3, a4) ); |
|
2081 |
case (INT)__mkSmallInteger(3): |
|
2082 |
RETURN ( (*thecode)(home, a1, a2, a3) ); |
|
2083 |
case (INT)__mkSmallInteger(2): |
|
2084 |
RETURN ( (*thecode)(home, a1, a2) ); |
|
2085 |
case (INT)__mkSmallInteger(1): |
|
2086 |
RETURN ( (*thecode)(home, a1) ); |
|
2087 |
case (INT)__mkSmallInteger(0): |
|
2088 |
RETURN ( (*thecode)(home) ); |
|
2089 |
break; |
|
2090 |
} |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2091 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2092 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2093 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2094 |
#ifdef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2095 |
if (thecode != (OBJFUNC)nil) { |
18992 | 2096 |
RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2097 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2098 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2099 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2100 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2101 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2102 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2103 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2104 |
#else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2105 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2106 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2107 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2108 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2109 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2110 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2111 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2112 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2113 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2114 |
error: ; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2115 |
%}. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2116 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2117 |
the above code only supports up-to 15 arguments |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2118 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2119 |
^ ArgumentError |
18992 | 2120 |
raiseRequestWith:self |
2121 |
errorString:'only blocks with up-to 15 arguments supported' |
|
2122 |
||
2123 |
" |
|
2124 |
[:a :b :c :d| Transcript showCR:a; showCR:b; showCR:c; showCR:d] valueWithPossibleArguments:#(1 2 3). |
|
20178 | 2125 |
[:a :b :c :d| Transcript showCR:a; showCR:b; showCR:c; showCR:d] valueWithPossibleArguments:#(1 2 3 4 5). |
18992 | 2126 |
[:a :b :c :d| Transcript showCR:a; showCR:b; showCR:c; showCR:d] valueWithPossibleArguments:#(1 2 3) asOrderedCollection. |
2127 |
" |
|
154 | 2128 |
! ! |
2129 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2130 |
!Block methodsFor:'exception handling'! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2131 |
|
6512 | 2132 |
on:aSignalOrSignalSetOrException do:exceptionBlock |
2133 |
"added for ANSI compatibility; evaluate the receiver, |
|
18252 | 2134 |
handling aSignalOrSignalSetOrException. |
18316 | 2135 |
If the signal is raised during evaluation, |
2136 |
the 2nd argument, exceptionBlock is evaluated (and its value returned" |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2137 |
|
4542
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
2138 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2139 |
<exception: #handle> |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2140 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2141 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2142 |
^ 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
|
2143 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2144 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2145 |
[ |
18316 | 2146 |
1 foo |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2147 |
] on:MessageNotUnderstood do:[:ex | self halt] |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2148 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2149 |
[ |
18316 | 2150 |
1 foo |
6512 | 2151 |
] on:(MessageNotUnderstood , AbortOperationRequest) do:[:ex | self halt] |
2152 |
||
2153 |
[ |
|
18316 | 2154 |
1 foo |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2155 |
] on:SignalSet anySignal do:[:ex| 2 bar. self halt] |
18316 | 2156 |
|
2157 |
[ |
|
2158 |
1 foo |
|
2159 |
] on:Error do:[:ex| 2 ] |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2160 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2161 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2162 |
"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
|
2163 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2164 |
|
11338 | 2165 |
on:aSignalOrSignalSetOrException do:exceptionBlock ensure:ensureBlock |
2166 |
"added for ANSI compatibility; evaluate the receiver, |
|
18252 | 2167 |
handling aSignalOrSignalSetOrException. |
11338 | 2168 |
The 2nd argument, exceptionBlock is evaluated |
2169 |
if the signal is raised during evaluation. |
|
2170 |
The 3rd argument, ensureBlock is evaluated in any case - even if the activity |
|
2171 |
was unwound due to an unhandled exception." |
|
2172 |
||
2173 |
<context: #return> |
|
2174 |
<exception: #handle> |
|
2175 |
<exception: #unwind> |
|
2176 |
||
2177 |
|v| |
|
2178 |
||
2179 |
v := self value. "the real logic is in Context>>unwind and Exception>>doRaise" |
|
2180 |
thisContext unmarkForUnwind. |
|
2181 |
ensureBlock value. |
|
2182 |
^ v |
|
2183 |
||
2184 |
" |
|
2185 |
|e| |
|
2186 |
||
2187 |
e := 0. |
|
2188 |
[ |
|
18252 | 2189 |
1 foo |
2190 |
] on:MessageNotUnderstood |
|
11338 | 2191 |
do:[:ex | self halt] |
2192 |
ensure:[ e := 1 ]. |
|
2193 |
self assert:(e == 1). |
|
2194 |
" |
|
2195 |
||
2196 |
" |
|
2197 |
|e| |
|
2198 |
||
2199 |
e := 0. |
|
2200 |
[ |
|
18252 | 2201 |
1 negated |
2202 |
] on:MessageNotUnderstood |
|
11338 | 2203 |
do:[:ex | self halt] |
2204 |
ensure:[ e := 1 ]. |
|
2205 |
self assert:(e == 1). |
|
2206 |
" |
|
2207 |
! |
|
2208 |
||
18959 | 2209 |
on:aSignalOrSignalSetOrException do:exceptionBlock ifCurtailed:curtailBlock |
2210 |
"evaluate the receiver, |
|
2211 |
handling aSignalOrSignalSetOrException. |
|
2212 |
The 2nd argument, exceptionBlock is evaluated |
|
2213 |
if the signal is raised during evaluation. |
|
2214 |
The 3rd argument, curtailBlock is evaluated if the activity |
|
2215 |
was unwound due to an unhandled exception in the receiver block |
|
2216 |
(but not in the exceptionBlock)." |
|
2217 |
||
2218 |
<context: #return> |
|
2219 |
<exception: #handle> |
|
2220 |
<exception: #unwind> |
|
2221 |
||
2222 |
|v| |
|
2223 |
||
2224 |
v := self value. "the real logic is in Context>>unwind and Exception>>doRaise" |
|
2225 |
thisContext unmarkForUnwind. |
|
2226 |
^ v |
|
2227 |
||
2228 |
" |
|
2229 |
|e| |
|
2230 |
||
2231 |
e := 0. |
|
2232 |
[ |
|
2233 |
1 foo |
|
2234 |
] on:MessageNotUnderstood |
|
2235 |
do:[:ex | e := 1] |
|
2236 |
ifCurtailed:[ e := 2 ]. |
|
2237 |
self assert:(e == 1). |
|
2238 |
" |
|
2239 |
||
2240 |
" |
|
2241 |
abort the debugger to perform the ifCurtailedBlock... |
|
2242 |
continue the debugger to go to the end |
|
2243 |
||
2244 |
|e| |
|
2245 |
||
2246 |
e := 0. |
|
2247 |
[ |
|
2248 |
#[] at:2 |
|
2249 |
] on:MessageNotUnderstood |
|
2250 |
do:[:ex | e := 1] |
|
2251 |
ifCurtailed:[ e := 2. e inspect ]. |
|
2252 |
self assert:(e == 0). |
|
2253 |
" |
|
2254 |
||
2255 |
" |
|
2256 |
|e| |
|
2257 |
||
2258 |
e := 0. |
|
2259 |
[ |
|
2260 |
1 negated |
|
2261 |
] on:MessageNotUnderstood |
|
2262 |
do:[:ex | self halt] |
|
2263 |
ifCurtailed:[ e := 1 ]. |
|
2264 |
self assert:(e == 0). |
|
2265 |
" |
|
2266 |
! |
|
2267 |
||
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2268 |
on:anExceptionHandler do:exceptionBlock on:anExceptionHandler2 do:anExceptionBlock2 |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2269 |
"added for ANSI compatibility; evaluate the receiver, |
18252 | 2270 |
handling aSignalOrSignalSetOrException. |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2271 |
The 2nd argument, exceptionBlock is evaluated |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2272 |
if the signal is raised during evaluation." |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2273 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2274 |
<context: #return> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2275 |
<exception: #handle> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2276 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2277 |
"/ thisContext markForHandle. -- same as above pragma |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2278 |
^ self value. "the real logic is in Exception>>doRaise" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2279 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2280 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2281 |
[ |
18252 | 2282 |
1 foo |
2283 |
] on:MessageNotUnderstood do:[:ex | self halt:'Got MessageNotUnderstood'] |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2284 |
on:Error do:[:ex| self halt:'Got Error'] |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2285 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2286 |
[ |
18252 | 2287 |
1 // 0 |
2288 |
] on:MessageNotUnderstood do:[:ex | self halt:'Got MessageNotUnderstood'] |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2289 |
on:Error do:[:ex| self halt:'Got Error'] |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2290 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2291 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2292 |
"Modified: / 26.7.1999 / 15:30:48 / stefan" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2293 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2294 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2295 |
valueWithExceptionHandler:handler |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2296 |
"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
|
2297 |
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
|
2298 |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
2299 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2300 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2301 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2302 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2303 |
^ 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
|
2304 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2305 |
"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
|
2306 |
"Modified: / 26.7.1999 / 11:24:06 / stefan" |
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2307 |
! |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2308 |
|
19237 | 2309 |
valueWithTimeout:aTimeDurationOrIntegerSeconds |
14803 | 2310 |
"execute the receiver, but abort the evaluation after aTimeDuration if still running. |
16076 | 2311 |
Return the receiver's value, or nil if aborted." |
14803 | 2312 |
|
19237 | 2313 |
|milliseconds| |
2314 |
||
2315 |
milliseconds := aTimeDurationOrIntegerSeconds isTimeDuration |
|
2316 |
ifTrue:[ aTimeDurationOrIntegerSeconds asMilliseconds ] |
|
2317 |
ifFalse:[ (aTimeDurationOrIntegerSeconds * 1000) truncated]. |
|
2318 |
^ self valueWithWatchDog:[^ nil] afterMilliseconds:milliseconds |
|
14803 | 2319 |
|
2320 |
" |
|
2321 |
[ |
|
19237 | 2322 |
1 to:15 do:[:round | |
2323 |
Transcript showCR:round. |
|
2324 |
Delay waitForMilliseconds:20. |
|
2325 |
]. |
|
2326 |
true |
|
18252 | 2327 |
] valueWithTimeout:(TimeDuration seconds:1) |
14803 | 2328 |
" |
2329 |
||
2330 |
" |
|
2331 |
[ |
|
19237 | 2332 |
1 to:100 do:[:round | |
2333 |
Transcript showCR:round. |
|
2334 |
Delay waitForMilliseconds:20. |
|
2335 |
]. |
|
2336 |
true |
|
18252 | 2337 |
] valueWithTimeout:(TimeDuration seconds:1) |
14803 | 2338 |
" |
2339 |
! |
|
2340 |
||
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2341 |
valueWithWatchDog:exceptionBlock afterMilliseconds:aTimeLimit |
11803 | 2342 |
"a watchdog on a block's execution. If the block does not finish its |
2343 |
evaluation after aTimeLimit milliseconds, it is interrupted (aborted) and |
|
2344 |
exceptionBlock's value is returned. The receiver's code must be prepared |
|
2345 |
for premature returning (by adding ensure blocks, as required)" |
|
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2346 |
|
13220
21b4d5e57663
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
13054
diff
changeset
|
2347 |
|showStopper me retVal done inError| |
12927
1caadc2e24d8
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12921
diff
changeset
|
2348 |
|
1caadc2e24d8
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12921
diff
changeset
|
2349 |
done := false. |
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2350 |
me := Processor activeProcess. |
11704
a47fdf0a638d
oops - valueWithWatchDog did not
Claus Gittinger <cg@exept.de>
parents:
11638
diff
changeset
|
2351 |
|
18252 | 2352 |
showStopper := |
2353 |
[ |
|
2354 |
done ifFalse:[ |
|
2355 |
me interruptWith:[ |
|
2356 |
(Processor activeProcess state ~~ #debug) ifTrue:[ |
|
2357 |
done ifFalse:[ TimeoutNotification raiseRequest ] |
|
2358 |
] |
|
2359 |
] |
|
2360 |
] |
|
2361 |
]. |
|
13030
9b9f51659b4a
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12931
diff
changeset
|
2362 |
|
9b9f51659b4a
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12931
diff
changeset
|
2363 |
TimeoutNotification handle:[:ex | |
18252 | 2364 |
inError ifTrue:[ |
2365 |
ex proceed |
|
2366 |
]. |
|
2367 |
retVal := exceptionBlock value. |
|
10700
0436b2f40e4c
changed #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
10678
diff
changeset
|
2368 |
] do:[ |
18252 | 2369 |
NoHandlerError handle:[:ex | |
2370 |
inError := true. |
|
2371 |
ex reject. |
|
2372 |
] do:[ |
|
2373 |
[ |
|
2374 |
Processor |
|
2375 |
addTimedBlock:showStopper |
|
2376 |
for:me |
|
2377 |
afterMilliseconds:aTimeLimit. |
|
2378 |
||
2379 |
retVal := self value. |
|
2380 |
done := true. |
|
2381 |
] ensure:[ |
|
2382 |
Processor removeTimedBlock:showStopper |
|
2383 |
]. |
|
2384 |
] |
|
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2385 |
]. |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2386 |
^ retVal |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2387 |
|
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2388 |
" |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2389 |
[ |
18252 | 2390 |
Delay waitForSeconds:5. |
2391 |
true |
|
2392 |
] valueWithWatchDog:[false] afterMilliseconds:2000 |
|
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2393 |
" |
10678
5cd10f301f94
changed #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
10473
diff
changeset
|
2394 |
|
12928 | 2395 |
"Modified: / 21-05-2010 / 12:19:57 / sr" |
13220
21b4d5e57663
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
13054
diff
changeset
|
2396 |
"Modified: / 18-01-2011 / 19:24:13 / cg" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2397 |
! ! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2398 |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2399 |
!Block methodsFor:'exception handling private'! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2400 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2401 |
exceptionHandlerFor:anException in:aContext |
11338 | 2402 |
"answer the exceptionHandler (the Error or signal) for anException from aContext." |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2403 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2404 |
aContext selector == #on:do:on:do: ifTrue:[ |
18252 | 2405 |
|exceptionCreator exceptionHandlerInContext| |
2406 |
||
2407 |
exceptionCreator := anException creator. |
|
2408 |
exceptionHandlerInContext := aContext argAt:1. |
|
2409 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2410 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2411 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2412 |
] ifFalse:[ |
|
2413 |
(exceptionHandlerInContext isBehavior |
|
2414 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2415 |
"If the exception class is still autoloaded, |
|
2416 |
it does not accept our exception. Raising the exception would load the class" |
|
2417 |
^ nil |
|
2418 |
] ifFalse:[ |
|
2419 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2420 |
] |
|
2421 |
]. |
|
2422 |
aContext fullPrintString errorPrintCR. |
|
2423 |
self breakPoint:#cg. |
|
2424 |
^ nil. |
|
2425 |
]. |
|
2426 |
(exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[ |
|
2427 |
^ exceptionHandlerInContext. |
|
2428 |
]. |
|
2429 |
||
2430 |
exceptionHandlerInContext := aContext argAt:3. |
|
2431 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2432 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2433 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2434 |
] ifFalse:[ |
|
2435 |
(exceptionHandlerInContext isBehavior |
|
2436 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2437 |
"If the exception class is still autoloaded, |
|
2438 |
it does not accept our exception. Raising the exception would load the class" |
|
2439 |
^ nil |
|
2440 |
] ifFalse:[ |
|
2441 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2442 |
] |
|
2443 |
]. |
|
2444 |
aContext fullPrintString errorPrintCR. |
|
2445 |
self breakPoint:#cg. |
|
2446 |
^ nil. |
|
2447 |
]. |
|
2448 |
(exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[ |
|
2449 |
^ exceptionHandlerInContext. |
|
2450 |
]. |
|
2451 |
^ nil. |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2452 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2453 |
|
11338 | 2454 |
"aContext selector must be #on:do: , #on:do:ensure: or #valueWithExceptionHandler:" |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2455 |
^ aContext argAt:1. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2456 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2457 |
|
18959 | 2458 |
handlerForSignal:exceptionCreator context:theContext originator:originator |
2459 |
"answer the handler block for the exceptionCreator from originator. |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2460 |
The handler block is retrieved from aContext. |
18959 | 2461 |
Answer nil if the exceptionCreator is not handled." |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2462 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2463 |
|selector exceptionHandlerInContext| |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2464 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2465 |
selector := theContext selector. |
11338 | 2466 |
|
2467 |
(selector == #on:do: |
|
18959 | 2468 |
or:[ selector == #on:do:ensure: |
2469 |
or:[ selector == #on:do:ifCurtailed: ]] |
|
2470 |
) ifTrue:[ |
|
2471 |
exceptionHandlerInContext := theContext argAt:1. |
|
2472 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2473 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2474 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2475 |
] ifFalse:[(exceptionHandlerInContext isBehavior |
|
2476 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2477 |
"If the exception class is still autoloaded, |
|
2478 |
it does not accept our exception. Raising the exception would load the class" |
|
2479 |
^ nil |
|
2480 |
] ifFalse:[ |
|
2481 |
'Block [warning]: non-ExceptionHandler in on:do:-context' errorPrintCR. |
|
2482 |
]]. |
|
2483 |
theContext fullPrint. |
|
2484 |
^ nil. |
|
2485 |
]. |
|
2486 |
(exceptionHandlerInContext == exceptionCreator |
|
2487 |
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[ |
|
2488 |
selector == #on:do:ifCurtailed: ifTrue:[ |
|
2489 |
theContext unmarkForUnwind. "if there is a handler, no unwind block has to be performed" |
|
2490 |
]. |
|
2491 |
^ (theContext argAt:2) ? [nil]. |
|
2492 |
]. |
|
2493 |
^ nil |
|
11338 | 2494 |
]. |
2495 |
||
2496 |
selector == #on:do:on:do: ifTrue:[ |
|
18959 | 2497 |
exceptionHandlerInContext := theContext argAt:1. |
2498 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2499 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2500 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2501 |
] ifFalse:[(exceptionHandlerInContext isBehavior |
|
2502 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2503 |
"If the exception class is still autoloaded, |
|
2504 |
it does not accept our exception. Raising the exception would load the class" |
|
2505 |
^ nil |
|
2506 |
] ifFalse:[ |
|
2507 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2508 |
]]. |
|
2509 |
theContext fullPrint. |
|
2510 |
^ nil. |
|
2511 |
]. |
|
2512 |
(exceptionHandlerInContext == exceptionCreator |
|
2513 |
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[ |
|
2514 |
^ (theContext argAt:2) ? [nil]. |
|
2515 |
]. |
|
2516 |
||
2517 |
exceptionHandlerInContext := theContext argAt:3. |
|
2518 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2519 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2520 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2521 |
] ifFalse:[(exceptionHandlerInContext isBehavior |
|
2522 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2523 |
"If the exception class is still autoloaded, |
|
2524 |
it does not accept our exception. Raising the exception would load the class" |
|
2525 |
^ nil |
|
2526 |
] ifFalse:[ |
|
2527 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2528 |
]]. |
|
2529 |
theContext fullPrint. |
|
2530 |
^ nil. |
|
2531 |
]. |
|
2532 |
(exceptionHandlerInContext == exceptionCreator |
|
2533 |
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[ |
|
2534 |
^ (theContext argAt:4) ? [nil]. |
|
2535 |
]. |
|
2536 |
^ nil |
|
11338 | 2537 |
]. |
2538 |
||
2539 |
selector == #valueWithExceptionHandler: ifTrue:[ |
|
18959 | 2540 |
^ (theContext argAt:1) handlerForSignal:exceptionCreator. |
11338 | 2541 |
]. |
2542 |
||
2543 |
"/ mhmh - should not arrive here |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2544 |
^ nil |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2545 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2546 |
"Created: / 25.7.1999 / 19:52:58 / stefan" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2547 |
"Modified: / 26.7.1999 / 14:30:42 / stefan" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2548 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2549 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2550 |
handlerProtectedBlock:doBlock inContext:context |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2551 |
"set the block that is protected by an exception handler in context. |
11338 | 2552 |
This is the receiver of the #on:do: or #valueWithExceptionHandler:. |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2553 |
Needed for #restartDo:" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2554 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2555 |
context receiver:doBlock |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2556 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2557 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2558 |
[1/0] on:Error do:[:ex| ex restartDo:[55]] |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2559 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2560 |
! ! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2561 |
|
14139 | 2562 |
|
623 | 2563 |
!Block methodsFor:'looping'! |
325 | 2564 |
|
623 | 2565 |
doUntil:aBlock |
2566 |
"repeat the receiver block until aBlock evaluates to true. |
|
2567 |
The receiver is evaluated at least once. |
|
2568 |
This is the same as '... doWhile:[... not]' " |
|
325 | 2569 |
|
623 | 2570 |
"this implementation is for purists ... :-)" |
2571 |
||
2572 |
self value. |
|
2573 |
aBlock value ifTrue:[^ nil]. |
|
2574 |
thisContext restart |
|
325 | 2575 |
|
2576 |
" |
|
623 | 2577 |
|n| |
154 | 2578 |
|
623 | 2579 |
n := 1. |
8602 | 2580 |
[n printCR] doUntil:[ (n := n + 1) > 5 ] |
154 | 2581 |
" |
1 | 2582 |
! |
2583 |
||
623 | 2584 |
doWhile:aBlock |
2585 |
"repeat the receiver block until aBlock evaluates to false. |
|
2586 |
The receiver is evaluated at least once." |
|
67 | 2587 |
|
154 | 2588 |
"this implementation is for purists ... :-)" |
2589 |
||
623 | 2590 |
self value. |
2591 |
aBlock value ifFalse:[^ nil]. |
|
2592 |
thisContext restart |
|
2593 |
||
2594 |
" |
|
2595 |
|n| |
|
2596 |
||
2597 |
n := 1. |
|
8602 | 2598 |
[n printCR] doWhile:[ (n := n + 1) <= 5 ] |
623 | 2599 |
" |
2600 |
! |
|
2601 |
||
2602 |
loop |
|
18252 | 2603 |
"repeat the receiver forever |
1211 | 2604 |
(the receiver block should contain a return somewhere). |
2605 |
The implementation below was inspired by a corresponding Self method." |
|
623 | 2606 |
|
2607 |
self value. |
|
67 | 2608 |
thisContext restart |
2609 |
||
2610 |
" |
|
2611 |
|n| |
|
2612 |
||
2613 |
n := 1. |
|
623 | 2614 |
[ |
18252 | 2615 |
n printCR. |
2616 |
n >= 10 ifTrue:[^ nil]. |
|
2617 |
n := n + 1 |
|
623 | 2618 |
] loop |
2619 |
" |
|
1211 | 2620 |
|
2621 |
"Modified: 18.4.1996 / 13:50:40 / cg" |
|
623 | 2622 |
! |
2623 |
||
2624 |
loopWithExit |
|
18252 | 2625 |
"the receiver must be a block of one argument. It is evaluated in a loop forever, |
2626 |
and is passed a block, which, if sent a value:-message, will exit the receiver block, |
|
623 | 2627 |
returning the parameter of the value:-message. Used for loops with exit in the middle. |
2628 |
Inspired by a corresponding Self method." |
|
2629 |
||
2630 |
|exitBlock| |
|
2631 |
||
2632 |
exitBlock := [:exitValue | ^ exitValue]. |
|
16239 | 2633 |
[self value:exitBlock] loop. |
623 | 2634 |
|
2635 |
" |
|
2636 |
|i| |
|
2637 |
i := 1. |
|
2638 |
[:exit | |
|
18252 | 2639 |
Transcript showCR:i. |
2640 |
i == 5 ifTrue:[exit value:'thats it']. |
|
2641 |
i := i + 1 |
|
623 | 2642 |
] loopWithExit |
2643 |
" |
|
2644 |
! |
|
2645 |
||
2646 |
repeat |
|
1211 | 2647 |
"repeat the receiver forever - same as loop, for ST-80 compatibility. |
2648 |
(the receiver block should contain a return somewhere)." |
|
623 | 2649 |
|
2650 |
self value. |
|
2651 |
thisContext restart |
|
1211 | 2652 |
|
2653 |
"Modified: 18.4.1996 / 13:50:55 / cg" |
|
623 | 2654 |
! |
2655 |
||
16162 | 2656 |
repeat:n |
18252 | 2657 |
"repeat the receiver n times - similar to timesRepeat, but optionally passes the |
16162 | 2658 |
loop counter as argument" |
2659 |
||
18434 | 2660 |
self argumentCount == 0 ifTrue:[ |
2661 |
n timesRepeat:self |
|
16162 | 2662 |
] ifFalse:[ |
18434 | 2663 |
1 to:n do:self |
16162 | 2664 |
]. |
2665 |
||
2666 |
" |
|
2667 |
[ Transcript showCR:'hello' ] repeat:3 |
|
2668 |
[:i | Transcript showCR:'hello',i printString ] repeat:3 |
|
2669 |
" |
|
2670 |
! |
|
2671 |
||
623 | 2672 |
valueWithExit |
2673 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
|
18252 | 2674 |
which, if sent a value:-message, will exit the receiver block, returning the parameter of the |
623 | 2675 |
value:-message. Used for premature returns to the caller. |
2676 |
Taken from a manchester goody (a similar construct also appears in Self)." |
|
2677 |
||
1211 | 2678 |
^ self value:[:exitValue | ^exitValue] |
623 | 2679 |
|
2680 |
" |
|
2681 |
[:exit | |
|
2238 | 2682 |
1 to:10 do:[:i | |
2683 |
Transcript showCR:i. |
|
2684 |
i == 5 ifTrue:[exit value:'thats it'] |
|
2685 |
]. |
|
2686 |
'regular block-value; never returned' |
|
623 | 2687 |
] valueWithExit |
2688 |
" |
|
1211 | 2689 |
|
2690 |
"Modified: 18.4.1996 / 13:51:38 / cg" |
|
623 | 2691 |
! |
2692 |
||
5215 | 2693 |
valueWithRestart |
14683 | 2694 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
15244 | 2695 |
which, if sent a value-message, will restart the receiver block from the beginning" |
2696 |
||
15316 | 2697 |
|myContext restartAction| |
5215 | 2698 |
|
2699 |
myContext := thisContext. |
|
15320 | 2700 |
restartAction := [ myContext unwindAndRestart ]. |
15316 | 2701 |
^ self value:restartAction. |
5215 | 2702 |
|
2703 |
" |
|
2704 |
[:restart | |
|
18252 | 2705 |
(self confirm:'try again ?') ifTrue:[ |
2706 |
restart value. |
|
2707 |
] |
|
5215 | 2708 |
] valueWithRestart |
2709 |
" |
|
2710 |
||
2711 |
"Modified: / 25.1.2000 / 21:47:50 / cg" |
|
2712 |
! |
|
2713 |
||
14683 | 2714 |
valueWithRestartAndExit |
2715 |
"the receiver must be a block of two arguments, a restart and an exit block. |
|
2716 |
See description of valueWithExit and valueWithRestart for their use" |
|
2717 |
||
15316 | 2718 |
|myContext restartAction| |
14683 | 2719 |
|
2720 |
myContext := thisContext. |
|
15320 | 2721 |
restartAction := [ myContext unwindAndRestart ]. |
15316 | 2722 |
^ self value:restartAction value:[:exitValue | ^exitValue]. |
14683 | 2723 |
|
2724 |
" |
|
2725 |
[:restart :exit | |
|
18252 | 2726 |
|i| |
2727 |
||
2728 |
i := 0. |
|
2729 |
[ |
|
2730 |
i := i + 1. |
|
2731 |
(self confirm:('i is ',i printString,'; start over ?')) ifTrue:[ |
|
2732 |
restart value. |
|
2733 |
]. |
|
2734 |
(self confirm:'enough ?') ifTrue:[ |
|
2735 |
exit value:nil. |
|
2736 |
]. |
|
2737 |
] loop |
|
14683 | 2738 |
] valueWithRestartAndExit |
2739 |
" |
|
2740 |
! |
|
2741 |
||
623 | 2742 |
whileFalse |
2743 |
"evaluate the receiver while it evaluates to false (ST80 compatibility)" |
|
2744 |
||
2745 |
"this implementation is for purists ... :-)" |
|
2746 |
||
2747 |
self value ifTrue:[^ nil]. |
|
2748 |
thisContext restart |
|
2749 |
||
2750 |
" |
|
2751 |
|n| |
|
2752 |
||
2753 |
n := 1. |
|
8602 | 2754 |
[n printCR. (n := n + 1) > 10] whileFalse |
67 | 2755 |
" |
2756 |
! |
|
1 | 2757 |
|
67 | 2758 |
whileFalse:aBlock |
2759 |
"evaluate the argument, aBlock while the receiver evaluates to false. |
|
18252 | 2760 |
- usually open coded by compilers, but needed here for #perform |
67 | 2761 |
and expression evaluation." |
2762 |
||
154 | 2763 |
"this implementation is for purists ... :-)" |
2764 |
||
67 | 2765 |
self value ifTrue:[^ nil]. |
2766 |
aBlock value. |
|
2767 |
thisContext restart |
|
2768 |
||
2769 |
" |
|
2770 |
|n| |
|
2771 |
||
2772 |
n := 1. |
|
2773 |
[n > 10] whileFalse:[ |
|
18252 | 2774 |
n printCR. |
2775 |
n := n + 1 |
|
67 | 2776 |
] |
2777 |
" |
|
1 | 2778 |
! |
2779 |
||
2780 |
whileTrue |
|
67 | 2781 |
"evaluate the receiver while it evaluates to true (ST80 compatibility)" |
1 | 2782 |
|
154 | 2783 |
"this implementation is for purists ... :-)" |
2784 |
||
67 | 2785 |
self value ifFalse:[^ nil]. |
2786 |
thisContext restart |
|
1 | 2787 |
|
67 | 2788 |
" |
2789 |
|n| |
|
1 | 2790 |
|
67 | 2791 |
n := 1. |
8602 | 2792 |
[n printCR. (n := n + 1) <= 10] whileTrue |
67 | 2793 |
" |
1 | 2794 |
! |
2795 |
||
623 | 2796 |
whileTrue:aBlock |
2797 |
"evaluate the argument, aBlock while the receiver evaluates to true. |
|
18252 | 2798 |
- usually open coded by compilers, but needed here for #perform |
623 | 2799 |
and expression evaluation." |
1 | 2800 |
|
154 | 2801 |
"this implementation is for purists ... :-)" |
2802 |
||
623 | 2803 |
self value ifFalse:[^ nil]. |
2804 |
aBlock value. |
|
67 | 2805 |
thisContext restart |
2806 |
||
2807 |
" |
|
2808 |
|n| |
|
1 | 2809 |
|
67 | 2810 |
n := 1. |
623 | 2811 |
[n <= 10] whileTrue:[ |
18252 | 2812 |
n printCR. |
2813 |
n := n + 1 |
|
623 | 2814 |
] |
68 | 2815 |
" |
67 | 2816 |
! ! |
2817 |
||
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2818 |
!Block methodsFor:'parallel evaluation'! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2819 |
|
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2820 |
futureValue |
18252 | 2821 |
"Fork a synchronised evaluation of myself. |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2822 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2823 |
any access to wait until the result is computed." |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2824 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2825 |
^ Future new block:self |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2826 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2827 |
|
18252 | 2828 |
futureValue:aValue |
2829 |
"Fork a synchronised evaluation of myself. |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2830 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2831 |
any access to wait until the result is computed." |
18252 | 2832 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2833 |
^ Future new block:self value:aValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2834 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2835 |
|
18252 | 2836 |
futureValue:aValue value:anotherValue |
2837 |
"Fork a synchronised evaluation of myself. |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2838 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2839 |
any access to wait until the result is computed." |
18252 | 2840 |
|
2841 |
^ Future new |
|
2842 |
block:self |
|
2843 |
value:aValue |
|
2844 |
value:anotherValue |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2845 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2846 |
|
18252 | 2847 |
futureValue:aValue value:anotherValue value:bValue |
2848 |
"Fork a synchronised evaluation of myself. |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2849 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2850 |
any access to wait until the result is computed." |
18252 | 2851 |
|
2852 |
^ Future new |
|
2853 |
block:self |
|
2854 |
value:aValue |
|
2855 |
value:anotherValue |
|
2856 |
value:bValue |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2857 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2858 |
|
18252 | 2859 |
futureValueWithArguments:anArray |
2860 |
"Fork a synchronised evaluation of myself. |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2861 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2862 |
any access to wait until the result is computed." |
18252 | 2863 |
|
2864 |
^ Future new |
|
2865 |
block:self |
|
2866 |
valueWithArguments:anArray |
|
13767 | 2867 |
|
2868 |
"Modified (format): / 04-10-2011 / 14:55:40 / cg" |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2869 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2870 |
|
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2871 |
lazyValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2872 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2873 |
the evaluation when the result is requested." |
18252 | 2874 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2875 |
^ Lazy new block:self |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2876 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2877 |
|
18252 | 2878 |
lazyValue:aValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2879 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2880 |
the evaluation when the result is requested." |
18252 | 2881 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2882 |
^ Lazy new block:self value:aValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2883 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2884 |
|
18252 | 2885 |
lazyValue:aValue value:anotherValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2886 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2887 |
the evaluation when the result is requested." |
18252 | 2888 |
|
2889 |
^ Lazy new |
|
2890 |
block:self |
|
2891 |
value:aValue |
|
2892 |
value:anotherValue |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2893 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2894 |
|
18252 | 2895 |
lazyValue:aValue value:anotherValue value:bValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2896 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2897 |
the evaluation when the result is requested." |
18252 | 2898 |
|
2899 |
^ Lazy new |
|
2900 |
block:self |
|
2901 |
value:aValue |
|
2902 |
value:anotherValue |
|
2903 |
value:bValue |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2904 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2905 |
|
18252 | 2906 |
lazyValueWithArguments:anArray |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2907 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2908 |
the evaluation when the result is requested." |
18252 | 2909 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2910 |
^ Lazy new block:self valueWithArguments:anArray |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2911 |
! ! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2912 |
|
92 | 2913 |
!Block methodsFor:'printing & storing'! |
1 | 2914 |
|
7151 | 2915 |
printBlockBracketsOn:aStream |
18252 | 2916 |
aStream nextPutAll:'[]'. |
7151 | 2917 |
! |
2918 |
||
1 | 2919 |
printOn:aStream |
44 | 2920 |
"append a a printed representation of the block to aStream" |
2921 |
||
6633 | 2922 |
|h sel methodClass| |
54 | 2923 |
|
2924 |
"cheap blocks have no home context, but a method instead" |
|
2925 |
||
2926 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
18252 | 2927 |
aStream nextPutAll:'[] in '. |
2928 |
||
2929 |
" |
|
2930 |
currently, some cheap blocks don't know where they have been created |
|
2931 |
" |
|
2932 |
aStream nextPutAll:' ??? (optimized)'. |
|
2933 |
^ self |
|
54 | 2934 |
]. |
2935 |
||
2936 |
"a full blown block (with home, but without method)" |
|
7151 | 2937 |
self printBlockBracketsOn:aStream. |
18252 | 2938 |
aStream nextPutAll:' in '. |
154 | 2939 |
h := self methodHome. |
2940 |
sel := h selector. |
|
2941 |
"/ old: |
|
2942 |
"/ home receiver class name printOn:aStream. |
|
2943 |
"/ new: |
|
212 | 2944 |
"/ (h searchClass whichClassImplements:sel) name printOn:aStream. |
213 | 2945 |
methodClass := h methodClass. |
2946 |
methodClass isNil ifTrue:[ |
|
18252 | 2947 |
'UnboundMethod' printOn:aStream. |
213 | 2948 |
] ifFalse:[ |
18252 | 2949 |
methodClass name printOn:aStream. |
213 | 2950 |
]. |
7157
935eaabbe6dc
printString now "... in className >> sel"
Claus Gittinger <cg@exept.de>
parents:
7151
diff
changeset
|
2951 |
aStream nextPutAll:'>>'. |
154 | 2952 |
sel printOn:aStream. |
54 | 2953 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2954 |
"/ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2955 |
"/ aStream nextPutAll:'[] in '. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2956 |
"/ homeClass := home containingClass. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2957 |
"/ homeClass notNil ifTrue:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2958 |
"/ homeClass name printOn:aStream. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2959 |
"/ aStream space. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2960 |
"/ (homeClass selectorForMethod:home) printOn:aStream |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2961 |
"/ ] ifFalse:[ |
18252 | 2962 |
"/ aStream nextPutAll:' ???' |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2963 |
"/ ] |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2964 |
"/ |
9253 | 2965 |
! |
2966 |
||
2967 |
storeOn:aStream |
|
15850 | 2968 |
MethodNotAppropriateError raiseRequestErrorString:'Blocks cannot be stored (yet)'. |
9287 | 2969 |
self printOn:aStream. |
1 | 2970 |
! ! |
623 | 2971 |
|
7257 | 2972 |
!Block methodsFor:'private-accessing'! |
623 | 2973 |
|
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
2974 |
byteCode:bCode numArgs:numArgs numVars:numVars numStack:numStack sourcePosition:srcPos initialPC:iPC literals:lits |
1265 | 2975 |
"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
|
2976 |
DANGER ALERT: this interface is strictly private." |
623 | 2977 |
|
2978 |
byteCode := bCode. |
|
2979 |
nargs := numArgs. |
|
2980 |
sourcePos := srcPos. |
|
2981 |
initialPC := iPC. |
|
1777 | 2982 |
flags := 0. |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
2983 |
self stackSize:numStack. |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2984 |
self literals:lits. |
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
2985 |
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
|
2986 |
self numberOfVars:numVars. "/ must set the compiledCode flags as well |
1265 | 2987 |
|
2988 |
"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
|
2989 |
"Modified: 24.6.1996 / 12:37:37 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
2990 |
"Created: 13.4.1997 / 00:00:57 / cg" |
623 | 2991 |
! |
2992 |
||
18252 | 2993 |
initialPC |
5779 | 2994 |
"return the initial pc for evaluation." |
2995 |
||
2996 |
^ initialPC |
|
2997 |
! |
|
2998 |
||
18252 | 2999 |
initialPC:initial |
1265 | 3000 |
"set the initial pc for evaluation. |
3001 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 3002 |
|
3003 |
initialPC := initial |
|
1265 | 3004 |
|
3005 |
"Modified: 23.4.1996 / 16:05:39 / cg" |
|
623 | 3006 |
! |
3007 |
||
3008 |
numArgs:numArgs |
|
1265 | 3009 |
"set the number of arguments the receiver expects for evaluation. |
3010 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 3011 |
|
3012 |
nargs := numArgs |
|
1265 | 3013 |
|
3014 |
"Modified: 23.4.1996 / 16:05:52 / cg" |
|
623 | 3015 |
! |
3016 |
||
5744 | 3017 |
setHome:aContext |
3018 |
home := aContext |
|
3019 |
! |
|
3020 |
||
18252 | 3021 |
source |
7323 | 3022 |
|m| |
3023 |
||
3024 |
sourcePos isString ifTrue:[ "/ misuses the sourcePosition slot |
|
18252 | 3025 |
^ sourcePos |
7323 | 3026 |
]. |
3027 |
m := self method. |
|
3028 |
m notNil ifTrue:[ |
|
18252 | 3029 |
^ m source |
7323 | 3030 |
]. |
3031 |
^ nil |
|
3032 |
! |
|
3033 |
||
18252 | 3034 |
source:aString |
6981 | 3035 |
"set the source - only to be used, if the block is not contained in a method. |
3036 |
This interface is for knowledgable users only." |
|
3037 |
||
3038 |
sourcePos := aString "/ misuse the sourcePosition slot |
|
3039 |
! |
|
3040 |
||
18252 | 3041 |
sourcePosition:position |
1265 | 3042 |
"set the position of the source within my method. |
3043 |
This interface is for the compiler only." |
|
623 | 3044 |
|
3045 |
sourcePos := position |
|
1265 | 3046 |
|
3047 |
"Modified: 23.4.1996 / 16:06:19 / cg" |
|
623 | 3048 |
! ! |
3049 |
||
3050 |
!Block methodsFor:'privileged evaluation'! |
|
3051 |
||
3052 |
valueUninterruptably |
|
3053 |
"evaluate the receiver with interrupts blocked. |
|
3054 |
This does not prevent preemption by a higher priority processes |
|
3055 |
if any becomes runnable due to the evaluation of the receiver |
|
3056 |
(i.e. if a semaphore is signalled)." |
|
3057 |
||
2301 | 3058 |
"we must keep track of blocking-state if this is called nested" |
3059 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3060 |
"/ already blocked. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3061 |
^ self value |
2301 | 3062 |
]. |
864 | 3063 |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3064 |
^ self ensure:[OperatingSystem unblockInterrupts]. |
623 | 3065 |
! |
3066 |
||
3067 |
valueUnpreemptively |
|
3068 |
"evaluate the receiver without the possiblity of preemption |
|
3069 |
(i.e. at a very high priority)" |
|
3070 |
||
3071 |
|oldPrio activeProcess| |
|
3072 |
||
3073 |
activeProcess := Processor activeProcess. |
|
3074 |
oldPrio := activeProcess changePriority:(Processor highestPriority). |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3075 |
^ self ensure:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3076 |
activeProcess priority:oldPrio |
623 | 3077 |
] |
3078 |
! ! |
|
3079 |
||
3080 |
!Block methodsFor:'process creation'! |
|
3081 |
||
3082 |
fork |
|
3083 |
"create a new process executing the receiver at the current priority." |
|
3084 |
||
3085 |
^ self newProcess resume |
|
3086 |
! |
|
3087 |
||
3088 |
forkAt:priority |
|
3089 |
"create a new process executing the receiver at a different priority." |
|
3090 |
||
3091 |
^ (self newProcess priority:priority) resume |
|
3092 |
! |
|
3093 |
||
6609 | 3094 |
forkNamed:aString |
18252 | 3095 |
"create a new process, give it a name and let it start |
6609 | 3096 |
executing the receiver at the current priority." |
3097 |
||
3098 |
|newProcess| |
|
3099 |
||
18252 | 3100 |
newProcess := self newProcess. |
6609 | 3101 |
newProcess name:aString. |
3102 |
newProcess resume. |
|
3103 |
^ newProcess. |
|
3104 |
! |
|
3105 |
||
623 | 3106 |
forkWith:argArray |
3107 |
"create a new process executing the receiver, |
|
3108 |
passing elements in argArray as arguments to the receiver block." |
|
3109 |
||
3110 |
^ [self valueWithArguments:argArray] fork. |
|
3111 |
! |
|
3112 |
||
3113 |
newProcess |
|
3114 |
"create a new (unscheduled) process executing the receiver" |
|
3115 |
||
3116 |
^ Process for:self priority:(Processor activePriority) |
|
3117 |
! |
|
3118 |
||
3119 |
newProcessWithArguments:argArray |
|
3120 |
"create a new (unscheduled) process executing the receiver, |
|
3121 |
passing the elements in argArray as arguments to the receiver block." |
|
3122 |
||
3123 |
^ [self valueWithArguments:argArray] newProcess |
|
3124 |
! |
|
3125 |
||
3126 |
promise |
|
3127 |
"create a promise on the receiver. The promise will evaluate the |
|
3128 |
receiver and promise to return the value with the #value message. |
|
3129 |
The evaluation will be performed as a separate process. |
|
3130 |
Asking the promise for its value will either block the asking process |
|
3131 |
(if the evaluation has not yet been finished) or return the value |
|
3132 |
immediately." |
|
3133 |
||
3134 |
^ Promise value:self |
|
3135 |
||
3136 |
" |
|
3137 |
|p| |
|
3138 |
||
3139 |
p := [1000 factorial] promise. |
|
3140 |
'do something else ...'. |
|
3141 |
p value |
|
3142 |
" |
|
3143 |
! |
|
3144 |
||
3145 |
promiseAt:prio |
|
3146 |
"create a promise on the receiver. The promise will evaluate the |
|
3147 |
receiver and promise to return the value with the #value message. |
|
3148 |
The evaluation will be performed as a separate process running at prio. |
|
3149 |
Asking the promise for its value will either block the asking process |
|
3150 |
(if the evaluation has not yet been finished) or return the value |
|
3151 |
immediately." |
|
3152 |
||
3153 |
^ Promise value:self priority:prio |
|
3154 |
! ! |
|
3155 |
||
3156 |
!Block methodsFor:'testing'! |
|
3157 |
||
3158 |
isBlock |
|
3159 |
"return true, if this is a block - yes I am" |
|
3160 |
||
3161 |
^ true |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3162 |
! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3163 |
|
16276 | 3164 |
isCheapBlock |
3165 |
^ false |
|
3166 |
! |
|
3167 |
||
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3168 |
isVarArgBlock |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3169 |
"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
|
3170 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3171 |
^ false |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3172 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3173 |
"Created: 23.1.1997 / 04:59:51 / cg" |
623 | 3174 |
! ! |
3175 |
||
3176 |
!Block methodsFor:'unwinding'! |
|
3177 |
||
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3178 |
unwindHandlerInContext:aContext |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3179 |
"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
|
3180 |
retrieve the handler block. |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3181 |
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
|
3182 |
#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
|
3183 |
methods to be added)" |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3184 |
|
11338 | 3185 |
|selector| |
3186 |
||
3187 |
selector := aContext selector. |
|
3188 |
selector == #'value:onUnwindDo:' ifTrue:[ |
|
18959 | 3189 |
^ aContext argAt:2 |
4896 | 3190 |
]. |
18959 | 3191 |
(selector == #'on:do:ensure:' |
3192 |
or:[selector == #'on:do:ifCurtailed:'])ifTrue:[ |
|
3193 |
^ aContext argAt:3 |
|
11338 | 3194 |
]. |
4896 | 3195 |
|
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3196 |
"/ for now, only #valueNowOrOnUnwindDo: |
4896 | 3197 |
"/ or #valueOnUnwindDo: |
5666
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
3198 |
"/ or #ensure: |
6608 | 3199 |
"/ or #ifCurtailed: |
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3200 |
|
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3201 |
^ aContext argAt:1 |
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3202 |
! ! |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3203 |
|
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3204 |
!Block methodsFor:'unwinding-old'! |
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3205 |
|
4896 | 3206 |
value:arg onUnwindDo:aBlock |
3207 |
"evaluate the receiver, passing it one argument |
|
3208 |
- when some method sent within unwinds (i.e. does |
|
3209 |
a long return), evaluate the argument, aBlock. |
|
3210 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
3211 |
executed regardless of error actions" |
|
3212 |
||
3213 |
<exception: #unwind> |
|
3214 |
||
3215 |
|v| |
|
3216 |
||
3217 |
"/ thisContext markForUnwind. -- same as above pragma |
|
3218 |
v := self value:arg. "the real logic is in Context>>unwind" |
|
3219 |
thisContext unmarkForUnwind. |
|
3220 |
^ v |
|
3221 |
||
3222 |
" |
|
3223 |
|s| |
|
3224 |
||
3225 |
s := 'Makefile' asFilename readStream. |
|
3226 |
[:arg | |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3227 |
^ self |
4896 | 3228 |
] value:12345 onUnwindDo:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3229 |
Transcript showCR:'closing the stream - even though a return occurred'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3230 |
s close |
4896 | 3231 |
] |
3232 |
" |
|
3233 |
" |
|
3234 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3235 |
|s| |
4896 | 3236 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3237 |
s := 'Makefile' asFilename readStream. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3238 |
[:arg | |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3239 |
Processor activeProcess terminate |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3240 |
] value:12345 onUnwindDo:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3241 |
Transcript showCR:'closing the stream - even though process was terminated'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3242 |
s close |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3243 |
] |
4896 | 3244 |
] fork |
3245 |
" |
|
3246 |
||
3247 |
! |
|
3248 |
||
623 | 3249 |
valueNowOrOnUnwindDo:aBlock |
3250 |
"evaluate the receiver - after that, or when some method sent within unwinds (i.e. does |
|
3251 |
a long return), evaluate the argument, aBlock. |
|
3252 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3253 |
executed regardless of error actions. |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3254 |
Same as the more modern #ensure:" |
623 | 3255 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3256 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3257 |
|
623 | 3258 |
|v| |
3259 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3260 |
"/ thisContext markForUnwind. -- same as above pragma |
623 | 3261 |
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
|
3262 |
thisContext unmarkForUnwind. |
623 | 3263 |
aBlock value. |
3264 |
^ v |
|
3265 |
||
3266 |
" |
|
3267 |
in the following example, f will be closed even if the block |
|
3268 |
returns with 'oops'. There are many more applications of this kind |
|
3269 |
found in the system. |
|
3270 |
" |
|
3271 |
" |
|
3272 |
|f| |
|
3273 |
||
3274 |
f := 'Makefile' asFilename readStream. |
|
3275 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3276 |
l := f nextLine. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3277 |
l isNil ifTrue:[^ 'oops'] |
623 | 3278 |
] valueNowOrOnUnwindDo:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3279 |
f close |
623 | 3280 |
] |
3281 |
" |
|
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
3282 |
|
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
3283 |
"Modified: 16.4.1996 / 11:05:26 / stefan" |
623 | 3284 |
! |
3285 |
||
3286 |
valueOnUnwindDo:aBlock |
|
3287 |
"evaluate the receiver - when some method sent within unwinds (i.e. does |
|
3288 |
a long return), evaluate the argument, aBlock. |
|
3289 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3290 |
executed regardless of error actions |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3291 |
Same as the more modern #ifCurtailed:" |
623 | 3292 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3293 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3294 |
|
2286 | 3295 |
|v| |
3296 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3297 |
"/ thisContext markForUnwind. -- same as above pragma |
2286 | 3298 |
v := self value. "the real logic is in Context>>unwind" |
3299 |
thisContext unmarkForUnwind. |
|
3300 |
^ v |
|
3301 |
||
4896 | 3302 |
" |
3303 |
|s| |
|
3304 |
||
3305 |
s := 'Makefile' asFilename readStream. |
|
3306 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3307 |
^ self |
4896 | 3308 |
] valueOnUnwindDo:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3309 |
Transcript showCR:'closing the stream - even though a return occurred'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3310 |
s close |
4896 | 3311 |
] |
3312 |
" |
|
3313 |
" |
|
3314 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3315 |
|s| |
4896 | 3316 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3317 |
s := 'Makefile' asFilename readStream. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3318 |
[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3319 |
Processor activeProcess terminate |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3320 |
] valueOnUnwindDo:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3321 |
Transcript showCR:'closing the stream - even though process was terminated'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3322 |
s close |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3323 |
] |
4896 | 3324 |
] fork |
3325 |
" |
|
623 | 3326 |
! ! |
3327 |
||
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3328 |
!Block methodsFor:'visiting'! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3329 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3330 |
acceptVisitor:aVisitor with:aParameter |
16730 | 3331 |
"dispatch for visitor pattern; send #visitBlock:with: to aVisitor" |
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3332 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3333 |
^ aVisitor visitBlock:self with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3334 |
! ! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3335 |
|
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
3336 |
!Block class methodsFor:'documentation'! |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3337 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3338 |
version |
18959 | 3339 |
^ '$Header$' |
12118
41ee8ff1908e
comment/format in: #deferredValue
Claus Gittinger <cg@exept.de>
parents:
11998
diff
changeset
|
3340 |
! |
41ee8ff1908e
comment/format in: #deferredValue
Claus Gittinger <cg@exept.de>
parents:
11998
diff
changeset
|
3341 |
|
41ee8ff1908e
comment/format in: #deferredValue
Claus Gittinger <cg@exept.de>
parents:
11998
diff
changeset
|
3342 |
version_CVS |
18959 | 3343 |
^ '$Header$' |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3344 |
! ! |
6785 | 3345 |
|
14683 | 3346 |
|
623 | 3347 |
Block initialize! |