From 89457d91f0bb04ba3a9d59b8615bf1642723ee3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Fri, 6 Mar 2026 22:43:55 +0100 Subject: [PATCH] exceptions: make reader.d usable in the early env --- src/c/error.d | 6 ++++++ src/c/reader.d | 25 +++++++++++++++++++++---- src/h/object.h | 2 ++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/c/error.d b/src/c/error.d index 8c59ddeb2..ba2e2624e 100644 --- a/src/c/error.d +++ b/src/c/error.d @@ -95,6 +95,12 @@ ecl_exception_handler(cl_object o) case ECL_EX_STRM_UNREAD: FEunread_stream(arg1, arg2); break; + case ECL_EX_READ_BADELT: + FEreader_error("Found invalid character ~:C", arg1, 1, arg2); + break; + case ECL_EX_READ_VALUES: + FEerror("The readmacro ~S returned ~D values.", 2, arg1, arg2); + break; case ECL_EX_EOF: FEend_of_file(arg1); break; diff --git a/src/c/reader.d b/src/c/reader.d index cc58747f2..d5248b63d 100644 --- a/src/c/reader.d +++ b/src/c/reader.d @@ -26,6 +26,24 @@ #include #include +static void +_FEreader_invalid_character(cl_object in, cl_object ch) +{ + ecl_ferror3(ECL_EX_READ_BADELT, in, ch); +} + +static void +_FEreader_too_many_values(cl_object x, cl_object n) +{ + ecl_ferror3(ECL_EX_READ_VALUES, x, n); +} + +static void +_FEend_of_file(cl_object in) +{ + ecl_ferror2(ECL_EX_EOF, in); +} + int ecl_readtable_get(cl_object readtable, int c, cl_object *macro, cl_object *table) { @@ -314,7 +332,7 @@ ecl_read_token(cl_object rtbl, cl_object in, int flags) break; } unlikely_if (ecl_invalid_character_p(c) && !suppress) { - FEreader_error("Found invalid character ~:C", in, 1, ECL_CODE_CHAR(c)); + _FEreader_invalid_character(in, ECL_CODE_CHAR(c)); } if (read_case != ecl_case_preserve) { if (ecl_upper_case_p(c)) { @@ -369,7 +387,7 @@ ecl_read_object_with_delimiter(cl_object rtbl, cl_object in, int delimiter, int return OBJNULL; } if (c == EOF) - FEend_of_file(in); + _FEend_of_file(in); a = ecl_readtable_get(rtbl, c, &x, NULL); } while (a == cat_whitespace); if ((a == cat_terminating || a == cat_non_terminating)) { @@ -380,8 +398,7 @@ ecl_read_object_with_delimiter(cl_object rtbl, cl_object in, int delimiter, int goto BEGIN; } unlikely_if (the_env->nvalues > 1) { - FEerror("The readmacro ~S returned ~D values.", - 2, x, ecl_make_fixnum(the_env->nvalues)); + _FEreader_too_many_values(x, ecl_make_fixnum(the_env->nvalues)); } return o; } diff --git a/src/h/object.h b/src/h/object.h index 58e5b0940..c6f58e442 100644 --- a/src/h/object.h +++ b/src/h/object.h @@ -976,6 +976,8 @@ typedef enum { ECL_EX_STRM_BADELT, /* invalid stream element type */ ECL_EX_STRM_CLOSED, /* the stream is closed */ ECL_EX_STRM_UNREAD, /* error while unreading into the stream */ + ECL_EX_READ_BADELT, /* invalid character when reading a token */ + ECL_EX_READ_VALUES, /* character macro returned too many values */ /* Kludges for the bytecodes VM */ ECL_EX_VM_BADARG_EXCD, ECL_EX_VM_BADARG_UNKK,