aboutsummaryrefslogtreecommitdiffstats
path: root/src/bootstrap/errors.c
blob: 13a2f3c115f068499e4a163f19ae3f56a9f34f56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
typedef enum ErrorType {
    ERR_TYPE_LEXER,
    ERR_TYPE_PARSER,
    ERR_TYPE_RUNTIME,
} ErrorType;

typedef enum ErrorValue {
    ERR_UNKNOWN = 0,
    ERR_UNMATCHED_STRING,
    ERR_UNBALANCED_PAREN,
    ERR_NOT_IMPLEMENTED,
    ERR_EOF_REACHED,
    ERR_UNKNOWN_TOKEN,
    ERR_UNKNOWN_OBJ_TYPE,
    ERR_NOT_A_SYMBOL,
    ERR_SYMBOL_NOT_FOUND,
    ERR_OBJ_NOT_CALLABLE,
    ERR_NOT_ENOUGH_ARGS,
    ERR_WRONG_ARG_TYPE,
    ERR_DIVISION_BY_ZERO,
} ErrorValue;

typedef struct Error {
    ErrorType type;
    ErrorValue value;
    size_t line;
    size_t col;
} Error;

static const char* error_msgs[] = {
    [ERR_UNKNOWN] = "error: something unexpected happened",
    [ERR_UNMATCHED_STRING] = "error: unmatched string delimiter",
    [ERR_UNBALANCED_PAREN] = "error: unbalanced parentheses",
    [ERR_NOT_IMPLEMENTED] = "error: not implemented",
    [ERR_EOF_REACHED] = "error: EOF reached",
    [ERR_UNKNOWN_TOKEN] = "error: unknown token",
    [ERR_UNKNOWN_OBJ_TYPE] = "error: can't eval unknown object type",
    [ERR_NOT_A_SYMBOL] = "error: object is not a symbol",
    [ERR_SYMBOL_NOT_FOUND] = "error: symbol not found",
    [ERR_OBJ_NOT_CALLABLE] = "error: object is not callable",
    [ERR_NOT_ENOUGH_ARGS] = "error: not enough arguments",
    [ERR_WRONG_ARG_TYPE] = "error: wrong argument type",
    [ERR_DIVISION_BY_ZERO] = "error: division by zero",
};

#define ERR_MAX_NUMBER 16
static Error errors[ERR_MAX_NUMBER];
static size_t errors_n = 0;

void
error_push(Error error) {
    if (errors_n < ERR_MAX_NUMBER) {
        errors[errors_n++] = error;
    }
}