parrotcode: Untitled | |
Contents | Compilers |
This file contains functions related to opcodes.
static int get_signature_length(expression *const e)
set $I0, 42 --> set_i_ictherefore, 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)
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)
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_ncFor 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)
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.
|