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. */
34 #include "syssignal.h"
36 #ifdef LISP_FLOAT_TYPE
43 /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */
44 #ifndef IEEE_FLOATING_POINT
45 #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
46 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
47 #define IEEE_FLOATING_POINT 1
49 #define IEEE_FLOATING_POINT 0
53 /* Work around a problem that happens because math.h on hpux 7
54 defines two static variables--which, in Emacs, are not really static,
55 because `static' is defined as nothing. The problem is that they are
56 here, in floatfns.c, and in lread.c.
57 These macros prevent the name conflict. */
58 #if defined (HPUX) && !defined (HPUX8)
59 #define _MAXLDBL data_c_maxldbl
60 #define _NMAXLDBL data_c_nmaxldbl
64 #endif /* LISP_FLOAT_TYPE */
67 extern double atof ();
70 Lisp_Object Qnil
, Qt
, Qquote
, Qlambda
, Qsubr
, Qunbound
;
71 Lisp_Object Qerror_conditions
, Qerror_message
, Qtop_level
;
72 Lisp_Object Qerror
, Qquit
, Qwrong_type_argument
, Qargs_out_of_range
;
73 Lisp_Object Qvoid_variable
, Qvoid_function
, Qcyclic_function_indirection
;
74 Lisp_Object Qsetting_constant
, Qinvalid_read_syntax
;
75 Lisp_Object Qinvalid_function
, Qwrong_number_of_arguments
, Qno_catch
;
76 Lisp_Object Qend_of_file
, Qarith_error
, Qmark_inactive
;
77 Lisp_Object Qbeginning_of_buffer
, Qend_of_buffer
, Qbuffer_read_only
;
78 Lisp_Object Qintegerp
, Qnatnump
, Qwholenump
, Qsymbolp
, Qlistp
, Qconsp
;
79 Lisp_Object Qstringp
, Qarrayp
, Qsequencep
, Qbufferp
;
80 Lisp_Object Qchar_or_string_p
, Qmarkerp
, Qinteger_or_marker_p
, Qvectorp
;
81 Lisp_Object Qbuffer_or_string_p
;
82 Lisp_Object Qboundp
, Qfboundp
;
83 Lisp_Object Qchar_table_p
, Qvector_or_char_table_p
;
86 Lisp_Object Qad_advice_info
, Qad_activate
;
88 Lisp_Object Qrange_error
, Qdomain_error
, Qsingularity_error
;
89 Lisp_Object Qoverflow_error
, Qunderflow_error
;
91 #ifdef LISP_FLOAT_TYPE
93 Lisp_Object Qnumberp
, Qnumber_or_marker_p
;
96 static Lisp_Object Qinteger
, Qsymbol
, Qstring
, Qcons
, Qmarker
, Qoverlay
;
97 static Lisp_Object Qfloat
, Qwindow_configuration
, Qwindow
;
99 static Lisp_Object Qcompiled_function
, Qbuffer
, Qframe
, Qvector
;
100 static Lisp_Object Qchar_table
, Qbool_vector
;
102 static Lisp_Object
swap_in_symval_forwarding ();
105 wrong_type_argument (predicate
, value
)
106 register Lisp_Object predicate
, value
;
108 register Lisp_Object tem
;
111 if (!EQ (Vmocklisp_arguments
, Qt
))
113 if (STRINGP (value
) &&
114 (EQ (predicate
, Qintegerp
) || EQ (predicate
, Qinteger_or_marker_p
)))
115 return Fstring_to_number (value
);
116 if (INTEGERP (value
) && EQ (predicate
, Qstringp
))
117 return Fnumber_to_string (value
);
120 /* If VALUE is not even a valid Lisp object, abort here
121 where we can get a backtrace showing where it came from. */
122 if ((unsigned int) XGCTYPE (value
) >= Lisp_Type_Limit
)
125 value
= Fsignal (Qwrong_type_argument
, Fcons (predicate
, Fcons (value
, Qnil
)));
126 tem
= call1 (predicate
, value
);
134 error ("Attempt to modify read-only object");
138 args_out_of_range (a1
, a2
)
142 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Qnil
)));
146 args_out_of_range_3 (a1
, a2
, a3
)
147 Lisp_Object a1
, a2
, a3
;
150 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Fcons (a3
, Qnil
))));
153 /* On some machines, XINT needs a temporary location.
154 Here it is, in case it is needed. */
156 int sign_extend_temp
;
158 /* On a few machines, XINT can only be done by calling this. */
161 sign_extend_lisp_int (num
)
164 if (num
& (((EMACS_INT
) 1) << (VALBITS
- 1)))
165 return num
| (((EMACS_INT
) (-1)) << VALBITS
);
167 return num
& ((((EMACS_INT
) 1) << VALBITS
) - 1);
170 /* Data type predicates */
172 DEFUN ("eq", Feq
, Seq
, 2, 2, 0,
173 "T if the two args are the same Lisp object.")
175 Lisp_Object obj1
, obj2
;
182 DEFUN ("null", Fnull
, Snull
, 1, 1, 0, "T if OBJECT is nil.")
191 DEFUN ("type-of", Ftype_of
, Stype_of
, 1, 1, 0,
192 "Return a symbol representing the type of OBJECT.\n\
193 The symbol returned names the object's basic type;\n\
194 for example, (type-of 1) returns `integer'.")
198 switch (XGCTYPE (object
))
213 switch (XMISCTYPE (object
))
215 case Lisp_Misc_Marker
:
217 case Lisp_Misc_Overlay
:
219 case Lisp_Misc_Float
:
224 case Lisp_Vectorlike
:
225 if (GC_WINDOW_CONFIGURATIONP (object
))
226 return Qwindow_configuration
;
227 if (GC_PROCESSP (object
))
229 if (GC_WINDOWP (object
))
231 if (GC_SUBRP (object
))
233 if (GC_COMPILEDP (object
))
234 return Qcompiled_function
;
235 if (GC_BUFFERP (object
))
237 if (GC_CHAR_TABLE_P (object
))
239 if (GC_BOOL_VECTOR_P (object
))
241 if (GC_FRAMEP (object
))
245 #ifdef LISP_FLOAT_TYPE
255 DEFUN ("consp", Fconsp
, Sconsp
, 1, 1, 0, "T if OBJECT is a cons cell.")
264 DEFUN ("atom", Fatom
, Satom
, 1, 1, 0, "T if OBJECT is not a cons cell. This includes nil.")
273 DEFUN ("listp", Flistp
, Slistp
, 1, 1, 0, "T if OBJECT is a list. This includes nil.")
277 if (CONSP (object
) || NILP (object
))
282 DEFUN ("nlistp", Fnlistp
, Snlistp
, 1, 1, 0, "T if OBJECT is not a list. Lists include nil.")
286 if (CONSP (object
) || NILP (object
))
291 DEFUN ("symbolp", Fsymbolp
, Ssymbolp
, 1, 1, 0, "T if OBJECT is a symbol.")
295 if (SYMBOLP (object
))
300 DEFUN ("vectorp", Fvectorp
, Svectorp
, 1, 1, 0, "T if OBJECT is a vector.")
304 if (VECTORP (object
))
309 DEFUN ("stringp", Fstringp
, Sstringp
, 1, 1, 0, "T if OBJECT is a string.")
313 if (STRINGP (object
))
318 DEFUN ("char-table-p", Fchar_table_p
, Schar_table_p
, 1, 1, 0, "T if OBJECT is a char-table.")
322 if (CHAR_TABLE_P (object
))
327 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p
,
328 Svector_or_char_table_p
, 1, 1, 0,
329 "T if OBJECT is a char-table or vector.")
333 if (VECTORP (object
) || CHAR_TABLE_P (object
))
338 DEFUN ("bool-vector-p", Fbool_vector_p
, Sbool_vector_p
, 1, 1, 0, "T if OBJECT is a bool-vector.")
342 if (BOOL_VECTOR_P (object
))
347 DEFUN ("arrayp", Farrayp
, Sarrayp
, 1, 1, 0, "T if OBJECT is an array (string or vector).")
351 if (VECTORP (object
) || STRINGP (object
))
356 DEFUN ("sequencep", Fsequencep
, Ssequencep
, 1, 1, 0,
357 "T if OBJECT is a sequence (list or array).")
359 register Lisp_Object object
;
361 if (CONSP (object
) || NILP (object
) || VECTORP (object
) || STRINGP (object
)
362 || CHAR_TABLE_P (object
) || BOOL_VECTOR_P (object
))
367 DEFUN ("bufferp", Fbufferp
, Sbufferp
, 1, 1, 0, "T if OBJECT is an editor buffer.")
371 if (BUFFERP (object
))
376 DEFUN ("markerp", Fmarkerp
, Smarkerp
, 1, 1, 0, "T if OBJECT is a marker (editor pointer).")
380 if (MARKERP (object
))
385 DEFUN ("subrp", Fsubrp
, Ssubrp
, 1, 1, 0, "T if OBJECT is a built-in function.")
394 DEFUN ("byte-code-function-p", Fbyte_code_function_p
, Sbyte_code_function_p
,
395 1, 1, 0, "T if OBJECT is a byte-compiled function object.")
399 if (COMPILEDP (object
))
404 DEFUN ("char-or-string-p", Fchar_or_string_p
, Schar_or_string_p
, 1, 1, 0,
405 "T if OBJECT is a character (an integer) or a string.")
407 register Lisp_Object object
;
409 if (INTEGERP (object
) || STRINGP (object
))
414 DEFUN ("integerp", Fintegerp
, Sintegerp
, 1, 1, 0, "T if OBJECT is an integer.")
418 if (INTEGERP (object
))
423 DEFUN ("integer-or-marker-p", Finteger_or_marker_p
, Sinteger_or_marker_p
, 1, 1, 0,
424 "T if OBJECT is an integer or a marker (editor pointer).")
426 register Lisp_Object object
;
428 if (MARKERP (object
) || INTEGERP (object
))
433 DEFUN ("natnump", Fnatnump
, Snatnump
, 1, 1, 0,
434 "T if OBJECT is a nonnegative integer.")
438 if (NATNUMP (object
))
443 DEFUN ("numberp", Fnumberp
, Snumberp
, 1, 1, 0,
444 "T if OBJECT is a number (floating point or integer).")
448 if (NUMBERP (object
))
454 DEFUN ("number-or-marker-p", Fnumber_or_marker_p
,
455 Snumber_or_marker_p
, 1, 1, 0,
456 "T if OBJECT is a number or a marker.")
460 if (NUMBERP (object
) || MARKERP (object
))
465 #ifdef LISP_FLOAT_TYPE
466 DEFUN ("floatp", Ffloatp
, Sfloatp
, 1, 1, 0,
467 "T if OBJECT is a floating point number.")
475 #endif /* LISP_FLOAT_TYPE */
477 /* Extract and set components of lists */
479 DEFUN ("car", Fcar
, Scar
, 1, 1, 0,
480 "Return the car of LIST. If arg is nil, return nil.\n\
481 Error if arg is not nil and not a cons cell. See also `car-safe'.")
483 register Lisp_Object list
;
488 return XCONS (list
)->car
;
489 else if (EQ (list
, Qnil
))
492 list
= wrong_type_argument (Qlistp
, list
);
496 DEFUN ("car-safe", Fcar_safe
, Scar_safe
, 1, 1, 0,
497 "Return the car of OBJECT if it is a cons cell, or else nil.")
502 return XCONS (object
)->car
;
507 DEFUN ("cdr", Fcdr
, Scdr
, 1, 1, 0,
508 "Return the cdr of LIST. If arg is nil, return nil.\n\
509 Error if arg is not nil and not a cons cell. See also `cdr-safe'.")
512 register Lisp_Object list
;
517 return XCONS (list
)->cdr
;
518 else if (EQ (list
, Qnil
))
521 list
= wrong_type_argument (Qlistp
, list
);
525 DEFUN ("cdr-safe", Fcdr_safe
, Scdr_safe
, 1, 1, 0,
526 "Return the cdr of OBJECT if it is a cons cell, or else nil.")
531 return XCONS (object
)->cdr
;
536 DEFUN ("setcar", Fsetcar
, Ssetcar
, 2, 2, 0,
537 "Set the car of CELL to be NEWCAR. Returns NEWCAR.")
539 register Lisp_Object cell
, newcar
;
542 cell
= wrong_type_argument (Qconsp
, cell
);
545 XCONS (cell
)->car
= newcar
;
549 DEFUN ("setcdr", Fsetcdr
, Ssetcdr
, 2, 2, 0,
550 "Set the cdr of CELL to be NEWCDR. Returns NEWCDR.")
552 register Lisp_Object cell
, newcdr
;
555 cell
= wrong_type_argument (Qconsp
, cell
);
558 XCONS (cell
)->cdr
= newcdr
;
562 /* Extract and set components of symbols */
564 DEFUN ("boundp", Fboundp
, Sboundp
, 1, 1, 0, "T if SYMBOL's value is not void.")
566 register Lisp_Object symbol
;
568 Lisp_Object valcontents
;
569 CHECK_SYMBOL (symbol
, 0);
571 valcontents
= XSYMBOL (symbol
)->value
;
573 if (BUFFER_LOCAL_VALUEP (valcontents
)
574 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
575 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
577 return (EQ (valcontents
, Qunbound
) ? Qnil
: Qt
);
580 DEFUN ("fboundp", Ffboundp
, Sfboundp
, 1, 1, 0, "T if SYMBOL's function definition is not void.")
582 register Lisp_Object symbol
;
584 CHECK_SYMBOL (symbol
, 0);
585 return (EQ (XSYMBOL (symbol
)->function
, Qunbound
) ? Qnil
: Qt
);
588 DEFUN ("makunbound", Fmakunbound
, Smakunbound
, 1, 1, 0, "Make SYMBOL's value be void.")
590 register Lisp_Object symbol
;
592 CHECK_SYMBOL (symbol
, 0);
593 if (NILP (symbol
) || EQ (symbol
, Qt
))
594 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
595 Fset (symbol
, Qunbound
);
599 DEFUN ("fmakunbound", Ffmakunbound
, Sfmakunbound
, 1, 1, 0, "Make SYMBOL's function definition be void.")
601 register Lisp_Object symbol
;
603 CHECK_SYMBOL (symbol
, 0);
604 if (NILP (symbol
) || EQ (symbol
, Qt
))
605 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
606 XSYMBOL (symbol
)->function
= Qunbound
;
610 DEFUN ("symbol-function", Fsymbol_function
, Ssymbol_function
, 1, 1, 0,
611 "Return SYMBOL's function definition. Error if that is void.")
613 register Lisp_Object symbol
;
615 CHECK_SYMBOL (symbol
, 0);
616 if (EQ (XSYMBOL (symbol
)->function
, Qunbound
))
617 return Fsignal (Qvoid_function
, Fcons (symbol
, Qnil
));
618 return XSYMBOL (symbol
)->function
;
621 DEFUN ("symbol-plist", Fsymbol_plist
, Ssymbol_plist
, 1, 1, 0, "Return SYMBOL's property list.")
623 register Lisp_Object symbol
;
625 CHECK_SYMBOL (symbol
, 0);
626 return XSYMBOL (symbol
)->plist
;
629 DEFUN ("symbol-name", Fsymbol_name
, Ssymbol_name
, 1, 1, 0, "Return SYMBOL's name, a string.")
631 register Lisp_Object symbol
;
633 register Lisp_Object name
;
635 CHECK_SYMBOL (symbol
, 0);
636 XSETSTRING (name
, XSYMBOL (symbol
)->name
);
640 DEFUN ("fset", Ffset
, Sfset
, 2, 2, 0,
641 "Set SYMBOL's function definition to DEFINITION, and return DEFINITION.")
643 register Lisp_Object symbol
, definition
;
645 CHECK_SYMBOL (symbol
, 0);
646 if (NILP (symbol
) || EQ (symbol
, Qt
))
647 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
648 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
649 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
651 XSYMBOL (symbol
)->function
= definition
;
652 /* Handle automatic advice activation */
653 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
655 call2 (Qad_activate
, symbol
, Qnil
);
656 definition
= XSYMBOL (symbol
)->function
;
661 DEFUN ("defalias", Fdefalias
, Sdefalias
, 2, 2, 0,
662 "Set SYMBOL's function definition to DEFINITION, and return DEFINITION.\n\
663 Associates the function with the current load file, if any.")
665 register Lisp_Object symbol
, definition
;
667 CHECK_SYMBOL (symbol
, 0);
668 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
669 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
671 XSYMBOL (symbol
)->function
= definition
;
672 /* Handle automatic advice activation */
673 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
675 call2 (Qad_activate
, symbol
, Qnil
);
676 definition
= XSYMBOL (symbol
)->function
;
678 LOADHIST_ATTACH (symbol
);
682 DEFUN ("setplist", Fsetplist
, Ssetplist
, 2, 2, 0,
683 "Set SYMBOL's property list to NEWVAL, and return NEWVAL.")
685 register Lisp_Object symbol
, newplist
;
687 CHECK_SYMBOL (symbol
, 0);
688 XSYMBOL (symbol
)->plist
= newplist
;
693 /* Getting and setting values of symbols */
695 /* Given the raw contents of a symbol value cell,
696 return the Lisp value of the symbol.
697 This does not handle buffer-local variables; use
698 swap_in_symval_forwarding for that. */
701 do_symval_forwarding (valcontents
)
702 register Lisp_Object valcontents
;
704 register Lisp_Object val
;
706 if (MISCP (valcontents
))
707 switch (XMISCTYPE (valcontents
))
709 case Lisp_Misc_Intfwd
:
710 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
713 case Lisp_Misc_Boolfwd
:
714 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
716 case Lisp_Misc_Objfwd
:
717 return *XOBJFWD (valcontents
)->objvar
;
719 case Lisp_Misc_Buffer_Objfwd
:
720 offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
721 return *(Lisp_Object
*)(offset
+ (char *)current_buffer
);
723 case Lisp_Misc_Kboard_Objfwd
:
724 offset
= XKBOARD_OBJFWD (valcontents
)->offset
;
725 return *(Lisp_Object
*)(offset
+ (char *)current_kboard
);
730 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
731 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
732 buffer-independent contents of the value cell: forwarded just one
733 step past the buffer-localness. */
736 store_symval_forwarding (symbol
, valcontents
, newval
)
738 register Lisp_Object valcontents
, newval
;
740 switch (SWITCH_ENUM_CAST (XTYPE (valcontents
)))
743 switch (XMISCTYPE (valcontents
))
745 case Lisp_Misc_Intfwd
:
746 CHECK_NUMBER (newval
, 1);
747 *XINTFWD (valcontents
)->intvar
= XINT (newval
);
748 if (*XINTFWD (valcontents
)->intvar
!= XINT (newval
))
749 error ("Value out of range for variable `%s'",
750 XSYMBOL (symbol
)->name
->data
);
753 case Lisp_Misc_Boolfwd
:
754 *XBOOLFWD (valcontents
)->boolvar
= NILP (newval
) ? 0 : 1;
757 case Lisp_Misc_Objfwd
:
758 *XOBJFWD (valcontents
)->objvar
= newval
;
761 case Lisp_Misc_Buffer_Objfwd
:
763 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
766 type
= *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
);
767 if (! NILP (type
) && ! NILP (newval
)
768 && XTYPE (newval
) != XINT (type
))
769 buffer_slot_type_mismatch (offset
);
771 *(Lisp_Object
*)(offset
+ (char *)current_buffer
) = newval
;
775 case Lisp_Misc_Kboard_Objfwd
:
776 (*(Lisp_Object
*)((char *)current_kboard
777 + XKBOARD_OBJFWD (valcontents
)->offset
))
788 valcontents
= XSYMBOL (symbol
)->value
;
789 if (BUFFER_LOCAL_VALUEP (valcontents
)
790 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
791 XBUFFER_LOCAL_VALUE (valcontents
)->car
= newval
;
793 XSYMBOL (symbol
)->value
= newval
;
797 /* Set up the buffer-local symbol SYMBOL for validity in the current
798 buffer. VALCONTENTS is the contents of its value cell.
799 Return the value forwarded one step past the buffer-local indicator. */
802 swap_in_symval_forwarding (symbol
, valcontents
)
803 Lisp_Object symbol
, valcontents
;
805 /* valcontents is a pointer to a struct resembling the cons
806 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
808 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
809 local_var_alist, that being the element whose car is this
810 variable. Or it can be a pointer to the
811 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not have
812 an element in its alist for this variable.
814 If the current buffer is not BUFFER, we store the current
815 REALVALUE value into CURRENT-ALIST-ELEMENT, then find the
816 appropriate alist element for the buffer now current and set up
817 CURRENT-ALIST-ELEMENT. Then we set REALVALUE out of that
818 element, and store into BUFFER.
820 Note that REALVALUE can be a forwarding pointer. */
822 register Lisp_Object tem1
;
823 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
825 if (NILP (tem1
) || current_buffer
!= XBUFFER (tem1
))
827 tem1
= XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
829 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->car
));
830 tem1
= assq_no_quit (symbol
, current_buffer
->local_var_alist
);
832 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
;
833 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
= tem1
;
834 XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
,
836 store_symval_forwarding (symbol
, XBUFFER_LOCAL_VALUE (valcontents
)->car
,
839 return XBUFFER_LOCAL_VALUE (valcontents
)->car
;
842 /* Find the value of a symbol, returning Qunbound if it's not bound.
843 This is helpful for code which just wants to get a variable's value
844 if it has one, without signaling an error.
845 Note that it must not be possible to quit
846 within this function. Great care is required for this. */
849 find_symbol_value (symbol
)
852 register Lisp_Object valcontents
, tem1
;
853 register Lisp_Object val
;
854 CHECK_SYMBOL (symbol
, 0);
855 valcontents
= XSYMBOL (symbol
)->value
;
857 if (BUFFER_LOCAL_VALUEP (valcontents
)
858 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
859 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
861 if (MISCP (valcontents
))
863 switch (XMISCTYPE (valcontents
))
865 case Lisp_Misc_Intfwd
:
866 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
869 case Lisp_Misc_Boolfwd
:
870 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
872 case Lisp_Misc_Objfwd
:
873 return *XOBJFWD (valcontents
)->objvar
;
875 case Lisp_Misc_Buffer_Objfwd
:
876 return *(Lisp_Object
*)(XBUFFER_OBJFWD (valcontents
)->offset
877 + (char *)current_buffer
);
879 case Lisp_Misc_Kboard_Objfwd
:
880 return *(Lisp_Object
*)(XKBOARD_OBJFWD (valcontents
)->offset
881 + (char *)current_kboard
);
888 DEFUN ("symbol-value", Fsymbol_value
, Ssymbol_value
, 1, 1, 0,
889 "Return SYMBOL's value. Error if that is void.")
895 val
= find_symbol_value (symbol
);
896 if (EQ (val
, Qunbound
))
897 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
902 DEFUN ("set", Fset
, Sset
, 2, 2, 0,
903 "Set SYMBOL's value to NEWVAL, and return NEWVAL.")
905 register Lisp_Object symbol
, newval
;
907 return set_internal (symbol
, newval
, 0);
910 /* Stpre the value NEWVAL into SYMBOL.
911 If BINDFLAG is zero, then if this symbol is supposed to become
912 local in every buffer where it is set, then we make it local.
913 If BINDFLAG is nonzero, we don't do that. */
916 set_internal (symbol
, newval
, bindflag
)
917 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 or if this is `let' rather than `set',
997 make CURRENT-ALIST-ELEMENT point to itself,
998 indicating that we're seeing the default value. */
999 if (bindflag
|| SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1000 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
;
1002 /* If it's a Lisp_Buffer_Local_Value, being set not bound,
1003 give this buffer a new assoc for a local value and set
1004 CURRENT-ALIST-ELEMENT to point to that. */
1007 tem1
= Fcons (symbol
, Fcdr (current_alist_element
));
1008 current_buffer
->local_var_alist
=
1009 Fcons (tem1
, current_buffer
->local_var_alist
);
1012 /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT. */
1013 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
1016 /* Set BUFFER, now that CURRENT-ALIST-ELEMENT is accurate. */
1017 XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
,
1020 valcontents
= XBUFFER_LOCAL_VALUE (valcontents
)->car
;
1023 /* If storing void (making the symbol void), forward only through
1024 buffer-local indicator, not through Lisp_Objfwd, etc. */
1026 store_symval_forwarding (symbol
, Qnil
, newval
);
1028 store_symval_forwarding (symbol
, valcontents
, newval
);
1033 /* Access or set a buffer-local symbol's default value. */
1035 /* Return the default value of SYMBOL, but don't check for voidness.
1036 Return Qunbound if it is void. */
1039 default_value (symbol
)
1042 register Lisp_Object valcontents
;
1044 CHECK_SYMBOL (symbol
, 0);
1045 valcontents
= XSYMBOL (symbol
)->value
;
1047 /* For a built-in buffer-local variable, get the default value
1048 rather than letting do_symval_forwarding get the current value. */
1049 if (BUFFER_OBJFWDP (valcontents
))
1051 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1053 if (XINT (*(Lisp_Object
*) (idx
+ (char *) &buffer_local_flags
)) != 0)
1054 return *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
);
1057 /* Handle user-created local variables. */
1058 if (BUFFER_LOCAL_VALUEP (valcontents
)
1059 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1061 /* If var is set up for a buffer that lacks a local value for it,
1062 the current value is nominally the default value.
1063 But the current value slot may be more up to date, since
1064 ordinary setq stores just that slot. So use that. */
1065 Lisp_Object current_alist_element
, alist_element_car
;
1066 current_alist_element
1067 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
1068 alist_element_car
= XCONS (current_alist_element
)->car
;
1069 if (EQ (alist_element_car
, current_alist_element
))
1070 return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->car
);
1072 return XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->cdr
;
1074 /* For other variables, get the current value. */
1075 return do_symval_forwarding (valcontents
);
1078 DEFUN ("default-boundp", Fdefault_boundp
, Sdefault_boundp
, 1, 1, 0,
1079 "Return T if SYMBOL has a non-void default value.\n\
1080 This is the value that is seen in buffers that do not have their own values\n\
1081 for this variable.")
1085 register Lisp_Object value
;
1087 value
= default_value (symbol
);
1088 return (EQ (value
, Qunbound
) ? Qnil
: Qt
);
1091 DEFUN ("default-value", Fdefault_value
, Sdefault_value
, 1, 1, 0,
1092 "Return SYMBOL's default value.\n\
1093 This is the value that is seen in buffers that do not have their own values\n\
1094 for this variable. The default value is meaningful for variables with\n\
1095 local bindings in certain buffers.")
1099 register Lisp_Object value
;
1101 value
= default_value (symbol
);
1102 if (EQ (value
, Qunbound
))
1103 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
1107 DEFUN ("set-default", Fset_default
, Sset_default
, 2, 2, 0,
1108 "Set SYMBOL's default value to VAL. SYMBOL and VAL are evaluated.\n\
1109 The default value is seen in buffers that do not have their own values\n\
1110 for this variable.")
1112 Lisp_Object symbol
, value
;
1114 register Lisp_Object valcontents
, current_alist_element
, alist_element_buffer
;
1116 CHECK_SYMBOL (symbol
, 0);
1117 valcontents
= XSYMBOL (symbol
)->value
;
1119 /* Handle variables like case-fold-search that have special slots
1120 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1122 if (BUFFER_OBJFWDP (valcontents
))
1124 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1125 register struct buffer
*b
;
1126 register int mask
= XINT (*((Lisp_Object
*)
1127 (idx
+ (char *)&buffer_local_flags
)));
1131 *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
) = value
;
1132 for (b
= all_buffers
; b
; b
= b
->next
)
1133 if (!(b
->local_var_flags
& mask
))
1134 *(Lisp_Object
*)(idx
+ (char *) b
) = value
;
1139 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1140 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1141 return Fset (symbol
, value
);
1143 /* Store new value into the DEFAULT-VALUE slot */
1144 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->cdr
= value
;
1146 /* If that slot is current, we must set the REALVALUE slot too */
1147 current_alist_element
1148 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
1149 alist_element_buffer
= Fcar (current_alist_element
);
1150 if (EQ (alist_element_buffer
, current_alist_element
))
1151 store_symval_forwarding (symbol
, XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1157 DEFUN ("setq-default", Fsetq_default
, Ssetq_default
, 2, UNEVALLED
, 0,
1158 "Set the default value of variable VAR to VALUE.\n\
1159 VAR, the variable name, is literal (not evaluated);\n\
1160 VALUE is an expression and it is evaluated.\n\
1161 The default value of a variable is seen in buffers\n\
1162 that do not have their own values for the variable.\n\
1164 More generally, you can use multiple variables and values, as in\n\
1165 (setq-default SYMBOL VALUE SYMBOL VALUE...)\n\
1166 This sets each SYMBOL's default value to the corresponding VALUE.\n\
1167 The VALUE for the Nth SYMBOL can refer to the new default values\n\
1172 register Lisp_Object args_left
;
1173 register Lisp_Object val
, symbol
;
1174 struct gcpro gcpro1
;
1184 val
= Feval (Fcar (Fcdr (args_left
)));
1185 symbol
= Fcar (args_left
);
1186 Fset_default (symbol
, val
);
1187 args_left
= Fcdr (Fcdr (args_left
));
1189 while (!NILP (args_left
));
1195 /* Lisp functions for creating and removing buffer-local variables. */
1197 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local
, Smake_variable_buffer_local
,
1198 1, 1, "vMake Variable Buffer Local: ",
1199 "Make VARIABLE have a separate value for each buffer.\n\
1200 At any time, the value for the current buffer is in effect.\n\
1201 There is also a default value which is seen in any buffer which has not yet\n\
1202 set its own value.\n\
1203 Using `set' or `setq' to set the variable causes it to have a separate value\n\
1204 for the current buffer if it was previously using the default value.\n\
1205 The function `default-value' gets the default value and `set-default' sets it.")
1207 register Lisp_Object variable
;
1209 register Lisp_Object tem
, valcontents
, newval
;
1211 CHECK_SYMBOL (variable
, 0);
1213 valcontents
= XSYMBOL (variable
)->value
;
1214 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1215 error ("Symbol %s may not be buffer-local", XSYMBOL (variable
)->name
->data
);
1217 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1219 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1221 XMISCTYPE (XSYMBOL (variable
)->value
) = Lisp_Misc_Buffer_Local_Value
;
1224 if (EQ (valcontents
, Qunbound
))
1225 XSYMBOL (variable
)->value
= Qnil
;
1226 tem
= Fcons (Qnil
, Fsymbol_value (variable
));
1227 XCONS (tem
)->car
= tem
;
1228 newval
= allocate_misc ();
1229 XMISCTYPE (newval
) = Lisp_Misc_Buffer_Local_Value
;
1230 XBUFFER_LOCAL_VALUE (newval
)->car
= XSYMBOL (variable
)->value
;
1231 XBUFFER_LOCAL_VALUE (newval
)->cdr
= Fcons (Fcurrent_buffer (), tem
);
1232 XSYMBOL (variable
)->value
= newval
;
1236 DEFUN ("make-local-variable", Fmake_local_variable
, Smake_local_variable
,
1237 1, 1, "vMake Local Variable: ",
1238 "Make VARIABLE have a separate value in the current buffer.\n\
1239 Other buffers will continue to share a common default value.\n\
1240 \(The buffer-local value of VARIABLE starts out as the same value\n\
1241 VARIABLE previously had. If VARIABLE was void, it remains void.\)\n\
1242 See also `make-variable-buffer-local'.\n\n\
1243 If the variable is already arranged to become local when set,\n\
1244 this function causes a local value to exist for this buffer,\n\
1245 just as setting the variable would do.\n\
1247 Do not use `make-local-variable' to make a hook variable buffer-local.\n\
1248 Use `make-local-hook' instead.")
1250 register Lisp_Object variable
;
1252 register Lisp_Object tem
, valcontents
;
1254 CHECK_SYMBOL (variable
, 0);
1256 valcontents
= XSYMBOL (variable
)->value
;
1257 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1258 error ("Symbol %s may not be buffer-local", XSYMBOL (variable
)->name
->data
);
1260 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1262 tem
= Fboundp (variable
);
1264 /* Make sure the symbol has a local value in this particular buffer,
1265 by setting it to the same value it already has. */
1266 Fset (variable
, (EQ (tem
, Qt
) ? Fsymbol_value (variable
) : Qunbound
));
1269 /* Make sure symbol is set up to hold per-buffer values */
1270 if (!SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1273 tem
= Fcons (Qnil
, do_symval_forwarding (valcontents
));
1274 XCONS (tem
)->car
= tem
;
1275 newval
= allocate_misc ();
1276 XMISCTYPE (newval
) = Lisp_Misc_Some_Buffer_Local_Value
;
1277 XBUFFER_LOCAL_VALUE (newval
)->car
= XSYMBOL (variable
)->value
;
1278 XBUFFER_LOCAL_VALUE (newval
)->cdr
= Fcons (Qnil
, tem
);
1279 XSYMBOL (variable
)->value
= newval
;
1281 /* Make sure this buffer has its own value of symbol */
1282 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1285 /* Swap out any local binding for some other buffer, and make
1286 sure the current value is permanently recorded, if it's the
1288 find_symbol_value (variable
);
1290 current_buffer
->local_var_alist
1291 = Fcons (Fcons (variable
, XCONS (XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (variable
)->value
)->cdr
)->cdr
)->cdr
),
1292 current_buffer
->local_var_alist
);
1294 /* Make sure symbol does not think it is set up for this buffer;
1295 force it to look once again for this buffer's value */
1297 Lisp_Object
*pvalbuf
;
1299 valcontents
= XSYMBOL (variable
)->value
;
1301 pvalbuf
= &XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
1302 if (current_buffer
== XBUFFER (*pvalbuf
))
1307 /* If the symbol forwards into a C variable, then swap in the
1308 variable for this buffer immediately. If C code modifies the
1309 variable before we swap in, then that new value will clobber the
1310 default value the next time we swap. */
1311 valcontents
= XBUFFER_LOCAL_VALUE (XSYMBOL (variable
)->value
)->car
;
1312 if (INTFWDP (valcontents
) || BOOLFWDP (valcontents
) || OBJFWDP (valcontents
))
1313 swap_in_symval_forwarding (variable
, XSYMBOL (variable
)->value
);
1318 DEFUN ("kill-local-variable", Fkill_local_variable
, Skill_local_variable
,
1319 1, 1, "vKill Local Variable: ",
1320 "Make VARIABLE no longer have a separate value in the current buffer.\n\
1321 From now on the default value will apply in this buffer.")
1323 register Lisp_Object variable
;
1325 register Lisp_Object tem
, valcontents
;
1327 CHECK_SYMBOL (variable
, 0);
1329 valcontents
= XSYMBOL (variable
)->value
;
1331 if (BUFFER_OBJFWDP (valcontents
))
1333 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1334 register int mask
= XINT (*((Lisp_Object
*)
1335 (idx
+ (char *)&buffer_local_flags
)));
1339 *(Lisp_Object
*)(idx
+ (char *) current_buffer
)
1340 = *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
);
1341 current_buffer
->local_var_flags
&= ~mask
;
1346 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1347 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1350 /* Get rid of this buffer's alist element, if any */
1352 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1354 current_buffer
->local_var_alist
1355 = Fdelq (tem
, current_buffer
->local_var_alist
);
1357 /* If the symbol is set up for the current buffer, recompute its
1358 value. We have to do it now, or else forwarded objects won't
1361 Lisp_Object
*pvalbuf
;
1362 valcontents
= XSYMBOL (variable
)->value
;
1363 pvalbuf
= &XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
1364 if (current_buffer
== XBUFFER (*pvalbuf
))
1367 find_symbol_value (variable
);
1374 DEFUN ("local-variable-p", Flocal_variable_p
, Slocal_variable_p
,
1376 "Non-nil if VARIABLE has a local binding in buffer BUFFER.\n\
1377 BUFFER defaults to the current buffer.")
1379 register Lisp_Object variable
, buffer
;
1381 Lisp_Object valcontents
;
1382 register struct buffer
*buf
;
1385 buf
= current_buffer
;
1388 CHECK_BUFFER (buffer
, 0);
1389 buf
= XBUFFER (buffer
);
1392 CHECK_SYMBOL (variable
, 0);
1394 valcontents
= XSYMBOL (variable
)->value
;
1395 if (BUFFER_LOCAL_VALUEP (valcontents
)
1396 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1398 Lisp_Object tail
, elt
;
1399 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1401 elt
= XCONS (tail
)->car
;
1402 if (EQ (variable
, XCONS (elt
)->car
))
1406 if (BUFFER_OBJFWDP (valcontents
))
1408 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1409 int mask
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
1410 if (mask
== -1 || (buf
->local_var_flags
& mask
))
1416 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p
, Slocal_variable_if_set_p
,
1418 "Non-nil if VARIABLE will be local in buffer BUFFER if it is set there.\n\
1419 BUFFER defaults to the current buffer.")
1421 register Lisp_Object variable
, buffer
;
1423 Lisp_Object valcontents
;
1424 register struct buffer
*buf
;
1427 buf
= current_buffer
;
1430 CHECK_BUFFER (buffer
, 0);
1431 buf
= XBUFFER (buffer
);
1434 CHECK_SYMBOL (variable
, 0);
1436 valcontents
= XSYMBOL (variable
)->value
;
1438 /* This means that make-variable-buffer-local was done. */
1439 if (BUFFER_LOCAL_VALUEP (valcontents
))
1441 /* All these slots become local if they are set. */
1442 if (BUFFER_OBJFWDP (valcontents
))
1444 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1446 Lisp_Object tail
, elt
;
1447 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1449 elt
= XCONS (tail
)->car
;
1450 if (EQ (variable
, XCONS (elt
)->car
))
1457 /* Find the function at the end of a chain of symbol function indirections. */
1459 /* If OBJECT is a symbol, find the end of its function chain and
1460 return the value found there. If OBJECT is not a symbol, just
1461 return it. If there is a cycle in the function chain, signal a
1462 cyclic-function-indirection error.
1464 This is like Findirect_function, except that it doesn't signal an
1465 error if the chain ends up unbound. */
1467 indirect_function (object
)
1468 register Lisp_Object object
;
1470 Lisp_Object tortoise
, hare
;
1472 hare
= tortoise
= object
;
1476 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1478 hare
= XSYMBOL (hare
)->function
;
1479 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1481 hare
= XSYMBOL (hare
)->function
;
1483 tortoise
= XSYMBOL (tortoise
)->function
;
1485 if (EQ (hare
, tortoise
))
1486 Fsignal (Qcyclic_function_indirection
, Fcons (object
, Qnil
));
1492 DEFUN ("indirect-function", Findirect_function
, Sindirect_function
, 1, 1, 0,
1493 "Return the function at the end of OBJECT's function chain.\n\
1494 If OBJECT is a symbol, follow all function indirections and return the final\n\
1495 function binding.\n\
1496 If OBJECT is not a symbol, just return it.\n\
1497 Signal a void-function error if the final symbol is unbound.\n\
1498 Signal a cyclic-function-indirection error if there is a loop in the\n\
1499 function chain of symbols.")
1501 register Lisp_Object object
;
1505 result
= indirect_function (object
);
1507 if (EQ (result
, Qunbound
))
1508 return Fsignal (Qvoid_function
, Fcons (object
, Qnil
));
1512 /* Extract and set vector and string elements */
1514 DEFUN ("aref", Faref
, Saref
, 2, 2, 0,
1515 "Return the element of ARRAY at index IDX.\n\
1516 ARRAY may be a vector, a string, a char-table, a bool-vector,\n\
1517 or a byte-code object. IDX starts at 0.")
1519 register Lisp_Object array
;
1522 register int idxval
;
1524 CHECK_NUMBER (idx
, 1);
1525 idxval
= XINT (idx
);
1526 if (STRINGP (array
))
1529 if (idxval
< 0 || idxval
>= XSTRING (array
)->size
)
1530 args_out_of_range (array
, idx
);
1531 XSETFASTINT (val
, (unsigned char) XSTRING (array
)->data
[idxval
]);
1534 else if (BOOL_VECTOR_P (array
))
1538 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1539 args_out_of_range (array
, idx
);
1541 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
];
1542 return (val
& (1 << (idxval
% BITS_PER_CHAR
)) ? Qt
: Qnil
);
1544 else if (CHAR_TABLE_P (array
))
1549 args_out_of_range (array
, idx
);
1550 if (idxval
< CHAR_TABLE_SINGLE_BYTE_SLOTS
)
1552 /* For ASCII and 8-bit European characters, the element is
1553 stored in the top table. */
1554 val
= XCHAR_TABLE (array
)->contents
[idxval
];
1556 val
= XCHAR_TABLE (array
)->defalt
;
1557 while (NILP (val
)) /* Follow parents until we find some value. */
1559 array
= XCHAR_TABLE (array
)->parent
;
1562 val
= XCHAR_TABLE (array
)->contents
[idxval
];
1564 val
= XCHAR_TABLE (array
)->defalt
;
1571 Lisp_Object sub_table
;
1573 SPLIT_NON_ASCII_CHAR (idxval
, code
[0], code
[1], code
[2]);
1574 if (code
[0] != CHARSET_COMPOSITION
)
1576 if (code
[1] < 32) code
[1] = -1;
1577 else if (code
[2] < 32) code
[2] = -1;
1579 /* Here, the possible range of CODE[0] (== charset ID) is
1580 128..MAX_CHARSET. Since the top level char table contains
1581 data for multibyte characters after 256th element, we must
1582 increment CODE[0] by 128 to get a correct index. */
1584 code
[3] = -1; /* anchor */
1586 try_parent_char_table
:
1588 for (i
= 0; code
[i
] >= 0; i
++)
1590 val
= XCHAR_TABLE (sub_table
)->contents
[code
[i
]];
1591 if (SUB_CHAR_TABLE_P (val
))
1596 val
= XCHAR_TABLE (sub_table
)->defalt
;
1599 array
= XCHAR_TABLE (array
)->parent
;
1601 goto try_parent_char_table
;
1606 /* Here, VAL is a sub char table. We try the default value
1608 val
= XCHAR_TABLE (val
)->defalt
;
1611 array
= XCHAR_TABLE (array
)->parent
;
1613 goto try_parent_char_table
;
1621 if (VECTORP (array
))
1622 size
= XVECTOR (array
)->size
;
1623 else if (COMPILEDP (array
))
1624 size
= XVECTOR (array
)->size
& PSEUDOVECTOR_SIZE_MASK
;
1626 wrong_type_argument (Qarrayp
, array
);
1628 if (idxval
< 0 || idxval
>= size
)
1629 args_out_of_range (array
, idx
);
1630 return XVECTOR (array
)->contents
[idxval
];
1634 DEFUN ("aset", Faset
, Saset
, 3, 3, 0,
1635 "Store into the element of ARRAY at index IDX the value NEWELT.\n\
1636 ARRAY may be a vector or a string. IDX starts at 0.")
1637 (array
, idx
, newelt
)
1638 register Lisp_Object array
;
1639 Lisp_Object idx
, newelt
;
1641 register int idxval
;
1643 CHECK_NUMBER (idx
, 1);
1644 idxval
= XINT (idx
);
1645 if (!VECTORP (array
) && !STRINGP (array
) && !BOOL_VECTOR_P (array
)
1646 && ! CHAR_TABLE_P (array
))
1647 array
= wrong_type_argument (Qarrayp
, array
);
1648 CHECK_IMPURE (array
);
1650 if (VECTORP (array
))
1652 if (idxval
< 0 || idxval
>= XVECTOR (array
)->size
)
1653 args_out_of_range (array
, idx
);
1654 XVECTOR (array
)->contents
[idxval
] = newelt
;
1656 else if (BOOL_VECTOR_P (array
))
1660 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1661 args_out_of_range (array
, idx
);
1663 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
];
1665 if (! NILP (newelt
))
1666 val
|= 1 << (idxval
% BITS_PER_CHAR
);
1668 val
&= ~(1 << (idxval
% BITS_PER_CHAR
));
1669 XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
] = val
;
1671 else if (CHAR_TABLE_P (array
))
1676 args_out_of_range (array
, idx
);
1677 if (idxval
< CHAR_TABLE_SINGLE_BYTE_SLOTS
)
1678 XCHAR_TABLE (array
)->contents
[idxval
] = newelt
;
1684 SPLIT_NON_ASCII_CHAR (idxval
, code
[0], code
[1], code
[2]);
1685 if (code
[0] != CHARSET_COMPOSITION
)
1687 if (code
[1] < 32) code
[1] = -1;
1688 else if (code
[2] < 32) code
[2] = -1;
1690 /* See the comment of the corresponding part in Faref. */
1692 code
[3] = -1; /* anchor */
1693 for (i
= 0; code
[i
+ 1] >= 0; i
++)
1695 val
= XCHAR_TABLE (array
)->contents
[code
[i
]];
1696 if (SUB_CHAR_TABLE_P (val
))
1699 /* VAL is a leaf. Create a sub char table with the
1700 default value VAL here and look into it. */
1701 array
= (XCHAR_TABLE (array
)->contents
[code
[i
]]
1702 = make_sub_char_table (val
));
1704 XCHAR_TABLE (array
)->contents
[code
[i
]] = newelt
;
1709 if (idxval
< 0 || idxval
>= XSTRING (array
)->size
)
1710 args_out_of_range (array
, idx
);
1711 CHECK_NUMBER (newelt
, 2);
1712 XSTRING (array
)->data
[idxval
] = XINT (newelt
);
1718 /* Arithmetic functions */
1720 enum comparison
{ equal
, notequal
, less
, grtr
, less_or_equal
, grtr_or_equal
};
1723 arithcompare (num1
, num2
, comparison
)
1724 Lisp_Object num1
, num2
;
1725 enum comparison comparison
;
1730 #ifdef LISP_FLOAT_TYPE
1731 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1
, 0);
1732 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2
, 0);
1734 if (FLOATP (num1
) || FLOATP (num2
))
1737 f1
= (FLOATP (num1
)) ? XFLOAT (num1
)->data
: XINT (num1
);
1738 f2
= (FLOATP (num2
)) ? XFLOAT (num2
)->data
: XINT (num2
);
1741 CHECK_NUMBER_COERCE_MARKER (num1
, 0);
1742 CHECK_NUMBER_COERCE_MARKER (num2
, 0);
1743 #endif /* LISP_FLOAT_TYPE */
1748 if (floatp
? f1
== f2
: XINT (num1
) == XINT (num2
))
1753 if (floatp
? f1
!= f2
: XINT (num1
) != XINT (num2
))
1758 if (floatp
? f1
< f2
: XINT (num1
) < XINT (num2
))
1763 if (floatp
? f1
<= f2
: XINT (num1
) <= XINT (num2
))
1768 if (floatp
? f1
> f2
: XINT (num1
) > XINT (num2
))
1773 if (floatp
? f1
>= f2
: XINT (num1
) >= XINT (num2
))
1782 DEFUN ("=", Feqlsign
, Seqlsign
, 2, 2, 0,
1783 "T if two args, both numbers or markers, are equal.")
1785 register Lisp_Object num1
, num2
;
1787 return arithcompare (num1
, num2
, equal
);
1790 DEFUN ("<", Flss
, Slss
, 2, 2, 0,
1791 "T if first arg is less than second arg. Both must be numbers or markers.")
1793 register Lisp_Object num1
, num2
;
1795 return arithcompare (num1
, num2
, less
);
1798 DEFUN (">", Fgtr
, Sgtr
, 2, 2, 0,
1799 "T if first arg is greater than second arg. Both must be numbers or markers.")
1801 register Lisp_Object num1
, num2
;
1803 return arithcompare (num1
, num2
, grtr
);
1806 DEFUN ("<=", Fleq
, Sleq
, 2, 2, 0,
1807 "T if first arg is less than or equal to second arg.\n\
1808 Both must be numbers or markers.")
1810 register Lisp_Object num1
, num2
;
1812 return arithcompare (num1
, num2
, less_or_equal
);
1815 DEFUN (">=", Fgeq
, Sgeq
, 2, 2, 0,
1816 "T if first arg is greater than or equal to second arg.\n\
1817 Both must be numbers or markers.")
1819 register Lisp_Object num1
, num2
;
1821 return arithcompare (num1
, num2
, grtr_or_equal
);
1824 DEFUN ("/=", Fneq
, Sneq
, 2, 2, 0,
1825 "T if first arg is not equal to second arg. Both must be numbers or markers.")
1827 register Lisp_Object num1
, num2
;
1829 return arithcompare (num1
, num2
, notequal
);
1832 DEFUN ("zerop", Fzerop
, Szerop
, 1, 1, 0, "T if NUMBER is zero.")
1834 register Lisp_Object number
;
1836 #ifdef LISP_FLOAT_TYPE
1837 CHECK_NUMBER_OR_FLOAT (number
, 0);
1839 if (FLOATP (number
))
1841 if (XFLOAT(number
)->data
== 0.0)
1846 CHECK_NUMBER (number
, 0);
1847 #endif /* LISP_FLOAT_TYPE */
1854 /* Convert between long values and pairs of Lisp integers. */
1860 unsigned int top
= i
>> 16;
1861 unsigned int bot
= i
& 0xFFFF;
1863 return make_number (bot
);
1864 if (top
== (unsigned long)-1 >> 16)
1865 return Fcons (make_number (-1), make_number (bot
));
1866 return Fcons (make_number (top
), make_number (bot
));
1873 Lisp_Object top
, bot
;
1876 top
= XCONS (c
)->car
;
1877 bot
= XCONS (c
)->cdr
;
1879 bot
= XCONS (bot
)->car
;
1880 return ((XINT (top
) << 16) | XINT (bot
));
1883 DEFUN ("number-to-string", Fnumber_to_string
, Snumber_to_string
, 1, 1, 0,
1884 "Convert NUMBER to a string by printing it in decimal.\n\
1885 Uses a minus sign if negative.\n\
1886 NUMBER may be an integer or a floating point number.")
1890 char buffer
[VALBITS
];
1892 #ifndef LISP_FLOAT_TYPE
1893 CHECK_NUMBER (number
, 0);
1895 CHECK_NUMBER_OR_FLOAT (number
, 0);
1897 if (FLOATP (number
))
1899 char pigbuf
[350]; /* see comments in float_to_string */
1901 float_to_string (pigbuf
, XFLOAT(number
)->data
);
1902 return build_string (pigbuf
);
1904 #endif /* LISP_FLOAT_TYPE */
1906 if (sizeof (int) == sizeof (EMACS_INT
))
1907 sprintf (buffer
, "%d", XINT (number
));
1908 else if (sizeof (long) == sizeof (EMACS_INT
))
1909 sprintf (buffer
, "%ld", XINT (number
));
1912 return build_string (buffer
);
1915 DEFUN ("string-to-number", Fstring_to_number
, Sstring_to_number
, 1, 1, 0,
1916 "Convert STRING to a number by parsing it as a decimal number.\n\
1917 This parses both integers and floating point numbers.\n\
1918 It ignores leading spaces and tabs.")
1920 register Lisp_Object string
;
1925 CHECK_STRING (string
, 0);
1927 p
= XSTRING (string
)->data
;
1929 /* Skip any whitespace at the front of the number. Some versions of
1930 atoi do this anyway, so we might as well make Emacs lisp consistent. */
1931 while (*p
== ' ' || *p
== '\t')
1934 #ifdef LISP_FLOAT_TYPE
1935 if (isfloat_string (p
))
1936 return make_float (atof (p
));
1937 #endif /* LISP_FLOAT_TYPE */
1939 if (sizeof (int) == sizeof (EMACS_INT
))
1940 XSETINT (value
, atoi (p
));
1941 else if (sizeof (long) == sizeof (EMACS_INT
))
1942 XSETINT (value
, atol (p
));
1949 { Aadd
, Asub
, Amult
, Adiv
, Alogand
, Alogior
, Alogxor
, Amax
, Amin
};
1951 extern Lisp_Object
float_arith_driver ();
1952 extern Lisp_Object
fmod_float ();
1955 arith_driver (code
, nargs
, args
)
1958 register Lisp_Object
*args
;
1960 register Lisp_Object val
;
1961 register int argnum
;
1962 register EMACS_INT accum
;
1963 register EMACS_INT next
;
1965 switch (SWITCH_ENUM_CAST (code
))
1978 for (argnum
= 0; argnum
< nargs
; argnum
++)
1980 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
1981 #ifdef LISP_FLOAT_TYPE
1982 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
1984 if (FLOATP (val
)) /* time to do serious math */
1985 return (float_arith_driver ((double) accum
, argnum
, code
,
1988 CHECK_NUMBER_COERCE_MARKER (val
, argnum
);
1989 #endif /* LISP_FLOAT_TYPE */
1990 args
[argnum
] = val
; /* runs into a compiler bug. */
1991 next
= XINT (args
[argnum
]);
1992 switch (SWITCH_ENUM_CAST (code
))
1994 case Aadd
: accum
+= next
; break;
1996 if (!argnum
&& nargs
!= 1)
2000 case Amult
: accum
*= next
; break;
2002 if (!argnum
) accum
= next
;
2006 Fsignal (Qarith_error
, Qnil
);
2010 case Alogand
: accum
&= next
; break;
2011 case Alogior
: accum
|= next
; break;
2012 case Alogxor
: accum
^= next
; break;
2013 case Amax
: if (!argnum
|| next
> accum
) accum
= next
; break;
2014 case Amin
: if (!argnum
|| next
< accum
) accum
= next
; break;
2018 XSETINT (val
, accum
);
2023 #define isnan(x) ((x) != (x))
2025 #ifdef LISP_FLOAT_TYPE
2028 float_arith_driver (accum
, argnum
, code
, nargs
, args
)
2030 register int argnum
;
2033 register Lisp_Object
*args
;
2035 register Lisp_Object val
;
2038 for (; argnum
< nargs
; argnum
++)
2040 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2041 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
2045 next
= XFLOAT (val
)->data
;
2049 args
[argnum
] = val
; /* runs into a compiler bug. */
2050 next
= XINT (args
[argnum
]);
2052 switch (SWITCH_ENUM_CAST (code
))
2058 if (!argnum
&& nargs
!= 1)
2070 if (! IEEE_FLOATING_POINT
&& next
== 0)
2071 Fsignal (Qarith_error
, Qnil
);
2078 return wrong_type_argument (Qinteger_or_marker_p
, val
);
2080 if (!argnum
|| isnan (next
) || next
> accum
)
2084 if (!argnum
|| isnan (next
) || next
< accum
)
2090 return make_float (accum
);
2092 #endif /* LISP_FLOAT_TYPE */
2094 DEFUN ("+", Fplus
, Splus
, 0, MANY
, 0,
2095 "Return sum of any number of arguments, which are numbers or markers.")
2100 return arith_driver (Aadd
, nargs
, args
);
2103 DEFUN ("-", Fminus
, Sminus
, 0, MANY
, 0,
2104 "Negate number or subtract numbers or markers.\n\
2105 With one arg, negates it. With more than one arg,\n\
2106 subtracts all but the first from the first.")
2111 return arith_driver (Asub
, nargs
, args
);
2114 DEFUN ("*", Ftimes
, Stimes
, 0, MANY
, 0,
2115 "Returns product of any number of arguments, which are numbers or markers.")
2120 return arith_driver (Amult
, nargs
, args
);
2123 DEFUN ("/", Fquo
, Squo
, 2, MANY
, 0,
2124 "Returns first argument divided by all the remaining arguments.\n\
2125 The arguments must be numbers or markers.")
2130 return arith_driver (Adiv
, nargs
, args
);
2133 DEFUN ("%", Frem
, Srem
, 2, 2, 0,
2134 "Returns remainder of X divided by Y.\n\
2135 Both must be integers or markers.")
2137 register Lisp_Object x
, y
;
2141 CHECK_NUMBER_COERCE_MARKER (x
, 0);
2142 CHECK_NUMBER_COERCE_MARKER (y
, 1);
2144 if (XFASTINT (y
) == 0)
2145 Fsignal (Qarith_error
, Qnil
);
2147 XSETINT (val
, XINT (x
) % XINT (y
));
2161 /* If the magnitude of the result exceeds that of the divisor, or
2162 the sign of the result does not agree with that of the dividend,
2163 iterate with the reduced value. This does not yield a
2164 particularly accurate result, but at least it will be in the
2165 range promised by fmod. */
2167 r
-= f2
* floor (r
/ f2
);
2168 while (f2
<= (r
< 0 ? -r
: r
) || ((r
< 0) != (f1
< 0) && ! isnan (r
)));
2172 #endif /* ! HAVE_FMOD */
2174 DEFUN ("mod", Fmod
, Smod
, 2, 2, 0,
2175 "Returns X modulo Y.\n\
2176 The result falls between zero (inclusive) and Y (exclusive).\n\
2177 Both X and Y must be numbers or markers.")
2179 register Lisp_Object x
, y
;
2184 #ifdef LISP_FLOAT_TYPE
2185 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x
, 0);
2186 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y
, 1);
2188 if (FLOATP (x
) || FLOATP (y
))
2189 return fmod_float (x
, y
);
2191 #else /* not LISP_FLOAT_TYPE */
2192 CHECK_NUMBER_COERCE_MARKER (x
, 0);
2193 CHECK_NUMBER_COERCE_MARKER (y
, 1);
2194 #endif /* not LISP_FLOAT_TYPE */
2200 Fsignal (Qarith_error
, Qnil
);
2204 /* If the "remainder" comes out with the wrong sign, fix it. */
2205 if (i2
< 0 ? i1
> 0 : i1
< 0)
2212 DEFUN ("max", Fmax
, Smax
, 1, MANY
, 0,
2213 "Return largest of all the arguments (which must be numbers or markers).\n\
2214 The value is always a number; markers are converted to numbers.")
2219 return arith_driver (Amax
, nargs
, args
);
2222 DEFUN ("min", Fmin
, Smin
, 1, MANY
, 0,
2223 "Return smallest of all the arguments (which must be numbers or markers).\n\
2224 The value is always a number; markers are converted to numbers.")
2229 return arith_driver (Amin
, nargs
, args
);
2232 DEFUN ("logand", Flogand
, Slogand
, 0, MANY
, 0,
2233 "Return bitwise-and of all the arguments.\n\
2234 Arguments may be integers, or markers converted to integers.")
2239 return arith_driver (Alogand
, nargs
, args
);
2242 DEFUN ("logior", Flogior
, Slogior
, 0, MANY
, 0,
2243 "Return bitwise-or of all the arguments.\n\
2244 Arguments may be integers, or markers converted to integers.")
2249 return arith_driver (Alogior
, nargs
, args
);
2252 DEFUN ("logxor", Flogxor
, Slogxor
, 0, MANY
, 0,
2253 "Return bitwise-exclusive-or of all the arguments.\n\
2254 Arguments may be integers, or markers converted to integers.")
2259 return arith_driver (Alogxor
, nargs
, args
);
2262 DEFUN ("ash", Fash
, Sash
, 2, 2, 0,
2263 "Return VALUE with its bits shifted left by COUNT.\n\
2264 If COUNT is negative, shifting is actually to the right.\n\
2265 In this case, the sign bit is duplicated.")
2267 register Lisp_Object value
, count
;
2269 register Lisp_Object val
;
2271 CHECK_NUMBER (value
, 0);
2272 CHECK_NUMBER (count
, 1);
2274 if (XINT (count
) > 0)
2275 XSETINT (val
, XINT (value
) << XFASTINT (count
));
2277 XSETINT (val
, XINT (value
) >> -XINT (count
));
2281 DEFUN ("lsh", Flsh
, Slsh
, 2, 2, 0,
2282 "Return VALUE with its bits shifted left by COUNT.\n\
2283 If COUNT is negative, shifting is actually to the right.\n\
2284 In this case, zeros are shifted in on the left.")
2286 register Lisp_Object value
, count
;
2288 register Lisp_Object val
;
2290 CHECK_NUMBER (value
, 0);
2291 CHECK_NUMBER (count
, 1);
2293 if (XINT (count
) > 0)
2294 XSETINT (val
, (EMACS_UINT
) XUINT (value
) << XFASTINT (count
));
2296 XSETINT (val
, (EMACS_UINT
) XUINT (value
) >> -XINT (count
));
2300 DEFUN ("1+", Fadd1
, Sadd1
, 1, 1, 0,
2301 "Return NUMBER plus one. NUMBER may be a number or a marker.\n\
2302 Markers are converted to integers.")
2304 register Lisp_Object number
;
2306 #ifdef LISP_FLOAT_TYPE
2307 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
, 0);
2309 if (FLOATP (number
))
2310 return (make_float (1.0 + XFLOAT (number
)->data
));
2312 CHECK_NUMBER_COERCE_MARKER (number
, 0);
2313 #endif /* LISP_FLOAT_TYPE */
2315 XSETINT (number
, XINT (number
) + 1);
2319 DEFUN ("1-", Fsub1
, Ssub1
, 1, 1, 0,
2320 "Return NUMBER minus one. NUMBER may be a number or a marker.\n\
2321 Markers are converted to integers.")
2323 register Lisp_Object number
;
2325 #ifdef LISP_FLOAT_TYPE
2326 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
, 0);
2328 if (FLOATP (number
))
2329 return (make_float (-1.0 + XFLOAT (number
)->data
));
2331 CHECK_NUMBER_COERCE_MARKER (number
, 0);
2332 #endif /* LISP_FLOAT_TYPE */
2334 XSETINT (number
, XINT (number
) - 1);
2338 DEFUN ("lognot", Flognot
, Slognot
, 1, 1, 0,
2339 "Return the bitwise complement of NUMBER. NUMBER must be an integer.")
2341 register Lisp_Object number
;
2343 CHECK_NUMBER (number
, 0);
2344 XSETINT (number
, ~XINT (number
));
2351 Lisp_Object error_tail
, arith_tail
;
2353 Qquote
= intern ("quote");
2354 Qlambda
= intern ("lambda");
2355 Qsubr
= intern ("subr");
2356 Qerror_conditions
= intern ("error-conditions");
2357 Qerror_message
= intern ("error-message");
2358 Qtop_level
= intern ("top-level");
2360 Qerror
= intern ("error");
2361 Qquit
= intern ("quit");
2362 Qwrong_type_argument
= intern ("wrong-type-argument");
2363 Qargs_out_of_range
= intern ("args-out-of-range");
2364 Qvoid_function
= intern ("void-function");
2365 Qcyclic_function_indirection
= intern ("cyclic-function-indirection");
2366 Qvoid_variable
= intern ("void-variable");
2367 Qsetting_constant
= intern ("setting-constant");
2368 Qinvalid_read_syntax
= intern ("invalid-read-syntax");
2370 Qinvalid_function
= intern ("invalid-function");
2371 Qwrong_number_of_arguments
= intern ("wrong-number-of-arguments");
2372 Qno_catch
= intern ("no-catch");
2373 Qend_of_file
= intern ("end-of-file");
2374 Qarith_error
= intern ("arith-error");
2375 Qbeginning_of_buffer
= intern ("beginning-of-buffer");
2376 Qend_of_buffer
= intern ("end-of-buffer");
2377 Qbuffer_read_only
= intern ("buffer-read-only");
2378 Qmark_inactive
= intern ("mark-inactive");
2380 Qlistp
= intern ("listp");
2381 Qconsp
= intern ("consp");
2382 Qsymbolp
= intern ("symbolp");
2383 Qintegerp
= intern ("integerp");
2384 Qnatnump
= intern ("natnump");
2385 Qwholenump
= intern ("wholenump");
2386 Qstringp
= intern ("stringp");
2387 Qarrayp
= intern ("arrayp");
2388 Qsequencep
= intern ("sequencep");
2389 Qbufferp
= intern ("bufferp");
2390 Qvectorp
= intern ("vectorp");
2391 Qchar_or_string_p
= intern ("char-or-string-p");
2392 Qmarkerp
= intern ("markerp");
2393 Qbuffer_or_string_p
= intern ("buffer-or-string-p");
2394 Qinteger_or_marker_p
= intern ("integer-or-marker-p");
2395 Qboundp
= intern ("boundp");
2396 Qfboundp
= intern ("fboundp");
2398 #ifdef LISP_FLOAT_TYPE
2399 Qfloatp
= intern ("floatp");
2400 Qnumberp
= intern ("numberp");
2401 Qnumber_or_marker_p
= intern ("number-or-marker-p");
2402 #endif /* LISP_FLOAT_TYPE */
2404 Qchar_table_p
= intern ("char-table-p");
2405 Qvector_or_char_table_p
= intern ("vector-or-char-table-p");
2407 Qcdr
= intern ("cdr");
2409 /* Handle automatic advice activation */
2410 Qad_advice_info
= intern ("ad-advice-info");
2411 Qad_activate
= intern ("ad-activate");
2413 error_tail
= Fcons (Qerror
, Qnil
);
2415 /* ERROR is used as a signaler for random errors for which nothing else is right */
2417 Fput (Qerror
, Qerror_conditions
,
2419 Fput (Qerror
, Qerror_message
,
2420 build_string ("error"));
2422 Fput (Qquit
, Qerror_conditions
,
2423 Fcons (Qquit
, Qnil
));
2424 Fput (Qquit
, Qerror_message
,
2425 build_string ("Quit"));
2427 Fput (Qwrong_type_argument
, Qerror_conditions
,
2428 Fcons (Qwrong_type_argument
, error_tail
));
2429 Fput (Qwrong_type_argument
, Qerror_message
,
2430 build_string ("Wrong type argument"));
2432 Fput (Qargs_out_of_range
, Qerror_conditions
,
2433 Fcons (Qargs_out_of_range
, error_tail
));
2434 Fput (Qargs_out_of_range
, Qerror_message
,
2435 build_string ("Args out of range"));
2437 Fput (Qvoid_function
, Qerror_conditions
,
2438 Fcons (Qvoid_function
, error_tail
));
2439 Fput (Qvoid_function
, Qerror_message
,
2440 build_string ("Symbol's function definition is void"));
2442 Fput (Qcyclic_function_indirection
, Qerror_conditions
,
2443 Fcons (Qcyclic_function_indirection
, error_tail
));
2444 Fput (Qcyclic_function_indirection
, Qerror_message
,
2445 build_string ("Symbol's chain of function indirections contains a loop"));
2447 Fput (Qvoid_variable
, Qerror_conditions
,
2448 Fcons (Qvoid_variable
, error_tail
));
2449 Fput (Qvoid_variable
, Qerror_message
,
2450 build_string ("Symbol's value as variable is void"));
2452 Fput (Qsetting_constant
, Qerror_conditions
,
2453 Fcons (Qsetting_constant
, error_tail
));
2454 Fput (Qsetting_constant
, Qerror_message
,
2455 build_string ("Attempt to set a constant symbol"));
2457 Fput (Qinvalid_read_syntax
, Qerror_conditions
,
2458 Fcons (Qinvalid_read_syntax
, error_tail
));
2459 Fput (Qinvalid_read_syntax
, Qerror_message
,
2460 build_string ("Invalid read syntax"));
2462 Fput (Qinvalid_function
, Qerror_conditions
,
2463 Fcons (Qinvalid_function
, error_tail
));
2464 Fput (Qinvalid_function
, Qerror_message
,
2465 build_string ("Invalid function"));
2467 Fput (Qwrong_number_of_arguments
, Qerror_conditions
,
2468 Fcons (Qwrong_number_of_arguments
, error_tail
));
2469 Fput (Qwrong_number_of_arguments
, Qerror_message
,
2470 build_string ("Wrong number of arguments"));
2472 Fput (Qno_catch
, Qerror_conditions
,
2473 Fcons (Qno_catch
, error_tail
));
2474 Fput (Qno_catch
, Qerror_message
,
2475 build_string ("No catch for tag"));
2477 Fput (Qend_of_file
, Qerror_conditions
,
2478 Fcons (Qend_of_file
, error_tail
));
2479 Fput (Qend_of_file
, Qerror_message
,
2480 build_string ("End of file during parsing"));
2482 arith_tail
= Fcons (Qarith_error
, error_tail
);
2483 Fput (Qarith_error
, Qerror_conditions
,
2485 Fput (Qarith_error
, Qerror_message
,
2486 build_string ("Arithmetic error"));
2488 Fput (Qbeginning_of_buffer
, Qerror_conditions
,
2489 Fcons (Qbeginning_of_buffer
, error_tail
));
2490 Fput (Qbeginning_of_buffer
, Qerror_message
,
2491 build_string ("Beginning of buffer"));
2493 Fput (Qend_of_buffer
, Qerror_conditions
,
2494 Fcons (Qend_of_buffer
, error_tail
));
2495 Fput (Qend_of_buffer
, Qerror_message
,
2496 build_string ("End of buffer"));
2498 Fput (Qbuffer_read_only
, Qerror_conditions
,
2499 Fcons (Qbuffer_read_only
, error_tail
));
2500 Fput (Qbuffer_read_only
, Qerror_message
,
2501 build_string ("Buffer is read-only"));
2503 #ifdef LISP_FLOAT_TYPE
2504 Qrange_error
= intern ("range-error");
2505 Qdomain_error
= intern ("domain-error");
2506 Qsingularity_error
= intern ("singularity-error");
2507 Qoverflow_error
= intern ("overflow-error");
2508 Qunderflow_error
= intern ("underflow-error");
2510 Fput (Qdomain_error
, Qerror_conditions
,
2511 Fcons (Qdomain_error
, arith_tail
));
2512 Fput (Qdomain_error
, Qerror_message
,
2513 build_string ("Arithmetic domain error"));
2515 Fput (Qrange_error
, Qerror_conditions
,
2516 Fcons (Qrange_error
, arith_tail
));
2517 Fput (Qrange_error
, Qerror_message
,
2518 build_string ("Arithmetic range error"));
2520 Fput (Qsingularity_error
, Qerror_conditions
,
2521 Fcons (Qsingularity_error
, Fcons (Qdomain_error
, arith_tail
)));
2522 Fput (Qsingularity_error
, Qerror_message
,
2523 build_string ("Arithmetic singularity error"));
2525 Fput (Qoverflow_error
, Qerror_conditions
,
2526 Fcons (Qoverflow_error
, Fcons (Qdomain_error
, arith_tail
)));
2527 Fput (Qoverflow_error
, Qerror_message
,
2528 build_string ("Arithmetic overflow error"));
2530 Fput (Qunderflow_error
, Qerror_conditions
,
2531 Fcons (Qunderflow_error
, Fcons (Qdomain_error
, arith_tail
)));
2532 Fput (Qunderflow_error
, Qerror_message
,
2533 build_string ("Arithmetic underflow error"));
2535 staticpro (&Qrange_error
);
2536 staticpro (&Qdomain_error
);
2537 staticpro (&Qsingularity_error
);
2538 staticpro (&Qoverflow_error
);
2539 staticpro (&Qunderflow_error
);
2540 #endif /* LISP_FLOAT_TYPE */
2544 staticpro (&Qquote
);
2545 staticpro (&Qlambda
);
2547 staticpro (&Qunbound
);
2548 staticpro (&Qerror_conditions
);
2549 staticpro (&Qerror_message
);
2550 staticpro (&Qtop_level
);
2552 staticpro (&Qerror
);
2554 staticpro (&Qwrong_type_argument
);
2555 staticpro (&Qargs_out_of_range
);
2556 staticpro (&Qvoid_function
);
2557 staticpro (&Qcyclic_function_indirection
);
2558 staticpro (&Qvoid_variable
);
2559 staticpro (&Qsetting_constant
);
2560 staticpro (&Qinvalid_read_syntax
);
2561 staticpro (&Qwrong_number_of_arguments
);
2562 staticpro (&Qinvalid_function
);
2563 staticpro (&Qno_catch
);
2564 staticpro (&Qend_of_file
);
2565 staticpro (&Qarith_error
);
2566 staticpro (&Qbeginning_of_buffer
);
2567 staticpro (&Qend_of_buffer
);
2568 staticpro (&Qbuffer_read_only
);
2569 staticpro (&Qmark_inactive
);
2571 staticpro (&Qlistp
);
2572 staticpro (&Qconsp
);
2573 staticpro (&Qsymbolp
);
2574 staticpro (&Qintegerp
);
2575 staticpro (&Qnatnump
);
2576 staticpro (&Qwholenump
);
2577 staticpro (&Qstringp
);
2578 staticpro (&Qarrayp
);
2579 staticpro (&Qsequencep
);
2580 staticpro (&Qbufferp
);
2581 staticpro (&Qvectorp
);
2582 staticpro (&Qchar_or_string_p
);
2583 staticpro (&Qmarkerp
);
2584 staticpro (&Qbuffer_or_string_p
);
2585 staticpro (&Qinteger_or_marker_p
);
2586 #ifdef LISP_FLOAT_TYPE
2587 staticpro (&Qfloatp
);
2588 staticpro (&Qnumberp
);
2589 staticpro (&Qnumber_or_marker_p
);
2590 #endif /* LISP_FLOAT_TYPE */
2591 staticpro (&Qchar_table_p
);
2592 staticpro (&Qvector_or_char_table_p
);
2594 staticpro (&Qboundp
);
2595 staticpro (&Qfboundp
);
2597 staticpro (&Qad_advice_info
);
2598 staticpro (&Qad_activate
);
2600 /* Types that type-of returns. */
2601 Qinteger
= intern ("integer");
2602 Qsymbol
= intern ("symbol");
2603 Qstring
= intern ("string");
2604 Qcons
= intern ("cons");
2605 Qmarker
= intern ("marker");
2606 Qoverlay
= intern ("overlay");
2607 Qfloat
= intern ("float");
2608 Qwindow_configuration
= intern ("window-configuration");
2609 Qprocess
= intern ("process");
2610 Qwindow
= intern ("window");
2611 /* Qsubr = intern ("subr"); */
2612 Qcompiled_function
= intern ("compiled-function");
2613 Qbuffer
= intern ("buffer");
2614 Qframe
= intern ("frame");
2615 Qvector
= intern ("vector");
2616 Qchar_table
= intern ("char-table");
2617 Qbool_vector
= intern ("bool-vector");
2619 staticpro (&Qinteger
);
2620 staticpro (&Qsymbol
);
2621 staticpro (&Qstring
);
2623 staticpro (&Qmarker
);
2624 staticpro (&Qoverlay
);
2625 staticpro (&Qfloat
);
2626 staticpro (&Qwindow_configuration
);
2627 staticpro (&Qprocess
);
2628 staticpro (&Qwindow
);
2629 /* staticpro (&Qsubr); */
2630 staticpro (&Qcompiled_function
);
2631 staticpro (&Qbuffer
);
2632 staticpro (&Qframe
);
2633 staticpro (&Qvector
);
2634 staticpro (&Qchar_table
);
2635 staticpro (&Qbool_vector
);
2639 defsubr (&Stype_of
);
2644 defsubr (&Sintegerp
);
2645 defsubr (&Sinteger_or_marker_p
);
2646 defsubr (&Snumberp
);
2647 defsubr (&Snumber_or_marker_p
);
2648 #ifdef LISP_FLOAT_TYPE
2650 #endif /* LISP_FLOAT_TYPE */
2651 defsubr (&Snatnump
);
2652 defsubr (&Ssymbolp
);
2653 defsubr (&Sstringp
);
2654 defsubr (&Svectorp
);
2655 defsubr (&Schar_table_p
);
2656 defsubr (&Svector_or_char_table_p
);
2657 defsubr (&Sbool_vector_p
);
2659 defsubr (&Ssequencep
);
2660 defsubr (&Sbufferp
);
2661 defsubr (&Smarkerp
);
2663 defsubr (&Sbyte_code_function_p
);
2664 defsubr (&Schar_or_string_p
);
2667 defsubr (&Scar_safe
);
2668 defsubr (&Scdr_safe
);
2671 defsubr (&Ssymbol_function
);
2672 defsubr (&Sindirect_function
);
2673 defsubr (&Ssymbol_plist
);
2674 defsubr (&Ssymbol_name
);
2675 defsubr (&Smakunbound
);
2676 defsubr (&Sfmakunbound
);
2678 defsubr (&Sfboundp
);
2680 defsubr (&Sdefalias
);
2681 defsubr (&Ssetplist
);
2682 defsubr (&Ssymbol_value
);
2684 defsubr (&Sdefault_boundp
);
2685 defsubr (&Sdefault_value
);
2686 defsubr (&Sset_default
);
2687 defsubr (&Ssetq_default
);
2688 defsubr (&Smake_variable_buffer_local
);
2689 defsubr (&Smake_local_variable
);
2690 defsubr (&Skill_local_variable
);
2691 defsubr (&Slocal_variable_p
);
2692 defsubr (&Slocal_variable_if_set_p
);
2695 defsubr (&Snumber_to_string
);
2696 defsubr (&Sstring_to_number
);
2697 defsubr (&Seqlsign
);
2721 XSYMBOL (Qwholenump
)->function
= XSYMBOL (Qnatnump
)->function
;
2728 #if defined(USG) && !defined(POSIX_SIGNALS)
2729 /* USG systems forget handlers when they are used;
2730 must reestablish each time */
2731 signal (signo
, arith_error
);
2734 /* VMS systems are like USG. */
2735 signal (signo
, arith_error
);
2739 #else /* not BSD4_1 */
2740 sigsetmask (SIGEMPTYMASK
);
2741 #endif /* not BSD4_1 */
2743 Fsignal (Qarith_error
, Qnil
);
2748 /* Don't do this if just dumping out.
2749 We don't want to call `signal' in this case
2750 so that we don't have trouble with dumping
2751 signal-delivering routines in an inconsistent state. */
2755 #endif /* CANNOT_DUMP */
2756 signal (SIGFPE
, arith_error
);
2759 signal (SIGEMT
, arith_error
);