NAME
Parrot::Op - Parrot Operation
SYNOPSIS
use Parrot::Op;
DESCRIPTION
Parrot::Op
represents a Parrot operation (op, for short), as read from an ops file via Parrot::OpsFile
, or perhaps even generated by some other means. It is the Perl equivalent of the op_info_t
C struct
defined in include/parrot/op.h.
Op Type
Ops are either auto or manual. Manual ops are responsible for having explicit next-op RETURN()
statements, while auto ops can count on an automatically generated next-op to be appended to the op body.
Note that tools/build/ops2c.pl supplies either 'inline' or 'function' as the op's type, depending on whether the inline
keyword is present in the op definition. This has the effect of causing all ops to be considered manual.
Op Arguments
Note that argument 0 is considered to be the op itself, with arguments 1..9 being the arguments passed to the op.
Op argument direction and type are represented by short one or two letter descriptors.
Op Direction:
i The argument is incoming
o The argument is outgoing
io The argument is both incoming and outgoing
Op Type:
i The argument is an integer register index.
n The argument is a number register index.
p The argument is a PMC register index.
s The argument is a string register index.
ic The argument is an integer constant (in-line).
nc The argument is a number constant index.
pc The argument is a PMC constant index.
sc The argument is a string constant index.
kc The argument is a key constant index.
ki The argument is a key integer register index.
kic The argument is a key integer constant (in-line).
Class Methods
new($code, $type, $name, $args, $argdirs, $labels, $flags)
-
Allocates a new bodyless op. A body must be provided eventually for the op to be usable.
$code
is the integer identifier for the op.$type
is the type of op (see the note on op types above).$name
is the name of the op.$args
is a reference to an array of argument type descriptors.$argdirs
is a reference to an array of argument direction descriptors. Element x is the direction of argument$args->[x]
.$labels
is a reference to an array of boolean values indicating whether each argument direction was prefixed by 'label
'.$flags
is one or more (comma-separated) hints.
Instance Methods
code()
-
Returns the op code.
type()
-
The type of the op, either 'inline' or 'function'.
name()
-
The (short or root) name of the op.
full_name()
-
For argumentless ops, it's the same as
name()
. For ops with arguments, an underscore followed by underscore-separated argument types are appended to the name. func_name()
-
The same as
full_name()
, but with 'Parrot_
' prefixed. arg_types()
-
Returns the types of the op's arguments.
arg_type($index)
-
Returns the type of the op's argument at
$index
. arg_dirs()
-
Returns the directions of the op's arguments.
labels()
-
Returns the labels.
flags(@flags)
flags()
-
Sets/gets the op's flags.
arg_dir($index)
-
Returns the direction of the op's argument at
$index
. body($body)
body()
-
Sets/gets the op's code body.
jump($jump)
jump()
-
Sets/gets a string containing one or more
op_jump_t
values joined with|
(see include/parrot/op.h). This indicates if and how an op may jump. full_body()
-
For manual ops,
full_body()
is the same asbody()
. For auto ops this method adds a finalgoto NEXT()
line to the code to represent the auto-computed return value. See the note on op types above. rewrite_body($body, $trans)
-
Performs the various macro substitutions using the specified transform, correctly handling nested substitions, and repeating over the whole string until no more substitutions can be made.
VTABLE_
macros are enforced by convertingx->vtable->method
toVTABLE_method
. source($trans)
-
Returns the
full_body()
of the op with substitutions made by$trans
(a subclass ofParrot::OpTrans
). size()
-
Returns the op's number of arguments. Note that this also includes the op itself as one argument.
SEE ALSO
HISTORY
Author: Gregor N. Purdy <gregor@focusresearch.com>