cvsuser     04/01/11 03:33:02

  Modified:    classes  parrotobject.pmc
  Log:
  patch to support nums, strings and pmcs as attributes
  Courtesy of St�phane Payrard
  
  Revision  Changes    Path
  1.15      +178 -6    parrot/classes/parrotobject.pmc
  
  Index: parrotobject.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/parrotobject.pmc,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -w -r1.14 -r1.15
  --- parrotobject.pmc  5 Dec 2003 16:40:55 -0000       1.14
  +++ parrotobject.pmc  11 Jan 2004 11:33:02 -0000      1.15
  @@ -1,7 +1,7 @@
   /* parrotobject.pmc
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: parrotobject.pmc,v 1.14 2003/12/05 16:40:55 leo Exp $
  + *     $Id: parrotobject.pmc,v 1.15 2004/01/11 11:33:02 leo Exp $
    *  Overview:
    *     These are the vtable functions for the ParrotObject base class
    *  Data Structure and Algorithms:
  @@ -32,7 +32,7 @@
   pmclass ParrotObject extends ParrotClass need_ext {
   
       void init() {
  -     /* make sure all users "new" the register class and not
  +     /* make sure all users "new" the registered class PMC and not
         * the ParrotObject itself.
         * During Parrot_class_register this init() method
         * gets replaced by Parrot_instantiate_object
  @@ -86,9 +86,20 @@
        return SELF.get_integer_keyed_int(idx);
       }
   
  +    /*
  +     * if there is a chance that attributes are accessed with an explicit
  +     * Key PMC, we need the test for the key type - if not only the
  +     * keyed_str thingy is necessary
  +     * This holds for all plain _keyed get_ and set_ variants
  +     */
       INTVAL get_integer_keyed (PMC* attr) {
  +     int flag = PObj_get_FLAGS(attr) & KEY_type_FLAGS;
  +     if ( flag & KEY_integer_FLAG) {
  +         return SELF.get_integer_keyed_int(key_integer(interpreter, attr));
  +     } else {
        return SELF.get_integer_keyed_str(key_string(interpreter, attr));
       }
  +    }
   
       void set_integer_keyed_int (INTVAL idx, INTVAL value) {
        PMC* data_array = (PMC*) PMC_data(SELF);
  @@ -107,6 +118,167 @@
       }
   
       void set_integer_keyed (PMC* attr, INTVAL value) {
  +     int flag = PObj_get_FLAGS(attr) & KEY_type_FLAGS;
  +     if ( flag & KEY_integer_FLAG) {
  +         SELF.set_integer_keyed_int(key_integer(interpreter, attr), value);
  +     } else {
        SELF.set_integer_keyed_str(key_string(interpreter, attr), value);
  +     }
  +    }
  +
  +
  +    FLOATVAL get_number_keyed_int (INTVAL idx) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     return VTABLE_get_number_keyed_int(interpreter, data_array,
  +             idx + SELF->cache.int_val);
  +    }
  +
  +    FLOATVAL get_number_keyed_str (STRING* attr) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     PMC *class = VTABLE_get_pmc_keyed_int(interpreter, data_array,
  +             POD_CLASS);
  +     INTVAL idx = VTABLE_get_integer_keyed_str(interpreter, class, attr);
  +     if (idx < 0)
  +         internal_exception(1, "No such attribute");
  +     return SELF.get_number_keyed_int(idx);
  +    }
  +
  +    FLOATVAL get_number_keyed (PMC* attr) {
  +     int flag = PObj_get_FLAGS(attr) & KEY_type_FLAGS;
  +     if ( flag & KEY_integer_FLAG) {
  +         return SELF.get_number_keyed_int(key_integer(interpreter, attr));
  +     } else {
  +         return SELF.get_number_keyed_str(key_string(interpreter, attr));
  +     }
  +
  +    }
  +
  +    void set_number_keyed_int (INTVAL idx, FLOATVAL value) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     VTABLE_set_number_keyed_int(interpreter, data_array,
  +             idx + SELF->cache.int_val, value);
  +    }
  +
  +    void set_number_keyed_str (STRING* attr, FLOATVAL value) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     PMC *class = VTABLE_get_pmc_keyed_int(interpreter, data_array,
  +             POD_CLASS);
  +     INTVAL idx = VTABLE_get_integer_keyed_str(interpreter, class, attr);
  +     if (idx < 0)
  +         internal_exception(1, "No such attribute");
  +     SELF.set_number_keyed_int(idx, value);
  +    }
  +
  +    void set_number_keyed (PMC* attr, FLOATVAL value) {
  +     int flag = PObj_get_FLAGS(attr) & KEY_type_FLAGS;
  +     if ( flag & KEY_integer_FLAG) {
  +         SELF.set_number_keyed_int(key_integer(interpreter, attr), value);
  +     } else {
  +         SELF.set_number_keyed_str(key_string(interpreter, attr), value);
  +     }
  +
  +    }
  +
  +
  +    STRING* get_string_keyed_int (INTVAL idx) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     return VTABLE_get_string_keyed_int(interpreter, data_array,
  +             idx + SELF->cache.int_val);
  +    }
  +
  +    STRING* get_string_keyed_str (STRING* attr) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     PMC *class = VTABLE_get_pmc_keyed_int(interpreter, data_array,
  +             POD_CLASS);
  +     INTVAL idx = VTABLE_get_integer_keyed_str(interpreter, class, attr);
  +     if (idx < 0)
  +         internal_exception(1, "No such attribute");
  +     return SELF.get_string_keyed_int(idx);
  +    }
  +
  +    STRING* get_string_keyed (PMC* attr) {
  +     int flag = PObj_get_FLAGS(attr) & KEY_type_FLAGS;
  +     if ( flag & KEY_integer_FLAG) {
  +         return SELF.get_string_keyed_int(key_integer(interpreter, attr));
  +     } else {
  +         return SELF.get_string_keyed_str(key_string(interpreter, attr));
  +     }
  +    }
  +
  +    void set_string_keyed_int (INTVAL idx, STRING* value) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     VTABLE_set_string_keyed_int(interpreter, data_array,
  +             idx + SELF->cache.int_val, value);
  +    }
  +
  +    void set_string_keyed_str (STRING* attr, STRING* value) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     PMC *class = VTABLE_get_pmc_keyed_int(interpreter, data_array,
  +             POD_CLASS);
  +     INTVAL idx = VTABLE_get_integer_keyed_str(interpreter, class, attr);
  +     if (idx < 0)
  +         internal_exception(1, "No such attribute");
  +     SELF.set_string_keyed_int(idx, value);
  +    }
  +
  +    void set_string_keyed (PMC* attr, STRING* value) {
  +     int flag = PObj_get_FLAGS(attr) & KEY_type_FLAGS;
  +     if ( flag & KEY_integer_FLAG) {
  +         SELF.set_string_keyed_int(key_integer(interpreter, attr), value);
  +     } else {
  +         SELF.set_string_keyed_str(key_string(interpreter, attr), value);
  +     }
  +    }
  +
  +
  +    PMC* get_pmc_keyed_int (INTVAL idx) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     return VTABLE_get_pmc_keyed_int(interpreter, data_array,
  +             idx + SELF->cache.int_val);
  +    }
  +
  +    PMC* get_pmc_keyed_str (STRING* attr) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     PMC *class = VTABLE_get_pmc_keyed_int(interpreter, data_array,
  +             POD_CLASS);
  +     INTVAL idx = VTABLE_get_integer_keyed_str(interpreter, class, attr);
  +     if (idx < 0)
  +         internal_exception(1, "No such attribute");
  +     return SELF.get_pmc_keyed_int(idx);
  +    }
  +
  +    PMC* get_pmc_keyed (PMC* attr) {
  +     int flag = PObj_get_FLAGS(attr) & KEY_type_FLAGS;
  +     if ( flag & KEY_integer_FLAG) {
  +         return SELF.get_pmc_keyed_int(key_integer(interpreter, attr));
  +     } else {
  +         return SELF.get_pmc_keyed_str(key_string(interpreter, attr));
  +     }
  +
  +    }
  +
  +    void set_pmc_keyed_int (INTVAL idx, PMC* value) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     VTABLE_set_pmc_keyed_int(interpreter, data_array,
  +             idx + SELF->cache.int_val, value);
  +    }
  +
  +    void set_pmc_keyed_str (STRING* attr, PMC* value) {
  +     PMC* data_array = (PMC*) PMC_data(SELF);
  +     PMC *class = VTABLE_get_pmc_keyed_int(interpreter, data_array,
  +             POD_CLASS);
  +     INTVAL idx = VTABLE_get_integer_keyed_str(interpreter, class, attr);
  +     if (idx < 0)
  +         internal_exception(1, "No such attribute");
  +     SELF.set_pmc_keyed_int(idx, value);
  +    }
  +
  +    void set_pmc_keyed (PMC* attr, PMC* value) {
  +     int flag = PObj_get_FLAGS(attr) & KEY_type_FLAGS;
  +     if ( flag & KEY_integer_FLAG) {
  +         SELF.set_pmc_keyed_int(key_integer(interpreter, attr), value);
  +     } else {
  +         SELF.set_pmc_keyed_str(key_string(interpreter, attr), value);
  +     }
       }
   }
  
  
  

Reply via email to