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" : )
In reply to Macro system on B-Level? by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |