Grant Report: Implementation of Macros in Rakudo
Sun, 02-Dec-2012 by
Karen Pauley
edit post
*Carl Mäsak writes:*
This is a report on the progress that I have made with my current Hague Grant, [Implementation of macros in Rakudo](http://news.perlfoundation.org/2011/09/hague-grant-application-implem.html). We're now at the halfway point of the grant, and Rakudo has an early, working implementation of macros.
Here is the status of the deliverables identified in the [original report](http://news.perlfoundation.org/2011/09/hague-grant-application-implem.html):
**D1. (Macro declarations and invocation. Rudimentary quasiquotes.)** Completed. In Rakudo, you can now declare macros just like you declare ordinary subroutines. There's also a `quasi` block construct, often used inside the macro body to "quote" a piece of code as an abstract syntax tree (AST) and return it in this form to the caller. Finally, macro expansion works, which means that AST so returned gets spliced into the mainline code and gets run at runtime. My progress is summarized in these blog posts: [one](http://strangelyconsistent.org/blog/macros-progress-report-a-bit-of-d1), [two](http://strangelyconsistent.org/blog/macros-progress-report-interesting-things), [three](http://strangelyconsistent.org/blog/macros-progress-report-d1-merged).
**D2. (Quasiquote splicing.)** Completed. Subexpressions in a `quasi` block surrounded with `{{{ }}}` delimiters are evaluated at `quasi` evaluation time, and their value is expected to be an AST, which is spliced into the `quasi` AST. Special care has to be taken to preserve the original lexical context of the things spliced in. The support for this had to be coded both in nqp and Rakudo. My progress is summarized in these blog posts: [one](http://strangelyconsistent.org/blog/macros-progress-report-quantum-yak-shaving), [two](http://strangelyconsistent.org/blog/macros-progress-report-d2-merged).
**D3. (Hygienic macros and the `COMPILING::` pseudopackage.)** Underway. In the current implementation, macros are already hygienic. Making them (optionally) unhygienic is supposed to happen through the `COMPILING::` pseudopackage, which provides a sort of escape hatch back to the mainline code and its lexical context. This is what I expect to do next.
**D4. ("Delayed" declarations of routines and types within quasiquotes.)** Not started yet.
**D5. (Updates to the S06 to align the spec with the implementation.)** The synopsis has stood up unexpectedly well in the face of implementation, and has been a big help in clarifying semantics in some cases. I have discussed extensively with Larry Wall and Jonathan Worthington about whether the `{{{ }}}` syntax needs to be replaced with something more generic. This ongoing discussion is expected to eventually land in S06 and STD.pm6 as changes.
**D6. (Spectests to cover the implemented features.)** Two new spectest files cover the new macro features implemented in Rakudo, including some tests for bugs that were discovered along the way. All tests pass. The test files exercise [quasi blocks](https://github.com/perl6/roast/blob/master/S06-macros/quasi-blocks.t) and [unquoting](https://github.com/perl6/roast/blob/master/S06-macros/unquoting.t), respectively. We've also started passing a couple of tests from a pre-existing test file exercising [opaque ASTs](https://github.com/perl6/roast/blob/master/S06-macros/opaque-ast.t).
**D7. (Regular reports on implementation progress.)** Though I hesitate to call the reports "regular", I have blogged about my progress whenever the implementation has taken yet another step forward. Furthermore, it turns out that writing pieces smaller than blog posts and publishing them as gists helps a lot in advancing discussion and understanding of macros. I've made sure to link to any such gists from the subsequent blog post.
I'd like to thank Ian Hague and the Perl Foundation for funding this grant. I'd also like to take a moment to thank the community for their patience and support with regard to my work on this grant so far — it's wonderful to be a part of it, and to work with so many great people.
Category:
(none)
Comments (0)