Above are two other cases where ``VARARG`` needs to copy all passed parameters over to a set of registers in order for the next operation to proceed. Both the above forms of table creation and return accepts a variable number of values or objects.
Above are two other cases where ``VARARG`` needs to copy all passed parameters
over to a set of registers in order for the next operation to proceed. Both the above forms of
table creation and return accepts a variable number of values or objects.
Relational And logic Instructions
=================================
Relational and logic instructions are used in conjunction with other instructions to implement control
structures or expressions. Instead of generating boolean results, these instructions conditionally perform
a jump over the next instruction; the emphasis is on implementing control blocks. Instructions are arranged
so that there are two paths to follow based on the relational test.
::
EQ A B C if ((RK(B) == RK(C)) ~= A) then PC++
LT A B C if ((RK(B) < RK(C)) ~= A) then PC++
LE A B C if ((RK(B) <= RK(C)) ~= A) then PC++
Description
-----------
Compares RK(B) and RK(C), which may be registers or constants. If the boolean result is not A,
then skip the next instruction. Conversely, if the boolean result equals A, continue with the
next instruction.
``EQ`` is for equality. ``LT`` is for “less than” comparison. ``LE`` is for “less than or equal to”
comparison. The boolean A field allows the full set of relational comparison operations to be
synthesized from these three instructions. The Lua code generator produces either 0 or 1 for the boolean A.
For the fall-through case, a ``JMP`` is always expected, in order to optimize execution in the
virtual machine. In effect, ``EQ``, ``LT`` and ``LE`` must always be paired with a following ``JMP``
instruction.
Examples
--------
By comparing the result of the relational operation with A, the sense of the comparison can
be reversed. Obviously the alternative is to reverse the paths taken by the instruction, but that
will probably complicate code generation some more. The conditional jump is performed if the comparison
result is not A, whereas execution continues normally if the comparison result matches A.
Due to the way code is generated and the way the virtual machine works, a ``JMP`` instruction is
always expected to follow an ``EQ``, ``LT`` or ``LE``. The following ``JMP`` is optimized by
executing it in conjunction with ``EQ``, ``LT`` or ``LE``.
::
local x,y; return x ~= y
Generates::
main <(string):0,0> (7 instructions at 0000001BC48FD390)