[squeak-dev] Re: Boolean over-optimization #ifTrue:/#ifFalse:
Joshua Gargus
schwa at fastmail.us
Wed Mar 5 07:58:13 UTC 2008
The #compilerClass method allows you to specify the compiler to be
used for a class (and its subclasses). So, one approach would be to
implement a subclass of Compiler (say, "ProxyCompiler") that disables
optimization of #ifTrue:ifFalse: etc.
I'm not sure about a clean way to disable optimizations in a subclass
of Compiler. Here's a moderately horrible way to disable them
globally...
- give Compiler a boolean class variable "DisableSpecialSelectors"
- hack MethodNode>>noteSpecialSelector: thusly...
noteSpecialSelector: selectorSymbol
" special > 0 denotes specially treated messages. "
DisableSpecialSelectors ifTrue: [special := 0. ^self].
"Deconvert initial keywords from SQ2K"
special := #(:Test:Yes: :Test:No: :Test:Yes:No: :Test:No:Yes:
and: or:
:Until:do: :While:do: whileFalse whileTrue
:Repeat:to:do: :Repeat:to:by:do:
) indexOf: selectorSymbol.
special > 0 ifTrue: [^ self].
special := MacroSelectors indexOf: selectorSymbol.
Then, you could override #translate:noPattern:ifFail: in
ProxyCompiler, as follows...
translate: aStream noPattern: noPattern ifFail: failBlock
[ DisableSpecialSelectors := true.
^super translate: aStream noPattern: noPattern ifFail: failBlock
] ensure: [DisableSpecialSelectors := false].
Finally, implement #compilerClass on the class-side of your Proxy
class, and answer ProxyCompiler.
Heh, that was sorta fun!
Josh
On Mar 4, 2008, at 10:39 PM, Igor Stasenko wrote:
> On 05/03/2008, Paolo Bonzini <bonzini at gnu.org> wrote:
>> Igor Stasenko wrote:
>>> Hello,
>>>
>>> i currently tried to implement a proxy (subclass of ProtoObject)
>>> with
>>> own IfTrue:/ifFalse: methods.
>>> What i can't understand, is why VM throws me with #mustBeBoolean
>>> message instead of doing real send if optimized pattern fails (when
>>> receiver of #IfTrue: is a non-boolean)?
>>
>>
>> Because you cannot distinguish #ifTrue:#ifFalse: sends from
>> #whileTrue:
>> for example, and because there are no BlockC{ontext,losure} objects
>> for
>> the argument blocks.
>>
>
> So, the only way is to compile method without optimization of
> #ifTrue #ifFalse:,
> to make sure they do real sends?
>
> If yes, i'd like to see optimizations optional, so people can do like:
>
> Compiler turnOffOptimizations.
> MyClass compileAll.
> Compiler turnOnOptimizations.
>
>>
>> Paolo
>>
>>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>
More information about the Squeak-dev
mailing list
|