[Vm-dev] Proposal: get rid of primitive numbers

David T. Lewis lewis at mail.msen.com
Sat Mar 10 22:12:14 UTC 2012


On Sat, Mar 10, 2012 at 12:08:08PM +0100, Igor Stasenko wrote:
>  
> I am get annoyed by these numbers..
> why, living in our amazingly powerful smalltalk world, in order to see
> what the primitive does,
> i should first lookup the selector in #initializePrimitiveTable method?
> 
> Is it so hard for compiler to lookup the prim by its symbolic name ,
> why i forced to do that manually all the time?
> 
> Just out of curiosity, can anyone say (without looking into image), what
> <primitive: 135> does?
> And now, same question, what
> <primitive: #primitiveMillisecondClock>
> does?
> 
> Never ending fight: meaningful names vs meaningless numbers
> 

FWIW here is what I use (attached).

So for <primitive: 135> I would do "Interpreter browsePrimitive: 135".

Dave

-------------- next part --------------
'From Squeak3.11alpha of 13 February 2012 [latest update: #11895] on 10 March 2012 at 4:19:40 pm'!


!Interpreter class methodsFor: '*DTL' stamp: 'dtl 5/24/2011 08:21'!
browsePrimitive: index
	"Interpreter browsePrimitive: 168"

	| sel |
	sel := Interpreter primitiveTable at: index + 1.
	SystemNavigation browseAllImplementorsOf: sel.
	^ index -> sel! !

!Interpreter class methodsFor: '*DTL' stamp: 'dtl 5/28/2011 09:05'!
browsePrimitiveAndPragmas: index
	"Interpreter browsePrimitiveAndPragmas: 168"

	| sel senders |
	sel := Interpreter primitiveTable at: index + 1.
	self systemNavigation browseAllImplementorsOf: sel.
	Smalltalk at: #Pragma ifPresent: [ :cls |
		senders := cls allInstances
			select: [:e | e keyword = #primitive: and: [e arguments = { index } ]]
			thenCollect: [:e | e method ]].
	^ { index -> sel . senders}! !

!Interpreter class methodsFor: '*DTL' stamp: 'dtl 5/28/2011 09:06'!
primIndexSenders: primIndex
	"Interpreter primIndexSenders: 168"

	| sel senders |
	sel := Interpreter primitiveTable at: primIndex + 1.
	self systemNavigation allImplementorsOf: sel.
	Smalltalk at: #Pragma ifPresent: [ :cls |
		senders := cls allInstances
			select: [:e | e keyword = #primitive: and: [e arguments = { primIndex } ]]
			thenCollect: [:e | e method ]].
	^ senders! !

!Interpreter class methodsFor: '*DTL' stamp: 'dtl 5/28/2011 09:08'!
primitiveForIndex: index
	"Interpreter primitiveForIndex: 168"

	^ self systemNavigation allImplementorsOf: (Interpreter primitiveTable at: index + 1)! !


More information about the Vm-dev mailing list