Reduct  v4.0.5-1-g4851deb
A functional and immutable language.
Loading...
Searching...
No Matches
Opcodes

Detailed Description

Data Structures

struct  reduct_opcode_info_t
 Opcode information structure. More...
 

Macros

#define REDUCT_OPCODE_BASE(_op)   ((_op) & ~REDUCT_OPCODE_MODE_CONST)
 Get the base form of the opcode without the constant bit set.
 
#define REDUCT_OPCODE_GET_NAME(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].name)
 Get the name of an opcode.
 
#define REDUCT_OPCODE_GET_LAYOUT(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].layout)
 Get the layout of an opcode.
 
#define REDUCT_OPCODE_IS_COMPARE(_op)    (REDUCT_OPCODE_BASE(_op) >= REDUCT_OPCODE_EQ && REDUCT_OPCODE_BASE(_op) <= REDUCT_OPCODE_GE)
 Check if an opcode is a comparison instruction.
 
#define REDUCT_OPCODE_TO_SKIP(_op)
 Get the skip version of a comparison opcode.
 
#define REDUCT_OPCODE_INVERT_SKIP(_op)
 Invert a skip comparison opcode (e.g. JEQ <-> JNEQ).
 
#define REDUCT_OPCODE_TO_RECUR(_op)
 Get the recursive version of a call opcode.
 
#define REDUCT_OPCODE_TO_TAIL(_op)
 Get the tail version of a call or return opcode.
 
#define REDUCT_OPCODE_HAS_TARGET(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_HAS_TARGET)
 Check if an opcode modifies its target register (A).
 
#define REDUCT_OPCODE_IS_RECUR(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_RECUR)
 Check if an opcode is a recursive call.
 
#define REDUCT_OPCODE_IS_JUMP(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_JUMP)
 Check if an opcode is a jump instruction.
 
#define REDUCT_OPCODE_HAS_CONST(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_HAS_CONST)
 Check if an opcode uses the C operand and has both a constant and register version.
 
#define REDUCT_OPCODE_READS_A(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_READ_A)
 Check if an opcode reads from register A.
 
#define REDUCT_OPCODE_READS_B(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_READ_B)
 Check if an opcode reads from register B.
 
#define REDUCT_OPCODE_READS_C(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_READ_C)
 Check if an opcode reads from register/constant C.
 
#define REDUCT_OPCODE_READS_RANGE(_op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_READ_RANGE)
 Check if an opcode reads a range of registers starting at A.
 
#define REDUCT_OPCODE_IS_COMMUTATIVE(_op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_COMMUTATIVE)
 Check if an opcode is commutative.
 
#define REDUCT_OPCODE_IS_SKIP(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_SKIP)
 Check if an opcode is a skip instruction.
 
#define REDUCT_OPCODE_IS_BRANCH(_op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & (REDUCT_OPCODE_FLAG_IS_SKIP | REDUCT_OPCODE_FLAG_IS_JUMP))
 Check if an opcode is a skip or jump instruction.
 
#define REDUCT_OPCODE_IS_CALL(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_CALL)
 Check if an opcode is a function call.
 
#define REDUCT_OPCODE_IS_TERMINATOR(_op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_TERMINATOR)
 Check if an opcode is a terminator.
 
#define REDUCT_OPCODE_IS_BINARY(_op)
 Check if an opcode is a binary operation (reads B and C).
 
#define REDUCT_OPCODE_IS_TERNARY(_op)
 Check if an opcode is a ternary operation (reads A, B and C).
 
#define REDUCT_OPCODE_IS_UNARY(_op)
 Check if an opcode is a unary operation (reads C only).
 
#define REDUCT_OPCODE_IS_FORK(_op)   (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_FORK)
 Check if an opcode is a fork instruction.
 

Enumerations

enum  reduct_opcode_mode_t { REDUCT_OPCODE_MODE_REG = 0 , REDUCT_OPCODE_MODE_CONST = 1 << 7 }
 Opcode mode enumeration. More...
 
enum  reduct_opcode_layout_t {
  REDUCT_LAYOUT_ABC , REDUCT_LAYOUT_AB , REDUCT_LAYOUT_AC , REDUCT_LAYOUT_C ,
  REDUCT_LAYOUT_SAX , REDUCT_LAYOUT_SAXC , REDUCT_LAYOUT_ABC_RANGE , REDUCT_LAYOUT_AB_RANGE ,
  REDUCT_LAYOUT_NONE
}
 Opcode operand layouts. More...
 
enum  reduct_opcode_t {
  REDUCT_OPCODE_NOP = 0x10 , REDUCT_OPCODE_MOV , REDUCT_OPCODE_LIST , REDUCT_OPCODE_CLOSURE ,
  REDUCT_OPCODE_CAPTURE , REDUCT_OPCODE_JMP , REDUCT_OPCODE_JMPF , REDUCT_OPCODE_JMPT ,
  REDUCT_OPCODE_CALL , REDUCT_OPCODE_RET , REDUCT_OPCODE_TAILCALL , REDUCT_OPCODE_RECUR ,
  REDUCT_OPCODE_TAILRECUR , REDUCT_OPCODE_EQ , REDUCT_OPCODE_NEQ , 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_JEQ , REDUCT_OPCODE_JNEQ ,
  REDUCT_OPCODE_JLT , REDUCT_OPCODE_JLE , REDUCT_OPCODE_JGT , REDUCT_OPCODE_JGE ,
  REDUCT_OPCODE_LEN , REDUCT_OPCODE_NTH2 , REDUCT_OPCODE_NTH3 , REDUCT_OPCODE_RANGE1 ,
  REDUCT_OPCODE_RANGE2 , REDUCT_OPCODE_RANGE3 , REDUCT_OPCODE_REPEAT , REDUCT_OPCODE_FORK ,
  REDUCT_OPCODE_JOIN , REDUCT_OPCODE_CONCAT , REDUCT_OPCODE_APPEND , REDUCT_OPCODE_PREPEND ,
  REDUCT_OPCODE_FIRST , REDUCT_OPCODE_LAST , REDUCT_OPCODE_REST , REDUCT_OPCODE_INIT ,
  REDUCT_OPCODE_MOV_CONST = REDUCT_OPCODE_MOV | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_CALL_CONST = REDUCT_OPCODE_CALL | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_RET_CONST = REDUCT_OPCODE_RET | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_CAPTURE_CONST = REDUCT_OPCODE_CAPTURE | REDUCT_OPCODE_MODE_CONST ,
  REDUCT_OPCODE_TAILCALL_CONST = REDUCT_OPCODE_TAILCALL | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_EQ_CONST = REDUCT_OPCODE_EQ | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_NEQ_CONST = REDUCT_OPCODE_NEQ | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_LT_CONST = REDUCT_OPCODE_LT | REDUCT_OPCODE_MODE_CONST ,
  REDUCT_OPCODE_LE_CONST = REDUCT_OPCODE_LE | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_GT_CONST = REDUCT_OPCODE_GT | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_GE_CONST = REDUCT_OPCODE_GE | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_ADD_CONST = REDUCT_OPCODE_ADD | REDUCT_OPCODE_MODE_CONST ,
  REDUCT_OPCODE_SUB_CONST = REDUCT_OPCODE_SUB | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_MUL_CONST = REDUCT_OPCODE_MUL | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_DIV_CONST = REDUCT_OPCODE_DIV | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_MOD_CONST = REDUCT_OPCODE_MOD | REDUCT_OPCODE_MODE_CONST ,
  REDUCT_OPCODE_BAND_CONST = REDUCT_OPCODE_BAND | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_BOR_CONST = REDUCT_OPCODE_BOR | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_BXOR_CONST = REDUCT_OPCODE_BXOR | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_BNOT_CONST = REDUCT_OPCODE_BNOT | REDUCT_OPCODE_MODE_CONST ,
  REDUCT_OPCODE_SHL_CONST = REDUCT_OPCODE_SHL | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_SHR_CONST = REDUCT_OPCODE_SHR | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_JEQ_CONST = REDUCT_OPCODE_JEQ | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_JNEQ_CONST = REDUCT_OPCODE_JNEQ | REDUCT_OPCODE_MODE_CONST ,
  REDUCT_OPCODE_JLT_CONST = REDUCT_OPCODE_JLT | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_JLE_CONST = REDUCT_OPCODE_JLE | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_JGT_CONST = REDUCT_OPCODE_JGT | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_JGE_CONST = REDUCT_OPCODE_JGE | REDUCT_OPCODE_MODE_CONST ,
  REDUCT_OPCODE_LEN_CONST = REDUCT_OPCODE_LEN | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_NTH2_CONST = REDUCT_OPCODE_NTH2 | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_NTH3_CONST = REDUCT_OPCODE_NTH3 | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_RANGE1_CONST = REDUCT_OPCODE_RANGE1 | REDUCT_OPCODE_MODE_CONST ,
  REDUCT_OPCODE_RANGE2_CONST = REDUCT_OPCODE_RANGE2 | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_RANGE3_CONST = REDUCT_OPCODE_RANGE3 | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_REPEAT_CONST = REDUCT_OPCODE_REPEAT | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_FORK_CONST = REDUCT_OPCODE_FORK | REDUCT_OPCODE_MODE_CONST ,
  REDUCT_OPCODE_JOIN_CONST = REDUCT_OPCODE_JOIN | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_FIRST_CONST = REDUCT_OPCODE_FIRST | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_LAST_CONST = REDUCT_OPCODE_LAST | REDUCT_OPCODE_MODE_CONST , REDUCT_OPCODE_REST_CONST = REDUCT_OPCODE_REST | REDUCT_OPCODE_MODE_CONST ,
  REDUCT_OPCODE_INIT_CONST = REDUCT_OPCODE_INIT | REDUCT_OPCODE_MODE_CONST
}
 Opcode enumeration. More...
 
enum  reduct_opcode_flags_t {
  REDUCT_OPCODE_FLAG_HAS_TARGET = (1 << 0) , REDUCT_OPCODE_FLAG_IS_JUMP = (1 << 1) , REDUCT_OPCODE_FLAG_HAS_CONST = (1 << 2) , REDUCT_OPCODE_FLAG_READ_A = (1 << 3) ,
  REDUCT_OPCODE_FLAG_READ_B = (1 << 4) , REDUCT_OPCODE_FLAG_READ_C = (1 << 5) , REDUCT_OPCODE_FLAG_READ_RANGE = (1 << 6) , REDUCT_OPCODE_FLAG_IS_COMMUTATIVE = (1 << 7) ,
  REDUCT_OPCODE_FLAG_IS_SKIP = (1 << 8) , REDUCT_OPCODE_FLAG_IS_CALL = (1 << 9) , REDUCT_OPCODE_FLAG_IS_TERMINATOR = (1 << 10) , REDUCT_OPCODE_FLAG_IS_RECUR = (1 << 11) ,
  REDUCT_OPCODE_FLAG_IS_FORK = (1 << 12)
}
 Opcode flags. More...
 

Variables

REDUCT_API const reduct_opcode_info_t reductOpcodeTable [128]
 Opcode information and flags table.
 

Macro Definition Documentation

◆ REDUCT_OPCODE_BASE

#define REDUCT_OPCODE_BASE (   _op)    ((_op) & ~REDUCT_OPCODE_MODE_CONST)

Get the base form of the opcode without the constant bit set.

Parameters
_opThe opcode.

Definition at line 188 of file opcode.h.

◆ REDUCT_OPCODE_GET_NAME

#define REDUCT_OPCODE_GET_NAME (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].name)

Get the name of an opcode.

Parameters
_opThe opcode.

Definition at line 195 of file opcode.h.

◆ REDUCT_OPCODE_GET_LAYOUT

#define REDUCT_OPCODE_GET_LAYOUT (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].layout)

Get the layout of an opcode.

Parameters
_opThe opcode.

Definition at line 202 of file opcode.h.

◆ REDUCT_OPCODE_IS_COMPARE

#define REDUCT_OPCODE_IS_COMPARE (   _op)     (REDUCT_OPCODE_BASE(_op) >= REDUCT_OPCODE_EQ && REDUCT_OPCODE_BASE(_op) <= REDUCT_OPCODE_GE)

Check if an opcode is a comparison instruction.

Parameters
_opThe opcode.

Definition at line 209 of file opcode.h.

◆ REDUCT_OPCODE_TO_SKIP

#define REDUCT_OPCODE_TO_SKIP (   _op)
Value:
#define REDUCT_OPCODE_IS_COMPARE(_op)
Check if an opcode is a comparison instruction.
Definition opcode.h:209
reduct_opcode_t
Opcode enumeration.
Definition opcode.h:50
@ REDUCT_OPCODE_EQ
(A, B, C) If R(B) == R/K(C) store true in R(A), else false.
Definition opcode.h:64
@ REDUCT_OPCODE_NOP
No operation.
Definition opcode.h:51
@ REDUCT_OPCODE_JEQ
(B, C) Skip the next instruction if R(B) == R/K(C), else continue.
Definition opcode.h:81

Get the skip version of a comparison opcode.

Parameters
_opThe comparison opcode.

Definition at line 217 of file opcode.h.

◆ REDUCT_OPCODE_INVERT_SKIP

#define REDUCT_OPCODE_INVERT_SKIP (   _op)
Value:
: (_op)) | \
#define REDUCT_OPCODE_BASE(_op)
Get the base form of the opcode without the constant bit set.
Definition opcode.h:188
@ REDUCT_OPCODE_JGT
(B, C) Skip the next instruction if R(B) > R/K(C), else continue.
Definition opcode.h:85
@ REDUCT_OPCODE_JNEQ
(B, C) Skip the next instruction if R(B) != R/K(C), else continue.
Definition opcode.h:82
@ REDUCT_OPCODE_JLE
(B, C) Skip the next instruction if R(B) <= R/K(C), else continue.
Definition opcode.h:84
@ REDUCT_OPCODE_JGE
(B, C) Skip the next instruction if R(B) >= R/K(C), else continue.
Definition opcode.h:86
@ REDUCT_OPCODE_JLT
(B, C) Skip the next instruction if R(B) < R/K(C), else continue.
Definition opcode.h:83
@ REDUCT_OPCODE_MODE_CONST
Constant operand mode.
Definition opcode.h:21

Invert a skip comparison opcode (e.g. JEQ <-> JNEQ).

Parameters
_opThe skip opcode.

Definition at line 226 of file opcode.h.

◆ REDUCT_OPCODE_TO_RECUR

#define REDUCT_OPCODE_TO_RECUR (   _op)
Value:
#define REDUCT_OPCODE_IS_CALL(_op)
Check if an opcode is a function call.
Definition opcode.h:343
@ REDUCT_OPCODE_RECUR
(A, B) Recursively call the current function with B args starting from R(A).
Definition opcode.h:62
@ REDUCT_OPCODE_TAILCALL
(A, B, C) Tail call callable in R/K(C) with B args starting from R(A).
Definition opcode.h:61
@ REDUCT_OPCODE_TAILRECUR
(A, B) Recursively tail call the current function with B args starting from R(A).
Definition opcode.h:63

Get the recursive version of a call opcode.

Parameters
_opThe call opcode.

Definition at line 241 of file opcode.h.

◆ REDUCT_OPCODE_TO_TAIL

#define REDUCT_OPCODE_TO_TAIL (   _op)
Value:
: (_op))
@ REDUCT_OPCODE_CALL
(A, B, C) Call callable in R/K(C) with B args starting from R(A). Result in R(A).
Definition opcode.h:59
@ REDUCT_OPCODE_CALL_CONST
Definition opcode.h:105
@ REDUCT_OPCODE_TAILCALL_CONST
Definition opcode.h:108

Get the tail version of a call or return opcode.

Parameters
_opThe opcode.

Definition at line 252 of file opcode.h.

◆ REDUCT_OPCODE_HAS_TARGET

#define REDUCT_OPCODE_HAS_TARGET (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_HAS_TARGET)

Check if an opcode modifies its target register (A).

Parameters
_opThe opcode.

Definition at line 263 of file opcode.h.

◆ REDUCT_OPCODE_IS_RECUR

#define REDUCT_OPCODE_IS_RECUR (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_RECUR)

Check if an opcode is a recursive call.

Parameters
_opThe opcode.

Definition at line 270 of file opcode.h.

◆ REDUCT_OPCODE_IS_JUMP

#define REDUCT_OPCODE_IS_JUMP (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_JUMP)

Check if an opcode is a jump instruction.

Parameters
_opThe opcode.

Definition at line 277 of file opcode.h.

◆ REDUCT_OPCODE_HAS_CONST

#define REDUCT_OPCODE_HAS_CONST (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_HAS_CONST)

Check if an opcode uses the C operand and has both a constant and register version.

Parameters
_opThe opcode.

Definition at line 284 of file opcode.h.

◆ REDUCT_OPCODE_READS_A

#define REDUCT_OPCODE_READS_A (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_READ_A)

Check if an opcode reads from register A.

Parameters
_opThe opcode.

Definition at line 291 of file opcode.h.

◆ REDUCT_OPCODE_READS_B

#define REDUCT_OPCODE_READS_B (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_READ_B)

Check if an opcode reads from register B.

Parameters
_opThe opcode.

Definition at line 298 of file opcode.h.

◆ REDUCT_OPCODE_READS_C

#define REDUCT_OPCODE_READS_C (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_READ_C)

Check if an opcode reads from register/constant C.

Parameters
_opThe opcode.

Definition at line 305 of file opcode.h.

◆ REDUCT_OPCODE_READS_RANGE

#define REDUCT_OPCODE_READS_RANGE (   _op)     (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_READ_RANGE)

Check if an opcode reads a range of registers starting at A.

Parameters
_opThe opcode.

Definition at line 312 of file opcode.h.

◆ REDUCT_OPCODE_IS_COMMUTATIVE

#define REDUCT_OPCODE_IS_COMMUTATIVE (   _op)     (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_COMMUTATIVE)

Check if an opcode is commutative.

Parameters
_opThe opcode.

Definition at line 320 of file opcode.h.

◆ REDUCT_OPCODE_IS_SKIP

#define REDUCT_OPCODE_IS_SKIP (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_SKIP)

Check if an opcode is a skip instruction.

Parameters
_opThe opcode.

Definition at line 328 of file opcode.h.

◆ REDUCT_OPCODE_IS_BRANCH

#define REDUCT_OPCODE_IS_BRANCH (   _op)     (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & (REDUCT_OPCODE_FLAG_IS_SKIP | REDUCT_OPCODE_FLAG_IS_JUMP))

Check if an opcode is a skip or jump instruction.

Parameters
_opThe opcode.

Definition at line 335 of file opcode.h.

◆ REDUCT_OPCODE_IS_CALL

#define REDUCT_OPCODE_IS_CALL (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_CALL)

Check if an opcode is a function call.

Parameters
_opThe opcode.

Definition at line 343 of file opcode.h.

◆ REDUCT_OPCODE_IS_TERMINATOR

#define REDUCT_OPCODE_IS_TERMINATOR (   _op)     (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_TERMINATOR)

Check if an opcode is a terminator.

Parameters
_opThe opcode.

Definition at line 350 of file opcode.h.

◆ REDUCT_OPCODE_IS_BINARY

#define REDUCT_OPCODE_IS_BINARY (   _op)
Value:
REDUCT_API const reduct_opcode_info_t reductOpcodeTable[128]
Opcode information and flags table.
@ REDUCT_OPCODE_FLAG_READ_C
Opcode reads from register/constant C.
Definition opcode.h:158
@ REDUCT_OPCODE_FLAG_READ_B
Opcode reads from register B.
Definition opcode.h:157
reduct_opcode_flags_t flags
Definition opcode.h:175

Check if an opcode is a binary operation (reads B and C).

Parameters
_opThe opcode.

Definition at line 358 of file opcode.h.

◆ REDUCT_OPCODE_IS_TERNARY

#define REDUCT_OPCODE_IS_TERNARY (   _op)
Value:

Check if an opcode is a ternary operation (reads A, B and C).

Parameters
_opThe opcode.

Definition at line 367 of file opcode.h.

◆ REDUCT_OPCODE_IS_UNARY

#define REDUCT_OPCODE_IS_UNARY (   _op)
Value:

Check if an opcode is a unary operation (reads C only).

Parameters
_opThe opcode.

Definition at line 377 of file opcode.h.

◆ REDUCT_OPCODE_IS_FORK

#define REDUCT_OPCODE_IS_FORK (   _op)    (reductOpcodeTable[REDUCT_OPCODE_BASE(_op)].flags & REDUCT_OPCODE_FLAG_IS_FORK)

Check if an opcode is a fork instruction.

Parameters
_opThe opcode.

Definition at line 387 of file opcode.h.

Enumeration Type Documentation

◆ reduct_opcode_mode_t

Opcode mode enumeration.

Enumerator
REDUCT_OPCODE_MODE_REG 

Register operand mode.

REDUCT_OPCODE_MODE_CONST 

Constant operand mode.

Definition at line 18 of file opcode.h.

◆ reduct_opcode_layout_t

Opcode operand layouts.

Enumerator
REDUCT_LAYOUT_ABC 

R(A) R(B) R/K(C)

REDUCT_LAYOUT_AB 

R(A) R(B)

REDUCT_LAYOUT_AC 

R(A) R/K(C)

REDUCT_LAYOUT_C 

R/K(C)

REDUCT_LAYOUT_SAX 

sAx

REDUCT_LAYOUT_SAXC 

sAx R/K(C)

REDUCT_LAYOUT_ABC_RANGE 

R(A) B R/K(C)

REDUCT_LAYOUT_AB_RANGE 

R(A) B.

REDUCT_LAYOUT_NONE 

No operands.

Definition at line 28 of file opcode.h.

◆ reduct_opcode_t

Opcode enumeration.

Warning
Instructins that start a new frame such as REDUCT_OPCODE_CALL or REDUCT_OPCODE_RECUR will utilize the target register (R(A)) as the base of the new frame. As such, this register must be greater than any live register to avoid clobbering.
Enumerator
REDUCT_OPCODE_NOP 

No operation.

REDUCT_OPCODE_MOV 

(A, C) Move value in R/K(C) to R(A).

REDUCT_OPCODE_LIST 

(A, B) R(A) = (R(A) R(A + 1) ... R(A + B - 1))

REDUCT_OPCODE_CLOSURE 

(A, C) Wrap the function prototype in K(C) in a closure and store in R(A).

REDUCT_OPCODE_CAPTURE 

(A, B, C) Capture R/K(C) into constant slot B in closure R(A).

REDUCT_OPCODE_JMP 

(sAx) Unconditional jump by relative offset sAx.

REDUCT_OPCODE_JMPF 

(sAx, C) Jump by sAx if R(C) is falsy.

REDUCT_OPCODE_JMPT 

(sAx, C) Jump by sAx if R(C) is truthy.

REDUCT_OPCODE_CALL 

(A, B, C) Call callable in R/K(C) with B args starting from R(A). Result in R(A).

REDUCT_OPCODE_RET 

(C) Return value in R/K(C).

REDUCT_OPCODE_TAILCALL 

(A, B, C) Tail call callable in R/K(C) with B args starting from R(A).

REDUCT_OPCODE_RECUR 

(A, B) Recursively call the current function with B args starting from R(A).

REDUCT_OPCODE_TAILRECUR 

(A, B) Recursively tail call the current function with B args starting from R(A).

REDUCT_OPCODE_EQ 

(A, B, C) If R(B) == R/K(C) store true in R(A), else false.

REDUCT_OPCODE_NEQ 

(A, B, C) If R(B) != R/K(C) store true in R(A), else false.

REDUCT_OPCODE_LT 

(A, B, C) If R(B) < R/K(C) store true in R(A), else false.

REDUCT_OPCODE_LE 

(A, B, C) If R(B) <= R/K(C) store true in R(A), else false.

REDUCT_OPCODE_GT 

(A, B, C) If R(B) > R/K(C) store true in R(A), else false.

REDUCT_OPCODE_GE 

(A, B, C) If R(B) >= R/K(C) store true in R(A), else false.

REDUCT_OPCODE_ADD 

(A, B, C) R(A) = R(B) + R/K(C)

REDUCT_OPCODE_SUB 

(A, B, C) R(A) = R(B) - R/K(C)

REDUCT_OPCODE_MUL 

(A, B, C) R(A) = R(B) * R/K(C)

REDUCT_OPCODE_DIV 

(A, B, C) R(A) = R(B) / R/K(C)

REDUCT_OPCODE_MOD 

(A, B, C) R(A) = R(B) % R/K(C)

REDUCT_OPCODE_BAND 

(A, B, C) R(A) = R(B) & R/K(C)

REDUCT_OPCODE_BOR 

(A, B, C) R(A) = R(B) | R/K(C)

REDUCT_OPCODE_BXOR 

(A, B, C) R(A) = R(B) ^ R/K(C)

REDUCT_OPCODE_BNOT 

(A, C) R(A) = ~R/K(C)

REDUCT_OPCODE_SHL 

(A, B, C) R(A) = R(B) << R/K(C)

REDUCT_OPCODE_SHR 

(A, B, C) R(A) = R(B) >> R/K(C)

REDUCT_OPCODE_JEQ 

(B, C) Skip the next instruction if R(B) == R/K(C), else continue.

REDUCT_OPCODE_JNEQ 

(B, C) Skip the next instruction if R(B) != R/K(C), else continue.

REDUCT_OPCODE_JLT 

(B, C) Skip the next instruction if R(B) < R/K(C), else continue.

REDUCT_OPCODE_JLE 

(B, C) Skip the next instruction if R(B) <= R/K(C), else continue.

REDUCT_OPCODE_JGT 

(B, C) Skip the next instruction if R(B) > R/K(C), else continue.

REDUCT_OPCODE_JGE 

(B, C) Skip the next instruction if R(B) >= R/K(C), else continue.

REDUCT_OPCODE_LEN 

(A, C) R(A) = length of R/K(C)

REDUCT_OPCODE_NTH2 

(A, B, C) R(A) = R(B)[R/K(C)]

REDUCT_OPCODE_NTH3 

(A, B, C) R(A) = R(A)[R(B)][R/K(C)]

REDUCT_OPCODE_RANGE1 

(A, C) R(A) = range(0, R/K(C), 1)

REDUCT_OPCODE_RANGE2 

(A, B, C) R(A) = range(R(B), R/K(C), 1)

REDUCT_OPCODE_RANGE3 

(A, B, C) R(A) = range(R(A), R(B), R/K(C))

REDUCT_OPCODE_REPEAT 

(A, B, C) R(A) = repeat(R(B), R/K(C))

REDUCT_OPCODE_FORK 

(A, B, C) Spawn a thread for R/K(C) with B args starting at R(A). Task handle stored in R(A).

REDUCT_OPCODE_JOIN 

(A, C) Wait for task handle in R(C) to complete, result stored in R(A).

REDUCT_OPCODE_CONCAT 

(A, B) R(A) = concat(R(A) ... R(A + B - 1))

REDUCT_OPCODE_APPEND 

(A, B) R(A) = append(R(A), R(A + 1) ... R(A + B - 1))

REDUCT_OPCODE_PREPEND 

(A, B) R(A) = prepend(R(A), R(A + 1) ... R(A + B - 1))

REDUCT_OPCODE_FIRST 

(A, C) R(A) = first(R/K(C))

REDUCT_OPCODE_LAST 

(A, C) R(A) = last(R/K(C))

REDUCT_OPCODE_REST 

(A, C) R(A) = rest(R/K(C))

REDUCT_OPCODE_INIT 

(A, C) R(A) = init(R/K(C))

REDUCT_OPCODE_MOV_CONST 
REDUCT_OPCODE_CALL_CONST 
REDUCT_OPCODE_RET_CONST 
REDUCT_OPCODE_CAPTURE_CONST 
REDUCT_OPCODE_TAILCALL_CONST 
REDUCT_OPCODE_EQ_CONST 
REDUCT_OPCODE_NEQ_CONST 
REDUCT_OPCODE_LT_CONST 
REDUCT_OPCODE_LE_CONST 
REDUCT_OPCODE_GT_CONST 
REDUCT_OPCODE_GE_CONST 
REDUCT_OPCODE_ADD_CONST 
REDUCT_OPCODE_SUB_CONST 
REDUCT_OPCODE_MUL_CONST 
REDUCT_OPCODE_DIV_CONST 
REDUCT_OPCODE_MOD_CONST 
REDUCT_OPCODE_BAND_CONST 
REDUCT_OPCODE_BOR_CONST 
REDUCT_OPCODE_BXOR_CONST 
REDUCT_OPCODE_BNOT_CONST 
REDUCT_OPCODE_SHL_CONST 
REDUCT_OPCODE_SHR_CONST 
REDUCT_OPCODE_JEQ_CONST 
REDUCT_OPCODE_JNEQ_CONST 
REDUCT_OPCODE_JLT_CONST 
REDUCT_OPCODE_JLE_CONST 
REDUCT_OPCODE_JGT_CONST 
REDUCT_OPCODE_JGE_CONST 
REDUCT_OPCODE_LEN_CONST 
REDUCT_OPCODE_NTH2_CONST 
REDUCT_OPCODE_NTH3_CONST 
REDUCT_OPCODE_RANGE1_CONST 
REDUCT_OPCODE_RANGE2_CONST 
REDUCT_OPCODE_RANGE3_CONST 
REDUCT_OPCODE_REPEAT_CONST 
REDUCT_OPCODE_FORK_CONST 
REDUCT_OPCODE_JOIN_CONST 
REDUCT_OPCODE_FIRST_CONST 
REDUCT_OPCODE_LAST_CONST 
REDUCT_OPCODE_REST_CONST 
REDUCT_OPCODE_INIT_CONST 

Definition at line 49 of file opcode.h.

◆ reduct_opcode_flags_t

Opcode flags.

Enumerator
REDUCT_OPCODE_FLAG_HAS_TARGET 

Opcode modifies target register A.

REDUCT_OPCODE_FLAG_IS_JUMP 

Opcode is a jump.

REDUCT_OPCODE_FLAG_HAS_CONST 

Opcode uses C operand and has both reg/const versions.

REDUCT_OPCODE_FLAG_READ_A 

Opcode reads from register A (or range starting at A).

REDUCT_OPCODE_FLAG_READ_B 

Opcode reads from register B.

REDUCT_OPCODE_FLAG_READ_C 

Opcode reads from register/constant C.

REDUCT_OPCODE_FLAG_READ_RANGE 

Opcode reads a range of registers starting at A.

REDUCT_OPCODE_FLAG_IS_COMMUTATIVE 

Opcode is commutative.

REDUCT_OPCODE_FLAG_IS_SKIP 

Opcode is a skip instruction.

REDUCT_OPCODE_FLAG_IS_CALL 

Opcode is a function call.

REDUCT_OPCODE_FLAG_IS_TERMINATOR 

Opcode ends basic block reachability.

REDUCT_OPCODE_FLAG_IS_RECUR 

Opcode is a recursive call.

REDUCT_OPCODE_FLAG_IS_FORK 

Opcode returns a task handle.

Definition at line 151 of file opcode.h.

Variable Documentation

◆ reductOpcodeTable

REDUCT_API const reduct_opcode_info_t reductOpcodeTable[128]
extern

Opcode information and flags table.