Leopold Toetsch <[EMAIL PROTECTED]> wrote:
> Dan Sugalski <[EMAIL PROTECTED]> wrote:

>> Basically we want to be able to walk a continuation chain and get
>> access to everything.

> I think having methods is ok for that. It's in no way time critical to
> warrant opcodes.

I've now created two methods "caller" and "continuation" in the
Continuation PMC that allows walking the continuation chain. It's
slightly different then the previous example as Sub PMCs don't have a
context. To get at the previous caller, we have to get the continuation
of the continuation.

$ ./parrot call.imc
main foo
Bar bar
caller: foo
Bar foo
called from Sub 'bar' pc 146
called from Sub 'foo' pc 75
called from Sub 'main' pc 21
Bar foo
called from Sub 'main' pc 44
ok

$ cat call.imc
.sub main @MAIN
.include "interpinfo.pasm"
    foo()
    $P0 = find_global "Bar", "foo"
    $P0()
    print "ok\n"
.end
.sub foo
    print "main foo\n"
    $P0 = find_global "Bar", "bar"
    $P0()
.end
.namespace ["Bar"]
.sub bar
    print "Bar bar\n"
    $P1 = interpinfo .INTERPINFO_CURRENT_CONT
    $P0 = $P1."caller"()
    print "caller: "
    print $P0
    print "\n"
    foo()
.end
.sub foo
    print "Bar foo\n"
    $P1 = interpinfo .INTERPINFO_CURRENT_CONT
tb_loop:
    unless $P1 goto tb_end
    print $P1
    $P1 = $P1."continuation"()
    goto tb_loop
tb_end:
.end

leo

Reply via email to