2#define REDUCT_ERROR_H 1
17#define REDUCT_ERROR_MAX_LEN 512
23typedef enum reduct_error_type
53#define REDUCT_ERROR() ((reduct_error_t){0})
115#define REDUCT_ERROR_CATCH(_error) (REDUCT_SETJMP((_error)->jmp))
125#define REDUCT_ERROR_THROW(_error, _item, _type, ...) \
128 const char* __path; \
129 const char* __input; \
130 reduct_size_t __input_length; \
131 reduct_size_t __region_length; \
132 reduct_size_t __position; \
133 reduct_error_get_item_params((_item), &__path, &__input, &__input_length, &__region_length, &__position); \
134 reduct_error_set((_error), __path, __input, __input_length, __region_length, __position, \
135 REDUCT_ERROR_TYPE_##_type, __VA_ARGS__); \
136 REDUCT_LONGJMP((_error)->jmp, REDUCT_TRUE); \
147#define REDUCT_ERROR_SYNTAX(_error, _input, _ptr, ...) \
150 reduct_error_set((_error), (_input)->path, (_input)->buffer, (_input)->end - (_input)->buffer, 1, \
151 (reduct_size_t)((_ptr) - (_input)->buffer), REDUCT_ERROR_TYPE_SYNTAX, __VA_ARGS__); \
152 REDUCT_LONGJMP((_error)->jmp, REDUCT_TRUE); \
162#define REDUCT_ERROR_COMPILE(_compiler, _item, ...) \
163 REDUCT_ERROR_THROW((_compiler)->reduct->error, \
164 (((_item) != REDUCT_NULL && (_item)->input != REDUCT_NULL) \
166 : ((_compiler)->lastItem != REDUCT_NULL ? (_compiler)->lastItem : (_item))), \
167 COMPILE, __VA_ARGS__)
175#define REDUCT_ERROR_RUNTIME(_reduct, ...) reduct_error_throw_runtime((_reduct), __VA_ARGS__)
183#define REDUCT_ERROR_INTERNAL(_reduct, ...) REDUCT_ERROR_THROW((_reduct)->error, REDUCT_NULL, INTERNAL, __VA_ARGS__)
188#define REDUCT_ERROR_CHECK_TYPE(_reduct, _name, _handle, _expected) \
191 REDUCT_ERROR_RUNTIME(_reduct, "%s expects %s, got %s", _name, _expected, \
192 reduct_item_type_str(REDUCT_HANDLE_GET_TYPE(_handle))); \
198#define REDUCT_ERROR_CHECK_LIST(_reduct, _handle, _name) \
201 if (!REDUCT_HANDLE_IS_LIST(_handle)) \
203 REDUCT_ERROR_CHECK_TYPE(_reduct, _name, _handle, "a list"); \
210#define REDUCT_ERROR_CHECK_CALLABLE(_reduct, _handle, _name) \
213 if (!REDUCT_HANDLE_IS_CALLABLE(_handle)) \
215 REDUCT_ERROR_CHECK_TYPE(_reduct, _name, _handle, "a callable"); \
222#define REDUCT_ERROR_CHECK_SEQUENCE(_reduct, _handle, _name) \
225 if (!REDUCT_HANDLE_IS_LIST(_handle) && !REDUCT_HANDLE_IS_ATOM(_handle)) \
227 REDUCT_ERROR_CHECK_TYPE(_reduct, _name, _handle, "a list or atom"); \
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_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 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_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 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_error_type_t
Error type enumeration.
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)
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_check_min_arity(struct reduct *reduct, reduct_size_t argc, reduct_size_t min, const char *name)
#define REDUCT_ERROR_MAX_LEN
Maximum length of an error string.
@ REDUCT_ERROR_TYPE_SYNTAX
@ REDUCT_ERROR_TYPE_RUNTIME
@ REDUCT_ERROR_TYPE_INTERNAL
@ REDUCT_ERROR_TYPE_COMPILE
reduct_error_type_t type
The type of the error.
reduct_size_t index
The index of the region in the input buffer that caused the error.
const char * input
The input buffer.
const char * path
THe path to the file that caused the error.
reduct_size_t inputLength
The total length of the input buffer.
reduct_size_t regionLength
The length of the region that caused the error.