[squeak-dev] Questions about FullBlock closures

tim Rowledge tim at rowledge.org
Mon Feb 13 01:17:05 UTC 2023



> On 2023-02-12, at 12:48 PM, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> 
> No, no and thrice times no!! :-) There is a story I'll tell you at the end if the email, but first...

Ah, but your tale shows precisely why it is instructive to peek at the generated code here - it very clearly shows how complicated a once simple routine can become when it has to handle all the cleverness that has been added to the VM. And that should scare any sensible person off doing it again.

And wholly khao! I found an ancient changeset with the original VM slang code from 2000.

primitiveTerminateTo
	"Primitive. Terminate up the context stack from the receiver up to but not including the argument, if previousContext is on my Context stack. Make previousContext my sender. This prim has to shadow the code in ContextPart>terminateTo: to be correct"
	| thisCntx currentCntx aContext nextCntx nilOop |
	aContext _ self popStack.
	thisCntx _ self popStack.

	"make sure that aContext is in my chain"
	(self context: thisCntx hasSender: aContext) ifTrue:[
		nilOop _ nilObj.
		currentCntx _ self fetchPointer: SenderIndex ofObject: thisCntx.
		[currentCntx = aContext] whileFalse: [
			nextCntx _ self fetchPointer: SenderIndex ofObject: currentCntx.
			self storePointer: SenderIndex ofObject: currentCntx withValue: nilOop.
			currentCntx _ nextCntx]].

	self storePointer: SenderIndex ofObject: thisCntx withValue: aContext.
	^self push: thisCntx

context: thisCntx hasSender: aContext
	"Does thisCntx have aContext in its sender chain?"
	| s nilOop |
	self inline: true.
	thisCntx == aContext ifTrue: [^false].
	nilOop _ nilObj.
	s _ self fetchPointer: SenderIndex ofObject: thisCntx.
	[s == nilOop]
		whileFalse: 
			[s == aContext ifTrue: [^true].
			s _ s self fetchPointer: SenderIndex ofObject: s].
	^false

and so on. Compare that to the latest version that has to handle returning to machine code or not, stack frames, married contexts and so forth.

tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Useful random insult:- Been playing with the pharmacy section again.




More information about the Squeak-dev mailing list