On Wed, Nov 23, 2005 at 10:49:18PM +0100, Leopold Toetsch wrote:
> outer_sub - (the static sub PMC info) can't refer to :outer because the 
> :outer can be a closure too.  There are many incarnations of the :outer 
> then. Therefore the implementation needs sub->ctx (currently and IMHO).

The docs conflate non-closure Subs and closure Subs in confusing way.
Sorry.  So I'm going to write my way through this.  I think the design
as is can work, with each Sub having a static outer_sub attribute, but
only if closures also have an attribute that points to the Sub that
they were created from.

(Perl 5 calls this closure-creation process "cloning".  I might adopt
it, even though the reasons for the name are obsolete.  I kept the
term "pad" even though it's also technically obsolete...)

OK, here goes.  Correct me where I go wrong:

 * The initial static result of compilation is N Parrot_subroutines
   (Subs).

 * Each of these Subs may have a non-NULL outer_sub attribute, which
   describes the textual relationship of the Subs in the original
   source code.  For example, given:

      sub foo {
         my sub bar {
            my sub baz {
            }
         }
      }

   baz.outer_sub is bar, and bar.outer_sub is foo.

 * This is a static description of a static situation (the source code
   doesn't evolve at runtime).  So it need never change.

 * The result of newclosure is a new Sub, but I'm going to call it a
   Closure for clarity in this message.

Now speculation:

 * We are free to give the Closure a new outer_sub attribute at the
   time it's created, if we choose, and that won't violate the rule
   that the original (source) Sub's attributes should be const, as
   long as the old outer_sub value can be captured.

 * For a nested closure like &baz above, how about if at newclosure
   time, we set the outer_sub to the specific Closure of bar that is
   currently executing?

In order to do this:

 * Closures would need an attribute that points to the Sub they were
   created from.  That would allow us to connect the running &bar
   _Closure_ to the &bar _Sub_ it was created from.  (The reason we
   would need that connection is that the Sub &baz's outer_sub
   attribute points only to the static Sub &bar.)

OK so far?

If so I'll follow up with design docs.
-- 
Chip Salzenberg <[EMAIL PROTECTED]>

Reply via email to