[Cuis-dev] [RFC] Class and Metaclass changes to support environments

Gerald Klix cuis.01 at klix.ch
Tue Oct 6 05:20:00 PDT 2020

Hi all, hi Juan, hi Hernan,

here come some changes to Class and Metaclass
to support name lookup in environments.

I hope this change is OK, currently it did not
get much testing.

Best Regards,

-------------- next part --------------
'From Cuis 5.0 [latest update: #4384] on 6 October 2020 at 2:10:42 pm'!

!Class methodsFor: 'compiling' stamp: 'KLG 10/6/2020 14:06:06'!
nonLocalBindingOf: aVarName
	"Answer the non local binding of aVarName.
	Answer nil if no binding is available."

	"The metaclass provides the environment to search in."
	self class forNonLocalBindingEnvironmentsDo: [ :environment |
		environment bindingOf: aVarName :: ifNotNil: [ :binding | ^ binding ] ].
	^ nil ! !

!Metaclass methodsFor: 'compiling' stamp: 'KLG 10/6/2020 14:08:05'!
forNonLocalBindingEnvironmentsDo: aBlock
	"Evaluate aBlock for all non local environments.
	Maybe overriden in meta classes, that provide support/for
	Ordinary metaclasses only provide Smalltalk as global namespace."

	^ aBlock value: Smalltalk! !

!Class methodsFor: 'compiling' stamp: 'KLG 10/6/2020 14:03:40'!

	^ self nonLocalBindingOf: name :: ifNil: [ nil -> self ]! !

!Class methodsFor: 'compiling' stamp: 'KLG 10/6/2020 14:04:26'!
bindingOf: varName
	"Answer the binding of some variable resolved in the scope of the receiver"
	| aSymbol |
	aSymbol _ varName asSymbol.

	"First look in receiver, and up the hierarchy. Inherited variables take precedence over globals."
	(self localBindingOf: aSymbol) ifNotNil: [ :binding | ^binding ].

	"Next look in globals."
	(self nonLocalBindingOf: aSymbol) ifNotNil: [ :binding | ^binding ].

	"Fail at the end."
	^nil! !

More information about the Cuis-dev mailing list