"Chip Salzenberg" <[EMAIL PROTECTED]> wrote:
I've got a partial solution to the pending question of namespace vs. class.
Specifically, I've realized that Parrot already had most of a simple
solution to populating a class's methods even if the class has no public
namespace, what with the ".const .Sub" technique.

When I went to implement the rest, I found it was already mostly there:
default.pmc already implements the "add_method" vtable entry, but there's no "addmethod" opcode... or at least, there _was_ no "addmethod" opcode until
a minute ago.  :-)  This example now works:

       .sub main :main
           .local pmc c
           c = newclass ['whatever']

           .const .Sub foo = "whatever_foo"
           addmethod c, "foo", foo

           $P0 = new ['whatever']
           $P0.foo()
       .end

       .sub whatever_foo :anon :method
           print "Foo!\n"
       .end

Note that the default implementation of vtable add_method() still depends on
public namespaces.  But we can fix that.  }:-)

This looks pretty nice.  A couple of initial things that spring to mind.

1) (Can we|Will we be able to) do the whole newclass/addattribute/addmethod thing at compile time (in a :immediate), so that you have your classes defined and just freeze the class PMC, then thaw 'em and be done when you run? Just thinking of the common case where we know a load of class details at compile time (like in .Net ;-)).

2) What about class (aka static) methods?

Thanks,

Jonathan

Reply via email to