I have just committed a new library module (and modified the compiler to support it). This module provides functions to display the list of dynamically allocable types:
////////// open Rtti; var k = new 1.0; println$ *k; var h = shape_list_head (); whilst not isNULL(h) do println$ "type " + cname h; h = next_shape h; done ///////////// ~/felix>flx --test=build/release-optimized/ rtt 1 type double type thread_frame_t type unit type address type int type _uctor_ type schannel_t type fthread_t type slist_t type slist_node_t My program is to add functions to allow you to *dynamically create new types*. The original need came about when trying to write the library for Google's re2. The problem is re2::RE2, the regexp class, is not copyable. As you know, Felix requires all values to be first class, that is, default constructable, copyable, assignable, and destructable. Variables are never initialised in the C++ sense, instead they're always default initialised and then assigned their initial value. Values allocated on the heap have associated shape objects which contain the size of the object, an array of offsets into the object which contain pointers, and a finaliser (and a couple of flags and other things). In order to heap allocate an object on the Felix heap, you have to call: new (gc, shape) Ctor (args) where gc is a reference to the garbage collector, and shape is a reference to the shape object for that type. The data in the shape is used to check the allocation size, and the finaliser is called when the object becomes unreachable via a Felix heap pointer. The only way to use the Google re2::RE2 type is to allocate it on the heap. The existing "new" will not work (dang!) because it *copies* an object onto the heap. It is easy enough to write a constructor function binding to C code like the above new function call .. **except** that we have no shape object for this type, and no way to make one. The obvious solution is to add a property to the type (if there isn't one already, LOL!) which forces the compiler to generate a shape. I will probably do this anyhow but .. .. it is a good opportunity to provide a more powerful tool: the ability to generate shapes at run time. After all, a shape is just a C struct with some data in it :) So the program will be: a) make sure we can get info about what shapes we have, so we can check the dynamic generation is working. It is interesting but we can actually print the addresses of every heap objects categorised by type! Since we have a judy array which maps every allocated pointer to its shape. b) Provide routines to construct new shape objects .. on the heap! Which means I need to add a "shape of shape" shape .. :) c) provide a routine to link the shape into the list. The list has no semantics, it is there purely for diagnostic purposes. d) We need to ensure the shape object is not deleted by the gc before all the object of that type are deleted, since it holds the finaliser for those objects. The easiest way is to just make these shapes roots. Given this, the user can dynamically create a new type *managed by the gc*. [Creating new types dynamically in general is trivial, it is just casting and raw addesss manipulation] -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. http://p.sf.net/sfu/intelisp-dev2dev _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language