Christoph Otto via RT wrote:
Allison Randal via RT wrote:
<snip>
Parent and child had to have the same struct in the original (because every PMC defined the same union val struct), and so still have to have the same struct in the new version. It is progress: at least the struct members will have more meaningful names, and it will become possible to subclass these older PMCs from within PIR. More progress will come later with enhancements to inheritance, but that's no reason to hold up the deprecation of the union struct.

So you're saying that multiple inheritance in its current state should be allowed to continue, and that there's only a problem with ATTRs if a PMC tries to extend two PMCs, both of which have their own ATTRs? If this is the case, I'm happy. The PMCs I've found which use multiple inheritance (LuaFunction, TclInt and TclFloat) all have one parent which appears to be a generic or abstract PMC type for that language (LuaAny and TclObject, respectively). I'll get to work on a patch to propagate ATTRs to children and post it here when it gets close to ready.

The attached patch implements this behavior and fixes two core PMCs that had been doing the inheritance manually. All tests in make test pass. I didn't bother testing any HLLs as this is more of a "here's what I'm thinking" patch, but it's not likely there will need to be any changes other than nuking a few more now-redundant ATTRs. Obviously, the HLLs will get a test before this gets committed, barring any other objections.
Index: src/pmc/timer.pmc
===================================================================
--- src/pmc/timer.pmc	(revision 35876)
+++ src/pmc/timer.pmc	(working copy)
@@ -59,16 +59,6 @@
 #include "parrot/scheduler_private.h"
 
 pmclass Timer extends Task provides event need_ext {
-    ATTR INTVAL        id;        /* The task ID. */
-    ATTR INTVAL        priority;  /* The priority of the task. */
-    ATTR FLOATVAL      birthtime; /* The creation time stamp of the task. */
-    ATTR STRING       *type;      /* The type of the task. */
-    ATTR STRING       *subtype;   /* The subtype of the task. */
-    ATTR STRING       *status;    /* The status of the task. */
-    ATTR Parrot_Interp interp;    /* The interpreter that created the task. */
-    ATTR PMC          *codeblock; /* An (optional) codeblock for the task. */
-    ATTR PMC          *data;      /* Additional data for the task. */
-    ATTR char         *cb_data;   /* Additional data for a callback event. */
     ATTR FLOATVAL      duration;  /* The duration of the timer pause */
     ATTR FLOATVAL      interval;  /* How often to repeat */
     ATTR INTVAL        repeat;    /* Whether to repeat:
Index: src/pmc/callsignature.pmc
===================================================================
--- src/pmc/callsignature.pmc	(revision 35876)
+++ src/pmc/callsignature.pmc	(working copy)
@@ -30,8 +30,6 @@
         PARROT_CAPTURE(obj)->hash = pmc_new((i), enum_class_Hash);
 
 pmclass CallSignature extends Capture need_ext provides array provides hash {
-    ATTR PMC    *array;      /* Positional arguments */
-    ATTR PMC    *hash;       /* Named arguments */
     ATTR PMC    *returns;    /* Result PMCs, if they were passed with the call */
     ATTR PMC    *type_tuple; /* Cached argument types for multiple dispatch */
     ATTR STRING *short_sig;  /* Simple string signature args & returns */
Index: lib/Parrot/Pmc2c/Parser.pm
===================================================================
--- lib/Parrot/Pmc2c/Parser.pm	(revision 35876)
+++ lib/Parrot/Pmc2c/Parser.pm	(working copy)
@@ -76,7 +76,7 @@
     my $lineno = count_newlines($preamble) + $chewed_lines + 1;
     my $class_init;
 
-    ($lineno, $pmcbody)    = find_attrs(  $pmc, $pmcbody, $lineno, $filename);
+    ($lineno, $pmcbody)    = find_attrs(  $pmc, $pmcbody, $lineno, $filename, $pmc2cMain);
     ($lineno, $class_init) = find_methods($pmc, $pmcbody, $lineno, $filename);
 
     $pmc->postamble( Parrot::Pmc2c::Emitter->text( $post, $filename, $lineno ) );
@@ -90,7 +90,7 @@
 }
 
 sub find_attrs {
-    my ($pmc, $pmcbody, $lineno, $filename) = @_;
+    my ($pmc, $pmcbody, $lineno, $filename, $pmc2cMain) = @_;
 
     # backreferences here are all +1 because below the qr is wrapped in quotes
     my $attr_re = qr{
@@ -130,6 +130,24 @@
     (/\*.*?\*/)?
     }sx;
 
+    #prepend parent ATTRs to this PMC's ATTR list
+    if (@{$pmc->{parents}} > 0 && $pmc->{parents}[0] ne 'default') {
+        my $got_attrs_from = '';
+        foreach my $parent (@{$pmc->{parents}}) {
+            my $parent_dump = $pmc2cMain->read_dump(lc($parent).'.dump');
+            if ($got_attrs_from ne '' && $parent_dump->{has_attribute}) {
+                die "$filename is trying to extend $got_attrs_from and $parent, ".
+                    "but both these PMCs have ATTRs.";
+            }
+            if ($parent_dump->{has_attribute}) {
+                $got_attrs_from = $parent;
+                foreach my $parent_attrs (@{$parent_dump->{attributes}}) {
+                    $pmc->add_attribute($parent_attrs);
+                }
+            }
+        }
+    }
+
     while ($pmcbody =~ s/($attr_re)//o) {
         my ($type, $name, @modifiers, $comment);
         $type = $2;

Reply via email to