[ENH request] self class.

lex at cc.gatech.edu lex at cc.gatech.edu
Fri Oct 15 21:14:19 UTC 2004


Avi Bryant <avi at beta4.com> wrote:
> On Oct 14, 2004, at 3:06 PM, Lukas Renggli wrote:
> 
> >>> Would it be possible to rename the primitive Object>>class to
> >>> Object>>basicClass, and then implement Object>>class as:
> >>
> >> In many Smalltalks, you can't override #class. Squeak is one of those 
> >> --
> >> you can comment out the primitive call in Object >> #class, and 
> >> everything
> >> still works fine. The compiler short-circuits the message, and just 
> >> answers
> >> the class (or something like that).
> >
> > I once did something similar: you can remove #class from the 
> > special-selectors collection in the compiler (class-var StdSelectors 
> > in ParseNode). From then on all methods you compile actually send the 
> > message #class and therefor it can also be overridden.
> 
> Oh, it's not in the VM - good.  Markus, does the new Compiler package 
> still have this?  Can we get rid of it?

Given that you can easily disable the optimization if you need to, I
don't see the big fuss.  At best, it seems worth removing it if there is
no performance gain.  If there is a performance gain, though, why not
leave it in?

What *would* be nice would be a comment in Object>>class, something
like:

	"Primitive. Answer the object which is the receiver's class. Essential.
See 
	Object documentation whatIsAPrimitive.

	The standard Squeak compiler does not invoke this method with the usual
message-sending mechanism.  Instead, it uses a special bytecode that
pushes the class of the receiver.  To disable this optimization, edit
Encoder initScopeAndLiteralTables and uncommen the desginated line"


And, of course, actually having a line in the Encoder method like the
following:

	"selectorSet removeKey: #class."    "uncomment this line to generate a
full message-send for sending #class"



-Lex


PS -- best of all, it would be nice if the bytecode checked the receiver
somehow, and thus maintained the illusion that it is following the
rules.  I don't know how to do it, though....



More information about the Squeak-dev mailing list