aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2014-05-15 22:48:34 +0300
committerOskari Timperi <oskari.timperi@iki.fi>2014-05-15 22:48:34 +0300
commite23d0ee6eec1433849e4af1f3906a0946a19aef4 (patch)
treeb7eaef2719ebc43a976cd5f63dea30d03fecca9a
parent3666d3b9334286a2242c8da20cac446dd9ee17e9 (diff)
downloadlispish-e23d0ee6eec1433849e4af1f3906a0946a19aef4.tar.gz
lispish-e23d0ee6eec1433849e4af1f3906a0946a19aef4.zip
add atom types for true, false, nil
-rw-r--r--atom.c6
-rw-r--r--atom.h13
2 files changed, 12 insertions, 7 deletions
diff --git a/atom.c b/atom.c
index 73ecd7e..375bd3e 100644
--- a/atom.c
+++ b/atom.c
@@ -4,9 +4,9 @@
#include <stdlib.h>
#include <string.h>
-struct atom true_atom;
-struct atom false_atom;
-struct atom nil_atom;
+struct atom true_atom = { ATOM_TRUE };
+struct atom false_atom = { ATOM_FALSE };
+struct atom nil_atom = { ATOM_NIL } ;
struct atom *atom_new(char type)
{
diff --git a/atom.h b/atom.h
index 3b716fa..62e3276 100644
--- a/atom.h
+++ b/atom.h
@@ -4,13 +4,16 @@
#define LIST_GET_ATOM(LIST) ((struct atom *) (LIST)->data)
#define ATOM_TYPE(LIST) ((LIST_GET_ATOM(LIST))->type)
+
#define IS_INT(LIST) ((ATOM_TYPE(LIST)) == ATOM_INT)
#define IS_STR(LIST) ((ATOM_TYPE(LIST)) == ATOM_STR)
#define IS_SYM(LIST) ((ATOM_TYPE(LIST)) == ATOM_SYMBOL)
#define IS_LIST(LIST) ((ATOM_TYPE(LIST)) == ATOM_LIST)
+#define IS_ATOM(LIST) (!(IS_LIST(LIST)))
#define IS_TRUE(LIST) (LIST_GET_ATOM(LIST) == &true_atom)
#define IS_FALSE(LIST) (LIST_GET_ATOM(LIST) == &false_atom)
+
#define IS_NIL(LIST) (LIST_GET_ATOM(LIST) == &nil_atom)
#define CAR(LIST) LIST
@@ -24,11 +27,16 @@ enum
ATOM_INT,
ATOM_STR,
ATOM_SYMBOL,
- ATOM_LIST
+ ATOM_LIST,
+ ATOM_TRUE,
+ ATOM_FALSE
};
+struct list;
+
struct atom
{
+ char type;
union
{
long l;
@@ -39,11 +47,8 @@ struct atom
} str;
struct list *list;
};
- char type;
};
-struct list;
-
struct atom *atom_new(char type);
struct atom *atom_new_int(long l);
struct atom *atom_new_str(const char *str, int len);