There isn't yet any API for introspecting ASTs ("parsing of passed-in code" as you call it), nor for programmatically constructing new AST nodes. Such things will hopefully emerge once macro implementation and specification become more concrete.
So I can only guess what it would look like; take the following with a rock of salt:
macro do-in-reverse($code) {
$code.clone(statements => $code.statements.reverse);
}
do-in-reverse {
say 'First';
say 'Second';
say 'Third';
};
But it might turn out not be that simple.The diffulcty comes from the fact that unlike Lisp, in Perl 6 not everything is a list, so you can't treat the AST as a list (... of lists, possibly) either. The .clone would take care to preserve things like outer lexicals and the signature of the block (you don't see it; it's implicit) and other non-listy things.