A hashref defining extra constants for expression parsing. The names of the constants must be valid identifiers (/[^\W\d]\w*/) and the values must be valid numeric constants (that Perl recognizes in scalars).
Imager::Expr may define its own constants (currently just pi.)
A reference to an array of variable names. These are allocated numeric registers starting from register zero.
The Imager::Expr::error() method is used to retrieve the error if the expression object cannot be created.
Imager::Expr provides only a few simple methods meant for external use:
Imager::Expr->type_registered($keyword) Returns true if the given expression type is available. The parameter is the key supplied to the new() method. $expr->code() Returns the compiled code. $expr->nregs() Returns a reference to the array of numeric registers. $expr->cregs() Returns a reference to the array of color registers. $expr->dumpops() Returns a string with the generated VM machine code. $expr->dumpcode() Returns a string with the disassembled VM machine code.
Ill write this one day.
Methods used by parsers:
compile This is the main method youll need to implement in a parser. See the existing parsers for a guide.
Its supplied the following parameters:
o $expr - the expression to be parsed o $options - the options hash supplied to transform2.
Return an array ref of array refs containing opcodes and operands.
@vars = $self->_variables() A list (not a reference) of the input variables. This should be used to allocate as many registers as there are variable as input registers. $self->error($message) Set the return value of Imager::Expr::error() @ops = $self->stack_to_reg(@stack_ops) Converts marginally parsed RPN to register code. assemble() Called to convert op codes into byte code. numre() Returns a regular expression that matches floating point numbers. optimize() Optimizes the assembly code, including attempting common subexpression elimination and strength reducing division by a constant into multiplication by a constant. register_type() Called by a new expression parser implementation to register itself, call as:
where type code is the parameter that will accept the expression.
Try to avoid doing your own optimization beyond literal folding - if we add some sort of jump, the existing optimizer will need to be rewritten, and any optimization you perform may well be broken too (well, your code generation will probably be broken anyway <sigh>).
Tony Cook <firstname.lastname@example.org>, Arnar M. Hrafnkelsson
|perl v5.20.3||IMAGER::EXPR (3)||2014-01-10|