|parrotcode: Parrot abstract syntax tree|
|Contents | Compilers|
PAST - Parrot abstract syntax tree
This file implements the various abstract syntax tree nodes for compiling programs in Parrot.
PAST::Node is the base class for all PAST (and POST) nodes.
It's derived from class
so that it has both array and hash components.
The array component is used to maintain a node's children,
while the hash component contains the attributes of the node.
In general we provide and use accessor methods for a node's attributes,
instead of accessing the hash component directly.
Every PAST node predefines
name attribute is the node's name,
pos are used to identify the location in the original source code for the node.
pos values are generally set by the
node method below.
Other node attributes are generally defined by subclasses of
pushmethod, below) and calls the appropriate accessor method for each attribute. And returns the node.
classinitialized with the given children and attributes. Returns the newly created node.
childto the end of the invocant's list of children.
class, initializes it with the given children and attributes, and adds it to the end of the invocant's array of children. Returns the newly created PAST node.
posattributes to those of
valis another PAST node, then
posare simply copied from that node, otherwise
valis assumed to be a
Matchobject and obtains source/position information from that.
has_valueis true then set the invocant's value of
value. Returns the (resulting) value of
attrnamein the invocant.
fmtis provided, then it will be used as a prefix to the unique number.
namein a format that can be compiled by PIR.
nameattribute of the invocant.
PAST::Val nodes represent constant values in the abstract syntax tree.
name attribute represents the value of the node.
.String, or an integer might use a language-specific
PAST::Valnode may be rendered directly into PIR code as a Parrot constant instead of first generating a PMC.
valueis a sequence of character representing the various argument types for which the node's name is a usable constant:
i I registers or int n N register or num + Any numeric argument (int/num) s S register or string ~ Any string argument
ctypeisn't set, then the PAST::Val node always results in a newly generated PMC initialized with the node's name.
PAST::Var nodes represent variables within the abstract syntax tree. The variable name (if any) is given as the node's
ismyattribute (for lexical variables) to
flag. A true value of
ismyindicates that the variable given by this node is to be created within the current lexical scope. Otherwise, the node refers to a lexical variable from an outer scope.
isslurpyattribute (for parameter variables) to
flag. A true value of
isslurpyindicates that the parameter variable given by this node is to be created as a slurpy parameter (consuming all remaining arguments passed in).
typeindicates either the type of the value to create for the node or (future implementation) a PAST tree to create the value.
islvalueattribute, which indicates whether this variable is being used in an lvalue context.
PAST::Op nodes represent the operations in an abstract syntax tree. The primary function of the node is given by its
pasttype, secondary functions may be given by the node's
pirop, or other attributes.
pasttypedetermines the type of operation to be performed. Predefined values of
nameattribute, if the node has no
nameattribute then the first child is assumed to evaluate to a callable sub.
inlineattribute (a string). See the
inlinemethod below for details.
nameattribute, then the first child is the invocant and any remaining children are arguments. If the node doesn't have a
nameattribute, then the first child evaluates to the method to be called, the second child is the invocant, and the remaining children are arguments to the method call.
pasttype, then it assumes "pirop" if its
piropattribute is set, otherwise it assumes "call".
returnsattribute identifies the type of the result (default is
.Undefif not set).
pasttypeis "inline". The
codeargument is PIR text to be inserted in the final generated code sequence. Sequences of "%0", "%1", "%2", ... "%9" in
codeare replaced with the evaluated results of the first, second, third, ..., tenth children nodes. (If you need more than ten arguments to your inline PIR, consider making it a subroutine call instead.)
%r - Generate a unique PMC register for the result. %t - Generate a unique PMC register for the result, and initialize it with an object of type C<returns> before the execution of the inline PIR. %u - Re-use the first child's PMC (%0) if it's a temporary result, otherwise same as %t above. %v - (void) Re-use the first child's PMC (%0) as the result of this operation.
PAST::Stmts is a container of
PAST::Node without any specific methods.
PAST::Block nodes represent lexical scopes within an abstract syntax tree, and roughly translate to individual Parrot subroutines. A
PAST::Block node nested within another
PAST::Block node acts like a nested lexical scope.
If the block has a
name attribute, that becomes the name of the resulting Parrot sub, otherwise a unique name is automatically generated for the block.
while, and other similar statements).
symtablefor any code generation.
nameinstead of the standard PAST compiler.
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.
Copyright (C) 2006, The Perl Foundation.