>>>>> "SC" == Simon Cozens <[EMAIL PROTECTED]> writes:


  SC> So, for instance, the method to get an integer value
  SC> ends up looking like this:

  SC> static INTVAL Parrot_scalar_get_integer (struct Parrot_Interp *interpreter, PMC* 
pmc) {
  SC>     if (pmc->flags & PS_INTEGER_OK) {
  SC>         return ((struct PerlScalarData *)(pmc->data))->intdata;
  SC>     } else if (pmc->flags & PS_NUMBER_OK) {
  pmc-> flags |= PS_INTEGER_OK;
  SC>     return ((struct PerlScalarData*)(pmc->data))->intdata
  SC>         = (INTVAL)(((struct PerlScalarData*)(pmc->data))->numdata);
  SC>     ...
  SC> }

  SC> Any suggestions for cleaning up this crap and making it a bit
  SC> more maintainable?

unions?

the data field could be a union of all possible data type pointers. then
your code would be more like:

<rough code>

        return pmc->data.int->intdata;

        return pmc->data.int->intdata = (INTVAL) pmc->data.num->numdata ;

and the PMC would have in it:

        union {

                INTVAL  *int ;
                NUMVAL  *num ;
        } data ;

i know there are anti-unionists out there but this does solve the
massive casting problems and lets the compiler do more type checking.

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

Reply via email to