[uim-commit] r2460 - branches/r5rs/sigscheme

kzk at freedesktop.org kzk at freedesktop.org
Thu Dec 8 15:12:15 PST 2005


Author: kzk
Date: 2005-12-08 15:12:01 -0800 (Thu, 08 Dec 2005)
New Revision: 2460

Modified:
   branches/r5rs/sigscheme/sigschemetype-compact.h
Log:
* simplify accessors of pointer handling types

* sigscheme/sigschemetype-compact.h
  - (SCM_TAG_OTHERS_VALUE_OFFSET_C_POINTER_LSBADDR,
     SCM_PTR_OTHERSBITS,
     SCM_PTR_RAW_LSB,
     SCM_PTR_LSB, 
     SCM_PTR_VALUE,
     SCM_SET_PTR_OTHERSBITS,
     SCM_SET_PTR_LSB,
     SCM_SET_PTR_VALUE): new macro
  - (SCM_FUNC_CFUNC, SCM_FUNC_SET_CFUNC,
     SCM_FUNC_TYPECODE, SCM_FUNC_SET_TYPECODE,
     SCM_C_POINTER_VALUE, SCM_C_POINTER_SET_VALUE,
     SCM_C_FUNCPOINTER_VALUE, SCM_C_FUNCPOINTER_SET_VALUE)
     : rewrite with new macros
  - (SCM_SYNTAXP, SCM_PROCEDUREP): move to new section


Modified: branches/r5rs/sigscheme/sigschemetype-compact.h
===================================================================
--- branches/r5rs/sigscheme/sigschemetype-compact.h	2005-12-08 22:25:47 UTC (rev 2459)
+++ branches/r5rs/sigscheme/sigschemetype-compact.h	2005-12-08 23:12:01 UTC (rev 2460)
@@ -285,6 +285,7 @@
 #define SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_FUNCTYPE (SCM_GCBIT_WIDTH + SCM_TAG_WIDTH + 3 + 1)
 #define SCM_TAG_OTHERS_VALUE_OFFSET_PORT          (SCM_GCBIT_WIDTH + SCM_TAG_WIDTH + 3)
 #define SCM_TAG_OTHERS_VALUE_OFFSET_CONTINUATION  (SCM_GCBIT_WIDTH + SCM_TAG_WIDTH + 3)
+#define SCM_TAG_OTHERS_VALUE_OFFSET_C_POINTER_LSBADDR     (SCM_GCBIT_WIDTH + SCM_TAG_WIDTH + 3 + 1)
 #define SCM_TAG_OTHERS_VALUE_OFFSET_C_FUNCPOINTER_LSBADDR (SCM_GCBIT_WIDTH + SCM_TAG_WIDTH + 3 + 1)
 
 /*==============================================================================
@@ -569,37 +570,7 @@
 #define SCM_VALUEPACKET_VALUES(a)        (SCM_CAR_GET_VALUE_AS_OBJ(SCM_AS_VALUEPACKET(a)))
 #define SCM_VALUEPACKET_SET_VALUES(a, v) (SCM_CAR_SET_VALUE_AS_OBJ(SCM_AS_VALUEPACKET(a), (v)))
 
-
 /*============================================================================
-   Real Accessors : CFunc
-
-   GCC4.0 doesn't align the address of function, so we need to store LSB of the function
-   address to the cdr part.
-  
-   FuncAddr = (S->car & ~0x01) | ((S->cdr >> SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_LSBADDR) & 0x1)
-============================================================================*/
-#define SCM_FUNC_CFUNC_OTHERB(a) (SCM_CAST_UINT(SCM_CAR_GET_VALUE_AS_PTR(a)))
-#define SCM_FUNC_CFUNC_LSB(a)    (SCM_CDR_GET_VALUE_AS_INT((a), SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_LSBADDR) & 0x1)
-#define SCM_FUNC_CFUNC(a)        (SCM_WORD_CAST(ScmFuncType, SCM_FUNC_CFUNC_OTHERB(a) | SCM_FUNC_CFUNC_LSB(a)))
-#define SCM_FUNC_TYPECODE(a)     ((enum ScmFuncTypeCode)SCM_CDR_GET_VALUE_AS_INT((a), SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_FUNCTYPE))
-
-#define SCM_FUNC_SET_CFUNC_LSB(a, val)    (SCM_SET_DIRECT_CDR((a),\
-                                                              (SCM_CAST_CDR_UINT(a) \
-                                                               | ((SCM_CAST_UINT(val) & 0x1) << SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_LSBADDR))))
-#define SCM_FUNC_SET_CFUNC_OTHERB(a, val) (SCM_CAR_SET_VALUE_AS_PTR((a), SCM_WORD_CAST(ScmObj, (val))))
-#define SCM_FUNC_SET_CFUNC(a, fptr)       (SCM_FUNC_SET_CFUNC_OTHERB((a), (SCM_CAST_UINT(fptr) & ~0x1)), \
-                                           SCM_FUNC_SET_CFUNC_LSB((a), (SCM_CAST_UINT(fptr) & 0x1)))
-#define SCM_FUNC_SET_TYPECODE(a, code)    (SCM_CDR_SET_VALUE_AS_INT((a), (code), SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_FUNCTYPE, \
-                                                                    (SCM_TAG_OTHERS_FUNC | (SCM_FUNC_CFUNC_LSB(a) << SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_LSBADDR))))
-
-#define SCM_SYNTAXP(a) (SCM_FUNCP(a)                                    \
-                        && (SCM_FUNC_TYPECODE(a) & SCM_FUNCTYPE_SYNTAX))
-#define SCM_PROCEDUREP(a) ((SCM_FUNCP(a)                                     \
-                            && !(SCM_FUNC_TYPECODE(a) & SCM_FUNCTYPE_SYNTAX)) \
-                           || SCM_CLOSUREP(a)                                \
-                           || SCM_CONTINUATIONP(a))
-
-/*============================================================================
    Real Accessors : Port
 ============================================================================*/
 #define SCM_PORT_IMPL(a)                 ((ScmCharPort*)SCM_CAR_GET_VALUE_AS_PTR(SCM_AS_PORT(a)))
@@ -616,31 +587,44 @@
 #define SCM_CONTINUATION_SET_TAG(a, val)    (SCM_CDR_SET_VALUE_AS_INT(SCM_AS_CONTINUATION(a), (val), SCM_TAG_OTHERS_VALUE_OFFSET_CONTINUATION, SCM_TAG_OTHERS_CONTINUATION))
 
 /*============================================================================
-   Real Accessors : CPointer
-============================================================================*/
-#define SCM_C_POINTER_VALUE(a)              ((void*)SCM_CAR_GET_VALUE_AS_PTR(SCM_AS_C_POINTER(a)))
-#define SCM_C_POINTER_SET_VALUE(a, val)     (SCM_CAR_SET_VALUE_AS_PTR(SCM_AS_C_POINTER(a), (val)))
+   Real Accessors : Pointer Handling Types (CFunc, CPointer, CFuncPointer)
 
-/*============================================================================
-   Real Accessors : CFuncPointer
+   GCC4.0 doesn't align the address of function, so we need to store LSB of
+   the function address to the cdr part.
 
-   
-   GCC4.0 doesn't align the address of function, so we need to store LSB of the function
-   address to the cdr part.
-  
-   FuncAddr = (S->car & ~0x01) | ((S->cdr >> SCM_TAG_OTHERS_VALUE_OFFSET_C_FUNCPOINTER_LSBADDR) & 0x1)
+   Addr = ((S->car & ~0x01)
+            | ((S->cdr >> lsboffset) & 0x1))
 ============================================================================*/
-#define SCM_C_FUNCPOINTER_OTHERSB(a)        (SCM_CAST_UINT(SCM_CAR_GET_VALUE_AS_PTR(a)))
-#define SCM_C_FUNCPOINTER_LSB(a)            (SCM_CDR_GET_VALUE_AS_INT((a), SCM_TAG_OTHERS_VALUE_OFFSET_C_FUNCPOINTER_LSBADDR) & 0x1)
-#define SCM_C_FUNCPOINTER_VALUE(a)          (SCM_WORD_CAST(ScmCFunc, SCM_C_FUNCPOINTER_OTHERSB(a) | SCM_C_FUNCPOINTER_LSB(a)))
+/* General Pointer Accessor */
+#define SCM_PTR_OTHERSBITS(a)       (SCM_CAST_UINT(SCM_CAR_GET_VALUE_AS_PTR(a)))
+#define SCM_PTR_RAW_LSB(a, offset)  (SCM_CAST_CDR_UINT(a) & (0x1 << (offset)))
+#define SCM_PTR_LSB(a, offset)      (SCM_CDR_GET_VALUE_AS_INT((a), (offset)) & 0x1)
+#define SCM_PTR_VALUE(a, lsboffset) ((void*)(SCM_PTR_OTHERSBITS(a) | SCM_PTR_LSB((a), (lsboffset))))
 
-#define SCM_C_FUNCPOINTER_SET_OTHERSB(a, val) (SCM_CAR_SET_VALUE_AS_PTR((a), (val)))
-#define SCM_C_FUNCPOINTER_SET_LSB(a, val)     (SCM_SET_DIRECT_CDR((a),  \
-                                                                  (SCM_CAST_CDR_UINT(a) \
-                                                                   | ((SCM_CAST_UINT(val) & 0x1) << SCM_TAG_OTHERS_VALUE_OFFSET_C_FUNCPOINTER_LSBADDR))))
-#define SCM_C_FUNCPOINTER_SET_VALUE(a, val)   (SCM_C_FUNCPOINTER_SET_OTHERSB((a), (SCM_CAST_UINT(val) & ~0x1)), \
-                                               SCM_C_FUNCPOINTER_SET_LSB((a), (SCM_CAST_UINT(val) & 0x1)))
+#define SCM_SET_PTR_OTHERSBITS(a, val)  (SCM_CAR_SET_VALUE_AS_PTR((a), SCM_WORD_CAST(ScmObj, (val))))
+#define SCM_SET_PTR_LSB(a, val, offset) (SCM_SET_DIRECT_CDR((a),         \
+                                                            (SCM_CAST_CDR_UINT(a) \
+                                                             | ((SCM_CAST_UINT(val) & 0x1) << (offset)))))
+#define SCM_SET_PTR_VALUE(a, val, lsboffset) (SCM_SET_PTR_OTHERSBITS((a), (val)), \
+                                              SCM_SET_PTR_LSB((a), (SCM_CAST_UINT(val) & 0x1), (lsboffset)))
 
+/* CFunc */
+#define SCM_FUNC_CFUNC(a) (SCM_WORD_CAST(ScmFuncType, SCM_PTR_VALUE((a), SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_LSBADDR)))
+#define SCM_FUNC_SET_CFUNC(a, val) (SCM_SET_PTR_VALUE((a), SCM_CAST_UINT(val), SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_LSBADDR))
+
+#define SCM_FUNC_TYPECODE(a) ((enum ScmFuncTypeCode)SCM_CDR_GET_VALUE_AS_INT((a), SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_FUNCTYPE))
+#define SCM_FUNC_SET_TYPECODE(a, val) (SCM_CDR_SET_VALUE_AS_INT((a), (val), SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_FUNCTYPE, \
+                                                                (SCM_TAG_OTHERS_FUNC \
+                                                                 | SCM_PTR_RAW_LSB((a), SCM_TAG_OTHERS_VALUE_OFFSET_FUNC_LSBADDR))))
+
+/* CPointer */
+#define SCM_C_POINTER_VALUE(a) (SCM_PTR_VALUE((a), SCM_TAG_OTHERS_VALUE_OFFSET_C_POINTER_LSBADDR))
+#define SCM_C_POINTER_SET_VALUE(a, val) (SCM_SET_PTR_VALUE((a), SCM_CAST_UINT(val), SCM_TAG_OTHERS_VALUE_OFFSET_C_POINTER_LSBADDR))
+
+/* CFuncPointer */
+#define SCM_C_FUNCPOINTER_VALUE(a) (SCM_WORD_CAST(ScmCFunc, SCM_PTR_VALUE((a), SCM_TAG_OTHERS_VALUE_OFFSET_C_FUNCPOINTER_LSBADDR)))
+#define SCM_C_FUNCPOINTER_SET_VALUE(a, val) (SCM_SET_PTR_VALUE((a), SCM_CAST_UINT(val), SCM_TAG_OTHERS_VALUE_OFFSET_C_FUNCPOINTER_LSBADDR))
+
 /*============================================================================
    Real Accessors : Int
 
@@ -681,6 +665,16 @@
 #define SCM_CHAR_SET_VALUE(a, ch) (SCM_PRIMARY_SET_VALUE_AS_INT((a), (ch), SCM_TAG_IMM_VALUE_OFFSET_CHAR, SCM_TAG_IMM_CHAR))
 
 /*=======================================
+   Misc Predicates
+=======================================*/
+#define SCM_SYNTAXP(a) (SCM_FUNCP(a)                                    \
+                        && (SCM_FUNC_TYPECODE(a) & SCM_FUNCTYPE_SYNTAX))
+#define SCM_PROCEDUREP(a) ((SCM_FUNCP(a)                                \
+                            && !(SCM_FUNC_TYPECODE(a) & SCM_FUNCTYPE_SYNTAX)) \
+                           || SCM_CLOSUREP(a)                           \
+                           || SCM_CONTINUATIONP(a))
+
+/*=======================================
    Scheme Special Constants
 =======================================*/
 #define SCM_NULL        ((ScmObj)(SCM_IMM_NULL))



More information about the uim-commit mailing list