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_cons(char *name, struct ao_lisp_cons *cons)
22 printf("\t\t%s(", name);
29 ao_lisp_poly_print(cons->car);
31 cons = ao_lisp_poly_cons(cons->cdr);
38 static void tabs(int indent)
45 ao_lisp_error_frame(int indent, char *name, struct ao_lisp_frame *frame)
52 for (f = 0; f < ao_lisp_frame_num(frame); f++) {
57 ao_lisp_poly_print(frame->vals[f].atom);
59 ao_lisp_poly_print(frame->vals[f].val);
63 ao_lisp_error_frame(indent + 1, "prev: ", ao_lisp_poly_frame(frame->prev));
69 static const char *state_names[] = {
80 ao_lisp_stack_print(void)
82 struct ao_lisp_stack *s;
83 printf("Value: "); ao_lisp_poly_print(ao_lisp_v); printf("\n");
85 for (s = ao_lisp_stack; s; s = ao_lisp_poly_stack(s->prev)) {
87 printf("\t\texpr: "); ao_lisp_poly_print(s->list); printf("\n");
88 printf("\t\tstate: %s\n", state_names[s->state]);
89 // printf("\t\tmacro: %s\n", s->macro ? "true" : "false");
90 ao_lisp_error_cons ("sexprs: ", ao_lisp_poly_cons(s->sexprs));
91 ao_lisp_error_cons ("values: ", ao_lisp_poly_cons(s->values));
92 ao_lisp_error_frame(2, "frame: ", ao_lisp_poly_frame(s->frame));
93 // ao_lisp_error_frame(2, "mframe: ", ao_lisp_poly_frame(s->macro_frame));
99 ao_lisp_error(int error, char *format, ...)
103 ao_lisp_exception |= error;
104 va_start(args, format);
105 vprintf(format, args);
108 ao_lisp_stack_print();
109 printf("Globals:\n\t");
110 ao_lisp_frame_print(ao_lisp_frame_poly(ao_lisp_frame_global));