X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Ftest%2Fao_lisp_test.c;h=41dae07aabf3d9155d331c63125d40e8961f245e;hb=8f2d60b4c029bffaa559bd1f31f5b15230dfa674;hp=8bc677daa5a54e947f4c86c69caa704e0f4f949d;hpb=77db0e8162cd01c2b42737b3d71b38cea942484f;p=fw%2Faltos diff --git a/src/test/ao_lisp_test.c b/src/test/ao_lisp_test.c index 8bc677da..41dae07a 100644 --- a/src/test/ao_lisp_test.c +++ b/src/test/ao_lisp_test.c @@ -15,55 +15,72 @@ #include "ao_lisp.h" #include -#if 0 -static struct ao_lisp_cons *list; -static char *string; -#endif +static FILE *ao_lisp_file; +static int newline = 1; + +static char save_file[] = "lisp.image"; int -main (int argc, char **argv) +ao_lisp_os_save(void) { -#if 0 - int i, j; + FILE *save = fopen(save_file, "w"); - 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); + if (!save) { + perror(save_file); + return 0; + } + fwrite(ao_lisp_pool, 1, AO_LISP_POOL_TOTAL, save); + fclose(save); + return 1; +} - /* allocator test */ - for (j = 0; j < 10; j++) { - list = 0; - string = ao_lisp_string_new(0); - for (i = 0; i < 2; i++) { - string = ao_lisp_string_cat(string, "a"); - list = ao_lisp_cons_cons(ao_lisp_string_poly(string), list); - list = ao_lisp_cons_cons(ao_lisp_int_poly(i), list); - atom = ao_lisp_atom_intern("ant"); - list = ao_lisp_cons_cons(ao_lisp_atom_poly(atom), list); - } - ao_lisp_poly_print(ao_lisp_cons_poly(list)); - printf("\n"); +int +ao_lisp_os_restore(void) +{ + FILE *restore = fopen(save_file, "r"); + size_t ret; + + if (!restore) { + perror(save_file); + return 0; + } + ret = fread(ao_lisp_pool, 1, AO_LISP_POOL_TOTAL, restore); + fclose(restore); + if (ret != AO_LISP_POOL_TOTAL) + return 0; + return 1; +} + +int +ao_lisp_getc(void) +{ + int c; + + if (ao_lisp_file) + return getc(ao_lisp_file); + + if (newline) { + printf("> "); + newline = 0; } + c = getchar(); + if (c == '\n') + newline = 1; + return c; +} - for (atom = ao_lisp_poly_atom(ao_builtin_atoms); atom; atom = ao_lisp_poly_atom(atom->next)) { - printf("%s = ", atom->name); - ao_lisp_poly_print(ao_lisp_atom_get(ao_lisp_atom_poly(atom))); - printf("\n"); +int +main (int argc, char **argv) +{ + while (*++argv) { + ao_lisp_file = fopen(*argv, "r"); + if (!ao_lisp_file) { + perror(*argv); + exit(1); + } + ao_lisp_read_eval_print(); + fclose(ao_lisp_file); + ao_lisp_file = NULL; } -#endif -#if 0 - list = ao_lisp_cons_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("+")), - ao_lisp_cons_cons(ao_lisp_cons_poly(ao_lisp_cons_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("+")), - ao_lisp_cons_cons(ao_lisp_int_poly(3), - ao_lisp_cons_cons(ao_lisp_int_poly(4), NULL)))), - ao_lisp_cons_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"); -#endif -#if 1 ao_lisp_read_eval_print(); -#endif }