I'm still having troubles, when thinking about namespace PMCs and
implementation thereof.
Especially the relationship of class namespaces and the store_global
opcode.

We have e.g. this PIR snippets:

  .sub main :main
     cl = newclass 'Foo'       # a class isa/hasa namespace ?!
     ...
   .end

   .namespace ['Foo']          # namespace 'Foo'

   .sub __init :method         # a method &Foo::__init
   ...
   .end

Currently '__init' is stored with:

  store_global "Foo', '__init', $PSub

(Actually, if the class already exists, the C<add_method> vtable is
used, but that just does C<store_global> too) But usually, this happens at compile-time,
or PBC-load-time, when the class 'Foo' doesn't yet exist.

Therefore C<Foo> can't be stored into the proposed class->vtable->namespace,
as there is no such class (yet).

To actually implement this (and assuming that my thoughts so far are correct)
I was thinking about this strategy:

The usage of the C<.namespace> directive causes the creation of a new
namespace PMC with that name. Additionally the namespace PMC is registered as a type. This needs a bit of additional code that prevents instantiation
of namespaces.

When now at runtime C<newclass 'Foo'> is executed, we find the existing
namespace PMC (with all the statically visible methods inside) and just
promote the namespace PMC into a class PMC.

Is this sane?
Comments welcome,

leo

Reply via email to