On Mon, 2004-08-09 at 12:11, Dan Sugalski wrote: > You could look at what we do for class registration -- that code > might be similar. I don't think we've got too much at the C level > that messes around with parrot hashes yet, though.
No, not a lot of examples. Here's a patch that's somewhat naive but passes all tests on my machine (Linux PPC). I'm a bit concerned about the initialization code, especially the static hash, but it's more important to have code available for review than improvement than to wait until it's perfect to release it. -- c
Index: build_tools/build_nativecall.pl =================================================================== RCS file: /cvs/public/parrot/build_tools/build_nativecall.pl,v retrieving revision 1.49 diff -u -u -r1.49 build_nativecall.pl --- build_tools/build_nativecall.pl 9 Aug 2004 21:20:12 -0000 1.49 +++ build_tools/build_nativecall.pl 11 Aug 2004 00:21:39 -0000 @@ -175,6 +175,7 @@ * References: */ #include "parrot/parrot.h" +#include "parrot/hash.h" /* * if the architecture can build some or all of these signatures @@ -249,6 +250,8 @@ STRING *message; char *c; void *result = NULL; + static Hash *known_frames = NULL; + HashBucket *b; #if defined(CAN_BUILD_CALL_FRAMES) /* Try if JIT code can build that signature, @@ -264,8 +267,17 @@ "here there be hacks" */ UNUSED(pmc_nci); if (0 == string_length(interpreter, signature)) return F2DPTR(pcf_v_v); - $icky_global_bit + if (known_frames == NULL) + { + new_hash( interpreter, &known_frames ); + +$icky_global_bit + } + + b = hash_get_bucket( interpreter, known_frames, signature ); + if (b) + return F2DPTR( b->value ); /* These three lines have been added to aid debugging. I want to be able to @@ -437,20 +449,14 @@ HEADER } - if (defined $params) { - push @icky_global_variable, <<CALL; - if (!string_compare(interpreter, signature, - string_from_cstring(interpreter, "$return$params", 0))) - return F2DPTR(pcf_${return}_$params); -CALL - } - else { + my ($key, $value) = (defined $params ? + ( "$return$params", "pcf_${return}_$params" ) : + ( "$return", "pcf_${return}" )); + push @icky_global_variable, <<CALL; - if (!string_compare(interpreter, signature, - string_from_cstring(interpreter, "$return", 0))) - return F2DPTR(pcf_${return}); + hash_put( interpreter, known_frames, + string_from_cstring(interpreter, "$key", 0), $value ); CALL - } }