3 Imager::regmach - documents the register virtual machine used by
8 The register machine is a complete rewrite of the stack machine
9 originally used by Imager::transform(), written for use by
14 (This document might be a little incoherent.)
16 The register machine is a fast implementation of a small instruction
17 set designed for evaluating an arithmetic expression to produce a
20 The machine takes as input:
26 An array of instructions
28 =item numeric registers
30 An array of numeric registers. Some registers are initialized as
35 An array of color registers. Currently these registers aren't
40 An array of Imager i_img pointers. The C<getpn> operators read pixels
45 The instructions supplied each take up to 4 input numeric or color
46 registers with a single output numeric or color register. The
47 machine attempts to execute instructions as safely as possible,
48 assuming that correct instructions have been provided, eg. the machine
49 protects against divide by zero, but doesn't check register numbers
52 The final instruction must be a C<ret> instruction, which returns the
55 =head2 Adding new instructions
57 To add a new instruction:
63 Add a new opcode to the enumeration in F<regmach.h> - make sure to add
64 comment after the enum name giving the input registers (C<rX> for
65 numeric, C<pX> for color) that the instruction takes. These must be in
66 the order that the instruction expects to take the. Put a letter (r
67 or p) after -> to indicate the result type.
71 Add a case to F<regmach.c> that executes the instruction.
79 The F<Makefile> should rebuild the F<Regops.pm> file, and your new
80 instruction will be added as a function.
82 If you want to add a single alternative instruction that might take
83 different argument types (it must take the same number of parameters),
84 create another instruction with that name followed by a p. The
85 current expression parsers explicitly look for such instruction names.
87 =head2 Future directions
89 Conditional and non-conditional jumps to implement iteration. This
90 will break the current optimizer in L<Imager::Expr> (and the compilers
91 for both expression compilers, for that matter.)
93 Complex arithmetic (Addi suggested this one). This would most likely
94 be a separate machine. Otherwise we'll have a very significant
99 If you feed bad 'machine code' to the register machine, you have a
100 good chance of a C<SIGSEGV>.
104 Tony Cook <tonyc@cpan.org>, Arnar M. Hrafnkelsson