NAME ^

PAST::Compiler - PAST Compiler

DESCRIPTION ^

PAST::Compiler implements a basic compiler for PAST nodes. By default PAST::Compiler transforms a PAST tree into POST.

Compiler methods ^

to_post(node [, 'option'=>option, ...])

Compile the abstract syntax tree given by past into POST.

post_children(node [, 'signature'=>signature] )

Return the POST representation of evaluating all of 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)
The first character of 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.

Methods on PAST::Node arguments ^

The methods below are used to transform PAST nodes into their POST equivalents.

Defaults

post(node)

Return a POST representation of 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.

If 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.

If node revaluates to false, return an empty POST node.

Otherwise, 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

post(PAST::Block node)

Return the POST representation of a PAST::Block.

PAST::Op

post(PAST::Op node)

Return the POST representation of a PAST::Op node. Normally this is handled by redispatching to a method corresponding to the node's "pasttype" attribute.

pirop(PAST::Op node)

Return the POST representation of a PAST::Op node with a 'pasttype' of 'pirop'.

call(PAST::Op node)

callmethod(PAST::Op node)

Return the POST representation of a PAST::Op node with a 'pasttype' attribute of either 'call' or 'callmethod'.

if(PAST::Op node)

unless(PAST::Op node)

Return the POST representation of PAST::Op nodes with a 'pasttype' of if/unless.

while(PAST::Op node)

until(PAST::Op node)

Return the POST representation of a while or until loop.

repeat_while(PAST::Op node)

repeat_until(PAST::Op node)

Return the POST representation of a repeat_while or repeat_until loop.

for(PAST::Op node)

Return the POST representation of the for loop given by node.

try(PAST::Op node)

Return the POST representation of a 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.

chain(PAST::Op node)

A short-circuiting chain of operations. In a sequence of nodes with pasttype 'chain', the right operand of a node serves as the left operand of its parent. Each node is evaluated only once, and the first false result short-circuits the chain. In other words, $x < $y < $z is true only if $x < $y and $y < $z, but $y only gets evaluated once.

def_or(PAST::Op node)

The short-circuiting default operator (e.g., Perl 6's infix:<//>). Returns its first child if its defined, otherwise it evaluates and returns the second child. (N.B.: This particular pasttype is a candidate for being refactored out using thunks of some sort.)

xor(PAST::Op node)

A short-circuiting exclusive-or operation. Each child is evaluated, if exactly one child evaluates to true then its value is returned, otherwise return Undef. Short-circuits with Undef as soon as a second child is found that evaluates as true.

bind(PAST::Op node)

Return the POST representation of a PAST::Op node with a 'pasttype' of bind.

assign(PAST::Op node)

Implement a 'copy' assignment (at least until we get the 'copy' opcode -- see RT#47828).

inline(PAST::Op node)

Return the POST representation of a PAST::Op node with a 'pasttype' of inline.

PAST::Var

scope(PAST::Var node)

Helper function to return the scope of a variable given by 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

post(PAST::Val node [, 'rtype'=>rtype])

Return the POST representation of the constant value given by 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.

AUTHOR ^

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.

HISTORY ^

2006-11-20 Patrick Michaud added first draft of POD documentation. 2006-11-27 Significant refactor into separate modules.

COPYRIGHT ^

Copyright (C) 2006-2008, The Perl Foundation.


parrot