summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--ChangeLog16
-rw-r--r--Makefile3
-rwxr-xr-xconfigure7
-rw-r--r--lib.c4
-rw-r--r--lib.h41
5 files changed, 56 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 976d60f3..2293dc40 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2009-11-19 Kaz Kylheku <kkylheku@gmail.com>
+ Get rid of macros in favor of safer inline functions.
+
+ The recent auto_str("byte str") error could have been caught
+ at compile time.
+
+ * Makefile (CFLAGS): Include expansion of INLINE_FLAGS.
+
+ * configure (inline_flags): New variable.
+ (INLINE_FLAGS): New variable generated in config.make.
+
+ * lib.h (tag, is_ptr, is_num, is_chr, is_lit, type,
+ auto_str, static_str, litptr): Function-like macros converted to
+ functions.
+
+2009-11-19 Kaz Kylheku <kkylheku@gmail.com>
+
Version 024
Fixed show-stopper breakage in parse error diagnostic function.
diff --git a/Makefile b/Makefile
index 8e2d746a..dddce7d2 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,8 @@
-include config.make
-CFLAGS := -I$(top_srcdir) $(LANG_FLAGS) $(DIAG_FLAGS) $(OPT_FLAGS) $(DBG_FLAGS)
+CFLAGS := -I$(top_srcdir) $(LANG_FLAGS) $(DIAG_FLAGS) \
+ $(OPT_FLAGS) $(INLINE_FLAGS) $(DBG_FLAGS)
OBJS := txr.o lex.yy.o y.tab.o match.o lib.o regex.o gc.o unwind.o stream.o
OBJS += hash.o utf8.o
diff --git a/configure b/configure
index 1777b44d..fdd97854 100755
--- a/configure
+++ b/configure
@@ -112,6 +112,7 @@ opt_flags=${opt_flags--O2}
lang_flags=${lang_flags--ansi -std=c89 -D_POSIX_C_SOURCE=2}
diag_flags=${diag_flags--Wall}
debug_flags=${debug_flags--g}
+inline_flags=${inline_flags--Dinline=\"static __inline\"}
lex_dbg_flags=${lex_dbg_flags-}
txr_dbg_opts=${txr_dbg_opts---gc-debug}
#
@@ -245,6 +246,11 @@ debug_flags [$debug_flags]
Specifies flags for requesting that debugging information be
retained in the compile and link.
+inline_flags [$inline_flags]
+
+ Specifies flag for defining a macro that expands to a suitable
+ compiler-specific inline specifier.
+
lex_dbg_flags [$lex_dbg_flags]
Specifies debug flags to be passed to lex, perhaps to generate a debugging
@@ -453,6 +459,7 @@ OPT_FLAGS := $opt_flags
LANG_FLAGS := $lang_flags
DIAG_FLAGS := $diag_flags
DBG_FLAGS := $debug_flags
+INLINE_FLAGS := $inline_flags
LEX_DBG_FLAGS := $lex_dbg_flags
TXR_DBG_OPTS := $txr_dbg_opts
!
diff --git a/lib.c b/lib.c
index ab1447fa..57f340c0 100644
--- a/lib.c
+++ b/lib.c
@@ -582,8 +582,8 @@ obj_t *consp(obj_t *obj)
if (!obj) {
return nil;
} else {
- type_t type = type(obj);
- return (type == CONS || type == LCONS) ? t : nil;
+ type_t ty = type(obj);
+ return (ty == CONS || ty == LCONS) ? t : nil;
}
}
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;