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