summaryrefslogtreecommitdiffstats
path: root/lib.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2009-11-09 20:33:25 -0800
committerKaz Kylheku <kaz@kylheku.com>2009-11-09 20:33:25 -0800
commitee8103fa715d464da45850f794da2df8f3773811 (patch)
tree9892644aaf89cda6322a3ec3938fb5df83d3f0f2 /lib.h
parent42fdb7eb02593476b5030ce4a7dc471d4b01a49e (diff)
downloadtxr-ee8103fa715d464da45850f794da2df8f3773811.tar.gz
txr-ee8103fa715d464da45850f794da2df8f3773811.tar.bz2
txr-ee8103fa715d464da45850f794da2df8f3773811.zip
Changing representation of objects to allow for unboxed characters.
Now numbers and characters fit into a cell. We lose one more bit from the range of numbers.
Diffstat (limited to 'lib.h')
-rw-r--r--lib.h31
1 files changed, 14 insertions, 17 deletions
diff --git a/lib.h b/lib.h
index 2b32582d..b993d39e 100644
--- a/lib.h
+++ b/lib.h
@@ -24,8 +24,16 @@
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#define TAG_SHIFT 2
+#define TAG_MASK ((1 << TAG_SHIFT) - 1)
+#define TAG_PTR 0
+#define TAG_NUM 1
+#define TAG_CHR 2
+#define NUM_MAX (LONG_MAX/4)
+#define NUM_MIN (LONG_MIN/4)
+
typedef enum type {
- CONS = 1, STR, CHR, NUM, SYM, FUN, VEC, LCONS, LSTR, COBJ
+ NUM = TAG_NUM, CHR = TAG_CHR, CONS, STR, SYM, FUN, VEC, LCONS, LSTR, COBJ
} type_t;
typedef enum functype
@@ -35,16 +43,11 @@ typedef enum functype
N0, N1, N2, N3, N4 /* No-env intrinsics. */
} functype_t;
-#define TAG_SHIFT 1
-#define TAG_MASK ((1 << TAG_SHIFT) - 1)
-#define TAG_NUM 1
-#define TAG_PTR 0
-#define NUM_MAX (LONG_MAX/2)
-#define NUM_MIN (LONG_MIN/2)
-
-#define is_ptr(obj) ((obj) && (((long) obj) & TAG_MASK) == TAG_PTR)
-#define is_num(obj) ((((long) obj) & TAG_MASK) == TAG_NUM)
-#define type(obj) ((is_num(obj)) ? NUM : obj->t.type)
+#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 type(obj) (tag(obj) ? ((type_t) tag(obj)) : obj->t.type)
typedef union obj obj_t;
@@ -65,11 +68,6 @@ struct string {
obj_t *len;
};
-struct chr {
- type_t type;
- int ch;
-};
-
struct sym {
type_t type;
obj_t *name;
@@ -149,7 +147,6 @@ union obj {
struct any t;
struct cons c;
struct string st;
- struct chr ch;
struct sym s;
struct func f;
struct vec v;