On Sun, Nov 13, 2005 at 11:33:07AM +0100, Leopold Toetsch wrote:
> On Nov 13, 2005, at 4:45, Chip Salzenberg wrote:
> >  $P0 = callframe 1
> 
> We already have this kind of introspection: $ grep caller t/pmc/sub.t

OK, the Interpreter PMC interface is certainly flexible enough to
handle the introspections we need.

> OTOH treating a callframe PMC as "normal" PMC would mean that its 
> contents is kept alive as long as the callframe PMC lives. This would 
> make timely destruction near to impossible in the case of an existing 
> callframe PMC.

OK, call frame as PMC looks like a non-starter.  Consider it rescinded.

> [1] I'd use just methods, either on the interpreter or a sub pmc:
> 
>     interp."get_caller"(n_levels)    # interpreter method or
>     sub_class = getclass 'Sub'
>     sub_class."get_caller"(n_levels) # class method 0 = this sub, 1 =  
> caller, ...
>     a_sub."get_caller"(nlevels)      # obj method, if you already have a sub

Well, like I explained WRT lexicals, subroutines don't have callers
(nor do they have LexPads).  _Call_frames_ have callers (and LexPads).
Which leads to:

The current introspection model only walks back the current call chain.
That's good but not enough.  We also need to walk back any live call
chain, using any live continuation as a starting point.

How about if we implement get_caller() on Interpreter and Continuation,
rather than Interpreter and Sub?  Alternatively, I guess we could make
get_caller() take two parameters: a Continuation as a starting point
(Null would mean "me"), and a number of levels up.

PS: I generally dislike the road-painting algorithm[*] implied by the
    "nlevels" interface, but optimizing for introspection is silly, so
    I'm not going to worry about it.

[*] Painting a line in the road but not moving your paint can:
     1. paint a meter, walk one meter to the bucket
     2. walk one meter, paint a meter, walk two meters to the bucket
     3. walk two meters, paint a meter, walk three meters to the bucket
    etc.
-- 
Chip Salzenberg <[EMAIL PROTECTED]>

Reply via email to