clean up smob macro implementation
authorAndy Wingo <wingo@pobox.com>
Tue, 8 Dec 2009 21:14:26 +0000 (22:14 +0100)
committerAndy Wingo <wingo@pobox.com>
Tue, 8 Dec 2009 22:13:07 +0000 (23:13 +0100)
* libguile/smob.h: Regularize the SCM_SMOB macros, and make them all go
  through some generic SMOB accessor macros.

* libguile/smob.c (scm_i_set_smob_flags): Remove, as it is unused.

libguile/smob.c
libguile/smob.h

index 31f6dd0..d96a043 100644 (file)
 long scm_numsmob;
 scm_smob_descriptor scm_smobs[MAX_SMOB_COUNT];
 
-/* Lower 16 bit of data must be zero. 
-*/
-void
-scm_i_set_smob_flags (SCM x, scm_t_bits data)
-{
-  SCM_SET_CELL_WORD_0 (x, (SCM_CELL_WORD_0 (x) & 0xFFFF) | data);
-}
-
 void
 scm_assert_smob_type (scm_t_bits tag, SCM val)
 {
index ee0e53e..06b1c48 100644 (file)
@@ -122,24 +122,44 @@ while (0)
   } while (0)
 
 
-#define SCM_SMOB_FLAGS(x)               (SCM_CELL_WORD_0 (x) >> 16)
-#define SCM_SMOB_DATA(x)               (SCM_CELL_WORD_1 (x))
-#define SCM_SMOB_DATA_2(x)             (SCM_CELL_WORD_2 (x))
-#define SCM_SMOB_DATA_3(x)             (SCM_CELL_WORD_3 (x))
-#define SCM_SET_SMOB_DATA(x, data)     (SCM_SET_CELL_WORD_1 ((x), (data)))
-#define SCM_SET_SMOB_DATA_2(x, data)   (SCM_SET_CELL_WORD_2 ((x), (data)))
-#define SCM_SET_SMOB_DATA_3(x, data)   (SCM_SET_CELL_WORD_3 ((x), (data)))
-#define SCM_SET_SMOB_FLAGS(x, data)     (scm_i_set_smob_flags((x),(data)<<16))
-
-#define SCM_SMOB_OBJECT(x)             (SCM_CELL_OBJECT_1 (x))
-#define SCM_SMOB_OBJECT_2(x)           (SCM_CELL_OBJECT_2 (x))
-#define SCM_SMOB_OBJECT_3(x)           (SCM_CELL_OBJECT_3 (x))
-#define SCM_SET_SMOB_OBJECT(x,obj)     (SCM_SET_CELL_OBJECT_1 ((x), (obj)))
-#define SCM_SET_SMOB_OBJECT_2(x,obj)    (SCM_SET_CELL_OBJECT_2 ((x), (obj)))
-#define SCM_SET_SMOB_OBJECT_3(x,obj)    (SCM_SET_CELL_OBJECT_3 ((x), (obj)))
-#define SCM_SMOB_OBJECT_LOC(x)         (SCM_CELL_OBJECT_LOC ((x), 1))
-#define SCM_SMOB_OBJECT_2_LOC(x)       (SCM_CELL_OBJECT_LOC ((x), 2))
-#define SCM_SMOB_OBJECT_3_LOC(x)       (SCM_CELL_OBJECT_LOC ((x), 3))
+#define SCM_SMOB_DATA_N(x, n)          (SCM_CELL_WORD ((x), (n)))
+#define SCM_SET_SMOB_DATA_N(x, n, data)        (SCM_SET_CELL_WORD ((x), (n), (data)))
+
+#define SCM_SMOB_DATA_0(x)             (SCM_SMOB_DATA_N ((x), 0))
+#define SCM_SMOB_DATA_1(x)             (SCM_SMOB_DATA_N ((x), 1))
+#define SCM_SMOB_DATA_2(x)             (SCM_SMOB_DATA_N ((x), 2))
+#define SCM_SMOB_DATA_3(x)             (SCM_SMOB_DATA_N ((x), 3))
+#define SCM_SET_SMOB_DATA_0(x, data)   (SCM_SET_SMOB_DATA_N ((x), 0, (data)))
+#define SCM_SET_SMOB_DATA_1(x, data)   (SCM_SET_SMOB_DATA_N ((x), 1, (data)))
+#define SCM_SET_SMOB_DATA_2(x, data)   (SCM_SET_SMOB_DATA_N ((x), 2, (data)))
+#define SCM_SET_SMOB_DATA_3(x, data)   (SCM_SET_SMOB_DATA_N ((x), 3, (data)))
+
+#define SCM_SMOB_FLAGS(x)               (SCM_SMOB_DATA_0 (x) >> 16)
+#define SCM_SMOB_DATA(x)               (SCM_SMOB_DATA_1 (x))
+#define SCM_SET_SMOB_FLAGS(x, data)     (SCM_SET_SMOB_DATA_0 ((x), (SCM_CELL_TYPE (x)&0xffff)|((data)<<16)))
+#define SCM_SET_SMOB_DATA(x, data)     (SCM_SET_SMOB_DATA_1 ((x), (data)))
+
+#define SCM_SMOB_OBJECT_N(x,n)         (SCM_CELL_OBJECT ((x), (n)))
+#define SCM_SET_SMOB_OBJECT_N(x,n,obj) (SCM_SET_CELL_OBJECT ((x), (n), (obj)))
+#define SCM_SMOB_OBJECT_N_LOC(x,n)     (SCM_CELL_OBJECT_LOC ((x), (n)))
+
+/*#define SCM_SMOB_OBJECT_0(x)         (SCM_SMOB_OBJECT_N ((x), 0))*/
+#define SCM_SMOB_OBJECT_1(x)           (SCM_SMOB_OBJECT_N ((x), 1))
+#define SCM_SMOB_OBJECT_2(x)           (SCM_SMOB_OBJECT_N ((x), 2))
+#define SCM_SMOB_OBJECT_3(x)           (SCM_SMOB_OBJECT_N ((x), 3))
+/*#define SCM_SET_SMOB_OBJECT_0(x,obj) (SCM_SET_SMOB_OBJECT_N ((x), 0, (obj)))*/
+#define SCM_SET_SMOB_OBJECT_1(x,obj)   (SCM_SET_SMOB_OBJECT_N ((x), 1, (obj)))
+#define SCM_SET_SMOB_OBJECT_2(x,obj)   (SCM_SET_SMOB_OBJECT_N ((x), 2, (obj)))
+#define SCM_SET_SMOB_OBJECT_3(x,obj)   (SCM_SET_SMOB_OBJECT_N ((x), 3, (obj)))
+#define SCM_SMOB_OBJECT_0_LOC(x)       (SCM_SMOB_OBJECT_N_LOC ((x), 0)))
+#define SCM_SMOB_OBJECT_1_LOC(x)       (SCM_SMOB_OBJECT_N_LOC ((x), 1)))
+#define SCM_SMOB_OBJECT_2_LOC(x)       (SCM_SMOB_OBJECT_N_LOC ((x), 2)))
+#define SCM_SMOB_OBJECT_3_LOC(x)       (SCM_SMOB_OBJECT_N_LOC ((x), 3)))
+
+#define SCM_SMOB_OBJECT(x)             (SCM_SMOB_OBJECT_1 (x))
+#define SCM_SET_SMOB_OBJECT(x,obj)     (SCM_SET_SMOB_OBJECT_1 ((x), (obj)))
+#define SCM_SMOB_OBJECT_LOC(x)         (SCM_SMOB_OBJECT_1_LOC (x)))
+
 
 #define SCM_TC2SMOBNUM(x)              (0x0ff & ((x) >> 8))
 #define SCM_SMOBNUM(x)                 (SCM_TC2SMOBNUM (SCM_CELL_TYPE (x)))
@@ -159,7 +179,6 @@ while (0)
 SCM_API long scm_numsmob;
 SCM_API scm_smob_descriptor scm_smobs[];
 
-SCM_API void scm_i_set_smob_flags (SCM x, scm_t_bits data);
 SCM_API void scm_i_finalize_smob (GC_PTR obj, GC_PTR data);
 
 \f