[squeak-dev] Accessing temp variables bindings in a BlockClosure

Stéphane Rollandin lecteur at zogotounga.net
Sun Apr 19 22:21:12 UTC 2020


At the moment I have something working in many cases, but not all (attached)

It can do

	| y |
	y := 10.
	[:x | y + x] tempBindings 	"returns {'y'->10}"

and

	| y x |
	y := 10.
	x := 8.
	[:a :b | a + y + x] tempBindings 	" {'y'->10 . 'x'->8} "


but fails for example here:

	|blockSourceStream methodNode compiledMethod block |

	blockSourceStream :=
		'|x y| [:a :b | x := b. y := a. x + y]' readStream.

	methodNode := nil class evaluatorClass new
		compileNoPattern: blockSourceStream
		in: nil class notifying: nil ifFail: [nil].

	compiledMethod := methodNode generateWithTempNames.

	block := nil withArgs: #() executeMethod: compiledMethod.

	block tempBindings	"Error !!"

because the block basicAt: 1 is actually a list with the value of both x 
and y - and I do not see how to detect this case.

Stef
-------------- next part --------------
'From Squeak5.3 of 3 March 2020 [latest update: #19431] on 20 April 2020 at 12:14:10 am'!

!BlockClosure methodsFor: '*ModularAgency' stamp: 'spfa 4/20/2020 00:08'!
tempBindings 

	| tmpNames usedNames |

	tmpNames := self method tempNames.

	usedNames := Array streamContents: [:str | 
		self decompile nodesDo: [:ea | (ea isTemp and: [tmpNames includes: ea name])
			ifTrue: [str nextPut: ea name]]] .

	^	Array streamContents: [:str |
			(1 to: self basicSize) with: usedNames do: [:i :n |
				str nextPut: (n -> (self basicAt: i))]]
! !


More information about the Squeak-dev mailing list