ao_lisp_lambda.c \
ao_lisp_eval.c \
ao_lisp_rep.c \
+ ao_lisp_save.c \
ao_lisp_error.c
OBJS=$(SRCS:.c=.o)
//#include <stdio.h>
#include <ao_lisp_os.h>
+typedef uint16_t ao_poly;
+typedef int16_t ao_signed_poly;
+
+#ifdef AO_LISP_SAVE
+
+struct ao_lisp_os_save {
+ ao_poly ao_lisp_atoms;
+ ao_poly ao_lisp_globals;
+};
+
+#define AO_LISP_POOL (AO_LISP_POOL_TOTAL - sizeof (struct ao_lisp_os_save))
+
+int
+ao_lisp_os_save(void);
+
+int
+ao_lisp_os_restore(void);
+
+#endif
+
#ifdef AO_LISP_MAKE_CONST
#define AO_LISP_POOL_CONST 16384
extern uint8_t ao_lisp_const[AO_LISP_POOL_CONST];
extern uint8_t ao_lisp_exception;
-typedef uint16_t ao_poly;
-typedef int16_t ao_signed_poly;
-
static inline int
ao_lisp_is_const(ao_poly poly) {
return poly & AO_LISP_CONST;
builtin_flush,
builtin_delay,
builtin_led,
+ builtin_save,
+ builtin_restore,
_builtin_last
};
/* eval */
+void
+ao_lisp_eval_clear_globals(void);
+
+int
+ao_lisp_eval_restart(void);
+
ao_poly
ao_lisp_eval(ao_poly p);
ao_poly
ao_lisp_lambda_eval(void);
+/* save */
+
+ao_poly
+ao_lisp_save(struct ao_lisp_cons *cons);
+
+ao_poly
+ao_lisp_restore(struct ao_lisp_cons *cons);
+
/* error */
void
[builtin_flush] = _ao_lisp_atom_flush,
[builtin_delay] = _ao_lisp_atom_delay,
[builtin_led] = _ao_lisp_atom_led,
+ [builtin_save] = _ao_lisp_atom_save,
+ [builtin_restore] = _ao_lisp_atom_restore,
+
};
static char *
[builtin_flush] = ao_lisp_flush,
[builtin_led] = ao_lisp_led,
[builtin_delay] = ao_lisp_delay,
+ [builtin_save] = ao_lisp_save,
+ [builtin_restore] = ao_lisp_restore,
};
[eval_while_test] = ao_lisp_eval_while_test,
};
+/*
+ * Called at restore time to reset all execution state
+ */
+
+void
+ao_lisp_eval_clear_globals(void)
+{
+ ao_lisp_stack = NULL;
+ ao_lisp_frame_current = NULL;
+ ao_lisp_v = AO_LISP_NIL;
+}
+
+int
+ao_lisp_eval_restart(void)
+{
+ return ao_lisp_stack_push();
+}
+
ao_poly
ao_lisp_eval(ao_poly _v)
{
"flush", AO_LISP_FUNC_LAMBDA, builtin_flush,
"delay", AO_LISP_FUNC_LAMBDA, builtin_delay,
"led", AO_LISP_FUNC_LEXPR, builtin_led,
+ "save", AO_LISP_FUNC_LAMBDA, builtin_save,
+ "restore", AO_LISP_FUNC_LAMBDA, builtin_restore,
};
#define N_FUNC (sizeof funcs / sizeof funcs[0])
--- /dev/null
+/*
+ * Copyright © 2016 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+#include <ao_lisp.h>
+
+ao_poly
+ao_lisp_save(struct ao_lisp_cons *cons)
+{
+#ifdef AO_LISP_SAVE
+ struct ao_lisp_os_save *os = (struct ao_lisp_os_save *) &ao_lisp_pool[AO_LISP_POOL];
+
+ ao_lisp_collect();
+ os->ao_lisp_atoms = ao_lisp_atom_poly(ao_lisp_atoms);
+ os->ao_lisp_globals = ao_lisp_frame_poly(ao_lisp_frame_global);
+ if (ao_lisp_os_save())
+ return _ao_lisp_atom_t;
+#endif
+ return AO_LISP_NIL;
+}
+
+ao_poly
+ao_lisp_restore(struct ao_lisp_cons *cons)
+{
+#ifdef AO_LISP_SAVE
+ struct ao_lisp_os_save *os = (struct ao_lisp_os_save *) &ao_lisp_pool[AO_LISP_POOL];
+
+ if (ao_lisp_os_restore()) {
+
+ ao_lisp_atoms = ao_lisp_poly_atom(os->ao_lisp_atoms);
+ ao_lisp_frame_global = ao_lisp_poly_frame(os->ao_lisp_globals);
+
+ /* Clear the eval global variabls */
+ ao_lisp_eval_clear_globals();
+
+ /* Reset the allocator */
+ ao_lisp_top = AO_LISP_POOL;
+ ao_lisp_collect();
+
+ /* Re-create the evaluator stack */
+ if (!ao_lisp_eval_restart())
+ return AO_LISP_NIL;
+ return _ao_lisp_atom_t;
+ }
+#endif
+ return AO_LISP_NIL;
+}