Brent Dax: # 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.
Actually, that should be more like: 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; } FLAG_pmc_iok_SET(pmc); if(FLAG_pmc_nok_TEST(pmc)) { return sd->intdata=(INTVAL) sd->numdata; } else if(FLAG_pmc_sok_TEST(pmc)) { return sd->intdata=Parrot_string_to_int(sd->strdata); } else if(FLAG_pmc_rok_TEST(pmc)) { /* assuming we want to handle references this way */ return sd->intdata=sd->refdata->vtable->get_integer(interpreter, sd->refdata); } else { Parrot_croak("PANIC: Parrot_scalar_get_integer"); return 0; } } --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