[Newbies] Polymorphic or: with block argument

Bert Freudenberg 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
> intent
> 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
> performance
> 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
Compiler.

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

    a
    jump if false to 1
    push true
    jump to 2
1: b
2: ...

As you can see, the closure is gone completely.

- Bert -​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/beginners/attachments/20170911/4fcdee35/attachment.html>


More information about the Beginners mailing list