|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.
stras a PIR constant string.
fmtis provided, then it will be used as a prefix to the unique number.
rtypeis one of the signature flags described above.
postto have a return value compatible with
rtypecan also be a specific register, in which case the result of
postis forced into that register (with conversions as needed).
node's children in sequence. The
signatureoption 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
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.
The methods below are used to transform PAST nodes into their POST equivalents.
node. Note that
postis 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::Opnode. Normally this is handled by redispatching to a method corresponding to the node's "pasttype" attribute.
PAST::Opnode with a 'pasttype' of 'pirop'.
PAST::Opnode for calling a sub.
PAST::Opnode to invoke a method on a PMC.
PAST::Opnodes with a 'pasttype' of if/unless.
forloop given by
returnsattribute, which defaults to
ResizablePMCArrayif not set.
PAST::Opnode 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 < $zis 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::Opnode with a 'pasttype' of bind.
PAST::Opnode with a 'pasttype' of inline.
PAST::Var. Generally we redispatch to an appropriate handler based on the node's 'scope' attribute.
rtypeparameter 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 <email@example.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.