summaryrefslogtreecommitdiffstats
path: root/lib.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2009-11-19 14:54:04 -0800
committerKaz Kylheku <kaz@kylheku.com>2009-11-19 14:54:04 -0800
commitd3abb71364d041a2d8334fcd8d32ba7857606fb0 (patch)
tree5991ff81ef062a16ec23419a2977eba2016715b4 /lib.h
parentf5b18ec696f2c176a2f9f49a3c3a5e158291d00f (diff)
downloadtxr-d3abb71364d041a2d8334fcd8d32ba7857606fb0.tar.gz
txr-d3abb71364d041a2d8334fcd8d32ba7857606fb0.tar.bz2
txr-d3abb71364d041a2d8334fcd8d32ba7857606fb0.zip
Get rid of macros in favor of safer inline functions.
The recent auto_str("byte str") error could have been caught at compile time.
Diffstat (limited to 'lib.h')
-rw-r--r--lib.h41
1 files changed, 29 insertions, 12 deletions
diff --git a/lib.h b/lib.h
index f0ee023c..197270a7 100644
--- a/lib.h
+++ b/lib.h
@@ -45,18 +45,6 @@ typedef enum functype
N0, N1, N2, N3, N4 /* No-env intrinsics. */
} functype_t;
-#define tag(obj) (((long) (obj)) & TAG_MASK)
-#define is_ptr(obj) ((obj) && (tag(obj) == TAG_PTR))
-#define is_num(obj) (tag(obj) == TAG_NUM)
-#define is_chr(obj) (tag(obj) == TAG_CHR)
-#define is_lit(obj) (tag(obj) == TAG_LIT)
-#define type(obj) (tag(obj) ? ((type_t) tag(obj)) : (obj)->t.type)
-#define lit_noex(strlit) ((obj_t *) ((long) (L ## strlit) | TAG_LIT))
-#define lit(strlit) lit_noex(strlit)
-#define auto_str(str) ((obj_t *) ((long) (str) | TAG_LIT))
-#define static_str(str) ((obj_t *) ((long) (str) | TAG_LIT))
-#define litptr(obj) ((wchar_t *) ((long) obj & ~TAG_MASK))
-
typedef union obj obj_t;
struct any {
@@ -163,6 +151,35 @@ union obj {
struct cobj co;
};
+inline long tag(obj_t *obj) { return ((long) obj) & TAG_MASK; }
+inline int is_ptr(obj_t *obj) { return obj && tag(obj) == TAG_PTR; }
+inline int is_num(obj_t *obj) { return tag(obj) == TAG_NUM; }
+inline int is_chr(obj_t *obj) { return tag(obj) == TAG_CHR; }
+inline int is_lit(obj_t *obj) { return tag(obj) == TAG_LIT; }
+
+inline type_t type(obj_t *obj)
+{
+ return tag(obj) ? (type_t) tag(obj) : obj->t.type;
+}
+
+inline obj_t *auto_str(const wchar_t *str)
+{
+ return (obj_t *) ((long) (str) | TAG_LIT);
+}
+
+inline obj_t *static_str(const wchar_t *str)
+{
+ return (obj_t *) ((long) (str) | TAG_LIT);
+}
+
+inline wchar_t *litptr(obj_t *obj)
+{
+ return (wchar_t *) ((long) obj & ~TAG_MASK);
+}
+
+#define lit_noex(strlit) ((obj_t *) ((long) (L ## strlit) | TAG_LIT))
+#define lit(strlit) lit_noex(strlit)
+
extern obj_t *interned_syms;
extern obj_t *t, *cons_t, *str_t, *chr_t, *num_t, *sym_t, *fun_t, *vec_t;