author | Claus Gittinger <cg@exept.de> |
Thu, 17 Oct 1996 15:08:17 +0200 | |
changeset 1773 | 442d1b73ecb9 |
parent 1672 | 1b56d6e95c9e |
child 1777 | 150a1516ef75 |
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 |
||
249 | 13 |
CompiledCode subclass:#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) |
1254 | 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 |
|
1254 | 76 |
relative to methods source beginning |
222 | 77 |
initialPC <SmallInteger> the start position within the byteCode |
1254 | 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 |
|
1254 | 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:] |
|
91 |
Claus Gittinger |
|
92 |
||
93 |
[see also:] |
|
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: |
1316 | 103 |
[exBegin] |
1265 | 104 |
|b| |
105 |
||
1422 | 106 |
b := [ Transcript showCR:'hello' ]. |
1293 | 107 |
|
1422 | 108 |
Transcript showCR:'now evaluating the block ...'. |
1265 | 109 |
b value. |
1316 | 110 |
[exEnd] |
1265 | 111 |
|
112 |
||
1293 | 113 |
|
1265 | 114 |
even here, blocks are involved: |
115 |
(although, the compiler optimizes things if possible) |
|
1316 | 116 |
[exBegin] |
1422 | 117 |
Transcript showCR:'now evaluating one of two blocks ...'. |
1265 | 118 |
1 > 4 ifTrue:[ |
1422 | 119 |
Transcript showCR:'foo' |
1265 | 120 |
] ifFalse:[ |
1422 | 121 |
Transcript showCR:'bar' |
1265 | 122 |
] |
1316 | 123 |
[exEnd] |
1265 | 124 |
|
125 |
||
1293 | 126 |
|
1265 | 127 |
here things become obvious: |
1316 | 128 |
[exBegin] |
1265 | 129 |
|yesBlock noBlock| |
130 |
||
1422 | 131 |
yesBlock := [ Transcript showCR:'foo' ]. |
132 |
noBlock := [ Transcript showCR:'bar' ]. |
|
1265 | 133 |
|
1422 | 134 |
Transcript showCR:'now evaluating one of two blocks ...'. |
1265 | 135 |
1 > 4 ifTrue:yesBlock |
136 |
ifFalse:noBlock |
|
1316 | 137 |
[exEnd] |
1265 | 138 |
|
139 |
||
1293 | 140 |
|
1265 | 141 |
simple loops: |
142 |
not very objectOriented: |
|
1316 | 143 |
[exBegin] |
1265 | 144 |
|i| |
145 |
||
146 |
i := 1. |
|
147 |
[i < 10] whileTrue:[ |
|
1422 | 148 |
Transcript showCR:i. |
1265 | 149 |
i := i + 1 |
150 |
] |
|
1316 | 151 |
[exEnd] |
1265 | 152 |
|
153 |
||
154 |
using integer protocol: |
|
1316 | 155 |
[exBegin] |
1265 | 156 |
1 to:10 do:[:i | |
1422 | 157 |
Transcript showCR:i. |
1265 | 158 |
] |
1316 | 159 |
[exEnd] |
1265 | 160 |
|
161 |
||
162 |
interval protocol: |
|
1316 | 163 |
[exBegin] |
1265 | 164 |
(1 to:10) do:[:i | |
1422 | 165 |
Transcript showCR:i. |
1265 | 166 |
] |
1316 | 167 |
[exEnd] |
1265 | 168 |
|
169 |
||
1293 | 170 |
|
1265 | 171 |
looping over collections: |
172 |
||
1293 | 173 |
bad code: |
174 |
(only works with numeric-indexable collections) |
|
1316 | 175 |
[exBegin] |
1265 | 176 |
|i coll| |
177 |
||
178 |
coll := #(9 8 7 6 5). |
|
179 |
i := 1. |
|
180 |
[i <= coll size] whileTrue:[ |
|
1422 | 181 |
Transcript showCR:(coll at:i). |
1265 | 182 |
i := i + 1. |
183 |
] |
|
1316 | 184 |
[exEnd] |
1265 | 185 |
|
186 |
||
187 |
||
1293 | 188 |
just as bad (well, marginally better ;-): |
189 |
(only works with numeric-indexable collections) |
|
1316 | 190 |
[exBegin] |
1293 | 191 |
|coll| |
1265 | 192 |
|
193 |
coll := #(9 8 7 6 5). |
|
194 |
1 to:coll size do:[:i | |
|
1422 | 195 |
Transcript showCR:(coll at:i). |
1265 | 196 |
] |
1316 | 197 |
[exEnd] |
1265 | 198 |
|
199 |
||
200 |
||
1293 | 201 |
the smalltalk way: |
202 |
(works with any collection) |
|
1316 | 203 |
[exBegin] |
1293 | 204 |
|coll| |
1265 | 205 |
|
206 |
coll := #(9 8 7 6 5). |
|
207 |
coll do:[:element | |
|
1422 | 208 |
Transcript showCR:element. |
1265 | 209 |
] |
1316 | 210 |
[exEnd] |
1265 | 211 |
|
212 |
Rule: use enumeration protocol of the collection instead of |
|
213 |
manually indexing it. [with few exceptions] |
|
214 |
||
215 |
||
216 |
||
217 |
processes: |
|
218 |
||
219 |
forking a lightweight process (thread): |
|
1316 | 220 |
[exBegin] |
1265 | 221 |
[ |
1422 | 222 |
Transcript showCR:'waiting ...'. |
1265 | 223 |
Delay waitForSeconds:2. |
1422 | 224 |
Transcript showCR:'here I am'. |
1265 | 225 |
] fork |
1316 | 226 |
[exEnd] |
1265 | 227 |
|
228 |
||
229 |
||
230 |
some with low prio: |
|
1316 | 231 |
[exBegin] |
1265 | 232 |
[ |
1422 | 233 |
Transcript showCR:'computing ...'. |
1265 | 234 |
10000 factorial. |
1422 | 235 |
Transcript showCR:'here I am'. |
1265 | 236 |
] forkAt:(Processor userBackgroundPriority) |
1316 | 237 |
[exEnd] |
1265 | 238 |
|
239 |
||
1293 | 240 |
|
241 |
handling exceptions: |
|
1316 | 242 |
[exBegin] |
1265 | 243 |
Object errorSignal handle:[:ex | |
1422 | 244 |
Transcript showCR:'exception handler forces return'. |
1265 | 245 |
ex return |
246 |
] do:[ |
|
1422 | 247 |
Transcript showCR:'now, doing something bad ...'. |
1265 | 248 |
1 / 0. |
1422 | 249 |
Transcript showCR:'not reached' |
1265 | 250 |
] |
1316 | 251 |
[exEnd] |
1265 | 252 |
|
253 |
||
1293 | 254 |
|
255 |
performing cleanup actions: |
|
1316 | 256 |
[exBegin] |
1265 | 257 |
Object errorSignal handle:[:ex | |
1422 | 258 |
Transcript showCR:'exception handler forces return'. |
1265 | 259 |
ex return |
260 |
] do:[ |
|
261 |
[ |
|
1422 | 262 |
Transcript showCR:'doing something bad ...'. |
1265 | 263 |
1 / 0. |
1422 | 264 |
Transcript showCR:'not reached' |
1265 | 265 |
] valueOnUnwindDo:[ |
1422 | 266 |
Transcript showCR:'cleanup' |
1265 | 267 |
] |
268 |
] |
|
1316 | 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 ;-) |
|
1316 | 275 |
[exBegin] |
1265 | 276 |
|showBlock countBlock |
277 |
howMany |
|
278 |
top panel b1 b2| |
|
279 |
||
280 |
howMany := 0. |
|
281 |
||
1422 | 282 |
showBlock := [ Transcript showCR:howMany ]. |
1265 | 283 |
countBlock := [ howMany := howMany + 1 ]. |
284 |
||
285 |
top := StandardSystemView extent:200@200. |
|
286 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
287 |
||
288 |
b1 := Button label:'count up' in:panel. |
|
289 |
b1 action:countBlock. |
|
290 |
||
291 |
b2 := Button label:'show value' in:panel. |
|
292 |
b2 action:showBlock. |
|
293 |
||
294 |
top open. |
|
295 |
||
1422 | 296 |
Transcript showCR:'new process started;'. |
297 |
Transcript showCR:'notice: the blocks can still access the'. |
|
298 |
Transcript showCR:' howMany local variable.'. |
|
1316 | 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:[ |
1254 | 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 |
|
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
319 |
byteCode:bCode numArgs:numArgs 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)) |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
326 |
byteCode:bCode |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
327 |
numArgs:numArgs |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
328 |
sourcePosition:sourcePos |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
329 |
initialPC:initialPC |
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
330 |
literals:literals. |
1 | 331 |
^ newBlock |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
332 |
|
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
333 |
"Modified: 24.6.1996 / 12:36:48 / stefan" |
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
334 |
"Created: 17.10.1996 / 14:04:17 / cg" |
1 | 335 |
! |
336 |
||
22 | 337 |
new |
1 | 338 |
"catch creation of blocks - only the system creates blocks" |
339 |
||
128 | 340 |
^ InvalidNewSignal raise. |
1 | 341 |
! |
342 |
||
22 | 343 |
new:size |
1 | 344 |
"catch creation of blocks - only the system creates blocks" |
345 |
||
128 | 346 |
^ InvalidNewSignal raise. |
1 | 347 |
! ! |
348 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
349 |
!Block class methodsFor:'queries'! |
1 | 350 |
|
623 | 351 |
isBuiltInClass |
1264 | 352 |
"return true if this class is known by the run-time-system. |
353 |
Here, true is returned for myself, false for subclasses." |
|
11 | 354 |
|
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
355 |
^ self == Block |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
356 |
|
1264 | 357 |
"Modified: 23.4.1996 / 15:55:58 / cg" |
1626 | 358 |
! |
359 |
||
360 |
maxNumberOfArguments |
|
361 |
"return the maximum number of arguments a block can have. |
|
362 |
This is a limit in the VM, which may be removed in one of |
|
363 |
the next versions ..." |
|
364 |
||
365 |
%{ /* NOCONTEXT */ |
|
366 |
RETURN (__MKSMALLINT(MAX_METHOD_ARGS)); |
|
367 |
%} |
|
1 | 368 |
! ! |
369 |
||
623 | 370 |
!Block methodsFor:'STV compatibility'! |
1 | 371 |
|
623 | 372 |
on:aSignal do:exceptionBlock |
373 |
"added for ST/V compatibility; evaluate the receiver, |
|
374 |
handling aSignal. The argument, exceptionBlock is evaluated |
|
375 |
if the signal is raised during evaluation. |
|
376 |
Warning: no warranty, if the code below mimics ST/V's behavior |
|
377 |
correctly - give me a note if it does not ." |
|
1 | 378 |
|
623 | 379 |
aSignal handle:[:ex | |
380 |
exceptionBlock value. |
|
381 |
ex return |
|
382 |
] do:self |
|
1 | 383 |
|
623 | 384 |
" |
385 |
[ |
|
386 |
1 foo |
|
387 |
] on:MessageNotUnderstoodSignal do:[] |
|
388 |
" |
|
389 |
! ! |
|
390 |
||
391 |
!Block methodsFor:'accessing'! |
|
154 | 392 |
|
393 |
home |
|
394 |
"return the receivers home context (the context where it was |
|
395 |
created). For cheap blocks, nil is returned" |
|
396 |
||
397 |
^ home |
|
161 | 398 |
! |
399 |
||
400 |
method |
|
401 |
"return the receivers method |
|
402 |
(the method where the block was created)." |
|
403 |
||
404 |
home notNil ifTrue:[ |
|
405 |
^ home method |
|
406 |
]. |
|
407 |
^ nil |
|
623 | 408 |
! |
11 | 409 |
|
623 | 410 |
methodHome |
411 |
"return the receivers method home context (the context where it was |
|
412 |
defined). For cheap blocks, nil is returned" |
|
413 |
||
414 |
home notNil ifTrue:[ |
|
415 |
^ home methodHome |
|
416 |
]. |
|
417 |
^ home |
|
11 | 418 |
! |
419 |
||
623 | 420 |
numArgs |
421 |
"return the number of arguments I expect for evaluation" |
|
1 | 422 |
|
623 | 423 |
^ nargs |
424 |
! ! |
|
1 | 425 |
|
623 | 426 |
!Block methodsFor:'copying'! |
1 | 427 |
|
623 | 428 |
deepCopy |
429 |
"raise an error - deepCopy is not allowed for blocks" |
|
1 | 430 |
|
623 | 431 |
^ self deepCopyError |
1 | 432 |
! ! |
433 |
||
434 |
!Block methodsFor:'error handling'! |
|
435 |
||
328 | 436 |
invalidCodeObject |
67 | 437 |
"this error is triggered by the interpreter when a non-Block object |
438 |
is about to be executed. |
|
439 |
In this case, the VM sends this to the bad method (the receiver). |
|
440 |
Can only happen when the Compiler/runtime system is broken or |
|
441 |
someone played around." |
|
1 | 442 |
|
128 | 443 |
^ InvalidCodeSignal |
154 | 444 |
raiseRequestWith:self |
445 |
errorString:'invalid block - not executable' |
|
623 | 446 |
! |
447 |
||
448 |
wrongNumberOfArguments:numberGiven |
|
449 |
"report that the number of arguments given does not match the number expected" |
|
450 |
||
451 |
^ ArgumentSignal |
|
452 |
raiseRequestWith:self |
|
453 |
errorString:('block got ' , numberGiven printString , |
|
454 |
' args while ' , nargs printString , ' where expected') |
|
1 | 455 |
! ! |
456 |
||
457 |
!Block methodsFor:'evaluation'! |
|
458 |
||
459 |
value |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
460 |
"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
|
461 |
The receiver must be a block without arguments." |
1 | 462 |
|
463 |
%{ /* NOCONTEXT */ |
|
464 |
||
465 |
REGISTER OBJFUNC thecode; |
|
466 |
OBJ home; |
|
467 |
||
1133 | 468 |
if (__INST(nargs) == __MKSMALLINT(0)) { |
1 | 469 |
#if defined(THIS_CONTEXT) |
328 | 470 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 471 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 472 |
#endif |
328 | 473 |
|
1133 | 474 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 475 |
#ifdef NEW_BLOCK_CALL |
154 | 476 |
if (thecode != (OBJFUNC)nil) { |
477 |
/* compiled machine code */ |
|
478 |
RETURN ( (*thecode)(self, COMMA_SND) ); |
|
479 |
} |
|
480 |
/* interpreted code */ |
|
328 | 481 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
482 |
RETURN ( __interpret(self, 0, nil, nil COMMA_SND, nil, nil) ); |
328 | 483 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
484 |
RETURN ( __interpret(self, 0, nil, nil COMMA_SND, nil, nil) ); |
328 | 485 |
# endif |
11 | 486 |
#else |
1133 | 487 |
home = __BlockInstPtr(self)->b_home; |
154 | 488 |
if (thecode != (OBJFUNC)nil) { |
489 |
/* compiled machine code */ |
|
490 |
RETURN ( (*thecode)(home COMMA_SND) ); |
|
491 |
} |
|
492 |
/* interpreted code */ |
|
328 | 493 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
494 |
RETURN ( __interpret(self, 0, nil, home COMMA_SND, nil, nil) ); |
328 | 495 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
496 |
RETURN ( __interpret(self, 0, nil, home COMMA_SND, nil, nil) ); |
328 | 497 |
# endif |
11 | 498 |
#endif |
1 | 499 |
} |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
500 |
%}. |
103 | 501 |
^ self wrongNumberOfArguments:0 |
1 | 502 |
! |
503 |
||
504 |
value:arg |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
505 |
"evaluate the receiver with one argument. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
506 |
The receiver must be a 1-arg block." |
1 | 507 |
|
508 |
%{ /* NOCONTEXT */ |
|
509 |
||
510 |
REGISTER OBJFUNC thecode; |
|
511 |
OBJ home; |
|
512 |
||
1133 | 513 |
if (__INST(nargs) == __MKSMALLINT(1)) { |
1 | 514 |
#if defined(THIS_CONTEXT) |
328 | 515 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 516 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 517 |
#endif |
1133 | 518 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 519 |
#ifdef NEW_BLOCK_CALL |
154 | 520 |
if (thecode != (OBJFUNC)nil) { |
521 |
RETURN ( (*thecode)(self COMMA_SND, arg) ); |
|
522 |
} |
|
523 |
/* interpreted code */ |
|
328 | 524 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
525 |
RETURN ( __interpret(self, 1, nil, nil COMMA_SND, nil, nil, &arg) ); |
328 | 526 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
527 |
RETURN ( __interpret(self, 1, nil, nil COMMA_SND, nil, nil, arg) ); |
328 | 528 |
# endif |
1 | 529 |
#else |
1133 | 530 |
home = __BlockInstPtr(self)->b_home; |
154 | 531 |
if (thecode != (OBJFUNC)nil) { |
532 |
RETURN ( (*thecode)(home COMMA_SND, arg) ); |
|
533 |
} |
|
534 |
/* interpreted code */ |
|
328 | 535 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
536 |
RETURN ( __interpret(self, 1, nil, home COMMA_SND, nil, nil, &arg) ); |
328 | 537 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
538 |
RETURN ( __interpret(self, 1, nil, home COMMA_SND, nil, nil, arg) ); |
328 | 539 |
# endif |
1 | 540 |
#endif |
541 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
542 |
%}. |
103 | 543 |
^ self wrongNumberOfArguments:1 |
1 | 544 |
! |
545 |
||
546 |
value:arg1 value:arg2 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
547 |
"evaluate the receiver with two arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
548 |
The receiver must be a 2-arg block." |
1 | 549 |
|
550 |
%{ /* NOCONTEXT */ |
|
551 |
||
552 |
REGISTER OBJFUNC thecode; |
|
553 |
OBJ home; |
|
554 |
||
1133 | 555 |
if (__INST(nargs) == __MKSMALLINT(2)) { |
1 | 556 |
#if defined(THIS_CONTEXT) |
328 | 557 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 558 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 559 |
#endif |
1133 | 560 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 561 |
#ifdef NEW_BLOCK_CALL |
154 | 562 |
if (thecode != (OBJFUNC)nil) { |
563 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2) ); |
|
564 |
} |
|
328 | 565 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
566 |
RETURN ( __interpret(self, 2, nil, nil COMMA_SND, nil, nil, &arg1) ); |
328 | 567 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
568 |
RETURN ( __interpret(self, 2, nil, nil COMMA_SND, nil, nil, arg1, arg2) ); |
328 | 569 |
# endif |
1 | 570 |
#else |
1133 | 571 |
home = __BlockInstPtr(self)->b_home; |
154 | 572 |
if (thecode != (OBJFUNC)nil) { |
573 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2) ); |
|
574 |
} |
|
328 | 575 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
576 |
RETURN ( __interpret(self, 2, nil, home COMMA_SND, nil, nil, &arg1) ); |
328 | 577 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
578 |
RETURN ( __interpret(self, 2, nil, home COMMA_SND, nil, nil, arg1, arg2) ); |
328 | 579 |
# endif |
1 | 580 |
#endif |
581 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
582 |
%}. |
103 | 583 |
^ self wrongNumberOfArguments:2 |
1 | 584 |
! |
585 |
||
586 |
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
|
587 |
"evaluate the receiver with three arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
588 |
The receiver must be a 3-arg block." |
1 | 589 |
|
590 |
%{ /* NOCONTEXT */ |
|
591 |
||
592 |
REGISTER OBJFUNC thecode; |
|
593 |
OBJ home; |
|
594 |
||
1133 | 595 |
if (__INST(nargs) == __MKSMALLINT(3)) { |
1 | 596 |
#if defined(THIS_CONTEXT) |
328 | 597 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 598 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 599 |
#endif |
1133 | 600 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 601 |
#ifdef NEW_BLOCK_CALL |
154 | 602 |
if (thecode != (OBJFUNC)nil) { |
603 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3) ); |
|
604 |
} |
|
328 | 605 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
606 |
RETURN ( __interpret(self, 3, nil, nil COMMA_SND, nil, nil, &arg1) ); |
328 | 607 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
608 |
RETURN ( __interpret(self, 3, nil, nil COMMA_SND, nil, nil, arg1, arg2, arg3) ); |
328 | 609 |
# endif |
1 | 610 |
#else |
1133 | 611 |
home = __BlockInstPtr(self)->b_home; |
154 | 612 |
if (thecode != (OBJFUNC)nil) { |
613 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3) ); |
|
614 |
} |
|
328 | 615 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
616 |
RETURN ( __interpret(self, 3, nil, home COMMA_SND, nil, nil, &arg1) ); |
328 | 617 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
618 |
RETURN ( __interpret(self, 3, nil, home COMMA_SND, nil, nil, arg1, arg2, arg3) ); |
328 | 619 |
# endif |
1 | 620 |
#endif |
621 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
622 |
%}. |
103 | 623 |
^ self wrongNumberOfArguments:3 |
1 | 624 |
! |
625 |
||
626 |
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
|
627 |
"evaluate the receiver with four arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
628 |
The receiver must be a 4-arg block." |
1 | 629 |
|
630 |
%{ /* NOCONTEXT */ |
|
631 |
||
632 |
REGISTER OBJFUNC thecode; |
|
633 |
OBJ home; |
|
634 |
||
1133 | 635 |
if (__INST(nargs) == __MKSMALLINT(4)) { |
1 | 636 |
#if defined(THIS_CONTEXT) |
328 | 637 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 638 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 639 |
#endif |
1133 | 640 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 641 |
#ifdef NEW_BLOCK_CALL |
154 | 642 |
if (thecode != (OBJFUNC)nil) { |
643 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3, arg4) ); |
|
644 |
} |
|
328 | 645 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
646 |
RETURN ( __interpret(self, 4, nil, nil COMMA_SND, nil, nil, &arg1) ); |
328 | 647 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
648 |
RETURN ( __interpret(self, 4, nil, nil COMMA_SND, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 649 |
# endif |
1 | 650 |
#else |
1133 | 651 |
home = __BlockInstPtr(self)->b_home; |
154 | 652 |
if (thecode != (OBJFUNC)nil) { |
653 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3, arg4) ); |
|
654 |
} |
|
328 | 655 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
656 |
RETURN ( __interpret(self, 4, nil, home COMMA_SND, nil, nil, &arg1) ); |
328 | 657 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
658 |
RETURN ( __interpret(self, 4, nil, home COMMA_SND, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 659 |
# endif |
1 | 660 |
#endif |
661 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
662 |
%}. |
103 | 663 |
^ self wrongNumberOfArguments:4 |
1 | 664 |
! |
665 |
||
666 |
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
|
667 |
"evaluate the receiver with five arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
668 |
The receiver must be a 5-arg block." |
1 | 669 |
|
670 |
%{ /* NOCONTEXT */ |
|
671 |
||
672 |
REGISTER OBJFUNC thecode; |
|
673 |
OBJ home; |
|
674 |
||
1133 | 675 |
if (__INST(nargs) == __MKSMALLINT(5)) { |
1 | 676 |
#if defined(THIS_CONTEXT) |
328 | 677 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 678 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 679 |
#endif |
1133 | 680 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 681 |
#ifdef NEW_BLOCK_CALL |
154 | 682 |
if (thecode != (OBJFUNC)nil) { |
683 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3, arg4, arg5) ); |
|
684 |
} |
|
328 | 685 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
686 |
RETURN ( __interpret(self, 5, nil, nil COMMA_SND, nil, nil, &arg1) ); |
328 | 687 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
688 |
RETURN ( __interpret(self, 5, nil, nil COMMA_SND, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 689 |
# endif |
1 | 690 |
#else |
1133 | 691 |
home = __BlockInstPtr(self)->b_home; |
154 | 692 |
if (thecode != (OBJFUNC)nil) { |
693 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3, arg4, arg5) ); |
|
694 |
} |
|
328 | 695 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
696 |
RETURN ( __interpret(self, 5, nil, home COMMA_SND, nil, nil, &arg1) ); |
328 | 697 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
698 |
RETURN ( __interpret(self, 5, nil, home COMMA_SND, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 699 |
# endif |
1 | 700 |
#endif |
701 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
702 |
%}. |
103 | 703 |
^ self wrongNumberOfArguments:5 |
1 | 704 |
! |
705 |
||
706 |
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
|
707 |
"evaluate the receiver with six arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
708 |
The receiver must be a 6-arg block." |
1 | 709 |
|
710 |
%{ /* NOCONTEXT */ |
|
711 |
||
712 |
REGISTER OBJFUNC thecode; |
|
713 |
OBJ home; |
|
714 |
||
1133 | 715 |
if (__INST(nargs) == __MKSMALLINT(6)) { |
1 | 716 |
#if defined(THIS_CONTEXT) |
328 | 717 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 718 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 719 |
#endif |
1133 | 720 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 721 |
#ifdef NEW_BLOCK_CALL |
154 | 722 |
if (thecode != (OBJFUNC)nil) { |
723 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
724 |
} |
|
328 | 725 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
726 |
RETURN ( __interpret(self, 6, nil, nil COMMA_SND, nil, nil, &arg1) ); |
328 | 727 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
728 |
RETURN ( __interpret(self, 6, nil, nil COMMA_SND, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 729 |
# endif |
1 | 730 |
#else |
1133 | 731 |
home = __BlockInstPtr(self)->b_home; |
154 | 732 |
if (thecode != (OBJFUNC)nil) { |
733 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
734 |
} |
|
328 | 735 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
736 |
RETURN ( __interpret(self, 6, nil, home COMMA_SND, nil, nil, &arg1) ); |
328 | 737 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
738 |
RETURN ( __interpret(self, 6, nil, home COMMA_SND, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 739 |
# endif |
1 | 740 |
#endif |
741 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
742 |
%}. |
103 | 743 |
^ self wrongNumberOfArguments:6 |
1 | 744 |
! |
745 |
||
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
746 |
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
|
747 |
"evaluate the receiver with seven arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
748 |
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
|
749 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
750 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
751 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
752 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
753 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
754 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
755 |
if (__INST(nargs) == __MKSMALLINT(7)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
756 |
#if defined(THIS_CONTEXT) |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
757 |
if (__ISVALID_ILC_LNO(__pilc)) |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
758 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
759 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
760 |
thecode = __BlockInstPtr(self)->b_code; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
761 |
#ifdef NEW_BLOCK_CALL |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
762 |
if (thecode != (OBJFUNC)nil) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
763 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
764 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
765 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
766 |
RETURN ( __interpret(self, 7, nil, nil COMMA_SND, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
767 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
768 |
RETURN ( __interpret(self, 7, nil, nil COMMA_SND, 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
|
769 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
770 |
#else |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
771 |
home = __BlockInstPtr(self)->b_home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
772 |
if (thecode != (OBJFUNC)nil) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
773 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
774 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
775 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
776 |
RETURN ( __interpret(self, 7, nil, home COMMA_SND, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
777 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
778 |
RETURN ( __interpret(self, 7, nil, home COMMA_SND, 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
|
779 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
780 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
781 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
782 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
783 |
^ self wrongNumberOfArguments:7 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
784 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
785 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
786 |
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
|
787 |
"evaluate the receiver with eight arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
788 |
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
|
789 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
790 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
791 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
792 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
793 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
794 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
795 |
if (__INST(nargs) == __MKSMALLINT(8)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
796 |
#if defined(THIS_CONTEXT) |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
797 |
if (__ISVALID_ILC_LNO(__pilc)) |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
798 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
799 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
800 |
thecode = __BlockInstPtr(self)->b_code; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
801 |
#ifdef NEW_BLOCK_CALL |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
802 |
if (thecode != (OBJFUNC)nil) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
803 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
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 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
806 |
RETURN ( __interpret(self, 8, nil, nil COMMA_SND, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
807 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
808 |
RETURN ( __interpret(self, 8, nil, nil COMMA_SND, 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
|
809 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
810 |
#else |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
811 |
home = __BlockInstPtr(self)->b_home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
812 |
if (thecode != (OBJFUNC)nil) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
813 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
814 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
815 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
816 |
RETURN ( __interpret(self, 8, nil, home COMMA_SND, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
817 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
818 |
RETURN ( __interpret(self, 8, nil, home COMMA_SND, 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
|
819 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
820 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
821 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
822 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
823 |
^ self wrongNumberOfArguments:8 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
824 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
825 |
|
1 | 826 |
valueWithArguments:argArray |
827 |
"evaluate the receiver with arguments taken from argArray. |
|
313 | 828 |
ArgArray must be either an Array or nil. |
1 | 829 |
The size of the argArray must match the number of arguments the receiver expects." |
830 |
||
1037 | 831 |
|a1 a2 a3 a4 a5 a6 a7 a8| |
1 | 832 |
|
319 | 833 |
(argArray notNil and:[argArray class ~~ Array]) ifTrue:[ |
154 | 834 |
^ self badArgumentArry |
1 | 835 |
]. |
836 |
(argArray size == nargs) ifFalse:[ |
|
154 | 837 |
^ self wrongNumberOfArguments:(argArray size) |
1 | 838 |
]. |
839 |
%{ |
|
840 |
||
841 |
REGISTER OBJFUNC thecode; |
|
842 |
OBJ home; |
|
67 | 843 |
REGISTER OBJ *ap; |
328 | 844 |
int nargs; |
1 | 845 |
|
846 |
#if defined(THIS_CONTEXT) |
|
328 | 847 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 848 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 849 |
#endif |
1133 | 850 |
thecode = __BlockInstPtr(self)->b_code; |
1037 | 851 |
|
852 |
#ifndef NEW_BLOCK_CALL |
|
1133 | 853 |
home = __BlockInstPtr(self)->b_home; |
1037 | 854 |
if (thecode != (OBJFUNC)nil) { |
1133 | 855 |
switch (nargs = __intVal(__INST(nargs))) { |
1037 | 856 |
default: |
857 |
goto error; |
|
858 |
case 8: |
|
1133 | 859 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 860 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
861 |
case 7: |
|
1133 | 862 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 863 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
864 |
case 6: |
|
1133 | 865 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 866 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
867 |
case 5: |
|
1133 | 868 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 869 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
870 |
case 4: |
|
1133 | 871 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 872 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2], ap[3]) ); |
873 |
case 3: |
|
1133 | 874 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 875 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2]) ); |
876 |
case 2: |
|
1133 | 877 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 878 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1]) ); |
879 |
case 1: |
|
1133 | 880 |
RETURN ( (*thecode)(home COMMA_SND, __ArrayInstPtr(argArray)->a_element[0]) ); |
1037 | 881 |
case 0: |
882 |
RETURN ( (*thecode)(home COMMA_SND) ); |
|
883 |
break; |
|
884 |
} |
|
885 |
} |
|
886 |
#endif |
|
887 |
||
1133 | 888 |
switch (nargs = __intVal(__INST(nargs))) { |
154 | 889 |
default: |
890 |
goto error; |
|
1037 | 891 |
case 8: |
1133 | 892 |
a8 = __ArrayInstPtr(argArray)->a_element[7]; |
154 | 893 |
case 7: |
1133 | 894 |
a7 = __ArrayInstPtr(argArray)->a_element[6]; |
154 | 895 |
case 6: |
1133 | 896 |
a6 = __ArrayInstPtr(argArray)->a_element[5]; |
154 | 897 |
case 5: |
1133 | 898 |
a5 = __ArrayInstPtr(argArray)->a_element[4]; |
154 | 899 |
case 4: |
1133 | 900 |
a4 = __ArrayInstPtr(argArray)->a_element[3]; |
154 | 901 |
case 3: |
1133 | 902 |
a3 = __ArrayInstPtr(argArray)->a_element[2]; |
154 | 903 |
case 2: |
1133 | 904 |
a2 = __ArrayInstPtr(argArray)->a_element[1]; |
154 | 905 |
case 1: |
1133 | 906 |
a1 = __ArrayInstPtr(argArray)->a_element[0]; |
154 | 907 |
case 0: |
908 |
break; |
|
1 | 909 |
} |
1133 | 910 |
|
11 | 911 |
#ifdef NEW_BLOCK_CALL |
1 | 912 |
if (thecode != (OBJFUNC)nil) { |
1037 | 913 |
RETURN ( (*thecode)(self COMMA_SND, a1, a2, a3, a4, a5, a6, a7, a8) ); |
11 | 914 |
} |
328 | 915 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
916 |
RETURN ( __interpret(self, nargs, nil, nil COMMA_SND, nil, nil, &a1) ); |
328 | 917 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
918 |
RETURN ( __interpret(self, nargs, nil, nil COMMA_SND, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8) ); |
328 | 919 |
# endif |
1037 | 920 |
|
1 | 921 |
#else |
1037 | 922 |
|
328 | 923 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
924 |
RETURN ( __interpret(self, nargs, nil, home COMMA_SND, nil, nil, &a1) ); |
328 | 925 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
926 |
RETURN ( __interpret(self, nargs, nil, home COMMA_SND, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8) ); |
328 | 927 |
# endif |
1037 | 928 |
|
1 | 929 |
#endif |
67 | 930 |
|
11 | 931 |
error: ; |
1 | 932 |
%} |
11 | 933 |
. |
138 | 934 |
" |
935 |
the above code only supports up-to 7 arguments |
|
936 |
" |
|
128 | 937 |
^ ArgumentSignal |
154 | 938 |
raiseRequestWith:self |
939 |
errorString:'only blocks with up-to 7 arguments supported' |
|
940 |
! ! |
|
941 |
||
623 | 942 |
!Block methodsFor:'looping'! |
325 | 943 |
|
623 | 944 |
doUntil:aBlock |
945 |
"repeat the receiver block until aBlock evaluates to true. |
|
946 |
The receiver is evaluated at least once. |
|
947 |
This is the same as '... doWhile:[... not]' " |
|
325 | 948 |
|
623 | 949 |
"this implementation is for purists ... :-)" |
950 |
||
951 |
self value. |
|
952 |
aBlock value ifTrue:[^ nil]. |
|
953 |
thisContext restart |
|
325 | 954 |
|
955 |
" |
|
623 | 956 |
|n| |
154 | 957 |
|
623 | 958 |
n := 1. |
959 |
[n printNewline] doUntil:[ (n := n + 1) > 5 ] |
|
154 | 960 |
" |
1 | 961 |
! |
962 |
||
623 | 963 |
doWhile:aBlock |
964 |
"repeat the receiver block until aBlock evaluates to false. |
|
965 |
The receiver is evaluated at least once." |
|
67 | 966 |
|
154 | 967 |
"this implementation is for purists ... :-)" |
968 |
||
623 | 969 |
self value. |
970 |
aBlock value ifFalse:[^ nil]. |
|
971 |
thisContext restart |
|
972 |
||
973 |
" |
|
974 |
|n| |
|
975 |
||
976 |
n := 1. |
|
977 |
[n printNewline] doWhile:[ (n := n + 1) <= 5 ] |
|
978 |
" |
|
979 |
! |
|
980 |
||
981 |
loop |
|
1211 | 982 |
"repeat the receiver forever |
983 |
(the receiver block should contain a return somewhere). |
|
984 |
The implementation below was inspired by a corresponding Self method." |
|
623 | 985 |
|
986 |
self value. |
|
67 | 987 |
thisContext restart |
988 |
||
989 |
" |
|
990 |
|n| |
|
991 |
||
992 |
n := 1. |
|
623 | 993 |
[ |
1211 | 994 |
n printNewline. |
995 |
n >= 10 ifTrue:[^ nil]. |
|
996 |
n := n + 1 |
|
623 | 997 |
] loop |
998 |
" |
|
1211 | 999 |
|
1000 |
"Modified: 18.4.1996 / 13:50:40 / cg" |
|
623 | 1001 |
! |
1002 |
||
1003 |
loopWithExit |
|
1004 |
"the receiver must be a block of one argument. It is evaluated in a loop forever, |
|
1005 |
and is passed a block, which, if sent a value:-message, will exit the receiver block, |
|
1006 |
returning the parameter of the value:-message. Used for loops with exit in the middle. |
|
1007 |
Inspired by a corresponding Self method." |
|
1008 |
||
1009 |
|exitBlock| |
|
1010 |
||
1011 |
exitBlock := [:exitValue | ^ exitValue]. |
|
1012 |
[true] whileTrue:[self value:exitBlock] |
|
1013 |
||
1014 |
" |
|
1015 |
|i| |
|
1016 |
i := 1. |
|
1017 |
[:exit | |
|
1422 | 1018 |
Transcript showCR:i. |
623 | 1019 |
i == 5 ifTrue:[exit value:'thats it']. |
1020 |
i := i + 1 |
|
1021 |
] loopWithExit |
|
1022 |
" |
|
1023 |
! |
|
1024 |
||
1025 |
repeat |
|
1211 | 1026 |
"repeat the receiver forever - same as loop, for ST-80 compatibility. |
1027 |
(the receiver block should contain a return somewhere)." |
|
623 | 1028 |
|
1029 |
self value. |
|
1030 |
thisContext restart |
|
1211 | 1031 |
|
1032 |
"Modified: 18.4.1996 / 13:50:55 / cg" |
|
623 | 1033 |
! |
1034 |
||
1035 |
valueWithExit |
|
1036 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
|
1037 |
which, if sent a value:-message, will exit the receiver block, returning the parameter of the |
|
1038 |
value:-message. Used for premature returns to the caller. |
|
1039 |
Taken from a manchester goody (a similar construct also appears in Self)." |
|
1040 |
||
1211 | 1041 |
^ self value:[:exitValue | ^exitValue] |
623 | 1042 |
|
1043 |
" |
|
1044 |
[:exit | |
|
1211 | 1045 |
1 to:10 do:[:i | |
1422 | 1046 |
Transcript showCR:i. |
1211 | 1047 |
i == 5 ifTrue:[exit value:'thats it'] |
1048 |
]. |
|
1049 |
'regular block-value; never returned' |
|
623 | 1050 |
] valueWithExit |
1051 |
" |
|
1211 | 1052 |
|
1053 |
"Modified: 18.4.1996 / 13:51:38 / cg" |
|
623 | 1054 |
! |
1055 |
||
1056 |
whileFalse |
|
1057 |
"evaluate the receiver while it evaluates to false (ST80 compatibility)" |
|
1058 |
||
1059 |
"this implementation is for purists ... :-)" |
|
1060 |
||
1061 |
self value ifTrue:[^ nil]. |
|
1062 |
thisContext restart |
|
1063 |
||
1064 |
" |
|
1065 |
|n| |
|
1066 |
||
1067 |
n := 1. |
|
1068 |
[n printNewline. (n := n + 1) > 10] whileFalse |
|
67 | 1069 |
" |
1070 |
! |
|
1 | 1071 |
|
67 | 1072 |
whileFalse:aBlock |
1073 |
"evaluate the argument, aBlock while the receiver evaluates to false. |
|
1074 |
- usually open coded by compilers, but needed here for #perform |
|
1075 |
and expression evaluation." |
|
1076 |
||
154 | 1077 |
"this implementation is for purists ... :-)" |
1078 |
||
67 | 1079 |
self value ifTrue:[^ nil]. |
1080 |
aBlock value. |
|
1081 |
thisContext restart |
|
1082 |
||
1083 |
" |
|
1084 |
|n| |
|
1085 |
||
1086 |
n := 1. |
|
1087 |
[n > 10] whileFalse:[ |
|
154 | 1088 |
n printNewline. |
1089 |
n := n + 1 |
|
67 | 1090 |
] |
1091 |
" |
|
1 | 1092 |
! |
1093 |
||
1094 |
whileTrue |
|
67 | 1095 |
"evaluate the receiver while it evaluates to true (ST80 compatibility)" |
1 | 1096 |
|
154 | 1097 |
"this implementation is for purists ... :-)" |
1098 |
||
67 | 1099 |
self value ifFalse:[^ nil]. |
1100 |
thisContext restart |
|
1 | 1101 |
|
67 | 1102 |
" |
1103 |
|n| |
|
1 | 1104 |
|
67 | 1105 |
n := 1. |
1106 |
[n printNewline. (n := n + 1) <= 10] whileTrue |
|
1107 |
" |
|
1 | 1108 |
! |
1109 |
||
623 | 1110 |
whileTrue:aBlock |
1111 |
"evaluate the argument, aBlock while the receiver evaluates to true. |
|
1112 |
- usually open coded by compilers, but needed here for #perform |
|
1113 |
and expression evaluation." |
|
1 | 1114 |
|
154 | 1115 |
"this implementation is for purists ... :-)" |
1116 |
||
623 | 1117 |
self value ifFalse:[^ nil]. |
1118 |
aBlock value. |
|
67 | 1119 |
thisContext restart |
1120 |
||
1121 |
" |
|
1122 |
|n| |
|
1 | 1123 |
|
67 | 1124 |
n := 1. |
623 | 1125 |
[n <= 10] whileTrue:[ |
154 | 1126 |
n printNewline. |
1127 |
n := n + 1 |
|
623 | 1128 |
] |
68 | 1129 |
" |
67 | 1130 |
! ! |
1131 |
||
92 | 1132 |
!Block methodsFor:'printing & storing'! |
1 | 1133 |
|
1134 |
printOn:aStream |
|
44 | 1135 |
"append a a printed representation of the block to aStream" |
1136 |
||
213 | 1137 |
|homeClass h sel methodClass| |
54 | 1138 |
|
1139 |
"cheap blocks have no home context, but a method instead" |
|
1140 |
||
1141 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
154 | 1142 |
aStream nextPutAll:'[] in '. |
1 | 1143 |
|
154 | 1144 |
" |
1145 |
currently, some cheap blocks don't know where they have been created |
|
1146 |
" |
|
1147 |
aStream nextPutAll:' ??? (optimized)'. |
|
1148 |
^ self |
|
54 | 1149 |
]. |
1150 |
||
1151 |
"a full blown block (with home, but without method)" |
|
1152 |
||
1153 |
aStream nextPutAll:'[] in '. |
|
154 | 1154 |
h := self methodHome. |
1155 |
sel := h selector. |
|
1156 |
"/ old: |
|
1157 |
"/ home receiver class name printOn:aStream. |
|
1158 |
"/ new: |
|
212 | 1159 |
"/ (h searchClass whichClassImplements:sel) name printOn:aStream. |
213 | 1160 |
methodClass := h methodClass. |
1161 |
methodClass isNil ifTrue:[ |
|
1162 |
'UnboundMethod' printOn:aStream. |
|
1163 |
] ifFalse:[ |
|
1164 |
methodClass name printOn:aStream. |
|
1165 |
]. |
|
54 | 1166 |
aStream nextPut:$-. |
154 | 1167 |
sel printOn:aStream. |
54 | 1168 |
|
1169 |
" |
|
1 | 1170 |
aStream nextPutAll:'[] in '. |
1171 |
homeClass := home containingClass. |
|
1172 |
homeClass notNil ifTrue:[ |
|
154 | 1173 |
homeClass name printOn:aStream. |
1174 |
aStream space. |
|
1175 |
(homeClass selectorForMethod:home) printOn:aStream |
|
1 | 1176 |
] ifFalse:[ |
154 | 1177 |
aStream nextPutAll:' ???' |
1 | 1178 |
] |
54 | 1179 |
" |
1 | 1180 |
! ! |
623 | 1181 |
|
1182 |
!Block methodsFor:'private accessing'! |
|
1183 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1184 |
byteCode:bCode numArgs:numArgs sourcePosition:srcPos initialPC:iPC literals:lits |
1265 | 1185 |
"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
|
1186 |
DANGER ALERT: this interface is strictly private." |
623 | 1187 |
|
1188 |
byteCode := bCode. |
|
1189 |
nargs := numArgs. |
|
1190 |
sourcePos := srcPos. |
|
1191 |
initialPC := iPC. |
|
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1192 |
self literals:lits. |
1265 | 1193 |
|
1194 |
"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
|
1195 |
"Modified: 24.6.1996 / 12:37:37 / stefan" |
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1196 |
"Created: 17.10.1996 / 14:05:45 / cg" |
623 | 1197 |
! |
1198 |
||
1199 |
initialPC:initial |
|
1265 | 1200 |
"set the initial pc for evaluation. |
1201 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1202 |
|
1203 |
initialPC := initial |
|
1265 | 1204 |
|
1205 |
"Modified: 23.4.1996 / 16:05:39 / cg" |
|
623 | 1206 |
! |
1207 |
||
1208 |
numArgs:numArgs |
|
1265 | 1209 |
"set the number of arguments the receiver expects for evaluation. |
1210 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1211 |
|
1212 |
nargs := numArgs |
|
1265 | 1213 |
|
1214 |
"Modified: 23.4.1996 / 16:05:52 / cg" |
|
623 | 1215 |
! |
1216 |
||
1217 |
sourcePosition:position |
|
1265 | 1218 |
"set the position of the source within my method. |
1219 |
This interface is for the compiler only." |
|
623 | 1220 |
|
1221 |
sourcePos := position |
|
1265 | 1222 |
|
1223 |
"Modified: 23.4.1996 / 16:06:19 / cg" |
|
623 | 1224 |
! ! |
1225 |
||
1226 |
!Block methodsFor:'privileged evaluation'! |
|
1227 |
||
1228 |
valueUninterruptably |
|
1229 |
"evaluate the receiver with interrupts blocked. |
|
1230 |
This does not prevent preemption by a higher priority processes |
|
1231 |
if any becomes runnable due to the evaluation of the receiver |
|
1232 |
(i.e. if a semaphore is signalled)." |
|
1233 |
||
864 | 1234 |
|wasBlocked| |
1235 |
||
1236 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1041
12e2524284e2
oops - unterrupts remained blocked sometimes
Claus Gittinger <cg@exept.de>
parents:
1037
diff
changeset
|
1237 |
^ self valueNowOrOnUnwindDo:[wasBlocked ifFalse:[OperatingSystem unblockInterrupts]]. |
623 | 1238 |
! |
1239 |
||
1240 |
valueUnpreemptively |
|
1241 |
"evaluate the receiver without the possiblity of preemption |
|
1242 |
(i.e. at a very high priority)" |
|
1243 |
||
1244 |
|oldPrio activeProcess| |
|
1245 |
||
1246 |
activeProcess := Processor activeProcess. |
|
1247 |
oldPrio := activeProcess changePriority:(Processor highestPriority). |
|
864 | 1248 |
^ self valueNowOrOnUnwindDo:[ |
623 | 1249 |
activeProcess priority:oldPrio |
1250 |
] |
|
1251 |
! ! |
|
1252 |
||
1253 |
!Block methodsFor:'process creation'! |
|
1254 |
||
1255 |
fork |
|
1256 |
"create a new process executing the receiver at the current priority." |
|
1257 |
||
1258 |
^ self newProcess resume |
|
1259 |
! |
|
1260 |
||
1261 |
forkAt:priority |
|
1262 |
"create a new process executing the receiver at a different priority." |
|
1263 |
||
1264 |
^ (self newProcess priority:priority) resume |
|
1265 |
! |
|
1266 |
||
1267 |
forkWith:argArray |
|
1268 |
"create a new process executing the receiver, |
|
1269 |
passing elements in argArray as arguments to the receiver block." |
|
1270 |
||
1271 |
^ [self valueWithArguments:argArray] fork. |
|
1272 |
! |
|
1273 |
||
1274 |
newProcess |
|
1275 |
"create a new (unscheduled) process executing the receiver" |
|
1276 |
||
1277 |
^ Process for:self priority:(Processor activePriority) |
|
1278 |
! |
|
1279 |
||
1280 |
newProcessWithArguments:argArray |
|
1281 |
"create a new (unscheduled) process executing the receiver, |
|
1282 |
passing the elements in argArray as arguments to the receiver block." |
|
1283 |
||
1284 |
^ [self valueWithArguments:argArray] newProcess |
|
1285 |
! |
|
1286 |
||
1287 |
promise |
|
1288 |
"create a promise on the receiver. The promise will evaluate the |
|
1289 |
receiver and promise to return the value with the #value message. |
|
1290 |
The evaluation will be performed as a separate process. |
|
1291 |
Asking the promise for its value will either block the asking process |
|
1292 |
(if the evaluation has not yet been finished) or return the value |
|
1293 |
immediately." |
|
1294 |
||
1295 |
^ Promise value:self |
|
1296 |
||
1297 |
" |
|
1298 |
|p| |
|
1299 |
||
1300 |
p := [1000 factorial] promise. |
|
1301 |
'do something else ...'. |
|
1302 |
p value |
|
1303 |
" |
|
1304 |
! |
|
1305 |
||
1306 |
promiseAt:prio |
|
1307 |
"create a promise on the receiver. The promise will evaluate the |
|
1308 |
receiver and promise to return the value with the #value message. |
|
1309 |
The evaluation will be performed as a separate process running at prio. |
|
1310 |
Asking the promise for its value will either block the asking process |
|
1311 |
(if the evaluation has not yet been finished) or return the value |
|
1312 |
immediately." |
|
1313 |
||
1314 |
^ Promise value:self priority:prio |
|
1315 |
! ! |
|
1316 |
||
1317 |
!Block methodsFor:'testing'! |
|
1318 |
||
1319 |
isBlock |
|
1320 |
"return true, if this is a block - yes I am" |
|
1321 |
||
1322 |
^ true |
|
1323 |
! ! |
|
1324 |
||
1325 |
!Block methodsFor:'unwinding'! |
|
1326 |
||
1327 |
valueNowOrOnUnwindDo:aBlock |
|
1328 |
"evaluate the receiver - after that, or when some method sent within unwinds (i.e. does |
|
1329 |
a long return), evaluate the argument, aBlock. |
|
1330 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1331 |
executed regardless of error actions" |
|
1332 |
||
1333 |
|v| |
|
1334 |
||
1335 |
thisContext markForUnwind. |
|
1336 |
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
|
1337 |
thisContext unmarkForUnwind. |
623 | 1338 |
aBlock value. |
1339 |
^ v |
|
1340 |
||
1341 |
" |
|
1342 |
in the following example, f will be closed even if the block |
|
1343 |
returns with 'oops'. There are many more applications of this kind |
|
1344 |
found in the system. |
|
1345 |
" |
|
1346 |
" |
|
1347 |
|f| |
|
1348 |
||
1349 |
f := 'Makefile' asFilename readStream. |
|
1350 |
[ |
|
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1351 |
l := f nextLine. |
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1352 |
l isNil ifTrue:[^ 'oops'] |
623 | 1353 |
] valueNowOrOnUnwindDo:[ |
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1354 |
f close |
623 | 1355 |
] |
1356 |
" |
|
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1357 |
|
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1358 |
"Modified: 16.4.1996 / 11:05:26 / stefan" |
623 | 1359 |
! |
1360 |
||
1361 |
valueOnUnwindDo:aBlock |
|
1362 |
"evaluate the receiver - when some method sent within unwinds (i.e. does |
|
1363 |
a long return), evaluate the argument, aBlock. |
|
1364 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1365 |
executed regardless of error actions" |
|
1366 |
||
1367 |
thisContext markForUnwind. |
|
1368 |
^ self value "the real logic is in Context>>unwind" |
|
1369 |
! ! |
|
1370 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1371 |
!Block class methodsFor:'documentation'! |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1372 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1373 |
version |
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1374 |
^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.62 1996-10-17 13:08:17 cg Exp $' |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1375 |
! ! |
623 | 1376 |
Block initialize! |