Tuesday, September 13, 2005

Implementing Composite Types using Aspects

I've been able to implement composite types outside the kernel of Maverick in a very novel way. The facilities provided by the kernel are sufficient to implement even this fundamental capability using the same features any user has access to.

The kernel of Maverick is largely composed of a hierarchical type mechanism with support for extensible attribution, a basic Aspect mechanism, and a base instance implementation that supports both general instances and lvalues.

Even Lvalues are arguably an extension to the kernel, since they are essentially implemented as a specialization aspect of instance that adds the setValue() behavior. However from a user's point of view, lvalues can't be subtypes of instances since constants and variables are both equivalent for type comparison purposes. Therefore the orthogonality of implementation is compromised trivially so that lvalues are type equivalent with instances despite their implementation.

Extending this kernel with even fundamental behaviors isn't too hard. Since even type is an instance, we can add both traditional runtime behaviors and compile-time (runtime for type) behaviors using the same basic mechanisms.

In the particular case of composite types, I added a new subtype called struct which has the runtime initializer behavior overloaded to construct a new instance's value by examining the struct subtype's new type attribute properties to discover a list of the members of the structure. The initializer then creates a value for the instance which is a hash of members and allocates a new instance for each member according to the types found in struct->properties

I also added compiletime/definetime behaviors addMember() and getMember() to the struct type so that we can add members to structs at the time the struct is defined.

Total code? Less than a hundred and fifty lines in a single user-level file.

1 comment:

Randall Lee Reetz said...

Will you please write a summery in common english. Non of the posts on your blog are brave enough to do this. Why?

Randall