How to create a self-desribing BlockContext?

Dan Ingalls Dan.Ingalls at disney.com
Thu Sep 9 15:50:59 UTC 1999


>I need a new BlockContext that describes the send it contains, in terms of
>receiver, selector, and arguments.  I need these as instance variables, so
>that I can compute a hash to determine the block's uniqueness.  Current
>BlockContexts seem to be instantiated as modified clones of an blank block
>in the "special objects" array.  I don't see immediately how to work with
>this situation.  My first thought is to create another special object and
>modify the block syntax slightly and the parser accordingly, to accommodate
>the new blocks without messing up the old ones.  Any suggestions on how to
>created the new BlockContext class would be appreciated.

BlockContexts are treated specialy by the VM so it is unlikely that you can get things to work with your own implementation, except as a simulation.  It's hard to make suggestions, since you haven't said what you really want to do.  The text of your message seems to imply that your blocks are very simple, as

	[rcvr selector: arg].

If this is the case, then you could just as easily use an instance of Message (or a subclass which you could eeasily write that included the receiver) instead of a block.  It would be easy to hash and compare these, and it would be easy to get the equivalent of the #value method by using the existing #sentTo: method.

Hope this helps.

	- Dan

PS  Of course it is easy to determine a block's uniqueness using ==, and its response to identityHash should also work fine for you.  There are more things that blocks can easily tell you, such as what method they are from, in what class, and so on.  If you must use blocks, I can even show you how to make it look like rcvr, selector and arg are instance variables in a simple case like that above, but it won't be quite so simple.





More information about the Squeak-dev mailing list