Shouldn't ifEmpty return self?
Benjamin Schroeder
benschroeder at acm.org
Mon Jun 12 21:59:40 UTC 2006
On Jun 12, 2006, at 5:38 PM, Klaus D. Witzel wrote:
> Ah. And I was believing the description in True>>#ifTrue:
> -------
> ifTrue: alternativeBlock
> "Answer the value of alternativeBlock. Execution does not actually
> reach here because the expression is compiled in-line."
>
> ^alternativeBlock value
> -------
>
> So the bug is in the documentation? This is not an easy one: who
> would doubt the implementation of such an essential behavior?
I think I see what you're saying. I did a little digging ...
Most of the time, it's only "as if" #ifTrue:, and hence #value, gets
sent. Interestingly, the whole block gets compiled inline in these
cases:
foo
4 > 3 ifTrue: [self halt]
compiles to
17 <21> pushConstant: 4
18 <22> pushConstant: 3
19 <B3> send: >
20 <9A> jumpFalse: 24
21 <70> self
22 <D0> send: halt
23 <87> pop
24 <78> returnSelf
(This output is from the "bytecodes" choice on the source dropdown of
the browser.)
However, #ifTrue: is actually sent if the situation isn't as obvious,
as when the block is referred to using a variable:
foo
| block |
block _ [self halt].
4 > 3 ifTrue: block
compiles to
21 <89> pushThisContext:
22 <75> pushConstant: 0
23 <C8> send: blockCopy:
24 <A4 03> jumpTo: 29
26 <70> self
27 <D0> send: halt
28 <7D> blockReturn
29 <68> popIntoTemp: 0
30 <22> pushConstant: 4
31 <23> pushConstant: 3
32 <B3> send: >
33 <10> pushTemp: 0
34 <E1> send: ifTrue:
35 <87> pop
36 <78> returnSelf
I don't know if the VM recognizes sends of #ifTrue: and does any
runtime optimization on them or not.
The behavior should be the same in either case, at any rate - it
should act as though #value were sent - so I might be missing what
you're saying about a bug.
Benjamin Schroeder
More information about the Squeak-dev
mailing list
|