[self-interest] Block activation verification...

Dru Nelson dru at redwoodsoft.com
Sat Jun 3 22:26:40 UTC 2000


First, Thanks Jecel!


> True. This greatly offends some people who feel they are being cheated
> by these tricks. This led me to take a look at some outliners for

Yes, I understood the hidden slots. I don't feel tricked :-)

> 
> Variable scoping in other languages is simulated in Self using object
> inheritance. By making the implicit receiver be the current context and
> having that point to the original receiver via a self* parent slot, you
> can access both "local variables" and "instance variables" (and "class
> variables! And "globals") in a uniform way.

Yes, I understood this part too. A very elegant solution.

> this (and it would be a good idea to know this anyway since otherwise
> we can't execute the "non local return" bytecode, the "^").
> 

Now to the heart of the question  :-)

> > (3 < 4) ifTrue: [ ^nil ].
> > 
> > How is that done? 
> 
> Yet another trick - when the bytecode tells us to push a block on the
> stack, we create a clone of it with an extra slot to point to the
> currently executing context and push that instead. Note that you can't
> see this in the debugger - it does every thing it can to make you think
> that the original block was used, not its evil twin ;-)
> 
> Now when we send the 'value' message, it will go to the modified clone
> instead of the block, and this clone does know about the context we are
> interested in and so can fill in the 'lexicalParent*' slot correctly.
> >From now on, everything works as claimed.

OK, this is the trick I was looking for. I read about this in the slides
and the Self 4.0 progs' ref.  However, I didn't know how the final 
clone was created *efficiently*. In order for this to work in a naive
way, every push of a reference would have to know if the argument
was a block (a significant read barrier).  Or a block would be a 
special object type specified in the reference so the bytecode could 
do this.

Is that how it works?


> Don't worry too much about understanding all this... Self doesn't
> really work this way at all under the hood!!

I'm sure the optimizer is a whole other field in itself :-)

> 
> So David's answer was probably just what you needed :-)
> 

The last trick is the answer I needed.


Dru Nelson
San Mateo, California







More information about the Self-interest mailing list