Does #class deserve to be a very-special shortcut bytecodeanymore?

ducasse ducasse at iam.unibe.ch
Sun Jan 6 09:08:16 UTC 2002


on 1/6/02 3:22 AM, Stephen Pair at spair at advantive.com wrote:

> ducasse wrote:
> 
>> Since I saw the animorphic way of doing that, I'm really
>> thinking that I want to try. Moving all the reflective stuff
>> into mirror.
>> 
>> I never wrote a primitive (yet). But for the instVarAt: the
>> primitive right now works on the receiver and with mirror all
>> the reflection will be on arguments.
>> 
>> I would like to know if this means that I have to change the
>> primitives like
>> instVarAt:  and recompile eveyrthing. May be I can try to add
>> some primitives to have the system still running plus having
>> mirrors. What is your experience?
>> 
>> Stef



I could not resist so I tried something.


> It's pretty straightforward to add a new primitive that works like an
> existing one, but does it's work on an argument instead of the receiver.
> In fact, a while ago someone (I think Tim) noted that you can actually
> use existing primitives, but just compile them into a method with an
> extra argument. 

You mean 

Mirror>>on: anObject

    reflected := anObject

Mirror>>instVarAt: anInteger

    ^ reflected instVarAt: anInteger


With this solution I do not have to compile them into a method but the
behavior is still on Object. This can be only good to play with the idea.

I do not really see how the primitive can work with the following

Mirror>>instVarAt: index of: anObject

    <primitive: 73>
    "Access beyond fixed variables."
    ^ anObject basicAt: index - anObject class instSize

But the code of the primitive is referring to the receiver so how this can
work? 


 You wouldn't need to re-compile everything, just change
> the users of the old methods to use the mirror based protocol instead.
> The problem I have with doing such things is that it breaks
> encapsulation...ultimately, what would be good is to use a mirror based
> scheme, but allow the object itself to govern what can and cannot be
> done through the mirror, and to even override the default behaviors of a
> mirror when reflecting on it.

Stef





More information about the Squeak-dev mailing list