1#ifndef REDUCT_ERROR_IMPL_H
2#define REDUCT_ERROR_IMPL_H 1
13 return "syntax error";
15 return "compile error";
17 return "runtime error";
19 return "internal error";
36 const char* current = ptr;
39 if (*current ==
'\\' && current + 1 < end)
54 else if (*current ==
')')
70 const char* current = ptr + 1;
73 if (*current ==
'\\' && current + 1 < end)
89 const char* current = ptr;
90 while (current < end && *current !=
' ' && *current !=
'\t' && *current !=
'\n' && *current !=
'\r' &&
91 *current !=
'(' && *current !=
')')
120 const char* lineStart = error->
input + error->
index;
121 while (lineStart > error->
input && *(lineStart - 1) !=
'\n')
126 const char* lineEnd = error->
input + error->
index;
127 while (lineEnd < error->input + error->
inputLength && *lineEnd !=
'\n' && *lineEnd !=
'\r')
133 REDUCT_FPRINTF(file,
" %4zu | %.*s\n", row, (
int)lineLen, lineStart);
169 if (error->
input[i] ==
'\n')
188 error->
input = input;
192 error->
index = position;
205 *path = item->input->path;
206 *input = item->input->buffer;
207 *inputLength = item->input->end - item->input->buffer;
209 if (*regionLength == 0)
214 *position = item->position;
234 if (reduct->evalState !=
REDUCT_NULL && reduct->evalState->frameCount > 0)
236 reduct_eval_frame_t* frame = &reduct->evalState->frames[reduct->evalState->frameCount - 1];
249 path = funcItem->
input->path;
250 input = funcItem->
input->buffer;
253 if (regionLength == 0)
#define REDUCT_VA_END(_ap)
#define REDUCT_UNLIKELY(_x)
reduct_bool_t
Boolean type.
#define REDUCT_FWRITE(_ptr, _size, _nmemb, _file)
#define REDUCT_CONTAINER_OF(_ptr, _type, _member)
Container of macro.
#define REDUCT_LONGJMP(_env, _val)
#define REDUCT_ASSERT(_cond)
#define REDUCT_VA_START(_ap, _last)
Error handling and reporting.
REDUCT_API void reduct_error_check_arity_range(reduct_t *reduct, reduct_size_t argc, reduct_size_t min, reduct_size_t max, const char *name)
REDUCT_API void reduct_error_check_arity(reduct_t *reduct, reduct_size_t argc, reduct_size_t expected, const char *name)
REDUCT_API void reduct_error_check_min_arity(reduct_t *reduct, reduct_size_t argc, reduct_size_t min, const char *name)
static const char * reduct_error_type_str(reduct_error_type_t type)
static reduct_size_t reduct_error_get_region_length(const char *ptr, const char *end)
Virtual machine evaluation.
REDUCT_API void reduct_error_print(reduct_error_t *error, reduct_file_t file)
Format and print the error to a file.
#define REDUCT_ERROR_RUNTIME(_reduct,...)
Throw a runtime error using the jump buffer in the error structure.
REDUCT_API 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_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.
#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.
char message[REDUCT_ERROR_MAX_LEN]
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.
Evaluation frame structure.
struct reduct_closure * closure
The closure being evaluated.
reduct_inst_t * ip
The current instruction pointer.
Compiled function structure.
reduct_inst_t * insts
An array of instructions.
reduct_uint32_t * positions
An array of source positions parallel to the instructions.
struct reduct_input * input
The parsed input that created this item.