Reduct  v1.0.4-3-gdaf0d70
A functional and immutable language.
Loading...
Searching...
No Matches
Error

Detailed Description

Data Structures

struct  reduct_error_t
 Error structure. More...
 

Macros

#define REDUCT_ERROR_MAX_LEN   512
 Maximum length of an error string.
 
#define REDUCT_ERROR()   ((reduct_error_t){0})
 Create a Reduct error structure.
 
#define REDUCT_ERROR_CATCH(_error)   (REDUCT_SETJMP((_error)->jmp))
 Catch an error using the jump buffer in the error structure.
 
#define REDUCT_ERROR_THROW(_error, _item, _type, ...)
 Throw an error using the jump buffer in the error structure.
 
#define REDUCT_ERROR_SYNTAX(_error, _input, _ptr, ...)
 Throw a syntax error using the jump buffer in the error structure.
 
#define REDUCT_ERROR_COMPILE(_compiler, _item, ...)
 Throw a compile error using the jump buffer in the error structure.
 
#define REDUCT_ERROR_RUNTIME(_reduct, ...)   reduct_error_throw_runtime((_reduct), __VA_ARGS__)
 Throw a runtime error using the jump buffer in the error structure.
 
#define REDUCT_ERROR_INTERNAL(_reduct, ...)   REDUCT_ERROR_THROW((_reduct)->error, REDUCT_NULL, INTERNAL, __VA_ARGS__)
 Throw an internal error using the jump buffer in the error structure.
 
#define REDUCT_ERROR_CHECK_TYPE(_reduct, _name, _handle, _expected)
 Report a type error for a handle.
 
#define REDUCT_ERROR_CHECK_LIST(_reduct, _handle, _name)
 Assert that a handle is a list.
 
#define REDUCT_ERROR_CHECK_CALLABLE(_reduct, _handle, _name)
 Assert that a handle is a callable.
 
#define REDUCT_ERROR_CHECK_SEQUENCE(_reduct, _handle, _name)
 Assert that a handle is a sequence (list or atom).
 

Enumerations

enum  reduct_error_type_t {
  REDUCT_ERROR_TYPE_NONE , REDUCT_ERROR_TYPE_SYNTAX , REDUCT_ERROR_TYPE_COMPILE , REDUCT_ERROR_TYPE_RUNTIME ,
  REDUCT_ERROR_TYPE_INTERNAL
}
 Error type enumeration. More...
 

Functions

REDUCT_API void reduct_error_print (reduct_error_t *error, reduct_file_t file)
 Format and print the error to a file.
 
REDUCT_API void reduct_error_get_row_column (reduct_error_t *error, reduct_size_t *row, reduct_size_t *column)
 Get the row and column by traversing the input buffer.
 
REDUCT_API void reduct_error_set (reduct_error_t *error, const char *path, const char *input, reduct_size_t inputLength, reduct_size_t regionLength, reduct_size_t position, reduct_error_type_t type, const char *message,...)
 Set the error information in the error structure.
 
REDUCT_API void reduct_error_get_item_params (struct reduct_item *item, const char **path, const char **input, reduct_size_t *inputLength, reduct_size_t *regionLength, reduct_size_t *position)
 Get the error parameters from a Reduct item.
 
REDUCT_API REDUCT_NORETURN void reduct_error_throw_runtime (struct reduct *reduct, const char *message,...)
 Throw a runtime error utilizing the evaluation state to determine the context.
 
REDUCT_API void reduct_error_check_arity (struct reduct *reduct, reduct_size_t argc, reduct_size_t expected, const char *name)
 Check the arity of a native function call.
 
REDUCT_API void reduct_error_check_min_arity (struct reduct *reduct, reduct_size_t argc, reduct_size_t min, const char *name)
 
REDUCT_API void reduct_error_check_arity_range (struct reduct *reduct, reduct_size_t argc, reduct_size_t min, reduct_size_t max, const char *name)
 

Macro Definition Documentation

◆ REDUCT_ERROR_MAX_LEN

#define REDUCT_ERROR_MAX_LEN   512

Maximum length of an error string.

Definition at line 17 of file error.h.

◆ REDUCT_ERROR

#define REDUCT_ERROR ( )    ((reduct_error_t){0})

Create a Reduct error structure.

Returns
A new Reduct error structure initialized to zero.

Definition at line 53 of file error.h.

◆ REDUCT_ERROR_CATCH

#define REDUCT_ERROR_CATCH (   _error)    (REDUCT_SETJMP((_error)->jmp))

Catch an error using the jump buffer in the error structure.

Parameters
_errorPointer to the error structure.

Definition at line 115 of file error.h.

◆ REDUCT_ERROR_THROW

#define REDUCT_ERROR_THROW (   _error,
  _item,
  _type,
  ... 
)
Value:
do \
{ \
const char* __path; \
const char* __input; \
reduct_size_t __input_length; \
reduct_size_t __region_length; \
reduct_size_t __position; \
reduct_error_get_item_params((_item), &__path, &__input, &__input_length, &__region_length, &__position); \
reduct_error_set((_error), __path, __input, __input_length, __region_length, __position, \
REDUCT_ERROR_TYPE_##_type, __VA_ARGS__); \
REDUCT_LONGJMP((_error)->jmp, REDUCT_TRUE); \
} while (0)
size_t reduct_size_t
Definition defs.h:100
@ REDUCT_TRUE
Definition defs.h:136

Throw an error using the jump buffer in the error structure.

Parameters
_errorPointer to the error structure.
_itemPointer to the item that caused the error.
_typeThe suffix of the error type (e.g., INTERNAL, RUNTIME, etc.).
...The error message format string and any optional arguments.

Definition at line 125 of file error.h.

◆ REDUCT_ERROR_SYNTAX

#define REDUCT_ERROR_SYNTAX (   _error,
  _input,
  _ptr,
  ... 
)
Value:
do \
{ \
reduct_error_set((_error), (_input)->path, (_input)->buffer, (_input)->end - (_input)->buffer, 1, \
(reduct_size_t)((_ptr) - (_input)->buffer), REDUCT_ERROR_TYPE_SYNTAX, __VA_ARGS__); \
REDUCT_LONGJMP((_error)->jmp, REDUCT_TRUE); \
} while (0)
@ REDUCT_ERROR_TYPE_SYNTAX
Definition error.h:26

Throw a syntax error using the jump buffer in the error structure.

Parameters
_errorPointer to the error structure.
_inputPointer to the input structure being parsed.
_ptrPointer to the current position in the input buffer.
...The error message format string and any optional arguments.

Definition at line 147 of file error.h.

◆ REDUCT_ERROR_COMPILE

#define REDUCT_ERROR_COMPILE (   _compiler,
  _item,
  ... 
)
Value:
REDUCT_ERROR_THROW((_compiler)->reduct->error, \
(((_item) != REDUCT_NULL && (_item)->input != REDUCT_NULL) \
? (_item) \
: ((_compiler)->lastItem != REDUCT_NULL ? (_compiler)->lastItem : (_item))), \
COMPILE, __VA_ARGS__)
#define REDUCT_NULL
Definition defs.h:23
#define REDUCT_ERROR_THROW(_error, _item, _type,...)
Throw an error using the jump buffer in the error structure.
Definition error.h:125

Throw a compile error using the jump buffer in the error structure.

Parameters
_compilerThe compiler instance.
_itemPointer to the item that caused the error.
...The error message format string and any optional arguments.

Definition at line 162 of file error.h.

◆ REDUCT_ERROR_RUNTIME

#define REDUCT_ERROR_RUNTIME (   _reduct,
  ... 
)    reduct_error_throw_runtime((_reduct), __VA_ARGS__)

Throw a runtime error using the jump buffer in the error structure.

Parameters
_reductPointer to the reduct instance.
...The error message format string and any optional arguments.

Definition at line 175 of file error.h.

◆ REDUCT_ERROR_INTERNAL

#define REDUCT_ERROR_INTERNAL (   _reduct,
  ... 
)    REDUCT_ERROR_THROW((_reduct)->error, REDUCT_NULL, INTERNAL, __VA_ARGS__)

Throw an internal error using the jump buffer in the error structure.

Parameters
_reductPointer to the reduct instance.
...The error message format string and any optional arguments.

Definition at line 183 of file error.h.

◆ REDUCT_ERROR_CHECK_TYPE

#define REDUCT_ERROR_CHECK_TYPE (   _reduct,
  _name,
  _handle,
  _expected 
)
Value:
do \
{ \
REDUCT_ERROR_RUNTIME(_reduct, "%s expects %s, got %s", _name, _expected, \
} while (0)
#define REDUCT_HANDLE_GET_TYPE(_handle)
Get the type of the item referenced by the handle, or REDUCT_ITEM_TYPE_ATOM if not an item.
Definition handle.h:153
REDUCT_API const char * reduct_item_type_str(reduct_item_type_t type)
Get the string representation of an Reduct item type.
Definition item_impl.h:139

Report a type error for a handle.

Definition at line 188 of file error.h.

◆ REDUCT_ERROR_CHECK_LIST

#define REDUCT_ERROR_CHECK_LIST (   _reduct,
  _handle,
  _name 
)
Value:
do \
{ \
if (!REDUCT_HANDLE_IS_LIST(_handle)) \
{ \
REDUCT_ERROR_CHECK_TYPE(_reduct, _name, _handle, "a list"); \
} \
} while (0)
#define REDUCT_HANDLE_IS_LIST(_handle)
Check if a handle is a list.
Definition handle.h:187

Assert that a handle is a list.

Definition at line 198 of file error.h.

◆ REDUCT_ERROR_CHECK_CALLABLE

#define REDUCT_ERROR_CHECK_CALLABLE (   _reduct,
  _handle,
  _name 
)
Value:
do \
{ \
if (!REDUCT_HANDLE_IS_CALLABLE(_handle)) \
{ \
REDUCT_ERROR_CHECK_TYPE(_reduct, _name, _handle, "a callable"); \
} \
} while (0)
#define REDUCT_HANDLE_IS_CALLABLE(_handle)
Check if a handle is callable.
Definition handle.h:228

Assert that a handle is a callable.

Definition at line 210 of file error.h.

◆ REDUCT_ERROR_CHECK_SEQUENCE

#define REDUCT_ERROR_CHECK_SEQUENCE (   _reduct,
  _handle,
  _name 
)
Value:
do \
{ \
if (!REDUCT_HANDLE_IS_LIST(_handle) && !REDUCT_HANDLE_IS_ATOM(_handle)) \
{ \
REDUCT_ERROR_CHECK_TYPE(_reduct, _name, _handle, "a list or atom"); \
} \
} while (0)
#define REDUCT_HANDLE_IS_ATOM(_handle)
Check if a handle is an atom.
Definition handle.h:179

Assert that a handle is a sequence (list or atom).

Definition at line 222 of file error.h.

Enumeration Type Documentation

◆ reduct_error_type_t

Error type enumeration.

Enumerator
REDUCT_ERROR_TYPE_NONE 
REDUCT_ERROR_TYPE_SYNTAX 
REDUCT_ERROR_TYPE_COMPILE 
REDUCT_ERROR_TYPE_RUNTIME 
REDUCT_ERROR_TYPE_INTERNAL 

Definition at line 23 of file error.h.

Function Documentation

◆ reduct_error_print()

REDUCT_API void reduct_error_print ( reduct_error_t error,
reduct_file_t  file 
)

Format and print the error to a file.

Parameters
errorPointer to the error structure.
fileThe file to print to.

Definition at line 99 of file error_impl.h.

Here is the call graph for this function:

◆ reduct_error_get_row_column()

REDUCT_API void reduct_error_get_row_column ( reduct_error_t error,
reduct_size_t row,
reduct_size_t column 
)

Get the row and column by traversing the input buffer.

Parameters
errorPointer to the error structure.
rowPointer to the row variable.
columnPointer to the column variable.

Definition at line 153 of file error_impl.h.

Here is the caller graph for this function:

◆ reduct_error_set()

REDUCT_API void reduct_error_set ( reduct_error_t error,
const char *  path,
const char *  input,
reduct_size_t  inputLength,
reduct_size_t  regionLength,
reduct_size_t  position,
reduct_error_type_t  type,
const char *  message,
  ... 
)

Set the error information in the error structure.

Parameters
errorPointer to the error structure.
pathThe path to the file where the error occurred.
inputThe input buffer where the error occurred.
inputLengthThe total length of the input buffer.
regionLengthThe length of the token/region that caused the error.
positionThe position in the input buffer where the error occurred.
typeThe type of the error.
messageThe error message format string.
...The arguments for the format string.

Definition at line 181 of file error_impl.h.

Here is the caller graph for this function:

◆ reduct_error_get_item_params()

REDUCT_API void reduct_error_get_item_params ( struct reduct_item *  item,
const char **  path,
const char **  input,
reduct_size_t inputLength,
reduct_size_t regionLength,
reduct_size_t position 
)

Get the error parameters from a Reduct item.

Parameters
itemPointer to the item.
pathPointer to the path variable.
inputPointer to the input variable.
inputLengthPointer to the input length variable.
regionLengthPointer to the region length variable.
positionPointer to the position variable.

Definition at line 200 of file error_impl.h.

Here is the call graph for this function:

◆ reduct_error_throw_runtime()

REDUCT_API REDUCT_NORETURN void reduct_error_throw_runtime ( struct reduct *  reduct,
const char *  message,
  ... 
)

Throw a runtime error utilizing the evaluation state to determine the context.

Parameters
reductPointer to the Reduct instance.
messageThe error message format string.
...Additional arguments.

Definition at line 226 of file error_impl.h.

Here is the call graph for this function:

◆ reduct_error_check_arity()

REDUCT_API void reduct_error_check_arity ( struct reduct *  reduct,
reduct_size_t  argc,
reduct_size_t  expected,
const char *  name 
)

Check the arity of a native function call.

Here is the caller graph for this function:

◆ reduct_error_check_min_arity()

REDUCT_API void reduct_error_check_min_arity ( struct reduct *  reduct,
reduct_size_t  argc,
reduct_size_t  min,
const char *  name 
)

◆ reduct_error_check_arity_range()

REDUCT_API void reduct_error_check_arity_range ( struct reduct *  reduct,
reduct_size_t  argc,
reduct_size_t  min,
reduct_size_t  max,
const char *  name 
)
Here is the caller graph for this function: