From 8d3356e761c0469c124e4e88de3ec3b835d4069c Mon Sep 17 00:00:00 2001 From: Dirk Herrmann Date: Sat, 25 Mar 2000 08:26:38 +0000 Subject: [PATCH] * Allow to activate strict compile time type checking by defining the macro SCM_STRICT_TYPING. * Defined SCM_EQ_P as a macro equivalent for eq?. --- libguile/ChangeLog | 9 ++++++++ libguile/tags.h | 51 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 1bb8644f7..d2a3c7db3 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,12 @@ +2000-03-25 Dirk Herrmann + + * tags.h (SCM_STRICT_TYPING): New macro that, if defined, + activates strict compile time type checking for variables of + type SCM. + (SCM, SCM_PACK, SCM_UNPACK): Define according to whether + SCM_STRICT_TYPING or SCM_VOIDP_TEST are defined. + (SCM_EQ_P): Defined as a macro equivalent for eq?. + 2000-03-25 Dirk Herrmann * tags.h (SCM_POINTERS_MUNGED): Removed. diff --git a/libguile/tags.h b/libguile/tags.h index 9da09aa80..720a3af3d 100644 --- a/libguile/tags.h +++ b/libguile/tags.h @@ -54,25 +54,50 @@ +/* #define SCM_STRICT_TYPING */ +/* #define SCM_VOIDP_TEST */ /* In the beginning was the Word: */ typedef long scm_bits_t; -/* - But as external interface, we use void*, which will be checked more strictly for - dubious conversions. + +/* But as external interface, we use SCM, which may, according to the desired + * level of type checking, be defined in several ways: */ -/* #define SCM_VOIDP_TEST */ -#ifndef SCM_VOIDP_TEST -typedef scm_bits_t SCM; -#define SCM_UNPACK(x) (x) -#define SCM_PACK(x) (x) +#if defined (SCM_STRICT_TYPING) +/* Use this for _compile time_ type checking only, since the compiled result + * will be quite inefficient. The right way to make use of this mode is to do + * a 'make clean' of your project, 'make all CFLAGS=-DSCM_STRICT_TYPING', fix + * your errors, and then do 'make clean; make all'. +*/ + typedef union { struct { scm_bits_t n; } n; } SCM; + static SCM scm_pack(scm_bits_t b) { SCM s; s.n.n = b; return s; } + #define SCM_UNPACK(x) ((x).n.n) + #define SCM_PACK(x) (scm_pack (x)) +#elif defined (SCM_VOIDP_TEST) +/* This is the default, which provides an intermediate level of compile time + * type checking while still resulting in very efficient code. + */ + typedef void * SCM; + #define SCM_UNPACK(x) ((scm_bits_t) (x)) + #define SCM_PACK(x) ((SCM) (x)) #else -typedef void * SCM; -#define SCM_UNPACK(x) ((scm_bits_t) (x)) -#define SCM_PACK(x) ((SCM) (x)) +/* This should be used as a fall back solution for machines on which casting + * to a pointer may lead to loss of bit information, e. g. in the three least + * significant bits. + */ + typedef scm_bits_t SCM; + #define SCM_UNPACK(x) (x) + #define SCM_PACK(x) (x) #endif + +/* SCM values can not be compared by using the operator ==. Use the following + * macro instead, which is the equivalent of the scheme predicate 'eq?'. + */ +#define SCM_EQ_P(x, y) (SCM_UNPACK (x) == SCM_UNPACK (y)) + + /* SCM_UNPACK_CAR is a convenience for treating the CAR of X as a word */ #define SCM_UNPACK_CAR(x) SCM_UNPACK (SCM_CAR (x)) @@ -81,8 +106,8 @@ typedef void * SCM; * rather than each byte, the 3 most significant bits encode the byte * within the word. The following macros deal with this by storing the * native Cray pointers like the ones that looks like scm expects. This - * is done for any pointers that might appear in the car of a scm_cell, pointers - * to scm_vector elts, functions, &c are not munged. + * is done for any pointers that might appear in the car of a scm_cell, + * pointers to scm_vector elts, functions, &c are not munged. */ #ifdef _UNICOS # define SCM2PTR(x) ((void *) (SCM_UNPACK (x) >> 3))