summaryrefslogtreecommitdiff
path: root/src/test/ao_lisp_test.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-10-31 16:43:44 -0700
committerKeith Packard <keithp@keithp.com>2016-11-17 22:18:39 -0800
commiteabd97e4b1a9d34416455b0fceb14a9a480c63a4 (patch)
tree57053a1ea332cfc8057f5b4a17ee977f77ae020b /src/test/ao_lisp_test.c
parentd46698a01ed4903d36635b34867bfc4bb8fbafc6 (diff)
Add first lisp bits
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/test/ao_lisp_test.c')
-rw-r--r--src/test/ao_lisp_test.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/test/ao_lisp_test.c b/src/test/ao_lisp_test.c
new file mode 100644
index 00000000..bbadfa75
--- /dev/null
+++ b/src/test/ao_lisp_test.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright © 2016 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+#include "ao_lisp.h"
+#include <stdio.h>
+
+static struct ao_lisp_cons *list;
+static char *string;
+
+int
+main (int argc, char **argv)
+{
+ int i, j;
+ struct ao_lisp_atom *atom;
+ ao_lisp_root_add(&ao_lisp_cons_type, (void **) &list);
+ ao_lisp_root_add(&ao_lisp_string_type, (void **) &string);
+
+ /* allocator test */
+ for (j = 0; j < 10; j++) {
+ list = 0;
+ string = ao_lisp_string_new(0);
+ for (i = 0; i < 7; i++) {
+ string = ao_lisp_string_cat(string, "a");
+ list = ao_lisp_cons(ao_lisp_string_poly(string), list);
+ list = ao_lisp_cons(ao_lisp_int_poly(i), list);
+ atom = ao_lisp_atom_intern("ant");
+ atom->val = ao_lisp_cons_poly(list);
+ list = ao_lisp_cons(ao_lisp_atom_poly(atom), list);
+ }
+ ao_lisp_poly_print(ao_lisp_cons_poly(list));
+ printf("\n");
+ }
+
+ atom = ao_lisp_atom_intern("ant");
+ atom->val = ao_lisp_string_poly(ao_lisp_string_cat("hello world", ""));
+
+ list = ao_lisp_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("plus")),
+ ao_lisp_cons(ao_lisp_cons_poly(ao_lisp_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("plus")),
+ ao_lisp_cons(ao_lisp_int_poly(3),
+ ao_lisp_cons(ao_lisp_int_poly(4), NULL)))),
+ ao_lisp_cons(ao_lisp_int_poly(2), NULL)));
+ printf("list: ");
+ ao_lisp_poly_print(ao_lisp_cons_poly(list));
+ printf ("\n");
+ ao_lisp_poly_print(ao_lisp_eval(ao_lisp_cons_poly(list)));
+ printf ("\n");
+}