Hi

I'm trying to understand lvalue subs on the opcode level and would appreciate some help. For the motivation please read Another approach to extend lvalues ?

here the perlcode I want to analyze

my $scalar; test(); sub normal :lvalue { proxy(); } sub proxy :lvalue { $scalar; } sub nlv { my $x="not lvalue" } sub test { nlv(); normal=42; print $scalar; }
and now how the corresponding opcode looks like, I added the original code as comment. *
perl -MO=Concise,-exec,test,normal,proxy,nlv lvalue.pl main::test: 1 <;> nextstate(main 6 concise.pl:16) v # nlv(); 2 <0> pushmark s 3 <#> gv[*nlv] s 4 <1> entersub[t2] vKS/TARG,1 5 <;> nextstate(main 6 concise.pl:17) v # normal=42; 6 <$> const[IV 42] s 7 <0> pushmark s 8 <#> gv[*normal] s 9 <1> entersub[t4] sKRMS*/NO(),TARG,1 a <2> sassign vKS/2 b <;> nextstate(main 6 concise.pl:18) v # print $scalar; c <0> pushmark s d <0> padsv[$scalar:FAKE] l e <@> print sK f <1> leavesub[1 ref] K/REFC,1 main::normal: g <;> nextstate(main 2 concise.pl:5) v # proxy(); h <0> pushmark s i <#> gv[*proxy] s/EARLYCV j <1> rv2cv sK/NO(),1 k <1> entersub[t2] KS/NO(),TARG,1 l <1> leavesublv[1 ref] K/REFC,1 main::proxy: m <;> nextstate(main 3 concise.pl:8) v # $scalar; n <0> padsv[$scalar:FAKE] o <1> leavesublv[1 ref] K/REFC,1 main::nlv: p <;> nextstate(main 4 concise.pl:12) v # my $x="not lvalue" q <$> const[PV "not lvalue"] s r <0> padsv[$x:4,5] sRM*/LVINTRO s <2> sassign sKS/2 t <1> leavesub[1 ref] K/REFC,1

Well I'm still struggling to understand the opcodes, but please look at the lines 6-a and k.

my interpretation is that by assigning a value to a lvalue-sub the steps are:

  1. cache the value
  2. call the lvalue-sub, which returns a var by refrence
  3. assign the cached value to this var

so even on the level of the opcodes the lvaluesub has no chance to know which value will be assigned to the variable he returns ... Correct?

I'm a little bit confused about line j, what means "rv2cv" (it's the first time this happens right before a sub call)?

I googled through perlguts op.c and concise.pod but can't get a sufficient answer...

Thanx Rolf

* I know with 5.10 I wouldn't need to do it manually but I'm sticking on 5.8.8. I have to figure out how to safely install two different perl-versions on the same system, so that I can maintain both with aptitude.


In reply to Analyzing opcodes of lvalue-subs... by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.