[squeak-dev] Decompiling with temps

Eliot Miranda eliot.miranda at gmail.com
Thu Jan 13 17:33:27 UTC 2011


On Thu, Jan 13, 2011 at 2:29 AM, Bert Freudenberg <bert at freudenbergs.de>wrote:

> Here's another decompiler problem that I actually ran into in production
> code. When decompiling this method, either the block-local temp should
> remain block-local, or one of the vars needs to be renamed:
>
> blockLocalsAndArgs
>        | product |
>        product := 1.
>        1 to: 2 do: [:i |
>                i = 1
>                        ifTrue: [ | factor | factor := 6.
>                                product := product * factor ]
>                        ifFalse: [ #(9) do: [:factor |
>                                product := product * factor ] ] ].
>        ^ product = 13r42
>
> This works fine if decompiled without temps but the standard in Squeak is
> to use the actual temp names - just accept this as a method and switch to
> decompiled view.
>
> The best fix might be if the decompiler always declared the variables in
> the inner-most block possible. Maybe moving the declarations is not even
> that hard to do as a post-process on the AST?
>

Right.  And there's now a visitor method for determining that scope,
TempScopeEditor>>#blockNode:isEnclosingScopeFor:.  But I've been too
lazy^H^H^H^Hbusy to apply it in the context of the decompiler.  Feel free to
feel motivated...

best
Eliot


>
> - Bert -
>
> On 13.01.2011, at 00:51, Nicolas Cellier wrote:
>
> > Follow up on unused temps :
> >
> > Wanna play with temps ? Try this :
> >
> > testUnusedVariable
> >       self
> >               compiling: 'griffle | goo | ^nil'
> >               shouldRaise: UnusedVariable;
> >               compiling: 'griffle | | ^[ | goo | ]'
> >               shouldRaise: UnusedVariable;
> >               compiling: 'griffle | | [ | goo | goo := nil. goo]
> yourself. ^[ | goo | ]'
> >               shouldRaise: UnusedVariable;
> >               compiling: 'griffle | | [ | goo | ] yourself. ^[ | goo |
> goo := nil. goo]'
> >               shouldRaise: UnusedVariable
> >
> > What happens is that Parser.scopeTable has a single entry for 'goo'.
> > Consequently, the last registered goo wins.
> > In the 3rd case, the last goo is unused, so hasRef = false, so
> > UnusedVariable is raised.
> > In the 4th case, the last goo nowHasRef, and we don't get any
> UnusedVariable.
> >
> > Until we get a scopeTable mapping each temp of each block, we gonna
> > live in trouble.
> >
> > Nicolas
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20110113/9086d7fe/attachment.htm


More information about the Squeak-dev mailing list