Reduct  v1.0.4-3-gdaf0d70
A functional and immutable language.
Loading...
Searching...
No Matches
inst.h File Reference

Bytecode instruction format. More...

#include "defs.h"
Include dependency graph for inst.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define REDUCT_REG_INVALID   ((reduct_reg_t) - 1)
 Invalid register value.
 
#define REDUCT_INST_WIDTH_OPCODE   6ULL
 Opcode width in bits.
 
#define REDUCT_INST_WIDTH_A   8ULL
 A operand width in bits.
 
#define REDUCT_INST_WIDTH_B   8ULL
 B operand width in bits.
 
#define REDUCT_INST_WIDTH_C   10ULL
 C operand width in bits.
 
#define REDUCT_INST_WIDTH_SBX   (REDUCT_INST_WIDTH_B + REDUCT_INST_WIDTH_C)
 SBx operand width in bits.
 
#define REDUCT_REGISTER_MAX   (1ULL << REDUCT_INST_WIDTH_A)
 The max number of registers per function frame.
 
#define REDUCT_CONSTANT_MAX   (1ULL << REDUCT_INST_WIDTH_C)
 The max number of constants per function.
 
#define REDUCT_INST_POS_OPCODE   0ULL
 Opcode position in bits.
 
#define REDUCT_INST_POS_A   (REDUCT_INST_POS_OPCODE + REDUCT_INST_WIDTH_OPCODE)
 A operand position in bits.
 
#define REDUCT_INST_POS_B   (REDUCT_INST_POS_A + REDUCT_INST_WIDTH_A)
 B operand position in bits.
 
#define REDUCT_INST_POS_C   (REDUCT_INST_POS_B + REDUCT_INST_WIDTH_B)
 C operand position in bits.
 
#define REDUCT_INST_MASK_OPCODE   ((1ULL << REDUCT_INST_WIDTH_OPCODE) - 1ULL)
 Opcode mask.
 
#define REDUCT_INST_MASK_A   ((1ULL << REDUCT_INST_WIDTH_A) - 1ULL)
 A operand mask.
 
#define REDUCT_INST_MASK_B   ((1ULL << REDUCT_INST_WIDTH_B) - 1ULL)
 B operand mask.
 
#define REDUCT_INST_MASK_C   ((1ULL << REDUCT_INST_WIDTH_C) - 1ULL)
 C operand mask.
 
#define REDUCT_INST_MASK_SBX   ((1ULL << REDUCT_INST_WIDTH_SBX) - 1ULL)
 SBx operand mask.
 
#define REDUCT_INST_MAKE_ABC(_op, _a, _b, _c)
 Create an instruction with opcode, A, B, and C operands.
 
#define REDUCT_INST_MAKE_ASBX(_op, _a, _sbx)
 Create an instruction with opcode and A operands, and SBx B operand.
 
#define REDUCT_INST_GET_OP(_inst)   (((_inst) >> REDUCT_INST_POS_OPCODE) & REDUCT_INST_MASK_OPCODE)
 Get the opcode from an instruction.
 
#define REDUCT_INST_GET_OP_BASE(_inst)    (((_inst) >> REDUCT_INST_POS_OPCODE) & (REDUCT_INST_MASK_OPCODE & ~REDUCT_MODE_CONST))
 Get the opcode base (without reduct_mode_t) from an instruction. Mask clears the REDUCT_MODE_CONST bit.
 
#define REDUCT_INST_GET_A(_inst)   (((_inst) >> REDUCT_INST_POS_A) & REDUCT_INST_MASK_A)
 Get the A operand from an instruction.
 
#define REDUCT_INST_GET_B(_inst)   (((_inst) >> REDUCT_INST_POS_B) & REDUCT_INST_MASK_B)
 Get the B operand from an instruction.
 
#define REDUCT_INST_GET_C(_inst)   (((_inst) >> REDUCT_INST_POS_C) & REDUCT_INST_MASK_C)
 Get the C operand from an instruction.
 
#define REDUCT_INST_GET_SBX(_inst)
 Get the SBX operand from an instruction.
 
#define REDUCT_INST_SET_A(_inst, _a)    (((_inst) & ~(REDUCT_INST_MASK_A << REDUCT_INST_POS_A)) | (((_a) & REDUCT_INST_MASK_A) << REDUCT_INST_POS_A))
 Set the A operand in an instruction.
 
#define REDUCT_INST_SET_SBX(_inst, _sbx)    (((_inst) & ~(REDUCT_INST_MASK_SBX << REDUCT_INST_POS_B)) | (((_sbx) & REDUCT_INST_MASK_SBX) << REDUCT_INST_POS_B))
 Set the SBX operand in an instruction.
 

Typedefs

typedef reduct_uint16_t reduct_reg_t
 Register type.
 
typedef reduct_uint32_t reduct_inst_t
 Instruction type.
 

Enumerations

enum  reduct_mode_t { REDUCT_MODE_NONE = -1 , REDUCT_MODE_TARGET = -2 , REDUCT_MODE_REG = 0 , REDUCT_MODE_CONST = 1 << 5 }
 Opcode mode enumeration. More...
 
enum  reduct_opcode_t {
  REDUCT_OPCODE_NONE , REDUCT_OPCODE_LIST , REDUCT_OPCODE_JMP , REDUCT_OPCODE_JMPF ,
  REDUCT_OPCODE_JMPT , REDUCT_OPCODE_JEQ , REDUCT_OPCODE_CALL , REDUCT_OPCODE_MOV ,
  REDUCT_OPCODE_RET , REDUCT_OPCODE_APPEND , REDUCT_OPCODE_EQ , REDUCT_OPCODE_NEQ ,
  REDUCT_OPCODE_SEQ , REDUCT_OPCODE_SNEQ , REDUCT_OPCODE_LT , REDUCT_OPCODE_LE ,
  REDUCT_OPCODE_GT , REDUCT_OPCODE_GE , REDUCT_OPCODE_ADD , REDUCT_OPCODE_SUB ,
  REDUCT_OPCODE_MUL , REDUCT_OPCODE_DIV , REDUCT_OPCODE_MOD , REDUCT_OPCODE_BAND ,
  REDUCT_OPCODE_BOR , REDUCT_OPCODE_BXOR , REDUCT_OPCODE_BNOT , REDUCT_OPCODE_SHL ,
  REDUCT_OPCODE_SHR , REDUCT_OPCODE_CLOSURE , REDUCT_OPCODE_CAPTURE , REDUCT_OPCODE_TAILCALL
}
 Opcode enumeration. More...
 

Detailed Description

Bytecode instruction format.

Definition in file inst.h.