author | Claus Gittinger <cg@exept.de> |
Tue, 20 Jul 1999 18:40:26 +0200 | |
changeset 4418 | ea5bee8b8a28 |
parent 4417 | 6295d85911a7 |
child 4419 | 3cd7688f4c1b |
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 |
||
4417 | 514 |
ensure:aBlock |
515 |
"evaluate the receiver and return its result. |
|
516 |
After evaluation, also evaluate aBlock but ignore its result. |
|
4418 | 517 |
aBlock is also evaluated in case of abnormal termination. |
518 |
(the same as #valueNowOrOnUnwindDo:)" |
|
4417 | 519 |
|
520 |
|v| |
|
521 |
||
522 |
"/ #ensure could be implemented as: |
|
523 |
"/ |
|
524 |
"/ [ |
|
525 |
"/ v := self value. |
|
526 |
"/ ] valueNowOrOnUnwindDo:aBlock. |
|
527 |
"/ ^ v |
|
528 |
"/ |
|
529 |
"/ however, we save one block creation, by doing it as: |
|
530 |
"/ |
|
531 |
thisContext markForUnwind. |
|
532 |
v := self value. "the real logic is in Context>>unwind" |
|
533 |
thisContext unmarkForUnwind. |
|
534 |
aBlock value. |
|
535 |
^ v |
|
536 |
||
537 |
" |
|
538 |
[ |
|
539 |
[ |
|
540 |
Transcript showCR:'one'. |
|
541 |
Processor activeProcess terminate. |
|
542 |
Transcript showCR:'two'. |
|
543 |
] ensure:[ |
|
544 |
Transcript showCR:'three'. |
|
545 |
]. |
|
546 |
] fork. |
|
547 |
" |
|
548 |
" |
|
549 |
[ |
|
550 |
[ |
|
551 |
Transcript showCR:'one'. |
|
552 |
Transcript showCR:'two'. |
|
553 |
] ensure:[ |
|
554 |
Transcript showCR:'three'. |
|
555 |
]. |
|
556 |
] fork. |
|
557 |
" |
|
558 |
||
559 |
! |
|
560 |
||
1 | 561 |
value |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
562 |
"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
|
563 |
The receiver must be a block without arguments." |
1 | 564 |
|
565 |
%{ /* NOCONTEXT */ |
|
566 |
||
567 |
REGISTER OBJFUNC thecode; |
|
568 |
OBJ home; |
|
569 |
||
1133 | 570 |
if (__INST(nargs) == __MKSMALLINT(0)) { |
1 | 571 |
#if defined(THIS_CONTEXT) |
328 | 572 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 573 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 574 |
#endif |
328 | 575 |
|
1133 | 576 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 577 |
#ifdef NEW_BLOCK_CALL |
154 | 578 |
if (thecode != (OBJFUNC)nil) { |
579 |
/* compiled machine code */ |
|
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
580 |
RETURN ( (*thecode)(self) ); |
154 | 581 |
} |
582 |
/* interpreted code */ |
|
328 | 583 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
584 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
328 | 585 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
586 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
328 | 587 |
# endif |
11 | 588 |
#else |
1133 | 589 |
home = __BlockInstPtr(self)->b_home; |
154 | 590 |
if (thecode != (OBJFUNC)nil) { |
591 |
/* compiled machine code */ |
|
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
592 |
RETURN ( (*thecode)(home) ); |
154 | 593 |
} |
594 |
/* interpreted code */ |
|
328 | 595 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
596 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
328 | 597 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
598 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
328 | 599 |
# endif |
11 | 600 |
#endif |
1 | 601 |
} |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
602 |
%}. |
103 | 603 |
^ self wrongNumberOfArguments:0 |
1 | 604 |
! |
605 |
||
606 |
value:arg |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
607 |
"evaluate the receiver with one argument. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
608 |
The receiver must be a 1-arg block." |
1 | 609 |
|
610 |
%{ /* NOCONTEXT */ |
|
611 |
||
612 |
REGISTER OBJFUNC thecode; |
|
613 |
OBJ home; |
|
614 |
||
1133 | 615 |
if (__INST(nargs) == __MKSMALLINT(1)) { |
1 | 616 |
#if defined(THIS_CONTEXT) |
328 | 617 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 618 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 619 |
#endif |
1133 | 620 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 621 |
#ifdef NEW_BLOCK_CALL |
154 | 622 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
623 |
RETURN ( (*thecode)(self, arg) ); |
154 | 624 |
} |
625 |
/* interpreted code */ |
|
328 | 626 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
627 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, &arg) ); |
328 | 628 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
629 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, arg) ); |
328 | 630 |
# endif |
1 | 631 |
#else |
1133 | 632 |
home = __BlockInstPtr(self)->b_home; |
154 | 633 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
634 |
RETURN ( (*thecode)(home, arg) ); |
154 | 635 |
} |
636 |
/* interpreted code */ |
|
328 | 637 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
638 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, &arg) ); |
328 | 639 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
640 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, arg) ); |
328 | 641 |
# endif |
1 | 642 |
#endif |
643 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
644 |
%}. |
103 | 645 |
^ self wrongNumberOfArguments:1 |
1 | 646 |
! |
647 |
||
648 |
value:arg1 value:arg2 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
649 |
"evaluate the receiver with two arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
650 |
The receiver must be a 2-arg block." |
1 | 651 |
|
652 |
%{ /* NOCONTEXT */ |
|
653 |
||
654 |
REGISTER OBJFUNC thecode; |
|
655 |
OBJ home; |
|
656 |
||
1133 | 657 |
if (__INST(nargs) == __MKSMALLINT(2)) { |
1 | 658 |
#if defined(THIS_CONTEXT) |
328 | 659 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 660 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 661 |
#endif |
1133 | 662 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 663 |
#ifdef NEW_BLOCK_CALL |
154 | 664 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
665 |
RETURN ( (*thecode)(self, arg1, arg2) ); |
154 | 666 |
} |
328 | 667 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
668 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, &arg1) ); |
328 | 669 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
670 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, arg1, arg2) ); |
328 | 671 |
# endif |
1 | 672 |
#else |
1133 | 673 |
home = __BlockInstPtr(self)->b_home; |
154 | 674 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
675 |
RETURN ( (*thecode)(home, arg1, arg2) ); |
154 | 676 |
} |
328 | 677 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
678 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, &arg1) ); |
328 | 679 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
680 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, arg1, arg2) ); |
328 | 681 |
# endif |
1 | 682 |
#endif |
683 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
684 |
%}. |
103 | 685 |
^ self wrongNumberOfArguments:2 |
1 | 686 |
! |
687 |
||
688 |
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
|
689 |
"evaluate the receiver with three arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
690 |
The receiver must be a 3-arg block." |
1 | 691 |
|
692 |
%{ /* NOCONTEXT */ |
|
693 |
||
694 |
REGISTER OBJFUNC thecode; |
|
695 |
OBJ home; |
|
696 |
||
1133 | 697 |
if (__INST(nargs) == __MKSMALLINT(3)) { |
1 | 698 |
#if defined(THIS_CONTEXT) |
328 | 699 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 700 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 701 |
#endif |
1133 | 702 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 703 |
#ifdef NEW_BLOCK_CALL |
154 | 704 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
705 |
RETURN ( (*thecode)(self, arg1, arg2, arg3) ); |
154 | 706 |
} |
328 | 707 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
708 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, &arg1) ); |
328 | 709 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
710 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, arg1, arg2, arg3) ); |
328 | 711 |
# endif |
1 | 712 |
#else |
1133 | 713 |
home = __BlockInstPtr(self)->b_home; |
154 | 714 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
715 |
RETURN ( (*thecode)(home, arg1, arg2, arg3) ); |
154 | 716 |
} |
328 | 717 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
718 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, &arg1) ); |
328 | 719 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
720 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, arg1, arg2, arg3) ); |
328 | 721 |
# endif |
1 | 722 |
#endif |
723 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
724 |
%}. |
103 | 725 |
^ self wrongNumberOfArguments:3 |
1 | 726 |
! |
727 |
||
728 |
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
|
729 |
"evaluate the receiver with four arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
730 |
The receiver must be a 4-arg block." |
1 | 731 |
|
732 |
%{ /* NOCONTEXT */ |
|
733 |
||
734 |
REGISTER OBJFUNC thecode; |
|
735 |
OBJ home; |
|
736 |
||
1133 | 737 |
if (__INST(nargs) == __MKSMALLINT(4)) { |
1 | 738 |
#if defined(THIS_CONTEXT) |
328 | 739 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 740 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 741 |
#endif |
1133 | 742 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 743 |
#ifdef NEW_BLOCK_CALL |
154 | 744 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
745 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4) ); |
154 | 746 |
} |
328 | 747 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
748 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, &arg1) ); |
328 | 749 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
750 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 751 |
# endif |
1 | 752 |
#else |
1133 | 753 |
home = __BlockInstPtr(self)->b_home; |
154 | 754 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
755 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4) ); |
154 | 756 |
} |
328 | 757 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
758 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, &arg1) ); |
328 | 759 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
760 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 761 |
# endif |
1 | 762 |
#endif |
763 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
764 |
%}. |
103 | 765 |
^ self wrongNumberOfArguments:4 |
1 | 766 |
! |
767 |
||
768 |
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
|
769 |
"evaluate the receiver with five arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
770 |
The receiver must be a 5-arg block." |
1 | 771 |
|
772 |
%{ /* NOCONTEXT */ |
|
773 |
||
774 |
REGISTER OBJFUNC thecode; |
|
775 |
OBJ home; |
|
776 |
||
1133 | 777 |
if (__INST(nargs) == __MKSMALLINT(5)) { |
1 | 778 |
#if defined(THIS_CONTEXT) |
328 | 779 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 780 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 781 |
#endif |
1133 | 782 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 783 |
#ifdef NEW_BLOCK_CALL |
154 | 784 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
785 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5) ); |
154 | 786 |
} |
328 | 787 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
788 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, &arg1) ); |
328 | 789 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
790 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 791 |
# endif |
1 | 792 |
#else |
1133 | 793 |
home = __BlockInstPtr(self)->b_home; |
154 | 794 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
795 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5) ); |
154 | 796 |
} |
328 | 797 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
798 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, &arg1) ); |
328 | 799 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
800 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 801 |
# endif |
1 | 802 |
#endif |
803 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
804 |
%}. |
103 | 805 |
^ self wrongNumberOfArguments:5 |
1 | 806 |
! |
807 |
||
808 |
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
|
809 |
"evaluate the receiver with six arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
810 |
The receiver must be a 6-arg block." |
1 | 811 |
|
812 |
%{ /* NOCONTEXT */ |
|
813 |
||
814 |
REGISTER OBJFUNC thecode; |
|
815 |
OBJ home; |
|
816 |
||
1133 | 817 |
if (__INST(nargs) == __MKSMALLINT(6)) { |
1 | 818 |
#if defined(THIS_CONTEXT) |
328 | 819 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 820 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 821 |
#endif |
1133 | 822 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 823 |
#ifdef NEW_BLOCK_CALL |
154 | 824 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
825 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6) ); |
154 | 826 |
} |
328 | 827 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
828 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, &arg1) ); |
328 | 829 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
830 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 831 |
# endif |
1 | 832 |
#else |
1133 | 833 |
home = __BlockInstPtr(self)->b_home; |
154 | 834 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
835 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6) ); |
154 | 836 |
} |
328 | 837 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
838 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, &arg1) ); |
328 | 839 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
840 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 841 |
# endif |
1 | 842 |
#endif |
843 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
844 |
%}. |
103 | 845 |
^ self wrongNumberOfArguments:6 |
1 | 846 |
! |
847 |
||
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
848 |
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
|
849 |
"evaluate the receiver with seven arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
850 |
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
|
851 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
852 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
853 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
854 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
855 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
856 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
857 |
if (__INST(nargs) == __MKSMALLINT(7)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
858 |
#if defined(THIS_CONTEXT) |
2238 | 859 |
if (__ISVALID_ILC_LNO(__pilc)) |
860 |
__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
|
861 |
#endif |
2238 | 862 |
thecode = __BlockInstPtr(self)->b_code; |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
863 |
#ifdef NEW_BLOCK_CALL |
2238 | 864 |
if (thecode != (OBJFUNC)nil) { |
865 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
866 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
867 |
# ifdef PASS_ARG_POINTER |
2238 | 868 |
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
|
869 |
# else |
2238 | 870 |
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
|
871 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
872 |
#else |
2238 | 873 |
home = __BlockInstPtr(self)->b_home; |
874 |
if (thecode != (OBJFUNC)nil) { |
|
875 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
876 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
877 |
# ifdef PASS_ARG_POINTER |
2238 | 878 |
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
|
879 |
# else |
2238 | 880 |
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
|
881 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
882 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
883 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
884 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
885 |
^ self wrongNumberOfArguments:7 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
886 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
887 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
888 |
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
|
889 |
"evaluate the receiver with eight arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
890 |
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
|
891 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
892 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
893 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
894 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
895 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
896 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
897 |
if (__INST(nargs) == __MKSMALLINT(8)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
898 |
#if defined(THIS_CONTEXT) |
2238 | 899 |
if (__ISVALID_ILC_LNO(__pilc)) |
900 |
__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
|
901 |
#endif |
2238 | 902 |
thecode = __BlockInstPtr(self)->b_code; |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
903 |
#ifdef NEW_BLOCK_CALL |
2238 | 904 |
if (thecode != (OBJFUNC)nil) { |
905 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
906 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
907 |
# ifdef PASS_ARG_POINTER |
2238 | 908 |
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
|
909 |
# else |
2238 | 910 |
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
|
911 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
912 |
#else |
2238 | 913 |
home = __BlockInstPtr(self)->b_home; |
914 |
if (thecode != (OBJFUNC)nil) { |
|
915 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
916 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
917 |
# ifdef PASS_ARG_POINTER |
2238 | 918 |
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
|
919 |
# else |
2238 | 920 |
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
|
921 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
922 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
923 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
924 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
925 |
^ self wrongNumberOfArguments:8 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
926 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
927 |
|
3688 | 928 |
valueAt:priority |
929 |
"evaluate the receiver, at the given prioriy; |
|
930 |
i.e. change the priority for the execution of the receiver." |
|
931 |
||
932 |
|oldPrio retVal| |
|
933 |
||
934 |
oldPrio := Processor activePriority. |
|
935 |
[ |
|
936 |
Processor activeProcess priority:priority. |
|
937 |
retVal := self value. |
|
938 |
] valueNowOrOnUnwindDo:[ |
|
939 |
Processor activeProcess priority:oldPrio |
|
940 |
]. |
|
941 |
^ retVal |
|
942 |
||
943 |
" |
|
944 |
[ |
|
945 |
1000 timesRepeat:[ |
|
946 |
1000 factorial |
|
947 |
] |
|
948 |
] valueAt:3 |
|
949 |
" |
|
950 |
||
951 |
"Created: / 29.7.1998 / 19:19:48 / cg" |
|
952 |
! |
|
953 |
||
1 | 954 |
valueWithArguments:argArray |
955 |
"evaluate the receiver with arguments taken from argArray. |
|
313 | 956 |
ArgArray must be either an Array or nil. |
1 | 957 |
The size of the argArray must match the number of arguments the receiver expects." |
958 |
||
3497 | 959 |
|a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12| |
1 | 960 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
961 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
3497 | 962 |
^ self badArgumentArry |
1 | 963 |
]. |
964 |
(argArray size == nargs) ifFalse:[ |
|
3497 | 965 |
^ self wrongNumberOfArguments:(argArray size) |
1 | 966 |
]. |
967 |
%{ |
|
968 |
||
969 |
REGISTER OBJFUNC thecode; |
|
970 |
OBJ home; |
|
67 | 971 |
REGISTER OBJ *ap; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
972 |
int __nargs; |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
973 |
OBJ nA; |
1 | 974 |
|
975 |
#if defined(THIS_CONTEXT) |
|
328 | 976 |
if (__ISVALID_ILC_LNO(__pilc)) |
3497 | 977 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 978 |
#endif |
1133 | 979 |
thecode = __BlockInstPtr(self)->b_code; |
1037 | 980 |
|
981 |
#ifndef NEW_BLOCK_CALL |
|
1133 | 982 |
home = __BlockInstPtr(self)->b_home; |
1037 | 983 |
if (thecode != (OBJFUNC)nil) { |
3497 | 984 |
if ((nA = __INST(nargs)) == __MKSMALLINT(0)) { |
985 |
RETURN ( (*thecode)(home) ); |
|
986 |
} |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
987 |
|
3497 | 988 |
switch (__intVal(__INST(nargs))) { |
989 |
default: |
|
990 |
goto error; |
|
991 |
case 12: |
|
992 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
993 |
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]) ); |
|
994 |
case 11: |
|
995 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
996 |
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]) ); |
|
997 |
case 10: |
|
998 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
999 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) ); |
|
1000 |
case 9: |
|
1001 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1002 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) ); |
|
1003 |
case 8: |
|
1004 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1005 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
|
1006 |
case 7: |
|
1007 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1008 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
1009 |
case 6: |
|
1010 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1011 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
1012 |
case 5: |
|
1013 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1014 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1015 |
case 4: |
|
1016 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1017 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) ); |
|
1018 |
case 3: |
|
1019 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1020 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) ); |
|
1021 |
case 2: |
|
1022 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1023 |
RETURN ( (*thecode)(home, ap[0], ap[1]) ); |
|
1024 |
case 1: |
|
1025 |
RETURN ( (*thecode)(home, __ArrayInstPtr(argArray)->a_element[0]) ); |
|
1026 |
case 0: |
|
1027 |
RETURN ( (*thecode)(home) ); |
|
1028 |
break; |
|
1029 |
} |
|
1037 | 1030 |
} |
1031 |
#endif |
|
1032 |
||
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1033 |
__nargs = __intVal(__INST(nargs)); |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1034 |
if (__nargs) { |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1035 |
switch (__nargs) { |
3497 | 1036 |
default: |
1037 |
goto error; |
|
1038 |
case 12: |
|
1039 |
a12 = __ArrayInstPtr(argArray)->a_element[11]; |
|
1040 |
case 11: |
|
1041 |
a11 = __ArrayInstPtr(argArray)->a_element[10]; |
|
1042 |
case 10: |
|
1043 |
a10 = __ArrayInstPtr(argArray)->a_element[9]; |
|
1044 |
case 9: |
|
1045 |
a9 = __ArrayInstPtr(argArray)->a_element[8]; |
|
1046 |
case 8: |
|
1047 |
a8 = __ArrayInstPtr(argArray)->a_element[7]; |
|
1048 |
case 7: |
|
1049 |
a7 = __ArrayInstPtr(argArray)->a_element[6]; |
|
1050 |
case 6: |
|
1051 |
a6 = __ArrayInstPtr(argArray)->a_element[5]; |
|
1052 |
case 5: |
|
1053 |
a5 = __ArrayInstPtr(argArray)->a_element[4]; |
|
1054 |
case 4: |
|
1055 |
a4 = __ArrayInstPtr(argArray)->a_element[3]; |
|
1056 |
case 3: |
|
1057 |
a3 = __ArrayInstPtr(argArray)->a_element[2]; |
|
1058 |
case 2: |
|
1059 |
a2 = __ArrayInstPtr(argArray)->a_element[1]; |
|
1060 |
case 1: |
|
1061 |
a1 = __ArrayInstPtr(argArray)->a_element[0]; |
|
1062 |
case 0: |
|
1063 |
break; |
|
1064 |
} |
|
1 | 1065 |
} |
1133 | 1066 |
|
11 | 1067 |
#ifdef NEW_BLOCK_CALL |
1 | 1068 |
if (thecode != (OBJFUNC)nil) { |
3497 | 1069 |
RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
11 | 1070 |
} |
328 | 1071 |
# ifdef PASS_ARG_POINTER |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1072 |
RETURN ( __interpret(self, __nargs, nil, nil, nil, nil, &a1) ); |
328 | 1073 |
# else |
3497 | 1074 |
RETURN ( __interpret(self, __nargs, nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
328 | 1075 |
# endif |
1037 | 1076 |
|
1 | 1077 |
#else |
1037 | 1078 |
|
328 | 1079 |
# ifdef PASS_ARG_POINTER |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1080 |
RETURN ( __interpret(self, __nargs, nil, home, nil, nil, &a1) ); |
328 | 1081 |
# else |
3497 | 1082 |
RETURN ( __interpret(self, __nargs, nil, home, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
328 | 1083 |
# endif |
1037 | 1084 |
|
1 | 1085 |
#endif |
67 | 1086 |
|
11 | 1087 |
error: ; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1088 |
%}. |
138 | 1089 |
" |
3497 | 1090 |
the above code only supports up-to 12 arguments |
138 | 1091 |
" |
128 | 1092 |
^ ArgumentSignal |
3497 | 1093 |
raiseRequestWith:self |
1094 |
errorString:'only blocks with up-to 12 arguments supported' |
|
154 | 1095 |
! ! |
1096 |
||
623 | 1097 |
!Block methodsFor:'looping'! |
325 | 1098 |
|
623 | 1099 |
doUntil:aBlock |
1100 |
"repeat the receiver block until aBlock evaluates to true. |
|
1101 |
The receiver is evaluated at least once. |
|
1102 |
This is the same as '... doWhile:[... not]' " |
|
325 | 1103 |
|
623 | 1104 |
"this implementation is for purists ... :-)" |
1105 |
||
1106 |
self value. |
|
1107 |
aBlock value ifTrue:[^ nil]. |
|
1108 |
thisContext restart |
|
325 | 1109 |
|
1110 |
" |
|
623 | 1111 |
|n| |
154 | 1112 |
|
623 | 1113 |
n := 1. |
1114 |
[n printNewline] doUntil:[ (n := n + 1) > 5 ] |
|
154 | 1115 |
" |
1 | 1116 |
! |
1117 |
||
623 | 1118 |
doWhile:aBlock |
1119 |
"repeat the receiver block until aBlock evaluates to false. |
|
1120 |
The receiver is evaluated at least once." |
|
67 | 1121 |
|
154 | 1122 |
"this implementation is for purists ... :-)" |
1123 |
||
623 | 1124 |
self value. |
1125 |
aBlock value ifFalse:[^ nil]. |
|
1126 |
thisContext restart |
|
1127 |
||
1128 |
" |
|
1129 |
|n| |
|
1130 |
||
1131 |
n := 1. |
|
1132 |
[n printNewline] doWhile:[ (n := n + 1) <= 5 ] |
|
1133 |
" |
|
1134 |
! |
|
1135 |
||
1136 |
loop |
|
1211 | 1137 |
"repeat the receiver forever |
1138 |
(the receiver block should contain a return somewhere). |
|
1139 |
The implementation below was inspired by a corresponding Self method." |
|
623 | 1140 |
|
1141 |
self value. |
|
67 | 1142 |
thisContext restart |
1143 |
||
1144 |
" |
|
1145 |
|n| |
|
1146 |
||
1147 |
n := 1. |
|
623 | 1148 |
[ |
2238 | 1149 |
n printNewline. |
1150 |
n >= 10 ifTrue:[^ nil]. |
|
1151 |
n := n + 1 |
|
623 | 1152 |
] loop |
1153 |
" |
|
1211 | 1154 |
|
1155 |
"Modified: 18.4.1996 / 13:50:40 / cg" |
|
623 | 1156 |
! |
1157 |
||
1158 |
loopWithExit |
|
1159 |
"the receiver must be a block of one argument. It is evaluated in a loop forever, |
|
1160 |
and is passed a block, which, if sent a value:-message, will exit the receiver block, |
|
1161 |
returning the parameter of the value:-message. Used for loops with exit in the middle. |
|
1162 |
Inspired by a corresponding Self method." |
|
1163 |
||
1164 |
|exitBlock| |
|
1165 |
||
1166 |
exitBlock := [:exitValue | ^ exitValue]. |
|
1167 |
[true] whileTrue:[self value:exitBlock] |
|
1168 |
||
1169 |
" |
|
1170 |
|i| |
|
1171 |
i := 1. |
|
1172 |
[:exit | |
|
1422 | 1173 |
Transcript showCR:i. |
623 | 1174 |
i == 5 ifTrue:[exit value:'thats it']. |
1175 |
i := i + 1 |
|
1176 |
] loopWithExit |
|
1177 |
" |
|
1178 |
! |
|
1179 |
||
1180 |
repeat |
|
1211 | 1181 |
"repeat the receiver forever - same as loop, for ST-80 compatibility. |
1182 |
(the receiver block should contain a return somewhere)." |
|
623 | 1183 |
|
1184 |
self value. |
|
1185 |
thisContext restart |
|
1211 | 1186 |
|
1187 |
"Modified: 18.4.1996 / 13:50:55 / cg" |
|
623 | 1188 |
! |
1189 |
||
1190 |
valueWithExit |
|
1191 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
|
1192 |
which, if sent a value:-message, will exit the receiver block, returning the parameter of the |
|
1193 |
value:-message. Used for premature returns to the caller. |
|
1194 |
Taken from a manchester goody (a similar construct also appears in Self)." |
|
1195 |
||
1211 | 1196 |
^ self value:[:exitValue | ^exitValue] |
623 | 1197 |
|
1198 |
" |
|
1199 |
[:exit | |
|
2238 | 1200 |
1 to:10 do:[:i | |
1201 |
Transcript showCR:i. |
|
1202 |
i == 5 ifTrue:[exit value:'thats it'] |
|
1203 |
]. |
|
1204 |
'regular block-value; never returned' |
|
623 | 1205 |
] valueWithExit |
1206 |
" |
|
1211 | 1207 |
|
1208 |
"Modified: 18.4.1996 / 13:51:38 / cg" |
|
623 | 1209 |
! |
1210 |
||
1211 |
whileFalse |
|
1212 |
"evaluate the receiver while it evaluates to false (ST80 compatibility)" |
|
1213 |
||
1214 |
"this implementation is for purists ... :-)" |
|
1215 |
||
1216 |
self value ifTrue:[^ nil]. |
|
1217 |
thisContext restart |
|
1218 |
||
1219 |
" |
|
1220 |
|n| |
|
1221 |
||
1222 |
n := 1. |
|
1223 |
[n printNewline. (n := n + 1) > 10] whileFalse |
|
67 | 1224 |
" |
1225 |
! |
|
1 | 1226 |
|
67 | 1227 |
whileFalse:aBlock |
1228 |
"evaluate the argument, aBlock while the receiver evaluates to false. |
|
1229 |
- usually open coded by compilers, but needed here for #perform |
|
1230 |
and expression evaluation." |
|
1231 |
||
154 | 1232 |
"this implementation is for purists ... :-)" |
1233 |
||
67 | 1234 |
self value ifTrue:[^ nil]. |
1235 |
aBlock value. |
|
1236 |
thisContext restart |
|
1237 |
||
1238 |
" |
|
1239 |
|n| |
|
1240 |
||
1241 |
n := 1. |
|
1242 |
[n > 10] whileFalse:[ |
|
154 | 1243 |
n printNewline. |
1244 |
n := n + 1 |
|
67 | 1245 |
] |
1246 |
" |
|
1 | 1247 |
! |
1248 |
||
1249 |
whileTrue |
|
67 | 1250 |
"evaluate the receiver while it evaluates to true (ST80 compatibility)" |
1 | 1251 |
|
154 | 1252 |
"this implementation is for purists ... :-)" |
1253 |
||
67 | 1254 |
self value ifFalse:[^ nil]. |
1255 |
thisContext restart |
|
1 | 1256 |
|
67 | 1257 |
" |
1258 |
|n| |
|
1 | 1259 |
|
67 | 1260 |
n := 1. |
1261 |
[n printNewline. (n := n + 1) <= 10] whileTrue |
|
1262 |
" |
|
1 | 1263 |
! |
1264 |
||
623 | 1265 |
whileTrue:aBlock |
1266 |
"evaluate the argument, aBlock while the receiver evaluates to true. |
|
1267 |
- usually open coded by compilers, but needed here for #perform |
|
1268 |
and expression evaluation." |
|
1 | 1269 |
|
154 | 1270 |
"this implementation is for purists ... :-)" |
1271 |
||
623 | 1272 |
self value ifFalse:[^ nil]. |
1273 |
aBlock value. |
|
67 | 1274 |
thisContext restart |
1275 |
||
1276 |
" |
|
1277 |
|n| |
|
1 | 1278 |
|
67 | 1279 |
n := 1. |
623 | 1280 |
[n <= 10] whileTrue:[ |
154 | 1281 |
n printNewline. |
1282 |
n := n + 1 |
|
623 | 1283 |
] |
68 | 1284 |
" |
67 | 1285 |
! ! |
1286 |
||
92 | 1287 |
!Block methodsFor:'printing & storing'! |
1 | 1288 |
|
1289 |
printOn:aStream |
|
44 | 1290 |
"append a a printed representation of the block to aStream" |
1291 |
||
213 | 1292 |
|homeClass h sel methodClass| |
54 | 1293 |
|
1294 |
"cheap blocks have no home context, but a method instead" |
|
1295 |
||
1296 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
154 | 1297 |
aStream nextPutAll:'[] in '. |
1 | 1298 |
|
154 | 1299 |
" |
1300 |
currently, some cheap blocks don't know where they have been created |
|
1301 |
" |
|
1302 |
aStream nextPutAll:' ??? (optimized)'. |
|
1303 |
^ self |
|
54 | 1304 |
]. |
1305 |
||
1306 |
"a full blown block (with home, but without method)" |
|
1307 |
||
1308 |
aStream nextPutAll:'[] in '. |
|
154 | 1309 |
h := self methodHome. |
1310 |
sel := h selector. |
|
1311 |
"/ old: |
|
1312 |
"/ home receiver class name printOn:aStream. |
|
1313 |
"/ new: |
|
212 | 1314 |
"/ (h searchClass whichClassImplements:sel) name printOn:aStream. |
213 | 1315 |
methodClass := h methodClass. |
1316 |
methodClass isNil ifTrue:[ |
|
1317 |
'UnboundMethod' printOn:aStream. |
|
1318 |
] ifFalse:[ |
|
1319 |
methodClass name printOn:aStream. |
|
1320 |
]. |
|
54 | 1321 |
aStream nextPut:$-. |
154 | 1322 |
sel printOn:aStream. |
54 | 1323 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1324 |
"/ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1325 |
"/ aStream nextPutAll:'[] in '. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1326 |
"/ homeClass := home containingClass. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1327 |
"/ homeClass notNil ifTrue:[ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1328 |
"/ homeClass name printOn:aStream. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1329 |
"/ aStream space. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1330 |
"/ (homeClass selectorForMethod:home) printOn:aStream |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1331 |
"/ ] ifFalse:[ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1332 |
"/ aStream nextPutAll:' ???' |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1333 |
"/ ] |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1334 |
"/ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1335 |
|
1 | 1336 |
! ! |
623 | 1337 |
|
1338 |
!Block methodsFor:'private accessing'! |
|
1339 |
||
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
1340 |
byteCode:bCode numArgs:numArgs numStack:numStack sourcePosition:srcPos initialPC:iPC literals:lits |
1265 | 1341 |
"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
|
1342 |
DANGER ALERT: this interface is strictly private." |
623 | 1343 |
|
1344 |
byteCode := bCode. |
|
1345 |
nargs := numArgs. |
|
1346 |
sourcePos := srcPos. |
|
1347 |
initialPC := iPC. |
|
1777 | 1348 |
flags := 0. |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
1349 |
self stackSize:numStack. |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1350 |
self literals:lits. |
1265 | 1351 |
|
1352 |
"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
|
1353 |
"Modified: 24.6.1996 / 12:37:37 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
1354 |
"Created: 13.4.1997 / 00:00:57 / cg" |
623 | 1355 |
! |
1356 |
||
1357 |
initialPC:initial |
|
1265 | 1358 |
"set the initial pc for evaluation. |
1359 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1360 |
|
1361 |
initialPC := initial |
|
1265 | 1362 |
|
1363 |
"Modified: 23.4.1996 / 16:05:39 / cg" |
|
623 | 1364 |
! |
1365 |
||
1366 |
numArgs:numArgs |
|
1265 | 1367 |
"set the number of arguments the receiver expects for evaluation. |
1368 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1369 |
|
1370 |
nargs := numArgs |
|
1265 | 1371 |
|
1372 |
"Modified: 23.4.1996 / 16:05:52 / cg" |
|
623 | 1373 |
! |
1374 |
||
1375 |
sourcePosition:position |
|
1265 | 1376 |
"set the position of the source within my method. |
1377 |
This interface is for the compiler only." |
|
623 | 1378 |
|
1379 |
sourcePos := position |
|
1265 | 1380 |
|
1381 |
"Modified: 23.4.1996 / 16:06:19 / cg" |
|
623 | 1382 |
! ! |
1383 |
||
1384 |
!Block methodsFor:'privileged evaluation'! |
|
1385 |
||
1386 |
valueUninterruptably |
|
1387 |
"evaluate the receiver with interrupts blocked. |
|
1388 |
This does not prevent preemption by a higher priority processes |
|
1389 |
if any becomes runnable due to the evaluation of the receiver |
|
1390 |
(i.e. if a semaphore is signalled)." |
|
1391 |
||
2301 | 1392 |
"we must keep track of blocking-state if this is called nested" |
1393 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
1394 |
"/ already blocked. |
|
1395 |
^ self value |
|
1396 |
]. |
|
864 | 1397 |
|
2301 | 1398 |
^ self valueNowOrOnUnwindDo:[OperatingSystem unblockInterrupts]. |
623 | 1399 |
! |
1400 |
||
1401 |
valueUnpreemptively |
|
1402 |
"evaluate the receiver without the possiblity of preemption |
|
1403 |
(i.e. at a very high priority)" |
|
1404 |
||
1405 |
|oldPrio activeProcess| |
|
1406 |
||
1407 |
activeProcess := Processor activeProcess. |
|
1408 |
oldPrio := activeProcess changePriority:(Processor highestPriority). |
|
864 | 1409 |
^ self valueNowOrOnUnwindDo:[ |
623 | 1410 |
activeProcess priority:oldPrio |
1411 |
] |
|
1412 |
! ! |
|
1413 |
||
1414 |
!Block methodsFor:'process creation'! |
|
1415 |
||
1416 |
fork |
|
1417 |
"create a new process executing the receiver at the current priority." |
|
1418 |
||
1419 |
^ self newProcess resume |
|
1420 |
! |
|
1421 |
||
1422 |
forkAt:priority |
|
1423 |
"create a new process executing the receiver at a different priority." |
|
1424 |
||
1425 |
^ (self newProcess priority:priority) resume |
|
1426 |
! |
|
1427 |
||
1428 |
forkWith:argArray |
|
1429 |
"create a new process executing the receiver, |
|
1430 |
passing elements in argArray as arguments to the receiver block." |
|
1431 |
||
1432 |
^ [self valueWithArguments:argArray] fork. |
|
1433 |
! |
|
1434 |
||
1435 |
newProcess |
|
1436 |
"create a new (unscheduled) process executing the receiver" |
|
1437 |
||
1438 |
^ Process for:self priority:(Processor activePriority) |
|
1439 |
! |
|
1440 |
||
1441 |
newProcessWithArguments:argArray |
|
1442 |
"create a new (unscheduled) process executing the receiver, |
|
1443 |
passing the elements in argArray as arguments to the receiver block." |
|
1444 |
||
1445 |
^ [self valueWithArguments:argArray] newProcess |
|
1446 |
! |
|
1447 |
||
1448 |
promise |
|
1449 |
"create a promise on the receiver. The promise will evaluate the |
|
1450 |
receiver and promise to return the value with the #value message. |
|
1451 |
The evaluation will be performed as a separate process. |
|
1452 |
Asking the promise for its value will either block the asking process |
|
1453 |
(if the evaluation has not yet been finished) or return the value |
|
1454 |
immediately." |
|
1455 |
||
1456 |
^ Promise value:self |
|
1457 |
||
1458 |
" |
|
1459 |
|p| |
|
1460 |
||
1461 |
p := [1000 factorial] promise. |
|
1462 |
'do something else ...'. |
|
1463 |
p value |
|
1464 |
" |
|
1465 |
! |
|
1466 |
||
1467 |
promiseAt:prio |
|
1468 |
"create a promise on the receiver. The promise will evaluate the |
|
1469 |
receiver and promise to return the value with the #value message. |
|
1470 |
The evaluation will be performed as a separate process running at prio. |
|
1471 |
Asking the promise for its value will either block the asking process |
|
1472 |
(if the evaluation has not yet been finished) or return the value |
|
1473 |
immediately." |
|
1474 |
||
1475 |
^ Promise value:self priority:prio |
|
1476 |
! ! |
|
1477 |
||
1478 |
!Block methodsFor:'testing'! |
|
1479 |
||
1480 |
isBlock |
|
1481 |
"return true, if this is a block - yes I am" |
|
1482 |
||
1483 |
^ true |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1484 |
! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1485 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1486 |
isVarArgBlock |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1487 |
"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
|
1488 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1489 |
^ false |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1490 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1491 |
"Created: 23.1.1997 / 04:59:51 / cg" |
623 | 1492 |
! ! |
1493 |
||
1494 |
!Block methodsFor:'unwinding'! |
|
1495 |
||
1496 |
valueNowOrOnUnwindDo:aBlock |
|
1497 |
"evaluate the receiver - after that, or when some method sent within unwinds (i.e. does |
|
1498 |
a long return), evaluate the argument, aBlock. |
|
1499 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1500 |
executed regardless of error actions" |
|
1501 |
||
1502 |
|v| |
|
1503 |
||
1504 |
thisContext markForUnwind. |
|
1505 |
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
|
1506 |
thisContext unmarkForUnwind. |
623 | 1507 |
aBlock value. |
1508 |
^ v |
|
1509 |
||
1510 |
" |
|
1511 |
in the following example, f will be closed even if the block |
|
1512 |
returns with 'oops'. There are many more applications of this kind |
|
1513 |
found in the system. |
|
1514 |
" |
|
1515 |
" |
|
1516 |
|f| |
|
1517 |
||
1518 |
f := 'Makefile' asFilename readStream. |
|
1519 |
[ |
|
2238 | 1520 |
l := f nextLine. |
1521 |
l isNil ifTrue:[^ 'oops'] |
|
623 | 1522 |
] valueNowOrOnUnwindDo:[ |
2238 | 1523 |
f close |
623 | 1524 |
] |
1525 |
" |
|
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1526 |
|
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1527 |
"Modified: 16.4.1996 / 11:05:26 / stefan" |
623 | 1528 |
! |
1529 |
||
1530 |
valueOnUnwindDo:aBlock |
|
1531 |
"evaluate the receiver - when some method sent within unwinds (i.e. does |
|
1532 |
a long return), evaluate the argument, aBlock. |
|
1533 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1534 |
executed regardless of error actions" |
|
1535 |
||
2286 | 1536 |
|v| |
1537 |
||
623 | 1538 |
thisContext markForUnwind. |
2286 | 1539 |
v := self value. "the real logic is in Context>>unwind" |
1540 |
thisContext unmarkForUnwind. |
|
1541 |
^ v |
|
1542 |
||
1543 |
"Modified: 27.1.1997 / 23:47:40 / cg" |
|
623 | 1544 |
! ! |
1545 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1546 |
!Block class methodsFor:'documentation'! |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1547 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1548 |
version |
4418 | 1549 |
^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.83 1999-07-20 16:40:26 cg Exp $' |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1550 |
! ! |
623 | 1551 |
Block initialize! |