[Dynamite] Thoughts

Ian Holmes ihh@fruitfly.org
Wed, 22 Mar 2000 16:23:51 -0800 (PST)


I kind of like "edl" as a file extension actually.

more random thoughts on templates...

The IDL definition includes the full C++ preprocessor.
So I think we should define EDL to be our restricted IDL + a special set
of macros:

	#define EuclidArray(X,T) typedef sequence<X> T;
	#define EuclidSet(X,T) interface T { long cmp(X a, X b); ... more GTree-like methods ... };
	etc

These #defines all expand to real, typesafe IDL that maps directly to the
objects we provide when run through the C preprocessor so we are
effectively doing generic programming with macros.

sequence<X> is a special case because it seems to ask to be treated as an
in-memory, sized object (like a struct) rather than an anonymous pointer
(like an interface). We cannot provide this directly because we can't
overload the "=" operator in C.

I think the best we can do is implement it as a pseudo-interface CTYPE
(where CTYPE is a unique C name derived from the scoped IDL type T in
EuclidArray(X,T)). We provide a copy constructor & an assign method:

  CTYPE CTYPE_new_copy (CTYPE ctype);  // makes a copy & returns a pointer to it
  void CTYPE_copy_from (CTYPE ctype, CTYPE vector_to_copy_from);

Both of these are methods, so the first argument "CTYPE ctype" is like a
"this" pointer. They copy the actual X's.

There is an issue about whether to use GLib's GArray or GPtrArray for the
underlying representation of a sequence<X>. GArray is more efficient for
interfaces, GPtrArray (sometimes) for structs (because interfaces are
already pointers). It would be nice if the euclid compiler could work this
out but that will have to wait until I have a couple of afternoons to
spare. Until then I think we should try to use different macros for the
two in the IDL, i.e.

	#define EuclidArray(X,T)    typedef sequence<X> T;
	#define EuclidPtrArray(X,T) typedef sequence<X> T;

	EuclidArray(InterfaceX,T);
	EuclidPtrArray(StructY,U);

rather than

	typedef sequence<InterfaceX> T;
	typedef sequence<StructY> U;

nb both EuclidArray & EuclidPtrArray typedef to the same thing, and we
offer the same methods on them in "module_idl.h" (i.e. get functions that
return X's rather than X*'s).

Ian

-- 
Ian Holmes  ....  Howard Hughes Medical Institute  ....  ihh@fruitfly.org