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.
15 #include "ao_scheme.h"
19 ao_scheme_error_poly(char *name, ao_poly poly, ao_poly last)
22 printf("\t\t%s(", name);
23 if (ao_scheme_poly_type(poly) == AO_SCHEME_CONS) {
26 struct ao_scheme_cons *cons = ao_scheme_poly_cons(poly);
31 ao_scheme_poly_write(cons->car);
41 ao_scheme_poly_write(poly);
46 static void tabs(int indent)
53 ao_scheme_error_frame(int indent, char *name, struct ao_scheme_frame *frame)
60 struct ao_scheme_frame_vals *vals = ao_scheme_poly_frame_vals(frame->vals);
61 if (frame->type & AO_SCHEME_FRAME_PRINT)
64 frame->type |= AO_SCHEME_FRAME_PRINT;
65 for (f = 0; f < frame->num; f++) {
70 ao_scheme_poly_write(vals->vals[f].atom);
72 ao_scheme_poly_write(vals->vals[f].val);
76 ao_scheme_error_frame(indent + 1, "prev: ", ao_scheme_poly_frame(frame->prev));
77 frame->type &= ~AO_SCHEME_FRAME_PRINT;
86 ao_scheme_vprintf(char *format, va_list args)
90 while ((c = *format++) != '\0') {
92 switch (c = *format++) {
94 ao_scheme_poly_write((ao_poly) va_arg(args, unsigned int));
97 printf("%p", va_arg(args, void *));
100 printf("%d", va_arg(args, int));
103 printf("%s", va_arg(args, char *));
115 ao_scheme_printf(char *format, ...)
118 va_start(args, format);
119 ao_scheme_vprintf(format, args);
124 ao_scheme_error(int error, char *format, ...)
128 ao_scheme_exception |= error;
129 va_start(args, format);
130 ao_scheme_vprintf(format, args);
133 ao_scheme_printf("Value: %v\n", ao_scheme_v);
134 ao_scheme_printf("Frame: %v\n", ao_scheme_frame_poly(ao_scheme_frame_current));
136 ao_scheme_stack_write(ao_scheme_stack_poly(ao_scheme_stack));
137 ao_scheme_printf("Globals: %v\n", ao_scheme_frame_poly(ao_scheme_frame_global));
138 return AO_SCHEME_NIL;