Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Handy Algorithm For Using B::Generate

by chromatic (Archbishop)
on Jan 25, 2004 at 23:40 UTC ( #324028=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: The B:: Modules
in thread The B:: Modules

  1. Write the Perl code you want to produce.
  2. Dump it to opcodes with B::Concise.
  3. Write the Perl code you want to transform.
  4. Dump it to opcodes.
  5. Figure out the difference between #2 and #4.
  6. Write the B::Generate code to produce those opcodes.
  7. Fiddle with stuff until it stops segfaulting.
  8. Fiddle with stuff until it stops running into an infinite loop.

For extra credit, fiddle with stuff until it produces the right answer. If you reach this step, please tell the rest of us how you did it!


Comment on Handy Algorithm For Using B::Generate
Select or Download Code
Re: Handy Algorithm For Using B::Generate
by stvn (Monsignor) on Jan 25, 2004 at 23:54 UTC
    chromatic,

    Thanks, I started to doing this earlier today, and then just got stuck on trying to get plain old B to print out the innards of my subroutines (building off Simon's tutorial's examples). I think I read about half the code in B::Deparse before I managed to hit something similar to the infinite loop you speak of in Step 8.

    I also kept encountering a package B::SPECIAL, for which I saw no listing in B documentation for, but did find in the source that is was just a plain old B::OBJECT. Anyone know what this refers too?

    -stvn
      B::SPECIAL objects are instances of pointers to the perl global invariants, PL_sv_undef, PL_sv_yes, and PL_sv_no. You were seeing one of those.

        You guys wouldn't happen to know how to fetch the scalar value associated with a B::GV object too would you?

        Looking at the results from Devel::Peek::Dump($a), it would seem to me that the GV -> GP -> SV would be the pathway to the SV (and its eventual value), but there is no GP method for the B::GV object. I am sure I am just missing something very obvious here, but I can't seem to resolve this. All I can seem to get when I call B::GV->SV is a B::NULL object, which makes no sense. Am I just running into the optimizer here?

        Okay, going to bed now with visions of op-code trees dancing in my head. Should make for some interesting dreams.

        -stvn
Re: Handy Algorithm For Using B::Generate
by diotalevi (Canon) on Jul 01, 2004 at 05:07 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://324028]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2014-10-01 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (38 votes), past polls