LanX has asked for the wisdom of the Perl Monks concerning the following question:
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
and now how the corresponding opcode looks like, I added the original code as comment. *my $scalar; test(); sub normal :lvalue { proxy(); } sub proxy :lvalue { $scalar; } sub nlv { my $x="not lvalue" } sub test { nlv(); normal=42; print $scalar; }
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:
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Analyzing opcodes of lvalue-subs...
by ikegami (Patriarch) on Nov 21, 2008 at 02:16 UTC | |
Re: Analyzing opcodes of lvalue-subs...
by ikegami (Patriarch) on Nov 21, 2008 at 02:43 UTC | |
by LanX (Saint) on Nov 21, 2008 at 11:52 UTC | |
Re: Analyzing opcodes of lvalue-subs...
by dave_the_m (Monsignor) on Nov 21, 2008 at 10:51 UTC |