[squeak-dev] Re: Boolean over-optimization #ifTrue:/#ifFalse:

Igor Stasenko siguctua at gmail.com
Thu Mar 6 12:11:44 UTC 2008


On 05/03/2008, Joshua Gargus <schwa at fastmail.us> wrote:
> 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:

What are these selectors (:Test:Yes: :Test:No: :Test:Yes:No: :Test:No:Yes:)?
And why they need special handling..
And what SQ2K means?
Ohh.. it seems that its easier to write own parser than using default one.

I'd like to add that a Parser/Compiler are focused on compiling
things, not for examining parse tree, which is bad.
Like, for instance, why MethodNode doesn't have accessor to arguments
ivar and forcing me to use #asTranslationMethodOfClass: only for a
single reason - to have a change to look an argument names of parsed
method.


>                                 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
>
>
>


-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list