Simon Cozens: # I've hit upon quite a major problem with implementing # Perl scalar PMCs. The problem is that the code is just # too damned ugly for words. # # Remember that PMCs have a data area which is a void # pointer; I'm connecting that to a structure which has # integer, number and string slots. Those of you familiar # with Perl SVs will know exactly where I'm coming from. # # So, for instance, the method to get an integer value # ends up looking like this: # # static INTVAL Parrot_scalar_get_integer (struct Parrot_Interp # *interpreter, PMC* pmc) { # if (pmc->flags & PS_INTEGER_OK) { # return ((struct PerlScalarData *)(pmc->data))->intdata; # } else if (pmc->flags & PS_NUMBER_OK) { # pmc->flags |= PS_INTEGER_OK; # return ((struct PerlScalarData*)(pmc->data))->intdata # = (INTVAL)(((struct PerlScalarData*)(pmc->data))->numdata); # ... # }
static INTVAL Parrot_scalar_get_integer(struct Parrot_Interp *interpreter, PMC* pmc) { PSD* sd=(PSD*)pmc->data; if(FLAG_pmc_iok_TEST(pmc)) { return sd->intdata; } else if(FLAG_pmc_nok_TEST(pmc)) { return sd->intdata=(INTVAL)sd->numdata; /*should this be floatdata?*/ } else if(FLAG_pmc_sok_TEST(pmc)) { return sd->intdata=Parrot_string_to_int(psd->strdata); } else if(FLAG_pmc_rok_TEST(pmc)) { /* reference */ return (*sd->refdata->vtable[get_integer])(interpreter, sd->refdata); /*or however vtable funcs are called*/ } else { /*this should never happen*/ Parrot_croak("PANIC: Parrot_scalar_get_integer"); return 0; /*keep compilers happy*/ } } IIRC, that even complies with coding standards. Beyond that there's the distinct possibility of vtable swap outs, but it seems a bit extreme to swap out the vtable when you execute $foo+1. # And that's mild. I could typedef "struct PerlScalarData" to "PSD", # but that wouldn't really help that much. And I could fudge it all # with macros, but that's a Perl 5 thing to do. Macros for setting and testing flags are good. Other macros are bad. (Although I've been seriously thinking about how annoying it is to type 'struct Parrot_Interp *interpreter' all the time...) # Any suggestions for cleaning up this crap and making it a bit # more maintainable? As Andy already said, temporaries. --Brent Dax [EMAIL PROTECTED] Configure pumpking for Perl 6 When I take action, I'm not going to fire a $2 million missile at a $10 empty tent and hit a camel in the butt. --Dubya