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