in reply to Composing or chaining subroutines

You're effectively talking about in-lining the subroutines.

I did once think that it might be possible to create a true macro facility in Perl 5 by using B::Generate. The basic idea was that you could introspect the code generated by the macro using B::Bblock and similar modules, alias the formal/actual parameters, and then patch the code into the expansion scope using B::Generate.

Unfortunately, I never managed to get B::Generate to compile here, so the idea died with those attempts.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Composing or chaining subroutines
by chromatic (Archbishop) on Jan 14, 2006 at 19:13 UTC

    The biggest hurdle there is that you have to clone branches of opcodes, lest you rethread the next and child pointers in one instance and break them for all instances. That's quite difficult, as if dodging segfaults and infinite loops weren't enough.

Re^2: Composing or chaining subroutines
by diotalevi (Canon) on Jan 16, 2006 at 18:05 UTC

    You never submitted a bug report about it not compiling.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      True. That was remiss of me.

      I think that given the lack of informed response I got from my question here, combined with the either totally absence of any response; condecending "you don't know what your doing, so I'm just gonna quietly close this bug report as 'user error'"; or outright hostile rants; I've received in the past, I guess I couldn't face the hassle.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        In theory, I'm the maintainer of B::Generate and I was unaware of your issues. I couldn't have solved them because I don't have a Windows computer and don't have PodMaster's experience with MSVC. At least the note would have been there in rt.cpan.org and I would have known that something was up. I didn't know there was a problem at all til I happened to notice your note here. You should always file a bug report if only so other people can see it.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re^2: Composing or chaining subroutines
by Anonymous Monk on Jan 14, 2006 at 19:36 UTC

      I think that you may have misunderstood. I was not talking about source filter macros, but 'proper' macros.

      The macro body would be an ordinary subroutine compiled by Perl in exactly the same way as any other subroutine. Then at INIT{} or CHECK() time, the calls to that subroutine would be inlined at the call site. That is, the opcode tree built for the macro body, would be cloned and inserted into the opcode tree in place of the call opcode, with references to it's formal arguments replaced by references to the actual arguments.

      There would probably have to be some fairly strict restrictions on what the macro body could do, like

      • no references to variables outside the scope of it's body.
      • no recursion--either self or mutual.
      • probably a lot of other things I haven't thought of.

      I've also played with source filter macros, and got somethings to work--but they quickly get messy and never play nice with other source filters.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.