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