aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alisp.h3
-rw-r--r--constructor.c16
-rw-r--r--sys.c9
3 files changed, 24 insertions, 4 deletions
diff --git a/alisp.h b/alisp.h
index c3d25c3..e9694d9 100644
--- a/alisp.h
+++ b/alisp.h
@@ -126,6 +126,9 @@ vec_t *as_vec(lisp_t *);
#define CAR(L) (as_cons(L)->car)
#define CDR(L) (as_cons(L)->cdr)
+lisp_t *car(lisp_t *);
+lisp_t *cdr(lisp_t *);
+
/// Pointer tagging scheme for lisps
typedef enum Tag
diff --git a/constructor.c b/constructor.c
index 9db0330..e0fab52 100644
--- a/constructor.c
+++ b/constructor.c
@@ -46,3 +46,19 @@ lisp_t *intern(sys_t *sys, sv_t sv)
char *str = sym_table_find(&sys->symtable, sv);
return tag_sym(str);
}
+
+lisp_t *car(lisp_t *lsp)
+{
+ if (!IS_TAG(lsp, CONS))
+ return NIL;
+ else
+ return CAR(lsp);
+}
+
+lisp_t *cdr(lisp_t *lsp)
+{
+ if (!IS_TAG(lsp, CONS))
+ return NIL;
+ else
+ return CDR(lsp);
+}
diff --git a/sys.c b/sys.c
index d3a9bb2..ac26a88 100644
--- a/sys.c
+++ b/sys.c
@@ -43,12 +43,13 @@ void sys_cleanup(sys_t *sys)
return;
// Iterate through each element of memory
- for (lisp_t *cell = sys->memory, *next = CDR(cell); cell;
- cell = next, next = CDR(cell))
+ for (lisp_t *cell = sys->memory, *next = cdr(cell); cell;
+ cell = next, next = cdr(next))
{
// Only reason allocated exists is because we had to allocate memory on the
- // heap for it. It's therefore
- lisp_t *allocated = CAR(cell);
+ // heap for it. It's therefore enough to deal with only the allocated
+ // types.
+ lisp_t *allocated = car(cell);
switch (get_tag(allocated))
{
case TAG_CONS: