From 5e9ac36a39450a9d529095ce5a8e7a34e54fd1d2 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Fri, 9 Dec 2022 21:22:50 +0100 Subject: [PATCH] Get rid of fatal errors and report allocation error directly --- src/apfl.h | 9 ++--- src/context.c | 61 ++++++++++++++++----------------- src/error.c | 11 ------ src/eval.c | 34 +++++++++--------- src/functional-test-runner.c | 5 ++- src/globals.c | 34 +++++++++--------- src/main.c | 9 +++-- webpage/playground/playground.c | 5 ++- 8 files changed, 75 insertions(+), 93 deletions(-) diff --git a/src/apfl.h b/src/apfl.h index ebca6ea..e52f4b6 100644 --- a/src/apfl.h +++ b/src/apfl.h @@ -234,9 +234,6 @@ bool apfl_error_as_string(struct apfl_error, struct apfl_allocator, struct apfl_ const char *apfl_error_as_const_string(struct apfl_error error); struct apfl_error apfl_error_simple(enum apfl_error_type); -bool apfl_error_is_fatal_type(enum apfl_error_type); - -#define APFL_ERROR_IS_FATAL(err) (apfl_error_is_fatal_type((err).type)) enum apfl_expr_type { APFL_EXPR_LIST, @@ -625,7 +622,7 @@ enum apfl_result { // sure what to return / how errors/exceptions should work. Maybe a // value + a backtrace? APFL_RESULT_ERR, - APFL_RESULT_ERR_FATAL, + APFL_RESULT_ERR_ALLOC, }; struct apfl_config { @@ -728,9 +725,9 @@ enum apfl_result apfl_call_protected(apfl_ctx, apfl_stackidx func, apfl_stackidx bool apfl_debug_print_val(apfl_ctx, apfl_stackidx, struct apfl_format_writer); // Raise an error with a value from the stack as the message. -APFL_NORETURN void apfl_raise_error_with_type(apfl_ctx, apfl_stackidx, enum apfl_result type); +APFL_NORETURN void apfl_raise_error(apfl_ctx, apfl_stackidx); // Raise an error with a constant string as the message. -APFL_NORETURN void apfl_raise_const_error(apfl_ctx, enum apfl_result type, const char *message); +APFL_NORETURN void apfl_raise_const_error(apfl_ctx, const char *message); // Raise a memory allocation error. APFL_NORETURN void apfl_raise_alloc_error(apfl_ctx); // Raise an error for invalid stack indices. diff --git a/src/context.c b/src/context.c index 99c304f..faac0c2 100644 --- a/src/context.c +++ b/src/context.c @@ -131,41 +131,40 @@ raise_error(apfl_ctx ctx, bool with_error_on_stack, enum apfl_result type) } APFL_NORETURN void -apfl_raise_error_with_type(apfl_ctx ctx, apfl_stackidx idx, enum apfl_result type) +apfl_raise_error(apfl_ctx ctx, apfl_stackidx idx) { bool ok = current_stack_move_to_top(ctx, idx); - raise_error(ctx, ok, type); + raise_error(ctx, ok, APFL_RESULT_ERR); } APFL_NORETURN void -apfl_raise_const_error(apfl_ctx ctx, enum apfl_result type, const char *message) +apfl_raise_const_error(apfl_ctx ctx, const char *message) { - raise_error(ctx, try_push_const_string(ctx, message), type); + raise_error(ctx, try_push_const_string(ctx, message), APFL_RESULT_ERR); } APFL_NORETURN void apfl_raise_alloc_error(apfl_ctx ctx) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR_FATAL, apfl_messages.could_not_alloc_mem); + raise_error(ctx, false, APFL_RESULT_ERR_ALLOC); } APFL_NORETURN void apfl_raise_invalid_stackidx(apfl_ctx ctx) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.invalid_stack_index); + apfl_raise_const_error(ctx, apfl_messages.invalid_stack_index); } APFL_NORETURN void apfl_raise_error_object(apfl_ctx ctx, struct apfl_error error) { - enum apfl_result errtype = APFL_RESULT_ERR; - if (apfl_error_is_fatal_type(error.type)) { - errtype = APFL_RESULT_ERR_FATAL; + if (error.type == APFL_ERR_MALLOC_FAILED) { + apfl_raise_alloc_error(ctx); } const char *const_str = apfl_error_as_const_string(error); if (const_str != NULL) { - apfl_raise_const_error(ctx, errtype, const_str); + apfl_raise_const_error(ctx, const_str); } struct apfl_string string; @@ -177,7 +176,7 @@ apfl_raise_error_object(apfl_ctx ctx, struct apfl_error error) apfl_raise_alloc_error(ctx); } - apfl_raise_error_with_type(ctx, -1, errtype); + apfl_raise_error(ctx, -1); } void @@ -1002,7 +1001,7 @@ apfl_list_append(apfl_ctx ctx, apfl_stackidx list_index, apfl_stackidx value_ind } if (list_val->type != VALUE_LIST) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_list); + apfl_raise_const_error(ctx, apfl_messages.not_a_list); } struct apfl_value value = apfl_stack_must_get(ctx, value_index); @@ -1031,14 +1030,14 @@ apfl_list_append_list(apfl_ctx ctx, apfl_stackidx dst_index, apfl_stackidx src_i } if (dst_val->type != VALUE_LIST) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_list); + apfl_raise_const_error(ctx, apfl_messages.not_a_list); } struct apfl_value src_val = apfl_stack_must_get(ctx, src_index); if (src_val.type != VALUE_LIST) { assert(apfl_stack_drop(ctx, src_index)); - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_list); + apfl_raise_const_error(ctx, apfl_messages.not_a_list); } if (!apfl_list_splice( @@ -1087,7 +1086,7 @@ apfl_dict_set( if (dict_value->type != VALUE_DICT) { assert(apfl_stack_drop_multi(ctx, 2, (apfl_stackidx[]){k_index, v_index})); - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_dict); + apfl_raise_const_error(ctx, apfl_messages.not_a_dict); } if (!apfl_dict_set_raw(&ctx->gc, &dict_value->dict, k, v)) { @@ -1132,10 +1131,10 @@ apfl_get_member_if_exists( case GET_ITEM_KEY_DOESNT_EXIST: return false; case GET_ITEM_NOT_A_CONTAINER: - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.value_is_not_a_container); + apfl_raise_const_error(ctx, apfl_messages.value_is_not_a_container); break; case GET_ITEM_WRONG_KEY_TYPE: - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.wrong_key_type); + apfl_raise_const_error(ctx, apfl_messages.wrong_key_type); break; } @@ -1150,7 +1149,7 @@ apfl_get_member( apfl_stackidx k_index ) { if (!apfl_get_member_if_exists(ctx, container_index, k_index)) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.key_doesnt_exist); + apfl_raise_const_error(ctx, apfl_messages.key_doesnt_exist); } } @@ -1163,11 +1162,11 @@ apfl_get_list_member_by_index( struct apfl_value list = apfl_stack_must_get(ctx, list_index); if (list.type != VALUE_LIST) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_list); + apfl_raise_const_error(ctx, apfl_messages.not_a_list); } if (index >= list.list->len) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.key_doesnt_exist); + apfl_raise_const_error(ctx, apfl_messages.key_doesnt_exist); } struct apfl_value *value = apfl_stack_push_placeholder(ctx); @@ -1191,11 +1190,11 @@ apfl_set_list_member_by_index( } if (list->type != VALUE_LIST) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_list); + apfl_raise_const_error(ctx, apfl_messages.not_a_list); } if (index_in_list >= list->list->len) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.key_doesnt_exist); + apfl_raise_const_error(ctx, apfl_messages.key_doesnt_exist); } struct apfl_value value = apfl_stack_must_get(ctx, value_index); @@ -1225,7 +1224,7 @@ apfl_len(apfl_ctx ctx, apfl_stackidx index) case VALUE_FUNC: case VALUE_CFUNC: case VALUE_USERDATA: - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.wrong_type); + apfl_raise_const_error(ctx, apfl_messages.wrong_type); return 0; case VALUE_STRING: return value.string->len; @@ -1271,7 +1270,7 @@ apfl_get_string(apfl_ctx ctx, apfl_stackidx index) { struct apfl_string_view sv; if (!get_string_view_of_value(&sv, apfl_stack_must_get(ctx, index))) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.wrong_type); + apfl_raise_const_error(ctx, apfl_messages.wrong_type); } return sv; } @@ -1318,7 +1317,7 @@ apfl_join_strings(apfl_ctx ctx, apfl_stackidx glue, apfl_stackidx parts) glue = -1; if (apfl_get_type(ctx, parts) != APFL_VALUE_LIST) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_list); + apfl_raise_const_error(ctx, apfl_messages.not_a_list); } size_t parts_len = apfl_len(ctx, parts); @@ -1406,7 +1405,7 @@ apfl_get_number(apfl_ctx ctx, apfl_stackidx index) if (value.type == VALUE_NUMBER) { return value.number; } - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.wrong_type); + apfl_raise_const_error(ctx, apfl_messages.wrong_type); } bool @@ -1437,9 +1436,9 @@ apfl_cmp(apfl_ctx ctx, apfl_stackidx _a, apfl_stackidx _b) case CMP_GT: return 1; case CMP_UNCOMPARABLE: - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.uncomparable); + apfl_raise_const_error(ctx, apfl_messages.uncomparable); case CMP_INCOMPATIBLE_TYPES: - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.incompatible_types); + apfl_raise_const_error(ctx, apfl_messages.incompatible_types); } assert(false); @@ -1500,7 +1499,7 @@ apfl_push_cfunc(apfl_ctx ctx, apfl_cfunc cfunc, size_t nslots) static APFL_NORETURN void raise_no_cfunc(apfl_ctx ctx) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_c_function); + apfl_raise_const_error(ctx, apfl_messages.not_a_c_function); } static struct cfunction * @@ -1532,7 +1531,7 @@ static struct apfl_value ** cfunc_getslotvar(apfl_ctx ctx, struct cfunction *cfunction, apfl_slotidx slot) { if (slot >= cfunction->slots_len) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.invalid_slotidx); + apfl_raise_const_error(ctx, apfl_messages.invalid_slotidx); } return &cfunction->slots[slot]; } @@ -1604,7 +1603,7 @@ void *apfl_get_userdata(apfl_ctx ctx, apfl_stackidx index) { struct apfl_value value = apfl_stack_must_pop(ctx, index); if (value.type != VALUE_USERDATA) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.wrong_type); + apfl_raise_const_error(ctx, apfl_messages.wrong_type); } return value.userdata; } diff --git a/src/error.c b/src/error.c index 875d7a1..ea84754 100644 --- a/src/error.c +++ b/src/error.c @@ -212,14 +212,3 @@ apfl_error_simple(enum apfl_error_type type) { return (struct apfl_error) { .type = type }; } - -bool -apfl_error_is_fatal_type(enum apfl_error_type type) -{ - switch (type) { - case APFL_ERR_MALLOC_FAILED: - return true; - default: - return false; - } -} diff --git a/src/eval.c b/src/eval.c index 134b5b4..1475eeb 100644 --- a/src/eval.c +++ b/src/eval.c @@ -33,7 +33,7 @@ stack_must_drop(apfl_ctx ctx, apfl_stackidx index) #define ABSTRACT_MUST_GET_ARG(get, ctx, i, ilist, arg) \ if (!get(i, ilist, arg)) { \ - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.corrupted_bytecode); \ + apfl_raise_const_error(ctx, apfl_messages.corrupted_bytecode); \ } static bool @@ -128,7 +128,7 @@ variable_get(apfl_ctx ctx, struct scopes scopes, struct apfl_string *name, bool return; } - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.variable_doesnt_exist); + apfl_raise_const_error(ctx, apfl_messages.variable_doesnt_exist); } static bool @@ -225,13 +225,13 @@ matcher_stack_top(apfl_ctx ctx, struct func_call_stack_entry *cse) { struct matcher_stack *matcher_stack = &cse->matcher_stack; if (matcher_stack->len == 0) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.corrupted_bytecode); + apfl_raise_const_error(ctx, apfl_messages.corrupted_bytecode); } struct matcher *matcher = matcher_stack->items[matcher_stack->len-1]; if (matcher == NULL) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.corrupted_bytecode); + apfl_raise_const_error(ctx, apfl_messages.corrupted_bytecode); } return matcher; @@ -242,7 +242,7 @@ matcher_stack_drop(apfl_ctx ctx, struct func_call_stack_entry *cse) { struct matcher_stack *matcher_stack = &cse->matcher_stack; if (matcher_stack->len == 0) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.corrupted_bytecode); + apfl_raise_const_error(ctx, apfl_messages.corrupted_bytecode); } assert( @@ -298,11 +298,11 @@ func_add_subfunc(apfl_ctx ctx, struct func_call_stack_entry *cse, struct instruc struct apfl_value value = apfl_stack_must_get(ctx, -1); if (value.type != VALUE_FUNC) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.corrupted_bytecode); + apfl_raise_const_error(ctx, apfl_messages.corrupted_bytecode); } if (!apfl_func_add_subfunc(value.func, body, matcher_stack_top(ctx, cse))) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.corrupted_bytecode); + apfl_raise_const_error(ctx, apfl_messages.corrupted_bytecode); } matcher_stack_drop(ctx, cse); @@ -437,10 +437,10 @@ call_inner(apfl_ctx ctx, size_t tmproots, apfl_stackidx func_index, apfl_stackid assert(apfl_stack_drop_multi(ctx, 2, (apfl_stackidx[]){func_index, args_index})); if (!VALUE_IS_A(func, APFL_VALUE_FUNC)) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_function); + apfl_raise_const_error(ctx, apfl_messages.not_a_function); } if (!VALUE_IS_A(args, APFL_VALUE_LIST)) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_list); + apfl_raise_const_error(ctx, apfl_messages.not_a_list); } switch (func.type) { @@ -515,7 +515,7 @@ matcher_set_val(apfl_ctx ctx, struct func_call_stack_entry *cse, size_t index) struct matcher *matcher = matcher_stack_top(ctx, cse); if (index >= matcher->instructions->value_count) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.corrupted_bytecode); + apfl_raise_const_error(ctx, apfl_messages.corrupted_bytecode); } matcher->values[index] = apfl_stack_must_pop(ctx, -1); @@ -541,7 +541,7 @@ evaluate(apfl_ctx ctx, struct func_call_stack_entry *cse) { if (cse->returning_from_matcher) { if (!cse->matcher_result) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.value_doesnt_match); + apfl_raise_const_error(ctx, apfl_messages.value_doesnt_match); } cse->returning_from_matcher = false; } @@ -695,7 +695,7 @@ matcher_state_push(apfl_ctx ctx, struct matcher_call_stack_entry *cse, struct ma APFL_NORETURN static void raise_invalid_matcher_state(apfl_ctx ctx) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.invalid_matcher_state); + apfl_raise_const_error(ctx, apfl_messages.invalid_matcher_state); } static void @@ -725,7 +725,7 @@ matcher_init_matching_inner(apfl_ctx ctx, struct matcher *matcher, struct scopes must_tmproot_add_value(ctx, value); if (matcher == NULL) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.corrupted_bytecode); + apfl_raise_const_error(ctx, apfl_messages.corrupted_bytecode); } size_t capture_count = matcher->instructions->capture_count; @@ -820,7 +820,7 @@ static void matcher_check_index(apfl_ctx ctx, size_t count, size_t index) { if (index >= count) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.corrupted_bytecode); + apfl_raise_const_error(ctx, apfl_messages.corrupted_bytecode); } } @@ -1036,7 +1036,7 @@ matcher_transfer(apfl_ctx ctx, struct matcher_call_stack_entry *cse) variable_get(ctx, cse->scopes, transfer.var, false); if (apfl_get_type(ctx, -1) != APFL_VALUE_DICT) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_dict); + apfl_raise_const_error(ctx, apfl_messages.not_a_dict); } @@ -1050,7 +1050,7 @@ matcher_transfer(apfl_ctx ctx, struct matcher_call_stack_entry *cse) apfl_stack_must_push(ctx, apfl_value_set_cow_flag(cse->matcher->values[value_index])); if (apfl_get_member_if_exists(ctx, -2, -1)) { if (apfl_get_type(ctx, -1) != APFL_VALUE_DICT) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.not_a_dict); + apfl_raise_const_error(ctx, apfl_messages.not_a_dict); } } else { apfl_dict_create(ctx); @@ -1312,7 +1312,7 @@ dispatch(apfl_ctx ctx, struct call_stack_entry *cse) } if (fd_cse->subfunc >= function->subfunctions_len) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.no_matching_subfunction); + apfl_raise_const_error(ctx, apfl_messages.no_matching_subfunction); } // matcher_init_matching consumes the value on the top of the stack, we need diff --git a/src/functional-test-runner.c b/src/functional-test-runner.c index 3f46a5b..b418965 100644 --- a/src/functional-test-runner.c +++ b/src/functional-test-runner.c @@ -175,9 +175,8 @@ runtest(const char *filename) fprintf(stderr, "Error occurred during evaluation.\n"); dump_stack_error(ctx, runner); return T_ERR; - case APFL_RESULT_ERR_FATAL: - fprintf(stderr, "Fatal error occurred during evaluation.\n"); - dump_stack_error(ctx, runner); + case APFL_RESULT_ERR_ALLOC: + fprintf(stderr, "Fatal: Could not allocate memory.\n"); return T_FATAL; } } diff --git a/src/globals.c b/src/globals.c index 01f7c02..ab5969e 100644 --- a/src/globals.c +++ b/src/globals.c @@ -8,11 +8,11 @@ #include "globals.h" #include "scope.h" -#define TRY_FORMAT(ctx, x) \ - do { \ - if (!(x)) { \ - apfl_raise_const_error((ctx), APFL_RESULT_ERR, apfl_messages.io_error); \ - } \ +#define TRY_FORMAT(ctx, x) \ + do { \ + if (!(x)) { \ + apfl_raise_const_error((ctx), apfl_messages.io_error); \ + } \ } while (0) static void @@ -29,7 +29,7 @@ impl_if(apfl_ctx ctx) size_t len = apfl_len(ctx, 0); if (len < 2) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, "if needs at least 2 arguments"); + apfl_raise_const_error(ctx, "if needs at least 2 arguments"); } size_t i = 0; @@ -66,7 +66,7 @@ impl_eq(apfl_ctx ctx) { size_t len = apfl_len(ctx, 0); if (len < 2) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, "== needs at least 2 arguments"); + apfl_raise_const_error(ctx, "== needs at least 2 arguments"); } for (size_t i = 0; i < len-1; i++) { @@ -87,7 +87,7 @@ impl_eq(apfl_ctx ctx) { \ size_t len = apfl_len(ctx, 0); \ if (len < 2) { \ - apfl_raise_const_error(ctx, APFL_RESULT_ERR, name " needs at least 2 arguments"); \ + apfl_raise_const_error(ctx, name " needs at least 2 arguments"); \ } \ \ for (size_t i = 0; i < len-1; i++) { \ @@ -121,7 +121,7 @@ IMPLEMENT_COMPARISON(impl_le, "<=", <=) { \ size_t len = apfl_len(ctx, 0); \ if (len < 1) { \ - apfl_raise_const_error(ctx, APFL_RESULT_ERR, name " needs at least 1 argument"); \ + apfl_raise_const_error(ctx, name " needs at least 1 argument"); \ } \ \ apfl_get_list_member_by_index(ctx, 0, 0); \ @@ -162,7 +162,7 @@ static apfl_number op_div(apfl_ctx ctx, apfl_number a, apfl_number b) { if (b == 0.0 || b == -0.0) { // apfl_number is a double, so there are technically two zeroes :/ - apfl_raise_const_error(ctx, APFL_RESULT_ERR, "Division by zero"); + apfl_raise_const_error(ctx, "Division by zero"); } return a / b; } @@ -181,7 +181,7 @@ impl_join(apfl_ctx ctx) { size_t len = apfl_len(ctx, 0); if (len != 2) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, "join expects exactly 2 arguments"); + apfl_raise_const_error(ctx, "join expects exactly 2 arguments"); } apfl_get_list_member_by_index(ctx, 0, 0); @@ -232,7 +232,7 @@ disasm(apfl_ctx ctx) apfl_drop(ctx, 0); struct apfl_value value = apfl_stack_must_get(ctx, -1); if (value.type != VALUE_FUNC) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, apfl_messages.wrong_type); + apfl_raise_const_error(ctx, apfl_messages.wrong_type); } struct function *func = value.func; @@ -257,7 +257,7 @@ require_exactly_one_arg(apfl_ctx ctx, const char *error) { size_t len = apfl_len(ctx, 0); if (len != 1) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, error); + apfl_raise_const_error(ctx, error); } apfl_get_list_member_by_index(ctx, 0, 0); @@ -326,16 +326,16 @@ impl_while(apfl_ctx ctx) { size_t argc = apfl_len(ctx, 0); if (argc != 2) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, "while needs 2 functions as arguments"); + apfl_raise_const_error(ctx, "while needs 2 functions as arguments"); } apfl_get_list_member_by_index(ctx, 0, 0); if (apfl_get_type(ctx, -1) != APFL_VALUE_FUNC) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, "while needs 2 functions as arguments"); + apfl_raise_const_error(ctx, "while needs 2 functions as arguments"); } apfl_get_list_member_by_index(ctx, 0, 1); if (apfl_get_type(ctx, -1) != APFL_VALUE_FUNC) { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, "while needs 2 functions as arguments"); + apfl_raise_const_error(ctx, "while needs 2 functions as arguments"); } apfl_drop(ctx, 0); @@ -370,7 +370,7 @@ impl_gc(apfl_ctx ctx) } else if (apfl_string_eq(sv, "collect")) { apfl_gc_full(&ctx->gc); } else { - apfl_raise_const_error(ctx, APFL_RESULT_ERR, "Unknown gc command"); + apfl_raise_const_error(ctx, "Unknown gc command"); } apfl_drop(ctx, -1); diff --git a/src/main.c b/src/main.c index 4620039..fb781e3 100644 --- a/src/main.c +++ b/src/main.c @@ -64,7 +64,7 @@ repl_tokenizer(struct apfl_allocator allocator, apfl_tokenizer_ptr tokenizer) err = apfl_tokenizer_get_error(tokenizer); apfl_error_print(err, stderr); - if (err.type == APFL_ERR_INPUT_ERROR || APFL_ERROR_IS_FATAL(err)) { + if (err.type == APFL_ERR_INPUT_ERROR || err.type == APFL_ERR_MALLOC_FAILED) { return 1; } break; @@ -91,7 +91,7 @@ repl_parser(struct apfl_allocator allocator, apfl_parser_ptr parser) err = apfl_parser_get_error(parser); apfl_error_print(err, stderr); - if (err.type == APFL_ERR_INPUT_ERROR || APFL_ERROR_IS_FATAL(err)) { + if (err.type == APFL_ERR_INPUT_ERROR || err.type == APFL_ERR_MALLOC_FAILED) { return 1; } break; @@ -180,9 +180,8 @@ repl_eval(void) dump_stack_error(ctx, runner); fprintf(stderr, "Error occurred during evaluation.\n"); break; - case APFL_RESULT_ERR_FATAL: - dump_stack_error(ctx, runner); - fprintf(stderr, "Fatal error occurred during evaluation.\n"); + case APFL_RESULT_ERR_ALLOC: + fprintf(stderr, "Fatal: Could not allocate memory.\n"); rv = 1; goto exit; } diff --git a/webpage/playground/playground.c b/webpage/playground/playground.c index d3513b0..b13d2aa 100644 --- a/webpage/playground/playground.c +++ b/webpage/playground/playground.c @@ -117,9 +117,8 @@ main(void) dump_stack_error(ctx, runner, w_err); assert(apfl_format_put_string(w_err, "Error occurred during evaluation.\n")); break; - case APFL_RESULT_ERR_FATAL: - dump_stack_error(ctx, runner, w_err); - assert(apfl_format_put_string(w_err, "Fatal error occurred during evaluation.\n")); + case APFL_RESULT_ERR_ALLOC: + assert(apfl_format_put_string(w_err, "Fatal: Could not allocate memory.\n")); rv = 1; goto exit; }