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