~qpfiffer/lair

57ba725136b7161e2f06b4a0e319cb51e6273372 — Quinlan Pfiffer 12 days ago db88921 syntax_update_2023
Assert works!
4 files changed, 7 insertions(+), 3 deletions(-)

M include/error.h
M src/error.c
M src/lair_std.c
M src/parse.c
M include/error.h => include/error.h +1 -0
@@ 6,6 6,7 @@ struct _lair_runtime;
typedef enum {
	ERR_PARSE,
	ERR_SYNTAX,
	ERR_ASSERT,
	ERR_RUNTIME
} ERROR_TYPE;


M src/error.c => src/error.c +1 -0
@@ 11,6 11,7 @@
static inline const char *_friendly_err(const ERROR_TYPE err) {
	switch (err) {
		case ERR_PARSE:			return "ERR_PARSE";
		case ERR_ASSERT:		return "ERR_ASSERT";
		case ERR_RUNTIME:		return "ERR_RUNTIME";
		case ERR_SYNTAX:		return "ERR_SYNTAX";
		default:				return "ERROR";

M src/lair_std.c => src/lair_std.c +2 -2
@@ 207,8 207,8 @@ const struct _lair_type *_lair_builtin_str(LAIR_FUNCTION_SIG) {

const struct _lair_type *_lair_builtin_assert(LAIR_FUNCTION_SIG) {
	check(r, argc == 1, ERR_RUNTIME, "Incorrect number of arguments to 'assert' function.");
	_lair_builtin_print(r, argc, argv);
	printf("\n");
	if (argv[0] != _lair_canonical_true())
		throw_exception(r, ERR_ASSERT, "Assertion failed.");

	return NULL;
}

M src/parse.c => src/parse.c +3 -1
@@ 141,7 141,7 @@ static int _is_valid_string(const char *stripped, const size_t stripped_len) {
}

static int _is_operator(const char *stripped, const size_t stripped_len) {
	if (stripped_len != 0)
	if (stripped_len != 1)
		return 0;

	switch (stripped[0]) {


@@ 190,6 190,8 @@ void _intuit_token_type(
			new_token->token_type = LR_RETURN;
		else if (stripped[0] == '?')
			new_token->token_type = LR_IF;
		else if (stripped[0] == '!')
			new_token->token_type = LR_INVERT;
		else if (_is_operator(stripped, stripped_len))
			new_token->token_type = LR_OPERATOR;
		else if (_is_valid_string(stripped, stripped_len))