bbadfa755289ec35818a7992b421bf349ac70aa3
[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 static struct ao_lisp_cons      *list;
19 static char                     *string;
20
21 int
22 main (int argc, char **argv)
23 {
24         int     i, j;
25         struct ao_lisp_atom     *atom;
26         ao_lisp_root_add(&ao_lisp_cons_type, (void **) &list);
27         ao_lisp_root_add(&ao_lisp_string_type, (void **) &string);
28
29         /* allocator test */
30         for (j = 0; j < 10; j++) {
31                 list = 0;
32                 string = ao_lisp_string_new(0);
33                 for (i = 0; i < 7; i++) {
34                         string = ao_lisp_string_cat(string, "a");
35                         list = ao_lisp_cons(ao_lisp_string_poly(string), list);
36                         list = ao_lisp_cons(ao_lisp_int_poly(i), list);
37                         atom = ao_lisp_atom_intern("ant");
38                         atom->val = ao_lisp_cons_poly(list);
39                         list = ao_lisp_cons(ao_lisp_atom_poly(atom), list);
40                 }
41                 ao_lisp_poly_print(ao_lisp_cons_poly(list));
42                 printf("\n");
43         }
44
45         atom = ao_lisp_atom_intern("ant");
46         atom->val = ao_lisp_string_poly(ao_lisp_string_cat("hello world", ""));
47
48         list = ao_lisp_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("plus")),
49                             ao_lisp_cons(ao_lisp_cons_poly(ao_lisp_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("plus")),
50                                                                         ao_lisp_cons(ao_lisp_int_poly(3),
51                                                                                      ao_lisp_cons(ao_lisp_int_poly(4), NULL)))),
52                                          ao_lisp_cons(ao_lisp_int_poly(2), NULL)));
53         printf("list: ");
54         ao_lisp_poly_print(ao_lisp_cons_poly(list));
55         printf ("\n");
56         ao_lisp_poly_print(ao_lisp_eval(ao_lisp_cons_poly(list)));
57         printf ("\n");
58 }