summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-11-11 21:18:50 -0800
committerKeith Packard <keithp@keithp.com>2016-11-17 22:18:39 -0800
commit6187afea14c2dbaae98b595963104c527a3a45c8 (patch)
treeb27e34c3b1d6fedf94287b31ea7e99872bcd1c19
parent0fd008d75ca451ba68ad8ae773ea8a5ebc1785c5 (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>
-rw-r--r--src/test/Makefile4
-rw-r--r--src/test/ao_lisp_os.h3
-rw-r--r--src/test/ao_lisp_test.c33
-rw-r--r--src/test/hanoi.lisp2
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)