Reduct  v1.0.4-3-gdaf0d70
A functional and immutable language.
Loading...
Searching...
No Matches
eval_impl.h File Reference
#include "closure.h"
#include "defs.h"
#include "eval.h"
#include "item.h"
#include "standard.h"
#include "parse.h"
#include "compile.h"
Include dependency graph for eval_impl.h:

Go to the source code of this file.

Data Structures

struct  eval_run_state_t
 

Macros

#define DISPATCH()
 
#define OP_COMPARE(_label, _op)
 
#define OP_ARITH(_label, _op)
 
#define DECODE_A()   reduct_uint32_t a = REDUCT_INST_GET_A(inst)
 
#define DECODE_B()   reduct_uint32_t b = REDUCT_INST_GET_B(inst)
 
#define DECODE_C_REG()
 
#define DECODE_C_CONST()
 
#define DECODE_SBX()   reduct_int32_t sbx = REDUCT_INST_GET_SBX(inst)
 
#define ERROR_CHECK(_expr, ...)
 
#define OP_ENTRY(_op, _label)   [_op] = &&_label, [_op | REDUCT_MODE_CONST] = &&_label
 
#define OP_ENTRY_C(_op, _label)   [_op] = &&_label, [_op | REDUCT_MODE_CONST] = &&_label##_k
 
#define OP_BITWISE(_label, _op)
 
#define OP_EQUALITY(_label, _func, _truth)
 
#define LABEL_C_OP(_label, ...)
 

Functions

static void reduct_eval_state_init (reduct_t *reduct, reduct_eval_state_t *state)
 
REDUCT_API void reduct_eval_state_deinit (reduct_eval_state_t *state)
 Deinitialize an evaluation state structure.
 
static REDUCT_ALWAYS_INLINE void reduct_eval_ensure_regs (reduct_t *reduct, reduct_eval_state_t *state, reduct_uint32_t neededRegs)
 
static REDUCT_ALWAYS_INLINE void reduct_eval_push_frame (reduct_t *reduct, reduct_eval_state_t *state, reduct_closure_t *closure, reduct_uint32_t target)
 
static REDUCT_ALWAYS_INLINE void reduct_eval_pop_frame (reduct_eval_state_t *state)
 
static REDUCT_ALWAYS_INLINE void reduct_eval_tail_frame (reduct_t *reduct, reduct_eval_state_t *state, reduct_closure_t *closure)
 
static reduct_handle_t reduct_eval_run (reduct_t *reduct, reduct_eval_state_t *state, reduct_uint32_t initialFrameCount)
 
REDUCT_API reduct_handle_t reduct_eval (struct reduct *reduct, reduct_function_t *function)
 
REDUCT_API reduct_handle_t reduct_eval_file (reduct_t *reduct, const char *path)
 Parses, compiles and evaluates a file.
 
REDUCT_API reduct_handle_t reduct_eval_string (reduct_t *reduct, const char *str, reduct_size_t len)
 Parses, compiles and evaluates a string.
 
REDUCT_API reduct_handle_t reduct_eval_call (reduct_t *reduct, reduct_handle_t callable, reduct_size_t argc, reduct_handle_t *argv)
 Calls a Reduct callable (closure or native) with arguments.
 

Macro Definition Documentation

◆ DISPATCH

#define DISPATCH ( )
Value:
do \
{ \
inst = *ip++; \
op = REDUCT_INST_GET_OP(inst); \
goto* dispatchTable[op]; \
} while (0)
#define REDUCT_INST_GET_OP(_inst)
Get the opcode from an instruction.
Definition inst.h:156

◆ OP_COMPARE

#define OP_COMPARE (   _label,
  _op 
)
Value:
LABEL_C_OP(_label, { \
DECODE_A(); \
DECODE_B(); \
base[a] = REDUCT_HANDLE_COMPARE_FAST(reduct, &base[b], &valC, _op) ? REDUCT_HANDLE_TRUE() : REDUCT_HANDLE_FALSE(); \
DISPATCH(); \
})
#define LABEL_C_OP(_label,...)
#define REDUCT_HANDLE_FALSE()
Constant false handle.
Definition handle.h:267
#define REDUCT_HANDLE_COMPARE_FAST(_reduct, _a, _b, _op)
Compare two handles using a given operator with a fast path for integers and floats.
Definition handle.h:287
#define REDUCT_HANDLE_TRUE()
Constant true handle.
Definition handle.h:269

◆ OP_ARITH

#define OP_ARITH (   _label,
  _op 
)
Value:
LABEL_C_OP(_label, { \
DECODE_A(); \
DECODE_B(); \
REDUCT_HANDLE_ARITHMETIC_FAST(reduct, &base[a], &base[b], &valC, _op); \
DISPATCH(); \
})

◆ DECODE_A

#define DECODE_A ( )    reduct_uint32_t a = REDUCT_INST_GET_A(inst)

◆ DECODE_B

#define DECODE_B ( )    reduct_uint32_t b = REDUCT_INST_GET_B(inst)

◆ DECODE_C_REG

#define DECODE_C_REG ( )
Value:
reduct_handle_t valC = base[c]
reduct_uint64_t reduct_handle_t
Handle type.
Definition defs.h:189
uint32_t reduct_uint32_t
Definition defs.h:95
#define REDUCT_INST_GET_C(_inst)
Get the C operand from an instruction.
Definition inst.h:185

◆ DECODE_C_CONST

#define DECODE_C_CONST ( )
Value:
reduct_handle_t valC = constants[c]

◆ DECODE_SBX

#define DECODE_SBX ( )    reduct_int32_t sbx = REDUCT_INST_GET_SBX(inst)

◆ ERROR_CHECK

#define ERROR_CHECK (   _expr,
  ... 
)
Value:
do \
{ \
if (REDUCT_UNLIKELY(!(_expr))) \
{ \
frame->ip = ip; \
REDUCT_ERROR_RUNTIME(__VA_ARGS__); \
} \
} while (0)
#define REDUCT_UNLIKELY(_x)
Definition defs.h:118

◆ OP_ENTRY

#define OP_ENTRY (   _op,
  _label 
)    [_op] = &&_label, [_op | REDUCT_MODE_CONST] = &&_label

◆ OP_ENTRY_C

#define OP_ENTRY_C (   _op,
  _label 
)    [_op] = &&_label, [_op | REDUCT_MODE_CONST] = &&_label##_k

◆ OP_BITWISE

#define OP_BITWISE (   _label,
  _op 
)
Value:
LABEL_C_OP(_label, { \
DECODE_A(); \
DECODE_B(); \
base[a] = REDUCT_HANDLE_FROM_INT(reduct_get_int(reduct, &base[b]) _op reduct_get_int(reduct, &valC)); \
DISPATCH(); \
})
#define REDUCT_HANDLE_FROM_INT(_val)
Create a handle from an integer.
Definition handle.h:54
REDUCT_API reduct_handle_t reduct_get_int(struct reduct *reduct, reduct_handle_t *handle)

◆ OP_EQUALITY

#define OP_EQUALITY (   _label,
  _func,
  _truth 
)
Value:
LABEL_C_OP(_label, { \
DECODE_A(); \
DECODE_B(); \
base[a] = (_func(reduct, &base[b], &valC) == _truth) ? REDUCT_HANDLE_TRUE() : REDUCT_HANDLE_FALSE(); \
DISPATCH(); \
})

◆ LABEL_C_OP

#define LABEL_C_OP (   _label,
  ... 
)
Value:
_label: \
{ \
DECODE_C_REG(); \
__VA_ARGS__ \
} \
_label##_k: \
{ \
DECODE_C_CONST(); \
__VA_ARGS__ \
}

Function Documentation

◆ reduct_eval_state_init()

static void reduct_eval_state_init ( reduct_t reduct,
reduct_eval_state_t state 
)
static

Definition at line 12 of file eval_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_eval_ensure_regs()

static REDUCT_ALWAYS_INLINE void reduct_eval_ensure_regs ( reduct_t reduct,
reduct_eval_state_t state,
reduct_uint32_t  neededRegs 
)
inlinestatic

Definition at line 44 of file eval_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_eval_push_frame()

static REDUCT_ALWAYS_INLINE void reduct_eval_push_frame ( reduct_t reduct,
reduct_eval_state_t state,
reduct_closure_t closure,
reduct_uint32_t  target 
)
inlinestatic

Definition at line 68 of file eval_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_eval_pop_frame()

static REDUCT_ALWAYS_INLINE void reduct_eval_pop_frame ( reduct_eval_state_t state)
inlinestatic

Definition at line 100 of file eval_impl.h.

Here is the caller graph for this function:

◆ reduct_eval_tail_frame()

static REDUCT_ALWAYS_INLINE void reduct_eval_tail_frame ( reduct_t reduct,
reduct_eval_state_t state,
reduct_closure_t closure 
)
inlinestatic

Definition at line 109 of file eval_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_eval_run()

static reduct_handle_t reduct_eval_run ( reduct_t reduct,
reduct_eval_state_t state,
reduct_uint32_t  initialFrameCount 
)
static
Todo:
Write some macro magic to turn this into a switch case if not using GCC or Clang

Definition at line 138 of file eval_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_eval()

REDUCT_API reduct_handle_t reduct_eval ( struct reduct *  reduct,
reduct_function_t function 
)

Definition at line 498 of file eval_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function: