[uim-commit] r2929 - in branches/r5rs/sigscheme: . src

yamaken at freedesktop.org yamaken at freedesktop.org
Sun Jan 15 07:41:34 PST 2006


Author: yamaken
Date: 2006-01-15 07:41:30 -0800 (Sun, 15 Jan 2006)
New Revision: 2929

Modified:
   branches/r5rs/sigscheme/configure.in
   branches/r5rs/sigscheme/src/config.h
   branches/r5rs/sigscheme/src/encoding.h
   branches/r5rs/sigscheme/src/sigscheme.h
Log:
* This commit add abstract primitive types to make 64bit platforms
  capable. Please let me know your opinion about this organization and
  names. I'll start rewriting all codes soon after this commit.

* sigscheme/configure.in
  - Add AC_CHECK_SIZEOF for primitives and stdint types
* sigscheme/src/config.h
  - (SCM_USE_64BIT_FIXNUM, SCM_USE_32BIT_FIXNUM, SCM_USE_INT_FIXNUM,
    SCM_USE_LONG_FIXNUM, SCM_USE_64BIT_SCMREF, SCM_USE_32BIT_SCMREF,
    SCM_USE_INTPTR_SCMREF): New macro
* sigscheme/src/encoding.h
  - (SCM_HAS_2OCT_WCHAR, SCM_HAS_4OCT_WCHAR): New macro
* sigscheme/src/sigscheme.h
  - Include stdint.h
  - (scm_int_t, scm_uint_t, scm_intref_t, scm_uintref_t, scm_intobj_t,
    scm_uintobj_t, scm_ichar_t, scm_byte_t, scm_wchar_t): New type
  - (SIZEOF_SCM_INT_T, SIZEOF_SCM_UINT_T, SCM_USE_LONG_FIXNUM,
    SIZEOF_SCM_INTREF_T, SIZEOF_SCM_UINTREF_T, SCM_USE_INTPTR_SCMREF,
    SIZEOF_SCM_INTOBJ_T, SIZEOF_SCM_UINTOBJ_T, SIZEOF_SCM_ICHAR_T,
    SIZEOF_SCM_BYTE_T, SIZEOF_SCM_WCHAR_T): New macro


Modified: branches/r5rs/sigscheme/configure.in
===================================================================
--- branches/r5rs/sigscheme/configure.in	2006-01-15 03:46:31 UTC (rev 2928)
+++ branches/r5rs/sigscheme/configure.in	2006-01-15 15:41:30 UTC (rev 2929)
@@ -25,6 +25,29 @@
 AC_TYPE_SIZE_T
 AC_C_VOLATILE
 
+AC_CHECK_SIZEOF(short)
+AC_CHECK_SIZEOF(int)
+AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(float)
+AC_CHECK_SIZEOF(double)
+AC_CHECK_SIZEOF(long double)
+AC_CHECK_SIZEOF(void *)
+
+# Do not assume (sizeof(int32_t) == 4) and so on
+AC_CHECK_SIZEOF(int16_t)
+AC_CHECK_SIZEOF(int32_t)
+AC_CHECK_SIZEOF(int64_t)
+AC_CHECK_SIZEOF(int_least8_t)
+AC_CHECK_SIZEOF(int_least16_t)
+AC_CHECK_SIZEOF(int_least32_t)
+AC_CHECK_SIZEOF(int_least64_t)
+AC_CHECK_SIZEOF(int_fast8_t)
+AC_CHECK_SIZEOF(int_fast16_t)
+AC_CHECK_SIZEOF(int_fast32_t)
+AC_CHECK_SIZEOF(int_fast64_t)
+AC_CHECK_SIZEOF(intmax_t)
+AC_CHECK_SIZEOF(intptr_t)
+
 # Checks for library functions.
 
 # FIXME: provide alternative source code

Modified: branches/r5rs/sigscheme/src/config.h
===================================================================
--- branches/r5rs/sigscheme/src/config.h	2006-01-15 03:46:31 UTC (rev 2928)
+++ branches/r5rs/sigscheme/src/config.h	2006-01-15 15:41:30 UTC (rev 2929)
@@ -95,7 +95,7 @@
 #define SCM_GCC4_READY_GC       1  /* use experimental gcc4-ready stack protection */
 
 /*===========================================================================
-  Tunings
+  Memory configurations
 ===========================================================================*/
 /* on-stack initial token buffer size for parser */
 #define SCM_INITIAL_STRING_BUF_SIZE 64
@@ -116,6 +116,15 @@
 #define SCM_DEFAULT_N_HEAPS_INIT         1
 #define SCM_DEFAULT_SYMBOL_HASH_SIZE     0x400
 
+#define SCM_USE_64BIT_FIXNUM    0 /* use int64_t  as scm_int_t */
+#define SCM_USE_32BIT_FIXNUM    0 /* use int32_t  as scm_int_t */
+#define SCM_USE_INT_FIXNUM      0 /* use int      as scm_int_t */
+#define SCM_USE_LONG_FIXNUM     0 /* use long     as scm_int_t (default) */
+
+#define SCM_USE_64BIT_SCMREF    0 /* use int64_t  as scm_intref_t */
+#define SCM_USE_32BIT_SCMREF    0 /* use int32_t  as scm_intref_t */
+#define SCM_USE_INTPTR_SCMREF   0 /* use intptr_t as scm_intref_t (default) */
+
 /*===========================================================================
   Debugging
 ===========================================================================*/

Modified: branches/r5rs/sigscheme/src/encoding.h
===================================================================
--- branches/r5rs/sigscheme/src/encoding.h	2006-01-15 03:46:31 UTC (rev 2928)
+++ branches/r5rs/sigscheme/src/encoding.h	2006-01-15 15:41:30 UTC (rev 2929)
@@ -53,6 +53,9 @@
 
 #define SCM_MB_MAX_LEN 4
 
+#define SCM_HAS_2OCT_WCHAR 0
+#define SCM_HAS_4OCT_WCHAR 0
+
 #define SCM_MBCINFO_SET_SIZE(inf, siz)   ((inf).size = (siz))
 #define SCM_MBCINFO_GET_SIZE(inf)        ((inf).size)
 #if SCM_USE_STATEFUL_ENCODING

Modified: branches/r5rs/sigscheme/src/sigscheme.h
===================================================================
--- branches/r5rs/sigscheme/src/sigscheme.h	2006-01-15 03:46:31 UTC (rev 2928)
+++ branches/r5rs/sigscheme/src/sigscheme.h	2006-01-15 15:41:30 UTC (rev 2929)
@@ -42,6 +42,7 @@
    System Include
 =======================================*/
 #include <limits.h>
+#include <stdint.h> /* FIXME: make C99-independent */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -226,9 +227,11 @@
 /*============================================================================
   Type Definitions
 ============================================================================*/
-
+/*=======================================
+   Primitive Types
+=======================================*/
 /*
- * SigScheme's own Boolean type:
+ * SigScheme's own Boolean type
  *
  * libsscm does not use C99 stdbool, its autoconf equivalent or popular
  * combination of {int, TRUE, FALSE}, to avoid system-dependent ABI
@@ -250,6 +253,170 @@
 #define scm_true  (!scm_false)
 #endif
 
+/*
+ * Fixed bit width numbers
+ *
+ * This types define internal representation corresponding to each number
+ * objects of Scheme.
+ *
+ * The configuration alters both ABI and storage implementation of
+ * libsscm. Although it specifies the bit width, actual width varies for each
+ * substantial storage implementation. Refer SCM_INT_BITS, SCM_INT_MAX and so
+ * on to know such values.
+ *
+ * The integer type defaults to 64bit on LP64 platforms.
+ */
+#if SCM_USE_64BIT_FIXNUM
+typedef int64_t           scm_int_t;
+typedef uint64_t          scm_uint_t;
+#define SIZEOF_SCM_INT_T  SIZEOF_INT64_T
+#define SIZEOF_SCM_UINT_T SIZEOF_INT64_T
+#elif SCM_USE_32BIT_FIXNUM
+typedef int32_t           scm_int_t;
+typedef uint32_t          scm_uint_t;
+#define SIZEOF_SCM_INT_T  SIZEOF_INT32_T
+#define SIZEOF_SCM_UINT_T SIZEOF_INT32_T
+#elif SCM_USE_INT_FIXNUM
+typedef int               scm_int_t;
+typedef unsigned int      scm_uint_t;
+#define SIZEOF_SCM_INT_T  SIZEOF_INT
+#define SIZEOF_SCM_UINT_T SIZEOF_INT
+#else
+#undef  SCM_USE_LONG_FIXNUM
+#define SCM_USE_LONG_FIXNUM
+typedef long              scm_int_t;
+typedef unsigned long     scm_uint_t;
+#define SIZEOF_SCM_INT_T  SIZEOF_LONG
+#define SIZEOF_SCM_UINT_T SIZEOF_LONG
+#endif
+
+/*
+ * Integer representation of abstract reference to ScmObj
+ *
+ * This types define sufficient width integer which is capable of holding any
+ * ScmRef that is used in currently selected storage implementation.
+ *
+ * A ScmRef is abstract reference to a ScmObj. It is usually a pointer, but do
+ * not assume it since another representation may be used. For instance, a pair
+ * of heap index and object index in the heap can be a ScmRef. In such case,
+ * scm_uintref_t can address any object in a heap scattered in full 64bit
+ * address space even if the bit width of the reference is smaller than a 64bit
+ * pointer. So any size assumption between pointer and the reference must not
+ * be coded.
+ *
+ * The integer representation is intended for low-level bitwise processing. Use
+ * ScmRef instead for higher-level code.
+ *
+ * Since actual representation is entirely controlled in each storage
+ * implementation, this configuration only specifies the ABI about maximum size
+ * of reference objects. Deal with particular storage implementation if fine
+ * tuning is required. Otherwise simply keep untouched.
+ *
+ * The type defaults to direct pointer represenation, so *LP64 gets 64bit.
+ */
+#if SCM_USE_64BIT_SCMREF
+typedef int64_t              scm_intref_t;
+typedef uint64_t             scm_uintref_t;
+#define SIZEOF_SCM_INTREF_T  SIZEOF_INT64_T
+#define SIZEOF_SCM_UINTREF_T SIZEOF_INT64_T
+#elif SCM_USE_32BIT_SCMREF
+typedef int32_t              scm_intref_t;
+typedef uint32_t             scm_uintref_t;
+#define SIZEOF_SCM_INTREF_T  SIZEOF_INT32_T
+#define SIZEOF_SCM_UINTREF_T SIZEOF_INT32_T
+#else
+#undef  SCM_USE_INTPTR_SCMREF
+#define SCM_USE_INTPTR_SCMREF
+typedef intptr_t             scm_intref_t;
+typedef uintptr_t            scm_uintref_t;
+#define SIZEOF_SCM_INTREF_T  SIZEOF_INTPTR_T
+#define SIZEOF_SCM_UINTREF_T SIZEOF_INTPTR_T
+#endif
+
+/*
+ * Integer representation of ScmObj
+ *
+ * This types define sufficient width integer which is capable of holding the
+ * ScmObj that is used in currently selected storage implementation.
+ *
+ * A ScmObj is abstract Scheme object. Its represenation and size vary for each
+ * storage implementations. But the size is surely defined as larger one of
+ * scm_uint_t and scm_uintref_t. It can be assumed on coding.
+ *
+ * The integer representation is intended for low-level bitwise processing. Use
+ * ScmObj instead for higher-level code.
+ *
+ * This configuration is passively chosen in accordance with the fixnum size
+ * and reference size. And of course alters the ABI.
+ */
+#if (SIZEOF_SCM_INT_T < SIZEOF_SCM_INTREF_T)
+typedef scm_intref_t         scm_intobj_t;
+typedef scm_uintref_t        scm_uintobj_t;
+#define SIZEOF_SCM_INTOBJ_T  SIZEOF_SCM_INTREF_T
+#define SIZEOF_SCM_UINTOBJ_T SIZEOF_SCM_UINTREF_T
+#else
+typedef scm_int_t            scm_intobj_t;
+typedef scm_uint_t           scm_uintobj_t;
+#define SIZEOF_SCM_INTOBJ_T  SIZEOF_SCM_INT_T
+#define SIZEOF_SCM_UINTOBJ_T SIZEOF_SCM_UINT_T
+#endif
+
+/*
+ * Internal integer representation of Scheme character object
+ *
+ * The type is used to pass a Scheme-level character object in C codes.
+ *
+ * It is distinguished from the element of fixed-width character string
+ * (scm_wchar_t). This integer type is defined as broad as capable of any
+ * multibyte char, and not configurable, to keep ABI stable regardless of
+ * configuration about scm_wchar_t.
+ *
+ * Actual bit width varies for each storage implementation. Refer
+ * SCM_CHAR_BITS, SCM_CHAR_MAX and SCM_CHAR_MIN if needed.
+ */
+typedef int32_t            scm_ichar_t;
+#define SIZEOF_SCM_ICHAR_T SIZEOF_INT32_T
+
+/*
+ * Definitive byte type
+ *
+ * To avoid the sign-extension problem, platform-dependent signedness variation
+ * (for example, ARM compilers treat 'char' as 'unsigned char'), use this type
+ * for raw strings and so on.
+ */
+typedef unsigned char     scm_byte_t;
+#define SIZEOF_SCM_BYTE_T 1
+
+/*
+ * Constant-width character for strings (not used yet)
+ */
+#if SCM_HAS_4OCT_WCHAR
+typedef uint32_t           scm_wchar_t;
+#define SIZEOF_SCM_WCHAR_T SIZEOF_INT32_T
+#elif SCM_HAS_2OCT_WCHAR
+typedef uint16_t           scm_wchar_t;
+#define SIZEOF_SCM_WCHAR_T SIZEOF_INT16_T
+#else
+typedef scm_byte_t         scm_wchar_t;
+#define SIZEOF_SCM_WCHAR_T SIZEOF_SCM_BYTE_T
+#endif
+
+/* size constraints */
+#if !(   SIZEOF_SCM_INT_T    == SIZEOF_SCM_UINT_T                            \
+      && SIZEOF_SCM_INTREF_T == SIZEOF_SCM_UINTREF_T                         \
+      && SIZEOF_SCM_INTOBJ_T == SIZEOF_SCM_UINTOBJ_T                         \
+      && SIZEOF_SCM_INTREF_T <= SIZEOF_SCM_INTOBJ_T                          \
+      && SIZEOF_SCM_INT_T    <= SIZEOF_SCM_INTOBJ_T                          \
+      && (   SIZEOF_SCM_INTREF_T <= SIZEOF_SCM_INT_T                         \
+          || SIZEOF_SCM_INTREF_T >= SIZEOF_SCM_INT_T)                        \
+      && SIZEOF_SCM_WCHAR_T  <= SIZEOF_SCM_ICHAR_T                           \
+      && SIZEOF_SCM_ICHAR_T  <= SIZEOF_SCM_INT_T)
+#error "size constraints of primitive types are broken"
+#endif
+
+/*=======================================
+   Enums
+=======================================*/
 enum ScmDebugCategory {
     SCM_DBG_NONE         = 0,
     SCM_DBG_ERRMSG       = 1 << 0,   /* the "Error: foo bar" style msgs */



More information about the uim-commit mailing list