shotgunefx has asked for the wisdom of the Perl Monks concerning the following question:

I've been playing around with xs lately and I've got to admit, I haven't fumbled around this much since I was a teenager

What I was trying to do (and have done) is to hack Padwalker to returns the padlist names and current values as regular array references for the intent of adding lexicals. (Why I want to do this is another story for another post), It works fine so far "almost" (Though you have to set the PADMY_on and PADTMP_off after setting a value) but one thing has been troubling me.

When iterating, the inserted lexical is retaining it's value. I would assume that this is because there is no padsv call, but then I came across this from Extending and Embedding Perl
"op_seq is a sequence number allocated by the optimizer. It allows for, for instance, correct scoping of lexical variables by storing the sequence numbers of the beginning and end of scope operations inside the pad."


I've tried googling but haven't come up with any better explanation of what this means.

Does anyone care to try and expand on this in a way that I might be able to grasp? :)

Thanks,
-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re: What does op_seq do?
by diotalevi (Canon) on Jan 04, 2003 at 15:53 UTC

    I don't know the answer to your question but I almost always start out on this sort of thing by looking in a few places: grep op_seq *.h (cop.h, embedvar.h, intrpvar.h, op.h, perlapi.h). op.h and cop.h show it as part of the base OP struct. A grep op_seq *.c shows it's only relevant in op.c and sv.c. Inspection of sv.c shows it's not really used there so the entire shebang is restricted to op.c.

    op_seq itself is used all over op.c but after a quick scan it looks like it's used for scoping rules. So... relevant to your actual question I'd suggest you take a look at pad_addlex and see how op_seq is being used there. I'd guess that if you're adding lexicals that you just need to add the scope information to NVX/IVX. pad_find(lex/my) shows how your seq information is used.

    So in general - the source is probably your best reference for this. Maybe someone here actually knows what to set your NVX/IVX values to. [Added NVX is your op_seq value and IVX is PL_seqmax. The difficulty is on how you find the right op_seq value and whether you have to increment PL_seqmax, increment other lexical's op_seq/seqmax values, walk the opcode tree to update their op_seq values... etc. That's why I was hazy.]

    Addition: Oh yes - the whole point of this node is to demonstrate how it's easy to find these sorts of answers by reading the source. This is what fifteen minutes with grep and less returned - I'm sure that since you already have an environment which gives you access to these variables that it's even easier to verify their operation.


    Fun Fun Fun in the Fluffy Chair

      Believe me, I have. Understanding it is another. My C/Asm days are long behind me (or were anyway). There's quite a bit to take in and with so many macros and things that functionally aren't documented (or at least I haven't been able to find them), it's rather daunting.

      On the "guts" side, it's more tinkering than programming. Sort of like when as a kid I took apart my Omega Supreme to see how it worked. It still worked but he never walked the same again.

      I hope to eventually get the kind of hold on Perl innards as I do on the outside but I think it's going to take me quite a bit of time.

      -Lee

      "To be civilized is to deny one's nature."
      Thanks! (hadn't even heard of pad_addlex yet)
      That's what I've been doing since I posted but it's definitely hard for myself. So many damn macros!I've been going along pp_padsv, etc and when I'm able to find what it does, just commenting it. I've I had the time it would be nice (for people like myself anyway) to automate this. It would certainly make for an easier introduction.

      -Lee

      "To be civilized is to deny one's nature."