I'm meditating about a macrosystem which is working after compilation and before execution
The idea is to flag subs as :macro and and to replace every call with the string the sub returns.
so thatuse B::MyMacro; sub foo :macro { return "bar()" }
will be replaced withprint; foo(); print;
print; do { bar() }; print;
Of course eval "string" needs also to be overridden, such that the macroreplacement will also be executed after eval's compilation.
This mechanism can already be realised using B::Deparse, RegEx and evals, but with rather fragile dependencies. I'm looking for a stable and simple opcode-based solution, replacing every macro-call with new opcodes.
IMHO, this approach would be much more stable and useful than codefilters, because "only perl can parse perl" ¹.
I'm wondering if nobody ever tried to implement this, googling and supersearching didn't bring any examples. Do you know any other similar approach?
Cheers Rolf
UPDATES:
(¹) ... but "Even B:: can parse optree" : )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Macro system on B-Level?
by moritz (Cardinal) on Nov 26, 2008 at 12:04 UTC | |
|
Re: Macro system on B-Level?
by salva (Canon) on Nov 26, 2008 at 11:37 UTC | |
by LanX (Saint) on Nov 26, 2008 at 12:05 UTC | |
|
Re: Macro system on B-Level?
by jdporter (Paladin) on Nov 26, 2008 at 15:48 UTC | |
by LanX (Saint) on Nov 26, 2008 at 15:57 UTC | |
by LanX (Saint) on Nov 26, 2008 at 16:33 UTC |