http://qs321.pair.com?node_id=1225868


in reply to Re^8: B::Xref buggy?
in thread B::Xref buggy?

This looks pretty much like the lexical order in the source which is needed to track variables and subs
I think that is the heart of your misapprehension. Concise doesn't output ops in source lexical order, apart from happenstance. As a trivial counterexample, this source:
unless ($var1) { $var2++; } else { $var3++; }
gives:
perl -MO=Concise,-exec /tmp/p | grep var 3 <#> gvsv[*var1] s 7 <#> gvsv[*var3] s d <#> gvsv[*var2] s
Note that var3 comes before var2.

Dave.

Replies are listed 'Best First'.
Re^10: B::Xref buggy?
by LanX (Saint) on Nov 15, 2018 at 19:23 UTC
    Thanks, Dave.

    I was aware that OPs do kind of gotos to next-OPs (the ->label at the end of each line).

    But it didn't seem logical that the -src option could be offered if B::Concise wasn't respecting the order.*

    The solution is that the source lines they are not in order, but the line numbers are still reliable:

    D:\tmp>type tst_b_xref3.pl unless ($var1) { $var2++; } else { $var3++; }
    (Win Activestate 5.24)
    D:\tmp>perl -MO=Concise,-src tst_b_xref3.pl|find "var" tst_b_xref3.pl syntax OK # 1: unless ($var1) { 3 <#> gvsv[*var1] s ->4 # 5: $var3++; 7 <#> gvsv[*var3] s ->8 # 2: $var2++; d <#> gvsv[*var2] s ->e

    So strictly speaking it's still possible to use B::Concise to emulate B::Xref on line number level.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

    *) Interestingly this also depends on the Perl version. Here the vars appear in order: (Ubuntu 5.18)

    $ perl -MO=Concise,-src tst_b_xref3.pl|grep var tst_b_xref3.pl syntax OK # 1: unless ($var1) { 3 <#> gvsv[*var1] s ->4 # 2: $var2++; 8 <#> gvsv[*var2] s ->9 # 5: $var3++; e <#> gvsv[*var3] s ->f

    update

    and that's the reason why, 5.24 is optimizing the negation away by swapping the branches:

    D:\tmp>perl -MO=Deparse tst_b_xref3.pl tst_b_xref3.pl syntax OK if ($var1) { ++$var3; } else { ++$var2; }
      The solution is that the source lines they are not in order, but the line numbers are still reliable:
      (Cough)
      $ cat /tmp/p for ( $var1++; $var2++; $var3++ ) { $var4++; } $ perl -MO=Concise,-src /tmp/p | grep var /tmp/p syntax OK 3 <#> gvsv[*var1] s ->4 f <#> gvsv[*var2] s ->g # 6: $var4++; 9 <#> gvsv[*var4] s ->a c <#> gvsv[*var3] s ->d

      Dave.

        well the information is still available, var3 belongs to the tree below the first nextstate

        $ perl -MO=Concise,-src tst_b_xref4.pl|perl -pe 'substr $_, -1, 0, " " +x(68-length$_) . " #:$1" if /(^#|nextstate|var\d+)/;' tst_b_xref4.pl syntax OK j <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 # 1: for ( # +:# 2 <;> nextstate(main 3 tst_b_xref4.pl:1) v:{ ->3 # +:nextstate 4 <1> preinc[t2] vK/1 ->5 - <1> ex-rv2sv sKRM/1 ->4 3 <#> gvsv[*var1] s ->4 # +:var1 5 <0> unstack v* ->6 i <2> leaveloop vK/2 ->j 6 <{> enterloop(next->c last->i redo->7) v ->f - <1> null vK/1 ->i h <|> and(other->7) vK/1 ->i g <1> postinc[t4] sK/1 ->h - <1> ex-rv2sv sKRM/1 ->g f <#> gvsv[*var2] s ->g # +:var2 - <@> lineseq vK ->- b <@> leave vKP ->c 7 <0> enter v ->8 # 6: $var4++; # +:# 8 <;> nextstate(main 1 tst_b_xref4.pl:6) v:{ ->9 # +:nextstate a <1> preinc[t8] vK/1 ->b - <1> ex-rv2sv sKRM/1 ->a 9 <#> gvsv[*var4] s ->a # +:var4 d <1> preinc[t6] vK/1 ->e - <1> ex-rv2sv sKRM/1 ->d c <#> gvsv[*var3] s ->d # +:var3 e <0> unstack v ->f

        thanks Dave, I learned a lot! :)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice