[Vm-dev] Fwd: Question about closure

stephane ducasse stephane.ducasse at gmail.com
Sun Apr 22 18:48:35 UTC 2012


Hi eliot

I'm rereading your blog. I understand that you create an array so that you are sure that 
local of the activation context of the method containing a block are not modified, just the 
array elements. so this means in particular that since the array is not allocated on the heap
you guarantee that captured variables of the closure environment outlive the method activation.
I hope I got it correctly.

Now I have a question about the following snippet representing what the compiler is doing.
Where indirectTempsCopy is initialized and to what?

inject: thisValue into: binaryBlock 
	| indirectTemps |
	indirectTemps := Array new: 1. 
	indirectTemps at: 1 put: thisValue. 
	self do: (thisContext
		closureCopy:
			[:each | 	
				| binaryBlockCopy indirectTempsCopy | 
				indirectTempsCopy
					at:1
					put: (binaryBlockCopy value: (indirectTempsCopy at: 1) value: each)]
				copiedValues: (Array with: binaryBlock with: indirectTemps)).
	^indirectTemps at: 1

I thought that it should be like and I was wondering after if and why the indirectTemps should be copied.
Because we create one context for each 

		[:each | 	
				| binaryBlockCopy indirectTempsCopy | 
				indirectTempsCopy := indirectTemps 
			^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
				indirectTempsCopy
					at:1
					put: (binaryBlockCopy value: (indirectTempsCopy at: 1) value: each)]
				copiedValues: (Array with: binaryBlock with: indirectTemps)).
	^indirectTemps at: 1


Thanks.
Stef






More information about the Vm-dev mailing list