altos: Add lambda support to lisp
[fw/altos] / src / test / ao_lisp_test.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 #include <stdio.h>
17
18 #if 0
19 static struct ao_lisp_cons      *list;
20 static char                     *string;
21 #endif
22
23 int
24 main (int argc, char **argv)
25 {
26 #if 0
27         int                     i, j;
28
29         struct ao_lisp_atom     *atom;
30         ao_lisp_root_add(&ao_lisp_cons_type, (void **) &list);
31         ao_lisp_root_add(&ao_lisp_string_type, (void **) &string);
32
33         /* allocator test */
34         for (j = 0; j < 10; j++) {
35                 list = 0;
36                 string = ao_lisp_string_new(0);
37                 for (i = 0; i < 2; i++) {
38                         string = ao_lisp_string_cat(string, "a");
39                         list = ao_lisp_cons_cons(ao_lisp_string_poly(string), list);
40                         list = ao_lisp_cons_cons(ao_lisp_int_poly(i), list);
41                         atom = ao_lisp_atom_intern("ant");
42                         list = ao_lisp_cons_cons(ao_lisp_atom_poly(atom), list);
43                 }
44                 ao_lisp_poly_print(ao_lisp_cons_poly(list));
45                 printf("\n");
46         }
47
48         for (atom = ao_lisp_poly_atom(ao_builtin_atoms); atom; atom = ao_lisp_poly_atom(atom->next)) {
49                 printf("%s = ", atom->name);
50                 ao_lisp_poly_print(ao_lisp_atom_get(ao_lisp_atom_poly(atom)));
51                 printf("\n");
52         }
53 #endif
54 #if 0
55         list = ao_lisp_cons_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("+")),
56                                  ao_lisp_cons_cons(ao_lisp_cons_poly(ao_lisp_cons_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("+")),
57                                                                                        ao_lisp_cons_cons(ao_lisp_int_poly(3),
58                                                                                                          ao_lisp_cons_cons(ao_lisp_int_poly(4), NULL)))),
59                                                    ao_lisp_cons_cons(ao_lisp_int_poly(2), NULL)));
60         printf("list: ");
61         ao_lisp_poly_print(ao_lisp_cons_poly(list));
62         printf ("\n");
63         ao_lisp_poly_print(ao_lisp_eval(ao_lisp_cons_poly(list)));
64         printf ("\n");
65 #endif
66 #if 1
67         ao_lisp_read_eval_print();
68 #endif
69 }