-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathhh_error.c
73 lines (62 loc) · 1.55 KB
/
hh_error.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* This file is part of Hedgehog LISP.
* Copyright (C) 2003, 2004, 2005 Oliotalo Ltd.
* See file LICENSE.LGPL for pertinent licensing conditions.
*
* Author: Kenneth Oksanen <[email protected]>
*/
#include "hh_common.h"
#include "hh_error.h"
#include "hh_interp.h"
#include "hh_data.h"
#include "hh_printf.h"
unsigned char hh_error_kind[HH_N_ERRORS] = {
0, /* HH_OK */
#define ERROR(code, kind, description_string) \
kind,
#include "hh_error.def"
};
char *hh_error_string[HH_N_ERRORS] = {
"OK", /* HH_OK */
#define ERROR(code, kind, description_string) \
description_string,
#include "hh_error.def"
};
void hh_error_print(hh_error_t error, void *aux_info)
{
char *s;
switch (hh_error_kind[error]) {
case HH_SYSTEM_WARNING:
s = "System warning";
break;
case HH_PROGRAM_WARNING:
s = "Program warning";
break;
case HH_SYSTEM_FATAL:
s = "Fatal system error";
break;
case HH_PROGRAM_FATAL:
s = "Fatal program error";
break;
default:
s = "Unknown error";
break;
}
HH_PRINT("%s #%d: %s", s, (int) error, hh_error_string[error]);
#ifndef HH_SMALL
if (aux_info == NULL)
return;
if (hh_error_kind[error] == HH_PROGRAM_FATAL
|| hh_error_kind[error] == HH_PROGRAM_WARNING) {
hh_context_t *ctx = (hh_context_t *) aux_info;
if (ctx->offending_value != 0) {
HH_PRINT(", got ");
hh_lisp_print_interpreter(ctx, ctx->offending_value, -1);
}
HH_PRINT(". pc = %06d, sp = %d.\n",
ctx->pc - (ctx->program + 12),
ctx->sp - ctx->stack);
}
#else
HH_PRINT(".\n");
#endif
}