Leopold Toetsch wrote:

Matt Diephouse wrote:

There's currently no way to call a superclass' method. I've just run
into this and leo suggested I sent a note to the list.

Here's what I want to do:

I have a ParrotClass (a class defined in PIR) that is derived from the
String class. I want to override it's set_string_native method to do
some processing before I store the value. My first attempt was this:

    .sub __set_string_native method
      .param string value
      self = value
      print "assign\n"
    .end


While we haven't something like:

      self.SUPER::__set_string_native(value)


... it's still possible to call super for some methods like the __set_string_native, by extracting the first attribute:

.sub __set_string_native method
   .param string s
   $I0 = classoffset self, "MyClass"
   $P0 = getattribute self, $I0
   $P0 = s
.end

see also t/pmc/object-meths_30.pir (r8674)

The question ramains of course, why you should do that, as the inherited method just does the same, that is - just don't declare __set_string_native, *if* there isn't any difference in implementation.
leo

I've been in situations that you would want to call the superclass' constructor from the child's constructor, this is handy in situations that you want to add some extra things to the constructor, and you don't want to duplicate the code. So, in my opinion it would be handy. A somewhat related point to this, as well as related to an earlier question of mine wrt implementing PMCs in PIR; is it possible to access the internal datastructure of the PMC in PIR? So, for example, if you would want to set/get the integer value of a PMC in PIR, how would you do that? (or will there be supporting syntax for that?)

klaas-jan













Reply via email to