On Thu, Jan 24, 2002 at 01:31:50PM -0000, Ivor Williams wrote:
> Is there a way of getting a coderef for where you are inside caller?

The coderef for "where you are" is an interesting concept, which sadly
doesn't map very well to perl's internals. Only subroutines have
coderefs; there isn't a coderef for some arbitrary sequence point part
way through a subroutine. So I'd say "no", though I don't doubt that
it could be done with some serious internal trickery.

> Is there also a way of tricking the call stack into making it look
> as if you have come from there?

That could be done using some /fairly/ simple XS trickery. The return
stack (PL_retstack) is just an array of OP*.

> Also, is there a way of generating extra stack frames including their
> lexical variable space (i.e. reverse PadWalker)?

That would be moderately tricky I think, because there are several
different stacks to deal with: the return stack, the context stack
and the save stack at least. I'm sure it could be done, by somebody
with sufficient patience.

> If the answer to all 3 is Yes, then I can see a way of doing continuations
> in perl.

I've previously wondered about a completely different way of doing
continuations: using a pre-processing phase (source filter). If you
could translate

  sub foo {
    # some stuff here
    my $cc = current_continuation;
    # more stuff
  }

into

  sub foo {
    # some stuff here
    my $cc = sub {
      # more stuff
    }
    goto &$cc;
  }

would that be sufficient? It seems like an easier approach, if it
would work.

 .robin.

Reply via email to