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

Throughout the compiler PAST uses a number of 1-character "flags" to indicate allowable register types and conversions. This helps the compiler generate more efficient code and know what sorts of conversions are allowed (or desired). The basic flags are:
    P,S,I,N   PMC, string, int, or num register
    s         string register or constant
    i         int register or constant
    n         num register or constant
    r         any register result
    v         void (no result)
    *         any result type except void
    +         PMC, int register, num register, or numeric constant
    ~         PMC, string register, or string constant
    :         argument (same as '*'), possibly with :named or :flat
These flags are used to describe signatures and desired return types for various operations. For example, if an opcode is specified with a signature of I~P*, then the opcode places its result in an int register, its first child is coerced into some sort of string value, its second child is coerced into a PMC register, and the third and subsequent children can return any value type.

past into POST.str as a PIR constant string.fmt is provided, then it will be used as a prefix to the unique number.rtype, where rtype is one of the signature flags described above.post to have a return value compatible with rtype. rtype can also be a specific register, in which case the result of post is forced into that register (with conversions as needed).node's children in sequence. The signature option is a string of flags as described in "Signature Flags" above. Since we're just evaluating children nodes, the first character of signature (return value type) is ignored. Thus a signature of 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.class. This is typically invoked by the various vivification methods below (e.g., in a PAST::Var node to default a variable to a given type).node's children in sequence. The result of the final child is used as the result of this node.PAST::Stmts.PAST::BlockPAST::Block.PAST::OpPAST::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 for calling a sub.PAST::Op node to invoke a method on a PMC.PAST::Op nodes with a 'pasttype' of if/unless.while or until loop.repeat_while or repeat_until loop.for loop given by node.returns attribute, which defaults to ResizablePMCArray if not set.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.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.)PAST::Op node with a 'pasttype' of bind.PAST::Op node with a 'pasttype' of inline.PAST::VarPAST::Var. Generally we redispatch to an appropriate handler based on the node's 'scope' attribute.PAST::Valnode. 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-2008, The Perl Foundation.
|  |   |