Re: Lexical scope pad stack

1 view
Skip to first unread message

Cory Spencer

unread,
Apr 1, 2005, 6:05:37 PM4/1/05
to perl6-i...@perl.org

> Is there currently any method of determining the depth of the lexical scope
> pad stack? None of the ops in var.pod seem to be able to provide that
> information at the moment...

Actually, I suppose I should clarify what I want to get at here, which is
when lexical pads popped off the stack. Am I responsible for cleaning up
any lexical pads I push on the stack? (I assume I am, but just wanted to
be sure) ie) If I'm in a subroutine that just pushed a lexical pad on the
stack and an exception gets thrown, do I have to catch the exception, pop
the pad off the stack, and then rethrow the exception?

Cory

Cory Spencer

unread,
Apr 1, 2005, 6:00:25 PM4/1/05
to perl6-i...@perl.org

Just a quick question:

Is there currently any method of determining the depth of the lexical
scope pad stack? None of the ops in var.pod seem to be able to provide
that information at the moment...

Cory

Leopold Toetsch

unread,
Apr 2, 2005, 4:56:59 AM4/2/05
to Cory Spencer, perl6-i...@perl.org
Cory Spencer <cspe...@sprocket.org> wrote:

>> Is there currently any method of determining the depth of the lexical scope
>> pad stack? None of the ops in var.pod seem to be able to provide that
>> information at the moment...

You can query the pad depth like in [1], but ...

> Actually, I suppose I should clarify what I want to get at here, which is
> when lexical pads popped off the stack. Am I responsible for cleaning up
> any lexical pads I push on the stack? (I assume I am, but just wanted to
> be sure) ie) If I'm in a subroutine that just pushed a lexical pad on the
> stack and an exception gets thrown, do I have to catch the exception, pop
> the pad off the stack, and then rethrow the exception?

... you don't need to. The lexical pads hangs off the context structure.
Whenever the context changes, either by returning from a Sub call or
when an exception was thrown, the context is restored to the previous
state, and the lexicals with their pads are gone.

> Cory

leo

[1]

$ cat lex.imc
.sub main @MAIN
new_pad 0
new_pad -1
$P0 = peek_pad
$I0 = elements $P0
print $I0
new_pad -1
$P0 = peek_pad
$I0 = elements $P0
print $I0
print "\n"
.end
$ ./parrot lex.imc
23

Reply all
Reply to author
Forward
0 new messages