aboutsummaryrefslogtreecommitdiff
path: root/atom.h
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2014-05-14 22:27:34 +0300
committerOskari Timperi <oskari.timperi@iki.fi>2014-05-14 22:27:34 +0300
commitd45a5b21de22438c004e1db96a8f154da09cdc0e (patch)
treec2a7bd2a4d08de03ef5e11932d9a1abf85110c80 /atom.h
downloadlispish-d45a5b21de22438c004e1db96a8f154da09cdc0e.tar.gz
lispish-d45a5b21de22438c004e1db96a8f154da09cdc0e.zip
Initial commit
- tokenizing, parsing and basic eval support - arithmetic (+, -, *, /) - quote - atom for checking if the arg is an atom (i.e. not a list) - eq for checking equality - > for checking order - if - some unit testing - simple repl - mem management needs improvement :-)
Diffstat (limited to 'atom.h')
-rw-r--r--atom.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/atom.h b/atom.h
new file mode 100644
index 0000000..3b716fa
--- /dev/null
+++ b/atom.h
@@ -0,0 +1,57 @@
+#ifndef ATOM_H
+#define ATOM_H
+
+#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_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
+
+#define CDR(LIST) ((LIST) != NULL ? (LIST)->next : NULL)
+#define CDDR(LIST) CDR(CDR(LIST))
+
+enum
+{
+ ATOM_NIL,
+ ATOM_INT,
+ ATOM_STR,
+ ATOM_SYMBOL,
+ ATOM_LIST
+};
+
+struct atom
+{
+ union
+ {
+ long l;
+ struct
+ {
+ char *str;
+ int len;
+ } 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);
+struct atom *atom_new_sym(const char *sym, int len);
+struct atom *atom_new_list(struct list *list);
+
+extern struct atom true_atom;
+extern struct atom false_atom;
+extern struct atom nil_atom;
+
+#endif