On 01/02/2011, at 3:42 PM, john skaller wrote: > Felix now has a pluggable object scanner in the GC. >> From the commit log: >
So with a Judy1 scanner implemented in C++ as standard part of the gc system, this is (almost) working: private type J1Array_ = "void*" requires scanner "::flx::gc::generic::Judy1_scanner", header '#include "flx_judy_scanner.hpp"' ; _gc_pointer _gc_type J1Array_ type J1Array = "void**" requires property "needs_gc"; // @0 is wrong here, we need a J1Array_ptr_map // but then, we don't need the "scanner" spec gen _ctor_J1Array: 1 -> J1Array = "_mkj1(FLX_POINTER_TO_THREAD_FRAME, &@0)" requires body """ void **_mkj1(FLX_APAR_DECL ::flx::gc::generic::gc_shape_t *jptr_map){ typedef void *voidp; // syntax void **m = new (*PTF gcp, *jptr_map, false) voidp; *m=0; return m; } """, property "needs_gc"; I'm sure you'll agree .. this is a bit of a mess! What happens is: First a Judy array value is a just a void*, initially 0. However such pointers aren't copyable, so we need to add a level of indirection and use a void**: that's a pointer we can copy about which is (intended to) refer to a single Judy array on the heap. However, the scanner scans an actual Judy array, not a point to one. This is intentional because in some C struct we might legitimately have an actual Judy array, safe if the C struct thing isn't copied. So we introduce a private type for the actual Judy array, specify the new fangled scanner should be used for that type, and then include the header file so the system can actually find the scanner function. Now we define the Judy array we're going to use as a void**. We have to tell Felix that when we use one of these animals, we have to generate a shape object for a Judy array, that's what the _gc_type thing is for. We also have to tell Felix that the public level abstract type is actually a pointer which the GC needs to trace. Finally we have to tell Felix that using this type requires garbage collection, so if we're using some function with the type in it, construction requires a pointer to the thread frame (which contains a pointer to the collector). Now the constructor calls the C functions _mkj1, passing in the thread frame and a pointer to the shape object, which is given by @0 meaning "shape of the return type". Actually it uses the shape of the return types *delegate* which is the _gc_type thing. We use a pointer because shapes aren't intended to be copyable. To make this function work we have to define it, which we do in that body clause. We make the Judy array on the heap, and set it to 0, then return the pointer. All of this actually seems to work! The only problem is that the scanner doesn't :) -- 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