diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2009-11-09 17:33:46 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2009-11-09 17:33:46 -0800 |
commit | dd68bf698a5618226fb3807d752c4ff73966cb5f (patch) | |
tree | c2da5348387f6c75aa225f00ecbc5b2f7e198788 /lib.h | |
parent | 357121301094005f6c56471fb18f9ff1b6bc8d13 (diff) | |
download | txr-dd68bf698a5618226fb3807d752c4ff73966cb5f.tar.gz txr-dd68bf698a5618226fb3807d752c4ff73966cb5f.tar.bz2 txr-dd68bf698a5618226fb3807d752c4ff73966cb5f.zip |
Changing representation of objects to allow the NUM type to be
unboxed. If the lowest bit of the obj_t * pointer is 1, then
the remaining bits are a number. A lot of assumptions are made:
- the long type can be converted to and from a pointer
- two's complement.
- behavior of << and >> operators when the sign bit is involved.
Diffstat (limited to 'lib.h')
-rw-r--r-- | lib.h | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -35,6 +35,17 @@ 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) + typedef union obj obj_t; struct any { @@ -59,11 +70,6 @@ struct chr { int ch; }; -struct num { - type_t type; - long val; -}; - struct sym { type_t type; obj_t *name; @@ -144,7 +150,6 @@ union obj { struct cons c; struct string st; struct chr ch; - struct num n; struct sym s; struct func f; struct vec v; @@ -321,7 +326,7 @@ obj_t *match(obj_t *spec, obj_t *data); #define nil ((obj_t *) 0) -#define nao ((obj_t *) -1) /* "not an object", useful as a sentinel. */ +#define nao ((obj_t *) (-1 << TAG_SHIFT)) /* "not an object" sentinel value. */ #define eq(a, b) ((a) == (b) ? t : nil) |