altos/lisp: Finish first pass through r7rs
[fw/altos] / src / lisp / ao_lisp_bool.c
1 /*
2  * Copyright © 2017 Keith Packard <keithp@keithp.com>
3  *
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.
8  *
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.
13  */
14
15 #include "ao_lisp.h"
16
17 static void bool_mark(void *addr)
18 {
19         (void) addr;
20 }
21
22 static int bool_size(void *addr)
23 {
24         (void) addr;
25         return sizeof (struct ao_lisp_bool);
26 }
27
28 static void bool_move(void *addr)
29 {
30         (void) addr;
31 }
32
33 const struct ao_lisp_type ao_lisp_bool_type = {
34         .mark = bool_mark,
35         .size = bool_size,
36         .move = bool_move,
37         .name = "bool"
38 };
39
40 void
41 ao_lisp_bool_write(ao_poly v)
42 {
43         struct ao_lisp_bool     *b = ao_lisp_poly_bool(v);
44
45         if (b->value)
46                 printf("#t");
47         else
48                 printf("#f");
49 }
50
51 #ifdef AO_LISP_MAKE_CONST
52
53 struct ao_lisp_bool     *ao_lisp_true, *ao_lisp_false;
54
55 struct ao_lisp_bool *
56 ao_lisp_bool_get(uint8_t value)
57 {
58         struct ao_lisp_bool     **b;
59
60         if (value)
61                 b = &ao_lisp_true;
62         else
63                 b = &ao_lisp_false;
64
65         if (!*b) {
66                 *b = ao_lisp_alloc(sizeof (struct ao_lisp_bool));
67                 (*b)->type = AO_LISP_BOOL;
68                 (*b)->value = value;
69         }
70         return *b;
71 }
72
73 #endif