*** empty log message ***
[bpt/guile.git] / libguile / tags.h
index 27b36e4..f0d953c 100644 (file)
@@ -2,7 +2,7 @@
 
 #ifndef TAGSH
 #define TAGSH
-/* Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 \f
 
+
 /* In the beginning was the Word:
  */
-typedef long SCM;
+typedef long scm_bits_t;
+/*
+  But as external interface, we use void*, which will be checked more strictly for
+  dubious conversions.
+ */
+#define SCM_VOIDP_TEST
+#ifndef SCM_VOIDP_TEST
+typedef scm_bits_t  SCM;
+#define SCM_UNPACK(x) (x)
+#define SCM_PACK(x) (x)
+#else
+typedef void * SCM;
+#define SCM_UNPACK(x) ((scm_bits_t) (x))
+#define SCM_PACK(x) ((SCM) (x))
+#endif
 
+/* 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))
 
 
 /* Cray machines have pointers that are incremented once for each word,
@@ -106,7 +123,7 @@ typedef long SCM;
  * (Not always impossible but it is fair to say that many details of tags
  * are mutually dependent).  */
 
-#define SCM_IMP(x)             (6 & (SCM) (x))
+#define SCM_IMP(x)             (6 & SCM_UNPACK (x))
 #define SCM_NIMP(x)            (!SCM_IMP (x))
 
 /* Here is a summary of tagging in SCM values as they might occur in
@@ -264,11 +281,11 @@ typedef long SCM;
  * stored in the SCM_CAR of a non-immediate object have a 1 in bit 1:
  */
 
-#define SCM_SLOPPY_NCONSP(x) (1 & SCM_CAR (x))
-#define SCM_SLOPPY_CONSP(x)  (!(1 & SCM_CAR (x)))
+#define SCM_SLOPPY_NCONSP(x) (1 & SCM_UNPACK_CAR (x))
+#define SCM_SLOPPY_CONSP(x)  (!SCM_SLOPPY_NCONSP (x))
 
-#define SCM_NCONSP(x) (SCM_IMP (x)  || (1 & SCM_CAR (x)))
-#define SCM_CONSP(x)  (SCM_NIMP (x) && !(1 & SCM_CAR (x)))
+#define SCM_NCONSP(x) (SCM_IMP (x) || SCM_SLOPPY_NCONSP (x))
+#define SCM_CONSP(x)  (SCM_NIMP (x) && SCM_SLOPPY_CONSP (x))
 
 
 /* SCM_ECONSP should be used instead of SCM_CONSP at places where GLOCS
@@ -286,21 +303,21 @@ typedef long SCM;
 \f
 
 #define SCM_CELLP(x)   (!SCM_NCELLP (x))
-#define SCM_NCELLP(x)  ((sizeof (scm_cell) - 1) & (SCM) (x))
+#define SCM_NCELLP(x)  ((sizeof (scm_cell) - 1) & SCM_UNPACK (x))
 
 /* See numbers.h for macros relating to immediate integers.
  */
 
-#define SCM_ITAG3(x)           (7 & (SCM) x)
-#define SCM_TYP3(x)            (7 & SCM_CAR (x))
+#define SCM_ITAG3(x)           (7 & SCM_UNPACK (x))
+#define SCM_TYP3(x)            (7 & SCM_UNPACK_CAR (x))
 #define scm_tc3_cons           0
 #define scm_tc3_cons_gloc      1
 #define scm_tc3_int_1          2
-#define scm_tc3_closure                3
-#define scm_tc3_imm24          4
-#define scm_tc3_tc7_1          5
-#define scm_tc3_int_2          6
-#define scm_tc3_tc7_2          7
+#define scm_tc3_closure                 3
+#define scm_tc3_imm24           4
+#define scm_tc3_tc7_1           5
+#define scm_tc3_int_2           6
+#define scm_tc3_tc7_2           7
 
 
 /*
@@ -308,20 +325,20 @@ typedef long SCM;
  */
 
 
-#define SCM_TYP7(x)            (SCM_CAR (x) & 0x7f)
-#define SCM_TYP7S(x)           (SCM_CAR (x) & (0x7f & ~2))
+#define SCM_TYP7(x)            (0x7f &        SCM_UNPACK_CAR (x))
+#define SCM_TYP7S(x)           ((0x7f & ~2) & SCM_UNPACK_CAR (x))
 
 
-#define SCM_TYP16(x)           (0xffff & SCM_CAR (x))
-#define SCM_TYP16S(x)          (0xfeff & SCM_CAR (x))
-#define SCM_GCTYP16(x)                 (0xff7f & SCM_CAR (x))
+#define SCM_TYP16(x)           (0xffff & SCM_UNPACK_CAR (x))
+#define SCM_TYP16S(x)          (0xfeff & SCM_UNPACK_CAR (x))
+#define SCM_GCTYP16(x)                 (0xff7f & SCM_UNPACK_CAR (x))
 
 
 
 /* Testing and Changing GC Marks in Various Standard Positions
  */
-#define SCM_GCMARKP(x)                 (1 & SCM_CDR (x))
-#define SCM_GC8MARKP(x)        (0x80 & SCM_CAR (x))
+#define SCM_GCMARKP(x)                 (1 & SCM_UNPACK (SCM_CDR (x)))
+#define SCM_GC8MARKP(x)        (0x80 & SCM_UNPACK_CAR (x))
 #define SCM_SETGCMARK(x)       SCM_SETOR_CDR (x, 1)
 #define SCM_CLRGCMARK(x)       SCM_SETAND_CDR (x, ~1L)
 #define SCM_SETGC8MARK(x)      SCM_SETOR_CAR (x, 0x80)
@@ -437,9 +454,9 @@ enum scm_tags
   scm_tc8_iloc = 0xfc
 };
 
-#define SCM_ITAG8(X)           ((SCM) (X) & 0xff)
-#define SCM_MAKE_ITAG8(X, TAG) (((X) << 8) + TAG)
-#define SCM_ITAG8_DATA(X)      ((X) >> 8)
+#define SCM_ITAG8(X)           (SCM_UNPACK (X) & 0xff)
+#define SCM_MAKE_ITAG8(X, TAG) SCM_PACK (((X) << 8) + TAG)
+#define SCM_ITAG8_DATA(X)      (SCM_UNPACK (X) >> 8)
 
 
 \f
@@ -447,15 +464,15 @@ enum scm_tags
  */
 
 /* SCM_ISYMP tests for ISPCSYM and ISYM */
-#define SCM_ISYMP(n)           ((0x187 & (SCM) (n)) == 4)
+#define SCM_ISYMP(n)           ((0x187 & SCM_UNPACK (n)) == 4)
 
 /* SCM_IFLAGP tests for ISPCSYM, ISYM and IFLAG */
-#define SCM_IFLAGP(n)          ((0x87 & (SCM) (n)) == 4)
-#define SCM_ISYMNUM(n)                 ((SCM) ((n) >> 9))
+#define SCM_IFLAGP(n)          ((0x87 & SCM_UNPACK (n)) == 4)
+#define SCM_ISYMNUM(n)                 (SCM_UNPACK (n) >> 9)
 #define SCM_ISYMCHARS(n)       (scm_isymnames[SCM_ISYMNUM (n)])
-#define SCM_MAKSPCSYM(n)       (((n) << 9) + ((n) << 3) + 4L)
-#define SCM_MAKISYM(n)                 (((n) << 9) + 0x74L)
-#define SCM_MAKIFLAG(n)        (((n) << 9) + 0x174L)
+#define SCM_MAKSPCSYM(n)       SCM_PACK (((n) << 9) + ((n) << 3) + 4L)
+#define SCM_MAKISYM(n)                 SCM_PACK (((n) << 9) + 0x74L)
+#define SCM_MAKIFLAG(n)        SCM_PACK (((n) << 9) + 0x174L)
 
 extern char *scm_isymnames[];   /* defined in print.c */