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

@ -107,7 +107,8 @@ struct hf__result shell(const struct arguments *const arguments) {
struct hf__interpreter interpreter = {
.call_stack = malloc(sizeof(struct hf__node) * 10),
.call_stack_len = 0,
.call_stack_size = 10,
.call_stack_cap = 10,
.call_stack_cap_max = HF__INTERPRETER__CALL_STACK_CAP_MAX,
.words =
{
@ -148,7 +149,7 @@ struct hf__result shell(const struct arguments *const arguments) {
free(tokens);
free(input);
if (!parse_res.ok) {
hf__print_error(&parse_res.error);
hf__handle_error_light(&parse_res.error);
putchar('\n');
continue;
}
@ -156,7 +157,7 @@ struct hf__result shell(const struct arguments *const arguments) {
for (size_t i = nodes_len - 1; i != 0 - 1; i--) {
hf__parser__node_array_push(&interpreter.call_stack,
&interpreter.call_stack_len,
&interpreter.call_stack_size, nodes[i]);
&interpreter.call_stack_cap, nodes[i]);
}
free(nodes);
@ -166,7 +167,7 @@ struct hf__result shell(const struct arguments *const arguments) {
while (interpreter.call_stack_len != 0 && interpreter.is_running) {
struct hf__result res = hf__interpreter__run(&interpreter);
if (!res.ok) {
hf__print_error(&res.error);
hf__handle_error_light(&res.error);
putchar('\n');
}
}
@ -229,7 +230,7 @@ int main(int argc, char *argv[]) {
}
if (!res.ok) {
hf__print_error(&res.error);
hf__handle_error_light(&res.error);
putchar('\n');
return 1;
}
@ -256,7 +257,8 @@ int main(int argc, char *argv[]) {
struct hf__interpreter interpreter = {
.call_stack = malloc(sizeof(struct hf__node) * 10),
.call_stack_len = 0,
.call_stack_size = 10,
.call_stack_cap = 10,
.call_stack_cap_max = HF__INTERPRETER__CALL_STACK_CAP_MAX,
.words =
{
@ -283,7 +285,7 @@ int main(int argc, char *argv[]) {
struct hf__result parse_res = hf__parse(&parser, src, tokens, tokens_len,
&nodes, &nodes_len, &nodes_size);
if (!parse_res.ok) {
hf__print_error(&parse_res.error);
hf__handle_error_light(&parse_res.error);
putchar('\n');
return 1;
}
@ -293,7 +295,7 @@ int main(int argc, char *argv[]) {
for (size_t i = nodes_len - 1; i != 0 - 1; i--) {
hf__parser__node_array_push(&interpreter.call_stack,
&interpreter.call_stack_len,
&interpreter.call_stack_size, nodes[i]);
&interpreter.call_stack_cap, nodes[i]);
}
free(nodes);
@ -301,7 +303,7 @@ int main(int argc, char *argv[]) {
while (interpreter.call_stack_len != 0 && interpreter.is_running) {
struct hf__result res = hf__interpreter__run(&interpreter);
if (!res.ok) {
hf__print_error(&res.error);
hf__handle_error_light(&res.error);
putchar('\n');
if (arguments.debug) {