Hi

I'm trying to realize a Lisp-like macro mechanism in Perl to get a general and reliable extension mechanism.

I successfully hacked B::Deparse such that function calls to macros are replaced with the string returned.

This works fine when translating the body of single functions with B::Deparse::coderef2text the resulting code is evaluated afterwards to replace the body.

Now I'm looking for ideas how to this for complete files.

My current approach is to use a codefilter to wrap the whole file with

macroexpand { ... oldfile ... }

But it gets tricky when handling __DATA__ and __END__ and anyway the idea was to get rid of codefilters

So does anybody know of a way to change the op-tree just after compilation?

I'm pondering to modify B::Deparse::compile for this purpose and to call it within CHECK { ... } or UNITCHECK {...}

An other approach would be to reset the implicit DATA filehandle to reread the code just after compilation phase.

Any brain storming idea is welcome.

Cheers Rolf


In reply to Implicetely deparse, change and replace perlcode in file 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.