altos/lisp: Evaluate macros once, then smash them into place
[fw/altos] / src / lisp / ao_lisp.h
index e90d791ad8dc83576f24a281a337a481105c328a..2db4914fb6ebc507859fc1e51b9e9c1bcb96027f 100644 (file)
@@ -173,14 +173,15 @@ ao_lisp_frame_poly(struct ao_lisp_frame *frame) {
 
 enum eval_state {
        eval_sexpr,             /* Evaluate an sexpr */
-       eval_val,
-       eval_formal,
-       eval_exec,
-       eval_cond,
-       eval_cond_test,
-       eval_progn,
-       eval_while,
-       eval_while_test,
+       eval_val,               /* Value computed */
+       eval_formal,            /* Formal computed */
+       eval_exec,              /* Start a lambda evaluation */
+       eval_cond,              /* Start next cond clause */
+       eval_cond_test,         /* Check cond condition */
+       eval_progn,             /* Start next progn entry */
+       eval_while,             /* Start while condition */
+       eval_while_test,        /* Check while condition */
+       eval_macro,             /* Finished with macro generation */
 };
 
 struct ao_lisp_stack {
@@ -206,6 +207,7 @@ ao_lisp_stack_poly(struct ao_lisp_stack *stack)
 }
 
 extern struct ao_lisp_stack    *ao_lisp_stack;
+extern struct ao_lisp_stack    *ao_lisp_stack_free_list;
 extern ao_poly                 ao_lisp_v;
 
 #define AO_LISP_FUNC_LAMBDA    0
@@ -213,6 +215,14 @@ extern ao_poly                     ao_lisp_v;
 #define AO_LISP_FUNC_MACRO     2
 #define AO_LISP_FUNC_LEXPR     3
 
+#define AO_LISP_FUNC_FREE_ARGS 0x80
+#define AO_LISP_FUNC_MASK      0x7f
+
+#define AO_LISP_FUNC_F_LAMBDA  (AO_LISP_FUNC_FREE_ARGS | AO_LISP_FUNC_LAMBDA)
+#define AO_LISP_FUNC_F_NLAMBDA (AO_LISP_FUNC_FREE_ARGS | AO_LISP_FUNC_NLAMBDA)
+#define AO_LISP_FUNC_F_MACRO   (AO_LISP_FUNC_FREE_ARGS | AO_LISP_FUNC_MACRO)
+#define AO_LISP_FUNC_F_LEXPR   (AO_LISP_FUNC_FREE_ARGS | AO_LISP_FUNC_LEXPR)
+
 struct ao_lisp_builtin {
        uint8_t         type;
        uint8_t         args;
@@ -390,6 +400,9 @@ ao_lisp_builtin_poly(struct ao_lisp_builtin *b)
 }
 
 /* memory functions */
+
+extern int ao_lisp_collects;
+
 /* returns 1 if the object was already marked */
 int
 ao_lisp_mark(const struct ao_lisp_type *type, void *addr);
@@ -439,6 +452,11 @@ extern const struct ao_lisp_type ao_lisp_cons_type;
 struct ao_lisp_cons *
 ao_lisp_cons_cons(ao_poly car, struct ao_lisp_cons *cdr);
 
+extern struct ao_lisp_cons *ao_lisp_cons_free_list;
+
+void
+ao_lisp_cons_free(struct ao_lisp_cons *cons);
+
 void
 ao_lisp_cons_print(ao_poly);