A simple, powerful, efficient typesystem

Eric W. Biederman ebiederm@cse.unl.edu
Wed, 24 Apr 1996 02:59:46 -0500


I have been recently doing some thinking and reviewing and trying to
come to terms with how to implement a system with the effeciency of
C++ without the high perobject space cost, and inflexibility that C++
has.

The basic typesystem has 3 parts.

Types -- roughly a C++ class

Interfaces -- an abstraction that states how an instance of a type may
              be implemented.

Views -- A mapping between the functions of a type, (possibly also of
         data) and the expected layout of an interface.

The way this is implemented is instead of sticking type & subtype
information inside of every object, in the form of a virtual function
table pointer as in C++, the virtual function table pointer is put in
the object reference along with a pointer to the object.  From that
point on it's just like C++, in efficiency.

Views are the behide the scenes guys that make all of this work.  A
view really is a virtual function table.  But it is user configurable
and mappable to different functions, so you no longer have to have an
inheritence tree to deal with types & subtypes (As represented by
interfaces).  In fact all of the C++ nonsense about virtual functions
versus nonvirtual functions can be pretty much forgotten.  

The only penalty for this method of organization is that object
pointers are twice as big (unless you seperate views from objects ?)
and when a view is generated from another view essentially a whole new
view must be generated on the fly, so they are no longer totally
static.  These seem to be reasonable tradeoffs for a language that is
destined to as a very hll, with who knows what not going on behind the
scenes. 

It probably should be looked at to see which OO languages implement
this distinction of objects & interfaces.

This has been implemented in g++ so it's not my own idea.  Though
you'll have to dig to find it.  I haven't read the docs on it in a
very, very long time.

I real neat potential for this reorganization of OO implementation is
that generics/templates could be rolled into invokers of virtual
functions upon views, while also being able to be specialized for
added efficiency.

Anyhow so version of these concepts would work nicely I think for
tunes.

What do you tunespeople think?

Eric