2 * Copyright © 2016 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
19 ao_lisp_error_poly(char *name, ao_poly poly)
22 printf("\t\t%s(", name);
23 if (ao_lisp_poly_type(poly) == AO_LISP_CONS) {
24 struct ao_lisp_cons *cons = ao_lisp_poly_cons(poly);
32 ao_lisp_poly_print(cons->car);
34 cons = ao_lisp_poly_cons(cons->cdr);
40 ao_lisp_poly_print(poly);
45 static void tabs(int indent)
52 ao_lisp_error_frame(int indent, char *name, struct ao_lisp_frame *frame)
59 for (f = 0; f < ao_lisp_frame_num(frame); f++) {
64 ao_lisp_poly_print(frame->vals[f].atom);
66 ao_lisp_poly_print(frame->vals[f].val);
70 ao_lisp_error_frame(indent + 1, "prev: ", ao_lisp_poly_frame(frame->prev));
76 static const char *state_names[] = {
87 ao_lisp_stack_print(void)
89 struct ao_lisp_stack *s;
90 printf("Value: "); ao_lisp_poly_print(ao_lisp_v); printf("\n");
92 for (s = ao_lisp_stack; s; s = ao_lisp_poly_stack(s->prev)) {
94 printf("\t\texpr: "); ao_lisp_poly_print(s->list); printf("\n");
95 printf("\t\tstate: %s\n", state_names[s->state]);
96 // printf("\t\tmacro: %s\n", s->macro ? "true" : "false");
97 ao_lisp_error_poly ("sexprs: ", s->sexprs);
98 ao_lisp_error_poly ("values: ", s->values);
99 ao_lisp_error_frame(2, "frame: ", ao_lisp_poly_frame(s->frame));
100 // ao_lisp_error_frame(2, "mframe: ", ao_lisp_poly_frame(s->macro_frame));
106 ao_lisp_error(int error, char *format, ...)
110 ao_lisp_exception |= error;
111 va_start(args, format);
112 vprintf(format, args);
115 ao_lisp_stack_print();
116 printf("Globals:\n\t");
117 ao_lisp_frame_print(ao_lisp_frame_poly(ao_lisp_frame_global));