[Newbies] Polymorphic or: with block argument
bert at freudenbergs.de
Mon Sep 11 18:25:00 UTC 2017
On Sun, Sep 10, 2017 at 3:06 PM, Lorenz Köhl <rainbowtwigs at gmail.com> wrote:
> I am not sure what you are trying to do with your examples. Can you
>> explain the intent?
> Set was just an example object that's quick to test the behaviour. My
> is to understand this behaviour, bc. Smalltalk usually goes to great length
> to keep the messaging system consistent. But in VisualWorks the behaviour
> is the same, so I presume (and Marcel confirms) that without this the
> of the whole system suffers.
It avoids a message send and the allocation of a block. These used to be
very costly with the interpreter, but even now with a JIT compiler having
these get transformed to simple jumps behind the scenes is advantageous.
You can see how it works in class MessageNode, which is used by the
In MessageNode class>>initialize all the macro transformations are
registered. E.g. for "or:" we have "transformOr:" as a transformer and
"emitCodeForIf:encoder:value:" as an emitter. The first transforms the
"or:" message into an "ifTrue:ifFalse:" message, and the second emits the
proper branch byte code to conditionally skip the blocks:
a or: [b]
gets transformed to
a ifTrue: [true] ifFalse: [b]
and then byte code is emitted like
jump if false to 1
jump to 2
As you can see, the closure is gone completely.
- Bert -
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners