~brenns10/funlisp

229b9e57ba7bbc02d3f435bdd3326f58f2d6e958 — Stephen Brennan 1 year, 5 months ago 9c51536
Rename errno to err_num
5 files changed, 23 insertions(+), 23 deletions(-)

M inc/funlisp.h
M src/builtins.c
M src/funlisp_internal.h
M src/parse.c
M src/util.c
M inc/funlisp.h => inc/funlisp.h +2 -2
@@ 894,11 894,11 @@ extern const char *lisp_error_name[LE_MAX_ERR];
 * @endcode
 *
 * @param rt runtime
 * @param errno error number, for easy programatic acccess
 * @param err_num error number, for easy programatic acccess
 * @param message message to show the user
 * @return NULL
 */
lisp_value *lisp_error(lisp_runtime *rt, enum lisp_errno errno, char *message);
lisp_value *lisp_error(lisp_runtime *rt, enum lisp_errno err_num, char *message);

/**
 * Dump the execution stack to a file. This is useful if you want to print a

M src/builtins.c => src/builtins.c +5 -5
@@ 619,7 619,7 @@ static lisp_value *lisp_builtin_assert_error(
	/* args are NOT evaluated, to avoid error handling short circuit */
	lisp_value *sym, *expr;
	lisp_symbol *sym_evald;
	enum lisp_errno errno;
	enum lisp_errno err_num;
	(void) user;

	if (!lisp_get_args(rt, arglist, "**", &sym, &expr))


@@ 629,19 629,19 @@ static lisp_value *lisp_builtin_assert_error(
	lisp_error_check(sym_evald);
	if (sym_evald->type != type_symbol)
		return lisp_error(rt, LE_TYPE, "error type must be symbol");
	errno = lisp_sym_to_errno(sym_evald);
	if (errno == LE_MAX_ERR)
	err_num = lisp_sym_to_errno(sym_evald);
	if (err_num == LE_MAX_ERR)
		return lisp_error(rt, LE_VALUE, "unrecognized error type");

	lisp_eval(rt, scope, expr); /* we don't care, cause we expect error */
	/* NO ERROR CHECK HERE */

	if (errno == lisp_get_errno(rt)) {
	if (err_num == lisp_get_errno(rt)) {
		lisp_clear_error(rt);
		return (lisp_value*) sym_evald;
	} else {
		fprintf(stderr, "Assertion error! Expected %s\n",
			lisp_error_name[errno]);
			lisp_error_name[err_num]);
		fprintf(stderr, "This was the actual error encountered: ");
		lisp_print_error(rt, stderr);
		fprintf(stderr, "\nBelow should be the assertion error stack trace.\n");

M src/funlisp_internal.h => src/funlisp_internal.h +4 -4
@@ 64,15 64,15 @@ struct lisp_runtime {
	/* Data we use for reporting errors. This is very single-threaded of me,
	 * but it works for now.
	 * REQUIREMENTS:
	 *   - error and errno must both always be non-NULL and non-0
	 *   - error and err_num must both always be non-NULL and non-0
	 *     respectively when an error occurs
	 *   - error_line and error_stack may optionally be set
	 * You can use lisp_error() to set error, errno, and error_stack.
	 * Parsing functions typically use a macro to set error, errno, and
	 * You can use lisp_error() to set error, err_num, and error_stack.
	 * Parsing functions typically use a macro to set error, err_num, and
	 * error_line.
	 */
	char *error;
	enum lisp_errno errno;
	enum lisp_errno err_num;
	unsigned int error_line;
	lisp_list *error_stack;


M src/parse.c => src/parse.c +2 -2
@@ 327,7 327,7 @@ int lisp_parse_value(lisp_runtime *rt, char *input, int index, lisp_value **outp
	result r = lisp_parse_value_internal(rt, input, index);
	bytes = r.index - index;
	if (r.error) {
		rt->errno = r.error;
		rt->err_num = r.error;
		set_error_lineno(rt, input, r.index);
		bytes = -1;
	}


@@ 391,7 391,7 @@ lisp_value *lisp_parse_progn_f(lisp_runtime *rt, FILE *input)
	input_string = read_file(input);
	if (!input_string) {
		rt->error = "error reading from input file";
		rt->errno = LE_FERROR;
		rt->err_num = LE_FERROR;
		return NULL;
	}
	result = lisp_parse_progn(rt, input_string);

M src/util.c => src/util.c +10 -10
@@ 182,7 182,7 @@ int lisp_get_args(lisp_runtime *rt, lisp_list *list, char *format, ...)
		type = lisp_get_type(*format);
		if (type != NULL && type != list->left->type) {
			rt->error = "incorrect argument type";
			rt->errno = LE_TYPE;
			rt->err_num = LE_TYPE;
			return 0;
		}
		*v = list->left;


@@ 191,11 191,11 @@ int lisp_get_args(lisp_runtime *rt, lisp_list *list, char *format, ...)
	}
	if (*format != '\0') {
		rt->error = "not enough arguments";
		rt->errno = LE_2FEW;
		rt->err_num = LE_2FEW;
		return 0;
	} else if(!lisp_nil_p((lisp_value*)list)) {
		rt->error = "too many arguments";
		rt->errno = LE_2MANY;
		rt->err_num = LE_2MANY;
		return 0;
	}
	return 1;


@@ 386,10 386,10 @@ void lisp_dump_stack(lisp_runtime *rt, lisp_list *stack, FILE *file)
	}
}

lisp_value *lisp_error(lisp_runtime *rt, enum lisp_errno errno, char *message)
lisp_value *lisp_error(lisp_runtime *rt, enum lisp_errno err_num, char *message)
{
	rt->error = message;
	rt->errno = errno;
	rt->err_num = err_num;
	rt->error_stack = rt->stack;
	return NULL;
}


@@ 401,7 401,7 @@ char *lisp_get_error(lisp_runtime *rt)

enum lisp_errno lisp_get_errno(lisp_runtime *rt)
{
	return rt->errno;
	return rt->err_num;
}

void lisp_clear_error(lisp_runtime *rt)


@@ 409,7 409,7 @@ void lisp_clear_error(lisp_runtime *rt)
	rt->error = NULL;
	rt->error_stack = NULL;
	rt->error_line = 0;
	rt->errno = 0;
	rt->err_num = 0;
}

void lisp_print_error(lisp_runtime *rt, FILE *file)


@@ 423,12 423,12 @@ void lisp_print_error(lisp_runtime *rt, FILE *file)
	if (rt->error_line)
		fprintf(file, "at line %d: ", rt->error_line);

	if (rt->errno == LE_ERRNO) {
	if (rt->err_num == LE_ERRNO) {
		errmsg = strerror(get_errno());
		fprintf(file, "Error %s: %s\nSystem error: %s\n",
			lisp_error_name[rt->errno], rt->error, errmsg);
			lisp_error_name[rt->err_num], rt->error, errmsg);
	} else {
		fprintf(file, "Error %s: %s\n", lisp_error_name[rt->errno], rt->error);
		fprintf(file, "Error %s: %s\n", lisp_error_name[rt->err_num], rt->error);
	}

	if (rt->error_stack)