problem in porting from smalltalk

Hans-Martin Mosner hmm at heeg.de
Fri Feb 24 19:32:20 UTC 2006


Louis LaBrunda wrote:

>Hi All,
>
>I am not new to Smalltalk but I am very, very new to Squeak and know
>nothing about the compiler and its optimizations, so this suggestion may be
>way off base, but here goes, couldn't the optimized code for and: and or:
>be enhanced to test to see if the receiver is a boolean and if not pass the
>message on the receiver in the non optimized way?  Hopefully this extra
>test would not reduced the optimization much.
>  
>
That does not work because in the optimized case, the block object which 
is the argument to the message does not really get created at all.
Instead, there are bytecodes which conditionally jump around the code in 
the block.
It would be possible (with some trickery) to extract those bytecodes 
from the offending method and create a normal block with the same 
functionality, but given the observation that most cases where and: or 
or: are sent to a non-Boolean in error, it's probably not worth the effort.
Removing the optimization from the compiler if the argument is not a 
block is quite easy, though.
Currently, the boolean messages accept either a block or a variable as 
their argument, but not arbitrary expressions, which seems rather 
illogical to me.
You can change the method in MessageNode which does this to read:
checkBlock: node as: nodeName from: encoder

    ^(node isKindOf: BlockNode)
        ifTrue: [(node numberOfArguments > 0)
            ifTrue:    [encoder notify: '<- ', nodeName , ' of ' ,
                    (MacroSelectors at: special) , ' must be a 
0-argument block']
            ifFalse: [true]]
        ifFalse: [false]

Then the optimization only happens if the argument is a 0-argument block.

Cheers,
Hans-Martin



More information about the Squeak-dev mailing list