parrotcode: PAST Compiler | |
Contents | Compilers |
PAST::Compiler - PAST Compiler
PAST::Compiler implements a basic compiler for PAST nodes. By default PAST::Compiler transforms a PAST tree into POST.
past
into POST.node
's children in sequence.
The signature
option is a string of characters that allow the caller to suggest the type of result that should be returned by each child: * Anything
P PMC register
+ PMC, numeric register, or numeric constant
~ PMC, string register, or string constant
: Argument (same as '*'), possibly with :named or :flat
v void result (result value not used)
signature
is ignored (return type), thus v~P*
says that the first child needs to be something in string context, the second child should be a PMC, and the third and subsequent children can be any value they wish.PAST::Node
arguments The methods below are used to transform PAST nodes into their POST equivalents.
node
. Note that post
is a multimethod based on the type of its first argument, this is the method that is called when no other methods match.node
is an instance of PAST::Node
(meaning that none of the other post
multimethods were invoked), then return the POST representation of node
's children, with the result of the node being the result of the last child.node
revaluates to false, return an empty POST node.node
is treated as a string, and a POST node is returned to create a new object of the type given by node
. This is useful for vivifying values with a simple type name instead of an entire PAST structure.PAST::Block
PAST::Block
.PAST::Op
PAST::Op
node. Normally this is handled by redispatching to a method corresponding to the node's "pasttype" attribute.PAST::Op
node with a 'pasttype' of 'pirop'.PAST::Op
node with a 'pasttype' attribute of either 'call' or 'callmethod'.PAST::Op
nodes with a 'pasttype' of if/unless.while
or until
loop.repeat_while
or repeat_until
loop.for
loop given by node
.PAST::Op
node with a 'pasttype' of bind. The first child is the code to be surrounded by an exception handler, the second child (if any) is the code to process the handler.$x < $y < $z
is true only if $x < $y and $y < $z, but $y only gets evaluated once.PAST::Op
node with a 'pasttype' of bind.PAST::Op
node with a 'pasttype' of inline.PAST::Var
node
. The scope is determined by the node's scope
attribute if set, otherwise search outward through the symbol tables of any lexical blocks to determine the scope.PAST::Val
node
. The rtype
parameter advises the method whether the value may be returned directly as a PIR constant or needs to have a PMC generated containing the constant value.Patrick Michaud <pmichaud@pobox.com> is the author and maintainer. Please send patches and suggestions to the Parrot porters or Perl 6 compilers mailing lists.
2006-11-20 Patrick Michaud added first draft of POD documentation. 2006-11-27 Significant refactor into separate modules.
Copyright (C) 2006-2007, The Perl Foundation.
|