altos/lisp: Add save/restore to ao_lisp_test
authorKeith Packard <keithp@keithp.com>
Sat, 12 Nov 2016 05:18:50 +0000 (21:18 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 20 Feb 2017 19:16:50 +0000 (11:16 -0800)
Allow testing of the save/restore code under Linux.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/test/Makefile
src/test/ao_lisp_os.h
src/test/ao_lisp_test.c
src/test/hanoi.lisp

index d6777090f07f63eaf391c6fc0f4910568b4716d3..df24c2b6e350166de5d91c460daa88c9c7b7c481 100644 (file)
@@ -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
index c979697eba5bae34f5a8363a6c6b68ed8a805b9f..8b9c1475cbea625bd4d58f8b0fce6d811e11ea62 100644 (file)
@@ -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
index 6973910016ec0fc7072f65c54d7a0edcec739696..41dae07aabf3d9155d331c63125d40e8961f245e 100644 (file)
 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)
 {
index 09a3611ca58f93ff5b201bb1d281edacc0daa3fd..01398d9121029dba270802d9362e687bb3e9c888 100644 (file)
   (clear)
   (_hanoi len 0 1 2)
   )
-
-(hanoi)