anObject becomeForward: aSmallInteger

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

anObject becomeForward: aSmallInteger

Michael van der Gulik
Why can an object not #becomeForward to a SmallInteger? The primitive fails.

A SmallInteger's value is stored in the actual pointer. It makes them a
special case, but the abstraction is surprisingly water-tight :-)!

I don't see any reason why this primitive can't succeed with this case.
Just carve out the object reference and stick a SmallInteger there, or
vice versa. Is there something obvious that I'm missing?

Mikevdg.


Reply | Threaded
Open this post in threaded view
|

Re: anObject becomeForward: aSmallInteger

Tom Phoenix
On 6/25/06, Michael van der Gulik <[hidden email]> wrote:

> Why can an object not #becomeForward to a SmallInteger? The
> primitive fails.

In performing #becomeForward:, the VM converts each pointer to object
Old into a pointer to object New. But there is no pointer to a
SmallInteger (and maybe other classes, depending upon the Smalltalk
implementation).

But in principle, the VM could certainly replace each instance of
object Old instead with a SmallInteger. It doesn't, probably because
that's not what #become: is made to do; it's made to work with object
pointers, not immediate objects.

You could use a subclass of PointerFinder to do what you want, I
think. It would need to not only find the pointer to object Old, but
replace it with whatever target value you would like, even a
SmallInteger. You'd have to use some minor magic, such as
#instVarAt:put:, but that's less likely to cause confusion compared to
the #become: family.

Good luck with it!

--Tom Phoenix