[BUG] ProtoObject class

Dwight Hughes dwighth at ipa.net
Fri Jul 7 19:59:55 UTC 2000


It is important that messages sent as arguments to #perform: and its ilk
return the same results as the same message "hardwired" in code. The
Object>>class method is there for that reason (though it could be moved
up to ProtoObject now if desired).

Marcus Denker wrote:
> 
> On Thu, Jul 06, 2000 at 02:37:56PM +0200, Johan Fabry wrote:
> > Also, if you define a 'class' method in a PrimitiveObject subclass (e.g.
> > 'self halt.'), this code will not be executed, you will still get the
> > class of the receiver.
> >
> Yes. the "class"-Method is never called. There is a special bytecode for
> this message-send generated by the compiler:

It will be called if you do "1 perform: #class", or if the compiler is
changed to not emit the #class bytecode.

> eg. a method  "1 class" will be compiled to
> 
> 5 <76> pushConstant: 1
> 6 <C7> send: class
> 7 <87> pop
> 8 <78> returnSelf
> 
> That's Bytecode C7 (199)
> 
> Now look at Interpreter class>>initializeBytecodeTable, there you will
> find
> 
>  (199 bytecodePrimClass)
> 
> so primitive 111 (primitiveClass) never gets called, and it's even
> not implemented in the Interpreter.
> 

Primitive 111 certainly gets called with <anObject> perform: #class .
Look at Interpreter class>>initializePrimitiveTable. What do you suppose
the Interpreter>>primitiveClass method does?

> > I was wondering, since I have never messed around with primitives, can I
> > safely copy-paste the contents of the definition of 'class' into
> > ProtoObject and then remove the definition from Object? (Have not tried
> > it yet, just wondering if this will generate random crashes or some
> > other ugly/unpredictable behaviour)
> 
> You can even delete it ;-)

I wouldn't.

-- Dwight





More information about the Squeak-dev mailing list