DESCRIPTION ^

This file contains functions related to opcodes.

FUNCTIONS ^

static int get_signature_length(expression *const e)
Calculate the length of the signature for one operand; an operand is separated from the instruction name or another operand through '_', which must also be counted.
 set $I0, 42  --> set_i_ic
therefore, for $I0 (a target), return 1 for the type, 1 for the '_', and whatever is needed for a key, if any, as in this example:
 set $P0[1] = "hi"  --> set_p_kic_sc
$P0 is a target, resulting in "_p", the key [1] is a key ('k') of type int ('i'), and it's a constant ('c'). Add 1 for the '_'.
static char *write_signature(expression *const iter, char *instr_writer)
Write the signature for the operand iter, using the character pointer instr_writer. When the operand is an indexed target node (in other words, it has a key node), this function is invoked recursively passing the key as an argument.This function returns the updated character pointer (due to pass-by-value semantics of the C calling conventions).
static char *get_signatured_opname(instruction *const instr)
Returns the full opname of the instruction name; the signature of the opname is based on the operands, some examples are shown below:
 set I0, 10        --> set_i_ic
 print "hi"        --> print_sc
 set P0[1], 3.14   --> set_p_kic_nc
For each operand, an underscore is added; then for the types int, num, string or pmc, an 'i', 'n', 's' or 'p' is added respectively. If the operand is a constant, a 'c' suffic is added.If the operand is a key of something, a 'k' prefix is added.
int get_opinfo(lexer_state *const lexer)
Compute the signatured opname from the instruction name and its arguments. Based on this signature, the opcode is retrieved. If the opcode cannot be found (i.e., it's -1), then a check is done for some special math ops; add_i_ic_ic and the like do not exist, but instead should be replaced by set_i_ic (and the like). If it's not one of these special cases, then that means the op is not valid, and an error message will be reported.


parrot