Prototype Objects in Squeak

Russell Allen mail at russell-allen.com
Sat Apr 9 07:07:26 UTC 2005


Hi all,

In a fit of procrastination, I have created a changeset allowing 
classless objects in Squeak (actually objects which are their own 
class).

Its at: http://russell-allen.com/squeak/prototypes/

Use at your own risk!  This sort of stuff can seriously affect your 
image...  Please tell me if it doesn't work as I haven't really tested 
it much (ok, at all).

Cheers,

Russell

 From the changeset:

This is an implementation of prototype objects.

It replaces a previous implementation by Hans-Martin Mosner, which I 
extended (in an ugly way) to handle delegation of behaviour.  
Hans-Martin's code is still available.

Filing in this changeset and running Prototype>>newPrototype will 
return a prototype object, that is an object without a class.

This object will understand the following basic messages:

	parent/parent:				set and retrieve the parent of the object
	addSlot:/removeSlot:			add and remove a data slot
	addMethod:/removeMethod:	add and remove a method
	clone						return a new prototype, same as the old prototype
							
Single inheritance is preserved through the parent slot.   At the 
moment, the prototypes must inherit (eventually) from Behavior 
otherwise they blow up.

The code works by creating an object which is its own class.  You can 
test this on a prototype:

|p|
p _ Prototype newPrototype.
p == p class

should evaluate to true.

A simple clone of a prototype creates a lightweight prototype 
(essentially an instance) to save memory space.  Changing anything (ie 
adding a slot etc) will result in the conversion to a heavyweight 
prototype.

At the moment, I think an image full of prototypes would be larger and 
slower; but I think that this penalty can be reduced (perhaps to nil).

Prototype objects can be inspected and altered in the inspector, 
debugging should work.




More information about the Squeak-dev mailing list