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
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)
{