On 25/11/2010, at 3:36 PM, john skaller wrote: [] Well, more work: RE2 objects are uncopyable, so we can't use them directly in Felix. Instead, we have to use a pointer. Unfortunately, if we just use this:
type RE2 = "*::re2::RE2"; then we have to manage the memory ourselves, i.e. delete the object explicitly. What we want if for the garbage collector to track these pointers and delete the object when there are no references to it. OTOH, we have no idea what's in the object so we don't want to scan it. This can all be done by constructing an RE2_ptr_map, that is, an RTTI object and just put no offsets .. the problem is, this has to be done in C++, and the RTTI object has to link into the chain of RTTI objects. At present, there's no way to add an RTTI object into the chain, statically or dynamically. These things aren't hard to make: // ******************************************************** // pointer implementation // ******************************************************** //OFFSETS for address static std::size_t _address_offsets[1]={ 0 }; ::flx::gc::generic::gc_shape_t _address_ptr_map = { &_int_ptr_map, "address", 1, sizeof(void*), 0, 1, _address_offsets, gc::generic::gc_flags_default }; is from the RTL, modelling a raw pointer. notice the back link to the model for int. This would actually work fine for any pointer, whether it is a pointer to the Felix heap or otherwise, since the GC keeps track of all pointers it allocates. The problem is, for a non-Felix pointer the object pointed at just gets lost, not destroyed or deleted, so we need a real RE2 shape. There is in fact a uniform way to get this: provide a polymorphic ref-counted pointer in the RTL, something like template<class T> struct ptr { int *count; T *data; }; The shape for this is independent of T and has no offsets. As usual, if the count goes to zero, data is deleted. The destructor is vital, since it decrements the ref count (possibly deleting the data too). However this destructor is polymorphic! Because delete data is polymorphic (depends on type T). This means the compiler has to instantiate it, in the usual way for type refptr[T] = "refptr<?1>"; it should do this .. if only T=RE2 were available. To stop copying this might work: incomplete type RE2 = "::re2::RE2"; This prevents all instantiations of RE2, you can't make one. But you should be able to do: var r : &RE2 = new RE2; and then, we don't need any shape stuff! Well maybe .. Unfortunately, operator new is hacked: it works by COPYING an object onto the heap. In particular the syntax is new (any_expression) in other words, it doesn't require a constructor (Felix doesn't HAVE constructors!), just an object .. and RE2 objects aren't copyable :) The question now is: can this be done a) in Felix as is b) with help from the C++ library c) or do I have to modify the compiler? There is actually one, messy, way to do it in the RTL: modify the GC so it allows a NULL shape. At the moment the shape contains the object length (see above, sizeof(T) thing). However this isn't needed to allocate via C++ operator new, since the size is passed in. And it isn't needed to delete the memory with the current malloc/free implementation (since free doesn't require it). If we really hacked the GC, the dynamic size could be used. Anyhow, I'm not sure of the bottom line here! For the moment, RE2 can easily be tested by requiring manual deletion, but it doesn't solve the problem in general. -- 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