Add first lisp bits
[fw/altos] / src / lisp / ao_lisp_prim.c
1 /*
2  * Copyright © 2016 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 ao_lisp_poly
18 ao_lisp_poly_print(ao_lisp_poly p)
19 {
20         switch (ao_lisp_poly_type(p)) {
21         case AO_LISP_CONS:
22                 ao_lisp_cons_print(ao_lisp_poly_cons(p));
23                 break;
24         case AO_LISP_STRING:
25                 ao_lisp_string_print(ao_lisp_poly_string(p));
26                 break;
27         case AO_LISP_INT:
28                 ao_lisp_int_print(ao_lisp_poly_int(p));
29                 break;
30         case AO_LISP_ATOM:
31                 ao_lisp_atom_print(ao_lisp_poly_atom(p));
32                 break;
33         case AO_LISP_BUILTIN:
34                 ao_lisp_builtin_print(ao_lisp_poly_builtin(p));
35                 break;
36         }
37         return AO_LISP_NIL;
38 }
39
40 void
41 ao_lisp_poly_mark(ao_lisp_poly p)
42 {
43         switch (ao_lisp_poly_type(p)) {
44         case AO_LISP_CONS:
45                 ao_lisp_mark(&ao_lisp_cons_type, ao_lisp_poly_cons(p));
46                 break;
47         case AO_LISP_STRING:
48                 ao_lisp_mark(&ao_lisp_string_type, ao_lisp_poly_string(p));
49                 break;
50         case AO_LISP_ATOM:
51                 ao_lisp_mark(&ao_lisp_atom_type, ao_lisp_poly_atom(p));
52                 break;
53         }
54 }
55
56 ao_lisp_poly
57 ao_lisp_poly_move(ao_lisp_poly p)
58 {
59         switch (ao_lisp_poly_type(p)) {
60         case AO_LISP_CONS:
61                 p = ao_lisp_cons_poly(ao_lisp_move(&ao_lisp_cons_type, ao_lisp_poly_cons(p)));
62                 break;
63         case AO_LISP_STRING:
64                 p = ao_lisp_string_poly(ao_lisp_move(&ao_lisp_string_type, ao_lisp_poly_string(p)));
65                 break;
66         case AO_LISP_ATOM:
67                 p = ao_lisp_atom_poly(ao_lisp_move(&ao_lisp_atom_type, ao_lisp_poly_atom(p)));
68                 break;
69         }
70         return p;
71 }