[svn:parrot] r36525 - in trunk: lib/Parrot lib/Parrot/Pmc2c src/pmc t/tools

NotFound at svn.parrot.org NotFound at svn.parrot.org
Tue Feb 10 03:50:39 UTC 2009


Author: NotFound
Date: Tue Feb 10 03:50:34 2009
New Revision: 36525
URL: https://trac.parrot.org/parrot/changeset/36525

Log:
[core] implement inheritance of PMC args to pir derived classes, TT #299, realclean recommended

Modified:
   trunk/lib/Parrot/Pmc2c/Attribute.pm
   trunk/lib/Parrot/Pmc2c/PMCEmitter.pm
   trunk/lib/Parrot/Vtable.pm
   trunk/src/pmc/exceptionhandler.pmc
   trunk/src/pmc/pmcproxy.pmc
   trunk/t/tools/pmc2c.t

Modified: trunk/lib/Parrot/Pmc2c/Attribute.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/Attribute.pm	Tue Feb 10 03:34:18 2009	(r36524)
+++ trunk/lib/Parrot/Pmc2c/Attribute.pm	Tue Feb 10 03:50:34 2009	(r36525)
@@ -104,6 +104,7 @@
     my $isptrtostring = qr/STRING\s*\*$/;
     my $isptrtopmc    = qr/PMC\s*\*$/;
 
+    my $inherit        = 1;
     my $decl           = <<"EOA";
 
 /* Generated macro accessors for '$attrname' attribute of $pmcname PMC. */
@@ -116,21 +117,21 @@
         $decl .= <<"EOA";
             PMC *attr_value = VTABLE_get_attr_str(interp, \\
                               pmc, Parrot_str_new_constant(interp, "$attrname")); \\
-            (dest) = VTABLE_get_integer(interp, attr_value); \\
+            (dest) = (PMC_IS_NULL(attr_value) ? (INTVAL) 0: VTABLE_get_integer(interp, attr_value)); \\
 EOA
     }
     elsif ($attrtype eq "FLOATVAL") {
         $decl .= <<"EOA";
             PMC *attr_value = VTABLE_get_attr_str(interp, \\
                               pmc, Parrot_str_new_constant(interp, "$attrname")); \\
-            (dest) = VTABLE_get_number(interp, attr_value); \\
+            (dest) =  (PMC_IS_NULL(attr_value) ? (FLOATVAL) 0.0: VTABLE_get_number(interp, attr_value)); \\
 EOA
     }
     elsif ($attrtype =~ $isptrtostring) {
         $decl .= <<"EOA";
             PMC *attr_value = VTABLE_get_attr_str(interp, \\
                               pmc, Parrot_str_new_constant(interp, "$attrname")); \\
-            (dest) = VTABLE_get_string(interp, attr_value); \\
+            (dest) =  (PMC_IS_NULL(attr_value) ? (STRING *) 0: VTABLE_get_string(interp, attr_value)); \\
 EOA
     }
     elsif ($attrtype =~ $isptrtopmc) {
@@ -141,6 +142,7 @@
     }
 
     else {
+        $inherit = 0;
         $decl .= <<"EOA";
             Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, \\
                 "Attributes of type '$attrtype' cannot be " \\
@@ -206,6 +208,8 @@
 
 EOA
 
+    $self->{inherit} = $inherit;
+
     $h->emit($decl);
 
     return 1;

Modified: trunk/lib/Parrot/Pmc2c/PMCEmitter.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/PMCEmitter.pm	Tue Feb 10 03:34:18 2009	(r36524)
+++ trunk/lib/Parrot/Pmc2c/PMCEmitter.pm	Tue Feb 10 03:50:34 2009	(r36525)
@@ -435,6 +435,7 @@
         NULL,       /* isa_hash */
         NULL,       /* class */
         NULL,       /* mro */
+        attr_defs,  /* attribute_defs */
         NULL,       /* ro_variant_vtable */
         $methlist
     };
@@ -487,6 +488,34 @@
 void
 Parrot_${classname}_class_init(PARROT_INTERP, int entry, int pass)
 {
+    static const char attr_defs [] =
+EOC
+    $cout .= '        "';
+
+    my $attributes = $self->attributes;
+    foreach my $attribute ( @$attributes ) {
+        my $attrtype       = $attribute->{type};
+        my $typeid = ':'; # Unhandled
+        if ($attrtype eq "INTVAL") {
+            $typeid = 'I';
+        }
+        elsif ($attrtype eq "FLOATVAL") {
+            $typeid = 'F';
+        }
+        elsif ($attrtype =~ /STRING\s*\*$/) {
+            $typeid = 'S';
+        }
+        elsif ($attrtype =~ /PMC\s*\*$/) {
+            $typeid = 'F';
+        }
+
+        $cout .= $typeid;
+        $cout .= $attribute->name;
+        $cout .= ' ';
+    }
+
+    $cout .= "\";\n";
+    $cout .= <<"EOC";
 $vtable_decl
 EOC
 

Modified: trunk/lib/Parrot/Vtable.pm
==============================================================================
--- trunk/lib/Parrot/Vtable.pm	Tue Feb 10 03:34:18 2009	(r36524)
+++ trunk/lib/Parrot/Vtable.pm	Tue Feb 10 03:50:34 2009	(r36525)
@@ -175,6 +175,7 @@
     PMC    *pmc_class;      /* for PMCs: a PMC of that type
                                for objects: the class PMC */
     PMC    *mro;            /* array PMC of [class, parents ... ] */
+    const char *attribute_defs; /* list of PMC attributes */
     struct _vtable *ro_variant_vtable; /* A variant of this vtable with the
                                    opposite IS_READONLY flag */
     /* Vtable Functions */

Modified: trunk/src/pmc/exceptionhandler.pmc
==============================================================================
--- trunk/src/pmc/exceptionhandler.pmc	Tue Feb 10 03:34:18 2009	(r36524)
+++ trunk/src/pmc/exceptionhandler.pmc	Tue Feb 10 03:50:34 2009	(r36525)
@@ -192,20 +192,22 @@
         STRING * const sev    = CONST_STRING(interp, "severity");
         STRING * const ex_str = CONST_STRING(interp, "Exception");
 
-        Parrot_ExceptionHandler_attributes * const core_struct =
-                    PARROT_EXCEPTIONHANDLER(SELF);
         INTVAL severity = VTABLE_get_integer_keyed_str(interp, exception, sev);
 
         if (exception->vtable->base_type == enum_class_Exception
         ||  VTABLE_isa(INTERP, exception, ex_str)) {
-            PMC * handled_types;
+            PMC *handled_types;
+            PMC *handled_types_except;
+	    INTVAL min_severity, max_severity;
             GET_ATTR_handled_types(INTERP, SELF, handled_types);
+            GET_ATTR_handled_types_except(INTERP, SELF, handled_types_except);
+            GET_ATTR_max_severity(INTERP, SELF, max_severity);
+            GET_ATTR_min_severity(INTERP, SELF, min_severity);
 
-            if (severity < core_struct->min_severity) {
+            if (severity < min_severity) {
                 RETURN(INTVAL 0);
             }
-            if (core_struct->max_severity > 0
-                 &&  severity                  > core_struct->max_severity) {
+            if (max_severity > 0 &&  severity > max_severity) {
                 RETURN(INTVAL 0);
             }
             if (! PMC_IS_NULL(handled_types)) {
@@ -222,22 +224,21 @@
 
                 RETURN(INTVAL 0);
             }
-            if (core_struct->handled_types_except != PMCNULL) {
-                const INTVAL elems = VTABLE_elements(interp, core_struct->handled_types_except);
+            if (handled_types_except != PMCNULL) {
+                const INTVAL elems = VTABLE_elements(interp, handled_types_except);
                 const INTVAL type  = VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "type"));
                 INTVAL i;
 
                 for (i = 0; i < elems; i++) {
                     const INTVAL handled_type = VTABLE_get_integer_keyed_int(interp,
-                            core_struct->handled_types_except, i);
+                            handled_types_except, i);
                     if (handled_type == type)
                         RETURN(INTVAL 0);
                 }
 
                 RETURN(INTVAL 1);
             }
-            else if (core_struct->max_severity > 0 ||
-                    core_struct->min_severity > 0) {
+            else if (max_severity > 0 || min_severity > 0) {
                 RETURN(INTVAL 1);
             }
 

Modified: trunk/src/pmc/pmcproxy.pmc
==============================================================================
--- trunk/src/pmc/pmcproxy.pmc	Tue Feb 10 03:34:18 2009	(r36524)
+++ trunk/src/pmc/pmcproxy.pmc	Tue Feb 10 03:50:34 2009	(r36525)
@@ -160,6 +160,26 @@
             Parrot_oo_extract_methods_from_namespace(interp, SELF,
                     proxy_info->_namespace);
         }
+
+        { /* Create inherited attributes */
+            /* Each attribute is prefixed with his type
+             * and terminated by an space,
+             * the list is '\0' terminated
+             */
+            const char * attr = interp->vtables[type_num]->attribute_defs;
+            while (* attr) {
+                const char * const current = attr + 1;
+                size_t l;
+                char attrtype = * attr;
+                while (* attr != ' ') ++attr;
+                l= attr - current;
+                if (attrtype != ':') {
+                    STRING *sattr = Parrot_str_new(interp, current, l);
+                    SELF.add_attribute(sattr, NULL);
+                }
+                ++attr;
+            }
+        }
     }
 
 /*

Modified: trunk/t/tools/pmc2c.t
==============================================================================
--- trunk/t/tools/pmc2c.t	Tue Feb 10 03:34:18 2009	(r36524)
+++ trunk/t/tools/pmc2c.t	Tue Feb 10 03:50:34 2009	(r36525)
@@ -93,6 +93,8 @@
 void
 Parrot_a_class_init(PARROT_INTERP, int entry, int pass)
 {
+    static const char attr_defs [] =
+        "";
     const VTABLE temp_base_vtable = {
 END_C
 


More information about the parrot-commits mailing list