From ee8103fa715d464da45850f794da2df8f3773811 Mon Sep 17 00:00:00 2001
From: Kaz Kylheku <kaz@kylheku.com>
Date: Mon, 9 Nov 2009 20:33:25 -0800
Subject: 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.

---
 lib.h | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

(limited to 'lib.h')

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;
-- 
cgit v1.2.3