Add error call stack if call stack exceeds maximum capacity
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Dominic Grimm 2023-08-05 20:19:52 +02:00
parent 411665061d
commit 7490439223
9 changed files with 138 additions and 102 deletions

View file

@ -17,10 +17,13 @@ struct hf__interpreter__word {
extern const hf__hashmap__free_value_t hf__interpreter__word_free;
#define HF__INTERPRETER__CALL_STACK_CAP_MAX 1024
struct hf__interpreter {
struct hf__node *call_stack;
size_t call_stack_len;
size_t call_stack_size;
size_t call_stack_cap;
size_t call_stack_cap_max;
struct hf__hashmap words; // struct hf__interpreter__word *
@ -41,7 +44,7 @@ extern const hf__interpreter__word_func_t
HF__INTERPRETER__WORD_FUNCTION[__HF__NODE_TYPE__N];
extern void hf__interpreter__stack_push(long **arr, size_t *const len,
size_t *const size, long item);
size_t *const cap, long item);
extern struct hf__result
hf__interpreter__run(struct hf__interpreter *const interpreter);

View file

@ -24,6 +24,6 @@ struct hf__token {
extern void hf__lex(const char *const src, const size_t src_len,
struct hf__token **tokens, size_t *const len,
size_t *const size);
size_t *const cap);
#endif

View file

@ -74,12 +74,12 @@ extern void hf__parser__init_keyword_map(struct hf__hashmap *const map,
size_t cap);
extern void hf__parser__node_array_push(struct hf__node **arr,
size_t *const len, size_t *const size,
size_t *const len, size_t *const cap,
struct hf__node item);
extern struct hf__result
hf__parse(struct hf__parser *const parser, const char *const src,
const struct hf__token *const tokens, const size_t tokens_len,
struct hf__node **nodes, size_t *const len, size_t *const size);
struct hf__node **nodes, size_t *const len, size_t *const cap);
#endif

View file

@ -9,6 +9,7 @@ enum hf__error {
HF__ERROR__PARSER__WORD_DEF_INVALID_NAME,
HF__ERROR__PARSER__WORD_DEF_IS_KEYWORD,
HF__ERROR__INTERPRETER__CALL_STACK_TOO_BIG,
HF__ERROR__INTERPRETER__UNKNOWN_WORD,
HF__ERROR__INTERPRETER__WORD_ALREADY_DEF,
HF__ERROR__INTERPRETER__STACK_UNDERFLOW,
@ -31,12 +32,27 @@ static const char *const HF__ERROR_STR[__HF__ERROR__N] = {
"Invalid token type for word name",
[HF__ERROR__PARSER__WORD_DEF_IS_KEYWORD] = "Word name is already a keyword",
[HF__ERROR__INTERPRETER__CALL_STACK_TOO_BIG] = "Call stack is too big",
[HF__ERROR__INTERPRETER__UNKNOWN_WORD] = "Unknown word",
[HF__ERROR__INTERPRETER__WORD_ALREADY_DEF] = "Word is already defined",
[HF__ERROR__INTERPRETER__STACK_UNDERFLOW] = "Stack underflow",
};
extern void hf__print_error(struct hf__error_wrapper *error);
static const bool HF__ERROR_PANIC[__HF__ERROR__N] = {
[HF__ERROR__PARSER__UNEXPECTED] = false,
[HF__ERROR__PARSER__INVALID_NUMBER] = false,
[HF__ERROR__PARSER__INVALID_CHAR] = false,
[HF__ERROR__PARSER__WORD_DEF_INCOMPLETE] = false,
[HF__ERROR__PARSER__WORD_DEF_INVALID_NAME] = false,
[HF__ERROR__PARSER__WORD_DEF_IS_KEYWORD] = false,
[HF__ERROR__INTERPRETER__CALL_STACK_TOO_BIG] = true,
[HF__ERROR__INTERPRETER__UNKNOWN_WORD] = false,
[HF__ERROR__INTERPRETER__WORD_ALREADY_DEF] = false,
[HF__ERROR__INTERPRETER__STACK_UNDERFLOW] = false,
};
extern void hf__handle_error_light(struct hf__error_wrapper *error);
struct hf__result {
bool ok;