1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 86, 88, 93, 94, 95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
33 #include "syssignal.h"
35 #ifdef LISP_FLOAT_TYPE
41 /* Work around a problem that happens because math.h on hpux 7
42 defines two static variables--which, in Emacs, are not really static,
43 because `static' is defined as nothing. The problem is that they are
44 here, in floatfns.c, and in lread.c.
45 These macros prevent the name conflict. */
46 #if defined (HPUX) && !defined (HPUX8)
47 #define _MAXLDBL data_c_maxldbl
48 #define _NMAXLDBL data_c_nmaxldbl
52 #endif /* LISP_FLOAT_TYPE */
55 extern double atof ();
58 Lisp_Object Qnil
, Qt
, Qquote
, Qlambda
, Qsubr
, Qunbound
;
59 Lisp_Object Qerror_conditions
, Qerror_message
, Qtop_level
;
60 Lisp_Object Qerror
, Qquit
, Qwrong_type_argument
, Qargs_out_of_range
;
61 Lisp_Object Qvoid_variable
, Qvoid_function
, Qcyclic_function_indirection
;
62 Lisp_Object Qsetting_constant
, Qinvalid_read_syntax
;
63 Lisp_Object Qinvalid_function
, Qwrong_number_of_arguments
, Qno_catch
;
64 Lisp_Object Qend_of_file
, Qarith_error
, Qmark_inactive
;
65 Lisp_Object Qbeginning_of_buffer
, Qend_of_buffer
, Qbuffer_read_only
;
66 Lisp_Object Qintegerp
, Qnatnump
, Qwholenump
, Qsymbolp
, Qlistp
, Qconsp
;
67 Lisp_Object Qstringp
, Qarrayp
, Qsequencep
, Qbufferp
;
68 Lisp_Object Qchar_or_string_p
, Qmarkerp
, Qinteger_or_marker_p
, Qvectorp
;
69 Lisp_Object Qbuffer_or_string_p
;
70 Lisp_Object Qboundp
, Qfboundp
;
71 Lisp_Object Qchar_table_p
, Qvector_or_char_table_p
;
74 Lisp_Object Qad_advice_info
, Qad_activate
;
76 Lisp_Object Qrange_error
, Qdomain_error
, Qsingularity_error
;
77 Lisp_Object Qoverflow_error
, Qunderflow_error
;
79 #ifdef LISP_FLOAT_TYPE
81 Lisp_Object Qnumberp
, Qnumber_or_marker_p
;
84 static Lisp_Object Qinteger
, Qsymbol
, Qstring
, Qcons
, Qmarker
, Qoverlay
;
85 static Lisp_Object Qfloat
, Qwindow_configuration
, Qprocess
, Qwindow
;
86 static Lisp_Object Qcompiled_function
, Qbuffer
, Qframe
, Qvector
;
87 static Lisp_Object Qchar_table
, Qbool_vector
;
89 static Lisp_Object
swap_in_symval_forwarding ();
92 wrong_type_argument (predicate
, value
)
93 register Lisp_Object predicate
, value
;
95 register Lisp_Object tem
;
98 if (!EQ (Vmocklisp_arguments
, Qt
))
100 if (STRINGP (value
) &&
101 (EQ (predicate
, Qintegerp
) || EQ (predicate
, Qinteger_or_marker_p
)))
102 return Fstring_to_number (value
);
103 if (INTEGERP (value
) && EQ (predicate
, Qstringp
))
104 return Fnumber_to_string (value
);
107 /* If VALUE is not even a valid Lisp object, abort here
108 where we can get a backtrace showing where it came from. */
109 if ((unsigned int) XGCTYPE (value
) >= Lisp_Type_Limit
)
112 value
= Fsignal (Qwrong_type_argument
, Fcons (predicate
, Fcons (value
, Qnil
)));
113 tem
= call1 (predicate
, value
);
121 error ("Attempt to modify read-only object");
125 args_out_of_range (a1
, a2
)
129 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Qnil
)));
133 args_out_of_range_3 (a1
, a2
, a3
)
134 Lisp_Object a1
, a2
, a3
;
137 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Fcons (a3
, Qnil
))));
140 /* On some machines, XINT needs a temporary location.
141 Here it is, in case it is needed. */
143 int sign_extend_temp
;
145 /* On a few machines, XINT can only be done by calling this. */
148 sign_extend_lisp_int (num
)
151 if (num
& (((EMACS_INT
) 1) << (VALBITS
- 1)))
152 return num
| (((EMACS_INT
) (-1)) << VALBITS
);
154 return num
& ((((EMACS_INT
) 1) << VALBITS
) - 1);
157 /* Data type predicates */
159 DEFUN ("eq", Feq
, Seq
, 2, 2, 0,
160 "T if the two args are the same Lisp object.")
162 Lisp_Object obj1
, obj2
;
169 DEFUN ("null", Fnull
, Snull
, 1, 1, 0, "T if OBJECT is nil.")
178 DEFUN ("type-of", Ftype_of
, Stype_of
, 1, 1, 0,
179 "Return a symbol representing the type of OBJECT.\n\
180 The symbol returned names the object's basic type;\n\
181 for example, (type-of 1) returns `integer'.")
185 switch (XGCTYPE (object
))
200 switch (XMISCTYPE (object
))
202 case Lisp_Misc_Marker
:
204 case Lisp_Misc_Overlay
:
206 case Lisp_Misc_Float
:
211 case Lisp_Vectorlike
:
212 if (GC_WINDOW_CONFIGURATIONP (object
))
213 return Qwindow_configuration
;
214 if (GC_PROCESSP (object
))
216 if (GC_WINDOWP (object
))
218 if (GC_SUBRP (object
))
220 if (GC_COMPILEDP (object
))
221 return Qcompiled_function
;
222 if (GC_BUFFERP (object
))
224 if (GC_CHAR_TABLE_P (object
))
226 if (GC_BOOL_VECTOR_P (object
))
230 if (GC_FRAMEP (object
))
235 #ifdef LISP_FLOAT_TYPE
245 DEFUN ("consp", Fconsp
, Sconsp
, 1, 1, 0, "T if OBJECT is a cons cell.")
254 DEFUN ("atom", Fatom
, Satom
, 1, 1, 0, "T if OBJECT is not a cons cell. This includes nil.")
263 DEFUN ("listp", Flistp
, Slistp
, 1, 1, 0, "T if OBJECT is a list. This includes nil.")
267 if (CONSP (object
) || NILP (object
))
272 DEFUN ("nlistp", Fnlistp
, Snlistp
, 1, 1, 0, "T if OBJECT is not a list. Lists include nil.")
276 if (CONSP (object
) || NILP (object
))
281 DEFUN ("symbolp", Fsymbolp
, Ssymbolp
, 1, 1, 0, "T if OBJECT is a symbol.")
285 if (SYMBOLP (object
))
290 DEFUN ("vectorp", Fvectorp
, Svectorp
, 1, 1, 0, "T if OBJECT is a vector.")
294 if (VECTORP (object
))
299 DEFUN ("stringp", Fstringp
, Sstringp
, 1, 1, 0, "T if OBJECT is a string.")
303 if (STRINGP (object
))
308 DEFUN ("char-table-p", Fchar_table_p
, Schar_table_p
, 1, 1, 0, "T if OBJECT is a char-table.")
312 if (CHAR_TABLE_P (object
))
317 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p
,
318 Svector_or_char_table_p
, 1, 1, 0,
319 "T if OBJECT is a char-table or vector.")
323 if (VECTORP (object
) || CHAR_TABLE_P (object
))
328 DEFUN ("bool-vector-p", Fbool_vector_p
, Sbool_vector_p
, 1, 1, 0, "T if OBJECT is a bool-vector.")
332 if (BOOL_VECTOR_P (object
))
337 DEFUN ("arrayp", Farrayp
, Sarrayp
, 1, 1, 0, "T if OBJECT is an array (string or vector).")
341 if (VECTORP (object
) || STRINGP (object
))
346 DEFUN ("sequencep", Fsequencep
, Ssequencep
, 1, 1, 0,
347 "T if OBJECT is a sequence (list or array).")
349 register Lisp_Object object
;
351 if (CONSP (object
) || NILP (object
) || VECTORP (object
) || STRINGP (object
)
352 || CHAR_TABLE_P (object
) || BOOL_VECTOR_P (object
))
357 DEFUN ("bufferp", Fbufferp
, Sbufferp
, 1, 1, 0, "T if OBJECT is an editor buffer.")
361 if (BUFFERP (object
))
366 DEFUN ("markerp", Fmarkerp
, Smarkerp
, 1, 1, 0, "T if OBJECT is a marker (editor pointer).")
370 if (MARKERP (object
))
375 DEFUN ("subrp", Fsubrp
, Ssubrp
, 1, 1, 0, "T if OBJECT is a built-in function.")
384 DEFUN ("byte-code-function-p", Fbyte_code_function_p
, Sbyte_code_function_p
,
385 1, 1, 0, "T if OBJECT is a byte-compiled function object.")
389 if (COMPILEDP (object
))
394 DEFUN ("char-or-string-p", Fchar_or_string_p
, Schar_or_string_p
, 1, 1, 0,
395 "T if OBJECT is a character (an integer) or a string.")
397 register Lisp_Object object
;
399 if (INTEGERP (object
) || STRINGP (object
))
404 DEFUN ("integerp", Fintegerp
, Sintegerp
, 1, 1, 0, "T if OBJECT is an integer.")
408 if (INTEGERP (object
))
413 DEFUN ("integer-or-marker-p", Finteger_or_marker_p
, Sinteger_or_marker_p
, 1, 1, 0,
414 "T if OBJECT is an integer or a marker (editor pointer).")
416 register Lisp_Object object
;
418 if (MARKERP (object
) || INTEGERP (object
))
423 DEFUN ("natnump", Fnatnump
, Snatnump
, 1, 1, 0,
424 "T if OBJECT is a nonnegative integer.")
428 if (NATNUMP (object
))
433 DEFUN ("numberp", Fnumberp
, Snumberp
, 1, 1, 0,
434 "T if OBJECT is a number (floating point or integer).")
438 if (NUMBERP (object
))
444 DEFUN ("number-or-marker-p", Fnumber_or_marker_p
,
445 Snumber_or_marker_p
, 1, 1, 0,
446 "T if OBJECT is a number or a marker.")
450 if (NUMBERP (object
) || MARKERP (object
))
455 #ifdef LISP_FLOAT_TYPE
456 DEFUN ("floatp", Ffloatp
, Sfloatp
, 1, 1, 0,
457 "T if OBJECT is a floating point number.")
465 #endif /* LISP_FLOAT_TYPE */
467 /* Extract and set components of lists */
469 DEFUN ("car", Fcar
, Scar
, 1, 1, 0,
470 "Return the car of LIST. If arg is nil, return nil.\n\
471 Error if arg is not nil and not a cons cell. See also `car-safe'.")
473 register Lisp_Object list
;
478 return XCONS (list
)->car
;
479 else if (EQ (list
, Qnil
))
482 list
= wrong_type_argument (Qlistp
, list
);
486 DEFUN ("car-safe", Fcar_safe
, Scar_safe
, 1, 1, 0,
487 "Return the car of OBJECT if it is a cons cell, or else nil.")
492 return XCONS (object
)->car
;
497 DEFUN ("cdr", Fcdr
, Scdr
, 1, 1, 0,
498 "Return the cdr of LIST. If arg is nil, return nil.\n\
499 Error if arg is not nil and not a cons cell. See also `cdr-safe'.")
502 register Lisp_Object list
;
507 return XCONS (list
)->cdr
;
508 else if (EQ (list
, Qnil
))
511 list
= wrong_type_argument (Qlistp
, list
);
515 DEFUN ("cdr-safe", Fcdr_safe
, Scdr_safe
, 1, 1, 0,
516 "Return the cdr of OBJECT if it is a cons cell, or else nil.")
521 return XCONS (object
)->cdr
;
526 DEFUN ("setcar", Fsetcar
, Ssetcar
, 2, 2, 0,
527 "Set the car of CELL to be NEWCAR. Returns NEWCAR.")
529 register Lisp_Object cell
, newcar
;
532 cell
= wrong_type_argument (Qconsp
, cell
);
535 XCONS (cell
)->car
= newcar
;
539 DEFUN ("setcdr", Fsetcdr
, Ssetcdr
, 2, 2, 0,
540 "Set the cdr of CELL to be NEWCDR. Returns NEWCDR.")
542 register Lisp_Object cell
, newcdr
;
545 cell
= wrong_type_argument (Qconsp
, cell
);
548 XCONS (cell
)->cdr
= newcdr
;
552 /* Extract and set components of symbols */
554 DEFUN ("boundp", Fboundp
, Sboundp
, 1, 1, 0, "T if SYMBOL's value is not void.")
556 register Lisp_Object symbol
;
558 Lisp_Object valcontents
;
559 CHECK_SYMBOL (symbol
, 0);
561 valcontents
= XSYMBOL (symbol
)->value
;
563 if (BUFFER_LOCAL_VALUEP (valcontents
)
564 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
565 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
567 return (EQ (valcontents
, Qunbound
) ? Qnil
: Qt
);
570 DEFUN ("fboundp", Ffboundp
, Sfboundp
, 1, 1, 0, "T if SYMBOL's function definition is not void.")
572 register Lisp_Object symbol
;
574 CHECK_SYMBOL (symbol
, 0);
575 return (EQ (XSYMBOL (symbol
)->function
, Qunbound
) ? Qnil
: Qt
);
578 DEFUN ("makunbound", Fmakunbound
, Smakunbound
, 1, 1, 0, "Make SYMBOL's value be void.")
580 register Lisp_Object symbol
;
582 CHECK_SYMBOL (symbol
, 0);
583 if (NILP (symbol
) || EQ (symbol
, Qt
))
584 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
585 Fset (symbol
, Qunbound
);
589 DEFUN ("fmakunbound", Ffmakunbound
, Sfmakunbound
, 1, 1, 0, "Make SYMBOL's function definition be void.")
591 register Lisp_Object symbol
;
593 CHECK_SYMBOL (symbol
, 0);
594 if (NILP (symbol
) || EQ (symbol
, Qt
))
595 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
596 XSYMBOL (symbol
)->function
= Qunbound
;
600 DEFUN ("symbol-function", Fsymbol_function
, Ssymbol_function
, 1, 1, 0,
601 "Return SYMBOL's function definition. Error if that is void.")
603 register Lisp_Object symbol
;
605 CHECK_SYMBOL (symbol
, 0);
606 if (EQ (XSYMBOL (symbol
)->function
, Qunbound
))
607 return Fsignal (Qvoid_function
, Fcons (symbol
, Qnil
));
608 return XSYMBOL (symbol
)->function
;
611 DEFUN ("symbol-plist", Fsymbol_plist
, Ssymbol_plist
, 1, 1, 0, "Return SYMBOL's property list.")
613 register Lisp_Object symbol
;
615 CHECK_SYMBOL (symbol
, 0);
616 return XSYMBOL (symbol
)->plist
;
619 DEFUN ("symbol-name", Fsymbol_name
, Ssymbol_name
, 1, 1, 0, "Return SYMBOL's name, a string.")
621 register Lisp_Object symbol
;
623 register Lisp_Object name
;
625 CHECK_SYMBOL (symbol
, 0);
626 XSETSTRING (name
, XSYMBOL (symbol
)->name
);
630 DEFUN ("fset", Ffset
, Sfset
, 2, 2, 0,
631 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.")
633 register Lisp_Object symbol
, newdef
;
635 CHECK_SYMBOL (symbol
, 0);
636 if (NILP (symbol
) || EQ (symbol
, Qt
))
637 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
638 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
639 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
641 XSYMBOL (symbol
)->function
= newdef
;
642 /* Handle automatic advice activation */
643 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
645 call2 (Qad_activate
, symbol
, Qnil
);
646 newdef
= XSYMBOL (symbol
)->function
;
651 /* This name should be removed once it is eliminated from elsewhere. */
653 DEFUN ("defalias", Fdefalias
, Sdefalias
, 2, 2, 0,
654 "Set SYMBOL's function definition to NEWDEF, and return NEWDEF.\n\
655 Associates the function with the current load file, if any.")
657 register Lisp_Object symbol
, newdef
;
659 CHECK_SYMBOL (symbol
, 0);
660 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
661 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
663 XSYMBOL (symbol
)->function
= newdef
;
664 /* Handle automatic advice activation */
665 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
667 call2 (Qad_activate
, symbol
, Qnil
);
668 newdef
= XSYMBOL (symbol
)->function
;
670 LOADHIST_ATTACH (symbol
);
674 DEFUN ("define-function", Fdefine_function
, Sdefine_function
, 2, 2, 0,
675 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\
676 Associates the function with the current load file, if any.")
678 register Lisp_Object symbol
, newdef
;
680 CHECK_SYMBOL (symbol
, 0);
681 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
682 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
684 XSYMBOL (symbol
)->function
= newdef
;
685 /* Handle automatic advice activation */
686 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
688 call2 (Qad_activate
, symbol
, Qnil
);
689 newdef
= XSYMBOL (symbol
)->function
;
691 LOADHIST_ATTACH (symbol
);
695 DEFUN ("setplist", Fsetplist
, Ssetplist
, 2, 2, 0,
696 "Set SYMBOL's property list to NEWVAL, and return NEWVAL.")
698 register Lisp_Object symbol
, newplist
;
700 CHECK_SYMBOL (symbol
, 0);
701 XSYMBOL (symbol
)->plist
= newplist
;
706 /* Getting and setting values of symbols */
708 /* Given the raw contents of a symbol value cell,
709 return the Lisp value of the symbol.
710 This does not handle buffer-local variables; use
711 swap_in_symval_forwarding for that. */
714 do_symval_forwarding (valcontents
)
715 register Lisp_Object valcontents
;
717 register Lisp_Object val
;
719 if (MISCP (valcontents
))
720 switch (XMISCTYPE (valcontents
))
722 case Lisp_Misc_Intfwd
:
723 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
726 case Lisp_Misc_Boolfwd
:
727 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
729 case Lisp_Misc_Objfwd
:
730 return *XOBJFWD (valcontents
)->objvar
;
732 case Lisp_Misc_Buffer_Objfwd
:
733 offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
734 return *(Lisp_Object
*)(offset
+ (char *)current_buffer
);
736 case Lisp_Misc_Kboard_Objfwd
:
737 offset
= XKBOARD_OBJFWD (valcontents
)->offset
;
738 return *(Lisp_Object
*)(offset
+ (char *)current_kboard
);
743 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
744 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
745 buffer-independent contents of the value cell: forwarded just one
746 step past the buffer-localness. */
749 store_symval_forwarding (symbol
, valcontents
, newval
)
751 register Lisp_Object valcontents
, newval
;
753 switch (SWITCH_ENUM_CAST (XTYPE (valcontents
)))
756 switch (XMISCTYPE (valcontents
))
758 case Lisp_Misc_Intfwd
:
759 CHECK_NUMBER (newval
, 1);
760 *XINTFWD (valcontents
)->intvar
= XINT (newval
);
761 if (*XINTFWD (valcontents
)->intvar
!= XINT (newval
))
762 error ("Value out of range for variable `%s'",
763 XSYMBOL (symbol
)->name
->data
);
766 case Lisp_Misc_Boolfwd
:
767 *XBOOLFWD (valcontents
)->boolvar
= NILP (newval
) ? 0 : 1;
770 case Lisp_Misc_Objfwd
:
771 *XOBJFWD (valcontents
)->objvar
= newval
;
774 case Lisp_Misc_Buffer_Objfwd
:
776 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
779 type
= *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
);
780 if (! NILP (type
) && ! NILP (newval
)
781 && XTYPE (newval
) != XINT (type
))
782 buffer_slot_type_mismatch (offset
);
784 *(Lisp_Object
*)(offset
+ (char *)current_buffer
) = newval
;
788 case Lisp_Misc_Kboard_Objfwd
:
789 (*(Lisp_Object
*)((char *)current_kboard
790 + XKBOARD_OBJFWD (valcontents
)->offset
))
801 valcontents
= XSYMBOL (symbol
)->value
;
802 if (BUFFER_LOCAL_VALUEP (valcontents
)
803 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
804 XBUFFER_LOCAL_VALUE (valcontents
)->car
= newval
;
806 XSYMBOL (symbol
)->value
= newval
;
810 /* Set up the buffer-local symbol SYMBOL for validity in the current
811 buffer. VALCONTENTS is the contents of its value cell.
812 Return the value forwarded one step past the buffer-local indicator. */
815 swap_in_symval_forwarding (symbol
, valcontents
)
816 Lisp_Object symbol
, valcontents
;
818 /* valcontents is a pointer to a struct resembling the cons
819 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
821 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
822 local_var_alist, that being the element whose car is this
823 variable. Or it can be a pointer to the
824 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not have
825 an element in its alist for this variable.
827 If the current buffer is not BUFFER, we store the current
828 REALVALUE value into CURRENT-ALIST-ELEMENT, then find the
829 appropriate alist element for the buffer now current and set up
830 CURRENT-ALIST-ELEMENT. Then we set REALVALUE out of that
831 element, and store into BUFFER.
833 Note that REALVALUE can be a forwarding pointer. */
835 register Lisp_Object tem1
;
836 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
838 if (NILP (tem1
) || current_buffer
!= XBUFFER (tem1
))
840 tem1
= XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
842 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->car
));
843 tem1
= assq_no_quit (symbol
, current_buffer
->local_var_alist
);
845 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
;
846 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
= tem1
;
847 XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
,
849 store_symval_forwarding (symbol
, XBUFFER_LOCAL_VALUE (valcontents
)->car
,
852 return XBUFFER_LOCAL_VALUE (valcontents
)->car
;
855 /* Find the value of a symbol, returning Qunbound if it's not bound.
856 This is helpful for code which just wants to get a variable's value
857 if it has one, without signaling an error.
858 Note that it must not be possible to quit
859 within this function. Great care is required for this. */
862 find_symbol_value (symbol
)
865 register Lisp_Object valcontents
, tem1
;
866 register Lisp_Object val
;
867 CHECK_SYMBOL (symbol
, 0);
868 valcontents
= XSYMBOL (symbol
)->value
;
870 if (BUFFER_LOCAL_VALUEP (valcontents
)
871 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
872 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
874 if (MISCP (valcontents
))
876 switch (XMISCTYPE (valcontents
))
878 case Lisp_Misc_Intfwd
:
879 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
882 case Lisp_Misc_Boolfwd
:
883 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
885 case Lisp_Misc_Objfwd
:
886 return *XOBJFWD (valcontents
)->objvar
;
888 case Lisp_Misc_Buffer_Objfwd
:
889 return *(Lisp_Object
*)(XBUFFER_OBJFWD (valcontents
)->offset
890 + (char *)current_buffer
);
892 case Lisp_Misc_Kboard_Objfwd
:
893 return *(Lisp_Object
*)(XKBOARD_OBJFWD (valcontents
)->offset
894 + (char *)current_kboard
);
901 DEFUN ("symbol-value", Fsymbol_value
, Ssymbol_value
, 1, 1, 0,
902 "Return SYMBOL's value. Error if that is void.")
908 val
= find_symbol_value (symbol
);
909 if (EQ (val
, Qunbound
))
910 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
915 DEFUN ("set", Fset
, Sset
, 2, 2, 0,
916 "Set SYMBOL's value to NEWVAL, and return NEWVAL.")
918 register Lisp_Object symbol
, newval
;
920 int voide
= EQ (newval
, Qunbound
);
922 register Lisp_Object valcontents
, tem1
, current_alist_element
;
924 CHECK_SYMBOL (symbol
, 0);
925 if (NILP (symbol
) || EQ (symbol
, Qt
))
926 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
927 valcontents
= XSYMBOL (symbol
)->value
;
929 if (BUFFER_OBJFWDP (valcontents
))
931 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
932 register int mask
= XINT (*((Lisp_Object
*)
933 (idx
+ (char *)&buffer_local_flags
)));
935 current_buffer
->local_var_flags
|= mask
;
938 else if (BUFFER_LOCAL_VALUEP (valcontents
)
939 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
941 /* valcontents is actually a pointer to a struct resembling a cons,
942 with contents something like:
943 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE).
945 BUFFER is the last buffer for which this symbol's value was
948 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
949 local_var_alist, that being the element whose car is this
950 variable. Or it can be a pointer to the
951 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not
952 have an element in its alist for this variable (that is, if
953 BUFFER sees the default value of this variable).
955 If we want to examine or set the value and BUFFER is current,
956 we just examine or set REALVALUE. If BUFFER is not current, we
957 store the current REALVALUE value into CURRENT-ALIST-ELEMENT,
958 then find the appropriate alist element for the buffer now
959 current and set up CURRENT-ALIST-ELEMENT. Then we set
960 REALVALUE out of that element, and store into BUFFER.
962 If we are setting the variable and the current buffer does
963 not have an alist entry for this variable, an alist entry is
966 Note that REALVALUE can be a forwarding pointer. Each time
967 it is examined or set, forwarding must be done. */
969 /* What value are we caching right now? */
970 current_alist_element
=
971 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
973 /* If the current buffer is not the buffer whose binding is
974 currently cached, or if it's a Lisp_Buffer_Local_Value and
975 we're looking at the default value, the cache is invalid; we
976 need to write it out, and find the new CURRENT-ALIST-ELEMENT. */
978 != XBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
))
979 || (BUFFER_LOCAL_VALUEP (valcontents
)
980 && EQ (XCONS (current_alist_element
)->car
,
981 current_alist_element
)))
983 /* Write out the cached value for the old buffer; copy it
984 back to its alist element. This works if the current
985 buffer only sees the default value, too. */
986 Fsetcdr (current_alist_element
,
987 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->car
));
989 /* Find the new value for CURRENT-ALIST-ELEMENT. */
990 tem1
= Fassq (symbol
, current_buffer
->local_var_alist
);
993 /* This buffer still sees the default value. */
995 /* If the variable is a Lisp_Some_Buffer_Local_Value,
996 make CURRENT-ALIST-ELEMENT point to itself,
997 indicating that we're seeing the default value. */
998 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
999 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
;
1001 /* If it's a Lisp_Buffer_Local_Value, give this buffer a
1002 new assoc for a local value and set
1003 CURRENT-ALIST-ELEMENT to point to that. */
1006 tem1
= Fcons (symbol
, Fcdr (current_alist_element
));
1007 current_buffer
->local_var_alist
=
1008 Fcons (tem1
, current_buffer
->local_var_alist
);
1011 /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT. */
1012 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
1015 /* Set BUFFER, now that CURRENT-ALIST-ELEMENT is accurate. */
1016 XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
,
1019 valcontents
= XBUFFER_LOCAL_VALUE (valcontents
)->car
;
1022 /* If storing void (making the symbol void), forward only through
1023 buffer-local indicator, not through Lisp_Objfwd, etc. */
1025 store_symval_forwarding (symbol
, Qnil
, newval
);
1027 store_symval_forwarding (symbol
, valcontents
, newval
);
1032 /* Access or set a buffer-local symbol's default value. */
1034 /* Return the default value of SYMBOL, but don't check for voidness.
1035 Return Qunbound if it is void. */
1038 default_value (symbol
)
1041 register Lisp_Object valcontents
;
1043 CHECK_SYMBOL (symbol
, 0);
1044 valcontents
= XSYMBOL (symbol
)->value
;
1046 /* For a built-in buffer-local variable, get the default value
1047 rather than letting do_symval_forwarding get the current value. */
1048 if (BUFFER_OBJFWDP (valcontents
))
1050 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1052 if (XINT (*(Lisp_Object
*) (idx
+ (char *) &buffer_local_flags
)) != 0)
1053 return *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
);
1056 /* Handle user-created local variables. */
1057 if (BUFFER_LOCAL_VALUEP (valcontents
)
1058 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1060 /* If var is set up for a buffer that lacks a local value for it,
1061 the current value is nominally the default value.
1062 But the current value slot may be more up to date, since
1063 ordinary setq stores just that slot. So use that. */
1064 Lisp_Object current_alist_element
, alist_element_car
;
1065 current_alist_element
1066 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
1067 alist_element_car
= XCONS (current_alist_element
)->car
;
1068 if (EQ (alist_element_car
, current_alist_element
))
1069 return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->car
);
1071 return XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->cdr
;
1073 /* For other variables, get the current value. */
1074 return do_symval_forwarding (valcontents
);
1077 DEFUN ("default-boundp", Fdefault_boundp
, Sdefault_boundp
, 1, 1, 0,
1078 "Return T if SYMBOL has a non-void default value.\n\
1079 This is the value that is seen in buffers that do not have their own values\n\
1080 for this variable.")
1084 register Lisp_Object value
;
1086 value
= default_value (symbol
);
1087 return (EQ (value
, Qunbound
) ? Qnil
: Qt
);
1090 DEFUN ("default-value", Fdefault_value
, Sdefault_value
, 1, 1, 0,
1091 "Return SYMBOL's default value.\n\
1092 This is the value that is seen in buffers that do not have their own values\n\
1093 for this variable. The default value is meaningful for variables with\n\
1094 local bindings in certain buffers.")
1098 register Lisp_Object value
;
1100 value
= default_value (symbol
);
1101 if (EQ (value
, Qunbound
))
1102 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
1106 DEFUN ("set-default", Fset_default
, Sset_default
, 2, 2, 0,
1107 "Set SYMBOL's default value to VAL. SYMBOL and VAL are evaluated.\n\
1108 The default value is seen in buffers that do not have their own values\n\
1109 for this variable.")
1111 Lisp_Object symbol
, value
;
1113 register Lisp_Object valcontents
, current_alist_element
, alist_element_buffer
;
1115 CHECK_SYMBOL (symbol
, 0);
1116 valcontents
= XSYMBOL (symbol
)->value
;
1118 /* Handle variables like case-fold-search that have special slots
1119 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1121 if (BUFFER_OBJFWDP (valcontents
))
1123 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1124 register struct buffer
*b
;
1125 register int mask
= XINT (*((Lisp_Object
*)
1126 (idx
+ (char *)&buffer_local_flags
)));
1130 *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
) = value
;
1131 for (b
= all_buffers
; b
; b
= b
->next
)
1132 if (!(b
->local_var_flags
& mask
))
1133 *(Lisp_Object
*)(idx
+ (char *) b
) = value
;
1138 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1139 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1140 return Fset (symbol
, value
);
1142 /* Store new value into the DEFAULT-VALUE slot */
1143 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->cdr
= value
;
1145 /* If that slot is current, we must set the REALVALUE slot too */
1146 current_alist_element
1147 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
1148 alist_element_buffer
= Fcar (current_alist_element
);
1149 if (EQ (alist_element_buffer
, current_alist_element
))
1150 store_symval_forwarding (symbol
, XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1156 DEFUN ("setq-default", Fsetq_default
, Ssetq_default
, 2, UNEVALLED
, 0,
1157 "Set the default value of variable VAR to VALUE.\n\
1158 VAR, the variable name, is literal (not evaluated);\n\
1159 VALUE is an expression and it is evaluated.\n\
1160 The default value of a variable is seen in buffers\n\
1161 that do not have their own values for the variable.\n\
1163 More generally, you can use multiple variables and values, as in\n\
1164 (setq-default SYMBOL VALUE SYMBOL VALUE...)\n\
1165 This sets each SYMBOL's default value to the corresponding VALUE.\n\
1166 The VALUE for the Nth SYMBOL can refer to the new default values\n\
1171 register Lisp_Object args_left
;
1172 register Lisp_Object val
, symbol
;
1173 struct gcpro gcpro1
;
1183 val
= Feval (Fcar (Fcdr (args_left
)));
1184 symbol
= Fcar (args_left
);
1185 Fset_default (symbol
, val
);
1186 args_left
= Fcdr (Fcdr (args_left
));
1188 while (!NILP (args_left
));
1194 /* Lisp functions for creating and removing buffer-local variables. */
1196 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local
, Smake_variable_buffer_local
,
1197 1, 1, "vMake Variable Buffer Local: ",
1198 "Make VARIABLE have a separate value for each buffer.\n\
1199 At any time, the value for the current buffer is in effect.\n\
1200 There is also a default value which is seen in any buffer which has not yet\n\
1201 set its own value.\n\
1202 Using `set' or `setq' to set the variable causes it to have a separate value\n\
1203 for the current buffer if it was previously using the default value.\n\
1204 The function `default-value' gets the default value and `set-default' sets it.")
1206 register Lisp_Object variable
;
1208 register Lisp_Object tem
, valcontents
, newval
;
1210 CHECK_SYMBOL (variable
, 0);
1212 valcontents
= XSYMBOL (variable
)->value
;
1213 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1214 error ("Symbol %s may not be buffer-local", XSYMBOL (variable
)->name
->data
);
1216 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1218 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1220 XMISCTYPE (XSYMBOL (variable
)->value
) = Lisp_Misc_Buffer_Local_Value
;
1223 if (EQ (valcontents
, Qunbound
))
1224 XSYMBOL (variable
)->value
= Qnil
;
1225 tem
= Fcons (Qnil
, Fsymbol_value (variable
));
1226 XCONS (tem
)->car
= tem
;
1227 newval
= allocate_misc ();
1228 XMISCTYPE (newval
) = Lisp_Misc_Buffer_Local_Value
;
1229 XBUFFER_LOCAL_VALUE (newval
)->car
= XSYMBOL (variable
)->value
;
1230 XBUFFER_LOCAL_VALUE (newval
)->cdr
= Fcons (Fcurrent_buffer (), tem
);
1231 XSYMBOL (variable
)->value
= newval
;
1235 DEFUN ("make-local-variable", Fmake_local_variable
, Smake_local_variable
,
1236 1, 1, "vMake Local Variable: ",
1237 "Make VARIABLE have a separate value in the current buffer.\n\
1238 Other buffers will continue to share a common default value.\n\
1239 \(The buffer-local value of VARIABLE starts out as the same value\n\
1240 VARIABLE previously had. If VARIABLE was void, it remains void.\)\n\
1241 See also `make-variable-buffer-local'.\n\n\
1242 If the variable is already arranged to become local when set,\n\
1243 this function causes a local value to exist for this buffer,\n\
1244 just as setting the variable would do.\n\
1246 Do not use `make-local-variable' to make a hook variable buffer-local.\n\
1247 Use `make-local-hook' instead.")
1249 register Lisp_Object variable
;
1251 register Lisp_Object tem
, valcontents
;
1253 CHECK_SYMBOL (variable
, 0);
1255 valcontents
= XSYMBOL (variable
)->value
;
1256 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1257 error ("Symbol %s may not be buffer-local", XSYMBOL (variable
)->name
->data
);
1259 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1261 tem
= Fboundp (variable
);
1263 /* Make sure the symbol has a local value in this particular buffer,
1264 by setting it to the same value it already has. */
1265 Fset (variable
, (EQ (tem
, Qt
) ? Fsymbol_value (variable
) : Qunbound
));
1268 /* Make sure symbol is set up to hold per-buffer values */
1269 if (!SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1272 tem
= Fcons (Qnil
, do_symval_forwarding (valcontents
));
1273 XCONS (tem
)->car
= tem
;
1274 newval
= allocate_misc ();
1275 XMISCTYPE (newval
) = Lisp_Misc_Some_Buffer_Local_Value
;
1276 XBUFFER_LOCAL_VALUE (newval
)->car
= XSYMBOL (variable
)->value
;
1277 XBUFFER_LOCAL_VALUE (newval
)->cdr
= Fcons (Qnil
, tem
);
1278 XSYMBOL (variable
)->value
= newval
;
1280 /* Make sure this buffer has its own value of symbol */
1281 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1284 /* Swap out any local binding for some other buffer, and make
1285 sure the current value is permanently recorded, if it's the
1287 find_symbol_value (variable
);
1289 current_buffer
->local_var_alist
1290 = Fcons (Fcons (variable
, XCONS (XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (variable
)->value
)->cdr
)->cdr
)->cdr
),
1291 current_buffer
->local_var_alist
);
1293 /* Make sure symbol does not think it is set up for this buffer;
1294 force it to look once again for this buffer's value */
1296 Lisp_Object
*pvalbuf
;
1298 valcontents
= XSYMBOL (variable
)->value
;
1300 pvalbuf
= &XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
1301 if (current_buffer
== XBUFFER (*pvalbuf
))
1306 /* If the symbol forwards into a C variable, then swap in the
1307 variable for this buffer immediately. If C code modifies the
1308 variable before we swap in, then that new value will clobber the
1309 default value the next time we swap. */
1310 valcontents
= XBUFFER_LOCAL_VALUE (XSYMBOL (variable
)->value
)->car
;
1311 if (INTFWDP (valcontents
) || BOOLFWDP (valcontents
) || OBJFWDP (valcontents
))
1312 swap_in_symval_forwarding (variable
, XSYMBOL (variable
)->value
);
1317 DEFUN ("kill-local-variable", Fkill_local_variable
, Skill_local_variable
,
1318 1, 1, "vKill Local Variable: ",
1319 "Make VARIABLE no longer have a separate value in the current buffer.\n\
1320 From now on the default value will apply in this buffer.")
1322 register Lisp_Object variable
;
1324 register Lisp_Object tem
, valcontents
;
1326 CHECK_SYMBOL (variable
, 0);
1328 valcontents
= XSYMBOL (variable
)->value
;
1330 if (BUFFER_OBJFWDP (valcontents
))
1332 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1333 register int mask
= XINT (*((Lisp_Object
*)
1334 (idx
+ (char *)&buffer_local_flags
)));
1338 *(Lisp_Object
*)(idx
+ (char *) current_buffer
)
1339 = *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
);
1340 current_buffer
->local_var_flags
&= ~mask
;
1345 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1346 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1349 /* Get rid of this buffer's alist element, if any */
1351 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1353 current_buffer
->local_var_alist
1354 = Fdelq (tem
, current_buffer
->local_var_alist
);
1356 /* If the symbol is set up for the current buffer, recompute its
1357 value. We have to do it now, or else forwarded objects won't
1360 Lisp_Object
*pvalbuf
;
1361 valcontents
= XSYMBOL (variable
)->value
;
1362 pvalbuf
= &XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
1363 if (current_buffer
== XBUFFER (*pvalbuf
))
1366 find_symbol_value (variable
);
1373 DEFUN ("local-variable-p", Flocal_variable_p
, Slocal_variable_p
,
1375 "Non-nil if VARIABLE has a local binding in buffer BUFFER.\n\
1376 BUFFER defaults to the current buffer.")
1378 register Lisp_Object variable
, buffer
;
1380 Lisp_Object valcontents
;
1381 register struct buffer
*buf
;
1384 buf
= current_buffer
;
1387 CHECK_BUFFER (buffer
, 0);
1388 buf
= XBUFFER (buffer
);
1391 CHECK_SYMBOL (variable
, 0);
1393 valcontents
= XSYMBOL (variable
)->value
;
1394 if (BUFFER_LOCAL_VALUEP (valcontents
)
1395 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1397 Lisp_Object tail
, elt
;
1398 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1400 elt
= XCONS (tail
)->car
;
1401 if (EQ (variable
, XCONS (elt
)->car
))
1405 if (BUFFER_OBJFWDP (valcontents
))
1407 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1408 int mask
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
1409 if (mask
== -1 || (buf
->local_var_flags
& mask
))
1415 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p
, Slocal_variable_if_set_p
,
1417 "Non-nil if VARIABLE will be local in buffer BUFFER if it is set there.\n\
1418 BUFFER defaults to the current buffer.")
1420 register Lisp_Object variable
, buffer
;
1422 Lisp_Object valcontents
;
1423 register struct buffer
*buf
;
1426 buf
= current_buffer
;
1429 CHECK_BUFFER (buffer
, 0);
1430 buf
= XBUFFER (buffer
);
1433 CHECK_SYMBOL (variable
, 0);
1435 valcontents
= XSYMBOL (variable
)->value
;
1437 /* This means that make-variable-buffer-local was done. */
1438 if (BUFFER_LOCAL_VALUEP (valcontents
))
1440 /* All these slots become local if they are set. */
1441 if (BUFFER_OBJFWDP (valcontents
))
1443 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1445 Lisp_Object tail
, elt
;
1446 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1448 elt
= XCONS (tail
)->car
;
1449 if (EQ (variable
, XCONS (elt
)->car
))
1456 /* Find the function at the end of a chain of symbol function indirections. */
1458 /* If OBJECT is a symbol, find the end of its function chain and
1459 return the value found there. If OBJECT is not a symbol, just
1460 return it. If there is a cycle in the function chain, signal a
1461 cyclic-function-indirection error.
1463 This is like Findirect_function, except that it doesn't signal an
1464 error if the chain ends up unbound. */
1466 indirect_function (object
)
1467 register Lisp_Object object
;
1469 Lisp_Object tortoise
, hare
;
1471 hare
= tortoise
= object
;
1475 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1477 hare
= XSYMBOL (hare
)->function
;
1478 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1480 hare
= XSYMBOL (hare
)->function
;
1482 tortoise
= XSYMBOL (tortoise
)->function
;
1484 if (EQ (hare
, tortoise
))
1485 Fsignal (Qcyclic_function_indirection
, Fcons (object
, Qnil
));
1491 DEFUN ("indirect-function", Findirect_function
, Sindirect_function
, 1, 1, 0,
1492 "Return the function at the end of OBJECT's function chain.\n\
1493 If OBJECT is a symbol, follow all function indirections and return the final\n\
1494 function binding.\n\
1495 If OBJECT is not a symbol, just return it.\n\
1496 Signal a void-function error if the final symbol is unbound.\n\
1497 Signal a cyclic-function-indirection error if there is a loop in the\n\
1498 function chain of symbols.")
1500 register Lisp_Object object
;
1504 result
= indirect_function (object
);
1506 if (EQ (result
, Qunbound
))
1507 return Fsignal (Qvoid_function
, Fcons (object
, Qnil
));
1511 /* Extract and set vector and string elements */
1513 DEFUN ("aref", Faref
, Saref
, 2, 2, 0,
1514 "Return the element of ARRAY at index IDX.\n\
1515 ARRAY may be a vector, a string, a char-table, a bool-vector,\n\
1516 or a byte-code object. IDX starts at 0.")
1518 register Lisp_Object array
;
1521 register int idxval
;
1523 CHECK_NUMBER (idx
, 1);
1524 idxval
= XINT (idx
);
1525 if (STRINGP (array
))
1528 if (idxval
< 0 || idxval
>= XSTRING (array
)->size
)
1529 args_out_of_range (array
, idx
);
1530 XSETFASTINT (val
, (unsigned char) XSTRING (array
)->data
[idxval
]);
1533 else if (BOOL_VECTOR_P (array
))
1537 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1538 args_out_of_range (array
, idx
);
1540 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
];
1541 return (val
& (1 << (idxval
% BITS_PER_CHAR
)) ? Qt
: Qnil
);
1543 else if (CHAR_TABLE_P (array
))
1548 args_out_of_range (array
, idx
);
1550 if ((unsigned) idxval
>= CHAR_TABLE_ORDINARY_SLOTS
)
1551 args_out_of_range (array
, idx
);
1552 return val
= XCHAR_TABLE (array
)->contents
[idxval
];
1554 if ((unsigned) idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
1555 val
= XCHAR_TABLE (array
)->data
[idxval
];
1559 unsigned char c1
, c2
;
1560 Lisp_Object val
, temp
;
1562 BREAKUP_NON_ASCII_CHAR (idxval
, charset
, c1
, c2
);
1564 try_parent_char_table
:
1565 val
= XCHAR_TABLE (array
)->contents
[charset
];
1566 if (c1
== 0 || !CHAR_TABLE_P (val
))
1569 temp
= XCHAR_TABLE (val
)->contents
[c1
];
1571 val
= XCHAR_TABLE (val
)->defalt
;
1575 if (NILP (val
) && !NILP (XCHAR_TABLE (array
)->parent
))
1577 array
= XCHAR_TABLE (array
)->parent
;
1578 goto try_parent_char_table
;
1582 if (c2
== 0 || !CHAR_TABLE_P (val
))
1585 temp
= XCHAR_TABLE (val
)->contents
[c2
];
1587 val
= XCHAR_TABLE (val
)->defalt
;
1591 if (NILP (val
) && !NILP (XCHAR_TABLE (array
)->parent
))
1593 array
= XCHAR_TABLE (array
)->parent
;
1594 goto try_parent_char_table
;
1604 if (VECTORP (array
))
1605 size
= XVECTOR (array
)->size
;
1606 else if (COMPILEDP (array
))
1607 size
= XVECTOR (array
)->size
& PSEUDOVECTOR_SIZE_MASK
;
1609 wrong_type_argument (Qarrayp
, array
);
1611 if (idxval
< 0 || idxval
>= size
)
1612 args_out_of_range (array
, idx
);
1613 return XVECTOR (array
)->contents
[idxval
];
1617 DEFUN ("aset", Faset
, Saset
, 3, 3, 0,
1618 "Store into the element of ARRAY at index IDX the value NEWELT.\n\
1619 ARRAY may be a vector or a string. IDX starts at 0.")
1620 (array
, idx
, newelt
)
1621 register Lisp_Object array
;
1622 Lisp_Object idx
, newelt
;
1624 register int idxval
;
1626 CHECK_NUMBER (idx
, 1);
1627 idxval
= XINT (idx
);
1628 if (!VECTORP (array
) && !STRINGP (array
) && !BOOL_VECTOR_P (array
)
1629 && ! CHAR_TABLE_P (array
))
1630 array
= wrong_type_argument (Qarrayp
, array
);
1631 CHECK_IMPURE (array
);
1633 if (VECTORP (array
))
1635 if (idxval
< 0 || idxval
>= XVECTOR (array
)->size
)
1636 args_out_of_range (array
, idx
);
1637 XVECTOR (array
)->contents
[idxval
] = newelt
;
1639 else if (BOOL_VECTOR_P (array
))
1643 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1644 args_out_of_range (array
, idx
);
1646 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
];
1648 if (! NILP (newelt
))
1649 val
|= 1 << (idxval
% BITS_PER_CHAR
);
1651 val
&= ~(1 << (idxval
% BITS_PER_CHAR
));
1652 XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
] = val
;
1654 else if (CHAR_TABLE_P (array
))
1659 args_out_of_range (array
, idx
);
1661 if (idxval
>= CHAR_TABLE_ORDINARY_SLOTS
)
1662 args_out_of_range (array
, idx
);
1663 XCHAR_TABLE (array
)->contents
[idxval
] = newelt
;
1666 if (idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
1667 val
= XCHAR_TABLE (array
)->contents
[idxval
];
1671 unsigned char c1
, c2
;
1672 Lisp_Object val
, val2
;
1674 BREAKUP_NON_ASCII_CHAR (idxval
, charset
, c1
, c2
);
1677 return XCHAR_TABLE (array
)->contents
[charset
] = newelt
;
1679 val
= XCHAR_TABLE (array
)->contents
[charset
];
1680 if (!CHAR_TABLE_P (val
))
1681 XCHAR_TABLE (array
)->contents
[charset
]
1682 = val
= Fmake_char_table (Qnil
);
1685 return XCHAR_TABLE (val
)->contents
[c1
] = newelt
;
1687 val2
= XCHAR_TABLE (val
)->contents
[c2
];
1688 if (!CHAR_TABLE_P (val2
))
1689 XCHAR_TABLE (val
)->contents
[charset
]
1690 = val2
= Fmake_char_table (Qnil
);
1692 return XCHAR_TABLE (val2
)->contents
[c2
] = newelt
;
1698 if (idxval
< 0 || idxval
>= XSTRING (array
)->size
)
1699 args_out_of_range (array
, idx
);
1700 CHECK_NUMBER (newelt
, 2);
1701 XSTRING (array
)->data
[idxval
] = XINT (newelt
);
1707 /* Arithmetic functions */
1709 enum comparison
{ equal
, notequal
, less
, grtr
, less_or_equal
, grtr_or_equal
};
1712 arithcompare (num1
, num2
, comparison
)
1713 Lisp_Object num1
, num2
;
1714 enum comparison comparison
;
1719 #ifdef LISP_FLOAT_TYPE
1720 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1
, 0);
1721 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2
, 0);
1723 if (FLOATP (num1
) || FLOATP (num2
))
1726 f1
= (FLOATP (num1
)) ? XFLOAT (num1
)->data
: XINT (num1
);
1727 f2
= (FLOATP (num2
)) ? XFLOAT (num2
)->data
: XINT (num2
);
1730 CHECK_NUMBER_COERCE_MARKER (num1
, 0);
1731 CHECK_NUMBER_COERCE_MARKER (num2
, 0);
1732 #endif /* LISP_FLOAT_TYPE */
1737 if (floatp
? f1
== f2
: XINT (num1
) == XINT (num2
))
1742 if (floatp
? f1
!= f2
: XINT (num1
) != XINT (num2
))
1747 if (floatp
? f1
< f2
: XINT (num1
) < XINT (num2
))
1752 if (floatp
? f1
<= f2
: XINT (num1
) <= XINT (num2
))
1757 if (floatp
? f1
> f2
: XINT (num1
) > XINT (num2
))
1762 if (floatp
? f1
>= f2
: XINT (num1
) >= XINT (num2
))
1771 DEFUN ("=", Feqlsign
, Seqlsign
, 2, 2, 0,
1772 "T if two args, both numbers or markers, are equal.")
1774 register Lisp_Object num1
, num2
;
1776 return arithcompare (num1
, num2
, equal
);
1779 DEFUN ("<", Flss
, Slss
, 2, 2, 0,
1780 "T if first arg is less than second arg. Both must be numbers or markers.")
1782 register Lisp_Object num1
, num2
;
1784 return arithcompare (num1
, num2
, less
);
1787 DEFUN (">", Fgtr
, Sgtr
, 2, 2, 0,
1788 "T if first arg is greater than second arg. Both must be numbers or markers.")
1790 register Lisp_Object num1
, num2
;
1792 return arithcompare (num1
, num2
, grtr
);
1795 DEFUN ("<=", Fleq
, Sleq
, 2, 2, 0,
1796 "T if first arg is less than or equal to second arg.\n\
1797 Both must be numbers or markers.")
1799 register Lisp_Object num1
, num2
;
1801 return arithcompare (num1
, num2
, less_or_equal
);
1804 DEFUN (">=", Fgeq
, Sgeq
, 2, 2, 0,
1805 "T if first arg is greater than or equal to second arg.\n\
1806 Both must be numbers or markers.")
1808 register Lisp_Object num1
, num2
;
1810 return arithcompare (num1
, num2
, grtr_or_equal
);
1813 DEFUN ("/=", Fneq
, Sneq
, 2, 2, 0,
1814 "T if first arg is not equal to second arg. Both must be numbers or markers.")
1816 register Lisp_Object num1
, num2
;
1818 return arithcompare (num1
, num2
, notequal
);
1821 DEFUN ("zerop", Fzerop
, Szerop
, 1, 1, 0, "T if NUMBER is zero.")
1823 register Lisp_Object number
;
1825 #ifdef LISP_FLOAT_TYPE
1826 CHECK_NUMBER_OR_FLOAT (number
, 0);
1828 if (FLOATP (number
))
1830 if (XFLOAT(number
)->data
== 0.0)
1835 CHECK_NUMBER (number
, 0);
1836 #endif /* LISP_FLOAT_TYPE */
1843 /* Convert between long values and pairs of Lisp integers. */
1849 unsigned int top
= i
>> 16;
1850 unsigned int bot
= i
& 0xFFFF;
1852 return make_number (bot
);
1853 if (top
== (unsigned long)-1 >> 16)
1854 return Fcons (make_number (-1), make_number (bot
));
1855 return Fcons (make_number (top
), make_number (bot
));
1862 Lisp_Object top
, bot
;
1865 top
= XCONS (c
)->car
;
1866 bot
= XCONS (c
)->cdr
;
1868 bot
= XCONS (bot
)->car
;
1869 return ((XINT (top
) << 16) | XINT (bot
));
1872 DEFUN ("number-to-string", Fnumber_to_string
, Snumber_to_string
, 1, 1, 0,
1873 "Convert NUMBER to a string by printing it in decimal.\n\
1874 Uses a minus sign if negative.\n\
1875 NUMBER may be an integer or a floating point number.")
1879 char buffer
[VALBITS
];
1881 #ifndef LISP_FLOAT_TYPE
1882 CHECK_NUMBER (number
, 0);
1884 CHECK_NUMBER_OR_FLOAT (number
, 0);
1886 if (FLOATP (number
))
1888 char pigbuf
[350]; /* see comments in float_to_string */
1890 float_to_string (pigbuf
, XFLOAT(number
)->data
);
1891 return build_string (pigbuf
);
1893 #endif /* LISP_FLOAT_TYPE */
1895 if (sizeof (int) == sizeof (EMACS_INT
))
1896 sprintf (buffer
, "%d", XINT (number
));
1897 else if (sizeof (long) == sizeof (EMACS_INT
))
1898 sprintf (buffer
, "%ld", XINT (number
));
1901 return build_string (buffer
);
1904 DEFUN ("string-to-number", Fstring_to_number
, Sstring_to_number
, 1, 1, 0,
1905 "Convert STRING to a number by parsing it as a decimal number.\n\
1906 This parses both integers and floating point numbers.\n\
1907 It ignores leading spaces and tabs.")
1909 register Lisp_Object string
;
1914 CHECK_STRING (string
, 0);
1916 p
= XSTRING (string
)->data
;
1918 /* Skip any whitespace at the front of the number. Some versions of
1919 atoi do this anyway, so we might as well make Emacs lisp consistent. */
1920 while (*p
== ' ' || *p
== '\t')
1923 #ifdef LISP_FLOAT_TYPE
1924 if (isfloat_string (p
))
1925 return make_float (atof (p
));
1926 #endif /* LISP_FLOAT_TYPE */
1928 if (sizeof (int) == sizeof (EMACS_INT
))
1929 XSETINT (value
, atoi (p
));
1930 else if (sizeof (long) == sizeof (EMACS_INT
))
1931 XSETINT (value
, atol (p
));
1938 { Aadd
, Asub
, Amult
, Adiv
, Alogand
, Alogior
, Alogxor
, Amax
, Amin
};
1940 extern Lisp_Object
float_arith_driver ();
1943 arith_driver (code
, nargs
, args
)
1946 register Lisp_Object
*args
;
1948 register Lisp_Object val
;
1949 register int argnum
;
1950 register EMACS_INT accum
;
1951 register EMACS_INT next
;
1953 switch (SWITCH_ENUM_CAST (code
))
1966 for (argnum
= 0; argnum
< nargs
; argnum
++)
1968 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
1969 #ifdef LISP_FLOAT_TYPE
1970 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
1972 if (FLOATP (val
)) /* time to do serious math */
1973 return (float_arith_driver ((double) accum
, argnum
, code
,
1976 CHECK_NUMBER_COERCE_MARKER (val
, argnum
);
1977 #endif /* LISP_FLOAT_TYPE */
1978 args
[argnum
] = val
; /* runs into a compiler bug. */
1979 next
= XINT (args
[argnum
]);
1980 switch (SWITCH_ENUM_CAST (code
))
1982 case Aadd
: accum
+= next
; break;
1984 if (!argnum
&& nargs
!= 1)
1988 case Amult
: accum
*= next
; break;
1990 if (!argnum
) accum
= next
;
1994 Fsignal (Qarith_error
, Qnil
);
1998 case Alogand
: accum
&= next
; break;
1999 case Alogior
: accum
|= next
; break;
2000 case Alogxor
: accum
^= next
; break;
2001 case Amax
: if (!argnum
|| next
> accum
) accum
= next
; break;
2002 case Amin
: if (!argnum
|| next
< accum
) accum
= next
; break;
2006 XSETINT (val
, accum
);
2010 #ifdef LISP_FLOAT_TYPE
2013 #define isnan(x) ((x) != (x))
2016 float_arith_driver (accum
, argnum
, code
, nargs
, args
)
2018 register int argnum
;
2021 register Lisp_Object
*args
;
2023 register Lisp_Object val
;
2026 for (; argnum
< nargs
; argnum
++)
2028 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2029 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
2033 next
= XFLOAT (val
)->data
;
2037 args
[argnum
] = val
; /* runs into a compiler bug. */
2038 next
= XINT (args
[argnum
]);
2040 switch (SWITCH_ENUM_CAST (code
))
2046 if (!argnum
&& nargs
!= 1)
2059 Fsignal (Qarith_error
, Qnil
);
2066 return wrong_type_argument (Qinteger_or_marker_p
, val
);
2068 if (!argnum
|| isnan (next
) || next
> accum
)
2072 if (!argnum
|| isnan (next
) || next
< accum
)
2078 return make_float (accum
);
2080 #endif /* LISP_FLOAT_TYPE */
2082 DEFUN ("+", Fplus
, Splus
, 0, MANY
, 0,
2083 "Return sum of any number of arguments, which are numbers or markers.")
2088 return arith_driver (Aadd
, nargs
, args
);
2091 DEFUN ("-", Fminus
, Sminus
, 0, MANY
, 0,
2092 "Negate number or subtract numbers or markers.\n\
2093 With one arg, negates it. With more than one arg,\n\
2094 subtracts all but the first from the first.")
2099 return arith_driver (Asub
, nargs
, args
);
2102 DEFUN ("*", Ftimes
, Stimes
, 0, MANY
, 0,
2103 "Returns product of any number of arguments, which are numbers or markers.")
2108 return arith_driver (Amult
, nargs
, args
);
2111 DEFUN ("/", Fquo
, Squo
, 2, MANY
, 0,
2112 "Returns first argument divided by all the remaining arguments.\n\
2113 The arguments must be numbers or markers.")
2118 return arith_driver (Adiv
, nargs
, args
);
2121 DEFUN ("%", Frem
, Srem
, 2, 2, 0,
2122 "Returns remainder of X divided by Y.\n\
2123 Both must be integers or markers.")
2125 register Lisp_Object x
, y
;
2129 CHECK_NUMBER_COERCE_MARKER (x
, 0);
2130 CHECK_NUMBER_COERCE_MARKER (y
, 1);
2132 if (XFASTINT (y
) == 0)
2133 Fsignal (Qarith_error
, Qnil
);
2135 XSETINT (val
, XINT (x
) % XINT (y
));
2146 return (f1
- f2
* floor (f1
/f2
));
2148 #endif /* ! HAVE_FMOD */
2150 DEFUN ("mod", Fmod
, Smod
, 2, 2, 0,
2151 "Returns X modulo Y.\n\
2152 The result falls between zero (inclusive) and Y (exclusive).\n\
2153 Both X and Y must be numbers or markers.")
2155 register Lisp_Object x
, y
;
2160 #ifdef LISP_FLOAT_TYPE
2161 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x
, 0);
2162 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y
, 1);
2164 if (FLOATP (x
) || FLOATP (y
))
2168 f1
= FLOATP (x
) ? XFLOAT (x
)->data
: XINT (x
);
2169 f2
= FLOATP (y
) ? XFLOAT (y
)->data
: XINT (y
);
2171 Fsignal (Qarith_error
, Qnil
);
2174 /* If the "remainder" comes out with the wrong sign, fix it. */
2175 if (f2
< 0 ? f1
> 0 : f1
< 0)
2177 return (make_float (f1
));
2179 #else /* not LISP_FLOAT_TYPE */
2180 CHECK_NUMBER_COERCE_MARKER (x
, 0);
2181 CHECK_NUMBER_COERCE_MARKER (y
, 1);
2182 #endif /* not LISP_FLOAT_TYPE */
2188 Fsignal (Qarith_error
, Qnil
);
2192 /* If the "remainder" comes out with the wrong sign, fix it. */
2193 if (i2
< 0 ? i1
> 0 : i1
< 0)
2200 DEFUN ("max", Fmax
, Smax
, 1, MANY
, 0,
2201 "Return largest of all the arguments (which must be numbers or markers).\n\
2202 The value is always a number; markers are converted to numbers.")
2207 return arith_driver (Amax
, nargs
, args
);
2210 DEFUN ("min", Fmin
, Smin
, 1, MANY
, 0,
2211 "Return smallest of all the arguments (which must be numbers or markers).\n\
2212 The value is always a number; markers are converted to numbers.")
2217 return arith_driver (Amin
, nargs
, args
);
2220 DEFUN ("logand", Flogand
, Slogand
, 0, MANY
, 0,
2221 "Return bitwise-and of all the arguments.\n\
2222 Arguments may be integers, or markers converted to integers.")
2227 return arith_driver (Alogand
, nargs
, args
);
2230 DEFUN ("logior", Flogior
, Slogior
, 0, MANY
, 0,
2231 "Return bitwise-or of all the arguments.\n\
2232 Arguments may be integers, or markers converted to integers.")
2237 return arith_driver (Alogior
, nargs
, args
);
2240 DEFUN ("logxor", Flogxor
, Slogxor
, 0, MANY
, 0,
2241 "Return bitwise-exclusive-or of all the arguments.\n\
2242 Arguments may be integers, or markers converted to integers.")
2247 return arith_driver (Alogxor
, nargs
, args
);
2250 DEFUN ("ash", Fash
, Sash
, 2, 2, 0,
2251 "Return VALUE with its bits shifted left by COUNT.\n\
2252 If COUNT is negative, shifting is actually to the right.\n\
2253 In this case, the sign bit is duplicated.")
2255 register Lisp_Object value
, count
;
2257 register Lisp_Object val
;
2259 CHECK_NUMBER (value
, 0);
2260 CHECK_NUMBER (count
, 1);
2262 if (XINT (count
) > 0)
2263 XSETINT (val
, XINT (value
) << XFASTINT (count
));
2265 XSETINT (val
, XINT (value
) >> -XINT (count
));
2269 DEFUN ("lsh", Flsh
, Slsh
, 2, 2, 0,
2270 "Return VALUE with its bits shifted left by COUNT.\n\
2271 If COUNT is negative, shifting is actually to the right.\n\
2272 In this case, zeros are shifted in on the left.")
2274 register Lisp_Object value
, count
;
2276 register Lisp_Object val
;
2278 CHECK_NUMBER (value
, 0);
2279 CHECK_NUMBER (count
, 1);
2281 if (XINT (count
) > 0)
2282 XSETINT (val
, (EMACS_UINT
) XUINT (value
) << XFASTINT (count
));
2284 XSETINT (val
, (EMACS_UINT
) XUINT (value
) >> -XINT (count
));
2288 DEFUN ("1+", Fadd1
, Sadd1
, 1, 1, 0,
2289 "Return NUMBER plus one. NUMBER may be a number or a marker.\n\
2290 Markers are converted to integers.")
2292 register Lisp_Object number
;
2294 #ifdef LISP_FLOAT_TYPE
2295 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
, 0);
2297 if (FLOATP (number
))
2298 return (make_float (1.0 + XFLOAT (number
)->data
));
2300 CHECK_NUMBER_COERCE_MARKER (number
, 0);
2301 #endif /* LISP_FLOAT_TYPE */
2303 XSETINT (number
, XINT (number
) + 1);
2307 DEFUN ("1-", Fsub1
, Ssub1
, 1, 1, 0,
2308 "Return NUMBER minus one. NUMBER may be a number or a marker.\n\
2309 Markers are converted to integers.")
2311 register Lisp_Object number
;
2313 #ifdef LISP_FLOAT_TYPE
2314 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
, 0);
2316 if (FLOATP (number
))
2317 return (make_float (-1.0 + XFLOAT (number
)->data
));
2319 CHECK_NUMBER_COERCE_MARKER (number
, 0);
2320 #endif /* LISP_FLOAT_TYPE */
2322 XSETINT (number
, XINT (number
) - 1);
2326 DEFUN ("lognot", Flognot
, Slognot
, 1, 1, 0,
2327 "Return the bitwise complement of NUMBER. NUMBER must be an integer.")
2329 register Lisp_Object number
;
2331 CHECK_NUMBER (number
, 0);
2332 XSETINT (number
, ~XINT (number
));
2339 Lisp_Object error_tail
, arith_tail
;
2341 Qquote
= intern ("quote");
2342 Qlambda
= intern ("lambda");
2343 Qsubr
= intern ("subr");
2344 Qerror_conditions
= intern ("error-conditions");
2345 Qerror_message
= intern ("error-message");
2346 Qtop_level
= intern ("top-level");
2348 Qerror
= intern ("error");
2349 Qquit
= intern ("quit");
2350 Qwrong_type_argument
= intern ("wrong-type-argument");
2351 Qargs_out_of_range
= intern ("args-out-of-range");
2352 Qvoid_function
= intern ("void-function");
2353 Qcyclic_function_indirection
= intern ("cyclic-function-indirection");
2354 Qvoid_variable
= intern ("void-variable");
2355 Qsetting_constant
= intern ("setting-constant");
2356 Qinvalid_read_syntax
= intern ("invalid-read-syntax");
2358 Qinvalid_function
= intern ("invalid-function");
2359 Qwrong_number_of_arguments
= intern ("wrong-number-of-arguments");
2360 Qno_catch
= intern ("no-catch");
2361 Qend_of_file
= intern ("end-of-file");
2362 Qarith_error
= intern ("arith-error");
2363 Qbeginning_of_buffer
= intern ("beginning-of-buffer");
2364 Qend_of_buffer
= intern ("end-of-buffer");
2365 Qbuffer_read_only
= intern ("buffer-read-only");
2366 Qmark_inactive
= intern ("mark-inactive");
2368 Qlistp
= intern ("listp");
2369 Qconsp
= intern ("consp");
2370 Qsymbolp
= intern ("symbolp");
2371 Qintegerp
= intern ("integerp");
2372 Qnatnump
= intern ("natnump");
2373 Qwholenump
= intern ("wholenump");
2374 Qstringp
= intern ("stringp");
2375 Qarrayp
= intern ("arrayp");
2376 Qsequencep
= intern ("sequencep");
2377 Qbufferp
= intern ("bufferp");
2378 Qvectorp
= intern ("vectorp");
2379 Qchar_or_string_p
= intern ("char-or-string-p");
2380 Qmarkerp
= intern ("markerp");
2381 Qbuffer_or_string_p
= intern ("buffer-or-string-p");
2382 Qinteger_or_marker_p
= intern ("integer-or-marker-p");
2383 Qboundp
= intern ("boundp");
2384 Qfboundp
= intern ("fboundp");
2386 #ifdef LISP_FLOAT_TYPE
2387 Qfloatp
= intern ("floatp");
2388 Qnumberp
= intern ("numberp");
2389 Qnumber_or_marker_p
= intern ("number-or-marker-p");
2390 #endif /* LISP_FLOAT_TYPE */
2392 Qchar_table_p
= intern ("char-table-p");
2393 Qvector_or_char_table_p
= intern ("vector-or-char-table-p");
2395 Qcdr
= intern ("cdr");
2397 /* Handle automatic advice activation */
2398 Qad_advice_info
= intern ("ad-advice-info");
2399 Qad_activate
= intern ("ad-activate");
2401 error_tail
= Fcons (Qerror
, Qnil
);
2403 /* ERROR is used as a signaler for random errors for which nothing else is right */
2405 Fput (Qerror
, Qerror_conditions
,
2407 Fput (Qerror
, Qerror_message
,
2408 build_string ("error"));
2410 Fput (Qquit
, Qerror_conditions
,
2411 Fcons (Qquit
, Qnil
));
2412 Fput (Qquit
, Qerror_message
,
2413 build_string ("Quit"));
2415 Fput (Qwrong_type_argument
, Qerror_conditions
,
2416 Fcons (Qwrong_type_argument
, error_tail
));
2417 Fput (Qwrong_type_argument
, Qerror_message
,
2418 build_string ("Wrong type argument"));
2420 Fput (Qargs_out_of_range
, Qerror_conditions
,
2421 Fcons (Qargs_out_of_range
, error_tail
));
2422 Fput (Qargs_out_of_range
, Qerror_message
,
2423 build_string ("Args out of range"));
2425 Fput (Qvoid_function
, Qerror_conditions
,
2426 Fcons (Qvoid_function
, error_tail
));
2427 Fput (Qvoid_function
, Qerror_message
,
2428 build_string ("Symbol's function definition is void"));
2430 Fput (Qcyclic_function_indirection
, Qerror_conditions
,
2431 Fcons (Qcyclic_function_indirection
, error_tail
));
2432 Fput (Qcyclic_function_indirection
, Qerror_message
,
2433 build_string ("Symbol's chain of function indirections contains a loop"));
2435 Fput (Qvoid_variable
, Qerror_conditions
,
2436 Fcons (Qvoid_variable
, error_tail
));
2437 Fput (Qvoid_variable
, Qerror_message
,
2438 build_string ("Symbol's value as variable is void"));
2440 Fput (Qsetting_constant
, Qerror_conditions
,
2441 Fcons (Qsetting_constant
, error_tail
));
2442 Fput (Qsetting_constant
, Qerror_message
,
2443 build_string ("Attempt to set a constant symbol"));
2445 Fput (Qinvalid_read_syntax
, Qerror_conditions
,
2446 Fcons (Qinvalid_read_syntax
, error_tail
));
2447 Fput (Qinvalid_read_syntax
, Qerror_message
,
2448 build_string ("Invalid read syntax"));
2450 Fput (Qinvalid_function
, Qerror_conditions
,
2451 Fcons (Qinvalid_function
, error_tail
));
2452 Fput (Qinvalid_function
, Qerror_message
,
2453 build_string ("Invalid function"));
2455 Fput (Qwrong_number_of_arguments
, Qerror_conditions
,
2456 Fcons (Qwrong_number_of_arguments
, error_tail
));
2457 Fput (Qwrong_number_of_arguments
, Qerror_message
,
2458 build_string ("Wrong number of arguments"));
2460 Fput (Qno_catch
, Qerror_conditions
,
2461 Fcons (Qno_catch
, error_tail
));
2462 Fput (Qno_catch
, Qerror_message
,
2463 build_string ("No catch for tag"));
2465 Fput (Qend_of_file
, Qerror_conditions
,
2466 Fcons (Qend_of_file
, error_tail
));
2467 Fput (Qend_of_file
, Qerror_message
,
2468 build_string ("End of file during parsing"));
2470 arith_tail
= Fcons (Qarith_error
, error_tail
);
2471 Fput (Qarith_error
, Qerror_conditions
,
2473 Fput (Qarith_error
, Qerror_message
,
2474 build_string ("Arithmetic error"));
2476 Fput (Qbeginning_of_buffer
, Qerror_conditions
,
2477 Fcons (Qbeginning_of_buffer
, error_tail
));
2478 Fput (Qbeginning_of_buffer
, Qerror_message
,
2479 build_string ("Beginning of buffer"));
2481 Fput (Qend_of_buffer
, Qerror_conditions
,
2482 Fcons (Qend_of_buffer
, error_tail
));
2483 Fput (Qend_of_buffer
, Qerror_message
,
2484 build_string ("End of buffer"));
2486 Fput (Qbuffer_read_only
, Qerror_conditions
,
2487 Fcons (Qbuffer_read_only
, error_tail
));
2488 Fput (Qbuffer_read_only
, Qerror_message
,
2489 build_string ("Buffer is read-only"));
2491 #ifdef LISP_FLOAT_TYPE
2492 Qrange_error
= intern ("range-error");
2493 Qdomain_error
= intern ("domain-error");
2494 Qsingularity_error
= intern ("singularity-error");
2495 Qoverflow_error
= intern ("overflow-error");
2496 Qunderflow_error
= intern ("underflow-error");
2498 Fput (Qdomain_error
, Qerror_conditions
,
2499 Fcons (Qdomain_error
, arith_tail
));
2500 Fput (Qdomain_error
, Qerror_message
,
2501 build_string ("Arithmetic domain error"));
2503 Fput (Qrange_error
, Qerror_conditions
,
2504 Fcons (Qrange_error
, arith_tail
));
2505 Fput (Qrange_error
, Qerror_message
,
2506 build_string ("Arithmetic range error"));
2508 Fput (Qsingularity_error
, Qerror_conditions
,
2509 Fcons (Qsingularity_error
, Fcons (Qdomain_error
, arith_tail
)));
2510 Fput (Qsingularity_error
, Qerror_message
,
2511 build_string ("Arithmetic singularity error"));
2513 Fput (Qoverflow_error
, Qerror_conditions
,
2514 Fcons (Qoverflow_error
, Fcons (Qdomain_error
, arith_tail
)));
2515 Fput (Qoverflow_error
, Qerror_message
,
2516 build_string ("Arithmetic overflow error"));
2518 Fput (Qunderflow_error
, Qerror_conditions
,
2519 Fcons (Qunderflow_error
, Fcons (Qdomain_error
, arith_tail
)));
2520 Fput (Qunderflow_error
, Qerror_message
,
2521 build_string ("Arithmetic underflow error"));
2523 staticpro (&Qrange_error
);
2524 staticpro (&Qdomain_error
);
2525 staticpro (&Qsingularity_error
);
2526 staticpro (&Qoverflow_error
);
2527 staticpro (&Qunderflow_error
);
2528 #endif /* LISP_FLOAT_TYPE */
2532 staticpro (&Qquote
);
2533 staticpro (&Qlambda
);
2535 staticpro (&Qunbound
);
2536 staticpro (&Qerror_conditions
);
2537 staticpro (&Qerror_message
);
2538 staticpro (&Qtop_level
);
2540 staticpro (&Qerror
);
2542 staticpro (&Qwrong_type_argument
);
2543 staticpro (&Qargs_out_of_range
);
2544 staticpro (&Qvoid_function
);
2545 staticpro (&Qcyclic_function_indirection
);
2546 staticpro (&Qvoid_variable
);
2547 staticpro (&Qsetting_constant
);
2548 staticpro (&Qinvalid_read_syntax
);
2549 staticpro (&Qwrong_number_of_arguments
);
2550 staticpro (&Qinvalid_function
);
2551 staticpro (&Qno_catch
);
2552 staticpro (&Qend_of_file
);
2553 staticpro (&Qarith_error
);
2554 staticpro (&Qbeginning_of_buffer
);
2555 staticpro (&Qend_of_buffer
);
2556 staticpro (&Qbuffer_read_only
);
2557 staticpro (&Qmark_inactive
);
2559 staticpro (&Qlistp
);
2560 staticpro (&Qconsp
);
2561 staticpro (&Qsymbolp
);
2562 staticpro (&Qintegerp
);
2563 staticpro (&Qnatnump
);
2564 staticpro (&Qwholenump
);
2565 staticpro (&Qstringp
);
2566 staticpro (&Qarrayp
);
2567 staticpro (&Qsequencep
);
2568 staticpro (&Qbufferp
);
2569 staticpro (&Qvectorp
);
2570 staticpro (&Qchar_or_string_p
);
2571 staticpro (&Qmarkerp
);
2572 staticpro (&Qbuffer_or_string_p
);
2573 staticpro (&Qinteger_or_marker_p
);
2574 #ifdef LISP_FLOAT_TYPE
2575 staticpro (&Qfloatp
);
2576 staticpro (&Qnumberp
);
2577 staticpro (&Qnumber_or_marker_p
);
2578 #endif /* LISP_FLOAT_TYPE */
2579 staticpro (&Qchar_table_p
);
2580 staticpro (&Qvector_or_char_table_p
);
2582 staticpro (&Qboundp
);
2583 staticpro (&Qfboundp
);
2585 staticpro (&Qad_advice_info
);
2586 staticpro (&Qad_activate
);
2588 /* Types that type-of returns. */
2589 Qinteger
= intern ("integer");
2590 Qsymbol
= intern ("symbol");
2591 Qstring
= intern ("string");
2592 Qcons
= intern ("cons");
2593 Qmarker
= intern ("marker");
2594 Qoverlay
= intern ("overlay");
2595 Qfloat
= intern ("float");
2596 Qwindow_configuration
= intern ("window-configuration");
2597 Qprocess
= intern ("process");
2598 Qwindow
= intern ("window");
2599 /* Qsubr = intern ("subr"); */
2600 Qcompiled_function
= intern ("compiled-function");
2601 Qbuffer
= intern ("buffer");
2602 Qframe
= intern ("frame");
2603 Qvector
= intern ("vector");
2604 Qchar_table
= intern ("char-table");
2605 Qbool_vector
= intern ("bool-vector");
2607 staticpro (&Qinteger
);
2608 staticpro (&Qsymbol
);
2609 staticpro (&Qstring
);
2611 staticpro (&Qmarker
);
2612 staticpro (&Qoverlay
);
2613 staticpro (&Qfloat
);
2614 staticpro (&Qwindow_configuration
);
2615 staticpro (&Qprocess
);
2616 staticpro (&Qwindow
);
2617 /* staticpro (&Qsubr); */
2618 staticpro (&Qcompiled_function
);
2619 staticpro (&Qbuffer
);
2620 staticpro (&Qframe
);
2621 staticpro (&Qvector
);
2622 staticpro (&Qchar_table
);
2623 staticpro (&Qbool_vector
);
2627 defsubr (&Stype_of
);
2632 defsubr (&Sintegerp
);
2633 defsubr (&Sinteger_or_marker_p
);
2634 defsubr (&Snumberp
);
2635 defsubr (&Snumber_or_marker_p
);
2636 #ifdef LISP_FLOAT_TYPE
2638 #endif /* LISP_FLOAT_TYPE */
2639 defsubr (&Snatnump
);
2640 defsubr (&Ssymbolp
);
2641 defsubr (&Sstringp
);
2642 defsubr (&Svectorp
);
2643 defsubr (&Schar_table_p
);
2644 defsubr (&Svector_or_char_table_p
);
2645 defsubr (&Sbool_vector_p
);
2647 defsubr (&Ssequencep
);
2648 defsubr (&Sbufferp
);
2649 defsubr (&Smarkerp
);
2651 defsubr (&Sbyte_code_function_p
);
2652 defsubr (&Schar_or_string_p
);
2655 defsubr (&Scar_safe
);
2656 defsubr (&Scdr_safe
);
2659 defsubr (&Ssymbol_function
);
2660 defsubr (&Sindirect_function
);
2661 defsubr (&Ssymbol_plist
);
2662 defsubr (&Ssymbol_name
);
2663 defsubr (&Smakunbound
);
2664 defsubr (&Sfmakunbound
);
2666 defsubr (&Sfboundp
);
2668 defsubr (&Sdefalias
);
2669 defsubr (&Sdefine_function
);
2670 defsubr (&Ssetplist
);
2671 defsubr (&Ssymbol_value
);
2673 defsubr (&Sdefault_boundp
);
2674 defsubr (&Sdefault_value
);
2675 defsubr (&Sset_default
);
2676 defsubr (&Ssetq_default
);
2677 defsubr (&Smake_variable_buffer_local
);
2678 defsubr (&Smake_local_variable
);
2679 defsubr (&Skill_local_variable
);
2680 defsubr (&Slocal_variable_p
);
2681 defsubr (&Slocal_variable_if_set_p
);
2684 defsubr (&Snumber_to_string
);
2685 defsubr (&Sstring_to_number
);
2686 defsubr (&Seqlsign
);
2710 XSYMBOL (Qwholenump
)->function
= XSYMBOL (Qnatnump
)->function
;
2718 /* USG systems forget handlers when they are used;
2719 must reestablish each time */
2720 signal (signo
, arith_error
);
2723 /* VMS systems are like USG. */
2724 signal (signo
, arith_error
);
2728 #else /* not BSD4_1 */
2729 sigsetmask (SIGEMPTYMASK
);
2730 #endif /* not BSD4_1 */
2732 Fsignal (Qarith_error
, Qnil
);
2737 /* Don't do this if just dumping out.
2738 We don't want to call `signal' in this case
2739 so that we don't have trouble with dumping
2740 signal-delivering routines in an inconsistent state. */
2744 #endif /* CANNOT_DUMP */
2745 signal (SIGFPE
, arith_error
);
2748 signal (SIGEMT
, arith_error
);