The Last Week and a Half in PAST Optimization

I noticed yesterday that I forgot to post a blog post last week. I'll try to make up for that with double the blog post goodness this week(expect a second post Thursday or Friday).

Essentially, what I did for the remainder of the week before last after my most recent blog post was make PAST::Walker and PAST::Transformer more convenient to use, especially in NQP. Step 1 of that was something that I'd been planning from my first blog post: ::Dynamic subclasses of PAST::Walker and PAST::Transformer that have attributes for the subs to invoke on each PAST::Node types.

The second thing I did was something that I only discovered would be useful when I started writing tests and examples using PAST::Walker::Dynamic and PAST::Transformer::Dynamic in NQP. For a normal Parrot class PAST::Walker created with the newclass opcode, you can't do in NQP. You have to do pir::new__PP(PAST::Walker). However, if you instead use P6metaclass's new_class method to create your class, as PCT does for its PCT::Node and subclasses(including PAST::Node), you can create instances of your class in NQP with the simple

Last week, I spent a few days thinking and talking about possible syntaxes for PAST transformations, but eventually decided to just implement something like the PAST::Pattern API I discussed earlier for now; any convenient syntax for it could be implemented later on top of the programmatic interface.

PAST::Pattern is mostly implemented. There are a few things left to be done, including global matching(currently, you get just the first match via depth-first traversal of the tree), and placing the sub-patterns in the array and hash parts of the match result(so that you can use $0, $1, $2, and so on. In addition to those two things, a tool to apply a transformation to all the parts of a PAST that match a PAST::Pattern needs to be written. Once this is done, we can start writing actual optimizations with it! There are a few convenience patterns that will also need to be implemented, but they aren't immediately necessary, so I plan to hold off on them until after I have it working for optimization purposes at all.

That's all I have to say for now: time for me to get back to coding.


Looks interesting! Good luck, and I look forward to future updates.