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
))
228 if (GC_FRAMEP (object
))
232 #ifdef LISP_FLOAT_TYPE
242 DEFUN ("consp", Fconsp
, Sconsp
, 1, 1, 0, "T if OBJECT is a cons cell.")
251 DEFUN ("atom", Fatom
, Satom
, 1, 1, 0, "T if OBJECT is not a cons cell. This includes nil.")
260 DEFUN ("listp", Flistp
, Slistp
, 1, 1, 0, "T if OBJECT is a list. This includes nil.")
264 if (CONSP (object
) || NILP (object
))
269 DEFUN ("nlistp", Fnlistp
, Snlistp
, 1, 1, 0, "T if OBJECT is not a list. Lists include nil.")
273 if (CONSP (object
) || NILP (object
))
278 DEFUN ("symbolp", Fsymbolp
, Ssymbolp
, 1, 1, 0, "T if OBJECT is a symbol.")
282 if (SYMBOLP (object
))
287 DEFUN ("vectorp", Fvectorp
, Svectorp
, 1, 1, 0, "T if OBJECT is a vector.")
291 if (VECTORP (object
))
296 DEFUN ("stringp", Fstringp
, Sstringp
, 1, 1, 0, "T if OBJECT is a string.")
300 if (STRINGP (object
))
305 DEFUN ("char-table-p", Fchar_table_p
, Schar_table_p
, 1, 1, 0, "T if OBJECT is a char-table.")
309 if (CHAR_TABLE_P (object
))
314 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p
,
315 Svector_or_char_table_p
, 1, 1, 0,
316 "T if OBJECT is a char-table or vector.")
320 if (VECTORP (object
) || CHAR_TABLE_P (object
))
325 DEFUN ("bool-vector-p", Fbool_vector_p
, Sbool_vector_p
, 1, 1, 0, "T if OBJECT is a bool-vector.")
329 if (BOOL_VECTOR_P (object
))
334 DEFUN ("arrayp", Farrayp
, Sarrayp
, 1, 1, 0, "T if OBJECT is an array (string or vector).")
338 if (VECTORP (object
) || STRINGP (object
))
343 DEFUN ("sequencep", Fsequencep
, Ssequencep
, 1, 1, 0,
344 "T if OBJECT is a sequence (list or array).")
346 register Lisp_Object object
;
348 if (CONSP (object
) || NILP (object
) || VECTORP (object
) || STRINGP (object
)
349 || CHAR_TABLE_P (object
) || BOOL_VECTOR_P (object
))
354 DEFUN ("bufferp", Fbufferp
, Sbufferp
, 1, 1, 0, "T if OBJECT is an editor buffer.")
358 if (BUFFERP (object
))
363 DEFUN ("markerp", Fmarkerp
, Smarkerp
, 1, 1, 0, "T if OBJECT is a marker (editor pointer).")
367 if (MARKERP (object
))
372 DEFUN ("subrp", Fsubrp
, Ssubrp
, 1, 1, 0, "T if OBJECT is a built-in function.")
381 DEFUN ("byte-code-function-p", Fbyte_code_function_p
, Sbyte_code_function_p
,
382 1, 1, 0, "T if OBJECT is a byte-compiled function object.")
386 if (COMPILEDP (object
))
391 DEFUN ("char-or-string-p", Fchar_or_string_p
, Schar_or_string_p
, 1, 1, 0,
392 "T if OBJECT is a character (an integer) or a string.")
394 register Lisp_Object object
;
396 if (INTEGERP (object
) || STRINGP (object
))
401 DEFUN ("integerp", Fintegerp
, Sintegerp
, 1, 1, 0, "T if OBJECT is an integer.")
405 if (INTEGERP (object
))
410 DEFUN ("integer-or-marker-p", Finteger_or_marker_p
, Sinteger_or_marker_p
, 1, 1, 0,
411 "T if OBJECT is an integer or a marker (editor pointer).")
413 register Lisp_Object object
;
415 if (MARKERP (object
) || INTEGERP (object
))
420 DEFUN ("natnump", Fnatnump
, Snatnump
, 1, 1, 0,
421 "T if OBJECT is a nonnegative integer.")
425 if (NATNUMP (object
))
430 DEFUN ("numberp", Fnumberp
, Snumberp
, 1, 1, 0,
431 "T if OBJECT is a number (floating point or integer).")
435 if (NUMBERP (object
))
441 DEFUN ("number-or-marker-p", Fnumber_or_marker_p
,
442 Snumber_or_marker_p
, 1, 1, 0,
443 "T if OBJECT is a number or a marker.")
447 if (NUMBERP (object
) || MARKERP (object
))
452 #ifdef LISP_FLOAT_TYPE
453 DEFUN ("floatp", Ffloatp
, Sfloatp
, 1, 1, 0,
454 "T if OBJECT is a floating point number.")
462 #endif /* LISP_FLOAT_TYPE */
464 /* Extract and set components of lists */
466 DEFUN ("car", Fcar
, Scar
, 1, 1, 0,
467 "Return the car of LIST. If arg is nil, return nil.\n\
468 Error if arg is not nil and not a cons cell. See also `car-safe'.")
470 register Lisp_Object list
;
475 return XCONS (list
)->car
;
476 else if (EQ (list
, Qnil
))
479 list
= wrong_type_argument (Qlistp
, list
);
483 DEFUN ("car-safe", Fcar_safe
, Scar_safe
, 1, 1, 0,
484 "Return the car of OBJECT if it is a cons cell, or else nil.")
489 return XCONS (object
)->car
;
494 DEFUN ("cdr", Fcdr
, Scdr
, 1, 1, 0,
495 "Return the cdr of LIST. If arg is nil, return nil.\n\
496 Error if arg is not nil and not a cons cell. See also `cdr-safe'.")
499 register Lisp_Object list
;
504 return XCONS (list
)->cdr
;
505 else if (EQ (list
, Qnil
))
508 list
= wrong_type_argument (Qlistp
, list
);
512 DEFUN ("cdr-safe", Fcdr_safe
, Scdr_safe
, 1, 1, 0,
513 "Return the cdr of OBJECT if it is a cons cell, or else nil.")
518 return XCONS (object
)->cdr
;
523 DEFUN ("setcar", Fsetcar
, Ssetcar
, 2, 2, 0,
524 "Set the car of CELL to be NEWCAR. Returns NEWCAR.")
526 register Lisp_Object cell
, newcar
;
529 cell
= wrong_type_argument (Qconsp
, cell
);
532 XCONS (cell
)->car
= newcar
;
536 DEFUN ("setcdr", Fsetcdr
, Ssetcdr
, 2, 2, 0,
537 "Set the cdr of CELL to be NEWCDR. Returns NEWCDR.")
539 register Lisp_Object cell
, newcdr
;
542 cell
= wrong_type_argument (Qconsp
, cell
);
545 XCONS (cell
)->cdr
= newcdr
;
549 /* Extract and set components of symbols */
551 DEFUN ("boundp", Fboundp
, Sboundp
, 1, 1, 0, "T if SYMBOL's value is not void.")
553 register Lisp_Object symbol
;
555 Lisp_Object valcontents
;
556 CHECK_SYMBOL (symbol
, 0);
558 valcontents
= XSYMBOL (symbol
)->value
;
560 if (BUFFER_LOCAL_VALUEP (valcontents
)
561 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
562 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
564 return (EQ (valcontents
, Qunbound
) ? Qnil
: Qt
);
567 DEFUN ("fboundp", Ffboundp
, Sfboundp
, 1, 1, 0, "T if SYMBOL's function definition is not void.")
569 register Lisp_Object symbol
;
571 CHECK_SYMBOL (symbol
, 0);
572 return (EQ (XSYMBOL (symbol
)->function
, Qunbound
) ? Qnil
: Qt
);
575 DEFUN ("makunbound", Fmakunbound
, Smakunbound
, 1, 1, 0, "Make SYMBOL's value be void.")
577 register Lisp_Object symbol
;
579 CHECK_SYMBOL (symbol
, 0);
580 if (NILP (symbol
) || EQ (symbol
, Qt
))
581 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
582 Fset (symbol
, Qunbound
);
586 DEFUN ("fmakunbound", Ffmakunbound
, Sfmakunbound
, 1, 1, 0, "Make SYMBOL's function definition be void.")
588 register Lisp_Object symbol
;
590 CHECK_SYMBOL (symbol
, 0);
591 if (NILP (symbol
) || EQ (symbol
, Qt
))
592 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
593 XSYMBOL (symbol
)->function
= Qunbound
;
597 DEFUN ("symbol-function", Fsymbol_function
, Ssymbol_function
, 1, 1, 0,
598 "Return SYMBOL's function definition. Error if that is void.")
600 register Lisp_Object symbol
;
602 CHECK_SYMBOL (symbol
, 0);
603 if (EQ (XSYMBOL (symbol
)->function
, Qunbound
))
604 return Fsignal (Qvoid_function
, Fcons (symbol
, Qnil
));
605 return XSYMBOL (symbol
)->function
;
608 DEFUN ("symbol-plist", Fsymbol_plist
, Ssymbol_plist
, 1, 1, 0, "Return SYMBOL's property list.")
610 register Lisp_Object symbol
;
612 CHECK_SYMBOL (symbol
, 0);
613 return XSYMBOL (symbol
)->plist
;
616 DEFUN ("symbol-name", Fsymbol_name
, Ssymbol_name
, 1, 1, 0, "Return SYMBOL's name, a string.")
618 register Lisp_Object symbol
;
620 register Lisp_Object name
;
622 CHECK_SYMBOL (symbol
, 0);
623 XSETSTRING (name
, XSYMBOL (symbol
)->name
);
627 DEFUN ("fset", Ffset
, Sfset
, 2, 2, 0,
628 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.")
630 register Lisp_Object symbol
, newdef
;
632 CHECK_SYMBOL (symbol
, 0);
633 if (NILP (symbol
) || EQ (symbol
, Qt
))
634 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
635 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
636 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
638 XSYMBOL (symbol
)->function
= newdef
;
639 /* Handle automatic advice activation */
640 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
642 call2 (Qad_activate
, symbol
, Qnil
);
643 newdef
= XSYMBOL (symbol
)->function
;
648 /* This name should be removed once it is eliminated from elsewhere. */
650 DEFUN ("defalias", Fdefalias
, Sdefalias
, 2, 2, 0,
651 "Set SYMBOL's function definition to NEWDEF, and return NEWDEF.\n\
652 Associates the function with the current load file, if any.")
654 register Lisp_Object symbol
, newdef
;
656 CHECK_SYMBOL (symbol
, 0);
657 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
658 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
660 XSYMBOL (symbol
)->function
= newdef
;
661 /* Handle automatic advice activation */
662 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
664 call2 (Qad_activate
, symbol
, Qnil
);
665 newdef
= XSYMBOL (symbol
)->function
;
667 LOADHIST_ATTACH (symbol
);
671 DEFUN ("define-function", Fdefine_function
, Sdefine_function
, 2, 2, 0,
672 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\
673 Associates the function with the current load file, if any.")
675 register Lisp_Object symbol
, newdef
;
677 CHECK_SYMBOL (symbol
, 0);
678 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
679 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
681 XSYMBOL (symbol
)->function
= newdef
;
682 /* Handle automatic advice activation */
683 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
685 call2 (Qad_activate
, symbol
, Qnil
);
686 newdef
= XSYMBOL (symbol
)->function
;
688 LOADHIST_ATTACH (symbol
);
692 DEFUN ("setplist", Fsetplist
, Ssetplist
, 2, 2, 0,
693 "Set SYMBOL's property list to NEWVAL, and return NEWVAL.")
695 register Lisp_Object symbol
, newplist
;
697 CHECK_SYMBOL (symbol
, 0);
698 XSYMBOL (symbol
)->plist
= newplist
;
703 /* Getting and setting values of symbols */
705 /* Given the raw contents of a symbol value cell,
706 return the Lisp value of the symbol.
707 This does not handle buffer-local variables; use
708 swap_in_symval_forwarding for that. */
711 do_symval_forwarding (valcontents
)
712 register Lisp_Object valcontents
;
714 register Lisp_Object val
;
716 if (MISCP (valcontents
))
717 switch (XMISCTYPE (valcontents
))
719 case Lisp_Misc_Intfwd
:
720 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
723 case Lisp_Misc_Boolfwd
:
724 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
726 case Lisp_Misc_Objfwd
:
727 return *XOBJFWD (valcontents
)->objvar
;
729 case Lisp_Misc_Buffer_Objfwd
:
730 offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
731 return *(Lisp_Object
*)(offset
+ (char *)current_buffer
);
733 case Lisp_Misc_Kboard_Objfwd
:
734 offset
= XKBOARD_OBJFWD (valcontents
)->offset
;
735 return *(Lisp_Object
*)(offset
+ (char *)current_kboard
);
740 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
741 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
742 buffer-independent contents of the value cell: forwarded just one
743 step past the buffer-localness. */
746 store_symval_forwarding (symbol
, valcontents
, newval
)
748 register Lisp_Object valcontents
, newval
;
750 switch (SWITCH_ENUM_CAST (XTYPE (valcontents
)))
753 switch (XMISCTYPE (valcontents
))
755 case Lisp_Misc_Intfwd
:
756 CHECK_NUMBER (newval
, 1);
757 *XINTFWD (valcontents
)->intvar
= XINT (newval
);
758 if (*XINTFWD (valcontents
)->intvar
!= XINT (newval
))
759 error ("Value out of range for variable `%s'",
760 XSYMBOL (symbol
)->name
->data
);
763 case Lisp_Misc_Boolfwd
:
764 *XBOOLFWD (valcontents
)->boolvar
= NILP (newval
) ? 0 : 1;
767 case Lisp_Misc_Objfwd
:
768 *XOBJFWD (valcontents
)->objvar
= newval
;
771 case Lisp_Misc_Buffer_Objfwd
:
773 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
776 type
= *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
);
777 if (! NILP (type
) && ! NILP (newval
)
778 && XTYPE (newval
) != XINT (type
))
779 buffer_slot_type_mismatch (offset
);
781 *(Lisp_Object
*)(offset
+ (char *)current_buffer
) = newval
;
785 case Lisp_Misc_Kboard_Objfwd
:
786 (*(Lisp_Object
*)((char *)current_kboard
787 + XKBOARD_OBJFWD (valcontents
)->offset
))
798 valcontents
= XSYMBOL (symbol
)->value
;
799 if (BUFFER_LOCAL_VALUEP (valcontents
)
800 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
801 XBUFFER_LOCAL_VALUE (valcontents
)->car
= newval
;
803 XSYMBOL (symbol
)->value
= newval
;
807 /* Set up the buffer-local symbol SYMBOL for validity in the current
808 buffer. VALCONTENTS is the contents of its value cell.
809 Return the value forwarded one step past the buffer-local indicator. */
812 swap_in_symval_forwarding (symbol
, valcontents
)
813 Lisp_Object symbol
, valcontents
;
815 /* valcontents is a pointer to a struct resembling the cons
816 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
818 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
819 local_var_alist, that being the element whose car is this
820 variable. Or it can be a pointer to the
821 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not have
822 an element in its alist for this variable.
824 If the current buffer is not BUFFER, we store the current
825 REALVALUE value into CURRENT-ALIST-ELEMENT, then find the
826 appropriate alist element for the buffer now current and set up
827 CURRENT-ALIST-ELEMENT. Then we set REALVALUE out of that
828 element, and store into BUFFER.
830 Note that REALVALUE can be a forwarding pointer. */
832 register Lisp_Object tem1
;
833 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
835 if (NILP (tem1
) || current_buffer
!= XBUFFER (tem1
))
837 tem1
= XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
839 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->car
));
840 tem1
= assq_no_quit (symbol
, current_buffer
->local_var_alist
);
842 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
;
843 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
= tem1
;
844 XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
,
846 store_symval_forwarding (symbol
, XBUFFER_LOCAL_VALUE (valcontents
)->car
,
849 return XBUFFER_LOCAL_VALUE (valcontents
)->car
;
852 /* Find the value of a symbol, returning Qunbound if it's not bound.
853 This is helpful for code which just wants to get a variable's value
854 if it has one, without signaling an error.
855 Note that it must not be possible to quit
856 within this function. Great care is required for this. */
859 find_symbol_value (symbol
)
862 register Lisp_Object valcontents
, tem1
;
863 register Lisp_Object val
;
864 CHECK_SYMBOL (symbol
, 0);
865 valcontents
= XSYMBOL (symbol
)->value
;
867 if (BUFFER_LOCAL_VALUEP (valcontents
)
868 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
869 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
871 if (MISCP (valcontents
))
873 switch (XMISCTYPE (valcontents
))
875 case Lisp_Misc_Intfwd
:
876 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
879 case Lisp_Misc_Boolfwd
:
880 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
882 case Lisp_Misc_Objfwd
:
883 return *XOBJFWD (valcontents
)->objvar
;
885 case Lisp_Misc_Buffer_Objfwd
:
886 return *(Lisp_Object
*)(XBUFFER_OBJFWD (valcontents
)->offset
887 + (char *)current_buffer
);
889 case Lisp_Misc_Kboard_Objfwd
:
890 return *(Lisp_Object
*)(XKBOARD_OBJFWD (valcontents
)->offset
891 + (char *)current_kboard
);
898 DEFUN ("symbol-value", Fsymbol_value
, Ssymbol_value
, 1, 1, 0,
899 "Return SYMBOL's value. Error if that is void.")
905 val
= find_symbol_value (symbol
);
906 if (EQ (val
, Qunbound
))
907 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
912 DEFUN ("set", Fset
, Sset
, 2, 2, 0,
913 "Set SYMBOL's value to NEWVAL, and return NEWVAL.")
915 register Lisp_Object symbol
, newval
;
917 int voide
= EQ (newval
, Qunbound
);
919 register Lisp_Object valcontents
, tem1
, current_alist_element
;
921 CHECK_SYMBOL (symbol
, 0);
922 if (NILP (symbol
) || EQ (symbol
, Qt
))
923 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
924 valcontents
= XSYMBOL (symbol
)->value
;
926 if (BUFFER_OBJFWDP (valcontents
))
928 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
929 register int mask
= XINT (*((Lisp_Object
*)
930 (idx
+ (char *)&buffer_local_flags
)));
932 current_buffer
->local_var_flags
|= mask
;
935 else if (BUFFER_LOCAL_VALUEP (valcontents
)
936 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
938 /* valcontents is actually a pointer to a struct resembling a cons,
939 with contents something like:
940 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE).
942 BUFFER is the last buffer for which this symbol's value was
945 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
946 local_var_alist, that being the element whose car is this
947 variable. Or it can be a pointer to the
948 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not
949 have an element in its alist for this variable (that is, if
950 BUFFER sees the default value of this variable).
952 If we want to examine or set the value and BUFFER is current,
953 we just examine or set REALVALUE. If BUFFER is not current, we
954 store the current REALVALUE value into CURRENT-ALIST-ELEMENT,
955 then find the appropriate alist element for the buffer now
956 current and set up CURRENT-ALIST-ELEMENT. Then we set
957 REALVALUE out of that element, and store into BUFFER.
959 If we are setting the variable and the current buffer does
960 not have an alist entry for this variable, an alist entry is
963 Note that REALVALUE can be a forwarding pointer. Each time
964 it is examined or set, forwarding must be done. */
966 /* What value are we caching right now? */
967 current_alist_element
=
968 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
970 /* If the current buffer is not the buffer whose binding is
971 currently cached, or if it's a Lisp_Buffer_Local_Value and
972 we're looking at the default value, the cache is invalid; we
973 need to write it out, and find the new CURRENT-ALIST-ELEMENT. */
975 != XBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
))
976 || (BUFFER_LOCAL_VALUEP (valcontents
)
977 && EQ (XCONS (current_alist_element
)->car
,
978 current_alist_element
)))
980 /* Write out the cached value for the old buffer; copy it
981 back to its alist element. This works if the current
982 buffer only sees the default value, too. */
983 Fsetcdr (current_alist_element
,
984 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->car
));
986 /* Find the new value for CURRENT-ALIST-ELEMENT. */
987 tem1
= Fassq (symbol
, current_buffer
->local_var_alist
);
990 /* This buffer still sees the default value. */
992 /* If the variable is a Lisp_Some_Buffer_Local_Value,
993 make CURRENT-ALIST-ELEMENT point to itself,
994 indicating that we're seeing the default value. */
995 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
996 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
;
998 /* If it's a Lisp_Buffer_Local_Value, give this buffer a
999 new assoc for a local value and set
1000 CURRENT-ALIST-ELEMENT to point to that. */
1003 tem1
= Fcons (symbol
, Fcdr (current_alist_element
));
1004 current_buffer
->local_var_alist
=
1005 Fcons (tem1
, current_buffer
->local_var_alist
);
1008 /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT. */
1009 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
1012 /* Set BUFFER, now that CURRENT-ALIST-ELEMENT is accurate. */
1013 XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
,
1016 valcontents
= XBUFFER_LOCAL_VALUE (valcontents
)->car
;
1019 /* If storing void (making the symbol void), forward only through
1020 buffer-local indicator, not through Lisp_Objfwd, etc. */
1022 store_symval_forwarding (symbol
, Qnil
, newval
);
1024 store_symval_forwarding (symbol
, valcontents
, newval
);
1029 /* Access or set a buffer-local symbol's default value. */
1031 /* Return the default value of SYMBOL, but don't check for voidness.
1032 Return Qunbound if it is void. */
1035 default_value (symbol
)
1038 register Lisp_Object valcontents
;
1040 CHECK_SYMBOL (symbol
, 0);
1041 valcontents
= XSYMBOL (symbol
)->value
;
1043 /* For a built-in buffer-local variable, get the default value
1044 rather than letting do_symval_forwarding get the current value. */
1045 if (BUFFER_OBJFWDP (valcontents
))
1047 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1049 if (XINT (*(Lisp_Object
*) (idx
+ (char *) &buffer_local_flags
)) != 0)
1050 return *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
);
1053 /* Handle user-created local variables. */
1054 if (BUFFER_LOCAL_VALUEP (valcontents
)
1055 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1057 /* If var is set up for a buffer that lacks a local value for it,
1058 the current value is nominally the default value.
1059 But the current value slot may be more up to date, since
1060 ordinary setq stores just that slot. So use that. */
1061 Lisp_Object current_alist_element
, alist_element_car
;
1062 current_alist_element
1063 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
1064 alist_element_car
= XCONS (current_alist_element
)->car
;
1065 if (EQ (alist_element_car
, current_alist_element
))
1066 return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->car
);
1068 return XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->cdr
;
1070 /* For other variables, get the current value. */
1071 return do_symval_forwarding (valcontents
);
1074 DEFUN ("default-boundp", Fdefault_boundp
, Sdefault_boundp
, 1, 1, 0,
1075 "Return T if SYMBOL has a non-void default value.\n\
1076 This is the value that is seen in buffers that do not have their own values\n\
1077 for this variable.")
1081 register Lisp_Object value
;
1083 value
= default_value (symbol
);
1084 return (EQ (value
, Qunbound
) ? Qnil
: Qt
);
1087 DEFUN ("default-value", Fdefault_value
, Sdefault_value
, 1, 1, 0,
1088 "Return SYMBOL's default value.\n\
1089 This is the value that is seen in buffers that do not have their own values\n\
1090 for this variable. The default value is meaningful for variables with\n\
1091 local bindings in certain buffers.")
1095 register Lisp_Object value
;
1097 value
= default_value (symbol
);
1098 if (EQ (value
, Qunbound
))
1099 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
1103 DEFUN ("set-default", Fset_default
, Sset_default
, 2, 2, 0,
1104 "Set SYMBOL's default value to VAL. SYMBOL and VAL are evaluated.\n\
1105 The default value is seen in buffers that do not have their own values\n\
1106 for this variable.")
1108 Lisp_Object symbol
, value
;
1110 register Lisp_Object valcontents
, current_alist_element
, alist_element_buffer
;
1112 CHECK_SYMBOL (symbol
, 0);
1113 valcontents
= XSYMBOL (symbol
)->value
;
1115 /* Handle variables like case-fold-search that have special slots
1116 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1118 if (BUFFER_OBJFWDP (valcontents
))
1120 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1121 register struct buffer
*b
;
1122 register int mask
= XINT (*((Lisp_Object
*)
1123 (idx
+ (char *)&buffer_local_flags
)));
1127 *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
) = value
;
1128 for (b
= all_buffers
; b
; b
= b
->next
)
1129 if (!(b
->local_var_flags
& mask
))
1130 *(Lisp_Object
*)(idx
+ (char *) b
) = value
;
1135 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1136 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1137 return Fset (symbol
, value
);
1139 /* Store new value into the DEFAULT-VALUE slot */
1140 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->cdr
= value
;
1142 /* If that slot is current, we must set the REALVALUE slot too */
1143 current_alist_element
1144 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
1145 alist_element_buffer
= Fcar (current_alist_element
);
1146 if (EQ (alist_element_buffer
, current_alist_element
))
1147 store_symval_forwarding (symbol
, XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1153 DEFUN ("setq-default", Fsetq_default
, Ssetq_default
, 2, UNEVALLED
, 0,
1154 "Set the default value of variable VAR to VALUE.\n\
1155 VAR, the variable name, is literal (not evaluated);\n\
1156 VALUE is an expression and it is evaluated.\n\
1157 The default value of a variable is seen in buffers\n\
1158 that do not have their own values for the variable.\n\
1160 More generally, you can use multiple variables and values, as in\n\
1161 (setq-default SYMBOL VALUE SYMBOL VALUE...)\n\
1162 This sets each SYMBOL's default value to the corresponding VALUE.\n\
1163 The VALUE for the Nth SYMBOL can refer to the new default values\n\
1168 register Lisp_Object args_left
;
1169 register Lisp_Object val
, symbol
;
1170 struct gcpro gcpro1
;
1180 val
= Feval (Fcar (Fcdr (args_left
)));
1181 symbol
= Fcar (args_left
);
1182 Fset_default (symbol
, val
);
1183 args_left
= Fcdr (Fcdr (args_left
));
1185 while (!NILP (args_left
));
1191 /* Lisp functions for creating and removing buffer-local variables. */
1193 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local
, Smake_variable_buffer_local
,
1194 1, 1, "vMake Variable Buffer Local: ",
1195 "Make VARIABLE have a separate value for each buffer.\n\
1196 At any time, the value for the current buffer is in effect.\n\
1197 There is also a default value which is seen in any buffer which has not yet\n\
1198 set its own value.\n\
1199 Using `set' or `setq' to set the variable causes it to have a separate value\n\
1200 for the current buffer if it was previously using the default value.\n\
1201 The function `default-value' gets the default value and `set-default' sets it.")
1203 register Lisp_Object variable
;
1205 register Lisp_Object tem
, valcontents
, newval
;
1207 CHECK_SYMBOL (variable
, 0);
1209 valcontents
= XSYMBOL (variable
)->value
;
1210 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1211 error ("Symbol %s may not be buffer-local", XSYMBOL (variable
)->name
->data
);
1213 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1215 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1217 XMISCTYPE (XSYMBOL (variable
)->value
) = Lisp_Misc_Buffer_Local_Value
;
1220 if (EQ (valcontents
, Qunbound
))
1221 XSYMBOL (variable
)->value
= Qnil
;
1222 tem
= Fcons (Qnil
, Fsymbol_value (variable
));
1223 XCONS (tem
)->car
= tem
;
1224 newval
= allocate_misc ();
1225 XMISCTYPE (newval
) = Lisp_Misc_Buffer_Local_Value
;
1226 XBUFFER_LOCAL_VALUE (newval
)->car
= XSYMBOL (variable
)->value
;
1227 XBUFFER_LOCAL_VALUE (newval
)->cdr
= Fcons (Fcurrent_buffer (), tem
);
1228 XSYMBOL (variable
)->value
= newval
;
1232 DEFUN ("make-local-variable", Fmake_local_variable
, Smake_local_variable
,
1233 1, 1, "vMake Local Variable: ",
1234 "Make VARIABLE have a separate value in the current buffer.\n\
1235 Other buffers will continue to share a common default value.\n\
1236 \(The buffer-local value of VARIABLE starts out as the same value\n\
1237 VARIABLE previously had. If VARIABLE was void, it remains void.\)\n\
1238 See also `make-variable-buffer-local'.\n\n\
1239 If the variable is already arranged to become local when set,\n\
1240 this function causes a local value to exist for this buffer,\n\
1241 just as setting the variable would do.\n\
1243 Do not use `make-local-variable' to make a hook variable buffer-local.\n\
1244 Use `make-local-hook' instead.")
1246 register Lisp_Object variable
;
1248 register Lisp_Object tem
, valcontents
;
1250 CHECK_SYMBOL (variable
, 0);
1252 valcontents
= XSYMBOL (variable
)->value
;
1253 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1254 error ("Symbol %s may not be buffer-local", XSYMBOL (variable
)->name
->data
);
1256 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1258 tem
= Fboundp (variable
);
1260 /* Make sure the symbol has a local value in this particular buffer,
1261 by setting it to the same value it already has. */
1262 Fset (variable
, (EQ (tem
, Qt
) ? Fsymbol_value (variable
) : Qunbound
));
1265 /* Make sure symbol is set up to hold per-buffer values */
1266 if (!SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1269 tem
= Fcons (Qnil
, do_symval_forwarding (valcontents
));
1270 XCONS (tem
)->car
= tem
;
1271 newval
= allocate_misc ();
1272 XMISCTYPE (newval
) = Lisp_Misc_Some_Buffer_Local_Value
;
1273 XBUFFER_LOCAL_VALUE (newval
)->car
= XSYMBOL (variable
)->value
;
1274 XBUFFER_LOCAL_VALUE (newval
)->cdr
= Fcons (Qnil
, tem
);
1275 XSYMBOL (variable
)->value
= newval
;
1277 /* Make sure this buffer has its own value of symbol */
1278 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1281 /* Swap out any local binding for some other buffer, and make
1282 sure the current value is permanently recorded, if it's the
1284 find_symbol_value (variable
);
1286 current_buffer
->local_var_alist
1287 = Fcons (Fcons (variable
, XCONS (XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (variable
)->value
)->cdr
)->cdr
)->cdr
),
1288 current_buffer
->local_var_alist
);
1290 /* Make sure symbol does not think it is set up for this buffer;
1291 force it to look once again for this buffer's value */
1293 Lisp_Object
*pvalbuf
;
1295 valcontents
= XSYMBOL (variable
)->value
;
1297 pvalbuf
= &XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
1298 if (current_buffer
== XBUFFER (*pvalbuf
))
1303 /* If the symbol forwards into a C variable, then swap in the
1304 variable for this buffer immediately. If C code modifies the
1305 variable before we swap in, then that new value will clobber the
1306 default value the next time we swap. */
1307 valcontents
= XBUFFER_LOCAL_VALUE (XSYMBOL (variable
)->value
)->car
;
1308 if (INTFWDP (valcontents
) || BOOLFWDP (valcontents
) || OBJFWDP (valcontents
))
1309 swap_in_symval_forwarding (variable
, XSYMBOL (variable
)->value
);
1314 DEFUN ("kill-local-variable", Fkill_local_variable
, Skill_local_variable
,
1315 1, 1, "vKill Local Variable: ",
1316 "Make VARIABLE no longer have a separate value in the current buffer.\n\
1317 From now on the default value will apply in this buffer.")
1319 register Lisp_Object variable
;
1321 register Lisp_Object tem
, valcontents
;
1323 CHECK_SYMBOL (variable
, 0);
1325 valcontents
= XSYMBOL (variable
)->value
;
1327 if (BUFFER_OBJFWDP (valcontents
))
1329 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1330 register int mask
= XINT (*((Lisp_Object
*)
1331 (idx
+ (char *)&buffer_local_flags
)));
1335 *(Lisp_Object
*)(idx
+ (char *) current_buffer
)
1336 = *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
);
1337 current_buffer
->local_var_flags
&= ~mask
;
1342 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1343 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1346 /* Get rid of this buffer's alist element, if any */
1348 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1350 current_buffer
->local_var_alist
1351 = Fdelq (tem
, current_buffer
->local_var_alist
);
1353 /* If the symbol is set up for the current buffer, recompute its
1354 value. We have to do it now, or else forwarded objects won't
1357 Lisp_Object
*pvalbuf
;
1358 valcontents
= XSYMBOL (variable
)->value
;
1359 pvalbuf
= &XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
1360 if (current_buffer
== XBUFFER (*pvalbuf
))
1363 find_symbol_value (variable
);
1370 DEFUN ("local-variable-p", Flocal_variable_p
, Slocal_variable_p
,
1372 "Non-nil if VARIABLE has a local binding in buffer BUFFER.\n\
1373 BUFFER defaults to the current buffer.")
1375 register Lisp_Object variable
, buffer
;
1377 Lisp_Object valcontents
;
1378 register struct buffer
*buf
;
1381 buf
= current_buffer
;
1384 CHECK_BUFFER (buffer
, 0);
1385 buf
= XBUFFER (buffer
);
1388 CHECK_SYMBOL (variable
, 0);
1390 valcontents
= XSYMBOL (variable
)->value
;
1391 if (BUFFER_LOCAL_VALUEP (valcontents
)
1392 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1394 Lisp_Object tail
, elt
;
1395 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1397 elt
= XCONS (tail
)->car
;
1398 if (EQ (variable
, XCONS (elt
)->car
))
1402 if (BUFFER_OBJFWDP (valcontents
))
1404 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1405 int mask
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
1406 if (mask
== -1 || (buf
->local_var_flags
& mask
))
1412 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p
, Slocal_variable_if_set_p
,
1414 "Non-nil if VARIABLE will be local in buffer BUFFER if it is set there.\n\
1415 BUFFER defaults to the current buffer.")
1417 register Lisp_Object variable
, buffer
;
1419 Lisp_Object valcontents
;
1420 register struct buffer
*buf
;
1423 buf
= current_buffer
;
1426 CHECK_BUFFER (buffer
, 0);
1427 buf
= XBUFFER (buffer
);
1430 CHECK_SYMBOL (variable
, 0);
1432 valcontents
= XSYMBOL (variable
)->value
;
1434 /* This means that make-variable-buffer-local was done. */
1435 if (BUFFER_LOCAL_VALUEP (valcontents
))
1437 /* All these slots become local if they are set. */
1438 if (BUFFER_OBJFWDP (valcontents
))
1440 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1442 Lisp_Object tail
, elt
;
1443 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1445 elt
= XCONS (tail
)->car
;
1446 if (EQ (variable
, XCONS (elt
)->car
))
1453 /* Find the function at the end of a chain of symbol function indirections. */
1455 /* If OBJECT is a symbol, find the end of its function chain and
1456 return the value found there. If OBJECT is not a symbol, just
1457 return it. If there is a cycle in the function chain, signal a
1458 cyclic-function-indirection error.
1460 This is like Findirect_function, except that it doesn't signal an
1461 error if the chain ends up unbound. */
1463 indirect_function (object
)
1464 register Lisp_Object object
;
1466 Lisp_Object tortoise
, hare
;
1468 hare
= tortoise
= object
;
1472 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1474 hare
= XSYMBOL (hare
)->function
;
1475 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1477 hare
= XSYMBOL (hare
)->function
;
1479 tortoise
= XSYMBOL (tortoise
)->function
;
1481 if (EQ (hare
, tortoise
))
1482 Fsignal (Qcyclic_function_indirection
, Fcons (object
, Qnil
));
1488 DEFUN ("indirect-function", Findirect_function
, Sindirect_function
, 1, 1, 0,
1489 "Return the function at the end of OBJECT's function chain.\n\
1490 If OBJECT is a symbol, follow all function indirections and return the final\n\
1491 function binding.\n\
1492 If OBJECT is not a symbol, just return it.\n\
1493 Signal a void-function error if the final symbol is unbound.\n\
1494 Signal a cyclic-function-indirection error if there is a loop in the\n\
1495 function chain of symbols.")
1497 register Lisp_Object object
;
1501 result
= indirect_function (object
);
1503 if (EQ (result
, Qunbound
))
1504 return Fsignal (Qvoid_function
, Fcons (object
, Qnil
));
1508 /* Extract and set vector and string elements */
1510 DEFUN ("aref", Faref
, Saref
, 2, 2, 0,
1511 "Return the element of ARRAY at index IDX.\n\
1512 ARRAY may be a vector, a string, a char-table, a bool-vector,\n\
1513 or a byte-code object. IDX starts at 0.")
1515 register Lisp_Object array
;
1518 register int idxval
;
1520 CHECK_NUMBER (idx
, 1);
1521 idxval
= XINT (idx
);
1522 if (STRINGP (array
))
1525 if (idxval
< 0 || idxval
>= XSTRING (array
)->size
)
1526 args_out_of_range (array
, idx
);
1527 XSETFASTINT (val
, (unsigned char) XSTRING (array
)->data
[idxval
]);
1530 else if (BOOL_VECTOR_P (array
))
1534 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1535 args_out_of_range (array
, idx
);
1537 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
];
1538 return (val
& (1 << (idxval
% BITS_PER_CHAR
)) ? Qt
: Qnil
);
1540 else if (CHAR_TABLE_P (array
))
1545 args_out_of_range (array
, idx
);
1547 if ((unsigned) idxval
>= CHAR_TABLE_ORDINARY_SLOTS
)
1548 args_out_of_range (array
, idx
);
1549 return val
= XCHAR_TABLE (array
)->contents
[idxval
];
1551 if ((unsigned) idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
1552 val
= XCHAR_TABLE (array
)->data
[idxval
];
1556 unsigned char c1
, c2
;
1557 Lisp_Object val
, temp
;
1559 BREAKUP_NON_ASCII_CHAR (idxval
, charset
, c1
, c2
);
1561 try_parent_char_table
:
1562 val
= XCHAR_TABLE (array
)->contents
[charset
];
1563 if (c1
== 0 || !CHAR_TABLE_P (val
))
1566 temp
= XCHAR_TABLE (val
)->contents
[c1
];
1568 val
= XCHAR_TABLE (val
)->defalt
;
1572 if (NILP (val
) && !NILP (XCHAR_TABLE (array
)->parent
))
1574 array
= XCHAR_TABLE (array
)->parent
;
1575 goto try_parent_char_table
;
1579 if (c2
== 0 || !CHAR_TABLE_P (val
))
1582 temp
= XCHAR_TABLE (val
)->contents
[c2
];
1584 val
= XCHAR_TABLE (val
)->defalt
;
1588 if (NILP (val
) && !NILP (XCHAR_TABLE (array
)->parent
))
1590 array
= XCHAR_TABLE (array
)->parent
;
1591 goto try_parent_char_table
;
1601 if (VECTORP (array
))
1602 size
= XVECTOR (array
)->size
;
1603 else if (COMPILEDP (array
))
1604 size
= XVECTOR (array
)->size
& PSEUDOVECTOR_SIZE_MASK
;
1606 wrong_type_argument (Qarrayp
, array
);
1608 if (idxval
< 0 || idxval
>= size
)
1609 args_out_of_range (array
, idx
);
1610 return XVECTOR (array
)->contents
[idxval
];
1614 DEFUN ("aset", Faset
, Saset
, 3, 3, 0,
1615 "Store into the element of ARRAY at index IDX the value NEWELT.\n\
1616 ARRAY may be a vector or a string. IDX starts at 0.")
1617 (array
, idx
, newelt
)
1618 register Lisp_Object array
;
1619 Lisp_Object idx
, newelt
;
1621 register int idxval
;
1623 CHECK_NUMBER (idx
, 1);
1624 idxval
= XINT (idx
);
1625 if (!VECTORP (array
) && !STRINGP (array
) && !BOOL_VECTOR_P (array
)
1626 && ! CHAR_TABLE_P (array
))
1627 array
= wrong_type_argument (Qarrayp
, array
);
1628 CHECK_IMPURE (array
);
1630 if (VECTORP (array
))
1632 if (idxval
< 0 || idxval
>= XVECTOR (array
)->size
)
1633 args_out_of_range (array
, idx
);
1634 XVECTOR (array
)->contents
[idxval
] = newelt
;
1636 else if (BOOL_VECTOR_P (array
))
1640 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1641 args_out_of_range (array
, idx
);
1643 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
];
1645 if (! NILP (newelt
))
1646 val
|= 1 << (idxval
% BITS_PER_CHAR
);
1648 val
&= ~(1 << (idxval
% BITS_PER_CHAR
));
1649 XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
] = val
;
1651 else if (CHAR_TABLE_P (array
))
1656 args_out_of_range (array
, idx
);
1658 if (idxval
>= CHAR_TABLE_ORDINARY_SLOTS
)
1659 args_out_of_range (array
, idx
);
1660 XCHAR_TABLE (array
)->contents
[idxval
] = newelt
;
1663 if (idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
1664 val
= XCHAR_TABLE (array
)->contents
[idxval
];
1668 unsigned char c1
, c2
;
1669 Lisp_Object val
, val2
;
1671 BREAKUP_NON_ASCII_CHAR (idxval
, charset
, c1
, c2
);
1674 return XCHAR_TABLE (array
)->contents
[charset
] = newelt
;
1676 val
= XCHAR_TABLE (array
)->contents
[charset
];
1677 if (!CHAR_TABLE_P (val
))
1678 XCHAR_TABLE (array
)->contents
[charset
]
1679 = val
= Fmake_char_table (Qnil
);
1682 return XCHAR_TABLE (val
)->contents
[c1
] = newelt
;
1684 val2
= XCHAR_TABLE (val
)->contents
[c2
];
1685 if (!CHAR_TABLE_P (val2
))
1686 XCHAR_TABLE (val
)->contents
[charset
]
1687 = val2
= Fmake_char_table (Qnil
);
1689 return XCHAR_TABLE (val2
)->contents
[c2
] = newelt
;
1695 if (idxval
< 0 || idxval
>= XSTRING (array
)->size
)
1696 args_out_of_range (array
, idx
);
1697 CHECK_NUMBER (newelt
, 2);
1698 XSTRING (array
)->data
[idxval
] = XINT (newelt
);
1704 /* Arithmetic functions */
1706 enum comparison
{ equal
, notequal
, less
, grtr
, less_or_equal
, grtr_or_equal
};
1709 arithcompare (num1
, num2
, comparison
)
1710 Lisp_Object num1
, num2
;
1711 enum comparison comparison
;
1716 #ifdef LISP_FLOAT_TYPE
1717 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1
, 0);
1718 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2
, 0);
1720 if (FLOATP (num1
) || FLOATP (num2
))
1723 f1
= (FLOATP (num1
)) ? XFLOAT (num1
)->data
: XINT (num1
);
1724 f2
= (FLOATP (num2
)) ? XFLOAT (num2
)->data
: XINT (num2
);
1727 CHECK_NUMBER_COERCE_MARKER (num1
, 0);
1728 CHECK_NUMBER_COERCE_MARKER (num2
, 0);
1729 #endif /* LISP_FLOAT_TYPE */
1734 if (floatp
? f1
== f2
: XINT (num1
) == XINT (num2
))
1739 if (floatp
? f1
!= f2
: XINT (num1
) != XINT (num2
))
1744 if (floatp
? f1
< f2
: XINT (num1
) < XINT (num2
))
1749 if (floatp
? f1
<= f2
: XINT (num1
) <= XINT (num2
))
1754 if (floatp
? f1
> f2
: XINT (num1
) > XINT (num2
))
1759 if (floatp
? f1
>= f2
: XINT (num1
) >= XINT (num2
))
1768 DEFUN ("=", Feqlsign
, Seqlsign
, 2, 2, 0,
1769 "T if two args, both numbers or markers, are equal.")
1771 register Lisp_Object num1
, num2
;
1773 return arithcompare (num1
, num2
, equal
);
1776 DEFUN ("<", Flss
, Slss
, 2, 2, 0,
1777 "T if first arg is less than second arg. Both must be numbers or markers.")
1779 register Lisp_Object num1
, num2
;
1781 return arithcompare (num1
, num2
, less
);
1784 DEFUN (">", Fgtr
, Sgtr
, 2, 2, 0,
1785 "T if first arg is greater than second arg. Both must be numbers or markers.")
1787 register Lisp_Object num1
, num2
;
1789 return arithcompare (num1
, num2
, grtr
);
1792 DEFUN ("<=", Fleq
, Sleq
, 2, 2, 0,
1793 "T if first arg is less than or equal to second arg.\n\
1794 Both must be numbers or markers.")
1796 register Lisp_Object num1
, num2
;
1798 return arithcompare (num1
, num2
, less_or_equal
);
1801 DEFUN (">=", Fgeq
, Sgeq
, 2, 2, 0,
1802 "T if first arg is greater than or equal to second arg.\n\
1803 Both must be numbers or markers.")
1805 register Lisp_Object num1
, num2
;
1807 return arithcompare (num1
, num2
, grtr_or_equal
);
1810 DEFUN ("/=", Fneq
, Sneq
, 2, 2, 0,
1811 "T if first arg is not equal to second arg. Both must be numbers or markers.")
1813 register Lisp_Object num1
, num2
;
1815 return arithcompare (num1
, num2
, notequal
);
1818 DEFUN ("zerop", Fzerop
, Szerop
, 1, 1, 0, "T if NUMBER is zero.")
1820 register Lisp_Object number
;
1822 #ifdef LISP_FLOAT_TYPE
1823 CHECK_NUMBER_OR_FLOAT (number
, 0);
1825 if (FLOATP (number
))
1827 if (XFLOAT(number
)->data
== 0.0)
1832 CHECK_NUMBER (number
, 0);
1833 #endif /* LISP_FLOAT_TYPE */
1840 /* Convert between long values and pairs of Lisp integers. */
1846 unsigned int top
= i
>> 16;
1847 unsigned int bot
= i
& 0xFFFF;
1849 return make_number (bot
);
1850 if (top
== (unsigned long)-1 >> 16)
1851 return Fcons (make_number (-1), make_number (bot
));
1852 return Fcons (make_number (top
), make_number (bot
));
1859 Lisp_Object top
, bot
;
1862 top
= XCONS (c
)->car
;
1863 bot
= XCONS (c
)->cdr
;
1865 bot
= XCONS (bot
)->car
;
1866 return ((XINT (top
) << 16) | XINT (bot
));
1869 DEFUN ("number-to-string", Fnumber_to_string
, Snumber_to_string
, 1, 1, 0,
1870 "Convert NUMBER to a string by printing it in decimal.\n\
1871 Uses a minus sign if negative.\n\
1872 NUMBER may be an integer or a floating point number.")
1876 char buffer
[VALBITS
];
1878 #ifndef LISP_FLOAT_TYPE
1879 CHECK_NUMBER (number
, 0);
1881 CHECK_NUMBER_OR_FLOAT (number
, 0);
1883 if (FLOATP (number
))
1885 char pigbuf
[350]; /* see comments in float_to_string */
1887 float_to_string (pigbuf
, XFLOAT(number
)->data
);
1888 return build_string (pigbuf
);
1890 #endif /* LISP_FLOAT_TYPE */
1892 if (sizeof (int) == sizeof (EMACS_INT
))
1893 sprintf (buffer
, "%d", XINT (number
));
1894 else if (sizeof (long) == sizeof (EMACS_INT
))
1895 sprintf (buffer
, "%ld", XINT (number
));
1898 return build_string (buffer
);
1901 DEFUN ("string-to-number", Fstring_to_number
, Sstring_to_number
, 1, 1, 0,
1902 "Convert STRING to a number by parsing it as a decimal number.\n\
1903 This parses both integers and floating point numbers.\n\
1904 It ignores leading spaces and tabs.")
1906 register Lisp_Object string
;
1911 CHECK_STRING (string
, 0);
1913 p
= XSTRING (string
)->data
;
1915 /* Skip any whitespace at the front of the number. Some versions of
1916 atoi do this anyway, so we might as well make Emacs lisp consistent. */
1917 while (*p
== ' ' || *p
== '\t')
1920 #ifdef LISP_FLOAT_TYPE
1921 if (isfloat_string (p
))
1922 return make_float (atof (p
));
1923 #endif /* LISP_FLOAT_TYPE */
1925 if (sizeof (int) == sizeof (EMACS_INT
))
1926 XSETINT (value
, atoi (p
));
1927 else if (sizeof (long) == sizeof (EMACS_INT
))
1928 XSETINT (value
, atol (p
));
1935 { Aadd
, Asub
, Amult
, Adiv
, Alogand
, Alogior
, Alogxor
, Amax
, Amin
};
1937 extern Lisp_Object
float_arith_driver ();
1940 arith_driver (code
, nargs
, args
)
1943 register Lisp_Object
*args
;
1945 register Lisp_Object val
;
1946 register int argnum
;
1947 register EMACS_INT accum
;
1948 register EMACS_INT next
;
1950 switch (SWITCH_ENUM_CAST (code
))
1963 for (argnum
= 0; argnum
< nargs
; argnum
++)
1965 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
1966 #ifdef LISP_FLOAT_TYPE
1967 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
1969 if (FLOATP (val
)) /* time to do serious math */
1970 return (float_arith_driver ((double) accum
, argnum
, code
,
1973 CHECK_NUMBER_COERCE_MARKER (val
, argnum
);
1974 #endif /* LISP_FLOAT_TYPE */
1975 args
[argnum
] = val
; /* runs into a compiler bug. */
1976 next
= XINT (args
[argnum
]);
1977 switch (SWITCH_ENUM_CAST (code
))
1979 case Aadd
: accum
+= next
; break;
1981 if (!argnum
&& nargs
!= 1)
1985 case Amult
: accum
*= next
; break;
1987 if (!argnum
) accum
= next
;
1991 Fsignal (Qarith_error
, Qnil
);
1995 case Alogand
: accum
&= next
; break;
1996 case Alogior
: accum
|= next
; break;
1997 case Alogxor
: accum
^= next
; break;
1998 case Amax
: if (!argnum
|| next
> accum
) accum
= next
; break;
1999 case Amin
: if (!argnum
|| next
< accum
) accum
= next
; break;
2003 XSETINT (val
, accum
);
2007 #ifdef LISP_FLOAT_TYPE
2010 #define isnan(x) ((x) != (x))
2013 float_arith_driver (accum
, argnum
, code
, nargs
, args
)
2015 register int argnum
;
2018 register Lisp_Object
*args
;
2020 register Lisp_Object val
;
2023 for (; argnum
< nargs
; argnum
++)
2025 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2026 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
2030 next
= XFLOAT (val
)->data
;
2034 args
[argnum
] = val
; /* runs into a compiler bug. */
2035 next
= XINT (args
[argnum
]);
2037 switch (SWITCH_ENUM_CAST (code
))
2043 if (!argnum
&& nargs
!= 1)
2056 Fsignal (Qarith_error
, Qnil
);
2063 return wrong_type_argument (Qinteger_or_marker_p
, val
);
2065 if (!argnum
|| isnan (next
) || next
> accum
)
2069 if (!argnum
|| isnan (next
) || next
< accum
)
2075 return make_float (accum
);
2077 #endif /* LISP_FLOAT_TYPE */
2079 DEFUN ("+", Fplus
, Splus
, 0, MANY
, 0,
2080 "Return sum of any number of arguments, which are numbers or markers.")
2085 return arith_driver (Aadd
, nargs
, args
);
2088 DEFUN ("-", Fminus
, Sminus
, 0, MANY
, 0,
2089 "Negate number or subtract numbers or markers.\n\
2090 With one arg, negates it. With more than one arg,\n\
2091 subtracts all but the first from the first.")
2096 return arith_driver (Asub
, nargs
, args
);
2099 DEFUN ("*", Ftimes
, Stimes
, 0, MANY
, 0,
2100 "Returns product of any number of arguments, which are numbers or markers.")
2105 return arith_driver (Amult
, nargs
, args
);
2108 DEFUN ("/", Fquo
, Squo
, 2, MANY
, 0,
2109 "Returns first argument divided by all the remaining arguments.\n\
2110 The arguments must be numbers or markers.")
2115 return arith_driver (Adiv
, nargs
, args
);
2118 DEFUN ("%", Frem
, Srem
, 2, 2, 0,
2119 "Returns remainder of X divided by Y.\n\
2120 Both must be integers or markers.")
2122 register Lisp_Object x
, y
;
2126 CHECK_NUMBER_COERCE_MARKER (x
, 0);
2127 CHECK_NUMBER_COERCE_MARKER (y
, 1);
2129 if (XFASTINT (y
) == 0)
2130 Fsignal (Qarith_error
, Qnil
);
2132 XSETINT (val
, XINT (x
) % XINT (y
));
2143 return (f1
- f2
* floor (f1
/f2
));
2145 #endif /* ! HAVE_FMOD */
2147 DEFUN ("mod", Fmod
, Smod
, 2, 2, 0,
2148 "Returns X modulo Y.\n\
2149 The result falls between zero (inclusive) and Y (exclusive).\n\
2150 Both X and Y must be numbers or markers.")
2152 register Lisp_Object x
, y
;
2157 #ifdef LISP_FLOAT_TYPE
2158 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x
, 0);
2159 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y
, 1);
2161 if (FLOATP (x
) || FLOATP (y
))
2165 f1
= FLOATP (x
) ? XFLOAT (x
)->data
: XINT (x
);
2166 f2
= FLOATP (y
) ? XFLOAT (y
)->data
: XINT (y
);
2168 Fsignal (Qarith_error
, Qnil
);
2171 /* If the "remainder" comes out with the wrong sign, fix it. */
2172 if (f2
< 0 ? f1
> 0 : f1
< 0)
2174 return (make_float (f1
));
2176 #else /* not LISP_FLOAT_TYPE */
2177 CHECK_NUMBER_COERCE_MARKER (x
, 0);
2178 CHECK_NUMBER_COERCE_MARKER (y
, 1);
2179 #endif /* not LISP_FLOAT_TYPE */
2185 Fsignal (Qarith_error
, Qnil
);
2189 /* If the "remainder" comes out with the wrong sign, fix it. */
2190 if (i2
< 0 ? i1
> 0 : i1
< 0)
2197 DEFUN ("max", Fmax
, Smax
, 1, MANY
, 0,
2198 "Return largest of all the arguments (which must be numbers or markers).\n\
2199 The value is always a number; markers are converted to numbers.")
2204 return arith_driver (Amax
, nargs
, args
);
2207 DEFUN ("min", Fmin
, Smin
, 1, MANY
, 0,
2208 "Return smallest of all the arguments (which must be numbers or markers).\n\
2209 The value is always a number; markers are converted to numbers.")
2214 return arith_driver (Amin
, nargs
, args
);
2217 DEFUN ("logand", Flogand
, Slogand
, 0, MANY
, 0,
2218 "Return bitwise-and of all the arguments.\n\
2219 Arguments may be integers, or markers converted to integers.")
2224 return arith_driver (Alogand
, nargs
, args
);
2227 DEFUN ("logior", Flogior
, Slogior
, 0, MANY
, 0,
2228 "Return bitwise-or of all the arguments.\n\
2229 Arguments may be integers, or markers converted to integers.")
2234 return arith_driver (Alogior
, nargs
, args
);
2237 DEFUN ("logxor", Flogxor
, Slogxor
, 0, MANY
, 0,
2238 "Return bitwise-exclusive-or of all the arguments.\n\
2239 Arguments may be integers, or markers converted to integers.")
2244 return arith_driver (Alogxor
, nargs
, args
);
2247 DEFUN ("ash", Fash
, Sash
, 2, 2, 0,
2248 "Return VALUE with its bits shifted left by COUNT.\n\
2249 If COUNT is negative, shifting is actually to the right.\n\
2250 In this case, the sign bit is duplicated.")
2252 register Lisp_Object value
, count
;
2254 register Lisp_Object val
;
2256 CHECK_NUMBER (value
, 0);
2257 CHECK_NUMBER (count
, 1);
2259 if (XINT (count
) > 0)
2260 XSETINT (val
, XINT (value
) << XFASTINT (count
));
2262 XSETINT (val
, XINT (value
) >> -XINT (count
));
2266 DEFUN ("lsh", Flsh
, Slsh
, 2, 2, 0,
2267 "Return VALUE with its bits shifted left by COUNT.\n\
2268 If COUNT is negative, shifting is actually to the right.\n\
2269 In this case, zeros are shifted in on the left.")
2271 register Lisp_Object value
, count
;
2273 register Lisp_Object val
;
2275 CHECK_NUMBER (value
, 0);
2276 CHECK_NUMBER (count
, 1);
2278 if (XINT (count
) > 0)
2279 XSETINT (val
, (EMACS_UINT
) XUINT (value
) << XFASTINT (count
));
2281 XSETINT (val
, (EMACS_UINT
) XUINT (value
) >> -XINT (count
));
2285 DEFUN ("1+", Fadd1
, Sadd1
, 1, 1, 0,
2286 "Return NUMBER plus one. NUMBER may be a number or a marker.\n\
2287 Markers are converted to integers.")
2289 register Lisp_Object number
;
2291 #ifdef LISP_FLOAT_TYPE
2292 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
, 0);
2294 if (FLOATP (number
))
2295 return (make_float (1.0 + XFLOAT (number
)->data
));
2297 CHECK_NUMBER_COERCE_MARKER (number
, 0);
2298 #endif /* LISP_FLOAT_TYPE */
2300 XSETINT (number
, XINT (number
) + 1);
2304 DEFUN ("1-", Fsub1
, Ssub1
, 1, 1, 0,
2305 "Return NUMBER minus one. NUMBER may be a number or a marker.\n\
2306 Markers are converted to integers.")
2308 register Lisp_Object number
;
2310 #ifdef LISP_FLOAT_TYPE
2311 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
, 0);
2313 if (FLOATP (number
))
2314 return (make_float (-1.0 + XFLOAT (number
)->data
));
2316 CHECK_NUMBER_COERCE_MARKER (number
, 0);
2317 #endif /* LISP_FLOAT_TYPE */
2319 XSETINT (number
, XINT (number
) - 1);
2323 DEFUN ("lognot", Flognot
, Slognot
, 1, 1, 0,
2324 "Return the bitwise complement of NUMBER. NUMBER must be an integer.")
2326 register Lisp_Object number
;
2328 CHECK_NUMBER (number
, 0);
2329 XSETINT (number
, ~XINT (number
));
2336 Lisp_Object error_tail
, arith_tail
;
2338 Qquote
= intern ("quote");
2339 Qlambda
= intern ("lambda");
2340 Qsubr
= intern ("subr");
2341 Qerror_conditions
= intern ("error-conditions");
2342 Qerror_message
= intern ("error-message");
2343 Qtop_level
= intern ("top-level");
2345 Qerror
= intern ("error");
2346 Qquit
= intern ("quit");
2347 Qwrong_type_argument
= intern ("wrong-type-argument");
2348 Qargs_out_of_range
= intern ("args-out-of-range");
2349 Qvoid_function
= intern ("void-function");
2350 Qcyclic_function_indirection
= intern ("cyclic-function-indirection");
2351 Qvoid_variable
= intern ("void-variable");
2352 Qsetting_constant
= intern ("setting-constant");
2353 Qinvalid_read_syntax
= intern ("invalid-read-syntax");
2355 Qinvalid_function
= intern ("invalid-function");
2356 Qwrong_number_of_arguments
= intern ("wrong-number-of-arguments");
2357 Qno_catch
= intern ("no-catch");
2358 Qend_of_file
= intern ("end-of-file");
2359 Qarith_error
= intern ("arith-error");
2360 Qbeginning_of_buffer
= intern ("beginning-of-buffer");
2361 Qend_of_buffer
= intern ("end-of-buffer");
2362 Qbuffer_read_only
= intern ("buffer-read-only");
2363 Qmark_inactive
= intern ("mark-inactive");
2365 Qlistp
= intern ("listp");
2366 Qconsp
= intern ("consp");
2367 Qsymbolp
= intern ("symbolp");
2368 Qintegerp
= intern ("integerp");
2369 Qnatnump
= intern ("natnump");
2370 Qwholenump
= intern ("wholenump");
2371 Qstringp
= intern ("stringp");
2372 Qarrayp
= intern ("arrayp");
2373 Qsequencep
= intern ("sequencep");
2374 Qbufferp
= intern ("bufferp");
2375 Qvectorp
= intern ("vectorp");
2376 Qchar_or_string_p
= intern ("char-or-string-p");
2377 Qmarkerp
= intern ("markerp");
2378 Qbuffer_or_string_p
= intern ("buffer-or-string-p");
2379 Qinteger_or_marker_p
= intern ("integer-or-marker-p");
2380 Qboundp
= intern ("boundp");
2381 Qfboundp
= intern ("fboundp");
2383 #ifdef LISP_FLOAT_TYPE
2384 Qfloatp
= intern ("floatp");
2385 Qnumberp
= intern ("numberp");
2386 Qnumber_or_marker_p
= intern ("number-or-marker-p");
2387 #endif /* LISP_FLOAT_TYPE */
2389 Qchar_table_p
= intern ("char-table-p");
2390 Qvector_or_char_table_p
= intern ("vector-or-char-table-p");
2392 Qcdr
= intern ("cdr");
2394 /* Handle automatic advice activation */
2395 Qad_advice_info
= intern ("ad-advice-info");
2396 Qad_activate
= intern ("ad-activate");
2398 error_tail
= Fcons (Qerror
, Qnil
);
2400 /* ERROR is used as a signaler for random errors for which nothing else is right */
2402 Fput (Qerror
, Qerror_conditions
,
2404 Fput (Qerror
, Qerror_message
,
2405 build_string ("error"));
2407 Fput (Qquit
, Qerror_conditions
,
2408 Fcons (Qquit
, Qnil
));
2409 Fput (Qquit
, Qerror_message
,
2410 build_string ("Quit"));
2412 Fput (Qwrong_type_argument
, Qerror_conditions
,
2413 Fcons (Qwrong_type_argument
, error_tail
));
2414 Fput (Qwrong_type_argument
, Qerror_message
,
2415 build_string ("Wrong type argument"));
2417 Fput (Qargs_out_of_range
, Qerror_conditions
,
2418 Fcons (Qargs_out_of_range
, error_tail
));
2419 Fput (Qargs_out_of_range
, Qerror_message
,
2420 build_string ("Args out of range"));
2422 Fput (Qvoid_function
, Qerror_conditions
,
2423 Fcons (Qvoid_function
, error_tail
));
2424 Fput (Qvoid_function
, Qerror_message
,
2425 build_string ("Symbol's function definition is void"));
2427 Fput (Qcyclic_function_indirection
, Qerror_conditions
,
2428 Fcons (Qcyclic_function_indirection
, error_tail
));
2429 Fput (Qcyclic_function_indirection
, Qerror_message
,
2430 build_string ("Symbol's chain of function indirections contains a loop"));
2432 Fput (Qvoid_variable
, Qerror_conditions
,
2433 Fcons (Qvoid_variable
, error_tail
));
2434 Fput (Qvoid_variable
, Qerror_message
,
2435 build_string ("Symbol's value as variable is void"));
2437 Fput (Qsetting_constant
, Qerror_conditions
,
2438 Fcons (Qsetting_constant
, error_tail
));
2439 Fput (Qsetting_constant
, Qerror_message
,
2440 build_string ("Attempt to set a constant symbol"));
2442 Fput (Qinvalid_read_syntax
, Qerror_conditions
,
2443 Fcons (Qinvalid_read_syntax
, error_tail
));
2444 Fput (Qinvalid_read_syntax
, Qerror_message
,
2445 build_string ("Invalid read syntax"));
2447 Fput (Qinvalid_function
, Qerror_conditions
,
2448 Fcons (Qinvalid_function
, error_tail
));
2449 Fput (Qinvalid_function
, Qerror_message
,
2450 build_string ("Invalid function"));
2452 Fput (Qwrong_number_of_arguments
, Qerror_conditions
,
2453 Fcons (Qwrong_number_of_arguments
, error_tail
));
2454 Fput (Qwrong_number_of_arguments
, Qerror_message
,
2455 build_string ("Wrong number of arguments"));
2457 Fput (Qno_catch
, Qerror_conditions
,
2458 Fcons (Qno_catch
, error_tail
));
2459 Fput (Qno_catch
, Qerror_message
,
2460 build_string ("No catch for tag"));
2462 Fput (Qend_of_file
, Qerror_conditions
,
2463 Fcons (Qend_of_file
, error_tail
));
2464 Fput (Qend_of_file
, Qerror_message
,
2465 build_string ("End of file during parsing"));
2467 arith_tail
= Fcons (Qarith_error
, error_tail
);
2468 Fput (Qarith_error
, Qerror_conditions
,
2470 Fput (Qarith_error
, Qerror_message
,
2471 build_string ("Arithmetic error"));
2473 Fput (Qbeginning_of_buffer
, Qerror_conditions
,
2474 Fcons (Qbeginning_of_buffer
, error_tail
));
2475 Fput (Qbeginning_of_buffer
, Qerror_message
,
2476 build_string ("Beginning of buffer"));
2478 Fput (Qend_of_buffer
, Qerror_conditions
,
2479 Fcons (Qend_of_buffer
, error_tail
));
2480 Fput (Qend_of_buffer
, Qerror_message
,
2481 build_string ("End of buffer"));
2483 Fput (Qbuffer_read_only
, Qerror_conditions
,
2484 Fcons (Qbuffer_read_only
, error_tail
));
2485 Fput (Qbuffer_read_only
, Qerror_message
,
2486 build_string ("Buffer is read-only"));
2488 #ifdef LISP_FLOAT_TYPE
2489 Qrange_error
= intern ("range-error");
2490 Qdomain_error
= intern ("domain-error");
2491 Qsingularity_error
= intern ("singularity-error");
2492 Qoverflow_error
= intern ("overflow-error");
2493 Qunderflow_error
= intern ("underflow-error");
2495 Fput (Qdomain_error
, Qerror_conditions
,
2496 Fcons (Qdomain_error
, arith_tail
));
2497 Fput (Qdomain_error
, Qerror_message
,
2498 build_string ("Arithmetic domain error"));
2500 Fput (Qrange_error
, Qerror_conditions
,
2501 Fcons (Qrange_error
, arith_tail
));
2502 Fput (Qrange_error
, Qerror_message
,
2503 build_string ("Arithmetic range error"));
2505 Fput (Qsingularity_error
, Qerror_conditions
,
2506 Fcons (Qsingularity_error
, Fcons (Qdomain_error
, arith_tail
)));
2507 Fput (Qsingularity_error
, Qerror_message
,
2508 build_string ("Arithmetic singularity error"));
2510 Fput (Qoverflow_error
, Qerror_conditions
,
2511 Fcons (Qoverflow_error
, Fcons (Qdomain_error
, arith_tail
)));
2512 Fput (Qoverflow_error
, Qerror_message
,
2513 build_string ("Arithmetic overflow error"));
2515 Fput (Qunderflow_error
, Qerror_conditions
,
2516 Fcons (Qunderflow_error
, Fcons (Qdomain_error
, arith_tail
)));
2517 Fput (Qunderflow_error
, Qerror_message
,
2518 build_string ("Arithmetic underflow error"));
2520 staticpro (&Qrange_error
);
2521 staticpro (&Qdomain_error
);
2522 staticpro (&Qsingularity_error
);
2523 staticpro (&Qoverflow_error
);
2524 staticpro (&Qunderflow_error
);
2525 #endif /* LISP_FLOAT_TYPE */
2529 staticpro (&Qquote
);
2530 staticpro (&Qlambda
);
2532 staticpro (&Qunbound
);
2533 staticpro (&Qerror_conditions
);
2534 staticpro (&Qerror_message
);
2535 staticpro (&Qtop_level
);
2537 staticpro (&Qerror
);
2539 staticpro (&Qwrong_type_argument
);
2540 staticpro (&Qargs_out_of_range
);
2541 staticpro (&Qvoid_function
);
2542 staticpro (&Qcyclic_function_indirection
);
2543 staticpro (&Qvoid_variable
);
2544 staticpro (&Qsetting_constant
);
2545 staticpro (&Qinvalid_read_syntax
);
2546 staticpro (&Qwrong_number_of_arguments
);
2547 staticpro (&Qinvalid_function
);
2548 staticpro (&Qno_catch
);
2549 staticpro (&Qend_of_file
);
2550 staticpro (&Qarith_error
);
2551 staticpro (&Qbeginning_of_buffer
);
2552 staticpro (&Qend_of_buffer
);
2553 staticpro (&Qbuffer_read_only
);
2554 staticpro (&Qmark_inactive
);
2556 staticpro (&Qlistp
);
2557 staticpro (&Qconsp
);
2558 staticpro (&Qsymbolp
);
2559 staticpro (&Qintegerp
);
2560 staticpro (&Qnatnump
);
2561 staticpro (&Qwholenump
);
2562 staticpro (&Qstringp
);
2563 staticpro (&Qarrayp
);
2564 staticpro (&Qsequencep
);
2565 staticpro (&Qbufferp
);
2566 staticpro (&Qvectorp
);
2567 staticpro (&Qchar_or_string_p
);
2568 staticpro (&Qmarkerp
);
2569 staticpro (&Qbuffer_or_string_p
);
2570 staticpro (&Qinteger_or_marker_p
);
2571 #ifdef LISP_FLOAT_TYPE
2572 staticpro (&Qfloatp
);
2573 staticpro (&Qnumberp
);
2574 staticpro (&Qnumber_or_marker_p
);
2575 #endif /* LISP_FLOAT_TYPE */
2576 staticpro (&Qchar_table_p
);
2577 staticpro (&Qvector_or_char_table_p
);
2579 staticpro (&Qboundp
);
2580 staticpro (&Qfboundp
);
2582 staticpro (&Qad_advice_info
);
2583 staticpro (&Qad_activate
);
2585 /* Types that type-of returns. */
2586 Qinteger
= intern ("integer");
2587 Qsymbol
= intern ("symbol");
2588 Qstring
= intern ("string");
2589 Qcons
= intern ("cons");
2590 Qmarker
= intern ("marker");
2591 Qoverlay
= intern ("overlay");
2592 Qfloat
= intern ("float");
2593 Qwindow_configuration
= intern ("window-configuration");
2594 Qprocess
= intern ("process");
2595 Qwindow
= intern ("window");
2596 /* Qsubr = intern ("subr"); */
2597 Qcompiled_function
= intern ("compiled-function");
2598 Qbuffer
= intern ("buffer");
2599 Qframe
= intern ("frame");
2600 Qvector
= intern ("vector");
2601 Qchar_table
= intern ("char-table");
2602 Qbool_vector
= intern ("bool-vector");
2604 staticpro (&Qinteger
);
2605 staticpro (&Qsymbol
);
2606 staticpro (&Qstring
);
2608 staticpro (&Qmarker
);
2609 staticpro (&Qoverlay
);
2610 staticpro (&Qfloat
);
2611 staticpro (&Qwindow_configuration
);
2612 staticpro (&Qprocess
);
2613 staticpro (&Qwindow
);
2614 /* staticpro (&Qsubr); */
2615 staticpro (&Qcompiled_function
);
2616 staticpro (&Qbuffer
);
2617 staticpro (&Qframe
);
2618 staticpro (&Qvector
);
2619 staticpro (&Qchar_table
);
2620 staticpro (&Qbool_vector
);
2624 defsubr (&Stype_of
);
2629 defsubr (&Sintegerp
);
2630 defsubr (&Sinteger_or_marker_p
);
2631 defsubr (&Snumberp
);
2632 defsubr (&Snumber_or_marker_p
);
2633 #ifdef LISP_FLOAT_TYPE
2635 #endif /* LISP_FLOAT_TYPE */
2636 defsubr (&Snatnump
);
2637 defsubr (&Ssymbolp
);
2638 defsubr (&Sstringp
);
2639 defsubr (&Svectorp
);
2640 defsubr (&Schar_table_p
);
2641 defsubr (&Svector_or_char_table_p
);
2642 defsubr (&Sbool_vector_p
);
2644 defsubr (&Ssequencep
);
2645 defsubr (&Sbufferp
);
2646 defsubr (&Smarkerp
);
2648 defsubr (&Sbyte_code_function_p
);
2649 defsubr (&Schar_or_string_p
);
2652 defsubr (&Scar_safe
);
2653 defsubr (&Scdr_safe
);
2656 defsubr (&Ssymbol_function
);
2657 defsubr (&Sindirect_function
);
2658 defsubr (&Ssymbol_plist
);
2659 defsubr (&Ssymbol_name
);
2660 defsubr (&Smakunbound
);
2661 defsubr (&Sfmakunbound
);
2663 defsubr (&Sfboundp
);
2665 defsubr (&Sdefalias
);
2666 defsubr (&Sdefine_function
);
2667 defsubr (&Ssetplist
);
2668 defsubr (&Ssymbol_value
);
2670 defsubr (&Sdefault_boundp
);
2671 defsubr (&Sdefault_value
);
2672 defsubr (&Sset_default
);
2673 defsubr (&Ssetq_default
);
2674 defsubr (&Smake_variable_buffer_local
);
2675 defsubr (&Smake_local_variable
);
2676 defsubr (&Skill_local_variable
);
2677 defsubr (&Slocal_variable_p
);
2678 defsubr (&Slocal_variable_if_set_p
);
2681 defsubr (&Snumber_to_string
);
2682 defsubr (&Sstring_to_number
);
2683 defsubr (&Seqlsign
);
2707 XSYMBOL (Qwholenump
)->function
= XSYMBOL (Qnatnump
)->function
;
2714 #if defined(USG) && !defined(POSIX_SIGNALS)
2715 /* USG systems forget handlers when they are used;
2716 must reestablish each time */
2717 signal (signo
, arith_error
);
2720 /* VMS systems are like USG. */
2721 signal (signo
, arith_error
);
2725 #else /* not BSD4_1 */
2726 sigsetmask (SIGEMPTYMASK
);
2727 #endif /* not BSD4_1 */
2729 Fsignal (Qarith_error
, Qnil
);
2734 /* Don't do this if just dumping out.
2735 We don't want to call `signal' in this case
2736 so that we don't have trouble with dumping
2737 signal-delivering routines in an inconsistent state. */
2741 #endif /* CANNOT_DUMP */
2742 signal (SIGFPE
, arith_error
);
2745 signal (SIGEMT
, arith_error
);