Does #class deserve to be a very-special shortcutbytecodeanymore?

Stephen Pair spair at advantive.com
Sun Jan 6 15:18:25 UTC 2002


> 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? 

Actually, it should be:

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

The receiver needs to be the first parameter.  It's a dirty little hack
that works only because the primitive doesn't care that an extra thing
has been pushed onto the stack...note that the extra thing (the
receiver) will stay on the stack.  All the primitive cares about are the
top two things on the stack.  A similar pattern can be used for the
other primitives.

- Stephen






More information about the Squeak-dev mailing list