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 static void cons_mark(void *addr)
19 struct ao_lisp_cons *cons = addr;
22 ao_lisp_poly_mark(cons->car, 1);
23 cons = ao_lisp_poly_cons(cons->cdr);
26 if (ao_lisp_mark_memory(&ao_lisp_cons_type, cons))
31 static int cons_size(void *addr)
34 return sizeof (struct ao_lisp_cons);
37 static void cons_move(void *addr)
39 struct ao_lisp_cons *cons = addr;
45 struct ao_lisp_cons *cdr;
48 MDBG_MOVE("cons_move start %d (%d, %d)\n",
49 MDBG_OFFSET(cons), MDBG_OFFSET(ao_lisp_ref(cons->car)), MDBG_OFFSET(ao_lisp_ref(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(&ao_lisp_cons_type, (void **) &cdr);
55 if (cdr != ao_lisp_poly_cons(cons->cdr))
56 cons->cdr = ao_lisp_cons_poly(cdr);
57 MDBG_MOVE("cons_move end %d (%d, %d)\n",
58 MDBG_OFFSET(cons), MDBG_OFFSET(ao_lisp_ref(cons->car)), MDBG_OFFSET(ao_lisp_ref(cons->cdr)));
65 const struct ao_lisp_type ao_lisp_cons_type = {
72 struct ao_lisp_cons *ao_lisp_cons_free_list;
75 ao_lisp_cons_cons(ao_poly car, struct ao_lisp_cons *cdr)
77 struct ao_lisp_cons *cons;
79 if (ao_lisp_cons_free_list) {
80 cons = ao_lisp_cons_free_list;
81 ao_lisp_cons_free_list = ao_lisp_poly_cons(cons->cdr);
83 ao_lisp_poly_stash(0, car);
84 ao_lisp_cons_stash(0, cdr);
85 cons = ao_lisp_alloc(sizeof (struct ao_lisp_cons));
86 car = ao_lisp_poly_fetch(0);
87 cdr = ao_lisp_cons_fetch(0);
92 cons->cdr = ao_lisp_cons_poly(cdr);
97 ao_lisp_cons_free(struct ao_lisp_cons *cons)
100 ao_poly cdr = cons->cdr;
101 cons->cdr = ao_lisp_cons_poly(ao_lisp_cons_free_list);
102 ao_lisp_cons_free_list = cons;
103 cons = ao_lisp_poly_cons(cdr);
108 ao_lisp_cons_print(ao_poly c)
110 struct ao_lisp_cons *cons = ao_lisp_poly_cons(c);
116 ao_lisp_poly_print(cons->car);
117 cons = ao_lisp_poly_cons(cons->cdr);
124 ao_lisp_cons_patom(ao_poly c)
126 struct ao_lisp_cons *cons = ao_lisp_poly_cons(c);
129 ao_lisp_poly_patom(cons->car);
130 cons = ao_lisp_poly_cons(cons->cdr);
135 ao_lisp_cons_length(struct ao_lisp_cons *cons)
140 cons = ao_lisp_poly_cons(cons->cdr);