#include "ao_lisp.h"
-#if 0
-#define DBG(...) printf (__VA_ARGS__)
-#else
-#define DBG(...)
-#endif
-
struct ao_lisp_funcs {
void (*print)(ao_poly);
void (*patom)(ao_poly);
.print = ao_lisp_lambda_print,
.patom = ao_lisp_lambda_print,
},
+ [AO_LISP_STACK] = {
+ .print = ao_lisp_stack_print,
+ .patom = ao_lisp_stack_print,
+ },
};
static const struct ao_lisp_funcs *
f->patom(p);
}
+void *
+ao_lisp_ref(ao_poly poly) {
+ if (poly == AO_LISP_NIL)
+ return NULL;
+ if (poly & AO_LISP_CONST)
+ return (void *) (ao_lisp_const + (poly & AO_LISP_REF_MASK) - 4);
+ return (void *) (ao_lisp_pool + (poly & AO_LISP_REF_MASK) - 4);
+}
+
+ao_poly
+ao_lisp_poly(const void *addr, ao_poly type) {
+ const uint8_t *a = addr;
+ if (a == NULL)
+ return AO_LISP_NIL;
+ if (AO_LISP_IS_CONST(a))
+ return AO_LISP_CONST | (a - ao_lisp_const + 4) | type;
+ return (a - ao_lisp_pool + 4) | type;
+}