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.
17 #define OFFSET(a) ((int) ((uint8_t *) (a) - ao_lisp_const))
19 static void cons_mark(void *addr)
21 struct ao_lisp_cons *cons = addr;
24 ao_lisp_poly_mark(cons->car, 1);
25 cons = ao_lisp_poly_cons(cons->cdr);
28 if (ao_lisp_mark_memory(cons, sizeof (struct ao_lisp_cons)))
33 static int cons_size(void *addr)
36 return sizeof (struct ao_lisp_cons);
39 static void cons_move(void *addr)
41 struct ao_lisp_cons *cons = addr;
47 struct ao_lisp_cons *cdr;
50 (void) ao_lisp_poly_move(&cons->car, 1);
51 cdr = ao_lisp_poly_cons(cons->cdr);
54 ret = ao_lisp_move_memory((void **) &cdr, sizeof (struct ao_lisp_cons));
55 if (cdr != ao_lisp_poly_cons(cons->cdr))
56 cons->cdr = ao_lisp_cons_poly(cdr);
63 const struct ao_lisp_type ao_lisp_cons_type = {
69 static ao_poly cons_car;
70 static struct ao_lisp_cons *cons_cdr;
74 ao_lisp_cons_cons(ao_poly car, struct ao_lisp_cons *cdr)
76 struct ao_lisp_cons *cons;
79 ao_lisp_root_add(&ao_lisp_cons_type, &cons_cdr);
80 ao_lisp_root_poly_add(&cons_car);
85 cons = ao_lisp_alloc(sizeof (struct ao_lisp_cons));
89 cons->cdr = ao_lisp_cons_poly(cons_cdr);
90 cons_car = AO_LISP_NIL;
96 ao_lisp_cons_print(ao_poly c)
98 struct ao_lisp_cons *cons = ao_lisp_poly_cons(c);
104 ao_lisp_poly_print(cons->car);
105 cons = ao_lisp_poly_cons(cons->cdr);
112 ao_lisp_cons_patom(ao_poly c)
114 struct ao_lisp_cons *cons = ao_lisp_poly_cons(c);
117 ao_lisp_poly_patom(cons->car);
118 cons = ao_lisp_poly_cons(cons->cdr);
123 ao_lisp_cons_length(struct ao_lisp_cons *cons)
128 cons = ao_lisp_poly_cons(cons->cdr);