1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 1986, 1988, 1992 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 1, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
31 #include "syssignal.h"
33 #ifdef LISP_FLOAT_TYPE
35 #endif /* LISP_FLOAT_TYPE */
37 Lisp_Object Qnil
, Qt
, Qquote
, Qlambda
, Qsubr
, Qunbound
;
38 Lisp_Object Qerror_conditions
, Qerror_message
, Qtop_level
;
39 Lisp_Object Qerror
, Qquit
, Qwrong_type_argument
, Qargs_out_of_range
;
40 Lisp_Object Qvoid_variable
, Qvoid_function
, Qcyclic_function_indirection
;
41 Lisp_Object Qsetting_constant
, Qinvalid_read_syntax
;
42 Lisp_Object Qinvalid_function
, Qwrong_number_of_arguments
, Qno_catch
;
43 Lisp_Object Qend_of_file
, Qarith_error
;
44 Lisp_Object Qbeginning_of_buffer
, Qend_of_buffer
, Qbuffer_read_only
;
45 Lisp_Object Qintegerp
, Qnatnump
, Qsymbolp
, Qlistp
, Qconsp
;
46 Lisp_Object Qstringp
, Qarrayp
, Qsequencep
, Qbufferp
;
47 Lisp_Object Qchar_or_string_p
, Qmarkerp
, Qinteger_or_marker_p
, Qvectorp
;
48 Lisp_Object Qboundp
, Qfboundp
;
51 #ifdef LISP_FLOAT_TYPE
52 Lisp_Object Qfloatp
, Qinteger_or_floatp
, Qinteger_or_float_or_marker_p
;
53 Lisp_Object Qnumberp
, Qnumber_or_marker_p
;
56 static Lisp_Object
swap_in_symval_forwarding ();
59 wrong_type_argument (predicate
, value
)
60 register Lisp_Object predicate
, value
;
62 register Lisp_Object tem
;
65 if (!EQ (Vmocklisp_arguments
, Qt
))
67 if (XTYPE (value
) == Lisp_String
&&
68 (EQ (predicate
, Qintegerp
) || EQ (predicate
, Qinteger_or_marker_p
)))
69 return Fstring_to_int (value
, Qt
);
70 if (XTYPE (value
) == Lisp_Int
&& EQ (predicate
, Qstringp
))
71 return Fint_to_string (value
);
73 value
= Fsignal (Qwrong_type_argument
, Fcons (predicate
, Fcons (value
, Qnil
)));
74 tem
= call1 (predicate
, value
);
82 error ("Attempt to modify read-only object");
86 args_out_of_range (a1
, a2
)
90 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Qnil
)));
94 args_out_of_range_3 (a1
, a2
, a3
)
95 Lisp_Object a1
, a2
, a3
;
98 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Fcons (a3
, Qnil
))));
105 register Lisp_Object val
;
106 XSET (val
, Lisp_Int
, num
);
110 /* On some machines, XINT needs a temporary location.
111 Here it is, in case it is needed. */
113 int sign_extend_temp
;
115 /* On a few machines, XINT can only be done by calling this. */
118 sign_extend_lisp_int (num
)
121 if (num
& (1 << (VALBITS
- 1)))
122 return num
| ((-1) << VALBITS
);
124 return num
& ((1 << VALBITS
) - 1);
127 /* Data type predicates */
129 DEFUN ("eq", Feq
, Seq
, 2, 2, 0,
130 "T if the two args are the same Lisp object.")
132 Lisp_Object obj1
, obj2
;
139 DEFUN ("null", Fnull
, Snull
, 1, 1, 0, "T if OBJECT is nil.")
148 DEFUN ("consp", Fconsp
, Sconsp
, 1, 1, 0, "T if OBJECT is a cons cell.")
152 if (XTYPE (obj
) == Lisp_Cons
)
157 DEFUN ("atom", Fatom
, Satom
, 1, 1, 0, "T if OBJECT is not a cons cell. This includes nil.")
161 if (XTYPE (obj
) == Lisp_Cons
)
166 DEFUN ("listp", Flistp
, Slistp
, 1, 1, 0, "T if OBJECT is a list. This includes nil.")
170 if (XTYPE (obj
) == Lisp_Cons
|| NILP (obj
))
175 DEFUN ("nlistp", Fnlistp
, Snlistp
, 1, 1, 0, "T if OBJECT is not a list. Lists include nil.")
179 if (XTYPE (obj
) == Lisp_Cons
|| NILP (obj
))
184 DEFUN ("symbolp", Fsymbolp
, Ssymbolp
, 1, 1, 0, "T if OBJECT is a symbol.")
188 if (XTYPE (obj
) == Lisp_Symbol
)
193 DEFUN ("vectorp", Fvectorp
, Svectorp
, 1, 1, 0, "T if OBJECT is a vector.")
197 if (XTYPE (obj
) == Lisp_Vector
)
202 DEFUN ("stringp", Fstringp
, Sstringp
, 1, 1, 0, "T if OBJECT is a string.")
206 if (XTYPE (obj
) == Lisp_String
)
211 DEFUN ("arrayp", Farrayp
, Sarrayp
, 1, 1, 0, "T if OBJECT is an array (string or vector).")
215 if (XTYPE (obj
) == Lisp_Vector
|| XTYPE (obj
) == Lisp_String
)
220 DEFUN ("sequencep", Fsequencep
, Ssequencep
, 1, 1, 0,
221 "T if OBJECT is a sequence (list or array).")
223 register Lisp_Object obj
;
225 if (CONSP (obj
) || NILP (obj
) ||
226 XTYPE (obj
) == Lisp_Vector
|| XTYPE (obj
) == Lisp_String
)
231 DEFUN ("bufferp", Fbufferp
, Sbufferp
, 1, 1, 0, "T if OBJECT is an editor buffer.")
235 if (XTYPE (obj
) == Lisp_Buffer
)
240 DEFUN ("markerp", Fmarkerp
, Smarkerp
, 1, 1, 0, "T if OBJECT is a marker (editor pointer).")
244 if (XTYPE (obj
) == Lisp_Marker
)
249 DEFUN ("integer-or-marker-p", Finteger_or_marker_p
, Sinteger_or_marker_p
, 1, 1, 0,
250 "T if OBJECT is an integer or a marker (editor pointer).")
252 register Lisp_Object obj
;
254 if (XTYPE (obj
) == Lisp_Marker
|| XTYPE (obj
) == Lisp_Int
)
259 DEFUN ("subrp", Fsubrp
, Ssubrp
, 1, 1, 0, "T if OBJECT is a built-in function.")
263 if (XTYPE (obj
) == Lisp_Subr
)
268 DEFUN ("compiled-function-p", Fcompiled_function_p
, Scompiled_function_p
,
269 1, 1, 0, "T if OBJECT is a compiled function object.")
273 if (XTYPE (obj
) == Lisp_Compiled
)
278 DEFUN ("char-or-string-p", Fchar_or_string_p
, Schar_or_string_p
, 1, 1, 0, "T if OBJECT is a character (a number) or a string.")
280 register Lisp_Object obj
;
282 if (XTYPE (obj
) == Lisp_Int
|| XTYPE (obj
) == Lisp_String
)
287 DEFUN ("integerp", Fintegerp
, Sintegerp
, 1, 1, 0, "T if OBJECT is a number.")
291 if (XTYPE (obj
) == Lisp_Int
)
296 DEFUN ("natnump", Fnatnump
, Snatnump
, 1, 1, 0, "T if OBJECT is a nonnegative number.")
300 if (XTYPE (obj
) == Lisp_Int
&& XINT (obj
) >= 0)
305 #ifdef LISP_FLOAT_TYPE
306 DEFUN ("floatp", Ffloatp
, Sfloatp
, 1, 1, 0,
307 "T if OBJECT is a floating point number.")
311 if (XTYPE (obj
) == Lisp_Float
)
316 DEFUN ("numberp", Fnumberp
, Snumberp
, 1, 1, 0,
317 "T if OBJECT is a number (floating point or integer).")
321 if (XTYPE (obj
) == Lisp_Float
|| XTYPE (obj
) == Lisp_Int
)
326 DEFUN ("number-or-marker-p", Fnumber_or_marker_p
,
327 Snumber_or_marker_p
, 1, 1, 0,
328 "T if OBJECT is a number or a marker.")
332 if (XTYPE (obj
) == Lisp_Float
333 || XTYPE (obj
) == Lisp_Int
334 || XTYPE (obj
) == Lisp_Marker
)
338 #endif /* LISP_FLOAT_TYPE */
340 /* Extract and set components of lists */
342 DEFUN ("car", Fcar
, Scar
, 1, 1, 0,
343 "Return the car of CONSCELL. If arg is nil, return nil.\n\
344 Error if arg is not nil and not a cons cell. See also `car-safe'.")
346 register Lisp_Object list
;
350 if (XTYPE (list
) == Lisp_Cons
)
351 return XCONS (list
)->car
;
352 else if (EQ (list
, Qnil
))
355 list
= wrong_type_argument (Qlistp
, list
);
359 DEFUN ("car-safe", Fcar_safe
, Scar_safe
, 1, 1, 0,
360 "Return the car of OBJECT if it is a cons cell, or else nil.")
364 if (XTYPE (object
) == Lisp_Cons
)
365 return XCONS (object
)->car
;
370 DEFUN ("cdr", Fcdr
, Scdr
, 1, 1, 0,
371 "Return the cdr of CONSCELL. If arg is nil, return nil.\n\
372 Error if arg is not nil and not a cons cell. See also `cdr-safe'.")
375 register Lisp_Object list
;
379 if (XTYPE (list
) == Lisp_Cons
)
380 return XCONS (list
)->cdr
;
381 else if (EQ (list
, Qnil
))
384 list
= wrong_type_argument (Qlistp
, list
);
388 DEFUN ("cdr-safe", Fcdr_safe
, Scdr_safe
, 1, 1, 0,
389 "Return the cdr of OBJECT if it is a cons cell, or else nil.")
393 if (XTYPE (object
) == Lisp_Cons
)
394 return XCONS (object
)->cdr
;
399 DEFUN ("setcar", Fsetcar
, Ssetcar
, 2, 2, 0,
400 "Set the car of CONSCELL to be NEWCAR. Returns NEWCAR.")
402 register Lisp_Object cell
, newcar
;
404 if (XTYPE (cell
) != Lisp_Cons
)
405 cell
= wrong_type_argument (Qconsp
, cell
);
408 XCONS (cell
)->car
= newcar
;
412 DEFUN ("setcdr", Fsetcdr
, Ssetcdr
, 2, 2, 0,
413 "Set the cdr of CONSCELL to be NEWCDR. Returns NEWCDR.")
415 register Lisp_Object cell
, newcdr
;
417 if (XTYPE (cell
) != Lisp_Cons
)
418 cell
= wrong_type_argument (Qconsp
, cell
);
421 XCONS (cell
)->cdr
= newcdr
;
425 /* Extract and set components of symbols */
427 DEFUN ("boundp", Fboundp
, Sboundp
, 1, 1, 0, "T if SYMBOL's value is not void.")
429 register Lisp_Object sym
;
431 Lisp_Object valcontents
;
432 CHECK_SYMBOL (sym
, 0);
434 valcontents
= XSYMBOL (sym
)->value
;
436 #ifdef SWITCH_ENUM_BUG
437 switch ((int) XTYPE (valcontents
))
439 switch (XTYPE (valcontents
))
442 case Lisp_Buffer_Local_Value
:
443 case Lisp_Some_Buffer_Local_Value
:
444 valcontents
= swap_in_symval_forwarding (sym
, valcontents
);
447 return (XTYPE (valcontents
) == Lisp_Void
|| EQ (valcontents
, Qunbound
)
451 DEFUN ("fboundp", Ffboundp
, Sfboundp
, 1, 1, 0, "T if SYMBOL's function definition is not void.")
453 register Lisp_Object sym
;
455 CHECK_SYMBOL (sym
, 0);
456 return (XTYPE (XSYMBOL (sym
)->function
) == Lisp_Void
457 || EQ (XSYMBOL (sym
)->function
, Qunbound
))
461 DEFUN ("makunbound", Fmakunbound
, Smakunbound
, 1, 1, 0, "Make SYMBOL's value be void.")
463 register Lisp_Object sym
;
465 CHECK_SYMBOL (sym
, 0);
466 if (NILP (sym
) || EQ (sym
, Qt
))
467 return Fsignal (Qsetting_constant
, Fcons (sym
, Qnil
));
468 Fset (sym
, Qunbound
);
472 DEFUN ("fmakunbound", Ffmakunbound
, Sfmakunbound
, 1, 1, 0, "Make SYMBOL's function definition be void.")
474 register Lisp_Object sym
;
476 CHECK_SYMBOL (sym
, 0);
477 XSYMBOL (sym
)->function
= Qunbound
;
481 DEFUN ("symbol-function", Fsymbol_function
, Ssymbol_function
, 1, 1, 0,
482 "Return SYMBOL's function definition. Error if that is void.")
484 register Lisp_Object symbol
;
486 CHECK_SYMBOL (symbol
, 0);
487 if (EQ (XSYMBOL (symbol
)->function
, Qunbound
))
488 return Fsignal (Qvoid_function
, Fcons (symbol
, Qnil
));
489 return XSYMBOL (symbol
)->function
;
492 DEFUN ("symbol-plist", Fsymbol_plist
, Ssymbol_plist
, 1, 1, 0, "Return SYMBOL's property list.")
494 register Lisp_Object sym
;
496 CHECK_SYMBOL (sym
, 0);
497 return XSYMBOL (sym
)->plist
;
500 DEFUN ("symbol-name", Fsymbol_name
, Ssymbol_name
, 1, 1, 0, "Return SYMBOL's name, a string.")
502 register Lisp_Object sym
;
504 register Lisp_Object name
;
506 CHECK_SYMBOL (sym
, 0);
507 XSET (name
, Lisp_String
, XSYMBOL (sym
)->name
);
511 DEFUN ("fset", Ffset
, Sfset
, 2, 2, 0,
512 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.")
514 register Lisp_Object sym
, newdef
;
516 CHECK_SYMBOL (sym
, 0);
517 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (sym
)->function
, Qunbound
))
518 Vautoload_queue
= Fcons (Fcons (sym
, XSYMBOL (sym
)->function
),
520 XSYMBOL (sym
)->function
= newdef
;
524 DEFUN ("setplist", Fsetplist
, Ssetplist
, 2, 2, 0,
525 "Set SYMBOL's property list to NEWVAL, and return NEWVAL.")
527 register Lisp_Object sym
, newplist
;
529 CHECK_SYMBOL (sym
, 0);
530 XSYMBOL (sym
)->plist
= newplist
;
535 /* Getting and setting values of symbols */
537 /* Given the raw contents of a symbol value cell,
538 return the Lisp value of the symbol.
539 This does not handle buffer-local variables; use
540 swap_in_symval_forwarding for that. */
543 do_symval_forwarding (valcontents
)
544 register Lisp_Object valcontents
;
546 register Lisp_Object val
;
547 #ifdef SWITCH_ENUM_BUG
548 switch ((int) XTYPE (valcontents
))
550 switch (XTYPE (valcontents
))
554 XSET (val
, Lisp_Int
, *XINTPTR (valcontents
));
558 if (*XINTPTR (valcontents
))
563 return *XOBJFWD (valcontents
);
565 case Lisp_Buffer_Objfwd
:
566 return *(Lisp_Object
*)(XUINT (valcontents
) + (char *)current_buffer
);
571 /* Store NEWVAL into SYM, where VALCONTENTS is found in the value cell
572 of SYM. If SYM is buffer-local, VALCONTENTS should be the
573 buffer-independent contents of the value cell: forwarded just one
574 step past the buffer-localness. */
577 store_symval_forwarding (sym
, valcontents
, newval
)
579 register Lisp_Object valcontents
, newval
;
581 #ifdef SWITCH_ENUM_BUG
582 switch ((int) XTYPE (valcontents
))
584 switch (XTYPE (valcontents
))
588 CHECK_NUMBER (newval
, 1);
589 *XINTPTR (valcontents
) = XINT (newval
);
593 *XINTPTR (valcontents
) = NILP(newval
) ? 0 : 1;
597 *XOBJFWD (valcontents
) = newval
;
600 case Lisp_Buffer_Objfwd
:
601 *(Lisp_Object
*)(XUINT (valcontents
) + (char *)current_buffer
) = newval
;
605 valcontents
= XSYMBOL (sym
)->value
;
606 if (XTYPE (valcontents
) == Lisp_Buffer_Local_Value
607 || XTYPE (valcontents
) == Lisp_Some_Buffer_Local_Value
)
608 XCONS (XSYMBOL (sym
)->value
)->car
= newval
;
610 XSYMBOL (sym
)->value
= newval
;
614 /* Set up the buffer-local symbol SYM for validity in the current
615 buffer. VALCONTENTS is the contents of its value cell.
616 Return the value forwarded one step past the buffer-local indicator. */
619 swap_in_symval_forwarding (sym
, valcontents
)
620 Lisp_Object sym
, valcontents
;
622 /* valcontents is a list
623 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
625 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
626 local_var_alist, that being the element whose car is this variable.
627 Or it can be a pointer to the (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER
628 does not have an element in its alist for this variable.
630 If the current buffer is not BUFFER, we store the current REALVALUE value into
631 CURRENT-ALIST-ELEMENT, then find the appropriate alist element for
632 the buffer now current and set up CURRENT-ALIST-ELEMENT.
633 Then we set REALVALUE out of that element, and store into BUFFER.
634 Note that REALVALUE can be a forwarding pointer. */
636 register Lisp_Object tem1
;
637 tem1
= XCONS (XCONS (valcontents
)->cdr
)->car
;
639 if (NILP (tem1
) || current_buffer
!= XBUFFER (tem1
))
641 tem1
= XCONS (XCONS (XCONS (valcontents
)->cdr
)->cdr
)->car
;
642 Fsetcdr (tem1
, do_symval_forwarding (XCONS (valcontents
)->car
));
643 tem1
= assq_no_quit (sym
, current_buffer
->local_var_alist
);
645 tem1
= XCONS (XCONS (valcontents
)->cdr
)->cdr
;
646 XCONS (XCONS (XCONS (valcontents
)->cdr
)->cdr
)->car
= tem1
;
647 XSET (XCONS (XCONS (valcontents
)->cdr
)->car
, Lisp_Buffer
, current_buffer
);
648 store_symval_forwarding (sym
, XCONS (valcontents
)->car
, Fcdr (tem1
));
650 return XCONS (valcontents
)->car
;
653 /* Find the value of a symbol, returning Qunbound if it's not bound.
654 This is helpful for code which just wants to get a variable's value
655 if it has one, without signalling an error.
656 Note that it must not be possible to quit
657 within this function. Great care is required for this. */
660 find_symbol_value (sym
)
663 register Lisp_Object valcontents
, tem1
;
664 register Lisp_Object val
;
665 CHECK_SYMBOL (sym
, 0);
666 valcontents
= XSYMBOL (sym
)->value
;
669 #ifdef SWITCH_ENUM_BUG
670 switch ((int) XTYPE (valcontents
))
672 switch (XTYPE (valcontents
))
675 case Lisp_Buffer_Local_Value
:
676 case Lisp_Some_Buffer_Local_Value
:
677 valcontents
= swap_in_symval_forwarding (sym
, valcontents
);
681 XSET (val
, Lisp_Int
, *XINTPTR (valcontents
));
685 if (*XINTPTR (valcontents
))
690 return *XOBJFWD (valcontents
);
692 case Lisp_Buffer_Objfwd
:
693 return *(Lisp_Object
*)(XUINT (valcontents
) + (char *)current_buffer
);
702 DEFUN ("symbol-value", Fsymbol_value
, Ssymbol_value
, 1, 1, 0,
703 "Return SYMBOL's value. Error if that is void.")
707 Lisp_Object val
= find_symbol_value (sym
);
709 if (EQ (val
, Qunbound
))
710 return Fsignal (Qvoid_variable
, Fcons (sym
, Qnil
));
715 DEFUN ("set", Fset
, Sset
, 2, 2, 0,
716 "Set SYMBOL's value to NEWVAL, and return NEWVAL.")
718 register Lisp_Object sym
, newval
;
720 int voide
= (XTYPE (newval
) == Lisp_Void
|| EQ (newval
, Qunbound
));
722 #ifndef RTPC_REGISTER_BUG
723 register Lisp_Object valcontents
, tem1
, current_alist_element
;
724 #else /* RTPC_REGISTER_BUG */
725 register Lisp_Object tem1
;
726 Lisp_Object valcontents
, current_alist_element
;
727 #endif /* RTPC_REGISTER_BUG */
729 CHECK_SYMBOL (sym
, 0);
730 if (NILP (sym
) || EQ (sym
, Qt
))
731 return Fsignal (Qsetting_constant
, Fcons (sym
, Qnil
));
732 valcontents
= XSYMBOL (sym
)->value
;
734 if (XTYPE (valcontents
) == Lisp_Buffer_Objfwd
)
736 register int idx
= XUINT (valcontents
);
737 register int mask
= *(int *)(idx
+ (char *) &buffer_local_flags
);
739 current_buffer
->local_var_flags
|= mask
;
742 if (XTYPE (valcontents
) == Lisp_Buffer_Local_Value
743 || XTYPE (valcontents
) == Lisp_Some_Buffer_Local_Value
)
745 /* valcontents is a list
746 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
748 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
749 local_var_alist, that being the element whose car is this variable.
750 Or it can be a pointer to the (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER
751 does not have an element in its alist for this variable.
753 If the current buffer is not BUFFER, we store the current REALVALUE value into
754 CURRENT-ALIST-ELEMENT, then find the appropriate alist element for
755 the buffer now current and set up CURRENT-ALIST-ELEMENT.
756 Then we set REALVALUE out of that element, and store into BUFFER.
757 Note that REALVALUE can be a forwarding pointer. */
759 current_alist_element
= XCONS (XCONS (XCONS (valcontents
)->cdr
)->cdr
)->car
;
760 if (current_buffer
!= ((XTYPE (valcontents
) == Lisp_Some_Buffer_Local_Value
)
761 ? XBUFFER (XCONS (XCONS (valcontents
)->cdr
)->car
)
762 : XBUFFER (XCONS (current_alist_element
)->car
)))
764 Fsetcdr (current_alist_element
, do_symval_forwarding (XCONS (valcontents
)->car
));
766 tem1
= Fassq (sym
, current_buffer
->local_var_alist
);
768 /* This buffer sees the default value still.
769 If type is Lisp_Some_Buffer_Local_Value, set the default value.
770 If type is Lisp_Buffer_Local_Value, give this buffer a local value
772 if (XTYPE (valcontents
) == Lisp_Some_Buffer_Local_Value
)
773 tem1
= XCONS (XCONS (valcontents
)->cdr
)->cdr
;
776 tem1
= Fcons (sym
, Fcdr (current_alist_element
));
777 current_buffer
->local_var_alist
= Fcons (tem1
, current_buffer
->local_var_alist
);
779 XCONS (XCONS (XCONS (valcontents
)->cdr
)->cdr
)->car
= tem1
;
780 XSET (XCONS (XCONS (valcontents
)->cdr
)->car
, Lisp_Buffer
, current_buffer
);
782 valcontents
= XCONS (valcontents
)->car
;
784 /* If storing void (making the symbol void), forward only through
785 buffer-local indicator, not through Lisp_Objfwd, etc. */
787 store_symval_forwarding (sym
, Qnil
, newval
);
789 store_symval_forwarding (sym
, valcontents
, newval
);
793 /* Access or set a buffer-local symbol's default value. */
795 /* Return the default value of SYM, but don't check for voidness.
796 Return Qunbound or a Lisp_Void object if it is void. */
802 register Lisp_Object valcontents
;
804 CHECK_SYMBOL (sym
, 0);
805 valcontents
= XSYMBOL (sym
)->value
;
807 /* For a built-in buffer-local variable, get the default value
808 rather than letting do_symval_forwarding get the current value. */
809 if (XTYPE (valcontents
) == Lisp_Buffer_Objfwd
)
811 register int idx
= XUINT (valcontents
);
813 if (*(int *) (idx
+ (char *) &buffer_local_flags
) != 0)
814 return *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
);
817 /* Handle user-created local variables. */
818 if (XTYPE (valcontents
) == Lisp_Buffer_Local_Value
819 || XTYPE (valcontents
) == Lisp_Some_Buffer_Local_Value
)
821 /* If var is set up for a buffer that lacks a local value for it,
822 the current value is nominally the default value.
823 But the current value slot may be more up to date, since
824 ordinary setq stores just that slot. So use that. */
825 Lisp_Object current_alist_element
, alist_element_car
;
826 current_alist_element
827 = XCONS (XCONS (XCONS (valcontents
)->cdr
)->cdr
)->car
;
828 alist_element_car
= XCONS (current_alist_element
)->car
;
829 if (EQ (alist_element_car
, current_alist_element
))
830 return do_symval_forwarding (XCONS (valcontents
)->car
);
832 return XCONS (XCONS (XCONS (valcontents
)->cdr
)->cdr
)->cdr
;
834 /* For other variables, get the current value. */
835 return do_symval_forwarding (valcontents
);
838 DEFUN ("default-boundp", Fdefault_boundp
, Sdefault_boundp
, 1, 1, 0,
839 "Return T if SYMBOL has a non-void default value.\n\
840 This is the value that is seen in buffers that do not have their own values\n\
845 register Lisp_Object value
;
847 value
= default_value (sym
);
848 return (XTYPE (value
) == Lisp_Void
|| EQ (value
, Qunbound
)
852 DEFUN ("default-value", Fdefault_value
, Sdefault_value
, 1, 1, 0,
853 "Return SYMBOL's default value.\n\
854 This is the value that is seen in buffers that do not have their own values\n\
855 for this variable. The default value is meaningful for variables with\n\
856 local bindings in certain buffers.")
860 register Lisp_Object value
;
862 value
= default_value (sym
);
863 if (XTYPE (value
) == Lisp_Void
|| EQ (value
, Qunbound
))
864 return Fsignal (Qvoid_variable
, Fcons (sym
, Qnil
));
868 DEFUN ("set-default", Fset_default
, Sset_default
, 2, 2, 0,
869 "Set SYMBOL's default value to VAL. SYMBOL and VAL are evaluated.\n\
870 The default value is seen in buffers that do not have their own values\n\
873 Lisp_Object sym
, value
;
875 register Lisp_Object valcontents
, current_alist_element
, alist_element_buffer
;
877 CHECK_SYMBOL (sym
, 0);
878 valcontents
= XSYMBOL (sym
)->value
;
880 /* Handle variables like case-fold-search that have special slots
881 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
883 if (XTYPE (valcontents
) == Lisp_Buffer_Objfwd
)
885 register int idx
= XUINT (valcontents
);
886 #ifndef RTPC_REGISTER_BUG
887 register struct buffer
*b
;
891 register int mask
= *(int *) (idx
+ (char *) &buffer_local_flags
);
895 *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
) = value
;
896 for (b
= all_buffers
; b
; b
= b
->next
)
897 if (!(b
->local_var_flags
& mask
))
898 *(Lisp_Object
*)(idx
+ (char *) b
) = value
;
903 if (XTYPE (valcontents
) != Lisp_Buffer_Local_Value
&&
904 XTYPE (valcontents
) != Lisp_Some_Buffer_Local_Value
)
905 return Fset (sym
, value
);
907 /* Store new value into the DEFAULT-VALUE slot */
908 XCONS (XCONS (XCONS (valcontents
)->cdr
)->cdr
)->cdr
= value
;
910 /* If that slot is current, we must set the REALVALUE slot too */
911 current_alist_element
= XCONS (XCONS (XCONS (valcontents
)->cdr
)->cdr
)->car
;
912 alist_element_buffer
= Fcar (current_alist_element
);
913 if (EQ (alist_element_buffer
, current_alist_element
))
914 store_symval_forwarding (sym
, XCONS (valcontents
)->car
, value
);
919 DEFUN ("setq-default", Fsetq_default
, Ssetq_default
, 2, UNEVALLED
, 0,
921 (setq-default SYM VAL SYM VAL ...): set each SYM's default value to its VAL.\n\
922 VAL is evaluated; SYM is not. The default value is seen in buffers that do\n\
923 not have their own values for this variable.")
927 register Lisp_Object args_left
;
928 register Lisp_Object val
, sym
;
939 val
= Feval (Fcar (Fcdr (args_left
)));
940 sym
= Fcar (args_left
);
941 Fset_default (sym
, val
);
942 args_left
= Fcdr (Fcdr (args_left
));
944 while (!NILP (args_left
));
950 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local
, Smake_variable_buffer_local
,
951 1, 1, "vMake Variable Buffer Local: ",
952 "Make VARIABLE have a separate value for each buffer.\n\
953 At any time, the value for the current buffer is in effect.\n\
954 There is also a default value which is seen in any buffer which has not yet\n\
955 set its own value.\n\
956 Using `set' or `setq' to set the variable causes it to have a separate value\n\
957 for the current buffer if it was previously using the default value.\n\
958 The function `default-value' gets the default value and `set-default' sets it.")
960 register Lisp_Object sym
;
962 register Lisp_Object tem
, valcontents
;
964 CHECK_SYMBOL (sym
, 0);
966 if (EQ (sym
, Qnil
) || EQ (sym
, Qt
))
967 error ("Symbol %s may not be buffer-local", XSYMBOL (sym
)->name
->data
);
969 valcontents
= XSYMBOL (sym
)->value
;
970 if ((XTYPE (valcontents
) == Lisp_Buffer_Local_Value
) ||
971 (XTYPE (valcontents
) == Lisp_Buffer_Objfwd
))
973 if (XTYPE (valcontents
) == Lisp_Some_Buffer_Local_Value
)
975 XSETTYPE (XSYMBOL (sym
)->value
, Lisp_Buffer_Local_Value
);
978 if (EQ (valcontents
, Qunbound
))
979 XSYMBOL (sym
)->value
= Qnil
;
980 tem
= Fcons (Qnil
, Fsymbol_value (sym
));
981 XCONS (tem
)->car
= tem
;
982 XSYMBOL (sym
)->value
= Fcons (XSYMBOL (sym
)->value
, Fcons (Fcurrent_buffer (), tem
));
983 XSETTYPE (XSYMBOL (sym
)->value
, Lisp_Buffer_Local_Value
);
987 DEFUN ("make-local-variable", Fmake_local_variable
, Smake_local_variable
,
988 1, 1, "vMake Local Variable: ",
989 "Make VARIABLE have a separate value in the current buffer.\n\
990 Other buffers will continue to share a common default value.\n\
991 See also `make-variable-buffer-local'.\n\n\
992 If the variable is already arranged to become local when set,\n\
993 this function causes a local value to exist for this buffer,\n\
994 just as if the variable were set.")
996 register Lisp_Object sym
;
998 register Lisp_Object tem
, valcontents
;
1000 CHECK_SYMBOL (sym
, 0);
1002 if (EQ (sym
, Qnil
) || EQ (sym
, Qt
))
1003 error ("Symbol %s may not be buffer-local", XSYMBOL (sym
)->name
->data
);
1005 valcontents
= XSYMBOL (sym
)->value
;
1006 if (XTYPE (valcontents
) == Lisp_Buffer_Local_Value
1007 || XTYPE (valcontents
) == Lisp_Buffer_Objfwd
)
1009 tem
= Fboundp (sym
);
1011 /* Make sure the symbol has a local value in this particular buffer,
1012 by setting it to the same value it already has. */
1013 Fset (sym
, (EQ (tem
, Qt
) ? Fsymbol_value (sym
) : Qunbound
));
1016 /* Make sure sym is set up to hold per-buffer values */
1017 if (XTYPE (valcontents
) != Lisp_Some_Buffer_Local_Value
)
1019 if (EQ (valcontents
, Qunbound
))
1020 XSYMBOL (sym
)->value
= Qnil
;
1021 tem
= Fcons (Qnil
, do_symval_forwarding (valcontents
));
1022 XCONS (tem
)->car
= tem
;
1023 XSYMBOL (sym
)->value
= Fcons (XSYMBOL (sym
)->value
, Fcons (Qnil
, tem
));
1024 XSETTYPE (XSYMBOL (sym
)->value
, Lisp_Some_Buffer_Local_Value
);
1026 /* Make sure this buffer has its own value of sym */
1027 tem
= Fassq (sym
, current_buffer
->local_var_alist
);
1030 current_buffer
->local_var_alist
1031 = Fcons (Fcons (sym
, XCONS (XCONS (XCONS (XSYMBOL (sym
)->value
)->cdr
)->cdr
)->cdr
),
1032 current_buffer
->local_var_alist
);
1034 /* Make sure symbol does not think it is set up for this buffer;
1035 force it to look once again for this buffer's value */
1037 /* This local variable avoids "expression too complex" on IBM RT. */
1040 xs
= XSYMBOL (sym
)->value
;
1041 if (current_buffer
== XBUFFER (XCONS (XCONS (xs
)->cdr
)->car
))
1042 XCONS (XCONS (XSYMBOL (sym
)->value
)->cdr
)->car
= Qnil
;
1049 DEFUN ("kill-local-variable", Fkill_local_variable
, Skill_local_variable
,
1050 1, 1, "vKill Local Variable: ",
1051 "Make VARIABLE no longer have a separate value in the current buffer.\n\
1052 From now on the default value will apply in this buffer.")
1054 register Lisp_Object sym
;
1056 register Lisp_Object tem
, valcontents
;
1058 CHECK_SYMBOL (sym
, 0);
1060 valcontents
= XSYMBOL (sym
)->value
;
1062 if (XTYPE (valcontents
) == Lisp_Buffer_Objfwd
)
1064 register int idx
= XUINT (valcontents
);
1065 register int mask
= *(int *) (idx
+ (char *) &buffer_local_flags
);
1069 *(Lisp_Object
*)(idx
+ (char *) current_buffer
)
1070 = *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
);
1071 current_buffer
->local_var_flags
&= ~mask
;
1076 if (XTYPE (valcontents
) != Lisp_Buffer_Local_Value
&&
1077 XTYPE (valcontents
) != Lisp_Some_Buffer_Local_Value
)
1080 /* Get rid of this buffer's alist element, if any */
1082 tem
= Fassq (sym
, current_buffer
->local_var_alist
);
1084 current_buffer
->local_var_alist
= Fdelq (tem
, current_buffer
->local_var_alist
);
1086 /* Make sure symbol does not think it is set up for this buffer;
1087 force it to look once again for this buffer's value */
1090 sv
= XSYMBOL (sym
)->value
;
1091 if (current_buffer
== XBUFFER (XCONS (XCONS (sv
)->cdr
)->car
))
1092 XCONS (XCONS (sv
)->cdr
)->car
= Qnil
;
1098 /* Find the function at the end of a chain of symbol function indirections. */
1100 /* If OBJECT is a symbol, find the end of its function chain and
1101 return the value found there. If OBJECT is not a symbol, just
1102 return it. If there is a cycle in the function chain, signal a
1103 cyclic-function-indirection error.
1105 This is like Findirect_function, except that it doesn't signal an
1106 error if the chain ends up unbound. */
1108 indirect_function (object
, error
)
1109 register Lisp_Object object
;
1111 Lisp_Object tortise
, hare
;
1113 hare
= tortise
= object
;
1117 if (XTYPE (hare
) != Lisp_Symbol
|| EQ (hare
, Qunbound
))
1119 hare
= XSYMBOL (hare
)->function
;
1120 if (XTYPE (hare
) != Lisp_Symbol
|| EQ (hare
, Qunbound
))
1122 hare
= XSYMBOL (hare
)->function
;
1124 tortise
= XSYMBOL (tortise
)->function
;
1126 if (EQ (hare
, tortise
))
1127 Fsignal (Qcyclic_function_indirection
, Fcons (object
, Qnil
));
1133 DEFUN ("indirect-function", Findirect_function
, Sindirect_function
, 1, 1, 0,
1134 "Return the function at the end of OBJECT's function chain.\n\
1135 If OBJECT is a symbol, follow all function indirections and return the final\n\
1136 function binding.\n\
1137 If OBJECT is not a symbol, just return it.\n\
1138 Signal a void-function error if the final symbol is unbound.\n\
1139 Signal a cyclic-function-indirection error if there is a loop in the\n\
1140 function chain of symbols.")
1142 register Lisp_Object object
;
1146 result
= indirect_function (object
);
1148 if (EQ (result
, Qunbound
))
1149 return Fsignal (Qvoid_function
, Fcons (object
, Qnil
));
1153 /* Extract and set vector and string elements */
1155 DEFUN ("aref", Faref
, Saref
, 2, 2, 0,
1156 "Return the element of ARRAY at index INDEX.\n\
1157 ARRAY may be a vector or a string, or a byte-code object. INDEX starts at 0.")
1159 register Lisp_Object array
;
1162 register int idxval
;
1164 CHECK_NUMBER (idx
, 1);
1165 idxval
= XINT (idx
);
1166 if (XTYPE (array
) != Lisp_Vector
&& XTYPE (array
) != Lisp_String
1167 && XTYPE (array
) != Lisp_Compiled
)
1168 array
= wrong_type_argument (Qarrayp
, array
);
1169 if (idxval
< 0 || idxval
>= XVECTOR (array
)->size
)
1170 args_out_of_range (array
, idx
);
1171 if (XTYPE (array
) == Lisp_String
)
1174 XFASTINT (val
) = (unsigned char) XSTRING (array
)->data
[idxval
];
1178 return XVECTOR (array
)->contents
[idxval
];
1181 DEFUN ("aset", Faset
, Saset
, 3, 3, 0,
1182 "Store into the element of ARRAY at index INDEX the value NEWVAL.\n\
1183 ARRAY may be a vector or a string. INDEX starts at 0.")
1184 (array
, idx
, newelt
)
1185 register Lisp_Object array
;
1186 Lisp_Object idx
, newelt
;
1188 register int idxval
;
1190 CHECK_NUMBER (idx
, 1);
1191 idxval
= XINT (idx
);
1192 if (XTYPE (array
) != Lisp_Vector
&& XTYPE (array
) != Lisp_String
)
1193 array
= wrong_type_argument (Qarrayp
, array
);
1194 if (idxval
< 0 || idxval
>= XVECTOR (array
)->size
)
1195 args_out_of_range (array
, idx
);
1196 CHECK_IMPURE (array
);
1198 if (XTYPE (array
) == Lisp_Vector
)
1199 XVECTOR (array
)->contents
[idxval
] = newelt
;
1202 CHECK_NUMBER (newelt
, 2);
1203 XSTRING (array
)->data
[idxval
] = XINT (newelt
);
1210 Farray_length (array
)
1211 register Lisp_Object array
;
1213 register Lisp_Object size
;
1214 if (XTYPE (array
) != Lisp_Vector
&& XTYPE (array
) != Lisp_String
1215 && XTYPE (array
) != Lisp_Compiled
)
1216 array
= wrong_type_argument (Qarrayp
, array
);
1217 XFASTINT (size
) = XVECTOR (array
)->size
;
1221 /* Arithmetic functions */
1223 enum comparison
{ equal
, notequal
, less
, grtr
, less_or_equal
, grtr_or_equal
};
1226 arithcompare (num1
, num2
, comparison
)
1227 Lisp_Object num1
, num2
;
1228 enum comparison comparison
;
1233 #ifdef LISP_FLOAT_TYPE
1234 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1
, 0);
1235 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2
, 0);
1237 if (XTYPE (num1
) == Lisp_Float
|| XTYPE (num2
) == Lisp_Float
)
1240 f1
= (XTYPE (num1
) == Lisp_Float
) ? XFLOAT (num1
)->data
: XINT (num1
);
1241 f2
= (XTYPE (num2
) == Lisp_Float
) ? XFLOAT (num2
)->data
: XINT (num2
);
1244 CHECK_NUMBER_COERCE_MARKER (num1
, 0);
1245 CHECK_NUMBER_COERCE_MARKER (num2
, 0);
1246 #endif /* LISP_FLOAT_TYPE */
1251 if (floatp
? f1
== f2
: XINT (num1
) == XINT (num2
))
1256 if (floatp
? f1
!= f2
: XINT (num1
) != XINT (num2
))
1261 if (floatp
? f1
< f2
: XINT (num1
) < XINT (num2
))
1266 if (floatp
? f1
<= f2
: XINT (num1
) <= XINT (num2
))
1271 if (floatp
? f1
> f2
: XINT (num1
) > XINT (num2
))
1276 if (floatp
? f1
>= f2
: XINT (num1
) >= XINT (num2
))
1282 DEFUN ("=", Feqlsign
, Seqlsign
, 2, 2, 0,
1283 "T if two args, both numbers or markers, are equal.")
1285 register Lisp_Object num1
, num2
;
1287 return arithcompare (num1
, num2
, equal
);
1290 DEFUN ("<", Flss
, Slss
, 2, 2, 0,
1291 "T if first arg is less than second arg. Both must be numbers or markers.")
1293 register Lisp_Object num1
, num2
;
1295 return arithcompare (num1
, num2
, less
);
1298 DEFUN (">", Fgtr
, Sgtr
, 2, 2, 0,
1299 "T if first arg is greater than second arg. Both must be numbers or markers.")
1301 register Lisp_Object num1
, num2
;
1303 return arithcompare (num1
, num2
, grtr
);
1306 DEFUN ("<=", Fleq
, Sleq
, 2, 2, 0,
1307 "T if first arg is less than or equal to second arg.\n\
1308 Both must be numbers or markers.")
1310 register Lisp_Object num1
, num2
;
1312 return arithcompare (num1
, num2
, less_or_equal
);
1315 DEFUN (">=", Fgeq
, Sgeq
, 2, 2, 0,
1316 "T if first arg is greater than or equal to second arg.\n\
1317 Both must be numbers or markers.")
1319 register Lisp_Object num1
, num2
;
1321 return arithcompare (num1
, num2
, grtr_or_equal
);
1324 DEFUN ("/=", Fneq
, Sneq
, 2, 2, 0,
1325 "T if first arg is not equal to second arg. Both must be numbers or markers.")
1327 register Lisp_Object num1
, num2
;
1329 return arithcompare (num1
, num2
, notequal
);
1332 DEFUN ("zerop", Fzerop
, Szerop
, 1, 1, 0, "T if NUMBER is zero.")
1334 register Lisp_Object num
;
1336 #ifdef LISP_FLOAT_TYPE
1337 CHECK_NUMBER_OR_FLOAT (num
, 0);
1339 if (XTYPE(num
) == Lisp_Float
)
1341 if (XFLOAT(num
)->data
== 0.0)
1346 CHECK_NUMBER (num
, 0);
1347 #endif /* LISP_FLOAT_TYPE */
1354 DEFUN ("int-to-string", Fint_to_string
, Sint_to_string
, 1, 1, 0,
1355 "Convert INT to a string by printing it in decimal.\n\
1356 Uses a minus sign if negative.")
1362 #ifndef LISP_FLOAT_TYPE
1363 CHECK_NUMBER (num
, 0);
1365 CHECK_NUMBER_OR_FLOAT (num
, 0);
1367 if (XTYPE(num
) == Lisp_Float
)
1369 char pigbuf
[350]; /* see comments in float_to_string */
1371 float_to_string (pigbuf
, XFLOAT(num
)->data
);
1372 return build_string (pigbuf
);
1374 #endif /* LISP_FLOAT_TYPE */
1376 sprintf (buffer
, "%d", XINT (num
));
1377 return build_string (buffer
);
1380 DEFUN ("string-to-int", Fstring_to_int
, Sstring_to_int
, 1, 1, 0,
1381 "Convert STRING to an integer by parsing it as a decimal number.")
1383 register Lisp_Object str
;
1385 CHECK_STRING (str
, 0);
1387 #ifdef LISP_FLOAT_TYPE
1388 if (isfloat_string (XSTRING (str
)->data
))
1389 return make_float (atof (XSTRING (str
)->data
));
1390 #endif /* LISP_FLOAT_TYPE */
1392 return make_number (atoi (XSTRING (str
)->data
));
1396 { Aadd
, Asub
, Amult
, Adiv
, Alogand
, Alogior
, Alogxor
, Amax
, Amin
};
1403 register Lisp_Object
*args
;
1405 register Lisp_Object val
;
1406 register int argnum
;
1410 #ifdef SWITCH_ENUM_BUG
1427 for (argnum
= 0; argnum
< nargs
; argnum
++)
1429 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
1430 #ifdef LISP_FLOAT_TYPE
1431 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
1433 if (XTYPE (val
) == Lisp_Float
) /* time to do serious math */
1434 return (float_arith_driver ((double) accum
, argnum
, code
,
1437 CHECK_NUMBER_COERCE_MARKER (val
, argnum
);
1438 #endif /* LISP_FLOAT_TYPE */
1439 args
[argnum
] = val
; /* runs into a compiler bug. */
1440 next
= XINT (args
[argnum
]);
1441 #ifdef SWITCH_ENUM_BUG
1447 case Aadd
: accum
+= next
; break;
1449 if (!argnum
&& nargs
!= 1)
1453 case Amult
: accum
*= next
; break;
1455 if (!argnum
) accum
= next
;
1458 case Alogand
: accum
&= next
; break;
1459 case Alogior
: accum
|= next
; break;
1460 case Alogxor
: accum
^= next
; break;
1461 case Amax
: if (!argnum
|| next
> accum
) accum
= next
; break;
1462 case Amin
: if (!argnum
|| next
< accum
) accum
= next
; break;
1466 XSET (val
, Lisp_Int
, accum
);
1470 #ifdef LISP_FLOAT_TYPE
1472 float_arith_driver (accum
, argnum
, code
, nargs
, args
)
1474 register int argnum
;
1477 register Lisp_Object
*args
;
1479 register Lisp_Object val
;
1482 for (; argnum
< nargs
; argnum
++)
1484 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
1485 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
1487 if (XTYPE (val
) == Lisp_Float
)
1489 next
= XFLOAT (val
)->data
;
1493 args
[argnum
] = val
; /* runs into a compiler bug. */
1494 next
= XINT (args
[argnum
]);
1496 #ifdef SWITCH_ENUM_BUG
1506 if (!argnum
&& nargs
!= 1)
1522 return wrong_type_argument (Qinteger_or_marker_p
, val
);
1524 if (!argnum
|| next
> accum
)
1528 if (!argnum
|| next
< accum
)
1534 return make_float (accum
);
1536 #endif /* LISP_FLOAT_TYPE */
1538 DEFUN ("+", Fplus
, Splus
, 0, MANY
, 0,
1539 "Return sum of any number of arguments, which are numbers or markers.")
1544 return arith_driver (Aadd
, nargs
, args
);
1547 DEFUN ("-", Fminus
, Sminus
, 0, MANY
, 0,
1548 "Negate number or subtract numbers or markers.\n\
1549 With one arg, negates it. With more than one arg,\n\
1550 subtracts all but the first from the first.")
1555 return arith_driver (Asub
, nargs
, args
);
1558 DEFUN ("*", Ftimes
, Stimes
, 0, MANY
, 0,
1559 "Returns product of any number of arguments, which are numbers or markers.")
1564 return arith_driver (Amult
, nargs
, args
);
1567 DEFUN ("/", Fquo
, Squo
, 2, MANY
, 0,
1568 "Returns first argument divided by all the remaining arguments.\n\
1569 The arguments must be numbers or markers.")
1574 return arith_driver (Adiv
, nargs
, args
);
1577 DEFUN ("%", Frem
, Srem
, 2, 2, 0,
1578 "Returns remainder of first arg divided by second.\n\
1579 Both must be numbers or markers.")
1581 register Lisp_Object num1
, num2
;
1585 #ifdef LISP_FLOAT_TYPE
1586 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1
, 0);
1587 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2
, 0);
1589 if (XTYPE (num1
) == Lisp_Float
|| XTYPE (num2
) == Lisp_Float
)
1593 f1
= XTYPE (num1
) == Lisp_Float
? XFLOAT (num1
)->data
: XINT (num1
);
1594 f2
= XTYPE (num2
) == Lisp_Float
? XFLOAT (num2
)->data
: XINT (num2
);
1595 return (make_float (drem (f1
,f2
)));
1597 #else /* not LISP_FLOAT_TYPE */
1598 CHECK_NUMBER_COERCE_MARKER (num1
, 0);
1599 CHECK_NUMBER_COERCE_MARKER (num2
, 1);
1600 #endif /* not LISP_FLOAT_TYPE */
1602 XSET (val
, Lisp_Int
, XINT (num1
) % XINT (num2
));
1606 DEFUN ("max", Fmax
, Smax
, 1, MANY
, 0,
1607 "Return largest of all the arguments (which must be numbers or markers).\n\
1608 The value is always a number; markers are converted to numbers.")
1613 return arith_driver (Amax
, nargs
, args
);
1616 DEFUN ("min", Fmin
, Smin
, 1, MANY
, 0,
1617 "Return smallest of all the arguments (which must be numbers or markers).\n\
1618 The value is always a number; markers are converted to numbers.")
1623 return arith_driver (Amin
, nargs
, args
);
1626 DEFUN ("logand", Flogand
, Slogand
, 0, MANY
, 0,
1627 "Return bitwise-and of all the arguments.\n\
1628 Arguments may be integers, or markers converted to integers.")
1633 return arith_driver (Alogand
, nargs
, args
);
1636 DEFUN ("logior", Flogior
, Slogior
, 0, MANY
, 0,
1637 "Return bitwise-or of all the arguments.\n\
1638 Arguments may be integers, or markers converted to integers.")
1643 return arith_driver (Alogior
, nargs
, args
);
1646 DEFUN ("logxor", Flogxor
, Slogxor
, 0, MANY
, 0,
1647 "Return bitwise-exclusive-or of all the arguments.\n\
1648 Arguments may be integers, or markers converted to integers.")
1653 return arith_driver (Alogxor
, nargs
, args
);
1656 DEFUN ("ash", Fash
, Sash
, 2, 2, 0,
1657 "Return VALUE with its bits shifted left by COUNT.\n\
1658 If COUNT is negative, shifting is actually to the right.\n\
1659 In this case, the sign bit is duplicated.")
1661 register Lisp_Object num1
, num2
;
1663 register Lisp_Object val
;
1665 CHECK_NUMBER (num1
, 0);
1666 CHECK_NUMBER (num2
, 1);
1668 if (XINT (num2
) > 0)
1669 XSET (val
, Lisp_Int
, XINT (num1
) << XFASTINT (num2
));
1671 XSET (val
, Lisp_Int
, XINT (num1
) >> -XINT (num2
));
1675 DEFUN ("lsh", Flsh
, Slsh
, 2, 2, 0,
1676 "Return VALUE with its bits shifted left by COUNT.\n\
1677 If COUNT is negative, shifting is actually to the right.\n\
1678 In this case, zeros are shifted in on the left.")
1680 register Lisp_Object num1
, num2
;
1682 register Lisp_Object val
;
1684 CHECK_NUMBER (num1
, 0);
1685 CHECK_NUMBER (num2
, 1);
1687 if (XINT (num2
) > 0)
1688 XSET (val
, Lisp_Int
, (unsigned) XFASTINT (num1
) << XFASTINT (num2
));
1690 XSET (val
, Lisp_Int
, (unsigned) XFASTINT (num1
) >> -XINT (num2
));
1694 DEFUN ("1+", Fadd1
, Sadd1
, 1, 1, 0,
1695 "Return NUMBER plus one. NUMBER may be a number or a marker.\n\
1696 Markers are converted to integers.")
1698 register Lisp_Object num
;
1700 #ifdef LISP_FLOAT_TYPE
1701 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num
, 0);
1703 if (XTYPE (num
) == Lisp_Float
)
1704 return (make_float (1.0 + XFLOAT (num
)->data
));
1706 CHECK_NUMBER_COERCE_MARKER (num
, 0);
1707 #endif /* LISP_FLOAT_TYPE */
1709 XSETINT (num
, XFASTINT (num
) + 1);
1713 DEFUN ("1-", Fsub1
, Ssub1
, 1, 1, 0,
1714 "Return NUMBER minus one. NUMBER may be a number or a marker.\n\
1715 Markers are converted to integers.")
1717 register Lisp_Object num
;
1719 #ifdef LISP_FLOAT_TYPE
1720 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num
, 0);
1722 if (XTYPE (num
) == Lisp_Float
)
1723 return (make_float (-1.0 + XFLOAT (num
)->data
));
1725 CHECK_NUMBER_COERCE_MARKER (num
, 0);
1726 #endif /* LISP_FLOAT_TYPE */
1728 XSETINT (num
, XFASTINT (num
) - 1);
1732 DEFUN ("lognot", Flognot
, Slognot
, 1, 1, 0,
1733 "Return the bitwise complement of ARG. ARG must be an integer.")
1735 register Lisp_Object num
;
1737 CHECK_NUMBER (num
, 0);
1738 XSETINT (num
, ~XFASTINT (num
));
1745 Qquote
= intern ("quote");
1746 Qlambda
= intern ("lambda");
1747 Qsubr
= intern ("subr");
1748 Qerror_conditions
= intern ("error-conditions");
1749 Qerror_message
= intern ("error-message");
1750 Qtop_level
= intern ("top-level");
1752 Qerror
= intern ("error");
1753 Qquit
= intern ("quit");
1754 Qwrong_type_argument
= intern ("wrong-type-argument");
1755 Qargs_out_of_range
= intern ("args-out-of-range");
1756 Qvoid_function
= intern ("void-function");
1757 Qcyclic_function_indirection
= intern ("cyclic-function-indirection");
1758 Qvoid_variable
= intern ("void-variable");
1759 Qsetting_constant
= intern ("setting-constant");
1760 Qinvalid_read_syntax
= intern ("invalid-read-syntax");
1762 Qinvalid_function
= intern ("invalid-function");
1763 Qwrong_number_of_arguments
= intern ("wrong-number-of-arguments");
1764 Qno_catch
= intern ("no-catch");
1765 Qend_of_file
= intern ("end-of-file");
1766 Qarith_error
= intern ("arith-error");
1767 Qbeginning_of_buffer
= intern ("beginning-of-buffer");
1768 Qend_of_buffer
= intern ("end-of-buffer");
1769 Qbuffer_read_only
= intern ("buffer-read-only");
1771 Qlistp
= intern ("listp");
1772 Qconsp
= intern ("consp");
1773 Qsymbolp
= intern ("symbolp");
1774 Qintegerp
= intern ("integerp");
1775 Qnatnump
= intern ("natnump");
1776 Qstringp
= intern ("stringp");
1777 Qarrayp
= intern ("arrayp");
1778 Qsequencep
= intern ("sequencep");
1779 Qbufferp
= intern ("bufferp");
1780 Qvectorp
= intern ("vectorp");
1781 Qchar_or_string_p
= intern ("char-or-string-p");
1782 Qmarkerp
= intern ("markerp");
1783 Qinteger_or_marker_p
= intern ("integer-or-marker-p");
1784 Qboundp
= intern ("boundp");
1785 Qfboundp
= intern ("fboundp");
1787 #ifdef LISP_FLOAT_TYPE
1788 Qfloatp
= intern ("floatp");
1789 Qnumberp
= intern ("numberp");
1790 Qnumber_or_marker_p
= intern ("number-or-marker-p");
1791 #endif /* LISP_FLOAT_TYPE */
1793 Qcdr
= intern ("cdr");
1795 /* ERROR is used as a signaler for random errors for which nothing else is right */
1797 Fput (Qerror
, Qerror_conditions
,
1798 Fcons (Qerror
, Qnil
));
1799 Fput (Qerror
, Qerror_message
,
1800 build_string ("error"));
1802 Fput (Qquit
, Qerror_conditions
,
1803 Fcons (Qquit
, Qnil
));
1804 Fput (Qquit
, Qerror_message
,
1805 build_string ("Quit"));
1807 Fput (Qwrong_type_argument
, Qerror_conditions
,
1808 Fcons (Qwrong_type_argument
, Fcons (Qerror
, Qnil
)));
1809 Fput (Qwrong_type_argument
, Qerror_message
,
1810 build_string ("Wrong type argument"));
1812 Fput (Qargs_out_of_range
, Qerror_conditions
,
1813 Fcons (Qargs_out_of_range
, Fcons (Qerror
, Qnil
)));
1814 Fput (Qargs_out_of_range
, Qerror_message
,
1815 build_string ("Args out of range"));
1817 Fput (Qvoid_function
, Qerror_conditions
,
1818 Fcons (Qvoid_function
, Fcons (Qerror
, Qnil
)));
1819 Fput (Qvoid_function
, Qerror_message
,
1820 build_string ("Symbol's function definition is void"));
1822 Fput (Qcyclic_function_indirection
, Qerror_conditions
,
1823 Fcons (Qcyclic_function_indirection
, Fcons (Qerror
, Qnil
)));
1824 Fput (Qcyclic_function_indirection
, Qerror_message
,
1825 build_string ("Symbol's chain of function indirections contains a loop"));
1827 Fput (Qvoid_variable
, Qerror_conditions
,
1828 Fcons (Qvoid_variable
, Fcons (Qerror
, Qnil
)));
1829 Fput (Qvoid_variable
, Qerror_message
,
1830 build_string ("Symbol's value as variable is void"));
1832 Fput (Qsetting_constant
, Qerror_conditions
,
1833 Fcons (Qsetting_constant
, Fcons (Qerror
, Qnil
)));
1834 Fput (Qsetting_constant
, Qerror_message
,
1835 build_string ("Attempt to set a constant symbol"));
1837 Fput (Qinvalid_read_syntax
, Qerror_conditions
,
1838 Fcons (Qinvalid_read_syntax
, Fcons (Qerror
, Qnil
)));
1839 Fput (Qinvalid_read_syntax
, Qerror_message
,
1840 build_string ("Invalid read syntax"));
1842 Fput (Qinvalid_function
, Qerror_conditions
,
1843 Fcons (Qinvalid_function
, Fcons (Qerror
, Qnil
)));
1844 Fput (Qinvalid_function
, Qerror_message
,
1845 build_string ("Invalid function"));
1847 Fput (Qwrong_number_of_arguments
, Qerror_conditions
,
1848 Fcons (Qwrong_number_of_arguments
, Fcons (Qerror
, Qnil
)));
1849 Fput (Qwrong_number_of_arguments
, Qerror_message
,
1850 build_string ("Wrong number of arguments"));
1852 Fput (Qno_catch
, Qerror_conditions
,
1853 Fcons (Qno_catch
, Fcons (Qerror
, Qnil
)));
1854 Fput (Qno_catch
, Qerror_message
,
1855 build_string ("No catch for tag"));
1857 Fput (Qend_of_file
, Qerror_conditions
,
1858 Fcons (Qend_of_file
, Fcons (Qerror
, Qnil
)));
1859 Fput (Qend_of_file
, Qerror_message
,
1860 build_string ("End of file during parsing"));
1862 Fput (Qarith_error
, Qerror_conditions
,
1863 Fcons (Qarith_error
, Fcons (Qerror
, Qnil
)));
1864 Fput (Qarith_error
, Qerror_message
,
1865 build_string ("Arithmetic error"));
1867 Fput (Qbeginning_of_buffer
, Qerror_conditions
,
1868 Fcons (Qbeginning_of_buffer
, Fcons (Qerror
, Qnil
)));
1869 Fput (Qbeginning_of_buffer
, Qerror_message
,
1870 build_string ("Beginning of buffer"));
1872 Fput (Qend_of_buffer
, Qerror_conditions
,
1873 Fcons (Qend_of_buffer
, Fcons (Qerror
, Qnil
)));
1874 Fput (Qend_of_buffer
, Qerror_message
,
1875 build_string ("End of buffer"));
1877 Fput (Qbuffer_read_only
, Qerror_conditions
,
1878 Fcons (Qbuffer_read_only
, Fcons (Qerror
, Qnil
)));
1879 Fput (Qbuffer_read_only
, Qerror_message
,
1880 build_string ("Buffer is read-only"));
1884 staticpro (&Qquote
);
1885 staticpro (&Qlambda
);
1887 staticpro (&Qunbound
);
1888 staticpro (&Qerror_conditions
);
1889 staticpro (&Qerror_message
);
1890 staticpro (&Qtop_level
);
1892 staticpro (&Qerror
);
1894 staticpro (&Qwrong_type_argument
);
1895 staticpro (&Qargs_out_of_range
);
1896 staticpro (&Qvoid_function
);
1897 staticpro (&Qcyclic_function_indirection
);
1898 staticpro (&Qvoid_variable
);
1899 staticpro (&Qsetting_constant
);
1900 staticpro (&Qinvalid_read_syntax
);
1901 staticpro (&Qwrong_number_of_arguments
);
1902 staticpro (&Qinvalid_function
);
1903 staticpro (&Qno_catch
);
1904 staticpro (&Qend_of_file
);
1905 staticpro (&Qarith_error
);
1906 staticpro (&Qbeginning_of_buffer
);
1907 staticpro (&Qend_of_buffer
);
1908 staticpro (&Qbuffer_read_only
);
1910 staticpro (&Qlistp
);
1911 staticpro (&Qconsp
);
1912 staticpro (&Qsymbolp
);
1913 staticpro (&Qintegerp
);
1914 staticpro (&Qnatnump
);
1915 staticpro (&Qstringp
);
1916 staticpro (&Qarrayp
);
1917 staticpro (&Qsequencep
);
1918 staticpro (&Qbufferp
);
1919 staticpro (&Qvectorp
);
1920 staticpro (&Qchar_or_string_p
);
1921 staticpro (&Qmarkerp
);
1922 staticpro (&Qinteger_or_marker_p
);
1923 #ifdef LISP_FLOAT_TYPE
1924 staticpro (&Qfloatp
);
1925 staticpro (&Qinteger_or_floatp
);
1926 staticpro (&Qinteger_or_float_or_marker_p
);
1927 #endif /* LISP_FLOAT_TYPE */
1929 staticpro (&Qboundp
);
1930 staticpro (&Qfboundp
);
1939 defsubr (&Sintegerp
);
1940 #ifdef LISP_FLOAT_TYPE
1942 defsubr (&Snumberp
);
1943 defsubr (&Snumber_or_marker_p
);
1944 #endif /* LISP_FLOAT_TYPE */
1945 defsubr (&Snatnump
);
1946 defsubr (&Ssymbolp
);
1947 defsubr (&Sstringp
);
1948 defsubr (&Svectorp
);
1950 defsubr (&Ssequencep
);
1951 defsubr (&Sbufferp
);
1952 defsubr (&Smarkerp
);
1953 defsubr (&Sinteger_or_marker_p
);
1955 defsubr (&Scompiled_function_p
);
1956 defsubr (&Schar_or_string_p
);
1959 defsubr (&Scar_safe
);
1960 defsubr (&Scdr_safe
);
1963 defsubr (&Ssymbol_function
);
1964 defsubr (&Sindirect_function
);
1965 defsubr (&Ssymbol_plist
);
1966 defsubr (&Ssymbol_name
);
1967 defsubr (&Smakunbound
);
1968 defsubr (&Sfmakunbound
);
1970 defsubr (&Sfboundp
);
1972 defsubr (&Ssetplist
);
1973 defsubr (&Ssymbol_value
);
1975 defsubr (&Sdefault_boundp
);
1976 defsubr (&Sdefault_value
);
1977 defsubr (&Sset_default
);
1978 defsubr (&Ssetq_default
);
1979 defsubr (&Smake_variable_buffer_local
);
1980 defsubr (&Smake_local_variable
);
1981 defsubr (&Skill_local_variable
);
1984 defsubr (&Sint_to_string
);
1985 defsubr (&Sstring_to_int
);
1986 defsubr (&Seqlsign
);
2015 /* USG systems forget handlers when they are used;
2016 must reestablish each time */
2017 signal (signo
, arith_error
);
2020 /* VMS systems are like USG. */
2021 signal (signo
, arith_error
);
2025 #else /* not BSD4_1 */
2026 sigsetmask (SIGEMPTYMASK
);
2027 #endif /* not BSD4_1 */
2029 Fsignal (Qarith_error
, Qnil
);
2034 /* Don't do this if just dumping out.
2035 We don't want to call `signal' in this case
2036 so that we don't have trouble with dumping
2037 signal-delivering routines in an inconsistent state. */
2041 #endif /* CANNOT_DUMP */
2042 signal (SIGFPE
, arith_error
);
2045 signal (SIGEMT
, arith_error
);