It is close to time to redesign the shape thing to get dynamics.
Lets look at the problem.

We already support a finaliser for objects, and a fixed method of
scanning for contained pointers. The size of an object is known.
Arrays of objects (both static and varray) are handled automatically
for both the finalisation and scanning methods.

We will need to add some alignment info. Now.. lets also add these methods:

init_default, copy, assign

and possibly a couple of others (such as "str"). For example:

void copy(void *dst,  void*src); // copy T object

Clearly we wish to make it possible to build such a shape object under
program control.

Now suppose we want to make a product dynamically.
All we really need is an array of shapes, and generic versions of the
base methods such as

void product_copy (shape_t *shapes, int nshapes, void *dst, void *src);

Clearly, this is just a "for" loop applied to the pointers, with offsets added
each step.

We would also like to construct variants and functions, but lets focus on
the products.

Now, the problem is our copy function is the wrong type to go in a "copy"
slot. We actually need a *closure* of the function over the shape array.

There are two ways I can think of to do this.

(1) Use Felix. This is ambitious. Also it doesn't fit so well with the fact
that most of the base methods for C++ object will be wrappers around
constructors/assignment ops etc. The compiler can generate these easily.
It is not so easy to generate Felix objects.. all sorts of issues arise.

Eventually we'd like to do this of course .. :)


(2) Use C++ version of closures: applicative objects.

Now, the idea here is instead of just a simple POD for a shape,
we actually use OO (Arggghjhh ... :) :) :)

So we have an *abstract* shape base now, with pure virtual functions.

Then we have a "basic type" derived class.

The compiler will make instances by instantiating the basic type.
For example:

basic_type shape_some_type (name, size, offset_array, noffsets ..);

the only real hassle here is that this requries static initialisation.
One simple workaround is to create these in "main()" dynamically,
based on a list of POD's similar to what we have now.

OK, so for a product it is easy, we just derived a "product" class,
its constructor takes a shape array as an argument.

Obviously, variants can be handles the same way.

In fact these "meta-types" can do just about anything.
Note of course you can use "inline" C++ code in Felix to define
any new meta-types.

The real question is how to add new methods, for example to support
comparison for equality.

[And serialisation comes to mind too .. ]

The compiler will have to be extended so all this stuff can be specified for
modelled C/C++ types (i.e. abstract primitives). In case the C++ defaults
don't work.

--
john skaller
skal...@users.sourceforge.net





------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to