Fix bugs with inappropriate mixing of Lisp_Object with int.
[bpt/emacs.git] / src / lisp.h
index 01bf1fe..ecfc0b6 100644 (file)
@@ -181,12 +181,11 @@ Lisp_Object;
 #endif /* NO_UNION_TYPE */
 
 
-/* If union type is not wanted, define Lisp_Object as just a number
-   and define the macros below to extract fields by shifting */
+/* If union type is not wanted, define Lisp_Object as just a number.  */
 
 #ifdef NO_UNION_TYPE
-
 #define Lisp_Object EMACS_INT
+#endif /* NO_UNION_TYPE */
 
 #ifndef VALMASK
 #define VALMASK ((((EMACS_INT) 1)<<VALBITS) - 1)
@@ -243,8 +242,6 @@ enum pvec_type
 
 /* For convenience, we also store the number of elements in these bits.  */
 #define PSEUDOVECTOR_SIZE_MASK 0x1ff
-
-#endif /* NO_UNION_TYPE */
 \f
 /* These macros extract various sorts of values from a Lisp_Object.
  For example, if tem is a Lisp_Object whose type is Lisp_Cons,
@@ -372,6 +369,8 @@ extern int pure_size;
 #define XSET(var, vartype, ptr) \
    (((var).s.type = ((char) (vartype))), ((var).s.val = ((int) (ptr))))
 
+extern Lisp_Object make_number ();
+
 /* During garbage collection, XGCTYPE must be used for extracting types
  so that the mark bit is ignored.  XMARKBIT access the markbit.
  Markbits are used only in particular slots of particular structure types.
@@ -564,34 +563,87 @@ struct Lisp_Vector
     Lisp_Object contents[1];
   };
 
-/* A char table is a kind of vectorlike, with contents are like a vector
-   but with a few other slots.  For some purposes, it makes sense
-   to handle a chartable with type struct Lisp_Vector.  */
-
-/* This is the number of slots that apply to characters
-   or character sets.  */
-#define CHAR_TABLE_ORDINARY_SLOTS 256
-
-/* This is the number of slots that every char table must have.
-   This counts the ordinary slots and the parent and defalt slots.  */
-#define CHAR_TABLE_STANDARD_SLOTS (256+3)
+/* A char table is a kind of vectorlike, with contents are like a
+   vector but with a few other slots.  For some purposes, it makes
+   sense to handle a chartable with type struct Lisp_Vector.  An
+   element of a char table can be any Lisp objects, but if it is a sub
+   char-table, we treat it a table that contains information of a
+   group of characters of the same charsets or a specific character of
+   a charset.  A sub char-table has the same structure as a char table
+   except for that the former omits several slots at the tail.  A sub
+   char table appears only in an element of a char table, and there's
+   no way to access it directly from Emacs Lisp program.  */
+
+/* This is the number of slots that apply to characters or character
+   sets.  The first 128 are for ASCII, the next 128 are for 8-bit
+   European characters, and the last 128 are for multibyte characters.
+   The first 256 are indexed by the code itself, but the last 128 are
+   indexed by (charset-id + 128).  */
+#define CHAR_TABLE_ORDINARY_SLOTS 384
+
+/* This is the number of slots that apply to characters of ASCII and
+   8-bit Europeans only.  */
+#define CHAR_TABLE_SINGLE_BYTE_SLOTS 256
+
+/* This is the number of slots that every char table must have.  This
+   counts the ordinary slots and the top, defalt, parent, and purpose
+   slots.  */
+#define CHAR_TABLE_STANDARD_SLOTS (CHAR_TABLE_ORDINARY_SLOTS + 4)
+
+/* This is the number of slots that apply to position-code-1 and
+   position-code-2 of a multibyte character at the 2nd and 3rd level
+   sub char tables respectively.  */
+#define SUB_CHAR_TABLE_ORDINARY_SLOTS 128
+
+/* This is the number of slots that every sub char table must have.
+   This counts the ordinary slots and the top and defalt slot.  */
+#define SUB_CHAR_TABLE_STANDARD_SLOTS (SUB_CHAR_TABLE_ORDINARY_SLOTS + 2)
 
 /* Return the number of "extra" slots in the char table CT.  */
 
 #define CHAR_TABLE_EXTRA_SLOTS(CT)     \
   (((CT)->size & PSEUDOVECTOR_SIZE_MASK) - CHAR_TABLE_STANDARD_SLOTS)
 
+/* Almost equivalent to Faref (CT, IDX) with optimization for ASCII
+   and 8-bit Europeans characters.  For these characters, do not check
+   validity of CT.  Do not follow parent.  */
+#define CHAR_TABLE_REF(CT, IDX)                                \
+  ((IDX) < CHAR_TABLE_SINGLE_BYTE_SLOTS                        \
+   ? (!NILP (XCHAR_TABLE (CT)->contents[IDX])          \
+      ? XCHAR_TABLE (CT)->contents[IDX]                        \
+      : XCHAR_TABLE (CT)->defalt)                      \
+   : Faref (CT, make_number (IDX)))
+
+/* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and
+   8-bit Europeans characters.  Do not check validity of CT.  */
+#define CHAR_TABLE_SET(CT, IDX, VAL)                   \
+  do {                                                 \
+    if (XFASTINT (IDX) < CHAR_TABLE_SINGLE_BYTE_SLOTS) \
+      XCHAR_TABLE (CT)->contents[XFASTINT (IDX)] = VAL;        \
+    else                                               \
+      Faset (CT, IDX, VAL);                            \
+  } while (0)
+
 struct Lisp_Char_Table
   {
     /* This is the vector's size field, which also holds the
        pseudovector type information.  It holds the size, too.
-       The size counts the defalt and parent slots.  */
+       The size counts the top, defalt, purpose, and parent slots.
+       The last three are not counted if this is a sub char table.  */
     EMACS_INT size;
     struct Lisp_Vector *next;
-    Lisp_Object contents[CHAR_TABLE_ORDINARY_SLOTS];
+    /* This holds a flag to tell if this is a top level char table (t)
+       or a sub char table (nil).  */
+    Lisp_Object top;
     /* This holds a default value,
        which is used whenever the value for a specific character is nil.  */
     Lisp_Object defalt;
+    /* This holds an actual value of each element.  A sub char table
+       has only SUB_CHAR_TABLE_ORDINARY_SLOTS number of elements.  */
+    Lisp_Object contents[CHAR_TABLE_ORDINARY_SLOTS];
+
+    /* A sub char table doesn't has the following slots.  */
+
     /* This points to another char table, which we inherit from
        when the value for a specific character is nil.
        The `defalt' slot takes precedence over this.  */
@@ -625,6 +677,7 @@ struct Lisp_Symbol
     Lisp_Object value;
     Lisp_Object function;
     Lisp_Object plist;
+    Lisp_Object obarray;
     struct Lisp_Symbol *next;  /* -> next symbol in this obarray bucket */
   };
 
@@ -635,7 +688,7 @@ struct Lisp_Symbol
    This type is treated in most respects as a pseudovector,
    but since we never dynamically allocate or free them,
    we don't need a next-vector field.  */
-   
+
 struct Lisp_Subr
   {
     EMACS_INT size;
@@ -656,7 +709,7 @@ struct Lisp_Free
     union Lisp_Misc *chain;
   };
 
-/* In a marker, the markbit of the chain field is used as the gc mark bit */
+/* In a marker, the markbit of the chain field is used as the gc mark bit */
 struct Lisp_Marker
 {
   int type : 16;               /* = Lisp_Misc_Marker */
@@ -799,9 +852,9 @@ union Lisp_Misc
 /* Optional Lisp floating point type */
 struct Lisp_Float
   {
-    Lisp_Object type;          /* essentially used for mark-bit 
+    Lisp_Object type;          /* essentially used for mark-bit
                                   and chaining when on free-list */
-    double data;  
+    double data;
   };
 #endif /* LISP_FLOAT_TYPE */
 
@@ -832,6 +885,10 @@ typedef unsigned char UCHAR;
 #define CHAR_CTL   (0x4000000)
 #define CHAR_META  (0x8000000)
 
+/* Actually, the current Emacs uses 19 bits for the character value
+   itself.  */
+#define CHARACTERBITS 19
+
 #ifdef USE_X_TOOLKIT
 #ifdef NO_UNION_TYPE
 /* Use this for turning a (void *) into a Lisp_Object, as when the
@@ -863,26 +920,37 @@ typedef unsigned char UCHAR;
 \f
 /* The glyph datatype, used to represent characters on the display.  */
 
-/* The low eight bits are the character code, and the bits above them
-   are the numeric face ID.  If FID is the face ID of a glyph on a
-   frame F, then F->display.x->faces[FID] contains the description of
-   that face.  This is an int instead of a short, so we can support a
-   good bunch of face ID's; given that we have no mechanism for
-   tossing unused frame face ID's yet, we'll probably run out of 255
-   pretty quickly.  */
+/* The low 19 bits (CHARACTERBITS) are the character code, and the
+   bits above them except for the topmost two bits are the numeric
+   face ID.  If FID is the face ID of a glyph on a frame F, then
+   F->display.x->faces[FID] contains the description of that face.
+   This is an int instead of a short, so we can support a good bunch
+   of face ID's (i.e. 2^(32 - 19 - 2) = 2048 ID's) ; given that we
+   have no mechanism for tossing unused frame face ID's yet, we'll
+   probably run out of 255 pretty quickly.  */
 #define GLYPH unsigned int
 
+/* Mask bit for a glyph of a character which should be written from
+   right to left.  */
+#define GLYPH_MASK_REV_DIR 0x80000000
+/* Mask bit for a padding glyph of a multi-column character.  */
+#define GLYPH_MASK_PADDING 0x40000000
+/* Mask bits for face.  */
+#define GLYPH_MASK_FACE    0x3FF80000
+/* Mask bits for character code.  */
+#define GLYPH_MASK_CHAR    0x0007FFFF /* The lowest 19 bits */
+
 #ifdef HAVE_FACES
 /* The FAST macros assume that we already know we're in an X window.  */
 
 /* Given a character code and a face ID, return the appropriate glyph.  */
-#define FAST_MAKE_GLYPH(char, face) ((char) | ((face) << 8))
+#define FAST_MAKE_GLYPH(char, face) ((char) | ((face) << CHARACTERBITS))
 
 /* Return a glyph's character code.  */
-#define FAST_GLYPH_CHAR(glyph) ((glyph) & 0xff)
+#define FAST_GLYPH_CHAR(glyph) ((glyph) & GLYPH_MASK_CHAR)
 
 /* Return a glyph's face ID.  */
-#define FAST_GLYPH_FACE(glyph) (((glyph) >> 8) & ((1 << 24) - 1))
+#define FAST_GLYPH_FACE(glyph) (((glyph) & GLYPH_MASK_FACE) >> CHARACTERBITS)
 
 /* Slower versions that test the frame type first.  */
 #define MAKE_GLYPH(f, char, face) (FRAME_TERMCAP_P (f) ? (char) \
@@ -891,10 +959,17 @@ typedef unsigned char UCHAR;
 #define GLYPH_FACE(f, g) (FRAME_TERMCAP_P (f) ? (0) : FAST_GLYPH_FACE (g))
 #else /* not HAVE_FACES */
 #define MAKE_GLYPH(f, char, face) (char)
-#define GLYPH_CHAR(f, g) (g)
-#define GLYPH_FACE(f, g) (g)
+#define FAST_MAKE_GLYPH(char, face) (char)
+#define GLYPH_CHAR(f, g) ((g) & GLYPH_MASK_CHAR)
+#define FAST_GLYPH_CHAR(g) ((g) & GLYPH_MASK_CHAR)
+#define GLYPH_FACE(f, g) ((g) & GLYPH_MASK_FACE)
+#define FAST_GLYPH_FACE(g) ((g) & GLYPH_MASK_FACE)
 #endif /* not HAVE_FACES */
 
+/* Return 1 iff GLYPH contains valid character code.  */
+#define GLYPH_CHAR_VALID_P(glyph) \
+  ((GLYPH) (FAST_GLYPH_CHAR (glyph)) <= MAX_CHAR)
+
 /* The ID of the mode line highlighting face.  */
 #define GLYPH_MODE_LINE_FACE 1
 \f
@@ -987,6 +1062,8 @@ typedef unsigned char UCHAR;
 #define GC_BOOL_VECTOR_P(x) GC_PSEUDOVECTORP (x, PVEC_BOOL_VECTOR)
 #define FRAMEP(x) PSEUDOVECTORP (x, PVEC_FRAME)
 #define GC_FRAMEP(x) GC_PSEUDOVECTORP (x, PVEC_FRAME)
+
+#define SUB_CHAR_TABLE_P(x) (CHAR_TABLE_P (x) && NILP (XCHAR_TABLE (x)->top))
 \f
 #define EQ(x, y) (XFASTINT (x) == XFASTINT (y))
 #define GC_EQ(x, y) (XGCTYPE (x) == XGCTYPE (y) && XPNTR (x) == XPNTR (y))
@@ -1022,7 +1099,7 @@ typedef unsigned char UCHAR;
   do { if (!WINDOWP ((x))) x = wrong_type_argument (Qwindowp, (x)); } while (0)
 
 /* This macro rejects windows on the interior of the window tree as
-   "dead", which is what we want; this is an argument-checking macro, and 
+   "dead", which is what we want; this is an argument-checking macro, and
    the user should never get access to interior windows.
 
    A window of any sort, leaf or interior, is dead iff the buffer,
@@ -1236,40 +1313,49 @@ extern char *stack_bottom;
 
 #define QUITP (!NILP (Vquit_flag) && NILP (Vinhibit_quit))
 \f
-/* 1 if CH is upper case.  */
+/* Variables used locally in the following case handling macros.  */
+extern int case_temp1;
+extern Lisp_Object case_temp2;
 
-#define UPPERCASEP(CH) \
-  (XCHAR_TABLE (current_buffer->downcase_table)->contents[CH] != (CH))
+/* Current buffer's map from characters to lower-case characters.  */
 
-/* 1 if CH is lower case.  */
+#define DOWNCASE_TABLE current_buffer->downcase_table
 
-#define LOWERCASEP(CH) \
-  (!UPPERCASEP (CH) \
-   && XCHAR_TABLE (current_buffer->upcase_table)->contents[CH] != (CH))
+/* Current buffer's map from characters to upper-case characters.  */
 
-/* 1 if CH is neither upper nor lower case.  */
+#define UPCASE_TABLE current_buffer->upcase_table
 
-#define NOCASEP(CH) \
-  (XCHAR_TABLE (current_buffer->upcase_table)->contents[CH] == (CH))
+/* Downcase a character, or make no change if that cannot be done.  */
 
-/* Upcase a character, or make no change if that cannot be done.  */
+#define DOWNCASE(CH)                                           \
+  ((case_temp1 = (CH),                                         \
+    case_temp2 = CHAR_TABLE_REF (DOWNCASE_TABLE, case_temp1),  \
+    NATNUMP (case_temp2))                                      \
+   ? XFASTINT (case_temp2) : case_temp1)
 
-#define UPCASE(CH) \
-  (XCHAR_TABLE (current_buffer->downcase_table)->contents[CH] == (CH) \
-   ? UPCASE1 (CH) : (CH))
+/* 1 if CH is upper case.  */
 
-/* Upcase a character known to be not upper case.  */
+#define UPPERCASEP(CH) (DOWNCASE (CH) != (CH))
 
-#define UPCASE1(CH) (XCHAR_TABLE (current_buffer->upcase_table)->contents[CH])
+/* 1 if CH is neither upper nor lower case.  */
 
-/* Downcase a character, or make no change if that cannot be done.  */
+#define NOCASEP(CH) (UPCASE1 (CH) == (CH))
 
-#define DOWNCASE(CH) \
-  (XCHAR_TABLE (current_buffer->downcase_table)->contents[CH])
+/* 1 if CH is lower case.  */
 
-/* Current buffer's map from characters to lower-case characters.  */
+#define LOWERCASEP(CH) (!UPPERCASEP (CH) && !NOCASEP(CH))
+
+/* Upcase a character, or make no change if that cannot be done.  */
 
-#define DOWNCASE_TABLE XCHAR_TABLE (current_buffer->downcase_table)->contents
+#define UPCASE(CH) (!UPPERCASEP (CH) ? UPCASE1 (CH) : (CH))
+
+/* Upcase a character known to be not upper case.  */
+
+#define UPCASE1(CH)                                            \
+  ((case_temp1 = (CH),                                         \
+    case_temp2 = CHAR_TABLE_REF (UPCASE_TABLE, case_temp1),    \
+    NATNUMP (case_temp2))                                      \
+   ? XFASTINT (case_temp2) : case_temp1)
 
 extern Lisp_Object Vascii_downcase_table;
 \f
@@ -1336,7 +1422,7 @@ struct gcpro
 /* Call staticpro (&var) to protect static variable `var'.  */
 
 void staticpro();
-  
+
 #define UNGCPRO (gcprolist = gcpro1.next)
 
 /* Evaluate expr, UNGCPRO, and then return the value of expr.  */
@@ -1399,6 +1485,7 @@ extern Lisp_Object Ffset (), Fsetplist ();
 extern Lisp_Object Fsymbol_value (), find_symbol_value (), Fset ();
 extern Lisp_Object Fdefault_value (), Fset_default (), Fdefault_boundp ();
 extern Lisp_Object Fmake_local_variable ();
+extern Lisp_Object Flocal_variable_if_set_p ();
 
 extern Lisp_Object Faref (), Faset ();
 
@@ -1429,6 +1516,11 @@ extern Lisp_Object Ffloat ();
 /* Defined in cmds.c */
 extern Lisp_Object Fend_of_line (), Fforward_char (), Fforward_line ();
 
+/* Defined in coding.c */
+extern Lisp_Object Fcoding_system_p (), Fcheck_coding_system ();
+extern Lisp_Object Fread_coding_system (), Fread_non_nil_coding_system ();
+extern Lisp_Object Ffind_coding_system ();
+
 /* Defined in syntax.c */
 extern Lisp_Object Fforward_word ();
 
@@ -1445,11 +1537,13 @@ extern Lisp_Object Freverse (), Fnreverse (), Fget (), Fput (), Fequal ();
 extern Lisp_Object Ffillarray (), Fnconc (), Fmapcar (), Fmapconcat ();
 extern Lisp_Object Fy_or_n_p (), do_yes_or_no_p ();
 extern Lisp_Object Ffeaturep (), Frequire () , Fprovide ();
-extern Lisp_Object concat2 (), nconc2 ();
+extern Lisp_Object concat2 (), concat3 (), nconc2 ();
 extern Lisp_Object assq_no_quit ();
 extern Lisp_Object Fcopy_alist ();
 extern Lisp_Object Fplist_get ();
 extern Lisp_Object Fset_char_table_parent ();
+extern Lisp_Object Fchar_table_extra_slot ();
+extern Lisp_Object Frassoc ();
 
 /* Defined in insdel.c */
 extern void move_gap ();
@@ -1497,6 +1591,7 @@ extern Lisp_Object pure_cons (), make_pure_vector ();
 extern Lisp_Object Fgarbage_collect ();
 extern Lisp_Object Fmake_byte_code ();
 extern Lisp_Object Fmake_bool_vector (), Fmake_char_table ();
+extern Lisp_Object make_sub_char_table ();
 extern Lisp_Object Qchar_table_extra_slots;
 extern struct Lisp_Vector *allocate_vectorlike ();
 extern int gc_in_progress;
@@ -1520,7 +1615,7 @@ extern Lisp_Object Fintern (), Fintern_soft (), Fload ();
 extern Lisp_Object Fget_file_char (), Fread_char ();
 extern Lisp_Object read_filtered_event ();
 extern Lisp_Object Feval_current_buffer (), Feval_region ();
-extern Lisp_Object intern (), oblookup ();
+extern Lisp_Object intern (), make_symbol (), oblookup ();
 #define LOADHIST_ATTACH(x) \
  if (initialized) Vcurrent_load_list = Fcons (x, Vcurrent_load_list)
 extern Lisp_Object Vcurrent_load_list;
@@ -1570,6 +1665,7 @@ extern Lisp_Object Fgoto_char ();
 extern Lisp_Object Fpoint_min_marker (), Fpoint_max_marker ();
 extern Lisp_Object Fpoint_min (), Fpoint_max ();
 extern Lisp_Object Fpoint (), Fpoint_marker (), Fmark_marker ();
+extern Lisp_Object Fline_beginning_position (), Fline_end_position ();
 extern Lisp_Object Ffollowing_char (), Fprevious_char (), Fchar_after ();
 extern Lisp_Object Finsert (), Finsert_and_inherit ();
 extern Lisp_Object Finsert_before_markers ();
@@ -1584,6 +1680,7 @@ extern Lisp_Object save_excursion_save (), save_restriction_save ();
 extern Lisp_Object save_excursion_restore (), save_restriction_restore ();
 extern Lisp_Object Fchar_to_string ();
 extern Lisp_Object Fdelete_region (), Fnarrow_to_region (), Fwiden ();
+extern Lisp_Object Fuser_login_name (), Fsystem_name ();
 
 /* defined in buffer.c */
 extern Lisp_Object Foverlay_start (), Foverlay_end ();
@@ -1602,7 +1699,9 @@ extern Lisp_Object Fkill_buffer (), Fkill_all_local_variables ();
 extern Lisp_Object Fbuffer_disable_undo (), Fbuffer_enable_undo ();
 extern Lisp_Object Ferase_buffer ();
 extern Lisp_Object Qoverlayp;
+extern Lisp_Object get_truename_buffer ();
 extern struct buffer *all_buffers;
+extern Lisp_Object Fprevious_overlay_change ();
 
 /* defined in marker.c */
 
@@ -1627,6 +1726,7 @@ extern Lisp_Object Ffile_accessible_directory_p ();
 extern Lisp_Object Funhandled_file_name_directory ();
 extern Lisp_Object Ffile_directory_p ();
 extern Lisp_Object Fwrite_region ();
+extern Lisp_Object Ffile_readable_p (), Ffile_executable_p ();
 
 /* Defined in abbrev.c */
 
@@ -1643,7 +1743,7 @@ extern Lisp_Object Fskip_chars_forward (), Fskip_chars_backward ();
 /* defined in minibuf.c */
 
 extern Lisp_Object last_minibuf_string;
-extern Lisp_Object read_minibuf (), Fcompleting_read ();
+extern Lisp_Object Fcompleting_read ();
 extern Lisp_Object Fread_from_minibuffer ();
 extern Lisp_Object Fread_variable (), Fread_buffer (), Fread_key_sequence ();
 extern Lisp_Object Fread_minibuffer (), Feval_minibuffer ();
@@ -1673,7 +1773,7 @@ extern Lisp_Object Fset_standard_case_table ();
 /* defined in keyboard.c */
 
 extern Lisp_Object Qdisabled;
-extern Lisp_Object Vhelp_form, Vtop_level;
+extern Lisp_Object Vtty_erase_char, Vhelp_form, Vtop_level;
 extern Lisp_Object Fdiscard_input (), Frecursive_edit ();
 extern Lisp_Object Fcommand_execute (), Finput_pending_p ();
 extern Lisp_Object menu_bar_items ();
@@ -1696,6 +1796,7 @@ extern void describe_map_tree ();
 
 /* defined in indent.c */
 extern Lisp_Object Fvertical_motion (), Findent_to (), Fcurrent_column ();
+extern Lisp_Object Fmove_to_column ();
 
 /* defined in window.c */
 extern Lisp_Object Qwindowp, Qwindow_live_p;
@@ -1746,6 +1847,7 @@ extern Lisp_Object Fset_frame_size ();
 extern Lisp_Object Fset_frame_position ();
 extern Lisp_Object Fraise_frame ();
 extern Lisp_Object Fredirect_frame_focus ();
+extern Lisp_Object frame_buffer_list ();
 
 /* defined in emacs.c */
 extern Lisp_Object decode_env_path ();
@@ -1799,6 +1901,8 @@ extern Lisp_Object Fprevious_single_property_change ();
 extern Lisp_Object Fget_text_property (), Fput_text_property ();
 extern Lisp_Object Fset_text_properties ();
 extern Lisp_Object Ftext_property_not_all ();
+extern Lisp_Object Fprevious_char_property_change ();
+extern Lisp_Object Fnext_char_property_change ();
 
 /* defined in intervals.c */
 extern Lisp_Object get_local_map ();
@@ -1819,7 +1923,7 @@ extern long *xmalloc (), *xrealloc ();
 extern void xfree ();
 
 extern char *egetenv ();
+
 /* Set up the name of the machine we're running on.  */
 extern void init_system_name ();