diff options
author | Keith Packard <keithp@keithp.com> | 2016-11-11 21:18:50 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-02-20 11:16:50 -0800 |
commit | 8f2d60b4c029bffaa559bd1f31f5b15230dfa674 (patch) | |
tree | 3b19d160542e3bcf26625f023f572658e8f79127 /src/test | |
parent | dba374516ed396633659dec571b6a44b03da8ad1 (diff) |
altos/lisp: Add save/restore to ao_lisp_test
Allow testing of the save/restore code under Linux.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/Makefile | 4 | ||||
-rw-r--r-- | src/test/ao_lisp_os.h | 3 | ||||
-rw-r--r-- | src/test/ao_lisp_test.c | 33 | ||||
-rw-r--r-- | src/test/hanoi.lisp | 2 |
4 files changed, 38 insertions, 4 deletions
diff --git a/src/test/Makefile b/src/test/Makefile index d6777090..df24c2b6 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -91,9 +91,9 @@ ao_quaternion_test: ao_quaternion_test.c ao_quaternion.h AO_LISP_OBJS = ao_lisp_test.o ao_lisp_mem.o ao_lisp_cons.o ao_lisp_string.o \ ao_lisp_atom.o ao_lisp_int.o ao_lisp_eval.o ao_lisp_poly.o \ ao_lisp_builtin.o ao_lisp_read.o ao_lisp_rep.o ao_lisp_frame.o \ - ao_lisp_lambda.o ao_lisp_error.o + ao_lisp_lambda.o ao_lisp_error.o ao_lisp_save.o ao_lisp_test: $(AO_LISP_OBJS) cc $(CFLAGS) -o $@ $(AO_LISP_OBJS) -$(AO_LISP_OBJS): ao_lisp.h ao_lisp_const.h +$(AO_LISP_OBJS): ao_lisp.h ao_lisp_const.h ao_lisp_os.h diff --git a/src/test/ao_lisp_os.h b/src/test/ao_lisp_os.h index c979697e..8b9c1475 100644 --- a/src/test/ao_lisp_os.h +++ b/src/test/ao_lisp_os.h @@ -22,6 +22,9 @@ #include <stdlib.h> #include <time.h> +#define AO_LISP_POOL_TOTAL 3072 +#define AO_LISP_SAVE + extern int ao_lisp_getc(void); static inline void diff --git a/src/test/ao_lisp_test.c b/src/test/ao_lisp_test.c index 69739100..41dae07a 100644 --- a/src/test/ao_lisp_test.c +++ b/src/test/ao_lisp_test.c @@ -18,6 +18,39 @@ static FILE *ao_lisp_file; static int newline = 1; +static char save_file[] = "lisp.image"; + +int +ao_lisp_os_save(void) +{ + FILE *save = fopen(save_file, "w"); + + if (!save) { + perror(save_file); + return 0; + } + fwrite(ao_lisp_pool, 1, AO_LISP_POOL_TOTAL, save); + fclose(save); + return 1; +} + +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) { diff --git a/src/test/hanoi.lisp b/src/test/hanoi.lisp index 09a3611c..01398d91 100644 --- a/src/test/hanoi.lisp +++ b/src/test/hanoi.lisp @@ -125,5 +125,3 @@ (clear) (_hanoi len 0 1 2) ) - -(hanoi) |