[squeak-dev] Decompiling with temps

Bert Freudenberg bert at freudenbergs.de
Thu Jan 13 10:29:50 UTC 2011


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?

- 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





More information about the Squeak-dev mailing list