in reply to Find opcode's reverse sibling?

I think what diotalevi is trying to acheive is the reverse of B's next method, a new previous method. Yes? If so, then I think that your snippet would be fine (although I don't muck around with the B modules much).

Replies are listed 'Best First'.
Re^2: Find opcode's reverse sibling?
by dave_the_m (Monsignor) on Jun 12, 2004 at 22:16 UTC
    I think what diotalevi is trying to acheive is the reverse of B's next method
    Er, no. Siblings and next are two different things. Siblings are a chain of ops at the same level in a tree; next is the next op in execution sequence. For example
    $ perl584 -MO=Concise -e'print "a", $b+1;' 9 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 8 <@> print vK ->9 3 <0> pushmark s ->4 4 <$> const(PV "a") s ->5 7 <2> add[t1] sK/2 ->8 - <1> ex-rv2sv sK/1 ->6 5 <$> gvsv(*b) s ->6 6 <$> const(IV 1) s ->7 $ perl584 -MO=Concise,-exec -e'print "a", $b+1;' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v 3 <0> pushmark s 4 <$> const(PV "a") s 5 <$> gvsv(*b) s 6 <$> const(IV 1) s 7 <2> add[t1] sK/2 8 <@> print vK 9 <@> leave[1 ref] vKP/REFC
    Here, the first child of print is pushmark, and const and add are the two siblings of pushmark. On the other hand, print's next op is leave.

    Internally Perl doesn't store pointers to previous siblings, not does it store a pointer to the parent. So my initial reaction is that the OP's approach is correct. However, since the B modules provide a parent() method when internally there is no such pointer, it's posssible that B:;* can do other clever stuff too. I've never looked at it myself.

    Dave.

      That just goes to show how little I really know about B. I thought if you had stored a child op that you could use next on it to get the next sibling. Hence my comment about reversing it to create a previous method. Looks like I'll need to reread that stuff again. :)