*** empty log message ***
[bpt/guile.git] / libguile / tags.h
index a9b9acb..9e61ce1 100644 (file)
@@ -2,7 +2,7 @@
 
 #ifndef TAGSH
 #define TAGSH
-/* Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1995-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
  * If you write modifications of your own for GUILE, it is your choice
  * whether to permit this exception to apply to your modifications.
  * If you do not wish that, delete this exception notice.  */
+
+/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
+   gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
+
 \f
 
 /** This file defines the format of SCM values and cons pairs.
 
 \f
 
+
 /* In the beginning was the Word:
  */
-typedef long SCM;
+typedef long SCMWORD;
+/*
+  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 SCMWORD  SCM;
+#define SCM_ASWORD(x) (x)
+#define SCM_ASSCM(x) (x)
+#else
+typedef void * SCM;
+#define SCM_ASWORD(x) ((SCMWORD) (x))
+#define SCM_ASSCM(x) ((SCM) (x))
+#endif
 
+/* SCM_CARW is a convenience for treating the CAR of X as a word */
+#define SCM_CARW(x) SCM_ASWORD (SCM_CAR (x))
 
 
 /* Cray machines have pointers that are incremented once for each word,
@@ -64,12 +85,12 @@ typedef long SCM;
  * to scm_vector elts, functions, &c are not munged.
  */
 #ifdef _UNICOS
-# define SCM2PTR(x) ((int)(x) >> 3)
-# define PTR2SCM(x) (((SCM)(x)) << 3)
+# define SCM2PTR(x) ((int) (x) >> 3)
+# define PTR2SCM(x) (((SCM) (x)) << 3)
 # define SCM_POINTERS_MUNGED
 #else
 # define SCM2PTR(x) (x)
-# define PTR2SCM(x) ((SCM)(x))
+# define PTR2SCM(x) ((SCM) (x))
 #endif /* def _UNICOS */
 
 \f
@@ -102,8 +123,8 @@ 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_NIMP(x)            (!SCM_IMP(x))
+#define SCM_IMP(x)             (6 & SCM_ASWORD (x))
+#define SCM_NIMP(x)            (!SCM_IMP (x))
 
 /* Here is a summary of tagging in SCM values as they might occur in
  * SCM variables or in the heap.
@@ -260,38 +281,43 @@ typedef long SCM;
  * stored in the SCM_CAR of a non-immediate object have a 1 in bit 1:
  */
 
-#define SCM_NCONSP(x) (1 & SCM_CAR(x))
-#define SCM_CONSP(x) (!SCM_NCONSP(x))
+#define SCM_SLOPPY_NCONSP(x) (1 & SCM_CARW (x))
+#define SCM_SLOPPY_CONSP(x)  (!SCM_SLOPPY_NCONSP (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
  * can be expected to occur.
  */
-#define SCM_ECONSP(x) (SCM_CONSP (x) \
-                      || (SCM_TYP3(x) == 1 \
-                           && SCM_CDR (SCM_CAR (x) - 1) != 0))
-#define SCM_NECONSP(x) (SCM_NCONSP(x) \
-                       && (SCM_TYP3(x) != 1 \
-                           || SCM_CDR (SCM_CAR (x) - 1) == 0))
+#define SCM_ECONSP(x) (SCM_NIMP (x) \
+                      && (SCM_SLOPPY_CONSP (x) \
+                          || (SCM_TYP3 (x) == 1 \
+                              && SCM_CDR (SCM_CAR (x) - 1) != 0)))
+#define SCM_NECONSP(x) (SCM_IMP (x) \
+                       || (SCM_SLOPPY_NCONSP (x) \
+                           && (SCM_TYP3 (x) != 1 \
+                               || SCM_CDR (SCM_CAR (x) - 1) == 0)))
 
 \f
 
-#define SCM_CELLP(x)   (!SCM_NCELLP(x))
-#define SCM_NCELLP(x)  ((sizeof(scm_cell)-1) & (SCM)(x))
+#define SCM_CELLP(x)   (!SCM_NCELLP (x))
+#define SCM_NCELLP(x)  ((sizeof (scm_cell) - 1) & (SCMWORD) SCM_ASWORD (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_ASWORD (x))
+#define SCM_TYP3(x)            (7 & SCM_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
 
 
 /*
@@ -299,21 +325,21 @@ 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_CARW (x))
+#define SCM_TYP7S(x)           ((0x7f & ~2) & SCM_CARW (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_CAR(x))
+#define SCM_TYP16S(x)          (0xfeff & SCM_CAR(x))
+#define SCM_GCTYP16(x)                 (0xff7f & SCM_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_SETGCMARK(x)       SCM_SETOR_CDR (x,1)
+#define SCM_GCMARKP(x)                 (1 & SCM_ASWORD (SCM_CDR (x)))
+#define SCM_GC8MARKP(x)        (0x80 & SCM_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)
 #define SCM_CLRGC8MARK(x)      SCM_SETAND_CAR (x, ~0x80L)
@@ -337,20 +363,24 @@ typedef long SCM;
  * into structs or smobs.  We need back some
  * of these 7 bit tags!
  */
-#define scm_tc7_llvect          29
 #define scm_tc7_pws            31
-#define scm_tc7_uvect          37
 #define scm_tc7_lvector                39
+
+#ifdef HAVE_ARRAYS
+#define scm_tc7_llvect          29
+#define scm_tc7_uvect          37
 #define scm_tc7_fvect          45
 #define scm_tc7_dvect          47
 #define scm_tc7_cvect          53
 #define scm_tc7_svect          55
-#define scm_tc7_contin         61
-#define scm_tc7_cclo           63
-#define scm_tc7_rpsubr         69
 #define scm_tc7_bvect          71
 #define scm_tc7_byvect         77
 #define scm_tc7_ivect          79
+#endif
+
+#define scm_tc7_contin         61
+#define scm_tc7_cclo           63
+#define scm_tc7_rpsubr         69
 #define scm_tc7_subr_0         85
 #define scm_tc7_subr_1         87
 #define scm_tc7_cxr            93
@@ -368,10 +398,10 @@ typedef long SCM;
  */
 #define scm_tc7_port           125
 
-#define scm_tc16_fport                 (scm_tc7_port + 0*256L)
+#define scm_tc16_fport                 (scm_tc7_port + 0 * 256L)
 /* scm_tc16_pipe was here.  */
-#define scm_tc16_strport       (scm_tc7_port + 2*256L)
-#define scm_tc16_sfport        (scm_tc7_port + 3*256L)
+#define scm_tc16_strport       (scm_tc7_port + 2 * 256L)
+#define scm_tc16_sfport        (scm_tc7_port + 3 * 256L)
 
 
 /* There are 256 smob subtypes.  Here are the first four.
@@ -396,10 +426,10 @@ typedef long SCM;
 
 /* Some option bits begeinning at bit 16 of scm_tc16_flo:
  */
-#define SCM_REAL_PART          (1L<<16)
-#define SCM_IMAG_PART          (2L<<16)
-#define scm_tc_dblr            (scm_tc16_flo|SCM_REAL_PART)
-#define scm_tc_dblc            (scm_tc16_flo|SCM_REAL_PART|SCM_IMAG_PART)
+#define SCM_REAL_PART          (1L << 16)
+#define SCM_IMAG_PART          (2L << 16)
+#define scm_tc_dblr            (scm_tc16_flo | SCM_REAL_PART)
+#define scm_tc_dblc            (scm_tc16_flo | SCM_REAL_PART | SCM_IMAG_PART)
 
 
 /* Smob types 2 and 3:
@@ -407,6 +437,12 @@ typedef long SCM;
 #define scm_tc16_bigpos                0x027f
 #define scm_tc16_bigneg                0x037f
 
+/* Smob type 4: this is allocated, but not initialized cells;
+   this is required to prevent the gc from hosing your cells if
+   you have to allocate while creating the cell*/
+
+#define scm_tc16_allocated      0x047f
+
 
 \f
 /* {Immediate Values}
@@ -418,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_ASWORD (X) & 0xff)
+#define SCM_MAKE_ITAG8(X, TAG) SCM_ASSCM (((X) << 8) + TAG)
+#define SCM_ITAG8_DATA(X)      (SCM_ASWORD (X) >> 8)
 
 
 \f
@@ -428,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_ASWORD (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_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_IFLAGP(n)          ((0x87 & SCM_ASWORD (n)) == 4)
+#define SCM_ISYMNUM(n)                 (SCM_ASWORD (n) >> 9)
+#define SCM_ISYMCHARS(n)       (scm_isymnames[SCM_ISYMNUM (n)])
+#define SCM_MAKSPCSYM(n)       SCM_ASSCM (((n) << 9) + ((n) << 3) + 4L)
+#define SCM_MAKISYM(n)                 SCM_ASSCM (((n) << 9) + 0x74L)
+#define SCM_MAKIFLAG(n)        SCM_ASSCM (((n) << 9) + 0x174L)
 
 extern char *scm_isymnames[];   /* defined in print.c */
 
@@ -448,50 +484,60 @@ extern char *scm_isymnames[];   /* defined in print.c */
  *
  */
 
-#define SCM_IM_AND             SCM_MAKSPCSYM(0)
-#define SCM_IM_BEGIN           SCM_MAKSPCSYM(1)
-#define SCM_IM_CASE            SCM_MAKSPCSYM(2)
-#define SCM_IM_COND            SCM_MAKSPCSYM(3)
-#define SCM_IM_DO              SCM_MAKSPCSYM(4)
-#define SCM_IM_IF              SCM_MAKSPCSYM(5)
-#define SCM_IM_LAMBDA          SCM_MAKSPCSYM(6)
-#define SCM_IM_LET             SCM_MAKSPCSYM(7)
-#define SCM_IM_LETSTAR         SCM_MAKSPCSYM(8)
-#define SCM_IM_LETREC          SCM_MAKSPCSYM(9)
-#define SCM_IM_OR              SCM_MAKSPCSYM(10)
-#define SCM_IM_QUOTE           SCM_MAKSPCSYM(11)
-#define SCM_IM_SET_X           SCM_MAKSPCSYM(12)
-#define SCM_IM_DEFINE          SCM_MAKSPCSYM(13)
-#define SCM_IM_APPLY           SCM_MAKISYM(14)
-#define SCM_IM_CONT            SCM_MAKISYM(15)
-#define SCM_BOOL_F             SCM_MAKIFLAG(16)
-#define SCM_BOOL_T             SCM_MAKIFLAG(17)
-#define SCM_UNDEFINED          SCM_MAKIFLAG(18)
-#define SCM_EOF_VAL            SCM_MAKIFLAG(19)
-#define SCM_EOL                        SCM_MAKIFLAG(20)
-#define SCM_UNSPECIFIED                SCM_MAKIFLAG(21)
-#define SCM_IM_DISPATCH                SCM_MAKISYM(22)
-#define SCM_IM_SLOT_REF                SCM_MAKISYM(23)
-#define SCM_IM_SLOT_SET_X      SCM_MAKISYM(24)
+#define SCM_IM_AND             SCM_MAKSPCSYM (0)
+#define SCM_IM_BEGIN           SCM_MAKSPCSYM (1)
+#define SCM_IM_CASE            SCM_MAKSPCSYM (2)
+#define SCM_IM_COND            SCM_MAKSPCSYM (3)
+#define SCM_IM_DO              SCM_MAKSPCSYM (4)
+#define SCM_IM_IF              SCM_MAKSPCSYM (5)
+#define SCM_IM_LAMBDA          SCM_MAKSPCSYM (6)
+#define SCM_IM_LET             SCM_MAKSPCSYM (7)
+#define SCM_IM_LETSTAR         SCM_MAKSPCSYM (8)
+#define SCM_IM_LETREC          SCM_MAKSPCSYM (9)
+#define SCM_IM_OR              SCM_MAKSPCSYM (10)
+#define SCM_IM_QUOTE           SCM_MAKSPCSYM (11)
+#define SCM_IM_SET_X           SCM_MAKSPCSYM (12)
+#define SCM_IM_DEFINE          SCM_MAKSPCSYM (13)
+#define SCM_IM_APPLY           SCM_MAKISYM (14)
+#define SCM_IM_CONT            SCM_MAKISYM (15)
+#define SCM_BOOL_F             SCM_MAKIFLAG (16)
+#define SCM_BOOL_T             SCM_MAKIFLAG (17)
+#define SCM_UNDEFINED          SCM_MAKIFLAG (18)
+#define SCM_EOF_VAL            SCM_MAKIFLAG (19)
+#define SCM_EOL                        SCM_MAKIFLAG (20)
+#define SCM_UNSPECIFIED                SCM_MAKIFLAG (21)
+#define SCM_IM_DISPATCH                SCM_MAKISYM (22)
+#define SCM_IM_SLOT_REF                SCM_MAKISYM (23)
+#define SCM_IM_SLOT_SET_X      SCM_MAKISYM (24)
 
 /* Multi-language support */
 
-#define SCM_IM_NIL_COND                SCM_MAKISYM(25)
-#define SCM_IM_NIL_IFY         SCM_MAKISYM(26)
-#define SCM_IM_T_IFY           SCM_MAKISYM(27)
-#define SCM_IM_0_COND          SCM_MAKISYM(28)
-#define SCM_IM_0_IFY           SCM_MAKISYM(29)
-#define SCM_IM_1_IFY           SCM_MAKISYM(30)
-#define SCM_IM_BIND            SCM_MAKISYM(31)
-
-#define SCM_IM_DELAY           SCM_MAKISYM(32)
+#define SCM_IM_NIL_COND                SCM_MAKISYM (25)
+#define SCM_IM_NIL_IFY         SCM_MAKISYM (26)
+#define SCM_IM_T_IFY           SCM_MAKISYM (27)
+#define SCM_IM_0_COND          SCM_MAKISYM (28)
+#define SCM_IM_0_IFY           SCM_MAKISYM (29)
+#define SCM_IM_1_IFY           SCM_MAKISYM (30)
+#define SCM_IM_BIND            SCM_MAKISYM (31)
+
+#define SCM_IM_DELAY           SCM_MAKISYM (32)
+
+/* When a variable is unbound this is marked by the SCM_UNDEFINED
+ * value.  The following is an unbound value which can be handled on
+ * the Scheme level, i.e., it can be stored in and retrieved from a
+ * Scheme variable.  This value is only intended to mark an unbound
+ * slot in GOOPS.  It is needed now, but we should probably rewrite
+ * the code which handles this value in C so that SCM_UNDEFINED can be
+ * used instead.  It is not ideal to let this kind of unique and
+ * strange values loose on the Scheme level.
+ */
+#define SCM_UNBOUND            SCM_MAKIFLAG (33)
 
-#define SCM_UNBNDP(x)  (SCM_UNDEFINED==(x))
+#define SCM_UNBNDP(x)  (SCM_UNDEFINED == (x))
 
 \f
 
-/* Dispatching aids:
- */
+/* Dispatching aids: */
 
 
 /* For cons pairs with immediate values in the CAR