Use "ASET (a, i, v)" rather than "AREF (a, i) = v".
[bpt/emacs.git] / src / lisp.h
index cf5c70b..dfddb09 100644 (file)
@@ -398,8 +398,11 @@ enum More_Lisp_Bits
 
 #if USE_LSB_TAG
 
-static int const VALMASK = -1 << GCTYPEBITS;
-#define TYPEMASK ((1 << GCTYPEBITS) - 1)
+enum lsb_bits
+  {
+    TYPEMASK = (1 << GCTYPEBITS) - 1,
+    VALMASK = ~ TYPEMASK
+  };
 #define XTYPE(a) ((enum Lisp_Type) (XLI (a) & TYPEMASK))
 #define XINT(a) (XLI (a) >> INTTYPEBITS)
 #define XUINT(a) ((EMACS_UINT) XLI (a) >> INTTYPEBITS)
@@ -595,7 +598,7 @@ clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
 #define ASET(ARRAY, IDX, VAL)  \
   (eassert ((IDX) == (IDX)),                           \
    eassert ((IDX) >= 0 && (IDX) < ASIZE (ARRAY)),      \
-   AREF ((ARRAY), (IDX)) = (VAL))
+   XVECTOR (ARRAY)->contents[IDX] = (VAL))
 
 /* Convenience macros for dealing with Lisp strings.  */
 
@@ -619,8 +622,13 @@ clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
 #define CHECK_TYPE(ok, Qxxxp, x) \
   do { if (!(ok)) wrong_type_argument (Qxxxp, (x)); } while (0)
 
+/* Lisp fields are usually hidden from most code and accessed
+   via special macros.  Only select pieces of code, like the GC,
+   are allowed to use INTERNAL_FIELD directly.  Objects which
+   aren't using this convention should be fixed.  */
+
+#define INTERNAL_FIELD(field) field ## _
 
-\f
 /* See the macros in intervals.h.  */
 
 typedef struct interval *INTERVAL;
@@ -629,17 +637,22 @@ typedef struct interval *INTERVAL;
 #define CHECK_STRING_OR_BUFFER(x) \
   CHECK_TYPE (STRINGP (x) || BUFFERP (x), Qbuffer_or_string_p, x)
 
-\f
-/* In a cons, the markbit of the car is the gc mark bit */
+/* Most code should use this macro to
+   access Lisp fields in struct Lisp_Cons.  */
+
+#define CVAR(cons, field) ((cons)->INTERNAL_FIELD (field))
 
 struct Lisp_Cons
   {
-    /* Please do not use the names of these elements in code other
-       than the core lisp implementation.  Use XCAR and XCDR below.  */
-    Lisp_Object car;
+    /* Car of this cons cell.  */
+    Lisp_Object INTERNAL_FIELD (car);
+
     union
     {
-      Lisp_Object cdr;
+      /* Cdr of this cons cell.  */
+      Lisp_Object INTERNAL_FIELD (cdr);
+
+      /* Used to chain conses on a free list.  */
       struct Lisp_Cons *chain;
     } u;
   };
@@ -651,8 +664,8 @@ struct Lisp_Cons
    fields are not accessible as lvalues.  (What if we want to switch to
    a copying collector someday?  Cached cons cell field addresses may be
    invalidated at arbitrary points.)  */
-#define XCAR_AS_LVALUE(c) (XCONS ((c))->car)
-#define XCDR_AS_LVALUE(c) (XCONS ((c))->u.cdr)
+#define XCAR_AS_LVALUE(c) (CVAR (XCONS (c), car))
+#define XCDR_AS_LVALUE(c) (CVAR (XCONS (c), u.cdr))
 
 /* Use these from normal code.  */
 #define XCAR(c)        LISP_MAKE_RVALUE (XCAR_AS_LVALUE (c))
@@ -715,12 +728,12 @@ extern ptrdiff_t string_bytes (struct Lisp_String *);
    would expose alloc.c internal details that we'd rather keep
    private.
 
-   This is a macros for use in static initializers, and a constant for
+   This is a macro for use in static initializers, and a constant for
    visibility to GDB.  The cast to ptrdiff_t ensures that
-   STRING_BYTES_BOUND is signed.  */
+   the macro is signed.  */
 static ptrdiff_t const STRING_BYTES_BOUND =
 #define STRING_BYTES_BOUND  \
-  min (MOST_POSITIVE_FIXNUM, (ptrdiff_t) min (SIZE_MAX, PTRDIFF_MAX) - 1)
+  ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, min (SIZE_MAX, PTRDIFF_MAX) - 1))
        STRING_BYTES_BOUND;
 
 /* Mark STR as a unibyte string.  */
@@ -1031,6 +1044,11 @@ enum symbol_redirect
   SYMBOL_FORWARDED = 3
 };
 
+/* Most code should use this macro to access
+   Lisp fields in struct Lisp_Symbol.  */
+
+#define SVAR(sym, field) ((sym)->INTERNAL_FIELD (field))
+
 struct Lisp_Symbol
 {
   unsigned gcmarkbit : 1;
@@ -1058,22 +1076,22 @@ struct Lisp_Symbol
   /* The symbol's name, as a Lisp string.
      The name "xname" is used to intentionally break code referring to
      the old field "name" of type pointer to struct Lisp_String.  */
-  Lisp_Object xname;
+  Lisp_Object INTERNAL_FIELD (xname);
 
   /* Value of the symbol or Qunbound if unbound.  Which alternative of the
      union is used depends on the `redirect' field above.  */
   union {
-    Lisp_Object value;
+    Lisp_Object INTERNAL_FIELD (value);
     struct Lisp_Symbol *alias;
     struct Lisp_Buffer_Local_Value *blv;
     union Lisp_Fwd *fwd;
   } val;
 
   /* Function value of the symbol or Qunbound if not fboundp.  */
-  Lisp_Object function;
+  Lisp_Object INTERNAL_FIELD (function);
 
   /* The symbol's property list.  */
-  Lisp_Object plist;
+  Lisp_Object INTERNAL_FIELD (plist);
 
   /* Next symbol in obarray bucket, if the symbol is interned.  */
   struct Lisp_Symbol *next;
@@ -1082,7 +1100,7 @@ struct Lisp_Symbol
 /* Value is name of symbol.  */
 
 #define SYMBOL_VAL(sym)   \
-  (eassert ((sym)->redirect == SYMBOL_PLAINVAL),  (sym)->val.value)
+  (eassert ((sym)->redirect == SYMBOL_PLAINVAL),  SVAR (sym, val.value))
 #define SYMBOL_ALIAS(sym) \
   (eassert ((sym)->redirect == SYMBOL_VARALIAS),  (sym)->val.alias)
 #define SYMBOL_BLV(sym)   \
@@ -1090,7 +1108,7 @@ struct Lisp_Symbol
 #define SYMBOL_FWD(sym)   \
   (eassert ((sym)->redirect == SYMBOL_FORWARDED), (sym)->val.fwd)
 #define SET_SYMBOL_VAL(sym, v)     \
-  (eassert ((sym)->redirect == SYMBOL_PLAINVAL),  (sym)->val.value = (v))
+  (eassert ((sym)->redirect == SYMBOL_PLAINVAL),  SVAR (sym, val.value) = (v))
 #define SET_SYMBOL_ALIAS(sym, v)   \
   (eassert ((sym)->redirect == SYMBOL_VARALIAS),  (sym)->val.alias = (v))
 #define SET_SYMBOL_BLV(sym, v)     \
@@ -1099,7 +1117,7 @@ struct Lisp_Symbol
   (eassert ((sym)->redirect == SYMBOL_FORWARDED), (sym)->val.fwd = (v))
 
 #define SYMBOL_NAME(sym)  \
-     LISP_MAKE_RVALUE (XSYMBOL (sym)->xname)
+     LISP_MAKE_RVALUE (SVAR (XSYMBOL (sym), xname))
 
 /* Value is non-zero if SYM is an interned symbol.  */
 
@@ -1248,7 +1266,11 @@ enum DEFAULT_HASH_SIZE { DEFAULT_HASH_SIZE = 65 };
 
 #define DEFAULT_REHASH_SIZE 1.5
 
-\f
+/* Most code should use this macro to access
+   Lisp fields in a different misc objects.  */
+
+#define MVAR(misc, field) ((misc)->INTERNAL_FIELD (field))
+
 /* These structures are used for various misc types.  */
 
 struct Lisp_Misc_Any           /* Supertype of all Misc types.  */
@@ -1318,7 +1340,9 @@ struct Lisp_Overlay
     unsigned gcmarkbit : 1;
     int spacer : 15;
     struct Lisp_Overlay *next;
-    Lisp_Object start, end, plist;
+    Lisp_Object INTERNAL_FIELD (start);
+    Lisp_Object INTERNAL_FIELD (end);
+    Lisp_Object INTERNAL_FIELD (plist);
   };
 
 /* Hold a C pointer for later use.
@@ -1517,7 +1541,7 @@ enum char_bits
     CHAR_META = 0x8000000,
 
     CHAR_MODIFIER_MASK =
-     (CHAR_ALT | CHAR_SUPER | CHAR_HYPER | CHAR_SHIFT | CHAR_CTL | CHAR_META),
+      CHAR_ALT | CHAR_SUPER | CHAR_HYPER | CHAR_SHIFT | CHAR_CTL | CHAR_META,
 
     /* Actually, the current Emacs uses 22 bits for the character value
        itself.  */
@@ -1740,7 +1764,8 @@ typedef struct {
    vchild, and hchild members are all nil.  */
 
 #define CHECK_LIVE_WINDOW(x) \
-  CHECK_TYPE (WINDOWP (x) && !NILP (XWINDOW (x)->buffer), Qwindow_live_p, x)
+  CHECK_TYPE (WINDOWP (x) && !NILP (WVAR (XWINDOW (x), buffer)), \
+             Qwindow_live_p, x)
 
 #define CHECK_PROCESS(x) \
   CHECK_TYPE (PROCESSP (x), Qprocessp, x)
@@ -2311,6 +2336,44 @@ void staticpro (Lisp_Object *);
 struct window;
 struct frame;
 
+/* Simple access functions.  */
+
+static inline Lisp_Object *
+aref_addr (Lisp_Object array, ptrdiff_t idx)
+{
+  return & XVECTOR (array)->contents[idx];
+}
+
+static inline void
+set_hash_key (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
+{
+  ASET (h->key_and_value, 2 * idx, val);
+}
+
+static inline void
+set_hash_value (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
+{
+  ASET (h->key_and_value, 2 * idx + 1, val);
+}
+
+static inline void
+set_hash_next (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
+{
+  ASET (h->next, idx, val);
+}
+
+static inline void
+set_hash_hash (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
+{
+  ASET (h->hash, idx, val);
+}
+
+static inline void
+set_hash_index (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val)
+{
+  ASET (h->index, idx, val);
+}
+
 /* Defined in data.c.  */
 extern Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
 extern Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
@@ -2842,7 +2905,7 @@ extern _Noreturn void verror (const char *, va_list)
   ATTRIBUTE_FORMAT_PRINTF (1, 0);
 extern Lisp_Object un_autoload (Lisp_Object);
 extern void init_eval_once (void);
-extern Lisp_Object safe_call (ptrdiff_t, Lisp_Object *);
+extern Lisp_Object safe_call (ptrdiff_t, Lisp_Object, ...);
 extern Lisp_Object safe_call1 (Lisp_Object, Lisp_Object);
 extern Lisp_Object safe_call2 (Lisp_Object, Lisp_Object, Lisp_Object);
 extern void init_eval (void);
@@ -3297,26 +3360,7 @@ extern char *egetenv (const char *);
 /* Set up the name of the machine we're running on.  */
 extern void init_system_name (void);
 
-/* Some systems (e.g., NT) use a different path separator than Unix,
-   in addition to a device separator.  Set the path separator
-   to '/', and don't test for a device separator in IS_ANY_SEP.  */
-
-#define DIRECTORY_SEP '/'
-#ifndef IS_DIRECTORY_SEP
-#define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
-#endif
-#ifndef IS_DEVICE_SEP
-#ifndef DEVICE_SEP
-#define IS_DEVICE_SEP(_c_) 0
-#else
-#define IS_DEVICE_SEP(_c_) ((_c_) == DEVICE_SEP)
-#endif
-#endif
-#ifndef IS_ANY_SEP
-#define IS_ANY_SEP(_c_) (IS_DIRECTORY_SEP (_c_))
-#endif
-
-#define SWITCH_ENUM_CAST(x) (x)
+static char const DIRECTORY_SEP = '/';
 
 /* Use this to suppress gcc's warnings.  */
 #ifdef lint